diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 177a789..8ee4477 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -15,6 +15,10 @@ .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: @@ -98,7 +102,7 @@ zasmParseFile: ; resulting opcode(s) through ioPutC and increases (IO_PC) by the number of ; bytes written. BC is set to the result of the call to tokenize. ; Sets Z if parse was successful, unset if there was an error. EOF is not an -; error. +; error. If there is an error, A is set to the corresponding error code (ERR_*). parseLine: call tokenize ld a, b ; TOK_* @@ -109,9 +113,10 @@ parseLine: cp TOK_LABEL jr z, _parseLabel cp TOK_EOF - ret ; Z is correct. If EOF, Z is set and not an - ; error, otherwise, it means bad token and - ; errors out. + ret z ; We're finished, no error. + ; Bad token + ld a, ERR_UNKWN + jp unsetZ ; return with Z unset _parseInstr: ld a, c ; I_* diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index 162e76e..8194765 100644 Binary files a/tools/emul/zasm/zasm.bin and b/tools/emul/zasm/zasm.bin differ diff --git a/tools/emul/zasm/zasm.c b/tools/emul/zasm/zasm.c index 19fe986..f3bc0fb 100644 --- a/tools/emul/zasm/zasm.c +++ b/tools/emul/zasm/zasm.c @@ -188,9 +188,10 @@ int main() } #endif fflush(stdout); -#ifdef DEBUG - fprintf(stderr, "Ended with A=%d DE=%d\n", cpu.R1.br.A, cpu.R1.wr.DE); -#endif - return 0; + int res = cpu.R1.br.A; + if (res != 0) { + fprintf(stderr, "Error %d\n", res); + } + return res; } diff --git a/tools/tests/zasm/errtests.sh b/tools/tests/zasm/errtests.sh new file mode 100755 index 0000000..a9e9de9 --- /dev/null +++ b/tools/tests/zasm/errtests.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# no "set -e" because we test errors + +ZASM=../../emul/zasm/zasm + +chkerr() { + echo "Check that '$1' results in error $2" + ${ZASM} <<< $1 > /dev/null + local res=$? + if [[ $res == $2 ]]; then + echo "Good!" + else + echo "$res != $2" + exit 1 + fi +} + +chkerr "foo" 1 + diff --git a/tools/tests/zasm/runtests.sh b/tools/tests/zasm/runtests.sh index d7b82db..a97c8e2 100755 --- a/tools/tests/zasm/runtests.sh +++ b/tools/tests/zasm/runtests.sh @@ -23,7 +23,7 @@ cmpas() { fi } -for fn in *.asm; do +for fn in test*.asm; do echo "Comparing ${fn}" cmpas $fn done @@ -34,3 +34,4 @@ while read line; do cmpas ${TMPFILE} done +./errtests.sh