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

Subversion Repositories t80

[/] [t80/] [trunk/] [rtl/] [vhdl/] [T80_MCode.vhd] - Blame information for rev 29

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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