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

129 lines
3.5 KiB
C

#include "../tdkpin_game_assets.h"
#include "../tdkpin_borland_objects.h"
#include <assert.h>
static uint8_t g_dgroup[0x5000];
static uint8_t g_window_bytes[0x0c00];
static Win16FarPtr g_window;
static Win16FarPtr g_owned;
static HGDIOBJ16 g_deleted[32];
static unsigned g_delete_count;
static unsigned g_step;
static Win16FarPtr dgroup_at(uint16_t offset)
{
return win16_make_far_pointer(0x5000, offset);
}
HCURSOR16 LoadCursor16(HINSTANCE16 instance, Win16FarPtr resource)
{
assert(++g_step == 1 && instance == 0);
assert(resource == win16_make_far_pointer(0, 0x7f02));
return 0x1111;
}
HCURSOR16 SetCursor16(HCURSOR16 cursor)
{
if (++g_step == 2) {
assert(cursor == 0x1111);
return 0x2222;
}
assert(cursor == 0x2222);
return 0;
}
void tdkpin_unload_sounds(void)
{
assert(++g_step == 3);
}
void borland_dispose_object(Win16FarPtr object)
{
assert(++g_step == 4 && object == g_owned);
}
void tdkpin_drain_messages_except_input(void)
{
assert(++g_step == 5);
}
BOOL16 DeleteObject16(HGDIOBJ16 object)
{
assert(object != 0 && g_delete_count < 32);
g_deleted[g_delete_count++] = object;
return 1;
}
void PostQuitMessage16(INT16 exit_code)
{
assert(exit_code == 0x12);
}
void object_windows_window_destruct(
Win16FarPtr window, uint16_t vmt)
{
assert(window == g_window && vmt == 0);
}
BOOL16 InvalidateRect16(
HWND16 window, Win16FarPtr rectangle, BOOL16 erase)
{
assert(window == 0x3333 && rectangle == 0 && erase == 1);
return 1;
}
void borland_finish_object_destructor(
BorlandObjectCallFrame *frame, uint16_t vmt_field_offset)
{
assert(frame->object == g_window && frame->vmt_argument == 0x9999);
assert(vmt_field_offset == 0);
}
int main(void)
{
win16_reset_segment_bindings();
win16_bind_segment(0x5000, g_dgroup, sizeof(g_dgroup), true);
win16_bind_segment(0x6000, g_window_bytes, sizeof(g_window_bytes), true);
win16_set_dgroup_selector(0x5000);
g_window = win16_make_far_pointer(0x6000, 0);
g_owned = win16_make_far_pointer(0x6000, 0x0800);
win16_write_u16(g_window, 4, 0x3333);
win16_write_u16(g_window, 0x52, 1);
win16_write_u32(g_window, 0x49, g_owned);
static const uint16_t global_offsets[] = {
0x0859, 0x0863, 0x0865, 0x085f, 0x085b, 0x0861, 0x085d,
};
for (uint16_t index = 0; index < 7; index++) {
win16_write_u16(dgroup_at(global_offsets[index]), 0, (uint16_t)(index + 2));
}
for (uint16_t index = 0; index < 8; index++) {
win16_write_u16(dgroup_at(0x430b), (uint16_t)(index * 2), (uint16_t)(10 + index));
}
for (uint16_t index = 1; index <= 4; index++) {
win16_write_u16(dgroup_at(0x4319), (uint16_t)(index * 2), (uint16_t)(19 + index));
}
for (uint16_t index = 1; index <= 9; index++) {
win16_write_u16(dgroup_at(0x4321), (uint16_t)(index * 2), (uint16_t)(29 + index));
}
tdkpin_asset_window_destruct(g_window, 0x9999);
assert(g_delete_count == 29);
for (uint16_t index = 0; index < 8; index++) {
assert(g_deleted[index] == index + 1);
}
for (uint16_t index = 0; index < 8; index++) {
assert(g_deleted[8 + index] == 10 + index);
}
for (uint16_t index = 0; index < 4; index++) {
assert(g_deleted[16 + index] == 20 + index);
}
for (uint16_t index = 0; index < 9; index++) {
assert(g_deleted[20 + index] == 30 + index);
}
assert(win16_read_u8(win16_far_add_offset(g_window, 0x0bd8)) == 1);
assert(win16_read_u8(win16_far_add_offset(g_window, 0x0bd9)) == 1);
return 0;
}