Files
tdkpin/original/reconstructed/tdkpin_multimedia_startup.c
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

130 lines
4.4 KiB
C

/* CTL3D file probing and Pascal unit initialization from Code3. */
#include "tdkpin_multimedia.h"
#include "tdkpin_borland_files.h"
#include "tdkpin_borland_records.h"
#include "tdkpin_shortstrings.h"
#include "tdkpin_strings.h"
extern Win16FarPtr g_multimedia_procedures[11]; /* 1028:4750..477b */
extern HINSTANCE16 g_multimedia_module; /* 1028:4781 */
extern uint8_t g_multimedia_initialized; /* 1028:4784 */
enum {
DGROUP_CTL3D_DLL = 0x0522,
DGROUP_CTL3DV2_DLL = 0x052c,
DGROUP_MULTIMEDIA_LIBRARY_PATH = 0x478d,
DGROUP_SYSTEM_DIRECTORY = 0x47a4,
DGROUP_CTL3D_FULL_SHORT = 0x486d,
DGROUP_CTL3DV2_FULL_SHORT = 0x496d,
};
/*
* 1010:0405 -- existence probe for one Pascal ShortString path. A failed
* open is consumed through IOResult and reported false. A successful open is
* closed, and any close failure follows the original RuntimeError path.
*/
bool multimedia_short_file_exists(Win16FarPtr short_name)
{
uint8_t copied_name[256];
uint8_t length = win16_read_u8(short_name);
copied_name[0] = length;
for (uint16_t index = 0; index < length; index++) {
copied_name[index + 1] = win16_read_u8(
win16_far_add_offset(short_name, (uint16_t)(index + 1)));
}
uint8_t record_bytes[128];
Win16FarPtr copied_name_far = win16_stack_pointer(copied_name);
Win16FarPtr record = win16_stack_pointer(record_bytes);
borland_assign_file_short(copied_name_far, record);
borland_open_generic_file(1, record);
if (borland_take_io_result() != 0) {
return false;
}
borland_close_generic_file(record);
borland_require_io_success();
return true;
}
static void construct_system_path(
Win16FarPtr destination,
Win16FarPtr file_name,
Win16FarPtr temporary_directory,
Win16FarPtr temporary_file)
{
borland_c_to_short_string(
temporary_directory,
win16_dgroup_pointer(DGROUP_SYSTEM_DIRECTORY));
borland_short_concat(
temporary_directory,
win16_relocated_code_pointer(3, 0x0470));
borland_c_to_short_string(temporary_file, file_name);
borland_short_concat(temporary_directory, temporary_file);
borland_short_assign_truncated(
destination, temporary_directory, 0xff);
}
/*
* 1010:0472 -- initialize all CTL3D unit state and Windows-version policy.
* The two 256-byte temporaries are Pascal ShortStrings. The system-directory
* paths remain ShortStrings at 486d/496d; only the selected DLL basename at
* 478d is converted back to a NUL-terminated C string for LoadLibrary.
*/
void multimedia_initialize_runtime_unit(void)
{
g_multimedia_system_directory_length = GetSystemDirectoryFar16(
win16_dgroup_pointer(DGROUP_SYSTEM_DIRECTORY), 200);
uint8_t directory_short[256];
uint8_t file_short[256];
Win16FarPtr directory = win16_stack_pointer(directory_short);
Win16FarPtr file = win16_stack_pointer(file_short);
construct_system_path(
win16_dgroup_pointer(DGROUP_CTL3D_FULL_SHORT),
win16_dgroup_pointer(DGROUP_CTL3D_DLL),
directory,
file);
construct_system_path(
win16_dgroup_pointer(DGROUP_CTL3DV2_FULL_SHORT),
win16_dgroup_pointer(DGROUP_CTL3DV2_DLL),
directory,
file);
if (g_multimedia_system_directory_length != 0) {
borland_c_to_short_string(
file, win16_dgroup_pointer(DGROUP_CTL3DV2_DLL));
(void)borland_short_to_c_string(
win16_dgroup_pointer(DGROUP_MULTIMEDIA_LIBRARY_PATH), file);
if (!multimedia_short_file_exists(
win16_dgroup_pointer(DGROUP_CTL3DV2_FULL_SHORT)) &&
multimedia_short_file_exists(
win16_dgroup_pointer(DGROUP_CTL3D_FULL_SHORT))) {
borland_c_to_short_string(
file, win16_dgroup_pointer(DGROUP_CTL3D_DLL));
(void)borland_short_to_c_string(
win16_dgroup_pointer(DGROUP_MULTIMEDIA_LIBRARY_PATH), file);
}
}
for (uint16_t index = 0; index < 11; index++) {
g_multimedia_procedures[index] = 0;
}
g_multimedia_windows_version = (uint16_t)GetVersion16();
uint8_t major = (uint8_t)g_multimedia_windows_version;
uint8_t minor = (uint8_t)(g_multimedia_windows_version >> 8);
g_multimedia_legacy_windows = major == 3 && minor < 10;
g_multimedia_auto_subclassed = 0;
g_multimedia_argument_2 = 0;
g_multimedia_argument_1 = 1;
g_multimedia_module = 0;
g_multimedia_pending = 0;
g_multimedia_initialized = 0;
}