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

113 lines
3.1 KiB
C

#include "../tdkpin_gameplay_helpers.h"
#include <assert.h>
#include <string.h>
static uint8_t g_dgroup[0x5000];
static unsigned g_create_dc_calls;
static unsigned g_create_bitmap_calls;
static unsigned g_select_calls;
static unsigned g_blit_calls;
static unsigned g_delete_object_calls;
static unsigned g_delete_dc_calls;
HDC16 CreateCompatibleDC16(HDC16 dc)
{
assert(dc == 0x3333 && g_create_dc_calls < 3);
return (HDC16)(0x4001 + g_create_dc_calls++);
}
HBITMAP16 CreateCompatibleBitmap16(HDC16 dc, INT16 width, INT16 height)
{
assert(dc == 0x3333 && width == 14 && height == 14);
g_create_bitmap_calls++;
return 0x5000;
}
HGDIOBJ16 SelectObject16(HDC16 dc, HGDIOBJ16 object)
{
switch (g_select_calls++) {
case 0:
assert(dc == 0x4001 && object == 0x6000);
return 0x7001;
case 1:
assert(dc == 0x4002 && object == 0x6003);
return 0x7002;
case 2:
assert(dc == 0x4003 && object == 0x5000);
return 0x7003;
case 3:
assert(dc == 0x4003 && object == 0x7003);
return 0x5000;
case 4:
assert(dc == 0x4002 && object == 0x7002);
return 0x6003;
default:
assert(g_select_calls == 6);
assert(dc == 0x4001 && object == 0x7001);
return 0x6000;
}
}
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)
{
assert(raster_operation == 0x00cc0020u);
switch (g_blit_calls++) {
case 0:
assert(destination == 0x4003 && destination_x == 0);
assert(destination_y == 0 && width == 14 && height == 14);
assert(source == 0x4001 && source_x == 84 && source_y == 77);
break;
case 1:
assert(destination == 0x4001 && destination_x == 55);
assert(destination_y == 79 && width == 42 && height == 123);
assert(source == 0x4002 && source_x == 0 && source_y == 0);
break;
default:
assert(g_blit_calls == 3);
assert(destination == 0x4001 && destination_x == 84);
assert(destination_y == 77 && width == 14 && height == 14);
assert(source == 0x4003 && source_x == 0 && source_y == 0);
break;
}
return 1;
}
BOOL16 DeleteObject16(HGDIOBJ16 object)
{
assert(object == 0x5000);
g_delete_object_calls++;
return 1;
}
BOOL16 DeleteDC16(HDC16 dc)
{
assert(dc == (HDC16)(0x4003 - g_delete_dc_calls));
g_delete_dc_calls++;
return 1;
}
int main(void)
{
memset(g_dgroup, 0, sizeof(g_dgroup));
win16_reset_segment_bindings();
win16_bind_segment(0x7200, g_dgroup, sizeof(g_dgroup), true);
win16_set_dgroup_selector(0x7200);
win16_write_u16(win16_dgroup_pointer(0x085b), 0, 0x6000);
win16_write_u16(win16_dgroup_pointer(0x4311), 0, 0x6003);
tdkpin_composite_player_sprite(3, 0x3333);
assert(g_create_dc_calls == 3 && g_create_bitmap_calls == 1);
assert(g_select_calls == 6 && g_blit_calls == 3);
assert(g_delete_object_calls == 1 && g_delete_dc_calls == 3);
return 0;
}