0 | 0 |
# encoding: UTF-8
|
1 | 1 |
|
2 | |
from sixtypical.ast import Program, Routine, Block, Instr, SingleOp, If, Repeat, For, WithInterruptsOff
|
|
2 |
from sixtypical.ast import Program, Routine, Block, Instr, SingleOp, If, Repeat, For, WithInterruptsOff, Save
|
3 | 3 |
from sixtypical.model import (
|
4 | 4 |
ConstantRef, LocationRef, IndexedRef, IndirectRef, AddressRef,
|
5 | 5 |
TYPE_BIT, TYPE_BYTE, TYPE_WORD,
|
|
11 | 11 |
Immediate, Absolute, AbsoluteX, AbsoluteY, ZeroPage, Indirect, IndirectY, Relative,
|
12 | 12 |
LDA, LDX, LDY, STA, STX, STY,
|
13 | 13 |
TAX, TAY, TXA, TYA,
|
|
14 |
PHA, PLA,
|
14 | 15 |
CLC, SEC, ADC, SBC, ROL, ROR,
|
15 | 16 |
INC, INX, INY, DEC, DEX, DEY,
|
16 | 17 |
CMP, CPX, CPY, AND, ORA, EOR,
|
|
168 | 169 |
return self.compile_for(instr)
|
169 | 170 |
elif isinstance(instr, WithInterruptsOff):
|
170 | 171 |
return self.compile_with_interrupts_off(instr)
|
|
172 |
elif isinstance(instr, Save):
|
|
173 |
return self.compile_save(instr)
|
171 | 174 |
else:
|
172 | 175 |
raise NotImplementedError
|
173 | 176 |
|
|
612 | 615 |
self.emitter.emit(SEI())
|
613 | 616 |
self.compile_block(instr.block)
|
614 | 617 |
self.emitter.emit(CLI())
|
|
618 |
|
|
619 |
def compile_save(self, instr):
|
|
620 |
location = instr.locations[0]
|
|
621 |
if location == REG_A:
|
|
622 |
self.emitter.emit(PHA())
|
|
623 |
self.compile_block(instr.block)
|
|
624 |
self.emitter.emit(PLA())
|
|
625 |
elif location == REG_X:
|
|
626 |
self.emitter.emit(TXA())
|
|
627 |
self.emitter.emit(PHA())
|
|
628 |
self.compile_block(instr.block)
|
|
629 |
self.emitter.emit(PLA())
|
|
630 |
self.emitter.emit(TAX())
|
|
631 |
elif location == REG_Y:
|
|
632 |
self.emitter.emit(TYA())
|
|
633 |
self.emitter.emit(PHA())
|
|
634 |
self.compile_block(instr.block)
|
|
635 |
self.emitter.emit(PLA())
|
|
636 |
self.emitter.emit(TAY())
|
|
637 |
else:
|
|
638 |
raise NotImplementedError
|