saving some cycles in generic pointer get
[fw/sdcc] / device / lib / _gptrget.c
1 /*-------------------------------------------------------------------------
2
3   _gptrget.c :- get 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
27 /* the  return value is expected to be in acc, and not in the standard
28  * location dpl. Therefore we choose return type void here: */
29 void
30 _gptrget (char *gptr)
31 {
32     gptr; /* hush the compiler */
33         
34     _asm
35     ;   save values passed
36     ;
37     ;   depending on the pointer type acc. to SDCCsymt.h
38     ;
39         mov     a,b
40         jz      00001$  ; 0 near
41         dec     a
42         jz      00002$  ; 1 far
43         dec     a
44         jz      00003$  ; 2 code
45         dec     a
46         jz      00004$
47         dec     a       ; 4 skip generic pointer
48         dec     a
49         jz      00001$  ; 5 idata
50     ;
51     ;   any other value for type
52     ;   return xFF
53         mov     a,#0xff
54         sjmp    00005$
55     ;
56     ;   Pointer to data space
57     ;
58  00001$:
59         push    ar0
60         ;
61         mov     r0,dpl     ; use only low order address
62         mov     a,@r0
63         ;
64         pop     ar0
65         ;
66         sjmp    00005$
67     ;
68     ;   pointer to xternal data
69     ;
70  00002$:
71         movx    a,@dptr
72         sjmp    00005$
73 ;
74 ;   pointer to code area
75 ;
76  00003$:
77         ; clr     a  is already 0
78         movc    a,@a+dptr
79         sjmp    00005$
80 ;
81 ;   pointer to xternal stack
82 ;
83  00004$:
84         mov     dph,p2          ; p2 holds high byte for pdata access
85         movx    a,@dptr
86 ;
87 ;   return
88 ;
89  00005$:
90      _endasm ;
91 }
92
93 #ifdef SDCC_ds390
94 /* the  return value is expected to be in acc/_ap, and not in the standard
95  * location dpl/dph. Therefore we choose return type void here: */
96 void
97 _gptrgetWord (unsigned *gptr)
98 {
99     gptr; /* hush the compiler */
100
101     _asm
102     ;
103     ;   depending on the pointer type acc. to SDCCsymt.h
104     ;
105         mov     a,b
106         jz      00001$  ; 0 near
107         dec     a
108         jz      00002$  ; 1 far
109         dec     a
110         jz      00003$  ; 2 code
111         dec     a
112         jz      00004$
113         dec     a       ; 4 skip generic pointer
114         dec     a
115         jz      00001$  ; 5 idata
116     ;
117     ;   any other value for type
118     ;   return xFF
119         mov     a,#0xff
120         sjmp    00006$
121     ;
122     ;   Pointer to data space
123     ;
124  00001$:
125         push    ar0
126         mov     r0,dpl     ; use only low order address
127         mov     _ap,@r0
128         inc     r0
129         mov     a,@r0
130         inc     dpl
131         sjmp    00005$
132     ;
133     ;   pointer to xternal data
134     ;
135  00002$:
136         movx    a,@dptr
137         mov     _ap,a
138         inc     dptr
139         movx    a,@dptr
140         sjmp    00006$
141 ;
142 ;   pointer to code area
143 ;
144  00003$:
145         ; clr     a  is already 0
146         movc    a,@a+dptr
147         mov     _ap,a
148         clr     a
149         inc     dptr
150         movc    a,@a+dptr
151         sjmp    00006$
152 ;
153 ;   pointer to xternal stack
154 ;
155  00004$:
156         push    ar0
157         mov     r0,dpl
158         movx    a,@r0
159         mov     _ap,a
160         inc     r0
161         movx    a,@r0
162         inc     dpl
163 ;
164 ;   restore and return
165 ;
166 00005$:
167     pop ar0
168 00006$: 
169      _endasm ;
170
171 }
172 #endif