-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogic-ops.h
233 lines (230 loc) · 5.28 KB
/
logic-ops.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// logic-ops.cfragment - AND, ORA, EOR
/*******************************
* AND Accumulator with Memory *
*******************************/
case OP_AND_IMM:
op_and(readByte(programCounter++));
break;
case OP_AND_ABS:
op_and(readByte(getABSAddr()));
break;
case OP_AND_ZP:
op_and(readByte(getZPAddr()));
break;
case OP_AND_ZP_IND:
op_and(readByte(getZP_INDAddr()));
break;
case OP_AND_ABS_X:
op_and(readByte(getABS_XAddr()));
break;
case OP_AND_ABS_Y:
op_and(readByte(getABS_YAddr()));
break;
case OP_AND_ZP_X:
op_and(readByte(getZP_XAddr()));
break;
case OP_AND_ZP_X_IND:
op_and(readByte(getZP_X_INDAddr()));
break;
case OP_AND_ZP_IND_Y:
op_and(readByte(getZP_IND_YAddr()));
break;
/******************************
* OR Accumulator with Memory *
******************************/
case OP_ORA_IMM:
ora(readByte(programCounter++));
break;
case OP_ORA_ABS:
ora(readByte(getABSAddr()));
break;
case OP_ORA_ZP:
ora(readByte(getZPAddr()));
break;
case OP_ORA_ZP_IND:
ora(readByte(getZP_INDAddr()));
break;
case OP_ORA_ABS_X:
ora(readByte(getABS_XAddr()));
break;
case OP_ORA_ABS_Y:
ora(readByte(getABS_YAddr()));
break;
case OP_ORA_ZP_X:
ora(readByte(getZP_XAddr()));
break;
case OP_ORA_ZP_X_IND:
ora(readByte(getZP_X_INDAddr()));
break;
case OP_ORA_ZP_IND_Y:
ora(readByte(getZP_IND_YAddr()));
break;
/*******************************
* XOR Accumulator with Memory *
*******************************/
case OP_EOR_IMM:
eor(readByte(programCounter++));
break;
case OP_EOR_ABS:
eor(readByte(getABSAddr()));
break;
case OP_EOR_ZP:
eor(readByte(getZPAddr()));
break;
case OP_EOR_ZP_IND:
eor(readByte(getZP_INDAddr()));
break;
case OP_EOR_ABS_X:
eor(readByte(getABS_XAddr()));
break;
case OP_EOR_ABS_Y:
eor(readByte(getABS_YAddr()));
break;
case OP_EOR_ZP_X:
eor(readByte(getZP_XAddr()));
break;
case OP_EOR_ZP_X_IND:
eor(readByte(getZP_X_INDAddr()));
break;
case OP_EOR_ZP_IND_Y:
eor(readByte(getZP_IND_YAddr()));
break;
/****************************************
* Test memory bits against accumulator *
****************************************/
case OP_BIT_IMM:
// Immediate mode only affects the Z flag, and bit() does N,V, and Z
flagZero = (A & readByte(programCounter++)) == 0x00;
break;
case OP_BIT_ABS:
op_bit(readByte(getABSAddr()));
break;
case OP_BIT_ZP:
op_bit(readByte(getZPAddr()));
break;
case OP_BIT_ABS_X:
op_bit(readByte(getABS_XAddr()));
break;
case OP_BIT_ZP_X:
op_bit(readByte(getZP_XAddr()));
break;
/*************************
* Arithmetic Shift Left *
*************************/
case OP_ASL_ACC:
{
uint8_t value = A;
// shift left by one place, and mask the bottom bit out to ensure it's zero.
A = (value << 1) & 0xFE;
// set carry if high bit was set, clear it otherwise
flagCarry = (value & 0x80) != 0;
flagNegative = (A & 0x80) != 0;
flagZero = A == 0x00;
}
break;
case OP_ASL_ABS:
asl(getABSAddr());
break;
case OP_ASL_ZP:
asl(getZPAddr());
break;
case OP_ASL_ABS_X:
asl(getABS_XAddr());
break;
case OP_ASL_ZP_X:
asl(getZP_XAddr());
break;
/***********************
* Logical Shift Right *
***********************/
case OP_LSR_ACC:
{
uint8_t value = A;
// shift left by one place, and mask out the top bit
A = (value >> 1) & 0x7F;
// low bit moves into carry
flagCarry = (value & 0x01) != 0;
// zero is shifted in, so N is always cleared
flagNegative = false;
flagZero = A == 0x00;
}
break;
case OP_LSR_ABS:
lsr(getABSAddr());
break;
case OP_LSR_ZP:
lsr(getZPAddr());
break;
case OP_LSR_ABS_X:
lsr(getABS_XAddr());
break;
case OP_LSR_ZP_X:
lsr(getZP_XAddr());
break;
/***************
* Rotate Left *
***************/
case OP_ROL_ACC:
{
uint8_t value = A;
// shift left by one place, mask the bottom bit out, and add in the carry
A = ((value << 1) & 0xFE) + (flagCarry?1:0);
// set carry if high bit was set, clear it otherwise
flagCarry = (value & 0x80) != 0;
flagNegative = (A & 0x80) != 0;
flagZero = A == 0x00;
}
break;
case OP_ROL_ABS:
rol(getABSAddr());
break;
case OP_ROL_ZP:
rol(getZPAddr());
break;
case OP_ROL_ABS_X:
rol(getABS_XAddr());
break;
case OP_ROL_ZP_X:
rol(getZP_XAddr());
break;
/****************
* Rotate Right *
****************/
case OP_ROR_ACC:
{
uint8_t value = A;
// shift right by one place, mask the bottom bit out, and add in the carry
A = ((value >> 1) & 0x7F) + (flagCarry?0x80:0x00);
// set carry if high bit was set, clear it otherwise
flagCarry = (value & 0x01) != 0;
flagNegative = (A & 0x80) != 0;
flagZero = A == 0x00;
}
break;
case OP_ROR_ABS:
ror(getABSAddr());
break;
case OP_ROR_ZP:
ror(getZPAddr());
break;
case OP_ROR_ABS_X:
ror(getABS_XAddr());
break;
case OP_ROR_ZP_X:
ror(getZP_XAddr());
break;
/***************************
* Test and Set/Reset Bits *
***************************/
case OP_TRB_ZP:
trb(getZPAddr());
break;
case OP_TRB_ABS:
trb(getABSAddr());
break;
case OP_TSB_ZP:
tsb(getZPAddr());
break;
case OP_TSB_ABS:
tsb(getABSAddr());
break;