Add Verilator simulation (ImGui + headless)
verilator/ runs the core on the host with the shared FM-7 / Apple-IIgs sim framework: windowed (ImGui/SDL2) or --headless, typing on a frame schedule, screenshots, text-screen dump, 6809 disassembly trace, floppy/SDC/cart/cassette, and RS-232 Pak serial debugging (TXD decoder, RXD driver, pty bridge, ACIA trace) with a minimal DriveWire server and a script to run the real FujiNet daemon against the sim. See verilator/README.md. - The VHDL the build uses (ROMs, RAMs, font) is converted to Verilog in verilator/rtl/; the VHDL CPU is not instantiated (CoCo3_CYC_ACC_6809). - sdram2.sv is simulated with its own controller logic and an SDR chip model. - run_tests.sh: boot, keyboard, disk, WIDTH 80 and HSCREEN tests, judged on the text screen and byte-for-byte against test-ref/ screenshots. rtl/wd1793.sv: spt_addr and buff_wr are declared at module scope instead of inside generate blocks. They are assigned outside those blocks; Quartus accepted it, Verilator rejected spt_addr and silently split buff_wr into a separate net. No change on the FPGA (FM-7 made the same fix). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
aae1ceabf1
commit
874f4f3083
79 files changed
+81058
-2
No files matched your search
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Minimal DriveWire 3 server for the sim's --serial-pty.
|
||||
|
||||
Serves one or more .dsk images (256-byte sectors, LSN n at offset n*256) to
|
||||
HDB-DOS DW over the pty the sim prints at start-up:
|
||||
|
||||
./obj_dir/Vemu --serial-pty ... & # prints "Serial: ... on pty /dev/ttysNNN"
|
||||
python3 tests/dwserver.py /dev/ttysNNN tests/hello.dsk
|
||||
|
||||
It is a test stand-in for FujiNet / pyDriveWire, covering only what HDB-DOS
|
||||
uses: READ/READEX/REREAD(EX), WRITE/REWRITE, TIME, INIT/TERM/RESET/NOP and
|
||||
DWINIT. Every operation is logged. Writes go to memory, never to the file.
|
||||
Uses only the standard library.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import termios
|
||||
import time
|
||||
import tty
|
||||
|
||||
OP_NOP, OP_TIME, OP_INIT, OP_TERM = 0x00, 0x23, 0x49, 0x54
|
||||
OP_READ, OP_REREAD, OP_READEX, OP_REREADEX = 0x52, 0x72, 0xD2, 0xF2
|
||||
OP_WRITE, OP_REWRITE, OP_DWINIT = 0x57, 0x77, 0x5A
|
||||
OP_RESETS = (0xFE, 0xFF, 0xF8)
|
||||
E_OK, E_CRC, E_NOTRDY = 0x00, 0xF3, 0xF6
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(f"[dw {time.strftime('%H:%M:%S')}] {msg}", flush=True)
|
||||
|
||||
|
||||
class Port:
|
||||
def __init__(self, path):
|
||||
self.fd = os.open(path, os.O_RDWR | os.O_NOCTTY)
|
||||
tty.setraw(self.fd)
|
||||
attrs = termios.tcgetattr(self.fd)
|
||||
attrs[3] &= ~termios.ECHO
|
||||
termios.tcsetattr(self.fd, termios.TCSANOW, attrs)
|
||||
|
||||
def read(self, n):
|
||||
out = b""
|
||||
while len(out) < n:
|
||||
chunk = os.read(self.fd, n - len(out))
|
||||
if not chunk:
|
||||
raise EOFError
|
||||
out += chunk
|
||||
return out
|
||||
|
||||
def write(self, data):
|
||||
os.write(self.fd, data)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
sys.exit(__doc__)
|
||||
port = Port(sys.argv[1])
|
||||
disks = [bytearray(open(p, "rb").read()) for p in sys.argv[2:]]
|
||||
for i, p in enumerate(sys.argv[2:]):
|
||||
log(f"drive {i}: {p} ({len(disks[i]) // 256} sectors)")
|
||||
|
||||
def sector(drive, lsn):
|
||||
if drive >= len(disks):
|
||||
return None
|
||||
d = disks[drive]
|
||||
off = lsn * 256
|
||||
return bytes(d[off:off + 256]).ljust(256, b"\x00") if off < len(d) else bytes(256)
|
||||
|
||||
while True:
|
||||
op = port.read(1)[0]
|
||||
if op in (OP_READEX, OP_REREADEX):
|
||||
drive, *l = port.read(4)
|
||||
lsn = (l[0] << 16) | (l[1] << 8) | l[2]
|
||||
data = sector(drive, lsn)
|
||||
port.write(data if data is not None else bytes(256))
|
||||
csum = int.from_bytes(port.read(2), "big")
|
||||
ok = data is not None and csum == sum(data) & 0xFFFF
|
||||
err = E_OK if ok else (E_NOTRDY if data is None else E_CRC)
|
||||
port.write(bytes([err]))
|
||||
log(f"{'REREADEX' if op == OP_REREADEX else 'READEX'} drive {drive} LSN {lsn}"
|
||||
f" -> {'ok' if ok else f'error ${err:02X} (their checksum ${csum:04X})'}")
|
||||
elif op in (OP_READ, OP_REREAD):
|
||||
drive, *l = port.read(4)
|
||||
lsn = (l[0] << 16) | (l[1] << 8) | l[2]
|
||||
data = sector(drive, lsn)
|
||||
if data is None:
|
||||
port.write(bytes([E_NOTRDY]))
|
||||
else:
|
||||
port.write(bytes([E_OK]) + data + (sum(data) & 0xFFFF).to_bytes(2, "big"))
|
||||
log(f"READ drive {drive} LSN {lsn}")
|
||||
elif op in (OP_WRITE, OP_REWRITE):
|
||||
drive, *l = port.read(4)
|
||||
lsn = (l[0] << 16) | (l[1] << 8) | l[2]
|
||||
data = port.read(256)
|
||||
csum = int.from_bytes(port.read(2), "big")
|
||||
ok = csum == sum(data) & 0xFFFF and drive < len(disks)
|
||||
if ok:
|
||||
d = disks[drive]
|
||||
need = (lsn + 1) * 256
|
||||
if len(d) < need:
|
||||
d.extend(bytes(need - len(d)))
|
||||
d[lsn * 256:need] = data
|
||||
port.write(bytes([E_OK if ok else E_CRC]))
|
||||
log(f"WRITE drive {drive} LSN {lsn} -> {'ok' if ok else 'checksum error'}")
|
||||
elif op == OP_TIME:
|
||||
t = time.localtime()
|
||||
port.write(bytes([t.tm_year - 1900, t.tm_mon, t.tm_mday,
|
||||
t.tm_hour, t.tm_min, t.tm_sec]))
|
||||
log("TIME")
|
||||
elif op == OP_DWINIT:
|
||||
caps = port.read(1)[0]
|
||||
port.write(bytes([0x00]))
|
||||
log(f"DWINIT (client caps ${caps:02X})")
|
||||
elif op in (OP_INIT, OP_TERM, OP_NOP) or op in OP_RESETS:
|
||||
log(f"op ${op:02X}")
|
||||
else:
|
||||
log(f"unknown op ${op:02X} -- ignored")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
pass
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Boot a FujiNet cart against the real FujiNet daemon (FujiNet-PC, the same code
|
||||
# the MiSTer build runs on the HPS), bridged to the sim's RS-232 Pak by a pty.
|
||||
#
|
||||
# tests/fujinet_boot.sh FUJINET_DIST CART STOP_FRAME [extra sim args...]
|
||||
#
|
||||
# FUJINET_DIST a FujiNet-PC `make dist` directory for FUJINET_TARGET=COCO
|
||||
# (fujinet binary + data/). A copy is made; the original is not
|
||||
# touched.
|
||||
# CONFIG env: fnconfig.ini to start from (default: FujiNet_MiSTer's
|
||||
# config/fnconfig.ini). Only [Serial] port is changed.
|
||||
#
|
||||
# tests/fujinet_boot.sh ~/fn/dist ../../FujiNet_MiSTer/roms/HDBDW3L3_19200.CCC 400 \
|
||||
# --fast-clocks
|
||||
#
|
||||
# Output in $OUT (default fujinet_boot/): sim.log, fujinet.log, screenshot.
|
||||
|
||||
set -u
|
||||
cd "$(dirname "$0")/.."
|
||||
[ $# -ge 3 ] || { sed -n 3,18p "$0"; exit 2; }
|
||||
dist=$1; cart=$2; stop=$3; shift 3
|
||||
config=${CONFIG:-../../FujiNet_MiSTer/config/fnconfig.ini}
|
||||
out=${OUT:-fujinet_boot}
|
||||
rm -rf "$out"; mkdir -p "$out/fn"
|
||||
cp -R "$dist"/. "$out/fn/"
|
||||
mkdir -p "$out/fn/SD"
|
||||
|
||||
./obj_dir/Vemu --headless --cart "$cart" --serial-pty --stop-at-frame "$stop" \
|
||||
--screenshot "$stop" --screenshot-prefix "$out/shot" --ascii-end "$@" > "$out/sim.log" 2>&1 &
|
||||
sim=$!
|
||||
pty=
|
||||
for _ in $(seq 1 100); do
|
||||
pty=$(grep -o '/dev/ttys[0-9]*\|/dev/pts/[0-9]*' "$out/sim.log" | head -1)
|
||||
[ -n "$pty" ] && break
|
||||
sleep 0.1
|
||||
done
|
||||
[ -n "$pty" ] || { echo "sim did not open a pty"; kill $sim; exit 1; }
|
||||
|
||||
sed "s|^port=.*|port=$pty|" "$config" > "$out/fn/fnconfig.ini"
|
||||
echo "sim on $pty; FujiNet config from $config"
|
||||
( cd "$out/fn" && exec ./fujinet -c fnconfig.ini -s SD ) > "$out/fujinet.log" 2>&1 &
|
||||
fn=$!
|
||||
trap 'kill $sim $fn 2>/dev/null' INT TERM
|
||||
wait $sim
|
||||
kill $fn 2>/dev/null
|
||||
|
||||
echo "--- sim"
|
||||
grep -E '^\||^Serial' "$out/sim.log" | grep -v '^| *|$'
|
||||
echo "--- FujiNet (DriveWire lines)"
|
||||
grep -a -i -E 'drivewire|op_|readex|read |sector|lsn|timeout|checksum|mount|serial' "$out/fujinet.log" | head -60
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build tests/hello.dsk: a Disk BASIC (DECB) floppy holding one ASCII BASIC
|
||||
program, HELLO.BAS. Used by run_tests.sh to exercise the FDC path end to end:
|
||||
wd1793 -> fdc.sv -> hps block device -> sim_blkdevice.
|
||||
|
||||
Layout (35 tracks x 18 sectors x 256 bytes, sectors numbered from 1):
|
||||
track 17 sector 2 FAT, one byte per granule (68 granules of 9 sectors)
|
||||
track 17 sectors 3-11 directory, 32-byte entries
|
||||
Granules 0/1 are track 0 sectors 1-9 / 10-18, granule 2k is track k (k<17),
|
||||
and so on, skipping the directory track.
|
||||
"""
|
||||
import os
|
||||
|
||||
TRACKS, SECTORS, SSIZE = 35, 18, 256
|
||||
img = bytearray(b'\xff' * (TRACKS * SECTORS * SSIZE))
|
||||
|
||||
def sector(track, sec): # sec is 1-based
|
||||
off = (track * SECTORS + sec - 1) * SSIZE
|
||||
return off
|
||||
|
||||
prog = b'10 PRINT "HELLO FROM DISK"\r20 PRINT 6*7\r'
|
||||
|
||||
# The program goes in granule 0 (track 0, sectors 1..9); it fits in one sector.
|
||||
img[sector(0, 1):sector(0, 1) + SSIZE] = prog.ljust(SSIZE, b'\x00')
|
||||
|
||||
# FAT: granule 0 is the last granule of the file and uses 1 sector.
|
||||
fat = sector(17, 2)
|
||||
img[fat:fat + SSIZE] = b'\xff' * SSIZE
|
||||
img[fat + 0] = 0xC0 | 1
|
||||
img[fat + 68:fat + SSIZE] = b'\x00' * (SSIZE - 68)
|
||||
|
||||
# Directory: first entry HELLO.BAS, BASIC (type 0), ASCII (flag $FF).
|
||||
d = sector(17, 3)
|
||||
entry = bytearray(32)
|
||||
entry[0:8] = b'HELLO '
|
||||
entry[8:11] = b'BAS'
|
||||
entry[11] = 0x00 # file type: BASIC program
|
||||
entry[12] = 0xFF # ASCII
|
||||
entry[13] = 0 # first granule
|
||||
entry[14:16] = len(prog).to_bytes(2, 'big') # bytes used in the last sector
|
||||
img[d:d + 32] = entry
|
||||
# Unused entries start with $FF ("never used"); the rest of the track is $FF.
|
||||
|
||||
out = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'hello.dsk')
|
||||
open(out, 'wb').write(img)
|
||||
print(f'wrote {out} ({len(img)} bytes)')
|
||||
Reference in new issue
Block a user