mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-01-08 19:30:29 +00:00
Subtract word (constant or memory location) from word memory location.
This commit is contained in:
parent
1478db0fb4
commit
5f535c963e
@ -9,6 +9,7 @@ History of SixtyPical
|
||||
in a `copy` to a vector is a routine that is defined further down in the source.
|
||||
* Initialized `word` memory locations.
|
||||
* Can `copy` a literal word to a word table.
|
||||
* Subtract word (constant or memory location) from word memory location.
|
||||
* Fixed bug which was preventing `if` branches to diverge in what they initialized,
|
||||
if it was already initialized when going into the `if`.
|
||||
* Fixed a bug which was making it crash when trying to analyze `repeat forever` loops.
|
||||
|
@ -273,9 +273,15 @@ class Analyzer(object):
|
||||
else:
|
||||
self.assert_type(TYPE_WORD, dest)
|
||||
elif opcode == 'sub':
|
||||
self.assert_type(TYPE_BYTE, src, dest)
|
||||
context.assert_meaningful(src, dest, FLAG_C)
|
||||
context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
|
||||
if src.type == TYPE_BYTE:
|
||||
self.assert_type(TYPE_BYTE, src, dest)
|
||||
context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
|
||||
else:
|
||||
self.assert_type(TYPE_WORD, src, dest)
|
||||
context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
|
||||
context.set_touched(REG_A)
|
||||
context.set_unmeaningful(REG_A)
|
||||
elif opcode in ('inc', 'dec'):
|
||||
self.assert_type(TYPE_BYTE, dest)
|
||||
context.assert_meaningful(dest)
|
||||
|
@ -230,6 +230,26 @@ class Compiler(object):
|
||||
self.emitter.emit(SBC(Immediate(Byte(src.value))))
|
||||
else:
|
||||
self.emitter.emit(SBC(Absolute(self.labels[src.name])))
|
||||
elif isinstance(dest, LocationRef) and src.type == TYPE_WORD and dest.type == TYPE_WORD:
|
||||
if isinstance(src, ConstantRef):
|
||||
dest_label = self.labels[dest.name]
|
||||
self.emitter.emit(LDA(Absolute(dest_label)))
|
||||
self.emitter.emit(SBC(Immediate(Byte(src.low_byte()))))
|
||||
self.emitter.emit(STA(Absolute(dest_label)))
|
||||
self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
|
||||
self.emitter.emit(SBC(Immediate(Byte(src.high_byte()))))
|
||||
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
|
||||
elif isinstance(src, LocationRef):
|
||||
src_label = self.labels[src.name]
|
||||
dest_label = self.labels[dest.name]
|
||||
self.emitter.emit(LDA(Absolute(dest_label)))
|
||||
self.emitter.emit(SBC(Absolute(src_label)))
|
||||
self.emitter.emit(STA(Absolute(dest_label)))
|
||||
self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
|
||||
self.emitter.emit(SBC(Absolute(Offset(src_label, 1))))
|
||||
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
|
||||
else:
|
||||
raise UnsupportedOpcodeError(instr)
|
||||
else:
|
||||
raise UnsupportedOpcodeError(instr)
|
||||
elif opcode == 'inc':
|
||||
|
@ -593,6 +593,60 @@ Can't `sub` to a memory location that isn't writeable.
|
||||
| }
|
||||
? ForbiddenWriteError: a in main
|
||||
|
||||
You can `sub` a word constant from a word memory location.
|
||||
|
||||
| word score
|
||||
| routine main
|
||||
| inputs a, score
|
||||
| outputs score
|
||||
| trashes a, c, z, v, n
|
||||
| {
|
||||
| st on, c
|
||||
| sub score, 1999
|
||||
| }
|
||||
= ok
|
||||
|
||||
`sub`ing a word constant from a word memory location trashes `a`.
|
||||
|
||||
| word score
|
||||
| routine main
|
||||
| inputs a, score
|
||||
| outputs score, a
|
||||
| trashes c, z, v, n
|
||||
| {
|
||||
| st on, c
|
||||
| sub score, 1999
|
||||
| }
|
||||
? UnmeaningfulOutputError: a in main
|
||||
|
||||
You can `sub` a word memory location from another word memory location.
|
||||
|
||||
| word score
|
||||
| word delta
|
||||
| routine main
|
||||
| inputs score, delta
|
||||
| outputs score
|
||||
| trashes a, c, z, v, n
|
||||
| {
|
||||
| st off, c
|
||||
| sub score, delta
|
||||
| }
|
||||
= ok
|
||||
|
||||
`sub`ing a word memory location from a word memory location trashes `a`.
|
||||
|
||||
| word score
|
||||
| word delta
|
||||
| routine main
|
||||
| inputs score, delta
|
||||
| outputs score
|
||||
| trashes c, z, v, n
|
||||
| {
|
||||
| st off, c
|
||||
| sub score, delta
|
||||
| }
|
||||
? ForbiddenWriteError: a in main
|
||||
|
||||
### inc ###
|
||||
|
||||
Location must be initialized and writeable.
|
||||
|
@ -895,6 +895,47 @@ Adding a word memory location to another word memory location.
|
||||
= $081D STA $0822
|
||||
= $0820 RTS
|
||||
|
||||
Subtracting a constant word from a word memory location.
|
||||
|
||||
| word score
|
||||
| routine main
|
||||
| inputs score
|
||||
| outputs score
|
||||
| trashes a, c, z, v, n
|
||||
| {
|
||||
| st on, c
|
||||
| sub score, 1999
|
||||
| }
|
||||
= $080D SEC
|
||||
= $080E LDA $081F
|
||||
= $0811 SBC #$CF
|
||||
= $0813 STA $081F
|
||||
= $0816 LDA $0820
|
||||
= $0819 SBC #$07
|
||||
= $081B STA $0820
|
||||
= $081E RTS
|
||||
|
||||
Subtracting a word memory location from another word memory location.
|
||||
|
||||
| word score
|
||||
| word delta
|
||||
| routine main
|
||||
| inputs score, delta
|
||||
| outputs score
|
||||
| trashes a, c, z, v, n
|
||||
| {
|
||||
| st on, c
|
||||
| sub score, delta
|
||||
| }
|
||||
= $080D SEC
|
||||
= $080E LDA $0821
|
||||
= $0811 SBC $0823
|
||||
= $0814 STA $0821
|
||||
= $0817 LDA $0822
|
||||
= $081A SBC $0824
|
||||
= $081D STA $0822
|
||||
= $0820 RTS
|
||||
|
||||
### Buffers and Pointers
|
||||
|
||||
Load address into pointer.
|
||||
|
Loading…
Reference in New Issue
Block a user