From 8594084b0610abf783ddcc3b4a9679eafea1cdcd Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 21 Apr 2019 14:23:24 -0400 Subject: [PATCH] zasm: simplify code --- apps/zasm/zasm.asm | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/zasm/zasm.asm b/apps/zasm/zasm.asm index e9c8f73..8ccb0ba 100644 --- a/apps/zasm/zasm.asm +++ b/apps/zasm/zasm.asm @@ -391,7 +391,8 @@ findInGroup: ; For constant args, it's easy: if A == (HL), it's a success. ; If it's not this, then we check if it's a numerical arg. ; If A is a group ID, we do something else: we check that (HL) exists in the -; groupspec (argGrpTbl). +; groupspec (argGrpTbl). Moreover, we go and write the group's "value" (index) +; in (HL+1). This will save us significant processing later in getUpcode. ; Set Z according to whether we match or not. matchArg: cp a, (hl) @@ -430,6 +431,12 @@ matchArg: pop hl call findInGroup pop hl + ret nz + ; we found our group? let's write down its "value" in (HL+1). We hold + ; this value in A at the moment. + inc hl + ld (hl), a + dec hl ret ; Compare primary row at (DE) with string at tokInstr. Sets Z flag if there's a @@ -535,11 +542,8 @@ handleBITR: call handleBIT ret nz ; error ; get group value - ld a, (curArg2) - ld h, 0xb - call findInGroup - ret nz ; error - push af ; push group value + ld a, (curArg2+1) ; group value + ld c, a ; write first upcode ld a, 0xcb ; first upcode ld (curUpcode), a @@ -549,8 +553,7 @@ handleBITR: call rlaX ; Now we have group value in stack, bit value in A (properly shifted) ; and we want to OR them together - pop bc ; from push af earlier - or b ; Now we have our ORed value + or c ; Now we have our ORed value or 0b01000000 ; and with the constant value for that byte... ; we're good! ld (curUpcode+1), a @@ -609,11 +612,7 @@ handleLDIYr: ld a, 0xfd handleLDIXYr: ld (curUpcode), a - ; get group value - ld a, (curArg2) - ld h, 0xb - call findInGroup - ret nz ; error + ld a, (curArg2+1) ; group value or 0b01110000 ; second upcode ld (curUpcode+1), a ld a, (curArg1+1) ; IXY displacement @@ -676,14 +675,9 @@ getUpcode: ld hl, curArg1 .isGroup: ; A is a group, good, now let's get its value. HL is pointing to - ; the argument. A little bit of stack gymnastic is necessary to put - ; A into H and (HL) into A. - push af + ; the argument. Our group value is at (HL+1). + inc hl ld a, (hl) - pop hl ; from push af 2 lines above - call findInGroup ; we don't check for match, it's supposed to - ; always match. Something is very wrong if it - ; doesn't ; Now, we have our arg "group value" in A. Were going to need to ; displace it left by the number of steps specified in the table. push af