From a7693ffd86cc2301f66406efda15fd6c9ac5ceab Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 30 Apr 2019 21:40:22 -0400 Subject: [PATCH] zasm: still inching toward directives --- apps/zasm/directive.asm | 27 +++++++++++++++++++++++++++ apps/zasm/instr.asm | 11 ++++------- apps/zasm/main.asm | 21 +++++++++++++++------ apps/zasm/tok.asm | 2 ++ 4 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 apps/zasm/directive.asm diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm new file mode 100644 index 0000000..6baf14f --- /dev/null +++ b/apps/zasm/directive.asm @@ -0,0 +1,27 @@ +; *** CONSTS *** + +D_DB .equ 0x00 +D_BAD .equ 0xff + +; *** CODE *** + +; 4 bytes per row, fill with zero +directiveNames: + .db ".DB", 0 + +; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if +; there's a match. +getDirectiveID: + push bc + push de + ld b, 1 + ld c, 4 + ld de, directiveNames + call findStringInList + pop de + pop bc + ret + +parseDirective: + xor a + ret diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index 65c0053..6c0bb40 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -769,15 +769,12 @@ processArg: call JUMP_UNSETZ ret -; Parse tokens in (tokInstr), (tokArg1) and (tokArg2) and write resulting -; opcode(s) in (curUpcode). Returns the number of bytes written in A. -parseTokens: +; Parse instruction specified in A (I_* const) with args in (tokArg1) and +; (tokArg2) and write resulting opcode(s) in (curUpcode). Returns the number of +; bytes written in A. +parseInstruction: push hl push de - 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 8f2a980..9d74368 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -19,6 +19,11 @@ main: .stop: ret +#include "util.asm" +#include "tok.asm" +#include "instr.asm" +#include "directive.asm" + ; Parse line in (HL), write the resulting opcode(s) in (DE) and returns the ; number of written bytes in A. Advances HL where tokenization stopped and DE ; to where we should write the next upcode. @@ -26,15 +31,24 @@ parseLine: push bc call gotoNextNotBlankLine + jr nz, .error push de ld de, tokInstr call tokenize + ld a, (tokInstr) ; TOK_* + cp TOK_BAD + jr z, .error ld de, tokArg1 call tokenizeInstrArg ld de, tokArg2 call tokenizeInstrArg pop de - call parseTokens + cp TOK_INSTR + jr z, .instr + jr .error ; directive not supported yet +.instr: + ld a, (tokInstr+1) ; I_* + call parseInstruction or a ; is zero? jr z, .error ld b, 0 @@ -51,11 +65,6 @@ parseLine: pop bc ret -#include "util.asm" -#include "tok.asm" -#include "instr.asm" -#include "directive.asm" - ; *** Variables *** tokInstr: diff --git a/apps/zasm/tok.asm b/apps/zasm/tok.asm index 1dae855..0b71ddc 100644 --- a/apps/zasm/tok.asm +++ b/apps/zasm/tok.asm @@ -48,11 +48,13 @@ tokenize: 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.