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

Subversion Repositories t6507lp

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

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 164 gabrielosh
        // BCD
116 161 gabrielosh
        // LDA
117
        alu_a = 0;
118
        alu_opcode = LDA_IMM;
119
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
120
        //$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);
121
        @(negedge clk);
122
        alu_result_expected = 8'h00;
123
        //                       NV1BDIZC
124 164 gabrielosh
        alu_status_expected[N] = 0;
125
        alu_status_expected[Z] = 1;
126 173 gabrielosh
        check;
127 164 gabrielosh
        // SED
128
        alu_opcode = SED_IMP;
129 181 gabrielosh
        //$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
130 164 gabrielosh
        @(negedge clk);
131
        alu_status_expected[D] = 1;
132 173 gabrielosh
        check;
133 161 gabrielosh
 
134
        // ADC
135
        alu_opcode = ADC_IMM;
136
        for (i = 0; i < 1000; i = i + 1)
137
        begin
138
                alu_a = $random;
139 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);
140 161 gabrielosh
                @(negedge clk);
141 181 gabrielosh
                C_temp = 0;
142 161 gabrielosh
                sign = alu_result_expected[7];
143 164 gabrielosh
                AL = alu_a[3:0];
144
                AH = alu_a[7:4];
145
                BL = alu_result_expected[3:0];
146
                BH = alu_result_expected[7:4];
147 181 gabrielosh
                /*
148
                if (AL > 9) begin
149 164 gabrielosh
                        AL = AL - 10;
150
                        AH = AH + 1;
151
                end
152 181 gabrielosh
                if ( AH > 9 ) begin
153 164 gabrielosh
                        AH = AH - 10;
154 181 gabrielosh
                        C_temp = 1;
155 164 gabrielosh
                end
156 181 gabrielosh
                if (BL > 9) begin
157 164 gabrielosh
                        BL = BL - 10;
158
                        BH = BH + 1;
159
                end
160
                if ( BH > 9 ) begin
161
                        BH = BH - 10;
162 181 gabrielosh
                        C_temp = 1;
163 164 gabrielosh
                end
164 181 gabrielosh
                */
165
                //$display("AL = %h BL = %h", AL, BL, );
166
                temp1 = AL + BL + alu_status_expected[C];
167
                //AH = A[7:4] + alu_a[7:4];
168
                temp2 = AH + BH;
169
                //$display("temp1 = %h temp2 = %h", temp1, temp2);
170
                if (temp1 > 9) begin
171
                        temp2 = temp2 + (temp1 / 10);
172
                        temp1 = temp1 % 10;
173 164 gabrielosh
                end
174 181 gabrielosh
                if (temp2 > 9) begin
175 165 gabrielosh
                        alu_status_expected[C] = 1;
176 181 gabrielosh
                        temp2 = temp2 % 10;
177 164 gabrielosh
                end
178 181 gabrielosh
                else begin
179
                        alu_status_expected[C] = 0;
180
                end
181
                //$display("bcdh2 = %d", bcdh2);
182
                //$display("bcdl = %d", bcdl);
183
                alu_result_expected = {temp2[3:0],temp1[3:0]};
184
                //{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
185
                //{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
186
                //if ( alu_result_expected[3:0] > 9 ) begin
187
                //      alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
188
        //              alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
189
                //end
190
                //if ( alu_result_expected[7:4] > 9 ) begin
191
                //      alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
192
        //              alu_status_expected[C] = 1;
193
                //end
194 161 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
195
                alu_status_expected[N] = alu_result_expected[7];
196
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
197 173 gabrielosh
                check;
198 179 gabrielosh
        end
199 181 gabrielosh
        //$stop;
200 179 gabrielosh
        // CLD
201
        alu_opcode = CLD_IMP;
202
        @(negedge clk);
203
        alu_status_expected[D] = 0;
204
        check;
205
 
206 184 gabrielosh
/*
207 181 gabrielosh
        // SBC BCD
208
        // LDA
209
        alu_a = 0;
210
        alu_opcode = LDA_IMM;
211
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
212
        //$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);
213
        @(negedge clk);
214
        alu_result_expected = 8'h00;
215
        //                       NV1BDIZC
216
        alu_status_expected[N] = 0;
217
        alu_status_expected[Z] = 1;
218
        check;
219
        // SED
220
        alu_opcode = SED_IMP;
221
        $display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
222
        @(negedge clk);
223
        alu_status_expected[D] = 1;
224
        check;
225
 
226 184 gabrielosh
        // SBC
227 181 gabrielosh
        alu_opcode = SBC_IMM;
228
        for (i = 0; i < 1000; i = i + 1)
229
        begin
230
                alu_a = $random;
231
                $display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
232
                @(negedge clk);
233
                C_temp = 0;
234
                sign   = alu_a[7];
235
                AL     = alu_a[3:0];
236
                AH     = alu_a[7:4];
237
                BL     = ~alu_result_expected[3:0];
238
                BH     = ~alu_result_expected[7:4];
239
 
240
                //$display("AL = %h BL = %h", AL, BL, );
241
                temp1 = AL + BL + alu_status_expected[C];
242
                //AH = A[7:4] + alu_a[7:4];
243
                temp2 = AH + BH;
244
                //$display("temp1 = %h temp2 = %h", temp1, temp2);
245
                if (temp1 > 9) begin
246
                        temp2 = temp2 + (temp1 / 10);
247
                        temp1 = temp1 % 10;
248
                end
249
                if (temp2 > 9) begin
250
                        alu_status_expected[C] = 1;
251
                        temp2 = temp2 % 10;
252
                end
253
                else begin
254
                        alu_status_expected[C] = 0;
255
                end
256
                //$display("bcdh2 = %d", bcdh2);
257
                //$display("bcdl = %d", bcdl);
258
                alu_result_expected = {temp2[3:0],temp1[3:0]};
259
                //{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
260
                //{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
261
                //if ( alu_result_expected[3:0] > 9 ) begin
262
                //      alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
263
        //              alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
264
                //end
265
                //if ( alu_result_expected[7:4] > 9 ) begin
266
                //      alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
267
        //              alu_status_expected[C] = 1;
268
                //end
269
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
270
                alu_status_expected[N] = alu_result_expected[7];
271
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
272
                check;
273
        end
274 183 gabrielosh
        //$stop;
275 181 gabrielosh
        // CLD
276
        alu_opcode = CLD_IMP;
277
        @(negedge clk);
278
        alu_status_expected[D] = 0;
279
        check;
280 184 gabrielosh
*/
281
 
282 148 gabrielosh
        // ASL
283 145 gabrielosh
        alu_opcode = ASL_ABS;
284
        for (i = 0; i < 1000; i = i + 1)
285
        begin
286
                alu_a = i;
287
                @(negedge clk);
288
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
289
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
290
                //$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);
291
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
292
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
293
                alu_status_expected[N] = alu_result_expected[7];
294 173 gabrielosh
                check;
295 145 gabrielosh
        end
296
 
297
        // LDA
298 156 gabrielosh
        alu_a = 137;
299
        alu_opcode = LDA_IMM;
300
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
301
        //$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);
302
        @(negedge clk);
303
        alu_result_expected = 8'd137;
304
        //                       NV1BDIZC
305
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
306
        alu_status_expected[N] = alu_result_expected[7];
307 173 gabrielosh
        check;
308 156 gabrielosh
 
309
        // EOR
310
        alu_opcode = EOR_IMM;
311
        for (i = 0; i < 1000; i = i + 1)
312
        begin
313
                alu_a = i;
314
                @(negedge clk);
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 179 gabrielosh
                //$display("result_expected = %d",alu_result_expected);
319 156 gabrielosh
                alu_result_expected = alu_a ^ alu_result_expected;
320
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
321
                alu_status_expected[N] = alu_result_expected[7];
322 179 gabrielosh
                //$display("result_expected = %d", alu_result_expected);
323 173 gabrielosh
                check;
324 156 gabrielosh
        end
325
 
326
        // LDA
327 145 gabrielosh
        alu_a = 0;
328
        alu_opcode = LDA_IMM;
329
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
330
        //$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);
331
        @(negedge clk);
332
        alu_result_expected = 8'h00;
333
        //                       NV1BDIZC
334
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
335
        alu_status_expected[N] = alu_result_expected[7];
336 173 gabrielosh
        check;
337 145 gabrielosh
 
338 127 gabrielosh
        // SBC
339
        alu_opcode = SBC_IMM;
340
        for (i = 0; i < 1000; i = i + 1)
341
        begin
342 145 gabrielosh
                alu_a = 1;
343 140 gabrielosh
                @(negedge clk);
344 174 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
345
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
346
                //$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);
347 156 gabrielosh
                sign = alu_result_expected[7];
348 174 gabrielosh
                alu_result_expected = alu_result_expected - alu_a - ( 1 - alu_status_expected[C]);
349
                alu_status_expected[C] = ~alu_result_expected[7];
350 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
351
                alu_status_expected[N] = alu_result_expected[7];
352 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]);
353 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
354 173 gabrielosh
                check;
355 127 gabrielosh
        end
356
 
357
        // LDA
358
        alu_opcode = LDA_IMM;
359
        for (i = 0; i < 1000; i = i + 1)
360
        begin
361
                alu_a = i;
362 140 gabrielosh
                @(negedge clk);
363 127 gabrielosh
                alu_result_expected = i;
364
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
365
                alu_status_expected[N] = alu_result_expected[7];
366
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
367
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
368
                //$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);
369 173 gabrielosh
                check;
370 127 gabrielosh
        end
371
 
372
        // LDX
373
        alu_opcode = LDX_IMM;
374
        for (i = 0; i < 1000; i = i + 1)
375
        begin
376
                alu_a = i;
377 140 gabrielosh
                @(negedge clk);
378 178 gabrielosh
                alu_x_expected = alu_a;
379 179 gabrielosh
                //$display("alu_x_expected = %h", alu_x_expected);
380 127 gabrielosh
                //alu_result_expected = i;
381
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
382
                alu_status_expected[N] = alu_x_expected[7];
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 173 gabrielosh
                check;
387 127 gabrielosh
        end
388
 
389
        // LDY
390
        alu_opcode = LDY_IMM;
391
        for (i = 0; i < 1001; i = i + 1)
392
        begin
393
                alu_a = i;
394 140 gabrielosh
                @(negedge clk);
395 178 gabrielosh
                alu_y_expected = alu_a;
396 179 gabrielosh
                //$display("alu_y_expected = %h", alu_y_expected);
397 127 gabrielosh
                //alu_result_expected = i;
398
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
399
                alu_status_expected[N] = alu_y_expected[7];
400
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
401
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
402
                //$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);
403 173 gabrielosh
                check;
404 127 gabrielosh
        end
405
 
406
        // STA
407
        alu_opcode = STA_ABS;
408
        for (i = 0; i < 1000; i = i + 1)
409
        begin
410
                alu_a = i;
411 140 gabrielosh
                @(negedge clk);
412 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
413
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
414
                //$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);
415 178 gabrielosh
                //alu_result_expected = alu_a;
416
                //alu_result_expected = DUT.A;
417 173 gabrielosh
                check;
418 127 gabrielosh
        end
419
 
420
        // STX
421
        alu_opcode = STX_ABS;
422
        for (i = 0; i < 1000; i = i + 1)
423
        begin
424
                alu_a = i;
425 140 gabrielosh
                @(negedge clk);
426 179 gabrielosh
                //$display("alu_x_expected = %h", alu_x_expected);
427 127 gabrielosh
                //alu_result_expected = i;
428 178 gabrielosh
                //alu_x_expected = alu_a;
429 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
430
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
431
                //$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);
432 173 gabrielosh
                check;
433 127 gabrielosh
        end
434
 
435
        // STY
436
        alu_opcode = STY_ABS;
437
        for (i = 0; i < 1000; i = i + 1)
438
        begin
439
                alu_a = i;
440 140 gabrielosh
                @(negedge clk);
441 179 gabrielosh
                //$display("alu_y_expected = %h", alu_y_expected);
442 127 gabrielosh
                //alu_result_expected = i;
443 178 gabrielosh
                //alu_y_expected = alu_a;
444 127 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 173 gabrielosh
                check;
448 127 gabrielosh
        end
449
 
450
        // CMP
451
        alu_opcode = CMP_IMM;
452
        for (i = 0; i < 1000; i = i + 1)
453
        begin
454
                alu_a = i;
455 140 gabrielosh
                @(negedge clk);
456 181 gabrielosh
                temp1 = alu_result_expected - alu_a;
457
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
458
                alu_status_expected[N] = temp1[7];
459 127 gabrielosh
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
460
                //alu_result_expected = i;
461
                //alu_y_expected = i;
462
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
463
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
464
                //$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);
465 173 gabrielosh
                check;
466 127 gabrielosh
        end
467
 
468
        // CPX
469
        alu_opcode = CPX_IMM;
470
        for (i = 0; i < 1000; i = i + 1)
471
        begin
472
                alu_a = i;
473 140 gabrielosh
                @(negedge clk);
474 181 gabrielosh
                temp1 = alu_x_expected - alu_a;
475
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
476
                alu_status_expected[N] = temp1[7];
477 127 gabrielosh
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
478
                //alu_result_expected = i;
479
                //alu_y_expected = i;
480
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
481
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
482
                //$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);
483 173 gabrielosh
                check;
484 127 gabrielosh
        end
485
 
486
        // CPY
487
        alu_opcode = CPY_IMM;
488
        for (i = 0; i < 1000; i = i + 1)
489
        begin
490
                alu_a = i;
491 140 gabrielosh
                @(negedge clk);
492 181 gabrielosh
                temp1 = alu_y_expected - alu_a;
493
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
494
                alu_status_expected[N] = temp1[7];
495 127 gabrielosh
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
496
                //alu_result_expected = i;
497
                //alu_y_expected = i;
498
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
499
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
500
                //$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);
501 173 gabrielosh
                check;
502 127 gabrielosh
        end
503
 
504
 
505
        // AND
506
        alu_opcode = AND_IMM;
507
        for (i = 0; i < 1000; i = i + 1)
508
        begin
509
                alu_a = i;
510 140 gabrielosh
                @(negedge clk);
511 156 gabrielosh
                alu_result_expected = alu_a & alu_result_expected;
512 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
513
                alu_status_expected[N] = alu_result_expected[7];
514
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
515
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
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 173 gabrielosh
                check;
518 127 gabrielosh
        end
519
 
520
        // ASL
521
        alu_opcode = ASL_ACC;
522
        for (i = 0; i < 1000; i = i + 1)
523
        begin
524
                alu_a = i;
525 140 gabrielosh
                @(negedge clk);
526 127 gabrielosh
                alu_status_expected[C] = alu_result_expected[7];
527
                alu_result_expected[7:0] = alu_result_expected << 1;
528
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
529
                alu_status_expected[N] = alu_result_expected[7];
530
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
531
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
532
                //$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);
533 173 gabrielosh
                check;
534 127 gabrielosh
        end
535
 
536
        // INC
537
        alu_opcode = INC_ZPG;
538
        for (i = 0; i < 1000; i = i + 1)
539
        begin
540
                alu_a = i;
541 140 gabrielosh
                @(negedge clk);
542 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
543
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
544
                //$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);
545
                alu_result_expected = alu_a + 1;
546
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
547
                alu_status_expected[N] = alu_result_expected[7];
548 173 gabrielosh
                check;
549 127 gabrielosh
        end
550
 
551
        // INX
552
        alu_opcode = INX_IMP;
553
        for (i = 0; i < 1000; i = i + 1)
554
        begin
555
                alu_a = i;
556 140 gabrielosh
                @(negedge clk);
557 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
558
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
559
                //$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);
560
                alu_x_expected = alu_x_expected + 1;
561
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
562
                alu_status_expected[N] = alu_x_expected[7];
563 173 gabrielosh
                check;
564 127 gabrielosh
        end
565
 
566
        // INY
567
        alu_opcode = INY_IMP;
568
        for (i = 0; i < 1000; i = i + 1)
569
        begin
570
                alu_a = i;
571 140 gabrielosh
                @(negedge clk);
572 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
573
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
574
                //$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);
575
                alu_y_expected = alu_y_expected + 1;
576
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
577
                alu_status_expected[N] = alu_y_expected[7];
578 173 gabrielosh
                check;
579 127 gabrielosh
        end
580
 
581
        // DEC
582
        alu_opcode = DEC_ZPG;
583
        for (i = 0; i < 1000; i = i + 1)
584
        begin
585
                alu_a = i;
586 140 gabrielosh
                @(negedge clk);
587 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
588
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
589
                //$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);
590
                alu_result_expected = alu_a - 1;
591
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
592
                alu_status_expected[N] = alu_result_expected[7];
593 173 gabrielosh
                check;
594 127 gabrielosh
        end
595
 
596
        // DEX
597
        alu_opcode = DEX_IMP;
598
        for (i = 0; i < 1000; i = i + 1)
599
        begin
600
                alu_a = i;
601 140 gabrielosh
                @(negedge clk);
602 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
603
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
604
                //$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);
605
                alu_x_expected = alu_x_expected - 1;
606
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
607
                alu_status_expected[N] = alu_x_expected[7];
608 173 gabrielosh
                check;
609 127 gabrielosh
        end
610
 
611
        // DEY
612
        alu_opcode = DEY_IMP;
613
        for (i = 0; i < 1000; i = i + 1)
614
        begin
615
                alu_a = i;
616 140 gabrielosh
                @(negedge clk);
617 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
618
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
619
                //$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);
620
                alu_y_expected = alu_y_expected - 1;
621
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
622
                alu_status_expected[N] = alu_y_expected[7];
623 173 gabrielosh
                check;
624 127 gabrielosh
        end
625
 
626
 
627
        // LDA
628
        alu_a = 0;
629
        alu_opcode = LDA_IMM;
630
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
631
        //$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);
632 140 gabrielosh
        @(negedge clk);
633 127 gabrielosh
        alu_result_expected = 8'h00;
634
        //                       NV1BDIZC
635
        alu_status_expected = 8'b00100010;
636 173 gabrielosh
        check;
637 127 gabrielosh
 
638
        // BIT
639
        alu_opcode = BIT_ZPG;
640
        for (i = 0; i < 1000; i = i + 1)
641
        begin
642
                alu_a = i;
643 140 gabrielosh
                @(negedge clk);
644 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
645
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
646
                //$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);
647 127 gabrielosh
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
648
                alu_status_expected[V] = alu_a[6];
649
                alu_status_expected[N] = alu_a[7];
650 173 gabrielosh
                check;
651 127 gabrielosh
        end
652 158 gabrielosh
 
653 176 gabrielosh
        // RTI
654
        alu_opcode = RTI_IMP;
655
        for (i = 0; i < 1000; i = i + 1)
656
        begin
657
                alu_a = i;
658
                @(negedge clk);
659
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
660
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
661
                //$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);
662
                alu_status_expected[C] = alu_a[C];
663
                alu_status_expected[Z] = alu_a[Z];
664
                alu_status_expected[N] = alu_a[N];
665
                alu_status_expected[V] = alu_a[V];
666
                alu_status_expected[B] = alu_a[B];
667
                alu_status_expected[D] = alu_a[D];
668
                alu_status_expected[I] = alu_a[I];
669
                check;
670
        end
671 178 gabrielosh
 
672
        // PLP
673
        alu_opcode = PLP_IMP;
674
        for (i = 0; i < 1000; i = i + 1)
675
        begin
676
                alu_a = i;
677
                @(negedge clk);
678
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
679
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
680
                //$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);
681
                alu_status_expected[C] = alu_a[C];
682
                alu_status_expected[Z] = alu_a[Z];
683
                alu_status_expected[N] = alu_a[N];
684
                alu_status_expected[V] = alu_a[V];
685
                alu_status_expected[B] = alu_a[B];
686
                alu_status_expected[D] = alu_a[D];
687
                alu_status_expected[I] = alu_a[I];
688
                check;
689
        end
690
 
691 158 gabrielosh
        // PHA
692
        alu_opcode = PHA_IMP;
693
        @(negedge clk);
694
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
695
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
696
        //$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);
697 178 gabrielosh
        //alu_result_expected = DUT.A;
698 181 gabrielosh
        //alu_result_expected = alu_a;
699 173 gabrielosh
        check;
700 158 gabrielosh
 
701
        // PHP
702
        alu_opcode = PHP_IMP;
703
        @(negedge clk);
704
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
705
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
706
        //$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);
707 173 gabrielosh
        //alu_status_expected = DUT.STATUS;
708
        check;
709 158 gabrielosh
 
710
        // BRK
711
        alu_opcode = BRK_IMP;
712
        @(negedge clk);
713
        alu_status_expected[B] = 1;
714 173 gabrielosh
        check;
715 158 gabrielosh
 
716 127 gabrielosh
        // SEC
717
        alu_opcode = SEC_IMP;
718 140 gabrielosh
        @(negedge clk);
719 127 gabrielosh
        alu_status_expected[C] = 1;
720 173 gabrielosh
        check;
721 127 gabrielosh
 
722
        // SED
723
        alu_opcode = SED_IMP;
724 140 gabrielosh
        @(negedge clk);
725 127 gabrielosh
        alu_status_expected[D] = 1;
726 173 gabrielosh
        check;
727 127 gabrielosh
 
728
        // SEI
729
        alu_opcode = SEI_IMP;
730 140 gabrielosh
        @(negedge clk);
731 127 gabrielosh
        alu_status_expected[I] = 1;
732 173 gabrielosh
        check;
733 127 gabrielosh
 
734
        // CLC
735
        alu_opcode = CLC_IMP;
736 140 gabrielosh
        @(negedge clk);
737 127 gabrielosh
        alu_status_expected[C] = 0;
738 173 gabrielosh
        check;
739 127 gabrielosh
 
740
        // CLD
741
        alu_opcode = CLD_IMP;
742 140 gabrielosh
        @(negedge clk);
743 127 gabrielosh
        alu_status_expected[D] = 0;
744 173 gabrielosh
        check;
745 127 gabrielosh
 
746
        // CLI
747
        alu_opcode = CLI_IMP;
748 140 gabrielosh
        @(negedge clk);
749 127 gabrielosh
        alu_status_expected[I] = 0;
750 173 gabrielosh
        check;
751 127 gabrielosh
 
752
        // CLV
753
        alu_opcode = CLV_IMP;
754 140 gabrielosh
        @(negedge clk);
755 127 gabrielosh
        alu_status_expected[V] = 0;
756 173 gabrielosh
        check;
757 127 gabrielosh
 
758
        // LDA
759
        alu_opcode = LDA_IMM;
760
        alu_a = 8'h76;
761 140 gabrielosh
        @(negedge clk);
762 127 gabrielosh
        alu_result_expected = alu_a;
763
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
764
        alu_status_expected[N] = alu_result_expected[7];
765 173 gabrielosh
        check;
766 127 gabrielosh
 
767
        // TAX
768
        alu_opcode = TAX_IMP;
769 140 gabrielosh
        @(negedge clk);
770 127 gabrielosh
        alu_x_expected = alu_result_expected;
771
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
772
        alu_status_expected[N] = alu_x_expected[7];
773 173 gabrielosh
        check;
774 127 gabrielosh
 
775
        // TAY
776
        alu_opcode = TAY_IMP;
777 140 gabrielosh
        @(negedge clk);
778 127 gabrielosh
        alu_y_expected = alu_result_expected;
779
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
780
        alu_status_expected[N] = alu_y_expected[7];
781 173 gabrielosh
        check;
782 127 gabrielosh
 
783
        // TSX
784
        alu_opcode = TSX_IMP;
785 140 gabrielosh
        @(negedge clk);
786 127 gabrielosh
        alu_x_expected = alu_a;
787
        //alu_result_expected = alu_a;
788
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
789
        alu_status_expected[N] = alu_x_expected[7];
790 173 gabrielosh
        check;
791 127 gabrielosh
 
792
        // TXA
793
        alu_opcode = TXA_IMP;
794 140 gabrielosh
        @(negedge clk);
795 127 gabrielosh
        alu_result_expected = alu_x_expected;
796
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
797
        alu_status_expected[N] = alu_result_expected[7];
798 173 gabrielosh
        check;
799 127 gabrielosh
 
800
        // TXS
801
        alu_opcode = TXS_IMP;
802 140 gabrielosh
        @(negedge clk);
803 127 gabrielosh
        alu_result_expected = alu_x_expected;
804 173 gabrielosh
        check;
805 127 gabrielosh
 
806
        // TYA
807
        alu_opcode = TYA_IMP;
808 140 gabrielosh
        @(negedge clk);
809 127 gabrielosh
        alu_result_expected = alu_y_expected;
810
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
811
        alu_status_expected[N] = alu_result_expected[7];
812 173 gabrielosh
        check;
813 127 gabrielosh
 
814
        // Nothing should happen
815
        // BCC
816
        alu_opcode = BCC_REL;
817 140 gabrielosh
        @(negedge clk);
818 173 gabrielosh
        check;
819 127 gabrielosh
 
820
        // BCS
821
        alu_opcode = BCS_REL;
822 140 gabrielosh
        @(negedge clk);
823 173 gabrielosh
        check;
824 127 gabrielosh
 
825
        // BEQ
826
        alu_opcode = BEQ_REL;
827 140 gabrielosh
        @(negedge clk);
828 173 gabrielosh
        check;
829 127 gabrielosh
 
830
        // BMI
831
        alu_opcode = BMI_REL;
832 140 gabrielosh
        @(negedge clk);
833 173 gabrielosh
        check;
834 127 gabrielosh
 
835
        // BNE
836
        alu_opcode = BNE_REL;
837 140 gabrielosh
        @(negedge clk);
838 173 gabrielosh
        check;
839 127 gabrielosh
 
840
        // BPL
841
        alu_opcode = BPL_REL;
842 140 gabrielosh
        @(negedge clk);
843 173 gabrielosh
        check;
844 127 gabrielosh
 
845
        // BVC
846
        alu_opcode = BVC_REL;
847 140 gabrielosh
        @(negedge clk);
848 173 gabrielosh
        check;
849 127 gabrielosh
 
850
        // BVS
851
        alu_opcode = BVS_REL;
852 140 gabrielosh
        @(negedge clk);
853 173 gabrielosh
        check;
854 127 gabrielosh
 
855
        // JMP
856
        alu_opcode = JMP_ABS;
857 140 gabrielosh
        @(negedge clk);
858 173 gabrielosh
        check;
859 127 gabrielosh
 
860
        // JMP
861
        alu_opcode = JMP_IND;
862 140 gabrielosh
        @(negedge clk);
863 173 gabrielosh
        check;
864 127 gabrielosh
 
865
        // JSR
866
        alu_opcode = JSR_ABS;
867 140 gabrielosh
        @(negedge clk);
868 173 gabrielosh
        check;
869 127 gabrielosh
 
870
        // NOP
871
        alu_opcode = NOP_IMP;
872 140 gabrielosh
        @(negedge clk);
873 173 gabrielosh
        check;
874 127 gabrielosh
 
875
        // RTS
876
        alu_opcode = RTS_IMP;
877 140 gabrielosh
        @(negedge clk);
878 173 gabrielosh
        check;
879 127 gabrielosh
 
880
        $display("TEST PASSED");
881
        $finish;
882
end
883
 
884
endmodule
885
 

powered by: WebSVN 2.1.0

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