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

Subversion Repositories t6507lp

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

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

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

powered by: WebSVN 2.1.0

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