client/tests/vertex_initialization.c (2804B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_250F5C40(void); 5 static unsigned locks, unlocks; 6 7 static void retain(void) { g_esp += 4; } 8 9 static void resize_sections(void) 10 { 11 assert(g_ecx == 0x5000000c); 12 MEM32(g_ecx) = MEM32(g_esp + 4); 13 MEM32(g_ecx + 4) = 0x50000100; 14 g_esp += 8; 15 } 16 17 static void resize_parts(void) 18 { 19 assert(g_ecx == 0x50000104); 20 MEM32(g_ecx) = MEM32(g_esp + 4); 21 MEM32(g_ecx + 4) = 0x50000200; 22 g_esp += 8; 23 } 24 25 static void create_vertices(void) 26 { 27 assert(g_ecx == 0x50000200); 28 assert(MEM32(g_esp + 4) == 2); 29 memset((void *)ADDR(0x50008000), 0xa5, 64); 30 g_esp += 8; 31 } 32 33 static void lock_vertices(void) 34 { 35 assert(g_ecx == 0x50000200); 36 ++locks; 37 g_eax = 0x50008000; 38 g_esp += 4; 39 } 40 41 static void unlock_vertices(void) 42 { 43 assert(g_ecx == 0x50000200); 44 ++unlocks; 45 g_esp += 4; 46 } 47 48 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 49 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 50 recomp_func_t recomp_lookup(uint32_t address) 51 { 52 switch (address) { 53 case 0x250e6360: case 0x70000000: return retain; 54 case 0x250f7470: return resize_sections; 55 case 0x250f73a0: return resize_parts; 56 case 0x250f7270: return create_vertices; 57 case 0x250f72e0: return lock_vertices; 58 case 0x25118ef0: return unlock_vertices; 59 default: fprintf(stderr, "unexpected %08x\n", address); abort(); 60 } 61 } 62 63 static void test_initial_vertices(void) 64 { 65 memset((void *)ADDR(0x50000000), 0, 0x10000); 66 MEM32(0x50000000) = 0x50000900; 67 MEM32(0x50000908) = 0x70000000; 68 MEM32(0x50001040) = 1; 69 MEM32(0x50001044) = 0x50002000; 70 MEM32(0x50002010) = 1; 71 MEM32(0x50002014) = 0x50003000; 72 MEM32(0x50003008) = 2; 73 MEM32(0x5000300c) = 0x50004000; 74 const float vertices[] = { 75 11,12,13, 14,15,16, -7,8,9, 0,1,0, .25f,.5f, 0,0,1, 76 21,22,23, 24,25,26, 17,-18,19, 1,0,0, .75f,1, 0,0,1, 77 }; 78 memcpy((void *)ADDR(0x50004000), vertices, sizeof(vertices)); 79 g_ecx = 0x50000000; 80 g_esp = 0x5000ff00; 81 MEM32(g_esp + 4) = 0x50001000; 82 g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444; 83 locks = unlocks = 0; 84 85 sub_250F5C40(); 86 87 const float expected[] = {-7,8,9, 0,1,0, .25f,.5f, 88 17,-18,19, 1,0,0, .75f,1}; 89 assert(!memcmp((void *)ADDR(0x50008000), expected, sizeof(expected))); 90 assert(locks == 1 && unlocks == 1); 91 assert(MEM32(0x50000004) == 0x50001000); 92 assert(MEM32(0x50000024) == 1); 93 assert(g_esp == 0x5000ff08); 94 assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444); 95 } 96 97 int main(void) 98 { 99 assert(guest_map("vertex initialization fixture", 0x50000000, 0x10000)); 100 test_initial_vertices(); 101 puts("vertex initialization: complete bind pose before animation passed"); 102 }