-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
126 lines (104 loc) · 3.31 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef __UTILS_H__
#define __UTILS_H__
#include <time.h>
#include "types.h"
#include "rom.h"
#include "os_structs.h"
extern void FreeROM (ROMPtr pROM);
extern void FreePRC (PRCPtr pPRC);
extern void FreePRCList (PRCPtr* pPRCList,
int nItems);
extern void FreeROMVersion (ROMVersion* pVersion);
extern int CompareAddrs (const void* pAddr1,
const void* pAddr2);
extern MemChunkHeaderUnionType*
LocateAddrInChunk (MemChunkHeaderUnionType* pChunk,
UInt16 version,
UInt32 addr);
extern MemChunkHeaderUnionType*
LocateAddrInHeap (MemHeapHeaderUnionType* pHeap,
UInt32 addr);
extern MemChunkHeaderUnionType*
LocateChunk (HeapListPtr pHeapList,
UInt32 addr);
extern DatabaseHdrPtr LocateDBbyName (DatabaseListPtr pDBList,
char* name);
extern DatabaseHdrPtr LocateDB (DatabaseListPtr pDBList,
UInt32 type,
UInt32 creator,
UInt32* pStart);
extern DatabaseHdrPtr LocateDBOverlay (DatabaseListPtr pDBList,
OmOverlaySpecType* pOvly,
UInt32* pStart);
extern RsrcEntryPtr LocateResource (DatabaseHdrPtr pDB,
UInt32 Type,
UInt16 ID);
extern char* GetPalmOSVersion (ROMPtr pROM);
extern int SizeOfRecordContents (ROMPtr pROM,
UInt32 highAddr,
RecordListPtr pRecordList,
UInt16 lType,
UInt16 idex);
extern int DBTotalSize (ROMPtr pROM,
DatabaseHdrPtr pDB);
extern OmOverlaySpecType*
LocateOverlayResource (DatabaseHdrPtr pDatabase);
extern time_t pilot_time_to_unix_time (UInt32 raw_time);
extern UInt32 unix_time_to_pilot_time (time_t time);
extern char* pilot_time_str (UInt32 raw_time);
extern TypeCtorPtr StrList2TypeCtorList (char* StrList[],
UInt32 numEntries);
extern UInt8 IsInTypeCtorList (UInt32 type,
UInt32 ctor,
TypeCtorPtr TypeCtorList,
UInt32 numEntries);
/*
* Adjust the given 'offset' by an 'adjust'ment value
*/
static inline UInt32 Adjust (UInt32 offset,
UInt32 adjust)
{
return (offset ? (offset - adjust) : offset);
//return (offset < adjust ? offset : (offset - adjust));
//return (offset - adjust);
}
/* Does the pointer point inside the rom */
static inline int IsValidPtr (ROMPtr pROM, void* pItem)
{
return ((UInt8*)pItem >= pROM->pROM &&
(UInt8*)pItem < pROM->pROM + pROM->ROMSize);
}
/*
* Returns the size of the chunk containing the given address
*/
static inline UInt32 SizeOfChunk (HeapListPtr pHeapList,
UInt32 addr)
{
MemChunkHeaderUnionType* pChunk;
UInt16 version;
if (! pHeapList)
return 0;
if (! (pChunk = LocateChunk (pHeapList, addr)))
return 0;
version = memUChunkVer (pHeapList->heapOffset[0]);
return (memUChunkPayloadSize (pChunk, version));
}
/*
* Given the head of a list (pList) and an item on the list (pItem)
* locate the items index in the list.
*/
static inline UInt32 LocateItemIdex (void** pList,
void* pItem,
UInt32 nItems,
UInt32 stepSize)
{
UInt32 idex = 0;
for (idex = 0; idex < nItems; idex++)
{
if (*pList == pItem)
return idex;
pList = (void**)((UInt8*)pList + stepSize);
}
return(nItems);
}
#endif // __UTILS_H__