aorecomp

Anarchy Online classic in the browser

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


client/tests/bitmap_clear.c (2682B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_250AF340(void);
      5 
      6 /* Color conversion is independent of the bitmap's addressing and row fills. */
      7 static void convert_color(void)
      8 {
      9     g_eax = MEM32(g_esp + 4);
     10     g_esp += 8;
     11 }
     12 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     13 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     14 recomp_func_t recomp_lookup(uint32_t address)
     15 {
     16     assert(address == 0x250d84e0);
     17     return convert_color;
     18 }
     19 
     20 int main(void)
     21 {
     22     assert(guest_map("bitmap pixels", 0x50000000, 0x80000));
     23     assert(guest_map("bitmap and stack", 0x51000000, 0x10000));
     24     const struct {
     25         unsigned width, height, pitch, depth, format, opaque, expected;
     26     } cases[] = {
     27         {480, 480, 960, 2, 0, 1, 0x1234},
     28         {2, 2, 4, 2, 0, 1, 0x1234},
     29         {1, 2, 2, 2, 0, 1, 0x1234},
     30         {3, 2, 6, 2, 0, 1, 0x1234},
     31         {2, 2, 8, 2, 0, 1, 0x1234},
     32         {2, 2, 4, 2, 2, 0, 0x9234},
     33         {2, 2, 4, 2, 2, 1, 0x1234},
     34         {2, 2, 8, 4, 0, 1, 0x1234},
     35         {2, 2, 16, 4, 0, 1, 0x1234},
     36         {0, 2, 0, 2, 0, 1, 0x1234},
     37         {2, 0, 4, 2, 0, 1, 0x1234},
     38     };
     39     for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
     40         unsigned size = cases[i].height * cases[i].pitch;
     41         uint32_t pixels = 0x50080000 - size;
     42         memset((void *)ADDR(0x50000000), 0xa5, 0x80000);
     43         MEM32(0x51000000) = pixels;
     44         MEM32(0x51000008) = cases[i].height;
     45         MEM32(0x5100000c) = cases[i].width;
     46         MEM32(0x51000020) = cases[i].pitch;
     47         MEM32(0x51000024) = cases[i].depth;
     48         MEM32(0x5100002c) = cases[i].format;
     49         g_ecx = 0x51000000;
     50         g_esp = 0x5100ff00;
     51         g_ebp = 123; g_ebx = 234; g_esi = 345; g_edi = 456;
     52         MEM32(g_esp + 4) = 0;
     53         MEM32(g_esp + 8) = 0x1234;
     54         MEM32(g_esp + 12) = cases[i].opaque;
     55 
     56         sub_250AF340();
     57 
     58         assert(g_esp == 0x5100ff10 && g_ebp == 123);
     59         assert(g_ebx == 234 && g_esi == 345 && g_edi == 456);
     60         assert(MEM8(pixels - 1) == 0xa5);
     61         for (unsigned y = 0; y < cases[i].height; ++y) {
     62             for (unsigned x = 0; x < cases[i].width; ++x) {
     63                 uint32_t pixel = pixels + y * cases[i].pitch + x * cases[i].depth;
     64                 if (cases[i].depth == 2) assert(MEM16(pixel) == cases[i].expected);
     65                 else assert(MEM32(pixel) == cases[i].expected);
     66             }
     67             for (unsigned x = cases[i].width * cases[i].depth; x < cases[i].pitch; ++x)
     68                 assert(MEM8(pixels + y * cases[i].pitch + x) == 0xa5);
     69         }
     70     }
     71     puts("bitmap clear: page boundary, odd/even widths, row padding, empty images and alpha passed");
     72 }