Get rid of DirectDraw

This commit is contained in:
Alexander Batalov 2022-05-24 23:19:36 +03:00
parent 2446621719
commit a2698b220c
9 changed files with 174 additions and 286 deletions

View File

@ -71,18 +71,6 @@ unsigned int _ticker_ = 0;
// 0x51E2AC
int gMouseButtonsState = 0;
// 0x51E2B0
LPDIRECTDRAW gDirectDraw = NULL;
// 0x51E2B4
LPDIRECTDRAWSURFACE gDirectDrawSurface1 = NULL;
// 0x51E2B8
LPDIRECTDRAWSURFACE gDirectDrawSurface2 = NULL;
// 0x51E2BC
LPDIRECTDRAWPALETTE gDirectDrawPalette = NULL;
// NOTE: This value is never set, so it's impossible to understand it's
// meaning.
//
@ -2120,26 +2108,17 @@ int directDrawInit(int width, int height, int bpp)
}
SDL_SetPaletteColors(gSdlSurface->format->palette, colors, 0, 256);
return 0;
} else {
DDPIXELFORMAT ddpf;
ddpf.dwSize = sizeof(DDPIXELFORMAT);
gRedMask = gSdlSurface->format->Rmask;
gGreenMask = gSdlSurface->format->Gmask;
gBlueMask = gSdlSurface->format->Bmask;
if (IDirectDrawSurface_GetPixelFormat(gDirectDrawSurface1, &ddpf) != DD_OK) {
return -1;
}
gRedMask = ddpf.dwRBitMask;
gGreenMask = ddpf.dwGBitMask;
gBlueMask = ddpf.dwBBitMask;
gRedShift = getShiftForBitMask(gRedMask) - 7;
gGreenShift = getShiftForBitMask(gGreenMask) - 7;
gBlueShift = getShiftForBitMask(gBlueMask) - 7;
return 0;
gRedShift = gSdlSurface->format->Rshift;
gGreenShift = gSdlSurface->format->Gshift;
gBlueShift = gSdlSurface->format->Bshift;
}
return 0;
}
// 0x4CB1B0
@ -2299,29 +2278,12 @@ void _GNW95_ShowRect(unsigned char* src, int srcPitch, int a3, int srcX, int src
// 0x4CB93C
void _GNW95_MouseShowRect16(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY)
{
DDSURFACEDESC ddsd;
HRESULT hr;
if (!gProgramIsActive) {
return;
}
while (1) {
ddsd.dwSize = sizeof(ddsd);
hr = IDirectDrawSurface_Lock(gDirectDrawSurface1, NULL, &ddsd, 1, NULL);
if (hr == DD_OK) {
break;
}
if (hr == DDERR_SURFACELOST) {
if (IDirectDrawSurface_Restore(gDirectDrawSurface2) != DD_OK) {
return;
}
}
}
unsigned char* dest = (unsigned char*)ddsd.lpSurface + ddsd.lPitch * destY + 2 * destX;
SDL_LockSurface(gSdlSurface);
unsigned char* dest = (unsigned char*)gSdlSurface->pixels + gSdlSurface->pitch * destY + 2 * destX;
src += srcPitch * srcY + srcX;
@ -2334,11 +2296,23 @@ void _GNW95_MouseShowRect16(unsigned char* src, int srcPitch, int a3, int srcX,
srcPtr++;
}
dest += ddsd.lPitch;
dest += gSdlSurface->pitch;
src += srcPitch;
}
IDirectDrawSurface_Unlock(gDirectDrawSurface1, ddsd.lpSurface);
SDL_UnlockSurface(gSdlSurface);
SDL_Rect srcRect;
srcRect.x = destX;
srcRect.y = destY;
srcRect.w = srcWidth;
srcRect.h = srcHeight;
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlWindowSurface, &destRect);
SDL_UpdateWindowSurface(gSdlWindow);
}
// 0x4CBA44
@ -2350,29 +2324,12 @@ void _GNW95_ShowRect16(unsigned char* src, int srcPitch, int a3, int srcX, int s
// 0x4CBAB0
void _GNW95_MouseShowTransRect16(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, unsigned char keyColor)
{
DDSURFACEDESC ddsd;
HRESULT hr;
if (!gProgramIsActive) {
return;
}
while (1) {
ddsd.dwSize = sizeof(ddsd);
hr = IDirectDrawSurface_Lock(gDirectDrawSurface1, NULL, &ddsd, 1, NULL);
if (hr == DD_OK) {
break;
}
if (hr == DDERR_SURFACELOST) {
if (IDirectDrawSurface_Restore(gDirectDrawSurface2) != DD_OK) {
return;
}
}
}
unsigned char* dest = (unsigned char*)ddsd.lpSurface + ddsd.lPitch * destY + 2 * destX;
SDL_LockSurface(gSdlSurface);
unsigned char* dest = (unsigned char*)gSdlSurface->pixels + gSdlSurface->pitch * destY + 2 * destX;
src += srcPitch * srcY + srcX;
@ -2387,11 +2344,23 @@ void _GNW95_MouseShowTransRect16(unsigned char* src, int srcPitch, int a3, int s
srcPtr++;
}
dest += ddsd.lPitch;
dest += gSdlSurface->pitch;
src += srcPitch;
}
IDirectDrawSurface_Unlock(gDirectDrawSurface1, ddsd.lpSurface);
SDL_UnlockSurface(gSdlSurface);
SDL_Rect srcRect;
srcRect.x = destX;
srcRect.y = destY;
srcRect.w = srcWidth;
srcRect.h = srcHeight;
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;
SDL_BlitSurface(gSdlSurface, &srcRect, gSdlWindowSurface, &destRect);
SDL_UpdateWindowSurface(gSdlWindow);
}
// Clears drawing surface.
@ -2399,36 +2368,22 @@ void _GNW95_MouseShowTransRect16(unsigned char* src, int srcPitch, int a3, int s
// 0x4CBBC8
void _GNW95_zero_vid_mem()
{
DDSURFACEDESC ddsd;
HRESULT hr;
unsigned char* surface;
if (!gProgramIsActive) {
return;
}
while (1) {
ddsd.dwSize = sizeof(DDSURFACEDESC);
SDL_LockSurface(gSdlSurface);
hr = IDirectDrawSurface_Lock(gDirectDrawSurface1, NULL, &ddsd, 1, NULL);
if (hr == DD_OK) {
break;
}
if (hr == DDERR_SURFACELOST) {
if (IDirectDrawSurface_Restore(gDirectDrawSurface2) != DD_OK) {
return;
}
}
unsigned char* surface = (unsigned char*)gSdlSurface->pixels;
for (unsigned int y = 0; y < gSdlSurface->h; y++) {
memset(surface, 0, gSdlSurface->w);
surface += gSdlSurface->pitch;
}
surface = (unsigned char*)ddsd.lpSurface;
for (unsigned int y = 0; y < ddsd.dwHeight; y++) {
memset(surface, 0, ddsd.dwWidth);
surface += ddsd.lPitch;
}
SDL_UnlockSurface(gSdlSurface);
IDirectDrawSurface_Unlock(gDirectDrawSurface1, ddsd.lpSurface);
SDL_BlitSurface(gSdlSurface, NULL, gSdlWindowSurface, NULL);
SDL_UpdateWindowSurface(gSdlWindow);
}
// 0x4CBC90

View File

@ -6,7 +6,7 @@
#include "geometry.h"
#include "window.h"
#include <SDL_scancode.h>
#include <SDL.h>
#include <stdbool.h>
@ -439,10 +439,6 @@ extern double gMouseSensitivity;
extern unsigned int _ticker_;
extern int gMouseButtonsState;
extern LPDIRECTDRAW gDirectDraw;
extern LPDIRECTDRAWSURFACE gDirectDrawSurface1;
extern LPDIRECTDRAWSURFACE gDirectDrawSurface2;
extern LPDIRECTDRAWPALETTE gDirectDrawPalette;
extern void (*_update_palette_func)();
extern bool gMmxEnabled;
extern bool gMmxProbed;
@ -530,6 +526,10 @@ extern KeyboardEvent gLastKeyboardEvent;
extern int gKeyboardLayout;
extern unsigned char gPressedPhysicalKeysCount;
extern SDL_Window* gSdlWindow;
extern SDL_Surface* gSdlWindowSurface;
extern SDL_Surface* gSdlSurface;
int coreInit(int a1);
void coreExit();
int _get_input();

View File

@ -132,11 +132,6 @@ int gameMoviesSave(File* stream)
// 0x44E690
int gameMoviePlay(int movie, int flags)
{
// TODO: SDL
paletteSetEntries(gPaletteBlack);
gGameMoviesSeen[movie] = 1;
return 0;
gGameMovieIsPlaying = true;
const char* movieFileName = gMovieFileNames[movie];

View File

@ -114,9 +114,6 @@ int _movieW;
// 0x638E98
void (*_movieFrameGrabFunc)();
// 0x638E9C
LPDIRECTDRAWSURFACE gMovieDirectDrawSurface;
// 0x638EA0
int _subtitleH;
@ -144,6 +141,8 @@ File* _alphaHandle;
// 0x638EC0
unsigned char* _alphaBuf;
SDL_Surface* gMovieSdlSurface = NULL;
// 0x4865FC
void* movieMallocImpl(size_t size)
{
@ -163,83 +162,80 @@ bool movieReadImpl(int fileHandle, void* buf, int count)
}
// 0x486654
void movieDirectImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
void movieDirectImpl(SDL_Surface* surface, int srcWidth, int srcHeight, int srcX, int srcY, int destWidth, int destHeight, int a8, int a9)
{
int v14;
int v15;
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(DDSURFACEDESC));
ddsd.dwSize = sizeof(DDSURFACEDESC);
RECT srcRect;
srcRect.left = a4;
srcRect.top = a5;
srcRect.right = a2 + a4;
srcRect.bottom = a3 + a5;
SDL_Rect srcRect;
srcRect.x = srcX;
srcRect.y = srcY;
srcRect.w = srcWidth;
srcRect.h = srcHeight;
v14 = gMovieWindowRect.right - gMovieWindowRect.left;
v15 = gMovieWindowRect.right - gMovieWindowRect.left + 1;
RECT destRect;
SDL_Rect destRect;
if (_movieScaleFlag) {
if ((gMovieFlags & MOVIE_EXTENDED_FLAG_0x08) != 0) {
destRect.top = (gMovieWindowRect.bottom - gMovieWindowRect.top + 1 - a7) / 2;
destRect.left = (v15 - 4 * a2 / 3) / 2;
destRect.y = (gMovieWindowRect.bottom - gMovieWindowRect.top + 1 - destHeight) / 2;
destRect.x = (v15 - 4 * srcWidth / 3) / 2;
} else {
destRect.top = _movieY + gMovieWindowRect.top;
destRect.left = gMovieWindowRect.left + _movieX;
destRect.y = _movieY + gMovieWindowRect.top;
destRect.x = gMovieWindowRect.left + _movieX;
}
destRect.right = 4 * a2 / 3 + destRect.left;
destRect.bottom = a7 + destRect.top;
destRect.w = 4 * srcWidth / 3;
destRect.h = destHeight;
} else {
if ((gMovieFlags & MOVIE_EXTENDED_FLAG_0x08) != 0) {
destRect.top = (gMovieWindowRect.bottom - gMovieWindowRect.top + 1 - a7) / 2;
destRect.left = (v15 - a6) / 2;
destRect.y = (gMovieWindowRect.bottom - gMovieWindowRect.top + 1 - destHeight) / 2;
destRect.x = (v15 - destWidth) / 2;
} else {
destRect.top = _movieY + gMovieWindowRect.top;
destRect.left = gMovieWindowRect.left + _movieX;
destRect.y = _movieY + gMovieWindowRect.top;
destRect.x = gMovieWindowRect.left + _movieX;
}
destRect.right = a6 + destRect.left;
destRect.bottom = a7 + destRect.top;
destRect.w = destWidth;
destRect.h = destHeight;
}
_lastMovieSX = a4;
_lastMovieSY = a5;
_lastMovieX = destRect.left;
_lastMovieY = destRect.top;
_lastMovieBH = a3;
_lastMovieW = destRect.right - destRect.left;
gMovieDirectDrawSurface = a1;
_lastMovieBW = a2;
_lastMovieH = destRect.bottom - destRect.top;
_lastMovieSX = srcX;
_lastMovieSY = srcY;
_lastMovieX = destRect.x;
_lastMovieY = destRect.y;
_lastMovieBH = srcHeight;
_lastMovieW = destRect.w;
gMovieSdlSurface = surface;
_lastMovieBW = srcWidth;
_lastMovieH = destRect.h;
// The code above assumes `gMovieWindowRect` is always at (0,0) which is not
// the case in HRP. For blitting purposes we have to adjust it relative to
// the actual origin. We do it here because the variables above need to stay
// in movie window coordinate space (for proper subtitles positioning).
destRect.left += gMovieWindowRect.left;
destRect.top += gMovieWindowRect.top;
destRect.right += gMovieWindowRect.left;
destRect.bottom += gMovieWindowRect.top;
destRect.x += gMovieWindowRect.left;
destRect.y += gMovieWindowRect.top;
HRESULT hr;
do {
if (_movieCaptureFrameFunc != NULL) {
if (IDirectDrawSurface_Lock(a1, NULL, &ddsd, 1, NULL) == DD_OK) {
_movieCaptureFrameFunc(ddsd.lpSurface, a2, destRect.left, destRect.top, destRect.right - destRect.left, destRect.bottom - destRect.top);
IDirectDrawSurface_Unlock(a1, ddsd.lpSurface);
}
if (_movieCaptureFrameFunc != NULL) {
if (SDL_LockSurface(surface) == 0) {
_movieCaptureFrameFunc(surface->pixels, srcWidth, destRect.x, destRect.y, destRect.w, destRect.h);
SDL_UnlockSurface(surface);
}
}
hr = IDirectDrawSurface_Blt(gDirectDrawSurface1, &destRect, a1, &srcRect, 0, NULL);
} while (hr != DD_OK && hr != DDERR_SURFACELOST && hr == DDERR_WASSTILLDRAWING);
// TODO: This is a super-ugly hack. The reason is that surfaces managed by
// MVE does not have palette. If we blit from these internal surfaces into
// backbuffer surface (with palette set), all we get is shiny white box.
SDL_SetSurfacePalette(surface, gSdlSurface->format->palette);
SDL_BlitSurface(surface, &srcRect, gSdlSurface, &destRect);
SDL_BlitSurface(gSdlSurface, NULL, gSdlWindowSurface, NULL);
SDL_UpdateWindowSurface(gSdlWindow);
}
// 0x486900
void movieBufferedImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
void movieBufferedImpl(SDL_Surface* a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
{
int v13;
@ -248,7 +244,7 @@ void movieBufferedImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, i
}
_lastMovieBW = a2;
gMovieDirectDrawSurface = a1;
gMovieSdlSurface = a1;
_lastMovieBH = a2;
_lastMovieW = a6;
_lastMovieH = a7;
@ -257,10 +253,7 @@ void movieBufferedImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, i
_lastMovieSX = a4;
_lastMovieSY = a5;
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof(DDSURFACEDESC);
if (IDirectDrawSurface_Lock(a1, NULL, &ddsd, 1, NULL) != DD_OK) {
if (SDL_LockSurface(a1) != 0) {
return;
}
@ -277,7 +270,7 @@ void movieBufferedImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, i
// TODO: Incomplete.
}
IDirectDrawSurface_Unlock(a1, ddsd.lpSurface);
SDL_UnlockSurface(a1);
}
// 0x486C74
@ -338,7 +331,6 @@ void movieInit()
movieLibSetMemoryProcs(movieMallocImpl, movieFreeImpl);
movieLibSetDirectSound(gDirectSound);
gMovieDirectSoundInitialized = (gDirectSound != NULL);
movieLibSetDirectDraw(gDirectDraw);
movieLibSetPaletteEntriesProc(movieSetPaletteEntriesImpl);
_MVE_sfSVGA(640, 480, 480, 0, 0, 0, 0, 0, 0);
movieLibSetReadProc(movieReadImpl);
@ -366,18 +358,16 @@ void _cleanupMovie(int a1)
_lastMovieBuffer = NULL;
}
if (gMovieDirectDrawSurface != NULL) {
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof(DDSURFACEDESC);
if (IDirectDrawSurface_Lock(gMovieDirectDrawSurface, 0, &ddsd, 1, NULL) == DD_OK) {
if (gMovieSdlSurface != NULL) {
if (SDL_LockSurface(gMovieSdlSurface) == 0) {
_lastMovieBuffer = (unsigned char*)internal_malloc_safe(_lastMovieBH * _lastMovieBW, __FILE__, __LINE__); // "..\\int\\MOVIE.C", 802
blitBufferToBuffer((unsigned char*)ddsd.lpSurface + ddsd.lPitch * _lastMovieSX + _lastMovieSY, _lastMovieBW, _lastMovieBH, ddsd.lPitch, _lastMovieBuffer, _lastMovieBW);
IDirectDrawSurface_Unlock(gMovieDirectDrawSurface, ddsd.lpSurface);
blitBufferToBuffer((unsigned char*)gMovieSdlSurface->pixels + gMovieSdlSurface->pitch * _lastMovieSX + _lastMovieSY, _lastMovieBW, _lastMovieBH, gMovieSdlSurface->pitch, _lastMovieBuffer, _lastMovieBW);
SDL_UnlockSurface(gMovieSdlSurface);
} else {
debugPrint("Couldn't lock movie surface\n");
}
gMovieDirectDrawSurface = NULL;
gMovieSdlSurface = NULL;
}
if (a1) {
@ -501,7 +491,7 @@ void _cleanupLast()
_lastMovieBuffer = NULL;
}
gMovieDirectDrawSurface = NULL;
gMovieSdlSurface = NULL;
}
// 0x48731C

View File

@ -3,7 +3,8 @@
#include "db.h"
#include "geometry.h"
#include "win32.h"
#include <SDL.h>
typedef enum MovieFlags {
MOVIE_FLAG_0x01 = 0x01,
@ -63,7 +64,6 @@ extern void (*_movieCaptureFrameFunc)(void*, int, int, int, int, int);
extern unsigned char* _lastMovieBuffer;
extern int _movieW;
extern void (*_movieFrameGrabFunc)();
extern LPDIRECTDRAWSURFACE gMovieDirectDrawSurface;
extern int _subtitleH;
extern int _running;
extern File* gMovieFileStream;
@ -74,11 +74,13 @@ extern bool gMovieDirectSoundInitialized;
extern File* _alphaHandle;
extern unsigned char* _alphaBuf;
extern SDL_Surface* gMovieSdlSurface;
void* movieMallocImpl(size_t size);
void movieFreeImpl(void* ptr);
bool movieReadImpl(int fileHandle, void* buf, int count);
void movieDirectImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
void movieBufferedImpl(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
void movieDirectImpl(SDL_Surface* a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
void movieBufferedImpl(SDL_Surface* a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
int _movieScaleSubRectAlpha(int a1);
int _blitAlpha(int win, unsigned char* a2, int a3, int a4, int a5);
int _blitNormal(int win, int a2, int a3, int a4, int a5);

View File

@ -52,9 +52,6 @@ unsigned short word_51EBE0[256] = {
// clang-format on
};
// 0x51EDE0
LPDIRECTDRAW gMovieLibDirectDraw = NULL;
// 0x51EDE4
int _sync_active = 0;
@ -76,14 +73,8 @@ int gMovieLibVolume = 0;
// 0x51EDFC
int gMovieLibPan = 0;
// 0x51EE00
LPDIRECTDRAWSURFACE gMovieDirectDrawSurface1 = NULL;
// 0x51EE04
LPDIRECTDRAWSURFACE gMovieDirectDrawSurface2 = NULL;
// 0x51EE08
void (*_sf_ShowFrame)(LPDIRECTDRAWSURFACE, int, int, int, int, int, int, int, int) = _do_nothing_2;
MovieShowFrameProc* _sf_ShowFrame = _do_nothing_2;
// 0x51EE0C
int dword_51EE0C = 1;
@ -436,6 +427,9 @@ int dword_6B403B;
// 0x6B403F
int dword_6B403F;
SDL_Surface* gMovieSdlSurface1;
SDL_Surface* gMovieSdlSurface2;
// 0x4F4800
void movieLibSetMemoryProcs(MallocProc* mallocProc, FreeProc* freeProc)
{
@ -524,13 +518,13 @@ void _MVE_sfSVGA(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8,
}
// 0x4F49F0
void _MVE_sfCallbacks(void (*fn)(LPDIRECTDRAWSURFACE, int, int, int, int, int, int, int, int))
void _MVE_sfCallbacks(MovieShowFrameProc* proc)
{
_sf_ShowFrame = fn;
_sf_ShowFrame = proc;
}
// 0x4F4A00
void _do_nothing_2(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
void _do_nothing_2(SDL_Surface* a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
{
}
@ -546,12 +540,6 @@ int _sub_4F4B5()
return 0;
}
// 0x4F4B80
void movieLibSetDirectDraw(LPDIRECTDRAW dd)
{
gMovieLibDirectDraw = dd;
}
// 0x4F4B90
void _MVE_rmCallbacks(int (*fn)())
{
@ -580,10 +568,6 @@ int _MVE_rmPrepMovie(int fileHandle, int a2, int a3, char a4)
{
_sub_4F4DD();
if (gMovieLibDirectDraw == NULL) {
return -11;
}
_rm_dx = a2;
_rm_dy = a3;
_rm_track_bit = 1 << a4;
@ -1434,16 +1418,14 @@ void _MVE_sndResume()
// 0x4F5CB0
int _nfConfig(int a1, int a2, int a3, int a4)
{
DDSURFACEDESC ddsd;
if (gMovieDirectDrawSurface1 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface1);
gMovieDirectDrawSurface1 = NULL;
if (gMovieSdlSurface1 != NULL) {
SDL_FreeSurface(gMovieSdlSurface1);
gMovieSdlSurface1 = NULL;
}
if (gMovieDirectDrawSurface2 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface2);
gMovieDirectDrawSurface2 = NULL;
if (gMovieSdlSurface2 != NULL) {
SDL_FreeSurface(gMovieSdlSurface2);
gMovieSdlSurface2 = NULL;
}
byte_6B400D = a1;
@ -1456,31 +1438,29 @@ int _nfConfig(int a1, int a2, int a3, int a4)
_mveBH >>= 1;
}
memset(&ddsd, 0, sizeof(DDSURFACEDESC));
ddsd.dwSize = sizeof(DDSURFACEDESC);
ddsd.dwFlags = (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT);
ddsd.dwWidth = _mveBW;
ddsd.dwHeight = _mveBH;
ddsd.ddsCaps.dwCaps = (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN);
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
int depth;
int rmask;
int gmask;
int bmask;
if (a4) {
ddsd.ddpfPixelFormat.dwFlags = 64;
ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
ddsd.ddpfPixelFormat.dwRBitMask = 0x7C00;
ddsd.ddpfPixelFormat.dwGBitMask = 0x3E0;
ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
depth = 16;
rmask = 0x7C00;
gmask = 0x3E0;
bmask = 0x1F;
} else {
ddsd.ddpfPixelFormat.dwFlags = 96;
ddsd.ddpfPixelFormat.dwRGBBitCount = 8;
depth = 8;
rmask = 0;
gmask = 0;
bmask = 0;
}
if (IDirectDraw_CreateSurface(gMovieLibDirectDraw, &ddsd, &gMovieDirectDrawSurface1, NULL) != DD_OK) {
gMovieSdlSurface1 = SDL_CreateRGBSurface(0, _mveBW, _mveBH, depth, rmask, gmask, bmask, 0);
if (gMovieSdlSurface1 == NULL) {
return 0;
}
if (IDirectDraw_CreateSurface(gMovieLibDirectDraw, &ddsd, &gMovieDirectDrawSurface2, NULL) != DD_OK) {
gMovieSdlSurface2 = SDL_CreateRGBSurface(0, _mveBW, _mveBH, depth, rmask, gmask, bmask, 0);
if (gMovieSdlSurface2 == NULL) {
return 0;
}
@ -1503,22 +1483,18 @@ int _nfConfig(int a1, int a2, int a3, int a4)
// 0x4F5E60
bool movieLockSurfaces()
{
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof(DDSURFACEDESC);
if (gMovieDirectDrawSurface1 != NULL && gMovieDirectDrawSurface2 != NULL) {
if (IDirectDrawSurface_Lock(gMovieDirectDrawSurface1, NULL, &ddsd, 0, NULL) != DD_OK) {
if (gMovieSdlSurface1 != NULL && gMovieSdlSurface2 != NULL) {
if (SDL_LockSurface(gMovieSdlSurface1) != 0) {
return false;
}
gMovieDirectDrawSurfaceBuffer1 = (unsigned char*)ddsd.lpSurface;
gMovieDirectDrawSurfaceBuffer1 = (unsigned char*)gMovieSdlSurface1->pixels;
if (IDirectDrawSurface_Lock(gMovieDirectDrawSurface2, NULL, &ddsd, 0, NULL) != DD_OK) {
if (SDL_LockSurface(gMovieSdlSurface2) != 0) {
return false;
}
gMovieDirectDrawSurfaceBuffer2 = (unsigned char*)ddsd.lpSurface;
gMovieDirectDrawSurfaceBuffer2 = (unsigned char*)gMovieSdlSurface2->pixels;
}
return true;
@ -1527,16 +1503,16 @@ bool movieLockSurfaces()
// 0x4F5EF0
void movieUnlockSurfaces()
{
IDirectDrawSurface_Unlock(gMovieDirectDrawSurface1, NULL);
IDirectDrawSurface_Unlock(gMovieDirectDrawSurface2, NULL);
SDL_UnlockSurface(gMovieSdlSurface1);
SDL_UnlockSurface(gMovieSdlSurface2);
}
// 0x4F5F20
void movieSwapSurfaces()
{
LPDIRECTDRAWSURFACE tmp = gMovieDirectDrawSurface2;
gMovieDirectDrawSurface2 = gMovieDirectDrawSurface1;
gMovieDirectDrawSurface1 = tmp;
SDL_Surface* tmp = gMovieSdlSurface2;
gMovieSdlSurface2 = gMovieSdlSurface1;
gMovieSdlSurface1 = tmp;
}
// 0x4F5F40
@ -1586,9 +1562,9 @@ void _sfShowFrame(int a1, int a2, int a3)
// TODO: Incomplete.
// _mve_ShowFrameField(off_6B4033, _mveBW, v6, dword_6B401B, dword_6B401F, dword_6B4017, dword_6B4023, v7, v5, a3);
} else if (dword_51EBDC == 4) {
_sf_ShowFrame(gMovieDirectDrawSurface1, _mveBW, v6, dword_6B401B, dword_6B401F, dword_6B4017, dword_6B4023, v7, v5);
_sf_ShowFrame(gMovieSdlSurface1, _mveBW, v6, dword_6B401B, dword_6B401F, dword_6B4017, dword_6B4023, v7, v5);
} else {
_sf_ShowFrame(gMovieDirectDrawSurface1, _mveBW, v6, 0, dword_6B401F, ((4 * _mveBW / dword_51EBDC - 12) & 0xFFFFFFF0) + 12, dword_6B4023, v7, v5);
_sf_ShowFrame(gMovieSdlSurface1, _mveBW, v6, 0, dword_6B401F, ((4 * _mveBW / dword_51EBDC - 12) & 0xFFFFFFF0) + 12, dword_6B4023, v7, v5);
}
}
@ -1682,14 +1658,14 @@ void _MVE_sndRelease()
// 0x4F6390
void _nfRelease()
{
if (gMovieDirectDrawSurface1 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface1);
gMovieDirectDrawSurface1 = NULL;
if (gMovieSdlSurface1 != NULL) {
SDL_FreeSurface(gMovieSdlSurface1);
gMovieSdlSurface1 = NULL;
}
if (gMovieDirectDrawSurface2 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface2);
gMovieDirectDrawSurface2 = NULL;
if (gMovieSdlSurface2 != NULL) {
SDL_FreeSurface(gMovieSdlSurface2);
gMovieSdlSurface2 = NULL;
}
}
@ -1702,8 +1678,8 @@ void _frLoad(STRUCT_4F6930* a1)
_io_mem_buf.field_8 = a1->field_8.field_8;
_io_handle = a1->fileHandle;
_io_next_hdr = a1->field_18;
gMovieDirectDrawSurface1 = a1->field_24;
gMovieDirectDrawSurface2 = a1->field_28;
gMovieSdlSurface1 = a1->field_24;
gMovieSdlSurface2 = a1->field_28;
dword_6B3AE8 = a1->field_2C;
gMovieDirectDrawSurfaceBuffer1 = a1->field_30;
gMovieDirectDrawSurfaceBuffer2 = a1->field_34;
@ -1730,8 +1706,8 @@ void _frSave(STRUCT_4F6930* a1)
ptr->field_8 = _io_mem_buf.field_8;
a1->fileHandle = _io_handle;
a1->field_18 = _io_next_hdr;
a1->field_24 = gMovieDirectDrawSurface1;
a1->field_28 = gMovieDirectDrawSurface2;
a1->field_24 = gMovieSdlSurface1;
a1->field_28 = gMovieSdlSurface2;
a1->field_2C = dword_6B3AE8;
a1->field_30 = gMovieDirectDrawSurfaceBuffer1;
a1->field_34 = gMovieDirectDrawSurfaceBuffer2;

View File

@ -3,8 +3,7 @@
#include "memory_defs.h"
#define DIRECTDRAW_VERSION 0x0300
#include <ddraw.h>
#include <SDL.h>
#define DIRECTSOUND_VERSION 0x0300
#include <dsound.h>
@ -28,6 +27,7 @@ typedef struct Mve {
#pragma pack()
typedef bool MovieReadProc(int fileHandle, void* buffer, int count);
typedef void(MovieShowFrameProc)(SDL_Surface*, int, int, int, int, int, int, int, int);
typedef struct STRUCT_4F6930 {
int field_0;
@ -35,8 +35,8 @@ typedef struct STRUCT_4F6930 {
STRUCT_6B3690 field_8;
int fileHandle;
int field_18;
LPDIRECTDRAWSURFACE field_24;
LPDIRECTDRAWSURFACE field_28;
SDL_Surface* field_24;
SDL_Surface* field_28;
int field_2C;
unsigned char* field_30;
unsigned char* field_34;
@ -55,7 +55,6 @@ typedef struct STRUCT_4F6930 {
extern int dword_51EBD8;
extern int dword_51EBDC;
extern unsigned short word_51EBE0[256];
extern LPDIRECTDRAW gMovieLibDirectDraw;
extern int _sync_active;
extern int _sync_late;
extern int _sync_FrameDropped;
@ -63,9 +62,7 @@ extern LPDIRECTSOUND gMovieLibDirectSound;
extern LPDIRECTSOUNDBUFFER gMovieLibDirectSoundBuffer;
extern int gMovieLibVolume;
extern int gMovieLibPan;
extern LPDIRECTDRAWSURFACE gMovieDirectDrawSurface1;
extern LPDIRECTDRAWSURFACE gMovieDirectDrawSurface2;
extern void (*_sf_ShowFrame)(LPDIRECTDRAWSURFACE, int, int, int, int, int, int, int, int);
extern MovieShowFrameProc* _sf_ShowFrame;
extern int dword_51EE0C;
extern void (*_pal_SetPalette)(unsigned char*, int, int);
extern int _rm_hold;
@ -136,6 +133,9 @@ extern unsigned char* gMovieDirectDrawSurfaceBuffer2;
extern int dword_6B403B;
extern int dword_6B403F;
extern SDL_Surface* gMovieSdlSurface1;
extern SDL_Surface* gMovieSdlSurface2;
void movieLibSetMemoryProcs(MallocProc* mallocProc, FreeProc* freeProc);
void movieLibSetReadProc(MovieReadProc* readProc);
void _MVE_MemInit(STRUCT_6B3690* a1, int a2, void* a3);
@ -144,11 +144,10 @@ void movieLibSetDirectSound(LPDIRECTSOUND ds);
void movieLibSetVolume(int volume);
void movieLibSetPan(int pan);
void _MVE_sfSVGA(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
void _MVE_sfCallbacks(void (*fn)(LPDIRECTDRAWSURFACE, int, int, int, int, int, int, int, int));
void _do_nothing_2(LPDIRECTDRAWSURFACE a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
void _MVE_sfCallbacks(MovieShowFrameProc* proc);
void _do_nothing_2(SDL_Surface* a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
void movieLibSetPaletteEntriesProc(void (*fn)(unsigned char*, int, int));
int _sub_4F4B5();
void movieLibSetDirectDraw(LPDIRECTDRAW dd);
void _MVE_rmCallbacks(int (*fn)());
void _sub_4F4BB(int a1);
void _MVE_rmFrameCounts(int* a1, int* a2);

View File

@ -7,9 +7,6 @@
#include <signal.h>
// 0x51E428
DirectDrawCreateProc* gDirectDrawCreateProc = NULL;
// 0x51E430
DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
@ -31,9 +28,6 @@ bool gProgramIsActive = false;
// GNW95MUTEX
HANDLE _GNW95_mutex = NULL;
// 0x51E44C
HMODULE gDDrawDLL = NULL;
// 0x51E454
HMODULE gDSoundDLL = NULL;
@ -96,16 +90,6 @@ bool _InitInstance()
// 0x4DE8D0
bool _LoadDirectX()
{
gDDrawDLL = LoadLibraryA("DDRAW.DLL");
if (gDDrawDLL == NULL) {
goto err;
}
gDirectDrawCreateProc = (DirectDrawCreateProc*)GetProcAddress(gDDrawDLL, "DirectDrawCreate");
if (gDirectDrawCreateProc == NULL) {
goto err;
}
gDSoundDLL = LoadLibraryA("DSOUND.DLL");
if (gDSoundDLL == NULL) {
goto err;
@ -134,13 +118,6 @@ void _UnloadDirectX(void)
if (gDSoundDLL != NULL) {
FreeLibrary(gDSoundDLL);
gDSoundDLL = NULL;
gDirectDrawCreateProc = NULL;
}
if (gDDrawDLL != NULL) {
FreeLibrary(gDDrawDLL);
gDDrawDLL = NULL;
gDirectSoundCreateProc = NULL;
}
}

View File

@ -4,9 +4,6 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define DIRECTDRAW_VERSION 0x0300
#include <ddraw.h>
#include <mmreg.h>
#define DIRECTSOUND_VERSION 0x0300
@ -14,10 +11,8 @@
#include <stdbool.h>
typedef HRESULT(__stdcall DirectDrawCreateProc)(GUID*, LPDIRECTDRAW*, IUnknown*);
typedef HRESULT(__stdcall DirectSoundCreateProc)(GUID*, LPDIRECTSOUND*, IUnknown*);
extern DirectDrawCreateProc* gDirectDrawCreateProc;
extern DirectSoundCreateProc* gDirectSoundCreateProc;
extern HWND gProgramWindow;
extern HINSTANCE gInstance;
@ -25,7 +20,6 @@ extern LPSTR gCmdLine;
extern int gCmdShow;
extern bool gProgramIsActive;
extern HANDLE _GNW95_mutex;
extern HMODULE gDDrawDLL;
extern HMODULE gDSoundDLL;
bool _InitInstance();