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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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