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

Subversion Repositories t6507lp

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

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 176 gabrielosh
        // RTI
543
        alu_opcode = RTI_IMP;
544
        for (i = 0; i < 1000; i = i + 1)
545
        begin
546
                alu_a = i;
547
                @(negedge clk);
548
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
549
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
550
                //$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);
551
                alu_status_expected[C] = alu_a[C];
552
                alu_status_expected[Z] = alu_a[Z];
553
                alu_status_expected[N] = alu_a[N];
554
                alu_status_expected[V] = alu_a[V];
555
                alu_status_expected[B] = alu_a[B];
556
                alu_status_expected[D] = alu_a[D];
557
                alu_status_expected[I] = alu_a[I];
558
                check;
559
        end
560
 
561 158 gabrielosh
        // PHA
562
        alu_opcode = PHA_IMP;
563
        @(negedge clk);
564
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
565
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
566
        //$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);
567
        alu_result_expected = DUT.A;
568 173 gabrielosh
        check;
569 158 gabrielosh
 
570
        // PHP
571
        alu_opcode = PHP_IMP;
572
        @(negedge clk);
573
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
574
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
575
        //$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);
576 173 gabrielosh
        //alu_status_expected = DUT.STATUS;
577
        check;
578 158 gabrielosh
 
579
        // BRK
580
        alu_opcode = BRK_IMP;
581
        @(negedge clk);
582
        alu_status_expected[B] = 1;
583 173 gabrielosh
        check;
584 158 gabrielosh
 
585 127 gabrielosh
        // SEC
586
        alu_opcode = SEC_IMP;
587 140 gabrielosh
        @(negedge clk);
588 127 gabrielosh
        alu_status_expected[C] = 1;
589 173 gabrielosh
        check;
590 127 gabrielosh
 
591
        // SED
592
        alu_opcode = SED_IMP;
593 140 gabrielosh
        @(negedge clk);
594 127 gabrielosh
        alu_status_expected[D] = 1;
595 173 gabrielosh
        check;
596 127 gabrielosh
 
597
        // SEI
598
        alu_opcode = SEI_IMP;
599 140 gabrielosh
        @(negedge clk);
600 127 gabrielosh
        alu_status_expected[I] = 1;
601 173 gabrielosh
        check;
602 127 gabrielosh
 
603
        // CLC
604
        alu_opcode = CLC_IMP;
605 140 gabrielosh
        @(negedge clk);
606 127 gabrielosh
        alu_status_expected[C] = 0;
607 173 gabrielosh
        check;
608 127 gabrielosh
 
609
        // CLD
610
        alu_opcode = CLD_IMP;
611 140 gabrielosh
        @(negedge clk);
612 127 gabrielosh
        alu_status_expected[D] = 0;
613 173 gabrielosh
        check;
614 127 gabrielosh
 
615
        // CLI
616
        alu_opcode = CLI_IMP;
617 140 gabrielosh
        @(negedge clk);
618 127 gabrielosh
        alu_status_expected[I] = 0;
619 173 gabrielosh
        check;
620 127 gabrielosh
 
621
        // CLV
622
        alu_opcode = CLV_IMP;
623 140 gabrielosh
        @(negedge clk);
624 127 gabrielosh
        alu_status_expected[V] = 0;
625 173 gabrielosh
        check;
626 127 gabrielosh
 
627
        // LDA
628
        alu_opcode = LDA_IMM;
629
        alu_a = 8'h76;
630 140 gabrielosh
        @(negedge clk);
631 127 gabrielosh
        alu_result_expected = alu_a;
632
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
633
        alu_status_expected[N] = alu_result_expected[7];
634 173 gabrielosh
        check;
635 127 gabrielosh
 
636
        // TAX
637
        alu_opcode = TAX_IMP;
638 140 gabrielosh
        @(negedge clk);
639 127 gabrielosh
        alu_x_expected = alu_result_expected;
640
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
641
        alu_status_expected[N] = alu_x_expected[7];
642 173 gabrielosh
        check;
643 127 gabrielosh
 
644
        // TAY
645
        alu_opcode = TAY_IMP;
646 140 gabrielosh
        @(negedge clk);
647 127 gabrielosh
        alu_y_expected = alu_result_expected;
648
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
649
        alu_status_expected[N] = alu_y_expected[7];
650 173 gabrielosh
        check;
651 127 gabrielosh
 
652
        // TSX
653
        alu_opcode = TSX_IMP;
654 140 gabrielosh
        @(negedge clk);
655 127 gabrielosh
        alu_x_expected = alu_a;
656
        //alu_result_expected = alu_a;
657
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
658
        alu_status_expected[N] = alu_x_expected[7];
659 173 gabrielosh
        check;
660 127 gabrielosh
 
661
        // TXA
662
        alu_opcode = TXA_IMP;
663 140 gabrielosh
        @(negedge clk);
664 127 gabrielosh
        alu_result_expected = alu_x_expected;
665
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
666
        alu_status_expected[N] = alu_result_expected[7];
667 173 gabrielosh
        check;
668 127 gabrielosh
 
669
        // TXS
670
        alu_opcode = TXS_IMP;
671 140 gabrielosh
        @(negedge clk);
672 127 gabrielosh
        alu_result_expected = alu_x_expected;
673 173 gabrielosh
        check;
674 127 gabrielosh
 
675
        // TYA
676
        alu_opcode = TYA_IMP;
677 140 gabrielosh
        @(negedge clk);
678 127 gabrielosh
        alu_result_expected = alu_y_expected;
679
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
680
        alu_status_expected[N] = alu_result_expected[7];
681 173 gabrielosh
        check;
682 127 gabrielosh
 
683
        // Nothing should happen
684
        // BCC
685
        alu_opcode = BCC_REL;
686 140 gabrielosh
        @(negedge clk);
687 173 gabrielosh
        check;
688 127 gabrielosh
 
689
        // BCS
690
        alu_opcode = BCS_REL;
691 140 gabrielosh
        @(negedge clk);
692 173 gabrielosh
        check;
693 127 gabrielosh
 
694
        // BEQ
695
        alu_opcode = BEQ_REL;
696 140 gabrielosh
        @(negedge clk);
697 173 gabrielosh
        check;
698 127 gabrielosh
 
699
        // BMI
700
        alu_opcode = BMI_REL;
701 140 gabrielosh
        @(negedge clk);
702 173 gabrielosh
        check;
703 127 gabrielosh
 
704
        // BNE
705
        alu_opcode = BNE_REL;
706 140 gabrielosh
        @(negedge clk);
707 173 gabrielosh
        check;
708 127 gabrielosh
 
709
        // BPL
710
        alu_opcode = BPL_REL;
711 140 gabrielosh
        @(negedge clk);
712 173 gabrielosh
        check;
713 127 gabrielosh
 
714
        // BVC
715
        alu_opcode = BVC_REL;
716 140 gabrielosh
        @(negedge clk);
717 173 gabrielosh
        check;
718 127 gabrielosh
 
719
        // BVS
720
        alu_opcode = BVS_REL;
721 140 gabrielosh
        @(negedge clk);
722 173 gabrielosh
        check;
723 127 gabrielosh
 
724
        // JMP
725
        alu_opcode = JMP_ABS;
726 140 gabrielosh
        @(negedge clk);
727 173 gabrielosh
        check;
728 127 gabrielosh
 
729
        // JMP
730
        alu_opcode = JMP_IND;
731 140 gabrielosh
        @(negedge clk);
732 173 gabrielosh
        check;
733 127 gabrielosh
 
734
        // JSR
735
        alu_opcode = JSR_ABS;
736 140 gabrielosh
        @(negedge clk);
737 173 gabrielosh
        check;
738 127 gabrielosh
 
739
        // NOP
740
        alu_opcode = NOP_IMP;
741 140 gabrielosh
        @(negedge clk);
742 173 gabrielosh
        check;
743 127 gabrielosh
 
744
        // RTS
745
        alu_opcode = RTS_IMP;
746 140 gabrielosh
        @(negedge clk);
747 173 gabrielosh
        check;
748 127 gabrielosh
 
749
        $display("TEST PASSED");
750
        $finish;
751
end
752
 
753
endmodule
754
 

powered by: WebSVN 2.1.0

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