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

120 lines
3.1 KiB
C

#include "../tdkpin_render.h"
#include <assert.h>
static uint8_t g_dgroup[0x1000];
static unsigned g_step;
static unsigned g_mode;
HDC16 CreateCompatibleDC16(HDC16 dc)
{
assert(dc == 0x1111);
g_step++;
return (HDC16)(0x2000 + g_step);
}
HGDIOBJ16 SelectObject16(HDC16 dc, HGDIOBJ16 object)
{
g_step++;
if (g_mode == 4) {
if (g_step == 2) {
assert(dc == 0x2001 && object == 0x3000);
return 0x4000;
}
assert(g_step == 4 && dc == 0x2001 && object == 0x4000);
return 0x3000;
}
if (g_step == 3) {
assert(dc == 0x2001 && object == 0x3000);
return 0x4000;
}
if (g_step == 4) {
HGDIOBJ16 expected = g_mode == 1 ? 0x3333 : (g_mode == 2 ? 0x3002 : 0x3001);
assert(dc == 0x2002 && object == expected);
return 0x4001;
}
if (g_step == 6) {
assert(dc == 0x2002 && object == 0x4001);
return 0;
}
assert(g_step == 7 && dc == 0x2001 && object == 0x4000);
return 0;
}
BOOL16 BitBlt16(
HDC16 destination,
INT16 destination_x,
INT16 destination_y,
INT16 width,
INT16 height,
HDC16 source,
INT16 source_x,
INT16 source_y,
uint32_t raster_operation)
{
g_step++;
assert(raster_operation == 0x00cc0020);
assert(width == 30 && height == 40);
if (g_mode == 4) {
assert(g_step == 3 && destination == 0x1111 && source == 0x2001);
assert(destination_x == 10 && destination_y == 20);
assert(source_x == 10 && source_y == 20);
} else {
assert(g_step == 5 && destination == 0x2001 && source == 0x2002);
assert(destination_x == 10 && destination_y == 20);
if (g_mode == 1) {
assert(source_x == 0 && source_y == 0);
} else {
assert(source_x == 10 && source_y == 20);
}
}
return 1;
}
BOOL16 DeleteDC16(HDC16 dc)
{
g_step++;
if (g_mode == 4) {
assert(g_step == 5 && dc == 0x2001);
} else if (g_step == 8) {
assert(dc == 0x2002);
} else {
assert(g_step == 9 && dc == 0x2001);
}
return 1;
}
static void run_mode(unsigned mode)
{
g_mode = mode;
g_step = 0;
if (mode == 1) {
tdkpin_blit_bitmap_to_background(0x3333, 40, 30, 20, 10, 0x1111);
assert(g_step == 9);
} else if (mode == 2) {
tdkpin_restore_background_region_a(40, 30, 20, 10, 0x1111);
assert(g_step == 9);
} else if (mode == 3) {
tdkpin_restore_background_region_b(40, 30, 20, 10, 0x1111);
assert(g_step == 9);
} else {
tdkpin_present_background_region(40, 30, 20, 10, 0x1111);
assert(g_step == 5);
}
}
int main(void)
{
win16_reset_segment_bindings();
win16_bind_segment(0x5000, g_dgroup, sizeof(g_dgroup), true);
win16_set_dgroup_selector(0x5000);
win16_write_u16(win16_make_far_pointer(0x5000, 0x085b), 0, 0x3000);
win16_write_u16(win16_make_far_pointer(0x5000, 0x085d), 0, 0x3001);
win16_write_u16(win16_make_far_pointer(0x5000, 0x085f), 0, 0x3002);
run_mode(1);
run_mode(2);
run_mode(3);
run_mode(4);
return 0;
}