2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 11.06.1998
|
2017-03-05 01:09:12 +00:00
|
|
|
; Christian Krueger: 08-Aug-2013, optimization
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; size_t strspn (const char* s1, const char* s2);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _strspn
|
2018-05-22 13:59:05 +00:00
|
|
|
.import popptr1, _strlen
|
2024-01-05 18:39:03 +00:00
|
|
|
.importzp ptr1, ptr4, tmp1, tmp2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_strspn:
|
2024-01-05 18:39:03 +00:00
|
|
|
jsr _strlen ; get length in a/x and transfer s2 to ptr4
|
2017-03-05 01:09:12 +00:00
|
|
|
; Note: It does not make sense to
|
|
|
|
; have more than 255 test chars, so
|
2024-01-05 18:39:03 +00:00
|
|
|
; we don't support a high byte here! (ptr4+1 is
|
2017-03-05 01:09:12 +00:00
|
|
|
; also unchanged in strlen then (important!))
|
|
|
|
; -> the original implementation also
|
|
|
|
; ignored this case
|
|
|
|
|
|
|
|
sta tmp1 ; tmp1 = strlen of test chars
|
2018-05-22 13:59:05 +00:00
|
|
|
jsr popptr1 ; get and save s1 to ptr1
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
ldx #0 ; low counter byte
|
|
|
|
stx tmp2 ; high counter byte
|
|
|
|
|
|
|
|
loadChar:
|
|
|
|
ldy #0
|
2018-05-22 13:59:05 +00:00
|
|
|
lda (ptr1),y ; get next char from s1
|
2017-03-05 01:09:12 +00:00
|
|
|
beq leave ; handly byte of s1
|
|
|
|
advance:
|
2018-05-22 13:59:05 +00:00
|
|
|
inc ptr1 ; advance string position to test
|
2017-03-05 01:09:12 +00:00
|
|
|
bne check
|
2018-05-22 13:59:05 +00:00
|
|
|
inc ptr1+1
|
2017-03-05 01:09:12 +00:00
|
|
|
dey ; correct next iny (faster/shorter than bne...)
|
|
|
|
|
|
|
|
checkNext:
|
2013-05-09 11:56:54 +00:00
|
|
|
iny
|
2017-03-05 01:09:12 +00:00
|
|
|
check: cpy tmp1 ; compare with length of test character string
|
|
|
|
beq leave
|
2024-01-05 18:39:03 +00:00
|
|
|
cmp (ptr4),y ; found matching char?
|
2017-04-06 15:53:57 +00:00
|
|
|
bne checkNext
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
foundTestChar:
|
2013-05-09 11:56:54 +00:00
|
|
|
inx
|
2017-03-05 01:09:12 +00:00
|
|
|
bne loadChar
|
|
|
|
inc tmp2
|
2017-04-06 15:53:57 +00:00
|
|
|
bne loadChar ; like bra...
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
leave: txa ; restore position of finding
|
|
|
|
ldx tmp2 ; and return
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|