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

Subversion Repositories t6507lp

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

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

powered by: WebSVN 2.1.0

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