aboutsummaryrefslogtreecommitdiff
path: root/src/strlen8.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/strlen8.s')
-rw-r--r--src/strlen8.s24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/strlen8.s b/src/strlen8.s
new file mode 100644
index 0000000..c622d73
--- /dev/null
+++ b/src/strlen8.s
@@ -0,0 +1,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
+