zasm: still inching toward directives

This commit is contained in:
Virgil Dupras 2019-04-30 21:40:22 -04:00
parent 1ffe05dd09
commit a7693ffd86
4 changed files with 48 additions and 13 deletions

27
apps/zasm/directive.asm Normal file
View File

@ -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

View File

@ -769,15 +769,12 @@ processArg:
call JUMP_UNSETZ call JUMP_UNSETZ
ret ret
; Parse tokens in (tokInstr), (tokArg1) and (tokArg2) and write resulting ; Parse instruction specified in A (I_* const) with args in (tokArg1) and
; opcode(s) in (curUpcode). Returns the number of bytes written in A. ; (tokArg2) and write resulting opcode(s) in (curUpcode). Returns the number of
parseTokens: ; bytes written in A.
parseInstruction:
push hl push hl
push de 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 hl, tokArg1
ld de, curArg1 ld de, curArg1
call processArg call processArg

View File

@ -19,6 +19,11 @@ main:
.stop: .stop:
ret 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 ; 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 ; number of written bytes in A. Advances HL where tokenization stopped and DE
; to where we should write the next upcode. ; to where we should write the next upcode.
@ -26,15 +31,24 @@ parseLine:
push bc push bc
call gotoNextNotBlankLine call gotoNextNotBlankLine
jr nz, .error
push de push de
ld de, tokInstr ld de, tokInstr
call tokenize call tokenize
ld a, (tokInstr) ; TOK_*
cp TOK_BAD
jr z, .error
ld de, tokArg1 ld de, tokArg1
call tokenizeInstrArg call tokenizeInstrArg
ld de, tokArg2 ld de, tokArg2
call tokenizeInstrArg call tokenizeInstrArg
pop de 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? or a ; is zero?
jr z, .error jr z, .error
ld b, 0 ld b, 0
@ -51,11 +65,6 @@ parseLine:
pop bc pop bc
ret ret
#include "util.asm"
#include "tok.asm"
#include "instr.asm"
#include "directive.asm"
; *** Variables *** ; *** Variables ***
tokInstr: tokInstr:

View File

@ -48,11 +48,13 @@ tokenize:
ret ret
tokenizeInstrArg: tokenizeInstrArg:
push af
xor a xor a
ld (de), a ld (de), a
call toWord call toWord
ld a, 8 ld a, 8
call readWord call readWord
pop af
ret ret
; Sets Z is A is ';', CR, LF, or null. ; Sets Z is A is ';', CR, LF, or null.