Files
tdkpin/original/reconstructed/tdkpin_segmented.h
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

112 lines
3.9 KiB
C

#ifndef TDKPIN_SEGMENTED_H
#define TDKPIN_SEGMENTED_H
#include "tdkpin_win16.h"
#include <stdbool.h>
#include <stddef.h>
/*
* Explicit operations whose semantics depend on a live Win16 selector table.
* Keeping them visible prevents a host pointer cast from silently replacing
* segmented 16:16 behavior in the reconstructed source.
*/
Win16FarPtr win16_dgroup_pointer(uint16_t offset);
Win16FarPtr win16_relocated_code_pointer(uint16_t ne_segment, uint16_t offset);
Win16FarPtr win16_stack_pointer(void *pointer);
Win16FarPtr win16_current_stack_address(uint16_t offset);
Win16FarPtr win16_read_far_pointer(Win16FarPtr base, uint16_t byte_offset);
uint8_t win16_read_u8(Win16FarPtr address);
uint16_t win16_read_u16(Win16FarPtr address);
uint32_t win16_read_u32(Win16FarPtr address);
void win16_write_u8(Win16FarPtr address, uint8_t value);
void win16_write_u16(Win16FarPtr base, uint16_t byte_offset, uint16_t value);
void win16_write_u32(Win16FarPtr base, uint16_t byte_offset, uint32_t value);
LRESULT16 win16_call_window_proc(
Win16FarPtr procedure,
HWND16 window,
UINT16 message,
WPARAM16 wparam,
LPARAM16 lparam);
uint16_t win16_call_pascal_u16(
Win16FarPtr procedure, uint16_t argument);
uint16_t win16_call_pascal_u16_no_args(Win16FarPtr procedure);
void win16_call_exit_proc(Win16FarPtr procedure);
void win16_call_object_destructor(
Win16FarPtr procedure,
Win16FarPtr object,
uint16_t dispose_mode);
void win16_call_dynamic_method(Win16FarPtr procedure);
void win16_call_dynamic_method_two_far(
Win16FarPtr procedure,
Win16FarPtr receiver,
Win16FarPtr argument);
void win16_call_object_method(
Win16FarPtr procedure, Win16FarPtr object);
void win16_call_object_u16_method(
Win16FarPtr procedure,
Win16FarPtr object,
uint16_t argument);
void win16_fill_bytes(Win16FarPtr destination, uint16_t count, uint8_t value);
_Noreturn void win16_dos_terminate(uint8_t status);
uint16_t win16_indeterminate_u16(void);
uint32_t win16_dos_time_words(void);
Win16FarPtr win16_current_return_address(void);
uint16_t win16_current_stack_pointer(void);
uint16_t win16_read_stack_u16(uint16_t offset);
void win16_write_stack_u16(uint16_t offset, uint16_t value);
uint16_t win16_exchange_u16(Win16FarPtr address, uint16_t value);
_Noreturn void win16_integer_divide_fault(void);
typedef struct {
uint16_t ax;
bool carry;
} Win16DosResult;
/* Register-complete result for DOS calls whose successful value is DX:AX. */
typedef struct {
uint16_t ax;
uint16_t dx;
bool carry;
} Win16DosExtendedResult;
typedef struct {
uint16_t attributes;
bool carry;
} Win16DosFileAttributesResult;
Win16DosResult win16_dos_read(
uint16_t handle, Win16FarPtr buffer, uint16_t count);
Win16DosResult win16_dos_write(
uint16_t handle, Win16FarPtr buffer, uint16_t count);
Win16DosResult win16_dos_close(uint16_t handle);
Win16DosResult win16_dos_seek(
uint16_t handle, uint32_t offset, uint8_t origin);
Win16DosResult win16_dos_open(
Win16FarPtr name, uint8_t access_mode);
Win16DosResult win16_dos_create(
Win16FarPtr name, uint16_t attributes);
Win16DosExtendedResult win16_dos_seek_extended(
uint16_t handle, uint32_t offset, uint8_t origin);
Win16DosExtendedResult win16_dos_get_device_info(uint16_t handle);
Win16DosFileAttributesResult win16_dos_get_file_attributes(
Win16FarPtr oem_name);
/* Portable verification/runtime binding for selector-backed host memory. */
void win16_reset_segment_bindings(void);
void win16_bind_segment(
uint16_t selector, void *bytes, size_t size, bool writable);
void win16_bind_ne_segment(
uint16_t ne_segment,
uint16_t selector,
void *bytes,
size_t size,
bool writable);
void win16_set_dgroup_selector(uint16_t selector);
void win16_set_current_return_address(Win16FarPtr address);
void win16_set_dos_time_words(uint32_t words);
void win16_set_indeterminate_u16(uint16_t value);
void win16_set_stack_state(uint16_t selector, uint16_t stack_pointer);
#endif