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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc2/] [rtl/] [core/] [tv80_mcode.v] - Blame information for rev 46

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

powered by: WebSVN 2.1.0

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