aorecomp

Anarchy Online classic in the browser

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


commit 78ca38f7493a52a1c4fdd6691cdcc2e643a94eed
parent 2ca665d99cb769051aceeeee1e2e19f2e490a68d
Author: anon <anon@example.com>
Date:   Fri, 16 Oct 2026 22:20:24 +0000

Avoid translating zero-count vertex copy pointers

Diffstat:
Msrc/Makefile.linux | 9+++++++++
Msrc/game/bbr.dll/lifted-0057.c | 5+++--
Asrc/tests/vertex_upload.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.linux b/src/Makefile.linux @@ -222,6 +222,8 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric ./build/linux/fpu-stack ./build/linux/water-ring ./build/linux/tile-corners + ./build/linux/vertex-upload + ./build/linux/vertex-upload-paged ./build/linux/guest-memory build/linux/surfaces: tests/surfaces.c runtime/linux_graphics.c runtime/linux_window.c runtime/gl_renderer.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/linux_graphics.h runtime/linux_window.h runtime/gl_renderer.h runtime/guest_heap.h runtime/guest_memory.h runtime/recomp_types.h @@ -431,3 +433,10 @@ build/linux/tile-corners: tests/tile_corners.c game/llr.dll/lifted-0021.c game/l $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@ test: build/linux/tile-corners + +# Exercise both native direct addressing and the browser's checked page table. +build/linux/vertex-upload build/linux/vertex-upload-paged: tests/vertex_upload.c game/bbr.dll/lifted-0057.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h + mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) $(if $(filter %-paged,$@),-U__linux__) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@ + +test: build/linux/vertex-upload build/linux/vertex-upload-paged diff --git a/src/game/bbr.dll/lifted-0057.c b/src/game/bbr.dll/lifted-0057.c @@ -8130,7 +8130,8 @@ L_250E87D2: if (2u) _cf = (((ecx) >> 1) & 1u); /* 0x250E8817: shr ecx, 2 */ if (2u) { _flag_a = recomp_flags_pack((ecx >> 2u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } ecx = ecx >> 2u; /* 0x250E8817: shr ecx, 2 */ - { uint32_t _n = ecx, _b = _n * 4u; /* 0x250E881A: rep movsd dword ptr es:[edi], dword ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 4u), (void*)ADDR(esi - _b + 4u), _b); esi -= _b; edi -= _b; } ecx = 0; } + /* A zero-count REP must not translate one-past-the-buffer addresses. */ + if (ecx) { uint32_t _n = ecx, _b = _n * 4u; /* 0x250E881A: rep movsd dword ptr es:[edi], dword ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 4u), (void*)ADDR(esi - _b + 4u), _b); esi -= _b; edi -= _b; } ecx = 0; } ecx = edx; /* 0x250E881C: mov ecx, edx */ edx = MEM32(ebp + (-0x14)); /* 0x250E881E: mov edx, dword ptr [ebp - 0x14] */ _flag_a = (uint32_t)(ecx); _flag_b = (uint32_t)(3); @@ -8139,7 +8140,7 @@ L_250E87D2: _flag_k = FK_TEST; PUSH32(esp, eax); /* 0x250E8824: push eax */ eax = MEM32(ebp + 0x8); /* 0x250E8825: mov eax, dword ptr [ebp + 8] */ - { uint32_t _n = ecx, _b = _n * 1u; /* 0x250E8828: rep movsb byte ptr es:[edi], byte ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 1u), (void*)ADDR(esi - _b + 1u), _b); esi -= _b; edi -= _b; } ecx = 0; } + if (ecx) { uint32_t _n = ecx, _b = _n * 1u; /* 0x250E8828: rep movsb byte ptr es:[edi], byte ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 1u), (void*)ADDR(esi - _b + 1u), _b); esi -= _b; edi -= _b; } ecx = 0; } ecx = MEM32(ebp + 0x10); /* 0x250E882A: mov ecx, dword ptr [ebp + 0x10] */ PUSH32(esp, ecx); /* 0x250E882D: push ecx */ ecx = MEM32(ebp + (-0x18)); /* 0x250E882E: mov ecx, dword ptr [ebp - 0x18] */ diff --git a/src/tests/vertex_upload.c b/src/tests/vertex_upload.c @@ -0,0 +1,77 @@ +#include "recomp_types.h" +#include <assert.h> + +void sub_250E8790(void); +static unsigned count; +static unsigned submissions; + +static void manager(void) { g_eax = 0x53002000; g_esp += 4; } +static void stride(void) { g_eax = 4; g_esp += 8; } +static void allocate(void) +{ + assert(MEM32(g_esp + 8) == 4); + assert(MEM32(g_esp + 12) == count); + MEM32(MEM32(g_esp + 16)) = 0x51010000 - count * 4; + g_eax = 1234; + g_esp += 20; +} +static void buffer(void) { g_eax = 0x53003000; g_esp += 8; } +static void submit(void) +{ + assert(MEM32(g_esp + 4) == 0x53003000); + assert(MEM32(g_esp + 8) == 1234); + assert(MEM32(g_esp + 12) == count); + assert(MEM32(g_esp + 16) == 7); + ++submissions; + g_eax = 0; + g_esp += 20; +} + +recomp_func_t recomp_lookup(uint32_t address) +{ + switch (address) { + case 0x250F7690: return manager; + case 0x25103CB0: return stride; + case 0x250F77E0: return allocate; + case 0x250F7840: return buffer; + case 0x250E7D90: return submit; + default: fprintf(stderr, "Unexpected vertex-upload call %08x\n", address); abort(); + } +} +recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); } +recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } + +int main(void) +{ + for (unsigned i = 0; i < 4; ++i) + assert(guest_map("vertex upload", 0x50000000 + i * 0x1000000, 0x10000)); + assert(guest_map("renderer globals", 0x251B0000, 0x10000)); + MEM32(0x251BB840) = 0x100; + MEM32(0x53000000) = 1; + const unsigned counts[] = {1, 0, 2, 3, 512, 16383}; + for (unsigned i = 0; i < sizeof(counts) / sizeof(counts[0]); ++i) { + count = counts[i]; + unsigned length = count * 4; + uint32_t input = 0x50010000 - length, output = 0x51010000 - length; + memset((void *)ADDR(0x51000000), 0xa5, 0x10000); + for (unsigned j = 0; j < length; ++j) MEM8(input + j) = j * 13 + 7; + g_fs_base = 0x53001000; + MEM32(g_fs_base) = 0xffffffff; + g_esp = 0x5200ff00; g_ecx = 0x53000000; + MEM32(g_esp + 4) = 0x42; MEM32(g_esp + 8) = input; + MEM32(g_esp + 12) = count; MEM32(g_esp + 16) = 7; + g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456; + submissions = 0; + + sub_250E8790(); + + assert(submissions == 1); + assert(g_esp == 0x5200ff14); + assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456); + assert(MEM32(g_fs_base) == 0xffffffff); + for (unsigned j = 0; j < length; ++j) + assert(MEM8(output + j) == (unsigned char)(j * 13 + 7)); + assert(MEM8(output - 1) == 0xa5); + } + puts("vertex upload: 6 page-ending payloads; bytes, submission, canary, FS and ABI passed"); +}