zasm: deduplicate code
This commit is contained in:
parent
746c86cbf8
commit
17dbee6a49
@ -33,6 +33,25 @@
|
|||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
|
|
||||||
|
; Advance HL to the beginning of the next symbol name in SYM_NAMES except if
|
||||||
|
; (HL) is already zero, meaning we're at the end of the chain. In this case,
|
||||||
|
; do nothing.
|
||||||
|
; Sets Z if it succeeded, unset it if there is no next.
|
||||||
|
_symNext:
|
||||||
|
xor a
|
||||||
|
cp (hl)
|
||||||
|
jr nz, .do ; (HL) is not zero? we can advance.
|
||||||
|
; (HL) is zero? we're at the end of the chain.
|
||||||
|
call JUMP_UNSETZ
|
||||||
|
ret
|
||||||
|
.do:
|
||||||
|
; A is already 0
|
||||||
|
call JUMP_FINDCHAR ; find next null char
|
||||||
|
; go to the char after it.
|
||||||
|
inc hl
|
||||||
|
cp a ; ensure Z
|
||||||
|
ret
|
||||||
|
|
||||||
; Place HL at the end of SYM_NAMES end (that is, at the point where we have two
|
; Place HL at the end of SYM_NAMES end (that is, at the point where we have two
|
||||||
; consecutive null chars. We return the index of that new name in A.
|
; consecutive null chars. We return the index of that new name in A.
|
||||||
; If we're within bounds, Z is set, otherwise unset.
|
; If we're within bounds, Z is set, otherwise unset.
|
||||||
@ -44,13 +63,8 @@ symNamesEnd:
|
|||||||
ld hl, SYM_NAMES
|
ld hl, SYM_NAMES
|
||||||
ld de, SYM_NAMES+SYM_BUFSIZE
|
ld de, SYM_NAMES+SYM_BUFSIZE
|
||||||
.loop:
|
.loop:
|
||||||
ld a, (hl)
|
call _symNext
|
||||||
or a ; cp 0
|
jr nz, .success ; We've reached the end of the chain.
|
||||||
jr z, .success ; We've reached the end, Z is set, all good
|
|
||||||
xor a
|
|
||||||
call JUMP_FINDCHAR ; find next null char
|
|
||||||
; go to the char after it.
|
|
||||||
inc hl
|
|
||||||
; Are we out of bounds?
|
; Are we out of bounds?
|
||||||
call cpHLDE
|
call cpHLDE
|
||||||
jr nc, .outOfBounds ; HL >= DE
|
jr nc, .outOfBounds ; HL >= DE
|
||||||
@ -146,17 +160,12 @@ symFind:
|
|||||||
ld b, 0
|
ld b, 0
|
||||||
ld hl, SYM_NAMES
|
ld hl, SYM_NAMES
|
||||||
.loop:
|
.loop:
|
||||||
ld a, (hl)
|
ld a, c ; recall strlen
|
||||||
or a ; cp 0
|
|
||||||
jr z, .nomatch
|
|
||||||
ld a, c
|
|
||||||
call JUMP_STRNCMP
|
call JUMP_STRNCMP
|
||||||
jr z, .match
|
jr z, .match
|
||||||
; ok, next!
|
; ok, next!
|
||||||
xor a
|
call _symNext
|
||||||
call JUMP_FINDCHAR ; find next null char
|
jr nz, .nomatch ; end of the chain, nothing found
|
||||||
; go to the char after it.
|
|
||||||
inc hl
|
|
||||||
djnz .loop
|
djnz .loop
|
||||||
; exhausted djnz? no match
|
; exhausted djnz? no match
|
||||||
.nomatch:
|
.nomatch:
|
||||||
@ -174,7 +183,6 @@ symFind:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; Return value associated with symbol index A into DE
|
; Return value associated with symbol index A into DE
|
||||||
; Sets Z on success, unset on error.
|
|
||||||
symGetVal:
|
symGetVal:
|
||||||
; our index is in A. Let's fetch the proper value
|
; our index is in A. Let's fetch the proper value
|
||||||
push hl
|
push hl
|
||||||
@ -185,5 +193,4 @@ symGetVal:
|
|||||||
inc hl
|
inc hl
|
||||||
ld d, (hl)
|
ld d, (hl)
|
||||||
pop hl
|
pop hl
|
||||||
cp a ; ensure Z
|
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user