2019-04-30 21:40:22 -04:00
|
|
|
; *** CONSTS ***
|
|
|
|
|
2019-05-01 14:07:01 -04:00
|
|
|
.equ D_DB 0x00
|
|
|
|
.equ D_DW 0x01
|
2019-05-11 22:11:05 -04:00
|
|
|
.equ D_EQU 0x02
|
2019-05-19 13:22:14 -04:00
|
|
|
.equ D_ORG 0x03
|
2019-05-20 08:20:00 -04:00
|
|
|
.equ D_FIL 0x04
|
|
|
|
.equ D_INC 0x05
|
2019-05-01 14:07:01 -04:00
|
|
|
.equ D_BAD 0xff
|
2019-04-30 21:40:22 -04:00
|
|
|
|
2019-05-11 22:11:05 -04:00
|
|
|
; *** Variables ***
|
|
|
|
.equ DIREC_SCRATCHPAD DIREC_RAMSTART
|
|
|
|
.equ DIREC_RAMEND DIREC_SCRATCHPAD+SCRATCHPAD_SIZE
|
2019-04-30 21:40:22 -04:00
|
|
|
; *** CODE ***
|
|
|
|
|
|
|
|
; 4 bytes per row, fill with zero
|
|
|
|
directiveNames:
|
|
|
|
.db ".DB", 0
|
2019-05-01 14:07:01 -04:00
|
|
|
.db ".DW", 0
|
2019-05-11 22:11:05 -04:00
|
|
|
.db ".EQU"
|
2019-05-19 13:22:14 -04:00
|
|
|
.db ".ORG"
|
2019-05-20 08:20:00 -04:00
|
|
|
.db ".FIL"
|
2019-05-16 21:15:00 -04:00
|
|
|
.db "#inc"
|
2019-04-30 21:40:22 -04:00
|
|
|
|
2019-05-01 11:26:41 -04:00
|
|
|
; This is a list of handlers corresponding to indexes in directiveNames
|
|
|
|
directiveHandlers:
|
|
|
|
.dw handleDB
|
2019-05-01 14:07:01 -04:00
|
|
|
.dw handleDW
|
2019-05-11 22:11:05 -04:00
|
|
|
.dw handleEQU
|
2019-05-19 13:22:14 -04:00
|
|
|
.dw handleORG
|
2019-05-20 08:20:00 -04:00
|
|
|
.dw handleFIL
|
2019-05-16 21:15:00 -04:00
|
|
|
.dw handleINC
|
2019-05-01 11:26:41 -04:00
|
|
|
|
|
|
|
handleDB:
|
|
|
|
push hl
|
2019-05-17 15:39:28 -04:00
|
|
|
.loop:
|
2019-05-01 11:26:41 -04:00
|
|
|
call readWord
|
2019-05-27 13:44:53 -04:00
|
|
|
jr nz, .badfmt
|
2019-05-01 11:26:41 -04:00
|
|
|
ld hl, scratchpad
|
2019-05-17 16:17:22 -04:00
|
|
|
call enterDoubleQuotes
|
|
|
|
jr z, .stringLiteral
|
2019-05-17 17:21:49 -04:00
|
|
|
call parseExpr
|
2019-05-27 13:44:53 -04:00
|
|
|
jr nz, .badarg
|
2019-05-18 20:37:34 -04:00
|
|
|
push ix \ pop hl
|
2019-05-27 13:44:53 -04:00
|
|
|
ld a, h
|
|
|
|
or a ; cp 0
|
|
|
|
jr nz, .overflow ; not zero? overflow
|
2019-05-18 20:37:34 -04:00
|
|
|
ld a, l
|
2019-05-17 15:14:38 -04:00
|
|
|
call ioPutC
|
2019-05-17 16:17:22 -04:00
|
|
|
.stopStrLit:
|
2019-05-17 15:39:28 -04:00
|
|
|
call readComma
|
|
|
|
jr z, .loop
|
2019-05-27 13:44:53 -04:00
|
|
|
cp a ; ensure Z
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
.badfmt:
|
|
|
|
ld a, ERR_BAD_FMT
|
|
|
|
jr .error
|
|
|
|
.badarg:
|
|
|
|
ld a, ERR_BAD_ARG
|
|
|
|
jr .error
|
|
|
|
.overflow:
|
|
|
|
ld a, ERR_OVFL
|
|
|
|
.error:
|
|
|
|
call unsetZ
|
2019-05-01 11:26:41 -04:00
|
|
|
pop hl
|
|
|
|
ret
|
2019-05-27 13:44:53 -04:00
|
|
|
|
2019-05-17 16:17:22 -04:00
|
|
|
.stringLiteral:
|
|
|
|
ld a, (hl)
|
|
|
|
inc hl
|
|
|
|
or a ; when we encounter 0, that was what used to
|
|
|
|
jr z, .stopStrLit ; be our closing quote. Stop.
|
|
|
|
; Normal character, output
|
|
|
|
call ioPutC
|
|
|
|
jr .stringLiteral
|
2019-05-01 11:26:41 -04:00
|
|
|
|
2019-05-01 14:07:01 -04:00
|
|
|
handleDW:
|
|
|
|
push hl
|
2019-05-17 15:39:28 -04:00
|
|
|
.loop:
|
2019-05-01 14:07:01 -04:00
|
|
|
call readWord
|
2019-05-27 13:52:58 -04:00
|
|
|
jr nz, .badfmt
|
2019-05-01 14:07:01 -04:00
|
|
|
ld hl, scratchpad
|
2019-05-14 15:26:29 -04:00
|
|
|
call parseExpr
|
2019-05-27 13:52:58 -04:00
|
|
|
jr nz, .badarg
|
2019-05-17 15:14:38 -04:00
|
|
|
push ix \ pop hl
|
|
|
|
ld a, l
|
|
|
|
call ioPutC
|
|
|
|
ld a, h
|
|
|
|
call ioPutC
|
2019-05-17 15:39:28 -04:00
|
|
|
call readComma
|
|
|
|
jr z, .loop
|
2019-05-27 13:44:53 -04:00
|
|
|
cp a ; ensure Z
|
2019-05-01 14:07:01 -04:00
|
|
|
pop hl
|
|
|
|
ret
|
2019-05-27 13:52:58 -04:00
|
|
|
.badfmt:
|
|
|
|
ld a, ERR_BAD_FMT
|
|
|
|
jr .error
|
|
|
|
.badarg:
|
|
|
|
ld a, ERR_BAD_ARG
|
|
|
|
.error:
|
|
|
|
call unsetZ
|
|
|
|
pop hl
|
|
|
|
ret
|
2019-05-01 11:26:41 -04:00
|
|
|
|
2019-05-11 22:11:05 -04:00
|
|
|
handleEQU:
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
; Read our constant name
|
|
|
|
call readWord
|
2019-05-27 14:07:07 -04:00
|
|
|
jr nz, .badfmt
|
2019-05-11 22:11:05 -04:00
|
|
|
; We can't register our symbol yet: we don't have our value!
|
|
|
|
; Let's copy it over.
|
2019-05-16 07:53:42 -04:00
|
|
|
ld de, DIREC_SCRATCHPAD
|
|
|
|
ld bc, SCRATCHPAD_SIZE
|
|
|
|
ldir
|
2019-05-11 22:11:05 -04:00
|
|
|
|
|
|
|
; Now, read the value associated to it
|
|
|
|
call readWord
|
2019-05-27 14:07:07 -04:00
|
|
|
jr nz, .badfmt
|
2019-05-11 22:11:05 -04:00
|
|
|
ld hl, scratchpad
|
2019-05-14 15:26:29 -04:00
|
|
|
call parseExpr
|
2019-05-27 14:07:07 -04:00
|
|
|
jr nz, .badarg
|
2019-05-11 22:11:05 -04:00
|
|
|
ld hl, DIREC_SCRATCHPAD
|
2019-05-18 20:37:34 -04:00
|
|
|
push ix \ pop de
|
2019-05-27 14:07:07 -04:00
|
|
|
call symRegister ; TODO: handle duplicate symbol error, OOM, etc.
|
|
|
|
cp a ; ensure Z
|
|
|
|
jr .end
|
|
|
|
.badfmt:
|
|
|
|
ld a, ERR_BAD_FMT
|
|
|
|
jr .error
|
|
|
|
.badarg:
|
|
|
|
ld a, ERR_BAD_ARG
|
|
|
|
.error:
|
|
|
|
call unsetZ
|
2019-05-11 22:11:05 -04:00
|
|
|
.end:
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2019-05-19 13:22:14 -04:00
|
|
|
handleORG:
|
|
|
|
call readWord
|
|
|
|
call parseExpr
|
|
|
|
ret nz
|
|
|
|
push ix \ pop hl
|
2019-05-27 13:44:53 -04:00
|
|
|
call zasmSetOrg
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
2019-05-19 13:22:14 -04:00
|
|
|
|
2019-05-20 08:20:00 -04:00
|
|
|
handleFIL:
|
|
|
|
call readWord
|
|
|
|
call parseExpr
|
|
|
|
ret nz
|
|
|
|
push bc
|
|
|
|
push ix \ pop bc
|
|
|
|
xor a
|
|
|
|
ld b, c
|
|
|
|
.loop:
|
|
|
|
call ioPutC
|
|
|
|
djnz .loop
|
2019-05-27 13:44:53 -04:00
|
|
|
cp a ; ensure Z
|
2019-05-20 08:20:00 -04:00
|
|
|
pop bc
|
2019-05-20 10:46:27 -04:00
|
|
|
ret
|
2019-05-20 08:20:00 -04:00
|
|
|
|
2019-05-16 21:15:00 -04:00
|
|
|
handleINC:
|
|
|
|
call readWord
|
|
|
|
jr nz, .end
|
|
|
|
; HL points to scratchpad
|
2019-05-17 16:17:22 -04:00
|
|
|
call enterDoubleQuotes
|
2019-05-16 21:15:00 -04:00
|
|
|
jr nz, .end
|
|
|
|
call ioOpenInclude
|
|
|
|
.end:
|
|
|
|
xor a ; zero bytes written
|
|
|
|
ret
|
|
|
|
|
2019-04-30 21:40:22 -04:00
|
|
|
; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if
|
|
|
|
; there's a match.
|
|
|
|
getDirectiveID:
|
|
|
|
push bc
|
|
|
|
push de
|
2019-05-16 21:15:00 -04:00
|
|
|
ld b, D_INC+1 ; D_INC is last
|
2019-04-30 21:40:22 -04:00
|
|
|
ld c, 4
|
|
|
|
ld de, directiveNames
|
|
|
|
call findStringInList
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2019-05-16 07:53:42 -04:00
|
|
|
; Parse directive specified in A (D_* const) with args in I/O and act in
|
2019-05-01 11:26:41 -04:00
|
|
|
; an appropriate manner. If the directive results in writing data at its
|
2019-05-17 15:14:38 -04:00
|
|
|
; current location, that data is directly written through ioPutC.
|
2019-05-27 13:44:53 -04:00
|
|
|
; Each directive has the same return value pattern: Z on success, not-Z on
|
|
|
|
; error, A contains the error number (ERR_*).
|
2019-04-30 21:40:22 -04:00
|
|
|
parseDirective:
|
2019-05-01 11:26:41 -04:00
|
|
|
push de
|
|
|
|
; double A to have a proper offset in directiveHandlers
|
|
|
|
add a, a
|
|
|
|
ld de, directiveHandlers
|
2019-05-17 09:50:11 -04:00
|
|
|
call addDE
|
|
|
|
call intoDE
|
2019-05-18 20:37:34 -04:00
|
|
|
push de \ pop ix
|
2019-05-01 11:26:41 -04:00
|
|
|
pop de
|
|
|
|
jp (ix)
|