zasm: add support for the ".dw" directive

This commit is contained in:
Virgil Dupras 2019-05-01 14:07:01 -04:00
parent dde5161fc1
commit 6811d98618
4 changed files with 28 additions and 3 deletions

View File

@ -1,17 +1,20 @@
; *** CONSTS *** ; *** CONSTS ***
D_DB .equ 0x00 .equ D_DB 0x00
D_BAD .equ 0xff .equ D_DW 0x01
.equ D_BAD 0xff
; *** CODE *** ; *** CODE ***
; 4 bytes per row, fill with zero ; 4 bytes per row, fill with zero
directiveNames: directiveNames:
.db ".DB", 0 .db ".DB", 0
.db ".DW", 0
; This is a list of handlers corresponding to indexes in directiveNames ; This is a list of handlers corresponding to indexes in directiveNames
directiveHandlers: directiveHandlers:
.dw handleDB .dw handleDB
.dw handleDW
handleDB: handleDB:
push de push de
@ -29,13 +32,30 @@ handleDB:
pop de pop de
ret ret
handleDW:
push de
push hl
call toWord
ld de, scratchpad
ld a, 8
call readWord
ld hl, scratchpad
call parseNumber
ld a, ixl
ld (direcData), a
ld a, ixh
ld (direcData+1), a
ld a, 2
pop hl
pop de
ret
; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if ; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if
; there's a match. ; there's a match.
getDirectiveID: getDirectiveID:
push bc push bc
push de push de
ld b, 1 ld b, D_DW+1 ; D_DW is last
ld c, 4 ld c, 4
ld de, directiveNames ld de, directiveNames
call findStringInList call findStringInList
@ -53,6 +73,7 @@ parseDirective:
add a, a add a, a
ld de, directiveHandlers ld de, directiveHandlers
call JUMP_ADDDE call JUMP_ADDDE
call JUMP_INTODE
ld ixh, d ld ixh, d
ld ixl, e ld ixl, e
pop de pop de

View File

@ -9,6 +9,7 @@ jp strncmp
jp addDE jp addDE
jp upcase jp upcase
jp unsetZ jp unsetZ
jp intoDE
init: init:
di di

View File

@ -7,3 +7,4 @@ JUMP_STRNCMP .equ 0x02
JUMP_ADDDE .equ 0x05 JUMP_ADDDE .equ 0x05
JUMP_UPCASE .equ 0x08 JUMP_UPCASE .equ 0x08
JUMP_UNSETZ .equ 0x0b JUMP_UNSETZ .equ 0x0b
JUMP_INTODE .equ 0x0e

View File

@ -3,3 +3,5 @@
inc a ; comment inc a ; comment
; comment ; comment
.db 42 .db 42
.dw 42
.dw 3742