1 /*-------------------------------------------------------------------------
2    gptrput2.c - put 2 byte value at generic pointer
3 
4    Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
5    Adopted for pic16 port by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
6 
7    This library is free software; you can redistribute it and/or modify it
8    under the terms of the GNU 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 General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this library; see the file COPYING. If not, write to the
19    Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20    MA 02110-1301, USA.
21 
22    As a special exception, if you link this library with other files,
23    some of which are compiled with SDCC, to produce an executable,
24    this library does not by itself cause the resulting executable to
25    be covered by the GNU General Public License. This exception does
26    not however invalidate any other reasons why the executable file
27    might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
29 
30 /* write address is expected to be in WREG:PRODL:FSR0L while
31  * write value is in TBLPTRH:TBLPTRL:PRODH:[stack] */
32 
33 extern int FSR0H;
34 extern int POSTINC0;
35 extern int PREINC1;
36 extern int PRODH;
37 extern int PRODL;
38 extern int WREG;
39 extern int __eeprom_gptrput2;
40 
_gptrput2(void)41 void _gptrput2(void) __naked
42 {
43   __asm
44     /* decode generic pointer MSB (in WREG) bits 6 and 7:
45      * 00 -> code (unimplemented)
46      * 01 -> EEPROM
47      * 10 -> data
48      * 11 -> data
49      *
50      * address: (WREG, PRODL, FSR0L)
51      * value: (TBLPTRH, TBLPTRL, PRODH, STACK1[+1])
52      */
53     btfss	_WREG, 7
54     bra		_lab_01_
55 
56     /* data pointer  */
57     /* FSR0L is already set up */
58     movff	_PRODL, _FSR0H
59 
60     movff	_PREINC1, _POSTINC0
61     movff	_PRODH, _POSTINC0
62 
63     return
64 
65 
66 _lab_01_:
67     /* code or eeprom */
68     btfsc	_WREG, 6
69     goto        ___eeprom_gptrput2
70 
71     /* code pointer, cannot write code pointers */
72     return
73 
74   __endasm;
75 }
76