Rev 668 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 668 | Rev 684 | ||
|---|---|---|---|
| Line 45... | Line 45... | ||
| 45 | 45 | ||
| 46 | `include "../include/tune.v" |
46 | `include "../include/tune.v" |
| 47 | 47 | ||
| 48 | module zclock( |
48 | module zclock( |
| 49 | 49 | ||
| 50 | input fclk, |
50 | input wire fclk, |
| 51 | input rst_n, |
51 | input wire rst_n, |
| 52 | 52 | ||
| 53 | input zclk, // Z80 clock, buffered via act04 and returned back to the FPGA |
53 | input wire zclk, // Z80 clock, buffered via act04 and returned back to the FPGA |
| 54 | 54 | ||
| - | 55 | input wire [15:0] a, // for contention |
|
| - | 56 | ||
| - | 57 | input wire [ 1:0] modes_raster, |
|
| - | 58 | input wire mode_contend_type, |
|
| - | 59 | input wire mode_contend_ena, |
|
| - | 60 | input wire [ 2:0] mode_7ffd_bits, // low 3 bits of 7FFD for 128k contention |
|
| - | 61 | ||
| - | 62 | input wire contend, |
|
| - | 63 | ||
| - | 64 | input wire mreq_n, |
|
| - | 65 | input wire iorq_n, |
|
| - | 66 | input wire m1_n, |
|
| 55 | input rfsh_n, // switch turbo modes in RFSH part of m1 |
67 | input wire rfsh_n, // switch turbo modes in RFSH part of m1 |
| 56 | 68 | ||
| 57 | 69 | ||
| 58 | output reg zclk_out, // generated Z80 clock - passed through inverter externally! |
70 | output reg zclk_out, // generated Z80 clock - passed through inverter externally! |
| 59 | 71 | ||
| 60 | output reg zpos, |
72 | output reg zpos, |
| Line 64... | Line 76... | ||
| 64 | input wire zclk_stall, |
76 | input wire zclk_stall, |
| 65 | 77 | ||
| 66 | 78 | ||
| 67 | 79 | ||
| 68 | 80 | ||
| 69 | input [1:0] turbo, // 2'b00 - 3.5 MHz |
81 | input wire [ 1:0] turbo, // 2'b00 - 3.5 MHz |
| 70 | // 2'b01 - 7.0 MHz |
82 | // 2'b01 - 7.0 MHz |
| 71 | // 2'b1x - 14.0 MHz |
83 | // 2'b1x - 14.0 MHz |
| 72 | 84 | ||
| 73 | output reg [1:0] int_turbo, // internal turbo, switched on /RFSH |
85 | output reg [ 1:0] int_turbo, // internal turbo, switched on /RFSH |
| 74 | 86 | ||
| 75 | 87 | ||
| 76 | // input signals for 14MHz external IORQ waits |
88 | // input signals for 14MHz external IORQ waits |
| 77 | input wire external_port, |
89 | input wire external_port, |
| 78 | input wire iorq_n, |
- | |
| 79 | input wire m1_n, |
- | |
| 80 | 90 | ||
| 81 | 91 | ||
| 82 | input cbeg, |
92 | input wire cbeg, |
| 83 | input pre_cend // syncing signals, taken from arbiter.v and dram.v |
93 | input wire pre_cend // syncing signals, taken from arbiter.v and dram.v |
| 84 | ); |
94 | ); |
| 85 | 95 | ||
| 86 | 96 | ||
| 87 | reg precend_cnt; |
97 | reg precend_cnt; |
| 88 | wire h_precend_1; // to take every other pulse of pre_cend |
98 | wire h_precend_1; // to take every other pulse of pre_cend |
| 89 | wire h_precend_2; // to take every other pulse of pre_cend |
99 | wire h_precend_2; // to take every other pulse of pre_cend |
| 90 | 100 | ||
| 91 | reg [2:0] zcount; // counter for generating 3.5 and 7 MHz z80 clocks |
101 | reg [2:0] zcount; // counter for generating 3.5 and 7 MHz z80 clocks |
| 92 | 102 | ||
| 93 | - | ||
| 94 | reg old_rfsh_n; |
103 | reg old_rfsh_n; |
| 95 | 104 | ||
| 96 | - | ||
| 97 | wire stall; |
105 | wire stall; |
| 98 | 106 | ||
| 99 | - | ||
| 100 | reg clk14_src; // source for 14MHz clock |
107 | reg clk14_src; // source for 14MHz clock |
| 101 | 108 | ||
| 102 | - | ||
| 103 | - | ||
| 104 | - | ||
| 105 | - | ||
| 106 | wire pre_zpos_35, |
109 | wire pre_zpos_35, |
| 107 | pre_zneg_35; |
110 | pre_zneg_35; |
| 108 | 111 | ||
| 109 | wire pre_zpos_70, |
112 | wire pre_zpos_70, |
| 110 | pre_zneg_70; |
113 | pre_zneg_70; |
| 111 | 114 | ||
| 112 | wire pre_zpos_140, |
115 | wire pre_zpos_140, |
| 113 | pre_zneg_140; |
116 | pre_zneg_140; |
| 114 | 117 | ||
| 115 | 118 | ||
| - | 119 | reg r_mreq_n; |
|
| - | 120 | wire iorq_n_a; |
|
| - | 121 | reg r_iorq_n_a; |
|
| - | 122 | wire contend_wait; |
|
| - | 123 | wire contend_mem; |
|
| - | 124 | wire contend_io; |
|
| - | 125 | wire contend_addr; |
|
| - | 126 | ||
| - | 127 | reg [2:0] p7ffd; // resync to 14MHz |
|
| 116 | 128 | ||
| 117 | 129 | ||
| 118 | `ifdef SIMULATE |
130 | `ifdef SIMULATE |
| 119 | initial // simulation... |
131 | initial // simulation... |
| 120 | begin |
132 | begin |
| Line 135... | Line 147... | ||
| 135 | if( old_rfsh_n && !rfsh_n ) |
147 | if( old_rfsh_n && !rfsh_n ) |
| 136 | int_turbo <= turbo; |
148 | int_turbo <= turbo; |
| 137 | end |
149 | end |
| 138 | 150 | ||
| 139 | 151 | ||
| - | 152 | // resync p7ffd |
|
| - | 153 | always @(posedge fclk) |
|
| - | 154 | p7ffd <= mode_7ffd_bits; |
|
| - | 155 | ||
| 140 | 156 | ||
| 141 | 157 | ||
| 142 | // make 14MHz iorq wait |
158 | // make 14MHz iorq wait |
| 143 | reg [3:0] io_wait_cnt; |
159 | reg [3:0] io_wait_cnt; |
| 144 | 160 | ||
| Line 175... | Line 191... | ||
| 175 | endcase |
191 | endcase |
| 176 | 192 | ||
| 177 | 193 | ||
| 178 | 194 | ||
| 179 | 195 | ||
| 180 | assign stall = zclk_stall | io_wait; |
196 | assign stall = zclk_stall | io_wait | contend_wait; |
| 181 | 197 | ||
| 182 | 198 | ||
| 183 | 199 | ||
| 184 | // 14MHz clocking |
200 | // 14MHz clocking |
| 185 | always @(posedge fclk) |
201 | always @(posedge fclk) |
| Line 241... | Line 257... | ||
| 241 | if( zneg ) |
257 | if( zneg ) |
| 242 | zclk_out <= 1'b1; |
258 | zclk_out <= 1'b1; |
| 243 | end |
259 | end |
| 244 | 260 | ||
| 245 | 261 | ||
| - | 262 | ||
| - | 263 | ||
| - | 264 | ||
| - | 265 | // contention emulation -- only 48k by now, TODO 128k pages and +2a/+3! |
|
| - | 266 | // |
|
| - | 267 | assign iorq_n_a = iorq_n || (a[0]==1'b1); |
|
| - | 268 | // |
|
| - | 269 | always @(posedge fclk) |
|
| - | 270 | if( zpos ) |
|
| - | 271 | begin |
|
| - | 272 | r_mreq_n <= mreq_n; |
|
| - | 273 | r_iorq_n_a <= iorq_n_a; |
|
| - | 274 | end |
|
| - | 275 | // |
|
| - | 276 | assign contend_addr = (modes_raster[0]==1'b0) ? ( a[15:14]==2'b01 ) : // 48k mode |
|
| - | 277 | ( a[15:14]==2'b01 || (a[15:14]==2'b11 && p7ffd[0]) ) ; // 128k mode (yet only 128/+2) |
|
| - | 278 | // |
|
| - | 279 | assign contend_mem = contend_addr && r_mreq_n; |
|
| - | 280 | assign contend_io = !iorq_n_a && r_iorq_n_a; |
|
| - | 281 | // |
|
| - | 282 | assign contend_wait = contend && (contend_mem || contend_io) && !int_turbo && modes_raster[1] && mode_contend_ena; |
|
| - | 283 | // |
|
| - | 284 | // TODO: contend is 28MHz signal, while we'd better have here |
|
| - | 285 | // 3.5MHz-synced r_contend signal, which should be synced |
|
| - | 286 | // to free-running 3.5MHz zpos/zneg sequence (not affected by stall) |
|
| - | 287 | ||
| 246 | endmodule |
288 | endmodule |
| 247 | 289 | ||