client/tests/shop_empty_total.c (3580B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_3601E2E0(void); 5 enum { transaction = 0x50000000, list = 0x50000100, sentinel = 0x50000200, 6 first = 0x50000300, second = 0x50000340, source = 0x50000400 }; 7 static unsigned releases, notifications; 8 static uint32_t expected_quote; 9 10 static void release_row(void) 11 { 12 assert(MEM32(g_esp + 4) == first); 13 ++releases; 14 g_esp += 4; 15 } 16 17 static void selection_changed(void) 18 { 19 assert(g_ecx == transaction); 20 assert(MEM32(transaction + 0x14) == expected_quote); 21 ++notifications; 22 g_esp += 4; 23 } 24 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 0x3615fcc4: return release_row; 31 case 0x3601e450: return selection_changed; 32 default: fprintf(stderr, "Unexpected shop selection dependency: %08x\n", address); abort(); 33 } 34 } 35 36 int main(void) 37 { 38 assert(guest_map("shop selection and stack", 0x50000000, 0x10000)); 39 const struct { 40 uint32_t total, price; 41 unsigned quantity, rows; 42 uint32_t expected_total; 43 unsigned expected_rows, expected_quantity, found; 44 } cases[] = { 45 {230, 228, 1, 1, 0, 0, 0, 1}, 46 {228, 230, 1, 1, 0, 0, 0, 1}, 47 {460, 228, 2, 1, 232, 1, 1, 1}, 48 {460, 228, 1, 2, 232, 1, 0, 1}, 49 {230, 228, 1, 1, 230, 1, 1, 0}, 50 {0, 228, 0, 0, 0, 0, 0, 0}, 51 }; 52 for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) { 53 memset((void *)ADDR(transaction), 0, 0x10000); 54 releases = notifications = 0; 55 expected_quote = cases[i].expected_total; 56 MEM32(transaction + 0x10) = list; 57 MEM32(transaction + 0x14) = cases[i].total; 58 MEM32(list + 4) = sentinel; 59 MEM32(list + 8) = cases[i].rows; 60 MEM32(sentinel) = cases[i].rows ? first : sentinel; 61 MEM32(sentinel + 4) = cases[i].rows == 2 ? second : cases[i].rows ? first : sentinel; 62 MEM32(first) = cases[i].rows == 2 ? second : sentinel; 63 MEM32(first + 4) = sentinel; 64 MEM32(first + 8) = 111; 65 MEM32(first + 12) = 1; 66 MEM16(first + 0x18) = cases[i].quantity; 67 MEM32(second) = sentinel; 68 MEM32(second + 4) = first; 69 MEM32(second + 8) = 111; 70 MEM32(second + 12) = 2; 71 MEM16(second + 0x18) = 1; 72 MEM32(source) = 111; 73 MEM32(source + 4) = cases[i].found ? 1 : 9; 74 g_ecx = transaction; 75 g_esp = 0x5000ff00; 76 g_ebp = 123; g_ebx = 234; g_esi = 345; g_edi = 456; 77 g_fp_top = 8; 78 MEM32(g_esp + 4) = source; 79 MEM32(g_esp + 8) = cases[i].price; 80 81 sub_3601E2E0(); 82 83 assert(MEM32(transaction + 0x14) == cases[i].expected_total); 84 assert(MEM32(list + 8) == cases[i].expected_rows); 85 assert((g_eax & 255) == cases[i].found); 86 assert(notifications == cases[i].found); 87 assert(releases == (cases[i].found && cases[i].quantity == 1)); 88 if (cases[i].expected_quantity) assert(MEM16(first + 0x18) == cases[i].expected_quantity); 89 if (!cases[i].expected_rows) assert(MEM32(sentinel) == sentinel && MEM32(sentinel + 4) == sentinel); 90 if (cases[i].rows == 2) assert(MEM32(sentinel) == second && MEM32(second + 4) == sentinel); 91 assert(g_esp == 0x5000ff0c && g_ebp == 123); 92 assert(g_ebx == 234 && g_esi == 345 && g_edi == 456 && g_fp_top == 8); 93 } 94 puts("shop empty total: positive/negative residue, quantities, other rows, misses and ABI passed"); 95 }