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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc2/] [rtl/] [core/] [tv80_mcode_cb.v] - Blame information for rev 86

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

Line No. Rev Author Line
1 48 ghutchis
//
2
// TV80 8-Bit Microprocessor Core
3
// Based on the VHDL T80 core by Daniel Wallner (jesus@opencores.org)
4
//
5
// Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a 
8
// copy of this software and associated documentation files (the "Software"), 
9
// to deal in the Software without restriction, including without limitation 
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
11
// and/or sell copies of the Software, and to permit persons to whom the 
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included 
15
// in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
19
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
20
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
21
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
22
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
23
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
25
module tv80_mcode_cb
26
  (/*AUTOARG*/
27
  // Outputs
28
  output_vector,
29
  // Inputs
30
  IR, MCycle
31
  );
32
 
33
  parameter             Mode   = 0;
34
  parameter             Flag_C = 0;
35
  parameter             Flag_N = 1;
36
  parameter             Flag_P = 2;
37
  parameter             Flag_X = 3;
38
  parameter             Flag_H = 4;
39
  parameter             Flag_Y = 5;
40
  parameter             Flag_Z = 6;
41
  parameter             Flag_S = 7;
42
 
43
  output [67:0]         output_vector;
44
 
45
  input [7:0]           IR;
46
  input [6:0]           MCycle                  ;
47
 
48
  // regs
49
  reg [2:0]             MCycles                 ;
50
  reg [2:0]             TStates                 ;
51
  reg [1:0]             Prefix                  ; // None,BC,ED,DD/FD
52
  reg                   Inc_PC                  ;
53
  reg                   Inc_WZ                  ;
54
  reg [3:0]             IncDec_16               ; // BC,DE,HL,SP   0 is inc
55
  reg                   Read_To_Reg             ;
56
  reg                   Read_To_Acc             ;
57
  reg [3:0]             Set_BusA_To     ; // B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
58
  reg [3:0]             Set_BusB_To     ; // B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
59
  reg [3:0]             ALU_Op                  ;
60
  reg                   Save_ALU                ;
61
  reg                   PreserveC               ;
62
  reg                   Arith16                 ;
63
  reg [2:0]             Set_Addr_To             ; // aNone,aXY,aIOA,aSP,aBC,aDE,aZI
64
  reg                   IORQ                    ;
65
  reg                   Jump                    ;
66
  reg                   JumpE                   ;
67
  reg                   JumpXY                  ;
68
  reg                   Call                    ;
69
  reg                   RstP                    ;
70
  reg                   LDZ                     ;
71
  reg                   LDW                     ;
72
  reg                   LDSPHL                  ;
73
  reg [2:0]             Special_LD              ; // A,I;A,R;I,A;R,A;None
74
  reg                   ExchangeDH              ;
75
  reg                   ExchangeRp              ;
76
  reg                   ExchangeAF              ;
77
  reg                   ExchangeRS              ;
78
  reg                   I_DJNZ                  ;
79
  reg                   I_CPL                   ;
80
  reg                   I_CCF                   ;
81
  reg                   I_SCF                   ;
82
  reg                   I_RETN                  ;
83
  reg                   I_BT                    ;
84
  reg                   I_BC                    ;
85
  reg                   I_BTR                   ;
86
  reg                   I_RLD                   ;
87
  reg                   I_RRD                   ;
88
  reg                   I_INRC                  ;
89
  reg                   SetDI                   ;
90
  reg                   SetEI                   ;
91
  reg [1:0]             IMode                   ;
92
  reg                   Halt                    ;
93
  reg                   NoRead                  ;
94
  reg                   Write   ;
95
 
96
  parameter             aNone   = 3'b111;
97
  parameter             aBC     = 3'b000;
98
  parameter             aDE     = 3'b001;
99
  parameter             aXY     = 3'b010;
100
  parameter             aIOA    = 3'b100;
101
  parameter             aSP     = 3'b101;
102
  parameter             aZI     = 3'b110;
103
  //    constant aNone  : std_logic_vector[2:0] = 3'b000;
104
  //    constant aXY    : std_logic_vector[2:0] = 3'b001;
105
  //    constant aIOA   : std_logic_vector[2:0] = 3'b010;
106
  //    constant aSP    : std_logic_vector[2:0] = 3'b011;
107
  //    constant aBC    : std_logic_vector[2:0] = 3'b100;
108
  //    constant aDE    : std_logic_vector[2:0] = 3'b101;
109
  //    constant aZI    : std_logic_vector[2:0] = 3'b110;
110
 
111
  function is_cc_true;
112
    input [7:0] F;
113
    input [2:0] cc;
114
    begin
115
      if (Mode == 3 )
116
        begin
117
          case (cc)
118
            3'b000  : is_cc_true = F[7] == 1'b0; // NZ
119
            3'b001  : is_cc_true = F[7] == 1'b1; // Z
120
            3'b010  : is_cc_true = F[4] == 1'b0; // NC
121
            3'b011  : is_cc_true = F[4] == 1'b1; // C
122
            3'b100  : is_cc_true = 0;
123
            3'b101  : is_cc_true = 0;
124
            3'b110  : is_cc_true = 0;
125
            3'b111  : is_cc_true = 0;
126
          endcase
127
        end
128
      else
129
        begin
130
          case (cc)
131
            3'b000  : is_cc_true = F[6] == 1'b0; // NZ
132
            3'b001  : is_cc_true = F[6] == 1'b1; // Z
133
            3'b010  : is_cc_true = F[0] == 1'b0; // NC
134
            3'b011  : is_cc_true = F[0] == 1'b1; // C
135
            3'b100  : is_cc_true = F[2] == 1'b0; // PO
136
            3'b101  : is_cc_true = F[2] == 1'b1; // PE
137
            3'b110  : is_cc_true = F[7] == 1'b0; // P
138
            3'b111  : is_cc_true = F[7] == 1'b1; // M
139
          endcase
140
        end
141
    end
142
  endfunction // is_cc_true
143
 
144
 
145
  reg [2:0] DDD;
146
  reg [2:0] SSS;
147
  reg [1:0] DPAIR;
148
  reg [7:0] IRB;
149
 
150
  always @ (/*AUTOSENSE*/IR or MCycle)
151
    begin
152
      DDD = IR[5:3];
153
      SSS = IR[2:0];
154
      DPAIR = IR[5:4];
155
      IRB = IR;
156
 
157
      MCycles = 3'b001;
158
      if (MCycle[0] )
159
        begin
160
          TStates = 3'b100;
161
        end
162
      else
163
        begin
164
          TStates = 3'b011;
165
        end
166
      Prefix = 2'b00;
167
      Inc_PC = 1'b0;
168
      Inc_WZ = 1'b0;
169
      IncDec_16 = 4'b0000;
170
      Read_To_Acc = 1'b0;
171
      Read_To_Reg = 1'b0;
172
      Set_BusB_To = 4'b0000;
173
      Set_BusA_To = 4'b0000;
174
      ALU_Op = { 1'b0, IR[5:3] };
175
      Save_ALU = 1'b0;
176
      PreserveC = 1'b0;
177
      Arith16 = 1'b0;
178
      IORQ = 1'b0;
179
      Set_Addr_To = aNone;
180
      Jump = 1'b0;
181
      JumpE = 1'b0;
182
      JumpXY = 1'b0;
183
      Call = 1'b0;
184
      RstP = 1'b0;
185
      LDZ = 1'b0;
186
      LDW = 1'b0;
187
      LDSPHL = 1'b0;
188
      Special_LD = 3'b000;
189
      ExchangeDH = 1'b0;
190
      ExchangeRp = 1'b0;
191
      ExchangeAF = 1'b0;
192
      ExchangeRS = 1'b0;
193
      I_DJNZ = 1'b0;
194
      I_CPL = 1'b0;
195
      I_CCF = 1'b0;
196
      I_SCF = 1'b0;
197
      I_RETN = 1'b0;
198
      I_BT = 1'b0;
199
      I_BC = 1'b0;
200
      I_BTR = 1'b0;
201
      I_RLD = 1'b0;
202
      I_RRD = 1'b0;
203
      I_INRC = 1'b0;
204
      SetDI = 1'b0;
205
      SetEI = 1'b0;
206
      IMode = 2'b11;
207
      Halt = 1'b0;
208
      NoRead = 1'b0;
209
      Write = 1'b0;
210
 
211
 
212
      //----------------------------------------------------------------------------
213
      //
214
      //  CB prefixed instructions
215
      //
216
      //----------------------------------------------------------------------------
217
 
218
      Set_BusA_To[2:0] = IR[2:0];
219
      Set_BusB_To[2:0] = IR[2:0];
220
 
221
      case (IRB)
222
        8'b00000000,8'b00000001,8'b00000010,8'b00000011,8'b00000100,8'b00000101,8'b00000111,
223
        8'b00010000,8'b00010001,8'b00010010,8'b00010011,8'b00010100,8'b00010101,8'b00010111,
224
        8'b00001000,8'b00001001,8'b00001010,8'b00001011,8'b00001100,8'b00001101,8'b00001111,
225
        8'b00011000,8'b00011001,8'b00011010,8'b00011011,8'b00011100,8'b00011101,8'b00011111,
226
        8'b00100000,8'b00100001,8'b00100010,8'b00100011,8'b00100100,8'b00100101,8'b00100111,
227
        8'b00101000,8'b00101001,8'b00101010,8'b00101011,8'b00101100,8'b00101101,8'b00101111,
228
        8'b00110000,8'b00110001,8'b00110010,8'b00110011,8'b00110100,8'b00110101,8'b00110111,
229
        8'b00111000,8'b00111001,8'b00111010,8'b00111011,8'b00111100,8'b00111101,8'b00111111 :
230
          begin
231
            // RLC r
232
            // RL r
233
            // RRC r
234
            // RR r
235
            // SLA r
236
            // SRA r
237
            // SRL r
238
            // SLL r (Undocumented) / SWAP r
239
            if (MCycle[0] ) begin
240
              ALU_Op = 4'b1000;
241
              Read_To_Reg = 1'b1;
242
              Save_ALU = 1'b1;
243
            end
244
          end // case: 8'b00000000,8'b00000001,8'b00000010,8'b00000011,8'b00000100,8'b00000101,8'b00000111,...
245
 
246
        8'b00000110,8'b00010110,8'b00001110,8'b00011110,8'b00101110,8'b00111110,8'b00100110,8'b00110110  :
247
          begin
248
            // RLC (HL)
249
            // RL (HL)
250
            // RRC (HL)
251
            // RR (HL)
252
            // SRA (HL)
253
            // SRL (HL)
254
            // SLA (HL)
255
            // SLL (HL) (Undocumented) / SWAP (HL)
256
            MCycles = 3'b011;
257
            case (1'b1) // MCycle
258
              MCycle[0], MCycle[6] :
259
                Set_Addr_To = aXY;
260
              MCycle[1] :
261
                begin
262
                  ALU_Op = 4'b1000;
263
                  Read_To_Reg = 1'b1;
264
                  Save_ALU = 1'b1;
265
                  Set_Addr_To = aXY;
266
                  TStates = 3'b100;
267
                end
268
 
269
              MCycle[2] :
270
                Write = 1'b1;
271
              default :;
272
            endcase // case(MCycle)
273
          end // case: 8'b00000110,8'b00010110,8'b00001110,8'b00011110,8'b00101110,8'b00111110,8'b00100110,8'b00110110
274
 
275
        8'b01000000,8'b01000001,8'b01000010,8'b01000011,8'b01000100,8'b01000101,8'b01000111,
276
            8'b01001000,8'b01001001,8'b01001010,8'b01001011,8'b01001100,8'b01001101,8'b01001111,
277
            8'b01010000,8'b01010001,8'b01010010,8'b01010011,8'b01010100,8'b01010101,8'b01010111,
278
            8'b01011000,8'b01011001,8'b01011010,8'b01011011,8'b01011100,8'b01011101,8'b01011111,
279
            8'b01100000,8'b01100001,8'b01100010,8'b01100011,8'b01100100,8'b01100101,8'b01100111,
280
            8'b01101000,8'b01101001,8'b01101010,8'b01101011,8'b01101100,8'b01101101,8'b01101111,
281
            8'b01110000,8'b01110001,8'b01110010,8'b01110011,8'b01110100,8'b01110101,8'b01110111,
282
            8'b01111000,8'b01111001,8'b01111010,8'b01111011,8'b01111100,8'b01111101,8'b01111111 :
283
              begin
284
                // BIT b,r
285
                if (MCycle[0] )
286
                  begin
287
                    Set_BusB_To[2:0] = IR[2:0];
288
                    ALU_Op = 4'b1001;
289
                  end
290
              end // case: 8'b01000000,8'b01000001,8'b01000010,8'b01000011,8'b01000100,8'b01000101,8'b01000111,...
291
 
292
        8'b01000110,8'b01001110,8'b01010110,8'b01011110,8'b01100110,8'b01101110,8'b01110110,8'b01111110  :
293
          begin
294
            // BIT b,(HL)
295
            MCycles = 3'b010;
296
            case (1'b1) // MCycle
297
              MCycle[0], MCycle[6] :
298
                Set_Addr_To = aXY;
299
              MCycle[1] :
300
                begin
301
                  ALU_Op = 4'b1001;
302
                  TStates = 3'b100;
303
                end
304
 
305
              default :;
306
            endcase // case(MCycle)
307
          end // case: 8'b01000110,8'b01001110,8'b01010110,8'b01011110,8'b01100110,8'b01101110,8'b01110110,8'b01111110
308
 
309
        8'b11000000,8'b11000001,8'b11000010,8'b11000011,8'b11000100,8'b11000101,8'b11000111,
310
            8'b11001000,8'b11001001,8'b11001010,8'b11001011,8'b11001100,8'b11001101,8'b11001111,
311
            8'b11010000,8'b11010001,8'b11010010,8'b11010011,8'b11010100,8'b11010101,8'b11010111,
312
            8'b11011000,8'b11011001,8'b11011010,8'b11011011,8'b11011100,8'b11011101,8'b11011111,
313
            8'b11100000,8'b11100001,8'b11100010,8'b11100011,8'b11100100,8'b11100101,8'b11100111,
314
            8'b11101000,8'b11101001,8'b11101010,8'b11101011,8'b11101100,8'b11101101,8'b11101111,
315
            8'b11110000,8'b11110001,8'b11110010,8'b11110011,8'b11110100,8'b11110101,8'b11110111,
316
            8'b11111000,8'b11111001,8'b11111010,8'b11111011,8'b11111100,8'b11111101,8'b11111111 :
317
              begin
318
                // SET b,r
319
                if (MCycle[0] )
320
                  begin
321
                    ALU_Op = 4'b1010;
322
                    Read_To_Reg = 1'b1;
323
                    Save_ALU = 1'b1;
324
                  end
325
              end // case: 8'b11000000,8'b11000001,8'b11000010,8'b11000011,8'b11000100,8'b11000101,8'b11000111,...
326
 
327
        8'b11000110,8'b11001110,8'b11010110,8'b11011110,8'b11100110,8'b11101110,8'b11110110,8'b11111110  :
328
          begin
329
            // SET b,(HL)
330
            MCycles = 3'b011;
331
            case (1'b1) // MCycle
332
              MCycle[0], MCycle[6] :
333
                Set_Addr_To = aXY;
334
              MCycle[1] :
335
                begin
336
                  ALU_Op = 4'b1010;
337
                  Read_To_Reg = 1'b1;
338
                  Save_ALU = 1'b1;
339
                  Set_Addr_To = aXY;
340
                  TStates = 3'b100;
341
                end
342
              MCycle[2] :
343
                Write = 1'b1;
344
              default :;
345
            endcase // case(MCycle)
346
          end // case: 8'b11000110,8'b11001110,8'b11010110,8'b11011110,8'b11100110,8'b11101110,8'b11110110,8'b11111110
347
 
348
        8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,
349
            8'b10001000,8'b10001001,8'b10001010,8'b10001011,8'b10001100,8'b10001101,8'b10001111,
350
            8'b10010000,8'b10010001,8'b10010010,8'b10010011,8'b10010100,8'b10010101,8'b10010111,
351
            8'b10011000,8'b10011001,8'b10011010,8'b10011011,8'b10011100,8'b10011101,8'b10011111,
352
            8'b10100000,8'b10100001,8'b10100010,8'b10100011,8'b10100100,8'b10100101,8'b10100111,
353
            8'b10101000,8'b10101001,8'b10101010,8'b10101011,8'b10101100,8'b10101101,8'b10101111,
354
            8'b10110000,8'b10110001,8'b10110010,8'b10110011,8'b10110100,8'b10110101,8'b10110111,
355
            8'b10111000,8'b10111001,8'b10111010,8'b10111011,8'b10111100,8'b10111101,8'b10111111 :
356
              begin
357
                // RES b,r
358
                if (MCycle[0] )
359
                  begin
360
                    ALU_Op = 4'b1011;
361
                    Read_To_Reg = 1'b1;
362
                    Save_ALU = 1'b1;
363
                  end
364
              end // case: 8'b10000000,8'b10000001,8'b10000010,8'b10000011,8'b10000100,8'b10000101,8'b10000111,...
365
 
366
        8'b10000110,8'b10001110,8'b10010110,8'b10011110,8'b10100110,8'b10101110,8'b10110110,8'b10111110  :
367
          begin
368
            // RES b,(HL)
369
            MCycles = 3'b011;
370
            case (1'b1) // MCycle
371
              MCycle[0], MCycle[6] :
372
                Set_Addr_To = aXY;
373
              MCycle[1] :
374
                begin
375
                  ALU_Op = 4'b1011;
376
                  Read_To_Reg = 1'b1;
377
                  Save_ALU = 1'b1;
378
                  Set_Addr_To = aXY;
379
                  TStates = 3'b100;
380
                end
381
 
382
              MCycle[2] :
383
                Write = 1'b1;
384
              default :;
385
            endcase // case(MCycle)
386
          end // case: 8'b10000110,8'b10001110,8'b10010110,8'b10011110,8'b10100110,8'b10101110,8'b10110110,8'b10111110
387
 
388
      endcase // case(IRB)
389
 
390
    end // always @ (IR, ISet, MCycle, F, NMICycle, IntCycle)
391
 
392
  assign output_vector = { MCycles,
393
                           TStates,
394
                           Prefix,
395
                           Inc_PC,
396
                           Inc_WZ,
397
                           IncDec_16,
398
                           Read_To_Reg,
399
                           Read_To_Acc,
400
                           Set_BusA_To,
401
                           Set_BusB_To,
402
                           ALU_Op,
403
                           Save_ALU,
404
                           PreserveC,
405
                           Arith16,
406
                           Set_Addr_To,
407
                           IORQ,
408
                           Jump,
409
                           JumpE,
410
                           JumpXY,
411
                           Call,
412
                           RstP,
413
                           LDZ,
414
                           LDW,
415
                           LDSPHL,
416
                           Special_LD,
417
                           ExchangeDH,
418
                           ExchangeRp,
419
                           ExchangeAF,
420
                           ExchangeRS,
421
                           I_DJNZ,
422
                           I_CPL,
423
                           I_CCF,
424
                           I_SCF,
425
                           I_RETN,
426
                           I_BT,
427
                           I_BC,
428
                           I_BTR,
429
                           I_RLD,
430
                           I_RRD,
431
                           I_INRC,
432
                           SetDI,
433
                           SetEI,
434
                           IMode,
435
                           Halt,
436
                           NoRead,
437
                           Write };
438
 
439
  // synopsys dc_script_begin
440
  // set_attribute current_design "revision" "$Id: tv80_mcode_cb.v,v 1.1.2.1 2004-11-30 21:58:10 ghutchis Exp $" -type string -quiet
441
  // synopsys dc_script_end
442
endmodule // T80_MCode

powered by: WebSVN 2.1.0

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