minor work
[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 unsigned char _gptrgetc ()
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      00003$  ; 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 ;   pointer to code area
61 ;
62  00003$:
63         ; clr     a  is already 0
64         movc    a,@a+dptr
65         sjmp    00005$
66 ;
67 ;   pointer to xternal stack
68 ;
69  00004$:
70         mov     r0,dpl
71         movx    a,@r0
72 ;
73 ;   restore and return
74 ;
75  00005$:
76         mov     r0,a
77         pop     acc
78         xch     a,r0
79      _endasm ;
80
81 }