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

133 lines
4.1 KiB
C

#include "../tdkpin_window_messages.h"
#include "../tdkpin_object_list.h"
#include <assert.h>
Win16FarPtr g_object_windows_application;
HINSTANCE16 g_win16_previous_instance;
HINSTANCE16 g_win16_instance;
uint16_t g_win16_show_command;
Win16FarPtr g_win16_message_box;
Win16FarPtr g_object_windows_dispatch_proc;
uint16_t g_object_windows_thunk_code_selector;
Win16FarPtr g_object_windows_free_thunk;
Win16FarPtr g_object_windows_message_hook;
Win16FarPtr g_object_windows_creating_object;
static Win16FarPtr g_client_result;
static Win16FarPtr g_client_getter;
static unsigned g_getter_calls;
static HWND16 g_destroyed_window;
static HWND16 g_sent_window;
static UINT16 g_sent_message;
static WPARAM16 g_sent_wparam;
static LPARAM16 g_sent_lparam;
void win16_call_object_action(
Win16FarPtr procedure, Win16FarPtr child)
{
assert(procedure == win16_make_far_pointer(0x6000, 0x0cc7));
object_windows_set_flag_4_if_windowed(0xffff, child);
}
Win16FarPtr win16_call_object_far_method(
Win16FarPtr procedure, Win16FarPtr object)
{
(void)object;
assert(procedure == g_client_getter);
g_getter_calls++;
return g_client_result;
}
BOOL16 DestroyWindow16(HWND16 window)
{
g_destroyed_window = window;
return 1;
}
LRESULT16 SendMessage16(
HWND16 window, UINT16 message, WPARAM16 wparam, LPARAM16 lparam)
{
g_sent_window = window;
g_sent_message = message;
g_sent_wparam = wparam;
g_sent_lparam = lparam;
return 0;
}
static void write_far(uint16_t offset, Win16FarPtr pointer)
{
win16_write_u16(
win16_dgroup_pointer(offset), 0, win16_far_offset(pointer));
win16_write_u16(
win16_dgroup_pointer((uint16_t)(offset + 2)),
0,
win16_far_selector(pointer));
}
static void reset_calls(void)
{
g_getter_calls = 0;
g_destroyed_window = 0;
g_sent_window = 0;
g_sent_message = 0;
g_sent_wparam = 0;
g_sent_lparam = 0;
}
int main(void)
{
static uint8_t dgroup[0x1000];
static uint8_t code[0x1000];
static uint8_t window_bytes[64];
static uint8_t child_bytes[64];
static uint8_t parent_bytes[64];
static uint8_t client_bytes[64];
win16_reset_segment_bindings();
win16_bind_segment(0x5000, dgroup, sizeof(dgroup), true);
win16_set_dgroup_selector(0x5000);
win16_bind_ne_segment(4, 0x6000, code, sizeof(code), false);
win16_bind_segment(0x7000, window_bytes, sizeof(window_bytes), true);
win16_bind_segment(0x7100, child_bytes, sizeof(child_bytes), true);
win16_bind_segment(0x7200, parent_bytes, sizeof(parent_bytes), true);
win16_bind_segment(0x7300, client_bytes, sizeof(client_bytes), true);
Win16FarPtr window = win16_make_far_pointer(0x7000, 2);
Win16FarPtr child = win16_make_far_pointer(0x7100, 2);
Win16FarPtr parent = win16_make_far_pointer(0x7200, 2);
Win16FarPtr client = win16_make_far_pointer(0x7300, 2);
win16_write_u16(window, 4, 0x77);
win16_write_u16(child, 4, 0x88);
win16_write_u16(client, 4, 0x99);
win16_write_u16(window, 6, win16_far_offset(parent));
win16_write_u16(window, 8, win16_far_selector(parent));
object_windows_append_child(window, child);
win16_write_u16(parent, 0, 0x0100);
g_client_getter = win16_make_far_pointer(0x6100, 0x0200);
write_far(0x0130, g_client_getter);
reset_calls();
object_windows_destroy_native_window(window);
assert(g_destroyed_window == 0x77);
assert(object_windows_has_flags(child, 4));
object_windows_update_flags(window, true, 8);
reset_calls();
g_client_result = 0;
object_windows_destroy_native_window(window);
assert(g_getter_calls == 1 && g_destroyed_window == 0x77);
reset_calls();
g_client_result = client;
object_windows_destroy_native_window(window);
assert(g_getter_calls == 2 && g_destroyed_window == 0);
assert(g_sent_window == 0x99 && g_sent_message == 0x221);
assert(g_sent_wparam == 0x77 && g_sent_lparam == 0);
win16_write_u16(window, 4, 0);
reset_calls();
object_windows_destroy_native_window(window);
assert(g_getter_calls == 0 && g_destroyed_window == 0);
return 0;
}