Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f71b2b2
TextureRenderCore: add RGB555To565Asm.hpp, the original's handwritten…
kotijekriv Nov 7, 2026
1cb7eec
[IMPORT]: add custom RGB555To565Asm.hpp
kotijekriv Nov 7, 2026
d6d2014
headers: TextureRenderCore.bitmapFaceSizes holds 36 ints
kotijekriv Nov 7, 2026
8344fca
headers: TextureRenderCore.gmAndGfxImageDataBuffer is a byte*
kotijekriv Nov 7, 2026
d593ea7
checkIfGfxTgxStartsWithTransparentPixels: drop the cast the byte* buf…
kotijekriv Nov 7, 2026
8c4f735
reimplement: SHC_3BB0A8C1_0x0044C940 100.0% Reimplemented
kotijekriv Nov 7, 2026
1c36692
reimplement: SHC_3BB0A8C1_0x0044CAE0 100.0% Reimplemented
kotijekriv Nov 7, 2026
fa867c2
reimplement: SHC_3BB0A8C1_0x0044CB60 100.0% Reimplemented
kotijekriv Nov 7, 2026
6030b3a
reimplement: SHC_3BB0A8C1_0x0044F020 100.0% Reimplemented
kotijekriv Nov 7, 2026
0d3c9c3
reimplement: SHC_3BB0A8C1_0x0044F850 100.0% Reimplemented
kotijekriv Nov 7, 2026
6c9e276
reimplement: SHC_3BB0A8C1_0x00454620 100.0% Reimplemented
kotijekriv Nov 7, 2026
09b8359
reimplement: SHC_3BB0A8C1_0x004547C0 100.0% Reimplemented
kotijekriv Nov 7, 2026
5442a70
reimplement: SHC_3BB0A8C1_0x00454900 100.0% Reimplemented
kotijekriv Nov 7, 2026
46cc90e
reimplement: SHC_3BB0A8C1_0x00454A60 100.0% Reimplemented
kotijekriv Nov 7, 2026
7092040
reimplement: SHC_3BB0A8C1_0x00454CB0 100.0% Reimplemented
kotijekriv Nov 7, 2026
bf5081d
reimplement: SHC_3BB0A8C1_0x00455050 100.0% Reimplemented
kotijekriv Nov 7, 2026
2585581
reimplement: SHC_3BB0A8C1_0x00455390 100.0% Reimplemented
kotijekriv Nov 7, 2026
9328674
reimplement: SHC_3BB0A8C1_0x004554A0 100.0% Reimplemented
kotijekriv Nov 7, 2026
b41983f
reimplement: SHC_3BB0A8C1_0x00454700 100.0% Reimplemented
kotijekriv Nov 7, 2026
d60605d
reimplement: SHC_3BB0A8C1_0x004557B0 100.0% Reimplemented
kotijekriv Nov 7, 2026
b67b8bb
reimplement: SHC_3BB0A8C1_0x0044C9C0 100.0% Reimplemented
kotijekriv Nov 7, 2026
e401895
reimplement: SHC_3BB0A8C1_0x0044F6F0 100.0% Reimplemented
kotijekriv Nov 7, 2026
3290e40
reimplement: SHC_3BB0A8C1_0x004549F0 100.0% Reimplemented
kotijekriv Nov 7, 2026
d452b69
reimplement: SHC_3BB0A8C1_0x00455C60 100.0% Reimplemented
kotijekriv Nov 7, 2026
0e99baa
reimplement: SHC_3BB0A8C1_0x00455300 100.0% Reimplemented
kotijekriv Nov 7, 2026
bbe6673
reimplement: SHC_3BB0A8C1_0x0044CE00 100.0% Reimplemented
kotijekriv Nov 7, 2026
7fb2040
reimplement: SHC_3BB0A8C1_0x00455290 100.0% Reimplemented
kotijekriv Nov 7, 2026
26a2033
reimplement: SHC_3BB0A8C1_0x0044CD40 100.0% Reimplemented
kotijekriv Nov 7, 2026
8e4c48a
Constructor_TextureRenderCore: cast the two mallocs to the types of t…
kotijekriv Nov 7, 2026
008439d
headers: TextureRenderCore.gmProcessedImageData is a byte*
kotijekriv Nov 7, 2026
8a7df40
headers: TextureRenderCore.bitmapsFaces_0x94 is a ushort (*)[66][64]
kotijekriv Nov 7, 2026
0f23499
TextureRenderCore: drop the casts the two retyped fields make redundant
kotijekriv Nov 7, 2026
6e3f0db
headers: TextureRenderCore.bitmapsFaces_0x94 is a ushort*
kotijekriv Nov 7, 2026
a2dd7d0
TextureRenderCore: take the faces through the plain ushort* bitmapsFa…
kotijekriv Nov 7, 2026
d96eff7
Merge main (eef6f667a, gynt's header sync) into reimpl/UI-TextureRend…
kotijekriv Nov 7, 2026
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
2 changes: 2 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ src/OpenSHC/UI/Rendering/RenderButtonImageWithBlending.cpp
src/OpenSHC/UI/Helpers/SetTribesPatrolButtonPressed.cpp
src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemActionHandler_BuildMenu_UnitActionButtons.cpp
src/OpenSHC/UI/Rendering/RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk.cpp
src/OpenSHC/UI/Rendering/TextureRenderCore/transformTilesetToRGB565.cpp
src/OpenSHC/UI/Rendering/TextureRenderCore/transformTileObjectToRGB565.cpp
src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_DrawbridgeOpenClose.cpp
src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_GatehouseOpenClose.cpp
src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_WorkshopWeaponSelection.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "../TextureRenderCore.func.hpp"

#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/Rendering/Enums/RenderTarget.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x00455050
TextureRenderCore* TextureRenderCore::Constructor_TextureRenderCore(
int processedImageDataBufferSize, int gmAndGfxImageDataBufferSize, int unknownMemSize)
{
// the buffer sizes are kept here and allocated below; the second unknown buffer is half the first
this->gmProcessedImageDataBufferSize_0x74 = processedImageDataBufferSize;
this->gmAndGfxImageDataBufferSize_0x8c = gmAndGfxImageDataBufferSize;
if (unknownMemSize != 0) {
this->unknownMemSize_1_0x7c = unknownMemSize;
this->unknownMemSize_2_0x84 = unknownMemSize / 2;
} else {
this->unknownMemSize_1_0x7c = 0;
this->unknownMemSize_2_0x84 = 0;
}
this->bufferAllocStateUnk_0x0 = 0;
this->drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME;
this->currentRenderSurfaceIdentifierUnk_0x8 = OpenSHC::Rendering::Enums::RT_SCREEN_MENU;
this->field_0x128 = 0;
this->field_0x12c = 0;
this->field_0x2c = 1;
this->isZoom2 = 0;
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::clearSomeMemory, this)();
this->unknownSfxAndGmRelatedFlag = FALSE;
// bufferAllocStateUnk_0x0 records a failed allocation: 1 for an image buffer, 2 and 3 for the other two
this->gmProcessedImageData
= (byte*)MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->gmProcessedImageDataBufferSize_0x74);
if (!this->gmProcessedImageData) {
this->bufferAllocStateUnk_0x0 = 1;
return this;
}
if (unknownMemSize != 0) {
this->unknownMemPtr_1_0x80 = MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->unknownMemSize_1_0x7c);
if (!this->unknownMemPtr_1_0x80) {
this->bufferAllocStateUnk_0x0 = 2;
return this;
}
this->address2 = MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->unknownMemSize_2_0x84);
if (!this->address2) {
this->bufferAllocStateUnk_0x0 = 3;
return this;
}
} else {
this->unknownMemPtr_1_0x80 = NULL;
this->address2 = NULL;
}
this->gmAndGfxImageDataBuffer
= (byte*)MACRO_CALL(OpenSHC::OS_Func::_malloc)(this->gmAndGfxImageDataBufferSize_0x8c);
if (!this->gmAndGfxImageDataBuffer) {
this->bufferAllocStateUnk_0x0 = 1;
return this;
}
this->totalLoadedGfx = 0;
this->colorPaletteOverride = 0;
// room for one 64 x 66 RGB565 face bitmap per entry of bitmapFaceSizes, and their sizes, none loaded yet
this->bitmapsFaces_0x94 = (ushort*)MACRO_CALL(OpenSHC::OS_Func::_malloc)(
countof(this->bitmapFaceSizes) * 66 * 64 * sizeof(ushort));
for (int i = 0; i < countof(this->bitmapFaceSizes); ++i) {
this->bitmapFaceSizes[i] = 0;
}
return this;
}

}
}
}
91 changes: 91 additions & 0 deletions src/OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
HAND WRITTEN - not generated.

path: 'OpenSHC/UI/Rendering/TextureRenderCore/RGB555To565Asm.hpp'

Converting RGB555 pixels to RGB565 in place is handwritten assembly in the original, and it is a
MACRO: the identical instruction stream appears, never as a call, as the whole loop in
transformRawWithMarkerUnkToRGB555To565 (0x0044C940), transformTileObjectToRGB565 (0x0044CAE0) and
transformRawToRGB555To565 (0x0044CB60), and as the pixel body twice in transformTgxFromRGB555ToRGB565
(0x0044C9C0: at 0x0044CA08 with the marker test, at 0x0044CA6D without). It is recognisable by

- "cmp edx, 0" where MSVC would emit "test edx, edx",
- the pixel read with "mov ax, word ptr [esi]" and every channel computed in 16-bit registers,
where MSVC would emit movzx and work in 32 bits,
- the loop closed with an unconditional "jmp" back to its test.

Red goes into a dead parameter's stack slot, as in the original.

The macros expect these names in the enclosing function:

ushort _blue declared after the pixel pointer
ushort _green declared after _blue
RED the dead parameter that holds red: imageOffset in the loops, tgxDataPtr in
0x0044C9C0

and the loops also

ushort* _colorPtr the first pixel, gmProcessedImageData + imageOffset, declared first
int imageOffset the parameter

MACRO_RGB555_TO_565_PIXEL converts the pixel at [esi], then steps edx back by 2 and esi on by 2. With
MACRO_ASM_SKIP_MARKER_TEST and MACRO_ASM_SKIP_MARKER_LABEL it leaves pixels equal to 0xf81f untouched;
that is magenta already encoded as RGB565, the transparency marker. COUNT is the buffer size in bytes.
All of them clobber eax and ebx, the loops also edx and esi. They define assembler labels, so a loop
can be expanded once per function, and the pixel macro more than once, but with the skip label once.
*/

#pragma once

// clang-format off

#define MACRO_ASM_NONE
#define MACRO_ASM_SKIP_MARKER_TEST \
__asm cmp ax, 0xf81f \
__asm je skip_color
#define MACRO_ASM_SKIP_MARKER_LABEL \
__asm skip_color:

#define MACRO_RGB555_TO_565_PIXEL(RED, SKIP_TEST, SKIP_LABEL) \
__asm mov ax, word ptr [esi] \
SKIP_TEST \
__asm mov bx, ax \
__asm and bx, 0x1f \
__asm mov _blue, bx \
__asm mov bx, ax \
__asm and bx, 0x3e0 \
__asm shr bx, 5 \
__asm mov _green, bx \
__asm mov bx, ax \
__asm and bx, 0x7c00 \
__asm shr bx, 10 \
__asm mov word ptr RED, bx \
__asm mov ax, _blue \
__asm mov bx, _green \
__asm shl bx, 6 \
__asm add ax, bx \
__asm mov bx, word ptr RED \
__asm shl bx, 11 \
__asm add ax, bx \
__asm mov word ptr [esi], ax \
SKIP_LABEL \
__asm sub edx, 2 \
__asm add esi, 2

#define MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, SKIP_TEST, SKIP_LABEL) \
__asm mov esi, _colorPtr \
__asm mov edx, COUNT \
__asm next_color: \
__asm cmp edx, 0 \
__asm jle done \
MACRO_RGB555_TO_565_PIXEL(imageOffset, SKIP_TEST, SKIP_LABEL) \
__asm jmp next_color \
__asm done:

#define MACRO_RGB555_TO_565_LOOP(COUNT) \
MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, MACRO_ASM_NONE, MACRO_ASM_NONE)

#define MACRO_RGB555_TO_565_LOOP_SKIPPING_MARKER(COUNT) \
MACRO_RGB555_TO_565_LOOP_IMPL(COUNT, MACRO_ASM_SKIP_MARKER_TEST, MACRO_ASM_SKIP_MARKER_LABEL)

// clang-format on
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "OpenSHC/IO/Graphics/GfxRef.hpp"
#include "../TextureRenderCore.func.hpp"

#include "OpenSHC/IO/Graphics/TgxToken.hpp"
#include "OpenSHC/UI/Rendering/TextureRenderCore.hpp"

#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"

Expand All @@ -13,7 +13,7 @@ namespace UI {
BOOLEnum TextureRenderCore::checkIfGfxTgxStartsWithTransparentPixels(int gfxIndex)
{
int byteIndex = this->loadedGfxArray[gfxIndex].offsetInBuffer + 8;
byte checkByte = ((byte*)this->gmAndGfxImageDataBuffer)[byteIndex];
byte checkByte = this->gmAndGfxImageDataBuffer[byteIndex];
if ((checkByte & OpenSHC::IO::Graphics::TT_TGX_PIXEL_HEADER)
== OpenSHC::IO::Graphics::TT_TRANSPARENT_PIXELS) {
return TRUE;
Expand Down
59 changes: 59 additions & 0 deletions src/OpenSHC/UI/Rendering/TextureRenderCore/drawBitmapFace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "../TextureRenderCore.func.hpp"

#include "OpenSHC/Rendering/Enums/RenderTarget.hpp"

#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp"
#include "OpenSHC/Globals/COL_MAGENTA.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"
#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x0044CD40
void TextureRenderCore::drawBitmapFace(int bitmapFaceIndex, int xPos, int yPos)
{
// A face bitmap is 64 x 66 pixels; rowSkip is the surface's gap between two face rows
int rowSkip;
int lineByteWidth;
ushort* face = this->bitmapsFaces_0x94 + bitmapFaceIndex * 66 * 64;
// Stored through the global in each arm (a surface local: quick_diff 0.9804 -> 0.7255; this->: 0.5524)
switch (this->drawBufferChoiceValue) {
case OpenSHC::Rendering::Enums::RT_MAP_GAME:
DAT_TextureRenderCoreObject::instance.currentRenderSurface
= DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame;
rowSkip = 4056 - 64;
lineByteWidth = 4056 * 2;
break;
case OpenSHC::Rendering::Enums::RT_BUTTON_AND_ALPHA:
DAT_TextureRenderCoreObject::instance.currentRenderSurface
= AlphaAndButtonSurfaceObj::instance.surfacePtr;
rowSkip = AlphaAndButtonSurfaceObj::instance.currentImageWidth - 64;
lineByteWidth = AlphaAndButtonSurfaceObj::instance.currentImageWidth * 2;
break;
default:
DAT_TextureRenderCoreObject::instance.currentRenderSurface
= DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu;
rowSkip = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine / 2 - 64;
lineByteWidth = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine;
break;
}
ushort* pixel = (ushort*)((byte*)DAT_TextureRenderCoreObject::instance.currentRenderSurface
+ lineByteWidth * yPos + xPos * 2);
for (int row = 0; row < 66; ++row) {
for (int column = 0; column < 64; ++column) {
ushort const color = *face;
++face;
if (color != (ushort)COL_MAGENTA::instance.shortValue) {
*pixel = color;
}
++pixel;
}
pixel += rowSkip;
}
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "../TextureRenderCore.func.hpp"

#include "OpenSHC/IO/Graphics/GmImageType.hpp"

#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp"
#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp"
#include "OpenSHC/Globals/GMFirstPictureIndex.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004554A0
void TextureRenderCore::drawTgxGmOnFlaggedSurface(GmID gmId, int imageIndexInGm, int xPos, int yPos)
{
// picture imageIndexInGm of the gm file, counted from 1
int const imageIndex = GMFirstPictureIndex::instance[gmId] + imageIndexInGm - 1;
ushort* const source = (ushort*)(this->gmProcessedImageData + DAT_GMImageOffsets::instance[imageIndex]);
// interface elements and compressed images draw the same way
// two tests as in the original (one test with ||: quick_diff 1.0000 -> 0.3014)
if (this->gmFileHeaderColorpaletteArray[gmId].ImageType == OpenSHC::IO::Graphics::GIT_InterfaceElement) {
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawTgxOnFlaggedSurface, this)(xPos,
yPos, DAT_GMImageHeaders::instance.imh[imageIndex].width,
DAT_GMImageHeaders::instance.imh[imageIndex].height, source);
}
if (this->gmFileHeaderColorpaletteArray[gmId].ImageType == OpenSHC::IO::Graphics::GIT_CompressedImage) {
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawTgxOnFlaggedSurface, this)(xPos,
yPos, DAT_GMImageHeaders::instance.imh[imageIndex].width,
DAT_GMImageHeaders::instance.imh[imageIndex].height, source);
}
}

}
}
}
Loading
Loading