Remove the sound chip; Ctrl-Alt-Del opens the monitor

The sound chip (rtl/sound.v, ports 90h-9Dh, the PmodAMP2 on JA) is removed:
its ports now read FFh like any unused port, the JA pins are free, and the
manual, README, example and tests no longer mention it. No game used it.

Ctrl-Alt-Del raises the monitor's NMI (STOPPED BY CTRL-ALT-DEL) instead of
resetting; pressed in the monitor, again within 2 s, or while an NMI is still
pending it restarts the computer. The monitor gains RESET (port 62), and
BASIC returns to the main screen at start-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-12-02 09:08:48 -08:00
1 parent addf0157fc
commit 305c608bb5
19 files changed
+1707 -2021

No files matched your search

-142
View File
@@ -1,142 +0,0 @@
`timescale 1ns / 1ps
// Testbench for rtl/sound.v at the Z-80's 90 MHz clock: pitch, mixer, noise,
// volume levels, the attack and decay envelopes, reading back and hushing.
// scripts/sim-sound.sh
module tb_sound;
reg clk = 0, rst = 1, hush = 0, io_wr = 0;
reg [7:0] port = 0, wd = 0;
wire [7:0] q;
wire audio;
integer errors = 0;
sound #(.CPU_HZ(90_000_000)) dut (
.clk(clk), .rst(rst), .hush(hush), .io_wr(io_wr), .io_port(port), .io_wd(wd),
.io_q(q), .audio(audio)
);
always #5.556 clk = ~clk;
task out(input [7:0] p, input [7:0] v);
begin
@(posedge clk) begin port <= p; wd <= v; io_wr <= 1; end
@(posedge clk) io_wr <= 0;
end
endtask
task rd(input [7:0] p); // q then holds the port's value
begin port = p; #1; end
endtask
task check(input [8*48-1:0] what, input ok);
begin
if (ok) $display("PASS %0s", what);
else begin $display("FAIL %0s", what); errors = errors + 1; end
end
endtask
// count rising edges of voice 0's tone over a time, and the output's duty
integer edges, ones, total;
real t0, duty;
task measure(input real ms);
begin
edges = 0; ones = 0; total = 0;
t0 = $realtime;
while ($realtime - t0 < ms * 1e6) begin
@(posedge clk);
total = total + 1;
ones = ones + audio;
end
duty = 1.0 * ones / total;
end
endtask
reg t_prev = 0;
integer tone_edges = 0;
always @(posedge clk) begin
t_prev <= dut.tone[0];
if (dut.tone[0] && !t_prev) tone_edges = tone_edges + 1;
end
real d15, d7;
integer n0, v, k, rose_at, fell_at;
initial begin
repeat (10) @(posedge clk);
rst = 0;
repeat (10) @(posedge clk);
measure(1.0);
check("no output after reset", ones == 0);
// voice 0 at 440 Hz: 125000 / 284 = 440.1
out(8'h90, 284 % 256); out(8'h91, 284 / 256);
out(8'h97, 8'b000_001);
out(8'h98, 8'd15);
n0 = tone_edges;
measure(50.0);
$display(" voice 0: %0d cycles in 50 ms (%.1f Hz), duty %.3f", tone_edges - n0,
(tone_edges - n0) / 0.05, duty);
check("pitch 284 plays about 440 Hz", tone_edges - n0 >= 21 && tone_edges - n0 <= 23);
d15 = duty;
check("one voice at full volume: high 1/8 of the time", d15 > 0.11 && d15 < 0.13);
out(8'h98, 8'd7);
measure(50.0);
d7 = duty;
$display(" volume 15 duty %.4f, volume 7 duty %.4f (ratio %.1f)", d15, d7, d15 / d7);
check("volume 7 is about 24 dB quieter", d15 / d7 > 12 && d15 / d7 < 20);
rd(8'h98);
check("volume reads back", q == 8'd7);
// decay: 15 steps of 2 x 4 ms from 15 = 120 ms
out(8'h9B, 8'h02);
out(8'h98, 8'd15);
t0 = $realtime;
wait (dut.cur[0] == 0);
$display(" decay from 15 took %.1f ms", ($realtime - t0) / 1e6);
check("decay 2 fades 15 steps in 120 ms", ($realtime - t0) / 1e6 > 115 && ($realtime - t0) / 1e6 < 125);
rd(8'h98);
check("a finished sound reads back 0", q == 8'd0);
// attack then decay: up 12 steps of 1 x 4 ms, then down
out(8'h9B, 8'h13);
out(8'h98, 8'd12);
t0 = $realtime;
check("attack starts from 0", dut.cur[0] == 0);
wait (dut.cur[0] == 12);
rose_at = ($realtime - t0) / 1e6;
wait (dut.cur[0] == 0);
fell_at = ($realtime - t0) / 1e6;
$display(" attack reached 12 at %0d ms, faded out at %0d ms", rose_at, fell_at);
check("attack 1 rises 12 steps in 48 ms", rose_at >= 46 && rose_at <= 50);
check("decay 3 then falls 12 steps in 144 ms", fell_at - rose_at >= 140 && fell_at - rose_at <= 150);
// noise on voice 1, no tone
out(8'h96, 8'd4);
out(8'h97, 8'b010_000);
out(8'h9C, 8'h00);
out(8'h99, 8'd15);
n0 = 0;
for (k = 0; k < 2000; k = k + 1) begin
repeat (360) @(posedge clk);
n0 = n0 + dut.lfsr[0];
end
$display(" noise was high %0d of 2000 samples", n0);
check("noise is about half high, half low", n0 > 800 && n0 < 1200);
// all three voices and CLS
out(8'h92, 8'd142); out(8'h94, 8'd71);
out(8'h97, 8'b000_111);
out(8'h98, 8'd15); out(8'h99, 8'd15); out(8'h9A, 8'd15);
measure(20.0);
check("three voices make sound", duty > 0.2);
@(posedge clk) hush <= 1;
@(posedge clk) hush <= 0;
repeat (4) @(posedge clk); // what was already in the mixer
measure(2.0);
$display(" after CLS: output high %0d times in 2 ms", ones);
rd(8'h99);
check("CLS silences everything", ones == 0 && q == 0);
rd(8'h97);
check("other ports read FFh", q == 8'hFF);
if (errors == 0) $display("ALL SOUND TESTS PASSED");
else $display("%0d SOUND TESTS FAILED", errors);
$finish;
end
endmodule
+66 -12
View File
@@ -52,6 +52,16 @@ module tb_terminal;
end
endtask
// Ctrl-Alt-Del pressed and let go (Delete as E0 71), then 10 ms
task cad_press;
begin
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);
#10_000_000;
end
endtask
task ps2_send(input [7:0] d);
integer i;
reg [10:0] f;
@@ -201,6 +211,34 @@ module tb_terminal;
end
endtask
// the restarted BASIC's banner, on whichever row it lands, on the main
// screen (BASIC leaves the monitor's alternate screen as it starts)
task wait_banner(input [8*48-1:0] what);
realtime t0;
integer br, seen;
reg [7:0] b0, b1, b2;
begin
t0 = $realtime;
seen = 0;
while (!seen && $realtime - t0 < 500_000_000) begin
#100_000;
// one cellraw() at a time: several in one expression read wrong
for (br = 0; br < 32; br = br + 1) begin
b0 = cellraw(br, 0); b1 = cellraw(br, 1); b2 = cellraw(br, 2);
if ({b0, b1, b2} == "DAR") seen = 1;
end
end
if (seen && !dut.alt_scr) $display("PASS %0s", what);
else begin
$display("FAIL %0s: banner %0s, alternate screen %b", what,
seen ? "seen" : "not seen", dut.alt_scr);
errors = errors + 1;
dump_screen;
end
#5_000_000;
end
endtask
reg [31:0] pc_a, pc_b, jp_to;
reg [15:0] jp_txt;
integer i;
@@ -623,9 +661,9 @@ module tb_terminal;
// the float registers, in place of the memory window, and setting one
uart_str("F\015");
wait_at(21, 0, " FLOAT REGISTERS");
wait_at(22, 0, " F0 ");
wait_at(22, 0, "FT0 ");
uart_str("R F1=3FC00000\015");
wait_at(22, 13, " F1 3FC00000");
wait_at(22, 13, "FT1 3FC00000");
uart_str("M\015");
wait_at(21, 0, " MEMORY");
uart_str("\015"); // Enter: one step
@@ -716,16 +754,32 @@ module tb_terminal;
uart_str("CLS:CALL 73728\015");
wait_row(0, "ASM OK");
// ---- Ctrl-Alt-Del restarts the computer
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);
// the restarted BASIC's banner, on whichever row it lands
t_cmd = $realtime;
while ({cellraw(2, 0), cellraw(2, 1)} != "DA" && {cellraw(3, 0), cellraw(3, 1)} != "DA" &&
{cellraw(4, 0), cellraw(4, 1)} != "DA" && $realtime - t_cmd < 50_000_000) #100_000;
if ($realtime - t_cmd < 50_000_000) $display("PASS Ctrl-Alt-Del restarted BASIC");
else begin $display("FAIL Ctrl-Alt-Del: no banner"); errors = errors + 1; end
// ---- Ctrl-Alt-Del: into the monitor, even with interrupts off in a
// tight loop; again (within 2 s, or in the monitor) restarts the computer
// csrci mstatus,8 (interrupts off) at 12000, then j . at 12004
uart_str("CLS:POKE 73728,115:POKE 73729,112:POKE 73730,4:POKE 73731,48\015");
uart_str("POKE 73732,111:POKE 73733,0:POKE 73734,0:POKE 73735,0\015");
#5_000_000;
uart_str("CALL 73728\015"); // hangs at 12004, interrupts off
#5_000_000;
cad_press;
wait_at(0, 50, "STOPPED BY CTRL-ALT-DEL");
if (screen_pc(0) == 32'h12004) $display("PASS Ctrl-Alt-Del stopped the loop at 12004");
else begin $display("FAIL Ctrl-Alt-Del: PC %h", screen_pc(0)); errors = errors + 1; end
uart_str("X\015"); // back into the loop
#10_000_000;
cad_press; // within 2 s: restart
wait_banner("Ctrl-Alt-Del twice restarted BASIC");
// a trap goes to the monitor; Ctrl-Alt-Del there restarts
uart_str("CLS:POKE 73728,0:POKE 73729,0:POKE 73730,0:POKE 73731,0:CALL 73728\015");
wait_at(0, 50, "STOPPED BY ILLEGAL INSTRUCTI");
cad_press;
wait_banner("Ctrl-Alt-Del in the monitor restarted BASIC");
// the monitor's RESET
uart_str("CLS:MONITOR\015");
wait_at(29, 0, "> ");
uart_str("RESET\015");
wait_banner("the monitor's RESET restarted BASIC");
dump_screen;
`endif
if (errors == 0) $display("ALL TESTS PASSED");