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
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Type a BASIC program into the Basys 3 RISC-V computer over the serial port.
|
||||
|
||||
The board needs SW15 and SW14 up (computer mode, PC serial linked), and nothing
|
||||
else may be using the port (stop the getty first). The baud rate must match
|
||||
SW1:0. Sets BASIC's clock to the PC's (unless --no-date), sends NEW unless
|
||||
--keep is given, then the program, then RUN if --run is given.
|
||||
|
||||
tools/send-bas.py basic/examples/graphics-demo.bas --baud 9600 --run
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import select
|
||||
import termios
|
||||
import time
|
||||
|
||||
BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600,
|
||||
3000000: termios.B3000000}
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("file")
|
||||
ap.add_argument("--port", default="/dev/ttyUSB1")
|
||||
ap.add_argument("--baud", type=int, default=115200, choices=sorted(BAUDS))
|
||||
ap.add_argument("--keep", action="store_true", help="don't send NEW first")
|
||||
ap.add_argument("--run", action="store_true", help="send RUN at the end")
|
||||
ap.add_argument("--no-date", action="store_true", help="don't set BASIC's clock")
|
||||
a = ap.parse_args()
|
||||
|
||||
fd = os.open(a.port, os.O_RDWR | os.O_NOCTTY)
|
||||
t = termios.tcgetattr(fd)
|
||||
t[0] = termios.IXON # honour XON/XOFF
|
||||
t[1] = 0
|
||||
t[2] = termios.CS8 | termios.CREAD | termios.CLOCAL
|
||||
t[3] = 0
|
||||
t[4] = t[5] = BAUDS[a.baud]
|
||||
termios.tcsetattr(fd, termios.TCSANOW, t)
|
||||
|
||||
lines = [l.rstrip() for l in open(a.file) if l.strip()]
|
||||
if not a.keep:
|
||||
lines.insert(0, "NEW")
|
||||
if a.run:
|
||||
lines.append("RUN")
|
||||
if not a.no_date:
|
||||
lines.insert(0, time.strftime('DATE "%Y-%m-%d %H:%M:%S"'))
|
||||
t[6][termios.VMIN] = 0 # reads don't wait
|
||||
t[6][termios.VTIME] = 0
|
||||
termios.tcsetattr(fd, termios.TCSANOW, t)
|
||||
for n, line in enumerate(lines, 1):
|
||||
os.write(fd, line.encode("ascii") + b"\r")
|
||||
termios.tcdrain(fd)
|
||||
time.sleep(0.02) # let BASIC store the line
|
||||
# Read BASIC's echo (copied back when SW14 is up). Left unread, it fills the
|
||||
# PC's input buffer; Linux then stops reading the port, misses the board's
|
||||
# XON and never sends again.
|
||||
while select.select([fd], [], [], 0)[0] and os.read(fd, 4096):
|
||||
pass
|
||||
print("\r%d/%d lines" % (n, len(lines)), end="", flush=True)
|
||||
print()
|
||||
os.close(fd)
|
||||
Reference in new issue
Block a user