* .version: bumped version to 2.4.7
[fw/sdcc] / device / lib / _gptrgetc.c
1 /*-------------------------------------------------------------------------
2
3   _gptrget.c :- get value for a generic pointer (used with --xram-movc)
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 _gptrgetc (char *gptr) _naked
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      00003$  ; 1 far
45         dec     a
46         jz      00003$  ; 2 code
47         dec     a
48         jz      00004$  ; 3 pdata
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 ;   pointer to code area
67 ;
68  00003$:
69         ; clr     a  is already 0
70         movc    a,@a+dptr
71         sjmp    00005$
72 ;
73 ;   pointer to xternal stack
74 ;
75  00004$:
76         mov     r0,dpl
77         movx    a,@r0
78 ;
79 ;   restore and return
80 ;
81  00005$:
82         mov     r0,a
83         pop     acc
84         xch     a,r0
85         ret
86      _endasm ;
87
88 }