X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/blobdiff_plain/bb6b2dcdd9acffabfd373c4c3f6b64a9cc43f335..07618dcb5a69971dde69b56cfda977d92de48525:/csrc/pf_inner.c diff --git a/csrc/pf_inner.c b/csrc/pf_inner.c index d7f1239..15f764f 100644 --- a/csrc/pf_inner.c +++ b/csrc/pf_inner.c @@ -27,7 +27,10 @@ ***************************************************************/ #include "pf_all.h" + +#ifdef WIN32 #include +#endif #define SYSTEM_LOAD_FILE "system.fth" @@ -190,10 +193,38 @@ static void TraceNames( ExecToken Token, int32 Level ) /* Use local copy of CODE_BASE for speed. */ #define LOCAL_CODEREL_TO_ABS( a ) ((cell *) (((int32) a) + CodeBase)) +static const char *pfSelectFileModeCreate( int fam ); +static const char *pfSelectFileModeOpen( int fam ); + +/**************************************************************/ +static const char *pfSelectFileModeCreate( int fam ) +{ + const char *famText = NULL; + switch( fam ) + { + case (PF_FAM_WRITE_ONLY + PF_FAM_BINARY_FLAG): + famText = PF_FAM_BIN_CREATE_WO; + break; + case (PF_FAM_READ_WRITE + PF_FAM_BINARY_FLAG): + famText = PF_FAM_BIN_CREATE_RW; + break; + case PF_FAM_WRITE_ONLY: + famText = PF_FAM_CREATE_WO; + break; + case PF_FAM_READ_WRITE: + famText = PF_FAM_CREATE_RW; + break; + default: + famText = "illegal"; + break; + } + return famText; +} + /**************************************************************/ -const char *pfSelectFileMode( int fam ) +static const char *pfSelectFileModeOpen( int fam ) { - char *famText = NULL; + const char *famText = NULL; switch( fam ) { case (PF_FAM_READ_ONLY + PF_FAM_BINARY_FLAG): @@ -890,10 +921,10 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); Temp = M_POP; /* caddr */ if( Scratch < TIB_SIZE-2 ) { - const char *famText = pfSelectFileMode( TOS ); + const char *famText = pfSelectFileModeCreate( TOS ); pfCopyMemory( gScratch, (char *) Temp, (uint32) Scratch ); gScratch[Scratch] = '\0'; - DBUG(("Create file = %s\n", gScratch )); + DBUG(("Create file = %s with famTxt %s\n", gScratch, famText )); FileID = sdOpenFile( gScratch, famText ); TOS = ( FileID == NULL ) ? -1 : 0 ; M_PUSH( (cell) FileID ); @@ -912,7 +943,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); Temp = M_POP; /* caddr */ if( Scratch < TIB_SIZE-2 ) { - const char *famText = pfSelectFileMode( TOS ); + const char *famText = pfSelectFileModeOpen( TOS ); pfCopyMemory( gScratch, (char *) Temp, (uint32) Scratch ); gScratch[Scratch] = '\0'; DBUG(("Open file = %s\n", gScratch )); @@ -1366,12 +1397,13 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); /* Resize memory allocated by ALLOCATE. */ case ID_RESIZE: /* ( addr1 u -- addr2 result ) */ { - cell *FreePtr; - - FreePtr = (cell *) ( M_POP - sizeof(cell) ); + cell *Addr1 = (cell *) M_POP; + // Point to validator below users address. + cell *FreePtr = Addr1 - 1; if( ((uint32)*FreePtr) != ((uint32)FreePtr ^ PF_MEMORY_VALIDATOR)) { - M_PUSH( 0 ); + // 090218 - Fixed bug, was returning zero. + M_PUSH( Addr1 ); TOS = -3; } else @@ -1383,15 +1415,18 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); /* Copy memory including validation. */ pfCopyMemory( (char *) CellPtr, (char *) FreePtr, TOS + sizeof(cell) ); *CellPtr = (cell)(((uint32)CellPtr) ^ (uint32)PF_MEMORY_VALIDATOR); - CellPtr++; - M_PUSH( (cell) ++CellPtr ); - TOS = 0; + // 090218 - Fixed bug that was incrementing the address twice. Thanks Reinhold Straub. + // Increment past validator to user address. + M_PUSH( (cell) (CellPtr + 1) ); + TOS = 0; // Result code. + // Mark old cell as dead so we can't free it twice. FreePtr[0] = 0xDeadBeef; pfFreeMem((char *) FreePtr); } else { - M_PUSH( 0 ); + // 090218 - Fixed bug, was returning zero. + M_PUSH( Addr1 ); TOS = -4; /* FIXME Fix error code. */ } }