2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 31.05.1998
|
|
|
|
;
|
|
|
|
; const char* strchr (const char* s, int c);
|
|
|
|
;
|
|
|
|
|
2000-06-09 12:07:53 +00:00
|
|
|
.export _strchr
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1, tmp1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_strchr:
|
|
|
|
sta tmp1 ; Save c
|
|
|
|
jsr popax ; get s
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
ldy #0
|
|
|
|
|
2000-06-09 12:07:53 +00:00
|
|
|
Loop: lda (ptr1),y ; Get next char
|
|
|
|
beq EOS ; Jump on end of string
|
|
|
|
cmp tmp1 ; Found?
|
|
|
|
beq Found ; Jump if yes
|
2000-05-28 13:40:48 +00:00
|
|
|
iny
|
2000-06-09 12:07:53 +00:00
|
|
|
bne Loop
|
2000-05-28 13:40:48 +00:00
|
|
|
inc ptr1+1
|
2000-06-09 12:07:53 +00:00
|
|
|
bne Loop ; Branch always
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-09 12:07:53 +00:00
|
|
|
; End of string. Check if we're searching for the terminating zero
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-09 12:07:53 +00:00
|
|
|
EOS: lda tmp1 ; Get the char we're searching for
|
|
|
|
bne NotFound ; Jump if not searching for terminator
|
|
|
|
|
|
|
|
; Found. Calculate pointer to c.
|
|
|
|
|
|
|
|
Found: ldx ptr1+1 ; Load high byte of pointer
|
|
|
|
tya ; Low byte offset
|
2000-05-28 13:40:48 +00:00
|
|
|
clc
|
|
|
|
adc ptr1
|
2000-06-09 12:07:53 +00:00
|
|
|
bcc Found1
|
2000-05-28 13:40:48 +00:00
|
|
|
inx
|
2000-06-09 12:07:53 +00:00
|
|
|
Found1: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-09 12:07:53 +00:00
|
|
|
; Not found, return NULL
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-09 12:07:53 +00:00
|
|
|
NotFound:
|
|
|
|
lda #0
|
|
|
|
tax
|
2000-05-28 13:40:48 +00:00
|
|
|
rts
|
|
|
|
|