client/tests/mission_waypoint_removal.c (3898B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_2B081BB0(void); 5 void sub_2B083400(void); 6 void sub_250ABCF0(void); 7 enum { bus = 0x50000000, bottom = 0x50000100, compass = 0x50000200, 8 overview = 0x50000300, planet = 0x50000400, local = 0x50000500, 9 identity = 0x50000700 }; 10 static unsigned type, id, received, refreshed, cleared; 11 12 static void get_bus(void) { g_eax = bus; g_esp += 4; } 13 14 static void receive_identity(void) 15 { 16 assert(g_ecx == bus); 17 uint32_t target = MEM32(g_esp + 4); 18 MEM32(target) = type; 19 MEM32(target + 4) = id; 20 ++received; 21 g_esp += 8; 22 } 23 24 static void refresh_planet(void) 25 { 26 assert(g_ecx == (refreshed ? planet : overview)); 27 assert(MEM8(0x2b0ef07c) == 0); 28 ++refreshed; 29 g_esp += 4; 30 } 31 32 static void clear_compass(void) 33 { 34 assert(g_ecx == compass); 35 uint32_t target = MEM32(g_esp + 4); 36 assert(MEM32(target) == type && MEM32(target + 4) == id); 37 MEM8(compass + 0x30) = 0; 38 ++cleared; 39 g_esp += 8; 40 } 41 42 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 43 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 44 recomp_func_t recomp_lookup(uint32_t address) 45 { 46 switch (address) { 47 case 1: return get_bus; 48 case 2: return receive_identity; 49 case 0x2b07e1e0: return refresh_planet; 50 case 0x2b076490: return clear_compass; 51 default: fprintf(stderr, "Unexpected waypoint dependency: %08x\n", address); abort(); 52 } 53 } 54 55 int main(void) 56 { 57 assert(guest_map("waypoint imports", 0x2b0b0000, 0x10000)); 58 assert(guest_map("waypoint globals", 0x2b0e0000, 0x10000)); 59 assert(guest_map("waypoint objects and stack", 0x50000000, 0x10000)); 60 const struct { unsigned type, id, views, removes; } cases[] = { 61 {56003, 17, 1, 1}, {56003, 18, 1, 0}, {56004, 17, 1, 0}, 62 {0, 0, 1, 1}, {0, 17, 1, 0}, {56003, 0, 1, 0}, 63 {56003, 17, 0, 1}, {56003, 18, 0, 0}, 64 }; 65 for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) { 66 type = cases[i].type; 67 id = cases[i].id; 68 received = refreshed = cleared = 0; 69 MEM32(0x2b0b53cc) = 1; 70 MEM32(0x2b0b53ac) = 2; 71 MEM32(0x2b0ef070) = MEM32(compass + 0x14) = 56003; 72 MEM32(0x2b0ef074) = MEM32(compass + 0x18) = 17; 73 MEM8(0x2b0ef07c) = MEM8(compass + 0x30) = 1; 74 MEM32(0x2b0ef078) = cases[i].views ? overview : 0; 75 MEM32(0x2b0ef094) = cases[i].views ? planet : 0; 76 MEM32(0x2b0ef0a4) = cases[i].views ? bottom : 0; 77 MEM32(bottom + 0x3c) = compass; 78 MEM32(local + 0xc0) = 56003; 79 MEM32(local + 0xc4) = 17; 80 MEM8(local + 0xdc) = 1; 81 MEM32(identity) = type; 82 MEM32(identity + 4) = id; 83 g_esp = 0x5000ff00; 84 g_ebp = 123; g_ebx = 234; g_esi = 345; g_edi = 456; 85 g_fp_top = 8; 86 87 sub_2B081BB0(); 88 assert(g_esp == 0x5000ff04); 89 g_esp = 0x5000ff00; 90 sub_2B083400(); 91 assert(g_esp == 0x5000ff04); 92 g_esp = 0x5000ff00; 93 MEM32(g_esp + 4) = identity; 94 g_ecx = local; 95 sub_250ABCF0(); 96 97 assert(MEM8(0x2b0ef07c) == !cases[i].removes); 98 assert(MEM8(compass + 0x30) == !(cases[i].removes && cases[i].views)); 99 assert(received == 1 + cases[i].views); 100 assert(refreshed == 2 * cases[i].removes * cases[i].views); 101 assert(cleared == cases[i].removes * cases[i].views); 102 assert(MEM32(0x2b0ef070) == 56003 && MEM32(0x2b0ef074) == 17); 103 assert(MEM32(compass + 0x14) == 56003 && MEM32(compass + 0x18) == 17); 104 assert(MEM8(local + 0xdc) == !cases[i].removes); 105 assert(MEM32(local + 0xc0) == 56003 && MEM32(local + 0xc4) == 17); 106 assert(g_esp == 0x5000ff08 && g_ebp == 123); 107 assert(g_ebx == 234 && g_esi == 345 && g_edi == 456 && g_fp_top == 8); 108 } 109 puts("mission waypoints: identity/type selection, clear-all, absent views and guest ABI passed"); 110 }