1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-24 06:58:06 +11:00

zasm: parseExpr --> parseExprDE

This commit is contained in:
Virgil Dupras 2019-12-23 17:16:46 -05:00
parent 025b90909f
commit 476178ee7c
3 changed files with 77 additions and 84 deletions

View File

@ -643,14 +643,15 @@ _readK8:
jr _readExpr jr _readExpr
_readDouble: _readDouble:
push ix push de
call parseExpr call parseExprDE
jr nz, .end jr nz, .end
push ix \ pop bc ld b, d
ld c, e
; BC is already set. For good measure, let's set A to BC's MSB ; BC is already set. For good measure, let's set A to BC's MSB
ld a, b ld a, b
.end: .end:
pop ix pop de
ret ret
_readk7: _readk7:
@ -705,6 +706,7 @@ _readR4:
; read a rXX argument and return register number in A. ; read a rXX argument and return register number in A.
; Set Z for success. ; Set Z for success.
_readR5: _readR5:
push de
push ix push ix
ld a, (hl) ld a, (hl)
call upcase call upcase
@ -713,43 +715,44 @@ _readR5:
inc hl inc hl
call parseDecimal call parseDecimal
jr nz, .end jr nz, .end
push ix \ pop de
ld a, 31 ld a, 31
call _IX2A call _DE2A
.end: .end:
pop ix pop ix
pop de
ret ret
; Put IX's LSB into A and, additionally, ensure that the new value is <= ; Put DE's LSB into A and, additionally, ensure that the new value is <=
; than what was previously in A. ; than what was previously in A.
; Z for success. ; Z for success.
_IX2A: _DE2A:
push ix \ pop hl cp e
cp l jp c, unsetZ ; A < E
jp c, unsetZ ; A < L ld a, d
ld a, h
or a or a
ret nz ; should be zero ret nz ; should be zero
ld a, l ld a, e
; Z set from "or a" ; Z set from "or a"
ret ret
; Read expr and return success only if result in under number given in A ; Read expr and return success only if result in under number given in A
; Z for success ; Z for success
_readExpr: _readExpr:
push ix push de
push bc push bc
ld b, a ld b, a
call parseExpr call parseExprDE
jr nz, .end jr nz, .end
ld a, b ld a, b
call _IX2A call _DE2A
jr nz, .end jr nz, .end
or c or c
ld c, a ld c, a
cp a ; ensure Z cp a ; ensure Z
.end: .end:
pop bc pop bc
pop ix pop de
ret ret
; Parse one of the following: X, Y, Z, X+, Y+, Z+, -X, -Y, -Z. ; Parse one of the following: X, Y, Z, X+, Y+, Z+, -X, -Y, -Z.

View File

@ -40,6 +40,7 @@ dirHandlers:
.dw handleBIN .dw handleBIN
handleDB: handleDB:
push de
push hl push hl
.loop: .loop:
call readWord call readWord
@ -47,20 +48,21 @@ handleDB:
ld hl, scratchpad ld hl, scratchpad
call enterDoubleQuotes call enterDoubleQuotes
jr z, .stringLiteral jr z, .stringLiteral
call parseExpr call parseExprDE
jr nz, .badarg jr nz, .badarg
push ix \ pop hl ld a, d
ld a, h
or a ; cp 0 or a ; cp 0
jr nz, .overflow ; not zero? overflow jr nz, .overflow ; not zero? overflow
ld a, l ld a, e
call ioPutB call ioPutB
jr nz, .ioError jr nz, .ioError
.stopStrLit: .stopStrLit:
call readComma call readComma
jr z, .loop jr z, .loop
cp a ; ensure Z cp a ; ensure Z
.end:
pop hl pop hl
pop de
ret ret
.ioError: .ioError:
ld a, SHELL_ERR_IO_ERROR ld a, SHELL_ERR_IO_ERROR
@ -74,9 +76,8 @@ handleDB:
.overflow: .overflow:
ld a, ERR_OVFL ld a, ERR_OVFL
.error: .error:
call unsetZ or a ; unset Z
pop hl jr .end
ret
.stringLiteral: .stringLiteral:
ld a, (hl) ld a, (hl)
@ -89,24 +90,26 @@ handleDB:
jr .stringLiteral jr .stringLiteral
handleDW: handleDW:
push de
push hl push hl
.loop: .loop:
call readWord call readWord
jr nz, .badfmt jr nz, .badfmt
ld hl, scratchpad ld hl, scratchpad
call parseExpr call parseExprDE
jr nz, .badarg jr nz, .badarg
push ix \ pop hl ld a, e
ld a, l
call ioPutB call ioPutB
jr nz, .ioError jr nz, .ioError
ld a, h ld a, d
call ioPutB call ioPutB
jr nz, .ioError jr nz, .ioError
call readComma call readComma
jr z, .loop jr z, .loop
cp a ; ensure Z cp a ; ensure Z
.end:
pop hl pop hl
pop de
ret ret
.ioError: .ioError:
ld a, SHELL_ERR_IO_ERROR ld a, SHELL_ERR_IO_ERROR
@ -117,9 +120,8 @@ handleDW:
.badarg: .badarg:
ld a, ERR_BAD_ARG ld a, ERR_BAD_ARG
.error: .error:
call unsetZ or a ; unset Z
pop hl jr .end
ret
handleEQU: handleEQU:
call zasmIsLocalPass ; Are we in local pass? Then ignore all .equ. call zasmIsLocalPass ; Are we in local pass? Then ignore all .equ.
@ -178,14 +180,17 @@ handleEQU:
jp readWord jp readWord
handleORG: handleORG:
push de
call readWord call readWord
jr nz, .badfmt jr nz, .badfmt
call parseExpr call parseExprDE
jr nz, .badarg jr nz, .badarg
push ix \ pop hl ex de, hl
ld (DIREC_LASTVAL), hl ld (DIREC_LASTVAL), hl
call zasmSetOrg call zasmSetOrg
cp a ; ensure Z cp a ; ensure Z
.end:
pop de
ret ret
.badfmt: .badfmt:
ld a, ERR_BAD_FMT ld a, ERR_BAD_FMT
@ -193,31 +198,28 @@ handleORG:
.badarg: .badarg:
ld a, ERR_BAD_ARG ld a, ERR_BAD_ARG
.error: .error:
call unsetZ or a ; unset Z
ret jr .end
handleFIL: handleFIL:
call readWord call readWord
jr nz, .badfmt jr nz, .badfmt
call parseExpr call parseExprDE
jr nz, .badarg jr nz, .badarg
push bc ; --> lvl 1 ld a, d
push ix \ pop bc
ld a, b
cp 0xd0 cp 0xd0
jr nc, .overflow jr nc, .overflow
.loop: .loop:
ld a, b ld a, d
or c or e
jr z, .loopend jr z, .loopend
xor a xor a
call ioPutB call ioPutB
jr nz, .ioError jr nz, .ioError
dec bc dec de
jr .loop jr .loop
.loopend: .loopend:
cp a ; ensure Z cp a ; ensure Z
pop bc ; <-- lvl 1
ret ret
.ioError: .ioError:
ld a, SHELL_ERR_IO_ERROR ld a, SHELL_ERR_IO_ERROR
@ -229,11 +231,11 @@ handleFIL:
ld a, ERR_BAD_ARG ld a, ERR_BAD_ARG
jp unsetZ jp unsetZ
.overflow: .overflow:
pop bc ; <-- lvl 1
ld a, ERR_OVFL ld a, ERR_OVFL
jp unsetZ jp unsetZ
handleOUT: handleOUT:
push de
push hl push hl
; Read our expression ; Read our expression
call readWord call readWord
@ -241,12 +243,11 @@ handleOUT:
call zasmIsFirstPass ; No .out during first pass call zasmIsFirstPass ; No .out during first pass
jr z, .end jr z, .end
ld hl, scratchpad ld hl, scratchpad
call parseExpr call parseExprDE
jr nz, .badarg jr nz, .badarg
push ix \ pop hl ld a, d
ld a, h
out (ZASM_DEBUG_PORT), a out (ZASM_DEBUG_PORT), a
ld a, l ld a, e
out (ZASM_DEBUG_PORT), a out (ZASM_DEBUG_PORT), a
jr .end jr .end
.badfmt: .badfmt:
@ -255,9 +256,10 @@ handleOUT:
.badarg: .badarg:
ld a, ERR_BAD_ARG ld a, ERR_BAD_ARG
.error: .error:
call unsetZ or a ; unset Z
.end: .end:
pop hl pop hl
pop de
ret ret
handleINC: handleINC:

View File

@ -146,7 +146,7 @@ parseIXY:
; any argspec (A == 0 means arg is empty). A return value of 0xff means an ; any argspec (A == 0 means arg is empty). A return value of 0xff means an
; error. ; error.
; ;
; If the parsed argument is a number constant, 'N' is returned and IX contains ; If the parsed argument is a number constant, 'N' is returned and DE contains
; the value of that constant. ; the value of that constant.
parseArg: parseArg:
call strlen call strlen
@ -154,13 +154,8 @@ parseArg:
ret z ; empty string? A already has our result: 0 ret z ; empty string? A already has our result: 0
push bc push bc
push de
push hl push hl
; We always initialize IX to zero so that non-numerical args end up with
; a clean zero.
ld ix, 0
ld de, argspecTbl ld de, argspecTbl
; DE now points the the "argspec char" part of the entry, but what ; DE now points the the "argspec char" part of the entry, but what
; we're comparing in the loop is the string next to it. Let's offset ; we're comparing in the loop is the string next to it. Let's offset
@ -181,7 +176,7 @@ parseArg:
; (HL) has no parens ; (HL) has no parens
call .maybeParseExpr call .maybeParseExpr
jr nz, .nomatch jr nz, .nomatch
; We have a proper number in no parens. Number in IX. ; We have a proper number in no parens. Number in DE.
ld a, 'N' ld a, 'N'
jr .end jr .end
.withParens: .withParens:
@ -208,23 +203,20 @@ parseArg:
.parseNumberInParens: .parseNumberInParens:
call .maybeParseExpr call .maybeParseExpr
jr nz, .nomatch jr nz, .nomatch
; We have a proper number in parens. Number in IX ; We have a proper number in parens. Number in DE
; is '-' in B? if yes, we need to negate the low part of IX ; is '-' in B? if yes, we need to negate the low part of DE
ld a, b ld a, b
cp '-' cp '-'
jr nz, .dontNegateIX jr nz, .dontNegateDE
; we need to negate the low part of IX ; we need to negate the low part of DE
; TODO: when parsing routines properly support unary negative numbers, ; TODO: when parsing routines properly support unary negative numbers,
; We could replace this complicated scheme below with a nice hack where ; We could replace this complicated scheme below with a nice hack where
; we start parsing our displacement number at the '+' and '-' char. ; we start parsing our displacement number at the '+' and '-' char.
; HL isn't needed anymore and can be destroyed. ld a, e
push ix \ pop hl
ld a, l
neg neg
ld l, a ld e, a
push hl \ pop ix .dontNegateDE:
.dontNegateIX:
ld a, c ; M, x, or y ld a, c ; M, x, or y
jr .end jr .end
.nomatch: .nomatch:
@ -235,9 +227,13 @@ parseArg:
; found the matching argspec row. Our result is one byte left of DE. ; found the matching argspec row. Our result is one byte left of DE.
dec de dec de
ld a, (de) ld a, (de)
; When we have non-numerical args, we set DE to zero to have a clean
; result.
ld de, 0
.end: .end:
pop hl pop hl
pop de
pop bc pop bc
ret ret
@ -247,9 +243,10 @@ parseArg:
; harmless, but in some cases it causes false failures. For example, ; harmless, but in some cases it causes false failures. For example,
; a "-" operator can cause is to falsely overflow and generate ; a "-" operator can cause is to falsely overflow and generate
; truncation error. ; truncation error.
ld de, 0 ; in first pass, return a clean zero
call zasmIsFirstPass call zasmIsFirstPass
ret z ret z
jp parseExpr jp parseExprDE
; Returns, with Z, whether A is a groupId ; Returns, with Z, whether A is a groupId
isGroupId: isGroupId:
@ -817,27 +814,18 @@ spitUpcode:
ld (INS_UPCODE+2), a ld (INS_UPCODE+2), a
ret ret
; Parse argument in (HL) and place it in (DE) ; Parse argument in (HL) and place it in (IX)
; DE is not preserved
; Sets Z on success, reset on error. ; Sets Z on success, reset on error.
processArg: processArg:
call parseArg call parseArg
cp 0xff cp 0xff
jr z, .error jr z, .error
ld (de), a ld (ix), a
; When A is a number, IX is set with the value of that number. Because ; When A is a number, DE is set with the value of that number. Because
; We don't use the space allocated to store those numbers in any other ; We don't use the space allocated to store those numbers in any other
; occasion, we store IX there unconditonally, LSB first. ; occasion, we store DE there unconditonally, LSB first.
inc de ld (ix+1), e
ex (sp), ix ; (SP) is kept in IX and will be restored ld (ix+2), d
ex (sp), hl ; old HL is on (SP)
ld a, l
ld (de), a
inc de
ld a, h
ld (de), a
ex (sp), hl ; restore old HL from (SP)
ex (sp), ix ; restore old (SP) from IX
cp a ; ensure Z cp a ; ensure Z
ret ret
.error: .error:
@ -860,14 +848,14 @@ parseInstruction:
ld (INS_CURARG2), a ld (INS_CURARG2), a
call readWord call readWord
jr nz, .nomorearg jr nz, .nomorearg
ld de, INS_CURARG1 ld ix, INS_CURARG1
call processArg call processArg
jr nz, .end ; A is set to error, Z is unset jr nz, .end ; A is set to error, Z is unset
call readComma call readComma
jr nz, .nomorearg jr nz, .nomorearg
call readWord call readWord
jr nz, .badfmt jr nz, .badfmt
ld de, INS_CURARG2 ld ix, INS_CURARG2
call processArg call processArg
jr nz, .end ; A is set to error, Z is unset jr nz, .end ; A is set to error, Z is unset
.nomorearg: .nomorearg: