diff --git a/apps/zasm/io.asm b/apps/zasm/io.asm index 3fa0da0..126f9db 100644 --- a/apps/zasm/io.asm +++ b/apps/zasm/io.asm @@ -58,8 +58,10 @@ .equ IO_PC IO_IN_INCLUDE+1 ; Current lineno in top-level file .equ IO_LINENO IO_PC+2 +; Current lineno in include file +.equ IO_INC_LINENO IO_LINENO+2 ; Line number (can be top-level or include) when ioSavePos was last called. -.equ IO_SAVED_LINENO IO_LINENO+2 +.equ IO_SAVED_LINENO IO_INC_LINENO+2 .equ IO_RAMEND IO_SAVED_LINENO+2 ; *** Code *** @@ -81,6 +83,17 @@ ioGetC: ld de, IO_INCLUDE_HDL call fsGetC pop de + cp 0x0a ; newline + jr nz, .notNewline + ; We have newline. Increase lineno and return (the rest of the + ; processing below isn't needed. + push hl + ld hl, IO_INC_LINENO + inc (hl) + pop hl + ret + +.notNewline: or a ; cp 0 ret nz ; not zero, all good ; We reached EOF. What we do depends on whether we're in Local Pass @@ -212,10 +225,21 @@ ioOpenInclude: call fsOpen ld a, 1 ld (IO_IN_INCLUDE), a + ld hl, 0 + ld (IO_INC_LINENO), hl cp a ; ensure Z ret -; Return current lineno in HL +; Return current lineno in HL and, if in an include, its lineno in DE. +; If not in an include, DE is set to 0 ioLineNo: + push af ld hl, (IO_LINENO) + ld de, 0 + call ioInInclude + jr z, .end + ld de, (IO_INC_LINENO) +.end: + pop af ret + diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 02f2763..38437fd 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -45,7 +45,7 @@ zasmMain: ld (ZASM_FIRST_PASS), a call zasmParseFile .end: - jp ioLineNo ; --> HL, returns + jp ioLineNo ; --> HL, --> DE, returns ; Sets Z according to whether we're in first pass. zasmIsFirstPass: diff --git a/tools/emul/runbin/runbin.c b/tools/emul/runbin/runbin.c index a8e6a34..c3d5947 100644 --- a/tools/emul/runbin/runbin.c +++ b/tools/emul/runbin/runbin.c @@ -42,6 +42,10 @@ int main() i++; c = getchar(); } + if (!i) { + fprintf(stderr, "No input, aborting\n"); + return 1; + } Z80RESET(&cpu); cpu.ioRead = io_read; cpu.ioWrite = io_write; diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index d0d68a3..938b7a9 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 10508f0..e470bf8 100644 --- a/tools/emul/zasm/zasm.c +++ b/tools/emul/zasm/zasm.c @@ -191,7 +191,17 @@ int main() int res = cpu.R1.br.A; if (res != 0) { int lineno = cpu.R1.wr.HL; - fprintf(stderr, "Error %d on line %d\n", res, lineno); + int inclineno = cpu.R1.wr.DE; + if (inclineno) { + fprintf( + stderr, + "Error %d on line %d, include line %d\n", + res, + lineno, + inclineno); + } else { + fprintf(stderr, "Error %d on line %d\n", res, lineno); + } } return res; }