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
67 lines
2.3 KiB
C
67 lines
2.3 KiB
C
#include "tdkpin_command_line.h"
|
|
|
|
/*
|
|
* 1020:0871 — scan one DOS command-tail token.
|
|
* Bytes <= space are separators. A zero starting index intentionally wraps to
|
|
* ffff after the first token and counts until the zero-length terminal scan.
|
|
*/
|
|
BorlandCommandToken borland_scan_command_token(uint16_t index)
|
|
{
|
|
Win16FarPtr cursor = g_borland_command_line;
|
|
while (true) {
|
|
uint8_t value;
|
|
do {
|
|
value = win16_read_u8(cursor);
|
|
cursor = win16_far_add_offset(cursor, 1);
|
|
} while (value != 0 && value <= 0x20);
|
|
|
|
cursor = win16_far_add_offset(cursor, 0xffff);
|
|
Win16FarPtr token = cursor;
|
|
do {
|
|
value = win16_read_u8(cursor);
|
|
cursor = win16_far_add_offset(cursor, 1);
|
|
} while (value > 0x20);
|
|
cursor = win16_far_add_offset(cursor, 0xffff);
|
|
uint16_t length =
|
|
(uint16_t)(win16_far_offset(cursor) - win16_far_offset(token));
|
|
if (length == 0) {
|
|
return (BorlandCommandToken){token, 0, index};
|
|
}
|
|
index--;
|
|
if (index == 0) {
|
|
return (BorlandCommandToken){token, length, index};
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 1020:0866 — CX=0 scan followed by XCHG/NEG returns the token count. */
|
|
uint16_t borland_parameter_count(void)
|
|
{
|
|
BorlandCommandToken terminal = borland_scan_command_token(0);
|
|
return (uint16_t)(0 - terminal.remaining_index);
|
|
}
|
|
|
|
/*
|
|
* 1020:082e — ParamStr with a hidden far ShortString result.
|
|
* For command tokens, AL becomes the length byte while REP MOVSB retains the
|
|
* complete uint16 token length; this deliberately preserves >255 overflow.
|
|
*/
|
|
void borland_parameter_string(uint16_t index, Win16FarPtr destination)
|
|
{
|
|
if (index == 0) {
|
|
uint16_t length = GetModuleFileNameFar16(
|
|
g_win16_instance,
|
|
win16_far_add_offset(destination, 1),
|
|
0xff);
|
|
win16_write_u8(destination, (uint8_t)length);
|
|
return;
|
|
}
|
|
BorlandCommandToken token = borland_scan_command_token(index);
|
|
win16_write_u8(destination, (uint8_t)token.length);
|
|
for (uint16_t offset = 0; offset < token.length; offset++) {
|
|
win16_write_u8(
|
|
win16_far_add_offset(destination, (uint16_t)(offset + 1)),
|
|
win16_read_u8(win16_far_add_offset(token.token, offset)));
|
|
}
|
|
}
|