URL
https://opencores.org/ocsvn/tms1000/tms1000/trunk
Subversion Repositories tms1000
[/] [tms1000/] [trunk/] [sr16/] [tms1000_tb.v] - Rev 3
Compare with Previous | Blame | View Log
// This file is part of TMS1000 CPU // // tms1000_tb.v - Testbench for the TMS1000 processor // Simulates SR16 calculator // Written By - Nand Gates (2021) // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) any // later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // In other words, you are welcome to use, share and improve this program. // You are forbidden to forbid anyone else to use, share and improve // what you give them. Help stamp out software-hoarding! module tms1000_tb(); /*AUTOREGINPUT*/ // Beginning of automatic reg inputs (for undeclared instantiated-module inputs) reg clk; // To tms1000 of tms1000.v tri0 [3:0] k; // To tms1000 of tms1000.v reg reset_n; // To tms1000 of tms1000.v // End of automatics /*AUTOWIRE*/ // Beginning of automatic wires (for undeclared instantiated-module outputs) wire [7:0] q; // From tms1000 of tms1000.v wire [12:0] r; // From tms1000 of tms1000.v // End of automatics parameter key_0 = 5'h00; parameter key_1 = 5'h01; parameter key_2 = 5'h02; parameter key_3 = 5'h03; parameter key_4 = 5'h04; parameter key_5 = 5'h05; parameter key_6 = 5'h06; parameter key_7 = 5'h07; parameter key_8 = 5'h08; parameter key_9 = 5'h09; parameter key_c = 5'h0a; parameter key_ce = 5'h0b; parameter key_eq = 5'h0c; parameter key_plus = 5'h0d; parameter key_minus = 5'h0e; parameter key_mul = 5'h0f; parameter key_div = 5'h10; parameter key_sum = 5'h11; parameter key_1byx = 5'h12; parameter key_x2 = 5'h13; parameter key_10x = 5'h14; parameter key_sqrt = 5'h15; parameter key_log = 5'h16; parameter key_lnx = 5'h17; parameter key_ex = 5'h18; parameter key_ee = 5'h19; parameter key_yx = 5'h1a; parameter key_rcl = 5'h1b; parameter key_sto = 5'h1c; parameter key_plmi = 5'h1d; parameter key_dp = 5'h1e; reg key0 ; reg key1 ; reg key2 ; reg key3 ; reg key4 ; reg key5 ; reg key6 ; reg key7 ; reg key8 ; reg key9 ; reg keyclk ; reg keyc ; reg keyeq ; reg keyplus ; reg keyminus ; reg keymul ; reg keydiv ; reg keysum ; reg key1byx ; reg keyx2 ; reg key10x ; reg keysqrt ; reg keylog ; reg keylnx ; reg keyex ; reg keyee ; reg keyce ; reg keyyx ; reg keyrcl ; reg keysto ; reg keyplmi ; reg keydp ; reg clk_60; integer count; reg [7:0]d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12; tms1000 tms1000(/*AUTOINST*/ // Outputs .r (r[12:0]), .q (q[7:0]), // Inputs .clk (clk), .reset_n (reset_n), .k (k[3:0])); bufif1 buf0 (k[3], key0 , r[0]); bufif1 buf1 (k[3], key1 , r[1]); bufif1 buf2 (k[3], key2 , r[2]); bufif1 buf3 (k[3], key3 , r[3]); bufif1 buf4 (k[3], key4 , r[4]); bufif1 buf5 (k[3], key5 , r[5]); bufif1 buf6 (k[3], key6 , r[6]); bufif1 buf7 (k[3], key7 , r[7]); bufif1 buf8 (k[3], key8 , r[8]); bufif1 buf9 (k[3], key9 , r[9]); bufif1 buf10(k[2], keyrcl , r[0]); bufif1 buf11(k[2], keyce , r[1]); bufif1 buf12(k[2], keyplmi , r[2]); bufif1 buf13(k[2], keydp , r[3]); bufif1 buf14(k[2], keyee , r[4]); bufif1 buf15(k[2], keysto , r[5]); bufif1 buf16(k[2], keyyx , r[6]); bufif1 buf17(k[2], keyex , r[8]); bufif1 buf18(k[2], keylnx , r[10]); bufif1 buf19(k[1], keyminus, r[0]); bufif1 buf20(k[1], keyplus , r[1]); bufif1 buf21(k[1], keymul , r[2]); bufif1 buf22(k[1], keydiv , r[3]); bufif1 buf23(k[1], keyeq , r[4]); bufif1 buf24(k[1], keysum , r[5]); bufif1 buf25(k[1], key1byx , r[6]); bufif1 buf26(k[1], keyx2 , r[7]); bufif1 buf27(k[1], key10x , r[8]); bufif1 buf28(k[1], keysqrt , r[9]); bufif1 buf29(k[1], keylog , r[10]); bufif1 buf30(k[0], keyc ,r[10]); task do_key; input [4:0] key; begin case (key) key_0 : begin key0 = 1'b1 ; #25000; key0 = 1'b0; end key_1 : begin key1 = 1'b1 ; #25000; key1 = 1'b0; end key_2 : begin key2 = 1'b1 ; #25000; key2 = 1'b0; end key_3 : begin key3 = 1'b1 ; #25000; key3 = 1'b0; end key_4 : begin key4 = 1'b1 ; #25000; key4 = 1'b0; end key_5 : begin key5 = 1'b1 ; #25000; key5 = 1'b0; end key_6 : begin key6 = 1'b1 ; #25000; key6 = 1'b0; end key_7 : begin key7 = 1'b1 ; #25000; key7 = 1'b0; end key_8 : begin key8 = 1'b1 ; #25000; key8 = 1'b0; end key_9 : begin key9 = 1'b1 ; #25000; key9 = 1'b0; end key_c : begin keyc = 1'b1 ; #25000; keyc = 1'b0; end key_ce : begin keyce = 1'b1 ; #25000; keyce = 1'b0; end key_eq : begin keyeq = 1'b1 ; #25000; keyeq = 1'b0; end key_plus : begin keyplus = 1'b1 ; #25000; keyplus = 1'b0; end key_minus : begin keyminus= 1'b1 ; #25000; keyminus= 1'b0; end key_mul : begin keymul = 1'b1 ; #25000; keymul = 1'b0; end key_div : begin keydiv = 1'b1 ; #25000; keydiv = 1'b0; end key_rcl : begin keyrcl = 1'b1 ; #25000; keyrcl = 1'b0; end key_plmi : begin keyplmi = 1'b1 ; #25000; keyplmi = 1'b0; end key_dp : begin keydp = 1'b1 ; #25000; keydp = 1'b0; end key_ee : begin keyee = 1'b1 ; #25000; keyee = 1'b0; end key_sto : begin keysto = 1'b1 ; #25000; keysto = 1'b0; end key_yx : begin keyyx = 1'b1 ; #25000; keyyx = 1'b0; end key_ex : begin keyex = 1'b1 ; #25000; keyex = 1'b0; end key_lnx : begin keylnx = 1'b1 ; #25000; keylnx = 1'b0; end key_sum : begin keysum = 1'b1 ; #25000; keysum = 1'b0; end key_1byx : begin key1byx = 1'b1 ; #25000; key1byx = 1'b0; end key_x2 : begin keyx2 = 1'b1 ; #25000; keyx2 = 1'b0; end key_10x : begin key10x = 1'b1 ; #25000; key10x = 1'b0; end key_sqrt : begin keysqrt = 1'b1 ; #25000; keysqrt = 1'b0; end key_log : begin keylog = 1'b1 ; #25000; keylog = 1'b0; end endcase // case(key) end endtask // do_key initial begin clk = 0; key0 = 0; key1 = 0; key2 = 0; key3 = 0; key4 = 0; key5 = 0; key6 = 0; key7 = 0; key8 = 0; key9 = 0; keyc = 0; keyce = 0; keyeq = 0; keyplus = 0; keyminus = 0; keymul = 0; keydiv = 0; keyrcl = 1'b0; keyplmi = 1'b0; keyee = 1'b0; keysto = 1'b0; keyyx = 1'b0; keyex = 1'b0; keylnx = 1'b0; keysum = 1'b0; key1byx = 1'b0; keyx2 = 1'b0; key10x = 1'b0; keysqrt = 1'b0; keylog = 1'b0; keydp = 1'b0; clk_60 = 0; count = 0; d0 = 0; d1 = 0; d2 = 0; d3 = 0; d4 = 0; d5 = 0; d6 = 0; d7 = 0; d8 = 0; d9 = 0; d10 = 0; d11 = 0; d12 = 0; reset_n = 0; #33 reset_n = 1; /* -----\/----- EXCLUDED -----\/----- #88000; do_key(key_3); #28000; do_key(key_minus); #28000; do_key(key_1); #28000; do_key(key_eq); #28000; $display("Xreg_0 = %h",tms1000_tb.tms1000.ram.Xreg_0[63:0]); $display("Xreg_1 = %h",tms1000_tb.tms1000.ram.Xreg_1[63:0]); $display("Xreg_2 = %h",tms1000_tb.tms1000.ram.Xreg_2[63:0]); $display("Xreg_3 = %h",tms1000_tb.tms1000.ram.Xreg_3[63:0]); $finish; -----/\----- EXCLUDED -----/\----- */ /* -----\/----- EXCLUDED -----\/----- do_key(key_1); #28000; do_key(key_2); #28000; do_key(key_3); #28000; do_key(key_4); #28000; do_key(key_5); #28000; do_key(key_6); #28000; do_key(key_7); #28000; do_key(key_8); #28000; do_key(key_9); -----/\----- EXCLUDED -----/\----- */ /* -----\/----- EXCLUDED -----\/----- do_key(key_4); #28000; do_key(key_ent); #28000; do_key(key_2); #28000; do_key(key_minus/-*key_plus key_mul*-/); #80000; $display("Xreg_0 = %h",tms1000_tb.tms1000.ram.Xreg_0[63:0]); $display("Xreg_1 = %h",tms1000_tb.tms1000.ram.Xreg_1[63:0]); $display("Xreg_2 = %h",tms1000_tb.tms1000.ram.Xreg_2[63:0]); $display("Xreg_3 = %h",tms1000_tb.tms1000.ram.Xreg_3[63:0]); $finish; -----/\----- EXCLUDED -----/\----- */ end // initial begin always @(r) begin case (1'b1) r[0] : d0 = q; r[1] : d1 = q; r[2] : d2 = q; r[3] : d3 = q; r[4] : d4 = q; r[5] : d5 = q; r[6] : d6 = q; r[7] : d7 = q; r[8] : d8 = q; r[9] : d9 = q; r[10] : d10 = q; r[11] : d11 = q; r[12] : d12 = q; endcase end always #5 clk = ~clk; always @(posedge clk) if (count == 1000) begin clk_60 <= ~clk_60; count <= 0; end else count <= count + 1; endmodule // tms1000_tb