mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 19:38:05 +11:00
zasm: still inching toward directives
This commit is contained in:
parent
1ffe05dd09
commit
a7693ffd86
27
apps/zasm/directive.asm
Normal file
27
apps/zasm/directive.asm
Normal 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
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user