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

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7.3/] [DE1/] [vhdl/] [z80soc.vhd.bak] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 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
use work.z80soc_pack.all;
80
 
81
entity  Z80SOC is
82
        port(
83
    -- Clocks
84
    CLOCK_50 : in std_logic;              -- 50 MHz
85
 
86
    -- Buttons and switches
87
    KEY : in std_logic_vector(3 downto 0);         -- Push buttons
88
    SW : in std_logic_vector(17 downto 0);          -- Switches
89
 
90
    -- LED displays
91
    HEX0, HEX1, HEX2, HEX3, HEX4, HEX5, HEX6, HEX7  -- 7-segment displays
92
                        : out std_logic_vector(6 downto 0);
93
    LEDG : out std_logic_vector(8 downto 0);       -- Green LEDs
94
    LEDR : out std_logic_vector(17 downto 0);       -- Red LEDs
95
 
96
    -- RS-232 interface
97
    UART_TXD : out std_logic;                      -- UART transmitter
98
    UART_RXD : in std_logic;                       -- UART receiver
99
    UART_RTS : in std_logic;                       -- UART RTS
100
         UART_CTS : in std_logic;                       -- UART CTS
101
 
102
    -- IRDA interface
103
 
104
    -- IRDA_TXD : out std_logic;                      -- IRDA Transmitter
105
    IRDA_RXD : in std_logic;                       -- IRDA Receiver
106
 
107
    -- SDRAM
108
    DRAM_BA_0,                                     -- Bank Address 0
109
    DRAM_BA_1,                                     -- Bank Address 0
110
    DRAM_DQM_0,                                     -- Byte Data Mask 0
111
    DRAM_DQM_1,                                     -- Byte Data Mask 1
112
    DRAM_DQM_2,                                     -- Byte Data Mask 2
113
    DRAM_DQM_3,                                     -- Byte Data Mask 3
114
    DRAM_WE_N,                                     -- Write Enable
115
    DRAM_CAS_N,                                    -- Column Address Strobe
116
    DRAM_RAS_N,                                    -- Row Address Strobe
117
    DRAM_CS_N :   out std_logic;                   -- Chip Select
118
    DRAM_DQ : inout std_logic_vector(31 downto 0); -- Data Bus
119
    DRAM_ADDR : out std_logic_vector(12 downto 0); -- Address Bus
120
    DRAM_CLK,                                      -- Clock
121
    DRAM_CKE : out std_logic;                      -- Clock Enable
122
 
123
    -- FLASH
124
    FL_DQ : inout std_logic_vector(7 downto 0);      -- Data bus
125
    FL_ADDR : out std_logic_vector(22 downto 0);     -- Address bus
126
         FL_RY : in std_logic;
127
         FL_WP_N,
128
    FL_WE_N,                                         -- Write Enable
129
    FL_RST_N,                                        -- Reset
130
    FL_OE_N,                                         -- Output Enable
131
    FL_CE_N : out std_logic;                         -- Chip Enable
132
 
133
    -- SRAM
134
    SRAM_DQ : inout std_logic_vector(15 downto 0); -- Data bus 16 Bits
135
    SRAM_ADDR : out std_logic_vector(SRAM_width - 1 downto 0); -- Address bus 18 Bits
136
    SRAM_UB_N,                                     -- High-byte Data Mask
137
    SRAM_LB_N,                                     -- Low-byte Data Mask
138
    SRAM_WE_N,                                     -- Write Enable
139
    SRAM_CE_N,                                     -- Chip Enable
140
    SRAM_OE_N : out std_logic;                     -- Output Enable
141
 
142
    -- SD card interface
143
    SD_DAT0 : in std_logic;      -- SD Card Data      SD "DAT 0/DataOut"
144
    SD_DAT1 : inout std_logic;      -- SD Card Data   SD "DAT 1"
145
    SD_DAT2 : inout std_logic;    -- SD Card Data 3   SD "DAT 2"
146
    SD_DAT3 : out std_logic;    -- SD Card Data 3    SD "DAT 3/nCS"
147
         SD_CMD : out std_logic;     -- SD Card Command   SD "CMD/DataIn"
148
    SD_CLK : out std_logic;     -- SD Card Clock     SD "CLK"
149
 
150
    -- PS/2 port
151
    PS2_DAT,                    -- Data
152
    PS2_CLK : inout std_logic;     -- Clock
153
         PS2_DAT2,                    -- Data
154
    PS2_CLK2 : inout std_logic;     -- Clock
155
 
156
    -- VGA output
157
         VGA_SYNC_N,
158
         VGA_CLK,
159
         VGA_BLANK_N,
160
    VGA_HS,                                             -- H_SYNC
161
    VGA_VS : out std_logic;                             -- SYNC
162
    VGA_R,                                              -- Red[7:0]
163
    VGA_G,                                              -- Green[7:0]
164
    VGA_B : out std_logic_vector(7 downto 0);           -- Blue[7:0]
165
 
166
    -- Audio CODEC
167
    AUD_ADCLRCK : inout std_logic;                      -- ADC LR Clock
168
    AUD_ADCDAT : in std_logic;                          -- ADC Data
169
    AUD_DACLRCK : inout std_logic;                      -- DAC LR Clock
170
    AUD_DACDAT : out std_logic;                         -- DAC Data
171
    AUD_BCLK : inout std_logic;                         -- Bit-Stream Clock
172
    AUD_XCK : out std_logic;                                                                      -- Chip Clock
173
    LCD_RS             : OUT    std_logic;
174
    LCD_EN             : OUT    std_logic;
175
    LCD_RW             : OUT    std_logic;
176
         LCD_ON             : OUT    std_logic;
177
    LCD_BLON           : OUT    std_logic; -- lcd on DE2 do not support this signal
178
    LCD_DATA           : INOUT  STD_LOGIC_VECTOR(7 DOWNTO 0));
179
end Z80SOC;
180
 
181
architecture rtl of Z80SOC is
182
 
183
        component T80se
184
        generic(
185
                Mode : integer := 0;    -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
186
                T2Write : integer := 1; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
187
                IOWait : integer := 1   -- 0 => Siomngle cycle I/O, 1 => Std I/O cycle
188
        );
189
        port(
190
                RESET_n : in std_logic;
191
                CLK_n           : in std_logic;
192
                CLKEN           : in std_logic;
193
                WAIT_n  : in std_logic;
194
                INT_n           : in std_logic;
195
                NMI_n           : in std_logic;
196
                BUSRQ_n : in std_logic;
197
                M1_n            : out std_logic;
198
                MREQ_n  : out std_logic;
199
                IORQ_n  : out std_logic;
200
                RD_n            : out std_logic;
201
                WR_n            : out std_logic;
202
                RFSH_n  : out std_logic;
203
                HALT_n  : out std_logic;
204
                BUSAK_n : out std_logic;
205
                A                       : out std_logic_vector(15 downto 0);
206
                DI                      : in std_logic_vector(7 downto 0);
207
                DO                      : out std_logic_vector(7 downto 0)
208
        );
209
        end component;
210
 
211
        component rom
212
        port (
213
                clock   : in std_logic;
214
                address : in std_logic_vector(13 downto 0);
215
                q       : out std_logic_vector(7 downto 0));
216
        end component;
217
 
218
        component Clock_357Mhz
219
        PORT (
220
                clock_50Mhz                             : IN    STD_LOGIC;
221
                clock_357Mhz                    : OUT   STD_LOGIC);
222
        end component;
223
 
224
 
225
    component clk_div
226
    PORT
227
    (
228
        clock_in_50Mhz          : IN    STD_LOGIC;
229
        clock_25MHz             : OUT   STD_LOGIC;
230
                clock_10MHz             : OUT   STD_LOGIC;
231
                clock_357MHz            : OUT   STD_LOGIC;
232
        clock_1MHz              : OUT   STD_LOGIC;
233
        clock_100KHz            : OUT   STD_LOGIC;
234
        clock_10KHz             : OUT   STD_LOGIC;
235
        clock_1KHz              : OUT   STD_LOGIC;
236
        clock_100Hz             : OUT   STD_LOGIC;
237
        clock_10Hz              : OUT   STD_LOGIC;
238
        clock_1Hz               : OUT   STD_LOGIC);
239
    end component;
240
 
241
        component decoder_7seg
242
        port (
243
                NUMBER          : in   std_logic_vector(3 downto 0);
244
                HEX_DISP                : out  std_logic_vector(6 downto 0));
245
        end component;
246
 
247
        component ps2kbd
248
        port (
249
                        keyboard_clk    : inout std_logic;
250
                        keyboard_data   : inout std_logic;
251
                        clock                           : in std_logic;
252
                        clkdelay                        : in std_logic;
253
                        reset                           : in std_logic;
254
                        read                            : in std_logic;
255
                        scan_ready              : out std_logic;
256
                        ps2_ascii_code  : out std_logic_vector(7 downto 0));
257
        end component;
258
 
259
        component vram
260
        port
261
        (
262
                rdaddress               : IN STD_LOGIC_VECTOR (12 DOWNTO 0);
263
                wraddress               : IN STD_LOGIC_VECTOR (12 DOWNTO 0);
264
                rdclock                 : IN STD_LOGIC;
265
                wrclock                 : IN STD_LOGIC;
266
                data                    : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
267
                wren                    : IN STD_LOGIC;
268
                q                               : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
269
        );
270
        end component;
271
 
272
        component charram2k
273
        port (
274
                data                    : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
275
                rdaddress               : IN STD_LOGIC_VECTOR (10 DOWNTO 0);
276
                rdclock                 : IN STD_LOGIC ;
277
                wraddress               : IN STD_LOGIC_VECTOR (10 DOWNTO 0);
278
                wrclock                 : IN STD_LOGIC;
279
                wren                    : IN STD_LOGIC;
280
                q                               : OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
281
        end component;
282
 
283
        COMPONENT video
284
        PORT (
285
                CLOCK_25                : IN STD_LOGIC;
286
                VRAM_DATA               : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
287
                VRAM_ADDR               : OUT STD_LOGIC_VECTOR(13 DOWNTO 0);
288
                VRAM_CLOCK              : OUT STD_LOGIC;
289
                VRAM_WREN               : OUT STD_LOGIC;
290
                CRAM_DATA               : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
291
                CRAM_ADDR               : OUT STD_LOGIC_VECTOR(10 DOWNTO 0);
292
                CRAM_WEB                : OUT STD_LOGIC;
293
                VGA_R,
294
                VGA_G,
295
                VGA_B                   : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
296
                VGA_HS,
297
                VGA_VS                  : OUT STD_LOGIC);
298
        END COMPONENT;
299
 
300
        COMPONENT PLL_Clocks
301
        PORT
302
        (
303
                inclk0          : IN STD_LOGIC  := '0';
304
                c0                      : OUT STD_LOGIC;
305
                c1                      : OUT STD_LOGIC;
306
                c2                      : OUT STD_LOGIC
307
        );
308
        END COMPONENT;
309
 
310
        COMPONENT LCD
311
   PORT(
312
      reset             : IN     std_logic;  -- Map this Port to a Switch within your [Port Declarations / Pin Planer]
313
      CLOCK_50          : IN     std_logic;  -- Using the DE2 50Mhz Clk, in order to Genreate the 400Hz signal... clk_count_400hz reset count value must be set to:  <= x"0F424"
314
      LCD_RS            : OUT    std_logic;
315
      LCD_EN            : OUT    std_logic;
316
      LCD_RW            : OUT    std_logic;
317
      LCD_ON            : OUT    std_logic;
318
      LCD_BLON          : OUT    std_logic;
319
      LCD_DATA          : INOUT         STD_LOGIC_VECTOR(7 DOWNTO 0);
320
                lcd_on_sig                      : IN            STD_LOGIC;
321
           next_char                    : IN            STD_LOGIC_VECTOR(7 DOWNTO 0);
322
                char_count                      : OUT           STD_LOGIC_VECTOR(4 downto 0);
323
                clk400hz                                : OUT           STD_LOGIC);
324
        END COMPONENT;
325
 
326
        signal MREQ_n   : std_logic;
327
        signal IORQ_n   : std_logic;
328
        signal RD_n             : std_logic;
329
        signal WR_n             : std_logic;
330
        signal MWr_n    : std_logic;
331
        signal Rst_n_s  : std_logic;
332
        signal Clk_Z80  : std_logic;
333
        signal DI_CPU   : std_logic_vector(7 downto 0);
334
        signal DO_CPU   : std_logic_vector(7 downto 0);
335
        signal A                : std_logic_vector(15 downto 0);
336
        signal One              : std_logic;
337
 
338
        signal D_ROM    : std_logic_vector(7 downto 0);
339
        signal rom_data : std_logic_vector(7 downto 0);
340
        signal rom_wren : std_logic;
341
 
342
        signal clk_count_400hz: std_logic_vector(19 downto 0);
343
        signal clk100mhz        : std_logic;
344
        signal clk25mhz : std_logic;
345
        signal clk1mhz          : std_logic;
346
        signal clk10mhz : std_logic;
347
        signal clk100hz : std_logic;
348
        signal clk10hz          : std_logic;
349
        signal clk1hz           : std_logic;
350
        signal clk357mhz   : std_logic;
351
 
352
 
353
        signal HEX_DISP0        : std_logic_vector(6 downto 0);
354
        signal HEX_DISP1        : std_logic_vector(6 downto 0);
355
        signal HEX_DISP2        : std_logic_vector(6 downto 0);
356
        signal HEX_DISP3        : std_logic_vector(6 downto 0);
357
        signal HEX_DISP4        : std_logic_vector(6 downto 0);
358
        signal HEX_DISP5        : std_logic_vector(6 downto 0);
359
        signal HEX_DISP6        : std_logic_vector(6 downto 0);
360
        signal HEX_DISP7        : std_logic_vector(6 downto 0);
361
 
362
        signal NUMBER0          : std_logic_vector(3 downto 0);
363
        signal NUMBER1          : std_logic_vector(3 downto 0);
364
        signal NUMBER2          : std_logic_vector(3 downto 0);
365
        signal NUMBER3          : std_logic_vector(3 downto 0);
366
        signal NUMBER4          : std_logic_vector(3 downto 0);
367
        signal NUMBER5          : std_logic_vector(3 downto 0);
368
        signal NUMBER6          : std_logic_vector(3 downto 0);
369
        signal NUMBER7          : std_logic_vector(3 downto 0);
370
 
371
        --signal GPIO_0_buf_in  : std_logic_vector(35 downto 0);
372
        --signal GPIO_1_buf_in  : std_logic_vector(35 downto 0);
373
 
374
        signal  vram_addra              : std_logic_vector(15 downto 0);
375
        signal  vram_addrb              : std_logic_vector(13 downto 0);
376
        signal  vram_dina               : std_logic_vector(7 downto 0);
377
        signal  vram_dinb               : std_logic_vector(7 downto 0);
378
        signal  vram_douta              : std_logic_vector(7 downto 0);
379
        signal  vram_doutb              : std_logic_vector(7 downto 0);
380
        signal  vram_wea                : std_logic;
381
        signal  vram_web                : std_logic;
382
        signal  vram_clka               : std_logic;
383
        signal  vram_clkb               : std_logic;
384
 
385
--      signal vram_douta_reg   : std_logic_vector(7 downto 0);
386
 
387
        signal cram_addra               : std_logic_vector(15 downto 0);
388
        signal cram_addrb               : std_logic_vector(15 downto 0);
389
        signal cram_dina                : std_logic_vector(7 downto 0);
390
        signal cram_dinb                : std_logic_vector(7 downto 0);
391
        signal cram_douta               : std_logic_vector(7 downto 0);
392
        signal cram_doutb               : std_logic_vector(7 downto 0);
393
        signal cram_wea                 : std_logic;
394
        signal cram_web                 : std_logic;
395
        signal cram_clka                : std_logic;
396
        signal cram_clkb                : std_logic;
397
 
398
        -- PS/2 Keyboard
399
        signal ps2_read                         : std_logic;
400
        signal ps2_scan_ready           : std_logic;
401
        signal ps2_ascii_sig            : std_logic_vector(7 downto 0);
402
        signal ps2_ascii_reg1           : std_logic_vector(7 downto 0);
403
        signal ps2_ascii_reg            : std_logic_vector(7 downto 0);
404
 
405
        -- LCD signals
406
        type character_string is array ( 0 to 31 ) of STD_LOGIC_VECTOR( 7 downto 0 );
407
        signal lcdvram                          : character_string;
408
        signal lcdaddr_w_sig            : std_logic_vector(15 downto 0);
409
        signal lcdaddr_sig                              : std_logic_vector(15 downto 0) := LCD_value;
410
        signal clk400hz                                 : std_logic;
411
        signal char_count_sig                   : std_logic_vector(4 downto 0);
412
        signal next_char_sig                            : std_logic_vector(7 downto 0);
413
        signal temp                                                     : std_logic;
414
 
415
        signal Z80SOC_Arch_reg                  : std_logic_vector(2 downto 0)  := Z80SOC_Arch_value;   -- "000" = DE1, "001" = S3E, "010" = DE2115
416
        signal RAMTOP_reg                                       : std_logic_vector(15 downto 0) := RAMTOP_value;
417
        signal RAMBOTT_reg                              : std_logic_vector(15 downto 0) := RAMBOTT_value;
418
        signal LCD_reg                                          : std_logic_vector(15 downto 0) := LCD_value;
419
        signal VRAM_reg                                 : std_logic_vector(15 downto 0) := VRAM_value;
420
        signal STACK_reg                                        : std_logic_vector(15 downto 0) := STACK_value;
421
        signal CHARRAM_reg                              : std_logic_vector(15 downto 0) := CHARRAM_value;
422
        signal VRAMNXTCHAR_reg                  : std_logic_vector(15 downto 0);
423
        signal CURX_reg                                 : std_logic_vector(7 downto 0);
424
        signal CURY_reg                                 : std_logic_vector(7 downto 0);
425
        signal STDOUT_reg                                       : std_logic_vector(7 downto 0);
426
        signal LCDON_reg                                        : std_logic;
427
begin
428
 
429
        -- required signals for DE2-115
430
        VGA_BLANK_N <= '1';
431
        VGA_CLK <= clk25mhz;
432
        --
433
        STDOUT_reg <= DO_CPU when (A = x"57CD" and Wr_n = '0' and MReq_n = '0');
434
        CURX_reg   <= DO_CPU when (A = x"57CF" and Wr_n = '0' and MReq_n = '0');
435
        CURY_reg   <= DO_CPU when (A = x"57CE" and Wr_n = '0' and MReq_n = '0');
436
        VRAMNXTCHAR_reg(7 DOWNTO 0)  <= DO_CPU when (A = x"57D0" and Wr_n = '0' and MReq_n = '0');
437
        VRAMNXTCHAR_reg(15 DOWNTO 8) <= DO_CPU when (A = x"57D1" and Wr_n = '0' and MReq_n = '0');
438
 
439
        -- Modo Turbo 10Mhz
440
        Clk_Z80 <= clk357mhz when SW(16) = '0' else clk10mhz;
441
        LEDR(17) <= SW(17);
442
        LEDR(16) <= SW(16);
443
 
444
        --Z80SOC_Arch_reg <= Z80SOC_Arch_addr;  -- "000" = DE1, "001" = S3E, "010" = DE2115
445
        Rst_n_s <= not SW(17);
446
 
447
        HEX0 <= HEX_DISP0;
448
        HEX1 <= HEX_DISP1;
449
        HEX2 <= HEX_DISP2;
450
        HEX3 <= HEX_DISP3;
451
        HEX4 <= HEX_DISP4;
452
        HEX5 <= HEX_DISP5;
453
        HEX6 <= HEX_DISP6;
454
        HEX7 <= HEX_DISP7;
455
 
456
--      Write into VRAM and System Variables
457
        vram_addra <= A - VRAM_value;
458
        vram_dina  <= DO_CPU;
459
        vram_wea   <= '0' when (A >= VRAM_value and A < LCD_value and Wr_n = '0' and MReq_n = '0') else
460
                  '1';
461
 
462
-- Write into char ram
463
        cram_addra      <= A - CHARRAM_value;
464
        cram_dina       <= DO_CPU;
465
        cram_wea        <= '0' when (A >= CHARRAM_value and A < RAMBOTT_value and Wr_n = '0' and MReq_n = '0') else '1';
466
 
467
-- Write into LCD video ram
468
        --LCD_ON <= KEY(3);
469
        lcdvram(CONV_INTEGER(A - LCD_value)) <= DO_CPU when A >= LCD_value and (A < LCD_value + 32) and Wr_n = '0' and MReq_n = '0';
470
 
471
        -- SRAM control signals
472
        -- SRAM will store data for video, characters patterns and RAM (only on DE1 version)
473
        -- Due to limitation in dual-port block rams on this platform
474
 
475
        SRAM_ADDR(15 downto 0) <= A - RAMBOTT_value;
476
        SRAM_DQ(7 downto 0) <= DO_CPU when (Wr_n = '0' and MREQ_n = '0' and A >= RAMBOTT_value) else (others => 'Z');
477
        SRAM_WE_N <= '0' when (Wr_n = '0' and MREQ_n = '0' and A >= RAMBOTT_value) else '1';
478
        SRAM_OE_N <= '0' when (Rd_n = '0' and MREQ_n = '0' and A >= RAMBOTT_value) else '1';
479
        SRAM_DQ(15 downto 8) <= (others => 'Z');
480
        SRAM_ADDR(19 downto 16) <= "0000";
481
        SRAM_UB_N <= '1';
482
        SRAM_LB_N <= '0';
483
        SRAM_CE_N <= '0';
484
 
485
        -- Input to Z80
486
        DI_CPU <= ("00000" & Z80SOC_Arch_reg) when (Rd_n = '0' and MREQ_n = '0' and A = Z80SOC_Arch_addr) else
487
                        ps2_ascii_reg when (Rd_n = '0' and MREQ_n = '0' and A = KEYPRESS_addr) else
488
                        RAMTOP_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = RAMTOP_addr) else
489
                        RAMTOP_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = RAMTOP_addr + 1)) else
490
                        RAMBOTT_reg (7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = RAMBOTT_addr) else
491
                        RAMBOTT_reg (15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = RAMBOTT_addr + 1)) else
492
                        LCD_reg (7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = LCD_addr) else
493
                        LCD_reg (15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = LCD_addr + 1)) else
494
                        VRAM_reg (7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = VRAM_addr) else
495
                        VRAM_reg (15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = VRAM_addr + 1)) else
496
                        CHARRAM_reg (7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = CHARRAM_addr) else
497
                        CHARRAM_reg (15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = CHARRAM_addr + 1)) else
498
                        STACK_reg (7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = STACK_addr) else
499
                        STACK_reg (15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = STACK_addr + 1)) else
500
                        VRAMNXTCHAR_reg (7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = x"57D0") else
501
                        VRAMNXTCHAR_reg (15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and A = x"57D1") else
502
                        CURX_reg when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A = x"57CF") else
503
                        CURY_reg when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A = x"57CE") else
504
                        STDOUT_reg when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A = x"57CD") else
505
                        D_ROM when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A < VRAM_value) else
506
                        --vram_doutb when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and (A >= VRAM_value + 4800) and A < LCD_value) else
507
                        SRAM_DQ(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A >= RAMBOTT_value) else
508
                        SW(7 downto 0) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"20") else
509
                        SW(15 downto 8) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"21") else
510
                        ("0000" & not KEY) when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"30") else
511
                        --ps2_ascii_reg when (IORQ_n = '0' and MREQ_n = '1' and Rd_n = '0' and A(7 downto 0) = x"80") else
512
                        "ZZZZZZZZ";
513
 
514
        -- Process to latch leds and hex displays
515
        pinout_process: process(Clk_Z80)
516
        variable NUMBER0_sig    : std_logic_vector(3 downto 0);
517
        variable NUMBER1_sig    : std_logic_vector(3 downto 0);
518
        variable NUMBER2_sig    : std_logic_vector(3 downto 0);
519
        variable NUMBER3_sig    : std_logic_vector(3 downto 0);
520
        variable NUMBER4_sig    : std_logic_vector(3 downto 0);
521
        variable NUMBER5_sig    : std_logic_vector(3 downto 0);
522
        variable NUMBER6_sig    : std_logic_vector(3 downto 0);
523
        variable NUMBER7_sig    : std_logic_vector(3 downto 0);
524
        variable LEDG_sig               : std_logic_vector(7 downto 0);
525
        variable LEDR_sig               : std_logic_vector(15 downto 0);
526
        --variable GPIO_0_buf_out: std_logic_vector(35 downto 0);
527
        --variable GPIO_1_buf_out: std_logic_vector(35 downto 0);
528
        begin
529
                if Clk_Z80'event and Clk_Z80 = '1' then
530
                  if IORQ_n = '0' and MREQ_n = '1' and Wr_n = '0' then
531
                        -- LEDG
532
                        if A(7 downto 0) = x"01" then
533
                                LEDG_sig := DO_CPU;
534
                        -- LEDR
535
                        elsif A(7 downto 0) = x"02" then
536
                                LEDR_sig(7 downto 0) := DO_CPU;
537
                        elsif A(7 downto 0) = x"03" then
538
                                LEDR_sig(15 downto 8) := DO_CPU;
539
                        -- HEX1 and HEX0
540
                        elsif A(7 downto 0) = x"10" then
541
                                NUMBER0_sig := DO_CPU(3 downto 0);
542
                                NUMBER1_sig := DO_CPU(7 downto 4);
543
                        -- HEX3 and HEX2
544
                        elsif A(7 downto 0) = x"11" then
545
                                NUMBER2_sig := DO_CPU(3 downto 0);
546
                                NUMBER3_sig := DO_CPU(7 downto 4);
547
                        -- HEX5 and HEX4
548
                        elsif A(7 downto 0) = x"12" then
549
                                NUMBER4_sig := DO_CPU(3 downto 0);
550
                                NUMBER5_sig := DO_CPU(7 downto 4);
551
                        -- HEX7 and HEX6
552
                        elsif A(7 downto 0) = x"13" then
553
                                NUMBER6_sig := DO_CPU(3 downto 0);
554
                                NUMBER7_sig := DO_CPU(7 downto 4);
555
                        elsif A(7 downto 0) = x"15" then
556
                                LCDON_reg <= DO_CPU(0);
557
                        end if;
558
                  end if;
559
                end if;
560
                -- Latches the signals
561
                NUMBER0 <= NUMBER0_sig;
562
                NUMBER1 <= NUMBER1_sig;
563
                NUMBER2 <= NUMBER2_sig;
564
                NUMBER3 <= NUMBER3_sig;
565
                NUMBER4 <= NUMBER4_sig;
566
                NUMBER5 <= NUMBER5_sig;
567
                NUMBER6 <= NUMBER6_sig;
568
                NUMBER7 <= NUMBER7_sig;
569
                LEDR(15 downto 0) <= LEDR_sig;
570
                LEDG(7 downto 0) <= LEDG_sig;
571
        end process;
572
 
573
        -- the following three processes deals with different clock domain signals
574
        ps2_process1: process(CLOCK_50)
575
        begin
576
                if CLOCK_50'event and CLOCK_50 = '1' then
577
                        if ps2_read = '1' then
578
                                if ps2_ascii_sig /= x"FF" then
579
                                        ps2_read <= '0';
580
                                        ps2_ascii_reg1 <= "00000000";
581
                                end if;
582
                        elsif ps2_scan_ready = '1' then
583
                                if ps2_ascii_sig = x"FF" then
584
                                        ps2_read <= '1';
585
                                else
586
                                        ps2_ascii_reg1 <= ps2_ascii_sig;
587
                                end if;
588
                        end if;
589
                end if;
590
        end process;
591
 
592
        ps2_process2: process(Clk_Z80)
593
        begin
594
                if Clk_Z80'event and Clk_Z80 = '1' then
595
                        ps2_ascii_reg <= ps2_ascii_reg1;
596
                end if;
597
        end process;
598
 
599
        lcd_printchar: process(char_count_sig)
600
        begin
601
                next_char_sig <= lcdvram(CONV_INTEGER(char_count_sig));
602
        end process;
603
 
604
        One <= '1';
605
        z80_inst: T80se
606
                port map (
607
                        M1_n => open,
608
                        MREQ_n => MREQ_n,
609
                        IORQ_n => IORQ_n,
610
                        RD_n => Rd_n,
611
                        WR_n => Wr_n,
612
                        RFSH_n => open,
613
                        HALT_n => open,
614
                        WAIT_n => One,
615
                        INT_n => One,
616
                        NMI_n => One,
617
                        RESET_n => Rst_n_s,
618
                        BUSRQ_n => One,
619
                        BUSAK_n => open,
620
                        CLK_n => Clk_Z80,
621
                        CLKEN => One,
622
                        A => A,
623
                        DI => DI_CPU,
624
                        DO => DO_CPU
625
                );
626
 
627
        video_inst: video port map (
628
                        CLOCK_25                => clk25mhz,
629
                        VRAM_DATA               => vram_doutb,
630
                        VRAM_ADDR               => vram_addrb(13 downto 0),
631
                        VRAM_CLOCK              => vram_clkb,
632
                        VRAM_WREN               => vram_web,
633
                        CRAM_DATA               => cram_doutb,
634
                        CRAM_ADDR               => cram_addrb(10 downto 0),
635
                        CRAM_WEB                => cram_web,
636
                        VGA_R                   => VGA_R(7 downto 4),
637
                        VGA_G                   => VGA_G(7 downto 4),
638
                        VGA_B                   => VGA_B(7 downto 4),
639
                        VGA_HS                  => VGA_HS,
640
                        VGA_VS                  => VGA_VS
641
        );
642
 
643
        vram_inst : vram
644
                port map (
645
                rdclock         => vram_clkb,
646
                wrclock         => Clk_Z80,
647
                wren            => not vram_wea, -- inverted logic so code is similar to SRAM and S3E port
648
                wraddress       => vram_addra(12 downto 0),
649
                rdaddress       => vram_addrb(12 downto 0),
650
                data            => vram_dina,
651
                q                       => vram_doutb
652
        );
653
 
654
        cram: charram2k
655
                port map (
656
                rdaddress       => cram_addrb(10 downto 0),
657
                wraddress       => cram_addra(10 downto 0),
658
                wrclock         => Clk_Z80,
659
                rdclock         => vram_clkb,
660
                data            => cram_dina,
661
                q                       => cram_doutb,
662
                wren            => NOT cram_wea
663
        );
664
 
665
        rom_inst: rom
666
                port map (
667
                        clock => clk25mhz,
668
                        address => A(13 downto 0),
669
                        q       => D_ROM
670
                );
671
 
672
        -- PLL below is used to generate the pixel clock frequency
673
        -- Uses DE1 50Mhz clock for PLL's input clock
674
        PLL_Clocks_inst: PLL_Clocks
675
        port map (
676
                inclk0   => CLOCK_50,
677
                c0                      => clk25mhz,
678
                c1                      => clk10mhz,
679
                c2                      => clk100mhz
680
        );
681
 
682
    clkdiv_inst: clk_div
683
    port map (
684
        clock_in_50mhz          => CLOCK_50,
685
        clock_25mhz             => clk25mhz,
686
        clock_10MHz             => clk10mhz,
687
                clock_357Mhz            => clk357mhz,
688
        clock_1MHz              => clk1mhz,
689
        clock_100KHz            => open,
690
        clock_10KHz             => open,
691
        clock_1KHz              => open,
692
        clock_100Hz             => clk100hz,
693
        clock_10Hz              => clk10hz,
694
        clock_1Hz               => clk1hz
695
    );
696
 
697
        DISPHEX0 : decoder_7seg PORT MAP (
698
                NUMBER                  =>      NUMBER0,
699
                HEX_DISP                =>      HEX_DISP0
700
        );
701
 
702
        DISPHEX1 : decoder_7seg PORT MAP (
703
                NUMBER                  =>      NUMBER1,
704
                HEX_DISP                =>      HEX_DISP1
705
        );
706
 
707
        DISPHEX2 : decoder_7seg PORT MAP (
708
                NUMBER                  =>      NUMBER2,
709
                HEX_DISP                =>      HEX_DISP2
710
        );
711
 
712
        DISPHEX3 : decoder_7seg PORT MAP (
713
                NUMBER                  =>      NUMBER3,
714
                HEX_DISP                =>      HEX_DISP3
715
        );
716
 
717
                DISPHEX4 : decoder_7seg PORT MAP (
718
                NUMBER                  =>      NUMBER4,
719
                HEX_DISP                =>      HEX_DISP4
720
        );
721
 
722
        DISPHEX5 : decoder_7seg PORT MAP (
723
                NUMBER                  =>      NUMBER5,
724
                HEX_DISP                =>      HEX_DISP5
725
        );
726
 
727
        DISPHEX6 : decoder_7seg PORT MAP (
728
                NUMBER                  =>      NUMBER6,
729
                HEX_DISP                =>      HEX_DISP6
730
        );
731
 
732
        DISPHEX7 : decoder_7seg PORT MAP (
733
                NUMBER                  =>      NUMBER7,
734
                HEX_DISP                =>      HEX_DISP7
735
        );
736
 
737
        ps2_kbd_inst : ps2kbd PORT MAP (
738
                keyboard_clk    => PS2_CLK,
739
                keyboard_data   => PS2_DAT,
740
                clock                   => CLOCK_50,
741
                clkdelay                => clk100hz,
742
                reset                   => Rst_n_s,
743
                read                    => ps2_read,
744
                scan_ready              => ps2_scan_ready,
745
                ps2_ascii_code  => ps2_ascii_sig
746
        );
747
 
748
          -- Component instantiation
749
        lcd_inst: lcd PORT MAP (
750
                reset                   => Rst_n_s,
751
                CLOCK_50                => CLOCK_50,
752
                LCD_RS          => LCD_RS,
753
                LCD_EN          => LCD_EN,
754
                LCD_RW          => LCD_RW,
755
                LCD_ON          => LCD_ON,
756
                LCD_DATA                => LCD_DATA(7 DOWNTO 0),
757
                lcd_on_sig      => LCDON_reg,
758
                next_char       => next_char_sig,
759
                char_count      => char_count_sig,
760
                clk400hz                => clk400hz
761
        );
762
 
763
        --
764
        UART_TXD <= 'Z';
765
        DRAM_ADDR <= (others => '0');
766
        DRAM_DQM_0 <= '0';
767
        DRAM_DQM_1 <= '0';
768
        DRAM_DQM_2 <= '0';
769
        DRAM_DQM_3 <= '0';
770
        DRAM_WE_N <= '1';
771
        DRAM_CAS_N <= '1';
772
        DRAM_RAS_N <= '1';
773
        DRAM_CS_N <= '1';
774
        DRAM_BA_0 <= '0';
775
        DRAM_BA_1 <= '0';
776
        DRAM_CLK <= '0';
777
        DRAM_CKE <= '0';
778
        FL_ADDR <= (others => '0');
779
        FL_WE_N <= '1';
780
        FL_RST_N <= '0';
781
        FL_OE_N <= '1';
782
        FL_CE_N <= '1';
783
        AUD_DACDAT <= '0';
784
        AUD_XCK <= '0';
785
        -- Set all bidirectional ports to tri-state
786
        DRAM_DQ     <= (others => 'Z');
787
        FL_DQ       <= (others => 'Z');
788
 
789
        AUD_ADCLRCK <= 'Z';
790
        AUD_DACLRCK <= 'Z';
791
        AUD_BCLK    <= 'Z';
792
        --GPIO_0 <= (others => 'Z');
793
        --GPIO_1 <= (others => 'Z');
794
end;

powered by: WebSVN 2.1.0

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