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

Subversion Repositories z80soc

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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