longm/longx properties

This commit is contained in:
Kelvin Sherlock 2019-08-11 01:13:49 -04:00
parent 9b1084f9a3
commit 3eff95d766
2 changed files with 27 additions and 18 deletions

31
asm.py
View File

@ -33,9 +33,11 @@ class Assembler(object):
def __init__(self, name):
self.name = name
self.mx = 0b11
self.blocks = []
self.b = None
self.label = 0
self.new_block()
@ -56,11 +58,8 @@ class Assembler(object):
self.new_block()
def new_block(self):
mx = 0b11
if self.b:
mx = self.b.mx
self.b = Block()
self.b.mx = mx
self.b.mx = self.mx
self.blocks.append(self.b)
@ -75,24 +74,35 @@ class Assembler(object):
self.b.instr.append("\t" + op)
def mx_common(self, onoff, mask):
mx = oldmx = self.b.mx
mx = self.mx
if onoff: mx |= mask
else: mx &= ~mask
if mx == oldmx: return
if mx == self.mx: return
if not self.b.empty():
self.new_block()
self.b.mx = mx
self.mx = mx
@property
def longm(self):
return bool(self.mx & 0b10)
def longm(self, onoff):
self.mx_common(onoff, 0b10)
@longm.setter
def longm(self, value):
self.mx_common(value, 0b10)
def longx(self, onoff):
self.mx_common(onoff, 0b01)
@property
def longx(self):
return bool(self.mx & 0b01)
@longx.setter
def longx(self, value):
self.mx_common(value, 0b01)
def merge_rts(self):
blocks = []
@ -214,6 +224,7 @@ class Assembler(object):
self.footer(io)
self.blocks = []
self.mx = 0b11
self.new_block()
def header(self, io):

View File

@ -33,7 +33,7 @@ def mask_char(asm, short_m, old, new):
if old & ~new:
asm.emit("tya", 1)
asm.longm(not short_m)
asm.longm = not short_m
if short_m:
asm.emit("ora #${:02x}".format(new), 2)
else:
@ -70,10 +70,10 @@ def generate_asm(asm, d, level):
if count>0:
if short_m:
asm.longm(False)
asm.longm = False
asm.emit("sep #$20", 2)
else:
asm.longm(True)
asm.longm = True
if level==0:
asm.emit("lda (cp)", 2)
@ -90,14 +90,14 @@ def generate_asm(asm, d, level):
l = asm.reserve_label()
if flag_i: mask = mask_char(asm, short_m, mask, or_mask(k))
v = str_to_int(k)
asm.longm(True)
asm.longm = True
asm.emit("cmp #${:04x}\t; '{}'".format(v, encode_string(k)), 3)
asm.bne(l)
generate_asm(asm, dd, level+1)
asm.emit_label(l)
if single and double:
asm.longm(False)
asm.longm = False
asm.emit("sep #$20", 2)
short_m = True
mask = mask & 0xff
@ -107,15 +107,13 @@ def generate_asm(asm, d, level):
l = asm.reserve_label()
if flag_i: mask = mask_char(asm, short_m, mask, or_mask(k))
v = str_to_int(k)
asm.longm(False)
asm.longm = False
asm.emit("cmp #${:02x}\t; '{}'".format(v, encode_string(k)), 2)
asm.bne(l)
generate_asm(asm, dd, level+1)
asm.emit_label(l)
# if short_m: asm.longm(True)
if "" in d:
d = d[""]
asm.emit("ldx #{}\t; '{}'".format(d["__value__"], d["__key__"]), 3)