#include "../tdkpin_gameplay_helpers.h" #include #include uint8_t g_current_player; 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_get_dc_calls; static unsigned g_release_dc_calls; static unsigned g_sound_calls; static unsigned g_status_calls; static unsigned g_score_calls; static unsigned g_restore_a_calls; static unsigned g_restore_b_calls; static unsigned g_present_calls; static uint8_t g_status_player; static int32_t g_draw_score_argument; HDC16 GetDC16(HWND16 window) { assert(window == 0x2222); g_get_dc_calls++; return 0x3333; } INT16 ReleaseDC16(HWND16 window, HDC16 dc) { assert(window == 0x2222 && dc == 0x3333); g_release_dc_calls++; return 1; } void tdkpin_play_sound_if_not_tilted(uint16_t sound_number) { assert(sound_number == 7); g_sound_calls++; } void tdkpin_update_status_display(uint8_t player, HDC16 dc) { assert(dc == 0x3333); g_status_player = player; g_status_calls++; } void tdkpin_draw_score(HDC16 dc, int32_t value_or_player) { assert(dc == 0x3333); g_draw_score_argument = value_or_player; g_score_calls++; } void tdkpin_restore_background_region_a( INT16 height, INT16 width, INT16 y, INT16 x, HDC16 dc) { assert(height == 5 && width == 5 && dc == 0x3333); assert(y == 342 && x >= 391 && x <= 431); g_restore_a_calls++; } void tdkpin_restore_background_region_b( INT16 height, INT16 width, INT16 y, INT16 x, HDC16 dc) { assert(height == 5 && width == 5 && dc == 0x3333); assert(y == 342 && x >= 391 && x <= 431); g_restore_b_calls++; } void tdkpin_present_background_region( INT16 height, INT16 width, INT16 y, INT16 x, HDC16 dc) { assert(height == 5 && width == 5 && dc == 0x3333); assert(y == 342 && x >= 391 && x <= 431); g_present_calls++; } 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_u16(g_receiver, 4, 0x2222); g_current_player = 2; g_get_dc_calls = 0; g_release_dc_calls = 0; g_sound_calls = 0; g_status_calls = 0; g_score_calls = 0; g_restore_a_calls = 0; g_restore_b_calls = 0; g_present_calls = 0; g_status_player = 0; g_draw_score_argument = 0; } static uint32_t player_score(void) { return win16_read_u32(win16_dgroup_pointer(0x0986)); } static void test_multipliers_and_redraw_only_gates(void) { prepare_fixture(); win16_write_u32(win16_dgroup_pointer(0x0986), 0, 100); win16_write_u32(win16_dgroup_pointer(0x083d), 0, 5); win16_write_u8(win16_dgroup_pointer(0x0874), 1); win16_write_u8(win16_far_add_offset(g_receiver, 0x0bdc), 1); tdkpin_add_score_from_caller_frame(0x0100, 10); assert(player_score() == 140); assert(g_status_calls == 1 && g_status_player == 2); assert(g_score_calls == 1 && g_draw_score_argument == 2); assert(g_sound_calls == 0 && g_get_dc_calls == 1); assert(g_release_dc_calls == 1); prepare_fixture(); win16_write_u32(win16_dgroup_pointer(0x0986), 0, 100); tdkpin_add_score_from_caller_frame(0x0100, -1); assert(player_score() == 100 && g_status_calls == 0); assert(g_score_calls == 1 && g_release_dc_calls == 1); prepare_fixture(); win16_write_u32(win16_dgroup_pointer(0x0986), 0, 100); win16_write_u8(win16_dgroup_pointer(0x07c6), 1); tdkpin_add_score_from_caller_frame(0x0100, 10); assert(player_score() == 100 && g_status_calls == 0); assert(g_score_calls == 1 && g_release_dc_calls == 1); } static void test_threshold_award_and_marker_refresh(void) { prepare_fixture(); win16_write_u32(win16_dgroup_pointer(0x0986), 0, 90); win16_write_u32(win16_dgroup_pointer(0x083d), 0, 0); win16_write_u32(win16_dgroup_pointer(0x0825), 0, 100); win16_write_u16(win16_dgroup_pointer(0x0823), 0, 3); tdkpin_add_score_from_caller_frame(0x0100, 10); assert(player_score() == 100); assert(win16_read_u32(win16_dgroup_pointer(0x083d)) == 1); assert(win16_read_u16(win16_dgroup_pointer(0x0823)) == 4); assert(g_sound_calls == 1 && g_status_calls == 1); assert(g_restore_a_calls == 4 && g_restore_b_calls == 2); assert(g_present_calls == 6); assert(g_get_dc_calls == 2 && g_release_dc_calls == 2); assert(g_score_calls == 1 && g_draw_score_argument == 2); } int main(void) { test_multipliers_and_redraw_only_gates(); test_threshold_award_and_marker_refresh(); return 0; }