Basys 3 RISC-V computer
The Basys 3 Z-80 computer with the Z-80 replaced by an RV32IM processor written from scratch (rtl/rv32_cpu.v): multi-cycle, 90 MHz, CSRs and traps, interrupts, two hardware triggers and a resumable NMI for the monitor. Passes riscv-tests rv32ui/um/mi. rv32_system.v keeps all the Z-80 machine's peripherals, with I/O port N at FFFFFF00h + N, 80 KB of RAM with BASIC preloaded, and a 32 KB monitor ROM. BASIC, the five games and the monitor (with an RV32 disassembler, assembler, breakpoints and single step) are ported to RISC-V GCC. Python emulator and tests in tools/; full-system simulation in sim/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
5930b958b4
103 files changed
+55677
No files matched your search
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Try BASIC's string arrays in tools/rv32emu.py, with the screen kept by pyte.
|
||||
|
||||
python3 test-strarr.py
|
||||
"""
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
spec = importlib.util.spec_from_file_location("te", os.path.join(HERE, "test-edit.py"))
|
||||
te = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(te)
|
||||
CR = te.CR
|
||||
|
||||
|
||||
def main():
|
||||
b = te.Basic()
|
||||
errors = 0
|
||||
|
||||
def check(what, ok):
|
||||
nonlocal errors
|
||||
print(("PASS " if ok else "FAIL ") + what)
|
||||
errors += not ok
|
||||
|
||||
def run(prog):
|
||||
b.type(b"NEW" + CR)
|
||||
for line in prog.strip().splitlines():
|
||||
b.type(line.encode() + CR)
|
||||
b.type(b"RUN" + CR)
|
||||
return "\n".join(l.rstrip() for l in b.screen_text().display).split("RUN")[-1]
|
||||
|
||||
b.type(b"")
|
||||
out = run('''
|
||||
10 DIM N$(4), A(3)
|
||||
20 FOR I = 0 TO 4: READ N$(I): NEXT I
|
||||
30 A(2) = 7: A$ = "PLAIN"
|
||||
40 FOR I = 4 TO 0 STEP -1: PRINT N$(I);",";: NEXT I
|
||||
50 PRINT: PRINT A$; A(2); LEN(N$(1)); " "; LEFT$(N$(3), 2)
|
||||
60 DATA RED, GREEN, BLUE, "YEL, LOW", WHITE
|
||||
''')
|
||||
check("DIM, READ and PRINT a string array", "WHITE,YEL, LOW,BLUE,GREEN,RED," in out)
|
||||
check("plain A$ and A() kept apart", "PLAIN 7 5 YE" in out)
|
||||
|
||||
out = run('''
|
||||
10 DIM B$(2,3)
|
||||
20 B$(1,2) = "MID": B$(2,3) = B$(1,2) + "DLE"
|
||||
30 PRINT B$(2,3); "/"; B$(0,0); "/"; LEN(B$(0,1))
|
||||
40 C$(10) = "AUTO": PRINT C$(10)
|
||||
50 IF B$(1,2) = "MID" THEN PRINT "EQUAL"
|
||||
''')
|
||||
check("two subscripts and joining", "MIDDLE// 0" in out)
|
||||
check("undeclared string array gets 0..10", "AUTO" in out)
|
||||
check("comparing an element", "EQUAL" in out)
|
||||
|
||||
out = run('''
|
||||
10 INPUT "NAME"; N$(3)
|
||||
20 PRINT "HI "; N$(3)
|
||||
''')
|
||||
b.type(b"ZED" + CR)
|
||||
check("INPUT into an element", "HI ZED" in "\n".join(l.rstrip() for l in b.screen_text().display))
|
||||
|
||||
out = run('10 LINE INPUT L$(1): PRINT "<"; L$(1); ">"')
|
||||
b.type(b"A, B" + CR)
|
||||
check("LINE INPUT into an element", "<A, B>" in "\n".join(l.rstrip() for l in b.screen_text().display))
|
||||
|
||||
out = run('10 DIM Q$(2): Q$(3) = "X"')
|
||||
check("subscript out of range", "SUBSCRIPT" in out.upper())
|
||||
out = run('10 DIM Z$(300)')
|
||||
check("too many elements is an error", "SUBSCRIPT" in out.upper())
|
||||
out = run('10 DIM Z$(200), Y$(200)')
|
||||
check("running out of memory is an error", "MEMORY" in out.upper())
|
||||
out = run('10 DIM Z$(200): Z$(200) = "LAST": PRINT Z$(200)')
|
||||
check("a 201-element string array fits", "LAST" in out)
|
||||
sys.exit(1 if errors else 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user