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

137 lines
4.3 KiB
C

#include "../tdkpin_window_messages.h"
#include <assert.h>
#include <string.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_class_name_proc;
static Win16FarPtr g_builder_proc;
static Win16FarPtr g_class_name;
static BOOL16 g_class_exists;
static uint16_t g_register_result;
static unsigned g_builder_calls;
static unsigned g_register_calls;
static unsigned g_load_icon_calls;
static unsigned g_load_cursor_calls;
Win16FarPtr win16_call_object_far_method(
Win16FarPtr procedure, Win16FarPtr object)
{
(void)object;
assert(procedure == g_class_name_proc);
return g_class_name;
}
void win16_call_object_wndclass_method(
Win16FarPtr procedure, Win16FarPtr object, WNDCLASS16 *window_class)
{
(void)object;
assert(procedure == g_builder_proc);
memset(window_class, 0, sizeof(*window_class));
window_class->style = 3;
window_class->class_name = g_class_name;
g_builder_calls++;
}
BOOL16 GetClassInfo16(
HINSTANCE16 instance,
Win16FarPtr class_name,
WNDCLASS16 *window_class)
{
assert(instance == g_win16_instance && class_name == g_class_name);
(void)window_class;
return g_class_exists;
}
uint16_t RegisterClass16(const WNDCLASS16 *window_class)
{
assert(window_class->style == 3);
assert(window_class->class_name == g_class_name);
g_register_calls++;
return g_register_result;
}
HICON16 LoadIcon16(HINSTANCE16 instance, Win16FarPtr resource)
{
assert(instance == 0 && resource == win16_make_far_pointer(0, 0x7f00));
g_load_icon_calls++;
return 0x1111;
}
HCURSOR16 LoadCursor16(HINSTANCE16 instance, Win16FarPtr resource)
{
assert(instance == 0 && resource == win16_make_far_pointer(0, 0x7f00));
g_load_cursor_calls++;
return 0x2222;
}
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));
}
int main(void)
{
static uint8_t dgroup[0x1000];
static uint8_t window_bytes[64];
static uint8_t code[0x200];
win16_reset_segment_bindings();
win16_bind_segment(0x5000, dgroup, sizeof(dgroup), true);
win16_set_dgroup_selector(0x5000);
win16_bind_segment(0x7000, window_bytes, sizeof(window_bytes), true);
win16_bind_ne_segment(4, 0x6000, code, sizeof(code), false);
Win16FarPtr window = win16_make_far_pointer(0x7000, 2);
uint16_t vmt = 0x0100;
win16_write_u16(window, 0, vmt);
g_class_name_proc = win16_make_far_pointer(0x6000, 0x1000);
g_builder_proc = win16_make_far_pointer(0x6000, 0x2000);
g_class_name = win16_make_far_pointer(0x5000, 0x068c);
g_win16_instance = 0x1234;
write_far(vmt + 0x2c, g_class_name_proc);
write_far(vmt + 0x34, g_builder_proc);
g_class_exists = 1;
g_builder_calls = 0;
g_register_calls = 0;
assert(object_windows_register_class(window));
assert(g_builder_calls == 0 && g_register_calls == 0);
g_class_exists = 0;
g_register_result = 7;
assert(object_windows_register_class(window));
assert(g_builder_calls == 1 && g_register_calls == 1);
g_register_result = 0;
assert(!object_windows_register_class(window));
assert(g_builder_calls == 2 && g_register_calls == 2);
WNDCLASS16 descriptor;
g_load_icon_calls = 0;
g_load_cursor_calls = 0;
object_windows_build_window_class(window, &descriptor);
assert(descriptor.style == 3);
assert(descriptor.window_proc == win16_make_far_pointer(0x6000, 0x018b));
assert(descriptor.class_extra_bytes == 0 && descriptor.window_extra_bytes == 0);
assert(descriptor.instance == g_win16_instance);
assert(descriptor.icon == 0x1111 && descriptor.cursor == 0x2222);
assert(descriptor.background_brush == 6);
assert(descriptor.menu_name == 0 && descriptor.class_name == g_class_name);
assert(g_load_icon_calls == 1 && g_load_cursor_calls == 1);
return 0;
}