Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 581 lines (487 sloc) 10.248 kb
b126e264 » tbradshaw
2012-01-31 The source of the setup program included with DOOM, Final DOOM, Strif…
1 //
2 // MAIN.C - Handles StartUp and the MainMenu
3 //
4 #include <process.h>
5 #include <io.h>
6 #include <dos.h>
7 #include <mem.h>
8 #include <conio.h>
9 #include <bios.h>
10 #include <string.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "main.h"
15 #include "default.h"
16 #include "scguess.h"
17
18 int cdrom; // cmd-line param flag
19
20 char keydesc[256][10];
21 unsigned char ASCIINames[] = // Unshifted ASCII for scan codes
22 {
23 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
24 0 ,0 ,'1','2','3','4','5','6','7','8','9','0','-','=',0 ,0 , // 0
25 'Q','W','E','R','T','Y','U','I','O','P','[',']',0 ,0 ,'A','S', // 1
26 'D','F','G','H','J','K','L',';',0, '`', 0 ,92 ,'Z','X','C','V', // 2
27 'B','N','M',',','.','/',0 ,'*',0 , 0, 0 ,0 ,0 ,0 ,0 ,0 , // 3
28 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
29 '2','3','0',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
30 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
31 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
32 };
33
34 char cards[M_LAST][20] = {
35 S_NONE,
36 S_PCSP,
37 "Adlib",
38 "Sound Blaster",
39 "Pro Audio Spectrum",
40 "Gravis Ultra Sound",
41 "WaveBlaster",
42 "Roland Sound Canvas",
43 "General Midi",
44 "Sound Blaster AWE32"
45 };
46
47 char controls [C_LAST][20] = {
48 S_CON1,
49 S_CON2,
50 S_CON3
51 };
52
53 CONTS curk;
54
55 net_t netinfo;
56 net_t info; // in case ESC is pressed
57
58 serial_t modeminfo;
59 serial_t minfo; // in case ESC is pressed
60
61 serial_t serialinfo;
62 serial_t sinfo; // in case ESC is pressed
63
64 DMXINFO lastc;
65 DMXINFO newc;
66
67 void * swindow;
68 BOOL savemusic = FALSE;
69 BOOL savefx = FALSE;
70
71 #define KEYBOARDINT 0x9
72
73 int mousepresent = 0;
74
75 enum
76 {
77 MAIN_CMUSIC,
78 MAIN_CSFX,
79 MAIN_TYPE,
80 MAIN_CONFIG,
81 MAIN_SAVE,
82
83 MAIN_NET,
84 MAIN_NETSG,
85 MAIN_MAX
86 };
87
88 item_t mainitems[]=
89 {
90 {MAIN_CMUSIC, 21,12,39, -1,-1},
91 {MAIN_CSFX, 21,13,39, -1,-1},
92 {MAIN_TYPE, 21,14,39, -1,-1},
93 {MAIN_CONFIG, 21,15,39, -1,-1},
94 {MAIN_SAVE, 21,16,39, -1,-1},
95 {MAIN_NET, 21,18,39, -1,-1},
96 {MAIN_NETSG, 21,19,39, -1,-1}
97 };
98
99 menu_t mainmenu =
100 {
101 &mainitems[0],
102 MAIN_CMUSIC,
103 MAIN_MAX,
104 0x7f
105 };
106
107 //
108 // Draw a PUP and get a keypress
109 //
110 void ErrorWindow(pup_t far *pup)
111 {
112 SaveScreen();
113 DrawPup(pup);
114 while (kbhit())
115 getch();
116 while (getch() != 0x1b);
117 RestoreScreen();
118 while (kbhit())
119 getch();
120 sound(3000);
121 delay(10);
122 nosound();
123 }
124
125 //
126 // Make ASCII names/key value lookup
127 //
128 void MakeKeyLookup (void)
129 {
130 int loop;
131
132 memset ( keydesc, 0, sizeof ( keydesc ) );
133
134 for ( loop = 0; loop < 128; loop++ )
135 keydesc [ loop ] [ 0 ] = ASCIINames[ loop ];
136
137 strcpy ( keydesc [ SC_CAPS_LOCK ], "CAPSLOCK" );
138 strcpy ( keydesc [ SC_BACKSPACE ], "BACKSP" );
139 strcpy ( keydesc [ SC_ENTER ], "ENTER" );
140 strcpy ( keydesc [ SC_TAB ], "TAB" );
141 strcpy ( keydesc [ SC_RIGHT_SHIFT ], "RSHIFT" );
142 strcpy ( keydesc [ SC_SPACE ], "SPACE" );
143 strcpy ( keydesc [ SC_CTRL ], "CTRL" );
144 strcpy ( keydesc [ SC_ALT ], "ALT" );
145 strcpy ( keydesc [ SC_INSERT ], "INS" );
146 strcpy ( keydesc [ SC_DELETE ], "DEL" );
147 strcpy ( keydesc [ SC_PAGEUP ], "PGUP" );
148 strcpy ( keydesc [ SC_PAGEDN ], "PGDN" );
149 strcpy ( keydesc [ SC_HOME ], "HOME" );
150 strcpy ( keydesc [ SC_END ], "END" );
151 strcpy ( keydesc [ SC_UP ], "UP" );
152 strcpy ( keydesc [ SC_DOWN ], "DOWN" );
153 strcpy ( keydesc [ SC_LEFT ], "LEFT" );
154 strcpy ( keydesc [ SC_RIGHT ], "RIGHT" );
155 }
156
157 //
158 // Set funky blue color
159 //
160 void SetColor (void)
161 {
162 return; // DON'T DO ANYTHING UNTIL I CAN SET IT BACK!
163 #if 0
164 _asm
165 {
166 push ax
167 push dx
168
169 mov dx, 0x3C8
170 mov ax, 1
171 out dx, al
172 inc dx
173
174 mov ax, 1
175 out dx, al
176
177 mov ax, 5
178 out dx, al
179
180 mov ax, 16
181 out dx, al
182
183 pop dx
184 pop ax
185 }
186 #endif
187 }
188
189 //
190 // Draw current config info in window
191 // MAKE SURE NO WINDOWS ARE ON TOP!
192 //
193 void DrawCurrentConfig(void)
194 {
195 RestoreScreen();
196 textcolor(8);
197 textbackground(7);
198 gotoxy(43,6);
199 cprintf(" ");
200 gotoxy(43,6);
201 cprintf("%s",controls [ newc.control ]);
202
203 gotoxy(43,7);
204 cprintf(" ");
205 gotoxy(43,7);
206 cprintf("%s",cards [ newc.m.card ]);
207
208 gotoxy(43,8);
209 cprintf(" ");
210 gotoxy(43,8);
211 cprintf("%s",cards [ newc.d.card ]);
212 gotoxy(1,25);
213 SaveScreen();
214 }
215
216 //
217 // Quitting - save changes?
218 //
219 enum { SAVEYES, SAVENO, SAVEMAX };
220 item_t quitwinitems[]=
221 {
222 {SAVEYES, 35,11,7, -1,-1},
223 {SAVENO, 35,12,7, -1,-1}
224 };
225 menu_t quitwinmenu=
226 {
227 &quitwinitems[0],
228 SAVEYES,
229 SAVEMAX,
230 0x7f
231 };
232
233 int QuitAndSave(void)
234 {
235 short key;
236 short field;
237
238 SaveScreen();
239 DrawPup(&quitwin);
240
241 quitwinmenu.startitem = SAVEYES;
242
243 while(1)
244 {
245 SetupMenu(&quitwinmenu);
246 field = GetMenuInput();
247 key = menukey;
248
249 switch(key)
250 {
251 case KEY_ESC:
252 RestoreScreen();
253 return -1;
254
255 case KEY_ENTER:
256 if (field == SAVEYES)
257 M_SaveDefaults();
258 RestoreScreen();
259 return 0;
260 }
261 }
262 }
263
264 //
265 // Start up and initialize SETUP
266 //
267 void StartUp(void)
268 {
269 int addr;
270 int irq;
271 int dma;
272 int midi;
273 union REGS r;
274
275 r.x.ax = 0;
276 int86(0x33,&r,&r);
277 if (r.x.ax == 0xffff)
278 mousepresent = 1;
279 else
280 mousepresent = 0;
281
282 r.x.ax = 2;
283 int86(0x33, &r, &r );
284
285 SetColor();
286
287 memset ( &newc, 0, sizeof ( DMXINFO ) );
288 memset ( &lastc, 0, sizeof ( DMXINFO ) );
289
290 MakeKeyLookup();
291 midi = addr = irq = dma = 0; // WILL BE INITED LATER
292
293 curk.up = SC_UP;
294 curk.down = SC_DOWN;
295 curk.left = SC_LEFT;
296 curk.right = SC_RIGHT;
297 curk.fire = SC_CTRL;
298 curk.use = SC_SPACE;
299 curk.key1 = SC_ALT;
300 curk.key2 = SC_RIGHT_SHIFT;
301 curk.key3 = SC_COMMA;
302 curk.key4 = SC_PERIOD;
303 curk.mouse[0] = 0;
304 curk.mouse[1] = 1;
305 curk.mouse[2] = 2;
306 curk.joy[0] = 0;
307 curk.joy[1] = 1;
308 curk.joy[2] = 2;
309 curk.joy[3] = 3;
310
311 newc.m.card = M_NONE;
312 newc.m.port = -1;
313 newc.m.midiport = -1;
314 newc.m.irq = -1;
315 newc.m.dma = -1;
316 newc.d = newc.m;
317 newc.numdig = 2;
318
319 DrawPup(&title);
320 DrawPup(&show);
321 DrawPup(&idmain2);
322 SaveScreen();
323
324 if ( !M_LoadDefaults() )
325 {
326 //
327 // Auto-detect ONLY first time through
328 //
329 if ( SmellsLikeGUS ( &addr, &irq, &dma ) )
330 {
331 if (newc.m.irq > 7)
332 ErrorWindow(&gusirqer);
333
334 newc.m.card = M_GUS;
335 newc.m.port = addr;
336 newc.m.midiport = -1;
337 newc.m.irq = irq;
338 newc.m.dma = dma;
339 newc.d = newc.m;
340 //fprintf(stderr, "GUS: addr=%x, irq=%d, dma=%d\n", addr, irq, dma);
341 }
342 else if ( SmellsLikeSB ( &addr, &irq, &dma, &midi ) )
343 {
344 newc.m.card = M_SB;
345 newc.m.port = addr;
346 newc.m.midiport = midi;
347 newc.m.irq = irq;
348 newc.m.dma = dma;
349 newc.d = newc.m;
350 }
351
352 ChooseController();
353 SetupMusic();
354 SetupFX();
355
356 lastc.control = newc.control;
357 lastc.numdig = newc.numdig;
358 lastc.m = newc.m;
359 lastc.d = newc.d;
360 mainmenu.startitem = MAIN_SAVE;
361 }
362 else
363 {
364 lastc.control = newc.control;
365 lastc.numdig = newc.numdig;
366 lastc.m = newc.m;
367 lastc.d = newc.d;
368
369 if (newc.m.irq > 7)
370 ErrorWindow(&gusirqer);
371
372 mainmenu.startitem = MAIN_CMUSIC;
373 }
374
375 DrawCurrentConfig();
376
377 //
378 // GLOBALS
379 //
380 respawn = nomonsters = 0;
381
382 MainMenu();
383 clrscr();
384 }
385
386 //
387 // Main menu
388 //
389 void MainMenu (void)
390 {
391 int i;
392 int field;
393 short key;
394 char *args[10];
395 char string[10][10];
396 int argcount;
397
398 // ASSUME THAT THE MAIN MENU HAS BEEN DRAWN IN STARTUP
399
400 while(1)
401 {
402 SetupMenu(&mainmenu);
403 field = GetMenuInput();
404 key = menukey;
405
406 if ( key == KEY_ESC )
407 {
408 if (QuitAndSave() < 0)
409 continue;
410 break;
411 }
412
413 //
414 // WARP
415 //
416 if (key == KEY_F1)
417 {
418 int level;
419 int i;
420
421 level = WarpTime();
422 if (!level)
423 continue;
424
425 M_SaveDefaults();
426 RestoreScreen();
427
428 argcount = 1;
429
430 if (nomonsters)
431 args[argcount++] = "-nomonsters";
432
433 if (respawn)
434 args[argcount++] = "-respawn";
435
436 args[argcount++] = "-warp";
437 #ifdef DOOM2
438 sprintf(string[argcount],"%d",level);
439 args[argcount] = string[argcount];
440 #else
441 sprintf(string[argcount],"%d",level>>8);
442 args[argcount] = string[argcount];
443 argcount++;
444 sprintf(string[argcount],"%d",level&0x0f);
445 args[argcount] = string[argcount];
446 #endif
447 argcount++;
448
449 if (cdrom)
450 args[argcount++] = "-cdrom";
451
452 for (i = 1;i < myargc; i++)
453 args[argcount++] = myargv[i];
454
455 args[argcount] = NULL;
456
457 textbackground(0);
458 textcolor(7);
459 clrscr();
460
461 if (!access("doom2.exe",0))
462 {
463 args[0] = "doom2.exe ";
464 execv("doom2.exe",args);
465 }
466 else
467 if (!access("heretic.exe",0))
468 {
469 args[0] = "heretic.exe ";
470 execv("heretic.exe",args);
471 }
472 else
473 if (!access("strife.exe",0))
474 {
475 args[0] = "strife.exe ";
476 execv("strife.exe",args);
477 }
478 else
479 {
480 args[0] = "doom.exe ";
481 execv("doom.exe",args);
482 }
483
484 printf("Problem EXECing "EXENAME" for netplay. Need to be in same directory!");
485
486 //
487 // ERROR EXECing!
488 //
489 exit(0);
490 }
491
492 if ( key != KEY_ENTER && key != KEY_F10 ) continue;
493
494 switch ( field )
495 {
496 case MAIN_CMUSIC:
497 SetupMusic();
498 break;
499
500 case MAIN_CSFX:
501 SetupFX();
502 break;
503
504 case MAIN_TYPE:
505 ChooseController();
506 break;
507
508 case MAIN_CONFIG:
509 ConfigControl();
510 break;
511
512 case MAIN_SAVE:
513
514 M_SaveDefaults();
515
516 textbackground(0);
517 textcolor(7);
518 clrscr();
519
520 argcount = 1;
521
522 for (i = 1;i < myargc; i++)
523 args[argcount++] = myargv[i];
524
525 if (cdrom)
526 args[argcount++] = "-cdrom";
527
528 if (!access("heretic.exe",0))
529 {
530 args[0] = "heretic.exe";
531 args[argcount] = NULL;
532 execv("heretic.exe",args);
533 }
534 else
535 if (!access("strife.exe",0))
536 {
537 args[0] = "strife.exe ";
538 execv("strife.exe",args);
539 }
540 else
541 if (!access("doom2.exe",0))
542 {
543 args[0] = "doom2.exe";
544 args[argcount] = NULL;
545 execv("doom2.exe",args);
546 }
547 else
548 {
549 args[0] = "doom.exe ";
550 args[argcount] = NULL;
551 execv("doom.exe",args);
552 }
553
554 printf("Problem EXECing "EXENAME"! Probably not in same directory!\n");
555 exit(0);
556
557 goto func_exit;
558
559 case MAIN_NET:
560 ChooseNetplay();
561 break;
562
563 case MAIN_NETSG:
564 #ifndef STRIFE
565 ChooseNetrestore();
566 #endif
567 break;
568
569 default:
570 break;
571 }
572 }
573
574 func_exit:
575
576 textbackground(0);
577 textcolor(7);
578 clrscr();
579
580 return;
581 }
Something went wrong with that request. Please try again.