WINSTUB.CPP 32 KB

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