]> git.sur5r.net Git - cc65/blob - libsrc/common/strpbrk.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / common / strpbrk.s
1 ;                                                   
2 ; Ullrich von Bassewitz, 11.06.1998
3 ;
4 ; char* strpbrk (const char* s1, const char* s2);
5 ;
6
7         .export         _strpbrk
8         .import         popax, return0
9         .importzp       ptr1, ptr2, tmp1, tmp2, tmp3
10
11 _strpbrk:
12         jsr     popax           ; get s2
13         sta     ptr2
14         stx     ptr2+1
15         jsr     popax           ; get s1
16         sta     ptr1
17         stx     ptr1+1
18         ldy     #$00
19
20 L1:     lda     (ptr1),y        ; get next char from s1
21         beq     L9              ; jump if done
22         sta     tmp2            ; save char
23         iny
24         bne     L2
25         inc     ptr1+1
26 L2:     sty     tmp3            ; save index into s1
27
28         ldy     #0              ; get index into s2
29 L3:     lda     (ptr2),y        ;
30         beq     L4              ; jump if done
31         cmp     tmp2
32         beq     L6
33         iny
34         bne     L3
35
36 ; The character was not found in s2. Increment the counter and start over
37
38 L4:     ldy     tmp3            ; reload index
39         inx
40         bne     L1
41         inc     tmp1
42         bne     L1
43
44 ; A character was found. Calculate a pointer to this char in s1 and return it.
45
46 L6:     ldx     ptr1+1
47         lda     tmp3            ; get y offset
48         clc
49         adc     ptr1
50         bcc     L7
51         inx
52 L7:     rts
53
54 ; None of the characters in s2 was found - return NULL
55
56 L9:     jmp     return0
57
58
59
60