mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 00:18:05 +11:00
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:
parent
981c93bfd4
commit
15628da7de
@ -98,12 +98,9 @@ parseLiteralOrVar:
|
|||||||
push hl ; --> lvl 1
|
push hl ; --> lvl 1
|
||||||
ld hl, VAR_TBL
|
ld hl, VAR_TBL
|
||||||
call addHL
|
call addHL
|
||||||
push de ; --> lvl 2
|
|
||||||
ld e, (hl)
|
ld e, (hl)
|
||||||
inc hl
|
inc hl
|
||||||
ld d, (hl)
|
ld d, (hl)
|
||||||
push de \ pop ix
|
|
||||||
pop de ; <-- lvl 2
|
|
||||||
pop hl ; <-- lvl 1
|
pop hl ; <-- lvl 1
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
;
|
;
|
||||||
; EXPR_PARSE: routine to call to parse literals or symbols that are part of
|
; EXPR_PARSE: routine to call to parse literals or symbols that are part of
|
||||||
; the expression. Routine's signature:
|
; 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 ***
|
; *** Code ***
|
||||||
;
|
;
|
||||||
@ -258,7 +258,6 @@ _parseNumber:
|
|||||||
ret
|
ret
|
||||||
.skip1:
|
.skip1:
|
||||||
; End of special case 1
|
; End of special case 1
|
||||||
push ix
|
|
||||||
; Copy beginning of string to DE, we'll need it later
|
; Copy beginning of string to DE, we'll need it later
|
||||||
ld d, h
|
ld d, h
|
||||||
ld e, l
|
ld e, l
|
||||||
@ -288,19 +287,16 @@ _parseNumber:
|
|||||||
xor a
|
xor a
|
||||||
ld (hl), a
|
ld (hl), a
|
||||||
ex de, hl ; rewind to beginning of number
|
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)
|
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 hl ; <-- lvl 2, end of string
|
||||||
pop af ; <-- lvl 1, saved op
|
pop af ; <-- lvl 1, saved op
|
||||||
ld (hl), a
|
ld (hl), a
|
||||||
ex af, af' ; restore Z from EXPR_PARSE
|
ex af, af' ; restore Z from EXPR_PARSE
|
||||||
jr nz, .end
|
ret nz
|
||||||
; HL is currently at the end of the number's string
|
; HL is currently at the end of the number's string
|
||||||
; On success, have A be the operator char following the number
|
; On success, have A be the operator char following the number
|
||||||
ex af, af'
|
ex af, af'
|
||||||
.end:
|
|
||||||
pop ix
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Sets Z if A contains a valid operator char or a null char.
|
; Sets Z if A contains a valid operator char or a null char.
|
||||||
|
@ -67,7 +67,7 @@ parseHexPair:
|
|||||||
; add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
; add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
||||||
; sub 0xff-9 ; maps to 0-9 and carries if not a digit
|
; 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.
|
; same conditions as parseLiteral.
|
||||||
; Sets Z on success, unset on error.
|
; Sets Z on success, unset on error.
|
||||||
; To parse successfully, all characters following HL must be digits and those
|
; To parse successfully, all characters following HL must be digits and those
|
||||||
@ -76,7 +76,7 @@ parseHexPair:
|
|||||||
; digit in the string.
|
; digit in the string.
|
||||||
|
|
||||||
parseDecimal:
|
parseDecimal:
|
||||||
push hl
|
push hl ; --> lvl 1
|
||||||
|
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
||||||
@ -129,23 +129,23 @@ parseDecimal:
|
|||||||
; to 0x00+(0xff-'9')-(0xff-9)=-0x30=0xd0
|
; to 0x00+(0xff-'9')-(0xff-9)=-0x30=0xd0
|
||||||
sub 0xd0 ; if a is null, set Z
|
sub 0xd0 ; if a is null, set Z
|
||||||
; a is checked for null before any errors
|
; a is checked for null before any errors
|
||||||
push hl \ pop ix
|
push hl ; --> lvl 2, result
|
||||||
exx ; restore original de and bc
|
exx ; restore original bc
|
||||||
pop hl
|
pop de ; <-- lvl 2, result
|
||||||
|
pop hl ; <-- lvl 1, orig
|
||||||
ret z
|
ret z
|
||||||
; A is not 0? Ok, but if it's a space, we're happy too.
|
; A is not 0? Ok, but if it's a space, we're happy too.
|
||||||
jp isWS
|
jp isWS
|
||||||
.error:
|
.error:
|
||||||
pop hl
|
pop hl ; <-- lvl 1, orig
|
||||||
jp unsetZ
|
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.
|
; same conditions as parseLiteral.
|
||||||
parseHexadecimal:
|
parseHexadecimal:
|
||||||
call hasHexPrefix
|
call hasHexPrefix
|
||||||
ret nz
|
ret nz
|
||||||
push hl
|
push hl
|
||||||
push de
|
|
||||||
ld d, 0
|
ld d, 0
|
||||||
inc hl ; get rid of "0x"
|
inc hl ; get rid of "0x"
|
||||||
inc hl
|
inc hl
|
||||||
@ -179,8 +179,6 @@ parseHexadecimal:
|
|||||||
.error:
|
.error:
|
||||||
call unsetZ
|
call unsetZ
|
||||||
.end:
|
.end:
|
||||||
push de \ pop ix
|
|
||||||
pop de
|
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -196,15 +194,14 @@ hasHexPrefix:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse string at (HL) as a binary value (0b010101) and return value in IX.
|
; Parse string at (HL) as a binary value (0b010101) and return value in E.
|
||||||
; High IX byte is always clear.
|
; D is always zero.
|
||||||
; Sets Z on success.
|
; Sets Z on success.
|
||||||
parseBinaryLiteral:
|
parseBinaryLiteral:
|
||||||
call hasBinPrefix
|
call hasBinPrefix
|
||||||
ret nz
|
ret nz
|
||||||
push bc
|
push bc
|
||||||
push hl
|
push hl
|
||||||
push de
|
|
||||||
ld d, 0
|
ld d, 0
|
||||||
inc hl ; get rid of "0b"
|
inc hl ; get rid of "0b"
|
||||||
inc hl
|
inc hl
|
||||||
@ -236,8 +233,6 @@ parseBinaryLiteral:
|
|||||||
.error:
|
.error:
|
||||||
call unsetZ
|
call unsetZ
|
||||||
.end:
|
.end:
|
||||||
push de \ pop ix
|
|
||||||
pop de
|
|
||||||
pop hl
|
pop hl
|
||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
@ -255,7 +250,7 @@ hasBinPrefix:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse string at (HL) and, if it is a char literal, sets Z and return
|
; 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
|
; 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
|
; middle. No escape sequence are accepted, but ''' will return the apostrophe
|
||||||
@ -266,7 +261,6 @@ parseCharLiteral:
|
|||||||
ret nz
|
ret nz
|
||||||
|
|
||||||
push hl
|
push hl
|
||||||
push de
|
|
||||||
inc hl
|
inc hl
|
||||||
inc hl
|
inc hl
|
||||||
cp (hl)
|
cp (hl)
|
||||||
@ -283,12 +277,10 @@ parseCharLiteral:
|
|||||||
ld e, a
|
ld e, a
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
.end:
|
.end:
|
||||||
push de \ pop ix
|
|
||||||
pop de
|
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
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
|
; can be a decimal literal (1234), a hexadecimal literal (0x1234) or a char
|
||||||
; literal ('X').
|
; literal ('X').
|
||||||
;
|
;
|
||||||
|
@ -657,7 +657,6 @@ _readDouble:
|
|||||||
_readk7:
|
_readk7:
|
||||||
push hl
|
push hl
|
||||||
push de
|
push de
|
||||||
push ix
|
|
||||||
call parseExpr
|
call parseExpr
|
||||||
jr nz, .end
|
jr nz, .end
|
||||||
; If we're in first pass, stop now. The value of HL doesn't matter and
|
; If we're in first pass, stop now. The value of HL doesn't matter and
|
||||||
@ -686,7 +685,6 @@ _readk7:
|
|||||||
ld a, l
|
ld a, l
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
.end:
|
.end:
|
||||||
pop ix
|
|
||||||
pop de
|
pop de
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
@ -707,7 +705,6 @@ _readR4:
|
|||||||
; Set Z for success.
|
; Set Z for success.
|
||||||
_readR5:
|
_readR5:
|
||||||
push de
|
push de
|
||||||
push ix
|
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
call upcase
|
call upcase
|
||||||
cp 'R'
|
cp 'R'
|
||||||
@ -715,11 +712,9 @@ _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 _DE2A
|
call _DE2A
|
||||||
.end:
|
.end:
|
||||||
pop ix
|
|
||||||
pop de
|
pop de
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
; Parse string in (HL) and return its numerical value whether its a number
|
; 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.
|
; Sets Z if number or symbol is valid, unset otherwise.
|
||||||
parseNumberOrSymbol:
|
parseNumberOrSymbol:
|
||||||
call parseLiteral
|
call parseLiteral
|
||||||
@ -14,31 +14,25 @@ parseNumberOrSymbol:
|
|||||||
cp '@'
|
cp '@'
|
||||||
jr nz, .symbol
|
jr nz, .symbol
|
||||||
; last val
|
; last val
|
||||||
ld ix, (DIREC_LASTVAL)
|
ld de, (DIREC_LASTVAL)
|
||||||
ret
|
ret
|
||||||
.symbol:
|
.symbol:
|
||||||
push de ; --> lvl 1
|
|
||||||
call symFindVal ; --> DE
|
call symFindVal ; --> DE
|
||||||
jr nz, .notfound
|
jr nz, .notfound
|
||||||
; value in DE. We need it in IX
|
|
||||||
push de \ pop ix
|
|
||||||
pop de ; <-- lvl 1
|
|
||||||
cp a ; ensure Z
|
|
||||||
ret
|
ret
|
||||||
.notfound:
|
.notfound:
|
||||||
pop de ; <-- lvl 1
|
|
||||||
; If not found, check if we're in first pass. If we are, it doesn't
|
; 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.
|
; matter that we didn't find our symbol. Return success anyhow.
|
||||||
; Otherwise return error. Z is already unset, so in fact, this is the
|
; Otherwise return error. Z is already unset, so in fact, this is the
|
||||||
; same as jumping to zasmIsFirstPass
|
; 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).
|
; values can have weird consequence (such as false overflow errors).
|
||||||
ld ix, 0
|
ld de, 0
|
||||||
jp zasmIsFirstPass
|
jp zasmIsFirstPass
|
||||||
|
|
||||||
.returnPC:
|
.returnPC:
|
||||||
push hl
|
push hl
|
||||||
call zasmGetPC
|
call zasmGetPC
|
||||||
push hl \ pop ix
|
ex de, hl ; result in DE
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user