aorecomp

Anarchy Online classic in the browser

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


client/tests/image_row.c (1877B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 #ifdef _WIN32
      4 #include <windows.h>
      5 #endif
      6 
      7 void sub_250CB6E0(void);
      8 void sub_37012DA0(void);
      9 recomp_func_t recomp_lookup(uint32_t address) { abort(); }
     10 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     11 recomp_func_t recomp_lookup_manual(uint32_t address) { abort(); }
     12 
     13 int main(void)
     14 {
     15     for (unsigned i = 0; i < 4; ++i) {
     16         uint32_t address = 0x50000000u + i * 0x1000000u;
     17 #ifdef _WIN32
     18         assert(VirtualAlloc((void *)(uintptr_t)address, 0x10000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == (void *)(uintptr_t)address);
     19 #else
     20         assert(guest_map("image row test", address, 0x10000));
     21 #endif
     22     }
     23     const unsigned lengths[] = {0, 1, 2, 3, 4, 7, 8, 2048};
     24     for (unsigned decoder = 0; decoder < 2; ++decoder)
     25     for (unsigned i = 0; i < sizeof(lengths) / sizeof(lengths[0]); ++i) {
     26         unsigned length = lengths[i];
     27         uint32_t input = 0x50010000 - length, output = 0x51010000 - length;
     28         memset((void *)ADDR(0x51000000), 0xa5, 0x10000);
     29         for (unsigned j = 0; j < length; ++j) MEM8(input + j) = j * 13 + 7;
     30         MEM32(0x520000f8) = input - 1;
     31         MEM32(0x520000d4) = length;
     32         MEM8(0x52000117) = 8;
     33         g_esp = 0x5300ff00;
     34         MEM32(g_esp + 4) = 0x52000000;
     35         MEM32(g_esp + 8) = output;
     36         MEM32(g_esp + 12) = 255;
     37         g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
     38 
     39         if (decoder == 0) sub_250CB6E0();
     40         else sub_37012DA0();
     41 
     42         assert(g_esp == 0x5300ff04);
     43         assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
     44         for (unsigned j = 0; j < length; ++j) assert(MEM8(output + j) == (unsigned char)(j * 13 + 7));
     45         assert(MEM8(output - 1) == 0xa5);
     46     }
     47     puts("image row: 2 decoders, 8 boundary-ending copies each, including zero length; bytes, canaries and ABI passed");
     48 }