zasm: remove the "token" variable

This commit is contained in:
Virgil Dupras 2019-04-30 22:27:11 -04:00
parent 5fd9b7812c
commit a00bc8cc4b
3 changed files with 27 additions and 36 deletions

View File

@ -415,14 +415,12 @@ matchArg:
dec hl dec hl
ret ret
; Compare primary row at (DE) with ID at (token+1). Sets Z flag if there's a ; Compare primary row at (DE) with ID in A. Sets Z flag if there's a match.
; 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, (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
@ -778,18 +776,22 @@ 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 jr .end
ret
.error: .error:
call JUMP_UNSETZ call JUMP_UNSETZ
.end:
pop hl pop hl
ret ret
; Parse instruction specified in A (I_* const) with args in (HL) and write ; 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. ; resulting opcode(s) in (curUpcode). Returns the number of bytes written in A.
parseInstruction: parseInstruction:
push bc
push hl push hl
push de push de
; 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
ld de, curArg1 ld de, curArg1
call processArg call processArg
jr nz, .error jr nz, .error
@ -800,7 +802,7 @@ parseInstruction:
ld de, instrTBl ld de, instrTBl
ld b, INSTR_TBL_CNT ld b, INSTR_TBL_CNT
.loop: .loop:
ld a, (de) ld a, c ; recall A param
call matchPrimaryRow call matchPrimaryRow
jr z, .match jr z, .match
ld a, INSTR_TBL_ROWSIZE ld a, INSTR_TBL_ROWSIZE
@ -819,6 +821,7 @@ parseInstruction:
.end: .end:
pop de pop de
pop hl pop hl
pop bc
ret ret

View File

@ -32,18 +32,15 @@ parseLine:
call gotoNextNotBlankLine call gotoNextNotBlankLine
jr nz, .error jr nz, .error
push de
ld de, token
call tokenize call tokenize
pop de ld a, b ; TOK_*
ld a, (token) ; TOK_*
cp TOK_BAD cp TOK_BAD
jr z, .error jr z, .error
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, (token+1) ; I_* ld a, c ; I_*
call parseInstruction call parseInstruction
or a ; is zero? or a ; is zero?
jr z, .error jr z, .error
@ -62,9 +59,5 @@ parseLine:
ret ret
; *** Variables *** ; *** Variables ***
token:
.fill 5
scratchpad: scratchpad:
.fill 0x20 .fill 0x20

View File

@ -11,40 +11,35 @@ TOK_DIRECTIVE .equ 0x02
TOK_BAD .equ 0xff TOK_BAD .equ 0xff
; *** Code *** ; *** Code ***
; Parse line in (HL) and read the next token in (DE). The token is written on ; Parse line in (HL) and read the next token in BC. The token is written on
; two bytes. The first byte is a token type (TOK_* constants) and the second ; two bytes (B and C). B is a token type (TOK_* constants) and C is an ID
; byte is an ID specific to that token type. ; specific to that token type.
; If no token matches, TOK_BAD is written to (DE) ; Advance HL to after the read word.
; If no token matches, TOK_BAD is written to B
tokenize: tokenize:
xor a push de
ld (de), a
call toWord call toWord
ld a, 4 ld a, 4
ld de, scratchpad
call readWord call readWord
ex hl, de push hl ; Save advanced HL for later
ld hl, scratchpad
call getInstID call getInstID
jr z, .instr jr z, .instr
call getDirectiveID call getDirectiveID
jr z, .direc jr z, .direc
; no match ; no match
ex hl, de ; swap it back ld b, TOK_BAD
ld a, TOK_BAD jr .end
ld (de), a
ret
.instr: .instr:
ex af, af' ld b, TOK_INSTR
ld a, TOK_INSTR
jr .end jr .end
.direc: .direc:
ex af, af' ld b, TOK_DIRECTIVE
ld a, TOK_DIRECTIVE
jr .end
.end: .end:
ex hl, de ; swap it back ld c, a
ld (de), a pop hl
ex af, af' pop de
inc de
ld (de), a
ret ret
; Sets Z is A is ';', CR, LF, or null. ; Sets Z is A is ';', CR, LF, or null.