Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
Loading...
Searching...
No Matches
memapi.c
Go to the documentation of this file.
1
/*
2
* Memory stack frames and packet handles.
3
*
4
* Retail object 0x458E10-0x45915F (link order; see docs/ORDER.md).
5
*/
6
#include "
game.h
"
7
8
/* Function start: 0x458E10 */
9
/* Nothing in the shipped executable calls this. The DOS memory API's heap
10
* reset; on Win32 the heap it resets is an empty hook. */
11
void
ClearMemoryHeaps
(
void
)
12
{
13
TimerResetHook
();
14
}
15
16
/* Function start: 0x458E20 */
17
unsigned
short
IsSoundHardwarePresent
(
short
device)
18
{
19
EnableHighMemoryResources
();
20
return
1;
21
}
22
23
/* Function start: 0x458E39 */
24
void
MessagePumpHook
(
int
mode)
25
{
26
TimerStopHook
();
27
}
28
29
/* Function start: 0x458E49 */
30
void
*
PushMemoryStackFrame
(
void
*memory,
int
offset)
31
{
32
if
(offset != 0) {
33
printf(
"push %p by %d\n"
, memory, offset);
34
if
(
g_nPacketHandleCount
== 0x1000)
35
exit_squadron
(
"qq mem push overflow"
);
36
g_aiPacketHandleOffsets
[
37
g_nPacketHandleCount
] = offset;
38
if
(offset < 0) {
39
memory = (
unsigned
char
*)memory - offset;
40
g_9_apPacketHandlesTable
[
41
g_nPacketHandleCount
] = memory;
42
}
else
{
43
memory = (
unsigned
char
*)memory + offset;
44
g_9_apPacketHandlesTable
[
45
g_nPacketHandleCount
] = memory;
46
}
47
g_nPacketHandleCount
++;
48
}
49
return
memory;
50
}
51
52
/* Function start: 0x458EED */
53
int
IsPushedPacketHandle
(
void
*handle)
54
{
55
int
index;
56
57
for
(index = 0; index <
g_nPacketHandleCount
; index++) {
58
if
(
g_9_apPacketHandlesTable
[index] == handle) {
59
return
g_aiPacketHandleOffsets
[index] < 0;
60
}
61
}
62
return
0;
63
}
64
65
/* Function start: 0x458F5A */
66
void
*
MapPacketHandleToBlock
(
void
*handle)
67
{
68
int
i;
69
70
for
(i = 0; i <
g_nPacketHandleCount
; i++) {
71
if
(
g_9_apPacketHandlesTable
[i] == handle) {
72
if
(
g_aiPacketHandleOffsets
[i] < 0)
73
handle = (
unsigned
char
*)handle +
74
g_aiPacketHandleOffsets
[i];
75
else
76
handle = (
unsigned
char
*)handle -
77
g_aiPacketHandleOffsets
[i];
78
g_nPacketHandleCount
--;
79
g_9_apPacketHandlesTable
[i] =
80
g_9_apPacketHandlesTable
[
g_nPacketHandleCount
];
81
g_aiPacketHandleOffsets
[i] =
82
g_aiPacketHandleOffsets
[
83
g_nPacketHandleCount
];
84
return
MapPacketHandleToBlock
(handle);
85
}
86
}
87
return
handle;
88
}
89
90
#pragma function(memcpy)
91
/* Function start: 0x45901D */
92
void
*
AllocateTaggedMemory
(
unsigned
int
size,
short
flags)
93
{
94
void
*memory;
95
96
if
((flags & 0x40) != 0)
97
size += 8;
98
memory =
AllocateGuardedMemory
(size);
99
if
((flags & 0x40) != 0) {
100
memcpy(memory,
g_abTaggedAllocationPrefix
,
101
sizeof
(
g_abTaggedAllocationPrefix
));
102
memory =
PushMemoryStackFrame
(memory, -8);
103
}
104
return
memory;
105
}
106
107
/* Function start: 0x459082 */
108
void
ReleasePacketHandle
(
void
*handle)
109
{
110
int
group;
111
int
entry;
112
113
if
(handle == 0)
114
return
;
115
for
(group = 0; group < 4; group++) {
116
if
(
g_apPacketReferenceGroups
[group] != 0) {
117
for
(entry = 0; entry < 0x25; entry++) {
118
if
(
g_apPacketReferenceGroups
[group][entry] ==
119
handle)
120
g_apPacketReferenceGroups
[group][entry] = 0;
121
}
122
}
123
}
124
handle =
MapPacketHandleToBlock
(handle);
125
FreeGuardedAllocation
(handle);
126
}
127
128
/* Function start: 0x459134 */
129
/* Tail-jump thunk to 0x004362E0, not a constant return -- Ghidra followed the
130
* jump and folded the callee's body into the display. The optimized compiler
131
* emits the tail jump from this forwarding return. */
132
unsigned
int
GetAvailableFarMemoryByType
(
short
memoryType)
133
{
134
(
void
)memoryType;
135
return
GetAvailableFarMemory
();
136
}
137
138
/* Function start: 0x459149 */
139
unsigned
int
GetLargestFreeMemoryBlockByType
(
short
memoryType)
140
{
141
(
void
)memoryType;
142
return
GetLargestFreeMemoryBlock
();
143
}
144
145
/* Linker commons defined here. LINK lays a unit's commons out by the
146
* identifiers' hash keys, so these spellings follow the original addresses. */
147
void
*
g_9_apPacketHandlesTable
[0x1000];
/* 0x005c9020 */
148
int
g_aiPacketHandleOffsets
[0x1000];
/* 0x005cd020 */
149
int
g_nPacketHandleCount
;
/* 0x005d1020 */
void
void(__cdecl *g_pIxFree)(void *)
GetLargestFreeMemoryBlock
unsigned int GetLargestFreeMemoryBlock(void)
Definition
eventmgr.c:1515
TimerResetHook
void TimerResetHook(void)
Definition
eventmgr.c:1485
IsPushedPacketHandle
int IsPushedPacketHandle(void *handle)
Definition
memapi.c:53
PushMemoryStackFrame
void * PushMemoryStackFrame(void *memory, int offset)
Definition
memapi.c:30
AllocateGuardedMemory
void * AllocateGuardedMemory(unsigned int size)
Definition
winmain.c:757
GetLargestFreeMemoryBlockByType
unsigned int GetLargestFreeMemoryBlockByType(short memoryType)
Definition
memapi.c:139
FreeGuardedAllocation
void FreeGuardedAllocation(void *memory)
Definition
winmain.c:908
AllocateTaggedMemory
void * AllocateTaggedMemory(unsigned int size, short flags)
Definition
memapi.c:92
IsSoundHardwarePresent
unsigned short IsSoundHardwarePresent(short device)
Definition
memapi.c:17
ClearMemoryHeaps
void ClearMemoryHeaps(void)
Definition
memapi.c:11
MapPacketHandleToBlock
void * MapPacketHandleToBlock(void *handle)
Definition
memapi.c:66
ReleasePacketHandle
void ReleasePacketHandle(void *handle)
Definition
memapi.c:108
GetAvailableFarMemoryByType
unsigned int GetAvailableFarMemoryByType(short memoryType)
Definition
memapi.c:132
TimerStopHook
void TimerStopHook(void)
Definition
eventmgr.c:1503
exit_squadron
void exit_squadron(const char *msg,...)
Definition
message.c:44
MessagePumpHook
void MessagePumpHook(int mode)
Definition
memapi.c:24
EnableHighMemoryResources
unsigned short EnableHighMemoryResources(void)
Definition
eventmgr.c:1456
GetAvailableFarMemory
unsigned int GetAvailableFarMemory(void)
Definition
eventmgr.c:1509
game.h
Shared Win32 declarations, types and library interfaces.
g_aiPacketHandleOffsets
int g_aiPacketHandleOffsets[0x1000]
Definition
memapi.c:148
g_9_apPacketHandlesTable
void * g_9_apPacketHandlesTable[0x1000]
Definition
memapi.c:147
g_nPacketHandleCount
int g_nPacketHandleCount
Definition
memapi.c:149
g_apPacketReferenceGroups
void ** g_apPacketReferenceGroups[5]
Definition
mission.c:10
g_abTaggedAllocationPrefix
unsigned char g_abTaggedAllocationPrefix[8]
Definition
optmenu.c:8
src
memapi.c
Generated by
1.18.0