* device/lib/pic16/libsdcc/gptr/{*.c, Makefile}: NEW
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 1 Oct 2004 14:57:24 +0000 (14:57 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 1 Oct 2004 14:57:24 +0000 (14:57 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3514 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/pic16/libsdcc/gptr/Makefile [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrget1.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrget2.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrget3.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrget4.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrput1.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrput2.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrput3.c [new file with mode: 0644]
device/lib/pic16/libsdcc/gptr/gptrput4.c [new file with mode: 0644]

diff --git a/device/lib/pic16/libsdcc/gptr/Makefile b/device/lib/pic16/libsdcc/gptr/Makefile
new file mode 100644 (file)
index 0000000..9e36970
--- /dev/null
@@ -0,0 +1,30 @@
+#
+# Makefile - Makefile to build pic16 generic pointer support library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+#      Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+
+SRCS   =       gptrget1 \
+               gptrget2 \
+               gptrget3 \
+               gptrget4 \
+               gptrput1 \
+               gptrput2 \
+               gptrput3 \
+               gptrput4
+               
+
+include ../Makefile.rules
+
+all: build-library
+
+build-library: $(OFILES)
+#      @$(CP) -v $(OFILES) ../../bin
diff --git a/device/lib/pic16/libsdcc/gptr/gptrget1.c b/device/lib/pic16/libsdcc/gptr/gptrget1.c
new file mode 100644 (file)
index 0000000..084ccae
--- /dev/null
@@ -0,0 +1,93 @@
+/*-------------------------------------------------------------------------
+
+   gptrget1.c :- get 1 byte value from generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+/*
+** $Id$
+*/
+
+/* the return value is expected to be in WREG, therefore we choose return
+ * type void here. Generic pointer is expected to be in WREG:FSR0H:FSR0L,
+ * so function arguments are void, too */
+
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+
+void _gptrget1(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code
+     * 01 -> EEPROM
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+
+    /* debug info */
+    movf       _POSTINC0, w
+
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    ; code pointer
+    movwf      _TBLPTRU
+    movff      _FSR0L, _TBLPTRL    
+    movff      _FSR0H, _TBLPTRH
+    
+    TBLRD*
+    
+    /* result in TBLAT */
+    movf       _TABLAT, w
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrget2.c b/device/lib/pic16/libsdcc/gptr/gptrget2.c
new file mode 100644 (file)
index 0000000..c16581f
--- /dev/null
@@ -0,0 +1,96 @@
+/*-------------------------------------------------------------------------
+
+   gptrget2.c :- get 2 byte value from generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* the return value is expected to be in WREG:PRODL, therefore we choose return
+ * type void here. Generic pointer is expected to be in WREG:FSR0H:FSR0L,
+ * so function arguments are void, too */
+
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+
+void _gptrget2(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code
+     * 01 -> EEPROM
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movf       _POSTINC0, w
+    movff      _POSTINC0, _PRODL
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    ; code pointer
+    movwf      _TBLPTRU
+    movff      _FSR0L, _TBLPTRL    
+    movff      _FSR0H, _TBLPTRH
+    
+    /* fetch first byte */
+    TBLRD*+
+    movf       _TABLAT, w
+
+    /* fetch second byte  */
+    TBLRD*+
+    movff      _TABLAT, _PRODL
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrget3.c b/device/lib/pic16/libsdcc/gptr/gptrget3.c
new file mode 100644 (file)
index 0000000..0e5d586
--- /dev/null
@@ -0,0 +1,102 @@
+/*-------------------------------------------------------------------------
+
+   gptrget3.c :- get 3 byte value from generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* the return value is expected to be in WREG:PRODL:PRODH, therefore we choose return
+ * type void here. Generic pointer is expected to be in WREG:FSR0H:FSR0L,
+ * so function arguments are void, too */
+
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+extern PRODH;
+
+void _gptrget3(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code
+     * 01 -> EEPROM
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movf       _POSTINC0, w
+    movff      _POSTINC0, _PRODL
+    movff      _POSTINC0, _PRODH
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    ; code pointer
+    movwf      _TBLPTRU
+    movff      _FSR0L, _TBLPTRL    
+    movff      _FSR0H, _TBLPTRH
+    
+    /* fetch first byte */
+    TBLRD*+
+    movf       _TABLAT, w
+
+    /* fetch second byte  */
+    TBLRD*+
+    movff      _TABLAT, _PRODL
+    
+    /* fetch third byte */
+    TBLRD*+
+    movff      _TABLAT, _PRODH
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrget4.c b/device/lib/pic16/libsdcc/gptr/gptrget4.c
new file mode 100644 (file)
index 0000000..74f0a2c
--- /dev/null
@@ -0,0 +1,107 @@
+/*-------------------------------------------------------------------------
+
+   gptrget4.c :- get 4 byte value from generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* the return value is expected to be in WREG:PRODL, therefore we choose return
+ * type void here. Generic pointer is expected to be in WREG:FSR0H:FSR0L,
+ * so function arguments are void, too */
+
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+extern PRODH;
+
+void _gptrget4(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code
+     * 01 -> EEPROM
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movf       _POSTINC0, w
+    movff      _POSTINC0, _PRODL
+    movff      _POSTINC0, _PRODH
+    movff      _POSTINC0, _FSR0L
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    ; code pointer
+    movwf      _TBLPTRU
+    movff      _FSR0L, _TBLPTRL    
+    movff      _FSR0H, _TBLPTRH
+    
+    /* fetch first byte */
+    TBLRD*+
+    movf       _TABLAT, w
+
+    /* fetch second byte  */
+    TBLRD*+
+    movff      _TABLAT, _PRODL
+    
+    /* fetch third byte */
+    TBLRD*+
+    movff      _TABLAT, _PRODH
+    
+    /* fetch fourth byte */
+    TBLRD*+
+    movff      _TABLAT, _FSR0L
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrput1.c b/device/lib/pic16/libsdcc/gptr/gptrput1.c
new file mode 100644 (file)
index 0000000..edda1e9
--- /dev/null
@@ -0,0 +1,84 @@
+/*-------------------------------------------------------------------------
+
+   gptrput1.c :- put 1 byte value at generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* write address is expected to be in WREG:FSR0H:FSR0L while
+ * write value is in TBLPTRL:TBLPTRH:PRODH:PRODL */
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+extern PRODH;
+
+void _gptrput1(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code (unimplemented)
+     * 01 -> EEPROM (unimplemented)
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movff      _PRODL, _POSTINC0
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    /* code pointer, cannot write code pointers */
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrput2.c b/device/lib/pic16/libsdcc/gptr/gptrput2.c
new file mode 100644 (file)
index 0000000..58e2daa
--- /dev/null
@@ -0,0 +1,85 @@
+/*-------------------------------------------------------------------------
+
+   gptrput1.c :- put 1 byte value at generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* write address is expected to be in WREG:FSR0H:FSR0L while
+ * write value is in TBLPTRL:TBLPTRH:PRODH:PRODL */
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+extern PRODH;
+
+void _gptrput2(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code (unimplemented)
+     * 01 -> EEPROM (unimplemented)
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movff      _PRODL, _POSTINC0
+    movff      _PRODH, _POSTINC0
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    /* code pointer, cannot write code pointers */
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrput3.c b/device/lib/pic16/libsdcc/gptr/gptrput3.c
new file mode 100644 (file)
index 0000000..7ce8762
--- /dev/null
@@ -0,0 +1,86 @@
+/*-------------------------------------------------------------------------
+
+   gptrput1.c :- put 1 byte value at generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* write address is expected to be in WREG:FSR0H:FSR0L while
+ * write value is in TBLPTRH:TBLPTRL:PRODH:PRODL */
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+extern PRODH;
+
+void _gptrput3(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code (unimplemented)
+     * 01 -> EEPROM (unimplemented)
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movff      _PRODL, _POSTINC0
+    movff      _PRODH, _POSTINC0
+    movff      _TBLPTRL, _POSTINC0
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    /* code pointer, cannot write code pointers */
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}
diff --git a/device/lib/pic16/libsdcc/gptr/gptrput4.c b/device/lib/pic16/libsdcc/gptr/gptrput4.c
new file mode 100644 (file)
index 0000000..adf5a8f
--- /dev/null
@@ -0,0 +1,87 @@
+/*-------------------------------------------------------------------------
+
+   gptrput1.c :- put 1 byte value at generic pointer
+
+   Adopted for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   In other words, you are welcome to use, share and improve this program.
+   You are forbidden to forbid anyone else to use, share and improve
+   what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+/*
+** $Id$
+*/
+
+/* write address is expected to be in WREG:FSR0H:FSR0L while
+ * write value is in TBLPTRH:TBLPTRL:PRODH:PRODL */
+extern POSTINC0;
+extern INDF0;
+extern FSR0L;
+extern FSR0H;
+extern WREG;
+extern TBLPTRL;
+extern TBLPTRH;
+extern TBLPTRU;
+extern TABLAT;
+extern PRODL;
+extern PRODH;
+
+void _gptrput4(void)
+{
+  _asm
+    /* decode generic pointer MSB (in WREG) bits 6 and 7:
+     * 00 -> code (unimplemented)
+     * 01 -> EEPROM (unimplemented)
+     * 10 -> data
+     * 11 -> unimplemented
+     */
+    btfss      _WREG, 7
+    goto       _lab_01_
+    
+    /* data pointer  */
+    /* data are already in FSR0 */
+    movff      _PRODL, _POSTINC0
+    movff      _PRODH, _POSTINC0
+    movff      _TBLPTRL, _POSTINC0
+    movff      _TBLPTRH, _POSTINC0
+    
+    goto _end_
+    
+
+_lab_01_:
+    /* code or eeprom */
+    btfsc      _WREG, 6
+    goto       _lab_02_
+    
+    /* code pointer, cannot write code pointers */
+    
+    goto _end_
+  
+_lab_02_:
+    /* EEPROM pointer */
+
+    /* unimplemented yet */
+
+_end_:
+
+  _endasm;
+}