CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

WINSTUB.CPP (31388B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header: /CounterStrike/WINSTUB.CPP 3     3/13/97 2:06p Steve_tall $ */
     17 /***********************************************************************************************
     18  ***              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               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Command & Conquer                                            *
     22  *                                                                                             *
     23  *                    File Name : WINSTUB.CPP                                                  *
     24  *                                                                                             *
     25  *                   Programmer : Steve Tall                                                   *
     26  *                                                                                             *
     27  *                   Start Date : 10/04/95                                                     *
     28  *                                                                                             *
     29  *                  Last Update : October 4th 1995 [ST]                                        *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Overview:                                                                                   *
     33  *   This file contains stubs for undefined externals when linked under Watcom for Win 95      *
     34  *                                                                                             *
     35  *---------------------------------------------------------------------------------------------*
     36  *                                                                                             *
     37  * Functions:                                                                                  *
     38  *   Assert_Failure -- display the line and source file where a failed assert occurred         *
     39  *   Check_For_Focus_Loss -- check for the end of the focus loss                               *
     40  *   Create_Main_Window -- opens the MainWindow for C&C                                        *
     41  *   Focus_Loss -- this function is called when a library function detects focus loss          *
     42  *   Memory_Error_Handler -- Handle a possibly fatal failure to allocate memory                *
     43  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     44 
     45 #include	"function.h"
     46 
     47 #ifdef WINSOCK_IPX
     48 #include "WSProto.h"
     49 #else	//WINSOCK_IPX
     50 #include "tcpip.h"
     51 #include "ipx95.h"
     52 #endif	//WINSOCK_IPX
     53 
     54 void output(short,short)
     55 {}
     56 
     57 
     58 unsigned long CCFocusMessage = WM_USER+50;	//Private message for receiving application focus
     59 extern	void VQA_PauseAudio(void);
     60 extern	void VQA_ResumeAudio(void);
     61 
     62 //#include "WolDebug.h"
     63 
     64 
     65 /***********************************************************************************************
     66  * Focus_Loss -- this function is called when a library function detects focus loss            *
     67  *                                                                                             *
     68  *                                                                                             *
     69  *                                                                                             *
     70  * INPUT:    Nothing                                                                           *
     71  *                                                                                             *
     72  * OUTPUT:   Nothing                                                                           *
     73  *                                                                                             *
     74  * WARNINGS: None                                                                              *
     75  *                                                                                             *
     76  * HISTORY:                                                                                    *
     77  *    2/1/96 2:10PM ST : Created                                                               *
     78  *=============================================================================================*/
     79 
     80 void Focus_Loss(void)
     81 {
     82 	Theme.Suspend();
     83 	Stop_Primary_Sound_Buffer();
     84 	if (WWMouse) WWMouse->Clear_Cursor_Clip();
     85 }
     86 
     87 void Focus_Restore(void)
     88 {
     89 	Restore_Cached_Icons();
     90 	Map.Flag_To_Redraw(true);
     91 	Start_Primary_Sound_Buffer(TRUE);
     92 	if (WWMouse) WWMouse->Set_Cursor_Clip();
     93 	VisiblePage.Clear();
     94 	HiddenPage.Clear();
     95 }
     96 
     97 
     98 
     99 /***********************************************************************************************
    100  * Check_For_Focus_Loss -- check for the end of the focus loss                                 *
    101  *                                                                                             *
    102  *                                                                                             *
    103  *                                                                                             *
    104  * INPUT:    Nothing                                                                           *
    105  *                                                                                             *
    106  * OUTPUT:   Nothing                                                                           *
    107  *                                                                                             *
    108  * WARNINGS: None                                                                              *
    109  *                                                                                             *
    110  * HISTORY:                                                                                    *
    111  *    2/2/96 10:49AM ST : Created                                                              *
    112  *=============================================================================================*/
    113 
    114 void Check_For_Focus_Loss(void)
    115 {
    116 #if (0)//PG
    117 	static BOOL	focus_last_time = 1;
    118 			 MSG	msg;
    119 
    120 
    121 	if ( !GameInFocus ) {
    122 		Focus_Loss();
    123 		while ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD ) ) {
    124 	  		if (!GetMessage( &msg, NULL, 0, 0 ) ) {
    125 				return;
    126 			}
    127 			TranslateMessage(&msg);
    128 			DispatchMessage(&msg);
    129 		}
    130 	}
    131 
    132 	if (!focus_last_time && GameInFocus) {
    133 
    134 		VQA_PauseAudio();
    135 		CountDownTimerClass cd;
    136 		cd.Set(60*1);
    137 
    138 		do {
    139 			while (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE )) {
    140 	  			if (!GetMessage( &msg, NULL, 0, 0 ) ) {
    141 					return;
    142 				}
    143 				TranslateMessage(&msg);
    144 				DispatchMessage(&msg);
    145 			}
    146 
    147 		} while (cd.Time());
    148 		VQA_ResumeAudio();
    149 		PostMessage (MainWindow, CCFocusMessage, 0, 0);
    150 //		AllSurfaces.Restore_Surfaces();
    151 //		VisiblePage.Clear();
    152 //		HiddenPage.Clear();
    153 //		Map.Flag_To_Redraw(true);
    154 	}
    155 
    156 	focus_last_time = GameInFocus;
    157 #endif
    158 }
    159 
    160 
    161 
    162 extern bool InMovie;
    163 #if (0)//PG
    164 long FAR PASCAL _export Windows_Procedure(HWND hwnd, UINT message, UINT wParam, LONG lParam)
    165 {
    166 
    167 	int	low_param = LOWORD(wParam);
    168 
    169 	if (message == CCFocusMessage) {
    170 		Start_Primary_Sound_Buffer(TRUE);
    171 		if (!InMovie) {
    172 			Theme.Stop();
    173 			Theme.Queue_Song(THEME_PICK_ANOTHER);
    174 		}
    175 		return(0);
    176 	}
    177 
    178 #ifdef WINSOCK_IPX
    179 	/*
    180 	** Pass on any messages intended for the winsock message handler.
    181 	*/
    182 	if ( PacketTransport ) {
    183 		if ( message == (UINT) PacketTransport->Protocol_Event_Message() ) {
    184 			if ( PacketTransport->Message_Handler (hwnd, message, wParam, lParam) ){
    185 				return ( DefWindowProc (hwnd, message, wParam, lParam) );
    186 			}else{
    187 				return (0);
    188 			}
    189 		}
    190 	}
    191 #endif	//WINSOCK_IPX
    192 
    193 	
    194 	/*
    195 	**	Pass this message through to the keyboard handler. If the message
    196 	**	was processed and requires no further action, then return with
    197 	**	this information.
    198 	*/
    199 	if (Keyboard->Message_Handler(hwnd, message, wParam, lParam)) {
    200 		return(1);
    201 	}
    202 
    203 	switch ( message ) {
    204 //		case WM_SYSKEYDOWN:
    205 //			Mono_Printf("wparam=%08X lparam=%08X\n", (long)wParam, (long)lParam);
    206 			// fall through
    207 
    208 //		case WM_MOUSEMOVE:
    209 //		case WM_KEYDOWN:
    210 //		case WM_SYSKEYUP:
    211 //		case WM_KEYUP:
    212 //		case WM_LBUTTONDOWN:
    213 //		case WM_LBUTTONUP:
    214 //		case WM_LBUTTONDBLCLK:
    215 //		case WM_MBUTTONDOWN:
    216 //		case WM_MBUTTONUP:
    217 //		case WM_MBUTTONDBLCLK:
    218 //		case WM_RBUTTONDOWN:
    219 //		case WM_RBUTTONUP:
    220 //		case WM_RBUTTONDBLCLK:
    221 //	 		Keyboard->Message_Handler(hwnd, message, wParam, lParam);
    222 //			return(0);
    223 
    224 			/*
    225 			** Windoze message says we have to shut down. Try and do it cleanly.
    226 			*/
    227 		case WM_DESTROY:
    228 			Prog_End("WM_DESTROY", false);
    229 			Invalidate_Cached_Icons();
    230 			VisiblePage.Un_Init();
    231 			HiddenPage.Un_Init();
    232 			AllSurfaces.Release();
    233 			if (!InDebugger) Reset_Video_Mode();
    234 			Stop_Profiler();
    235 			PostQuitMessage( 0 );
    236 
    237 			/*
    238 			** If we are shutting down gracefully than flag that the message loop has finished.
    239 			** If this is a forced shutdown (ReadyToQuit == 0) then try and close down everything
    240 			** before we exit.
    241 			*/
    242 			switch (ReadyToQuit) {
    243 				case 1:
    244 					ReadyToQuit = 2;
    245 					break;
    246 
    247 				case 0:
    248 					Shutdown_Network();
    249 #ifndef WINSOCK_IPX
    250 					if (Winsock.Get_Connected()) Winsock.Close();
    251 					/*
    252 					** Free the THIPX32 dll
    253 					*/
    254 					Unload_IPX_Dll();
    255 #endif	//WINSOCK_IPX
    256 					ExitProcess(0);
    257 					break;
    258 				case 3:
    259 					Shutdown_Network();
    260 #ifndef WINSOCK_IPX
    261 					/*
    262 					** Call the function to disable the IPX callback as horrible things can
    263 					** happen if we get a callback after the process has exited!
    264 					*/
    265 					if (Session.Type == GAME_IPX){
    266 						IPX_Shut_Down95();
    267 					}
    268 					/*
    269 					** Free the THIPX32 dll
    270 					*/
    271 #ifdef FIXIT_CSII	//	checked - ajw 9/28/98
    272 #else
    273 					Unload_IPX_Dll();
    274 #endif
    275 
    276 					if (Winsock.Get_Connected()) Winsock.Close();
    277 #endif	//WINSOCK_IPX
    278 					ReadyToQuit = 2;
    279 					break;
    280 
    281 			}
    282 			return(0);
    283 
    284 		case WM_ACTIVATEAPP:
    285 			GameInFocus=(BOOL)wParam;
    286 			if (!GameInFocus) Focus_Loss();
    287 			AllSurfaces.Set_Surface_Focus (GameInFocus);
    288 			AllSurfaces.Restore_Surfaces();
    289 //			if (GameInFocus) {
    290 //				Restore_Cached_Icons();
    291 //				Map.Flag_To_Redraw(true);
    292 //				Start_Primary_Sound_Buffer(TRUE);
    293 //				if (WWMouse) WWMouse->Set_Cursor_Clip();
    294 //			}
    295 			return(0);
    296 #ifdef NEVER
    297 		case WM_ACTIVATE:
    298 			if (low_param == WA_INACTIVE) {
    299 				GameInFocus = FALSE;
    300 				Focus_Loss();
    301 			}
    302 			return(0);
    303 #endif	//NEVER
    304 
    305 
    306 		case WM_SYSCOMMAND:
    307 			switch ( wParam ) {
    308 
    309 				case SC_CLOSE:
    310 					/*
    311 					** Windows sent us a close message. Probably in response to Alt-F4. Ignore it by
    312 					** pretending to handle the message and returning true;
    313 					*/
    314 					return (0);
    315 
    316 				case SC_SCREENSAVE:
    317 					/*
    318 					** Windoze is about to start the screen saver. If we just return without passing
    319 					** this message to DefWindowProc then the screen saver will not be allowed to start.
    320 					*/
    321 					return (0);
    322 			}
    323 			break;
    324 
    325 
    326 #ifndef WINSOCK_IPX
    327 		case WM_ACCEPT:
    328 		case WM_HOSTBYADDRESS:
    329 		case WM_HOSTBYNAME:
    330 		case WM_ASYNCEVENT:
    331 		case WM_UDPASYNCEVENT:
    332 	 		Winsock.Message_Handler(hwnd, message, wParam, lParam);
    333 			return (0);
    334 #endif	//WINSOCK_IPX
    335 	}
    336 
    337 
    338 
    339 	return DefWindowProc (hwnd, message, wParam, lParam);
    340 }
    341 #endif
    342 
    343 
    344 
    345 
    346 
    347 HANDLE DebugFile = INVALID_HANDLE_VALUE;
    348 
    349 /***********************************************************************************************
    350  * WWDebugString -- sends a string to the debugger and echos it to disk                        *
    351  *                                                                                             *
    352  *                                                                                             *
    353  *                                                                                             *
    354  * INPUT:    string                                                                            *
    355  *                                                                                             *
    356  * OUTPUT:   Nothing                                                                           *
    357  *                                                                                             *
    358  * WARNINGS: None                                                                              *
    359  *                                                                                             *
    360  * HISTORY:                                                                                    *
    361  *    10/28/96 12:48PM ST : Created                                                              *
    362  *=============================================================================================*/
    363 void WWDebugString (char *string)
    364 {
    365 #if (0)
    366 	char outstr[256];
    367 
    368 	sprintf (outstr, "%s", string);
    369 
    370 	DWORD	actual;
    371 	if (DebugFile == INVALID_HANDLE_VALUE){
    372 		DebugFile = CreateFile("debug.txt", GENERIC_WRITE, 0,
    373 												NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    374 	}else{
    375 		DebugFile = CreateFile("debug.txt", GENERIC_WRITE, 0,
    376 												NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    377 	}
    378 
    379 	if (DebugFile != INVALID_HANDLE_VALUE){
    380 		SetFilePointer (DebugFile, 0, NULL, FILE_END);
    381 		WriteFile(DebugFile, outstr, strlen(outstr)+1, &actual, NULL);
    382 		CloseHandle (DebugFile);
    383 	}
    384 
    385 	OutputDebugString (string);
    386 #else	//(0)
    387 
    388 	string = string;
    389 //	debugprint( string );
    390 
    391 #endif	//(0)
    392 
    393 }
    394 
    395 
    396 
    397 
    398 
    399 
    400 
    401 
    402 
    403 /***********************************************************************************************
    404  * Create_Main_Window -- opens the MainWindow for C&C                                          *
    405  *                                                                                             *
    406  *                                                                                             *
    407  *                                                                                             *
    408  * INPUT:    instance -- handle to program instance                                            *
    409  *                                                                                             *
    410  * OUTPUT:   Nothing                                                                           *
    411  *                                                                                             *
    412  * WARNINGS: None                                                                              *
    413  *                                                                                             *
    414  * HISTORY:                                                                                    *
    415  *    10/10/95 4:08PM ST : Created                                                             *
    416  *=============================================================================================*/
    417 
    418 #define CC_ICON 1
    419 
    420 #if (ENGLISH)
    421 #define WINDOW_NAME		"Red Alert"
    422 #endif
    423 
    424 #if (FRENCH)
    425 #define WINDOW_NAME		"Alerte Rouge"
    426 #endif
    427 
    428 #if (GERMAN)
    429 #define WINDOW_NAME		"Alarmstufe Rot"
    430 #endif
    431 
    432 
    433 void Create_Main_Window ( HANDLE instance , int command_show , int width , int height )
    434 
    435 {
    436 	MainWindow = NULL;
    437 	return;
    438 #if (0)//PG
    439 	HWND        	hwnd ;
    440 	WNDCLASS    	wndclass ;
    441 	//
    442 	// Register the window class
    443 	//
    444 
    445 	wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
    446 	wndclass.lpfnWndProc   = Windows_Procedure ;
    447 	wndclass.cbClsExtra    = 0 ;
    448 	wndclass.cbWndExtra    = 0 ;
    449 	wndclass.hInstance     = instance ;
    450 	wndclass.hIcon         = LoadIcon (instance, MAKEINTRESOURCE(CC_ICON)) ;
    451 	wndclass.hCursor       = NULL;
    452 	wndclass.hbrBackground = NULL;
    453 	wndclass.lpszMenuName  = WINDOW_NAME;	//NULL
    454 	wndclass.lpszClassName = WINDOW_NAME;
    455 
    456 	RegisterClass (&wndclass) ;
    457 
    458 
    459 	//
    460 	// Create our main window
    461 	//
    462 	hwnd = CreateWindowEx (
    463 							WS_EX_TOPMOST,
    464 							WINDOW_NAME,
    465 							WINDOW_NAME,
    466 							WS_POPUP, // Denzil | WS_MAXIMIZE,
    467 							0,
    468 							0,
    469 							// Denzil 5/18/98 - Making window fullscreen prevents other apps
    470 							// from getting WM_PAINT messages
    471 							GetSystemMetrics(SM_CXSCREEN), //width,
    472 							GetSystemMetrics(SM_CYSCREEN), //height,
    473 							// End Denzil
    474 							NULL,
    475 							NULL,
    476 							instance,
    477 							NULL );
    478 // Denzil
    479 width = width; height = height;
    480 // End
    481 
    482 	ShowWindow (hwnd, command_show );
    483 	ShowCommand = command_show;
    484 	UpdateWindow (hwnd);
    485 	SetFocus (hwnd);
    486 	MainWindow=hwnd;			//Save the handle to our main window
    487 	hInstance = instance;
    488 
    489 	CCFocusMessage = RegisterWindowMessage ("CC_GOT_FOCUS");
    490 
    491 	Audio_Focus_Loss_Function = &Focus_Loss;
    492 	Misc_Focus_Loss_Function = &Focus_Loss;
    493 	Misc_Focus_Restore_Function = &Focus_Restore;
    494 	Gbuffer_Focus_Loss_Function = &Focus_Loss;
    495 #endif
    496 }
    497 
    498 
    499 void Window_Dialog_Box(HANDLE  hinst, LPCTSTR  lpszTemplate, HWND  hwndOwner, DLGPROC  dlgprc)
    500 {
    501 #if (0)//PG
    502 	MSG					msg;
    503 	/*
    504 	** Get rid of the Westwood mouse cursor because we are showing a
    505 	** dialog box and we want to have the right windows cursor showing
    506 	** for it.
    507 	*/
    508 	Hide_Mouse();
    509 	ShowCursor(TRUE);
    510 
    511 	/*
    512 	** Pop up the dialog box and then run a standard message handler
    513 	** until the dialog box is closed.
    514 	*/
    515 
    516 	DialogBox(hinst, lpszTemplate, hwndOwner, dlgprc);
    517 	while (GetMessage(&msg, NULL, 0, 0) && !AllDone) {
    518 		TranslateMessage(&msg);
    519 		DispatchMessage(&msg);
    520 	}
    521 
    522 	/*
    523 	** Restore the westwood mouse cursor and get rid of the windows one
    524 	** because it is now time to restore back to the westwood way of
    525 	** doing things.
    526 	*/
    527 	ShowCursor(FALSE);
    528 	Show_Mouse();
    529 #endif
    530 }
    531 
    532 
    533 
    534 typedef struct tColourList {
    535 
    536 	char	Red;
    537 	char	Green;
    538 	char	Blue;
    539 } ColourList;
    540 
    541 ColourList	ColourLookup[9]={
    542 	0,0,0,
    543 	63,0,0,
    544 	0,63,0,
    545 	0,0,63,
    546 	63,0,63,
    547 	63,63,0,
    548 	0,63,63,
    549 	32,32,32,
    550 	63,63,63
    551 };
    552 
    553 
    554 
    555 
    556 int	DebugColour=1;
    557 
    558 
    559 extern "C" void Set_Palette_Register(int number, int red, int green, int blue);
    560 //#pragma off (unreferenced)
    561 void Colour_Debug (int call_number)
    562 {
    563 #if (0)//PG
    564 	//#if 0
    565 	//if (DebugColour==call_number || !call_number) {
    566 
    567 		//if (call_number) {
    568 		//	Wait_Vert_Blank();
    569 		//}
    570 
    571 		Set_Palette_Register (0,ColourLookup[call_number].Red ,
    572 										ColourLookup[call_number].Green,
    573 										ColourLookup[call_number].Blue);
    574 	//}
    575 	//#endif
    576 #endif
    577 }
    578 
    579 //#pragma on (unreferenced)
    580 
    581 
    582 
    583 
    584 
    585 BOOL Any_Locked (void)
    586 {
    587 	if (SeenBuff.Get_LockCount() ||
    588 		HidPage.Get_LockCount()) {
    589 		return (TRUE);
    590 	} else {
    591 		return(FALSE);
    592 	}
    593 }
    594 
    595 
    596 
    597 
    598 
    599 
    600 
    601 
    602 //
    603 // Miscellaneous stubs. Mainly for multi player stuff
    604 //
    605 //
    606 //
    607 
    608 //IPXAddressClass::IPXAddressClass(void) {
    609 //	int i;
    610 //	i++;
    611 //}
    612 //int IPXManagerClass::Num_Connections(void) { return (0); }
    613 //int IPXManagerClass::Connection_ID( int ) { return (0); }
    614 //IPXAddressClass * IPXManagerClass::Connection_Address( int ) { return ((IPXAddressClass*)0); }
    615 //char * IPXManagerClass::Connection_Name( int ) { return ((char*)0); }
    616 //int IPXAddressClass::Is_Broadcast() { return (0); }
    617 //int IPXManagerClass::Send_Global_Message( void *, int, int, IPXAddressClass * ) { return (0); }
    618 //int IPXManagerClass::Service() { return (0); }
    619 //int IPXManagerClass::Get_Global_Message( void  *, int  *, IPXAddressClass  *, short unsigned  * ) { return (0); }
    620 //int IPXAddressClass::operator ==( IPXAddressClass  & ) { return (0); }
    621 //IPXManagerClass::IPXManagerClass( int, int, int, int, short unsigned, short unsigned ) {}
    622 //IPXManagerClass::~IPXManagerClass() {
    623 //	int i;
    624 //	i++;
    625 //	}
    626 //int  IPXManagerClass::Delete_Connection( int ) { return (0); }
    627 //IPXAddressClass::IPXAddressClass( char unsigned  *, char unsigned  * ) {}
    628 //void  IPXManagerClass::Set_Socket( short unsigned ) {}
    629 //int  IPXManagerClass::Is_IPX() { return (0); }
    630 //int  IPXManagerClass::Init() { return (0); }
    631 //void  IPXAddressClass::Get_Address( char unsigned  *, char unsigned  * ) {}
    632 //void  IPXManagerClass::Set_Bridge( char unsigned  * ) {}
    633 //int  IPXManagerClass::Global_Num_Send() { return (0); }
    634 //void  IPXManagerClass::Set_Timing( long unsigned, long unsigned, long unsigned ) {}
    635 //unsigned long IPXManagerClass::Global_Response_Time() { return (0); }
    636 //int  IPXManagerClass::Create_Connection( int, char  *, IPXAddressClass  * ) { return (0); }
    637 //int  IPXAddressClass::operator !=( IPXAddressClass  & ) { return (0); }
    638 //int  IPXManagerClass::Send_Private_Message( void  *, int, int, int ) { return (0); }
    639 //int  IPXManagerClass::Get_Private_Message( void  *, int  *, int  * ) { return (0); }
    640 //int  IPXManagerClass::Connection_Index( int ) { return (0); }
    641 //void  IPXManagerClass::Reset_Response_Time() {}
    642 //long unsigned  IPXManagerClass::Response_Time() { return (0); }
    643 //int  IPXManagerClass::Private_Num_Send( int ) { return (0); }
    644 
    645 //_VQAHandle  *  VQA_Alloc(void) { return ((_VQAHandle *)0); }
    646 //void  VQA_Init( _VQAHandle  *, long ( *)()) {}
    647 //long  VQA_Open( _VQAHandle  *, char const  *, _VQAConfig  * ) { return (0); }
    648 //void  VQA_Free( _VQAHandle  * ) {}
    649 //void  VQA_Close( _VQAHandle  * ) {}
    650 //long  VQA_Play( _VQAHandle  *, long ) { return (0); }
    651 
    652 //void VQA_Init(VQAHandle *, long(*)(VQAHandle *vqa, long action,	void *buffer, long nbytes)) {}
    653 
    654 //long VQA_Open(VQAHandle *, char const *, VQAConfig *)
    655 //{
    656 //	return (0);
    657 //}
    658 
    659 //void VQA_Close(VQAHandle *) {}
    660 
    661 //long VQA_Play(VQAHandle *, long)
    662 //{
    663 //	return (0);
    664 //}
    665 
    666 
    667 unsigned char	*VQPalette;
    668 long				VQNumBytes;
    669 unsigned long	VQSlowpal;
    670 bool				VQPaletteChange = false;
    671 
    672 
    673 extern "C"{
    674 	void __cdecl SetPalette(unsigned char *palette, long numbytes, unsigned long slowpal);
    675 }
    676 
    677 
    678 
    679 void Flag_To_Set_Palette(unsigned char *palette, long numbytes, unsigned long slowpal)
    680 {
    681 	VQPalette = palette;
    682 	VQNumBytes = numbytes;
    683 	VQSlowpal = slowpal;
    684 	VQPaletteChange = true;
    685 }
    686 
    687 
    688 
    689 void Check_VQ_Palette_Set(void)
    690 {
    691 	if (VQPaletteChange) {
    692 		SetPalette(VQPalette, VQNumBytes, VQSlowpal);
    693 		VQPaletteChange = false;
    694 	}
    695 }
    696 
    697 
    698 
    699 
    700 
    701 void __cdecl SetPalette(unsigned char *palette, long, unsigned long)
    702 {
    703 	for (int i=0 ; i<256*3 ; i++) {
    704 		*(palette+i)&=63;
    705 	}
    706 	Increase_Palette_Luminance(palette , 15 , 15 , 15 ,63);
    707 
    708 	if (PalettesRead) {
    709 		memcpy (&PaletteInterpolationTable[0][0] , InterpolatedPalettes[PaletteCounter++] , 65536);
    710 	}
    711 	Set_Palette(palette);
    712 }
    713 
    714 
    715 #ifndef NDEBUG
    716 /***********************************************************************************************
    717  * Assert_Failure -- display the line and source file where a failed assert occurred           *
    718  *                                                                                             *
    719  *                                                                                             *
    720  * INPUT:    line number in source file                                                        *
    721  *           name of source file                                                               *
    722  *                                                                                             *
    723  * OUTPUT:   Nothing                                                                           *
    724  *                                                                                             *
    725  * WARNINGS: None                                                                              *
    726  *                                                                                             *
    727  * HISTORY:                                                                                    *
    728  *    4/17/96 9:58AM ST : Created                                                              *
    729  *=============================================================================================*/
    730 
    731 void Assert_Failure (char *expression, int line, char *file)
    732 {
    733 	char	assertbuf[256];
    734 	char   timebuff[512];
    735 	SYSTEMTIME	time;
    736 
    737 	sprintf (assertbuf, "assert '%s' failed at line %d in module %s.\n", expression, line, file);
    738 
    739 	if (!MonoClass::Is_Enabled()) MonoClass::Enable();
    740 
    741 	Mono_Clear_Screen();
    742 	Mono_Printf("%s", assertbuf);
    743 
    744 	WWDebugString(assertbuf);
    745 
    746 	GetLocalTime(&time);
    747 
    748 	sprintf (timebuff, "%02d/%02d/%04d %02d:%02d:%02d - %s", time.wMonth, time.wDay, time.wYear,
    749 																		time.wHour, time.wMinute, time.wSecond,
    750 																		assertbuf);
    751 
    752 
    753 	HMMIO handle = mmioOpen("ASSERT.TXT", NULL, MMIO_WRITE);
    754 	if (!handle) {
    755 		handle = mmioOpen("ASSERT.TXT", NULL, MMIO_CREATE | MMIO_WRITE);
    756 		//mmioClose(handle, 0);
    757 		//handle = mmioOpen("ASSERT.TXT", NULL, MMIO_WRITE);
    758 	}
    759 
    760 	if (handle) {
    761 
    762 		mmioWrite(handle, timebuff, strlen(timebuff));
    763 		mmioClose(handle, 0);
    764 	}
    765 
    766 	WWMessageBox().Process(assertbuf);
    767 //	WWMessageBox().Process("Red Alert demo timed out - Aborting");
    768 	//Get_Key();
    769 
    770 	Prog_End(assertbuf, false);
    771 	Invalidate_Cached_Icons();
    772 	//PostQuitMessage( 0 );
    773 	//ExitProcess(0);
    774 }
    775 #endif
    776 
    777 
    778 
    779 
    780 
    781 
    782 
    783 /***********************************************************************************************
    784  * Memory_Error_Handler -- Handle a possibly fatal failure to allocate memory                  *
    785  *                                                                                             *
    786  *                                                                                             *
    787  *                                                                                             *
    788  * INPUT:    Nothing                                                                           *
    789  *                                                                                             *
    790  * OUTPUT:   Nothing                                                                           *
    791  *                                                                                             *
    792  * WARNINGS: None                                                                              *
    793  *                                                                                             *
    794  * HISTORY:                                                                                    *
    795  *    5/22/96 3:57PM ST : Created                                                              *
    796  *=============================================================================================*/
    797 void Memory_Error_Handler(void)
    798 {
    799 	VisiblePage.Clear();
    800 	CCPalette.Set();
    801 	while (Get_Mouse_State()) {Show_Mouse();};
    802 	WWMessageBox().Process(TEXT_MEMORY_ERROR, TEXT_ABORT, false);
    803 
    804 	ReadyToQuit = 1;
    805 
    806 	PostMessage(MainWindow, WM_DESTROY, 0, 0);
    807 	do
    808 	{
    809 		Keyboard->Check();
    810 	}while (ReadyToQuit == 1);
    811 
    812 	ExitProcess(0);
    813 }
    814 
    815 
    816 
    817 
    818 
    819 
    820 
    821 
    822 GraphicBufferClass* Read_PCX_File(char* name, char* Palette, void *Buff, long Size);
    823 void Load_Title_Screen(char *name, GraphicViewPortClass *video_page, unsigned char *palette)
    824 {
    825 
    826 	GraphicBufferClass *load_buffer;
    827 
    828 
    829 	load_buffer = Read_PCX_File (name, (char*)palette, NULL, 0);
    830 
    831 	if (load_buffer) {
    832 		load_buffer->Blit(*video_page);
    833 		delete load_buffer;
    834 	}
    835 }
    836 
    837 
    838 
    839 #include "filepcx.h"
    840 
    841 /***************************************************************************
    842  * READ_PCX_FILE -- read a pcx file into a Graphic Buffer                  *
    843  *                                                                         *
    844  *	GraphicBufferClass* Read_PCX_File (char* name, char* palette ,void *Buff, long size );	*
    845  *  																								*
    846  *                                                                         *
    847  * INPUT: name is a NULL terminated string of the format [xxxx.pcx]        *
    848  *        palette is optional, if palette != NULL the the color palette of *
    849  *					 the pcx file will be place in the memory block pointed	   *
    850  *               by palette.																*
    851  *			 Buff is optional, if Buff == NULL a new memory Buffer		 		*
    852  *					 will be allocated, otherwise the file will be placed 		*
    853  *					 at location pointed by Buffer;										*
    854  *			Size is the size in bytes of the memory block pointed by Buff		*
    855  *				  is also optional;															*                                                                         *
    856  * OUTPUT: on success a pointer to a GraphicBufferClass containing the     *
    857  *         pcx file, NULL otherwise.                                       *
    858  *																									*
    859  * WARNINGS:                                                               *
    860  *         Appears to be a comment-free zone                               *
    861  *                                                                         *
    862  * HISTORY:                                                                *
    863  *   05/03/1995 JRJ : Created.                                             *
    864  *   04/30/1996 ST : Tidied up and modified to use CCFileClass             *
    865  *=========================================================================*/
    866 
    867 #define	POOL_SIZE 2048
    868 #define	READ_CHAR()  *file_ptr++ ; \
    869 							 if ( file_ptr	>= & pool [ POOL_SIZE ]	) { \
    870 								 file_handle.Read (pool , POOL_SIZE ); \
    871 								 file_ptr = pool ; \
    872 							 }
    873 
    874 
    875 GraphicBufferClass* Read_PCX_File(char* name, char* palette, void *Buff, long Size)
    876 {
    877 	unsigned					i, j;
    878 	unsigned					rle;
    879 	unsigned					color;
    880 	unsigned					scan_pos;
    881 	char						*file_ptr;
    882 	int						width;
    883 	int						height;
    884 	char						*buffer;
    885 	PCX_HEADER				header;
    886 	RGB						*pal;
    887 	char						pool [POOL_SIZE];
    888 	GraphicBufferClass	*pic;
    889 
    890 	CCFileClass file_handle(name);
    891 
    892 	if (!file_handle.Is_Available()) return (NULL);
    893 
    894 	file_handle.Open(READ);
    895 
    896 	file_handle.Read (&header, sizeof (PCX_HEADER));
    897 
    898 	if (header.id != 10 &&  header.version != 5 && header.pixelsize != 8 ) return NULL ;
    899 
    900 	width = header.width - header.x + 1;
    901 	height = header.height - header.y + 1;
    902 
    903 	if (Buff) {
    904     	buffer = (char *)Buff;
    905     	i = Size / width;
    906     	height = MIN ((int)i - 1, height);
    907     	pic = new GraphicBufferClass(width, height, buffer, Size);
    908     	if ( !(pic && pic->Get_Buffer()) ) return NULL ;
    909 	} else {
    910     	pic = new GraphicBufferClass(width, height, NULL, width*(height+4));
    911     	if ( !(pic && pic->Get_Buffer()) ) return NULL ;
    912 	}
    913 
    914 	buffer = (char *) pic->Get_Buffer();
    915 	file_ptr = pool ;
    916 	file_handle.Read (pool , POOL_SIZE);
    917 
    918 	if ( header.byte_per_line != width ) {
    919 
    920 		for ( scan_pos = j = 0 ; j < (unsigned) height ; j ++, scan_pos += width ) {
    921 			for ( i = 0 ; i < (unsigned)width ; ) {
    922 				rle = READ_CHAR ();
    923 				if ( rle > 192 ) {
    924 					rle -= 192 ;
    925 					color =	READ_CHAR (); ;
    926 					memset ( buffer + scan_pos + i , color , rle );
    927 					i += rle;
    928 				} else {
    929 					*(buffer+scan_pos + i++ ) = (char)rle;
    930 				}
    931 			}
    932       	}
    933 
    934 		if ( i == width ) rle = READ_CHAR ();
    935 		if ( rle > 192 )  rle = READ_CHAR ();
    936 
    937 	} else {
    938 
    939 		for ( i = 0 ; i < (unsigned)width * height ; ) {
    940   			rle = READ_CHAR ();
    941   			rle &= 0xff;
    942   			if ( rle > 192 ) {
    943         		rle -= 192 ;
    944         		color = READ_CHAR ();
    945   				memset ( buffer + i , color , rle );
    946         		i += rle ;
    947      		} else {
    948 				*(buffer + i++) = (char)rle;
    949 			}
    950 		}
    951 	}
    952 
    953 	if ( palette ) {
    954 		file_handle.Seek (- (256 * (int)sizeof ( RGB )) , SEEK_END );
    955 		file_handle.Read (palette , 256L * sizeof ( RGB ));
    956 
    957 		pal = ( RGB * ) palette;
    958 		for (i = 0 ; i < 256 ; i ++) {
    959 			pal ->red	>>= 2;
    960 			pal ->green	>>= 2;
    961 			pal ->blue	>>= 2;
    962 			pal ++ ;
    963 		}
    964 	}
    965 
    966 	file_handle.Close();
    967 	return pic;
    968 }