2003-08-20 10:17:53 +00:00
|
|
|
;
|
2015-10-23 22:02:21 +00:00
|
|
|
; 2003-08-20, Ullrich von Bassewitz
|
2017-03-05 01:09:12 +00:00
|
|
|
; 2009-09-13, Christian Krueger -- performance increase (about 20%), 2013-07-25 improved unrolling
|
2015-10-23 22:02:21 +00:00
|
|
|
; 2015-10-23, Greg King
|
2003-08-20 10:17:53 +00:00
|
|
|
;
|
|
|
|
; void* __fastcall__ memmove (void* dest, const void* src, size_t size);
|
|
|
|
;
|
|
|
|
; NOTE: This function uses entry points from memcpy!
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _memmove
|
2009-09-20 14:32:25 +00:00
|
|
|
.import memcpy_getparams, memcpy_upwards, popax
|
2013-05-09 11:56:54 +00:00
|
|
|
.importzp ptr1, ptr2, ptr3, ptr4, tmp1
|
2003-08-20 10:17:53 +00:00
|
|
|
|
|
|
|
.macpack generic
|
|
|
|
.macpack longbranch
|
|
|
|
|
|
|
|
; ----------------------------------------------------------------------
|
|
|
|
_memmove:
|
|
|
|
jsr memcpy_getparams
|
|
|
|
|
|
|
|
; Check for the copy direction. If dest < src, we must copy upwards (start at
|
|
|
|
; low addresses and increase pointers), otherwise we must copy downwards
|
|
|
|
; (start at high addresses and decrease pointers).
|
|
|
|
|
2015-10-23 22:02:21 +00:00
|
|
|
cmp ptr1
|
2003-08-20 10:17:53 +00:00
|
|
|
txa
|
|
|
|
sbc ptr1+1
|
|
|
|
jcc memcpy_upwards ; Branch if dest < src (upwards copy)
|
|
|
|
|
|
|
|
; Copy downwards. Adjust the pointers to the end of the memory regions.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr1+1
|
|
|
|
add ptr3+1
|
|
|
|
sta ptr1+1
|
2003-08-20 10:17:53 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr2+1
|
|
|
|
add ptr3+1
|
|
|
|
sta ptr2+1
|
2003-08-20 10:17:53 +00:00
|
|
|
|
2009-09-20 14:32:25 +00:00
|
|
|
; handle fractions of a page size first
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy ptr3 ; count, low byte
|
|
|
|
bne @entry ; something to copy?
|
|
|
|
beq PageSizeCopy ; here like bra...
|
2009-09-20 14:32:25 +00:00
|
|
|
|
|
|
|
@copyByte:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
sta (ptr2),y
|
2009-09-20 14:32:25 +00:00
|
|
|
@entry:
|
2013-05-09 11:56:54 +00:00
|
|
|
dey
|
|
|
|
bne @copyByte
|
|
|
|
lda (ptr1),y ; copy remaining byte
|
|
|
|
sta (ptr2),y
|
2009-09-20 14:32:25 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
PageSizeCopy: ; assert Y = 0
|
|
|
|
ldx ptr3+1 ; number of pages
|
|
|
|
beq done ; none? -> done
|
2009-09-20 14:32:25 +00:00
|
|
|
|
|
|
|
@initBase:
|
2013-05-09 11:56:54 +00:00
|
|
|
dec ptr1+1 ; adjust base...
|
|
|
|
dec ptr2+1
|
|
|
|
dey ; in entry case: 0 -> FF
|
2009-09-20 14:32:25 +00:00
|
|
|
@copyBytes:
|
2017-03-05 01:09:12 +00:00
|
|
|
.repeat 3 ; unroll this a bit to make it faster...
|
|
|
|
lda (ptr1),y ; important: unrolling three times gives a nice
|
|
|
|
sta (ptr2),y ; 255/3 = 85 loop which ends at 0
|
2013-05-09 11:56:54 +00:00
|
|
|
dey
|
|
|
|
.endrepeat
|
|
|
|
@copyEntry: ; in entry case: 0 -> FF
|
|
|
|
bne @copyBytes
|
|
|
|
lda (ptr1),y ; Y = 0, copy last byte
|
2009-09-20 14:32:25 +00:00
|
|
|
sta (ptr2),y
|
2013-05-09 11:56:54 +00:00
|
|
|
dex ; one page to copy less
|
|
|
|
bne @initBase ; still a page to copy?
|
2003-08-20 10:17:53 +00:00
|
|
|
|
|
|
|
; Done, return dest
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
done: jmp popax ; Pop ptr and return as result
|