Announce SDCC 4.5.0 RC1.
[sdcc.git] / sdcc / device / lib / ds390 / memcpyx.c
blob5ec6eba9b57f7be260a681ec1646c106fdeed789
1 /*-------------------------------------------------------------------------
2 memcpyx.c
4 Copyright (C) 2000, 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 void __xdata * memcpyx (
32 void __xdata * dst,
33 void __xdata * src,
34 int count
35 ) __naked
37 /* Shut compiler up about unused parameters. */
38 dst; src; count;
40 /* AUTO_TOGGLE uses the '390 DPTS toggle bit. */
41 #define AUTO_TOGGLE
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 #ifdef AUTO_TOGGLE
73 mov dps, #0x21 ; Current DPTR is alt DPTR, toggle after each op.
74 #else
75 mov dps, #0x0 ; Current DPTR is normal DPTR, no toggle.
76 #endif
78 ; src is in alt DPTR, dst is in normal DPTR, count is in r2/r3.
80 ; If we have zero bytes to copy, quick out.
81 mov a, r2
82 orl a, r3
83 jz _memcpy_done
85 ; increment r3 if r2 != 0 (makes djnz end-of-loop sequence possible).
86 inc r3
87 cjne r2, #0x0, _memcpyx_loopTop
88 dec r3
90 _memcpyx_loopTop:
92 #ifdef AUTO_TOGGLE
93 movx a, @dptr
94 movx @dptr, a
95 inc dptr
96 inc dptr
97 #else
98 inc dps
99 movx a, @dptr
100 inc dptr
101 dec dps
102 movx @dptr, a
103 inc dptr
104 #endif
106 djnz r2, _memcpyx_loopTop
107 djnz r3, _memcpyx_loopTop
109 _memcpy_done:
111 #ifdef AUTO_TOGGLE
112 mov dps, #0x0
113 #endif
115 pop dpl
116 pop dph
117 pop dpx
119 __endasm;