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

Subversion Repositories t6507lp

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

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 181 gabrielosh
reg C_temp;
24
reg [7:0] temp1;
25
reg [7:0] temp2;
26 156 gabrielosh
reg sign;
27 164 gabrielosh
reg [3:0] AL;
28
reg [3:0] AH;
29
reg [3:0] BL;
30
reg [3:0] BH;
31
reg [7:0] alu_result_expected_temp;
32 127 gabrielosh
 
33 136 gabrielosh
t6507lp_alu DUT (
34
                        .clk            (clk),
35
                        .reset_n        (reset_n),
36 127 gabrielosh
                        .alu_enable     (alu_enable),
37
                        .alu_result     (alu_result),
38
                        .alu_status     (alu_status),
39
                        .alu_opcode     (alu_opcode),
40
                        .alu_a          (alu_a),
41
                        .alu_x          (alu_x),
42
                        .alu_y          (alu_y)
43
                );
44
 
45
 
46
localparam period = 10;
47
 
48
task check;
49
        begin
50
                $display("               RESULTS       EXPECTED");
51
                $display("alu_result       %h             %h   ", alu_result, alu_result_expected);
52
                $display("alu_status    %b       %b   ", alu_status, alu_status_expected);
53
                $display("alu_x            %h             %h   ", alu_x,      alu_x_expected     );
54
                $display("alu_y            %h             %h   ", alu_y,      alu_y_expected     );
55 150 gabrielosh
                if ((alu_result_expected == alu_result) && (alu_status_expected == alu_status) && (alu_x_expected == alu_x) && (alu_y_expected == alu_y))
56 127 gabrielosh
                begin
57 150 gabrielosh
                        $display("Instruction %h... OK!", alu_opcode);
58 127 gabrielosh
                end
59
                else
60
                begin
61 150 gabrielosh
                        $display("ERROR at instruction %h",alu_opcode);
62
                        $finish;
63 127 gabrielosh
                end
64
        end
65
endtask
66
 
67
 
68
always begin
69 136 gabrielosh
        #(period/2) clk = ~clk;
70 127 gabrielosh
end
71
 
72
initial
73
begin
74
        // Reset
75 136 gabrielosh
        clk = 0;
76
        reset_n = 0;
77 140 gabrielosh
        @(negedge clk);
78 150 gabrielosh
        //@(negedge clk);
79 148 gabrielosh
        reset_n = 1;
80 127 gabrielosh
        alu_enable = 1;
81
        alu_result_expected = 8'h00;
82
        alu_status_expected = 8'b00100010;
83
        alu_x_expected = 8'h00;
84
        alu_y_expected = 8'h00;
85
 
86
        // LDA
87
        alu_a = 0;
88
        alu_opcode = LDA_IMM;
89
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
90
        //$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);
91 140 gabrielosh
        @(negedge clk);
92 127 gabrielosh
        alu_result_expected = 8'h00;
93
        //                       NV1BDIZC
94 149 gabrielosh
    alu_status_expected = 8'b00100010;
95 173 gabrielosh
        check;
96 127 gabrielosh
 
97
        // ADC
98
        alu_opcode = ADC_IMM;
99
        alu_a = 1;
100
        for (i = 0; i < 1000; i = i + 1)
101
        begin
102 149 gabrielosh
                alu_a = $random;
103 140 gabrielosh
                @(negedge clk);
104 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
105
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
106
                //$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);
107 156 gabrielosh
                sign = alu_result_expected[7];
108 127 gabrielosh
                {alu_status_expected[C], alu_result_expected} = alu_a + alu_result_expected + alu_status_expected[C];
109
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
110
                alu_status_expected[N] = alu_result_expected[7];
111 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
112 173 gabrielosh
                check;
113 127 gabrielosh
        end
114 169 gabrielosh
 
115 186 gabrielosh
        // CLC
116
        alu_opcode = CLC_IMP;
117
        @(negedge clk);
118
        alu_status_expected[C] = 0;
119
        check;
120
 
121
        // SED
122
        alu_opcode = SED_IMP;
123
        //$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
124
        @(negedge clk);
125
        alu_status_expected[D] = 1;
126
        check;
127
        //Corner Case 12 + 88 decimal mode
128
        // LDA
129
        alu_a = 8'h88;
130
        alu_opcode = LDA_IMM;
131
        @(negedge clk);
132
        alu_result_expected = 8'h88;
133
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
134
        alu_status_expected[N] = alu_result_expected[7];
135
        check;
136
 
137
        // ADC
138
        alu_opcode = ADC_IMM;
139
        alu_a = 8'h12;
140
        $display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
141
        @(negedge clk);
142
        sign = alu_result_expected[7];
143
        AL = alu_a[3:0] + alu_result_expected[3:0] + alu_status_expected[C];
144
        $display("AL = %b", AL);
145
        AH = alu_a[7:4] + alu_result_expected[7:4] + AL[4];
146
        $display("AH = %b", AH);
147
        if (AL > 9) begin
148
          temp1 = AL - 6;
149
        end
150
        else begin
151
          temp1 = AL;
152
        end
153
        $display("temp1 = %b", temp1);
154
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
155
        alu_status_expected[N] = alu_result_expected[7];
156
        alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
157
        if (AH > 9) begin
158
          temp2 = AH - 6;
159
        end
160
        else begin
161
          temp2 = AH;
162
        end
163
        $display("temp2 = %b", temp2);
164
        alu_status_expected[C] = (temp2 > 15) ? 1 : 0;
165
        alu_result_expected = {temp2[3:0],temp1[3:0]};
166
        $display("A = %b PS = %b", alu_result_expected, alu_status_expected);
167
        check;
168
 
169
        // CLD
170
        alu_opcode = CLD_IMP;
171
        @(negedge clk);
172
        alu_status_expected[D] = 0;
173
        check;
174
        $stop;
175 164 gabrielosh
        // BCD
176 161 gabrielosh
        // LDA
177
        alu_a = 0;
178
        alu_opcode = LDA_IMM;
179
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
180
        //$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);
181
        @(negedge clk);
182
        alu_result_expected = 8'h00;
183
        //                       NV1BDIZC
184 164 gabrielosh
        alu_status_expected[N] = 0;
185
        alu_status_expected[Z] = 1;
186 173 gabrielosh
        check;
187 164 gabrielosh
        // SED
188
        alu_opcode = SED_IMP;
189 181 gabrielosh
        //$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
190 164 gabrielosh
        @(negedge clk);
191
        alu_status_expected[D] = 1;
192 173 gabrielosh
        check;
193 161 gabrielosh
 
194
        // ADC
195
        alu_opcode = ADC_IMM;
196
        for (i = 0; i < 1000; i = i + 1)
197
        begin
198
                alu_a = $random;
199 181 gabrielosh
                //$display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
200 161 gabrielosh
                @(negedge clk);
201 186 gabrielosh
                AL = alu_result_expected[3:0] + alu_a[3:0] + alu_status_expected[C];
202
                AH = alu_result_expected[7:4] + alu_a[7:4] + AL[4];
203
                if (AL > 9) AL = AL + 6;
204
                if (AH > 9) AH = AH + 6;
205
                alu_status_expected[C] = AH[4];
206
                alu_result_expected = {AH[3:0],AL[3:0]};
207
                //C_temp = 0;
208
                //sign = alu_result_expected[7];
209
                //AL = alu_a[3:0];
210
                //AH = alu_a[7:4];
211
                //BL = alu_result_expected[3:0];
212
                //BH = alu_result_expected[7:4];
213 181 gabrielosh
                /*
214
                if (AL > 9) begin
215 164 gabrielosh
                        AL = AL - 10;
216
                        AH = AH + 1;
217
                end
218 181 gabrielosh
                if ( AH > 9 ) begin
219 164 gabrielosh
                        AH = AH - 10;
220 181 gabrielosh
                        C_temp = 1;
221 164 gabrielosh
                end
222 181 gabrielosh
                if (BL > 9) begin
223 164 gabrielosh
                        BL = BL - 10;
224
                        BH = BH + 1;
225
                end
226
                if ( BH > 9 ) begin
227
                        BH = BH - 10;
228 181 gabrielosh
                        C_temp = 1;
229 164 gabrielosh
                end
230 181 gabrielosh
                */
231
                //$display("AL = %h BL = %h", AL, BL, );
232 186 gabrielosh
                //temp1 = AL + BL + alu_status_expected[C];
233 181 gabrielosh
                //AH = A[7:4] + alu_a[7:4];
234 186 gabrielosh
                //temp2 = AH + BH + temp1[4];
235 181 gabrielosh
                //$display("temp1 = %h temp2 = %h", temp1, temp2);
236 186 gabrielosh
                //if (temp1 > 9) begin
237
                //      temp2 = temp2 + (temp1 / 10);
238
        //              temp1 = temp1 % 10;
239
                //end
240
                //if (temp2 > 9) begin
241
                //      alu_status_expected[C] = 1;
242
                //      temp2 = temp2 % 10;
243
                //end
244
                //else begin
245
                //      alu_status_expected[C] = 0;
246
                //end
247 181 gabrielosh
                //$display("bcdh2 = %d", bcdh2);
248
                //$display("bcdl = %d", bcdl);
249 186 gabrielosh
                //alu_result_expected = {temp2[3:0],temp1[3:0]};
250 181 gabrielosh
                //{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
251
                //{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
252
                //if ( alu_result_expected[3:0] > 9 ) begin
253
                //      alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
254
        //              alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
255
                //end
256
                //if ( alu_result_expected[7:4] > 9 ) begin
257
                //      alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
258
        //              alu_status_expected[C] = 1;
259
                //end
260 161 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
261
                alu_status_expected[N] = alu_result_expected[7];
262
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
263 173 gabrielosh
                check;
264 179 gabrielosh
        end
265 181 gabrielosh
        //$stop;
266 179 gabrielosh
        // CLD
267
        alu_opcode = CLD_IMP;
268
        @(negedge clk);
269
        alu_status_expected[D] = 0;
270
        check;
271
 
272 184 gabrielosh
/*
273 181 gabrielosh
        // SBC BCD
274
        // LDA
275
        alu_a = 0;
276
        alu_opcode = LDA_IMM;
277
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
278
        //$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);
279
        @(negedge clk);
280
        alu_result_expected = 8'h00;
281
        //                       NV1BDIZC
282
        alu_status_expected[N] = 0;
283
        alu_status_expected[Z] = 1;
284
        check;
285
        // SED
286
        alu_opcode = SED_IMP;
287
        $display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
288
        @(negedge clk);
289
        alu_status_expected[D] = 1;
290
        check;
291
 
292 184 gabrielosh
        // SBC
293 181 gabrielosh
        alu_opcode = SBC_IMM;
294
        for (i = 0; i < 1000; i = i + 1)
295
        begin
296
                alu_a = $random;
297
                $display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
298
                @(negedge clk);
299
                C_temp = 0;
300
                sign   = alu_a[7];
301
                AL     = alu_a[3:0];
302
                AH     = alu_a[7:4];
303
                BL     = ~alu_result_expected[3:0];
304
                BH     = ~alu_result_expected[7:4];
305
 
306
                //$display("AL = %h BL = %h", AL, BL, );
307
                temp1 = AL + BL + alu_status_expected[C];
308
                //AH = A[7:4] + alu_a[7:4];
309
                temp2 = AH + BH;
310
                //$display("temp1 = %h temp2 = %h", temp1, temp2);
311
                if (temp1 > 9) begin
312
                        temp2 = temp2 + (temp1 / 10);
313
                        temp1 = temp1 % 10;
314
                end
315
                if (temp2 > 9) begin
316
                        alu_status_expected[C] = 1;
317
                        temp2 = temp2 % 10;
318
                end
319
                else begin
320
                        alu_status_expected[C] = 0;
321
                end
322
                //$display("bcdh2 = %d", bcdh2);
323
                //$display("bcdl = %d", bcdl);
324
                alu_result_expected = {temp2[3:0],temp1[3:0]};
325
                //{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
326
                //{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
327
                //if ( alu_result_expected[3:0] > 9 ) begin
328
                //      alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
329
        //              alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
330
                //end
331
                //if ( alu_result_expected[7:4] > 9 ) begin
332
                //      alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
333
        //              alu_status_expected[C] = 1;
334
                //end
335
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
336
                alu_status_expected[N] = alu_result_expected[7];
337
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
338
                check;
339
        end
340 183 gabrielosh
        //$stop;
341 181 gabrielosh
        // CLD
342
        alu_opcode = CLD_IMP;
343
        @(negedge clk);
344
        alu_status_expected[D] = 0;
345
        check;
346 184 gabrielosh
*/
347
 
348 148 gabrielosh
        // ASL
349 145 gabrielosh
        alu_opcode = ASL_ABS;
350
        for (i = 0; i < 1000; i = i + 1)
351
        begin
352
                alu_a = i;
353
                @(negedge clk);
354
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
355
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
356
                //$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);
357
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
358
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
359
                alu_status_expected[N] = alu_result_expected[7];
360 173 gabrielosh
                check;
361 145 gabrielosh
        end
362
 
363 186 gabrielosh
        // ROL
364
        alu_opcode = ROL_ABS;
365
        for (i = 0; i < 1000; i = i + 1)
366
        begin
367
                alu_a = i;
368
                $display("A = %b", alu_a);
369
                @(negedge clk);
370
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
371
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
372
                //$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);
373
                {alu_status_expected[C], alu_result_expected} = {alu_a,alu_status_expected[C]};
374
                $display("R = %b", alu_result);
375
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
376
                alu_status_expected[N] = alu_result_expected[7];
377
                check;
378
        end
379
 
380
        // ROR
381
        alu_opcode = ROR_ABS;
382
        for (i = 0; i < 1000; i = i + 1)
383
        begin
384
                alu_a = i;
385
                $display("A = %b", alu_a);
386
                @(negedge clk);
387
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
388
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
389
                //$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);
390
                {alu_result_expected, alu_status_expected[C]} = {alu_status_expected[C],alu_a};
391
                $display("R = %b", alu_result);
392
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
393
                alu_status_expected[N] = alu_result_expected[7];
394
                check;
395
        end
396
 
397 145 gabrielosh
        // LDA
398 156 gabrielosh
        alu_a = 137;
399
        alu_opcode = LDA_IMM;
400
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
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
        @(negedge clk);
403
        alu_result_expected = 8'd137;
404
        //                       NV1BDIZC
405
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
406
        alu_status_expected[N] = alu_result_expected[7];
407 173 gabrielosh
        check;
408 156 gabrielosh
 
409
        // EOR
410
        alu_opcode = EOR_IMM;
411
        for (i = 0; i < 1000; i = i + 1)
412
        begin
413
                alu_a = i;
414
                @(negedge clk);
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 179 gabrielosh
                //$display("result_expected = %d",alu_result_expected);
419 156 gabrielosh
                alu_result_expected = alu_a ^ alu_result_expected;
420
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
421
                alu_status_expected[N] = alu_result_expected[7];
422 179 gabrielosh
                //$display("result_expected = %d", alu_result_expected);
423 173 gabrielosh
                check;
424 156 gabrielosh
        end
425
 
426
        // LDA
427 145 gabrielosh
        alu_a = 0;
428
        alu_opcode = LDA_IMM;
429
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
430
        //$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);
431
        @(negedge clk);
432
        alu_result_expected = 8'h00;
433
        //                       NV1BDIZC
434
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
435
        alu_status_expected[N] = alu_result_expected[7];
436 173 gabrielosh
        check;
437 145 gabrielosh
 
438 127 gabrielosh
        // SBC
439
        alu_opcode = SBC_IMM;
440
        for (i = 0; i < 1000; i = i + 1)
441
        begin
442 145 gabrielosh
                alu_a = 1;
443 140 gabrielosh
                @(negedge clk);
444 174 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
445
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
446
                //$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);
447 156 gabrielosh
                sign = alu_result_expected[7];
448 174 gabrielosh
                alu_result_expected = alu_result_expected - alu_a - ( 1 - alu_status_expected[C]);
449
                alu_status_expected[C] = ~alu_result_expected[7];
450 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
451
                alu_status_expected[N] = alu_result_expected[7];
452 174 gabrielosh
                //$display("alu_a[7] = %b == sign = %b && alu_a[7] = %b != alu_result_expected[7] = %b", alu_a[7], sign, alu_a[7], alu_result_expected[7]);
453 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
454 173 gabrielosh
                check;
455 127 gabrielosh
        end
456
 
457
        // LDA
458
        alu_opcode = LDA_IMM;
459
        for (i = 0; i < 1000; i = i + 1)
460
        begin
461
                alu_a = i;
462 140 gabrielosh
                @(negedge clk);
463 127 gabrielosh
                alu_result_expected = i;
464
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
465
                alu_status_expected[N] = alu_result_expected[7];
466
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
467
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
468
                //$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);
469 173 gabrielosh
                check;
470 127 gabrielosh
        end
471
 
472
        // LDX
473
        alu_opcode = LDX_IMM;
474
        for (i = 0; i < 1000; i = i + 1)
475
        begin
476
                alu_a = i;
477 140 gabrielosh
                @(negedge clk);
478 178 gabrielosh
                alu_x_expected = alu_a;
479 179 gabrielosh
                //$display("alu_x_expected = %h", alu_x_expected);
480 127 gabrielosh
                //alu_result_expected = i;
481
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
482
                alu_status_expected[N] = alu_x_expected[7];
483
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
484
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
485
                //$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);
486 173 gabrielosh
                check;
487 127 gabrielosh
        end
488
 
489
        // LDY
490
        alu_opcode = LDY_IMM;
491
        for (i = 0; i < 1001; i = i + 1)
492
        begin
493
                alu_a = i;
494 140 gabrielosh
                @(negedge clk);
495 178 gabrielosh
                alu_y_expected = alu_a;
496 179 gabrielosh
                //$display("alu_y_expected = %h", alu_y_expected);
497 127 gabrielosh
                //alu_result_expected = i;
498
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
499
                alu_status_expected[N] = alu_y_expected[7];
500
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
501
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
502
                //$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);
503 173 gabrielosh
                check;
504 127 gabrielosh
        end
505
 
506
        // STA
507
        alu_opcode = STA_ABS;
508
        for (i = 0; i < 1000; i = i + 1)
509
        begin
510
                alu_a = i;
511 140 gabrielosh
                @(negedge clk);
512 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
513
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
514
                //$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);
515 178 gabrielosh
                //alu_result_expected = alu_a;
516
                //alu_result_expected = DUT.A;
517 173 gabrielosh
                check;
518 127 gabrielosh
        end
519
 
520
        // STX
521
        alu_opcode = STX_ABS;
522
        for (i = 0; i < 1000; i = i + 1)
523
        begin
524
                alu_a = i;
525 140 gabrielosh
                @(negedge clk);
526 179 gabrielosh
                //$display("alu_x_expected = %h", alu_x_expected);
527 127 gabrielosh
                //alu_result_expected = i;
528 178 gabrielosh
                //alu_x_expected = alu_a;
529 127 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 173 gabrielosh
                check;
533 127 gabrielosh
        end
534
 
535
        // STY
536
        alu_opcode = STY_ABS;
537
        for (i = 0; i < 1000; i = i + 1)
538
        begin
539
                alu_a = i;
540 140 gabrielosh
                @(negedge clk);
541 179 gabrielosh
                //$display("alu_y_expected = %h", alu_y_expected);
542 127 gabrielosh
                //alu_result_expected = i;
543 178 gabrielosh
                //alu_y_expected = alu_a;
544 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
545
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
546
                //$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);
547 173 gabrielosh
                check;
548 127 gabrielosh
        end
549
 
550
        // CMP
551
        alu_opcode = CMP_IMM;
552
        for (i = 0; i < 1000; i = i + 1)
553
        begin
554
                alu_a = i;
555 140 gabrielosh
                @(negedge clk);
556 181 gabrielosh
                temp1 = alu_result_expected - alu_a;
557
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
558
                alu_status_expected[N] = temp1[7];
559 127 gabrielosh
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
560
                //alu_result_expected = i;
561
                //alu_y_expected = i;
562
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
563
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
564
                //$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);
565 173 gabrielosh
                check;
566 127 gabrielosh
        end
567
 
568
        // CPX
569
        alu_opcode = CPX_IMM;
570
        for (i = 0; i < 1000; i = i + 1)
571
        begin
572
                alu_a = i;
573 140 gabrielosh
                @(negedge clk);
574 181 gabrielosh
                temp1 = alu_x_expected - alu_a;
575
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
576
                alu_status_expected[N] = temp1[7];
577 127 gabrielosh
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
578
                //alu_result_expected = i;
579
                //alu_y_expected = i;
580
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
581
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
582
                //$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);
583 173 gabrielosh
                check;
584 127 gabrielosh
        end
585
 
586
        // CPY
587
        alu_opcode = CPY_IMM;
588
        for (i = 0; i < 1000; i = i + 1)
589
        begin
590
                alu_a = i;
591 140 gabrielosh
                @(negedge clk);
592 181 gabrielosh
                temp1 = alu_y_expected - alu_a;
593
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
594
                alu_status_expected[N] = temp1[7];
595 127 gabrielosh
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
596
                //alu_result_expected = i;
597
                //alu_y_expected = i;
598
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
599
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
600
                //$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);
601 173 gabrielosh
                check;
602 127 gabrielosh
        end
603
 
604
 
605
        // AND
606
        alu_opcode = AND_IMM;
607
        for (i = 0; i < 1000; i = i + 1)
608
        begin
609
                alu_a = i;
610 140 gabrielosh
                @(negedge clk);
611 156 gabrielosh
                alu_result_expected = alu_a & alu_result_expected;
612 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
613
                alu_status_expected[N] = alu_result_expected[7];
614
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
615
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
616
                //$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);
617 173 gabrielosh
                check;
618 127 gabrielosh
        end
619
 
620
        // ASL
621
        alu_opcode = ASL_ACC;
622
        for (i = 0; i < 1000; i = i + 1)
623
        begin
624
                alu_a = i;
625 140 gabrielosh
                @(negedge clk);
626 127 gabrielosh
                alu_status_expected[C] = alu_result_expected[7];
627
                alu_result_expected[7:0] = alu_result_expected << 1;
628
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
629
                alu_status_expected[N] = alu_result_expected[7];
630
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
631
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
632
                //$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);
633 173 gabrielosh
                check;
634 127 gabrielosh
        end
635
 
636
        // INC
637
        alu_opcode = INC_ZPG;
638
        for (i = 0; i < 1000; i = i + 1)
639
        begin
640
                alu_a = i;
641 140 gabrielosh
                @(negedge clk);
642 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
643
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
644
                //$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);
645
                alu_result_expected = alu_a + 1;
646
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
647
                alu_status_expected[N] = alu_result_expected[7];
648 173 gabrielosh
                check;
649 127 gabrielosh
        end
650
 
651
        // INX
652
        alu_opcode = INX_IMP;
653
        for (i = 0; i < 1000; i = i + 1)
654
        begin
655
                alu_a = i;
656 140 gabrielosh
                @(negedge clk);
657 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
658
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
659
                //$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);
660
                alu_x_expected = alu_x_expected + 1;
661
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
662
                alu_status_expected[N] = alu_x_expected[7];
663 173 gabrielosh
                check;
664 127 gabrielosh
        end
665
 
666
        // INY
667
        alu_opcode = INY_IMP;
668
        for (i = 0; i < 1000; i = i + 1)
669
        begin
670
                alu_a = i;
671 140 gabrielosh
                @(negedge clk);
672 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
673
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
674
                //$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);
675
                alu_y_expected = alu_y_expected + 1;
676
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
677
                alu_status_expected[N] = alu_y_expected[7];
678 173 gabrielosh
                check;
679 127 gabrielosh
        end
680
 
681
        // DEC
682
        alu_opcode = DEC_ZPG;
683
        for (i = 0; i < 1000; i = i + 1)
684
        begin
685
                alu_a = i;
686 140 gabrielosh
                @(negedge clk);
687 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
688
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
689
                //$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);
690
                alu_result_expected = alu_a - 1;
691
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
692
                alu_status_expected[N] = alu_result_expected[7];
693 173 gabrielosh
                check;
694 127 gabrielosh
        end
695
 
696
        // DEX
697
        alu_opcode = DEX_IMP;
698
        for (i = 0; i < 1000; i = i + 1)
699
        begin
700
                alu_a = i;
701 140 gabrielosh
                @(negedge clk);
702 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
703
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
704
                //$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);
705
                alu_x_expected = alu_x_expected - 1;
706
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
707
                alu_status_expected[N] = alu_x_expected[7];
708 173 gabrielosh
                check;
709 127 gabrielosh
        end
710
 
711
        // DEY
712
        alu_opcode = DEY_IMP;
713
        for (i = 0; i < 1000; i = i + 1)
714
        begin
715
                alu_a = i;
716 140 gabrielosh
                @(negedge clk);
717 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
718
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
719
                //$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);
720
                alu_y_expected = alu_y_expected - 1;
721
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
722
                alu_status_expected[N] = alu_y_expected[7];
723 173 gabrielosh
                check;
724 127 gabrielosh
        end
725
 
726
 
727
        // LDA
728
        alu_a = 0;
729
        alu_opcode = LDA_IMM;
730
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
731
        //$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);
732 140 gabrielosh
        @(negedge clk);
733 127 gabrielosh
        alu_result_expected = 8'h00;
734
        //                       NV1BDIZC
735
        alu_status_expected = 8'b00100010;
736 173 gabrielosh
        check;
737 127 gabrielosh
 
738
        // BIT
739
        alu_opcode = BIT_ZPG;
740
        for (i = 0; i < 1000; i = i + 1)
741
        begin
742
                alu_a = i;
743 140 gabrielosh
                @(negedge clk);
744 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
745
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
746
                //$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);
747 127 gabrielosh
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
748
                alu_status_expected[V] = alu_a[6];
749
                alu_status_expected[N] = alu_a[7];
750 173 gabrielosh
                check;
751 127 gabrielosh
        end
752 158 gabrielosh
 
753 176 gabrielosh
        // RTI
754
        alu_opcode = RTI_IMP;
755
        for (i = 0; i < 1000; i = i + 1)
756
        begin
757
                alu_a = i;
758
                @(negedge clk);
759
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
760
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
761
                //$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);
762
                alu_status_expected[C] = alu_a[C];
763
                alu_status_expected[Z] = alu_a[Z];
764
                alu_status_expected[N] = alu_a[N];
765
                alu_status_expected[V] = alu_a[V];
766
                alu_status_expected[B] = alu_a[B];
767
                alu_status_expected[D] = alu_a[D];
768
                alu_status_expected[I] = alu_a[I];
769
                check;
770
        end
771 178 gabrielosh
 
772
        // PLP
773
        alu_opcode = PLP_IMP;
774
        for (i = 0; i < 1000; i = i + 1)
775
        begin
776
                alu_a = i;
777
                @(negedge clk);
778
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
779
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
780
                //$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);
781
                alu_status_expected[C] = alu_a[C];
782
                alu_status_expected[Z] = alu_a[Z];
783
                alu_status_expected[N] = alu_a[N];
784
                alu_status_expected[V] = alu_a[V];
785
                alu_status_expected[B] = alu_a[B];
786
                alu_status_expected[D] = alu_a[D];
787
                alu_status_expected[I] = alu_a[I];
788
                check;
789
        end
790
 
791 158 gabrielosh
        // PHA
792
        alu_opcode = PHA_IMP;
793
        @(negedge clk);
794
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
795
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
796
        //$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);
797 178 gabrielosh
        //alu_result_expected = DUT.A;
798 181 gabrielosh
        //alu_result_expected = alu_a;
799 173 gabrielosh
        check;
800 158 gabrielosh
 
801
        // PHP
802
        alu_opcode = PHP_IMP;
803
        @(negedge clk);
804
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
805
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
806
        //$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);
807 173 gabrielosh
        //alu_status_expected = DUT.STATUS;
808
        check;
809 158 gabrielosh
 
810
        // BRK
811
        alu_opcode = BRK_IMP;
812
        @(negedge clk);
813
        alu_status_expected[B] = 1;
814 173 gabrielosh
        check;
815 158 gabrielosh
 
816 127 gabrielosh
        // SEC
817
        alu_opcode = SEC_IMP;
818 140 gabrielosh
        @(negedge clk);
819 127 gabrielosh
        alu_status_expected[C] = 1;
820 173 gabrielosh
        check;
821 127 gabrielosh
 
822
        // SED
823
        alu_opcode = SED_IMP;
824 140 gabrielosh
        @(negedge clk);
825 127 gabrielosh
        alu_status_expected[D] = 1;
826 173 gabrielosh
        check;
827 127 gabrielosh
 
828
        // SEI
829
        alu_opcode = SEI_IMP;
830 140 gabrielosh
        @(negedge clk);
831 127 gabrielosh
        alu_status_expected[I] = 1;
832 173 gabrielosh
        check;
833 127 gabrielosh
 
834
        // CLC
835
        alu_opcode = CLC_IMP;
836 140 gabrielosh
        @(negedge clk);
837 127 gabrielosh
        alu_status_expected[C] = 0;
838 173 gabrielosh
        check;
839 127 gabrielosh
 
840
        // CLD
841
        alu_opcode = CLD_IMP;
842 140 gabrielosh
        @(negedge clk);
843 127 gabrielosh
        alu_status_expected[D] = 0;
844 173 gabrielosh
        check;
845 127 gabrielosh
 
846
        // CLI
847
        alu_opcode = CLI_IMP;
848 140 gabrielosh
        @(negedge clk);
849 127 gabrielosh
        alu_status_expected[I] = 0;
850 173 gabrielosh
        check;
851 127 gabrielosh
 
852
        // CLV
853
        alu_opcode = CLV_IMP;
854 140 gabrielosh
        @(negedge clk);
855 127 gabrielosh
        alu_status_expected[V] = 0;
856 173 gabrielosh
        check;
857 127 gabrielosh
 
858
        // LDA
859
        alu_opcode = LDA_IMM;
860
        alu_a = 8'h76;
861 140 gabrielosh
        @(negedge clk);
862 127 gabrielosh
        alu_result_expected = alu_a;
863
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
864
        alu_status_expected[N] = alu_result_expected[7];
865 173 gabrielosh
        check;
866 127 gabrielosh
 
867
        // TAX
868
        alu_opcode = TAX_IMP;
869 140 gabrielosh
        @(negedge clk);
870 127 gabrielosh
        alu_x_expected = alu_result_expected;
871
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
872
        alu_status_expected[N] = alu_x_expected[7];
873 173 gabrielosh
        check;
874 127 gabrielosh
 
875
        // TAY
876
        alu_opcode = TAY_IMP;
877 140 gabrielosh
        @(negedge clk);
878 127 gabrielosh
        alu_y_expected = alu_result_expected;
879
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
880
        alu_status_expected[N] = alu_y_expected[7];
881 173 gabrielosh
        check;
882 127 gabrielosh
 
883
        // TSX
884
        alu_opcode = TSX_IMP;
885 140 gabrielosh
        @(negedge clk);
886 127 gabrielosh
        alu_x_expected = alu_a;
887
        //alu_result_expected = alu_a;
888
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
889
        alu_status_expected[N] = alu_x_expected[7];
890 173 gabrielosh
        check;
891 127 gabrielosh
 
892
        // TXA
893
        alu_opcode = TXA_IMP;
894 140 gabrielosh
        @(negedge clk);
895 127 gabrielosh
        alu_result_expected = alu_x_expected;
896
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
897
        alu_status_expected[N] = alu_result_expected[7];
898 173 gabrielosh
        check;
899 127 gabrielosh
 
900
        // TXS
901
        alu_opcode = TXS_IMP;
902 140 gabrielosh
        @(negedge clk);
903 127 gabrielosh
        alu_result_expected = alu_x_expected;
904 173 gabrielosh
        check;
905 127 gabrielosh
 
906
        // TYA
907
        alu_opcode = TYA_IMP;
908 140 gabrielosh
        @(negedge clk);
909 127 gabrielosh
        alu_result_expected = alu_y_expected;
910
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
911
        alu_status_expected[N] = alu_result_expected[7];
912 173 gabrielosh
        check;
913 127 gabrielosh
 
914
        // Nothing should happen
915
        // BCC
916
        alu_opcode = BCC_REL;
917 140 gabrielosh
        @(negedge clk);
918 173 gabrielosh
        check;
919 127 gabrielosh
 
920
        // BCS
921
        alu_opcode = BCS_REL;
922 140 gabrielosh
        @(negedge clk);
923 173 gabrielosh
        check;
924 127 gabrielosh
 
925
        // BEQ
926
        alu_opcode = BEQ_REL;
927 140 gabrielosh
        @(negedge clk);
928 173 gabrielosh
        check;
929 127 gabrielosh
 
930
        // BMI
931
        alu_opcode = BMI_REL;
932 140 gabrielosh
        @(negedge clk);
933 173 gabrielosh
        check;
934 127 gabrielosh
 
935
        // BNE
936
        alu_opcode = BNE_REL;
937 140 gabrielosh
        @(negedge clk);
938 173 gabrielosh
        check;
939 127 gabrielosh
 
940
        // BPL
941
        alu_opcode = BPL_REL;
942 140 gabrielosh
        @(negedge clk);
943 173 gabrielosh
        check;
944 127 gabrielosh
 
945
        // BVC
946
        alu_opcode = BVC_REL;
947 140 gabrielosh
        @(negedge clk);
948 173 gabrielosh
        check;
949 127 gabrielosh
 
950
        // BVS
951
        alu_opcode = BVS_REL;
952 140 gabrielosh
        @(negedge clk);
953 173 gabrielosh
        check;
954 127 gabrielosh
 
955
        // JMP
956
        alu_opcode = JMP_ABS;
957 140 gabrielosh
        @(negedge clk);
958 173 gabrielosh
        check;
959 127 gabrielosh
 
960
        // JMP
961
        alu_opcode = JMP_IND;
962 140 gabrielosh
        @(negedge clk);
963 173 gabrielosh
        check;
964 127 gabrielosh
 
965
        // JSR
966
        alu_opcode = JSR_ABS;
967 140 gabrielosh
        @(negedge clk);
968 173 gabrielosh
        check;
969 127 gabrielosh
 
970
        // NOP
971
        alu_opcode = NOP_IMP;
972 140 gabrielosh
        @(negedge clk);
973 173 gabrielosh
        check;
974 127 gabrielosh
 
975
        // RTS
976
        alu_opcode = RTS_IMP;
977 140 gabrielosh
        @(negedge clk);
978 173 gabrielosh
        check;
979 127 gabrielosh
 
980
        $display("TEST PASSED");
981
        $finish;
982
end
983
 
984
endmodule
985
 

powered by: WebSVN 2.1.0

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