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

View File

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

View File

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