From 67803f6cb5c013fca15d409e540cd83f4e84e547 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 14 May 2019 15:42:15 -0400 Subject: [PATCH] zasm: don't upcase char literals --- apps/zasm/instr.asm | 2 +- apps/zasm/tests/test4.asm | 1 + apps/zasm/tok.asm | 1 - apps/zasm/util.asm | 41 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index 0f60f65..0ffd33d 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -143,7 +143,7 @@ parseArg: ld b, ARGSPEC_TBL_CNT .loop1: ld a, 4 - call JUMP_STRNCMP + call strncmpI jr z, .found ; got it! ld a, 5 call JUMP_ADDDE diff --git a/apps/zasm/tests/test4.asm b/apps/zasm/tests/test4.asm index c1dcf45..b04228f 100644 --- a/apps/zasm/tests/test4.asm +++ b/apps/zasm/tests/test4.asm @@ -5,3 +5,4 @@ ld a, 0x42 ld hl, 0x4234 ld hl, (0x4234) ld a, 'X' +ld a, 'a' ; don't upcase! diff --git a/apps/zasm/tok.asm b/apps/zasm/tok.asm index 02e15c8..76f06bd 100644 --- a/apps/zasm/tok.asm +++ b/apps/zasm/tok.asm @@ -75,7 +75,6 @@ readWord: ld a, (hl) call isSepOrLineEnd jr z, .success - call JUMP_UPCASE ld (de), a inc hl inc de diff --git a/apps/zasm/util.asm b/apps/zasm/util.asm index 74a9938..1366985 100644 --- a/apps/zasm/util.asm +++ b/apps/zasm/util.asm @@ -55,6 +55,42 @@ strlen: pop bc ret +; Compares strings pointed to by HL and DE up to A count of characters in a +; case-insensitive manner. +; If equal, Z is set. If not equal, Z is reset. +strncmpI: + push bc + push hl + push de + + ld b, a +.loop: + ld a, (de) + call JUMP_UPCASE + ld c, a + ld a, (hl) + call JUMP_UPCASE + cp c + jr nz, .end ; not equal? break early. NZ is carried out + ; to the called + or a ; cp 0. If our chars are null, stop the cmp + jr z, .end ; The positive result will be carried to the + ; caller + inc hl + inc de + djnz .loop + ; Success + ; We went through all chars with success. Ensure Z + cp a +.end: + pop de + pop hl + pop bc + ; Because we don't call anything else than CP that modify the Z flag, + ; our Z value will be that of the last cp (reset if we broke the loop + ; early, set otherwise) + ret + ; If string at (HL) starts with ( and ends with ), "enter" into the parens ; (advance HL and put a null char at the end of the string) and set Z. ; Otherwise, do nothing and reset Z. @@ -87,14 +123,15 @@ enterParens: call JUMP_UNSETZ ret -; Find string (HL) in string list (DE) of size B. Each string is C bytes wide. +; Find string (HL) in string list (DE) of size B, in a case-insensitive manner. +; Each string is C bytes wide. ; Returns the index of the found string. Sets Z if found, unsets Z if not found. findStringInList: push de push bc .loop: ld a, c - call JUMP_STRNCMP + call strncmpI ld a, c call JUMP_ADDDE jr z, .match