wolf3d

The original open source release of Wolfenstein 3D
Log | Files | Refs

WL_MENU.C (70337B)


      1 ////////////////////////////////////////////////////////////////////
      2 //
      3 // WL_MENU.C
      4 // by John Romero (C) 1992 Id Software, Inc.
      5 //
      6 ////////////////////////////////////////////////////////////////////
      7 #include "wl_def.h"
      8 #pragma hdrstop
      9 
     10 //
     11 // PRIVATE PROTOTYPES
     12 //
     13 void CP_ReadThis(void);
     14 
     15 #ifdef SPEAR
     16 #define STARTITEM	newgame
     17 
     18 #else
     19 #ifdef GOODTIMES
     20 #define STARTITEM	newgame
     21 
     22 #else
     23 #define STARTITEM	readthis
     24 #endif
     25 #endif
     26 
     27 char far endStrings[9][80]=
     28 {
     29 #ifndef SPEAR
     30 	{"Dost thou wish to\nleave with such hasty\nabandon?"},
     31 	{"Chickening out...\nalready?"},
     32 	{"Press N for more carnage.\nPress Y to be a weenie."},
     33 	{"So, you think you can\nquit this easily, huh?"},
     34 	{"Press N to save the world.\nPress Y to abandon it in\nits hour of need."},
     35 	{"Press N if you are brave.\nPress Y to cower in shame."},
     36 	{"Heroes, press N.\nWimps, press Y."},
     37 	{"You are at an intersection.\nA sign says, 'Press Y to quit.'\n>"},
     38 	{"For guns and glory, press N.\nFor work and worry, press Y."}
     39 #else
     40 	ENDSTR1,
     41 	ENDSTR2,
     42 	ENDSTR3,
     43 	ENDSTR4,
     44 	ENDSTR5,
     45 	ENDSTR6,
     46 	ENDSTR7,
     47 	ENDSTR8,
     48 	ENDSTR9
     49 #endif
     50 };
     51 
     52 CP_iteminfo
     53 	MainItems={MENU_X,MENU_Y,10,STARTITEM,24},
     54 	SndItems={SM_X,SM_Y1,12,0,52},
     55 	LSItems={LSM_X,LSM_Y,10,0,24},
     56 	CtlItems={CTL_X,CTL_Y,6,-1,56},
     57 	CusItems={8,CST_Y+13*2,9,-1,0},
     58 	NewEitems={NE_X,NE_Y,11,0,88},
     59 	NewItems={NM_X,NM_Y,4,2,24};
     60 
     61 #pragma warn -sus
     62 CP_itemtype far
     63 MainMenu[]=
     64 {
     65 #ifdef JAPAN
     66 	{1,"",CP_NewGame},
     67 	{1,"",CP_Sound},
     68 	{1,"",CP_Control},
     69 	{1,"",CP_LoadGame},
     70 	{0,"",CP_SaveGame},
     71 	{1,"",CP_ChangeView},
     72 	{2,"",CP_ReadThis},
     73 	{1,"",CP_ViewScores},
     74 	{1,"",0},
     75 	{1,"",0}
     76 #else
     77 
     78 	{1,STR_NG,CP_NewGame},
     79 	{1,STR_SD,CP_Sound},
     80 	{1,STR_CL,CP_Control},
     81 	{1,STR_LG,CP_LoadGame},
     82 	{0,STR_SG,CP_SaveGame},
     83 	{1,STR_CV,CP_ChangeView},
     84 
     85 #ifndef GOODTIMES
     86 #ifndef SPEAR
     87 
     88 	#ifdef SPANISH
     89 	{2,"Ve esto!",CP_ReadThis},
     90 	#else
     91 	{2,"Read This!",CP_ReadThis},
     92 	#endif
     93 
     94 #endif
     95 #endif
     96 
     97 	{1,STR_VS,CP_ViewScores},
     98 	{1,STR_BD,0},
     99 	{1,STR_QT,0}
    100 #endif
    101 },
    102 
    103 far SndMenu[]=
    104 {
    105 #ifdef JAPAN
    106 	{1,"",0},
    107 	{1,"",0},
    108 	{1,"",0},
    109 	{0,"",0},
    110 	{0,"",0},
    111 	{1,"",0},
    112 	{1,"",0},
    113 	{1,"",0},
    114 	{0,"",0},
    115 	{0,"",0},
    116 	{1,"",0},
    117 	{1,"",0},
    118 #else
    119 	{1,STR_NONE,0},
    120 	{1,STR_PC,0},
    121 	{1,STR_ALSB,0},
    122 	{0,"",0},
    123 	{0,"",0},
    124 	{1,STR_NONE,0},
    125 	{1,STR_DISNEY,0},
    126 	{1,STR_SB,0},
    127 	{0,"",0},
    128 	{0,"",0},
    129 	{1,STR_NONE,0},
    130 	{1,STR_ALSB,0}
    131 #endif
    132 },
    133 
    134 far CtlMenu[]=
    135 {
    136 #ifdef JAPAN
    137 	{0,"",0},
    138 	{0,"",0},
    139 	{0,"",0},
    140 	{0,"",0},
    141 	{0,"",MouseSensitivity},
    142 	{1,"",CustomControls}
    143 #else
    144 	{0,STR_MOUSEEN,0},
    145 	{0,STR_JOYEN,0},
    146 	{0,STR_PORT2,0},
    147 	{0,STR_GAMEPAD,0},
    148 	{0,STR_SENS,MouseSensitivity},
    149 	{1,STR_CUSTOM,CustomControls}
    150 #endif
    151 },
    152 
    153 #pragma warn +sus
    154 
    155 #ifndef SPEAR
    156 far NewEmenu[]=
    157 {
    158 #ifdef JAPAN
    159 #ifdef JAPDEMO
    160 	{1,"",0},
    161 	{0,"",0},
    162 	{0,"",0},
    163 	{0,"",0},
    164 	{0,"",0},
    165 	{0,"",0},
    166 	{0,"",0},
    167 	{0,"",0},
    168 	{0,"",0},
    169 	{0,"",0},
    170 	{0,"",0},
    171 	{0,"",0},
    172 #else
    173 	{1,"",0},
    174 	{0,"",0},
    175 	{1,"",0},
    176 	{0,"",0},
    177 	{1,"",0},
    178 	{0,"",0},
    179 	{1,"",0},
    180 	{0,"",0},
    181 	{1,"",0},
    182 	{0,"",0},
    183 	{1,"",0},
    184 	{0,"",0}
    185 #endif
    186 #else
    187 	#ifdef SPANISH
    188 	{1,"Episodio 1\n"
    189 	   "Fuga desde Wolfenstein",0},
    190 	{0,"",0},
    191 	{3,"Episodio 2\n"
    192 		   "Operacion Eisenfaust",0},
    193 	{0,"",0},
    194 	{3,"Episodio 3\n"
    195 		   "Muere, Fuhrer, Muere!",0},
    196 	{0,"",0},
    197 	{3,"Episodio 4\n"
    198 		  "Un Negro Secreto",0},
    199 	{0,"",0},
    200 	{3,"Episodio 5\n"
    201 		  "Huellas del Loco",0},
    202 	{0,"",0},
    203 	{3,"Episodio 6\n"
    204 		  "Confrontacion",0}
    205 	#else
    206 	{1,"Episode 1\n"
    207 	   "Escape from Wolfenstein",0},
    208 	{0,"",0},
    209 	{3,"Episode 2\n"
    210 		   "Operation: Eisenfaust",0},
    211 	{0,"",0},
    212 	{3,"Episode 3\n"
    213 		   "Die, Fuhrer, Die!",0},
    214 	{0,"",0},
    215 	{3,"Episode 4\n"
    216 		  "A Dark Secret",0},
    217 	{0,"",0},
    218 	{3,"Episode 5\n"
    219 		  "Trail of the Madman",0},
    220 	{0,"",0},
    221 	{3,"Episode 6\n"
    222 		  "Confrontation",0}
    223 	#endif
    224 #endif
    225 },
    226 #endif
    227 
    228 
    229 far NewMenu[]=
    230 {
    231 #ifdef JAPAN
    232 	{1,"",0},
    233 	{1,"",0},
    234 	{1,"",0},
    235 	{1,"",0}
    236 #else
    237 	{1,STR_DADDY,0},
    238 	{1,STR_HURTME,0},
    239 	{1,STR_BRINGEM,0},
    240 	{1,STR_DEATH,0}
    241 #endif
    242 },
    243 
    244 far LSMenu[]=
    245 {
    246 	{1,"",0},
    247 	{1,"",0},
    248 	{1,"",0},
    249 	{1,"",0},
    250 	{1,"",0},
    251 	{1,"",0},
    252 	{1,"",0},
    253 	{1,"",0},
    254 	{1,"",0},
    255 	{1,"",0}
    256 },
    257 
    258 far CusMenu[]=
    259 {
    260 	{1,"",0},
    261 	{0,"",0},
    262 	{0,"",0},
    263 	{1,"",0},
    264 	{0,"",0},
    265 	{0,"",0},
    266 	{1,"",0},
    267 	{0,"",0},
    268 	{1,"",0}
    269 }
    270 ;
    271 
    272 
    273 int color_hlite[]={
    274    DEACTIVE,
    275    HIGHLIGHT,
    276    READHCOLOR,
    277    0x67
    278    },
    279 
    280    color_norml[]={
    281    DEACTIVE,
    282    TEXTCOLOR,
    283    READCOLOR,
    284    0x6b
    285    };
    286 
    287 int EpisodeSelect[6]={1};
    288 
    289 
    290 int SaveGamesAvail[10],StartGame,SoundStatus=1,pickquick;
    291 char SaveGameNames[10][32],SaveName[13]="SAVEGAM?.";
    292 
    293 
    294 ////////////////////////////////////////////////////////////////////
    295 //
    296 // INPUT MANAGER SCANCODE TABLES
    297 //
    298 ////////////////////////////////////////////////////////////////////
    299 static byte
    300 					*ScanNames[] =		// Scan code names with single chars
    301 					{
    302 	"?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
    303 	"Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
    304 	"D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
    305 	"B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
    306 	"?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
    307 	"\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
    308 	"?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
    309 	"?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
    310 					},	// DEBUG - consolidate these
    311 					far ExtScanCodes[] =	// Scan codes with >1 char names
    312 					{
    313 	1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
    314 	0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
    315 	0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
    316 	0x50,0x4b,0x4d,0x00
    317 					},
    318 					*ExtScanNames[] =	// Names corresponding to ExtScanCodes
    319 					{
    320 	"Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
    321 	"F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
    322 	"PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
    323 	"Down","Left","Right",""
    324 					};
    325 
    326 
    327 ////////////////////////////////////////////////////////////////////
    328 //
    329 // Wolfenstein Control Panel!  Ta Da!
    330 //
    331 ////////////////////////////////////////////////////////////////////
    332 void US_ControlPanel(byte scancode)
    333 {
    334 	int which,i,start;
    335 
    336 
    337 	if (ingame)
    338 		if (CP_CheckQuick(scancode))
    339 			return;
    340 
    341 	StartCPMusic(MENUSONG);
    342 	SetupControlPanel();
    343 
    344 	//
    345 	// F-KEYS FROM WITHIN GAME
    346 	//
    347 	switch(scancode)
    348 	{
    349 		case sc_F1:
    350 			#ifdef SPEAR
    351 			BossKey();
    352 			#else
    353 			#ifdef GOODTIMES
    354 			BossKey();
    355 			#else
    356 			HelpScreens();
    357 			#endif
    358 			#endif
    359 			goto finishup;
    360 
    361 		case sc_F2:
    362 			CP_SaveGame(0);
    363 			goto finishup;
    364 
    365 		case sc_F3:
    366 			CP_LoadGame(0);
    367 			goto finishup;
    368 
    369 		case sc_F4:
    370 			CP_Sound();
    371 			goto finishup;
    372 
    373 		case sc_F5:
    374 			CP_ChangeView();
    375 			goto finishup;
    376 
    377 		case sc_F6:
    378 			CP_Control();
    379 			goto finishup;
    380 
    381 		finishup:
    382 			CleanupControlPanel();
    383 			#ifdef SPEAR
    384 			UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    385 			#endif
    386 			return;
    387 	}
    388 
    389 #ifdef SPEAR
    390 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    391 #endif
    392 
    393 	DrawMainMenu();
    394 	MenuFadeIn();
    395 	StartGame=0;
    396 
    397 	//
    398 	// MAIN MENU LOOP
    399 	//
    400 	do
    401 	{
    402 		which=HandleMenu(&MainItems,&MainMenu[0],NULL);
    403 
    404 		#ifdef SPEAR
    405 		#ifndef SPEARDEMO
    406 		//
    407 		// EASTER EGG FOR SPEAR OF DESTINY!
    408 		//
    409 		if (Keyboard[sc_I] && Keyboard[sc_D])
    410 		{
    411 			VW_FadeOut();
    412 			StartCPMusic (XJAZNAZI_MUS);
    413 			UnCacheLump(OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    414 			UnCacheLump(BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    415 			MM_SortMem ();
    416 			ClearMemory ();
    417 
    418 
    419 			CA_CacheGrChunk (IDGUYS1PIC);
    420 			VWB_DrawPic(0,0,IDGUYS1PIC);
    421 			UNCACHEGRCHUNK(IDGUYS1PIC);
    422 
    423 			CA_CacheGrChunk (IDGUYS2PIC);
    424 			VWB_DrawPic(0,80,IDGUYS2PIC);
    425 			UNCACHEGRCHUNK(IDGUYS2PIC);
    426 
    427 			VW_UpdateScreen();
    428 
    429 			CA_CacheGrChunk (IDGUYSPALETTE);
    430 			VL_FadeIn(0,255,grsegs[IDGUYSPALETTE],30);
    431 			UNCACHEGRCHUNK(IDGUYSPALETTE);
    432 
    433 			while (Keyboard[sc_I] || Keyboard[sc_D]);
    434 			IN_ClearKeysDown();
    435 			IN_Ack();
    436 
    437 			VW_FadeOut();
    438 
    439 			CacheLump(BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    440 			CacheLump(OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    441 			DrawMainMenu();
    442 			StartCPMusic (MENUSONG);
    443 			MenuFadeIn();
    444 		}
    445 		#endif
    446 		#endif
    447 
    448 		switch(which)
    449 		{
    450 			case viewscores:
    451 				if (MainMenu[viewscores].routine == NULL)
    452 					if (CP_EndGame())
    453 						StartGame=1;
    454 
    455 				DrawMainMenu();
    456 				MenuFadeIn();
    457 				break;
    458 
    459 			case backtodemo:
    460 				#ifdef SPEAR
    461 				if (!ingame)
    462 				{
    463 					//
    464 					// DEALLOCATE ALL SOUNDS!
    465 					//
    466 					switch (SoundMode)
    467 					{
    468 						case sdm_PC:
    469 							start = STARTPCSOUNDS;
    470 							break;
    471 						case sdm_AdLib:
    472 							start = STARTADLIBSOUNDS;
    473 							break;
    474 					}
    475 
    476 					if (SoundMode != sdm_Off)
    477 						for (i=0;i<NUMSOUNDS;i++,start++)
    478 							if (audiosegs[start])
    479 								MM_SetPurge (&(memptr)audiosegs[start],3);		// make purgable
    480 				}
    481 				#endif
    482 
    483 				MM_SortMem();
    484 				StartGame=1;
    485 				if (!ingame)
    486 					StartCPMusic(INTROSONG);
    487 				VL_FadeOut(0,255,0,0,0,10);
    488 				break;
    489 
    490 			case -1:
    491 			case quit:
    492 				CP_Quit();
    493 				break;
    494 
    495 			default:
    496 				if (!StartGame)
    497 				{
    498 					DrawMainMenu();
    499 					MenuFadeIn();
    500 				}
    501 		}
    502 
    503 	//
    504 	// "EXIT OPTIONS" OR "NEW GAME" EXITS
    505 	//
    506 	} while(!StartGame);
    507 
    508 	//
    509 	// DEALLOCATE EVERYTHING
    510 	//
    511 	CleanupControlPanel();
    512 
    513 	//
    514 	// CHANGE MAINMENU ITEM
    515 	//
    516 	if (startgame || loadedgame)
    517 	{
    518 		#pragma warn -sus
    519 		MainMenu[viewscores].routine = NULL;
    520 		#ifndef JAPAN
    521 		_fstrcpy(MainMenu[viewscores].string,STR_EG);
    522 		#endif
    523 		#pragma warn +sus
    524 	}
    525 
    526 	// RETURN/START GAME EXECUTION
    527 
    528 #ifdef SPEAR
    529 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    530 	MM_SortMem ();
    531 #endif
    532 }
    533 
    534 
    535 ////////////////////////
    536 //
    537 // DRAW MAIN MENU SCREEN
    538 //
    539 void DrawMainMenu(void)
    540 {
    541 #ifdef JAPAN
    542 	CA_CacheScreen(S_OPTIONSPIC);
    543 #else
    544 	ClearMScreen();
    545 
    546 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
    547 	DrawStripes(10);
    548 	VWB_DrawPic(84,0,C_OPTIONSPIC);
    549 
    550 	#ifdef SPANISH
    551 	DrawWindow(MENU_X-8,MENU_Y-3,MENU_W+8,MENU_H,BKGDCOLOR);
    552 	#else
    553 	DrawWindow(MENU_X-8,MENU_Y-3,MENU_W,MENU_H,BKGDCOLOR);
    554 	#endif
    555 #endif
    556 
    557 	//
    558 	// CHANGE "GAME" AND "DEMO"
    559 	//
    560 	if (ingame)
    561 	{
    562 		#ifndef JAPAN
    563 
    564 		#ifdef SPANISH
    565 		_fstrcpy(&MainMenu[backtodemo].string,STR_GAME);
    566 		#else
    567 		_fstrcpy(&MainMenu[backtodemo].string[8],STR_GAME);
    568 		#endif
    569 
    570 		#else
    571 		CA_CacheGrChunk(C_MRETGAMEPIC);
    572 		VWB_DrawPic(12*8,20*8,C_MRETGAMEPIC);
    573 		UNCACHEGRCHUNK(C_MRETGAMEPIC);
    574 		CA_CacheGrChunk(C_MENDGAMEPIC);
    575 		VWB_DrawPic(12*8,18*8,C_MENDGAMEPIC);
    576 		UNCACHEGRCHUNK(C_MENDGAMEPIC);
    577 		#endif
    578 		MainMenu[backtodemo].active=2;
    579 	}
    580 	else
    581 	{
    582 		#ifndef JAPAN
    583 		#ifdef SPANISH
    584 		_fstrcpy(&MainMenu[backtodemo].string,STR_BD);
    585 		#else
    586 		_fstrcpy(&MainMenu[backtodemo].string[8],STR_DEMO);
    587 		#endif
    588 		#else
    589 		CA_CacheGrChunk(C_MRETDEMOPIC);
    590 		VWB_DrawPic(12*8,20*8,C_MRETDEMOPIC);
    591 		UNCACHEGRCHUNK(C_MRETDEMOPIC);
    592 		CA_CacheGrChunk(C_MSCORESPIC);
    593 		VWB_DrawPic(12*8,18*8,C_MSCORESPIC);
    594 		UNCACHEGRCHUNK(C_MSCORESPIC);
    595 		#endif
    596 		MainMenu[backtodemo].active=1;
    597 	}
    598 
    599 	DrawMenu(&MainItems,&MainMenu[0]);
    600 	VW_UpdateScreen();
    601 }
    602 
    603 #ifndef GOODTIMES
    604 #ifndef SPEAR
    605 ////////////////////////////////////////////////////////////////////
    606 //
    607 // READ THIS!
    608 //
    609 ////////////////////////////////////////////////////////////////////
    610 void CP_ReadThis(void)
    611 {
    612 	StartCPMusic(CORNER_MUS);
    613 	HelpScreens();
    614 	StartCPMusic(MENUSONG);
    615 }
    616 #endif
    617 #endif
    618 
    619 #ifndef SPEAR
    620 #ifndef GOODTIMES
    621 #else
    622 ////////////////////////////////////////////////////////////////////
    623 //
    624 // BOSS KEY
    625 //
    626 ////////////////////////////////////////////////////////////////////
    627 void BossKey(void)
    628 {
    629 	SD_MusicOff();
    630 	_AX = 3;
    631 	geninterrupt(0x10);
    632 	printf("C>");
    633 	while (!Keyboard[sc_Escape])
    634 	IN_ClearKeysDown();
    635 
    636 	SD_MusicOn();
    637 	VL_SetVGAPlaneMode ();
    638 	VL_TestPaletteSet ();
    639 	VL_SetPalette (&gamepal);
    640 	LoadLatchMem();
    641 }
    642 #endif
    643 #endif
    644 
    645 ////////////////////////////////////////////////////////////////////
    646 //
    647 // CHECK QUICK-KEYS & QUIT (WHILE IN A GAME)
    648 //
    649 ////////////////////////////////////////////////////////////////////
    650 int CP_CheckQuick(unsigned scancode)
    651 {
    652 	switch(scancode)
    653 	{
    654 		//
    655 		// END GAME
    656 		//
    657 		case sc_F7:
    658 			CA_CacheGrChunk(STARTFONT+1);
    659 
    660 			WindowH=160;
    661 			#ifdef JAPAN
    662 			if (GetYorN(7,8,C_JAPQUITPIC))
    663 			#else
    664 			if (Confirm(ENDGAMESTR))
    665 			#endif
    666 			{
    667 				playstate = ex_died;
    668 				pickquick = gamestate.lives = 0;
    669 			}
    670 
    671 			DrawAllPlayBorder();
    672 			WindowH=200;
    673 			fontnumber=0;
    674 			MainMenu[savegame].active = 0;
    675 			return 1;
    676 
    677 		//
    678 		// QUICKSAVE
    679 		//
    680 		case sc_F8:
    681 			if (SaveGamesAvail[LSItems.curpos] && pickquick)
    682 			{
    683 				CA_CacheGrChunk(STARTFONT+1);
    684 				fontnumber = 1;
    685 				Message(STR_SAVING"...");
    686 				CP_SaveGame(1);
    687 				fontnumber=0;
    688 			}
    689 			else
    690 			{
    691 				#ifndef SPEAR
    692 				CA_CacheGrChunk(STARTFONT+1);
    693 				CA_CacheGrChunk(C_CURSOR1PIC);
    694 				CA_CacheGrChunk(C_CURSOR2PIC);
    695 				CA_CacheGrChunk(C_DISKLOADING1PIC);
    696 				CA_CacheGrChunk(C_DISKLOADING2PIC);
    697 				CA_CacheGrChunk(C_SAVEGAMEPIC);
    698 				CA_CacheGrChunk(C_MOUSELBACKPIC);
    699 				#else
    700 				CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    701 				CA_CacheGrChunk(C_CURSOR1PIC);
    702 				#endif
    703 
    704 				VW_FadeOut ();
    705 
    706 				StartCPMusic(MENUSONG);
    707 				pickquick=CP_SaveGame(0);
    708 
    709 				SETFONTCOLOR(0,15);
    710 				IN_ClearKeysDown();
    711 				DrawPlayScreen ();
    712 
    713 				if (!startgame && !loadedgame)
    714 				{
    715 					VW_FadeIn ();
    716 					StartMusic ();
    717 				}
    718 
    719 				if (loadedgame)
    720 					playstate = ex_abort;
    721 				lasttimecount = TimeCount;
    722 
    723 				if (MousePresent)
    724 					Mouse(MDelta);	// Clear accumulated mouse movement
    725 
    726 				PM_CheckMainMem ();
    727 
    728 				#ifndef SPEAR
    729 				UNCACHEGRCHUNK(C_CURSOR1PIC);
    730 				UNCACHEGRCHUNK(C_CURSOR2PIC);
    731 				UNCACHEGRCHUNK(C_DISKLOADING1PIC);
    732 				UNCACHEGRCHUNK(C_DISKLOADING2PIC);
    733 				UNCACHEGRCHUNK(C_SAVEGAMEPIC);
    734 				UNCACHEGRCHUNK(C_MOUSELBACKPIC);
    735 				#else
    736 				UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    737 				#endif
    738 			}
    739 			return 1;
    740 
    741 		//
    742 		// QUICKLOAD
    743 		//
    744 		case sc_F9:
    745 			if (SaveGamesAvail[LSItems.curpos] && pickquick)
    746 			{
    747 				char string[100]=STR_LGC;
    748 
    749 
    750 				CA_CacheGrChunk(STARTFONT+1);
    751 				fontnumber = 1;
    752 
    753 				strcat(string,SaveGameNames[LSItems.curpos]);
    754 				strcat(string,"\"?");
    755 
    756 				if (Confirm(string))
    757 					CP_LoadGame(1);
    758 
    759 				DrawAllPlayBorder();
    760 				fontnumber=0;
    761 			}
    762 			else
    763 			{
    764 				#ifndef SPEAR
    765 				CA_CacheGrChunk(STARTFONT+1);
    766 				CA_CacheGrChunk(C_CURSOR1PIC);
    767 				CA_CacheGrChunk(C_CURSOR2PIC);
    768 				CA_CacheGrChunk(C_DISKLOADING1PIC);
    769 				CA_CacheGrChunk(C_DISKLOADING2PIC);
    770 				CA_CacheGrChunk(C_LOADGAMEPIC);
    771 				CA_CacheGrChunk(C_MOUSELBACKPIC);
    772 				#else
    773 				CA_CacheGrChunk(C_CURSOR1PIC);
    774 				CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    775 				#endif
    776 
    777 				VW_FadeOut ();
    778 
    779 				StartCPMusic(MENUSONG);
    780 				pickquick=CP_LoadGame(0);
    781 
    782 				SETFONTCOLOR(0,15);
    783 				IN_ClearKeysDown();
    784 				DrawPlayScreen ();
    785 
    786 				if (!startgame && !loadedgame)
    787 				{
    788 					VW_FadeIn ();
    789 					StartMusic ();
    790 				}
    791 
    792 				if (loadedgame)
    793 					playstate = ex_abort;
    794 
    795 				lasttimecount = TimeCount;
    796 
    797 				if (MousePresent)
    798 					Mouse(MDelta);	// Clear accumulated mouse movement
    799 				PM_CheckMainMem ();
    800 
    801 				#ifndef SPEAR
    802 				UNCACHEGRCHUNK(C_CURSOR1PIC);
    803 				UNCACHEGRCHUNK(C_CURSOR2PIC);
    804 				UNCACHEGRCHUNK(C_DISKLOADING1PIC);
    805 				UNCACHEGRCHUNK(C_DISKLOADING2PIC);
    806 				UNCACHEGRCHUNK(C_LOADGAMEPIC);
    807 				UNCACHEGRCHUNK(C_MOUSELBACKPIC);
    808 				#else
    809 				UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    810 				#endif
    811 			}
    812 			return 1;
    813 
    814 		//
    815 		// QUIT
    816 		//
    817 		case sc_F10:
    818 			CA_CacheGrChunk(STARTFONT+1);
    819 
    820 			WindowX=WindowY=0;
    821 			WindowW=320;
    822 			WindowH=160;
    823 			#ifdef JAPAN
    824 			if (GetYorN(7,8,C_QUITMSGPIC))
    825 			#else
    826 				#ifdef SPANISH
    827 			if (Confirm(ENDGAMESTR))
    828 				#else
    829 			if (Confirm(endStrings[US_RndT()&0x7+(US_RndT()&1)]))
    830 				#endif
    831 			#endif
    832 			{
    833 				int i;
    834 
    835 
    836 				VW_UpdateScreen();
    837 				SD_MusicOff();
    838 				SD_StopSound();
    839 				MenuFadeOut();
    840 
    841 				//
    842 				// SHUT-UP THE ADLIB
    843 				//
    844 				for (i=1;i<=0xf5;i++)
    845 					alOut(i,0);
    846 				Quit(NULL);
    847 			}
    848 
    849 			DrawAllPlayBorder();
    850 			WindowH=200;
    851 			fontnumber=0;
    852 			return 1;
    853 		}
    854 
    855 	return 0;
    856 }
    857 
    858 
    859 ////////////////////////////////////////////////////////////////////
    860 //
    861 // END THE CURRENT GAME
    862 //
    863 ////////////////////////////////////////////////////////////////////
    864 int CP_EndGame(void)
    865 {
    866 #ifdef JAPAN
    867 	if (!GetYorN(7,8,C_JAPQUITPIC))
    868 #else
    869 	if (!Confirm(ENDGAMESTR))
    870 #endif
    871 		return 0;
    872 
    873 	pickquick = gamestate.lives = 0;
    874 	playstate = ex_died;
    875 
    876 	#pragma warn -sus
    877 	MainMenu[savegame].active = 0;
    878 	MainMenu[viewscores].routine=CP_ViewScores;
    879 	#ifndef JAPAN
    880 	_fstrcpy(MainMenu[viewscores].string,STR_VS);
    881 	#endif
    882 	#pragma warn +sus
    883 
    884 	return 1;
    885 }
    886 
    887 
    888 ////////////////////////////////////////////////////////////////////
    889 //
    890 // VIEW THE HIGH SCORES
    891 //
    892 ////////////////////////////////////////////////////////////////////
    893 void CP_ViewScores(void)
    894 {
    895 	fontnumber=0;
    896 
    897 #ifdef SPEAR
    898 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    899 	StartCPMusic (XAWARD_MUS);
    900 #else
    901 	StartCPMusic (ROSTER_MUS);
    902 #endif
    903 
    904 	DrawHighScores ();
    905 	VW_UpdateScreen ();
    906 	MenuFadeIn();
    907 	fontnumber=1;
    908 
    909 	IN_Ack();
    910 
    911 	StartCPMusic(MENUSONG);
    912 	MenuFadeOut();
    913 
    914 #ifdef SPEAR
    915 	CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
    916 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    917 #endif
    918 }
    919 
    920 
    921 ////////////////////////////////////////////////////////////////////
    922 //
    923 // START A NEW GAME
    924 //
    925 ////////////////////////////////////////////////////////////////////
    926 void CP_NewGame(void)
    927 {
    928 	int which,episode;
    929 
    930 #ifdef SPEAR
    931 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
    932 #endif
    933 
    934 
    935 #ifndef SPEAR
    936 firstpart:
    937 
    938 	DrawNewEpisode();
    939 	do
    940 	{
    941 		which=HandleMenu(&NewEitems,&NewEmenu[0],NULL);
    942 		switch(which)
    943 		{
    944 			case -1:
    945 				MenuFadeOut();
    946 				return;
    947 
    948 			default:
    949 				if (!EpisodeSelect[which/2])
    950 				{
    951 					SD_PlaySound (NOWAYSND);
    952 					Message("Please select \"Read This!\"\n"
    953 							"from the Options menu to\n"
    954 							"find out how to order this\n"
    955 							"episode from Apogee.");
    956 					IN_ClearKeysDown();
    957 					IN_Ack();
    958 					DrawNewEpisode();
    959 					which = 0;
    960 				}
    961 				else
    962 				{
    963 					episode = which/2;
    964 					which = 1;
    965 				}
    966 				break;
    967 		}
    968 
    969 	} while (!which);
    970 
    971 	ShootSnd();
    972 
    973 	//
    974 	// ALREADY IN A GAME?
    975 	//
    976 	if (ingame)
    977 		#ifdef JAPAN
    978 		if (!GetYorN(7,8,C_JAPNEWGAMEPIC))
    979 		#else
    980 		if (!Confirm(CURGAME))
    981 		#endif
    982 		{
    983 			MenuFadeOut();
    984 			return;
    985 		}
    986 
    987 	MenuFadeOut();
    988 
    989 #else
    990 	episode = 0;
    991 
    992 	//
    993 	// ALREADY IN A GAME?
    994 	//
    995 	CacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
    996 	DrawNewGame();
    997 	if (ingame)
    998 		if (!Confirm(CURGAME))
    999 		{
   1000 			MenuFadeOut();
   1001 			UnCacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
   1002 			CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1003 			return;
   1004 		}
   1005 
   1006 #endif
   1007 
   1008 	DrawNewGame();
   1009 	which=HandleMenu(&NewItems,&NewMenu[0],DrawNewGameDiff);
   1010 	if (which<0)
   1011 	{
   1012 		MenuFadeOut();
   1013 		#ifndef SPEAR
   1014 		goto firstpart;
   1015 		#else
   1016 		UnCacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
   1017 		CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1018 		return;
   1019 		#endif
   1020 	}
   1021 
   1022 	ShootSnd();
   1023 	NewGame(which,episode);
   1024 	StartGame=1;
   1025 	MenuFadeOut();
   1026 
   1027 	//
   1028 	// CHANGE "READ THIS!" TO NORMAL COLOR
   1029 	//
   1030 	#ifndef SPEAR
   1031 	#ifndef GOODTIMES
   1032 	MainMenu[readthis].active=1;
   1033 	#endif
   1034 	#endif
   1035 
   1036 	pickquick = 0;
   1037 
   1038 #ifdef SPEAR
   1039 	UnCacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
   1040 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1041 #endif
   1042 }
   1043 
   1044 
   1045 #ifndef SPEAR
   1046 /////////////////////
   1047 //
   1048 // DRAW NEW EPISODE MENU
   1049 //
   1050 void DrawNewEpisode(void)
   1051 {
   1052 	int i;
   1053 
   1054 #ifdef JAPAN
   1055 	CA_CacheScreen(S_EPISODEPIC);
   1056 #else
   1057 	ClearMScreen();
   1058 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   1059 
   1060 	DrawWindow(NE_X-4,NE_Y-4,NE_W+8,NE_H+8,BKGDCOLOR);
   1061 	SETFONTCOLOR(READHCOLOR,BKGDCOLOR);
   1062 	PrintY=2;
   1063 	WindowX=0;
   1064 	#ifdef SPANISH
   1065 	US_CPrint("Cual episodio jugar?");
   1066 	#else
   1067 	US_CPrint("Which episode to play?");
   1068 	#endif
   1069 #endif
   1070 
   1071 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   1072 	DrawMenu(&NewEitems,&NewEmenu[0]);
   1073 
   1074 	for (i=0;i<6;i++)
   1075 		VWB_DrawPic(NE_X+32,NE_Y+i*26,C_EPISODE1PIC+i);
   1076 
   1077 	VW_UpdateScreen();
   1078 	MenuFadeIn();
   1079 	WaitKeyUp();
   1080 }
   1081 #endif
   1082 
   1083 /////////////////////
   1084 //
   1085 // DRAW NEW GAME MENU
   1086 //
   1087 void DrawNewGame(void)
   1088 {
   1089 #ifdef JAPAN
   1090 	CA_CacheScreen(S_SKILLPIC);
   1091 #else
   1092 	ClearMScreen();
   1093 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   1094 
   1095 	SETFONTCOLOR(READHCOLOR,BKGDCOLOR);
   1096 	PrintX=NM_X+20;
   1097 	PrintY=NM_Y-32;
   1098 
   1099 #ifndef SPEAR
   1100 	#ifdef SPANISH
   1101 	US_Print("Eres macho?");
   1102 	#else
   1103 	US_Print("How tough are you?");
   1104 	#endif
   1105 #else
   1106 	VWB_DrawPic (PrintX,PrintY,C_HOWTOUGHPIC);
   1107 #endif
   1108 
   1109 	DrawWindow(NM_X-5,NM_Y-10,NM_W,NM_H,BKGDCOLOR);
   1110 #endif
   1111 
   1112 	DrawMenu(&NewItems,&NewMenu[0]);
   1113 	DrawNewGameDiff(NewItems.curpos);
   1114 	VW_UpdateScreen();
   1115 	MenuFadeIn();
   1116 	WaitKeyUp();
   1117 }
   1118 
   1119 
   1120 ////////////////////////
   1121 //
   1122 // DRAW NEW GAME GRAPHIC
   1123 //
   1124 void DrawNewGameDiff(int w)
   1125 {
   1126 	VWB_DrawPic(NM_X+185,NM_Y+7,w+C_BABYMODEPIC);
   1127 }
   1128 
   1129 
   1130 ////////////////////////////////////////////////////////////////////
   1131 //
   1132 // HANDLE SOUND MENU
   1133 //
   1134 ////////////////////////////////////////////////////////////////////
   1135 void CP_Sound(void)
   1136 {
   1137 	int which,i;
   1138 
   1139 
   1140 #ifdef SPEAR
   1141 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1142 	CacheLump (SOUND_LUMP_START,SOUND_LUMP_END);
   1143 #endif
   1144 
   1145 	DrawSoundMenu();
   1146 	MenuFadeIn();
   1147 	WaitKeyUp();
   1148 
   1149 	do
   1150 	{
   1151 		which=HandleMenu(&SndItems,&SndMenu[0],NULL);
   1152 		//
   1153 		// HANDLE MENU CHOICES
   1154 		//
   1155 		switch(which)
   1156 		{
   1157 			//
   1158 			// SOUND EFFECTS
   1159 			//
   1160 			case 0:
   1161 				if (SoundMode!=sdm_Off)
   1162 				{
   1163 					SD_WaitSoundDone();
   1164 					SD_SetSoundMode(sdm_Off);
   1165 					DrawSoundMenu();
   1166 				}
   1167 				break;
   1168 			case 1:
   1169 				if (SoundMode!=sdm_PC)
   1170 				{
   1171 					SD_WaitSoundDone();
   1172 					SD_SetSoundMode(sdm_PC);
   1173 					CA_LoadAllSounds();
   1174 					DrawSoundMenu();
   1175 					ShootSnd();
   1176 				}
   1177 				break;
   1178 			case 2:
   1179 				if (SoundMode!=sdm_AdLib)
   1180 				{
   1181 					SD_WaitSoundDone();
   1182 					SD_SetSoundMode(sdm_AdLib);
   1183 					CA_LoadAllSounds();
   1184 					DrawSoundMenu();
   1185 					ShootSnd();
   1186 				}
   1187 				break;
   1188 
   1189 			//
   1190 			// DIGITIZED SOUND
   1191 			//
   1192 			case 5:
   1193 				if (DigiMode!=sds_Off)
   1194 				{
   1195 					SD_SetDigiDevice(sds_Off);
   1196 					DrawSoundMenu();
   1197 				}
   1198 				break;
   1199 			case 6:
   1200 				if (DigiMode!=sds_SoundSource)
   1201 				{
   1202 					SD_SetDigiDevice(sds_SoundSource);
   1203 					DrawSoundMenu();
   1204 					ShootSnd();
   1205 				}
   1206 				break;
   1207 			case 7:
   1208 				if (DigiMode!=sds_SoundBlaster)
   1209 				{
   1210 					SD_SetDigiDevice(sds_SoundBlaster);
   1211 					DrawSoundMenu();
   1212 					ShootSnd();
   1213 				}
   1214 				break;
   1215 
   1216 			//
   1217 			// MUSIC
   1218 			//
   1219 			case 10:
   1220 				if (MusicMode!=smm_Off)
   1221 				{
   1222 					SD_SetMusicMode(smm_Off);
   1223 					DrawSoundMenu();
   1224 					ShootSnd();
   1225 				}
   1226 				break;
   1227 			case 11:
   1228 				if (MusicMode!=smm_AdLib)
   1229 				{
   1230 					SD_SetMusicMode(smm_AdLib);
   1231 					DrawSoundMenu();
   1232 					ShootSnd();
   1233 					StartCPMusic(MENUSONG);
   1234 				}
   1235 				break;
   1236 		}
   1237 	} while(which>=0);
   1238 
   1239 	MenuFadeOut();
   1240 
   1241 #ifdef SPEAR
   1242 	UnCacheLump (SOUND_LUMP_START,SOUND_LUMP_END);
   1243 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1244 #endif
   1245 }
   1246 
   1247 
   1248 //////////////////////
   1249 //
   1250 // DRAW THE SOUND MENU
   1251 //
   1252 void DrawSoundMenu(void)
   1253 {
   1254 	int i,on;
   1255 
   1256 
   1257 #ifdef JAPAN
   1258 	CA_CacheScreen(S_SOUNDPIC);
   1259 #else
   1260 	//
   1261 	// DRAW SOUND MENU
   1262 	//
   1263 	ClearMScreen();
   1264 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   1265 
   1266 	DrawWindow(SM_X-8,SM_Y1-3,SM_W,SM_H1,BKGDCOLOR);
   1267 	DrawWindow(SM_X-8,SM_Y2-3,SM_W,SM_H2,BKGDCOLOR);
   1268 	DrawWindow(SM_X-8,SM_Y3-3,SM_W,SM_H3,BKGDCOLOR);
   1269 #endif
   1270 
   1271 	//
   1272 	// IF NO ADLIB, NON-CHOOSENESS!
   1273 	//
   1274 	if (!AdLibPresent && !SoundBlasterPresent)
   1275 	{
   1276 		SndMenu[2].active=SndMenu[10].active=SndMenu[11].active=0;
   1277 	}
   1278 
   1279 	if (!SoundSourcePresent)
   1280 		SndMenu[6].active=0;
   1281 
   1282 	if (!SoundBlasterPresent)
   1283 		SndMenu[7].active=0;
   1284 
   1285 	if (!SoundSourcePresent && !SoundBlasterPresent)
   1286 		SndMenu[5].active=0;
   1287 
   1288 	DrawMenu(&SndItems,&SndMenu[0]);
   1289 #ifndef JAPAN
   1290 	VWB_DrawPic(100,SM_Y1-20,C_FXTITLEPIC);
   1291 	VWB_DrawPic(100,SM_Y2-20,C_DIGITITLEPIC);
   1292 	VWB_DrawPic(100,SM_Y3-20,C_MUSICTITLEPIC);
   1293 #endif
   1294 
   1295 	for (i=0;i<SndItems.amount;i++)
   1296 #ifdef JAPAN
   1297 		if (i!=3 && i!=4 && i!=8 && i!=9)
   1298 #else
   1299 		if (SndMenu[i].string[0])
   1300 #endif
   1301 		{
   1302 			//
   1303 			// DRAW SELECTED/NOT SELECTED GRAPHIC BUTTONS
   1304 			//
   1305 			on=0;
   1306 			switch(i)
   1307 			{
   1308 				//
   1309 				// SOUND EFFECTS
   1310 				//
   1311 				case 0: if (SoundMode==sdm_Off) on=1; break;
   1312 				case 1: if (SoundMode==sdm_PC) on=1; break;
   1313 				case 2: if (SoundMode==sdm_AdLib) on=1; break;
   1314 
   1315 				//
   1316 				// DIGITIZED SOUND
   1317 				//
   1318 				case 5: if (DigiMode==sds_Off) on=1; break;
   1319 				case 6: if (DigiMode==sds_SoundSource) on=1; break;
   1320 				case 7: if (DigiMode==sds_SoundBlaster) on=1; break;
   1321 
   1322 				//
   1323 				// MUSIC
   1324 				//
   1325 				case 10: if (MusicMode==smm_Off) on=1; break;
   1326 				case 11: if (MusicMode==smm_AdLib) on=1; break;
   1327 			}
   1328 
   1329 			if (on)
   1330 				VWB_DrawPic(SM_X+24,SM_Y1+i*13+2,C_SELECTEDPIC);
   1331 			else
   1332 				VWB_DrawPic(SM_X+24,SM_Y1+i*13+2,C_NOTSELECTEDPIC);
   1333 		}
   1334 
   1335 	DrawMenuGun(&SndItems);
   1336 	VW_UpdateScreen();
   1337 }
   1338 
   1339 
   1340 //
   1341 // DRAW LOAD/SAVE IN PROGRESS
   1342 //
   1343 void DrawLSAction(int which)
   1344 {
   1345 	#define LSA_X	96
   1346 	#define LSA_Y	80
   1347 	#define LSA_W	130
   1348 	#define LSA_H	42
   1349 
   1350 	DrawWindow(LSA_X,LSA_Y,LSA_W,LSA_H,TEXTCOLOR);
   1351 	DrawOutline(LSA_X,LSA_Y,LSA_W,LSA_H,0,HIGHLIGHT);
   1352 	VWB_DrawPic(LSA_X+8,LSA_Y+5,C_DISKLOADING1PIC);
   1353 
   1354 	fontnumber=1;
   1355 	SETFONTCOLOR(0,TEXTCOLOR);
   1356 	PrintX=LSA_X+46;
   1357 	PrintY=LSA_Y+13;
   1358 
   1359 	if (!which)
   1360 		US_Print(STR_LOADING"...");
   1361 	else
   1362 		US_Print(STR_SAVING"...");
   1363 
   1364 	VW_UpdateScreen();
   1365 }
   1366 
   1367 
   1368 ////////////////////////////////////////////////////////////////////
   1369 //
   1370 // LOAD SAVED GAMES
   1371 //
   1372 ////////////////////////////////////////////////////////////////////
   1373 int CP_LoadGame(int quick)
   1374 {
   1375 	int handle,which,exit=0;
   1376 	char name[13];
   1377 
   1378 
   1379 	strcpy(name,SaveName);
   1380 
   1381 	//
   1382 	// QUICKLOAD?
   1383 	//
   1384 	if (quick)
   1385 	{
   1386 		which=LSItems.curpos;
   1387 
   1388 		if (SaveGamesAvail[which])
   1389 		{
   1390 			name[7]=which+'0';
   1391 			handle=open(name,O_BINARY);
   1392 			lseek(handle,32,SEEK_SET);
   1393 			loadedgame=true;
   1394 			LoadTheGame(handle,0,0);
   1395 			loadedgame=false;
   1396 			close(handle);
   1397 
   1398 			DrawFace ();
   1399 			DrawHealth ();
   1400 			DrawLives ();
   1401 			DrawLevel ();
   1402 			DrawAmmo ();
   1403 			DrawKeys ();
   1404 			DrawWeapon ();
   1405 			DrawScore ();
   1406 			return 1;
   1407 		}
   1408 	}
   1409 
   1410 
   1411 #ifdef SPEAR
   1412 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1413 	CacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
   1414 #endif
   1415 
   1416 	DrawLoadSaveScreen(0);
   1417 
   1418 	do
   1419 	{
   1420 		which=HandleMenu(&LSItems,&LSMenu[0],TrackWhichGame);
   1421 		if (which>=0 && SaveGamesAvail[which])
   1422 		{
   1423 			ShootSnd();
   1424 			name[7]=which+'0';
   1425 
   1426 			handle=open(name,O_BINARY);
   1427 			lseek(handle,32,SEEK_SET);
   1428 
   1429 			DrawLSAction(0);
   1430 			loadedgame=true;
   1431 
   1432 			LoadTheGame(handle,LSA_X+8,LSA_Y+5);
   1433 			close(handle);
   1434 
   1435 			StartGame=1;
   1436 			ShootSnd();
   1437 			//
   1438 			// CHANGE "READ THIS!" TO NORMAL COLOR
   1439 			//
   1440 
   1441 			#ifndef SPEAR
   1442 			#ifndef GOODTIMES
   1443 			MainMenu[readthis].active=1;
   1444 			#endif
   1445 			#endif
   1446 
   1447 			exit=1;
   1448 			break;
   1449 		}
   1450 
   1451 	} while(which>=0);
   1452 
   1453 	MenuFadeOut();
   1454 
   1455 #ifdef SPEAR
   1456 	UnCacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
   1457 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1458 #endif
   1459 
   1460 	return exit;
   1461 }
   1462 
   1463 
   1464 ///////////////////////////////////
   1465 //
   1466 // HIGHLIGHT CURRENT SELECTED ENTRY
   1467 //
   1468 void TrackWhichGame(int w)
   1469 {
   1470 	static int lastgameon=0;
   1471 
   1472 	PrintLSEntry(lastgameon,TEXTCOLOR);
   1473 	PrintLSEntry(w,HIGHLIGHT);
   1474 
   1475 	lastgameon=w;
   1476 }
   1477 
   1478 
   1479 ////////////////////////////
   1480 //
   1481 // DRAW THE LOAD/SAVE SCREEN
   1482 //
   1483 void DrawLoadSaveScreen(int loadsave)
   1484 {
   1485 	#define DISKX	100
   1486 	#define DISKY	0
   1487 
   1488 	int i;
   1489 
   1490 
   1491 	ClearMScreen();
   1492 	fontnumber=1;
   1493 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   1494 	DrawWindow(LSM_X-10,LSM_Y-5,LSM_W,LSM_H,BKGDCOLOR);
   1495 	DrawStripes(10);
   1496 
   1497 	if (!loadsave)
   1498 		VWB_DrawPic(60,0,C_LOADGAMEPIC);
   1499 	else
   1500 		VWB_DrawPic(60,0,C_SAVEGAMEPIC);
   1501 
   1502 	for (i=0;i<10;i++)
   1503 		PrintLSEntry(i,TEXTCOLOR);
   1504 
   1505 	DrawMenu(&LSItems,&LSMenu[0]);
   1506 	VW_UpdateScreen();
   1507 	MenuFadeIn();
   1508 	WaitKeyUp();
   1509 }
   1510 
   1511 
   1512 ///////////////////////////////////////////
   1513 //
   1514 // PRINT LOAD/SAVE GAME ENTRY W/BOX OUTLINE
   1515 //
   1516 void PrintLSEntry(int w,int color)
   1517 {
   1518 	SETFONTCOLOR(color,BKGDCOLOR);
   1519 	DrawOutline(LSM_X+LSItems.indent,LSM_Y+w*13,LSM_W-LSItems.indent-15,11,color,color);
   1520 	PrintX=LSM_X+LSItems.indent+2;
   1521 	PrintY=LSM_Y+w*13+1;
   1522 	fontnumber=0;
   1523 
   1524 	if (SaveGamesAvail[w])
   1525 		US_Print(SaveGameNames[w]);
   1526 	else
   1527 		US_Print("      - "STR_EMPTY" -");
   1528 
   1529 	fontnumber=1;
   1530 }
   1531 
   1532 
   1533 ////////////////////////////////////////////////////////////////////
   1534 //
   1535 // SAVE CURRENT GAME
   1536 //
   1537 ////////////////////////////////////////////////////////////////////
   1538 int CP_SaveGame(int quick)
   1539 {
   1540 	int handle,which,exit=0;
   1541 	unsigned nwritten;
   1542 	char name[13],input[32];
   1543 
   1544 
   1545 	strcpy(name,SaveName);
   1546 
   1547 	//
   1548 	// QUICKSAVE?
   1549 	//
   1550 	if (quick)
   1551 	{
   1552 		which=LSItems.curpos;
   1553 
   1554 		if (SaveGamesAvail[which])
   1555 		{
   1556 			name[7]=which+'0';
   1557 			unlink(name);
   1558 			handle=creat(name,S_IREAD|S_IWRITE);
   1559 
   1560 			strcpy(input,&SaveGameNames[which][0]);
   1561 
   1562 			_dos_write(handle,(void far *)input,32,&nwritten);
   1563 			lseek(handle,32,SEEK_SET);
   1564 			SaveTheGame(handle,0,0);
   1565 			close(handle);
   1566 
   1567 			return 1;
   1568 		}
   1569 	}
   1570 
   1571 
   1572 #ifdef SPEAR
   1573 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1574 	CacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
   1575 #endif
   1576 
   1577 	DrawLoadSaveScreen(1);
   1578 
   1579 	do
   1580 	{
   1581 		which=HandleMenu(&LSItems,&LSMenu[0],TrackWhichGame);
   1582 		if (which>=0)
   1583 		{
   1584 			//
   1585 			// OVERWRITE EXISTING SAVEGAME?
   1586 			//
   1587 			if (SaveGamesAvail[which])
   1588 				#ifdef JAPAN
   1589 				if (!GetYorN(7,8,C_JAPSAVEOVERPIC))
   1590 				#else
   1591 				if (!Confirm(GAMESVD))
   1592 				#endif
   1593 				{
   1594 					DrawLoadSaveScreen(1);
   1595 					continue;
   1596 				}
   1597 				else
   1598 				{
   1599 					DrawLoadSaveScreen(1);
   1600 					PrintLSEntry(which,HIGHLIGHT);
   1601 					VW_UpdateScreen();
   1602 				}
   1603 
   1604 			ShootSnd();
   1605 
   1606 			strcpy(input,&SaveGameNames[which][0]);
   1607 			name[7]=which+'0';
   1608 
   1609 			fontnumber=0;
   1610 			if (!SaveGamesAvail[which])
   1611 				VWB_Bar(LSM_X+LSItems.indent+1,LSM_Y+which*13+1,LSM_W-LSItems.indent-16,10,BKGDCOLOR);
   1612 			VW_UpdateScreen();
   1613 
   1614 			if (US_LineInput(LSM_X+LSItems.indent+2,LSM_Y+which*13+1,input,input,true,31,LSM_W-LSItems.indent-30))
   1615 			{
   1616 				SaveGamesAvail[which]=1;
   1617 				strcpy(&SaveGameNames[which][0],input);
   1618 
   1619 				unlink(name);
   1620 				handle=creat(name,S_IREAD|S_IWRITE);
   1621 				_dos_write(handle,(void far *)input,32,&nwritten);
   1622 				lseek(handle,32,SEEK_SET);
   1623 
   1624 				DrawLSAction(1);
   1625 				SaveTheGame(handle,LSA_X+8,LSA_Y+5);
   1626 
   1627 				close(handle);
   1628 
   1629 				ShootSnd();
   1630 				exit=1;
   1631 			}
   1632 			else
   1633 			{
   1634 				VWB_Bar(LSM_X+LSItems.indent+1,LSM_Y+which*13+1,LSM_W-LSItems.indent-16,10,BKGDCOLOR);
   1635 				PrintLSEntry(which,HIGHLIGHT);
   1636 				VW_UpdateScreen();
   1637 				SD_PlaySound(ESCPRESSEDSND);
   1638 				continue;
   1639 			}
   1640 
   1641 			fontnumber=1;
   1642 			break;
   1643 		}
   1644 
   1645 	} while(which>=0);
   1646 
   1647 	MenuFadeOut();
   1648 
   1649 #ifdef SPEAR
   1650 	UnCacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
   1651 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1652 #endif
   1653 
   1654 	return exit;
   1655 }
   1656 
   1657 
   1658 ////////////////////////////////////////////////////////////////////
   1659 //
   1660 // CALIBRATE JOYSTICK
   1661 //
   1662 ////////////////////////////////////////////////////////////////////
   1663 int CalibrateJoystick(void)
   1664 {
   1665 	#define CALX	85
   1666 	#define CALY	40
   1667 	#define CALW	158
   1668 	#define CALH	140
   1669 
   1670 	unsigned xmin,ymin,xmax,ymax,jb;
   1671 
   1672 
   1673 
   1674 	#ifdef JAPAN
   1675 	VWB_DrawPic(CALX,CALY,C_JOY0PIC);
   1676 	#else
   1677 	DrawWindow(CALX-5,CALY-5,CALW,CALH,TEXTCOLOR);
   1678 	DrawOutline(CALX-5,CALY-5,CALW,CALH,0,HIGHLIGHT);
   1679 	SETFONTCOLOR(0,TEXTCOLOR);
   1680 
   1681 	WindowX = PrintX = CALX;
   1682 	WindowW = CALW;
   1683 	WindowH = CALH;
   1684 	WindowY = PrintY = CALY;
   1685 	US_Print("    "STR_CALIB"\n    "STR_JOYST"\n");
   1686 	VWB_DrawPic(CALX+40,CALY+30,C_JOY1PIC);
   1687 	PrintY = CALY+80;
   1688 	US_Print(STR_MOVEJOY);
   1689 	SETFONTCOLOR(BKGDCOLOR,TEXTCOLOR);
   1690 	US_Print("   "STR_ESCEXIT);
   1691 	#endif
   1692 	VW_UpdateScreen();
   1693 
   1694 	do
   1695 	{
   1696 		jb=IN_JoyButtons();
   1697 		if (Keyboard[sc_Escape])
   1698 			return 0;
   1699 		#ifndef SPEAR
   1700 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   1701 			PicturePause();
   1702 		#endif
   1703 
   1704 	} while(!(jb&1));
   1705 
   1706 	SD_PlaySound(SHOOTSND);
   1707 	IN_GetJoyAbs(joystickport,&xmin,&ymin);
   1708 
   1709 
   1710 	#ifdef JAPAN
   1711 	VWB_DrawPic(CALX,CALY,C_JOY1PIC);
   1712 	#else
   1713 	DrawWindow(CALX-5,CALY-5,CALW,CALH,TEXTCOLOR);
   1714 	DrawOutline(CALX-5,CALY-5,CALW,CALH,0,HIGHLIGHT);
   1715 	SETFONTCOLOR(0,TEXTCOLOR);
   1716 
   1717 	PrintX = CALX;
   1718 	PrintY = CALY;
   1719 	US_Print("    "STR_CALIB"\n    "STR_JOYST"\n");
   1720 	VWB_DrawPic(CALX+40,CALY+30,C_JOY2PIC);
   1721 	PrintY = CALY+80;
   1722 	US_Print(STR_MOVEJOY2);
   1723 	SETFONTCOLOR(BKGDCOLOR,TEXTCOLOR);
   1724 	US_Print("   "STR_ESCEXIT);
   1725 	#endif
   1726 	VW_UpdateScreen();
   1727 
   1728 	do
   1729 	{
   1730 		jb=IN_JoyButtons();
   1731 		if (Keyboard[sc_Escape])
   1732 			return 0;
   1733 		#ifndef SPEAR
   1734 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   1735 			PicturePause();
   1736 		#endif
   1737 	} while(!(jb&2));
   1738 
   1739 	IN_GetJoyAbs(joystickport,&xmax,&ymax);
   1740 	SD_PlaySound(SHOOTSND);
   1741 
   1742 	while (IN_JoyButtons());
   1743 
   1744 	//
   1745 	// ASSIGN ACTUAL VALUES HERE
   1746 	//
   1747 	if ((xmin != xmax) && (ymin != ymax))
   1748 		IN_SetupJoy(joystickport,xmin,xmax,ymin,ymax);
   1749 	else
   1750 		return 0;
   1751 
   1752 	return 1;
   1753 }
   1754 
   1755 
   1756 ////////////////////////////////////////////////////////////////////
   1757 //
   1758 // DEFINE CONTROLS
   1759 //
   1760 ////////////////////////////////////////////////////////////////////
   1761 void CP_Control(void)
   1762 {
   1763 	#define CTL_SPC	70
   1764 	enum {MOUSEENABLE,JOYENABLE,USEPORT2,PADENABLE,MOUSESENS,CUSTOMIZE};
   1765 	int i,which;
   1766 
   1767 
   1768 #ifdef SPEAR
   1769 	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1770 	CacheLump (CONTROL_LUMP_START,CONTROL_LUMP_END);
   1771 #endif
   1772 
   1773 	DrawCtlScreen();
   1774 	MenuFadeIn();
   1775 	WaitKeyUp();
   1776 
   1777 	do
   1778 	{
   1779 		which=HandleMenu(&CtlItems,&CtlMenu[0],NULL);
   1780 		switch(which)
   1781 		{
   1782 			case MOUSEENABLE:
   1783 				mouseenabled^=1;
   1784 				_CX=_DX=CENTER;
   1785 				Mouse(4);
   1786 				DrawCtlScreen();
   1787 				CusItems.curpos=-1;
   1788 				ShootSnd();
   1789 				break;
   1790 
   1791 			case JOYENABLE:
   1792 				joystickenabled^=1;
   1793 				if (joystickenabled)
   1794 					if (!CalibrateJoystick())
   1795 						joystickenabled = 0;
   1796 				DrawCtlScreen();
   1797 				CusItems.curpos=-1;
   1798 				ShootSnd();
   1799 				break;
   1800 
   1801 			case USEPORT2:
   1802 				joystickport^=1;
   1803 				DrawCtlScreen();
   1804 				ShootSnd();
   1805 				break;
   1806 
   1807 			case PADENABLE:
   1808 				joypadenabled^=1;
   1809 				DrawCtlScreen();
   1810 				ShootSnd();
   1811 				break;
   1812 
   1813 			case MOUSESENS:
   1814 			case CUSTOMIZE:
   1815 				DrawCtlScreen();
   1816 				MenuFadeIn();
   1817 				WaitKeyUp();
   1818 				break;
   1819 		}
   1820 	} while(which>=0);
   1821 
   1822 	MenuFadeOut();
   1823 
   1824 #ifdef SPEAR
   1825 	UnCacheLump (CONTROL_LUMP_START,CONTROL_LUMP_END);
   1826 	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
   1827 #endif
   1828 }
   1829 
   1830 
   1831 ////////////////////////////////
   1832 //
   1833 // DRAW MOUSE SENSITIVITY SCREEN
   1834 //
   1835 void DrawMouseSens(void)
   1836 {
   1837 #ifdef JAPAN
   1838 	CA_CacheScreen(S_MOUSESENSPIC);
   1839 #else
   1840 	ClearMScreen();
   1841 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   1842 	#ifdef SPANISH
   1843 	DrawWindow(10,80,300,43,BKGDCOLOR);
   1844 	#else
   1845 	DrawWindow(10,80,300,30,BKGDCOLOR);
   1846 	#endif
   1847 
   1848 	WindowX=0;
   1849 	WindowW=320;
   1850 	PrintY=82;
   1851 	SETFONTCOLOR(READCOLOR,BKGDCOLOR);
   1852 	US_CPrint(STR_MOUSEADJ);
   1853 
   1854 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   1855 	#ifdef SPANISH
   1856 	PrintX=14;
   1857 	PrintY=95+13;
   1858 	US_Print(STR_SLOW);
   1859 	PrintX=252;
   1860 	US_Print(STR_FAST);
   1861 	#else
   1862 	PrintX=14;
   1863 	PrintY=95;
   1864 	US_Print(STR_SLOW);
   1865 	PrintX=269;
   1866 	US_Print(STR_FAST);
   1867 	#endif
   1868 #endif
   1869 
   1870 	VWB_Bar(60,97,200,10,TEXTCOLOR);
   1871 	DrawOutline(60,97,200,10,0,HIGHLIGHT);
   1872 	DrawOutline(60+20*mouseadjustment,97,20,10,0,READCOLOR);
   1873 	VWB_Bar(61+20*mouseadjustment,98,19,9,READHCOLOR);
   1874 
   1875 	VW_UpdateScreen();
   1876 	MenuFadeIn();
   1877 }
   1878 
   1879 
   1880 ///////////////////////////
   1881 //
   1882 // ADJUST MOUSE SENSITIVITY
   1883 //
   1884 void MouseSensitivity(void)
   1885 {
   1886 	ControlInfo ci;
   1887 	int exit=0,oldMA;
   1888 
   1889 
   1890 	oldMA=mouseadjustment;
   1891 	DrawMouseSens();
   1892 	do
   1893 	{
   1894 		ReadAnyControl(&ci);
   1895 		switch(ci.dir)
   1896 		{
   1897 			case dir_North:
   1898 			case dir_West:
   1899 				if (mouseadjustment)
   1900 				{
   1901 					mouseadjustment--;
   1902 					VWB_Bar(60,97,200,10,TEXTCOLOR);
   1903 					DrawOutline(60,97,200,10,0,HIGHLIGHT);
   1904 					DrawOutline(60+20*mouseadjustment,97,20,10,0,READCOLOR);
   1905 					VWB_Bar(61+20*mouseadjustment,98,19,9,READHCOLOR);
   1906 					VW_UpdateScreen();
   1907 					SD_PlaySound(MOVEGUN1SND);
   1908 					while(Keyboard[sc_LeftArrow]);
   1909 					WaitKeyUp();
   1910 				}
   1911 				break;
   1912 
   1913 			case dir_South:
   1914 			case dir_East:
   1915 				if (mouseadjustment<9)
   1916 				{
   1917 					mouseadjustment++;
   1918 					VWB_Bar(60,97,200,10,TEXTCOLOR);
   1919 					DrawOutline(60,97,200,10,0,HIGHLIGHT);
   1920 					DrawOutline(60+20*mouseadjustment,97,20,10,0,READCOLOR);
   1921 					VWB_Bar(61+20*mouseadjustment,98,19,9,READHCOLOR);
   1922 					VW_UpdateScreen();
   1923 					SD_PlaySound(MOVEGUN1SND);
   1924 					while(Keyboard[sc_RightArrow]);
   1925 					WaitKeyUp();
   1926 				}
   1927 				break;
   1928 		}
   1929 
   1930 		#ifndef SPEAR
   1931 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   1932 		#else
   1933 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("debugmode"))
   1934 		#endif
   1935 			PicturePause();
   1936 
   1937 		if (ci.button0 || Keyboard[sc_Space] || Keyboard[sc_Enter])
   1938 			exit=1;
   1939 		else
   1940 		if (ci.button1 || Keyboard[sc_Escape])
   1941 			exit=2;
   1942 
   1943 	} while(!exit);
   1944 
   1945 	if (exit==2)
   1946 	{
   1947 		mouseadjustment=oldMA;
   1948 		SD_PlaySound(ESCPRESSEDSND);
   1949 	}
   1950 	else
   1951 		SD_PlaySound(SHOOTSND);
   1952 
   1953 	WaitKeyUp();
   1954 	MenuFadeOut();
   1955 }
   1956 
   1957 
   1958 ///////////////////////////
   1959 //
   1960 // DRAW CONTROL MENU SCREEN
   1961 //
   1962 void DrawCtlScreen(void)
   1963 {
   1964  int i,x,y;
   1965 
   1966 
   1967 #ifdef JAPAN
   1968 	CA_CacheScreen(S_CONTROLPIC);
   1969 #else
   1970  ClearMScreen();
   1971  DrawStripes(10);
   1972  VWB_DrawPic(80,0,C_CONTROLPIC);
   1973  VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   1974  DrawWindow(CTL_X-8,CTL_Y-5,CTL_W,CTL_H,BKGDCOLOR);
   1975 #endif
   1976  WindowX=0;
   1977  WindowW=320;
   1978  SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   1979 
   1980  if (JoysPresent[0])
   1981    CtlMenu[1].active=
   1982    CtlMenu[2].active=
   1983    CtlMenu[3].active=1;
   1984 
   1985  CtlMenu[2].active=CtlMenu[3].active=joystickenabled;
   1986 
   1987  if (MousePresent)
   1988  {
   1989   CtlMenu[4].active=
   1990   CtlMenu[0].active=1;
   1991  }
   1992 
   1993  CtlMenu[4].active=mouseenabled;
   1994 
   1995 
   1996  DrawMenu(&CtlItems,&CtlMenu[0]);
   1997 
   1998 
   1999  x=CTL_X+CtlItems.indent-24;
   2000  y=CTL_Y+3;
   2001  if (mouseenabled)
   2002    VWB_DrawPic(x,y,C_SELECTEDPIC);
   2003  else
   2004    VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
   2005 
   2006  y=CTL_Y+16;
   2007  if (joystickenabled)
   2008    VWB_DrawPic(x,y,C_SELECTEDPIC);
   2009  else
   2010    VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
   2011 
   2012  y=CTL_Y+29;
   2013  if (joystickport)
   2014    VWB_DrawPic(x,y,C_SELECTEDPIC);
   2015  else
   2016    VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
   2017 
   2018  y=CTL_Y+42;
   2019  if (joypadenabled)
   2020    VWB_DrawPic(x,y,C_SELECTEDPIC);
   2021  else
   2022    VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
   2023 
   2024  //
   2025  // PICK FIRST AVAILABLE SPOT
   2026  //
   2027  if (CtlItems.curpos<0 || !CtlMenu[CtlItems.curpos].active)
   2028    for (i=0;i<6;i++)
   2029 	 if (CtlMenu[i].active)
   2030 	 {
   2031 	  CtlItems.curpos=i;
   2032 	  break;
   2033 	 }
   2034 
   2035  DrawMenuGun(&CtlItems);
   2036  VW_UpdateScreen();
   2037 }
   2038 
   2039 
   2040 ////////////////////////////////////////////////////////////////////
   2041 //
   2042 // CUSTOMIZE CONTROLS
   2043 //
   2044 ////////////////////////////////////////////////////////////////////
   2045 enum {FIRE,STRAFE,RUN,OPEN};
   2046 char mbarray[4][3]={"b0","b1","b2","b3"},
   2047 	   order[4]={RUN,OPEN,FIRE,STRAFE};
   2048 
   2049 
   2050 void CustomControls(void)
   2051 {
   2052  int which;
   2053 
   2054 
   2055  DrawCustomScreen();
   2056  do
   2057  {
   2058   which=HandleMenu(&CusItems,&CusMenu[0],FixupCustom);
   2059   switch(which)
   2060   {
   2061    case 0:
   2062 	 DefineMouseBtns();
   2063 	 DrawCustMouse(1);
   2064 	 break;
   2065    case 3:
   2066 	 DefineJoyBtns();
   2067 	 DrawCustJoy(0);
   2068 	 break;
   2069    case 6:
   2070 	 DefineKeyBtns();
   2071 	 DrawCustKeybd(0);
   2072 	 break;
   2073    case 8:
   2074 	 DefineKeyMove();
   2075 	 DrawCustKeys(0);
   2076   }
   2077  } while(which>=0);
   2078 
   2079 
   2080 
   2081  MenuFadeOut();
   2082 }
   2083 
   2084 
   2085 ////////////////////////
   2086 //
   2087 // DEFINE THE MOUSE BUTTONS
   2088 //
   2089 void DefineMouseBtns(void)
   2090 {
   2091  CustomCtrls mouseallowed={0,1,1,1};
   2092  EnterCtrlData(2,&mouseallowed,DrawCustMouse,PrintCustMouse,MOUSE);
   2093 }
   2094 
   2095 
   2096 ////////////////////////
   2097 //
   2098 // DEFINE THE JOYSTICK BUTTONS
   2099 //
   2100 void DefineJoyBtns(void)
   2101 {
   2102  CustomCtrls joyallowed={1,1,1,1};
   2103  EnterCtrlData(5,&joyallowed,DrawCustJoy,PrintCustJoy,JOYSTICK);
   2104 }
   2105 
   2106 
   2107 ////////////////////////
   2108 //
   2109 // DEFINE THE KEYBOARD BUTTONS
   2110 //
   2111 void DefineKeyBtns(void)
   2112 {
   2113  CustomCtrls keyallowed={1,1,1,1};
   2114  EnterCtrlData(8,&keyallowed,DrawCustKeybd,PrintCustKeybd,KEYBOARDBTNS);
   2115 }
   2116 
   2117 
   2118 ////////////////////////
   2119 //
   2120 // DEFINE THE KEYBOARD BUTTONS
   2121 //
   2122 void DefineKeyMove(void)
   2123 {
   2124 	CustomCtrls keyallowed={1,1,1,1};
   2125 	EnterCtrlData(10,&keyallowed,DrawCustKeys,PrintCustKeys,KEYBOARDMOVE);
   2126 }
   2127 
   2128 
   2129 ////////////////////////
   2130 //
   2131 // ENTER CONTROL DATA FOR ANY TYPE OF CONTROL
   2132 //
   2133 enum {FWRD,RIGHT,BKWD,LEFT};
   2134 int moveorder[4]={LEFT,RIGHT,FWRD,BKWD};
   2135 
   2136 void EnterCtrlData(int index,CustomCtrls *cust,void (*DrawRtn)(int),void (*PrintRtn)(int),int type)
   2137 {
   2138  int j,exit,tick,redraw,which,x,picked;
   2139  ControlInfo ci;
   2140 
   2141 
   2142  ShootSnd();
   2143  PrintY=CST_Y+13*index;
   2144  IN_ClearKeysDown();
   2145  exit=0;
   2146  redraw=1;
   2147  //
   2148  // FIND FIRST SPOT IN ALLOWED ARRAY
   2149  //
   2150  for (j=0;j<4;j++)
   2151    if (cust->allowed[j])
   2152    {
   2153 	which=j;
   2154 	break;
   2155    }
   2156 
   2157  do
   2158  {
   2159   if (redraw)
   2160   {
   2161    x=CST_START+CST_SPC*which;
   2162    DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
   2163 
   2164    DrawRtn(1);
   2165    DrawWindow(x-2,PrintY,CST_SPC,11,TEXTCOLOR);
   2166    DrawOutline(x-2,PrintY,CST_SPC,11,0,HIGHLIGHT);
   2167    SETFONTCOLOR(0,TEXTCOLOR);
   2168    PrintRtn(which);
   2169    PrintX=x;
   2170    SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   2171    VW_UpdateScreen();
   2172    WaitKeyUp();
   2173    redraw=0;
   2174   }
   2175 
   2176   ReadAnyControl(&ci);
   2177 
   2178   if (type==MOUSE || type==JOYSTICK)
   2179 	if (IN_KeyDown(sc_Enter)||IN_KeyDown(sc_Control)||IN_KeyDown(sc_Alt))
   2180 	{
   2181 	 IN_ClearKeysDown();
   2182 	 ci.button0=ci.button1=false;
   2183 	}
   2184 
   2185   //
   2186   // CHANGE BUTTON VALUE?
   2187   //
   2188   if ((ci.button0|ci.button1|ci.button2|ci.button3)||
   2189 	  ((type==KEYBOARDBTNS||type==KEYBOARDMOVE) && LastScan==sc_Enter))
   2190   {
   2191    tick=TimeCount=picked=0;
   2192    SETFONTCOLOR(0,TEXTCOLOR);
   2193 
   2194    do
   2195    {
   2196 	int button,result=0;
   2197 
   2198 
   2199 	if (type==KEYBOARDBTNS||type==KEYBOARDMOVE)
   2200 	  IN_ClearKeysDown();
   2201 
   2202 	//
   2203 	// FLASH CURSOR
   2204 	//
   2205 	if (TimeCount>10)
   2206 	{
   2207 	 switch(tick)
   2208 	 {
   2209 	  case 0:
   2210 	VWB_Bar(x,PrintY+1,CST_SPC-2,10,TEXTCOLOR);
   2211 	break;
   2212 	  case 1:
   2213 	PrintX=x;
   2214 	US_Print("?");
   2215 	SD_PlaySound(HITWALLSND);
   2216 	 }
   2217 	 tick^=1;
   2218 	 TimeCount=0;
   2219 	 VW_UpdateScreen();
   2220 	}
   2221 
   2222 	//
   2223 	// WHICH TYPE OF INPUT DO WE PROCESS?
   2224 	//
   2225 	switch(type)
   2226 	{
   2227 	 case MOUSE:
   2228 	   Mouse(3);
   2229 	   button=_BX;
   2230 	   switch(button)
   2231 	   {
   2232 	case 1: result=1; break;
   2233 	case 2: result=2; break;
   2234 	case 4: result=3; break;
   2235 	   }
   2236 
   2237 	   if (result)
   2238 	   {
   2239 	int z;
   2240 
   2241 
   2242 	for (z=0;z<4;z++)
   2243 	  if (order[which]==buttonmouse[z])
   2244 	  {
   2245 	   buttonmouse[z]=bt_nobutton;
   2246 	   break;
   2247 	  }
   2248 
   2249 	buttonmouse[result-1]=order[which];
   2250 	picked=1;
   2251 	SD_PlaySound(SHOOTDOORSND);
   2252 	   }
   2253 	   break;
   2254 
   2255 	 case JOYSTICK:
   2256 	   if (ci.button0) result=1;
   2257 	   else
   2258 	   if (ci.button1) result=2;
   2259 	   else
   2260 	   if (ci.button2) result=3;
   2261 	   else
   2262 	   if (ci.button3) result=4;
   2263 
   2264 	   if (result)
   2265 	   {
   2266 	int z;
   2267 
   2268 
   2269 	for (z=0;z<4;z++)
   2270 	  if (order[which]==buttonjoy[z])
   2271 	  {
   2272 	   buttonjoy[z]=bt_nobutton;
   2273 	   break;
   2274 	  }
   2275 
   2276 	buttonjoy[result-1]=order[which];
   2277 	picked=1;
   2278 	SD_PlaySound(SHOOTDOORSND);
   2279 	   }
   2280 	   break;
   2281 
   2282 	 case KEYBOARDBTNS:
   2283 	   if (LastScan)
   2284 	   {
   2285 	buttonscan[order[which]]=LastScan;
   2286 	picked=1;
   2287 	ShootSnd();
   2288 	IN_ClearKeysDown();
   2289 	   }
   2290 	   break;
   2291 
   2292 	 case KEYBOARDMOVE:
   2293 	   if (LastScan)
   2294 	   {
   2295 	dirscan[moveorder[which]]=LastScan;
   2296 	picked=1;
   2297 	ShootSnd();
   2298 	IN_ClearKeysDown();
   2299 	   }
   2300 	   break;
   2301 	}
   2302 
   2303 	//
   2304 	// EXIT INPUT?
   2305 	//
   2306 	if (IN_KeyDown(sc_Escape))
   2307 	{
   2308 	 picked=1;
   2309 	 continue;
   2310 	}
   2311 
   2312    } while(!picked);
   2313 
   2314    SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   2315    redraw=1;
   2316    WaitKeyUp();
   2317    continue;
   2318   }
   2319 
   2320   if (ci.button1 || IN_KeyDown(sc_Escape))
   2321 	exit=1;
   2322 
   2323   //
   2324   // MOVE TO ANOTHER SPOT?
   2325   //
   2326   switch(ci.dir)
   2327   {
   2328    case dir_West:
   2329 	 do
   2330 	 {
   2331 	  which--;
   2332 	  if (which<0)
   2333 	which=3;
   2334 	 } while(!cust->allowed[which]);
   2335 	 redraw=1;
   2336 	 SD_PlaySound(MOVEGUN1SND);
   2337 	 while(ReadAnyControl(&ci),ci.dir!=dir_None);
   2338 	 IN_ClearKeysDown();
   2339 	 break;
   2340 
   2341    case dir_East:
   2342 	 do
   2343 	 {
   2344 	  which++;
   2345 	  if (which>3)
   2346 	which=0;
   2347 	 } while(!cust->allowed[which]);
   2348 	 redraw=1;
   2349 	 SD_PlaySound(MOVEGUN1SND);
   2350 	 while(ReadAnyControl(&ci),ci.dir!=dir_None);
   2351 	 IN_ClearKeysDown();
   2352 	 break;
   2353    case dir_North:
   2354    case dir_South:
   2355 	 exit=1;
   2356   }
   2357  } while(!exit);
   2358 
   2359  SD_PlaySound(ESCPRESSEDSND);
   2360  WaitKeyUp();
   2361  DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
   2362 }
   2363 
   2364 
   2365 ////////////////////////
   2366 //
   2367 // FIXUP GUN CURSOR OVERDRAW SHIT
   2368 //
   2369 void FixupCustom(int w)
   2370 {
   2371 	static int lastwhich=-1;
   2372 	int y=CST_Y+26+w*13;
   2373 
   2374 
   2375 	VWB_Hlin(7,32,y-1,DEACTIVE);
   2376 	VWB_Hlin(7,32,y+12,BORD2COLOR);
   2377 #ifndef SPEAR
   2378 	VWB_Hlin(7,32,y-2,BORDCOLOR);
   2379 	VWB_Hlin(7,32,y+13,BORDCOLOR);
   2380 #else
   2381 	VWB_Hlin(7,32,y-2,BORD2COLOR);
   2382 	VWB_Hlin(7,32,y+13,BORD2COLOR);
   2383 #endif
   2384 
   2385 	switch(w)
   2386 	{
   2387 		case 0: DrawCustMouse(1); break;
   2388 		case 3: DrawCustJoy(1); break;
   2389 		case 6: DrawCustKeybd(1); break;
   2390 		case 8: DrawCustKeys(1);
   2391 	}
   2392 
   2393 
   2394 	if (lastwhich>=0)
   2395 	{
   2396 		y=CST_Y+26+lastwhich*13;
   2397 		VWB_Hlin(7,32,y-1,DEACTIVE);
   2398 		VWB_Hlin(7,32,y+12,BORD2COLOR);
   2399 #ifndef SPEAR
   2400 		VWB_Hlin(7,32,y-2,BORDCOLOR);
   2401 		VWB_Hlin(7,32,y+13,BORDCOLOR);
   2402 #else
   2403 		VWB_Hlin(7,32,y-2,BORD2COLOR);
   2404 		VWB_Hlin(7,32,y+13,BORD2COLOR);
   2405 #endif
   2406 
   2407 		if (lastwhich!=w)
   2408 			switch(lastwhich)
   2409 			{
   2410 				case 0: DrawCustMouse(0); break;
   2411 				case 3: DrawCustJoy(0); break;
   2412 				case 6: DrawCustKeybd(0); break;
   2413 				case 8: DrawCustKeys(0);
   2414 			}
   2415 	}
   2416 
   2417 	lastwhich=w;
   2418 }
   2419 
   2420 
   2421 ////////////////////////
   2422 //
   2423 // DRAW CUSTOMIZE SCREEN
   2424 //
   2425 void DrawCustomScreen(void)
   2426 {
   2427 	int i;
   2428 
   2429 
   2430 #ifdef JAPAN
   2431 	CA_CacheScreen(S_CUSTOMPIC);
   2432 	fontnumber=1;
   2433 
   2434 	PrintX=CST_START;
   2435 	PrintY = CST_Y+26;
   2436 	DrawCustMouse(0);
   2437 
   2438 	PrintX=CST_START;
   2439 	US_Print("\n\n\n");
   2440 	DrawCustJoy(0);
   2441 
   2442 	PrintX=CST_START;
   2443 	US_Print("\n\n\n");
   2444 	DrawCustKeybd(0);
   2445 
   2446 	PrintX=CST_START;
   2447 	US_Print("\n\n\n");
   2448 	DrawCustKeys(0);
   2449 #else
   2450 	ClearMScreen();
   2451 	WindowX=0;
   2452 	WindowW=320;
   2453 	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
   2454 	DrawStripes(10);
   2455 	VWB_DrawPic(80,0,C_CUSTOMIZEPIC);
   2456 
   2457 	//
   2458 	// MOUSE
   2459 	//
   2460 	SETFONTCOLOR(READCOLOR,BKGDCOLOR);
   2461 	WindowX=0;
   2462 	WindowW=320;
   2463 
   2464 #ifndef SPEAR
   2465 	PrintY=CST_Y;
   2466 	US_CPrint("Mouse\n");
   2467 #else
   2468 	PrintY = CST_Y+13;
   2469 	VWB_DrawPic (128,48,C_MOUSEPIC);
   2470 #endif
   2471 
   2472 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   2473 	#ifdef SPANISH
   2474 	PrintX=CST_START-16;
   2475 	US_Print(STR_CRUN);
   2476 	PrintX=CST_START-16+CST_SPC*1;
   2477 	US_Print(STR_COPEN);
   2478 	PrintX=CST_START-16+CST_SPC*2;
   2479 	US_Print(STR_CFIRE);
   2480 	PrintX=CST_START-16+CST_SPC*3;
   2481 	US_Print(STR_CSTRAFE"\n");
   2482 	#else
   2483 	PrintX=CST_START;
   2484 	US_Print(STR_CRUN);
   2485 	PrintX=CST_START+CST_SPC*1;
   2486 	US_Print(STR_COPEN);
   2487 	PrintX=CST_START+CST_SPC*2;
   2488 	US_Print(STR_CFIRE);
   2489 	PrintX=CST_START+CST_SPC*3;
   2490 	US_Print(STR_CSTRAFE"\n");
   2491 	#endif
   2492 
   2493 	DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
   2494 	DrawCustMouse(0);
   2495 	US_Print("\n");
   2496 
   2497 
   2498 	//
   2499 	// JOYSTICK/PAD
   2500 	//
   2501 #ifndef SPEAR
   2502 	SETFONTCOLOR(READCOLOR,BKGDCOLOR);
   2503 	US_CPrint("Joystick/Gravis GamePad\n");
   2504 #else
   2505 	PrintY += 13;
   2506 	VWB_DrawPic (40,88,C_JOYSTICKPIC);
   2507 #endif
   2508 
   2509 #ifdef SPEAR
   2510 	VWB_DrawPic (112,120,C_KEYBOARDPIC);
   2511 #endif
   2512 
   2513 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   2514 	#ifdef SPANISH
   2515 	PrintX=CST_START-16;
   2516 	US_Print(STR_CRUN);
   2517 	PrintX=CST_START-16+CST_SPC*1;
   2518 	US_Print(STR_COPEN);
   2519 	PrintX=CST_START-16+CST_SPC*2;
   2520 	US_Print(STR_CFIRE);
   2521 	PrintX=CST_START-16+CST_SPC*3;
   2522 	US_Print(STR_CSTRAFE"\n");
   2523 	#else
   2524 	PrintX=CST_START;
   2525 	US_Print(STR_CRUN);
   2526 	PrintX=CST_START+CST_SPC*1;
   2527 	US_Print(STR_COPEN);
   2528 	PrintX=CST_START+CST_SPC*2;
   2529 	US_Print(STR_CFIRE);
   2530 	PrintX=CST_START+CST_SPC*3;
   2531 	US_Print(STR_CSTRAFE"\n");
   2532 	#endif
   2533 	DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
   2534 	DrawCustJoy(0);
   2535 	US_Print("\n");
   2536 
   2537 
   2538 	//
   2539 	// KEYBOARD
   2540 	//
   2541 #ifndef SPEAR
   2542 	SETFONTCOLOR(READCOLOR,BKGDCOLOR);
   2543 	US_CPrint("Keyboard\n");
   2544 #else
   2545 	PrintY += 13;
   2546 #endif
   2547 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   2548 	#ifdef SPANISH
   2549 	PrintX=CST_START-16;
   2550 	US_Print(STR_CRUN);
   2551 	PrintX=CST_START-16+CST_SPC*1;
   2552 	US_Print(STR_COPEN);
   2553 	PrintX=CST_START-16+CST_SPC*2;
   2554 	US_Print(STR_CFIRE);
   2555 	PrintX=CST_START-16+CST_SPC*3;
   2556 	US_Print(STR_CSTRAFE"\n");
   2557 	#else
   2558 	PrintX=CST_START;
   2559 	US_Print(STR_CRUN);
   2560 	PrintX=CST_START+CST_SPC*1;
   2561 	US_Print(STR_COPEN);
   2562 	PrintX=CST_START+CST_SPC*2;
   2563 	US_Print(STR_CFIRE);
   2564 	PrintX=CST_START+CST_SPC*3;
   2565 	US_Print(STR_CSTRAFE"\n");
   2566 	#endif
   2567 	DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
   2568 	DrawCustKeybd(0);
   2569 	US_Print("\n");
   2570 
   2571 
   2572 	//
   2573 	// KEYBOARD MOVE KEYS
   2574 	//
   2575 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   2576 	#ifdef SPANISH
   2577 	PrintX=4;
   2578 	US_Print(STR_LEFT);
   2579 	US_Print("/");
   2580 	US_Print(STR_RIGHT);
   2581 	US_Print("/");
   2582 	US_Print(STR_FRWD);
   2583 	US_Print("/");
   2584 	US_Print(STR_BKWD"\n");
   2585 	#else
   2586 	PrintX=CST_START;
   2587 	US_Print(STR_LEFT);
   2588 	PrintX=CST_START+CST_SPC*1;
   2589 	US_Print(STR_RIGHT);
   2590 	PrintX=CST_START+CST_SPC*2;
   2591 	US_Print(STR_FRWD);
   2592 	PrintX=CST_START+CST_SPC*3;
   2593 	US_Print(STR_BKWD"\n");
   2594 	#endif
   2595 	DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
   2596 	DrawCustKeys(0);
   2597 #endif
   2598 	//
   2599 	// PICK STARTING POINT IN MENU
   2600 	//
   2601 	if (CusItems.curpos<0)
   2602 		for (i=0;i<CusItems.amount;i++)
   2603 			if (CusMenu[i].active)
   2604 			{
   2605 				CusItems.curpos=i;
   2606 				break;
   2607 			}
   2608 
   2609 
   2610 	VW_UpdateScreen();
   2611 	MenuFadeIn();
   2612 }
   2613 
   2614 
   2615 void PrintCustMouse(int i)
   2616 {
   2617 	int j;
   2618 
   2619 	for (j=0;j<4;j++)
   2620 		if (order[i]==buttonmouse[j])
   2621 		{
   2622 			PrintX=CST_START+CST_SPC*i;
   2623 			US_Print(mbarray[j]);
   2624 			break;
   2625 		}
   2626 }
   2627 
   2628 void DrawCustMouse(int hilight)
   2629 {
   2630 	int i,color;
   2631 
   2632 
   2633 	color=TEXTCOLOR;
   2634 	if (hilight)
   2635 		color=HIGHLIGHT;
   2636 	SETFONTCOLOR(color,BKGDCOLOR);
   2637 
   2638 	if (!mouseenabled)
   2639 	{
   2640 		SETFONTCOLOR(DEACTIVE,BKGDCOLOR);
   2641 		CusMenu[0].active=0;
   2642 	}
   2643 	else
   2644 		CusMenu[0].active=1;
   2645 
   2646 	PrintY=CST_Y+13*2;
   2647 	for (i=0;i<4;i++)
   2648 		PrintCustMouse(i);
   2649 }
   2650 
   2651 void PrintCustJoy(int i)
   2652 {
   2653 	int j;
   2654 
   2655 	for (j=0;j<4;j++)
   2656 		if (order[i]==buttonjoy[j])
   2657 		{
   2658 			PrintX=CST_START+CST_SPC*i;
   2659 			US_Print(mbarray[j]);
   2660 			break;
   2661 		}
   2662 }
   2663 
   2664 void DrawCustJoy(int hilight)
   2665 {
   2666 	int i,color;
   2667 
   2668 
   2669 	color=TEXTCOLOR;
   2670 	if (hilight)
   2671 		color=HIGHLIGHT;
   2672 	SETFONTCOLOR(color,BKGDCOLOR);
   2673 
   2674 	if (!joystickenabled)
   2675 	{
   2676 		SETFONTCOLOR(DEACTIVE,BKGDCOLOR);
   2677 		CusMenu[3].active=0;
   2678 	}
   2679 	else
   2680 		CusMenu[3].active=1;
   2681 
   2682 	PrintY=CST_Y+13*5;
   2683 	for (i=0;i<4;i++)
   2684 		PrintCustJoy(i);
   2685 }
   2686 
   2687 
   2688 void PrintCustKeybd(int i)
   2689 {
   2690 	PrintX=CST_START+CST_SPC*i;
   2691 	US_Print(IN_GetScanName(buttonscan[order[i]]));
   2692 }
   2693 
   2694 void DrawCustKeybd(int hilight)
   2695 {
   2696 	int i,color;
   2697 
   2698 
   2699 	color=TEXTCOLOR;
   2700 	if (hilight)
   2701 		color=HIGHLIGHT;
   2702 	SETFONTCOLOR(color,BKGDCOLOR);
   2703 
   2704 	PrintY=CST_Y+13*8;
   2705 	for (i=0;i<4;i++)
   2706 		PrintCustKeybd(i);
   2707 }
   2708 
   2709 void PrintCustKeys(int i)
   2710 {
   2711 	PrintX=CST_START+CST_SPC*i;
   2712 	US_Print(IN_GetScanName(dirscan[moveorder[i]]));
   2713 }
   2714 
   2715 void DrawCustKeys(int hilight)
   2716 {
   2717 	int i,color;
   2718 
   2719 
   2720 	color=TEXTCOLOR;
   2721 	if (hilight)
   2722 		color=HIGHLIGHT;
   2723 	SETFONTCOLOR(color,BKGDCOLOR);
   2724 
   2725 	PrintY=CST_Y+13*10;
   2726 	for (i=0;i<4;i++)
   2727 		PrintCustKeys(i);
   2728 }
   2729 
   2730 
   2731 ////////////////////////////////////////////////////////////////////
   2732 //
   2733 // CHANGE SCREEN VIEWING SIZE
   2734 //
   2735 ////////////////////////////////////////////////////////////////////
   2736 void CP_ChangeView(void)
   2737 {
   2738 	int exit=0,oldview,newview;
   2739 	ControlInfo ci;
   2740 
   2741 
   2742 	WindowX=WindowY=0;
   2743 	WindowW=320;
   2744 	WindowH=200;
   2745 	newview=oldview=viewwidth/16;
   2746 	DrawChangeView(oldview);
   2747 
   2748 	do
   2749 	{
   2750 		CheckPause();
   2751 		ReadAnyControl(&ci);
   2752 		switch(ci.dir)
   2753 		{
   2754 		case dir_South:
   2755 		case dir_West:
   2756 			newview--;
   2757 			if (newview<4)
   2758 				newview=4;
   2759 			ShowViewSize(newview);
   2760 			VW_UpdateScreen();
   2761 			SD_PlaySound(HITWALLSND);
   2762 			TicDelay(10);
   2763 			break;
   2764 
   2765 		case dir_North:
   2766 		case dir_East:
   2767 			newview++;
   2768 			if (newview>19)
   2769 				newview=19;
   2770 			ShowViewSize(newview);
   2771 			VW_UpdateScreen();
   2772 			SD_PlaySound(HITWALLSND);
   2773 			TicDelay(10);
   2774 			break;
   2775 		}
   2776 
   2777 		#ifndef SPEAR
   2778 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   2779 		#else
   2780 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("debugmode"))
   2781 		#endif
   2782 			PicturePause();
   2783 
   2784 		if (ci.button0 || Keyboard[sc_Enter])
   2785 			exit=1;
   2786 		else
   2787 		if (ci.button1 || Keyboard[sc_Escape])
   2788 		{
   2789 			viewwidth=oldview*16;
   2790 			SD_PlaySound(ESCPRESSEDSND);
   2791 			MenuFadeOut();
   2792 			return;
   2793 		}
   2794 
   2795 	} while(!exit);
   2796 
   2797 
   2798 	if (oldview!=newview)
   2799 	{
   2800 		SD_PlaySound (SHOOTSND);
   2801 		Message(STR_THINK"...");
   2802 		NewViewSize(newview);
   2803 	}
   2804 
   2805 	ShootSnd();
   2806 	MenuFadeOut();
   2807 }
   2808 
   2809 
   2810 /////////////////////////////
   2811 //
   2812 // DRAW THE CHANGEVIEW SCREEN
   2813 //
   2814 void DrawChangeView(int view)
   2815 {
   2816 #ifdef JAPAN
   2817 	CA_CacheScreen(S_CHANGEPIC);
   2818 
   2819 	ShowViewSize(view);
   2820 #else
   2821 	VWB_Bar(0,160,320,40,VIEWCOLOR);
   2822 	ShowViewSize(view);
   2823 
   2824 	PrintY=161;
   2825 	WindowX=0;
   2826 	WindowY=320;
   2827 	SETFONTCOLOR(HIGHLIGHT,BKGDCOLOR);
   2828 
   2829 	US_CPrint(STR_SIZE1"\n");
   2830 	US_CPrint(STR_SIZE2"\n");
   2831 	US_CPrint(STR_SIZE3);
   2832 #endif
   2833 	VW_UpdateScreen();
   2834 
   2835 	MenuFadeIn();
   2836 }
   2837 
   2838 
   2839 ////////////////////////////////////////////////////////////////////
   2840 //
   2841 // QUIT THIS INFERNAL GAME!
   2842 //
   2843 ////////////////////////////////////////////////////////////////////
   2844 void CP_Quit(void)
   2845 {
   2846 	int i;
   2847 
   2848 
   2849 	#ifdef JAPAN
   2850 	if (GetYorN(7,11,C_QUITMSGPIC))
   2851 	#else
   2852 
   2853 	#ifdef SPANISH
   2854 	if (Confirm(ENDGAMESTR))
   2855 	#else
   2856 	if (Confirm(endStrings[US_RndT()&0x7+(US_RndT()&1)]))
   2857 	#endif
   2858 
   2859 	#endif
   2860 	{
   2861 		VW_UpdateScreen();
   2862 		SD_MusicOff();
   2863 		SD_StopSound();
   2864 		MenuFadeOut();
   2865 		//
   2866 		// SHUT-UP THE ADLIB
   2867 		//
   2868 		for (i=1;i<=0xf5;i++)
   2869 			alOut(i,0);
   2870 		Quit(NULL);
   2871 	}
   2872 
   2873 	DrawMainMenu();
   2874 }
   2875 
   2876 
   2877 ////////////////////////////////////////////////////////////////////
   2878 //
   2879 // HANDLE INTRO SCREEN (SYSTEM CONFIG)
   2880 //
   2881 ////////////////////////////////////////////////////////////////////
   2882 void IntroScreen(void)
   2883 {
   2884 #ifdef SPEAR
   2885 
   2886 #define MAINCOLOR	0x4f
   2887 #define EMSCOLOR	0x4f
   2888 #define XMSCOLOR	0x4f
   2889 
   2890 #else
   2891 
   2892 #define MAINCOLOR	0x6c
   2893 #define EMSCOLOR	0x6c
   2894 #define XMSCOLOR	0x6c
   2895 
   2896 #endif
   2897 #define FILLCOLOR	14
   2898 
   2899 	long memory,emshere,xmshere;
   2900 	int i,num,ems[10]={100,200,300,400,500,600,700,800,900,1000},
   2901 		xms[10]={100,200,300,400,500,600,700,800,900,1000},
   2902 		main[10]={32,64,96,128,160,192,224,256,288,320};
   2903 
   2904 
   2905 	//
   2906 	// DRAW MAIN MEMORY
   2907 	//
   2908 	memory=(1023l+mminfo.nearheap+mminfo.farheap)/1024l;
   2909 	for (i=0;i<10;i++)
   2910 		if (memory>=main[i])
   2911 			VWB_Bar(49,163-8*i,6,5,MAINCOLOR-i);
   2912 
   2913 
   2914 	//
   2915 	// DRAW EMS MEMORY
   2916 	//
   2917 	if (EMSPresent)
   2918 	{
   2919 		emshere=4l*EMSPagesAvail;
   2920 		for (i=0;i<10;i++)
   2921 			if (emshere>=ems[i])
   2922 				VWB_Bar(89,163-8*i,6,5,EMSCOLOR-i);
   2923 	}
   2924 
   2925 	//
   2926 	// DRAW XMS MEMORY
   2927 	//
   2928 	if (XMSPresent)
   2929 	{
   2930 		xmshere=4l*XMSPagesAvail;
   2931 		for (i=0;i<10;i++)
   2932 			if (xmshere>=xms[i])
   2933 				VWB_Bar(129,163-8*i,6,5,XMSCOLOR-i);
   2934 	}
   2935 
   2936 	//
   2937 	// FILL BOXES
   2938 	//
   2939 	if (MousePresent)
   2940 		VWB_Bar(164,82,12,2,FILLCOLOR);
   2941 
   2942 	if (JoysPresent[0] || JoysPresent[1])
   2943 		VWB_Bar(164,105,12,2,FILLCOLOR);
   2944 
   2945 	if (AdLibPresent && !SoundBlasterPresent)
   2946 		VWB_Bar(164,128,12,2,FILLCOLOR);
   2947 
   2948 	if (SoundBlasterPresent)
   2949 		VWB_Bar(164,151,12,2,FILLCOLOR);
   2950 
   2951 	if (SoundSourcePresent)
   2952 		VWB_Bar(164,174,12,2,FILLCOLOR);
   2953 }
   2954 
   2955 
   2956 ////////////////////////////////////////////////////////////////////
   2957 ////////////////////////////////////////////////////////////////////
   2958 //
   2959 // SUPPORT ROUTINES
   2960 //
   2961 ////////////////////////////////////////////////////////////////////
   2962 ////////////////////////////////////////////////////////////////////
   2963 
   2964 ////////////////////////////////////////////////////////////////////
   2965 //
   2966 // Clear Menu screens to dark red
   2967 //
   2968 ////////////////////////////////////////////////////////////////////
   2969 void ClearMScreen(void)
   2970 {
   2971 #ifndef SPEAR
   2972 	VWB_Bar(0,0,320,200,BORDCOLOR);
   2973 #else
   2974 	VWB_DrawPic(0,0,C_BACKDROPPIC);
   2975 #endif
   2976 }
   2977 
   2978 
   2979 ////////////////////////////////////////////////////////////////////
   2980 //
   2981 // Un/Cache a LUMP of graphics
   2982 //
   2983 ////////////////////////////////////////////////////////////////////
   2984 void CacheLump(int lumpstart,int lumpend)
   2985 {
   2986  int i;
   2987 
   2988  for (i=lumpstart;i<=lumpend;i++)
   2989    CA_CacheGrChunk(i);
   2990 }
   2991 
   2992 
   2993 void UnCacheLump(int lumpstart,int lumpend)
   2994 {
   2995  int i;
   2996 
   2997  for (i=lumpstart;i<=lumpend;i++)
   2998 	if (grsegs[i])
   2999 		UNCACHEGRCHUNK(i);
   3000 }
   3001 
   3002 
   3003 ////////////////////////////////////////////////////////////////////
   3004 //
   3005 // Draw a window for a menu
   3006 //
   3007 ////////////////////////////////////////////////////////////////////
   3008 void DrawWindow(int x,int y,int w,int h,int wcolor)
   3009 {
   3010 	VWB_Bar(x,y,w,h,wcolor);
   3011 	DrawOutline(x,y,w,h,BORD2COLOR,DEACTIVE);
   3012 }
   3013 
   3014 
   3015 void DrawOutline(int x,int y,int w,int h,int color1,int color2)
   3016 {
   3017 	VWB_Hlin(x,x+w,y,color2);
   3018 	VWB_Vlin(y,y+h,x,color2);
   3019 	VWB_Hlin(x,x+w,y+h,color1);
   3020 	VWB_Vlin(y,y+h,x+w,color1);
   3021 }
   3022 
   3023 
   3024 ////////////////////////////////////////////////////////////////////
   3025 //
   3026 // Setup Control Panel stuff - graphics, etc.
   3027 //
   3028 ////////////////////////////////////////////////////////////////////
   3029 void SetupControlPanel(void)
   3030 {
   3031 	struct ffblk f;
   3032 	char name[13];
   3033 	int which,i;
   3034 
   3035 
   3036 	//
   3037 	// CACHE GRAPHICS & SOUNDS
   3038 	//
   3039 	CA_CacheGrChunk(STARTFONT+1);
   3040 #ifndef SPEAR
   3041 	CacheLump(CONTROLS_LUMP_START,CONTROLS_LUMP_END);
   3042 #else
   3043 	CacheLump(BACKDROP_LUMP_START,BACKDROP_LUMP_END);
   3044 #endif
   3045 
   3046 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   3047 	fontnumber=1;
   3048 	WindowH=200;
   3049 
   3050 	if (!ingame)
   3051 		CA_LoadAllSounds();
   3052 	else
   3053 		MainMenu[savegame].active=1;
   3054 
   3055 	//
   3056 	// SEE WHICH SAVE GAME FILES ARE AVAILABLE & READ STRING IN
   3057 	//
   3058 	strcpy(name,SaveName);
   3059 	if (!findfirst(name,&f,0))
   3060 		do
   3061 		{
   3062 			which=f.ff_name[7]-'0';
   3063 			if (which<10)
   3064 			{
   3065 				int handle;
   3066 				char temp[32];
   3067 
   3068 				SaveGamesAvail[which]=1;
   3069 				handle=open(f.ff_name,O_BINARY);
   3070 				read(handle,temp,32);
   3071 				close(handle);
   3072 				strcpy(&SaveGameNames[which][0],temp);
   3073 			}
   3074 		} while(!findnext(&f));
   3075 
   3076 	//
   3077 	// CENTER MOUSE
   3078 	//
   3079 	_CX=_DX=CENTER;
   3080 	Mouse(4);
   3081 }
   3082 
   3083 
   3084 ////////////////////////////////////////////////////////////////////
   3085 //
   3086 // Clean up all the Control Panel stuff
   3087 //
   3088 ////////////////////////////////////////////////////////////////////
   3089 void CleanupControlPanel(void)
   3090 {
   3091 #ifndef SPEAR
   3092 	UnCacheLump(CONTROLS_LUMP_START,CONTROLS_LUMP_END);
   3093 #else
   3094 	UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
   3095 #endif
   3096 
   3097 	fontnumber = 0;
   3098 }
   3099 
   3100 
   3101 ////////////////////////////////////////////////////////////////////
   3102 //
   3103 // Handle moving gun around a menu
   3104 //
   3105 ////////////////////////////////////////////////////////////////////
   3106 int HandleMenu(CP_iteminfo *item_i,CP_itemtype far *items,void (*routine)(int w))
   3107 {
   3108 	char key;
   3109 	static int redrawitem=1,lastitem=-1;
   3110 	int i,x,y,basey,exit,which,shape,timer;
   3111 	ControlInfo ci;
   3112 
   3113 
   3114 	which=item_i->curpos;
   3115 	x=item_i->x&-8;
   3116 	basey=item_i->y-2;
   3117 	y=basey+which*13;
   3118 
   3119 	VWB_DrawPic(x,y,C_CURSOR1PIC);
   3120 	SetTextColor(items+which,1);
   3121 	if (redrawitem)
   3122 	{
   3123 		PrintX=item_i->x+item_i->indent;
   3124 		PrintY=item_i->y+which*13;
   3125 		US_Print((items+which)->string);
   3126 	}
   3127 	//
   3128 	// CALL CUSTOM ROUTINE IF IT IS NEEDED
   3129 	//
   3130 	if (routine)
   3131 		routine(which);
   3132 	VW_UpdateScreen();
   3133 
   3134 	shape=C_CURSOR1PIC;
   3135 	timer=8;
   3136 	exit=0;
   3137 	TimeCount=0;
   3138 	IN_ClearKeysDown();
   3139 
   3140 
   3141 	do
   3142 	{
   3143 		//
   3144 		// CHANGE GUN SHAPE
   3145 		//
   3146 		if (TimeCount>timer)
   3147 		{
   3148 			TimeCount=0;
   3149 			if (shape==C_CURSOR1PIC)
   3150 			{
   3151 				shape=C_CURSOR2PIC;
   3152 				timer=8;
   3153 			}
   3154 			else
   3155 			{
   3156 				shape=C_CURSOR1PIC;
   3157 				timer=70;
   3158 			}
   3159 			VWB_DrawPic(x,y,shape);
   3160 			if (routine)
   3161 				routine(which);
   3162 			VW_UpdateScreen();
   3163 		}
   3164 
   3165 		CheckPause();
   3166 
   3167 		//
   3168 		// SEE IF ANY KEYS ARE PRESSED FOR INITIAL CHAR FINDING
   3169 		//
   3170 		key=LastASCII;
   3171 		if (key)
   3172 		{
   3173 			int ok=0;
   3174 
   3175 			//
   3176 			// CHECK FOR SCREEN CAPTURE
   3177 			//
   3178 			#ifndef SPEAR
   3179 			if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   3180 			#else
   3181 			if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("debugmode"))
   3182 			#endif
   3183 				PicturePause();
   3184 
   3185 
   3186 			if (key>='a')
   3187 				key-='a'-'A';
   3188 
   3189 			for (i=which+1;i<item_i->amount;i++)
   3190 				if ((items+i)->active && (items+i)->string[0]==key)
   3191 				{
   3192 					EraseGun(item_i,items,x,y,which);
   3193 					which=i;
   3194 					DrawGun(item_i,items,x,&y,which,basey,routine);
   3195 					ok=1;
   3196 					IN_ClearKeysDown();
   3197 					break;
   3198 				}
   3199 
   3200 			//
   3201 			// DIDN'T FIND A MATCH FIRST TIME THRU. CHECK AGAIN.
   3202 			//
   3203 			if (!ok)
   3204 			{
   3205 				for (i=0;i<which;i++)
   3206 					if ((items+i)->active && (items+i)->string[0]==key)
   3207 					{
   3208 						EraseGun(item_i,items,x,y,which);
   3209 						which=i;
   3210 						DrawGun(item_i,items,x,&y,which,basey,routine);
   3211 						IN_ClearKeysDown();
   3212 						break;
   3213 					}
   3214 			}
   3215 		}
   3216 
   3217 		//
   3218 		// GET INPUT
   3219 		//
   3220 		ReadAnyControl(&ci);
   3221 		switch(ci.dir)
   3222 		{
   3223 			////////////////////////////////////////////////
   3224 			//
   3225 			// MOVE UP
   3226 			//
   3227 			case dir_North:
   3228 
   3229 			EraseGun(item_i,items,x,y,which);
   3230 
   3231 			//
   3232 			// ANIMATE HALF-STEP
   3233 			//
   3234 			if (which && (items+which-1)->active)
   3235 			{
   3236 				y-=6;
   3237 				DrawHalfStep(x,y);
   3238 			}
   3239 
   3240 			//
   3241 			// MOVE TO NEXT AVAILABLE SPOT
   3242 			//
   3243 			do
   3244 			{
   3245 				if (!which)
   3246 					which=item_i->amount-1;
   3247 				else
   3248 					which--;
   3249 			} while(!(items+which)->active);
   3250 
   3251 			DrawGun(item_i,items,x,&y,which,basey,routine);
   3252 			//
   3253 			// WAIT FOR BUTTON-UP OR DELAY NEXT MOVE
   3254 			//
   3255 			TicDelay(20);
   3256 			break;
   3257 
   3258 			////////////////////////////////////////////////
   3259 			//
   3260 			// MOVE DOWN
   3261 			//
   3262 			case dir_South:
   3263 
   3264 			EraseGun(item_i,items,x,y,which);
   3265 			//
   3266 			// ANIMATE HALF-STEP
   3267 			//
   3268 			if (which!=item_i->amount-1 && (items+which+1)->active)
   3269 			{
   3270 				y+=6;
   3271 				DrawHalfStep(x,y);
   3272 			}
   3273 
   3274 			do
   3275 			{
   3276 				if (which==item_i->amount-1)
   3277 					which=0;
   3278 				else
   3279 					which++;
   3280 			} while(!(items+which)->active);
   3281 
   3282 			DrawGun(item_i,items,x,&y,which,basey,routine);
   3283 
   3284 			//
   3285 			// WAIT FOR BUTTON-UP OR DELAY NEXT MOVE
   3286 			//
   3287 			TicDelay(20);
   3288 			break;
   3289 		}
   3290 
   3291 		if (ci.button0 ||
   3292 			Keyboard[sc_Space] ||
   3293 			Keyboard[sc_Enter])
   3294 				exit=1;
   3295 
   3296 		if (ci.button1 ||
   3297 			Keyboard[sc_Escape])
   3298 				exit=2;
   3299 
   3300 	} while(!exit);
   3301 
   3302 
   3303 	IN_ClearKeysDown();
   3304 
   3305 	//
   3306 	// ERASE EVERYTHING
   3307 	//
   3308 	if (lastitem!=which)
   3309 	{
   3310 		VWB_Bar(x-1,y,25,16,BKGDCOLOR);
   3311 		PrintX=item_i->x+item_i->indent;
   3312 		PrintY=item_i->y+which*13;
   3313 		US_Print((items+which)->string);
   3314 		redrawitem=1;
   3315 	}
   3316 	else
   3317 		redrawitem=0;
   3318 
   3319 	if (routine)
   3320 		routine(which);
   3321 	VW_UpdateScreen();
   3322 
   3323 	item_i->curpos=which;
   3324 
   3325 	lastitem=which;
   3326 	switch(exit)
   3327 	{
   3328 		case 1:
   3329 			//
   3330 			// CALL THE ROUTINE
   3331 			//
   3332 			if ((items+which)->routine!=NULL)
   3333 			{
   3334 				ShootSnd();
   3335 				MenuFadeOut();
   3336 				(items+which)->routine(0);
   3337 			}
   3338 			return which;
   3339 
   3340 		case 2:
   3341 			SD_PlaySound(ESCPRESSEDSND);
   3342 			return -1;
   3343 	}
   3344 
   3345 	return 0; // JUST TO SHUT UP THE ERROR MESSAGES!
   3346 }
   3347 
   3348 
   3349 //
   3350 // ERASE GUN & DE-HIGHLIGHT STRING
   3351 //
   3352 void EraseGun(CP_iteminfo *item_i,CP_itemtype far *items,int x,int y,int which)
   3353 {
   3354 	VWB_Bar(x-1,y,25,16,BKGDCOLOR);
   3355 	SetTextColor(items+which,0);
   3356 
   3357 	PrintX=item_i->x+item_i->indent;
   3358 	PrintY=item_i->y+which*13;
   3359 	US_Print((items+which)->string);
   3360 	VW_UpdateScreen();
   3361 }
   3362 
   3363 
   3364 //
   3365 // DRAW HALF STEP OF GUN TO NEXT POSITION
   3366 //
   3367 void DrawHalfStep(int x,int y)
   3368 {
   3369 	VWB_DrawPic(x,y,C_CURSOR1PIC);
   3370 	VW_UpdateScreen();
   3371 	SD_PlaySound(MOVEGUN1SND);
   3372 	TimeCount=0;
   3373 	while(TimeCount<8);
   3374 }
   3375 
   3376 
   3377 //
   3378 // DRAW GUN AT NEW POSITION
   3379 //
   3380 void DrawGun(CP_iteminfo *item_i,CP_itemtype far *items,int x,int *y,int which,int basey,void (*routine)(int w))
   3381 {
   3382 	VWB_Bar(x-1,*y,25,16,BKGDCOLOR);
   3383 	*y=basey+which*13;
   3384 	VWB_DrawPic(x,*y,C_CURSOR1PIC);
   3385 	SetTextColor(items+which,1);
   3386 
   3387 	PrintX=item_i->x+item_i->indent;
   3388 	PrintY=item_i->y+which*13;
   3389 	US_Print((items+which)->string);
   3390 
   3391 	//
   3392 	// CALL CUSTOM ROUTINE IF IT IS NEEDED
   3393 	//
   3394 	if (routine)
   3395 		routine(which);
   3396 	VW_UpdateScreen();
   3397 	SD_PlaySound(MOVEGUN2SND);
   3398 }
   3399 
   3400 ////////////////////////////////////////////////////////////////////
   3401 //
   3402 // DELAY FOR AN AMOUNT OF TICS OR UNTIL CONTROLS ARE INACTIVE
   3403 //
   3404 ////////////////////////////////////////////////////////////////////
   3405 void TicDelay(int count)
   3406 {
   3407 	ControlInfo ci;
   3408 
   3409 
   3410 	TimeCount=0;
   3411 	do
   3412 	{
   3413 		ReadAnyControl(&ci);
   3414 	} while(TimeCount<count && ci.dir!=dir_None);
   3415 }
   3416 
   3417 
   3418 ////////////////////////////////////////////////////////////////////
   3419 //
   3420 // Draw a menu
   3421 //
   3422 ////////////////////////////////////////////////////////////////////
   3423 void DrawMenu(CP_iteminfo *item_i,CP_itemtype far *items)
   3424 {
   3425 	int i,which=item_i->curpos;
   3426 
   3427 
   3428 	WindowX=PrintX=item_i->x+item_i->indent;
   3429 	WindowY=PrintY=item_i->y;
   3430 	WindowW=320;
   3431 	WindowH=200;
   3432 
   3433 	for (i=0;i<item_i->amount;i++)
   3434 	{
   3435 		SetTextColor(items+i,which==i);
   3436 
   3437 		PrintY=item_i->y+i*13;
   3438 		if ((items+i)->active)
   3439 			US_Print((items+i)->string);
   3440 		else
   3441 		{
   3442 			SETFONTCOLOR(DEACTIVE,BKGDCOLOR);
   3443 			US_Print((items+i)->string);
   3444 			SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
   3445 		}
   3446 
   3447 		US_Print("\n");
   3448 	}
   3449 }
   3450 
   3451 
   3452 ////////////////////////////////////////////////////////////////////
   3453 //
   3454 // SET TEXT COLOR (HIGHLIGHT OR NO)
   3455 //
   3456 ////////////////////////////////////////////////////////////////////
   3457 void SetTextColor(CP_itemtype far *items,int hlight)
   3458 {
   3459 	if (hlight)
   3460 		{SETFONTCOLOR(color_hlite[items->active],BKGDCOLOR);}
   3461 	else
   3462 		{SETFONTCOLOR(color_norml[items->active],BKGDCOLOR);}
   3463 }
   3464 
   3465 
   3466 ////////////////////////////////////////////////////////////////////
   3467 //
   3468 // WAIT FOR CTRLKEY-UP OR BUTTON-UP
   3469 //
   3470 ////////////////////////////////////////////////////////////////////
   3471 void WaitKeyUp(void)
   3472 {
   3473 	ControlInfo ci;
   3474 	while(ReadAnyControl(&ci),	ci.button0|
   3475 								ci.button1|
   3476 								ci.button2|
   3477 								ci.button3|
   3478 								Keyboard[sc_Space]|
   3479 								Keyboard[sc_Enter]|
   3480 								Keyboard[sc_Escape]);
   3481 }
   3482 
   3483 
   3484 ////////////////////////////////////////////////////////////////////
   3485 //
   3486 // READ KEYBOARD, JOYSTICK AND MOUSE FOR INPUT
   3487 //
   3488 ////////////////////////////////////////////////////////////////////
   3489 void ReadAnyControl(ControlInfo *ci)
   3490 {
   3491 	int mouseactive=0;
   3492 
   3493 
   3494 	IN_ReadControl(0,ci);
   3495 
   3496 	if (mouseenabled)
   3497 	{
   3498 		int mousey,mousex;
   3499 
   3500 
   3501 		// READ MOUSE MOTION COUNTERS
   3502 		// RETURN DIRECTION
   3503 		// HOME MOUSE
   3504 		// CHECK MOUSE BUTTONS
   3505 
   3506 		Mouse(3);
   3507 		mousex=_CX;
   3508 		mousey=_DX;
   3509 
   3510 		if (mousey<CENTER-SENSITIVE)
   3511 		{
   3512 			ci->dir=dir_North;
   3513 			_CX=_DX=CENTER;
   3514 			Mouse(4);
   3515 			mouseactive=1;
   3516 		}
   3517 		else
   3518 		if (mousey>CENTER+SENSITIVE)
   3519 		{
   3520 			ci->dir=dir_South;
   3521 			_CX=_DX=CENTER;
   3522 			Mouse(4);
   3523 			mouseactive=1;
   3524 		}
   3525 
   3526 		if (mousex<CENTER-SENSITIVE)
   3527 		{
   3528 			ci->dir=dir_West;
   3529 			_CX=_DX=CENTER;
   3530 			Mouse(4);
   3531 			mouseactive=1;
   3532 		}
   3533 		else
   3534 		if (mousex>CENTER+SENSITIVE)
   3535 		{
   3536 			ci->dir=dir_East;
   3537 			_CX=_DX=CENTER;
   3538 			Mouse(4);
   3539 			mouseactive=1;
   3540 		}
   3541 
   3542 		if (IN_MouseButtons())
   3543 		{
   3544 			ci->button0=IN_MouseButtons()&1;
   3545 			ci->button1=IN_MouseButtons()&2;
   3546 			ci->button2=IN_MouseButtons()&4;
   3547 			ci->button3=false;
   3548 			mouseactive=1;
   3549 		}
   3550 	}
   3551 
   3552 	if (joystickenabled && !mouseactive)
   3553 	{
   3554 		int jx,jy,jb;
   3555 
   3556 
   3557 		INL_GetJoyDelta(joystickport,&jx,&jy);
   3558 		if (jy<-SENSITIVE)
   3559 			ci->dir=dir_North;
   3560 		else
   3561 		if (jy>SENSITIVE)
   3562 			ci->dir=dir_South;
   3563 
   3564 		if (jx<-SENSITIVE)
   3565 			ci->dir=dir_West;
   3566 		else
   3567 		if (jx>SENSITIVE)
   3568 			ci->dir=dir_East;
   3569 
   3570 		jb=IN_JoyButtons();
   3571 		if (jb)
   3572 		{
   3573 			ci->button0=jb&1;
   3574 			ci->button1=jb&2;
   3575 			if (joypadenabled)
   3576 			{
   3577 				ci->button2=jb&4;
   3578 				ci->button3=jb&8;
   3579 			}
   3580 			else
   3581 				ci->button2=ci->button3=false;
   3582 		}
   3583 	}
   3584 }
   3585 
   3586 
   3587 ////////////////////////////////////////////////////////////////////
   3588 //
   3589 // DRAW DIALOG AND CONFIRM YES OR NO TO QUESTION
   3590 //
   3591 ////////////////////////////////////////////////////////////////////
   3592 int Confirm(char far *string)
   3593 {
   3594 	int xit=0,i,x,y,tick=0,time,whichsnd[2]={ESCPRESSEDSND,SHOOTSND};
   3595 
   3596 
   3597 	Message(string);
   3598 	IN_ClearKeysDown();
   3599 
   3600 	//
   3601 	// BLINK CURSOR
   3602 	//
   3603 	x=PrintX;
   3604 	y=PrintY;
   3605 	TimeCount=0;
   3606 
   3607 	do
   3608 	{
   3609 		if (TimeCount>=10)
   3610 		{
   3611 			switch(tick)
   3612 			{
   3613 				case 0:
   3614 					VWB_Bar(x,y,8,13,TEXTCOLOR);
   3615 					break;
   3616 				case 1:
   3617 					PrintX=x;
   3618 					PrintY=y;
   3619 					US_Print("_");
   3620 			}
   3621 			VW_UpdateScreen();
   3622 			tick^=1;
   3623 			TimeCount=0;
   3624 		}
   3625 
   3626 		#ifndef SPEAR
   3627 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   3628 			PicturePause();
   3629 		#endif
   3630 
   3631 	#ifdef SPANISH
   3632 	} while(!Keyboard[sc_S] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
   3633 	#else
   3634 	} while(!Keyboard[sc_Y] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
   3635 	#endif
   3636 
   3637 	#ifdef SPANISH
   3638 	if (Keyboard[sc_S])
   3639 	{
   3640 		xit=1;
   3641 		ShootSnd();
   3642 	}
   3643 
   3644 	while(Keyboard[sc_S] || Keyboard[sc_N] || Keyboard[sc_Escape]);
   3645 
   3646 	#else
   3647 
   3648 	if (Keyboard[sc_Y])
   3649 	{
   3650 		xit=1;
   3651 		ShootSnd();
   3652 	}
   3653 
   3654 	while(Keyboard[sc_Y] || Keyboard[sc_N] || Keyboard[sc_Escape]);
   3655 	#endif
   3656 
   3657 	IN_ClearKeysDown();
   3658 	SD_PlaySound(whichsnd[xit]);
   3659 	return xit;
   3660 }
   3661 
   3662 #ifdef JAPAN
   3663 ////////////////////////////////////////////////////////////////////
   3664 //
   3665 // DRAW MESSAGE & GET Y OR N
   3666 //
   3667 ////////////////////////////////////////////////////////////////////
   3668 int GetYorN(int x,int y,int pic)
   3669 {
   3670 	int xit=0,whichsnd[2]={ESCPRESSEDSND,SHOOTSND};
   3671 
   3672 
   3673 	CA_CacheGrChunk(pic);
   3674 	VWB_DrawPic(x * 8,y * 8,pic);
   3675 	UNCACHEGRCHUNK(pic);
   3676 	VW_UpdateScreen();
   3677 	IN_ClearKeysDown();
   3678 
   3679 	do
   3680 	{
   3681 		#ifndef SPEAR
   3682 		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
   3683 			PicturePause();
   3684 		#endif
   3685 
   3686 	#ifdef SPANISH
   3687 	} while(!Keyboard[sc_S] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
   3688 	#else
   3689 	} while(!Keyboard[sc_Y] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
   3690 	#endif
   3691 
   3692 	#ifdef SPANISH
   3693 	if (Keyboard[sc_S])
   3694 	{
   3695 		xit=1;
   3696 		ShootSnd();
   3697 	}
   3698 
   3699 	while(Keyboard[sc_S] || Keyboard[sc_N] || Keyboard[sc_Escape]);
   3700 
   3701 	#else
   3702 
   3703 	if (Keyboard[sc_Y])
   3704 	{
   3705 		xit=1;
   3706 		ShootSnd();
   3707 	}
   3708 
   3709 	while(Keyboard[sc_Y] || Keyboard[sc_N] || Keyboard[sc_Escape]);
   3710 	#endif
   3711 
   3712 	IN_ClearKeysDown();
   3713 	SD_PlaySound(whichsnd[xit]);
   3714 	return xit;
   3715 }
   3716 #endif
   3717 
   3718 
   3719 ////////////////////////////////////////////////////////////////////
   3720 //
   3721 // PRINT A MESSAGE IN A WINDOW
   3722 //
   3723 ////////////////////////////////////////////////////////////////////
   3724 void Message(char far *string)
   3725 {
   3726 	int h=0,w=0,mw=0,i,x,y,time;
   3727 	fontstruct _seg *font;
   3728 
   3729 
   3730 	CA_CacheGrChunk (STARTFONT+1);
   3731 	fontnumber=1;
   3732 	font=grsegs[STARTFONT+fontnumber];
   3733 	h=font->height;
   3734 	for (i=0;i<_fstrlen(string);i++)
   3735 		if (string[i]=='\n')
   3736 		{
   3737 			if (w>mw)
   3738 				mw=w;
   3739 			w=0;
   3740 			h+=font->height;
   3741 		}
   3742 		else
   3743 			w+=font->width[string[i]];
   3744 
   3745 	if (w+10>mw)
   3746 		mw=w+10;
   3747 
   3748 	PrintY=(WindowH/2)-h/2;
   3749 	PrintX=WindowX=160-mw/2;
   3750 
   3751 	DrawWindow(WindowX-5,PrintY-5,mw+10,h+10,TEXTCOLOR);
   3752 	DrawOutline(WindowX-5,PrintY-5,mw+10,h+10,0,HIGHLIGHT);
   3753 	SETFONTCOLOR(0,TEXTCOLOR);
   3754 	US_Print(string);
   3755 	VW_UpdateScreen();
   3756 }
   3757 
   3758 
   3759 ////////////////////////////////////////////////////////////////////
   3760 //
   3761 // THIS MAY BE FIXED A LITTLE LATER...
   3762 //
   3763 ////////////////////////////////////////////////////////////////////
   3764 static	int	lastmusic;
   3765 
   3766 void StartCPMusic(int song)
   3767 {
   3768 	musicnames	chunk;
   3769 
   3770 	if (audiosegs[STARTMUSIC + lastmusic])	// JDC
   3771 		MM_FreePtr ((memptr *)&audiosegs[STARTMUSIC + lastmusic]);
   3772 	lastmusic = song;
   3773 
   3774 	SD_MusicOff();
   3775 	chunk =	song;
   3776 
   3777 	MM_BombOnError (false);
   3778 	CA_CacheAudioChunk(STARTMUSIC + chunk);
   3779 	MM_BombOnError (true);
   3780 	if (mmerror)
   3781 		mmerror = false;
   3782 	else
   3783 	{
   3784 		MM_SetLock(&((memptr)audiosegs[STARTMUSIC + chunk]),true);
   3785 		SD_StartMusic((MusicGroup far *)audiosegs[STARTMUSIC + chunk]);
   3786 	}
   3787 }
   3788 
   3789 void FreeMusic (void)
   3790 {
   3791 	if (audiosegs[STARTMUSIC + lastmusic])	// JDC
   3792 		MM_FreePtr ((memptr *)&audiosegs[STARTMUSIC + lastmusic]);
   3793 }
   3794 
   3795 
   3796 ///////////////////////////////////////////////////////////////////////////
   3797 //
   3798 //	IN_GetScanName() - Returns a string containing the name of the
   3799 //		specified scan code
   3800 //
   3801 ///////////////////////////////////////////////////////////////////////////
   3802 byte *
   3803 IN_GetScanName(ScanCode scan)
   3804 {
   3805 	byte		**p;
   3806 	ScanCode	far *s;
   3807 
   3808 	for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
   3809 		if (*s == scan)
   3810 			return(*p);
   3811 
   3812 	return(ScanNames[scan]);
   3813 }
   3814 
   3815 
   3816 ///////////////////////////////////////////////////////////////////////////
   3817 //
   3818 // CHECK FOR PAUSE KEY (FOR MUSIC ONLY)
   3819 //
   3820 ///////////////////////////////////////////////////////////////////////////
   3821 void CheckPause(void)
   3822 {
   3823 	if (Paused)
   3824 	{
   3825 		switch(SoundStatus)
   3826 		{
   3827 			case 0: SD_MusicOn(); break;
   3828 			case 1: SD_MusicOff(); break;
   3829 		}
   3830 
   3831 		SoundStatus^=1;
   3832 		VW_WaitVBL(3);
   3833 		IN_ClearKeysDown();
   3834 		Paused=false;
   3835  }
   3836 }
   3837 
   3838 
   3839 ///////////////////////////////////////////////////////////////////////////
   3840 //
   3841 // DRAW GUN CURSOR AT CORRECT POSITION IN MENU
   3842 //
   3843 ///////////////////////////////////////////////////////////////////////////
   3844 void DrawMenuGun(CP_iteminfo *iteminfo)
   3845 {
   3846 	int x,y;
   3847 
   3848 
   3849 	x=iteminfo->x;
   3850 	y=iteminfo->y+iteminfo->curpos*13-2;
   3851 	VWB_DrawPic(x,y,C_CURSOR1PIC);
   3852 }
   3853 
   3854 
   3855 ///////////////////////////////////////////////////////////////////////////
   3856 //
   3857 // DRAW SCREEN TITLE STRIPES
   3858 //
   3859 ///////////////////////////////////////////////////////////////////////////
   3860 void DrawStripes(int y)
   3861 {
   3862 #ifndef SPEAR
   3863 	VWB_Bar(0,y,320,24,0);
   3864 	VWB_Hlin(0,319,y+22,STRIPE);
   3865 #else
   3866 	VWB_Bar(0,y,320,22,0);
   3867 	VWB_Hlin(0,319,y+23,0);
   3868 #endif
   3869 }
   3870 
   3871 void ShootSnd(void)
   3872 {
   3873 	SD_PlaySound(SHOOTSND);
   3874 }
   3875 
   3876 
   3877 ///////////////////////////////////////////////////////////////////////////
   3878 //
   3879 // CHECK FOR EPISODES
   3880 //
   3881 ///////////////////////////////////////////////////////////////////////////
   3882 void CheckForEpisodes(void)
   3883 {
   3884 	struct ffblk f;
   3885 
   3886 //
   3887 // JAPANESE VERSION
   3888 //
   3889 #ifdef JAPAN
   3890 #ifdef JAPDEMO
   3891 	if (!findfirst("*.WJ1",&f,FA_ARCH))
   3892 	{
   3893 		strcpy(extension,"WJ1");
   3894 #else
   3895 	if (!findfirst("*.WJ6",&f,FA_ARCH))
   3896 	{
   3897 		strcpy(extension,"WJ6");
   3898 #endif
   3899 		strcat(configname,extension);
   3900 		strcat(SaveName,extension);
   3901 		strcat(PageFileName,extension);
   3902 		strcat(audioname,extension);
   3903 		strcat(demoname,extension);
   3904 		EpisodeSelect[1] =
   3905 		EpisodeSelect[2] =
   3906 		EpisodeSelect[3] =
   3907 		EpisodeSelect[4] =
   3908 		EpisodeSelect[5] = 1;
   3909 	}
   3910 	else
   3911 		Quit("NO JAPANESE WOLFENSTEIN 3-D DATA FILES to be found!");
   3912 #else
   3913 
   3914 //
   3915 // ENGLISH
   3916 //
   3917 #ifndef UPLOAD
   3918 #ifndef SPEAR
   3919 	if (!findfirst("*.WL6",&f,FA_ARCH))
   3920 	{
   3921 		strcpy(extension,"WL6");
   3922 		NewEmenu[2].active =
   3923 		NewEmenu[4].active =
   3924 		NewEmenu[6].active =
   3925 		NewEmenu[8].active =
   3926 		NewEmenu[10].active =
   3927 		EpisodeSelect[1] =
   3928 		EpisodeSelect[2] =
   3929 		EpisodeSelect[3] =
   3930 		EpisodeSelect[4] =
   3931 		EpisodeSelect[5] = 1;
   3932 	}
   3933 	else
   3934 	if (!findfirst("*.WL3",&f,FA_ARCH))
   3935 	{
   3936 		strcpy(extension,"WL3");
   3937 		NewEmenu[2].active =
   3938 		NewEmenu[4].active =
   3939 		EpisodeSelect[1] =
   3940 		EpisodeSelect[2] = 1;
   3941 	}
   3942 	else
   3943 #endif
   3944 #endif
   3945 
   3946 
   3947 
   3948 #ifdef SPEAR
   3949 #ifndef SPEARDEMO
   3950 	if (!findfirst("*.SOD",&f,FA_ARCH))
   3951 	{
   3952 		strcpy(extension,"SOD");
   3953 	}
   3954 	else
   3955 		Quit("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
   3956 #else
   3957 	if (!findfirst("*.SDM",&f,FA_ARCH))
   3958 	{
   3959 		strcpy(extension,"SDM");
   3960 	}
   3961 	else
   3962 		Quit("NO SPEAR OF DESTINY DEMO DATA FILES TO BE FOUND!");
   3963 #endif
   3964 
   3965 #else
   3966 	if (!findfirst("*.WL1",&f,FA_ARCH))
   3967 	{
   3968 		strcpy(extension,"WL1");
   3969 	}
   3970 	else
   3971 		Quit("NO WOLFENSTEIN 3-D DATA FILES to be found!");
   3972 #endif
   3973 
   3974 	strcat(configname,extension);
   3975 	strcat(SaveName,extension);
   3976 	strcat(PageFileName,extension);
   3977 	strcat(audioname,extension);
   3978 	strcat(demoname,extension);
   3979 #ifndef SPEAR
   3980 #ifndef GOODTIMES
   3981 	strcat(helpfilename,extension);
   3982 #endif
   3983 	strcat(endfilename,extension);
   3984 #endif
   3985 #endif
   3986 }