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
50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
#include "../tdkpin_random.h"
|
|
|
|
#include <assert.h>
|
|
|
|
uint32_t g_borland_random_seed;
|
|
|
|
static uint32_t expected_next(uint32_t seed)
|
|
{
|
|
return seed * 0x08088405u + 1u;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
g_borland_random_seed = 0x12345678;
|
|
uint32_t first = expected_next(g_borland_random_seed);
|
|
assert(borland_next_random() == first);
|
|
|
|
uint32_t second = expected_next(first);
|
|
uint16_t expected_below = (uint16_t)(((uint64_t)second * 3800) >> 32);
|
|
assert(borland_random_below(3800) == expected_below);
|
|
|
|
uint32_t third = expected_next(second);
|
|
int8_t expected_exponent = 0;
|
|
if (third != 0) {
|
|
expected_exponent = -128;
|
|
while ((third & 0x80000000u) == 0) {
|
|
third <<= 1;
|
|
expected_exponent--;
|
|
}
|
|
}
|
|
assert(borland_random_exponent() == expected_exponent);
|
|
|
|
g_borland_random_seed = 7;
|
|
(void)borland_random_below(0);
|
|
assert(g_borland_random_seed == expected_next(7));
|
|
|
|
g_borland_random_seed = 0xfedcba98;
|
|
uint32_t unit_seed = expected_next(g_borland_random_seed);
|
|
assert(borland_random_unit_interval() ==
|
|
(double)unit_seed / 4294967296.0);
|
|
assert(borland_random_unit_interval() >= 0.0 &&
|
|
borland_random_unit_interval() < 1.0);
|
|
|
|
win16_reset_segment_bindings();
|
|
win16_set_dos_time_words(0x33441122);
|
|
borland_seed_random_from_dos_time();
|
|
assert(g_borland_random_seed == 0x33441122);
|
|
return 0;
|
|
}
|