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

Subversion Repositories t6507lp

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

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 132 creep
        inst : alu_input_s;
13
        next_inst : alu_input_s;
14
 
15 131 creep
        count_cycles : int;
16
        first_cycle : bool;
17
 
18
        keep first_cycle == TRUE;
19
        keep count_cycles == 0;
20
 
21
        store(input : alu_input_s) is {
22 134 creep
                count_cycles = count_cycles + 1;
23
 
24
                out ("CYCLE ", count_cycles, " STORE:");
25 132 creep
                print input;
26
 
27
                if (first_cycle) {
28
                        inst = input;
29
                        next_inst = input;
30
                }
31
                else {
32
                        inst = next_inst;
33
                        next_inst = input;
34
                };
35
 
36
 
37
                if (count_cycles == 10000) {
38
                        dut_error();
39
                }
40 131 creep
        };
41
 
42
        compare(alu_result:byte, alu_status:byte, alu_x:byte, alu_y:byte ) is {
43
                if (first_cycle) {
44
                        first_cycle = FALSE;
45
                        reg_x = alu_x;
46
                        reg_y = alu_y;
47
                        reg_status = alu_status;
48 132 creep
                        reg_a = 0; // TODO: check this
49 135 creep
                        reg_result = 0;
50 131 creep
                }
51 132 creep
                else {
52 134 creep
                        out ("CYCLE ", count_cycles, " COMPARE:");
53
                        print inst;
54
 
55 132 creep
                        case inst.input_kind {
56
                                ENABLED_VALID: {
57 134 creep
                                        out("CYCLE ", count_cycles, ": executing and comparing");
58 132 creep
                                        execute();
59
                                };
60
                                DISABLED_VALID: {
61 134 creep
                                        out("CYCLE ", count_cycles, ": just comparing");
62 132 creep
                                };
63
                                default: {
64
                                        dut_error("error at e code");
65
                                };
66
                        };
67
 
68 133 creep
                        // here i have already calculated. must compare!
69 135 creep
                        if (reg_result != alu_result) {
70
                                print inst;
71
                                print me;
72 134 creep
                                print alu_result;
73 135 creep
                                print alu_status;
74
                                print alu_x;
75
                                print alu_y;
76
 
77 133 creep
                                dut_error("WRONG!");
78
                        };
79
 
80
                        if (reg_x != alu_x) {
81
                                dut_error("WRONG!");
82
                        };
83
 
84
                        if (reg_y != alu_y) {
85
                                dut_error("WRONG!");
86
                        };
87
 
88
                        if (reg_status != alu_status) {
89
                                dut_error("WRONG!");
90
                        };
91 132 creep
                }
92 131 creep
        };
93 132 creep
 
94
        execute() is {
95
                case inst.alu_opcode {
96
                        ADC_IMM: { exec_sum(); }; // A,Z,C,N = A+M+C
97
                        ADC_ZPG: { exec_sum(); };
98
                        ADC_ZPX: { exec_sum(); };
99
                        ADC_ABS: { exec_sum(); };
100
                        ADC_ABX: { exec_sum(); };
101
                        ADC_ABY: { exec_sum(); };
102
                        ADC_IDX: { exec_sum(); };
103
                        ADC_IDY: { exec_sum(); };
104
 
105 133 creep
                        AND_IMM: { exec_and(); }; // A,Z,N = A&M
106 132 creep
                        AND_ZPG: { exec_and(); };
107
                        AND_ZPX: { exec_and(); };
108
                        AND_ABS: { exec_and(); };
109
                        AND_ABX: { exec_and(); };
110
                        AND_ABY: { exec_and(); };
111
                        AND_IDX: { exec_and(); };
112
                        AND_IDY: { exec_and(); };
113
 
114 135 creep
                        ASL_ACC: { exec_asl_acc(); }; // A,Z,C,N = M*2
115 132 creep
 
116 135 creep
                        ASL_ZPG: { exec_asl_mem(); }; // M,Z,C,N = M*2
117
                        ASL_ZPX: { exec_asl_mem(); };
118
                        ASL_ABS: { exec_asl_mem(); };
119
                        ASL_ABX: { exec_asl_mem(); };
120
 
121 132 creep
                        default: {
122
                                //dut_error("unknown opcode");
123
                        }
124
                };
125
        };
126
 
127 135 creep
        exec_asl_acc() is {
128
                reg_status[0:0] = reg_a[7:7];
129
                reg_a = reg_a * 2;
130
                update_z(reg_a);
131
                update_n(reg_a);
132
                reg_result = reg_a;
133
        };
134
 
135
        exec_asl_mem() is {
136
                reg_status[0:0] = inst.alu_a[7:7];
137
                reg_result = inst.alu_a * 2;
138
                update_z(reg_result);
139
                update_n(reg_result);
140
        };
141
 
142 132 creep
        exec_and() is {
143 133 creep
                reg_a = reg_a & inst.alu_a; // TODO: this is probably wrong
144
                update_z(reg_a);
145
                update_n(reg_a);
146 135 creep
                reg_result = reg_a;
147 132 creep
        };
148
 
149
        exec_sum() is {
150
                update_c(reg_a, inst.alu_a);
151
                reg_a = reg_a + inst.alu_a;
152
                update_z(reg_a);
153
                update_n(reg_a);
154 135 creep
                reg_result = reg_a;
155
                //print me;
156 134 creep
                //dut_error();
157 132 creep
        };
158
 
159
        update_z(arg : byte) is {
160
                if (arg == 0) {
161
                        reg_status[1:1] = 1;
162
                }
163
                else {
164
                        reg_status[1:1] = 0;
165
                }
166
        };
167
 
168
        update_c(arg1 : byte, arg2 : byte) is {
169
                if (arg1 + arg2 > 256) {
170
                        reg_status[0:0] = 1;
171
                }
172
                else {
173
                        reg_status[0:0] = 0;
174
                }
175
        };
176
 
177
        update_n(arg : byte) is {
178
                if (arg[7:7] == 1) {
179
                        reg_status[7:7] = 1;
180
                }
181
                else {
182
                        reg_status[7:7] = 0;
183
                }
184
        };
185 131 creep
};
186
'>

powered by: WebSVN 2.1.0

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