aorecomp

Anarchy Online classic in the browser

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


client/tests/animation_transform.c (4306B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_25096DD0(void), sub_25096D20(void), sub_25096DC0(void), sub_250E34E0(void);
      5 static unsigned callbacks, custom_callbacks;
      6 static uint32_t callback_frames[4], callback_masks[4], callback_dirty[4];
      7 
      8 static void manager(void)
      9 {
     10     g_eax = 0x50005000;
     11     g_esp += 4;
     12 }
     13 
     14 static void invalidate(void)
     15 {
     16     assert(callbacks < 4);
     17     callback_frames[callbacks] = g_ecx;
     18     callback_masks[callbacks] = MEM32(g_esp + 4);
     19     callback_dirty[callbacks++] = MEM8(g_ecx + 0x132);
     20     sub_250E34E0();
     21 }
     22 
     23 static void custom_invalidate(void)
     24 {
     25     ++custom_callbacks;
     26     invalidate();
     27 }
     28 
     29 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     30 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     31 recomp_func_t recomp_lookup(uint32_t address)
     32 {
     33     switch (address) {
     34     case 0x25096d20: return sub_25096D20;
     35     case 0x25096dc0: return sub_25096DC0;
     36     case 0x2507f900: return manager;
     37     case 0x250e34e0: return invalidate;
     38     case 1: return custom_invalidate;
     39     default: abort();
     40     }
     41 }
     42 
     43 static void test_transform(unsigned shape, unsigned dirty, unsigned changes, uint32_t value)
     44 {
     45     memset((void *)ADDR(0x50000000), 0, 0x10000);
     46     callbacks = custom_callbacks = 0;
     47     uint32_t frame = 0x5000103c;
     48     MEM32(0x50000028) = 0x50001000;
     49     MEM32(frame) = MEM32(0x50002000) = 0x50003000;
     50     MEM32(0x5000302c) = shape & 4 ? 1 : 0x250e34e0;
     51     MEM32(frame + 0x6c) = shape & 1 ? 0x50004000 : 0;
     52     MEM32(0x50004074) = shape & 1 ? frame : 0;
     53     MEM32(frame + 0x74) = shape & 2 ? 0x50002000 : 0;
     54     MEM8(frame + 0x132) = dirty;
     55     MEM8(frame + 0x130) = 0x84;
     56     MEM8(frame + 0x131) = 0x42;
     57     for (unsigned i = 0; i < 3; i++) MEM32(frame + 0x78 + i * 4) = MEM32(0x50008000 + i * 4) = value;
     58     for (unsigned i = 0; i < 4; i++) MEM32(frame + 0x84 + i * 4) = MEM32(0x50008020 + i * 4) = value;
     59     if (changes & 1) MEM32(0x50008004) ^= 1;
     60     if (changes & 2) MEM32(0x50008028) ^= 1;
     61 
     62     /* An empty animation list keeps the real driver focused on the transform. */
     63     MEM32(0x50005718) = 0x50006000;
     64     MEM32(0x50000020) = 0x50007000;
     65     MEM32(0x50007004) = 0x50007100;
     66     MEM32(0x50007100) = 0x50007100;
     67     g_ecx = 0x50000000;
     68     g_esp = 0x5000ff00;
     69     MEM32(g_esp + 4) = 0x50008000;
     70     MEM32(g_esp + 8) = 0x50008020;
     71     *(float *)ADDR(g_esp + 12) = .016f;
     72     g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444;
     73     g_fp_top = 8;
     74 
     75     sub_25096DD0();
     76 
     77     int keep_cache = !(shape & 6) && !dirty && !changes;
     78     assert(MEM8(frame + 0x132) == (keep_cache ? 0 : (dirty | 3)));
     79     assert(MEM8(frame + 0x130) == 0x87 && MEM8(frame + 0x131) == 0x42);
     80     assert(!memcmp((void *)ADDR(frame + 0x78), (void *)ADDR(0x50008000), 12));
     81     assert(!memcmp((void *)ADDR(frame + 0x84), (void *)ADDR(0x50008020), 16));
     82     assert(callbacks == (shape & 2 ? 4 : 2));
     83     assert(custom_callbacks == (shape & 4 ? callbacks : 0));
     84     assert(callback_frames[0] == frame && callback_masks[0] == 1 && callback_dirty[0] == dirty);
     85     unsigned second = shape & 2 ? 2 : 1;
     86     assert(callback_frames[second] == frame && callback_masks[second] == 2 && callback_dirty[second] == (dirty | 1));
     87     if (shape & 2) {
     88         assert(callback_frames[1] == 0x50002000 && callback_masks[1] == 1);
     89         assert(callback_frames[3] == 0x50002000 && callback_masks[3] == 2);
     90         assert(MEM8(0x50002132) == 3 && MEM8(0x50002130) == 3);
     91     }
     92     assert(g_eax == UINT32_MAX && g_esp == 0x5000ff10);
     93     assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444);
     94     assert(g_fp_top == 8);
     95 }
     96 
     97 int main(void)
     98 {
     99     assert(guest_map("animation transform fixture", 0x50000000, 0x10000));
    100     assert(guest_map("animation transform constants", 0x25150000, 0x10000));
    101     *(float *)ADDR(0x25152c10) = 1000;
    102     *(double *)ADDR(0x25152f28) = .5;
    103     const uint32_t values[] = {0, 0x80000000, 0x3f800000, 0x7fc00001};
    104     for (unsigned shape = 0; shape < 8; shape++)
    105         for (unsigned dirty = 0; dirty < 16; dirty++)
    106             for (unsigned changes = 0; changes < 4; changes++)
    107                 for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); i++)
    108                     test_transform(shape, dirty, changes, values[i]);
    109     puts("animation transform: 2048 driver cases preserve callbacks, dirty flags and guest ABI");
    110 }