Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
titlemnu.c
Go to the documentation of this file.
1/*
2 * Joystick calibration, title menu and barracks screen.
3 *
4 * Retail object 0x418770-0x4199EF (link order; see docs/ORDER.md).
5 */
6#define TITLEMNU_C
7#include "game.h"
8
9/* Function start: 0x418770 */
11{
12 short yTop;
13 short leftX;
14 short savedFailure;
15 InputDeviceSample sample[2];
16 short centreX;
17 short midY;
18 short fontReady;
19 short maxX;
20 short yMax;
21 int error;
22 int file;
23
24 fontReady = 0;
25 savedFailure = (short)g_4_nControllerFailureValue;
26 error = 1;
28 return;
30 if (g_36_apTextGlyphs[1] != 0)
31 fontReady++;
32
36 "Turn AUTO FIRE off if present, press a button") != 0) {
41 }
42
44 "Move stick to the UPPER LEFT, press a button") != 0) {
49 leftX = (short)g_12_nJoystickMinimumXNumber;
51 yTop = (short)g_2_nJsMinimumY;
54 }
55
57 "Move stick to the LOWER RIGHT, press a button") != 0) {
62 maxX = (short)g_4_nJoystickMaximumXValue;
64 yMax = (short)g_nJoystickMaximumY;
67 }
68
70 "Center Joystick, press a button") != 0) {
75 centreX = (short)g_1_nJoystickCentreXNumber;
77 midY = (short)g_2_nJoystickCentreY;
80 }
81
82 if (fontReady == 0)
84
105 if (g_1_nJsRightScaleWord == 0)
109
121
124 if (ShowModalTextPanel(1,
125 "FAILED! Center Joystick, press a button") != 0) {
126 DIBslamReal();
129 LoadJoystickCalibrationFile(8, 8, 1, 1);
131 }
132 _unlink("j.cal");
133 return;
134 }
135
136 file = _open("j.cal", 0x8301, 0x180);
137 if (file != -1) {
138 error = _write(file, &g_8_nActiveInputDeviceWord, 2) == -1;
139 if (error == 0)
140 error = _write(file, &leftX, 2) == -1;
141 if (error == 0)
142 error = _write(file, &yTop, 2) == -1;
143 if (error == 0)
144 error = _write(file, &maxX, 2) == -1;
145 if (error == 0)
146 error = _write(file, &yMax, 2) == -1;
147 if (error == 0)
148 error = _write(file, &centreX, 2) == -1;
149 if (error == 0)
150 error = _write(file, &midY, 2) == -1;
151 _close(file);
152 if (error != 0)
153 _unlink("j.cal");
154 }
155}
156
157/* Function start: 0x418D14 */
169
170/* Function start: 0x418D5F */
182
183/* Function start: 0x418DAA */
184short RunCampaignSelectionFrame(void *scene, void *field)
185{
186 short selection;
187
188 selection = 0;
189 while ((selection = PollSceneHotspotInput(scene, 0, 0, 0, 0)) == 0) {
192 &g_stSecondaryViewBufferBlock, 0, 0, field, 0);
195 &g_stSecondaryViewBufferBlock, 0, 0, scene, 0);
196 if (g_pszPersonnelFooter != 0) {
203 (unsigned short)((320 -
205 g_pszPersonnelFooter)) >> 1),
206 180);
210 }
215 }
217 selection = 0;
218 return selection;
219}
220
221/* Function start: 0x418ECD */
222short RunTitleMenuInputLoop(unsigned char *buttons,
223 unsigned char *logo,
224 unsigned char *background,
225 short showSecondButton)
226{
227 int savedKeyboardMouse;
228 short choice;
229 short maxSelection;
230
231 choice = 0;
232 maxSelection = 0;
233 if (showSecondButton == 0)
234 maxSelection = 1;
238 while ((choice = PollSceneHotspotInput(buttons, 0, 0, 0,
239 maxSelection)) == 0) {
242 background, 0);
245 logo, 0x19);
247 logo, 0x1f);
249 logo, 0x20);
251 buttons, 0);
252 if (showSecondButton != 0)
254 buttons, 1);
256 }
257 g_bKeyboardMouseEnabled = savedKeyboardMouse;
258 return choice;
259}
260
261/* Function start: 0x418FFC */
262short RunTitleScreen(void)
263{
264 unsigned char *background;
265 int sfxHandle;
266 unsigned char *buttons;
267 unsigned char *logo;
268 signed char done;
269 short logoFrame;
270 short canContinueCampaign;
271 signed char menuChoice;
272 int wipeType;
273 Viewport screenCopy;
274 void *wipeState;
275
276 menuChoice = 0;
277 done = 0;
278 buttons = 0;
279 logo = 0;
280 background = 0;
281 sfxHandle = 0;
295 screenCopy.left = 0;
296 screenCopy.right = 319;
297 screenCopy.top = 0;
298 screenCopy.bottom = 199;
299 if (AllocateViewport(&screenCopy,
302 PreloadMusicTrack(0x36);
303 spacetrack(0x36, 1, 1);
307 buttons = FetchDiskPacketRetrying("buttons.v00", 0, 0);
308 logo = FetchDiskPacketRetrying("wc2logo.vga", 0, 0);
309 background = FetchDiskPacketRetrying("field.v00", 1, 0);
312 if (WaitForInputKey() != 0)
315 PlaySfxWaveFileByNumber(0x28, -1, 0);
316 if (g_bSceneEscapeRequested == 0) {
317 for (logoFrame = 0; logoFrame < 0x1a; logoFrame++) {
319 0, 0, background, 0);
322 160, 100, logo, logoFrame);
324 if (WaitForInputKey() != 0) {
326 break;
327 }
329 }
330 }
331 if (sfxHandle != 0) {
332 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(
333 sfxHandle, 0);
334 }
335 sfxHandle = 0;
336 if (g_bSceneEscapeRequested == 0) {
337 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(0, 0);
338 PlaySfxWaveFileByNumber(99, -1, 0);
339 }
340 if (g_bSceneEscapeRequested == 0) {
341 for (logoFrame = 0; logoFrame < 10; logoFrame++) {
343 0, 0, background, 0);
346 160, 100, logo, 0x19);
348 if (WaitForInputKey() != 0) {
350 break;
351 }
353 }
354 }
355 if (sfxHandle != 0) {
356 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(
357 sfxHandle, 0);
358 }
359 sfxHandle = 0;
360 PlaySfxWaveFileByNumber(6, -1, 0);
361 if (g_bSceneEscapeRequested == 0) {
362 for (logoFrame = 0x1a; logoFrame < 0x20; logoFrame++) {
364 0, 0, background, 0);
367 160, 100, logo, 0x19);
369 160, 100, logo, logoFrame);
371 if (WaitForInputKey() != 0) {
373 break;
374 }
376 }
377 }
378 if (sfxHandle != 0) {
379 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(
380 sfxHandle, 0);
381 }
382 sfxHandle = 0;
384 PlaySfxWaveFileByNumber(99, -1, 0);
385 if (g_bSceneEscapeRequested == 0) {
386 for (logoFrame = 0; logoFrame < 10; logoFrame++) {
388 0, 0, background, 0);
391 160, 100, logo, 0x19);
393 160, 100, logo, 0x1f);
395 if (WaitForInputKey() != 0) {
397 break;
398 }
400 }
401 }
402 if (sfxHandle != 0) {
403 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(
404 sfxHandle, 0);
405 }
406 sfxHandle = 0;
408 PlaySfxWaveFileByNumber(100, -1, 0);
410 0, 0, background, 0);
413 160, 100, logo, 0x19);
415 160, 100, logo, 0x1f);
418 160, 100, logo, 0x20);
420 &screenCopy);
421 MarkDibDirty();
422 DIBslamReal();
423 wipeType = 8;
426 wipeState = AllocateTaggedMemory(0xce, 0);
427 if (wipeState != 0) {
429 &screenCopy, wipeType, 0x3c, 0,
430 wipeState);
431 done = 0;
432 while (done == 0) {
433 done = AdvanceViewportWipe(wipeState);
434 if (WaitForInputKey() != 0 ||
437 break;
438 }
439 CopyViewportContents(&screenCopy,
442 0, 0, background, 0);
445 160, 100, logo, 0x19);
447 160, 100, logo, 0x1f);
449 160, 100, logo, 0x20);
450 }
451 FinishViewportWipe(wipeState);
452 ReleasePacketHandle(wipeState);
453 }
454 }
455 if (sfxHandle != 0) {
456 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(
457 sfxHandle, 0);
458 }
459 sfxHandle = 0;
460 canContinueCampaign = (short)HasSavedPilotCampaign();
466 ((void (__cdecl *)(int, int))FlushSoundEffectsAndLog)(
467 sfxHandle, 0);
469 free_viewport(&screenCopy);
472 /* Retail calls the pump here with no argument at all (no prototype
473 * was in scope); the SDL build passes the zero the other callers use. */
474 ((unsigned int (__cdecl *)(void))PumpWindowMessages)();
475 while (TakeInputPressCount() != 0) {
476 ((unsigned int (__cdecl *)(void))PumpWindowMessages)();
478 }
481 menuChoice = 0;
482 while (menuChoice == 0) {
483 menuChoice = (signed char)RunTitleMenuInputLoop(
484 buttons, logo, background, canContinueCampaign);
485 }
487 FreePacketAndClear(&buttons, 0);
488 FreePacketAndClear(&logo, 0);
489 FreePacketAndClear(&background, 0);
493 ReleaseMusicTrack(0x36);
495 return (short)(menuChoice - 1);
496}
497
498/* Function start: 0x419831 */
499short BarracksScreen(void)
500{
501 signed char choice;
502 void *campaignScene;
503 void *field;
504
505 choice = 0;
506 campaignScene = 0;
507 field = 0;
515 if ((short)AllocateViewport(
519 }
521 campaignScene = LoadNamedPacket(
522 "campaign.vga", 0, 0, 0, 0, 1);
523 if (campaignScene != 0 && WaitForSceneAdvance(campaignScene) != 0) {
524 field = FetchDiskPacketRetrying("field.v00", 1, 0);
532 while (choice == 0) {
533 choice = (signed char)RunCampaignSelectionFrame(
534 campaignScene, field);
535 }
537 FreePacketAndClear(&campaignScene, 0);
538 FreePacketAndClear(&field, 0);
540 return (short)(choice - 1);
541 }
542 FreePacketAndClear(&campaignScene, 0);
544 return 0;
545}
void(__cdecl *g_pIxFree)(void *)
void SetInputViewport(Viewport *viewport)
Definition eventmgr.c:2093
short WaitForSceneAdvance(void *scenePacket)
Definition hotspot.c:9
signed char InitializeViewportWipe(Viewport *source, Viewport *destination, int wipeType, short duration, short passFlags, void *workspace)
Definition wipe.c:12
void InitializeTextContextFromFont(TextContext *context, short fontIndex, unsigned char colour, signed char background)
Definition disk.c:254
short AllocateViewport(Viewport *viewport, short clearColour, short flags)
Definition vpalloc.c:32
void CalibrateJoystickInteractive()
Definition titlemnu.c:10
void free_viewport(Viewport *viewport)
Definition vpfree.c:10
void RefreshMemoryStatusOverlay(void)
Definition main.c:283
void WaitForJoystickButtonRelease(void)
Definition titlemnu.c:158
short MeasureTextPixelWidthClamped(const char *text)
Definition strwidth.c:10
void ReleaseTextFont(short fontIndex)
Definition disk.c:274
void ReportFatalErrorCode(const char *errorCode)
Definition message.c:29
void DrawSpriteDefault(Viewport *viewport, short x, short y, unsigned char *shape, short frame)
Definition gr.c:682
void * LoadNamedPacket(const char *filename, short section, void *destination, unsigned short flags, void *decompressionWorkspace, int registerHandle)
Definition eventmgr.c:2170
void StopMusicUnlessSuppressed(void)
Definition music.c:160
void FlushInputEvents(void)
Definition eventmgr.c:1014
void DIBslamReal(void)
Definition dib.cpp:562
short WaitForInputKey(void)
Definition disk.c:319
void ReleaseMusicTrack(int track)
Definition fltsetup.c:976
void spacetrack(int track, int mode, int enabled)
Definition music.c:152
signed char AdvanceViewportWipe(void *workspace)
Definition wipe.c:255
void InitializeConstellationField(Viewport *viewport, short direction, short density)
Definition starfld.c:55
unsigned int PumpWindowMessages(int skipMessages)
Definition winmain.c:292
short RunTitleScreen(void)
Definition titlemnu.c:262
short BarracksScreen(void)
Definition titlemnu.c:499
void * AllocateTaggedMemory(unsigned int size, short flags)
Definition memapi.c:92
void * FetchDiskPacketRetrying(char *fileName, short section, short flags)
Definition disk.c:187
void ServiceSoundSystem(void)
Definition sound.c:389
short RunCampaignSelectionFrame(void *scene, void *field)
Definition titlemnu.c:184
void WaitForVerticalBlankThunk(void)
Definition eventmgr.c:189
void ClearDebugPauseFlags(void)
Definition console.cpp:82
int TakeInputPressCount(void)
Definition winmain.c:1313
short PollSceneHotspotInput(void *scenePacket, short offsetX, short offsetY, short dismissOnBackground, short maximumSelection)
Definition hotspot.c:170
void WaitForJoystickButtonPress(void)
Definition titlemnu.c:171
void DisableMouseCursorDrawing(void)
Definition eventmgr.c:1327
short LoadJoystickCalibrationFile(short horizontalRange, short verticalRange, short horizontalDeadZone, short verticalDeadZone)
Definition joycal.c:15
short RunTitleMenuInputLoop(unsigned char *buttons, unsigned char *logo, unsigned char *background, short showSecondButton)
Definition titlemnu.c:222
void SampleJoystickDevice(InputDeviceSample *samples, short joystick, unsigned int fallback)
Definition joystick.c:22
void ClearViewport(Viewport *viewport, short colour)
Definition gr.c:1027
void EnableMouseCursorDrawing(void)
Definition eventmgr.c:1254
void FlushSoundEffectsAndLog(void *effect, short flags)
Definition music.c:439
void DrawConstellationField(void)
Definition starfld.c:108
void SetPersonnelMousePosition(short x, short y)
Definition mousepos.c:9
void PlaySfxWaveFileByNumber(int soundNumber, int sourceObject, int looping)
Definition music.c:490
void SetMenuInputPump(void)
Definition eventmgr.c:2106
void init_constellation(short scene)
Definition fltsetup.c:425
void ReleasePacketHandle(void *handle)
Definition memapi.c:108
void SetTextCursor(unsigned short a, unsigned short b)
Definition eventmgr.c:172
void ReleaseModalTextPanel(void)
Definition optmenu.c:208
void FreePacketAndClear(void *slot, unsigned short releaseFlags)
Definition disk.c:45
void SetFrameTimerAndWait(short period)
Definition eventmgr.c:1411
void DrawFormattedText(const char *format,...)
Definition textfmt.c:103
void MarkDibDirty(void)
Definition dib.cpp:532
void PreloadMusicTrack(int track)
Definition fltsetup.c:961
unsigned short HasSavedPilotCampaign(void)
Definition personnel.c:276
void CopyViewportContents(Viewport *source, Viewport *destination)
Definition gr.c:995
void FinishViewportWipe(void *workspace)
Definition wipe.c:902
short ShowModalTextPanel(short fontIndex, const char *format,...)
Definition optmenu.c:163
void ReleaseInputEventQueue(void)
Definition eventmgr.c:734
Shared Win32 declarations, types and library interfaces.
signed char g_bSceneEscapeRequested
Definition eventmgr.c:2420
unsigned char * g_pConstellationSprite
Definition message.c:230
int g_12_nJoystickDownScaleWord
Definition joystick.c:70
int g_12_nControllerLeftScaleValue
Definition joystick.c:62
int g_bKeyboardMouseEnabled
Definition kbmouse.c:10
short g_bNewPilotCampaignInitialized
Definition campaign.c:9
int g_4_nJoystickMaximumXValue
Definition joystick.c:63
int g_1_nJoystickCentreXNumber
Definition joystick.c:72
char * g_pszPersonnelFooter
Definition hotspot.c:243
unsigned char g_cSecondaryViewBufferColour
Definition startup.c:544
int g_2_nJsMinimumY
Definition joystick.c:66
unsigned char g_bPrimaryViewBufferColour
Definition startup.c:545
Viewport g_2_stModalSourceWindow
Definition message.c:231
int g_1_nJsRightScaleWord
Definition joystick.c:69
InputDeviceSample g_aInputDeviceSamplesList[2]
Definition joystick.c:75
Viewport g_101_stScrViewInfo
Definition cockpt.c:3831
signed char g_bRoomTransitionAnimationEnabled
Definition gameflow.c:14
int g_nJoystickVerticalRangeNumber
Definition joystick.c:67
int g_2_nJoystickCentreY
Definition joystick.c:71
Viewport g_stSecondaryViewBufferBlock
Definition message.c:234
short g_8_nActiveInputDeviceWord
Definition joystick.c:57
int g_4_nControllerFailureValue
Definition joystick.c:73
short g_18_nInterfaceEventMode
Definition eventmgr.c:2570
int g_3_nControllerHorizontalRange
Definition joystick.c:68
TextContext g_3_stDefaultStringContext
Definition message.c:239
int g_12_nJoystickMinimumXNumber
Definition joystick.c:65
unsigned char * g_36_apTextGlyphs[4]
Definition cockpt.c:3835
int g_59_nJoystickUpScaleWord
Definition joystick.c:61
int g_nJoystickMaximumY
Definition joystick.c:64
signed char alignment
Definition game.h:292
Viewport * viewport
Definition game.h:284
short right
Definition game.h:154
short bottom
Definition game.h:155
short left
Definition game.h:152
short top
Definition game.h:153