Files
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

83 lines
2.7 KiB
C

/* TDKPIN global asset and main-window shutdown sequence. */
#include "tdkpin_game_assets.h"
#include "tdkpin_borland_objects.h"
#include "tdkpin_message_pump.h"
#include "tdkpin_sound.h"
#include "tdkpin_window_lifecycle.h"
enum {
DGROUP_GLOBAL_BITMAP_FIRST = 0x0859,
DGROUP_SPRITE_BITMAPS = 0x430b,
DGROUP_STATUS_BITMAPS_BASE = 0x4319,
DGROUP_ITEM_BITMAPS_BASE = 0x4321,
WINDOW_HANDLE_OFFSET = 4,
WINDOW_MASK_BITMAP_OFFSET = 0x52,
WINDOW_OWNED_OBJECT_OFFSET = 0x49,
WINDOW_ALREADY_REDRAWN_OFFSET = 0x0bd8,
WINDOW_REDRAW_BUSY_OFFSET = 0x0bd9,
WIN16_IDC_WAIT = 0x7f02,
};
static void delete_dgroup_bitmap(uint16_t offset)
{
(void)DeleteObject16(
win16_read_u16(win16_dgroup_pointer(offset)));
}
/*
* 1000:51f5 — stop sound, dispose all globally published image assets, restore
* the cursor, post quit code 18, then run TWindow and derived destructor exits.
* Handles are intentionally left stale in their slots, exactly like the image.
*/
void tdkpin_asset_window_destruct(
Win16FarPtr window, uint16_t vmt)
{
HCURSOR16 wait = LoadCursor16(
0, win16_make_far_pointer(0, WIN16_IDC_WAIT));
HCURSOR16 previous_cursor = SetCursor16(wait);
tdkpin_unload_sounds();
win16_write_u8(
win16_far_add_offset(window, WINDOW_REDRAW_BUSY_OFFSET), 1);
win16_write_u8(
win16_far_add_offset(window, WINDOW_ALREADY_REDRAWN_OFFSET), 1);
Win16FarPtr owned =
win16_read_far_pointer(window, WINDOW_OWNED_OBJECT_OFFSET);
if (owned != 0) {
borland_dispose_object(owned);
}
tdkpin_drain_messages_except_input();
(void)DeleteObject16(
win16_read_u16(win16_far_add_offset(
window, WINDOW_MASK_BITMAP_OFFSET)));
delete_dgroup_bitmap(DGROUP_GLOBAL_BITMAP_FIRST);
delete_dgroup_bitmap(0x0863);
delete_dgroup_bitmap(0x0865);
delete_dgroup_bitmap(0x085f);
delete_dgroup_bitmap(0x085b);
delete_dgroup_bitmap(0x0861);
delete_dgroup_bitmap(0x085d);
for (uint16_t index = 0; index < 8; index++) {
delete_dgroup_bitmap(
(uint16_t)(DGROUP_SPRITE_BITMAPS + index * 2));
}
for (uint16_t index = 1; index <= 4; index++) {
delete_dgroup_bitmap(
(uint16_t)(DGROUP_STATUS_BITMAPS_BASE + index * 2));
}
for (uint16_t index = 1; index <= 9; index++) {
delete_dgroup_bitmap(
(uint16_t)(DGROUP_ITEM_BITMAPS_BASE + index * 2));
}
(void)SetCursor16(previous_cursor);
PostQuitMessage16(0x12);
object_windows_window_destruct(window, 0);
HWND16 handle =
win16_read_u16(win16_far_add_offset(window, WINDOW_HANDLE_OFFSET));
(void)InvalidateRect16(handle, 0, 1);
BorlandObjectCallFrame frame = {window, vmt};
borland_finish_object_destructor(&frame, 0);
}