Subversion Repositories KoE_projects

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. --------------------------------------------------------------------------------
  2. -- ****
  3. -- T80(c) core. Attempt to finish all undocumented features and provide
  4. --              accurate timings.
  5. -- Version 350.
  6. -- Copyright (c) 2018 Sorgelig
  7. --  Test passed: ZEXDOC, ZEXALL, Z80Full(*), Z80memptr
  8. --  (*) Currently only SCF and CCF instructions aren't passed X/Y flags check as
  9. --      correct implementation is still unclear.
  10. --
  11. -- ****
  12. -- T80(b) core. In an effort to merge and maintain bug fixes ....
  13. --
  14. -- Ver 303 add undocumented DDCB and FDCB opcodes by TobiFlex 20.04.2010
  15. -- Ver 300 started tidyup
  16. -- MikeJ March 2005
  17. -- Latest version from www.fpgaarcade.com (original www.opencores.org)
  18. --
  19. -- ****
  20. -- Z80 compatible microprocessor core
  21. --
  22. -- Version : 0242
  23. -- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
  24. -- All rights reserved
  25. --
  26. -- Redistribution and use in source and synthezised forms, with or without
  27. -- modification, are permitted provided that the following conditions are met:
  28. --
  29. -- Redistributions of source code must retain the above copyright notice,
  30. -- this list of conditions and the following disclaimer.
  31. --
  32. -- Redistributions in synthesized form must reproduce the above copyright
  33. -- notice, this list of conditions and the following disclaimer in the
  34. -- documentation and/or other materials provided with the distribution.
  35. --
  36. -- Neither the name of the author nor the names of other contributors may
  37. -- be used to endorse or promote products derived from this software without
  38. -- specific prior written permission.
  39. --
  40. -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  41. -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  42. -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43. -- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
  44. -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  45. -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47. -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48. -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  50. -- POSSIBILITY OF SUCH DAMAGE.
  51. --
  52. -- Please report bugs to the author, but before you do so, please
  53. -- make sure that this is not a derivative work and that
  54. -- you have the latest version of this file.
  55. --
  56. -- The latest version of this file can be found at:
  57. --      http://www.opencores.org/cvsweb.shtml/t80/
  58. --
  59. -- Limitations :
  60. --
  61. -- File history :
  62. --
  63. --      0208 : First complete release
  64. --      0211 : Fixed IM 1
  65. --      0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
  66. --      0235 : Added IM 2 fix by Mike Johnson
  67. --      0238 : Added NoRead signal
  68. --      0238b: Fixed instruction timing for POP and DJNZ
  69. --      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
  71. --      0242 : Fixed I/O instruction timing, cleanup
  72. --
  73.  
  74. library IEEE;
  75. use IEEE.std_logic_1164.all;
  76. use IEEE.numeric_std.all;
  77.  
  78. entity T80_MCode is
  79.         generic(
  80.                 Mode   : integer := 0;
  81.                 Flag_C : integer := 0;
  82.                 Flag_N : integer := 1;
  83.                 Flag_P : integer := 2;
  84.                 Flag_X : integer := 3;
  85.                 Flag_H : integer := 4;
  86.                 Flag_Y : integer := 5;
  87.                 Flag_Z : integer := 6;
  88.                 Flag_S : integer := 7
  89.         );
  90.         port(
  91.       IR          : in std_logic_vector(7 downto 0);
  92.       ISet        : in std_logic_vector(1 downto 0);
  93.       MCycle      : in std_logic_vector(2 downto 0);
  94.       F           : in std_logic_vector(7 downto 0);
  95.       NMICycle    : in std_logic;
  96.       IntCycle    : in std_logic;
  97.       XY_State    : in std_logic_vector(1 downto 0);
  98.       MCycles     : out std_logic_vector(2 downto 0);
  99.       TStates     : out std_logic_vector(2 downto 0);
  100.       Prefix      : out std_logic_vector(1 downto 0); -- None,CB,ED,DD/FD
  101.       Inc_PC      : out std_logic;
  102.       Inc_WZ      : out std_logic;
  103.       IncDec_16   : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP   0 is inc
  104.       Read_To_Reg : out std_logic;
  105.       Read_To_Acc : out std_logic;
  106.       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
  107.       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
  108.       ALU_Op      : out std_logic_vector(3 downto 0);
  109.          -- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
  110.       Save_ALU    : out std_logic;
  111.       PreserveC   : out std_logic;
  112.       Arith16     : out std_logic;
  113.       Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
  114.       IORQ        : out std_logic;
  115.       Jump        : out std_logic;
  116.       JumpE       : out std_logic;
  117.       JumpXY      : out std_logic;
  118.       Call        : out std_logic;
  119.       RstP        : out std_logic;
  120.       LDZ         : out std_logic;
  121.       LDW         : out std_logic;
  122.       LDSPHL      : out std_logic;
  123.       Special_LD  : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
  124.       ExchangeDH  : out std_logic;
  125.       ExchangeRp  : out std_logic;
  126.       ExchangeAF  : out std_logic;
  127.       ExchangeRS  : out std_logic;
  128.       I_DJNZ      : out std_logic;
  129.       I_CPL       : out std_logic;
  130.       I_CCF       : out std_logic;
  131.       I_SCF       : out std_logic;
  132.       I_RETN      : out std_logic;
  133.       I_BT        : out std_logic;
  134.       I_BC        : out std_logic;
  135.       I_BTR       : out std_logic;
  136.       I_RLD       : out std_logic;
  137.       I_RRD       : out std_logic;
  138.       I_INRC      : out std_logic;
  139.       SetWZ       : out std_logic_vector(1 downto 0);
  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;
  146.       XYbit_undoc : out std_logic
  147.    );
  148. end T80_MCode;
  149.  
  150. architecture rtl of T80_MCode is
  151.  
  152.         constant aNone : std_logic_vector(2 downto 0) := "111";
  153.         constant aBC   : std_logic_vector(2 downto 0) := "000";
  154.         constant aDE   : std_logic_vector(2 downto 0) := "001";
  155.         constant aXY   : std_logic_vector(2 downto 0) := "010";
  156.         constant aIOA  : std_logic_vector(2 downto 0) := "100";
  157.         constant aSP   : std_logic_vector(2 downto 0) := "101";
  158.         constant aZI   : std_logic_vector(2 downto 0) := "110";
  159.  
  160.         function is_cc_true(
  161.                 F : std_logic_vector(7 downto 0);
  162.                 cc : bit_vector(2 downto 0)
  163.                 ) return boolean is
  164.         begin
  165.                 if Mode = 3 then
  166.                         case cc is
  167.                         when "000" => return F(Flag_S) = '0'; -- NZ
  168.                         when "001" => return F(Flag_S) = '1'; -- Z
  169.                         when "010" => return F(Flag_H) = '0'; -- NC
  170.                         when "011" => return F(Flag_H) = '1'; -- C
  171.                         when "100" => return false;
  172.                         when "101" => return false;
  173.                         when "110" => return false;
  174.                         when "111" => return false;
  175.                         end case;
  176.                 else
  177.                         case cc is
  178.                         when "000" => return F(Flag_Z) = '0'; -- NZ
  179.                         when "001" => return F(Flag_Z) = '1'; -- Z
  180.                         when "010" => return F(Flag_C) = '0'; -- NC
  181.                         when "011" => return F(Flag_C) = '1'; -- C
  182.                         when "100" => return F(Flag_P) = '0'; -- PO
  183.                         when "101" => return F(Flag_P) = '1'; -- PE
  184.                         when "110" => return F(Flag_S) = '0'; -- P
  185.                         when "111" => return F(Flag_S) = '1'; -- M
  186.                         end case;
  187.                 end if;
  188.         end;
  189.  
  190. begin
  191.  
  192.         process (IR, ISet, MCycle, F, NMICycle, IntCycle, XY_State)
  193.                 variable DDD   : std_logic_vector(2 downto 0);
  194.                 variable SSS   : std_logic_vector(2 downto 0);
  195.                 variable DPair : std_logic_vector(1 downto 0);
  196.                 variable IRB   : bit_vector(7 downto 0);
  197.         begin
  198.                 DDD := IR(5 downto 3);
  199.                 SSS := IR(2 downto 0);
  200.                 DPair := IR(5 downto 4);
  201.                 IRB := to_bitvector(IR);
  202.  
  203.                 MCycles <= "001";
  204.                 if MCycle = "001" then
  205.                         TStates <= "100";
  206.                 else
  207.                         TStates <= "011";
  208.                 end if;
  209.                 Prefix <= "00";
  210.                 Inc_PC <= '0';
  211.                 Inc_WZ <= '0';
  212.                 IncDec_16 <= "0000";
  213.                 Read_To_Acc <= '0';
  214.                 Read_To_Reg <= '0';
  215.                 Set_BusB_To <= "0000";
  216.                 Set_BusA_To <= "0000";
  217.                 ALU_Op <= "0" & IR(5 downto 3);
  218.                 Save_ALU <= '0';
  219.                 PreserveC <= '0';
  220.                 Arith16 <= '0';
  221.                 IORQ <= '0';
  222.                 Set_Addr_To <= aNone;
  223.                 Jump <= '0';
  224.                 JumpE <= '0';
  225.                 JumpXY <= '0';
  226.                 Call <= '0';
  227.                 RstP <= '0';
  228.                 LDZ <= '0';
  229.                 LDW <= '0';
  230.                 LDSPHL <= '0';
  231.                 Special_LD <= "000";
  232.                 ExchangeDH <= '0';
  233.                 ExchangeRp <= '0';
  234.                 ExchangeAF <= '0';
  235.                 ExchangeRS <= '0';
  236.                 I_DJNZ <= '0';
  237.                 I_CPL <= '0';
  238.                 I_CCF <= '0';
  239.                 I_SCF <= '0';
  240.                 I_RETN <= '0';
  241.                 I_BT <= '0';
  242.                 I_BC <= '0';
  243.                 I_BTR <= '0';
  244.                 I_RLD <= '0';
  245.                 I_RRD <= '0';
  246.                 I_INRC <= '0';
  247.                 SetDI <= '0';
  248.                 SetEI <= '0';
  249.                 IMode <= "11";
  250.                 Halt <= '0';
  251.                 NoRead <= '0';
  252.                 Write <= '0';
  253.                 XYbit_undoc <= '0';
  254.                 SetWZ <= "00";
  255.  
  256.                 case ISet is
  257.                 when "00" =>
  258.  
  259. ------------------------------------------------------------------------------
  260. --
  261. --      Unprefixed instructions
  262. --
  263. ------------------------------------------------------------------------------
  264.  
  265.                 case IRB is
  266. -- 8 BIT LOAD GROUP
  267.                 when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
  268.                         |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
  269.                         |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
  270.                         |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
  271.                         |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
  272.                         |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
  273.                         |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
  274.                         -- LD r,r'
  275.                         Set_BusB_To(2 downto 0) <= SSS;
  276.                         ExchangeRp <= '1';
  277.                         Set_BusA_To(2 downto 0) <= DDD;
  278.                         Read_To_Reg <= '1';
  279.                 when "00000110"|"00001110"|"00010110"|"00011110"|"00100110"|"00101110"|"00111110" =>
  280.                         -- LD r,n
  281.                         MCycles <= "010";
  282.                         case to_integer(unsigned(MCycle)) is
  283.                         when 2 =>
  284.                                 Inc_PC <= '1';
  285.                                 Set_BusA_To(2 downto 0) <= DDD;
  286.                                 Read_To_Reg <= '1';
  287.                         when others => null;
  288.                         end case;
  289.                 when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01111110" =>
  290.                         -- LD r,(HL)
  291.                         MCycles <= "010";
  292.                         case to_integer(unsigned(MCycle)) is
  293.                         when 1 =>
  294.                                 Set_Addr_To <= aXY;
  295.                         when 2 =>
  296.                                 Set_BusA_To(2 downto 0) <= DDD;
  297.                                 Read_To_Reg <= '1';
  298.                         when others => null;
  299.                         end case;
  300.                 when "01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111" =>
  301.                         -- LD (HL),r
  302.                         MCycles <= "010";
  303.                         case to_integer(unsigned(MCycle)) is
  304.                         when 1 =>
  305.                                 Set_Addr_To <= aXY;
  306.                                 Set_BusB_To(2 downto 0) <= SSS;
  307.                                 Set_BusB_To(3) <= '0';
  308.                         when 2 =>
  309.                                 Write <= '1';
  310.                         when others => null;
  311.                         end case;
  312.                 when "00110110" =>
  313.                         -- LD (HL),n
  314.                         MCycles <= "011";
  315.                         case to_integer(unsigned(MCycle)) is
  316.                         when 2 =>
  317.                                 Inc_PC <= '1';
  318.                                 Set_Addr_To <= aXY;
  319.                                 Set_BusB_To(2 downto 0) <= SSS;
  320.                                 Set_BusB_To(3) <= '0';
  321.                         when 3 =>
  322.                                 Write <= '1';
  323.                         when others => null;
  324.                         end case;
  325.                 when "00001010" =>
  326.                         -- LD A,(BC)
  327.                         MCycles <= "010";
  328.                         case to_integer(unsigned(MCycle)) is
  329.                         when 1 =>
  330.                                 Set_Addr_To <= aBC;
  331.                         when 2 =>
  332.                                 Read_To_Acc <= '1';
  333.                         when others => null;
  334.                         end case;
  335.                 when "00011010" =>
  336.                         -- LD A,(DE)
  337.                         MCycles <= "010";
  338.                         case to_integer(unsigned(MCycle)) is
  339.                         when 1 =>
  340.                                 Set_Addr_To <= aDE;
  341.                         when 2 =>
  342.                                 Read_To_Acc <= '1';
  343.                         when others => null;
  344.                         end case;
  345.                 when "00111010" =>
  346.                         if Mode = 3 then
  347.                                 -- LDD A,(HL)
  348.                                 MCycles <= "010";
  349.                                 case to_integer(unsigned(MCycle)) is
  350.                                 when 1 =>
  351.                                         Set_Addr_To <= aXY;
  352.                                 when 2 =>
  353.                                         Read_To_Acc <= '1';
  354.                                         IncDec_16 <= "1110";
  355.                                 when others => null;
  356.                                 end case;
  357.                         else
  358.                                 -- LD A,(nn)
  359.                                 MCycles <= "100";
  360.                                 case to_integer(unsigned(MCycle)) is
  361.                                 when 2 =>
  362.                                         Inc_PC <= '1';
  363.                                         LDZ <= '1';
  364.                                 when 3 =>
  365.                                         Set_Addr_To <= aZI;
  366.                                         Inc_PC <= '1';
  367.                                 when 4 =>
  368.                                         Read_To_Acc <= '1';
  369.                                 when others => null;
  370.                                 end case;
  371.                         end if;
  372.                 when "00000010" =>
  373.                         -- LD (BC),A
  374.                         MCycles <= "010";
  375.                         case to_integer(unsigned(MCycle)) is
  376.                         when 1 =>
  377.                                 Set_Addr_To <= aBC;
  378.                                 Set_BusB_To <= "0111";
  379.                                 SetWZ <= "10";
  380.                         when 2 =>
  381.                                 Write <= '1';
  382.                         when others => null;
  383.                         end case;
  384.                 when "00010010" =>
  385.                         -- LD (DE),A
  386.                         MCycles <= "010";
  387.                         case to_integer(unsigned(MCycle)) is
  388.                         when 1 =>
  389.                                 Set_Addr_To <= aDE;
  390.                                 Set_BusB_To <= "0111";
  391.                                 SetWZ <= "10";
  392.                         when 2 =>
  393.                                 Write <= '1';
  394.                         when others => null;
  395.                         end case;
  396.                 when "00110010" =>
  397.                         if Mode = 3 then
  398.                                 -- LDD (HL),A
  399.                                 MCycles <= "010";
  400.                                 case to_integer(unsigned(MCycle)) is
  401.                                 when 1 =>
  402.                                         Set_Addr_To <= aXY;
  403.                                         Set_BusB_To <= "0111";
  404.                                 when 2 =>
  405.                                         Write <= '1';
  406.                                         IncDec_16 <= "1110";
  407.                                 when others => null;
  408.                                 end case;
  409.                         else
  410.                                 -- LD (nn),A
  411.                                 MCycles <= "100";
  412.                                 case to_integer(unsigned(MCycle)) is
  413.                                 when 2 =>
  414.                                         Inc_PC <= '1';
  415.                                         LDZ <= '1';
  416.                                 when 3 =>
  417.                                         Set_Addr_To <= aZI;
  418.                                         SetWZ <= "10";
  419.                                         Inc_PC <= '1';
  420.                                         Set_BusB_To <= "0111";
  421.                                 when 4 =>
  422.                                         Write <= '1';
  423.                                 when others => null;
  424.                                 end case;
  425.                         end if;
  426.  
  427. -- 16 BIT LOAD GROUP
  428.                 when "00000001"|"00010001"|"00100001"|"00110001" =>
  429.                         -- LD dd,nn
  430.                         MCycles <= "011";
  431.                         case to_integer(unsigned(MCycle)) is
  432.                         when 2 =>
  433.                                 Inc_PC <= '1';
  434.                                 Read_To_Reg <= '1';
  435.                                 if DPAIR = "11" then
  436.                                         Set_BusA_To(3 downto 0) <= "1000";
  437.                                 else
  438.                                         Set_BusA_To(2 downto 1) <= DPAIR;
  439.                                         Set_BusA_To(0) <= '1';
  440.                                 end if;
  441.                         when 3 =>
  442.                                 Inc_PC <= '1';
  443.                                 Read_To_Reg <= '1';
  444.                                 if DPAIR = "11" then
  445.                                         Set_BusA_To(3 downto 0) <= "1001";
  446.                                 else
  447.                                         Set_BusA_To(2 downto 1) <= DPAIR;
  448.                                         Set_BusA_To(0) <= '0';
  449.                                 end if;
  450.                         when others => null;
  451.                         end case;
  452.                 when "00101010" =>
  453.                         if Mode = 3 then
  454.                                 -- LDI A,(HL)
  455.                                 MCycles <= "010";
  456.                                 case to_integer(unsigned(MCycle)) is
  457.                                 when 1 =>
  458.                                         Set_Addr_To <= aXY;
  459.                                 when 2 =>
  460.                                         Read_To_Acc <= '1';
  461.                                         IncDec_16 <= "0110";
  462.                                 when others => null;
  463.                                 end case;
  464.                         else
  465.                                 -- LD HL,(nn)
  466.                                 MCycles <= "101";
  467.                                 case to_integer(unsigned(MCycle)) is
  468.                                 when 2 =>
  469.                                         Inc_PC <= '1';
  470.                                         LDZ <= '1';
  471.                                 when 3 =>
  472.                                         Set_Addr_To <= aZI;
  473.                                         Inc_PC <= '1';
  474.                                         LDW <= '1';
  475.                                 when 4 =>
  476.                                         Set_BusA_To(2 downto 0) <= "101"; -- L
  477.                                         Read_To_Reg <= '1';
  478.                                         Inc_WZ <= '1';
  479.                                         Set_Addr_To <= aZI;
  480.                                 when 5 =>
  481.                                         Set_BusA_To(2 downto 0) <= "100"; -- H
  482.                                         Read_To_Reg <= '1';
  483.                                 when others => null;
  484.                                 end case;
  485.                         end if;
  486.                 when "00100010" =>
  487.                         if Mode = 3 then
  488.                                 -- LDI (HL),A
  489.                                 MCycles <= "010";
  490.                                 case to_integer(unsigned(MCycle)) is
  491.                                 when 1 =>
  492.                                         Set_Addr_To <= aXY;
  493.                                         Set_BusB_To <= "0111";
  494.                                 when 2 =>
  495.                                         Write <= '1';
  496.                                         IncDec_16 <= "0110";
  497.                                 when others => null;
  498.                                 end case;
  499.                         else
  500.                                 -- LD (nn),HL
  501.                                 MCycles <= "101";
  502.                                 case to_integer(unsigned(MCycle)) is
  503.                                 when 2 =>
  504.                                         Inc_PC <= '1';
  505.                                         LDZ <= '1';
  506.                                 when 3 =>
  507.                                         Set_Addr_To <= aZI;
  508.                                         Inc_PC <= '1';
  509.                                         LDW <= '1';
  510.                                         Set_BusB_To <= "0101"; -- L
  511.                                 when 4 =>
  512.                                         Inc_WZ <= '1';
  513.                                         Set_Addr_To <= aZI;
  514.                                         Write <= '1';
  515.                                         Set_BusB_To <= "0100"; -- H
  516.                                 when 5 =>
  517.                                         Write <= '1';
  518.                                 when others => null;
  519.                                 end case;
  520.                         end if;
  521.                 when "11111001" =>
  522.                         -- LD SP,HL
  523.                         TStates <= "110";
  524.                         LDSPHL <= '1';
  525.                 when "11000101"|"11010101"|"11100101"|"11110101" =>
  526.                         -- PUSH qq
  527.                         MCycles <= "011";
  528.                         case to_integer(unsigned(MCycle)) is
  529.                         when 1 =>
  530.                                 TStates <= "101";
  531.                                 IncDec_16 <= "1111";
  532.                                 Set_Addr_TO <= aSP;
  533.                                 if DPAIR = "11" then
  534.                                         Set_BusB_To <= "0111";
  535.                                 else
  536.                                         Set_BusB_To(2 downto 1) <= DPAIR;
  537.                                         Set_BusB_To(0) <= '0';
  538.                                         Set_BusB_To(3) <= '0';
  539.                                 end if;
  540.                         when 2 =>
  541.                                 IncDec_16 <= "1111";
  542.                                 Set_Addr_To <= aSP;
  543.                                 if DPAIR = "11" then
  544.                                         Set_BusB_To <= "1011";
  545.                                 else
  546.                                         Set_BusB_To(2 downto 1) <= DPAIR;
  547.                                         Set_BusB_To(0) <= '1';
  548.                                         Set_BusB_To(3) <= '0';
  549.                                 end if;
  550.                                 Write <= '1';
  551.                         when 3 =>
  552.                                 Write <= '1';
  553.                         when others => null;
  554.                         end case;
  555.                 when "11000001"|"11010001"|"11100001"|"11110001" =>
  556.                         -- POP qq
  557.                         MCycles <= "011";
  558.                         case to_integer(unsigned(MCycle)) is
  559.                         when 1 =>
  560.                                 Set_Addr_To <= aSP;
  561.                         when 2 =>
  562.                                 IncDec_16 <= "0111";
  563.                                 Set_Addr_To <= aSP;
  564.                                 Read_To_Reg <= '1';
  565.                                 if DPAIR = "11" then
  566.                                         Set_BusA_To(3 downto 0) <= "1011";
  567.                                 else
  568.                                         Set_BusA_To(2 downto 1) <= DPAIR;
  569.                                         Set_BusA_To(0) <= '1';
  570.                                 end if;
  571.                         when 3 =>
  572.                                 IncDec_16 <= "0111";
  573.                                 Read_To_Reg <= '1';
  574.                                 if DPAIR = "11" then
  575.                                         Set_BusA_To(3 downto 0) <= "0111";
  576.                                 else
  577.                                         Set_BusA_To(2 downto 1) <= DPAIR;
  578.                                         Set_BusA_To(0) <= '0';
  579.                                 end if;
  580.                         when others => null;
  581.                         end case;
  582.  
  583. -- EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
  584.                 when "11101011" =>
  585.                         if Mode /= 3 then
  586.                                 -- EX DE,HL
  587.                                 ExchangeDH <= '1';
  588.                         end if;
  589.                 when "00001000" =>
  590.                         if Mode = 3 then
  591.                                 -- LD (nn),SP
  592.                                 MCycles <= "101";
  593.                                 case to_integer(unsigned(MCycle)) is
  594.                                 when 2 =>
  595.                                         Inc_PC <= '1';
  596.                                         LDZ <= '1';
  597.                                 when 3 =>
  598.                                         Set_Addr_To <= aZI;
  599.                                         Inc_PC <= '1';
  600.                                         LDW <= '1';
  601.                                         Set_BusB_To <= "1000";
  602.                                 when 4 =>
  603.                                         Inc_WZ <= '1';
  604.                                         Set_Addr_To <= aZI;
  605.                                         Write <= '1';
  606.                                         Set_BusB_To <= "1001";
  607.                                 when 5 =>
  608.                                         Write <= '1';
  609.                                 when others => null;
  610.                                 end case;
  611.                         elsif Mode < 2 then
  612.                                 -- EX AF,AF'
  613.                                 ExchangeAF <= '1';
  614.                         end if;
  615.                 when "11011001" =>
  616.                         if Mode = 3 then
  617.                                 -- RETI
  618.                                 MCycles <= "011";
  619.                                 case to_integer(unsigned(MCycle)) is
  620.                                 when 1 =>
  621.                                         Set_Addr_TO <= aSP;
  622.                                 when 2 =>
  623.                                         IncDec_16 <= "0111";
  624.                                         Set_Addr_To <= aSP;
  625.                                         LDZ <= '1';
  626.                                 when 3 =>
  627.                                         Jump <= '1';
  628.                                         IncDec_16 <= "0111";
  629.                                         I_RETN <= '1';
  630.                                         SetEI <= '1';
  631.                                 when others => null;
  632.                                 end case;
  633.                         elsif Mode < 2 then
  634.                                 -- EXX
  635.                                 ExchangeRS <= '1';
  636.                         end if;
  637.                 when "11100011" =>
  638.                         if Mode /= 3 then
  639.                                 -- EX (SP),HL
  640.                                 MCycles <= "101";
  641.                                 case to_integer(unsigned(MCycle)) is
  642.                                 when 1 =>
  643.                                         Set_Addr_To <= aSP;
  644.                                 when 2 =>
  645.                                         Read_To_Reg <= '1';
  646.                                         Set_BusA_To <= "0101";
  647.                                         Set_BusB_To <= "0101";
  648.                                         Set_Addr_To <= aSP;
  649.                                         LDZ <= '1';
  650.                                 when 3 =>
  651.                                         IncDec_16 <= "0111";
  652.                                         Set_Addr_To <= aSP;
  653.                                         TStates <= "100";
  654.                                         Write <= '1';
  655.                                 when 4 =>
  656.                                         Read_To_Reg <= '1';
  657.                                         Set_BusA_To <= "0100";
  658.                                         Set_BusB_To <= "0100";
  659.                                         Set_Addr_To <= aSP;
  660.                                         LDW <= '1';
  661.                                 when 5 =>
  662.                                         IncDec_16 <= "1111";
  663.                                         TStates <= "101";
  664.                                         Write <= '1';
  665.                                 when others => null;
  666.                                 end case;
  667.                         end if;
  668.  
  669. -- 8 BIT ARITHMETIC AND LOGICAL GROUP
  670.                 when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
  671.                         |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
  672.                         |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
  673.                         |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
  674.                         |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
  675.                         |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
  676.                         |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
  677.                         |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
  678.                         -- ADD A,r
  679.                         -- ADC A,r
  680.                         -- SUB A,r
  681.                         -- SBC A,r
  682.                         -- AND A,r
  683.                         -- OR A,r
  684.                         -- XOR A,r
  685.                         -- CP A,r
  686.                         Set_BusB_To(2 downto 0) <= SSS;
  687.                         Set_BusA_To(2 downto 0) <= "111";
  688.                         Read_To_Reg <= '1';
  689.                         Save_ALU <= '1';
  690.                 when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
  691.                         -- ADD A,(HL)
  692.                         -- ADC A,(HL)
  693.                         -- SUB A,(HL)
  694.                         -- SBC A,(HL)
  695.                         -- AND A,(HL)
  696.                         -- OR A,(HL)
  697.                         -- XOR A,(HL)
  698.                         -- CP A,(HL)
  699.                         MCycles <= "010";
  700.                         case to_integer(unsigned(MCycle)) is
  701.                         when 1 =>
  702.                                 Set_Addr_To <= aXY;
  703.                         when 2 =>
  704.                                 Read_To_Reg <= '1';
  705.                                 Save_ALU <= '1';
  706.                                 Set_BusB_To(2 downto 0) <= SSS;
  707.                                 Set_BusA_To(2 downto 0) <= "111";
  708.                         when others => null;
  709.                         end case;
  710.                 when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
  711.                         -- ADD A,n
  712.                         -- ADC A,n
  713.                         -- SUB A,n
  714.                         -- SBC A,n
  715.                         -- AND A,n
  716.                         -- OR A,n
  717.                         -- XOR A,n
  718.                         -- CP A,n
  719.                         MCycles <= "010";
  720.                         if MCycle = "010" then
  721.                                 Inc_PC <= '1';
  722.                                 Read_To_Reg <= '1';
  723.                                 Save_ALU <= '1';
  724.                                 Set_BusB_To(2 downto 0) <= SSS;
  725.                                 Set_BusA_To(2 downto 0) <= "111";
  726.                         end if;
  727.                 when "00000100"|"00001100"|"00010100"|"00011100"|"00100100"|"00101100"|"00111100" =>
  728.                         -- INC r
  729.                         Set_BusB_To <= "1010";
  730.                         Set_BusA_To(2 downto 0) <= DDD;
  731.                         Read_To_Reg <= '1';
  732.                         Save_ALU <= '1';
  733.                         PreserveC <= '1';
  734.                         ALU_Op <= "0000";
  735.                 when "00110100" =>
  736.                         -- INC (HL)
  737.                         MCycles <= "011";
  738.                         case to_integer(unsigned(MCycle)) is
  739.                         when 1 =>
  740.                                 Set_Addr_To <= aXY;
  741.                         when 2 =>
  742.                                 TStates <= "100";
  743.                                 Set_Addr_To <= aXY;
  744.                                 Read_To_Reg <= '1';
  745.                                 Save_ALU <= '1';
  746.                                 PreserveC <= '1';
  747.                                 ALU_Op <= "0000";
  748.                                 Set_BusB_To <= "1010";
  749.                                 Set_BusA_To(2 downto 0) <= DDD;
  750.                         when 3 =>
  751.                                 Write <= '1';
  752.                         when others => null;
  753.                         end case;
  754.                 when "00000101"|"00001101"|"00010101"|"00011101"|"00100101"|"00101101"|"00111101" =>
  755.                         -- DEC r
  756.                         Set_BusB_To <= "1010";
  757.                         Set_BusA_To(2 downto 0) <= DDD;
  758.                         Read_To_Reg <= '1';
  759.                         Save_ALU <= '1';
  760.                         PreserveC <= '1';
  761.                         ALU_Op <= "0010";
  762.                 when "00110101" =>
  763.                         -- DEC (HL)
  764.                         MCycles <= "011";
  765.                         case to_integer(unsigned(MCycle)) is
  766.                         when 1 =>
  767.                                 Set_Addr_To <= aXY;
  768.                         when 2 =>
  769.                                 TStates <= "100";
  770.                                 Set_Addr_To <= aXY;
  771.                                 ALU_Op <= "0010";
  772.                                 Read_To_Reg <= '1';
  773.                                 Save_ALU <= '1';
  774.                                 PreserveC <= '1';
  775.                                 Set_BusB_To <= "1010";
  776.                                 Set_BusA_To(2 downto 0) <= DDD;
  777.                         when 3 =>
  778.                                 Write <= '1';
  779.                         when others => null;
  780.                         end case;
  781.  
  782. -- GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
  783.                 when "00100111" =>
  784.                         -- DAA
  785.                         Set_BusA_To(2 downto 0) <= "111";
  786.                         Read_To_Reg <= '1';
  787.                         ALU_Op <= "1100";
  788.                         Save_ALU <= '1';
  789.                 when "00101111" =>
  790.                         -- CPL
  791.                         I_CPL <= '1';
  792.                 when "00111111" =>
  793.                         -- CCF
  794.                         I_CCF <= '1';
  795.                 when "00110111" =>
  796.                         -- SCF
  797.                         I_SCF <= '1';
  798.                 when "00000000" =>
  799.                         if NMICycle = '1' then
  800.                                 -- NMI
  801.                                 MCycles <= "011";
  802.                                 case to_integer(unsigned(MCycle)) is
  803.                                 when 1 =>
  804.                                         TStates <= "101";
  805.                                         IncDec_16 <= "1111";
  806.                                         Set_Addr_To <= aSP;
  807.                                         Set_BusB_To <= "1101";
  808.                                 when 2 =>
  809.                                         Write <= '1';
  810.                                         IncDec_16 <= "1111";
  811.                                         Set_Addr_To <= aSP;
  812.                                         Set_BusB_To <= "1100";
  813.                                 when 3 =>
  814.                                         Write <= '1';
  815.                                 when others => null;
  816.                                 end case;
  817.                         elsif IntCycle = '1' then
  818.                                 -- INT (IM 2)
  819.                                 MCycles <= "101";
  820.                                 case to_integer(unsigned(MCycle)) is
  821.                                 when 1 =>
  822.                                         LDZ <= '1';
  823.                                         TStates <= "101";
  824.                                         IncDec_16 <= "1111";
  825.                                         Set_Addr_To <= aSP;
  826.                                         Set_BusB_To <= "1101";
  827.                                 when 2 =>
  828.                                         --TStates <= "100";
  829.                                         Write <= '1';
  830.                                         IncDec_16 <= "1111";
  831.                                         Set_Addr_To <= aSP;
  832.                                         Set_BusB_To <= "1100";
  833.                                 when 3 =>
  834.                                         --TStates <= "100";
  835.                                         Write <= '1';
  836.                                 when 4 =>
  837.                                         Inc_PC <= '1';
  838.                                         LDZ <= '1';
  839.                                 when 5 =>
  840.                                         Jump <= '1';
  841.                                 when others => null;
  842.                                 end case;
  843.                         else
  844.                                 -- NOP
  845.                         end if;
  846.                 when "01110110" =>
  847.                         -- HALT
  848.                         Halt <= '1';
  849.                 when "11110011" =>
  850.                         -- DI
  851.                         SetDI <= '1';
  852.                 when "11111011" =>
  853.                         -- EI
  854.                         SetEI <= '1';
  855.  
  856. -- 16 BIT ARITHMETIC GROUP
  857.                 when "00001001"|"00011001"|"00101001"|"00111001" =>
  858.                         -- ADD HL,ss
  859.                         MCycles <= "011";
  860.                         case to_integer(unsigned(MCycle)) is
  861.                         when 2 =>
  862.                                 NoRead <= '1';
  863.                                 ALU_Op <= "0000";
  864.                                 Read_To_Reg <= '1';
  865.                                 Save_ALU <= '1';
  866.                                 Set_BusA_To(2 downto 0) <= "101";
  867.                                 case to_integer(unsigned(IR(5 downto 4))) is
  868.                                 when 0|1|2 =>
  869.                                         Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  870.                                         Set_BusB_To(0) <= '1';
  871.                                 when others =>
  872.                                         Set_BusB_To <= "1000";
  873.                                 end case;
  874.                                 TStates <= "100";
  875.                                 Arith16 <= '1';
  876.                                 SetWZ <= "11";
  877.                         when 3 =>
  878.                                 NoRead <= '1';
  879.                                 Read_To_Reg <= '1';
  880.                                 Save_ALU <= '1';
  881.                                 ALU_Op <= "0001";
  882.                                 Set_BusA_To(2 downto 0) <= "100";
  883.                                 case to_integer(unsigned(IR(5 downto 4))) is
  884.                                 when 0|1|2 =>
  885.                                         Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  886.                                 when others =>
  887.                                         Set_BusB_To <= "1001";
  888.                                 end case;
  889.                                 Arith16 <= '1';
  890.                         when others =>
  891.                         end case;
  892.                 when "00000011"|"00010011"|"00100011"|"00110011" =>
  893.                         -- INC ss
  894.                         TStates <= "110";
  895.                         IncDec_16(3 downto 2) <= "01";
  896.                         IncDec_16(1 downto 0) <= DPair;
  897.                 when "00001011"|"00011011"|"00101011"|"00111011" =>
  898.                         -- DEC ss
  899.                         TStates <= "110";
  900.                         IncDec_16(3 downto 2) <= "11";
  901.                         IncDec_16(1 downto 0) <= DPair;
  902.  
  903. -- ROTATE AND SHIFT GROUP
  904.                 when "00000111"
  905.                         -- RLCA
  906.                         |"00010111"
  907.                         -- RLA
  908.                         |"00001111"
  909.                         -- RRCA
  910.                         |"00011111" =>
  911.                         -- RRA
  912.                         Set_BusA_To(2 downto 0) <= "111";
  913.                         ALU_Op <= "1000";
  914.                         Read_To_Reg <= '1';
  915.                         Save_ALU <= '1';
  916.  
  917. -- JUMP GROUP
  918.                 when "11000011" =>
  919.                         -- JP nn
  920.                         MCycles <= "011";
  921.                         case to_integer(unsigned(MCycle)) is
  922.                         when 2 =>
  923.                                 Inc_PC <= '1';
  924.                                 LDZ <= '1';
  925.                         when 3 =>
  926.                                 Inc_PC <= '1';
  927.                                 Jump <= '1';
  928.                                 LDW <= '1';
  929.                         when others => null;
  930.                         end case;
  931.                 when "11000010"|"11001010"|"11010010"|"11011010"|"11100010"|"11101010"|"11110010"|"11111010" =>
  932.                         if IR(5) = '1' and Mode = 3 then
  933.                                 case IRB(4 downto 3) is
  934.                                 when "00" =>
  935.                                         -- LD ($FF00+C),A
  936.                                         MCycles <= "010";
  937.                                         case to_integer(unsigned(MCycle)) is
  938.                                         when 1 =>
  939.                                                 Set_Addr_To <= aBC;
  940.                                                 Set_BusB_To     <= "0111";
  941.                                         when 2 =>
  942.                                                 Write <= '1';
  943.                                                 IORQ <= '1';
  944.                                         when others =>
  945.                                         end case;
  946.                                 when "01" =>
  947.                                         -- LD (nn),A
  948.                                         MCycles <= "100";
  949.                                         case to_integer(unsigned(MCycle)) is
  950.                                         when 2 =>
  951.                                                 Inc_PC <= '1';
  952.                                                 LDZ <= '1';
  953.                                         when 3 =>
  954.                                                 Set_Addr_To <= aZI;
  955.                                                 Inc_PC <= '1';
  956.                                                 Set_BusB_To <= "0111";
  957.                                         when 4 =>
  958.                                                 Write <= '1';
  959.                                         when others => null;
  960.                                         end case;
  961.                                 when "10" =>
  962.                                         -- LD A,($FF00+C)
  963.                                         MCycles <= "010";
  964.                                         case to_integer(unsigned(MCycle)) is
  965.                                         when 1 =>
  966.                                                 Set_Addr_To <= aBC;
  967.                                         when 2 =>
  968.                                                 Read_To_Acc <= '1';
  969.                                                 IORQ <= '1';
  970.                                         when others =>
  971.                                         end case;
  972.                                 when "11" =>
  973.                                         -- LD A,(nn)
  974.                                         MCycles <= "100";
  975.                                         case to_integer(unsigned(MCycle)) is
  976.                                         when 2 =>
  977.                                                 Inc_PC <= '1';
  978.                                                 LDZ <= '1';
  979.                                         when 3 =>
  980.                                                 Set_Addr_To <= aZI;
  981.                                                 Inc_PC <= '1';
  982.                                         when 4 =>
  983.                                                 Read_To_Acc <= '1';
  984.                                         when others => null;
  985.                                         end case;
  986.                                 end case;
  987.                         else
  988.                                 -- JP cc,nn
  989.                                 MCycles <= "011";
  990.                                 case to_integer(unsigned(MCycle)) is
  991.                                 when 2 =>
  992.                                         Inc_PC <= '1';
  993.                                         LDZ <= '1';
  994.                                 when 3 =>
  995.                                         LDW <= '1';
  996.                                         Inc_PC <= '1';
  997.                                         if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
  998.                                                 Jump <= '1';
  999.                                         end if;
  1000.                                 when others => null;
  1001.                                 end case;
  1002.                         end if;
  1003.                 when "00011000" =>
  1004.                         if Mode /= 2 then
  1005.                                 -- JR e
  1006.                                 MCycles <= "011";
  1007.                                 case to_integer(unsigned(MCycle)) is
  1008.                                 when 2 =>
  1009.                                         Inc_PC <= '1';
  1010.                                 when 3 =>
  1011.                                         NoRead <= '1';
  1012.                                         JumpE <= '1';
  1013.                                         TStates <= "101";
  1014.                                 when others => null;
  1015.                                 end case;
  1016.                         end if;
  1017.                 when "00111000" =>
  1018.                         if Mode /= 2 then
  1019.                                 -- JR C,e
  1020.                                 MCycles <= "011";
  1021.                                 case to_integer(unsigned(MCycle)) is
  1022.                                 when 2 =>
  1023.                                         Inc_PC <= '1';
  1024.                                         if F(Flag_C) = '0' then
  1025.                                                 MCycles <= "010";
  1026.                                         end if;
  1027.                                 when 3 =>
  1028.                                         NoRead <= '1';
  1029.                                         JumpE <= '1';
  1030.                                         TStates <= "101";
  1031.                                 when others => null;
  1032.                                 end case;
  1033.                         end if;
  1034.                 when "00110000" =>
  1035.                         if Mode /= 2 then
  1036.                                 -- JR NC,e
  1037.                                 MCycles <= "011";
  1038.                                 case to_integer(unsigned(MCycle)) is
  1039.                                 when 2 =>
  1040.                                         Inc_PC <= '1';
  1041.                                         if F(Flag_C) = '1' then
  1042.                                                 MCycles <= "010";
  1043.                                         end if;
  1044.                                 when 3 =>
  1045.                                         NoRead <= '1';
  1046.                                         JumpE <= '1';
  1047.                                         TStates <= "101";
  1048.                                 when others => null;
  1049.                                 end case;
  1050.                         end if;
  1051.                 when "00101000" =>
  1052.                         if Mode /= 2 then
  1053.                                 -- JR Z,e
  1054.                                 MCycles <= "011";
  1055.                                 case to_integer(unsigned(MCycle)) is
  1056.                                 when 2 =>
  1057.                                         Inc_PC <= '1';
  1058.                                         if F(Flag_Z) = '0' then
  1059.                                                 MCycles <= "010";
  1060.                                         end if;
  1061.                                 when 3 =>
  1062.                                         NoRead <= '1';
  1063.                                         JumpE <= '1';
  1064.                                         TStates <= "101";
  1065.                                 when others => null;
  1066.                                 end case;
  1067.                         end if;
  1068.                 when "00100000" =>
  1069.                         if Mode /= 2 then
  1070.                                 -- JR NZ,e
  1071.                                 MCycles <= "011";
  1072.                                 case to_integer(unsigned(MCycle)) is
  1073.                                 when 2 =>
  1074.                                         Inc_PC <= '1';
  1075.                                         if F(Flag_Z) = '1' then
  1076.                                                 MCycles <= "010";
  1077.                                         end if;
  1078.                                 when 3 =>
  1079.                                         NoRead <= '1';
  1080.                                         JumpE <= '1';
  1081.                                         TStates <= "101";
  1082.                                 when others => null;
  1083.                                 end case;
  1084.                         end if;
  1085.                 when "11101001" =>
  1086.                         -- JP (HL)
  1087.                         JumpXY <= '1';
  1088.                 when "00010000" =>
  1089.                         if Mode = 3 then
  1090.                                 I_DJNZ <= '1';
  1091.                         elsif Mode < 2 then
  1092.                                 -- DJNZ,e
  1093.                                 MCycles <= "011";
  1094.                                 case to_integer(unsigned(MCycle)) is
  1095.                                 when 1 =>
  1096.                                         TStates <= "101";
  1097.                                         I_DJNZ <= '1';
  1098.                                         Set_BusB_To <= "1010";
  1099.                                         Set_BusA_To(2 downto 0) <= "000";
  1100.                                         Read_To_Reg <= '1';
  1101.                                         Save_ALU <= '1';
  1102.                                         ALU_Op <= "0010";
  1103.                                 when 2 =>
  1104.                                         I_DJNZ <= '1';
  1105.                                         Inc_PC <= '1';
  1106.                                 when 3 =>
  1107.                                         NoRead <= '1';
  1108.                                         JumpE <= '1';
  1109.                                         TStates <= "101";
  1110.                                 when others => null;
  1111.                                 end case;
  1112.                         end if;
  1113.  
  1114. -- CALL AND RETURN GROUP
  1115.                 when "11001101" =>
  1116.                         -- CALL nn
  1117.                         MCycles <= "101";
  1118.                         case to_integer(unsigned(MCycle)) is
  1119.                         when 2 =>
  1120.                                 Inc_PC <= '1';
  1121.                                 LDZ <= '1';
  1122.                         when 3 =>
  1123.                                 IncDec_16 <= "1111";
  1124.                                 Inc_PC <= '1';
  1125.                                 TStates <= "100";
  1126.                                 Set_Addr_To <= aSP;
  1127.                                 LDW <= '1';
  1128.                                 Set_BusB_To <= "1101";
  1129.                         when 4 =>
  1130.                                 Write <= '1';
  1131.                                 IncDec_16 <= "1111";
  1132.                                 Set_Addr_To <= aSP;
  1133.                                 Set_BusB_To <= "1100";
  1134.                         when 5 =>
  1135.                                 Write <= '1';
  1136.                                 Call <= '1';
  1137.                         when others => null;
  1138.                         end case;
  1139.                 when "11000100"|"11001100"|"11010100"|"11011100"|"11100100"|"11101100"|"11110100"|"11111100" =>
  1140.                         if IR(5) = '0' or Mode /= 3 then
  1141.                                 -- CALL cc,nn
  1142.                                 MCycles <= "101";
  1143.                                 case to_integer(unsigned(MCycle)) is
  1144.                                 when 2 =>
  1145.                                         Inc_PC <= '1';
  1146.                                         LDZ <= '1';
  1147.                                 when 3 =>
  1148.                                         Inc_PC <= '1';
  1149.                                         LDW <= '1';
  1150.                                         if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
  1151.                                                 IncDec_16 <= "1111";
  1152.                                                 Set_Addr_TO <= aSP;
  1153.                                                 TStates <= "100";
  1154.                                                 Set_BusB_To <= "1101";
  1155.                                         else
  1156.                                                 MCycles <= "011";
  1157.                                         end if;
  1158.                                 when 4 =>
  1159.                                         Write <= '1';
  1160.                                         IncDec_16 <= "1111";
  1161.                                         Set_Addr_To <= aSP;
  1162.                                         Set_BusB_To <= "1100";
  1163.                                 when 5 =>
  1164.                                         Write <= '1';
  1165.                                         Call <= '1';
  1166.                                 when others => null;
  1167.                                 end case;
  1168.                         end if;
  1169.                 when "11001001" =>
  1170.                         -- RET
  1171.                         MCycles <= "011";
  1172.                         case to_integer(unsigned(MCycle)) is
  1173.                         when 1 =>
  1174.                                 --TStates <= "101";
  1175.                                 Set_Addr_TO <= aSP;
  1176.                         when 2 =>
  1177.                                 IncDec_16 <= "0111";
  1178.                                 Set_Addr_To <= aSP;
  1179.                                 LDZ <= '1';
  1180.                         when 3 =>
  1181.                                 Jump <= '1';
  1182.                                 IncDec_16 <= "0111";
  1183.                         when others => null;
  1184.                         end case;
  1185.                 when "11000000"|"11001000"|"11010000"|"11011000"|"11100000"|"11101000"|"11110000"|"11111000" =>
  1186.                         if IR(5) = '1' and Mode = 3 then
  1187.                                 case IRB(4 downto 3) is
  1188.                                 when "00" =>
  1189.                                         -- LD ($FF00+nn),A
  1190.                                         MCycles <= "011";
  1191.                                         case to_integer(unsigned(MCycle)) is
  1192.                                         when 2 =>
  1193.                                                 Inc_PC <= '1';
  1194.                                                 Set_Addr_To <= aIOA;
  1195.                                                 Set_BusB_To     <= "0111";
  1196.                                         when 3 =>
  1197.                                                 Write <= '1';
  1198.                                         when others => null;
  1199.                                         end case;
  1200.                                 when "01" =>
  1201.                                         -- ADD SP,n
  1202.                                         MCycles <= "011";
  1203.                                         case to_integer(unsigned(MCycle)) is
  1204.                                         when 2 =>
  1205.                                                 ALU_Op <= "0000";
  1206.                                                 Inc_PC <= '1';
  1207.                                                 Read_To_Reg <= '1';
  1208.                                                 Save_ALU <= '1';
  1209.                                                 Set_BusA_To <= "1000";
  1210.                                                 Set_BusB_To <= "0110";
  1211.                                         when 3 =>
  1212.                                                 NoRead <= '1';
  1213.                                                 Read_To_Reg <= '1';
  1214.                                                 Save_ALU <= '1';
  1215.                                                 ALU_Op <= "0001";
  1216.                                                 Set_BusA_To <= "1001";
  1217.                                                 Set_BusB_To <= "1110";  -- Incorrect unsigned !!!!!!!!!!!!!!!!!!!!!
  1218.                                         when others =>
  1219.                                         end case;
  1220.                                 when "10" =>
  1221.                                         -- LD A,($FF00+nn)
  1222.                                         MCycles <= "011";
  1223.                                         case to_integer(unsigned(MCycle)) is
  1224.                                         when 2 =>
  1225.                                                 Inc_PC <= '1';
  1226.                                                 Set_Addr_To <= aIOA;
  1227.                                         when 3 =>
  1228.                                                 Read_To_Acc <= '1';
  1229.                                         when others => null;
  1230.                                         end case;
  1231.                                 when "11" =>
  1232.                                         -- LD HL,SP+n   -- Not correct !!!!!!!!!!!!!!!!!!!
  1233.                                         MCycles <= "101";
  1234.                                         case to_integer(unsigned(MCycle)) is
  1235.                                         when 2 =>
  1236.                                                 Inc_PC <= '1';
  1237.                                                 LDZ <= '1';
  1238.                                         when 3 =>
  1239.                                                 Set_Addr_To <= aZI;
  1240.                                                 Inc_PC <= '1';
  1241.                                                 LDW <= '1';
  1242.                                         when 4 =>
  1243.                                                 Set_BusA_To(2 downto 0) <= "101"; -- L
  1244.                                                 Read_To_Reg <= '1';
  1245.                                                 Inc_WZ <= '1';
  1246.                                                 Set_Addr_To <= aZI;
  1247.                                         when 5 =>
  1248.                                                 Set_BusA_To(2 downto 0) <= "100"; -- H
  1249.                                                 Read_To_Reg <= '1';
  1250.                                         when others => null;
  1251.                                         end case;
  1252.                                 end case;
  1253.                         else
  1254.                                 -- RET cc
  1255.                                 MCycles <= "011";
  1256.                                 case to_integer(unsigned(MCycle)) is
  1257.                                 when 1 =>
  1258.                                         if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
  1259.                                                 Set_Addr_TO <= aSP;
  1260.                                         else
  1261.                                                 MCycles <= "001";
  1262.                                         end if;
  1263.                                         TStates <= "101";
  1264.                                 when 2 =>
  1265.                                         IncDec_16 <= "0111";
  1266.                                         Set_Addr_To <= aSP;
  1267.                                         LDZ <= '1';
  1268.                                 when 3 =>
  1269.                                         Jump <= '1';
  1270.                                         IncDec_16 <= "0111";
  1271.                                 when others => null;
  1272.                                 end case;
  1273.                         end if;
  1274.                 when "11000111"|"11001111"|"11010111"|"11011111"|"11100111"|"11101111"|"11110111"|"11111111" =>
  1275.                         -- RST p
  1276.                         MCycles <= "011";
  1277.                         case to_integer(unsigned(MCycle)) is
  1278.                         when 1 =>
  1279.                                 TStates <= "101";
  1280.                                 IncDec_16 <= "1111";
  1281.                                 Set_Addr_To <= aSP;
  1282.                                 Set_BusB_To <= "1101";
  1283.                         when 2 =>
  1284.                                 Write <= '1';
  1285.                                 IncDec_16 <= "1111";
  1286.                                 Set_Addr_To <= aSP;
  1287.                                 Set_BusB_To <= "1100";
  1288.                         when 3 =>
  1289.                                 Write <= '1';
  1290.                                 RstP <= '1';
  1291.                         when others => null;
  1292.                         end case;
  1293.  
  1294. -- INPUT AND OUTPUT GROUP
  1295.                 when "11011011" =>
  1296.                         if Mode /= 3 then
  1297.                                 -- IN A,(n)
  1298.                                 MCycles <= "011";
  1299.                                 case to_integer(unsigned(MCycle)) is
  1300.                                 when 2 =>
  1301.                                         Inc_PC <= '1';
  1302.                                         Set_Addr_To <= aIOA;
  1303.                                 when 3 =>
  1304.                                         Read_To_Acc <= '1';
  1305.                                         IORQ <= '1';
  1306.                                 when others => null;
  1307.                                 end case;
  1308.                         end if;
  1309.                 when "11010011" =>
  1310.                         if Mode /= 3 then
  1311.                                 -- OUT (n),A
  1312.                                 MCycles <= "011";
  1313.                                 case to_integer(unsigned(MCycle)) is
  1314.                                 when 2 =>
  1315.                                         Inc_PC <= '1';
  1316.                                         Set_Addr_To <= aIOA;
  1317.                                         Set_BusB_To     <= "0111";
  1318.                                 when 3 =>
  1319.                                         Write <= '1';
  1320.                                         IORQ <= '1';
  1321.                                 when others => null;
  1322.                                 end case;
  1323.                         end if;
  1324.  
  1325. ------------------------------------------------------------------------------
  1326. ------------------------------------------------------------------------------
  1327. -- MULTIBYTE INSTRUCTIONS
  1328. ------------------------------------------------------------------------------
  1329. ------------------------------------------------------------------------------
  1330.  
  1331.                 when "11001011" =>
  1332.                         if Mode /= 2 then
  1333.                                 Prefix <= "01";
  1334.                         end if;
  1335.  
  1336.                 when "11101101" =>
  1337.                         if Mode < 2 then
  1338.                                 Prefix <= "10";
  1339.                         end if;
  1340.  
  1341.                 when "11011101"|"11111101" =>
  1342.                         if Mode < 2 then
  1343.                                 Prefix <= "11";
  1344.                         end if;
  1345.  
  1346.                 end case;
  1347.  
  1348.                 when "01" =>
  1349.  
  1350. ------------------------------------------------------------------------------
  1351. --
  1352. --      CB prefixed instructions
  1353. --
  1354. ------------------------------------------------------------------------------
  1355.  
  1356.                         Set_BusA_To(2 downto 0) <= IR(2 downto 0);
  1357.                         Set_BusB_To(2 downto 0) <= IR(2 downto 0);
  1358.  
  1359.                         case IRB is
  1360.                         when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000111"
  1361.                                 |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010111"
  1362.                                 |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001111"
  1363.                                 |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011111"
  1364.                                 |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100111"
  1365.                                 |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101111"
  1366.                                 |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110111"
  1367.                                 |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111111" =>
  1368.                                 -- RLC r
  1369.                                 -- RL r
  1370.                                 -- RRC r
  1371.                                 -- RR r
  1372.                                 -- SLA r
  1373.                                 -- SRA r
  1374.                                 -- SRL r
  1375.                                 -- SLL r (Undocumented) / SWAP r
  1376.                                 if XY_State="00" then
  1377.                                         if MCycle = "001" then
  1378.                                           ALU_Op <= "1000";
  1379.                                           Read_To_Reg <= '1';
  1380.                                           Save_ALU <= '1';
  1381.                                         end if;
  1382.                                 else
  1383.                                 -- R/S (IX+d),Reg, undocumented
  1384.                                         MCycles <= "011";
  1385.                                         XYbit_undoc <= '1';
  1386.                                         case to_integer(unsigned(MCycle)) is
  1387.                                         when 1 | 7=>
  1388.                                                 Set_Addr_To <= aXY;
  1389.                                         when 2 =>
  1390.                                                 ALU_Op <= "1000";
  1391.                                                 Read_To_Reg <= '1';
  1392.                                                 Save_ALU <= '1';
  1393.                                                 Set_Addr_To <= aXY;
  1394.                                                 TStates <= "100";
  1395.                                         when 3 =>
  1396.                                                 Write <= '1';
  1397.                                         when others => null;
  1398.                                         end case;
  1399.                                 end if;
  1400.  
  1401.                         when "00000110"|"00010110"|"00001110"|"00011110"|"00101110"|"00111110"|"00100110"|"00110110" =>
  1402.                                 -- RLC (HL)
  1403.                                 -- RL (HL)
  1404.                                 -- RRC (HL)
  1405.                                 -- RR (HL)
  1406.                                 -- SRA (HL)
  1407.                                 -- SRL (HL)
  1408.                                 -- SLA (HL)
  1409.                                 -- SLL (HL) (Undocumented) / SWAP (HL)
  1410.                                 MCycles <= "011";
  1411.                                 case to_integer(unsigned(MCycle)) is
  1412.                                 when 1 | 7 =>
  1413.                                         Set_Addr_To <= aXY;
  1414.                                 when 2 =>
  1415.                                         ALU_Op <= "1000";
  1416.                                         Read_To_Reg <= '1';
  1417.                                         Save_ALU <= '1';
  1418.                                         Set_Addr_To <= aXY;
  1419.                                         TStates <= "100";
  1420.                                 when 3 =>
  1421.                                         Write <= '1';
  1422.                                 when others =>
  1423.                                 end case;
  1424.                         when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
  1425.                                 |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
  1426.                                 |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
  1427.                                 |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
  1428.                                 |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
  1429.                                 |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
  1430.                                 |"01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111"
  1431.                                 |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
  1432.                                 -- BIT b,r
  1433.                                 if XY_State="00" then
  1434.                                         if MCycle = "001" then
  1435.                                           Set_BusB_To(2 downto 0) <= IR(2 downto 0);
  1436.                                           ALU_Op <= "1001";
  1437.                                         end if;
  1438.                                 else
  1439.                                 -- BIT b,(IX+d), undocumented
  1440.                                         MCycles <= "010";
  1441.                                         XYbit_undoc <= '1';
  1442.                                         case to_integer(unsigned(MCycle)) is
  1443.                                         when 1 | 7=>
  1444.                                                 Set_Addr_To <= aXY;
  1445.                                         when 2 =>
  1446.                                                 ALU_Op <= "1001";
  1447.                                                 TStates <= "100";
  1448.                                         when others => null;
  1449.                                         end case;
  1450.                                 end if;
  1451.  
  1452.                         when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01110110"|"01111110" =>
  1453.                                 -- BIT b,(HL)
  1454.                                 MCycles <= "010";
  1455.                                 case to_integer(unsigned(MCycle)) is
  1456.                                 when 1 | 7 =>
  1457.                                         Set_Addr_To <= aXY;
  1458.                                 when 2 =>
  1459.                                         ALU_Op <= "1001";
  1460.                                         TStates <= "100";
  1461.                                 when others => null;
  1462.                                 end case;
  1463.                         when "11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000111"
  1464.                                 |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001111"
  1465.                                 |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010111"
  1466.                                 |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011111"
  1467.                                 |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100111"
  1468.                                 |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101111"
  1469.                                 |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110111"
  1470.                                 |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111111" =>
  1471.                                 -- SET b,r
  1472.                                 if XY_State="00" then
  1473.                                         if MCycle = "001" then
  1474.                                                 ALU_Op <= "1010";
  1475.                                                 Read_To_Reg <= '1';
  1476.                                                 Save_ALU <= '1';
  1477.                                         end if;
  1478.                                 else
  1479.                                 -- SET b,(IX+d),Reg, undocumented
  1480.                                         MCycles <= "011";
  1481.                                         XYbit_undoc <= '1';
  1482.                                         case to_integer(unsigned(MCycle)) is
  1483.                                         when 1 | 7=>
  1484.                                                 Set_Addr_To <= aXY;
  1485.                                         when 2 =>
  1486.                                                 ALU_Op <= "1010";
  1487.                                                 Read_To_Reg <= '1';
  1488.                                                 Save_ALU <= '1';
  1489.                                                 Set_Addr_To <= aXY;
  1490.                                                 TStates <= "100";
  1491.                                         when 3 =>
  1492.                                                 Write <= '1';
  1493.                                         when others => null;
  1494.                                         end case;
  1495.                                 end if;
  1496.  
  1497.                         when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
  1498.                                 -- SET b,(HL)
  1499.                                 MCycles <= "011";
  1500.                                 case to_integer(unsigned(MCycle)) is
  1501.                                 when 1 | 7 =>
  1502.                                         Set_Addr_To <= aXY;
  1503.                                 when 2 =>
  1504.                                         ALU_Op <= "1010";
  1505.                                         Read_To_Reg <= '1';
  1506.                                         Save_ALU <= '1';
  1507.                                         Set_Addr_To <= aXY;
  1508.                                         TStates <= "100";
  1509.                                 when 3 =>
  1510.                                         Write <= '1';
  1511.                                 when others => null;
  1512.                                 end case;
  1513.                         when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
  1514.                                 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
  1515.                                 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
  1516.                                 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
  1517.                                 |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
  1518.                                 |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
  1519.                                 |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
  1520.                                 |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
  1521.                                 -- RES b,r
  1522.                                 if XY_State="00" then
  1523.                                         if MCycle = "001" then
  1524.                                                 ALU_Op <= "1011";
  1525.                                                 Read_To_Reg <= '1';
  1526.                                                 Save_ALU <= '1';
  1527.                                         end if;
  1528.                                 else
  1529.                                 -- RES b,(IX+d),Reg, undocumented
  1530.                                         MCycles <= "011";
  1531.                                         XYbit_undoc <= '1';
  1532.                                         case to_integer(unsigned(MCycle)) is
  1533.                                         when 1 | 7=>
  1534.                                                 Set_Addr_To <= aXY;
  1535.                                         when 2 =>
  1536.                                                 ALU_Op <= "1011";
  1537.                                                 Read_To_Reg <= '1';
  1538.                                                 Save_ALU <= '1';
  1539.                                                 Set_Addr_To <= aXY;
  1540.                                                 TStates <= "100";
  1541.                                         when 3 =>
  1542.                                                 Write <= '1';
  1543.                                         when others => null;
  1544.                                         end case;
  1545.                                 end if;
  1546.  
  1547.                         when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
  1548.                                 -- RES b,(HL)
  1549.                                 MCycles <= "011";
  1550.                                 case to_integer(unsigned(MCycle)) is
  1551.                                 when 1 | 7 =>
  1552.                                         Set_Addr_To <= aXY;
  1553.                                 when 2 =>
  1554.                                         ALU_Op <= "1011";
  1555.                                         Read_To_Reg <= '1';
  1556.                                         Save_ALU <= '1';
  1557.                                         Set_Addr_To <= aXY;
  1558.                                         TStates <= "100";
  1559.                                 when 3 =>
  1560.                                         Write <= '1';
  1561.                                 when others => null;
  1562.                                 end case;
  1563.                         end case;
  1564.  
  1565.                 when others =>
  1566.  
  1567. ------------------------------------------------------------------------------
  1568. --
  1569. --      ED prefixed instructions
  1570. --
  1571. ------------------------------------------------------------------------------
  1572.  
  1573.                         case IRB is
  1574.                         when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000110"|"00000111"
  1575.                                 |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001110"|"00001111"
  1576.                                 |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010110"|"00010111"
  1577.                                 |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011110"|"00011111"
  1578.                                 |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100110"|"00100111"
  1579.                                 |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101110"|"00101111"
  1580.                                 |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110110"|"00110111"
  1581.                                 |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111110"|"00111111"
  1582.  
  1583.  
  1584.                                 |"10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000110"|"10000111"
  1585.                                 |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001110"|"10001111"
  1586.                                 |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010110"|"10010111"
  1587.                                 |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011110"|"10011111"
  1588.                                 |                                            "10100100"|"10100101"|"10100110"|"10100111"
  1589.                                 |                                            "10101100"|"10101101"|"10101110"|"10101111"
  1590.                                 |                                            "10110100"|"10110101"|"10110110"|"10110111"
  1591.                                 |                                            "10111100"|"10111101"|"10111110"|"10111111"
  1592.                                 |"11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000110"|"11000111"
  1593.                                 |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001110"|"11001111"
  1594.                                 |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010110"|"11010111"
  1595.                                 |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011110"|"11011111"
  1596.                                 |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100110"|"11100111"
  1597.                                 |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101110"|"11101111"
  1598.                                 |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110110"|"11110111"
  1599.                                 |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111110"|"11111111" =>
  1600.                                 null; -- NOP, undocumented
  1601.                         when "01111110"|"01111111" =>
  1602.                                 -- NOP, undocumented
  1603.                                 null;
  1604. -- 8 BIT LOAD GROUP
  1605.                         when "01010111" =>
  1606.                                 -- LD A,I
  1607.                                 Special_LD <= "100";
  1608.                                 TStates <= "101";
  1609.                         when "01011111" =>
  1610.                                 -- LD A,R
  1611.                                 Special_LD <= "101";
  1612.                                 TStates <= "101";
  1613.                         when "01000111" =>
  1614.                                 -- LD I,A
  1615.                                 Special_LD <= "110";
  1616.                                 TStates <= "101";
  1617.                         when "01001111" =>
  1618.                                 -- LD R,A
  1619.                                 Special_LD <= "111";
  1620.                                 TStates <= "101";
  1621. -- 16 BIT LOAD GROUP
  1622.                         when "01001011"|"01011011"|"01101011"|"01111011" =>
  1623.                                 -- LD dd,(nn)
  1624.                                 MCycles <= "101";
  1625.                                 case to_integer(unsigned(MCycle)) is
  1626.                                 when 2 =>
  1627.                                         Inc_PC <= '1';
  1628.                                         LDZ <= '1';
  1629.                                 when 3 =>
  1630.                                         Set_Addr_To <= aZI;
  1631.                                         Inc_PC <= '1';
  1632.                                         LDW <= '1';
  1633.                                 when 4 =>
  1634.                                         Read_To_Reg <= '1';
  1635.                                         if IR(5 downto 4) = "11" then
  1636.                                                 Set_BusA_To <= "1000";
  1637.                                         else
  1638.                                                 Set_BusA_To(2 downto 1) <= IR(5 downto 4);
  1639.                                                 Set_BusA_To(0) <= '1';
  1640.                                         end if;
  1641.                                         Inc_WZ <= '1';
  1642.                                         Set_Addr_To <= aZI;
  1643.                                 when 5 =>
  1644.                                         Read_To_Reg <= '1';
  1645.                                         if IR(5 downto 4) = "11" then
  1646.                                                 Set_BusA_To <= "1001";
  1647.                                         else
  1648.                                                 Set_BusA_To(2 downto 1) <= IR(5 downto 4);
  1649.                                                 Set_BusA_To(0) <= '0';
  1650.                                         end if;
  1651.                                 when others => null;
  1652.                                 end case;
  1653.                         when "01000011"|"01010011"|"01100011"|"01110011" =>
  1654.                                 -- LD (nn),dd
  1655.                                 MCycles <= "101";
  1656.                                 case to_integer(unsigned(MCycle)) is
  1657.                                 when 2 =>
  1658.                                         Inc_PC <= '1';
  1659.                                         LDZ <= '1';
  1660.                                 when 3 =>
  1661.                                         Set_Addr_To <= aZI;
  1662.                                         Inc_PC <= '1';
  1663.                                         LDW <= '1';
  1664.                                         if IR(5 downto 4) = "11" then
  1665.                                                 Set_BusB_To <= "1000";
  1666.                                         else
  1667.                                                 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  1668.                                                 Set_BusB_To(0) <= '1';
  1669.                                                 Set_BusB_To(3) <= '0';
  1670.                                         end if;
  1671.                                 when 4 =>
  1672.                                         Inc_WZ <= '1';
  1673.                                         Set_Addr_To <= aZI;
  1674.                                         Write <= '1';
  1675.                                         if IR(5 downto 4) = "11" then
  1676.                                                 Set_BusB_To <= "1001";
  1677.                                         else
  1678.                                                 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  1679.                                                 Set_BusB_To(0) <= '0';
  1680.                                                 Set_BusB_To(3) <= '0';
  1681.                                         end if;
  1682.                                 when 5 =>
  1683.                                         Write <= '1';
  1684.                                 when others => null;
  1685.                                 end case;
  1686.                         when "10100000" | "10101000" | "10110000" | "10111000" =>
  1687.                                 -- LDI, LDD, LDIR, LDDR
  1688.                                 MCycles <= "100";
  1689.                                 case to_integer(unsigned(MCycle)) is
  1690.                                 when 1 =>
  1691.                                         Set_Addr_To <= aXY;
  1692.                                         IncDec_16 <= "1100"; -- BC
  1693.                                 when 2 =>
  1694.                                         Set_BusB_To <= "0110";
  1695.                                         Set_BusA_To(2 downto 0) <= "111";
  1696.                                         ALU_Op <= "0000";
  1697.                                         Set_Addr_To <= aDE;
  1698.                                         if IR(3) = '0' then
  1699.                                                 IncDec_16 <= "0110"; -- IX
  1700.                                         else
  1701.                                                 IncDec_16 <= "1110";
  1702.                                         end if;
  1703.                                 when 3 =>
  1704.                                         I_BT <= '1';
  1705.                                         TStates <= "101";
  1706.                                         Write <= '1';
  1707.                                         if IR(3) = '0' then
  1708.                                                 IncDec_16 <= "0101"; -- DE
  1709.                                         else
  1710.                                                 IncDec_16 <= "1101";
  1711.                                         end if;
  1712.                                 when 4 =>
  1713.                                         NoRead <= '1';
  1714.                                         TStates <= "101";
  1715.                                 when others => null;
  1716.                                 end case;
  1717.                         when "10100001" | "10101001" | "10110001" | "10111001" =>
  1718.                                 -- CPI, CPD, CPIR, CPDR
  1719.                                 MCycles <= "100";
  1720.                                 case to_integer(unsigned(MCycle)) is
  1721.                                 when 1 =>
  1722.                                         Set_Addr_To <= aXY;
  1723.                                         IncDec_16 <= "1100"; -- BC
  1724.                                 when 2 =>
  1725.                                         Set_BusB_To <= "0110";
  1726.                                         Set_BusA_To(2 downto 0) <= "111";
  1727.                                         ALU_Op <= "0111";
  1728.                                         Save_ALU <= '1';
  1729.                                         PreserveC <= '1';
  1730.                                         if IR(3) = '0' then
  1731.                                                 IncDec_16 <= "0110";
  1732.                                         else
  1733.                                                 IncDec_16 <= "1110";
  1734.                                         end if;
  1735.                                 when 3 =>
  1736.                                         NoRead <= '1';
  1737.                                         I_BC <= '1';
  1738.                                         TStates <= "101";
  1739.                                 when 4 =>
  1740.                                         NoRead <= '1';
  1741.                                         TStates <= "101";
  1742.                                 when others => null;
  1743.                                 end case;
  1744.                         when "01000100"|"01001100"|"01010100"|"01011100"|"01100100"|"01101100"|"01110100"|"01111100" =>
  1745.                                 -- NEG
  1746.                                 Alu_OP <= "0010";
  1747.                                 Set_BusB_To <= "0111";
  1748.                                 Set_BusA_To <= "1010";
  1749.                                 Read_To_Acc <= '1';
  1750.                                 Save_ALU <= '1';
  1751.                         when "01000110"|"01001110"|"01100110"|"01101110" =>
  1752.                                 -- IM 0
  1753.                                 IMode <= "00";
  1754.                         when "01010110"|"01110110" =>
  1755.                                 -- IM 1
  1756.                                 IMode <= "01";
  1757.                         when "01011110"|"01110111" =>
  1758.                                 -- IM 2
  1759.                                 IMode <= "10";
  1760. -- 16 bit arithmetic
  1761.                         when "01001010"|"01011010"|"01101010"|"01111010" =>
  1762.                                 -- ADC HL,ss
  1763.                                 MCycles <= "011";
  1764.                                 case to_integer(unsigned(MCycle)) is
  1765.                                 when 2 =>
  1766.                                         NoRead <= '1';
  1767.                                         ALU_Op <= "0001";
  1768.                                         Read_To_Reg <= '1';
  1769.                                         Save_ALU <= '1';
  1770.                                         Set_BusA_To(2 downto 0) <= "101";
  1771.                                         case to_integer(unsigned(IR(5 downto 4))) is
  1772.                                         when 0|1|2 =>
  1773.                                                 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  1774.                                                 Set_BusB_To(0) <= '1';
  1775.                                         when others =>
  1776.                                                 Set_BusB_To <= "1000";
  1777.                                         end case;
  1778.                                         TStates <= "100";
  1779.                                         SetWZ <= "11";
  1780.                                 when 3 =>
  1781.                                         NoRead <= '1';
  1782.                                         Read_To_Reg <= '1';
  1783.                                         Save_ALU <= '1';
  1784.                                         ALU_Op <= "0001";
  1785.                                         Set_BusA_To(2 downto 0) <= "100";
  1786.                                         case to_integer(unsigned(IR(5 downto 4))) is
  1787.                                         when 0|1|2 =>
  1788.                                                 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  1789.                                                 Set_BusB_To(0) <= '0';
  1790.                                         when others =>
  1791.                                                 Set_BusB_To <= "1001";
  1792.                                         end case;
  1793.                                 when others =>
  1794.                                 end case;
  1795.                         when "01000010"|"01010010"|"01100010"|"01110010" =>
  1796.                                 -- SBC HL,ss
  1797.                                 MCycles <= "011";
  1798.                                 case to_integer(unsigned(MCycle)) is
  1799.                                 when 2 =>
  1800.                                         NoRead <= '1';
  1801.                                         ALU_Op <= "0011";
  1802.                                         Read_To_Reg <= '1';
  1803.                                         Save_ALU <= '1';
  1804.                                         Set_BusA_To(2 downto 0) <= "101";
  1805.                                         case to_integer(unsigned(IR(5 downto 4))) is
  1806.                                         when 0|1|2 =>
  1807.                                                 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  1808.                                                 Set_BusB_To(0) <= '1';
  1809.                                         when others =>
  1810.                                                 Set_BusB_To <= "1000";
  1811.                                         end case;
  1812.                                         TStates <= "100";
  1813.                                         SetWZ <= "11";
  1814.                                 when 3 =>
  1815.                                         NoRead <= '1';
  1816.                                         ALU_Op <= "0011";
  1817.                                         Read_To_Reg <= '1';
  1818.                                         Save_ALU <= '1';
  1819.                                         Set_BusA_To(2 downto 0) <= "100";
  1820.                                         case to_integer(unsigned(IR(5 downto 4))) is
  1821.                                         when 0|1|2 =>
  1822.                                                 Set_BusB_To(2 downto 1) <= IR(5 downto 4);
  1823.                                         when others =>
  1824.                                                         Set_BusB_To <= "1001";
  1825.                                         end case;
  1826.                                 when others =>
  1827.                                 end case;
  1828.                         when "01101111" =>
  1829.                                 -- RLD -- Read in M2, not M3! fixed by Sorgelig
  1830.                                 MCycles <= "100";
  1831.                                 case to_integer(unsigned(MCycle)) is
  1832.                                 when 1 =>
  1833.                                         Set_Addr_To <= aXY;
  1834.                                 when 2 =>
  1835.                                         Read_To_Reg <= '1';
  1836.                                         Set_BusB_To(2 downto 0) <= "110";
  1837.                                         Set_BusA_To(2 downto 0) <= "111";
  1838.                                         ALU_Op <= "1101";
  1839.                                         Save_ALU <= '1';
  1840.                                 when 3 =>
  1841.                                         TStates <= "100";
  1842.                                         I_RLD <= '1';
  1843.                                         NoRead <= '1';
  1844.                                         Set_Addr_To <= aXY;
  1845.                                 when 4 =>
  1846.                                         Write <= '1';
  1847.                                 when others =>
  1848.                                 end case;
  1849.                         when "01100111" =>
  1850.                                 -- RRD -- Read in M2, not M3! fixed by Sorgelig
  1851.                                 MCycles <= "100";
  1852.                                 case to_integer(unsigned(MCycle)) is
  1853.                                 when 1 =>
  1854.                                         Set_Addr_To <= aXY;
  1855.                                 when 2 =>
  1856.                                         Read_To_Reg <= '1';
  1857.                                         Set_BusB_To(2 downto 0) <= "110";
  1858.                                         Set_BusA_To(2 downto 0) <= "111";
  1859.                                         ALU_Op <= "1110";
  1860.                                         Save_ALU <= '1';
  1861.                                 when 3 =>
  1862.                                         TStates <= "100";
  1863.                                         I_RRD <= '1';
  1864.                                         NoRead <= '1';
  1865.                                         Set_Addr_To <= aXY;
  1866.                                 when 4 =>
  1867.                                         Write <= '1';
  1868.                                 when others =>
  1869.                                 end case;
  1870.                         when "01000101"|"01001101"|"01010101"|"01011101"|"01100101"|"01101101"|"01110101"|"01111101" =>
  1871.                                 -- RETI/RETN
  1872.                                 MCycles <= "011";
  1873.                                 case to_integer(unsigned(MCycle)) is
  1874.                                 when 1 =>
  1875.                                         Set_Addr_TO <= aSP;
  1876.                                 when 2 =>
  1877.                                         IncDec_16 <= "0111";
  1878.                                         Set_Addr_To <= aSP;
  1879.                                         LDZ <= '1';
  1880.                                 when 3 =>
  1881.                                         Jump <= '1';
  1882.                                         IncDec_16 <= "0111";
  1883.                                         LDW <= '1';
  1884.                                         I_RETN <= '1';
  1885.                                 when others => null;
  1886.                                 end case;
  1887.                         when "01000000"|"01001000"|"01010000"|"01011000"|"01100000"|"01101000"|"01110000"|"01111000" =>
  1888.                                 -- IN r,(C)
  1889.                                 MCycles <= "010";
  1890.                                 case to_integer(unsigned(MCycle)) is
  1891.                                 when 1 =>
  1892.                                         Set_Addr_To <= aBC;
  1893.                                         SetWZ <= "01";
  1894.                                 when 2 =>
  1895.                                         IORQ <= '1';
  1896.                                         if IR(5 downto 3) /= "110" then
  1897.                                                 Read_To_Reg <= '1';
  1898.                                                 Set_BusA_To(2 downto 0) <= IR(5 downto 3);
  1899.                                         end if;
  1900.                                         I_INRC <= '1';
  1901.                                 when others =>
  1902.                                 end case;
  1903.                         when "01000001"|"01001001"|"01010001"|"01011001"|"01100001"|"01101001"|"01110001"|"01111001" =>
  1904.                                 -- OUT (C),r
  1905.                                 -- OUT (C),0
  1906.                                 MCycles <= "010";
  1907.                                 case to_integer(unsigned(MCycle)) is
  1908.                                 when 1 =>
  1909.                                         Set_Addr_To <= aBC;
  1910.                                         SetWZ <= "01";
  1911.                                         Set_BusB_To(2 downto 0) <= IR(5 downto 3);
  1912.                                         if IR(5 downto 3) = "110" then
  1913.                                                 Set_BusB_To(3) <= '1';
  1914.                                         end if;
  1915.                                 when 2 =>
  1916.                                         Write <= '1';
  1917.                                         IORQ <= '1';
  1918.                                 when others =>
  1919.                                 end case;
  1920.                         when "10100010" | "10101010" | "10110010" | "10111010" =>
  1921.                                 -- INI, IND, INIR, INDR
  1922.                                 MCycles <= "100";
  1923.                                 case to_integer(unsigned(MCycle)) is
  1924.                                 when 1 =>
  1925.                                         TStates <= "101";
  1926.                                         Set_Addr_To <= aBC;
  1927.                                         Set_BusB_To <= "1010";
  1928.                                         Set_BusA_To <= "0000";
  1929.                                         Read_To_Reg <= '1';
  1930.                                         Save_ALU <= '1';
  1931.                                         ALU_Op <= "0010";
  1932.                                         SetWZ <= "11";
  1933.                                         IncDec_16(3) <= IR(3);
  1934.                                 when 2 =>
  1935.                                         IORQ <= '1';
  1936.                                         Set_BusB_To <= "0110";
  1937.                                         Set_Addr_To <= aXY;
  1938.                                 when 3 =>
  1939.                                         if IR(3) = '0' then
  1940.                                                 IncDec_16 <= "0110";
  1941.                                         else
  1942.                                                 IncDec_16 <= "1110";
  1943.                                         end if;
  1944.                                         Write <= '1';
  1945.                                         I_BTR <= '1';
  1946.                                 when 4 =>
  1947.                                         NoRead <= '1';
  1948.                                         TStates <= "101";
  1949.                                 when others => null;
  1950.                                 end case;
  1951.                         when "10100011" | "10101011" | "10110011" | "10111011" =>
  1952.                                 -- OUTI, OUTD, OTIR, OTDR
  1953.                                 MCycles <= "100";
  1954.                                 case to_integer(unsigned(MCycle)) is
  1955.                                 when 1 =>
  1956.                                         TStates <= "101";
  1957.                                         Set_Addr_To <= aXY;
  1958.                                         Set_BusB_To <= "1010";
  1959.                                         Set_BusA_To <= "0000";
  1960.                                         Read_To_Reg <= '1';
  1961.                                         Save_ALU <= '1';
  1962.                                         ALU_Op <= "0010";
  1963.                                 when 2 =>
  1964.                                         Set_BusB_To <= "0110";
  1965.                                         Set_Addr_To <= aBC;
  1966.                                         SetWZ <= "11";
  1967.                                         IncDec_16(3) <= IR(3);
  1968.                                 when 3 =>
  1969.                                         if IR(3) = '0' then
  1970.                                                 IncDec_16 <= "0110";
  1971.                                         else
  1972.                                                 IncDec_16 <= "1110";
  1973.                                         end if;
  1974.                                         IORQ <= '1';
  1975.                                         Write <= '1';
  1976.                                         I_BTR <= '1';
  1977.                                 when 4 =>
  1978.                                         NoRead <= '1';
  1979.                                         TStates <= "101";
  1980.                                 when others => null;
  1981.                                 end case;
  1982.                         end case;
  1983.  
  1984.                 end case;
  1985.  
  1986.                 if Mode = 1 then
  1987.                         if MCycle = "001" then
  1988. --                              TStates <= "100";
  1989.                         else
  1990.                                 TStates <= "011";
  1991.                         end if;
  1992.                 end if;
  1993.  
  1994.                 if Mode = 3 then
  1995.                         if MCycle = "001" then
  1996. --                              TStates <= "100";
  1997.                         else
  1998.                                 TStates <= "100";
  1999.                         end if;
  2000.                 end if;
  2001.  
  2002.                 if Mode < 2 then
  2003.                         if MCycle = "110" then
  2004.                                 Inc_PC <= '1';
  2005.                                 if Mode = 1 then
  2006.                                         Set_Addr_To <= aXY;
  2007.                                         TStates <= "100";
  2008.                                         Set_BusB_To(2 downto 0) <= SSS;
  2009.                                         Set_BusB_To(3) <= '0';
  2010.                                 end if;
  2011.                                 if IRB = "00110110" or IRB = "11001011" then
  2012.                                         Set_Addr_To <= aNone;
  2013.                                 end if;
  2014.                         end if;
  2015.                         if MCycle = "111" then
  2016.                                 if Mode = 0 then
  2017.                                         TStates <= "101";
  2018.                                 end if;
  2019.                                 if ISet /= "01" then
  2020.                                         Set_Addr_To <= aXY;
  2021.                                 end if;
  2022.                                 Set_BusB_To(2 downto 0) <= SSS;
  2023.                                 Set_BusB_To(3) <= '0';
  2024.                                 if IRB = "00110110" or ISet = "01" then
  2025.                                         -- LD (HL),n
  2026.                                         Inc_PC <= '1';
  2027.                                 else
  2028.                                         NoRead <= '1';
  2029.                                 end if;
  2030.                         end if;
  2031.                 end if;
  2032.  
  2033.         end process;
  2034.  
  2035. end;
  2036.