2000-05-28 13:40:48 +00:00
|
|
|
;
|
2000-09-15 17:23:19 +00:00
|
|
|
; Ullrich von Bassewitz, 15.09.2000
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; int memcmp (const void* p1, const void* p2, size_t count);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _memcmp
|
|
|
|
.import popax, return0
|
|
|
|
.importzp ptr1, ptr2, ptr3
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_memcmp:
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Calculate (-count-1) and store it into ptr3. This is some overhead here but
|
|
|
|
; saves time in the compare loop
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
eor #$FF
|
|
|
|
sta ptr3
|
|
|
|
txa
|
|
|
|
eor #$FF
|
|
|
|
sta ptr3+1
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Get the pointer parameters
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; Get p2
|
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1
|
|
|
|
jsr popax ; Get p1
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-09-15 17:23:19 +00:00
|
|
|
; Loop initialization
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx ptr3 ; Load low counter byte into X
|
|
|
|
ldy #$00 ; Initialize pointer
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Head of compare loop: Test for the end condition
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
Loop: inx ; Bump low byte of (-count-1)
|
|
|
|
beq BumpHiCnt ; Jump on overflow
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Do the compare
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
Comp: lda (ptr1),y
|
|
|
|
cmp (ptr2),y
|
|
|
|
bne NotEqual ; Jump if bytes not equal
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Bump the pointers
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
iny ; Increment pointer
|
|
|
|
bne Loop
|
|
|
|
inc ptr1+1 ; Increment high bytes
|
|
|
|
inc ptr2+1
|
|
|
|
bne Loop ; Branch always (pointer wrap is illegal)
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Entry on low counter byte overflow
|
|
|
|
|
|
|
|
BumpHiCnt:
|
2013-05-09 11:56:54 +00:00
|
|
|
inc ptr3+1 ; Bump high byte of (-count-1)
|
|
|
|
bne Comp ; Jump if not done
|
|
|
|
jmp return0 ; Count is zero, areas are identical
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Not equal, check which one is greater
|
|
|
|
|
2000-09-15 17:23:19 +00:00
|
|
|
NotEqual:
|
2013-05-09 11:56:54 +00:00
|
|
|
bcs Greater
|
|
|
|
ldx #$FF ; Make result negative
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-09-15 17:23:19 +00:00
|
|
|
Greater:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #$01 ; Make result positive
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|