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

146 lines
3.5 KiB
C

#include "../tdkpin_runtime_ui.h"
#include "../tdkpin_segmented.h"
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
HWND16 g_tpwincrt_window;
uint8_t g_tpwincrt_paint_message_active;
HDC16 g_tpwincrt_paint_dc;
PAINTSTRUCT16 g_tpwincrt_paint;
HGDIOBJ16 g_tpwincrt_previous_font;
uint16_t g_tpwincrt_character_width;
uint16_t g_tpwincrt_character_height;
uint16_t g_tpwincrt_caret_y_offset;
uint16_t g_tpwincrt_columns;
uint16_t g_tpwincrt_rows;
static unsigned g_release_calls;
static unsigned g_select_calls;
HDC16 GetDC16(HWND16 window)
{
assert(window == 0x77);
return 0x100;
}
HDC16 BeginPaint16(HWND16 window, Win16FarPtr paint)
{
(void)window;
(void)paint;
assert(false);
return 0;
}
BOOL16 EndPaint16(HWND16 window, Win16FarPtr paint)
{
(void)window;
(void)paint;
assert(false);
return 0;
}
INT16 ReleaseDC16(HWND16 window, HDC16 dc)
{
assert(window == 0x77 && dc == 0x100);
g_release_calls++;
return 1;
}
HGDIOBJ16 GetStockObject16(INT16 object)
{
assert(object == 0x10);
return 0x200;
}
HGDIOBJ16 SelectObject16(HDC16 dc, HGDIOBJ16 object)
{
assert(dc == 0x100);
g_select_calls++;
if (g_select_calls == 1) {
assert(object == 0x200);
return 0x300;
}
assert(object == 0x300);
return 0x200;
}
COLORREF16 GetSysColor16(INT16 index)
{
return (COLORREF16)(0x1000 + index);
}
COLORREF16 SetTextColor16(HDC16 dc, COLORREF16 color)
{
assert(dc == 0x100 && color == 0x1008);
return 0;
}
COLORREF16 SetBkColor16(HDC16 dc, COLORREF16 color)
{
assert(dc == 0x100 && color == 0x1005);
return 0;
}
BOOL16 GetTextMetrics16(HDC16 dc, Win16FarPtr metrics)
{
assert(dc == 0x100);
TEXTMETRIC16 value;
memset(&value, 0, sizeof(value));
value.height = 12;
value.external_leading = 2;
value.ascent = 9;
value.maximum_character_width = 8;
const uint8_t *bytes = (const uint8_t *)&value;
for (uint16_t index = 0; index < sizeof(value); index++) {
win16_write_u8(win16_far_add_offset(metrics, index), bytes[index]);
}
return 1;
}
INT16 GetSystemMetrics16(INT16 index)
{
switch (index) {
case 0: return 640;
case 1: return 480;
case 2: return 16;
case 3: return 16;
case 4: return 20;
case 32: return 4;
case 33: return 5;
default: assert(false); return 0;
}
}
int main(void)
{
uint8_t stack_marker;
uintptr_t stack_base = (uintptr_t)&stack_marker - 0x8000;
static uint8_t output[32];
win16_reset_segment_bindings();
win16_bind_segment(0x9000, (void *)stack_base, 0x10000, true);
win16_bind_segment(0x8000, output, sizeof(output), true);
g_tpwincrt_window = 0x77;
g_tpwincrt_paint_message_active = 0;
g_tpwincrt_columns = 80;
g_tpwincrt_rows = 25;
g_release_calls = 0;
g_select_calls = 0;
Win16FarPtr target = win16_make_far_pointer(0x8000, 0);
tpwincrt_fill_minmax_info(target);
assert(g_tpwincrt_character_width == 8);
assert(g_tpwincrt_character_height == 14);
assert(g_tpwincrt_caret_y_offset == 9);
assert(win16_read_u16(win16_far_add_offset(target, 4)) == 648);
assert(win16_read_u16(win16_far_add_offset(target, 6)) == 396);
assert(win16_read_u16(win16_far_add_offset(target, 12)) == 152);
assert(win16_read_u16(win16_far_add_offset(target, 14)) == 102);
assert(win16_read_u16(win16_far_add_offset(target, 16)) == 648);
assert(win16_read_u16(win16_far_add_offset(target, 18)) == 396);
assert(g_select_calls == 2 && g_release_calls == 1);
return 0;
}