From 1ffe05dd099f207d82492c7d4f3ee637581fab32 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 30 Apr 2019 21:27:44 -0400 Subject: [PATCH] zasm: creep in the notion of directive --- apps/zasm/instr.asm | 11 ++++++----- apps/zasm/main.asm | 1 + apps/zasm/tok.asm | 31 ++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index c8abaaf..65c0053 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -415,14 +415,14 @@ matchArg: dec hl 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. matchPrimaryRow: push hl push ix ld ixh, d ld ixl, e - ld a, (tokInstr) + ld a, (tokInstr+1) cp (ix) jr nz, .end ; name matches, let's see the rest @@ -774,9 +774,10 @@ processArg: parseTokens: push hl push de - ld a, (tokInstr) - cp TOK_BAD - jr z, .error ; for now, we treat blank lines as errors + ld a, (tokInstr) ; TOK_* + cp TOK_INSTR + jr nz, .error ; Not an instruction, error + ld a, (tokInstr+1) ; I_* ld hl, tokArg1 ld de, curArg1 call processArg diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 081eab0..8f2a980 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -54,6 +54,7 @@ parseLine: #include "util.asm" #include "tok.asm" #include "instr.asm" +#include "directive.asm" ; *** Variables *** diff --git a/apps/zasm/tok.asm b/apps/zasm/tok.asm index 00c74ff..1dae855 100644 --- a/apps/zasm/tok.asm +++ b/apps/zasm/tok.asm @@ -7,13 +7,14 @@ ; *** Consts *** TOK_INSTR .equ 0x01 +TOK_DIRECTIVE .equ 0x02 TOK_BAD .equ 0xff ; *** Code *** -; Parse line in (HL) and read the next token in (DE). For now, it only supports -; instructions. Arguments must be tokenized with the appropriate specialized -; routine. Values are null-terminated and empty if not present. All letters are -; uppercased. +; Parse line in (HL) and read the next token in (DE). The token is written on +; two bytes. The first byte is a token type (TOK_* constants) and the second +; byte is an ID specific to that token type. +; If no token matches, TOK_BAD is written to (DE) tokenize: xor a ld (de), a @@ -22,11 +23,27 @@ tokenize: call readWord ex hl, de call getInstID - ex hl, de - jr z, .match + jr z, .instr + call getDirectiveID + jr z, .direc ; no match + ex hl, de ; swap it back 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 ret