OpenCores
URL https://opencores.org/ocsvn/zx_ula/zx_ula/trunk

Subversion Repositories zx_ula

[/] [zx_ula/] [branches/] [xilinx/] [spectrum_48k_spartan3a_for_gameduino_mod_vga_timex_hicolor_ulaplus/] [T80_MCode.vhd] - Blame information for rev 29

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.