| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- /*
- ** Command & Conquer Red Alert(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /* $Header: /counterstrike/STARTUP.CPP 6 3/15/97 7:18p Steve_tall $ */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * File Name : STARTUP.CPP *
- * *
- * Programmer : Joe L. Bostic *
- * *
- * Start Date : October 3, 1994 *
- * *
- * Last Update : September 30, 1996 [JLB] *
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * Prog_End -- Cleans up library systems in prep for game exit. *
- * main -- Initial startup routine (preps library systems). *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "function.h"
- #include <conio.h>
- #include <io.h>
- #ifdef WIN32
- #include "ccdde.h"
- #include "ipx95.h"
- #endif //WIN32
- #ifdef MCIMPEG // Denzil 6/15/98
- #include "mcimovie.h"
- #endif
- #ifdef WOLAPI_INTEGRATION
- //#include "WolDebug.h"
- #endif
- bool Read_Private_Config_Struct(FileClass & file, NewConfigType * config);
- void Print_Error_End_Exit(char * string);
- void Print_Error_Exit(char * string);
- #ifdef WIN32
- //WinTimerClass * WinTimer;
- extern void Create_Main_Window ( HANDLE instance , int command_show , int width , int height);
- extern bool RA95AlreadyRunning;
- HINSTANCE ProgramInstance;
- void Check_Use_Compressed_Shapes (void);
- void Read_Setup_Options(RawFileClass *config_file);
- bool VideoBackBufferAllowed = true;
- #else
- BOOL Init_Timer_System(unsigned int freq, int partial = FALSE);
- BOOL Remove_Timer_System(VOID);
- #endif //WIN32
- const char* Game_Registry_Key();
- #if (ENGLISH)
- #define WINDOW_NAME "Red Alert"
- #endif
- #if (FRENCH)
- #define WINDOW_NAME "Alerte Rouge"
- #endif
- #if (GERMAN)
- #define WINDOW_NAME "Alarmstufe Rot"
- #endif
- /***********************************************************************************************
- * main -- Initial startup routine (preps library systems). *
- * *
- * This is the routine that is first called when the program starts up. It basically *
- * handles the command line parsing and setting up library systems. *
- * *
- * INPUT: argc -- Number of command line arguments. *
- * *
- * argv -- Pointer to array of command line argument strings. *
- * *
- * OUTPUT: Returns with execution failure code (if any). *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 03/20/1995 JLB : Created. *
- *=============================================================================================*/
- #ifdef WIN32
- //int PASCAL WinMain(HINSTANCE, HINSTANCE, char *, int )
- int PASCAL WinMain ( HINSTANCE instance , HINSTANCE , char * command_line , int command_show )
- #else //WIN32
- int main(int argc, char * argv[])
- #endif //WIN32
- {
- #ifdef WIN32
- #ifndef MPEGMOVIE // Denzil 6/10/98
- DDSCAPS surface_capabilities;
- #endif
- /*
- ** First thing to do is check if there is another instance of Red Alert already running
- ** and if so, switch to the existing instance and terminate ourselves.
- */
- SpawnedFromWChat = false;
- if (RA95AlreadyRunning) { //Set in the DDEServer constructor
- //MessageBox (NULL, "Error - attempt to restart Red Alert 95 when already running.", "Red Alert", MB_ICONEXCLAMATION|MB_OK);
- HWND ccwindow;
- ccwindow = FindWindow (WINDOW_NAME, WINDOW_NAME);
- if (ccwindow) {
- SetForegroundWindow ( ccwindow );
- ShowWindow ( ccwindow, SW_RESTORE );
- }
- return (EXIT_SUCCESS);
- }
- #endif
- //printf("in program.\n");getch();
- //printf("ram free = %ld\n",Ram_Free(MEM_NORMAL));getch();
- #ifdef WIN32
- if (Ram_Free(MEM_NORMAL) < 7000000) {
- #else
- void *temp_mem = malloc (13*1024*1024);
- if (temp_mem) {
- free (temp_mem);
- }else{
- //if (Ram_Free(MEM_NORMAL) < 13000000) {
- // if (Ram_Free(MEM_NORMAL) < 3500000) {
- #endif
- printf (TEXT_NO_RAM);
- #ifndef WIN32
- printf (TEXT_USE_START_MENU);
- getch();
- #endif
- #if (0)
- /*
- ** Take a stab at finding out how much memory there is available.
- */
- for ( int mem = 13*1024*1024 ; mem >0 ; mem -=1024 ) {
- temp_mem = malloc (mem);
- if (temp_mem){
- free (temp_mem);
- printf ("Memory available: %d", mem);
- break;
- }
- }
- getch();
- #endif //(0)
- return(EXIT_FAILURE);
- }
- #ifdef WIN32
- if (strstr(command_line, "f:\\projects\\c&c0") != NULL ||
- strstr(command_line, "F:\\PROJECTS\\C&C0") != NULL) {
- MessageBox(0, "Playing off of the network is not allowed.", "Red Alert", MB_OK|MB_ICONSTOP);
- return(EXIT_FAILURE);
- }
- int argc; //Command line argument count
- unsigned command_scan;
- char command_char;
- char * argv[20]; //Pointers to command line arguments
- char path_to_exe[132];
- ProgramInstance = instance;
- /*
- ** Get the full path to the .EXE
- */
- GetModuleFileName (instance, &path_to_exe[0], 132);
- /*
- ** First argument is supposed to be a pointer to the .EXE that is running
- **
- */
- argc=1; //Set argument count to 1
- argv[0]=&path_to_exe[0]; //Set 1st command line argument to point to full path
- /*
- ** Get pointers to command line arguments just like if we were in DOS
- **
- ** The command line we get is cr/zero? terminated.
- **
- */
- command_scan=0;
- do {
- /*
- ** Scan for non-space character on command line
- */
- do {
- command_char = *( command_line+command_scan++ );
- } while ( command_char==' ' );
- if ( command_char!=0 && command_char != 13 ) {
- argv[argc++]=command_line+command_scan-1;
- /*
- ** Scan for space character on command line
- */
- do {
- command_char = *( command_line+command_scan++ );
- } while ( command_char!=' ' && command_char != 0 && command_char!=13 );
- *( command_line+command_scan-1 ) = 0;
- }
- } while ( command_char != 0 && command_char != 13 && argc<20 );
- #endif //WIN32
- /*
- ** Remember the current working directory and drive.
- */
- unsigned olddrive;
- char oldpath[PATH_MAX];
- getcwd(oldpath, sizeof(oldpath));
- _dos_getdrive(&olddrive);
- /*
- ** Change directory to the where the executable is located. Handle the
- ** case where there is no path attached to argv[0].
- */
- char drive[_MAX_DRIVE];
- char path[_MAX_PATH];
- unsigned drivecount;
- _splitpath(argv[0], drive, path, NULL, NULL);
- if (!drive[0]) {
- drive[0] = ('A' + olddrive)-1;
- }
- if (!path[0]) {
- strcpy(path, ".");
- }
- _dos_setdrive(toupper((drive[0])-'A')+1, &drivecount);
- if (path[strlen(path)-1] == '\\') {
- path[strlen(path)-1] = '\0';
- }
- chdir(path);
- #ifdef WOLAPI_INTEGRATION
- // Look for special wolapi install program, used after the patch to version 3, to install "Shared Internet Components".
- WIN32_FIND_DATA wfd;
- HANDLE hWOLSetupFile = FindFirstFile( "wolsetup.exe", &wfd );
- bool bWOLSetupFile = ( hWOLSetupFile != INVALID_HANDLE_VALUE );
- // if( bWOLSetupFile )
- // debugprint( "Found wolsetup.exe\n" );
- FindClose( hWOLSetupFile );
- // Look for special registry entry that tells us when the setup exe has done its thing.
- HKEY hKey;
- RegOpenKeyEx( HKEY_LOCAL_MACHINE, Game_Registry_Key(), 0, KEY_READ, &hKey );
- DWORD dwValue;
- DWORD dwBufSize = sizeof( DWORD );
- if( RegQueryValueEx( hKey, "WolapiInstallComplete", 0, NULL, (LPBYTE)&dwValue, &dwBufSize ) == ERROR_SUCCESS )
- {
- // debugprint( "Found WolapiInstallComplete in registry\n" );
- // Setup has finished. Delete the setup exe and remove reg key.
- if( bWOLSetupFile )
- {
- if( DeleteFile( "wolsetup.exe" ) )
- RegDeleteValue( hKey, "WolapiInstallComplete" );
- }
- else
- RegDeleteValue( hKey, "WolapiInstallComplete" );
- }
- RegCloseKey( hKey );
- // I've been having problems getting the patch to delete "conquer.eng", which is present in the game
- // directory for 1.08, but which must NOT be present for this version (Aftermath mix files provide the
- // string overrides that the 1.08 separate conquer.eng did before Aftermath).
- // Delete conquer.eng if it's found.
- if( FindFirstFile( "conquer.eng", &wfd ) != INVALID_HANDLE_VALUE )
- DeleteFile( "conquer.eng" );
- #endif
- if (Parse_Command_Line(argc, argv)) {
- #if(TEN)
- //
- // Only allow the TEN version of the game to run if the TEN
- // or AllowSoloPlayOptions arguments are specified.
- //
- if (Session.AllowSolo==0 && Session.Type != GAME_TEN) {
- #ifdef WIN32
- MessageBox(NULL, "Red Alert for TEN\n (c) 1996 Westwood Studios",
- "Red Alert", MB_OK);
- exit(0);
- #else
- printf("\n");
- printf(" Red Alert for TEN\n");
- printf(" (c) 1996 Westwood Studios\n");
- printf("\n");
- exit(0);
- #endif // WIN32
- }
- #endif // TEN
- #if(MPATH)
- //
- // Only allow the MPATH version of the game to run if the MPATH
- // or AllowSoloPlayOptions arguments are specified.
- //
- if (Session.AllowSolo==0 && Session.Type != GAME_MPATH) {
- #ifdef WIN32
- MessageBox(NULL, "Red Alert for MPATH\n (c) 1996 Westwood Studios",
- "Red Alert", MB_OK);
- exit(0);
- #else
- printf("\n");
- printf(" Red Alert for MPATH\n");
- printf(" (c) 1996 Westwood Studios\n");
- printf("\n");
- exit(0);
- #endif // WIN32
- }
- #endif // MPATH
- #ifdef WIN32
- WindowsTimer = new WinTimerClass(60, FALSE);
- int time_test = WindowsTimer->Get_System_Tick_Count();
- Sleep (1000);
- if (WindowsTimer->Get_System_Tick_Count() == time_test){
- MessageBox(0, TEXT_ERROR_TIMER, TEXT_SHORT_TITLE, MB_OK|MB_ICONSTOP);
- return(EXIT_FAILURE);
- }
- #else //WIN32
- Init_Timer_System(60, true);
- #endif //WIN32
- RawFileClass cfile(CONFIG_FILE_NAME);
- #ifndef WIN32
- Install_Keyboard_Interrupt(Get_RM_Keyboard_Address(), Get_RM_Keyboard_Size());
- #endif //WIN32
- #ifdef NEVER
- Keyboard->IsLibrary = true;
- if (Debug_Flag) {
- Keyboard_Attributes_On(DEBUGINT);
- }
- #endif
- Keyboard = new KeyboardClass();
- #ifdef WIN32
- /*
- ** If there is loads of memory then use uncompressed shapes
- */
- Check_Use_Compressed_Shapes();
- #endif
- /*
- ** If there is not enough disk space free, don't allow the product to run.
- */
- if (Disk_Space_Available() < INIT_FREE_DISK_SPACE) {
- #ifdef WIN32
- char disk_space_message [512];
- sprintf (disk_space_message, TEXT_CRITICALLY_LOW, (INIT_FREE_DISK_SPACE) / (1024 * 1024));
- int reply = MessageBox(NULL, disk_space_message, TEXT_SHORT_TITLE, MB_ICONQUESTION|MB_YESNO);
- if (reply == IDNO) {
- if ( WindowsTimer )
- delete WindowsTimer;
- return (EXIT_FAILURE);
- }
- #else
- printf(TEXT_INSUFFICIENT);
- printf(TEXT_MUST_HAVE, INIT_FREE_DISK_SPACE / (1024 * 1024));
- printf("\n");
- if (Keyboard) Keyboard->Get();
- // Keyboard::IsLibrary = false;
- Remove_Keyboard_Interrupt();
- Remove_Timer_System();
- return(EXIT_FAILURE);
- #endif
- }
- if (cfile.Is_Available()) {
- Read_Private_Config_Struct(cfile, &NewConfig);
- #ifdef WIN32
- /*
- ** Set the options as requested by the ccsetup program
- */
- Read_Setup_Options( &cfile );
- Create_Main_Window( instance , command_show , ScreenWidth , ScreenHeight );
- SoundOn = Audio_Init ( MainWindow , 16 , false , 11025*2 , 0 );
- #else //WIN32
- if (!Debug_Quiet) {
- Audio_Init(NewConfig.DigitCard,
- NewConfig.Port,
- NewConfig.IRQ,
- NewConfig.DMA,
- PLAYBACK_RATE_NORMAL,
- // (NewConfig.Speed) ? PLAYBACK_RATE_SLOW : PLAYBACK_RATE_NORMAL,
- NewConfig.BitsPerSample,
- // 4,
- (Get_CPU() < 5) ? 3 : 5,
- // (NewConfig.Speed) ? 3 : 5,
- NewConfig.Reverse);
- SoundOn = true;
- } else {
- Audio_Init(0, -1, -1, -1, PLAYBACK_RATE_NORMAL, 8, 5, false);
- }
- #endif //WIN32
- #ifdef WIN32
- #ifdef MPEGMOVIE // Denzil 6/10/98
- if (!InitDDraw())
- return (EXIT_FAILURE);
- #else
- BOOL video_success = FALSE;
- /*
- ** Set 640x400 video mode. If its not available then try for 640x480
- */
- if (ScreenHeight == 400) {
- if (Set_Video_Mode (MainWindow, ScreenWidth, ScreenHeight, 8)) {
- video_success = TRUE;
- } else {
- if (Set_Video_Mode (MainWindow, ScreenWidth, 480, 8)) {
- video_success = TRUE;
- ScreenHeight = 480;
- }
- }
- } else {
- if (Set_Video_Mode (MainWindow, ScreenWidth, ScreenHeight, 8)) {
- video_success = TRUE;
- }
- }
- if (!video_success) {
- MessageBox(MainWindow, TEXT_VIDEO_ERROR, TEXT_SHORT_TITLE, MB_ICONEXCLAMATION|MB_OK);
- if (WindowsTimer) delete WindowsTimer;
- //if (Palette) delete Palette;
- return (EXIT_FAILURE);
- }
- if (ScreenWidth==320) {
- VisiblePage.Init( ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
- ModeXBuff.Init( ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)(GBC_VISIBLE | GBC_VIDEOMEM));
- } else {
- VisiblePage.Init( ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)(GBC_VISIBLE | GBC_VIDEOMEM));
- /*
- ** Check that we really got a video memory page. Failure is fatal.
- */
- memset (&surface_capabilities, 0, sizeof(surface_capabilities));
- VisiblePage.Get_DD_Surface()->GetCaps(&surface_capabilities);
- if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY) {
- /*
- ** Aaaarrgghh!
- */
- WWDebugString(TEXT_DDRAW_ERROR);WWDebugString("\n");
- MessageBox(MainWindow, TEXT_DDRAW_ERROR, TEXT_SHORT_TITLE, MB_ICONEXCLAMATION|MB_OK);
- if (WindowsTimer) delete WindowsTimer;
- return (EXIT_FAILURE);
- }
- /*
- ** If we have enough left then put the hidpage in video memory unless...
- **
- ** If there is no blitter then we will get better performance with a system
- ** memory hidpage
- **
- ** Use a system memory page if the user has specified it via the ccsetup program.
- */
- unsigned video_memory = Get_Free_Video_Memory();
- unsigned video_capabilities = Get_Video_Hardware_Capabilities();
- if (video_memory < ScreenWidth*ScreenHeight ||
- (! (video_capabilities & VIDEO_BLITTER)) ||
- (video_capabilities & VIDEO_NO_HARDWARE_ASSIST) ||
- !VideoBackBufferAllowed) {
- HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
- } else {
- //HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
- HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)GBC_VIDEOMEM);
- /*
- ** Make sure we really got a video memory hid page. If we didnt then things
- ** will run very slowly.
- */
- memset (&surface_capabilities, 0, sizeof(surface_capabilities));
- HiddenPage.Get_DD_Surface()->GetCaps(&surface_capabilities);
- if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY) {
- /*
- ** Oh dear, big trub. This must be an IBM crAptiva or something similarly cruddy.
- ** We must redo the Hidden Page as system memory.
- */
- AllSurfaces.Remove_DD_Surface(HiddenPage.Get_DD_Surface()); // Remove the old surface from the AllSurfaces list
- HiddenPage.Get_DD_Surface()->Release();
- HiddenPage.Init (ScreenWidth , ScreenHeight , NULL , 0 , (GBC_Enum)0);
- } else {
- VisiblePage.Attach_DD_Surface(&HiddenPage);
- }
- }
- }
- ScreenHeight = 400;
- if (VisiblePage.Get_Height() == 480) {
- SeenBuff.Attach(&VisiblePage, 0, 40, 640, 400);
- HidPage.Attach(&HiddenPage, 0, 40, 640, 400);
- } else {
- SeenBuff.Attach(&VisiblePage, 0, 0, 640, 400);
- HidPage.Attach(&HiddenPage, 0, 0, 640, 400);
- }
- #endif // MPEGMOVIE - Denzil 6/10/98
-
- Options.Adjust_Variables_For_Resolution();
- /*
- ** Install the memory error handler
- */
- Memory_Error = &Memory_Error_Handler;
- WindowList[0][WINDOWWIDTH] = SeenBuff.Get_Width();
- WindowList[0][WINDOWHEIGHT] = SeenBuff.Get_Height();
- WindowList[WINDOW_EDITOR][WINDOWWIDTH] = SeenBuff.Get_Width();
- WindowList[WINDOW_EDITOR][WINDOWHEIGHT]= SeenBuff.Get_Height();
- WWMouse = new WWMouseClass(&SeenBuff, 48, 48);
- MouseInstalled = TRUE;
- CDFileClass::Set_CD_Drive (CDList.Get_First_CD_Drive());
- #else //WIN32
- Options.Adjust_Variables_For_Resolution();
- if (!Special.IsFromInstall) {
- BlackPalette.Set();
- // Set_Palette(Palette);
- Set_Video_Mode(MCGA_MODE);
- }
- MouseInstalled = Install_Mouse(32, 24, 320, 200);
- #endif //WIN32
- /*
- ** See if we should run the intro
- */
- INIClass ini;
- ini.Load(cfile);
- /*
- ** Check for forced intro movie run disabling. If the conquer
- ** configuration file says "no", then don't run the intro.
- ** Don't do this for TEN & MPath.
- */
- if (!Special.IsFromInstall && Session.Type != GAME_TEN &&
- Session.Type != GAME_MPATH) {
- Special.IsFromInstall = ini.Get_Bool("Intro", "PlayIntro", true);
- }
- SlowPalette = ini.Get_Bool("Options", "SlowPalette", false);
- /*
- ** Regardless of whether we should run it or not, here we're
- ** gonna change it to say "no" in the future.
- */
- if (Special.IsFromInstall) {
- BreakoutAllowed = true;
- // BreakoutAllowed = false;
- ini.Put_Bool("Intro", "PlayIntro", false);
- ini.Save(cfile);
- }
- #ifndef WOLAPI_INTEGRATION
- #ifdef WIN32
- /*
- ** If WChat has been trying to send us a game start packet then receive it and
- ** flag that we were spawned from WCHat so we dont play the into movie.
- */
- if (DDEServer.Get_MPlayer_Game_Info()){
- Check_From_WChat(NULL);
- }else{
- //Check_From_WChat("C&CSPAWN.INI");
- //if (Special.IsFromWChat){
- // DDEServer.Disable();
- //}
- }
- #endif //WIN32
- #endif
- /*
- ** If the intro is being run for the first time, then don't
- ** allow breaking out of it with the <ESC> key.
- */
- if (Special.IsFromInstall) {
- BreakoutAllowed = true;
- // BreakoutAllowed = false;
- }
- Memory_Error_Exit = Print_Error_End_Exit;
- Main_Game(argc, argv);
- #ifdef MPEGMOVIE // Denzil 6/15/98
- if (MpgSettings != NULL)
- delete MpgSettings;
-
- #ifdef MCIMPEG
- if (MciMovie != NULL)
- delete MciMovie;
- #endif
- #endif
-
- #ifdef WIN32
- VisiblePage.Clear();
- HiddenPage.Clear();
- #else //WIN32
- SeenPage.Clear();
- Set_Video_Mode(RESET_MODE);
- #endif //WIN32
- Memory_Error_Exit = Print_Error_Exit;
- #ifdef WIN32
- /*
- ** Flag that this is a clean shutdown (not killed with Ctrl-Alt-Del)
- */
- ReadyToQuit = 1;
- /*
- ** Post a message to our message handler to tell it to clean up.
- */
- PostMessage(MainWindow, WM_DESTROY, 0, 0);
- /*
- ** Wait until the message handler has dealt with the message
- */
- do
- {
- Keyboard->Check();
- }while (ReadyToQuit == 1);
- return (EXIT_SUCCESS);
- #else //WIN32
- Remove_Mouse();
- Sound_End();
- #endif //WIN32
- } else {
- puts(TEXT_SETUP_FIRST);
- Keyboard->Get();
- }
- #ifdef WIN32
- if (WindowsTimer) {
- delete WindowsTimer;
- WindowsTimer = NULL;
- }
- #else //WIN32
- Remove_Keyboard_Interrupt();
- Remove_Timer_System();
- #endif //WIN32
- }
- /*
- ** Restore the current drive and directory.
- */
- #ifndef WIN32
- _dos_setdrive(olddrive, &drivecount);
- chdir(oldpath);
- #endif //WIN32
- return(EXIT_SUCCESS);
- }
- /* Initialize DirectDraw and surfaces */
- bool InitDDraw(void)
- {
- DDSCAPS surface_capabilities;
- BOOL video_success = FALSE;
- /* Set 640x400 video mode. If its not available then try for 640x480 */
- if (ScreenHeight == 400)
- {
- if (Set_Video_Mode(MainWindow, ScreenWidth, ScreenHeight, 8))
- {
- video_success = TRUE;
- }
- else
- {
- if (Set_Video_Mode(MainWindow, ScreenWidth, 480, 8))
- {
- video_success = TRUE;
- ScreenHeight = 480;
- }
- }
- }
- else
- {
- if (Set_Video_Mode(MainWindow, ScreenWidth, ScreenHeight, 8))
- {
- video_success = TRUE;
- }
- }
- if (!video_success)
- {
- MessageBox(MainWindow, TEXT_VIDEO_ERROR, TEXT_SHORT_TITLE, MB_ICONEXCLAMATION|MB_OK);
- if (WindowsTimer)
- delete WindowsTimer;
- return false;
- }
- if (ScreenWidth == 320)
- {
- VisiblePage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)0);
- ModeXBuff.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)(GBC_VISIBLE|GBC_VIDEOMEM));
- }
- else
- {
- VisiblePage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)(GBC_VISIBLE|GBC_VIDEOMEM));
- /* Check that we really got a video memory page. Failure is fatal. */
- memset(&surface_capabilities, 0, sizeof(surface_capabilities));
- VisiblePage.Get_DD_Surface()->GetCaps(&surface_capabilities);
- if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY)
- {
- /* Aaaarrgghh! */
- WWDebugString(TEXT_DDRAW_ERROR);WWDebugString("\n");
- MessageBox(MainWindow, TEXT_DDRAW_ERROR, TEXT_SHORT_TITLE, MB_ICONEXCLAMATION|MB_OK);
- if (WindowsTimer)
- delete WindowsTimer;
-
- return false;
- }
- /* If we have enough left then put the hidpage in video memory unless...
- *
- * If there is no blitter then we will get better performance with a system
- * memory hidpage
- *
- * Use a system memory page if the user has specified it via the ccsetup program.
- */
- unsigned video_memory = Get_Free_Video_Memory();
- unsigned video_capabilities = Get_Video_Hardware_Capabilities();
- if (video_memory < ScreenWidth * ScreenHeight
- || (!(video_capabilities & VIDEO_BLITTER))
- || (video_capabilities & VIDEO_NO_HARDWARE_ASSIST)
- || !VideoBackBufferAllowed)
- {
- HiddenPage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)0);
- }
- else
- {
- HiddenPage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)GBC_VIDEOMEM);
- /* Make sure we really got a video memory hid page. If we didnt then things
- * will run very slowly.
- */
- memset(&surface_capabilities, 0, sizeof(surface_capabilities));
- HiddenPage.Get_DD_Surface()->GetCaps(&surface_capabilities);
-
- if (surface_capabilities.dwCaps & DDSCAPS_SYSTEMMEMORY)
- {
- /* Oh dear, big trub. This must be an IBM crAptiva or something similarly cruddy.
- * We must redo the Hidden Page as system memory.
- */
- AllSurfaces.Remove_DD_Surface(HiddenPage.Get_DD_Surface()); // Remove the old surface from the AllSurfaces list
- HiddenPage.Get_DD_Surface()->Release();
- HiddenPage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)0);
- }
- else
- {
- VisiblePage.Attach_DD_Surface(&HiddenPage);
- }
- }
- }
- ScreenHeight = 400;
- if (VisiblePage.Get_Height() == 480)
- {
- SeenBuff.Attach(&VisiblePage, 0, 40, 640, 400);
- HidPage.Attach(&HiddenPage, 0, 40, 640, 400);
- }
- else
- {
- SeenBuff.Attach(&VisiblePage, 0, 0, 640, 400);
- HidPage.Attach(&HiddenPage, 0, 0, 640, 400);
- }
- return true;
- }
- /***********************************************************************************************
- * Prog_End -- Cleans up library systems in prep for game exit. *
- * *
- * This routine should be called before the game terminates. It handles cleaning up *
- * library systems so that a graceful return to the host operating system is achieved. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: none *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 03/20/1995 JLB : Created. *
- *=============================================================================================*/
- #ifdef WIN32
- void __cdecl Prog_End(void)
- {
- Sound_End();
- if (WWMouse) {
- delete WWMouse;
- WWMouse = NULL;
- }
- if (WindowsTimer) {
- delete WindowsTimer;
- WindowsTimer = NULL;
- }
- }
- #else //WIN32
- void Prog_End(void)
- {
- if (Session.Type == GAME_MODEM || Session.Type == GAME_NULL_MODEM) {
- NullModem.Change_IRQ_Priority(0);
- }
- Set_Video_Mode(RESET_MODE);
- Remove_Keyboard_Interrupt();
- Remove_Mouse();
- Sound_End();
- Remove_Timer_System();
- }
- #endif //WIN32
- void Print_Error_End_Exit(char * string)
- {
- Prog_End();
- printf( "%s\n", string );
- exit(1);
- }
- void Print_Error_Exit(char * string)
- {
- printf( "%s\n", string );
- exit(1);
- }
- /***********************************************************************************************
- * Emergency_Exit -- Function to call when we want to exit unexpectedly. *
- * Use this function instead of exit(n) so everything is properly cleaned up.*
- * *
- * *
- * INPUT: Code to return to the OS *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 3/13/97 1:32AM ST : Created *
- *=============================================================================================*/
- void Emergency_Exit ( int code )
- {
- #ifdef WIN32
- /*
- ** Clear out the video buffers so we dont glitch when we lose focus
- */
- VisiblePage.Clear();
- HiddenPage.Clear();
- BlackPalette.Set();
- Memory_Error_Exit = Print_Error_Exit;
- /*
- ** Flag that this is an emergency shut down - not a clean shutdown but
- ** not killed with Ctrl-Alt-Del either.
- */
- ReadyToQuit = 3;
- /*
- ** Post a message to our message handler to tell it to clean up.
- */
- PostMessage(MainWindow, WM_DESTROY, 0, 0);
- /*
- ** Wait until the message handler has dealt with the message
- */
- do
- {
- Keyboard->Check();
- }while (ReadyToQuit == 3);
- #else //WIN32
- /*
- ** Do the DOS end
- */
- Prog_End();
- #endif //WIN32
- exit ( code );
- }
- #ifdef WIN32
- /***********************************************************************************************
- * Read_Setup_Options -- Read stuff in from the INI file that we need to know sooner *
- * *
- * *
- * *
- * INPUT: Ptr to config file class *
- * *
- * OUTPUT: Nothing *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 6/7/96 4:09PM ST : Created *
- * 09/30/1996 JLB : Uses INI class. *
- *=============================================================================================*/
- void Read_Setup_Options( RawFileClass *config_file )
- {
- if (config_file->Is_Available()) {
- INIClass ini;
- ini.Load(*config_file);
- /*
- ** Read in the boolean options
- */
- VideoBackBufferAllowed = ini.Get_Bool("Options", "VideoBackBuffer", true);
- AllowHardwareBlitFills = ini.Get_Bool("Options", "HardwareFills", true);
- ScreenHeight = ini.Get_Bool("Options", "Resolution", false) ? 480 : 400;
- /*
- ** See if an alternative socket number has been specified
- */
- int socket = ini.Get_Int("Options", "Socket", 0);
- if (socket >0 ) {
- socket += 0x4000;
- if (socket >= 0x4000 && socket < 0x8000) {
- Ipx.Set_Socket (socket);
- }
- }
- /*
- ** See if a destination network has been specified
- */
- char netbuf [512];
- memset(netbuf, 0, sizeof(netbuf));
- char * netptr = netbuf;
- bool found = ini.Get_String("Options", "DestNet", NULL, netbuf, sizeof(netbuf));
- if (found && netptr != NULL && strlen(netbuf)) {
- NetNumType net;
- NetNodeType node;
- /*
- ** Scan the string, pulling off each address piece
- */
- int i = 0;
- char * p = strtok(netbuf,".");
- int x;
- while (p != NULL) {
- sscanf(p,"%x",&x); // convert from hex string to int
- if (i < 4) {
- net[i] = (char)x; // fill NetNum
- } else {
- node[i-4] = (char)x; // fill NetNode
- }
- i++;
- p = strtok(NULL,".");
- }
- /*
- ** If all the address components were successfully read, fill in the
- ** BridgeNet with a broadcast address to the network across the bridge.
- */
- if (i >= 4) {
- Session.IsBridge = 1;
- memset(node, 0xff, 6);
- Session.BridgeNet = IPXAddressClass(net, node);
- }
- }
- }
- }
- void Get_OS_Version (void)
- {
- WindowsNT = ((GetVersion() & 0x80000000) == 0) ? true : false;
- #if (0)
- OSVERSIONINFO osversion;
- if ( GetVersionEx (&osversion) ){
- WindowsNT = (osversion.dwPlatformId == VER_PLATFORM_WIN32_NT) ? true : false;
- OutputDebugString ("RA95 - Got OS version\n");
- }else{
- OutputDebugString ("RA95 - Failed to get OS version\n");
- char fuck [128];
- sprintf (fuck,"RA95 - Error code is %d\n", GetLastError());
- OutputDebugString (fuck);
- }
- #endif //(0)
- }
- #endif //WIN32
|