Change from GPL to LPGL
[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 unsigned char _gptrget ()
27 {
28     _asm
29     ;   save values passed
30         xch    a,r0
31         push   acc
32     ;
33     ;   depending on the pointer type
34     ;
35         mov     a,b
36         jz      00001$
37         dec     a
38         jz      00002$
39         dec     a
40         jz      00003$
41         dec     a
42         jz      00004$
43     ;
44     ;   any other value for type 
45     ;   return xFF
46         mov     a,#0xff
47         sjmp    00005$
48     ;
49     ;   Pointer to data space
50     ;   
51  00001$:
52         mov     r0,dpl     ; use only low order address
53         mov     a,@r0
54         sjmp    00005$
55     ;
56     ;   pointer to xternal data
57     ;
58  00002$:
59         movx    a,@dptr
60         sjmp    00005$
61 ;
62 ;   pointer to code area
63 ;   
64  00003$:
65         clr     a
66         movc    a,@a+dptr
67         sjmp    00005$
68 ;
69 ;   pointer to xternal stack
70 ;
71  00004$:
72         mov     r0,dpl
73         movx    a,@r0
74 ;
75 ;   restore and return
76 ;
77  00005$:               
78         mov     r0,a    
79         pop     acc
80         xch     a,r0
81      _endasm ;
82         
83 }