2000-05-28 13:40:48 +00:00
|
|
|
;
|
2018-05-29 18:29:50 +00:00
|
|
|
; 1998-06-11, Ullrich von Bassewitz
|
|
|
|
; 2018-05-29, Greg King
|
|
|
|
;
|
|
|
|
; char* __fastcall__ strpbrk (const char* str, const char* set);
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _strpbrk
|
2018-05-29 18:29:50 +00:00
|
|
|
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1, ptr2, tmp2, tmp3
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_strpbrk:
|
2018-05-29 18:29:50 +00:00
|
|
|
sta ptr2 ; store set
|
2013-05-09 11:56:54 +00:00
|
|
|
stx ptr2+1
|
2018-05-29 18:29:50 +00:00
|
|
|
jsr popax
|
|
|
|
stx ptr1+1 ; store str's high byte
|
|
|
|
ldx #<$0000
|
|
|
|
stx ptr1
|
|
|
|
tay ; use str's low byte as index
|
2013-05-09 11:56:54 +00:00
|
|
|
|
2018-05-29 18:29:50 +00:00
|
|
|
L1: lda (ptr1),y ; get next char from str
|
2013-05-09 11:56:54 +00:00
|
|
|
beq L9 ; jump if done
|
|
|
|
sta tmp2 ; save char
|
2018-05-29 18:29:50 +00:00
|
|
|
sty tmp3 ; save index into str
|
2013-05-09 11:56:54 +00:00
|
|
|
|
2018-05-29 18:29:50 +00:00
|
|
|
ldy #$00
|
|
|
|
L3: lda (ptr2),y ; look at each char in set
|
2013-05-09 11:56:54 +00:00
|
|
|
beq L4 ; jump if done
|
|
|
|
cmp tmp2
|
2018-05-29 18:29:50 +00:00
|
|
|
beq L6 ; break out of loops if something found
|
2013-05-09 11:56:54 +00:00
|
|
|
iny
|
|
|
|
bne L3
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-05-29 18:29:50 +00:00
|
|
|
; The character was not found in set. Increment the counter; and start over.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L4: ldy tmp3 ; reload index
|
2018-05-29 18:29:50 +00:00
|
|
|
iny
|
2013-05-09 11:56:54 +00:00
|
|
|
bne L1
|
2018-05-29 18:29:50 +00:00
|
|
|
inc ptr1+1
|
|
|
|
bne L1 ; branch always
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-05-29 18:29:50 +00:00
|
|
|
; A character was found. Return its str pointer.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L6: ldx ptr1+1
|
2018-05-29 18:29:50 +00:00
|
|
|
lda tmp3 ; get .Y offset
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-05-29 18:29:50 +00:00
|
|
|
; None of the characters in set was found -- return NULL.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-05-29 18:29:50 +00:00
|
|
|
L9: ;ldx #>$0000 ; (set by prolog)
|
|
|
|
;lda #<$0000 ; (set by '\0' at end of str)
|
|
|
|
rts
|