gIsVC is introduced, VC_HACKS define is removed

This commit is contained in:
aglab2
2021-09-05 16:59:50 +08:00
parent 4c655bfdc0
commit 6ba869691b
5 changed files with 36 additions and 19 deletions

View File

@@ -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

View File

@@ -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) {

View File

@@ -33,6 +33,7 @@
#include <prevent_bss_reordering.h>
#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++;
}

7
src/game/vc_check.c Normal file
View File

@@ -0,0 +1,7 @@
#include "vc_check.h"
// literally return what was passed
f32 round_double_to_float(f64 v)
{
return v;
}

20
src/game/vc_check.h Normal file
View File

@@ -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