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

119 lines
3.8 KiB
C

#include "../tdkpin_shortstrings.h"
#include <assert.h>
#include <string.h>
static uint8_t g_left[0x10000];
static uint8_t g_right[0x10000];
static Win16FarPtr left_at(uint16_t offset)
{
return win16_make_far_pointer(0x3333, offset);
}
static Win16FarPtr right_at(uint16_t offset)
{
return win16_make_far_pointer(0x4444, offset);
}
static void reset_memory(void)
{
memset(g_left, 0, sizeof(g_left));
memset(g_right, 0, sizeof(g_right));
win16_reset_segment_bindings();
win16_bind_segment(0x3333, g_left, sizeof(g_left), true);
win16_bind_segment(0x4444, g_right, sizeof(g_right), true);
}
static void set_short(uint8_t *bytes, uint16_t offset, const char *text)
{
size_t length = strlen(text);
assert(length <= 255);
bytes[offset] = (uint8_t)length;
memcpy(&bytes[offset + 1], text, length);
}
static void test_shifts(void)
{
assert(borland_shift_right_u32(0x87654321, 4) == 0x08765432);
assert(borland_shift_left_u32(0x87654321, 4) == 0x76543210);
assert(borland_shift_right_u32(0x87654321, 36) == 0x08765432);
assert(borland_shift_left_u32(0x87654321, 32) == 0x87654321);
}
static void test_assignment_copy_and_concat(void)
{
reset_memory();
set_short(g_left, 10, "abcdef");
borland_short_assign(right_at(10), left_at(10));
assert(memcmp(&g_right[10], &g_left[10], 7) == 0);
borland_short_assign_truncated(right_at(30), left_at(10), 3);
assert(g_right[30] == 3 && memcmp(&g_right[31], "abc", 3) == 0);
borland_short_substring(right_at(50), left_at(10), 2, 3);
assert(g_right[50] == 3 && memcmp(&g_right[51], "bcd", 3) == 0);
borland_short_substring(right_at(60), left_at(10), -2, -1);
assert(g_right[60] == 0);
set_short(g_right, 100, "one");
set_short(g_left, 100, "two");
borland_short_concat(right_at(100), left_at(100));
assert(g_right[100] == 6 && memcmp(&g_right[101], "onetwo", 6) == 0);
g_right[200] = 250;
memset(&g_right[201], 'x', 250);
g_left[200] = 10;
memset(&g_left[201], 'y', 10);
borland_short_concat(right_at(200), left_at(200));
assert(g_right[200] == 255);
assert(memcmp(&g_right[451], "yyyyy", 5) == 0);
}
static void test_search_compare_and_conversion(void)
{
reset_memory();
set_short(g_left, 10, "cab");
set_short(g_right, 10, "abcabc");
assert(borland_short_position(left_at(10), right_at(10)) == 3);
g_left[10] = 0;
assert(borland_short_position(left_at(10), right_at(10)) == 0);
set_short(g_left, 30, "abc");
set_short(g_right, 30, "abd");
assert(borland_short_compare(left_at(30), right_at(30)) < 0);
set_short(g_right, 30, "abcx");
assert(borland_short_compare(left_at(30), right_at(30)) < 0);
borland_character_to_short(right_at(60), 'Q');
assert(g_right[60] == 1 && g_right[61] == 'Q');
memcpy(&g_left[80], "bytes", 5);
borland_bytes_to_short(right_at(80), left_at(80), 5);
assert(g_right[80] == 5 && memcmp(&g_right[81], "bytes", 5) == 0);
}
static void test_insert_and_delete(void)
{
reset_memory();
set_short(g_right, 100, "abcd");
set_short(g_left, 100, "XY");
borland_short_insert(right_at(100), left_at(100), 3, 255);
assert(g_right[100] == 6 && memcmp(&g_right[101], "abXYcd", 6) == 0);
set_short(g_right, 120, "abcd");
borland_short_insert(right_at(120), left_at(100), 99, 5);
assert(g_right[120] == 5 && memcmp(&g_right[121], "abcdX", 5) == 0);
borland_short_delete(right_at(100), 2, 3);
assert(g_right[100] == 3 && memcmp(&g_right[101], "acd", 3) == 0);
borland_short_delete(right_at(100), 0, 2);
assert(g_right[100] == 3 && memcmp(&g_right[101], "acd", 3) == 0);
}
int main(void)
{
test_shifts();
test_assignment_copy_and_concat();
test_search_compare_and_conversion();
test_insert_and_delete();
return 0;
}