diff options
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. |