client/tests/terrain_texture.c (3700B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_2504E0D0(void); 5 static unsigned width, bytes_per_pixel, allocations, submissions; 6 7 static void allocate(void) 8 { 9 unsigned size = MEM32(g_esp + 4); 10 assert(size == (allocations ? 20 : width * width * bytes_per_pixel)); 11 g_eax = allocations++ ? 0x53004000 : 0x51010000 - size; 12 g_esp += 4; 13 } 14 static void empty(void) { g_esp += 4; } 15 static void construct(void) { g_eax = g_ecx; g_esp += 4; } 16 static void copy(void) { g_esp += 8; } 17 static void valid(void) { g_eax = 1; g_esp += 4; } 18 static void stride(void) { g_eax = width * bytes_per_pixel; g_esp += 4; } 19 static void pixels(void) 20 { 21 g_eax = 0x50010000 - width * width * bytes_per_pixel; 22 g_esp += 4; 23 } 24 static void format(void) { g_eax = 32; g_esp += 4; } 25 static void create(void) { g_eax = 0x53005000; g_esp += 4; } 26 static void submit(void) 27 { 28 assert(g_ecx == 0x53005000); 29 assert(MEM32(g_esp + 4) == 0x51010000 - width * width * bytes_per_pixel); 30 ++submissions; 31 g_esp += 28; 32 } 33 34 recomp_func_t recomp_lookup(uint32_t address) 35 { 36 switch (address) { 37 case 0x251380D0: return allocate; 38 case 0x2504B530: return construct; 39 case 0x2504B5F0: return copy; 40 case 0x2504B630: case 0x25137EEC: return empty; 41 case 0x25094220: return valid; 42 case 0x2504B6B0: return stride; 43 case 0x2511C620: return pixels; 44 case 0x25051020: return format; 45 case 0x25050FA0: return create; 46 case 0x250EBC10: return submit; 47 default: fprintf(stderr, "Unexpected terrain-texture call %08x\n", address); abort(); 48 } 49 } 50 recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); } 51 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 52 53 int main(void) 54 { 55 for (unsigned i = 0; i < 4; ++i) 56 assert(guest_map("terrain texture", 0x50000000 + i * 0x1000000, 0x10000)); 57 const unsigned sizes[][2] = {{1, 4}, {2, 4}, {1, 3}, {2, 3}, {1, 1}, {2, 1}}; 58 /* Tile orientation zero flips the source rows. */ 59 const unsigned char expected[][16] = { 60 {1, 2, 3, 4}, {9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8}, 61 {1, 2, 3}, {7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6}, 62 {1}, {3, 4, 1, 2} 63 }; 64 for (unsigned i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) { 65 width = sizes[i][0]; bytes_per_pixel = sizes[i][1]; 66 unsigned length = width * width * bytes_per_pixel; 67 memset((void *)ADDR(0x51000000), 0xa5, 0x10000); 68 for (unsigned j = 0; j < length; ++j) MEM8(0x50010000 - length + j) = j + 1; 69 memset((void *)ADDR(0x53000000), 0, 0x10000); 70 MEM32(0x53000038) = 1; 71 MEM32(0x53000050) = 0x53002000; 72 MEM32(0x53002034) = 0x53003000; 73 MEM32(0x5300005c) = 0x53006000; 74 MEM32(0x53000060) = 0x53006004; 75 MEM32(0x53000074) = bytes_per_pixel * 8; 76 g_fs_base = 0x53001000; MEM32(g_fs_base) = 0xffffffff; 77 g_esp = 0x5200ff00; g_ecx = 0x53000000; 78 MEM32(g_esp + 4) = 0; MEM32(g_esp + 8) = 0; 79 MEM32(g_esp + 12) = width; MEM32(g_esp + 16) = 1; 80 g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456; 81 allocations = submissions = 0; 82 83 sub_2504E0D0(); 84 85 assert(allocations == 2 && submissions == 1); 86 assert(g_eax == 0x53005000 && g_esp == 0x5200ff14); 87 assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456); 88 assert(MEM32(g_fs_base) == 0xffffffff); 89 for (unsigned j = 0; j < length; ++j) 90 assert(MEM8(0x51010000 - length + j) == expected[i][j]); 91 assert(MEM8(0x51010000 - length - 1) == 0xa5); 92 } 93 puts("terrain texture: page-ending tiles, copied bytes, submission, canary, FS and ABI passed"); 94 }