mirror of
https://github.com/hsoft/collapseos.git
synced 2025-04-02 09:18:40 +11:00
zasm: consolidate code
This commit is contained in:
parent
a2b5b1efab
commit
34ff0a6c2a
@ -113,41 +113,32 @@ zasmParseFile:
|
|||||||
jr .loop
|
jr .loop
|
||||||
|
|
||||||
; Parse line in (HL), write the resulting opcode(s) through ioPutC and increases
|
; Parse line in (HL), write the resulting opcode(s) through ioPutC and increases
|
||||||
; (ZASM_PC) by the number of bytes written.
|
; (ZASM_PC) by the number of bytes written. BC is set to the result of the call
|
||||||
|
; to tokenize.
|
||||||
; Sets Z if parse was successful, unset if there was an error or EOF.
|
; Sets Z if parse was successful, unset if there was an error or EOF.
|
||||||
parseLine:
|
parseLine:
|
||||||
push bc
|
|
||||||
|
|
||||||
call tokenize
|
call tokenize
|
||||||
ld a, b ; TOK_*
|
ld a, b ; TOK_*
|
||||||
cp TOK_INSTR
|
cp TOK_INSTR
|
||||||
jr z, .instr
|
jp z, _parseInstr
|
||||||
cp TOK_DIRECTIVE
|
cp TOK_DIRECTIVE
|
||||||
jr z, .direc
|
jp z, _parseDirec
|
||||||
cp TOK_LABEL
|
cp TOK_LABEL
|
||||||
jr z, .label
|
jr z, .label
|
||||||
cp TOK_EMPTY
|
cp TOK_EMPTY
|
||||||
jr .end ; Z is correct. If empty, Z is set and not an
|
ret ; Z is correct. If empty, Z is set and not an
|
||||||
; error, otherwise, it means bad token and
|
; error, otherwise, it means bad token and
|
||||||
; errors out.
|
; errors out.
|
||||||
.instr:
|
|
||||||
call _parseInstr
|
|
||||||
jr .end ; Z is correct
|
|
||||||
.direc:
|
|
||||||
call _parseDirec
|
|
||||||
jr .end ; Z is correct
|
|
||||||
.label:
|
.label:
|
||||||
push hl
|
push hl
|
||||||
call _parseLabel
|
call _parseLabel
|
||||||
pop hl
|
pop hl
|
||||||
jr nz, .end ; error out
|
ret nz ; error out
|
||||||
; We're finished here. However, because it's a label, it's possible that
|
; We're finished here. However, because it's a label, it's possible that
|
||||||
; another logical line follows directly after the label. Let's parse
|
; another logical line follows directly after the label. Let's parse
|
||||||
; this and propagate error.
|
; this and propagate error.
|
||||||
call parseLine
|
call parseLine
|
||||||
; Continue to .end, Z has proper value
|
; Z has proper value
|
||||||
.end:
|
|
||||||
pop bc
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
_parseInstr:
|
_parseInstr:
|
||||||
@ -195,8 +186,6 @@ _parseDirec:
|
|||||||
|
|
||||||
_parseLabel:
|
_parseLabel:
|
||||||
; The string in (scratchpad) is a label with its trailing ':' removed.
|
; The string in (scratchpad) is a label with its trailing ':' removed.
|
||||||
ex hl, de ; save current HL (end of label) in DE,
|
|
||||||
; we will need it later
|
|
||||||
ld hl, scratchpad
|
ld hl, scratchpad
|
||||||
call zasmIsFirstPass
|
call zasmIsFirstPass
|
||||||
jr z, .registerLabel ; When we encounter a label in the first
|
jr z, .registerLabel ; When we encounter a label in the first
|
||||||
|
Loading…
Reference in New Issue
Block a user