Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b126e26499
Fetching contributors…

Cannot retrieve contributors at this time

file 581 lines (487 sloc) 10.248 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
//
// MAIN.C - Handles StartUp and the MainMenu
//
#include <process.h>
#include <io.h>
#include <dos.h>
#include <mem.h>
#include <conio.h>
#include <bios.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "main.h"
#include "default.h"
#include "scguess.h"

int cdrom; // cmd-line param flag

char keydesc[256][10];
unsigned char ASCIINames[] = // Unshifted ASCII for scan codes
{
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 ,0 ,'1','2','3','4','5','6','7','8','9','0','-','=',0 ,0 , // 0
'Q','W','E','R','T','Y','U','I','O','P','[',']',0 ,0 ,'A','S', // 1
'D','F','G','H','J','K','L',';',0, '`', 0 ,92 ,'Z','X','C','V', // 2
'B','N','M',',','.','/',0 ,'*',0 , 0, 0 ,0 ,0 ,0 ,0 ,0 , // 3
0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
'2','3','0',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
};

char cards[M_LAST][20] = {
S_NONE,
S_PCSP,
"Adlib",
"Sound Blaster",
"Pro Audio Spectrum",
"Gravis Ultra Sound",
"WaveBlaster",
"Roland Sound Canvas",
"General Midi",
"Sound Blaster AWE32"
};

char controls [C_LAST][20] = {
S_CON1,
S_CON2,
S_CON3
};

CONTS curk;

net_t netinfo;
net_t info; // in case ESC is pressed

serial_t modeminfo;
serial_t minfo; // in case ESC is pressed

serial_t serialinfo;
serial_t sinfo; // in case ESC is pressed

DMXINFO lastc;
DMXINFO newc;

void * swindow;
BOOL savemusic = FALSE;
BOOL savefx = FALSE;

#define KEYBOARDINT 0x9

int mousepresent = 0;

enum
{
MAIN_CMUSIC,
MAIN_CSFX,
MAIN_TYPE,
MAIN_CONFIG,
MAIN_SAVE,

MAIN_NET,
MAIN_NETSG,
MAIN_MAX
};

item_t mainitems[]=
{
{MAIN_CMUSIC, 21,12,39, -1,-1},
{MAIN_CSFX, 21,13,39, -1,-1},
{MAIN_TYPE, 21,14,39, -1,-1},
{MAIN_CONFIG, 21,15,39, -1,-1},
{MAIN_SAVE, 21,16,39, -1,-1},
{MAIN_NET, 21,18,39, -1,-1},
{MAIN_NETSG, 21,19,39, -1,-1}
};

menu_t mainmenu =
{
&mainitems[0],
MAIN_CMUSIC,
MAIN_MAX,
0x7f
};

//
// Draw a PUP and get a keypress
//
void ErrorWindow(pup_t far *pup)
{
SaveScreen();
DrawPup(pup);
while (kbhit())
getch();
while (getch() != 0x1b);
RestoreScreen();
while (kbhit())
getch();
sound(3000);
delay(10);
nosound();
}

//
// Make ASCII names/key value lookup
//
void MakeKeyLookup (void)
{
int loop;

memset ( keydesc, 0, sizeof ( keydesc ) );

for ( loop = 0; loop < 128; loop++ )
keydesc [ loop ] [ 0 ] = ASCIINames[ loop ];

strcpy ( keydesc [ SC_CAPS_LOCK ], "CAPSLOCK" );
strcpy ( keydesc [ SC_BACKSPACE ], "BACKSP" );
strcpy ( keydesc [ SC_ENTER ], "ENTER" );
strcpy ( keydesc [ SC_TAB ], "TAB" );
strcpy ( keydesc [ SC_RIGHT_SHIFT ], "RSHIFT" );
strcpy ( keydesc [ SC_SPACE ], "SPACE" );
strcpy ( keydesc [ SC_CTRL ], "CTRL" );
strcpy ( keydesc [ SC_ALT ], "ALT" );
strcpy ( keydesc [ SC_INSERT ], "INS" );
strcpy ( keydesc [ SC_DELETE ], "DEL" );
strcpy ( keydesc [ SC_PAGEUP ], "PGUP" );
strcpy ( keydesc [ SC_PAGEDN ], "PGDN" );
strcpy ( keydesc [ SC_HOME ], "HOME" );
strcpy ( keydesc [ SC_END ], "END" );
strcpy ( keydesc [ SC_UP ], "UP" );
strcpy ( keydesc [ SC_DOWN ], "DOWN" );
strcpy ( keydesc [ SC_LEFT ], "LEFT" );
strcpy ( keydesc [ SC_RIGHT ], "RIGHT" );
}

//
// Set funky blue color
//
void SetColor (void)
{
return; // DON'T DO ANYTHING UNTIL I CAN SET IT BACK!
#if 0
_asm
{
push ax
push dx

mov dx, 0x3C8
mov ax, 1
out dx, al
inc dx

mov ax, 1
out dx, al

mov ax, 5
out dx, al

mov ax, 16
out dx, al

pop dx
pop ax
}
#endif
}

//
// Draw current config info in window
// MAKE SURE NO WINDOWS ARE ON TOP!
//
void DrawCurrentConfig(void)
{
RestoreScreen();
textcolor(8);
textbackground(7);
gotoxy(43,6);
cprintf(" ");
gotoxy(43,6);
cprintf("%s",controls [ newc.control ]);

gotoxy(43,7);
cprintf(" ");
gotoxy(43,7);
cprintf("%s",cards [ newc.m.card ]);

gotoxy(43,8);
cprintf(" ");
gotoxy(43,8);
cprintf("%s",cards [ newc.d.card ]);
gotoxy(1,25);
SaveScreen();
}

//
// Quitting - save changes?
//
enum { SAVEYES, SAVENO, SAVEMAX };
item_t quitwinitems[]=
{
{SAVEYES, 35,11,7, -1,-1},
{SAVENO, 35,12,7, -1,-1}
};
menu_t quitwinmenu=
{
&quitwinitems[0],
SAVEYES,
SAVEMAX,
0x7f
};

int QuitAndSave(void)
{
short key;
short field;

SaveScreen();
DrawPup(&quitwin);

quitwinmenu.startitem = SAVEYES;

while(1)
{
SetupMenu(&quitwinmenu);
field = GetMenuInput();
key = menukey;

switch(key)
{
case KEY_ESC:
RestoreScreen();
return -1;

case KEY_ENTER:
if (field == SAVEYES)
M_SaveDefaults();
RestoreScreen();
return 0;
}
}
}

//
// Start up and initialize SETUP
//
void StartUp(void)
{
int addr;
int irq;
int dma;
int midi;
union REGS r;

r.x.ax = 0;
int86(0x33,&r,&r);
if (r.x.ax == 0xffff)
mousepresent = 1;
else
mousepresent = 0;

r.x.ax = 2;
int86(0x33, &r, &r );

SetColor();

memset ( &newc, 0, sizeof ( DMXINFO ) );
memset ( &lastc, 0, sizeof ( DMXINFO ) );

MakeKeyLookup();
midi = addr = irq = dma = 0; // WILL BE INITED LATER

curk.up = SC_UP;
curk.down = SC_DOWN;
curk.left = SC_LEFT;
curk.right = SC_RIGHT;
curk.fire = SC_CTRL;
curk.use = SC_SPACE;
curk.key1 = SC_ALT;
curk.key2 = SC_RIGHT_SHIFT;
curk.key3 = SC_COMMA;
curk.key4 = SC_PERIOD;
curk.mouse[0] = 0;
curk.mouse[1] = 1;
curk.mouse[2] = 2;
curk.joy[0] = 0;
curk.joy[1] = 1;
curk.joy[2] = 2;
curk.joy[3] = 3;

newc.m.card = M_NONE;
newc.m.port = -1;
newc.m.midiport = -1;
newc.m.irq = -1;
newc.m.dma = -1;
newc.d = newc.m;
newc.numdig = 2;

DrawPup(&title);
DrawPup(&show);
DrawPup(&idmain2);
SaveScreen();

if ( !M_LoadDefaults() )
{
//
// Auto-detect ONLY first time through
//
if ( SmellsLikeGUS ( &addr, &irq, &dma ) )
{
if (newc.m.irq > 7)
ErrorWindow(&gusirqer);

newc.m.card = M_GUS;
newc.m.port = addr;
newc.m.midiport = -1;
newc.m.irq = irq;
newc.m.dma = dma;
newc.d = newc.m;
//fprintf(stderr, "GUS: addr=%x, irq=%d, dma=%d\n", addr, irq, dma);
}
else if ( SmellsLikeSB ( &addr, &irq, &dma, &midi ) )
{
newc.m.card = M_SB;
newc.m.port = addr;
newc.m.midiport = midi;
newc.m.irq = irq;
newc.m.dma = dma;
newc.d = newc.m;
}

ChooseController();
SetupMusic();
SetupFX();

lastc.control = newc.control;
lastc.numdig = newc.numdig;
lastc.m = newc.m;
lastc.d = newc.d;
mainmenu.startitem = MAIN_SAVE;
}
else
{
lastc.control = newc.control;
lastc.numdig = newc.numdig;
lastc.m = newc.m;
lastc.d = newc.d;

if (newc.m.irq > 7)
ErrorWindow(&gusirqer);

mainmenu.startitem = MAIN_CMUSIC;
}

DrawCurrentConfig();

//
// GLOBALS
//
respawn = nomonsters = 0;

MainMenu();
clrscr();
}

//
// Main menu
//
void MainMenu (void)
{
int i;
int field;
short key;
char *args[10];
char string[10][10];
int argcount;

// ASSUME THAT THE MAIN MENU HAS BEEN DRAWN IN STARTUP

while(1)
{
SetupMenu(&mainmenu);
field = GetMenuInput();
key = menukey;

if ( key == KEY_ESC )
{
if (QuitAndSave() < 0)
continue;
break;
}

//
// WARP
//
if (key == KEY_F1)
{
int level;
int i;

level = WarpTime();
if (!level)
continue;

M_SaveDefaults();
RestoreScreen();

argcount = 1;

if (nomonsters)
args[argcount++] = "-nomonsters";

if (respawn)
args[argcount++] = "-respawn";

args[argcount++] = "-warp";
#ifdef DOOM2
sprintf(string[argcount],"%d",level);
args[argcount] = string[argcount];
#else
sprintf(string[argcount],"%d",level>>8);
args[argcount] = string[argcount];
argcount++;
sprintf(string[argcount],"%d",level&0x0f);
args[argcount] = string[argcount];
#endif
argcount++;

if (cdrom)
args[argcount++] = "-cdrom";

for (i = 1;i < myargc; i++)
args[argcount++] = myargv[i];

args[argcount] = NULL;

textbackground(0);
textcolor(7);
clrscr();

if (!access("doom2.exe",0))
{
args[0] = "doom2.exe ";
execv("doom2.exe",args);
}
else
if (!access("heretic.exe",0))
{
args[0] = "heretic.exe ";
execv("heretic.exe",args);
}
else
if (!access("strife.exe",0))
{
args[0] = "strife.exe ";
execv("strife.exe",args);
}
else
{
args[0] = "doom.exe ";
execv("doom.exe",args);
}

printf("Problem EXECing "EXENAME" for netplay. Need to be in same directory!");

//
// ERROR EXECing!
//
exit(0);
}

if ( key != KEY_ENTER && key != KEY_F10 ) continue;

switch ( field )
{
case MAIN_CMUSIC:
SetupMusic();
break;

case MAIN_CSFX:
SetupFX();
break;

case MAIN_TYPE:
ChooseController();
break;

case MAIN_CONFIG:
ConfigControl();
break;

case MAIN_SAVE:

M_SaveDefaults();

textbackground(0);
textcolor(7);
clrscr();

argcount = 1;

for (i = 1;i < myargc; i++)
args[argcount++] = myargv[i];

if (cdrom)
args[argcount++] = "-cdrom";

if (!access("heretic.exe",0))
{
args[0] = "heretic.exe";
args[argcount] = NULL;
execv("heretic.exe",args);
}
else
if (!access("strife.exe",0))
{
args[0] = "strife.exe ";
execv("strife.exe",args);
}
else
if (!access("doom2.exe",0))
{
args[0] = "doom2.exe";
args[argcount] = NULL;
execv("doom2.exe",args);
}
else
{
args[0] = "doom.exe ";
args[argcount] = NULL;
execv("doom.exe",args);
}

printf("Problem EXECing "EXENAME"! Probably not in same directory!\n");
exit(0);

goto func_exit;

case MAIN_NET:
ChooseNetplay();
break;

case MAIN_NETSG:
#ifndef STRIFE
ChooseNetrestore();
#endif
break;

default:
break;
}
}

func_exit:

textbackground(0);
textcolor(7);
clrscr();

return;
}
Something went wrong with that request. Please try again.