diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index 8d4c8da..6c89efe 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -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 diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 23e15fe..4b3f1aa 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -121,7 +121,6 @@ _parseInstr: _parseDirec: ld a, c ; D_* call parseDirective - cp a ; ensure Z ret _parseLabel: diff --git a/tools/tests/zasm/errtests.sh b/tools/tests/zasm/errtests.sh index 028eccd..fb7f7b2 100755 --- a/tools/tests/zasm/errtests.sh +++ b/tools/tests/zasm/errtests.sh @@ -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