struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / _gptrgetc.c
bloba2f53c731eac27caf543743fe983fc398cdfbc73
1 /*-------------------------------------------------------------------------
2 _gptrgetc.c - get value for a generic pointer (used with --xram-movc)
4 Copyright (c) 1999, Sandeep Dutta . sandeep.dutta@usa.net
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 MA 02110-1301, USA.
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
30 /* the return value is expected to be in acc, and not in the standard
31 * location dpl. Therefore we choose return type void here: */
33 #if 1
35 void
36 _gptrgetc (char *gptr) __naked
38 /* This is the new version with pointers up to 16 bits.
39 B cannot be trashed */
41 gptr; /* hush the compiler */
43 __asm
44 ; save values passed
46 ; depending on the pointer type acc. to SDCCsymt.h
48 jb _B_7,codeptr$ ; >0x80 code ; 3
49 jnb _B_6,xdataptr$ ; <0x40 far ; 3
51 mov dph,r0 ; save r0 independent of regbank ; 2
52 mov r0,dpl ; use only low order address ; 2
54 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
56 ; Pointer to data space
58 mov a,@r0 ; 1
59 mov r0,dph ; restore r0 ; 2
60 mov dph,#0 ; restore dph ; 2
61 ret ; 1
63 ; pointer to external stack or pdata
65 pdataptr$:
66 movx a,@r0 ; 1
67 mov r0,dph ; restore r0 ; 2
68 mov dph,#0 ; restore dph ; 2
69 ret ; 1
71 ; pointer to xternal data
72 ; pointer to code area
74 codeptr$:
75 xdataptr$:
76 clr a ; 1
77 movc a,@a+dptr ; 1
78 ret ; 1
79 ;===
80 ;28 bytes
81 __endasm;
84 #else
86 void
87 _gptrgetc (char *gptr) __naked
89 gptr; /* hush the compiler */
91 __asm
92 ; save values passed
93 xch a,r0
94 push acc
96 ; depending on the pointer type acc. to SDCCsymt.h
98 mov a,b
99 jz 00001$ ; 0 near
100 dec a
101 jz 00003$ ; 1 far
102 dec a
103 jz 00003$ ; 2 code
104 dec a
105 jz 00004$ ; 3 pdata
106 dec a ; 4 skip generic pointer
107 dec a
108 jz 00001$ ; 5 idata
110 ; any other value for type
111 ; return xFF
112 mov a,#0xff
115 ; Pointer to data space
117 00001$:
118 mov r0,dpl ; use only low order address
119 mov a,@r0
122 ; pointer to xternal data
123 ; pointer to code area
125 00003$:
126 ; clr a is already 0
127 movc a,@a+dptr
130 ; pointer to xternal stack
132 00004$:
133 mov r0,dpl
134 movx a,@r0
136 ; restore and return
138 mov r0,a
139 pop acc
140 xch a,r0
142 __endasm;
145 #endif