1 /* @(#) pfcustom.c 98/01/26 1.3 */
5 /***************************************************************
6 ** Call Custom Functions for pForth
8 ** Create a file similar to this and compile it into pForth
9 ** by setting -DPF_USER_CUSTOM="mycustom.c"
11 ** Using this, you could, for example, call X11 from Forth.
12 ** See "pf_cglue.c" for more information.
15 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
17 ** Permission to use, copy, modify, and/or distribute this
18 ** software for any purpose with or without fee is hereby granted.
20 ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
21 ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
22 ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
23 ** THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
24 ** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
25 ** FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
26 ** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27 ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 ***************************************************************/
34 static cell_t CTest0( cell_t Val );
35 static void CTest1( cell_t Val1, cell_t Val2 );
37 /****************************************************************
38 ** Step 1: Put your own special glue routines here
39 ** or link them in from another file or library.
40 ****************************************************************/
41 static cell_t CTest0( cell_t Val )
43 MSG_NUM_D("CTest0: Val = ", Val);
47 static void CTest1( cell_t Val1, cell_t Val2 )
50 MSG("CTest1: Val1 = "); ffDot(Val1);
51 MSG_NUM_D(", Val2 = ", Val2);
54 /****************************************************************
55 ** Step 2: Create CustomFunctionTable.
56 ** Do not change the name of CustomFunctionTable!
57 ** It is used by the pForth kernel.
58 ****************************************************************/
60 #ifdef PF_NO_GLOBAL_INIT
62 ** If your loader does not support global initialization, then you
63 ** must define PF_NO_GLOBAL_INIT and provide a function to fill
64 ** the table. Some embedded system loaders require this!
65 ** Do not change the name of LoadCustomFunctionTable()!
66 ** It is called by the pForth kernel.
68 #define NUM_CUSTOM_FUNCTIONS (2)
69 CFunc0 CustomFunctionTable[NUM_CUSTOM_FUNCTIONS];
71 Err LoadCustomFunctionTable( void )
73 CustomFunctionTable[0] = CTest0;
74 CustomFunctionTable[1] = CTest1;
80 ** If your loader supports global initialization (most do.) then just
81 ** create the table like this.
83 CFunc0 CustomFunctionTable[] =
90 /****************************************************************
91 ** Step 3: Add custom functions to the dictionary.
92 ** Do not change the name of CompileCustomFunctions!
93 ** It is called by the pForth kernel.
94 ****************************************************************/
96 #if (!defined(PF_NO_INIT)) && (!defined(PF_NO_SHELL))
97 Err CompileCustomFunctions( void )
101 /* Compile Forth words that call your custom functions.
102 ** Make sure order of functions matches that in LoadCustomFunctionTable().
103 ** Parameters are: Name in UPPER CASE, Function, Index, Mode, NumParams
105 err = CreateGlueToC( "CTEST0", i++, C_RETURNS_VALUE, 1 );
106 if( err < 0 ) return err;
107 err = CreateGlueToC( "CTEST1", i++, C_RETURNS_VOID, 2 );
108 if( err < 0 ) return err;
113 Err CompileCustomFunctions( void ) { return 0; }
116 /****************************************************************
117 ** Step 4: Recompile using compiler option PF_USER_CUSTOM
118 ** and link with your code.
119 ** Then rebuild the Forth using "pforth -i system.fth"
120 ** Test: 10 Ctest0 ( should print message then '11' )
121 ****************************************************************/
123 #endif /* PF_USER_CUSTOM */