Browse Source

zasm: still inching toward directives

pull/10/head
Virgil Dupras 5 years ago
parent
commit
a7693ffd86
4 changed files with 48 additions and 13 deletions
  1. +27
    -0
      apps/zasm/directive.asm
  2. +4
    -7
      apps/zasm/instr.asm
  3. +15
    -6
      apps/zasm/main.asm
  4. +2
    -0
      apps/zasm/tok.asm

+ 27
- 0
apps/zasm/directive.asm 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

+ 4
- 7
apps/zasm/instr.asm View File

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


+ 15
- 6
apps/zasm/main.asm View File

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


+ 2
- 0
apps/zasm/tok.asm View File

@@ -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…
Cancel
Save