1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-24 03:28:07 +11:00

zasm: de-index symRegister

Make symRegister's logic pointer-based so we can break through the 0x100
limit.
This commit is contained in:
Virgil Dupras 2019-05-19 09:06:24 -04:00
parent c01816b055
commit 98695f9912
6 changed files with 75 additions and 54 deletions

View File

@ -26,6 +26,7 @@
; unsetZ ; unsetZ
; intoDE ; intoDE
; intoHL ; intoHL
; writeHLinDE
; findchar ; findchar
; parseHex ; parseHex
; parseHexPair ; parseHexPair

View File

@ -107,35 +107,32 @@ symIsLabelLocal:
cp (hl) cp (hl)
ret ret
; Place HL at the end of (SYM_CTX_NAMES) end (that is, at the point where we have two ; Place HL at the end of (SYM_CTX_NAMES) end (that is, at the point where we
; consecutive null chars. We return the index of that new name in A. ; have two consecutive null chars and DE at the corresponding position in
; SYM_CTX_VALUES).
; If we're within bounds, Z is set, otherwise unset. ; If we're within bounds, Z is set, otherwise unset.
symNamesEnd: symNamesEnd:
push bc push ix
push de
ld b, 0 ld ix, (SYM_CTX_VALUES)
ld hl, (SYM_CTX_NAMES) ld hl, (SYM_CTX_NAMES)
ld de, (SYM_CTX_NAMESEND) ld de, (SYM_CTX_NAMESEND)
.loop: .loop:
call _symNext call _symNext
jr nz, .success ; We've reached the end of the chain. jr nz, .success ; We've reached the end of the chain.
inc ix
inc ix
; Are we out of bounds? ; Are we out of bounds?
call cpHLDE call cpHLDE
jr nc, .outOfBounds ; HL >= DE jr c, .loop ; HL < DE
djnz .loop ; out of bounds
; exhausted djnz? out of bounds
.outOfBounds:
call unsetZ call unsetZ
jr .end jr .end
.success: .success:
; Our index is 0 - B (if B is, for example 0xfd, A is 0x3) push ix \ pop de ; our values pos goes in DE
xor a
sub b
cp a ; ensure Z cp a ; ensure Z
.end: .end:
pop de pop ix
pop bc
ret ret
; Register label in (HL) (minus the ending ":") into the symbol registry and ; Register label in (HL) (minus the ending ":") into the symbol registry and
@ -143,19 +140,16 @@ symNamesEnd:
; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and ; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and
; A is an error code (SYM_ERR_*). ; A is an error code (SYM_ERR_*).
symRegister: symRegister:
push hl push hl ; will be used during processing. it's the symbol to add
push bc push de ; will be used during processing. it's our value.
push de
; First, let's get our strlen ; First, let's get our strlen
call strlen call strlen
ld c, a ; save that strlen for later ld c, a ; save that strlen for later
ex de, hl ; symbol to add is now in DE
call symNamesEnd call symNamesEnd
jr nz, .error jr nz, .error
; A is our index. Save it
ex af, af'
; Is our new name going to make us go out of bounds? ; Is our new name going to make us go out of bounds?
push hl push hl
push de push de
@ -167,40 +161,33 @@ symRegister:
pop hl pop hl
jr nc, .error ; HL >= DE jr nc, .error ; HL >= DE
; HL point to where we want to add the string ; Success. At this point, we have:
ex de, hl ; symbol to add in HL, dest in DE ; HL -> where we want to add the string
; DE -> where the value goes
; SP -> value to register
; SP+2 -> string to register
; Let's start with the value.
push hl \ pop ix ; save HL for later
pop hl ; value to register
call writeHLinDE ; write value where it goes.
; Good! now, the string.
pop hl ; string to register
push ix \ pop de ; string destination
; Copy HL into DE until we reach null char ; Copy HL into DE until we reach null char
; C already have our strlen (minus null char). Let's prepare BC for call strcpyM
; a LDIR.
inc c ; include null char
ld b, 0
ldir ; copy C chars from HL to DE
; We need to add a second null char to indicate the end of the name ; We need to add a second null char to indicate the end of the name
; list. DE is already correctly placed. ; list. DE is already correctly placed, A is already zero
xor a
ld (de), a ld (de), a
; I'd say we're pretty good just about now. What we need to do is to ; Nothing to pop. We've already popped our stack in the lines above.
; save the value in our original DE that is just on top of the stack ret
; into the proper index in (SYM_CTX_VALUES). Our index, remember, is
; currently in A'.
ex af, af'
pop de
push de ; push it right back to avoid stack imbalance
ld hl, (SYM_CTX_VALUES)
call addHL
call addHL ; twice because our values are words
; Everything is set! DE is our value HL points to the proper index in
; (SYM_CTX_VALUES). Let's just write it (little endian).
ld (hl), e
inc hl
ld (hl), d
.error: .error:
; Z already unset ; Z already unset
pop de pop de
pop bc
pop hl pop hl
ret ret

View File

@ -117,6 +117,27 @@ strcmp:
; early, set otherwise) ; early, set otherwise)
ret ret
; Copy string from (HL) in (DE), that is, copy bytes until a null char is
; encountered. The null char is also copied.
; HL and DE point to the char right after the null char.
strcpyM:
ld a, (hl)
ld (de), a
inc hl
inc de
or a
jr nz, strcpyM
ret
; Like strcpyM, but preserve HL and DE
strcpy:
push hl
push de
call strcpyM
pop de
pop hl
ret
; If string at (HL) starts with ( and ends with ), "enter" into the parens ; 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. ; (advance HL and put a null char at the end of the string) and set Z.
; Otherwise, do nothing and reset Z. ; Otherwise, do nothing and reset Z.

View File

@ -16,6 +16,7 @@ jp upcase
jp unsetZ jp unsetZ
jp intoDE jp intoDE
jp intoHL jp intoHL
jp writeHLinDE
jp findchar jp findchar
jp parseHex jp parseHex
jp parseHexPair jp parseHexPair

View File

@ -6,15 +6,16 @@ upcase .equ 0x0c
unsetZ .equ 0x0f unsetZ .equ 0x0f
intoDE .equ 0x12 intoDE .equ 0x12
intoHL .equ 0x15 intoHL .equ 0x15
findchar .equ 0x18 writeHLinDE .equ 0x18
parseHex .equ 0x1b findchar .equ 0x1b
parseHexPair .equ 0x1e parseHex .equ 0x1e
blkSel .equ 0x21 parseHexPair .equ 0x21
fsFindFN .equ 0x24 blkSel .equ 0x24
fsOpen .equ 0x27 fsFindFN .equ 0x27
fsGetC .equ 0x2a fsOpen .equ 0x2a
fsSeek .equ 0x2d fsGetC .equ 0x2d
fsTell .equ 0x30 fsSeek .equ 0x30
fsTell .equ 0x33
.equ FS_HANDLE_SIZE 8 .equ FS_HANDLE_SIZE 8
.equ STDERR_PORT 0x04 .equ STDERR_PORT 0x04

View File

@ -34,6 +34,16 @@ test:
jp nz, fail jp nz, fail
call nexttest call nexttest
ld a, 1 ; index of FOO
call symGetVal
ld a, d
or a
jp nz, fail
ld a, e
cp 43
jp nz, fail
call nexttest
; success ; success
xor a xor a
halt halt