diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index 2c3f147..7578b2d 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -30,13 +30,24 @@ handleDB: .loop: call readWord ld hl, scratchpad + call enterDoubleQuotes + jr z, .stringLiteral call parseLiteral ld a, ixl call ioPutC +.stopStrLit: call readComma jr z, .loop pop hl ret +.stringLiteral: + ld a, (hl) + inc hl + or a ; when we encounter 0, that was what used to + jr z, .stopStrLit ; be our closing quote. Stop. + ; Normal character, output + call ioPutC + jr .stringLiteral handleDW: push hl @@ -96,23 +107,8 @@ handleINC: call readWord jr nz, .end ; HL points to scratchpad - ; First, let's verify that our string is enquoted - ld a, (hl) - cp '"' + call enterDoubleQuotes jr nz, .end - ; We have opening quote - inc hl - xor a - call findchar ; go to end of string - dec hl - ld a, (hl) - cp '"' - jr nz, .end - ; we have ending quote, let's replace with null char - xor a - ld (hl), a - ; Good, let's go back - ld hl, scratchpad+1 ; +1 because of the opening quote call ioOpenInclude .end: xor a ; zero bytes written diff --git a/apps/zasm/util_z.asm b/apps/zasm/util_z.asm index bc98d33..c76d45c 100644 --- a/apps/zasm/util_z.asm +++ b/apps/zasm/util_z.asm @@ -149,6 +149,39 @@ enterParens: call unsetZ ret +; Scans (HL) and sets Z according to whether the string is double quoted, that +; is, starts with a " and ends with a ". If it is double quoted, "enter" them, +; that is, advance HL by one and transform the ending quote into a null char. +; If the string isn't double-enquoted, HL isn't changed. +enterDoubleQuotes: + ld a, (hl) + cp '"' + ret nz + push hl + inc hl + ld a, (hl) + or a ; already end of string? + jr z, .nomatch + xor a + call findchar ; go to end of string + dec hl + ld a, (hl) + cp '"' + jr nz, .nomatch + ; We have a match, replace ending quote with null char + xor a + ld (hl), a + ; Good, let's go back + pop hl + ; ... but one char further + inc hl + cp a ; ensure Z + ret +.nomatch: + call unsetZ + pop hl + ret + ; 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. diff --git a/tools/tests/zasm/test4.asm b/tools/tests/zasm/test4.asm index b04228f..8b1b5d7 100644 --- a/tools/tests/zasm/test4.asm +++ b/tools/tests/zasm/test4.asm @@ -6,3 +6,4 @@ ld hl, 0x4234 ld hl, (0x4234) ld a, 'X' ld a, 'a' ; don't upcase! +.db "bonjour"