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

Subversion Repositories m65c02

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

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

Line No. Rev Author Line
1 2 MichaelA
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  Copyright 2012-2013 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 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:     15:34:45 02/22/2013
45
// Design Name:     M65C02
46
// Module Name:     C:/XProjects/ISE10.1i/M65C02/tb_M65C02.v
47
// Project Name:    M65C02
48
// Target Device:   Xilinx Spartan-3A FPGA - XC3S50A-4VQ100
49
// Tool versions:   ISE 10.1i SP3  
50
//
51
// Description: 
52
//
53
// Verilog Test Fixture created by ISE for module: M65C02
54
//
55
// Dependencies:
56
// 
57
// Revision:
58
//
59
//  0.01    13B22   MAM     File Created
60
//
61
//  1.00    14B24   MAM     Initial release
62
//
63
//  1.10    13B26   MAM     Changed to support M65C02 with internal 2kB Boot ROM    
64
//
65
// Additional Comments:
66
// 
67
////////////////////////////////////////////////////////////////////////////////
68
 
69
module tb_M65C02;
70
 
71
parameter pRAM_AddrWidth = 14;
72
parameter pSim_Loop      = 16'h0400;
73
 
74
// UUT Signal Declarations
75
 
76
reg     nRst;
77
tri1    nRstO;
78
 
79
reg     ClkIn;
80
 
81
wire    Phi1O;
82
wire    Phi2O;
83
 
84
tri1    nSO;
85
tri1    nNMI;
86
tri1    nIRQ;
87
tri1    nVP;
88
 
89
reg     BE_In;
90
tri1    Rdy;
91
tri0    Sync;
92
tri1    nML;
93
wire    nWait;
94
 
95
tri1    [3:0] nCE;
96
tri1    RnW;
97
tri1    nOE;
98
tri1    nWr;
99
tri1    [ 3:0] XA;
100
tri1    [15:0] A;
101
tri1    [ 7:0] DB;
102
 
103
//tri1    nSel;
104
//tri1    SCk;
105
//tri1    MOSI;
106
//reg     MISO;
107
 
108
wire    [4:0] LED;
109
 
110
//  Define simulation variables
111
 
112
reg     Sim_nSO, Sim_nNMI, Sim_nIRQ;
113
reg     [ 7:0] TestNum;
114
reg     [17:0] chkdad, chkadd;
115
 
116
//integer i = 0;
117
 
118
integer cycle_cnt = 0;
119
integer instr_cnt = 0;
120
 
121
integer Loop_Start = 0;
122
 
123
integer Hist_File = 0;          // File handle for instruction histogram
124
//integer SV_Output = 0;          // File handle for State Vector Outputs
125
 
126
reg     [31:0] Hist [255:0];    // Instruction Histogram array
127
reg     [31:0] val;             // Instruction Histogram variable
128
reg     [31:0] i, j;            // loop counters
129
 
130
//reg     [((5*8) - 1):0] Op;     // Processor Mode Mnemonics String
131
//reg     [((6*8) - 1):0] Opcode; // Opcode Mnemonics String
132
//reg     [((9*8) - 1):0] AddrMd; // Addressing Mode Mnemonics String
133
 
134
// Instantiate the Unit Under Test (UUT)
135
 
136
M65C02  #(
137
            .pBootROM_File("M65C02_Tst5.txt")
138
        ) uut (
139
            .nRst(nRst),
140
            .nRstO(nRstO),
141
 
142
            .ClkIn(ClkIn),
143
 
144
            .Phi1O(Phi1O),
145
            .Phi2O(Phi2O),
146
 
147
            .nSO(nSO),
148
            .nNMI(nNMI),
149
            .nIRQ(nIRQ),
150
            .nVP(nVP),
151
 
152
            .BE_In(BE_In),
153
            .Sync(Sync),
154
            .nML(nML),
155
 
156
            .nCE(nCE),
157
            .RnW(RnW),
158
            .nWr(nWr),
159
            .nOE(nOE),
160
            .Rdy(Rdy),
161
            .XA(XA),
162
            .A(A),
163
            .DB(DB),
164
 
165
            .nWP_In(1'b0),
166
 
167
            .nWait(nWait),
168
 
169
            .LED(LED),
170
 
171
            .nSel(nSel),
172
            .SCk(SCk),
173
            .MOSI(MOSI),
174
            .MISO(MISO)
175
        );
176
 
177
////  Instantiate Boot/Monitor ROM Module
178
//
179
//wire    [7:0] ROM_DO;
180
//reg     ROM_WE;
181
//
182
//M65C02_RAM  #(
183
//                .pAddrSize(pRAM_AddrWidth),
184
//                .pDataSize(8),
185
//                .pFileName("M65C02_Tst3.txt")
186
//            ) ROM (
187
//                .Clk(~Phi2O),
188
////                .Ext(1'b1),     // 4 cycle memory
189
////                .ZP(1'b0),
190
////                .Ext(1'b0),     // 2 cycle memory
191
////                .ZP(1'b0),
192
//                .Ext(1'b0),   // 1 cycle memory
193
//                .ZP(1'b1),
194
//                .WE(ROM_WE),
195
//                .AI(A[(pRAM_AddrWidth - 1):0]),
196
//                .DI(DB),
197
//                .DO(ROM_DO)
198
//            );
199
 
200
//  Instantiate RAM Module
201
 
202
wire    [7:0] RAM_DO;
203
reg     RAM_WE;
204
 
205
M65C02_RAM  #(
206
                .pAddrSize(pRAM_AddrWidth),
207
                .pDataSize(8),
208
                .pFileName("65C02_FT.txt")
209
            ) RAM (
210
                .Clk(~Phi2O),
211
//                .Ext(1'b1),     // 4 cycle memory
212
//                .ZP(1'b0),
213
//                .Ext(1'b0),     // 2 cycle memory
214
//                .ZP(1'b0),
215
                .Ext(1'b0),     // 1 cycle memory
216
                .ZP(1'b1),
217
                .WE(RAM_WE),
218
                .AI(A[(pRAM_AddrWidth - 1):0]),
219
                .DI(DB),
220
                .DO(RAM_DO)
221
            );
222
 
223
initial begin
224
    // Initialize Inputs
225
    nRst     = 0;
226
    ClkIn    = 1;
227
    Sim_nSO  = 0;
228
    Sim_nNMI = 0;
229
    Sim_nIRQ = 0;
230
    BE_In    = 1;
231
    //Rdy      = 1;
232
    //MISO     = 1;
233
    TestNum  = 0;
234
    chkdad   = 0;
235
    chkadd   = 0;
236
 
237
    // Intialize Simulation Time Format
238
 
239
    $timeformat (-9, 3, " ns", 12);
240
 
241
    //  Initialize Instruction Execution Histogram array
242
 
243
    for(cycle_cnt = 0; cycle_cnt < 256; cycle_cnt = cycle_cnt + 1)
244
        Hist[cycle_cnt] = 0;
245
    cycle_cnt = 0;
246
 
247
    Hist_File = $fopen("M65C02_Hist_File.txt", "w");
248
//    SV_Output = $fopen("M65C02_SV_Output.txt", "w");
249
 
250
    // Wait 100 ns for global reset to finish
251
 
252
    #101 nRst = 1;
253
 
254
    // Add stimulus here
255
 
256
    // Start the Simulation Loop
257
 
258
    wait(A == pSim_Loop);
259
    @(posedge Phi1O);
260
 
261
    // Test WAI w/ IRQ_Mask set
262
 
263
    fork
264
        begin
265
            @(negedge nWait);
266
            for(i = 0; i < 4; i = i + 1) @(posedge Phi1O);
267
            Sim_nIRQ = 1;
268
            @(posedge nWait);
269
            @(posedge Phi1O) Sim_nIRQ = 0;
270
        end
271
 
272
        begin
273
            while(1) begin
274
                @(posedge Phi1O);
275
                if(A == pSim_Loop) begin
276
                    @(posedge Phi1O);
277
                    @(posedge Phi1O);
278
                    @(posedge Phi1O);
279
                    $display("End of Simulation - Looping to Start detected/n");
280
                    $display("\tSuccess - All enabled tests passed.\n");
281
                    $stop;
282
                end
283
            end
284
        end
285
    join
286
end
287
 
288
////////////////////////////////////////////////////////////////////////////////
289
//
290
//  Clocks
291
//
292
 
293
//always #20.000 ClkIn = ~ClkIn;
294
//always #27.127 ClkIn = ~ClkIn;
295
always #33.908 ClkIn = ~ClkIn;
296
//always #12.500 ClkIn = ~ClkIn;
297
 
298
////////////////////////////////////////////////////////////////////////////////
299
//
300
//  Test Structures
301
//
302
 
303
always @(posedge nWr)
304
begin
305
    TestNum = ((A == 16'h0200) ? DB : TestNum);
306
end
307
 
308
always @(posedge nOE)
309
begin
310
    chkdad = ((A == 16'h3405) ? (chkdad + 1) : chkdad);
311
end
312
 
313
always @(posedge nOE)
314
begin
315
    chkadd = ((A == 16'h354E) ? (chkadd + 1) : chkadd);
316
end
317
 
318
//  Connect ROM/RAM to M65C02 memory bus
319
 
320
//always @(*) ROM_WE <= Phi2O &  A[15] & ~nWr;
321
always @(*) RAM_WE <= Phi2O & ~A[15] & ~nWr;
322
 
323
//assign DB = ((~nOE) ? ((A[15]) ? ROM_DO : RAM_DO) : {8{1'bZ}});
324
assign DB = ((~nOE) ? RAM_DO : {8{1'bZ}});
325
 
326
//  Generate Simulate nIRQ signal based on writes by test program to address
327
//      0xFFF8 (assert nIRQ) or 0xFFF9 (deassert nIRQ)
328
 
329
always @(posedge nWr or negedge nRstO)
330
begin
331
    if(~nRstO)
332
        Sim_nIRQ <= 0;
333
    else
334
        Sim_nIRQ <= ((A[15:1] == 15'b1111_1111_1111_100) ? ~A[0] : Sim_nIRQ);
335
end
336
 
337
//  Drive nSO, nNMI, and nIRQ using simulation controlled signals
338
 
339
assign nSO  = ((Sim_nSO)  ? 0 : 1'bZ);
340
assign nNMI = ((Sim_nNMI) ? 0 : 1'bZ);
341
assign nIRQ = ((Sim_nIRQ) ? 0 : 1'bZ);
342
 
343
//  Count number of cycles and the number of instructions between between
344
//      0x0210 and the repeat at 0x0210 
345
 
346
always @(posedge uut.ClkGen.Clk)
347
begin
348
    if((uut.ClkGen.Rst | ~uut.ClkGen.nRst))
349
        cycle_cnt = 0;
350
    else if(Phi1O & uut.C4)
351
        cycle_cnt = ((A == 16'h0400) ? 1 : (cycle_cnt + 1));
352
end
353
 
354
always @(posedge uut.ClkGen.Clk)
355
begin
356
    if((uut.ClkGen.Rst | ~uut.ClkGen.nRst))
357
        instr_cnt = 0;
358
    else if(Sync & Phi1O & uut.C4)
359
        instr_cnt = ((A == 16'h0400) ? 1 : (instr_cnt + 1));
360
end
361
 
362
//  Perform Instruction Histogramming for coverage puposes
363
 
364
always @(posedge uut.ClkGen.Clk)
365
begin
366
//    $fstrobe(SV_Output, "%b, %b, %b, %h, %b, %b, %h, %b, %b, %b, %h, %b, %h, %h, %h, %h, %h, %h, %h, %h, %h, %h, %h, %h",
367
//             IRQ_Msk, Sim_Int, Int, Vector, Done, SC, Mode, RMW, IntSvc, Rdy, IO_Op, Ref_Ack, AO, DI, DO, A, X, Y, S, P, PC, IR, OP1, OP2);
368
 
369
    if(~(uut.ClkGen.Rst | ~uut.ClkGen.nRst)) begin
370
        if(Sync & Phi2O & uut.C3) begin
371
            if((A == 16'h0400)) begin
372
                if((Loop_Start == 1)) begin
373
                    for(i = 0; i < 16; i = i + 1)
374
                        for(j = 0; j < 16; j = j + 1) begin
375
                            val = Hist[(j * 16) + i];
376
                            Hist[(j * 16) + i] = 0;
377
                            if((j == 0))
378
                                $fwrite(Hist_File, "\n%h : %h", ((j * 16) + i), val);
379
                            else
380
                                $fwrite(Hist_File, " %h", val);
381
                        end
382
                    $fclose(Hist_File);
383
//                    $fclose(SV_Output);
384
 
385
                    $display("\nTest Loop Complete\n");
386
 
387
//                    $stop;
388
                end else begin
389
                    Loop_Start = 1;
390
                end
391
            end
392
            val      = Hist[DB];
393
            Hist[DB] = val + 1;
394
        end
395
    end
396
end
397
 
398
////  Test Monitor System Function
399
//
400
//always @(posedge Phi1O)
401
//begin
402
//    $monitor("%b, %b, %b, %h, %b, %b, %h, %b, %b, %b, %h, %b, %h, %h, %h, %h, %h, %h, %h, %h, %h, %h, %h, %h",
403
//             IRQ_Msk, Sim_Int, Int, Vector, Done, SC, Mode, RMW, IntSvc, Rdy, IO_Op, Ref_Ack, AO, DI, DO, A, X, Y, S, P, PC, IR, OP1, OP2);
404
//end
405
 
406
endmodule
407
 

powered by: WebSVN 2.1.0

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