aorecomp

Anarchy Online classic in the browser

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


client/tests/loading_fade.c (2315B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_2B03A030(void);
      5 static unsigned redirected, removed, alpha_calls, hide_scene;
      6 static float alpha;
      7 
      8 static void timer(void) { g_eax = 0x50001000; g_esp += 4; }
      9 static void instance(void) { g_eax = 0x50002000; g_esp += 4; }
     10 static void set_alpha(void)
     11 {
     12     alpha = (*(float *)ADDR(g_esp + 4));
     13     hide_scene = MEM32(g_esp + 8);
     14     ++alpha_calls;
     15     g_esp += 4;
     16 }
     17 static void remove_program(void) { removed = MEM32(g_esp + 4); g_esp += 8; }
     18 static void redirect(void) { ++redirected; g_esp += 4; }
     19 
     20 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     21 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     22 recomp_func_t recomp_lookup(uint32_t address)
     23 {
     24     switch (address) {
     25     case 1: return timer;
     26     case 2: return instance;
     27     case 3: return remove_program;
     28     case 4: return redirect;
     29     case 0x2B039F80: return set_alpha;
     30     default: abort();
     31     }
     32 }
     33 
     34 int main(void)
     35 {
     36     assert(guest_map("loading state", 0x2b000000, 0x100000));
     37     assert(guest_map("loading test", 0x50000000, 0x10000));
     38     MEM32(0x2b0b53bc) = 1;
     39     MEM32(0x2b0b53cc) = MEM32(0x2b0b5f70) = 2;
     40     MEM32(0x2b0b5394) = 3; MEM32(0x2b0b5f64) = 4;
     41     (*(float *)ADDR(0x2b0b63d0)) = 1.0f;
     42     for (unsigned opening = 0; opening < 2; ++opening) {
     43         MEM8(0x2b0ee96c) = 1;
     44         MEM8(0x2b0e6d0c) = opening;
     45         (*(float *)ADDR(0x2b0ee970)) = 1000.0f;
     46         MEM32(0x50001024) = 1075;
     47         g_esp = 0x5000ff00; g_ebp = 123;
     48         redirected = removed = alpha_calls = 0;
     49 
     50         sub_2B03A030();
     51 
     52         assert(alpha == 0.5f && alpha_calls == 1);
     53         assert(hide_scene == !opening && redirected == 0 && removed == 0);
     54         assert(MEM8(0x2b0ee96c) == 1);
     55         assert(g_esp == 0x5000ff04 && g_ebp == 123);
     56 
     57         /* Complete the fade, then verify that subsequent frames are inactive. */
     58         MEM32(0x50001024) = 1151;
     59         g_esp = 0x5000ff00;
     60         sub_2B03A030();
     61         assert(alpha == (opening ? 1.0f : 0.0f) && alpha_calls == 2);
     62         assert(removed == (opening ? 7 : 6) && redirected == opening);
     63         assert(MEM8(0x2b0ee96c) == 0);
     64         assert(g_esp == 0x5000ff04 && g_ebp == 123);
     65         g_esp = 0x5000ff00;
     66         sub_2B03A030();
     67         assert(alpha_calls == 2 && redirected == opening);
     68     }
     69 }