diff --git a/uefidoom/d_main.c b/uefidoom/d_main.c index a0212c9..0be374e 100644 --- a/uefidoom/d_main.c +++ b/uefidoom/d_main.c @@ -1,4 +1,4 @@ -// Emacs style mode select -*- C++ -*- +// Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // // $Id:$ @@ -24,12 +24,10 @@ // //----------------------------------------------------------------------------- - static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $"; -#define BGCOLOR 7 -#define FGCOLOR 8 - +#define BGCOLOR 7 +#define FGCOLOR 8 //#ifdef NORMALUNIX #include @@ -42,14 +40,12 @@ static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $"; //#endif - #include "doomdef.h" #include "doomstat.h" #include "dstrings.h" #include "sounds.h" - #include "z_zone.h" #include "w_wad.h" #include "s_sound.h" @@ -76,7 +72,6 @@ static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $"; #include "p_setup.h" #include "r_local.h" - #include "d_main.h" // @@ -88,51 +83,42 @@ static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $"; // calls all ?_Responder, ?_Ticker, and ?_Drawer, // calls I_GetTime, I_StartFrame, and I_StartTic // -void D_DoomLoop (void); - - -char* wadfiles[MAXWADFILES]; - +void D_DoomLoop(void); -boolean devparm; // started game with -devparm -boolean nomonsters; // checkparm of -nomonsters -boolean respawnparm; // checkparm of -respawn -boolean fastparm; // checkparm of -fast +char *wadfiles[MAXWADFILES]; -boolean drone; - -boolean singletics = true; // debug flag to cancel adaptiveness +boolean devparm; // started game with -devparm +boolean nomonsters; // checkparm of -nomonsters +boolean respawnparm; // checkparm of -respawn +boolean fastparm; // checkparm of -fast +boolean drone; +boolean singletics = true; // debug flag to cancel adaptiveness //extern int soundVolume; //extern int sfxVolume; //extern int musicVolume; -extern boolean inhelpscreens; - -skill_t startskill; -int startepisode; -int startmap; -boolean autostart; - -FILE* debugfile; - -boolean advancedemo; +extern boolean inhelpscreens; +skill_t startskill; +int startepisode; +int startmap; +boolean autostart; +FILE *debugfile; +boolean advancedemo; -char wadfile[1024]; // primary wad file -char mapdir[1024]; // directory of development maps -char basedefault[1024]; // default file - - -void D_CheckNetGame (void); -void D_ProcessEvents (void); -void G_BuildTiccmd (ticcmd_t* cmd); -void D_DoAdvanceDemo (void); +char wadfile[1024]; // primary wad file +char mapdir[1024]; // directory of development maps +char basedefault[1024]; // default file +void D_CheckNetGame(void); +void D_ProcessEvents(void); +void G_BuildTiccmd(ticcmd_t *cmd); +void D_DoAdvanceDemo(void); // // EVENT HANDLING @@ -140,46 +126,40 @@ void D_DoAdvanceDemo (void); // Events are asynchronous inputs generally generated by the game user. // Events can be discarded if no responder claims them // -event_t events[MAXEVENTS]; -int eventhead; -int eventtail; - +event_t events[MAXEVENTS]; +int eventhead; +int eventtail; // // D_PostEvent // Called by the I/O functions when input is detected // -void D_PostEvent (event_t* ev) +void D_PostEvent(event_t *ev) { - events[eventhead] = *ev; - eventhead = (++eventhead)&(MAXEVENTS-1); + events[eventhead] = *ev; + eventhead = (++eventhead) & (MAXEVENTS - 1); } - // // D_ProcessEvents // Send all the events of the given timestamp down the responder chain // -void D_ProcessEvents (void) +void D_ProcessEvents(void) { - event_t* ev; - - // IF STORE DEMO, DO NOT ACCEPT INPUT - if ( ( gamemode == commercial ) - && (W_CheckNumForName("map01")<0) ) - return; - - for ( ; eventtail != eventhead ; eventtail = (++eventtail)&(MAXEVENTS-1) ) - { - ev = &events[eventtail]; - if (M_Responder (ev)) - continue; // menu ate the event - G_Responder (ev); - } -} - + event_t *ev; + // IF STORE DEMO, DO NOT ACCEPT INPUT + if ((gamemode == commercial) && (W_CheckNumForName("map01") < 0)) + return; + for (; eventtail != eventhead; eventtail = (++eventtail) & (MAXEVENTS - 1)) + { + ev = &events[eventtail]; + if (M_Responder(ev)) + continue; // menu ate the event + G_Responder(ev); + } +} // // D_Display @@ -187,379 +167,359 @@ void D_ProcessEvents (void) // // wipegamestate can be set to -1 to force a wipe on the next draw -gamestate_t wipegamestate = GS_DEMOSCREEN; -extern boolean setsizeneeded; -extern int showMessages; -void R_ExecuteSetViewSize (void); +gamestate_t wipegamestate = GS_DEMOSCREEN; +extern boolean setsizeneeded; +extern int showMessages; +void R_ExecuteSetViewSize(void); -void D_Display (void) +void D_Display(void) { - static boolean viewactivestate = false; - static boolean menuactivestate = false; - static boolean inhelpscreensstate = false; - static boolean fullscreen = false; - static gamestate_t oldgamestate = -1; - static int borderdrawcount; - int nowtime; - int tics; - int wipestart; - int y; - boolean done; - boolean wipe; - boolean redrawsbar; - - if (nodrawers) - return; // for comparative timing / profiling - - redrawsbar = false; - - // change the view size if needed - if (setsizeneeded) - { - R_ExecuteSetViewSize (); - oldgamestate = -1; // force background redraw - borderdrawcount = 3; - } + static boolean viewactivestate = false; + static boolean menuactivestate = false; + static boolean inhelpscreensstate = false; + static boolean fullscreen = false; + static gamestate_t oldgamestate = -1; + static int borderdrawcount; + int nowtime; + int tics; + int wipestart; + int y; + boolean done; + boolean wipe; + boolean redrawsbar; + + if (nodrawers) + return; // for comparative timing / profiling + + redrawsbar = false; + + // change the view size if needed + if (setsizeneeded) + { + R_ExecuteSetViewSize(); + oldgamestate = -1; // force background redraw + borderdrawcount = 3; + } - // save the current screen if about to wipe - if (gamestate != wipegamestate) - { - wipe = true; - wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); - } - else - wipe = false; - - if (gamestate == GS_LEVEL && gametic) - HU_Erase(); - - // do buffered drawing - switch (gamestate) - { - case GS_LEVEL: - if (!gametic) - break; - if (automapactive) - AM_Drawer (); - if (wipe || (viewheight != 200 && fullscreen) ) - redrawsbar = true; - if (inhelpscreensstate && !inhelpscreens) - redrawsbar = true; // just put away the help screen - ST_Drawer (viewheight == 200, redrawsbar ); - fullscreen = viewheight == 200; - break; + // save the current screen if about to wipe + if (gamestate != wipegamestate) + { + wipe = true; + wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); + } + else + wipe = false; - case GS_INTERMISSION: - WI_Drawer (); - break; + if (gamestate == GS_LEVEL && gametic) + HU_Erase(); - case GS_FINALE: - F_Drawer (); - break; + // do buffered drawing + switch (gamestate) + { + case GS_LEVEL: + if (!gametic) + break; + if (automapactive) + AM_Drawer(); + if (wipe || (viewheight != 200 && fullscreen)) + redrawsbar = true; + if (inhelpscreensstate && !inhelpscreens) + redrawsbar = true; // just put away the help screen + ST_Drawer(viewheight == 200, redrawsbar); + fullscreen = viewheight == 200; + break; + + case GS_INTERMISSION: + WI_Drawer(); + break; + + case GS_FINALE: + F_Drawer(); + break; + + case GS_DEMOSCREEN: + D_PageDrawer(); + break; + } - case GS_DEMOSCREEN: - D_PageDrawer (); - break; - } - - // draw buffered stuff to screen - I_UpdateNoBlit (); - - // draw the view directly - if (gamestate == GS_LEVEL && !automapactive && gametic) - R_RenderPlayerView (&players[displayplayer]); - - if (gamestate == GS_LEVEL && gametic) - HU_Drawer (); - - // clean up border stuff - if (gamestate != oldgamestate && gamestate != GS_LEVEL) - I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE)); - - // see if the border needs to be initially drawn - if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL) - { - viewactivestate = false; // view was not active - R_FillBackScreen (); // draw the pattern into the back screen - } + // draw buffered stuff to screen + I_UpdateNoBlit(); - // see if the border needs to be updated to the screen - if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320) - { - if (menuactive || menuactivestate || !viewactivestate) - borderdrawcount = 3; - if (borderdrawcount) + // draw the view directly + if (gamestate == GS_LEVEL && !automapactive && gametic) + R_RenderPlayerView(&players[displayplayer]); + + if (gamestate == GS_LEVEL && gametic) + HU_Drawer(); + + // clean up border stuff + if (gamestate != oldgamestate && gamestate != GS_LEVEL) + I_SetPalette(W_CacheLumpName("PLAYPAL", PU_CACHE)); + + // see if the border needs to be initially drawn + if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL) { - R_DrawViewBorder (); // erase old menu stuff - borderdrawcount--; + viewactivestate = false; // view was not active + R_FillBackScreen(); // draw the pattern into the back screen } - } + // see if the border needs to be updated to the screen + if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320) + { + if (menuactive || menuactivestate || !viewactivestate) + borderdrawcount = 3; + if (borderdrawcount) + { + R_DrawViewBorder(); // erase old menu stuff + borderdrawcount--; + } + } - menuactivestate = menuactive; - viewactivestate = viewactive; - inhelpscreensstate = inhelpscreens; - oldgamestate = wipegamestate = gamestate; - - // draw pause pic - if (paused) - { - if (automapactive) - y = 4; - else - y = viewwindowy+4; - V_DrawPatchDirect(viewwindowx+(scaledviewwidth-68)/2, - y,0,W_CacheLumpName ("M_PAUSE", PU_CACHE)); - } + menuactivestate = menuactive; + viewactivestate = viewactive; + inhelpscreensstate = inhelpscreens; + oldgamestate = wipegamestate = gamestate; + // draw pause pic + if (paused) + { + if (automapactive) + y = 4; + else + y = viewwindowy + 4; + V_DrawPatchDirect(viewwindowx + (scaledviewwidth - 68) / 2, + y, 0, W_CacheLumpName("M_PAUSE", PU_CACHE)); + } - // menus go directly to the screen - M_Drawer (); // menu is drawn even on top of everything - NetUpdate (); // send out any new accumulation + // menus go directly to the screen + M_Drawer(); // menu is drawn even on top of everything + NetUpdate(); // send out any new accumulation + // normal update + if (!wipe) + { + I_FinishUpdate(); // page flip or blit buffer + return; + } - // normal update - if (!wipe) - { - I_FinishUpdate (); // page flip or blit buffer - return; - } - - // wipe update - wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); + // wipe update + wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); - wipestart = I_GetTime () - 1; + wipestart = I_GetTime() - 1; - do - { do { - nowtime = I_GetTime (); - tics = nowtime - wipestart; - } while (!tics); - wipestart = nowtime; - done = wipe_ScreenWipe(wipe_Melt - , 0, 0, SCREENWIDTH, SCREENHEIGHT, tics); - I_UpdateNoBlit (); - M_Drawer (); // menu is drawn even on top of wipes - I_FinishUpdate (); // page flip or blit buffer - } while (!done); + do + { + nowtime = I_GetTime(); + tics = nowtime - wipestart; + } while (!tics); + wipestart = nowtime; + done = wipe_ScreenWipe(wipe_Melt, 0, 0, SCREENWIDTH, SCREENHEIGHT, tics); + I_UpdateNoBlit(); + M_Drawer(); // menu is drawn even on top of wipes + I_FinishUpdate(); // page flip or blit buffer + } while (!done); } - - // // D_DoomLoop // -extern boolean demorecording; +extern boolean demorecording; -void D_DoomLoop (void) +void D_DoomLoop(void) { printf("D_MainLoop\n"); - if (demorecording) - G_BeginRecording (); - - if (M_CheckParm ("-debugfile")) - { - char filename[20]; - sprintf (filename,"debug%i.txt",consoleplayer); - printf ("debug output to: %s\n",filename); - debugfile = fopen (filename,"w"); - } - - I_InitGraphics (); + if (demorecording) + G_BeginRecording(); - while (1) - { - // frame syncronous IO operations - I_StartFrame (); - - // process one or more tics - if (singletics) - { - usleep((1000 * 1000) / 35); - //for (int ticstart = 0; ticstart < 6; ticstart++) // Process up to 5 events. - I_StartTic (); - D_ProcessEvents (); - G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]); - if (advancedemo) - D_DoAdvanceDemo (); - M_Ticker (); - G_Ticker (); - gametic++; - maketic++; - } - else + if (M_CheckParm("-debugfile")) { - TryRunTics (); // will run at least one tic + char filename[20]; + sprintf(filename, "debug%i.txt", consoleplayer); + printf("debug output to: %s\n", filename); + debugfile = fopen(filename, "w"); } - G_ResetKeycmd (); + I_InitGraphics(); - S_UpdateSounds (players[consoleplayer].mo);// move positional sounds - - // Update display, next frame, with current state. - D_Display (); + while (1) + { + // frame syncronous IO operations + I_StartFrame(); + + // process one or more tics + if (singletics) + { + usleep((1000 * 1000) / 35); + //for (int ticstart = 0; ticstart < 6; ticstart++) // Process up to 5 events. + I_StartTic(); + D_ProcessEvents(); + G_BuildTiccmd(&netcmds[consoleplayer][maketic % BACKUPTICS]); + if (advancedemo) + D_DoAdvanceDemo(); + M_Ticker(); + G_Ticker(); + gametic++; + maketic++; + } + else + { + TryRunTics(); // will run at least one tic + } + + G_ResetKeycmd(); + + S_UpdateSounds(players[consoleplayer].mo); // move positional sounds + + // Update display, next frame, with current state. + D_Display(); #ifndef SNDSERV - // Sound mixing for the buffer is snychronous. - I_UpdateSound(); -#endif - // Synchronous sound output is explicitly called. + // Sound mixing for the buffer is snychronous. + I_UpdateSound(); +#endif + // Synchronous sound output is explicitly called. #ifndef SNDINTR - // Update sound output. - I_SubmitSound(); + // Update sound output. + I_SubmitSound(); #endif - } + } } - - // // DEMO LOOP // -int demosequence; -int pagetic; -char *pagename; - +int demosequence; +int pagetic; +char *pagename; // // D_PageTicker // Handles timing for warped projection // -void D_PageTicker (void) +void D_PageTicker(void) { - if (--pagetic < 0) - D_AdvanceDemo (); + if (--pagetic < 0) + D_AdvanceDemo(); } - - // // D_PageDrawer // -void D_PageDrawer (void) +void D_PageDrawer(void) { - V_DrawPatch (0,0, 0, W_CacheLumpName(pagename, PU_CACHE)); + V_DrawPatch(0, 0, 0, W_CacheLumpName(pagename, PU_CACHE)); } - // // D_AdvanceDemo // Called after each demo or intro demosequence finishes // -void D_AdvanceDemo (void) +void D_AdvanceDemo(void) { - advancedemo = true; + advancedemo = true; } - // // This cycles through the demo sequences. // FIXME - version dependend demo numbers? // - void D_DoAdvanceDemo (void) +void D_DoAdvanceDemo(void) { - players[consoleplayer].playerstate = PST_LIVE; // not reborn - advancedemo = false; - usergame = false; // no save / end game here - paused = false; - gameaction = ga_nothing; - - if ( gamemode == retail ) - demosequence = (demosequence+1)%7; - else - demosequence = (demosequence+1)%6; - - switch (demosequence) - { - case 0: - if ( gamemode == commercial ) - pagetic = 35 * 11; - else - pagetic = 170; - gamestate = GS_DEMOSCREEN; - pagename = "TITLEPIC"; - if ( gamemode == commercial ) - S_StartMusic(mus_dm2ttl); + players[consoleplayer].playerstate = PST_LIVE; // not reborn + advancedemo = false; + usergame = false; // no save / end game here + paused = false; + gameaction = ga_nothing; + + if (gamemode == retail) + demosequence = (demosequence + 1) % 7; else - S_StartMusic (mus_intro); - break; - case 1: - G_DeferedPlayDemo ("demo1"); - break; - case 2: - pagetic = 200; - gamestate = GS_DEMOSCREEN; - pagename = "CREDIT"; - break; - case 3: - G_DeferedPlayDemo ("demo2"); - break; - case 4: - gamestate = GS_DEMOSCREEN; - if ( gamemode == commercial) - { - pagetic = 35 * 11; - pagename = "TITLEPIC"; - S_StartMusic(mus_dm2ttl); - } - else - { - pagetic = 200; + demosequence = (demosequence + 1) % 6; - if ( gamemode == retail ) - pagename = "CREDIT"; - else - pagename = "HELP2"; + switch (demosequence) + { + case 0: + if (gamemode == commercial) + pagetic = 35 * 11; + else + pagetic = 170; + gamestate = GS_DEMOSCREEN; + pagename = "TITLEPIC"; + if (gamemode == commercial) + S_StartMusic(mus_dm2ttl); + else + S_StartMusic(mus_intro); + break; + case 1: + G_DeferedPlayDemo("demo1"); + break; + case 2: + pagetic = 200; + gamestate = GS_DEMOSCREEN; + pagename = "CREDIT"; + break; + case 3: + G_DeferedPlayDemo("demo2"); + break; + case 4: + gamestate = GS_DEMOSCREEN; + if (gamemode == commercial) + { + pagetic = 35 * 11; + pagename = "TITLEPIC"; + S_StartMusic(mus_dm2ttl); + } + else + { + pagetic = 200; + + if (gamemode == retail) + pagename = "CREDIT"; + else + pagename = "HELP2"; + } + break; + case 5: + G_DeferedPlayDemo("demo3"); + break; + // THE DEFINITIVE DOOM Special Edition demo + case 6: + G_DeferedPlayDemo("demo4"); + break; } - break; - case 5: - G_DeferedPlayDemo ("demo3"); - break; - // THE DEFINITIVE DOOM Special Edition demo - case 6: - G_DeferedPlayDemo ("demo4"); - break; - } } - - // // D_StartTitle // -void D_StartTitle (void) +void D_StartTitle(void) { - gameaction = ga_nothing; - demosequence = -1; - D_AdvanceDemo (); + gameaction = ga_nothing; + demosequence = -1; + D_AdvanceDemo(); } - - - // print title for every printed line -char title[128]; - - +char title[128]; // // D_AddFile // -void D_AddFile (char *file) +void D_AddFile(char *file) { - int numwadfiles; - char *newfile; - - for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++) - ; - - newfile = malloc (strlen(file)+1); - strcpy (newfile, file); - - wadfiles[numwadfiles] = newfile; + int numwadfiles; + char *newfile; + + for (numwadfiles = 0; wadfiles[numwadfiles]; numwadfiles++) + ; + + newfile = malloc(strlen(file) + 1); + strcpy(newfile, file); + + wadfiles[numwadfiles] = newfile; } // @@ -568,101 +528,100 @@ void D_AddFile (char *file) // to determine whether registered/commercial features // should be executed (notably loading PWAD's). // -void IdentifyVersion (void) +void IdentifyVersion(void) { - char* doom1wad; - char* doomwad; - char* doomuwad; - char* doom2wad; + char *doom1wad; + char *doomwad; + char *doomuwad; + char *doom2wad; - char* doom2fwad; - char* plutoniawad; - char* tntwad; + char *doom2fwad; + char *plutoniawad; + char *tntwad; - char *home; - char *doomwaddir; - doomwaddir = getenv("DOOMWADDIR"); - if (!doomwaddir) - doomwaddir = "."; + char *home; + char *doomwaddir; + doomwaddir = getenv("DOOMWADDIR"); + if (!doomwaddir) + doomwaddir = "."; - // Commercial. - //doom2wad = malloc(strlen(doomwaddir)+1+9+1); - //sprintf(doom2wad, "%s/doom2.wad", doomwaddir); + // Commercial. + //doom2wad = malloc(strlen(doomwaddir)+1+9+1); + //sprintf(doom2wad, "%s/doom2.wad", doomwaddir); - // Retail. - //doomuwad = malloc(strlen(doomwaddir)+1+8+1); - //sprintf(doomuwad, "%s/doomu.wad", doomwaddir); - - // Registered. - doomwad = malloc(strlen(doomwaddir)+1+18+1); - sprintf(doomwad, "%s/doom.wad", doomwaddir); + // Retail. + //doomuwad = malloc(strlen(doomwaddir)+1+8+1); + //sprintf(doomuwad, "%s/doomu.wad", doomwaddir); - // Shareware. - //doom1wad = malloc(strlen(doomwaddir)+1+9+1); - //sprintf(doom1wad, "%s/doom1.wad", doomwaddir); + // Registered. + doomwad = malloc(strlen(doomwaddir) + 1 + 18 + 1); + sprintf(doomwad, "%s/doom.wad", doomwaddir); - // Bug, dear Shawn. - // Insufficient malloc, caused spurious realloc errors. - //plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1); - //sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir); + // Shareware. + //doom1wad = malloc(strlen(doomwaddir)+1+9+1); + //sprintf(doom1wad, "%s/doom1.wad", doomwaddir); - //tntwad = malloc(strlen(doomwaddir)+1+9+1); - //sprintf(tntwad, "%s/tnt.wad", doomwaddir); + // Bug, dear Shawn. + // Insufficient malloc, caused spurious realloc errors. + //plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1); + //sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir); + //tntwad = malloc(strlen(doomwaddir)+1+9+1); + //sprintf(tntwad, "%s/tnt.wad", doomwaddir); - // French stuff. - //doom2fwad = malloc(strlen(doomwaddir)+1+10+1); - //sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir); + // French stuff. + //doom2fwad = malloc(strlen(doomwaddir)+1+10+1); + //sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir); -/* + /* home = getenv("HOME"); if (!home) I_Error("Please set $HOME to your home directory"); sprintf(basedefault, "%s/.doomrc", home); */ - if (M_CheckParm ("-shdev")) - { - gamemode = shareware; - devparm = true; - D_AddFile (DEVDATA"doom1.wad"); - D_AddFile (DEVMAPS"data_se/texture1.lmp"); - D_AddFile (DEVMAPS"data_se/pnames.lmp"); - strcpy (basedefault,DEVDATA"default.cfg"); - return; - } + if (M_CheckParm("-shdev")) + { + gamemode = shareware; + devparm = true; + D_AddFile(DEVDATA "doom1.wad"); + D_AddFile(DEVMAPS "data_se/texture1.lmp"); + D_AddFile(DEVMAPS "data_se/pnames.lmp"); + strcpy(basedefault, DEVDATA "default.cfg"); + return; + } - if (M_CheckParm ("-regdev")) - { - gamemode = registered; - devparm = true; - D_AddFile (DEVDATA"doom.wad"); - D_AddFile (DEVMAPS"data_se/texture1.lmp"); - D_AddFile (DEVMAPS"data_se/texture2.lmp"); - D_AddFile (DEVMAPS"data_se/pnames.lmp"); - strcpy (basedefault,DEVDATA"default.cfg"); - return; - } + if (M_CheckParm("-regdev")) + { + gamemode = registered; + devparm = true; + D_AddFile(DEVDATA "doom.wad"); + D_AddFile(DEVMAPS "data_se/texture1.lmp"); + D_AddFile(DEVMAPS "data_se/texture2.lmp"); + D_AddFile(DEVMAPS "data_se/pnames.lmp"); + strcpy(basedefault, DEVDATA "default.cfg"); + return; + } - if (M_CheckParm ("-comdev")) - { - gamemode = commercial; - devparm = true; - /* I don't bother + if (M_CheckParm("-comdev")) + { + gamemode = commercial; + devparm = true; + /* I don't bother if(plutonia) D_AddFile (DEVDATA"plutonia.wad"); else if(tnt) D_AddFile (DEVDATA"tnt.wad"); else*/ - D_AddFile (DEVDATA"doom2.wad"); - - D_AddFile (DEVMAPS"cdata/texture1.lmp"); - D_AddFile (DEVMAPS"cdata/pnames.lmp"); - strcpy (basedefault,DEVDATA"default.cfg"); - return; - } + D_AddFile(DEVDATA "doom2.wad"); -/* + D_AddFile(DEVMAPS "cdata/texture1.lmp"); + D_AddFile(DEVMAPS "cdata/pnames.lmp"); + strcpy(basedefault, DEVDATA "default.cfg"); + return; + } + + /* if ( 0 == access (doom2fwad,R_OK) ) { gamemode = commercial; @@ -675,7 +634,7 @@ void IdentifyVersion (void) } */ -/* + /* if ( 0 == access (doom2wad,R_OK) ) { gamemode = commercial; @@ -685,7 +644,7 @@ void IdentifyVersion (void) } */ -/* + /* if ( 0 == access (doomuwad,R_OK) ) { printf("%s\n", doomuwad); @@ -695,14 +654,14 @@ void IdentifyVersion (void) } */ - if ( 0 == access (doomwad,R_OK) ) - { - gamemode = registered; - D_AddFile (doomwad); - return; - } + if (0 == access(doomwad, R_OK)) + { + gamemode = registered; + D_AddFile(doomwad); + return; + } -/* + /* if ( 0 == access (doom1wad,R_OK) ) { printf("%s\n", doom1wad); @@ -712,143 +671,142 @@ void IdentifyVersion (void) } */ - Print(L"Game mode indeterminate.\n"); - gamemode = indetermined; + Print(L"Game mode indeterminate.\n"); + gamemode = indetermined; - // We don't abort. Let's see what the PWAD contains. - //exit(1); - //I_Error ("Game mode indeterminate\n"); + // We don't abort. Let's see what the PWAD contains. + //exit(1); + //I_Error ("Game mode indeterminate\n"); } // // Find a Response File // -void FindResponseFile (void) +void FindResponseFile(void) { - int i; -#define MAXARGVS 100 - - for (i = 1;i < myargc;i++) - if (myargv[i][0] == '@') - { - FILE * handle; - int size; - int k; - int index; - int indexinfile; - char *infile; - char *file; - char *moreargs[20]; - char *firstargv; - - // READ THE RESPONSE FILE INTO MEMORY - handle = fopen (&myargv[i][1],"rb"); - if (!handle) - { - printf("\nNo such response file!"); - exit(1); - } - printf("Found response file %s!\n",&myargv[i][1]); - fseek (handle,0,SEEK_END); - size = ftell(handle); - fseek (handle,0,SEEK_SET); - file = malloc (size); - fread (file,size,1,handle); - fclose (handle); - - // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG - for (index = 0,k = i+1; k < myargc; k++) - moreargs[index++] = myargv[k]; - - firstargv = myargv[0]; - myargv = malloc(sizeof(char *)*MAXARGVS); - memset(myargv,0,sizeof(char *)*MAXARGVS); - myargv[0] = firstargv; - - infile = file; - indexinfile = k = 0; - indexinfile++; // SKIP PAST ARGV[0] (KEEP IT) - do - { - myargv[indexinfile++] = infile+k; - while(k < size && - ((*(infile+k)>= ' '+1) && (*(infile+k)<='z'))) - k++; - *(infile+k) = 0; - while(k < size && - ((*(infile+k)<= ' ') || (*(infile+k)>'z'))) - k++; - } while(k < size); - - for (k = 0;k < index;k++) - myargv[indexinfile++] = moreargs[k]; - myargc = indexinfile; - - // DISPLAY ARGS - printf("%d command-line args:\n",myargc); - for (k=1;k= ' ' + 1) && (*(infile + k) <= 'z'))) + k++; + *(infile + k) = 0; + while (k < size && + ((*(infile + k) <= ' ') || (*(infile + k) > 'z'))) + k++; + } while (k < size); + + for (k = 0; k < index; k++) + myargv[indexinfile++] = moreargs[k]; + myargc = indexinfile; + + // DISPLAY ARGS + printf("%d command-line args:\n", myargc); + for (k = 1; k < myargc; k++) + printf("%s\n", myargv[k]); + + break; + } } - // // D_DoomMain // -void D_DoomMain (void) +void D_DoomMain(void) { - int p; - char file[256]; - - FindResponseFile (); - - IdentifyVersion (); - - setbuf (stdout, NULL); - modifiedgame = false; - - nomonsters = M_CheckParm ("-nomonsters"); - respawnparm = M_CheckParm ("-respawn"); - fastparm = M_CheckParm ("-fast"); - devparm = M_CheckParm ("-devparm"); - if (M_CheckParm ("-altdeath")) - deathmatch = 2; - else if (M_CheckParm ("-deathmatch")) - deathmatch = 1; - - switch ( gamemode ) - { - case retail: - sprintf (title, - " " - "The Ultimate DOOM Startup v%i.%i" - " ", - VERSION/100,VERSION%100); - break; - case shareware: - sprintf (title, - " " - "DOOM Shareware Startup v%i.%i" - " ", - VERSION/100,VERSION%100); - break; - case registered: - sprintf (title, - " " - "DOOM Registered Startup v%i.%i" - " ", - VERSION/100,VERSION%100); - break; - case commercial: - sprintf (title, - " " - "DOOM 2: Hell on Earth v%i.%i" - " ", - VERSION/100,VERSION%100); - break; -/*FIXME + int p; + char file[256]; + + FindResponseFile(); + + IdentifyVersion(); + + setbuf(stdout, NULL); + modifiedgame = false; + + nomonsters = M_CheckParm("-nomonsters"); + respawnparm = M_CheckParm("-respawn"); + fastparm = M_CheckParm("-fast"); + devparm = M_CheckParm("-devparm"); + if (M_CheckParm("-altdeath")) + deathmatch = 2; + else if (M_CheckParm("-deathmatch")) + deathmatch = 1; + + switch (gamemode) + { + case retail: + sprintf(title, + " " + "The Ultimate DOOM Startup v%i.%i" + " ", + VERSION / 100, VERSION % 100); + break; + case shareware: + sprintf(title, + " " + "DOOM Shareware Startup v%i.%i" + " ", + VERSION / 100, VERSION % 100); + break; + case registered: + sprintf(title, + " " + "DOOM Registered Startup v%i.%i" + " ", + VERSION / 100, VERSION % 100); + break; + case commercial: + sprintf(title, + " " + "DOOM 2: Hell on Earth v%i.%i" + " ", + VERSION / 100, VERSION % 100); + break; + /*FIXME case pack_plut: sprintf (title, " " @@ -864,312 +822,303 @@ void D_DoomMain (void) VERSION/100,VERSION%100); break; */ - default: - sprintf (title, - " " - "Public DOOM - v%i.%i" - " ", - VERSION/100,VERSION%100); - break; - } - - printf ("%s\n",title); + default: + sprintf(title, + " " + "Public DOOM - v%i.%i" + " ", + VERSION / 100, VERSION % 100); + break; + } - if (devparm) - printf(D_DEVSTR); - - if (M_CheckParm("-cdrom")) - { - printf(D_CDROM); - mkdir("FS0:\\doomdata",0); - strcpy (basedefault,"FS0:/doomdata/default.cfg"); - } - - // turbo option - if ( (p=M_CheckParm ("-turbo")) ) - { - int scale = 200; - extern int forwardmove[2]; - extern int sidemove[2]; - - if (p 400) - scale = 400; - printf ("turbo scale: %i%%\n",scale); - forwardmove[0] = forwardmove[0]*scale/100; - forwardmove[1] = forwardmove[1]*scale/100; - sidemove[0] = sidemove[0]*scale/100; - sidemove[1] = sidemove[1]*scale/100; - } - - // add any files specified on the command line with -file wadfile - // to the wad list - // - // convenience hack to allow -wart e m to add a wad file - // prepend a tilde to the filename so wadfile will be reloadable - p = M_CheckParm ("-wart"); - if (p) - { - myargv[p][4] = 'p'; // big hack, change to -warp + printf("%s\n", title); - // Map name handling. - switch (gamemode ) + if (devparm) + printf(D_DEVSTR); + + if (M_CheckParm("-cdrom")) { - case shareware: - case retail: - case registered: - sprintf (file,"~"DEVMAPS"E%cM%c.wad", - myargv[p+1][0], myargv[p+2][0]); - printf("Warping to Episode %s, Map %s.\n", - myargv[p+1],myargv[p+2]); - break; - - case commercial: - default: - p = atoi (myargv[p+1]); - if (p<10) - sprintf (file,"~"DEVMAPS"cdata/map0%i.wad", p); - else - sprintf (file,"~"DEVMAPS"cdata/map%i.wad", p); - break; + printf(D_CDROM); + mkdir("FS0:/doomdata", 0); + strcpy(basedefault, "FS0:/doomdata/default.cfg"); } - D_AddFile (file); - } - - p = M_CheckParm ("-file"); - if (p) - { - // the parms after p are wadfile/lump names, - // until end of parms or another - preceded parm - modifiedgame = true; // homebrew levels - while (++p != myargc && myargv[p][0] != '-') - D_AddFile (myargv[p]); - } - p = M_CheckParm ("-playdemo"); + // turbo option + if ((p = M_CheckParm("-turbo"))) + { + int scale = 200; + extern int forwardmove[2]; + extern int sidemove[2]; + + if (p < myargc - 1) + scale = atoi(myargv[p + 1]); + if (scale < 10) + scale = 10; + if (scale > 400) + scale = 400; + printf("turbo scale: %i%%\n", scale); + forwardmove[0] = forwardmove[0] * scale / 100; + forwardmove[1] = forwardmove[1] * scale / 100; + sidemove[0] = sidemove[0] * scale / 100; + sidemove[1] = sidemove[1] * scale / 100; + } - if (!p) - p = M_CheckParm ("-timedemo"); + // add any files specified on the command line with -file wadfile + // to the wad list + // + // convenience hack to allow -wart e m to add a wad file + // prepend a tilde to the filename so wadfile will be reloadable + p = M_CheckParm("-wart"); + if (p) + { + myargv[p][4] = 'p'; // big hack, change to -warp + + // Map name handling. + switch (gamemode) + { + case shareware: + case retail: + case registered: + sprintf(file, "~" DEVMAPS "E%cM%c.wad", + myargv[p + 1][0], myargv[p + 2][0]); + printf("Warping to Episode %s, Map %s.\n", + myargv[p + 1], myargv[p + 2]); + break; + + case commercial: + default: + p = atoi(myargv[p + 1]); + if (p < 10) + sprintf(file, "~" DEVMAPS "cdata/map0%i.wad", p); + else + sprintf(file, "~" DEVMAPS "cdata/map%i.wad", p); + break; + } + D_AddFile(file); + } - if (p && p < myargc-1) - { - sprintf (file,"%s.lmp", myargv[p+1]); - D_AddFile (file); - printf("Playing demo %s.lmp.\n",myargv[p+1]); - } - - // get skill / episode / map from parms - startskill = sk_medium; - startepisode = 1; - startmap = 1; - autostart = false; - - - p = M_CheckParm ("-skill"); - if (p && p < myargc-1) - { - startskill = myargv[p+1][0]-'1'; - autostart = true; - } + p = M_CheckParm("-file"); + if (p) + { + // the parms after p are wadfile/lump names, + // until end of parms or another - preceded parm + modifiedgame = true; // homebrew levels + while (++p != myargc && myargv[p][0] != '-') + D_AddFile(myargv[p]); + } - p = M_CheckParm ("-episode"); - if (p && p < myargc-1) - { - startepisode = myargv[p+1][0]-'0'; + p = M_CheckParm("-playdemo"); + + if (!p) + p = M_CheckParm("-timedemo"); + + if (p && p < myargc - 1) + { + sprintf(file, "%s.lmp", myargv[p + 1]); + D_AddFile(file); + printf("Playing demo %s.lmp.\n", myargv[p + 1]); + } + + // get skill / episode / map from parms + startskill = sk_medium; + startepisode = 1; startmap = 1; - autostart = true; - } - - p = M_CheckParm ("-timer"); - if (p && p < myargc-1 && deathmatch) - { - int time; - time = atoi(myargv[p+1]); - printf("Levels will end after %d minute",time); - if (time>1) - printf("s"); - printf(".\n"); - } + autostart = false; - p = M_CheckParm ("-avg"); - if (p && p < myargc-1 && deathmatch) - printf("Austin Virtual Gaming: Levels will end after 20 minutes\n"); + p = M_CheckParm("-skill"); + if (p && p < myargc - 1) + { + startskill = myargv[p + 1][0] - '1'; + autostart = true; + } - p = M_CheckParm ("-warp"); - if (p && p < myargc-1) - { - if (gamemode == commercial) - startmap = atoi (myargv[p+1]); - else + p = M_CheckParm("-episode"); + if (p && p < myargc - 1) { - startepisode = myargv[p+1][0]-'0'; - startmap = myargv[p+2][0]-'0'; + startepisode = myargv[p + 1][0] - '0'; + startmap = 1; + autostart = true; } - autostart = true; - } - - // init subsystems - printf ("V_Init: allocate screens.\n"); - V_Init (); - printf ("M_LoadDefaults: Load system defaults.\n"); - M_LoadDefaults (); // load before initing other systems + p = M_CheckParm("-timer"); + if (p && p < myargc - 1 && deathmatch) + { + int time; + time = atoi(myargv[p + 1]); + printf("Levels will end after %d minute", time); + if (time > 1) + printf("s"); + printf(".\n"); + } + + p = M_CheckParm("-avg"); + if (p && p < myargc - 1 && deathmatch) + printf("Austin Virtual Gaming: Levels will end after 20 minutes\n"); + + p = M_CheckParm("-warp"); + if (p && p < myargc - 1) + { + if (gamemode == commercial) + startmap = atoi(myargv[p + 1]); + else + { + startepisode = myargv[p + 1][0] - '0'; + startmap = myargv[p + 2][0] - '0'; + } + autostart = true; + } - printf ("Z_Init: Init zone memory allocation daemon. \n"); - Z_Init (); + // init subsystems + printf("V_Init: allocate screens.\n"); + V_Init(); - printf ("W_Init: Init WADfiles.\n"); - W_InitMultipleFiles (wadfiles); - + printf("M_LoadDefaults: Load system defaults.\n"); + M_LoadDefaults(); // load before initing other systems - // Check for -file in shareware - if (modifiedgame) - { - // These are the lumps that will be checked in IWAD, - // if any one is not present, execution will be aborted. - char name[23][8]= + printf("Z_Init: Init zone memory allocation daemon. \n"); + Z_Init(); + + printf("W_Init: Init WADfiles.\n"); + W_InitMultipleFiles(wadfiles); + + // Check for -file in shareware + if (modifiedgame) { - "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9", - "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9", - "dphoof","bfgga0","heada1","cybra1","spida1d1" - }; - int i; - - if ( gamemode == shareware) - I_Error("\nYou cannot -file with the shareware " - "version. Register!"); - - // Check for fake IWAD with right name, - // but w/o all the lumps of the registered version. - if (gamemode == registered) - for (i = 0;i < 23; i++) - if (W_CheckNumForName(name[i])<0) - I_Error("\nThis is not the registered version."); - } - - // Iff additonal PWAD files are used, print modified banner - if (modifiedgame) - { - /*m*/printf ( - "===========================================================================\n" - "ATTENTION: This version of DOOM has been modified. If you would like to\n" - "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n" - " You will not receive technical support for modified games.\n" - " press enter to continue\n" - "===========================================================================\n" - ); - getchar (); - } - + // These are the lumps that will be checked in IWAD, + // if any one is not present, execution will be aborted. + char name[23][8] = + { + "e2m1", "e2m2", "e2m3", "e2m4", "e2m5", "e2m6", "e2m7", "e2m8", "e2m9", + "e3m1", "e3m3", "e3m3", "e3m4", "e3m5", "e3m6", "e3m7", "e3m8", "e3m9", + "dphoof", "bfgga0", "heada1", "cybra1", "spida1d1"}; + int i; + + if (gamemode == shareware) + I_Error("\nYou cannot -file with the shareware " + "version. Register!"); + + // Check for fake IWAD with right name, + // but w/o all the lumps of the registered version. + if (gamemode == registered) + for (i = 0; i < 23; i++) + if (W_CheckNumForName(name[i]) < 0) + I_Error("\nThis is not the registered version."); + } - // Check and print which version is executed. - switch ( gamemode ) - { - case shareware: - case indetermined: - printf ( - "===========================================================================\n" - " Shareware!\n" - "===========================================================================\n" - ); - break; - case registered: - case retail: - case commercial: - printf ( - "===========================================================================\n" - " Commercial product - do not distribute!\n" - " Please report software piracy to the SPA: 1-800-388-PIR8\n" - "===========================================================================\n" - ); - break; - - default: - // Ouch. - break; - } + // Iff additonal PWAD files are used, print modified banner + if (modifiedgame) + { + /*m*/ printf( + "===========================================================================\n" + "ATTENTION: This version of DOOM has been modified. If you would like to\n" + "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n" + " You will not receive technical support for modified games.\n" + " press enter to continue\n" + "===========================================================================\n"); + getchar(); + } + + // Check and print which version is executed. + switch (gamemode) + { + case shareware: + case indetermined: + printf( + "===========================================================================\n" + " Shareware!\n" + "===========================================================================\n"); + break; + case registered: + case retail: + case commercial: + printf( + "===========================================================================\n" + " Commercial product - do not distribute!\n" + " Please report software piracy to the SPA: 1-800-388-PIR8\n" + "===========================================================================\n"); + break; + + default: + // Ouch. + break; + } - printf ("M_Init: Init miscellaneous info.\n"); - M_Init (); + printf("M_Init: Init miscellaneous info.\n"); + M_Init(); - printf ("R_Init: Init DOOM refresh daemon - "); - R_Init (); + printf("R_Init: Init DOOM refresh daemon - "); + R_Init(); - printf ("\nP_Init: Init Playloop state.\n"); - P_Init (); + printf("\nP_Init: Init Playloop state.\n"); + P_Init(); - printf ("I_Init: Setting up machine state.\n"); - I_Init (); + printf("I_Init: Setting up machine state.\n"); + I_Init(); - printf ("D_CheckNetGame: Checking network game status.\n"); - D_CheckNetGame (); + printf("D_CheckNetGame: Checking network game status.\n"); + D_CheckNetGame(); - printf ("S_Init: Setting up sound.\n"); - S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ ); + printf("S_Init: Setting up sound.\n"); + S_Init(snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/); - printf ("HU_Init: Setting up heads up display.\n"); - HU_Init (); + printf("HU_Init: Setting up heads up display.\n"); + HU_Init(); - printf ("ST_Init: Init status bar.\n"); - ST_Init (); + printf("ST_Init: Init status bar.\n"); + ST_Init(); - // check for a driver that wants intermission stats - p = M_CheckParm ("-statcopy"); - if (p && p #include "doomdef.h" #include "Uefi.h" #include #include +#include +#include EFI_AUDIO_IO_PROTOCOL *audioIo; -EFI_AUDIO_IO_PROTOCOL_PORT* outputPorts = NULL; +EFI_AUDIO_IO_PROTOCOL_PORT *outputPorts = NULL; +EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL; UINTN outputCount = 0; UINTN outputToUse = 0; boolean outputFound = 0; UINTN soundFreq = 44100; +STATIC CHAR16 *DefaultDevices[EfiAudioIoDeviceMaximum] = { L"Line", L"Speaker", L"Headphones", L"SPDIF", L"Mic", L"HDMI", L"Other" }; +STATIC CHAR16 *Locations[EfiAudioIoLocationMaximum] = { L"N/A", L"rear", L"front", L"left", L"right", L"top", L"bottom", L"other" }; +STATIC CHAR16 *Surfaces[EfiAudioIoSurfaceMaximum] = { L"external", L"internal", L"other" }; void I_InitSound() { - EFI_STATUS status = gBS->LocateProtocol(&gEfiAudioIoProtocolGuid,NULL,(void**) audioIo); - if (EFI_ERROR(status)) + UINTN HandlesCount = 0; + EFI_HANDLE* handles = malloc(sizeof(EFI_HANDLE) * 256); + EFI_STATUS status1 = gBS->LocateHandleBuffer(ByProtocol,&gEfiAudioIoProtocolGuid,NULL,&HandlesCount,&handles); + if (!EFI_ERROR(status1)) { - printf("Sound driver not found.\n"); - } - else - { - outputPorts = (EFI_AUDIO_IO_PROTOCOL_PORT*)calloc(sizeof(outputPorts), 256); - status = audioIo->GetOutputs(audioIo,outputPorts,&outputCount); - if (EFI_ERROR(status)) - { - gST->ConOut->OutputString(gST->ConOut,L"Audio driver not found\n"); - } - else + for (UINTN h = 0; h < HandlesCount; h++) { - outputFound = 1; - for (int i = 0; i < outputCount; i++) + // Open Audio I/O protocol. + status1 = gBS->HandleProtocol(handles[h], &gEfiAudioIoProtocolGuid, (VOID**)&audioIo); + // ASSERT_EFI_ERROR(status1); + if (EFI_ERROR(status1)) + continue; + + // Get device path. + status1 = gBS->HandleProtocol(handles[h], &gEfiDevicePathProtocolGuid, (VOID**)&DevicePath); + // ASSERT_EFI_ERROR(status1); + if (EFI_ERROR(status1)) + continue; + + // Get output devices. + status1 = audioIo->GetOutputs(audioIo, &outputPorts, &outputCount); + //ASSERT_EFI_ERROR(status1); + if (EFI_ERROR(status1)) + continue; + for (int o = 0; o < outputCount; o++) { - if (outputPorts[i].Device == EfiAudioIoDeviceSpeaker - && outputPorts[i].Location == EfiAudioIoLocationRear) + Print(L"Device Num: %d, output location: %s, output surface: %s, output device: %s\n", + o,Locations[outputPorts[o].Location], Surfaces[outputPorts[o].Surface], DefaultDevices[outputPorts[o].Device]); + Print(L"Supported Freqs: "); + if (outputPorts[o].SupportedFreqs & EfiAudioIoFreq11kHz) printf("%d, ",11025); + if (outputPorts[o].SupportedFreqs & EfiAudioIoFreq22kHz) printf("%d, ",22050); + if (outputPorts[o].SupportedFreqs & EfiAudioIoFreq44kHz) printf("%d, ",44100); + if (outputPorts[o].SupportedFreqs & EfiAudioIoFreq48kHz) printf("%d\n",48000); + if (outputPorts[o].Device == EfiAudioIoDeviceLine + || outputPorts[o].Device == EfiAudioIoDeviceSpeaker) + if (outputFound != true) { - outputToUse = i; - if (outputPorts[i].SupportedFreqs & EfiAudioIoFreq11kHz) soundFreq = 11025; - else soundFreq = 44100; + if (outputPorts[o].SupportedFreqs & EfiAudioIoFreq11kHz) soundFreq = 11025; + else soundFreq = 44100; + + outputToUse = o; + outputFound = true; + printf("Selected output.\n"); } } } } + else + { + printf("Sound not found.\n"); + } + } void I_UpdateSound(void) { - } void I_SubmitSound(void) { - } void I_ShutdownSound(void) { - + if (audioIo) audioIo->StopPlayback(audioIo); } - // // SFX I/O // void I_SetChannels() { - } -int I_GetSfxLumpNum(sfxinfo_t* sfx) +int I_GetSfxLumpNum(sfxinfo_t *sfx) { char namebuf[9]; sprintf(namebuf, "ds%s", sfx->name); return W_GetNumForName(namebuf); } -#define SAMPLECOUNT 512 -void* -getsfx -( char* sfxname, - int* len ) +#define SAMPLECOUNT 512 +void * +getsfx(char *sfxname, + int *len) { - unsigned char* sfx; - unsigned char* paddedsfx; - int i; - int size; - int paddedsize; - char name[20]; - int sfxlump; + unsigned char *sfx; + unsigned char *paddedsfx; + int i; + int size; + int paddedsize; + char name[20]; + int sfxlump; - // Get the sound data from the WAD, allocate lump // in zone memory. sprintf(name, "ds%s", sfxname); @@ -132,87 +157,115 @@ getsfx // I do not do runtime patches to that // variable. Instead, we will use a // default sound for replacement. - if ( W_CheckNumForName(name) == -1 ) - sfxlump = W_GetNumForName("dspistol"); + if (W_CheckNumForName(name) == -1) + sfxlump = W_GetNumForName("dspistol"); else - sfxlump = W_GetNumForName(name); - - size = W_LumpLength( sfxlump ); + sfxlump = W_GetNumForName(name); + + size = W_LumpLength(sfxlump); // Debug. // fprintf( stderr, "." ); //fprintf( stderr, " -loading %s (lump %d, %d bytes)\n", // sfxname, sfxlump, size ); //fflush( stderr ); - - sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC ); + + sfx = (unsigned char *)W_CacheLumpNum(sfxlump, PU_STATIC); // Pads the sound effect out to the mixing buffer size. // The original realloc would interfere with zone memory. - paddedsize = ((size-8 + (SAMPLECOUNT-1)) / SAMPLECOUNT) * SAMPLECOUNT; + paddedsize = ((size - 8 + (SAMPLECOUNT - 1)) / SAMPLECOUNT) * SAMPLECOUNT; // Allocate from zone memory. - paddedsfx = (unsigned char*)Z_Malloc( paddedsize+8, PU_STATIC, 0 ); + paddedsfx = (unsigned char *)Z_Malloc(paddedsize + 8, PU_STATIC, 0); // ddt: (unsigned char *) realloc(sfx, paddedsize+8); // This should interfere with zone memory handling, // which does not kick in in the soundserver. // Now copy and pad. - memcpy( paddedsfx, sfx, size ); - for (i=size ; iSetupPlayback(audioIo, outputToUse, realvol, EfiAudioIoFreq44kHz, EfiAudioIoBits16, 2); + audioIo->StartPlaybackAsync(audioIo, sfxdata, lumplength * 4, 8 * 4, I_FinishedSound, (void*)calldata); // Blast it out unprocessed. + return; + S_sfx[id].data = getsfx(S_sfx[id].name, length); + EFI_STATUS stats; if (audioIo) { - if (soundFreq == 11025) audioIo->SetupPlayback(audioIo,outputToUse,realvol,EfiAudioIoFreq11kHz,EfiAudioIoBits16,2); - else audioIo->SetupPlayback(audioIo,outputToUse,realvol,EfiAudioIoFreq44kHz,EfiAudioIoBits16,2); + if (soundFreq == 11025) + audioIo->SetupPlayback(audioIo, outputToUse, realvol, EfiAudioIoFreq11kHz, EfiAudioIoBits16, 2); + else + audioIo->SetupPlayback(audioIo, outputToUse, realvol, EfiAudioIoFreq44kHz, EfiAudioIoBits16, 2); if (soundFreq == 44100) { // Expand the sample data. - signed char* expandedSampleData = calloc(1,(*length) * 4); - signed char* sfxdata = S_sfx[id].data; - for (int sampleByte = 0; sampleByte < *length; sampleByte++) + char *expandedSampleData = calloc(1, (sampLength) * 4); + char *sfxdata = sampdata; + for (int sampleByte = 0; sampleByte < sampLength; sampleByte++) { - expandedSampleData[sampleByte * 4] = - expandedSampleData[sampleByte * 4 + 1] = + expandedSampleData[sampleByte * 4] = + expandedSampleData[sampleByte * 4 + 1] = expandedSampleData[sampleByte * 4 + 2] = expandedSampleData[sampleByte * 4 + 3] = sfxdata[sampleByte]; } - audioIo->StartPlaybackAsync(audioIo,expandedSampleData,*length * 4,0,NULL,NULL); // Blast it out processed. + stats = audioIo->StartPlaybackAsync(audioIo, expandedSampleData, sampLength * 4, 0, I_FinishedSound, (void*)calldata); // Blast it out processed. + if (EFI_ERROR(stats)) printf("Failed to play sound.\n"); + } + else + { + stats = audioIo->StartPlaybackAsync(audioIo, sampdata, sampLength, 0, I_FinishedSound, (void*)calldata); // Blast it out unprocessed. + if (EFI_ERROR(stats)) printf("Failed to play sound.\n"); } - else audioIo->StartPlaybackAsync(audioIo,S_sfx[id].data,*length,0,NULL,NULL); // Blast it out unprocessed. } return id; } - void I_StopSound(int handle) { - } // Called by S_*() functions @@ -225,45 +278,36 @@ int I_SoundIsPlaying(int handle) // Updates the volume, separation, // and pitch of a sound channel. -void -I_UpdateSoundParams -( int handle, - int vol, - int sep, - int pitch ) +void I_UpdateSoundParams(int handle, + int vol, + int sep, + int pitch) { - } - // // MUSIC I/O // void I_InitMusic(void) { - } void I_ShutdownMusic(void) { - } // Volume. void I_SetMusicVolume(int volume) { - } // PAUSE game handling. void I_PauseSong(int handle) { - } void I_ResumeSong(int handle) { - } // Registers a song handle to song data. @@ -276,23 +320,17 @@ int I_RegisterSong(void *data) // plays a song, and when the song is done, // starts playing it again in an endless loop. // Horrible thing to do, considering. -void -I_PlaySong -( int handle, - int looping ) +void I_PlaySong(int handle, + int looping) { - } // Stops a song over 3 seconds. void I_StopSong(int handle) { - } // See above (register), then think backwards void I_UnRegisterSong(int handle) { - } - diff --git a/uefidoom/efi/i_system.c b/uefidoom/efi/i_system.c index 8f138de..dded7be 100644 --- a/uefidoom/efi/i_system.c +++ b/uefidoom/efi/i_system.c @@ -146,24 +146,27 @@ extern boolean demorecording; void I_Error (char *error, ...) { - va_list argptr; + // [Cacodemon345] First, shut everything down. Specially, we need to exit back to text mode. + // Shutdown. Here might be other errors. + if (demorecording) + G_CheckDemoStatus(); + + D_QuitNetGame (); + I_ShutdownGraphics(); + I_ShutdownSound(); // Message first. + va_list argptr; va_start (argptr,error); printf ("Error: "); vprintf (error,argptr); printf ("\n"); va_end (argptr); - // Shutdown. Here might be other errors. - if (demorecording) - G_CheckDemoStatus(); - D_QuitNetGame (); - I_ShutdownGraphics(); - while(1) ; - //exit(-1); + + exit(-1); } /// diff --git a/uefidoom/efi/i_video.c b/uefidoom/efi/i_video.c index 907f226..d81fb8a 100644 --- a/uefidoom/efi/i_video.c +++ b/uefidoom/efi/i_video.c @@ -171,19 +171,21 @@ void GopBltRender(void) } } -void I_KeyNotify(EFI_KEY_DATA* keydata) +EFI_STATUS EFIAPI I_KeyNotify(EFI_KEY_DATA* keydata) { event_t event; event.type = ev_keydown; event.data1 = keydata->Key.UnicodeChar; D_PostEvent(&event); + return EFI_SUCCESS; } -void I_ScanKeyNotify(EFI_KEY_DATA* keydata) +EFI_STATUS EFIAPI I_ScanKeyNotify(EFI_KEY_DATA* keydata) { event_t event; event.type = ev_keydown; event.data1 = xlatekey(&keydata->Key); D_PostEvent(&event); + return EFI_SUCCESS; } EFI_HANDLE *NotifHandle; EFI_HANDLE *ScanNotifHandle; @@ -211,7 +213,28 @@ void I_InitGraphics (void) return; } status = gBS->HandleProtocol(gST->ConsoleInHandle,&gEfiSimplePointerProtocolGuid, (void**) &gMouseProtocol); - if (EFI_ERROR(status)) printf("Failed to initialize mouse pointer.\n"); + if (EFI_ERROR(status)) + { + status = gBS->LocateProtocol(&gEfiSimplePointerProtocolGuid,NULL, (void**) &gMouseProtocol); + if (EFI_ERROR(status)) + { + EFI_HANDLE* handles; + UINTN count; + status = gBS->LocateHandleBuffer(ByProtocol,&gEfiSimplePointerProtocolGuid,NULL,&count,&handles); + if (!EFI_ERROR(status)) + { + for (int HandleCountIndex = 0; HandleCountIndex < count; HandleCountIndex++) + { + if (EFI_ERROR(gBS->HandleProtocol(handles[HandleCountIndex],&gEfiSimplePointerProtocolGuid,(void**)&gMouseProtocol))) + { + continue; + } + else break; + } + } + else printf("Failed to initialize mouse pointer.\n"); + } + } status = gBS->HandleProtocol(gST->ConsoleInHandle,&gEfiSimpleTextInputExProtocolGuid,(void**) &gInputEx); if (EFI_ERROR(status)) printf("Failed to initialize Extended Input protocol.\n"); else @@ -319,7 +342,7 @@ void I_ShutdownGraphics(void) gGOP = NULL; gRenderFunc = NULL; - gST->ConOut->SetMode(gST->ConOut,0); + gST->ConOut->Reset(gST->ConOut,TRUE); gST->ConOut->ClearScreen(gST->ConOut); gST->ConOut->EnableCursor(gST->ConOut, TRUE); } diff --git a/uefidoom/m_argv.c b/uefidoom/m_argv.c index 1595671..5cf8356 100644 --- a/uefidoom/m_argv.c +++ b/uefidoom/m_argv.c @@ -25,6 +25,7 @@ rcsid[] = "$Id: m_argv.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; #include +#include int myargc; char** myargv;