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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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