* sdcc/sim/device/lib/_gptrget.c: mem region 5 (idata) added
[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 acc. to SDCCsymt.h
34     ;
35         mov     a,b
36         jz      00001$  ; 0 near
37         dec     a
38         jz      00002$  ; 1 far
39         dec     a
40         jz      00003$  ; 2 code
41         dec     a
42         jz      00004$
43         dec     a       ; 4 skip generic pointer
44         dec     a
45         jz      00001$  ; 5 idata
46     ;
47     ;   any other value for type
48     ;   return xFF
49         mov     a,#0xff
50         sjmp    00005$
51     ;
52     ;   Pointer to data space
53     ;
54  00001$:
55         mov     r0,dpl     ; use only low order address
56         mov     a,@r0
57         sjmp    00005$
58     ;
59     ;   pointer to xternal data
60     ;
61  00002$:
62         movx    a,@dptr
63         sjmp    00005$
64 ;
65 ;   pointer to code area
66 ;
67  00003$:
68         ; clr     a  is already 0
69         movc    a,@a+dptr
70         sjmp    00005$
71 ;
72 ;   pointer to xternal stack
73 ;
74  00004$:
75         mov     r0,dpl
76         movx    a,@r0
77 ;
78 ;   restore and return
79 ;
80  00005$:
81         mov     r0,a
82         pop     acc
83         xch     a,r0
84      _endasm ;
85
86 }