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