]> git.sur5r.net Git - cc65/blob - libsrc/pce/memmove.s
Adjusted to the current multiline-comment style.
[cc65] / libsrc / pce / memmove.s
1 ;
2 ; This file, instead of "common/memmove.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.
5 ;
6 ; 2003-08-20, Ullrich von Bassewitz
7 ; 2015-10-23, Greg King
8 ;
9 ; void* __fastcall__ memmove (void* dest, const void* src, size_t size);
10 ;
11 ; NOTE: This function uses entry points from "pce/memcpy.s"!
12 ;
13
14         .export         _memmove
15
16         .import         memcpy_getparams, memcpy_increment, memcpy_transfer
17         .importzp       ptr1, ptr2, ptr3
18
19         .macpack        generic
20         .macpack        longbranch
21
22
23 ; ----------------------------------------------------------------------
24 _memmove:
25         jsr     memcpy_getparams
26
27 ; Check for the copy direction.  If dest < src, we must copy downwards (start
28 ; at low addresses, and increase pointers); otherwise, we must copy upwards
29 ; (start at high addresses, and decrease pointers).
30
31         cmp     ptr1
32         txa
33         sbc     ptr1+1
34         jcc     memcpy_increment        ; Branch if dest < src
35
36 ; Copy decrementing; adjust the pointers to the end of the memory regions.
37
38         lda     ptr1
39         add     ptr3
40         sta     ptr1
41         lda     ptr1+1
42         adc     ptr3+1
43         sta     ptr1+1
44
45         lda     ptr1                    ; point to last byte of source
46         bne     @L1
47         dec     ptr1+1
48 @L1:    dec     ptr1
49
50         lda     ptr2
51         add     ptr3
52         sta     ptr2
53         lda     ptr2+1
54         adc     ptr3+1
55         sta     ptr2+1
56
57         lda     ptr2                    ; point to last byte of target
58         bne     @L2
59         dec     ptr2+1
60 @L2:    dec     ptr2
61
62         ldy     #$C3                    ; TDD opcode
63         jmp     memcpy_transfer