aorecomp

Anarchy Online classic in the browser

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


client/tests/ground_height.c (3601B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_25040840(void);
      5 void sub_25040CB0(void);
      6 
      7 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
      8 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
      9 recomp_func_t recomp_lookup(uint32_t address) { abort(); }
     10 
     11 static void setup(void)
     12 {
     13     memset((void *)ADDR(0x50000000), 0xa5, 0x20000);
     14     g_eax = 0x12345678; g_ebx = 0x23456789; g_edx = 0x34567890;
     15     g_esi = 0x45678901; g_edi = 0x56789012; g_ebp = 0x67890123;
     16     g_ecx = 0x50002000; g_esp = 0x5001f000;
     17     g_flag_k = FK_CMP; g_flag_a = 12; g_flag_b = 34; g_flag_cf = 1;
     18     g_fp_top = 3;
     19     for (unsigned i = 0; i < 8; ++i) {
     20         g_st[i] = i + .375;
     21         g_st_i64[i] = INT64_MAX - i;
     22     }
     23 
     24     /* Two resident patches with a 65-sample row, including the border. */
     25     MEM32(0x50002024) = 0x1234beef;
     26     MEM8(0x50002029) = 1;
     27     MEM32(0x50002038) = 64;
     28     MEM32(0x5000203c) = 6;
     29     MEM32(0x50002040) = 63;
     30     MEM32(0x50002048) = 3;
     31     MEM32(0x50002050) = 0x50003000;
     32     MEM32(0x5000301c) = 0x50005000;
     33     MEM32(0x50003070) = 0x50007400;
     34 }
     35 
     36 static void check_preserved_state(void)
     37 {
     38     assert(g_ebx == 0x23456789 && g_esi == 0x45678901);
     39     assert(g_edi == 0x56789012 && g_ebp == 0x67890123);
     40     assert(MEM32(0x5001effc) == 0x67890123);
     41     assert(MEM32(0x5001efe4) == 0x23456789);
     42     assert(MEM32(0x5001efe0) == 0x45678901);
     43     assert(MEM32(0x5001efdc) == 0x56789012);
     44     assert(g_fp_top == 3);
     45     for (unsigned i = 0; i < 8; ++i) {
     46         assert(g_st[i] == i + .375);
     47         assert(g_st_i64[i] == INT64_MAX - i);
     48     }
     49 }
     50 
     51 static void height_crosses_patch_boundary(unsigned full)
     52 {
     53     setup();
     54     MEM8(0x50002029) = full;
     55     MEM32(g_esp + 4) = 65;
     56     MEM32(g_esp + 8) = 2;
     57     MEM16(0x50007506) = 0xabcd;
     58 
     59     sub_25040840();
     60 
     61     assert(g_eax == (full ? 0xabcd : 0xab));
     62     assert(g_ecx == 0x50007400);
     63     assert(g_edx == (full ? 0x1234beef : 131));
     64     assert(g_esp == 0x5001f00c);
     65     assert(MEM32(0x5000306c) == 0x1234beef);
     66     assert(MEM32(0x50003018) == 0xa5a5a5a5);
     67     assert(MEM32(0x5001f004) == (full ? 1 : 65));
     68     assert(MEM32(0x5001f008) == 0x50003054);
     69     if (full) {
     70         assert(g_flag_k == FK_ADD && g_flag_a == 130 && g_flag_b == 1);
     71         assert(g_flag_cf == 0);
     72     } else {
     73         assert(g_flag_k == FK_EFLAGS && g_flag_a == 0x203 && g_flag_b == 0);
     74         assert(g_flag_cf == 1);
     75         assert(MEM32(0x5001eff0) == 2);
     76         assert(MEM32(0x5001efec) == 1);
     77         assert(MEM32(0x5001efe8) == 0x50003054);
     78     }
     79     check_preserved_state();
     80 }
     81 
     82 static void raw_height_reads_border(unsigned stamp_alias)
     83 {
     84     setup();
     85     MEM32(g_esp + 4) = 0x50003000;
     86     MEM32(g_esp + 8) = 64;
     87     MEM32(g_esp + 12) = 64;
     88     MEM16(0x50007100) = 0xabcd;
     89     if (stamp_alias)
     90         MEM32(0x5000301c) = 0x50000f18;
     91 
     92     sub_25040CB0();
     93 
     94     assert(g_eax == (stamp_alias ? 0x5000beef : 0x5000abcd));
     95     assert(g_ecx == (stamp_alias ? 0x50000f18 : 0x50005000));
     96     assert(g_edx == 4224 && g_esp == 0x5001f010);
     97     assert(MEM32(0x50003018) == 0x1234beef);
     98     assert(MEM32(0x5001eff4) == 0x50003000);
     99     assert(MEM32(0x5001efe8) == 0x50002000);
    100     assert(g_flag_k == FK_ADD && g_flag_a == 4160 && g_flag_b == 64);
    101     assert(g_flag_cf == 0);
    102     check_preserved_state();
    103 }
    104 
    105 int main(void)
    106 {
    107     assert(guest_map("ground height fixture", 0x50000000, 0x20000));
    108     height_crosses_patch_boundary(0);
    109     height_crosses_patch_boundary(1);
    110     raw_height_reads_border(0);
    111     raw_height_reads_border(1);
    112     puts("ground height: patch crossing, normalization, border and stamp alias passed");
    113     return 0;
    114 }