zasm: make each token type parse the remaining of line directly
This commit is contained in:
parent
a7693ffd86
commit
5fd9b7812c
@ -415,14 +415,14 @@ matchArg:
|
|||||||
dec hl
|
dec hl
|
||||||
ret
|
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.
|
; match, reset if not.
|
||||||
matchPrimaryRow:
|
matchPrimaryRow:
|
||||||
push hl
|
push hl
|
||||||
push ix
|
push ix
|
||||||
ld ixh, d
|
ld ixh, d
|
||||||
ld ixl, e
|
ld ixl, e
|
||||||
ld a, (tokInstr+1)
|
ld a, (token+1)
|
||||||
cp (ix)
|
cp (ix)
|
||||||
jr nz, .end
|
jr nz, .end
|
||||||
; name matches, let's see the rest
|
; name matches, let's see the rest
|
||||||
@ -747,9 +747,23 @@ getUpcode:
|
|||||||
pop ix
|
pop ix
|
||||||
ret
|
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.
|
; Sets Z on success, reset on error.
|
||||||
processArg:
|
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
|
call parseArg
|
||||||
cp 0xff
|
cp 0xff
|
||||||
jr z, .error
|
jr z, .error
|
||||||
@ -764,22 +778,21 @@ processArg:
|
|||||||
ld a, ixh
|
ld a, ixh
|
||||||
ld (de), a
|
ld (de), a
|
||||||
cp a ; ensure Z is set
|
cp a ; ensure Z is set
|
||||||
|
pop hl
|
||||||
ret
|
ret
|
||||||
.error:
|
.error:
|
||||||
call JUMP_UNSETZ
|
call JUMP_UNSETZ
|
||||||
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse instruction specified in A (I_* const) with args in (tokArg1) and
|
; Parse instruction specified in A (I_* const) with args in (HL) and write
|
||||||
; (tokArg2) and write resulting opcode(s) in (curUpcode). Returns the number of
|
; resulting opcode(s) in (curUpcode). Returns the number of bytes written in A.
|
||||||
; bytes written in A.
|
|
||||||
parseInstruction:
|
parseInstruction:
|
||||||
push hl
|
push hl
|
||||||
push de
|
push de
|
||||||
ld hl, tokArg1
|
|
||||||
ld de, curArg1
|
ld de, curArg1
|
||||||
call processArg
|
call processArg
|
||||||
jr nz, .error
|
jr nz, .error
|
||||||
ld hl, tokArg2
|
|
||||||
ld de, curArg2
|
ld de, curArg2
|
||||||
call processArg
|
call processArg
|
||||||
jr nz, .error
|
jr nz, .error
|
||||||
|
@ -33,21 +33,17 @@ parseLine:
|
|||||||
call gotoNextNotBlankLine
|
call gotoNextNotBlankLine
|
||||||
jr nz, .error
|
jr nz, .error
|
||||||
push de
|
push de
|
||||||
ld de, tokInstr
|
ld de, token
|
||||||
call tokenize
|
call tokenize
|
||||||
ld a, (tokInstr) ; TOK_*
|
pop de
|
||||||
|
ld a, (token) ; TOK_*
|
||||||
cp TOK_BAD
|
cp TOK_BAD
|
||||||
jr z, .error
|
jr z, .error
|
||||||
ld de, tokArg1
|
|
||||||
call tokenizeInstrArg
|
|
||||||
ld de, tokArg2
|
|
||||||
call tokenizeInstrArg
|
|
||||||
pop de
|
|
||||||
cp TOK_INSTR
|
cp TOK_INSTR
|
||||||
jr z, .instr
|
jr z, .instr
|
||||||
jr .error ; directive not supported yet
|
jr .error ; directive not supported yet
|
||||||
.instr:
|
.instr:
|
||||||
ld a, (tokInstr+1) ; I_*
|
ld a, (token+1) ; I_*
|
||||||
call parseInstruction
|
call parseInstruction
|
||||||
or a ; is zero?
|
or a ; is zero?
|
||||||
jr z, .error
|
jr z, .error
|
||||||
@ -67,10 +63,8 @@ parseLine:
|
|||||||
|
|
||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
|
|
||||||
tokInstr:
|
token:
|
||||||
.fill 5
|
.fill 5
|
||||||
tokArg1:
|
|
||||||
.fill 9
|
|
||||||
tokArg2:
|
|
||||||
.fill 9
|
|
||||||
|
|
||||||
|
scratchpad:
|
||||||
|
.fill 0x20
|
||||||
|
@ -47,16 +47,6 @@ tokenize:
|
|||||||
ld (de), a
|
ld (de), a
|
||||||
ret
|
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.
|
; Sets Z is A is ';', CR, LF, or null.
|
||||||
isLineEndOrComment:
|
isLineEndOrComment:
|
||||||
cp ';'
|
cp ';'
|
||||||
|
Loading…
Reference in New Issue
Block a user