From 590aed0f63270318c58c7ee79915bb0346ab4621 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 07:26:38 +0100 Subject: [PATCH 1/4] reimplement: SHC_3BB0A8C1_0x004B5330 100.0% Reimplemented MinimapViewState::renderMinimapTileStripWithLuminescence, the minimap's second picture: for a strip of the screen tile rows it takes the colour of what stands on each tile (moat, trees, plain tiles with one display flag, or the first entry of MiniMapDefinedData's table that shares a bit with the tile's flags), scales it by the tile's luminescence (RGB555 or RGB565) and writes it into the second minimap buffer, at full or at half size; a tile without a colour takes the terrain picture's pixel. It is the sibling of renderMinimapTileColors (0x004B58D0) and is written the same way, from the original's listing. The function was a 21.4% draft in #313 ("Pixel store and registers differ"). #313's version started from gynt's draft as it stood on his fork's reimpl/UI-Core-development, 10280b1610 (2026-10-25; status line "9.3% | Reimplemented, asm differs"), with the body rewritten from the listing. His newest version is 4a1f8dd396 (2026-11-02, a style pass over the UI folders; "9.0% | Style pass, asm differs") on reimpl/UI-MenuItems-development, where 1056d3fa28, 2da2d36623 and b60bb72c08 are earlier steps of it (9.03%); 24080c9f6c and 1955a67481 (9.0%) are the same draft on reimpl/UI-Core (#256). No behaviour change against #313's code (the strip's end is now divided signed, as in the original; the same for every real argument). What #313 changed against every version of the draft stays: - `mapSize <= 200` where the draft has `< 200` (every 200 by 200 map); - the return past the strip's end, which the draft lacks (reached by drawMinimap's 2% strips). gynt has it himself in 8ca78619cd on reimpl/Wilps-2026-10-18; - the second buffer written through `this`, as in the original, where every version of the draft goes through the global instance (the same address while `this` is DAT_MinimapViewState); - the screen tile table indexed from its base on today's main (not the draft's mistake: its `- 8` was right for the header of its day). What the match needed: - The pixel stores are handwritten assembly in the original: the same two stores as in renderMinimapTileColors, with the address computation of renderMinimapPreview and drawCurrentPixel (`add eax, eax` and a `mul edx` by the row pitch, here the constant 400). Two `__asm` blocks, one per size. No frame pointer, as in the original. - The colour is a 16-bit local, and the blue channel and the mix are written out in both colour-mode arms. Here the original has one shared end for the two arms: the compiler merges the two identical ends itself. Written once behind the arms, the registers of the whole block are different ones. - The channels initialised blue, green, red; red's and green's masks as statements right after their caps, blue's in the mix, as in renderMinimapTileColors. - The table loop: the entry's bits in a local that is set before the tile's flags are read, the first test on that local and the loop's test on the table. The two tests take their operands in the order the variables are first set; with the first test on the table and the loop's on the local, both come out swapped. A flag tells "no entry" from "found"; the compiler turns it into the two jumps. The loop is a guarded do-while: a plain while loop reads 99.7% (one of the two tests swapped, whether it tests the local or the table), and a for loop with a break at its end compiles to two instructions more. - The five simple initialisations before the buffer and the strip rows, so that every stack slot is the original's; the row base holding the orientation's offset first; the viewport height read from the global a second time; the column loop's bound in its test; the tile read before x and y; y inside the tile loop and a copy of x at the top of the full-size branch; the row base stepped in the row loop's header. The channel masks have names in a small file-local enum, as in renderMinimapTileColors. Measured in a narrow build on main 3458fea34 of this file alone (main is now 812d14969: #399 and #398 add only the optional function-visibility units, off by default), struct resolvers and its resolver on: 100.0% raw and normalised, no diff entry. Not run in game. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...renderMinimapTileStripWithLuminescence.cpp | 252 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp diff --git a/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp b/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp new file mode 100644 index 0000000000..d44bfd3b18 --- /dev/null +++ b/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp @@ -0,0 +1,252 @@ +#include "../MinimapViewState.func.hpp" + +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Rendering/ColorMode.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_MiniMapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace Map::LogicHelpers; + + // The channels' bits in an RGB555 and in an RGB565 colour. + enum { + RGB555_RED = 31744, // 0x7c00 + RGB555_GREEN = 992, // 0x03e0 + RGB565_RED = 63488, // 0xf800 + RGB565_GREEN = 2016, // 0x07e0 + RGB_BLUE = 31 // 0x001f + }; + + // Draws a strip of the screen tile rows into the second minimap buffer: what stands on each tile, in its light. + // FUNCTION: STRONGHOLDCRUSADER 0x004B5330 + void MinimapViewState::renderMinimapTileStripWithLuminescence( + uint flags, int widthFactor, int heightFactor, uint stripStart, int stripLength) + { + // These five in this order before the buffer and the strip rows (after them, the stack slots change). + int firstRow = 0; + BOOLEnum isRGB565 = FALSE; + int rowBase = 8; + int scale = 1; + int columnDivisor = 2; + // The assembly below takes the buffer's address from this local. + ushort* const buffer = this->field_0x44; + // the strip covers rows stripStart% .. stripStart + stripLength% of the 400 screen tile rows + // (int): the original divides signed (stripStart is a uint in the header). + int const firstStripRow = (int)(stripStart * 400) / 100; + int const endStripRow = (int)((stripStart + stripLength) * 400) / 100; + if (flags & 4) { + // zoomed out: half the size + scale = 2; + } + int const columns = 400 / widthFactor * scale; + int const rowCount = scale * 200; + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { + isRGB565 = TRUE; + } + if (DAT_TileMapState::instance.mapSize <= 200) { + firstRow = 100; + columnDivisor = 1; + } + int const viewportHeight = DAT_ViewportRenderState::instance.viewportState.viewportHeight; + // The global again (from the first local, viewportHeight + 1 is added up anew in every row). + int const otherParity = DAT_ViewportRenderState::instance.viewportState.viewportHeight + 1; + int rowParity = otherParity; + // rowBase first holds the orientation's offset into the screen tile table (in a variable of its own, the row + // base's sum has its operands the other way round). + if (DAT_TileMapState::instance.mapOrientation != Map::Enums::MO_NORTH) { + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { + rowBase = 80408; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH) { + rowBase = 160808; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { + rowBase = 241208; + } + } + int const firstColumn = firstRow / 2; + rowBase = firstColumn * 401 + rowBase + 1; + int rowLength; + // rowBase steps in the header, so that the continues below step it too. + for (int row = firstRow; row < rowCount - firstRow; ++row, rowBase += rowLength) { + // the screen tile rows are staggered: every other row starts half a tile in and has one entry less in + // the screen tile table (200 against 201) + int rowX; + if (rowParity == otherParity) { + rowParity = viewportHeight; + rowX = widthFactor / 2; + rowLength = 200; + } else { + rowParity = otherParity; + rowX = 0; + rowLength = 201; + } + if (row < firstStripRow) { + continue; + } + if (row >= endStripRow) { + return; + } + if (scale == 2 && (row * heightFactor & 1)) { + continue; + } + // The bound in the loop's test (in a local in front of the loop, the first column comes after it). + for (int column = firstColumn - 2; column < columns / columnDivisor - firstColumn; ++column) { + // Both set before the tile's flags are read (the table loop's tests take their operands in the + // order the variables are first set). + int entry = 0; + int entryBits = 0; + // The tile before x and y (after them, the tile loop's set-up is in another order). + int const tile = DAT_ViewportRenderState::instance.screenPointToTileNumber[column + rowBase]; + int const x = (column - firstColumn) * widthFactor + rowX; + int const y = (row - firstRow) * heightFactor; + int const logic = DAT_TileMapState::instance.LogicLayer[tile]; + int const random = DAT_TileMapState::instance.RandomLayer[tile]; + int const luminescence = DAT_TileMapState::instance.LuminesenceLayer[tile]; + // 16 bits wide (as a uint, the mix below extends each channel on its own). + ushort color; + if (logic & L_MOAT) { + color = DAT_MiniMapDefinedData::instance.field_0x74[isRGB565 + (random & 3) * 2]; + } else if (logic & (L_TREE | L_TREE_VARIATION)) { + color = DAT_MiniMapDefinedData::instance.field_0x144[isRGB565 + (random & 3) * 2]; + } else if (logic & L_PLAIN2_AND_PITCH) { + if (DAT_TileMapState::instance.MiscDisplayLayer[tile] & MD_RUBBLE_EDGEUnk) { + color = DAT_MiniMapDefinedData::instance.field_0x20[isRGB565]; + } else { + color = 0; + } + } else { + // The colour of the first table entry sharing a bit with the flags; a 0 entry ends it. + // First test on entryBits, the loop's on the table (swapped, both swap their operands). + bool hasEntry = true; + entryBits = DAT_MiniMapDefinedData::instance.MinimapColorByLogicBit[entry].integer; + if (!(entryBits & logic)) { + // A do-while (a while loop swaps the operands of one of the two tests; a for loop with a + // break at its end adds two instructions). + do { + if (!entryBits) { + hasEntry = false; + break; + } + ++entry; + entryBits = DAT_MiniMapDefinedData::instance.MinimapColorByLogicBit[entry].integer; + } while (!(DAT_MiniMapDefinedData::instance.MinimapColorByLogicBit[entry].integer & logic)); + } + if (hasEntry) { + color = DAT_MiniMapDefinedData::instance.MinimapColorByLogicBit[entry] + .colorModeSpecificValue[isRGB565]; + } else { + color = 0; + } + } + // brightness entry 2 is 100%: the colour as it is + if (luminescence != 2 && color != 0 && !(logic & L_STOCKPILEUnk)) { + int const brightness = DAT_MiniMapDefinedData::instance.LuminescenceBrightnessPercent[luminescence]; + // Set in this order (the mix takes green and red in the order they are first set). + int blue = 0; + int green = 0; + int red = 0; + // Red's and green's masks right after their caps, blue's in the mix. Blue and the mix in + // both arms (written once behind them, the registers of the whole block change). + if (!isRGB565) { + red = (color & RGB555_RED) * brightness / 100; + if (red > RGB555_RED) { + red = RGB555_RED; + } + red &= RGB555_RED; + green = (color & RGB555_GREEN) * brightness / 100; + if (green > RGB555_GREEN) { + green = RGB555_GREEN; + } + green &= RGB555_GREEN; + blue = (color & RGB_BLUE) * brightness / 100; + if (blue > RGB_BLUE) { + blue = RGB_BLUE; + } + color = (ushort)(blue & RGB_BLUE | green | red); + } else { + red = (color & RGB565_RED) * brightness / 100; + if (red > RGB565_RED) { + red = RGB565_RED; + } + red &= RGB565_RED; + green = (color & RGB565_GREEN) * brightness / 100; + if (green > RGB565_GREEN) { + green = RGB565_GREEN; + } + green &= RGB565_GREEN; + blue = (color & RGB_BLUE) * brightness / 100; + if (blue > RGB_BLUE) { + blue = RGB_BLUE; + } + color = (ushort)(blue & RGB_BLUE | green | red); + } + } + // A tile without a colour takes the terrain picture's pixel, once, at the first pixel it draws. + // The pixel stores are handwritten assembly in the original, transcribed from the binary. + if (scale == 1) { + // A copy for the assembly (x named there is stored at the top of the tile loop). + int const pixelX = x; + for (int offsetX = 0; offsetX < widthFactor; ++offsetX) { + if (x + offsetX < 0 || x + offsetX >= columns * widthFactor) { + continue; + } + for (int offsetY = 0; offsetY < heightFactor; ++offsetY) { + if (color == 0) { + color = this->minimapPixelBuffer[(y + offsetY) * 400 / 2 + x + offsetX]; + } + __asm { + mov edi, buffer + mov eax, pixelX + add eax, offsetX + add eax, eax + add edi, eax + mov eax, y + add eax, offsetY + mov edx, 400 + mul edx + add edi, eax + mov ax, color + mov word ptr [edi], ax + } + } + } + } else { + // Every other pixel at half the position (a plain loop skipping odd ones loses the match). + for (int offsetX = x & 1; offsetX < widthFactor; offsetX += 2) { + if (x + offsetX < 0 || x + offsetX >= columns * widthFactor) { + continue; + } + int const halfX = (x + offsetX) / scale; + for (int offsetY = 0; offsetY < heightFactor; ++offsetY) { + int const halfY = (y + offsetY) / scale; + if (color == 0) { + color = this->minimapPixelBuffer[halfY * 400 / 2 + halfX]; + } + __asm { + mov edi, buffer + mov eax, halfX + add eax, eax + add edi, eax + mov eax, halfY + mov edx, 400 + mul edx + add edi, eax + mov ax, color + mov word ptr [edi], ax + } + } + } + } + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..3ba83614c1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -26883,7 +26883,7 @@ SHC_3BB0A8C1_0x004B5280 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B5300 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B5330 | 0.0% | Pending +SHC_3BB0A8C1_0x004B5330 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B5480 | 0.0% | Pending From 2246b2f5b4caade86b81bd8b1a41fb5784f7bb3a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 15:32:51 +0100 Subject: [PATCH 2/4] headers: ColorChannelMask, the channel bits of an RGB555 and an RGB565 colour A new enum in OpenSHC::Rendering beside ColorMode: the masks of the red, green and blue channels in the two colour modes. renderMinimapTileStripWithLuminescence (and renderMinimapTileColors) scale each channel of a minimap colour by the tile's light and cap it at these masks; they had them as a file-local enum. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Rendering/ColorChannelMask.hpp | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/OpenSHC/Rendering/ColorChannelMask.hpp diff --git a/src/OpenSHC/Rendering/ColorChannelMask.hpp b/src/OpenSHC/Rendering/ColorChannelMask.hpp new file mode 100644 index 0000000000..0acccad586 --- /dev/null +++ b/src/OpenSHC/Rendering/ColorChannelMask.hpp @@ -0,0 +1,25 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Rendering/ColorChannelMask.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Rendering { + typedef enum ColorChannelMask { + + CCM_RGB_BLUE = 31, // 0x0000001F + CCM_RGB555_GREEN = 992, // 0x000003E0 + CCM_RGB565_GREEN = 2016, // 0x000007E0 + CCM_RGB555_RED = 31744, // 0x00007C00 + CCM_RGB565_RED = 63488 // 0x0000F800 + + } ColorChannelMask; + + static_assert_cpp98_obj(sizeof(ColorChannelMask) == 4, ColorChannelMask); +} // namespace Rendering +} // namespace OpenSHC From b1a528726dc2fd8623f8c0df11c849cb7df6687a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 15:32:51 +0100 Subject: [PATCH 3/4] renderMinimapTileStripWithLuminescence: name the numbers by main's constants Review: the channel masks come from the new ColorChannelMask header enum; the map's 400 rows and its 200-tile size from Map::MapConstants (MC_MAP_XY_LIMIT, MC_MAP_SIZE_200); the screen tile table's start, its two row lengths (200 and 201) and its 80400 entries per orientation from Rendering::Enums::ViewportConstants. The orientation offsets are VC_SCREEN_POINT_TABLE_START + k * VC_SCREEN_POINT_TABLE_SIZE, and 401 is a short and a long row. The two inline assembly blocks take the buffer's row length from a file-local enum, since inline assembly cannot name a qualified constant. The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and normalised with no diff entry. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...renderMinimapTileStripWithLuminescence.cpp | 108 ++++++++++-------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp b/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp index d44bfd3b18..da11415f0f 100644 --- a/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp +++ b/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp @@ -3,7 +3,10 @@ #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Rendering/ColorChannelMask.hpp" #include "OpenSHC/Rendering/ColorMode.hpp" +#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_MiniMapDefinedData.hpp" @@ -16,14 +19,18 @@ namespace UI { using namespace Map::LogicHelpers; - // The channels' bits in an RGB555 and in an RGB565 colour. - enum { - RGB555_RED = 31744, // 0x7c00 - RGB555_GREEN = 992, // 0x03e0 - RGB565_RED = 63488, // 0xf800 - RGB565_GREEN = 2016, // 0x07e0 - RGB_BLUE = 31 // 0x001f - }; + using OpenSHC::Rendering::CCM_RGB555_GREEN; + using OpenSHC::Rendering::CCM_RGB555_RED; + using OpenSHC::Rendering::CCM_RGB565_GREEN; + using OpenSHC::Rendering::CCM_RGB565_RED; + using OpenSHC::Rendering::CCM_RGB_BLUE; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_LONG_ROW; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_SHORT_ROW; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_SIZE; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_START; + + // A row of the second minimap buffer in bytes, for the assembly (it cannot name a qualified constant). + enum { BUFFER_ROW_BYTES = Map::MC_MAP_XY_LIMIT }; // Draws a strip of the screen tile rows into the second minimap buffer: what stands on each tile, in its light. // FUNCTION: STRONGHOLDCRUSADER 0x004B5330 @@ -33,25 +40,25 @@ namespace UI { // These five in this order before the buffer and the strip rows (after them, the stack slots change). int firstRow = 0; BOOLEnum isRGB565 = FALSE; - int rowBase = 8; + int rowBase = VC_SCREEN_POINT_TABLE_START; int scale = 1; int columnDivisor = 2; // The assembly below takes the buffer's address from this local. ushort* const buffer = this->field_0x44; // the strip covers rows stripStart% .. stripStart + stripLength% of the 400 screen tile rows // (int): the original divides signed (stripStart is a uint in the header). - int const firstStripRow = (int)(stripStart * 400) / 100; - int const endStripRow = (int)((stripStart + stripLength) * 400) / 100; + int const firstStripRow = (int)(stripStart * Map::MC_MAP_XY_LIMIT) / 100; + int const endStripRow = (int)((stripStart + stripLength) * Map::MC_MAP_XY_LIMIT) / 100; if (flags & 4) { // zoomed out: half the size scale = 2; } - int const columns = 400 / widthFactor * scale; - int const rowCount = scale * 200; + int const columns = Map::MC_MAP_XY_LIMIT / widthFactor * scale; + int const rowCount = scale * Map::MC_MAP_SIZE_200; if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { isRGB565 = TRUE; } - if (DAT_TileMapState::instance.mapSize <= 200) { + if (DAT_TileMapState::instance.mapSize <= Map::MC_MAP_SIZE_200) { firstRow = 100; columnDivisor = 1; } @@ -59,19 +66,19 @@ namespace UI { // The global again (from the first local, viewportHeight + 1 is added up anew in every row). int const otherParity = DAT_ViewportRenderState::instance.viewportState.viewportHeight + 1; int rowParity = otherParity; - // rowBase first holds the orientation's offset into the screen tile table (in a variable of its own, the row - // base's sum has its operands the other way round). + // rowBase first holds the orientation's offset into the screen tile table, which holds one table per + // orientation (in a variable of its own, the row base's sum has its operands the other way round). if (DAT_TileMapState::instance.mapOrientation != Map::Enums::MO_NORTH) { if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { - rowBase = 80408; + rowBase = VC_SCREEN_POINT_TABLE_START + VC_SCREEN_POINT_TABLE_SIZE; } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH) { - rowBase = 160808; + rowBase = VC_SCREEN_POINT_TABLE_START + 2 * VC_SCREEN_POINT_TABLE_SIZE; } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { - rowBase = 241208; + rowBase = VC_SCREEN_POINT_TABLE_START + 3 * VC_SCREEN_POINT_TABLE_SIZE; } } int const firstColumn = firstRow / 2; - rowBase = firstColumn * 401 + rowBase + 1; + rowBase = firstColumn * (VC_SCREEN_POINT_SHORT_ROW + VC_SCREEN_POINT_LONG_ROW) + rowBase + 1; int rowLength; // rowBase steps in the header, so that the continues below step it too. for (int row = firstRow; row < rowCount - firstRow; ++row, rowBase += rowLength) { @@ -81,11 +88,11 @@ namespace UI { if (rowParity == otherParity) { rowParity = viewportHeight; rowX = widthFactor / 2; - rowLength = 200; + rowLength = VC_SCREEN_POINT_SHORT_ROW; } else { rowParity = otherParity; rowX = 0; - rowLength = 201; + rowLength = VC_SCREEN_POINT_LONG_ROW; } if (row < firstStripRow) { continue; @@ -155,37 +162,37 @@ namespace UI { // Red's and green's masks right after their caps, blue's in the mix. Blue and the mix in // both arms (written once behind them, the registers of the whole block change). if (!isRGB565) { - red = (color & RGB555_RED) * brightness / 100; - if (red > RGB555_RED) { - red = RGB555_RED; + red = (color & CCM_RGB555_RED) * brightness / 100; + if (red > CCM_RGB555_RED) { + red = CCM_RGB555_RED; } - red &= RGB555_RED; - green = (color & RGB555_GREEN) * brightness / 100; - if (green > RGB555_GREEN) { - green = RGB555_GREEN; + red &= CCM_RGB555_RED; + green = (color & CCM_RGB555_GREEN) * brightness / 100; + if (green > CCM_RGB555_GREEN) { + green = CCM_RGB555_GREEN; } - green &= RGB555_GREEN; - blue = (color & RGB_BLUE) * brightness / 100; - if (blue > RGB_BLUE) { - blue = RGB_BLUE; + green &= CCM_RGB555_GREEN; + blue = (color & CCM_RGB_BLUE) * brightness / 100; + if (blue > CCM_RGB_BLUE) { + blue = CCM_RGB_BLUE; } - color = (ushort)(blue & RGB_BLUE | green | red); + color = (ushort)(blue & CCM_RGB_BLUE | green | red); } else { - red = (color & RGB565_RED) * brightness / 100; - if (red > RGB565_RED) { - red = RGB565_RED; + red = (color & CCM_RGB565_RED) * brightness / 100; + if (red > CCM_RGB565_RED) { + red = CCM_RGB565_RED; } - red &= RGB565_RED; - green = (color & RGB565_GREEN) * brightness / 100; - if (green > RGB565_GREEN) { - green = RGB565_GREEN; + red &= CCM_RGB565_RED; + green = (color & CCM_RGB565_GREEN) * brightness / 100; + if (green > CCM_RGB565_GREEN) { + green = CCM_RGB565_GREEN; } - green &= RGB565_GREEN; - blue = (color & RGB_BLUE) * brightness / 100; - if (blue > RGB_BLUE) { - blue = RGB_BLUE; + green &= CCM_RGB565_GREEN; + blue = (color & CCM_RGB_BLUE) * brightness / 100; + if (blue > CCM_RGB_BLUE) { + blue = CCM_RGB_BLUE; } - color = (ushort)(blue & RGB_BLUE | green | red); + color = (ushort)(blue & CCM_RGB_BLUE | green | red); } } // A tile without a colour takes the terrain picture's pixel, once, at the first pixel it draws. @@ -199,7 +206,8 @@ namespace UI { } for (int offsetY = 0; offsetY < heightFactor; ++offsetY) { if (color == 0) { - color = this->minimapPixelBuffer[(y + offsetY) * 400 / 2 + x + offsetX]; + color + = this->minimapPixelBuffer[(y + offsetY) * Map::MC_MAP_XY_LIMIT / 2 + x + offsetX]; } __asm { mov edi, buffer @@ -209,7 +217,7 @@ namespace UI { add edi, eax mov eax, y add eax, offsetY - mov edx, 400 + mov edx, BUFFER_ROW_BYTES mul edx add edi, eax mov ax, color @@ -227,7 +235,7 @@ namespace UI { for (int offsetY = 0; offsetY < heightFactor; ++offsetY) { int const halfY = (y + offsetY) / scale; if (color == 0) { - color = this->minimapPixelBuffer[halfY * 400 / 2 + halfX]; + color = this->minimapPixelBuffer[halfY * Map::MC_MAP_XY_LIMIT / 2 + halfX]; } __asm { mov edi, buffer @@ -235,7 +243,7 @@ namespace UI { add eax, eax add edi, eax mov eax, halfY - mov edx, 400 + mov edx, BUFFER_ROW_BYTES mul edx add edi, eax mov ax, color From 1954ae21adb1e1eb680b0a837431b06d78228a46 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 16:49:12 +0100 Subject: [PATCH 4/4] renderMinimapTileStripWithLuminescence: the small map's margin and the buffer's row from map constants Review: the first row for a map of up to 200 tiles is the margin around it, (MC_MAP_XY_LIMIT - MC_MAP_SIZE_200) / 2, and the assembly's row length is a buffer row of MC_MAP_XY_LIMIT / 2 pixels in bytes (both minimap buffers are 400 rows of 200 ushorts). The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and normalised with no diff entry. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../renderMinimapTileStripWithLuminescence.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp b/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp index da11415f0f..fc925dad76 100644 --- a/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp +++ b/src/OpenSHC/UI/MinimapViewState/renderMinimapTileStripWithLuminescence.cpp @@ -29,8 +29,8 @@ namespace UI { using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_SIZE; using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_START; - // A row of the second minimap buffer in bytes, for the assembly (it cannot name a qualified constant). - enum { BUFFER_ROW_BYTES = Map::MC_MAP_XY_LIMIT }; + // A row of the minimap buffers (200 pixels) in bytes, for the assembly (it cannot name a qualified constant). + enum { BUFFER_ROW_BYTES = Map::MC_MAP_XY_LIMIT / 2 * sizeof(ushort) }; // Draws a strip of the screen tile rows into the second minimap buffer: what stands on each tile, in its light. // FUNCTION: STRONGHOLDCRUSADER 0x004B5330 @@ -59,7 +59,7 @@ namespace UI { isRGB565 = TRUE; } if (DAT_TileMapState::instance.mapSize <= Map::MC_MAP_SIZE_200) { - firstRow = 100; + firstRow = (Map::MC_MAP_XY_LIMIT - Map::MC_MAP_SIZE_200) / 2; columnDivisor = 1; } int const viewportHeight = DAT_ViewportRenderState::instance.viewportState.viewportHeight;