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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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