From d284bfb53d27831c1bfa1b39a265eab748217cea Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 8 May 2021 14:53:21 -0400 Subject: 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. --- programs/sub-suite/utils.s | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'programs') 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. -- cgit v1.2.3-13-gbd6f