#include "../tdkpin_system_timer.h" #include static BorlandAllocationAttempt g_allocation; static Win16FarPtr g_freed_object; static uint16_t g_freed_size; static uint16_t g_make_result; static HWND16 g_make_recipient; static uint16_t g_make_delay; static uint16_t g_make_resolution; static uint16_t g_make_one_shot; static uint16_t g_killed_timer; BorlandAllocationAttempt borland_try_get_mem(uint16_t bytes) { assert(bytes == 6); return g_allocation; } bool borland_try_free_mem(Win16FarPtr object, uint16_t bytes) { g_freed_object = object; g_freed_size = bytes; return false; } _Noreturn void borland_runtime_error(uint16_t code) { (void)code; assert(false); __builtin_unreachable(); } uint16_t SystemTimerMake16( HWND16 recipient, uint16_t delay_ms, uint16_t resolution_ms, uint16_t one_shot) { g_make_recipient = recipient; g_make_delay = delay_ms; g_make_resolution = resolution_ms; g_make_one_shot = one_shot; return g_make_result; } uint16_t TimeKillEvent16(uint16_t timer_id) { g_killed_timer = timer_id; return 0; } int main(void) { static uint8_t dgroup[0x1000]; static uint8_t stack[0x10000]; static uint8_t caller_object[32]; static uint8_t allocated_object[32]; win16_reset_segment_bindings(); win16_bind_segment(0x5000, dgroup, sizeof(dgroup), true); win16_set_dgroup_selector(0x5000); win16_bind_segment(0x6000, stack, sizeof(stack), true); win16_set_stack_state(0x6000, 0x8000); win16_write_stack_u16(0x000a, 0x1000); win16_write_stack_u16(0x000e, 0x7fff); win16_bind_segment( 0x7000, caller_object, sizeof(caller_object), true); win16_bind_segment( 0x7100, allocated_object, sizeof(allocated_object), true); win16_write_u16(win16_make_far_pointer(0x5000, 0x0200), 0, 6); Win16FarPtr caller = win16_make_far_pointer(0x7000, 4); g_make_result = 0x4321; Win16FarPtr result = tdkpin_system_timer_construct( caller, 0x0200, 1, 7, 250, 0x1234); assert(result == caller); assert(win16_read_u16(caller) == 0x0200); assert(win16_read_u16(win16_far_add_offset(caller, 2)) == 0x4321); assert(win16_read_u16(win16_far_add_offset(caller, 4)) == 0x1234); assert(g_make_recipient == 0x1234); assert(g_make_delay == 250 && g_make_resolution == 7); assert(g_make_one_shot == 0x7b01); g_killed_timer = 0; tdkpin_system_timer_stop(caller); assert(g_killed_timer == 0x4321); assert(win16_read_u16(win16_far_add_offset(caller, 2)) == 0); tdkpin_system_timer_stop(caller); assert(g_killed_timer == 0x4321); Win16FarPtr allocated = win16_make_far_pointer(0x7100, 8); g_allocation = (BorlandAllocationAttempt){allocated, false}; g_make_result = 0; g_freed_object = 0; result = tdkpin_system_timer_construct( 0, 0x0200, 0, 1, 20, 0x2222); assert(result == 0); assert(g_freed_object == allocated && g_freed_size == 6); g_make_result = 0; g_freed_object = 0; result = tdkpin_system_timer_construct( caller, 0x0200, 0, 1, 20, 0x3333); assert(result == caller && g_freed_object == 0); win16_write_u16(caller, 0, 0x0200); win16_write_u16(caller, 2, 0x1111); g_freed_object = 0; tdkpin_system_timer_destruct(caller, 1); assert(g_killed_timer == 0x1111); assert(g_freed_object == caller && g_freed_size == 6); return 0; }