mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-26 14:49:15 +00:00
{Low,High}AddressByte emittables to fix copy, make indirect call!
This commit is contained in:
parent
0b2b5d904e
commit
0d3ac8c247
@ -7,7 +7,7 @@ from sixtypical.model import (
|
||||
RoutineType, VectorType,
|
||||
REG_A, REG_X, REG_Y, FLAG_C
|
||||
)
|
||||
from sixtypical.emitter import Byte, Label, Offset
|
||||
from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte
|
||||
from sixtypical.gen6502 import (
|
||||
Immediate, Absolute, AbsoluteX, AbsoluteY, Indirect, Relative,
|
||||
LDA, LDX, LDY, STA, STX, STY,
|
||||
@ -267,14 +267,20 @@ class Compiler(object):
|
||||
self.compile_block(instr.block)
|
||||
self.emitter.emit(CLI())
|
||||
elif opcode == 'copy':
|
||||
if isinstance(src.type, (RoutineType, VectorType)) and \
|
||||
isinstance(dest.type, VectorType):
|
||||
if isinstance(src.type, VectorType) and isinstance(dest.type, VectorType):
|
||||
src_label = self.labels[src.name]
|
||||
dest_label = self.labels[dest.name]
|
||||
self.emitter.emit(LDA(Absolute(src_label)))
|
||||
self.emitter.emit(STA(Absolute(dest_label)))
|
||||
self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
|
||||
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
|
||||
elif isinstance(src.type, RoutineType) and isinstance(dest.type, VectorType):
|
||||
src_label = self.labels[src.name]
|
||||
dest_label = self.labels[dest.name]
|
||||
self.emitter.emit(LDA(Immediate(HighAddressByte(src_label))))
|
||||
self.emitter.emit(STA(Absolute(dest_label)))
|
||||
self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
|
||||
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
|
||||
else:
|
||||
raise NotImplementedError(src.type)
|
||||
else:
|
||||
|
@ -82,6 +82,39 @@ class Offset(Emittable):
|
||||
return "%s(%r, %r)" % (self.__class__.__name__, self.label, self.offset)
|
||||
|
||||
|
||||
class HighAddressByte(Emittable):
|
||||
def __init__(self, label):
|
||||
assert isinstance(label, Label)
|
||||
self.label = label
|
||||
|
||||
def size(self):
|
||||
return 1
|
||||
|
||||
def serialize(self, addr=None):
|
||||
return self.label.serialize()[0]
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%r)" % (self.__class__.__name__, self.label)
|
||||
|
||||
|
||||
class LowAddressByte(Emittable):
|
||||
def __init__(self, label):
|
||||
assert isinstance(label, Label)
|
||||
self.label = label
|
||||
|
||||
def size(self):
|
||||
return 1
|
||||
|
||||
def serialize(self, addr=None):
|
||||
return self.label.serialize()[1]
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%r)" % (self.__class__.__name__, self.label)
|
||||
|
||||
|
||||
# - - - -
|
||||
|
||||
|
||||
class Emitter(object):
|
||||
def __init__(self, addr):
|
||||
self.accum = []
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Emittables for 6502 machine code."""
|
||||
|
||||
from sixtypical.emitter import Emittable, Byte, Label, Offset
|
||||
from sixtypical.emitter import Emittable, Byte, Label, Offset, LowAddressByte, HighAddressByte
|
||||
|
||||
|
||||
class AddressingMode(Emittable):
|
||||
@ -28,7 +28,7 @@ class Implied(AddressingMode):
|
||||
|
||||
class Immediate(AddressingMode):
|
||||
def __init__(self, value):
|
||||
assert isinstance(value, Byte)
|
||||
assert isinstance(value, (Byte, LowAddressByte, HighAddressByte))
|
||||
self.value = value
|
||||
|
||||
def size(self):
|
||||
@ -82,6 +82,9 @@ class Relative(AddressingMode):
|
||||
return self.value.serialize_relative_to(addr)
|
||||
|
||||
|
||||
# - - - -
|
||||
|
||||
|
||||
class Instruction(Emittable):
|
||||
def __init__(self, operand=None):
|
||||
self.operand = operand or Implied()
|
||||
|
Loading…
Reference in New Issue
Block a user