2000-05-28 13:40:48 +00:00
|
|
|
;
|
2003-08-20 10:17:53 +00:00
|
|
|
; Ullrich von Bassewitz, 2003-08-20
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2003-08-20 10:17:53 +00:00
|
|
|
; void* __fastcall__ memcpy (void* dest, const void* src, size_t n);
|
|
|
|
;
|
|
|
|
; NOTE: This function contains entry points for memmove, which will ressort
|
|
|
|
; to memcpy for an upwards copy. Don't change this module without looking
|
|
|
|
; at memmove!
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2003-08-20 10:17:53 +00:00
|
|
|
.export _memcpy, memcpy_upwards, memcpy_getparams
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1, ptr2, ptr3, tmp1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ----------------------------------------------------------------------
|
|
|
|
_memcpy:
|
2003-08-20 10:17:53 +00:00
|
|
|
jsr memcpy_getparams
|
|
|
|
|
|
|
|
memcpy_upwards:
|
|
|
|
ldy #0
|
|
|
|
ldx ptr3 ; Get low counter byte
|
|
|
|
|
|
|
|
; Copy loop
|
|
|
|
|
|
|
|
@L1: inx ; Bump low counter byte
|
|
|
|
beq @L2 ; Jump on overflow
|
|
|
|
lda (ptr1),y
|
|
|
|
sta (ptr2),y
|
|
|
|
iny
|
|
|
|
bne @L1
|
|
|
|
inc ptr1+1 ; Bump pointers
|
|
|
|
inc ptr2+1
|
|
|
|
bne @L1 ; Branch always
|
|
|
|
@L2: inc ptr3+1 ; Bump high counter byte
|
|
|
|
bne @L1
|
|
|
|
|
|
|
|
; Done. The low byte of dest is still in ptr2
|
|
|
|
|
|
|
|
done: lda ptr2
|
|
|
|
ldx tmp1 ; get function result (dest)
|
2000-05-28 13:40:48 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; ----------------------------------------------------------------------
|
2003-08-20 10:17:53 +00:00
|
|
|
; Get the parameters from stack as follows:
|
|
|
|
;
|
|
|
|
; -(size-1) --> ptr3
|
|
|
|
; src --> ptr1
|
|
|
|
; dest --> ptr2
|
|
|
|
; high(dest) --> tmp1
|
|
|
|
;
|
|
|
|
; dest is returned in a/x.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-08-20 10:17:53 +00:00
|
|
|
memcpy_getparams:
|
|
|
|
eor #$FF
|
|
|
|
sta ptr3
|
|
|
|
txa
|
|
|
|
eor #$FF
|
|
|
|
sta ptr3+1 ; Save -(size-1)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
jsr popax ; src
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
2003-08-20 10:17:53 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
jsr popax ; dest
|
|
|
|
sta ptr2
|
2003-08-20 10:17:53 +00:00
|
|
|
stx ptr2+1 ; Save work copy
|
|
|
|
stx tmp1 ; Save for function result
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-08-20 10:17:53 +00:00
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|