V25 with 64-bit support
[pforth] / csrc / pf_save.c
index 410a2ae..6a9d195 100644 (file)
 **            of names and code was the same when saved and reloaded.\r
 ** 940228 PLB Added PF_NO_FILEIO version\r
 ** 961204 PLB Added PF_STATIC_DIC\r
 **            of names and code was the same when saved and reloaded.\r
 ** 940228 PLB Added PF_NO_FILEIO version\r
 ** 961204 PLB Added PF_STATIC_DIC\r
-** 000623 PLB Cast chars as uint32 before shifting for 16 bit systems.\r
+** 000623 PLB Cast chars as ucell_t before shifting for 16 bit systems.\r
 ***************************************************************/\r
 \r
 ***************************************************************/\r
 \r
+#include <assert.h>\r
+\r
 #include "pf_all.h"\r
 \r
 /* If no File I/O, then force static dictionary. */\r
 #include "pf_all.h"\r
 \r
 /* If no File I/O, then force static dictionary. */\r
@@ -65,41 +67,72 @@ Chunks
 \r
 /***************************************************************/\r
 /* Endian-ness tools. */\r
 \r
 /***************************************************************/\r
 /* Endian-ness tools. */\r
-uint32 ReadLongBigEndian( const uint32 *addr )\r
+ucell_t ReadCellBigEndian( const uint8_t *addr )\r
 {\r
 {\r
-       const unsigned char *bp = (const unsigned char *) addr;\r
-/* We must cast char to uint32 before shifting because\r
-** of systems with 16 bit ints. 000623 */\r
-       uint32 temp = ((uint32)bp[0])<<24;\r
-       temp |= ((uint32)bp[1])<<16;\r
-       temp |= ((uint32)bp[2])<<8;\r
-       temp |= ((uint32)bp[3]);\r
+       ucell_t temp = (ucell_t)addr[0];\r
+       temp = (temp << 8) | ((ucell_t)addr[1]);\r
+       temp = (temp << 8) | ((ucell_t)addr[2]);\r
+       temp = (temp << 8) | ((ucell_t)addr[3]);\r
+       if( sizeof(ucell_t) == 8 )\r
+       {\r
+               temp = (temp << 8) | ((ucell_t)addr[4]);\r
+               temp = (temp << 8) | ((ucell_t)addr[5]);\r
+               temp = (temp << 8) | ((ucell_t)addr[6]);\r
+               temp = (temp << 8) | ((ucell_t)addr[7]);\r
+       }\r
+               \r
        return temp;\r
 }\r
 /***************************************************************/\r
        return temp;\r
 }\r
 /***************************************************************/\r
-uint16 ReadShortBigEndian( const uint16 *addr )\r
+/* Endian-ness tools. */\r
+uint32_t Read32BigEndian( const uint8_t *addr )\r
 {\r
 {\r
-       const unsigned char *bp = (const unsigned char *) addr;\r
-       return (uint16) ((bp[0]<<8) | bp[1]);\r
+       uint32_t temp = (uint32_t)addr[0];\r
+       temp = (temp << 8) | ((uint32_t)addr[1]);\r
+       temp = (temp << 8) | ((uint32_t)addr[2]);\r
+       temp = (temp << 8) | ((uint32_t)addr[3]);\r
+       return temp;\r
 }\r
 \r
 /***************************************************************/\r
 }\r
 \r
 /***************************************************************/\r
-uint32 ReadLongLittleEndian( const uint32 *addr )\r
+uint16_t Read16BigEndian( const uint8_t *addr )\r
 {\r
 {\r
-       const unsigned char *bp = (const unsigned char *) addr;\r
-/* We must cast char to uint32 before shifting because\r
-** of systems with 16 bit ints. 000623 */\r
-       uint32 temp = ((uint32)bp[3])<<24;\r
-       temp |= ((uint32)bp[2])<<16;\r
-       temp |= ((uint32)bp[1])<<8;\r
-       temp |= ((uint32)bp[0]);\r
+       return (uint16_t) ((addr[0]<<8) | addr[1]);\r
+}\r
+\r
+/***************************************************************/\r
+ucell_t ReadCellLittleEndian( const uint8_t *addr )\r
+{\r
+       ucell_t temp = 0;\r
+       if( sizeof(ucell_t) == 8 )\r
+       {\r
+               temp = (temp << 8) | ((uint32_t)addr[7]);\r
+               temp = (temp << 8) | ((uint32_t)addr[6]);\r
+               temp = (temp << 8) | ((uint32_t)addr[5]);\r
+               temp = (temp << 8) | ((uint32_t)addr[4]);\r
+       }\r
+       temp = (temp << 8) | ((uint32_t)addr[3]);\r
+       temp = (temp << 8) | ((uint32_t)addr[2]);\r
+       temp = (temp << 8) | ((uint32_t)addr[1]);\r
+       temp = (temp << 8) | ((uint32_t)addr[0]);\r
        return temp;\r
 }\r
        return temp;\r
 }\r
+\r
 /***************************************************************/\r
 /***************************************************************/\r
-uint16 ReadShortLittleEndian( const uint16 *addr )\r
+uint32_t Read32LittleEndian( const uint8_t *addr )\r
+{\r
+       uint32_t temp = (uint32_t)addr[3];\r
+       temp = (temp << 8) | ((uint32_t)addr[2]);\r
+       temp = (temp << 8) | ((uint32_t)addr[1]);\r
+       temp = (temp << 8) | ((uint32_t)addr[0]);\r
+       return temp;\r
+}\r
+\r
+/***************************************************************/\r
+uint16_t Read16LittleEndian( const uint8_t *addr )\r
 {\r
        const unsigned char *bp = (const unsigned char *) addr;\r
 {\r
        const unsigned char *bp = (const unsigned char *) addr;\r
-       return (uint16) ((bp[1]<<8) | bp[0]);\r
+       return (uint16_t) ((bp[1]<<8) | bp[0]);\r
 }\r
 \r
 #ifdef PF_SUPPORT_FP\r
 }\r
 \r
 #ifdef PF_SUPPORT_FP\r
@@ -178,42 +211,81 @@ PF_FLOAT ReadFloatLittleEndian( const PF_FLOAT *addr )
 #endif /* PF_SUPPORT_FP */\r
 \r
 /***************************************************************/\r
 #endif /* PF_SUPPORT_FP */\r
 \r
 /***************************************************************/\r
-void WriteLongBigEndian( uint32 *addr, uint32 data )\r
+void WriteCellBigEndian( uint8_t *addr, ucell_t data )\r
 {\r
 {\r
-       unsigned char *bp = (unsigned char *) addr;\r
-\r
-       bp[0] = (unsigned char) (data>>24);\r
-       bp[1] = (unsigned char) (data>>16);\r
-       bp[2] = (unsigned char) (data>>8);\r
-       bp[3] = (unsigned char) (data);\r
+       // Write should be in order of increasing address\r
+       // to optimize for burst writes to DRAM.\r
+       if( sizeof(ucell_t) == 8 )\r
+       {\r
+               *addr++ = (uint8_t) (data>>56);\r
+               *addr++ = (uint8_t) (data>>48);\r
+               *addr++ = (uint8_t) (data>>40);\r
+               *addr++ = (uint8_t) (data>>32);\r
+       }\r
+       *addr++ = (uint8_t) (data>>24);\r
+       *addr++ = (uint8_t) (data>>16);\r
+       *addr++ = (uint8_t) (data>>8);\r
+       *addr = (uint8_t) (data);\r
 }\r
 \r
 /***************************************************************/\r
 }\r
 \r
 /***************************************************************/\r
-void WriteShortBigEndian( uint16 *addr, uint16 data )\r
+void Write32BigEndian( uint8_t *addr, uint32_t data )\r
 {\r
 {\r
-       unsigned char *bp = (unsigned char *) addr;\r
-\r
-       bp[0] = (unsigned char) (data>>8);\r
-       bp[1] = (unsigned char) (data);\r
+       *addr++ = (uint8_t) (data>>24);\r
+       *addr++ = (uint8_t) (data>>16);\r
+       *addr++ = (uint8_t) (data>>8);\r
+       *addr = (uint8_t) (data);\r
 }\r
 \r
 /***************************************************************/\r
 }\r
 \r
 /***************************************************************/\r
-void WriteLongLittleEndian( uint32 *addr, uint32 data )\r
+void Write16BigEndian( uint8_t *addr, uint16_t data )\r
 {\r
 {\r
-       unsigned char *bp = (unsigned char *) addr;\r
+       *addr++ = (uint8_t) (data>>8);\r
+       *addr = (uint8_t) (data);\r
+}\r
 \r
 \r
-       bp[0] = (unsigned char) (data);\r
-       bp[1] = (unsigned char) (data>>8);\r
-       bp[2] = (unsigned char) (data>>16);\r
-       bp[3] = (unsigned char) (data>>24);\r
+/***************************************************************/\r
+void WriteCellLittleEndian( uint8_t *addr, ucell_t data )\r
+{\r
+       // Write should be in order of increasing address\r
+       // to optimize for burst writes to DRAM.\r
+       if( sizeof(ucell_t) == 8 )\r
+       {\r
+               *addr++ = (uint8_t) data;  // LSB at near end\r
+               data = data >> 8;\r
+               *addr++ = (uint8_t) data;\r
+               data = data >> 8;\r
+               *addr++ = (uint8_t) data;\r
+               data = data >> 8;\r
+               *addr++ = (uint8_t) data;\r
+               data = data >> 8;\r
+       }\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr = (uint8_t) data;\r
 }\r
 /***************************************************************/\r
 }\r
 /***************************************************************/\r
-void WriteShortLittleEndian( uint16 *addr, uint16 data )\r
+void Write32LittleEndian( uint8_t *addr, uint32_t data )\r
 {\r
 {\r
-       unsigned char *bp = (unsigned char *) addr;\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr = (uint8_t) data;\r
+}\r
 \r
 \r
-       bp[0] = (unsigned char) (data);\r
-       bp[1] = (unsigned char) (data>>8);\r
+/***************************************************************/\r
+void Write16LittleEndian( uint8_t *addr, uint16_t data )\r
+{\r
+       *addr++ = (uint8_t) data;\r
+       data = data >> 8;\r
+       *addr = (uint8_t) data;\r
 }\r
 \r
 /***************************************************************/\r
 }\r
 \r
 /***************************************************************/\r
@@ -227,7 +299,7 @@ int IsHostLittleEndian( void )
 \r
 #if defined(PF_NO_FILEIO) || defined(PF_NO_SHELL)\r
 \r
 \r
 #if defined(PF_NO_FILEIO) || defined(PF_NO_SHELL)\r
 \r
-int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, int32 CodeSize)\r
+cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, cell_t CodeSize)\r
 {\r
        TOUCH(FileName);\r
        TOUCH(EntryPoint);\r
 {\r
        TOUCH(FileName);\r
        TOUCH(EntryPoint);\r
@@ -241,33 +313,33 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i
 #else /* PF_NO_FILEIO or PF_NO_SHELL */\r
 \r
 /***************************************************************/\r
 #else /* PF_NO_FILEIO or PF_NO_SHELL */\r
 \r
 /***************************************************************/\r
-static int32 WriteLong( FileStream *fid, int32 Val )\r
+static int Write32ToFile( FileStream *fid, uint32_t Val )\r
 {\r
 {\r
-       int32 numw;\r
-       uint32 pad;\r
+       int numw;\r
+       uint8_t pad[4];\r
 \r
 \r
-       WriteLongBigEndian(&pad,Val);\r
-       numw = sdWriteFile( (char *) &pad, 1, sizeof(int32), fid );\r
-       if( numw != sizeof(int32) ) return -1;\r
+       Write32BigEndian(pad,Val);\r
+       numw = sdWriteFile( pad, 1, sizeof(pad), fid );\r
+       if( numw != sizeof(pad) ) return -1;\r
        return 0;\r
 }\r
 \r
 /***************************************************************/\r
        return 0;\r
 }\r
 \r
 /***************************************************************/\r
-static int32 WriteChunk( FileStream *fid, int32 ID, char *Data, int32 NumBytes )\r
+static cell_t WriteChunkToFile( FileStream *fid, cell_t ID, char *Data, int32_t NumBytes )\r
 {\r
 {\r
-       int32 numw;\r
-       int32 EvenNumW;\r
+       cell_t numw;\r
+       cell_t EvenNumW;\r
 \r
        EvenNumW = EVENUP(NumBytes);\r
 \r
 \r
        EvenNumW = EVENUP(NumBytes);\r
 \r
-       if( WriteLong( fid, ID ) < 0 ) goto error;\r
-       if( WriteLong( fid, EvenNumW ) < 0 ) goto error;\r
+       if( Write32ToFile( fid, ID ) < 0 ) goto error;\r
+       if( Write32ToFile( fid, EvenNumW ) < 0 ) goto error;\r
 \r
        numw = sdWriteFile( Data, 1, EvenNumW, fid );\r
        if( numw != EvenNumW ) goto error;\r
        return 0;\r
 error:\r
 \r
        numw = sdWriteFile( Data, 1, EvenNumW, fid );\r
        if( numw != EvenNumW ) goto error;\r
        return 0;\r
 error:\r
-       pfReportError("WriteChunk", PF_ERR_WRITE_FILE);\r
+       pfReportError("WriteChunkToFile", PF_ERR_WRITE_FILE);\r
        return -1;\r
 }\r
 \r
        return -1;\r
 }\r
 \r
@@ -276,15 +348,14 @@ error:
 ** If EntryPoint is NULL, save as development environment.\r
 ** If EntryPoint is non-NULL, save as turnKey environment with no names.\r
 */\r
 ** If EntryPoint is NULL, save as development environment.\r
 ** If EntryPoint is non-NULL, save as turnKey environment with no names.\r
 */\r
-int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, int32 CodeSize)\r
+cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, cell_t CodeSize)\r
 {\r
        FileStream *fid;\r
        DictionaryInfoChunk SD;\r
 {\r
        FileStream *fid;\r
        DictionaryInfoChunk SD;\r
-       int32 FormSize;\r
-       int32 NameChunkSize = 0;\r
-       int32 CodeChunkSize;\r
-       uint32 rhp, rcp;\r
-       uint32 *p;\r
+       uint32_t FormSize;\r
+       uint32_t NameChunkSize = 0;\r
+       uint32_t CodeChunkSize;\r
+       uint32_t relativeCodePtr;\r
        int   i;\r
 \r
        fid = sdOpenFile( FileName, "wb" );\r
        int   i;\r
 \r
        fid = sdOpenFile( FileName, "wb" );\r
@@ -298,17 +369,17 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i
        pfExecIfDefined("AUTO.TERM");\r
 \r
 /* Write FORM Header ---------------------------- */\r
        pfExecIfDefined("AUTO.TERM");\r
 \r
 /* Write FORM Header ---------------------------- */\r
-       if( WriteLong( fid, ID_FORM ) < 0 ) goto error;\r
-       if( WriteLong( fid, 0 ) < 0 ) goto error;\r
-       if( WriteLong( fid, ID_P4TH ) < 0 ) goto error;\r
+       if( Write32ToFile( fid, ID_FORM ) < 0 ) goto error;\r
+       if( Write32ToFile( fid, 0 ) < 0 ) goto error;\r
+       if( Write32ToFile( fid, ID_P4TH ) < 0 ) goto error;\r
 \r
 /* Write P4DI Dictionary Info  ------------------ */\r
        SD.sd_Version = PF_FILE_VERSION;\r
 \r
 \r
 /* Write P4DI Dictionary Info  ------------------ */\r
        SD.sd_Version = PF_FILE_VERSION;\r
 \r
-       rcp = ABS_TO_CODEREL(gCurrentDictionary->dic_CodePtr.Byte); /* 940225 */\r
-       SD.sd_RelCodePtr = rcp\r
-       SD.sd_UserStackSize = sizeof(cell) * (gCurrentTask->td_StackBase - gCurrentTask->td_StackLimit);\r
-       SD.sd_ReturnStackSize = sizeof(cell) * (gCurrentTask->td_ReturnBase - gCurrentTask->td_ReturnLimit);\r
+       relativeCodePtr = ABS_TO_CODEREL(gCurrentDictionary->dic_CodePtr.Byte); /* 940225 */\r
+       SD.sd_RelCodePtr = relativeCodePtr\r
+       SD.sd_UserStackSize = sizeof(cell_t) * (gCurrentTask->td_StackBase - gCurrentTask->td_StackLimit);\r
+       SD.sd_ReturnStackSize = sizeof(cell_t) * (gCurrentTask->td_ReturnBase - gCurrentTask->td_ReturnLimit);\r
        SD.sd_NumPrimitives = gNumPrimitives;  /* Must match compiled dictionary. */\r
 \r
 #ifdef PF_SUPPORT_FP\r
        SD.sd_NumPrimitives = gNumPrimitives;  /* Must match compiled dictionary. */\r
 \r
 #ifdef PF_SUPPORT_FP\r
@@ -317,9 +388,9 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i
        SD.sd_FloatSize = 0;\r
 #endif\r
 \r
        SD.sd_FloatSize = 0;\r
 #endif\r
 \r
-       SD.sd_Reserved = 0;\r
+       SD.sd_CellSize = sizeof(cell_t);\r
 \r
 \r
-/* Set bit that specifiec whether dictionary is BIG or LITTLE Endian. */\r
+/* Set bit that specifies whether dictionary is BIG or LITTLE Endian. */\r
        {\r
 #if defined(PF_BIG_ENDIAN_DIC)\r
                int eflag = SD_F_BIG_ENDIAN_DIC;\r
        {\r
 #if defined(PF_BIG_ENDIAN_DIC)\r
                int eflag = SD_F_BIG_ENDIAN_DIC;\r
@@ -349,13 +420,14 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i
        }\r
        else\r
        {\r
        }\r
        else\r
        {\r
+               uint32_t relativeHeaderPtr;\r
 /* Development mode. */\r
                SD.sd_RelContext = ABS_TO_NAMEREL(gVarContext);\r
 /* Development mode. */\r
                SD.sd_RelContext = ABS_TO_NAMEREL(gVarContext);\r
-               rhp = ABS_TO_NAMEREL(gCurrentDictionary->dic_HeaderPtr.Byte);\r
-               SD.sd_RelHeaderPtr = rhp;\r
+               relativeHeaderPtr = ABS_TO_NAMEREL(gCurrentDictionary->dic_HeaderPtr.Byte);\r
+               SD.sd_RelHeaderPtr = relativeHeaderPtr;\r
 \r
 /* How much real name space is there? */\r
 \r
 /* How much real name space is there? */\r
-               NameChunkSize = QUADUP(rhp);  /* Align */\r
+               NameChunkSize = QUADUP(relativeHeaderPtr);  /* Align */\r
 \r
 /* NameSize must be 0 or greater than NameChunkSize + 1K */\r
                NameSize = QUADUP(NameSize);  /* Align */\r
 \r
 /* NameSize must be 0 or greater than NameChunkSize + 1K */\r
                NameSize = QUADUP(NameSize);  /* Align */\r
@@ -367,53 +439,52 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i
        }\r
 \r
 /* How much real code is there? */\r
        }\r
 \r
 /* How much real code is there? */\r
-       CodeChunkSize = QUADUP(rcp);\r
+       CodeChunkSize = QUADUP(relativeCodePtr);\r
        CodeSize = QUADUP(CodeSize);  /* Align */\r
        CodeSize = MAX( CodeSize, (CodeChunkSize + 2048) );\r
        SD.sd_CodeSize = CodeSize;\r
 \r
        \r
        CodeSize = QUADUP(CodeSize);  /* Align */\r
        CodeSize = MAX( CodeSize, (CodeChunkSize + 2048) );\r
        SD.sd_CodeSize = CodeSize;\r
 \r
        \r
-/* Convert all fields in structure from Native to BigEndian. */\r
-       p = (uint32 *) &SD;\r
-       for( i=0; i<((int)(sizeof(SD)/sizeof(int32))); i++ )\r
+/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. \r
+ * This assumes they are all 32-bit integers.\r
+ */\r
        {\r
        {\r
-               WriteLongBigEndian( &p[i], p[i] );\r
+               uint32_t *p = (uint32_t *) &SD;\r
+               for( i=0; i<((int)(sizeof(SD)/sizeof(uint32_t))); i++ )\r
+               {\r
+                       Write32BigEndian( (uint8_t *)&p[i], p[i] );\r
+               }\r
        }\r
 \r
        }\r
 \r
-       if( WriteChunk( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error;\r
+       if( WriteChunkToFile( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error;\r
 \r
 /* Write Name Fields if NameSize non-zero ------- */\r
        if( NameSize > 0 )\r
        {\r
 \r
 /* Write Name Fields if NameSize non-zero ------- */\r
        if( NameSize > 0 )\r
        {\r
-               if( WriteChunk( fid, ID_P4NM, (char *) NAME_BASE,\r
+               if( WriteChunkToFile( fid, ID_P4NM, (char *) NAME_BASE,\r
                        NameChunkSize ) < 0 ) goto error;\r
        }\r
 \r
 /* Write Code Fields ---------------------------- */\r
                        NameChunkSize ) < 0 ) goto error;\r
        }\r
 \r
 /* Write Code Fields ---------------------------- */\r
-       if( WriteChunk( fid, ID_P4CD, (char *) CODE_BASE,\r
+       if( WriteChunkToFile( fid, ID_P4CD, (char *) CODE_BASE,\r
                CodeChunkSize ) < 0 ) goto error;\r
 \r
        FormSize = sdTellFile( fid ) - 8;\r
        sdSeekFile( fid, 4, PF_SEEK_SET );\r
                CodeChunkSize ) < 0 ) goto error;\r
 \r
        FormSize = sdTellFile( fid ) - 8;\r
        sdSeekFile( fid, 4, PF_SEEK_SET );\r
-       if( WriteLong( fid, FormSize ) < 0 ) goto error;\r
+       if( Write32ToFile( fid, FormSize ) < 0 ) goto error;\r
 \r
        sdCloseFile( fid );\r
 \r
 \r
        sdCloseFile( fid );\r
 \r
-\r
-\r
 /* Restore initialization. */\r
 /* Restore initialization. */\r
-\r
        pfExecIfDefined("AUTO.INIT");\r
        pfExecIfDefined("AUTO.INIT");\r
-\r
        return 0;\r
 \r
 error:\r
        sdSeekFile( fid, 0, PF_SEEK_SET );\r
        return 0;\r
 \r
 error:\r
        sdSeekFile( fid, 0, PF_SEEK_SET );\r
-       WriteLong( fid, ID_BADF ); /* Mark file as bad. */\r
+       Write32ToFile( fid, ID_BADF ); /* Mark file as bad. */\r
        sdCloseFile( fid );\r
 \r
 /* Restore initialization. */\r
        sdCloseFile( fid );\r
 \r
 /* Restore initialization. */\r
-\r
        pfExecIfDefined("AUTO.INIT");\r
 \r
        return -1;\r
        pfExecIfDefined("AUTO.INIT");\r
 \r
        return -1;\r
@@ -425,14 +496,13 @@ error:
 #ifndef PF_NO_FILEIO\r
 \r
 /***************************************************************/\r
 #ifndef PF_NO_FILEIO\r
 \r
 /***************************************************************/\r
-static int32 ReadLong( FileStream *fid, int32 *ValPtr )\r
+static uint32_t Read32FromFile( FileStream *fid, uint32_t *ValPtr )\r
 {\r
 {\r
-       int32 numr;\r
-       uint32 temp;\r
-\r
-       numr = sdReadFile( &temp, 1, sizeof(int32), fid );\r
-       if( numr != sizeof(int32) ) return -1;\r
-       *ValPtr = ReadLongBigEndian( &temp );\r
+       int32_t numr;\r
+       uint8_t pad[4];\r
+       numr = sdReadFile( pad, 1, sizeof(pad), fid );\r
+       if( numr != sizeof(pad) ) return -1;\r
+       *ValPtr = Read32BigEndian( pad );\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
@@ -442,12 +512,11 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt
        pfDictionary_t *dic = NULL;\r
        FileStream *fid;\r
        DictionaryInfoChunk *sd;\r
        pfDictionary_t *dic = NULL;\r
        FileStream *fid;\r
        DictionaryInfoChunk *sd;\r
-       int32 ChunkID;\r
-       int32 ChunkSize;\r
-       int32 FormSize;\r
-       int32 BytesLeft;\r
-       int32 numr;\r
-       uint32 *p;\r
+       uint32_t ChunkID;\r
+       uint32_t ChunkSize;\r
+       uint32_t FormSize;\r
+       uint32_t BytesLeft;\r
+       uint32_t numr;\r
        int   i;\r
        int   isDicBigEndian;\r
 \r
        int   i;\r
        int   isDicBigEndian;\r
 \r
@@ -462,17 +531,17 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
        }\r
 \r
 /* Read FORM, Size, ID */\r
        }\r
 \r
 /* Read FORM, Size, ID */\r
-       if (ReadLong( fid, &ChunkID ) < 0) goto read_error;\r
+       if (Read32FromFile( fid, &ChunkID ) < 0) goto read_error;\r
        if( ChunkID != ID_FORM )\r
        {\r
                pfReportError("pfLoadDictionary", PF_ERR_WRONG_FILE);\r
                goto error;\r
        }\r
 \r
        if( ChunkID != ID_FORM )\r
        {\r
                pfReportError("pfLoadDictionary", PF_ERR_WRONG_FILE);\r
                goto error;\r
        }\r
 \r
-       if (ReadLong( fid, &FormSize ) < 0) goto read_error;\r
+       if (Read32FromFile( fid, &FormSize ) < 0) goto read_error;\r
        BytesLeft = FormSize;\r
 \r
        BytesLeft = FormSize;\r
 \r
-       if (ReadLong( fid, &ChunkID ) < 0) goto read_error;\r
+       if (Read32FromFile( fid, &ChunkID ) < 0) goto read_error;\r
        BytesLeft -= 4;\r
        if( ChunkID != ID_P4TH )\r
        {\r
        BytesLeft -= 4;\r
        if( ChunkID != ID_P4TH )\r
        {\r
@@ -483,11 +552,11 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
 /* Scan and parse all chunks in file. */\r
        while( BytesLeft > 0 )\r
        {\r
 /* Scan and parse all chunks in file. */\r
        while( BytesLeft > 0 )\r
        {\r
-               if (ReadLong( fid, &ChunkID ) < 0) goto read_error;\r
-               if (ReadLong( fid, &ChunkSize ) < 0) goto read_error;\r
+               if (Read32FromFile( fid, &ChunkID ) < 0) goto read_error;\r
+               if (Read32FromFile( fid, &ChunkSize ) < 0) goto read_error;\r
                BytesLeft -= 8;\r
 \r
                BytesLeft -= 8;\r
 \r
-               DBUG(("ChunkID = %4s, Size = %d\n", &ChunkID, ChunkSize ));\r
+               DBUG(("ChunkID = %4s, Size = %d\n", (char *)&ChunkID, ChunkSize ));\r
 \r
                switch( ChunkID )\r
                {\r
 \r
                switch( ChunkID )\r
                {\r
@@ -500,12 +569,14 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                        BytesLeft -= ChunkSize;\r
                        \r
 /* Convert all fields in structure from BigEndian to Native. */\r
                        BytesLeft -= ChunkSize;\r
                        \r
 /* Convert all fields in structure from BigEndian to Native. */\r
-                       p = (uint32 *) sd;\r
-                       for( i=0; i<((int)(sizeof(*sd)/sizeof(int32))); i++ )\r
                        {\r
                        {\r
-                               p[i] = ReadLongBigEndian( &p[i] );\r
+                               uint32_t *p = (uint32_t *) sd;\r
+                               for( i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++ )\r
+                               {\r
+                                       p[i] = Read32BigEndian( (uint8_t *)&p[i] );\r
+                               }\r
                        }\r
                        }\r
-\r
+                               \r
                        isDicBigEndian = sd->sd_Flags & SD_F_BIG_ENDIAN_DIC;\r
 \r
                        if( !gVarQuiet )\r
                        isDicBigEndian = sd->sd_Flags & SD_F_BIG_ENDIAN_DIC;\r
 \r
                        if( !gVarQuiet )\r
@@ -516,6 +587,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                                MSG_NUM_D("     Name space size = ", sd->sd_NameSize );\r
                                MSG_NUM_D("     Code space size = ", sd->sd_CodeSize );\r
                                MSG_NUM_D("     Entry Point     = ", sd->sd_EntryPoint );\r
                                MSG_NUM_D("     Name space size = ", sd->sd_NameSize );\r
                                MSG_NUM_D("     Code space size = ", sd->sd_CodeSize );\r
                                MSG_NUM_D("     Entry Point     = ", sd->sd_EntryPoint );\r
+                               MSG_NUM_D("     Cell Size       = ", sd->sd_CellSize );\r
                                MSG( (isDicBigEndian ? "     Big Endian Dictionary" :\r
                                                       "     Little  Endian Dictionary") );\r
                                if( isDicBigEndian == IsHostLittleEndian() ) MSG(" !!!!");\r
                                MSG( (isDicBigEndian ? "     Big Endian Dictionary" :\r
                                                       "     Little  Endian Dictionary") );\r
                                if( isDicBigEndian == IsHostLittleEndian() ) MSG(" !!!!");\r
@@ -532,6 +604,11 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                                pfReportError("pfLoadDictionary", PF_ERR_VERSION_PAST );\r
                                goto error;\r
                        }\r
                                pfReportError("pfLoadDictionary", PF_ERR_VERSION_PAST );\r
                                goto error;\r
                        }\r
+                       if( sd->sd_CellSize != sizeof(cell_t) )\r
+                       {\r
+                               pfReportError("pfLoadDictionary", PF_ERR_CELL_SIZE_CONFLICT );\r
+                               goto error;\r
+                       }\r
                        if( sd->sd_NumPrimitives > NUM_PRIMITIVES )\r
                        {\r
                                pfReportError("pfLoadDictionary", PF_ERR_NOT_SUPPORTED );\r
                        if( sd->sd_NumPrimitives > NUM_PRIMITIVES )\r
                        {\r
                                pfReportError("pfLoadDictionary", PF_ERR_NOT_SUPPORTED );\r
@@ -568,7 +645,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                        if( sd->sd_NameSize > 0 )\r
                        {\r
                                gVarContext = (char *) NAMEREL_TO_ABS(sd->sd_RelContext); /* Restore context. */\r
                        if( sd->sd_NameSize > 0 )\r
                        {\r
                                gVarContext = (char *) NAMEREL_TO_ABS(sd->sd_RelContext); /* Restore context. */\r
-                               gCurrentDictionary->dic_HeaderPtr.Byte = (uint8 *)\r
+                               gCurrentDictionary->dic_HeaderPtr.Byte = (uint8_t *)\r
                                        NAMEREL_TO_ABS(sd->sd_RelHeaderPtr);\r
                        }\r
                        else\r
                                        NAMEREL_TO_ABS(sd->sd_RelHeaderPtr);\r
                        }\r
                        else\r
@@ -576,7 +653,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                                gVarContext = 0;\r
                                gCurrentDictionary->dic_HeaderPtr.Byte = NULL;\r
                        }\r
                                gVarContext = 0;\r
                                gCurrentDictionary->dic_HeaderPtr.Byte = NULL;\r
                        }\r
-                       gCurrentDictionary->dic_CodePtr.Byte = (uint8 *) CODEREL_TO_ABS(sd->sd_RelCodePtr);\r
+                       gCurrentDictionary->dic_CodePtr.Byte = (uint8_t *) CODEREL_TO_ABS(sd->sd_RelCodePtr);\r
                        gNumPrimitives = sd->sd_NumPrimitives;  /* Must match compiled dictionary. */\r
 /* Pass EntryPoint back to caller. */\r
                        if( EntryPointPtr != NULL ) *EntryPointPtr = sd->sd_EntryPoint;\r
                        gNumPrimitives = sd->sd_NumPrimitives;  /* Must match compiled dictionary. */\r
 /* Pass EntryPoint back to caller. */\r
                        if( EntryPointPtr != NULL ) *EntryPointPtr = sd->sd_EntryPoint;\r
@@ -636,7 +713,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
 \r
        if( NAME_BASE != NULL)\r
        {\r
 \r
        if( NAME_BASE != NULL)\r
        {\r
-               int32 Result;\r
+               cell_t Result;\r
 /* Find special words in dictionary for global XTs. */\r
                if( (Result = FindSpecialXTs()) < 0 )\r
                {\r
 /* Find special words in dictionary for global XTs. */\r
                if( (Result = FindSpecialXTs()) < 0 )\r
                {\r
@@ -645,7 +722,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                }\r
        }\r
 \r
                }\r
        }\r
 \r
-DBUG(("pfLoadDictionary: return 0x%x\n", dic));\r
+DBUG(("pfLoadDictionary: return %p\n", dic));\r
        return (PForthDictionary) dic;\r
 \r
 nomem_error:\r
        return (PForthDictionary) dic;\r
 \r
 nomem_error:\r
@@ -677,9 +754,9 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt
 PForthDictionary pfLoadStaticDictionary( void )\r
 {\r
 #ifdef PF_STATIC_DIC\r
 PForthDictionary pfLoadStaticDictionary( void )\r
 {\r
 #ifdef PF_STATIC_DIC\r
-       int32 Result;\r
+       cell_t Result;\r
        pfDictionary_t *dic;\r
        pfDictionary_t *dic;\r
-       int32 NewNameSize, NewCodeSize;\r
+       cell_t NewNameSize, NewCodeSize;\r
        \r
        if( IF_LITTLE_ENDIAN != IsHostLittleEndian() )\r
        {\r
        \r
        if( IF_LITTLE_ENDIAN != IsHostLittleEndian() )\r
        {\r
@@ -725,15 +802,15 @@ PForthDictionary pfLoadStaticDictionary( void )
 \r
        pfCopyMemory( dic->dic_HeaderBase, MinDicNames, sizeof(MinDicNames) );\r
        pfCopyMemory( dic->dic_CodeBase, MinDicCode, sizeof(MinDicCode) );\r
 \r
        pfCopyMemory( dic->dic_HeaderBase, MinDicNames, sizeof(MinDicNames) );\r
        pfCopyMemory( dic->dic_CodeBase, MinDicCode, sizeof(MinDicCode) );\r
-       DBUG("Static data copied to newly allocated dictionaries.\n");\r
+       DBUG(("Static data copied to newly allocated dictionaries.\n"));\r
 \r
 \r
-       dic->dic_CodePtr.Byte = (uint8 *) CODEREL_TO_ABS(CODEPTR);\r
+       dic->dic_CodePtr.Byte = (uint8_t *) CODEREL_TO_ABS(CODEPTR);\r
        gNumPrimitives = NUM_PRIMITIVES;\r
 \r
        if( NAME_BASE != NULL)\r
        {\r
 /* Setup name space. */\r
        gNumPrimitives = NUM_PRIMITIVES;\r
 \r
        if( NAME_BASE != NULL)\r
        {\r
 /* Setup name space. */\r
-               dic->dic_HeaderPtr.Byte = (uint8 *) NAMEREL_TO_ABS(HEADERPTR);\r
+               dic->dic_HeaderPtr.Byte = (uint8_t *) NAMEREL_TO_ABS(HEADERPTR);\r
                gVarContext = (char *) NAMEREL_TO_ABS(RELCONTEXT); /* Restore context. */\r
 \r
 /* Find special words in dictionary for global XTs. */\r
                gVarContext = (char *) NAMEREL_TO_ABS(RELCONTEXT); /* Restore context. */\r
 \r
 /* Find special words in dictionary for global XTs. */\r