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
|
|
|
;
|
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
.export _memchr
|
|
|
|
.import popax, return0
|
|
|
|
.importzp ptr1, ptr2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
.proc _memchr
|
|
|
|
|
|
|
|
eor #$FF
|
|
|
|
sta ptr2
|
|
|
|
txa
|
|
|
|
eor #$FF
|
|
|
|
sta ptr2+1 ; Save ones complement of n
|
|
|
|
jsr popax ; get c
|
|
|
|
pha
|
2000-05-28 13:40:48 +00:00
|
|
|
jsr popax ; get p
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
ldy #$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
|
|
|
|
2003-05-05 17:19:48 +00:00
|
|
|
found: ldx ptr1+1 ; get high byte of pointer
|
2000-05-28 13:40:48 +00:00
|
|
|
tya ; low byte offset
|
|
|
|
clc
|
|
|
|
adc ptr1
|
2003-05-05 17:19:48 +00:00
|
|
|
bcc L9
|
2000-05-28 13:40:48 +00:00
|
|
|
inx
|
2003-05-05 17:19:48 +00:00
|
|
|
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
|
|
|
|