1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-25 23:49:17 +00:00

Adding a constant word to a memory location.

This commit is contained in:
Chris Pressey 2017-12-07 12:48:56 +00:00
parent cf679b293a
commit 92525fd482
4 changed files with 32 additions and 5 deletions

View File

@ -2,7 +2,7 @@ word score
routine main
inputs score
outputs score
trashes c, z, v, n
trashes a, c, z, v, n
{
st off, c
add score, 1999

View File

@ -147,6 +147,14 @@ class Compiler(object):
self.emitter.emit(ADC(Immediate(Byte(src.value))))
else:
self.emitter.emit(ADC(Absolute(self.labels[src.name])))
elif isinstance(src, ConstantRef) and isinstance(dest, LocationRef) and dest.type == TYPE_WORD:
dest_label = self.labels[dest.name]
self.emitter.emit(LDA(Absolute(dest_label)))
self.emitter.emit(ADC(Immediate(Byte(src.low_byte()))))
self.emitter.emit(STA(Absolute(dest_label)))
self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
self.emitter.emit(ADC(Immediate(Byte(src.high_byte()))))
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
else:
raise UnsupportedOpcodeError(instr)
elif opcode == 'sub':
@ -318,11 +326,9 @@ class Compiler(object):
elif src.type == TYPE_WORD and dest.type == TYPE_WORD:
if isinstance(src, ConstantRef):
dest_label = self.labels[dest.name]
hi = (src.value >> 8) & 255
lo = src.value & 255
self.emitter.emit(LDA(Immediate(Byte(hi))))
self.emitter.emit(LDA(Immediate(Byte(src.high_byte()))))
self.emitter.emit(STA(Absolute(dest_label)))
self.emitter.emit(LDA(Immediate(Byte(lo))))
self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
else:
src_label = self.labels[src.name]

View File

@ -191,6 +191,12 @@ class ConstantRef(Ref):
def is_constant(self):
return True
def high_byte(self):
return (self.value >> 8) & 255
def low_byte(self):
return self.value & 255
REG_A = LocationRef(TYPE_BYTE, 'a')
REG_X = LocationRef(TYPE_BYTE, 'x')

View File

@ -342,6 +342,21 @@ goto.
| }
= 00c0a0c84c06c060a2c860
### word operations
Adding a constant word to a memory location.
| word score
| routine main
| inputs a, score
| outputs score
| trashes a, c, z, v, n
| {
| st off, c
| add score, 1999
| }
= 00c018ad12c069cf8d12c0ad13c069078d13c060
### Buffers and Pointers
Load address into pointer.