From 0f2b3aca24f4e3ea6da8a0a8b0c719b5bc55e8fb Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 18 Feb 2020 15:46:55 -0500 Subject: [PATCH] zasm: allow zasm to omit its 3rd argument A bug in rdWS made zasm error out when omiting its 3rd argument. fixes #90 --- apps/lib/util.asm | 8 +++---- emul/shell/user.h | 1 - tests/unit/test_lib_util.asm | 55 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/unit/test_lib_util.asm diff --git a/apps/lib/util.asm b/apps/lib/util.asm index 0dda00f..386f990 100644 --- a/apps/lib/util.asm +++ b/apps/lib/util.asm @@ -20,10 +20,10 @@ toWS: ; Set Z if non-WS found, unset if end-of-string. rdWS: ld a, (hl) - call isWS - jr nz, .ok cp 0x01 ; if a is null, carries and unsets z ret c + call isWS + jr nz, .ok inc hl jr rdWS .ok: @@ -97,8 +97,8 @@ strlen: ld c, a cpir ; advances HL to the char after the null .found: - ; How many char do we have? We have strlen=(NEG BC)-1, since BC started - ; at 0 and decreased at each CPIR loop. In this routine, + ; How many char do we have? We have strlen=(NEG BC)-1, since BC started + ; at 0 and decreased at each CPIR loop. In this routine, ; we stay in the 8-bit realm, so C only. add hl, bc sub c diff --git a/emul/shell/user.h b/emul/shell/user.h index 47aac6d..d4a758d 100644 --- a/emul/shell/user.h +++ b/emul/shell/user.h @@ -1,4 +1,3 @@ -.equ SHELL_RAMSTART 0x4100 .equ USER_CODE 0x4200 ; in sync with glue.asm ; *** JUMP TABLE *** diff --git a/tests/unit/test_lib_util.asm b/tests/unit/test_lib_util.asm new file mode 100644 index 0000000..f1d28aa --- /dev/null +++ b/tests/unit/test_lib_util.asm @@ -0,0 +1,55 @@ +jp test + +.inc "ascii.h" +.inc "core.asm" +.equ STDIO_RAMSTART RAMSTART +.inc "stdio.asm" +.inc "common.asm" +.inc "lib/ari.asm" +.inc "lib/fmt.asm" +.inc "lib/util.asm" + +test: + ld sp, 0xffff + + call testRdWS + + ; success + xor a + halt + +testRdWS: + ld hl, .allGood + ld ix, .testGood + call testList + ld hl, .allBad + ld ix, .testBad + jp testList + +.testGood: + call rdWS + jp assertZ + +.testBad: + call rdWS + jp assertNZ + +; Strings ending with a non-WS, and thus yielding Z +.g1: + .db " X", 0 +.g2: + .db "X", 0 + +.allGood: + .dw .g1, .g2, 0 + +; Strings ending with a WS, and thus yielding NZ +.b1: + .db 0 +.b2: + .db " ", 0 + +.allBad: + .dw .b1, .b2, 0 + +RAMSTART: