Wing Commander II
Reconstructed Win32 source (1996)
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. */
12{
14}
15
16/* Function start: 0x458E20 */
17unsigned short IsSoundHardwarePresent(short device)
18{
20 return 1;
21}
22
23/* Function start: 0x458E39 */
24void MessagePumpHook(int mode)
25{
27}
28
29/* Function start: 0x458E49 */
30void *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");
37 g_nPacketHandleCount] = offset;
38 if (offset < 0) {
39 memory = (unsigned char *)memory - offset;
41 g_nPacketHandleCount] = memory;
42 } else {
43 memory = (unsigned char *)memory + offset;
45 g_nPacketHandleCount] = memory;
46 }
48 }
49 return memory;
50}
51
52/* Function start: 0x458EED */
53int 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 */
66void *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 +
75 else
76 handle = (unsigned char *)handle -
84 return MapPacketHandleToBlock(handle);
85 }
86 }
87 return handle;
88}
89
90#pragma function(memcpy)
91/* Function start: 0x45901D */
92void *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,
102 memory = PushMemoryStackFrame(memory, -8);
103 }
104 return memory;
105}
106
107/* Function start: 0x459082 */
108void 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. */
132unsigned int GetAvailableFarMemoryByType(short memoryType)
133{
134 (void)memoryType;
135 return GetAvailableFarMemory();
136}
137
138/* Function start: 0x459149 */
139unsigned int GetLargestFreeMemoryBlockByType(short memoryType)
140{
141 (void)memoryType;
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. */
147void *g_9_apPacketHandlesTable[0x1000]; /* 0x005c9020 */
148int g_aiPacketHandleOffsets[0x1000]; /* 0x005cd020 */
149int g_nPacketHandleCount; /* 0x005d1020 */
void(__cdecl *g_pIxFree)(void *)
unsigned int GetLargestFreeMemoryBlock(void)
Definition eventmgr.c:1515
void TimerResetHook(void)
Definition eventmgr.c:1485
int IsPushedPacketHandle(void *handle)
Definition memapi.c:53
void * PushMemoryStackFrame(void *memory, int offset)
Definition memapi.c:30
void * AllocateGuardedMemory(unsigned int size)
Definition winmain.c:757
unsigned int GetLargestFreeMemoryBlockByType(short memoryType)
Definition memapi.c:139
void FreeGuardedAllocation(void *memory)
Definition winmain.c:908
void * AllocateTaggedMemory(unsigned int size, short flags)
Definition memapi.c:92
unsigned short IsSoundHardwarePresent(short device)
Definition memapi.c:17
void ClearMemoryHeaps(void)
Definition memapi.c:11
void * MapPacketHandleToBlock(void *handle)
Definition memapi.c:66
void ReleasePacketHandle(void *handle)
Definition memapi.c:108
unsigned int GetAvailableFarMemoryByType(short memoryType)
Definition memapi.c:132
void TimerStopHook(void)
Definition eventmgr.c:1503
void exit_squadron(const char *msg,...)
Definition message.c:44
void MessagePumpHook(int mode)
Definition memapi.c:24
unsigned short EnableHighMemoryResources(void)
Definition eventmgr.c:1456
unsigned int GetAvailableFarMemory(void)
Definition eventmgr.c:1509
Shared Win32 declarations, types and library interfaces.
int g_aiPacketHandleOffsets[0x1000]
Definition memapi.c:148
void * g_9_apPacketHandlesTable[0x1000]
Definition memapi.c:147
int g_nPacketHandleCount
Definition memapi.c:149
void ** g_apPacketReferenceGroups[5]
Definition mission.c:10
unsigned char g_abTaggedAllocationPrefix[8]
Definition optmenu.c:8