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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc1/] [rtl/] [core/] [tv80_core.v] - Blame information for rev 101

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
  reg [7:0]     BusB;
148
  reg [7:0]     BusA;
149
  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
     .F                    (F),
221
     .NMICycle             (NMICycle),
222
     .IntCycle             (IntCycle),
223
     .MCycles              (mcycles_d),
224
     .TStates              (tstates),
225
     .Prefix               (Prefix),
226
     .Inc_PC               (Inc_PC),
227
     .Inc_WZ               (Inc_WZ),
228
     .IncDec_16            (IncDec_16),
229
     .Read_To_Acc          (Read_To_Acc),
230
     .Read_To_Reg          (Read_To_Reg),
231
     .Set_BusB_To          (Set_BusB_To),
232
     .Set_BusA_To          (Set_BusA_To),
233
     .ALU_Op               (ALU_Op),
234
     .Save_ALU             (Save_ALU),
235
     .PreserveC            (PreserveC),
236
     .Arith16              (Arith16),
237
     .Set_Addr_To          (Set_Addr_To),
238
     .IORQ                 (iorq_i),
239
     .Jump                 (Jump),
240
     .JumpE                (JumpE),
241
     .JumpXY               (JumpXY),
242
     .Call                 (Call),
243
     .RstP                 (RstP),
244
     .LDZ                  (LDZ),
245
     .LDW                  (LDW),
246
     .LDSPHL               (LDSPHL),
247
     .Special_LD           (Special_LD),
248
     .ExchangeDH           (ExchangeDH),
249
     .ExchangeRp           (ExchangeRp),
250
     .ExchangeAF           (ExchangeAF),
251
     .ExchangeRS           (ExchangeRS),
252
     .I_DJNZ               (I_DJNZ),
253
     .I_CPL                (I_CPL),
254
     .I_CCF                (I_CCF),
255
     .I_SCF                (I_SCF),
256
     .I_RETN               (I_RETN),
257
     .I_BT                 (I_BT),
258
     .I_BC                 (I_BC),
259
     .I_BTR                (I_BTR),
260
     .I_RLD                (I_RLD),
261
     .I_RRD                (I_RRD),
262
     .I_INRC               (I_INRC),
263
     .SetDI                (SetDI),
264
     .SetEI                (SetEI),
265
     .IMode                (IMode),
266
     .Halt                 (Halt),
267
     .NoRead               (no_read),
268
     .Write                (write)
269
     );
270
 
271
  tv80_alu #(Mode, Flag_C, Flag_N, Flag_P, Flag_X, Flag_H, Flag_Y, Flag_Z, Flag_S) i_alu
272
    (
273
     .Arith16              (Arith16_r),
274
     .Z16                  (Z16_r),
275
     .ALU_Op               (ALU_Op_r),
276
     .IR                   (IR[5:0]),
277
     .ISet                 (ISet),
278
     .BusA                 (BusA),
279
     .BusB                 (BusB),
280
     .F_In                 (F),
281
     .Q                    (ALU_Q),
282
     .F_Out                (F_Out)
283
     );
284
 
285 21 ghutchis
  function [6:0] number_to_bitvec;
286
    input [2:0] num;
287
    begin
288
      case (num)
289
        1 : number_to_bitvec = 7'b0000001;
290
        2 : number_to_bitvec = 7'b0000010;
291
        3 : number_to_bitvec = 7'b0000100;
292
        4 : number_to_bitvec = 7'b0001000;
293
        5 : number_to_bitvec = 7'b0010000;
294
        6 : number_to_bitvec = 7'b0100000;
295
        7 : number_to_bitvec = 7'b1000000;
296
        default : number_to_bitvec = 7'bx;
297
      endcase // case(num)
298
    end
299
  endfunction // number_to_bitvec
300
 
301
  always @(/*AUTOSENSE*/mcycle or mcycles or tstate or tstates)
302
    begin
303
      case (mcycles)
304
        1 : last_mcycle = mcycle[0];
305
        2 : last_mcycle = mcycle[1];
306
        3 : last_mcycle = mcycle[2];
307
        4 : last_mcycle = mcycle[3];
308
        5 : last_mcycle = mcycle[4];
309
        6 : last_mcycle = mcycle[5];
310
        7 : last_mcycle = mcycle[6];
311
        default : last_mcycle = 1'bx;
312
      endcase // case(mcycles)
313
 
314
      case (tstates)
315
 
316
        1 : last_tstate = tstate[1];
317
        2 : last_tstate = tstate[2];
318
        3 : last_tstate = tstate[3];
319
        4 : last_tstate = tstate[4];
320
        5 : last_tstate = tstate[5];
321
        6 : last_tstate = tstate[6];
322
        default : last_tstate = 1'bx;
323
      endcase
324
    end // always @ (...
325
 
326
 
327 2 ghutchis
  always @(/*AUTOSENSE*/ALU_Q or BusAck or BusB or DI_Reg
328 21 ghutchis
           or ExchangeRp or IR or Save_ALU_r or Set_Addr_To or XY_Ind
329
           or XY_State or cen or last_tstate or mcycle)
330 2 ghutchis
    begin
331
      ClkEn = cen && ~ BusAck;
332
 
333 21 ghutchis
      if (last_tstate)
334 2 ghutchis
        T_Res = 1'b1;
335
      else T_Res = 1'b0;
336
 
337
      if (XY_State != 2'b00 && XY_Ind == 1'b0 &&
338
          ((Set_Addr_To == aXY) ||
339 21 ghutchis
           (mcycle[0] && IR == 8'b11001011) ||
340
           (mcycle[0] && IR == 8'b00110110)))
341 2 ghutchis
        NextIs_XY_Fetch = 1'b1;
342
      else
343
        NextIs_XY_Fetch = 1'b0;
344
 
345
      if (ExchangeRp)
346
        Save_Mux = BusB;
347
      else if (!Save_ALU_r)
348
        Save_Mux = DI_Reg;
349
      else
350
        Save_Mux = ALU_Q;
351
    end // always @ *
352
 
353
  always @ (posedge clk)
354
    begin
355
      if (reset_n == 1'b0 )
356
        begin
357
          PC <= #1 0;  // Program Counter
358
          A <= #1 0;
359
          TmpAddr <= #1 0;
360
          IR <= #1 8'b00000000;
361
          ISet <= #1 2'b00;
362
          XY_State <= #1 2'b00;
363
          IStatus <= #1 2'b00;
364
          mcycles <= #1 3'b000;
365
          do <= #1 8'b00000000;
366
 
367
          ACC <= #1 8'hFF;
368
          F <= #1 8'hFF;
369
          Ap <= #1 8'hFF;
370
          Fp <= #1 8'hFF;
371
          I <= #1 0;
372
          R <= #1 0;
373
          SP <= #1 16'hFFFF;
374
          Alternate <= #1 1'b0;
375
 
376
          Read_To_Reg_r <= #1 5'b00000;
377
          Arith16_r <= #1 1'b0;
378
          BTR_r <= #1 1'b0;
379
          Z16_r <= #1 1'b0;
380
          ALU_Op_r <= #1 4'b0000;
381
          Save_ALU_r <= #1 1'b0;
382
          PreserveC_r <= #1 1'b0;
383
          XY_Ind <= #1 1'b0;
384
        end
385
      else
386
        begin
387
 
388
          if (ClkEn == 1'b1 )
389
            begin
390
 
391
              ALU_Op_r <= #1 4'b0000;
392
              Save_ALU_r <= #1 1'b0;
393
              Read_To_Reg_r <= #1 5'b00000;
394
 
395
              mcycles <= #1 mcycles_d;
396
 
397
              if (IMode != 2'b11 )
398
                begin
399
                  IStatus <= #1 IMode;
400
                end
401
 
402
              Arith16_r <= #1 Arith16;
403
              PreserveC_r <= #1 PreserveC;
404 21 ghutchis
              if (ISet == 2'b10 && ALU_Op[2] == 1'b0 && ALU_Op[0] == 1'b1 && mcycle[2] )
405 2 ghutchis
                begin
406
                  Z16_r <= #1 1'b1;
407
                end
408
              else
409
                begin
410
                  Z16_r <= #1 1'b0;
411
                end
412
 
413 21 ghutchis
              if (mcycle[0] && (tstate[1] | tstate[2] | tstate[3] ))
414 2 ghutchis
                begin
415
                  // mcycle == 1 && tstate == 1, 2, || 3
416
 
417 21 ghutchis
                  if (tstate[2] && wait_n == 1'b1 )
418 2 ghutchis
                    begin
419
                      if (Mode < 2 )
420
                        begin
421
                          A[7:0] <= #1 R;
422
                          A[15:8] <= #1 I;
423
                          R[6:0] <= #1 R[6:0] + 1;
424
                        end
425
 
426
                      if (Jump == 1'b0 && Call == 1'b0 && NMICycle == 1'b0 && IntCycle == 1'b0 && ~ (Halt_FF == 1'b1 || Halt == 1'b1) )
427
                        begin
428
                          PC <= #1 PC16;
429
                        end
430
 
431
                      if (IntCycle == 1'b1 && IStatus == 2'b01 )
432
                        begin
433
                          IR <= #1 8'b11111111;
434
                        end
435
                      else if (Halt_FF == 1'b1 || (IntCycle == 1'b1 && IStatus == 2'b10) || NMICycle == 1'b1 )
436
                        begin
437
                          IR <= #1 8'b00000000;
438
                        end
439
                      else
440
                        begin
441
                          IR <= #1 dinst;
442
                        end
443
 
444
                      ISet <= #1 2'b00;
445
                      if (Prefix != 2'b00 )
446
                        begin
447
                          if (Prefix == 2'b11 )
448
                            begin
449
                              if (IR[5] == 1'b1 )
450
                                begin
451
                                  XY_State <= #1 2'b10;
452
                                end
453
                              else
454
                                begin
455
                                  XY_State <= #1 2'b01;
456
                                end
457
                            end
458
                          else
459
                            begin
460
                              if (Prefix == 2'b10 )
461
                                begin
462
                                  XY_State <= #1 2'b00;
463
                                  XY_Ind <= #1 1'b0;
464
                                end
465
                              ISet <= #1 Prefix;
466
                            end
467
                        end
468
                      else
469
                        begin
470
                          XY_State <= #1 2'b00;
471
                          XY_Ind <= #1 1'b0;
472
                        end
473
                    end // if (tstate == 2 && wait_n == 1'b1 )
474
 
475
 
476
                end
477
              else
478
                begin
479
                  // either (mcycle > 1) OR (mcycle == 1 AND tstate > 3)
480
 
481 21 ghutchis
                  if (mcycle[5] )
482 2 ghutchis
                    begin
483
                      XY_Ind <= #1 1'b1;
484
                      if (Prefix == 2'b01 )
485
                        begin
486
                          ISet <= #1 2'b01;
487
                        end
488
                    end
489
 
490
                  if (T_Res == 1'b1 )
491
                    begin
492
                      BTR_r <= #1 (I_BT || I_BC || I_BTR) && ~ No_BTR;
493
                      if (Jump == 1'b1 )
494
                        begin
495
                          A[15:8] <= #1 DI_Reg;
496
                          A[7:0] <= #1 TmpAddr[7:0];
497
                          PC[15:8] <= #1 DI_Reg;
498
                          PC[7:0] <= #1 TmpAddr[7:0];
499
                        end
500
                      else if (JumpXY == 1'b1 )
501
                        begin
502
                          A <= #1 RegBusC;
503
                          PC <= #1 RegBusC;
504
                        end else if (Call == 1'b1 || RstP == 1'b1 )
505
                          begin
506
                            A <= #1 TmpAddr;
507
                            PC <= #1 TmpAddr;
508
                          end
509 21 ghutchis
                        else if (last_mcycle && NMICycle == 1'b1 )
510 2 ghutchis
                          begin
511
                            A <= #1 16'b0000000001100110;
512
                            PC <= #1 16'b0000000001100110;
513
                          end
514 21 ghutchis
                        else if (mcycle[2] && IntCycle == 1'b1 && IStatus == 2'b10 )
515 2 ghutchis
                          begin
516
                            A[15:8] <= #1 I;
517
                            A[7:0] <= #1 TmpAddr[7:0];
518
                            PC[15:8] <= #1 I;
519
                            PC[7:0] <= #1 TmpAddr[7:0];
520
                          end
521
                        else
522
                          begin
523
                            case (Set_Addr_To)
524
                              aXY :
525
                                begin
526
                                  if (XY_State == 2'b00 )
527
                                    begin
528
                                      A <= #1 RegBusC;
529
                                    end
530
                                  else
531
                                    begin
532
                                      if (NextIs_XY_Fetch == 1'b1 )
533
                                        begin
534
                                          A <= #1 PC;
535
                                        end
536
                                      else
537
                                        begin
538
                                          A <= #1 TmpAddr;
539
                                        end
540
                                    end // else: !if(XY_State == 2'b00 )
541
                                end // case: aXY
542
 
543
                              aIOA :
544
                                begin
545
                                  if (Mode == 3 )
546
                                    begin
547
                                      // Memory map I/O on GBZ80
548
                                      A[15:8] <= #1 8'hFF;
549
                                    end
550
                                  else if (Mode == 2 )
551
                                    begin
552
                                      // Duplicate I/O address on 8080
553
                                      A[15:8] <= #1 DI_Reg;
554
                                    end
555
                                  else
556
                                    begin
557
                                      A[15:8] <= #1 ACC;
558
                                    end
559
                                  A[7:0] <= #1 DI_Reg;
560
                                end // case: aIOA
561
 
562
 
563
                              aSP :
564
                                begin
565
                                  A <= #1 SP;
566
                                end
567
 
568
                              aBC :
569
                                begin
570
                                  if (Mode == 3 && iorq_i == 1'b1 )
571
                                    begin
572
                                      // Memory map I/O on GBZ80
573
                                      A[15:8] <= #1 8'hFF;
574
                                      A[7:0] <= #1 RegBusC[7:0];
575
                                    end
576
                                  else
577
                                    begin
578
                                      A <= #1 RegBusC;
579
                                    end
580
                                end // case: aBC
581
 
582
                              aDE :
583
                                begin
584
                                  A <= #1 RegBusC;
585
                                end
586
 
587
                              aZI :
588
                                begin
589
                                  if (Inc_WZ == 1'b1 )
590
                                    begin
591
                                      A <= #1 TmpAddr + 1;
592
                                    end
593
                                  else
594
                                    begin
595
                                      A[15:8] <= #1 DI_Reg;
596
                                      A[7:0] <= #1 TmpAddr[7:0];
597
                                    end
598
                                end // case: aZI
599
 
600
                              default   :
601
                                begin
602
                                  A <= #1 PC;
603
                                end
604
                            endcase // case(Set_Addr_To)
605
 
606 21 ghutchis
                          end // else: !if(mcycle[2] && IntCycle == 1'b1 && IStatus == 2'b10 )
607 2 ghutchis
 
608
 
609
                      Save_ALU_r <= #1 Save_ALU;
610
                      ALU_Op_r <= #1 ALU_Op;
611
 
612
                      if (I_CPL == 1'b1 )
613
                        begin
614
                          // CPL
615
                          ACC <= #1 ~ ACC;
616
                          F[Flag_Y] <= #1 ~ ACC[5];
617
                          F[Flag_H] <= #1 1'b1;
618
                          F[Flag_X] <= #1 ~ ACC[3];
619
                          F[Flag_N] <= #1 1'b1;
620
                        end
621
                      if (I_CCF == 1'b1 )
622
                        begin
623
                          // CCF
624
                          F[Flag_C] <= #1 ~ F[Flag_C];
625
                          F[Flag_Y] <= #1 ACC[5];
626
                          F[Flag_H] <= #1 F[Flag_C];
627
                          F[Flag_X] <= #1 ACC[3];
628
                          F[Flag_N] <= #1 1'b0;
629
                        end
630
                      if (I_SCF == 1'b1 )
631
                        begin
632
                          // SCF
633
                          F[Flag_C] <= #1 1'b1;
634
                          F[Flag_Y] <= #1 ACC[5];
635
                          F[Flag_H] <= #1 1'b0;
636
                          F[Flag_X] <= #1 ACC[3];
637
                          F[Flag_N] <= #1 1'b0;
638
                        end
639
                    end // if (T_Res == 1'b1 )
640
 
641
 
642 21 ghutchis
                  if (tstate[2] && wait_n == 1'b1 )
643 2 ghutchis
                    begin
644 21 ghutchis
                      if (ISet == 2'b01 && mcycle[6] )
645 2 ghutchis
                        begin
646
                          IR <= #1 dinst;
647
                        end
648
                      if (JumpE == 1'b1 )
649
                        begin
650
                          PC <= #1 PC16;
651
                        end
652
                      else if (Inc_PC == 1'b1 )
653
                        begin
654
                          //PC <= #1 PC + 1;
655
                          PC <= #1 PC16;
656
                        end
657
                      if (BTR_r == 1'b1 )
658
                        begin
659
                          //PC <= #1 PC - 2;
660
                          PC <= #1 PC16;
661
                        end
662
                      if (RstP == 1'b1 )
663
                        begin
664
                          TmpAddr <= #1 { 10'h0, IR[5:3], 3'h0 };
665
                          //TmpAddr <= #1 (others =>1'b0);
666
                          //TmpAddr[5:3] <= #1 IR[5:3];
667
                        end
668
                    end
669 21 ghutchis
                  if (tstate[3] && mcycle[5] )
670 2 ghutchis
                    begin
671
                      TmpAddr <= #1 SP16;
672
                    end
673
 
674 21 ghutchis
                  if ((tstate[2] && wait_n == 1'b1) || (tstate[4] && mcycle[0]) )
675 2 ghutchis
                    begin
676
                      if (IncDec_16[2:0] == 3'b111 )
677
                        begin
678
                          SP <= #1 SP16;
679
                        end
680
                    end
681
 
682
                  if (LDSPHL == 1'b1 )
683
                    begin
684
                      SP <= #1 RegBusC;
685
                    end
686
                  if (ExchangeAF == 1'b1 )
687
                    begin
688
                      Ap <= #1 ACC;
689
                      ACC <= #1 Ap;
690
                      Fp <= #1 F;
691
                      F <= #1 Fp;
692
                    end
693
                  if (ExchangeRS == 1'b1 )
694
                    begin
695
                      Alternate <= #1 ~ Alternate;
696
                    end
697
                end // else: !if(mcycle  == 3'b001 && tstate(2) == 1'b0 )
698
 
699
 
700 21 ghutchis
              if (tstate[3] )
701 2 ghutchis
                begin
702
                  if (LDZ == 1'b1 )
703
                    begin
704
                      TmpAddr[7:0] <= #1 DI_Reg;
705
                    end
706
                  if (LDW == 1'b1 )
707
                    begin
708
                      TmpAddr[15:8] <= #1 DI_Reg;
709
                    end
710
 
711
                  if (Special_LD[2] == 1'b1 )
712
                    begin
713
                      case (Special_LD[1:0])
714
                        2'b00 :
715
                          begin
716
                            ACC <= #1 I;
717
                            F[Flag_P] <= #1 IntE_FF2;
718
                          end
719
 
720
                        2'b01 :
721
                          begin
722
                            ACC <= #1 R;
723
                            F[Flag_P] <= #1 IntE_FF2;
724
                          end
725
 
726
                        2'b10 :
727
                          I <= #1 ACC;
728
 
729
                        default :
730
                          R <= #1 ACC;
731
                      endcase
732
                    end
733
                end // if (tstate == 3 )
734
 
735
 
736
              if ((I_DJNZ == 1'b0 && Save_ALU_r == 1'b1) || ALU_Op_r == 4'b1001 )
737
                begin
738
                  if (Mode == 3 )
739
                    begin
740
                      F[6] <= #1 F_Out[6];
741
                      F[5] <= #1 F_Out[5];
742
                      F[7] <= #1 F_Out[7];
743
                      if (PreserveC_r == 1'b0 )
744
                        begin
745
                          F[4] <= #1 F_Out[4];
746
                        end
747
                    end
748
                  else
749
                    begin
750
                      F[7:1] <= #1 F_Out[7:1];
751
                      if (PreserveC_r == 1'b0 )
752
                        begin
753
                          F[Flag_C] <= #1 F_Out[0];
754
                        end
755
                    end
756
                end // if ((I_DJNZ == 1'b0 && Save_ALU_r == 1'b1) || ALU_Op_r == 4'b1001 )
757
 
758
              if (T_Res == 1'b1 && I_INRC == 1'b1 )
759
                begin
760
                  F[Flag_H] <= #1 1'b0;
761
                  F[Flag_N] <= #1 1'b0;
762
                  if (DI_Reg[7:0] == 8'b00000000 )
763
                    begin
764
                      F[Flag_Z] <= #1 1'b1;
765
                    end
766
                  else
767
                    begin
768
                      F[Flag_Z] <= #1 1'b0;
769
                    end
770
                  F[Flag_S] <= #1 DI_Reg[7];
771
                  F[Flag_P] <= #1 ~ (^DI_Reg[7:0]);
772
                end // if (T_Res == 1'b1 && I_INRC == 1'b1 )
773
 
774
 
775 21 ghutchis
              if (tstate[1] && Auto_Wait_t1 == 1'b0 )
776 2 ghutchis
                begin
777
                  do <= #1 BusB;
778
                  if (I_RLD == 1'b1 )
779
                    begin
780
                      do[3:0] <= #1 BusA[3:0];
781
                      do[7:4] <= #1 BusB[3:0];
782
                    end
783
                  if (I_RRD == 1'b1 )
784
                    begin
785
                      do[3:0] <= #1 BusB[7:4];
786
                      do[7:4] <= #1 BusA[3:0];
787
                    end
788
                end
789
 
790
              if (T_Res == 1'b1 )
791
                begin
792
                  Read_To_Reg_r[3:0] <= #1 Set_BusA_To;
793
                  Read_To_Reg_r[4] <= #1 Read_To_Reg;
794
                  if (Read_To_Acc == 1'b1 )
795
                    begin
796
                      Read_To_Reg_r[3:0] <= #1 4'b0111;
797
                      Read_To_Reg_r[4] <= #1 1'b1;
798
                    end
799
                end
800
 
801 21 ghutchis
              if (tstate[1] && I_BT == 1'b1 )
802 2 ghutchis
                begin
803
                  F[Flag_X] <= #1 ALU_Q[3];
804
                  F[Flag_Y] <= #1 ALU_Q[1];
805
                  F[Flag_H] <= #1 1'b0;
806
                  F[Flag_N] <= #1 1'b0;
807
                end
808
              if (I_BC == 1'b1 || I_BT == 1'b1 )
809
                begin
810
                  F[Flag_P] <= #1 IncDecZ;
811
                end
812
 
813 21 ghutchis
              if ((tstate[1] && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||
814 2 ghutchis
                  (Save_ALU_r == 1'b1 && ALU_Op_r != 4'b0111) )
815
                begin
816
                  case (Read_To_Reg_r)
817
                    5'b10111 :
818
                      ACC <= #1 Save_Mux;
819
                    5'b10110 :
820
                      do <= #1 Save_Mux;
821
                    5'b11000 :
822
                      SP[7:0] <= #1 Save_Mux;
823
                    5'b11001 :
824
                      SP[15:8] <= #1 Save_Mux;
825
                    5'b11011 :
826
                      F <= #1 Save_Mux;
827
                  endcase
828
                end // if ((tstate == 1 && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||...              
829
            end // if (ClkEn == 1'b1 )         
830
        end // else: !if(reset_n == 1'b0 )
831
    end
832
 
833
 
834
  //-------------------------------------------------------------------------
835
  //
836
  // BC('), DE('), HL('), IX && IY
837
  //
838
  //-------------------------------------------------------------------------
839
  always @ (posedge clk)
840
    begin
841
      if (ClkEn == 1'b1 )
842
        begin
843
          // Bus A / Write
844
          RegAddrA_r <= #1  { Alternate, Set_BusA_To[2:1] };
845
          if (XY_Ind == 1'b0 && XY_State != 2'b00 && Set_BusA_To[2:1] == 2'b10 )
846
            begin
847
              RegAddrA_r <= #1 { XY_State[1],  2'b11 };
848
            end
849
 
850
          // Bus B
851
          RegAddrB_r <= #1 { Alternate, Set_BusB_To[2:1] };
852
          if (XY_Ind == 1'b0 && XY_State != 2'b00 && Set_BusB_To[2:1] == 2'b10 )
853
            begin
854
              RegAddrB_r <= #1 { XY_State[1],  2'b11 };
855
            end
856
 
857
          // Address from register
858
          RegAddrC <= #1 { Alternate,  Set_Addr_To[1:0] };
859
          // Jump (HL), LD SP,HL
860
          if ((JumpXY == 1'b1 || LDSPHL == 1'b1) )
861
            begin
862
              RegAddrC <= #1 { Alternate, 2'b10 };
863
            end
864 21 ghutchis
          if (((JumpXY == 1'b1 || LDSPHL == 1'b1) && XY_State != 2'b00) || (mcycle[5]) )
865 2 ghutchis
            begin
866
              RegAddrC <= #1 { XY_State[1],  2'b11 };
867
            end
868
 
869
          if (I_DJNZ == 1'b1 && Save_ALU_r == 1'b1 && Mode < 2 )
870
            begin
871
              IncDecZ <= #1 F_Out[Flag_Z];
872
            end
873 21 ghutchis
          if ((tstate[2] || (tstate[3] && mcycle[0])) && IncDec_16[2:0] == 3'b100 )
874 2 ghutchis
            begin
875
              if (ID16 == 0 )
876
                begin
877
                  IncDecZ <= #1 1'b0;
878
                end
879
              else
880
                begin
881
                  IncDecZ <= #1 1'b1;
882
                end
883
            end
884
 
885
          RegBusA_r <= #1 RegBusA;
886
        end
887
 
888
    end // always @ (posedge clk)
889
 
890
 
891
  always @(/*AUTOSENSE*/Alternate or ExchangeDH or IncDec_16
892 21 ghutchis
           or RegAddrA_r or RegAddrB_r or XY_State or mcycle or tstate)
893 2 ghutchis
    begin
894 21 ghutchis
      if ((tstate[2] || (tstate[3] && mcycle[0] && IncDec_16[2] == 1'b1)) && XY_State == 2'b00)
895 2 ghutchis
        RegAddrA = { Alternate, IncDec_16[1:0] };
896 21 ghutchis
      else if ((tstate[2] || (tstate[3] && mcycle[0] && IncDec_16[2] == 1'b1)) && IncDec_16[1:0] == 2'b10)
897 2 ghutchis
        RegAddrA = { XY_State[1], 2'b11 };
898 21 ghutchis
      else if (ExchangeDH == 1'b1 && tstate[3])
899 2 ghutchis
        RegAddrA = { Alternate, 2'b10 };
900 21 ghutchis
      else if (ExchangeDH == 1'b1 && tstate[4])
901 2 ghutchis
        RegAddrA = { Alternate, 2'b01 };
902
      else
903
        RegAddrA = RegAddrA_r;
904
 
905 21 ghutchis
      if (ExchangeDH == 1'b1 && tstate[3])
906 2 ghutchis
        RegAddrB = { Alternate, 2'b01 };
907
      else
908
        RegAddrB = RegAddrB_r;
909
    end // always @ *
910
 
911
 
912
  always @(/*AUTOSENSE*/ALU_Op_r or Auto_Wait_t1 or ExchangeDH
913 21 ghutchis
           or IncDec_16 or Read_To_Reg_r or Save_ALU_r or mcycle
914
           or tstate or wait_n)
915 2 ghutchis
    begin
916
      RegWEH = 1'b0;
917
      RegWEL = 1'b0;
918 21 ghutchis
      if ((tstate[1] && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||
919 2 ghutchis
          (Save_ALU_r == 1'b1 && ALU_Op_r != 4'b0111) )
920
        begin
921
          case (Read_To_Reg_r)
922
            5'b10000 , 5'b10001 , 5'b10010 , 5'b10011 , 5'b10100 , 5'b10101 :
923
              begin
924
                RegWEH = ~ Read_To_Reg_r[0];
925
                RegWEL = Read_To_Reg_r[0];
926
              end
927
          endcase // case(Read_To_Reg_r)
928
 
929
        end // if ((tstate == 1 && Save_ALU_r == 1'b0 && Auto_Wait_t1 == 1'b0) ||...
930
 
931
 
932 21 ghutchis
      if (ExchangeDH == 1'b1 && (tstate[3] || tstate[4]) )
933 2 ghutchis
        begin
934
          RegWEH = 1'b1;
935
          RegWEL = 1'b1;
936
        end
937
 
938 21 ghutchis
      if (IncDec_16[2] == 1'b1 && ((tstate[2] && wait_n == 1'b1 && mcycle != 3'b001) || (tstate[3] && mcycle[0])) )
939 2 ghutchis
        begin
940
          case (IncDec_16[1:0])
941
            2'b00 , 2'b01 , 2'b10 :
942
              begin
943
                RegWEH = 1'b1;
944
                RegWEL = 1'b1;
945
              end
946
          endcase
947
        end
948
    end // always @ *
949
 
950
 
951
  always @(/*AUTOSENSE*/ExchangeDH or ID16 or IncDec_16 or RegBusA_r
952 21 ghutchis
           or RegBusB or Save_Mux or mcycle or tstate)
953 2 ghutchis
    begin
954
      RegDIH = Save_Mux;
955
      RegDIL = Save_Mux;
956
 
957 21 ghutchis
      if (ExchangeDH == 1'b1 && tstate[3] )
958 2 ghutchis
        begin
959
          RegDIH = RegBusB[15:8];
960
          RegDIL = RegBusB[7:0];
961
        end
962 21 ghutchis
      else if (ExchangeDH == 1'b1 && tstate[4] )
963 2 ghutchis
        begin
964
          RegDIH = RegBusA_r[15:8];
965
          RegDIL = RegBusA_r[7:0];
966
        end
967 21 ghutchis
      else if (IncDec_16[2] == 1'b1 && ((tstate[2] && mcycle != 3'b001) || (tstate[3] && mcycle[0])) )
968 2 ghutchis
        begin
969
          RegDIH = ID16[15:8];
970
          RegDIL = ID16[7:0];
971
        end
972
    end
973
 
974
  tv80_reg i_reg
975
    (
976
     .clk                  (clk),
977
     .CEN                  (ClkEn),
978
     .WEH                  (RegWEH),
979
     .WEL                  (RegWEL),
980
     .AddrA                (RegAddrA),
981
     .AddrB                (RegAddrB),
982
     .AddrC                (RegAddrC),
983
     .DIH                  (RegDIH),
984
     .DIL                  (RegDIL),
985
     .DOAH                 (RegBusA[15:8]),
986
     .DOAL                 (RegBusA[7:0]),
987
     .DOBH                 (RegBusB[15:8]),
988
     .DOBL                 (RegBusB[7:0]),
989
     .DOCH                 (RegBusC[15:8]),
990
     .DOCL                 (RegBusC[7:0])
991
     );
992
 
993
  //-------------------------------------------------------------------------
994
  //
995
  // Buses
996
  //
997
  //-------------------------------------------------------------------------
998
 
999
  always @ (posedge clk)
1000
    begin
1001
      if (ClkEn == 1'b1 )
1002
        begin
1003
          case (Set_BusB_To)
1004
            4'b0111 :
1005
              BusB <= #1 ACC;
1006
            4'b0000 , 4'b0001 , 4'b0010 , 4'b0011 , 4'b0100 , 4'b0101 :
1007
              begin
1008
                if (Set_BusB_To[0] == 1'b1 )
1009
                  begin
1010
                    BusB <= #1 RegBusB[7:0];
1011
                  end
1012
                else
1013
                  begin
1014
                    BusB <= #1 RegBusB[15:8];
1015
                  end
1016
              end
1017
            4'b0110 :
1018
              BusB <= #1 DI_Reg;
1019
            4'b1000 :
1020
              BusB <= #1 SP[7:0];
1021
            4'b1001 :
1022
              BusB <= #1 SP[15:8];
1023
            4'b1010 :
1024
              BusB <= #1 8'b00000001;
1025
            4'b1011 :
1026
              BusB <= #1 F;
1027
            4'b1100 :
1028
              BusB <= #1 PC[7:0];
1029
            4'b1101 :
1030
              BusB <= #1 PC[15:8];
1031
            4'b1110 :
1032
              BusB <= #1 8'b00000000;
1033
            default :
1034
              BusB <= #1 8'hxx;
1035
          endcase
1036
 
1037
          case (Set_BusA_To)
1038
            4'b0111 :
1039
              BusA <= #1 ACC;
1040
            4'b0000 , 4'b0001 , 4'b0010 , 4'b0011 , 4'b0100 , 4'b0101 :
1041
              begin
1042
                if (Set_BusA_To[0] == 1'b1 )
1043
                  begin
1044
                    BusA <= #1 RegBusA[7:0];
1045
                  end
1046
                else
1047
                  begin
1048
                    BusA <= #1 RegBusA[15:8];
1049
                  end
1050
              end
1051
            4'b0110 :
1052
              BusA <= #1 DI_Reg;
1053
            4'b1000 :
1054
              BusA <= #1 SP[7:0];
1055
            4'b1001 :
1056
              BusA <= #1 SP[15:8];
1057
            4'b1010 :
1058
              BusA <= #1 8'b00000000;
1059
            default :
1060
              BusB <= #1  8'hxx;
1061
          endcase
1062
        end
1063
    end
1064
 
1065
  //-------------------------------------------------------------------------
1066
  //
1067
  // Generate external control signals
1068
  //
1069
  //-------------------------------------------------------------------------
1070
  always @ (posedge clk)
1071
    begin
1072
      if (reset_n == 1'b0 )
1073
        begin
1074
          rfsh_n <= #1 1'b1;
1075
        end
1076
      else
1077
        begin
1078
          if (cen == 1'b1 )
1079
            begin
1080 21 ghutchis
              if (mcycle[0] && ((tstate[2]  && wait_n == 1'b1) || tstate[3]) )
1081 2 ghutchis
                begin
1082
                  rfsh_n <= #1 1'b0;
1083
                end
1084
              else
1085
                begin
1086
                  rfsh_n <= #1 1'b1;
1087
                end
1088
            end
1089
        end
1090
    end
1091
 
1092
 
1093
  always @(/*AUTOSENSE*/BusAck or Halt_FF or I_DJNZ or IntCycle
1094 21 ghutchis
           or IntE_FF1 or di or iorq_i or mcycle or tstate)
1095 2 ghutchis
    begin
1096
      mc = mcycle;
1097
      ts = tstate;
1098
      DI_Reg = di;
1099
      halt_n = ~ Halt_FF;
1100
      busak_n = ~ BusAck;
1101
      intcycle_n = ~ IntCycle;
1102
      IntE = IntE_FF1;
1103
      iorq = iorq_i;
1104
      stop = I_DJNZ;
1105
    end
1106
 
1107
  //-----------------------------------------------------------------------
1108
  //
1109
  // Syncronise inputs
1110
  //
1111
  //-----------------------------------------------------------------------
1112
 
1113
  always @ (posedge clk)
1114
    begin : sync_inputs
1115
 
1116
      if (reset_n == 1'b0 )
1117
        begin
1118
          BusReq_s <= #1 1'b0;
1119
          INT_s <= #1 1'b0;
1120
          NMI_s <= #1 1'b0;
1121
          Oldnmi_n <= #1 1'b0;
1122
        end
1123
      else
1124
        begin
1125
          if (cen == 1'b1 )
1126
            begin
1127
              BusReq_s <= #1 ~ busrq_n;
1128
              INT_s <= #1 ~ int_n;
1129
              if (NMICycle == 1'b1 )
1130
                begin
1131
                  NMI_s <= #1 1'b0;
1132
                end
1133
              else if (nmi_n == 1'b0 && Oldnmi_n == 1'b1 )
1134
                begin
1135
                  NMI_s <= #1 1'b1;
1136
                end
1137
              Oldnmi_n <= #1 nmi_n;
1138
            end
1139
        end
1140
    end
1141
 
1142
  //-----------------------------------------------------------------------
1143
  //
1144
  // Main state machine
1145
  //
1146
  //-----------------------------------------------------------------------
1147
 
1148
  always @ (posedge clk)
1149
    begin
1150
      if (reset_n == 1'b0 )
1151
        begin
1152 21 ghutchis
          mcycle <= #1 7'b0000001;
1153
          tstate <= #1 7'b0000001;
1154 2 ghutchis
          Pre_XY_F_M <= #1 3'b000;
1155
          Halt_FF <= #1 1'b0;
1156
          BusAck <= #1 1'b0;
1157
          NMICycle <= #1 1'b0;
1158
          IntCycle <= #1 1'b0;
1159
          IntE_FF1 <= #1 1'b0;
1160
          IntE_FF2 <= #1 1'b0;
1161
          No_BTR <= #1 1'b0;
1162
          Auto_Wait_t1 <= #1 1'b0;
1163
          Auto_Wait_t2 <= #1 1'b0;
1164
          m1_n <= #1 1'b1;
1165
        end
1166
      else
1167
        begin
1168
          if (cen == 1'b1 )
1169
            begin
1170
              if (T_Res == 1'b1 )
1171
                begin
1172
                  Auto_Wait_t1 <= #1 1'b0;
1173
                end
1174
              else
1175
                begin
1176
                  Auto_Wait_t1 <= #1 Auto_Wait || iorq_i;
1177
                end
1178
              Auto_Wait_t2 <= #1 Auto_Wait_t1;
1179
              No_BTR <= #1 (I_BT && (~ IR[4] || ~ F[Flag_P])) ||
1180
                        (I_BC && (~ IR[4] || F[Flag_Z] || ~ F[Flag_P])) ||
1181
                        (I_BTR && (~ IR[4] || F[Flag_Z]));
1182 21 ghutchis
              if (tstate[2] )
1183 2 ghutchis
                begin
1184
                  if (SetEI == 1'b1 )
1185
                    begin
1186
                      IntE_FF1 <= #1 1'b1;
1187
                      IntE_FF2 <= #1 1'b1;
1188
                    end
1189
                  if (I_RETN == 1'b1 )
1190
                    begin
1191
                      IntE_FF1 <= #1 IntE_FF2;
1192
                    end
1193
                end
1194 21 ghutchis
              if (tstate[3] )
1195 2 ghutchis
                begin
1196
                  if (SetDI == 1'b1 )
1197
                    begin
1198
                      IntE_FF1 <= #1 1'b0;
1199
                      IntE_FF2 <= #1 1'b0;
1200
                    end
1201
                end
1202
              if (IntCycle == 1'b1 || NMICycle == 1'b1 )
1203
                begin
1204
                  Halt_FF <= #1 1'b0;
1205
                end
1206 21 ghutchis
              if (mcycle[0] && tstate[2] && wait_n == 1'b1 )
1207 2 ghutchis
                begin
1208
                  m1_n <= #1 1'b1;
1209
                end
1210
              if (BusReq_s == 1'b1 && BusAck == 1'b1 )
1211
                begin
1212
                end
1213
              else
1214
                begin
1215
                  BusAck <= #1 1'b0;
1216 21 ghutchis
                  if (tstate[2] && wait_n == 1'b0 )
1217 2 ghutchis
                    begin
1218
                    end
1219
                  else if (T_Res == 1'b1 )
1220
                    begin
1221
                      if (Halt == 1'b1 )
1222
                        begin
1223
                          Halt_FF <= #1 1'b1;
1224
                        end
1225
                      if (BusReq_s == 1'b1 )
1226
                        begin
1227
                          BusAck <= #1 1'b1;
1228
                        end
1229
                      else
1230
                        begin
1231 22 ghutchis
                          tstate <= #1 7'b0000010;
1232 2 ghutchis
                          if (NextIs_XY_Fetch == 1'b1 )
1233
                            begin
1234 21 ghutchis
                              mcycle <= #1 7'b0100000;
1235 2 ghutchis
                              Pre_XY_F_M <= #1 mcycle;
1236
                              if (IR == 8'b00110110 && Mode == 0 )
1237
                                begin
1238
                                  Pre_XY_F_M <= #1 3'b010;
1239
                                end
1240
                            end
1241 21 ghutchis
                          else if ((mcycle[6]) || (mcycle[5] && Mode == 1 && ISet != 2'b01) )
1242 2 ghutchis
                            begin
1243 21 ghutchis
                              mcycle <= #1 number_to_bitvec(Pre_XY_F_M + 1);
1244 2 ghutchis
                            end
1245 21 ghutchis
                          else if ((last_mcycle) ||
1246 2 ghutchis
                                   No_BTR == 1'b1 ||
1247 21 ghutchis
                                   (mcycle[1] && I_DJNZ == 1'b1 && IncDecZ == 1'b1) )
1248 2 ghutchis
                            begin
1249
                              m1_n <= #1 1'b0;
1250 21 ghutchis
                              mcycle <= #1 7'b0000001;
1251 2 ghutchis
                              IntCycle <= #1 1'b0;
1252
                              NMICycle <= #1 1'b0;
1253
                              if (NMI_s == 1'b1 && Prefix == 2'b00 )
1254
                                begin
1255
                                  NMICycle <= #1 1'b1;
1256
                                  IntE_FF1 <= #1 1'b0;
1257
                                end
1258
                              else if ((IntE_FF1 == 1'b1 && INT_s == 1'b1) && Prefix == 2'b00 && SetEI == 1'b0 )
1259
                                begin
1260
                                  IntCycle <= #1 1'b1;
1261
                                  IntE_FF1 <= #1 1'b0;
1262
                                  IntE_FF2 <= #1 1'b0;
1263
                                end
1264
                            end
1265
                          else
1266
                            begin
1267 21 ghutchis
                              mcycle <= #1 { mcycle[5:0], mcycle[6] };
1268 2 ghutchis
                            end
1269
                        end
1270
                    end
1271
                  else
1272
                    begin   // verilog has no "nor" operator
1273
                      if ( ~(Auto_Wait == 1'b1 && Auto_Wait_t2 == 1'b0) &&
1274
                           ~(IOWait == 1 && iorq_i == 1'b1 && Auto_Wait_t1 == 1'b0) )
1275
                        begin
1276 21 ghutchis
                          tstate <= #1 { tstate[5:0], tstate[6] };
1277 2 ghutchis
                        end
1278
                    end
1279
                end
1280 21 ghutchis
              if (tstate[0])
1281 2 ghutchis
                begin
1282
                  m1_n <= #1 1'b0;
1283
                end
1284
            end
1285
        end
1286
    end
1287
 
1288
  always @(/*AUTOSENSE*/BTR_r or DI_Reg or IncDec_16 or JumpE or PC
1289 21 ghutchis
           or RegBusA or RegBusC or SP or tstate)
1290 2 ghutchis
    begin
1291
      if (JumpE == 1'b1 )
1292
        begin
1293
          PC16_B = { {8{DI_Reg[7]}}, DI_Reg };
1294
        end
1295
      else if (BTR_r == 1'b1 )
1296
        begin
1297
          PC16_B = -2;
1298
        end
1299
      else
1300
        begin
1301
          PC16_B = 1;
1302
        end
1303
 
1304 21 ghutchis
      if (tstate[3])
1305 2 ghutchis
        begin
1306
          SP16_A = RegBusC;
1307
          SP16_B = { {8{DI_Reg[7]}}, DI_Reg };
1308
        end
1309
      else
1310
        begin
1311
          // suspect that ID16 and SP16 could be shared
1312
          SP16_A = SP;
1313
 
1314
          if (IncDec_16[3] == 1'b1)
1315
            SP16_B = -1;
1316
          else
1317
            SP16_B = 1;
1318
        end
1319
 
1320
      if (IncDec_16[3])
1321
        ID16_B = -1;
1322
      else
1323
        ID16_B = 1;
1324
 
1325
      ID16 = RegBusA + ID16_B;
1326
      PC16 = PC + PC16_B;
1327
      SP16 = SP16_A + SP16_B;
1328
    end // always @ *
1329
 
1330
 
1331
  always @(/*AUTOSENSE*/IntCycle or NMICycle or mcycle)
1332
    begin
1333
      Auto_Wait = 1'b0;
1334
      if (IntCycle == 1'b1 || NMICycle == 1'b1 )
1335
        begin
1336 21 ghutchis
          if (mcycle[0] )
1337 2 ghutchis
            begin
1338
              Auto_Wait = 1'b1;
1339
            end
1340
        end
1341
    end // always @ *
1342
 
1343
// synopsys dc_script_begin
1344 24 ghutchis
// set_attribute current_design "revision" "$Id: tv80_core.v,v 1.4 2004-10-05 08:09:43 ghutchis Exp $" -type string -quiet
1345 2 ghutchis
// synopsys dc_script_end
1346
endmodule // T80
1347
 

powered by: WebSVN 2.1.0

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