-
Notifications
You must be signed in to change notification settings - Fork 2
/
zx48.sv
312 lines (241 loc) · 6.31 KB
/
zx48.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
module zx48_top
(
//Master input clock
input CLOCK_27,
output [5:0] VGA_R,
output [5:0] VGA_G,
output [5:0] VGA_B,
output VGA_HS,
output VGA_VS,
output LED, // 1 - ON, 0 - OFF.
output AUDIO_L,
output AUDIO_R,
//SDRAM interface with lower latency
output SDRAM_CLK,
output SDRAM_CKE,
output [12:0] SDRAM_A,
output [1:0] SDRAM_BA,
inout [15:0] SDRAM_DQ,
output SDRAM_DQML,
output SDRAM_DQMH,
output SDRAM_nCS,
output SDRAM_nCAS,
output SDRAM_nRAS,
output SDRAM_nWE,
input SPI_SCK,
output SPI_DO,
input SPI_DI,
input SPI_SS2,
input SPI_SS3,
input CONF_DATA0,
input UART_RX,
output UART_TX,
output [9:0] DAC_L,
output [9:0] DAC_R
);
`include "build_id.v"
localparam CONF_STR =
{
"zx48;;",
"S0,VHD,Mount virtual SD;",
"O1,Model,48K,+2;",
"O2,DivMMC automapper,Enabled,Disabled;",
"T0,Reset;",
"V,v1.2 ",`BUILD_DATE
};
wire [ 1:0] buttons;
wire [31:0] status;
wire [10:0] ps2_key;
wire [15:0] joystick_0;
wire [15:0] joystick_1;
wire [31:0] sd_lba;
wire [ 8:0] sd_buff_addr;
wire [ 7:0] sd_buff_dout;
wire [ 7:0] sd_buff_din;
wire sd_rd;
wire sd_wr;
wire sd_ack;
wire sd_ack_conf;
wire sd_buff_wr;
wire sdclk;
wire sdss;
wire sdmosi;
wire sdmiso;
wire vsdmiso;
wire [63:0] img_size;
wire img_mounted;
wire img_readonly;
wire[26:0] ioctl_addr;
wire[ 7:0] ioctl_dout;
wire ioctl_download;
wire ioctl_wr;
wire forced_scandoubler;
mist_io #(.STRLEN($size(CONF_STR)>>3)) mist_io
(
.clk_sys (clk_sys),
.conf_str (CONF_STR),
.SPI_SCK (SPI_SCK),
.CONF_DATA0 (CONF_DATA0),
.SPI_SS2 (SPI_SS2),
.SPI_DO (SPI_DO),
.SPI_DI (SPI_DI),
.status (status),
.ps2_key (ps2_key),
.joystick_0 (joystick_0),
.joystick_1 (joystick_1),
.sd_lba (sd_lba),
.sd_rd (sd_rd),
.sd_wr (sd_wr),
.sd_ack (sd_ack),
.sd_ack_conf (sd_ack_conf),
.sd_buff_addr (sd_buff_addr),
.sd_buff_dout (sd_buff_dout),
.sd_buff_din (sd_buff_din),
.sd_buff_wr (sd_buff_wr),
.img_mounted (img_mounted),
//.img_readonly(img_readonly),
.img_size (img_size),
.ioctl_download(ioctl_download),
.ioctl_wr (ioctl_wr ),
.ioctl_addr (ioctl_addr ),
.ioctl_dout (ioctl_dout ),
.buttons (buttons),
.scandoubler_disable(forced_scandoubler)
);
//-------------------------------------------------------------------------------------------------
assign sdmiso = vsd_sel ? vsdmiso : SD_MISO;
reg vsd_sel = 0;
always @(posedge clk_sys) if(img_mounted) vsd_sel <= |img_size;
sd_card sd_card
(
.clk_sys(clk_sys),
.reset(~reset),
.sdhc(1),
.sd_lba(sd_lba),
.sd_rd(sd_rd),
.sd_wr(sd_wr),
.sd_ack(sd_ack),
.sd_ack_conf(sd_ack_conf),
.sd_buff_addr(sd_buff_addr),
.sd_buff_dout(sd_buff_dout),
.sd_buff_din(sd_buff_din),
.sd_buff_wr(sd_buff_wr),
.clk_spi(clk_sys),
.sck(sdclk),
.ss(sdss | ~vsd_sel),
.mosi(sdmosi),
.miso(vsdmiso)
);
wire SD_CS;
wire SD_SCK;
wire SD_MOSI;
wire SD_MISO;
assign SD_CS = sdss | vsd_sel;
assign SD_SCK = sdclk & ~vsd_sel;
assign SD_MOSI = sdmosi & ~vsd_sel;
reg sd_act;
always @(posedge clk_sys) begin
reg old_mosi, old_miso;
integer timeout = 0;
old_mosi <= sdmosi;
old_miso <= sdmiso;
sd_act <= 0;
if(timeout < 1000000) begin
timeout <= timeout + 1;
sd_act <= 1;
end
if((old_mosi ^ sdmosi) || (old_miso ^ sdmiso)) timeout <= 0;
end
//-------------------------------------------------------------------------------------------------
wire clk_sys,clk_sd;
wire locked;
pll pll
(
.inclk0 (CLOCK_27),
.areset (0 ),
.locked (locked ),
.c0 (clk_sys), // 56 MHz
.c1 (clk_sd ) // 14 MHz
);
//-------------------------------------------------------------------------------------------------
reg ps2k10d, kstrobe;
always @(posedge clk_sys) begin ps2k10d <= ps2_key[10]; kstrobe <= ps2k10d != ps2_key[10]; end
wire reset = ~(status[0] | buttons[1] | ioctl_download);
wire model = status[1];
wire nomap = status[2];
wire[ 1:0] blank;
wire[ 1:0] sync;
wire[23:0] rgb;
wire ear = ~UART_RX;
wire[9:0] laudio;
wire[9:0] raudio;
wire kpress = ~ps2_key[9];
wire[7:0] kcode = ps2_key[7:0];
wire[1:0] kleds;
wire[5:0] jstick = joystick_0[5:0]; // | joystick_1[5:0]) : 6'd0;
wire iniBusy = ioctl_download;
wire iniWr = ioctl_wr;
wire[ 7:0] iniD = ioctl_dout;
wire[15:0] iniA = ioctl_addr[15:0];
zx48 ZX48
(
.clock (clk_sys),
.reset (reset ),
.model (model ),
.nomap (nomap ),
.locked (locked ),
.blank (blank ),
.sync (sync ),
.rgb (rgb ),
.pce (ce_pix ),
.ear (ear ),
.laudio (laudio ),
.raudio (raudio ),
.kstrobe(kstrobe),
.kpress (kpress ),
.kcode (kcode ),
.kleds (kleds ),
.jstick (jstick ),
.usdCk (sdclk ),
.usdCs (sdss ),
.usdMiso(sdmiso ),
.usdMosi(sdmosi ),
.iniBusy(iniBusy),
.iniWr (iniWr ),
.iniD (iniD ),
.iniA (iniA )
);
//-------------------------------------------------------------------------------------------------
wire ce_pix;
video_mixer #(.LINE_LENGTH(720)) video_mixer
(
.*,
.ce_pix(ce_pix),
.ce_pix_actual(ce_pix),
.scandoubler_disable(forced_scandoubler),
.hq2x(),
.mono(0),
.scanlines(),
.ypbpr(),
.ypbpr_full(0),
.line_start(0),
.R(rgb[23:18]),
.G(rgb[15:10]),
.B(rgb[7:2]),
.HSync(sync[0]),
.VSync(sync[1]),
.HBlank(blank[0]),
.VBlank(blank[1])
);
//assign VGA_DE = ~|blank;
//assign VGA_HS = sync[0];
//assign VGA_VS = sync[1];
//assign VGA_R = rgb[23:16];
//assign VGA_G = rgb[15: 8];
//assign VGA_B = rgb[ 7: 0];
assign LED = vsd_sel & sd_act;
assign DAC_L = { 2'd0, laudio, 4'd0 };
assign DAC_R = { 2'd0, raudio, 4'd0 };
//-------------------------------------------------------------------------------------------------
endmodule
//-------------------------------------------------------------------------------------------------