aorecomp

Anarchy Online classic in the browser

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


commit 79f1905fee6b2bdb0a28494f71098bd27ebf12bc
parent d4a12d3ed366d8a06ce9c650650fb229c9b3ddba
Author: anon <anon@example.com>
Date:   Sat, 17 Oct 2026 16:47:31 +0000

Reduce texture resampling overhead and loading-screen fades

Diffstat:
Msrc/Makefile.linux | 15+++++++++++++++
Msrc/Makefile.wasm | 8++++++++
Msrc/game/bbr.dll/lifted-0082.c | 150+++++++++++++++++++++++++------------------------------------------------------
Msrc/game/bbr.dll/lifted-0083.c | 34+++++++++++-----------------------
Msrc/game/ddr.dll/lifted-0014.c | 10++++++----
Asrc/tests/loading_fade.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/tests/texture_resampling.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 212 insertions(+), 129 deletions(-)

diff --git a/src/Makefile.linux b/src/Makefile.linux @@ -234,6 +234,9 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric ./build/linux/vertex-upload-paged ./build/linux/terrain-texture ./build/linux/terrain-texture-paged + ./build/linux/texture-resampling + ./build/linux/texture-resampling-paged + ./build/linux/loading-fade ./build/linux/archive-string ./build/linux/archive-string-paged ./build/linux/guest-memory @@ -512,3 +515,15 @@ build/linux/animation-initialization: tests/animation_initialization.c game/bbr. $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@ test: build/linux/animation-initialization + +build/linux/texture-resampling build/linux/texture-resampling-paged: tests/texture_resampling.c game/bbr.dll/lifted-0082.c game/bbr.dll/lifted-0083.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/texture-resampling build/linux/texture-resampling-paged + +build/linux/loading-fade: tests/loading_fade.c game/ddr.dll/lifted-0014.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h + mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@ + +test: build/linux/loading-fade diff --git a/src/Makefile.wasm b/src/Makefile.wasm @@ -109,3 +109,11 @@ build/wasm/animation-initialization.js: tests/animation_initialization.c game/bb build/wasm/rtti.js: tests/rtti.c runtime/guest_rtti.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_rtti.h runtime/guest_memory.h @mkdir -p $(@D) $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -lm -o $@ + +build/wasm/texture-resampling.js: tests/texture_resampling.c game/bbr.dll/lifted-0082.c game/bbr.dll/lifted-0083.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h + mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@ + +build/wasm/loading-fade.js: tests/loading_fade.c game/ddr.dll/lifted-0014.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h + mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@ diff --git a/src/game/bbr.dll/lifted-0082.c b/src/game/bbr.dll/lifted-0082.c @@ -8245,108 +8245,54 @@ L_25140F40: _flag_k = FK_TEST; goto L_25140FE9; /* 0x25140F46: jmp 0x25140fe9 */ L_25140F4B: - ecx = MEM32(ebp + (-0x8)); /* 0x25140F4B: mov ecx, dword ptr [ebp - 8] */ - eax = edi; /* 0x25140F4E: mov eax, edi */ - eax = (uint32_t)((int32_t)eax * (int32_t)ecx); /* 0x25140F50: imul eax, ecx */ - if (16u) _cf = (((eax) >> 15) & 1u); /* 0x25140F53: shr eax, 0x10 */ - if (16u) { _flag_a = recomp_flags_pack((eax >> 16u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - eax = eax >> 16u; /* 0x25140F53: shr eax, 0x10 */ - edx = 0x00010000u; /* 0x25140F56: mov edx, 0x10000 */ - _flag_a = (uint32_t)(ecx); _flag_b = (uint32_t)(eax); - _cf = (uint32_t)CMP_B(_flag_a, _flag_b); - ecx = ecx - eax; /* 0x25140F5B: sub ecx, eax */ - _flag_k = FK_CMP; - _flag_a = (uint32_t)(edx); _flag_b = (uint32_t)(eax); - _cf = (uint32_t)CMP_B(_flag_a, _flag_b); - edx = edx - eax; /* 0x25140F5D: sub edx, eax */ - _flag_k = FK_CMP; - _flag_a = (uint32_t)(edi); _flag_b = (uint32_t)(eax); - _cf = (uint32_t)CMP_B(_flag_a, _flag_b); - edi = edi - eax; /* 0x25140F5F: sub edi, eax */ - _flag_k = FK_CMP; - _flag_a = (uint32_t)(edx); _flag_b = (uint32_t)(ecx); - _cf = (uint32_t)CMP_B(_flag_a, _flag_b); - edx = edx - ecx; /* 0x25140F61: sub edx, ecx */ - _flag_k = FK_CMP; - MEM32(ebp + (-0x40)) = edi; /* 0x25140F63: mov dword ptr [ebp - 0x40], edi */ - if (8u) _cf = (((MEM32(ebp + (-0x40))) >> 7) & 1u); /* 0x25140F66: shr dword ptr [ebp - 0x40], 8 */ - if (8u) { _flag_a = recomp_flags_pack((MEM32(ebp + (-0x40)) >> 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - MEM32(ebp + (-0x40)) = MEM32(ebp + (-0x40)) >> 8u; /* 0x25140F66: shr dword ptr [ebp - 0x40], 8 */ - _flag_a = (uint32_t)(edx); _flag_b = (uint32_t)(edi); - _cf = (uint32_t)CMP_B(_flag_a, _flag_b); - edx = edx - edi; /* 0x25140F6A: sub edx, edi */ - _flag_k = FK_CMP; - MEM32(ebp + (-0xC)) = 1; /* 0x25140F6C: mov dword ptr [ebp - 0xc], 1 */ - if (8u) _cf = (((edx) >> 7) & 1u); /* 0x25140F73: shr edx, 8 */ - if (8u) { _flag_a = recomp_flags_pack((edx >> 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - edx = edx >> 8u; /* 0x25140F73: shr edx, 8 */ - MEM32(ebp + (-0x44)) = edx; /* 0x25140F76: mov dword ptr [ebp - 0x44], edx */ - if (8u) _cf = (((ecx) >> 7) & 1u); /* 0x25140F79: shr ecx, 8 */ - if (8u) { _flag_a = recomp_flags_pack((ecx >> 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - ecx = ecx >> 8u; /* 0x25140F79: shr ecx, 8 */ - if (8u) _cf = (((eax) >> 7) & 1u); /* 0x25140F7C: shr eax, 8 */ - if (8u) { _flag_a = recomp_flags_pack((eax >> 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - eax = eax >> 8u; /* 0x25140F7C: shr eax, 8 */ - _flag_a = (uint32_t)(0); _flag_b = (uint32_t)(0); - edx = 0; /* 0x25140F7F: xor edx, edx */ - _cf = 0; - _flag_k = FK_TEST; - MEM32(ebp + (-0x3C)) = ecx; /* 0x25140F81: mov dword ptr [ebp - 0x3c], ecx */ - MEM32(ebp + (-0x38)) = eax; /* 0x25140F84: mov dword ptr [ebp - 0x38], eax */ - MEM32(ebp + (-0x18)) = edx; /* 0x25140F87: mov dword ptr [ebp - 0x18], edx */ - MEM32(ebp + (-0x10)) = edx; /* 0x25140F8A: mov dword ptr [ebp - 0x10], edx */ - MEM32(ebp + (-0x4)) = edx; /* 0x25140F8D: mov dword ptr [ebp - 4], edx */ - ecx = 0x00FF00FFu; /* 0x25140F90: mov ecx, 0xff00ff */ -L_25140F95: - eax = MEM32(ebx + 0xB4); /* 0x25140F95: mov eax, dword ptr [ebx + 0xb4] */ - /* test MEM32(ebp + (-0xC)), eax */ /* 0x25140F9B: test dword ptr [ebp - 0xc], eax */ - _flag_a = (uint32_t)(MEM32(ebp + (-0xC))); _flag_b = (uint32_t)(eax); - _cf = 0; - _flag_k = FK_TEST; - if (TEST_NZ(_flag_a, _flag_b)) goto L_25140FC8; /* 0x25140F9E: jne 0x25140fc8 */ -L_25140FA0: - edx = MEM32(ebp + (-0x4)); /* 0x25140FA0: mov edx, dword ptr [ebp - 4] */ - eax = MEM32(ebp + edx + (-0x54)); /* 0x25140FA3: mov eax, dword ptr [ebp + edx - 0x54] */ - edx = MEM32(ebp + edx + (-0x44)); /* 0x25140FA7: mov edx, dword ptr [ebp + edx - 0x44] */ - edi = eax; /* 0x25140FAB: mov edi, eax */ - _flag_a = (uint32_t)(eax); _flag_b = (uint32_t)(ecx); - eax = eax & ecx; /* 0x25140FAD: and eax, ecx */ - _cf = 0; - _flag_k = FK_TEST; - if (8u) _cf = (((edi) >> 7) & 1u); /* 0x25140FAF: shr edi, 8 */ - if (8u) { _flag_a = recomp_flags_pack((edi >> 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - edi = edi >> 8u; /* 0x25140FAF: shr edi, 8 */ - eax = (uint32_t)((int32_t)eax * (int32_t)edx); /* 0x25140FB2: imul eax, edx */ - _flag_a = (uint32_t)(edi); _flag_b = (uint32_t)(ecx); - edi = edi & ecx; /* 0x25140FB5: and edi, ecx */ - _cf = 0; - _flag_k = FK_TEST; - MEM32(ebp + (-0x24)) = edx; /* 0x25140FB7: mov dword ptr [ebp - 0x24], edx */ - edi = (uint32_t)((int32_t)edi * (int32_t)edx); /* 0x25140FBA: imul edi, edx */ - edx = MEM32(ebp + (-0x18)); /* 0x25140FBD: mov edx, dword ptr [ebp - 0x18] */ - _flag_a = (uint32_t)(MEM32(ebp + (-0x10))); _flag_b = (uint32_t)(edi); - _cf = (uint32_t)((uint32_t)(_flag_a + _flag_b) < (uint32_t)_flag_a); - MEM32(ebp + (-0x10)) = MEM32(ebp + (-0x10)) + edi; /* 0x25140FC0: add dword ptr [ebp - 0x10], edi */ - _flag_k = FK_ADD; - _flag_a = (uint32_t)(edx); _flag_b = (uint32_t)(eax); - _cf = (uint32_t)((uint32_t)(_flag_a + _flag_b) < (uint32_t)_flag_a); - edx = edx + eax; /* 0x25140FC3: add edx, eax */ - _flag_k = FK_ADD; - MEM32(ebp + (-0x18)) = edx; /* 0x25140FC5: mov dword ptr [ebp - 0x18], edx */ -L_25140FC8: - _flag_a = (uint32_t)(MEM32(ebp + (-0x4))); _flag_b = (uint32_t)(4); - _cf = (uint32_t)((uint32_t)(_flag_a + _flag_b) < (uint32_t)_flag_a); - MEM32(ebp + (-0x4)) = MEM32(ebp + (-0x4)) + 4; /* 0x25140FC8: add dword ptr [ebp - 4], 4 */ - _flag_k = FK_ADD; - if (1u) _cf = (((MEM32(ebp + (-0xC))) >> 31) & 1u); /* 0x25140FCC: shl dword ptr [ebp - 0xc], 1 */ - if (1u) { _flag_a = recomp_flags_pack((MEM32(ebp + (-0xC)) << 1u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - MEM32(ebp + (-0xC)) = MEM32(ebp + (-0xC)) << 1u; /* 0x25140FCC: shl dword ptr [ebp - 0xc], 1 */ - /* cmp MEM32(ebp + (-0x4)), 0x10u */ /* 0x25140FCF: cmp dword ptr [ebp - 4], 0x10 */ - _flag_a = (uint32_t)(MEM32(ebp + (-0x4))); _flag_b = (uint32_t)(0x10u); - _cf = (uint32_t)CMP_B(_flag_a, _flag_b); - _flag_k = FK_CMP; - RECOMP_BACKEDGE(); - if (CMP_L(_flag_a, _flag_b)) goto L_25140F95; /* 0x25140FD3: jl 0x25140f95 */ + { + /* The contiguous guest stack frame is shared with the pixel callback. */ + struct { + uint32_t addresses[5], pixels[4], weights[4], bounds[4]; + uint32_t last_weight, remaining, bytes_per_pixel, red_blue; + uint32_t stride, green_alpha, bit, y_fraction, offset; + } *frame = (void *)ADDR(ebp - 0x68); + _Static_assert(sizeof(*frame) == 0x68, "Resampling frame layout"); + /* Preserve 16.16 coordinate truncation before reducing weights to 8 bits. */ + uint32_t x_fraction = edi; + uint32_t y_fraction = frame->y_fraction; + uint32_t diagonal = (x_fraction * y_fraction) >> 16; + edi = x_fraction - diagonal; + ecx = y_fraction - diagonal; + edx = 65536u - diagonal - ecx - edi; + frame->weights[0] = edx >> 8; + frame->weights[1] = edi >> 8; + frame->weights[2] = ecx >> 8; + frame->weights[3] = diagonal >> 8; + frame->bit = 1; + frame->red_blue = 0; + frame->green_alpha = 0; + frame->offset = 0; + edx = 0; + ecx = 0x00ff00ff; + + /* Accumulate alternating byte channels without rounding or saturation. */ + do { + eax = MEM32(ebx + 0xb4); + if (!(frame->bit & eax)) { + uint32_t offset = frame->offset; + uint32_t pixel = frame->pixels[offset/4]; + uint32_t weight = frame->weights[offset/4]; + eax = (pixel & ecx) * weight; + edi = ((pixel >> 8) & ecx) * weight; + frame->last_weight = weight; + frame->green_alpha += edi; + edx = frame->red_blue + eax; + frame->red_blue = edx; + } + frame->offset += 4; + frame->bit <<= 1; + _flag_a = frame->offset; _flag_b = 16; + _cf = CMP_B(_flag_a, _flag_b); _flag_k = FK_CMP; + RECOMP_BACKEDGE(); + frame = (void *)ADDR(ebp - 0x68); + } while (CMP_L(_flag_a, _flag_b)); + } L_25140FD5: eax = MEM32(ebp + (-0x10)); /* 0x25140FD5: mov eax, dword ptr [ebp - 0x10] */ if (8u) _cf = (((edx) >> 7) & 1u); /* 0x25140FD8: shr edx, 8 */ diff --git a/src/game/bbr.dll/lifted-0083.c b/src/game/bbr.dll/lifted-0083.c @@ -2207,29 +2207,17 @@ L_251423B6: _flag_k = FK_TEST; if (TEST_NZ(_flag_a, _flag_b)) goto L_251423DB; /* 0x251423B9: jne 0x251423db */ L_251423BB: - eax = MEM32(ecx); /* 0x251423BB: mov eax, dword ptr [ecx] */ - edi = (uint32_t)MEM8(eax + 0x2); /* 0x251423BD: movzx edi, byte ptr [eax + 2] */ - ebx = (uint32_t)MEM8(eax + 0x1); /* 0x251423C1: movzx ebx, byte ptr [eax + 1] */ - eax = (uint32_t)MEM8(eax); /* 0x251423C5: movzx eax, byte ptr [eax] */ - _flag_a = (uint32_t)((edi | 0xFFFFFF00u)); _flag_b = (uint32_t)((edi | 0xFFFFFF00u)); - edi = edi | 0xFFFFFF00u; /* 0x251423C8: or edi, 0xffffff00 */ - _cf = 0; - _flag_k = FK_TEST; - if (8u) _cf = (((edi) >> 24) & 1u); /* 0x251423CE: shl edi, 8 */ - if (8u) { _flag_a = recomp_flags_pack((edi << 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - edi = edi << 8u; /* 0x251423CE: shl edi, 8 */ - _flag_a = (uint32_t)((edi | ebx)); _flag_b = (uint32_t)((edi | ebx)); - edi = edi | ebx; /* 0x251423D1: or edi, ebx */ - _cf = 0; - _flag_k = FK_TEST; - if (8u) _cf = (((edi) >> 24) & 1u); /* 0x251423D3: shl edi, 8 */ - if (8u) { _flag_a = recomp_flags_pack((edi << 8u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } - edi = edi << 8u; /* 0x251423D3: shl edi, 8 */ - _flag_a = (uint32_t)((edi | eax)); _flag_b = (uint32_t)((edi | eax)); - edi = edi | eax; /* 0x251423D6: or edi, eax */ - _cf = 0; - _flag_k = FK_TEST; - MEM32(esi + ecx) = edi; /* 0x251423D8: mov dword ptr [esi + ecx], edi */ + { + /* Expand a BGR triplet to an opaque BGRA sample. */ + const unsigned char *pixel = (const unsigned char *)ADDR(MEM32(ecx)); + uint32_t blue = pixel[0]; + uint32_t green = pixel[1]; + uint32_t red = pixel[2]; + eax = blue; + ebx = green; + edi = 0xff000000u | (red << 16) | (green << 8) | blue; + MEM32(esi + ecx) = edi; + } L_251423DB: if (1u) _cf = (((MEM32(ebp + (-0x4))) >> 31) & 1u); /* 0x251423DB: shl dword ptr [ebp - 4], 1 */ if (1u) { _flag_a = recomp_flags_pack((MEM32(ebp + (-0x4)) << 1u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; } diff --git a/src/game/ddr.dll/lifted-0014.c b/src/game/ddr.dll/lifted-0014.c @@ -1649,6 +1649,8 @@ L_2B03A010: } void sub_2B03A030(void) { + /* Keep the connection and scene-reveal fades brief. Timer_t uses milliseconds. */ + const double fade_ms = 150.0; int _fpu_cmp = 0; uint32_t _cf = 0; int _df = 1; @@ -1681,7 +1683,7 @@ L_2B03A04A: eax = MEM32(eax + 0x24); /* 0x2B03A050: mov eax, dword ptr [eax + 0x24] */ MEM32(ebp + (-0x4)) = eax; /* 0x2B03A053: mov dword ptr [ebp - 4], eax */ fp_push((double)(int32_t)MEM32(ebp + (-0x4))); /* 0x2B03A056: fild dword ptr [ebp - 4] */ - fp_push(*(float*)&MEM32(0x2B0B6870)); /* 0x2B03A059: fld dword ptr [0x2b0b6870] */ + fp_push(fade_ms); _st[0] += (double)*(float*)ADDR(0x2B0EE970); /* 0x2B03A05F: fadd dword ptr [0x2b0ee970] */ _fpu_cmp = FPU_CMP(_st[0], _st[1]); /* 0x2B03A065: fcomp st(1) */ fp_pop(); @@ -1720,7 +1722,7 @@ L_2B03A0A8: _st[0] -= (double)*(float*)ADDR(0x2B0EE970); /* 0x2B03A0A8: fsub dword ptr [0x2b0ee970] */ PUSH32(esp, 0); /* 0x2B03A0AE: push 0 */ PUSH32(esp, ecx); /* 0x2B03A0B0: push ecx */ - _st[0] /= (double)*(float*)ADDR(0x2B0B6870); /* 0x2B03A0B1: fdiv dword ptr [0x2b0b6870] */ + _st[0] /= fade_ms; { float _v = (float)fp_pop(); *(float*)ADDR(esp) = _v; } /* 0x2B03A0B7: fstp dword ptr [esp] */ RECOMP_ICALL(0x2B039F80u); /* 0x2B03A0BA: call 0x2b039f80 */ /* not lifted */ RECOMP_FLAGS_IN(); @@ -1737,7 +1739,7 @@ L_2B03A0C6: ecx = MEM32(eax + 0x24); /* 0x2B03A0CC: mov ecx, dword ptr [eax + 0x24] */ MEM32(ebp + (-0x4)) = ecx; /* 0x2B03A0CF: mov dword ptr [ebp - 4], ecx */ fp_push((double)(int32_t)MEM32(ebp + (-0x4))); /* 0x2B03A0D2: fild dword ptr [ebp - 4] */ - fp_push(*(float*)&MEM32(0x2B0B686C)); /* 0x2B03A0D5: fld dword ptr [0x2b0b686c] */ + fp_push(fade_ms); _st[0] += (double)*(float*)ADDR(0x2B0EE970); /* 0x2B03A0DB: fadd dword ptr [0x2b0ee970] */ _fpu_cmp = FPU_CMP(_st[0], _st[1]); /* 0x2B03A0E1: fcomp st(1) */ fp_pop(); @@ -1771,7 +1773,7 @@ L_2B03A113: _st[0] -= (double)*(float*)ADDR(0x2B0EE970); /* 0x2B03A113: fsub dword ptr [0x2b0ee970] */ PUSH32(esp, 1); /* 0x2B03A119: push 1 */ PUSH32(esp, ecx); /* 0x2B03A11B: push ecx */ - _st[0] /= (double)*(float*)ADDR(0x2B0B686C); /* 0x2B03A11C: fdiv dword ptr [0x2b0b686c] */ + _st[0] /= fade_ms; _st[0] = (double)*(float*)ADDR(0x2B0B63D0) - _st[0]; /* 0x2B03A122: fsubr dword ptr [0x2b0b63d0] */ { float _v = (float)fp_pop(); *(float*)ADDR(esp) = _v; } /* 0x2B03A128: fstp dword ptr [esp] */ RECOMP_ICALL(0x2B039F80u); /* 0x2B03A12B: call 0x2b039f80 */ /* not lifted */ diff --git a/src/tests/loading_fade.c b/src/tests/loading_fade.c @@ -0,0 +1,69 @@ +#include "recomp_types.h" +#include <assert.h> + +void sub_2B03A030(void); +static unsigned redirected, removed, alpha_calls, hide_scene; +static float alpha; + +static void timer(void) { g_eax = 0x50001000; g_esp += 4; } +static void instance(void) { g_eax = 0x50002000; g_esp += 4; } +static void set_alpha(void) +{ + alpha = (*(float *)ADDR(g_esp + 4)); + hide_scene = MEM32(g_esp + 8); + ++alpha_calls; + g_esp += 4; +} +static void remove_program(void) { removed = MEM32(g_esp + 4); g_esp += 8; } +static void redirect(void) { ++redirected; g_esp += 4; } + +recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } +recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } +recomp_func_t recomp_lookup(uint32_t address) +{ + switch (address) { + case 1: return timer; + case 2: return instance; + case 3: return remove_program; + case 4: return redirect; + case 0x2B039F80: return set_alpha; + default: abort(); + } +} + +int main(void) +{ + assert(guest_map("loading state", 0x2b000000, 0x100000)); + assert(guest_map("loading test", 0x50000000, 0x10000)); + MEM32(0x2b0b53bc) = 1; + MEM32(0x2b0b53cc) = MEM32(0x2b0b5f70) = 2; + MEM32(0x2b0b5394) = 3; MEM32(0x2b0b5f64) = 4; + (*(float *)ADDR(0x2b0b63d0)) = 1.0f; + for (unsigned opening = 0; opening < 2; ++opening) { + MEM8(0x2b0ee96c) = 1; + MEM8(0x2b0e6d0c) = opening; + (*(float *)ADDR(0x2b0ee970)) = 1000.0f; + MEM32(0x50001024) = 1075; + g_esp = 0x5000ff00; g_ebp = 123; + redirected = removed = alpha_calls = 0; + + sub_2B03A030(); + + assert(alpha == 0.5f && alpha_calls == 1); + assert(hide_scene == !opening && redirected == 0 && removed == 0); + assert(MEM8(0x2b0ee96c) == 1); + assert(g_esp == 0x5000ff04 && g_ebp == 123); + + /* Complete the fade, then verify that subsequent frames are inactive. */ + MEM32(0x50001024) = 1151; + g_esp = 0x5000ff00; + sub_2B03A030(); + assert(alpha == (opening ? 1.0f : 0.0f) && alpha_calls == 2); + assert(removed == (opening ? 7 : 6) && redirected == opening); + assert(MEM8(0x2b0ee96c) == 0); + assert(g_esp == 0x5000ff04 && g_ebp == 123); + g_esp = 0x5000ff00; + sub_2B03A030(); + assert(alpha_calls == 2 && redirected == opening); + } +} diff --git a/src/tests/texture_resampling.c b/src/tests/texture_resampling.c @@ -0,0 +1,55 @@ +#include "recomp_types.h" +#include <assert.h> + +void sub_25140DFB(void); +void sub_25142392(void); +recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } +recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } +recomp_func_t recomp_lookup(uint32_t address) +{ + assert(address == 0x25142392); + return sub_25142392; +} + +int main(void) +{ + assert(guest_map("texture resampling", 0x50000000, 0x20000)); + assert(guest_map("resampling stack", 0x51000000, 0x20000)); + /* BGR source pixels and the scratch stack cross guest page boundaries. */ + const unsigned char pixels[] = {0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255}; + /* Integer, fractional, clipped, reversed and fully outside rows. */ + const int positions[][3] = {{0, 0, 32768}, {0, 32768, 32768}, {-32768, 32768, 32768}, {98304, 32768, -32768}, {0, -65536, 32768}, {0, 131072, 32768}}; + const uint32_t expected[][4] = { + {0xffff0000, 0xff7f7f00, 0xff00ff00, 0xff00ff00}, + {0xff7f007f, 0xff7f7f7f, 0xff7fff7f, 0xff7fff7f}, + {0xfe7f007e, 0xff7f007f, 0xff7f7f7f, 0xff7fff7f}, + {0xff7fff7f, 0xff7fff7f, 0xff7f7f7f, 0xff7f007f}, + {0xfefe0000, 0xfe7f7e00, 0xfe00fe00, 0xfe00fe00}, + {0, 0, 0, 0} + }; + for (unsigned i = 0; i < 6; ++i) { + memset((void *)ADDR(0x50000000), 0xa5, 0x20000); + memcpy((void *)ADDR(0x5000fffe), pixels, sizeof(pixels)); + MEM32(0x50001020) = 24; MEM32(0x50001024) = 6; + MEM32(0x50001028) = 0x5000fffe; + MEM32(0x50001054) = 0; MEM32(0x50001058) = 0; + MEM32(0x5000105c) = 2; MEM32(0x50001060) = 2; + MEM32(0x50001090) = positions[i][2]; + MEM32(0x500010a8) = positions[i][0] + 0x7fff; + MEM32(0x500010ac) = positions[i][1] + 0x7fff; + MEM32(0x500010b8) = 0x25142392; + g_esp = 0x51010020; g_ebp = 123; + g_ebx = 234; g_esi = 345; g_edi = 456; + MEM32(g_esp + 4) = 4; + MEM32(g_esp + 8) = 0x50006000; + MEM32(g_esp + 12) = 0x50001000; + + sub_25140DFB(); + + for (unsigned j = 0; j < 4; ++j) + assert(MEM32(0x50006000 + j * 4) == expected[i][j]); + assert(g_esp == 0x51010024 && g_ebp == 123); + assert(g_ebx == 234 && g_esi == 345 && g_edi == 456); + assert(MEM32(0x50005ffc) == 0xa5a5a5a5 && MEM32(0x50006010) == 0xa5a5a5a5); + } +}