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

Subversion Repositories m65c02

[/] [m65c02/] [trunk/] [Sim/] [tb_M65C02_AddrGen.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 and 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 souce 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 souce 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:     11:24:10 04/28/2012
45
// Design Name:     M65C02_AddrGen
46
// Module Name:     C:/XProjects/ISE10.1i/M65C02/tb_M65C02_AddrGen.v
47
// Project Name:    M65C02
48
// Target Devices:  Generic SRAM-based FPGA 
49
// Tool versions:   Xilinx ISE10.1i SP3
50
//
51
// Description:
52
//
53
// Verilog Test Fixture created by ISE for module: M65C02_AddrGen.v
54
//
55
// Revision: 
56
//
57
//  0.00    12D28   MAM     Initial File Creation
58
//
59
// Additional Comments: 
60
//
61
///////////////////////////////////////////////////////////////////////////////
62
 
63
module tb_M65C02_AddrGen;
64
 
65
///////////////////////////////////////////////////////////////////////////////
66
//
67
//  Local Parameters
68
//
69
 
70
localparam  pNA_MAR  = 4'h0;    // NA <= MAR
71
localparam  pNA_PC   = 4'h1;    // NA <= PC
72
localparam  pNA_Stk  = 4'h2;    // NA <= {8'b1, StkPtr}
73
localparam  pNA_Jsr  = 4'h3;    // NA <= {OP2, OP1}
74
//
75
localparam  pNA_Bcc  = 4'h4;    // NA <= ((CC)?((Next)+{{8{DI[7]}},DI}):Next)
76
localparam  pNA_Pls  = 4'h5;    // NA <= Next = MAR + 1
77
localparam  pNA_Inc  = 4'h6;    // NA <= Next = MAR + 1
78
localparam  pNA_Dec  = 4'h7;    // NA <= Next = MAR - 1
79
//
80
localparam  pNA_DPN  = 4'h8;    // NA <= {8'b0, DI} + 0
81
localparam  pNA_Jmp  = 4'h9;    // NA <= { DI, OP1} + 0
82
localparam  pNA_LDA  = 4'hA;    // NA <= { DI, OP1} + 0
83
localparam  pNA_Rtn  = 4'hB;    // NA <= { DI, OP1} + 1
84
//
85
localparam  pNA_DPX  = 4'hC;    // NA <= {8'b0, DI} + {0, X}
86
localparam  pNA_LDAX = 4'hD;    // NA <= { DI, OP1} + {0, X}
87
localparam  pNA_DPY  = 4'hE;    // NA <= {8'b0, DI} + {0, Y}
88
localparam  pNA_LDAY = 4'hF;    // NA <= { DI, OP1} + {0, Y}
89
 
90
localparam  pRst_Vec = 16'hFFFC;
91
localparam  pIRQ_Vec = 16'hFFFE;
92
localparam  pNMI_Vec = 16'hFFFA;
93
 
94
///////////////////////////////////////////////////////////////////////////////
95
 
96
// Inputs
97
 
98
reg     Rst;
99
reg     Clk;
100
 
101
reg     [15:0] Vector;
102
reg     BRV3;
103
reg     Int;
104
 
105
reg     Rdy_In;
106
 
107
reg     [3:0] NA_Op;
108
 
109
reg     CC;
110
reg     [7:0] DI;
111
reg     [7:0] OP1;
112
reg     [7:0] OP2;
113
reg     [7:0] StkPtr;
114
reg     [7:0] X;
115
reg     [7:0] Y;
116
 
117
// Outputs
118
 
119
wire    [15:0] AO;
120
wire    Rdy_Out;
121
 
122
wire    [15:0] NA;
123
wire    [15:0] MAR;
124
wire    [15:0] PC;
125
wire    [15:0] dPC;
126
 
127
// Simulation Variables
128
 
129
reg     [15:0] Rel     = 0;
130
reg     [15:0] Next    = 0;
131
reg     [15:0] Old_PC  = 0;
132
reg     [15:0] Old_dPC = 0;
133
 
134
// Instantiate the Unit Under Test (UUT)
135
 
136
M65C02_AddrGen  uut (
137
                    .Rst(Rst),
138
                    .Clk(Clk),
139
 
140
                    .Vector(Vector),
141
                    .BRV3(BRV3),
142
                    .Int(Int),
143
 
144
                    .Rdy_In(Rdy_In),
145
 
146
                    .NA_Op(NA_Op),
147
 
148
                    .CC(CC),
149
                    .DI(DI),
150
                    .OP1(OP1),
151
                    .OP2(OP2),
152
                    .StkPtr(StkPtr),
153
                    .X(X),
154
                    .Y(Y),
155
 
156
                    .AO(AO),
157
                    .Rdy_Out(Rdy_Out),
158
 
159
                    .NA(NA),
160
                    .MAR(MAR),
161
                    .PC(PC),
162
                    .dPC(dPC)
163
                );
164
 
165
initial begin
166
    // Initialize Inputs
167
    Rst     = 1;
168
    Clk     = 1;
169
 
170
    Vector      = pRst_Vec;
171
    BRV3        = 0;
172
    Int         = 0;
173
 
174
    Rdy_In      = 1;
175
 
176
    NA_Op       = 0;
177
 
178
    CC          = 0;
179
    DI          = 8'h96;
180
    {OP2, OP1}  = 16'hA55A;
181
    StkPtr      = 8'hFF;
182
    X           = ~DI;
183
    Y           = ~DI + 1;
184
 
185
    // Wait 100 ns for global reset to finish
186
 
187
    #101 Rst = 0;
188
 
189
    // Add stimulus here
190
 
191
    $display("Begin M65C02_AddrGen Tests\n");
192
 
193
    @(posedge Clk);
194
    if(   (AO  != pRst_Vec)
195
       || (MAR != pRst_Vec)
196
       || (PC  != pRst_Vec)
197
       || (dPC != pRst_Vec)) begin
198
        $display("    Error: M65C02_AddrGen not Reset Properly\n");
199
        $display("    Vector: %h, AO: %h, MAR: %d, PC: %h, dPC: %h\n",
200
                  pRst_Vec, AO, MAR, PC, dPC);
201
        $stop;
202
    end
203
    if(Rdy_Out) begin
204
        $display("    Error: M65C02_AddrGen not Reset Properly\n");
205
        $display("    Rdy_Out: %b; Expected 0\n", Rdy_Out);
206
        $stop;
207
    end
208
 
209
    @(posedge Clk);
210
    if((MAR != pRst_Vec)) begin
211
        $display("    Error: M65C02_AddrGen MAR Incremented Unexpectedly\n");
212
        $display("    MAR: %h; Expected: %d\n", MAR, pRst_Vec);
213
        $stop;
214
    end
215
    if(!Rdy_Out) begin
216
        $display("    Error: Rdy_Out not asserted\n");
217
        $stop;
218
    end
219
    if((PC != pRst_Vec) || (dPC != pRst_Vec)) begin
220
        $display("    Error: M65C02_AddrGen PC/dPC Unexpectedly Changed\n");
221
        $display("    PC: %h, dPC: %h; Expected: %h\n", PC, dPC, pRst_Vec);
222
        $stop;
223
    end
224
 
225
    $display("Initialization Test Complete: PASS\n");
226
 
227
    $display("Testing Sequential Increment/Decrement Operations\n");
228
 
229
    #1 NA_Op = pNA_Inc;
230
    @(posedge Clk) #1 NA_Op = pNA_Dec;
231
    #1;
232
    if((MAR != (pRst_Vec + 1))) begin
233
        $display("    Error: M65C02_AddrGen MAR did not increment as expected\n");
234
        $display("    MAR: %h; Expected: %h\n", MAR, (pRst_Vec + 1));
235
        $stop;
236
    end
237
    if(!Rdy_Out) begin
238
        $display("    Error: Rdy_Out not asserted as expected\n");
239
        $stop;
240
    end
241
    if((PC != pRst_Vec) || (dPC != pRst_Vec)) begin
242
        $display("    Error: M65C02_AddrGen PC/dPC Unexpectedly Changed\n");
243
        $display("    PC: %h, dPC: %h; Expected: %h\n", PC, dPC, pRst_Vec);
244
        $stop;
245
    end
246
 
247
    @(posedge Clk) #1 NA_Op = pNA_MAR;
248
    #1;
249
    if((MAR != (pRst_Vec))) begin
250
        $display("    Error: M65C02_AddrGen MAR did not decrement as expected\n");
251
        $display("    MAR: %h; Expected: %h\n", MAR, (pRst_Vec));
252
        $stop;
253
    end
254
    if(!Rdy_Out) begin
255
        $display("    Error: Rdy_Out not asserted as expected\n");
256
        $stop;
257
    end
258
    if((PC != pRst_Vec) || (dPC != pRst_Vec)) begin
259
        $display("    Error: M65C02_AddrGen PC/dPC Unexpectedly Changed\n");
260
        $display("    PC: %h, dPC: %h; Expected: %h\n", PC, dPC, pRst_Vec);
261
        $stop;
262
    end
263
 
264
    $display("    Sequential Increment/Decrement Operations: PASS\n");
265
 
266
 
267
    $display("Testing MAR <= PC Operation\n");
268
 
269
    @(posedge Clk) #1 NA_Op = pNA_Inc;
270
    @(posedge Clk) #1 NA_Op = pNA_PC;
271
    @(posedge Clk) #1 NA_Op = pNA_MAR;
272
    #1;
273
    if((MAR != PC)) begin
274
        $display("    Error: M65C02_AddrGen PC not loaded into MAR\n");
275
        $display("    MAR: %h; Expected: %h\n", MAR, PC);
276
        $stop;
277
    end
278
    if(Rdy_Out) begin
279
        $display("Error: Rdy_Out asserted\n");
280
        $stop;
281
    end
282
    if((PC != pRst_Vec) || (dPC != pRst_Vec)) begin
283
        $display("    Error: M65C02_AddrGen PC/dPC Unexpectedly Changed\n");
284
        $display("    PC: %h, dPC: %h; Expected: %h\n", PC, dPC, pRst_Vec);
285
        $stop;
286
    end
287
    @(posedge Rdy_Out);
288
 
289
    $display("    Testing MAR <= PC Operation: PASS\n");
290
 
291
    $display("Testing MAR <= StkPtr Operation\n");
292
 
293
    @(posedge Clk) #1 NA_Op = pNA_Stk;
294
    @(posedge Clk) #1 NA_Op = pNA_MAR;
295
    #1;
296
    if((MAR != {8'b1, StkPtr})) begin
297
        $display("    Error: M65C02_AddrGen Stk_Ptr not loaded into MAR\n");
298
        $display("    MAR: %h; Expected: %h\n", MAR, {8'b1, StkPtr});
299
        $stop;
300
    end
301
    if(Rdy_Out) begin
302
        $display("Error: Rdy_Out asserted\n");
303
        $stop;
304
    end
305
    if((PC != pRst_Vec) || (dPC != pRst_Vec)) begin
306
        $display("    Error: M65C02_AddrGen PC/dPC Unexpectedly Changed\n");
307
        $display("    PC: %h, dPC: %h; Expected: %h\n", PC, dPC, pRst_Vec);
308
        $stop;
309
    end
310
    @(posedge Rdy_Out);
311
 
312
    $display("    Testing MAR/PC <= StkPtr Operation: PASS\n");
313
 
314
    $display("Testing MAR <= {OP2, OP1} Operation\n");
315
 
316
    @(posedge Clk) #1 NA_Op = pNA_Jsr;
317
    @(posedge Clk) #1 NA_Op = pNA_MAR;
318
    #1;
319
    if((MAR != {OP2, OP1})) begin
320
        $display("    Error: M65C02_AddrGen {OP2, OP1} not loaded into MAR\n");
321
        $display("    MAR: %h; Expected: %h\n", MAR, {OP2, OP1});
322
        $stop;
323
    end
324
    if(Rdy_Out) begin
325
        $display("    Error: Rdy_Out asserted\n");
326
        $stop;
327
    end
328
    if((PC != {OP2, OP1})) begin
329
        $display("    Error: M65C02_AddrGen {OP2, OP1} not loaded into PC\n");
330
        $display("    PC: %h; Expected: %h\n", PC, {OP2, OP1});
331
        $stop;
332
    end
333
    if((dPC != pRst_Vec)) begin
334
        $display("    Error: M65C02_AddrGen dPC Unexpectedly Changed\n");
335
        $display("    dPC: %h; Expected: %h\n", dPC, pRst_Vec);
336
        $stop;
337
    end
338
    @(posedge Rdy_Out);
339
 
340
    $display("    Testing MAR/PC <= {OP2, OP1} Operation: PASS\n");
341
 
342
    $display("Testing MAR/PC <= Bcc Operation\n");
343
 
344
    {OP2, OP1} = PC;
345
 
346
    @(posedge Clk) #1 NA_Op = pNA_Bcc; CC = 1;
347
    @(posedge Clk) #1 NA_Op = pNA_MAR; CC = 0;
348
    #1;
349
    if((MAR != Rel)) begin
350
        $display("    Error: M65C02_AddrGen (MAR + 1 + rel) not loaded into MAR\n");
351
        $display("    MAR: %h; Expected: %h\n", MAR, Rel);
352
        $stop;
353
    end
354
    if(Rdy_Out) begin
355
        $display("    Error: Rdy_Out asserted\n");
356
        $stop;
357
    end
358
    if((PC != Rel)) begin
359
        $display("    Error: M65C02_AddrGen (MAR + 1 + rel) not loaded into PC\n");
360
        $display("    PC: %h; Expected: %h\n", PC, Rel);
361
        $stop;
362
    end
363
    if((dPC != {OP2, OP1})) begin
364
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
365
        $display("    dPC: %h; Expected: %h\n", dPC, {OP2, OP1});
366
        $stop;
367
    end
368
    @(posedge Rdy_Out);
369
 
370
    {OP2, OP1} = PC;
371
 
372
    @(posedge Clk) #1 NA_Op = pNA_Bcc;
373
    @(posedge Clk) #1 NA_Op = pNA_MAR;
374
    #1;
375
    if((MAR != Rel)) begin
376
        $display("    Error: M65C02_AddrGen (MAR + 1) not loaded into MAR\n");
377
        $display("    MAR: %h; Expected: %h\n", MAR, Rel);
378
        $stop;
379
    end
380
    if(!Rdy_Out) begin
381
        $display("    Error: Rdy_Out not asserted\n");
382
        $stop;
383
    end
384
    if((PC != Rel)) begin
385
        $display("    Error: M65C02_AddrGen (MAR + 1) not loaded into PC\n");
386
        $display("    PC: %h; Expected: %h\n", PC, Rel);
387
        $stop;
388
    end
389
    if((dPC != {OP2, OP1})) begin
390
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
391
        $display("    dPC: %h; Expected: %h\n", dPC, {OP2, OP1});
392
        $stop;
393
    end
394
    @(posedge Clk) #1;
395
 
396
    $display("    Testing MAR/PC <= Bcc Operation: PASS\n");
397
 
398
    $display("Testing MAR/PC <= (PC + 1) Operation\n");
399
 
400
    {OP2, OP1} = PC;
401
    Next       = PC + 1;
402
 
403
    @(posedge Clk) #1 NA_Op = pNA_Pls;
404
    @(posedge Clk) #1 NA_Op = pNA_MAR;
405
    #1;
406
    if((MAR != Next)) begin
407
        $display("    Error: M65C02_AddrGen (MAR + 1) not loaded into MAR\n");
408
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
409
        $stop;
410
    end
411
    if(!Rdy_Out) begin
412
        $display("    Error: Rdy_Out not asserted\n");
413
        $stop;
414
    end
415
    if((PC != Next)) begin
416
        $display("    Error: M65C02_AddrGen (MAR + 1) not loaded into PC\n");
417
        $display("    PC: %h; Expected: %h\n", PC, Next);
418
        $stop;
419
    end
420
    if((dPC != {OP2, OP1})) begin
421
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
422
        $display("    dPC: %h; Expected: %h\n", dPC, {OP2, OP1});
423
        $stop;
424
    end
425
 
426
    $display("    Testing MAR/PC <= (PC + 1) Operation: PASS\n");
427
 
428
    $display("Testing MAR/PC <= Jmp Operation\n");
429
 
430
    {OP2, OP1} = PC;
431
    Next       = {DI, OP1};
432
 
433
    @(posedge Clk) #1 NA_Op = pNA_Jmp;
434
    @(posedge Clk) #1 NA_Op = pNA_MAR;
435
    #1;
436
    if((MAR != Next)) begin
437
        $display("    Error: M65C02_AddrGen {DI, OP1} not loaded into MAR\n");
438
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
439
        $stop;
440
    end
441
    if(Rdy_Out) begin
442
        $display("    Error: Rdy_Out asserted\n");
443
        $stop;
444
    end
445
    if((PC != Next)) begin
446
        $display("    Error: M65C02_AddrGen {DI, OP1} not loaded into PC\n");
447
        $display("    PC: %h; Expected: %h\n", PC, Next);
448
        $stop;
449
    end
450
    if((dPC != {OP2, OP1})) begin
451
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
452
        $display("    dPC: %h; Expected: %h\n", dPC, {OP2, OP1});
453
        $stop;
454
    end
455
    @(posedge Rdy_Out);
456
 
457
    $display("    Testing MAR/PC <= Jmp Operation: PASS\n");
458
 
459
    $display("Testing MAR/PC <= RTS/RTI Operation\n");
460
 
461
    {OP2, OP1} = PC;
462
    Next       = {DI, OP1} + 1;
463
 
464
    @(posedge Clk) #1 NA_Op = pNA_Rtn;
465
    @(posedge Clk) #1 NA_Op = pNA_MAR;
466
    #1;
467
    if((MAR != Next)) begin
468
        $display("    Error: M65C02_AddrGen {DI, OP1} + 1 not loaded into MAR\n");
469
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
470
        $stop;
471
    end
472
    if(Rdy_Out) begin
473
        $display("    Error: Rdy_Out asserted\n");
474
        $stop;
475
    end
476
    if((PC != Next)) begin
477
        $display("    Error: M65C02_AddrGen {DI, OP1} + 1 not loaded into PC\n");
478
        $display("    PC: %h; Expected: %h\n", PC, Next);
479
        $stop;
480
    end
481
    if((dPC != {OP2, OP1})) begin
482
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
483
        $display("    dPC: %h; Expected: %h\n", dPC, {OP2, OP1});
484
        $stop;
485
    end
486
    @(posedge Rdy_Out);
487
 
488
    $display("    Testing MAR/PC <= RTS/RTI Operation: PASS\n");
489
 
490
    $display("Testing MAR <= DP Operation\n");
491
 
492
    Old_PC  = PC;
493
    Old_dPC = dPC;
494
    Next    = {8'b0, DI};
495
 
496
    @(posedge Clk) #1 NA_Op = pNA_DPN;
497
    @(posedge Clk) #1 NA_Op = pNA_MAR;
498
    #1;
499
    if((MAR != Next)) begin
500
        $display("    Error: M65C02_AddrGen {8'b0, DI} not loaded into MAR\n");
501
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
502
        $stop;
503
    end
504
    if(Rdy_Out) begin
505
        $display("    Error: Rdy_Out asserted\n");
506
        $stop;
507
    end
508
    if((PC != Old_PC)) begin
509
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
510
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
511
        $stop;
512
    end
513
    if((dPC != Old_dPC)) begin
514
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
515
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
516
        $stop;
517
    end
518
    @(posedge Rdy_Out);
519
 
520
    $display("    Testing MAR <= DP Operation: PASS\n");
521
 
522
    $display("Testing MAR <= Abs Operation\n");
523
 
524
    Old_PC  = PC;
525
    Old_dPC = dPC;
526
    Next    = {DI, OP1};
527
 
528
    @(posedge Clk) #1 NA_Op = pNA_LDA;
529
    @(posedge Clk) #1 NA_Op = pNA_MAR;
530
    #1;
531
    if((MAR != Next)) begin
532
        $display("    Error: M65C02_AddrGen {DI, OP1} not loaded into MAR\n");
533
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
534
        $stop;
535
    end
536
    if(Rdy_Out) begin
537
        $display("    Error: Rdy_Out asserted\n");
538
        $stop;
539
    end
540
    if((PC != Old_PC)) begin
541
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
542
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
543
        $stop;
544
    end
545
    if((dPC != Old_dPC)) begin
546
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
547
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
548
        $stop;
549
    end
550
    @(posedge Rdy_Out);
551
 
552
    $display("    Testing MAR <= Abs Operation: PASS\n");
553
 
554
    $display("Testing MAR <= DP,X Operation\n");
555
 
556
    Old_PC  = PC;
557
    Old_dPC = dPC;
558
    Next    = {8'b0, (DI + X) & 8'hFF};
559
 
560
    @(posedge Clk) #1 NA_Op = pNA_DPX;
561
    @(posedge Clk) #1 NA_Op = pNA_MAR;
562
    #1;
563
    if((MAR != Next)) begin
564
        $display("    Error: M65C02_AddrGen {8'b0, (DI + X) mod 256} not loaded into MAR\n");
565
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
566
        $stop;
567
    end
568
    if(Rdy_Out) begin
569
        $display("    Error: Rdy_Out asserted\n");
570
        $stop;
571
    end
572
    if((PC != Old_PC)) begin
573
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
574
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
575
        $stop;
576
    end
577
    if((dPC != Old_dPC)) begin
578
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
579
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
580
        $stop;
581
    end
582
    @(posedge Rdy_Out);
583
 
584
    $display("    Testing MAR <= DP,X Operation: PASS\n");
585
 
586
    $display("Testing MAR <= DP,Y Operation\n");
587
 
588
    Old_PC  = PC;
589
    Old_dPC = dPC;
590
    Next    = {8'b0, (DI + Y) & 8'hFF};
591
 
592
    @(posedge Clk) #1 NA_Op = pNA_DPY;
593
    @(posedge Clk) #1 NA_Op = pNA_MAR;
594
    #1;
595
    if((MAR != Next)) begin
596
        $display("    Error: M65C02_AddrGen {8'b0, (DI + Y) mod 256} not loaded into MAR\n");
597
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
598
        $stop;
599
    end
600
    if(Rdy_Out) begin
601
        $display("    Error: Rdy_Out asserted\n");
602
        $stop;
603
    end
604
    if((PC != Old_PC)) begin
605
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
606
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
607
        $stop;
608
    end
609
    if((dPC != Old_dPC)) begin
610
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
611
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
612
        $stop;
613
    end
614
    @(posedge Rdy_Out);
615
 
616
    $display("    Testing MAR <= DP,Y Operation: PASS\n");
617
 
618
    $display("Testing MAR <= Abs,X Operation\n");
619
 
620
    Old_PC  = PC;
621
    Old_dPC = dPC;
622
    Next    = {DI, OP1} + {8'b0, X};
623
 
624
    @(posedge Clk) #1 NA_Op = pNA_LDAX;
625
    @(posedge Clk) #1 NA_Op = pNA_MAR;
626
    #1;
627
    if((MAR != Next)) begin
628
        $display("    Error: M65C02_AddrGen (Abs + X) not loaded into MAR\n");
629
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
630
        $stop;
631
    end
632
    if(Rdy_Out) begin
633
        $display("    Error: Rdy_Out asserted\n");
634
        $stop;
635
    end
636
    if((PC != Old_PC)) begin
637
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
638
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
639
        $stop;
640
    end
641
    if((dPC != Old_dPC)) begin
642
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
643
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
644
        $stop;
645
    end
646
    @(posedge Rdy_Out);
647
 
648
    $display("    Testing MAR <= Abs,X Operation: PASS\n");
649
 
650
    $display("Testing MAR <= Abs,Y Operation\n");
651
 
652
    Old_PC  = PC;
653
    Old_dPC = dPC;
654
    Next    = {DI, OP1} + {8'b0, Y};
655
 
656
    @(posedge Clk) #1 NA_Op = pNA_LDAY;
657
    @(posedge Clk) #1 NA_Op = pNA_MAR;
658
    #1;
659
    if((MAR != Next)) begin
660
        $display("    Error: M65C02_AddrGen (Abs + Y) not loaded into MAR\n");
661
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
662
        $stop;
663
    end
664
    if(Rdy_Out) begin
665
        $display("    Error: Rdy_Out asserted\n");
666
        $stop;
667
    end
668
    if((PC != Old_PC)) begin
669
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
670
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
671
        $stop;
672
    end
673
    if((dPC != Old_dPC)) begin
674
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
675
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
676
        $stop;
677
    end
678
    @(posedge Rdy_Out);
679
 
680
    $display("    Testing MAR <= Abs,Y Operation: PASS\n");
681
 
682
 
683
    $display("Testing PC Interrupt Behavior\n");
684
 
685
    Old_PC  = PC;
686
    Old_dPC = dPC;
687
    Next    = PC;
688
 
689
    BRV3 = 0; Int = 1;
690
 
691
    @(posedge Clk) #1 NA_Op = pNA_PC;
692
    @(posedge Clk) #1 NA_Op = pNA_Pls;
693
    #1;
694
    if((MAR != Next)) begin
695
        $display("    Error: MAR != PC\n");
696
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
697
        $stop;
698
    end
699
    if(Rdy_Out) begin
700
        $display("    Error: Rdy_Out asserted\n");
701
        $stop;
702
    end
703
    if((PC != Old_PC)) begin
704
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
705
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
706
        $stop;
707
    end
708
    if((dPC != Old_dPC)) begin
709
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
710
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
711
        $stop;
712
    end
713
    @(posedge Rdy_Out);
714
 
715
    $display("    BRV3 not asserted, Int asserted, MAR loaded with PC as expected\n");
716
 
717
    Old_PC  = PC + 1;
718
    Old_dPC = PC;
719
    Next    = PC + 1;
720
 
721
    BRV3 = 0; Int = 1;
722
 
723
    @(posedge Clk) #1 NA_Op = pNA_Pls;
724
    #1;
725
    if((MAR != Next)) begin
726
        $display("    Error: MAR != PC\n");
727
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
728
        $stop;
729
    end
730
    if(!Rdy_Out) begin
731
        $display("    Error: Rdy_Out not asserted\n");
732
        $stop;
733
    end
734
    if((PC != Old_PC)) begin
735
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
736
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
737
        $stop;
738
    end
739
    if((dPC != Old_dPC)) begin
740
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
741
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
742
        $stop;
743
    end
744
    @(posedge Clk) #1 NA_Op = pNA_Pls;
745
    #1;
746
 
747
    $display("    BRV3 not asserted, Int asserted, PC increments as expected\n");
748
 
749
    Old_PC  = PC + 1;
750
    Old_dPC = PC;
751
    Next    = PC + 1;
752
 
753
    BRV3 = 0; Int = 1;
754
 
755
    @(posedge Clk) #1 NA_Op = pNA_MAR;
756
    #1;
757
    if((MAR != Next)) begin
758
        $display("    Error: MAR != PC\n");
759
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
760
        $stop;
761
    end
762
    if(!Rdy_Out) begin
763
        $display("    Error: Rdy_Out not asserted\n");
764
        $stop;
765
    end
766
    if((PC != Old_PC)) begin
767
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
768
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
769
        $stop;
770
    end
771
    if((dPC != Old_dPC)) begin
772
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
773
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
774
        $stop;
775
    end
776
    @(posedge Clk) #1 NA_Op = pNA_Pls;
777
 
778
    $display("    BRV3 not asserted, Int asserted, PC increments as expected\n");
779
 
780
    BRV3 = 1; Int = 0;
781
 
782
    #1;
783
    Old_PC  = PC + 1;
784
    Old_dPC = PC;
785
    Next    = PC + 1;
786
 
787
    @(posedge Clk) #1 NA_Op = pNA_Pls;
788
    #1;
789
    if((MAR != Next)) begin
790
        $display("    Error: MAR != PC\n");
791
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
792
        $stop;
793
    end
794
    if(!Rdy_Out) begin
795
        $display("    Error: Rdy_Out not asserted\n");
796
        $stop;
797
    end
798
    if((PC != Old_PC)) begin
799
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
800
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
801
        $stop;
802
    end
803
    if((dPC != Old_dPC)) begin
804
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
805
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
806
        $stop;
807
    end
808
    @(posedge Clk) #1 NA_Op = pNA_Pls;
809
 
810
    $display("    BRV3 asserted, Int not asserted, PC increments as expected\n");
811
 
812
    BRV3 = 1; Int = 1;
813
 
814
    #1;
815
    Old_PC  = PC;
816
    Old_dPC = dPC;
817
    Next    = PC;
818
 
819
    @(posedge Clk) #1 NA_Op = pNA_Pls;
820
    #1;
821
    if((MAR != Next)) begin
822
        $display("    Error: MAR != PC\n");
823
        $display("    MAR: %h; Expected: %h\n", MAR, Next);
824
        $stop;
825
    end
826
    if(!Rdy_Out) begin
827
        $display("    Error: Rdy_Out not asserted\n");
828
        $stop;
829
    end
830
    if((PC != Old_PC)) begin
831
        $display("    Error: M65C02_AddrGen PC incorrectly changed\n");
832
        $display("    PC: %h; Expected: %h\n", PC, Old_PC);
833
        $stop;
834
    end
835
    if((dPC != Old_dPC)) begin
836
        $display("    Error: M65C02_AddrGen dPC incorrectly changed\n");
837
        $display("    dPC: %h; Expected: %h\n", dPC, Old_dPC);
838
        $stop;
839
    end
840
    @(posedge Clk) #1 NA_Op = pNA_MAR;
841
 
842
    $display("    BRV3 and Int asserted, as expected, MAR/PC does not increment\n");
843
 
844
    BRV3 = 0; Int = 0;
845
 
846
    $display("    PC operation with interrupts: PASS\n");
847
 
848
    /////////////////////////////////////////////
849
 
850
    $display("End M65C02_AddrGen Tests: PASS\n");
851
 
852
    NA_Op = pNA_MAR;
853
    @(posedge Clk) #1;
854
    @(posedge Clk) #1;
855
    @(posedge Clk) #1;
856
    @(posedge Clk) #1;
857
    $stop;
858
end
859
 
860
///////////////////////////////////////////////////////////////////////////////
861
//
862
//  System Clock
863
//
864
 
865
always #5 Clk = ~Clk;
866
 
867
///////////////////////////////////////////////////////////////////////////////
868
//
869
//
870
//
871
 
872
always @(posedge Clk) Rel = #1 (MAR + 1 + ((CC) ? {{8{DI[7]}}, DI} : 0));
873
 
874
always @(*) Rdy_In = Rdy_Out;
875
 
876
endmodule
877
 

powered by: WebSVN 2.1.0

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