Machine-code monitor, fast serial, memory files, Ctrl-Alt-Del

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>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-11-28 11:17:54 -08:00
1 parent 767377f38d
commit 634e314010
27 files changed
+37481 -3039

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ module tb_cpu;
z80_cpu cpu (
.clk(clk), .rst(rst), .ma(ma), .we(we), .wd(wd), .din(din),
.io_addr(io_addr), .io_rd(io_rd), .io_wr(io_wr), .io_wd(io_wd), .io_din(io_din),
.halted(halted), .ins_start(ins_start), .dbg_pc(pc),
.halted(halted), .nmi(1'b0), .nmi_now(1'b0), .ins_start(ins_start), .dbg_pc(pc),
.dbg_af(af), .dbg_bc(bc), .dbg_de(de), .dbg_hl(hl), .dbg_ix(ix), .dbg_iy(iy), .dbg_sp(sp)
);
+110 -3
View File
@@ -17,7 +17,7 @@ module tb_terminal;
wire qcs;
wire [3:0] qdb;
basys3_terminal #(.FONT_FILE(`FONT_FILE), .MEM_FILE(`MEM_FILE)) dut (
basys3_terminal #(.FONT_FILE(`FONT_FILE), .MEM_FILE(`MEM_FILE), .MON_FILE(`MON_FILE)) dut (
.clk(clk), .btnC(btnC), .btnU(btnU), .btnD(btnD), .sw(sw), .led(led), .seg(), .dp(), .an(),
.vgaRed(r), .vgaGreen(g), .vgaBlue(b), .Hsync(hs), .Vsync(vs),
.RsRx(rsrx), .RsTx(rstx), .PS2Clk(ps2c), .PS2Data(ps2d),
@@ -26,7 +26,7 @@ module tb_terminal;
spiflash_model flash (.cs_n(qcs), .sck(dut.fl_sck), .mosi(qdb[0]), .miso(qdb[1]));
localparam BIT_NS = 1_000_000_000 / 115200;
real BIT_NS = 1_000_000_000.0 / 115200; // changed for the 3 Mbaud test
integer errors = 0;
task uart_send(input [7:0] d);
@@ -102,7 +102,7 @@ module tb_terminal;
function [7:0] cellraw(input integer rr, input integer cc);
reg [17:0] v;
begin
v = dut.screen.mem[rr * 80 + cc];
v = dut.screen.mem[(dut.alt_scr ? 4096 : 0) + rr * 80 + cc]; // the page on show
cellraw = v[7:0];
end
endfunction
@@ -165,6 +165,34 @@ module tb_terminal;
end
endtask
// wait (up to 300 ms) for text at row rr from column c0
task wait_at(input integer rr, input integer c0, input [8*40-1:0] want);
integer cc, n;
reg [8*40-1:0] got;
realtime t0;
begin
t0 = $realtime;
n = 0;
for (cc = 0; cc < 40; cc = cc + 1) if (want[cc*8 +: 8] != 0) n = cc + 1;
got = 0;
while (got != want && $realtime - t0 < 300_000_000) begin
#100_000;
for (cc = 0; cc < n; cc = cc + 1) got[(n - 1 - cc) * 8 +: 8] = cellraw(rr, c0 + cc);
end
if (got == want) $display("PASS row %0d col %0d: %0s", rr, c0, want);
else begin
$display("FAIL row %0d col %0d: want \"%0s\" got \"%0s\"", rr, c0, want, got);
errors = errors + 1;
end
end
endtask
reg [31:0] pc_a, pc_b, jp_to;
reg [23:0] jp_txt;
function [31:0] screen_pc(input integer dummy);
screen_pc = {cellraw(2, 4), cellraw(2, 5), cellraw(2, 6), cellraw(2, 7)};
endfunction
// capture one frame
reg [11:0] fb [0:640*480-1];
reg cap = 0, smp = 0;
@@ -325,6 +353,85 @@ module tb_terminal;
uart_str({"CLS:OPEN \"D\" FOR OUTPUT AS 1:PRINT #1,\"XY\";\",\";7:CLOSE\015",
"OPEN \"D\" FOR INPUT AS 1:INPUT #1,A$,B:PRINT A$;B*6;EOF(1):CLOSE\015"});
wait_row(3, "XY 42 -1");
// ---- the machine-code monitor
uart_str("MONITOR\015");
wait_at(0, 50, "STOPPED BY MONITOR COMMAND");
wait_at(2, 0, " PC ");
wait_at(29, 0, "> ");
pc_a = screen_pc(0);
wait_at(5, 0, ">");
jp_txt = {cellraw(5, 21), cellraw(5, 22), cellraw(5, 23)};
jp_to = {cellraw(5, 24), cellraw(5, 25), cellraw(5, 26), cellraw(5, 27)};
dump_screen;
uart_str("\015"); // Enter: one step
wait_at(0, 50, "STOPPED BY STEP");
wait_at(29, 0, "> ");
pc_b = screen_pc(0);
// MONITOR stops on a JP (to the end of BASIC's statement routine): one
// step must land exactly on its target
if (pc_b == jp_to) $display("PASS step: PC %0s -> %0s (%0s)", pc_a, pc_b, jp_txt);
else begin $display("FAIL step: PC %0s -> %0s, wanted %0s (%0s)", pc_a, pc_b, jp_to, jp_txt); errors = errors + 1; end
// a breakpoint where the step stopped (the end of BASIC's statement
// routine), hit again by OUT; leaving from it steps off it first
uart_str("B "); uart_send(pc_b[31:24]); uart_send(pc_b[23:16]);
uart_send(pc_b[15:8]); uart_send(pc_b[7:0]); uart_send(8'h0D);
wait_at(29, 40, "BREAKPOINT SET");
uart_str("X\015");
wait_row(3, "XY 42 -1"); // BASIC's screen is back as it was
uart_str("OUT 32,7\015");
wait_at(0, 50, "STOPPED BY BREAKPOINT");
wait_at(29, 0, "> ");
if (screen_pc(0) == pc_b) $display("PASS breakpoint at %0s", pc_b);
else begin $display("FAIL breakpoint: PC %0s, wanted %0s", screen_pc(0), pc_b); errors = errors + 1; end
uart_str("B\015");
wait_at(29, 40, "BREAKPOINT CLEARED");
uart_str("X\015");
#5_000_000;
// the Pause key
ps2_send(8'hE1); ps2_send(8'h14); ps2_send(8'h77);
ps2_send(8'hE1); ps2_send(8'hF0); ps2_send(8'h14); ps2_send(8'hF0); ps2_send(8'h77);
wait_at(0, 50, "STOPPED BY PAUSE KEY");
wait_at(29, 0, "> ");
uart_str("X\015");
#2_000_000;
uart_str("CLS:PRINT 3*4\015");
wait_row(0, " 12");
// ---- 3 Mbaud (SW1:0 = 11): a program in, its output on screen and back
sw[1:0] = 2'b11;
BIT_NS = 1_000_000_000.0 / 3_000_000;
#200_000;
tx_n = 0; tx_log = 0;
uart_str({"CLS:NEW\01510 FOR I=1 TO 3:PRINT I*111;:NEXT I\01520 PRINT \"FAST\"\015",
"RUN\015"});
wait_row(5, " 111 222 333 FAST");
#2_000_000;
if (tx_log[8*7-1:0] == "READY\015\012") $display("PASS 3 Mbaud: %0d bytes back, ending READY", tx_n);
else begin $display("FAIL 3 Mbaud: %0d bytes back, last %h", tx_n, tx_log[8*7-1:0]); errors = errors + 1; end
// ---- memory files: the monitor's SAVE/LOAD/DIR, BASIC's BSAVE/BLOAD
uart_str("CLS:POKE 36864,72:POKE 36865,73:MONITOR\015");
wait_at(29, 0, "> ");
uart_str("SAVE \"MEM1\" 9000 9001\015");
wait_at(29, 40, "SAVED");
uart_str("E 9000 00 00\015");
wait_at(29, 0, "> ");
uart_str("LOAD \"MEM1\"\015");
wait_at(29, 40, "LOADED 9000-9001");
wait_at(22, 0, " 9000 48 49 ");
uart_str("DIR\015");
wait_at(29, 40, "M TO SHOW MEMORY AGAIN");
uart_str("X\015");
#3_000_000;
uart_str("CLS:POKE 36864,0:BLOAD \"MEM1\":BSAVE \"MEM2\",36864,2:BLOAD \"MEM2\",36866:PRINT PEEK(36866);PEEK(36867)\015");
wait_row(0, " 72 73");
// ---- Ctrl-Alt-Del restarts the Z-80
ps2_send(8'h14); ps2_send(8'h11); ps2_send(8'hE0); ps2_send(8'h71);
ps2_send(8'hE0); ps2_send(8'hF0); ps2_send(8'h71); ps2_send(8'hF0); ps2_send(8'h11);
ps2_send(8'hF0); ps2_send(8'h14);
wait_row(4, "DARTMOUTH-STYLE BASIC"); // the restarted BASIC's banner
dump_screen;
if (errors == 0) $display("ALL TESTS PASSED");
else $display("%0d TESTS FAILED", errors);