zasm: improve comma processing

We don't treat "," exactly as a whitespace anymore. We have specific
processing for it.
This commit is contained in:
Virgil Dupras 2019-05-17 14:34:38 -04:00
parent 4c37d869f4
commit 6547e83f20
2 changed files with 23 additions and 13 deletions

View File

@ -710,15 +710,9 @@ getUpcode:
pop ix
ret
; Parse next argument in I/O and place it in (DE)
; Parse argument in (HL) and place it in (DE)
; Sets Z on success, reset on error.
processArg:
call readWord
jr nz, .noarg
; Read word is in (HL). Now, let's push
; that HL value and replace it with (scratchpad) so that we can parse
; that arg.
call parseArg
cp 0xff
jr z, .error
@ -737,10 +731,6 @@ processArg:
.error:
call unsetZ
ret
.noarg:
xor a
ld (de), a
ret
; Parse instruction specified in A (I_* const) with args in I/O and write
; resulting opcode(s) in (instrUpcode). Returns the number of bytes written in
@ -752,12 +742,22 @@ parseInstruction:
; A is reused in matchPrimaryRow but that register is way too changing.
; Let's keep a copy in a more cosy register.
ld c, a
xor a
ld (curArg1), a
ld (curArg2), a
call readWord
jr nz, .nomorearg
ld de, curArg1
call processArg
jr nz, .error
call readComma
jr nz, .nomorearg
call readWord
jr nz, .error
ld de, curArg2
call processArg
jr nz, .error
.nomorearg:
; Parsing done, no error, let's move forward to instr row matching!
ld de, instrTBl
ld b, INSTR_TBL_CNT

View File

@ -34,8 +34,6 @@ isSep:
cp ' '
ret z
cp 0x09
ret z
cp ','
ret
; Sets Z is A is ' ', ',', ';', CR, LF, or null.
@ -100,6 +98,8 @@ readWord:
call ioGetC
call isSepOrLineEnd
jr z, .success
cp ','
jr z, .success
djnz .loop2
; out of space. error.
.error:
@ -118,6 +118,16 @@ readWord:
pop bc
ret
; Reads the next char in I/O. If it's a comma, Set Z and return. If it's not,
; Put the read char back in I/O and unset Z.
readComma:
call ioGetC
cp ','
ret z
call ioPutBack
call unsetZ
ret
; Read ioGetC until we reach the beginning of next line, skipping comments if
; necessary. This skips all whitespace, \n, \r, comments until we reach the
; first non-comment character. Then, we put it back (ioPutBack) and return.