2 -- T80(b) core. In an effort to merge and maintain bug fixes ....
5 -- Ver 300 started tidyup. Rmoved some auto_wait bits from 0247 which caused problems
8 -- Latest version from www.fpgaarcade.com (original www.opencores.org)
12 -- Z80 compatible microprocessor core
16 -- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
18 -- All rights reserved
20 -- Redistribution and use in source and synthezised forms, with or without
21 -- modification, are permitted provided that the following conditions are met:
23 -- Redistributions of source code must retain the above copyright notice,
24 -- this list of conditions and the following disclaimer.
26 -- Redistributions in synthesized form must reproduce the above copyright
27 -- notice, this list of conditions and the following disclaimer in the
28 -- documentation and/or other materials provided with the distribution.
30 -- Neither the name of the author nor the names of other contributors may
31 -- be used to endorse or promote products derived from this software without
32 -- specific prior written permission.
34 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
36 -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37 -- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
38 -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39 -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40 -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41 -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42 -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 -- POSSIBILITY OF SUCH DAMAGE.
46 -- Please report bugs to the author, but before you do so, please
47 -- make sure that this is not a derivative work and that
48 -- you have the latest version of this file.
50 -- The latest version of this file can be found at:
51 -- http://www.opencores.org/cvsweb.shtml/t80/
57 -- 0208 : First complete release
59 -- 0210 : Fixed wait and halt
61 -- 0211 : Fixed Refresh addition and IM 1
63 -- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
65 -- 0232 : Removed refresh address output for Mode > 1 and added DJNZ M1_n fix by Mike Johnson
67 -- 0235 : Added clock enable and IM 2 fix by Mike Johnson
69 -- 0237 : Changed 8080 I/O address output, added IntE output
71 -- 0238 : Fixed (IX/IY+d) timing and 16 bit ADC and SBC zero flag
73 -- 0240 : Added interrupt ack fix by Mike Johnson, changed (IX/IY+d) timing and changed flags in GB mode
75 -- 0242 : Added I/O wait, fixed refresh address, moved some registers to RAM
77 -- 0247 : Fixed bus req/ack cycle
81 use IEEE.std_logic_1164.all;
82 use IEEE.numeric_std.all;
83 use work.T80_Pack.all;
87 Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
88 IOWait : integer := 0; -- 1 => Single cycle I/O, 1 => Std I/O cycle
89 Flag_C : integer := 0;
90 Flag_N : integer := 1;
91 Flag_P : integer := 2;
92 Flag_X : integer := 3;
93 Flag_H : integer := 4;
94 Flag_Y : integer := 5;
95 Flag_Z : integer := 6;
99 RESET_n : in std_logic;
100 CLK_n : in std_logic;
102 WAIT_n : in std_logic;
103 INT_n : in std_logic;
104 NMI_n : in std_logic;
105 BUSRQ_n : in std_logic;
106 M1_n : out std_logic;
107 IORQ : out std_logic;
108 NoRead : out std_logic;
109 Write : out std_logic;
110 RFSH_n : out std_logic;
111 HALT_n : out std_logic;
112 BUSAK_n : out std_logic;
113 A : out std_logic_vector(15 downto 0);
114 DInst : in std_logic_vector(7 downto 0);
115 DI : in std_logic_vector(7 downto 0);
116 DO : out std_logic_vector(7 downto 0);
117 MC : out std_logic_vector(2 downto 0);
118 TS : out std_logic_vector(2 downto 0);
119 IntCycle_n : out std_logic;
120 IntE : out std_logic;
125 architecture rtl of T80 is
127 constant aNone : std_logic_vector(2 downto 0) := "111";
128 constant aBC : std_logic_vector(2 downto 0) := "000";
129 constant aDE : std_logic_vector(2 downto 0) := "001";
130 constant aXY : std_logic_vector(2 downto 0) := "010";
131 constant aIOA : std_logic_vector(2 downto 0) := "100";
132 constant aSP : std_logic_vector(2 downto 0) := "101";
133 constant aZI : std_logic_vector(2 downto 0) := "110";
136 signal ACC, F : std_logic_vector(7 downto 0);
137 signal Ap, Fp : std_logic_vector(7 downto 0);
138 signal I : std_logic_vector(7 downto 0);
139 signal R : unsigned(7 downto 0);
140 signal SP, PC : unsigned(15 downto 0);
142 signal RegDIH : std_logic_vector(7 downto 0);
143 signal RegDIL : std_logic_vector(7 downto 0);
144 signal RegBusA : std_logic_vector(15 downto 0);
145 signal RegBusB : std_logic_vector(15 downto 0);
146 signal RegBusC : std_logic_vector(15 downto 0);
147 signal RegAddrA_r : std_logic_vector(2 downto 0);
148 signal RegAddrA : std_logic_vector(2 downto 0);
149 signal RegAddrB_r : std_logic_vector(2 downto 0);
150 signal RegAddrB : std_logic_vector(2 downto 0);
151 signal RegAddrC : std_logic_vector(2 downto 0);
152 signal RegWEH : std_logic;
153 signal RegWEL : std_logic;
154 signal Alternate : std_logic;
157 signal TmpAddr : std_logic_vector(15 downto 0); -- Temporary address register
158 signal IR : std_logic_vector(7 downto 0); -- Instruction register
159 signal ISet : std_logic_vector(1 downto 0); -- Instruction set selector
160 signal RegBusA_r : std_logic_vector(15 downto 0);
162 signal ID16 : signed(15 downto 0);
163 signal Save_Mux : std_logic_vector(7 downto 0);
165 signal TState : unsigned(2 downto 0);
166 signal MCycle : std_logic_vector(2 downto 0);
167 signal IntE_FF1 : std_logic;
168 signal IntE_FF2 : std_logic;
169 signal Halt_FF : std_logic;
170 signal BusReq_s : std_logic;
171 signal BusAck : std_logic;
172 signal ClkEn : std_logic;
173 signal NMI_s : std_logic;
174 signal INT_s : std_logic;
175 signal IStatus : std_logic_vector(1 downto 0);
177 signal DI_Reg : std_logic_vector(7 downto 0);
178 signal T_Res : std_logic;
179 signal XY_State : std_logic_vector(1 downto 0);
180 signal Pre_XY_F_M : std_logic_vector(2 downto 0);
181 signal NextIs_XY_Fetch : std_logic;
182 signal XY_Ind : std_logic;
183 signal No_BTR : std_logic;
184 signal BTR_r : std_logic;
185 signal Auto_Wait : std_logic;
186 signal Auto_Wait_t1 : std_logic;
187 signal Auto_Wait_t2 : std_logic;
188 signal IncDecZ : std_logic;
191 signal BusB : std_logic_vector(7 downto 0);
192 signal BusA : std_logic_vector(7 downto 0);
193 signal ALU_Q : std_logic_vector(7 downto 0);
194 signal F_Out : std_logic_vector(7 downto 0);
196 -- Registered micro code outputs
197 signal Read_To_Reg_r : std_logic_vector(4 downto 0);
198 signal Arith16_r : std_logic;
199 signal Z16_r : std_logic;
200 signal ALU_Op_r : std_logic_vector(3 downto 0);
201 signal Save_ALU_r : std_logic;
202 signal PreserveC_r : std_logic;
203 signal MCycles : std_logic_vector(2 downto 0);
205 -- Micro code outputs
206 signal MCycles_d : std_logic_vector(2 downto 0);
207 signal TStates : std_logic_vector(2 downto 0);
208 signal IntCycle : std_logic;
209 signal NMICycle : std_logic;
210 signal Inc_PC : std_logic;
211 signal Inc_WZ : std_logic;
212 signal IncDec_16 : std_logic_vector(3 downto 0);
213 signal Prefix : std_logic_vector(1 downto 0);
214 signal Read_To_Acc : std_logic;
215 signal Read_To_Reg : std_logic;
216 signal Set_BusB_To : std_logic_vector(3 downto 0);
217 signal Set_BusA_To : std_logic_vector(3 downto 0);
218 signal ALU_Op : std_logic_vector(3 downto 0);
219 signal Save_ALU : std_logic;
220 signal PreserveC : std_logic;
221 signal Arith16 : std_logic;
222 signal Set_Addr_To : std_logic_vector(2 downto 0);
223 signal Jump : std_logic;
224 signal JumpE : std_logic;
225 signal JumpXY : std_logic;
226 signal Call : std_logic;
227 signal RstP : std_logic;
228 signal LDZ : std_logic;
229 signal LDW : std_logic;
230 signal LDSPHL : std_logic;
231 signal IORQ_i : std_logic;
232 signal Special_LD : std_logic_vector(2 downto 0);
233 signal ExchangeDH : std_logic;
234 signal ExchangeRp : std_logic;
235 signal ExchangeAF : std_logic;
236 signal ExchangeRS : std_logic;
237 signal I_DJNZ : std_logic;
238 signal I_CPL : std_logic;
239 signal I_CCF : std_logic;
240 signal I_SCF : std_logic;
241 signal I_RETN : std_logic;
242 signal I_BT : std_logic;
243 signal I_BC : std_logic;
244 signal I_BTR : std_logic;
245 signal I_RLD : std_logic;
246 signal I_RRD : std_logic;
247 signal I_INRC : std_logic;
248 signal SetDI : std_logic;
249 signal SetEI : std_logic;
250 signal IMode : std_logic_vector(1 downto 0);
251 signal Halt : std_logic;
271 NMICycle => NMICycle,
272 IntCycle => IntCycle,
273 MCycles => MCycles_d,
278 IncDec_16 => IncDec_16,
279 Read_To_Acc => Read_To_Acc,
280 Read_To_Reg => Read_To_Reg,
281 Set_BusB_To => Set_BusB_To,
282 Set_BusA_To => Set_BusA_To,
284 Save_ALU => Save_ALU,
285 PreserveC => PreserveC,
287 Set_Addr_To => Set_Addr_To,
297 Special_LD => Special_LD,
298 ExchangeDH => ExchangeDH,
299 ExchangeRp => ExchangeRp,
300 ExchangeAF => ExchangeAF,
301 ExchangeRS => ExchangeRS,
332 Arith16 => Arith16_r,
335 IR => IR(5 downto 0),
343 ClkEn <= CEN and not BusAck;
345 T_Res <= '1' when TState = unsigned(TStates) else '0';
347 NextIs_XY_Fetch <= '1' when XY_State /= "00" and XY_Ind = '0' and
348 ((Set_Addr_To = aXY) or
349 (MCycle = "001" and IR = "11001011") or
350 (MCycle = "001" and IR = "00110110")) else '0';
352 Save_Mux <= BusB when ExchangeRp = '1' else
353 DI_Reg when Save_ALU_r = '0' else
356 process (RESET_n, CLK_n)
358 if RESET_n = '0' then
359 PC <= (others => '0'); -- Program Counter
360 A <= (others => '0');
361 TmpAddr <= (others => '0');
369 ACC <= (others => '1');
370 F <= (others => '1');
371 Ap <= (others => '1');
372 Fp <= (others => '1');
373 I <= (others => '0');
374 R <= (others => '0');
375 SP <= (others => '1');
378 Read_To_Reg_r <= "00000";
379 F <= (others => '1');
388 elsif CLK_n'event and CLK_n = '1' then
394 Read_To_Reg_r <= "00000";
396 MCycles <= MCycles_d;
398 if IMode /= "11" then
402 Arith16_r <= Arith16;
403 PreserveC_r <= PreserveC;
404 if ISet = "10" and ALU_OP(2) = '0' and ALU_OP(0) = '1' and MCycle = "011" then
410 if MCycle = "001" and TState(2) = '0' then
411 -- MCycle = 1 and TState = 1, 2, or 3
413 if TState = 2 and Wait_n = '1' then
415 A(7 downto 0) <= std_logic_vector(R);
417 R(6 downto 0) <= R(6 downto 0) + 1;
420 if Jump = '0' and Call = '0' and NMICycle = '0' and IntCycle = '0' and not (Halt_FF = '1' or Halt = '1') then
424 if IntCycle = '1' and IStatus = "01" then
426 elsif Halt_FF = '1' or (IntCycle = '1' and IStatus = "10") or NMICycle = '1' then
433 if Prefix /= "00" then
434 if Prefix = "11" then
441 if Prefix = "10" then
454 -- either (MCycle > 1) OR (MCycle = 1 AND TState > 3)
456 if MCycle = "110" then
458 if Prefix = "01" then
464 BTR_r <= (I_BT or I_BC or I_BTR) and not No_BTR;
466 A(15 downto 8) <= DI_Reg;
467 A(7 downto 0) <= TmpAddr(7 downto 0);
468 PC(15 downto 8) <= unsigned(DI_Reg);
469 PC(7 downto 0) <= unsigned(TmpAddr(7 downto 0));
470 elsif JumpXY = '1' then
472 PC <= unsigned(RegBusC);
473 elsif Call = '1' or RstP = '1' then
475 PC <= unsigned(TmpAddr);
476 elsif MCycle = MCycles and NMICycle = '1' then
477 A <= "0000000001100110";
478 PC <= "0000000001100110";
479 elsif MCycle = "011" and IntCycle = '1' and IStatus = "10" then
481 A(7 downto 0) <= TmpAddr(7 downto 0);
482 PC(15 downto 8) <= unsigned(I);
483 PC(7 downto 0) <= unsigned(TmpAddr(7 downto 0));
487 if XY_State = "00" then
490 if NextIs_XY_Fetch = '1' then
491 A <= std_logic_vector(PC);
498 -- Memory map I/O on GBZ80
499 A(15 downto 8) <= (others => '1');
501 -- Duplicate I/O address on 8080
502 A(15 downto 8) <= DI_Reg;
504 A(15 downto 8) <= ACC;
506 A(7 downto 0) <= DI_Reg;
508 A <= std_logic_vector(SP);
510 if Mode = 3 and IORQ_i = '1' then
511 -- Memory map I/O on GBZ80
512 A(15 downto 8) <= (others => '1');
513 A(7 downto 0) <= RegBusC(7 downto 0);
521 A <= std_logic_vector(unsigned(TmpAddr) + 1);
523 A(15 downto 8) <= DI_Reg;
524 A(7 downto 0) <= TmpAddr(7 downto 0);
527 A <= std_logic_vector(PC);
531 Save_ALU_r <= Save_ALU;
537 F(Flag_Y) <= not ACC(5);
539 F(Flag_X) <= not ACC(3);
544 F(Flag_C) <= not F(Flag_C);
546 F(Flag_H) <= F(Flag_C);
560 if TState = 2 and Wait_n = '1' then
561 if ISet = "01" and MCycle = "111" then
565 PC <= unsigned(signed(PC) + signed(DI_Reg));
566 elsif Inc_PC = '1' then
573 TmpAddr <= (others =>'0');
574 TmpAddr(5 downto 3) <= IR(5 downto 3);
577 if TState = 3 and MCycle = "110" then
578 TmpAddr <= std_logic_vector(signed(RegBusC) + signed(DI_Reg));
581 if (TState = 2 and Wait_n = '1') or (TState = 4 and MCycle = "001") then
582 if IncDec_16(2 downto 0) = "111" then
583 if IncDec_16(3) = '1' then
592 SP <= unsigned(RegBusC);
594 if ExchangeAF = '1' then
600 if ExchangeRS = '1' then
601 Alternate <= not Alternate;
607 TmpAddr(7 downto 0) <= DI_Reg;
610 TmpAddr(15 downto 8) <= DI_Reg;
613 if Special_LD(2) = '1' then
614 case Special_LD(1 downto 0) is
617 F(Flag_P) <= IntE_FF2;
619 ACC <= std_logic_vector(R);
620 F(Flag_P) <= IntE_FF2;
629 if (I_DJNZ = '0' and Save_ALU_r = '1') or ALU_Op_r = "1001" then
634 if PreserveC_r = '0' then
638 F(7 downto 1) <= F_Out(7 downto 1);
639 if PreserveC_r = '0' then
640 F(Flag_C) <= F_Out(0);
644 if T_Res = '1' and I_INRC = '1' then
647 if DI_Reg(7 downto 0) = "00000000" then
652 F(Flag_S) <= DI_Reg(7);
653 F(Flag_P) <= not (DI_Reg(0) xor DI_Reg(1) xor DI_Reg(2) xor DI_Reg(3) xor
654 DI_Reg(4) xor DI_Reg(5) xor DI_Reg(6) xor DI_Reg(7));
660 DO(3 downto 0) <= BusA(3 downto 0);
661 DO(7 downto 4) <= BusB(3 downto 0);
664 DO(3 downto 0) <= BusB(7 downto 4);
665 DO(7 downto 4) <= BusA(3 downto 0);
670 Read_To_Reg_r(3 downto 0) <= Set_BusA_To;
671 Read_To_Reg_r(4) <= Read_To_Reg;
672 if Read_To_Acc = '1' then
673 Read_To_Reg_r(3 downto 0) <= "0111";
674 Read_To_Reg_r(4) <= '1';
678 if TState = 1 and I_BT = '1' then
679 F(Flag_X) <= ALU_Q(3);
680 F(Flag_Y) <= ALU_Q(1);
684 if I_BC = '1' or I_BT = '1' then
685 F(Flag_P) <= IncDecZ;
688 if (TState = 1 and Save_ALU_r = '0') or
689 (Save_ALU_r = '1' and ALU_OP_r /= "0111") then
690 case Read_To_Reg_r is
696 SP(7 downto 0) <= unsigned(Save_Mux);
698 SP(15 downto 8) <= unsigned(Save_Mux);
711 ---------------------------------------------------------------------------
713 -- BC('), DE('), HL('), IX and IY
715 ---------------------------------------------------------------------------
718 if CLK_n'event and CLK_n = '1' then
721 RegAddrA_r <= Alternate & Set_BusA_To(2 downto 1);
722 if XY_Ind = '0' and XY_State /= "00" and Set_BusA_To(2 downto 1) = "10" then
723 RegAddrA_r <= XY_State(1) & "11";
727 RegAddrB_r <= Alternate & Set_BusB_To(2 downto 1);
728 if XY_Ind = '0' and XY_State /= "00" and Set_BusB_To(2 downto 1) = "10" then
729 RegAddrB_r <= XY_State(1) & "11";
732 -- Address from register
733 RegAddrC <= Alternate & Set_Addr_To(1 downto 0);
734 -- Jump (HL), LD SP,HL
735 if (JumpXY = '1' or LDSPHL = '1') then
736 RegAddrC <= Alternate & "10";
738 if ((JumpXY = '1' or LDSPHL = '1') and XY_State /= "00") or (MCycle = "110") then
739 RegAddrC <= XY_State(1) & "11";
742 if I_DJNZ = '1' and Save_ALU_r = '1' and Mode < 2 then
743 IncDecZ <= F_Out(Flag_Z);
745 if (TState = 2 or (TState = 3 and MCycle = "001")) and IncDec_16(2 downto 0) = "100" then
753 RegBusA_r <= RegBusA;
759 -- 16 bit increment/decrement
760 Alternate & IncDec_16(1 downto 0) when (TState = 2 or
761 (TState = 3 and MCycle = "001" and IncDec_16(2) = '1')) and XY_State = "00" else
762 XY_State(1) & "11" when (TState = 2 or
763 (TState = 3 and MCycle = "001" and IncDec_16(2) = '1')) and IncDec_16(1 downto 0) = "10" else
765 Alternate & "10" when ExchangeDH = '1' and TState = 3 else
766 Alternate & "01" when ExchangeDH = '1' and TState = 4 else
772 Alternate & "01" when ExchangeDH = '1' and TState = 3 else
776 ID16 <= signed(RegBusA) - 1 when IncDec_16(3) = '1' else
779 process (Save_ALU_r, Auto_Wait_t1, ALU_OP_r, Read_To_Reg_r,
780 ExchangeDH, IncDec_16, MCycle, TState, Wait_n)
784 if (TState = 1 and Save_ALU_r = '0') or
785 (Save_ALU_r = '1' and ALU_OP_r /= "0111") then
786 case Read_To_Reg_r is
787 when "10000" | "10001" | "10010" | "10011" | "10100" | "10101" =>
788 RegWEH <= not Read_To_Reg_r(0);
789 RegWEL <= Read_To_Reg_r(0);
794 if ExchangeDH = '1' and (TState = 3 or TState = 4) then
799 if IncDec_16(2) = '1' and ((TState = 2 and Wait_n = '1' and MCycle /= "001") or (TState = 3 and MCycle = "001")) then
800 case IncDec_16(1 downto 0) is
801 when "00" | "01" | "10" =>
809 process (Save_Mux, RegBusB, RegBusA_r, ID16,
810 ExchangeDH, IncDec_16, MCycle, TState, Wait_n)
815 if ExchangeDH = '1' and TState = 3 then
816 RegDIH <= RegBusB(15 downto 8);
817 RegDIL <= RegBusB(7 downto 0);
819 if ExchangeDH = '1' and TState = 4 then
820 RegDIH <= RegBusA_r(15 downto 8);
821 RegDIL <= RegBusA_r(7 downto 0);
824 if IncDec_16(2) = '1' and ((TState = 2 and MCycle /= "001") or (TState = 3 and MCycle = "001")) then
825 RegDIH <= std_logic_vector(ID16(15 downto 8));
826 RegDIL <= std_logic_vector(ID16(7 downto 0));
841 DOAH => RegBusA(15 downto 8),
842 DOAL => RegBusA(7 downto 0),
843 DOBH => RegBusB(15 downto 8),
844 DOBL => RegBusB(7 downto 0),
845 DOCH => RegBusC(15 downto 8),
846 DOCL => RegBusC(7 downto 0));
848 ---------------------------------------------------------------------------
852 ---------------------------------------------------------------------------
855 if CLK_n'event and CLK_n = '1' then
860 when "0000" | "0001" | "0010" | "0011" | "0100" | "0101" =>
861 if Set_BusB_To(0) = '1' then
862 BusB <= RegBusB(7 downto 0);
864 BusB <= RegBusB(15 downto 8);
869 BusB <= std_logic_vector(SP(7 downto 0));
871 BusB <= std_logic_vector(SP(15 downto 8));
877 BusB <= std_logic_vector(PC(7 downto 0));
879 BusB <= std_logic_vector(PC(15 downto 8));
889 when "0000" | "0001" | "0010" | "0011" | "0100" | "0101" =>
890 if Set_BusA_To(0) = '1' then
891 BusA <= RegBusA(7 downto 0);
893 BusA <= RegBusA(15 downto 8);
898 BusA <= std_logic_vector(SP(7 downto 0));
900 BusA <= std_logic_vector(SP(15 downto 8));
910 ---------------------------------------------------------------------------
912 -- Generate external control signals
914 ---------------------------------------------------------------------------
915 process (RESET_n,CLK_n)
917 if RESET_n = '0' then
919 elsif CLK_n'event and CLK_n = '1' then
921 if MCycle = "001" and ((TState = 2 and Wait_n = '1') or TState = 3) then
930 MC <= std_logic_vector(MCycle);
931 TS <= std_logic_vector(TState);
933 HALT_n <= not Halt_FF;
934 BUSAK_n <= not BusAck;
935 IntCycle_n <= not IntCycle;
940 -------------------------------------------------------------------------
944 -------------------------------------------------------------------------
945 process (RESET_n, CLK_n)
946 variable OldNMI_n : std_logic;
948 if RESET_n = '0' then
953 elsif CLK_n'event and CLK_n = '1' then
955 BusReq_s <= not BUSRQ_n;
957 if NMICycle = '1' then
959 elsif NMI_n = '0' and OldNMI_n = '1' then
967 -------------------------------------------------------------------------
969 -- Main state machine
971 -------------------------------------------------------------------------
972 process (RESET_n, CLK_n)
974 if RESET_n = '0' then
988 elsif CLK_n'event and CLK_n = '1' then
990 Auto_Wait_t1 <= Auto_Wait;
991 Auto_Wait_t2 <= Auto_Wait_t1;
992 No_BTR <= (I_BT and (not IR(4) or not F(Flag_P))) or
993 (I_BC and (not IR(4) or F(Flag_Z) or not F(Flag_P))) or
994 (I_BTR and (not IR(4) or F(Flag_Z)));
1000 if I_RETN = '1' then
1001 IntE_FF1 <= IntE_FF2;
1010 if IntCycle = '1' or NMICycle = '1' then
1013 if MCycle = "001" and TState = 2 and Wait_n = '1' then
1016 if BusReq_s = '1' and BusAck = '1' then
1019 if TState = 2 and Wait_n = '0' then
1020 elsif T_Res = '1' then
1024 if BusReq_s = '1' then
1028 if NextIs_XY_Fetch = '1' then
1030 Pre_XY_F_M <= MCycle;
1031 if IR = "00110110" and Mode = 0 then
1032 Pre_XY_F_M <= "010";
1034 elsif (MCycle = "111") or
1035 (MCycle = "110" and Mode = 1 and ISet /= "01") then
1036 MCycle <= std_logic_vector(unsigned(Pre_XY_F_M) + 1);
1037 elsif (MCycle = MCycles) or
1039 (MCycle = "010" and I_DJNZ = '1' and IncDecZ = '1') then
1044 if NMI_s = '1' and Prefix = "00" then
1047 elsif (IntE_FF1 = '1' and INT_s = '1') and Prefix = "00" and SetEI = '0' then
1053 MCycle <= std_logic_vector(unsigned(MCycle) + 1);
1057 if Auto_Wait = '1' nand Auto_Wait_t2 = '0' then
1059 TState <= TState + 1;
1070 process (IntCycle, NMICycle, MCycle)
1073 if IntCycle = '1' or NMICycle = '1' then
1074 if MCycle = "001" then