From 2c80924df955e92fcb1c3e9ed0890df930629cd0 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 28 May 2019 09:57:29 -0400 Subject: [PATCH] zasm: indicate include lineno in errors --- apps/zasm/io.asm | 28 ++++++++++++++++++++++++++-- apps/zasm/main.asm | 2 +- tools/emul/runbin/runbin.c | 4 ++++ tools/emul/zasm/zasm.bin | Bin 4210 -> 4241 bytes tools/emul/zasm/zasm.c | 12 +++++++++++- 5 files changed, 42 insertions(+), 4 deletions(-) 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 d0d68a3fb1d70334590891978eb8c52b64c8364a..938b7a92e58a274e861eaff28ef955f0669617da 100644 GIT binary patch delta 2094 zcmZ8iU2Gdw7M>r+No~i8leQU}Cb|Aede=$1#)6_vr73?RwqqwDW$diN!<3d??L(u5 zhbD&9k)UYy1rQnucmSkIMdAS|i@IPyB2KV^JZTS-CCo0}9TdY3tCEejhD{a)?ZCN{ zQndRp_ue_@JKs6?+;h+UhP)6I%5S_Ne15x{966*G$(`_WlJ?dD9V!fSRog?FtsqhF zs2jx<*vQFTCEl%?QBH-3?&kZauH|TR!;E@V^LoRG_Nt+f3Qs3P?Wz$Csi9sq+OA3+ zpeCi(AjgFcGZ8`zbRu)aZAM*a=s1gURVMxLdHp;ei7_xyOU5=*1~`tzhO46QSM0KCALv+ACLhqOh!xss- zmZW}rhy@haZ(G;OLK@^H5>%OYhWblM*9uvZ*yo;q_r@c?IYxBcusm3$?c)a zp0%+@xl*J@nN8QIeVhu?reoD(KTLO+RFMAV2z;otSO5()E*T)Es265a$VNp zNYaCFAx-x|L4RGK{GauYg&{txe=j8X7xnwanMW>;RY1b;)L5mwk%AA#Dz(6OV~|c% z=>a&KgL66Jslmlu&8$~TM)_LKg0FLyS+5%ru4aLdu2&6t5PH(!@^z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vvs|#`pjmrD4sehKKQVJ?VWF17;Ptky>4}Z9LK~yjJ3ZKg@}B?5@vFE!zCmmN{Fv z>YKA2)Nk8mnaAKWrB@P}(tMI#HP%5J9)=!ZFQpBR&xw23wn5@yoxeU_!y+KUiqYs{ lzfr>Yu?}jDI5GAWye4=nX~6SIxL*kmYWVN6$Wc`={tu|FM{xiE 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; }