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

Subversion Repositories t6507lp

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

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
reg c_aux;
23
reg [7:0] temp;
24 156 gabrielosh
reg sign;
25 127 gabrielosh
 
26 136 gabrielosh
t6507lp_alu DUT (
27
                        .clk            (clk),
28
                        .reset_n        (reset_n),
29 127 gabrielosh
                        .alu_enable     (alu_enable),
30
                        .alu_result     (alu_result),
31
                        .alu_status     (alu_status),
32
                        .alu_opcode     (alu_opcode),
33
                        .alu_a          (alu_a),
34
                        .alu_x          (alu_x),
35
                        .alu_y          (alu_y)
36
                );
37
 
38
 
39
localparam period = 10;
40
 
41
task check;
42
        begin
43
                $display("               RESULTS       EXPECTED");
44
                $display("alu_result       %h             %h   ", alu_result, alu_result_expected);
45
                $display("alu_status    %b       %b   ", alu_status, alu_status_expected);
46
                $display("alu_x            %h             %h   ", alu_x,      alu_x_expected     );
47
                $display("alu_y            %h             %h   ", alu_y,      alu_y_expected     );
48 150 gabrielosh
                if ((alu_result_expected == alu_result) && (alu_status_expected == alu_status) && (alu_x_expected == alu_x) && (alu_y_expected == alu_y))
49 127 gabrielosh
                begin
50 150 gabrielosh
                        $display("Instruction %h... OK!", alu_opcode);
51 127 gabrielosh
                end
52
                else
53
                begin
54 150 gabrielosh
                        $display("ERROR at instruction %h",alu_opcode);
55
                        $finish;
56 127 gabrielosh
                end
57
        end
58
endtask
59
 
60
 
61
always begin
62 136 gabrielosh
        #(period/2) clk = ~clk;
63 127 gabrielosh
end
64
 
65
initial
66
begin
67
        // Reset
68 136 gabrielosh
        clk = 0;
69
        reset_n = 0;
70 140 gabrielosh
        @(negedge clk);
71 150 gabrielosh
        //@(negedge clk);
72 148 gabrielosh
        reset_n = 1;
73 127 gabrielosh
        alu_enable = 1;
74
        alu_result_expected = 8'h00;
75
        alu_status_expected = 8'b00100010;
76
        alu_x_expected = 8'h00;
77
        alu_y_expected = 8'h00;
78
 
79
        // LDA
80
        alu_a = 0;
81
        alu_opcode = LDA_IMM;
82
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
83
        //$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);
84 140 gabrielosh
        @(negedge clk);
85 127 gabrielosh
        alu_result_expected = 8'h00;
86
        //                       NV1BDIZC
87 149 gabrielosh
    alu_status_expected = 8'b00100010;
88 127 gabrielosh
        check();
89
 
90
        // ADC
91
        alu_opcode = ADC_IMM;
92
        alu_a = 1;
93
        for (i = 0; i < 1000; i = i + 1)
94
        begin
95 149 gabrielosh
                alu_a = $random;
96 140 gabrielosh
                @(negedge clk);
97 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
98
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
99
                //$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);
100 156 gabrielosh
                sign = alu_result_expected[7];
101 127 gabrielosh
                {alu_status_expected[C], alu_result_expected} = alu_a + alu_result_expected + alu_status_expected[C];
102
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
103
                alu_status_expected[N] = alu_result_expected[7];
104 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
105 127 gabrielosh
                check();
106
        end
107
 
108 161 gabrielosh
/*      // BCD
109
        // LDA
110
        alu_a = 0;
111
        alu_opcode = LDA_IMM;
112
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
113
        //$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);
114
        @(negedge clk);
115
        alu_result_expected = 8'h00;
116
        //                       NV1BDIZC
117
    alu_status_expected = 8'b00101010;
118
        check();
119
 
120
        // ADC
121
        alu_opcode = ADC_IMM;
122
        for (i = 0; i < 1000; i = i + 1)
123
        begin
124
                alu_a = $random;
125
                @(negedge clk);
126
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
127
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
128
                //$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);
129
                sign = alu_result_expected[7];
130
                {alu_status_expected[C], alu_result_expected} = alu_a + alu_result_expected + alu_status_expected[C];
131
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
132
                alu_status_expected[N] = alu_result_expected[7];
133
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
134
                check();
135
        end
136
*/
137
 
138 148 gabrielosh
        // ASL
139 145 gabrielosh
        alu_opcode = ASL_ABS;
140
        for (i = 0; i < 1000; i = i + 1)
141
        begin
142
                alu_a = i;
143
                @(negedge clk);
144
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
145
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
146
                //$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);
147
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
148
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
149
                alu_status_expected[N] = alu_result_expected[7];
150
                check();
151
        end
152
 
153
        // LDA
154 156 gabrielosh
        alu_a = 137;
155
        alu_opcode = LDA_IMM;
156
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
157
        //$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);
158
        @(negedge clk);
159
        alu_result_expected = 8'd137;
160
        //                       NV1BDIZC
161
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
162
        alu_status_expected[N] = alu_result_expected[7];
163
        check();
164
 
165
        // EOR
166
        alu_opcode = EOR_IMM;
167
        for (i = 0; i < 1000; i = i + 1)
168
        begin
169
                alu_a = i;
170
                @(negedge clk);
171
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
172
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
173
                //$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);
174
                $display("result_expected = %d",alu_result_expected);
175
                alu_result_expected = alu_a ^ alu_result_expected;
176
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
177
                alu_status_expected[N] = alu_result_expected[7];
178
                $display("result_expected = %d", alu_result_expected);
179
                check();
180
        end
181
 
182
        // LDA
183 145 gabrielosh
        alu_a = 0;
184
        alu_opcode = LDA_IMM;
185
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
186
        //$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);
187
        @(negedge clk);
188
        alu_result_expected = 8'h00;
189
        //                       NV1BDIZC
190
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
191
        alu_status_expected[N] = alu_result_expected[7];
192
        check();
193
 
194 127 gabrielosh
        // SBC
195
        alu_opcode = SBC_IMM;
196
        for (i = 0; i < 1000; i = i + 1)
197
        begin
198 145 gabrielosh
                alu_a = 1;
199 140 gabrielosh
                @(negedge clk);
200 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
201
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
202
                //$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);
203 156 gabrielosh
                sign = alu_result_expected[7];
204 127 gabrielosh
                {alu_status_expected[C], alu_result_expected} = alu_result_expected - alu_a - ~alu_status_expected[C];
205
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
206
                alu_status_expected[N] = alu_result_expected[7];
207 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
208 127 gabrielosh
                check();
209
        end
210
 
211
        // LDA
212
        alu_opcode = LDA_IMM;
213
        for (i = 0; i < 1000; i = i + 1)
214
        begin
215
                alu_a = i;
216 140 gabrielosh
                @(negedge clk);
217 127 gabrielosh
                alu_result_expected = i;
218
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
219
                alu_status_expected[N] = alu_result_expected[7];
220
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
221
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
222
                //$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);
223
                check();
224
        end
225
 
226
        // LDX
227
        alu_opcode = LDX_IMM;
228
        for (i = 0; i < 1000; i = i + 1)
229
        begin
230
                alu_a = i;
231 140 gabrielosh
                @(negedge clk);
232 127 gabrielosh
                alu_x_expected = i;
233
                //alu_result_expected = i;
234
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
235
                alu_status_expected[N] = alu_x_expected[7];
236
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
237
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
238
                //$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);
239
                check();
240
        end
241
 
242
        // LDY
243
        alu_opcode = LDY_IMM;
244
        for (i = 0; i < 1001; i = i + 1)
245
        begin
246
                alu_a = i;
247 140 gabrielosh
                @(negedge clk);
248 127 gabrielosh
                alu_y_expected = i;
249
                //alu_result_expected = i;
250
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
251
                alu_status_expected[N] = alu_y_expected[7];
252
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
253
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
254
                //$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);
255
                check();
256
        end
257
 
258
        // STA
259
        alu_opcode = STA_ABS;
260
        for (i = 0; i < 1000; i = i + 1)
261
        begin
262
                alu_a = i;
263 140 gabrielosh
                @(negedge clk);
264 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
265
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
266
                //$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);
267
                check();
268
        end
269
 
270
        // STX
271
        alu_opcode = STX_ABS;
272
        for (i = 0; i < 1000; i = i + 1)
273
        begin
274
                alu_a = i;
275 140 gabrielosh
                @(negedge clk);
276 127 gabrielosh
                //alu_result_expected = i;
277
                //alu_x_expected = i;
278
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
279
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
280
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
281
                check();
282
        end
283
 
284
        // STY
285
        alu_opcode = STY_ABS;
286
        for (i = 0; i < 1000; i = i + 1)
287
        begin
288
                alu_a = i;
289 140 gabrielosh
                @(negedge clk);
290 127 gabrielosh
                //alu_result_expected = i;
291
                //alu_y_expected = i;
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
                check();
296
        end
297
 
298
        // CMP
299
        alu_opcode = CMP_IMM;
300
        for (i = 0; i < 1000; i = i + 1)
301
        begin
302
                alu_a = i;
303 140 gabrielosh
                @(negedge clk);
304 127 gabrielosh
                temp = alu_result_expected - alu_a;
305
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
306
                alu_status_expected[N] = temp[7];
307
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
308
                //alu_result_expected = i;
309
                //alu_y_expected = i;
310
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
311
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
312
                //$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);
313
                check();
314
        end
315
 
316
        // CPX
317
        alu_opcode = CPX_IMM;
318
        for (i = 0; i < 1000; i = i + 1)
319
        begin
320
                alu_a = i;
321 140 gabrielosh
                @(negedge clk);
322 127 gabrielosh
                temp = alu_x_expected - alu_a;
323
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
324
                alu_status_expected[N] = temp[7];
325
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
326
                //alu_result_expected = i;
327
                //alu_y_expected = i;
328
                //$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
                check();
332
        end
333
 
334
        // CPY
335
        alu_opcode = CPY_IMM;
336
        for (i = 0; i < 1000; i = i + 1)
337
        begin
338
                alu_a = i;
339 140 gabrielosh
                @(negedge clk);
340 127 gabrielosh
                temp = alu_y_expected - alu_a;
341
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
342
                alu_status_expected[N] = temp[7];
343
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
344
                //alu_result_expected = i;
345
                //alu_y_expected = i;
346
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
347
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
348
                //$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);
349
                check();
350
        end
351
 
352
 
353
        // AND
354
        alu_opcode = AND_IMM;
355
        for (i = 0; i < 1000; i = i + 1)
356
        begin
357
                alu_a = i;
358 140 gabrielosh
                @(negedge clk);
359 156 gabrielosh
                alu_result_expected = alu_a & alu_result_expected;
360 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
361
                alu_status_expected[N] = alu_result_expected[7];
362
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
363
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
364
                //$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);
365
                check();
366
        end
367
 
368
        // ASL
369
        alu_opcode = ASL_ACC;
370
        for (i = 0; i < 1000; i = i + 1)
371
        begin
372
                alu_a = i;
373 140 gabrielosh
                @(negedge clk);
374 127 gabrielosh
                alu_status_expected[C] = alu_result_expected[7];
375
                alu_result_expected[7:0] = alu_result_expected << 1;
376
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
377
                alu_status_expected[N] = alu_result_expected[7];
378
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
379
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
380
                //$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);
381
                check();
382
        end
383
 
384
        // INC
385
        alu_opcode = INC_ZPG;
386
        for (i = 0; i < 1000; i = i + 1)
387
        begin
388
                alu_a = i;
389 140 gabrielosh
                @(negedge clk);
390 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
391
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
392
                //$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);
393
                alu_result_expected = alu_a + 1;
394
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
395
                alu_status_expected[N] = alu_result_expected[7];
396
                check();
397
        end
398
 
399
        // INX
400
        alu_opcode = INX_IMP;
401
        for (i = 0; i < 1000; i = i + 1)
402
        begin
403
                alu_a = i;
404 140 gabrielosh
                @(negedge clk);
405 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
406
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
407
                //$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);
408
                alu_x_expected = alu_x_expected + 1;
409
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
410
                alu_status_expected[N] = alu_x_expected[7];
411
                check();
412
        end
413
 
414
        // INY
415
        alu_opcode = INY_IMP;
416
        for (i = 0; i < 1000; i = i + 1)
417
        begin
418
                alu_a = i;
419 140 gabrielosh
                @(negedge clk);
420 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
421
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
422
                //$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);
423
                alu_y_expected = alu_y_expected + 1;
424
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
425
                alu_status_expected[N] = alu_y_expected[7];
426
                check();
427
        end
428
 
429
        // DEC
430
        alu_opcode = DEC_ZPG;
431
        for (i = 0; i < 1000; i = i + 1)
432
        begin
433
                alu_a = i;
434 140 gabrielosh
                @(negedge clk);
435 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
436
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
437
                //$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);
438
                alu_result_expected = alu_a - 1;
439
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
440
                alu_status_expected[N] = alu_result_expected[7];
441
                check();
442
        end
443
 
444
        // DEX
445
        alu_opcode = DEX_IMP;
446
        for (i = 0; i < 1000; i = i + 1)
447
        begin
448
                alu_a = i;
449 140 gabrielosh
                @(negedge clk);
450 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
451
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
452
                //$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);
453
                alu_x_expected = alu_x_expected - 1;
454
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
455
                alu_status_expected[N] = alu_x_expected[7];
456
                check();
457
        end
458
 
459
        // DEY
460
        alu_opcode = DEY_IMP;
461
        for (i = 0; i < 1000; i = i + 1)
462
        begin
463
                alu_a = i;
464 140 gabrielosh
                @(negedge clk);
465 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
466
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
467
                //$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);
468
                alu_y_expected = alu_y_expected - 1;
469
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
470
                alu_status_expected[N] = alu_y_expected[7];
471
                check();
472
        end
473
 
474
 
475
        // LDA
476
        alu_a = 0;
477
        alu_opcode = LDA_IMM;
478
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
479
        //$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);
480 140 gabrielosh
        @(negedge clk);
481 127 gabrielosh
        alu_result_expected = 8'h00;
482
        //                       NV1BDIZC
483
        alu_status_expected = 8'b00100010;
484
        check();
485
 
486
        // BIT
487
        alu_opcode = BIT_ZPG;
488
        for (i = 0; i < 1000; i = i + 1)
489
        begin
490
                alu_a = i;
491 140 gabrielosh
                @(negedge clk);
492 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
493
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
494
                //$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);
495 127 gabrielosh
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
496
                alu_status_expected[V] = alu_a[6];
497
                alu_status_expected[N] = alu_a[7];
498
                check();
499
        end
500 158 gabrielosh
 
501
        // PHA
502
        alu_opcode = PHA_IMP;
503
        @(negedge clk);
504
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
505
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
506
        //$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);
507
        alu_result_expected = DUT.A;
508
        check();
509
 
510
        // PHP
511
        alu_opcode = PHP_IMP;
512
        @(negedge clk);
513
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
514
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
515
        //$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);
516
        alu_status_expected = DUT.STATUS;
517
        check();
518
 
519
        // BRK
520
        alu_opcode = BRK_IMP;
521
        @(negedge clk);
522
        alu_status_expected[B] = 1;
523
        check();
524
 
525 127 gabrielosh
        // SEC
526
        alu_opcode = SEC_IMP;
527 140 gabrielosh
        @(negedge clk);
528 127 gabrielosh
        alu_status_expected[C] = 1;
529
        check();
530
 
531
        // SED
532
        alu_opcode = SED_IMP;
533 140 gabrielosh
        @(negedge clk);
534 127 gabrielosh
        alu_status_expected[D] = 1;
535
        check();
536
 
537
        // SEI
538
        alu_opcode = SEI_IMP;
539 140 gabrielosh
        @(negedge clk);
540 127 gabrielosh
        alu_status_expected[I] = 1;
541
        check();
542
 
543
        // CLC
544
        alu_opcode = CLC_IMP;
545 140 gabrielosh
        @(negedge clk);
546 127 gabrielosh
        alu_status_expected[C] = 0;
547
        check();
548
 
549
        // CLD
550
        alu_opcode = CLD_IMP;
551 140 gabrielosh
        @(negedge clk);
552 127 gabrielosh
        alu_status_expected[D] = 0;
553
        check();
554
 
555
        // CLI
556
        alu_opcode = CLI_IMP;
557 140 gabrielosh
        @(negedge clk);
558 127 gabrielosh
        alu_status_expected[I] = 0;
559
        check();
560
 
561
        // CLV
562
        alu_opcode = CLV_IMP;
563 140 gabrielosh
        @(negedge clk);
564 127 gabrielosh
        alu_status_expected[V] = 0;
565
        check();
566
 
567
        // LDA
568
        alu_opcode = LDA_IMM;
569
        alu_a = 8'h76;
570 140 gabrielosh
        @(negedge clk);
571 127 gabrielosh
        alu_result_expected = alu_a;
572
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
573
        alu_status_expected[N] = alu_result_expected[7];
574
        check();
575
 
576
        // TAX
577
        alu_opcode = TAX_IMP;
578 140 gabrielosh
        @(negedge clk);
579 127 gabrielosh
        alu_x_expected = alu_result_expected;
580
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
581
        alu_status_expected[N] = alu_x_expected[7];
582
        check();
583
 
584
        // TAY
585
        alu_opcode = TAY_IMP;
586 140 gabrielosh
        @(negedge clk);
587 127 gabrielosh
        alu_y_expected = alu_result_expected;
588
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
589
        alu_status_expected[N] = alu_y_expected[7];
590
        check();
591
 
592
        // TSX
593
        alu_opcode = TSX_IMP;
594 140 gabrielosh
        @(negedge clk);
595 127 gabrielosh
        alu_x_expected = alu_a;
596
        //alu_result_expected = alu_a;
597
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
598
        alu_status_expected[N] = alu_x_expected[7];
599
        check();
600
 
601
        // TXA
602
        alu_opcode = TXA_IMP;
603 140 gabrielosh
        @(negedge clk);
604 127 gabrielosh
        alu_result_expected = alu_x_expected;
605
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
606
        alu_status_expected[N] = alu_result_expected[7];
607
        check();
608
 
609
        // TXS
610
        alu_opcode = TXS_IMP;
611 140 gabrielosh
        @(negedge clk);
612 127 gabrielosh
        alu_result_expected = alu_x_expected;
613
        check();
614
 
615
        // TYA
616
        alu_opcode = TYA_IMP;
617 140 gabrielosh
        @(negedge clk);
618 127 gabrielosh
        alu_result_expected = alu_y_expected;
619
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
620
        alu_status_expected[N] = alu_result_expected[7];
621
        check();
622
 
623
        // Nothing should happen
624
        // BCC
625
        alu_opcode = BCC_REL;
626 140 gabrielosh
        @(negedge clk);
627 127 gabrielosh
        check();
628
 
629
        // BCS
630
        alu_opcode = BCS_REL;
631 140 gabrielosh
        @(negedge clk);
632 127 gabrielosh
        check();
633
 
634
        // BEQ
635
        alu_opcode = BEQ_REL;
636 140 gabrielosh
        @(negedge clk);
637 127 gabrielosh
        check();
638
 
639
        // BMI
640
        alu_opcode = BMI_REL;
641 140 gabrielosh
        @(negedge clk);
642 127 gabrielosh
        check();
643
 
644
        // BNE
645
        alu_opcode = BNE_REL;
646 140 gabrielosh
        @(negedge clk);
647 127 gabrielosh
        check();
648
 
649
        // BPL
650
        alu_opcode = BPL_REL;
651 140 gabrielosh
        @(negedge clk);
652 127 gabrielosh
        check();
653
 
654
        // BVC
655
        alu_opcode = BVC_REL;
656 140 gabrielosh
        @(negedge clk);
657 127 gabrielosh
        check();
658
 
659
        // BVS
660
        alu_opcode = BVS_REL;
661 140 gabrielosh
        @(negedge clk);
662 127 gabrielosh
        check();
663
 
664
        // JMP
665
        alu_opcode = JMP_ABS;
666 140 gabrielosh
        @(negedge clk);
667 127 gabrielosh
        check();
668
 
669
        // JMP
670
        alu_opcode = JMP_IND;
671 140 gabrielosh
        @(negedge clk);
672 127 gabrielosh
        check();
673
 
674
        // JSR
675
        alu_opcode = JSR_ABS;
676 140 gabrielosh
        @(negedge clk);
677 127 gabrielosh
        check();
678
 
679
        // NOP
680
        alu_opcode = NOP_IMP;
681 140 gabrielosh
        @(negedge clk);
682 127 gabrielosh
        check();
683
 
684
        // RTS
685
        alu_opcode = RTS_IMP;
686 140 gabrielosh
        @(negedge clk);
687 127 gabrielosh
        check();
688
 
689
        $display("TEST PASSED");
690
        $finish;
691
end
692
 
693
endmodule
694
 

powered by: WebSVN 2.1.0

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