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
141 lines
3.4 KiB
C
141 lines
3.4 KiB
C
#include "../tdkpin_game_assets.h"
|
|
|
|
#include <assert.h>
|
|
|
|
static uint8_t g_dgroup[0x5000];
|
|
static uint8_t g_window_bytes[32];
|
|
HINSTANCE16 g_win16_instance;
|
|
static Win16FarPtr g_window;
|
|
static unsigned g_setup_step;
|
|
static unsigned g_draw_step;
|
|
|
|
void object_windows_setup_window(Win16FarPtr window)
|
|
{
|
|
assert(++g_setup_step == 1 && window == g_window);
|
|
}
|
|
|
|
HCURSOR16 LoadCursor16(HINSTANCE16 instance, Win16FarPtr resource)
|
|
{
|
|
assert(instance == 0);
|
|
if (win16_far_offset(resource) == 0x7f02) {
|
|
assert(++g_setup_step == 2);
|
|
return 0x1111;
|
|
}
|
|
assert(++g_draw_step == 10);
|
|
assert(resource == win16_make_far_pointer(0, 0x7f00));
|
|
return 0x2222;
|
|
}
|
|
|
|
HCURSOR16 SetCursor16(HCURSOR16 cursor)
|
|
{
|
|
if (cursor == 0x1111) {
|
|
assert(++g_setup_step == 3);
|
|
} else {
|
|
assert(++g_draw_step == 11 && cursor == 0x2222);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
HBITMAP16 tdkpin_load_bitmap_resource(
|
|
Win16FarPtr resource_name, HINSTANCE16 instance)
|
|
{
|
|
assert(++g_setup_step == 4);
|
|
assert(resource_name == win16_make_far_pointer(0, 1005));
|
|
assert(instance == g_win16_instance);
|
|
return 0x3333;
|
|
}
|
|
|
|
HWND16 SetFocus16(HWND16 window)
|
|
{
|
|
assert(++g_setup_step == 5 && window == 0x7777);
|
|
return 0;
|
|
}
|
|
|
|
HPALETTE16 SelectPalette16(
|
|
HDC16 dc, HPALETTE16 palette, BOOL16 force_background)
|
|
{
|
|
assert(dc == 0x8888 && force_background == 0);
|
|
if (++g_draw_step == 1) {
|
|
assert(palette == 0x4444);
|
|
return 0x5555;
|
|
}
|
|
assert(g_draw_step == 9 && palette == 0x5555);
|
|
return 0x4444;
|
|
}
|
|
|
|
BOOL16 UnrealizeObject16(HGDIOBJ16 object)
|
|
{
|
|
assert(++g_draw_step == 2 && object == 0x4444);
|
|
return 1;
|
|
}
|
|
|
|
UINT16 RealizePalette16(HDC16 dc)
|
|
{
|
|
assert(++g_draw_step == 3 && dc == 0x8888);
|
|
return 256;
|
|
}
|
|
|
|
HDC16 CreateCompatibleDC16(HDC16 dc)
|
|
{
|
|
assert(++g_draw_step == 4 && dc == 0x8888);
|
|
return 0x9999;
|
|
}
|
|
|
|
HGDIOBJ16 SelectObject16(HDC16 dc, HGDIOBJ16 object)
|
|
{
|
|
assert(dc == 0x9999);
|
|
if (++g_draw_step == 5) {
|
|
assert(object == 0x3333);
|
|
return 0xaaaa;
|
|
}
|
|
assert(g_draw_step == 7 && object == 0xaaaa);
|
|
return 0x3333;
|
|
}
|
|
|
|
BOOL16 BitBlt16(
|
|
HDC16 destination,
|
|
INT16 destination_x,
|
|
INT16 destination_y,
|
|
INT16 width,
|
|
INT16 height,
|
|
HDC16 source,
|
|
INT16 source_x,
|
|
INT16 source_y,
|
|
uint32_t raster_operation)
|
|
{
|
|
assert(++g_draw_step == 6);
|
|
assert(destination == 0x8888 && source == 0x9999);
|
|
assert(destination_x == 0 && destination_y == 0);
|
|
assert(width == 640 && height == 460);
|
|
assert(source_x == 0 && source_y == 0);
|
|
assert(raster_operation == 0x00cc0020);
|
|
return 1;
|
|
}
|
|
|
|
BOOL16 DeleteDC16(HDC16 dc)
|
|
{
|
|
assert(++g_draw_step == 8 && dc == 0x9999);
|
|
return 1;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
win16_reset_segment_bindings();
|
|
win16_bind_segment(0x5000, g_dgroup, sizeof(g_dgroup), true);
|
|
win16_bind_segment(0x6000, g_window_bytes, sizeof(g_window_bytes), true);
|
|
win16_set_dgroup_selector(0x5000);
|
|
g_window = win16_make_far_pointer(0x6000, 0);
|
|
g_win16_instance = 0x6666;
|
|
win16_write_u16(g_window, 4, 0x7777);
|
|
win16_write_u16(win16_make_far_pointer(0x5000, 0x07cd), 0, 5);
|
|
win16_write_u16(win16_make_far_pointer(0x5000, 0x444e), 0, 0x4444);
|
|
|
|
tdkpin_setup_board_window(g_window);
|
|
assert(g_setup_step == 5);
|
|
assert(win16_read_u16(win16_make_far_pointer(0x5000, 0x0867)) == 0x3333);
|
|
|
|
tdkpin_draw_board_overlay(g_window, 0xbeef, 0xcafe, 0x8888);
|
|
assert(g_draw_step == 11);
|
|
return 0;
|
|
}
|