diff options
author | Chris Apers | 2003-06-08 09:28:18 +0000 |
---|---|---|
committer | Chris Apers | 2003-06-08 09:28:18 +0000 |
commit | 2600628339853a6734c5ebfd44c849c31e3f321c (patch) | |
tree | 501a05e24505fd8d5e3a74524009af9077c35392 /backends/PalmOS/Src/missing | |
parent | 8cc50d2460e8eda4c77c7aa49c8ef83090492c86 (diff) | |
download | scummvm-rg350-2600628339853a6734c5ebfd44c849c31e3f321c.tar.gz scummvm-rg350-2600628339853a6734c5ebfd44c849c31e3f321c.tar.bz2 scummvm-rg350-2600628339853a6734c5ebfd44c849c31e3f321c.zip |
Cleanup, add qsort function
svn-id: r8393
Diffstat (limited to 'backends/PalmOS/Src/missing')
-rw-r--r-- | backends/PalmOS/Src/missing/_stdlib.cpp | 165 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/stdlib.h | 18 |
2 files changed, 6 insertions, 177 deletions
diff --git a/backends/PalmOS/Src/missing/_stdlib.cpp b/backends/PalmOS/Src/missing/_stdlib.cpp index f9ccb9493a..b439d5614b 100644 --- a/backends/PalmOS/Src/missing/_stdlib.cpp +++ b/backends/PalmOS/Src/missing/_stdlib.cpp @@ -21,12 +21,6 @@ */ #include "stdlib.h" -#include "MemGlue.h" -/////////////////////////////////////////////////////////////////////////////// -/*void qsort(void *base, UInt32 nmemb, UInt32 size, ComparF *compar) { - - SysQSort(base, nmemb, size, compar); -}*/ /////////////////////////////////////////////////////////////////////////////// void *bsearch(const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *)) { @@ -38,136 +32,10 @@ void *bsearch(const void *key, const void *base, UInt32 nmemb, return NULL; } /////////////////////////////////////////////////////////////////////////////// -static DmOpenRef gExtMemory = NULL; - -static UInt16 MemFindHeapID(UInt32 size) -{ - UInt32 nFree, maxChunk ; - UInt16 maxCards = 1; //MemNumCards(); process only first card for now - UInt16 heapID = -1; // no heap avaliable - - UInt16 cardNo; - UInt16 maxHeaps, heapIndex; - - for (cardNo = 0; cardNo < maxCards; cardNo++) - { - if (MemNumRAMHeaps(cardNo) > 0) - { - maxHeaps = MemNumHeaps(cardNo); - for (heapIndex = 0; heapIndex < maxHeaps; heapIndex++) - { - // Obtain the ID of the heap. - heapID = MemHeapID(cardNo, heapIndex); - - if (!(MemHeapFlags(heapID) & memHeapFlagReadOnly)) - { - MemHeapFreeBytes( heapID, &nFree, &maxChunk ); - if (maxChunk > size) - return heapID; - } - } - } - } - - return heapID; -} - -void MemExtInit() -{ - if (!gExtMemory) - { - LocalID localID = DmFindDatabase(0, "ScummVM-Memory"); - if (localID) DmDeleteDatabase(0, localID); - - if (DmCreateDatabase (0, "ScummVM-Memory", 'ScVM', 'DATA', false) != errNone) - return; - - localID = DmFindDatabase(0, "ScummVM-Memory"); - gExtMemory = DmOpenDatabase(0, localID, dmModeReadWrite|dmModeExclusive); - } -} - -void MemExtCleanup() -{ - if (gExtMemory) { - DmCloseDatabase(gExtMemory); - LocalID localID = DmFindDatabase(0, "ScummVM-Memory"); - if (localID) - DmDeleteDatabase(0, localID); - } -} -//#define USE_EXTENDEDMEM -#ifdef USE_EXTENDEDMEM - -MemPtr calloc(UInt32 nelem, UInt32 elsize) -{ - UInt32 size = nelem*elsize; - MemPtr newP = NULL; - UInt16 heapID = MemFindHeapID(size); - - if (heapID != NO_HEAP_FOUND) - { - if (MemHeapDynamic(heapID) && size < 65536-8) // 8 = chunk header size - newP = MemPtrNew(size); - else - { - SysAppInfoPtr appInfoP; - UInt16 ownerID, large, nmovable; - UInt16 attr; - - ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID; - large = ((size > 65536-8) ? memNewChunkFlagAllowLarge : 0); - nmovable= (MemHeapDynamic(heapID) ? memNewChunkFlagNonMovable : memNewChunkFlagPreLock); - attr = ownerID|large|nmovable; - - //MEMORY_RESERVE_ACCESS - newP = MemChunkNew(heapID, size, attr); - //MEMORY_RELEASE_ACCESS - - if (newP && MemPtrDataStorage(newP)) { // if storage heap ? - if (!gExtMemory) { // if memory DB doesn't exist - MemChunkFree(newP); - return NULL; - } - - UInt16 index = dmMaxRecordIndex; // used for record purpose - MemHandle newH = MemPtrRecoverHandle(newP); // exists - if (DmAttachRecord(gExtMemory, &index, newH, NULL) != errNone) // attach to DB - { - MemChunkFree(newP); // error - return NULL; - } - } - } - } - - if (newP) - MemSet(newP,size,0); - - return newP; -} - -#else - -MemPtr calloc(UInt32 nelem, UInt32 elsize) -{ +MemPtr calloc(UInt32 nelem, UInt32 elsize) { + MemPtr newP; UInt32 size = nelem*elsize; - MemPtr newP = NULL; - -/* if (size < 65536-8) // 8 = chunk header size - newP = MemPtrNew(size); - else*/ -/* { - SysAppInfoPtr appInfoP; - UInt16 ownerID; - UInt16 attr; - - ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID; - attr = ownerID|memNewChunkFlagAllowLarge|memNewChunkFlagNonMovable; - newP = MemChunkNew(0, size, attr); - } -*/ newP = MemGluePtrNew(size); if (newP) @@ -175,39 +43,12 @@ MemPtr calloc(UInt32 nelem, UInt32 elsize) return newP; } - -#endif /////////////////////////////////////////////////////////////////////////////// -#ifdef USE_EXTENDEDMEM -Err free(MemPtr memP) -{ - Err err = memErrInvalidParam; - - if (!memP) - return err; - - if (MemPtrDataStorage(memP)) { // if storage heap ? - if (gExtMemory) { // if memory DB exists - DmOpenRef where; - MemHandle newH = MemPtrRecoverHandle(memP); - UInt16 index = DmSearchRecord(newH, &where); - err = DmRemoveRecord(gExtMemory, index); - } - } - else - err = MemChunkFree(memP); - - return err; -} -#else -Err free(MemPtr memP) -{ +Err free(MemPtr memP) { if (memP) return MemPtrFree(memP); - return memErrInvalidParam; } -#endif /////////////////////////////////////////////////////////////////////////////// MemPtr realloc(MemPtr oldP, UInt32 size) { diff --git a/backends/PalmOS/Src/missing/stdlib.h b/backends/PalmOS/Src/missing/stdlib.h index 544ee04bf9..3ace362a07 100644 --- a/backends/PalmOS/Src/missing/stdlib.h +++ b/backends/PalmOS/Src/missing/stdlib.h @@ -24,31 +24,19 @@ #define STDLIB_H #include <PalmOS.h> +#include "MemGlue.h" #include "mathlib.h" -//#define memNewChunkFlagNonMovable 0x0200 -#define memNewChunkFlagAllowLarge 0x1000 // this is not in the sdk *g* -#define memHeapFlagReadOnly 0x0001 - -#define NO_HEAP_FOUND -1 - -SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP) - SYS_TRAP(sysTrapSysGetAppInfo); - - #define atoi StrAToI #define atol StrAToI #define abs(a) ((a) < 0 ? -(a) : (a)) //#define abs fabs -#define malloc(a) calloc(a,1) +#define malloc(a) MemGluePtrNew(a) //#define free MemPtrFree #define strtol(a,b,c) StrAToI(a) -#define qsort(a,b,c,d) +#define qsort(a,b,c,d) SysQSort((a), (b), (c), (CmpFuncPtr)(&d), 0); #define rand() SysRandom(0) -void MemExtInit(); -void MemExtCleanup(); - MemPtr realloc(MemPtr oldP, UInt32 size); MemPtr calloc(UInt32 nelem, UInt32 elsize); Err free(MemPtr memP); |