Files
Basys3RiscV/basic/build.sh
T
brad ArantandClaude Opus 5.5 2e668c708f BASIC compiler (tools/basc.py) and a runtime jump table in BASIC's ROM
tools/basc.py compiles a BASIC program to C and through GCC to an Intel HEX
file loaded at A200h like the games, with a two-line BLOAD/CALL loader.
Arithmetic, variables, arrays, all control flow and graphics arguments are
compiled; PRINT, INPUT, strings, files, sound, DATA and the remaining
functions go through BASIC's ROM via a fixed jump table at 9F00h (RT_ABI 1),
so they behave identically. basic/test-compile.py runs 31 programs both
ways and checks identical screens and graphics; typical loops run 7-26x
faster. New error PROGRAM NEEDS ANOTHER BASIC.

Fixes a bug present since the first version: variable numbers past 255
wrapped, so X1-Z9 shared storage with A-B9 (A7 and Y were the same
variable). test-blocks.py checks it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 19:29:59 -08:00

22 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Compile BASIC for RV32IM and write basic.bin and the RAM images basic.mem
# (0000-FFFF) and basic-hi.mem (10000-13FFF).
set -e
cd "$(dirname "$0")"
source ../scripts/rv_env.sh
mkdir -p out
CFLAGS="$RV_ARCH_F -ffp-contract=off -Os -ffunction-sections -fdata-sections -fno-common -Wall -I../include"
${RV_PREFIX}gcc $CFLAGS -c -o out/crt0.o crt0.S
${RV_PREFIX}gcc $CFLAGS -c -o out/basic.o basic.c
${RV_PREFIX}gcc $CFLAGS -c -o out/string.o ../lib/string.c
${RV_PREFIX}gcc $CFLAGS -c -o out/mathf.o ../lib/mathf.c
${RV_PREFIX}gcc $CFLAGS -c -o out/setjmp.o ../lib/setjmp.S
${RV_PREFIX}gcc $RV_ARCH_F -nostdlib -nostartfiles -T basic.ld -Wl,--gc-sections -Wl,-Map,out/basic.map \
-Wl,--build-id=none -o out/basic.elf out/crt0.o out/basic.o out/string.o out/mathf.o out/setjmp.o -lgcc
${RV_PREFIX}objcopy -O binary -j .text -j .rtab -j .data out/basic.elf basic.bin
${RV_PREFIX}nm -n out/basic.elf > out/basic.sym
python3 ../tools/bin2mem.py basic.bin out/basic-all.mem 20480
head -n 16384 out/basic-all.mem > basic.mem
tail -n 4096 out/basic-all.mem > basic-hi.mem
${RV_PREFIX}size out/basic.elf