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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc2/] [rtl/] [core/] [tv80_mcode_base.v] - Blame information for rev 106

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

Line No. Rev Author Line
1 48 ghutchis
//
2
// TV80 8-Bit Microprocessor Core
3
// Based on the VHDL T80 core by Daniel Wallner (jesus@opencores.org)
4
//
5
// Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a 
8
// copy of this software and associated documentation files (the "Software"), 
9
// to deal in the Software without restriction, including without limitation 
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
11
// and/or sell copies of the Software, and to permit persons to whom the 
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included 
15
// in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
19
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
20
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
21
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
22
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
23
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
25
module tv80_mcode_base
26
  (/*AUTOARG*/
27
  // Outputs
28
  output_vector,
29
  // Inputs
30 51 ghutchis
  IR, MCycle, F, NMICycle, IntCycle, tstate
31 48 ghutchis
  );
32
 
33
  parameter             Mode   = 0;
34
  parameter             Flag_C = 0;
35
  parameter             Flag_N = 1;
36
  parameter             Flag_P = 2;
37
  parameter             Flag_X = 3;
38
  parameter             Flag_H = 4;
39
  parameter             Flag_Y = 5;
40
  parameter             Flag_Z = 6;
41
  parameter             Flag_S = 7;
42
 
43
  output [67:0]         output_vector;
44
 
45
  input [7:0]           IR;
46
  input [6:0]           MCycle                  ;
47
  input [7:0]           F                       ;
48
  input                 NMICycle                ;
49
  input                 IntCycle                ;
50 51 ghutchis
  input [6:0]           tstate;
51 48 ghutchis
 
52
  // regs
53
  reg [2:0]             MCycles                 ;
54
  reg [2:0]             TStates                 ;
55
  reg [1:0]             Prefix                  ; // None,BC,ED,DD/FD
56
  reg                   Inc_PC                  ;
57
  reg                   Inc_WZ                  ;
58
  reg [3:0]             IncDec_16               ; // BC,DE,HL,SP   0 is inc
59
  reg                   Read_To_Reg             ;
60
  reg                   Read_To_Acc             ;
61
  reg [3:0]             Set_BusA_To     ; // B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
62
  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
63
  reg [3:0]             ALU_Op                  ;
64
  reg                   Save_ALU                ;
65
  reg                   PreserveC               ;
66
  reg                   Arith16                 ;
67
  reg [2:0]             Set_Addr_To             ; // aNone,aXY,aIOA,aSP,aBC,aDE,aZI
68
  reg                   IORQ                    ;
69
  reg                   Jump                    ;
70
  reg                   JumpE                   ;
71
  reg                   JumpXY                  ;
72
  reg                   Call                    ;
73
  reg                   RstP                    ;
74
  reg                   LDZ                     ;
75
  reg                   LDW                     ;
76
  reg                   LDSPHL                  ;
77
  reg [2:0]             Special_LD              ; // A,I;A,R;I,A;R,A;None
78
  reg                   ExchangeDH              ;
79
  reg                   ExchangeRp              ;
80
  reg                   ExchangeAF              ;
81
  reg                   ExchangeRS              ;
82
  reg                   I_DJNZ                  ;
83
  reg                   I_CPL                   ;
84
  reg                   I_CCF                   ;
85
  reg                   I_SCF                   ;
86
  reg                   I_RETN                  ;
87
  reg                   I_BT                    ;
88
  reg                   I_BC                    ;
89
  reg                   I_BTR                   ;
90
  reg                   I_RLD                   ;
91
  reg                   I_RRD                   ;
92
  reg                   I_INRC                  ;
93
  reg                   SetDI                   ;
94
  reg                   SetEI                   ;
95
  reg [1:0]             IMode                   ;
96
  reg                   Halt                    ;
97
  reg                   NoRead                  ;
98
  reg                   Write   ;
99
 
100
  parameter             aNone   = 3'b111;
101
  parameter             aBC     = 3'b000;
102
  parameter             aDE     = 3'b001;
103
  parameter             aXY     = 3'b010;
104
  parameter             aIOA    = 3'b100;
105
  parameter             aSP     = 3'b101;
106
  parameter             aZI     = 3'b110;
107
  //    constant aNone  : std_logic_vector[2:0] = 3'b000;
108
  //    constant aXY    : std_logic_vector[2:0] = 3'b001;
109
  //    constant aIOA   : std_logic_vector[2:0] = 3'b010;
110
  //    constant aSP    : std_logic_vector[2:0] = 3'b011;
111
  //    constant aBC    : std_logic_vector[2:0] = 3'b100;
112
  //    constant aDE    : std_logic_vector[2:0] = 3'b101;
113
  //    constant aZI    : std_logic_vector[2:0] = 3'b110;
114
 
115
  function is_cc_true;
116
    input [7:0] F;
117
    input [2:0] cc;
118
    begin
119
      if (Mode == 3 )
120
        begin
121
          case (cc)
122
            3'b000  : is_cc_true = F[7] == 1'b0; // NZ
123
            3'b001  : is_cc_true = F[7] == 1'b1; // Z
124
            3'b010  : is_cc_true = F[4] == 1'b0; // NC
125
            3'b011  : is_cc_true = F[4] == 1'b1; // C
126
            3'b100  : is_cc_true = 0;
127
            3'b101  : is_cc_true = 0;
128
            3'b110  : is_cc_true = 0;
129
            3'b111  : is_cc_true = 0;
130
          endcase
131
        end
132
      else
133
        begin
134
          case (cc)
135
            3'b000  : is_cc_true = F[6] == 1'b0; // NZ
136
            3'b001  : is_cc_true = F[6] == 1'b1; // Z
137
            3'b010  : is_cc_true = F[0] == 1'b0; // NC
138
            3'b011  : is_cc_true = F[0] == 1'b1; // C
139
            3'b100  : is_cc_true = F[2] == 1'b0; // PO
140
            3'b101  : is_cc_true = F[2] == 1'b1; // PE
141
            3'b110  : is_cc_true = F[7] == 1'b0; // P
142
            3'b111  : is_cc_true = F[7] == 1'b1; // M
143
          endcase
144
        end
145
    end
146
  endfunction // is_cc_true
147
 
148
 
149
  reg [2:0] DDD;
150
  reg [2:0] SSS;
151
  reg [1:0] DPAIR;
152
 
153 51 ghutchis
  always @ (/*AUTOSENSE*/F or IR or IntCycle or MCycle or NMICycle
154
            or tstate)
155 48 ghutchis
    begin
156
      DDD = IR[5:3];
157
      SSS = IR[2:0];
158
      DPAIR = IR[5:4];
159
 
160
      MCycles = 3'b001;
161
      if (MCycle[0] )
162
        begin
163
          TStates = 3'b100;
164
        end
165
      else
166
        begin
167
          TStates = 3'b011;
168
        end
169
      Prefix = 2'b00;
170
      Inc_PC = 1'b0;
171
      Inc_WZ = 1'b0;
172
      IncDec_16 = 4'b0000;
173
      Read_To_Acc = 1'b0;
174
      Read_To_Reg = 1'b0;
175
      Set_BusB_To = 4'b0000;
176
      Set_BusA_To = 4'b0000;
177
      ALU_Op = { 1'b0, IR[5:3] };
178
      Save_ALU = 1'b0;
179
      PreserveC = 1'b0;
180
      Arith16 = 1'b0;
181
      IORQ = 1'b0;
182
      Set_Addr_To = aNone;
183
      Jump = 1'b0;
184
      JumpE = 1'b0;
185
      JumpXY = 1'b0;
186
      Call = 1'b0;
187
      RstP = 1'b0;
188
      LDZ = 1'b0;
189
      LDW = 1'b0;
190
      LDSPHL = 1'b0;
191
      Special_LD = 3'b000;
192
      ExchangeDH = 1'b0;
193
      ExchangeRp = 1'b0;
194
      ExchangeAF = 1'b0;
195
      ExchangeRS = 1'b0;
196
      I_DJNZ = 1'b0;
197
      I_CPL = 1'b0;
198
      I_CCF = 1'b0;
199
      I_SCF = 1'b0;
200
      I_RETN = 1'b0;
201
      I_BT = 1'b0;
202
      I_BC = 1'b0;
203
      I_BTR = 1'b0;
204
      I_RLD = 1'b0;
205
      I_RRD = 1'b0;
206
      I_INRC = 1'b0;
207
      SetDI = 1'b0;
208
      SetEI = 1'b0;
209
      IMode = 2'b11;
210
      Halt = 1'b0;
211
      NoRead = 1'b0;
212
      Write = 1'b0;
213
 
214
 
215
      casex (IR)
216
        // 8 BIT LOAD GROUP
217
        8'b01xxxxxx :
218
          begin
219
            if (IR[5:0] == 6'b110110)
220
              Halt = 1'b1;
221
            else if (IR[2:0] == 3'b110)
222
              begin
223
                // LD r,(HL)
224
                MCycles = 3'b010;
225
                if (MCycle[0])
226
                  Set_Addr_To = aXY;
227
                if (MCycle[1])
228
                  begin
229
                    Set_BusA_To[2:0] = DDD;
230
                    Read_To_Reg = 1'b1;
231
                  end
232
              end // if (IR[2:0] == 3'b110)
233
            else if (IR[5:3] == 3'b110)
234
              begin
235
                // LD (HL),r
236
                MCycles = 3'b010;
237
                if (MCycle[0])
238
                  begin
239
                    Set_Addr_To = aXY;
240
                    Set_BusB_To[2:0] = SSS;
241
                    Set_BusB_To[3] = 1'b0;
242
                  end
243
                if (MCycle[1])
244
                  Write = 1'b1;
245
              end // if (IR[5:3] == 3'b110)
246
            else
247
              begin
248
                Set_BusB_To[2:0] = SSS;
249
                ExchangeRp = 1'b1;
250
                Set_BusA_To[2:0] = DDD;
251
                Read_To_Reg = 1'b1;
252
              end // else: !if(IR[5:3] == 3'b110)
253
          end // case: 8'b01xxxxxx                                    
254
 
255
        8'b00xxx110 :
256
          begin
257
            if (IR[5:3] == 3'b110)
258
              begin
259
                // LD (HL),n
260
                MCycles = 3'b011;
261
                if (MCycle[1])
262
                  begin
263
                    Inc_PC = 1'b1;
264
                    Set_Addr_To = aXY;
265
                    Set_BusB_To[2:0] = SSS;
266
                    Set_BusB_To[3] = 1'b0;
267
                  end
268
                if (MCycle[2])
269
                  Write = 1'b1;
270
              end // if (IR[5:3] == 3'b110)
271
            else
272
              begin
273
                // LD r,n
274
                MCycles = 3'b010;
275
                if (MCycle[1])
276
                  begin
277
                    Inc_PC = 1'b1;
278
                    Set_BusA_To[2:0] = DDD;
279
                    Read_To_Reg = 1'b1;
280
                  end
281
              end
282
          end
283
 
284
        8'b00001010  :
285
          begin
286
            // LD A,(BC)
287
            MCycles = 3'b010;
288
            if (MCycle[0])
289
              Set_Addr_To = aBC;
290
            if (MCycle[1])
291
              Read_To_Acc = 1'b1;
292
          end // case: 8'b00001010
293
 
294
        8'b00011010  :
295
          begin
296
            // LD A,(DE)
297
            MCycles = 3'b010;
298
            if (MCycle[0])
299
              Set_Addr_To = aDE;
300
            if (MCycle[1])
301
              Read_To_Acc = 1'b1;
302
          end // case: 8'b00011010
303
 
304
        8'b00111010  :
305
          begin
306
            if (Mode == 3 )
307
              begin
308
                // LDD A,(HL)
309
                MCycles = 3'b010;
310
                if (MCycle[0])
311
                  Set_Addr_To = aXY;
312
                if (MCycle[1])
313
                  begin
314
                    Read_To_Acc = 1'b1;
315
                    IncDec_16 = 4'b1110;
316
                  end
317
              end
318
            else
319
              begin
320
                // LD A,(nn)
321
                MCycles = 3'b100;
322
                if (MCycle[1])
323
                  begin
324
                    Inc_PC = 1'b1;
325
                    LDZ = 1'b1;
326
                  end
327
                if (MCycle[2])
328
                  begin
329
                    Set_Addr_To = aZI;
330
                    Inc_PC = 1'b1;
331
                  end
332
                if (MCycle[3])
333
                  begin
334
                    Read_To_Acc = 1'b1;
335
                  end
336
              end // else: !if(Mode == 3 )
337
          end // case: 8'b00111010
338
 
339
        8'b00000010  :
340
          begin
341
            // LD (BC),A
342
            MCycles = 3'b010;
343
            if (MCycle[0])
344
              begin
345
                Set_Addr_To = aBC;
346
                Set_BusB_To = 4'b0111;
347
              end
348
            if (MCycle[1])
349
              begin
350
                Write = 1'b1;
351
              end
352
          end // case: 8'b00000010
353
 
354
        8'b00010010  :
355
          begin
356
            // LD (DE),A
357
            MCycles = 3'b010;
358
            case (1'b1) // MCycle
359
              MCycle[0] :
360
                begin
361
                  Set_Addr_To = aDE;
362
                  Set_BusB_To = 4'b0111;
363
                end
364
              MCycle[1] :
365
                Write = 1'b1;
366
              default :;
367
            endcase // case(MCycle)
368
          end // case: 8'b00010010
369
 
370
        8'b00110010  :
371
          begin
372
            if (Mode == 3 )
373
              begin
374
                // LDD (HL),A
375
                MCycles = 3'b010;
376
                case (1'b1) // MCycle
377
                  MCycle[0] :
378
                    begin
379
                      Set_Addr_To = aXY;
380
                      Set_BusB_To = 4'b0111;
381
                    end
382
                  MCycle[1] :
383
                    begin
384
                      Write = 1'b1;
385
                      IncDec_16 = 4'b1110;
386
                    end
387
                  default :;
388
                endcase // case(MCycle)
389
 
390
              end
391
            else
392
              begin
393
                // LD (nn),A
394
                MCycles = 3'b100;
395
                case (1'b1) // MCycle
396
                  MCycle[1] :
397
                    begin
398
                      Inc_PC = 1'b1;
399
                      LDZ = 1'b1;
400
                    end
401
                  MCycle[2] :
402
                    begin
403
                      Set_Addr_To = aZI;
404
                      Inc_PC = 1'b1;
405
                      Set_BusB_To = 4'b0111;
406
                    end
407
                  MCycle[3] :
408
                    begin
409
                      Write = 1'b1;
410
                    end
411
                  default :;
412
                endcase
413
              end // else: !if(Mode == 3 )
414
          end // case: 8'b00110010
415
 
416
 
417
        // 16 BIT LOAD GROUP
418
        8'b00000001,8'b00010001,8'b00100001,8'b00110001  :
419
          begin
420
            // LD dd,nn
421
            MCycles = 3'b011;
422
            case (1'b1) // MCycle
423
              MCycle[1] :
424
                begin
425
                  Inc_PC = 1'b1;
426
                  Read_To_Reg = 1'b1;
427
                  if (DPAIR == 2'b11 )
428
                    begin
429
                      Set_BusA_To[3:0] = 4'b1000;
430
                    end
431
                  else
432
                    begin
433
                      Set_BusA_To[2:1] = DPAIR;
434
                      Set_BusA_To[0] = 1'b1;
435
                    end
436
                end // case: 2
437
 
438
              MCycle[2] :
439
                begin
440
                  Inc_PC = 1'b1;
441
                  Read_To_Reg = 1'b1;
442
                  if (DPAIR == 2'b11 )
443
                    begin
444
                      Set_BusA_To[3:0] = 4'b1001;
445
                    end
446
                  else
447
                    begin
448
                      Set_BusA_To[2:1] = DPAIR;
449
                      Set_BusA_To[0] = 1'b0;
450
                    end
451
                end // case: 3
452
 
453
              default :;
454
            endcase // case(MCycle)
455
          end // case: 8'b00000001,8'b00010001,8'b00100001,8'b00110001
456
 
457
        8'b00101010  :
458
          begin
459
            if (Mode == 3 )
460
              begin
461
                // LDI A,(HL)
462
                MCycles = 3'b010;
463
                case (1'b1) // MCycle
464
                  MCycle[0] :
465
                    Set_Addr_To = aXY;
466
                  MCycle[1] :
467
                    begin
468
                      Read_To_Acc = 1'b1;
469
                      IncDec_16 = 4'b0110;
470
                    end
471
 
472
                  default :;
473
                endcase
474
              end
475
            else
476
              begin
477
                // LD HL,(nn)
478
                MCycles = 3'b101;
479
                case (1'b1) // MCycle
480
                  MCycle[1] :
481
                    begin
482
                      Inc_PC = 1'b1;
483
                      LDZ = 1'b1;
484
                    end
485
                  MCycle[2] :
486
                    begin
487
                      Set_Addr_To = aZI;
488
                      Inc_PC = 1'b1;
489
                      LDW = 1'b1;
490
                    end
491
                  MCycle[3] :
492
                    begin
493
                      Set_BusA_To[2:0] = 3'b101; // L
494
                      Read_To_Reg = 1'b1;
495
                      Inc_WZ = 1'b1;
496
                      Set_Addr_To = aZI;
497
                    end
498
                  MCycle[4] :
499
                    begin
500
                      Set_BusA_To[2:0] = 3'b100; // H
501
                      Read_To_Reg = 1'b1;
502
                    end
503
                  default :;
504
                endcase
505
              end // else: !if(Mode == 3 )
506
          end // case: 8'b00101010
507
 
508
        8'b00100010  :
509
          begin
510
            if (Mode == 3 )
511
              begin
512
                // LDI (HL),A
513
                MCycles = 3'b010;
514
                case (1'b1) // MCycle
515
                  MCycle[0] :
516
                    begin
517
                      Set_Addr_To = aXY;
518
                      Set_BusB_To = 4'b0111;
519
                    end
520
                  MCycle[1] :
521
                    begin
522
                      Write = 1'b1;
523
                      IncDec_16 = 4'b0110;
524
                    end
525
                  default :;
526
                endcase
527
              end
528
            else
529
              begin
530
                // LD (nn),HL
531
                MCycles = 3'b101;
532
                case (1'b1) // MCycle                        
533
                  MCycle[1] :
534
                    begin
535
                      Inc_PC = 1'b1;
536
                      LDZ = 1'b1;
537
                    end
538
 
539
                  MCycle[2] :
540
                    begin
541
                      Set_Addr_To = aZI;
542
                      Inc_PC = 1'b1;
543
                      LDW = 1'b1;
544
                      Set_BusB_To = 4'b0101; // L
545
                    end
546
 
547
                  MCycle[3] :
548
                    begin
549
                      Inc_WZ = 1'b1;
550
                      Set_Addr_To = aZI;
551
                      Write = 1'b1;
552
                      Set_BusB_To = 4'b0100; // H
553
                    end
554
                  MCycle[4] :
555
                    Write = 1'b1;
556
                  default :;
557
                endcase
558
              end // else: !if(Mode == 3 )
559
          end // case: 8'b00100010
560
 
561
        8'b11111001  :
562
          begin
563
            // LD SP,HL
564
            TStates = 3'b110;
565
            LDSPHL = 1'b1;
566
          end
567
 
568
        8'b11xx0101 :
569
          begin
570
            // PUSH qq
571
            MCycles = 3'b011;
572
            case (1'b1) // MCycle                    
573
              MCycle[0] :
574
                begin
575
                  TStates = 3'b101;
576
                  IncDec_16 = 4'b1111;
577
                  Set_Addr_To = aSP;
578
                  if (DPAIR == 2'b11 )
579
                    begin
580
                      Set_BusB_To = 4'b0111;
581
                    end
582
                  else
583
                    begin
584
                      Set_BusB_To[2:1] = DPAIR;
585
                      Set_BusB_To[0] = 1'b0;
586
                      Set_BusB_To[3] = 1'b0;
587
                    end
588
                end // case: 1
589
 
590
              MCycle[1] :
591
                begin
592
                  IncDec_16 = 4'b1111;
593
                  Set_Addr_To = aSP;
594
                  if (DPAIR == 2'b11 )
595
                    begin
596
                      Set_BusB_To = 4'b1011;
597
                    end
598
                  else
599
                    begin
600
                      Set_BusB_To[2:1] = DPAIR;
601
                      Set_BusB_To[0] = 1'b1;
602
                      Set_BusB_To[3] = 1'b0;
603
                    end
604
                  Write = 1'b1;
605
                end // case: 2
606
 
607
              MCycle[2] :
608
                Write = 1'b1;
609
              default :;
610
            endcase // case(MCycle)
611
          end // case: 8'b11000101,8'b11010101,8'b11100101,8'b11110101
612
 
613
        8'b11xx0001 :
614
          begin
615
            // POP qq
616
            MCycles = 3'b011;
617
            case (1'b1) // MCycle
618
              MCycle[0] :
619
                Set_Addr_To = aSP;
620
              MCycle[1] :
621
                begin
622
                  IncDec_16 = 4'b0111;
623
                  Set_Addr_To = aSP;
624
                  Read_To_Reg = 1'b1;
625
                  if (DPAIR == 2'b11 )
626
                    begin
627
                      Set_BusA_To[3:0] = 4'b1011;
628
                    end
629
                  else
630
                    begin
631
                      Set_BusA_To[2:1] = DPAIR;
632
                      Set_BusA_To[0] = 1'b1;
633
                    end
634
                end // case: 2
635
 
636
              MCycle[2] :
637
                begin
638
                  IncDec_16 = 4'b0111;
639
                  Read_To_Reg = 1'b1;
640
                  if (DPAIR == 2'b11 )
641
                    begin
642
                      Set_BusA_To[3:0] = 4'b0111;
643
                    end
644
                  else
645
                    begin
646
                      Set_BusA_To[2:1] = DPAIR;
647
                      Set_BusA_To[0] = 1'b0;
648
                    end
649
                end // case: 3
650
 
651
              default :;
652
            endcase // case(MCycle)
653
          end // case: 8'b11000001,8'b11010001,8'b11100001,8'b11110001
654
 
655
 
656
        // EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
657
        8'b11101011  :
658
          begin
659
            if (Mode != 3 )
660
              begin
661
                // EX DE,HL
662 51 ghutchis
 
663
                case (1'b1)
664
                  tstate[3] :
665
                    begin
666
                      Set_BusA_To = 4'b0100;
667
                      Set_BusB_To = 4'b0010;
668
                      ExchangeDH = 1'b1;
669
                    end
670
 
671
                  tstate[4] :
672
                    begin
673
                      Set_BusA_To = 4'b0010;
674
                      ExchangeDH = 1'b1;
675
                    end
676
 
677
                  default :;
678
                endcase
679 48 ghutchis
              end
680
          end
681
 
682
        8'b00001000  :
683
          begin
684
            if (Mode == 3 )
685
              begin
686
                // LD (nn),SP
687
                MCycles = 3'b101;
688
                case (1'b1) // MCycle
689
                  MCycle[1] :
690
                    begin
691
                      Inc_PC = 1'b1;
692
                      LDZ = 1'b1;
693
                    end
694
 
695
                  MCycle[2] :
696
                    begin
697
                      Set_Addr_To = aZI;
698
                      Inc_PC = 1'b1;
699
                      LDW = 1'b1;
700
                      Set_BusB_To = 4'b1000;
701
                    end
702
 
703
                  MCycle[3] :
704
                    begin
705
                      Inc_WZ = 1'b1;
706
                      Set_Addr_To = aZI;
707
                      Write = 1'b1;
708
                      Set_BusB_To = 4'b1001;
709
                    end
710
 
711
                  MCycle[4] :
712
                    Write = 1'b1;
713
                  default :;
714
                endcase
715
              end
716
            else if (Mode < 2 )
717
              begin
718
                // EX AF,AF'
719
                ExchangeAF = 1'b1;
720
              end
721
          end // case: 8'b00001000
722
 
723
        8'b11011001  :
724
          begin
725
            if (Mode == 3 )
726
              begin
727
                // RETI
728
                MCycles = 3'b011;
729
                case (1'b1) // MCycle
730
                  MCycle[0] :
731
                    Set_Addr_To = aSP;
732
                  MCycle[1] :
733
                    begin
734
                      IncDec_16 = 4'b0111;
735
                      Set_Addr_To = aSP;
736
                      LDZ = 1'b1;
737
                    end
738
 
739
                  MCycle[2] :
740
                    begin
741
                      Jump = 1'b1;
742
                      IncDec_16 = 4'b0111;
743
                      I_RETN = 1'b1;
744
                      SetEI = 1'b1;
745
                    end
746
                  default :;
747
                endcase
748
              end
749
            else if (Mode < 2 )
750
              begin
751
                // EXX
752
                ExchangeRS = 1'b1;
753
              end
754
          end // case: 8'b11011001
755
 
756
        8'b11100011  :
757
          begin
758
            if (Mode != 3 )
759
              begin
760
                // EX (SP),HL
761
                MCycles = 3'b101;
762
                case (1'b1) // MCycle
763
                  MCycle[0] :
764
                    Set_Addr_To = aSP;
765
                  MCycle[1] :
766
                    begin
767
                      Read_To_Reg = 1'b1;
768
                      Set_BusA_To = 4'b0101;
769
                      Set_BusB_To = 4'b0101;
770
                      Set_Addr_To = aSP;
771
                    end
772
                  MCycle[2] :
773
                    begin
774
                      IncDec_16 = 4'b0111;
775
                      Set_Addr_To = aSP;
776
                      TStates = 3'b100;
777
                      Write = 1'b1;
778
                    end
779
                  MCycle[3] :
780
                    begin
781
                      Read_To_Reg = 1'b1;
782
                      Set_BusA_To = 4'b0100;
783
                      Set_BusB_To = 4'b0100;
784
                      Set_Addr_To = aSP;
785
                    end
786
                  MCycle[4] :
787
                    begin
788
                      IncDec_16 = 4'b1111;
789
                      TStates = 3'b101;
790
                      Write = 1'b1;
791
                    end
792
 
793
                  default :;
794
                endcase
795
              end // if (Mode != 3 )
796
          end // case: 8'b11100011
797
 
798
 
799
        // 8 BIT ARITHMETIC AND LOGICAL GROUP
800
        8'b10xxxxxx :
801
          begin
802
            if (IR[2:0] == 3'b110)
803
              begin
804
                // ADD A,(HL)
805
                // ADC A,(HL)
806
                // SUB A,(HL)
807
                // SBC A,(HL)
808
                // AND A,(HL)
809
                // OR A,(HL)
810
                // XOR A,(HL)
811
                // CP A,(HL)
812
                MCycles = 3'b010;
813
                case (1'b1) // MCycle
814
                  MCycle[0] :
815
                    Set_Addr_To = aXY;
816
                  MCycle[1] :
817
                    begin
818
                      Read_To_Reg = 1'b1;
819
                      Save_ALU = 1'b1;
820
                      Set_BusB_To[2:0] = SSS;
821
                      Set_BusA_To[2:0] = 3'b111;
822
                    end
823
 
824
                  default :;
825
                endcase // case(MCycle)
826
              end // if (IR[2:0] == 3'b110)
827
            else
828
              begin
829
                // ADD A,r
830
                // ADC A,r
831
                // SUB A,r
832
                // SBC A,r
833
                // AND A,r
834
                // OR A,r
835
                // XOR A,r
836
                // CP A,r
837
                Set_BusB_To[2:0] = SSS;
838
                Set_BusA_To[2:0] = 3'b111;
839
                Read_To_Reg = 1'b1;
840
                Save_ALU = 1'b1;
841
              end // else: !if(IR[2:0] == 3'b110)                  
842
          end // case: 8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,...
843
 
844
        8'b11xxx110 :
845
          begin
846
            // ADD A,n
847
            // ADC A,n
848
            // SUB A,n
849
            // SBC A,n
850
            // AND A,n
851
            // OR A,n
852
            // XOR A,n
853
            // CP A,n
854
            MCycles = 3'b010;
855
            if (MCycle[1] )
856
              begin
857
                Inc_PC = 1'b1;
858
                Read_To_Reg = 1'b1;
859
                Save_ALU = 1'b1;
860
                Set_BusB_To[2:0] = SSS;
861
                Set_BusA_To[2:0] = 3'b111;
862
              end
863
          end
864
 
865
        8'b00xxx100 :
866
          begin
867
            if (IR[5:3] == 3'b110)
868
              begin
869
                // INC (HL)
870
                MCycles = 3'b011;
871
                case (1'b1) // MCycle
872
                  MCycle[0] :
873
                    Set_Addr_To = aXY;
874
                  MCycle[1] :
875
                    begin
876
                      TStates = 3'b100;
877
                      Set_Addr_To = aXY;
878
                      Read_To_Reg = 1'b1;
879
                      Save_ALU = 1'b1;
880
                      PreserveC = 1'b1;
881
                      ALU_Op = 4'b0000;
882
                      Set_BusB_To = 4'b1010;
883
                      Set_BusA_To[2:0] = DDD;
884
                    end // case: 2
885
 
886
                  MCycle[2] :
887
                    Write = 1'b1;
888
                  default :;
889
                endcase // case(MCycle)
890
              end // case: 8'b00110100
891
            else
892
              begin
893
                // INC r
894
                Set_BusB_To = 4'b1010;
895
                Set_BusA_To[2:0] = DDD;
896
                Read_To_Reg = 1'b1;
897
                Save_ALU = 1'b1;
898
                PreserveC = 1'b1;
899
                ALU_Op = 4'b0000;
900
              end
901
          end
902
 
903
        8'b00xxx101 :
904
          begin
905
            if (IR[5:3] == 3'b110)
906
              begin
907
                // DEC (HL)
908
                MCycles = 3'b011;
909
                case (1'b1) // MCycle
910
                  MCycle[0] :
911
                    Set_Addr_To = aXY;
912
                  MCycle[1] :
913
                    begin
914
                      TStates = 3'b100;
915
                      Set_Addr_To = aXY;
916
                      ALU_Op = 4'b0010;
917
                      Read_To_Reg = 1'b1;
918
                      Save_ALU = 1'b1;
919
                      PreserveC = 1'b1;
920
                      Set_BusB_To = 4'b1010;
921
                      Set_BusA_To[2:0] = DDD;
922
                    end // case: 2
923
 
924
                  MCycle[2] :
925
                    Write = 1'b1;
926
                  default :;
927
                endcase // case(MCycle)
928
              end
929
            else
930
              begin
931
                // DEC r
932
                Set_BusB_To = 4'b1010;
933
                Set_BusA_To[2:0] = DDD;
934
                Read_To_Reg = 1'b1;
935
                Save_ALU = 1'b1;
936
                PreserveC = 1'b1;
937
                ALU_Op = 4'b0010;
938
              end
939
          end
940
 
941
        // GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
942
        8'b00100111  :
943
          begin
944
            // DAA
945
            Set_BusA_To[2:0] = 3'b111;
946
            Read_To_Reg = 1'b1;
947
            ALU_Op = 4'b1100;
948
            Save_ALU = 1'b1;
949
          end
950
 
951
        8'b00101111  :
952
          // CPL
953
          I_CPL = 1'b1;
954
 
955
        8'b00111111  :
956
          // CCF
957
          I_CCF = 1'b1;
958
 
959
        8'b00110111  :
960
          // SCF
961
          I_SCF = 1'b1;
962
 
963
        8'b00000000  :
964
          begin
965
            if (NMICycle == 1'b1 )
966
              begin
967
                // NMI
968
                MCycles = 3'b011;
969
                case (1'b1) // MCycle
970
                  MCycle[0] :
971
                    begin
972
                      TStates = 3'b101;
973
                      IncDec_16 = 4'b1111;
974
                      Set_Addr_To = aSP;
975
                      Set_BusB_To = 4'b1101;
976
                    end
977
 
978
                  MCycle[1] :
979
                    begin
980
                      TStates = 3'b100;
981
                      Write = 1'b1;
982
                      IncDec_16 = 4'b1111;
983
                      Set_Addr_To = aSP;
984
                      Set_BusB_To = 4'b1100;
985
                    end
986
 
987
                  MCycle[2] :
988
                    begin
989
                      TStates = 3'b100;
990
                      Write = 1'b1;
991
                    end
992
 
993
                  default :;
994
                endcase // case(MCycle)
995
 
996
              end
997
            else if (IntCycle == 1'b1 )
998
              begin
999
                // INT (IM 2)
1000
                MCycles = 3'b101;
1001
                case (1'b1) // MCycle
1002
                  MCycle[0] :
1003
                    begin
1004
                      LDZ = 1'b1;
1005
                      TStates = 3'b101;
1006
                      IncDec_16 = 4'b1111;
1007
                      Set_Addr_To = aSP;
1008
                      Set_BusB_To = 4'b1101;
1009
                    end
1010
 
1011
                  MCycle[1] :
1012
                    begin
1013
                      TStates = 3'b100;
1014
                      Write = 1'b1;
1015
                      IncDec_16 = 4'b1111;
1016
                      Set_Addr_To = aSP;
1017
                      Set_BusB_To = 4'b1100;
1018
                    end
1019
 
1020
                  MCycle[2] :
1021
                    begin
1022
                      TStates = 3'b100;
1023
                      Write = 1'b1;
1024
                    end
1025
 
1026
                  MCycle[3] :
1027
                    begin
1028
                      Inc_PC = 1'b1;
1029
                      LDZ = 1'b1;
1030
                    end
1031
 
1032
                  MCycle[4] :
1033
                    Jump = 1'b1;
1034
                  default :;
1035
                endcase
1036
              end
1037
          end // case: 8'b00000000
1038
 
1039
        8'b11110011  :
1040
          // DI
1041
          SetDI = 1'b1;
1042
 
1043
        8'b11111011  :
1044
          // EI
1045
          SetEI = 1'b1;
1046
 
1047
        // 16 BIT ARITHMETIC GROUP
1048
        8'b00001001,8'b00011001,8'b00101001,8'b00111001  :
1049
          begin
1050
            // ADD HL,ss
1051
            MCycles = 3'b011;
1052
            case (1'b1) // MCycle
1053
              MCycle[1] :
1054
                begin
1055
                  NoRead = 1'b1;
1056
                  ALU_Op = 4'b0000;
1057
                  Read_To_Reg = 1'b1;
1058
                  Save_ALU = 1'b1;
1059
                  Set_BusA_To[2:0] = 3'b101;
1060
                  case (IR[5:4])
1061
                    0,1,2  :
1062
                      begin
1063
                        Set_BusB_To[2:1] = IR[5:4];
1064
                        Set_BusB_To[0] = 1'b1;
1065
                      end
1066
 
1067
                    default :
1068
                      Set_BusB_To = 4'b1000;
1069
                  endcase // case(IR[5:4])
1070
 
1071
                  TStates = 3'b100;
1072
                  Arith16 = 1'b1;
1073
                end // case: 2
1074
 
1075
              MCycle[2] :
1076
                begin
1077
                  NoRead = 1'b1;
1078
                  Read_To_Reg = 1'b1;
1079
                  Save_ALU = 1'b1;
1080
                  ALU_Op = 4'b0001;
1081
                  Set_BusA_To[2:0] = 3'b100;
1082
                  case (IR[5:4])
1083
                    0,1,2  :
1084
                      Set_BusB_To[2:1] = IR[5:4];
1085
                    default :
1086
                      Set_BusB_To = 4'b1001;
1087
                  endcase
1088
                  Arith16 = 1'b1;
1089
                end // case: 3
1090
 
1091
              default :;
1092
            endcase // case(MCycle)
1093
          end // case: 8'b00001001,8'b00011001,8'b00101001,8'b00111001              
1094
 
1095
        8'b00000011,8'b00010011,8'b00100011,8'b00110011  :
1096
          begin
1097
            // INC ss
1098
            TStates = 3'b110;
1099
            IncDec_16[3:2] = 2'b01;
1100
            IncDec_16[1:0] = DPAIR;
1101
          end
1102
 
1103
        8'b00001011,8'b00011011,8'b00101011,8'b00111011  :
1104
          begin
1105
            // DEC ss
1106
            TStates = 3'b110;
1107
            IncDec_16[3:2] = 2'b11;
1108
            IncDec_16[1:0] = DPAIR;
1109
          end
1110
 
1111
        // ROTATE AND SHIFT GROUP
1112
        8'b00000111,
1113
            // RLCA
1114
            8'b00010111,
1115
            // RLA
1116
            8'b00001111,
1117
            // RRCA
1118
            8'b00011111 :
1119
              // RRA
1120
              begin
1121
                Set_BusA_To[2:0] = 3'b111;
1122
                ALU_Op = 4'b1000;
1123
                Read_To_Reg = 1'b1;
1124
                Save_ALU = 1'b1;
1125
              end // case: 8'b00000111,...
1126
 
1127
 
1128
        // JUMP GROUP
1129
        8'b11000011  :
1130
          begin
1131
            // JP nn
1132
            MCycles = 3'b011;
1133
            if (MCycle[1])
1134
              begin
1135
                Inc_PC = 1'b1;
1136
                LDZ = 1'b1;
1137
              end
1138
 
1139
            if (MCycle[2])
1140
              begin
1141
                Inc_PC = 1'b1;
1142
                Jump = 1'b1;
1143
              end
1144
 
1145
          end // case: 8'b11000011
1146
 
1147
        8'b11000010,8'b11001010,8'b11010010,8'b11011010,8'b11100010,8'b11101010,8'b11110010,8'b11111010  :
1148
          begin
1149
            if (IR[5] == 1'b1 && Mode == 3 )
1150
              begin
1151
                case (IR[4:3])
1152
                  2'b00  :
1153
                    begin
1154
                      // LD ($FF00+C),A
1155
                      MCycles = 3'b010;
1156
                      case (1'b1) // MCycle
1157
                        MCycle[0] :
1158
                          begin
1159
                            Set_Addr_To = aBC;
1160
                            Set_BusB_To   = 4'b0111;
1161
                          end
1162
                        MCycle[1] :
1163
                          begin
1164
                            Write = 1'b1;
1165
                            IORQ = 1'b1;
1166
                          end
1167
 
1168
                        default :;
1169
                      endcase // case(MCycle)
1170
                    end // case: 2'b00
1171
 
1172
                  2'b01  :
1173
                    begin
1174
                      // LD (nn),A
1175
                      MCycles = 3'b100;
1176
                      case (1'b1) // MCycle
1177
                        MCycle[1] :
1178
                          begin
1179
                            Inc_PC = 1'b1;
1180
                            LDZ = 1'b1;
1181
                          end
1182
 
1183
                        MCycle[2] :
1184
                          begin
1185
                            Set_Addr_To = aZI;
1186
                            Inc_PC = 1'b1;
1187
                            Set_BusB_To = 4'b0111;
1188
                          end
1189
 
1190
                        MCycle[3] :
1191
                          Write = 1'b1;
1192
                        default :;
1193
                      endcase // case(MCycle)
1194
                    end // case: default :...
1195
 
1196
                  2'b10  :
1197
                    begin
1198
                      // LD A,($FF00+C)
1199
                      MCycles = 3'b010;
1200
                      case (1'b1) // MCycle
1201
                        MCycle[0] :
1202
                          Set_Addr_To = aBC;
1203
                        MCycle[1] :
1204
                          begin
1205
                            Read_To_Acc = 1'b1;
1206
                            IORQ = 1'b1;
1207
                          end
1208
                        default :;
1209
                      endcase // case(MCycle)
1210
                    end // case: 2'b10
1211
 
1212
                  2'b11  :
1213
                    begin
1214
                      // LD A,(nn)
1215
                      MCycles = 3'b100;
1216
                      case (1'b1) // MCycle
1217
                        MCycle[1] :
1218
                          begin
1219
                            Inc_PC = 1'b1;
1220
                            LDZ = 1'b1;
1221
                          end
1222
                        MCycle[2] :
1223
                          begin
1224
                            Set_Addr_To = aZI;
1225
                            Inc_PC = 1'b1;
1226
                          end
1227
                        MCycle[3] :
1228
                          Read_To_Acc = 1'b1;
1229
                        default :;
1230
                      endcase // case(MCycle)
1231
                    end
1232
                endcase
1233
              end
1234
            else
1235
              begin
1236
                // JP cc,nn
1237
                MCycles = 3'b011;
1238
                case (1'b1) // MCycle
1239
                  MCycle[1] :
1240
                    begin
1241
                      Inc_PC = 1'b1;
1242
                      LDZ = 1'b1;
1243
                    end
1244
                  MCycle[2] :
1245
                    begin
1246
                      Inc_PC = 1'b1;
1247
                      if (is_cc_true(F, IR[5:3]) )
1248
                        begin
1249
                          Jump = 1'b1;
1250
                        end
1251
                    end
1252
 
1253
                  default :;
1254
                endcase
1255
              end // else: !if(DPAIR == 2'b11 )
1256
          end // case: 8'b11000010,8'b11001010,8'b11010010,8'b11011010,8'b11100010,8'b11101010,8'b11110010,8'b11111010
1257
 
1258
        8'b00011000  :
1259
          begin
1260
            if (Mode != 2 )
1261
              begin
1262
                // JR e
1263
                MCycles = 3'b011;
1264
                case (1'b1) // MCycle
1265
                  MCycle[1] :
1266
                    Inc_PC = 1'b1;
1267
                  MCycle[2] :
1268
                    begin
1269
                      NoRead = 1'b1;
1270
                      JumpE = 1'b1;
1271
                      TStates = 3'b101;
1272
                    end
1273
                  default :;
1274
                endcase
1275
              end // if (Mode != 2 )
1276
          end // case: 8'b00011000
1277
 
1278
        8'b00111000  :
1279
          begin
1280
            if (Mode != 2 )
1281
              begin
1282
                // JR C,e
1283
                MCycles = 3'b011;
1284
                case (1'b1) // MCycle
1285
                  MCycle[1] :
1286
                    begin
1287
                      Inc_PC = 1'b1;
1288
                      if (F[Flag_C] == 1'b0 )
1289
                        begin
1290
                          MCycles = 3'b010;
1291
                        end
1292
                    end
1293
 
1294
                  MCycle[2] :
1295
                    begin
1296
                      NoRead = 1'b1;
1297
                      JumpE = 1'b1;
1298
                      TStates = 3'b101;
1299
                    end
1300
                  default :;
1301
                endcase
1302
              end // if (Mode != 2 )
1303
          end // case: 8'b00111000
1304
 
1305
        8'b00110000  :
1306
          begin
1307
            if (Mode != 2 )
1308
              begin
1309
                // JR NC,e
1310
                MCycles = 3'b011;
1311
                case (1'b1) // MCycle
1312
                  MCycle[1] :
1313
                    begin
1314
                      Inc_PC = 1'b1;
1315
                      if (F[Flag_C] == 1'b1 )
1316
                        begin
1317
                          MCycles = 3'b010;
1318
                        end
1319
                    end
1320
 
1321
                  MCycle[2] :
1322
                    begin
1323
                      NoRead = 1'b1;
1324
                      JumpE = 1'b1;
1325
                      TStates = 3'b101;
1326
                    end
1327
                  default :;
1328
                endcase
1329
              end // if (Mode != 2 )
1330
          end // case: 8'b00110000
1331
 
1332
        8'b00101000  :
1333
          begin
1334
            if (Mode != 2 )
1335
              begin
1336
                // JR Z,e
1337
                MCycles = 3'b011;
1338
                case (1'b1) // MCycle
1339
                  MCycle[1] :
1340
                    begin
1341
                      Inc_PC = 1'b1;
1342
                      if (F[Flag_Z] == 1'b0 )
1343
                        begin
1344
                          MCycles = 3'b010;
1345
                        end
1346
                    end
1347
 
1348
                  MCycle[2] :
1349
                    begin
1350
                      NoRead = 1'b1;
1351
                      JumpE = 1'b1;
1352
                      TStates = 3'b101;
1353
                    end
1354
 
1355
                  default :;
1356
                endcase
1357
              end // if (Mode != 2 )
1358
          end // case: 8'b00101000
1359
 
1360
        8'b00100000  :
1361
          begin
1362
            if (Mode != 2 )
1363
              begin
1364
                // JR NZ,e
1365
                MCycles = 3'b011;
1366
                case (1'b1) // MCycle
1367
                  MCycle[1] :
1368
                    begin
1369
                      Inc_PC = 1'b1;
1370
                      if (F[Flag_Z] == 1'b1 )
1371
                        begin
1372
                          MCycles = 3'b010;
1373
                        end
1374
                    end
1375
                  MCycle[2] :
1376
                    begin
1377
                      NoRead = 1'b1;
1378
                      JumpE = 1'b1;
1379
                      TStates = 3'b101;
1380
                    end
1381
                  default :;
1382
                endcase
1383
              end // if (Mode != 2 )
1384
          end // case: 8'b00100000
1385
 
1386
        8'b11101001  :
1387
          // JP (HL)
1388
          JumpXY = 1'b1;
1389
 
1390
        8'b00010000  :
1391
          begin
1392
            if (Mode == 3 )
1393
              begin
1394
                I_DJNZ = 1'b1;
1395
              end
1396
            else if (Mode < 2 )
1397
              begin
1398
                // DJNZ,e
1399
                MCycles = 3'b011;
1400
                case (1'b1) // MCycle
1401
                  MCycle[0] :
1402
                    begin
1403
                      TStates = 3'b101;
1404
                      I_DJNZ = 1'b1;
1405
                      Set_BusB_To = 4'b1010;
1406
                      Set_BusA_To[2:0] = 3'b000;
1407
                      Read_To_Reg = 1'b1;
1408
                      Save_ALU = 1'b1;
1409
                      ALU_Op = 4'b0010;
1410
                    end
1411
                  MCycle[1] :
1412
                    begin
1413
                      I_DJNZ = 1'b1;
1414
                      Inc_PC = 1'b1;
1415
                    end
1416
                  MCycle[2] :
1417
                    begin
1418
                      NoRead = 1'b1;
1419
                      JumpE = 1'b1;
1420
                      TStates = 3'b101;
1421
                    end
1422
                  default :;
1423
                endcase
1424
              end // if (Mode < 2 )
1425
          end // case: 8'b00010000
1426
 
1427
 
1428
        // CALL AND RETURN GROUP
1429
        8'b11001101  :
1430
          begin
1431
            // CALL nn
1432
            MCycles = 3'b101;
1433
            case (1'b1) // MCycle
1434
              MCycle[1] :
1435
                begin
1436
                  Inc_PC = 1'b1;
1437
                  LDZ = 1'b1;
1438
                end
1439
              MCycle[2] :
1440
                begin
1441
                  IncDec_16 = 4'b1111;
1442
                  Inc_PC = 1'b1;
1443
                  TStates = 3'b100;
1444
                  Set_Addr_To = aSP;
1445
                  LDW = 1'b1;
1446
                  Set_BusB_To = 4'b1101;
1447
                end
1448
              MCycle[3] :
1449
                begin
1450
                  Write = 1'b1;
1451
                  IncDec_16 = 4'b1111;
1452
                  Set_Addr_To = aSP;
1453
                  Set_BusB_To = 4'b1100;
1454
                end
1455
              MCycle[4] :
1456
                begin
1457
                  Write = 1'b1;
1458
                  Call = 1'b1;
1459
                end
1460
              default :;
1461
            endcase // case(MCycle)
1462
          end // case: 8'b11001101
1463
 
1464
        8'b11000100,8'b11001100,8'b11010100,8'b11011100,8'b11100100,8'b11101100,8'b11110100,8'b11111100  :
1465
          begin
1466
            if (IR[5] == 1'b0 || Mode != 3 )
1467
              begin
1468
                // CALL cc,nn
1469
                MCycles = 3'b101;
1470
                case (1'b1) // MCycle
1471
                  MCycle[1] :
1472
                    begin
1473
                      Inc_PC = 1'b1;
1474
                      LDZ = 1'b1;
1475
                    end
1476
                  MCycle[2] :
1477
                    begin
1478
                      Inc_PC = 1'b1;
1479
                      LDW = 1'b1;
1480
                      if (is_cc_true(F, IR[5:3]) )
1481
                        begin
1482
                          IncDec_16 = 4'b1111;
1483
                          Set_Addr_To = aSP;
1484
                          TStates = 3'b100;
1485
                          Set_BusB_To = 4'b1101;
1486
                        end
1487
                      else
1488
                        begin
1489
                          MCycles = 3'b011;
1490
                        end // else: !if(is_cc_true(F, IR[5:3]) )
1491
                    end // case: 3
1492
 
1493
                  MCycle[3] :
1494
                    begin
1495
                      Write = 1'b1;
1496
                      IncDec_16 = 4'b1111;
1497
                      Set_Addr_To = aSP;
1498
                      Set_BusB_To = 4'b1100;
1499
                    end
1500
 
1501
                  MCycle[4] :
1502
                    begin
1503
                      Write = 1'b1;
1504
                      Call = 1'b1;
1505
                    end
1506
 
1507
                  default :;
1508
                endcase
1509
              end // if (IR[5] == 1'b0 || Mode != 3 )
1510
          end // case: 8'b11000100,8'b11001100,8'b11010100,8'b11011100,8'b11100100,8'b11101100,8'b11110100,8'b11111100
1511
 
1512
        8'b11001001  :
1513
          begin
1514
            // RET
1515
            MCycles = 3'b011;
1516
            case (1'b1) // MCycle
1517
              MCycle[0] :
1518
                begin
1519
                  TStates = 3'b101;
1520
                  Set_Addr_To = aSP;
1521
                end
1522
 
1523
              MCycle[1] :
1524
                begin
1525
                  IncDec_16 = 4'b0111;
1526
                  Set_Addr_To = aSP;
1527
                  LDZ = 1'b1;
1528
                end
1529
 
1530
              MCycle[2] :
1531
                begin
1532
                  Jump = 1'b1;
1533
                  IncDec_16 = 4'b0111;
1534
                end
1535
 
1536
              default :;
1537
            endcase // case(MCycle)
1538
          end // case: 8'b11001001
1539
 
1540
        8'b11000000,8'b11001000,8'b11010000,8'b11011000,8'b11100000,8'b11101000,8'b11110000,8'b11111000  :
1541
          begin
1542
            if (IR[5] == 1'b1 && Mode == 3 )
1543
              begin
1544
                case (IR[4:3])
1545
                  2'b00  :
1546
                    begin
1547
                      // LD ($FF00+nn),A
1548
                      MCycles = 3'b011;
1549
                      case (1'b1) // MCycle
1550
                        MCycle[1] :
1551
                          begin
1552
                            Inc_PC = 1'b1;
1553
                            Set_Addr_To = aIOA;
1554
                            Set_BusB_To   = 4'b0111;
1555
                          end
1556
 
1557
                        MCycle[2] :
1558
                          Write = 1'b1;
1559
                        default :;
1560
                      endcase // case(MCycle)
1561
                    end // case: 2'b00
1562
 
1563
                  2'b01  :
1564
                    begin
1565
                      // ADD SP,n
1566
                      MCycles = 3'b011;
1567
                      case (1'b1) // MCycle
1568
                        MCycle[1] :
1569
                          begin
1570
                            ALU_Op = 4'b0000;
1571
                            Inc_PC = 1'b1;
1572
                            Read_To_Reg = 1'b1;
1573
                            Save_ALU = 1'b1;
1574
                            Set_BusA_To = 4'b1000;
1575
                            Set_BusB_To = 4'b0110;
1576
                          end
1577
 
1578
                        MCycle[2] :
1579
                          begin
1580
                            NoRead = 1'b1;
1581
                            Read_To_Reg = 1'b1;
1582
                            Save_ALU = 1'b1;
1583
                            ALU_Op = 4'b0001;
1584
                            Set_BusA_To = 4'b1001;
1585
                            Set_BusB_To = 4'b1110;        // Incorrect unsigned !!!!!!!!!!!!!!!!!!!!!
1586
                          end
1587
 
1588
                        default :;
1589
                      endcase // case(MCycle)
1590
                    end // case: 2'b01
1591
 
1592
                  2'b10  :
1593
                    begin
1594
                      // LD A,($FF00+nn)
1595
                      MCycles = 3'b011;
1596
                      case (1'b1) // MCycle
1597
                        MCycle[1] :
1598
                          begin
1599
                            Inc_PC = 1'b1;
1600
                            Set_Addr_To = aIOA;
1601
                          end
1602
 
1603
                        MCycle[2] :
1604
                          Read_To_Acc = 1'b1;
1605
                        default :;
1606
                      endcase // case(MCycle)
1607
                    end // case: 2'b10
1608
 
1609
                  2'b11  :
1610
                    begin
1611
                      // LD HL,SP+n       -- Not correct !!!!!!!!!!!!!!!!!!!
1612
                      MCycles = 3'b101;
1613
                      case (1'b1) // MCycle
1614
                        MCycle[1] :
1615
                          begin
1616
                            Inc_PC = 1'b1;
1617
                            LDZ = 1'b1;
1618
                          end
1619
 
1620
                        MCycle[2] :
1621
                          begin
1622
                            Set_Addr_To = aZI;
1623
                            Inc_PC = 1'b1;
1624
                            LDW = 1'b1;
1625
                          end
1626
 
1627
                        MCycle[3] :
1628
                          begin
1629
                            Set_BusA_To[2:0] = 3'b101; // L
1630
                            Read_To_Reg = 1'b1;
1631
                            Inc_WZ = 1'b1;
1632
                            Set_Addr_To = aZI;
1633
                          end
1634
 
1635
                        MCycle[4] :
1636
                          begin
1637
                            Set_BusA_To[2:0] = 3'b100; // H
1638
                            Read_To_Reg = 1'b1;
1639
                          end
1640
 
1641
                        default :;
1642
                      endcase // case(MCycle)
1643
                    end // case: 2'b11
1644
 
1645
                endcase // case(IR[4:3])
1646
 
1647
              end
1648
            else
1649
              begin
1650
                // RET cc
1651
                MCycles = 3'b011;
1652
                case (1'b1) // MCycle
1653
                  MCycle[0] :
1654
                    begin
1655
                      if (is_cc_true(F, IR[5:3]) )
1656
                        begin
1657
                          Set_Addr_To = aSP;
1658
                        end
1659
                      else
1660
                        begin
1661
                          MCycles = 3'b001;
1662
                        end
1663
                      TStates = 3'b101;
1664
                    end // case: 1
1665
 
1666
                  MCycle[1] :
1667
                    begin
1668
                      IncDec_16 = 4'b0111;
1669
                      Set_Addr_To = aSP;
1670
                      LDZ = 1'b1;
1671
                    end
1672
                  MCycle[2] :
1673
                    begin
1674
                      Jump = 1'b1;
1675
                      IncDec_16 = 4'b0111;
1676
                    end
1677
                  default :;
1678
                endcase
1679
              end // else: !if(IR[5] == 1'b1 && Mode == 3 )
1680
          end // case: 8'b11000000,8'b11001000,8'b11010000,8'b11011000,8'b11100000,8'b11101000,8'b11110000,8'b11111000
1681
 
1682
        8'b11000111,8'b11001111,8'b11010111,8'b11011111,8'b11100111,8'b11101111,8'b11110111,8'b11111111  :
1683
          begin
1684
            // RST p
1685
            MCycles = 3'b011;
1686
            case (1'b1) // MCycle
1687
              MCycle[0] :
1688
                begin
1689
                  TStates = 3'b101;
1690
                  IncDec_16 = 4'b1111;
1691
                  Set_Addr_To = aSP;
1692
                  Set_BusB_To = 4'b1101;
1693
                end
1694
 
1695
              MCycle[1] :
1696
                begin
1697
                  Write = 1'b1;
1698
                  IncDec_16 = 4'b1111;
1699
                  Set_Addr_To = aSP;
1700
                  Set_BusB_To = 4'b1100;
1701
                end
1702
 
1703
              MCycle[2] :
1704
                begin
1705
                  Write = 1'b1;
1706
                  RstP = 1'b1;
1707
                end
1708
 
1709
              default :;
1710
            endcase // case(MCycle)
1711
          end // case: 8'b11000111,8'b11001111,8'b11010111,8'b11011111,8'b11100111,8'b11101111,8'b11110111,8'b11111111
1712
 
1713
        // INPUT AND OUTPUT GROUP
1714
        8'b11011011  :
1715
          begin
1716
            if (Mode != 3 )
1717
              begin
1718
                // IN A,(n)
1719
                MCycles = 3'b011;
1720
                case (1'b1) // MCycle
1721
                  MCycle[1] :
1722
                    begin
1723
                      Inc_PC = 1'b1;
1724
                      Set_Addr_To = aIOA;
1725
                    end
1726
 
1727
                  MCycle[2] :
1728
                    begin
1729
                      Read_To_Acc = 1'b1;
1730
                      IORQ = 1'b1;
1731
                    end
1732
 
1733
                  default :;
1734
                endcase
1735
              end // if (Mode != 3 )
1736
          end // case: 8'b11011011
1737
 
1738
        8'b11010011  :
1739
          begin
1740
            if (Mode != 3 )
1741
              begin
1742
                // OUT (n),A
1743
                MCycles = 3'b011;
1744
                case (1'b1) // MCycle
1745
                  MCycle[1] :
1746
                    begin
1747
                      Inc_PC = 1'b1;
1748
                      Set_Addr_To = aIOA;
1749
                      Set_BusB_To = 4'b0111;
1750
                    end
1751
 
1752
                  MCycle[2] :
1753
                    begin
1754
                      Write = 1'b1;
1755
                      IORQ = 1'b1;
1756
                    end
1757
 
1758
                  default :;
1759
                endcase
1760
              end // if (Mode != 3 )
1761
          end // case: 8'b11010011
1762
 
1763
 
1764
        //----------------------------------------------------------------------------
1765
        //----------------------------------------------------------------------------
1766
        // MULTIBYTE INSTRUCTIONS
1767
        //----------------------------------------------------------------------------
1768
        //----------------------------------------------------------------------------
1769
 
1770
        8'b11001011  :
1771
          begin
1772
            if (Mode != 2 )
1773
              begin
1774
                Prefix = 2'b01;
1775
              end
1776
          end
1777
 
1778
        8'b11101101  :
1779
          begin
1780
            if (Mode < 2 )
1781
              begin
1782
                Prefix = 2'b10;
1783
              end
1784
          end
1785
 
1786
        8'b11011101,8'b11111101  :
1787
          begin
1788
            if (Mode < 2 )
1789
              begin
1790
                Prefix = 2'b11;
1791
              end
1792
          end
1793
 
1794
      endcase // case(IR)
1795
 
1796
 
1797
    end // always @ (IR, ISet, MCycle, F, NMICycle, IntCycle)
1798
 
1799
  assign output_vector = { MCycles,
1800
                           TStates,
1801
                           Prefix,
1802
                           Inc_PC,
1803
                           Inc_WZ,
1804
                           IncDec_16,
1805
                           Read_To_Reg,
1806
                           Read_To_Acc,
1807
                           Set_BusA_To,
1808
                           Set_BusB_To,
1809
                           ALU_Op,
1810
                           Save_ALU,
1811
                           PreserveC,
1812
                           Arith16,
1813
                           Set_Addr_To,
1814
                           IORQ,
1815
                           Jump,
1816
                           JumpE,
1817
                           JumpXY,
1818
                           Call,
1819
                           RstP,
1820
                           LDZ,
1821
                           LDW,
1822
                           LDSPHL,
1823
                           Special_LD,
1824
                           ExchangeDH,
1825
                           ExchangeRp,
1826
                           ExchangeAF,
1827
                           ExchangeRS,
1828
                           I_DJNZ,
1829
                           I_CPL,
1830
                           I_CCF,
1831
                           I_SCF,
1832
                           I_RETN,
1833
                           I_BT,
1834
                           I_BC,
1835
                           I_BTR,
1836
                           I_RLD,
1837
                           I_RRD,
1838
                           I_INRC,
1839
                           SetDI,
1840
                           SetEI,
1841
                           IMode,
1842
                           Halt,
1843
                           NoRead,
1844
                           Write };
1845
 
1846
 
1847
  // synopsys dc_script_begin
1848 51 ghutchis
  // set_attribute current_design "revision" "$Id: tv80_mcode_base.v,v 1.1.2.2 2004-12-16 00:46:34 ghutchis Exp $" -type string -quiet
1849 48 ghutchis
  // synopsys dc_script_end
1850
endmodule // T80_MCode

powered by: WebSVN 2.1.0

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