client/tests/player_voice.c (2895B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_3A007940(void); 5 void sub_3A002F50(void); 6 7 static unsigned formats, lookups, scheduled; 8 9 /* Keep native formatting/cache selection; observe its existing sound boundary. */ 10 static void format_filename(void) 11 { 12 assert(!strcmp((char *)ADDR(MEM32(g_esp + 8)), "sfx\\Player\\%s")); 13 g_eax = sprintf((char *)ADDR(MEM32(g_esp + 4)), "sfx\\Player\\%s", 14 (char *)ADDR(MEM32(g_esp + 12))); 15 ++formats; 16 g_esp += 4; 17 } 18 19 static void hash_filename(void) 20 { 21 assert(!strncmp((char *)ADDR(MEM32(g_esp + 4)), "sfx\\Player\\", 11)); 22 g_eax = 123; 23 g_esp += 4; 24 } 25 26 static void find_sound(void) 27 { 28 assert(g_ecx == 0x50001000 && MEM32(g_esp + 4) == 123); 29 ++lookups; 30 g_eax = 0x50002000; 31 g_esp += 8; 32 } 33 34 static void schedule_sound(void) 35 { 36 assert(g_ecx == 0x50001000 && MEM32(g_esp + 4) == 0x50002000); 37 assert(*(float *)ADDR(g_esp + 8) == 0.375f); 38 ++scheduled; 39 g_esp += 60; 40 } 41 42 recomp_func_t recomp_lookup(uint32_t address) 43 { 44 switch (address) { 45 case 0x3a002f50: return sub_3A002F50; 46 case 0x3a0022e0: return hash_filename; 47 case 0x3a002300: return find_sound; 48 case 0x3a002360: return schedule_sound; 49 case 0x70000000: return format_filename; 50 default: fprintf(stderr, "unexpected player voice call %08x\n", address); abort(); 51 } 52 } 53 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 54 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 55 56 static void test_filename(unsigned length) 57 { 58 memset((void *)ADDR(0x51000000), 'a', length); 59 memcpy((void *)ADDR(0x51000000 + length - 4), ".wav", 5); 60 formats = lookups = scheduled = 0; 61 g_esp = 0x50008000; 62 MEM32(g_esp) = 0; 63 MEM32(g_esp + 4) = 0x51000000; 64 *(float *)ADDR(g_esp + 8) = 0.75f; 65 g_ebx = 11; g_esi = 22; g_edi = 33; g_ebp = 44; 66 g_fs_base = 0x52000000; 67 MEM32(g_fs_base) = 55; 68 g_fp_top = 0; 69 70 sub_3A007940(); 71 72 assert(formats == (length <= 248)); 73 assert(lookups == (length <= 248) && scheduled == (length <= 248)); 74 assert(g_esp == 0x50008004 && g_ebx == 11 && g_esi == 22 && g_edi == 33 && g_ebp == 44); 75 assert(MEM32(g_fs_base) == 55 && g_fp_top == 0); 76 } 77 78 int main(void) 79 { 80 assert(guest_map("player voice globals", 0x3a000000, 0x10000)); 81 assert(guest_map("player voice fixture", 0x50000000, 0x10000)); 82 assert(guest_map("player voice filename", 0x51000000, 0x10000)); 83 assert(guest_map("player voice exceptions", 0x52000000, 0x10000)); 84 MEM32(0x3a00d2ec) = 0x50001000; 85 *(float *)ADDR(0x3a00d280) = 0.5f; 86 MEM32(0x3a00a058) = 0x70000000; 87 strcpy((char *)ADDR(0x3a00d044), "sfx\\Player\\%s"); 88 test_filename(4); 89 test_filename(248); 90 test_filename(249); 91 test_filename(2048); 92 test_filename(65535); 93 puts("player voice: native filename boundary, volume, cache scheduling and ABI passed"); 94 }