WINSTUB.CPP 30 KB

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