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