lib/expr: make EXPR_PARSE put result in DE instead of IX

Finally getting rid of this bad mistake of using IX for this.
This commit is contained in:
Virgil Dupras 2019-12-29 17:37:04 -05:00
parent 981c93bfd4
commit 15628da7de
5 changed files with 20 additions and 46 deletions

View File

@ -98,12 +98,9 @@ parseLiteralOrVar:
push hl ; --> lvl 1
ld hl, VAR_TBL
call addHL
push de ; --> lvl 2
ld e, (hl)
inc hl
ld d, (hl)
push de \ pop ix
pop de ; <-- lvl 2
pop hl ; <-- lvl 1
cp a ; ensure Z
ret

View File

@ -5,7 +5,7 @@
;
; EXPR_PARSE: routine to call to parse literals or symbols that are part of
; the expression. Routine's signature:
; String in (HL), returns its parsed value to IX. Z for success.
; String in (HL), returns its parsed value to DE. Z for success.
;
; *** Code ***
;
@ -258,7 +258,6 @@ _parseNumber:
ret
.skip1:
; End of special case 1
push ix
; Copy beginning of string to DE, we'll need it later
ld d, h
ld e, l
@ -288,19 +287,16 @@ _parseNumber:
xor a
ld (hl), a
ex de, hl ; rewind to beginning of number
call EXPR_PARSE
call EXPR_PARSE ; --> DE
ex af, af' ; keep result flags away while we restore (HL)
push ix \ pop de ; result in DE
pop hl ; <-- lvl 2, end of string
pop af ; <-- lvl 1, saved op
ld (hl), a
ex af, af' ; restore Z from EXPR_PARSE
jr nz, .end
ret nz
; HL is currently at the end of the number's string
; On success, have A be the operator char following the number
ex af, af'
.end:
pop ix
ret
; Sets Z if A contains a valid operator char or a null char.

View File

@ -67,7 +67,7 @@ parseHexPair:
; add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
; sub 0xff-9 ; maps to 0-9 and carries if not a digit
; Parse string at (HL) as a decimal value and return value in IX under the
; Parse string at (HL) as a decimal value and return value in DE under the
; same conditions as parseLiteral.
; Sets Z on success, unset on error.
; To parse successfully, all characters following HL must be digits and those
@ -76,7 +76,7 @@ parseHexPair:
; digit in the string.
parseDecimal:
push hl
push hl ; --> lvl 1
ld a, (hl)
add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
@ -129,23 +129,23 @@ parseDecimal:
; to 0x00+(0xff-'9')-(0xff-9)=-0x30=0xd0
sub 0xd0 ; if a is null, set Z
; a is checked for null before any errors
push hl \ pop ix
exx ; restore original de and bc
pop hl
push hl ; --> lvl 2, result
exx ; restore original bc
pop de ; <-- lvl 2, result
pop hl ; <-- lvl 1, orig
ret z
; A is not 0? Ok, but if it's a space, we're happy too.
jp isWS
.error:
pop hl
pop hl ; <-- lvl 1, orig
jp unsetZ
; Parse string at (HL) as a hexadecimal value and return value in IX under the
; Parse string at (HL) as a hexadecimal value and return value in DE under the
; same conditions as parseLiteral.
parseHexadecimal:
call hasHexPrefix
ret nz
push hl
push de
ld d, 0
inc hl ; get rid of "0x"
inc hl
@ -179,8 +179,6 @@ parseHexadecimal:
.error:
call unsetZ
.end:
push de \ pop ix
pop de
pop hl
ret
@ -196,15 +194,14 @@ hasHexPrefix:
pop hl
ret
; Parse string at (HL) as a binary value (0b010101) and return value in IX.
; High IX byte is always clear.
; Parse string at (HL) as a binary value (0b010101) and return value in E.
; D is always zero.
; Sets Z on success.
parseBinaryLiteral:
call hasBinPrefix
ret nz
push bc
push hl
push de
ld d, 0
inc hl ; get rid of "0b"
inc hl
@ -236,8 +233,6 @@ parseBinaryLiteral:
.error:
call unsetZ
.end:
push de \ pop ix
pop de
pop hl
pop bc
ret
@ -255,7 +250,7 @@ hasBinPrefix:
ret
; Parse string at (HL) and, if it is a char literal, sets Z and return
; corresponding value in IX. High IX byte is always clear.
; corresponding value in E. D is always zero.
;
; A valid char literal starts with ', ends with ' and has one character in the
; middle. No escape sequence are accepted, but ''' will return the apostrophe
@ -266,7 +261,6 @@ parseCharLiteral:
ret nz
push hl
push de
inc hl
inc hl
cp (hl)
@ -283,12 +277,10 @@ parseCharLiteral:
ld e, a
cp a ; ensure Z
.end:
push de \ pop ix
pop de
pop hl
ret
; Parses the string at (HL) and returns the 16-bit value in IX. The string
; Parses the string at (HL) and returns the 16-bit value in DE. The string
; can be a decimal literal (1234), a hexadecimal literal (0x1234) or a char
; literal ('X').
;

View File

@ -657,7 +657,6 @@ _readDouble:
_readk7:
push hl
push de
push ix
call parseExpr
jr nz, .end
; If we're in first pass, stop now. The value of HL doesn't matter and
@ -686,7 +685,6 @@ _readk7:
ld a, l
cp a ; ensure Z
.end:
pop ix
pop de
pop hl
ret
@ -707,7 +705,6 @@ _readR4:
; Set Z for success.
_readR5:
push de
push ix
ld a, (hl)
call upcase
cp 'R'
@ -715,11 +712,9 @@ _readR5:
inc hl
call parseDecimal
jr nz, .end
push ix \ pop de
ld a, 31
call _DE2A
.end:
pop ix
pop de
ret

View File

@ -1,5 +1,5 @@
; Parse string in (HL) and return its numerical value whether its a number
; literal or a symbol. Returns value in IX.
; literal or a symbol. Returns value in DE.
; Sets Z if number or symbol is valid, unset otherwise.
parseNumberOrSymbol:
call parseLiteral
@ -14,31 +14,25 @@ parseNumberOrSymbol:
cp '@'
jr nz, .symbol
; last val
ld ix, (DIREC_LASTVAL)
ld de, (DIREC_LASTVAL)
ret
.symbol:
push de ; --> lvl 1
call symFindVal ; --> DE
jr nz, .notfound
; value in DE. We need it in IX
push de \ pop ix
pop de ; <-- lvl 1
cp a ; ensure Z
ret
.notfound:
pop de ; <-- lvl 1
; If not found, check if we're in first pass. If we are, it doesn't
; matter that we didn't find our symbol. Return success anyhow.
; Otherwise return error. Z is already unset, so in fact, this is the
; same as jumping to zasmIsFirstPass
; however, before we do, load IX with zero. Returning dummy non-zero
; however, before we do, load DE with zero. Returning dummy non-zero
; values can have weird consequence (such as false overflow errors).
ld ix, 0
ld de, 0
jp zasmIsFirstPass
.returnPC:
push hl
call zasmGetPC
push hl \ pop ix
ex de, hl ; result in DE
pop hl
ret