Files
tdkpin/original/reconstructed/tests/test_palette_window_messages.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

142 lines
3.9 KiB
C

#include "../tdkpin_game_assets.h"
#include <assert.h>
#include <string.h>
static uint8_t g_dgroup[0x5000];
static uint8_t g_objects[0x100];
static Win16FarPtr g_window;
static Win16FarPtr g_message;
static HWND16 g_parent_result;
static int16_t g_realize_result;
static unsigned g_step;
static unsigned g_invalidate_calls;
HWND16 GetParent16(HWND16 window)
{
assert(++g_step == 1 && window == 0x3333);
return g_parent_result;
}
HDC16 GetDC16(HWND16 window)
{
assert(window == 0x2222);
g_step++;
return 0x4444;
}
HPALETTE16 SelectPalette16(
HDC16 dc, HPALETTE16 palette, BOOL16 force_background)
{
assert(dc == 0x4444);
g_step++;
if (palette == 0x5555) {
assert(force_background == 0 || force_background == 1);
return 0x6666;
}
assert(palette == 0x6666 && force_background == 0);
return 0x5555;
}
UINT16 RealizePalette16(HDC16 dc)
{
assert(dc == 0x4444);
g_step++;
return (uint16_t)g_realize_result;
}
BOOL16 UpdateColors16(HDC16 dc)
{
assert(dc == 0x4444);
g_step++;
return 1;
}
INT16 ReleaseDC16(HWND16 window, HDC16 dc)
{
assert(window == 0x2222 && dc == 0x4444);
g_step++;
return 1;
}
BOOL16 InvalidateRect16(
HWND16 window, Win16FarPtr rectangle, BOOL16 erase)
{
assert(window == 0x2222 && rectangle == 0 && erase == 0);
g_invalidate_calls++;
return 1;
}
static void reset_message(HWND16 changed_window)
{
memset(g_objects, 0, sizeof(g_objects));
win16_write_u16(g_window, 4, 0x2222);
win16_write_u16(g_message, 4, changed_window);
win16_write_u32(g_message, 10, 0x12345678);
g_step = 0;
g_invalidate_calls = 0;
g_parent_result = 0;
g_realize_result = 0;
}
int main(void)
{
win16_reset_segment_bindings();
win16_bind_segment(0x5000, g_dgroup, sizeof(g_dgroup), true);
win16_bind_segment(0x6000, g_objects, sizeof(g_objects), true);
win16_set_dgroup_selector(0x5000);
g_window = win16_make_far_pointer(0x6000, 0);
g_message = win16_make_far_pointer(0x6000, 0x40);
win16_write_u16(win16_make_far_pointer(0x5000, 0x444e), 0, 0x5555);
reset_message(0x2222);
assert(tdkpin_wm_palette_changed(g_window, g_message) == 1);
assert(g_step == 0);
reset_message(0x3333);
g_parent_result = 0x2222;
assert(tdkpin_wm_palette_changed(g_window, g_message) == 1);
assert(g_step == 1);
reset_message(0x3333);
assert(tdkpin_wm_palette_changed(g_window, g_message) == 0);
assert(g_step == 7);
assert(win16_read_u32(win16_far_add_offset(g_message, 10)) == 0);
reset_message(0);
g_realize_result = 0;
assert(tdkpin_wm_query_new_palette(g_window, g_message) == 0);
assert(g_step == 5 && g_invalidate_calls == 0);
assert(win16_read_u32(win16_far_add_offset(g_message, 10)) == 0);
reset_message(0);
g_realize_result = 3;
assert(tdkpin_wm_query_new_palette(g_window, g_message) == 3);
assert(g_step == 5 && g_invalidate_calls == 1);
assert(win16_read_u32(win16_far_add_offset(g_message, 10)) == 3);
uint16_t (*changed_variants[])(Win16FarPtr, Win16FarPtr) = {
tdkpin_wm_palette_changed_variant_b,
tdkpin_wm_palette_changed_variant_c,
};
for (unsigned index = 0; index < 2; index++) {
reset_message(0x3333);
assert(changed_variants[index](g_window, g_message) == 0);
assert(g_step == 7);
assert(win16_read_u32(win16_far_add_offset(g_message, 10)) == 0);
}
int16_t (*query_variants[])(Win16FarPtr, Win16FarPtr) = {
tdkpin_wm_query_new_palette_variant_b,
tdkpin_wm_query_new_palette_variant_c,
};
for (unsigned index = 0; index < 2; index++) {
reset_message(0);
g_realize_result = 2;
assert(query_variants[index](g_window, g_message) == 2);
assert(g_step == 5 && g_invalidate_calls == 1);
assert(win16_read_u32(win16_far_add_offset(g_message, 10)) == 2);
}
return 0;
}