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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [fv/] [alu_chk.e] - Blame information for rev 159

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 131 creep
alu_chk.e
2
<'
3
import alu_components;
4
 
5
unit alu_chk_u {
6
        reg_a : byte;
7
        reg_x : byte;
8
        reg_y : byte;
9
        reg_status : byte;
10 135 creep
        reg_result : byte;
11 131 creep
 
12 159 creep
        !inst : alu_input_s;
13
        !next_inst : alu_input_s;
14 132 creep
 
15 131 creep
        count_cycles : int;
16
        first_cycle : bool;
17 159 creep
        last_a : byte;
18
        last_status : byte;
19
        last_result : byte;
20 131 creep
 
21
        keep first_cycle == TRUE;
22
        keep count_cycles == 0;
23
 
24
        store(input : alu_input_s) is {
25 134 creep
                count_cycles = count_cycles + 1;
26
 
27 153 creep
                //out ("CYCLE ", count_cycles, " STORE:");
28
                //print input;
29 132 creep
 
30 159 creep
                last_a = reg_a;
31
                last_status = reg_status;
32
                last_result = reg_result;
33
 
34 132 creep
                if (first_cycle) {
35
                        inst = input;
36
                        next_inst = input;
37
                }
38
                else {
39
                        inst = next_inst;
40
                        next_inst = input;
41
                };
42
 
43 131 creep
        };
44
 
45
        compare(alu_result:byte, alu_status:byte, alu_x:byte, alu_y:byte ) is {
46
                if (first_cycle) {
47
                        first_cycle = FALSE;
48 143 creep
                        reg_x = 0;
49
                        reg_y = 0;
50
                        reg_status = 8'b00100010;
51 132 creep
                        reg_a = 0; // TODO: check this
52 135 creep
                        reg_result = 0;
53 131 creep
                }
54 132 creep
                else {
55 153 creep
                        //out ("CYCLE ", count_cycles, " COMPARE:");
56
                        //print inst;
57 134 creep
 
58 159 creep
                        if (count_cycles == 99999) {
59
                                out("ENOUGH!");
60
                                stop_run();
61
                        };
62
 
63 132 creep
                        case inst.input_kind {
64
                                ENABLED_VALID: {
65 153 creep
                                        //out("CYCLE ", count_cycles, ": executing and comparing");
66 132 creep
                                        execute();
67
                                };
68
                                DISABLED_VALID: {
69 153 creep
                                        //out("CYCLE ", count_cycles, ": just comparing");
70 132 creep
                                };
71 143 creep
                                RESET: {
72 146 creep
                                        reg_x = 0;
73
                                        reg_y = 0;
74
                                        reg_status = 8'b00100010;
75
                                        reg_a = 0; // TODO: check this
76
                                        reg_result = 0;
77
 
78 143 creep
                                        return;
79
                                };
80 132 creep
                                default: {
81
                                        dut_error("error at e code");
82
                                };
83
                        };
84
 
85 133 creep
                        // here i have already calculated. must compare!
86 143 creep
 
87 146 creep
                        if ((reg_result != alu_result) || (reg_x != alu_x) or (reg_y != alu_y) or (reg_status != alu_status)) {
88 153 creep
                                out("#########################################################");
89 135 creep
                                print me;
90 155 creep
                                print me.inst;
91 153 creep
                                out("#########################################################");
92 134 creep
                                print alu_result;
93 135 creep
                                print alu_status;
94
                                print alu_x;
95
                                print alu_y;
96
 
97 133 creep
                                dut_error("WRONG!");
98
                        };
99 146 creep
                };
100 131 creep
        };
101 132 creep
 
102
        execute() is {
103
                case inst.alu_opcode {
104
                        ADC_IMM: { exec_sum(); }; // A,Z,C,N = A+M+C
105
                        ADC_ZPG: { exec_sum(); };
106
                        ADC_ZPX: { exec_sum(); };
107
                        ADC_ABS: { exec_sum(); };
108
                        ADC_ABX: { exec_sum(); };
109
                        ADC_ABY: { exec_sum(); };
110
                        ADC_IDX: { exec_sum(); };
111
                        ADC_IDY: { exec_sum(); };
112
 
113 133 creep
                        AND_IMM: { exec_and(); }; // A,Z,N = A&M
114 132 creep
                        AND_ZPG: { exec_and(); };
115
                        AND_ZPX: { exec_and(); };
116
                        AND_ABS: { exec_and(); };
117
                        AND_ABX: { exec_and(); };
118
                        AND_ABY: { exec_and(); };
119
                        AND_IDX: { exec_and(); };
120
                        AND_IDY: { exec_and(); };
121
 
122 135 creep
                        ASL_ACC: { exec_asl_acc(); }; // A,Z,C,N = M*2
123 132 creep
 
124 135 creep
                        ASL_ZPG: { exec_asl_mem(); }; // M,Z,C,N = M*2
125
                        ASL_ZPX: { exec_asl_mem(); };
126
                        ASL_ABS: { exec_asl_mem(); };
127
                        ASL_ABX: { exec_asl_mem(); };
128
 
129 155 creep
                        BCC_REL: {}; // nothing is done. these are all branches.
130 153 creep
                        BCS_REL: {};
131
                        BEQ_REL: {};
132 155 creep
                        BMI_REL: {};
133
                        BNE_REL: {};
134
                        BPL_REL: {};
135
                        BVC_REL: {};
136
                        BVS_REL: {};
137 153 creep
 
138 155 creep
                        BIT_ZPG: { exec_bit(); }; // Z = A & M, N = M7, V = M6
139
                        BIT_ABS: { exec_bit(); };
140
 
141
                        BRK_IMP: { reg_status[4:4] = 1; };
142
 
143
                        CLC_IMP: { reg_status[0:0] = 0; };
144
                        CLD_IMP: { reg_status[3:3] = 0; };
145
                        CLI_IMP: { reg_status[2:2] = 0; };
146
                        CLV_IMP: { reg_status[6:6] = 0; };
147
 
148 159 creep
                        CMP_IMM: { exec_cmp(reg_a); }; // Z,C,N = A-M
149
                        CMP_ZPG: { exec_cmp(reg_a); };
150
                        CMP_ZPX: { exec_cmp(reg_a); };
151
                        CMP_ABS: { exec_cmp(reg_a); };
152
                        CMP_ABX: { exec_cmp(reg_a); };
153
                        CMP_ABY: { exec_cmp(reg_a); };
154
                        CMP_IDX: { exec_cmp(reg_a); };
155
                        CMP_IDY: { exec_cmp(reg_a); };
156
 
157
                        CPX_IMM: { exec_cmp(reg_x); }; // Z,C,N = X-M
158
                        CPX_ZPG: { exec_cmp(reg_x); };
159
                        CPX_ABS: { exec_cmp(reg_x); };
160
 
161
                        CPY_IMM: { exec_cmp(reg_y); }; //Z,C,N = Y-M
162
                        CPY_ZPG: { exec_cmp(reg_y); };
163
                        CPY_ABS: { exec_cmp(reg_y); };
164
 
165
                        DEC_ZPG: { exec_dec(inst.alu_a, TRUE); }; // M,Z,N = M-1
166
                        DEC_ZPX: { exec_dec(inst.alu_a, TRUE); };
167
                        DEC_ABS: { exec_dec(inst.alu_a, TRUE); };
168
                        DEC_ABX: { exec_dec(inst.alu_a, TRUE); };
169
 
170
                        DEX_IMP: { exec_dec(reg_x, FALSE); };  // X,Z,N = X-1
171
                        DEY_IMP: { exec_dec(reg_y, FALSE); };  // Y,Z,N = Y-1
172
 
173
                        EOR_IMM: { exec_eor(); }; // A,Z,N = A^M
174
                        EOR_ZPG: { exec_eor(); };
175
                        EOR_ZPX: { exec_eor(); };
176
                        EOR_ABS: { exec_eor(); };
177
                        EOR_ABX: { exec_eor(); };
178
                        EOR_ABY: { exec_eor(); };
179
                        EOR_IDX: { exec_eor(); };
180
                        EOR_IDY: { exec_eor(); };
181
 
182
                        INC_ZPG: { exec_inc(inst.alu_a, TRUE); };
183
                        INC_ZPX: { exec_inc(inst.alu_a, TRUE); };
184
                        INC_ABS: { exec_inc(inst.alu_a, TRUE); };
185
                        INC_ABX: { exec_inc(inst.alu_a, TRUE); };
186
 
187
                        INX_IMP: { exec_inc(reg_x, FALSE); };
188
                        INY_IMP: { exec_inc(reg_y, FALSE); };
189
 
190
                        JMP_ABS: {};
191
                        JMP_IND: {};
192
                        JSR_ABS: {};
193
 
194
                        LDA_IMM: { exec_load(reg_a, TRUE); }; // A,Z,N = M
195
                        LDA_ZPG: { exec_load(reg_a, TRUE); };
196
                        LDA_ZPX: { exec_load(reg_a, TRUE); };
197
                        LDA_ABS: { exec_load(reg_a, TRUE); };
198
                        LDA_ABX: { exec_load(reg_a, TRUE); };
199
                        LDA_ABY: { exec_load(reg_a, TRUE); };
200
                        LDA_IDX: { exec_load(reg_a, TRUE); };
201
                        LDA_IDY: { exec_load(reg_a, TRUE); };
202
 
203
                        LDX_IMM: { exec_load(reg_x, FALSE); };
204
                        LDX_ZPG: { exec_load(reg_x, FALSE); };
205
                        LDX_ZPY: { exec_load(reg_x, FALSE); };
206
                        LDX_ABS: { exec_load(reg_x, FALSE); };
207
                        LDX_ABY: { exec_load(reg_x, FALSE); };
208
 
209
                        LDY_IMM: { exec_load(reg_y, FALSE); };
210
                        LDY_ZPG: { exec_load(reg_y, FALSE); };
211
                        LDY_ZPX: { exec_load(reg_y, FALSE); };
212
                        LDY_ABS: { exec_load(reg_y, FALSE); };
213
                        LDY_ABX: { exec_load(reg_y, FALSE); };
214
 
215
                        LSR_ACC: { exec_lsr(reg_a); }; // A,C,Z,N = A/2 or M,C,Z,N = M/2
216
                        LSR_ZPG: { exec_lsr(inst.alu_a); };
217
                        LSR_ZPX: { exec_lsr(inst.alu_a); };
218
                        LSR_ABS: { exec_lsr(inst.alu_a); };
219
                        LSR_ABX: { exec_lsr(inst.alu_a); };
220
 
221
                        NOP_IMP: {};
222
 
223
                        ORA_IMM: { exec_or(); }; // A,Z,N = A|M
224
                        ORA_ZPG: { exec_or(); };
225
                        ORA_ZPX: { exec_or(); };
226
                        ORA_ABS: { exec_or(); };
227
                        ORA_ABX: { exec_or(); };
228
                        ORA_ABY: { exec_or(); };
229
                        ORA_IDX: { exec_or(); };
230
                        ORA_IDY: { exec_or(); };
231
 
232
                        PHA_IMP: { reg_result = reg_a; };
233
                        PHP_IMP: {}; // P is always connected and the result is not updated
234
                        PLA_IMP: {
235
                                reg_a = inst.alu_a;
236
                                reg_result = inst.alu_a;
237
                                update_z(reg_a);
238
                                update_n(reg_a);
239
                        };
240
                        PLP_IMP: {
241
                                reg_status = inst.alu_a;
242
                                reg_status[5:5] = 1; // this is always one
243
                        };
244
 
245 132 creep
                        default: {
246 155 creep
                                out(inst.alu_opcode);
247
                                dut_error("unknown opcode");
248 132 creep
                        }
249
                };
250
        };
251
 
252 159 creep
        exec_or() is {
253
                reg_a = reg_a | inst.alu_a;
254
                reg_result = reg_a;
255
                update_z(reg_a);
256
                update_n(reg_a);
257
        };
258
 
259
        exec_lsr(arg1 : *byte) is {
260
                reg_status[0:0] = arg1[0:0];
261
                arg1 = arg1 >> 1;
262
                update_z(arg1);
263
                update_n(arg1);
264
                reg_result = arg1;
265
        };
266
 
267
        exec_load(arg1 : *byte, update_result : bool) is {
268
                arg1 = inst.alu_a;
269
 
270
                if (update_result) { //
271
                        reg_result = inst.alu_a; // no need for this but...
272
                };
273
                update_z(arg1);
274
                update_n(arg1);
275
        };
276
 
277
        exec_inc(arg1 : *byte, update_result : bool) is {
278
                arg1 = arg1 + 1;
279
                update_z(arg1);
280
                update_n(arg1);
281
 
282
                if (update_result) { //
283
                        reg_result = arg1;
284
                };
285
        };
286
 
287
        exec_eor() is {
288
                reg_a = reg_a ^ inst.alu_a;
289
                reg_result = reg_a;
290
                update_z(reg_a);
291
                update_n(reg_a);
292
        };
293
 
294
        exec_dec(arg1 : *byte, update_result : bool) is {
295
                arg1 = arg1 - 1;
296
                update_z(arg1);
297
                update_n(arg1);
298
 
299
                if (update_result) { // DEX and DEY do not output the result
300
                        reg_result = arg1;
301
                };
302
        };
303
 
304
        exec_cmp(arg1 : byte) is {
305
                update_z(arg1 - inst.alu_a);
306
                update_n(arg1 - inst.alu_a);
307
 
308
                if (arg1 >= inst.alu_a) {
309
                        reg_status[0:0] = 1;
310
                }
311
                else {
312
                        reg_status[0:0] = 0;
313
                };
314
        };
315
 
316 155 creep
        exec_bit() is {
317
                update_z(reg_a & inst.alu_a);
318
                reg_status[7:7] = inst.alu_a[7:7];
319
                reg_status[6:6] = inst.alu_a[6:6];
320
        };
321
 
322 135 creep
        exec_asl_acc() is {
323
                reg_status[0:0] = reg_a[7:7];
324
                reg_a = reg_a * 2;
325
                update_z(reg_a);
326
                update_n(reg_a);
327
                reg_result = reg_a;
328
        };
329
 
330
        exec_asl_mem() is {
331
                reg_status[0:0] = inst.alu_a[7:7];
332
                reg_result = inst.alu_a * 2;
333
                update_z(reg_result);
334
                update_n(reg_result);
335
        };
336
 
337 132 creep
        exec_and() is {
338 133 creep
                reg_a = reg_a & inst.alu_a; // TODO: this is probably wrong
339
                update_z(reg_a);
340
                update_n(reg_a);
341 135 creep
                reg_result = reg_a;
342 132 creep
        };
343
 
344
        exec_sum() is {
345 153 creep
                //out("adding: ", reg_a, " + ", inst.alu_a, " + ", reg_status[0:0]);
346 144 creep
                reg_result = reg_a + inst.alu_a + reg_status[0:0];
347 143 creep
                update_c(reg_a, inst.alu_a, reg_status[0:0]);
348 146 creep
                update_v(reg_a, inst.alu_a, reg_result);
349 144 creep
                update_z(reg_result);
350
                update_n(reg_result);
351
                reg_a = reg_result;
352 135 creep
                //print me;
353 134 creep
                //dut_error();
354 132 creep
        };
355
 
356 143 creep
        update_c(arg1 : byte, arg2 : byte, arg3: bit) is {
357 153 creep
                if (arg1 + arg2 + arg3 > 255) {
358 132 creep
                        reg_status[0:0] = 1;
359
                }
360
                else {
361
                        reg_status[0:0] = 0;
362
                }
363
        };
364
 
365 146 creep
        update_v(op1 : byte, op2 : byte, res : byte) is {
366
                if ((op1[7:7] == op2[7:7]) && (op1[7:7] != res[7:7])) {
367
                        reg_status[6:6] = 1;
368
                }
369
                else {
370
                        reg_status[6:6] = 0;
371
                };
372
        };
373
 
374
        update_z(arg : byte) is {
375
                if (arg == 0) {
376
                        reg_status[1:1] = 1;
377
                }
378
                else {
379
                        reg_status[1:1] = 0;
380
                }
381
        };
382
 
383
 
384 132 creep
        update_n(arg : byte) is {
385
                if (arg[7:7] == 1) {
386
                        reg_status[7:7] = 1;
387
                }
388
                else {
389
                        reg_status[7:7] = 0;
390
                }
391
        };
392 131 creep
};
393
'>

powered by: WebSVN 2.1.0

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