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

Subversion Repositories tms1000

[/] [tms1000/] [trunk/] [sr16/] [tms1000_tb.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 3 nand_gates
// This file is part of TMS1000 CPU
2
// 
3
// tms1000_tb.v -  Testbench for the TMS1000 processor
4
//                 Simulates SR16 calculator
5
// Written By -  Nand Gates (2021)
6
//
7
// This program is free software; you can redistribute it and/or modify it
8
// under the terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 2, or (at your option) any
10
// later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
//
17
// In other words, you are welcome to use, share and improve this program.
18
// You are forbidden to forbid anyone else to use, share and improve
19
// what you give them.   Help stamp out software-hoarding!
20
 
21
module tms1000_tb();
22
   /*AUTOREGINPUT*/
23
   // Beginning of automatic reg inputs (for undeclared instantiated-module inputs)
24
   reg        clk;                    // To tms1000 of tms1000.v
25
   tri0 [3:0] k;                      // To tms1000 of tms1000.v
26
   reg        reset_n;                // To tms1000 of tms1000.v
27
   // End of automatics
28
   /*AUTOWIRE*/
29
   // Beginning of automatic wires (for undeclared instantiated-module outputs)
30
   wire [7:0] q;                      // From tms1000 of tms1000.v
31
   wire [12:0] r;                      // From tms1000 of tms1000.v
32
   // End of automatics
33
   parameter  key_0 = 5'h00;
34
   parameter  key_1 = 5'h01;
35
   parameter  key_2 = 5'h02;
36
   parameter  key_3 = 5'h03;
37
   parameter  key_4 = 5'h04;
38
   parameter  key_5 = 5'h05;
39
   parameter  key_6 = 5'h06;
40
   parameter  key_7 = 5'h07;
41
   parameter  key_8 = 5'h08;
42
   parameter  key_9 = 5'h09;
43
   parameter  key_c   = 5'h0a;
44
   parameter  key_ce    = 5'h0b;
45
   parameter  key_eq    = 5'h0c;
46
   parameter  key_plus  = 5'h0d;
47
   parameter  key_minus = 5'h0e;
48
   parameter  key_mul   = 5'h0f;
49
   parameter  key_div   = 5'h10;
50
 
51
   parameter  key_sum   = 5'h11;
52
   parameter  key_1byx  = 5'h12;
53
   parameter  key_x2    = 5'h13;
54
   parameter  key_10x   = 5'h14;
55
   parameter  key_sqrt  = 5'h15;
56
   parameter  key_log   = 5'h16;
57
   parameter  key_lnx   = 5'h17;
58
   parameter  key_ex    = 5'h18;
59
   parameter  key_ee    = 5'h19;
60
   parameter  key_yx    = 5'h1a;
61
   parameter  key_rcl   = 5'h1b;
62
   parameter  key_sto   = 5'h1c;
63
   parameter  key_plmi  = 5'h1d;
64
   parameter  key_dp    = 5'h1e;
65
 
66
   reg key0     ;
67
   reg key1     ;
68
   reg key2     ;
69
   reg key3     ;
70
   reg key4     ;
71
   reg key5     ;
72
   reg key6     ;
73
   reg key7     ;
74
   reg key8     ;
75
   reg key9     ;
76
   reg keyclk   ;
77
   reg keyc     ;
78
   reg keyeq   ;
79
   reg keyplus  ;
80
   reg keyminus ;
81
   reg keymul   ;
82
   reg keydiv   ;
83
   reg keysum   ;
84
   reg key1byx  ;
85
   reg keyx2    ;
86
   reg key10x   ;
87
   reg keysqrt  ;
88
   reg keylog   ;
89
   reg keylnx   ;
90
   reg keyex    ;
91
   reg keyee    ;
92
   reg keyce    ;
93
   reg keyyx    ;
94
   reg keyrcl   ;
95
   reg keysto   ;
96
   reg keyplmi  ;
97
   reg keydp  ;
98
   reg clk_60;
99
   integer     count;
100
 
101
   reg [7:0]d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12;
102
 
103
   tms1000 tms1000(/*AUTOINST*/
104
                   // Outputs
105
                   .r           (r[12:0]),
106
                   .q           (q[7:0]),
107
                   // Inputs
108
                   .clk         (clk),
109
                   .reset_n     (reset_n),
110
                   .k           (k[3:0]));
111
 
112
   bufif1 buf0 (k[3], key0    , r[0]);
113
   bufif1 buf1 (k[3], key1    , r[1]);
114
   bufif1 buf2 (k[3], key2    , r[2]);
115
   bufif1 buf3 (k[3], key3    , r[3]);
116
   bufif1 buf4 (k[3], key4    , r[4]);
117
   bufif1 buf5 (k[3], key5    , r[5]);
118
   bufif1 buf6 (k[3], key6    , r[6]);
119
   bufif1 buf7 (k[3], key7    , r[7]);
120
   bufif1 buf8 (k[3], key8    , r[8]);
121
   bufif1 buf9 (k[3], key9    , r[9]);
122
 
123
   bufif1 buf10(k[2], keyrcl  , r[0]);
124
   bufif1 buf11(k[2], keyce   , r[1]);
125
   bufif1 buf12(k[2], keyplmi , r[2]);
126
   bufif1 buf13(k[2], keydp   , r[3]);
127
   bufif1 buf14(k[2], keyee   , r[4]);
128
   bufif1 buf15(k[2], keysto  , r[5]);
129
   bufif1 buf16(k[2], keyyx   , r[6]);
130
   bufif1 buf17(k[2], keyex   , r[8]);
131
   bufif1 buf18(k[2], keylnx  , r[10]);
132
 
133
   bufif1 buf19(k[1], keyminus, r[0]);
134
   bufif1 buf20(k[1], keyplus , r[1]);
135
   bufif1 buf21(k[1], keymul  , r[2]);
136
   bufif1 buf22(k[1], keydiv  , r[3]);
137
   bufif1 buf23(k[1], keyeq   , r[4]);
138
   bufif1 buf24(k[1], keysum  , r[5]);
139
   bufif1 buf25(k[1], key1byx , r[6]);
140
   bufif1 buf26(k[1], keyx2   , r[7]);
141
   bufif1 buf27(k[1], key10x  , r[8]);
142
   bufif1 buf28(k[1], keysqrt , r[9]);
143
   bufif1 buf29(k[1], keylog  , r[10]);
144
 
145
   bufif1 buf30(k[0], keyc ,r[10]);
146
 
147
   task do_key;
148
      input [4:0] key;
149
      begin
150
         case (key)
151
           key_0     : begin key0    = 1'b1 ; #25000; key0    = 1'b0; end
152
           key_1     : begin key1    = 1'b1 ; #25000; key1    = 1'b0; end
153
           key_2     : begin key2    = 1'b1 ; #25000; key2    = 1'b0; end
154
           key_3     : begin key3    = 1'b1 ; #25000; key3    = 1'b0; end
155
           key_4     : begin key4    = 1'b1 ; #25000; key4    = 1'b0; end
156
           key_5     : begin key5    = 1'b1 ; #25000; key5    = 1'b0; end
157
           key_6     : begin key6    = 1'b1 ; #25000; key6    = 1'b0; end
158
           key_7     : begin key7    = 1'b1 ; #25000; key7    = 1'b0; end
159
           key_8     : begin key8    = 1'b1 ; #25000; key8    = 1'b0; end
160
           key_9     : begin key9    = 1'b1 ; #25000; key9    = 1'b0; end
161
           key_c     : begin keyc    = 1'b1 ; #25000; keyc    = 1'b0; end
162
           key_ce    : begin keyce   = 1'b1 ; #25000; keyce   = 1'b0; end
163
           key_eq    : begin keyeq   = 1'b1 ; #25000; keyeq   = 1'b0; end
164
           key_plus  : begin keyplus = 1'b1 ; #25000; keyplus = 1'b0; end
165
           key_minus : begin keyminus= 1'b1 ; #25000; keyminus= 1'b0; end
166
           key_mul   : begin keymul  = 1'b1 ; #25000; keymul  = 1'b0; end
167
           key_div   : begin keydiv  = 1'b1 ; #25000; keydiv  = 1'b0; end
168
           key_rcl  : begin keyrcl  = 1'b1 ; #25000;  keyrcl   = 1'b0; end
169
           key_plmi : begin keyplmi = 1'b1 ; #25000;  keyplmi  = 1'b0; end
170
           key_dp   : begin keydp   = 1'b1 ; #25000;  keydp    = 1'b0; end
171
           key_ee   : begin keyee   = 1'b1 ; #25000;  keyee    = 1'b0; end
172
           key_sto  : begin keysto  = 1'b1 ; #25000;  keysto   = 1'b0; end
173
           key_yx   : begin keyyx   = 1'b1 ; #25000;  keyyx    = 1'b0; end
174
           key_ex   : begin keyex   = 1'b1 ; #25000;  keyex    = 1'b0; end
175
           key_lnx  : begin keylnx  = 1'b1 ; #25000;  keylnx   = 1'b0; end
176
           key_sum  : begin keysum  = 1'b1 ; #25000;  keysum   = 1'b0; end
177
           key_1byx : begin key1byx = 1'b1 ; #25000;  key1byx  = 1'b0; end
178
           key_x2   : begin keyx2   = 1'b1 ; #25000;  keyx2    = 1'b0; end
179
           key_10x  : begin key10x  = 1'b1 ; #25000;  key10x   = 1'b0; end
180
           key_sqrt : begin keysqrt = 1'b1 ; #25000;  keysqrt  = 1'b0; end
181
           key_log  : begin keylog  = 1'b1 ; #25000;  keylog   = 1'b0; end
182
         endcase // case(key)
183
      end
184
   endtask // do_key
185
 
186
   initial begin
187
      clk = 0;
188
      key0     = 0;
189
      key1     = 0;
190
      key2     = 0;
191
      key3     = 0;
192
      key4     = 0;
193
      key5     = 0;
194
      key6     = 0;
195
      key7     = 0;
196
      key8     = 0;
197
      key9     = 0;
198
      keyc     = 0;
199
      keyce    = 0;
200
      keyeq    = 0;
201
      keyplus  = 0;
202
      keyminus = 0;
203
      keymul   = 0;
204
      keydiv   = 0;
205
 
206
      keyrcl   = 1'b0;
207
      keyplmi  = 1'b0;
208
      keyee    = 1'b0;
209
      keysto   = 1'b0;
210
      keyyx    = 1'b0;
211
      keyex    = 1'b0;
212
      keylnx   = 1'b0;
213
      keysum   = 1'b0;
214
      key1byx  = 1'b0;
215
      keyx2    = 1'b0;
216
      key10x   = 1'b0;
217
      keysqrt  = 1'b0;
218
      keylog   = 1'b0;
219
      keydp    = 1'b0;
220
 
221
      clk_60 = 0;
222
      count = 0;
223
 
224
      d0 = 0;
225
      d1 = 0;
226
      d2 = 0;
227
      d3 = 0;
228
      d4 = 0;
229
      d5 = 0;
230
      d6 = 0;
231
      d7 = 0;
232
      d8 = 0;
233
      d9 = 0;
234
      d10 = 0;
235
      d11 = 0;
236
      d12 = 0;
237
 
238
      reset_n = 0;
239
      #33 reset_n = 1;
240
/* -----\/----- EXCLUDED -----\/-----
241
      #88000;
242
      do_key(key_3);
243
      #28000;
244
      do_key(key_minus);
245
      #28000;
246
      do_key(key_1);
247
      #28000;
248
      do_key(key_eq);
249
      #28000;
250
      $display("Xreg_0 = %h",tms1000_tb.tms1000.ram.Xreg_0[63:0]);
251
      $display("Xreg_1 = %h",tms1000_tb.tms1000.ram.Xreg_1[63:0]);
252
      $display("Xreg_2 = %h",tms1000_tb.tms1000.ram.Xreg_2[63:0]);
253
      $display("Xreg_3 = %h",tms1000_tb.tms1000.ram.Xreg_3[63:0]);
254
      $finish;
255
 -----/\----- EXCLUDED -----/\----- */
256
/* -----\/----- EXCLUDED -----\/-----
257
       do_key(key_1);
258
       #28000;
259
       do_key(key_2);
260
       #28000;
261
       do_key(key_3);
262
       #28000;
263
       do_key(key_4);
264
       #28000;
265
       do_key(key_5);
266
       #28000;
267
       do_key(key_6);
268
       #28000;
269
       do_key(key_7);
270
       #28000;
271
       do_key(key_8);
272
       #28000;
273
       do_key(key_9);
274
 
275
 -----/\----- EXCLUDED -----/\----- */
276
/* -----\/----- EXCLUDED -----\/-----
277
         do_key(key_4);
278
         #28000;
279
         do_key(key_ent);
280
         #28000;
281
         do_key(key_2);
282
         #28000;
283
         do_key(key_minus/-*key_plus key_mul*-/);
284
        #80000;
285
        $display("Xreg_0 = %h",tms1000_tb.tms1000.ram.Xreg_0[63:0]);
286
        $display("Xreg_1 = %h",tms1000_tb.tms1000.ram.Xreg_1[63:0]);
287
        $display("Xreg_2 = %h",tms1000_tb.tms1000.ram.Xreg_2[63:0]);
288
        $display("Xreg_3 = %h",tms1000_tb.tms1000.ram.Xreg_3[63:0]);
289
        $finish;
290
 -----/\----- EXCLUDED -----/\----- */
291
   end // initial begin
292
   always @(r) begin
293
      case (1'b1)
294
        r[0] : d0 = q;
295
        r[1] : d1 = q;
296
        r[2] : d2 = q;
297
        r[3] : d3 = q;
298
        r[4] : d4 = q;
299
        r[5] : d5 = q;
300
        r[6] : d6 = q;
301
        r[7] : d7 = q;
302
        r[8] : d8 = q;
303
        r[9] : d9 = q;
304
        r[10] : d10 = q;
305
        r[11] : d11 = q;
306
        r[12] : d12 = q;
307
      endcase
308
   end
309
 
310
   always #5 clk = ~clk;
311
   always @(posedge clk)
312
     if (count == 1000) begin
313
        clk_60 <= ~clk_60;
314
        count <= 0;
315
     end else
316
        count <= count + 1;
317
 
318
endmodule // tms1000_tb

powered by: WebSVN 2.1.0

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