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