Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
ddraw.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /Commando/Code/Library/DDRAW.CPP $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 10/15/98 11:05a $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * Set_Video_Mode -- Initializes Direct Draw and sets the required Video Mode *
36 * Process_DD_Result -- Does a message box based on the result of a DD command *
37 * Reset_Video_Mode -- Resets video mode and deletes Direct Draw Object *
38 * Get_Free_Video_Memory -- returns amount of free video memory *
39 * Get_Video_Hardware_Caps -- returns bitmask of direct draw video hardware support *
40 * Wait_Vert_Blank -- Waits for the start (leading edge) of a vertical blank *
41 * Set_Palette -- set a direct draw palette *
42 * Check_Overlapped_Blit_Capability -- See if video driver supports blitting overlapped regions*
43 * Wait_Blit -- waits for the DirectDraw blitter to become idle *
44 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
45
46#include "always.h"
47#include "misc.h"
48#include "dsurface.h"
49#include "data.h"
50#include "_timer.h"
51#include <assert.h>
52#include <stdio.h>
53
54
55LPDIRECTDRAW DirectDrawObject = NULL; // Pointer to the direct draw object
56LPDIRECTDRAW2 DirectDraw2Interface = NULL; // Pointer to direct draw 2 interface
57
58static PALETTEENTRY PaletteEntries[256]; // 256 windows palette entries
59static LPDIRECTDRAWPALETTE PalettePtr; // Pointer to direct draw palette object
60static bool FirstPaletteSet = false; // Is this the first time 'Set_Palette' has been called?
61LPDIRECTDRAWSURFACE PaletteSurface = NULL;
62bool SurfacesRestored = false;
63static bool CanVblankSync = true;
64
65unsigned char CurrentPalette[768];
67
68int (*DirectDrawErrorHandler)(HRESULT error) = NULL;
69
70void Set_Palette(PaletteClass const & pal, int time, void (*callback)())
71{
73 PaletteClass original;
74 memcpy(&original, CurrentPalette, sizeof(CurrentPalette));
75 PaletteClass newpal = pal;
76
77 while (timer) {
78
79 /*
80 ** Build an intermediate palette that is as close to the destination palette
81 ** as the current time is proportional to the ending time.
82 */
83 PaletteClass palette = original;
84 int adjust = ((time - timer) * 256) / time;
85 adjust = MIN(adjust, 255);
86 palette.Adjust(adjust, newpal);
87
88 /*
89 ** Remember the current time so that multiple palette sets within the same game
90 ** time tick won't occur. This is probably unnecessary since the palette setting
91 ** code, at the time of this writing, delays at least one game tick in the process
92 ** of setting the palette.
93 */
94 int holdtime = timer;
95
96 /*
97 ** Set the palette to this intermediate palette and then loop back
98 ** to calculate and set a new intermediate palette.
99 */
100 Set_Palette((void*)&palette[0]);
101
102 /*
103 ** If the callback routine was specified, then call it once per palette
104 ** setting loop.
105 */
106 if (callback) {
107 callback();
108 }
109
110 /*
111 ** This loop ensures that the palette won't be set more than once per game tick. Setting
112 ** the palette more than once per game tick will have no effect since the calculation will
113 ** result in the same intermediate palette that was previously calculated.
114 */
115 while (timer == holdtime && holdtime != 0) {
116 if (callback) callback();
117 }
118 }
119
120 /*
121 ** Ensure that the final palette exactly matches the requested
122 ** palette before exiting the fading routine.
123 */
124 Set_Palette((void*)&newpal[0]);
125}
126
127
128/***********************************************************************************************
129 * Process_DD_Result -- Does a message box based on the result of a DD command *
130 * *
131 * INPUT: HRESULT result - the result returned from the direct draw command *
132 * int display_ok_msg - should a message be displayed if command ok * *
133 * *
134 * OUTPUT: none *
135 * *
136 * HISTORY: *
137 * 09/27/1995 PWG : Created. *
138 *=============================================================================================*/
139void Process_DD_Result(HRESULT result, int display_ok_msg)
140{
141#ifdef _DEBUG
142 static struct {
143 HRESULT Error;
144 char const * Message;
145 } _errors[] = {
146 {DDERR_ALREADYINITIALIZED, "This object is already initialized"},
147 {DDERR_BLTFASTCANTCLIP, "Return if a clipper object is attached to the source surface passed into a BltFast call."},
148 {DDERR_CANNOTATTACHSURFACE, "This surface can not be attached to the requested surface."},
149 {DDERR_CANNOTDETACHSURFACE, "This surface can not be detached from the requested surface."},
150 {DDERR_CANTCREATEDC, "Windows can not create any more DCs"},
151 {DDERR_CANTDUPLICATE, "Can't duplicate primary & 3D surfaces, or surfaces that are implicitly created."},
152 {DDERR_CANTLOCKSURFACE, "Unable to lock surface because no driver exists which can supply a pointer to the surface."},
153 {DDERR_CLIPPERISUSINGHWND, "An attempt was made to set a cliplist for a clipper object that is already monitoring an hwnd."},
154 {DDERR_COLORKEYNOTSET, "No src color key specified for this operation."},
155 {DDERR_CURRENTLYNOTAVAIL, "Support is currently not available."},
156 {DDERR_DIRECTDRAWALREADYCREATED, "A DirectDraw object representing this driver has already been created for this process."},
157 {DDERR_EXCEPTION, "An exception was encountered while performing the requested operation."},
158 {DDERR_EXCLUSIVEMODEALREADYSET, "An attempt was made to set the cooperative level when it was already set to exclusive."},
159 {DDERR_GENERIC, "Generic failure."},
160 {DDERR_HEIGHTALIGN, "Height of rectangle provided is not a multiple of reqd alignment."},
161 {DDERR_HWNDALREADYSET, "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or palettes created."},
162 {DDERR_HWNDSUBCLASSED, "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring state."},
163 {DDERR_IMPLICITLYCREATED, "This surface can not be restored because it is an implicitly created surface."},
164 {DDERR_INCOMPATIBLEPRIMARY, "Unable to match primary surface creation request with existing primary surface."},
165 {DDERR_INVALIDCAPS, "One or more of the caps bits passed to the callback are incorrect."},
166 {DDERR_INVALIDCLIPLIST, "DirectDraw does not support the provided cliplist."},
167 {DDERR_INVALIDDIRECTDRAWGUID, "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier."},
168 {DDERR_INVALIDMODE, "DirectDraw does not support the requested mode."},
169 {DDERR_INVALIDOBJECT, "DirectDraw received a pointer that was an invalid DIRECTDRAW object."},
170 {DDERR_INVALIDPARAMS, "One or more of the parameters passed to the function are incorrect."},
171 {DDERR_INVALIDPIXELFORMAT, "The pixel format was invalid as specified."},
172 {DDERR_INVALIDPOSITION, "Returned when the position of the overlay on the destination is no longer legal for that destination."},
173 {DDERR_INVALIDRECT, "Rectangle provided was invalid."},
174 {DDERR_INVALIDSURFACETYPE, "The requested action could not be performed because the surface was of the wrong type."},
175 {DDERR_LOCKEDSURFACES, "Operation could not be carried out because one or more surfaces are locked."},
176 {DDERR_NO3D, "There is no 3D present."},
177 {DDERR_NOALPHAHW, "Operation could not be carried out because there is no alpha accleration hardware present or available."},
178// {DDERR_NOANTITEARHW, "Operation could not be carried out because there is no hardware support for synchronizing blts to avoid tearing. "},
179 {DDERR_NOBLTHW, "No blter hardware present."},
180// {DDERR_NOBLTQUEUEHW, "Operation could not be carried out because there is no hardware support for asynchronous blting."},
181 {DDERR_NOCLIPLIST, "No cliplist available."},
182 {DDERR_NOCLIPPERATTACHED, "No clipper object attached to surface object."},
183 {DDERR_NOCOLORCONVHW, "Operation could not be carried out because there is no color conversion hardware present or available."},
184 {DDERR_NOCOLORKEY, "Surface doesn't currently have a color key"},
185 {DDERR_NOCOLORKEYHW, "Operation could not be carried out because there is no hardware support of the destination color key."},
186 {DDERR_NOCOOPERATIVELEVELSET, "Create function called without DirectDraw object method SetCooperativeLevel being called."},
187 {DDERR_NODC, "No DC was ever created for this surface."},
188 {DDERR_NODDROPSHW, "No DirectDraw ROP hardware."},
189 {DDERR_NODIRECTDRAWHW, "A hardware-only DirectDraw object creation was attempted but the driver did not support any hardware."},
190 {DDERR_NODIRECTDRAWSUPPORT, "No DirectDraw support possible with current display driver."},
191 {DDERR_NOEMULATION, "Software emulation not available."},
192 {DDERR_NOEXCLUSIVEMODE, "Operation requires the application to have exclusive mode but the application does not have exclusive mode."},
193 {DDERR_NOFLIPHW, "Flipping visible surfaces is not supported."},
194 {DDERR_NOGDI, "There is no GDI present."},
195 {DDERR_NOHWND, "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel HWND."},
196 {DDERR_NOMIRRORHW, "Operation could not be carried out because there is no hardware present or available."},
197 {DDERR_NOOVERLAYDEST, "Returned when GetOverlayPosition is called on an overlay that UpdateOverlay has never been called on to establish a destination."},
198 {DDERR_NOOVERLAYHW, "Operation could not be carried out because there is no overlay hardware present or available."},
199 {DDERR_NOPALETTEATTACHED, "No palette object attached to this surface. "},
200 {DDERR_NOPALETTEHW, "No hardware support for 16 or 256 color palettes."},
201 {DDERR_NORASTEROPHW, "Operation could not be carried out because there is no appropriate raster op hardware present or available."},
202 {DDERR_NOROTATIONHW, "Operation could not be carried out because there is no rotation hardware present or available."},
203 {DDERR_NOSTRETCHHW, "Operation could not be carried out because there is no hardware support for stretching."},
204 {DDERR_NOT4BITCOLOR, "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette."},
205 {DDERR_NOT4BITCOLORINDEX, "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette."},
206 {DDERR_NOT8BITCOLOR, "DirectDrawSurface is not in 8 bit color mode and the requested operation requires 8 bit color."},
207 {DDERR_NOTAOVERLAYSURFACE, "Returned when an overlay member is called for a non-overlay surface."},
208 {DDERR_NOTEXTUREHW, "Operation could not be carried out because there is no texture mapping hardware present or available."},
209 {DDERR_NOTFLIPPABLE, "An attempt has been made to flip a surface that is not flippable."},
210 {DDERR_NOTFOUND, "Requested item was not found."},
211 {DDERR_NOTLOCKED, "Surface was not locked. An attempt to unlock a surface that was not locked at all, or by this process, has been attempted."},
212 {DDERR_NOTPALETTIZED, "The surface being used is not a palette-based surface."},
213 {DDERR_NOVSYNCHW, "Operation could not be carried out because there is no hardware support for vertical blank synchronized operations."},
214 {DDERR_NOZBUFFERHW, "Operation could not be carried out because there is no hardware support for zbuffer blting."},
215 {DDERR_NOZOVERLAYHW, "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays."},
216 {DDERR_OUTOFCAPS, "The hardware needed for the requested operation has already been allocated."},
217 {DDERR_OUTOFMEMORY, "DirectDraw does not have enough memory to perform the operation."},
218 {DDERR_OUTOFVIDEOMEMORY, "DirectDraw does not have enough memory to perform the operation."},
219 {DDERR_OVERLAYCANTCLIP, "The hardware does not support clipped overlays."},
220 {DDERR_OVERLAYCOLORKEYONLYONEACTIVE, "Can only have ony color key active at one time for overlays."},
221 {DDERR_OVERLAYNOTVISIBLE, "Returned when GetOverlayPosition is called on a hidden overlay."},
222 {DDERR_PALETTEBUSY, "Access to this palette is being refused because the palette is already locked by another thread."},
223 {DDERR_PRIMARYSURFACEALREADYEXISTS, "This process already has created a primary surface."},
224 {DDERR_REGIONTOOSMALL, "Region passed to Clipper::GetClipList is too small."},
225 {DDERR_SURFACEALREADYATTACHED, "This surface is already attached to the surface it is being attached to."},
226 {DDERR_SURFACEALREADYDEPENDENT, "This surface is already a dependency of the surface it is being made a dependency of."},
227 {DDERR_SURFACEBUSY, "Access to this surface is being refused because the surface is already locked by another thread."},
228 {DDERR_SURFACEISOBSCURED, "Access to surface refused because the surface is obscured."},
229 {DDERR_SURFACELOST, "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."},
230 {DDERR_SURFACENOTATTACHED, "The requested surface is not attached."},
231 {DDERR_TOOBIGHEIGHT, "Height requested by DirectDraw is too large."},
232 {DDERR_TOOBIGSIZE, "Size requested by DirectDraw is too large -- the individual height and width are OK."},
233 {DDERR_TOOBIGWIDTH, "Width requested by DirectDraw is too large."},
234 {DDERR_UNSUPPORTED, "Action not supported."},
235 {DDERR_UNSUPPORTEDFORMAT, "FOURCC format requested is unsupported by DirectDraw."},
236 {DDERR_UNSUPPORTEDMASK, "Bitmask in the pixel format requested is unsupported by DirectDraw."},
237 {DDERR_VERTICALBLANKINPROGRESS, "Vertical blank is in progress."},
238 {DDERR_WASSTILLDRAWING, "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is incomplete."},
239 {DDERR_WRONGMODE, "This surface can not be restored because it was created in a different mode."},
240 {DDERR_XALIGN, "Rectangle provided was not horizontally aligned on required boundary."}
241 };
242#endif
243 /*
244 ** If there iwas no error detected, then either bail out or display a message to
245 ** this effect as indicated by the "display_ok_msg" parameter.
246 */
247 if (result == DD_OK) {
248 if (display_ok_msg) {
249 MessageBox(MainWindow, "Direct Draw operation processed without error", "Note", MB_OK);
250 }
251 return;
252 }
253
256 return;
257 }
258#ifdef _DEBUG
259 /*
260 ** Scan for a matching error code and display the appropriate message.
261 */
262 for (int index = 0; index < ARRAY_SIZE(_errors); index++) {
263 if (_errors[index].Error == result) {
264 MessageBox(MainWindow, _errors[index].Message, "Westwood Library Direct Draw Error", MB_ICONEXCLAMATION|MB_OK);
265 return;
266 }
267 }
268#endif
269
270 /*
271 ** Since it fell out of the above loop, this must be an unrecognized error code.
272 */
273 char str[80];
274 sprintf(str, "DDRAW.DLL Error code = %08X", result);
275 MessageBox(MainWindow, str, "Direct X", MB_ICONEXCLAMATION|MB_OK);
276}
277
278
279/***********************************************************************************************
280 * Check_Overlapped_Blit_Capability -- See if video driver supports blitting overlapped regions*
281 * *
282 * We will check for this by drawing something to a video page and blitting it over itself. *
283 * If we end up with the top line repeating then overlapped region blits dont work. *
284 * *
285 * INPUT: Nothing *
286 * *
287 * OUTPUT: Nothing *
288 * *
289 * WARNINGS: None *
290 * *
291 * HISTORY: *
292 * 6/7/96 5:06PM ST : Created *
293 *=============================================================================================*/
295{
296// OverlappedVideoBlits = false;
297
298#ifdef NEVER
299 /*
300 ** Assume we can until we find out otherwise
301 */
302 OverlappedVideoBlits = true;
303
304 GraphicBufferClass test_buffer;
305
306 test_buffer.Init (64, 64, NULL, 0, (GBC_Enum)GBC_VIDEOMEM);
307
308 test_buffer.Clear();
309
310 /*
311 ** Plot a pixel in the top left corner of the buffer.
312 */
313 test_buffer.Put_Pixel(0, 0, 255);
314
315 /*
316 ** Blit the buffer down by one line. If we end up with a vertical strip of pixel 255's then
317 ** overlapped blits dont work
318 */
319
320 test_buffer.Blit(test_buffer, 0, 0, 0, 1, test_buffer.Get_Width(), test_buffer.Get_Height()-1);
321
322 if (test_buffer.Get_Pixel(0, 5) == 255) OverlappedVideoBlits = false;
323#endif
324}
325
326
328{
329 //
330 // If there is not currently a direct draw object then we need to define one.
331 //
332 if ( DirectDrawObject == NULL ) {
333 HRESULT result = DirectDrawCreate(NULL, &DirectDrawObject, NULL);
334 Process_DD_Result(result, false);
335 if (result == DD_OK) {
336 if (Debug_Windowed) {
337 result = DirectDrawObject->SetCooperativeLevel(MainWindow, DDSCL_NORMAL);
338 } else {
339 result = DirectDrawObject->SetCooperativeLevel(MainWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
340 }
341 Process_DD_Result(result, false);
342 }
343 }
344}
345
346
347
348/***********************************************************************************************
349 * Set_Video_Mode -- Initializes Direct Draw and sets the required Video Mode *
350 * *
351 * INPUT: int width - the width of the video mode in pixels *
352 * int height - the height of the video mode in pixels *
353 * int bits_per_pixel - the number of bits per pixel the video mode supports *
354 * *
355 * OUTPUT: none *
356 * *
357 * HISTORY: *
358 * 09/26/1995 PWG : Created. *
359 *=============================================================================================*/
360bool Set_Video_Mode(HWND , int w, int h, int bits_per_pixel)
361{
362 HRESULT result;
363
365
366 //
367 // Set the required display mode with 8 bits per pixel
368 //
369 //MessageBox(MainWindow, "In Set_Video_Mode. About to call call SetDisplayMode.","Note", MB_ICONEXCLAMATION|MB_OK);
370 result = DirectDrawObject->SetDisplayMode(w, h, bits_per_pixel);
371 if (result != DD_OK) {
372// Process_DD_Result(result, false);
373 DirectDrawObject->Release();
375 return(false);
376 }
377
378 //
379 // Create a direct draw palette object
380 //
381 //MessageBox(MainWindow, "In Set_Video_Mode. About to call CreatePalette.","Note", MB_ICONEXCLAMATION|MB_OK);
382 result = DirectDrawObject->CreatePalette( DDPCAPS_8BIT | DDPCAPS_ALLOW256, &PaletteEntries[0], &PalettePtr, NULL);
383 Process_DD_Result(result, false);
384 if (result != DD_OK) {
385 return (false);
386 }
387
389
390 //MessageBox(MainWindow, "In Set_Video_Mode. About to return success.","Note", MB_ICONEXCLAMATION|MB_OK);
391#if (0)
392 /*
393 ** Find out if DirectX 2 extensions are available
394 */
395 result = DirectDrawObject->QueryInterface (IID_IDirectDraw2, (LPVOID*)&DirectDraw2Interface);
396 SystemToVideoBlits = false;
397 VideoToSystemBlits = false;
398 SystemToSystemBlits= false;
399 if (result != DD_OK) {
401 } else {
402 DDCAPS capabilities;
403 DDCAPS emulated_capabilities;
404
405 memset ((char*)&capabilities, 0, sizeof(capabilities));
406 memset ((char*)&emulated_capabilities, 0, sizeof(emulated_capabilities));
407 capabilities.dwSize = sizeof (capabilities);
408 emulated_capabilities.dwSize = sizeof (emulated_capabilities);
409
410 DirectDrawObject->GetCaps (&capabilities, &emulated_capabilities);
411
412 if (capabilities.dwCaps & DDCAPS_CANBLTSYSMEM) {
413 SystemToVideoBlits = (capabilities.dwSVBCaps & DDCAPS_BLT) ? true : false;
414 VideoToSystemBlits = (capabilities.dwVSBCaps & DDCAPS_BLT) ? true : false;
415 SystemToSystemBlits = (capabilities.dwSSBCaps & DDCAPS_BLT) ? true : false;
416 }
417 }
418#endif //(0)
419
420 //MessageBox(MainWindow, "In Set_Video_Mode. About to return success.","Note", MB_ICONEXCLAMATION|MB_OK);
421
422 return (true);
423
424}
425
426/***********************************************************************************************
427 * Reset_Video_Mode -- Resets video mode and deletes Direct Draw Object *
428 * *
429 * INPUT: none *
430 * *
431 * OUTPUT: none *
432 * *
433 * WARNINGS: *
434 * *
435 * HISTORY: *
436 * 09/26/1995 PWG : Created. *
437 *=============================================================================================*/
439{
440 HRESULT result;
441
442 //
443 // If a direct draw object has been declared and a video mode has been set
444 // then reset the video mode and release the direct draw object.
445 //
446 if ( DirectDrawObject ) {
447 result = DirectDrawObject->RestoreDisplayMode();
448 Process_DD_Result(result, false);
449 result = DirectDrawObject->Release();
450 Process_DD_Result(result, false);
451
453 }
454}
455
456
457/***********************************************************************************************
458 * Get_Free_Video_Memory -- returns amount of free video memory *
459 * *
460 * *
461 * *
462 * INPUT: Nothing *
463 * *
464 * OUTPUT: bytes of available video RAM *
465 * *
466 * WARNINGS: None *
467 * *
468 * HISTORY: *
469 * 11/29/95 12:52PM ST : Created *
470 *=============================================================================================*/
471unsigned int Get_Free_Video_Memory(void)
472{
473 DDCAPS video_capabilities;
474
475 if (DirectDrawObject) {
476
477 video_capabilities.dwSize = sizeof (video_capabilities);
478
479 if (DD_OK == DirectDrawObject->GetCaps (&video_capabilities, NULL)) {
480 char string [256];
481 wsprintf (string, "In Get_Free_Video_Memory. About to return %d bytes",video_capabilities.dwVidMemFree);
482 return (video_capabilities.dwVidMemFree);
483 }
484 }
485
486 return (0);
487}
488
489
490/***********************************************************************************************
491 * Get_Video_Hardware_Caps -- returns bitmask of direct draw video hardware support *
492 * *
493 * *
494 * *
495 * INPUT: Nothing *
496 * *
497 * OUTPUT: hardware flags *
498 * *
499 * WARNINGS: Must call Set_Video_Mode 1st to create the direct draw object *
500 * *
501 * HISTORY: *
502 * 1/12/96 9:14AM ST : Created *
503 *=============================================================================================*/
505{
506 DDCAPS video_capabilities;
507 unsigned video;
508
509 /*
510 ** Fail if the direct draw object has not been initialised
511 */
512 if (!DirectDrawObject) return (0);
513
514 /*
515 ** Get the capabilities of the direct draw object
516 */
517 video_capabilities.dwSize = sizeof(video_capabilities);
518 //MessageBox(MainWindow, "In Get_Video_Hardware_Capabilities. About to call GetCaps","Note", MB_ICONEXCLAMATION|MB_OK);
519 HRESULT result = DirectDrawObject->GetCaps (&video_capabilities, NULL);
520 if (result != DD_OK) {
521 Process_DD_Result(result, false);
522 return (0);
523 }
524
525 /*
526 ** Set flags to indicate the presence of the features we are interested in
527 */
528 video = 0;
529
530 /* Hardware blits supported? */
531 if (video_capabilities.dwCaps & DDCAPS_BLT) video |= VIDEO_BLITTER;
532
533 /* Hardware blits asyncronous? */
534 if (video_capabilities.dwCaps & DDCAPS_BLTQUEUE) video |= VIDEO_BLITTER_ASYNC;
535
536 /* Can palette changes be synced to vertical refresh? */
537 if (video_capabilities.dwCaps & DDCAPS_PALETTEVSYNC) video |= VIDEO_SYNC_PALETTE;
538
539 /* Is the video cards memory bank switched? */
540 if (video_capabilities.dwCaps & DDCAPS_BANKSWITCHED) video |= VIDEO_BANK_SWITCHED;
541
542 /* Can the blitter do filled rectangles? */
543 if (video_capabilities.dwCaps & DDCAPS_BLTCOLORFILL) video |= VIDEO_COLOR_FILL;
544
545 /* Is there no hardware assistance avaailable at all? */
546 if (video_capabilities.dwCaps & DDCAPS_NOHARDWARE) video |= VIDEO_NO_HARDWARE_ASSIST;
547
548 //MessageBox(MainWindow, "In Get_Video_Hardware_Capabilities. About to return success.","Note", MB_ICONEXCLAMATION|MB_OK);
549 return (video);
550}
551
552
553/***********************************************************************************************
554 * Wait_Vert_Blank -- Waits for the start (leading edge) of a vertical blank *
555 * *
556 * INPUT: *
557 * *
558 * OUTPUT: *
559 * *
560 * WARNINGS: *
561 * *
562 * HISTORY: *
563 *=============================================================================================*/
565{
566 if (CanVblankSync) {
567 HRESULT result = DirectDrawObject->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0);
568 if (result == E_NOTIMPL) {
569 CanVblankSync = false;
570 return;
571 }
572 Process_DD_Result(result, false);
573 }
574}
575
576
577/***********************************************************************************************
578 * Set_Palette -- set a direct draw palette *
579 * *
580 * *
581 * *
582 * INPUT: ptr to 768 rgb palette bytes *
583 * *
584 * OUTPUT: Nothing *
585 * *
586 * WARNINGS: None *
587 * *
588 * HISTORY: *
589 * 10/11/95 3:33PM ST : Created *
590 *=============================================================================================*/
591void Set_Palette(void const * palette)
592{
593 assert(palette != NULL);
594
595 if (&CurrentPalette[0] != palette) {
596 memmove(CurrentPalette, palette, sizeof(CurrentPalette));
597 }
598
600 unsigned char * palette_get = (unsigned char *)palette;
601 for (int index = 0; index < 256; index++) {
602
603 int red = *palette_get++;
604 int green = *palette_get++;
605 int blue = *palette_get++;
606
607 PaletteEntries[index].peRed = (unsigned char)red;
608 PaletteEntries[index].peGreen = (unsigned char)green;
609 PaletteEntries[index].peBlue = (unsigned char)blue;
610 }
611
612 if (PalettePtr != NULL) {
613 if (!FirstPaletteSet) {
614 PaletteSurface->SetPalette(PalettePtr);
615 FirstPaletteSet = true;
616 }
617
618 PalettePtr->SetEntries(0, 0, 256, &PaletteEntries[0]);
619 }
620 }
621}
622
623
624/***********************************************************************************************
625 * Wait_Blit -- waits for the DirectDraw blitter to become idle *
626 * *
627 * *
628 * *
629 * INPUT: Nothing *
630 * *
631 * OUTPUT: Nothing *
632 * *
633 * WARNINGS: None *
634 * *
635 * HISTORY: *
636 * 07-25-95 03:53pm ST : Created *
637 *=============================================================================================*/
638void Wait_Blit (void)
639{
640 HRESULT return_code;
641
642 do {
643 return_code=PaletteSurface->GetBltStatus (DDGBS_ISBLTDONE);
644 } while (return_code != DD_OK && return_code != DDERR_SURFACELOST);
645}
646
#define NULL
Definition BaseType.h:92
#define MIN(a, b)
Definition always.h:189
#define VIDEO_COLOR_FILL
Definition misc.h:99
#define VIDEO_NO_HARDWARE_ASSIST
Definition misc.h:102
#define VIDEO_BLITTER
Definition misc.h:87
#define VIDEO_BANK_SWITCHED
Definition misc.h:96
#define VIDEO_SYNC_PALETTE
Definition misc.h:93
#define VIDEO_BLITTER_ASYNC
Definition misc.h:90
Int timer
#define ARRAY_SIZE(a)
LPVOID(__stdcall *SnmpUtilMemAllocPtr)(IN DWORD bytes)
void Adjust(int ratio)
Definition palette.cpp:139
void Wait_Vert_Blank(void)
Definition ddraw.cpp:564
unsigned int Get_Free_Video_Memory(void)
Definition ddraw.cpp:471
void Process_DD_Result(HRESULT result, int display_ok_msg)
Definition ddraw.cpp:139
unsigned Get_Video_Hardware_Capabilities(void)
Definition ddraw.cpp:504
LPDIRECTDRAW2 DirectDraw2Interface
Definition ddraw.cpp:56
unsigned char CurrentPalette[768]
Definition ddraw.cpp:65
void Set_Palette(PaletteClass const &pal, int time, void(*callback)())
Definition ddraw.cpp:70
void Wait_Blit(void)
Definition ddraw.cpp:638
void Reset_Video_Mode(void)
Definition ddraw.cpp:438
LPDIRECTDRAW DirectDrawObject
Definition ddraw.cpp:55
LPDIRECTDRAWSURFACE PaletteSurface
Definition ddraw.cpp:61
void Check_Overlapped_Blit_Capability(void)
Definition ddraw.cpp:294
bool Debug_Windowed
Definition ddraw.cpp:66
void Prep_Direct_Draw(void)
Definition ddraw.cpp:327
bool SurfacesRestored
Definition ddraw.cpp:62
bool Set_Video_Mode(HWND, int w, int h, int bits_per_pixel)
Definition ddraw.cpp:360
int(* DirectDrawErrorHandler)(HRESULT error)
Definition ddraw.cpp:68