From 6ba869691bd38fe7450d54108e32c87de19b4ca6 Mon Sep 17 00:00:00 2001 From: aglab2 Date: Sun, 5 Sep 2021 16:59:50 +0800 Subject: [PATCH] gIsVC is introduced, VC_HACKS define is removed --- Makefile | 7 ------- src/audio/heap.c | 8 +++++--- src/game/game_init.c | 13 ++++--------- src/game/vc_check.c | 7 +++++++ src/game/vc_check.h | 20 ++++++++++++++++++++ 5 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 src/game/vc_check.c create mode 100644 src/game/vc_check.h diff --git a/Makefile b/Makefile index 4d4a5393..84330d1b 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,6 @@ USE_DEBUG := 0 # Build for the N64 (turn this off for ports) TARGET_N64 ?= 1 -# Virtual Console hacks. Enabling this makes your hack (hopefully) compatible with the Wii Virtual Console. -# One of the thing this does is disable the instant input patch, so do NOT use this for your normal z64 release. -VC_HACKS ?= 0 # CONSOLE - selects the console to target # bb - Targets the iQue Player (codenamed BB) @@ -39,10 +36,6 @@ else ifeq ($(CONSOLE),bb) DEFINES += BBPLAYER=1 endif -ifeq ($(VC_HACKS), 1) - DEFINES += VC_HACKS=1 -endif - # COMPILER - selects the C compiler to use # gcc - uses the GNU C Compiler # clang - uses clang C/C++ frontend for LLVM diff --git a/src/audio/heap.c b/src/audio/heap.c index b63b0664..4b518fc2 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -11,6 +11,8 @@ #define ALIGN16(val) (((val) + 0xF) & ~0xF) +extern u8 gIsVC; + struct PoolSplit { u32 wantSeq; u32 wantBank; @@ -1109,11 +1111,11 @@ s32 audio_shut_down_and_reset_step(void) { * Waits until a specified number of audio frames have been created */ void wait_for_audio_frames(s32 frames) { -#ifdef VC_HACKS // VC emulator stubs this function because busy loops are not supported // Technically we can put infinite loop that _looks_ like -O0 for emu but this is cleaner - return; -#endif + if (gIsVC) + return; + gAudioFrameCount = 0; // Sound thread will update gAudioFrameCount while (gAudioFrameCount < frames) { diff --git a/src/game/game_init.c b/src/game/game_init.c index dcde6663..854b7bda 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -33,6 +33,7 @@ #include #include "puppycam2.h" #include "debug_box.h" +#include "vc_check.h" // First 3 controller slots struct Controller gControllers[3]; @@ -48,6 +49,7 @@ OSContStatus gControllerStatuses[4]; OSContPad gControllerPads[4]; u8 gControllerBits; u8 gIsConsole = TRUE; // Needs to be initialized before audio_reset_session is called +u8 gIsVC = FALSE; u8 gBorderHeight; #ifdef CUSTOM_DEBUG u8 gCustomDebugMode; @@ -392,13 +394,9 @@ void render_init(void) { // Skip incrementing the initial framebuffer index on emulators so that they display immediately as the Gfx task finishes // VC probably emulates osViSwapBuffer accurately so instant patch breaks VC compatibility -#ifndef VC_HACKS if (gIsConsole) { // Read RDP Clock Register, has a value of zero on emulators -#endif sRenderingFrameBuffer++; -#ifndef VC_HACKS } -#endif gGlobalTimer++; } @@ -421,6 +419,7 @@ void select_gfx_pool(void) { * - Selects which framebuffer will be rendered and displayed to next time. */ void display_and_vsync(void) { + gIsVC = IS_VC(); if (IO_READ(DPC_PIPEBUSY_REG) && gIsConsole != 1) { gIsConsole = 1; @@ -440,18 +439,14 @@ void display_and_vsync(void) { profiler_log_thread5_time(THREAD5_END); osRecvMesg(&gGameVblankQueue, &gMainReceivedMesg, OS_MESG_BLOCK); // Skip swapping buffers on emulator so that they display immediately as the Gfx task finishes -#ifndef VC_HACKS - if (gIsConsole) { // Read RDP Clock Register, has a value of zero on emulators -#endif + if (gIsConsole || gIsVC) { // Read RDP Clock Register, has a value of zero on emulators if (++sRenderedFramebuffer == 3) { sRenderedFramebuffer = 0; } if (++sRenderingFrameBuffer == 3) { sRenderingFrameBuffer = 0; } -#ifndef VC_HACKS } -#endif gGlobalTimer++; } diff --git a/src/game/vc_check.c b/src/game/vc_check.c new file mode 100644 index 00000000..d5965bec --- /dev/null +++ b/src/game/vc_check.c @@ -0,0 +1,7 @@ +#include "vc_check.h" + +// literally return what was passed +f32 round_double_to_float(f64 v) +{ + return v; +} diff --git a/src/game/vc_check.h b/src/game/vc_check.h new file mode 100644 index 00000000..97a913e8 --- /dev/null +++ b/src/game/vc_check.h @@ -0,0 +1,20 @@ +#ifndef VC_CHECK_H +#define VC_CHECK_H + +#include "sm64.h" + +// This function must not be inlined by the compiler so I move it to a different C file +f32 round_double_to_float(f64); + +/* + * This check forces RTZ bug on vc + * If console is N64/adequate Emu round-to-nearest (RTN) rounding mode is used + * If console is VC round-to-zero (RTZ) mode is used + * + * The double value 0.9999999999999999 used is 0x3FEFFFFFFFFFFFFF in binary + * Exponent=01111111110, Mantissa=1111111111111111111111111111111111111111111111111111 + * RTZ will output not 1.0f, RTN will output exactly 1.0f + */ +#define IS_VC() (1.0f != round_double_to_float(0.9999999999999999)) + +#endif