2021-10-29 10:04:59 +00:00
|
|
|
module CNT(
|
2023-07-16 03:21:44 +00:00
|
|
|
/* FSB clock and E clock inputs */
|
2023-07-16 06:25:27 +00:00
|
|
|
input CLK, input C8M, input E,
|
2021-10-29 10:04:59 +00:00
|
|
|
/* Refresh request */
|
2023-07-16 03:21:44 +00:00
|
|
|
output reg RefReq, output reg RefUrg,
|
2023-03-26 08:33:59 +00:00
|
|
|
/* Reset, button */
|
|
|
|
output reg nRESout, input nIPL2,
|
2023-03-20 04:53:10 +00:00
|
|
|
/* Mac PDS bus master control outputs */
|
2023-04-08 09:46:13 +00:00
|
|
|
output reg AoutOE, output reg nBR_IOB,
|
|
|
|
/* Sound QoS */
|
2023-07-16 06:25:27 +00:00
|
|
|
input BACT, input WS, input nWE,
|
2023-07-16 03:21:44 +00:00
|
|
|
input SndROMCS, input SndRAMCSWR, input RAMCS,
|
|
|
|
output reg QoSReady);
|
2023-03-26 08:33:59 +00:00
|
|
|
|
|
|
|
/* E clock synchronization */
|
2023-07-16 06:25:27 +00:00
|
|
|
reg [1:0] Er; always @(posedge CLK) Er[1:0] <= { Er[0], E };
|
2023-03-26 08:33:59 +00:00
|
|
|
wire EFall = Er[1] && !Er[0];
|
2023-07-16 06:25:27 +00:00
|
|
|
|
|
|
|
/* C8M clock synchronization */
|
|
|
|
reg [1:0] C8Mr; always @(posedge CLK) C8Mr[1:0] <= { C8Mr[0], C8M };
|
|
|
|
wire C8MFall = C8Mr[1] && !C8Mr[0];
|
2023-07-16 03:21:44 +00:00
|
|
|
|
2023-04-08 09:46:13 +00:00
|
|
|
/* NMI button synchronization */
|
|
|
|
reg nIPL2r; always @(posedge CLK) nIPL2r <= nIPL2;
|
2023-04-08 09:49:29 +00:00
|
|
|
|
|
|
|
/* Startup sequence state */
|
|
|
|
reg [1:0] IS = 0;
|
2022-09-04 01:32:05 +00:00
|
|
|
|
2023-03-25 07:50:31 +00:00
|
|
|
/* Timer counts from 0 to 1010 (10) -- 11 states == 14.042 us
|
2023-03-22 01:11:58 +00:00
|
|
|
* Refresh timer sequence
|
2023-04-08 08:08:53 +00:00
|
|
|
* | Timer | RefReq | RefUrg |
|
|
|
|
* |---------|--------|-----------|
|
2023-03-22 01:11:58 +00:00
|
|
|
* | 0 0000 | 0 | 0 |
|
2023-04-08 08:08:53 +00:00
|
|
|
* | 1 0001 | 1 | 0 |
|
2023-03-26 08:33:59 +00:00
|
|
|
* | 2 0010 | 1 | 0 |
|
2023-03-22 01:11:58 +00:00
|
|
|
* | 3 0011 | 1 | 0 |
|
|
|
|
* | 4 0100 | 1 | 0 |
|
|
|
|
* | 5 0101 | 1 | 0 |
|
|
|
|
* | 6 0110 | 1 | 0 |
|
2023-03-25 07:50:31 +00:00
|
|
|
* | 7 0111 | 1 | 0 |
|
2023-04-08 08:08:53 +00:00
|
|
|
* | 8 1000 | 1 | 0 |
|
2023-04-10 08:08:23 +00:00
|
|
|
* | 9 1001 | 1 | 1 |
|
2023-03-25 07:50:31 +00:00
|
|
|
* | 10 1010 | 1 | 1 |
|
2023-03-20 04:53:10 +00:00
|
|
|
* back to timer==0
|
2022-09-04 01:32:05 +00:00
|
|
|
*/
|
2023-03-22 01:11:58 +00:00
|
|
|
reg [3:0] Timer = 0;
|
2023-04-10 08:08:23 +00:00
|
|
|
reg TimerTC;
|
2023-03-26 08:33:59 +00:00
|
|
|
always @(posedge CLK) begin
|
|
|
|
if (EFall) begin
|
2023-03-25 07:50:31 +00:00
|
|
|
if (TimerTC) Timer <= 0;
|
|
|
|
else Timer <= Timer+1;
|
2023-07-16 03:21:44 +00:00
|
|
|
RefUrg <= Timer==8 || Timer==9;
|
|
|
|
RefReq <= Timer!=10;
|
2023-04-10 08:08:23 +00:00
|
|
|
TimerTC <= Timer==9;
|
2023-03-25 07:50:31 +00:00
|
|
|
end
|
2021-10-29 10:04:59 +00:00
|
|
|
end
|
2023-07-16 03:21:44 +00:00
|
|
|
|
|
|
|
/* During init (IS!=3) long timer counts from 0 to 4095.
|
|
|
|
* 4096 states == 57.516 ms
|
|
|
|
* During operation (IS==3) long timer counts from 0 to 3
|
|
|
|
* starting at first sound RAM access.
|
|
|
|
* Period is 28.124 us - 42.240 us */
|
2023-04-09 08:19:06 +00:00
|
|
|
reg [11:0] LTimer;
|
2023-03-26 08:33:59 +00:00
|
|
|
reg LTimerTC;
|
2023-07-16 03:21:43 +00:00
|
|
|
always @(posedge CLK) begin
|
2023-09-28 06:46:30 +00:00
|
|
|
if (EFall && TimerTC) begin
|
|
|
|
LTimer <= LTimer+1;
|
|
|
|
LTimerTC <= LTimer[11:0]==12'hFFE;
|
|
|
|
end
|
2023-07-16 03:21:43 +00:00
|
|
|
end
|
2023-07-16 06:25:27 +00:00
|
|
|
|
2023-09-28 06:46:30 +00:00
|
|
|
/* Sound QoS trigger */
|
|
|
|
reg [1:0] QS;
|
|
|
|
wire QoSEN = QS!=0;
|
2023-04-08 09:46:13 +00:00
|
|
|
always @(posedge CLK) begin
|
2023-09-28 06:46:30 +00:00
|
|
|
if (BACT && SndRAMCSWR) QS[1:0] <= 1;
|
|
|
|
else if (QS==0) QS[1:0] <= 0;
|
|
|
|
else if (EFall && TimerTC) QS[1:0] <= QS+1;
|
|
|
|
end
|
|
|
|
|
2023-07-16 06:25:27 +00:00
|
|
|
/* Sound QoS */
|
2023-09-28 06:46:30 +00:00
|
|
|
reg [4:0] Wait = 0;
|
2023-07-16 06:25:27 +00:00
|
|
|
always @(posedge CLK) begin
|
2023-09-28 06:46:30 +00:00
|
|
|
if (!BACT) Wait <= 0;
|
|
|
|
else Wait <= Wait+1;
|
|
|
|
if (!BACT || !QoSReady) QoSReady <= !QoSEN || (Wait==16);
|
2023-04-08 09:46:13 +00:00
|
|
|
end
|
|
|
|
|
2023-04-08 09:49:29 +00:00
|
|
|
/* Startup sequence state control */
|
2023-04-08 09:46:13 +00:00
|
|
|
wire ISTC = EFall && TimerTC && LTimerTC;
|
2023-03-26 08:33:59 +00:00
|
|
|
always @(posedge CLK) begin
|
2023-04-08 09:46:13 +00:00
|
|
|
case (IS[1:0])
|
2023-04-10 02:47:27 +00:00
|
|
|
0: begin
|
2023-03-20 04:53:10 +00:00
|
|
|
AoutOE <= 0; // Tristate PDS address and control
|
|
|
|
nRESout <= 0; // Hold reset low
|
2023-03-22 01:11:58 +00:00
|
|
|
nBR_IOB <= 0; // Default to request bus
|
2023-04-08 09:46:13 +00:00
|
|
|
if (ISTC) IS <= 1;
|
2023-04-10 02:47:27 +00:00
|
|
|
end 1: begin
|
2023-03-26 08:33:59 +00:00
|
|
|
AoutOE <= 0;
|
|
|
|
nRESout <= 0;
|
|
|
|
nBR_IOB <= !(!nBR_IOB && nIPL2r); // Disable bus request if NMI pressed
|
2023-04-08 09:46:13 +00:00
|
|
|
if (ISTC && nIPL2r) IS <= 2;
|
2023-04-10 02:47:27 +00:00
|
|
|
end 2: begin
|
2023-03-26 08:33:59 +00:00
|
|
|
AoutOE <= !nBR_IOB;
|
|
|
|
nRESout <= 0;
|
2023-04-08 09:46:13 +00:00
|
|
|
if (ISTC) IS <= 3;
|
2023-04-10 02:47:27 +00:00
|
|
|
end 3: begin
|
2023-03-25 07:50:31 +00:00
|
|
|
nRESout <= 1; // Release reset
|
2023-04-08 09:46:13 +00:00
|
|
|
IS <= 3;
|
2022-09-04 01:32:05 +00:00
|
|
|
end
|
2022-09-11 21:15:53 +00:00
|
|
|
endcase
|
|
|
|
end
|
2023-07-16 03:21:44 +00:00
|
|
|
|
2021-10-29 10:04:59 +00:00
|
|
|
endmodule
|