WINSTUB.CPP 31 KB

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