Files
tdkpin/original/reconstructed/tests/test_runtime_input.c
T
ddidderr 8b99e9607c feat(reconstruction): complete binary-backed C recovery
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
2026-08-23 16:41:17 +02:00

156 lines
4.1 KiB
C

#include "../tdkpin_runtime_ui.h"
#include <assert.h>
#include <setjmp.h>
#include <stdbool.h>
#include <string.h>
uint8_t g_tpwincrt_has_focus;
uint8_t g_tpwincrt_caret_enabled;
uint8_t g_tpwincrt_break_check_enabled;
uint16_t g_tpwincrt_input_count;
uint8_t g_tpwincrt_input_buffer[64];
uint16_t g_tpwincrt_view_column;
uint16_t g_tpwincrt_view_row;
uint16_t g_tpwincrt_max_view_column;
uint16_t g_tpwincrt_max_view_row;
uint16_t g_tpwincrt_visible_columns;
uint16_t g_tpwincrt_visible_rows;
uint16_t g_tpwincrt_character_width;
uint16_t g_tpwincrt_character_height;
uint8_t g_tpwincrt_window_created;
HWND16 g_tpwincrt_window;
static unsigned g_destroy_caret_calls;
static uint16_t g_exit_status;
static jmp_buf g_exit_jump;
static INT16 g_key_state;
static unsigned g_scroll_window_calls;
BOOL16 DestroyCaret16(void)
{
g_destroy_caret_calls++;
return 1;
}
_Noreturn void borland_runtime_exit(uint16_t status)
{
g_exit_status = status;
longjmp(g_exit_jump, 1);
}
INT16 GetKeyState16(INT16 virtual_key)
{
assert(virtual_key == 0x11);
return g_key_state;
}
INT16 SetScrollPos16(
HWND16 window, INT16 bar, INT16 position, BOOL16 redraw)
{
assert(window == g_tpwincrt_window && redraw == 1);
assert(bar == 0 || bar == 1);
return position;
}
BOOL16 ScrollWindow16(
HWND16 window,
INT16 delta_x,
INT16 delta_y,
Win16FarPtr scroll,
Win16FarPtr clip)
{
assert(window == g_tpwincrt_window && scroll == 0 && clip == 0);
(void)delta_x;
(void)delta_y;
g_scroll_window_calls++;
return 1;
}
BOOL16 UpdateWindow16(HWND16 window)
{
assert(window == g_tpwincrt_window);
return 1;
}
static void expect_abort(bool focused, bool caret)
{
g_tpwincrt_has_focus = focused;
g_tpwincrt_caret_enabled = caret;
g_destroy_caret_calls = 0;
g_exit_status = 0;
if (setjmp(g_exit_jump) == 0) {
tpwincrt_abort_on_ctrl_c();
assert(false);
}
assert(g_exit_status == 0xff);
assert(g_destroy_caret_calls == (focused && caret ? 1u : 0u));
}
int main(void)
{
expect_abort(true, true);
expect_abort(true, false);
expect_abort(false, true);
memset(g_tpwincrt_input_buffer, 0, sizeof(g_tpwincrt_input_buffer));
g_tpwincrt_break_check_enabled = 0;
g_tpwincrt_input_count = 0;
tpwincrt_queue_character('A');
assert(g_tpwincrt_input_count == 1 && g_tpwincrt_input_buffer[0] == 'A');
tpwincrt_queue_character(3);
assert(g_tpwincrt_input_count == 2 && g_tpwincrt_input_buffer[1] == 3);
g_tpwincrt_input_count = 64;
tpwincrt_queue_character('B');
assert(g_tpwincrt_input_count == 64);
g_tpwincrt_break_check_enabled = 1;
g_tpwincrt_input_count = 0;
g_tpwincrt_has_focus = 1;
g_tpwincrt_caret_enabled = 1;
g_destroy_caret_calls = 0;
if (setjmp(g_exit_jump) == 0) {
tpwincrt_queue_character(3);
assert(false);
}
assert(g_exit_status == 0xff && g_destroy_caret_calls == 1);
assert(g_tpwincrt_input_count == 0);
g_tpwincrt_break_check_enabled = 0;
g_tpwincrt_window_created = 1;
g_tpwincrt_window = 0x77;
g_tpwincrt_max_view_column = 10;
g_tpwincrt_max_view_row = 10;
g_tpwincrt_visible_columns = 4;
g_tpwincrt_visible_rows = 4;
g_tpwincrt_character_width = 8;
g_tpwincrt_character_height = 16;
g_tpwincrt_view_column = 5;
g_tpwincrt_view_row = 5;
g_key_state = 0;
g_scroll_window_calls = 0;
tpwincrt_handle_keydown(0x25);
assert(g_tpwincrt_view_column == 4 && g_tpwincrt_view_row == 5);
g_tpwincrt_view_column = 5;
g_key_state = -1;
tpwincrt_handle_keydown(0x25);
assert(g_tpwincrt_view_column == 3);
g_key_state = 0;
tpwincrt_handle_keydown(0x26);
assert(g_tpwincrt_view_row == 4);
uint16_t column = g_tpwincrt_view_column;
uint16_t row = g_tpwincrt_view_row;
tpwincrt_handle_keydown(0x30);
assert(g_tpwincrt_view_column == column && g_tpwincrt_view_row == row);
assert(g_scroll_window_calls == 3);
g_tpwincrt_break_check_enabled = 1;
if (setjmp(g_exit_jump) == 0) {
tpwincrt_handle_keydown(3);
assert(false);
}
assert(g_exit_status == 0xff);
return 0;
}