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:
1 parent
addf0157fc
commit
305c608bb5
19 files changed
+1707
-2021
No files matched your search
+32
-10
@@ -56,8 +56,7 @@ module basys3_terminal #(
|
||||
input PS2Clk,
|
||||
input PS2Data,
|
||||
output QspiCSn,
|
||||
inout [3:0] QspiDB,
|
||||
output [3:0] JA // PmodAMP2: audio in, gain, -, shutdown (low)
|
||||
inout [3:0] QspiDB
|
||||
);
|
||||
localparam [7:0] XON = 8'h11, XOFF = 8'h13;
|
||||
|
||||
@@ -127,9 +126,34 @@ module basys3_terminal #(
|
||||
.clk(clk), .rst(rst | ~rv_mode), .code(scan), .code_valid(scan_valid), .down(keys_down)
|
||||
);
|
||||
|
||||
// Ctrl-Alt-Del in computer mode restarts the computer, like BTND (held 1 us)
|
||||
// Ctrl-Alt-Del in computer mode enters the monitor (an NMI, like Pause).
|
||||
// It restarts the computer instead, like BTND (held 1 us), when the monitor
|
||||
// is already running or an NMI is still waiting to be taken (the CPU is
|
||||
// wedged), or when it comes again within 2 s. A press counts only after
|
||||
// Delete has been up for 5 ms, so holding the keys (which repeats Delete)
|
||||
// is one press. Port 62 (the monitor's RESET) restarts the computer too.
|
||||
wire mon_busy, reset_t;
|
||||
(* ASYNC_REG = "TRUE" *) reg [1:0] busy_s = 2'd0;
|
||||
(* ASYNC_REG = "TRUE" *) reg [2:0] rreq_s = 3'd0;
|
||||
always @(posedge clk) begin
|
||||
busy_s <= {busy_s[0], mon_busy};
|
||||
rreq_s <= {rreq_s[1:0], reset_t};
|
||||
end
|
||||
reg [19:0] del_up = 20'd0; // how long Delete has been up
|
||||
reg [27:0] cad_win = 28'd0; // counts down 2 s after a press
|
||||
reg cad_nmi_t = 1'b0; // toggles: enter the monitor
|
||||
wire del_held = keys_down[8'h71] | keys_down[8'hF1];
|
||||
wire cad_new = cad && rv_mode && del_up[19];
|
||||
wire cad_rst = cad_new && (busy_s[1] || cad_win != 0);
|
||||
reg [6:0] cad_t = 7'd0;
|
||||
always @(posedge clk) cad_t <= cad && rv_mode ? 7'd100 : cad_t - (cad_t != 0);
|
||||
always @(posedge clk) begin
|
||||
if (rst || del_held || (cad && rv_mode)) del_up <= 20'd0;
|
||||
else del_up <= del_up + {19'd0, !del_up[19]};
|
||||
if (rst) cad_win <= 28'd0;
|
||||
else cad_win <= cad_new ? CLK_HZ * 2 : cad_win - (cad_win != 0);
|
||||
if (cad_new && !cad_rst) cad_nmi_t <= ~cad_nmi_t;
|
||||
cad_t <= cad_rst || (rreq_s[2] ^ rreq_s[1]) ? 7'd100 : cad_t - (cad_t != 0);
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------- host input
|
||||
// Keyboard bytes and terminal replies go to the host: the PC's UART, or in
|
||||
@@ -345,6 +369,8 @@ module basys3_terminal #(
|
||||
always @(posedge clk) if (scan_valid && scan == 8'hE1 && rv_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};
|
||||
(* ASYNC_REG = "TRUE" *) reg [2:0] cad_s = 3'd0;
|
||||
always @(posedge cpu_clk) cad_s <= {cad_s[1:0], cad_nmi_t};
|
||||
|
||||
wire wide; // DECCOLM from the terminal (term_ctrl below)
|
||||
rv32_system #(.MEM_FILE(MEM_FILE), .MEM_HI_FILE(MEM_HI_FILE), .MON_FILE(MON_FILE), .CPU_HZ(CPU_HZ), .ROM_TOP(ROM_TOP)) sys (
|
||||
@@ -352,19 +378,15 @@ module basys3_terminal #(
|
||||
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
|
||||
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack), .wide(wide),
|
||||
.seg_val(rv_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
||||
.cad_key(cad_s[2] ^ cad_s[1]), .mon_busy(mon_busy), .reset_t(reset_t),
|
||||
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||
.scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border),
|
||||
.g_hires(g_hires), .g_cols(g_cols),
|
||||
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
||||
.sp_pix(sp_pix), .sp_ftick(pix_frame), .keys(keys_down),
|
||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1]),
|
||||
.audio(JA[0])
|
||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
||||
);
|
||||
|
||||
// PmodAMP2 on JA's top row: gain high is 6 dB (low would be 12 dB), and
|
||||
// the amplifier is on unless its shutdown pin is low.
|
||||
assign JA[3:1] = 3'b101;
|
||||
|
||||
// The flash clock is the configuration clock pin, reached through STARTUPE2.
|
||||
// DQ2/DQ3 (write protect, hold) stay high.
|
||||
assign QspiDB[1] = 1'bz;
|
||||
|
||||
+11
-14
@@ -42,8 +42,9 @@
|
||||
// 40 SPI flash control, 41 SPI flash data (see flash_spi.v)
|
||||
// 60 out bit 1 = stop again (NMI) after one instruction of the program
|
||||
// in why the last NMI came: 1 Pause key, 2 port 61, 3 step,
|
||||
// 4 breakpoint 0, 5 breakpoint 1
|
||||
// 4 breakpoint 0, 5 breakpoint 1, 6 Ctrl-Alt-Del
|
||||
// 61 out enter the monitor (NMI)
|
||||
// 62 out restart the computer (as BTND does; the monitor's RESET)
|
||||
// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on
|
||||
// 70-78, 80-87 sprites (see sprites.v)
|
||||
// 88 in keys held: bit 0 up (W, cursor or keypad 8), 1 down (S, 2), 2 left
|
||||
@@ -51,7 +52,6 @@
|
||||
// 7 Esc
|
||||
// 89 out pick a scan code (set 2; add 128 for an E0 code)
|
||||
// in 1 if that key is held, else 0
|
||||
// 90-9D sound (see sound.v)
|
||||
// The Z-80's debug-read ports (62-64) are gone: the monitor runs in the same
|
||||
// address space as the program. Its breakpoint addresses are 32 bits, below.
|
||||
//
|
||||
@@ -88,6 +88,9 @@ module rv32_system #(
|
||||
output reg [15:0] seg_val,
|
||||
output halted,
|
||||
input brk_key, // pulse: the Pause key, enter the monitor
|
||||
input cad_key, // pulse: Ctrl-Alt-Del, enter the monitor too
|
||||
output mon_busy, // the monitor runs, or an NMI waits to be taken
|
||||
output reg reset_t = 1'b0, // toggles: port 62, restart the computer
|
||||
// graphics layer read port, on the video clock
|
||||
input vclk,
|
||||
input [16:0] gfx_vaddr,
|
||||
@@ -111,9 +114,7 @@ module rv32_system #(
|
||||
output fl_cs_n,
|
||||
output fl_sck,
|
||||
output fl_mosi,
|
||||
input fl_miso,
|
||||
// sound, for a PmodAMP2
|
||||
output audio
|
||||
input fl_miso
|
||||
);
|
||||
localparam [31:0] MON_BASE = 32'h0002_0000;
|
||||
assign halted = 1'b0;
|
||||
@@ -366,13 +367,6 @@ module rv32_system #(
|
||||
.rd_on(sp_on), .pix(sp_pix), .gfx_pix(gfx_vpix), .ftick(sp_ftick)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------- sound
|
||||
wire [7:0] snd_q;
|
||||
sound #(.CPU_HZ(CPU_HZ)) snd (
|
||||
.clk(clk), .rst(rst), .hush(io_wr && io_addr == 8'h34 && !io_wd[7]),
|
||||
.io_wr(io_wr), .io_port(io_addr), .io_wd(io_wd), .io_q(snd_q), .audio(audio)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------- held keys
|
||||
// The keyboard's clock writes these; a bit that changes while it is read
|
||||
// just reads as before or after.
|
||||
@@ -447,6 +441,8 @@ module rv32_system #(
|
||||
if (!nmi_r && !in_mon) begin
|
||||
if (brk_key) begin
|
||||
nmi_r <= 1'b1; why_r <= 3'd1;
|
||||
end else if (cad_key) begin
|
||||
nmi_r <= 1'b1; why_r <= 3'd6;
|
||||
end else if (io_wr && io_addr == 8'h61) begin
|
||||
nmi_r <= 1'b1; why_r <= 3'd2;
|
||||
end
|
||||
@@ -459,6 +455,9 @@ module rv32_system #(
|
||||
end
|
||||
end
|
||||
|
||||
assign mon_busy = nmi_r || in_mon;
|
||||
always @(posedge clk) if (io_wr && io_addr == 8'h62) reset_t <= ~reset_t;
|
||||
|
||||
(* ASYNC_REG = "TRUE" *) reg [1:0] wide_s = 2'b00;
|
||||
always @(posedge clk) wide_s <= {wide_s[0], wide};
|
||||
|
||||
@@ -480,8 +479,6 @@ module rv32_system #(
|
||||
io_din = spr_q;
|
||||
8'h88: io_din = joy;
|
||||
8'h89: io_din = {7'd0, keys[key_sel]};
|
||||
8'h98, 8'h99, 8'h9A:
|
||||
io_din = snd_q;
|
||||
default: io_din = 8'hFF;
|
||||
endcase
|
||||
always @* case (io_a[7:0])
|
||||
|
||||
-173
@@ -1,173 +0,0 @@
|
||||
`timescale 1ns / 1ps
|
||||
// A small sound chip for the Z-80, in the style of the 8-bit era's
|
||||
// programmable sound generators, played through a Digilent PmodAMP2.
|
||||
//
|
||||
// Three square-wave voices and a noise source. Each voice plays its tone,
|
||||
// the noise, or both (the mixer), at one of 16 volumes on a log scale (about
|
||||
// 3 dB a step). A volume write starts an envelope: an optional rise from 0 at
|
||||
// the attack rate, then an optional fall to 0 at the decay rate, so a game
|
||||
// can fire off a shot or an explosion with a few OUTs and leave it.
|
||||
//
|
||||
// 90h/91h voice 0 pitch, low byte / high 4 bits frequency = 125000 / pitch Hz
|
||||
// 92h/93h voice 1 pitch (pitch 0 counts as 1)
|
||||
// 94h/95h voice 2 pitch
|
||||
// 96h noise pitch, 0-31: higher is lower and rougher
|
||||
// 97h mixer: bits 0-2 tone on for voices 0-2, bits 3-5 noise on for them
|
||||
// 98h-9Ah voice 0-2 volume 0-15, which (re)starts its envelope; reading
|
||||
// gives the volume it is at now, so 0 means the sound has ended
|
||||
// 9Bh-9Dh voice 0-2 envelope: high nibble attack, low nibble decay, each
|
||||
// n x 4 ms a volume step (0 = jump straight up / hold)
|
||||
//
|
||||
// A voice with neither its tone nor the noise on outputs a steady level, as
|
||||
// on the old chips. `hush` (CLS) and reset silence everything.
|
||||
//
|
||||
// The three voices are added up and turned into a single bit by a first-order
|
||||
// sigma-delta modulator at the full clock rate; the PmodAMP2 filters it and
|
||||
// drives headphones or a speaker.
|
||||
module sound #(
|
||||
parameter CPU_HZ = 100_000_000
|
||||
) (
|
||||
input clk,
|
||||
input rst,
|
||||
input hush,
|
||||
input io_wr,
|
||||
input [7:0] io_port,
|
||||
input [7:0] io_wd,
|
||||
output reg [7:0] io_q, // for reads of 98h-9Ah
|
||||
output reg audio = 1'b0
|
||||
);
|
||||
localparam TICK_DIV = CPU_HZ / 250_000; // tone counters run at 250 kHz
|
||||
localparam MS4_DIV = CPU_HZ / 250; // envelope steps in 4 ms units
|
||||
|
||||
reg [11:0] pitch [0:2];
|
||||
reg [4:0] npitch;
|
||||
reg [5:0] mixer;
|
||||
reg [3:0] vol [0:2]; // the volume asked for
|
||||
reg [3:0] cur [0:2]; // the volume now
|
||||
reg [3:0] att [0:2], dec [0:2];
|
||||
reg rising [0:2];
|
||||
|
||||
// ---------------------------------------------------------------- ticks
|
||||
reg [9:0] tdiv = 10'd0;
|
||||
reg tick = 1'b0;
|
||||
reg [19:0] ediv = 20'd0;
|
||||
reg etick = 1'b0;
|
||||
always @(posedge clk) begin
|
||||
tick <= tdiv == 0;
|
||||
tdiv <= tdiv == 0 ? TICK_DIV - 1 : tdiv - 1'b1;
|
||||
etick <= ediv == 0;
|
||||
ediv <= ediv == 0 ? MS4_DIV - 1 : ediv - 1'b1;
|
||||
end
|
||||
|
||||
// --------------------------------------------------------------- voices
|
||||
reg [11:0] tcnt [0:2];
|
||||
reg [2:0] tone = 3'd0;
|
||||
reg [4:0] ncnt = 5'd0;
|
||||
reg [16:0] lfsr = 17'd1;
|
||||
reg [3:0] ecnt [0:2];
|
||||
integer i;
|
||||
initial for (i = 0; i < 3; i = i + 1) begin
|
||||
tcnt[i] = 12'd0; ecnt[i] = 4'd0; cur[i] = 4'd0; vol[i] = 4'd0;
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (rst || hush) begin
|
||||
for (i = 0; i < 3; i = i + 1) begin
|
||||
vol[i] <= 4'd0; cur[i] <= 4'd0; rising[i] <= 1'b0;
|
||||
if (rst) begin pitch[i] <= 12'd0; att[i] <= 4'd0; dec[i] <= 4'd0; end
|
||||
end
|
||||
mixer <= 6'd0;
|
||||
if (rst) begin npitch <= 5'd0; lfsr <= 17'd1; tone <= 3'd0; end
|
||||
end else begin
|
||||
if (io_wr) case (io_port)
|
||||
8'h90: pitch[0][7:0] <= io_wd;
|
||||
8'h91: pitch[0][11:8] <= io_wd[3:0];
|
||||
8'h92: pitch[1][7:0] <= io_wd;
|
||||
8'h93: pitch[1][11:8] <= io_wd[3:0];
|
||||
8'h94: pitch[2][7:0] <= io_wd;
|
||||
8'h95: pitch[2][11:8] <= io_wd[3:0];
|
||||
8'h96: npitch <= io_wd[4:0];
|
||||
8'h97: mixer <= io_wd[5:0];
|
||||
8'h9B: {att[0], dec[0]} <= io_wd;
|
||||
8'h9C: {att[1], dec[1]} <= io_wd;
|
||||
8'h9D: {att[2], dec[2]} <= io_wd;
|
||||
default: ;
|
||||
endcase
|
||||
|
||||
// tones: each output flips every `pitch` ticks
|
||||
if (tick) begin
|
||||
for (i = 0; i < 3; i = i + 1)
|
||||
if (tcnt[i] <= 12'd1) begin
|
||||
tcnt[i] <= pitch[i];
|
||||
tone[i] <= ~tone[i];
|
||||
end else
|
||||
tcnt[i] <= tcnt[i] - 1'b1;
|
||||
if (ncnt == 0) begin
|
||||
ncnt <= npitch;
|
||||
lfsr <= {lfsr[0] ^ lfsr[3], lfsr[16:1]};
|
||||
end else
|
||||
ncnt <= ncnt - 1'b1;
|
||||
end
|
||||
|
||||
// envelopes
|
||||
for (i = 0; i < 3; i = i + 1) begin
|
||||
if (io_wr && io_port == 8'h98 + i) begin
|
||||
vol[i] <= io_wd[3:0];
|
||||
ecnt[i] <= 4'd0;
|
||||
if (att[i] != 0 && io_wd[3:0] != 0) begin
|
||||
cur[i] <= 4'd0; rising[i] <= 1'b1;
|
||||
end else begin
|
||||
cur[i] <= io_wd[3:0]; rising[i] <= 1'b0;
|
||||
end
|
||||
end else if (etick) begin
|
||||
if (rising[i]) begin
|
||||
if (ecnt[i] + 1'b1 >= att[i]) begin
|
||||
ecnt[i] <= 4'd0;
|
||||
cur[i] <= cur[i] + 1'b1;
|
||||
if (cur[i] + 1'b1 >= vol[i]) rising[i] <= 1'b0;
|
||||
end else
|
||||
ecnt[i] <= ecnt[i] + 1'b1;
|
||||
end else if (dec[i] != 0 && cur[i] != 0) begin
|
||||
if (ecnt[i] + 1'b1 >= dec[i]) begin
|
||||
ecnt[i] <= 4'd0;
|
||||
cur[i] <= cur[i] - 1'b1;
|
||||
end else
|
||||
ecnt[i] <= ecnt[i] + 1'b1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
always @* case (io_port)
|
||||
8'h98: io_q = {4'd0, cur[0]};
|
||||
8'h99: io_q = {4'd0, cur[1]};
|
||||
8'h9A: io_q = {4'd0, cur[2]};
|
||||
default: io_q = 8'hFF;
|
||||
endcase
|
||||
|
||||
// ---------------------------------------------------------------- mixing
|
||||
function [7:0] level(input [3:0] v); // about 3 dB a step
|
||||
case (v)
|
||||
4'd0: level = 8'd0; 4'd1: level = 8'd2; 4'd2: level = 8'd3; 4'd3: level = 8'd4;
|
||||
4'd4: level = 8'd6; 4'd5: level = 8'd8; 4'd6: level = 8'd11; 4'd7: level = 8'd16;
|
||||
4'd8: level = 8'd23; 4'd9: level = 8'd32; 4'd10: level = 8'd45; 4'd11: level = 8'd64;
|
||||
4'd12: level = 8'd90; 4'd13: level = 8'd128; 4'd14: level = 8'd181; default: level = 8'd255;
|
||||
endcase
|
||||
endfunction
|
||||
|
||||
wire [2:0] on;
|
||||
genvar g;
|
||||
generate for (g = 0; g < 3; g = g + 1) begin : mix
|
||||
assign on[g] = (tone[g] | ~mixer[g]) & (lfsr[0] | ~mixer[g + 3]);
|
||||
end endgenerate
|
||||
|
||||
reg [9:0] sum = 10'd0;
|
||||
reg [10:0] acc = 11'd0;
|
||||
always @(posedge clk) begin
|
||||
sum <= (on[0] ? level(cur[0]) : 10'd0) + (on[1] ? level(cur[1]) : 10'd0) +
|
||||
(on[2] ? level(cur[2]) : 10'd0);
|
||||
acc <= rst ? 11'd0 : {1'b0, acc[9:0]} + {1'b0, sum}; // carry out = the output bit
|
||||
audio <= acc[10];
|
||||
end
|
||||
endmodule
|
||||
Reference in new issue
Block a user