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
44 lines
1.4 KiB
C
44 lines
1.4 KiB
C
#include "tdkpin_arithmetic.h"
|
|
#include "tdkpin_borland_runtime.h"
|
|
|
|
/* Low 32 bits of signed DX:AX * BX:CX, independent of CPU implementation path. */
|
|
int32_t borland_multiply_i32(int32_t left, int32_t right)
|
|
{
|
|
uint32_t bits = (uint32_t)((uint64_t)(uint32_t)left * (uint32_t)right);
|
|
return (int32_t)bits;
|
|
}
|
|
|
|
BorlandDivI32Result borland_divide_i32(int32_t dividend, int32_t divisor)
|
|
{
|
|
if (divisor == 0) {
|
|
borland_runtime_error(200);
|
|
}
|
|
if (dividend == INT32_MIN && divisor == -1) {
|
|
if (g_borland_cpu_level >= 2) {
|
|
win16_integer_divide_fault();
|
|
}
|
|
return (BorlandDivI32Result){INT32_MIN, 0};
|
|
}
|
|
|
|
bool quotient_negative = (dividend < 0) != (divisor < 0);
|
|
bool remainder_negative = dividend < 0;
|
|
uint32_t dividend_magnitude = dividend < 0
|
|
? (uint32_t)(0u - (uint32_t)dividend)
|
|
: (uint32_t)dividend;
|
|
uint32_t divisor_magnitude = divisor < 0
|
|
? (uint32_t)(0u - (uint32_t)divisor)
|
|
: (uint32_t)divisor;
|
|
uint32_t quotient_bits = dividend_magnitude / divisor_magnitude;
|
|
uint32_t remainder_bits = dividend_magnitude % divisor_magnitude;
|
|
if (quotient_negative) {
|
|
quotient_bits = 0u - quotient_bits;
|
|
}
|
|
if (remainder_negative) {
|
|
remainder_bits = 0u - remainder_bits;
|
|
}
|
|
return (BorlandDivI32Result){
|
|
(int32_t)quotient_bits,
|
|
(int32_t)remainder_bits,
|
|
};
|
|
}
|