#include "../tdkpin_gameplay_helpers.h" #include #include uint8_t g_borland_cpu_level = 2; _Noreturn void borland_runtime_error(uint16_t code) { (void)code; __builtin_trap(); } _Noreturn void win16_integer_divide_fault(void) { __builtin_trap(); } static uint8_t g_stack[0x400]; static uint8_t g_object[0x0c00]; static uint8_t g_dgroup[0x5000]; static Win16FarPtr g_receiver; static unsigned g_create_dc_calls; static unsigned g_select_calls; static unsigned g_blit_calls; static unsigned g_delete_dc_calls; static unsigned g_release_calls; static bool g_expect_present; BOOL16 GetClientRect16(HWND16 window, Win16FarPtr rectangle) { assert(window == 0x2222); assert(rectangle == win16_make_far_pointer(0x7000, 0x00e6)); return 1; } HDC16 GetDC16(HWND16 window) { assert(window == 0x2222); return 0x3333; } HDC16 CreateCompatibleDC16(HDC16 dc) { assert(dc == 0x3333 && g_create_dc_calls < 3); return (HDC16)(0x4001 + g_create_dc_calls++); } HBITMAP16 CreateCompatibleBitmap16(HDC16 dc, INT16 width, INT16 height) { assert(dc == 0x3333 && width == 100 && height == 100); return 0x5000; } HGDIOBJ16 SelectObject16(HDC16 dc, HGDIOBJ16 object) { switch (g_select_calls++) { case 0: assert(dc == 0x4001 && object == 0x6000); return 0x7001; case 1: assert(dc == 0x4002 && object == 0x5000); return 0x7002; case 2: assert(dc == 0x4001 && object == 0x7001); return 0x6000; case 3: assert(dc == 0x4002 && object == 0x7002); return 0x5000; default: assert(g_select_calls == 5); assert(dc == 0x4003 && object == 0x7003); return 0; } } 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(raster_operation == 0x00cc0020u); if (g_blit_calls == 0) { assert(destination == 0x4002 && destination_x == 0); assert(destination_y == 0 && width == 19 && height == 19); assert(source == 0x4001 && source_x == 91 && source_y == 431); } else { assert(g_expect_present && g_blit_calls == 1); assert(destination == 0x3333 && destination_x == 91); assert(destination_y == 431 && width == 19 && height == 12); assert(source == 0x4002 && source_x == 0 && source_y == 0); } g_blit_calls++; return 1; } BOOL16 DeleteObject16(HGDIOBJ16 object) { assert(object == 0x5000); return 1; } BOOL16 DeleteDC16(HDC16 dc) { assert(dc == (HDC16)(0x4001 + g_delete_dc_calls)); g_delete_dc_calls++; return 1; } INT16 ReleaseDC16(HWND16 window, HDC16 dc) { assert(window == 0x2222 && dc == 0x3333); g_release_calls++; return 1; } static void prepare_fixture(void) { memset(g_stack, 0, sizeof(g_stack)); memset(g_object, 0, sizeof(g_object)); memset(g_dgroup, 0, sizeof(g_dgroup)); win16_reset_segment_bindings(); win16_bind_segment(0x7000, g_stack, sizeof(g_stack), true); win16_bind_segment(0x7100, g_object, sizeof(g_object), true); win16_bind_segment(0x7200, g_dgroup, sizeof(g_dgroup), true); win16_set_dgroup_selector(0x7200); win16_set_stack_state(0x7000, 0); g_receiver = win16_make_far_pointer(0x7100, 0); win16_write_stack_u16(0x0106, win16_far_offset(g_receiver)); win16_write_stack_u16(0x0108, win16_far_selector(g_receiver)); win16_write_stack_u16(0x00fa, 0x7003); win16_write_u16(g_receiver, 4, 0x2222); win16_write_u32(g_receiver, 0x0bc2, 100000); win16_write_u32(g_receiver, 0x0bc6, 440000); win16_write_u32(g_receiver, 0x0baa, 0xaaaaaaaau); win16_write_u32(g_receiver, 0x0bae, 0xbbbbbbbbu); win16_write_u16(win16_dgroup_pointer(0x085b), 0, 0x6000); g_create_dc_calls = 0; g_select_calls = 0; g_blit_calls = 0; g_delete_dc_calls = 0; g_release_calls = 0; } static void run_case(uint8_t suppress) { prepare_fixture(); g_expect_present = suppress == 0; tdkpin_restore_previous_ball_region(0x0100, suppress); assert(g_create_dc_calls == 3 && g_select_calls == 5); assert(g_blit_calls == (g_expect_present ? 2u : 1u)); assert(g_delete_dc_calls == 3 && g_release_calls == 1); assert((int32_t)win16_read_u32( win16_far_add_offset(g_receiver, 0x0ba2)) == 92); assert((int32_t)win16_read_u32( win16_far_add_offset(g_receiver, 0x0ba6)) == 432); assert(win16_read_u32(win16_far_add_offset(g_receiver, 0x0baa)) == 0); assert(win16_read_u32(win16_far_add_offset(g_receiver, 0x0bae)) == 0); assert(win16_read_stack_u16(0x00d6) == 12); } int main(void) { run_case(0); run_case(1); return 0; }