]> git.sur5r.net Git - cc65/blob - libsrc/common/strcspn.s
atari5200: conio now uses just four colors altogether
[cc65] / libsrc / common / strcspn.s
1 ;
2 ; Ullrich von Bassewitz, 11.06.1998
3 ; Christian Krueger: 05-Aug-2013, optimization
4 ;
5 ; size_t strcspn (const char* s1, const char* s2);
6 ;
7
8         .export         _strcspn
9         .import         popptr1, _strlen
10         .importzp       ptr1, ptr2, tmp1, tmp2
11
12 _strcspn:
13         jsr _strlen         ; get length in a/x and transfer s2 to ptr2
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! (ptr2+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 popptr1         ; get and save s1 to ptr1
23         
24         ldx #0              ; low counter byte
25         stx tmp2            ; high counter byte
26
27 loadChar:
28         ldy #0
29         lda (ptr1),y        ; get next char from s1
30         beq leave           ; handly byte of s1
31 advance:
32         inc ptr1            ; advance string position to test
33         bne check
34         inc ptr1+1
35         dey                 ; correct next iny (faster/shorter than bne...)
36
37 checkNext:
38         iny
39 check:  cpy tmp1            ; compare with length of test character string
40         beq endOfTestChars
41         cmp (ptr2),y        ; found matching char?
42         bne checkNext
43
44 leave:  txa                 ; restore position of finding
45         ldx tmp2            ; and return
46         rts
47
48 endOfTestChars:
49         inx
50         bne loadChar
51         inc tmp2
52         bne loadChar        ; like bra...