DDRAW.CPP 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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 A S S O C I A T E S **
  16. ***************************************************************************
  17. * *
  18. * Project Name : Westwood Win32 Library *
  19. * *
  20. * File Name : DDRAW.CPP *
  21. * *
  22. * Programmer : Philip W. Gorrow *
  23. * *
  24. * Start Date : October 10, 1995 *
  25. * *
  26. * Last Update : October 10, 1995 [] *
  27. * *
  28. *-------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. /*=========================================================================*/
  32. /* The following PRIVATE functions are in this file: */
  33. /*=========================================================================*/
  34. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  35. #include "misc.h"
  36. #include <gbuffer.h>
  37. #include <palette.h>
  38. #include "stdio.h"
  39. LPDIRECTDRAW DirectDrawObject=NULL; // Pointer to the direct draw object
  40. LPDIRECTDRAW2 DirectDraw2Interface = NULL; // Pointer to direct draw 2 interface
  41. HWND MainWindow; // Handle to programs main window
  42. // this is passed to SetCooperativeLevel
  43. // so DirectDraw knows which window is ours
  44. PALETTEENTRY PaletteEntries[256]; // 256 windows palette entries
  45. LPDIRECTDRAWPALETTE PalettePtr; // Pointer to direct draw palette object
  46. BOOL FirstPaletteSet=FALSE; // Is this the first time 'Set_Palette' has been called?
  47. LPDIRECTDRAWSURFACE PaletteSurface=NULL;
  48. SurfaceMonitorClass AllSurfaces; //List of all direct draw surfaces
  49. BOOL CanVblankSync = TRUE;
  50. BOOL SystemToVideoBlits =FALSE; // Does hardware support system mem to video mem blits?
  51. BOOL VideoToSystemBlits =FALSE; // Does hardware support video mem to system mem blits?
  52. BOOL SystemToSystemBlits = FALSE; // Does hardware support system mem to system mem blits?
  53. BOOL OverlappedVideoBlits = TRUE; // Can video driver blit overlapped regions?
  54. /*
  55. ** Function to call if we detect focus loss
  56. */
  57. extern void (*Misc_Focus_Loss_Function)(void) = NULL;
  58. extern void (*Misc_Focus_Restore_Function)(void) = NULL;
  59. /***********************************************************************************************
  60. * Process_DD_Result -- Does a message box based on the result of a DD command *
  61. * *
  62. * INPUT: HRESULT result - the result returned from the direct draw command *
  63. * int display_ok_msg - should a message be displayed if command ok * *
  64. * *
  65. * OUTPUT: none *
  66. * *
  67. * HISTORY: *
  68. * 09/27/1995 PWG : Created. *
  69. *=============================================================================================*/
  70. void Process_DD_Result(HRESULT result, int display_ok_msg)
  71. {
  72. switch (result) {
  73. case DD_OK:
  74. if (display_ok_msg) {
  75. MessageBox(MainWindow, "Direct Draw request went ok.", "Note", MB_ICONEXCLAMATION|MB_OK);
  76. }
  77. break;
  78. case DDERR_ALREADYINITIALIZED:
  79. MessageBox(MainWindow, "This object is already initialized ","Note", MB_ICONEXCLAMATION|MB_OK);
  80. break;
  81. case DDERR_BLTFASTCANTCLIP:
  82. MessageBox(MainWindow, "Return if a clipper object is attached to the source surface passed into a BltFast call.","Note", MB_ICONEXCLAMATION|MB_OK);
  83. break;
  84. case DDERR_CANNOTATTACHSURFACE:
  85. MessageBox(MainWindow, "This surface can not be attached to the requested surface. ","Note", MB_ICONEXCLAMATION|MB_OK);
  86. break;
  87. case DDERR_CANNOTDETACHSURFACE:
  88. MessageBox(MainWindow, "This surface can not be detached from the requested surface. ","Note", MB_ICONEXCLAMATION|MB_OK);
  89. break;
  90. case DDERR_CANTCREATEDC:
  91. MessageBox(MainWindow, "Windows can not create any more DCs","Note", MB_ICONEXCLAMATION|MB_OK);
  92. break;
  93. case DDERR_CANTDUPLICATE:
  94. MessageBox(MainWindow, "Can't duplicate primary & 3D surfaces, or surfaces that are implicitly created.","Note", MB_ICONEXCLAMATION|MB_OK);
  95. break;
  96. case DDERR_CANTLOCKSURFACE:
  97. MessageBox(MainWindow, "Unable to lock surface because no driver exists which can supply a pointer to the surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  98. break;
  99. case DDERR_CLIPPERISUSINGHWND:
  100. MessageBox(MainWindow, "An attempt was made to set a cliplist for a clipper object that is already monitoring an hwnd.","Note", MB_ICONEXCLAMATION|MB_OK);
  101. break;
  102. case DDERR_COLORKEYNOTSET:
  103. MessageBox(MainWindow, "No src color key specified for this operation.","Note", MB_ICONEXCLAMATION|MB_OK);
  104. break;
  105. case DDERR_CURRENTLYNOTAVAIL:
  106. MessageBox(MainWindow, "Support is currently not available. ","Note", MB_ICONEXCLAMATION|MB_OK);
  107. break;
  108. case DDERR_DIRECTDRAWALREADYCREATED:
  109. MessageBox(MainWindow, "A DirectDraw object representing this driver has already been created for this process. ","Note", MB_ICONEXCLAMATION|MB_OK);
  110. break;
  111. case DDERR_EXCEPTION:
  112. MessageBox(MainWindow, "An exception was encountered while performing the requested operation. ","Note", MB_ICONEXCLAMATION|MB_OK);
  113. break;
  114. case DDERR_EXCLUSIVEMODEALREADYSET:
  115. MessageBox(MainWindow, "An attempt was made to set the cooperative level when it was already set to exclusive.","Note", MB_ICONEXCLAMATION|MB_OK);
  116. break;
  117. case DDERR_GENERIC:
  118. MessageBox(MainWindow, "Generic failure.","Note", MB_ICONEXCLAMATION|MB_OK);
  119. break;
  120. case DDERR_HEIGHTALIGN:
  121. MessageBox(MainWindow, "Height of rectangle provided is not a multiple of reqd alignment.","Note", MB_ICONEXCLAMATION|MB_OK);
  122. break;
  123. case DDERR_HWNDALREADYSET:
  124. MessageBox(MainWindow, "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or palettes created.","Note", MB_ICONEXCLAMATION|MB_OK);
  125. break;
  126. case DDERR_HWNDSUBCLASSED:
  127. MessageBox(MainWindow, "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring state.","Note", MB_ICONEXCLAMATION|MB_OK);
  128. break;
  129. case DDERR_IMPLICITLYCREATED:
  130. MessageBox(MainWindow, "This surface can not be restored because it is an implicitly created surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  131. break;
  132. case DDERR_INCOMPATIBLEPRIMARY:
  133. MessageBox(MainWindow, "Unable to match primary surface creation request with existing primary surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  134. break;
  135. case DDERR_INVALIDCAPS:
  136. MessageBox(MainWindow, "One or more of the caps bits passed to the callback are incorrect.","Note", MB_ICONEXCLAMATION|MB_OK);
  137. break;
  138. case DDERR_INVALIDCLIPLIST:
  139. MessageBox(MainWindow, "DirectDraw does not support the provided cliplist.","Note", MB_ICONEXCLAMATION|MB_OK);
  140. break;
  141. case DDERR_INVALIDDIRECTDRAWGUID:
  142. MessageBox(MainWindow, "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier.","Note", MB_ICONEXCLAMATION|MB_OK);
  143. break;
  144. case DDERR_INVALIDMODE:
  145. MessageBox(MainWindow, "DirectDraw does not support the requested mode.","Note", MB_ICONEXCLAMATION|MB_OK);
  146. break;
  147. case DDERR_INVALIDOBJECT:
  148. MessageBox(MainWindow, "DirectDraw received a pointer that was an invalid DIRECTDRAW object.","Note", MB_ICONEXCLAMATION|MB_OK);
  149. break;
  150. case DDERR_INVALIDPARAMS:
  151. MessageBox(MainWindow, "One or more of the parameters passed to the function are incorrect.","Note", MB_ICONEXCLAMATION|MB_OK);
  152. break;
  153. case DDERR_INVALIDPIXELFORMAT:
  154. MessageBox(MainWindow, "The pixel format was invalid as specified.","Note", MB_ICONEXCLAMATION|MB_OK);
  155. break;
  156. case DDERR_INVALIDPOSITION:
  157. MessageBox(MainWindow, "Returned when the position of the overlay on the destination is no longer legal for that destination.","Note", MB_ICONEXCLAMATION|MB_OK);
  158. break;
  159. case DDERR_INVALIDRECT:
  160. MessageBox(MainWindow, "Rectangle provided was invalid.","Note", MB_ICONEXCLAMATION|MB_OK);
  161. break;
  162. case DDERR_INVALIDSURFACETYPE:
  163. MessageBox(MainWindow, "The requested action could not be performed because the surface was of the wrong type.","Note", MB_ICONEXCLAMATION|MB_OK);
  164. break;
  165. case DDERR_LOCKEDSURFACES:
  166. MessageBox(MainWindow, "Operation could not be carried out because one or more surfaces are locked.","Note", MB_ICONEXCLAMATION|MB_OK);
  167. break;
  168. case DDERR_NO3D:
  169. MessageBox(MainWindow, "There is no 3D present.","Note", MB_ICONEXCLAMATION|MB_OK);
  170. break;
  171. case DDERR_NOALPHAHW:
  172. MessageBox(MainWindow, "Operation could not be carried out because there is no alpha accleration hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  173. break;
  174. #if(0)
  175. case DDERR_NOANTITEARHW:
  176. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware support for synchronizing blts to avoid tearing. ","Note", MB_ICONEXCLAMATION|MB_OK);
  177. break;
  178. #endif
  179. case DDERR_NOBLTHW:
  180. MessageBox(MainWindow, "No blter hardware present.","Note", MB_ICONEXCLAMATION|MB_OK);
  181. break;
  182. #if(0)
  183. case DDERR_NOBLTQUEUEHW:
  184. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware support for asynchronous blting. ","Note", MB_ICONEXCLAMATION|MB_OK);
  185. break;
  186. #endif
  187. case DDERR_NOCLIPLIST:
  188. MessageBox(MainWindow, "No cliplist available.","Note", MB_ICONEXCLAMATION|MB_OK);
  189. break;
  190. case DDERR_NOCLIPPERATTACHED:
  191. MessageBox(MainWindow, "No clipper object attached to surface object.","Note", MB_ICONEXCLAMATION|MB_OK);
  192. break;
  193. case DDERR_NOCOLORCONVHW:
  194. MessageBox(MainWindow, "Operation could not be carried out because there is no color conversion hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  195. break;
  196. case DDERR_NOCOLORKEY:
  197. MessageBox(MainWindow, "Surface doesn't currently have a color key","Note", MB_ICONEXCLAMATION|MB_OK);
  198. break;
  199. case DDERR_NOCOLORKEYHW:
  200. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware support of the destination color key.","Note", MB_ICONEXCLAMATION|MB_OK);
  201. break;
  202. case DDERR_NOCOOPERATIVELEVELSET:
  203. MessageBox(MainWindow, "Create function called without DirectDraw object method SetCooperativeLevel being called.","Note", MB_ICONEXCLAMATION|MB_OK);
  204. break;
  205. case DDERR_NODC:
  206. MessageBox(MainWindow, "No DC was ever created for this surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  207. break;
  208. case DDERR_NODDROPSHW:
  209. MessageBox(MainWindow, "No DirectDraw ROP hardware.","Note", MB_ICONEXCLAMATION|MB_OK);
  210. break;
  211. case DDERR_NODIRECTDRAWHW:
  212. MessageBox(MainWindow, "A hardware-only DirectDraw object creation was attempted but the driver did not support any hardware.","Note", MB_ICONEXCLAMATION|MB_OK);
  213. break;
  214. case DDERR_NODIRECTDRAWSUPPORT:
  215. MessageBox(MainWindow, "No DirectDraw support possible with current display driver.","Note", MB_ICONEXCLAMATION|MB_OK);
  216. break;
  217. case DDERR_NOEMULATION:
  218. MessageBox(MainWindow, "Software emulation not available.","Note", MB_ICONEXCLAMATION|MB_OK);
  219. break;
  220. case DDERR_NOEXCLUSIVEMODE:
  221. MessageBox(MainWindow, "Operation requires the application to have exclusive mode but the application does not have exclusive mode.","Note", MB_ICONEXCLAMATION|MB_OK);
  222. break;
  223. case DDERR_NOFLIPHW:
  224. MessageBox(MainWindow, "Flipping visible surfaces is not supported.","Note", MB_ICONEXCLAMATION|MB_OK);
  225. break;
  226. case DDERR_NOGDI:
  227. MessageBox(MainWindow, "There is no GDI present.","Note", MB_ICONEXCLAMATION|MB_OK);
  228. break;
  229. case DDERR_NOHWND:
  230. MessageBox(MainWindow, "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel HWND.","Note", MB_ICONEXCLAMATION|MB_OK);
  231. break;
  232. case DDERR_NOMIRRORHW:
  233. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  234. break;
  235. case DDERR_NOOVERLAYDEST:
  236. MessageBox(MainWindow, "Returned when GetOverlayPosition is called on an overlay that UpdateOverlay has never been called on to establish a destination.","Note", MB_ICONEXCLAMATION|MB_OK);
  237. break;
  238. case DDERR_NOOVERLAYHW:
  239. MessageBox(MainWindow, "Operation could not be carried out because there is no overlay hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  240. break;
  241. case DDERR_NOPALETTEATTACHED:
  242. MessageBox(MainWindow, "No palette object attached to this surface. ","Note", MB_ICONEXCLAMATION|MB_OK);
  243. break;
  244. case DDERR_NOPALETTEHW:
  245. MessageBox(MainWindow, "No hardware support for 16 or 256 color palettes.","Note", MB_ICONEXCLAMATION|MB_OK);
  246. break;
  247. case DDERR_NORASTEROPHW:
  248. MessageBox(MainWindow, "Operation could not be carried out because there is no appropriate raster op hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  249. break;
  250. case DDERR_NOROTATIONHW:
  251. MessageBox(MainWindow, "Operation could not be carried out because there is no rotation hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  252. break;
  253. case DDERR_NOSTRETCHHW:
  254. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware support for stretching.","Note", MB_ICONEXCLAMATION|MB_OK);
  255. break;
  256. case DDERR_NOT4BITCOLOR:
  257. MessageBox(MainWindow, "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette.","Note", MB_ICONEXCLAMATION|MB_OK);
  258. break;
  259. case DDERR_NOT4BITCOLORINDEX:
  260. MessageBox(MainWindow, "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette.","Note", MB_ICONEXCLAMATION|MB_OK);
  261. break;
  262. case DDERR_NOT8BITCOLOR:
  263. MessageBox(MainWindow, "DirectDrawSurface is not in 8 bit color mode and the requested operation requires 8 bit color.","Note", MB_ICONEXCLAMATION|MB_OK);
  264. break;
  265. case DDERR_NOTAOVERLAYSURFACE:
  266. MessageBox(MainWindow, "Returned when an overlay member is called for a non-overlay surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  267. break;
  268. case DDERR_NOTEXTUREHW:
  269. MessageBox(MainWindow, "Operation could not be carried out because there is no texture mapping hardware present or available.","Note", MB_ICONEXCLAMATION|MB_OK);
  270. break;
  271. case DDERR_NOTFLIPPABLE:
  272. MessageBox(MainWindow, "An attempt has been made to flip a surface that is not flippable.","Note", MB_ICONEXCLAMATION|MB_OK);
  273. break;
  274. case DDERR_NOTFOUND:
  275. MessageBox(MainWindow, "Requested item was not found.","Note", MB_ICONEXCLAMATION|MB_OK);
  276. break;
  277. case DDERR_NOTLOCKED:
  278. MessageBox(MainWindow, "Surface was not locked. An attempt to unlock a surface that was not locked at all, or by this process, has been attempted.","Note", MB_ICONEXCLAMATION|MB_OK);
  279. break;
  280. case DDERR_NOTPALETTIZED:
  281. MessageBox(MainWindow, "The surface being used is not a palette-based surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  282. break;
  283. case DDERR_NOVSYNCHW:
  284. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware support for vertical blank synchronized operations.","Note", MB_ICONEXCLAMATION|MB_OK);
  285. break;
  286. case DDERR_NOZBUFFERHW:
  287. MessageBox(MainWindow, "Operation could not be carried out because there is no hardware support for zbuffer blting.","Note", MB_ICONEXCLAMATION|MB_OK);
  288. break;
  289. case DDERR_NOZOVERLAYHW:
  290. MessageBox(MainWindow, "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays.","Note", MB_ICONEXCLAMATION|MB_OK);
  291. break;
  292. case DDERR_OUTOFCAPS:
  293. MessageBox(MainWindow, "The hardware needed for the requested operation has already been allocated.","Note", MB_ICONEXCLAMATION|MB_OK);
  294. break;
  295. case DDERR_OUTOFMEMORY:
  296. MessageBox(MainWindow, "DirectDraw does not have enough memory to perform the operation.","Note", MB_ICONEXCLAMATION|MB_OK);
  297. break;
  298. case DDERR_OUTOFVIDEOMEMORY:
  299. MessageBox(MainWindow, "DirectDraw does not have enough memory to perform the operation.","Note", MB_ICONEXCLAMATION|MB_OK);
  300. break;
  301. case DDERR_OVERLAYCANTCLIP:
  302. MessageBox(MainWindow, "The hardware does not support clipped overlays.","Note", MB_ICONEXCLAMATION|MB_OK);
  303. break;
  304. case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
  305. MessageBox(MainWindow, "Can only have ony color key active at one time for overlays.","Note", MB_ICONEXCLAMATION|MB_OK);
  306. break;
  307. case DDERR_OVERLAYNOTVISIBLE:
  308. MessageBox(MainWindow, "Returned when GetOverlayPosition is called on a hidden overlay.","Note", MB_ICONEXCLAMATION|MB_OK);
  309. break;
  310. case DDERR_PALETTEBUSY:
  311. MessageBox(MainWindow, "Access to this palette is being refused because the palette is already locked by another thread.","Note", MB_ICONEXCLAMATION|MB_OK);
  312. break;
  313. case DDERR_PRIMARYSURFACEALREADYEXISTS:
  314. MessageBox(MainWindow, "This process already has created a primary surface.","Note", MB_ICONEXCLAMATION|MB_OK);
  315. break;
  316. case DDERR_REGIONTOOSMALL:
  317. MessageBox(MainWindow, "Region passed to Clipper::GetClipList is too small.","Note", MB_ICONEXCLAMATION|MB_OK);
  318. break;
  319. case DDERR_SURFACEALREADYATTACHED:
  320. MessageBox(MainWindow, "This surface is already attached to the surface it is being attached to.","Note", MB_ICONEXCLAMATION|MB_OK);
  321. break;
  322. case DDERR_SURFACEALREADYDEPENDENT:
  323. MessageBox(MainWindow, "This surface is already a dependency of the surface it is being made a dependency of.","Note", MB_ICONEXCLAMATION|MB_OK);
  324. break;
  325. case DDERR_SURFACEBUSY:
  326. MessageBox(MainWindow, "Access to this surface is being refused because the surface is already locked by another thread.","Note", MB_ICONEXCLAMATION|MB_OK);
  327. break;
  328. case DDERR_SURFACEISOBSCURED:
  329. MessageBox(MainWindow, "Access to surface refused because the surface is obscured.","Note", MB_ICONEXCLAMATION|MB_OK);
  330. break;
  331. case DDERR_SURFACELOST:
  332. MessageBox(MainWindow, "Access to this surface is being refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have Restore called on it.","Note", MB_ICONEXCLAMATION|MB_OK);
  333. break;
  334. case DDERR_SURFACENOTATTACHED:
  335. MessageBox(MainWindow, "The requested surface is not attached.","Note", MB_ICONEXCLAMATION|MB_OK);
  336. break;
  337. case DDERR_TOOBIGHEIGHT:
  338. MessageBox(MainWindow, "Height requested by DirectDraw is too large.","Note", MB_ICONEXCLAMATION|MB_OK);
  339. break;
  340. case DDERR_TOOBIGSIZE:
  341. MessageBox(MainWindow, "Size requested by DirectDraw is too large -- the individual height and width are OK.","Note", MB_ICONEXCLAMATION|MB_OK);
  342. break;
  343. case DDERR_TOOBIGWIDTH:
  344. MessageBox(MainWindow, "Width requested by DirectDraw is too large.","Note", MB_ICONEXCLAMATION|MB_OK);
  345. break;
  346. case DDERR_UNSUPPORTED:
  347. MessageBox(MainWindow, "Action not supported.","Note", MB_ICONEXCLAMATION|MB_OK);
  348. break;
  349. case DDERR_UNSUPPORTEDFORMAT:
  350. MessageBox(MainWindow, "FOURCC format requested is unsupported by DirectDraw.","Note", MB_ICONEXCLAMATION|MB_OK);
  351. break;
  352. case DDERR_UNSUPPORTEDMASK:
  353. MessageBox(MainWindow, "Bitmask in the pixel format requested is unsupported by DirectDraw.","Note", MB_ICONEXCLAMATION|MB_OK);
  354. break;
  355. case DDERR_VERTICALBLANKINPROGRESS:
  356. MessageBox(MainWindow, "Vertical blank is in progress.","Note", MB_ICONEXCLAMATION|MB_OK);
  357. break;
  358. case DDERR_WASSTILLDRAWING:
  359. MessageBox(MainWindow, "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is incomplete.","Note", MB_ICONEXCLAMATION|MB_OK);
  360. break;
  361. case DDERR_WRONGMODE:
  362. MessageBox(MainWindow, "This surface can not be restored because it was created in a different mode.","Note", MB_ICONEXCLAMATION|MB_OK);
  363. break;
  364. case DDERR_XALIGN:
  365. MessageBox(MainWindow, "Rectangle provided was not horizontally aligned on required boundary.","Note", MB_ICONEXCLAMATION|MB_OK);
  366. break;
  367. default:
  368. char string[256];
  369. sprintf (string, "Unrecognised Direct Draw result code: %d", result & 0xffff);
  370. MessageBox(MainWindow, string,"Note", MB_ICONEXCLAMATION|MB_OK);
  371. break;
  372. }
  373. }
  374. /***********************************************************************************************
  375. * Check_Overlapped_Blit_Capability -- See if video driver supports blitting overlapped regions*
  376. * *
  377. * We will check for this by drawing something to a video page and blitting it over itself. *
  378. * If we end up with the top line repeating then overlapped region blits dont work. *
  379. * *
  380. * INPUT: Nothing *
  381. * *
  382. * OUTPUT: Nothing *
  383. * *
  384. * WARNINGS: None *
  385. * *
  386. * HISTORY: *
  387. * 6/7/96 5:06PM ST : Created *
  388. *=============================================================================================*/
  389. void Check_Overlapped_Blit_Capability(void)
  390. {
  391. /*
  392. ** Assume we can until we find out otherwise
  393. */
  394. OverlappedVideoBlits = TRUE;
  395. GraphicBufferClass test_buffer;
  396. test_buffer.Init (64, 64, NULL, 0, (GBC_Enum)GBC_VIDEOMEM);
  397. test_buffer.Clear();
  398. /*
  399. ** Plot a pixel in the top left corner of the buffer.
  400. */
  401. test_buffer.Put_Pixel(0, 0, 255);
  402. /*
  403. ** Blit the buffer down by one line. If we end up with a vertical strip of pixel 255's then
  404. ** overlapped blits dont work
  405. */
  406. test_buffer.Blit(test_buffer, 0, 0, 0, 1, test_buffer.Get_Width(), test_buffer.Get_Height()-1);
  407. if (test_buffer.Get_Pixel (0 ,5) == 255) OverlappedVideoBlits = FALSE;
  408. }
  409. /***********************************************************************************************
  410. * Set_Video_Mode -- Initializes Direct Draw and sets the required Video Mode *
  411. * *
  412. * INPUT: int width - the width of the video mode in pixels *
  413. * int height - the height of the video mode in pixels *
  414. * int bits_per_pixel - the number of bits per pixel the video mode supports *
  415. * *
  416. * OUTPUT: none *
  417. * *
  418. * HISTORY: *
  419. * 09/26/1995 PWG : Created. *
  420. *=============================================================================================*/
  421. BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel)
  422. {
  423. // ST - 1/3/2019 10:41AM
  424. return TRUE;
  425. #if (0)
  426. HRESULT result;
  427. //
  428. // If there is not currently a direct draw object then we need to define one.
  429. //
  430. if ( DirectDrawObject == NULL ){
  431. //MessageBox(MainWindow, "In Set_Video_Mode. About to call DirectDrawCreate.","Note", MB_ICONEXCLAMATION|MB_OK);
  432. result = DirectDrawCreate(NULL, &DirectDrawObject, NULL);
  433. Process_DD_Result(result, FALSE);
  434. if (result == DD_OK){
  435. if (w==320){
  436. result = DirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX);
  437. } else {
  438. //MessageBox(MainWindow, "In Set_Video_Mode. About to call SetCooperativeLevel.","Note", MB_ICONEXCLAMATION|MB_OK);
  439. result = DirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
  440. }
  441. Process_DD_Result(result, FALSE);
  442. }else{
  443. return (FALSE);
  444. }
  445. }
  446. //
  447. // Set the required display mode with 8 bits per pixel
  448. //
  449. //MessageBox(MainWindow, "In Set_Video_Mode. About to call call SetDisplayMode.","Note", MB_ICONEXCLAMATION|MB_OK);
  450. result = DirectDrawObject->SetDisplayMode ( w , h , bits_per_pixel );
  451. if (result != DD_OK){
  452. // Process_DD_Result(result, FALSE);
  453. DirectDrawObject->Release();
  454. DirectDrawObject = NULL;
  455. return(FALSE);
  456. }
  457. //
  458. // Create a direct draw palette object
  459. //
  460. //MessageBox(MainWindow, "In Set_Video_Mode. About to call CreatePalette.","Note", MB_ICONEXCLAMATION|MB_OK);
  461. result = DirectDrawObject->CreatePalette( DDPCAPS_8BIT | DDPCAPS_ALLOW256, &PaletteEntries[0] , &PalettePtr ,NULL);
  462. Process_DD_Result(result, FALSE);
  463. if (result != DD_OK){
  464. return (FALSE);
  465. }
  466. Check_Overlapped_Blit_Capability();
  467. //MessageBox(MainWindow, "In Set_Video_Mode. About to return success.","Note", MB_ICONEXCLAMATION|MB_OK);
  468. #if (0)
  469. /*
  470. ** Find out if DirectX 2 extensions are available
  471. */
  472. result = DirectDrawObject->QueryInterface (IID_IDirectDraw2, (LPVOID*)&DirectDraw2Interface);
  473. SystemToVideoBlits = FALSE;
  474. VideoToSystemBlits = FALSE;
  475. SystemToSystemBlits= FALSE;
  476. if (result != DD_OK){
  477. DirectDraw2Interface = NULL;
  478. }else{
  479. DDCAPS capabilities;
  480. DDCAPS emulated_capabilities;
  481. memset ((char*)&capabilities, 0, sizeof(capabilities));
  482. memset ((char*)&emulated_capabilities, 0, sizeof(emulated_capabilities));
  483. capabilities.dwSize = sizeof (capabilities);
  484. emulated_capabilities.dwSize = sizeof (emulated_capabilities);
  485. DirectDrawObject->GetCaps (&capabilities, &emulated_capabilities);
  486. if (capabilities.dwCaps & DDCAPS_CANBLTSYSMEM){
  487. SystemToVideoBlits = (capabilities.dwSVBCaps & DDCAPS_BLT) ? TRUE : FALSE;
  488. VideoToSystemBlits = (capabilities.dwVSBCaps & DDCAPS_BLT) ? TRUE : FALSE;
  489. SystemToSystemBlits = (capabilities.dwSSBCaps & DDCAPS_BLT) ? TRUE : FALSE;
  490. }
  491. }
  492. #endif //(0)
  493. //MessageBox(MainWindow, "In Set_Video_Mode. About to return success.","Note", MB_ICONEXCLAMATION|MB_OK);
  494. return (TRUE);
  495. #endif
  496. }
  497. /***********************************************************************************************
  498. * Reset_Video_Mode -- Resets video mode and deletes Direct Draw Object *
  499. * *
  500. * INPUT: none *
  501. * *
  502. * OUTPUT: none *
  503. * *
  504. * WARNINGS: *
  505. * *
  506. * HISTORY: *
  507. * 09/26/1995 PWG : Created. *
  508. *=============================================================================================*/
  509. void Reset_Video_Mode(void)
  510. {
  511. HRESULT result;
  512. //
  513. // If a direct draw object has been declared and a video mode has been set
  514. // then reset the video mode and release the direct draw object.
  515. //
  516. if ( DirectDrawObject ) {
  517. result = DirectDrawObject->RestoreDisplayMode();
  518. Process_DD_Result(result, FALSE);
  519. result = DirectDrawObject->Release();
  520. Process_DD_Result(result, FALSE);
  521. DirectDrawObject = NULL;
  522. }
  523. }
  524. /***********************************************************************************************
  525. * Get_Free_Video_Memory -- returns amount of free video memory *
  526. * *
  527. * *
  528. * *
  529. * INPUT: Nothing *
  530. * *
  531. * OUTPUT: bytes of available video RAM *
  532. * *
  533. * WARNINGS: None *
  534. * *
  535. * HISTORY: *
  536. * 11/29/95 12:52PM ST : Created *
  537. *=============================================================================================*/
  538. unsigned int Get_Free_Video_Memory(void)
  539. {
  540. DDCAPS video_capabilities;
  541. if (DirectDrawObject){
  542. video_capabilities.dwSize = sizeof (video_capabilities);
  543. //MessageBox(MainWindow, "In Get_Free_Video_Memory. About to call GetCaps","Note", MB_ICONEXCLAMATION|MB_OK);
  544. if (DD_OK == DirectDrawObject->GetCaps (&video_capabilities , NULL)){
  545. char string [256];
  546. sprintf (string, "In Get_Free_Video_Memory. About to return %d bytes",video_capabilities.dwVidMemFree);
  547. //MessageBox(MainWindow, string,"Note", MB_ICONEXCLAMATION|MB_OK);
  548. return (video_capabilities.dwVidMemFree);
  549. }
  550. }
  551. //MessageBox(MainWindow, "In Get_Free_Video_Memory. About to return failure","Note", MB_ICONEXCLAMATION|MB_OK);
  552. return (0);
  553. }
  554. /***********************************************************************************************
  555. * Get_Video_Hardware_Caps -- returns bitmask of direct draw video hardware support *
  556. * *
  557. * *
  558. * *
  559. * INPUT: Nothing *
  560. * *
  561. * OUTPUT: hardware flags *
  562. * *
  563. * WARNINGS: Must call Set_Video_Mode 1st to create the direct draw object *
  564. * *
  565. * HISTORY: *
  566. * 1/12/96 9:14AM ST : Created *
  567. *=============================================================================================*/
  568. unsigned Get_Video_Hardware_Capabilities(void)
  569. {
  570. DDCAPS video_capabilities;
  571. unsigned video;
  572. /*
  573. ** Fail if the direct draw object has not been initialised
  574. */
  575. if (!DirectDrawObject) return (0);
  576. /*
  577. ** Get the capabilities of the direct draw object
  578. */
  579. video_capabilities.dwSize = sizeof(video_capabilities);
  580. //MessageBox(MainWindow, "In Get_Video_Hardware_Capabilities. About to call GetCaps","Note", MB_ICONEXCLAMATION|MB_OK);
  581. HRESULT result = DirectDrawObject->GetCaps (&video_capabilities, NULL);
  582. if (result != DD_OK){
  583. Process_DD_Result(result, FALSE);
  584. return (0);
  585. }
  586. /*
  587. ** Set flags to indicate the presence of the features we are interested in
  588. */
  589. video = 0;
  590. /* Hardware blits supported? */
  591. if (video_capabilities.dwCaps & DDCAPS_BLT) video |= VIDEO_BLITTER;
  592. /* Hardware blits asyncronous? */
  593. if (video_capabilities.dwCaps & DDCAPS_BLTQUEUE) video |= VIDEO_BLITTER_ASYNC;
  594. /* Can palette changes be synced to vertical refresh? */
  595. if (video_capabilities.dwCaps & DDCAPS_PALETTEVSYNC) video |= VIDEO_SYNC_PALETTE;
  596. /* Is the video cards memory bank switched? */
  597. if (video_capabilities.dwCaps & DDCAPS_BANKSWITCHED) video |= VIDEO_BANK_SWITCHED;
  598. /* Can the blitter do filled rectangles? */
  599. if (video_capabilities.dwCaps & DDCAPS_BLTCOLORFILL) video |= VIDEO_COLOR_FILL;
  600. /* Is there no hardware assistance avaailable at all? */
  601. if (video_capabilities.dwCaps & DDCAPS_NOHARDWARE) video |= VIDEO_NO_HARDWARE_ASSIST;
  602. //MessageBox(MainWindow, "In Get_Video_Hardware_Capabilities. About to return success.","Note", MB_ICONEXCLAMATION|MB_OK);
  603. return (video);
  604. }
  605. /***********************************************************************************************
  606. * Wait_Vert_Blank -- Waits for the start (leading edge) of a vertical blank *
  607. * *
  608. * INPUT: *
  609. * *
  610. * OUTPUT: *
  611. * *
  612. * WARNINGS: *
  613. * *
  614. * HISTORY: *
  615. *=============================================================================================*/
  616. extern int ScreenWidth;
  617. void Wait_Vert_Blank(void)
  618. {
  619. if (DirectDrawObject == NULL) {
  620. return;
  621. }
  622. if( ScreenWidth!=320 && CanVblankSync){
  623. HRESULT result = DirectDrawObject->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0);
  624. if (result == E_NOTIMPL){
  625. CanVblankSync = FALSE;
  626. return;
  627. }
  628. Process_DD_Result(result, FALSE);
  629. }
  630. }
  631. /***********************************************************************************************
  632. * Set_Palette -- set a direct draw palette *
  633. * *
  634. * *
  635. * *
  636. * INPUT: ptr to 768 rgb palette bytes *
  637. * *
  638. * OUTPUT: Nothing *
  639. * *
  640. * WARNINGS: None *
  641. * *
  642. * HISTORY: *
  643. * 10/11/95 3:33PM ST : Created *
  644. *=============================================================================================*/
  645. void Set_DD_Palette ( void *palette )
  646. {
  647. /*
  648. ** Trap null ptr
  649. */
  650. if (!palette) return;
  651. int j;
  652. int k;
  653. char *palette_get;
  654. if ( DirectDrawObject && PaletteSurface ){
  655. k=0;
  656. palette_get = (char*)palette;
  657. for( j=0 ; j<768 ; j+=3 )
  658. {
  659. PaletteEntries[k].peRed = (unsigned char)((*palette_get++)<<2);
  660. PaletteEntries[k].peGreen = (unsigned char)((*palette_get++)<<2);
  661. PaletteEntries[k].peBlue = (unsigned char)((*palette_get++)<<2);
  662. k++;
  663. }
  664. if ( !FirstPaletteSet ){
  665. //MessageBox(MainWindow, "In Set_DD_Palette. About to call SetPalette","Note", MB_ICONEXCLAMATION|MB_OK);
  666. PaletteSurface->SetPalette( PalettePtr );
  667. FirstPaletteSet=TRUE;
  668. }
  669. //MessageBox(MainWindow, "In Set_DD_Palette. About to call SetEntries","Note", MB_ICONEXCLAMATION|MB_OK);
  670. PalettePtr->SetEntries( 0 , 0 , 256 , &PaletteEntries[0] );
  671. }
  672. //MessageBox(MainWindow, "Leaving Set_DD_Palette","Note", MB_ICONEXCLAMATION|MB_OK);
  673. }
  674. /***********************************************************************************************
  675. * Wait_Blit -- waits for the DirectDraw blitter to become idle *
  676. * *
  677. * *
  678. * *
  679. * INPUT: Nothing *
  680. * *
  681. * OUTPUT: Nothing *
  682. * *
  683. * WARNINGS: None *
  684. * *
  685. * HISTORY: *
  686. * 07-25-95 03:53pm ST : Created *
  687. *=============================================================================================*/
  688. void Wait_Blit (void)
  689. {
  690. HRESULT return_code;
  691. do {
  692. return_code=PaletteSurface->GetBltStatus (DDGBS_ISBLTDONE);
  693. } while (return_code != DD_OK && return_code != DDERR_SURFACELOST);
  694. }
  695. /***********************************************************************************************
  696. * SMC::SurfaceMonitorClass -- constructor for surface monitor class *
  697. * *
  698. * *
  699. * *
  700. * INPUT: Nothing *
  701. * *
  702. * OUTPUT: Nothing *
  703. * *
  704. * WARNINGS: None *
  705. * *
  706. * HISTORY: *
  707. * 11/3/95 3:23PM ST : Created *
  708. *=============================================================================================*/
  709. SurfaceMonitorClass::SurfaceMonitorClass(void)
  710. {
  711. for (int i=0 ; i<MAX_SURFACES ; i++)
  712. {
  713. Surface[i]=NULL;
  714. }
  715. InFocus=FALSE;
  716. SurfacesRestored=FALSE;
  717. }
  718. /***********************************************************************************************
  719. * SMC::Add_DD_Surface -- add a new surface to the list *
  720. * *
  721. * *
  722. * *
  723. * INPUT: ptr to surface *
  724. * *
  725. * OUTPUT: Nothing *
  726. * *
  727. * WARNINGS: None *
  728. * *
  729. * HISTORY: *
  730. * 11/3/95 3:24PM ST : Created *
  731. *=============================================================================================*/
  732. void SurfaceMonitorClass::Add_DD_Surface (LPDIRECTDRAWSURFACE new_surface)
  733. {
  734. if ( !Got_Surface_Already (new_surface) ){
  735. for (int i=0 ; i<MAX_SURFACES ; i++)
  736. {
  737. if ( Surface[i]==NULL ){
  738. Surface[i]=new_surface;
  739. return;
  740. }
  741. }
  742. }
  743. }
  744. /***********************************************************************************************
  745. * SMC::Remove_DD_Surface -- remove a direct draw surface from the list *
  746. * *
  747. * *
  748. * *
  749. * INPUT: ptr to Surface *
  750. * *
  751. * OUTPUT: Nothing *
  752. * *
  753. * WARNINGS: None *
  754. * *
  755. * HISTORY: *
  756. * 11/3/95 3:25PM ST : Created *
  757. *=============================================================================================*/
  758. void SurfaceMonitorClass::Remove_DD_Surface (LPDIRECTDRAWSURFACE old_surface)
  759. {
  760. for (int i=0 ; i<MAX_SURFACES ; i++)
  761. {
  762. if ( Surface[i]==old_surface ){
  763. Surface[i]=NULL;
  764. return;
  765. }
  766. }
  767. }
  768. /***********************************************************************************************
  769. * SMC::Got_Surface_Already -- check if a surface is already in the list *
  770. * *
  771. * *
  772. * *
  773. * INPUT: ptr to surface *
  774. * *
  775. * OUTPUT: True if surface is in list *
  776. * *
  777. * WARNINGS: None *
  778. * *
  779. * HISTORY: *
  780. * 11/3/95 3:25PM ST : Created *
  781. *=============================================================================================*/
  782. BOOL SurfaceMonitorClass::Got_Surface_Already (LPDIRECTDRAWSURFACE test_surface)
  783. {
  784. for (int i=0 ; i<MAX_SURFACES ; i++)
  785. {
  786. if ( Surface[i]==test_surface ){
  787. return(TRUE);
  788. }
  789. }
  790. return (FALSE);
  791. }
  792. /***********************************************************************************************
  793. * SMC::Restore_Surfaces -- restore the direct draw surfaces in the list *
  794. * *
  795. * *
  796. * *
  797. * INPUT: Nothing *
  798. * *
  799. * OUTPUT: Nothing *
  800. * *
  801. * WARNINGS: None *
  802. * *
  803. * HISTORY: *
  804. * 11/3/95 3:26PM ST : Created *
  805. *=============================================================================================*/
  806. void SurfaceMonitorClass::Restore_Surfaces (void)
  807. {
  808. if (InFocus){
  809. /*
  810. ** Call restore for each Direct Draw surface
  811. */
  812. for (int i=0 ; i<MAX_SURFACES ; i++)
  813. {
  814. if ( Surface[i] ){
  815. if (Surface[i]->Restore() != DD_OK){
  816. if (Misc_Focus_Loss_Function){
  817. Misc_Focus_Loss_Function();
  818. }
  819. return;
  820. }
  821. }
  822. }
  823. /*
  824. ** PWG/ST: Now that we know all the surfaces are restored call
  825. ** the function pointer to notify the program that it has
  826. ** happened. This function pointer is used to clear the pages,
  827. ** etc.
  828. */
  829. if (Misc_Focus_Restore_Function){
  830. Misc_Focus_Restore_Function();
  831. }
  832. SurfacesRestored = TRUE;
  833. /*
  834. ** Restore the palette
  835. */
  836. Set_DD_Palette (CurrentPalette);
  837. }
  838. }
  839. /***********************************************************************************************
  840. * SMC::Set_Surface_Focus -- set the InFocus flag to the given state *
  841. * *
  842. * The InFocus flag is used to keep track of whether our application is currently in focus. *
  843. * We dont want to be restoring video surfaces when we are supposed to be running in the *
  844. * background. *
  845. * *
  846. * INPUT: bool in focus *
  847. * *
  848. * OUTPUT: Nothing *
  849. * *
  850. * WARNINGS: None *
  851. * *
  852. * HISTORY: *
  853. * 11/6/95 12:21PM ST : Created *
  854. *=============================================================================================*/
  855. void SurfaceMonitorClass::Set_Surface_Focus ( BOOL in_focus )
  856. {
  857. InFocus=in_focus;
  858. }
  859. /***********************************************************************************************
  860. * SMC::Release -- releases all direct draw surfaces *
  861. * *
  862. * Call this at the end of the game before called RestoreDisplayMode *
  863. * *
  864. * INPUT: Nothing *
  865. * *
  866. * OUTPUT: Nothing *
  867. * *
  868. * WARNINGS: None *
  869. * *
  870. * HISTORY: *
  871. * 6/6/96 12:23PM ST : Created *
  872. *=============================================================================================*/
  873. void SurfaceMonitorClass::Release(void)
  874. {
  875. /*
  876. ** Call release for each Direct Draw surface
  877. */
  878. for (int i=0 ; i<MAX_SURFACES ; i++)
  879. {
  880. if ( Surface[i] ){
  881. Surface[i]->Release();
  882. Surface[i] = 0;
  883. }
  884. }
  885. }