OpenCores
URL https://opencores.org/ocsvn/mcs-4/mcs-4/trunk

Subversion Repositories mcs-4

[/] [mcs-4/] [trunk/] [rtl/] [verilog/] [i4004/] [i4004_tb.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 rrpollack
`timescale 1ns / 1ps
2
`default_nettype none
3
////////////////////////////////////////////////////////////////////////
4
//
5
// MCS-4 i4004 CPU testbench
6
//
7
// This module is a testbench for the i4004 and related modules.
8
//
9
// This testbench instantiates an i4004 CPU module, i4001 and
10
// i4001_rom ROM modules, and an i4002 RAM module, so that the
11
// simulation can be compared with that of Lagos Kintle's software
12
// emulator.
13
//
14
// This file is part of the MCS-4 project hosted at OpenCores:
15
//      http://www.opencores.org/cores/mcs-4/
16
//
17
// Copyright © 2021 by Reece Pollack <rrpollack@opencores.org>
18
//
19
// These materials are provided under the Creative Commons
20
// "Attribution-NonCommercial-ShareAlike" (CC BY-NC-SA) Public License.
21
// They are NOT "public domain", and are protected by copyright.
22
//
23
// This work based on materials provided by Intel Corporation and
24
// others under the same license. See the file doc/License for
25
// details of this license.
26
//
27
////////////////////////////////////////////////////////////////////////
28
 
29
module i4004_tb;
30
 
31
    localparam SYSCLK_TCY = 50;     // 20 MHz Oscillator period in ns
32
    // localparam SYSCLK_TCY = 20;     // 50 MHz Oscillator period in ns
33
 
34
    // Inputs
35
    reg         sysclk    = 1'b0;
36
    reg         poc_pad   = 1'b1;
37
    reg         test_pad  = 1'b1;
38
    reg         clear_pad = 1'b0;
39
    wire        clk1_pad;
40
    wire        clk2_pad;
41
 
42
    // Outputs
43
    wire        cmrom_pad;
44
    wire        cmram0_pad;
45
    wire        cmram1_pad;
46
    wire        cmram2_pad;
47
    wire        cmram3_pad;
48
    wire        sync_pad;
49
 
50
    // Bidirs
51
    wire [3:0]  data_pad;
52
    wire [3:0]  io_pad;
53
 
54
    // Generate a system clock
55
    always begin
56
        sysclk = 1'b0;
57
        #(SYSCLK_TCY / 2);
58
        sysclk = 1'b1;
59
        #(SYSCLK_TCY / 2);
60
    end
61
 
62
    // Instantiate the 2-phase clock generator
63
    clockgen #(
64
        .SYSCLK_TCY (SYSCLK_TCY)
65
    ) clockgen (
66
        .sysclk     (sysclk),
67
        .clk1       (clk1_pad),
68
        .clk2       (clk2_pad)
69
    );
70
 
71
    // Instantiate a 4001 ROM chip
72
    wire [11:0] rom_addr;
73
    wire [ 7:0] rom_data;
74
    i4001 #(
75
        .ROM_NUMBER(4'd0),
76
        .IO_OUTPUT(4'b1111)
77
    ) rom_0 (
78
        .sysclk(sysclk),
79
        .clk1_pad(clk1_pad),
80
        .clk2_pad(clk2_pad),
81
        .sync_pad(sync_pad),
82
        .poc_pad(poc_pad),
83
        .cmrom_pad(cmrom_pad),
84
        .data_pad(data_pad),
85
        .io_pad(io_pad),
86
        .clear_pad(clear_pad),
87
        .rom_addr(rom_addr),
88
        .rom_data(rom_data)
89
    );
90
 
91
    i4001_rom #(
92
        .ROM_NUMBER(4'd0)
93
    ) rom_store (
94
        .sysclk(sysclk),
95
        .rom_addr(rom_addr),
96
        .rom_data(rom_data)
97
    );
98
 
99
    // Instantiate a 4002 RAM chip
100
    wire [3:0]  oport;
101
    i4002 ram_0 (
102
        .sysclk         (sysclk),
103
        .clk1           (clk1_pad),
104
        .clk2           (clk2_pad),
105
        .sync           (sync_pad),
106
        .reset          (poc_pad),
107
        .cm             (cmram0_pad),
108
        .data           (data_pad),
109
        .oport          (oport),
110
        .ram0_addr2     (5'h00),
111
        .ram0_data2_out (),
112
        .ram1_addr2     (5'h00),
113
        .ram1_data2_out (),
114
        .ram2_addr2     (5'h00),
115
        .ram2_data2_out (),
116
        .ram3_addr2     (5'h00),
117
        .ram3_data2_out ()
118
    );
119
 
120
    // Instantiate the Unit Under Test (UUT)
121
    i4004 i4004 (
122
        .clk1_pad(clk1_pad),
123
        .clk2_pad(clk2_pad),
124
        .poc_pad(poc_pad),
125
        .test_pad(test_pad),
126
        .data_pad(data_pad),
127
        .cmrom_pad(cmrom_pad),
128
        .cmram0_pad(cmram0_pad),
129
        .cmram1_pad(cmram1_pad),
130
        .cmram2_pad(cmram2_pad),
131
        .cmram3_pad(cmram3_pad),
132
        .sync_pad(sync_pad)
133
    );
134
 
135
    // Simplify access to internal registers
136
    wire  [3:0] acc  = i4004.alu_board.acc;
137
    wire        cy   = i4004.alu_board.cy;
138
 
139
    wire  [7:0] r0r1 = i4004.sp_board.dram_array[0];
140
    wire  [7:0] r2r3 = i4004.sp_board.dram_array[1];
141
    wire  [7:0] r4r5 = i4004.sp_board.dram_array[2];
142
    wire  [7:0] r6r7 = i4004.sp_board.dram_array[3];
143
    wire  [7:0] r8r9 = i4004.sp_board.dram_array[4];
144
    wire  [7:0] rarb = i4004.sp_board.dram_array[5];
145
    wire  [7:0] rcrd = i4004.sp_board.dram_array[6];
146
    wire  [7:0] rerf = i4004.sp_board.dram_array[7];
147
 
148
    wire [11:0] ip0  = i4004.ip_board.dram_array[0];
149
    wire [11:0] ip1  = i4004.ip_board.dram_array[1];
150
    wire [11:0] ip2  = i4004.ip_board.dram_array[2];
151
    wire [11:0] ip3  = i4004.ip_board.dram_array[3];
152
    wire  [1:0] ptr  = i4004.ip_board.addr_ptr;
153
 
154
    // Count cycles to make it easier to sync with the analyzer
155
    integer     cycle = 1;
156
    always @(posedge clk1_pad or negedge clk1_pad or
157
             posedge clk2_pad or negedge clk2_pad) begin
158
        cycle = cycle + 1;
159
        if (cycle == 1100) begin
160
            // Bring us out of reset
161
            poc_pad = 1'b0;
162
        end
163
    end
164
 
165
    // initial begin
166
    //     // Wait for 33 SYNCs to allow the i4002 RAMs to initialize
167
    //     repeat (33)
168
    //         @(posedge sync_pad);
169
 
170
    //     // Bring us out of reset
171
    //     poc_pad = 1'b0;
172
    // end
173
 
174
endmodule

powered by: WebSVN 2.1.0

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