Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
eventmgr.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup shell
4 * @brief Event manager, mouse pointer and frame timer.
5 *
6 * Address range 4355f0-436cff. The FM Towns executable preserves this unit's
7 * original source name, `source\eventmgr.c`.
8 */
9#include "wc1.h"
10#include <malloc.h>
11#include <sys/types.h>
12
13/* The SDL renderer also reads the saved cursor background. */
14static
15unsigned char abCursorSaveArea[0x1000]; /* 0x004865a8 */
16
17/* Linker commons defined here; LINK orders them by identifier hash. */
18InputEvent aInputEvtPool[0x100]; /* 0x00598c40 */
19int nMouseCursorSavedCoordY; /* 0x0059a840 */
20int nMouseCursorSavedX; /* 0x0059a844 */
21unsigned char bInputModeState; /* 0x0059a848 */
22unsigned char bFilteredKeyWaitActive; /* 0x0059a849 */
23int bEventMouseCursorDrawnFlag; /* 0x0059a84c */
24short nEventManagerActive; /* 0x0059a850 */
25short nCurrentViewCenterPosX; /* 0x0059a852 */
26short nCurrentViewCenterPosY; /* 0x0059a854 */
27short bCurrentExpandedMemoryAvail; /* 0x0059a856 */
28short nPktDecompressSourceFile; /* 0x0059a858 */
29unsigned char abInputKeyStateArray[0x80]; /* 0x0059a860 */
30int nMousePointerDrawnY; /* 0x0059a8e0 */
31int nMousePointerDrawnX; /* 0x0059a8e4 */
34
35/* Function start: 0x4355F0 */
36void TranslatePolledInputEvent(unsigned short type, unsigned int value)
37{
38 InputDeviceSample *samples;
39 unsigned int state;
40
41 switch (type) {
42 case 2:
43 state = (value >> 2) |
48 state);
49 return;
50 case 6:
51 samples = aInputDevSamples;
53 samples[nCurrentActiveInputDevice].y, 0, 0, 0, 0);
54 return;
55 case 13:
57 0, 0, 0, 0);
58 return;
59 }
60}
61
62/* Function start: 0x4356A0 */
63void QueueInputEventAtCursor(unsigned short type, short primaryButton,
64 short secondaryButton)
65{
66 int eventType = type;
67
69 primaryButton, secondaryButton, 0);
70}
71
72/* Function start: 0x4356E0 */
74{
75 int *used;
76 int index;
77
79 index = 0;
81 do {
82 if (*used == 0) {
84 return &aInputEvtPool[index];
85 }
86 used++;
87 index++;
88 } while (used < &aiInputEventSlotUsedTable[0x100]);
89 return 0;
90 }
91 memset(aInputEvtPool, 0,
92 sizeof(aInputEvtPool));
97 return &aInputEvtPool[0];
98}
99
100/* Function start: 0x435760 */
102{
103 int *used;
104 int slot;
105
107 for (slot = 0; slot < 0x100; used++, slot++) {
108 if (&aInputEvtPool[slot] == event)
109 *used = 0;
110 }
111}
112
113/* Function start: 0x435790 */
114void QueueInputEvent(int type, int x, int y, int value,
115 int primaryButton, int secondaryButton,
116 unsigned int timestamp)
117{
118 unsigned int modifiers;
119 InputEvent *event;
120
121 modifiers = 0;
122 if (GetShiftKeyState() != 0)
123 modifiers = 0xe0;
124 if (GetControlKeyState() != 0)
125 modifiers |= 0x2000;
126 if (GetKeyboardModifiers() != 0)
127 modifiers |= 0x700;
128 if (primaryButton != 0)
129 modifiers |= 2;
130 if (secondaryButton != 0)
131 modifiers |= 4;
132
133 if (pInputEventHead == 0) {
135 if (pInputEventHead == 0) {
137 return;
138 }
142 } else {
143 event = AllocateInputEvent();
144 pInputEventTail->next = event;
145 if (pInputEventTail->next == 0) {
147 return;
148 }
153 }
154 pInputEventTail->type = type;
155 pInputEventTail->modifiers = modifiers;
156 pInputEventTail->x = x;
157 pInputEventTail->y = y;
158 pInputEventTail->value = value;
159 pInputEventTail->primaryButton = (short)primaryButton;
160 pInputEventTail->secondaryButton = (short)secondaryButton;
161}
162
163/* Function start: 0x4358B0 */
165{
167
168 while (event != 0) {
169 InputEvent *next = event->next;
170
171 ReleaseInputEvent(event);
172 event = next;
173 }
174 pInputEventTail = 0;
175 pInputEventHead = 0;
176}
177
178/* Function start: 0x4358E0 */
180{
182
183 while (event != 0) {
184 InputEvent *next = event->next;
185
186 if (event->type != type) {
187 if (event->previous != 0)
188 event->previous->next = next;
189 else
190 pInputEventHead = next;
191 if (event->next != 0)
192 event->next->previous = event->previous;
193 else
194 pInputEventTail = event->previous;
195 ReleaseInputEvent(event);
196 }
197 event = next;
198 }
199}
200
201/* Function start: 0x435940 */
203{
204 if (event->previous != 0) {
205 if (event->next != 0) {
206 event->previous->next = event->next;
207 event->next->previous = event->previous;
208 ReleaseInputEvent(event);
209 return;
210 }
211 event->previous->next = 0;
212 pInputEventTail = event->previous;
213 ReleaseInputEvent(event);
214 return;
215 }
216 if (event->next != 0) {
217 pInputEventHead = event->next;
218 event->next->previous = 0;
219 ReleaseInputEvent(event);
220 return;
221 }
222 pInputEventTail = 0;
223 pInputEventHead = 0;
224 ReleaseInputEvent(event);
225}
226
227/* Function start: 0x4359C0 */
228short __stdcall GetNextInputEvent(InputEventState *state)
229{
230 int eventX;
231 int eventY;
232 short limit;
233 int type;
234
235 type = 0;
236 if (pInputEventHead != 0) {
237 eventX = pInputEventHead->x;
238 eventY = pInputEventHead->y;
240 if (limit > eventX)
241 pInputEventHead->x = limit;
242 else {
244 if (limit < eventX)
245 pInputEventHead->x = limit;
246 }
248 if (limit > eventY)
249 pInputEventHead->y = limit;
250 else {
252 if (limit < eventY)
253 pInputEventHead->y = limit;
254 }
255
256 state->modifiers =
258 switch (pInputEventHead->type) {
259 case 1:
263 state->x = pInputEventHead->x;
264 state->y = pInputEventHead->y;
265 type = 1;
266 break;
267 case 2:
271 (unsigned char)pInputEventHead->primaryButton;
273 (unsigned char)pInputEventHead->secondaryButton;
274 state->x = pInputEventHead->x;
275 state->y = pInputEventHead->y;
276 type = 2;
277 state->value =
280 break;
281 case 3:
282 state->value = pInputEventHead->value;
283 state->x = stMouseCursorState.x;
284 state->y = stMouseCursorState.y;
285 type = 3;
286 break;
287 case 4:
288 state->x = pInputEventHead->value;
289 state->x = stMouseCursorState.x;
290 state->y = stMouseCursorState.y;
291 type = 4;
292 break;
293 case 5:
294 state->x = pInputEventHead->value;
295 type = 5;
296 break;
297 case 6:
298 state->x = pInputEventHead->x;
299 state->y = pInputEventHead->y;
300 type = 6;
301 break;
302 case 7:
303 state->x = pInputEventHead->x;
304 state->y = pInputEventHead->y;
305 type = 7;
306 break;
307 case 8:
308 state->x = pInputEventHead->x;
309 state->y = pInputEventHead->y;
310 type = 8;
311 break;
312 case 9:
313 state->x = pInputEventHead->x;
314 state->y = pInputEventHead->y;
315 type = 9;
316 break;
317 case 10:
318 state->x = pInputEventHead->x;
319 state->y = pInputEventHead->y;
320 type = 10;
321 break;
322 case 13:
325 state->x = pInputEventHead->x;
326 state->y = pInputEventHead->y;
327 type = 13;
328 break;
329 }
331 }
332 return type;
333}
334
335/* Function start: 0x435CC0 */
336short __stdcall PollInputEvent(InputEventState *event, short filter)
337{
339 return GetNextInputEvent(event);
340}
341
342/* Function start: 0x435CE0 */
343short __stdcall PeekInputEvent(InputEventState *state, short type)
344{
345 InputEvent *event;
346 int eventType;
347 int modifiers;
348
349 event = pInputEventHead;
350 modifiers = 0;
351 while (event != 0 && event->type != type)
352 event = event->next;
353 if (event != 0) {
354 state->type = event->type;
355 state->value = event->modifiers;
356 state->timestamp = event->timestamp;
357 eventType = (int)event->type;
358 if (eventType == 2 || eventType == 1)
359 modifiers = 1;
360 modifiers |= ((unsigned short)event->primaryButton < 1 ? 0 : -1) & 2;
361 modifiers |= ((unsigned short)event->secondaryButton < 1 ? 0 : -1) & 4;
362 state->modifiers = (short)modifiers;
363 state->x = event->x;
364 state->y = event->y;
365 return 1;
366 }
367 return 0;
368}
369
370/* Function start: 0x435D80 */
371short __stdcall IsInputEventQueued(short type)
372{
374
375 while (event != 0 && event->type != type)
376 event = event->next;
377 return event != 0;
378}
379
380/* Function start: 0x435DB0 */
382{
384}
385
386/* Function start: 0x435DC0 */
387short __stdcall ResetAllocationDepth(int x, int y)
388{
389 (void)x;
390 (void)y;
392 return 1;
393}
394
395/* Function start: 0x435DD0 */
396/* Returns 1. Nothing in the shipped executable calls it; reporting an
397 * installed mouse is inferred only from its place after the mouse-reset
398 * stand-in at 0x435DC0, which also returns 1. */
400{
401 return 1;
402}
403
404/* Function start: 0x435DE0 */
405void CheckCursor(void)
406{
407}
408
409/* Function start: 0x435DF0 */
410/* Empty in the Win32 build; the hidden kill-board code at 0x43F8B0 calls it. */
412{
413}
414
415/* Function start: 0x435E00 */
416/* Empty. Nothing in the shipped executable calls it, so its purpose
417 * cannot be recovered; it sits between the cursor hooks and the cursor
418 * drawing routines. */
420{
421}
422
423/* Function start: 0x435E10 */
424/* Empty. Nothing in the shipped executable calls it, so its purpose
425 * cannot be recovered; it immediately precedes the cursor background
426 * capture. */
428{
429}
430
431/* Function start: 0x435E20 */
463
464/* Function start: 0x435EF0 */
492
493/* Function start: 0x435FA0 */
523
524/* Function start: 0x436060 */
541
542/* Function start: 0x4360C0 */
543/* Empty. Nothing in the shipped executable calls it, so its purpose
544 * cannot be recovered; it follows the cursor display refresh. */
546{
547}
548
549/* Function start: 0x4360D0 */
554
555/* Function start: 0x4360E0 */
560
561/* Function start: 0x4360F0 */
579
580/* Function start: 0x436160 */
581void __stdcall SetMouseHomePosition(short x, short y)
582{
586}
587
588/* Function start: 0x436190 */
590{
591 stMouseCursorState.x = point.x;
592 stMouseCursorState.y = point.y;
593 SetMousePositionDuplicate(point.x, point.y);
594}
595
596/* Function start: 0x4361C0 */
597void __stdcall GetMouseCursorPosition(ShortPoint *point)
598{
599 point->x = stMouseCursorState.x;
600 point->y = stMouseCursorState.y;
601}
602
603/* Function start: 0x4361E0 */
604void SetFrameTimerPeriod(short period)
605{
606 SetMultimediaTimerCallback((int)period);
607}
608
609/* Function start: 0x4361F0 */
610void __stdcall SetFrameTimerAndWait(short period)
611{
612 SetFrameTimerPeriod(period);
614}
615
616/* Function start: 0x436210 */
617void __stdcall SetFrameTimerPeriodDirect(short p)
618{
620}
621
622/* Function start: 0x436230 */
624{
625 while (bFrameTickPendingFlag != 0) ;
626}
627
628/* Function start: 0x436240 */
630{
631 return bFrameTickPendingFlag == 0;
632}
633
634/* Function start: 0x436250 */
635/* Empty. Nothing in the shipped executable calls it, so its purpose
636 * cannot be recovered; it follows the frame-tick queries. */
638{
639}
640
641/* Function start: 0x436260 */
642unsigned short GetSoundHardwareFlag(void)
643{
644 return 1;
645}
646
647/* Function start: 0x436270 */
648void *AllocateUntaggedMemory(unsigned int size)
649{
650 return AllocateTaggedMemory(size, 0);
651}
652
653/* Function start: 0x436280 */
654/* Returns 0. Nothing in the shipped executable calls it, so its purpose
655 * cannot be recovered; it sits between the untagged allocation and release
656 * stand-ins. */
658{
659 return 0;
660}
661
662/* Function start: 0x436290 */
663void ReleaseUntaggedMemory(void *memory)
664{
665 ReleasePacketHandle(memory);
666}
667
668/* Function start: 0x4362A0 */
670{
671}
672
673/* Function start: 0x4362B0 */
674unsigned int GetPacketDecompressionResult(void *packet)
675{
676 (void)packet;
677 return 0;
678}
679
680/* Function start: 0x4362C0 */
681unsigned short IdentityWord(unsigned short v)
682{
683 return v;
684}
685
686/* Function start: 0x4362D0 */
688{
689}
690
691/* Function start: 0x4362E0 */
692unsigned int GetFixedOneMillion(void)
693{
694 return 0x3e8000;
695}
696
697/* Function start: 0x4362F0 */
698unsigned int GetFixedOneMillionAlt(void)
699{
700 return 0x3e8000;
701}
702
703/* Function start: 0x436300 */
704/* Returns 0. Nothing in the shipped executable calls it, so its purpose
705 * cannot be recovered; it follows the free-memory stand-ins that the memory
706 * manager reaches through 0x42FB20 and 0x42FB30. The role words of this
707 * and the following eight names only distinguish the entries. */
708int __stdcall MemoryServiceQueryHook(int value)
709{
710 (void)value;
711 return 0;
712}
713
714/* Function start: 0x436310 */
715/* Empty. Nothing in the shipped executable calls it, so its purpose
716 * cannot be recovered; it sits among the memory-service stand-ins. */
717void __stdcall MemoryServiceReleaseHook(int value)
718{
719 (void)value;
720}
721
722/* Function start: 0x436320 */
723/* Returns 0. Nothing in the shipped executable calls it, so its purpose
724 * cannot be recovered; it sits among the memory-service stand-ins. */
725int __stdcall MemoryServiceTransferHook(int first, int second)
726{
727 (void)first;
728 (void)second;
729 return 0;
730}
731
732/* Function start: 0x436330 */
733/* Returns 0. Nothing in the shipped executable calls it, so its purpose
734 * cannot be recovered; it sits among the memory-service stand-ins. */
735int __stdcall MemoryServiceMapHook(int value)
736{
737 (void)value;
738 return 0;
739}
740
741/* Function start: 0x436340 */
742/* Returns 0. Nothing in the shipped executable calls it, so its purpose
743 * cannot be recovered; it sits among the memory-service stand-ins. */
745{
746 return 0;
747}
748
749/* Function start: 0x436350 */
750/* Empty. Nothing in the shipped executable calls it, so its purpose
751 * cannot be recovered; it sits among the memory-service stand-ins. */
753{
754}
755
756/* Function start: 0x436360 */
757/* Returns 0. Nothing in the shipped executable calls it, so its purpose
758 * cannot be recovered; it sits among the memory-service stand-ins. */
760{
761 return 0;
762}
763
764/* Function start: 0x436370 */
765/* Returns 0. Nothing in the shipped executable calls it, so its purpose
766 * cannot be recovered; it sits among the memory-service stand-ins. */
768{
769 return 0;
770}
771
772/* Function start: 0x436380 */
773/* Returns 0. Nothing in the shipped executable calls it, so its purpose
774 * cannot be recovered; it is the last of the memory-service stand-ins. */
776{
777 return 0;
778}
779
780/* Function start: 0x436390 */
785
786/* Function start: 0x4363A0 */
788{
789 unsigned int control = abInputKeyStateArray[0x1d];
790 unsigned int alt = abInputKeyStateArray[0x38];
791
792 memset(abInputKeyStateArray, 0,
793 sizeof(abInputKeyStateArray));
794 abInputKeyStateArray[0x1d] = control;
795 abInputKeyStateArray[0x38] = alt;
797}
798
799/* Function start: 0x4363E0 */
801{
802 memset(abInputKeyStateArray, 0,
803 sizeof(abInputKeyStateArray));
805}
806
807/* Function start: 0x436400 */
808/* Empty. Nothing in the shipped executable calls it, so its purpose
809 * cannot be recovered; it follows the key-state clearing routines. */
811{
812}
813
814/* Function start: 0x436410 */
815/* Empty. Nothing in the shipped executable calls it, so its purpose
816 * cannot be recovered; it precedes the key-state setter. */
818{
819}
820
821/* Function start: 0x436420 */
822void SetInputKeyState(int scanCode, unsigned char pressed)
823{
824 if (scanCode >= 0 && scanCode < 0x80) {
825 abInputKeyStateArray[scanCode] = pressed;
826 return;
827 }
828 SystemDebugPrintf("keyboard almost messed up\n");
831 exit(1);
832}
833
834/* Function start: 0x436460 */
836{
837 int previous;
838 unsigned int distance;
839 int bestObject;
840 int obj;
841 int *placed;
842 int screenOffset;
843 int best;
844 int *sortedEntry;
845 int sorted;
846
847 previous = -999999999;
848 bestObject = -1;
851 obj = 0;
852 for (; obj < SPACE_OBJECT_COUNT; obj++) {
853 distance = asObjDistancesTable[obj];
854 if (previous < (int)distance) {
855 previous = (int)distance;
856 bestObject = obj;
857 }
858 }
859 sorted = 0;
860 sortedEntry = anSortedObjects;
861 for (; sorted < SPACE_OBJECT_COUNT; sorted++, sortedEntry++) {
862 *sortedEntry = bestObject;
863 best = -1;
864 if (bestObject == -1)
865 return;
866 screenOffset = 0;
867 obj = 0;
868 anEventObjectDepthPlacedList[bestObject] = 1;
869 bestObject = -1;
871 for (; placed < anEventObjectDepthPlacedList +
873 screenOffset += sizeof(short), placed++, obj++) {
874 if (*placed == 0 &&
875 *(short *)((unsigned char *)asObjectScreenXList +
876 screenOffset) != (short)0x8001) {
877 distance = *(unsigned short *)(
878 (unsigned char *)asObjDistancesTable +
879 screenOffset);
880 if (best < (int)distance && previous >= (int)distance) {
881 bestObject = obj;
882 best = (int)distance;
883 }
884 }
885 }
886 }
887}
888
889/* Function start: 0x436520 */
891{
892 int *sortedEntry;
893 int obj;
894 int objectClass;
895 struct Shape *shape;
896 short screenY;
897 short screenX;
898 int specialObject;
899
900 sortedEntry = anSortedObjects;
901 do {
902 obj = *sortedEntry;
903 if (obj < 0)
904 return;
905 if ((int)aeObjectTypeList[obj] < 0)
906 return;
907 objectClass = aeObjectClass[obj];
908 if (objectClass != OBJECT_CLASS_NULL) {
909 switch (objectClass) {
910 default: {
911 short objectX;
912 short objectY;
913 struct Shape *objectShape;
914
915 objectX = asObjectScreenXList[obj];
916 objectY = *(short volatile *)&asObjectScreenYArray[obj];
917 objectX = (short)(objectX +
919 objectShape = *(struct Shape *volatile *)&apObjShapeArray[obj];
920 asObjectDrawPosX[obj] = objectX;
921 objectY = (short)(objectY +
923 asObjectDrawPosY[obj] = objectY;
924 if (objectShape != 0) {
926 &stSpaceBufferViewport, objectX, objectY, objectShape,
930 asObjectFlipArray[obj]);
931 }
932 break;
933 }
937 specialObject = (int)nNavPointerObject;
938 screenY = asObjectScreenYArray[obj];
939 screenX = (short)(asObjectScreenXList[obj] +
941 asObjectDrawPosX[obj] = screenX;
942 screenY = (short)(screenY + nCurrentViewCenterPosY);
943 asObjectDrawPosY[obj] = screenY;
944 if (specialObject == obj) {
945 shape = apObjShapeArray[obj];
946 DrawSpriteDefault(&stSpaceBufferViewport, screenX, screenY, shape,
947 asObjectViewFrames[obj]);
948 } else {
950 DrawSpriteDefault(&stSpaceBufferViewport, screenX, screenY, shape,
951 asObjectViewFrames[obj]);
952 }
953 break;
954 }
955 }
956 sortedEntry++;
957 } while (sortedEntry < anSortedObjects +
959}
960
961/* Function start: 0x436650 */
963{
964 struct Shape *shape;
965 int objectClass;
966 int obj;
967
968 for (obj = 0; obj < SPACE_OBJECT_COUNT; obj++) {
969 if (aeObjectTypeList[obj] < 0)
970 return;
971 objectClass = aeObjectClass[obj];
972 if (objectClass != OBJECT_CLASS_NULL) {
973 switch (objectClass) {
974 default:
975 shape = apObjShapeArray[obj];
976 if (shape != 0) {
979 asObjectDrawPosX[obj],
980 asObjectDrawPosY[obj],
981 shape,
987 }
988 break;
992 if (obj == nNavPointerObject) {
995 asObjectDrawPosX[obj],
996 asObjectDrawPosY[obj],
997 apObjShapeArray[obj],
1000 } else {
1003 asObjectDrawPosX[obj],
1004 asObjectDrawPosY[obj],
1006 asObjectViewFrames[obj],
1008 }
1009 break;
1010 }
1011 }
1012 }
1013}
1014
1015/* Function start: 0x436740 */
1016void set_up_screen_viewport(signed char mode)
1017{
1018 cScreenViewMode = mode;
1019 switch (mode) {
1020 case 4:
1021 case 5:
1024 break;
1025 default:
1027 (const ScreenViewportGeometry *)(
1028 (const unsigned char *)pCurrentScreenViewportPkt +
1030 ->geometryOffsets[mode]);
1031 break;
1032 }
1033
1034 if (bCockpitlessView != 0 && bCockpitlessView != -2) {
1036 nCurrentViewCenterPosX = (short)(nScreenWidth / 2);
1041 switch ((int)cCurrentCockpitView) {
1042 case 0:
1045 break;
1046 case 1:
1049 break;
1050 case 2:
1053 break;
1054 }
1055 nScreenWidth = 320;
1056 nScreenHeight = 200;
1057 return;
1058 }
1059
1061 nCurrentViewCenterPosX = (short)(nScreenWidth / 2);
1066}
1067
1068/* Function start: 0x436890 */
1069/* Returns 0. Nothing in the shipped executable calls it, so its purpose
1070 * cannot be recovered; it follows set_up_screen_viewport. */
1072{
1073 return 0;
1074}
1075
1076/* Function start: 0x4368A0 */
1077/* Empty. Nothing in the shipped executable calls it, so its purpose
1078 * cannot be recovered; it follows set_up_screen_viewport. */
1080{
1081}
1082
1083/* Function start: 0x4368B0 */
1084/* Empty. Nothing in the shipped executable calls it, so its purpose
1085 * cannot be recovered; it precedes the mouse idle hook. */
1087{
1088}
1089
1090/* Function start: 0x4368C0 */
1092{
1093}
1094
1095/* The startup code installs this distinct empty entry for vector 0x21. */
1096/* Function start: 0x4368D0 */
1098{
1099}
1100
1101/* Function start: 0x4368E0 */
1102unsigned short GetNavRangeSentinel(void)
1103{
1104 return 0x8000;
1105}
1106
1107/* Function start: 0x4368F0 */
1108unsigned short GetOriginalFreeMemory(void)
1109{
1110 return 0x8000;
1111}
1112
1113/* Function start: 0x436900 */
1114void StartupHook(unsigned int (*callback)(unsigned int, short))
1115{
1116 (void)callback;
1117}
1118
1119/* Function start: 0x436910 */
1120unsigned int JoystickEdgeHook(int button)
1121{
1122 (void)button;
1123}
1124
1125/* Function start: 0x436920 */
1126/* Returns 0. Nothing in the shipped executable calls it, so its purpose
1127 * cannot be recovered; it follows the joystick edge hook. */
1129{
1130 return 0;
1131}
1132
1133/* Function start: 0x436930 */
1134/* Empty. Nothing in the shipped executable calls it, so its purpose
1135 * cannot be recovered; it follows the joystick edge hook. */
1137{
1138}
1139
1140/* Function start: 0x436940 */
1142{
1143 return malloc(size);
1144}
1145
1146/* Function start: 0x436950 */
1147void FreeIfNotNull(void *p)
1148{
1149 if (p != 0)
1150 free(p);
1151}
1152
1153/* Function start: 0x436970 */
1154unsigned int GetStartupErrorCode(int vector)
1155{
1156 (void)vector;
1157 return 0;
1158}
1159
1160/* Function start: 0x436980 */
1161void ShutdownHook(int vector, void *handler)
1162{
1163 (void)vector;
1164 (void)handler;
1165}
1166
1167/* Function start: 0x436990 */
1168/* Empty. Nothing in the shipped executable calls it, so its purpose
1169 * cannot be recovered; it follows the vector-restoring shutdown hook. */
1171{
1172}
1173
1174/* Function start: 0x4369A0 */
1175unsigned short __stdcall SelectDiskDriveHook(short drive)
1176{
1177 return 0;
1178}
1179
1180/* Function start: 0x4369B0 */
1182{
1183 return 0;
1184}
1185
1186/* Function start: 0x4369C0 */
1187unsigned short __stdcall GetShutdownErrorCode(unsigned char *driveState)
1188{
1189 (void)driveState;
1190 return 0;
1191}
1192
1193/* Function start: 0x4369D0 */
1195{
1196}
1197
1198/* Function start: 0x4369E0 */
1200{
1201}
1202
1203/* Function start: 0x4369F0 */
1204/* Returns 0. Nothing in the shipped executable calls it, so its purpose
1205 * cannot be recovered; it follows the exit cleanup hook. */
1207{
1208 return 0;
1209}
1210
1211/* Function start: 0x436A00 */
1212unsigned int IsVectorWithinRange(FixedVector *vector, short range)
1213{
1214 int magnitude = Vector_magnitude(vector);
1215
1216 if (abs((int)range << 8) >= magnitude)
1217 return 1;
1218 return 0;
1219}
1220
1221/* Function start: 0x436A30 */
1222unsigned int shrink_vector(FixedVector *vector)
1223{
1224 unsigned int shrinking;
1225
1226 do {
1227 shrinking = shrink(&vector->x);
1228 shrinking |= shrink(&vector->y);
1229 shrinking |= shrink(&vector->z);
1230 } while (shrinking != 0);
1231 return 0;
1232}
1233
1234/* Function start: 0x436A70 */
1235unsigned int shrink(int *component)
1236{
1237 int value;
1238 unsigned int fraction;
1239 unsigned int integerPart;
1240 short signedIntegerPart;
1241
1242 value = *component / 2;
1243 *component = value;
1244 fraction = value;
1245 integerPart = (unsigned int)value >> 16;
1246 signedIntegerPart = (short)integerPart;
1247 if (signedIntegerPart == 0)
1248 return (unsigned short)fraction > 0x0f00;
1249 if (signedIntegerPart == -1)
1250 return (unsigned short)fraction < 0xf100;
1251 if (signedIntegerPart != 0)
1252 integerPart = 1;
1253 return integerPart;
1254}
1255
1256/* Function start: 0x436AC0 */
1257short __stdcall GetViewportIntersection(ShortRect *intersection,
1258 const ShortRect *first,
1259 const ShortRect *second)
1260{
1261 int pointCount;
1262 int pointIndex;
1263 int xCoordinates[16];
1264 int yCoordinates[16];
1265 int inside[4];
1266 int x;
1267 int insideCount;
1268 int y;
1269
1270 pointCount = 0;
1271 xCoordinates[pointCount] = first->left;
1272 yCoordinates[pointCount] = first->top;
1273 pointCount++;
1274 xCoordinates[pointCount] = first->left;
1275 yCoordinates[pointCount] = first->bottom;
1276 pointCount++;
1277 xCoordinates[pointCount] = first->right;
1278 yCoordinates[pointCount] = first->top;
1279 pointCount++;
1280 xCoordinates[pointCount] = first->right;
1281 yCoordinates[pointCount] = first->bottom;
1282 pointCount++;
1283 xCoordinates[pointCount] = second->left;
1284 yCoordinates[pointCount] = second->top;
1285 pointCount++;
1286 xCoordinates[pointCount] = second->left;
1287 yCoordinates[pointCount] = second->bottom;
1288 pointCount++;
1289 xCoordinates[pointCount] = second->right;
1290 yCoordinates[pointCount] = second->top;
1291 pointCount++;
1292 xCoordinates[pointCount] = second->right;
1293 yCoordinates[pointCount] = second->bottom;
1294 pointCount++;
1295 xCoordinates[pointCount] = first->left;
1296 yCoordinates[pointCount] = second->top;
1297 pointCount++;
1298 xCoordinates[pointCount] = first->left;
1299 yCoordinates[pointCount] = second->bottom;
1300 pointCount++;
1301 xCoordinates[pointCount] = first->right;
1302 yCoordinates[pointCount] = second->top;
1303 pointCount++;
1304 xCoordinates[pointCount] = first->right;
1305 yCoordinates[pointCount] = second->bottom;
1306 pointCount++;
1307 xCoordinates[pointCount] = second->left;
1308 yCoordinates[pointCount] = first->top;
1309 pointCount++;
1310 xCoordinates[pointCount] = second->left;
1311 yCoordinates[pointCount] = first->bottom;
1312 pointCount++;
1313 xCoordinates[pointCount] = second->right;
1314 yCoordinates[pointCount] = first->top;
1315 pointCount++;
1316 xCoordinates[pointCount] = second->right;
1317 yCoordinates[pointCount] = first->bottom;
1318 pointCount++;
1319
1320 /* The original tests the postincrement and discards the comparison.
1321 * insideCount and inside remain uninitialized when this loop exits. */
1322 for (pointIndex = 0; pointIndex++; pointIndex < pointCount) {
1323 x = xCoordinates[pointIndex];
1324 y = yCoordinates[pointIndex];
1325 if (first->left <= x && x <= first->right &&
1326 second->left <= x && x <= second->right &&
1327 first->top <= y && y <= first->bottom &&
1328 second->top <= y && y <= second->bottom) {
1329 if (insideCount == 4)
1330 return 0;
1331 inside[insideCount] = 1;
1332 insideCount++;
1333 } else {
1334 if (insideCount == 4)
1335 return 0;
1336 inside[insideCount] = 0;
1337 insideCount++;
1338 }
1339 }
1340 if (insideCount != 4)
1341 return 0;
1342
1343 intersection->left = MinShort(
1344 (short)xCoordinates[inside[0]],
1345 MinShort((short)xCoordinates[inside[1]],
1346 (short)xCoordinates[inside[2]]));
1347 intersection->top = MinShort(
1348 (short)yCoordinates[inside[0]],
1349 MinShort((short)yCoordinates[inside[1]],
1350 (short)yCoordinates[inside[2]]));
1351 intersection->left = MaxShort(
1352 (short)xCoordinates[inside[0]],
1353 MaxShort((short)xCoordinates[inside[1]],
1354 (short)xCoordinates[inside[2]]));
1355 intersection->top = MaxShort(
1356 (short)yCoordinates[inside[0]],
1357 MaxShort((short)yCoordinates[inside[1]],
1358 (short)yCoordinates[inside[2]]));
1359 return 1;
1360}
1361
1362/* Function start: 0x436C70 */
1363void __stdcall FillGraphicSuffix(char *path, short number, short digits)
1364{
1365 char *dot;
1366 char *suffix;
1367
1368 suffix = DosStrchr(path, '.');
1369 dot = suffix;
1370 suffix++;
1371 if (dot == 0)
1372 suffix = path;
1373 suffix[digits] = '\0';
1374 ConvertChar_Int(suffix, number, digits);
1375}
1376
1377/* Function start: 0x436CB0 */
1378void __stdcall ConvertChar_Int(char *text, short number, short digits)
1379{
1380 while (digits--) {
1381 text[digits] = (char)(number % 10) + '0';
1382 number /= 10;
1383 }
1384}
void(__cdecl *pIxFree)(void *)
void InterruptVectorHook(void)
Definition eventmgr.c:1170
short IsMouseInstalled(void)
Definition eventmgr.c:399
int __stdcall MemoryServiceTransferHook(int first, int second)
Definition eventmgr.c:725
void FrameTickHook(void)
Definition eventmgr.c:637
void JoystickResetHook(void)
Definition eventmgr.c:1136
int __stdcall MemoryServiceMapHook(int value)
Definition eventmgr.c:735
void __stdcall MemoryServiceReleaseHook(int value)
Definition eventmgr.c:717
void MouseCursorDisplayHook(void)
Definition eventmgr.c:545
short MemoryServiceResetHook(void)
Definition eventmgr.c:775
void KeyboardStateHook(void)
Definition eventmgr.c:810
int MemoryServiceStatusHook(void)
Definition eventmgr.c:759
void MouseActivityHook(void)
Definition eventmgr.c:1086
void MemoryServiceShutdownHook(void)
Definition eventmgr.c:752
void MouseCursorRedrawHook(void)
Definition eventmgr.c:419
short MemoryServiceVersionHook(void)
Definition eventmgr.c:744
void MouseCursorCaptureHook(void)
Definition eventmgr.c:427
void KeyboardScanHook(void)
Definition eventmgr.c:817
int __stdcall MemoryServiceQueryHook(int value)
Definition eventmgr.c:708
void RefreshMouseCursorHook(void)
Definition eventmgr.c:411
void ScreenViewportResetHook(void)
Definition eventmgr.c:1079
short MemoryServiceErrorHook(void)
Definition eventmgr.c:767
static unsigned char abCursorSaveArea[0x1000]
Definition eventmgr.c:15
int UntaggedMemoryHook(void)
Definition eventmgr.c:657
void ResetInputKeyStatePreservingModifiers(void)
Definition eventmgr.c:781
int ScreenViewportHook(void)
Definition eventmgr.c:1071
short __stdcall GetViewportIntersection(ShortRect *intersection, const ShortRect *first, const ShortRect *second)
Definition eventmgr.c:1257
void DosInterruptHandlerHook(void)
Definition eventmgr.c:1097
short ExitStatusHook(void)
Definition eventmgr.c:1206
short JoystickStatusHook(void)
Definition eventmgr.c:1128
InputDeviceSample aInputDevSamples[2]
Definition nav.c:78
short nNavPointerObject
Definition cockpt.c:71
short asObjectDrawPosX[SPACE_OBJECT_COUNT]
Definition video.c:19
short nViewportOriginPositionX
Definition mathfp.c:22
short asObjScreenScalesArray[SPACE_OBJECT_COUNT]
Definition dib.c:105
int anEventObjectDepthPlacedList[SPACE_OBJECT_COUNT]
Definition eventmgr.c:32
int nMouseCursorSavedCoordY
Definition eventmgr.c:19
short asObjScreenAngles[SPACE_OBJECT_COUNT]
Definition joycal.c:26
int nMouseCursorDamageRight
Definition mathfp.c:18
int nEventMousePointerDamageBottom
Definition mathfp.c:19
int bMouseCursorDamagePending
Definition mathfp.c:17
int nMousePointerDrawnY
Definition eventmgr.c:30
InputEvent * pInputEventTail
Definition data.c:22
short nPktDecompressSourceFile
Definition eventmgr.c:28
short nViewportOriginPositionY
Definition mathfp.c:21
const ScreenViewportGeometry * pScreenViewGeometry
Definition strdos.c:14
int bEventMouseCursorDrawnFlag
Definition eventmgr.c:23
ScreenViewportGeometry aScreenViewportGeometry[7]
Definition data.c:52
int bCockpitlessView
Definition main.c:39
int nMousePointerDamageTopValue
Definition mathfp.c:26
unsigned char bInputModeState
Definition eventmgr.c:21
short DAT_0059a9f0
Definition eventmgr.c:33
short asObjectDrawPosY[SPACE_OBJECT_COUNT]
Definition video.c:18
int nMousePointerDrawnX
Definition eventmgr.c:31
enum ObjectClass aeObjectClass[SPACE_OBJECT_COUNT]
Definition video.c:21
short bCurrentExpandedMemoryAvail
Definition eventmgr.c:27
int anSortedObjects[SPACE_OBJECT_COUNT]
Definition strdos.c:15
struct Shape * pCurrentConstellationShape
Definition timer.c:20
MouseCursorState stMouseCursorState
Definition strdos.c:19
short asObjectScreenYArray[SPACE_OBJECT_COUNT]
Definition screen.c:20
int nHostMouseMessageX
Definition auto.c:19
signed char cCurrentCockpitView
Definition screen.c:23
unsigned char cPrimaryViewBufferColour
Definition init.c:27
short nEventManagerActive
Definition eventmgr.c:24
short nCurrentViewCenterPosX
Definition eventmgr.c:25
unsigned char abInputKeyStateArray[0x80]
Definition eventmgr.c:29
InputEvent aInputEvtPool[0x100]
Definition eventmgr.c:18
int aiInputEventSlotUsedTable[0x100]
Definition data.c:242
short nScreenWidth
Definition data.c:34
unsigned short asObjDistancesTable[SPACE_OBJECT_COUNT]
Definition data.c:253
Viewport stSpaceBufferViewport
Definition timer.c:13
int nHostMouseMessageY
Definition mono.c:326
int nMouseCursorDamageLeft
Definition mathfp.c:25
short asObjectScreenXList[SPACE_OBJECT_COUNT]
Definition screen.c:21
int bHostPrimaryMouseButton
Definition mono.c:327
struct Shape * apObjShapeArray[SPACE_OBJECT_COUNT]
Definition comm.c:48
short nCurrentActiveInputDevice
Definition nav.c:60
signed char cScreenViewMode
Definition strdos.c:13
enum ObjectType aeObjectTypeList[SPACE_OBJECT_COUNT]
Definition data.c:255
short asObjectViewFrames[SPACE_OBJECT_COUNT]
Definition video.c:23
struct Shape * pDrawnMouseCursorShape
Definition data.c:28
int bHostSecondaryMouseButton
Definition mono.c:328
short asObjectFlipArray[SPACE_OBJECT_COUNT]
Definition dib.c:97
ScreenViewportPacket * pCurrentScreenViewportPkt
Definition launch.c:49
unsigned char bFilteredKeyWaitActive
Definition eventmgr.c:22
short nScreenHeight
Definition data.c:37
InputEvent * pInputEventHead
Definition data.c:19
volatile int bFrameTickPendingFlag
Definition mathfp.c:16
short nCurrentViewCenterPosY
Definition eventmgr.c:26
int nMouseCursorShowCount
Definition data.c:31
int bInputEventPoolInitialized
Definition data.c:25
int nMouseCursorSavedX
Definition eventmgr.c:20
unsigned int value
Definition wc1base.h:140
short modifiers
Definition wc1base.h:142
unsigned int timestamp
Definition wc1base.h:141
unsigned int modifiers
Definition wc1base.h:127
short value
Definition wc1base.h:126
short x
Definition wc1base.h:124
struct InputEvent * next
Definition wc1base.h:131
struct InputEvent * previous
Definition wc1base.h:132
short secondaryButton
Definition wc1base.h:130
short type
Definition wc1base.h:123
short y
Definition wc1base.h:125
short primaryButton
Definition wc1base.h:129
Viewport * viewport
Definition wc1base.h:110
unsigned char secondaryButton
Definition wc1base.h:104
struct Shape * shape
Definition wc1base.h:107
unsigned char shapeChanged
Definition wc1base.h:112
unsigned char primaryButton
Definition wc1base.h:103
unsigned short frame
Definition wc1base.h:108
short y
Definition wcdata.h:416
short x
Definition wcdata.h:415
short top
Definition wcdata.h:441
short left
Definition wcdata.h:440
short right
Definition wcdata.h:442
short bottom
Definition wcdata.h:443
short right
Definition wc1base.h:78
short bottom
Definition wc1base.h:79
short left
Definition wc1base.h:76
short top
Definition wc1base.h:77
Umbrella header for the game core.
void SystemDebugPrintf(const char *fmt,...)
Definition pilot.cpp:182
void set_up_screen_viewport(signed char mode)
Definition eventmgr.c:1016
void RefreshMouseCursorDisplay(void)
Definition eventmgr.c:525
void * AllocateTaggedMemory(int size, unsigned short flags)
Definition ending.c:31
void LeaveAllocationScope(void)
Definition eventmgr.c:556
void QueueInputEventAtCursor(unsigned short type, short primaryButton, short secondaryButton)
Definition eventmgr.c:63
unsigned int GetPacketDecompressionResult(void *)
Definition eventmgr.c:674
void TimerResetHook(void)
Definition eventmgr.c:669
char PumpMessagesDuringWait(void)
Definition pilot.cpp:188
short __stdcall PollInputEvent(InputEventState *event, short filter)
Definition eventmgr.c:336
char *__stdcall DosStrchr(const char *s, short c)
Definition strdos.c:43
short __stdcall ResetAllocationDepth(int x, int y)
Definition eventmgr.c:387
void StartupHook(unsigned int(*callback)(unsigned int, short))
Definition eventmgr.c:1114
unsigned int GetFixedOneMillion(void)
Definition eventmgr.c:692
long Vector_magnitude(const FixedVector *vector)
Definition mathfp.c:132
void intro_drawbackgroundships(void)
Definition eventmgr.c:962
void RestoreMouseCursorBackground(void)
Definition eventmgr.c:494
void __stdcall SetFrameTimerAndWait(short period)
Definition eventmgr.c:610
void DrawSpriteScaled(Viewport *viewport, short x, short y, struct Shape *shape, short frame, short angle, short scale, short flip)
Definition gr.c:1176
void ClearInputKeyStatePreservingModifiers(void)
Definition eventmgr.c:787
void DrawSpriteDefault(Viewport *viewport, short x, short y, struct Shape *shape, short frame)
Definition gr.c:660
int IsFrameTickElapsed(void)
Definition eventmgr.c:629
void FlushInputEvents(void)
Definition eventmgr.c:381
void SetInputKeyState(int scanCode, unsigned char pressed)
Definition eventmgr.c:822
void SetMultimediaTimerCallback(int period)
Definition timer.c:41
short MinShort(short a, short b)
Definition mathutil.c:20
unsigned int GetFixedOneMillionAlt(void)
Definition eventmgr.c:698
void DrawMouseCursor(void)
Definition eventmgr.c:465
void QueueInputEvent(int type, int x, int y, int value, int primaryButton, int secondaryButton, unsigned int timestamp)
Definition eventmgr.c:114
void EnterAllocationScope(void)
Definition eventmgr.c:550
void __stdcall SetMouseHomePosition(short x, short y)
Definition eventmgr.c:581
void ClearInputKeyState(void)
Definition eventmgr.c:800
unsigned int PumpWindowMessages(void)
Definition winmain.c:740
void CaptureMouseCursorBackground(void)
Definition eventmgr.c:432
short __stdcall GetNextInputEvent(InputEventState *event)
Definition eventmgr.c:228
InputEvent * AllocateInputEvent(void)
Definition eventmgr.c:73
unsigned short GetOriginalFreeMemory(void)
Definition eventmgr.c:1108
void CheckCursor(void)
Definition eventmgr.c:405
void __stdcall SetFrameTimerPeriodDirect(short p)
Definition eventmgr.c:617
void ClearDebugPauseFlags(void)
Definition pilot.cpp:229
void ShutdownHook(int vector, void *handler)
Definition eventmgr.c:1161
void TranslatePolledInputEvent(unsigned short type, unsigned int value)
Definition eventmgr.c:36
void RestoreSpriteBackground(Viewport *viewport, unsigned char *background, short x, short y, struct Shape *shape, short frame)
Definition gr.c:799
void MouseIdleHook(void)
Definition eventmgr.c:1091
void ExitCleanupHook(void)
Definition eventmgr.c:1199
void draw_sorted_objects_to_buffer(void)
Definition eventmgr.c:890
void RetainInputEventsOfType(int type)
Definition eventmgr.c:179
void FinishPacketDecompressionHook(void)
Definition eventmgr.c:1194
void DrawSolidColourSprite(Viewport *viewport, short x, short y, struct Shape *shape, short frame, short colour)
Definition gr.c:935
int GetControlKeyState(void)
Definition winsys.c:117
void __stdcall GetMouseCursorPosition(ShortPoint *point)
Definition eventmgr.c:597
void sort_object_depth(void)
Definition eventmgr.c:835
void SetFrameTimerPeriod(short period)
Definition eventmgr.c:604
unsigned short IdentityWord(unsigned short v)
Definition eventmgr.c:681
void ReleaseInputEvent(InputEvent *event)
Definition eventmgr.c:101
void WaitForFrameTick(void)
Definition eventmgr.c:623
void __stdcall ApplyPackedMousePosition(ShortPoint point)
Definition eventmgr.c:589
unsigned short GetNavRangeSentinel(void)
Definition eventmgr.c:1102
unsigned int IsVectorWithinRange(FixedVector *vector, short range)
Definition eventmgr.c:1212
void __stdcall ConvertChar_Int(char *text, short number, short digits)
Definition eventmgr.c:1378
void DrawSolidColourSpriteScaled(Viewport *viewport, short x, short y, struct Shape *shape, short frame, short angle, short scale, short flip, short colour)
Definition gr.c:1185
unsigned int shrink_vector(FixedVector *vector)
Definition eventmgr.c:1222
unsigned int GetStartupErrorCode(int vector)
Definition eventmgr.c:1154
void CaptureSpriteBackground(Viewport *viewport, unsigned char *background, short x, short y, struct Shape *shape, short frame)
Definition gr.c:669
unsigned int JoystickEdgeHook(int button)
Definition eventmgr.c:1120
void ReleasePacketHandle(void *handle)
Definition ending.c:50
void TimerStopHook(void)
Definition eventmgr.c:687
unsigned int shrink(int *component)
Definition eventmgr.c:1235
void SetMousePositionDuplicate(int x, int y)
Definition winsys.c:149
short GetCurrentDiskDriveHook(void)
Definition eventmgr.c:1181
void DIBupdate(int left, int top, int right, int bottom)
Definition dib.c:665
void __stdcall SetMouseCursorShape(struct Shape *shape, short frame)
Definition eventmgr.c:562
int GetShiftKeyState(void)
Definition winsys.c:111
short MaxShort(short a, short b,...)
Definition mathutil.c:29
short __stdcall IsInputEventQueued(short type)
Definition eventmgr.c:371
unsigned int GetKeyboardModifiers(void)
Definition winsys.c:123
void FreeIfNotNull(void *p)
Definition eventmgr.c:1147
unsigned short __stdcall GetShutdownErrorCode(unsigned char *driveState)
Definition eventmgr.c:1187
void * AllocateUntaggedMemory(unsigned int size)
Definition eventmgr.c:648
void * AllocateSmallMemoryBlock(short size)
Definition eventmgr.c:1141
void RemoveInputEvent(InputEvent *event)
Definition eventmgr.c:202
void __stdcall FillGraphicSuffix(char *path, short number, short digits)
Definition eventmgr.c:1363
void ReleaseUntaggedMemory(void *memory)
Definition eventmgr.c:663
unsigned short GetSoundHardwareFlag(void)
Definition eventmgr.c:642
void ReleaseInputEventQueue(void)
Definition eventmgr.c:164
short __stdcall PeekInputEvent(InputEventState *event, short type)
Definition eventmgr.c:343
unsigned short __stdcall SelectDiskDriveHook(short drive)
Definition eventmgr.c:1175
#define SPACE_OBJECT_COUNT
Definition wcdata.h:1004
@ OBJECT_CLASS_PLANET
Definition wcdata.h:41
@ OBJECT_CLASS_DUST
Definition wcdata.h:42
@ OBJECT_CLASS_STAR
Definition wcdata.h:40
@ OBJECT_CLASS_NULL
Definition wcdata.h:38