OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [host/] [zxspectrum_de1/] [zxspectrum_de1.sv] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 gdevic
//============================================================================
2
// Sinclair ZX Spectrum host board
3
//
4
//  Copyright (C) 2014-2016  Goran Devic
5
//
6
//  This program is free software; you can redistribute it and/or modify it
7
//  under the terms of the GNU General Public License as published by the Free
8
//  Software Foundation; either version 2 of the License, or (at your option)
9
//  any later version.
10
//
11
//  This program is distributed in the hope that it will be useful, but WITHOUT
12
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
//  more details.
15
//
16
//  You should have received a copy of the GNU General Public License along
17
//  with this program; if not, write to the Free Software Foundation, Inc.,
18
//  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
//============================================================================
20
module zxspectrum_board
21
(
22
    //-------- Clocks and reset -----------------
23
    input wire CLOCK_27,            // Input clock 27 MHz
24
    input wire CLOCK_24,            // Input clock 24 MHz
25
    input wire KEY0,                // RESET button
26
    input wire KEY1,                // NMI button
27
 
28
    //-------- PS/2 Keyboard --------------------
29
    input wire PS2_CLK,
30
    input wire PS2_DAT,
31
 
32
    //-------- Audio (Tape player) --------------
33
    inout wire I2C_SCLK,
34
    inout wire I2C_SDAT,
35
    output wire AUD_XCK,
36
    output wire AUD_ADCLRCK,
37
    output wire AUD_DACLRCK,
38
    output wire AUD_BCLK,
39
    output wire AUD_DACDAT,
40
    input wire AUD_ADCDAT,
41
 
42
    //-------- VGA connector --------------------
43
    output wire [3:0] VGA_R,
44
    output wire [3:0] VGA_G,
45
    output wire [3:0] VGA_B,
46
    output reg VGA_HS,
47
    output reg VGA_VS,
48
 
49
    //-------- Flash memory interface -----------
50
    output wire [21:0] FL_ADDR,
51
    input wire [7:0] FL_DQ,
52
    output wire FL_CE_N,
53
    output wire FL_OE_N,
54
    output wire FL_WE_N,
55
    output wire FL_RST_N,
56
 
57
    //-------- SRAM memory interface ------------
58
    output wire [17:0] SRAM_ADDR,
59
    inout reg [15:0] SRAM_DQ,
60
    output wire SRAM_CE_N,
61
    output wire SRAM_OE_N,
62
    output wire SRAM_WE_N,
63
    output wire SRAM_UB_N,
64
    output wire SRAM_LB_N,
65
 
66
    //-------- My little imitation of a Kempston joystick -----------
67
    input wire [5:0] kempston,
68
    output wire [4:0] LEDG,         // Show the joystick state
69
 
70
    //-------- Misc and debug -------------------
71
    input wire SW0,                 // ROM selection
72
    input wire SW1,                 // Enable/disable interrupts
73
    input wire SW2,                 // Turbo speed (3.5 MHz x 2 = 7.0 MHz)
74
    output wire [2:0] LEDR,         // Shows the switch selection
75
    output wire [31:0] GPIO_1,      // Exports CPU chip pins
76
    output wire [2:0] LEDGTOP       // Show additional information visually
77
);
78
`default_nettype none
79
 
80
wire reset;
81
wire locked;
82
assign reset = locked & KEY0;
83
 
84
// Export selected pins to the extension connector
85
assign GPIO_1[15:0] = A[15:0];
86
assign GPIO_1[23:16] = D[7:0];
87
assign GPIO_1[31:24] = {nM1,nMREQ,nIORQ,nRD,nWR,nRFSH,nHALT,nBUSACK};
88
 
89
// Top 3 green LEDs show various states:
90
assign LEDGTOP[2] = 0;              // Reserved for future use
91
assign LEDGTOP[1] = beeper;         // Show the beeper state
92
assign LEDGTOP[0] = pressed;        // Show when a key is being pressed
93
 
94
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
// Internal buses and address map selection logic
96
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97
wire [15:0] A;                  // Global address bus
98
wire [7:0] D;                   // CPU data bus
99
 
100
wire [7:0] ram_data;            // Internal 16K RAM data
101
wire RamWE;
102
assign RamWE = A[15:14]==2'b01 && nIORQ==1 && nRD==1 && nWR==0;
103
 
104
wire ExtRamWE;                  // Extended (and external) 32K RAM
105
assign ExtRamWE = A[15]==1 && nIORQ==1 && nRD==1 && nWR==0;
106
assign SRAM_DQ[15:0] = ExtRamWE? {8'b0,D[7:0]} : {16{1'bz}};
107
 
108
wire [7:0] ula_data;            // ULA
109
wire io_we;
110
assign io_we = nIORQ==0 && nRD==1 && nWR==0;
111
 
112
// Memory map:
113
//   0000 - 3FFF  16K ROM (mapped to the external Flash memory)
114
//   4000 - 7FFF  16K dual-port RAM
115
//   8000 - FFFF  32K RAM (mapped to the external SRAM memory)
116
always @(*) // always_comb
117
begin
118
    case ({nIORQ,nRD,nWR})
119
        // -------------------------------- Memory read --------------------------------
120
        3'b101: begin
121
                casez (A[15:14])
122
                    2'b00:  D[7:0] = FL_DQ;
123
                    2'b01:  D[7:0] = ram_data;
124
                    2'b1?:  D[7:0] = SRAM_DQ[7:0];
125
                endcase
126
            end
127
        // ---------------------------------- IO read ----------------------------------
128
        3'b001: begin
129
                // Normally data supplied by the ULA
130
                D[7:0] = ula_data;
131
 
132
                // Kempston joystick at the IO address of 0x1F: active bits are high: 000FUDLR
133
                // The bits are scrambled since I just happen to solder them that way on a game
134
                // pad I've got (see my blog); you can remap it if you have another kind of joystick
135
                if (A[7:0]==8'h1F) begin
136
                    D[7:0] = { 3'b0, !kempston[3],!kempston[5],!kempston[4],!kempston[0],!kempston[2] };
137
                end
138
            end
139
    default:
140
        D[7:0] = {8{1'bz}};
141
    endcase
142
end
143
 
144
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145
// 16K of the original ZX Spectrum ROM is in the flash at the address 0
146
// 16K of The GOSH WONDERFUL ZX Spectrum ROM is in the flash following it
147
//    http://www.wearmouth.demon.co.uk/gw03/gw03info.htm
148
// SW0 selectes which ROM is going to be used by feeding the address bit 14
149
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
assign FL_ADDR[13:0] = A[13:0];
151
assign FL_ADDR[14] = SW0;
152
assign LEDR[0] = SW0;           // Glow red when using alternate ROM
153
assign FL_ADDR[21:15] = 0;
154
assign FL_RST_N = KEY0;
155
assign FL_CE_N = 0;
156
assign FL_OE_N = 0;
157
assign FL_WE_N = 1;
158
 
159
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160
// Instantiate 16K dual-port RAM
161
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162
wire clk_vram;
163
// "A" port is the CPU side, "B" port is the VGA image generator in the ULA
164
ram16 ram16_(
165
    .clock      (clk_vram),     // RAM connects to the higher, pixel clock rate
166
 
167
    .address_a  (A[13:0]),      // Address in to the RAM from the CPU side
168
    .data_a     (D),            // Data in to the RAM from the CPU side
169
    .q_a        (ram_data),     // Data out from the RAM into the data bus selector
170
    .wren_a     (RamWE),
171
 
172
    .address_b  ({1'b0, vram_address}),
173
    .data_b     (8'b0),
174
    .q_b        (vram_data),
175
    .wren_b     ('0));
176
 
177
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178
// 32K of ZX Spectrum extended RAM is using the external SRAM memory
179
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
assign SRAM_ADDR[14:0] = A[14:0];
181
assign SRAM_ADDR[17:15] = 0;
182
assign SRAM_CE_N = 0;
183
assign SRAM_OE_N = 0;
184
assign SRAM_WE_N = !ExtRamWE;
185
assign SRAM_UB_N = 1;
186
assign SRAM_LB_N = 0;
187
 
188
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189
// Instantiate ULA
190
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
wire clk_cpu;                   // Global CPU clock of 3.5 MHz
192
assign LEDR[2] = SW2;           // Glow red when in turbo mode (7.0 MHz)
193
wire [12:0] vram_address;       // ULA video block requests a byte from the video RAM
194
wire [7:0] vram_data;           // ULA video block reads a byte from the video RAM
195
wire vs_nintr;                  // Generates a vertical retrace interrupt
196
wire pressed;                   // Show that a key is being pressed
197
wire beeper;                    // Show the beeper state
198
 
199
ula ula_(
200
    //-------- Clocks and reset -----------------
201
    .CLOCK_27 (CLOCK_27),       // Input clock 27 MHz
202
    .CLOCK_24 (CLOCK_24),       // Input clock 24 MHz
203
    .turbo (SW2),               // Turbo speed (3.5 MHz x 2 = 7.0 MHz)
204
    .clk_vram (clk_vram),
205
    .reset (reset),             // KEY0 is reset
206
    .locked (locked),           // PLL is locked signal
207
 
208
    //-------- CPU control ----------------------
209
    .clk_cpu (clk_cpu),         // Generates CPU clock of 3.5 MHz
210
    .vs_nintr (vs_nintr),       // Generates a vertical retrace interrupt
211
 
212
    //-------- Address and data buses -----------
213
    .A (A),                     // Input address bus
214
    .D (D),                     // Input data bus
215
    .ula_data (ula_data),       // Output data
216
    .io_we (io_we),             // Write enable to data register through IO
217
 
218
    .vram_address (vram_address),// ULA video block requests a byte from the video RAM
219
    .vram_data (vram_data),     // ULA video block reads a byte from the video RAM
220
 
221
    //-------- PS/2 Keyboard --------------------
222
    .PS2_CLK (PS2_CLK),
223
    .PS2_DAT (PS2_DAT),
224
    .pressed (pressed),
225
 
226
    //-------- Audio (Tape player) --------------
227
    .I2C_SCLK (I2C_SCLK),
228
    .I2C_SDAT (I2C_SDAT),
229
    .AUD_XCK (AUD_XCK),
230
    .AUD_ADCLRCK (AUD_ADCLRCK),
231
    .AUD_DACLRCK (AUD_DACLRCK),
232
    .AUD_BCLK (AUD_BCLK),
233
    .AUD_DACDAT (AUD_DACDAT),
234
    .AUD_ADCDAT (AUD_ADCDAT),
235
    .beeper (beeper),
236
 
237
    //-------- VGA connector --------------------
238
    .VGA_R (VGA_R),
239
    .VGA_G (VGA_G),
240
    .VGA_B (VGA_B),
241
    .VGA_HS (VGA_HS),
242
    .VGA_VS (VGA_VS)
243
);
244
 
245
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246
// Instantiate A-Z80 CPU
247
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248
wire nM1;
249
wire nMREQ;
250
wire nIORQ;
251
wire nRD;
252
wire nWR;
253
wire nRFSH;
254
wire nHALT;
255
wire nBUSACK;
256
 
257
wire nWAIT = 1;
258
wire nINT = (SW1==0)? vs_nintr : '1;// SW1 disables interrupts and, hence, keyboard
259
assign LEDR[1] = SW1;               // Glow red when interrupts are *disabled*
260
wire nNMI = KEY1;                   // Pressing KEY1 issues a NMI
261
wire nBUSRQ = 1;
262
 
263
z80_top_direct_n z80_(
264
    .nM1 (nM1),
265
    .nMREQ (nMREQ),
266
    .nIORQ (nIORQ),
267
    .nRD (nRD),
268
    .nWR (nWR),
269
    .nRFSH (nRFSH),
270
    .nHALT (nHALT),
271
    .nBUSACK (nBUSACK),
272
 
273
    .nWAIT (nWAIT),
274
    .nINT (nINT),
275
    .nNMI (nNMI),
276
    .nRESET (reset),
277
    .nBUSRQ (nBUSRQ),
278
 
279
    .CLK (clk_cpu),
280
    .A (A),
281
    .D (D)
282
);
283
 
284
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
// Lit green LEDs to show activity on a Kempston compatible joystick
286
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287
assign LEDG[0] = !kempston[5];                  // UP
288
assign LEDG[1] = !kempston[4];                  // DOWN
289
assign LEDG[2] = !kempston[0];                  // LEFT
290
assign LEDG[3] = !kempston[2];                  // RIGHT
291
assign LEDG[4] = !kempston[3] | !kempston[1];   // BUTTON
292
 
293
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.