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
52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
/* Borland Pascal Win16 loader-register capture and runtime startup. */
|
|
|
|
#include "tdkpin_borland_startup.h"
|
|
|
|
enum {
|
|
WIN_FLAG_CPU_086 = 0x40,
|
|
WIN_FLAG_CPU_186 = 0x80,
|
|
WIN_FLAG_CPU_286 = 0x02,
|
|
BORLAND_HUGE_POINTER_INCREMENT = 8,
|
|
};
|
|
|
|
/*
|
|
* 1020:0002 -- first Borland runtime call made by ne_program_entry.
|
|
*
|
|
* The NE loader supplies the process state in registers, so the readable C
|
|
* interface packages those registers rather than pretending they were stack
|
|
* arguments. The original accepts only nonzero AX and a successful InitApp;
|
|
* either failure executes INT 21h/AH=4ch with AL=ff and never returns.
|
|
*/
|
|
void borland_initialize_win16_runtime(
|
|
const BorlandWin16StartupRegisters *registers)
|
|
{
|
|
if (registers->loader_ax == 0) {
|
|
win16_dos_terminate(0xff);
|
|
}
|
|
|
|
g_borland_windows_mode =
|
|
win16_far_selector(registers->command_line);
|
|
g_win16_previous_instance = registers->previous_instance;
|
|
g_win16_instance = registers->instance;
|
|
g_win16_show_command = registers->show_command;
|
|
g_borland_command_line = registers->command_line;
|
|
|
|
WaitEvent16(0);
|
|
if (InitApp16(g_win16_instance) == 0) {
|
|
win16_dos_terminate(0xff);
|
|
}
|
|
|
|
uint8_t flags = (uint8_t)GetWinFlags16();
|
|
uint16_t cpu_level = 0;
|
|
if ((flags & (WIN_FLAG_CPU_086 | WIN_FLAG_CPU_186)) == 0) {
|
|
cpu_level++;
|
|
if ((flags & WIN_FLAG_CPU_286) == 0) {
|
|
cpu_level++;
|
|
}
|
|
}
|
|
g_borland_cpu_level = (uint8_t)cpu_level;
|
|
|
|
/* KERNEL ordinal 114 is the imported equate __AHINCR, not a call. */
|
|
g_borland_huge_pointer_increment = BORLAND_HUGE_POINTER_INCREMENT;
|
|
}
|