]> git.sur5r.net Git - cc65/blob - libsrc/common/memcpy.s
Call interrupt handlers with carry clear
[cc65] / libsrc / common / memcpy.s
1 ;
2 ; Ullrich von Bassewitz, 2003-08-20
3 ;
4 ; void* __fastcall__ memcpy (void* dest, const void* src, size_t n);
5 ;
6 ; NOTE: This function contains entry points for memmove, which will ressort
7 ; to memcpy for an upwards copy. Don't change this module without looking
8 ; at memmove!
9 ;
10
11         .export         _memcpy, memcpy_upwards, memcpy_getparams
12         .import         popax
13         .importzp       ptr1, ptr2, ptr3, tmp1
14
15 ; ----------------------------------------------------------------------
16 _memcpy:
17         jsr     memcpy_getparams
18
19 memcpy_upwards:
20         ldy     #0
21         ldx     ptr3            ; Get low counter byte
22
23 ; Copy loop
24
25 @L1:    inx                     ; Bump low counter byte
26         beq     @L3             ; Jump on overflow
27 @L2:    lda     (ptr1),y
28         sta     (ptr2),y
29         iny
30         bne     @L1
31         inc     ptr1+1          ; Bump pointers
32         inc     ptr2+1
33         bne     @L1             ; Branch always
34 @L3:    inc     ptr3+1          ; Bump high counter byte
35         bne     @L2
36
37 ; Done. The low byte of dest is still in ptr2
38
39 done:   lda     ptr2
40         ldx     tmp1            ; get function result (dest)
41         rts
42
43 ; ----------------------------------------------------------------------
44 ; Get the parameters from stack as follows:
45 ;
46 ;       -(size-1)       --> ptr3
47 ;       src             --> ptr1
48 ;       dest            --> ptr2
49 ;       high(dest)      --> tmp1
50 ;
51 ; dest is returned in a/x.
52
53 memcpy_getparams:
54         eor     #$FF
55         sta     ptr3
56         txa
57         eor     #$FF
58         sta     ptr3+1          ; Save -(size-1)
59
60         jsr     popax           ; src
61         sta     ptr1
62         stx     ptr1+1
63
64         jsr     popax           ; dest
65         sta     ptr2
66         stx     ptr2+1          ; Save work copy
67         stx     tmp1            ; Save for function result
68
69         rts
70