f7aadc331f43acb9cc40fb19aac09a77bc8a7502
[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)
35 {
36     gptr; c; /* hush the compiler */
37
38     _asm
39         push     acc
40     ;
41     ;   depending on the pointer type acc. to SDCCsymt.h
42     ;
43         mov     a,b
44         jz      00001$  ; 0 near
45         dec     a
46         jz      00002$  ; 1 far
47         dec     a
48         jz      00003$  ; 2 code
49         dec     a
50         jz      00004$  ; 3 pdata
51         dec     a       ; 4 skip generic pointer
52         dec     a
53         jz      00001$  ; 5 idata
54
55  00003$:
56         pop     acc    ; do nothing
57         sjmp    00005$
58 ;
59 ;       store into near space
60 ;
61  00001$:
62         pop     acc
63         push    ar0
64         mov     r0,dpl
65         mov     @r0,a
66         pop     ar0
67         sjmp    00005$
68
69  00002$:
70         pop     acc
71         movx    @dptr,a
72         sjmp    00005$
73
74  00004$:
75 #if USE_PDATA_PAGING_REGISTER
76         pop     acc
77         mov     dph,__XPAGE     ; __XPAGE (usually p2) holds high byte for pdata access
78         movx    @dptr,a
79 #else
80         pop     acc
81         push    ar0
82         mov     r0,dpl
83         movx    @r0,a
84         pop     ar0
85 #endif
86
87  00005$:
88 _endasm;
89 }
90
91 #ifdef SDCC_ds390
92 void
93 _gptrputWord ()
94 {
95     _asm
96         push     acc
97     ;
98     ;   depending on the pointer type acc. to SDCCsymt.h
99     ;
100         mov     a,b
101         jz      00011$  ; 0 near
102         dec     a
103         jz      00012$  ; 1 far
104         dec     a
105         jz      00013$  ; 2 code
106         dec     a
107         jz      00014$  ; 3 pdata
108         dec     a       ; 4 skip generic pointer
109         dec     a
110         jz      00011$  ; 5 idata
111         pop     acc
112         sjmp    00016$
113 ;
114 ;       store into near space
115 ;
116  00011$:
117         pop     acc
118         push    ar0
119         mov     r0,dpl
120         mov     @r0,_ap
121         inc     r0
122         mov     @r0,a
123         sjmp    00015$
124
125  00012$:
126         mov     a, _ap
127         movx    @dptr,a
128         inc     dptr
129         pop     acc
130         movx    @dptr,a
131         sjmp    00016$
132
133  00013$:
134         pop     acc    ; do nothing
135         sjmp    00016$
136
137  00014$:
138         pop     acc
139         push    ar0
140         mov     r0,dpl
141         xch     a,_ap
142         movx    @r0,a
143         inc     r0
144         xch     a,_ap
145         movx    @r0, a
146  00015$:
147         inc     dptr
148         pop     ar0
149  00016$:
150     _endasm;
151 }
152
153 #endif