aorecomp

Anarchy Online classic in the browser

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


client/tests/weapon_range.c (2124B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_360AAE10(void);
      5 static int32_t item_range, range_modifier;
      6 
      7 static void item_stat(void)
      8 {
      9     assert(MEM32(g_esp + 4) == 287 && MEM32(g_esp + 8) == 2);
     10     g_eax = (uint32_t)item_range;
     11     g_esp += 12;
     12 }
     13 
     14 static void actor_stat(void)
     15 {
     16     assert(MEM32(g_esp + 4) == 380 && MEM32(g_esp + 8) == 0);
     17     g_eax = (uint32_t)range_modifier;
     18     g_esp += 12;
     19 }
     20 
     21 /* The tested values fit int32; retain the native truncation boundary. */
     22 static void integer(void)
     23 {
     24     g_eax = (uint32_t)(int32_t)g_st[0];
     25     fp_pop_impl(g_st, &g_fp_top);
     26     g_esp += 4;
     27 }
     28 
     29 recomp_func_t recomp_lookup(uint32_t address)
     30 {
     31     switch (address) {
     32     case 0x50000300: return item_stat;
     33     case 0x50000304: return actor_stat;
     34     case 0x3615fd8c: return integer;
     35     default: fprintf(stderr, "unexpected range call: %08x\n", address); abort();
     36     }
     37 }
     38 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     39 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     40 
     41 int main(void)
     42 {
     43     assert(guest_map("range fixture", 0x50000000, 0x10000));
     44     assert(guest_map("native range constant", 0x36170000, 0x10000));
     45     MEM32(0x36170894) = 0x3c23d70a;
     46     MEM32(0x5000001c) = 0x50000100;
     47     MEM32(0x50000100) = 0x50000180;
     48     MEM32(0x50000184) = 0x50000300;
     49     MEM32(0x500002e4) = 0x50000190;
     50     MEM32(0x50000194) = 0x50000304;
     51     const struct { int32_t range, modifier, expected; } cases[] = {
     52         {22, 0, 22}, {22, 2, 22}, {22, 5, 23}, {10, 10, 10},
     53         {20, 5, 20}, {22, 50, 32}, {22, 100, 40}, {50, 0, 40},
     54         {2, -100, 0}, {22, -200, -21}
     55     };
     56     for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
     57         item_range = cases[i].range;
     58         range_modifier = cases[i].modifier;
     59         g_esp = 0x5000ff00;
     60         g_ecx = 0x50000000;
     61         g_fp_top = 0;
     62         MEM32(g_esp + 4) = 0x50000200;
     63 
     64         sub_360AAE10();
     65 
     66         assert((int32_t)g_eax == cases[i].expected);
     67         assert(g_esp == 0x5000ff08 && g_fp_top == 0);
     68     }
     69     puts("native weapon range: percent modifier, float rounding, truncation and cap passed");
     70 }