2 -- T80(b) core. In an effort to merge and maintain bug fixes ....
5 -- Ver 300 started tidyup
7 -- Latest version from www.fpgaarcade.com (original www.opencores.org)
11 -- Z80 compatible microprocessor core
15 -- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
17 -- All rights reserved
19 -- Redistribution and use in source and synthezised forms, with or without
20 -- modification, are permitted provided that the following conditions are met:
22 -- Redistributions of source code must retain the above copyright notice,
23 -- this list of conditions and the following disclaimer.
25 -- Redistributions in synthesized form must reproduce the above copyright
26 -- notice, this list of conditions and the following disclaimer in the
27 -- documentation and/or other materials provided with the distribution.
29 -- Neither the name of the author nor the names of other contributors may
30 -- be used to endorse or promote products derived from this software without
31 -- specific prior written permission.
33 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
35 -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 -- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
37 -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 -- POSSIBILITY OF SUCH DAMAGE.
45 -- Please report bugs to the author, but before you do so, please
46 -- make sure that this is not a derivative work and that
47 -- you have the latest version of this file.
49 -- The latest version of this file can be found at:
50 -- http://www.opencores.org/cvsweb.shtml/t80/
56 -- 0208 : First complete release
60 -- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
62 -- 0235 : Added IM 2 fix by Mike Johnson
64 -- 0238 : Added NoRead signal
66 -- 0238b: Fixed instruction timing for POP and DJNZ
68 -- 0240 : Added (IX/IY+d) states, removed op-codes from mode 2 and added all remaining mode 3 op-codes
70 -- 0240mj1 fix for HL inc/dec for INI, IND, INIR, INDR, OUTI, OUTD, OTIR, OTDR
72 -- 0242 : Fixed I/O instruction timing, cleanup
76 use IEEE.std_logic_1164.all;
77 use IEEE.numeric_std.all;
78 use work.T80_Pack.all;
83 Flag_C : integer := 0;
84 Flag_N : integer := 1;
85 Flag_P : integer := 2;
86 Flag_X : integer := 3;
87 Flag_H : integer := 4;
88 Flag_Y : integer := 5;
89 Flag_Z : integer := 6;
93 IR : in std_logic_vector(7 downto 0);
94 ISet : in std_logic_vector(1 downto 0);
95 MCycle : in std_logic_vector(2 downto 0);
96 F : in std_logic_vector(7 downto 0);
97 NMICycle : in std_logic;
98 IntCycle : in std_logic;
99 MCycles : out std_logic_vector(2 downto 0);
100 TStates : out std_logic_vector(2 downto 0);
101 Prefix : out std_logic_vector(1 downto 0); -- None,BC,ED,DD/FD
102 Inc_PC : out std_logic;
103 Inc_WZ : out std_logic;
104 IncDec_16 : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP 0 is inc
105 Read_To_Reg : out std_logic;
106 Read_To_Acc : out std_logic;
107 Set_BusA_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
108 Set_BusB_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
109 ALU_Op : out std_logic_vector(3 downto 0);
110 -- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
111 Save_ALU : out std_logic;
112 PreserveC : out std_logic;
113 Arith16 : out std_logic;
114 Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
115 IORQ : out std_logic;
116 Jump : out std_logic;
117 JumpE : out std_logic;
118 JumpXY : out std_logic;
119 Call : out std_logic;
120 RstP : out std_logic;
123 LDSPHL : out std_logic;
124 Special_LD : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
125 ExchangeDH : out std_logic;
126 ExchangeRp : out std_logic;
127 ExchangeAF : out std_logic;
128 ExchangeRS : out std_logic;
129 I_DJNZ : out std_logic;
130 I_CPL : out std_logic;
131 I_CCF : out std_logic;
132 I_SCF : out std_logic;
133 I_RETN : out std_logic;
134 I_BT : out std_logic;
135 I_BC : out std_logic;
136 I_BTR : out std_logic;
137 I_RLD : out std_logic;
138 I_RRD : out std_logic;
139 I_INRC : out std_logic;
140 SetDI : out std_logic;
141 SetEI : out std_logic;
142 IMode : out std_logic_vector(1 downto 0);
143 Halt : out std_logic;
144 NoRead : out std_logic;
145 Write : out std_logic
149 architecture rtl of T80_MCode is
151 constant aNone : std_logic_vector(2 downto 0) := "111";
152 constant aBC : std_logic_vector(2 downto 0) := "000";
153 constant aDE : std_logic_vector(2 downto 0) := "001";
154 constant aXY : std_logic_vector(2 downto 0) := "010";
155 constant aIOA : std_logic_vector(2 downto 0) := "100";
156 constant aSP : std_logic_vector(2 downto 0) := "101";
157 constant aZI : std_logic_vector(2 downto 0) := "110";
160 F : std_logic_vector(7 downto 0);
161 cc : bit_vector(2 downto 0)
166 when "000" => return F(7) = '0'; -- NZ
167 when "001" => return F(7) = '1'; -- Z
168 when "010" => return F(4) = '0'; -- NC
169 when "011" => return F(4) = '1'; -- C
170 when "100" => return false;
171 when "101" => return false;
172 when "110" => return false;
173 when "111" => return false;
177 when "000" => return F(6) = '0'; -- NZ
178 when "001" => return F(6) = '1'; -- Z
179 when "010" => return F(0) = '0'; -- NC
180 when "011" => return F(0) = '1'; -- C
181 when "100" => return F(2) = '0'; -- PO
182 when "101" => return F(2) = '1'; -- PE
183 when "110" => return F(7) = '0'; -- P
184 when "111" => return F(7) = '1'; -- M
191 process (IR, ISet, MCycle, F, NMICycle, IntCycle)
192 variable DDD : std_logic_vector(2 downto 0);
193 variable SSS : std_logic_vector(2 downto 0);
194 variable DPair : std_logic_vector(1 downto 0);
195 variable IRB : bit_vector(7 downto 0);
197 DDD := IR(5 downto 3);
198 SSS := IR(2 downto 0);
199 DPair := IR(5 downto 4);
200 IRB := to_bitvector(IR);
203 if MCycle = "001" then
214 Set_BusB_To <= "0000";
215 Set_BusA_To <= "0000";
216 ALU_Op <= "0" & IR(5 downto 3);
221 Set_Addr_To <= aNone;
256 ------------------------------------------------------------------------------
258 -- Unprefixed instructions
260 ------------------------------------------------------------------------------
264 when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
265 |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
266 |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
267 |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
268 |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
269 |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
270 |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
272 Set_BusB_To(2 downto 0) <= SSS;
274 Set_BusA_To(2 downto 0) <= DDD;
276 when "00000110"|"00001110"|"00010110"|"00011110"|"00100110"|"00101110"|"00111110" =>
279 case to_integer(unsigned(MCycle)) is
282 Set_BusA_To(2 downto 0) <= DDD;
286 when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01111110" =>
289 case to_integer(unsigned(MCycle)) is
293 Set_BusA_To(2 downto 0) <= DDD;
297 when "01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111" =>
300 case to_integer(unsigned(MCycle)) is
303 Set_BusB_To(2 downto 0) <= SSS;
304 Set_BusB_To(3) <= '0';
312 case to_integer(unsigned(MCycle)) is
316 Set_BusB_To(2 downto 0) <= SSS;
317 Set_BusB_To(3) <= '0';
325 case to_integer(unsigned(MCycle)) is
335 case to_integer(unsigned(MCycle)) is
346 case to_integer(unsigned(MCycle)) is
357 case to_integer(unsigned(MCycle)) is
372 case to_integer(unsigned(MCycle)) is
375 Set_BusB_To <= "0111";
383 case to_integer(unsigned(MCycle)) is
386 Set_BusB_To <= "0111";
395 case to_integer(unsigned(MCycle)) is
398 Set_BusB_To <= "0111";
407 case to_integer(unsigned(MCycle)) is
414 Set_BusB_To <= "0111";
422 when "00000001"|"00010001"|"00100001"|"00110001" =>
425 case to_integer(unsigned(MCycle)) is
430 Set_BusA_To(3 downto 0) <= "1000";
432 Set_BusA_To(2 downto 1) <= DPAIR;
433 Set_BusA_To(0) <= '1';
439 Set_BusA_To(3 downto 0) <= "1001";
441 Set_BusA_To(2 downto 1) <= DPAIR;
442 Set_BusA_To(0) <= '0';
450 case to_integer(unsigned(MCycle)) is
461 case to_integer(unsigned(MCycle)) is
470 Set_BusA_To(2 downto 0) <= "101"; -- L
475 Set_BusA_To(2 downto 0) <= "100"; -- H
484 case to_integer(unsigned(MCycle)) is
487 Set_BusB_To <= "0111";
496 case to_integer(unsigned(MCycle)) is
504 Set_BusB_To <= "0101"; -- L
509 Set_BusB_To <= "0100"; -- H
519 when "11000101"|"11010101"|"11100101"|"11110101" =>
522 case to_integer(unsigned(MCycle)) is
528 Set_BusB_To <= "0111";
530 Set_BusB_To(2 downto 1) <= DPAIR;
531 Set_BusB_To(0) <= '0';
532 Set_BusB_To(3) <= '0';
538 Set_BusB_To <= "1011";
540 Set_BusB_To(2 downto 1) <= DPAIR;
541 Set_BusB_To(0) <= '1';
542 Set_BusB_To(3) <= '0';
549 when "11000001"|"11010001"|"11100001"|"11110001" =>
552 case to_integer(unsigned(MCycle)) is
560 Set_BusA_To(3 downto 0) <= "1011";
562 Set_BusA_To(2 downto 1) <= DPAIR;
563 Set_BusA_To(0) <= '1';
569 Set_BusA_To(3 downto 0) <= "0111";
571 Set_BusA_To(2 downto 1) <= DPAIR;
572 Set_BusA_To(0) <= '0';
577 -- EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
587 case to_integer(unsigned(MCycle)) is
595 Set_BusB_To <= "1000";
600 Set_BusB_To <= "1001";
613 case to_integer(unsigned(MCycle)) is
635 case to_integer(unsigned(MCycle)) is
640 Set_BusA_To <= "0101";
641 Set_BusB_To <= "0101";
650 Set_BusA_To <= "0100";
651 Set_BusB_To <= "0100";
661 -- 8 BIT ARITHMETIC AND LOGICAL GROUP
662 when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
663 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
664 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
665 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
666 |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
667 |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
668 |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
669 |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
678 Set_BusB_To(2 downto 0) <= SSS;
679 Set_BusA_To(2 downto 0) <= "111";
682 when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
692 case to_integer(unsigned(MCycle)) is
698 Set_BusB_To(2 downto 0) <= SSS;
699 Set_BusA_To(2 downto 0) <= "111";
702 when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
712 if MCycle = "010" then
716 Set_BusB_To(2 downto 0) <= SSS;
717 Set_BusA_To(2 downto 0) <= "111";
719 when "00000100"|"00001100"|"00010100"|"00011100"|"00100100"|"00101100"|"00111100" =>
721 Set_BusB_To <= "1010";
722 Set_BusA_To(2 downto 0) <= DDD;
730 case to_integer(unsigned(MCycle)) is
740 Set_BusB_To <= "1010";
741 Set_BusA_To(2 downto 0) <= DDD;
746 when "00000101"|"00001101"|"00010101"|"00011101"|"00100101"|"00101101"|"00111101" =>
748 Set_BusB_To <= "1010";
749 Set_BusA_To(2 downto 0) <= DDD;
757 case to_integer(unsigned(MCycle)) is
767 Set_BusB_To <= "1010";
768 Set_BusA_To(2 downto 0) <= DDD;
774 -- GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
777 Set_BusA_To(2 downto 0) <= "111";
791 if NMICycle = '1' then
794 case to_integer(unsigned(MCycle)) is
799 Set_BusB_To <= "1101";
805 Set_BusB_To <= "1100";
811 elsif IntCycle = '1' then
814 case to_integer(unsigned(MCycle)) is
820 Set_BusB_To <= "1101";
826 Set_BusB_To <= "1100";
850 -- 16 BIT ARITHMETIC GROUP
851 when "00001001"|"00011001"|"00101001"|"00111001" =>
854 case to_integer(unsigned(MCycle)) is
860 Set_BusA_To(2 downto 0) <= "101";
861 case to_integer(unsigned(IR(5 downto 4))) is
863 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
864 Set_BusB_To(0) <= '1';
866 Set_BusB_To <= "1000";
875 Set_BusA_To(2 downto 0) <= "100";
876 case to_integer(unsigned(IR(5 downto 4))) is
878 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
880 Set_BusB_To <= "1001";
885 when "00000011"|"00010011"|"00100011"|"00110011" =>
888 IncDec_16(3 downto 2) <= "01";
889 IncDec_16(1 downto 0) <= DPair;
890 when "00001011"|"00011011"|"00101011"|"00111011" =>
893 IncDec_16(3 downto 2) <= "11";
894 IncDec_16(1 downto 0) <= DPair;
896 -- ROTATE AND SHIFT GROUP
905 Set_BusA_To(2 downto 0) <= "111";
914 case to_integer(unsigned(MCycle)) is
923 when "11000010"|"11001010"|"11010010"|"11011010"|"11100010"|"11101010"|"11110010"|"11111010" =>
924 if IR(5) = '1' and Mode = 3 then
925 case IRB(4 downto 3) is
929 case to_integer(unsigned(MCycle)) is
932 Set_BusB_To <= "0111";
941 case to_integer(unsigned(MCycle)) is
948 Set_BusB_To <= "0111";
956 case to_integer(unsigned(MCycle)) is
967 case to_integer(unsigned(MCycle)) is
982 case to_integer(unsigned(MCycle)) is
988 if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
998 case to_integer(unsigned(MCycle)) is
1005 when others => null;
1012 case to_integer(unsigned(MCycle)) is
1015 if F(Flag_C) = '0' then
1022 when others => null;
1029 case to_integer(unsigned(MCycle)) is
1032 if F(Flag_C) = '1' then
1039 when others => null;
1046 case to_integer(unsigned(MCycle)) is
1049 if F(Flag_Z) = '0' then
1056 when others => null;
1063 case to_integer(unsigned(MCycle)) is
1066 if F(Flag_Z) = '1' then
1073 when others => null;
1085 case to_integer(unsigned(MCycle)) is
1089 Set_BusB_To <= "1010";
1090 Set_BusA_To(2 downto 0) <= "000";
1101 when others => null;
1105 -- CALL AND RETURN GROUP
1109 case to_integer(unsigned(MCycle)) is
1114 IncDec_16 <= "1111";
1119 Set_BusB_To <= "1101";
1122 IncDec_16 <= "1111";
1124 Set_BusB_To <= "1100";
1128 when others => null;
1130 when "11000100"|"11001100"|"11010100"|"11011100"|"11100100"|"11101100"|"11110100"|"11111100" =>
1131 if IR(5) = '0' or Mode /= 3 then
1134 case to_integer(unsigned(MCycle)) is
1141 if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
1142 IncDec_16 <= "1111";
1145 Set_BusB_To <= "1101";
1151 IncDec_16 <= "1111";
1153 Set_BusB_To <= "1100";
1157 when others => null;
1163 case to_integer(unsigned(MCycle)) is
1168 IncDec_16 <= "0111";
1173 IncDec_16 <= "0111";
1174 when others => null;
1176 when "11000000"|"11001000"|"11010000"|"11011000"|"11100000"|"11101000"|"11110000"|"11111000" =>
1177 if IR(5) = '1' and Mode = 3 then
1178 case IRB(4 downto 3) is
1182 case to_integer(unsigned(MCycle)) is
1185 Set_Addr_To <= aIOA;
1186 Set_BusB_To <= "0111";
1189 when others => null;
1194 case to_integer(unsigned(MCycle)) is
1200 Set_BusA_To <= "1000";
1201 Set_BusB_To <= "0110";
1207 Set_BusA_To <= "1001";
1208 Set_BusB_To <= "1110"; -- Incorrect unsigned !!!!!!!!!!!!!!!!!!!!!
1214 case to_integer(unsigned(MCycle)) is
1217 Set_Addr_To <= aIOA;
1220 when others => null;
1223 -- LD HL,SP+n -- Not correct !!!!!!!!!!!!!!!!!!!
1225 case to_integer(unsigned(MCycle)) is
1234 Set_BusA_To(2 downto 0) <= "101"; -- L
1239 Set_BusA_To(2 downto 0) <= "100"; -- H
1241 when others => null;
1247 case to_integer(unsigned(MCycle)) is
1249 if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
1256 IncDec_16 <= "0111";
1261 IncDec_16 <= "0111";
1262 when others => null;
1265 when "11000111"|"11001111"|"11010111"|"11011111"|"11100111"|"11101111"|"11110111"|"11111111" =>
1268 case to_integer(unsigned(MCycle)) is
1271 IncDec_16 <= "1111";
1273 Set_BusB_To <= "1101";
1276 IncDec_16 <= "1111";
1278 Set_BusB_To <= "1100";
1282 when others => null;
1285 -- INPUT AND OUTPUT GROUP
1290 case to_integer(unsigned(MCycle)) is
1293 Set_Addr_To <= aIOA;
1297 when others => null;
1304 case to_integer(unsigned(MCycle)) is
1307 Set_Addr_To <= aIOA;
1308 Set_BusB_To <= "0111";
1312 when others => null;
1316 ------------------------------------------------------------------------------
1317 ------------------------------------------------------------------------------
1318 -- MULTIBYTE INSTRUCTIONS
1319 ------------------------------------------------------------------------------
1320 ------------------------------------------------------------------------------
1332 when "11011101"|"11111101" =>
1341 ------------------------------------------------------------------------------
1343 -- CB prefixed instructions
1345 ------------------------------------------------------------------------------
1347 Set_BusA_To(2 downto 0) <= IR(2 downto 0);
1348 Set_BusB_To(2 downto 0) <= IR(2 downto 0);
1351 when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000111"
1352 |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010111"
1353 |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001111"
1354 |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011111"
1355 |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100111"
1356 |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101111"
1357 |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110111"
1358 |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111111" =>
1366 -- SLL r (Undocumented) / SWAP r
1367 if MCycle = "001" then
1372 when "00000110"|"00010110"|"00001110"|"00011110"|"00101110"|"00111110"|"00100110"|"00110110" =>
1380 -- SLL (HL) (Undocumented) / SWAP (HL)
1382 case to_integer(unsigned(MCycle)) is
1395 when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
1396 |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
1397 |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
1398 |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
1399 |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
1400 |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
1401 |"01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111"
1402 |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
1404 if MCycle = "001" then
1405 Set_BusB_To(2 downto 0) <= IR(2 downto 0);
1408 when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01110110"|"01111110" =>
1411 case to_integer(unsigned(MCycle)) is
1417 when others => null;
1419 when "11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000111"
1420 |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001111"
1421 |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010111"
1422 |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011111"
1423 |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100111"
1424 |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101111"
1425 |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110111"
1426 |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111111" =>
1428 if MCycle = "001" then
1433 when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
1436 case to_integer(unsigned(MCycle)) is
1447 when others => null;
1449 when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
1450 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
1451 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
1452 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
1453 |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
1454 |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
1455 |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
1456 |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
1458 if MCycle = "001" then
1463 when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
1466 case to_integer(unsigned(MCycle)) is
1477 when others => null;
1483 ------------------------------------------------------------------------------
1485 -- ED prefixed instructions
1487 ------------------------------------------------------------------------------
1490 when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000110"|"00000111"
1491 |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001110"|"00001111"
1492 |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010110"|"00010111"
1493 |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011110"|"00011111"
1494 |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100110"|"00100111"
1495 |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101110"|"00101111"
1496 |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110110"|"00110111"
1497 |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111110"|"00111111"
1500 |"10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000110"|"10000111"
1501 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001110"|"10001111"
1502 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010110"|"10010111"
1503 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011110"|"10011111"
1504 | "10100100"|"10100101"|"10100110"|"10100111"
1505 | "10101100"|"10101101"|"10101110"|"10101111"
1506 | "10110100"|"10110101"|"10110110"|"10110111"
1507 | "10111100"|"10111101"|"10111110"|"10111111"
1508 |"11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000110"|"11000111"
1509 |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001110"|"11001111"
1510 |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010110"|"11010111"
1511 |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011110"|"11011111"
1512 |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100110"|"11100111"
1513 |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101110"|"11101111"
1514 |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110110"|"11110111"
1515 |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111110"|"11111111" =>
1516 null; -- NOP, undocumented
1517 when "01111110"|"01111111" =>
1518 -- NOP, undocumented
1523 Special_LD <= "100";
1527 Special_LD <= "101";
1531 Special_LD <= "110";
1535 Special_LD <= "111";
1537 -- 16 BIT LOAD GROUP
1538 when "01001011"|"01011011"|"01101011"|"01111011" =>
1541 case to_integer(unsigned(MCycle)) is
1551 if IR(5 downto 4) = "11" then
1552 Set_BusA_To <= "1000";
1554 Set_BusA_To(2 downto 1) <= IR(5 downto 4);
1555 Set_BusA_To(0) <= '1';
1561 if IR(5 downto 4) = "11" then
1562 Set_BusA_To <= "1001";
1564 Set_BusA_To(2 downto 1) <= IR(5 downto 4);
1565 Set_BusA_To(0) <= '0';
1567 when others => null;
1569 when "01000011"|"01010011"|"01100011"|"01110011" =>
1572 case to_integer(unsigned(MCycle)) is
1580 if IR(5 downto 4) = "11" then
1581 Set_BusB_To <= "1000";
1583 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1584 Set_BusB_To(0) <= '1';
1585 Set_BusB_To(3) <= '0';
1591 if IR(5 downto 4) = "11" then
1592 Set_BusB_To <= "1001";
1594 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1595 Set_BusB_To(0) <= '0';
1596 Set_BusB_To(3) <= '0';
1600 when others => null;
1602 when "10100000" | "10101000" | "10110000" | "10111000" =>
1603 -- LDI, LDD, LDIR, LDDR
1605 case to_integer(unsigned(MCycle)) is
1608 IncDec_16 <= "1100"; -- BC
1610 Set_BusB_To <= "0110";
1611 Set_BusA_To(2 downto 0) <= "111";
1615 IncDec_16 <= "0110"; -- IX
1617 IncDec_16 <= "1110";
1624 IncDec_16 <= "0101"; -- DE
1626 IncDec_16 <= "1101";
1631 when others => null;
1633 when "10100001" | "10101001" | "10110001" | "10111001" =>
1634 -- CPI, CPD, CPIR, CPDR
1636 case to_integer(unsigned(MCycle)) is
1639 IncDec_16 <= "1100"; -- BC
1641 Set_BusB_To <= "0110";
1642 Set_BusA_To(2 downto 0) <= "111";
1647 IncDec_16 <= "0110";
1649 IncDec_16 <= "1110";
1658 when others => null;
1660 when "01000100"|"01001100"|"01010100"|"01011100"|"01100100"|"01101100"|"01110100"|"01111100" =>
1663 Set_BusB_To <= "0111";
1664 Set_BusA_To <= "1010";
1667 when "01000110"|"01001110"|"01100110"|"01101110" =>
1670 when "01010110"|"01110110" =>
1673 when "01011110"|"01110111" =>
1676 -- 16 bit arithmetic
1677 when "01001010"|"01011010"|"01101010"|"01111010" =>
1680 case to_integer(unsigned(MCycle)) is
1686 Set_BusA_To(2 downto 0) <= "101";
1687 case to_integer(unsigned(IR(5 downto 4))) is
1689 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1690 Set_BusB_To(0) <= '1';
1692 Set_BusB_To <= "1000";
1700 Set_BusA_To(2 downto 0) <= "100";
1701 case to_integer(unsigned(IR(5 downto 4))) is
1703 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1704 Set_BusB_To(0) <= '0';
1706 Set_BusB_To <= "1001";
1710 when "01000010"|"01010010"|"01100010"|"01110010" =>
1713 case to_integer(unsigned(MCycle)) is
1719 Set_BusA_To(2 downto 0) <= "101";
1720 case to_integer(unsigned(IR(5 downto 4))) is
1722 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1723 Set_BusB_To(0) <= '1';
1725 Set_BusB_To <= "1000";
1733 Set_BusA_To(2 downto 0) <= "100";
1734 case to_integer(unsigned(IR(5 downto 4))) is
1736 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1738 Set_BusB_To <= "1001";
1745 case to_integer(unsigned(MCycle)) is
1751 Set_BusB_To(2 downto 0) <= "110";
1752 Set_BusA_To(2 downto 0) <= "111";
1765 case to_integer(unsigned(MCycle)) is
1770 Set_BusB_To(2 downto 0) <= "110";
1771 Set_BusA_To(2 downto 0) <= "111";
1781 when "01000101"|"01001101"|"01010101"|"01011101"|"01100101"|"01101101"|"01110101"|"01111101" =>
1784 case to_integer(unsigned(MCycle)) is
1788 IncDec_16 <= "0111";
1793 IncDec_16 <= "0111";
1795 when others => null;
1797 when "01000000"|"01001000"|"01010000"|"01011000"|"01100000"|"01101000"|"01110000"|"01111000" =>
1800 case to_integer(unsigned(MCycle)) is
1805 if IR(5 downto 3) /= "110" then
1807 Set_BusA_To(2 downto 0) <= IR(5 downto 3);
1812 when "01000001"|"01001001"|"01010001"|"01011001"|"01100001"|"01101001"|"01110001"|"01111001" =>
1816 case to_integer(unsigned(MCycle)) is
1819 Set_BusB_To(2 downto 0) <= IR(5 downto 3);
1820 if IR(5 downto 3) = "110" then
1821 Set_BusB_To(3) <= '1';
1828 when "10100010" | "10101010" | "10110010" | "10111010" =>
1829 -- INI, IND, INIR, INDR
1830 -- note B is decremented AFTER being put on the bus
1832 case to_integer(unsigned(MCycle)) is
1835 Set_BusB_To <= "1010";
1836 Set_BusA_To <= "0000";
1842 Set_BusB_To <= "0110";
1846 --IncDec_16 <= "0010";
1847 IncDec_16 <= "0110";
1849 --IncDec_16 <= "1010";
1850 IncDec_16 <= "1110";
1858 when others => null;
1860 when "10100011" | "10101011" | "10110011" | "10111011" =>
1861 -- OUTI, OUTD, OTIR, OTDR
1862 -- note B is decremented BEFORE being put on the bus.
1863 -- mikej fix for hl inc
1865 case to_integer(unsigned(MCycle)) is
1869 Set_BusB_To <= "1010";
1870 Set_BusA_To <= "0000";
1875 Set_BusB_To <= "0110";
1879 IncDec_16 <= "0110"; -- mikej
1881 IncDec_16 <= "1110"; -- mikej
1889 when others => null;
1896 if MCycle = "001" then
1897 -- TStates <= "100";
1904 if MCycle = "001" then
1905 -- TStates <= "100";
1912 if MCycle = "110" then
1917 Set_BusB_To(2 downto 0) <= SSS;
1918 Set_BusB_To(3) <= '0';
1920 if IRB = "00110110" or IRB = "11001011" then
1921 Set_Addr_To <= aNone;
1924 if MCycle = "111" then
1928 if ISet /= "01" then
1931 Set_BusB_To(2 downto 0) <= SSS;
1932 Set_BusB_To(3) <= '0';
1933 if IRB = "00110110" or ISet = "01" then