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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,8 @@
#include "db.h" #include "db.h"
#include "geometry.h" #include "geometry.h"
#include "win32.h"
#include <SDL.h>
typedef enum MovieFlags { typedef enum MovieFlags {
MOVIE_FLAG_0x01 = 0x01, MOVIE_FLAG_0x01 = 0x01,
@ -63,7 +64,6 @@ extern void (*_movieCaptureFrameFunc)(void*, int, int, int, int, int);
extern unsigned char* _lastMovieBuffer; extern unsigned char* _lastMovieBuffer;
extern int _movieW; extern int _movieW;
extern void (*_movieFrameGrabFunc)(); extern void (*_movieFrameGrabFunc)();
extern LPDIRECTDRAWSURFACE gMovieDirectDrawSurface;
extern int _subtitleH; extern int _subtitleH;
extern int _running; extern int _running;
extern File* gMovieFileStream; extern File* gMovieFileStream;
@ -74,11 +74,13 @@ extern bool gMovieDirectSoundInitialized;
extern File* _alphaHandle; extern File* _alphaHandle;
extern unsigned char* _alphaBuf; extern unsigned char* _alphaBuf;
extern SDL_Surface* gMovieSdlSurface;
void* movieMallocImpl(size_t size); void* movieMallocImpl(size_t size);
void movieFreeImpl(void* ptr); void movieFreeImpl(void* ptr);
bool movieReadImpl(int fileHandle, void* buf, int count); 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 movieDirectImpl(SDL_Surface* 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 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 _movieScaleSubRectAlpha(int a1);
int _blitAlpha(int win, unsigned char* a2, int a3, int a4, int a5); 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); 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 // clang-format on
}; };
// 0x51EDE0
LPDIRECTDRAW gMovieLibDirectDraw = NULL;
// 0x51EDE4 // 0x51EDE4
int _sync_active = 0; int _sync_active = 0;
@ -76,14 +73,8 @@ int gMovieLibVolume = 0;
// 0x51EDFC // 0x51EDFC
int gMovieLibPan = 0; int gMovieLibPan = 0;
// 0x51EE00
LPDIRECTDRAWSURFACE gMovieDirectDrawSurface1 = NULL;
// 0x51EE04
LPDIRECTDRAWSURFACE gMovieDirectDrawSurface2 = NULL;
// 0x51EE08 // 0x51EE08
void (*_sf_ShowFrame)(LPDIRECTDRAWSURFACE, int, int, int, int, int, int, int, int) = _do_nothing_2; MovieShowFrameProc* _sf_ShowFrame = _do_nothing_2;
// 0x51EE0C // 0x51EE0C
int dword_51EE0C = 1; int dword_51EE0C = 1;
@ -436,6 +427,9 @@ int dword_6B403B;
// 0x6B403F // 0x6B403F
int dword_6B403F; int dword_6B403F;
SDL_Surface* gMovieSdlSurface1;
SDL_Surface* gMovieSdlSurface2;
// 0x4F4800 // 0x4F4800
void movieLibSetMemoryProcs(MallocProc* mallocProc, FreeProc* freeProc) 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 // 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 // 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; return 0;
} }
// 0x4F4B80
void movieLibSetDirectDraw(LPDIRECTDRAW dd)
{
gMovieLibDirectDraw = dd;
}
// 0x4F4B90 // 0x4F4B90
void _MVE_rmCallbacks(int (*fn)()) void _MVE_rmCallbacks(int (*fn)())
{ {
@ -580,10 +568,6 @@ int _MVE_rmPrepMovie(int fileHandle, int a2, int a3, char a4)
{ {
_sub_4F4DD(); _sub_4F4DD();
if (gMovieLibDirectDraw == NULL) {
return -11;
}
_rm_dx = a2; _rm_dx = a2;
_rm_dy = a3; _rm_dy = a3;
_rm_track_bit = 1 << a4; _rm_track_bit = 1 << a4;
@ -1434,16 +1418,14 @@ void _MVE_sndResume()
// 0x4F5CB0 // 0x4F5CB0
int _nfConfig(int a1, int a2, int a3, int a4) int _nfConfig(int a1, int a2, int a3, int a4)
{ {
DDSURFACEDESC ddsd; if (gMovieSdlSurface1 != NULL) {
SDL_FreeSurface(gMovieSdlSurface1);
if (gMovieDirectDrawSurface1 != NULL) { gMovieSdlSurface1 = NULL;
IDirectDrawSurface_Release(gMovieDirectDrawSurface1);
gMovieDirectDrawSurface1 = NULL;
} }
if (gMovieDirectDrawSurface2 != NULL) { if (gMovieSdlSurface2 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface2); SDL_FreeSurface(gMovieSdlSurface2);
gMovieDirectDrawSurface2 = NULL; gMovieSdlSurface2 = NULL;
} }
byte_6B400D = a1; byte_6B400D = a1;
@ -1456,31 +1438,29 @@ int _nfConfig(int a1, int a2, int a3, int a4)
_mveBH >>= 1; _mveBH >>= 1;
} }
memset(&ddsd, 0, sizeof(DDSURFACEDESC)); int depth;
int rmask;
ddsd.dwSize = sizeof(DDSURFACEDESC); int gmask;
ddsd.dwFlags = (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT); int bmask;
ddsd.dwWidth = _mveBW;
ddsd.dwHeight = _mveBH;
ddsd.ddsCaps.dwCaps = (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN);
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
if (a4) { if (a4) {
ddsd.ddpfPixelFormat.dwFlags = 64; depth = 16;
ddsd.ddpfPixelFormat.dwRGBBitCount = 16; rmask = 0x7C00;
ddsd.ddpfPixelFormat.dwRBitMask = 0x7C00; gmask = 0x3E0;
ddsd.ddpfPixelFormat.dwGBitMask = 0x3E0; bmask = 0x1F;
ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
} else { } else {
ddsd.ddpfPixelFormat.dwFlags = 96; depth = 8;
ddsd.ddpfPixelFormat.dwRGBBitCount = 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; 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; return 0;
} }
@ -1503,22 +1483,18 @@ int _nfConfig(int a1, int a2, int a3, int a4)
// 0x4F5E60 // 0x4F5E60
bool movieLockSurfaces() bool movieLockSurfaces()
{ {
DDSURFACEDESC ddsd; if (gMovieSdlSurface1 != NULL && gMovieSdlSurface2 != NULL) {
if (SDL_LockSurface(gMovieSdlSurface1) != 0) {
ddsd.dwSize = sizeof(DDSURFACEDESC);
if (gMovieDirectDrawSurface1 != NULL && gMovieDirectDrawSurface2 != NULL) {
if (IDirectDrawSurface_Lock(gMovieDirectDrawSurface1, NULL, &ddsd, 0, NULL) != DD_OK) {
return false; 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; return false;
} }
gMovieDirectDrawSurfaceBuffer2 = (unsigned char*)ddsd.lpSurface; gMovieDirectDrawSurfaceBuffer2 = (unsigned char*)gMovieSdlSurface2->pixels;
} }
return true; return true;
@ -1527,16 +1503,16 @@ bool movieLockSurfaces()
// 0x4F5EF0 // 0x4F5EF0
void movieUnlockSurfaces() void movieUnlockSurfaces()
{ {
IDirectDrawSurface_Unlock(gMovieDirectDrawSurface1, NULL); SDL_UnlockSurface(gMovieSdlSurface1);
IDirectDrawSurface_Unlock(gMovieDirectDrawSurface2, NULL); SDL_UnlockSurface(gMovieSdlSurface2);
} }
// 0x4F5F20 // 0x4F5F20
void movieSwapSurfaces() void movieSwapSurfaces()
{ {
LPDIRECTDRAWSURFACE tmp = gMovieDirectDrawSurface2; SDL_Surface* tmp = gMovieSdlSurface2;
gMovieDirectDrawSurface2 = gMovieDirectDrawSurface1; gMovieSdlSurface2 = gMovieSdlSurface1;
gMovieDirectDrawSurface1 = tmp; gMovieSdlSurface1 = tmp;
} }
// 0x4F5F40 // 0x4F5F40
@ -1586,9 +1562,9 @@ void _sfShowFrame(int a1, int a2, int a3)
// TODO: Incomplete. // TODO: Incomplete.
// _mve_ShowFrameField(off_6B4033, _mveBW, v6, dword_6B401B, dword_6B401F, dword_6B4017, dword_6B4023, v7, v5, a3); // _mve_ShowFrameField(off_6B4033, _mveBW, v6, dword_6B401B, dword_6B401F, dword_6B4017, dword_6B4023, v7, v5, a3);
} else if (dword_51EBDC == 4) { } 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 { } 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 // 0x4F6390
void _nfRelease() void _nfRelease()
{ {
if (gMovieDirectDrawSurface1 != NULL) { if (gMovieSdlSurface1 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface1); SDL_FreeSurface(gMovieSdlSurface1);
gMovieDirectDrawSurface1 = NULL; gMovieSdlSurface1 = NULL;
} }
if (gMovieDirectDrawSurface2 != NULL) { if (gMovieSdlSurface2 != NULL) {
IDirectDrawSurface_Release(gMovieDirectDrawSurface2); SDL_FreeSurface(gMovieSdlSurface2);
gMovieDirectDrawSurface2 = NULL; gMovieSdlSurface2 = NULL;
} }
} }
@ -1702,8 +1678,8 @@ void _frLoad(STRUCT_4F6930* a1)
_io_mem_buf.field_8 = a1->field_8.field_8; _io_mem_buf.field_8 = a1->field_8.field_8;
_io_handle = a1->fileHandle; _io_handle = a1->fileHandle;
_io_next_hdr = a1->field_18; _io_next_hdr = a1->field_18;
gMovieDirectDrawSurface1 = a1->field_24; gMovieSdlSurface1 = a1->field_24;
gMovieDirectDrawSurface2 = a1->field_28; gMovieSdlSurface2 = a1->field_28;
dword_6B3AE8 = a1->field_2C; dword_6B3AE8 = a1->field_2C;
gMovieDirectDrawSurfaceBuffer1 = a1->field_30; gMovieDirectDrawSurfaceBuffer1 = a1->field_30;
gMovieDirectDrawSurfaceBuffer2 = a1->field_34; gMovieDirectDrawSurfaceBuffer2 = a1->field_34;
@ -1730,8 +1706,8 @@ void _frSave(STRUCT_4F6930* a1)
ptr->field_8 = _io_mem_buf.field_8; ptr->field_8 = _io_mem_buf.field_8;
a1->fileHandle = _io_handle; a1->fileHandle = _io_handle;
a1->field_18 = _io_next_hdr; a1->field_18 = _io_next_hdr;
a1->field_24 = gMovieDirectDrawSurface1; a1->field_24 = gMovieSdlSurface1;
a1->field_28 = gMovieDirectDrawSurface2; a1->field_28 = gMovieSdlSurface2;
a1->field_2C = dword_6B3AE8; a1->field_2C = dword_6B3AE8;
a1->field_30 = gMovieDirectDrawSurfaceBuffer1; a1->field_30 = gMovieDirectDrawSurfaceBuffer1;
a1->field_34 = gMovieDirectDrawSurfaceBuffer2; a1->field_34 = gMovieDirectDrawSurfaceBuffer2;

View File

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

View File

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

View File

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