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:
1 parent
767377f38d
commit
634e314010
27 files changed
+37481
-3039
No files matched your search
+23
-5
@@ -11,8 +11,11 @@
|
||||
//
|
||||
// The full documented instruction set is implemented, plus the undocumented
|
||||
// IXH/IXL/IYH/IYL forms, SLL and the DDCB register copies. Block instructions
|
||||
// loop internally (LDIR moves a byte every 3 clocks). There are no interrupts:
|
||||
// EI/DI/IM only set their registers, and HALT stops the CPU until reset.
|
||||
// loop internally (LDIR moves a byte every 3 clocks). The only interrupt is a
|
||||
// non-maskable one for the monitor: a pulse on `nmi` is taken at the next
|
||||
// instruction start from that clock on (or in HALT), `nmi_now` at this one. It
|
||||
// pushes the address of the instruction not yet run, jumps to 0066h and clears
|
||||
// IFF1 (RETN copies IFF2 back). EI/DI/IM only set their registers.
|
||||
module z80_cpu (
|
||||
input clk,
|
||||
input rst,
|
||||
@@ -28,6 +31,8 @@ module z80_cpu (
|
||||
output reg [7:0] io_wd,
|
||||
input [7:0] io_din,
|
||||
output halted,
|
||||
input nmi, // pulse: take at the next instruction start
|
||||
input nmi_now, // level: take at this instruction start
|
||||
// debug: ins_start is high on the first clock of each instruction
|
||||
output ins_start,
|
||||
output [15:0] dbg_pc,
|
||||
@@ -70,12 +75,14 @@ module z80_cpu (
|
||||
reg take;
|
||||
reg [15:0] ea, tmp;
|
||||
reg [7:0] tlo;
|
||||
reg nmi_p; // NMI waiting
|
||||
|
||||
wire [15:0] BC = {rB, rC}, DE = {rD, rE}, HL = {rH, rL};
|
||||
|
||||
assign halted = st == S_HALT;
|
||||
assign ins_start = st == S_D && xm == 2'd0;
|
||||
assign dbg_pc = PC - 1'b1;
|
||||
wire take_nmi = xm == 2'd0 && (nmi_p || nmi || nmi_now);
|
||||
assign dbg_af = {rA, rF}; assign dbg_bc = BC; assign dbg_de = DE;
|
||||
assign dbg_hl = HL; assign dbg_ix = IX; assign dbg_iy = IY; assign dbg_sp = SP;
|
||||
|
||||
@@ -317,6 +324,7 @@ module z80_cpu (
|
||||
io_wr <= 1'b0;
|
||||
pd <= 1'b0;
|
||||
if (pd) nxt <= din;
|
||||
if (nmi) nmi_p <= 1'b1;
|
||||
|
||||
if (rst) begin
|
||||
st <= S_F; ma <= 16'h0000; PC <= 16'h0000;
|
||||
@@ -325,12 +333,17 @@ module z80_cpu (
|
||||
{aA, aF, aB, aC, aD, aE, aH, aL} <= 64'd0;
|
||||
IX <= 16'hFFFF; IY <= 16'hFFFF;
|
||||
rI <= 8'h00; rR <= 8'h00; iff1 <= 1'b0; iff2 <= 1'b0; im <= 2'd0;
|
||||
xm <= 2'd0; un <= 1'b0; rsm <= 1'b0; nbad <= 1'b0;
|
||||
xm <= 2'd0; un <= 1'b0; rsm <= 1'b0; nbad <= 1'b0; nmi_p <= 1'b0;
|
||||
end else case (st)
|
||||
S_F: next_stream;
|
||||
|
||||
// ------------------------------------------------------ main opcodes
|
||||
S_D: begin
|
||||
S_D: if (take_nmi) begin // NMI: like RST 66h, before this opcode
|
||||
tmp <= dbg_pc; ea <= 16'h0066;
|
||||
SP <= SP - 1'b1; wr(SP - 1'b1, dbg_pc[15:8]);
|
||||
iff2 <= iff1; iff1 <= 1'b0; nmi_p <= 1'b0;
|
||||
ic <= I_CALL; st <= S_W1;
|
||||
end else begin
|
||||
op = un ? nxt : din;
|
||||
x = op[7:6]; y = op[5:3]; z = op[2:0]; p = op[5:4]; q = op[3];
|
||||
rR <= {rR[7], rR[6:0] + 7'd1};
|
||||
@@ -716,7 +729,12 @@ module z80_cpu (
|
||||
st <= S_W;
|
||||
end
|
||||
|
||||
S_HALT: ;
|
||||
S_HALT: if (nmi_p || nmi) begin // NMI wakes HALT, returning after it
|
||||
tmp <= dbg_pc; ea <= 16'h0066;
|
||||
SP <= SP - 1'b1; wr(SP - 1'b1, dbg_pc[15:8]);
|
||||
iff2 <= iff1; iff1 <= 1'b0; nmi_p <= 1'b0;
|
||||
ic <= I_CALL; st <= S_W1;
|
||||
end
|
||||
default: st <= S_F;
|
||||
endcase
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user