Files
tdkpin/original/reconstructed/tests/test_palette_gdi.c
T
ddidderr 8b99e9607c feat(reconstruction): complete binary-backed C recovery
Replace the partial mechanics transcriptions with a separate, readable C11
reconstruction of the complete Win16 image while preserving the original raw
Ghidra export as immutable evidence. Cover all ordinary and overlapping entry
points, Borland runtime behavior, Win16 imports, segmented data, callbacks,
resources, indirect control flow, physics, rendering, persistence, and
startup/shutdown lifecycles.

Add deterministic extraction and audit tooling plus address-linked ledgers for
functions, imports, DGROUP ranges and objects, relocations, resources, and
callbacks. The final gate records zero raw, partial, restored, unknown,
blocked, or unclassified required units. Keep the semantic-fidelity boundary
explicit: the portable C is not claimed to reproduce a byte-identical Borland
NE build.

Add strict focused harnesses for every reconstructed C unit, exact resource
round-trip checks, and a 16-bit Borland Real48 reference probe. No Rust source
or Cargo metadata is changed in this phase.

Test Plan:
- `bash original/tools/test_reconstructed_c.sh` -- passed
- `bash original/tools/probe_real48_reference.sh` -- passed bit-for-bit
- `python3 original/tools/audit_reconstruction.py --require-complete` -- passed
- `git diff --cached --check` -- passed
- `git diff HEAD -- '*.rs' Cargo.toml Cargo.lock` -- empty
2026-08-23 16:41:17 +02:00

96 lines
2.5 KiB
C

#include "../tdkpin_palette.h"
#include <assert.h>
#include <stdbool.h>
#include <string.h>
static uint8_t g_palette_bytes[sizeof(LOGPALETTE256)];
static bool g_fail_allocation;
static unsigned g_step;
static unsigned g_get_mem_calls;
static unsigned g_free_mem_calls;
Win16FarPtr borland_get_mem(uint16_t bytes)
{
assert(bytes == sizeof(LOGPALETTE256));
g_get_mem_calls++;
return g_fail_allocation ? 0 : win16_make_far_pointer(0x6000, 0);
}
void borland_free_mem(Win16FarPtr block, uint16_t bytes)
{
assert(++g_step == 8);
assert(block == win16_make_far_pointer(0x6000, 0));
assert(bytes == sizeof(LOGPALETTE256));
g_free_mem_calls++;
}
HDC16 GetDC16(HWND16 window)
{
assert(++g_step == 1 && window == 0x1234);
return 0x2222;
}
HPALETTE16 CreatePalette16(Win16FarPtr logical_palette)
{
assert(++g_step == 2);
assert(win16_read_u16(logical_palette) == 0x0300);
assert(win16_read_u16(win16_far_add_offset(logical_palette, 2)) == 256);
for (uint16_t index = 0; index < 256; index++) {
Win16FarPtr entry = win16_far_add_offset(
logical_palette, (uint16_t)(4 + index * 4));
assert(win16_read_u8(entry) == 0);
assert(win16_read_u8(win16_far_add_offset(entry, 1)) == 0);
assert(win16_read_u8(win16_far_add_offset(entry, 2)) == 0);
assert(win16_read_u8(win16_far_add_offset(entry, 3)) == 4);
}
return 0x3333;
}
HPALETTE16 SelectPalette16(
HDC16 dc, HPALETTE16 palette, BOOL16 force_background)
{
assert(dc == 0x2222);
if (++g_step == 3) {
assert(palette == 0x3333 && force_background == 0);
return 0x4444;
}
assert(g_step == 5);
assert(palette == 0x4444 && force_background == 1);
return 0x3333;
}
UINT16 RealizePalette16(HDC16 dc)
{
assert(++g_step == 4 && dc == 0x2222);
return 256;
}
BOOL16 DeleteObject16(HGDIOBJ16 object)
{
assert(++g_step == 6 && object == 0x3333);
return 1;
}
INT16 ReleaseDC16(HWND16 window, HDC16 dc)
{
assert(++g_step == 7 && window == 0x1234 && dc == 0x2222);
return 1;
}
int main(void)
{
win16_reset_segment_bindings();
win16_bind_segment(
0x6000, g_palette_bytes, sizeof(g_palette_bytes), true);
g_fail_allocation = true;
tdkpin_realize_nocollapse_palette(0x1234);
assert(g_get_mem_calls == 1 && g_step == 0 && g_free_mem_calls == 0);
g_fail_allocation = false;
memset(g_palette_bytes, 0xff, sizeof(g_palette_bytes));
tdkpin_realize_nocollapse_palette(0x1234);
assert(g_get_mem_calls == 2 && g_step == 8 && g_free_mem_calls == 1);
return 0;
}