]> git.sur5r.net Git - cc65/blob - libsrc/common/strpbrk.s
Added a C header that translates from the source file's encoding to PetSCII.
[cc65] / libsrc / common / strpbrk.s
1 ;
2 ; 1998-06-11, Ullrich von Bassewitz
3 ; 2018-05-29, Greg King
4 ;
5 ; char* __fastcall__ strpbrk (const char* str, const char* set);
6 ;
7
8         .export         _strpbrk
9
10         .import         popax
11         .importzp       ptr1, ptr2, tmp2, tmp3
12
13 _strpbrk:
14         sta     ptr2            ; store set
15         stx     ptr2+1
16         jsr     popax
17         stx     ptr1+1          ; store str's high byte
18         ldx     #<$0000
19         stx     ptr1
20         tay                     ; use str's low byte as index
21
22 L1:     lda     (ptr1),y        ; get next char from str
23         beq     L9              ; jump if done
24         sta     tmp2            ; save char
25         sty     tmp3            ; save index into str
26
27         ldy     #$00
28 L3:     lda     (ptr2),y        ; look at each char in set
29         beq     L4              ; jump if done
30         cmp     tmp2
31         beq     L6              ; break out of loops if something found
32         iny
33         bne     L3
34
35 ; The character was not found in set. Increment the counter; and start over.
36
37 L4:     ldy     tmp3            ; reload index
38         iny
39         bne     L1
40         inc     ptr1+1
41         bne     L1              ; branch always
42
43 ; A character was found. Return its str pointer.
44
45 L6:     ldx     ptr1+1
46         lda     tmp3            ; get .Y offset
47         rts
48
49 ; None of the characters in set was found -- return NULL.
50
51 L9:     ;ldx     #>$0000        ; (set by prolog)
52         ;lda     #<$0000        ; (set by '\0' at end of str)
53         rts