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

62 lines
2.2 KiB
C

#include "../tdkpin_command_line.h"
#include <assert.h>
#include <string.h>
static uint8_t g_command_segment[0x10000];
Win16FarPtr g_borland_command_line;
HINSTANCE16 g_win16_instance;
UINT16 GetModuleFileNameFar16(
HINSTANCE16 module, Win16FarPtr buffer, UINT16 size)
{
assert(module == g_win16_instance && size == 0xff);
static const char path[] = "C:\\TDKPIN.EXE";
for (uint16_t index = 0; index < sizeof(path); index++) {
win16_write_u8(win16_far_add_offset(buffer, index), path[index]);
}
return (UINT16)(sizeof(path) - 1);
}
int main(void)
{
static const char command[] = " one two\tthree";
memcpy(&g_command_segment[0x100], command, sizeof(command));
win16_reset_segment_bindings();
win16_bind_segment(
0x5555, g_command_segment, sizeof(g_command_segment), true);
static uint8_t result_segment[0x10000];
win16_bind_segment(
0x6666, result_segment, sizeof(result_segment), true);
g_borland_command_line = win16_make_far_pointer(0x5555, 0x100);
assert(borland_parameter_count() == 3);
BorlandCommandToken first = borland_scan_command_token(1);
assert(first.token == win16_make_far_pointer(0x5555, 0x102));
assert(first.length == 3);
BorlandCommandToken second = borland_scan_command_token(2);
assert(second.token == win16_make_far_pointer(0x5555, 0x106));
assert(second.length == 3);
BorlandCommandToken missing = borland_scan_command_token(4);
assert(missing.length == 0);
Win16FarPtr result = win16_make_far_pointer(0x6666, 0x100);
borland_parameter_string(1, result);
assert(result_segment[0x100] == 3);
assert(memcmp(&result_segment[0x101], "one", 3) == 0);
borland_parameter_string(4, result);
assert(result_segment[0x100] == 0);
g_win16_instance = 0x1234;
borland_parameter_string(0, result);
assert(result_segment[0x100] == 13);
assert(memcmp(&result_segment[0x101], "C:\\TDKPIN.EXE", 13) == 0);
memset(&g_command_segment[0x200], 'x', 260);
g_command_segment[0x304] = 0;
g_borland_command_line = win16_make_far_pointer(0x5555, 0x200);
borland_parameter_string(1, result);
assert(result_segment[0x100] == 4);
assert(memcmp(&result_segment[0x101], &g_command_segment[0x200], 260) == 0);
return 0;
}