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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc2/] [rtl/] [core/] [tv80_core.v] - Blame information for rev 112

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

Line No. Rev Author Line
1 2 ghutchis
//
2
// TV80 8-Bit Microprocessor Core
3
// Based on the VHDL T80 core by Daniel Wallner (jesus@opencores.org)
4
//
5
// Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a 
8
// copy of this software and associated documentation files (the "Software"), 
9
// to deal in the Software without restriction, including without limitation 
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
11
// and/or sell copies of the Software, and to permit persons to whom the 
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included 
15
// in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
19
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
20
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
21
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
22
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
23
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
25
module tv80_core (/*AUTOARG*/
26
  // Outputs
27
  m1_n, iorq, no_read, write, rfsh_n, halt_n, busak_n, A, do, mc, ts,
28
  intcycle_n, IntE, stop,
29
  // Inputs
30
  reset_n, clk, cen, wait_n, int_n, nmi_n, busrq_n, dinst, di
31
  );
32
  // Beginning of automatic inputs (from unused autoinst inputs)
33
  // End of automatics
34
 
35
  parameter Mode = 1;   // 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
36 24 ghutchis
  parameter IOWait = 1; // 0 => Single cycle I/O, 1 => Std I/O cycle
37 2 ghutchis
  parameter Flag_C = 0;
38
  parameter Flag_N = 1;
39
  parameter Flag_P = 2;
40
  parameter Flag_X = 3;
41
  parameter Flag_H = 4;
42
  parameter Flag_Y = 5;
43
  parameter Flag_Z = 6;
44
  parameter Flag_S = 7;
45
 
46
  input     reset_n;
47
  input     clk;
48
  input     cen;
49
  input     wait_n;
50
  input     int_n;
51
  input     nmi_n;
52
  input     busrq_n;
53
  output    m1_n;
54
  output    iorq;
55
  output    no_read;
56
  output    write;
57
  output    rfsh_n;
58
  output    halt_n;
59
  output    busak_n;
60
  output [15:0] A;
61
  input [7:0]   dinst;
62
  input [7:0]   di;
63
  output [7:0]  do;
64 21 ghutchis
  output [6:0]  mc;
65
  output [6:0]  ts;
66 2 ghutchis
  output        intcycle_n;
67
  output        IntE;
68
  output        stop;
69
 
70
  reg    m1_n;
71
  reg    iorq;
72
  reg    rfsh_n;
73
  reg    halt_n;
74
  reg    busak_n;
75
  reg [15:0] A;
76
  reg [7:0]  do;
77 21 ghutchis
  reg [6:0]  mc;
78
  reg [6:0]  ts;
79 2 ghutchis
  reg   intcycle_n;
80
  reg   IntE;
81
  reg   stop;
82
 
83
  parameter     aNone    = 3'b111;
84
  parameter     aBC      = 3'b000;
85
  parameter     aDE      = 3'b001;
86
  parameter     aXY      = 3'b010;
87
  parameter     aIOA     = 3'b100;
88
  parameter     aSP      = 3'b101;
89
  parameter     aZI      = 3'b110;
90
 
91
  // Registers
92
  reg [7:0]     ACC, F;
93
  reg [7:0]     Ap, Fp;
94
  reg [7:0]     I;
95
  reg [7:0]     R;
96
  reg [15:0]    SP, PC;
97
  reg [7:0]     RegDIH;
98
  reg [7:0]     RegDIL;
99
  wire [15:0]   RegBusA;
100
  wire [15:0]   RegBusB;
101
  wire [15:0]   RegBusC;
102
  reg [2:0]     RegAddrA_r;
103
  reg [2:0]     RegAddrA;
104
  reg [2:0]     RegAddrB_r;
105
  reg [2:0]     RegAddrB;
106
  reg [2:0]     RegAddrC;
107
  reg           RegWEH;
108
  reg           RegWEL;
109
  reg           Alternate;
110
 
111
  // Help Registers
112
  reg [15:0]    TmpAddr; // Temporary address register
113
  reg [7:0]     IR;              // Instruction register
114
  reg [1:0]     ISet;            // Instruction set selector
115
  reg [15:0]    RegBusA_r;
116
 
117
  reg [15:0]    ID16;
118
  reg [7:0]     Save_Mux;
119
 
120 21 ghutchis
  reg [6:0]     tstate;
121
  reg [6:0]     mcycle;
122
  reg           last_mcycle, last_tstate;
123 2 ghutchis
  reg           IntE_FF1;
124
  reg           IntE_FF2;
125
  reg           Halt_FF;
126
  reg           BusReq_s;
127
  reg           BusAck;
128
  reg           ClkEn;
129
  reg           NMI_s;
130
  reg           INT_s;
131
  reg [1:0]     IStatus;
132
 
133
  reg [7:0]     DI_Reg;
134
  reg           T_Res;
135
  reg [1:0]     XY_State;
136
  reg [2:0]     Pre_XY_F_M;
137
  reg           NextIs_XY_Fetch;
138
  reg           XY_Ind;
139
  reg           No_BTR;
140
  reg           BTR_r;
141
  reg           Auto_Wait;
142
  reg           Auto_Wait_t1;
143
  reg           Auto_Wait_t2;
144
  reg           IncDecZ;
145
 
146
  // ALU signals
147 51 ghutchis
  reg [7:0]     BusB, NextBusB;
148
  reg [7:0]     BusA, NextBusA;
149 2 ghutchis
  wire [7:0]    ALU_Q;
150
  wire [7:0]    F_Out;
151
 
152
  // Registered micro code outputs
153
  reg [4:0]     Read_To_Reg_r;
154
  reg           Arith16_r;
155
  reg           Z16_r;
156
  reg [3:0]     ALU_Op_r;
157
  reg           Save_ALU_r;
158
  reg           PreserveC_r;
159
  reg [2:0]     mcycles;
160
 
161
  // Micro code outputs
162
  wire [2:0]    mcycles_d;
163
  wire [2:0]    tstates;
164
  reg           IntCycle;
165
  reg           NMICycle;
166
  wire          Inc_PC;
167
  wire          Inc_WZ;
168
  wire [3:0]    IncDec_16;
169
  wire [1:0]    Prefix;
170
  wire          Read_To_Acc;
171
  wire          Read_To_Reg;
172
  wire [3:0]     Set_BusB_To;
173
  wire [3:0]     Set_BusA_To;
174
  wire [3:0]     ALU_Op;
175
  wire           Save_ALU;
176
  wire           PreserveC;
177
  wire           Arith16;
178
  wire [2:0]     Set_Addr_To;
179
  wire           Jump;
180
  wire           JumpE;
181
  wire           JumpXY;
182
  wire           Call;
183
  wire           RstP;
184
  wire           LDZ;
185
  wire           LDW;
186
  wire           LDSPHL;
187
  wire           iorq_i;
188
  wire [2:0]     Special_LD;
189
  wire           ExchangeDH;
190
  wire           ExchangeRp;
191
  wire           ExchangeAF;
192
  wire           ExchangeRS;
193
  wire           I_DJNZ;
194
  wire           I_CPL;
195
  wire           I_CCF;
196
  wire           I_SCF;
197
  wire           I_RETN;
198
  wire           I_BT;
199
  wire           I_BC;
200
  wire           I_BTR;
201
  wire           I_RLD;
202
  wire           I_RRD;
203
  wire           I_INRC;
204
  wire           SetDI;
205
  wire           SetEI;
206
  wire [1:0]     IMode;
207
  wire           Halt;
208
 
209
  reg [15:0]     PC16;
210
  reg [15:0]     PC16_B;
211
  reg [15:0]     SP16, SP16_A, SP16_B;
212
  reg [15:0]     ID16_B;
213
  reg            Oldnmi_n;
214
 
215
  tv80_mcode #(Mode, Flag_C, Flag_N, Flag_P, Flag_X, Flag_H, Flag_Y, Flag_Z, Flag_S) i_mcode
216
    (
217
     .IR                   (IR),
218
     .ISet                 (ISet),
219
     .MCycle               (mcycle),
220 51 ghutchis
     .tstate               (tstate),
221 2 ghutchis
     .F                    (F),
222
     .NMICycle             (NMICycle),
223
     .IntCycle             (IntCycle),
224
     .MCycles              (mcycles_d),
225
     .TStates              (tstates),
226
     .Prefix               (Prefix),
227
     .Inc_PC               (Inc_PC),
228
     .Inc_WZ               (Inc_WZ),
229
     .IncDec_16            (IncDec_16),
230
     .Read_To_Acc          (Read_To_Acc),
231
     .Read_To_Reg          (Read_To_Reg),
232
     .Set_BusB_To          (Set_BusB_To),
233
     .Set_BusA_To          (Set_BusA_To),
234
     .ALU_Op               (ALU_Op),
235
     .Save_ALU             (Save_ALU),
236
     .PreserveC            (PreserveC),
237
     .Arith16              (Arith16),
238
     .Set_Addr_To          (Set_Addr_To),
239
     .IORQ                 (iorq_i),
240
     .Jump                 (Jump),
241
     .JumpE                (JumpE),
242
     .JumpXY               (JumpXY),
243
     .Call                 (Call),
244
     .RstP                 (RstP),
245
     .LDZ                  (LDZ),
246
     .LDW                  (LDW),
247
     .LDSPHL               (LDSPHL),
248
     .Special_LD           (Special_LD),
249
     .ExchangeDH           (ExchangeDH),
250
     .ExchangeRp           (ExchangeRp),
251
     .ExchangeAF           (ExchangeAF),
252
     .ExchangeRS           (ExchangeRS),
253
     .I_DJNZ               (I_DJNZ),
254
     .I_CPL                (I_CPL),
255
     .I_CCF                (I_CCF),
256
     .I_SCF                (I_SCF),
257
     .I_RETN               (I_RETN),
258
     .I_BT                 (I_BT),
259
     .I_BC                 (I_BC),
260
     .I_BTR                (I_BTR),
261
     .I_RLD                (I_RLD),
262
     .I_RRD                (I_RRD),
263
     .I_INRC               (I_INRC),
264
     .SetDI                (SetDI),
265
     .SetEI                (SetEI),
266
     .IMode                (IMode),
267
     .Halt                 (Halt),
268
     .NoRead               (no_read),
269
     .Write                (write)
270
     );
271
 
272
  tv80_alu #(Mode, Flag_C, Flag_N, Flag_P, Flag_X, Flag_H, Flag_Y, Flag_Z, Flag_S) i_alu
273
    (
274
     .Arith16              (Arith16_r),
275
     .Z16                  (Z16_r),
276
     .ALU_Op               (ALU_Op_r),
277
     .IR                   (IR[5:0]),
278
     .ISet                 (ISet),
279
     .BusA                 (BusA),
280
     .BusB                 (BusB),
281
     .F_In                 (F),
282
     .Q                    (ALU_Q),
283
     .F_Out                (F_Out)
284
     );
285
 
286 21 ghutchis
  function [6:0] number_to_bitvec;
287
    input [2:0] num;
288
    begin
289
      case (num)
290
        1 : number_to_bitvec = 7'b0000001;
291
        2 : number_to_bitvec = 7'b0000010;
292
        3 : number_to_bitvec = 7'b0000100;
293
        4 : number_to_bitvec = 7'b0001000;
294
        5 : number_to_bitvec = 7'b0010000;
295
        6 : number_to_bitvec = 7'b0100000;
296
        7 : number_to_bitvec = 7'b1000000;
297
        default : number_to_bitvec = 7'bx;
298
      endcase // case(num)
299
    end
300
  endfunction // number_to_bitvec
301
 
302
  always @(/*AUTOSENSE*/mcycle or mcycles or tstate or tstates)
303
    begin
304
      case (mcycles)
305
        1 : last_mcycle = mcycle[0];
306
        2 : last_mcycle = mcycle[1];
307
        3 : last_mcycle = mcycle[2];
308
        4 : last_mcycle = mcycle[3];
309
        5 : last_mcycle = mcycle[4];
310
        6 : last_mcycle = mcycle[5];
311
        7 : last_mcycle = mcycle[6];
312
        default : last_mcycle = 1'bx;
313
      endcase // case(mcycles)
314
 
315
      case (tstates)
316
 
317
        1 : last_tstate = tstate[1];
318
        2 : last_tstate = tstate[2];
319
        3 : last_tstate = tstate[3];
320
        4 : last_tstate = tstate[4];
321
        5 : last_tstate = tstate[5];
322
        6 : last_tstate = tstate[6];
323
        default : last_tstate = 1'bx;
324
      endcase
325
    end // always @ (...
326
 
327
 
328 2 ghutchis
  always @(/*AUTOSENSE*/ALU_Q or BusAck or BusB or DI_Reg
329 21 ghutchis
           or ExchangeRp or IR or Save_ALU_r or Set_Addr_To or XY_Ind
330
           or XY_State or cen or last_tstate or mcycle)
331 2 ghutchis
    begin
332
      ClkEn = cen && ~ BusAck;
333
 
334 21 ghutchis
      if (last_tstate)
335 2 ghutchis
        T_Res = 1'b1;
336
      else T_Res = 1'b0;
337
 
338
      if (XY_State != 2'b00 && XY_Ind == 1'b0 &&
339
          ((Set_Addr_To == aXY) ||
340 21 ghutchis
           (mcycle[0] && IR == 8'b11001011) ||
341
           (mcycle[0] && IR == 8'b00110110)))
342 2 ghutchis
        NextIs_XY_Fetch = 1'b1;
343
      else
344
        NextIs_XY_Fetch = 1'b0;
345
 
346
      if (ExchangeRp)
347
        Save_Mux = BusB;
348
      else if (!Save_ALU_r)
349
        Save_Mux = DI_Reg;
350
      else
351
        Save_Mux = ALU_Q;
352
    end // always @ *
353
 
354
  always @ (posedge clk)
355
    begin
356
      if (reset_n == 1'b0 )
357
        begin
358
          PC <= #1 0;  // Program Counter
359
          A <= #1 0;
360
          TmpAddr <= #1 0;
361
          IR <= #1 8'b00000000;
362
          ISet <= #1 2'b00;
363
          XY_State <= #1 2'b00;
364
          IStatus <= #1 2'b00;
365
          mcycles <= #1 3'b000;
366
          do <= #1 8'b00000000;
367
 
368
          ACC <= #1 8'hFF;
369
          F <= #1 8'hFF;
370
          Ap <= #1 8'hFF;
371
          Fp <= #1 8'hFF;
372
          I <= #1 0;
373
          R <= #1 0;
374
          SP <= #1 16'hFFFF;
375
          Alternate <= #1 1'b0;
376
 
377
          Read_To_Reg_r <= #1 5'b00000;
378
          Arith16_r <= #1 1'b0;
379
          BTR_r <= #1 1'b0;
380
          Z16_r <= #1 1'b0;
381
          ALU_Op_r <= #1 4'b0000;
382
          Save_ALU_r <= #1 1'b0;
383
          PreserveC_r <= #1 1'b0;
384
          XY_Ind <= #1 1'b0;
385
        end
386
      else
387
        begin
388
 
389
          if (ClkEn == 1'b1 )
390
            begin
391
 
392
              ALU_Op_r <= #1 4'b0000;
393
              Save_ALU_r <= #1 1'b0;
394
              Read_To_Reg_r <= #1 5'b00000;
395
 
396
              mcycles <= #1 mcycles_d;
397
 
398
              if (IMode != 2'b11 )
399
                begin
400
                  IStatus <= #1 IMode;
401
                end
402
 
403
              Arith16_r <= #1 Arith16;
404
              PreserveC_r <= #1 PreserveC;
405 21 ghutchis
              if (ISet == 2'b10 && ALU_Op[2] == 1'b0 && ALU_Op[0] == 1'b1 && mcycle[2] )
406 2 ghutchis
                begin
407
                  Z16_r <= #1 1'b1;
408
                end
409
              else
410
                begin
411
                  Z16_r <= #1 1'b0;
412
                end
413
 
414 21 ghutchis
              if (mcycle[0] && (tstate[1] | tstate[2] | tstate[3] ))
415 2 ghutchis
                begin
416
                  // mcycle == 1 && tstate == 1, 2, || 3
417
 
418 21 ghutchis
                  if (tstate[2] && wait_n == 1'b1 )
419 2 ghutchis
                    begin
420
                      if (Mode < 2 )
421
                        begin
422
                          A[7:0] <= #1 R;
423
                          A[15:8] <= #1 I;
424
                          R[6:0] <= #1 R[6:0] + 1;
425
                        end
426
 
427
                      if (Jump == 1'b0 && Call == 1'b0 && NMICycle == 1'b0 && IntCycle == 1'b0 && ~ (Halt_FF == 1'b1 || Halt == 1'b1) )
428
                        begin
429
                          PC <= #1 PC16;
430
                        end
431
 
432
                      if (IntCycle == 1'b1 && IStatus == 2'b01 )
433
                        begin
434
                          IR <= #1 8'b11111111;
435
                        end
436
                      else if (Halt_FF == 1'b1 || (IntCycle == 1'b1 && IStatus == 2'b10) || NMICycle == 1'b1 )
437
                        begin
438
                          IR <= #1 8'b00000000;
439
                        end
440
                      else
441
                        begin
442
                          IR <= #1 dinst;
443
                        end
444
 
445
                      ISet <= #1 2'b00;
446
                      if (Prefix != 2'b00 )
447
                        begin
448
                          if (Prefix == 2'b11 )
449
                            begin
450
                              if (IR[5] == 1'b1 )
451
                                begin
452
                                  XY_State <= #1 2'b10;
453
                                end
454
                              else
455
                                begin
456
                                  XY_State <= #1 2'b01;
457
                                end
458
                            end
459
                          else
460
                            begin
461
                              if (Prefix == 2'b10 )
462
                                begin
463
                                  XY_State <= #1 2'b00;
464
                                  XY_Ind <= #1 1'b0;
465
                                end
466
                              ISet <= #1 Prefix;
467
                            end
468
                        end
469
                      else
470
                        begin
471
                          XY_State <= #1 2'b00;
472
                          XY_Ind <= #1 1'b0;
473
                        end
474
                    end // if (tstate == 2 && wait_n == 1'b1 )
475
 
476
 
477
                end
478
              else
479
                begin
480
                  // either (mcycle > 1) OR (mcycle == 1 AND tstate > 3)
481
 
482 21 ghutchis
                  if (mcycle[5] )
483 2 ghutchis
                    begin
484
                      XY_Ind <= #1 1'b1;
485
                      if (Prefix == 2'b01 )
486
                        begin
487
                          ISet <= #1 2'b01;
488
                        end
489
                    end
490
 
491
                  if (T_Res == 1'b1 )
492
                    begin
493
                      BTR_r <= #1 (I_BT || I_BC || I_BTR) && ~ No_BTR;
494
                      if (Jump == 1'b1 )
495
                        begin
496
                          A[15:8] <= #1 DI_Reg;
497
                          A[7:0] <= #1 TmpAddr[7:0];
498
                          PC[15:8] <= #1 DI_Reg;
499
                          PC[7:0] <= #1 TmpAddr[7:0];
500
                        end
501
                      else if (JumpXY == 1'b1 )
502
                        begin
503
                          A <= #1 RegBusC;
504
                          PC <= #1 RegBusC;
505
                        end else if (Call == 1'b1 || RstP == 1'b1 )
506
                          begin
507
                            A <= #1 TmpAddr;
508
                            PC <= #1 TmpAddr;
509
                          end
510 21 ghutchis
                        else if (last_mcycle && NMICycle == 1'b1 )
511 2 ghutchis
                          begin
512
                            A <= #1 16'b0000000001100110;
513
                            PC <= #1 16'b0000000001100110;
514
                          end
515 21 ghutchis
                        else if (mcycle[2] && IntCycle == 1'b1 && IStatus == 2'b10 )
516 2 ghutchis
                          begin
517
                            A[15:8] <= #1 I;
518
                            A[7:0] <= #1 TmpAddr[7:0];
519
                            PC[15:8] <= #1 I;
520
                            PC[7:0] <= #1 TmpAddr[7:0];
521
                          end
522
                        else
523
                          begin
524
                            case (Set_Addr_To)
525
                              aXY :
526
                                begin
527
                                  if (XY_State == 2'b00 )
528
                                    begin
529
                                      A <= #1 RegBusC;
530
                                    end
531
                                  else
532
                                    begin
533
                                      if (NextIs_XY_Fetch == 1'b1 )
534
                                        begin
535
                                          A <= #1 PC;
536
                                        end
537
                                      else
538
                                        begin
539
                                          A <= #1 TmpAddr;
540
                                        end
541
                                    end // else: !if(XY_State == 2'b00 )
542
                                end // case: aXY
543
 
544
                              aIOA :
545
                                begin
546
                                  if (Mode == 3 )
547
                                    begin
548
                                      // Memory map I/O on GBZ80
549
                                      A[15:8] <= #1 8'hFF;
550
                                    end
551
                                  else if (Mode == 2 )
552
                                    begin
553
                                      // Duplicate I/O address on 8080
554
                                      A[15:8] <= #1 DI_Reg;
555
                                    end
556
                                  else
557
                                    begin
558
                                      A[15:8] <= #1 ACC;
559
                                    end
560
                                  A[7:0] <= #1 DI_Reg;
561
                                end // case: aIOA
562
 
563
 
564
                              aSP :
565
                                begin
566
                                  A <= #1 SP;
567
                                end
568
 
569
                              aBC :
570
                                begin
571
                                  if (Mode == 3 && iorq_i == 1'b1 )
572
                                    begin
573
                                      // Memory map I/O on GBZ80
574
                                      A[15:8] <= #1 8'hFF;
575
                                      A[7:0] <= #1 RegBusC[7:0];
576
                                    end
577
                                  else
578
                                    begin
579
                                      A <= #1 RegBusC;
580
                                    end
581
                                end // case: aBC
582
 
583
                              aDE :
584
                                begin
585
                                  A <= #1 RegBusC;
586
                                end
587
 
588
                              aZI :
589
                                begin
590
                                  if (Inc_WZ == 1'b1 )
591
                                    begin
592
                                      A <= #1 TmpAddr + 1;
593
                                    end
594
                                  else
595
                                    begin
596
                                      A[15:8] <= #1 DI_Reg;
597
                                      A[7:0] <= #1 TmpAddr[7:0];
598
                                    end
599
                                end // case: aZI
600
 
601
                              default   :
602
                                begin
603
                                  A <= #1 PC;
604
                                end
605
                            endcase // case(Set_Addr_To)
606
 
607 21 ghutchis
                          end // else: !if(mcycle[2] && IntCycle == 1'b1 && IStatus == 2'b10 )
608 2 ghutchis
 
609
 
610
                      Save_ALU_r <= #1 Save_ALU;
611
                      ALU_Op_r <= #1 ALU_Op;
612
 
613
                      if (I_CPL == 1'b1 )
614
                        begin
615
                          // CPL
616
                          ACC <= #1 ~ ACC;
617
                          F[Flag_Y] <= #1 ~ ACC[5];
618
                          F[Flag_H] <= #1 1'b1;
619
                          F[Flag_X] <= #1 ~ ACC[3];
620
                          F[Flag_N] <= #1 1'b1;
621
                        end
622
                      if (I_CCF == 1'b1 )
623
                        begin
624
                          // CCF
625
                          F[Flag_C] <= #1 ~ F[Flag_C];
626
                          F[Flag_Y] <= #1 ACC[5];
627
                          F[Flag_H] <= #1 F[Flag_C];
628
                          F[Flag_X] <= #1 ACC[3];
629
                          F[Flag_N] <= #1 1'b0;
630
                        end
631
                      if (I_SCF == 1'b1 )
632
                        begin
633
                          // SCF
634
                          F[Flag_C] <= #1 1'b1;
635
                          F[Flag_Y] <= #1 ACC[5];
636
                          F[Flag_H] <= #1 1'b0;
637
                          F[Flag_X] <= #1 ACC[3];
638
                          F[Flag_N] <= #1 1'b0;
639
                        end
640
                    end // if (T_Res == 1'b1 )
641
 
642
 
643 21 ghutchis
                  if (tstate[2] && wait_n == 1'b1 )
644 2 ghutchis
                    begin
645 21 ghutchis
                      if (ISet == 2'b01 && mcycle[6] )
646 2 ghutchis
                        begin
647
                          IR <= #1 dinst;
648
                        end
649
                      if (JumpE == 1'b1 )
650
                        begin
651
                          PC <= #1 PC16;
652
                        end
653
                      else if (Inc_PC == 1'b1 )
654
                        begin
655
                          //PC <= #1 PC + 1;
656
                          PC <= #1 PC16;
657
                        end
658
                      if (BTR_r == 1'b1 )
659
                        begin
660
                          //PC <= #1 PC - 2;
661
                          PC <= #1 PC16;
662
                        end
663
                      if (RstP == 1'b1 )
664
                        begin
665
                          TmpAddr <= #1 { 10'h0, IR[5:3], 3'h0 };
666
                          //TmpAddr <= #1 (others =>1'b0);
667
                          //TmpAddr[5:3] <= #1 IR[5:3];
668
                        end
669
                    end
670 21 ghutchis
                  if (tstate[3] && mcycle[5] )
671 2 ghutchis
                    begin
672
                      TmpAddr <= #1 SP16;
673
                    end
674
 
675 21 ghutchis
                  if ((tstate[2] && wait_n == 1'b1) || (tstate[4] && mcycle[0]) )
676 2 ghutchis
                    begin
677
                      if (IncDec_16[2:0] == 3'b111 )
678
                        begin
679
                          SP <= #1 SP16;
680
                        end
681
                    end
682
 
683
                  if (LDSPHL == 1'b1 )
684
                    begin
685
                      SP <= #1 RegBusC;
686
                    end
687
                  if (ExchangeAF == 1'b1 )
688
                    begin
689
                      Ap <= #1 ACC;
690
                      ACC <= #1 Ap;
691
                      Fp <= #1 F;
692
                      F <= #1 Fp;
693
                    end
694
                  if (ExchangeRS == 1'b1 )
695
                    begin
696
                      Alternate <= #1 ~ Alternate;
697
                    end
698
                end // else: !if(mcycle  == 3'b001 && tstate(2) == 1'b0 )
699
 
700
 
701 21 ghutchis
              if (tstate[3] )
702 2 ghutchis
                begin
703
                  if (LDZ == 1'b1 )
704
                    begin
705
                      TmpAddr[7:0] <= #1 DI_Reg;
706
                    end
707
                  if (LDW == 1'b1 )
708
                    begin
709
                      TmpAddr[15:8] <= #1 DI_Reg;
710
                    end
711
 
712
                  if (Special_LD[2] == 1'b1 )
713
                    begin
714
                      case (Special_LD[1:0])
715
                        2'b00 :
716
                          begin
717
                            ACC <= #1 I;
718
                            F[Flag_P] <= #1 IntE_FF2;
719
                          end
720
 
721
                        2'b01 :
722
                          begin
723
                            ACC <= #1 R;
724
                            F[Flag_P] <= #1 IntE_FF2;
725
                          end
726
 
727
                        2'b10 :
728
                          I <= #1 ACC;
729
 
730
                        default :
731
                          R <= #1 ACC;
732
                      endcase
733
                    end
734
                end // if (tstate == 3 )
735
 
736
 
737
              if ((I_DJNZ == 1'b0 && Save_ALU_r == 1'b1) || ALU_Op_r == 4'b1001 )
738
                begin
739
                  if (Mode == 3 )
740
                    begin
741
                      F[6] <= #1 F_Out[6];
742
                      F[5] <= #1 F_Out[5];
743
                      F[7] <= #1 F_Out[7];
744
                      if (PreserveC_r == 1'b0 )
745
                        begin
746
                          F[4] <= #1 F_Out[4];
747
                        end
748
                    end
749
                  else
750
                    begin
751
                      F[7:1] <= #1 F_Out[7:1];
752
                      if (PreserveC_r == 1'b0 )
753
                        begin
754
                          F[Flag_C] <= #1 F_Out[0];
755
                        end
756
                    end
757
                end // if ((I_DJNZ == 1'b0 && Save_ALU_r == 1'b1) || ALU_Op_r == 4'b1001 )
758
 
759
              if (T_Res == 1'b1 && I_INRC == 1'b1 )
760
                begin
761
                  F[Flag_H] <= #1 1'b0;
762
                  F[Flag_N] <= #1 1'b0;
763
                  if (DI_Reg[7:0] == 8'b00000000 )
764
                    begin
765
                      F[Flag_Z] <= #1 1'b1;
766
                    end
767
                  else
768
                    begin
769
                      F[Flag_Z] <= #1 1'b0;
770
                    end
771
                  F[Flag_S] <= #1 DI_Reg[7];
772
                  F[Flag_P] <= #1 ~ (^DI_Reg[7:0]);
773
                end // if (T_Res == 1'b1 && I_INRC == 1'b1 )
774
 
775
 
776 21 ghutchis
              if (tstate[1] && Auto_Wait_t1 == 1'b0 )
777 2 ghutchis
                begin
778
                  do <= #1 BusB;
779
                  if (I_RLD == 1'b1 )
780
                    begin
781
                      do[3:0] <= #1 BusA[3:0];
782
                      do[7:4] <= #1 BusB[3:0];
783
                    end
784
                  if (I_RRD == 1'b1 )
785
                    begin
786
                      do[3:0] <= #1 BusB[7:4];
787
                      do[7:4] <= #1 BusA[3:0];
788
                    end
789
                end
790
 
791
              if (T_Res == 1'b1 )
792
                begin
793
                  Read_To_Reg_r[3:0] <= #1 Set_BusA_To;
794
                  Read_To_Reg_r[4] <= #1 Read_To_Reg;
795
                  if (Read_To_Acc == 1'b1 )
796
                    begin
797
                      Read_To_Reg_r[3:0] <= #1 4'b0111;
798
                      Read_To_Reg_r[4] <= #1 1'b1;
799
                    end
800
                end
801
 
802 21 ghutchis
              if (tstate[1] && I_BT == 1'b1 )
803 2 ghutchis
                begin
804
                  F[Flag_X] <= #1 ALU_Q[3];
805
                  F[Flag_Y] <= #1 ALU_Q[1];
806
                  F[Flag_H] <= #1 1'b0;
807
                  F[Flag_N] <= #1 1'b0;
808
                end
809
              if (I_BC == 1'b1 || I_BT == 1'b1 )
810
                begin
811
                  F[Flag_P] <= #1 IncDecZ;
812
                end
813
 
814 21 ghutchis
              if ((tstate[1] && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||
815 2 ghutchis
                  (Save_ALU_r == 1'b1 && ALU_Op_r != 4'b0111) )
816
                begin
817
                  case (Read_To_Reg_r)
818
                    5'b10111 :
819
                      ACC <= #1 Save_Mux;
820
                    5'b10110 :
821
                      do <= #1 Save_Mux;
822
                    5'b11000 :
823
                      SP[7:0] <= #1 Save_Mux;
824
                    5'b11001 :
825
                      SP[15:8] <= #1 Save_Mux;
826
                    5'b11011 :
827
                      F <= #1 Save_Mux;
828
                  endcase
829
                end // if ((tstate == 1 && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||...              
830
            end // if (ClkEn == 1'b1 )         
831
        end // else: !if(reset_n == 1'b0 )
832
    end
833
 
834
 
835
  //-------------------------------------------------------------------------
836
  //
837
  // BC('), DE('), HL('), IX && IY
838
  //
839
  //-------------------------------------------------------------------------
840
  always @ (posedge clk)
841
    begin
842
      if (ClkEn == 1'b1 )
843
        begin
844
          // Bus A / Write
845
          RegAddrA_r <= #1  { Alternate, Set_BusA_To[2:1] };
846
          if (XY_Ind == 1'b0 && XY_State != 2'b00 && Set_BusA_To[2:1] == 2'b10 )
847
            begin
848
              RegAddrA_r <= #1 { XY_State[1],  2'b11 };
849
            end
850
 
851
          // Bus B
852
          RegAddrB_r <= #1 { Alternate, Set_BusB_To[2:1] };
853
          if (XY_Ind == 1'b0 && XY_State != 2'b00 && Set_BusB_To[2:1] == 2'b10 )
854
            begin
855
              RegAddrB_r <= #1 { XY_State[1],  2'b11 };
856
            end
857
 
858
          // Address from register
859
          RegAddrC <= #1 { Alternate,  Set_Addr_To[1:0] };
860
          // Jump (HL), LD SP,HL
861
          if ((JumpXY == 1'b1 || LDSPHL == 1'b1) )
862
            begin
863
              RegAddrC <= #1 { Alternate, 2'b10 };
864
            end
865 21 ghutchis
          if (((JumpXY == 1'b1 || LDSPHL == 1'b1) && XY_State != 2'b00) || (mcycle[5]) )
866 2 ghutchis
            begin
867
              RegAddrC <= #1 { XY_State[1],  2'b11 };
868
            end
869
 
870
          if (I_DJNZ == 1'b1 && Save_ALU_r == 1'b1 && Mode < 2 )
871
            begin
872
              IncDecZ <= #1 F_Out[Flag_Z];
873
            end
874 21 ghutchis
          if ((tstate[2] || (tstate[3] && mcycle[0])) && IncDec_16[2:0] == 3'b100 )
875 2 ghutchis
            begin
876
              if (ID16 == 0 )
877
                begin
878
                  IncDecZ <= #1 1'b0;
879
                end
880
              else
881
                begin
882
                  IncDecZ <= #1 1'b1;
883
                end
884
            end
885
 
886
          RegBusA_r <= #1 RegBusA;
887
        end
888
 
889
    end // always @ (posedge clk)
890
 
891
 
892
  always @(/*AUTOSENSE*/Alternate or ExchangeDH or IncDec_16
893 21 ghutchis
           or RegAddrA_r or RegAddrB_r or XY_State or mcycle or tstate)
894 2 ghutchis
    begin
895 21 ghutchis
      if ((tstate[2] || (tstate[3] && mcycle[0] && IncDec_16[2] == 1'b1)) && XY_State == 2'b00)
896 2 ghutchis
        RegAddrA = { Alternate, IncDec_16[1:0] };
897 21 ghutchis
      else if ((tstate[2] || (tstate[3] && mcycle[0] && IncDec_16[2] == 1'b1)) && IncDec_16[1:0] == 2'b10)
898 2 ghutchis
        RegAddrA = { XY_State[1], 2'b11 };
899 51 ghutchis
      else /* if (ExchangeDH == 1'b1 && tstate[3])
900 2 ghutchis
        RegAddrA = { Alternate, 2'b10 };
901 21 ghutchis
      else if (ExchangeDH == 1'b1 && tstate[4])
902 2 ghutchis
        RegAddrA = { Alternate, 2'b01 };
903 51 ghutchis
      else */
904 2 ghutchis
        RegAddrA = RegAddrA_r;
905
 
906 51 ghutchis
      /* if (ExchangeDH == 1'b1 && tstate[3])
907 2 ghutchis
        RegAddrB = { Alternate, 2'b01 };
908 51 ghutchis
      else */
909 2 ghutchis
        RegAddrB = RegAddrB_r;
910
    end // always @ *
911
 
912
 
913
  always @(/*AUTOSENSE*/ALU_Op_r or Auto_Wait_t1 or ExchangeDH
914 21 ghutchis
           or IncDec_16 or Read_To_Reg_r or Save_ALU_r or mcycle
915
           or tstate or wait_n)
916 2 ghutchis
    begin
917
      RegWEH = 1'b0;
918
      RegWEL = 1'b0;
919 21 ghutchis
      if ((tstate[1] && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||
920 2 ghutchis
          (Save_ALU_r == 1'b1 && ALU_Op_r != 4'b0111) )
921
        begin
922
          case (Read_To_Reg_r)
923
            5'b10000 , 5'b10001 , 5'b10010 , 5'b10011 , 5'b10100 , 5'b10101 :
924
              begin
925
                RegWEH = ~ Read_To_Reg_r[0];
926
                RegWEL = Read_To_Reg_r[0];
927
              end
928
          endcase // case(Read_To_Reg_r)
929
 
930
        end // if ((tstate == 1 && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||...
931
 
932
 
933 21 ghutchis
      if (ExchangeDH == 1'b1 && (tstate[3] || tstate[4]) )
934 2 ghutchis
        begin
935
          RegWEH = 1'b1;
936
          RegWEL = 1'b1;
937
        end
938
 
939 21 ghutchis
      if (IncDec_16[2] == 1'b1 && ((tstate[2] && wait_n == 1'b1 && mcycle != 3'b001) || (tstate[3] && mcycle[0])) )
940 2 ghutchis
        begin
941
          case (IncDec_16[1:0])
942
            2'b00 , 2'b01 , 2'b10 :
943
              begin
944
                RegWEH = 1'b1;
945
                RegWEL = 1'b1;
946
              end
947
          endcase
948
        end
949
    end // always @ *
950
 
951
 
952
  always @(/*AUTOSENSE*/ExchangeDH or ID16 or IncDec_16 or RegBusA_r
953 21 ghutchis
           or RegBusB or Save_Mux or mcycle or tstate)
954 2 ghutchis
    begin
955
      RegDIH = Save_Mux;
956
      RegDIL = Save_Mux;
957
 
958 51 ghutchis
      /*if (ExchangeDH == 1'b1 && tstate[3] )
959 2 ghutchis
        begin
960
          RegDIH = RegBusB[15:8];
961
          RegDIL = RegBusB[7:0];
962
        end
963 21 ghutchis
      else if (ExchangeDH == 1'b1 && tstate[4] )
964 2 ghutchis
        begin
965
          RegDIH = RegBusA_r[15:8];
966
          RegDIL = RegBusA_r[7:0];
967
        end
968 51 ghutchis
      else */ if (IncDec_16[2] == 1'b1 && ((tstate[2] && mcycle != 3'b001) || (tstate[3] && mcycle[0])) )
969 2 ghutchis
        begin
970
          RegDIH = ID16[15:8];
971
          RegDIL = ID16[7:0];
972
        end
973
    end
974
 
975
  tv80_reg i_reg
976
    (
977
     .clk                  (clk),
978
     .CEN                  (ClkEn),
979
     .WEH                  (RegWEH),
980
     .WEL                  (RegWEL),
981
     .AddrA                (RegAddrA),
982
     .AddrB                (RegAddrB),
983
     .AddrC                (RegAddrC),
984
     .DIH                  (RegDIH),
985
     .DIL                  (RegDIL),
986
     .DOAH                 (RegBusA[15:8]),
987
     .DOAL                 (RegBusA[7:0]),
988
     .DOBH                 (RegBusB[15:8]),
989
     .DOBL                 (RegBusB[7:0]),
990
     .DOCH                 (RegBusC[15:8]),
991
     .DOCL                 (RegBusC[7:0])
992
     );
993
 
994
  //-------------------------------------------------------------------------
995
  //
996
  // Buses
997
  //
998
  //-------------------------------------------------------------------------
999
 
1000 51 ghutchis
  always @(/*AUTOSENSE*/ACC or DI_Reg or F or PC or RegBusA or RegBusB
1001
           or SP or Set_BusA_To or Set_BusB_To)
1002
    begin
1003
      case (Set_BusB_To)
1004
        4'b0111 : NextBusB = ACC;
1005
        4'b0000 ,
1006
        4'b0100 ,
1007
        4'b0010 : NextBusB = RegBusB[15:8];
1008
        4'b0001 ,
1009
        4'b0011 ,
1010
        4'b0101 : NextBusB = RegBusB[7:0];
1011
        4'b0110 : NextBusB = DI_Reg;
1012
        4'b1000 : NextBusB = SP[7:0];
1013
        4'b1001 : NextBusB = SP[15:8];
1014
        4'b1010 : NextBusB = 8'b00000001;
1015
        4'b1011 : NextBusB = F;
1016
        4'b1100 : NextBusB = PC[7:0];
1017
        4'b1101 : NextBusB = PC[15:8];
1018
        4'b1110 : NextBusB = 8'b00000000;
1019
        default : NextBusB = 8'hxx;
1020
      endcase // case(Set_BusB_To)
1021
 
1022
      case (Set_BusA_To)
1023
        4'b0111 : NextBusA = ACC;
1024
        4'b0000 ,
1025
        4'b0100 ,
1026
        4'b0010 : NextBusA = RegBusA[15:8];
1027
        4'b0001 ,
1028
        4'b0011 ,
1029
        4'b0101 : NextBusA = RegBusA[7:0];
1030
        4'b0110 : NextBusA = DI_Reg;
1031
        4'b1000 : NextBusA = SP[7:0];
1032
        4'b1001 : NextBusA = SP[15:8];
1033
        4'b1010 : NextBusA = 8'b00000000;
1034
        default : NextBusA =  8'hxx;
1035
      endcase
1036
    end // always @ (...
1037
 
1038 2 ghutchis
  always @ (posedge clk)
1039
    begin
1040
      if (ClkEn == 1'b1 )
1041
        begin
1042 51 ghutchis
          BusA <= #1 NextBusA;
1043
          BusB <= #1 NextBusB;
1044 2 ghutchis
        end
1045
    end
1046
 
1047
  //-------------------------------------------------------------------------
1048
  //
1049
  // Generate external control signals
1050
  //
1051
  //-------------------------------------------------------------------------
1052
  always @ (posedge clk)
1053
    begin
1054
      if (reset_n == 1'b0 )
1055
        begin
1056
          rfsh_n <= #1 1'b1;
1057
        end
1058
      else
1059
        begin
1060
          if (cen == 1'b1 )
1061
            begin
1062 21 ghutchis
              if (mcycle[0] && ((tstate[2]  && wait_n == 1'b1) || tstate[3]) )
1063 2 ghutchis
                begin
1064
                  rfsh_n <= #1 1'b0;
1065
                end
1066
              else
1067
                begin
1068
                  rfsh_n <= #1 1'b1;
1069
                end
1070
            end
1071
        end
1072
    end
1073
 
1074
 
1075
  always @(/*AUTOSENSE*/BusAck or Halt_FF or I_DJNZ or IntCycle
1076 21 ghutchis
           or IntE_FF1 or di or iorq_i or mcycle or tstate)
1077 2 ghutchis
    begin
1078
      mc = mcycle;
1079
      ts = tstate;
1080
      DI_Reg = di;
1081
      halt_n = ~ Halt_FF;
1082
      busak_n = ~ BusAck;
1083
      intcycle_n = ~ IntCycle;
1084
      IntE = IntE_FF1;
1085
      iorq = iorq_i;
1086
      stop = I_DJNZ;
1087
    end
1088
 
1089
  //-----------------------------------------------------------------------
1090
  //
1091
  // Syncronise inputs
1092
  //
1093
  //-----------------------------------------------------------------------
1094
 
1095
  always @ (posedge clk)
1096
    begin : sync_inputs
1097
 
1098
      if (reset_n == 1'b0 )
1099
        begin
1100
          BusReq_s <= #1 1'b0;
1101
          INT_s <= #1 1'b0;
1102
          NMI_s <= #1 1'b0;
1103
          Oldnmi_n <= #1 1'b0;
1104
        end
1105
      else
1106
        begin
1107
          if (cen == 1'b1 )
1108
            begin
1109
              BusReq_s <= #1 ~ busrq_n;
1110
              INT_s <= #1 ~ int_n;
1111
              if (NMICycle == 1'b1 )
1112
                begin
1113
                  NMI_s <= #1 1'b0;
1114
                end
1115
              else if (nmi_n == 1'b0 && Oldnmi_n == 1'b1 )
1116
                begin
1117
                  NMI_s <= #1 1'b1;
1118
                end
1119
              Oldnmi_n <= #1 nmi_n;
1120
            end
1121
        end
1122
    end
1123
 
1124
  //-----------------------------------------------------------------------
1125
  //
1126
  // Main state machine
1127
  //
1128
  //-----------------------------------------------------------------------
1129
 
1130
  always @ (posedge clk)
1131
    begin
1132
      if (reset_n == 1'b0 )
1133
        begin
1134 21 ghutchis
          mcycle <= #1 7'b0000001;
1135
          tstate <= #1 7'b0000001;
1136 2 ghutchis
          Pre_XY_F_M <= #1 3'b000;
1137
          Halt_FF <= #1 1'b0;
1138
          BusAck <= #1 1'b0;
1139
          NMICycle <= #1 1'b0;
1140
          IntCycle <= #1 1'b0;
1141
          IntE_FF1 <= #1 1'b0;
1142
          IntE_FF2 <= #1 1'b0;
1143
          No_BTR <= #1 1'b0;
1144
          Auto_Wait_t1 <= #1 1'b0;
1145
          Auto_Wait_t2 <= #1 1'b0;
1146
          m1_n <= #1 1'b1;
1147
        end
1148
      else
1149
        begin
1150
          if (cen == 1'b1 )
1151
            begin
1152
              if (T_Res == 1'b1 )
1153
                begin
1154
                  Auto_Wait_t1 <= #1 1'b0;
1155
                end
1156
              else
1157
                begin
1158
                  Auto_Wait_t1 <= #1 Auto_Wait || iorq_i;
1159
                end
1160
              Auto_Wait_t2 <= #1 Auto_Wait_t1;
1161
              No_BTR <= #1 (I_BT && (~ IR[4] || ~ F[Flag_P])) ||
1162
                        (I_BC && (~ IR[4] || F[Flag_Z] || ~ F[Flag_P])) ||
1163
                        (I_BTR && (~ IR[4] || F[Flag_Z]));
1164 21 ghutchis
              if (tstate[2] )
1165 2 ghutchis
                begin
1166
                  if (SetEI == 1'b1 )
1167
                    begin
1168
                      IntE_FF1 <= #1 1'b1;
1169
                      IntE_FF2 <= #1 1'b1;
1170
                    end
1171
                  if (I_RETN == 1'b1 )
1172
                    begin
1173
                      IntE_FF1 <= #1 IntE_FF2;
1174
                    end
1175
                end
1176 21 ghutchis
              if (tstate[3] )
1177 2 ghutchis
                begin
1178
                  if (SetDI == 1'b1 )
1179
                    begin
1180
                      IntE_FF1 <= #1 1'b0;
1181
                      IntE_FF2 <= #1 1'b0;
1182
                    end
1183
                end
1184
              if (IntCycle == 1'b1 || NMICycle == 1'b1 )
1185
                begin
1186
                  Halt_FF <= #1 1'b0;
1187
                end
1188 21 ghutchis
              if (mcycle[0] && tstate[2] && wait_n == 1'b1 )
1189 2 ghutchis
                begin
1190
                  m1_n <= #1 1'b1;
1191
                end
1192
              if (BusReq_s == 1'b1 && BusAck == 1'b1 )
1193
                begin
1194
                end
1195
              else
1196
                begin
1197
                  BusAck <= #1 1'b0;
1198 21 ghutchis
                  if (tstate[2] && wait_n == 1'b0 )
1199 2 ghutchis
                    begin
1200
                    end
1201
                  else if (T_Res == 1'b1 )
1202
                    begin
1203
                      if (Halt == 1'b1 )
1204
                        begin
1205
                          Halt_FF <= #1 1'b1;
1206
                        end
1207
                      if (BusReq_s == 1'b1 )
1208
                        begin
1209
                          BusAck <= #1 1'b1;
1210
                        end
1211
                      else
1212
                        begin
1213 22 ghutchis
                          tstate <= #1 7'b0000010;
1214 2 ghutchis
                          if (NextIs_XY_Fetch == 1'b1 )
1215
                            begin
1216 21 ghutchis
                              mcycle <= #1 7'b0100000;
1217 2 ghutchis
                              Pre_XY_F_M <= #1 mcycle;
1218
                              if (IR == 8'b00110110 && Mode == 0 )
1219
                                begin
1220
                                  Pre_XY_F_M <= #1 3'b010;
1221
                                end
1222
                            end
1223 21 ghutchis
                          else if ((mcycle[6]) || (mcycle[5] && Mode == 1 && ISet != 2'b01) )
1224 2 ghutchis
                            begin
1225 21 ghutchis
                              mcycle <= #1 number_to_bitvec(Pre_XY_F_M + 1);
1226 2 ghutchis
                            end
1227 21 ghutchis
                          else if ((last_mcycle) ||
1228 2 ghutchis
                                   No_BTR == 1'b1 ||
1229 21 ghutchis
                                   (mcycle[1] && I_DJNZ == 1'b1 && IncDecZ == 1'b1) )
1230 2 ghutchis
                            begin
1231
                              m1_n <= #1 1'b0;
1232 21 ghutchis
                              mcycle <= #1 7'b0000001;
1233 2 ghutchis
                              IntCycle <= #1 1'b0;
1234
                              NMICycle <= #1 1'b0;
1235
                              if (NMI_s == 1'b1 && Prefix == 2'b00 )
1236
                                begin
1237
                                  NMICycle <= #1 1'b1;
1238
                                  IntE_FF1 <= #1 1'b0;
1239
                                end
1240
                              else if ((IntE_FF1 == 1'b1 && INT_s == 1'b1) && Prefix == 2'b00 && SetEI == 1'b0 )
1241
                                begin
1242
                                  IntCycle <= #1 1'b1;
1243
                                  IntE_FF1 <= #1 1'b0;
1244
                                  IntE_FF2 <= #1 1'b0;
1245
                                end
1246
                            end
1247
                          else
1248
                            begin
1249 21 ghutchis
                              mcycle <= #1 { mcycle[5:0], mcycle[6] };
1250 2 ghutchis
                            end
1251
                        end
1252
                    end
1253
                  else
1254
                    begin   // verilog has no "nor" operator
1255
                      if ( ~(Auto_Wait == 1'b1 && Auto_Wait_t2 == 1'b0) &&
1256
                           ~(IOWait == 1 && iorq_i == 1'b1 && Auto_Wait_t1 == 1'b0) )
1257
                        begin
1258 21 ghutchis
                          tstate <= #1 { tstate[5:0], tstate[6] };
1259 2 ghutchis
                        end
1260
                    end
1261
                end
1262 21 ghutchis
              if (tstate[0])
1263 2 ghutchis
                begin
1264
                  m1_n <= #1 1'b0;
1265
                end
1266
            end
1267
        end
1268
    end
1269
 
1270
  always @(/*AUTOSENSE*/BTR_r or DI_Reg or IncDec_16 or JumpE or PC
1271 21 ghutchis
           or RegBusA or RegBusC or SP or tstate)
1272 2 ghutchis
    begin
1273
      if (JumpE == 1'b1 )
1274
        begin
1275
          PC16_B = { {8{DI_Reg[7]}}, DI_Reg };
1276
        end
1277
      else if (BTR_r == 1'b1 )
1278
        begin
1279
          PC16_B = -2;
1280
        end
1281
      else
1282
        begin
1283
          PC16_B = 1;
1284
        end
1285
 
1286 21 ghutchis
      if (tstate[3])
1287 2 ghutchis
        begin
1288
          SP16_A = RegBusC;
1289
          SP16_B = { {8{DI_Reg[7]}}, DI_Reg };
1290
        end
1291
      else
1292
        begin
1293
          // suspect that ID16 and SP16 could be shared
1294
          SP16_A = SP;
1295
 
1296
          if (IncDec_16[3] == 1'b1)
1297
            SP16_B = -1;
1298
          else
1299
            SP16_B = 1;
1300
        end
1301
 
1302
      if (IncDec_16[3])
1303
        ID16_B = -1;
1304
      else
1305
        ID16_B = 1;
1306
 
1307
      ID16 = RegBusA + ID16_B;
1308
      PC16 = PC + PC16_B;
1309
      SP16 = SP16_A + SP16_B;
1310
    end // always @ *
1311
 
1312
 
1313
  always @(/*AUTOSENSE*/IntCycle or NMICycle or mcycle)
1314
    begin
1315
      Auto_Wait = 1'b0;
1316
      if (IntCycle == 1'b1 || NMICycle == 1'b1 )
1317
        begin
1318 21 ghutchis
          if (mcycle[0] )
1319 2 ghutchis
            begin
1320
              Auto_Wait = 1'b1;
1321
            end
1322
        end
1323
    end // always @ *
1324
 
1325
// synopsys dc_script_begin
1326 51 ghutchis
// set_attribute current_design "revision" "$Id: tv80_core.v,v 1.4.4.1 2004-12-16 00:46:19 ghutchis Exp $" -type string -quiet
1327 2 ghutchis
// synopsys dc_script_end
1328
endmodule // T80
1329
 

powered by: WebSVN 2.1.0

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