zasm: implement error conditions in .db

This commit is contained in:
Virgil Dupras 2019-05-27 13:44:53 -04:00
parent d76dd54f4b
commit f5d4321ece
3 changed files with 29 additions and 2 deletions

View File

@ -35,18 +35,37 @@ handleDB:
push hl
.loop:
call readWord
jr nz, .badfmt
ld hl, scratchpad
call enterDoubleQuotes
jr z, .stringLiteral
call parseExpr
jr nz, .badarg
push ix \ pop hl
ld a, h
or a ; cp 0
jr nz, .overflow ; not zero? overflow
ld a, l
call ioPutC
.stopStrLit:
call readComma
jr z, .loop
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
pop hl
ret
.stringLiteral:
ld a, (hl)
inc hl
@ -69,6 +88,7 @@ handleDW:
call ioPutC
call readComma
jr z, .loop
cp a ; ensure Z
pop hl
ret
@ -104,7 +124,9 @@ handleORG:
call parseExpr
ret nz
push ix \ pop hl
jp zasmSetOrg
call zasmSetOrg
cp a ; ensure Z
ret
handleFIL:
call readWord
@ -117,6 +139,7 @@ handleFIL:
.loop:
call ioPutC
djnz .loop
cp a ; ensure Z
pop bc
ret
@ -147,6 +170,8 @@ getDirectiveID:
; Parse directive specified in A (D_* const) with args in I/O and act in
; an appropriate manner. If the directive results in writing data at its
; current location, that data is directly written through ioPutC.
; Each directive has the same return value pattern: Z on success, not-Z on
; error, A contains the error number (ERR_*).
parseDirective:
push de
; double A to have a proper offset in directiveHandlers

View File

@ -121,7 +121,6 @@ _parseInstr:
_parseDirec:
ld a, c ; D_*
call parseDirective
cp a ; ensure Z
ret
_parseLabel:

View File

@ -19,6 +19,9 @@ chkerr() {
chkerr "foo" 1
chkerr "ld a, foo" 2
chkerr "ld a, hl" 2
chkerr ".db foo" 2
chkerr "ld a," 3
chkerr "ld a, 'A" 3
chkerr ".db 0x42," 3
chkerr "ld a, 0x100" 4
chkerr ".db 0x100" 4