git @ Cat's Eye Technologies SixtyPical / f4186c5
AbsoluteX, AbsoluteY addressing modes in 6502-code generator. Chris Pressey 6 years ago
1 changed file(s) with 33 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 """This is just a sketch for now."""
0 """Emittables for 6502 machine code."""
11
22 from sixtypical.emitter import Emittable, Byte, Word, Label
33
3939
4040 class Absolute(AddressingMode):
4141 def __init__(self, value):
42 assert isinstance(value, (Word, Label))
42 assert isinstance(value, Label)
4343 self.value = value
4444
4545 def size(self):
4747
4848 def serialize(self, addr):
4949 return self.value.serialize(addr)
50
51
52 class AbsoluteX(Absolute):
53 pass
54
55
56 class AbsoluteY(Absolute):
57 pass
5058
5159
5260 class Relative(AddressingMode):
8290 opcodes = {
8391 Immediate: 0x69,
8492 Absolute: 0x6d,
93 AbsoluteX: 0x7d,
94 AbsoluteY: 0x79,
8595 }
8696
8797
8999 opcodes = {
90100 Immediate: 0x29,
91101 Absolute: 0x2d,
102 AbsoluteX: 0x3d,
103 AbsoluteY: 0x39,
92104 }
93105
94106
126138 opcodes = {
127139 Immediate: 0xc9,
128140 Absolute: 0xcd,
141 AbsoluteX: 0xdd,
142 AbsoluteY: 0xd9,
129143 }
130144
131145
165179 opcodes = {
166180 Immediate: 0x49,
167181 Absolute: 0x4d,
182 AbsoluteX: 0x5d,
183 AbsoluteY: 0x59,
168184 }
169185
170186
171187 class INC(Opcode):
172188 opcodes = {
173189 Absolute: 0xee,
190 AbsoluteX: 0xfe,
174191 }
175192
176193
202219 opcodes = {
203220 Immediate: 0xa9,
204221 Absolute: 0xad,
222 AbsoluteX: 0xbd,
223 AbsoluteY: 0xb9,
205224 }
206225
207226
209228 opcodes = {
210229 Immediate: 0xa2,
211230 Absolute: 0xae,
231 AbsoluteY: 0xbe,
212232 }
213233
214234
216236 opcodes = {
217237 Immediate: 0xa0,
218238 Absolute: 0xac,
239 AbsoluteX: 0xbc,
219240 }
220241
221242
223244 opcodes = {
224245 Immediate: 0x09,
225246 Absolute: 0x0d,
247 AbsoluteX: 0x1d,
248 AbsoluteY: 0x19,
226249 }
227250
228251
229252 class ROL(Opcode):
230253 opcodes = {
231254 Implied: 0x2a, # Accumulator
255 Absolute: 0x2e,
256 AbsoluteX: 0x3e,
232257 }
233258
234259
235260 class ROR(Opcode):
236261 opcodes = {
237262 Implied: 0x6a, # Accumulator
263 Absolute: 0x6e,
264 AbsoluteX: 0x7e,
238265 }
239266
240267
248275 opcodes = {
249276 Immediate: 0xe9,
250277 Absolute: 0xed,
278 AbsoluteX: 0xfd,
279 AbsoluteY: 0xf9,
251280 }
252281
253282
260289 class STA(Opcode):
261290 opcodes = {
262291 Absolute: 0x8d,
292 AbsoluteX: 0x9d,
293 AbsoluteY: 0x99,
263294 }
264295
265296