2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 31.05.1998
|
2017-02-25 19:19:34 +00:00
|
|
|
; Christian Krueger, 2013-Aug-04, minor optimization
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; const char* strchr (const char* s, int c);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _strchr
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1, tmp1
|
2017-03-05 10:38:55 +00:00
|
|
|
.macpack cpu
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_strchr:
|
2017-02-25 19:19:34 +00:00
|
|
|
sta tmp1 ; Save c
|
|
|
|
jsr popax ; get s
|
|
|
|
tay ; low byte of pointer to y
|
|
|
|
stx ptr1+1
|
2017-03-05 01:09:12 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
|
|
|
stz ptr1
|
|
|
|
.else
|
2017-02-25 19:19:34 +00:00
|
|
|
lda #0
|
2017-03-05 01:09:12 +00:00
|
|
|
sta ptr1 ; access from page start, y contains low byte
|
2017-04-06 15:53:57 +00:00
|
|
|
.endif
|
2017-02-25 19:19:34 +00:00
|
|
|
|
|
|
|
Loop: lda (ptr1),y ; Get next char
|
|
|
|
beq EOS ; Jump on end of string
|
|
|
|
cmp tmp1 ; Found?
|
|
|
|
beq Found ; Jump if yes
|
2013-05-09 11:56:54 +00:00
|
|
|
iny
|
2017-02-25 19:19:34 +00:00
|
|
|
bne Loop
|
|
|
|
inc ptr1+1
|
2017-04-06 15:53:57 +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
|
|
|
|
2017-02-25 19:19:34 +00:00
|
|
|
EOS:
|
|
|
|
lda tmp1 ; Get the char we're searching for
|
|
|
|
bne NotFound ; Jump if not searching for terminator
|
2000-06-09 12:07:53 +00:00
|
|
|
|
2017-02-25 19:19:34 +00:00
|
|
|
; Found. Set pointer to c.
|
2000-06-09 12:07:53 +00:00
|
|
|
|
2017-02-25 19:19:34 +00:00
|
|
|
Found:
|
|
|
|
ldx ptr1+1 ; Load high byte of pointer
|
|
|
|
tya ; low byte is in y
|
|
|
|
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:
|
2017-02-25 19:19:34 +00:00
|
|
|
lda #0
|
2013-05-09 11:56:54 +00:00
|
|
|
tax
|
|
|
|
rts
|