struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / ds400 / memcpyx.c
blob2fc8d27fbd4e1542341bf63f26b673a9d20ae0ef
1 /*-------------------------------------------------------------------------
2 memcpyx.c
4 Copyright (C) 2003, Kevin Vigor
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 MA 02110-1301, USA.
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
29 #include <string.h>
31 // FIXME: can optimize even further on '400 with auto-increment/auto-toggle.
33 void __xdata * memcpyx (
34 void __xdata * dst,
35 void __xdata * src,
36 int count
37 ) __naked
39 /* Shut compiler up about unused parameters. */
40 dst; src; count;
42 __asm
43 ; Destination is in DPTR. Save it on stack so we can return it at end.
45 push dpx
46 push dph
47 push dpl
49 mov dps, #0x1 ; Alternate DPTR.
51 ; count is in _memcpyx_PARM_3
52 mov dptr, #_memcpyx_PARM_3
53 movx a, @dptr
54 inc dptr
55 mov r2, a
56 movx a, @dptr
57 mov r3, a
59 ; src is in _memcpyx_PARM_2
60 mov dptr, #_memcpyx_PARM_2
61 movx a, @dptr
62 inc dptr
63 push acc
64 movx a, @dptr
65 inc dptr
66 push acc
67 movx a, @dptr
68 mov dpx1, a
69 pop dph1
70 pop dpl1
72 mov dps, #0x21 ; Current DPTR is alt DPTR, toggle after each op.
74 ; src is in alt DPTR, dst is in normal DPTR, count is in r2/r3.
76 ; If we have zero bytes to copy, quick out.
77 mov a, r2
78 orl a, r3
79 jz _memcpy_done
81 ; increment r3 if r2 != 0 (makes djnz end-of-loop sequence possible).
82 inc r3
83 cjne r2, #0x0, _memcpyx_loopTop
84 dec r3
86 _memcpyx_loopTop:
88 movx a, @dptr
89 movx @dptr, a
90 inc dptr
91 inc dptr
93 djnz r2, _memcpyx_loopTop
94 djnz r3, _memcpyx_loopTop
96 _memcpy_done:
98 mov dps, #0x0
100 pop dpl
101 pop dph
102 pop dpx
104 __endasm;