1
0
mirror of https://github.com/cc65/cc65.git synced 2026-04-26 13:18:31 +00:00

Fixed strpbrk().

Added its prototype.  Documented it.
This commit is contained in:
Greg King
2018-05-29 14:29:50 -04:00
parent a0832b62c6
commit 6d87370881
4 changed files with 88 additions and 39 deletions
+29 -36
View File
@@ -1,60 +1,53 @@
;
; Ullrich von Bassewitz, 11.06.1998
;
; char* strpbrk (const char* s1, const char* s2);
; 1998-06-11, Ullrich von Bassewitz
; 2018-05-29, Greg King
;
; char* __fastcall__ strpbrk (const char* str, const char* set);
;
.export _strpbrk
.import popax, return0
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
.import popax
.importzp ptr1, ptr2, tmp2, tmp3
_strpbrk:
jsr popax ; get s2
sta ptr2
sta ptr2 ; store set
stx ptr2+1
jsr popax ; get s1
sta ptr1
stx ptr1+1
ldy #$00
jsr popax
stx ptr1+1 ; store str's high byte
ldx #<$0000
stx ptr1
tay ; use str's low byte as index
L1: lda (ptr1),y ; get next char from s1
L1: lda (ptr1),y ; get next char from str
beq L9 ; jump if done
sta tmp2 ; save char
iny
bne L2
inc ptr1+1
L2: sty tmp3 ; save index into s1
sty tmp3 ; save index into str
ldy #0 ; get index into s2
L3: lda (ptr2),y ;
ldy #$00
L3: lda (ptr2),y ; look at each char in set
beq L4 ; jump if done
cmp tmp2
beq L6
beq L6 ; break out of loops if something found
iny
bne L3
; The character was not found in s2. Increment the counter and start over
; The character was not found in set. Increment the counter; and start over.
L4: ldy tmp3 ; reload index
inx
bne L1
inc tmp1
iny
bne L1
inc ptr1+1
bne L1 ; branch always
; A character was found. Calculate a pointer to this char in s1 and return it.
; A character was found. Return its str pointer.
L6: ldx ptr1+1
lda tmp3 ; get y offset
clc
adc ptr1
bcc L7
inx
L7: rts
; None of the characters in s2 was found - return NULL
L9: jmp return0
lda tmp3 ; get .Y offset
rts
; None of the characters in set was found -- return NULL.
L9: ;ldx #>$0000 ; (set by prolog)
;lda #<$0000 ; (set by '\0' at end of str)
rts