diff --git a/apps/zasm/const.asm b/apps/zasm/const.asm new file mode 100644 index 0000000..3972478 --- /dev/null +++ b/apps/zasm/const.asm @@ -0,0 +1,8 @@ +; *** Errors *** +; Unknown instruction or directive +.equ ERR_UNKNOWN 0x01 + +; Bad argument: Doesn't match any constant argspec or, if an expression, +; contains references to undefined symbols. +.equ ERR_BAD_ARG 0x02 + diff --git a/apps/zasm/glue.asm b/apps/zasm/glue.asm index 47c1492..8d03714 100644 --- a/apps/zasm/glue.asm +++ b/apps/zasm/glue.asm @@ -45,6 +45,7 @@ jp zasmMain +#include "zasm/const.asm" #include "zasm/util.asm" .equ IO_RAMSTART USER_RAMSTART #include "zasm/io.asm" diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index b7a94e2..cefff68 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -766,12 +766,13 @@ processArg: cp a ; ensure Z is set ret .error: + ld a, ERR_BAD_ARG call unsetZ ret ; Parse instruction specified in A (I_* const) with args in I/O and write ; resulting opcode(s) in I/O. -; Sets Z on success. +; Sets Z on success. On error, A contains an error code (ERR_*) parseInstruction: push bc push hl @@ -786,14 +787,14 @@ parseInstruction: jr nz, .nomorearg ld de, curArg1 call processArg - jr nz, .error + jr nz, .error ; A is set to error call readComma jr nz, .nomorearg call readWord jr nz, .error ld de, curArg2 call processArg - jr nz, .error + jr nz, .error ; A is set to error .nomorearg: ; Parsing done, no error, let's move forward to instr row matching! ld de, instrTBl @@ -824,6 +825,7 @@ parseInstruction: cp a ; ensure Z jr .end .error: + ; A is set to error already call unsetZ .end: pop de diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 8ee4477..23e15fe 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -15,10 +15,6 @@ .equ ZASM_ORG ZASM_CTX_PC+2 .equ ZASM_RAMEND ZASM_ORG+2 -; *** Errors *** -; Unknown instruction or directive -.equ ERR_UNKWN 0x01 - ; Read file through blockdev ID in H and outputs its upcodes through blockdev ; ID in L. zasmMain: @@ -115,7 +111,7 @@ parseLine: cp TOK_EOF ret z ; We're finished, no error. ; Bad token - ld a, ERR_UNKWN + ld a, ERR_UNKNOWN jp unsetZ ; return with Z unset _parseInstr: diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index 8194765..dcd66d3 100644 Binary files a/tools/emul/zasm/zasm.bin and b/tools/emul/zasm/zasm.bin differ diff --git a/tools/tests/zasm/errtests.sh b/tools/tests/zasm/errtests.sh index a9e9de9..7bf15b2 100755 --- a/tools/tests/zasm/errtests.sh +++ b/tools/tests/zasm/errtests.sh @@ -17,4 +17,4 @@ chkerr() { } chkerr "foo" 1 - +chkerr "ld a, foo" 2 diff --git a/tools/tests/zasm/test7.asm b/tools/tests/zasm/test7.asm index 3894ff3..041f81b 100644 --- a/tools/tests/zasm/test7.asm +++ b/tools/tests/zasm/test7.asm @@ -21,6 +21,7 @@ .equ fsSeek 0x30 .equ fsTell 0x33 +#include "zasm/const.asm" #include "zasm/util.asm" .equ IO_RAMSTART USER_RAMSTART #include "zasm/io.asm"