zasm: creep in the notion of directive

This commit is contained in:
Virgil Dupras 2019-04-30 21:27:44 -04:00
parent 8241298c8f
commit 1ffe05dd09
3 changed files with 31 additions and 12 deletions

View File

@ -415,14 +415,14 @@ matchArg:
dec hl dec hl
ret ret
; Compare primary row at (DE) with ID at (tokInstr). Sets Z flag if there's a ; Compare primary row at (DE) with ID at (tokInstr+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) ld a, (tokInstr+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
@ -774,9 +774,10 @@ processArg:
parseTokens: parseTokens:
push hl push hl
push de push de
ld a, (tokInstr) ld a, (tokInstr) ; TOK_*
cp TOK_BAD cp TOK_INSTR
jr z, .error ; for now, we treat blank lines as errors jr nz, .error ; Not an instruction, error
ld a, (tokInstr+1) ; I_*
ld hl, tokArg1 ld hl, tokArg1
ld de, curArg1 ld de, curArg1
call processArg call processArg

View File

@ -54,6 +54,7 @@ parseLine:
#include "util.asm" #include "util.asm"
#include "tok.asm" #include "tok.asm"
#include "instr.asm" #include "instr.asm"
#include "directive.asm"
; *** Variables *** ; *** Variables ***

View File

@ -7,13 +7,14 @@
; *** Consts *** ; *** Consts ***
TOK_INSTR .equ 0x01 TOK_INSTR .equ 0x01
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). For now, it only supports ; Parse line in (HL) and read the next token in (DE). The token is written on
; instructions. Arguments must be tokenized with the appropriate specialized ; two bytes. The first byte is a token type (TOK_* constants) and the second
; routine. Values are null-terminated and empty if not present. All letters are ; byte is an ID specific to that token type.
; uppercased. ; If no token matches, TOK_BAD is written to (DE)
tokenize: tokenize:
xor a xor a
ld (de), a ld (de), a
@ -22,11 +23,27 @@ tokenize:
call readWord call readWord
ex hl, de ex hl, de
call getInstID call getInstID
ex hl, de jr z, .instr
jr z, .match call getDirectiveID
jr z, .direc
; no match ; no match
ex hl, de ; swap it back
ld a, TOK_BAD ld a, TOK_BAD
.match: ld (de), a
ret
.instr:
ex af, af'
ld a, TOK_INSTR
jr .end
.direc:
ex af, af'
ld a, TOK_DIRECTIVE
jr .end
.end:
ex hl, de ; swap it back
ld (de), a
ex af, af'
inc de
ld (de), a ld (de), a
ret ret