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

Subversion Repositories t6507lp

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

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 148 gabrielosh
        // ASL
109 145 gabrielosh
        alu_opcode = ASL_ABS;
110
        for (i = 0; i < 1000; i = i + 1)
111
        begin
112
                alu_a = i;
113
                @(negedge clk);
114
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
115
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
116
                //$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);
117
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
118
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
119
                alu_status_expected[N] = alu_result_expected[7];
120
                check();
121
        end
122
 
123
        // LDA
124 156 gabrielosh
        alu_a = 137;
125
        alu_opcode = LDA_IMM;
126
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
127
        //$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);
128
        @(negedge clk);
129
        alu_result_expected = 8'd137;
130
        //                       NV1BDIZC
131
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
132
        alu_status_expected[N] = alu_result_expected[7];
133
        check();
134
 
135
        // EOR
136
        alu_opcode = EOR_IMM;
137
        for (i = 0; i < 1000; i = i + 1)
138
        begin
139
                alu_a = i;
140
                @(negedge clk);
141
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
142
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
143
                //$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);
144
                $display("result_expected = %d",alu_result_expected);
145
                alu_result_expected = alu_a ^ alu_result_expected;
146
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
147
                alu_status_expected[N] = alu_result_expected[7];
148
                $display("result_expected = %d", alu_result_expected);
149
                check();
150
        end
151
 
152
        // LDA
153 145 gabrielosh
        alu_a = 0;
154
        alu_opcode = LDA_IMM;
155
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
156
        //$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);
157
        @(negedge clk);
158
        alu_result_expected = 8'h00;
159
        //                       NV1BDIZC
160
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
161
        alu_status_expected[N] = alu_result_expected[7];
162
        check();
163
 
164 127 gabrielosh
        // SBC
165
        alu_opcode = SBC_IMM;
166
        for (i = 0; i < 1000; i = i + 1)
167
        begin
168 145 gabrielosh
                alu_a = 1;
169 140 gabrielosh
                @(negedge clk);
170 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
171
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
172
                //$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);
173 156 gabrielosh
                sign = alu_result_expected[7];
174 127 gabrielosh
                {alu_status_expected[C], alu_result_expected} = alu_result_expected - alu_a - ~alu_status_expected[C];
175
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
176
                alu_status_expected[N] = alu_result_expected[7];
177 156 gabrielosh
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
178 127 gabrielosh
                check();
179
        end
180
 
181
        // LDA
182
        alu_opcode = LDA_IMM;
183
        for (i = 0; i < 1000; i = i + 1)
184
        begin
185
                alu_a = i;
186 140 gabrielosh
                @(negedge clk);
187 127 gabrielosh
                alu_result_expected = i;
188
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
189
                alu_status_expected[N] = alu_result_expected[7];
190
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
191
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
192
                //$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);
193
                check();
194
        end
195
 
196
        // LDX
197
        alu_opcode = LDX_IMM;
198
        for (i = 0; i < 1000; i = i + 1)
199
        begin
200
                alu_a = i;
201 140 gabrielosh
                @(negedge clk);
202 127 gabrielosh
                alu_x_expected = i;
203
                //alu_result_expected = i;
204
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
205
                alu_status_expected[N] = alu_x_expected[7];
206
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
207
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
208
                //$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);
209
                check();
210
        end
211
 
212
        // LDY
213
        alu_opcode = LDY_IMM;
214
        for (i = 0; i < 1001; i = i + 1)
215
        begin
216
                alu_a = i;
217 140 gabrielosh
                @(negedge clk);
218 127 gabrielosh
                alu_y_expected = i;
219
                //alu_result_expected = i;
220
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
221
                alu_status_expected[N] = alu_y_expected[7];
222
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
223
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
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
                check();
226
        end
227
 
228
        // STA
229
        alu_opcode = STA_ABS;
230
        for (i = 0; i < 1000; i = i + 1)
231
        begin
232
                alu_a = i;
233 140 gabrielosh
                @(negedge clk);
234 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
235
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
236
                //$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);
237
                check();
238
        end
239
 
240
        // STX
241
        alu_opcode = STX_ABS;
242
        for (i = 0; i < 1000; i = i + 1)
243
        begin
244
                alu_a = i;
245 140 gabrielosh
                @(negedge clk);
246 127 gabrielosh
                //alu_result_expected = i;
247
                //alu_x_expected = i;
248
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
249
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
250
                //$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);
251
                check();
252
        end
253
 
254
        // STY
255
        alu_opcode = STY_ABS;
256
        for (i = 0; i < 1000; i = i + 1)
257
        begin
258
                alu_a = i;
259 140 gabrielosh
                @(negedge clk);
260 127 gabrielosh
                //alu_result_expected = i;
261
                //alu_y_expected = i;
262
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
263
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
264
                //$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);
265
                check();
266
        end
267
 
268
        // CMP
269
        alu_opcode = CMP_IMM;
270
        for (i = 0; i < 1000; i = i + 1)
271
        begin
272
                alu_a = i;
273 140 gabrielosh
                @(negedge clk);
274 127 gabrielosh
                temp = alu_result_expected - alu_a;
275
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
276
                alu_status_expected[N] = temp[7];
277
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
278
                //alu_result_expected = i;
279
                //alu_y_expected = i;
280
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
281
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
282
                //$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);
283
                check();
284
        end
285
 
286
        // CPX
287
        alu_opcode = CPX_IMM;
288
        for (i = 0; i < 1000; i = i + 1)
289
        begin
290
                alu_a = i;
291 140 gabrielosh
                @(negedge clk);
292 127 gabrielosh
                temp = alu_x_expected - alu_a;
293
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
294
                alu_status_expected[N] = temp[7];
295
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
296
                //alu_result_expected = i;
297
                //alu_y_expected = i;
298
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
299
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
300
                //$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);
301
                check();
302
        end
303
 
304
        // CPY
305
        alu_opcode = CPY_IMM;
306
        for (i = 0; i < 1000; i = i + 1)
307
        begin
308
                alu_a = i;
309 140 gabrielosh
                @(negedge clk);
310 127 gabrielosh
                temp = alu_y_expected - alu_a;
311
                alu_status_expected[Z] = (temp == 0) ? 1 : 0;
312
                alu_status_expected[N] = temp[7];
313
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
314
                //alu_result_expected = i;
315
                //alu_y_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
 
323
        // AND
324
        alu_opcode = AND_IMM;
325
        for (i = 0; i < 1000; i = i + 1)
326
        begin
327
                alu_a = i;
328 140 gabrielosh
                @(negedge clk);
329 156 gabrielosh
                alu_result_expected = alu_a & alu_result_expected;
330 127 gabrielosh
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
331
                alu_status_expected[N] = alu_result_expected[7];
332
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
333
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
334
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
335
                check();
336
        end
337
 
338
        // ASL
339
        alu_opcode = ASL_ACC;
340
        for (i = 0; i < 1000; i = i + 1)
341
        begin
342
                alu_a = i;
343 140 gabrielosh
                @(negedge clk);
344 127 gabrielosh
                alu_status_expected[C] = alu_result_expected[7];
345
                alu_result_expected[7:0] = alu_result_expected << 1;
346
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
347
                alu_status_expected[N] = alu_result_expected[7];
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
        // INC
355
        alu_opcode = INC_ZPG;
356
        for (i = 0; i < 1000; i = i + 1)
357
        begin
358
                alu_a = i;
359 140 gabrielosh
                @(negedge clk);
360 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
361
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
362
                //$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);
363
                alu_result_expected = alu_a + 1;
364
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
365
                alu_status_expected[N] = alu_result_expected[7];
366
                check();
367
        end
368
 
369
        // INX
370
        alu_opcode = INX_IMP;
371
        for (i = 0; i < 1000; i = i + 1)
372
        begin
373
                alu_a = i;
374 140 gabrielosh
                @(negedge clk);
375 127 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
376
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
377
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
378
                alu_x_expected = alu_x_expected + 1;
379
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
380
                alu_status_expected[N] = alu_x_expected[7];
381
                check();
382
        end
383
 
384
        // INY
385
        alu_opcode = INY_IMP;
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_y_expected = alu_y_expected + 1;
394
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
395
                alu_status_expected[N] = alu_y_expected[7];
396
                check();
397
        end
398
 
399
        // DEC
400
        alu_opcode = DEC_ZPG;
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_result_expected = alu_a - 1;
409
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
410
                alu_status_expected[N] = alu_result_expected[7];
411
                check();
412
        end
413
 
414
        // DEX
415
        alu_opcode = DEX_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_x_expected = alu_x_expected - 1;
424
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
425
                alu_status_expected[N] = alu_x_expected[7];
426
                check();
427
        end
428
 
429
        // DEY
430
        alu_opcode = DEY_IMP;
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_y_expected = alu_y_expected - 1;
439
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
440
                alu_status_expected[N] = alu_y_expected[7];
441
                check();
442
        end
443
 
444
 
445
        // LDA
446
        alu_a = 0;
447
        alu_opcode = LDA_IMM;
448
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
449
        //$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);
450 140 gabrielosh
        @(negedge clk);
451 127 gabrielosh
        alu_result_expected = 8'h00;
452
        //                       NV1BDIZC
453
        alu_status_expected = 8'b00100010;
454
        check();
455
 
456
        // BIT
457
        alu_opcode = BIT_ZPG;
458
        for (i = 0; i < 1000; i = i + 1)
459
        begin
460
                alu_a = i;
461 140 gabrielosh
                @(negedge clk);
462 149 gabrielosh
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
463
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
464
                //$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);
465 127 gabrielosh
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
466
                alu_status_expected[V] = alu_a[6];
467
                alu_status_expected[N] = alu_a[7];
468
                check();
469
        end
470
 
471
        // SEC
472
        alu_opcode = SEC_IMP;
473 140 gabrielosh
        @(negedge clk);
474 127 gabrielosh
        alu_status_expected[C] = 1;
475
        check();
476
 
477
        // SED
478
        alu_opcode = SED_IMP;
479 140 gabrielosh
        @(negedge clk);
480 127 gabrielosh
        alu_status_expected[D] = 1;
481
        check();
482
 
483
        // SEI
484
        alu_opcode = SEI_IMP;
485 140 gabrielosh
        @(negedge clk);
486 127 gabrielosh
        alu_status_expected[I] = 1;
487
        check();
488
 
489
        // CLC
490
        alu_opcode = CLC_IMP;
491 140 gabrielosh
        @(negedge clk);
492 127 gabrielosh
        alu_status_expected[C] = 0;
493
        check();
494
 
495
        // CLD
496
        alu_opcode = CLD_IMP;
497 140 gabrielosh
        @(negedge clk);
498 127 gabrielosh
        alu_status_expected[D] = 0;
499
        check();
500
 
501
        // CLI
502
        alu_opcode = CLI_IMP;
503 140 gabrielosh
        @(negedge clk);
504 127 gabrielosh
        alu_status_expected[I] = 0;
505
        check();
506
 
507
        // CLV
508
        alu_opcode = CLV_IMP;
509 140 gabrielosh
        @(negedge clk);
510 127 gabrielosh
        alu_status_expected[V] = 0;
511
        check();
512
 
513
        // LDA
514
        alu_opcode = LDA_IMM;
515
        alu_a = 8'h76;
516 140 gabrielosh
        @(negedge clk);
517 127 gabrielosh
        alu_result_expected = alu_a;
518
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
519
        alu_status_expected[N] = alu_result_expected[7];
520
        check();
521
 
522
        // TAX
523
        alu_opcode = TAX_IMP;
524 140 gabrielosh
        @(negedge clk);
525 127 gabrielosh
        alu_x_expected = alu_result_expected;
526
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
527
        alu_status_expected[N] = alu_x_expected[7];
528
        check();
529
 
530
        // TAY
531
        alu_opcode = TAY_IMP;
532 140 gabrielosh
        @(negedge clk);
533 127 gabrielosh
        alu_y_expected = alu_result_expected;
534
        alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
535
        alu_status_expected[N] = alu_y_expected[7];
536
        check();
537
 
538
        // TSX
539
        alu_opcode = TSX_IMP;
540 140 gabrielosh
        @(negedge clk);
541 127 gabrielosh
        alu_x_expected = alu_a;
542
        //alu_result_expected = alu_a;
543
        alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
544
        alu_status_expected[N] = alu_x_expected[7];
545
        check();
546
 
547
        // TXA
548
        alu_opcode = TXA_IMP;
549 140 gabrielosh
        @(negedge clk);
550 127 gabrielosh
        alu_result_expected = alu_x_expected;
551
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
552
        alu_status_expected[N] = alu_result_expected[7];
553
        check();
554
 
555
        // TXS
556
        alu_opcode = TXS_IMP;
557 140 gabrielosh
        @(negedge clk);
558 127 gabrielosh
        alu_result_expected = alu_x_expected;
559
        check();
560
 
561
        // TYA
562
        alu_opcode = TYA_IMP;
563 140 gabrielosh
        @(negedge clk);
564 127 gabrielosh
        alu_result_expected = alu_y_expected;
565
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
566
        alu_status_expected[N] = alu_result_expected[7];
567
        check();
568
 
569
        // Nothing should happen
570
        // BCC
571
        alu_opcode = BCC_REL;
572 140 gabrielosh
        @(negedge clk);
573 127 gabrielosh
        check();
574
 
575
        // BCS
576
        alu_opcode = BCS_REL;
577 140 gabrielosh
        @(negedge clk);
578 127 gabrielosh
        check();
579
 
580
        // BEQ
581
        alu_opcode = BEQ_REL;
582 140 gabrielosh
        @(negedge clk);
583 127 gabrielosh
        check();
584
 
585
        // BMI
586
        alu_opcode = BMI_REL;
587 140 gabrielosh
        @(negedge clk);
588 127 gabrielosh
        check();
589
 
590
        // BNE
591
        alu_opcode = BNE_REL;
592 140 gabrielosh
        @(negedge clk);
593 127 gabrielosh
        check();
594
 
595
        // BPL
596
        alu_opcode = BPL_REL;
597 140 gabrielosh
        @(negedge clk);
598 127 gabrielosh
        check();
599
 
600
        // BVC
601
        alu_opcode = BVC_REL;
602 140 gabrielosh
        @(negedge clk);
603 127 gabrielosh
        check();
604
 
605
        // BVS
606
        alu_opcode = BVS_REL;
607 140 gabrielosh
        @(negedge clk);
608 127 gabrielosh
        check();
609
 
610
        // JMP
611
        alu_opcode = JMP_ABS;
612 140 gabrielosh
        @(negedge clk);
613 127 gabrielosh
        check();
614
 
615
        // JMP
616
        alu_opcode = JMP_IND;
617 140 gabrielosh
        @(negedge clk);
618 127 gabrielosh
        check();
619
 
620
        // JSR
621
        alu_opcode = JSR_ABS;
622 140 gabrielosh
        @(negedge clk);
623 127 gabrielosh
        check();
624
 
625
        // NOP
626
        alu_opcode = NOP_IMP;
627 140 gabrielosh
        @(negedge clk);
628 127 gabrielosh
        check();
629
 
630
        // RTS
631
        alu_opcode = RTS_IMP;
632 140 gabrielosh
        @(negedge clk);
633 127 gabrielosh
        check();
634
 
635
        $display("TEST PASSED");
636
        $finish;
637
end
638
 
639
endmodule
640
 

powered by: WebSVN 2.1.0

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