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
77 lines
2.5 KiB
C
77 lines
2.5 KiB
C
#include "../tdkpin_runtime_ui.h"
|
|
|
|
#include <assert.h>
|
|
#include <limits.h>
|
|
|
|
uint16_t g_tpwincrt_columns;
|
|
uint16_t g_tpwincrt_rows;
|
|
uint16_t g_tpwincrt_ring_row_origin;
|
|
Win16FarPtr g_tpwincrt_screen_buffer;
|
|
|
|
static void test_signed_bounds(void)
|
|
{
|
|
assert(tpwincrt_min_i16(-7, 3) == -7);
|
|
assert(tpwincrt_min_i16(INT16_MAX, INT16_MIN) == INT16_MIN);
|
|
assert(tpwincrt_max_i16(-7, 3) == 3);
|
|
assert(tpwincrt_max_i16(INT16_MIN, INT16_MAX) == INT16_MAX);
|
|
}
|
|
|
|
static void test_scroll_commands(void)
|
|
{
|
|
TpWinCrtScrollMessage message = {.thumb_position = 7};
|
|
|
|
message.command = TPWINCRT_SB_LINEUP;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 9);
|
|
message.command = TPWINCRT_SB_LINEDOWN;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 11);
|
|
message.command = TPWINCRT_SB_PAGEUP;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 6);
|
|
message.command = TPWINCRT_SB_PAGEDOWN;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 14);
|
|
message.command = TPWINCRT_SB_THUMBPOSITION;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 7);
|
|
message.command = TPWINCRT_SB_TOP;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 0);
|
|
message.command = TPWINCRT_SB_BOTTOM;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 20);
|
|
message.command = 5;
|
|
assert(tpwincrt_apply_scroll_command(&message, 20, 4, 10) == 10);
|
|
|
|
message.command = TPWINCRT_SB_LINEDOWN;
|
|
assert(tpwincrt_apply_scroll_command(&message, 0, 0, INT16_MAX) == INT16_MIN);
|
|
}
|
|
|
|
static void test_circular_cell_pointer(void)
|
|
{
|
|
g_tpwincrt_columns = 80;
|
|
g_tpwincrt_rows = 25;
|
|
g_tpwincrt_ring_row_origin = 24;
|
|
g_tpwincrt_screen_buffer = win16_make_far_pointer(0x1234, 0xfff0);
|
|
|
|
Win16FarPtr result = tpwincrt_cell_pointer(2, 5);
|
|
assert(win16_far_selector(result) == 0x1234);
|
|
assert(win16_far_offset(result) == 0x0045);
|
|
}
|
|
|
|
static void test_key_table_bytes(void)
|
|
{
|
|
static const uint8_t expected[48] = {
|
|
0x25, 0, 0, 0, 0x27, 0, 0, 1, 0x25, 1, 0, 2, 0x27, 1, 0, 3,
|
|
0x24, 0, 0, 6, 0x23, 0, 0, 7, 0x26, 0, 1, 0, 0x28, 0, 1, 1,
|
|
0x21, 0, 1, 2, 0x22, 0, 1, 3, 0x24, 1, 1, 6, 0x23, 1, 1, 7,
|
|
};
|
|
const uint8_t *actual = (const uint8_t *)g_tpwincrt_key_bindings;
|
|
for (unsigned index = 0; index < sizeof(expected); index++) {
|
|
assert(actual[index] == expected[index]);
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test_signed_bounds();
|
|
test_scroll_commands();
|
|
test_circular_cell_pointer();
|
|
test_key_table_bytes();
|
|
return 0;
|
|
}
|