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

115 lines
3.4 KiB
C

#include "../tdkpin_system_timer.h"
#include <assert.h>
static BorlandAllocationAttempt g_allocation;
static Win16FarPtr g_freed_object;
static uint16_t g_freed_size;
static uint16_t g_make_result;
static HWND16 g_make_recipient;
static uint16_t g_make_delay;
static uint16_t g_make_resolution;
static uint16_t g_make_one_shot;
static uint16_t g_killed_timer;
BorlandAllocationAttempt borland_try_get_mem(uint16_t bytes)
{
assert(bytes == 6);
return g_allocation;
}
bool borland_try_free_mem(Win16FarPtr object, uint16_t bytes)
{
g_freed_object = object;
g_freed_size = bytes;
return false;
}
_Noreturn void borland_runtime_error(uint16_t code)
{
(void)code;
assert(false);
__builtin_unreachable();
}
uint16_t SystemTimerMake16(
HWND16 recipient,
uint16_t delay_ms,
uint16_t resolution_ms,
uint16_t one_shot)
{
g_make_recipient = recipient;
g_make_delay = delay_ms;
g_make_resolution = resolution_ms;
g_make_one_shot = one_shot;
return g_make_result;
}
uint16_t TimeKillEvent16(uint16_t timer_id)
{
g_killed_timer = timer_id;
return 0;
}
int main(void)
{
static uint8_t dgroup[0x1000];
static uint8_t stack[0x10000];
static uint8_t caller_object[32];
static uint8_t allocated_object[32];
win16_reset_segment_bindings();
win16_bind_segment(0x5000, dgroup, sizeof(dgroup), true);
win16_set_dgroup_selector(0x5000);
win16_bind_segment(0x6000, stack, sizeof(stack), true);
win16_set_stack_state(0x6000, 0x8000);
win16_write_stack_u16(0x000a, 0x1000);
win16_write_stack_u16(0x000e, 0x7fff);
win16_bind_segment(
0x7000, caller_object, sizeof(caller_object), true);
win16_bind_segment(
0x7100, allocated_object, sizeof(allocated_object), true);
win16_write_u16(win16_make_far_pointer(0x5000, 0x0200), 0, 6);
Win16FarPtr caller = win16_make_far_pointer(0x7000, 4);
g_make_result = 0x4321;
Win16FarPtr result = tdkpin_system_timer_construct(
caller, 0x0200, 1, 7, 250, 0x1234);
assert(result == caller);
assert(win16_read_u16(caller) == 0x0200);
assert(win16_read_u16(win16_far_add_offset(caller, 2)) == 0x4321);
assert(win16_read_u16(win16_far_add_offset(caller, 4)) == 0x1234);
assert(g_make_recipient == 0x1234);
assert(g_make_delay == 250 && g_make_resolution == 7);
assert(g_make_one_shot == 0x7b01);
g_killed_timer = 0;
tdkpin_system_timer_stop(caller);
assert(g_killed_timer == 0x4321);
assert(win16_read_u16(win16_far_add_offset(caller, 2)) == 0);
tdkpin_system_timer_stop(caller);
assert(g_killed_timer == 0x4321);
Win16FarPtr allocated = win16_make_far_pointer(0x7100, 8);
g_allocation = (BorlandAllocationAttempt){allocated, false};
g_make_result = 0;
g_freed_object = 0;
result = tdkpin_system_timer_construct(
0, 0x0200, 0, 1, 20, 0x2222);
assert(result == 0);
assert(g_freed_object == allocated && g_freed_size == 6);
g_make_result = 0;
g_freed_object = 0;
result = tdkpin_system_timer_construct(
caller, 0x0200, 0, 1, 20, 0x3333);
assert(result == caller && g_freed_object == 0);
win16_write_u16(caller, 0, 0x0200);
win16_write_u16(caller, 2, 0x1111);
g_freed_object = 0;
tdkpin_system_timer_destruct(caller, 1);
assert(g_killed_timer == 0x1111);
assert(g_freed_object == caller && g_freed_size == 6);
return 0;
}