2000-05-28 13:40:48 +00:00
|
|
|
;
|
2003-05-05 17:19:48 +00:00
|
|
|
; Ullrich von Bassewitz, 2003-05-05
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2003-05-05 17:19:48 +00:00
|
|
|
; void* __fastcall__ memchr (const void* p, int c, size_t n);
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _memchr
|
2018-05-20 13:38:48 +00:00
|
|
|
.import popax, popptr1, return0
|
2013-05-09 11:56:54 +00:00
|
|
|
.importzp ptr1, ptr2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
.proc _memchr
|
|
|
|
|
|
|
|
eor #$FF
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr2
|
2003-05-05 17:19:48 +00:00
|
|
|
txa
|
|
|
|
eor #$FF
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr2+1 ; Save ones complement of n
|
|
|
|
jsr popax ; get c
|
|
|
|
pha
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; get p
|
|
|
|
|
|
|
|
; ldy #$00 is guaranteed by popptr1
|
2003-05-05 17:19:48 +00:00
|
|
|
pla ; Get c
|
|
|
|
ldx ptr2 ; Use X as low counter byte
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
L1: inx
|
|
|
|
beq L3
|
|
|
|
L2: cmp (ptr1),y
|
|
|
|
beq found
|
|
|
|
iny
|
|
|
|
bne L1
|
|
|
|
inc ptr1+1
|
|
|
|
bne L1 ; Branch always
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
L3: inc ptr2+1 ; Bump counter high byte
|
|
|
|
bne L2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
; Not found, return NULL
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
notfound:
|
|
|
|
jmp return0
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
; Found, return pointer to char
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
found: ldx ptr1+1 ; get high byte of pointer
|
|
|
|
tya ; low byte offset
|
|
|
|
clc
|
|
|
|
adc ptr1
|
|
|
|
bcc L9
|
|
|
|
inx
|
|
|
|
L9: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
.endproc
|
2000-05-28 13:40:48 +00:00
|
|
|
|