2 ; This file, instead of "common/memcpy.s", will be assembled for the pce
3 ; target. This version is smaller and faster because it uses the HuC6280's
4 ; block-copy instructions.
6 ; 2003-08-20, Ullrich von Bassewitz
7 ; 2015-11-02, Greg King
9 ; void* __fastcall__ memcpy (void* dest, const void* src, size_t size);
11 ; NOTE: This function contains entry points for memmove, which will resort
12 ; to memcpy for an incrementing copy. Don't change this module without looking
17 .export memcpy_increment, memcpy_transfer, memcpy_getparams
20 .importzp sp, ptr1, ptr2, ptr3
23 ; The structure of the transfer instructions
32 ; ----------------------------------------------------------------------
49 sta transfer+destination
50 stx transfer+destination+1
59 ; ----------------------------------------------------------------------
60 ; Get the parameters from the stack, as follows:
66 ; The first argument (dest) will remain on the stack; and, is returned in .XA!
70 stx ptr3+1 ; save size
74 ; The size is zero; copy nothing; just return the dest address.
75 ; (The HuC6280's transfer instructions can't copy $0000 bytes;
76 ; they would copy $10000 [64K] bytes instead.)
78 ply ; drop return address
80 jsr incsp2 ; drop src address
81 jmp popax ; get pointer; return it as result
87 ; (Direct stack access is six cycles faster [total cycle count].)
90 lda (sp),y ; get high byte
92 lda (sp) ; get low byte
95 rts ; return dest address (for memmove)
97 ; ----------------------------------------------------------------------
98 ; The transfer instructions use inline arguments.
99 ; Therefore, we must build the instruction, in the DATA segment.
104 tii $FFFF, $FFFF, $0001
105 jmp popax ; get pointer; return it as result