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

Subversion Repositories t6507lp

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

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 143 creep
                        reg_x = 0;
46
                        reg_y = 0;
47
                        reg_status = 8'b00100010;
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 143 creep
                                RESET: {
64
                                        return;
65
                                };
66 132 creep
                                default: {
67
                                        dut_error("error at e code");
68
                                };
69
                        };
70
 
71 133 creep
                        // here i have already calculated. must compare!
72 143 creep
 
73 144 creep
                        //if (count_cycles > 3) {
74 135 creep
                        if (reg_result != alu_result) {
75
                                print inst;
76
                                print me;
77 134 creep
                                print alu_result;
78 135 creep
                                print alu_status;
79
                                print alu_x;
80
                                print alu_y;
81
 
82 133 creep
                                dut_error("WRONG!");
83
                        };
84
 
85
                        if (reg_x != alu_x) {
86
                                dut_error("WRONG!");
87
                        };
88
 
89
                        if (reg_y != alu_y) {
90
                                dut_error("WRONG!");
91
                        };
92
 
93
                        if (reg_status != alu_status) {
94
                                dut_error("WRONG!");
95
                        };
96 143 creep
                        //};
97 132 creep
                }
98 131 creep
        };
99 132 creep
 
100
        execute() is {
101
                case inst.alu_opcode {
102
                        ADC_IMM: { exec_sum(); }; // A,Z,C,N = A+M+C
103
                        ADC_ZPG: { exec_sum(); };
104
                        ADC_ZPX: { exec_sum(); };
105
                        ADC_ABS: { exec_sum(); };
106
                        ADC_ABX: { exec_sum(); };
107
                        ADC_ABY: { exec_sum(); };
108
                        ADC_IDX: { exec_sum(); };
109
                        ADC_IDY: { exec_sum(); };
110
 
111 133 creep
                        AND_IMM: { exec_and(); }; // A,Z,N = A&M
112 132 creep
                        AND_ZPG: { exec_and(); };
113
                        AND_ZPX: { exec_and(); };
114
                        AND_ABS: { exec_and(); };
115
                        AND_ABX: { exec_and(); };
116
                        AND_ABY: { exec_and(); };
117
                        AND_IDX: { exec_and(); };
118
                        AND_IDY: { exec_and(); };
119
 
120 135 creep
                        ASL_ACC: { exec_asl_acc(); }; // A,Z,C,N = M*2
121 132 creep
 
122 135 creep
                        ASL_ZPG: { exec_asl_mem(); }; // M,Z,C,N = M*2
123
                        ASL_ZPX: { exec_asl_mem(); };
124
                        ASL_ABS: { exec_asl_mem(); };
125
                        ASL_ABX: { exec_asl_mem(); };
126
 
127 132 creep
                        default: {
128
                                //dut_error("unknown opcode");
129
                        }
130
                };
131
        };
132
 
133 135 creep
        exec_asl_acc() is {
134
                reg_status[0:0] = reg_a[7:7];
135
                reg_a = reg_a * 2;
136
                update_z(reg_a);
137
                update_n(reg_a);
138
                reg_result = reg_a;
139
        };
140
 
141
        exec_asl_mem() is {
142
                reg_status[0:0] = inst.alu_a[7:7];
143
                reg_result = inst.alu_a * 2;
144
                update_z(reg_result);
145
                update_n(reg_result);
146
        };
147
 
148 132 creep
        exec_and() is {
149 133 creep
                reg_a = reg_a & inst.alu_a; // TODO: this is probably wrong
150
                update_z(reg_a);
151
                update_n(reg_a);
152 135 creep
                reg_result = reg_a;
153 132 creep
        };
154
 
155
        exec_sum() is {
156 144 creep
                reg_result = reg_a + inst.alu_a + reg_status[0:0];
157 143 creep
                update_c(reg_a, inst.alu_a, reg_status[0:0]);
158 144 creep
                update_z(reg_result);
159
                update_n(reg_result);
160
                reg_a = reg_result;
161 135 creep
                //print me;
162 134 creep
                //dut_error();
163 132 creep
        };
164
 
165
        update_z(arg : byte) is {
166
                if (arg == 0) {
167
                        reg_status[1:1] = 1;
168
                }
169
                else {
170
                        reg_status[1:1] = 0;
171
                }
172
        };
173
 
174 143 creep
        update_c(arg1 : byte, arg2 : byte, arg3: bit) is {
175
                if (arg1 + arg2 + arg3 > 256) {
176 132 creep
                        reg_status[0:0] = 1;
177
                }
178
                else {
179
                        reg_status[0:0] = 0;
180
                }
181
        };
182
 
183
        update_n(arg : byte) is {
184
                if (arg[7:7] == 1) {
185
                        reg_status[7:7] = 1;
186
                }
187
                else {
188
                        reg_status[7:7] = 0;
189
                }
190
        };
191 131 creep
};
192
'>

powered by: WebSVN 2.1.0

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