diff --git a/Makefile b/Makefile index 9fa39d99..a0f181f7 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ endif # ditch g3, we aren't using that in GCC ifeq ($(COMPILER),gcc) - OPTFLAGS := -Os + OPTFLAGS := -Ofast else OPTFLAGS := -O2 -g3 endif @@ -339,12 +339,18 @@ build/src/libultra/os/%.o: OPTFLAGS := -Os build/src/libultra/rmon/%.o: OPTFLAGS := -Os build/src/libultra/debug/%.o: OPTFLAGS := -Os build/src/libultra/host/%.o: OPTFLAGS := -Os -build/src/audio/audio_load.o: OPTFLAGS := -O2 -build/src/audio/%.o: OPTFLAGS := -O2 -g # per-file flags -build/src/libc_sprintf.o: OPTFLAGS := -Os -build/src/libc_math64.o: OPTFLAGS := -Os +build/src/audio/audio_load.o: OPTFLAGS := -Os +build/src/audio/audio_heap.o: OPTFLAGS := -Os +build/src/audio/audio_effects.o: OPTFLAGS := -Os +build/src/audio/audio_general.o: OPTFLAGS := -Os +build/src/audio/audio_playback.o: OPTFLAGS := -Os +build/src/audio/audio_seqplayer.o: OPTFLAGS := -Os +build/src/audio/audio_thread.o: OPTFLAGS := -Os + +build/src/libc_sprintf.o: OPTFLAGS := -Ofast +build/src/libc_math64.o: OPTFLAGS := -Ofast build/src/libultra/libc/ldiv.o: OPTFLAGS := -Os build/src/libultra/libc/string.o: OPTFLAGS := -Os @@ -355,10 +361,10 @@ build/src/libultra/libc/ll.o: OPTFLAGS := -O2 build/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 # cc & asm-processor -build/src/libultra/gu/sqrtf.o: OPTFLAGS := -Os -build/src/libultra/gu/sinf.o: OPTFLAGS := -Os +build/src/libultra/gu/sqrtf.o: OPTFLAGS := -Ofast +build/src/libultra/gu/sinf.o: OPTFLAGS := -Ofast build/src/libultra/gu/lookat.o: OPTFLAGS := -Os -build/src/libultra/gu/ortho.o: OPTFLAGS := -Os +build/src/libultra/gu/ortho.o: OPTFLAGS := -Os build/src/libultra/gu/perspective.o: OPTFLAGS := -Os build/src/libultra/gu/mtxutil.o: OPTFLAGS := -Os build/src/libultra/gu/cosf.o: OPTFLAGS := -Os diff --git a/include/mods.h b/include/mods.h index 6930f516..fd93b357 100644 --- a/include/mods.h +++ b/include/mods.h @@ -8,17 +8,27 @@ */ #define MODS_LEVEL_SELECT 0 - /** * Sound Effects Jukebox: * Ability to play sound effects inside the expert sound menu */ #define MODS_SFX_JUKEBOX 0 +/** + * FPS Counter: + * Press L to toggle FPS Display +*/ +#define MODS_FPS_COUNTER 0 + + /* ************************* */ #if MODS_LEVEL_SELECT == 1 void Map_LevelSelect(void); #endif +#if MODS_FPS_COUNTER == 1 +static void Play_RenderFps(void); +#endif + #endif diff --git a/src/audio/audio_general.c b/src/audio/audio_general.c index ff1247ba..1bea0140 100644 --- a/src/audio/audio_general.c +++ b/src/audio/audio_general.c @@ -688,7 +688,6 @@ void Audio_SetSfxProperties(u8 bankId, u8 entryIndex, u8 channelId) { sSfxChannelState[channelId].pan = pan; } } - f32 Audio_UpdateDopplerShift(f32* srcPos, f32* srcVel, f32 soundSpeed, f32* curDopplerShift) { f32 xVel; f32 zVel; @@ -704,6 +703,12 @@ f32 Audio_UpdateDopplerShift(f32* srcPos, f32* srcVel, f32 soundSpeed, f32* curD f32 targetDopplerShift; s32 pad; +#ifdef AVOID_UB + if ((srcPos == NULL) || (srcVel == NULL) || (curDopplerShift == NULL)) { + return 0.0f; + } +#endif + xPos = srcPos[0]; zPos = srcPos[2]; xVel = srcVel[0]; @@ -2215,7 +2220,11 @@ void Audio_UpdateBlueMarineNoise(u8 playerId) { void Audio_UpdatePlayerFreqMod(void) { u8 playerId; +#ifdef AVOID_UB + for (playerId = 0; playerId < gCamCount; playerId++) { +#else for (playerId = 0; playerId < 4; playerId++) { +#endif switch (sPlayerNoise[playerId].form) { case FORM_ARWING: Audio_UpdateArwingNoise(playerId); diff --git a/src/audio/audio_heap.c b/src/audio/audio_heap.c index 2f59b183..df30ca33 100644 --- a/src/audio/audio_heap.c +++ b/src/audio/audio_heap.c @@ -973,7 +973,7 @@ SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(u32 size) { void AudioHeap_DiscardSampleCaches(void) { s32 fontId; s32 i; - s32 numFonts; + s32 numFonts = gSoundFontTable->numEntries; s32 pad; s32 sampleBankId2; s32 sampleBankId1; @@ -983,7 +983,10 @@ void AudioHeap_DiscardSampleCaches(void) { Instrument* instrument; SampleCacheEntry* entry; - numFonts = gSoundFontTable->numEntries; +#ifdef AVOID_UB + entry = gPersistentSampleCache.entries; +#endif + for (fontId = 0; fontId < numFonts; fontId++) { sampleBankId1 = gSoundFontList[fontId].sampleBankId1; sampleBankId2 = gSoundFontList[fontId].sampleBankId2; diff --git a/src/engine/fox_display.c b/src/engine/fox_display.c index 0e1e55d1..4385cd18 100644 --- a/src/engine/fox_display.c +++ b/src/engine/fox_display.c @@ -1,3 +1,4 @@ +#include "mods.h" #include "global.h" #include "assets/ast_arwing.h" #include "assets/ast_allies.h" @@ -1722,4 +1723,11 @@ void Play_Draw(void) { func_display_80051B30(); sPlayersVisible[gPlayerNum] = 0; Matrix_Pop(&gGfxMatrix); +#if MODS_FPS_COUNTER == 1 + Play_RenderFps(); +#endif } + +#if MODS_FPS_COUNTER == 1 +#include "../mods/fpscounter.c" +#endif diff --git a/src/libultra/gcc_fix/__floatundisf.c b/src/libultra/gcc_fix/__floatundisf.c new file mode 100644 index 00000000..b69a6103 --- /dev/null +++ b/src/libultra/gcc_fix/__floatundisf.c @@ -0,0 +1,27 @@ +#ifdef COMPILER_GCC + +typedef union DoubleFloatUnion { + double d; + long long int ll; + unsigned long long ull; +} DoubleFloatUnion; + +/** + * Gets float32 from uint64_t. + * + * https://gcc.gnu.org/onlinedocs/gccint/the-gcc-low-level-runtime-library/routines-for-floating-point-emulation.html#c.__floatundisf + */ +float __floatundisf(unsigned long long i) { + register DoubleFloatUnion dull; + register float ret; + + dull.ull = i; + __asm__("cvt.s.l %0, %1" : "=f"(ret) : "f"(dull.d)); + if ((long) i < 0) { + // cvt.s.l assumes signed input, adjust output + ret += 4294967296.0f; // 2^32 + } + + return ret; +} +#endif diff --git a/src/libultra/libc/ll.c b/src/libultra/libc/ll.c index a3cee6d7..6f64e972 100644 --- a/src/libultra/libc/ll.c +++ b/src/libultra/libc/ll.c @@ -1,3 +1,4 @@ +#include "mods.h" long long __ull_rshift(unsigned long long left, unsigned long long right) { return left >> right; @@ -44,3 +45,10 @@ long long __ll_mod(long long left, long long right) { long long __ll_rshift(long long left, long long right) { return left >> right; } + +// IDO FIX +#if MODS_FPS_COUNTER == 1 +float __ull_to_f(unsigned long long u) { + return u; +} +#endif diff --git a/src/mods/fpscounter.c b/src/mods/fpscounter.c new file mode 100644 index 00000000..2be76dff --- /dev/null +++ b/src/mods/fpscounter.c @@ -0,0 +1,47 @@ +#include "global.h" + +// SDK states that 1 cycle takes about 21.33 nanoseconds +#if 1 +#define SECONDS_PER_CYCLE 0.00000002133f +#else +// Use this macro if your N64 CPU is overclocked to 125 Mhz (x2 Multiplier) +#define SECONDS_PER_CYCLE 0.000000016f +#endif + +#define FPS_COUNTER_X_POS 14 +#define FPS_COUNTER_Y_POS 9 + +static OSTime gLastOSTime = 0; +static float gFrameTime = 0.0f; +static u16 gFrames = 0; +static u16 gFPS = 0; +static u8 gRenderFPS = false; + +static void CalculateFrameTimeFromOSTime(OSTime diff) { + gFrameTime += diff * SECONDS_PER_CYCLE; + gFrames++; +} + +static void Play_RenderFps(void) { + // Toggle rendering framerate with the L button. + if (gControllerPress[0].button & L_TRIG) { + gRenderFPS ^= 1; + } + if (gRenderFPS) { + OSTime newTime = osGetTime(); + CalculateFrameTimeFromOSTime(newTime - gLastOSTime); + // If frame time is longer or equal to a second, update FPS counter. + if (gFrameTime >= 1.0f) { + gFPS = gFrames; + gFrames = 0; + gFrameTime -= 1.0f; + } + + /* Draw */ + RCP_SetupDL(&gMasterDisp, 0x53); + gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255); + Graphics_DisplaySmallText(FPS_COUNTER_X_POS, FPS_COUNTER_Y_POS, 1.0f, 1.0f, "FPS:"); + Graphics_DisplaySmallNumber(FPS_COUNTER_X_POS + 35, FPS_COUNTER_Y_POS, gFPS); + gLastOSTime = newTime; + } +} diff --git a/src/mods/levelselect.c b/src/mods/levelselect.c index 55718f5e..5c5f8da6 100644 --- a/src/mods/levelselect.c +++ b/src/mods/levelselect.c @@ -3,13 +3,18 @@ extern PlanetId sPlanetList[15]; extern PlanetId sCurrentPlanetId; +extern s32 D_menu_801B8280; +extern s32 D_menu_801CD968; + +void Map_801A61B4(LevelId level); void Map_801A6368(void); void Map_801A914C(void); +void Map_801A6628(void); void Map_LevelSelect(void) { static char* sLevelSelectPlanetNames[] = { - "CORNERIA", "METEO", "TITANIA", "SECTOR X", "AQUAS", "BOLSE", "VENOM", "FORTUNA", - "AREA 6", "MACBETH", "SECTOR Z", "ZONESS", "KATINA", "SECTOR Y", "SOLAR", + "METEO", "AREA 6", "BOLSE", "SECTOR Z", "SECTOR X", "SECTOR Y", "KATINA", "MACBETH", + "ZONESS", "CORNERIA", "TITANIA", "AQUAS", "FORTUNA", "VENOM", "SOLAR", }; if (gControllerPress[0].button & L_JPAD) { @@ -33,10 +38,19 @@ void Map_LevelSelect(void) { } /* Draw */ + if ((sCurrentPlanetId >= 0) && (sCurrentPlanetId < PLANET_MAX)) { + RCP_SetupDL(&gMasterDisp, 0x53); + gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255); - RCP_SetupDL(&gMasterDisp, 0x53); - gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255); + Graphics_DisplaySmallText(20, 200, 1.0f, 1.0f, "PLANET:"); + Graphics_DisplaySmallText(80, 200, 1.0f, 1.0f, sLevelSelectPlanetNames[sCurrentPlanetId]); + } - Graphics_DisplaySmallText(20, 200, 1.0f, 1.0f, "PLANET:"); - Graphics_DisplaySmallText(80, 200, 1.0f, 1.0f, sLevelSelectPlanetNames[gCurrentPlanet]); + // Bypass briefing + if (gControllerPress[0].button & A_BUTTON) { + Map_801A61B4(gCurrentLevel); + D_menu_801B8280 = 0; + D_menu_801CD968 = 0; + Map_801A6628(); + } } diff --git a/src/overlays/ovl_menu/fox_map.c b/src/overlays/ovl_menu/fox_map.c index f94c7875..4e6a22bc 100644 --- a/src/overlays/ovl_menu/fox_map.c +++ b/src/overlays/ovl_menu/fox_map.c @@ -2539,7 +2539,7 @@ void Map_801A1C14(void) { D_menu_801CD964 = 1; D_menu_801CD96C = 1; // clang-format off - for (i = 0; i < 15; i++) {D_menu_801CD900[i] = 0;} + for (i = 0; i < 15; i++) { D_menu_801CD900[i] = 0; } // clang-format on D_menu_801CD970 = 0; @@ -2557,7 +2557,7 @@ void Map_801A1C14(void) { } bool Map_801A2304(void) { - s32 ret = false; + bool ret = false; f32 sp28; f32 sp24; f32 sp20; diff --git a/yamls/us/main.yaml b/yamls/us/main.yaml index 98f9b483..c80f1b94 100644 --- a/yamls/us/main.yaml +++ b/yamls/us/main.yaml @@ -47,6 +47,9 @@ - [0x206B0, c, libc_math64] - [0x20A60, hasm, libc_math64_fp] + # GCC + - [auto, c, libultra/gcc_fix/__floatundisf] + # Libultra - [0x20BC0, c, libultra/io/controller] - [0x20F80, c, libultra/io/contreaddata]