DS800C400 fun, improved ROM interface and tinibios
[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         xch    a,r0
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$
49         dec     a       ; 4 skip generic pointer
50         dec     a
51         jz      00001$  ; 5 idata
52     ;
53     ;   any other value for type
54     ;   return xFF
55         mov     a,#0xff
56         sjmp    00005$
57     ;
58     ;   Pointer to data space
59     ;
60  00001$:
61         mov     r0,dpl     ; use only low order address
62         mov     a,@r0
63         sjmp    00005$
64     ;
65     ;   pointer to xternal data
66     ;
67  00002$:
68         movx    a,@dptr
69         sjmp    00005$
70 ;
71 ;   pointer to code area
72 ;
73  00003$:
74         ; clr     a  is already 0
75         movc    a,@a+dptr
76         sjmp    00005$
77 ;
78 ;   pointer to xternal stack
79 ;
80  00004$:
81         mov     r0,dpl
82         movx    a,@r0
83 ;
84 ;   restore and return
85 ;
86  00005$:
87         mov     r0,a
88         pop     acc
89         xch     a,r0
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