DATE "YYYY-MM-DD[ HH:MM[:SS]]" sets a clock kept from the millisecond counter, DATE prints it and DATE$ returns it. Directory entries now record each file's creation date (format BFS2; a BFS1 directory is widened when read), and DIR shows it. send-bas.py and get-bas.py set the date from the PC when they connect (--no-date to skip). Data files: OPEN "NAME" FOR INPUT|OUTPUT|APPEND AS #n (n = 1-3), PRINT #n, INPUT #n, LINE INPUT [#n,], EOF(n), CLOSE [#n]. SAVE and LOAD now use the same channel code. A written file replaces the old one only at CLOSE; APPEND shares the old file's full blocks and copies the last part block. New errors FILE ALREADY OPEN, FILE NOT OPEN, INPUT PAST END; PROGRAM TOO BIG TO SAVE becomes FILE TOO BIG. The program area shrinks from 23000 to 22100 bytes to keep the stack at about 3 KB beside the file buffers. Code now ends at 7EBFh. The simulation sets the date, checks it in DIR and round-trips a data file, waiting for expected rows instead of fixed delays. Tested on the board: dates, write/append/read, EOF, the BFS1 conversion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.8 KiB
Python
Executable File
51 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Type a BASIC program into the Basys 3 Z-80 over the serial port.
|
|
|
|
The board needs SW15 and SW14 up (Z-80 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 termios
|
|
import time
|
|
|
|
BAUDS = {9600: termios.B9600, 19200: termios.B19200, 57600: termios.B57600,
|
|
115200: termios.B115200}
|
|
|
|
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"'))
|
|
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
|
|
print("\r%d/%d lines" % (n, len(lines)), end="", flush=True)
|
|
print()
|
|
os.close(fd)
|