aboutsummaryrefslogtreecommitdiff
path: root/src/strlen8.s
blob: c622d73fc4b1873090ad06152e406155715cd1fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 ; strlen() implementation that only looks at the first 256
 ; byte of the string. returns 255 if the length is >=255.
 ; saves a measly 4 bytes over the cc65 strlen().

 ; extern unsigned char strlen8(const char *str);

 .importzp ptr1
 .export _strlen8

_strlen8:
 sta ptr1
 stx ptr1+1
 ldy #0
@loop:
 lda (ptr1),y
 beq @done
 iny
 bne @loop
 dey ; return(255) if Y rolls over
@done:
 tya
 ldx #0 ; sadly necessary even though we return a char...
 rts