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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_alu_tb.v] - Blame information for rev 164

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

Line No. Rev Author Line
1 127 gabrielosh
`include "timescale.v"
2 136 gabrielosh
module t6507lp_alu_tb;
3 127 gabrielosh
 
4 136 gabrielosh
`include  "t6507lp_package.v"
5 127 gabrielosh
 
6 136 gabrielosh
reg         clk;
7 140 gabrielosh
reg         reset_n;
8 136 gabrielosh
reg         alu_enable;
9
wire [7:0]  alu_result;
10
wire [7:0]  alu_status;
11
reg  [7:0]  alu_opcode;
12
reg  [7:0]  alu_a;
13
wire [7:0]  alu_x;
14
wire [7:0]  alu_y;
15
reg  [31:0] i;
16 127 gabrielosh
 
17
reg [7:0] alu_result_expected;
18
reg [7:0] alu_status_expected;
19
reg [7:0] alu_x_expected;
20
reg [7:0] alu_y_expected;
21
 
22 164 gabrielosh
reg C_in;
23 127 gabrielosh
reg [7:0] temp;
24 156 gabrielosh
reg sign;
25 164 gabrielosh
reg [3:0] AL;
26
reg [3:0] AH;
27
reg [3:0] BL;
28
reg [3:0] BH;
29
reg [7:0] alu_result_expected_temp;
30 127 gabrielosh
 
31 136 gabrielosh
t6507lp_alu DUT (
32
                        .clk            (clk),
33
                        .reset_n        (reset_n),
34 127 gabrielosh
                        .alu_enable     (alu_enable),
35
                        .alu_result     (alu_result),
36
                        .alu_status     (alu_status),
37
                        .alu_opcode     (alu_opcode),
38
                        .alu_a          (alu_a),
39
                        .alu_x          (alu_x),
40
                        .alu_y          (alu_y)
41
                );
42
 
43
 
44
localparam period = 10;
45
 
46
task check;
47
        begin
48
                $display("               RESULTS       EXPECTED");
49
                $display("alu_result       %h             %h   ", alu_result, alu_result_expected);
50
                $display("alu_status    %b       %b   ", alu_status, alu_status_expected);
51
                $display("alu_x            %h             %h   ", alu_x,      alu_x_expected     );
52
                $display("alu_y            %h             %h   ", alu_y,      alu_y_expected     );
53 150 gabrielosh
                if ((alu_result_expected == alu_result) && (alu_status_expected == alu_status) && (alu_x_expected == alu_x) && (alu_y_expected == alu_y))
54 127 gabrielosh
                begin
55 150 gabrielosh
                        $display("Instruction %h... OK!", alu_opcode);
56 127 gabrielosh
                end
57
                else
58
                begin
59 150 gabrielosh
                        $display("ERROR at instruction %h",alu_opcode);
60
                        $finish;
61 127 gabrielosh
                end
62
        end
63
endtask
64
 
65
 
66
always begin
67 136 gabrielosh
        #(period/2) clk = ~clk;
68 127 gabrielosh
end
69
 
70
initial
71
begin
72
        // Reset
73 136 gabrielosh
        clk = 0;
74
        reset_n = 0;
75 140 gabrielosh
        @(negedge clk);
76 150 gabrielosh
        //@(negedge clk);
77 148 gabrielosh
        reset_n = 1;
78 127 gabrielosh
        alu_enable = 1;
79
        alu_result_expected = 8'h00;
80
        alu_status_expected = 8'b00100010;
81
        alu_x_expected = 8'h00;
82
        alu_y_expected = 8'h00;
83
 
84
        // LDA
85
        alu_a = 0;
86
        alu_opcode = LDA_IMM;
87
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
88
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
89 140 gabrielosh
        @(negedge clk);
90 127 gabrielosh
        alu_result_expected = 8'h00;
91
        //                       NV1BDIZC
92 149 gabrielosh
    alu_status_expected = 8'b00100010;
93 127 gabrielosh
        check();
94
 
95
        // ADC
96
        alu_opcode = ADC_IMM;
97
        alu_a = 1;
98
        for (i = 0; i < 1000; i = i + 1)
99
        begin
100 149 gabrielosh
                alu_a = $random;
101 140 gabrielosh
                @(negedge clk);
102 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
103
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
104
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], DUT.result);
105 156 gabrielosh
                sign = alu_result_expected[7];
106 127 gabrielosh
                {alu_status_expected[C], alu_result_expected} = alu_a + alu_result_expected + alu_status_expected[C];
107
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
108
                alu_status_expected[N] = alu_result_expected[7];
109 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
110 127 gabrielosh
                check();
111
        end
112
 
113 164 gabrielosh
        // BCD
114 161 gabrielosh
        // LDA
115
        alu_a = 0;
116
        alu_opcode = LDA_IMM;
117
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
118
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
119
        @(negedge clk);
120
        alu_result_expected = 8'h00;
121
        //                       NV1BDIZC
122 164 gabrielosh
        alu_status_expected[N] = 0;
123
        alu_status_expected[Z] = 1;
124 161 gabrielosh
        check();
125 164 gabrielosh
        // SED
126
        alu_opcode = SED_IMP;
127
        @(negedge clk);
128
        alu_status_expected[D] = 1;
129
        check();
130 161 gabrielosh
 
131
        // ADC
132
        alu_opcode = ADC_IMM;
133
        for (i = 0; i < 1000; i = i + 1)
134
        begin
135
                alu_a = $random;
136
                @(negedge clk);
137 164 gabrielosh
                $display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
138
                $display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
139
                $display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], DUT.result);
140 161 gabrielosh
                sign = alu_result_expected[7];
141 164 gabrielosh
                AL = alu_a[3:0];
142
                AH = alu_a[7:4];
143
                BL = alu_result_expected[3:0];
144
                BH = alu_result_expected[7:4];
145
                if ( AL > 9 ) begin
146
                        AL = AL - 10;
147
                        AH = AH + 1;
148
                end
149
                if (AH > 9) begin
150
                        AH = AH - 10;
151
                end
152
                if ( BL > 9 ) begin
153
                        BL = BL - 10;
154
                        BH = BH + 1;
155
                end
156
                if ( BH > 9 ) begin
157
                        BH = BH - 10;
158
                end
159
                {C_in,alu_result_expected_temp[3:0]} = AL + BL + alu_status_expected[C];
160
                {alu_status_expected[C],alu_result_expected_temp[7:4]} = AH + BH + C_in;
161
                if ( alu_result_expected_temp[3:0] > 9 ) begin
162
                        alu_result_expected[3:0] = alu_result_expected_temp[3:0] - 10;
163
                        alu_result_expected[7:4] = alu_result_expected_temp[7:4] + 1;
164
                end
165
                if ( alu_result_expected_temp[7:4] > 9 ) begin
166
                        alu_result_expected[7:4] = alu_result_expected_temp[7:4] - 10;
167
                end
168 161 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
169
                alu_status_expected[N] = alu_result_expected[7];
170
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
171
                check();
172
        end
173 164 gabrielosh
 
174 161 gabrielosh
 
175 148 gabrielosh
        // ASL
176 145 gabrielosh
        alu_opcode = ASL_ABS;
177
        for (i = 0; i < 1000; i = i + 1)
178
        begin
179
                alu_a = i;
180
                @(negedge clk);
181
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
182
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
183
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
184
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
185
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
186
                alu_status_expected[N] = alu_result_expected[7];
187
                check();
188
        end
189
 
190
        // LDA
191 156 gabrielosh
        alu_a = 137;
192
        alu_opcode = LDA_IMM;
193
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
194
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
195
        @(negedge clk);
196
        alu_result_expected = 8'd137;
197
        //                       NV1BDIZC
198
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
199
        alu_status_expected[N] = alu_result_expected[7];
200
        check();
201
 
202
        // EOR
203
        alu_opcode = EOR_IMM;
204
        for (i = 0; i < 1000; i = i + 1)
205
        begin
206
                alu_a = i;
207
                @(negedge clk);
208
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
209
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
210
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
211
                $display("result_expected = %d",alu_result_expected);
212
                alu_result_expected = alu_a ^ alu_result_expected;
213
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
214
                alu_status_expected[N] = alu_result_expected[7];
215
                $display("result_expected = %d", alu_result_expected);
216
                check();
217
        end
218
 
219
        // LDA
220 145 gabrielosh
        alu_a = 0;
221
        alu_opcode = LDA_IMM;
222
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
223
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
224
        @(negedge clk);
225
        alu_result_expected = 8'h00;
226
        //                       NV1BDIZC
227
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
228
        alu_status_expected[N] = alu_result_expected[7];
229
        check();
230
 
231 127 gabrielosh
        // SBC
232
        alu_opcode = SBC_IMM;
233
        for (i = 0; i < 1000; i = i + 1)
234
        begin
235 145 gabrielosh
                alu_a = 1;
236 140 gabrielosh
                @(negedge clk);
237 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
238
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
239
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
240 156 gabrielosh
                sign = alu_result_expected[7];
241 127 gabrielosh
                {alu_status_expected[C], alu_result_expected} = alu_result_expected - alu_a - ~alu_status_expected[C];
242
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
243
                alu_status_expected[N] = alu_result_expected[7];
244 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
245 127 gabrielosh
                check();
246
        end
247
 
248
        // LDA
249
        alu_opcode = LDA_IMM;
250
        for (i = 0; i < 1000; i = i + 1)
251
        begin
252
                alu_a = i;
253 140 gabrielosh
                @(negedge clk);
254 127 gabrielosh
                alu_result_expected = i;
255
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
256
                alu_status_expected[N] = alu_result_expected[7];
257
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
258
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
259
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
260
                check();
261
        end
262
 
263
        // LDX
264
        alu_opcode = LDX_IMM;
265
        for (i = 0; i < 1000; i = i + 1)
266
        begin
267
                alu_a = i;
268 140 gabrielosh
                @(negedge clk);
269 127 gabrielosh
                alu_x_expected = i;
270
                //alu_result_expected = i;
271
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
272
                alu_status_expected[N] = alu_x_expected[7];
273
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
274
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
275
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
276
                check();
277
        end
278
 
279
        // LDY
280
        alu_opcode = LDY_IMM;
281
        for (i = 0; i < 1001; i = i + 1)
282
        begin
283
                alu_a = i;
284 140 gabrielosh
                @(negedge clk);
285 127 gabrielosh
                alu_y_expected = i;
286
                //alu_result_expected = i;
287
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
288
                alu_status_expected[N] = alu_y_expected[7];
289
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
290
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
291
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
292
                check();
293
        end
294
 
295
        // STA
296
        alu_opcode = STA_ABS;
297
        for (i = 0; i < 1000; i = i + 1)
298
        begin
299
                alu_a = i;
300 140 gabrielosh
                @(negedge clk);
301 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
302
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
303
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
304
                check();
305
        end
306
 
307
        // STX
308
        alu_opcode = STX_ABS;
309
        for (i = 0; i < 1000; i = i + 1)
310
        begin
311
                alu_a = i;
312 140 gabrielosh
                @(negedge clk);
313 127 gabrielosh
                //alu_result_expected = i;
314
                //alu_x_expected = i;
315
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
316
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
317
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
318
                check();
319
        end
320
 
321
        // STY
322
        alu_opcode = STY_ABS;
323
        for (i = 0; i < 1000; i = i + 1)
324
        begin
325
                alu_a = i;
326 140 gabrielosh
                @(negedge clk);
327 127 gabrielosh
                //alu_result_expected = i;
328
                //alu_y_expected = i;
329
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
330
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
331
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
332
                check();
333
        end
334
 
335
        // CMP
336
        alu_opcode = CMP_IMM;
337
        for (i = 0; i < 1000; i = i + 1)
338
        begin
339
                alu_a = i;
340 140 gabrielosh
                @(negedge clk);
341 127 gabrielosh
                temp = alu_result_expected - alu_a;
342
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
343
                alu_status_expected[N] = temp[7];
344
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
345
                //alu_result_expected = i;
346
                //alu_y_expected = i;
347
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
348
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
349
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
350
                check();
351
        end
352
 
353
        // CPX
354
        alu_opcode = CPX_IMM;
355
        for (i = 0; i < 1000; i = i + 1)
356
        begin
357
                alu_a = i;
358 140 gabrielosh
                @(negedge clk);
359 127 gabrielosh
                temp = alu_x_expected - alu_a;
360
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
361
                alu_status_expected[N] = temp[7];
362
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
363
                //alu_result_expected = i;
364
                //alu_y_expected = i;
365
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
366
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
367
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
368
                check();
369
        end
370
 
371
        // CPY
372
        alu_opcode = CPY_IMM;
373
        for (i = 0; i < 1000; i = i + 1)
374
        begin
375
                alu_a = i;
376 140 gabrielosh
                @(negedge clk);
377 127 gabrielosh
                temp = alu_y_expected - alu_a;
378
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
379
                alu_status_expected[N] = temp[7];
380
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
381
                //alu_result_expected = i;
382
                //alu_y_expected = i;
383
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
384
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
385
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
386
                check();
387
        end
388
 
389
 
390
        // AND
391
        alu_opcode = AND_IMM;
392
        for (i = 0; i < 1000; i = i + 1)
393
        begin
394
                alu_a = i;
395 140 gabrielosh
                @(negedge clk);
396 156 gabrielosh
                alu_result_expected = alu_a & alu_result_expected;
397 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
398
                alu_status_expected[N] = alu_result_expected[7];
399
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
400
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
401
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
402
                check();
403
        end
404
 
405
        // ASL
406
        alu_opcode = ASL_ACC;
407
        for (i = 0; i < 1000; i = i + 1)
408
        begin
409
                alu_a = i;
410 140 gabrielosh
                @(negedge clk);
411 127 gabrielosh
                alu_status_expected[C] = alu_result_expected[7];
412
                alu_result_expected[7:0] = alu_result_expected << 1;
413
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
414
                alu_status_expected[N] = alu_result_expected[7];
415
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
416
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
417
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
418
                check();
419
        end
420
 
421
        // INC
422
        alu_opcode = INC_ZPG;
423
        for (i = 0; i < 1000; i = i + 1)
424
        begin
425
                alu_a = i;
426 140 gabrielosh
                @(negedge clk);
427 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
428
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
429
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
430
                alu_result_expected = alu_a + 1;
431
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
432
                alu_status_expected[N] = alu_result_expected[7];
433
                check();
434
        end
435
 
436
        // INX
437
        alu_opcode = INX_IMP;
438
        for (i = 0; i < 1000; i = i + 1)
439
        begin
440
                alu_a = i;
441 140 gabrielosh
                @(negedge clk);
442 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
443
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
444
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
445
                alu_x_expected = alu_x_expected + 1;
446
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
447
                alu_status_expected[N] = alu_x_expected[7];
448
                check();
449
        end
450
 
451
        // INY
452
        alu_opcode = INY_IMP;
453
        for (i = 0; i < 1000; i = i + 1)
454
        begin
455
                alu_a = i;
456 140 gabrielosh
                @(negedge clk);
457 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
458
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
459
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
460
                alu_y_expected = alu_y_expected + 1;
461
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
462
                alu_status_expected[N] = alu_y_expected[7];
463
                check();
464
        end
465
 
466
        // DEC
467
        alu_opcode = DEC_ZPG;
468
        for (i = 0; i < 1000; i = i + 1)
469
        begin
470
                alu_a = i;
471 140 gabrielosh
                @(negedge clk);
472 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
473
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
474
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
475
                alu_result_expected = alu_a - 1;
476
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
477
                alu_status_expected[N] = alu_result_expected[7];
478
                check();
479
        end
480
 
481
        // DEX
482
        alu_opcode = DEX_IMP;
483
        for (i = 0; i < 1000; i = i + 1)
484
        begin
485
                alu_a = i;
486 140 gabrielosh
                @(negedge clk);
487 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
488
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
489
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
490
                alu_x_expected = alu_x_expected - 1;
491
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
492
                alu_status_expected[N] = alu_x_expected[7];
493
                check();
494
        end
495
 
496
        // DEY
497
        alu_opcode = DEY_IMP;
498
        for (i = 0; i < 1000; i = i + 1)
499
        begin
500
                alu_a = i;
501 140 gabrielosh
                @(negedge clk);
502 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
503
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
504
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
505
                alu_y_expected = alu_y_expected - 1;
506
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
507
                alu_status_expected[N] = alu_y_expected[7];
508
                check();
509
        end
510
 
511
 
512
        // LDA
513
        alu_a = 0;
514
        alu_opcode = LDA_IMM;
515
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
516
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
517 140 gabrielosh
        @(negedge clk);
518 127 gabrielosh
        alu_result_expected = 8'h00;
519
        //                       NV1BDIZC
520
        alu_status_expected = 8'b00100010;
521
        check();
522
 
523
        // BIT
524
        alu_opcode = BIT_ZPG;
525
        for (i = 0; i < 1000; i = i + 1)
526
        begin
527
                alu_a = i;
528 140 gabrielosh
                @(negedge clk);
529 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
530
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
531
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
532 127 gabrielosh
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
533
                alu_status_expected[V] = alu_a[6];
534
                alu_status_expected[N] = alu_a[7];
535
                check();
536
        end
537 158 gabrielosh
 
538
        // PHA
539
        alu_opcode = PHA_IMP;
540
        @(negedge clk);
541
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
542
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
543
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
544
        alu_result_expected = DUT.A;
545
        check();
546
 
547
        // PHP
548
        alu_opcode = PHP_IMP;
549
        @(negedge clk);
550
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
551
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
552
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
553
        alu_status_expected = DUT.STATUS;
554
        check();
555
 
556
        // BRK
557
        alu_opcode = BRK_IMP;
558
        @(negedge clk);
559
        alu_status_expected[B] = 1;
560
        check();
561
 
562 127 gabrielosh
        // SEC
563
        alu_opcode = SEC_IMP;
564 140 gabrielosh
        @(negedge clk);
565 127 gabrielosh
        alu_status_expected[C] = 1;
566
        check();
567
 
568
        // SED
569
        alu_opcode = SED_IMP;
570 140 gabrielosh
        @(negedge clk);
571 127 gabrielosh
        alu_status_expected[D] = 1;
572
        check();
573
 
574
        // SEI
575
        alu_opcode = SEI_IMP;
576 140 gabrielosh
        @(negedge clk);
577 127 gabrielosh
        alu_status_expected[I] = 1;
578
        check();
579
 
580
        // CLC
581
        alu_opcode = CLC_IMP;
582 140 gabrielosh
        @(negedge clk);
583 127 gabrielosh
        alu_status_expected[C] = 0;
584
        check();
585
 
586
        // CLD
587
        alu_opcode = CLD_IMP;
588 140 gabrielosh
        @(negedge clk);
589 127 gabrielosh
        alu_status_expected[D] = 0;
590
        check();
591
 
592
        // CLI
593
        alu_opcode = CLI_IMP;
594 140 gabrielosh
        @(negedge clk);
595 127 gabrielosh
        alu_status_expected[I] = 0;
596
        check();
597
 
598
        // CLV
599
        alu_opcode = CLV_IMP;
600 140 gabrielosh
        @(negedge clk);
601 127 gabrielosh
        alu_status_expected[V] = 0;
602
        check();
603
 
604
        // LDA
605
        alu_opcode = LDA_IMM;
606
        alu_a = 8'h76;
607 140 gabrielosh
        @(negedge clk);
608 127 gabrielosh
        alu_result_expected = alu_a;
609
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
610
        alu_status_expected[N] = alu_result_expected[7];
611
        check();
612
 
613
        // TAX
614
        alu_opcode = TAX_IMP;
615 140 gabrielosh
        @(negedge clk);
616 127 gabrielosh
        alu_x_expected = alu_result_expected;
617
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
618
        alu_status_expected[N] = alu_x_expected[7];
619
        check();
620
 
621
        // TAY
622
        alu_opcode = TAY_IMP;
623 140 gabrielosh
        @(negedge clk);
624 127 gabrielosh
        alu_y_expected = alu_result_expected;
625
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
626
        alu_status_expected[N] = alu_y_expected[7];
627
        check();
628
 
629
        // TSX
630
        alu_opcode = TSX_IMP;
631 140 gabrielosh
        @(negedge clk);
632 127 gabrielosh
        alu_x_expected = alu_a;
633
        //alu_result_expected = alu_a;
634
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
635
        alu_status_expected[N] = alu_x_expected[7];
636
        check();
637
 
638
        // TXA
639
        alu_opcode = TXA_IMP;
640 140 gabrielosh
        @(negedge clk);
641 127 gabrielosh
        alu_result_expected = alu_x_expected;
642
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
643
        alu_status_expected[N] = alu_result_expected[7];
644
        check();
645
 
646
        // TXS
647
        alu_opcode = TXS_IMP;
648 140 gabrielosh
        @(negedge clk);
649 127 gabrielosh
        alu_result_expected = alu_x_expected;
650
        check();
651
 
652
        // TYA
653
        alu_opcode = TYA_IMP;
654 140 gabrielosh
        @(negedge clk);
655 127 gabrielosh
        alu_result_expected = alu_y_expected;
656
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
657
        alu_status_expected[N] = alu_result_expected[7];
658
        check();
659
 
660
        // Nothing should happen
661
        // BCC
662
        alu_opcode = BCC_REL;
663 140 gabrielosh
        @(negedge clk);
664 127 gabrielosh
        check();
665
 
666
        // BCS
667
        alu_opcode = BCS_REL;
668 140 gabrielosh
        @(negedge clk);
669 127 gabrielosh
        check();
670
 
671
        // BEQ
672
        alu_opcode = BEQ_REL;
673 140 gabrielosh
        @(negedge clk);
674 127 gabrielosh
        check();
675
 
676
        // BMI
677
        alu_opcode = BMI_REL;
678 140 gabrielosh
        @(negedge clk);
679 127 gabrielosh
        check();
680
 
681
        // BNE
682
        alu_opcode = BNE_REL;
683 140 gabrielosh
        @(negedge clk);
684 127 gabrielosh
        check();
685
 
686
        // BPL
687
        alu_opcode = BPL_REL;
688 140 gabrielosh
        @(negedge clk);
689 127 gabrielosh
        check();
690
 
691
        // BVC
692
        alu_opcode = BVC_REL;
693 140 gabrielosh
        @(negedge clk);
694 127 gabrielosh
        check();
695
 
696
        // BVS
697
        alu_opcode = BVS_REL;
698 140 gabrielosh
        @(negedge clk);
699 127 gabrielosh
        check();
700
 
701
        // JMP
702
        alu_opcode = JMP_ABS;
703 140 gabrielosh
        @(negedge clk);
704 127 gabrielosh
        check();
705
 
706
        // JMP
707
        alu_opcode = JMP_IND;
708 140 gabrielosh
        @(negedge clk);
709 127 gabrielosh
        check();
710
 
711
        // JSR
712
        alu_opcode = JSR_ABS;
713 140 gabrielosh
        @(negedge clk);
714 127 gabrielosh
        check();
715
 
716
        // NOP
717
        alu_opcode = NOP_IMP;
718 140 gabrielosh
        @(negedge clk);
719 127 gabrielosh
        check();
720
 
721
        // RTS
722
        alu_opcode = RTS_IMP;
723 140 gabrielosh
        @(negedge clk);
724 127 gabrielosh
        check();
725
 
726
        $display("TEST PASSED");
727
        $finish;
728
end
729
 
730
endmodule
731
 

powered by: WebSVN 2.1.0

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