diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-05-08 14:53:21 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-05-08 14:53:21 -0400 |
commit | d284bfb53d27831c1bfa1b39a265eab748217cea (patch) | |
tree | b73e7374cd0213fd83284864445bae725f56b3bc /programs/sub-suite | |
parent | 875dff40ad71847d59c272491e516e4b1f01058c (diff) |
Add a new subroutine called get_index.
This subroutine gets the index of a given character
from a string.
This will help in replacing some routines like
get_ctrlidx, isdelm, and isdelm2.
Diffstat (limited to 'programs/sub-suite')
-rw-r--r-- | programs/sub-suite/utils.s | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/programs/sub-suite/utils.s b/programs/sub-suite/utils.s index 8f4a643..3621051 100644 --- a/programs/sub-suite/utils.s +++ b/programs/sub-suite/utils.s @@ -316,6 +316,41 @@ findramend: mov a, d ; Return the end of RAM pointer. rts ; End of findramend. +; get_index: Get the index of a given character from a string. +; Input: D = Pointer to string. S = Character to look for. F = Indexing mode. +; Output: A = Index of the character in the string, if found. +; Caller preserved registers: D, S, F. +; Callee preserved registers: B. +; +; Indexing modes: +; 0 = Increment mode. +; 1 = Boolean mode. +; 2 = Increment mode, plus one. + +get_index: + phb.q ; Preserve B. + and #0 ; Reset A. + tab ; Reset B. + cmp f, #2 ; Is the index starting at one? + leq #1 ; Set the index to one if so. + dec ; Decrement the index to account for incrementing at the start. +@loop: + inc ; Increment the index. + mov b, (d+a) ; Are we at the end of the string? + beq @is_bool ; Yes, so check if we're using boolean mode. +@@loop: + cmp s, b ; Is this character the same as the one we're looking for? + bne @loop ; No, so keep looping. +@is_bool: + and f, f ; Are we using boolean mode? + beq @end ; No, so we're done. +@bool: + cmp s, b ; Is this character the same as the one we're looking for? + set a, eq ; Set the index to true if so. +@end: + plb.q ; Restore B. + rts ; End of get_index. + print_sfast: pha.q ; Preserve A. |