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

Subversion Repositories t80

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

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 25 jesus
-- Version : 0238
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 7 jesus
 
58
library IEEE;
59
use IEEE.std_logic_1164.all;
60
use IEEE.numeric_std.all;
61
use work.T80_Pack.all;
62
 
63
entity T80_MCode is
64
        generic(
65
                Mode : integer := 0
66
        );
67
        port(
68
                IR                              : in std_logic_vector(7 downto 0);
69
                ISet                    : in std_logic_vector(1 downto 0);
70
                MCycle                  : in std_logic_vector(2 downto 0);
71
                F                               : in std_logic_vector(7 downto 0);
72
                NMICycle                : in std_logic;
73
                IntCycle                : in std_logic;
74
                MCycles                 : out std_logic_vector(2 downto 0);
75
                TStates                 : out std_logic_vector(2 downto 0);
76
                Prefix                  : out std_logic_vector(1 downto 0); -- None,BC,ED,DD/FD
77
                Inc_PC                  : out std_logic;
78
                Inc_WZ                  : out std_logic;
79
                IncDec_16               : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP   0 is inc
80
                Read_To_Reg             : out std_logic;
81
                Read_To_Acc             : out std_logic;
82
                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
83
                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
84
                ALU_Op                  : out std_logic_vector(3 downto 0);
85
                        -- (ir)ADD, (ir)ADC, (ir)SUB, (ir)SBC, (ir)AND, (ir)XOR, (ir)OR, (ir)CP, ADD, ADC, SUB, SBC, DAA, RLD, RRD, CP
86
                Rot_Op                  : out std_logic;
87
                Bit_Op                  : out std_logic_vector(1 downto 0); -- None, BIT, SET, RES
88
                Save_ALU                : out std_logic;
89
                PreserveC               : out std_logic;
90
                Arith16                 : out std_logic;
91
                Set_Addr_To             : out AddressOutput; -- aXY,aIOA,aSP,aBC,aDE,aZI,aNone
92
                IORQ                    : out std_logic;
93
                Jump                    : out std_logic;
94
                JumpE                   : out std_logic;
95
                JumpXY                  : out std_logic;
96
                Call                    : out std_logic;
97
                RstP                    : out std_logic;
98
                LDZ                             : out std_logic;
99
                LDW                             : out std_logic;
100
                LDSPHL                  : out std_logic;
101
                Special_LD              : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
102
                ExchangeDH              : out std_logic;
103
                ExchangeRp              : out std_logic;
104
                ExchangeAF              : out std_logic;
105
                ExchangeRS              : out std_logic;
106
                I_DJNZ                  : out std_logic;
107
                I_CPL                   : out std_logic;
108
                I_CCF                   : out std_logic;
109
                I_SCF                   : out std_logic;
110
                I_RETN                  : out std_logic;
111
                I_BT                    : out std_logic;
112
                I_BC                    : out std_logic;
113
                I_BTR                   : out std_logic;
114
                I_RLD                   : out std_logic;
115
                I_RRD                   : out std_logic;
116
                I_INRC                  : out std_logic;
117
                SetDI                   : out std_logic;
118
                SetEI                   : out std_logic;
119
                IMode                   : out std_logic_vector(1 downto 0);
120
                Halt                    : out std_logic;
121 25 jesus
                NoRead                  : out std_logic;
122 7 jesus
                Write                   : out std_logic
123
        );
124
end T80_MCode;
125
 
126
architecture rtl of T80_MCode is
127
 
128
        function is_cc_true(
129
                F : std_logic_vector(7 downto 0);
130
                cc : bit_vector(2 downto 0)
131
                ) return boolean is
132
        begin
133
                case cc is
134
                when "000" => return F(6) = '0'; -- NZ
135
                when "001" => return F(6) = '1'; -- Z
136
                when "010" => return F(0) = '0'; -- NC
137
                when "011" => return F(0) = '1'; -- C
138
                when "100" => return F(2) = '0'; -- PO
139
                when "101" => return F(2) = '1'; -- PE
140
                when "110" => return F(7) = '0'; -- P
141
                when "111" => return F(7) = '1'; -- M
142
                end case;
143
        end;
144
 
145
begin
146
 
147
        process (IR, ISet, MCycle, F, NMICycle, IntCycle)
148
                variable DDD : std_logic_vector(2 downto 0);
149
                variable SSS : std_logic_vector(2 downto 0);
150
                variable DPair : std_logic_vector(1 downto 0);
151
                variable IRB : bit_vector(7 downto 0);
152
        begin
153
                DDD := IR(5 downto 3);
154
                SSS := IR(2 downto 0);
155
                DPair := IR(5 downto 4);
156
                IRB := to_bitvector(IR);
157
 
158
                MCycles <= "001";
159
                if MCycle = "001" then
160
                        TStates <= "100";
161
                else
162
                        TStates <= "011";
163
                end if;
164
                Prefix <= "00";
165
                Inc_PC <= '0';
166
                Inc_WZ <= '0';
167
                IncDec_16 <= "0000";
168
                Read_To_Acc <= '0';
169
                Read_To_Reg <= '0';
170
                Set_BusB_To <= "0000";
171
                Set_BusA_To <= "0000";
172
                ALU_Op <= "0000";
173
                Rot_Op <= '0';
174
                Bit_Op <= "00";
175
                Save_ALU <= '0';
176
                PreserveC <= '0';
177
                Arith16 <= '0';
178
                IORQ <= '0';
179
                Set_Addr_To <= aNone;
180
                Jump <= '0';
181
                JumpE <= '0';
182
                JumpXY <= '0';
183
                Call <= '0';
184
                RstP <= '0';
185
                LDZ <= '0';
186
                LDW <= '0';
187
                LDSPHL <= '0';
188
                Special_LD <= "000";
189
                ExchangeDH <= '0';
190
                ExchangeRp <= '0';
191
                ExchangeAF <= '0';
192
                ExchangeRS <= '0';
193
                I_DJNZ <= '0';
194
                I_CPL <= '0';
195
                I_CCF <= '0';
196
                I_SCF <= '0';
197
                I_RETN <= '0';
198
                I_BT <= '0';
199
                I_BC <= '0';
200
                I_BTR <= '0';
201
                I_RLD <= '0';
202
                I_RRD <= '0';
203
                I_INRC <= '0';
204
                SetDI <= '0';
205
                SetEI <= '0';
206
                IMode <= "11";
207
                Halt <= '0';
208 25 jesus
                NoRead <= '0';
209 7 jesus
                Write <= '0';
210
 
211
                case ISet is
212
                when "00" =>
213
 
214
------------------------------------------------------------------------------
215
--
216
--      Unprefixed instructions
217
--
218
------------------------------------------------------------------------------
219
 
220
                case IRB is
221
-- 8 BIT LOAD GROUP
222
                when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
223
                        |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
224
                        |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
225
                        |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
226
                        |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
227
                        |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
228
                        |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
229
                        -- LD r,r'
230
                        Set_BusB_To(2 downto 0) <= SSS;
231
                        ExchangeRp <= '1';
232
                        Set_BusA_To(2 downto 0) <= DDD;
233
                        Read_To_Reg <= '1';
234
                when "00000110"|"00001110"|"00010110"|"00011110"|"00100110"|"00101110"|"00111110" =>
235
                        -- LD r,n
236
                        MCycles <= "010";
237
                        case to_integer(unsigned(MCycle)) is
238
                        when 2 =>
239
                                Inc_PC <= '1';
240
                                Set_BusA_To(2 downto 0) <= DDD;
241
                                Read_To_Reg <= '1';
242
                        when others => null;
243
                        end case;
244
                when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01111110" =>
245
                        -- LD r,(HL)
246
                        MCycles <= "010";
247
                        case to_integer(unsigned(MCycle)) is
248
                        when 1 =>
249
                                Set_Addr_To <= aXY;
250
                        when 2 =>
251
                                Set_BusA_To(2 downto 0) <= DDD;
252
                                Read_To_Reg <= '1';
253
                        when others => null;
254
                        end case;
255
                when "01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111" =>
256
                        -- LD (HL),r
257
                        MCycles <= "010";
258
                        case to_integer(unsigned(MCycle)) is
259
                        when 1 =>
260
                                Set_Addr_To <= aXY;
261
                                Set_BusB_To(2 downto 0) <= SSS;
262
                                Set_BusB_To(3) <= '0';
263
                        when 2 =>
264
                                Write <= '1';
265
                        when others => null;
266
                        end case;
267
                when "00110110" =>
268
                        -- LD (HL),n
269
                        MCycles <= "011";
270
                        case to_integer(unsigned(MCycle)) is
271
                        when 2 =>
272
                                Inc_PC <= '1';
273
                                Set_Addr_To <= aXY;
274
                                Set_BusB_To(2 downto 0) <= SSS;
275
                                Set_BusB_To(3) <= '0';
276
                        when 3 =>
277
                                Write <= '1';
278
                        when others => null;
279
                        end case;
280
                when "00001010" =>
281
                        -- LD A,(BC)
282
                        MCycles <= "010";
283
                        case to_integer(unsigned(MCycle)) is
284
                        when 1 =>
285
                                Set_Addr_To <= aBC;
286
                        when 2 =>
287
                                Read_To_Acc <= '1';
288
                        when others => null;
289
                        end case;
290
                when "00011010" =>
291
                        -- LD A,(DE)
292
                        MCycles <= "010";
293
                        case to_integer(unsigned(MCycle)) is
294
                        when 1 =>
295
                                Set_Addr_To <= aDE;
296
                        when 2 =>
297
                                Read_To_Acc <= '1';
298
                        when others => null;
299
                        end case;
300
                when "00111010" =>
301
                        -- LD A,(nn)
302
                        MCycles <= "100";
303
                        case to_integer(unsigned(MCycle)) is
304
                        when 2 =>
305
                                Inc_PC <= '1';
306
                                LDZ <= '1';
307
                        when 3 =>
308
                                Set_Addr_To <= aZI;
309
                                Inc_PC <= '1';
310
                        when 4 =>
311
                                Read_To_Acc <= '1';
312
                        when others => null;
313
                        end case;
314
                when "00000010" =>
315
                        -- LD (BC),A
316
                        MCycles <= "010";
317
                        case to_integer(unsigned(MCycle)) is
318
                        when 1 =>
319
                                Set_Addr_To <= aBC;
320
                                Set_BusB_To <= "0111";
321
                        when 2 =>
322
                                Write <= '1';
323
                        when others => null;
324
                        end case;
325
                when "00010010" =>
326
                        -- LD (DE),A
327
                        MCycles <= "010";
328
                        case to_integer(unsigned(MCycle)) is
329
                        when 1 =>
330
                                Set_Addr_To <= aDE;
331
                                Set_BusB_To <= "0111";
332
                        when 2 =>
333
                                Write <= '1';
334
                        when others => null;
335
                        end case;
336
                when "00110010" =>
337
                        -- LD (nn),A
338
                        MCycles <= "100";
339
                        case to_integer(unsigned(MCycle)) is
340
                        when 2 =>
341
                                Inc_PC <= '1';
342
                                LDZ <= '1';
343
                        when 3 =>
344
                                Set_Addr_To <= aZI;
345
                                Inc_PC <= '1';
346
                                Set_BusB_To <= "0111";
347
                        when 4 =>
348
                                Write <= '1';
349
                        when others => null;
350
                        end case;
351
 
352
-- 16 BIT LOAD GROUP
353
                when "00000001"|"00010001"|"00100001"|"00110001" =>
354
                        -- LD dd,nn
355
                        MCycles <= "011";
356
                        case to_integer(unsigned(MCycle)) is
357
                        when 2 =>
358
                                Inc_PC <= '1';
359
                                Read_To_Reg <= '1';
360
                                if DPAIR = "11" then
361
                                        Set_BusA_To(3 downto 0) <= "1000";
362
                                else
363
                                        Set_BusA_To(2 downto 1) <= DPAIR;
364
                                        Set_BusA_To(0) <= '1';
365
                                end if;
366
                        when 3 =>
367
                                Inc_PC <= '1';
368
                                Read_To_Reg <= '1';
369
                                if DPAIR = "11" then
370
                                        Set_BusA_To(3 downto 0) <= "1001";
371
                                else
372
                                        Set_BusA_To(2 downto 1) <= DPAIR;
373
                                        Set_BusA_To(0) <= '0';
374
                                end if;
375
                        when others => null;
376
                        end case;
377
                when "00101010" =>
378
                        -- LD HL,(nn)
379
                        MCycles <= "101";
380
                        case to_integer(unsigned(MCycle)) is
381
                        when 2 =>
382
                                Inc_PC <= '1';
383
                                LDZ <= '1';
384
                        when 3 =>
385
                                Set_Addr_To <= aZI;
386
                                Inc_PC <= '1';
387
                                LDW <= '1';
388
                        when 4 =>
389
                                Set_BusA_To(2 downto 0) <= "101"; -- L
390
                                Read_To_Reg <= '1';
391
                                Inc_WZ <= '1';
392
                                Set_Addr_To <= aZI;
393
                        when 5 =>
394
                                Set_BusA_To(2 downto 0) <= "100"; -- H
395
                                Read_To_Reg <= '1';
396
                        when others => null;
397
                        end case;
398
                when "00100010" =>
399
                        -- LD (nn),HL
400
                        MCycles <= "101";
401
                        case to_integer(unsigned(MCycle)) is
402
                        when 2 =>
403
                                Inc_PC <= '1';
404
                                LDZ <= '1';
405
                        when 3 =>
406
                                Set_Addr_To <= aZI;
407
                                Inc_PC <= '1';
408
                                LDW <= '1';
409
                                Set_BusB_To <= "0101"; -- L
410
                        when 4 =>
411
                                Inc_WZ <= '1';
412
                                Set_Addr_To <= aZI;
413
                                Write <= '1';
414
                                Set_BusB_To <= "0100"; -- H
415
                        when 5 =>
416
                                Write <= '1';
417
                        when others => null;
418
                        end case;
419
                when "11111001" =>
420
                        -- LD SP,HL
421
                        TStates <= "110";
422
                        LDSPHL <= '1';
423
                when "11000101"|"11010101"|"11100101"|"11110101" =>
424
                        -- PUSH qq
425
                        MCycles <= "011";
426
                        case to_integer(unsigned(MCycle)) is
427
                        when 1 =>
428
                                TStates <= "101";
429
                                IncDec_16 <= "1111";
430
                                Set_Addr_TO <= aSP;
431
                                if DPAIR = "11" then
432
                                        Set_BusB_To <= "0111";
433
                                else
434
                                        Set_BusB_To(2 downto 1) <= DPAIR;
435
                                        Set_BusB_To(0) <= '0';
436
                                        Set_BusB_To(3) <= '0';
437
                                end if;
438
                        when 2 =>
439
                                IncDec_16 <= "1111";
440
                                Set_Addr_To <= aSP;
441
                                if DPAIR = "11" then
442
                                        Set_BusB_To <= "1011";
443
                                else
444
                                        Set_BusB_To(2 downto 1) <= DPAIR;
445
                                        Set_BusB_To(0) <= '1';
446
                                        Set_BusB_To(3) <= '0';
447
                                end if;
448
                                Write <= '1';
449
                        when 3 =>
450
                                Write <= '1';
451
                        when others => null;
452
                        end case;
453
                when "11000001"|"11010001"|"11100001"|"11110001" =>
454
                        -- POP qq
455
                        MCycles <= "011";
456
                        case to_integer(unsigned(MCycle)) is
457
                        when 1 =>
458
                                TStates <= "101";
459
                                Set_Addr_To <= aSP;
460
                        when 2 =>
461
                                IncDec_16 <= "0111";
462
                                Set_Addr_To <= aSP;
463
                                Read_To_Reg <= '1';
464
                                if DPAIR = "11" then
465
                                        Set_BusA_To(3 downto 0) <= "1011";
466
                                else
467
                                        Set_BusA_To(2 downto 1) <= DPAIR;
468
                                        Set_BusA_To(0) <= '1';
469
                                end if;
470
                        when 3 =>
471
                                IncDec_16 <= "0111";
472
                                Read_To_Reg <= '1';
473
                                if DPAIR = "11" then
474
                                        Set_BusA_To(3 downto 0) <= "0111";
475
                                else
476
                                        Set_BusA_To(2 downto 1) <= DPAIR;
477
                                        Set_BusA_To(0) <= '0';
478
                                end if;
479
                        when others => null;
480
                        end case;
481
 
482
-- EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
483
                when "11101011" =>
484
                        -- EX DE,HL
485
                        ExchangeDH <= '1';
486
                when "00001000" =>
487
                        -- EX AF,AF'
488
                        ExchangeAF <= '1';
489
                when "11011001" =>
490
                        -- EXX
491
                        ExchangeRS <= '1';
492
                when "11100011" =>
493
                        -- EX (SP),HL
494
                        MCycles <= "101";
495
                        case to_integer(unsigned(MCycle)) is
496
                        when 1 =>
497
                                Set_Addr_To <= aSP;
498
                        when 2 =>
499
                                Read_To_Reg <= '1';
500
                                Set_BusA_To <= "0101";
501
                                Set_BusB_To <= "0101";
502
                                Set_Addr_To <= aSP;
503
                        when 3 =>
504
                                IncDec_16 <= "0111";
505
                                Set_Addr_To <= aSP;
506
                                TStates <= "100";
507
                                Write <= '1';
508
                        when 4 =>
509
                                Read_To_Reg <= '1';
510
                                Set_BusA_To <= "0100";
511
                                Set_BusB_To <= "0100";
512
                                Set_Addr_To <= aSP;
513
                        when 5 =>
514
                                IncDec_16 <= "1111";
515
                                TStates <= "101";
516
                                Write <= '1';
517
                        when others => null;
518
                        end case;
519
 
520
-- 8 BIT ARITHMETIC AND LOGICAL GROUP
521
                when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
522
                        |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
523
                        |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
524
                        |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
525
                        |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
526
                        |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
527
                        |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
528
                        |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
529
                        -- ADD A,r
530
                        -- ADC A,r
531
                        -- SUB A,r
532
                        -- SBC A,r
533
                        -- AND A,r
534
                        -- OR A,r
535
                        -- XOR A,r
536
                        -- CP A,r
537
                        Set_BusB_To(2 downto 0) <= SSS;
538
                        Set_BusA_To(2 downto 0) <= "111";
539
                        Read_To_Reg <= '1';
540
                        Save_ALU <= '1';
541
                when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
542
                        -- ADD A,(HL)
543
                        -- ADC A,(HL)
544
                        -- SUB A,(HL)
545
                        -- SBC A,(HL)
546
                        -- AND A,(HL)
547
                        -- OR A,(HL)
548
                        -- XOR A,(HL)
549
                        -- CP A,(HL)
550
                        MCycles <= "010";
551
                        case to_integer(unsigned(MCycle)) is
552
                        when 1 =>
553
                                Set_Addr_To <= aXY;
554
                        when 2 =>
555
                                Read_To_Reg <= '1';
556
                                Save_ALU <= '1';
557
                                Set_BusB_To(2 downto 0) <= SSS;
558
                                Set_BusA_To(2 downto 0) <= "111";
559
                        when others => null;
560
                        end case;
561
                when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
562
                        -- ADD A,n
563
                        -- ADC A,n
564
                        -- SUB A,n
565
                        -- SBC A,n
566
                        -- AND A,n
567
                        -- OR A,n
568
                        -- XOR A,n
569
                        -- CP A,n
570
                        MCycles <= "010";
571
                        if MCycle = "010" then
572
                                Inc_PC <= '1';
573
                                Read_To_Reg <= '1';
574
                                Save_ALU <= '1';
575
                                Set_BusB_To(2 downto 0) <= SSS;
576
                                Set_BusA_To(2 downto 0) <= "111";
577
                        end if;
578
                when "00000100"|"00001100"|"00010100"|"00011100"|"00100100"|"00101100"|"00111100" =>
579
                        -- INC r
580
                        Set_BusB_To <= "1010";
581
                        Set_BusA_To(2 downto 0) <= DDD;
582
                        Read_To_Reg <= '1';
583
                        Save_ALU <= '1';
584
                        PreserveC <= '1';
585
                        ALU_Op <= "1000";
586
                when "00110100" =>
587
                        -- INC (HL)
588
                        MCycles <= "011";
589
                        case to_integer(unsigned(MCycle)) is
590
                        when 1 =>
591
                                Set_Addr_To <= aXY;
592
                        when 2 =>
593
                                TStates <= "100";
594
                                Set_Addr_To <= aXY;
595
                                Read_To_Reg <= '1';
596
                                Save_ALU <= '1';
597
                                PreserveC <= '1';
598
                                ALU_Op <= "1000";
599
                                Set_BusB_To <= "1010";
600
                                Set_BusA_To(2 downto 0) <= DDD;
601
                        when 3 =>
602
                                Write <= '1';
603
                        when others => null;
604
                        end case;
605
                when "00000101"|"00001101"|"00010101"|"00011101"|"00100101"|"00101101"|"00111101" =>
606
                        -- DEC r
607
                        Set_BusB_To <= "1010";
608
                        Set_BusA_To(2 downto 0) <= DDD;
609
                        Read_To_Reg <= '1';
610
                        Save_ALU <= '1';
611
                        PreserveC <= '1';
612
                        ALU_Op <= "1010";
613
                when "00110101" =>
614
                        -- DEC (HL)
615
                        MCycles <= "011";
616
                        case to_integer(unsigned(MCycle)) is
617
                        when 1 =>
618
                                Set_Addr_To <= aXY;
619
                        when 2 =>
620
                                TStates <= "100";
621
                                Set_Addr_To <= aXY;
622
                                ALU_Op <= "1010";
623
                                Read_To_Reg <= '1';
624
                                Save_ALU <= '1';
625
                                PreserveC <= '1';
626
                                Set_BusB_To <= "1010";
627
                                Set_BusA_To(2 downto 0) <= DDD;
628
                        when 3 =>
629
                                Write <= '1';
630
                        when others => null;
631
                        end case;
632
 
633
-- GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
634
                when "00100111" =>
635
                        -- DAA
636
                        Set_BusA_To(2 downto 0) <= "111";
637
                        Read_To_Reg <= '1';
638
                        ALU_Op <= "1100";
639
                        Save_ALU <= '1';
640
                when "00101111" =>
641
                        -- CPL
642
                        I_CPL <= '1';
643
                when "00111111" =>
644
                        -- CCF
645
                        I_CCF <= '1';
646
                when "00110111" =>
647
                        -- SCF
648
                        I_SCF <= '1';
649
                when "00000000" =>
650
                        if NMICycle = '1' then
651
                                -- NMI
652
                                MCycles <= "011";
653
                                case to_integer(unsigned(MCycle)) is
654
                                when 1 =>
655
                                        TStates <= "101";
656
                                        IncDec_16 <= "1111";
657
                                        Set_Addr_To <= aSP;
658
                                        Set_BusB_To <= "1101";
659
                                when 2 =>
660
                                        TStates <= "100";
661
                                        Write <= '1';
662
                                        IncDec_16 <= "1111";
663
                                        Set_Addr_To <= aSP;
664
                                        Set_BusB_To <= "1100";
665
                                when 3 =>
666
                                        TStates <= "100";
667
                                        Write <= '1';
668
                                when others => null;
669
                                end case;
670
                        elsif IntCycle = '1' then
671
                                -- INT (IM 2)
672 15 jesus
                                MCycles <= "101";
673 7 jesus
                                case to_integer(unsigned(MCycle)) is
674
                                when 1 =>
675
                                        LDZ <= '1';
676
                                        TStates <= "101";
677
                                        IncDec_16 <= "1111";
678
                                        Set_Addr_To <= aSP;
679
                                        Set_BusB_To <= "1101";
680
                                when 2 =>
681
                                        TStates <= "100";
682
                                        Write <= '1';
683
                                        IncDec_16 <= "1111";
684
                                        Set_Addr_To <= aSP;
685
                                        Set_BusB_To <= "1100";
686
                                when 3 =>
687
                                        TStates <= "100";
688
                                        Write <= '1';
689 15 jesus
                                when 4 =>
690
                                        Inc_PC <= '1';
691
                                        LDZ <= '1';
692
                                when 5 =>
693
                                        Jump <= '1';
694 7 jesus
                                when others => null;
695
                                end case;
696
                        else
697
                                -- NOP
698
                        end if;
699
                when "01110110" =>
700
                        -- HALT
701
                        Halt <= '1';
702
                when "11110011" =>
703
                        -- DI
704
                        SetDI <= '1';
705
                when "11111011" =>
706
                        -- EI
707
                        SetEI <= '1';
708
 
709
-- 16 BIT ARITHMETIC GROUP
710
                when "00001001"|"00011001"|"00101001"|"00111001" =>
711
                        -- ADD HL,ss
712
                        MCycles <= "011";
713
                        case to_integer(unsigned(MCycle)) is
714
                        when 2 =>
715 25 jesus
                                NoRead <= '1';
716 7 jesus
                                ALU_Op <= "1000";
717
                                Read_To_Reg <= '1';
718
                                Save_ALU <= '1';
719
                                Set_BusA_To(2 downto 0) <= "101";
720
                                case to_integer(unsigned(IR(5 downto 4))) is
721
                                when 0|1|2 =>
722
                                        Set_BusB_To(2 downto 1) <= IR(5 downto 4);
723
                                        Set_BusB_To(0) <= '1';
724
                                when others =>
725
                                        Set_BusB_To <= "1000";
726
                                end case;
727
                                TStates <= "100";
728
                                Arith16 <= '1';
729
                        when 3 =>
730 25 jesus
                                NoRead <= '1';
731 7 jesus
                                Read_To_Reg <= '1';
732
                                Save_ALU <= '1';
733
                                ALU_Op <= "1001";
734
                                Set_BusA_To(2 downto 0) <= "100";
735
                                case to_integer(unsigned(IR(5 downto 4))) is
736
                                when 0|1|2 =>
737
                                        Set_BusB_To(2 downto 1) <= IR(5 downto 4);
738
                                when others =>
739
                                        Set_BusB_To <= "1001";
740
                                end case;
741
                                Arith16 <= '1';
742
                        when others =>
743
                        end case;
744
                when "00000011"|"00010011"|"00100011"|"00110011" =>
745
                        -- INC ss
746
                        TStates <= "110";
747
                        IncDec_16(3 downto 2) <= "01";
748
                        IncDec_16(1 downto 0) <= DPair;
749
                when "00001011"|"00011011"|"00101011"|"00111011" =>
750
                        -- DEC ss
751
                        TStates <= "110";
752
                        IncDec_16(3 downto 2) <= "11";
753
                        IncDec_16(1 downto 0) <= DPair;
754
 
755
-- ROTATE AND SHIFT GROUP
756
                when "00000111"
757
                        -- RLCA
758
                        |"00010111"
759
                        -- RLA
760
                        |"00001111"
761
                        -- RRCA
762
                        |"00011111" =>
763
                        -- RRA
764
                        Set_BusA_To(2 downto 0) <= "111";
765
                        Rot_Op <= '1';
766
                        Read_To_Reg <= '1';
767
                        Save_ALU <= '1';
768
 
769
-- JUMP GROUP
770
                when "11000011" =>
771
                        -- JP nn
772
                        MCycles <= "011";
773
                        case to_integer(unsigned(MCycle)) is
774
                        when 2 =>
775
                                Inc_PC <= '1';
776
                                LDZ <= '1';
777
                        when 3 =>
778
                                Inc_PC <= '1';
779
                                Jump <= '1';
780
                        when others => null;
781
                        end case;
782
                when "11000010"|"11001010"|"11010010"|"11011010"|"11100010"|"11101010"|"11110010"|"11111010" =>
783
                        -- JP cc,nn
784
                        MCycles <= "011";
785
                        case to_integer(unsigned(MCycle)) is
786
                        when 2 =>
787
                                Inc_PC <= '1';
788
                                LDZ <= '1';
789
                        when 3 =>
790
                                Inc_PC <= '1';
791
                                if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
792
                                        Jump <= '1';
793
                                end if;
794
                        when others => null;
795
                        end case;
796
                when "00011000" =>
797
                        -- JR e
798
                        MCycles <= "011";
799
                        case to_integer(unsigned(MCycle)) is
800
                        when 2 =>
801
                                Inc_PC <= '1';
802
                        when 3 =>
803 25 jesus
                                NoRead <= '1';
804 7 jesus
                                JumpE <= '1';
805
                                TStates <= "101";
806
                        when others => null;
807
                        end case;
808
                when "00111000" =>
809
                        -- JR C,e
810
                        MCycles <= "011";
811
                        case to_integer(unsigned(MCycle)) is
812
                        when 2 =>
813
                                Inc_PC <= '1';
814
                                if F(0) = '0' then
815
                                        MCycles <= "010";
816
                                end if;
817
                        when 3 =>
818 25 jesus
                                NoRead <= '1';
819 7 jesus
                                JumpE <= '1';
820
                                TStates <= "101";
821
                        when others => null;
822
                        end case;
823
                when "00110000" =>
824
                        -- JR NC,e
825
                        MCycles <= "011";
826
                        case to_integer(unsigned(MCycle)) is
827
                        when 2 =>
828
                                Inc_PC <= '1';
829
                                if F(0) = '1' then
830
                                        MCycles <= "010";
831
                                end if;
832
                        when 3 =>
833 25 jesus
                                NoRead <= '1';
834 7 jesus
                                JumpE <= '1';
835
                                TStates <= "101";
836
                        when others => null;
837
                        end case;
838
                when "00101000" =>
839
                        -- JR Z,e
840
                        MCycles <= "011";
841
                        case to_integer(unsigned(MCycle)) is
842
                        when 2 =>
843
                                Inc_PC <= '1';
844
                                if F(6) = '0' then
845
                                        MCycles <= "010";
846
                                end if;
847
                        when 3 =>
848 25 jesus
                                NoRead <= '1';
849 7 jesus
                                JumpE <= '1';
850
                                TStates <= "101";
851
                        when others => null;
852
                        end case;
853
                when "00100000" =>
854
                        -- JR NZ,e
855
                        MCycles <= "011";
856
                        case to_integer(unsigned(MCycle)) is
857
                        when 2 =>
858
                                Inc_PC <= '1';
859
                                if F(6) = '1' then
860
                                        MCycles <= "010";
861
                                end if;
862
                        when 3 =>
863 25 jesus
                                NoRead <= '1';
864 7 jesus
                                JumpE <= '1';
865
                                TStates <= "101";
866
                        when others => null;
867
                        end case;
868
                when "11101001" =>
869
                        -- JP (HL)
870
                        JumpXY <= '1';
871
                when "00010000" =>
872
                        -- DJNZ,e
873
                        MCycles <= "011";
874
                        case to_integer(unsigned(MCycle)) is
875
                        when 1 =>
876
                                I_DJNZ <= '1';
877
                                Set_BusB_To <= "1010";
878
                                Set_BusA_To(2 downto 0) <= "000";
879
                                Read_To_Reg <= '1';
880
                                Save_ALU <= '1';
881
                                ALU_Op <= "1010";
882
                        when 2 =>
883
                                I_DJNZ <= '1';
884
                                Inc_PC <= '1';
885
                        when 3 =>
886 25 jesus
                                NoRead <= '1';
887 7 jesus
                                JumpE <= '1';
888
                                TStates <= "101";
889
                        when others => null;
890
                        end case;
891
 
892
-- CALL AND RETURN GROUP
893
                when "11001101" =>
894
                        -- CALL nn
895
                        MCycles <= "101";
896
                        case to_integer(unsigned(MCycle)) is
897
                        when 2 =>
898
                                Inc_PC <= '1';
899
                                LDZ <= '1';
900
                        when 3 =>
901
                                IncDec_16 <= "1111";
902
                                Inc_PC <= '1';
903
                                TStates <= "100";
904
                                Set_Addr_To <= aSP;
905
                                LDW <= '1';
906
                                Set_BusB_To <= "1101";
907
                        when 4 =>
908
                                Write <= '1';
909
                                IncDec_16 <= "1111";
910
                                Set_Addr_To <= aSP;
911
                                Set_BusB_To <= "1100";
912
                        when 5 =>
913
                                Write <= '1';
914
                                Call <= '1';
915
                        when others => null;
916
                        end case;
917
                when "11000100"|"11001100"|"11010100"|"11011100"|"11100100"|"11101100"|"11110100"|"11111100" =>
918
                        -- CALL cc,nn
919
                        MCycles <= "101";
920
                        case to_integer(unsigned(MCycle)) is
921
                        when 2 =>
922
                                Inc_PC <= '1';
923
                                LDZ <= '1';
924
                        when 3 =>
925
                                Inc_PC <= '1';
926
                                LDW <= '1';
927
                                if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
928
                                        IncDec_16 <= "1111";
929
                                        Set_Addr_TO <= aSP;
930
                                        TStates <= "100";
931
                                        Set_BusB_To <= "1101";
932
                                else
933
                                        MCycles <= "011";
934
                                end if;
935
                        when 4 =>
936
                                Write <= '1';
937
                                IncDec_16 <= "1111";
938
                                Set_Addr_To <= aSP;
939
                                Set_BusB_To <= "1100";
940
                        when 5 =>
941
                                Write <= '1';
942
                                Call <= '1';
943
                        when others => null;
944
                        end case;
945
                when "11001001" =>
946
                        -- RET
947
                        MCycles <= "011";
948
                        case to_integer(unsigned(MCycle)) is
949
                        when 1 =>
950
                                TStates <= "101";
951
                                Set_Addr_TO <= aSP;
952
                        when 2 =>
953
                                IncDec_16 <= "0111";
954
                                Set_Addr_To <= aSP;
955
                                LDZ <= '1';
956
                        when 3 =>
957
                                Jump <= '1';
958
                                IncDec_16 <= "0111";
959
                        when others => null;
960
                        end case;
961
                when "11000000"|"11001000"|"11010000"|"11011000"|"11100000"|"11101000"|"11110000"|"11111000" =>
962
                        -- RET cc
963
                        MCycles <= "011";
964
                        case to_integer(unsigned(MCycle)) is
965
                        when 1 =>
966
                                if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
967
                                        Set_Addr_TO <= aSP;
968
                                else
969
                                        MCycles <= "001";
970
                                end if;
971
                                TStates <= "101";
972
                        when 2 =>
973
                                IncDec_16 <= "0111";
974
                                Set_Addr_To <= aSP;
975
                                LDZ <= '1';
976
                        when 3 =>
977
                                Jump <= '1';
978
                                IncDec_16 <= "0111";
979
                        when others => null;
980
                        end case;
981
                when "11000111"|"11001111"|"11010111"|"11011111"|"11100111"|"11101111"|"11110111"|"11111111" =>
982
                        -- RST p
983
                        MCycles <= "011";
984
                        case to_integer(unsigned(MCycle)) is
985
                        when 1 =>
986
                                TStates <= "101";
987
                                IncDec_16 <= "1111";
988
                                Set_Addr_To <= aSP;
989
                                Set_BusB_To <= "1101";
990
                        when 2 =>
991
                                Write <= '1';
992
                                IncDec_16 <= "1111";
993
                                Set_Addr_To <= aSP;
994
                                Set_BusB_To <= "1100";
995
                        when 3 =>
996
                                Write <= '1';
997
                                RstP <= '1';
998
                        when others => null;
999
                        end case;
1000
 
1001
-- INPUT AND OUTPUT GROUP
1002
                when "11011011" =>
1003
                        -- IN A,(n)
1004
                        MCycles <= "011";
1005
                        case to_integer(unsigned(MCycle)) is
1006
                        when 2 =>
1007
                                Inc_PC <= '1';
1008
                                Set_Addr_To <= aIOA;
1009
                        when 3 =>
1010
                                Read_To_Acc <= '1';
1011
                                IORQ <= '1';
1012
                        when others => null;
1013
                        end case;
1014
                when "11010011" =>
1015
                        -- OUT (n),A
1016
                        MCycles <= "011";
1017
                        case to_integer(unsigned(MCycle)) is
1018
                        when 2 =>
1019
                                Inc_PC <= '1';
1020
                                Set_Addr_To <= aIOA;
1021
                                Set_BusB_To     <= "0111";
1022
                        when 3 =>
1023
                                Write <= '1';
1024
                                IORQ <= '1';
1025
                        when others => null;
1026
                        end case;
1027
 
1028
------------------------------------------------------------------------------
1029
------------------------------------------------------------------------------
1030
-- MULTIBYTE INSTRUCTIONS
1031
------------------------------------------------------------------------------
1032
------------------------------------------------------------------------------
1033
 
1034
                when "11001011" =>
1035
                        if Mode /= 2 then
1036
                                Prefix <= "01";
1037
                        end if;
1038
 
1039
                when "11101101" =>
1040
                        if Mode < 2 then
1041
                                Prefix <= "10";
1042
                        end if;
1043
 
1044
                when "11011101"|"11111101" =>
1045
                        if Mode < 2 then
1046
                                Prefix <= "11";
1047
                        end if;
1048
 
1049
                end case;
1050
 
1051
                when "01" =>
1052
 
1053
------------------------------------------------------------------------------
1054
--
1055
--      CB prefixed instructions
1056
--
1057
------------------------------------------------------------------------------
1058
 
1059
                        Set_BusA_To(2 downto 0) <= IR(2 downto 0);
1060
                        Set_BusB_To(2 downto 0) <= IR(2 downto 0);
1061
 
1062
                        case IRB is
1063
                        when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000111"
1064
                                |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010111"
1065
                                |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001111"
1066
                                |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011111"
1067
                                |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100111"
1068
                                |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101111"
1069
                                |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110111"
1070
                                |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111111" =>
1071
                                -- RLC r
1072
                                -- RL r
1073
                                -- RRC r
1074
                                -- RR r
1075
                                -- SLA r
1076
                                -- SRA r
1077
                                -- SRL r
1078
                                -- SLL r (Undocumented)
1079
                                Rot_Op <= '1';
1080
                                Read_To_Reg <= '1';
1081
                                Save_ALU <= '1';
1082
                        when "00000110"|"00010110"|"00001110"|"00011110"|"00101110"|"00111110"|"00100110"|"00110110" =>
1083
                                -- RLC (HL)
1084
                                -- RL (HL)
1085
                                -- RRC (HL)
1086
                                -- RR (HL)
1087
                                -- SRA (HL)
1088
                                -- SRL (HL)
1089
                                -- SLA (HL)
1090
                                -- SLL (HL) (Undocumented)
1091
                                MCycles <= "011";
1092
                                case to_integer(unsigned(MCycle)) is
1093
                                when 1 =>
1094
                                        Set_Addr_To <= aXY;
1095
                                when 2 =>
1096
                                        Rot_Op <= '1';
1097
                                        Read_To_Reg <= '1';
1098
                                        Save_ALU <= '1';
1099
                                        Set_Addr_To <= aXY;
1100
                                when 3 =>
1101
                                        Write <= '1';
1102
                                        TStates <= "011";
1103
                                when others =>
1104
                                end case;
1105
                        when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
1106
                                |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
1107
                                |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
1108
                                |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
1109
                                |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
1110
                                |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
1111
                                |"01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111"
1112
                                |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
1113
                                -- BIT b,r
1114
                                Set_BusB_To(2 downto 0) <= IR(2 downto 0);
1115
                                Bit_Op <= "01";
1116
                        when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01110110"|"01111110" =>
1117
                                -- BIT b,(HL)
1118
                                MCycles <= "010";
1119
                                case to_integer(unsigned(MCycle)) is
1120
                                when 1 =>
1121
                                        Set_Addr_To <= aXY;
1122
                                when 2 =>
1123
                                        Bit_Op <= "01";
1124
                                when others => null;
1125
                                end case;
1126
                        when "11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000111"
1127
                                |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001111"
1128
                                |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010111"
1129
                                |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011111"
1130
                                |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100111"
1131
                                |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101111"
1132
                                |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110111"
1133
                                |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111111" =>
1134
                                -- SET b,r
1135
                                Bit_Op <= "10";
1136
                                Read_To_Reg <= '1';
1137
                                Save_ALU <= '1';
1138
                        when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
1139
                                -- SET b,(HL)
1140
                                MCycles <= "011";
1141
                                case to_integer(unsigned(MCycle)) is
1142
                                when 1 =>
1143
                                        Set_Addr_To <= aXY;
1144
                                when 2 =>
1145
                                        Bit_Op <= "10";
1146
                                        Read_To_Reg <= '1';
1147
                                        Save_ALU <= '1';
1148
                                        Set_Addr_To <= aXY;
1149
                                when 3 =>
1150
                                        Write <= '1';
1151
                                when others => null;
1152
                                end case;
1153
                        when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
1154
                                |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
1155
                                |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
1156
                                |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
1157
                                |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
1158
                                |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
1159
                                |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
1160
                                |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
1161
                                -- RES b,r
1162
                                Bit_Op <= "11";
1163
                                Read_To_Reg <= '1';
1164
                                Save_ALU <= '1';
1165
                        when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
1166
                                -- RES b,(HL)
1167
                                MCycles <= "011";
1168
                                case to_integer(unsigned(MCycle)) is
1169
                                when 1 =>
1170
                                        Set_Addr_To <= aXY;
1171
                                when 2 =>
1172
                                        Bit_Op <= "11";
1173
                                        Read_To_Reg <= '1';
1174
                                        Save_ALU <= '1';
1175
                                        Set_Addr_To <= aXY;
1176
                                when 3 =>
1177
                                        Write <= '1';
1178
                                when others => null;
1179
                                end case;
1180
                        end case;
1181
 
1182
                when others =>
1183
 
1184
------------------------------------------------------------------------------
1185
--
1186
--      ED prefixed instructions
1187
--
1188
------------------------------------------------------------------------------
1189
 
1190
                        case IRB is
1191
                        when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000110"|"00000111"
1192
                                |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001110"|"00001111"
1193
                                |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010110"|"00010111"
1194
                                |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011110"|"00011111"
1195
                                |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100110"|"00100111"
1196
                                |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101110"|"00101111"
1197
                                |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110110"|"00110111"
1198
                                |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111110"|"00111111"
1199
 
1200
 
1201
                                |"10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000110"|"10000111"
1202
                                |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001110"|"10001111"
1203
                                |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010110"|"10010111"
1204
                                |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011110"|"10011111"
1205
                                |                                            "10100100"|"10100101"|"10100110"|"10100111"
1206
                                |                                            "10101100"|"10101101"|"10101110"|"10101111"
1207
                                |                                            "10110100"|"10110101"|"10110110"|"10110111"
1208
                                |                                            "10111100"|"10111101"|"10111110"|"10111111"
1209
                                |"11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000110"|"11000111"
1210
                                |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001110"|"11001111"
1211
                                |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010110"|"11010111"
1212
                                |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011110"|"11011111"
1213
                                |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100110"|"11100111"
1214
                                |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101110"|"11101111"
1215
                                |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110110"|"11110111"
1216
                                |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111110"|"11111111" =>
1217
                                null; -- NOP, undocumented
1218
                        when "01111110"|"01111111" =>
1219
                                -- NOP, undocumented
1220
                                null;
1221
-- 8 BIT LOAD GROUP
1222
                        when "01010111" =>
1223
                                -- LD A,I
1224
                                Special_LD <= "100";
1225
                                TStates <= "101";
1226
                        when "01011111" =>
1227
                                -- LD A,R
1228
                                Special_LD <= "101";
1229
                                TStates <= "101";
1230
                        when "01000111" =>
1231
                                -- LD I,A
1232
                                Special_LD <= "110";
1233
                                TStates <= "101";
1234
                        when "01001111" =>
1235
                                -- LD R,A
1236
                                Special_LD <= "111";
1237
                                TStates <= "101";
1238
-- 16 BIT LOAD GROUP
1239
                        when "01001011"|"01011011"|"01101011"|"01111011" =>
1240
                                -- LD dd,(nn)
1241
                                MCycles <= "101";
1242
                                case to_integer(unsigned(MCycle)) is
1243
                                when 2 =>
1244
                                        Inc_PC <= '1';
1245
                                        LDZ <= '1';
1246
                                when 3 =>
1247
                                        Set_Addr_To <= aZI;
1248
                                        Inc_PC <= '1';
1249
                                        LDW <= '1';
1250
                                when 4 =>
1251
                                        Read_To_Reg <= '1';
1252
                                        if IR(5 downto 4) = "11" then
1253
                                                Set_BusA_To <= "1000";
1254
                                        else
1255
                                                Set_BusA_To(2 downto 1) <= IR(5 downto 4);
1256
                                                Set_BusA_To(0) <= '1';
1257
                                        end if;
1258
                                        Inc_WZ <= '1';
1259
                                        Set_Addr_To <= aZI;
1260
                                when 5 =>
1261
                                        Read_To_Reg <= '1';
1262
                                        if IR(5 downto 4) = "11" then
1263
                                                Set_BusA_To <= "1001";
1264
                                        else
1265
                                                Set_BusA_To(2 downto 1) <= IR(5 downto 4);
1266
                                                Set_BusA_To(0) <= '0';
1267
                                        end if;
1268
                                when others => null;
1269
                                end case;
1270
                        when "01000011"|"01010011"|"01100011"|"01110011" =>
1271
                                -- LD (nn),dd
1272
                                MCycles <= "101";
1273
                                case to_integer(unsigned(MCycle)) is
1274
                                when 2 =>
1275
                                        Inc_PC <= '1';
1276
                                        LDZ <= '1';
1277
                                when 3 =>
1278
                                        Set_Addr_To <= aZI;
1279
                                        Inc_PC <= '1';
1280
                                        LDW <= '1';
1281
                                        if IR(5 downto 4) = "11" then
1282
                                                Set_BusB_To <= "1000";
1283
                                        else
1284
                                                Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1285
                                                Set_BusB_To(0) <= '1';
1286
                                                Set_BusB_To(3) <= '0';
1287
                                        end if;
1288
                                when 4 =>
1289
                                        Inc_WZ <= '1';
1290
                                        Set_Addr_To <= aZI;
1291
                                        Write <= '1';
1292
                                        if IR(5 downto 4) = "11" then
1293
                                                Set_BusB_To <= "1001";
1294
                                        else
1295
                                                Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1296
                                                Set_BusB_To(0) <= '0';
1297
                                                Set_BusB_To(3) <= '0';
1298
                                        end if;
1299
                                when 5 =>
1300
                                        Write <= '1';
1301
                                when others => null;
1302
                                end case;
1303
                        when "10100000" | "10101000" | "10110000" | "10111000" =>
1304
                                -- LDI, LDD, LDIR, LDDR
1305
                                MCycles <= "011";
1306
                                case to_integer(unsigned(MCycle)) is
1307
                                when 1 =>
1308
                                        Set_Addr_To <= aXY;
1309
                                        IncDec_16 <= "1100"; -- BC
1310
                                when 2 =>
1311
                                        Set_BusB_To <= "0110";
1312
                                        Set_BusA_To(2 downto 0) <= "111";
1313
                                        ALU_Op <= "1000";
1314
                                        Set_Addr_To <= aDE;
1315
                                        if IR(3) = '0' then
1316
                                                IncDec_16 <= "0110"; -- IX
1317
                                        else
1318
                                                IncDec_16 <= "1110";
1319
                                        end if;
1320
                                when 3 =>
1321
                                        I_BT <= '1';
1322
                                        TStates <= "101";
1323
                                        Write <= '1';
1324
                                        if IR(3) = '0' then
1325
                                                IncDec_16 <= "0101"; -- DE
1326
                                        else
1327
                                                IncDec_16 <= "1101";
1328
                                        end if;
1329
                                        if IR(4) = '1' and F(2) = '1' then
1330
                                                MCycles <= "100";
1331
                                        end if;
1332
                                when 4 =>
1333 25 jesus
                                        NoRead <= '1';
1334 7 jesus
                                        I_BTR <= '1';
1335
                                        TStates <= "101";
1336
                                        MCycles <= "100";
1337
                                when others => null;
1338
                                end case;
1339
                        when "10100001" | "10101001" | "10110001" | "10111001" =>
1340
                                -- CPI, CPD, CPIR, CPDR
1341
                                MCycles <= "011";
1342
                                case to_integer(unsigned(MCycle)) is
1343
                                when 1 =>
1344
                                        Set_Addr_To <= aXY;
1345
                                        IncDec_16 <= "1100"; -- BC
1346
                                when 2 =>
1347
                                        Set_BusB_To <= "0110";
1348
                                        Set_BusA_To(2 downto 0) <= "111";
1349
                                        ALU_Op <= "1111";
1350
                                        Save_ALU <= '1';
1351
                                        PreserveC <= '1';
1352
                                        if IR(3) = '0' then
1353
                                                IncDec_16 <= "0110";
1354
                                        else
1355
                                                IncDec_16 <= "1110";
1356
                                        end if;
1357
                                when 3 =>
1358 25 jesus
                                        NoRead <= '1';
1359 7 jesus
                                        I_BC <= '1';
1360
                                        TStates <= "101";
1361
                                        if IR(4) = '1' and F(2) = '1' and F(6) = '0' then
1362
                                                MCycles <= "100";
1363
                                        end if;
1364
                                when 4 =>
1365 25 jesus
                                        NoRead <= '1';
1366 7 jesus
                                        I_BTR <= '1';
1367
                                        TStates <= "101";
1368
                                        MCycles <= "100";
1369
                                when others => null;
1370
                                end case;
1371
                        when "01000100"|"01001100"|"01010100"|"01011100"|"01100100"|"01101100"|"01110100"|"01111100" =>
1372
                                -- NEG
1373
                                Alu_OP <= "1010";
1374
                                Set_BusB_To <= "0111";
1375
                                Set_BusA_To <= "1010";
1376
                                Read_To_Acc <= '1';
1377
                                Save_ALU <= '1';
1378
                        when "01000110"|"01001110"|"01100110"|"01101110" =>
1379
                                -- IM 0
1380
                                IMode <= "00";
1381
                        when "01010110"|"01110110" =>
1382
                                -- IM 1
1383
                                IMode <= "01";
1384
                        when "01011110"|"01110111" =>
1385
                                -- IM 2
1386
                                IMode <= "10";
1387
-- 16 bit arithmetic
1388
                        when "01001010"|"01011010"|"01101010"|"01111010" =>
1389
                                -- ADC HL,ss
1390
                                MCycles <= "011";
1391
                                case to_integer(unsigned(MCycle)) is
1392
                                when 2 =>
1393 25 jesus
                                        NoRead <= '1';
1394 7 jesus
                                        ALU_Op <= "1001";
1395
                                        Read_To_Reg <= '1';
1396
                                        Save_ALU <= '1';
1397
                                        Set_BusA_To(2 downto 0) <= "101";
1398
                                        case to_integer(unsigned(IR(5 downto 4))) is
1399
                                        when 0|1|2 =>
1400
                                                Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1401
                                        Set_BusB_To(0) <= '1';
1402
                                                when others =>
1403
                                                Set_BusB_To <= "1000";
1404
                                        end case;
1405
                                when 3 =>
1406 25 jesus
                                        NoRead <= '1';
1407 7 jesus
                                        Read_To_Reg <= '1';
1408
                                        Save_ALU <= '1';
1409
                                        ALU_Op <= "1001";
1410
                                        Set_BusA_To(2 downto 0) <= "100";
1411
                                        case to_integer(unsigned(IR(5 downto 4))) is
1412
                                        when 0|1|2 =>
1413
                                                Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1414
                                                Set_BusB_To(0) <= '0';
1415
                                        when others =>
1416
                                                Set_BusB_To <= "1001";
1417
                                        end case;
1418
                                        TStates <= "011";
1419
                                when others =>
1420
                                end case;
1421
                        when "01000010"|"01010010"|"01100010"|"01110010" =>
1422
                                -- SBC HL,ss
1423
                                MCycles <= "011";
1424
                                case to_integer(unsigned(MCycle)) is
1425
                                when 2 =>
1426 25 jesus
                                        NoRead <= '1';
1427 7 jesus
                                        ALU_Op <= "1011";
1428
                                        Read_To_Reg <= '1';
1429
                                        Save_ALU <= '1';
1430
                                        Set_BusA_To(2 downto 0) <= "101";
1431
                                        case to_integer(unsigned(IR(5 downto 4))) is
1432
                                        when 0|1|2 =>
1433
                                                Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1434
                                                Set_BusB_To(0) <= '1';
1435
                                        when others =>
1436
                                                Set_BusB_To <= "1000";
1437
                                        end case;
1438
                                when 3 =>
1439 25 jesus
                                        NoRead <= '1';
1440 7 jesus
                                        ALU_Op <= "1011";
1441
                                        Read_To_Reg <= '1';
1442
                                        Save_ALU <= '1';
1443
                                        Set_BusA_To(2 downto 0) <= "100";
1444
                                        case to_integer(unsigned(IR(5 downto 4))) is
1445
                                        when 0|1|2 =>
1446
                                                Set_BusB_To(2 downto 1) <= IR(5 downto 4);
1447
                                        when others =>
1448
                                                        Set_BusB_To <= "1001";
1449
                                        end case;
1450
                                        TStates <= "011";
1451
                                when others =>
1452
                                end case;
1453
                        when "01101111" =>
1454
                                -- RLD
1455
                                MCycles <= "100";
1456
                                case to_integer(unsigned(MCycle)) is
1457
                                when 2 =>
1458 25 jesus
                                        NoRead <= '1';
1459 7 jesus
                                        Set_Addr_To <= aXY;
1460
                                when 3 =>
1461
                                        Read_To_Reg <= '1';
1462
                                        Set_BusB_To(2 downto 0) <= "110";
1463
                                        Set_BusA_To(2 downto 0) <= "111";
1464
                                        ALU_Op <= "1101";
1465
                                        TStates <= "100";
1466
                                        Set_Addr_To <= aXY;
1467
                                        Save_ALU <= '1';
1468
                                when 4 =>
1469
                                        I_RLD <= '1';
1470
                                        Write <= '1';
1471
                                when others =>
1472
                                end case;
1473
                        when "01100111" =>
1474
                                -- RRD
1475
                                MCycles <= "100";
1476
                                case to_integer(unsigned(MCycle)) is
1477
                                when 2 =>
1478
                                        Set_Addr_To <= aXY;
1479
                                when 3 =>
1480
                                        Read_To_Reg <= '1';
1481
                                        Set_BusB_To(2 downto 0) <= "110";
1482
                                        Set_BusA_To(2 downto 0) <= "111";
1483
                                        ALU_Op <= "1110";
1484
                                        TStates <= "100";
1485
                                        Set_Addr_To <= aXY;
1486
                                        Save_ALU <= '1';
1487
                                when 4 =>
1488
                                        I_RRD <= '1';
1489
                                        Write <= '1';
1490
                                when others =>
1491
                                end case;
1492
                        when "01000101"|"01001101"|"01010101"|"01011101"|"01100101"|"01101101"|"01110101"|"01111101" =>
1493
                                -- RETI, RETN
1494
                                MCycles <= "011";
1495
                                case to_integer(unsigned(MCycle)) is
1496
                                when 1 =>
1497
                                        Set_Addr_TO <= aSP;
1498
                                when 2 =>
1499
                                        IncDec_16 <= "0111";
1500
                                        Set_Addr_To <= aSP;
1501
                                        LDZ <= '1';
1502
                                when 3 =>
1503
                                        Jump <= '1';
1504
                                        IncDec_16 <= "0111";
1505
                                        I_RETN <= '1';
1506
                                when others => null;
1507
                                end case;
1508
                        when "01000000"|"01001000"|"01010000"|"01011000"|"01100000"|"01101000"|"01110000"|"01111000" =>
1509
                                -- IN r,(C)
1510
                                MCycles <= "010";
1511
                                case to_integer(unsigned(MCycle)) is
1512
                                when 1 =>
1513
                                        Set_Addr_To <= aBC;
1514
                                when 2 =>
1515
                                        IORQ <= '1';
1516
                                        if IR(5 downto 3) /= "110" then
1517
                                                Read_To_Reg <= '1';
1518
                                                Set_BusA_To(2 downto 0) <= IR(5 downto 3);
1519
                                        end if;
1520
                                        I_INRC <= '1';
1521
                                when others =>
1522
                                end case;
1523
                        when "01000001"|"01001001"|"01010001"|"01011001"|"01100001"|"01101001"|"01110001"|"01111001" =>
1524
                                -- OUT (C),r
1525
                                -- OUT (C),0
1526
                                MCycles <= "010";
1527
                                case to_integer(unsigned(MCycle)) is
1528
                                when 1 =>
1529
                                        Set_Addr_To <= aBC;
1530
                                        Set_BusB_To(2 downto 0)  <= IR(5 downto 3);
1531
                                        if IR(5 downto 3) = "110" then
1532
                                                Set_BusB_To(3) <= '1';
1533
                                        end if;
1534
                                when 2 =>
1535
                                        Write <= '1';
1536
                                        IORQ <= '1';
1537
                                when others =>
1538
                                end case;
1539
                        when "10100010" | "10101010" | "10110010" | "10111010" =>
1540
                                -- INI, IND, INIR, INDR
1541
                                MCycles <= "011";
1542
                                case to_integer(unsigned(MCycle)) is
1543
                                when 1 =>
1544
                                        TStates <= "101";
1545
                                        Set_Addr_To <= aBC;
1546
                                        Set_BusB_To <= "1010";
1547
                                        Set_BusA_To <= "0000";
1548
                                        Read_To_Reg <= '1';
1549
                                        Save_ALU <= '1';
1550
                                        ALU_Op <= "1010";
1551
                                when 2 =>
1552
                                        IORQ <= '1';
1553
                                        Set_BusB_To <= "0110";
1554
                                        Set_Addr_To <= aXY;
1555
                                when 3 =>
1556
                                        if IR(3) = '0' then
1557
                                                IncDec_16 <= "0010";
1558
                                        else
1559
                                                IncDec_16 <= "1010";
1560
                                        end if;
1561
                                        TStates <= "100";
1562
                                        Write <= '1';
1563
                                        if IR(4) = '1' and F(6) = '0' then
1564
                                                MCycles <= "100";
1565
                                        end if;
1566
                                when 4 =>
1567 25 jesus
                                        NoRead <= '1';
1568 7 jesus
                                        I_BTR <= '1';
1569
                                        TStates <= "101";
1570
                                        MCycles <= "100";
1571
                                when others => null;
1572
                                end case;
1573
                        when "10100011" | "10101011" | "10110011" | "10111011" =>
1574
                                -- OUTI, OUTD, OTIR, OTDR
1575
                                MCycles <= "011";
1576
                                case to_integer(unsigned(MCycle)) is
1577
                                when 1 =>
1578
                                        TStates <= "101";
1579
                                        Set_Addr_To <= aXY;
1580
                                        Set_BusB_To <= "1010";
1581
                                        Set_BusA_To <= "0000";
1582
                                        Read_To_Reg <= '1';
1583
                                        Save_ALU <= '1';
1584
                                        ALU_Op <= "1010";
1585
                                when 2 =>
1586
                                        Set_BusB_To <= "0110";
1587
                                        Set_Addr_To <= aBC;
1588
                                when 3 =>
1589
                                        if IR(3) = '0' then
1590
                                                IncDec_16 <= "0010";
1591
                                        else
1592
                                                IncDec_16 <= "1010";
1593
                                        end if;
1594
                                        IORQ <= '1';
1595
                                        TStates <= "100";
1596
                                        Write <= '1';
1597
                                        if IR(4) = '1' and F(6) = '0' then
1598
                                                MCycles <= "100";
1599
                                        end if;
1600
                                when 4 =>
1601 25 jesus
                                        NoRead <= '1';
1602 7 jesus
                                        I_BTR <= '1';
1603
                                        TStates <= "101";
1604
                                        MCycles <= "100";
1605
                                when others => null;
1606
                                end case;
1607
                        end case;
1608
 
1609
                end case;
1610
 
1611
                if Mode = 1 then
1612
                        if MCycle = "001" then
1613
--                              TStates <= "100";
1614
                        else
1615
                                TStates <= "011";
1616
                        end if;
1617
                end if;
1618
 
1619
        end process;
1620
 
1621
end;

powered by: WebSVN 2.1.0

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