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 |
158 |
gabrielosh |
|
471 |
|
|
// PHA
|
472 |
|
|
alu_opcode = PHA_IMP;
|
473 |
|
|
@(negedge clk);
|
474 |
|
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
475 |
|
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
476 |
|
|
//$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);
|
477 |
|
|
alu_result_expected = DUT.A;
|
478 |
|
|
check();
|
479 |
|
|
|
480 |
|
|
// PHP
|
481 |
|
|
alu_opcode = PHP_IMP;
|
482 |
|
|
@(negedge clk);
|
483 |
|
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
484 |
|
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
485 |
|
|
//$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);
|
486 |
|
|
alu_status_expected = DUT.STATUS;
|
487 |
|
|
check();
|
488 |
|
|
|
489 |
|
|
// BRK
|
490 |
|
|
alu_opcode = BRK_IMP;
|
491 |
|
|
@(negedge clk);
|
492 |
|
|
alu_status_expected[B] = 1;
|
493 |
|
|
check();
|
494 |
|
|
|
495 |
127 |
gabrielosh |
// SEC
|
496 |
|
|
alu_opcode = SEC_IMP;
|
497 |
140 |
gabrielosh |
@(negedge clk);
|
498 |
127 |
gabrielosh |
alu_status_expected[C] = 1;
|
499 |
|
|
check();
|
500 |
|
|
|
501 |
|
|
// SED
|
502 |
|
|
alu_opcode = SED_IMP;
|
503 |
140 |
gabrielosh |
@(negedge clk);
|
504 |
127 |
gabrielosh |
alu_status_expected[D] = 1;
|
505 |
|
|
check();
|
506 |
|
|
|
507 |
|
|
// SEI
|
508 |
|
|
alu_opcode = SEI_IMP;
|
509 |
140 |
gabrielosh |
@(negedge clk);
|
510 |
127 |
gabrielosh |
alu_status_expected[I] = 1;
|
511 |
|
|
check();
|
512 |
|
|
|
513 |
|
|
// CLC
|
514 |
|
|
alu_opcode = CLC_IMP;
|
515 |
140 |
gabrielosh |
@(negedge clk);
|
516 |
127 |
gabrielosh |
alu_status_expected[C] = 0;
|
517 |
|
|
check();
|
518 |
|
|
|
519 |
|
|
// CLD
|
520 |
|
|
alu_opcode = CLD_IMP;
|
521 |
140 |
gabrielosh |
@(negedge clk);
|
522 |
127 |
gabrielosh |
alu_status_expected[D] = 0;
|
523 |
|
|
check();
|
524 |
|
|
|
525 |
|
|
// CLI
|
526 |
|
|
alu_opcode = CLI_IMP;
|
527 |
140 |
gabrielosh |
@(negedge clk);
|
528 |
127 |
gabrielosh |
alu_status_expected[I] = 0;
|
529 |
|
|
check();
|
530 |
|
|
|
531 |
|
|
// CLV
|
532 |
|
|
alu_opcode = CLV_IMP;
|
533 |
140 |
gabrielosh |
@(negedge clk);
|
534 |
127 |
gabrielosh |
alu_status_expected[V] = 0;
|
535 |
|
|
check();
|
536 |
|
|
|
537 |
|
|
// LDA
|
538 |
|
|
alu_opcode = LDA_IMM;
|
539 |
|
|
alu_a = 8'h76;
|
540 |
140 |
gabrielosh |
@(negedge clk);
|
541 |
127 |
gabrielosh |
alu_result_expected = alu_a;
|
542 |
|
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
543 |
|
|
alu_status_expected[N] = alu_result_expected[7];
|
544 |
|
|
check();
|
545 |
|
|
|
546 |
|
|
// TAX
|
547 |
|
|
alu_opcode = TAX_IMP;
|
548 |
140 |
gabrielosh |
@(negedge clk);
|
549 |
127 |
gabrielosh |
alu_x_expected = alu_result_expected;
|
550 |
|
|
alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
|
551 |
|
|
alu_status_expected[N] = alu_x_expected[7];
|
552 |
|
|
check();
|
553 |
|
|
|
554 |
|
|
// TAY
|
555 |
|
|
alu_opcode = TAY_IMP;
|
556 |
140 |
gabrielosh |
@(negedge clk);
|
557 |
127 |
gabrielosh |
alu_y_expected = alu_result_expected;
|
558 |
|
|
alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
|
559 |
|
|
alu_status_expected[N] = alu_y_expected[7];
|
560 |
|
|
check();
|
561 |
|
|
|
562 |
|
|
// TSX
|
563 |
|
|
alu_opcode = TSX_IMP;
|
564 |
140 |
gabrielosh |
@(negedge clk);
|
565 |
127 |
gabrielosh |
alu_x_expected = alu_a;
|
566 |
|
|
//alu_result_expected = alu_a;
|
567 |
|
|
alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
|
568 |
|
|
alu_status_expected[N] = alu_x_expected[7];
|
569 |
|
|
check();
|
570 |
|
|
|
571 |
|
|
// TXA
|
572 |
|
|
alu_opcode = TXA_IMP;
|
573 |
140 |
gabrielosh |
@(negedge clk);
|
574 |
127 |
gabrielosh |
alu_result_expected = alu_x_expected;
|
575 |
|
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
576 |
|
|
alu_status_expected[N] = alu_result_expected[7];
|
577 |
|
|
check();
|
578 |
|
|
|
579 |
|
|
// TXS
|
580 |
|
|
alu_opcode = TXS_IMP;
|
581 |
140 |
gabrielosh |
@(negedge clk);
|
582 |
127 |
gabrielosh |
alu_result_expected = alu_x_expected;
|
583 |
|
|
check();
|
584 |
|
|
|
585 |
|
|
// TYA
|
586 |
|
|
alu_opcode = TYA_IMP;
|
587 |
140 |
gabrielosh |
@(negedge clk);
|
588 |
127 |
gabrielosh |
alu_result_expected = alu_y_expected;
|
589 |
|
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
590 |
|
|
alu_status_expected[N] = alu_result_expected[7];
|
591 |
|
|
check();
|
592 |
|
|
|
593 |
|
|
// Nothing should happen
|
594 |
|
|
// BCC
|
595 |
|
|
alu_opcode = BCC_REL;
|
596 |
140 |
gabrielosh |
@(negedge clk);
|
597 |
127 |
gabrielosh |
check();
|
598 |
|
|
|
599 |
|
|
// BCS
|
600 |
|
|
alu_opcode = BCS_REL;
|
601 |
140 |
gabrielosh |
@(negedge clk);
|
602 |
127 |
gabrielosh |
check();
|
603 |
|
|
|
604 |
|
|
// BEQ
|
605 |
|
|
alu_opcode = BEQ_REL;
|
606 |
140 |
gabrielosh |
@(negedge clk);
|
607 |
127 |
gabrielosh |
check();
|
608 |
|
|
|
609 |
|
|
// BMI
|
610 |
|
|
alu_opcode = BMI_REL;
|
611 |
140 |
gabrielosh |
@(negedge clk);
|
612 |
127 |
gabrielosh |
check();
|
613 |
|
|
|
614 |
|
|
// BNE
|
615 |
|
|
alu_opcode = BNE_REL;
|
616 |
140 |
gabrielosh |
@(negedge clk);
|
617 |
127 |
gabrielosh |
check();
|
618 |
|
|
|
619 |
|
|
// BPL
|
620 |
|
|
alu_opcode = BPL_REL;
|
621 |
140 |
gabrielosh |
@(negedge clk);
|
622 |
127 |
gabrielosh |
check();
|
623 |
|
|
|
624 |
|
|
// BVC
|
625 |
|
|
alu_opcode = BVC_REL;
|
626 |
140 |
gabrielosh |
@(negedge clk);
|
627 |
127 |
gabrielosh |
check();
|
628 |
|
|
|
629 |
|
|
// BVS
|
630 |
|
|
alu_opcode = BVS_REL;
|
631 |
140 |
gabrielosh |
@(negedge clk);
|
632 |
127 |
gabrielosh |
check();
|
633 |
|
|
|
634 |
|
|
// JMP
|
635 |
|
|
alu_opcode = JMP_ABS;
|
636 |
140 |
gabrielosh |
@(negedge clk);
|
637 |
127 |
gabrielosh |
check();
|
638 |
|
|
|
639 |
|
|
// JMP
|
640 |
|
|
alu_opcode = JMP_IND;
|
641 |
140 |
gabrielosh |
@(negedge clk);
|
642 |
127 |
gabrielosh |
check();
|
643 |
|
|
|
644 |
|
|
// JSR
|
645 |
|
|
alu_opcode = JSR_ABS;
|
646 |
140 |
gabrielosh |
@(negedge clk);
|
647 |
127 |
gabrielosh |
check();
|
648 |
|
|
|
649 |
|
|
// NOP
|
650 |
|
|
alu_opcode = NOP_IMP;
|
651 |
140 |
gabrielosh |
@(negedge clk);
|
652 |
127 |
gabrielosh |
check();
|
653 |
|
|
|
654 |
|
|
// RTS
|
655 |
|
|
alu_opcode = RTS_IMP;
|
656 |
140 |
gabrielosh |
@(negedge clk);
|
657 |
127 |
gabrielosh |
check();
|
658 |
|
|
|
659 |
|
|
$display("TEST PASSED");
|
660 |
|
|
$finish;
|
661 |
|
|
end
|
662 |
|
|
|
663 |
|
|
endmodule
|
664 |
|
|
|