Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic16 / libsdcc / gptr / gptrget2.c
1 /*-------------------------------------------------------------------------
2
3    gptrget2.c :- get 2 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 /*
29 ** $Id: gptrget2.c 3714 2005-04-02 13:13:53Z vrokas $
30 */
31
32 /* the return value is expected to be in WREG:PRODL, therefore we choose return
33  * type void here. Generic pointer is expected to be in WREG:PRODL:FSR0L,
34  * so function arguments are void, too */
35
36 extern POSTINC0;
37 extern INDF0;
38 extern FSR0L;
39 extern FSR0H;
40 extern WREG;
41 extern TBLPTRL;
42 extern TBLPTRH;
43 extern TBLPTRU;
44 extern TABLAT;
45 extern PRODL;
46
47 void _gptrget2(void) __naked
48 {
49   __asm
50     /* decode generic pointer MSB (in WREG) bits 6 and 7:
51      * 00 -> code
52      * 01 -> EEPROM
53      * 10 -> data
54      * 11 -> unimplemented
55      */
56     btfss       _WREG, 7
57     bra         _lab_01_
58     
59     /* data pointer  */
60     /* data are already in FSR0 */
61     movff       _PRODL, _FSR0H
62     
63     movf        _POSTINC0, w
64     movff       _POSTINC0, _PRODL
65     
66     return
67     
68
69 _lab_01_:
70     /* code or eeprom */
71     btfsc       _WREG, 6
72     bra         _lab_02_
73     
74     ; code pointer
75     movff       _FSR0L, _TBLPTRL    
76     movff       _PRODL, _TBLPTRH
77     movwf       _TBLPTRU
78     
79     /* fetch first byte */
80     TBLRD*+
81     movf        _TABLAT, w
82
83     /* fetch second byte  */
84     TBLRD*+
85     movff       _TABLAT, _PRODL
86     
87     return
88  
89   
90 _lab_02_:
91     /* EEPROM pointer */
92
93     /* unimplemented yet */
94
95 _end_:
96
97   return
98   __endasm;
99 }