fix return values
[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$
46         dec     a       ; 4 skip generic pointer
47         dec     a
48         jz      00001$  ; 5 idata
49         pop     acc
50         sjmp    00006$
51 ;
52 ;       store into near space
53 ;
54  00001$:
55         pop     acc
56         push    ar0
57         mov     r0,dpl
58         mov     @r0,a
59         sjmp    00005$
60
61  00002$:
62         pop     acc
63         movx    @dptr,a
64         sjmp    00006$
65
66  00003$:
67         pop     acc    ; do nothing
68         sjmp    00006$
69
70  00004$:
71         pop     acc
72         push    ar0
73         mov     r0,dpl
74         movx    @r0,a
75  00005$:
76         pop     ar0
77  00006$:
78 _endasm;
79 }
80
81 #ifdef SDCC_ds390
82 void
83 _gptrputWord ()
84 {
85     _asm
86         push     acc
87     ;
88     ;   depending on the pointer type acc. to SDCCsymt.h
89     ;
90         mov     a,b
91         jz      00011$  ; 0 near
92         dec     a
93         jz      00012$  ; 1 far
94         dec     a
95         jz      00013$  ; 2 code
96         dec     a
97         jz      00014$
98         dec     a       ; 4 skip generic pointer
99         dec     a
100         jz      00011$  ; 5 idata
101         pop     acc
102         sjmp    00016$
103 ;
104 ;       store into near space
105 ;
106  00011$:
107         pop     acc
108         push    ar0
109         mov     r0,dpl
110         mov     @r0,_ap
111         inc     r0
112         mov     @r0,a
113         sjmp    00015$
114
115  00012$:
116         mov     a, _ap
117         movx    @dptr,a
118         inc     dptr
119         pop     acc
120         movx    @dptr,a
121         sjmp    00016$
122
123  00013$:
124         pop     acc    ; do nothing
125         sjmp    00016$
126
127  00014$:
128         pop     acc
129         push    ar0
130         mov     r0,dpl
131         xch     a,_ap
132         movx    @r0,a
133         inc     r0
134         xch     a,_ap
135         movx    @r0, a
136  00015$:        
137         inc     dptr
138         pop     ar0
139  00016$:        
140     _endasm;
141 }
142
143 #endif