* .version: bumped version to 2.4.7
[fw/sdcc] / device / lib / _gptrput.c
1 /*-------------------------------------------------------------------------
2
3   _gptrput.c :- put value for a generic pointer
4
5              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
6
7    This library is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Library General Public License as published by the
9    Free Software Foundation; either version 2, or (at your option) any
10    later version.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21    In other words, you are welcome to use, share and improve this program.
22    You are forbidden to forbid anyone else to use, share and improve
23    what you give them.   Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
25
26 /* not all devices use P2 to page pdata memory, therefore __XPAGE was
27    introduced. On some targets __XPAGE itself is a paged SFR so it is
28    not safe for all platforms to set this. Furthermore some targets
29    can be configured to behave differently for movx @dptr vs. movx @Ri
30    (don't drive high byte of address bus for movx @Ri only) */
31 #define USE_PDATA_PAGING_REGISTER 0
32
33 void
34 _gptrput (char *gptr, char c) _naked
35 {
36     gptr; c; /* hush the compiler */
37
38     _asm
39         ar0 = 0x00
40         push     acc
41     ;
42     ;   depending on the pointer type acc. to SDCCsymt.h
43     ;
44         mov     a,b
45         jz      00001$  ; 0 near
46         dec     a
47         jz      00002$  ; 1 far
48         dec     a
49         jz      00003$  ; 2 code
50         dec     a
51         jz      00004$  ; 3 pdata
52         dec     a       ; 4 skip generic pointer
53         dec     a
54         jz      00001$  ; 5 idata
55
56  00003$:
57         pop     acc    ; do nothing
58         sjmp    00005$
59 ;
60 ;       store into near space
61 ;
62  00001$:
63         pop     acc
64         push    ar0
65         mov     r0,dpl
66         mov     @r0,a
67         pop     ar0
68         sjmp    00005$
69
70  00002$:
71         pop     acc
72         movx    @dptr,a
73         sjmp    00005$
74
75  00004$:
76 #if USE_PDATA_PAGING_REGISTER
77         pop     acc
78         mov     dph,__XPAGE     ; __XPAGE (usually p2) holds high byte for pdata access
79         movx    @dptr,a
80 #else
81         pop     acc
82         push    ar0
83         mov     r0,dpl
84         movx    @r0,a
85         pop     ar0
86 #endif
87
88  00005$:
89         ret
90 _endasm;
91 }
92
93 #ifdef SDCC_ds390
94 void
95 _gptrputWord ()
96 {
97     _asm
98         push     acc
99     ;
100     ;   depending on the pointer type acc. to SDCCsymt.h
101     ;
102         mov     a,b
103         jz      00011$  ; 0 near
104         dec     a
105         jz      00012$  ; 1 far
106         dec     a
107         jz      00013$  ; 2 code
108         dec     a
109         jz      00014$  ; 3 pdata
110         dec     a       ; 4 skip generic pointer
111         dec     a
112         jz      00011$  ; 5 idata
113         pop     acc
114         sjmp    00016$
115 ;
116 ;       store into near space
117 ;
118  00011$:
119         pop     acc
120         push    ar0
121         mov     r0,dpl
122         mov     @r0,_ap
123         inc     r0
124         mov     @r0,a
125         sjmp    00015$
126
127  00012$:
128         mov     a, _ap
129         movx    @dptr,a
130         inc     dptr
131         pop     acc
132         movx    @dptr,a
133         sjmp    00016$
134
135  00013$:
136         pop     acc    ; do nothing
137         sjmp    00016$
138
139  00014$:
140         pop     acc
141         push    ar0
142         mov     r0,dpl
143         xch     a,_ap
144         movx    @r0,a
145         inc     r0
146         xch     a,_ap
147         movx    @r0, a
148  00015$:
149         inc     dptr
150         pop     ar0
151  00016$:
152     _endasm;
153 }
154
155 #endif