Skip to content

Commit 29ab08b

Browse files
committed
Process LD IX/IY + n always with +
LD (IX + n), n uses always '+' now implicitly. The sign of the offset is calculated within the expression. So LD (IX - 100), 0 is actually assembled as LD (IX + (-100)), 0. This makes things more consistent.
1 parent d429033 commit 29ab08b

File tree

9 files changed

+44
-9
lines changed

9 files changed

+44
-9
lines changed

asmparse.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ def try_eval(self):
284284
if item == '-' and len(self.children) == 1:
285285
return -self.left.try_eval()
286286

287+
if item == '+' and len(self.children) == 1:
288+
return self.left.try_eval()
289+
287290
try:
288291
return self.funct[item](self.left.try_eval(), self.right.try_eval())
289292
except ZeroDivisionError:
@@ -788,18 +791,33 @@ def p_reg8_hl(p):
788791

789792

790793
def p_ind8_I(p):
791-
""" reg8_I : LP IX PLUS expr RP
792-
| LP IX MINUS expr RP
793-
| LP IY PLUS expr RP
794-
| LP IY MINUS expr RP
794+
""" reg8_I : LP IX expr RP
795+
| LP IY expr RP
795796
| LP IX PLUS pexpr RP
796797
| LP IX MINUS pexpr RP
797798
| LP IY PLUS pexpr RP
798799
| LP IY MINUS pexpr RP
799800
"""
800-
expr = p[4]
801-
if p[3] == '-':
802-
expr = Expr.makenode(Container('-', p.lineno(3)), expr)
801+
if len(p) == 6:
802+
expr = p[4]
803+
sign = p[3]
804+
else:
805+
expr = p[3]
806+
gen_ = expr.inorder()
807+
first_expr = next(gen_, '')
808+
if first_expr and first_expr.parent:
809+
if len(first_expr.parent.children) == 2:
810+
first_token = first_expr.symbol.item
811+
else:
812+
first_token = first_expr.parent.symbol.item
813+
else:
814+
first_token = '<nothing>'
815+
if first_token not in ('-', '+'):
816+
error(p.lineno(2), "Unexpected token '{}'. Expected '+' or '-'".format(first_token))
817+
sign = '+'
818+
819+
if sign == '-':
820+
expr = Expr.makenode(Container(sign, p.lineno(2)), expr)
803821

804822
p[0] = ('(%s+N)' % p[2], expr)
805823

@@ -1355,8 +1373,9 @@ def p_expr_lprp(p):
13551373

13561374
def p_expr_uminus(p):
13571375
""" expr : MINUS expr %prec UMINUS
1376+
| PLUS expr %prec UMINUS
13581377
"""
1359-
p[0] = Expr.makenode(Container('-', p.lineno(1)), p[2])
1378+
p[0] = Expr.makenode(Container(p[1], p.lineno(1)), p[2])
13601379

13611380

13621381
def p_expr_int(p):

tests/functional/ldix.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
ld (ix - 12 + 5), 0
3+
ld (ix + (-12 + 5)), 0
4+

tests/functional/ldix.bin

8 Bytes
Binary file not shown.

tests/functional/ldix1.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
ld (ix - 12), 0
3+

tests/functional/ldix1.bin

4 Bytes
Binary file not shown.

tests/functional/ldix2.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
ld (ix (- 12 + 5)), 0
3+

tests/functional/ldix3.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
ld (ix 12 + 5), 0
3+

tests/functional/ldix4.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
ld (ix * 12), 0
3+

zxbasm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from api import global_
2525

2626
# Release version
27-
VERSION = '1.12.0'
27+
VERSION = '1.13.0'
2828

2929

3030
def main(args=None):

0 commit comments

Comments
 (0)