AbsoluteX, AbsoluteY addressing modes in 6502-code generator.
Chris Pressey
9 years ago
0 | """This is just a sketch for now.""" | |
0 | """Emittables for 6502 machine code.""" | |
1 | 1 | |
2 | 2 | from sixtypical.emitter import Emittable, Byte, Word, Label |
3 | 3 | |
39 | 39 | |
40 | 40 | class Absolute(AddressingMode): |
41 | 41 | def __init__(self, value): |
42 | assert isinstance(value, (Word, Label)) | |
42 | assert isinstance(value, Label) | |
43 | 43 | self.value = value |
44 | 44 | |
45 | 45 | def size(self): |
47 | 47 | |
48 | 48 | def serialize(self, addr): |
49 | 49 | return self.value.serialize(addr) |
50 | ||
51 | ||
52 | class AbsoluteX(Absolute): | |
53 | pass | |
54 | ||
55 | ||
56 | class AbsoluteY(Absolute): | |
57 | pass | |
50 | 58 | |
51 | 59 | |
52 | 60 | class Relative(AddressingMode): |
82 | 90 | opcodes = { |
83 | 91 | Immediate: 0x69, |
84 | 92 | Absolute: 0x6d, |
93 | AbsoluteX: 0x7d, | |
94 | AbsoluteY: 0x79, | |
85 | 95 | } |
86 | 96 | |
87 | 97 | |
89 | 99 | opcodes = { |
90 | 100 | Immediate: 0x29, |
91 | 101 | Absolute: 0x2d, |
102 | AbsoluteX: 0x3d, | |
103 | AbsoluteY: 0x39, | |
92 | 104 | } |
93 | 105 | |
94 | 106 | |
126 | 138 | opcodes = { |
127 | 139 | Immediate: 0xc9, |
128 | 140 | Absolute: 0xcd, |
141 | AbsoluteX: 0xdd, | |
142 | AbsoluteY: 0xd9, | |
129 | 143 | } |
130 | 144 | |
131 | 145 | |
165 | 179 | opcodes = { |
166 | 180 | Immediate: 0x49, |
167 | 181 | Absolute: 0x4d, |
182 | AbsoluteX: 0x5d, | |
183 | AbsoluteY: 0x59, | |
168 | 184 | } |
169 | 185 | |
170 | 186 | |
171 | 187 | class INC(Opcode): |
172 | 188 | opcodes = { |
173 | 189 | Absolute: 0xee, |
190 | AbsoluteX: 0xfe, | |
174 | 191 | } |
175 | 192 | |
176 | 193 | |
202 | 219 | opcodes = { |
203 | 220 | Immediate: 0xa9, |
204 | 221 | Absolute: 0xad, |
222 | AbsoluteX: 0xbd, | |
223 | AbsoluteY: 0xb9, | |
205 | 224 | } |
206 | 225 | |
207 | 226 | |
209 | 228 | opcodes = { |
210 | 229 | Immediate: 0xa2, |
211 | 230 | Absolute: 0xae, |
231 | AbsoluteY: 0xbe, | |
212 | 232 | } |
213 | 233 | |
214 | 234 | |
216 | 236 | opcodes = { |
217 | 237 | Immediate: 0xa0, |
218 | 238 | Absolute: 0xac, |
239 | AbsoluteX: 0xbc, | |
219 | 240 | } |
220 | 241 | |
221 | 242 | |
223 | 244 | opcodes = { |
224 | 245 | Immediate: 0x09, |
225 | 246 | Absolute: 0x0d, |
247 | AbsoluteX: 0x1d, | |
248 | AbsoluteY: 0x19, | |
226 | 249 | } |
227 | 250 | |
228 | 251 | |
229 | 252 | class ROL(Opcode): |
230 | 253 | opcodes = { |
231 | 254 | Implied: 0x2a, # Accumulator |
255 | Absolute: 0x2e, | |
256 | AbsoluteX: 0x3e, | |
232 | 257 | } |
233 | 258 | |
234 | 259 | |
235 | 260 | class ROR(Opcode): |
236 | 261 | opcodes = { |
237 | 262 | Implied: 0x6a, # Accumulator |
263 | Absolute: 0x6e, | |
264 | AbsoluteX: 0x7e, | |
238 | 265 | } |
239 | 266 | |
240 | 267 | |
248 | 275 | opcodes = { |
249 | 276 | Immediate: 0xe9, |
250 | 277 | Absolute: 0xed, |
278 | AbsoluteX: 0xfd, | |
279 | AbsoluteY: 0xf9, | |
251 | 280 | } |
252 | 281 | |
253 | 282 | |
260 | 289 | class STA(Opcode): |
261 | 290 | opcodes = { |
262 | 291 | Absolute: 0x8d, |
292 | AbsoluteX: 0x9d, | |
293 | AbsoluteY: 0x99, | |
263 | 294 | } |
264 | 295 | |
265 | 296 |