OpenCores
URL https://opencores.org/ocsvn/z80soc/z80soc/trunk

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7/] [DE1/] [vhdl/] [top_de1.vhd] - Blame information for rev 34

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 rrred
-------------------------------------------------------------------------------------------------
2
-- Z80_Soc (Z80 System on Chip)
3
--
4
-- Version history:
5
-------------------
6
-- version 0.6 for for Altera DE1
7
-- Release Date: 2008 / 05 / 21
8
--
9
-- Version 0.5 Beta for Altera DE1
10
-- Developer: Ronivon Candido Costa
11
-- Release Date: 2008 / 04 / 16
12
--
13
-- Based on the T80 core: http://www.opencores.org/projects.cgi/web/t80
14
-- This version developed and tested on: Altera DE1 Development Board
15
--
16
-- Peripherals configured (Using Ports):
17
--
18
--      16 KB Internal ROM      Read            (0x0000h - 0x3FFFh)
19
--      08 KB INTERNAL VRAM     Write           (0x4000h - 0x5FFFh)
20
--      32 KB External SRAM     Read/Write      (0x8000h - 0xFFFFh)
21
--      08 Green Leds           Out             (Port 0x01h)
22
--      08 Red Leds                     Out             (Port 0x02h)
23
--      04 Seven Seg displays   Out             (Ports 0x11h and 0x10h)
24
--      36 Pins GPIO0           In/Out  (Ports 0xA0h, 0xA1h, 0xA2h, 0xA3h, 0xA4h, 0xC0h)
25
--      36 Pins GPIO1           In/Out  (Ports 0xB0h, 0xB1h, 0xB2h, 0xB3h, 0xB4h, 0xC1h)
26
--      08 Switches                     In              (Port 0x20h)
27
--      04 Push buttons         In              (Port 0x30h)
28
--      01 PS/2 keyboard                In              (Port 0x80h)
29
--      01 Video write port     In              (Port 0x90h)
30
--
31
--  Revision history:
32
--
33
-- 2008/05/23 - Modified RAM layout to support new and future improvements
34
--            - Added port 0x90 to write a character to video.
35
--            - Cursor x,y automatically updated after writing to port 0x90
36
--            - Added port 0x91 for video cursor X
37
--            - Added port 0x92 for video cursor Y
38
--                - Updated ROM to demonstrate how to use these new resources
39
--            - Changed ROM to support 14 bit addresses (16 Kb)
40
--
41
-- 2008/05/12 - Added support for the Rotary Knob
42
--            - ROT_CENTER push button (Knob) reserved for RESET
43
--            - The four push buttons are now available for the user (Port 0x30)
44
--
45
-- 2008/05/11 - Fixed access to RAM and VRAM,
46
--              Released same ROM version for DE1 and S3E
47
--
48
-- 2008/05/01 - Added LCD support for Spartan 3E
49
--
50
-- 2008/04(21 - Release of Version 0.5-S3E-Beta for Diligent Spartan 3E
51
--
52
--      2008/04/17 - Added Video support for 40x30 mode
53
--
54
-- 2008/04/16 - Release of Version 0.5-DE1-Beta for Altera DE1
55
--
56
-- TO-DO:
57
-- - Implement hardware control for the A/D and IO pins
58
-- - Monitor program to introduce Z80 Assmebly codes and run
59
-- - Serial communication, to download assembly code from PC
60
-- - Add hardware support for 80x40 Video out
61
-- - SD/MMC card interface to read/store data and programs
62
-------------------------------------------------------------------------------------------------
63
 
64
library IEEE;
65
use IEEE.std_logic_1164.all;
66
use IEEE.std_logic_arith.all;
67
use IEEE.std_logic_unsigned.all;
68
 
69
entity  TOP_DE1 is
70
        port(
71
 
72
    -- Clocks
73
    CLOCK_27,                                      -- 27 MHz
74
    CLOCK_50,                                      -- 50 MHz
75
    EXT_CLOCK : in std_logic;                      -- External Clock
76
 
77
    -- Buttons and switches
78
    KEY : in std_logic_vector(3 downto 0);         -- Push buttons
79
    SW : in std_logic_vector(9 downto 0);          -- Switches
80
 
81
    -- LED displays
82
    HEX0, HEX1, HEX2, HEX3                         -- 7-segment displays
83
                        : out std_logic_vector(6 downto 0);
84
    LEDG : out std_logic_vector(7 downto 0);       -- Green LEDs
85
    LEDR : out std_logic_vector(9 downto 0);       -- Red LEDs
86
 
87
    -- RS-232 interface
88
    UART_TXD : out std_logic;                      -- UART transmitter   
89
    UART_RXD : in std_logic;                       -- UART receiver
90
 
91
    -- IRDA interface
92
 
93
    -- IRDA_TXD : out std_logic;                      -- IRDA Transmitter
94
    IRDA_RXD : in std_logic;                       -- IRDA Receiver
95
 
96
    -- SDRAM
97
    DRAM_DQ : inout std_logic_vector(15 downto 0); -- Data Bus
98
    DRAM_ADDR : out std_logic_vector(11 downto 0); -- Address Bus    
99
    DRAM_LDQM,                                     -- Low-byte Data Mask 
100
    DRAM_UDQM,                                     -- High-byte Data Mask
101
    DRAM_WE_N,                                     -- Write Enable
102
    DRAM_CAS_N,                                    -- Column Address Strobe
103
    DRAM_RAS_N,                                    -- Row Address Strobe
104
    DRAM_CS_N,                                     -- Chip Select
105
    DRAM_BA_0,                                     -- Bank Address 0
106
    DRAM_BA_1,                                     -- Bank Address 0
107
    DRAM_CLK,                                      -- Clock
108
    DRAM_CKE : out std_logic;                      -- Clock Enable
109
 
110
    -- FLASH
111
    FL_DQ : inout std_logic_vector(7 downto 0);      -- Data bus
112
    FL_ADDR : out std_logic_vector(21 downto 0);     -- Address bus
113
    FL_WE_N,                                         -- Write Enable
114
    FL_RST_N,                                        -- Reset
115
    FL_OE_N,                                         -- Output Enable
116
    FL_CE_N : out std_logic;                         -- Chip Enable
117
 
118
    -- SRAM
119
    SRAM_DQ : inout std_logic_vector(15 downto 0); -- Data bus 16 Bits
120
    SRAM_ADDR : out std_logic_vector(17 downto 0); -- Address bus 18 Bits
121
    SRAM_UB_N,                                     -- High-byte Data Mask 
122
    SRAM_LB_N,                                     -- Low-byte Data Mask 
123
    SRAM_WE_N,                                     -- Write Enable
124
    SRAM_CE_N,                                     -- Chip Enable
125
    SRAM_OE_N : out std_logic;                     -- Output Enable
126
 
127
    -- SD card interface
128
    SD_DAT : in std_logic;      -- SD Card Data      SD pin 7 "DAT 0/DataOut"
129
    SD_DAT3 : out std_logic;    -- SD Card Data 3    SD pin 1 "DAT 3/nCS"
130
    SD_CMD : out std_logic;     -- SD Card Command   SD pin 2 "CMD/DataIn"
131
    SD_CLK : out std_logic;     -- SD Card Clock     SD pin 5 "CLK"
132
 
133
    -- USB JTAG link
134
    TDI,                        -- CPLD -> FPGA (data in)
135
    TCK,                        -- CPLD -> FPGA (clk)
136
    TCS : in std_logic;         -- CPLD -> FPGA (CS)
137
    TDO : out std_logic;        -- FPGA -> CPLD (data out)
138
 
139
    -- I2C bus
140
    I2C_SDAT : inout std_logic; -- I2C Data
141
    I2C_SCLK : out std_logic;   -- I2C Clock
142
 
143
    -- PS/2 port
144
    PS2_DAT,                    -- Data
145
    PS2_CLK : inout std_logic;     -- Clock
146
 
147
    -- VGA output
148
    VGA_HS,                                             -- H_SYNC
149
    VGA_VS : out std_logic;                             -- SYNC
150
    VGA_R,                                              -- Red[3:0]
151
    VGA_G,                                              -- Green[3:0]
152
    VGA_B : out std_logic_vector(3 downto 0);           -- Blue[3:0]
153
 
154
    -- Audio CODEC
155
    AUD_ADCLRCK : inout std_logic;                      -- ADC LR Clock
156
    AUD_ADCDAT : in std_logic;                          -- ADC Data
157
    AUD_DACLRCK : inout std_logic;                      -- DAC LR Clock
158
    AUD_DACDAT : out std_logic;                         -- DAC Data
159
    AUD_BCLK : inout std_logic;                         -- Bit-Stream Clock
160
    AUD_XCK : out std_logic;                            -- Chip Clock
161
 
162
    -- General-purpose I/O
163
    GPIO_0,                                      -- GPIO Connection 0
164
    GPIO_1 : inout std_logic_vector(35 downto 0) -- GPIO Connection 1    
165
);
166
end TOP_DE1;
167
 
168
architecture rtl of TOP_DE1 is
169
 
170
        use work.z80soc_pack.all;
171
 
172
        component T80se
173
        generic(
174
                Mode : integer := 0;     -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
175
                T2Write : integer := 1; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
176
                IOWait : integer := 1   -- 0 => Single cycle I/O, 1 => Std I/O cycle
177
        );
178
        port(
179
                RESET_n : in std_logic;
180
                CLK_n           : in std_logic;
181
                CLKEN           : in std_logic;
182
                WAIT_n  : in std_logic;
183
                INT_n           : in std_logic;
184
                NMI_n           : in std_logic;
185
                BUSRQ_n : in std_logic;
186
                M1_n            : out std_logic;
187
                MREQ_n  : out std_logic;
188
                IORQ_n  : out std_logic;
189
                RD_n            : out std_logic;
190
                WR_n            : out std_logic;
191
                RFSH_n  : out std_logic;
192
                HALT_n  : out std_logic;
193
                BUSAK_n : out std_logic;
194
                A                       : out std_logic_vector(15 downto 0);
195
                DI                      : in std_logic_vector(7 downto 0);
196
                DO                      : out std_logic_vector(7 downto 0)
197
        );
198
        end component;
199
 
200
        component rom
201
        port (
202
                Clk     : in std_logic;
203
                A       : in std_logic_vector(11 downto 0);
204
                D       : out std_logic_vector(7 downto 0));
205
        end component;
206
 
207
        component Clock_357Mhz
208
        PORT (
209
                clock_50Mhz                             : IN    STD_LOGIC;
210
                clock_357Mhz                    : OUT   STD_LOGIC);
211
        end component;
212
 
213
        component clk_div
214
        PORT
215
        (
216
                clock_25Mhz                             : IN    STD_LOGIC;
217
                clock_1MHz                              : OUT   STD_LOGIC;
218
                clock_100KHz                    : OUT   STD_LOGIC;
219
                clock_10KHz                             : OUT   STD_LOGIC;
220
                clock_1KHz                              : OUT   STD_LOGIC;
221
                clock_100Hz                             : OUT   STD_LOGIC;
222
                clock_10Hz                              : OUT   STD_LOGIC;
223
                clock_1Hz                               : OUT   STD_LOGIC);
224
        end component;
225
 
226
        component decoder_7seg
227
        port (
228
                NUMBER          : in   std_logic_vector(3 downto 0);
229
                HEX_DISP        : out  std_logic_vector(6 downto 0));
230
        end component;
231
 
232
        component ps2kbd
233
        port (
234
                        keyboard_clk    : inout std_logic;
235
                        keyboard_data   : inout std_logic;
236
                        clock                           : in std_logic;
237
                        clkdelay                        : in std_logic;
238
                        reset                           : in std_logic;
239
                        read                            : in std_logic;
240
                        scan_ready              : out std_logic;
241
                        ps2_ascii_code  : out std_logic_vector(7 downto 0));
242
        end component;
243
 
244
        component vram3200x8
245
        port
246
        (
247
                rdaddress               : IN STD_LOGIC_VECTOR (11 DOWNTO 0);
248
                wraddress               : IN STD_LOGIC_VECTOR (11 DOWNTO 0);
249
                rdclock                 : IN STD_LOGIC;
250
                wrclock                 : IN STD_LOGIC;
251
                data                    : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
252
                wren                    : IN STD_LOGIC;
253
                q                               : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
254
        );
255
        end component;
256
 
257
        component charram2k
258
        port (
259
                data                    : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
260
                rdaddress               : IN STD_LOGIC_VECTOR (10 DOWNTO 0);
261
                rdclock                 : IN STD_LOGIC ;
262
                wraddress               : IN STD_LOGIC_VECTOR (10 DOWNTO 0);
263
                wrclock                 : IN STD_LOGIC;
264
                wren                    : IN STD_LOGIC;
265
                q                               : OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
266
        end component;
267
 
268
        COMPONENT video
269
        PORT (
270
                CLOCK_25                : IN STD_LOGIC;
271
                VRAM_DATA               : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
272
                VRAM_ADDR               : OUT STD_LOGIC_VECTOR(12 DOWNTO 0);
273
                VRAM_CLOCK              : OUT STD_LOGIC;
274
                VRAM_WREN               : OUT STD_LOGIC;
275
                CRAM_DATA               : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
276
                CRAM_ADDR               : OUT STD_LOGIC_VECTOR(10 DOWNTO 0);
277
                CRAM_WEB                : OUT STD_LOGIC;
278
                VGA_R,
279
                VGA_G,
280
                VGA_B                   : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
281
                VGA_HS,
282
                VGA_VS                  : OUT STD_LOGIC);
283
        END COMPONENT;
284
 
285
        COMPONENT video_PLL
286
        PORT
287
        (
288
                inclk0          : IN STD_LOGIC  := '0';
289
                c0                      : OUT STD_LOGIC
290
        );
291
        END COMPONENT;
292
 
293
        signal MREQ_n   : std_logic;
294
        signal IORQ_n   : std_logic;
295
        signal RD_n             : std_logic;
296
        signal WR_n             : std_logic;
297
        signal MWr_n    : std_logic;
298
        signal Rst_n_s  : std_logic;
299
        signal Clk_Z80  : std_logic;
300
        signal DI_CPU   : std_logic_vector(7 downto 0);
301
        signal DO_CPU   : std_logic_vector(7 downto 0);
302
        signal A                : std_logic_vector(15 downto 0);
303
        signal One              : std_logic;
304
 
305
        signal D_ROM    : std_logic_vector(7 downto 0);
306
 
307
        signal clk25mhz         : std_logic;
308
        signal clk100hz         : std_logic;
309
        signal clk10hz          : std_logic;
310
        signal clk1hz           : std_logic;
311
 
312
        signal HEX_DISP0        : std_logic_vector(6 downto 0);
313
        signal HEX_DISP1        : std_logic_vector(6 downto 0);
314
        signal HEX_DISP2        : std_logic_vector(6 downto 0);
315
        signal HEX_DISP3        : std_logic_vector(6 downto 0);
316
 
317
        signal NUMBER0          : std_logic_vector(3 downto 0);
318
        signal NUMBER1          : std_logic_vector(3 downto 0);
319
        signal NUMBER2          : std_logic_vector(3 downto 0);
320
        signal NUMBER3          : std_logic_vector(3 downto 0);
321
 
322
        signal GPIO_0_buf_in    : std_logic_vector(35 downto 0);
323
        signal GPIO_1_buf_in    : std_logic_vector(35 downto 0);
324
 
325
        signal  vram_addra              : std_logic_vector(15 downto 0);
326
        signal  vram_addrb              : std_logic_vector(12 downto 0);
327
        signal  vram_dina               : std_logic_vector(7 downto 0);
328
        signal  vram_dinb               : std_logic_vector(7 downto 0);
329
        signal  vram_douta              : std_logic_vector(7 downto 0);
330
        signal  vram_doutb              : std_logic_vector(7 downto 0);
331
        signal  vram_wea                : std_logic;
332
        signal  vram_web                : std_logic;
333
        signal  vram_clka               : std_logic;
334
        signal  vram_clkb               : std_logic;
335
 
336
        signal vram_douta_reg   : std_logic_vector(7 downto 0);
337
        signal VID_CURSOR               : std_logic_vector(15 downto 0);
338
        signal CURSOR_X             : std_logic_vector(6 downto 0);
339
        signal CURSOR_Y             : std_logic_vector(5 downto 0);
340
 
341
        signal cram_addra               : std_logic_vector(15 downto 0);
342
        signal cram_addrb               : std_logic_vector(15 downto 0);
343
        signal cram_dina                : std_logic_vector(7 downto 0);
344
        signal cram_dinb                : std_logic_vector(7 downto 0);
345
        signal cram_douta               : std_logic_vector(7 downto 0);
346
        signal cram_doutb               : std_logic_vector(7 downto 0);
347
        signal cram_wea                 : std_logic;
348
        signal cram_web                 : std_logic;
349
        signal cram_clka                : std_logic;
350
        signal cram_clkb                : std_logic;
351
 
352
        -- PS/2 Keyboard
353
        signal ps2_read                         : std_logic;
354
        signal ps2_scan_ready           : std_logic;
355
        signal ps2_ascii_sig            : std_logic_vector(7 downto 0);
356
        signal ps2_ascii_reg1           : std_logic_vector(7 downto 0);
357
        signal ps2_ascii_reg            : std_logic_vector(7 downto 0);
358
 
359
        signal Z80SOC_VERSION           : std_logic_vector(2 downto 0);   -- "000" = DE1, "001" = S3E
360
 
361
begin
362
 
363
        Z80SOC_VERSION <= "000";                -- "000" = DE1, "001" = S3E
364
        Rst_n_s <= not SW(9);
365
 
366
        HEX0 <= HEX_DISP0;
367
        HEX1 <= HEX_DISP1;
368
        HEX2 <= HEX_DISP2;
369
        HEX3 <= HEX_DISP3;
370
 
371
--      Write into VRAM
372
        vram_addra <= VID_CURSOR when (IORQ_n = '0' and MREQ_n = '1' and A(7 downto 0) = x"90")  else
373
                      A - x"4000" when (A >= x"4000" and A < x"4C80");
374
        vram_wea   <= '0' when ((A >= x"4000" and A < x"4C80" and Wr_n = '0' and MReq_n = '0') or (Wr_n = '0' and IORQ_n = '0' and A(7 downto 0) = x"90")) else
375
                '1';
376
        vram_dina <= DO_CPU;
377
 
378
-- Write into char ram
379
        cram_addra      <= A - x"4C80";
380
        cram_dina       <= DO_CPU;
381
        cram_wea        <= '0' when (A >= x"4C80" and A < x"5480" and Wr_n = '0' and MReq_n = '0') else '1';
382
 
383
        -- SRAM control signals
384
        -- SRAM will store data for video, characters patterns and RAM (only on DE1 version)
385
        -- Due to limitation in dual-port block rams onthis platform
386
        SRAM_ADDR(15 downto 0) <= A - x"4000" when (A >= x"4000"  and A < x"C000" and MREQ_n = '0');
387
        SRAM_DQ(7 downto 0) <= DO_CPU when (Wr_n = '0' and MREQ_n = '0' and A >= x"4000"  and A < x"C000") else (others => 'Z');
388
        SRAM_WE_N <= Wr_n or MREQ_n when (A >= x"4000" and A < x"C000");
389
        SRAM_OE_N <= Rd_n;
390
 
391
        -- Input to Z80
392
        DI_CPU <= ("00000" & Z80SOC_VERSION) when (Rd_n = '0' and MREQ_n = '0' and A = x"FFDF") else
393
                        D_ROM when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A < x"4000") else
394
                        --vram_douta when (MREQ_n = '0' and IORQ_n = '1' and Rd_n = '0' and A < x"4C80") else
395
                        --cram_douta when (MREQ_n = '0' and IORQ_n = '1' and Rd_n = '0' and A < x"5480") else
396
                        SRAM_DQ(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A >= x"4000" and A < x"C000") else
397
                        SW(7 downto 0) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"20") else
398
                        ("0000" & not KEY) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"30") else
399
                        GPIO_0(7 downto 0) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"A0") else
400
                        GPIO_0(15 downto 8) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"A1") else
401
                        GPIO_0(23 downto 16) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"A2") else
402
                        GPIO_0(31 downto 24) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"A3") else
403
                        ("0000" & GPIO_0(35 downto 32)) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"A4") else
404
                        GPIO_1(7 downto 0) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"B0") else
405
                        GPIO_1(15 downto 8) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"B1") else
406
                        GPIO_1(23 downto 16) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"B2") else
407
                        GPIO_1(31 downto 24) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"B3") else
408
                        ("0000" & GPIO_1(35 downto 32)) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"B4") else
409
                        ps2_ascii_reg when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"80") else
410
                        ("0" & CURSOR_X) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"91") else
411
                        ("00" & CURSOR_Y) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"92") else
412
                        "ZZZZZZZZ";
413
 
414
        -- Process to latch leds and hex displays
415
        pinout_process: process(Clk_Z80)
416
        variable NUMBER0_sig    : std_logic_vector(3 downto 0);
417
        variable NUMBER1_sig    : std_logic_vector(3 downto 0);
418
        variable NUMBER2_sig    : std_logic_vector(3 downto 0);
419
        variable NUMBER3_sig    : std_logic_vector(3 downto 0);
420
        variable LEDG_sig               : std_logic_vector(7 downto 0);
421
        variable LEDR_sig               : std_logic_vector(9 downto 0);
422
        variable GPIO_0_buf_out: std_logic_vector(35 downto 0);
423
        variable GPIO_1_buf_out: std_logic_vector(35 downto 0);
424
        begin
425
                if Clk_Z80'event and Clk_Z80 = '1' then
426
                  if IORQ_n = '0' and MREQ_n = '1' and Wr_n = '0' then
427
                        -- LEDG
428
                        if A(7 downto 0) = x"01" then
429
                                LEDG_sig := DO_CPU;
430
                        -- LEDR
431
                        elsif A(7 downto 0) = x"02" then
432
                                LEDR_sig(7 downto 0) := DO_CPU;
433
                        -- HEX1 and HEX0
434
                        elsif A(7 downto 0) = x"10" then
435
                                NUMBER2_sig := DO_CPU(3 downto 0);
436
                                NUMBER3_sig := DO_CPU(7 downto 4);
437
                        -- HEX3 and HEX2
438
                        elsif A(7 downto 0) = x"11" then
439
                                NUMBER0_sig := DO_CPU(3 downto 0);
440
                                NUMBER1_sig := DO_CPU(7 downto 4);
441
                        -- GPIO_0
442
                        elsif A(7 downto 0) = x"A0" then
443
                                GPIO_0_buf_out(7 downto 0)   := DO_CPU;
444
                        elsif A(7 downto 0) = x"A1" then
445
                                GPIO_0_buf_out(15 downto 8)  := DO_CPU;
446
                        elsif A(7 downto 0) = x"A2" then
447
                                GPIO_0_buf_out(23 downto 16) := DO_CPU;
448
                        elsif A(7 downto 0) = x"A3" then
449
                                GPIO_0_buf_out(31 downto 24) := DO_CPU;
450
                        elsif A(7 downto 0) = x"A4" then
451
                                GPIO_0_buf_out(35 downto 32) := DO_CPU(3 downto 0);
452
                        -- GPIO_1
453
                        elsif A(7 downto 0) = x"B0" then
454
                                GPIO_1_buf_out(7 downto 0)   := DO_CPU;
455
                        elsif A(7 downto 0) = x"B1" then
456
                                GPIO_1_buf_out(15 downto 8)  := DO_CPU;
457
                        elsif A(7 downto 0) = x"B2" then
458
                                GPIO_1_buf_out(23 downto 16) := DO_CPU;
459
                        elsif A(7 downto 0) = x"B3" then
460
                                GPIO_1_buf_out(31 downto 24) := DO_CPU;
461
                        elsif A(7 downto 0) = x"B4" then
462
                                GPIO_1_buf_out(35 downto 32) := DO_CPU(3 downto 0);
463
                        elsif A(7 downto 0) = x"C0" then
464
                                GPIO_0 <= GPIO_0_buf_out;
465
                        elsif A(7 downto 0) = x"C1" then
466
                                GPIO_1 <= GPIO_1_buf_out;
467
                        end if;
468
                  end if;
469
                end if;
470
                -- Latches the signals
471
                NUMBER0 <= NUMBER0_sig;
472
                NUMBER1 <= NUMBER1_sig;
473
                NUMBER2 <= NUMBER2_sig;
474
                NUMBER3 <= NUMBER3_sig;
475
                LEDR(7 downto 0) <= LEDR_sig(7 downto 0);
476
                LEDG <= LEDG_sig;
477
        end process;
478
 
479
        -- the following three processes deals with different clock domain signals
480
        ps2_process1: process(CLOCK_50)
481
        begin
482
                if CLOCK_50'event and CLOCK_50 = '1' then
483
                        if ps2_read = '1' then
484
                                if ps2_ascii_sig /= x"FF" then
485
                                        ps2_read <= '0';
486
                                        ps2_ascii_reg1 <= "00000000";
487
                                end if;
488
                        elsif ps2_scan_ready = '1' then
489
                                if ps2_ascii_sig = x"FF" then
490
                                        ps2_read <= '1';
491
                                else
492
                                        ps2_ascii_reg1 <= ps2_ascii_sig;
493
                                end if;
494
                        end if;
495
                end if;
496
        end process;
497
 
498
        ps2_process2: process(Clk_Z80)
499
        begin
500
                if Clk_Z80'event and Clk_Z80 = '1' then
501
                        ps2_ascii_reg <= ps2_ascii_reg1;
502
                end if;
503
        end process;
504
 
505
        cursorxy: process (Clk_Z80)
506
        variable VID_X  : std_logic_vector(6 downto 0);
507
        variable VID_Y  : std_logic_vector(5 downto 0);
508
        begin
509
                if Clk_Z80'event and Clk_Z80 = '1' then
510
                        if (IORQ_n = '0' and MREQ_n = '1' and Wr_n = '0' and A(7 downto 0) = x"91") then
511
                                VID_X := DO_CPU(6 downto 0);
512
                        elsif (IORQ_n = '0' and MREQ_n = '1' and Wr_n = '0' and A(7 downto 0) = x"92") then
513
                                VID_Y := DO_CPU(5 downto 0);
514
                        elsif (IORQ_n = '0' and MREQ_n = '1' and Wr_n = '0' and A(7 downto 0) = x"90") then
515
                                if VID_X = vid_cols - 1 then
516
                                        VID_X := "0000000";
517
                                        if VID_Y = vid_lines - 1 then
518
                                                VID_Y := "000000";
519
                                        else
520
                                                VID_Y := VID_Y + 1;
521
                                        end if;
522
                                else
523
                                        VID_X := VID_X + 1;
524
                                end if;
525
                        end if;
526
                end if;
527
                VID_CURSOR <= vram_base_addr + ( VID_X + ( VID_Y * conv_std_logic_vector(vid_cols,7)));
528
                CURSOR_X <= VID_X;
529
                CURSOR_Y <= VID_Y;
530
        end process;
531
 
532
        One <= '1';
533
        z80_inst: T80se
534
                port map (
535
                        M1_n => open,
536
                        MREQ_n => MREQ_n,
537
                        IORQ_n => IORQ_n,
538
                        RD_n => Rd_n,
539
                        WR_n => Wr_n,
540
                        RFSH_n => open,
541
                        HALT_n => open,
542
                        WAIT_n => One,
543
                        INT_n => One,
544
                        NMI_n => One,
545
                        RESET_n => Rst_n_s,
546
                        BUSRQ_n => One,
547
                        BUSAK_n => open,
548
                        CLK_n => Clk_Z80,
549
                        CLKEN => One,
550
                        A => A,
551
                        DI => DI_CPU,
552
                        DO => DO_CPU
553
                );
554
 
555
        video_inst: video port map (
556
                        CLOCK_25                => clk25mhz,
557
                        VRAM_DATA               => vram_doutb,
558
                        VRAM_ADDR               => vram_addrb(12 downto 0),
559
                        VRAM_CLOCK              => vram_clkb,
560
                        VRAM_WREN               => vram_web,
561
                        CRAM_DATA               => cram_doutb,
562
                        CRAM_ADDR               => cram_addrb(10 downto 0),
563
                        CRAM_WEB                => cram_web,
564
                        VGA_R                   => VGA_R,
565
                        VGA_G                   => VGA_G,
566
                        VGA_B                   => VGA_B,
567
                        VGA_HS                  => VGA_HS,
568
                        VGA_VS                  => VGA_VS
569
        );
570
 
571
        vram : vram3200x8
572
                port map (
573
                rdclock         => vram_clkb,
574
                wrclock         => Clk_Z80,
575
                wren            => not vram_wea, -- inverted logic so code is similar to SRAM and S3E port
576
                wraddress       => vram_addra(11 downto 0),
577
                rdaddress       => vram_addrb(11 downto 0),
578
                data            => vram_dina,
579
                q                       => vram_doutb
580
        );
581
 
582
        cram: charram2k
583
                port map (
584
                rdaddress       => cram_addrb(10 downto 0),
585
                wraddress       => cram_addra(10 downto 0),
586
                wrclock         => Clk_Z80,
587
                rdclock         => vram_clkb,
588
                data            => cram_dina,
589
                q                       => cram_doutb,
590
                wren            => NOT cram_wea
591
        );
592
 
593
        rom_inst: rom
594
                port map (
595
                        Clk => Clk_Z80,
596
                        A       => A(11 downto 0),
597
                        D       => D_ROM
598
                );
599
 
600
        -- PLL below is used to generate the pixel clock frequency
601
        -- Uses DE1 50Mhz clock for PLL's input clock
602
        video_PLL_inst: video_PLL
603
        port map (
604
                inclk0   => CLOCK_50,
605
                c0               => clk25mhz
606
        );
607
 
608
        clkdiv_inst: clk_div
609
        port map (
610
                clock_25Mhz                             => clk25mhz,
611
                clock_1MHz                              => open,
612
                clock_100KHz                    => open,
613
                clock_10KHz                             => open,
614
                clock_1KHz                              => open,
615
                clock_100Hz                             => clk100hz,
616
                clock_10Hz                              => clk10hz,
617
                clock_1Hz                               => clk1hz
618
        );
619
 
620
        clock_z80_inst : Clock_357Mhz
621
                port map (
622
                        clock_50Mhz             => CLOCK_50,
623
                        clock_357Mhz    => Clk_Z80
624
        );
625
 
626
        DISPHEX0 : decoder_7seg PORT MAP (
627
                NUMBER                  =>      NUMBER0,
628
                HEX_DISP                =>      HEX_DISP0
629
        );
630
 
631
        DISPHEX1 : decoder_7seg PORT MAP (
632
                NUMBER                  =>      NUMBER1,
633
                HEX_DISP                =>      HEX_DISP1
634
        );
635
 
636
        DISPHEX2 : decoder_7seg PORT MAP (
637
                NUMBER                  =>      NUMBER2,
638
                HEX_DISP                =>      HEX_DISP2
639
        );
640
 
641
        DISPHEX3 : decoder_7seg PORT MAP (
642
                NUMBER                  =>      NUMBER3,
643
                HEX_DISP                =>      HEX_DISP3
644
        );
645
 
646
        ps2_kbd_inst : ps2kbd PORT MAP (
647
                keyboard_clk    => PS2_CLK,
648
                keyboard_data   => PS2_DAT,
649
                clock                   => CLOCK_50,
650
                clkdelay                => clk100hz,
651
                reset                   => Rst_n_s,
652
                read                    => ps2_read,
653
                scan_ready              => ps2_scan_ready,
654
                ps2_ascii_code  => ps2_ascii_sig
655
        );
656
 
657
        --
658
        SRAM_DQ(15 downto 8) <= (others => 'Z');
659
        SRAM_ADDR(17 downto 16) <= "00";
660
        SRAM_UB_N <= '1';
661
        SRAM_LB_N <= '0';
662
        SRAM_CE_N <= '0';
663
        --
664
        UART_TXD <= 'Z';
665
        DRAM_ADDR <= (others => '0');
666
        DRAM_LDQM <= '0';
667
        DRAM_UDQM <= '0';
668
        DRAM_WE_N <= '1';
669
        DRAM_CAS_N <= '1';
670
        DRAM_RAS_N <= '1';
671
        DRAM_CS_N <= '1';
672
        DRAM_BA_0 <= '0';
673
        DRAM_BA_1 <= '0';
674
        DRAM_CLK <= '0';
675
        DRAM_CKE <= '0';
676
        FL_ADDR <= (others => '0');
677
        FL_WE_N <= '1';
678
        FL_RST_N <= '0';
679
        FL_OE_N <= '1';
680
        FL_CE_N <= '1';
681
        TDO <= '0';
682
        I2C_SCLK <= '0';
683
        AUD_DACDAT <= '0';
684
        AUD_XCK <= '0';
685
        -- Set all bidirectional ports to tri-state
686
        DRAM_DQ     <= (others => 'Z');
687
        FL_DQ       <= (others => 'Z');
688
        I2C_SDAT    <= 'Z';
689
        AUD_ADCLRCK <= 'Z';
690
        AUD_DACLRCK <= 'Z';
691
        AUD_BCLK    <= 'Z';
692
        GPIO_0 <= (others => 'Z');
693
        GPIO_1 <= (others => 'Z');
694
end;

powered by: WebSVN 2.1.0

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