| 1 |
46 |
rrred |
--
|
| 2 |
|
|
-- Z80 compatible microprocessor core, asynchronous top level
|
| 3 |
|
|
--
|
| 4 |
|
|
-- Version : 0247
|
| 5 |
|
|
--
|
| 6 |
|
|
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
|
| 7 |
|
|
--
|
| 8 |
|
|
-- All rights reserved
|
| 9 |
|
|
--
|
| 10 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
| 11 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
| 12 |
|
|
--
|
| 13 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
| 14 |
|
|
-- this list of conditions and the following disclaimer.
|
| 15 |
|
|
--
|
| 16 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
| 17 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
| 18 |
|
|
-- documentation and/or other materials provided with the distribution.
|
| 19 |
|
|
--
|
| 20 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
| 21 |
|
|
-- be used to endorse or promote products derived from this software without
|
| 22 |
|
|
-- specific prior written permission.
|
| 23 |
|
|
--
|
| 24 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 25 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
| 26 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 27 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
| 28 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 29 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 30 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 31 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 32 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 33 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 34 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
| 35 |
|
|
--
|
| 36 |
|
|
-- Please report bugs to the author, but before you do so, please
|
| 37 |
|
|
-- make sure that this is not a derivative work and that
|
| 38 |
|
|
-- you have the latest version of this file.
|
| 39 |
|
|
--
|
| 40 |
|
|
-- The latest version of this file can be found at:
|
| 41 |
|
|
-- http://www.opencores.org/cvsweb.shtml/t80/
|
| 42 |
|
|
--
|
| 43 |
|
|
-- Limitations :
|
| 44 |
|
|
--
|
| 45 |
|
|
-- File history :
|
| 46 |
|
|
--
|
| 47 |
|
|
-- 0208 : First complete release
|
| 48 |
|
|
--
|
| 49 |
|
|
-- 0211 : Fixed interrupt cycle
|
| 50 |
|
|
--
|
| 51 |
|
|
-- 0235 : Updated for T80 interface change
|
| 52 |
|
|
--
|
| 53 |
|
|
-- 0238 : Updated for T80 interface change
|
| 54 |
|
|
--
|
| 55 |
|
|
-- 0240 : Updated for T80 interface change
|
| 56 |
|
|
--
|
| 57 |
|
|
-- 0242 : Updated for T80 interface change
|
| 58 |
|
|
--
|
| 59 |
|
|
-- 0247 : Fixed bus req/ack cycle
|
| 60 |
|
|
--
|
| 61 |
|
|
|
| 62 |
|
|
library IEEE;
|
| 63 |
|
|
use IEEE.std_logic_1164.all;
|
| 64 |
|
|
use IEEE.numeric_std.all;
|
| 65 |
|
|
use work.T80_Pack.all;
|
| 66 |
|
|
|
| 67 |
|
|
entity T80a is
|
| 68 |
|
|
generic(
|
| 69 |
|
|
Mode : integer := 0 -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
|
| 70 |
|
|
);
|
| 71 |
|
|
port(
|
| 72 |
|
|
RESET_n : in std_logic;
|
| 73 |
|
|
CLK_n : in std_logic;
|
| 74 |
|
|
WAIT_n : in std_logic;
|
| 75 |
|
|
INT_n : in std_logic;
|
| 76 |
|
|
NMI_n : in std_logic;
|
| 77 |
|
|
BUSRQ_n : in std_logic;
|
| 78 |
|
|
M1_n : out std_logic;
|
| 79 |
|
|
MREQ_n : out std_logic;
|
| 80 |
|
|
IORQ_n : out std_logic;
|
| 81 |
|
|
RD_n : out std_logic;
|
| 82 |
|
|
WR_n : out std_logic;
|
| 83 |
|
|
RFSH_n : out std_logic;
|
| 84 |
|
|
HALT_n : out std_logic;
|
| 85 |
|
|
BUSAK_n : out std_logic;
|
| 86 |
|
|
A : out std_logic_vector(15 downto 0);
|
| 87 |
|
|
D : inout std_logic_vector(7 downto 0)
|
| 88 |
|
|
);
|
| 89 |
|
|
end T80a;
|
| 90 |
|
|
|
| 91 |
|
|
architecture rtl of T80a is
|
| 92 |
|
|
|
| 93 |
|
|
signal CEN : std_logic;
|
| 94 |
|
|
signal Reset_s : std_logic;
|
| 95 |
|
|
signal IntCycle_n : std_logic;
|
| 96 |
|
|
signal IORQ : std_logic;
|
| 97 |
|
|
signal NoRead : std_logic;
|
| 98 |
|
|
signal Write : std_logic;
|
| 99 |
|
|
signal MREQ : std_logic;
|
| 100 |
|
|
signal MReq_Inhibit : std_logic;
|
| 101 |
|
|
signal Req_Inhibit : std_logic;
|
| 102 |
|
|
signal RD : std_logic;
|
| 103 |
|
|
signal MREQ_n_i : std_logic;
|
| 104 |
|
|
signal IORQ_n_i : std_logic;
|
| 105 |
|
|
signal RD_n_i : std_logic;
|
| 106 |
|
|
signal WR_n_i : std_logic;
|
| 107 |
|
|
signal RFSH_n_i : std_logic;
|
| 108 |
|
|
signal BUSAK_n_i : std_logic;
|
| 109 |
|
|
signal A_i : std_logic_vector(15 downto 0);
|
| 110 |
|
|
signal DO : std_logic_vector(7 downto 0);
|
| 111 |
|
|
signal DI_Reg : std_logic_vector (7 downto 0); -- Input synchroniser
|
| 112 |
|
|
signal Wait_s : std_logic;
|
| 113 |
|
|
signal MCycle : std_logic_vector(2 downto 0);
|
| 114 |
|
|
signal TState : std_logic_vector(2 downto 0);
|
| 115 |
|
|
|
| 116 |
|
|
begin
|
| 117 |
|
|
|
| 118 |
|
|
CEN <= '1';
|
| 119 |
|
|
|
| 120 |
|
|
BUSAK_n <= BUSAK_n_i;
|
| 121 |
|
|
MREQ_n_i <= not MREQ or (Req_Inhibit and MReq_Inhibit);
|
| 122 |
|
|
RD_n_i <= not RD or Req_Inhibit;
|
| 123 |
|
|
|
| 124 |
|
|
MREQ_n <= MREQ_n_i when BUSAK_n_i = '1' else 'Z';
|
| 125 |
|
|
IORQ_n <= IORQ_n_i when BUSAK_n_i = '1' else 'Z';
|
| 126 |
|
|
RD_n <= RD_n_i when BUSAK_n_i = '1' else 'Z';
|
| 127 |
|
|
WR_n <= WR_n_i when BUSAK_n_i = '1' else 'Z';
|
| 128 |
|
|
RFSH_n <= RFSH_n_i when BUSAK_n_i = '1' else 'Z';
|
| 129 |
|
|
A <= A_i when BUSAK_n_i = '1' else (others => 'Z');
|
| 130 |
|
|
D <= DO when Write = '1' and BUSAK_n_i = '1' else (others => 'Z');
|
| 131 |
|
|
|
| 132 |
|
|
process (RESET_n, CLK_n)
|
| 133 |
|
|
begin
|
| 134 |
|
|
if RESET_n = '0' then
|
| 135 |
|
|
Reset_s <= '0';
|
| 136 |
|
|
elsif CLK_n'event and CLK_n = '1' then
|
| 137 |
|
|
Reset_s <= '1';
|
| 138 |
|
|
end if;
|
| 139 |
|
|
end process;
|
| 140 |
|
|
|
| 141 |
|
|
u0 : T80
|
| 142 |
|
|
generic map(
|
| 143 |
|
|
Mode => Mode,
|
| 144 |
|
|
IOWait => 1)
|
| 145 |
|
|
port map(
|
| 146 |
|
|
CEN => CEN,
|
| 147 |
|
|
M1_n => M1_n,
|
| 148 |
|
|
IORQ => IORQ,
|
| 149 |
|
|
NoRead => NoRead,
|
| 150 |
|
|
Write => Write,
|
| 151 |
|
|
RFSH_n => RFSH_n_i,
|
| 152 |
|
|
HALT_n => HALT_n,
|
| 153 |
|
|
WAIT_n => Wait_s,
|
| 154 |
|
|
INT_n => INT_n,
|
| 155 |
|
|
NMI_n => NMI_n,
|
| 156 |
|
|
RESET_n => Reset_s,
|
| 157 |
|
|
BUSRQ_n => BUSRQ_n,
|
| 158 |
|
|
BUSAK_n => BUSAK_n_i,
|
| 159 |
|
|
CLK_n => CLK_n,
|
| 160 |
|
|
A => A_i,
|
| 161 |
|
|
DInst => D,
|
| 162 |
|
|
DI => DI_Reg,
|
| 163 |
|
|
DO => DO,
|
| 164 |
|
|
MC => MCycle,
|
| 165 |
|
|
TS => TState,
|
| 166 |
|
|
IntCycle_n => IntCycle_n);
|
| 167 |
|
|
|
| 168 |
|
|
process (CLK_n)
|
| 169 |
|
|
begin
|
| 170 |
|
|
if CLK_n'event and CLK_n = '0' then
|
| 171 |
|
|
Wait_s <= WAIT_n;
|
| 172 |
|
|
if TState = "011" and BUSAK_n_i = '1' then
|
| 173 |
|
|
DI_Reg <= to_x01(D);
|
| 174 |
|
|
end if;
|
| 175 |
|
|
end if;
|
| 176 |
|
|
end process;
|
| 177 |
|
|
|
| 178 |
|
|
process (Reset_s,CLK_n)
|
| 179 |
|
|
begin
|
| 180 |
|
|
if Reset_s = '0' then
|
| 181 |
|
|
WR_n_i <= '1';
|
| 182 |
|
|
elsif CLK_n'event and CLK_n = '1' then
|
| 183 |
|
|
WR_n_i <= '1';
|
| 184 |
|
|
if TState = "001" then -- To short for IO writes !!!!!!!!!!!!!!!!!!!
|
| 185 |
|
|
WR_n_i <= not Write;
|
| 186 |
|
|
end if;
|
| 187 |
|
|
end if;
|
| 188 |
|
|
end process;
|
| 189 |
|
|
|
| 190 |
|
|
process (Reset_s,CLK_n)
|
| 191 |
|
|
begin
|
| 192 |
|
|
if Reset_s = '0' then
|
| 193 |
|
|
Req_Inhibit <= '0';
|
| 194 |
|
|
elsif CLK_n'event and CLK_n = '1' then
|
| 195 |
|
|
if MCycle = "001" and TState = "010" then
|
| 196 |
|
|
Req_Inhibit <= '1';
|
| 197 |
|
|
else
|
| 198 |
|
|
Req_Inhibit <= '0';
|
| 199 |
|
|
end if;
|
| 200 |
|
|
end if;
|
| 201 |
|
|
end process;
|
| 202 |
|
|
|
| 203 |
|
|
process (Reset_s,CLK_n)
|
| 204 |
|
|
begin
|
| 205 |
|
|
if Reset_s = '0' then
|
| 206 |
|
|
MReq_Inhibit <= '0';
|
| 207 |
|
|
elsif CLK_n'event and CLK_n = '0' then
|
| 208 |
|
|
if MCycle = "001" and TState = "010" then
|
| 209 |
|
|
MReq_Inhibit <= '1';
|
| 210 |
|
|
else
|
| 211 |
|
|
MReq_Inhibit <= '0';
|
| 212 |
|
|
end if;
|
| 213 |
|
|
end if;
|
| 214 |
|
|
end process;
|
| 215 |
|
|
|
| 216 |
|
|
process(Reset_s,CLK_n)
|
| 217 |
|
|
begin
|
| 218 |
|
|
if Reset_s = '0' then
|
| 219 |
|
|
RD <= '0';
|
| 220 |
|
|
IORQ_n_i <= '1';
|
| 221 |
|
|
MREQ <= '0';
|
| 222 |
|
|
elsif CLK_n'event and CLK_n = '0' then
|
| 223 |
|
|
|
| 224 |
|
|
if MCycle = "001" then
|
| 225 |
|
|
if TState = "001" then
|
| 226 |
|
|
RD <= IntCycle_n;
|
| 227 |
|
|
MREQ <= IntCycle_n;
|
| 228 |
|
|
IORQ_n_i <= IntCycle_n;
|
| 229 |
|
|
end if;
|
| 230 |
|
|
if TState = "011" then
|
| 231 |
|
|
RD <= '0';
|
| 232 |
|
|
IORQ_n_i <= '1';
|
| 233 |
|
|
MREQ <= '1';
|
| 234 |
|
|
end if;
|
| 235 |
|
|
if TState = "100" then
|
| 236 |
|
|
MREQ <= '0';
|
| 237 |
|
|
end if;
|
| 238 |
|
|
else
|
| 239 |
|
|
if TState = "001" and NoRead = '0' then
|
| 240 |
|
|
RD <= not Write;
|
| 241 |
|
|
IORQ_n_i <= not IORQ;
|
| 242 |
|
|
MREQ <= not IORQ;
|
| 243 |
|
|
end if;
|
| 244 |
|
|
if TState = "011" then
|
| 245 |
|
|
RD <= '0';
|
| 246 |
|
|
IORQ_n_i <= '1';
|
| 247 |
|
|
MREQ <= '0';
|
| 248 |
|
|
end if;
|
| 249 |
|
|
end if;
|
| 250 |
|
|
end if;
|
| 251 |
|
|
end process;
|
| 252 |
|
|
|
| 253 |
|
|
end;
|