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