16#pragma intrinsic(_disable, _enable)
23 56, 52, 75, 73, 0, 0, 0, 0
27 -10, 4, -8, 8, -12, 8, -8, 8
91 if (screenX == (
short)0x8001)
190void align(
short *value,
short quantum)
195 current = (short)(current - current % quantum);
209 hazardMoves = moving;
223 }
else if (hazardMoves != 0) {
229 travelTime = (short)(travelTime -
231 travelTime =
MaxShort(45, travelTime);
233 travelTime = (short)(travelTime -
235 travelTime =
MaxShort(7, travelTime);
238 (
int)travelTime << 8, &vector);
245 speed = (short)(speed / travelTime);
259 if (hazardMoves == 0) {
265 separation, &vector);
299 unsigned short outsideRange;
311 if (pitch > minimum &&
320 if (abs(pitch) > 5 && abs(pitch) < 20 &&
321 abs(yaw) > 5 && abs(yaw) < 20 &&
RandomBelow(100) < 30)
337 return outsideRange != 0 &&
429 short emptySlot = -1;
435 for (slot = 0; slot < 20; slot++) {
441 if (emptySlot != -1 &&
457 }
while (slot++ < 3);
462 short radius,
short density)
524 config = fopen(
"WINGCMDR.CFG",
"rt");
526 while (fscanf(config,
"%s", option) != EOF) {
529 if (memcmp(option,
"$#SAGA.EXE", 11) == 0)
559int WINAPI
WinMain(HINSTANCE instance, HINSTANCE previous,
560 LPSTR commandLine,
int showCommand)
562 MEMORYSTATUS memoryStatus;
568 CreateSemaphoreA(0, 0, 1,
"Wing Commander 1");
569 if (GetLastError() == ERROR_ALREADY_EXISTS) {
571 "Only one instance of Wing Commander 1 for Windows95 may be running at a time",
572 "ATTENTION", MB_ICONERROR);
576 memset(&memoryStatus, 0,
sizeof(memoryStatus));
577 memoryStatus.dwLength =
sizeof(memoryStatus);
578 GlobalMemoryStatus(&memoryStatus);
579 if (memoryStatus.dwTotalPhys < 0x800000) {
581 "You must have at leat 8 megs of memory available to play Wing Commander 1 for Windows95",
582 "ATTENTION", MB_ICONERROR);
585 if (memoryStatus.dwTotalPageFile < 0x800000) {
587 "You must have at leat 8 megs of virtual memory available to play Wing Commander 1 for Window95",
588 "ATTENTION", MB_ICONERROR);
592 if (waveOutGetNumDevs() < 1)
603 process = GetCurrentProcess();
605 SetPriorityClass(process, HIGH_PRIORITY_CLASS);
610 srand((
unsigned int)time(0));
623 main(0, (
char **)
"");
650 process = GetCurrentProcess();
651 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
660 MessageBoxA(0, text,
"NOTICE", 0x10);
671 process = GetCurrentProcess();
672 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
674 "Current: %i\nMax : %i\nTotal : %i\n",
678 OutputDebugStringA(
"Memory Info:\n");
688 WNDCLASSA windowClass;
694 windowClass.hInstance = instance;
697 windowClass.hCursor = 0;
698 windowClass.hIcon = LoadIconA(0, IDI_APPLICATION);
700 windowClass.hbrBackground = GetStockObject(BLACK_BRUSH);
701 windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
702 windowClass.cbClsExtra = 0;
703 windowClass.cbWndExtra = 0;
704 if (RegisterClassA(&windowClass) == 0)
709 WS_POPUP, 0, 0, 320, 200,
722 "You must be running with 256, or more, colors to play Wing Commander",
723 "NOTICE", MB_ICONEXCLAMATION);
755 if (GetMessageA(&message, 0, 0, 0) != 0) {
756 TranslateMessage(&message);
758 DispatchMessageA(&message);
771 process = GetCurrentProcess();
772 SetPriorityClass(process, HIGH_PRIORITY_CLASS);
779 SetCursorPos(cursor.x, cursor.y);
783 if (PeekMessageA(&message, 0, 0, 0, PM_NOREMOVE) != 0) {
784 if (GetMessageA(&message, 0, 0, 0) != 0) {
785 TranslateMessage(&message);
787 DispatchMessageA(&message);
803 process = GetCurrentProcess();
804 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
824 WPARAM wParam, LPARAM lParam)
828 unsigned int scanCode;
829 unsigned int primaryButton;
830 unsigned int secondaryButton;
833 unsigned int command;
834 unsigned short eventType;
838 primaryButton = (
unsigned int)wParam & 1;
839 secondaryButton = ((
unsigned int)wParam & 2) >> 1;
840 mouseX = (
unsigned short)lParam;
841 command = (
unsigned short)wParam;
842 mouseY = (
unsigned short)((
unsigned long)lParam >> 16);
853 process = GetCurrentProcess();
854 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
861 process = GetCurrentProcess();
862 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
872 if (wParam == VK_F1) {
873 if ((lParam & 0x40000000) != 0) {
880 scanCode = ((
unsigned long)lParam & 0xff0000) >> 16;
893 scanCode = ((
unsigned long)lParam & 0xff0000) >> 16;
901 if (((
unsigned long)lParam & 0x20000000) != 0) {
904 "Current: %i\nMax : %i\nTotal : %i\n",
908 OutputDebugStringA(
"Memory Info:\n");
911 }
else if (wParam ==
'N') {
913 }
else if (wParam ==
'M') {
927 if ((wParam & 0xfff0) == SC_SCREENSAVE ||
928 (wParam & 0xfff0) == SC_MONITORPOWER)
936 primaryButton, secondaryButton, 0);
947 primaryButton, secondaryButton, 0);
955 primaryButton, secondaryButton, 0);
959 if (mouseEvent != 0) {
965 return DefWindowProcA(window, message, wParam, lParam);
970 unsigned int *buttons,
short joystick,
971 unsigned short fallback)
974 unsigned int infoIndex;
975 unsigned int buttonState;
989 *buttons = buttonState;
991 *buttons = buttonState >> 2;
993 *buttons = buttonState & 3;
1000 *buttons = fallback;
1013 unsigned short *xMin,
unsigned short *xMax,
1014 unsigned short *yMin,
unsigned short *yMax)
1017 unsigned int device = joystick != 0;
1019 *xMin = *xMax = *yMin = *yMax = 0;
1020 if (joyGetDevCapsA(device, &caps,
sizeof(caps)) != JOYERR_NOERROR) {
1025 *xMin = (
unsigned short)caps.wXmin;
1026 *xMax = (
unsigned short)caps.wXmax;
1027 *yMin = (
unsigned short)caps.wYmin;
1028 *yMax = (
unsigned short)caps.wYmax;
1097 sprintf(text,
"Memory at %p %swritten. Corruption : (%i/%i) %s",
1098 memory, overrun ?
"over" :
"under", count, 0x100,
1100 ? (count > 0xc0 ?
"EXTREME" :
"SEVERE")
1101 : (count > 0x40 ?
"BAD" :
"NAUGHTY"));
1102 MessageBoxA(0, text,
"NOTICE", 0x10);
1111 unsigned int *guard;
1116 while (allocation != 0) {
1118 guard = (
unsigned int *)
block;
1122 if (*guard != 0xabababab)
1123 prefixCorrupt = prefixCorrupt + 1;
1127 if (prefixCorrupt != 0)
1130 guard = (
unsigned int *)((
unsigned char *)guard + allocation->
size);
1134 if (*guard != 0xabababab)
1135 suffixCorrupt = suffixCorrupt + 1;
1139 if (suffixCorrupt != 0)
1142 allocation = allocation->
next;
1151 void *
block = (
unsigned char *)memory - 0x400;
1153 unsigned int *guard;
1156 guard = (
unsigned int *)
block;
1157 if (allocation == 0)
1160 previous = allocation;
1161 allocation = allocation->
next;
1162 if (allocation == 0)
1169 if (*guard != 0xabababab)
1170 corrupt = corrupt + 1;
1177 guard = (
unsigned int *)((
unsigned char *)memory + allocation->
size);
1181 if (*guard != 0xabababab)
1182 corrupt = corrupt + 1;
void(__cdecl *pIxFree)(void *)
unsigned char bEscapePressedFlag
unsigned int nGuardedAllocationPeakBytes
short asObjScreenScalesArray[SPACE_OBJECT_COUNT]
HINSTANCE hCurrentAppInstance
short nRenderedSpaceFrame
short asObjScreenAngles[SPACE_OBJECT_COUNT]
short nHazardReferenceSpeed
volatile int bMainWindowMinimized
short anObjectYawRotation[SPACE_OBJECT_COUNT]
short anObjPitchRot[SPACE_OBJECT_COUNT]
int bShowKilrathiSagaCredits
JOYINFO aJoystickInfos[2]
unsigned int bKeyEventQueueEnabled
MouseCursorState stHostMouseState
HazardField * pActiveHazardField
int bPtrMovedByKeyboardState
FixedVector aShipRightVector[64]
enum ObjectClass aeObjectClass[SPACE_OBJECT_COUNT]
unsigned int nSystemKeyDown
MouseCursorState stMouseCursorState
int bWindowMessagePumpActive
short asObjectScreenYArray[SPACE_OBJECT_COUNT]
struct GuardedAllocation * pGuardedAllocationHead
HANDLE hSingleInstanceSemaphore
int bDirectDrawModeCascadeEnabled
FixedVector aShipVelocity[SPACE_OBJECT_COUNT]
short asObjectCollisionRadius[64]
signed char cCurrentCockpitView
short nCurrentViewCenterPosX
void(*) pCurrentEventManagerPump(void)
unsigned int nGuardedAllocationTotalBytes
unsigned int nSessionEndTime
unsigned short asObjDistancesTable[SPACE_OBJECT_COUNT]
Viewport stSpaceBufferViewport
short asObjectCounterArray[SPACE_OBJECT_COUNT]
int aiSoundEffectSourceActiveArray[0x40]
short awPaletteRgbWordsList[0x300]
FixedVector aShipUpVector[64]
short asObjectScreenXList[SPACE_OBJECT_COUNT]
signed char acObjOwnersTable[64]
int bHostPrimaryMouseButton
struct Shape * apObjShapeArray[SPACE_OBJECT_COUNT]
signed char acObjCollisionGraceTicks[SPACE_OBJECT_COUNT]
enum ObjectType aeObjectTypeList[SPACE_OBJECT_COUNT]
short asObjectViewFrames[SPACE_OBJECT_COUNT]
int bHostSecondaryMouseButton
short asObjectFlipArray[SPACE_OBJECT_COUNT]
HazardField aHazardFields[8]
struct GuardedAllocation * pGuardedAllocationTail
unsigned int nGuardedAllocationBytes
short nCurrentHazardFieldTotal
FixedVector aShipPositionsArray[SPACE_OBJECT_COUNT]
volatile unsigned int bF1KeyLatch
FixedVector aShipFwdVec[64]
short nCurrentViewCenterPosY
unsigned int nSessionStartTime
signed char abHazardObjects[0x14]
int bPlayerCollisionResponse
struct GuardedAllocation * next
void SystemDebugPrintf(const char *fmt,...)
int __stdcall GetJoystickPosition(int *x, int *y, unsigned int *buttons, short joystick, unsigned short fallback)
void remove_hazard(signed char hazard)
short kilrathi_near(short obj, short range)
void InitGameClockEpoch(void)
short GetTransformedShapeBounds(Viewport *viewport, short x, short y, struct Shape *shape, short frame, short angle, short scale, short flip, ShortRect *bounds)
void make_shard(short asteroid, FixedVector direction)
void DIBwholePaletteFromWords(short *palette)
void DestroyGlobalDebugOverlayConsole(void)
short distance_between_points(const FixedVector *from, const FixedVector *to)
short LogMemoryUsage(void)
void fix_objects_ijk(short obj)
void match_ship_to_eye(void)
void rotate_about_i(short angle, FixedVector *j, FixedVector *k)
void ServiceAudioStream(void)
void remove_object(short obj)
void alter_pitch(short angle, short obj)
void __stdcall GetPaletteEntry(short index, short *rgb)
void AddFixedVectors(const FixedVector *left, const FixedVector *right, FixedVector *sum)
void ShutdownGameWindow(void)
unsigned int AbortToDesktop(void)
void set_objects_data(short obj, enum ObjectType type, short owner)
void InitializeAudioStreamer(HWND window)
short easy2see(short obj)
void position_relative_ijk(FixedVector *position, short obj, short right, short up, short forward)
void * AllocateGuardedMemory(unsigned int size)
void init_player_input(void)
void ReportSpaceFlightMaxFps(float adjustment)
int ReadCheaterFlagFromRegistry(void)
unsigned int IsPointWithinRange(const FixedVector *from, const FixedVector *to, short range)
void CheckLauncherAndConfig(void)
HWND GetMainWindowHandle(void)
void RestoreGamePalette(void)
void SetInputKeyState(int scanCode, unsigned char pressed)
short MinShort(short a, short b)
void DIBinstall(HWND window)
short find_ratio(short inputMinimum, short inputMaximum, short input, short outputMinimum, short outputMaximum)
void FreeGuardedAllocation(void *memory)
short ok_hazard_spot(short obj)
void DIBpositionWindow(void)
void Streamer_close(void)
int main(short argc, char **argv)
LRESULT CALLBACK MainWindowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
void QueueInputEvent(int type, int x, int y, int value, int primaryButton, int secondaryButton, unsigned int timestamp)
void __stdcall SetMouseHomePosition(short x, short y)
void extra_hazard(short obj)
unsigned int PumpWindowMessages(void)
void copy_frame(short source, short destination)
void CheckAllGuardedAllocations(void)
short signed_random(short range)
void GetJoystickDevCaps(short joystick, unsigned short *xMin, unsigned short *xMax, unsigned short *yMin, unsigned short *yMax)
void alter_yaw(short angle, short obj)
void MonoDebug_install(void)
void WaitForVerticalBlankThunk(void)
void init_hazard(short obj, FixedVector position, short moving)
void InitializeAudioSystem(HWND window)
HINSTANCE GetApplicationInstance(void)
void ScaleFixedVector(const FixedVector *vector, int scale, FixedVector *result)
unsigned int GetF1KeyLatch(void)
void SetVectorFixedPoint(FixedVector *p, short v)
void __stdcall WarpMouseTo(short x, short y)
HDC GetMainWindowDeviceContext(void)
short GetJoystickButtons(void)
void SubtractFixedVectors(FixedVector *left, FixedVector *right, FixedVector *difference)
short real_velocity(short obj)
void start_hazard_field(short region)
short within_field(const HazardField *field, const FixedVector *point)
short RandomBelow(short n)
void ReportHeapGuardCorruption(void *memory, int count, int overrun)
void align(short *value, short quantum)
short find_vacant_3d_object(void)
void SignalAudioMixerWakeEvent(void)
short near_field(const HazardField *field, const FixedVector *point)
void point_at(short obj, FixedVector point)
int PromptInsertCorrectCd(void)
short asteroid_velocity(void)
void ShowNoticeMessageBox(const char *text)
short try_far_spot(FixedVector *spot, short *moving)
void SaveGamePalette(void)
short MaxShort(short a, short b,...)
void manage_hazard(short obj, short slot)
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR commandLine, int showCommand)
void add_hazard_field(enum ObjectType type, FixedVector center, short radius, short density)
short __stdcall RandomInRange(short lo, short hi)
void update_hazards(void)
void remove_all_hazards(void)
void CreateDebugOverlayConsole(HINSTANCE module, HWND window, short columns, short rows)
short RandomBelowOrEqual(short n)
int CreateMainWindow(HINSTANCE instance, HINSTANCE previous, int showCommand)
void skew_randomly(short obj, short allowReverse)
void negate_vector(FixedVector *vector)
void rotate_about_j(short angle, FixedVector *i, FixedVector *k)
@ OBJECT_TYPE_ASTEROID_FIELD
static signed char acHazardTravelTimeByView[8]
char szMainWindowClassName[]
static signed char acHazardPitchRange[8]
Declarations for the Win32 shell.