Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic16 / libsdcc / gptr / gptrget1.c
1 /*-------------------------------------------------------------------------
2
3    gptrget1.c :- get 1 byte value from generic pointer
4
5    Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
6
7              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
8
9    This library is free software; you can redistribute it and/or modify it
10    under the terms of the GNU Library General Public License as published by the
11    Free Software Foundation; either version 2, or (at your option) any
12    later version.
13
14    This library is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU Library General Public License for more details.
18
19    You should have received a copy of the GNU Library General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23    In other words, you are welcome to use, share and improve this program.
24    You are forbidden to forbid anyone else to use, share and improve
25    what you give them.   Help stamp out software-hoarding!
26 -------------------------------------------------------------------------*/
27 /*
28 ** $Id: gptrget1.c 3714 2005-04-02 13:13:53Z vrokas $
29 */
30
31 /* the return value is expected to be in WREG, therefore we choose return
32  * type void here. Generic pointer is expected to be in WREG:PRODL:FSR0L,
33  * so function arguments are void, too */
34
35 extern POSTINC0;
36 extern POSTINC1;
37 extern PREINC1;
38 extern INDF0;
39 extern FSR0L;
40 extern FSR0H;
41 extern WREG;
42 extern TBLPTRL;
43 extern TBLPTRH;
44 extern TBLPTRU;
45 extern TABLAT;
46 extern PRODL;
47
48
49 void _gptrget1(void) __naked
50 {
51   __asm
52     /* decode generic pointer MSB (in WREG) bits 6 and 7:
53      * 00 -> code
54      * 01 -> EEPROM
55      * 10 -> data
56      * 11 -> unimplemented
57      */
58     btfss       _WREG, 7
59     bra         _lab_01_
60     
61     ; data pointer
62     ; data are already in FSR0
63     movff       _PRODL, _FSR0H    
64
65     movf        _POSTINC0, w
66
67     return
68     
69
70 _lab_01_:
71     ; code or eeprom
72     btfsc       _WREG, 6
73     bra         _lab_02_
74     
75     ; code pointer
76     movff       _FSR0L, _TBLPTRL
77     movff       _PRODL, _TBLPTRH
78     movwf       _TBLPTRU
79     
80     tblrd*+
81     
82     ; result in WREG
83     movf        _TABLAT, w
84     
85     return 
86   
87 _lab_02_:
88     ; EEPROM pointer
89
90     ; unimplemented yet
91
92 _end_:
93
94   return
95   __endasm;
96 }