WINSTUB.CPP 31 KB

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