2021-12-24 22:44:57 +00:00
|
|
|
; size_t __fastcall__ strnlen (const char* s, size_t maxlen);
|
|
|
|
|
|
|
|
.export _strnlen
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1, tmp1, tmp2, tmp3, tmp4
|
|
|
|
|
|
|
|
.proc _strnlen
|
2021-12-25 08:11:58 +00:00
|
|
|
; Get maximum length.
|
|
|
|
tay
|
|
|
|
iny
|
|
|
|
sty tmp3
|
|
|
|
inx
|
|
|
|
stx tmp4
|
|
|
|
|
2021-12-24 22:44:57 +00:00
|
|
|
; Fetch string pointer.
|
2021-12-25 08:11:58 +00:00
|
|
|
jsr popax
|
2021-12-24 22:44:57 +00:00
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
|
|
|
|
; Clear return value.
|
2021-12-25 08:11:58 +00:00
|
|
|
ldy #0
|
|
|
|
sty tmp1
|
|
|
|
sty tmp2
|
2021-12-24 22:44:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Loop over string.
|
|
|
|
; Decrement maximum length.
|
|
|
|
next: dec tmp3
|
|
|
|
bne l2
|
|
|
|
dec tmp4
|
|
|
|
beq done
|
|
|
|
l2:
|
|
|
|
|
|
|
|
lda (ptr1),y
|
|
|
|
beq done
|
|
|
|
|
|
|
|
; Step to next character.
|
2021-12-25 08:11:58 +00:00
|
|
|
iny
|
2021-12-24 22:44:57 +00:00
|
|
|
bne l1
|
|
|
|
inc ptr1+1
|
|
|
|
l1:
|
|
|
|
|
|
|
|
; Increment return value.
|
|
|
|
inc tmp1
|
|
|
|
bne next
|
|
|
|
inc tmp2
|
|
|
|
|
2021-12-25 08:11:58 +00:00
|
|
|
bne next ; (jmp)
|
2021-12-24 22:44:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
done: lda tmp1
|
|
|
|
ldx tmp2
|
|
|
|
rts
|
|
|
|
.endproc
|