1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 12:18:07 +11:00

zasm: make each token type parse the remaining of line directly

This commit is contained in:
Virgil Dupras 2019-04-30 21:55:18 -04:00
parent a7693ffd86
commit 5fd9b7812c
3 changed files with 28 additions and 31 deletions

View File

@ -415,14 +415,14 @@ matchArg:
dec hl
ret
; Compare primary row at (DE) with ID at (tokInstr+1). Sets Z flag if there's a
; Compare primary row at (DE) with ID at (token+1). Sets Z flag if there's a
; match, reset if not.
matchPrimaryRow:
push hl
push ix
ld ixh, d
ld ixl, e
ld a, (tokInstr+1)
ld a, (token+1)
cp (ix)
jr nz, .end
; name matches, let's see the rest
@ -747,9 +747,23 @@ getUpcode:
pop ix
ret
; Parse tokenizes argument in (HL), parses it and place it in (DE)
; Parse next argument in string (HL) and place it in (DE)
; Sets Z on success, reset on error.
processArg:
push de
call toWord
xor a
ld de, scratchpad
ld (de), a
ld a, 8
call readWord
pop de
; Read word is in scratchpad, (DE) is back to initial value, HL is
; properly advanced. Now, let's push that HL value and replace it with
; (scratchpad) so that we can parse that arg.
push hl
ld hl, scratchpad
call parseArg
cp 0xff
jr z, .error
@ -764,22 +778,21 @@ processArg:
ld a, ixh
ld (de), a
cp a ; ensure Z is set
pop hl
ret
.error:
call JUMP_UNSETZ
pop hl
ret
; Parse instruction specified in A (I_* const) with args in (tokArg1) and
; (tokArg2) and write resulting opcode(s) in (curUpcode). Returns the number of
; bytes written in A.
; Parse instruction specified in A (I_* const) with args in (HL) and write
; resulting opcode(s) in (curUpcode). Returns the number of bytes written in A.
parseInstruction:
push hl
push de
ld hl, tokArg1
ld de, curArg1
call processArg
jr nz, .error
ld hl, tokArg2
ld de, curArg2
call processArg
jr nz, .error

View File

@ -33,21 +33,17 @@ parseLine:
call gotoNextNotBlankLine
jr nz, .error
push de
ld de, tokInstr
ld de, token
call tokenize
ld a, (tokInstr) ; TOK_*
pop de
ld a, (token) ; TOK_*
cp TOK_BAD
jr z, .error
ld de, tokArg1
call tokenizeInstrArg
ld de, tokArg2
call tokenizeInstrArg
pop de
cp TOK_INSTR
jr z, .instr
jr .error ; directive not supported yet
.instr:
ld a, (tokInstr+1) ; I_*
ld a, (token+1) ; I_*
call parseInstruction
or a ; is zero?
jr z, .error
@ -67,10 +63,8 @@ parseLine:
; *** Variables ***
tokInstr:
token:
.fill 5
tokArg1:
.fill 9
tokArg2:
.fill 9
scratchpad:
.fill 0x20

View File

@ -47,16 +47,6 @@ tokenize:
ld (de), a
ret
tokenizeInstrArg:
push af
xor a
ld (de), a
call toWord
ld a, 8
call readWord
pop af
ret
; Sets Z is A is ';', CR, LF, or null.
isLineEndOrComment:
cp ';'