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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc1/] [rtl/] [core/] [tv80_mcode.v] - Blame information for rev 23

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

Line No. Rev Author Line
1 2 ghutchis
//
2
// TV80 8-Bit Microprocessor Core
3
// Based on the VHDL T80 core by Daniel Wallner (jesus@opencores.org)
4
//
5
// Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a 
8
// copy of this software and associated documentation files (the "Software"), 
9
// to deal in the Software without restriction, including without limitation 
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
11
// and/or sell copies of the Software, and to permit persons to whom the 
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included 
15
// in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
19
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
20
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
21
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
22
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
23
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
25
module tv80_mcode (/*AUTOARG*/
26
  // Outputs
27
  MCycles, TStates, Prefix, Inc_PC, Inc_WZ, IncDec_16, Read_To_Reg,
28
  Read_To_Acc, Set_BusA_To, Set_BusB_To, ALU_Op, Save_ALU, PreserveC,
29
  Arith16, Set_Addr_To, IORQ, Jump, JumpE, JumpXY, Call, RstP, LDZ,
30
  LDW, LDSPHL, Special_LD, ExchangeDH, ExchangeRp, ExchangeAF,
31
  ExchangeRS, I_DJNZ, I_CPL, I_CCF, I_SCF, I_RETN, I_BT, I_BC, I_BTR,
32
  I_RLD, I_RRD, I_INRC, SetDI, SetEI, IMode, Halt, NoRead, Write,
33
  // Inputs
34
  IR, ISet, MCycle, F, NMICycle, IntCycle
35
  );
36
 
37
  parameter             Mode   = 0;
38
  parameter             Flag_C = 0;
39
  parameter             Flag_N = 1;
40
  parameter             Flag_P = 2;
41
  parameter             Flag_X = 3;
42
  parameter             Flag_H = 4;
43
  parameter             Flag_Y = 5;
44
  parameter             Flag_Z = 6;
45
  parameter             Flag_S = 7;
46
 
47
  input [7:0]           IR;
48
  input [1:0]           ISet                     ;
49 23 ghutchis
  input [6:0]           MCycle                   ;
50 2 ghutchis
  input [7:0]           F                        ;
51
  input                 NMICycle                ;
52
  input                 IntCycle                ;
53
  output [2:0]          MCycles                  ;
54
  output [2:0]          TStates                  ;
55
  output [1:0]          Prefix                   ; // None,BC,ED,DD/FD
56
  output                Inc_PC                  ;
57
  output                Inc_WZ                  ;
58
  output [3:0]          IncDec_16                ; // BC,DE,HL,SP   0 is inc
59
  output                Read_To_Reg             ;
60
  output                Read_To_Acc             ;
61
  output [3:0]          Set_BusA_To      ; // B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
62
  output [3:0]          Set_BusB_To      ; // B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
63
  output [3:0]          ALU_Op                   ;
64
  output                Save_ALU                ;
65
  output                PreserveC               ;
66
  output                Arith16                 ;
67
  output [2:0]          Set_Addr_To              ; // aNone,aXY,aIOA,aSP,aBC,aDE,aZI
68
  output                IORQ                    ;
69
  output                Jump                    ;
70
  output                JumpE                   ;
71
  output                JumpXY                  ;
72
  output                Call                    ;
73
  output                RstP                    ;
74
  output                LDZ                     ;
75
  output                LDW                     ;
76
  output                LDSPHL                  ;
77
  output [2:0]          Special_LD               ; // A,I;A,R;I,A;R,A;None
78
  output                ExchangeDH              ;
79
  output                ExchangeRp              ;
80
  output                ExchangeAF              ;
81
  output                ExchangeRS              ;
82
  output                I_DJNZ                  ;
83
  output                I_CPL                   ;
84
  output                I_CCF                   ;
85
  output                I_SCF                   ;
86
  output                I_RETN                  ;
87
  output                I_BT                    ;
88
  output                I_BC                    ;
89
  output                I_BTR                   ;
90
  output                I_RLD                   ;
91
  output                I_RRD                   ;
92
  output                I_INRC                  ;
93
  output                SetDI                   ;
94
  output                SetEI                   ;
95
  output [1:0]          IMode                    ;
96
  output                Halt                    ;
97
  output                NoRead                  ;
98
  output                Write   ;
99
 
100
  // regs
101
  reg [2:0]             MCycles                  ;
102
  reg [2:0]             TStates                  ;
103
  reg [1:0]             Prefix                   ; // None,BC,ED,DD/FD
104
  reg                   Inc_PC                  ;
105
  reg                   Inc_WZ                  ;
106
  reg [3:0]             IncDec_16                ; // BC,DE,HL,SP   0 is inc
107
  reg                   Read_To_Reg             ;
108
  reg                   Read_To_Acc             ;
109
  reg [3:0]             Set_BusA_To      ; // B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
110
  reg [3:0]             Set_BusB_To      ; // B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
111
  reg [3:0]             ALU_Op                   ;
112
  reg                   Save_ALU                ;
113
  reg                   PreserveC               ;
114
  reg                   Arith16                 ;
115
  reg [2:0]             Set_Addr_To              ; // aNone,aXY,aIOA,aSP,aBC,aDE,aZI
116
  reg                   IORQ                    ;
117
  reg                   Jump                    ;
118
  reg                   JumpE                   ;
119
  reg                   JumpXY                  ;
120
  reg                   Call                    ;
121
  reg                   RstP                    ;
122
  reg                   LDZ                     ;
123
  reg                   LDW                     ;
124
  reg                   LDSPHL                  ;
125
  reg [2:0]             Special_LD               ; // A,I;A,R;I,A;R,A;None
126
  reg                   ExchangeDH              ;
127
  reg                   ExchangeRp              ;
128
  reg                   ExchangeAF              ;
129
  reg                   ExchangeRS              ;
130
  reg                   I_DJNZ                  ;
131
  reg                   I_CPL                   ;
132
  reg                   I_CCF                   ;
133
  reg                   I_SCF                   ;
134
  reg                   I_RETN                  ;
135
  reg                   I_BT                    ;
136
  reg                   I_BC                    ;
137
  reg                   I_BTR                   ;
138
  reg                   I_RLD                   ;
139
  reg                   I_RRD                   ;
140
  reg                   I_INRC                  ;
141
  reg                   SetDI                   ;
142
  reg                   SetEI                   ;
143
  reg [1:0]             IMode                    ;
144
  reg                   Halt                    ;
145
  reg                   NoRead                  ;
146
  reg                   Write   ;
147
 
148
        parameter aNone = 3'b111;
149
        parameter aBC   = 3'b000;
150
        parameter aDE   = 3'b001;
151
        parameter aXY   = 3'b010;
152
        parameter aIOA  = 3'b100;
153
        parameter aSP   = 3'b101;
154
        parameter aZI   = 3'b110;
155
//      constant aNone  : std_logic_vector[2:0] = 3'b000;
156
//      constant aXY    : std_logic_vector[2:0] = 3'b001;
157
//      constant aIOA   : std_logic_vector[2:0] = 3'b010;
158
//      constant aSP    : std_logic_vector[2:0] = 3'b011;
159
//      constant aBC    : std_logic_vector[2:0] = 3'b100;
160
//      constant aDE    : std_logic_vector[2:0] = 3'b101;
161
//      constant aZI    : std_logic_vector[2:0] = 3'b110;
162
 
163
  function is_cc_true;
164
    input [7:0] F;
165
    input [2:0] cc;
166
    begin
167
      if (Mode == 3 )
168
        begin
169
          case (cc)
170
            3'b000  : is_cc_true = F[7] == 1'b0; // NZ
171
            3'b001  : is_cc_true = F[7] == 1'b1; // Z
172
            3'b010  : is_cc_true = F[4] == 1'b0; // NC
173
            3'b011  : is_cc_true = F[4] == 1'b1; // C
174
            3'b100  : is_cc_true = 0;
175
            3'b101  : is_cc_true = 0;
176
            3'b110  : is_cc_true = 0;
177
            3'b111  : is_cc_true = 0;
178
          endcase
179
        end
180
      else
181
        begin
182
          case (cc)
183
            3'b000  : is_cc_true = F[6] == 1'b0; // NZ
184
            3'b001  : is_cc_true = F[6] == 1'b1; // Z
185
            3'b010  : is_cc_true = F[0] == 1'b0; // NC
186
            3'b011  : is_cc_true = F[0] == 1'b1; // C
187
            3'b100  : is_cc_true = F[2] == 1'b0; // PO
188
            3'b101  : is_cc_true = F[2] == 1'b1; // PE
189
            3'b110  : is_cc_true = F[7] == 1'b0; // P
190
            3'b111  : is_cc_true = F[7] == 1'b1; // M
191
          endcase
192
        end
193
    end
194
  endfunction // is_cc_true
195
 
196
 
197
  reg [2:0] DDD;
198
  reg [2:0] SSS;
199
  reg [1:0] DPAIR;
200
  reg [7:0] IRB;
201
 
202
  always @ (/*AUTOSENSE*/F or IR or ISet or IntCycle or MCycle
203
            or NMICycle)
204
    begin
205
      DDD = IR[5:3];
206
      SSS = IR[2:0];
207
      DPAIR = IR[5:4];
208
      IRB = IR;
209
 
210
      MCycles = 3'b001;
211 21 ghutchis
      if (MCycle[0] )
212 2 ghutchis
        begin
213
          TStates = 3'b100;
214
        end
215
      else
216
        begin
217
          TStates = 3'b011;
218
        end
219
      Prefix = 2'b00;
220
      Inc_PC = 1'b0;
221
      Inc_WZ = 1'b0;
222
      IncDec_16 = 4'b0000;
223
      Read_To_Acc = 1'b0;
224
      Read_To_Reg = 1'b0;
225
      Set_BusB_To = 4'b0000;
226
      Set_BusA_To = 4'b0000;
227
      ALU_Op = { 1'b0, IR[5:3] };
228
      Save_ALU = 1'b0;
229
      PreserveC = 1'b0;
230
      Arith16 = 1'b0;
231
      IORQ = 1'b0;
232
      Set_Addr_To = aNone;
233
      Jump = 1'b0;
234
      JumpE = 1'b0;
235
      JumpXY = 1'b0;
236
      Call = 1'b0;
237
      RstP = 1'b0;
238
      LDZ = 1'b0;
239
      LDW = 1'b0;
240
      LDSPHL = 1'b0;
241
      Special_LD = 3'b000;
242
      ExchangeDH = 1'b0;
243
      ExchangeRp = 1'b0;
244
      ExchangeAF = 1'b0;
245
      ExchangeRS = 1'b0;
246
      I_DJNZ = 1'b0;
247
      I_CPL = 1'b0;
248
      I_CCF = 1'b0;
249
      I_SCF = 1'b0;
250
      I_RETN = 1'b0;
251
      I_BT = 1'b0;
252
      I_BC = 1'b0;
253
      I_BTR = 1'b0;
254
      I_RLD = 1'b0;
255
      I_RRD = 1'b0;
256
      I_INRC = 1'b0;
257
      SetDI = 1'b0;
258
      SetEI = 1'b0;
259
      IMode = 2'b11;
260
      Halt = 1'b0;
261
      NoRead = 1'b0;
262
      Write = 1'b0;
263
 
264
      case (ISet)
265
        2'b00  :
266
          begin
267
 
268
//----------------------------------------------------------------------------
269
//
270
//      Unprefixed instructions
271
//
272
//----------------------------------------------------------------------------
273
 
274
            case (IRB)
275
// 8 BIT LOAD GROUP
276
              8'b01000000,8'b01000001,8'b01000010,8'b01000011,8'b01000100,8'b01000101,8'b01000111,
277
              8'b01001000,8'b01001001,8'b01001010,8'b01001011,8'b01001100,8'b01001101,8'b01001111,
278
              8'b01010000,8'b01010001,8'b01010010,8'b01010011,8'b01010100,8'b01010101,8'b01010111,
279
              8'b01011000,8'b01011001,8'b01011010,8'b01011011,8'b01011100,8'b01011101,8'b01011111,
280
              8'b01100000,8'b01100001,8'b01100010,8'b01100011,8'b01100100,8'b01100101,8'b01100111,
281
              8'b01101000,8'b01101001,8'b01101010,8'b01101011,8'b01101100,8'b01101101,8'b01101111,
282
              8'b01111000,8'b01111001,8'b01111010,8'b01111011,8'b01111100,8'b01111101,8'b01111111 :
283
                begin
284
 
285
                  // LD r,r'
286
                  Set_BusB_To[2:0] = SSS;
287
                  ExchangeRp = 1'b1;
288
                  Set_BusA_To[2:0] = DDD;
289
                  Read_To_Reg = 1'b1;
290
                end // case: 8'b01000000,8'b01000001,8'b01000010,8'b01000011,8'b01000100,8'b01000101,8'b01000111,...
291
 
292
              8'b00000110,8'b00001110,8'b00010110,8'b00011110,8'b00100110,8'b00101110,8'b00111110  :
293
                begin
294
                  // LD r,n
295
                  MCycles = 3'b010;
296 23 ghutchis
                  if (MCycle[1])
297
                    begin
298
                      Inc_PC = 1'b1;
299
                      Set_BusA_To[2:0] = DDD;
300
                      Read_To_Reg = 1'b1;
301
                    end
302 2 ghutchis
                end // case: 8'b00000110,8'b00001110,8'b00010110,8'b00011110,8'b00100110,8'b00101110,8'b00111110
303
 
304
              8'b01000110,8'b01001110,8'b01010110,8'b01011110,8'b01100110,8'b01101110,8'b01111110  :
305
                  begin
306
                    // LD r,(HL)
307
                    MCycles = 3'b010;
308 23 ghutchis
                    if (MCycle[0])
309
                      Set_Addr_To = aXY;
310
                    if (MCycle[1])
311
                      begin
312
                        Set_BusA_To[2:0] = DDD;
313
                        Read_To_Reg = 1'b1;
314
                      end
315 2 ghutchis
                  end // case: 8'b01000110,8'b01001110,8'b01010110,8'b01011110,8'b01100110,8'b01101110,8'b01111110
316
 
317
              8'b01110000,8'b01110001,8'b01110010,8'b01110011,8'b01110100,8'b01110101,8'b01110111  :
318
                  begin
319
                    // LD (HL),r
320
                    MCycles = 3'b010;
321 23 ghutchis
                    if (MCycle[0])
322
                      begin
323
                        Set_Addr_To = aXY;
324
                        Set_BusB_To[2:0] = SSS;
325
                        Set_BusB_To[3] = 1'b0;
326
                      end
327
                    if (MCycle[1])
328
                      Write = 1'b1;
329 2 ghutchis
                  end // case: 8'b01110000,8'b01110001,8'b01110010,8'b01110011,8'b01110100,8'b01110101,8'b01110111
330
 
331
              8'b00110110  :
332
                  begin
333
                    // LD (HL),n
334
                    MCycles = 3'b011;
335 23 ghutchis
                    if (MCycle[1])
336
                      begin
337
                        Inc_PC = 1'b1;
338
                        Set_Addr_To = aXY;
339
                        Set_BusB_To[2:0] = SSS;
340
                        Set_BusB_To[3] = 1'b0;
341
                      end
342
                    if (MCycle[2])
343
                      Write = 1'b1;
344 2 ghutchis
                  end // case: 8'b00110110
345
 
346
              8'b00001010  :
347
                begin
348
                  // LD A,(BC)
349
                  MCycles = 3'b010;
350 23 ghutchis
                  if (MCycle[0])
351
                    Set_Addr_To = aBC;
352
                  if (MCycle[1])
353
                    Read_To_Acc = 1'b1;
354 2 ghutchis
                end // case: 8'b00001010
355
 
356
              8'b00011010  :
357
                begin
358
                  // LD A,(DE)
359
                  MCycles = 3'b010;
360 23 ghutchis
                  if (MCycle[0])
361
                    Set_Addr_To = aDE;
362
                  if (MCycle[1])
363
                    Read_To_Acc = 1'b1;
364 2 ghutchis
                end // case: 8'b00011010
365
 
366
              8'b00111010  :
367
                begin
368
                  if (Mode == 3 )
369
                    begin
370
                      // LDD A,(HL)
371
                      MCycles = 3'b010;
372 23 ghutchis
                      if (MCycle[0])
373
                        Set_Addr_To = aXY;
374
                      if (MCycle[1])
375
                        begin
376
                          Read_To_Acc = 1'b1;
377
                          IncDec_16 = 4'b1110;
378
                        end
379 2 ghutchis
                    end
380
                  else
381
                    begin
382
                      // LD A,(nn)
383
                      MCycles = 3'b100;
384 23 ghutchis
                      if (MCycle[1])
385
                        begin
386
                          Inc_PC = 1'b1;
387
                          LDZ = 1'b1;
388
                        end
389
                      if (MCycle[2])
390
                        begin
391
                          Set_Addr_To = aZI;
392
                          Inc_PC = 1'b1;
393
                        end
394
                      if (MCycle[3])
395
                        begin
396
                          Read_To_Acc = 1'b1;
397
                        end
398 2 ghutchis
                    end // else: !if(Mode == 3 )
399
                end // case: 8'b00111010
400
 
401
              8'b00000010  :
402
                begin
403
                  // LD (BC),A
404
                  MCycles = 3'b010;
405 23 ghutchis
                  if (MCycle[0])
406
                    begin
407
                      Set_Addr_To = aBC;
408
                      Set_BusB_To = 4'b0111;
409
                    end
410
                  if (MCycle[1])
411
                    begin
412
                      Write = 1'b1;
413
                    end
414 2 ghutchis
                end // case: 8'b00000010
415
 
416
              8'b00010010  :
417
                begin
418
                  // LD (DE),A
419
                  MCycles = 3'b010;
420 23 ghutchis
                  case (1'b1) // MCycle
421
                    MCycle[0] :
422 2 ghutchis
                      begin
423
                        Set_Addr_To = aDE;
424
                        Set_BusB_To = 4'b0111;
425
                      end
426 23 ghutchis
                    MCycle[1] :
427 2 ghutchis
                      Write = 1'b1;
428
                    default :;
429
                  endcase // case(MCycle)
430
                end // case: 8'b00010010
431
 
432
              8'b00110010  :
433
                begin
434
                  if (Mode == 3 )
435
                    begin
436
                      // LDD (HL),A
437
                      MCycles = 3'b010;
438 23 ghutchis
                      case (1'b1) // MCycle
439
                        MCycle[0] :
440 2 ghutchis
                          begin
441
                            Set_Addr_To = aXY;
442
                            Set_BusB_To = 4'b0111;
443
                          end
444 23 ghutchis
                        MCycle[1] :
445 2 ghutchis
                          begin
446
                            Write = 1'b1;
447
                            IncDec_16 = 4'b1110;
448
                          end
449
                        default :;
450
                      endcase // case(MCycle)
451
 
452
                    end
453
                  else
454
                    begin
455
                      // LD (nn),A
456
                      MCycles = 3'b100;
457 23 ghutchis
                      case (1'b1) // MCycle
458
                        MCycle[1] :
459 2 ghutchis
                          begin
460
                            Inc_PC = 1'b1;
461
                            LDZ = 1'b1;
462
                          end
463 23 ghutchis
                        MCycle[2] :
464 2 ghutchis
                          begin
465
                            Set_Addr_To = aZI;
466
                            Inc_PC = 1'b1;
467
                            Set_BusB_To = 4'b0111;
468
                          end
469 23 ghutchis
                        MCycle[3] :
470 2 ghutchis
                          begin
471
                            Write = 1'b1;
472
                          end
473
                        default :;
474
                      endcase
475
                    end // else: !if(Mode == 3 )
476
                end // case: 8'b00110010
477
 
478
 
479
// 16 BIT LOAD GROUP
480
              8'b00000001,8'b00010001,8'b00100001,8'b00110001  :
481
                begin
482
                  // LD dd,nn
483
                  MCycles = 3'b011;
484 23 ghutchis
                  case (1'b1) // MCycle
485
                    MCycle[1] :
486 2 ghutchis
                      begin
487
                        Inc_PC = 1'b1;
488
                        Read_To_Reg = 1'b1;
489
                        if (DPAIR == 2'b11 )
490
                          begin
491
                            Set_BusA_To[3:0] = 4'b1000;
492
                          end
493
                        else
494
                          begin
495
                            Set_BusA_To[2:1] = DPAIR;
496
                            Set_BusA_To[0] = 1'b1;
497
                          end
498
                      end // case: 2
499
 
500 23 ghutchis
                    MCycle[2] :
501 2 ghutchis
                      begin
502
                        Inc_PC = 1'b1;
503
                        Read_To_Reg = 1'b1;
504
                        if (DPAIR == 2'b11 )
505
                          begin
506
                            Set_BusA_To[3:0] = 4'b1001;
507
                          end
508
                        else
509
                          begin
510
                            Set_BusA_To[2:1] = DPAIR;
511
                            Set_BusA_To[0] = 1'b0;
512
                          end
513
                      end // case: 3
514
 
515
                    default :;
516
                  endcase // case(MCycle)
517
                end // case: 8'b00000001,8'b00010001,8'b00100001,8'b00110001
518
 
519
              8'b00101010  :
520
                begin
521
                  if (Mode == 3 )
522
                    begin
523
                      // LDI A,(HL)
524
                      MCycles = 3'b010;
525 23 ghutchis
                      case (1'b1) // MCycle
526
                        MCycle[0] :
527 2 ghutchis
                          Set_Addr_To = aXY;
528 23 ghutchis
                        MCycle[1] :
529 2 ghutchis
                          begin
530
                            Read_To_Acc = 1'b1;
531
                            IncDec_16 = 4'b0110;
532
                          end
533
 
534
                        default :;
535
                      endcase
536
                    end
537
                  else
538
                    begin
539
                      // LD HL,(nn)
540
                      MCycles = 3'b101;
541 23 ghutchis
                      case (1'b1) // MCycle
542
                        MCycle[1] :
543 2 ghutchis
                          begin
544
                            Inc_PC = 1'b1;
545
                            LDZ = 1'b1;
546
                          end
547 23 ghutchis
                        MCycle[2] :
548 2 ghutchis
                          begin
549
                            Set_Addr_To = aZI;
550
                            Inc_PC = 1'b1;
551
                            LDW = 1'b1;
552
                          end
553 23 ghutchis
                        MCycle[3] :
554 2 ghutchis
                          begin
555
                            Set_BusA_To[2:0] = 3'b101; // L
556
                            Read_To_Reg = 1'b1;
557
                            Inc_WZ = 1'b1;
558
                            Set_Addr_To = aZI;
559
                          end
560 23 ghutchis
                        MCycle[4] :
561 2 ghutchis
                          begin
562
                            Set_BusA_To[2:0] = 3'b100; // H
563
                            Read_To_Reg = 1'b1;
564
                          end
565
                        default :;
566
                      endcase
567
                    end // else: !if(Mode == 3 )
568
                end // case: 8'b00101010
569
 
570
              8'b00100010  :
571
                begin
572
                  if (Mode == 3 )
573
                    begin
574
                      // LDI (HL),A
575
                      MCycles = 3'b010;
576 23 ghutchis
                      case (1'b1) // MCycle
577
                        MCycle[0] :
578 2 ghutchis
                          begin
579
                            Set_Addr_To = aXY;
580
                            Set_BusB_To = 4'b0111;
581
                          end
582 23 ghutchis
                        MCycle[1] :
583 2 ghutchis
                          begin
584
                            Write = 1'b1;
585
                            IncDec_16 = 4'b0110;
586
                          end
587
                        default :;
588
                      endcase
589
                    end
590
                  else
591
                    begin
592
                      // LD (nn),HL
593
                      MCycles = 3'b101;
594 23 ghutchis
                      case (1'b1) // MCycle                        
595
                        MCycle[1] :
596 2 ghutchis
                          begin
597
                            Inc_PC = 1'b1;
598
                            LDZ = 1'b1;
599
                          end
600
 
601 23 ghutchis
                        MCycle[2] :
602 2 ghutchis
                          begin
603
                            Set_Addr_To = aZI;
604
                            Inc_PC = 1'b1;
605
                            LDW = 1'b1;
606
                            Set_BusB_To = 4'b0101; // L
607
                          end
608
 
609 23 ghutchis
                        MCycle[3] :
610 2 ghutchis
                          begin
611
                            Inc_WZ = 1'b1;
612
                            Set_Addr_To = aZI;
613
                            Write = 1'b1;
614
                            Set_BusB_To = 4'b0100; // H
615
                          end
616 23 ghutchis
                        MCycle[4] :
617 2 ghutchis
                          Write = 1'b1;
618
                        default :;
619
                      endcase
620
                    end // else: !if(Mode == 3 )
621
                end // case: 8'b00100010
622
 
623
                8'b11111001  :
624
                  begin
625
                    // LD SP,HL
626
                    TStates = 3'b110;
627
                    LDSPHL = 1'b1;
628
                  end
629
 
630
              8'b11000101,8'b11010101,8'b11100101,8'b11110101  :
631
                begin
632
                  // PUSH qq
633
                  MCycles = 3'b011;
634 23 ghutchis
                  case (1'b1) // MCycle                    
635
                    MCycle[0] :
636 2 ghutchis
                      begin
637
                        TStates = 3'b101;
638
                        IncDec_16 = 4'b1111;
639
                        Set_Addr_To = aSP;
640
                        if (DPAIR == 2'b11 )
641
                          begin
642
                            Set_BusB_To = 4'b0111;
643
                          end
644
                        else
645
                          begin
646
                            Set_BusB_To[2:1] = DPAIR;
647
                            Set_BusB_To[0] = 1'b0;
648
                            Set_BusB_To[3] = 1'b0;
649
                          end
650
                      end // case: 1
651
 
652 23 ghutchis
                    MCycle[1] :
653 2 ghutchis
                      begin
654
                        IncDec_16 = 4'b1111;
655
                        Set_Addr_To = aSP;
656
                        if (DPAIR == 2'b11 )
657
                          begin
658
                            Set_BusB_To = 4'b1011;
659
                          end
660
                        else
661
                          begin
662
                            Set_BusB_To[2:1] = DPAIR;
663
                            Set_BusB_To[0] = 1'b1;
664
                            Set_BusB_To[3] = 1'b0;
665
                          end
666
                        Write = 1'b1;
667
                      end // case: 2
668
 
669 23 ghutchis
                    MCycle[2] :
670 2 ghutchis
                      Write = 1'b1;
671
                    default :;
672
                  endcase // case(MCycle)
673
                end // case: 8'b11000101,8'b11010101,8'b11100101,8'b11110101
674
 
675
              8'b11000001,8'b11010001,8'b11100001,8'b11110001  :
676
                begin
677
                  // POP qq
678
                  MCycles = 3'b011;
679 23 ghutchis
                  case (1'b1) // MCycle
680
                    MCycle[0] :
681 2 ghutchis
                      Set_Addr_To = aSP;
682 23 ghutchis
                    MCycle[1] :
683 2 ghutchis
                      begin
684
                        IncDec_16 = 4'b0111;
685
                        Set_Addr_To = aSP;
686
                        Read_To_Reg = 1'b1;
687
                        if (DPAIR == 2'b11 )
688
                          begin
689
                            Set_BusA_To[3:0] = 4'b1011;
690
                          end
691
                        else
692
                          begin
693
                            Set_BusA_To[2:1] = DPAIR;
694
                            Set_BusA_To[0] = 1'b1;
695
                          end
696
                      end // case: 2
697
 
698 23 ghutchis
                    MCycle[2] :
699 2 ghutchis
                      begin
700
                        IncDec_16 = 4'b0111;
701
                        Read_To_Reg = 1'b1;
702
                        if (DPAIR == 2'b11 )
703
                          begin
704
                            Set_BusA_To[3:0] = 4'b0111;
705
                          end
706
                        else
707
                          begin
708
                            Set_BusA_To[2:1] = DPAIR;
709
                            Set_BusA_To[0] = 1'b0;
710
                          end
711
                      end // case: 3
712
 
713
                    default :;
714
                  endcase // case(MCycle)
715
                end // case: 8'b11000001,8'b11010001,8'b11100001,8'b11110001
716
 
717
 
718
// EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
719
              8'b11101011  :
720
                begin
721
                  if (Mode != 3 )
722
                    begin
723
                      // EX DE,HL
724
                      ExchangeDH = 1'b1;
725
                    end
726
                end
727
 
728
              8'b00001000  :
729
                begin
730
                  if (Mode == 3 )
731
                    begin
732
                      // LD (nn),SP
733
                      MCycles = 3'b101;
734 23 ghutchis
                      case (1'b1) // MCycle
735
                        MCycle[1] :
736 2 ghutchis
                          begin
737
                            Inc_PC = 1'b1;
738
                            LDZ = 1'b1;
739
                          end
740
 
741 23 ghutchis
                        MCycle[2] :
742 2 ghutchis
                          begin
743
                            Set_Addr_To = aZI;
744
                            Inc_PC = 1'b1;
745
                            LDW = 1'b1;
746
                            Set_BusB_To = 4'b1000;
747
                          end
748
 
749 23 ghutchis
                        MCycle[3] :
750 2 ghutchis
                          begin
751
                            Inc_WZ = 1'b1;
752
                            Set_Addr_To = aZI;
753
                            Write = 1'b1;
754
                            Set_BusB_To = 4'b1001;
755
                          end
756
 
757 23 ghutchis
                        MCycle[4] :
758 2 ghutchis
                          Write = 1'b1;
759
                        default :;
760
                      endcase
761
                    end
762
                  else if (Mode < 2 )
763
                    begin
764
                      // EX AF,AF'
765
                      ExchangeAF = 1'b1;
766
                    end
767
                end // case: 8'b00001000
768
 
769
              8'b11011001  :
770
                begin
771
                  if (Mode == 3 )
772
                    begin
773
                      // RETI
774
                      MCycles = 3'b011;
775 23 ghutchis
                      case (1'b1) // MCycle
776
                        MCycle[0] :
777 2 ghutchis
                          Set_Addr_To = aSP;
778 23 ghutchis
                        MCycle[1] :
779 2 ghutchis
                          begin
780
                            IncDec_16 = 4'b0111;
781
                            Set_Addr_To = aSP;
782
                            LDZ = 1'b1;
783
                          end
784
 
785 23 ghutchis
                        MCycle[2] :
786 2 ghutchis
                          begin
787
                            Jump = 1'b1;
788
                            IncDec_16 = 4'b0111;
789
                            I_RETN = 1'b1;
790
                            SetEI = 1'b1;
791
                          end
792
                        default :;
793
                      endcase
794
                    end
795
                  else if (Mode < 2 )
796
                    begin
797
                      // EXX
798
                      ExchangeRS = 1'b1;
799
                    end
800
                end // case: 8'b11011001
801
 
802
              8'b11100011  :
803
                begin
804
                  if (Mode != 3 )
805
                    begin
806
                      // EX (SP),HL
807
                      MCycles = 3'b101;
808 23 ghutchis
                      case (1'b1) // MCycle
809
                        MCycle[0] :
810 2 ghutchis
                          Set_Addr_To = aSP;
811 23 ghutchis
                        MCycle[1] :
812 2 ghutchis
                          begin
813
                            Read_To_Reg = 1'b1;
814
                            Set_BusA_To = 4'b0101;
815
                            Set_BusB_To = 4'b0101;
816
                            Set_Addr_To = aSP;
817
                          end
818 23 ghutchis
                        MCycle[2] :
819 2 ghutchis
                          begin
820
                            IncDec_16 = 4'b0111;
821
                            Set_Addr_To = aSP;
822
                            TStates = 3'b100;
823
                            Write = 1'b1;
824
                          end
825 23 ghutchis
                        MCycle[3] :
826 2 ghutchis
                          begin
827
                            Read_To_Reg = 1'b1;
828
                            Set_BusA_To = 4'b0100;
829
                            Set_BusB_To = 4'b0100;
830
                            Set_Addr_To = aSP;
831
                          end
832 23 ghutchis
                        MCycle[4] :
833 2 ghutchis
                          begin
834
                            IncDec_16 = 4'b1111;
835
                            TStates = 3'b101;
836
                            Write = 1'b1;
837
                          end
838
 
839
                        default :;
840
                      endcase
841
                    end // if (Mode != 3 )
842
                end // case: 8'b11100011
843
 
844
 
845
// 8 BIT ARITHMETIC AND LOGICAL GROUP
846
              8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,
847
              8'b10001000,8'b10001001,8'b10001010,8'b10001011,8'b10001100,8'b10001101,8'b10001111,
848
              8'b10010000,8'b10010001,8'b10010010,8'b10010011,8'b10010100,8'b10010101,8'b10010111,
849
              8'b10011000,8'b10011001,8'b10011010,8'b10011011,8'b10011100,8'b10011101,8'b10011111,
850
              8'b10100000,8'b10100001,8'b10100010,8'b10100011,8'b10100100,8'b10100101,8'b10100111,
851
              8'b10101000,8'b10101001,8'b10101010,8'b10101011,8'b10101100,8'b10101101,8'b10101111,
852
              8'b10110000,8'b10110001,8'b10110010,8'b10110011,8'b10110100,8'b10110101,8'b10110111,
853
              8'b10111000,8'b10111001,8'b10111010,8'b10111011,8'b10111100,8'b10111101,8'b10111111 :
854
                begin
855
                  // ADD A,r
856
                  // ADC A,r
857
                  // SUB A,r
858
                  // SBC A,r
859
                  // AND A,r
860
                  // OR A,r
861
                  // XOR A,r
862
                  // CP A,r
863
                  Set_BusB_To[2:0] = SSS;
864
                  Set_BusA_To[2:0] = 3'b111;
865
                  Read_To_Reg = 1'b1;
866
                  Save_ALU = 1'b1;
867
                end // case: 8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,...
868
 
869
              8'b10000110,8'b10001110,8'b10010110,8'b10011110,8'b10100110,8'b10101110,8'b10110110,8'b10111110  :
870
                begin
871
                  // ADD A,(HL)
872
                  // ADC A,(HL)
873
                  // SUB A,(HL)
874
                  // SBC A,(HL)
875
                  // AND A,(HL)
876
                  // OR A,(HL)
877
                  // XOR A,(HL)
878
                  // CP A,(HL)
879
                  MCycles = 3'b010;
880 23 ghutchis
                  case (1'b1) // MCycle
881
                    MCycle[0] :
882 2 ghutchis
                      Set_Addr_To = aXY;
883 23 ghutchis
                    MCycle[1] :
884 2 ghutchis
                      begin
885
                        Read_To_Reg = 1'b1;
886
                        Save_ALU = 1'b1;
887
                        Set_BusB_To[2:0] = SSS;
888
                        Set_BusA_To[2:0] = 3'b111;
889
                      end
890
 
891
                    default :;
892
                  endcase // case(MCycle)
893
                end // case: 8'b10000110,8'b10001110,8'b10010110,8'b10011110,8'b10100110,8'b10101110,8'b10110110,8'b10111110
894
 
895
              8'b11000110,8'b11001110,8'b11010110,8'b11011110,8'b11100110,8'b11101110,8'b11110110,8'b11111110  :
896
                begin
897
                  // ADD A,n
898
                  // ADC A,n
899
                  // SUB A,n
900
                  // SBC A,n
901
                  // AND A,n
902
                  // OR A,n
903
                  // XOR A,n
904
                  // CP A,n
905
                  MCycles = 3'b010;
906 21 ghutchis
                  if (MCycle[1] )
907 2 ghutchis
                    begin
908
                      Inc_PC = 1'b1;
909
                      Read_To_Reg = 1'b1;
910
                      Save_ALU = 1'b1;
911
                      Set_BusB_To[2:0] = SSS;
912
                      Set_BusA_To[2:0] = 3'b111;
913
                    end
914
                end // case: 8'b11000110,8'b11001110,8'b11010110,8'b11011110,8'b11100110,8'b11101110,8'b11110110,8'b11111110
915
 
916
              8'b00000100,8'b00001100,8'b00010100,8'b00011100,8'b00100100,8'b00101100,8'b00111100  :
917
                begin
918
                  // INC r
919
                  Set_BusB_To = 4'b1010;
920
                  Set_BusA_To[2:0] = DDD;
921
                  Read_To_Reg = 1'b1;
922
                  Save_ALU = 1'b1;
923
                  PreserveC = 1'b1;
924
                  ALU_Op = 4'b0000;
925
                end
926
 
927
              8'b00110100  :
928
                begin
929
                  // INC (HL)
930
                  MCycles = 3'b011;
931 23 ghutchis
                  case (1'b1) // MCycle
932
                    MCycle[0] :
933 2 ghutchis
                      Set_Addr_To = aXY;
934 23 ghutchis
                    MCycle[1] :
935 2 ghutchis
                      begin
936
                        TStates = 3'b100;
937
                        Set_Addr_To = aXY;
938
                        Read_To_Reg = 1'b1;
939
                        Save_ALU = 1'b1;
940
                        PreserveC = 1'b1;
941
                        ALU_Op = 4'b0000;
942
                        Set_BusB_To = 4'b1010;
943
                        Set_BusA_To[2:0] = DDD;
944
                      end // case: 2
945
 
946 23 ghutchis
                    MCycle[2] :
947 2 ghutchis
                      Write = 1'b1;
948
                    default :;
949
                  endcase // case(MCycle)
950
                end // case: 8'b00110100
951
 
952
              8'b00000101,8'b00001101,8'b00010101,8'b00011101,8'b00100101,8'b00101101,8'b00111101  :
953
                begin
954
                  // DEC r
955
                  Set_BusB_To = 4'b1010;
956
                  Set_BusA_To[2:0] = DDD;
957
                  Read_To_Reg = 1'b1;
958
                  Save_ALU = 1'b1;
959
                  PreserveC = 1'b1;
960
                  ALU_Op = 4'b0010;
961
                end
962
 
963
              8'b00110101  :
964
                begin
965
                  // DEC (HL)
966
                  MCycles = 3'b011;
967 23 ghutchis
                  case (1'b1) // MCycle
968
                    MCycle[0] :
969 2 ghutchis
                      Set_Addr_To = aXY;
970 23 ghutchis
                    MCycle[1] :
971 2 ghutchis
                      begin
972
                        TStates = 3'b100;
973
                        Set_Addr_To = aXY;
974
                        ALU_Op = 4'b0010;
975
                        Read_To_Reg = 1'b1;
976
                        Save_ALU = 1'b1;
977
                        PreserveC = 1'b1;
978
                        Set_BusB_To = 4'b1010;
979
                        Set_BusA_To[2:0] = DDD;
980
                      end // case: 2
981
 
982 23 ghutchis
                    MCycle[2] :
983 2 ghutchis
                      Write = 1'b1;
984
                    default :;
985
                  endcase // case(MCycle)
986
                end // case: 8'b00110101              
987
 
988
// GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
989
                8'b00100111  :
990
                  begin
991
                    // DAA
992
                    Set_BusA_To[2:0] = 3'b111;
993
                    Read_To_Reg = 1'b1;
994
                    ALU_Op = 4'b1100;
995
                    Save_ALU = 1'b1;
996
                  end
997
 
998
                8'b00101111  :
999
                  // CPL
1000
                  I_CPL = 1'b1;
1001
 
1002
                8'b00111111  :
1003
                  // CCF
1004
                  I_CCF = 1'b1;
1005
 
1006
                8'b00110111  :
1007
                  // SCF
1008
                  I_SCF = 1'b1;
1009
 
1010
                8'b00000000  :
1011
                  begin
1012
                    if (NMICycle == 1'b1 )
1013
                      begin
1014
                        // NMI
1015
                        MCycles = 3'b011;
1016 23 ghutchis
                        case (1'b1) // MCycle
1017
                          MCycle[0] :
1018 2 ghutchis
                            begin
1019
                              TStates = 3'b101;
1020
                              IncDec_16 = 4'b1111;
1021
                              Set_Addr_To = aSP;
1022
                              Set_BusB_To = 4'b1101;
1023
                            end
1024
 
1025 23 ghutchis
                          MCycle[1] :
1026 2 ghutchis
                            begin
1027
                              TStates = 3'b100;
1028
                              Write = 1'b1;
1029
                              IncDec_16 = 4'b1111;
1030
                              Set_Addr_To = aSP;
1031
                              Set_BusB_To = 4'b1100;
1032
                            end
1033
 
1034 23 ghutchis
                          MCycle[2] :
1035 2 ghutchis
                            begin
1036
                              TStates = 3'b100;
1037
                              Write = 1'b1;
1038
                            end
1039
 
1040
                          default :;
1041
                        endcase // case(MCycle)
1042
 
1043
                      end
1044
                    else if (IntCycle == 1'b1 )
1045
                      begin
1046
                        // INT (IM 2)
1047
                        MCycles = 3'b101;
1048 23 ghutchis
                        case (1'b1) // MCycle
1049
                          MCycle[0] :
1050 2 ghutchis
                            begin
1051
                              LDZ = 1'b1;
1052
                              TStates = 3'b101;
1053
                              IncDec_16 = 4'b1111;
1054
                              Set_Addr_To = aSP;
1055
                              Set_BusB_To = 4'b1101;
1056
                            end
1057
 
1058 23 ghutchis
                          MCycle[1] :
1059 2 ghutchis
                            begin
1060
                              TStates = 3'b100;
1061
                              Write = 1'b1;
1062
                              IncDec_16 = 4'b1111;
1063
                              Set_Addr_To = aSP;
1064
                              Set_BusB_To = 4'b1100;
1065
                            end
1066
 
1067 23 ghutchis
                          MCycle[2] :
1068 2 ghutchis
                            begin
1069
                              TStates = 3'b100;
1070
                              Write = 1'b1;
1071
                            end
1072
 
1073 23 ghutchis
                          MCycle[3] :
1074 2 ghutchis
                            begin
1075
                              Inc_PC = 1'b1;
1076
                              LDZ = 1'b1;
1077
                            end
1078
 
1079 23 ghutchis
                          MCycle[4] :
1080 2 ghutchis
                            Jump = 1'b1;
1081
                          default :;
1082
                        endcase
1083
                      end
1084
                  end // case: 8'b00000000
1085
 
1086
              8'b01110110  :
1087
                // HALT
1088
                Halt = 1'b1;
1089
 
1090
              8'b11110011  :
1091
                // DI
1092
                SetDI = 1'b1;
1093
 
1094
              8'b11111011  :
1095
                // EI
1096
                SetEI = 1'b1;
1097
 
1098
              // 16 BIT ARITHMETIC GROUP
1099
              8'b00001001,8'b00011001,8'b00101001,8'b00111001  :
1100
                begin
1101
                  // ADD HL,ss
1102
                  MCycles = 3'b011;
1103 23 ghutchis
                  case (1'b1) // MCycle
1104
                    MCycle[1] :
1105 2 ghutchis
                      begin
1106
                        NoRead = 1'b1;
1107
                        ALU_Op = 4'b0000;
1108
                        Read_To_Reg = 1'b1;
1109
                        Save_ALU = 1'b1;
1110
                        Set_BusA_To[2:0] = 3'b101;
1111
                        case (IR[5:4])
1112
                          0,1,2  :
1113
                            begin
1114
                              Set_BusB_To[2:1] = IR[5:4];
1115
                              Set_BusB_To[0] = 1'b1;
1116
                            end
1117
 
1118
                          default :
1119
                            Set_BusB_To = 4'b1000;
1120
                        endcase // case(IR[5:4])
1121
 
1122
                        TStates = 3'b100;
1123
                        Arith16 = 1'b1;
1124
                      end // case: 2
1125
 
1126 23 ghutchis
                    MCycle[2] :
1127 2 ghutchis
                      begin
1128
                        NoRead = 1'b1;
1129
                        Read_To_Reg = 1'b1;
1130
                        Save_ALU = 1'b1;
1131
                        ALU_Op = 4'b0001;
1132
                        Set_BusA_To[2:0] = 3'b100;
1133
                        case (IR[5:4])
1134
                          0,1,2  :
1135
                            Set_BusB_To[2:1] = IR[5:4];
1136
                          default :
1137
                            Set_BusB_To = 4'b1001;
1138
                        endcase
1139
                        Arith16 = 1'b1;
1140
                      end // case: 3
1141
 
1142
                    default :;
1143
                  endcase // case(MCycle)
1144
                end // case: 8'b00001001,8'b00011001,8'b00101001,8'b00111001              
1145
 
1146
              8'b00000011,8'b00010011,8'b00100011,8'b00110011  :
1147
                begin
1148
                  // INC ss
1149
                  TStates = 3'b110;
1150
                  IncDec_16[3:2] = 2'b01;
1151
                  IncDec_16[1:0] = DPAIR;
1152
                end
1153
 
1154
              8'b00001011,8'b00011011,8'b00101011,8'b00111011  :
1155
                begin
1156
                  // DEC ss
1157
                  TStates = 3'b110;
1158
                  IncDec_16[3:2] = 2'b11;
1159
                  IncDec_16[1:0] = DPAIR;
1160
                end
1161
 
1162
// ROTATE AND SHIFT GROUP
1163
              8'b00000111,
1164
                  // RLCA
1165
                  8'b00010111,
1166
                  // RLA
1167
                  8'b00001111,
1168
                  // RRCA
1169
                  8'b00011111 :
1170
                          // RRA
1171
                begin
1172
                  Set_BusA_To[2:0] = 3'b111;
1173
                  ALU_Op = 4'b1000;
1174
                  Read_To_Reg = 1'b1;
1175
                  Save_ALU = 1'b1;
1176
                end // case: 8'b00000111,...
1177
 
1178
 
1179
// JUMP GROUP
1180
              8'b11000011  :
1181
                begin
1182
                  // JP nn
1183
                  MCycles = 3'b011;
1184 23 ghutchis
                  if (MCycle[1])
1185 2 ghutchis
                      begin
1186
                        Inc_PC = 1'b1;
1187
                        LDZ = 1'b1;
1188
                      end
1189
 
1190 23 ghutchis
                  if (MCycle[2])
1191 2 ghutchis
                      begin
1192
                        Inc_PC = 1'b1;
1193
                        Jump = 1'b1;
1194
                      end
1195
 
1196
                end // case: 8'b11000011
1197
 
1198
              8'b11000010,8'b11001010,8'b11010010,8'b11011010,8'b11100010,8'b11101010,8'b11110010,8'b11111010  :
1199
                begin
1200
                  if (IR[5] == 1'b1 && Mode == 3 )
1201
                    begin
1202
                      case (IRB[4:3])
1203
                        2'b00  :
1204
                          begin
1205
                            // LD ($FF00+C),A
1206
                            MCycles = 3'b010;
1207 23 ghutchis
                            case (1'b1) // MCycle
1208
                              MCycle[0] :
1209 2 ghutchis
                                begin
1210
                                  Set_Addr_To = aBC;
1211
                                  Set_BusB_To   = 4'b0111;
1212
                                end
1213 23 ghutchis
                              MCycle[1] :
1214 2 ghutchis
                                begin
1215
                                  Write = 1'b1;
1216
                                  IORQ = 1'b1;
1217
                                end
1218
 
1219
                              default :;
1220
                            endcase // case(MCycle)
1221
                          end // case: 2'b00
1222
 
1223
                        2'b01  :
1224
                          begin
1225
                            // LD (nn),A
1226
                            MCycles = 3'b100;
1227 23 ghutchis
                            case (1'b1) // MCycle
1228
                              MCycle[1] :
1229 2 ghutchis
                                begin
1230
                                  Inc_PC = 1'b1;
1231
                                  LDZ = 1'b1;
1232
                                end
1233
 
1234 23 ghutchis
                              MCycle[2] :
1235 2 ghutchis
                                begin
1236
                                  Set_Addr_To = aZI;
1237
                                  Inc_PC = 1'b1;
1238
                                  Set_BusB_To = 4'b0111;
1239
                                end
1240
 
1241 23 ghutchis
                              MCycle[3] :
1242 2 ghutchis
                                Write = 1'b1;
1243
                              default :;
1244
                            endcase // case(MCycle)
1245
                          end // case: default :...
1246
 
1247
                        2'b10  :
1248
                          begin
1249
                            // LD A,($FF00+C)
1250
                            MCycles = 3'b010;
1251 23 ghutchis
                            case (1'b1) // MCycle
1252
                              MCycle[0] :
1253 2 ghutchis
                                Set_Addr_To = aBC;
1254 23 ghutchis
                              MCycle[1] :
1255 2 ghutchis
                                begin
1256
                                  Read_To_Acc = 1'b1;
1257
                                  IORQ = 1'b1;
1258
                                end
1259
                              default :;
1260
                            endcase // case(MCycle)
1261
                          end // case: 2'b10
1262
 
1263
                        2'b11  :
1264
                          begin
1265
                            // LD A,(nn)
1266
                            MCycles = 3'b100;
1267 23 ghutchis
                            case (1'b1) // MCycle
1268
                              MCycle[1] :
1269 2 ghutchis
                                begin
1270
                                  Inc_PC = 1'b1;
1271
                                  LDZ = 1'b1;
1272
                                end
1273 23 ghutchis
                              MCycle[2] :
1274 2 ghutchis
                                begin
1275
                                  Set_Addr_To = aZI;
1276
                                  Inc_PC = 1'b1;
1277
                                end
1278 23 ghutchis
                              MCycle[3] :
1279 2 ghutchis
                                Read_To_Acc = 1'b1;
1280
                              default :;
1281
                            endcase // case(MCycle)
1282
                          end
1283
                      endcase
1284
                    end
1285
                  else
1286
                    begin
1287
                      // JP cc,nn
1288
                      MCycles = 3'b011;
1289 23 ghutchis
                      case (1'b1) // MCycle
1290
                        MCycle[1] :
1291 2 ghutchis
                          begin
1292
                            Inc_PC = 1'b1;
1293
                            LDZ = 1'b1;
1294
                          end
1295 23 ghutchis
                        MCycle[2] :
1296 2 ghutchis
                          begin
1297
                            Inc_PC = 1'b1;
1298
                            if (is_cc_true(F, IR[5:3]) )
1299
                              begin
1300
                                Jump = 1'b1;
1301
                              end
1302
                          end
1303
 
1304
                        default :;
1305
                      endcase
1306
                    end // else: !if(DPAIR == 2'b11 )
1307
                end // case: 8'b11000010,8'b11001010,8'b11010010,8'b11011010,8'b11100010,8'b11101010,8'b11110010,8'b11111010
1308
 
1309
              8'b00011000  :
1310
                begin
1311
                  if (Mode != 2 )
1312
                    begin
1313
                      // JR e
1314
                      MCycles = 3'b011;
1315 23 ghutchis
                      case (1'b1) // MCycle
1316
                        MCycle[1] :
1317 2 ghutchis
                          Inc_PC = 1'b1;
1318 23 ghutchis
                        MCycle[2] :
1319 2 ghutchis
                          begin
1320
                            NoRead = 1'b1;
1321
                            JumpE = 1'b1;
1322
                            TStates = 3'b101;
1323
                          end
1324
                        default :;
1325
                      endcase
1326
                    end // if (Mode != 2 )
1327
                end // case: 8'b00011000
1328
 
1329
              8'b00111000  :
1330
                begin
1331
                  if (Mode != 2 )
1332
                    begin
1333
                      // JR C,e
1334
                      MCycles = 3'b011;
1335 23 ghutchis
                      case (1'b1) // MCycle
1336
                        MCycle[1] :
1337 2 ghutchis
                          begin
1338
                            Inc_PC = 1'b1;
1339
                            if (F[Flag_C] == 1'b0 )
1340
                              begin
1341
                                MCycles = 3'b010;
1342
                              end
1343
                          end
1344
 
1345 23 ghutchis
                        MCycle[2] :
1346 2 ghutchis
                          begin
1347
                            NoRead = 1'b1;
1348
                            JumpE = 1'b1;
1349
                            TStates = 3'b101;
1350
                          end
1351
                        default :;
1352
                      endcase
1353
                    end // if (Mode != 2 )
1354
                end // case: 8'b00111000
1355
 
1356
              8'b00110000  :
1357
                begin
1358
                  if (Mode != 2 )
1359
                    begin
1360
                      // JR NC,e
1361
                      MCycles = 3'b011;
1362 23 ghutchis
                      case (1'b1) // MCycle
1363
                        MCycle[1] :
1364 2 ghutchis
                          begin
1365
                            Inc_PC = 1'b1;
1366
                            if (F[Flag_C] == 1'b1 )
1367
                              begin
1368
                                MCycles = 3'b010;
1369
                              end
1370
                          end
1371
 
1372 23 ghutchis
                        MCycle[2] :
1373 2 ghutchis
                          begin
1374
                            NoRead = 1'b1;
1375
                            JumpE = 1'b1;
1376
                            TStates = 3'b101;
1377
                          end
1378
                        default :;
1379
                      endcase
1380
                    end // if (Mode != 2 )
1381
                end // case: 8'b00110000
1382
 
1383
              8'b00101000  :
1384
                begin
1385
                  if (Mode != 2 )
1386
                    begin
1387
                      // JR Z,e
1388
                      MCycles = 3'b011;
1389 23 ghutchis
                      case (1'b1) // MCycle
1390
                        MCycle[1] :
1391 2 ghutchis
                          begin
1392
                            Inc_PC = 1'b1;
1393
                            if (F[Flag_Z] == 1'b0 )
1394
                              begin
1395
                                MCycles = 3'b010;
1396
                              end
1397
                          end
1398
 
1399 23 ghutchis
                        MCycle[2] :
1400 2 ghutchis
                          begin
1401
                            NoRead = 1'b1;
1402
                            JumpE = 1'b1;
1403
                            TStates = 3'b101;
1404
                          end
1405
 
1406
                        default :;
1407
                      endcase
1408
                    end // if (Mode != 2 )
1409
                end // case: 8'b00101000
1410
 
1411
              8'b00100000  :
1412
                begin
1413
                  if (Mode != 2 )
1414
                    begin
1415
                      // JR NZ,e
1416
                      MCycles = 3'b011;
1417 23 ghutchis
                      case (1'b1) // MCycle
1418
                        MCycle[1] :
1419 2 ghutchis
                          begin
1420
                            Inc_PC = 1'b1;
1421
                            if (F[Flag_Z] == 1'b1 )
1422
                              begin
1423
                                MCycles = 3'b010;
1424
                              end
1425
                          end
1426 23 ghutchis
                        MCycle[2] :
1427 2 ghutchis
                          begin
1428
                            NoRead = 1'b1;
1429
                            JumpE = 1'b1;
1430
                            TStates = 3'b101;
1431
                          end
1432
                        default :;
1433
                      endcase
1434
                    end // if (Mode != 2 )
1435
                end // case: 8'b00100000
1436
 
1437
              8'b11101001  :
1438
                // JP (HL)
1439
                JumpXY = 1'b1;
1440
 
1441
              8'b00010000  :
1442
                begin
1443
                  if (Mode == 3 )
1444
                    begin
1445
                      I_DJNZ = 1'b1;
1446
                    end
1447
                  else if (Mode < 2 )
1448
                    begin
1449
                      // DJNZ,e
1450
                      MCycles = 3'b011;
1451 23 ghutchis
                      case (1'b1) // MCycle
1452
                        MCycle[0] :
1453 2 ghutchis
                          begin
1454
                            TStates = 3'b101;
1455
                            I_DJNZ = 1'b1;
1456
                            Set_BusB_To = 4'b1010;
1457
                            Set_BusA_To[2:0] = 3'b000;
1458
                            Read_To_Reg = 1'b1;
1459
                            Save_ALU = 1'b1;
1460
                            ALU_Op = 4'b0010;
1461
                          end
1462 23 ghutchis
                        MCycle[1] :
1463 2 ghutchis
                          begin
1464
                            I_DJNZ = 1'b1;
1465
                            Inc_PC = 1'b1;
1466
                          end
1467 23 ghutchis
                        MCycle[2] :
1468 2 ghutchis
                          begin
1469
                            NoRead = 1'b1;
1470
                            JumpE = 1'b1;
1471
                            TStates = 3'b101;
1472
                          end
1473
                        default :;
1474
                      endcase
1475
                    end // if (Mode < 2 )
1476
                end // case: 8'b00010000
1477
 
1478
 
1479
// CALL AND RETURN GROUP
1480
              8'b11001101  :
1481
                begin
1482
                  // CALL nn
1483
                  MCycles = 3'b101;
1484 23 ghutchis
                  case (1'b1) // MCycle
1485
                    MCycle[1] :
1486 2 ghutchis
                      begin
1487
                        Inc_PC = 1'b1;
1488
                        LDZ = 1'b1;
1489
                      end
1490 23 ghutchis
                    MCycle[2] :
1491 2 ghutchis
                      begin
1492
                        IncDec_16 = 4'b1111;
1493
                        Inc_PC = 1'b1;
1494
                        TStates = 3'b100;
1495
                        Set_Addr_To = aSP;
1496
                        LDW = 1'b1;
1497
                        Set_BusB_To = 4'b1101;
1498
                      end
1499 23 ghutchis
                    MCycle[3] :
1500 2 ghutchis
                      begin
1501
                        Write = 1'b1;
1502
                        IncDec_16 = 4'b1111;
1503
                        Set_Addr_To = aSP;
1504
                        Set_BusB_To = 4'b1100;
1505
                      end
1506 23 ghutchis
                    MCycle[4] :
1507 2 ghutchis
                      begin
1508
                        Write = 1'b1;
1509
                        Call = 1'b1;
1510
                      end
1511
                    default :;
1512
                  endcase // case(MCycle)
1513
                end // case: 8'b11001101
1514
 
1515
              8'b11000100,8'b11001100,8'b11010100,8'b11011100,8'b11100100,8'b11101100,8'b11110100,8'b11111100  :
1516
                begin
1517
                  if (IR[5] == 1'b0 || Mode != 3 )
1518
                    begin
1519
                      // CALL cc,nn
1520
                      MCycles = 3'b101;
1521 23 ghutchis
                      case (1'b1) // MCycle
1522
                        MCycle[1] :
1523 2 ghutchis
                          begin
1524
                            Inc_PC = 1'b1;
1525
                            LDZ = 1'b1;
1526
                          end
1527 23 ghutchis
                        MCycle[2] :
1528 2 ghutchis
                          begin
1529
                            Inc_PC = 1'b1;
1530
                            LDW = 1'b1;
1531
                            if (is_cc_true(F, IR[5:3]) )
1532
                              begin
1533
                                IncDec_16 = 4'b1111;
1534
                                Set_Addr_To = aSP;
1535
                                TStates = 3'b100;
1536
                                Set_BusB_To = 4'b1101;
1537
                              end
1538
                            else
1539
                              begin
1540
                                MCycles = 3'b011;
1541
                              end // else: !if(is_cc_true(F, IR[5:3]) )
1542
                          end // case: 3
1543
 
1544 23 ghutchis
                        MCycle[3] :
1545 2 ghutchis
                          begin
1546
                            Write = 1'b1;
1547
                            IncDec_16 = 4'b1111;
1548
                            Set_Addr_To = aSP;
1549
                            Set_BusB_To = 4'b1100;
1550
                          end
1551
 
1552 23 ghutchis
                        MCycle[4] :
1553 2 ghutchis
                          begin
1554
                            Write = 1'b1;
1555
                            Call = 1'b1;
1556
                          end
1557
 
1558
                        default :;
1559
                      endcase
1560
                    end // if (IR[5] == 1'b0 || Mode != 3 )
1561
                end // case: 8'b11000100,8'b11001100,8'b11010100,8'b11011100,8'b11100100,8'b11101100,8'b11110100,8'b11111100
1562
 
1563
              8'b11001001  :
1564
                begin
1565
                  // RET
1566
                  MCycles = 3'b011;
1567 23 ghutchis
                  case (1'b1) // MCycle
1568
                    MCycle[0] :
1569 2 ghutchis
                      begin
1570
                        TStates = 3'b101;
1571
                        Set_Addr_To = aSP;
1572
                      end
1573
 
1574 23 ghutchis
                    MCycle[1] :
1575 2 ghutchis
                      begin
1576
                        IncDec_16 = 4'b0111;
1577
                        Set_Addr_To = aSP;
1578
                        LDZ = 1'b1;
1579
                      end
1580
 
1581 23 ghutchis
                    MCycle[2] :
1582 2 ghutchis
                      begin
1583
                        Jump = 1'b1;
1584
                        IncDec_16 = 4'b0111;
1585
                      end
1586
 
1587
                    default :;
1588
                  endcase // case(MCycle)
1589
                end // case: 8'b11001001
1590
 
1591
              8'b11000000,8'b11001000,8'b11010000,8'b11011000,8'b11100000,8'b11101000,8'b11110000,8'b11111000  :
1592
                begin
1593
                  if (IR[5] == 1'b1 && Mode == 3 )
1594
                    begin
1595
                      case (IRB[4:3])
1596
                        2'b00  :
1597
                          begin
1598
                            // LD ($FF00+nn),A
1599
                            MCycles = 3'b011;
1600 23 ghutchis
                            case (1'b1) // MCycle
1601
                              MCycle[1] :
1602 2 ghutchis
                                begin
1603
                                  Inc_PC = 1'b1;
1604
                                  Set_Addr_To = aIOA;
1605
                                  Set_BusB_To   = 4'b0111;
1606
                                end
1607
 
1608 23 ghutchis
                              MCycle[2] :
1609 2 ghutchis
                                Write = 1'b1;
1610
                              default :;
1611
                            endcase // case(MCycle)
1612
                          end // case: 2'b00
1613
 
1614
                        2'b01  :
1615
                          begin
1616
                            // ADD SP,n
1617
                            MCycles = 3'b011;
1618 23 ghutchis
                            case (1'b1) // MCycle
1619
                              MCycle[1] :
1620 2 ghutchis
                                begin
1621
                                  ALU_Op = 4'b0000;
1622
                                  Inc_PC = 1'b1;
1623
                                  Read_To_Reg = 1'b1;
1624
                                  Save_ALU = 1'b1;
1625
                                  Set_BusA_To = 4'b1000;
1626
                                  Set_BusB_To = 4'b0110;
1627
                                end
1628
 
1629 23 ghutchis
                              MCycle[2] :
1630 2 ghutchis
                                begin
1631
                                  NoRead = 1'b1;
1632
                                  Read_To_Reg = 1'b1;
1633
                                  Save_ALU = 1'b1;
1634
                                  ALU_Op = 4'b0001;
1635
                                  Set_BusA_To = 4'b1001;
1636
                                  Set_BusB_To = 4'b1110;        // Incorrect unsigned !!!!!!!!!!!!!!!!!!!!!
1637
                                end
1638
 
1639
                              default :;
1640
                            endcase // case(MCycle)
1641
                          end // case: 2'b01
1642
 
1643
                        2'b10  :
1644
                          begin
1645
                            // LD A,($FF00+nn)
1646
                            MCycles = 3'b011;
1647 23 ghutchis
                            case (1'b1) // MCycle
1648
                              MCycle[1] :
1649 2 ghutchis
                                begin
1650
                                  Inc_PC = 1'b1;
1651
                                  Set_Addr_To = aIOA;
1652
                                end
1653
 
1654 23 ghutchis
                              MCycle[2] :
1655 2 ghutchis
                                Read_To_Acc = 1'b1;
1656
                              default :;
1657
                            endcase // case(MCycle)
1658
                          end // case: 2'b10
1659
 
1660
                        2'b11  :
1661
                          begin
1662
                            // LD HL,SP+n       -- Not correct !!!!!!!!!!!!!!!!!!!
1663
                            MCycles = 3'b101;
1664 23 ghutchis
                            case (1'b1) // MCycle
1665
                              MCycle[1] :
1666 2 ghutchis
                                begin
1667
                                  Inc_PC = 1'b1;
1668
                                  LDZ = 1'b1;
1669
                                end
1670
 
1671 23 ghutchis
                              MCycle[2] :
1672 2 ghutchis
                                begin
1673
                                  Set_Addr_To = aZI;
1674
                                  Inc_PC = 1'b1;
1675
                                  LDW = 1'b1;
1676
                                end
1677
 
1678 23 ghutchis
                              MCycle[3] :
1679 2 ghutchis
                                begin
1680
                                  Set_BusA_To[2:0] = 3'b101; // L
1681
                                  Read_To_Reg = 1'b1;
1682
                                  Inc_WZ = 1'b1;
1683
                                  Set_Addr_To = aZI;
1684
                                end
1685
 
1686 23 ghutchis
                              MCycle[4] :
1687 2 ghutchis
                                begin
1688
                                  Set_BusA_To[2:0] = 3'b100; // H
1689
                                  Read_To_Reg = 1'b1;
1690
                                end
1691
 
1692
                              default :;
1693
                            endcase // case(MCycle)
1694
                          end // case: 2'b11
1695
 
1696
                      endcase // case(IRB[4:3])
1697
 
1698
                    end
1699
                  else
1700
                    begin
1701
                      // RET cc
1702
                      MCycles = 3'b011;
1703 23 ghutchis
                      case (1'b1) // MCycle
1704
                        MCycle[0] :
1705 2 ghutchis
                          begin
1706
                            if (is_cc_true(F, IR[5:3]) )
1707
                              begin
1708
                                Set_Addr_To = aSP;
1709
                              end
1710
                            else
1711
                              begin
1712
                                MCycles = 3'b001;
1713
                              end
1714
                            TStates = 3'b101;
1715
                          end // case: 1
1716
 
1717 23 ghutchis
                        MCycle[1] :
1718 2 ghutchis
                          begin
1719
                            IncDec_16 = 4'b0111;
1720
                            Set_Addr_To = aSP;
1721
                            LDZ = 1'b1;
1722
                          end
1723 23 ghutchis
                        MCycle[2] :
1724 2 ghutchis
                          begin
1725
                            Jump = 1'b1;
1726
                            IncDec_16 = 4'b0111;
1727
                          end
1728
                        default :;
1729
                      endcase
1730
                    end // else: !if(IR[5] == 1'b1 && Mode == 3 )
1731
                end // case: 8'b11000000,8'b11001000,8'b11010000,8'b11011000,8'b11100000,8'b11101000,8'b11110000,8'b11111000
1732
 
1733
              8'b11000111,8'b11001111,8'b11010111,8'b11011111,8'b11100111,8'b11101111,8'b11110111,8'b11111111  :
1734
                begin
1735
                  // RST p
1736
                  MCycles = 3'b011;
1737 23 ghutchis
                  case (1'b1) // MCycle
1738
                    MCycle[0] :
1739 2 ghutchis
                      begin
1740
                        TStates = 3'b101;
1741
                        IncDec_16 = 4'b1111;
1742
                        Set_Addr_To = aSP;
1743
                        Set_BusB_To = 4'b1101;
1744
                      end
1745
 
1746 23 ghutchis
                    MCycle[1] :
1747 2 ghutchis
                      begin
1748
                        Write = 1'b1;
1749
                        IncDec_16 = 4'b1111;
1750
                        Set_Addr_To = aSP;
1751
                        Set_BusB_To = 4'b1100;
1752
                      end
1753
 
1754 23 ghutchis
                    MCycle[2] :
1755 2 ghutchis
                      begin
1756
                        Write = 1'b1;
1757
                        RstP = 1'b1;
1758
                      end
1759
 
1760
                    default :;
1761
                  endcase // case(MCycle)
1762
                end // case: 8'b11000111,8'b11001111,8'b11010111,8'b11011111,8'b11100111,8'b11101111,8'b11110111,8'b11111111
1763
 
1764
// INPUT AND OUTPUT GROUP
1765
              8'b11011011  :
1766
                begin
1767
                  if (Mode != 3 )
1768
                    begin
1769
                      // IN A,(n)
1770
                      MCycles = 3'b011;
1771 23 ghutchis
                      case (1'b1) // MCycle
1772
                        MCycle[1] :
1773 2 ghutchis
                          begin
1774
                            Inc_PC = 1'b1;
1775
                            Set_Addr_To = aIOA;
1776
                          end
1777
 
1778 23 ghutchis
                        MCycle[2] :
1779 2 ghutchis
                          begin
1780
                            Read_To_Acc = 1'b1;
1781
                            IORQ = 1'b1;
1782
                          end
1783
 
1784
                        default :;
1785
                      endcase
1786
                    end // if (Mode != 3 )
1787
                end // case: 8'b11011011
1788
 
1789
              8'b11010011  :
1790
                begin
1791
                  if (Mode != 3 )
1792
                    begin
1793
                      // OUT (n),A
1794
                      MCycles = 3'b011;
1795 23 ghutchis
                      case (1'b1) // MCycle
1796
                        MCycle[1] :
1797 2 ghutchis
                          begin
1798
                            Inc_PC = 1'b1;
1799
                            Set_Addr_To = aIOA;
1800
                            Set_BusB_To = 4'b0111;
1801
                          end
1802
 
1803 23 ghutchis
                        MCycle[2] :
1804 2 ghutchis
                          begin
1805
                            Write = 1'b1;
1806
                            IORQ = 1'b1;
1807
                          end
1808
 
1809
                        default :;
1810
                      endcase
1811
                    end // if (Mode != 3 )
1812
                end // case: 8'b11010011
1813
 
1814
 
1815
//----------------------------------------------------------------------------
1816
//----------------------------------------------------------------------------
1817
// MULTIBYTE INSTRUCTIONS
1818
//----------------------------------------------------------------------------
1819
//----------------------------------------------------------------------------
1820
 
1821
              8'b11001011  :
1822
                begin
1823
                  if (Mode != 2 )
1824
                    begin
1825
                      Prefix = 2'b01;
1826
                    end
1827
                end
1828
 
1829
              8'b11101101  :
1830
                begin
1831
                  if (Mode < 2 )
1832
                    begin
1833
                      Prefix = 2'b10;
1834
                    end
1835
                end
1836
 
1837
              8'b11011101,8'b11111101  :
1838
                begin
1839
                  if (Mode < 2 )
1840
                    begin
1841
                      Prefix = 2'b11;
1842
                    end
1843
                end
1844
 
1845
            endcase // case(IRB)
1846
          end // case: 2'b00
1847
 
1848
 
1849
        2'b01  :
1850
          begin
1851
 
1852
 
1853
            //----------------------------------------------------------------------------
1854
            //
1855
            //  CB prefixed instructions
1856
            //
1857
            //----------------------------------------------------------------------------
1858
 
1859
            Set_BusA_To[2:0] = IR[2:0];
1860
            Set_BusB_To[2:0] = IR[2:0];
1861
 
1862
            case (IRB)
1863
              8'b00000000,8'b00000001,8'b00000010,8'b00000011,8'b00000100,8'b00000101,8'b00000111,
1864
              8'b00010000,8'b00010001,8'b00010010,8'b00010011,8'b00010100,8'b00010101,8'b00010111,
1865
              8'b00001000,8'b00001001,8'b00001010,8'b00001011,8'b00001100,8'b00001101,8'b00001111,
1866
              8'b00011000,8'b00011001,8'b00011010,8'b00011011,8'b00011100,8'b00011101,8'b00011111,
1867
              8'b00100000,8'b00100001,8'b00100010,8'b00100011,8'b00100100,8'b00100101,8'b00100111,
1868
              8'b00101000,8'b00101001,8'b00101010,8'b00101011,8'b00101100,8'b00101101,8'b00101111,
1869
              8'b00110000,8'b00110001,8'b00110010,8'b00110011,8'b00110100,8'b00110101,8'b00110111,
1870
              8'b00111000,8'b00111001,8'b00111010,8'b00111011,8'b00111100,8'b00111101,8'b00111111 :
1871
                begin
1872
                  // RLC r
1873
                  // RL r
1874
                  // RRC r
1875
                  // RR r
1876
                  // SLA r
1877
                  // SRA r
1878
                  // SRL r
1879
                  // SLL r (Undocumented) / SWAP r
1880 21 ghutchis
                  if (MCycle[0] ) begin
1881 2 ghutchis
                    ALU_Op = 4'b1000;
1882
                    Read_To_Reg = 1'b1;
1883
                    Save_ALU = 1'b1;
1884
                  end
1885
                end // case: 8'b00000000,8'b00000001,8'b00000010,8'b00000011,8'b00000100,8'b00000101,8'b00000111,...
1886
 
1887
              8'b00000110,8'b00010110,8'b00001110,8'b00011110,8'b00101110,8'b00111110,8'b00100110,8'b00110110  :
1888
                begin
1889
                  // RLC (HL)
1890
                  // RL (HL)
1891
                  // RRC (HL)
1892
                  // RR (HL)
1893
                  // SRA (HL)
1894
                  // SRL (HL)
1895
                  // SLA (HL)
1896
                  // SLL (HL) (Undocumented) / SWAP (HL)
1897
                  MCycles = 3'b011;
1898 23 ghutchis
                  case (1'b1) // MCycle
1899
                    MCycle[0], MCycle[6] :
1900 2 ghutchis
                      Set_Addr_To = aXY;
1901 23 ghutchis
                    MCycle[1] :
1902 2 ghutchis
                      begin
1903
                        ALU_Op = 4'b1000;
1904
                        Read_To_Reg = 1'b1;
1905
                        Save_ALU = 1'b1;
1906
                        Set_Addr_To = aXY;
1907
                        TStates = 3'b100;
1908
                      end
1909
 
1910 23 ghutchis
                    MCycle[2] :
1911 2 ghutchis
                      Write = 1'b1;
1912
                    default :;
1913
                  endcase // case(MCycle)
1914
                end // case: 8'b00000110,8'b00010110,8'b00001110,8'b00011110,8'b00101110,8'b00111110,8'b00100110,8'b00110110
1915
 
1916
              8'b01000000,8'b01000001,8'b01000010,8'b01000011,8'b01000100,8'b01000101,8'b01000111,
1917
                  8'b01001000,8'b01001001,8'b01001010,8'b01001011,8'b01001100,8'b01001101,8'b01001111,
1918
                  8'b01010000,8'b01010001,8'b01010010,8'b01010011,8'b01010100,8'b01010101,8'b01010111,
1919
                  8'b01011000,8'b01011001,8'b01011010,8'b01011011,8'b01011100,8'b01011101,8'b01011111,
1920
                  8'b01100000,8'b01100001,8'b01100010,8'b01100011,8'b01100100,8'b01100101,8'b01100111,
1921
                  8'b01101000,8'b01101001,8'b01101010,8'b01101011,8'b01101100,8'b01101101,8'b01101111,
1922
                  8'b01110000,8'b01110001,8'b01110010,8'b01110011,8'b01110100,8'b01110101,8'b01110111,
1923
                  8'b01111000,8'b01111001,8'b01111010,8'b01111011,8'b01111100,8'b01111101,8'b01111111 :
1924
                    begin
1925
                      // BIT b,r
1926 21 ghutchis
                      if (MCycle[0] )
1927 2 ghutchis
                        begin
1928
                          Set_BusB_To[2:0] = IR[2:0];
1929
                          ALU_Op = 4'b1001;
1930
                        end
1931
                    end // case: 8'b01000000,8'b01000001,8'b01000010,8'b01000011,8'b01000100,8'b01000101,8'b01000111,...
1932
 
1933
              8'b01000110,8'b01001110,8'b01010110,8'b01011110,8'b01100110,8'b01101110,8'b01110110,8'b01111110  :
1934
                begin
1935
                  // BIT b,(HL)
1936
                  MCycles = 3'b010;
1937 23 ghutchis
                  case (1'b1) // MCycle
1938
                    MCycle[0], MCycle[6] :
1939 2 ghutchis
                      Set_Addr_To = aXY;
1940 23 ghutchis
                    MCycle[1] :
1941 2 ghutchis
                      begin
1942
                        ALU_Op = 4'b1001;
1943
                        TStates = 3'b100;
1944
                      end
1945
 
1946
                    default :;
1947
                  endcase // case(MCycle)
1948
                end // case: 8'b01000110,8'b01001110,8'b01010110,8'b01011110,8'b01100110,8'b01101110,8'b01110110,8'b01111110
1949
 
1950
              8'b11000000,8'b11000001,8'b11000010,8'b11000011,8'b11000100,8'b11000101,8'b11000111,
1951
                  8'b11001000,8'b11001001,8'b11001010,8'b11001011,8'b11001100,8'b11001101,8'b11001111,
1952
                  8'b11010000,8'b11010001,8'b11010010,8'b11010011,8'b11010100,8'b11010101,8'b11010111,
1953
                  8'b11011000,8'b11011001,8'b11011010,8'b11011011,8'b11011100,8'b11011101,8'b11011111,
1954
                  8'b11100000,8'b11100001,8'b11100010,8'b11100011,8'b11100100,8'b11100101,8'b11100111,
1955
                  8'b11101000,8'b11101001,8'b11101010,8'b11101011,8'b11101100,8'b11101101,8'b11101111,
1956
                  8'b11110000,8'b11110001,8'b11110010,8'b11110011,8'b11110100,8'b11110101,8'b11110111,
1957
                  8'b11111000,8'b11111001,8'b11111010,8'b11111011,8'b11111100,8'b11111101,8'b11111111 :
1958
                    begin
1959
                      // SET b,r
1960 21 ghutchis
                      if (MCycle[0] )
1961 2 ghutchis
                        begin
1962
                          ALU_Op = 4'b1010;
1963
                          Read_To_Reg = 1'b1;
1964
                          Save_ALU = 1'b1;
1965
                        end
1966
                    end // case: 8'b11000000,8'b11000001,8'b11000010,8'b11000011,8'b11000100,8'b11000101,8'b11000111,...
1967
 
1968
              8'b11000110,8'b11001110,8'b11010110,8'b11011110,8'b11100110,8'b11101110,8'b11110110,8'b11111110  :
1969
                begin
1970
                  // SET b,(HL)
1971
                  MCycles = 3'b011;
1972 23 ghutchis
                  case (1'b1) // MCycle
1973
                    MCycle[0], MCycle[6] :
1974 2 ghutchis
                      Set_Addr_To = aXY;
1975 23 ghutchis
                    MCycle[1] :
1976 2 ghutchis
                      begin
1977
                        ALU_Op = 4'b1010;
1978
                        Read_To_Reg = 1'b1;
1979
                        Save_ALU = 1'b1;
1980
                        Set_Addr_To = aXY;
1981
                        TStates = 3'b100;
1982
                      end
1983 23 ghutchis
                    MCycle[2] :
1984 2 ghutchis
                      Write = 1'b1;
1985
                    default :;
1986
                  endcase // case(MCycle)
1987
                end // case: 8'b11000110,8'b11001110,8'b11010110,8'b11011110,8'b11100110,8'b11101110,8'b11110110,8'b11111110
1988
 
1989
              8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,
1990
                  8'b10001000,8'b10001001,8'b10001010,8'b10001011,8'b10001100,8'b10001101,8'b10001111,
1991
                  8'b10010000,8'b10010001,8'b10010010,8'b10010011,8'b10010100,8'b10010101,8'b10010111,
1992
                  8'b10011000,8'b10011001,8'b10011010,8'b10011011,8'b10011100,8'b10011101,8'b10011111,
1993
                  8'b10100000,8'b10100001,8'b10100010,8'b10100011,8'b10100100,8'b10100101,8'b10100111,
1994
                  8'b10101000,8'b10101001,8'b10101010,8'b10101011,8'b10101100,8'b10101101,8'b10101111,
1995
                  8'b10110000,8'b10110001,8'b10110010,8'b10110011,8'b10110100,8'b10110101,8'b10110111,
1996
                  8'b10111000,8'b10111001,8'b10111010,8'b10111011,8'b10111100,8'b10111101,8'b10111111 :
1997
                    begin
1998
                      // RES b,r
1999 21 ghutchis
                      if (MCycle[0] )
2000 2 ghutchis
                        begin
2001
                          ALU_Op = 4'b1011;
2002
                          Read_To_Reg = 1'b1;
2003
                          Save_ALU = 1'b1;
2004
                        end
2005
                    end // case: 8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,...
2006
 
2007
              8'b10000110,8'b10001110,8'b10010110,8'b10011110,8'b10100110,8'b10101110,8'b10110110,8'b10111110  :
2008
                begin
2009
                  // RES b,(HL)
2010
                  MCycles = 3'b011;
2011 23 ghutchis
                  case (1'b1) // MCycle
2012
                    MCycle[0], MCycle[6] :
2013 2 ghutchis
                      Set_Addr_To = aXY;
2014 23 ghutchis
                    MCycle[1] :
2015 2 ghutchis
                      begin
2016
                        ALU_Op = 4'b1011;
2017
                        Read_To_Reg = 1'b1;
2018
                        Save_ALU = 1'b1;
2019
                        Set_Addr_To = aXY;
2020
                        TStates = 3'b100;
2021
                      end
2022
 
2023 23 ghutchis
                    MCycle[2] :
2024 2 ghutchis
                      Write = 1'b1;
2025
                    default :;
2026
                  endcase // case(MCycle)
2027
                end // case: 8'b10000110,8'b10001110,8'b10010110,8'b10011110,8'b10100110,8'b10101110,8'b10110110,8'b10111110
2028
 
2029
            endcase // case(IRB)
2030
          end // case: 2'b01
2031
 
2032
 
2033
        default :
2034
          begin : default_ed_block
2035
 
2036
            //----------------------------------------------------------------------------
2037
            //
2038
            //  ED prefixed instructions
2039
            //
2040
            //----------------------------------------------------------------------------
2041
 
2042
            case (IRB)
2043
              8'b00000000,8'b00000001,8'b00000010,8'b00000011,8'b00000100,8'b00000101,8'b00000110,8'b00000111
2044
                ,8'b00001000,8'b00001001,8'b00001010,8'b00001011,8'b00001100,8'b00001101,8'b00001110,8'b00001111
2045
                  ,8'b00010000,8'b00010001,8'b00010010,8'b00010011,8'b00010100,8'b00010101,8'b00010110,8'b00010111
2046
                    ,8'b00011000,8'b00011001,8'b00011010,8'b00011011,8'b00011100,8'b00011101,8'b00011110,8'b00011111
2047
                      ,8'b00100000,8'b00100001,8'b00100010,8'b00100011,8'b00100100,8'b00100101,8'b00100110,8'b00100111
2048
                        ,8'b00101000,8'b00101001,8'b00101010,8'b00101011,8'b00101100,8'b00101101,8'b00101110,8'b00101111
2049
                          ,8'b00110000,8'b00110001,8'b00110010,8'b00110011,8'b00110100,8'b00110101,8'b00110110,8'b00110111
2050
                            ,8'b00111000,8'b00111001,8'b00111010,8'b00111011,8'b00111100,8'b00111101,8'b00111110,8'b00111111
2051
 
2052
 
2053
                                  ,8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000110,8'b10000111
2054
                                    ,8'b10001000,8'b10001001,8'b10001010,8'b10001011,8'b10001100,8'b10001101,8'b10001110,8'b10001111
2055
                                      ,8'b10010000,8'b10010001,8'b10010010,8'b10010011,8'b10010100,8'b10010101,8'b10010110,8'b10010111
2056
                                        ,8'b10011000,8'b10011001,8'b10011010,8'b10011011,8'b10011100,8'b10011101,8'b10011110,8'b10011111
2057
                                          ,                                            8'b10100100,8'b10100101,8'b10100110,8'b10100111
2058
                                            ,                                            8'b10101100,8'b10101101,8'b10101110,8'b10101111
2059
                                              ,                                            8'b10110100,8'b10110101,8'b10110110,8'b10110111
2060
                                                ,                                            8'b10111100,8'b10111101,8'b10111110,8'b10111111
2061
                                                  ,8'b11000000,8'b11000001,8'b11000010,8'b11000011,8'b11000100,8'b11000101,8'b11000110,8'b11000111
2062
                                                    ,8'b11001000,8'b11001001,8'b11001010,8'b11001011,8'b11001100,8'b11001101,8'b11001110,8'b11001111
2063
                                                      ,8'b11010000,8'b11010001,8'b11010010,8'b11010011,8'b11010100,8'b11010101,8'b11010110,8'b11010111
2064
                                                        ,8'b11011000,8'b11011001,8'b11011010,8'b11011011,8'b11011100,8'b11011101,8'b11011110,8'b11011111
2065
                                                          ,8'b11100000,8'b11100001,8'b11100010,8'b11100011,8'b11100100,8'b11100101,8'b11100110,8'b11100111
2066
                                                            ,8'b11101000,8'b11101001,8'b11101010,8'b11101011,8'b11101100,8'b11101101,8'b11101110,8'b11101111
2067
                                                              ,8'b11110000,8'b11110001,8'b11110010,8'b11110011,8'b11110100,8'b11110101,8'b11110110,8'b11110111
2068
                                                                ,8'b11111000,8'b11111001,8'b11111010,8'b11111011,8'b11111100,8'b11111101,8'b11111110,8'b11111111 :
2069
                                ; // NOP, undocumented
2070
 
2071
                  8'b01111110,8'b01111111  :
2072
                    // NOP, undocumented
2073
                ;
2074
                  // 8 BIT LOAD GROUP
2075
                  8'b01010111  :
2076
                    begin
2077
                      // LD A,I
2078
                      Special_LD = 3'b100;
2079
                      TStates = 3'b101;
2080
                    end
2081
 
2082
                  8'b01011111  :
2083
                    begin
2084
                      // LD A,R
2085
                      Special_LD = 3'b101;
2086
                      TStates = 3'b101;
2087
                    end
2088
 
2089
                  8'b01000111  :
2090
                    begin
2091
                      // LD I,A
2092
                      Special_LD = 3'b110;
2093
                      TStates = 3'b101;
2094
                    end
2095
 
2096
                  8'b01001111  :
2097
                    begin
2098
                      // LD R,A
2099
                      Special_LD = 3'b111;
2100
                      TStates = 3'b101;
2101
                    end
2102
 
2103
                  // 16 BIT LOAD GROUP
2104
                  8'b01001011,8'b01011011,8'b01101011,8'b01111011  :
2105
                    begin
2106
                      // LD dd,(nn)
2107
                      MCycles = 3'b101;
2108 23 ghutchis
                      case (1'b1) // MCycle
2109
                        MCycle[1] :
2110 2 ghutchis
                          begin
2111
                            Inc_PC = 1'b1;
2112
                            LDZ = 1'b1;
2113
                          end
2114
 
2115 23 ghutchis
                        MCycle[2] :
2116 2 ghutchis
                          begin
2117
                            Set_Addr_To = aZI;
2118
                            Inc_PC = 1'b1;
2119
                            LDW = 1'b1;
2120
                          end
2121
 
2122 23 ghutchis
                        MCycle[3] :
2123 2 ghutchis
                          begin
2124
                            Read_To_Reg = 1'b1;
2125
                            if (IR[5:4] == 2'b11 )
2126
                              begin
2127
                                Set_BusA_To = 4'b1000;
2128
                              end
2129
                            else
2130
                              begin
2131
                                Set_BusA_To[2:1] = IR[5:4];
2132
                                Set_BusA_To[0] = 1'b1;
2133
                              end
2134
                            Inc_WZ = 1'b1;
2135
                            Set_Addr_To = aZI;
2136
                          end // case: 4
2137
 
2138 23 ghutchis
                        MCycle[4] :
2139 2 ghutchis
                          begin
2140
                            Read_To_Reg = 1'b1;
2141
                            if (IR[5:4] == 2'b11 )
2142
                              begin
2143
                                Set_BusA_To = 4'b1001;
2144
                              end
2145
                            else
2146
                              begin
2147
                                Set_BusA_To[2:1] = IR[5:4];
2148
                                Set_BusA_To[0] = 1'b0;
2149
                              end
2150
                          end // case: 5
2151
 
2152
                        default :;
2153
                      endcase // case(MCycle)
2154
                    end // case: 8'b01001011,8'b01011011,8'b01101011,8'b01111011
2155
 
2156
 
2157
                  8'b01000011,8'b01010011,8'b01100011,8'b01110011  :
2158
                    begin
2159
                      // LD (nn),dd
2160
                      MCycles = 3'b101;
2161 23 ghutchis
                      case (1'b1) // MCycle
2162
                        MCycle[1] :
2163 2 ghutchis
                          begin
2164
                            Inc_PC = 1'b1;
2165
                            LDZ = 1'b1;
2166
                          end
2167
 
2168 23 ghutchis
                        MCycle[2] :
2169 2 ghutchis
                          begin
2170
                            Set_Addr_To = aZI;
2171
                            Inc_PC = 1'b1;
2172
                            LDW = 1'b1;
2173
                            if (IR[5:4] == 2'b11 )
2174
                              begin
2175
                                Set_BusB_To = 4'b1000;
2176
                              end
2177
                            else
2178
                              begin
2179
                                Set_BusB_To[2:1] = IR[5:4];
2180
                                Set_BusB_To[0] = 1'b1;
2181
                                Set_BusB_To[3] = 1'b0;
2182
                              end
2183
                          end // case: 3
2184
 
2185 23 ghutchis
                        MCycle[3] :
2186 2 ghutchis
                          begin
2187
                            Inc_WZ = 1'b1;
2188
                            Set_Addr_To = aZI;
2189
                            Write = 1'b1;
2190
                            if (IR[5:4] == 2'b11 )
2191
                              begin
2192
                                Set_BusB_To = 4'b1001;
2193
                              end
2194
                            else
2195
                              begin
2196
                                Set_BusB_To[2:1] = IR[5:4];
2197
                                Set_BusB_To[0] = 1'b0;
2198
                                Set_BusB_To[3] = 1'b0;
2199
                              end
2200
                          end // case: 4
2201
 
2202 23 ghutchis
                        MCycle[4] :
2203 2 ghutchis
                          begin
2204
                            Write = 1'b1;
2205
                          end
2206
 
2207
                        default :;
2208
                      endcase // case(MCycle)
2209
                    end // case: 8'b01000011,8'b01010011,8'b01100011,8'b01110011
2210
 
2211
                  8'b10100000 , 8'b10101000 , 8'b10110000 , 8'b10111000  :
2212
                    begin
2213
                      // LDI, LDD, LDIR, LDDR
2214
                      MCycles = 3'b100;
2215 23 ghutchis
                      case (1'b1) // MCycle
2216
                        MCycle[0] :
2217 2 ghutchis
                          begin
2218
                            Set_Addr_To = aXY;
2219
                            IncDec_16 = 4'b1100; // BC
2220
                          end
2221
 
2222 23 ghutchis
                        MCycle[1] :
2223 2 ghutchis
                          begin
2224
                            Set_BusB_To = 4'b0110;
2225
                            Set_BusA_To[2:0] = 3'b111;
2226
                            ALU_Op = 4'b0000;
2227
                            Set_Addr_To = aDE;
2228
                            if (IR[3] == 1'b0 )
2229
                              begin
2230
                                IncDec_16 = 4'b0110; // IX
2231
                              end
2232
                            else
2233
                              begin
2234
                                IncDec_16 = 4'b1110;
2235
                              end
2236
                          end // case: 2
2237
 
2238 23 ghutchis
                        MCycle[2] :
2239 2 ghutchis
                          begin
2240
                            I_BT = 1'b1;
2241
                            TStates = 3'b101;
2242
                            Write = 1'b1;
2243
                            if (IR[3] == 1'b0 )
2244
                              begin
2245
                                IncDec_16 = 4'b0101; // DE
2246
                              end
2247
                            else
2248
                              begin
2249
                                IncDec_16 = 4'b1101;
2250
                              end
2251
                          end // case: 3
2252
 
2253 23 ghutchis
                        MCycle[3] :
2254 2 ghutchis
                          begin
2255
                            NoRead = 1'b1;
2256
                            TStates = 3'b101;
2257
                          end
2258
 
2259
                        default :;
2260
                      endcase // case(MCycle)
2261
                    end // case: 8'b10100000 , 8'b10101000 , 8'b10110000 , 8'b10111000
2262
 
2263
                  8'b10100001 , 8'b10101001 , 8'b10110001 , 8'b10111001  :
2264
                    begin
2265
                      // CPI, CPD, CPIR, CPDR
2266
                      MCycles = 3'b100;
2267 23 ghutchis
                      case (1'b1) // MCycle
2268
                        MCycle[0] :
2269 2 ghutchis
                          begin
2270
                            Set_Addr_To = aXY;
2271
                            IncDec_16 = 4'b1100; // BC
2272
                          end
2273
 
2274 23 ghutchis
                        MCycle[1] :
2275 2 ghutchis
                          begin
2276
                            Set_BusB_To = 4'b0110;
2277
                            Set_BusA_To[2:0] = 3'b111;
2278
                            ALU_Op = 4'b0111;
2279
                            Save_ALU = 1'b1;
2280
                            PreserveC = 1'b1;
2281
                            if (IR[3] == 1'b0 )
2282
                              begin
2283
                                IncDec_16 = 4'b0110;
2284
                              end
2285
                            else
2286
                              begin
2287
                                IncDec_16 = 4'b1110;
2288
                              end
2289
                          end // case: 2
2290
 
2291 23 ghutchis
                        MCycle[2] :
2292 2 ghutchis
                          begin
2293
                            NoRead = 1'b1;
2294
                            I_BC = 1'b1;
2295
                            TStates = 3'b101;
2296
                          end
2297
 
2298 23 ghutchis
                        MCycle[3] :
2299 2 ghutchis
                          begin
2300
                            NoRead = 1'b1;
2301
                            TStates = 3'b101;
2302
                          end
2303
 
2304
                        default :;
2305
                      endcase // case(MCycle)
2306
                    end // case: 8'b10100001 , 8'b10101001 , 8'b10110001 , 8'b10111001
2307
 
2308
                  8'b01000100,8'b01001100,8'b01010100,8'b01011100,8'b01100100,8'b01101100,8'b01110100,8'b01111100  :
2309
                    begin
2310
                      // NEG
2311
                      ALU_Op = 4'b0010;
2312
                      Set_BusB_To = 4'b0111;
2313
                      Set_BusA_To = 4'b1010;
2314
                      Read_To_Acc = 1'b1;
2315
                      Save_ALU = 1'b1;
2316
                    end
2317
 
2318
                  8'b01000110,8'b01001110,8'b01100110,8'b01101110  :
2319
                    begin
2320
                      // IM 0
2321
                      IMode = 2'b00;
2322
                    end
2323
 
2324
                  8'b01010110,8'b01110110  :
2325
                    // IM 1
2326
                    IMode = 2'b01;
2327
 
2328
                  8'b01011110,8'b01110111  :
2329
                    // IM 2
2330
                    IMode = 2'b10;
2331
 
2332
                  // 16 bit arithmetic
2333
                  8'b01001010,8'b01011010,8'b01101010,8'b01111010  :
2334
                    begin
2335
                      // ADC HL,ss
2336
                      MCycles = 3'b011;
2337 23 ghutchis
                      case (1'b1) // MCycle
2338
                        MCycle[1] :
2339 2 ghutchis
                          begin
2340
                            NoRead = 1'b1;
2341
                            ALU_Op = 4'b0001;
2342
                            Read_To_Reg = 1'b1;
2343
                            Save_ALU = 1'b1;
2344
                            Set_BusA_To[2:0] = 3'b101;
2345
                            case (IR[5:4])
2346
                              0,1,2  :
2347
                                begin
2348
                                  Set_BusB_To[2:1] = IR[5:4];
2349
                                  Set_BusB_To[0] = 1'b1;
2350
                                end
2351
                              default :
2352
                                Set_BusB_To = 4'b1000;
2353
                            endcase
2354
                            TStates = 3'b100;
2355
                          end // case: 2
2356
 
2357 23 ghutchis
                        MCycle[2] :
2358 2 ghutchis
                          begin
2359
                            NoRead = 1'b1;
2360
                            Read_To_Reg = 1'b1;
2361
                            Save_ALU = 1'b1;
2362
                            ALU_Op = 4'b0001;
2363
                            Set_BusA_To[2:0] = 3'b100;
2364
                            case (IR[5:4])
2365
                              0,1,2  :
2366
                                begin
2367
                                  Set_BusB_To[2:1] = IR[5:4];
2368
                                  Set_BusB_To[0] = 1'b0;
2369
                                end
2370
                              default :
2371
                                Set_BusB_To = 4'b1001;
2372
                            endcase // case(IR[5:4])
2373
                          end // case: 3
2374
 
2375
                        default :;
2376
                      endcase // case(MCycle)
2377
                    end // case: 8'b01001010,8'b01011010,8'b01101010,8'b01111010
2378
 
2379
                  8'b01000010,8'b01010010,8'b01100010,8'b01110010  :
2380
                    begin
2381
                      // SBC HL,ss
2382
                      MCycles = 3'b011;
2383 23 ghutchis
                      case (1'b1) // MCycle
2384
                        MCycle[1] :
2385 2 ghutchis
                          begin
2386
                            NoRead = 1'b1;
2387
                            ALU_Op = 4'b0011;
2388
                            Read_To_Reg = 1'b1;
2389
                            Save_ALU = 1'b1;
2390
                            Set_BusA_To[2:0] = 3'b101;
2391
                            case (IR[5:4])
2392
                              0,1,2  :
2393
                                begin
2394
                                  Set_BusB_To[2:1] = IR[5:4];
2395
                                  Set_BusB_To[0] = 1'b1;
2396
                                end
2397
                              default :
2398
                                Set_BusB_To = 4'b1000;
2399
                            endcase
2400
                            TStates = 3'b100;
2401
                          end // case: 2
2402
 
2403 23 ghutchis
                        MCycle[2] :
2404 2 ghutchis
                          begin
2405
                            NoRead = 1'b1;
2406
                            ALU_Op = 4'b0011;
2407
                            Read_To_Reg = 1'b1;
2408
                            Save_ALU = 1'b1;
2409
                            Set_BusA_To[2:0] = 3'b100;
2410
                            case (IR[5:4])
2411
                              0,1,2  :
2412
                                Set_BusB_To[2:1] = IR[5:4];
2413
                              default :
2414
                                Set_BusB_To = 4'b1001;
2415
                            endcase
2416
                          end // case: 3
2417
 
2418
                        default :;
2419
 
2420
                      endcase // case(MCycle)
2421
                    end // case: 8'b01000010,8'b01010010,8'b01100010,8'b01110010
2422
 
2423
                  8'b01101111  :
2424
                    begin
2425
                      // RLD
2426
                      MCycles = 3'b100;
2427 23 ghutchis
                      case (1'b1) // MCycle
2428
                        MCycle[1] :
2429 2 ghutchis
                          begin
2430
                            NoRead = 1'b1;
2431
                            Set_Addr_To = aXY;
2432
                          end
2433
 
2434 23 ghutchis
                        MCycle[2] :
2435 2 ghutchis
                          begin
2436
                            Read_To_Reg = 1'b1;
2437
                            Set_BusB_To[2:0] = 3'b110;
2438
                            Set_BusA_To[2:0] = 3'b111;
2439
                            ALU_Op = 4'b1101;
2440
                            TStates = 3'b100;
2441
                            Set_Addr_To = aXY;
2442
                            Save_ALU = 1'b1;
2443
                          end
2444
 
2445 23 ghutchis
                        MCycle[3] :
2446 2 ghutchis
                          begin
2447
                            I_RLD = 1'b1;
2448
                            Write = 1'b1;
2449
                          end
2450
 
2451
                        default :;
2452
                      endcase // case(MCycle)
2453
                    end // case: 8'b01101111
2454
 
2455
                  8'b01100111  :
2456
                    begin
2457
                      // RRD
2458
                      MCycles = 3'b100;
2459 23 ghutchis
                      case (1'b1) // MCycle
2460
                        MCycle[1] :
2461 2 ghutchis
                          Set_Addr_To = aXY;
2462 23 ghutchis
                        MCycle[2] :
2463 2 ghutchis
                          begin
2464
                            Read_To_Reg = 1'b1;
2465
                            Set_BusB_To[2:0] = 3'b110;
2466
                            Set_BusA_To[2:0] = 3'b111;
2467
                            ALU_Op = 4'b1110;
2468
                            TStates = 3'b100;
2469
                            Set_Addr_To = aXY;
2470
                            Save_ALU = 1'b1;
2471
                          end
2472
 
2473 23 ghutchis
                        MCycle[3] :
2474 2 ghutchis
                          begin
2475
                            I_RRD = 1'b1;
2476
                            Write = 1'b1;
2477
                          end
2478
 
2479
                        default :;
2480
                      endcase // case(MCycle)
2481
                    end // case: 8'b01100111
2482
 
2483
                  8'b01000101,8'b01001101,8'b01010101,8'b01011101,8'b01100101,8'b01101101,8'b01110101,8'b01111101  :
2484
                    begin
2485
                      // RETI, RETN
2486
                      MCycles = 3'b011;
2487 23 ghutchis
                      case (1'b1) // MCycle
2488
                        MCycle[0] :
2489 2 ghutchis
                          Set_Addr_To = aSP;
2490
 
2491 23 ghutchis
                        MCycle[1] :
2492 2 ghutchis
                          begin
2493
                            IncDec_16 = 4'b0111;
2494
                            Set_Addr_To = aSP;
2495
                            LDZ = 1'b1;
2496
                          end
2497
 
2498 23 ghutchis
                        MCycle[2] :
2499 2 ghutchis
                          begin
2500
                            Jump = 1'b1;
2501
                            IncDec_16 = 4'b0111;
2502
                            I_RETN = 1'b1;
2503
                          end
2504
 
2505
                        default :;
2506
                      endcase // case(MCycle)
2507
                    end // case: 8'b01000101,8'b01001101,8'b01010101,8'b01011101,8'b01100101,8'b01101101,8'b01110101,8'b01111101
2508
 
2509
                  8'b01000000,8'b01001000,8'b01010000,8'b01011000,8'b01100000,8'b01101000,8'b01110000,8'b01111000  :
2510
                    begin
2511
                      // IN r,(C)
2512
                      MCycles = 3'b010;
2513 23 ghutchis
                      case (1'b1) // MCycle
2514
                        MCycle[0] :
2515 2 ghutchis
                          Set_Addr_To = aBC;
2516
 
2517 23 ghutchis
                        MCycle[1] :
2518 2 ghutchis
                          begin
2519
                            IORQ = 1'b1;
2520
                            if (IR[5:3] != 3'b110 )
2521
                              begin
2522
                                Read_To_Reg = 1'b1;
2523
                                Set_BusA_To[2:0] = IR[5:3];
2524
                              end
2525
                            I_INRC = 1'b1;
2526
                          end
2527
 
2528
                        default :;
2529
                      endcase // case(MCycle)
2530
                    end // case: 8'b01000000,8'b01001000,8'b01010000,8'b01011000,8'b01100000,8'b01101000,8'b01110000,8'b01111000
2531
 
2532
                  8'b01000001,8'b01001001,8'b01010001,8'b01011001,8'b01100001,8'b01101001,8'b01110001,8'b01111001  :
2533
                    begin
2534
                      // OUT (C),r
2535
                      // OUT (C),0
2536
                      MCycles = 3'b010;
2537 23 ghutchis
                      case (1'b1) // MCycle
2538
                        MCycle[0] :
2539 2 ghutchis
                          begin
2540
                            Set_Addr_To = aBC;
2541
                            Set_BusB_To[2:0]     = IR[5:3];
2542
                            if (IR[5:3] == 3'b110 )
2543
                              begin
2544
                                Set_BusB_To[3] = 1'b1;
2545
                              end
2546
                          end
2547
 
2548 23 ghutchis
                        MCycle[1] :
2549 2 ghutchis
                          begin
2550
                            Write = 1'b1;
2551
                            IORQ = 1'b1;
2552
                          end
2553
 
2554
                        default :;
2555
                      endcase // case(MCycle)
2556
                    end // case: 8'b01000001,8'b01001001,8'b01010001,8'b01011001,8'b01100001,8'b01101001,8'b01110001,8'b01111001
2557
 
2558
                  8'b10100010 , 8'b10101010 , 8'b10110010 , 8'b10111010  :
2559
                    begin
2560
                      // INI, IND, INIR, INDR
2561
                      MCycles = 3'b100;
2562 23 ghutchis
                      case (1'b1) // MCycle
2563
                        MCycle[0] :
2564 2 ghutchis
                          begin
2565
                            Set_Addr_To = aBC;
2566
                            Set_BusB_To = 4'b1010;
2567
                            Set_BusA_To = 4'b0000;
2568
                            Read_To_Reg = 1'b1;
2569
                            Save_ALU = 1'b1;
2570
                            ALU_Op = 4'b0010;
2571
                          end
2572
 
2573 23 ghutchis
                        MCycle[1] :
2574 2 ghutchis
                          begin
2575
                            IORQ = 1'b1;
2576
                            Set_BusB_To = 4'b0110;
2577
                            Set_Addr_To = aXY;
2578
                          end
2579
 
2580 23 ghutchis
                        MCycle[2] :
2581 2 ghutchis
                          begin
2582
                            if (IR[3] == 1'b0 )
2583
                              begin
2584
                                IncDec_16 = 4'b0010;
2585
                              end
2586
                            else
2587
                              begin
2588
                                IncDec_16 = 4'b1010;
2589
                              end
2590
                            TStates = 3'b100;
2591
                            Write = 1'b1;
2592
                            I_BTR = 1'b1;
2593
                          end // case: 3
2594
 
2595 23 ghutchis
                        MCycle[3] :
2596 2 ghutchis
                          begin
2597
                            NoRead = 1'b1;
2598
                            TStates = 3'b101;
2599
                          end
2600
 
2601
                        default :;
2602
                      endcase // case(MCycle)
2603
                    end // case: 8'b10100010 , 8'b10101010 , 8'b10110010 , 8'b10111010
2604
 
2605
                  8'b10100011 , 8'b10101011 , 8'b10110011 , 8'b10111011  :
2606
                    begin
2607
                      // OUTI, OUTD, OTIR, OTDR
2608
                      MCycles = 3'b100;
2609 23 ghutchis
                      case (1'b1) // MCycle
2610
                        MCycle[0] :
2611 2 ghutchis
                          begin
2612
                            TStates = 3'b101;
2613
                            Set_Addr_To = aXY;
2614
                            Set_BusB_To = 4'b1010;
2615
                            Set_BusA_To = 4'b0000;
2616
                            Read_To_Reg = 1'b1;
2617
                            Save_ALU = 1'b1;
2618
                            ALU_Op = 4'b0010;
2619
                          end
2620
 
2621 23 ghutchis
                        MCycle[1] :
2622 2 ghutchis
                          begin
2623
                            Set_BusB_To = 4'b0110;
2624
                            Set_Addr_To = aBC;
2625
                          end
2626
 
2627 23 ghutchis
                        MCycle[2] :
2628 2 ghutchis
                          begin
2629
                            if (IR[3] == 1'b0 )
2630
                              begin
2631
                                IncDec_16 = 4'b0010;
2632
                              end
2633
                            else
2634
                              begin
2635
                                IncDec_16 = 4'b1010;
2636
                              end
2637
                            IORQ = 1'b1;
2638
                            Write = 1'b1;
2639
                            I_BTR = 1'b1;
2640
                          end // case: 3
2641
 
2642 23 ghutchis
                        MCycle[3] :
2643 2 ghutchis
                          begin
2644
                            NoRead = 1'b1;
2645
                            TStates = 3'b101;
2646
                          end
2647
 
2648
                        default :;
2649
                      endcase // case(MCycle)
2650
                    end // case: 8'b10100011 , 8'b10101011 , 8'b10110011 , 8'b10111011
2651
 
2652
                endcase // case(IRB)                  
2653
          end // block: default_ed_block        
2654
      endcase // case(ISet)
2655
 
2656
      if (Mode == 1 )
2657
        begin
2658 21 ghutchis
          if (MCycle[0] )
2659 2 ghutchis
            begin
2660
              //TStates = 3'b100;
2661
            end
2662
          else
2663
            begin
2664
              TStates = 3'b011;
2665
            end
2666
        end
2667
 
2668
      if (Mode == 3 )
2669
        begin
2670 21 ghutchis
          if (MCycle[0] )
2671 2 ghutchis
            begin
2672
              //TStates = 3'b100;
2673
            end
2674
          else
2675
            begin
2676
              TStates = 3'b100;
2677
            end
2678
        end
2679
 
2680
      if (Mode < 2 )
2681
        begin
2682 21 ghutchis
          if (MCycle[5] )
2683 2 ghutchis
            begin
2684
              Inc_PC = 1'b1;
2685
              if (Mode == 1 )
2686
                begin
2687
                  Set_Addr_To = aXY;
2688
                  TStates = 3'b100;
2689
                  Set_BusB_To[2:0] = SSS;
2690
                  Set_BusB_To[3] = 1'b0;
2691
                end
2692
              if (IRB == 8'b00110110 || IRB == 8'b11001011 )
2693
                begin
2694
                  Set_Addr_To = aNone;
2695
                end
2696
            end
2697 21 ghutchis
          if (MCycle[6] )
2698 2 ghutchis
            begin
2699
              if (Mode == 0 )
2700
                begin
2701
                  TStates = 3'b101;
2702
                end
2703
              if (ISet != 2'b01 )
2704
                begin
2705
                  Set_Addr_To = aXY;
2706
                end
2707
              Set_BusB_To[2:0] = SSS;
2708
              Set_BusB_To[3] = 1'b0;
2709
              if (IRB == 8'b00110110 || ISet == 2'b01 )
2710
                begin
2711
                  // LD (HL),n
2712
                  Inc_PC = 1'b1;
2713
                end
2714
              else
2715
                begin
2716
                  NoRead = 1'b1;
2717
                end
2718
            end
2719
        end // if (Mode < 2 )      
2720
 
2721
    end // always @ (IR, ISet, MCycle, F, NMICycle, IntCycle)
2722
 
2723
// synopsys dc_script_begin
2724 23 ghutchis
// set_attribute current_design "revision" "$Id: tv80_mcode.v,v 1.3 2004-09-22 18:07:14 ghutchis Exp $" -type string -quiet
2725 2 ghutchis
// synopsys dc_script_end
2726
endmodule // T80_MCode
2727
 
2728
 
2729
 

powered by: WebSVN 2.1.0

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