Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MxDisplaySurface::VTable0x34 #1264

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions LEGO1/omni/include/mxdisplaysurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class MxDisplaySurface : public MxCore {
MxS32 p_height,
MxBool p_RLE
); // vtable+0x30
virtual undefined4 VTable0x34(
undefined4,
undefined4,
undefined4,
undefined4,
undefined4,
undefined4
virtual void VTable0x34(
MxU8* p_pixels,
MxS32 p_bpp,
MxS32 p_width,
MxS32 p_height,
MxS32 p_x,
MxS32 p_y
); // vtable+0x34
virtual void Display(
MxS32 p_left,
Expand Down
72 changes: 69 additions & 3 deletions LEGO1/omni/src/video/mxdisplaysurface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mxdisplaysurface.h"

#include "mxbitmap.h"
#include "mxdebug.h"
#include "mxmisc.h"
#include "mxomni.h"
#include "mxpalette.h"
Expand Down Expand Up @@ -739,10 +740,75 @@ void MxDisplaySurface::DrawTransparentRLE(
}
}

// STUB: LEGO1 0x100bb850
undefined4 MxDisplaySurface::VTable0x34(undefined4, undefined4, undefined4, undefined4, undefined4, undefined4)
// FUNCTION: LEGO1 0x100bb850
// FUNCTION: BETA10 0x10141191
void MxDisplaySurface::VTable0x34(MxU8* p_pixels, MxS32 p_bpp, MxS32 p_width, MxS32 p_height, MxS32 p_x, MxS32 p_y)
{
return 0;
DDSURFACEDESC surfaceDesc;
memset(&surfaceDesc, 0, sizeof(surfaceDesc));
surfaceDesc.dwSize = sizeof(surfaceDesc);

HRESULT result = m_ddSurface2->Lock(NULL, &surfaceDesc, DDLOCK_WAIT, NULL);

if (result == DDERR_SURFACELOST) {
m_ddSurface2->Restore();
result = m_ddSurface2->Lock(NULL, &surfaceDesc, DDLOCK_WAIT, NULL);
}

if (result == DD_OK) {
MxU8* pixels = p_pixels;

switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) {
case 8: {
if (p_bpp == 16) {
MxTrace("16 bit source to 8 bit display NOT_IMPLEMENTED");
assert(0);
return;
}

MxU8* dst = (MxU8*) surfaceDesc.lpSurface + p_y * surfaceDesc.lPitch + p_x;
MxLong stride = p_width;
MxLong length = surfaceDesc.lPitch;

while (p_height--) {
memcpy(dst, pixels, p_width);
pixels += stride;
dst += length;
}
break;
}
case 16: {
if (p_bpp == 16) {
MxU8* dst = (MxU8*) surfaceDesc.lpSurface + p_y * surfaceDesc.lPitch + p_x;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct if both dest and src contain 16-bit pixels?
Shouldn't it be + 2 * p_x?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you are right. It looks like a bug. The function is never called in the game

MxLong stride = p_width * 2;
MxLong length = surfaceDesc.lPitch;

while (p_height--) {
memcpy(dst, pixels, 2 * p_width);
pixels += stride;
dst += length;
}
}
else if (p_bpp == 8) {
MxU8* dst = (MxU8*) surfaceDesc.lpSurface + p_y * surfaceDesc.lPitch + 2 * p_x;
MxLong stride = p_width * 2;
MxLong length = -2 * p_width + surfaceDesc.lPitch;

for (MxS32 i = 0; i < p_height; i++) {
for (MxS32 j = 0; j < p_width; j++) {
*(MxU16*) dst = m_16bitPal[*pixels++];
dst += 2;
}

pixels += stride;
dst += length;
}
}
}
}

m_ddSurface2->Unlock(surfaceDesc.lpSurface);
}
}

// FUNCTION: LEGO1 0x100bba50
Expand Down
Loading