2019-12-13 02:51:13 +11:00
|
|
|
; Whether A is a separator or end-of-string (null or ':')
|
|
|
|
isSepOrEnd:
|
|
|
|
or a
|
|
|
|
ret z
|
|
|
|
cp ':'
|
|
|
|
ret z
|
|
|
|
; continue to isSep
|
|
|
|
|
|
|
|
; Sets Z is A is ' ' or '\t' (whitespace)
|
2019-11-21 12:58:26 +11:00
|
|
|
isSep:
|
|
|
|
cp ' '
|
|
|
|
ret z
|
|
|
|
cp 0x09
|
|
|
|
ret
|
|
|
|
|
2019-11-19 05:40:23 +11:00
|
|
|
; Expect at least one whitespace (0x20, 0x09) at (HL), and then advance HL
|
|
|
|
; until a non-whitespace character is met.
|
|
|
|
; HL is advanced to the first non-whitespace char.
|
|
|
|
; Sets Z on success, unset on failure.
|
|
|
|
; Failure is either not having a first whitespace or reaching the end of the
|
|
|
|
; string.
|
|
|
|
; Sets Z if we found a non-whitespace char, unset if we found the end of string.
|
2019-11-21 12:58:26 +11:00
|
|
|
rdSep:
|
2019-11-19 05:40:23 +11:00
|
|
|
ld a, (hl)
|
|
|
|
call isSep
|
|
|
|
ret nz ; failure
|
|
|
|
.loop:
|
|
|
|
inc hl
|
|
|
|
ld a, (hl)
|
|
|
|
call isSep
|
|
|
|
jr z, .loop
|
2019-12-13 02:51:13 +11:00
|
|
|
call isSepOrEnd
|
|
|
|
jp z, .fail ; unexpected EOL. fail
|
2019-11-19 05:40:23 +11:00
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
.fail:
|
|
|
|
; A is zero at this point
|
|
|
|
inc a ; unset Z
|
|
|
|
ret
|
|
|
|
|
2019-11-21 12:58:26 +11:00
|
|
|
; Advance HL to the next separator or to the end of string.
|
2019-12-13 02:51:13 +11:00
|
|
|
toSepOrEnd:
|
2019-11-20 07:14:04 +11:00
|
|
|
ld a, (hl)
|
2019-12-13 02:51:13 +11:00
|
|
|
call isSepOrEnd
|
|
|
|
ret z
|
|
|
|
inc hl
|
|
|
|
jr toSepOrEnd
|
|
|
|
|
|
|
|
; Advance HL to the end of the line, that is, either a null terminating char
|
|
|
|
; or the ':'.
|
|
|
|
; Sets Z if we met a null char, unset if we met a ':'
|
|
|
|
toEnd:
|
|
|
|
ld a, (hl)
|
|
|
|
or a
|
2019-11-20 07:14:04 +11:00
|
|
|
ret z
|
2019-12-13 02:51:13 +11:00
|
|
|
cp ':'
|
|
|
|
jr z, .havesep
|
2019-11-20 07:14:04 +11:00
|
|
|
inc hl
|
2019-12-13 04:22:38 +11:00
|
|
|
call skipQuoted
|
2019-12-13 02:51:13 +11:00
|
|
|
jr toEnd
|
|
|
|
.havesep:
|
|
|
|
inc a ; unset Z
|
|
|
|
ret
|
2019-11-21 12:58:26 +11:00
|
|
|
|
|
|
|
; Read (HL) until the next separator and copy it in (DE)
|
|
|
|
; DE is preserved, but HL is advanced to the end of the read word.
|
|
|
|
rdWord:
|
|
|
|
push af
|
|
|
|
push de
|
|
|
|
.loop:
|
|
|
|
ld a, (hl)
|
2019-12-13 02:51:13 +11:00
|
|
|
call isSepOrEnd
|
2019-11-21 12:58:26 +11:00
|
|
|
jr z, .stop
|
|
|
|
ld (de), a
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
jr .loop
|
|
|
|
.stop:
|
|
|
|
xor a
|
|
|
|
ld (de), a
|
|
|
|
pop de
|
|
|
|
pop af
|
|
|
|
ret
|
2019-11-24 08:07:10 +11:00
|
|
|
|
|
|
|
; Read word from HL in SCRATCHPAD and then intepret that word as an expression.
|
|
|
|
; Put the result in IX.
|
|
|
|
; Z for success.
|
2019-12-24 11:01:03 +11:00
|
|
|
; TODO: put result in DE
|
2019-11-24 08:07:10 +11:00
|
|
|
rdExpr:
|
|
|
|
ld de, SCRATCHPAD
|
|
|
|
call rdWord
|
|
|
|
push hl
|
|
|
|
ex de, hl
|
2019-12-24 11:13:44 +11:00
|
|
|
call parseExpr
|
2019-12-24 11:01:03 +11:00
|
|
|
push de \ pop ix
|
2019-11-24 08:07:10 +11:00
|
|
|
pop hl
|
|
|
|
ret
|