]> git.sur5r.net Git - cc65/blob - libsrc/common/strspn.s
Removed bit opcode, not needed anymore.
[cc65] / libsrc / common / strspn.s
1 ;
2 ; Ullrich von Bassewitz, 11.06.1998
3 ; Christian Krueger: 08-Aug-2013, optimization
4 ;
5 ; size_t strspn (const char* s1, const char* s2);
6 ;
7
8         .export         _strspn
9         .import         popax, _strlen
10         .importzp       ptr1, ptr2, tmp1, tmp2
11
12 _strspn:
13         jsr _strlen         ; get length in a/x and transfer s2 to ptr1
14                             ; Note: It does not make sense to
15                             ; have more than 255 test chars, so
16                             ; we don't support a high byte here! (ptr1+1 is
17                             ; also unchanged in strlen then (important!))
18                             ; -> the original implementation also
19                             ; ignored this case
20
21         sta tmp1            ; tmp1 = strlen of test chars
22         jsr popax           ; get and save s1
23         sta ptr2            ; to ptr2
24         stx ptr2+1
25         ldx #0              ; low counter byte
26         stx tmp2            ; high counter byte
27
28 loadChar:
29         ldy #0
30         lda (ptr2),y        ; get next char from s1
31         beq leave           ; handly byte of s1
32 advance:
33         inc ptr2            ; advance string position to test
34         bne check
35         inc ptr2+1
36         dey                 ; correct next iny (faster/shorter than bne...)
37
38 checkNext:
39         iny
40 check:  cpy tmp1            ; compare with length of test character string
41         beq leave
42         cmp (ptr1),y        ; found matching char?
43         bne checkNext
44
45 foundTestChar:
46         inx
47         bne loadChar
48         inc tmp2
49         bne loadChar        ; like bra...
50
51 leave:  txa                 ; restore position of finding
52         ldx tmp2            ; and return
53         rts