Merge pull request #45 from linuxuser27/support2017
[debian/pforth] / csrc / pf_save.h
1 /* @(#) pf_save.h 96/12/18 1.8 */
2 #ifndef _pforth_save_h
3 #define _pforth_save_h
4
5 /***************************************************************
6 ** Include file for PForth SaveForth
7 **
8 ** Author: Phil Burk
9 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
10 **
11 ** The pForth software code is dedicated to the public domain,
12 ** and any third party may reproduce, distribute and modify
13 ** the pForth software code or any derivative works thereof
14 ** without any compensation or license.  The pForth software
15 ** code is provided on an "as is" basis without any warranty
16 ** of any kind, including, without limitation, the implied
17 ** warranties of merchantability and fitness for a particular
18 ** purpose and their equivalents under the laws of any jurisdiction.
19 **
20 **  941031  rdg     fix redefinition of MAKE_ID and EVENUP to be conditional
21 **
22 ***************************************************************/
23
24
25 typedef struct DictionaryInfoChunk
26 {
27 /* All fields are stored in BIG ENDIAN format for consistency in data files.
28  * All fields must be the same size for easy endian conversion.
29  * All fields must be 32 bit for file compatibility with older versions.
30  */
31     int32_t  sd_Version;
32     int32_t  sd_RelContext;      /* relative ptr to Dictionary Context */
33     int32_t  sd_RelHeaderPtr;    /* relative ptr to Dictionary Header Ptr */
34     int32_t  sd_RelCodePtr;      /* relative ptr to Dictionary Header Ptr */
35     int32_t  sd_EntryPoint;  /* relative ptr to entry point or NULL */
36     int32_t  sd_UserStackSize;   /* in bytes */
37     int32_t  sd_ReturnStackSize; /* in bytes */
38     int32_t  sd_NameSize;        /* in bytes */
39     int32_t  sd_CodeSize;        /* in bytes */
40     int32_t  sd_NumPrimitives;   /* To distinguish between primitive and secondary. */
41     uint32_t sd_Flags;
42     int32_t  sd_FloatSize;       /* In bytes. Must match code. 0 means no floats. */
43     int32_t  sd_CellSize;        /* In bytes. Must match code. */
44 } DictionaryInfoChunk;
45
46 /* Bits in sd_Flags */
47 #define SD_F_BIG_ENDIAN_DIC    (1<<0)
48
49 #ifndef MAKE_ID
50 #define MAKE_ID(a,b,c,d) ((((uint32_t)a)<<24)|(((uint32_t)b)<<16)|(((uint32_t)c)<<8)|((uint32_t)d))
51 #endif
52
53 #define ID_FORM MAKE_ID('F','O','R','M')
54 #define ID_P4TH MAKE_ID('P','4','T','H')
55 #define ID_P4DI MAKE_ID('P','4','D','I')
56 #define ID_P4NM MAKE_ID('P','4','N','M')
57 #define ID_P4CD MAKE_ID('P','4','C','D')
58 #define ID_BADF MAKE_ID('B','A','D','F')
59
60 #ifndef EVENUP
61 #define EVENUP(n) ((n+1)&(~1))
62 #endif
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, cell_t CodeSize );
69
70 /* Endian-ness tools. */
71 int    IsHostLittleEndian( void );
72
73 ucell_t ReadCellBigEndian( const uint8_t *addr );
74 uint32_t Read32BigEndian( const uint8_t *addr );
75 uint16_t Read16BigEndian( const uint8_t *addr );
76
77 ucell_t ReadCellLittleEndian( const uint8_t *addr );
78 uint32_t Read32LittleEndian( const uint8_t *addr );
79 uint16_t Read16LittleEndian( const uint8_t *addr );
80
81 void WriteCellBigEndian( uint8_t *addr, ucell_t data );
82 void Write32BigEndian( uint8_t *addr, uint32_t data );
83 void Write16BigEndian( uint8_t *addr, uint16_t data );
84
85 void WriteCellLittleEndian( uint8_t *addr, ucell_t data );
86 void Write32LittleEndian( uint8_t *addr, uint32_t data );
87 void Write16LittleEndian( uint8_t *addr, uint16_t data );
88
89 #ifdef PF_SUPPORT_FP
90 void WriteFloatBigEndian( PF_FLOAT *addr, PF_FLOAT data );
91 PF_FLOAT ReadFloatBigEndian( const PF_FLOAT *addr );
92 void WriteFloatLittleEndian( PF_FLOAT *addr, PF_FLOAT data );
93 PF_FLOAT ReadFloatLittleEndian( const PF_FLOAT *addr );
94 #endif
95
96 #ifdef __cplusplus
97 }
98 #endif
99
100 #endif /* _pforth_save_h */