Monitor: the CPU gets an NMI (taken at an instruction start, or from HALT) raised by the Pause key, BASIC's MONITOR, two hardware breakpoint comparators or a step counter. It enters through a trampoline at 0066h (the same bytes in BASIC's ROM and the monitor's, basic/tramp.s) that switches in a 32 KB monitor bank over 0000-7FFF. The monitor (monitor/, C) runs on the terminal's new alternate screen (CSI ?47 h/l, a second screen page; graphics hidden) and shows registers, flags, a disassembly from PC, the stack and memory. Commands: Enter/S n step, O step over, G/X go, B breakpoint, D/M windows, E edit, R registers, and SAVE/LOAD/ DIR for memory files. The disassembler covers every opcode; monitor/test-disasm.py round-trips all forms through sdasz80. Lockstep CPU tests still match the reference emulator. BASIC: MONITOR, CALL addr, BSAVE "N",start,len and BLOAD "N"[,addr] (memory files: load address then bytes). The DATE clock moves to F3F8h so the monitor can date files. F000-F3F7 is kept free for machine code (program area 21076 bytes). Serial: SW1:0 = 10 is now 921600 and 11 is 3 Mbaud. A 17 KB burst to BASIC lists back identical at both on the board. send-bas.py reads the echo while sending; unread, it could stall the PC's flow control. Ctrl-Alt-Del in Z-80 mode restarts the Z-80 like BTND. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.6 KiB
Python
Executable File
77 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Copy the program in the Basys 3 Z-80's memory to a file on the PC, or send
|
|
BASIC a command and print what it answers.
|
|
|
|
The board needs SW15 and SW14 up (Z-80 mode, PC serial linked: the Z-80's
|
|
output is then copied to the PC), and nothing else may be using the port
|
|
(stop the getty first). The baud rate must match SW1:0. BASIC's clock is set
|
|
to the PC's first (unless --no-date), so files saved get today's date.
|
|
|
|
tools/get-bas.py myprog.bas --baud 9600 # LIST into myprog.bas
|
|
tools/get-bas.py --cmd 'LOAD "DEMO"' --baud 9600 # run a command, show output
|
|
"""
|
|
import argparse
|
|
import os
|
|
import re
|
|
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", nargs="?", help="where to write the listing")
|
|
ap.add_argument("--cmd", action="append", help="send this command instead (repeatable)")
|
|
ap.add_argument("--port", default="/dev/ttyUSB1")
|
|
ap.add_argument("--baud", type=int, default=115200, choices=sorted(BAUDS))
|
|
ap.add_argument("--timeout", type=float, default=30, help="seconds to wait for READY")
|
|
ap.add_argument("--no-date", action="store_true", help="don't set BASIC's clock")
|
|
a = ap.parse_args()
|
|
if not a.file and not a.cmd:
|
|
ap.error("give a file name or --cmd")
|
|
|
|
fd = os.open(a.port, os.O_RDWR | os.O_NOCTTY)
|
|
t = termios.tcgetattr(fd)
|
|
t[0] = termios.IXON
|
|
t[1] = 0
|
|
t[2] = termios.CS8 | termios.CREAD | termios.CLOCAL
|
|
t[3] = 0
|
|
t[4] = t[5] = BAUDS[a.baud]
|
|
t[6][termios.VMIN] = 0
|
|
t[6][termios.VTIME] = 0
|
|
termios.tcsetattr(fd, termios.TCSANOW, t)
|
|
termios.tcflush(fd, termios.TCIFLUSH)
|
|
|
|
|
|
def run(cmd):
|
|
"""Send one line; return everything BASIC prints up to its next READY."""
|
|
os.write(fd, cmd.encode("ascii") + b"\r")
|
|
buf = b""
|
|
end = time.time() + a.timeout
|
|
while time.time() < end:
|
|
r, _, _ = select.select([fd], [], [], 0.2)
|
|
if r:
|
|
buf += os.read(fd, 4096)
|
|
if re.search(rb"\r\nREADY\r\n$", buf):
|
|
break
|
|
text = buf.decode("latin-1").replace("\r", "")
|
|
lines = text.split("\n")
|
|
if lines and lines[0].strip() == cmd.strip(): # BASIC echoes the command
|
|
lines = lines[1:]
|
|
return "\n".join(l for l in lines if l != "READY").strip("\n")
|
|
|
|
|
|
if not a.no_date:
|
|
run(time.strftime('DATE "%Y-%m-%d %H:%M:%S"'))
|
|
if a.cmd:
|
|
for c in a.cmd:
|
|
print(run(c))
|
|
else:
|
|
out = run("LIST")
|
|
prog = [l for l in out.split("\n") if re.match(r"\d+ ", l)]
|
|
with open(a.file, "w") as f:
|
|
f.write("\n".join(prog) + "\n")
|
|
print("%d lines written to %s" % (len(prog), a.file))
|
|
os.close(fd)
|