git @ Cat's Eye Technologies SixtyPical / 92525fd
Adding a constant word to a memory location. Chris Pressey 3 years ago
4 changed file(s) with 32 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
11 routine main
22 inputs score
33 outputs score
4 trashes c, z, v, n
4 trashes a, c, z, v, n
55 {
66 st off, c
77 add score, 1999
146146 self.emitter.emit(ADC(Immediate(Byte(src.value))))
147147 else:
148148 self.emitter.emit(ADC(Absolute(self.labels[src.name])))
149 elif isinstance(src, ConstantRef) and isinstance(dest, LocationRef) and dest.type == TYPE_WORD:
150 dest_label = self.labels[dest.name]
151 self.emitter.emit(LDA(Absolute(dest_label)))
152 self.emitter.emit(ADC(Immediate(Byte(src.low_byte()))))
153 self.emitter.emit(STA(Absolute(dest_label)))
154 self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
155 self.emitter.emit(ADC(Immediate(Byte(src.high_byte()))))
156 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
149157 else:
150158 raise UnsupportedOpcodeError(instr)
151159 elif opcode == 'sub':
317325 elif src.type == TYPE_WORD and dest.type == TYPE_WORD:
318326 if isinstance(src, ConstantRef):
319327 dest_label = self.labels[dest.name]
320 hi = (src.value >> 8) & 255
321 lo = src.value & 255
322 self.emitter.emit(LDA(Immediate(Byte(hi))))
328 self.emitter.emit(LDA(Immediate(Byte(src.high_byte()))))
323329 self.emitter.emit(STA(Absolute(dest_label)))
324 self.emitter.emit(LDA(Immediate(Byte(lo))))
330 self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
325331 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
326332 else:
327333 src_label = self.labels[src.name]
190190 def is_constant(self):
191191 return True
192192
193 def high_byte(self):
194 return (self.value >> 8) & 255
195
196 def low_byte(self):
197 return self.value & 255
198
193199
194200 REG_A = LocationRef(TYPE_BYTE, 'a')
195201 REG_X = LocationRef(TYPE_BYTE, 'x')
341341 | }
342342 = 00c0a0c84c06c060a2c860
343343
344 ### word operations
345
346 Adding a constant word to a memory location.
347
348 | word score
349 | routine main
350 | inputs a, score
351 | outputs score
352 | trashes a, c, z, v, n
353 | {
354 | st off, c
355 | add score, 1999
356 | }
357 = 00c018ad12c069cf8d12c0ad13c069078d13c060
358
344359 ### Buffers and Pointers
345360
346361 Load address into pointer.