mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 16:28:05 +11:00
zasm: add support for string literals in .db
This commit is contained in:
parent
b499d320de
commit
f9dac15449
@ -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
|
||||
|
@ -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.
|
||||
|
@ -6,3 +6,4 @@ ld hl, 0x4234
|
||||
ld hl, (0x4234)
|
||||
ld a, 'X'
|
||||
ld a, 'a' ; don't upcase!
|
||||
.db "bonjour"
|
||||
|
Loading…
Reference in New Issue
Block a user