client/tests/animation_events.c (4466B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_3604F180(void); 5 void sub_250973C0(void); 6 void sub_25097550(void); 7 void sub_250975A0(void); 8 void sub_250975D0(void); 9 void sub_250975F0(void); 10 static unsigned lookups; 11 12 static void get_mesh(void) 13 { 14 g_eax = MEM32(g_ecx); 15 g_esp += 4; 16 } 17 18 static void find_animation(void) 19 { 20 ++lookups; 21 sub_250973C0(); 22 } 23 24 static void yield(void) {} 25 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 26 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 27 recomp_func_t recomp_lookup(uint32_t address) 28 { 29 switch (address) { 30 case 1: return get_mesh; 31 case 2: return sub_250975F0; 32 case 0x250973C0: return find_animation; 33 case 0x25097550: return sub_25097550; 34 case 0x250975A0: return sub_250975A0; 35 case 0x250975D0: return sub_250975D0; 36 case 0x250975F0: return sub_250975F0; 37 default: abort(); 38 } 39 } 40 41 static void fixture(unsigned direction, unsigned previous, unsigned current, unsigned actual) 42 { 43 memset((void *)ADDR(0x50000000), 0, 0x10000); 44 MEM32(0x3616FFE8) = 1; 45 MEM32(0x3616F980) = 0x250975F0; 46 MEM32(0x3616F990) = 0x250975A0; 47 MEM32(0x3616F984) = 0x250975D0; 48 MEM32(0x3616F974) = 0x25097550; 49 recomp_yield_hook = NULL; 50 lookups = 0; 51 52 /* One mesh with a circular animation list and a three-event iterator. */ 53 MEM32(0x50000000) = 0x50000100; 54 MEM32(0x50000120) = 0x50000200; 55 MEM32(0x50000204) = 0x50000300; 56 MEM32(0x50000300) = 0x50000400; 57 MEM32(0x50000400) = 0x50000300; 58 MEM32(0x50000408) = 0x50000500; 59 MEM32(0x50000510) = 7; 60 MEM32(0x50000524) = direction; 61 MEM32(0x50000544) = previous; 62 MEM32(0x50000540) = current; 63 MEM32(0x5000053C) = actual; 64 MEM32(0x50000600) = 7; 65 MEM32(0x50000604) = -1; 66 MEM32(0x50000618) = 0; 67 MEM32(0x5000061C) = 40; 68 MEM32(0x5000062C) = 3; 69 MEM32(0x50000638) = 0x50000700; 70 for (unsigned i = 0; i < 3; ++i) { 71 MEM32(0x50000720 + i * 0x28) = 101 + i; 72 MEM32(0x50000724 + i * 0x28) = 10 + i * 10; 73 } 74 } 75 76 static unsigned next_event(recomp_func_t function) 77 { 78 g_ecx = 0x50000600; 79 g_esp = 0x5000ff00; 80 MEM32(g_esp + 4) = 0x50000000; 81 g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444; 82 function(); 83 assert(g_esp == 0x5000ff08); 84 assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444); 85 return g_eax; 86 } 87 88 static void test_forward(unsigned fallback) 89 { 90 fixture(0, 5, 25, 25); 91 if (fallback == 1) recomp_yield_hook = yield; 92 if (fallback == 2) MEM32(0x3616F980) = 2; 93 94 unsigned first = next_event(sub_3604F180); 95 unsigned first_lookups = lookups; 96 unsigned second = next_event(sub_3604F180); 97 unsigned end = next_event(sub_3604F180); 98 99 assert(first == 101 && second == 102 && end == UINT32_MAX); 100 assert(first_lookups == (fallback ? 5 : 1)); 101 assert(MEM32(0x50000630) == 2 && MEM32(0x50000634) == 3); 102 } 103 104 static void test_reverse(void) 105 { 106 fixture(1, 25, 5, 5); 107 108 unsigned first = next_event(sub_3604F180); 109 unsigned second = next_event(sub_3604F180); 110 unsigned end = next_event(sub_3604F180); 111 112 assert(first == 102 && second == 101 && end == UINT32_MAX); 113 } 114 115 static void test_wrap(void) 116 { 117 fixture(0, 25, 45, 15); 118 119 unsigned first = next_event(sub_3604F180); 120 unsigned second = next_event(sub_3604F180); 121 unsigned end = next_event(sub_3604F180); 122 123 assert(first == 103 && second == 101 && end == UINT32_MAX); 124 } 125 126 static void test_absent(unsigned kind) 127 { 128 fixture(0, 5, 25, 25); 129 if (kind == 0) MEM32(0x50000600) = 8; 130 if (kind == 1) MEM32(0x50000300) = 0x50000300; 131 if (kind == 2) MEM32(0x5000062C) = 0; 132 if (kind == 3) MEM32(0x50000000) = 0; 133 134 unsigned event = next_event(sub_3604F180); 135 136 assert(event == UINT32_MAX); 137 } 138 139 static void test_negative_id(void) 140 { 141 fixture(0, 5, 25, 25); 142 MEM32(0x50000510) = MEM32(0x50000600) = -2; 143 144 next_event(sub_3604F180); 145 146 assert(MEM32(0x50000620) == 5); 147 assert(MEM32(0x50000624) == 0); 148 assert(MEM32(0x50000628) == 25); 149 } 150 151 int main(void) 152 { 153 assert(guest_map("animation event fixture", 0x50000000, 0x10000)); 154 assert(guest_map("animation imports", 0x36160000, 0x10000)); 155 test_forward(0); 156 test_forward(1); 157 test_forward(2); 158 test_reverse(); 159 test_wrap(); 160 for (unsigned i = 0; i < 4; ++i) test_absent(i); 161 test_negative_id(); 162 puts("animation events: forward, reverse, wrap, absent, negative ID and fallback checks pass"); 163 }