Files
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

182 lines
5.1 KiB
C

#include "../tdkpin_game_windows.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
enum {
WINDOW_HANDLE = 4,
WINDOW_ATTRIBUTES = 0x21,
WINDOW_X = 0x29,
WINDOW_Y = 0x2b,
WINDOW_WIDTH = 0x2d,
WINDOW_HEIGHT = 0x2f,
WINDOW_OWNER = 0x41,
};
static uint8_t g_objects[0x1000];
static bool g_enter;
static uint32_t g_base_style;
static INT16 g_screen_width;
static INT16 g_screen_height;
static unsigned g_base_calls;
static Win16FarPtr g_expected_title;
static Win16FarPtr g_expected_parent;
static unsigned g_focus_calls;
static HWND16 g_focused_window;
static Win16FarPtr object_at(uint16_t offset)
{
return win16_make_far_pointer(0x6000, offset);
}
static void reset_fixture(void)
{
memset(g_objects, 0, sizeof(g_objects));
win16_reset_segment_bindings();
win16_bind_segment(0x6000, g_objects, sizeof(g_objects), true);
g_enter = true;
g_base_style = 0;
g_screen_width = 1024;
g_screen_height = 768;
g_base_calls = 0;
g_expected_title = object_at(0x700);
g_expected_parent = object_at(0x800);
g_focus_calls = 0;
g_focused_window = 0;
}
bool borland_enter_object_constructor(
BorlandObjectCallFrame *frame, uint16_t offset)
{
assert(offset == 0);
if (g_enter && frame->vmt_argument != 0) {
win16_write_u16(frame->object, 0, frame->vmt_argument);
}
return g_enter;
}
Win16FarPtr object_windows_window_construct(
Win16FarPtr window,
uint16_t vmt,
Win16FarPtr title,
Win16FarPtr parent)
{
assert(vmt == 0);
assert(title == g_expected_title);
assert(parent == g_expected_parent);
g_base_calls++;
win16_write_u32(window, WINDOW_ATTRIBUTES, g_base_style);
win16_write_u16(window, WINDOW_HANDLE, 0x4444);
return window;
}
INT16 GetSystemMetrics16(INT16 index)
{
assert(index == 0 || index == 1);
return index == 0 ? g_screen_width : g_screen_height;
}
HWND16 SetFocus16(HWND16 window)
{
g_focus_calls++;
g_focused_window = window;
return 0x9999;
}
static void assert_geometry(
Win16FarPtr window,
INT16 x,
INT16 y,
uint16_t width,
uint16_t height)
{
assert((INT16)win16_read_u16(
win16_far_add_offset(window, WINDOW_X)) == x);
assert((INT16)win16_read_u16(
win16_far_add_offset(window, WINDOW_Y)) == y);
assert(win16_read_u16(
win16_far_add_offset(window, WINDOW_WIDTH)) == width);
assert(win16_read_u16(
win16_far_add_offset(window, WINDOW_HEIGHT)) == height);
}
static void test_main_window(void)
{
reset_fixture();
Win16FarPtr window = object_at(0x100);
assert(tdkpin_main_window_construct(
window, 0x1234, g_expected_title, g_expected_parent) == window);
assert(g_base_calls == 1);
assert(win16_read_u16(window) == 0x1234);
assert_geometry(window, 192, 144, 640, 480);
assert(win16_read_u32(
win16_far_add_offset(window, WINDOW_ATTRIBUTES)) ==
0x86ca0000u);
assert(g_focus_calls == 0);
reset_fixture();
window = object_at(0x100);
g_screen_width = 801;
g_screen_height = 601;
(void)tdkpin_main_window_construct(
window, 0, g_expected_title, g_expected_parent);
assert_geometry(window, 80, 60, 640, 480);
}
static void test_centered_child_window(void)
{
reset_fixture();
Win16FarPtr window = object_at(0x200);
g_base_style = 0x00010000u;
assert(tdkpin_centered_child_window_construct(
window, 0x2345, g_expected_title, g_expected_parent) == window);
assert(g_base_calls == 1);
assert(win16_read_far_pointer(window, WINDOW_OWNER) == g_expected_parent);
assert_geometry(window, 140, 80, 360, 300);
assert(win16_read_u32(
win16_far_add_offset(window, WINDOW_ATTRIBUTES)) ==
0x46810002u);
assert(g_focus_calls == 1 && g_focused_window == 0x4444);
}
static void test_full_child_window(void)
{
reset_fixture();
Win16FarPtr window = object_at(0x300);
g_base_style = 0xffffffffu;
assert(tdkpin_full_child_window_construct(
window, 0x3456, g_expected_title, g_expected_parent) == window);
assert(g_base_calls == 1);
assert(win16_read_far_pointer(window, WINDOW_OWNER) == g_expected_parent);
assert_geometry(window, 0, 0, 640, 460);
assert(win16_read_u32(
win16_far_add_offset(window, WINDOW_ATTRIBUTES)) ==
0x46000002u);
assert(g_focus_calls == 1 && g_focused_window == 0x4444);
}
static void test_constructor_entry_failure(void)
{
reset_fixture();
Win16FarPtr window = object_at(0x400);
win16_write_u32(window, WINDOW_ATTRIBUTES, 0x11223344u);
g_enter = false;
assert(tdkpin_centered_child_window_construct(
window, 0x4567, g_expected_title, g_expected_parent) == window);
assert(g_base_calls == 0 && g_focus_calls == 0);
assert(win16_read_u32(
win16_far_add_offset(window, WINDOW_ATTRIBUTES)) ==
0x11223344u);
}
int main(void)
{
test_main_window();
test_centered_child_window();
test_full_child_window();
test_constructor_entry_failure();
return 0;
}