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

+26 -11
View File
@@ -5,7 +5,7 @@
// UART RX -> 80x30 colour text on VGA
// SW15 up: the terminal is the Z-80's console
//
// SW1:0 baud rate: 00 115200, 01 9600, 10 19200, 11 57600 (8N1)
// SW1:0 baud rate: 00 115200, 01 9600, 10 921600, 11 3000000 (8N1)
// SW2 local echo
// SW3 received LF also does CR
// SW5:4 default text colour: 00 green, 01 yellow, 10 white, 11 cyan
@@ -28,6 +28,7 @@
module basys3_terminal #(
parameter FONT_FILE = "font.mem",
parameter MEM_FILE = "basic.mem",
parameter MON_FILE = "monitor.mem",
parameter CLK_HZ = 100_000_000,
parameter real CPU_MULT = 9.0, // Z-80 clock = 100 MHz * CPU_MULT / CPU_DIV
parameter real CPU_DIV = 10.0,
@@ -82,8 +83,8 @@ module basys3_terminal #(
case (sw_r[1:0])
2'b00: baud_div <= CLK_HZ / 115200;
2'b01: baud_div <= CLK_HZ / 9600;
2'b10: baud_div <= CLK_HZ / 19200;
2'b11: baud_div <= CLK_HZ / 57600;
2'b10: baud_div <= CLK_HZ / 921600; // 108: 0.5% fast
2'b11: baud_div <= CLK_HZ / 3000000; // 33: 1% fast
endcase
reg [3:0] def_fg;
@@ -108,13 +109,18 @@ module basys3_terminal #(
.code(scan), .valid(scan_valid)
);
wire cad;
ps2_keymap kbd_map (
.clk(clk), .rst(rst), .code(scan), .code_valid(scan_valid),
.bs_del(sw_r[6]), .enter_crlf(sw_r[7] | lnm),
.cursor_app(cursor_app), .keypad_app(keypad_app),
.ascii(key), .ascii_valid(key_valid), .caps(caps)
.ascii(key), .ascii_valid(key_valid), .caps(caps), .cad(cad)
);
// Ctrl-Alt-Del in Z-80 mode restarts the Z-80, like BTND (held 1 us)
reg [6:0] cad_t = 7'd0;
always @(posedge clk) cad_t <= cad && z80_mode ? 7'd100 : cad_t - (cad_t != 0);
// ----------------------------------------------------------- host input
// Keyboard bytes and terminal replies go to the host: the PC's UART, or in
// Z-80 mode the Z-80's input FIFO. The keyboard/reply choice sticks until
@@ -259,7 +265,7 @@ module basys3_terminal #(
`endif
(* ASYNC_REG = "TRUE" *) reg [2:0] cpu_rst_s;
always @(posedge cpu_clk) cpu_rst_s <= {cpu_rst_s[1:0], rst | zrst_sync[1] | !locked};
always @(posedge cpu_clk) cpu_rst_s <= {cpu_rst_s[1:0], rst | zrst_sync[1] | (cad_t != 0) | !locked};
// Z-80 input: one byte at a time from z80_in_fifo
reg zrx_req, zrx_pend;
@@ -293,11 +299,18 @@ module basys3_terminal #(
wire [16:0] gfx_addr;
wire [3:0] gfx_pix;
z80_system #(.MEM_FILE(MEM_FILE), .CPU_HZ(CPU_HZ)) z80 (
// The Pause key (its scan codes start E1, used by nothing else) enters the
// Z-80 monitor: a toggle crosses to the CPU clock.
reg brk_t = 1'b0;
always @(posedge clk) if (scan_valid && scan == 8'hE1 && z80_mode) brk_t <= ~brk_t;
(* ASYNC_REG = "TRUE" *) reg [2:0] brk_s = 3'd0;
always @(posedge cpu_clk) brk_s <= {brk_s[1:0], brk_t};
z80_system #(.MEM_FILE(MEM_FILE), .MON_FILE(MON_FILE), .CPU_HZ(CPU_HZ)) z80 (
.clk(cpu_clk), .rst(cpu_rst_s[2]),
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
.seg_val(z80_seg), .halted(),
.seg_val(z80_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
);
@@ -367,6 +380,7 @@ module basys3_terminal #(
// ------------------------------------------------------------- terminal
wire [11:0] t_addr;
wire alt_scr;
wire t_we;
wire [17:0] t_wdata, t_rdata;
wire [4:0] cur_row, stop, sbot, sm_off;
@@ -385,22 +399,23 @@ module basys3_terminal #(
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
.resp_byte(resp_byte), .resp_wr(resp_wr), .resp_full(rq_full),
.cursor_app(cursor_app), .keypad_app(keypad_app), .lnm(lnm),
.dec_leds(dec_leds), .bell(bell)
.dec_leds(dec_leds), .bell(bell), .alt_scr(alt_scr)
);
wire [11:0] v_addr;
wire [17:0] v_data;
// the alternate screen (the Z-80 monitor uses it) has no graphics layer
char_ram screen (
.clk(clk),
.a_addr(t_addr), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
.b_addr(v_addr), .b_rdata(v_data)
.a_addr({alt_scr, t_addr}), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
.b_addr({alt_scr, v_addr}), .b_rdata(v_data)
);
text_display #(.FONT_FILE(FONT_FILE)) video (
.clk(clk), .rst(rst), .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
.ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(gfx_pix),
.ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(alt_scr ? 4'd0 : gfx_pix),
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
.frame_tick(frame_tick)
);