aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/tests/vertex_upload.c (2708B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_250E8790(void);
      5 static unsigned count;
      6 static unsigned submissions;
      7 
      8 static void manager(void) { g_eax = 0x53002000; g_esp += 4; }
      9 static void stride(void) { g_eax = 4; g_esp += 8; }
     10 static void allocate(void)
     11 {
     12     assert(MEM32(g_esp + 8) == 4);
     13     assert(MEM32(g_esp + 12) == count);
     14     MEM32(MEM32(g_esp + 16)) = 0x51010000 - count * 4;
     15     g_eax = 1234;
     16     g_esp += 20;
     17 }
     18 static void buffer(void) { g_eax = 0x53003000; g_esp += 8; }
     19 static void submit(void)
     20 {
     21     assert(MEM32(g_esp + 4) == 0x53003000);
     22     assert(MEM32(g_esp + 8) == 1234);
     23     assert(MEM32(g_esp + 12) == count);
     24     assert(MEM32(g_esp + 16) == 7);
     25     ++submissions;
     26     g_eax = 0;
     27     g_esp += 20;
     28 }
     29 
     30 recomp_func_t recomp_lookup(uint32_t address)
     31 {
     32     switch (address) {
     33     case 0x250F7690: return manager;
     34     case 0x25103CB0: return stride;
     35     case 0x250F77E0: return allocate;
     36     case 0x250F7840: return buffer;
     37     case 0x250E7D90: return submit;
     38     default: fprintf(stderr, "Unexpected vertex-upload call %08x\n", address); abort();
     39     }
     40 }
     41 recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); }
     42 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     43 
     44 int main(void)
     45 {
     46     for (unsigned i = 0; i < 4; ++i)
     47         assert(guest_map("vertex upload", 0x50000000 + i * 0x1000000, 0x10000));
     48     assert(guest_map("renderer globals", 0x251B0000, 0x10000));
     49     MEM32(0x251BB840) = 0x100;
     50     MEM32(0x53000000) = 1;
     51     const unsigned counts[] = {1, 0, 2, 3, 512, 16383};
     52     for (unsigned i = 0; i < sizeof(counts) / sizeof(counts[0]); ++i) {
     53         count = counts[i];
     54         unsigned length = count * 4;
     55         uint32_t input = 0x50010000 - length, output = 0x51010000 - length;
     56         memset((void *)ADDR(0x51000000), 0xa5, 0x10000);
     57         for (unsigned j = 0; j < length; ++j) MEM8(input + j) = j * 13 + 7;
     58         g_fs_base = 0x53001000;
     59         MEM32(g_fs_base) = 0xffffffff;
     60         g_esp = 0x5200ff00; g_ecx = 0x53000000;
     61         MEM32(g_esp + 4) = 0x42; MEM32(g_esp + 8) = input;
     62         MEM32(g_esp + 12) = count; MEM32(g_esp + 16) = 7;
     63         g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
     64         submissions = 0;
     65 
     66         sub_250E8790();
     67 
     68         assert(submissions == 1);
     69         assert(g_esp == 0x5200ff14);
     70         assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
     71         assert(MEM32(g_fs_base) == 0xffffffff);
     72         for (unsigned j = 0; j < length; ++j)
     73             assert(MEM8(output + j) == (unsigned char)(j * 13 + 7));
     74         assert(MEM8(output - 1) == 0xa5);
     75     }
     76     puts("vertex upload: 6 page-ending payloads; bytes, submission, canary, FS and ABI passed");
     77 }