Files
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

55 lines
1.5 KiB
C

#include "../tdkpin_arithmetic.h"
#include <assert.h>
#include <limits.h>
#include <setjmp.h>
#include <stdbool.h>
uint8_t g_borland_cpu_level;
static jmp_buf g_fault_jump;
static uint16_t g_runtime_code;
static bool g_divide_fault;
_Noreturn void borland_runtime_error(uint16_t code)
{
g_runtime_code = code;
longjmp(g_fault_jump, 1);
}
_Noreturn void win16_integer_divide_fault(void)
{
g_divide_fault = true;
longjmp(g_fault_jump, 1);
}
int main(void)
{
assert(borland_multiply_i32(123456, -789) == -97406784);
assert((uint32_t)borland_multiply_i32(INT32_MAX, INT32_MAX) == 1);
assert((uint32_t)borland_multiply_i32(INT32_MIN, 2) == 0);
BorlandDivI32Result result = borland_divide_i32(-100, 7);
assert(result.quotient == -14 && result.remainder == -2);
result = borland_divide_i32(100, -7);
assert(result.quotient == -14 && result.remainder == 2);
result = borland_divide_i32(-100, -7);
assert(result.quotient == 14 && result.remainder == -2);
g_borland_cpu_level = 1;
result = borland_divide_i32(INT32_MIN, -1);
assert(result.quotient == INT32_MIN && result.remainder == 0);
g_runtime_code = 0;
if (setjmp(g_fault_jump) == 0) {
(void)borland_divide_i32(1, 0);
assert(false);
}
assert(g_runtime_code == 200);
g_borland_cpu_level = 2;
g_divide_fault = false;
if (setjmp(g_fault_jump) == 0) {
(void)borland_divide_i32(INT32_MIN, -1);
assert(false);
}
assert(g_divide_fault);
return 0;
}