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

114 lines
2.9 KiB
C

#include "../tdkpin_runtime_ui.h"
#include <assert.h>
uint16_t g_tpwincrt_columns;
uint16_t g_tpwincrt_rows;
uint8_t g_tpwincrt_window_created;
Win16FarPtr g_tpwincrt_screen_buffer;
uint8_t g_tpwincrt_break_check_enabled;
HWND16 g_tpwincrt_window;
uint16_t g_tpwincrt_cursor_column;
uint16_t g_tpwincrt_cursor_row;
uint16_t g_tpwincrt_view_column;
uint16_t g_tpwincrt_view_row;
static uint16_t g_allocated_bytes;
static Win16FarPtr g_allocation;
static Win16FarPtr g_filled_block;
static uint16_t g_filled_bytes;
static uint8_t g_fill_value;
static unsigned g_menu_calls;
static HMENU16 g_enabled_menu;
static Win16FarPtr g_freed_block;
static uint16_t g_freed_bytes;
static INT16 g_quit_code;
Win16FarPtr borland_get_mem(uint16_t bytes)
{
g_allocated_bytes = bytes;
return g_allocation;
}
void borland_fill_bytes(
Win16FarPtr destination, uint16_t count, uint8_t value)
{
g_filled_block = destination;
g_filled_bytes = count;
g_fill_value = value;
}
HMENU16 GetSystemMenu16(HWND16 window, BOOL16 revert)
{
assert(window == g_tpwincrt_window && revert == 0);
g_menu_calls++;
return 0x1234;
}
BOOL16 EnableMenuItem16(HMENU16 menu, UINT16 item, UINT16 flags)
{
assert(item == 0xf060 && flags == 3);
g_enabled_menu = menu;
return 1;
}
void borland_free_mem(Win16FarPtr block, uint16_t bytes)
{
g_freed_block = block;
g_freed_bytes = bytes;
}
void PostQuitMessage16(INT16 exit_code)
{
g_quit_code = exit_code;
}
static void reset_create(void)
{
g_tpwincrt_window_created = 0;
g_tpwincrt_screen_buffer = 0;
g_allocated_bytes = 0;
g_filled_block = 0;
g_filled_bytes = 0;
g_fill_value = 0;
g_menu_calls = 0;
g_enabled_menu = 0;
}
int main(void)
{
g_tpwincrt_columns = 400;
g_tpwincrt_rows = 200;
uint16_t wrapped_bytes = (uint16_t)(400u * 200u);
g_allocation = win16_make_far_pointer(0x7000, 0x0100);
g_tpwincrt_window = 0x77;
reset_create();
g_tpwincrt_break_check_enabled = 1;
tpwincrt_on_create();
assert(g_tpwincrt_window_created == 1);
assert(g_allocated_bytes == wrapped_bytes);
assert(g_tpwincrt_screen_buffer == g_allocation);
assert(g_filled_block == g_allocation && g_filled_bytes == wrapped_bytes);
assert(g_fill_value == ' ' && g_menu_calls == 0);
reset_create();
g_tpwincrt_break_check_enabled = 0;
tpwincrt_on_create();
assert(g_menu_calls == 1 && g_enabled_menu == 0x1234);
g_tpwincrt_cursor_column = 4;
g_tpwincrt_cursor_row = 5;
g_tpwincrt_view_column = 6;
g_tpwincrt_view_row = 7;
g_tpwincrt_window_created = 1;
g_freed_block = 0;
g_quit_code = -1;
tpwincrt_on_destroy();
assert(g_freed_block == g_allocation && g_freed_bytes == wrapped_bytes);
assert(g_tpwincrt_cursor_column == 0 && g_tpwincrt_cursor_row == 0);
assert(g_tpwincrt_view_column == 0 && g_tpwincrt_view_row == 0);
assert(g_quit_code == 0 && g_tpwincrt_window_created == 0);
return 0;
}