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>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-12-01 19:29:59 -08:00
1 parent fa4752fd7a
commit 2e668c708f
11 files changed
+5703 -3671

No files matched your search

+8
View File
@@ -150,6 +150,14 @@ def main():
''')
check("GOTO back to a DO does not fill its stack", " 40 41 END" in out, out)
out = run('''
10 A7 = 5: Y = 9: X2 = 3: A = 1: B8 = 2
20 FOR Z9 = 1 TO 2: NEXT Z9
30 DEF FNQ(Y7) = Y7 * 10
40 PRINT A7; Y; X2; A; B8; Z9; FNQ(4); Y7
''')
check("X1 to Z9 are variables of their own (not A to B9)", " 5 9 3 1 2 3 40 0" in out, out)
b.type(b"CLS" + CR)
b.type(b'I=0: DO: I=I+1: LOOP UNTIL I=7: PRINT "DIRECT"; I' + CR)
check("DO ... LOOP in a direct statement", "DIRECT 7" in screen(), screen())