Z-80 computer with Dartmouth-style BASIC as the terminal's console

SW15 switches the terminal from the PC's serial line to a Z-80 running at
90 MHz from its own clock, with 64 KB of block RAM preloaded with BASIC.

- rtl/z80_cpu.v: Z-80 built for speed (one clock per memory access, next
  byte read during decode), full documented instruction set plus the
  common undocumented forms; no interrupts.
- rtl/z80_system.v: RAM, console/timer/7-segment ports, toggle handshakes
  to the terminal clock.
- basic/: BASIC interpreter in C for SDCC, start-up code, prebuilt image.
- tools/z80emu.py, tools/cputest.py, scripts/cpusim.sh: reference emulator
  and random tests comparing the CPU after every instruction.
- SW14 feeds the PC's UART into the Z-80 for pasting programs; BTND
  resets the Z-80 only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-11-27 20:25:41 -08:00
1 parent 1e4e2101b8
commit 59d5e617f2
20 files changed
+68756 -48

No files matched your search

+16 -4
View File
@@ -1,19 +1,31 @@
# Non-project Vivado build: vivado -mode batch -source scripts/build.tcl
# The Z-80 clock is 100 MHz * CPU_MULT / CPU_DIV (environment variables).
set root [file normalize [file dirname [info script]]/..]
set out $root/build
file mkdir $out
set mult [expr {[info exists ::env(CPU_MULT)] ? $::env(CPU_MULT) : 9.0}]
set div [expr {[info exists ::env(CPU_DIV)] ? $::env(CPU_DIV) : 10.0}]
set hz [expr {int(round(100e6 * $mult / $div))}]
puts "Z-80 clock: [expr {$hz / 1e6}] MHz"
read_verilog [glob $root/rtl/*.v]
read_mem $root/font/font.mem
read_mem $root/basic/basic.mem
read_xdc $root/constraints/basys3.xdc
synth_design -top basys3_terminal -part xc7a35tcpg236-1
opt_design
place_design
route_design
synth_design -top basys3_terminal -part xc7a35tcpg236-1 \
-generic CPU_MULT=$mult -generic CPU_DIV=$div -generic CPU_HZ=$hz
opt_design -directive Explore
place_design -directive ExtraTimingOpt
phys_opt_design -directive AggressiveExplore
route_design -directive Explore
phys_opt_design -directive AggressiveExplore
write_checkpoint -force $out/routed.dcp
report_utilization -file $out/utilization.rpt
report_timing_summary -file $out/timing.rpt
report_timing -max_paths 30 -nworst 1 -unique_pins -file $out/paths.rpt
write_bitstream -force $out/basys3_terminal.bit
write_cfgmem -force -format mcs -interface SPIx4 -size 4 \
-loadbit "up 0x0 $out/basys3_terminal.bit" $out/basys3_terminal.mcs
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
# Run a Z-80 image on the Verilog CPU and on tools/z80emu.py and compare traces.
# scripts/cpusim.sh image.mem [input-file] [max-clocks]
set -e
cd "$(dirname "$0")/.."
ROOT=$(pwd)
IMG=$(realpath "$1")
INP=$(realpath "${2:-/dev/null}")
MAX=${3:-20000000}
source scripts/vivado_env.sh
mkdir -p sim/cpu
cd sim/cpu
xvlog -d IMAGE="\"$IMG\"" -d INPUT="\"$INP\"" "$ROOT/rtl/z80_cpu.v" "$ROOT/sim/tb_cpu.v" >/dev/null
xelab -debug off tb_cpu -s tb_cpu >/dev/null
xsim tb_cpu -R -testplusarg max=$MAX | grep -v -e '^INFO' -e '^#' -e '^\*\*' -e '^Vivado' -e '^ *\*\*\*\*' -e '^source' -e '^run' -e '^exit' -e '^\$finish' -e '^Time:' -e '^Copyright'
python3 "$ROOT/tools/z80emu.py" "${IMG%.mem}.bin" --input "$INP" --trace trace_sw.txt \
--max "$(wc -l < trace_hw.txt)" > out_sw.txt
python3 "$ROOT/tools/cmptrace.py" trace_sw.txt trace_hw.txt
cmp -s mem_sw.txt mem_hw.txt && echo "memory 8000-FFFF matches" || { echo "MEMORY DIFFERS"; exit 1; }
+1 -1
View File
@@ -6,7 +6,7 @@ ROOT=$(pwd)
source scripts/vivado_env.sh
mkdir -p sim/work
cd sim/work
xvlog -d FONT_FILE="\"$ROOT/font/font.mem\"" "$ROOT"/rtl/*.v "$ROOT"/sim/tb_terminal.v
xvlog -d SIMULATION -d FONT_FILE="\"$ROOT/font/font.mem\"" -d MEM_FILE="\"$ROOT/basic/basic.mem\"" "$ROOT"/rtl/*.v "$ROOT"/sim/tb_terminal.v
xelab -debug off tb_terminal -s tb_terminal
xsim tb_terminal -R
if command -v python3 >/dev/null; then