2 -- Z80 compatible microprocessor core
6 -- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
10 -- Redistribution and use in source and synthezised forms, with or without
11 -- modification, are permitted provided that the following conditions are met:
13 -- Redistributions of source code must retain the above copyright notice,
14 -- this list of conditions and the following disclaimer.
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.
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.
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.
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.
40 -- The latest version of this file can be found at:
41 -- http://www.opencores.org/cvsweb.shtml/t80/
47 -- 0208 : First complete release
51 -- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
53 -- 0235 : Added IM 2 fix by Mike Johnson
55 -- 0238 : Added NoRead signal
57 -- 0238b: Fixed instruction timing for POP and DJNZ
59 -- 0240 : Added (IX/IY+d) states, removed op-codes from mode 2 and added all remaining mode 3 op-codes
61 -- 0242 : Fixed I/O instruction timing, cleanup
65 use IEEE.std_logic_1164.all;
66 use IEEE.numeric_std.all;
71 Flag_C : integer := 0;
72 Flag_N : integer := 1;
73 Flag_P : integer := 2;
74 Flag_X : integer := 3;
75 Flag_H : integer := 4;
76 Flag_Y : integer := 5;
77 Flag_Z : integer := 6;
81 IR : in std_logic_vector(7 downto 0);
82 ISet : in std_logic_vector(1 downto 0);
83 MCycle : in std_logic_vector(2 downto 0);
84 F : in std_logic_vector(7 downto 0);
85 NMICycle : in std_logic;
86 IntCycle : in std_logic;
87 MCycles : out std_logic_vector(2 downto 0);
88 TStates : out std_logic_vector(2 downto 0);
89 Prefix : out std_logic_vector(1 downto 0); -- None,BC,ED,DD/FD
90 Inc_PC : out std_logic;
91 Inc_WZ : out std_logic;
92 IncDec_16 : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP 0 is inc
93 Read_To_Reg : out std_logic;
94 Read_To_Acc : out std_logic;
95 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
96 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
97 ALU_Op : out std_logic_vector(3 downto 0);
98 -- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
99 Save_ALU : out std_logic;
100 PreserveC : out std_logic;
101 Arith16 : out std_logic;
102 Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
103 IORQ : out std_logic;
104 Jump : out std_logic;
105 JumpE : out std_logic;
106 JumpXY : out std_logic;
107 Call : out std_logic;
108 RstP : out std_logic;
111 LDSPHL : out std_logic;
112 Special_LD : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
113 ExchangeDH : out std_logic;
114 ExchangeRp : out std_logic;
115 ExchangeAF : out std_logic;
116 ExchangeRS : out std_logic;
117 I_DJNZ : out std_logic;
118 I_CPL : out std_logic;
119 I_CCF : out std_logic;
120 I_SCF : out std_logic;
121 I_RETN : out std_logic;
122 I_BT : out std_logic;
123 I_BC : out std_logic;
124 I_BTR : out std_logic;
125 I_RLD : out std_logic;
126 I_RRD : out std_logic;
127 I_INRC : out std_logic;
128 SetDI : out std_logic;
129 SetEI : out std_logic;
130 IMode : out std_logic_vector(1 downto 0);
131 Halt : out std_logic;
132 NoRead : out std_logic;
133 Write : out std_logic
137 architecture rtl of T80_MCode is
139 constant aNone : std_logic_vector(2 downto 0) := "111";
140 constant aBC : std_logic_vector(2 downto 0) := "000";
141 constant aDE : std_logic_vector(2 downto 0) := "001";
142 constant aXY : std_logic_vector(2 downto 0) := "010";
143 constant aIOA : std_logic_vector(2 downto 0) := "100";
144 constant aSP : std_logic_vector(2 downto 0) := "101";
145 constant aZI : std_logic_vector(2 downto 0) := "110";
146 -- constant aNone : std_logic_vector(2 downto 0) := "000";
147 -- constant aXY : std_logic_vector(2 downto 0) := "001";
148 -- constant aIOA : std_logic_vector(2 downto 0) := "010";
149 -- constant aSP : std_logic_vector(2 downto 0) := "011";
150 -- constant aBC : std_logic_vector(2 downto 0) := "100";
151 -- constant aDE : std_logic_vector(2 downto 0) := "101";
152 -- constant aZI : std_logic_vector(2 downto 0) := "110";
155 F : std_logic_vector(7 downto 0);
156 cc : bit_vector(2 downto 0)
161 when "000" => return F(7) = '0'; -- NZ
162 when "001" => return F(7) = '1'; -- Z
163 when "010" => return F(4) = '0'; -- NC
164 when "011" => return F(4) = '1'; -- C
165 when "100" => return false;
166 when "101" => return false;
167 when "110" => return false;
168 when "111" => return false;
172 when "000" => return F(6) = '0'; -- NZ
173 when "001" => return F(6) = '1'; -- Z
174 when "010" => return F(0) = '0'; -- NC
175 when "011" => return F(0) = '1'; -- C
176 when "100" => return F(2) = '0'; -- PO
177 when "101" => return F(2) = '1'; -- PE
178 when "110" => return F(7) = '0'; -- P
179 when "111" => return F(7) = '1'; -- M
186 process (IR, ISet, MCycle, F, NMICycle, IntCycle)
187 variable DDD : std_logic_vector(2 downto 0);
188 variable SSS : std_logic_vector(2 downto 0);
189 variable DPair : std_logic_vector(1 downto 0);
190 variable IRB : bit_vector(7 downto 0);
192 DDD := IR(5 downto 3);
193 SSS := IR(2 downto 0);
194 DPair := IR(5 downto 4);
195 IRB := to_bitvector(IR);
198 if MCycle = "001" then
209 Set_BusB_To <= "0000";
210 Set_BusA_To <= "0000";
211 ALU_Op <= "0" & IR(5 downto 3);
216 Set_Addr_To <= aNone;
251 ------------------------------------------------------------------------------
253 -- Unprefixed instructions
255 ------------------------------------------------------------------------------
259 when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
260 |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
261 |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
262 |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
263 |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
264 |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
265 |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
267 Set_BusB_To(2 downto 0) <= SSS;
269 Set_BusA_To(2 downto 0) <= DDD;
271 when "00000110"|"00001110"|"00010110"|"00011110"|"00100110"|"00101110"|"00111110" =>
274 case to_integer(unsigned(MCycle)) is
277 Set_BusA_To(2 downto 0) <= DDD;
281 when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01111110" =>
284 case to_integer(unsigned(MCycle)) is
288 Set_BusA_To(2 downto 0) <= DDD;
292 when "01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111" =>
295 case to_integer(unsigned(MCycle)) is
298 Set_BusB_To(2 downto 0) <= SSS;
299 Set_BusB_To(3) <= '0';
307 case to_integer(unsigned(MCycle)) is
311 Set_BusB_To(2 downto 0) <= SSS;
312 Set_BusB_To(3) <= '0';
320 case to_integer(unsigned(MCycle)) is
330 case to_integer(unsigned(MCycle)) is
341 case to_integer(unsigned(MCycle)) is
352 case to_integer(unsigned(MCycle)) is
367 case to_integer(unsigned(MCycle)) is
370 Set_BusB_To <= "0111";
378 case to_integer(unsigned(MCycle)) is
381 Set_BusB_To <= "0111";
390 case to_integer(unsigned(MCycle)) is
393 Set_BusB_To <= "0111";
402 case to_integer(unsigned(MCycle)) is
409 Set_BusB_To <= "0111";
417 when "00000001"|"00010001"|"00100001"|"00110001" =>
420 case to_integer(unsigned(MCycle)) is
425 Set_BusA_To(3 downto 0) <= "1000";
427 Set_BusA_To(2 downto 1) <= DPAIR;
428 Set_BusA_To(0) <= '1';
434 Set_BusA_To(3 downto 0) <= "1001";
436 Set_BusA_To(2 downto 1) <= DPAIR;
437 Set_BusA_To(0) <= '0';
445 case to_integer(unsigned(MCycle)) is
456 case to_integer(unsigned(MCycle)) is
465 Set_BusA_To(2 downto 0) <= "101"; -- L
470 Set_BusA_To(2 downto 0) <= "100"; -- H
479 case to_integer(unsigned(MCycle)) is
482 Set_BusB_To <= "0111";
491 case to_integer(unsigned(MCycle)) is
499 Set_BusB_To <= "0101"; -- L
504 Set_BusB_To <= "0100"; -- H
514 when "11000101"|"11010101"|"11100101"|"11110101" =>
517 case to_integer(unsigned(MCycle)) is
523 Set_BusB_To <= "0111";
525 Set_BusB_To(2 downto 1) <= DPAIR;
526 Set_BusB_To(0) <= '0';
527 Set_BusB_To(3) <= '0';
533 Set_BusB_To <= "1011";
535 Set_BusB_To(2 downto 1) <= DPAIR;
536 Set_BusB_To(0) <= '1';
537 Set_BusB_To(3) <= '0';
544 when "11000001"|"11010001"|"11100001"|"11110001" =>
547 case to_integer(unsigned(MCycle)) is
555 Set_BusA_To(3 downto 0) <= "1011";
557 Set_BusA_To(2 downto 1) <= DPAIR;
558 Set_BusA_To(0) <= '1';
564 Set_BusA_To(3 downto 0) <= "0111";
566 Set_BusA_To(2 downto 1) <= DPAIR;
567 Set_BusA_To(0) <= '0';
572 -- EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
582 case to_integer(unsigned(MCycle)) is
590 Set_BusB_To <= "1000";
595 Set_BusB_To <= "1001";
608 case to_integer(unsigned(MCycle)) is
630 case to_integer(unsigned(MCycle)) is
635 Set_BusA_To <= "0101";
636 Set_BusB_To <= "0101";
645 Set_BusA_To <= "0100";
646 Set_BusB_To <= "0100";
656 -- 8 BIT ARITHMETIC AND LOGICAL GROUP
657 when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
658 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
659 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
660 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
661 |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
662 |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
663 |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
664 |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
673 Set_BusB_To(2 downto 0) <= SSS;
674 Set_BusA_To(2 downto 0) <= "111";
677 when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
687 case to_integer(unsigned(MCycle)) is
693 Set_BusB_To(2 downto 0) <= SSS;
694 Set_BusA_To(2 downto 0) <= "111";
697 when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
707 if MCycle = "010" then
711 Set_BusB_To(2 downto 0) <= SSS;
712 Set_BusA_To(2 downto 0) <= "111";
714 when "00000100"|"00001100"|"00010100"|"00011100"|"00100100"|"00101100"|"00111100" =>
716 Set_BusB_To <= "1010";
717 Set_BusA_To(2 downto 0) <= DDD;
725 case to_integer(unsigned(MCycle)) is
735 Set_BusB_To <= "1010";
736 Set_BusA_To(2 downto 0) <= DDD;
741 when "00000101"|"00001101"|"00010101"|"00011101"|"00100101"|"00101101"|"00111101" =>
743 Set_BusB_To <= "1010";
744 Set_BusA_To(2 downto 0) <= DDD;
752 case to_integer(unsigned(MCycle)) is
762 Set_BusB_To <= "1010";
763 Set_BusA_To(2 downto 0) <= DDD;
769 -- GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
772 Set_BusA_To(2 downto 0) <= "111";
786 if NMICycle = '1' then
789 case to_integer(unsigned(MCycle)) is
794 Set_BusB_To <= "1101";
800 Set_BusB_To <= "1100";
806 elsif IntCycle = '1' then
809 case to_integer(unsigned(MCycle)) is
815 Set_BusB_To <= "1101";
821 Set_BusB_To <= "1100";
845 -- 16 BIT ARITHMETIC GROUP
846 when "00001001"|"00011001"|"00101001"|"00111001" =>
849 case to_integer(unsigned(MCycle)) is
855 Set_BusA_To(2 downto 0) <= "101";
856 case to_integer(unsigned(IR(5 downto 4))) is
858 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
859 Set_BusB_To(0) <= '1';
861 Set_BusB_To <= "1000";
870 Set_BusA_To(2 downto 0) <= "100";
871 case to_integer(unsigned(IR(5 downto 4))) is
873 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
875 Set_BusB_To <= "1001";
880 when "00000011"|"00010011"|"00100011"|"00110011" =>
883 IncDec_16(3 downto 2) <= "01";
884 IncDec_16(1 downto 0) <= DPair;
885 when "00001011"|"00011011"|"00101011"|"00111011" =>
888 IncDec_16(3 downto 2) <= "11";
889 IncDec_16(1 downto 0) <= DPair;
891 -- ROTATE AND SHIFT GROUP
900 Set_BusA_To(2 downto 0) <= "111";
909 case to_integer(unsigned(MCycle)) is
918 when "11000010"|"11001010"|"11010010"|"11011010"|"11100010"|"11101010"|"11110010"|"11111010" =>
919 if IR(5) = '1' and Mode = 3 then
920 case IRB(4 downto 3) is
924 case to_integer(unsigned(MCycle)) is
927 Set_BusB_To <= "0111";
936 case to_integer(unsigned(MCycle)) is
943 Set_BusB_To <= "0111";
951 case to_integer(unsigned(MCycle)) is
962 case to_integer(unsigned(MCycle)) is
977 case to_integer(unsigned(MCycle)) is
983 if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
993 case to_integer(unsigned(MCycle)) is
1000 when others => null;
1007 case to_integer(unsigned(MCycle)) is
1010 if F(Flag_C) = '0' then
1017 when others => null;
1024 case to_integer(unsigned(MCycle)) is
1027 if F(Flag_C) = '1' then
1034 when others => null;
1041 case to_integer(unsigned(MCycle)) is
1044 if F(Flag_Z) = '0' then
1051 when others => null;
1058 case to_integer(unsigned(MCycle)) is
1061 if F(Flag_Z) = '1' then
1068 when others => null;
1080 case to_integer(unsigned(MCycle)) is
1084 Set_BusB_To <= "1010";
1085 Set_BusA_To(2 downto 0) <= "000";
1096 when others => null;
1100 -- CALL AND RETURN GROUP
1104 case to_integer(unsigned(MCycle)) is
1109 IncDec_16 <= "1111";
1114 Set_BusB_To <= "1101";
1117 IncDec_16 <= "1111";
1119 Set_BusB_To <= "1100";
1123 when others => null;
1125 when "11000100"|"11001100"|"11010100"|"11011100"|"11100100"|"11101100"|"11110100"|"11111100" =>
1126 if IR(5) = '0' or Mode /= 3 then
1129 case to_integer(unsigned(MCycle)) is
1136 if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
1137 IncDec_16 <= "1111";
1140 Set_BusB_To <= "1101";
1146 IncDec_16 <= "1111";
1148 Set_BusB_To <= "1100";
1152 when others => null;
1158 case to_integer(unsigned(MCycle)) is
1163 IncDec_16 <= "0111";
1168 IncDec_16 <= "0111";
1169 when others => null;
1171 when "11000000"|"11001000"|"11010000"|"11011000"|"11100000"|"11101000"|"11110000"|"11111000" =>
1172 if IR(5) = '1' and Mode = 3 then
1173 case IRB(4 downto 3) is
1177 case to_integer(unsigned(MCycle)) is
1180 Set_Addr_To <= aIOA;
1181 Set_BusB_To <= "0111";
1184 when others => null;
1189 case to_integer(unsigned(MCycle)) is
1195 Set_BusA_To <= "1000";
1196 Set_BusB_To <= "0110";
1202 Set_BusA_To <= "1001";
1203 Set_BusB_To <= "1110"; -- Incorrect unsigned !!!!!!!!!!!!!!!!!!!!!
1209 case to_integer(unsigned(MCycle)) is
1212 Set_Addr_To <= aIOA;
1215 when others => null;
1218 -- LD HL,SP+n -- Not correct !!!!!!!!!!!!!!!!!!!
1220 case to_integer(unsigned(MCycle)) is
1229 Set_BusA_To(2 downto 0) <= "101"; -- L
1234 Set_BusA_To(2 downto 0) <= "100"; -- H
1236 when others => null;
1242 case to_integer(unsigned(MCycle)) is
1244 if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
1251 IncDec_16 <= "0111";
1256 IncDec_16 <= "0111";
1257 when others => null;
1260 when "11000111"|"11001111"|"11010111"|"11011111"|"11100111"|"11101111"|"11110111"|"11111111" =>
1263 case to_integer(unsigned(MCycle)) is
1266 IncDec_16 <= "1111";
1268 Set_BusB_To <= "1101";
1271 IncDec_16 <= "1111";
1273 Set_BusB_To <= "1100";
1277 when others => null;
1280 -- INPUT AND OUTPUT GROUP
1285 case to_integer(unsigned(MCycle)) is
1288 Set_Addr_To <= aIOA;
1292 when others => null;
1299 case to_integer(unsigned(MCycle)) is
1302 Set_Addr_To <= aIOA;
1303 Set_BusB_To <= "0111";
1307 when others => null;
1311 ------------------------------------------------------------------------------
1312 ------------------------------------------------------------------------------
1313 -- MULTIBYTE INSTRUCTIONS
1314 ------------------------------------------------------------------------------
1315 ------------------------------------------------------------------------------
1327 when "11011101"|"11111101" =>
1336 ------------------------------------------------------------------------------
1338 -- CB prefixed instructions
1340 ------------------------------------------------------------------------------
1342 Set_BusA_To(2 downto 0) <= IR(2 downto 0);
1343 Set_BusB_To(2 downto 0) <= IR(2 downto 0);
1346 when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000111"
1347 |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010111"
1348 |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001111"
1349 |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011111"
1350 |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100111"
1351 |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101111"
1352 |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110111"
1353 |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111111" =>
1361 -- SLL r (Undocumented) / SWAP r
1362 if MCycle = "001" then
1367 when "00000110"|"00010110"|"00001110"|"00011110"|"00101110"|"00111110"|"00100110"|"00110110" =>
1375 -- SLL (HL) (Undocumented) / SWAP (HL)
1377 case to_integer(unsigned(MCycle)) is
1390 when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
1391 |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
1392 |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
1393 |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
1394 |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
1395 |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
1396 |"01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111"
1397 |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
1399 if MCycle = "001" then
1400 Set_BusB_To(2 downto 0) <= IR(2 downto 0);
1403 when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01110110"|"01111110" =>
1406 case to_integer(unsigned(MCycle)) is
1414 when "11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000111"
1415 |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001111"
1416 |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010111"
1417 |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011111"
1418 |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100111"
1419 |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101111"
1420 |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110111"
1421 |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111111" =>
1423 if MCycle = "001" then
1428 when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
1431 case to_integer(unsigned(MCycle)) is
1444 when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
1445 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
1446 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
1447 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
1448 |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
1449 |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
1450 |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
1451 |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
1453 if MCycle = "001" then
1458 when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
1461 case to_integer(unsigned(MCycle)) is
1478 ------------------------------------------------------------------------------
1480 -- ED prefixed instructions
1482 ------------------------------------------------------------------------------
1485 when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000110"|"00000111"
1486 |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001110"|"00001111"
1487 |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010110"|"00010111"
1488 |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011110"|"00011111"
1489 |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100110"|"00100111"
1490 |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101110"|"00101111"
1491 |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110110"|"00110111"
1492 |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111110"|"00111111"
1495 |"10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000110"|"10000111"
1496 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001110"|"10001111"
1497 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010110"|"10010111"
1498 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011110"|"10011111"
1499 | "10100100"|"10100101"|"10100110"|"10100111"
1500 | "10101100"|"10101101"|"10101110"|"10101111"
1501 | "10110100"|"10110101"|"10110110"|"10110111"
1502 | "10111100"|"10111101"|"10111110"|"10111111"
1503 |"11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000110"|"11000111"
1504 |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001110"|"11001111"
1505 |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010110"|"11010111"
1506 |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011110"|"11011111"
1507 |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100110"|"11100111"
1508 |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101110"|"11101111"
1509 |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110110"|"11110111"
1510 |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111110"|"11111111" =>
1511 null; -- NOP, undocumented
1512 when "01111110"|"01111111" =>
1513 -- NOP, undocumented
1518 Special_LD <= "100";
1522 Special_LD <= "101";
1526 Special_LD <= "110";
1530 Special_LD <= "111";
1532 -- 16 BIT LOAD GROUP
1533 when "01001011"|"01011011"|"01101011"|"01111011" =>
1536 case to_integer(unsigned(MCycle)) is
1546 if IR(5 downto 4) = "11" then
1547 Set_BusA_To <= "1000";
1549 Set_BusA_To(2 downto 1) <= IR(5 downto 4);
1550 Set_BusA_To(0) <= '1';
1556 if IR(5 downto 4) = "11" then
1557 Set_BusA_To <= "1001";
1559 Set_BusA_To(2 downto 1) <= IR(5 downto 4);
1560 Set_BusA_To(0) <= '0';
1562 when others => null;
1564 when "01000011"|"01010011"|"01100011"|"01110011" =>
1567 case to_integer(unsigned(MCycle)) is
1575 if IR(5 downto 4) = "11" then
1576 Set_BusB_To <= "1000";
1578 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1579 Set_BusB_To(0) <= '1';
1580 Set_BusB_To(3) <= '0';
1586 if IR(5 downto 4) = "11" then
1587 Set_BusB_To <= "1001";
1589 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1590 Set_BusB_To(0) <= '0';
1591 Set_BusB_To(3) <= '0';
1595 when others => null;
1597 when "10100000" | "10101000" | "10110000" | "10111000" =>
1598 -- LDI, LDD, LDIR, LDDR
1600 case to_integer(unsigned(MCycle)) is
1603 IncDec_16 <= "1100"; -- BC
1605 Set_BusB_To <= "0110";
1606 Set_BusA_To(2 downto 0) <= "111";
1610 IncDec_16 <= "0110"; -- IX
1612 IncDec_16 <= "1110";
1619 IncDec_16 <= "0101"; -- DE
1621 IncDec_16 <= "1101";
1626 when others => null;
1628 when "10100001" | "10101001" | "10110001" | "10111001" =>
1629 -- CPI, CPD, CPIR, CPDR
1631 case to_integer(unsigned(MCycle)) is
1634 IncDec_16 <= "1100"; -- BC
1636 Set_BusB_To <= "0110";
1637 Set_BusA_To(2 downto 0) <= "111";
1642 IncDec_16 <= "0110";
1644 IncDec_16 <= "1110";
1653 when others => null;
1655 when "01000100"|"01001100"|"01010100"|"01011100"|"01100100"|"01101100"|"01110100"|"01111100" =>
1658 Set_BusB_To <= "0111";
1659 Set_BusA_To <= "1010";
1662 when "01000110"|"01001110"|"01100110"|"01101110" =>
1665 when "01010110"|"01110110" =>
1668 when "01011110"|"01110111" =>
1671 -- 16 bit arithmetic
1672 when "01001010"|"01011010"|"01101010"|"01111010" =>
1675 case to_integer(unsigned(MCycle)) is
1681 Set_BusA_To(2 downto 0) <= "101";
1682 case to_integer(unsigned(IR(5 downto 4))) is
1684 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1685 Set_BusB_To(0) <= '1';
1687 Set_BusB_To <= "1000";
1695 Set_BusA_To(2 downto 0) <= "100";
1696 case to_integer(unsigned(IR(5 downto 4))) is
1698 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1699 Set_BusB_To(0) <= '0';
1701 Set_BusB_To <= "1001";
1705 when "01000010"|"01010010"|"01100010"|"01110010" =>
1708 case to_integer(unsigned(MCycle)) is
1714 Set_BusA_To(2 downto 0) <= "101";
1715 case to_integer(unsigned(IR(5 downto 4))) is
1717 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1718 Set_BusB_To(0) <= '1';
1720 Set_BusB_To <= "1000";
1728 Set_BusA_To(2 downto 0) <= "100";
1729 case to_integer(unsigned(IR(5 downto 4))) is
1731 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1733 Set_BusB_To <= "1001";
1740 case to_integer(unsigned(MCycle)) is
1746 Set_BusB_To(2 downto 0) <= "110";
1747 Set_BusA_To(2 downto 0) <= "111";
1760 case to_integer(unsigned(MCycle)) is
1765 Set_BusB_To(2 downto 0) <= "110";
1766 Set_BusA_To(2 downto 0) <= "111";
1776 when "01000101"|"01001101"|"01010101"|"01011101"|"01100101"|"01101101"|"01110101"|"01111101" =>
1779 case to_integer(unsigned(MCycle)) is
1783 IncDec_16 <= "0111";
1788 IncDec_16 <= "0111";
1790 when others => null;
1792 when "01000000"|"01001000"|"01010000"|"01011000"|"01100000"|"01101000"|"01110000"|"01111000" =>
1795 case to_integer(unsigned(MCycle)) is
1800 if IR(5 downto 3) /= "110" then
1802 Set_BusA_To(2 downto 0) <= IR(5 downto 3);
1807 when "01000001"|"01001001"|"01010001"|"01011001"|"01100001"|"01101001"|"01110001"|"01111001" =>
1811 case to_integer(unsigned(MCycle)) is
1814 Set_BusB_To(2 downto 0) <= IR(5 downto 3);
1815 if IR(5 downto 3) = "110" then
1816 Set_BusB_To(3) <= '1';
1823 when "10100010" | "10101010" | "10110010" | "10111010" =>
1824 -- INI, IND, INIR, INDR
1826 case to_integer(unsigned(MCycle)) is
1829 Set_BusB_To <= "1010";
1830 Set_BusA_To <= "0000";
1836 Set_BusB_To <= "0110";
1840 IncDec_16 <= "0010";
1842 IncDec_16 <= "1010";
1850 when others => null;
1852 when "10100011" | "10101011" | "10110011" | "10111011" =>
1853 -- OUTI, OUTD, OTIR, OTDR
1855 case to_integer(unsigned(MCycle)) is
1859 Set_BusB_To <= "1010";
1860 Set_BusA_To <= "0000";
1865 Set_BusB_To <= "0110";
1869 IncDec_16 <= "0010";
1871 IncDec_16 <= "1010";
1879 when others => null;
1886 if MCycle = "001" then
1887 -- TStates <= "100";
1894 if MCycle = "001" then
1895 -- TStates <= "100";
1902 if MCycle = "110" then
1907 Set_BusB_To(2 downto 0) <= SSS;
1908 Set_BusB_To(3) <= '0';
1910 if IRB = "00110110" or IRB = "11001011" then
1911 Set_Addr_To <= aNone;
1914 if MCycle = "111" then
1918 if ISet /= "01" then
1921 Set_BusB_To(2 downto 0) <= SSS;
1922 Set_BusB_To(3) <= '0';
1923 if IRB = "00110110" or ISet = "01" then