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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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