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_27, -- 27 MHz
|
85 |
|
|
CLOCK_50, -- 50 MHz
|
86 |
|
|
EXT_CLOCK : in std_logic; -- External Clock
|
87 |
|
|
|
88 |
|
|
-- Buttons and switches
|
89 |
|
|
KEY : in std_logic_vector(3 downto 0); -- Push buttons
|
90 |
|
|
SW : in std_logic_vector(9 downto 0); -- Switches
|
91 |
|
|
|
92 |
|
|
-- LED displays
|
93 |
|
|
HEX0, HEX1, HEX2, HEX3 -- 7-segment displays
|
94 |
|
|
: out std_logic_vector(6 downto 0);
|
95 |
|
|
LEDG : out std_logic_vector(7 downto 0); -- Green LEDs
|
96 |
|
|
LEDR : out std_logic_vector(9 downto 0); -- Red LEDs
|
97 |
|
|
|
98 |
|
|
-- RS-232 interface
|
99 |
|
|
UART_TXD : out std_logic; -- UART transmitter
|
100 |
|
|
UART_RXD : in std_logic; -- UART receiver
|
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_DQ : inout std_logic_vector(15 downto 0); -- Data Bus
|
109 |
|
|
DRAM_ADDR : out std_logic_vector(11 downto 0); -- Address Bus
|
110 |
|
|
DRAM_LDQM, -- Low-byte Data Mask
|
111 |
|
|
DRAM_UDQM, -- High-byte Data Mask
|
112 |
|
|
DRAM_WE_N, -- Write Enable
|
113 |
|
|
DRAM_CAS_N, -- Column Address Strobe
|
114 |
|
|
DRAM_RAS_N, -- Row Address Strobe
|
115 |
|
|
DRAM_CS_N, -- Chip Select
|
116 |
|
|
DRAM_BA_0, -- Bank Address 0
|
117 |
|
|
DRAM_BA_1, -- Bank Address 0
|
118 |
|
|
DRAM_CLK, -- Clock
|
119 |
|
|
DRAM_CKE : out std_logic; -- Clock Enable
|
120 |
|
|
|
121 |
|
|
-- FLASH
|
122 |
|
|
FL_DQ : inout std_logic_vector(7 downto 0); -- Data bus
|
123 |
|
|
FL_ADDR : out std_logic_vector(21 downto 0); -- Address bus
|
124 |
|
|
FL_WE_N, -- Write Enable
|
125 |
|
|
FL_RST_N, -- Reset
|
126 |
|
|
FL_OE_N, -- Output Enable
|
127 |
|
|
FL_CE_N : out std_logic; -- Chip Enable
|
128 |
|
|
|
129 |
|
|
-- SRAM
|
130 |
|
|
SRAM_DQ : inout std_logic_vector(15 downto 0); -- Data bus 16 Bits
|
131 |
|
|
SRAM_ADDR : out std_logic_vector(17 downto 0); -- Address bus 18 Bits
|
132 |
|
|
SRAM_UB_N, -- High-byte Data Mask
|
133 |
|
|
SRAM_LB_N, -- Low-byte Data Mask
|
134 |
|
|
SRAM_WE_N, -- Write Enable
|
135 |
|
|
SRAM_CE_N, -- Chip Enable
|
136 |
|
|
SRAM_OE_N : out std_logic; -- Output Enable
|
137 |
|
|
|
138 |
|
|
-- SD card interface
|
139 |
|
|
SD_DAT : in std_logic; -- SD Card Data SD pin 7 "DAT 0/DataOut"
|
140 |
|
|
SD_DAT3 : out std_logic; -- SD Card Data 3 SD pin 1 "DAT 3/nCS"
|
141 |
|
|
SD_CMD : out std_logic; -- SD Card Command SD pin 2 "CMD/DataIn"
|
142 |
|
|
SD_CLK : out std_logic; -- SD Card Clock SD pin 5 "CLK"
|
143 |
|
|
|
144 |
|
|
-- USB JTAG link
|
145 |
|
|
TDI, -- CPLD -> FPGA (data in)
|
146 |
|
|
TCK, -- CPLD -> FPGA (clk)
|
147 |
|
|
TCS : in std_logic; -- CPLD -> FPGA (CS)
|
148 |
|
|
TDO : out std_logic; -- FPGA -> CPLD (data out)
|
149 |
|
|
|
150 |
|
|
-- I2C bus
|
151 |
|
|
I2C_SDAT : inout std_logic; -- I2C Data
|
152 |
|
|
I2C_SCLK : out std_logic; -- I2C Clock
|
153 |
|
|
|
154 |
|
|
-- PS/2 port
|
155 |
|
|
PS2_DAT, -- Data
|
156 |
|
|
PS2_CLK : inout std_logic; -- Clock
|
157 |
|
|
|
158 |
|
|
-- VGA output
|
159 |
|
|
VGA_HS, -- H_SYNC
|
160 |
|
|
VGA_VS : out std_logic; -- SYNC
|
161 |
|
|
VGA_R, -- Red[3:0]
|
162 |
|
|
VGA_G, -- Green[3:0]
|
163 |
|
|
VGA_B : out std_logic_vector(3 downto 0); -- Blue[3:0]
|
164 |
|
|
|
165 |
|
|
-- Audio CODEC
|
166 |
|
|
AUD_ADCLRCK : inout std_logic; -- ADC LR Clock
|
167 |
|
|
AUD_ADCDAT : in std_logic; -- ADC Data
|
168 |
|
|
AUD_DACLRCK : inout std_logic; -- DAC LR Clock
|
169 |
|
|
AUD_DACDAT : out std_logic; -- DAC Data
|
170 |
|
|
AUD_BCLK : inout std_logic; -- Bit-Stream Clock
|
171 |
|
|
AUD_XCK : out std_logic; -- Chip Clock
|
172 |
|
|
|
173 |
|
|
-- General-purpose I/O
|
174 |
|
|
GPIO_0, -- GPIO Connection 0
|
175 |
|
|
GPIO_1 : inout std_logic_vector(35 downto 0) -- GPIO Connection 1
|
176 |
|
|
);
|
177 |
|
|
end Z80SOC;
|
178 |
|
|
|
179 |
|
|
architecture rtl of Z80SOC is
|
180 |
|
|
|
181 |
|
|
component T80se
|
182 |
|
|
generic(
|
183 |
|
|
Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
|
184 |
|
|
T2Write : integer := 1; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
|
185 |
|
|
IOWait : integer := 1 -- 0 => Siomngle cycle I/O, 1 => Std I/O cycle
|
186 |
|
|
);
|
187 |
|
|
port(
|
188 |
|
|
RESET_n : in std_logic;
|
189 |
|
|
CLK_n : in std_logic;
|
190 |
|
|
CLKEN : in std_logic;
|
191 |
|
|
WAIT_n : in std_logic;
|
192 |
|
|
INT_n : in std_logic;
|
193 |
|
|
NMI_n : in std_logic;
|
194 |
|
|
BUSRQ_n : in std_logic;
|
195 |
|
|
M1_n : out std_logic;
|
196 |
|
|
MREQ_n : out std_logic;
|
197 |
|
|
IORQ_n : out std_logic;
|
198 |
|
|
RD_n : out std_logic;
|
199 |
|
|
WR_n : out std_logic;
|
200 |
|
|
RFSH_n : out std_logic;
|
201 |
|
|
HALT_n : out std_logic;
|
202 |
|
|
BUSAK_n : out std_logic;
|
203 |
|
|
A : out std_logic_vector(15 downto 0);
|
204 |
|
|
DI : in std_logic_vector(7 downto 0);
|
205 |
|
|
DO : out std_logic_vector(7 downto 0)
|
206 |
|
|
);
|
207 |
|
|
end component;
|
208 |
|
|
|
209 |
|
|
component rom
|
210 |
|
|
port (
|
211 |
|
|
clock : in std_logic;
|
212 |
|
|
address : in std_logic_vector(13 downto 0);
|
213 |
|
|
q : out std_logic_vector(7 downto 0));
|
214 |
|
|
end component;
|
215 |
|
|
|
216 |
|
|
component clk_div
|
217 |
|
|
PORT
|
218 |
|
|
(
|
219 |
|
|
clock_in_50Mhz : in std_logic;
|
220 |
|
|
clock_25MHz : out std_logic;
|
221 |
|
|
clock_10MHz : out std_logic;
|
222 |
|
|
clock_357MHz : out std_logic;
|
223 |
|
|
clock_1MHz : out std_logic;
|
224 |
|
|
clock_100KHz : out std_logic;
|
225 |
|
|
clock_10KHz : out std_logic;
|
226 |
|
|
clock_1KHz : out std_logic;
|
227 |
|
|
clock_100Hz : out std_logic;
|
228 |
|
|
clock_10Hz : out std_logic;
|
229 |
|
|
clock_1Hz : out std_logic);
|
230 |
|
|
end component;
|
231 |
|
|
|
232 |
|
|
component decoder_7seg
|
233 |
|
|
port (
|
234 |
|
|
NUMBER : in std_logic_vector(3 downto 0);
|
235 |
|
|
HEX_DISP : out std_logic_vector(6 downto 0));
|
236 |
|
|
end component;
|
237 |
|
|
|
238 |
|
|
component ps2kbd
|
239 |
|
|
port (
|
240 |
|
|
keyboard_clk : inout std_logic;
|
241 |
|
|
keyboard_data : inout std_logic;
|
242 |
|
|
clock : in std_logic;
|
243 |
|
|
clkdelay : in std_logic;
|
244 |
|
|
reset : in std_logic;
|
245 |
|
|
read : in std_logic;
|
246 |
|
|
scan_ready : out std_logic;
|
247 |
|
|
ps2_ascii_code : out std_logic_vector(7 downto 0));
|
248 |
|
|
end component;
|
249 |
|
|
|
250 |
|
|
component vram
|
251 |
|
|
port
|
252 |
|
|
(
|
253 |
|
|
rdaddress : in std_logic_vector (12 downto 0);
|
254 |
|
|
wraddress : in std_logic_vector (12 downto 0);
|
255 |
|
|
rdclock : in std_logic;
|
256 |
|
|
wrclock : in std_logic;
|
257 |
|
|
data : in std_logic_vector (7 downto 0);
|
258 |
|
|
wren : in std_logic;
|
259 |
|
|
q : out std_logic_vector (7 downto 0)
|
260 |
|
|
);
|
261 |
|
|
end component;
|
262 |
|
|
|
263 |
|
|
component charram
|
264 |
|
|
port (
|
265 |
|
|
data : in std_logic_vector (7 downto 0);
|
266 |
|
|
rdaddress : in std_logic_vector (10 downto 0);
|
267 |
|
|
rdclock : in std_logic ;
|
268 |
|
|
wraddress : in std_logic_vector (10 downto 0);
|
269 |
|
|
wrclock : in std_logic;
|
270 |
|
|
wren : in std_logic;
|
271 |
|
|
q : out std_logic_vector (7 downto 0));
|
272 |
|
|
end component;
|
273 |
|
|
|
274 |
|
|
COMPONENT video
|
275 |
|
|
PORT (
|
276 |
|
|
CLOCK_25 : in std_logic;
|
277 |
|
|
VRAM_DATA : in std_logic_vector(7 downto 0);
|
278 |
|
|
VRAM_ADDR : out std_logic_vector(13 downto 0);
|
279 |
|
|
VRAM_CLOCK : out std_logic;
|
280 |
|
|
VRAM_WREN : out std_logic;
|
281 |
|
|
CRAM_DATA : in std_logic_vector(7 downto 0);
|
282 |
|
|
CRAM_ADDR : out std_logic_vector(10 downto 0);
|
283 |
|
|
CRAM_WEB : out std_logic;
|
284 |
|
|
VGA_R : out std_logic_vector(3 downto 0);
|
285 |
|
|
VGA_G : out std_logic_vector(3 downto 0);
|
286 |
|
|
VGA_B : out std_logic_vector(3 downto 0);
|
287 |
|
|
VGA_HS : out std_logic;
|
288 |
|
|
VGA_VS : out std_logic);
|
289 |
|
|
END COMPONENT;
|
290 |
|
|
|
291 |
|
|
signal MREQ_n : std_logic;
|
292 |
|
|
signal IORQ_n : std_logic;
|
293 |
|
|
signal RD_n : std_logic;
|
294 |
|
|
signal WR_n : std_logic;
|
295 |
|
|
signal MWr_n : std_logic;
|
296 |
|
|
signal Rst_n_s : std_logic;
|
297 |
|
|
signal Clk_Z80 : std_logic;
|
298 |
|
|
signal DI_CPU : std_logic_vector(7 downto 0);
|
299 |
|
|
signal DO_CPU : std_logic_vector(7 downto 0);
|
300 |
|
|
signal A : std_logic_vector(15 downto 0);
|
301 |
|
|
signal One : std_logic;
|
302 |
|
|
|
303 |
|
|
signal D_ROM : std_logic_vector(7 downto 0);
|
304 |
|
|
signal rom_data : std_logic_vector(7 downto 0);
|
305 |
|
|
signal rom_wren : std_logic;
|
306 |
|
|
|
307 |
|
|
signal clk_count_400hz : std_logic_vector(19 downto 0);
|
308 |
|
|
signal clk100mhz : std_logic;
|
309 |
|
|
signal clk25mhz : std_logic;
|
310 |
|
|
signal clk1mhz : std_logic;
|
311 |
|
|
signal clk10mhz : std_logic;
|
312 |
|
|
signal clk400hz : std_logic;
|
313 |
|
|
signal clk100hz : std_logic;
|
314 |
|
|
signal clk10hz : std_logic;
|
315 |
|
|
signal clk1hz : std_logic;
|
316 |
|
|
signal clk357mhz : std_logic;
|
317 |
|
|
signal clk1khz : std_logic;
|
318 |
|
|
|
319 |
|
|
signal HEX_DISP0 : std_logic_vector(6 downto 0);
|
320 |
|
|
signal HEX_DISP1 : std_logic_vector(6 downto 0);
|
321 |
|
|
signal HEX_DISP2 : std_logic_vector(6 downto 0);
|
322 |
|
|
signal HEX_DISP3 : std_logic_vector(6 downto 0);
|
323 |
|
|
|
324 |
|
|
signal NUMBER0 : std_logic_vector(3 downto 0);
|
325 |
|
|
signal NUMBER1 : std_logic_vector(3 downto 0);
|
326 |
|
|
signal NUMBER2 : std_logic_vector(3 downto 0);
|
327 |
|
|
signal NUMBER3 : std_logic_vector(3 downto 0);
|
328 |
|
|
|
329 |
|
|
signal vram_addra : std_logic_vector(15 downto 0);
|
330 |
|
|
signal vram_addrb : std_logic_vector(13 downto 0);
|
331 |
|
|
signal vram_dina : std_logic_vector(7 downto 0);
|
332 |
|
|
signal vram_dinb : std_logic_vector(7 downto 0);
|
333 |
|
|
signal vram_douta : std_logic_vector(7 downto 0);
|
334 |
|
|
signal vram_doutb : std_logic_vector(7 downto 0);
|
335 |
|
|
signal vram_wea : std_logic; --_vector(0 downto 0);
|
336 |
|
|
signal vram_web : std_logic; --_vector(0 downto 0);
|
337 |
|
|
signal vram_clka : std_logic;
|
338 |
|
|
signal vram_clkb : std_logic;
|
339 |
|
|
|
340 |
|
|
signal cram_addra : std_logic_vector(15 downto 0);
|
341 |
|
|
signal cram_addrb : std_logic_vector(15 downto 0);
|
342 |
|
|
signal cram_dina : std_logic_vector(7 downto 0);
|
343 |
|
|
signal cram_dinb : std_logic_vector(7 downto 0);
|
344 |
|
|
signal cram_douta : std_logic_vector(7 downto 0);
|
345 |
|
|
signal cram_doutb : std_logic_vector(7 downto 0);
|
346 |
|
|
signal cram_wea : std_logic;
|
347 |
|
|
signal cram_web : std_logic;
|
348 |
|
|
signal cram_clka : std_logic;
|
349 |
|
|
signal cram_clkb : std_logic;
|
350 |
|
|
|
351 |
|
|
-- PS/2 Keyboard
|
352 |
|
|
signal ps2_read : std_logic;
|
353 |
|
|
signal ps2_scan_ready : std_logic;
|
354 |
|
|
signal ps2_ascii_sig : std_logic_vector(7 downto 0);
|
355 |
|
|
signal ps2_ascii_reg1 : std_logic_vector(7 downto 0);
|
356 |
|
|
signal ps2_ascii_reg : std_logic_vector(7 downto 0);
|
357 |
|
|
|
358 |
|
|
signal char_count_sig : std_logic_vector(4 downto 0);
|
359 |
|
|
signal next_char_sig : std_logic_vector(7 downto 0);
|
360 |
|
|
signal temp : std_logic;
|
361 |
|
|
|
362 |
|
|
signal Z80SOC_Arch_reg : std_logic_vector(2 downto 0) := Z80SOC_Arch_value;
|
363 |
|
|
-- "000" = DE1, "001" = S3E, "010" = DE2115
|
364 |
|
|
signal RAMTOP_reg : std_logic_vector(15 downto 0) := RAMTOP_value;
|
365 |
|
|
signal RAMBOTT_reg : std_logic_vector(15 downto 0) := RAMBOTT_value;
|
366 |
|
|
signal VRAM_reg : std_logic_vector(15 downto 0) := VRAM_value;
|
367 |
|
|
signal STACK_reg : std_logic_vector(15 downto 0) := STACK_value;
|
368 |
|
|
signal CHARRAM_reg : std_logic_vector(15 downto 0) := CHARRAM_value;
|
369 |
|
|
signal VIDCOLS_reg : std_logic_vector(7 downto 0) := conv_std_logic_vector(vid_cols, 8);
|
370 |
|
|
signal VIDROWS_reg : std_logic_vector(7 downto 0) := conv_std_logic_vector(vid_lines, 8);
|
371 |
|
|
signal STDOUT_reg : std_logic_vector(7 downto 0);
|
372 |
|
|
signal VID_CURSOR : std_logic_vector(15 downto 0);
|
373 |
|
|
signal RNDNUMBER_reg : std_logic_vector (random_width-1 downto 0);
|
374 |
|
|
|
375 |
|
|
begin
|
376 |
|
|
|
377 |
|
|
--VGA_BLANK_N <= '1';
|
378 |
|
|
--VGA_CLK <= clk25mhz;
|
379 |
|
|
HEX0 <= HEX_DISP0;
|
380 |
|
|
HEX1 <= HEX_DISP1;
|
381 |
|
|
HEX2 <= HEX_DISP2;
|
382 |
|
|
HEX3 <= HEX_DISP3;
|
383 |
|
|
|
384 |
|
|
Rst_n_s <= not SW(9);
|
385 |
|
|
--STDOUT_reg <= DO_CPU when (A = x"57CD" and Wr_n = '0' and MReq_n = '0');
|
386 |
|
|
--CURX_reg <= DO_CPU when (A = x"57CF" and Wr_n = '0' and MReq_n = '0');
|
387 |
|
|
--CURY_reg <= DO_CPU when (A = x"57CE" and Wr_n = '0' and MReq_n = '0');
|
388 |
|
|
-- Turbo 10Mhz
|
389 |
|
|
--Clk_Z80 <= clk357mhz when SW(16) = '0' else clk10mhz;
|
390 |
|
|
LEDR(8) <= SW(8);
|
391 |
|
|
LEDR(9) <= SW(9);
|
392 |
|
|
Clk_Z80 <= clk10mhz when SW(8) = '1' else
|
393 |
|
|
clk357mhz;
|
394 |
|
|
|
395 |
|
|
-- Write into VRAM and System Variables
|
396 |
|
|
vram_addra <= A - VRAM_value;
|
397 |
|
|
vram_dina <= DO_CPU;
|
398 |
|
|
vram_wea <= '0' when (A >= VRAM_value and A < (VRAM_value + (vid_cols * vid_lines)) and Wr_n = '0' and MReq_n = '0') else
|
399 |
|
|
'1';
|
400 |
|
|
|
401 |
|
|
-- Write into char ram
|
402 |
|
|
cram_addra <= A - CHARRAM_value;
|
403 |
|
|
cram_dina <= DO_CPU;
|
404 |
|
|
cram_wea <= '0' when (A >= CHARRAM_value and A < RAMBOTT_value and Wr_n = '0' and MReq_n = '0') else '1';
|
405 |
|
|
|
406 |
|
|
-- SRAM control signals
|
407 |
|
|
-- SRAM will store data for video, characters patterns and RAM (only on DE1 version)
|
408 |
|
|
-- Due to limitation in dual-port block rams on this platform
|
409 |
|
|
|
410 |
|
|
SRAM_ADDR(15 downto 0) <= A - VRAM_value;
|
411 |
|
|
SRAM_DQ(7 downto 0) <= DO_CPU when (Wr_n = '0' and MREQ_n = '0' and A >= VRAM_value) else
|
412 |
|
|
(others => 'Z');
|
413 |
|
|
SRAM_WE_N <= '0' when (Wr_n = '0' and MREQ_n = '0' and A >= VRAM_value) else '1';
|
414 |
|
|
SRAM_OE_N <= '0' when (Rd_n = '0' and MREQ_n = '0' and A >= VRAM_value) else '1';
|
415 |
|
|
SRAM_DQ(15 downto 8) <= (others => 'Z');
|
416 |
|
|
--SRAM_ADDR(19 downto 16) <= "0000";
|
417 |
|
|
SRAM_UB_N <= '1';
|
418 |
|
|
SRAM_LB_N <= '0';
|
419 |
|
|
SRAM_CE_N <= '0';
|
420 |
|
|
|
421 |
|
|
-- Input to Z80
|
422 |
|
|
DI_CPU <= ("00000" & Z80SOC_Arch_reg) when (Rd_n = '0' and MREQ_n = '0' and A = Z80SOC_Arch_addr) else
|
423 |
|
|
RNDNUMBER_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = x"57C9") else
|
424 |
|
|
RNDNUMBER_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and A = x"57CA") else
|
425 |
|
|
ps2_ascii_reg when (Rd_n = '0' and MREQ_n = '0' and A = KEYPRESS_addr) else
|
426 |
|
|
VIDCOLS_reg when (Rd_n = '0' and MREQ_n = '0' and A = x"57CC") else
|
427 |
|
|
VIDROWS_reg when (Rd_n = '0' and MREQ_n = '0' and A = x"57CB") else
|
428 |
|
|
STACK_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = STACK_addr) else
|
429 |
|
|
STACK_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = STACK_addr + 1)) else
|
430 |
|
|
RAMTOP_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = RAMTOP_addr) else
|
431 |
|
|
RAMTOP_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = RAMTOP_addr + 1)) else
|
432 |
|
|
RAMBOTT_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = RAMBOTT_addr) else
|
433 |
|
|
RAMBOTT_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = RAMBOTT_addr + 1)) else
|
434 |
|
|
VRAM_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = VRAM_addr) else
|
435 |
|
|
VRAM_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = VRAM_addr + 1)) else
|
436 |
|
|
CHARRAM_reg(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and A = CHARRAM_addr) else
|
437 |
|
|
CHARRAM_reg(15 downto 8) when (Rd_n = '0' and MREQ_n = '0' and (A = CHARRAM_addr + 1)) else
|
438 |
|
|
D_ROM when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A < VRAM_value) else
|
439 |
|
|
SRAM_DQ(7 downto 0) when (Rd_n = '0' and MREQ_n = '0' and IORQ_n = '1' and A >= VRAM_value) else
|
440 |
|
|
SW(7 downto 0) when (Rd_n = '0' and MREQ_n = '1' and IORQ_n = '0' and A(7 downto 0) = x"20") else
|
441 |
|
|
("0000" & not KEY) when (Rd_n = '0' and MREQ_n = '1' and IORQ_n = '0' and A(7 downto 0) = x"30") else
|
442 |
|
|
"ZZZZZZZZ";
|
443 |
|
|
|
444 |
|
|
-- Process to latch leds and hex displays
|
445 |
|
|
pinout_process: process(Clk_Z80)
|
446 |
|
|
variable NUMBER0_sig : std_logic_vector(3 downto 0);
|
447 |
|
|
variable NUMBER1_sig : std_logic_vector(3 downto 0);
|
448 |
|
|
variable NUMBER2_sig : std_logic_vector(3 downto 0);
|
449 |
|
|
variable NUMBER3_sig : std_logic_vector(3 downto 0);
|
450 |
|
|
variable LEDG_sig : std_logic_vector(7 downto 0);
|
451 |
|
|
variable LEDR_sig : std_logic_vector(7 downto 0);
|
452 |
|
|
|
453 |
|
|
begin
|
454 |
|
|
if Clk_Z80'event and Clk_Z80 = '1' then
|
455 |
|
|
if IORQ_n = '0' and MREQ_n = '1' and Wr_n = '0' then
|
456 |
|
|
-- LEDG
|
457 |
|
|
if A(7 downto 0) = x"01" then
|
458 |
|
|
LEDG_sig := DO_CPU;
|
459 |
|
|
-- LEDR
|
460 |
|
|
elsif A(7 downto 0) = x"02" then
|
461 |
|
|
LEDR_sig(7 downto 0) := DO_CPU;
|
462 |
|
|
-- HEX1 and HEX0
|
463 |
|
|
elsif A(7 downto 0) = x"10" then
|
464 |
|
|
NUMBER0_sig := DO_CPU(3 downto 0);
|
465 |
|
|
NUMBER1_sig := DO_CPU(7 downto 4);
|
466 |
|
|
-- HEX3 and HEX2
|
467 |
|
|
elsif A(7 downto 0) = x"11" then
|
468 |
|
|
NUMBER2_sig := DO_CPU(3 downto 0);
|
469 |
|
|
NUMBER3_sig := DO_CPU(7 downto 4);
|
470 |
|
|
end if;
|
471 |
|
|
--else
|
472 |
|
|
-- DEBUG ADDRESS BUSS
|
473 |
|
|
-- LEDR_sig(7 DOWNTO 0) := A;
|
474 |
|
|
end if;
|
475 |
|
|
end if;
|
476 |
|
|
|
477 |
|
|
-- Latches the signals
|
478 |
|
|
LEDR(7 downto 0) <= LEDR_sig;
|
479 |
|
|
LEDG(7 downto 0) <= LEDG_sig;
|
480 |
|
|
NUMBER0 <= NUMBER0_sig;
|
481 |
|
|
NUMBER1 <= NUMBER1_sig;
|
482 |
|
|
NUMBER2 <= NUMBER2_sig;
|
483 |
|
|
NUMBER3 <= NUMBER3_sig;
|
484 |
|
|
end process;
|
485 |
|
|
|
486 |
|
|
-- the following three processes deals with different clock domain signals
|
487 |
|
|
-- to interface with the PS/2 keyboard
|
488 |
|
|
ps2_process1: process(CLOCK_50)
|
489 |
|
|
begin
|
490 |
|
|
if CLOCK_50'event and CLOCK_50 = '1' then
|
491 |
|
|
if ps2_read = '1' then
|
492 |
|
|
if ps2_ascii_sig /= x"FF" then
|
493 |
|
|
ps2_read <= '0';
|
494 |
|
|
ps2_ascii_reg1 <= "00000000";
|
495 |
|
|
end if;
|
496 |
|
|
elsif ps2_scan_ready = '1' then
|
497 |
|
|
if ps2_ascii_sig = x"FF" then
|
498 |
|
|
ps2_read <= '1';
|
499 |
|
|
else
|
500 |
|
|
ps2_ascii_reg1 <= ps2_ascii_sig;
|
501 |
|
|
end if;
|
502 |
|
|
end if;
|
503 |
|
|
end if;
|
504 |
|
|
end process;
|
505 |
|
|
|
506 |
|
|
ps2_process2: process(Clk_Z80)
|
507 |
|
|
begin
|
508 |
|
|
if Clk_Z80'event and Clk_Z80 = '1' then
|
509 |
|
|
ps2_ascii_reg <= ps2_ascii_reg1;
|
510 |
|
|
end if;
|
511 |
|
|
end process;
|
512 |
|
|
|
513 |
|
|
random: process(CLOCK_50)
|
514 |
|
|
variable rand_temp : std_logic_vector(random_width-1 downto 0):=(random_width-1 => '1',others => '0');
|
515 |
|
|
variable temp : std_logic := '0';
|
516 |
|
|
begin
|
517 |
|
|
if(rising_edge(CLOCK_50)) then
|
518 |
|
|
temp := rand_temp(random_width-1) xor rand_temp(random_width-2);
|
519 |
|
|
rand_temp(random_width-1 downto 1) := rand_temp(random_width-2 downto 0);
|
520 |
|
|
rand_temp(0) := temp;
|
521 |
|
|
end if;
|
522 |
|
|
RNDNUMBER_reg <= rand_temp;
|
523 |
|
|
end process;
|
524 |
|
|
|
525 |
|
|
One <= '1';
|
526 |
|
|
z80_inst: T80se
|
527 |
|
|
port map (
|
528 |
|
|
M1_n => open,
|
529 |
|
|
MREQ_n => MREQ_n,
|
530 |
|
|
IORQ_n => IORQ_n,
|
531 |
|
|
RD_n => Rd_n,
|
532 |
|
|
WR_n => Wr_n,
|
533 |
|
|
RFSH_n => open,
|
534 |
|
|
HALT_n => open,
|
535 |
|
|
WAIT_n => One,
|
536 |
|
|
INT_n => One,
|
537 |
|
|
NMI_n => One,
|
538 |
|
|
RESET_n => Rst_n_s,
|
539 |
|
|
BUSRQ_n => One,
|
540 |
|
|
BUSAK_n => open,
|
541 |
|
|
CLK_n => Clk_Z80,
|
542 |
|
|
CLKEN => One,
|
543 |
|
|
A => A,
|
544 |
|
|
DI => DI_CPU,
|
545 |
|
|
DO => DO_CPU
|
546 |
|
|
);
|
547 |
|
|
|
548 |
|
|
video_inst: video
|
549 |
|
|
port map (
|
550 |
|
|
CLOCK_25 => clk25mhz,
|
551 |
|
|
VRAM_DATA => vram_doutb,
|
552 |
|
|
VRAM_ADDR => vram_addrb(13 downto 0),
|
553 |
|
|
VRAM_CLOCK => vram_clkb,
|
554 |
|
|
VRAM_WREN => vram_web,
|
555 |
|
|
CRAM_DATA => cram_doutb,
|
556 |
|
|
CRAM_ADDR => cram_addrb(10 downto 0),
|
557 |
|
|
CRAM_WEB => cram_web,
|
558 |
|
|
VGA_R => VGA_R(3 downto 0),
|
559 |
|
|
VGA_G => VGA_G(3 downto 0),
|
560 |
|
|
VGA_B => VGA_B(3 downto 0),
|
561 |
|
|
VGA_HS => VGA_HS,
|
562 |
|
|
VGA_VS => VGA_VS
|
563 |
|
|
);
|
564 |
|
|
|
565 |
|
|
vram_inst : vram
|
566 |
|
|
port map (
|
567 |
|
|
rdclock => vram_clkb,
|
568 |
|
|
wrclock => Clk_Z80,
|
569 |
|
|
wren => not vram_wea, -- inverted logic so code is similar to SRAM and S3E port
|
570 |
|
|
wraddress => vram_addra(12 downto 0),
|
571 |
|
|
rdaddress => vram_addrb(12 downto 0),
|
572 |
|
|
data => vram_dina,
|
573 |
|
|
q => vram_doutb
|
574 |
|
|
);
|
575 |
|
|
|
576 |
|
|
cram: charram
|
577 |
|
|
port map (
|
578 |
|
|
rdaddress => cram_addrb(10 downto 0),
|
579 |
|
|
wraddress => cram_addra(10 downto 0),
|
580 |
|
|
wrclock => Clk_Z80,
|
581 |
|
|
rdclock => vram_clkb,
|
582 |
|
|
data => cram_dina,
|
583 |
|
|
q => cram_doutb,
|
584 |
|
|
wren => NOT cram_wea
|
585 |
|
|
);
|
586 |
|
|
|
587 |
|
|
rom_inst: rom
|
588 |
|
|
port map (
|
589 |
|
|
clock => clk25mhz,
|
590 |
|
|
address => A(13 downto 0),
|
591 |
|
|
q => D_ROM
|
592 |
|
|
);
|
593 |
|
|
|
594 |
|
|
clkdiv_inst: clk_div
|
595 |
|
|
port map (
|
596 |
|
|
clock_in_50mhz => CLOCK_50,
|
597 |
|
|
clock_25mhz => clk25mhz,
|
598 |
|
|
clock_10MHz => clk10mhz,
|
599 |
|
|
clock_357Mhz => clk357mhz,
|
600 |
|
|
clock_1MHz => clk1mhz,
|
601 |
|
|
clock_100KHz => open,
|
602 |
|
|
clock_10KHz => open,
|
603 |
|
|
clock_1KHz => clk1khz,
|
604 |
|
|
clock_100Hz => clk100hz,
|
605 |
|
|
clock_10Hz => clk10hz,
|
606 |
|
|
clock_1Hz => clk1hz
|
607 |
|
|
);
|
608 |
|
|
|
609 |
|
|
DISPHEX0 : decoder_7seg
|
610 |
|
|
port map (
|
611 |
|
|
NUMBER => NUMBER0,
|
612 |
|
|
HEX_DISP => HEX_DISP0
|
613 |
|
|
);
|
614 |
|
|
|
615 |
|
|
DISPHEX1 : decoder_7seg
|
616 |
|
|
port map (
|
617 |
|
|
NUMBER => NUMBER1,
|
618 |
|
|
HEX_DISP => HEX_DISP1
|
619 |
|
|
);
|
620 |
|
|
|
621 |
|
|
DISPHEX2 : decoder_7seg
|
622 |
|
|
port map (
|
623 |
|
|
NUMBER => NUMBER2,
|
624 |
|
|
HEX_DISP => HEX_DISP2
|
625 |
|
|
);
|
626 |
|
|
|
627 |
|
|
DISPHEX3 : decoder_7seg
|
628 |
|
|
port map (
|
629 |
|
|
NUMBER => NUMBER3,
|
630 |
|
|
HEX_DISP => HEX_DISP3
|
631 |
|
|
);
|
632 |
|
|
|
633 |
|
|
ps2_kbd_inst : ps2kbd
|
634 |
|
|
port map (
|
635 |
|
|
keyboard_clk => PS2_CLK,
|
636 |
|
|
keyboard_data => PS2_DAT,
|
637 |
|
|
clock => CLOCK_50,
|
638 |
|
|
clkdelay => clk100hz,
|
639 |
|
|
reset => Rst_n_s,
|
640 |
|
|
read => ps2_read,
|
641 |
|
|
scan_ready => ps2_scan_ready,
|
642 |
|
|
ps2_ascii_code => ps2_ascii_sig
|
643 |
|
|
);
|
644 |
|
|
|
645 |
|
|
--
|
646 |
|
|
SRAM_DQ(15 downto 8) <= (others => 'Z');
|
647 |
|
|
SRAM_ADDR(17 downto 16) <= "00";
|
648 |
|
|
SRAM_UB_N <= '1';
|
649 |
|
|
SRAM_LB_N <= '0';
|
650 |
|
|
--
|
651 |
|
|
UART_TXD <= 'Z';
|
652 |
|
|
DRAM_ADDR <= (others => '0');
|
653 |
|
|
DRAM_LDQM <= '0';
|
654 |
|
|
DRAM_UDQM <= '0';
|
655 |
|
|
DRAM_WE_N <= '1';
|
656 |
|
|
DRAM_CAS_N <= '1';
|
657 |
|
|
DRAM_RAS_N <= '1';
|
658 |
|
|
DRAM_CS_N <= '1';
|
659 |
|
|
DRAM_BA_0 <= '0';
|
660 |
|
|
DRAM_BA_1 <= '0';
|
661 |
|
|
DRAM_CLK <= '0';
|
662 |
|
|
DRAM_CKE <= '0';
|
663 |
|
|
FL_ADDR <= (others => '0');
|
664 |
|
|
FL_WE_N <= '1';
|
665 |
|
|
FL_RST_N <= '0';
|
666 |
|
|
FL_OE_N <= '1';
|
667 |
|
|
FL_CE_N <= '1';
|
668 |
|
|
TDO <= '0';
|
669 |
|
|
I2C_SCLK <= '0';
|
670 |
|
|
AUD_DACDAT <= '0';
|
671 |
|
|
AUD_XCK <= '0';
|
672 |
|
|
-- Set all bidirectional ports to tri-state
|
673 |
|
|
DRAM_DQ <= (others => 'Z');
|
674 |
|
|
FL_DQ <= (others => 'Z');
|
675 |
|
|
I2C_SDAT <= 'Z';
|
676 |
|
|
AUD_ADCLRCK <= 'Z';
|
677 |
|
|
AUD_DACLRCK <= 'Z';
|
678 |
|
|
AUD_BCLK <= 'Z';
|
679 |
|
|
GPIO_0 <= (others => 'Z');
|
680 |
|
|
GPIO_1 <= (others => 'Z');
|
681 |
|
|
end;
|