diff --git a/lib/N64ModernRuntime b/lib/N64ModernRuntime index 46b7a37..e8d7aec 160000 --- a/lib/N64ModernRuntime +++ b/lib/N64ModernRuntime @@ -1 +1 @@ -Subproject commit 46b7a37a4c572b85fa6ef80986ed0af96d4857e7 +Subproject commit e8d7aec1bb7947fc15d8e521c0d5c4af8c0bcc3f diff --git a/patches/Makefile b/patches/Makefile index dea4de2..6f84a85 100644 --- a/patches/Makefile +++ b/patches/Makefile @@ -5,9 +5,9 @@ LD ?= ld.lld GBI_DEFINE := -DF3DEX_GBI CFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \ - -fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset \ + -fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset -funsigned-char \ -Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable -Wno-missing-braces -Wno-unsupported-floating-point-opt -Wno-cast-function-type-mismatch -CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -I ../lib/bk-decomp/include -I ../lib/bk-decomp/include/2.0L -I ../lib/bk-decomp/include/2.0L/PR -I../lib/rt64/include $(GBI_DEFINE) +CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -I ../lib/bk-decomp/include -I ../lib/bk-decomp/include/2.0L -I ../lib/bk-decomp/include/2.0L/PR -I../lib/rt64/include -I../lib/N64ModernRuntime/ultramodern/include $(GBI_DEFINE) LDFLAGS := -nostdlib -T patches.ld -T syms.ld -Map patches.map --unresolved-symbols=ignore-all --emit-relocs C_SRCS := $(wildcard *.c) diff --git a/patches/graphics_patches.c b/patches/graphics_patches.c index 23970f7..7d8b86d 100644 --- a/patches/graphics_patches.c +++ b/patches/graphics_patches.c @@ -1,4 +1,5 @@ #include "patches.h" +#include "ultra_extensions.h" #include "misc_funcs.h" #include "core1/core1.h" #include "core1/vimgr.h" @@ -22,7 +23,7 @@ extern struct{ void func_802E39D0(Gfx **gdl, Mtx **mptr, Vtx **vptr, s32 framebuffer_idx, s32 arg4); -// 10x the original sizes. +// 16x the original sizes. #define GFX_BUFFER_COUNT 37000 #define MTX_BUFFER_COUNT 7000 #define VTX_BUFFER_COUNT 4300 @@ -65,6 +66,7 @@ RECOMP_PATCH void graphicsCache_init(void){ } // @recomp Patched to check for graphics stack overflow after processing a frame. +// Also patched to wait for a message when the displaylist is completed immediately after queueing it to solve vertex modification race conditions. RECOMP_PATCH void game_draw(s32 arg0){ Gfx *gfx; Gfx *gfx_start; @@ -115,7 +117,18 @@ RECOMP_PATCH void game_draw(s32 arg0){ if(D_8037E8E0.unkC == 0){ sp2C = gfx; viMgr_func_8024C1DC(); + + // @recomp Set up the message queue and event for waiting on DL completion. + OSMesgQueue dl_complete_queue; + OSMesg dl_complete_queue_buf; + osCreateMesgQueue(&dl_complete_queue, &dl_complete_queue_buf, 1); + osExQueueDisplaylistEvent(&dl_complete_queue, NULL, gfx_start, OS_EX_DISPLAYLIST_EVENT_PARSED); + func_80253EC4(gfx_start, sp2C); + + // @recomp Wait for the displaylist to be completed after submitting it. This removes the race condition + // that exists with vertex modifications for texture scrolling. + osRecvMesg(&dl_complete_queue, NULL, OS_MESG_BLOCK); if(arg0) { scissorBox_setDefault(); diff --git a/patches/syms.ld b/patches/syms.ld index bfd546c..d0d116e 100644 --- a/patches/syms.ld +++ b/patches/syms.ld @@ -35,3 +35,4 @@ osVirtualToPhysical_recomp = 0x8F000078; osPiStartDma_recomp = 0x8F00007C; recomp_abort = 0x8F000080; recomp_get_target_aspect_ratio = 0x8F000084; +osExQueueDisplaylistEvent_recomp = 0x8F000088; diff --git a/patches/ultra_extensions.h b/patches/ultra_extensions.h new file mode 100644 index 0000000..b62fcdc --- /dev/null +++ b/patches/ultra_extensions.h @@ -0,0 +1,9 @@ +#ifndef __ULTRA_EXTENSIONS_H__ +#define __ULTRA_EXTENSIONS_H__ + +// TODO remove when the recompiler automatically renames symbols in patch recompilation. +#define osExQueueDisplaylistEvent osExQueueDisplaylistEvent_recomp + +#include "ultramodern/extensions.h" + +#endif \ No newline at end of file