Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
dib.cpp
Go to the documentation of this file.
1/*
2 * DirectDraw DIB display, frame timing and palettes.
3 *
4 * Retail object 0x45CCB0-0x45E9EF (link order; see docs/ORDER.md).
5 *
6 * A C++ unit: it opens with the frame-timing state, whose initializers are
7 * not constant expressions, so the compiler emits two dynamic initializer
8 * pairs (0x45CCB0-0x45CD2B) ahead of the first function. Its DirectDraw
9 * calls keep the C interface (CINTERFACE), which compiles to the same calls
10 * as the C++ one.
11 */
12#define CINTERFACE
13#define DIB_C
14#include "game.h"
15
16static int g_nDefaultFrameRate = 70; /* 0x0049ce88 */
17
18static int g_nDisplayFrameRate = 70; /* 0x0049ce8c */
19
21 (long)(1000.0 / g_nDisplayFrameRate); /* 0x005c343c */
22
24 (float)g_nDisplayFrameRate; /* 0x005c3440 */
25
26/* The DirectDraw GUIDs, instantiated here in the order of DirectX 3's
27 * ddraw.h (as INITGUID would). The compiler's SDK ships the DirectX 2
28 * header, which lacks CLSID_DirectDrawClipper, so they are spelled out. */
29/* 0x0048e0f0 */
30const GUID CLSID_DirectDraw = {
31 0xd7b70ee0, 0x4340, 0x11cf,
32 { 0xb0, 0x63, 0x00, 0x20, 0xaf, 0xc2, 0xcd, 0x35 }
33};
34/* 0x0048e100 */
36 0x593817a0, 0x7db3, 0x11cf,
37 { 0xa2, 0xde, 0x00, 0xaa, 0x00, 0xb9, 0x33, 0x56 }
38};
39/* 0x0048e110 */
40const GUID IID_IDirectDraw = {
41 0x6c14db80, 0xa733, 0x11ce,
42 { 0xa5, 0x21, 0x00, 0x20, 0xaf, 0x0b, 0xe5, 0x60 }
43};
44/* 0x0048e120 */
45const GUID IID_IDirectDraw2 = {
46 0xb3a6f3e0, 0x2b43, 0x11cf,
47 { 0xa2, 0xde, 0x00, 0xaa, 0x00, 0xb9, 0x33, 0x56 }
48};
49/* 0x0048e130 */
51 0x6c14db81, 0xa733, 0x11ce,
52 { 0xa5, 0x21, 0x00, 0x20, 0xaf, 0x0b, 0xe5, 0x60 }
53};
54/* 0x0048e140 */
56 0x57805885, 0x6eec, 0x11cf,
57 { 0x94, 0x41, 0xa8, 0x23, 0x03, 0xc1, 0x0e, 0x27 }
58};
59/* 0x0048e150 */
61 0x6c14db84, 0xa733, 0x11ce,
62 { 0xa5, 0x21, 0x00, 0x20, 0xaf, 0x0b, 0xe5, 0x60 }
63};
64/* 0x0048e160 */
66 0x6c14db85, 0xa733, 0x11ce,
67 { 0xa5, 0x21, 0x00, 0x20, 0xaf, 0x0b, 0xe5, 0x60 }
68};
69
70LPDIRECTDRAW2 g_pDirectDraw2 = 0; /* 0x0049ce90 */
71
72LPDIRECTDRAWSURFACE g_pPrimarySurface = 0; /* 0x0049ce94 */
73
74LPDIRECTDRAWSURFACE g_pSecondarySurface = 0; /* 0x0049ce98 */
75
76LPDIRECTDRAWPALETTE g_pDirectDrawPalette = 0; /* 0x0049ce9c */
77
78int g_nDisplayModeCascade = -1; /* 0x0049cea0 */
79
80DWORD g_dwNextFrameDeadline = 0; /* 0x0049cea4 */
81
82int g_nUnusedDibWord1 = 0; /* 0x0049cea8 */
83
84long g_lPreviousFrameTick = 0; /* 0x0049ceac */
85
86int g_nFrameTimingMode = 0; /* 0x0049ceb0 */
87
88float g_fSpaceFlightFrameRate = 20.0f; /* 0x0049ceb4 */
89
90int g_nUnusedDibWord2 = 0; /* 0x0049ceb8 */
91
92int g_bFrameTimingInitialized = 0; /* 0x0049cebc */
93
94int g_bDibSlamEnabled = 1; /* 0x0049cec0 */
95
96/* This unit's .bss: LINK orders C++ definitions by the identifiers' hash
97 * keys, and these spellings follow the original addresses. */
98char g_59_szFrameFrequencyString[32]; /* 0x005b3950 */
99unsigned int g_38_nDibOriginX; /* 0x005b3970 */
100unsigned int g_101_nDibOffsetY; /* 0x005b3974 */
101unsigned char *g_18_pDisplayPixelBuffer; /* 0x005b3978 */
102unsigned int g_28_nDisplayRowBytes; /* 0x005b397c */
103unsigned int g_38_nSurfaceHeight; /* 0x005b3980 */
104unsigned char g_11_abFrameBackingStore[0xfa00]; /* 0x005b3988 */
105int g_36_nDibBitsEachPx; /* 0x005c3388 */
106int g_4_nDibShowCount; /* 0x005c3390 */
107HWND g_2_hFrameHwnd; /* 0x005c33a4 */
108int g_nDibDirtyHitTotal; /* 0x005c33a8 */
109char g_szFrameErrorMessage[0x8c]; /* 0x005c33b0 */
110unsigned char g_3_abColourShadow[1024]; /* 0x005c3450 */
111float g_fMeasuredFrameRate; /* 0x005c3850 */
112char g_2_szDibDebugScratch[260]; /* 0x005c3858 */ /* MAX_PATH */
113int g_4_bScreenStale; /* 0x005c395c */
114int g_8_nDibFlipRealCount; /* 0x005c3960 */
115unsigned int g_10_dwLastSurfaceSlamRealNoticeTick; /* 0x005c396c */
116char g_18_szSpaceFlightBestFpsMessage[0x80]; /* 0x005c3970 */
117unsigned int g_dwLastDibDirtyReportTime; /* 0x005c39f0 */
118char g_3_szDibSlamRealDebugBuf[256]; /* 0x005c39f8 */
119/* Never referenced; retail reserves their storage among the words above. */
120int g_28_nUnusedFrameSlot; /* 0x005c338c */
121int g_nUnusedScreenWord1; /* 0x005c3394 */
122int g_nUnusedScreenWord2; /* 0x005c3398 */
123int g_4_nUnusedFrameWord; /* 0x005c339c */
124int g_5_nUnusedDibWord3; /* 0x005c33a0 */
125int g_nUnusedDibWord4; /* 0x005c3444 */
126int g_nUnusedDibWord5; /* 0x005c3448 */
127int g_2_nReservedDibWord; /* 0x005c344c */
128int g_12_nIdleFrameWord1; /* 0x005c3964 */
129int g_11_nIdleFrameWord2; /* 0x005c3968 */
130
131#pragma function(strlen)
132/* Function start: 0x45CD2C */
134{
137
138 if (g_bShowFrameRate != 0) {
139 sprintf(g_59_szFrameFrequencyString, "%f",
143 }
144
146 while (timeGetTime() < g_dwNextFrameDeadline) {
147 Sleep(0);
149 }
150 } else {
151 while (timeGetTime() < g_dwNextFrameDeadline)
152 Sleep(0);
153 }
154
155 if (g_bShowFrameRate != 0) {
156 if (g_lPreviousFrameTick != 0) {
158 1000.0f / ((float)timeGetTime() -
160 }
161 g_lPreviousFrameTick = timeGetTime();
162 sprintf(g_59_szFrameFrequencyString, "%f",
166 }
167
169 timeGetTime() + g_17_nFramePeriodMillis;
170}
171
172void SetHudMessageText(char *text, unsigned short colour, unsigned short duration);
173void DIBerror(const char *tag, int hr);
174
175/* Function start: 0x45CE9A */
176void ReportSpaceFlightMaxFps(float adjustment)
177{
178 g_fSpaceFlightFrameRate += adjustment;
179 if (g_fSpaceFlightFrameRate < 8.0)
181 else if (g_fSpaceFlightFrameRate > 32.0)
184 "Space Flight Max FPS : %.1f",
187 if (g_nFrameTimingMode == 1)
189}
190
191/* Function start: 0x45CF3B */
200
201/* Function start: 0x45CF7F */
210
211/* Function start: 0x45CFC3 */
212void SetCinematicFrameTiming(float frameRate)
213{
215 g_17_nFramePeriodMillis = (long)(1000.0 / frameRate);
218}
219
220/* Function start: 0x45D004 */
221void DIBerror(const char *tag, int hr)
222{
223 FILE *errorFile;
224
225 sprintf(g_szFrameErrorMessage, "ERROR: %i in %s",
226 (unsigned short)hr, tag);
229 IDirectDraw2_RestoreDisplayMode(g_pDirectDraw2);
230 IDirectDraw2_Release(g_pDirectDraw2);
232 SetWindowPos(g_2_hFrameHwnd, HWND_BOTTOM, 0, 0, 320, 200,
233 SWP_SHOWWINDOW);
234 errorFile = fopen("direct.err", "wt+");
235 fprintf(errorFile, g_szFrameErrorMessage);
236 fclose(errorFile);
237 MessageBoxA(0, g_szFrameErrorMessage, "DirectDraw Error", MB_ICONERROR);
238 exit(1);
239 return;
240}
241
242/* Function start: 0x45D11F */
244{
247 IDirectDraw2_RestoreDisplayMode(g_pDirectDraw2);
248 IDirectDraw2_Release(g_pDirectDraw2);
249 SetWindowPos(g_2_hFrameHwnd, HWND_BOTTOM, 0, 0, 320, 200,
250 SWP_SHOWWINDOW);
251}
252
253/* Function start: 0x45D1BB */
254void DIBreInstall(void)
255{
256 int err;
257
258 if (g_bConfigQuickModeEnabled != 0) {
259 if (g_pDirectDraw2 == 0)
260 return;
261 IDirectDraw2_SetCooperativeLevel(
263 if (DIBcascade(-2, &err) == 0)
264 DIBerror("DIBreInstall DIBcascade Failure", err);
265 } else {
267 }
268}
269
270#pragma function(memset)
271/* Function start: 0x45D23B */
272void DIBinstall(HWND window)
273{
274 LPDIRECTDRAW directDraw;
275 HRESULT result;
276
277 g_2_hFrameHwnd = window;
278 result = DirectDrawCreate(0, &directDraw, 0);
279 if (result != DD_OK)
280 DIBerror("DIBInstall Create", result);
281
282 result = IDirectDraw_QueryInterface(
283 directDraw, IID_IDirectDraw2,
284 (void **)&g_pDirectDraw2);
285 if (result != DD_OK)
286 DIBerror("DIBInstall Unable to acquire DirectDraw2 interface", result);
287
289 result = IDirectDraw2_SetCooperativeLevel(
291 else
292 result = IDirectDraw2_SetCooperativeLevel(
294 if (result != DD_OK)
295 DIBerror("DIBmakeInstall SetCooperativeLevel", result);
296
297 if (g_bConfigQuickModeEnabled != 0) {
298 if (DIBcascade(-1, 0) == 0)
299 DIBerror("DIBinstall DIBcascade Failure", result);
300 } else {
302 }
303
304 g_2_hFrameHwnd = window;
305 memset(g_3_abColourShadow, 0, sizeof(g_3_abColourShadow));
307 DIBmakeDIB();
310 return;
311}
312
313/* Function start: 0x45D3A1 */
314int DIBcascade(int mode, int *reportedResult)
315{
316 DDSURFACEDESC surface;
317 HRESULT result;
318
319 if (g_pDirectDraw2 == 0)
320 return 1;
321
322 if (mode != -2) {
323 if (mode == -1)
325 else
327 }
328
329 switch (g_nDisplayModeCascade) {
330 case 0:
331 result = g_pDirectDraw2->lpVtbl->SetDisplayMode(
332 g_pDirectDraw2, 320, 200, 8, 0, 0);
333 if (reportedResult != 0)
334 *reportedResult = result;
335 if (result != DD_OK)
336 return DIBcascade(0, 0);
337 WriteDebugString("320x200 achieved...testing\n");
338 break;
339 case 1:
340 result = g_pDirectDraw2->lpVtbl->SetDisplayMode(
341 g_pDirectDraw2, 640, 400, 8, 0, 0);
342 if (reportedResult != 0)
343 *reportedResult = result;
344 if (result != DD_OK)
345 return DIBcascade(0, 0);
346 WriteDebugString("640x400 achieved...testing\n");
347 break;
348 case 2:
349 result = g_pDirectDraw2->lpVtbl->SetDisplayMode(
350 g_pDirectDraw2, 640, 480, 8, 0, 0);
351 if (reportedResult != 0)
352 *reportedResult = result;
353 if (result != DD_OK)
354 return DIBcascade(0, 0);
355 WriteDebugString("640x480 achieved...testing\n");
356 break;
357 default:
358 return 0;
359 }
360
361 if (mode == -2) {
362 if (g_pSecondarySurface != 0) {
363 result = IDirectDrawSurface_Restore(
365 if (reportedResult != 0)
366 *reportedResult = result;
367 if (result != DD_OK)
368 DIBerror("DIBcascade Unable to restore surface (secondary)",
369 result);
370 }
371
372 result = IDirectDrawSurface_Restore(g_pPrimarySurface);
373 if (reportedResult != 0)
374 *reportedResult = result;
375 if (result != DD_OK)
376 DIBerror("DIBcascade Unable to restore surface", result);
377
378 result = IDirectDrawSurface_SetPalette(
380 if (result != DD_OK)
381 DIBerror("DIBcascade CreatePalette", result);
382 return 1;
383 }
384
385 WriteDebugString(" acquiring surface:");
386 memset(&surface, 0, sizeof(surface));
387 surface.dwSize = sizeof(surface);
388 surface.dwFlags = DDSD_CAPS;
389 surface.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
390 result = IDirectDraw2_CreateSurface(
391 g_pDirectDraw2, &surface,
393 if (reportedResult != 0)
394 *reportedResult = result;
395 if (result != DD_OK) {
396 WriteDebugString(" failed\n");
397 IDirectDraw2_RestoreDisplayMode(g_pDirectDraw2);
398 return DIBcascade(0, 0);
399 }
400
401 WriteDebugString(" successful\n locking surface:");
402 result = IDirectDrawSurface_Lock(
403 g_pPrimarySurface, 0, &surface, DDLOCK_WAIT, 0);
404 if (reportedResult != 0)
405 *reportedResult = result;
406 if (result != DD_OK) {
407 WriteDebugString(" failed\n");
408 IDirectDrawSurface_Release(g_pPrimarySurface);
409 IDirectDraw2_RestoreDisplayMode(g_pDirectDraw2);
410 return DIBcascade(0, 0);
411 }
412
413 IDirectDrawSurface_Unlock(g_pPrimarySurface,
414 surface.lpSurface);
415 IDirectDrawSurface_Release(g_pPrimarySurface);
417 WriteDebugString(" successful\n");
418 return 1;
419}
420
421/* Function start: 0x45D78C */
422/* Full teardown: destroy the DIB, release its surfaces, restore the display
423 * mode and release DirectDraw itself. */
424void DIBunInstall(void)
425{
429 IDirectDraw2_RestoreDisplayMode(g_pDirectDraw2);
430 IDirectDraw2_Release(g_pDirectDraw2);
431}
432
433#pragma function(memcpy)
434/* Function start: 0x45D80F */
435void DIBmakeDIB(void)
436{
437 DDSURFACEDESC surfaceDesc;
438 PALETTEENTRY colours[256];
439 HRESULT hr;
440 int paletteIndex;
441
442 memset(&surfaceDesc, 0, sizeof(surfaceDesc));
443 surfaceDesc.dwSize = sizeof(surfaceDesc);
444 surfaceDesc.dwFlags = DDSD_CAPS;
445 surfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_MODEX;
446 hr = IDirectDraw2_CreateSurface(
447 g_pDirectDraw2, &surfaceDesc,
449 if (hr != DD_OK)
450 DIBerror("DIBmakeDIB CreateSurface (primary)", hr);
451
453 for (paletteIndex = 0; paletteIndex < 256; paletteIndex++) {
454 colours[paletteIndex].peRed = g_3_abColourShadow[paletteIndex * 4 + 2];
455 colours[paletteIndex].peGreen = g_3_abColourShadow[paletteIndex * 4 + 1];
456 colours[paletteIndex].peBlue = g_3_abColourShadow[paletteIndex * 4];
457 colours[paletteIndex].peFlags = 0;
458 }
459
460 if (g_36_nDibBitsEachPx == 8) {
461 hr = IDirectDraw2_CreatePalette(
462 g_pDirectDraw2, DDPCAPS_8BIT, colours,
464 if (hr != DD_OK)
465 DIBerror("DIBmakeDIB CreatePalette", hr);
466
467 if (g_bUseHardwarePalette != 0) {
468 hr = IDirectDrawSurface_SetPalette(
471 if (hr != DD_OK)
472 DIBerror("DIBmakeDIB CreatePalette", hr);
473 }
474 }
475
476 if (g_nDisplayModeCascade > 0) {
477 memset(&surfaceDesc, 0, sizeof(surfaceDesc));
478 surfaceDesc.dwSize = sizeof(surfaceDesc);
479 surfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
480 surfaceDesc.dwWidth = 320;
481 surfaceDesc.dwHeight = 200;
482 surfaceDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
483 hr = IDirectDraw2_CreateSurface(
484 g_pDirectDraw2, &surfaceDesc,
486 if (hr != DD_OK)
487 DIBerror("DIBmakeDIB CreateSurface (secondary)", hr);
488 }
489
494 g_18_pDisplayPixelBuffer = (unsigned char *)malloc(64000);
499 return;
500}
501
502/* Function start: 0x45DA8C */
504{
505 int result;
506
509 if (g_nDisplayModeCascade > 0) {
510 result = IDirectDrawSurface_Release(g_pSecondarySurface);
511 if (result != 0)
512 DIBerror("DIBdestroyDIB secondary->Release", result);
514 }
515 if (g_pPrimarySurface != 0) {
516 result = IDirectDrawSurface_Release(g_pPrimarySurface);
517 if (result != 0)
518 DIBerror("DIBdestroyDIB primary->Release", result);
520 }
521 if (g_18_pDisplayPixelBuffer != 0) {
524 }
528 return;
529}
530
531/* Function start: 0x45DB8C */
532void MarkDibDirty(void)
533{
534 unsigned int tick;
535
536 tick = GetTickCount();
539 if (g_dwLastDibDirtyReportTime + 1000 <= tick) {
540 sprintf(g_2_szDibDebugScratch,
541 "DIBslam %d times in %d seconds\n",
546 }
547}
548
549/* Function start: 0x45DBFF */
551{
553}
554
555/* Function start: 0x45DC19 */
557{
559}
560
561/* Function start: 0x45DC33 */
562void DIBslamReal(void)
563{
564 DDSURFACEDESC surfaceDetails;
565 unsigned char *destPixels;
566 unsigned char *source;
567 RECT outputRect;
568 RECT sourceArea;
569 HRESULT status;
570 int scanline;
571 HDC drawDC;
572 unsigned int nowTick;
573
575 nowTick = GetTickCount();
576 if (g_bDibSlamEnabled == 0)
577 return;
578
580 if (g_10_dwLastSurfaceSlamRealNoticeTick + 1000 <= nowTick) {
582 "DIBslamReal %d times in %d seconds\n",
587 }
588
589 if (g_4_bScreenStale != 0) {
590 memset(&surfaceDetails, 0, sizeof(surfaceDetails));
591 surfaceDetails.dwSize = sizeof(surfaceDetails);
592
595
596 if (g_nDisplayModeCascade > 0) {
597 status = IDirectDrawSurface_Lock(
599 0, &surfaceDetails, DDLOCK_WAIT, 0);
600 } else {
601 status = IDirectDrawSurface_Lock(
603 0, &surfaceDetails, DDLOCK_WAIT, 0);
604 }
605 if (status != DD_OK) {
606 if (status == DDERR_SURFACELOST) {
607 if (g_nDisplayModeCascade > 0) {
608 status = IDirectDrawSurface_Restore(
610 if (status != DD_OK)
611 return;
612 }
613 status = IDirectDrawSurface_Restore(
615 if (status != DD_OK)
616 return;
617
618 if (g_nDisplayModeCascade > 0) {
619 status = IDirectDrawSurface_Lock(
621 0, &surfaceDetails, DDLOCK_WAIT, 0);
622 } else {
623 status = IDirectDrawSurface_Lock(
625 0, &surfaceDetails, DDLOCK_WAIT, 0);
626 }
627 if (status != DD_OK)
628 return;
629 } else {
630 IDirectDrawSurface_Unlock(
631 g_pPrimarySurface, surfaceDetails.lpSurface);
632 DIBerror("DIBslamReal secondary->Lock", status);
633 }
634 }
635
636 destPixels = (unsigned char *)surfaceDetails.lpSurface;
638 if (g_nDisplayModeCascade <= 0) {
639 IDirectDraw2_WaitForVerticalBlank(
640 g_pDirectDraw2, DDWAITVB_BLOCKBEGIN, 0);
641 }
642 for (scanline = 0; scanline < (int)g_38_nSurfaceHeight; scanline++) {
643 memcpy(destPixels, source, g_28_nDisplayRowBytes);
644 destPixels += surfaceDetails.lPitch;
645 source += g_28_nDisplayRowBytes;
646 }
647
648 if (g_nDisplayModeCascade > 0) {
649 status = IDirectDrawSurface_Unlock(
650 g_pSecondarySurface, surfaceDetails.lpSurface);
651 } else {
652 status = IDirectDrawSurface_Unlock(
653 g_pPrimarySurface, surfaceDetails.lpSurface);
654 }
655
657
658 if (g_nDisplayModeCascade > 0) {
659 outputRect.left = 0;
660 outputRect.top = 0;
661 outputRect.right = 639;
662 outputRect.bottom = 399;
663 sourceArea.left = 0;
664 sourceArea.top = 0;
665 sourceArea.right = 319;
666 sourceArea.bottom = 199;
667 if (g_nDisplayModeCascade == 2) {
668 outputRect.top += 40;
669 outputRect.bottom += 40;
670 }
671
672 status = IDirectDrawSurface_Blt(
673 g_pPrimarySurface, &outputRect,
674 g_pSecondarySurface, &sourceArea,
675 DDBLT_WAIT, 0);
676 if (status != DD_OK) {
677 if (status == DDERR_SURFACELOST) {
678 status = IDirectDrawSurface_Restore(
680 if (status != DD_OK)
681 return;
682 status = IDirectDrawSurface_Restore(
684 if (status != DD_OK)
685 return;
686 status = IDirectDrawSurface_Blt(
687 g_pPrimarySurface, &outputRect,
688 g_pSecondarySurface, &sourceArea,
689 DDBLT_WAIT, 0);
690 if (status != DD_OK)
691 return;
692 } else {
693 DIBerror("DIBslamReal primary->Blt", status);
694 }
695 }
696 }
698 }
699
702 drawDC = GetDC(g_2_hFrameHwnd);
704 ReleaseDC(g_2_hFrameHwnd, drawDC);
705}
706
707/* Function start: 0x45E060 */
708void DIBupdate(int left, int top, int right, int bottom)
709{
710 unsigned char *destPixels;
711 unsigned char *source;
712 DDSURFACEDESC surfaceDetails;
713 int byteWidth;
714 RECT targetRect;
715 RECT updateSource;
716 int currentLine;
717 int height;
718 HRESULT hResult;
719
720 if (g_nDisplayModeCascade > 0)
721 return;
722 if (left < 0)
723 left = 0;
724 else if (left > 319)
725 return;
726 if (right < 0)
727 return;
728 else if (right > 319)
729 right = 319;
730 if (top < 0)
731 top = 0;
732 else if (top > 199)
733 return;
734 if (bottom < 0)
735 return;
736 else if (bottom > 199)
737 bottom = 199;
738
739 byteWidth = right - left + 1;
740 height = bottom - top + 1;
741 /* Retail initializes both rectangles even though Lock does not use them. */
742 targetRect.left = left;
743 targetRect.top = top;
744 targetRect.right = byteWidth;
745 targetRect.bottom = height;
746 updateSource.left = left;
747 updateSource.top = top;
748 updateSource.right = byteWidth;
749 updateSource.bottom = height;
750 memset(&surfaceDetails, 0, sizeof(surfaceDetails));
751 surfaceDetails.dwSize = sizeof(surfaceDetails);
752 hResult = IDirectDrawSurface_Lock(
753 g_pPrimarySurface, 0, &surfaceDetails,
754 DDLOCK_WAIT, 0);
755 if (hResult != DD_OK) {
756 IDirectDrawSurface_Unlock(
757 g_pPrimarySurface, surfaceDetails.lpSurface);
758 DIBerror("DIBupdate primary->Lock", hResult);
759 }
760
761 destPixels = (unsigned char *)surfaceDetails.lpSurface
762 + surfaceDetails.lPitch * top + left;
763 /* Convert the completed row address before applying the column offset. */
764 source = (unsigned char *)((unsigned long)g_18_pDisplayPixelBuffer
765 + g_28_nDisplayRowBytes * top) + left;
766 IDirectDraw2_WaitForVerticalBlank(
767 g_pDirectDraw2, DDWAITVB_BLOCKBEGIN, 0);
768 for (currentLine = 0; height > currentLine; currentLine++) {
769 memcpy(destPixels, source, byteWidth);
770 destPixels += surfaceDetails.lPitch;
771 source += g_28_nDisplayRowBytes;
772 }
773 hResult = IDirectDrawSurface_Unlock(
774 g_pPrimarySurface, surfaceDetails.lpSurface);
775 return;
776}
777
778/* Function start: 0x45E276 */
779unsigned char *GetDIBPixelBuffer(void)
780{
782}
783
784/* Function start: 0x45E28B */
785/* Nothing in the shipped executable calls this. */
787{
788 return;
789}
790
791/* Function start: 0x45E29B */
792/* Nothing in the shipped executable calls this. */
794{
795 return g_2_hFrameHwnd;
796}
797
798/* Function start: 0x45E2B0 */
799/* Nothing in the shipped executable calls this. */
800unsigned int GetDIBWidth(void)
801{
803}
804
805/* Function start: 0x45E2C5 */
806unsigned int GetDIBHeight(void)
807{
808 return g_38_nSurfaceHeight;
809}
810
811/* Function start: 0x45E2DA */
812void CachePaletteEntryFromWords(short index, unsigned short *rgb)
813{
814 g_3_abColourShadow[index * 4 + 2] =
815 *(unsigned char *)&rgb[0];
816 g_ausPaletteWords[index][0] =
817 g_3_abColourShadow[index * 4 + 2];
818 g_3_abColourShadow[index * 4 + 1] =
819 *(unsigned char *)&rgb[1];
820 g_ausPaletteWords[index][1] =
821 g_3_abColourShadow[index * 4 + 1];
822 g_3_abColourShadow[index * 4] =
823 *(unsigned char *)&rgb[2];
824 g_ausPaletteWords[index][2] =
825 g_3_abColourShadow[index * 4];
826 g_3_abColourShadow[index * 4 + 3] = 1;
827}
828
829/* Function start: 0x45E37C */
831{
832 PALETTEENTRY entries[256];
833 int index;
834 HRESULT error;
835
836 for (index = 0; index < 256; index++) {
837 entries[index].peRed =
838 g_3_abColourShadow[index * 4 + 2];
839 entries[index].peGreen =
840 g_3_abColourShadow[index * 4 + 1];
841 entries[index].peBlue =
842 g_3_abColourShadow[index * 4];
843 entries[index].peFlags = 0;
844 }
845 if (g_bUseHardwarePalette != 0) {
846 error = IDirectDrawPalette_SetEntries(
847 g_pDirectDrawPalette, 0, 0, 256, entries);
848 if (error != DD_OK)
849 DIBerror("DIBramPalette SetEntries", error);
850 }
851}
852
853/* Function start: 0x45E46C */
854void DIBsetPalette(short index, short *rgb)
855{
856 PALETTEENTRY entry;
857 HRESULT error;
858
859 if ((int)g_3_abColourShadow[index * 4 + 2] == (int)rgb[0] &&
860 (int)g_3_abColourShadow[index * 4 + 1] == (int)rgb[1] &&
861 (int)g_3_abColourShadow[index * 4] == (int)rgb[2])
862 return;
863 g_3_abColourShadow[index * 4 + 2] =
864 *(unsigned char *)&rgb[0];
865 g_ausPaletteWords[index][0] =
866 g_3_abColourShadow[index * 4 + 2];
867 g_3_abColourShadow[index * 4 + 1] =
868 *(unsigned char *)&rgb[1];
869 g_ausPaletteWords[index][1] =
870 g_3_abColourShadow[index * 4 + 1];
871 g_3_abColourShadow[index * 4] =
872 *(unsigned char *)&rgb[2];
873 g_ausPaletteWords[index][2] =
874 g_3_abColourShadow[index * 4];
875 g_3_abColourShadow[index * 4 + 3] = 1;
876
877 /* SDL_PORT consumes this cache on the next normal frame submission.
878 A DirectDraw palette entry update did not blit or wait for vertical
879 blank, so flight fades must not submit additional SDL frames. */
880 entry.peRed = (unsigned char)g_ausPaletteWords[index][0];
881 entry.peGreen = (unsigned char)g_ausPaletteWords[index][1];
882 entry.peBlue = (unsigned char)g_ausPaletteWords[index][2];
883 entry.peFlags = 0;
884 if (g_bUseHardwarePalette != 0) {
885 error = IDirectDrawPalette_SetEntries(
886 g_pDirectDrawPalette, 0, (int)index, 1,
887 &entry);
888 if (error != DD_OK)
889 DIBerror("DIBsetPalette SetEntries", error);
890
891 error = IDirectDrawSurface_SetPalette(
894 if (error != DD_OK)
895 DIBerror("DIBmakeDIB CreatePalette", error);
896 }
897}
898
899/* Function start: 0x45E61C */
900void GetPaletteEntryAsWords(short i, unsigned short *rgb)
901{
902 rgb[0] = g_3_abColourShadow[i * 4 + 2];
903 rgb[1] = g_3_abColourShadow[i * 4 + 1];
904 rgb[2] = g_3_abColourShadow[i * 4];
905}
906
907/* Function start: 0x45E667 */
908void DIBwholePaletteFromTriplets(unsigned char *palette)
909{
910 unsigned char entries[0x400];
911 int hr;
912 int index = 0x100;
913
914 IDirectDraw2_WaitForVerticalBlank(
915 g_pDirectDraw2, DDWAITVB_BLOCKBEGIN, 0);
916 for (index = 0; index < 0x100; index++) {
917 g_3_abColourShadow[index * 4 + 2] =
918 palette[index * 3];
919 entries[index * 4] =
920 g_3_abColourShadow[index * 4 + 2];
921 g_3_abColourShadow[index * 4 + 1] =
922 palette[index * 3 + 1];
923 entries[index * 4 + 1] =
924 g_3_abColourShadow[index * 4 + 1];
925 g_3_abColourShadow[index * 4] =
926 palette[index * 3 + 2];
927 entries[index * 4 + 2] =
928 g_3_abColourShadow[index * 4];
929 entries[index * 4 + 3] = 0;
930 g_3_abColourShadow[index * 4 + 3] = 4;
931 }
932
933 if (g_bUseHardwarePalette != 0) {
934 hr = IDirectDrawPalette_SetEntries(
935 g_pDirectDrawPalette, 0, 0, 0x100,
936 (LPPALETTEENTRY)entries);
937 if (hr != 0)
938 DIBerror("DIBsetWholePalette SetEntries", hr);
939
940 hr = IDirectDrawSurface_SetPalette(
942 if (hr != 0)
943 DIBerror("DIBmakeDIB CreatePalette", hr);
944 }
945}
946
947/* Function start: 0x45E816 */
948void DIBwholePaletteFromWords(unsigned short *palette)
949{
950 unsigned char entries[0x400];
951 int hr;
952 int index = 0x100;
953
954 IDirectDraw2_WaitForVerticalBlank(
955 g_pDirectDraw2, DDWAITVB_BLOCKBEGIN, 0);
956 for (index = 0; index < 0x100; index++) {
957 g_3_abColourShadow[index * 4 + 2] =
958 *(unsigned char *)&palette[index * 3];
959 entries[index * 4] =
960 g_3_abColourShadow[index * 4 + 2];
961 g_3_abColourShadow[index * 4 + 1] =
962 *(unsigned char *)&palette[index * 3 + 1];
963 entries[index * 4 + 1] =
964 g_3_abColourShadow[index * 4 + 1];
965 g_3_abColourShadow[index * 4] =
966 *(unsigned char *)&palette[index * 3 + 2];
967 entries[index * 4 + 2] =
968 g_3_abColourShadow[index * 4];
969 entries[index * 4 + 3] = 0;
970 g_3_abColourShadow[index * 4 + 3] = 4;
971 }
972
973 if (g_bUseHardwarePalette != 0) {
974 hr = IDirectDrawPalette_SetEntries(
975 g_pDirectDrawPalette, 0, 0, 0x100,
976 (LPPALETTEENTRY)entries);
977 if (hr != 0)
978 DIBerror("DIBsetWholePalette SetEntries", hr);
979
980 hr = IDirectDrawSurface_SetPalette(
982 if (hr != 0)
983 DIBerror("DIBmakeDIB CreatePalette", hr);
984 }
985}
986
987/* Function start: 0x45E9C5 */
989{
990 IDirectDraw2_WaitForVerticalBlank(
991 g_pDirectDraw2, DDWAITVB_BLOCKBEGIN, 0);
992}
WINUSERAPI HDC WINAPI GetDC(HWND window)
WINUSERAPI int WINAPI ReleaseDC(HWND window, HDC deviceContext)
WINGDIAPI BOOL WINAPI TextOutA(HDC deviceContext, int x, int y, LPCSTR text, int length)
const GUID IID_IDirectDrawSurface2
Definition dib.cpp:55
const GUID IID_IDirectDrawPalette
Definition dib.cpp:60
static int g_nDisplayFrameRate
Definition dib.cpp:18
static int g_nDefaultFrameRate
Definition dib.cpp:16
const GUID IID_IDirectDrawClipper
Definition dib.cpp:65
const GUID IID_IDirectDraw
Definition dib.cpp:40
const GUID IID_IDirectDraw2
Definition dib.cpp:45
const GUID CLSID_DirectDraw
Definition dib.cpp:30
const GUID IID_IDirectDrawSurface
Definition dib.cpp:50
void RefreshMouseCursorDisplay(void)
Definition eventmgr.c:1165
void DIBpixelBufferHook(void)
Definition dib.cpp:786
HWND GetDIBWindowHandle(void)
Definition dib.cpp:793
void RestoreMouseCursorBackground(void)
Definition eventmgr.c:1131
void SetSpaceFlightFrameTiming(void)
Definition dib.cpp:192
void DIBramPalette(void)
Definition dib.cpp:830
void DIBunInstall(void)
Definition dib.cpp:424
void ReportSpaceFlightMaxFps(float adjustment)
Definition dib.cpp:176
void GetPaletteEntryAsWords(short i, unsigned short *rgb)
Definition dib.cpp:900
void ThrottleFrameAndDrawFps(HDC dc)
Definition dib.cpp:133
void DIBslamReal(void)
Definition dib.cpp:562
void DIBinstall(HWND window)
Definition dib.cpp:272
void DIBreInstall(void)
Definition dib.cpp:254
void DIBpositionWindow(void)
Definition dib.cpp:243
void DrawMouseCursor(void)
Definition eventmgr.c:1099
void DIBmakeDIB(void)
Definition dib.cpp:435
void DIBsetPalette(short index, short *rgb)
Definition dib.cpp:854
int DIBcascade(int mode, int *reportedResult)
Definition dib.cpp:314
void CaptureMouseCursorBackground(void)
Definition eventmgr.c:1063
void CachePaletteEntryFromWords(short index, unsigned short *rgb)
Definition dib.cpp:812
void ServiceSoundSystem(void)
Definition sound.c:389
unsigned int GetDIBWidth(void)
Definition dib.cpp:800
void DIBwholePaletteFromWords(unsigned short *palette)
Definition dib.cpp:948
unsigned char * GetDIBPixelBuffer(void)
Definition dib.cpp:779
void DIBdestroyDIB(void)
Definition dib.cpp:503
void UpdateStreamerStoppedFlag(void)
Definition stream.cpp:53
void DIBwholePaletteFromTriplets(unsigned char *palette)
Definition dib.cpp:908
void SetHudMessageText(char *text, unsigned short colour, unsigned short duration)
Definition cockpt.c:2742
void DisableDibSlam(void)
Definition dib.cpp:556
void DIBupdate(int left, int top, int right, int bottom)
Definition dib.cpp:708
void SetCinematicFrameTiming(float frameRate)
Definition dib.cpp:212
void DIBwaitForVerticalBlank(void)
Definition dib.cpp:988
void WriteDebugString(const char *s)
Definition winmain.c:1162
void DIBerror(const char *tag, int hr)
Definition dib.cpp:221
void MarkDibDirty(void)
Definition dib.cpp:532
void SetDefaultFrameTiming(void)
Definition dib.cpp:202
unsigned int GetDIBHeight(void)
Definition dib.cpp:806
void EnableDibSlam(void)
Definition dib.cpp:550
Shared Win32 declarations, types and library interfaces.
#define COM_RELEASE(surface)
Definition game.h:110
int g_2_nReservedDibWord
Definition dib.cpp:127
int g_bFrameTimingInitialized
Definition dib.cpp:92
QueuedMouseState g_16_stEventQueuePointerData
Definition eventmgr.c:2525
LPDIRECTDRAWSURFACE g_pSecondarySurface
Definition dib.cpp:74
int g_nFrameTimingMode
Definition dib.cpp:86
int g_nUnusedDibWord4
Definition dib.cpp:125
unsigned int g_38_nSurfaceHeight
Definition dib.cpp:103
int g_11_nIdleFrameWord2
Definition dib.cpp:129
unsigned int g_38_nDibOriginX
Definition dib.cpp:99
int g_bShowFrameRate
Definition winmain.c:1356
HWND g_2_hFrameHwnd
Definition dib.cpp:107
int g_bUseHardwarePalette
Definition winmain.c:1358
int g_nDibDirtyHitTotal
Definition dib.cpp:108
int g_28_nUnusedFrameSlot
Definition dib.cpp:120
LPDIRECTDRAWSURFACE g_pPrimarySurface
Definition dib.cpp:72
int g_bDibSlamEnabled
Definition dib.cpp:94
unsigned char g_11_abFrameBackingStore[0xfa00]
Definition dib.cpp:104
int g_nUnusedDibWord1
Definition dib.cpp:82
char g_szFrameErrorMessage[0x8c]
Definition dib.cpp:109
unsigned char g_3_abColourShadow[1024]
Definition dib.cpp:110
float g_fMeasuredFrameRate
Definition dib.cpp:111
char g_3_szDibSlamRealDebugBuf[256]
Definition dib.cpp:118
int g_nUnusedDibWord2
Definition dib.cpp:90
DWORD g_dwNextFrameDeadline
Definition dib.cpp:80
int g_nUnusedDibWord5
Definition dib.cpp:126
unsigned int g_10_dwLastSurfaceSlamRealNoticeTick
Definition dib.cpp:115
LPDIRECTDRAW2 g_pDirectDraw2
Definition dib.cpp:70
int g_36_nDibBitsEachPx
Definition dib.cpp:105
float g_1_fPreviousFrameSpeed
Definition dib.cpp:23
unsigned int g_101_nDibOffsetY
Definition dib.cpp:100
unsigned char * g_18_pDisplayPixelBuffer
Definition dib.cpp:101
unsigned int g_28_nDisplayRowBytes
Definition dib.cpp:102
char g_18_szSpaceFlightBestFpsMessage[0x80]
Definition dib.cpp:116
unsigned int g_dwLastDibDirtyReportTime
Definition dib.cpp:117
int g_nDisplayModeCascade
Definition dib.cpp:78
int g_bConfigQuickModeEnabled
Definition winmain.c:1357
int g_8_nDibFlipRealCount
Definition dib.cpp:114
unsigned short g_ausPaletteWords[256][3]
Definition palette.c:34
int g_12_nIdleFrameWord1
Definition dib.cpp:128
long g_17_nFramePeriodMillis
Definition dib.cpp:20
int g_nUnusedScreenWord2
Definition dib.cpp:122
char g_2_szDibDebugScratch[260]
Definition dib.cpp:112
Viewport g_101_stScrViewInfo
Definition cockpt.c:3831
long g_lPreviousFrameTick
Definition dib.cpp:84
const GUID CLSID_DirectDrawClipper
Definition dib.cpp:35
int g_nUnusedScreenWord1
Definition dib.cpp:121
LPDIRECTDRAWPALETTE g_pDirectDrawPalette
Definition dib.cpp:76
int g_4_nUnusedFrameWord
Definition dib.cpp:123
float g_fSpaceFlightFrameRate
Definition dib.cpp:88
char g_59_szFrameFrequencyString[32]
Definition dib.cpp:98
int g_5_nUnusedDibWord3
Definition dib.cpp:124
int g_4_nDibShowCount
Definition dib.cpp:106
int g_4_bScreenStale
Definition dib.cpp:113
Viewport * viewport
Definition globals.h:1017
unsigned char * pixels
Definition game.h:150
unsigned char * allocation
Definition game.h:156