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

Subversion Repositories t6507lp

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

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 178 gabrielosh
                alu_x_expected = alu_a;
274
                $display("alu_x_expected = %h", alu_x_expected);
275 127 gabrielosh
                //alu_result_expected = i;
276
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
277
                alu_status_expected[N] = alu_x_expected[7];
278
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
279
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
280
                //$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);
281 173 gabrielosh
                check;
282 127 gabrielosh
        end
283
 
284
        // LDY
285
        alu_opcode = LDY_IMM;
286
        for (i = 0; i < 1001; i = i + 1)
287
        begin
288
                alu_a = i;
289 140 gabrielosh
                @(negedge clk);
290 178 gabrielosh
                alu_y_expected = alu_a;
291
                $display("alu_y_expected = %h", alu_y_expected);
292 127 gabrielosh
                //alu_result_expected = i;
293
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
294
                alu_status_expected[N] = alu_y_expected[7];
295
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
296
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
297
                //$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);
298 173 gabrielosh
                check;
299 127 gabrielosh
        end
300
 
301
        // STA
302
        alu_opcode = STA_ABS;
303
        for (i = 0; i < 1000; i = i + 1)
304
        begin
305
                alu_a = i;
306 140 gabrielosh
                @(negedge clk);
307 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
308
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
309
                //$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);
310 178 gabrielosh
                //alu_result_expected = alu_a;
311
                //alu_result_expected = DUT.A;
312 173 gabrielosh
                check;
313 127 gabrielosh
        end
314
 
315
        // STX
316
        alu_opcode = STX_ABS;
317
        for (i = 0; i < 1000; i = i + 1)
318
        begin
319
                alu_a = i;
320 140 gabrielosh
                @(negedge clk);
321 178 gabrielosh
                $display("alu_x_expected = %h", alu_x_expected);
322 127 gabrielosh
                //alu_result_expected = i;
323 178 gabrielosh
                //alu_x_expected = alu_a;
324 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
325
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
326
                //$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);
327 173 gabrielosh
                check;
328 127 gabrielosh
        end
329
 
330
        // STY
331
        alu_opcode = STY_ABS;
332
        for (i = 0; i < 1000; i = i + 1)
333
        begin
334
                alu_a = i;
335 140 gabrielosh
                @(negedge clk);
336 178 gabrielosh
                $display("alu_y_expected = %h", alu_y_expected);
337 127 gabrielosh
                //alu_result_expected = i;
338 178 gabrielosh
                //alu_y_expected = alu_a;
339 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
340
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
341
                //$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);
342 173 gabrielosh
                check;
343 127 gabrielosh
        end
344
 
345
        // CMP
346
        alu_opcode = CMP_IMM;
347
        for (i = 0; i < 1000; i = i + 1)
348
        begin
349
                alu_a = i;
350 140 gabrielosh
                @(negedge clk);
351 127 gabrielosh
                temp = alu_result_expected - alu_a;
352
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
353
                alu_status_expected[N] = temp[7];
354
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
355
                //alu_result_expected = i;
356
                //alu_y_expected = i;
357
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
358
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
359
                //$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);
360 173 gabrielosh
                check;
361 127 gabrielosh
        end
362
 
363
        // CPX
364
        alu_opcode = CPX_IMM;
365
        for (i = 0; i < 1000; i = i + 1)
366
        begin
367
                alu_a = i;
368 140 gabrielosh
                @(negedge clk);
369 127 gabrielosh
                temp = alu_x_expected - alu_a;
370
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
371
                alu_status_expected[N] = temp[7];
372
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
373
                //alu_result_expected = i;
374
                //alu_y_expected = i;
375
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
376
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
377
                //$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);
378 173 gabrielosh
                check;
379 127 gabrielosh
        end
380
 
381
        // CPY
382
        alu_opcode = CPY_IMM;
383
        for (i = 0; i < 1000; i = i + 1)
384
        begin
385
                alu_a = i;
386 140 gabrielosh
                @(negedge clk);
387 127 gabrielosh
                temp = alu_y_expected - alu_a;
388
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
389
                alu_status_expected[N] = temp[7];
390
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
391
                //alu_result_expected = i;
392
                //alu_y_expected = i;
393
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
394
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
395
                //$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);
396 173 gabrielosh
                check;
397 127 gabrielosh
        end
398
 
399
 
400
        // AND
401
        alu_opcode = AND_IMM;
402
        for (i = 0; i < 1000; i = i + 1)
403
        begin
404
                alu_a = i;
405 140 gabrielosh
                @(negedge clk);
406 156 gabrielosh
                alu_result_expected = alu_a & alu_result_expected;
407 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
408
                alu_status_expected[N] = alu_result_expected[7];
409
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
410
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
411
                //$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);
412 173 gabrielosh
                check;
413 127 gabrielosh
        end
414
 
415
        // ASL
416
        alu_opcode = ASL_ACC;
417
        for (i = 0; i < 1000; i = i + 1)
418
        begin
419
                alu_a = i;
420 140 gabrielosh
                @(negedge clk);
421 127 gabrielosh
                alu_status_expected[C] = alu_result_expected[7];
422
                alu_result_expected[7:0] = alu_result_expected << 1;
423
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
424
                alu_status_expected[N] = alu_result_expected[7];
425
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
426
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
427
                //$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);
428 173 gabrielosh
                check;
429 127 gabrielosh
        end
430
 
431
        // INC
432
        alu_opcode = INC_ZPG;
433
        for (i = 0; i < 1000; i = i + 1)
434
        begin
435
                alu_a = i;
436 140 gabrielosh
                @(negedge clk);
437 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
438
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
439
                //$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);
440
                alu_result_expected = alu_a + 1;
441
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
442
                alu_status_expected[N] = alu_result_expected[7];
443 173 gabrielosh
                check;
444 127 gabrielosh
        end
445
 
446
        // INX
447
        alu_opcode = INX_IMP;
448
        for (i = 0; i < 1000; i = i + 1)
449
        begin
450
                alu_a = i;
451 140 gabrielosh
                @(negedge clk);
452 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
453
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
454
                //$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);
455
                alu_x_expected = alu_x_expected + 1;
456
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
457
                alu_status_expected[N] = alu_x_expected[7];
458 173 gabrielosh
                check;
459 127 gabrielosh
        end
460
 
461
        // INY
462
        alu_opcode = INY_IMP;
463
        for (i = 0; i < 1000; i = i + 1)
464
        begin
465
                alu_a = i;
466 140 gabrielosh
                @(negedge clk);
467 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
468
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
469
                //$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);
470
                alu_y_expected = alu_y_expected + 1;
471
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
472
                alu_status_expected[N] = alu_y_expected[7];
473 173 gabrielosh
                check;
474 127 gabrielosh
        end
475
 
476
        // DEC
477
        alu_opcode = DEC_ZPG;
478
        for (i = 0; i < 1000; i = i + 1)
479
        begin
480
                alu_a = i;
481 140 gabrielosh
                @(negedge clk);
482 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
483
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
484
                //$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);
485
                alu_result_expected = alu_a - 1;
486
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
487
                alu_status_expected[N] = alu_result_expected[7];
488 173 gabrielosh
                check;
489 127 gabrielosh
        end
490
 
491
        // DEX
492
        alu_opcode = DEX_IMP;
493
        for (i = 0; i < 1000; i = i + 1)
494
        begin
495
                alu_a = i;
496 140 gabrielosh
                @(negedge clk);
497 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
498
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
499
                //$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);
500
                alu_x_expected = alu_x_expected - 1;
501
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
502
                alu_status_expected[N] = alu_x_expected[7];
503 173 gabrielosh
                check;
504 127 gabrielosh
        end
505
 
506
        // DEY
507
        alu_opcode = DEY_IMP;
508
        for (i = 0; i < 1000; i = i + 1)
509
        begin
510
                alu_a = i;
511 140 gabrielosh
                @(negedge clk);
512 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
513
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
514
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
515
                alu_y_expected = alu_y_expected - 1;
516
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
517
                alu_status_expected[N] = alu_y_expected[7];
518 173 gabrielosh
                check;
519 127 gabrielosh
        end
520
 
521
 
522
        // LDA
523
        alu_a = 0;
524
        alu_opcode = LDA_IMM;
525
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
526
        //$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);
527 140 gabrielosh
        @(negedge clk);
528 127 gabrielosh
        alu_result_expected = 8'h00;
529
        //                       NV1BDIZC
530
        alu_status_expected = 8'b00100010;
531 173 gabrielosh
        check;
532 127 gabrielosh
 
533
        // BIT
534
        alu_opcode = BIT_ZPG;
535
        for (i = 0; i < 1000; i = i + 1)
536
        begin
537
                alu_a = i;
538 140 gabrielosh
                @(negedge clk);
539 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
540
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
541
                //$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);
542 127 gabrielosh
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
543
                alu_status_expected[V] = alu_a[6];
544
                alu_status_expected[N] = alu_a[7];
545 173 gabrielosh
                check;
546 127 gabrielosh
        end
547 158 gabrielosh
 
548 176 gabrielosh
        // RTI
549
        alu_opcode = RTI_IMP;
550
        for (i = 0; i < 1000; i = i + 1)
551
        begin
552
                alu_a = i;
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
                alu_status_expected[C] = alu_a[C];
558
                alu_status_expected[Z] = alu_a[Z];
559
                alu_status_expected[N] = alu_a[N];
560
                alu_status_expected[V] = alu_a[V];
561
                alu_status_expected[B] = alu_a[B];
562
                alu_status_expected[D] = alu_a[D];
563
                alu_status_expected[I] = alu_a[I];
564
                check;
565
        end
566 178 gabrielosh
 
567
        // PLP
568
        alu_opcode = PLP_IMP;
569
        for (i = 0; i < 1000; i = i + 1)
570
        begin
571
                alu_a = i;
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
                alu_status_expected[C] = alu_a[C];
577
                alu_status_expected[Z] = alu_a[Z];
578
                alu_status_expected[N] = alu_a[N];
579
                alu_status_expected[V] = alu_a[V];
580
                alu_status_expected[B] = alu_a[B];
581
                alu_status_expected[D] = alu_a[D];
582
                alu_status_expected[I] = alu_a[I];
583
                check;
584
        end
585
 
586 158 gabrielosh
        // PHA
587
        alu_opcode = PHA_IMP;
588
        @(negedge clk);
589
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
590
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
591
        //$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);
592 178 gabrielosh
        //alu_result_expected = DUT.A;
593
        alu_result_expected = alu_a;
594 173 gabrielosh
        check;
595 158 gabrielosh
 
596
        // PHP
597
        alu_opcode = PHP_IMP;
598
        @(negedge clk);
599
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
600
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
601
        //$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);
602 173 gabrielosh
        //alu_status_expected = DUT.STATUS;
603
        check;
604 158 gabrielosh
 
605
        // BRK
606
        alu_opcode = BRK_IMP;
607
        @(negedge clk);
608
        alu_status_expected[B] = 1;
609 173 gabrielosh
        check;
610 158 gabrielosh
 
611 127 gabrielosh
        // SEC
612
        alu_opcode = SEC_IMP;
613 140 gabrielosh
        @(negedge clk);
614 127 gabrielosh
        alu_status_expected[C] = 1;
615 173 gabrielosh
        check;
616 127 gabrielosh
 
617
        // SED
618
        alu_opcode = SED_IMP;
619 140 gabrielosh
        @(negedge clk);
620 127 gabrielosh
        alu_status_expected[D] = 1;
621 173 gabrielosh
        check;
622 127 gabrielosh
 
623
        // SEI
624
        alu_opcode = SEI_IMP;
625 140 gabrielosh
        @(negedge clk);
626 127 gabrielosh
        alu_status_expected[I] = 1;
627 173 gabrielosh
        check;
628 127 gabrielosh
 
629
        // CLC
630
        alu_opcode = CLC_IMP;
631 140 gabrielosh
        @(negedge clk);
632 127 gabrielosh
        alu_status_expected[C] = 0;
633 173 gabrielosh
        check;
634 127 gabrielosh
 
635
        // CLD
636
        alu_opcode = CLD_IMP;
637 140 gabrielosh
        @(negedge clk);
638 127 gabrielosh
        alu_status_expected[D] = 0;
639 173 gabrielosh
        check;
640 127 gabrielosh
 
641
        // CLI
642
        alu_opcode = CLI_IMP;
643 140 gabrielosh
        @(negedge clk);
644 127 gabrielosh
        alu_status_expected[I] = 0;
645 173 gabrielosh
        check;
646 127 gabrielosh
 
647
        // CLV
648
        alu_opcode = CLV_IMP;
649 140 gabrielosh
        @(negedge clk);
650 127 gabrielosh
        alu_status_expected[V] = 0;
651 173 gabrielosh
        check;
652 127 gabrielosh
 
653
        // LDA
654
        alu_opcode = LDA_IMM;
655
        alu_a = 8'h76;
656 140 gabrielosh
        @(negedge clk);
657 127 gabrielosh
        alu_result_expected = alu_a;
658
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
659
        alu_status_expected[N] = alu_result_expected[7];
660 173 gabrielosh
        check;
661 127 gabrielosh
 
662
        // TAX
663
        alu_opcode = TAX_IMP;
664 140 gabrielosh
        @(negedge clk);
665 127 gabrielosh
        alu_x_expected = alu_result_expected;
666
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
667
        alu_status_expected[N] = alu_x_expected[7];
668 173 gabrielosh
        check;
669 127 gabrielosh
 
670
        // TAY
671
        alu_opcode = TAY_IMP;
672 140 gabrielosh
        @(negedge clk);
673 127 gabrielosh
        alu_y_expected = alu_result_expected;
674
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
675
        alu_status_expected[N] = alu_y_expected[7];
676 173 gabrielosh
        check;
677 127 gabrielosh
 
678
        // TSX
679
        alu_opcode = TSX_IMP;
680 140 gabrielosh
        @(negedge clk);
681 127 gabrielosh
        alu_x_expected = alu_a;
682
        //alu_result_expected = alu_a;
683
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
684
        alu_status_expected[N] = alu_x_expected[7];
685 173 gabrielosh
        check;
686 127 gabrielosh
 
687
        // TXA
688
        alu_opcode = TXA_IMP;
689 140 gabrielosh
        @(negedge clk);
690 127 gabrielosh
        alu_result_expected = alu_x_expected;
691
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
692
        alu_status_expected[N] = alu_result_expected[7];
693 173 gabrielosh
        check;
694 127 gabrielosh
 
695
        // TXS
696
        alu_opcode = TXS_IMP;
697 140 gabrielosh
        @(negedge clk);
698 127 gabrielosh
        alu_result_expected = alu_x_expected;
699 173 gabrielosh
        check;
700 127 gabrielosh
 
701
        // TYA
702
        alu_opcode = TYA_IMP;
703 140 gabrielosh
        @(negedge clk);
704 127 gabrielosh
        alu_result_expected = alu_y_expected;
705
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
706
        alu_status_expected[N] = alu_result_expected[7];
707 173 gabrielosh
        check;
708 127 gabrielosh
 
709
        // Nothing should happen
710
        // BCC
711
        alu_opcode = BCC_REL;
712 140 gabrielosh
        @(negedge clk);
713 173 gabrielosh
        check;
714 127 gabrielosh
 
715
        // BCS
716
        alu_opcode = BCS_REL;
717 140 gabrielosh
        @(negedge clk);
718 173 gabrielosh
        check;
719 127 gabrielosh
 
720
        // BEQ
721
        alu_opcode = BEQ_REL;
722 140 gabrielosh
        @(negedge clk);
723 173 gabrielosh
        check;
724 127 gabrielosh
 
725
        // BMI
726
        alu_opcode = BMI_REL;
727 140 gabrielosh
        @(negedge clk);
728 173 gabrielosh
        check;
729 127 gabrielosh
 
730
        // BNE
731
        alu_opcode = BNE_REL;
732 140 gabrielosh
        @(negedge clk);
733 173 gabrielosh
        check;
734 127 gabrielosh
 
735
        // BPL
736
        alu_opcode = BPL_REL;
737 140 gabrielosh
        @(negedge clk);
738 173 gabrielosh
        check;
739 127 gabrielosh
 
740
        // BVC
741
        alu_opcode = BVC_REL;
742 140 gabrielosh
        @(negedge clk);
743 173 gabrielosh
        check;
744 127 gabrielosh
 
745
        // BVS
746
        alu_opcode = BVS_REL;
747 140 gabrielosh
        @(negedge clk);
748 173 gabrielosh
        check;
749 127 gabrielosh
 
750
        // JMP
751
        alu_opcode = JMP_ABS;
752 140 gabrielosh
        @(negedge clk);
753 173 gabrielosh
        check;
754 127 gabrielosh
 
755
        // JMP
756
        alu_opcode = JMP_IND;
757 140 gabrielosh
        @(negedge clk);
758 173 gabrielosh
        check;
759 127 gabrielosh
 
760
        // JSR
761
        alu_opcode = JSR_ABS;
762 140 gabrielosh
        @(negedge clk);
763 173 gabrielosh
        check;
764 127 gabrielosh
 
765
        // NOP
766
        alu_opcode = NOP_IMP;
767 140 gabrielosh
        @(negedge clk);
768 173 gabrielosh
        check;
769 127 gabrielosh
 
770
        // RTS
771
        alu_opcode = RTS_IMP;
772 140 gabrielosh
        @(negedge clk);
773 173 gabrielosh
        check;
774 127 gabrielosh
 
775
        $display("TEST PASSED");
776
        $finish;
777
end
778
 
779
endmodule
780
 

powered by: WebSVN 2.1.0

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