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

Subversion Repositories m65c02

[/] [m65c02/] [trunk/] [Sim/] [tb_M65C02_ALU.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
///////////////////////////////////////////////////////////////////////////////
2
//
3
//  Copyright 2012 by Michael A. Morris, dba M. A. Morris & Associates
4
//
5
//  All rights reserved. The source code contained herein is publicly released
6
//  under the terms an conditions of the GNU Lesser Public License. No part of
7
//  this source code may be reproduced or transmitted in any form or by any
8
//  means, electronic or mechanical, including photocopying, recording, or any
9
//  information storage and retrieval system in violation of the license under
10
//  which the source code is released.
11
//
12
//  The source code contained herein is free; it may be redistributed and/or 
13
//  modified in accordance with the terms of the GNU Lesser General Public
14
//  License as published by the Free Software Foundation; either version 2.1 of
15
//  the GNU Lesser General Public License, or any later version.
16
//
17
//  The source code contained herein is freely released WITHOUT ANY WARRANTY;
18
//  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19
//  PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
20
//  more details.)
21
//
22
//  A copy of the GNU Lesser General Public License should have been received
23
//  along with the source code contained herein; if not, a copy can be obtained
24
//  by writing to:
25
//
26
//  Free Software Foundation, Inc.
27
//  51 Franklin Street, Fifth Floor
28
//  Boston, MA  02110-1301 USA
29
//
30
//  Further, no use of this source code is permitted in any form or means
31
//  without inclusion of this banner prominently in any derived works. 
32
//
33
//  Michael A. Morris
34
//  Huntsville, AL
35
//
36
///////////////////////////////////////////////////////////////////////////////
37
 
38
`timescale 1ns / 1ps
39
 
40
///////////////////////////////////////////////////////////////////////////////
41
// Company:         M. A. Morris & Associates 
42
// Engineer:        Michael A. Morris
43
//
44
// Create Date:     09:02:48 11/28/2009
45
// Design Name:     W65C02_ALU
46
// Module Name:     C:/XProjects/ISE10.1i/MAM6502/tb_W65C02_ALU.v
47
// Project Name:    MAM6502
48
// Target Device:   SRAM-based FPGA  
49
// Tool versions:   Xilinx ISE 10.1i SP3
50
//  
51
// Description: 
52
//
53
// Verilog Test Fixture created by ISE for module: W65C02_ALU
54
//
55
// Dependencies:
56
// 
57
// Revision:
58
// 
59
//  0.01    09K28   MAM     Initial coding
60
//
61
// Additional Comments:
62
//
63
//  The simulation performs checks against expected results. A test vector file
64
//  could have been used. However, the vector would have been more difficult to
65
//  interpret and construct. Although this implementation is a brute force
66
//  approach, the test vectors as defined in this file can be used to construct
67
//  the "fixed" microprogram ROM. Only the En input field does not belong in
68
//  the "fixed" microcode ROM, i.e. instruction decoder ROM.
69
//
70
///////////////////////////////////////////////////////////////////////////////
71
 
72
module tb_M65C02_ALU;
73
 
74
///////////////////////////////////////////////////////////////////////////////
75
 
76
localparam pNOP  = 0;       // No Operation
77
 
78
//  Logic Unit
79
localparam pALU_NOP = 0;    // NOP - No Operation: ALU <= {OSel: 0,A,X,Y,P,S,M}
80
localparam pALU_AND = 1;    // AND - bitwise AND Accumulator with Memory
81
localparam pALU_ORA = 2;    // ORA - bitwise OR Accumulator with Memory
82
localparam pALU_EOR = 3;    // EOR - bitwise XOR Accumulator with Memory
83
//  Arithmetic Unit
84
localparam pALU_ADC = 4;    // ADC - Add Memory to Accumulator plus Carry
85
localparam pALU_SBC = 5;    // SBC - Sub Memory from Accumulator plus Carry
86
localparam pALU_INC = 6;    // INC - Increment {A, X, Y, or M}
87
localparam pALU_DEC = 7;    // DEC - Decrement {A, X, Y, or M}
88
//  Shift Unit
89
localparam pALU_ASL = 8;    // ASL - Arithmetic Shift Left {A, or M}
90
localparam pALU_LSR = 9;    // LSR - Logical Shift Right {A, or M}
91
localparam pALU_ROL = 10;   // ROL - Rotate Left through Carry {A, or M}
92
localparam pALU_ROR = 11;   // ROR - Rotate Right through Carry {A, or M}
93
//  Bit Unit
94
localparam pALU_BIT = 12;   // BIT - Test Memory with Bit Mask in Accumulator
95
localparam pALU_TRB = 13;   // TRB - Test and Reset Memory with Bit Mask in A
96
localparam pALU_TSB = 14;   // TSB - Test and Set Memory with Bit Mask in A
97
//  Compare Unit
98
localparam pALU_CMP = 15;   // CMP - Compare Register with Memory    
99
 
100
//  QSel = 0; RSel = 0; Sub = 0; CSel = 0; 
101
 
102
localparam pQS_A = 0;   // Select Accumulator
103
localparam pQS_M = 1;   // Select Memory Operand
104
localparam pQS_X = 2;   // Select X Index
105
localparam pQS_Y = 3;   // Select Y Index
106
 
107
// WSel Register Select Field Codes
108
 
109
localparam pWS_A = 1;   // Select Accumulator
110
localparam pWS_X = 2;   // Select X Index
111
localparam pWS_Y = 3;   // Select Y Index
112
localparam pWS_Z = 4;   // Select Zero
113
localparam pWS_S = 5;   // Select Stack Pointer
114
localparam pWS_P = 6;   // Select PSW
115
localparam pWS_M = 7;   // Select Memory Operand 
116
 
117
localparam pOS_A = 1;   // Output Accumulator
118
localparam pOS_X = 2;   // Output X Index
119
localparam pOS_Y = 3;   // Output Y Index
120
localparam pOS_Z = 4;   // Output Zero
121
localparam pOS_S = 5;   // Output Stack Pointer
122
localparam pOS_P = 6;   // Output PSW
123
localparam pOS_M = 7;   // Output Memory Operand 
124
 
125
//  Condition Code Select
126
 
127
localparam pCC   = 8;       // Carry Clear
128
localparam pCS   = 9;       // Carry Set
129
localparam pNE   = 10;      // Not Equal to Zero
130
localparam pEQ   = 11;      // Equal to Zero
131
localparam pVC   = 12;      // Overflow Clear
132
localparam pVS   = 13;      // Overflow Set
133
localparam pPL   = 14;      // Plus (Not Negative)
134
localparam pMI   = 15;      // Negative
135
localparam pCLC  = 16;      // Clear C
136
localparam pSEC  = 17;      // Set Carry
137
localparam pCLI  = 18;      // Clear Interrupt mask
138
localparam pSEI  = 19;      // Set Interrupt mask
139
localparam pCLD  = 20;      // Clear Decimal mode
140
localparam pSED  = 21;      // Set Decimal mode
141
localparam pCLV  = 22;      // Clear Overflow
142
localparam pBRK  = 23;      // Set BRK flag
143
localparam pZ    = 24;      // Set Z = ~|(A & M)
144
localparam pNZ   = 25;      // Set N and Z flags from ALU
145
localparam pNZC  = 26;      // Set N, Z, and C flags from ALU
146
localparam pNVZ  = 27;      // Set N and V flags from M[7:6], and Z = ~|(A & M)
147
localparam pNVZC = 28;      // Set N, V, Z, and C from ALU
148
localparam pPSW  = 31;      // Load PSW from Memory
149
 
150
//  PSW Bit Masks
151
 
152
localparam pPSW_C = 1;
153
localparam pPSW_Z = 2;
154
localparam pPSW_I = 4;
155
localparam pPSW_D = 8;
156
localparam pPSW_B = 16;
157
localparam pPSW_M = 32;
158
localparam pPSW_V = 64;
159
localparam pPSW_N = 128;
160
 
161
localparam pPSW_NZ   = (pPSW_N | pPSW_Z);
162
localparam pPSW_NZC  = (pPSW_N | pPSW_Z | pPSW_C);
163
localparam pPSW_NVZ  = (pPSW_N | pPSW_V | pPSW_Z);
164
localparam pPSW_NVZC = (pPSW_N | pPSW_V | pPSW_Z | pPSW_C);
165
 
166
///////////////////////////////////////////////////////////////////////////////
167
 
168
reg  Rst;
169
reg  Clk;
170
// Internal Ready
171
reg  Rdy;           // Operand Ready
172
// Execution Control
173
reg  En;            // ALU Operation Enable
174
reg  [2:0] Reg_WE;  // ALU Register Write Enable
175
reg  ISR;           // Interrup Service Routine Flag
176
// ALU
177
reg  [3:0] Op;      // ALU Function Select
178
reg  [1:0] QSel;    // ALU Q Bus Select
179
reg  RSel;          // ALU R Bus Select
180
reg  Sub;           // ALU AU Operation
181
reg  CSel;          // ALU AU Carry In Select
182
reg  [2:0] WSel;    // Register Write Select
183
reg  [2:0] OSel;    // ALU Output Select
184
reg  [4:0] CCSel;   // Condition Code Select
185
reg  [7:0] M;       // Memory Operand - OP1
186
wire [7:0] DO;      // ALU/Core Data Output Bus
187
wire Valid;
188
// Condition Code
189
wire CC_Out;
190
// Stack
191
reg  [1:0] StkOp;
192
wire [7:0] StkPtr;
193
// Internal Processor Registers
194
wire [7:0] A;
195
wire [7:0] X;
196
wire [7:0] Y;
197
wire [7:0] S;
198
// Processor Status Word
199
wire [7:0] P;
200
 
201
// Instantiate the Unit Under Test (UUT)
202
 
203
M65C02_ALU  uut (
204
                .Rst(Rst),
205
                .Clk(Clk),
206
 
207
                .Rdy(Rdy),
208
 
209
                .En(En),
210
                .Reg_WE(Reg_WE),
211
                .ISR(ISR),
212
 
213
                .Op(Op),
214
                .QSel(QSel),
215
                .RSel(RSel),
216
                .Sub(Sub),
217
                .CSel(CSel),
218
                .WSel(WSel),
219
                .OSel(OSel),
220
                .CCSel(CCSel),
221
                .Msk(Msk),
222
 
223
                .M(M),
224
                .Out(DO),
225
                .Valid(Valid),
226
 
227
                .CC_Out(CC_Out),
228
 
229
                .StkOp(StkOp),
230
                .StkPtr(StkPtr),
231
 
232
                .A(A),
233
                .X(X),
234
                .Y(Y),
235
                .S(S),
236
 
237
                .P(P)
238
            );
239
 
240
///////////////////////////////////////////////////////////////////////////////
241
 
242
initial begin
243
    // Initialize Inputs
244
    Rst    = 1;
245
    Clk    = 1;
246
    Rdy    = 1;
247
    En     = 0;
248
    Reg_WE = 0;
249
    ISR    = 0;
250
    Op     = 0;
251
    QSel   = 0;
252
    RSel   = 0;
253
    Sub    = 0;
254
    CSel   = 0;
255
    WSel   = 0;
256
    OSel   = 0;
257
    CCSel  = 0;
258
    M      = 0;
259
    StkOp  = 0;
260
 
261
    // Wait 100 ns for global reset to finish
262
    #101 Rst = 0;
263
    Op = pNOP;  QSel = pQS_M; RSel = pNOP; Sub = pNOP; CSel = pNOP;
264
    WSel = pWS_A; OSel = pOS_M;
265
    CCSel = pNZ;
266
    M = 255;
267
    @(posedge Clk) #1;
268
 
269
///////////////////////////////////////////////////////////////////////////////
270
///////////////////////////////////////////////////////////////////////////////
271
 
272
    if((A==0) && (X==0) && (Y==0) && (S==0) && (P==(pPSW_M | pPSW_I)))
273
        $display("Reset Initialization Complete: Registers Initialized");
274
    else begin
275
        $display("Reset Initialization Complete: Registers Not Initialized");
276
        $stop;
277
    end
278
 
279
///////////////////////////////////////////////////////////////////////////////
280
///////////////////////////////////////////////////////////////////////////////
281
 
282
    // Initial Check - Load Registers: A, X, Y, S, P
283
 
284
    $display("Start - Register Load Tests");
285
 
286
    // LDA #255, PLA
287
    En = 1; Reg_WE = 4; ISR = 0;
288
    Op = pNOP;  QSel = pQS_M; RSel = pNOP; Sub = pNOP; CSel = pNOP;
289
    WSel = pWS_A; OSel = pOS_M;
290
    CCSel = pNZ;
291
    M = 255;
292
    @(posedge Clk) #1.1;
293
    if((A!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
294
        $display("Error: A Register Load Test Failed");
295
        $stop;
296
    end
297
 
298
    // LDX #255, PLX
299
    En = 1; Reg_WE = 4; ISR = 0;
300
    Op = pNOP;  QSel = pQS_M; RSel = pNOP; Sub = pNOP; CSel = pNOP;
301
    WSel = pWS_X; OSel = pOS_M;
302
    CCSel = pNZ;
303
    M = 255;
304
    @(posedge Clk) #1.1;
305
    if((X!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
306
        $display("Error: X Register Load Test Failed");
307
        $stop;
308
    end
309
 
310
    // LDY #255, PLY
311
    En = 1; Reg_WE = 4; ISR = 0;
312
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
313
    WSel = pWS_Y; OSel = pOS_M;
314
    CCSel = pNZ;
315
    M = 255;
316
    @(posedge Clk) #1.1;
317
    if((Y!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
318
        $display("Error: Y Register Load Test Failed");
319
        $stop;
320
    end
321
 
322
    // TXS
323
    En = 1; Reg_WE = 4; ISR = 0;
324
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
325
    WSel = pWS_S; OSel = pOS_X;
326
    CCSel = pNOP;
327
    M = 0;
328
    @(posedge Clk) #1.1;
329
    if(S!=255) begin
330
        $display("Error: S Register Load Test Failed");
331
        $stop;
332
    end
333
 
334
    // LDA #1
335
    En = 1; Reg_WE = 4; ISR = 0;
336
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
337
    WSel = pWS_A; OSel = pOS_M;
338
    CCSel = pNZ;
339
    M = 1;
340
    @(posedge Clk) #1.1;
341
    if((A!=1) || ((P&(pPSW_NZ))!=(0))) begin
342
        $display("Error: A Register Load Test Failed");
343
        $stop;
344
    end
345
 
346
    // TAX
347
    En = 1; Reg_WE = 4; ISR = 0;
348
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
349
    WSel = pWS_X; OSel = pOS_A;
350
    CCSel = pNZ;
351
    M = 0;
352
    @(posedge Clk) #1.1;
353
    if((X!=1) || ((P&(pPSW_NZ))!=(0))) begin
354
        $display("Error: TAX Test Failed");
355
        $stop;
356
    end
357
 
358
    // LDA #2
359
    En = 1; Reg_WE = 4; ISR = 0;
360
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
361
    WSel = pWS_A; OSel = pOS_M;
362
    CCSel = pNZ;
363
    M = 2;
364
    @(posedge Clk) #1.1;
365
    if((A!=1) && ((P&(pPSW_NZ))!=(0))) begin
366
        $display("Error: A Register Load Test Failed");
367
        $stop;
368
    end
369
 
370
    // TAY
371
    En = 1; Reg_WE = 4; ISR = 0;
372
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
373
    WSel = pWS_Y; OSel = pOS_A;
374
    CCSel = pNZ;
375
    M = 0;
376
    @(posedge Clk) #1.1;
377
    if((Y!=2) || ((P&(pPSW_NZ))!=(0))) begin
378
        $display("Error: TAY Test Failed");
379
        $stop;
380
    end
381
 
382
    // LDA #255
383
    En = 1; Reg_WE = 4; ISR = 0;
384
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
385
    WSel = pWS_A; OSel = pOS_M;
386
    CCSel = pNZ;
387
    M = 255;
388
    @(posedge Clk) #1.1;
389
    if((A!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
390
        $display("Error: A Register Load Test Failed");
391
        $stop;
392
    end
393
 
394
    // TYA
395
    En = 1; Reg_WE = 4; ISR = 0;
396
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
397
    WSel = pWS_A; OSel = pOS_Y;
398
    CCSel = pNZ;
399
    M = 0;
400
    @(posedge Clk) #1.1;
401
    if((A!=2) || ((P&(pPSW_NZ))!=(0))) begin
402
        $display("Error: TYA Test Failed");
403
        $stop;
404
    end
405
 
406
    // TSX
407
    En = 1; Reg_WE = 4; ISR = 0;
408
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
409
    WSel = pWS_X; OSel = pOS_S;
410
    CCSel = pNZ;
411
    M = 0;
412
    @(posedge Clk) #1.1;
413
    if((X!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
414
        $display("Error: TSX Test Failed");
415
        $stop;
416
    end
417
 
418
    // TYA
419
    En = 1; Reg_WE = 4; ISR = 0;
420
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
421
    WSel = pWS_A; OSel = pOS_Y;
422
    CCSel = pNZ;
423
    M = 0;
424
    @(posedge Clk) #1.1;
425
    if((A!=2) || ((P&(pPSW_NZ))!=(0))) begin
426
        $display("Error: TYA Test Failed");
427
        $stop;
428
    end
429
 
430
    // TXA
431
    En = 1; Reg_WE = 4; ISR = 0;
432
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
433
    WSel = pWS_A; OSel = pOS_X;
434
    CCSel = pNZ;
435
    M = 0;
436
    @(posedge Clk) #1.1;
437
    if((A!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
438
        $display("Error: TXA Test Failed");
439
        $stop;
440
    end
441
 
442
    // TAY
443
    En = 1; Reg_WE = 4; ISR = 0;
444
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
445
    WSel = pWS_Y; OSel = pOS_A;
446
    CCSel = pNZ;
447
    M = 0;
448
    @(posedge Clk) #1.1;
449
    if((Y!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
450
        $display("Error: TAY Test Failed");
451
        $stop;
452
    end
453
 
454
    // PLP
455
    En = 1; Reg_WE = 4; ISR = 0;
456
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
457
    WSel = pWS_P; OSel = pOS_M;
458
    CCSel = pPSW;
459
    M = 0;
460
    @(posedge Clk) #1.1;
461
    if(P!=pPSW_M) begin
462
        $display("Error: P Register Load Test Failed");
463
        $stop;
464
    end
465
 
466
    // STZ
467
    En = 0;
468
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
469
    WSel = pNOP; OSel = pOS_Z;
470
    CCSel = pNOP;
471
    M = 255;
472
    @(posedge Clk) #1 En = 0;
473
    if(DO!=0) begin
474
        $display("Error: STZ Test Failed");
475
        $stop;
476
    end
477
 
478
    if((A==255)&&(X==255)&&(Y==255)&&(S==255)&&(P&pPSW_M)&&(DO==0)&&(M==255))
479
        $display("End - Register Load Tests: Pass");
480
    else
481
        $display("End - Register Load Tests: Error");
482
 
483
    // End of Test
484
 
485
    En = 0;
486
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
487
    WSel = pNOP; OSel = pOS_M;
488
    CCSel = pNOP;
489
    M = 255;
490
    @(posedge Clk) #1;
491
 
492
//    $stop;
493
 
494
///////////////////////////////////////////////////////////////////////////////
495
///////////////////////////////////////////////////////////////////////////////
496
 
497
    // Test Logic Unit
498
 
499
    $display("Start - Logic Unit Tests");
500
 
501
    // LDA #55
502
    En = 1; Reg_WE = 4; ISR = 0;
503
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
504
    WSel = pWS_A; OSel = pOS_M;
505
    CCSel = pNZ;
506
    M = 85;
507
    @(posedge Clk) #1.1;
508
    if((A!=85) || ((P&(pPSW_NZ))!=(0))) begin
509
        $display("Error: A Register Load Test Failed");
510
        $stop;
511
    end
512
 
513
    // ORA #AA
514
    En = 1; Reg_WE = 4; ISR = 0;
515
    Op = pALU_ORA; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
516
    WSel = pWS_A; OSel = pNOP;
517
    CCSel = pNZ;
518
    M = 170;
519
    @(posedge Clk) #1.1;
520
    if((A!=255) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
521
        $display("Error: ORA Test Failed");
522
        $stop;
523
    end
524
 
525
    // EOR #AA
526
    En = 1; Reg_WE = 4; ISR = 0;
527
    Op = pALU_EOR; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
528
    WSel = pWS_A; OSel = pNOP;
529
    CCSel = pNZ;
530
    M = 170;
531
    @(posedge Clk) #1.1;
532
    if((A!=85) || ((P&(pPSW_NZ))!=(0))) begin
533
        $display("Error: EOR Test Failed");
534
        $stop;
535
    end
536
 
537
    // AND #AA
538
    En = 1; Reg_WE = 4; ISR = 0;
539
    Op = pALU_AND; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
540
    WSel = pWS_A; OSel = pNOP;
541
    CCSel = pNZ;
542
    M = 170;
543
    @(posedge Clk) #1.01 En = 0;
544
    if((A!=0) || ((P&(pPSW_NZ))!=(pPSW_Z))) begin
545
        $display("Error: AND Test Failed");
546
        $stop;
547
    end
548
 
549
    // End of Test
550
 
551
    En = 0;
552
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
553
    WSel = pNOP; OSel = pOS_M;
554
    CCSel = pNOP;
555
    M = 255;
556
    @(posedge Clk) #1;
557
 
558
    $display("End - Logic Unit Test: Pass");
559
//    $stop;
560
 
561
///////////////////////////////////////////////////////////////////////////////
562
///////////////////////////////////////////////////////////////////////////////
563
 
564
    // Start Arithmetic Unit Test
565
 
566
    $display("Start Arithmetic Unit Tests");
567
 
568
    // LDA #128
569
    En = 1; Reg_WE = 4; ISR = 0;
570
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
571
    WSel = pWS_A; OSel = pOS_M;
572
    CCSel = pNZ;
573
    M = 128;
574
    @(posedge Clk) #1.1;
575
    if((A!=128) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
576
        $display("Error: A Register Load Test Failed");
577
        $stop;
578
    end
579
 
580
    // ADC #127
581
    En = 1; Reg_WE = 4; ISR = 0;
582
    Op = pALU_ADC; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
583
    WSel = pWS_A; OSel = pNOP;
584
    CCSel = pNVZC;
585
    M = 127;
586
    @(posedge Clk) #1.1;
587
    if((A!=255) || ((P&(pPSW_NVZC))!=(pPSW_N))) begin
588
        $display("Error: ADC Test #1 Failed");
589
        $stop;
590
    end
591
 
592
    // ADC #1
593
    En = 1; Reg_WE = 4; ISR = 0;
594
    Op = pALU_ADC; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
595
    WSel = pWS_A; OSel = pNOP;
596
    CCSel = pNVZC;
597
    M = 1;
598
    @(posedge Clk) #1.1;
599
    if((A!=0) || ((P&(pPSW_NVZC))!=(pPSW_Z | pPSW_C))) begin
600
        $display("Error: ADC Test #2 Failed");
601
        $stop;
602
    end
603
 
604
    // ADC #127, since CS, effectively a +128, which results in MI, VS, NE, CC
605
    En = 1; Reg_WE = 4; ISR = 0;
606
    Op = pALU_ADC; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
607
    WSel = pWS_A; OSel = pNOP;
608
    CCSel = pNVZC;
609
    M = 127;
610
    @(posedge Clk) #1.1;
611
    if((A!=128) || ((P&(pPSW_NVZC))!=(pPSW_N | pPSW_V))) begin
612
        $display("Error: ADC Test #3 Failed");
613
        $stop;
614
    end
615
 
616
    // ADC #255, M = -1, which results in PL, VS, NE, CS
617
    En = 1; Reg_WE = 4; ISR = 0;
618
    Op = pALU_ADC; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
619
    WSel = pWS_A; OSel = pNOP;
620
    CCSel = pNVZC;
621
    M = 255;
622
    @(posedge Clk) #1.1;
623
    if((A!=127) || ((P&(pPSW_NVZC))!=(pPSW_V | pPSW_C))) begin
624
        $display("Error: ADC Test #4 Failed");
625
        $stop;
626
    end
627
 
628
    //  A = 127, P = VC;
629
 
630
    // SBC #1, since CS, M = -1, which results in PL, VC, NE, CS
631
    En = 1; Reg_WE = 4; ISR = 0;
632
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
633
    WSel = pWS_A; OSel = pNOP;
634
    CCSel = pNVZC;
635
    M = 1;
636
    @(posedge Clk) #1.1;
637
    if((A!=126) || ((P&(pPSW_NVZC))!=(pPSW_C))) begin
638
        $display("Error: SBC Test #1 Failed");
639
        $stop;
640
    end
641
 
642
    // SBC #126, since CS, M = -126, which results in PL, VC, EQ, CS
643
    En = 1; Reg_WE = 4; ISR = 0;
644
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
645
    WSel = pWS_A; OSel = pNOP;
646
    CCSel = pNVZC;
647
    M = 126;
648
    @(posedge Clk) #1.1;
649
    if((A!=0) || ((P&(pPSW_NVZC))!=(pPSW_Z | pPSW_C))) begin
650
        $display("Error: SBC Test #2 Failed");
651
        $stop;
652
    end
653
 
654
    // SBC #128, since CS, M = -128, which results in MI, VS, NE, CC
655
    En = 1; Reg_WE = 4; ISR = 0;
656
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
657
    WSel = pWS_A; OSel = pNOP;
658
    CCSel = pNVZC;
659
    M = 128;
660
    @(posedge Clk) #1.1;
661
    if((A!=128) || ((P&(pPSW_NVZC))!=(pPSW_N | pPSW_V))) begin
662
        $display("Error: SBC Test #3 Failed");
663
        $stop;
664
    end
665
 
666
    // SBC #0, since CC, M = -1, which results in PL, VS, NE, CS
667
    En = 1; Reg_WE = 4; ISR = 0;
668
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
669
    WSel = pWS_A; OSel = pNOP;
670
    CCSel = pNVZC;
671
    M = 0;
672
    @(posedge Clk) #1.1;
673
    if((A!=127) || ((P&(pPSW_NVZC))!=(pPSW_V | pPSW_C))) begin
674
        $display("Error: SBC Test #4 Failed");
675
        $stop;
676
    end
677
 
678
    // SBC #127, since CS, M = -127, which results in PL, VC, EQ, CS
679
    En = 1; Reg_WE = 4; ISR = 0;
680
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
681
    WSel = pWS_A; OSel = pNOP;
682
    CCSel = pNVZC;
683
    M = 127;
684
    @(posedge Clk) #1.1;
685
    if((A!=0) || ((P&(pPSW_NVZC))!=(pPSW_Z | pPSW_C))) begin
686
        $display("Error: SBC Test #5 Failed");
687
        $stop;
688
    end
689
 
690
    // SBC #1, since CS, M = -1, which results in MI, VC, NE, CC
691
    En = 1; Reg_WE = 4; ISR = 0;
692
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
693
    WSel = pWS_A; OSel = pNOP;
694
    CCSel = pNVZC;
695
    M = 1;
696
    @(posedge Clk) #1.1;
697
    if((A!=255) || ((P&(pPSW_NVZC))!=(pPSW_N))) begin
698
        $display("Error: SBC Test #5 Failed");
699
        $stop;
700
    end
701
 
702
    // SBC #0, since CC, M = -1, which results in MI, VC, NE, CS
703
    En = 1; Reg_WE = 4; ISR = 0;
704
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
705
    WSel = pWS_A; OSel = pNOP;
706
    CCSel = pNVZC;
707
    M = 0;
708
    @(posedge Clk) #1.1;
709
    if((A!=254) || ((P&(pPSW_NVZC))!=(pPSW_N | pPSW_C))) begin
710
        $display("Error: SBC Test #6 Failed");
711
        $stop;
712
    end
713
 
714
    // SBC #126, since CS, M = -126, which results in MI, VC, NE, CS
715
    En = 1; Reg_WE = 4; ISR = 0;
716
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
717
    WSel = pWS_A; OSel = pNOP;
718
    CCSel = pNVZC;
719
    M = 126;
720
    @(posedge Clk) #1.1;
721
    if((A!=128) || ((P&(pPSW_NVZC))!=(pPSW_N | pPSW_C))) begin
722
        $display("Error: SBC Test #7 Failed");
723
        $stop;
724
    end
725
 
726
    // SBC #128, since CS, M = -128, which results in PL, VS, EQ, CS
727
    En = 1; Reg_WE = 4; ISR = 0;
728
    Op = pALU_SBC; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 0;
729
    WSel = pWS_A; OSel = pNOP;
730
    CCSel = pNVZC;
731
    M = 128;
732
    @(posedge Clk) #1.1;
733
    if((A!=0) || ((P&(pPSW_NVZC))!=(pPSW_Z | pPSW_C))) begin
734
        $display("Error: SBC Test #7 Failed");
735
        $stop;
736
    end
737
 
738
    // TAX
739
    En = 1; Reg_WE = 4; ISR = 0;
740
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
741
    WSel = pWS_X; OSel = pOS_A;
742
    CCSel = pNZ;
743
    M = 0;
744
    @(posedge Clk) #1.1;
745
    if((X!=0) || ((P&(pPSW_NZ))!=(pPSW_Z))) begin
746
        $display("Error: CLR X Failed");
747
        $stop;
748
    end
749
 
750
    // TAY
751
    En = 1; Reg_WE = 4; ISR = 0;
752
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
753
    WSel = pWS_Y; OSel = pOS_A;
754
    CCSel = pNZ;
755
    M = 0;
756
    @(posedge Clk) #1.1;
757
    if((Y!=0) || ((P&(pPSW_NZ))!=(pPSW_Z))) begin
758
        $display("Error: CLR Y Failed");
759
        $stop;
760
    end
761
 
762
    // DEC A, since A == 0, A <= -1, and MI, VC, NE, CC
763
    En = 1; Reg_WE = 4; ISR = 0;
764
    Op = pALU_DEC; QSel = pQS_A; RSel = 1; Sub = 1; CSel = 1;
765
    WSel = pWS_A; OSel = pNOP;
766
    CCSel = pNZC;
767
    M = 0;
768
    @(posedge Clk) #1.1;
769
    if((A!=255) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
770
        $display("Error: DEC A Test #1 Failed");
771
        $stop;
772
    end
773
 
774
    // INC A, since A == -1, A <= 0, and PL, VC, EQ, CS
775
    En = 1; Reg_WE = 4; ISR = 0;
776
    Op = pALU_INC; QSel = pQS_A; RSel = 1; Sub = 0; CSel = 1;
777
    WSel = pWS_A; OSel = pNOP;
778
    CCSel = pNZC;
779
    M = 0;
780
    @(posedge Clk) #1.1;
781
    if((A!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
782
        $display("Error: INC A Test #1 Failed");
783
        $stop;
784
    end
785
 
786
    // DEX, since X == 0, X <= -1, and MI, VC, NE, CC
787
    En = 1; Reg_WE = 4; ISR = 0;
788
    Op = pALU_DEC; QSel = pQS_X; RSel = 1; Sub = 1; CSel = 1;
789
    WSel = pWS_X; OSel = pNOP;
790
    CCSel = pNZC;
791
    M = 0;
792
    @(posedge Clk) #1.1;
793
    if((X!=255) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
794
        $display("Error: DEX Test #1 Failed");
795
        $stop;
796
    end
797
 
798
    // INX since X == -1, X <= 0, and PL, VC, EQ, CS
799
    En = 1; Reg_WE = 4; ISR = 0;
800
    Op = pALU_INC; QSel = pQS_X; RSel = 1; Sub = 0; CSel = 1;
801
    WSel = pWS_X; OSel = pNOP;
802
    CCSel = pNZC;
803
    M = 0;
804
    @(posedge Clk) #1.1;
805
   if((X!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
806
        $display("Error: INX Test #1 Failed");
807
        $stop;
808
    end
809
 
810
    // DEY, since Y == 0, Y <= -1, and MI, VC, NE, CC
811
    En = 1; Reg_WE = 4; ISR = 0;
812
    Op = pALU_DEC; QSel = pQS_Y; RSel = 1; Sub = 1; CSel = 1;
813
    WSel = pWS_Y; OSel = pNOP;
814
    CCSel = pNZC;
815
    M = 0;
816
    @(posedge Clk) #1.1;
817
    if((Y!=255) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
818
        $display("Error: DEY Test #1 Failed");
819
        $stop;
820
    end
821
 
822
    // INY since Y == -1, Y <= 0, and PL, VC, EQ, CS
823
    En = 1; Reg_WE = 4; ISR = 0;
824
    Op = pALU_INC; QSel = pQS_Y; RSel = 1; Sub = 0; CSel = 1;
825
    WSel = pWS_Y; OSel = pNOP;
826
    CCSel = pNZC;
827
    M = 0;
828
    @(posedge Clk) #1.1;
829
    if((A!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
830
        $display("Error: INY Test #1 Failed");
831
        $stop;
832
    end
833
 
834
    // DEC M, since M == 0, M <= -1, and MI, VC, NE, CC
835
    En = 1; Reg_WE = 4; ISR = 0;
836
    Op = pALU_DEC;  QSel = pQS_M; RSel = 1; Sub = 1; CSel = 1;
837
    WSel = pWS_M; OSel = pNOP;
838
    CCSel = pNZC;
839
    M = 0;
840
    @(posedge Clk) #1.1;
841
    if((DO!=255) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
842
        $display("Error: DEC M Test Failed");
843
        $stop;
844
    end
845
 
846
    // INC M, since M == -1, M <= 0, and PL, VC, EQ, CS
847
    En = 1; Reg_WE = 4; ISR = 0;
848
    Op = pALU_INC;  QSel = pQS_M; RSel = 1; Sub = 0; CSel = 1;
849
    WSel = pWS_M; OSel = pNOP;
850
    CCSel = pNZC;
851
    M = 255;
852
    @(posedge Clk) #1.1;
853
    if((DO!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
854
        $display("Error: INC M Test Failed");
855
        $stop;
856
    end
857
 
858
    // CMP #1 DO <= 255, and MI, VC, NE, CC
859
    En = 1; Reg_WE = 4; ISR = 0;
860
    Op = pALU_CMP; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 1;
861
    WSel = pWS_M; OSel = pNOP;
862
    CCSel = pNZC;
863
    M = 1;
864
    @(posedge Clk) #1.1;
865
    if((DO!=255) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
866
        $display("Error: CMP #1 Test Failed");
867
        $stop;
868
    end
869
 
870
    // CMP #0, DO <= 0, and MI, VC, NE, CS
871
    En = 1; Reg_WE = 4; ISR = 0;
872
    Op = pALU_CMP; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 1;
873
    WSel = pWS_M; OSel = pNOP;
874
    CCSel = pNZC;
875
    M = 0;
876
    @(posedge Clk) #1.1;
877
    if((DO!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
878
        $display("Error: CMP #0 Test Failed");
879
        $stop;
880
    end
881
 
882
    // CMP #-1, DO <= 1, and PL, VC, NE, CC
883
    En = 1; Reg_WE = 4; ISR = 0;
884
    Op = pALU_CMP; QSel = pQS_A; RSel = 0; Sub = 1; CSel = 1;
885
    WSel = pWS_M; OSel = pNOP;
886
    CCSel = pNZC;
887
    M = 255;
888
    @(posedge Clk) #1.1;
889
    if((DO!=1) || ((P&(pPSW_NZC))!=(0))) begin
890
        $display("Error: CMP #-1 Test Failed");
891
        $stop;
892
    end
893
 
894
    // CPX #2 DO <= -2, and MI, VC, NE, CC
895
    En = 1; Reg_WE = 4; ISR = 0;
896
    Op = pALU_CMP; QSel = pQS_X; RSel = 0; Sub = 1; CSel = 1;
897
    WSel = pWS_M; OSel = pNOP;
898
    CCSel = pNZC;
899
    M = 2;
900
    @(posedge Clk) #1.1;
901
    if((DO!=254) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
902
        $display("Error: CPX #2 Test Failed");
903
        $stop;
904
    end
905
 
906
    // CPX #0, DO <= 0, and MI, VC, NE, CS
907
    En = 1; Reg_WE = 4; ISR = 0;
908
    Op = pALU_CMP; QSel = pQS_X; RSel = 0; Sub = 1; CSel = 1;
909
    WSel = pWS_M; OSel = pNOP;
910
    CCSel = pNZC;
911
    M = 0;
912
    @(posedge Clk) #1.1;
913
    if((DO!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
914
        $display("Error: CPX #0 Test Failed");
915
        $stop;
916
    end
917
 
918
    // CPX #-2, DO <= 2, and PL, VC, NE, CC
919
    En = 1; Reg_WE = 4; ISR = 0;
920
    Op = pALU_CMP; QSel = pQS_Y; RSel = 0; Sub = 1; CSel = 1;
921
    WSel = pWS_M; OSel = pNOP;
922
    CCSel = pNZC;
923
    M = 254;
924
    @(posedge Clk) #1.1;
925
    if((DO!=2) || ((P&(pPSW_NZC))!=(0))) begin
926
        $display("Error: CPX #-2 Test Failed");
927
        $stop;
928
    end
929
 
930
    // CPY #3 DO <= 255, and MI, VC, NE, CC
931
    En = 1; Reg_WE = 4; ISR = 0;
932
    Op = pALU_CMP; QSel = pQS_Y; RSel = 0; Sub = 1; CSel = 1;
933
    WSel = pWS_M; OSel = pNOP;
934
    CCSel = pNZC;
935
    M = 3;
936
    @(posedge Clk) #1.1;
937
    if((DO!=253) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
938
        $display("Error: CPY #3 Test Failed");
939
        $stop;
940
    end
941
 
942
    // CPY #0, DO <= 0, and MI, VC, NE, CS
943
    En = 1; Reg_WE = 4; ISR = 0;
944
    Op = pALU_CMP; QSel = pQS_Y; RSel = 0; Sub = 1; CSel = 1;
945
    WSel = pWS_M; OSel = pNOP;
946
    CCSel = pNZC;
947
    M = 0;
948
    @(posedge Clk) #1.1;
949
    if((DO!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
950
        $display("Error: CPY #0 Test Failed");
951
        $stop;
952
    end
953
 
954
    // CPY #-3, DO <= 1, and PL, VC, NE, CC
955
    En = 1; Reg_WE = 4; ISR = 0;
956
    Op = pALU_CMP; QSel = pQS_Y; RSel = 0; Sub = 1; CSel = 1;
957
    WSel = pWS_M; OSel = pNOP;
958
    CCSel = pNZC; M = 253;
959
    @(posedge Clk) #1.1;
960
    if((DO!=3) || ((P&(pPSW_NZC))!=(0))) begin
961
        $display("Error: CPY #-3 Test Failed");
962
        $stop;
963
    end
964
 
965
    // End of Test
966
 
967
    En = 0;
968
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
969
    WSel = pNOP; OSel = pOS_M;
970
    CCSel = pNOP;
971
    M = 255;
972
    @(posedge Clk) #1;
973
 
974
    $display("End - Arithmetic Unit Test: Pass");
975
//    $stop;
976
 
977
///////////////////////////////////////////////////////////////////////////////
978
///////////////////////////////////////////////////////////////////////////////
979
 
980
    // Shift Unit Tests
981
 
982
    $display("Start - Shift Unit Tests");
983
 
984
    // LDA #128
985
    En = 1; Reg_WE = 4; ISR = 0;
986
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
987
    WSel = pWS_A; OSel = pOS_M;
988
    CCSel = pNZ;
989
    M = 128;
990
    @(posedge Clk) #1.1;
991
    if((A!=128) || ((P&(pPSW_NZ))!=(pPSW_N))) begin
992
        $display("Error: A Register Load Test Failed");
993
        $stop;
994
    end
995
 
996
    // ASL A
997
    En = 1; Reg_WE = 4; ISR = 0;
998
    Op = pALU_ASL; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
999
    WSel = pWS_A; OSel = pNOP;
1000
    CCSel = pNZC;
1001
    M = 0;
1002
    @(posedge Clk) #1.1;
1003
    if((A!=0) || ((P&(pPSW_NZC))!=(pPSW_Z | pPSW_C))) begin
1004
        $display("Error: ASL A Test Failed");
1005
        $stop;
1006
    end
1007
 
1008
    // ASL M
1009
    En = 1; Reg_WE = 4; ISR = 0;
1010
    Op = pALU_ASL; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1011
    WSel = pWS_M; OSel = pNOP;
1012
    CCSel = pNZC;
1013
    M = 85;
1014
    @(posedge Clk) #1.1;
1015
    if((DO!=170) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
1016
        $display("Error: ASL M Test Failed");
1017
        $stop;
1018
    end
1019
 
1020
    // LDA #85
1021
    En = 1; Reg_WE = 4; ISR = 0;
1022
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1023
    WSel = pWS_A; OSel = pOS_M;
1024
    CCSel = pNZ;
1025
    M = 85;
1026
    @(posedge Clk) #1.1;
1027
    if((A!=85) || ((P&(pPSW_NZ))!=(0))) begin
1028
        $display("Error: A Register Load Test Failed");
1029
        $stop;
1030
    end
1031
 
1032
    // LSR A
1033
    En = 1; Reg_WE = 4; ISR = 0;
1034
    Op = pALU_LSR; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
1035
    WSel = pWS_A; OSel = pNOP;
1036
    CCSel = pNZC;
1037
    M = 0;
1038
    @(posedge Clk) #1.1;
1039
    if((A!=42) || ((P&(pPSW_NZC))!=(pPSW_C))) begin
1040
        $display("Error: LSR A Test Failed");
1041
        $stop;
1042
    end
1043
 
1044
    // LSR M
1045
    En = 1; Reg_WE = 4; ISR = 0;
1046
    Op = pALU_LSR; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1047
    WSel = pWS_M; OSel = pNOP;
1048
    CCSel = pNZC;
1049
    M = 170;
1050
    @(posedge Clk) #1.1;
1051
    if((DO!=85) || ((P&(pPSW_NZC))!=(0))) begin
1052
        $display("Error: LSR M Test Failed");
1053
        $stop;
1054
    end
1055
 
1056
    // ROL A
1057
    En = 1; Reg_WE = 4; ISR = 0;
1058
    Op = pALU_ROL; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
1059
    WSel = pWS_A; OSel = pNOP;
1060
    CCSel = pNZC;
1061
    M = 0;
1062
    @(posedge Clk) #1.1;
1063
    if((A!=84) || ((P&(pPSW_NZC))!=(0))) begin
1064
        $display("Error: ROL A Test Failed");
1065
        $stop;
1066
    end
1067
 
1068
    // ROL M -- Asynchronous implementation mixing back into the output the C
1069
    //          at the lsb, but doesn't affect the external register or PSW
1070
    En = 1; Reg_WE = 4; ISR = 0;
1071
    Op = pALU_ROL; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1072
    WSel = pWS_M; OSel = pNOP;
1073
    CCSel = pNZC;
1074
    M = 170;
1075
    @(posedge Clk);
1076
    if((DO!=84)) begin
1077
        $display("Error: ROL M Test Failed");
1078
        $stop;
1079
    end
1080
    #1.1;
1081
    if(((P&(pPSW_NZC))!=(pPSW_C))) begin
1082
        $display("Error: ROL M Test Failed");
1083
        $stop;
1084
    end
1085
 
1086
    // ROR A
1087
    En = 1; Reg_WE = 4; ISR = 0;
1088
    Op = pALU_ROR; QSel = pQS_A; RSel = 0; Sub = 0; CSel = 0;
1089
    WSel = pWS_A; OSel = pNOP;
1090
    CCSel = pNZC;
1091
    M = 0;
1092
    @(posedge Clk) #1.1;
1093
    if((A!=170) || ((P&(pPSW_NZC))!=(pPSW_N))) begin
1094
        $display("Error: ROR A Test Failed");
1095
        $stop;
1096
    end
1097
 
1098
    // ROR M -- Asynchronous implementation mixing back into the output the C
1099
    //          at the msb, but doesn't affect the external register or PSW
1100
    En = 1; Reg_WE = 4; ISR = 0;
1101
    Op = pALU_ROR; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1102
    WSel = pWS_M; OSel = pNOP;
1103
    CCSel = pNZC;
1104
    M = 191;
1105
    @(posedge Clk);
1106
    if((DO!=95)) begin
1107
        $display("Error: ROR M Test Failed");
1108
        $stop;
1109
    end
1110
    #1.1;
1111
    if(((P&(pPSW_NZC))!=(pPSW_C))) begin
1112
        $display("Error: ROR M Test Failed");
1113
        $stop;
1114
    end
1115
 
1116
    // End of Test
1117
 
1118
    En = 0;
1119
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1120
    WSel = pNOP; OSel = pOS_M;
1121
    CCSel = pNOP;
1122
    M = 255;
1123
    @(posedge Clk) #1;
1124
 
1125
    $display("End - Shift Unit Tests: Pass");
1126
//    $stop;
1127
 
1128
///////////////////////////////////////////////////////////////////////////////
1129
///////////////////////////////////////////////////////////////////////////////
1130
 
1131
    // Bit Test Unit Tests
1132
 
1133
    $display("Start - Bit Test Unit Tests");
1134
 
1135
    // LDA #63
1136
    En = 1; Reg_WE = 4; ISR = 0;
1137
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1138
    WSel = pWS_A; OSel = pOS_M;
1139
    CCSel = pNZ;
1140
    M = 63;
1141
    @(posedge Clk) #1.1;
1142
    if((A!=63) || ((P&(pPSW_NZ))!=(0))) begin
1143
        $display("Error: A Register Load Test Failed");
1144
        $stop;
1145
    end
1146
 
1147
    // BIT M
1148
    En = 1; Reg_WE = 4; ISR = 0;
1149
    Op = pALU_BIT; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1150
    WSel = pWS_M; OSel = pNOP;
1151
    CCSel = pNVZ;
1152
    M = 192;
1153
    @(posedge Clk);
1154
    if((DO!=0)) begin
1155
        $display("Error: BIT M Test Failed");
1156
        $stop;
1157
    end
1158
    #1.1;
1159
    if(((P&(pPSW_NVZ))!=(pPSW_N | pPSW_V | pPSW_Z))) begin
1160
        $display("Error: BIT M Test Failed");
1161
        $stop;
1162
    end
1163
 
1164
    // BIT #192 -- check that {N,V} are unchanged from previous result
1165
    En = 1; Reg_WE = 4; ISR = 0;
1166
    Op = pALU_BIT; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1167
    WSel = pWS_M; OSel = pNOP;
1168
    CCSel = pZ;
1169
    M = 0;
1170
    @(posedge Clk);
1171
    if((DO!=0)) begin
1172
        $display("Error: BIT #imm Test Failed");
1173
        $stop;
1174
    end
1175
    #1.1;
1176
    if(((P&(pPSW_NVZ))!=(pPSW_N | pPSW_V | pPSW_Z))) begin
1177
        $display("Error: BIT #imm Test Failed");
1178
        $stop;
1179
    end
1180
 
1181
    // TRB #255 -- Z flag test is ~|(A & M) rather that ~|ALU
1182
    En = 1; Reg_WE = 4; ISR = 0;
1183
    Op = pALU_TRB; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1184
    WSel = pWS_M; OSel = pNOP;
1185
    CCSel = pZ;
1186
    M = 255;
1187
    @(posedge Clk);
1188
    if((DO!=192)) begin
1189
        $display("Error: TRB #imm Test Failed");
1190
        $stop;
1191
    end
1192
    #1.1;
1193
    if(((P&(pPSW_Z))!=(0))) begin
1194
        $display("Error: TRB #imm Test Failed");
1195
        $stop;
1196
    end
1197
 
1198
    // TSB #192 -- Z flag set because test is ~|(A & M) rather that ~|ALU
1199
    En = 1; Reg_WE = 4; ISR = 0;
1200
    Op = pALU_TSB; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1201
    WSel = pWS_M; OSel = pNOP;
1202
    CCSel = pZ;
1203
    M = 192;
1204
    @(posedge Clk);
1205
    if((DO!=255)) begin
1206
        $display("Error: TSB #imm Test Failed");
1207
        $stop;
1208
    end
1209
    #1.1;
1210
    if(((P&(pPSW_Z))!=(pPSW_Z))) begin
1211
        $display("Error: TSB #imm Test Failed");
1212
        $stop;
1213
    end
1214
 
1215
    // End of Test
1216
 
1217
    En = 0;
1218
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1219
    WSel = pNOP; OSel = pOS_M;
1220
    CCSel = pNOP;
1221
    M = 255;
1222
    @(posedge Clk) #1;
1223
 
1224
    $display("End - Bit Test Unit Tests: Pass");
1225
//    $stop;
1226
 
1227
///////////////////////////////////////////////////////////////////////////////
1228
///////////////////////////////////////////////////////////////////////////////
1229
 
1230
    // Condition Code Tests
1231
 
1232
    $display("Start - Condition Code Tests");
1233
 
1234
    // PLP
1235
    En = 1; Reg_WE = 6; ISR = 0;
1236
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1237
    WSel = pNOP; OSel = pOS_M;
1238
    CCSel = pPSW;
1239
    M = 255;
1240
    @(posedge Clk) #1.1;
1241
    if(P!=8'hEF) begin
1242
        $display("Error: P Register Load Failed");
1243
        $stop;
1244
    end
1245
 
1246
    $display("   Start - Test Condition Codes");
1247
 
1248
    // BCC
1249
    En = 0; Reg_WE = 0;
1250
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1251
    WSel = pNOP; OSel = pOS_M;
1252
    CCSel = pCC;
1253
    M = 8;
1254
    @(posedge Clk);
1255
    if(CC_Out!=0) begin
1256
        $display("Error: C Clear Test Failed");
1257
        $stop;
1258
    end
1259
 
1260
    // BCS
1261
    En = 0; Reg_WE = 0;
1262
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1263
    WSel = pNOP; OSel = pOS_M;
1264
    CCSel = pCS;
1265
    M = 8;
1266
    @(posedge Clk);
1267
    if(CC_Out!=1) begin
1268
        $display("Error: C Set Test Failed");
1269
        $stop;
1270
    end
1271
 
1272
    // BNE
1273
    En = 0; Reg_WE = 0;
1274
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1275
    WSel = pNOP; OSel = pOS_M;
1276
    CCSel = pNE;
1277
    M = 8;
1278
    @(posedge Clk);
1279
    if(CC_Out!=0) begin
1280
        $display("Error: Z Clear Test Failed");
1281
        $stop;
1282
    end
1283
 
1284
    // BEQ
1285
    En = 0; Reg_WE = 0;
1286
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1287
    WSel = pNOP; OSel = pOS_M;
1288
    CCSel = pEQ;
1289
    M = 8;
1290
    @(posedge Clk);
1291
    if(CC_Out!=1) begin
1292
        $display("Error: Z Set Test Failed");
1293
        $stop;
1294
    end
1295
 
1296
    // BVC
1297
    En = 0; Reg_WE = 0;
1298
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1299
    WSel = pNOP; OSel = pOS_M;
1300
    CCSel = pVC;
1301
    M = 8;
1302
    @(posedge Clk);
1303
    if(CC_Out!=0) begin
1304
        $display("Error: V Clear Test Failed");
1305
        $stop;
1306
    end
1307
 
1308
    // BVS
1309
    En = 0; Reg_WE = 0;
1310
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1311
    WSel = pNOP; OSel = pOS_M;
1312
    CCSel = pVS;
1313
    M = 8;
1314
    @(posedge Clk);
1315
    if(CC_Out!=1) begin
1316
        $display("Error: V Set Test Failed");
1317
        $stop;
1318
    end
1319
 
1320
    // BPL
1321
    En = 0; Reg_WE = 0;
1322
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1323
    WSel = pNOP; OSel = pOS_M;
1324
    CCSel = pPL;
1325
    M = 8;
1326
    @(posedge Clk);
1327
    if(CC_Out!=0) begin
1328
        $display("Error: N Clear Test Failed");
1329
        $stop;
1330
    end
1331
 
1332
    // BMI
1333
    En = 0; Reg_WE = 0;
1334
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1335
    WSel = pNOP; OSel = pOS_M;
1336
    CCSel = pMI;
1337
    M = 8;
1338
    @(posedge Clk);
1339
    if(CC_Out!=1) begin
1340
        $display("Error: N Set Test Failed");
1341
        $stop;
1342
    end
1343
 
1344
    $display("   End - Test Condition Codes");
1345
 
1346
    // PLP
1347
    En = 1; Reg_WE = 4; ISR = 0;
1348
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1349
    WSel = pWS_P; OSel = pOS_M;
1350
    CCSel = pPSW;
1351
    M = 64;
1352
    @(posedge Clk) #1.1;
1353
    if(P!=96) begin
1354
        $display("Error: P Register Load Failed");
1355
        $stop;
1356
    end
1357
 
1358
    $display("   Start - Set/Clr Condition Codes");
1359
 
1360
    // CLV
1361
    En = 1; Reg_WE = 6; ISR = 0;
1362
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1363
    WSel = pNOP; OSel = pOS_M;
1364
    CCSel = pCLV;
1365
    M = 0;
1366
    @(posedge Clk) #1.1;
1367
    if(P!=32) begin
1368
        $display("Error: CLV Test Failed");
1369
        $stop;
1370
    end
1371
 
1372
    // SEC
1373
    En = 1; Reg_WE = 6; ISR = 0;
1374
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1375
    WSel = pNOP; OSel = pOS_M;
1376
    CCSel = pSEC;
1377
    M = 0;
1378
    @(posedge Clk) #1.1;
1379
    if(P!=33) begin
1380
        $display("Error: SEC Test Failed");
1381
        $stop;
1382
    end
1383
 
1384
    // CLC
1385
    En = 1; Reg_WE = 6; ISR = 0;
1386
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1387
    WSel = pNOP; OSel = pOS_M;
1388
    CCSel = pCLC;
1389
    M = 0;
1390
    @(posedge Clk) #1.1;
1391
    if(P!=32) begin
1392
        $display("Error: CLC Test Failed");
1393
        $stop;
1394
    end
1395
 
1396
    // SEI
1397
    En = 1; Reg_WE = 6; ISR = 0;
1398
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1399
    WSel = pNOP; OSel = pOS_M;
1400
    CCSel = pSEI;
1401
    M = 0;
1402
    @(posedge Clk) #1.1;
1403
    if(P!=36) begin
1404
        $display("Error: SEI Test Failed");
1405
        $stop;
1406
    end
1407
 
1408
    // CLI
1409
    En = 1; Reg_WE = 6; ISR = 0;
1410
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1411
    WSel = pNOP; OSel = pOS_M;
1412
    CCSel = pCLI;
1413
    M = 0;
1414
    @(posedge Clk) #1.1;
1415
    if(P!=32) begin
1416
        $display("Error: CLI Test Failed");
1417
        $stop;
1418
    end
1419
 
1420
    // SED
1421
    En = 1; Reg_WE = 6; ISR = 0;
1422
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1423
    WSel = pNOP; OSel = pOS_M;
1424
    CCSel = pSED;
1425
    M = 0;
1426
    @(posedge Clk) #1.1;
1427
    if(P!=40) begin
1428
        $display("Error: SED Test Failed");
1429
        $stop;
1430
    end
1431
 
1432
    // CLD
1433
    En = 1; Reg_WE = 6; ISR = 0;
1434
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1435
    WSel = pNOP; OSel = pOS_M;
1436
    CCSel = pCLD;
1437
    M = 0;
1438
    @(posedge Clk) #1.1;
1439
    if(P!=32) begin
1440
        $display("Error: CLD Test Failed");
1441
        $stop;
1442
    end
1443
 
1444
    // BRK Tst
1445
    En = 1; Reg_WE = 6; ISR = 0;
1446
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1447
    WSel = pNOP; OSel = pOS_M;
1448
    CCSel = pBRK;
1449
    M = 0;
1450
    @(posedge Clk);
1451
    if(P!=48) begin
1452
        $display("Error: B bit BRK Test Failed");
1453
        $stop;
1454
    end
1455
    #1;
1456
 
1457
    // PHP Test
1458
    En = 1; Reg_WE = 7; ISR = 0;
1459
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1460
    WSel = pNOP; OSel = pOS_P;
1461
    CCSel = pBRK;
1462
    M = 16;
1463
    @(posedge Clk);
1464
    if(P!=48) begin
1465
        $display("Error: B bit PHP Test Failed");
1466
        $stop;
1467
    end
1468
    #1;
1469
 
1470
    $display("   End - Set/Clr Condition Codes");
1471
 
1472
    // End of Test
1473
 
1474
    En = 0; Reg_WE = 0;
1475
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1476
    WSel = pNOP; OSel = pOS_M;
1477
    CCSel = pNOP;
1478
    M = 255;
1479
    @(posedge Clk) #1;
1480
 
1481
    $display("End - Condition Code Tests: Pass");
1482
//    $stop;
1483
 
1484
///////////////////////////////////////////////////////////////////////////////
1485
///////////////////////////////////////////////////////////////////////////////
1486
 
1487
    // Stack Push/Pull Tests
1488
 
1489
    $display("Start - Stack Push/Pull Tests");
1490
 
1491
    // Push
1492
    StkOp = 2;  // Push
1493
    En = 1; Reg_WE = 4; ISR = 0;
1494
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1495
    WSel = pWS_M; OSel = pOS_M;
1496
    CCSel = pNOP;
1497
    M = 192;
1498
    @(posedge Clk);
1499
    if(StkPtr!=255) begin
1500
        $display("Error: Stack Push Test Failed");
1501
        $stop;
1502
    end
1503
    #1.1;
1504
    if(S!=254) begin
1505
        $display("Error: Stack Push Test Failed");
1506
        $stop;
1507
    end
1508
 
1509
    // Pull
1510
    StkOp = 3;  // Pull
1511
    En = 1; Reg_WE = 4; ISR = 0;
1512
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1513
    WSel = pWS_M; OSel = pOS_M;
1514
    CCSel = pNOP;
1515
    M = 192;
1516
    @(posedge Clk);
1517
    if(StkPtr!=255) begin
1518
        $display("Error: Stack Push Test Failed");
1519
        $stop;
1520
    end
1521
    #1.1;
1522
    if(S!=255) begin
1523
        $display("Error: Stack Push Test Failed");
1524
        $stop;
1525
    end
1526
 
1527
    // NOP
1528
    En = 0; Reg_WE = 0;
1529
    Op = pNOP; QSel = pQS_M; RSel = 0; Sub = 0; CSel = 0;
1530
    WSel = pNOP; OSel = pOS_M;
1531
    CCSel = pNOP;
1532
    M = 0;
1533
    @(posedge Clk) #1;
1534
 
1535
    $display("End - Stack Push/Pull Tests: Pass");
1536
 
1537
///////////////////////////////////////////////////////////////////////////////
1538
///////////////////////////////////////////////////////////////////////////////
1539
 
1540
    $display("End - ALU Tests: Pass");
1541
    @(posedge Clk) #1;
1542
    @(posedge Clk) #1;
1543
    @(posedge Clk) #1;
1544
    @(posedge Clk) #1;
1545
    @(posedge Clk) #1;
1546
    $stop;
1547
end
1548
 
1549
///////////////////////////////////////////////////////////////////////////////
1550
 
1551
always #5 Clk = ~Clk;
1552
 
1553
endmodule
1554
 

powered by: WebSVN 2.1.0

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