diff --git a/docs/MODDING.md b/docs/MODDING.md index d410a0d0641..5947f4bdf1a 100644 --- a/docs/MODDING.md +++ b/docs/MODDING.md @@ -65,22 +65,22 @@ Let's begin by finding where the time is updated. Thankfully in the save editor So this tells us that `gSaveContext.dayTime` is what we're looking for. Let's now do a global search for this to see if we can find where it is updated. We find the following in `soh/src/code/z_kankyo.c` around line 925: ```cpp -if (IS_DAY || gTimeIncrement >= 0x190) { - gSaveContext.dayTime += gTimeIncrement; +if (IS_DAY || gTimeSpeed >= 0x190) { + gSaveContext.dayTime += gTimeSpeed; } else { - gSaveContext.dayTime += gTimeIncrement * 2; // time moves twice as fast at night + gSaveContext.dayTime += gTimeSpeed * 2; // time moves twice as fast at night } ``` -We can make a quick change to this code to verify this is indeed what we are looking for, lets multiply the gTimeIncrement by 10: +We can make a quick change to this code to verify this is indeed what we are looking for, lets multiply the gTimeSpeed by 10: ```diff -if (IS_DAY || gTimeIncrement >= 0x190) { -- gSaveContext.dayTime += gTimeIncrement; -+ gSaveContext.dayTime += gTimeIncrement * 10; +if (IS_DAY || gTimeSpeed >= 0x190) { +- gSaveContext.dayTime += gTimeSpeed; ++ gSaveContext.dayTime += gTimeSpeed * 10; } else { -- gSaveContext.dayTime += gTimeIncrement * 2; // time moves twice as fast at night -+ gSaveContext.dayTime += gTimeIncrement * 2 * 10; // time moves twice as fast at night +- gSaveContext.dayTime += gTimeSpeed * 2; // time moves twice as fast at night ++ gSaveContext.dayTime += gTimeSpeed * 2 * 10; // time moves twice as fast at night } ``` @@ -102,12 +102,12 @@ This adds a `Widget` which sets a CVar, which then sets the options of the slide Now we need to replace our hard coded values with the new variable. We can do this by replacing the `10` with a cvar call ```diff -if (IS_DAY || gTimeIncrement >= 0x190) { -- gSaveContext.dayTime += gTimeIncrement * 10; -+ gSaveContext.dayTime += gTimeIncrement * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f); +if (IS_DAY || gTimeSpeed >= 0x190) { +- gSaveContext.dayTime += gTimeSpeed * 10; ++ gSaveContext.dayTime += gTimeSpeed * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f); } else { -- gSaveContext.dayTime += gTimeIncrement * 2 * 10; -+ gSaveContext.dayTime += gTimeIncrement * 2 * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f); +- gSaveContext.dayTime += gTimeSpeed * 2 * 10; ++ gSaveContext.dayTime += gTimeSpeed * 2 * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f); } ``` diff --git a/soh/include/alignment.h b/soh/include/alignment.h index 7a3b94ea2c3..87e88688af5 100644 --- a/soh/include/alignment.h +++ b/soh/include/alignment.h @@ -7,9 +7,12 @@ #define ALIGN64(val) (((val) + 0x3F) & ~0x3F) #define ALIGN256(val) (((val) + 0xFF) & ~0xFF) +// TODO: Update these #ifdef __GNUC__ +#define ALIGNED4 __attribute__ ((aligned (4))) #define ALIGNED8 __attribute__ ((aligned (8))) #else +#define ALIGNED4 #define ALIGNED8 #endif diff --git a/soh/include/debug_display.h b/soh/include/debug_display.h new file mode 100644 index 00000000000..a6fe03ed034 --- /dev/null +++ b/soh/include/debug_display.h @@ -0,0 +1,28 @@ +#ifndef DEBUG_DISPLAY_H +#define DEBUG_DISPLAY_H + +#include +#include "z64math.h" +#include + +#include "extern_c_helper.h" + +struct GraphicsContext; +struct PlayState; + +typedef struct DebugDispObject { + /* 0x00 */ Vec3f pos; + /* 0x0C */ Vec3s rot; + /* 0x14 */ Vec3f scale; + /* 0x20 */ Color_RGBA8 color; + /* 0x24 */ s16 type; + /* 0x28 */ struct DebugDispObject* next; +} DebugDispObject; // size = 0x2C + +EXTERN_C void DebugDisplay_Init(void); +EXTERN_C DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX, + f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type, + struct GraphicsContext* gfxCtx); +EXTERN_C void DebugDisplay_DrawObjects(struct PlayState* play); + +#endif \ No newline at end of file diff --git a/soh/include/environment.h b/soh/include/environment.h new file mode 100644 index 00000000000..fed5f7ef899 --- /dev/null +++ b/soh/include/environment.h @@ -0,0 +1,244 @@ +#ifndef ENVIRONMENT_H_ +#define ENVIRONMENT_H_ + +#include "z64math.h" +#include "z64light.h" +#include "z64dma.h" + +#include "extern_c_helper.h" + +struct GameOverContext; +struct MessageContext; +struct PauseContext; +struct PlayState; +struct SkyboxContext; +struct View; + +#define FILL_SCREEN_OPA (1 << 0) +#define FILL_SCREEN_XLU (1 << 1) + +// TODO: NEXT_TIME macros + +// TODO: LIGHT_SETTING macros + +// TODO: LIGHT_BLEND macros + +// TODO: LightMode enum + +typedef enum SkyboxDmaState { + /* 0 */ SKYBOX_DMA_INACTIVE, + /* 1 */ SKYBOX_DMA_FILE1_START, + /* 2 */ SKYBOX_DMA_FILE1_DONE, + /* 3 */ SKYBOX_DMA_PAL1_START, + /* 11 */ SKYBOX_DMA_FILE2_START = 11, + /* 12 */ SKYBOX_DMA_FILE2_DONE, + /* 13 */ SKYBOX_DMA_PAL2_START +} SkyboxDmaState; + +typedef enum LightningMode { + /* 0 */ LIGHTNING_MODE_OFF, // no lightning + /* 1 */ LIGHTNING_MODE_ON, // request ligtning strikes at random intervals + /* 2 */ LIGHTNING_MODE_LAST // request one lightning strike before turning off +} LightningMode; + +typedef enum LightningStrikeState { + /* 0 */ LIGHTNING_STRIKE_WAIT, // wait between lightning strikes. request bolts when timer hits 0 + /* 1 */ LIGHTNING_STRIKE_START, // fade in the flash. note: bolts are requested in the previous state + /* 2 */ LIGHTNING_STRIKE_END // fade out the flash and go back to wait +} LightningStrikeState; + +// TODO: WeatherMode enum + +// TODO: ChangeSkyboxState enum + +// TODO: PrecipitationData enum + +// TODO: StormRequest enum + +// TODO: StormState enum + +// TODO: TimeBasedSeqState enum + +typedef enum SandstormState { + /* 0 */ SANDSTORM_OFF, + /* 1 */ SANDSTORM_FILL, + /* 2 */ SANDSTORM_UNFILL, + /* 3 */ SANDSTORM_ACTIVE, + /* 4 */ SANDSTORM_DISSIPATE +} SandstormState; + +typedef struct LightningStrike { + /* 0x00 */ u8 state; + /* 0x01 */ u8 flashRed; + /* 0x02 */ u8 flashGreen; + /* 0x03 */ u8 flashBlue; + /* 0x04 */ u8 flashAlphaTarget; + /* 0x08 */ f32 delayTimer; +} LightningStrike; // size = 0xC + +// TODO: Update the type to upstream (TimeBasedSkyboxEntry) +// describes what skybox files and blending modes to use depending on time of day +typedef struct struct_8011FC1C { + /* 0x00 */ u16 startTime; + /* 0x02 */ u16 endTime; + /* 0x04 */ u8 blend; // if true, blend between.. skyboxes? palettes? + /* 0x05 */ u8 skybox1Index; // whats the difference between _pal and non _pal files? + /* 0x06 */ u8 skybox2Index; +} struct_8011FC1C; // size = 0x8 + +// TODO: CurrentEnvLightSettings struct + +// `EnvLightSettings` is very similar to `CurrentEnvLightSettings` with one key difference. +// The light settings data in the scene packs blend rate information with the fog near value. +// The blendRate determines how fast the current light settings fade to the next one +// (under LIGHT_MODE_SETTINGS, otherwise unused). + +// TODO: BLEND_RATE macro + +// TODO: ENV_LIGHT macros + +// TODO: Update the type to upstream +typedef struct EnvLightSettings { + /* 0x00 */ u8 ambientColor[3]; + /* 0x03 */ s8 light1Dir[3]; + /* 0x06 */ u8 light1Color[3]; + /* 0x09 */ s8 light2Dir[3]; + /* 0x0C */ u8 light2Color[3]; + /* 0x0F */ u8 fogColor[3]; + /* 0x12 */ s16 fogNear; + /* 0x14 */ s16 fogFar; +} EnvLightSettings; // size = 0x16 + +// TODO: Update the type to upstream +typedef struct EnvironmentContext { + /* 0x00 */ char unk_00[0x02]; + /* 0x02 */ u16 timeIncrement; // how many units of time that pass every update + /* 0x04 */ Vec3f sunPos; // moon position can be found by negating the sun position + /* 0x10 */ u8 skybox1Index; + /* 0x11 */ u8 skybox2Index; + /* 0x12 */ char unk_12[0x01]; + /* 0x13 */ u8 skyboxBlend; + /* 0x14 */ char unk_14[0x01]; + /* 0x15 */ u8 skyboxDisabled; + /* 0x16 */ u8 sunMoonDisabled; + /* 0x17 */ u8 unk_17; // currentWeatherMode for skybox? (prev called gloomySky) + /* 0x18 */ u8 unk_18; // nextWeatherMode for skybox? + /* 0x19 */ u8 unk_19; + /* 0x1A */ u16 unk_1A; + /* 0x1C */ char unk_1C[0x02]; + /* 0x1E */ u8 indoors; // when set, day time has no effect on lighting + /* 0x1F */ u8 unk_1F; // outdoor light index + /* 0x20 */ u8 unk_20; // prev outdoor light index? + /* 0x21 */ u8 unk_21; + /* 0x22 */ u16 unk_22; + /* 0x24 */ u16 unk_24; + /* 0x26 */ char unk_26[0x02]; + /* 0x28 */ LightInfo dirLight1; // used for sunlight outdoors + /* 0x36 */ LightInfo dirLight2; // used for moonlight outdoors + /* 0x44 */ s8 skyboxDmaState; + /* 0x48 */ DmaRequest dmaRequest; + /* 0x68 */ OSMesgQueue loadQueue; + /* 0x80 */ OSMesg loadMsg; + /* 0x84 */ f32 unk_84; + /* 0x88 */ f32 unk_88; + /* 0x8C */ s16 adjAmbientColor[3]; + /* 0x92 */ s16 adjLight1Color[3]; + /* 0x98 */ s16 adjFogColor[3]; + /* 0x9E */ s16 adjFogNear; + /* 0xA0 */ s16 adjFogFar; + /* 0xA2 */ char unk_A2[0x06]; + /* 0xA8 */ Vec3s windDirection; + /* 0xB0 */ f32 windSpeed; + /* 0xB4 */ u8 numLightSettings; + /* 0xB8 */ EnvLightSettings* lightSettingsList; // list of light settings from the scene file + /* 0xBC */ u8 blendIndoorLights; // when true, blend between indoor light settings when switching + /* 0xBD */ u8 unk_BD; // indoor light index + /* 0xBE */ u8 unk_BE; // prev indoor light index? + /* 0xBF */ u8 unk_BF; + /* 0xC0 */ EnvLightSettings lightSettings; + /* 0xD6 */ u16 unk_D6; + /* 0xD8 */ f32 unk_D8; // indoor light blend weight? + /* 0xDC */ u8 unk_DC; + /* 0xDD */ u8 gloomySkyMode; + /* 0xDE */ u8 unk_DE; // gloomy sky state + /* 0xDF */ u8 lightningMode; + /* 0xE0 */ u8 unk_E0; // env sounds state + /* 0xE1 */ u8 fillScreen; + /* 0xE2 */ u8 screenFillColor[4]; + /* 0xE6 */ u8 sandstormState; + /* 0xE7 */ u8 sandstormPrimA; + /* 0xE8 */ u8 sandstormEnvA; + /* 0xE9 */ u8 customSkyboxFilter; + /* 0xEA */ u8 skyboxFilterColor[4]; + /* 0xEE */ u8 unk_EE[4]; + /* 0xF2 */ u8 unk_F2[4]; + /* 0xF6 */ char unk_F6[0x06]; +} EnvironmentContext; // size = 0xFC + +// TODO: Rename variables +EXTERN_C u8 gSkyboxBlendingEnabled; +EXTERN_C struct_8011FC1C D_8011FC1C[][9]; + +EXTERN_C u8 gWeatherMode; +EXTERN_C u8 D_8011FB34; +EXTERN_C u8 D_8011FB38; +EXTERN_C u16 gTimeSpeed; + +EXTERN_C LightningStrike gLightningStrike; + +// TODO: These variables are here for BSS ordering but ideally they should not +// be extern. This could be fixed by putting more stuff (e.g. struct definitions) +// between gLightningStrike and gCustomLensFlareOn. +// TODO: Missing variables +EXTERN_C u8 gCustomLensFlareOn; +EXTERN_C Vec3f gCustomLensFlarePos; +EXTERN_C s16 gLensFlareScale; +EXTERN_C f32 gLensFlareColorIntensity; +EXTERN_C s16 gLensFlareScreenFillAlpha; + +// Environment_UpdateSkybox was updated during porting to add a PlayState* argument? +EXTERN_C void Environment_UpdateSkybox(struct PlayState* play, u8 skyboxId, EnvironmentContext* envCtx, struct SkyboxContext* skyboxCtx); +EXTERN_C void Environment_DrawSkyboxFilters(struct PlayState* play); + +// TODO: Rename to Environment_ZBufValToFixedPoint +EXTERN_C s32 func_8006F0A0(s32 arg0); +EXTERN_C u16 Environment_GetPixelDepth(s32 x, s32 y); +EXTERN_C void Environment_GraphCallback(struct GraphicsContext* gfxCtx, void* param); +EXTERN_C void Environment_Init(struct PlayState* play2, EnvironmentContext* envCtx, s32 unused); +EXTERN_C u8 Environment_SmoothStepToU8(u8* pvalue, u8 target, u8 scale, u8 step, u8 minStep); +EXTERN_C u8 Environment_SmoothStepToS8(s8* pvalue, s8 target, u8 scale, u8 step, u8 minStep); +EXTERN_C f32 Environment_LerpWeight(u16 max, u16 min, u16 val); +EXTERN_C f32 Environment_LerpWeightAccelDecel(u16 endFrame, u16 startFrame, u16 curFrame, u16 accelDuration, u16 decelDuration); +EXTERN_C void Environment_EnableUnderwaterLights(struct PlayState* play, s32 waterLightsIndex); +EXTERN_C void Environment_DisableUnderwaterLights(struct PlayState* play); +EXTERN_C void Environment_Update(struct PlayState* play, EnvironmentContext* envCtx, LightContext* lightCtx, + struct PauseContext* pauseCtx, struct MessageContext* msgCtx, + struct GameOverContext* gameOverCtx, struct GraphicsContext* gfxCtx); +EXTERN_C void Environment_DrawSunAndMoon(struct PlayState* play); +EXTERN_C void Environment_DrawSunLensFlare(struct PlayState* play, EnvironmentContext* envCtx, struct View* view, + struct GraphicsContext* gfxCtx, Vec3f pos, s32 unused); +EXTERN_C void Environment_DrawLensFlare(struct PlayState* play, EnvironmentContext* envCtx, struct View* view, + struct GraphicsContext* gfxCtx, Vec3f pos, s32 unused, s16 arg6, f32 arg7, s16 arg8, u8 arg9); +EXTERN_C void Environment_DrawRain(struct PlayState* play, struct View* view, struct GraphicsContext* gfxCtx); +// TODO: Rename to Environment_ChangeLightSetting +EXTERN_C void func_80074CE8(struct PlayState* play, u32 arg1); +EXTERN_C void Environment_UpdateLightningStrike(struct PlayState* play); +EXTERN_C void Environment_AddLightningBolts(struct PlayState* play, u8 num); +EXTERN_C void Environment_DrawLightning(struct PlayState* play, s32 unused); +EXTERN_C void Environment_PlaySceneSequence(struct PlayState* play); +EXTERN_C void Environment_DrawCustomLensFlare(struct PlayState* play); +EXTERN_C void Environment_InitGameOverLights(struct PlayState* play); +EXTERN_C void Environment_FadeInGameOverLights(struct PlayState* play); +EXTERN_C void Environment_FadeOutGameOverLights(struct PlayState* play); +EXTERN_C void Environment_FillScreen(struct GraphicsContext* gfxCtx, u8 red, u8 green, u8 blue, u8 alpha, u8 drawFlags); +EXTERN_C void Environment_DrawSandstorm(struct PlayState* play, u8 sandstormState); +EXTERN_C void Environment_AdjustLights(struct PlayState* play, f32 arg1, f32 arg2, f32 arg3, f32 arg4); +EXTERN_C s32 Environment_GetBgsDayCount(void); +EXTERN_C void Environment_ClearBgsDayCount(void); +EXTERN_C s32 Environment_GetTotalDays(void); +EXTERN_C void Environment_ForcePlaySequence(u16 seqId); +EXTERN_C s32 Environment_IsForcedSequenceDisabled(void); +EXTERN_C void Environment_PlayStormNatureAmbience(struct PlayState* play); +EXTERN_C void Environment_StopStormNatureAmbience(struct PlayState* play); +EXTERN_C void Environment_WarpSongLeave(struct PlayState* play); +#endif diff --git a/soh/include/extern_c_helper.h b/soh/include/extern_c_helper.h new file mode 100644 index 00000000000..4801a0d29e3 --- /dev/null +++ b/soh/include/extern_c_helper.h @@ -0,0 +1,9 @@ +#pragma once + +// SoH: Helper for headers which can be included in both C & C++ + +#if __cplusplus +#define EXTERN_C extern "C" +#else +#define EXTERN_C extern +#endif \ No newline at end of file diff --git a/soh/include/font.h b/soh/include/font.h new file mode 100644 index 00000000000..7fae7fed0f5 --- /dev/null +++ b/soh/include/font.h @@ -0,0 +1,39 @@ +#ifndef FONT_H +#define FONT_H + +#include + +#include "extern_c_helper.h" + +// #region SoH [Port]: Increased char buffer because texture paths could be bigger than (16 * 16 / 2) +#define FONT_CHAR_MULTIPLIER 256 +// #endregion + +// TODO get these properties from the textures themselves +#define FONT_CHAR_TEX_WIDTH 16 +#define FONT_CHAR_TEX_HEIGHT 16 +#define FONT_CHAR_TEX_SIZE ((FONT_CHAR_TEX_WIDTH * FONT_CHAR_TEX_HEIGHT) / 2) // 16x16 I4 texture + +// TODO: Update the type to upstream +typedef struct Font { + /* 0x0000 */ uintptr_t msgOffset; + /* 0x0004 */ u32 msgLength; + /* 0x0008 */ u8 charTexBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER]; + /* 0x3C08 */ u8 iconBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER]; + /* 0x3C88 */ u8 fontBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER]; + union { + /* 0xDC88 */ char msgBuf[1280]; + /* 0xDC88 */ u16 msgBufWide[640]; + }; +} Font; // size = 0xE188 + +// TODO: PLATFORM macros +#if false//PLATFORM_IQUE +EXTERN_C void Font_LoadCharCHN(Font* font, u16 character, u16 codePointIndex); +#endif +EXTERN_C void Font_LoadCharWide(Font* font, u16 character, u16 codePointIndex); +EXTERN_C void Font_LoadChar(Font* font, u8 character, u16 codePointIndex); +EXTERN_C void Font_LoadMessageBoxIcon(Font* font, u16 icon); +EXTERN_C void Font_LoadOrderedFont(Font* font); + +#endif \ No newline at end of file diff --git a/soh/include/functions.h b/soh/include/functions.h index 3e2954b7743..1e5d0056687 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -12,6 +12,7 @@ extern "C" #include #include +#include "libu64/gfxprint.h" #if (LOG_LEVEL_GAME_PRINTS >= SPDLOG_ACTIVE_LEVEL) && !(LOG_LEVEL_GAME_PRINTS >= 6) #define osSyncPrintf(...) lusprintf(__FILE__, __LINE__, LOG_LEVEL_GAME_PRINTS , __VA_ARGS__) @@ -102,11 +103,9 @@ s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag); void __osInitialize_common(void); void __osInitialize_autodetect(void); void __osExceptionPreamble(); -// ? __osException(?); void __osEnqueueAndYield(OSThread**); void __osEnqueueThread(OSThread**, OSThread*); OSThread* __osPopThread(OSThread**); -// ? __osNop(?); void __osDispatchThread(); void __osCleanupThread(void); void __osDequeueThread(OSThread** queue, OSThread* thread); @@ -574,20 +573,11 @@ u16 func_80037C30(PlayState* play, s16 arg1); s32 func_80037D98(PlayState* play, Actor* actor, s16 arg2, s32* arg3); s32 Actor_TrackPlayer(PlayState* play, Actor* actor, Vec3s* arg2, Vec3s* arg3, Vec3f arg4); -// ? func_80038600(?); u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList*); void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest); f32 CollisionPoly_GetPointDistanceFromPlane(CollisionPoly* poly, Vec3f* point); -CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest); -s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionContext* colCtx, f32* outY, Vec3f* pos, - f32 checkHeight, CollisionPoly** outPoly); -s32 BgCheck_CheckLineAgainstSSList(SSList* headNodeId, CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, - Vec3f* posA, Vec3f* posB, Vec3f* outPos, CollisionPoly** outPoly, f32* outDistSq, - f32 chkDist, s32 bccFlags); -void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* arg2); void BgCheck_Allocate(CollisionContext* colCtx, PlayState* play, CollisionHeader* colHeader); -s32 BgCheck_PosInStaticBoundingBox(CollisionContext* colCtx, Vec3f* pos); f32 BgCheck_EntityRaycastFloor1(CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos); f32 BgCheck_EntityRaycastFloor2(PlayState* play, CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos); @@ -851,15 +841,8 @@ s32 func_800635D0(s32); void func_800636C0(void); void func_8006375C(s32 arg0, s32 arg1, const char* text); void func_8006376C(u8 x, u8 y, u8 colorId, const char* text); -// ? func_80063828(?); void func_8006390C(Input* input); -// ? func_80063C04(?); void func_80063D7C(GraphicsContext* gfxCtx); -void DebugDisplay_Init(void); -DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX, - f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type, - GraphicsContext* gfxCtx); -void DebugDisplay_DrawObjects(PlayState* play); void func_8006450C(PlayState* play, CutsceneContext* csCtx); void func_80064520(PlayState* play, CutsceneContext* csCtx); void func_80064534(PlayState* play, CutsceneContext* csCtx); @@ -890,62 +873,9 @@ void SkelCurve_SetAnim(SkelAnimeCurve* skelCurve, TransformUpdateIndex* transUpd s32 SkelCurve_Update(PlayState* play, SkelAnimeCurve* skelCurve); void SkelCurve_Draw(Actor* actor, PlayState* play, SkelAnimeCurve* skelCurve, OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, void* data); -s32 Horse_CanSpawn(s32 scene); -void Horse_ResetHorseData(PlayState* play); -void Horse_FixLakeHyliaPosition(PlayState* play); -void Horse_SetupInGameplay(PlayState* play, Player* player); -void Horse_SetupInCutscene(PlayState* play, Player* player); -void Horse_InitPlayerHorse(PlayState* play, Player* player); -void Horse_RotateToPoint(Actor* actor, Vec3f* arg1, s16 arg2); -s32 Jpeg_Decode(void* data, void* zbuffer, void* workBuff, u32 workSize); void KaleidoSetup_Update(PlayState* play); void KaleidoSetup_Init(PlayState* play); void KaleidoSetup_Destroy(PlayState* play); -void Font_LoadCharWide(Font* font, u16 arg1, u16 arg2); -void Font_LoadChar(Font* font, u8 character, u16 codePointIndex); -void Font_LoadMessageBoxIcon(Font* font, u16 icon); -void Font_LoadOrderedFont(Font* font); -s32 func_8006F0A0(s32 arg0); -u16 Environment_GetPixelDepth(s32 x, s32 y); -void Environment_GraphCallback(GraphicsContext* gfxCtx, void* param); -void Environment_Init(PlayState* play, EnvironmentContext* envCtx, s32 unused); -u8 Environment_SmoothStepToU8(u8* pvalue, u8 target, u8 scale, u8 step, u8 minStep); -u8 Environment_SmoothStepToS8(s8* pvalue, s8 target, u8 scale, u8 step, u8 minStep); -f32 Environment_LerpWeight(u16 max, u16 min, u16 val); -f32 Environment_LerpWeightAccelDecel(u16 endFrame, u16 startFrame, u16 curFrame, u16 accelDuration, u16 decelDuration); -void Environment_UpdateSkybox(PlayState* play, u8 skyboxId, EnvironmentContext* envCtx, SkyboxContext* skyboxCtx); -void Environment_EnableUnderwaterLights(PlayState* play, s32 waterLightsIndex); -void Environment_DisableUnderwaterLights(PlayState* play); -void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContext* lightCtx, - PauseContext* pauseCtx, MessageContext* msgCtx, GameOverContext* gameOverCtx, - GraphicsContext* gfxCtx); -void Environment_DrawSunAndMoon(PlayState* play); -void Environment_DrawSunLensFlare(PlayState* play, EnvironmentContext* envCtx, View* view, - GraphicsContext* gfxCtx, Vec3f pos, s32 unused); -void Environment_DrawLensFlare(PlayState* play, EnvironmentContext* envCtx, View* view, - GraphicsContext* gfxCtx, Vec3f pos, s32 unused, s16 arg6, f32 arg7, s16 arg8, u8 arg9); -void Environment_DrawRain(PlayState* play, View* view, GraphicsContext* gfxCtx); -void func_80074CE8(PlayState* play, u32 arg1); -void Environment_DrawSkyboxFilters(PlayState* play); -void Environment_UpdateLightningStrike(PlayState* play); -void Environment_AddLightningBolts(PlayState* play, u8 num); -void Environment_DrawLightning(PlayState* play, s32 unused); -void Environment_PlaySceneSequence(PlayState* play); -void Environment_DrawCustomLensFlare(PlayState* play); -void Environment_InitGameOverLights(PlayState* play); -void Environment_FadeInGameOverLights(PlayState* play); -void Environment_FadeOutGameOverLights(PlayState* play); -void Environment_FillScreen(GraphicsContext* gfxCtx, u8 red, u8 green, u8 blue, u8 alpha, u8 drawFlags); -void Environment_DrawSandstorm(PlayState* play, u8 sandstormState); -void Environment_AdjustLights(PlayState* play, f32 arg1, f32 arg2, f32 arg3, f32 arg4); -s32 Environment_GetBgsDayCount(void); -void Environment_ClearBgsDayCount(void); -s32 Environment_GetTotalDays(void); -void Environment_ForcePlaySequence(u16 seqId); -s32 Environment_IsForcedSequenceDisabled(void); -void Environment_PlayStormNatureAmbience(PlayState* play); -void Environment_StopStormNatureAmbience(PlayState* play); -void Environment_WarpSongLeave(PlayState* play); f32 Math_CosS(s16 angle); f32 Math_SinS(s16 angle); f32 Math_AccurateCosS(s16 angle); @@ -1030,20 +960,6 @@ u8 ZeldaArena_IsInitalized(); void MapMark_Init(PlayState* play); void MapMark_ClearPointers(PlayState* play); void MapMark_Draw(PlayState* play); -void PreNmiBuff_Init(PreNmiBuff* this); -void PreNmiBuff_SetReset(PreNmiBuff* this); -u32 PreNmiBuff_IsResetting(PreNmiBuff* this); -void MsgEvent_SendNullTask(void); -f32 OLib_Vec3fDist(Vec3f* a, Vec3f* b); -f32 OLib_Vec3fDistXZ(Vec3f* a, Vec3f* b); -f32 OLib_ClampMinDist(f32 val, f32 min); -f32 OLib_ClampMaxDist(f32 val, f32 max); -Vec3f* OLib_Vec3fDistNormalize(Vec3f* dest, Vec3f* a, Vec3f* b); -Vec3f* OLib_VecSphGeoToVec3f(Vec3f* dest, VecSph* sph); -VecSph* OLib_Vec3fToVecSph(VecSph* dest, Vec3f* vec); -VecSph* OLib_Vec3fToVecSphGeo(VecSph* arg0, Vec3f* arg1); -VecSph* OLib_Vec3fDiffToVecSphGeo(VecSph* arg0, Vec3f* a, Vec3f* b); -Vec3f* OLib_Vec3fDiffRad(Vec3f* dest, Vec3f* a, Vec3f* b); void OnePointCutscene_SetCsCamPoints(Camera* camera, s16 actionParameters, s16 initTimer, CutsceneCameraPoint* atPoints, CutsceneCameraPoint* eyePoints); s16 OnePointCutscene_Init(PlayState* play, s16 csId, s16 timer, Actor* actor, s16 camIdx); s16 OnePointCutscene_EndCutscene(PlayState* play, s16 camIdx); @@ -1157,31 +1073,6 @@ u32 func_80091738(PlayState* play, u8* segment, SkelAnime* skelAnime); void Player_DrawPause(PlayState* play, u8* segment, SkelAnime* skelAnime, Vec3f* pos, Vec3s* rot, f32 scale, s32 sword, s32 tunic, s32 shield, s32 boots); void PreNMI_Init(GameState* thisx); -Vec3f* Quake_AddVec(Vec3f* dst, Vec3f* arg1, VecSph* arg2); -void Quake_UpdateShakeInfo(QuakeRequest* req, ShakeInfo* shake, f32 y, f32 x); -s16 Quake_Callback1(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_Callback2(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_Callback3(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_Callback4(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_Callback5(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_Callback6(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_GetFreeIndex(void); -QuakeRequest* Quake_AddImpl(Camera* cam, u32 callbackIdx); -void Quake_Remove(QuakeRequest* req); -QuakeRequest* Quake_GetRequest(s16 idx); -QuakeRequest* Quake_SetValue(s16 idx, s16 valueType, s16 value); -u32 Quake_SetSpeed(s16 idx, s16 value); -u32 Quake_SetCountdown(s16 idx, s16 value); -s16 Quake_GetCountdown(s16 idx); -u32 Quake_SetQuakeValues(s16 idx, s16 y, s16 x, s16 zoom, s16 rotZ); -u32 Quake_SetUnkValues(s16 idx, s16 arg1, SubQuakeRequest14 arg2); -void Quake_Init(void); -s16 Quake_Add(Camera* cam, u32 callbackIdx); -u32 Quake_RemoveFromIdx(s16 idx); -s16 Quake_Calc(Camera* camera, QuakeCamCalc* camData); -Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); -Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); -Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); Gfx* Gfx_SetupDL(Gfx* gfx, u32 i); Gfx* Gfx_SetupDL_57(Gfx* gfx); Gfx* Gfx_SetupDL_52NoCD(Gfx* gfx); @@ -1218,21 +1109,6 @@ void Gfx_SetupDL_27Xlu(GraphicsContext* gfxCtx); void Gfx_SetupDL_60NoCDXlu(GraphicsContext* gfxCtx); void Gfx_SetupDL_61Xlu(GraphicsContext* gfxCtx); void Gfx_SetupDL_56Ptr(Gfx** gfxp); -Gfx* Gfx_BranchTexScroll(Gfx** gfxp, u32 x, u32 y, s32 width, s32 height); -Gfx* func_80094E78(GraphicsContext* gfxCtx, u32 x, u32 y); -Gfx* Gfx_TexScroll(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height); -Gfx* Gfx_TexScrollEx(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height, s32 xStep, s32 yStep); -Gfx* Gfx_TwoTexScroll(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, - u32 y2, s32 width2, s32 height2); -Gfx* Gfx_TwoTexScrollEx(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, - u32 y2, s32 width2, s32 height2, s32 xStep1, s32 yStep1, s32 xStep2, s32 yStep2); -Gfx* Gfx_TwoTexScrollEnvColor(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, - u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a); -Gfx* Gfx_TwoTexScrollEnvColorEx(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, - u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a, s32 xStep1, s32 yStep1, s32 xStep2, s32 yStep2); -Gfx* Gfx_EnvColor(GraphicsContext* gfxCtx, s32 r, s32 g, s32 b, s32 a); -void Gfx_SetupFrame(GraphicsContext* gfxCtx, u8 r, u8 g, u8 b); -void func_80095974(GraphicsContext* gfxCtx); void func_80095AA0(PlayState* play, Room* room, Input* arg2, UNK_TYPE arg3); void Room_DrawBackground2D(Gfx** gfxP, void* tex, void* tlut, u16 width, u16 height, u8 fmt, u8 siz, u16 tlutMode, u16 tlutCount, f32 offsetX, f32 offsetY); @@ -1356,28 +1232,12 @@ void Skin_GetLimbPos(Skin* skin, s32 limbIndex, Vec3f* arg2, Vec3f* dst); void Skin_Init(PlayState* play, Skin* skin, SkeletonHeader* skeletonHeader, AnimationHeader* animationHeader); void Skin_Free(PlayState* play, Skin* skin); s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* mf, Actor* actor, s32 setTranslation); - -void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest); -void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest); -void SkinMatrix_MtxFMtxFMult(MtxF* mfA, MtxF* mfB, MtxF* dest); -void SkinMatrix_GetClear(MtxF** mf); -void SkinMatrix_Clear(MtxF* mf); -void SkinMatrix_MtxFCopy(MtxF* src, MtxF* dest); -s32 SkinMatrix_Invert(MtxF* src, MtxF* dest); -void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z); -void SkinMatrix_SetRotateZYX(MtxF* mf, s16 x, s16 y, s16 z); -void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z); -void SkinMatrix_SetTranslateRotateYXZScale(MtxF* dest, f32 scaleX, f32 scaleY, f32 scaleZ, s16 rotX, s16 rotY, s16 rotZ, - f32 translateX, f32 translateY, f32 translateZ); -void SkinMatrix_SetTranslateRotateZYX(MtxF* dest, s16 rotX, s16 rotY, s16 rotZ, f32 translateX, f32 translateY, - f32 translateZ); -Mtx* SkinMatrix_MtxFToNewMtx(GraphicsContext* gfxCtx, MtxF* src); -void SkinMatrix_SetRotateAxis(MtxF* mf, s16 angle, f32 axisX, f32 axisY, f32 axisZ); void Sram_OpenSave(); void Sram_InitSave(FileChooseContext* fileChoose); void Sram_InitSram(GameState* gameState); void SsSram_ReadWrite(uintptr_t addr, void* dramAddr, size_t size, s32 direction); -void func_800A9F30(PadMgr*, s32); +struct PadMgr; +void func_800A9F30(struct PadMgr*, s32); void func_800A9F6C(f32, u8, u8, u8); void Rumble_Request(f32, u8, u8, u8); void func_800AA0B4(); @@ -1414,11 +1274,6 @@ s32 func_800AB560(View* view); s32 func_800AB944(View* view); s32 func_800AB9EC(View* view, s32 arg1, Gfx** p); s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ); -void ViMode_LogPrint(OSViMode* viMode); -void ViMode_Configure(ViMode* viMode, s32 mode, s32 type, s32 unk_70, s32 unk_74, s32 unk_78, s32 unk_7C, s32 width, - s32 height, s32 unk_left, s32 unk_right, s32 unk_top, s32 unk_bottom); -void ViMode_Save(ViMode* viMode); -void ViMode_Load(ViMode* viMode); void ViMode_Init(ViMode* viMode); void ViMode_Destroy(ViMode* viMode); void ViMode_ConfigureFeatures(ViMode* viMode, s32 viFeatures); @@ -1475,49 +1330,12 @@ u32 ShrinkWindow_GetCurrentVal(void); void ShrinkWindow_Init(void); void ShrinkWindow_Destroy(void); void ShrinkWindow_Update(s32 updateRate); -// ? DbCamera_AddVecSph(?); -// ? DbCamera_CalcUpFromPitchYawRoll(?); -// ? DbCamera_SetTextValue(?); -// ? DbCamera_Vec3SToF(?); -// ? DbCamera_Vec3FToS(?); -// ? DbCamera_CopyVec3f(?); -// ? DbCamera_Vec3SToF2(?); -// ? func_800B3F94(?); -// ? func_800B3FF4(?); -// ? func_800B404C(?); -// ? func_800B4088(?); -// ? func_800B41DC(?); -// ? func_800B42C0(?); -// ? func_800B4370(?); -// ? func_800B44E0(?); -// ? DbCamera_PrintPoints(?); -// ? DbCamera_PrintF32Bytes(?); -// ? DbCamera_PrintU16Bytes(?); -// ? DbCamera_PrintS16Bytes(?); -// ? DbCamera_PrintCutBytes(?); void DbCamera_Init(DbCamera* dbCamera, Camera* cameraPtr); void DbgCamera_Enable(DbCamera* dbCamera, Camera* cam); void DbCamera_Update(DbCamera* dbCamera, Camera* cam); -// ? DbCamera_GetFirstAvailableLetter(?); -// ? DbCamera_InitCut(?); -// ? DbCamera_ResetCut(?); -// ? DbCamera_CalcMempakAllocSize(?); -// ? DbCamera_GetMempakAllocSize(?); -// ? DbCamera_DrawSlotLetters(?); -// ? DbCamera_PrintAllCuts(?); -// ? func_800B91B0(?); void DbCamera_Reset(Camera* cam, DbCamera* dbCam); -// ? DbCamera_UpdateDemoControl(?); void func_800BB0A0(f32 u, Vec3f* pos, f32* roll, f32* viewAngle, f32* point0, f32* point1, f32* point2, f32* point3); s32 func_800BB2B4(Vec3f* pos, f32* roll, f32* fov, CutsceneCameraPoint* point, s16* keyframe, f32* curFrame); -s32 Mempak_Init(s32 controllerNb); -s32 Mempak_GetFreeBytes(s32 controllerNb); -s32 Mempak_FindFile(s32 controllerNb, char start, char end); -s32 Mempak_Write(s32 controllerNb, char idx, void* buffer, s32 offset, ptrdiff_t size); -s32 Mempak_Read(s32 controllerNb, char idx, void* buffer, s32 offset, ptrdiff_t size); -s32 Mempak_Alloc(s32 controllerNb, char* idx, ptrdiff_t size); -s32 Mempak_DeleteFile(s32 controllerNb, char idx); -s32 Mempak_GetFileSize(s32 controllerNb, char idx); void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl); void KaleidoManager_ClearOvl(KaleidoMgrOverlay* ovl); void KaleidoManager_Init(PlayState* play); @@ -1588,35 +1406,6 @@ void func_800C24E0(PreRender* this, Gfx** gfxp); void func_800C2500(PreRender* this, s32 x, s32 y); void func_800C2FE4(PreRender* this); void PreRender_Calc(PreRender* this); -void THGA_Ct(TwoHeadGfxArena* thga, Gfx* start, size_t size); -void THGA_Dt(TwoHeadGfxArena* thga); -u32 THGA_IsCrash(TwoHeadGfxArena* thga); -void THGA_Init(TwoHeadGfxArena* thga); -s32 THGA_GetSize(TwoHeadGfxArena* thga); -Gfx* THGA_GetHead(TwoHeadGfxArena* thga); -void THGA_SetHead(TwoHeadGfxArena* thga, Gfx* start); -Gfx* THGA_GetTail(TwoHeadGfxArena* thga); -Gfx* THGA_AllocStartArray8(TwoHeadGfxArena* thga, u32 count); -Gfx* THGA_AllocStart8(TwoHeadGfxArena* thga); -Gfx* THGA_AllocStart8Wrapper(TwoHeadGfxArena* thga); -Gfx* THGA_AllocEnd(TwoHeadGfxArena* thga, size_t size); -Gfx* THGA_AllocEndArray64(TwoHeadGfxArena* thga, u32 count); -Gfx* THGA_AllocEnd64(TwoHeadGfxArena* thga); -Gfx* THGA_AllocEndArray16(TwoHeadGfxArena* thga, u32 count); -Gfx* THGA_AllocEnd16(TwoHeadGfxArena* thga); -void* THA_GetHead(TwoHeadArena* tha); -void THA_SetHead(TwoHeadArena* tha, void* start); -void* THA_GetTail(TwoHeadArena* tha); -void* THA_AllocStart(TwoHeadArena* tha, size_t size); -void* THA_AllocStart1(TwoHeadArena* tha); -void* THA_AllocEnd(TwoHeadArena* tha, size_t size); -void* THA_AllocEndAlign16(TwoHeadArena* tha, size_t size); -void* THA_AllocEndAlign(TwoHeadArena* tha, size_t size, size_t mask); -s32 THA_GetSize(TwoHeadArena* tha); -u32 THA_IsCrash(TwoHeadArena* tha); -void THA_Init(TwoHeadArena* tha); -void THA_Ct(TwoHeadArena* tha, void* ptr, size_t size); -void THA_Dt(TwoHeadArena* tha); void func_800C3C20(void); void func_800C3C80(AudioMgr* audioMgr); void AudioMgr_HandleRetrace(AudioMgr* audioMgr); @@ -1629,11 +1418,9 @@ void TitleSetup_Destroy(GameState* gameState); void TitleSetup_Init(GameState* gameState); void GameState_FaultPrint(void); void GameState_SetFBFilter(Gfx** gfx); -// ? func_800C4344(?); void GameState_DrawInputDisplay(u16 input, Gfx** gfx); void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx); void GameState_SetFrameBuffer(GraphicsContext* gfxCtx); -// ? func_800C49F4(?); void GameState_ReqPadData(GameState* gameState); void GameState_Update(GameState* gameState); void GameState_InitArena(GameState* gameState, size_t size); @@ -1649,20 +1436,6 @@ void* GameAlloc_Malloc(GameAlloc* this, size_t size); void GameAlloc_Free(GameAlloc* this, void* data); void GameAlloc_Cleanup(GameAlloc* this); void GameAlloc_Init(GameAlloc* this); -void Graph_FaultClient(); -void Graph_DisassembleUCode(Gfx* workBuf); -void Graph_UCodeFaultClient(Gfx* workBuf); -void Graph_InitTHGA(GraphicsContext* gfxCtx); -GameStateOverlay* Graph_GetNextGameState(GameState* gameState); -void Graph_Init(GraphicsContext* gfxCtx); -void Graph_Destroy(GraphicsContext* gfxCtx); -void Graph_TaskSet00(GraphicsContext* gfxCtx); -void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState); -void Graph_ThreadEntry(void*); -void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size); -void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size); -void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line); -void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line); Gfx* Graph_GfxPlusOne(Gfx* gfx); Gfx* Graph_BranchDlist(Gfx* gfx, Gfx* dst); void* Graph_DlistAlloc(Gfx** gfx, size_t size); @@ -1672,39 +1445,6 @@ void ListAlloc_Free(ListAlloc* this, void* data); void ListAlloc_FreeAll(ListAlloc* this); void Main_LogSystemHeap(void); void Main(void* arg); -OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padmgr); -void PadMgr_UnlockSerialMesgQueue(PadMgr* padmgr, OSMesgQueue* ctrlrqueue); -void PadMgr_LockPadData(PadMgr* padmgr); -void PadMgr_UnlockPadData(PadMgr* padmgr); -void PadMgr_RumbleControl(PadMgr* padmgr); -void PadMgr_RumbleStop(PadMgr* padmgr); -void PadMgr_RumbleReset(PadMgr* padmgr); -void PadMgr_RumbleSet(PadMgr* padmgr, u8* ctrlrRumbles); -void PadMgr_ProcessInputs(PadMgr* padmgr); -void PadMgr_HandleRetraceMsg(PadMgr* padmgr); -void PadMgr_HandlePreNMI(PadMgr* padmgr); -// This function must remain commented out, because it is called incorrectly in -// fault.c (actual bug in game), and the compiler notices and won't compile it -void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode); -void PadMgr_Init(PadMgr* padmgr, OSMesgQueue* siIntMsgQ, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack); -void Sched_SwapFrameBuffer(CfbInfo* cfbInfo); -void func_800C84E4(SchedContext* sc, CfbInfo* cfbInfo); -void Sched_HandleReset(SchedContext* sc); -void Sched_HandleStart(SchedContext* sc); -void Sched_QueueTask(SchedContext* sc, OSScTask* task); -void Sched_Yield(SchedContext* sc); -OSScTask* func_800C89D4(SchedContext* sc, OSScTask* task); -s32 Sched_Schedule(SchedContext* sc, OSScTask** sp, OSScTask** dp, s32 state); -void func_800C8BC4(SchedContext* sc, OSScTask* task); -u32 Sched_IsComplete(SchedContext* sc, OSScTask* task); -void Sched_RunTask(SchedContext* sc, OSScTask* spTask, OSScTask* dpTask); -void Sched_HandleEntry(SchedContext* sc); -void Sched_HandleRetrace(SchedContext* sc); -void Sched_HandleRSPDone(SchedContext* sc); -void Sched_HandleRDPDone(SchedContext* sc); -void Sched_SendEntryMsg(SchedContext* sc); -void Sched_ThreadEntry(void* arg); -void Sched_Init(SchedContext* sc, void* stack, OSPri priority, UNK_TYPE arg3, UNK_TYPE arg4, IrqMgr* irqMgr); void SpeedMeter_InitImpl(SpeedMeter* this, u32 arg1, u32 y); void SpeedMeter_Init(SpeedMeter* this); void SpeedMeter_Destroy(SpeedMeter* this); @@ -1721,73 +1461,6 @@ f32 Math_Factorial(s32 n); f32 Math_PowF(f32 base, s32 exp); f32 Math_SinF(f32 angle); f32 Math_CosF(f32 angle); -s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, - f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, - Vec3f* closestPoint); -void Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint); -s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, - f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint); -void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret); -f32 Math3D_Cos(Vec3f* a, Vec3f* b); -s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst); -void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec); -s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y); -f32 Math3D_Dist1DSq(f32 a, f32 b); -f32 Math3D_Dist2DSq(f32 x0, f32 y0, f32 x1, f32 y1); -f32 Math3D_Vec3fMagnitudeSq(Vec3f* vec); -f32 Math3D_Vec3fMagnitude(Vec3f* vec); -f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); -void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret); -void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal); -f32 Math3D_Vec3f_DistXYZ(Vec3f* a, Vec3f* b); -s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max); -s32 Math3D_PointRelativeToCubeEdges(Vec3f* point, Vec3f* min, Vec3f* max); -s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max); -s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); -void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d); -void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist); -f32 Math3D_UDistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); -f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); -s32 Math3D_TriChkPointParaYSlopedY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x); -s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, - f32 x, f32* yIntersect, f32 chkDist); -s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, - f32 z, f32 x, f32* yIntersect, f32 chkDist); -s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, - f32 x, f32* yIntersect, f32 y0, f32 y1); -s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 z, f32 x, f32 chkDist); -s32 Math3D_TriChkPointParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, - f32 z, f32* xIntersect); -s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, - f32 z, f32* xIntersect, f32 x0, f32 x1); -s32 Math3D_TriChkPointParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 y, f32 z, f32 chkDist); -s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, - f32 y, f32* zIntersect); -s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, - f32 y, f32* zIntersect, f32 z0, f32 z1); -s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist); -s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, - Vec3f* intersect, s32 fromFront); -void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc); -s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); -s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); -s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); -s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); -s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri); -s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect); -s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB); -s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize); -s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); -s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize); -s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist); -s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace); -s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist); -s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect); -s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); -s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); -s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); -void Math3D_DrawSphere(PlayState* play, Sphere16* sph); -void Math3D_DrawCylinder(PlayState* play, Cylinder16* cyl); s16 Math_Atan2S(f32 x, f32 y); f32 Math_Atan2F(f32 x, f32 y); void Matrix_Init(GameState* gameState); @@ -1830,18 +1503,6 @@ void func_800D3178(UnkRumbleStruct* arg0); void func_800D31A0(void); void func_800D31F0(void); void func_800D3210(void); -void IrqMgr_AddClient(IrqMgr* this, IrqMgrClient* c, OSMesgQueue* msgQ); -void IrqMgr_RemoveClient(IrqMgr* this, IrqMgrClient* c); -void IrqMgr_SendMesgForClient(IrqMgr* this, OSMesg msg); -void IrqMgr_JamMesgForClient(IrqMgr* this, OSMesg msg); -void IrqMgr_HandlePreNMI(IrqMgr* this); -void IrqMgr_CheckStack(); -void IrqMgr_HandlePRENMI450(IrqMgr* this); -void IrqMgr_HandlePRENMI480(IrqMgr* this); -void IrqMgr_HandlePRENMI500(IrqMgr* this); -void IrqMgr_HandleRetrace(IrqMgr* this); -void IrqMgr_ThreadEntry(void* arg0); -void IrqMgr_Init(IrqMgr* this, void* stack, OSPri pri, u8 retraceCount); void DebugArena_CheckPointer(void* ptr, size_t size, const char* name, const char* action); void* DebugArena_Malloc(size_t size); void* DebugArena_MallocDebug(size_t size, const char* file, s32 line); @@ -1918,15 +1579,8 @@ void FaultDrawer_DrawText(s32, s32, const char*, ...); void FaultDrawer_SetDrawerFB(void*, u16, u16); void FaultDrawer_SetInputCallback(void (*)()); void FaultDrawer_SetDefault(); -// ? UCodeDisas_TranslateAddr(?); -// ? UCodeDisas_ParseCombineColor(?); -// ? UCodeDisas_ParseCombineAlpha(?); void UCodeDisas_Init(UCodeDisas*); void UCodeDisas_Destroy(UCodeDisas*); -// ? UCodeDisas_SetCurUCodeImpl(?); -// ? UCodeDisas_ParseGeometryMode(?); -// ? UCodeDisas_ParseRenderMode(?); -// ? UCodeDisas_PrintVertices(?); //void UCodeDisas_Disassemble(UCodeDisas*, Gfx*); void UCodeDisas_RegisterUCode(UCodeDisas* this, s32 count, UCodeInfo* ucodeArray); void UCodeDisas_SetCurUCode(UCodeDisas*, void*); @@ -2122,10 +1776,7 @@ void Audio_SetCutsceneFlag(s8 flag); void Audio_PlaySoundIfNotInCutscene(u16 sfxId); void func_800F6964(u16); void Audio_StopBgmAndFanfare(u16); -// ? Audio_DisableAllSeq(?); -// ? func_800F6BB8(?); void Audio_PreNMI(); -// ? func_800F6C34(?); void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 port, u8 val); void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId); void Audio_Init(); @@ -2166,15 +1817,6 @@ void func_800FA3DC(void); u8 func_800FAD34(void); void Audio_ResetActiveSequences(void); void func_800FAEB4(void); -void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a); -void GfxPrint_SetPosPx(GfxPrint* this, s32 x, s32 y); -void GfxPrint_SetPos(GfxPrint* this, s32 x, s32 y); -void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y); -void GfxPrint_Init(GfxPrint* this); -void GfxPrint_Destroy(GfxPrint* this); -void GfxPrint_Open(GfxPrint* this, Gfx* dList); -Gfx* GfxPrint_Close(GfxPrint* this); -s32 GfxPrint_Printf(GfxPrint* this, const char* fmt, ...); void func_800FBCE0(); void func_800FBFD8(void); void* Overlay_AllocateAndLoad(uintptr_t vRomStart, uintptr_t vRomEnd, void* vRamStart, void* vRamEnd); @@ -2182,35 +1824,7 @@ void MtxConv_F2L(Mtx* m1, MtxF* m2); void MtxConv_L2F(MtxF* m1, Mtx* m2); void Overlay_Relocate(void* allocatedVRamAddress, OverlayRelocationSection* overlayInfo, void* vRamAddress); s32 Overlay_Load(uintptr_t vRomStart, uintptr_t vRomEnd, void* vRamStart, void* vRamEnd, void* allocatedVRamAddress); -// ? func_800FC800(?); -// ? func_800FC83C(?); -// ? func_800FCAB4(?); void SystemHeap_Init(void* start, size_t size); -void PadUtils_Init(Input* input); -void func_800FCB70(void); -void PadUtils_ResetPressRel(Input* input); -u32 PadUtils_CheckCurExact(Input* input, u16 value); -u32 PadUtils_CheckCur(Input* input, u16 key); -u32 PadUtils_CheckPressed(Input* input, u16 key); -u32 PadUtils_CheckReleased(Input* input, u16 key); -u16 PadUtils_GetCurButton(Input* input); -u16 PadUtils_GetPressButton(Input* input); -s8 PadUtils_GetCurX(Input* input); -s8 PadUtils_GetCurY(Input* input); -void PadUtils_SetRelXY(Input* input, s32 x, s32 y); -s8 PadUtils_GetRelXImpl(Input* input); -s8 PadUtils_GetRelYImpl(Input* input); -s8 PadUtils_GetRelX(Input* input); -s8 PadUtils_GetRelY(Input* input); -void PadUtils_UpdateRelXY(Input* input); -s8 PadUtils_GetCurRX(Input* input); -s8 PadUtils_GetCurRY(Input* input); -void PadUtils_SetRelRXY(Input* input, s32 x, s32 y); -s8 PadUtils_GetRelRXImpl(Input* input); -s8 PadUtils_GetRelRYImpl(Input* input); -s8 PadUtils_GetRelRX(Input* input); -s8 PadUtils_GetRelRY(Input* input); -void PadUtils_UpdateRelRXY(Input* input); s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status); f32 Math_FTanF(f32 x); f32 Math_FFloorF(f32 x); @@ -2222,10 +1836,6 @@ f32 Math_FAtanF(f32 x); f32 Math_FAtan2F(f32 y, f32 x); f32 Math_FAsinF(f32 x); f32 Math_FAcosF(f32 x); -/*f32 ceilf(f32 x); -f32 truncf(f32 x); -f32 roundf(f32 x); -f32 nearbyintf(f32 x);*/ void SystemArena_CheckPointer(void* ptr, size_t size, const char* name, const char* action); void* SystemArena_Malloc(size_t size); void* SystemArena_MallocDebug(size_t size, const char* file, s32 line); @@ -2291,23 +1901,6 @@ s32 __osCheckArena(Arena* arena); u8 func_800FF334(Arena* arena); s32 PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args); s32 PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...); -void Sleep_Cycles(OSTime cycles); -void Sleep_Nsec(u32 nsec); -void Sleep_Usec(u32 usec); -void Sleep_Msec(u32 ms); -void Sleep_Sec(u32 sec); -void JpegUtils_ProcessQuantizationTable(u8* dqt, JpegQuantizationTable* qt, u8 count); -s32 JpegUtils_ParseHuffmanCodesLengths(u8* ptr, u8* codesLengths); -s32 JpegUtils_GetHuffmanCodes(u8* codesLengths, u16* codes); -s32 JpegUtils_SetHuffmanTable(u8* data, JpegHuffmanTable* ht, u16* codes); -u32 JpegUtils_ProcessHuffmanTableImpl(u8* data, JpegHuffmanTable* ht, u8* codesLengths, u16* codes, u8 isAc); -u32 JpegUtils_ProcessHuffmanTable(u8* dht, JpegHuffmanTable* ht, u8* codesLengths, u16* codes, u8 count); -void JpegUtils_SetHuffmanTableOld(u8* data, JpegHuffmanTableOld* ht, u8* codesLengths, u16* codes, s16 count, u8 isAc); -u32 JpegUtils_ProcessHuffmanTableImplOld(u8* dht, JpegHuffmanTableOld* ht, u8* codesLengths, u16* codes); -s32 JpegDecoder_Decode(JpegDecoder* decoder, u16* mcuBuff, s32 count, u8 isFollowing, JpegDecoderState* state); -s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1, u16* mcu, s16* unk); -s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, s8* outZeroCount); -u16 JpegDecoder_ReadBits(u8 len); s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes); void guScale(Mtx* m, f32 x, f32 y, f32 z); s16 sins(u16); @@ -2400,14 +1993,6 @@ u32 __osSpGetStatus(void); void __osSpSetStatus(u32 status); void osWritebackDCacheAll(void); OSThread* __osGetCurrFaultedThread(void); -// ? __d_to_ll(?); -// ? __f_to_ll(?); -// ? __d_to_ull(?); -// ? __f_to_ull(?); -// ? __ll_to_d(?); -// ? __ll_to_f(?); -// ? __ull_to_d(?); -// ? __ull_to_f(?); u32* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* pc); f32 absf(f32); @@ -2445,8 +2030,6 @@ void FileChoose_Destroy(GameState* thisx); void Heaps_Alloc(void); void Heaps_Free(void); -CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); - // Exposing these methods to leverage them from the file select screen to render messages void Message_OpenText(PlayState* play, u16 textId); void Message_Decode(PlayState* play); diff --git a/soh/include/gfx.h b/soh/include/gfx.h index d8aa9945ff9..4c2baf2842c 100644 --- a/soh/include/gfx.h +++ b/soh/include/gfx.h @@ -1,9 +1,182 @@ #ifndef GFX_H #define GFX_H +#include +#include +#include "alignment.h" +#include "sched.h" +#include "thga.h" +#include "z64.h" + +#include "extern_c_helper.h" + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + // Texture memory size, 4 KiB #define TMEM_SIZE 0x1000 -// Upstream TODO: Rest of this file +// #region SoH [Interpolation]: Due to interpolation frames also using these buffers, we've doubled them in size +// TODO: Fix this + +typedef struct GfxPool { + /* 0x00000 */ u16 headMagic; // GFXPOOL_HEAD_MAGIC + /* 0x00008 */ Gfx polyOpaBuffer[0x2FC0]; + /* 0x0BF08 */ Gfx polyXluBuffer[0x1000]; + /* 0x0FF08 */ Gfx overlayBuffer[0x800]; + /* 0x11F08 */ Gfx workBuffer[0x100]; + /* 0x11308 */ Gfx unusedBuffer[0x40]; + /* 0x12408 */ u16 tailMagic; // GFXPOOL_TAIL_MAGIC +} GfxPool; // size = 0x24820 + +// #endregion + +typedef struct GraphicsContext { + /* 0x0000 */ Gfx* polyOpaBuffer; // Pointer to "Zelda 0" + /* 0x0004 */ Gfx* polyXluBuffer; // Pointer to "Zelda 1" + /* 0x0008 */ char unk_008[0x08]; // Unused, could this be pointers to "Zelda 2" / "Zelda 3" + /* 0x0010 */ Gfx* overlayBuffer; // Pointer to "Zelda 4" + /* 0x0014 */ u32 unk_014; + /* 0x0018 */ char unk_018[0x20]; + /* 0x0038 */ OSMesg msgBuff[0x08]; + /* 0x0058 */ OSMesgQueue* schedMsgQ; // ASDAFG: schedMsgQueue + /* 0x005C */ OSMesgQueue queue; + /* 0x0078 */ OSScTask task; + /* 0x00E0 */ char unk_0D0[0xD0]; + /* 0x01B0 */ Gfx* workBuffer; + /* 0x01B4 */ TwoHeadGfxArena work; + /* 0x01C4 */ char unk_01C4[0xC0]; + /* 0x0284 */ OSViMode* viMode; + /* 0x0288 */ char unk_0288[0x20]; // Unused, could this be Zelda 2/3 ? + /* 0x02A8 */ TwoHeadGfxArena overlay; // "Zelda 4" + /* 0x02B8 */ TwoHeadGfxArena polyOpa; // "Zelda 0" + /* 0x02C8 */ TwoHeadGfxArena polyXlu; // "Zelda 1" + /* 0x02D8 */ u32 gfxPoolIdx; + /* 0x02DC */ u16* curFrameBuffer; + /* 0x02E0 */ char unk_2E0[0x04]; + /* 0x02E4 */ u32 viFeatures; + /* 0x02E8 */ s32 fbIdx; + /* 0x02EC */ void (*callback)(struct GraphicsContext*, void*); + /* 0x02F0 */ void* callbackParam; +// TODO: Define & use OOT_VERSION +#if true//OOT_VERSION >= PAL_1_0 + /* 0x02F4 */ f32 xScale; + /* 0x02F8 */ f32 yScale; + /* 0x02FC */ char unk_2FC[0x04]; +#endif +} GraphicsContext; // size = 0x300 + +extern Gfx gEmptyDL[]; + +EXTERN_C Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); +EXTERN_C Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); +EXTERN_C Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); + +EXTERN_C Gfx* Gfx_BranchTexScroll(Gfx** gfxp, u32 x, u32 y, s32 width, s32 height); +EXTERN_C Gfx* func_80094E78(GraphicsContext* gfxCtx, u32 x, u32 y); +EXTERN_C Gfx* Gfx_TexScroll(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height); +EXTERN_C Gfx* Gfx_TwoTexScroll(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, + u32 y2, s32 width2, s32 height2); +EXTERN_C Gfx* Gfx_TwoTexScrollEnvColor(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, + u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a); +EXTERN_C Gfx* Gfx_EnvColor(GraphicsContext* gfxCtx, s32 r, s32 g, s32 b, s32 a); +EXTERN_C void Gfx_SetupFrame(GraphicsContext* gfxCtx, u8 r, u8 g, u8 b); +EXTERN_C void func_80095974(GraphicsContext* gfxCtx); + +// #region SoH [Interpolation]: Versions with xStep & yStep to aid texture scrolling interpolation +EXTERN_C Gfx* Gfx_TexScrollEx(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height, s32 xStep, s32 yStep); +EXTERN_C Gfx* Gfx_TwoTexScrollEx(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, + u32 y2, s32 width2, s32 height2, s32 xStep1, s32 yStep1, s32 xStep2, s32 yStep2); +EXTERN_C Gfx* Gfx_TwoTexScrollEnvColorEx(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, + u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a, s32 xStep1, s32 yStep1, s32 xStep2, s32 yStep2); +// #endregion + +EXTERN_C void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size); +EXTERN_C void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size); + +#define WORK_DISP __gfxCtx->work.p +#define POLY_OPA_DISP __gfxCtx->polyOpa.p +#define POLY_XLU_DISP __gfxCtx->polyXlu.p +#define OVERLAY_DISP __gfxCtx->overlay.p + +EXTERN_C void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line); +EXTERN_C void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line); + +// __gfxCtx shouldn't be used directly. +// Use the DISP macros defined above when writing to display buffers. +// #region SOH [General] +// Augmented to provide debug information in debug build and support interpolation +#ifndef NDEBUG +#define OPEN_DISPS(gfxCtx) \ + { \ + void FrameInterpolation_RecordOpenChild(const void* a, int b); \ + FrameInterpolation_RecordOpenChild(__FILE__, __LINE__); \ + GraphicsContext* __gfxCtx; \ + Gfx* dispRefs[4]; \ + __gfxCtx = gfxCtx; \ + (void)__gfxCtx; \ + Graph_OpenDisps(dispRefs, gfxCtx, __FILE__, __LINE__) +#else +#define OPEN_DISPS(gfxCtx) \ + { \ + void FrameInterpolation_RecordOpenChild(const void* a, int b); \ + FrameInterpolation_RecordOpenChild(__FILE__, __LINE__); \ + GraphicsContext* __gfxCtx; \ + __gfxCtx = gfxCtx; \ + (void)__gfxCtx; +#endif + +#ifndef NDEBUG +#define CLOSE_DISPS(gfxCtx) \ + {void FrameInterpolation_RecordCloseChild(void); \ + FrameInterpolation_RecordCloseChild();} \ + Graph_CloseDisps(dispRefs, gfxCtx, __FILE__, __LINE__); \ + } \ + (void)0 +#else +#define CLOSE_DISPS(gfxCtx) \ + {void FrameInterpolation_RecordCloseChild(void); \ + FrameInterpolation_RecordCloseChild();} \ + (void)0; \ + } \ + (void)0 +#endif +// #endregion + +// TODO: GRAPH_ALLOC macro + +void Graph_ThreadEntry(void*); + +extern u64 gMojiFontTLUTs[4][4]; // original name: "moji_tlut" +extern u64 gMojiFontTex[]; // original name: "font_ff" + +/** + * `x` vertex x + * `y` vertex y + * `z` vertex z + * `s` texture s coordinate + * `t` texture t coordinate + * `crnx` red component of color vertex, or x component of normal vertex + * `cgny` green component of color vertex, or y component of normal vertex + * `cbnz` blue component of color vertex, or z component of normal vertex + * `a` alpha + */ +#define VTX(x,y,z,s,t,crnx,cgny,cbnz,a) { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } } } + +#define VTX_T(x,y,z,s,t,cr,cg,cb,a) { { x, y, z }, 0, { s, t }, { cr, cg, cb, a } } + +// TODO: Update the macro to the decomp version +#define gDPSetTileCustom(pkt, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + do { \ + gDPPipeSync(pkt); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + } while (0) #endif diff --git a/soh/include/horse.h b/soh/include/horse.h new file mode 100644 index 00000000000..e0cfc3315c7 --- /dev/null +++ b/soh/include/horse.h @@ -0,0 +1,18 @@ +#ifndef HORSE_H +#define HORSE_H + +#include +#include "z64math.h" + +#include "extern_c_helper.h" + +struct PlayState; +struct Actor; +struct Player; + +EXTERN_C void Horse_ResetHorseData(struct PlayState* play); +EXTERN_C void Horse_FixLakeHyliaPosition(struct PlayState* play); +EXTERN_C void Horse_InitPlayerHorse(struct PlayState* play, struct Player* player); +EXTERN_C void Horse_RotateToPoint(struct Actor* actor, Vec3f* arg1, s16 arg2); + +#endif \ No newline at end of file diff --git a/soh/include/irqmgr.h b/soh/include/irqmgr.h new file mode 100644 index 00000000000..4d9d5abdeeb --- /dev/null +++ b/soh/include/irqmgr.h @@ -0,0 +1,51 @@ +#ifndef IRQMGR_H +#define IRQMGR_H + +#include + +#include "extern_c_helper.h" + +#define OS_SC_RETRACE_MSG 1 +#define OS_SC_DONE_MSG 2 +#define OS_SC_NMI_MSG 3 // name is made up, 3 is OS_SC_RDP_DONE_MSG in the original sched.c +#define OS_SC_PRE_NMI_MSG 4 + +// TODO: IrqResetStatus enum + +typedef struct OSScMsg { + /* 0x00 */ s16 type; + /* 0x02 */ char misc[0x1E]; +} OSScMsg; // size = 0x20 + +typedef struct IrqMgrClient { + /* 0x00 */ struct IrqMgrClient* prev; + /* 0x04 */ OSMesgQueue* queue; +} IrqMgrClient; + +typedef struct IrqMgr { + /* 0x000 */ OSScMsg retraceMsg; + /* 0x020 */ OSScMsg prenmiMsg; + /* 0x040 */ OSScMsg nmiMsg; + /* 0x060 */ OSMesgQueue queue; + /* 0x078 */ OSMesg msgBuf[8]; + /* 0x098 */ OSThread thread; + /* 0x248 */ IrqMgrClient* clients; + /* 0x24C */ u8 resetStatus; + /* 0x250 */ OSTime resetTime; + /* 0x258 */ OSTimer timer; + /* 0x278 */ OSTime retraceTime; +} IrqMgr; // size = 0x280 + +#ifdef __cplusplus +#define this thisx +#endif + +EXTERN_C void IrqMgr_Init(IrqMgr* this, void* stack, OSPri pri, u8 retraceCount); +EXTERN_C void IrqMgr_AddClient(IrqMgr* this, IrqMgrClient* c, OSMesgQueue* msgQ); +EXTERN_C void IrqMgr_RemoveClient(IrqMgr* this, IrqMgrClient* c); + +#ifdef __cplusplus +#undef this +#endif + +#endif \ No newline at end of file diff --git a/soh/include/jpeg.h b/soh/include/jpeg.h new file mode 100644 index 00000000000..cd13f057044 --- /dev/null +++ b/soh/include/jpeg.h @@ -0,0 +1,88 @@ +#ifndef JPEG_H +#define JPEG_H + +#include +#include "z64.h" + +#include "extern_c_helper.h" + +typedef struct JpegQuantizationTable { + /* 0x00 */ u16 table[8*8]; +} JpegQuantizationTable; // size = 0x80 + +typedef struct JpegHuffmanTable { + /* 0x00 */ u8 codeOffs[16]; + /* 0x10 */ u16 codesA[16]; + /* 0x30 */ u16 codesB[16]; + /* 0x50 */ u8* symbols; +} JpegHuffmanTable; // size = 0x54 + +// this struct might be inaccurate but it's not used outside jpegutils.c anyways +typedef struct JpegHuffmanTableOld { + /* 0x000 */ u8 codeOffs[16]; + /* 0x010 */ u16 dcCodes[120]; + /* 0x100 */ u16 acCodes[256]; +} JpegHuffmanTableOld; // size = 0x300 + +// TODO: Update the type to upstream +typedef struct JpegTaskData { + /* 0x00 */ u32 address; + /* 0x04 */ u32 mbCount; + /* 0x08 */ u32 mode; + /* 0x0C */ u32 qTableYPtr; + /* 0x10 */ u32 qTableUPtr; + /* 0x14 */ u32 qTableVPtr; + /* 0x18 */ u32 mbSize; // This field is used by the microcode to save the macroblock size during a yield +} JpegTaskData; // size = 0x20 + +typedef struct JpegWork { + /* 0x000 */ JpegTaskData taskData; + /* 0x020 */ u64 yieldData[0x200 / sizeof(u64)]; + /* 0x220 */ JpegQuantizationTable qTableY; + /* 0x2A0 */ JpegQuantizationTable qTableU; + /* 0x320 */ JpegQuantizationTable qTableV; + /* 0x3A0 */ u8 codesLengths[0x110]; + /* 0x4B0 */ u16 codes[0x108]; + /* 0x6C0 */ u16 data[4][0x180]; +} JpegWork; // size = 0x12C0 + +typedef struct JpegDecoder { + /* 0x00 */ void* imageData; + /* 0x04 */ u8 mode; + /* 0x05 */ u8 unk_05; + /* 0x08 */ JpegHuffmanTable* hTablePtrs[4]; + /* 0x18 */ u8 unk_18; +} JpegDecoder; // size = 0x1C + +typedef struct JpegContext { + /* 0x00 */ u8 dqtCount; + /* 0x04 */ u8* dqtPtr[3]; + /* 0x10 */ u8 dhtCount; + /* 0x14 */ u8* dhtPtr[4]; + /* 0x24 */ void* imageData; + /* 0x28 */ u32 mode; // 0 if Y V0 is 1 and 2 if Y V0 is 2 + /* 0x30 */ OSScTask scTask; + /* 0x88 */ char unk_88[0x10]; + /* 0x98 */ OSMesgQueue mq; + /* 0xB0 */ OSMesg msg; + /* 0xB4 */ JpegWork* workBuf; +} JpegContext; // size = 0xB8 + +typedef struct JpegDecoderState { + /* 0x00 */ u32 byteIdx; + /* 0x04 */ u8 bitIdx; + /* 0x05 */ u8 dontSkip; + /* 0x08 */ u32 curWord; + /* 0x0C */ s16 unk_0C; + /* 0x0E */ s16 unk_0E; + /* 0x10 */ s16 unk_10; +} JpegDecoderState; // size = 0x14 + +EXTERN_C s32 Jpeg_Decode(void* data, void* zbuffer, void* workBuff, u32 workSize); + +EXTERN_C void JpegUtils_ProcessQuantizationTable(u8* dqt, JpegQuantizationTable* qt, u8 count); +EXTERN_C u32 JpegUtils_ProcessHuffmanTable(u8* dht, JpegHuffmanTable* ht, u8* codesLengths, u16* codes, u8 count); + +EXTERN_C s32 JpegDecoder_Decode(JpegDecoder* decoder, u16* mcuBuff, s32 count, u8 isFollowing, JpegDecoderState* state); + +#endif \ No newline at end of file diff --git a/soh/include/libc64/sleep.h b/soh/include/libc64/sleep.h new file mode 100644 index 00000000000..68680dc5695 --- /dev/null +++ b/soh/include/libc64/sleep.h @@ -0,0 +1,12 @@ +#ifndef LIBC64_SLEEP_H +#define LIBC64_SLEEP_H + +#include + +void Sleep_Cycles(OSTime cycles); +void Sleep_Nsec(u32 nsec); +void Sleep_Usec(u32 usec); +void Sleep_Msec(u32 ms); +void Sleep_Sec(u32 sec); + +#endif \ No newline at end of file diff --git a/soh/include/libu64/gfxprint.h b/soh/include/libu64/gfxprint.h new file mode 100644 index 00000000000..2c7ab0ba1d2 --- /dev/null +++ b/soh/include/libu64/gfxprint.h @@ -0,0 +1,54 @@ +#ifndef LIBU64_GFXPRINT_H +#define LIBU64_GFXPRINT_H + +#include +#include + +#include "extern_c_helper.h" + +typedef struct GfxPrint { + /* 0x00 */ PrintCallback callback; + /* 0x04 */ Gfx* dList; + /* 0x08 */ u16 posX; + /* 0x0A */ u16 posY; + /* 0x0C */ u16 baseX; + /* 0x0E */ u8 baseY; + /* 0x0F */ u8 flags; + /* 0x10 */ Color_RGBA8_u32 color; + /* 0x14 */ char unk_14[0x1C]; // unused +} GfxPrint; // size = 0x30 + +// TODO: GFX_CHAR_X_SPACING & GFX_CHAR_Y_SPACING macros + +#define GFXP_UNUSED "\x8E" +#define GFXP_UNUSED_CHAR 0x8E +#define GFXP_HIRAGANA "\x8D" +#define GFXP_HIRAGANA_CHAR 0x8D +#define GFXP_KATAKANA "\x8C" +#define GFXP_KATAKANA_CHAR 0x8C +#define GFXP_RAINBOW_ON "\x8B" +#define GFXP_RAINBOW_ON_CHAR 0x8B +#define GFXP_RAINBOW_OFF "\x8A" +#define GFXP_RAINBOW_OFF_CHAR 0x8A + +#define GFXP_FLAG_HIRAGANA (1 << 0) +#define GFXP_FLAG_RAINBOW (1 << 1) +#define GFXP_FLAG_SHADOW (1 << 2) +#define GFXP_FLAG_UPDATE (1 << 3) +// TODO: PLATFORM macros +#if true//!PLATFORM_N64 +#define GFXP_FLAG_ENLARGE (1 << 6) +#endif +#define GFXP_FLAG_OPEN (1 << 7) + +EXTERN_C void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a); +EXTERN_C void GfxPrint_SetPosPx(GfxPrint* this, s32 x, s32 y); +EXTERN_C void GfxPrint_SetPos(GfxPrint* this, s32 x, s32 y); +EXTERN_C void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y); +EXTERN_C void GfxPrint_Init(GfxPrint* this); +EXTERN_C void GfxPrint_Destroy(GfxPrint* this); +EXTERN_C void GfxPrint_Open(GfxPrint* this, Gfx* dList); +EXTERN_C Gfx* GfxPrint_Close(GfxPrint* this); +EXTERN_C s32 GfxPrint_Printf(GfxPrint* this, const char* fmt, ...); + +#endif \ No newline at end of file diff --git a/soh/include/libu64/pad.h b/soh/include/libu64/pad.h new file mode 100644 index 00000000000..4a4f327c268 --- /dev/null +++ b/soh/include/libu64/pad.h @@ -0,0 +1,33 @@ +#ifndef LIBU64_PAD_H +#define LIBU64_PAD_H + +#include + +#include "extern_c_helper.h" + +typedef struct Input { + /* 0x00 */ OSContPad cur; + /* 0x06 */ OSContPad prev; + /* 0x0C */ OSContPad press; // X/Y store delta from last frame + /* 0x12 */ OSContPad rel; // X/Y store adjusted +} Input; // size = 0x18 + +EXTERN_C void PadUtils_Init(Input* input); +EXTERN_C void func_800FCB70(void); +EXTERN_C void PadUtils_ResetPressRel(Input* input); +EXTERN_C u32 PadUtils_CheckCurExact(Input* input, u16 value); +EXTERN_C u32 PadUtils_CheckCur(Input* input, u16 key); +EXTERN_C u32 PadUtils_CheckPressed(Input* input, u16 key); +EXTERN_C u32 PadUtils_CheckReleased(Input* input, u16 key); +EXTERN_C u16 PadUtils_GetCurButton(Input* input); +EXTERN_C u16 PadUtils_GetPressButton(Input* input); +EXTERN_C s8 PadUtils_GetCurX(Input* input); +EXTERN_C s8 PadUtils_GetCurY(Input* input); +EXTERN_C void PadUtils_SetRelXY(Input* input, s32 x, s32 y); +EXTERN_C s8 PadUtils_GetRelXImpl(Input* input); +EXTERN_C s8 PadUtils_GetRelYImpl(Input* input); +EXTERN_C s8 PadUtils_GetRelX(Input* input); +EXTERN_C s8 PadUtils_GetRelY(Input* input); +EXTERN_C void PadUtils_UpdateRelXY(Input* input); + +#endif \ No newline at end of file diff --git a/soh/include/macros.h b/soh/include/macros.h index eb377ffa0e8..174a357506c 100644 --- a/soh/include/macros.h +++ b/soh/include/macros.h @@ -36,66 +36,8 @@ //#define SEGMENTED_TO_VIRTUAL(addr) PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)] + SEGMENT_OFFSET(addr)) #define SEGMENTED_TO_VIRTUAL(addr) addr -#ifndef SQ -#define SQ(x) ((x)*(x)) -#endif -#ifndef ABS -#define ABS(x) ((x) >= 0 ? (x) : -(x)) -#endif -#define DECR(x) ((x) == 0 ? 0 : --(x)) -#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) -#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) -#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) - #define RGBA8(r, g, b, a) ((((r) & 0xFF) << 24) | (((g) & 0xFF) << 16) | (((b) & 0xFF) << 8) | (((a) & 0xFF) << 0)) -#define GET_PLAYER(play) ((Player*)(play)->actorCtx.actorLists[ACTORCAT_PLAYER].head) - -#define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamera]) // Upstream TODO: Camera - -#define LINK_IS_ADULT (gSaveContext.linkAge == LINK_AGE_ADULT) -#define LINK_IS_CHILD (gSaveContext.linkAge == LINK_AGE_CHILD) - -#define YEARS_CHILD 5 -#define YEARS_ADULT 17 -#define LINK_AGE_IN_YEARS (!LINK_IS_ADULT ? YEARS_CHILD : YEARS_ADULT) - -#define CLOCK_TIME(hr, min) ((s32)(((hr) * 60 + (min)) * (f32)0x10000 / (24 * 60) + 0.5f)) - -#define IS_DAY (gSaveContext.nightFlag == 0) -#define IS_NIGHT (gSaveContext.nightFlag == 1) - -#define SLOT(item) gItemSlots[item] -#define INV_CONTENT(item) gSaveContext.inventory.items[SLOT(item)] -#define AMMO(item) gSaveContext.inventory.ammo[SLOT(item)] -#define BEANS_BOUGHT AMMO(ITEM_BEAN + 1) - -#define ALL_EQUIP_VALUE(equip) ((s32)(gSaveContext.inventory.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) -#define CUR_EQUIP_VALUE(equip) ((s32)(gSaveContext.equips.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) -#define OWNED_EQUIP_FLAG(equip, value) (gBitFlags[value] << gEquipShifts[equip]) -#define OWNED_EQUIP_FLAG_ALT(equip, value) ((1 << (value)) << gEquipShifts[equip]) -#define CHECK_OWNED_EQUIP(equip, value) (OWNED_EQUIP_FLAG(equip, value) & gSaveContext.inventory.equipment) -#define CHECK_OWNED_EQUIP_ALT(equip, value) (gBitFlags[(value) + (equip) * 4] & gSaveContext.inventory.equipment) - -#define SWORD_EQUIP_TO_PLAYER(swordEquip) (swordEquip) -#define SHIELD_EQUIP_TO_PLAYER(shieldEquip) (shieldEquip) -#define TUNIC_EQUIP_TO_PLAYER(tunicEquip) ((tunicEquip) - 1) -#define BOOTS_EQUIP_TO_PLAYER(bootsEquip) ((bootsEquip) - 1) - -#define CUR_UPG_VALUE(upg) ((s32)(gSaveContext.inventory.upgrades & gUpgradeMasks[upg]) >> gUpgradeShifts[upg]) -#define CAPACITY(upg, value) gUpgradeCapacities[upg][value] -#define CUR_CAPACITY(upg) CAPACITY(upg, CUR_UPG_VALUE(upg)) - -#define CHECK_QUEST_ITEM(item) (gBitFlags[item] & gSaveContext.inventory.questItems) -#define CHECK_DUNGEON_ITEM(item, dungeonIndex) (gSaveContext.inventory.dungeonItems[dungeonIndex] & gBitFlags[item]) - -#define GET_GS_FLAGS(index) \ - ((gSaveContext.gsFlags[(index) >> 2] & gGsFlagsMasks[(index) & 3]) >> gGsFlagsShifts[(index) & 3]) -#define SET_GS_FLAGS(index, value) \ - (gSaveContext.gsFlags[(index) >> 2] |= (value) << gGsFlagsShifts[(index) & 3]) - -#define HIGH_SCORE(score) (gSaveContext.highScores[score]) - #define GET_EVENTCHKINF(flag) (gSaveContext.eventChkInf[(flag) >> 4] & (1 << ((flag) & 0xF))) #define SET_EVENTCHKINF(flag) (gSaveContext.eventChkInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) #define CLEAR_EVENTCHKINF(flag) (gSaveContext.eventChkInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) @@ -112,16 +54,6 @@ #define SET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) #define CLEAR_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) -#define B_BTN_ITEM ((gSaveContext.buttonStatus[0] == ITEM_NONE) \ - ? ITEM_NONE \ - : (gSaveContext.equips.buttonItems[0] == ITEM_SWORD_KNIFE) \ - ? ITEM_SWORD_BGS \ - : gSaveContext.equips.buttonItems[0]) - -#define C_BTN_ITEM(button) ((gSaveContext.buttonStatus[(button) + 1] != BTN_DISABLED) \ - ? gSaveContext.equips.buttonItems[(button) + 1] \ - : ITEM_NONE) - #define CHECK_BTN_ALL(state, combo) (~((state) | ~(combo)) == 0) #define CHECK_BTN_ANY(state, combo) (((state) & (combo)) != 0) @@ -191,82 +123,6 @@ } \ (void)0 -extern GraphicsContext* __gfxCtx; - -#define WORK_DISP __gfxCtx->work.p -#define POLY_OPA_DISP __gfxCtx->polyOpa.p -#define POLY_XLU_DISP __gfxCtx->polyXlu.p -#define OVERLAY_DISP __gfxCtx->overlay.p - -// __gfxCtx shouldn't be used directly. -// Use the DISP macros defined above when writing to display buffers. -// #region SOH [General] -// Augmented to provide debug information in debug build and support interpolation -#ifndef NDEBUG -#define OPEN_DISPS(gfxCtx) \ - { \ - void FrameInterpolation_RecordOpenChild(const void* a, int b); \ - FrameInterpolation_RecordOpenChild(__FILE__, __LINE__); \ - GraphicsContext* __gfxCtx; \ - Gfx* dispRefs[4]; \ - __gfxCtx = gfxCtx; \ - (void)__gfxCtx; \ - Graph_OpenDisps(dispRefs, gfxCtx, __FILE__, __LINE__) -#else -#define OPEN_DISPS(gfxCtx) \ - { \ - void FrameInterpolation_RecordOpenChild(const void* a, int b); \ - FrameInterpolation_RecordOpenChild(__FILE__, __LINE__); \ - GraphicsContext* __gfxCtx; \ - __gfxCtx = gfxCtx; \ - (void)__gfxCtx; -#endif - -#ifndef NDEBUG -#define CLOSE_DISPS(gfxCtx) \ - {void FrameInterpolation_RecordCloseChild(void); \ - FrameInterpolation_RecordCloseChild();} \ - Graph_CloseDisps(dispRefs, gfxCtx, __FILE__, __LINE__); \ - } \ - (void)0 -#else -#define CLOSE_DISPS(gfxCtx) \ - {void FrameInterpolation_RecordCloseChild(void); \ - FrameInterpolation_RecordCloseChild();} \ - (void)0; \ - } \ - (void)0 -#endif -// #endregion - -/** - * `x` vertex x - * `y` vertex y - * `z` vertex z - * `s` texture s coordinate - * `t` texture t coordinate - * `crnx` red component of color vertex, or x component of normal vertex - * `cgny` green component of color vertex, or y component of normal vertex - * `cbnz` blue component of color vertex, or z component of normal vertex - * `a` alpha - */ -#define VTX(x,y,z,s,t,crnx,cgny,cbnz,a) { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } } } - -#define VTX_T(x,y,z,s,t,cr,cg,cb,a) { { x, y, z }, 0, { s, t }, { cr, cg, cb, a } } - -#define gDPSetTileCustom(pkt, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ - do { \ - gDPPipeSync(pkt); \ - gDPTileSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, \ - masks, shifts); \ - gDPTileSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ - cms, masks, shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ - } while (0) - // #region SOH [General] #define OFFSETOF(structure, member) ((size_t)&(((structure*)0)->member)) diff --git a/soh/include/mempak.h b/soh/include/mempak.h new file mode 100644 index 00000000000..8f35618a44e --- /dev/null +++ b/soh/include/mempak.h @@ -0,0 +1,20 @@ +#ifndef MEMPAK_H +#define MEMPAK_H + +#include + +#include "extern_c_helper.h" + +EXTERN_C s32 Mempak_Init(s32 controllerNb); +EXTERN_C s32 Mempak_GetFreeBytes(s32 controllerNb); +EXTERN_C s32 Mempak_FindFile(s32 controllerNb, char start, char end); +EXTERN_C s32 Mempak_Write(s32 controllerNb, char idx, void* buffer, s32 offset, ptrdiff_t size); +EXTERN_C s32 Mempak_Read(s32 controllerNb, char idx, void* buffer, s32 offset, ptrdiff_t size); +// TODO: Rename to Mempak_CreateFile +EXTERN_C s32 Mempak_Alloc(s32 controllerNb, char* idx, ptrdiff_t size); +EXTERN_C s32 Mempak_DeleteFile(s32 controllerNb, char idx); +EXTERN_C s32 Mempak_GetFileSize(s32 controllerNb, char idx); + +// TODO: MEMPAK macros + +#endif \ No newline at end of file diff --git a/soh/include/olib.h b/soh/include/olib.h new file mode 100644 index 00000000000..8c367bc6384 --- /dev/null +++ b/soh/include/olib.h @@ -0,0 +1,19 @@ +#ifndef OLIB_H +#define OLIB_H + +#include "z64math.h" + +#include "extern_c_helper.h" + +EXTERN_C f32 OLib_Vec3fDist(Vec3f* a, Vec3f* b); +EXTERN_C f32 OLib_Vec3fDistXZ(Vec3f* a, Vec3f* b); +EXTERN_C f32 OLib_ClampMinDist(f32 val, f32 min); +EXTERN_C f32 OLib_ClampMaxDist(f32 val, f32 max); +EXTERN_C Vec3f* OLib_Vec3fDistNormalize(Vec3f* dest, Vec3f* a, Vec3f* b); +EXTERN_C Vec3f* OLib_VecSphGeoToVec3f(Vec3f* dest, VecSph* sph); +EXTERN_C VecSph* OLib_Vec3fToVecSph(VecSph* dest, Vec3f* vec); +EXTERN_C VecSph* OLib_Vec3fToVecSphGeo(VecSph* arg0, Vec3f* arg1); +EXTERN_C VecSph* OLib_Vec3fDiffToVecSphGeo(VecSph* arg0, Vec3f* a, Vec3f* b); +EXTERN_C Vec3f* OLib_Vec3fDiffRad(Vec3f* dest, Vec3f* a, Vec3f* b); + +#endif \ No newline at end of file diff --git a/soh/include/padmgr.h b/soh/include/padmgr.h new file mode 100644 index 00000000000..a78a59b13f8 --- /dev/null +++ b/soh/include/padmgr.h @@ -0,0 +1,65 @@ +#ifndef PADMGR_H +#define PADMGR_H + +#include +#include "libu64/pad.h" +#include "irqmgr.h" + +#include "extern_c_helper.h" + +// TODO: ControllerPakType enum + +typedef struct PadMgr { + /* 0x0000 */ OSContStatus padStatus[4]; + /* 0x0010 */ OSMesg serialMsgBuf[1]; + /* 0x0014 */ OSMesg lockMsgBuf[1]; + /* 0x0018 */ OSMesg interruptMsgBuf[4]; + /* 0x0028 */ OSMesgQueue serialMsgQ; + /* 0x0040 */ OSMesgQueue lockMsgQ; + /* 0x0058 */ OSMesgQueue interruptMsgQ; + /* 0x0070 */ IrqMgrClient irqClient; + /* 0x0078 */ IrqMgr* irqMgr; + /* 0x0080 */ OSThread thread; + /* 0x0230 */ Input inputs[4]; + /* 0x0290 */ OSContPad pads[4]; + /* 0x02A8 */ vu8 validCtrlrsMask; + /* 0x02A9 */ u8 nControllers; + /* 0x02AA */ u8 ctrlrIsConnected[4]; // "Key_switch" originally + /* 0x02AE */ u8 pakType[4]; // 1 if rumble pack, 2 if mempak? + /* 0x02B2 */ vu8 rumbleEnable[4]; + /* 0x02B6 */ u8 rumbleCounter[4]; // not clear exact meaning + /* 0x02BC */ OSPfs pfs[4]; + /* 0x045C */ vu8 rumbleOffFrames; + /* 0x045D */ vu8 rumbleOnFrames; + /* 0x045E */ u8 preNMIShutdown; + /* 0x0460 */ void (*retraceCallback)(struct PadMgr* padmgr, s32 unk464); + /* 0x0464 */ u32 retraceCallbackValue; +} PadMgr; // size = 0x468 + +// Initialization + +EXTERN_C void PadMgr_Init(PadMgr* padmgr, OSMesgQueue* siIntMsgQ, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack); + +// Fetching inputs + +// This function cannot be prototyped here in all configurations because it is called incorrectly in fault_gc.c +// (see bug in `Fault_PadCallback`) +#if true//PLATFORM_N64 || defined(AVOID_UB) +EXTERN_C void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 gameRequest); +#endif + +// For internal use by Controller Pak systems +// TODO: Rename to upstream's names +EXTERN_C OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padmgr); +EXTERN_C void PadMgr_UnlockSerialMesgQueue(PadMgr* padmgr, OSMesgQueue* ctrlrqueue); + +EXTERN_C void PadMgr_RumbleStop(PadMgr* padMgr); +EXTERN_C void PadMgr_RumbleReset(PadMgr* padMgr); +EXTERN_C void PadMgr_RumbleSetSingle(PadMgr* padMgr, u32 port, u32 rumble); +EXTERN_C void PadMgr_RumbleSet(PadMgr* padMgr, u8* enable); + +// TODO: PADMGR macros + +EXTERN_C PadMgr gPadMgr; + +#endif \ No newline at end of file diff --git a/soh/include/prenmi_buff.h b/soh/include/prenmi_buff.h new file mode 100644 index 00000000000..94380f46f1e --- /dev/null +++ b/soh/include/prenmi_buff.h @@ -0,0 +1,35 @@ +#ifndef PRENMI_BUFF_H +#define PRENMI_BUFF_H + +#include +#include "alignment.h" + +#include "extern_c_helper.h" + +// This struct is used at osAppNMIBuffer which is not at an 8-byte aligned address. This causes an unaligned access +// crash if the OSTime variables use 64-bit load/store instructions, which is the case in any MIPS ABI other than O32 +// where 64-bit load/store instructions are emulated with 2x 32-bit load/store instructions. The alignment attribute +// conveys that this structure will not always be 8-bytes aligned, allowing a modern compiler to generate non-crashing +// code for accessing these. This is not an issue in the original compiler as it only output O32 ABI code. +ALIGNED4 typedef struct PreNmiBuff { + /* 0x00 */ u32 resetting; + /* 0x04 */ u32 resetCount; + /* 0x08 */ OSTime duration; + /* 0x10 */ OSTime resetTime; +} PreNmiBuff; // size = 0x18 (actually osAppNmiBuffer is 0x40 bytes large but the rest is unused) + +#ifdef __cplusplus +#define this thisx +#endif + +EXTERN_C PreNmiBuff* gAppNmiBufferPtr; + +EXTERN_C void PreNmiBuff_Init(PreNmiBuff* this); +EXTERN_C void PreNmiBuff_SetReset(PreNmiBuff* this); +EXTERN_C u32 PreNmiBuff_IsResetting(PreNmiBuff* this); + +#ifdef __cplusplus +#undef this +#endif + +#endif \ No newline at end of file diff --git a/soh/include/quake.h b/soh/include/quake.h new file mode 100644 index 00000000000..f0d0b4415dd --- /dev/null +++ b/soh/include/quake.h @@ -0,0 +1,49 @@ +#ifndef QUAKE_H +#define QUAKE_H + +#include "z64camera.h" +#include "z64math.h" + +#include "extern_c_helper.h" + +typedef struct ShakeInfo { + /* 0x00 */ Vec3f vec1; + /* 0x0C */ Vec3f vec2; + /* 0x18 */ s16 rotZ; + /* 0x1A */ s16 unk_1A; + /* 0x1C */ s16 zoom; +} ShakeInfo; // size = 0x1E + +// TODO: Add QuakeType enum + +// TODO: Rename all of these functions +EXTERN_C s16 Quake_Add(Camera* cam, u32 callbackIdx); + +EXTERN_C u32 Quake_SetSpeed(s16 idx, s16 value); +EXTERN_C u32 Quake_SetQuakeValues(s16 idx, s16 y, s16 x, s16 zoom, s16 rotZ); +EXTERN_C u32 Quake_SetCountdown(s16 idx, s16 value); + +typedef struct SubQuakeRequest14 { + /* 0x00 */ s16 unk_00; + /* 0x02 */ s16 unk_02; + /* 0x04 */ s16 unk_04; +} SubQuakeRequest14; // size = 0x06 + +EXTERN_C u32 Quake_SetUnkValues(s16 idx, s16 arg1, SubQuakeRequest14 arg2); + +EXTERN_C s16 Quake_GetCountdown(s16 idx); +EXTERN_C u32 Quake_RemoveFromIdx(s16 idx); + +typedef struct QuakeCamCalc { + /* 0x00 */ Vec3f atOffset; + /* 0x0C */ Vec3f eyeOffset; + /* 0x18 */ s16 rotZ; + /* 0x1A */ s16 unk_1A; + /* 0x1C */ s16 zoom; + /* 0x20 */ f32 unk_20; +} QuakeCamCalc; // size = 0x24 + +EXTERN_C void Quake_Init(void); +EXTERN_C s16 Quake_Calc(Camera* camera, QuakeCamCalc* camData); + +#endif \ No newline at end of file diff --git a/soh/include/sched.h b/soh/include/sched.h new file mode 100644 index 00000000000..21e5736aa4f --- /dev/null +++ b/soh/include/sched.h @@ -0,0 +1,81 @@ +#ifndef SCHED_H +#define SCHED_H + +#include +#include "irqmgr.h" +#include "unk.h" + +#include "extern_c_helper.h" + +#define OS_SC_NEEDS_RDP 0x0001 +#define OS_SC_NEEDS_RSP 0x0002 +#define OS_SC_DRAM_DLIST 0x0004 +#define OS_SC_PARALLEL_TASK 0x0010 +#define OS_SC_LAST_TASK 0x0020 +#define OS_SC_SWAPBUFFER 0x0040 + +#define OS_SC_DP OS_SC_NEEDS_RDP +#define OS_SC_SP OS_SC_NEEDS_RSP +#define OS_SC_YIELD 0x0010 +#define OS_SC_YIELDED 0x0020 + +#define OS_SC_RCP_MASK (OS_SC_NEEDS_RDP | OS_SC_NEEDS_RSP) +#define OS_SC_TYPE_MASK (OS_SC_NEEDS_RDP | OS_SC_NEEDS_RSP | OS_SC_DRAM_DLIST) + +typedef struct CfbInfo { + /* 0x00 */ u16* fb1; + /* 0x04 */ u16* swapBuffer; + /* 0x08 */ OSViMode* viMode; + /* 0x0C */ u32 features; + /* 0x10 */ u8 unk_10; + /* 0x11 */ s8 updateRate; + /* 0x12 */ s8 updateRate2; + /* 0x13 */ u8 unk_13; +#if true//OOT_VERSION >= PAL_1_0 + /* 0x14 */ f32 xScale; + /* 0x18 */ f32 yScale; +#endif +} CfbInfo; // size = 0x1C + +typedef struct OSScTask { + /* 0x00 */ struct OSScTask* next; + /* 0x04 */ u32 state; + /* 0x08 */ u32 flags; + /* 0x0C */ CfbInfo* framebuffer; + /* 0x10 */ OSTask list; + /* 0x50 */ OSMesgQueue* msgQ; + /* 0x54 */ OSMesg msg; +} OSScTask; + +// TODO: Update the type to upstream's +typedef struct SchedContext { + /* 0x0000 */ OSMesgQueue interruptQ; + /* 0x0018 */ OSMesg intBuf[8]; + /* 0x0038 */ OSMesgQueue cmdQ; + /* 0x0050 */ OSMesg cmdMsgBuf[8]; + /* 0x0070 */ OSThread thread; + /* 0x0220 */ OSScTask* audioListHead; + /* 0x0224 */ OSScTask* gfxListHead; + /* 0x0228 */ OSScTask* audioListTail; + /* 0x022C */ OSScTask* gfxListTail; + /* 0x0230 */ OSScTask* curRSPTask; + /* 0x0234 */ OSScTask* curRDPTask; + /* 0x0238 */ s32 retraceCnt; + /* 0x023C */ s32 doAudio; + /* 0x0240 */ CfbInfo* curBuf; + /* 0x0244 */ CfbInfo* pendingSwapBuf1; + /* 0x0220 */ CfbInfo* pendingSwapBuf2; + /* 0x0220 */ UNK_TYPE4 unk_24C; + /* 0x0250 */ IrqMgrClient irqClient; +} SchedContext; // size = 0x258 + +// TODO: Rename to Sched_Notify +EXTERN_C void Sched_SendEntryMsg(SchedContext* sc); +EXTERN_C void Sched_Init(SchedContext* sc, void* stack, OSPri priority, UNK_TYPE arg3, UNK_TYPE arg4, IrqMgr* irqMgr); +// TODO: Rename to Sched_FlushTaskQueue +EXTERN_C void MsgEvent_SendNullTask(void); + +// TODO: Rename to gScheduler +EXTERN_C SchedContext gSchedContext; + +#endif \ No newline at end of file diff --git a/soh/include/skin_matrix.h b/soh/include/skin_matrix.h new file mode 100644 index 00000000000..7a966f4123b --- /dev/null +++ b/soh/include/skin_matrix.h @@ -0,0 +1,28 @@ +#ifndef SKIN_MATRIX_H +#define SKIN_MATRIX_H + +#include +#include "z64math.h" + +#include "extern_c_helper.h" + +struct GraphicsContext; + +EXTERN_C void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest); +EXTERN_C void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest); +EXTERN_C void SkinMatrix_MtxFMtxFMult(MtxF* mfA, MtxF* mfB, MtxF* dest); +EXTERN_C void SkinMatrix_GetClear(MtxF** mf); +EXTERN_C void SkinMatrix_Clear(MtxF* mf); +EXTERN_C void SkinMatrix_MtxFCopy(MtxF* src, MtxF* dest); +EXTERN_C s32 SkinMatrix_Invert(MtxF* src, MtxF* dest); +EXTERN_C void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z); +EXTERN_C void SkinMatrix_SetRotateZYX(MtxF* mf, s16 x, s16 y, s16 z); +EXTERN_C void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z); +EXTERN_C void SkinMatrix_SetTranslateRotateYXZScale(MtxF* dest, f32 scaleX, f32 scaleY, f32 scaleZ, s16 rotX, s16 rotY, s16 rotZ, + f32 translateX, f32 translateY, f32 translateZ); +EXTERN_C void SkinMatrix_SetTranslateRotateZYX(MtxF* dest, s16 rotX, s16 rotY, s16 rotZ, f32 translateX, f32 translateY, + f32 translateZ); +EXTERN_C Mtx* SkinMatrix_MtxFToNewMtx(struct GraphicsContext* gfxCtx, MtxF* src); +EXTERN_C void SkinMatrix_SetRotateAxis(MtxF* mf, s16 angle, f32 axisX, f32 axisY, f32 axisZ); + +#endif \ No newline at end of file diff --git a/soh/include/sys_math3d.h b/soh/include/sys_math3d.h new file mode 100644 index 00000000000..239dad06190 --- /dev/null +++ b/soh/include/sys_math3d.h @@ -0,0 +1,79 @@ +#ifndef SYS_MATH3D_H +#define SYS_MATH3D_H + +#include +#include "z64math.h" + +#include "extern_c_helper.h" + +struct PlayState; + +EXTERN_C s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, + f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, + Vec3f* closestPoint); +EXTERN_C void Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint); +EXTERN_C s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, + f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint); +EXTERN_C void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret); +EXTERN_C f32 Math3D_Cos(Vec3f* a, Vec3f* b); +EXTERN_C s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst); +EXTERN_C void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec); +EXTERN_C s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y); +EXTERN_C f32 Math3D_Dist1DSq(f32 a, f32 b); +EXTERN_C f32 Math3D_Dist2DSq(f32 x0, f32 y0, f32 x1, f32 y1); +EXTERN_C f32 Math3D_Vec3fMagnitudeSq(Vec3f* vec); +EXTERN_C f32 Math3D_Vec3fMagnitude(Vec3f* vec); +EXTERN_C f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); +EXTERN_C void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret); +EXTERN_C void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal); +EXTERN_C f32 Math3D_Vec3f_DistXYZ(Vec3f* a, Vec3f* b); +EXTERN_C s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max); +EXTERN_C s32 Math3D_PointRelativeToCubeEdges(Vec3f* point, Vec3f* min, Vec3f* max); +EXTERN_C s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max); +EXTERN_C s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); +EXTERN_C void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d); +EXTERN_C void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist); +EXTERN_C f32 Math3D_UDistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); +EXTERN_C f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); +EXTERN_C s32 Math3D_TriChkPointParaYSlopedY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x); +EXTERN_C s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, + f32 x, f32* yIntersect, f32 chkDist); +EXTERN_C s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, + f32 z, f32 x, f32* yIntersect, f32 chkDist); +EXTERN_C s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, + f32 x, f32* yIntersect, f32 y0, f32 y1); +EXTERN_C s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 z, f32 x, f32 chkDist); +EXTERN_C s32 Math3D_TriChkPointParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, + f32 z, f32* xIntersect); +EXTERN_C s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, + f32 z, f32* xIntersect, f32 x0, f32 x1); +EXTERN_C s32 Math3D_TriChkPointParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 y, f32 z, f32 chkDist); +EXTERN_C s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, + f32 y, f32* zIntersect); +EXTERN_C s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, + f32 y, f32* zIntersect, f32 z0, f32 z1); +EXTERN_C s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist); +EXTERN_C s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, + Vec3f* intersect, s32 fromFront); +EXTERN_C void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc); +EXTERN_C s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); +EXTERN_C s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); +EXTERN_C s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); +EXTERN_C s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); +EXTERN_C s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri); +EXTERN_C s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect); +EXTERN_C s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB); +EXTERN_C s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize); +EXTERN_C s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); +EXTERN_C s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize); +EXTERN_C s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist); +EXTERN_C s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace); +EXTERN_C s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist); +EXTERN_C s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect); +EXTERN_C s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); +EXTERN_C s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); +EXTERN_C s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); +EXTERN_C void Math3D_DrawSphere(struct PlayState* play, Sphere16* sph); +EXTERN_C void Math3D_DrawCylinder(struct PlayState* play, Cylinder16* cyl); + +#endif \ No newline at end of file diff --git a/soh/include/tha.h b/soh/include/tha.h new file mode 100644 index 00000000000..d312df07a8a --- /dev/null +++ b/soh/include/tha.h @@ -0,0 +1,31 @@ +#ifndef THA_H +#define THA_H + +#include + +#include "extern_c_helper.h" + +// TODO: Update the type to upstream +typedef struct TwoHeadArena { + /* 0x00 */ u32 size; + /* 0x04 */ void* bufp; + /* 0x08 */ void* head; + /* 0x0C */ void* tail; +} TwoHeadArena; // size = 0x10 + +// TODO: Update the names to upstream +EXTERN_C void* THA_GetHead(TwoHeadArena* tha); +EXTERN_C void THA_SetHead(TwoHeadArena* tha, void* start); +EXTERN_C void* THA_GetTail(TwoHeadArena* tha); +EXTERN_C void* THA_AllocStart(TwoHeadArena* tha, size_t size); +EXTERN_C void* THA_AllocStart1(TwoHeadArena* tha); +EXTERN_C void* THA_AllocEnd(TwoHeadArena* tha, size_t size); +EXTERN_C void* THA_AllocEndAlign16(TwoHeadArena* tha, size_t size); +EXTERN_C void* THA_AllocEndAlign(TwoHeadArena* tha, size_t size, size_t mask); +EXTERN_C s32 THA_GetSize(TwoHeadArena* tha); +EXTERN_C u32 THA_IsCrash(TwoHeadArena* tha); +EXTERN_C void THA_Init(TwoHeadArena* tha); +EXTERN_C void THA_Ct(TwoHeadArena* tha, void* ptr, size_t size); +EXTERN_C void THA_Dt(TwoHeadArena* tha); + +#endif \ No newline at end of file diff --git a/soh/include/thga.h b/soh/include/thga.h new file mode 100644 index 00000000000..1c3179261b5 --- /dev/null +++ b/soh/include/thga.h @@ -0,0 +1,31 @@ +#ifndef THGA_H +#define THGA_H + +#include "tha.h" + +// TODO: Update the type to upstream +typedef struct TwoHeadGfxArena { + /* 0x0000 */ u32 size; + /* 0x0004 */ Gfx* bufp; + /* 0x0008 */ Gfx* p; + /* 0x000C */ Gfx* d; +} TwoHeadGfxArena; // size = 0x10 + +EXTERN_C void THGA_Ct(TwoHeadGfxArena* thga, Gfx* start, size_t size); +EXTERN_C void THGA_Dt(TwoHeadGfxArena* thga); +EXTERN_C u32 THGA_IsCrash(TwoHeadGfxArena* thga); +EXTERN_C void THGA_Init(TwoHeadGfxArena* thga); +EXTERN_C s32 THGA_GetSize(TwoHeadGfxArena* thga); +EXTERN_C Gfx* THGA_GetHead(TwoHeadGfxArena* thga); +EXTERN_C void THGA_SetHead(TwoHeadGfxArena* thga, Gfx* start); +EXTERN_C Gfx* THGA_GetTail(TwoHeadGfxArena* thga); +EXTERN_C Gfx* THGA_AllocStartArray8(TwoHeadGfxArena* thga, u32 count); +EXTERN_C Gfx* THGA_AllocStart8(TwoHeadGfxArena* thga); +EXTERN_C Gfx* THGA_AllocStart8Wrapper(TwoHeadGfxArena* thga); +EXTERN_C Gfx* THGA_AllocEnd(TwoHeadGfxArena* thga, size_t size); +EXTERN_C Gfx* THGA_AllocEndArray64(TwoHeadGfxArena* thga, u32 count); +EXTERN_C Gfx* THGA_AllocEnd64(TwoHeadGfxArena* thga); +EXTERN_C Gfx* THGA_AllocEndArray16(TwoHeadGfxArena* thga, u32 count); +EXTERN_C Gfx* THGA_AllocEnd16(TwoHeadGfxArena* thga); + +#endif \ No newline at end of file diff --git a/soh/include/variables.h b/soh/include/variables.h index 281a049026c..0590499caba 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -73,12 +73,6 @@ extern "C" extern Gfx D_80116280[]; extern s32 gDbgCamEnabled; extern GameStateOverlay gGameStateOverlayTable[6]; - extern u8 gWeatherMode; - extern u8 D_8011FB34; - extern u8 D_8011FB38; - extern u8 gSkyboxBlendingEnabled; - extern u16 gTimeSpeed; - extern struct_8011FC1C D_8011FC1C[][9]; extern SkyboxFile gSkyboxFiles[]; extern s32 gZeldaArenaLogSeverity; extern MapData gMapDataTable; @@ -92,7 +86,6 @@ extern "C" extern Gfx* gPlayerLeftHandBoomerangDLs[]; extern Gfx gCullBackDList[]; extern Gfx gCullFrontDList[]; - extern Gfx gEmptyDL[]; extern u32 gBitFlags[32]; extern u16 gEquipMasks[4]; extern u16 gEquipNegMasks[4]; @@ -114,9 +107,6 @@ extern "C" extern EntranceInfo gEntranceTable[ENTR_MAX]; extern SceneTableEntry gSceneTable[SCENE_ID_MAX]; extern u16 gSramSlotOffsets[]; - // 4 16-colors palettes - extern u64 gMojiFontTLUTs[4][4]; // original name: "moji_tlut" - extern u64 gMojiFontTex[]; // original name: "font_ff" extern KaleidoMgrOverlay gKaleidoMgrOverlayTable[KALEIDO_OVL_MAX]; extern KaleidoMgrOverlay* gKaleidoMgrCurOvl; extern u8 gBossMarkState; @@ -192,20 +182,11 @@ extern "C" extern u16 D_8015FCC2; extern u16 D_8015FCC4; extern u8 D_8015FCC8; - extern u8 gCustomLensFlareOn; - extern Vec3f gCustomLensFlarePos; - extern s16 gLensFlareScale; - extern f32 gLensFlareColorIntensity; - extern s16 gLensFlareScreenFillAlpha; - extern LightningStrike gLightningStrike; extern MapData* gMapData; extern f32 gBossMarkScale; extern PauseMapMarksData* gLoadedPauseMarkDataTable; extern s32 gTrnsnUnkState; extern Color_RGBA8_u32 gVisMonoColor; - extern PreNmiBuff* gAppNmiBufferPtr; - extern SchedContext gSchedContext; - extern PadMgr gPadMgr; extern uintptr_t gSegments[NUM_SEGMENTS]; extern volatile OSTime D_8016A520; extern volatile OSTime D_8016A528; diff --git a/soh/include/z64.h b/soh/include/z64.h index 451d6f6d542..eda64f1062b 100644 --- a/soh/include/z64.h +++ b/soh/include/z64.h @@ -12,7 +12,7 @@ #include "z64audio.h" #include "z64object.h" #include "z64camera.h" -#include "z64environment.h" +#include "environment.h" #include "z64cutscene.h" #include "z64collision_check.h" #include "z64scene.h" @@ -33,6 +33,9 @@ #include "ichain.h" #include "regs.h" #include "gfx.h" +#include "font.h" +#include "libu64/pad.h" +#include "quake.h" #if defined(__LP64__) #define _SOH64 @@ -53,9 +56,6 @@ namespace Fast { #include #endif -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 240 - #define REGION_NULL 0 #define REGION_US 1 #define REGION_JP 2 @@ -93,93 +93,6 @@ typedef struct { /* 0x14 */ s16 data[REG_GROUPS * REG_PER_GROUP]; // 0xAE0 entries } GameInfo; // size = 0x15D4 -typedef struct { - /* 0x00000 */ u16 headMagic; // GFXPOOL_HEAD_MAGIC - /* 0x00008 */ Gfx polyOpaBuffer[0x2FC0]; - /* 0x0BF08 */ Gfx polyXluBuffer[0x1000]; - /* 0x0FF08 */ Gfx overlayBuffer[0x800]; - /* 0x11F08 */ Gfx workBuffer[0x100]; - /* 0x11308 */ Gfx unusedBuffer[0x40]; - /* 0x12408 */ u16 tailMagic; // GFXPOOL_TAIL_MAGIC -} GfxPool; // size = 0x24820 - -typedef struct { - /* 0x0000 */ u32 size; - /* 0x0004 */ void* bufp; - /* 0x0008 */ void* head; - /* 0x000C */ void* tail; -} TwoHeadArena; // size = 0x10 - -typedef struct { - /* 0x0000 */ u32 size; - /* 0x0004 */ Gfx* bufp; - /* 0x0008 */ Gfx* p; - /* 0x000C */ Gfx* d; -} TwoHeadGfxArena; // size = 0x10 - -typedef struct { - /* 0x00 */ u16* fb1; - /* 0x04 */ u16* swapBuffer; - /* 0x08 */ OSViMode* viMode; - /* 0x0C */ u32 features; - /* 0x10 */ u8 unk_10; - /* 0x11 */ s8 updateRate; - /* 0x12 */ s8 updateRate2; - /* 0x13 */ u8 unk_13; - /* 0x14 */ f32 xScale; - /* 0x18 */ f32 yScale; -} CfbInfo; // size = 0x1C - -typedef struct OSScTask { - /* 0x00 */ struct OSScTask* next; - /* 0x04 */ u32 state; - /* 0x08 */ u32 flags; - /* 0x0C */ CfbInfo* framebuffer; - /* 0x10 */ OSTask list; - /* 0x50 */ OSMesgQueue* msgQ; - /* 0x54 */ OSMesg msg; -} OSScTask; - -typedef struct GraphicsContext { - /* 0x0000 */ Gfx* polyOpaBuffer; // Pointer to "Zelda 0" - /* 0x0004 */ Gfx* polyXluBuffer; // Pointer to "Zelda 1" - /* 0x0008 */ char unk_008[0x08]; // Unused, could this be pointers to "Zelda 2" / "Zelda 3" - /* 0x0010 */ Gfx* overlayBuffer; // Pointer to "Zelda 4" - /* 0x0014 */ u32 unk_014; - /* 0x0018 */ char unk_018[0x20]; - /* 0x0038 */ OSMesg msgBuff[0x08]; - /* 0x0058 */ OSMesgQueue* schedMsgQ; - /* 0x005C */ OSMesgQueue queue; - /* 0x0074 */ char unk_074[0x04]; - /* 0x0078 */ OSScTask task; // size of OSScTask might be wrong - /* 0x00D0 */ char unk_0D0[0xE0]; - /* 0x01B0 */ Gfx* workBuffer; - /* 0x01B4 */ TwoHeadGfxArena work; - /* 0x01C4 */ char unk_01C4[0xC0]; - /* 0x0284 */ OSViMode* viMode; - /* 0x0288 */ char unk_0288[0x20]; // Unused, could this be Zelda 2/3 ? - /* 0x02A8 */ TwoHeadGfxArena overlay; // "Zelda 4" - /* 0x02B8 */ TwoHeadGfxArena polyOpa; // "Zelda 0" - /* 0x02C8 */ TwoHeadGfxArena polyXlu; // "Zelda 1" - /* 0x02D8 */ u32 gfxPoolIdx; - /* 0x02DC */ u16* curFrameBuffer; - /* 0x02E0 */ char unk_2E0[0x04]; - /* 0x02E4 */ u32 viFeatures; - /* 0x02E8 */ s32 fbIdx; - /* 0x02EC */ void (*callback)(struct GraphicsContext*, void*); - /* 0x02F0 */ void* callbackParam; - /* 0x02F4 */ f32 xScale; - /* 0x02F8 */ f32 yScale; - /* 0x02FC */ char unk_2FC[0x04]; -} GraphicsContext; // size = 0x300 - -typedef struct { - /* 0x00 */ OSContPad cur; - /* 0x06 */ OSContPad prev; - /* 0x0C */ OSContPad press; // X/Y store delta from last frame - /* 0x12 */ OSContPad rel; // X/Y store adjusted -} Input; // size = 0x18 - typedef struct { /* 0x0000 */ s32 topY; // uly (upper left y) /* 0x0004 */ s32 bottomY; // lry (lower right y) @@ -187,7 +100,7 @@ typedef struct { /* 0x000C */ s32 rightX; // lrx (lower right x) } Viewport; // size = 0x10 -typedef struct { +typedef struct View { /* 0x0000 */ s32 magic; // string literal "VIEW" / 0x56494557 /* 0x0004 */ GraphicsContext* gfxCtx; /* 0x0008 */ Viewport viewport; @@ -425,7 +338,7 @@ typedef enum { /* 0x27 */ SKYBOX_UNSET_27 = 39 } SkyboxId; -typedef struct { +typedef struct SkyboxContext { char unk_00[0x128]; s16 skyboxId; void* textures[2][6]; @@ -546,11 +459,6 @@ typedef enum { #define TODO_TRANSLATE "TranslateThis" -// TODO get these properties from the textures themselves -#define FONT_CHAR_TEX_WIDTH 16 -#define FONT_CHAR_TEX_HEIGHT 16 -#define FONT_CHAR_TEX_SIZE ((16 * 16) / 2) // 16x16 I4 texture - // TODO get these properties from the textures themselves #define MESSAGE_STATIC_TEX_SIZE 0x1000 @@ -627,21 +535,6 @@ typedef enum { /* 10 */ TEXT_STATE_AWAITING_NEXT } TextState; -// Increased char buffer because texture paths could be bigger than (16 * 16 / 2) -#define FONT_CHAR_MULTIPLIER 256 - -typedef struct { - /* 0x0000 */ uintptr_t msgOffset; - /* 0x0004 */ u32 msgLength; - /* 0x0008 */ u8 charTexBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER]; - /* 0x3C08 */ u8 iconBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER]; - /* 0x3C88 */ u8 fontBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER]; - union { - /* 0xDC88 */ char msgBuf[1280]; - /* 0xDC88 */ u16 msgBufWide[640]; - }; -} Font; // size = 0xE188 - #define TEXTBOX_ENDTYPE_DEFAULT 0x00 #define TEXTBOX_ENDTYPE_2_CHOICE 0x10 #define TEXTBOX_ENDTYPE_3_CHOICE 0x20 @@ -650,7 +543,7 @@ typedef struct { #define TEXTBOX_ENDTYPE_EVENT 0x50 #define TEXTBOX_ENDTYPE_FADING 0x60 -typedef struct { +typedef struct MessageContext { /* 0x0000 */ View view; /* 0x0128 */ Font font; /* 0xE2B0 */ void* textboxSegment; // original name: "fukidashiSegment" @@ -857,7 +750,7 @@ typedef enum { /* 0x04 */ PAUSE_WORLD_MAP } PauseMenuPage; -typedef struct { +typedef struct PauseContext { /* 0x0000 */ View view; /* 0x0128 */ u8* iconItemSegment; /* 0x012C */ u8* iconItem24Segment; @@ -943,7 +836,7 @@ typedef enum { /* 24 */ GAMEOVER_REVIVE_FADE_OUT // fade out the game over lights as link is revived and gets back up } GameOverState; -typedef struct { +typedef struct GameOverContext { /* 0x00 */ u16 state; } GameOverContext; // size = 0x2 @@ -1757,15 +1650,6 @@ typedef struct { typedef PauseMapMarkData PauseMapMarksData[3]; -typedef struct DebugDispObject { - /* 0x00 */ Vec3f pos; - /* 0x0C */ Vec3s rot; - /* 0x14 */ Vec3f scale; - /* 0x20 */ Color_RGBA8 color; - /* 0x24 */ s16 type; - /* 0x28 */ struct DebugDispObject* next; -} DebugDispObject; // size = 0x2C - typedef enum { MTXMODE_NEW, // generates a new matrix MTXMODE_APPLY // applies transformation to the current matrix @@ -1838,36 +1722,6 @@ typedef struct { /* 0x38 */ void(*inputCallback)(); } FaultDrawer; // size = 0x3C -typedef struct { - /* 0x00 */ PrintCallback callback; - /* 0x04 */ Gfx* dList; - /* 0x08 */ u16 posX; - /* 0x0A */ u16 posY; - /* 0x0C */ u16 baseX; - /* 0x0E */ u8 baseY; - /* 0x0F */ u8 flags; - /* 0x10 */ Color_RGBA8_u32 color; - /* 0x14 */ char unk_14[0x1C]; // unused -} GfxPrint; // size = 0x30 - -#define GFXP_UNUSED "\x8E" -#define GFXP_UNUSED_CHAR 0x8E -#define GFXP_HIRAGANA "\x8D" -#define GFXP_HIRAGANA_CHAR 0x8D -#define GFXP_KATAKANA "\x8C" -#define GFXP_KATAKANA_CHAR 0x8C -#define GFXP_RAINBOW_ON "\x8B" -#define GFXP_RAINBOW_ON_CHAR 0x8B -#define GFXP_RAINBOW_OFF "\x8A" -#define GFXP_RAINBOW_OFF_CHAR 0x8A - -#define GFXP_FLAG_HIRAGANA (1 << 0) -#define GFXP_FLAG_RAINBOW (1 << 1) -#define GFXP_FLAG_SHADOW (1 << 2) -#define GFXP_FLAG_UPDATE (1 << 3) -#define GFXP_FLAG_ENLARGE (1 << 6) -#define GFXP_FLAG_OPEN (1 << 7) - typedef struct StackEntry { /* 0x00 */ struct StackEntry* next; /* 0x04 */ struct StackEntry* prev; @@ -1914,107 +1768,13 @@ typedef struct { /* 0x10 */ u32 data[1]; } Yaz0Header; // size = 0x10 ("data" is not part of the header) -typedef struct { - /* 0x00 */ s16 type; - /* 0x02 */ char misc[0x1E]; -} OSScMsg; // size = 0x20 - -typedef struct IrqMgrClient { - /* 0x00 */ struct IrqMgrClient* prev; - /* 0x04 */ OSMesgQueue* queue; -} IrqMgrClient; - -typedef struct { - /* 0x000 */ OSScMsg retraceMsg; // this apparently got moved from OSSched - /* 0x020 */ OSScMsg prenmiMsg; // this apparently got moved from OSSched - /* 0x040 */ OSScMsg nmiMsg; - /* 0x060 */ OSMesgQueue queue; - /* 0x078 */ OSMesg msgBuf[8]; - /* 0x098 */ OSThread thread; - /* 0x248 */ IrqMgrClient* clients; - /* 0x24C */ u8 resetStatus; - /* 0x250 */ OSTime resetTime; - /* 0x258 */ OSTimer timer; - /* 0x278 */ OSTime retraceTime; -} IrqMgr; // size = 0x280 - -typedef struct PadMgr { - /* 0x0000 */ OSContStatus padStatus[4]; - /* 0x0010 */ OSMesg serialMsgBuf[1]; - /* 0x0014 */ OSMesg lockMsgBuf[1]; - /* 0x0018 */ OSMesg interruptMsgBuf[4]; - /* 0x0028 */ OSMesgQueue serialMsgQ; - /* 0x0040 */ OSMesgQueue lockMsgQ; - /* 0x0058 */ OSMesgQueue interruptMsgQ; - /* 0x0070 */ IrqMgrClient irqClient; - /* 0x0078 */ IrqMgr* irqMgr; - /* 0x0080 */ OSThread thread; - /* 0x0230 */ Input inputs[4]; - /* 0x0290 */ OSContPad pads[4]; - /* 0x02A8 */ vu8 validCtrlrsMask; - /* 0x02A9 */ u8 nControllers; - /* 0x02AA */ u8 ctrlrIsConnected[4]; // "Key_switch" originally - /* 0x02AE */ u8 pakType[4]; // 1 if rumble pack, 2 if mempak? - /* 0x02B2 */ vu8 rumbleEnable[4]; - /* 0x02B6 */ u8 rumbleCounter[4]; // not clear exact meaning - /* 0x02BC */ OSPfs pfs[4]; - /* 0x045C */ vu8 rumbleOffFrames; - /* 0x045D */ vu8 rumbleOnFrames; - /* 0x045E */ u8 preNMIShutdown; - /* 0x0460 */ void (*retraceCallback)(struct PadMgr* padmgr, s32 unk464); - /* 0x0464 */ u32 retraceCallbackValue; -} PadMgr; // size = 0x468 - -// == Previously sched.h - -#define OS_SC_NEEDS_RDP 0x0001 -#define OS_SC_NEEDS_RSP 0x0002 -#define OS_SC_DRAM_DLIST 0x0004 -#define OS_SC_PARALLEL_TASK 0x0010 -#define OS_SC_LAST_TASK 0x0020 -#define OS_SC_SWAPBUFFER 0x0040 - -#define OS_SC_RCP_MASK 0x0003 -#define OS_SC_TYPE_MASK 0x0007 - typedef struct { /* 0x0000 */ u16* curBuffer; /* 0x0004 */ u16* nextBuffer; } FrameBufferSwap; -typedef struct { - /* 0x0000 */ OSMesgQueue interruptQ; - /* 0x0018 */ OSMesg intBuf[8]; - /* 0x0038 */ OSMesgQueue cmdQ; - /* 0x0050 */ OSMesg cmdMsgBuf[8]; - /* 0x0070 */ OSThread thread; - /* 0x0220 */ OSScTask* audioListHead; - /* 0x0224 */ OSScTask* gfxListHead; - /* 0x0228 */ OSScTask* audioListTail; - /* 0x022C */ OSScTask* gfxListTail; - /* 0x0230 */ OSScTask* curRSPTask; - /* 0x0234 */ OSScTask* curRDPTask; - /* 0x0238 */ s32 retraceCnt; - /* 0x023C */ s32 doAudio; - /* 0x0240 */ CfbInfo* curBuf; - /* 0x0244 */ CfbInfo* pendingSwapBuf1; - /* 0x0220 */ CfbInfo* pendingSwapBuf2; - /* 0x0220 */ UNK_TYPE4 unk_24C; - /* 0x0250 */ IrqMgrClient irqClient; -} SchedContext; // size = 0x258 - // ======================== -#define OS_SC_RETRACE_MSG 1 -#define OS_SC_DONE_MSG 2 -#define OS_SC_NMI_MSG 3 // name is made up, 3 is OS_SC_RDP_DONE_MSG in the original sched.c -#define OS_SC_PRE_NMI_MSG 4 - -#define OS_SC_DP 0x0001 -#define OS_SC_SP 0x0002 -#define OS_SC_YIELD 0x0010 -#define OS_SC_YIELDED 0x0020 - typedef struct { /* 0x0000 */ IrqMgr* irqMgr; /* 0x0004 */ SchedContext* sched; @@ -2067,19 +1827,6 @@ typedef struct OverlayRelocationSection { /* 0x14 */ u32 relocations[1]; } OverlayRelocationSection; // size >= 0x18 -typedef struct { - /* 0x00 */ u32 resetting; - /* 0x04 */ u32 resetCount; - /* 0x08 */ OSTime duration; - /* 0x10 */ OSTime resetTime; -} PreNmiBuff; // size = 0x18 (actually osAppNmiBuffer is 0x40 bytes large but the rest is unused) - -typedef struct { - /* 0x00 */ s16 unk_00; - /* 0x02 */ s16 unk_02; - /* 0x04 */ s16 unk_04; -} SubQuakeRequest14; - typedef struct { /* 0x00 */ s16 randIdx; /* 0x02 */ s16 countdownMax; @@ -2096,24 +1843,6 @@ typedef struct { /* 0x20 */ s16 camPtrIdx; } QuakeRequest; // size = 0x24 -typedef struct { - /* 0x00 */ Vec3f vec1; - /* 0x0C */ Vec3f vec2; - /* 0x18 */ s16 rotZ; - /* 0x1A */ s16 unk_1A; - /* 0x1C */ s16 zoom; -} ShakeInfo; // size = 0x1E - -typedef struct { - /* 0x00 */ Vec3f atOffset; - /* 0x0C */ Vec3f eyeOffset; - /* 0x18 */ s16 rotZ; - /* 0x1A */ s16 unk_1A; - /* 0x1C */ s16 zoom; - /* 0x20 */ f32 unk_20; -} QuakeCamCalc; // size = 0x24 - - #define UCODE_NULL 0 #define UCODE_F3DZEX 1 #define UCODE_UNK 2 @@ -2149,78 +1878,6 @@ typedef struct { /* 0xD4 */ u32 geometryMode; } UCodeDisas; // size = 0xD8 -typedef struct { - /* 0x00 */ u16 table[8*8]; -} JpegQuantizationTable; // size = 0x80 - -typedef struct { - /* 0x00 */ u8 codeOffs[16]; - /* 0x10 */ u16 codesA[16]; - /* 0x30 */ u16 codesB[16]; - /* 0x50 */ u8* symbols; -} JpegHuffmanTable; // size = 0x54 - -// this struct might be inaccurate but it's not used outside jpegutils.c anyways -typedef struct { - /* 0x000 */ u8 codeOffs[16]; - /* 0x010 */ u16 dcCodes[120]; - /* 0x100 */ u16 acCodes[256]; -} JpegHuffmanTableOld; // size = 0x300 - -typedef struct { - /* 0x00 */ u32 address; - /* 0x04 */ u32 mbCount; - /* 0x08 */ u32 mode; - /* 0x0C */ u32 qTableYPtr; - /* 0x10 */ u32 qTableUPtr; - /* 0x14 */ u32 qTableVPtr; - /* 0x18 */ char unk_18[0x8]; -} JpegTaskData; // size = 0x20 - -typedef struct { - /* 0x000 */ JpegTaskData taskData; - /* 0x020 */ char yieldData[0x200]; - /* 0x220 */ JpegQuantizationTable qTableY; - /* 0x2A0 */ JpegQuantizationTable qTableU; - /* 0x320 */ JpegQuantizationTable qTableV; - /* 0x3A0 */ u8 codesLengths[0x110]; - /* 0x4B0 */ u16 codes[0x108]; - /* 0x6C0 */ u16 data[4][0x180]; -} JpegWork; // size = 0x12C0 - -typedef struct { - /* 0x00 */ void* imageData; - /* 0x04 */ u8 mode; - /* 0x05 */ u8 unk_05; - /* 0x08 */ JpegHuffmanTable* hTablePtrs[4]; - /* 0x18 */ u8 unk_18; -} JpegDecoder; // size = 0x1C - -typedef struct { - /* 0x00 */ u8 dqtCount; - /* 0x04 */ u8* dqtPtr[3]; - /* 0x10 */ u8 dhtCount; - /* 0x14 */ u8* dhtPtr[4]; - /* 0x24 */ void* imageData; - /* 0x28 */ u32 mode; // 0 if Y V0 is 1 and 2 if Y V0 is 2 - /* 0x2C */ char unk_2C[4]; - /* 0x30 */ OSScTask scTask; - /* 0x88 */ char unk_88[0x10]; - /* 0x98 */ OSMesgQueue mq; - /* 0xB0 */ OSMesg msg; - /* 0xB4 */ JpegWork* workBuf; -} JpegContext; // size = 0xB8 - -typedef struct { - /* 0x00 */ u32 byteIdx; - /* 0x04 */ u8 bitIdx; - /* 0x05 */ u8 dontSkip; - /* 0x08 */ u32 curWord; - /* 0x0C */ s16 unk_0C; - /* 0x0E */ s16 unk_0E; - /* 0x10 */ s16 unk_10; -} JpegDecoderState; // size = 0x14 - typedef struct { /* 0x0000 */ OSViMode customViMode; /* 0x0050 */ s32 viHeight; @@ -2338,6 +1995,9 @@ typedef enum { LED_SOURCE_CUSTOM } LEDColorSource; +#define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamera]) +#define GET_PLAYER(play) ((Player*)(play)->actorCtx.actorLists[ACTORCAT_PLAYER].head) + #define ROM_FILE(name) \ { 0, 0, #name } diff --git a/soh/include/z64environment.h b/soh/include/z64environment.h deleted file mode 100644 index 8cb69ddc44c..00000000000 --- a/soh/include/z64environment.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _Z64ENVIRONMENT_H_ -#define _Z64ENVIRONMENT_H_ - -#include "z64math.h" -#include "z64light.h" -#include "z64dma.h" - -#define FILL_SCREEN_OPA (1 << 0) -#define FILL_SCREEN_XLU (1 << 1) - -typedef enum { - /* 0 */ LIGHTNING_MODE_OFF, // no lightning - /* 1 */ LIGHTNING_MODE_ON, // request ligtning strikes at random intervals - /* 2 */ LIGHTNING_MODE_LAST // request one lightning strike before turning off -} LightningMode; - -typedef enum { - /* 0 */ LIGHTNING_STRIKE_WAIT, // wait between lightning strikes. request bolts when timer hits 0 - /* 1 */ LIGHTNING_STRIKE_START, // fade in the flash. note: bolts are requested in the previous state - /* 2 */ LIGHTNING_STRIKE_END // fade out the flash and go back to wait -} LightningStrikeState; - -typedef enum { - /* 0 */ SKYBOX_DMA_INACTIVE, - /* 1 */ SKYBOX_DMA_FILE1_START, - /* 2 */ SKYBOX_DMA_FILE1_DONE, - /* 3 */ SKYBOX_DMA_PAL1_START, - /* 11 */ SKYBOX_DMA_FILE2_START = 11, - /* 12 */ SKYBOX_DMA_FILE2_DONE, - /* 13 */ SKYBOX_DMA_PAL2_START -} SkyboxDmaState; - -typedef enum { - /* 0 */ SANDSTORM_OFF, - /* 1 */ SANDSTORM_FILL, - /* 2 */ SANDSTORM_UNFILL, - /* 3 */ SANDSTORM_ACTIVE, - /* 4 */ SANDSTORM_DISSIPATE -} SandstormState; - -typedef struct { - /* 0x00 */ u8 state; - /* 0x01 */ u8 flashRed; - /* 0x02 */ u8 flashGreen; - /* 0x03 */ u8 flashBlue; - /* 0x04 */ u8 flashAlphaTarget; - /* 0x08 */ f32 delayTimer; -} LightningStrike; // size = 0xC - -// describes what skybox files and blending modes to use depending on time of day -typedef struct { - /* 0x00 */ u16 startTime; - /* 0x02 */ u16 endTime; - /* 0x04 */ u8 blend; // if true, blend between.. skyboxes? palettes? - /* 0x05 */ u8 skybox1Index; // whats the difference between _pal and non _pal files? - /* 0x06 */ u8 skybox2Index; -} struct_8011FC1C; // size = 0x8 - -typedef struct { - /* 0x00 */ u8 ambientColor[3]; - /* 0x03 */ s8 light1Dir[3]; - /* 0x06 */ u8 light1Color[3]; - /* 0x09 */ s8 light2Dir[3]; - /* 0x0C */ u8 light2Color[3]; - /* 0x0F */ u8 fogColor[3]; - /* 0x12 */ s16 fogNear; - /* 0x14 */ s16 fogFar; -} EnvLightSettings; // size = 0x16 - -// 1.0: 801D8EC4 -// dbg: 80222A44 -typedef struct { - /* 0x00 */ char unk_00[0x02]; - /* 0x02 */ u16 timeIncrement; // how many units of time that pass every update - /* 0x04 */ Vec3f sunPos; // moon position can be found by negating the sun position - /* 0x10 */ u8 skybox1Index; - /* 0x11 */ u8 skybox2Index; - /* 0x12 */ char unk_12[0x01]; - /* 0x13 */ u8 skyboxBlend; - /* 0x14 */ char unk_14[0x01]; - /* 0x15 */ u8 skyboxDisabled; - /* 0x16 */ u8 sunMoonDisabled; - /* 0x17 */ u8 unk_17; // currentWeatherMode for skybox? (prev called gloomySky) - /* 0x18 */ u8 unk_18; // nextWeatherMode for skybox? - /* 0x19 */ u8 unk_19; - /* 0x1A */ u16 unk_1A; - /* 0x1C */ char unk_1C[0x02]; - /* 0x1E */ u8 indoors; // when set, day time has no effect on lighting - /* 0x1F */ u8 unk_1F; // outdoor light index - /* 0x20 */ u8 unk_20; // prev outdoor light index? - /* 0x21 */ u8 unk_21; - /* 0x22 */ u16 unk_22; - /* 0x24 */ u16 unk_24; - /* 0x26 */ char unk_26[0x02]; - /* 0x28 */ LightInfo dirLight1; // used for sunlight outdoors - /* 0x36 */ LightInfo dirLight2; // used for moonlight outdoors - /* 0x44 */ s8 skyboxDmaState; - /* 0x48 */ DmaRequest dmaRequest; - /* 0x68 */ OSMesgQueue loadQueue; - /* 0x80 */ OSMesg loadMsg; - /* 0x84 */ f32 unk_84; - /* 0x88 */ f32 unk_88; - /* 0x8C */ s16 adjAmbientColor[3]; - /* 0x92 */ s16 adjLight1Color[3]; - /* 0x98 */ s16 adjFogColor[3]; - /* 0x9E */ s16 adjFogNear; - /* 0xA0 */ s16 adjFogFar; - /* 0xA2 */ char unk_A2[0x06]; - /* 0xA8 */ Vec3s windDirection; - /* 0xB0 */ f32 windSpeed; - /* 0xB4 */ u8 numLightSettings; - /* 0xB8 */ EnvLightSettings* lightSettingsList; // list of light settings from the scene file - /* 0xBC */ u8 blendIndoorLights; // when true, blend between indoor light settings when switching - /* 0xBD */ u8 unk_BD; // indoor light index - /* 0xBE */ u8 unk_BE; // prev indoor light index? - /* 0xBF */ u8 unk_BF; - /* 0xC0 */ EnvLightSettings lightSettings; - /* 0xD6 */ u16 unk_D6; - /* 0xD8 */ f32 unk_D8; // indoor light blend weight? - /* 0xDC */ u8 unk_DC; - /* 0xDD */ u8 gloomySkyMode; - /* 0xDE */ u8 unk_DE; // gloomy sky state - /* 0xDF */ u8 lightningMode; - /* 0xE0 */ u8 unk_E0; // env sounds state - /* 0xE1 */ u8 fillScreen; - /* 0xE2 */ u8 screenFillColor[4]; - /* 0xE6 */ u8 sandstormState; - /* 0xE7 */ u8 sandstormPrimA; - /* 0xE8 */ u8 sandstormEnvA; - /* 0xE9 */ u8 customSkyboxFilter; - /* 0xEA */ u8 skyboxFilterColor[4]; - /* 0xEE */ u8 unk_EE[4]; - /* 0xF2 */ u8 unk_F2[4]; - /* 0xF6 */ char unk_F6[0x06]; -} EnvironmentContext; // size = 0xFC - -#endif diff --git a/soh/include/z64math.h b/soh/include/z64math.h index d07f56659c7..170ae9e4c56 100644 --- a/soh/include/z64math.h +++ b/soh/include/z64math.h @@ -12,77 +12,90 @@ #define Vec3s Vec3s_ #endif -typedef struct { +typedef struct Vec2f { f32 x, y; } Vec2f; // size = 0x08 -typedef struct { +typedef struct Vec3f { f32 x, y, z; } Vec3f; // size = 0x0C -typedef struct { +typedef struct Vec3us { u16 x, y, z; } Vec3us; // size = 0x06 -typedef struct { +typedef struct Vec3s { s16 x, y, z; } Vec3s; // size = 0x06 -typedef struct { +typedef struct Vec3i { s32 x, y, z; } Vec3i; // size = 0x0C -typedef struct { +typedef struct Sphere16 { Vec3s center; s16 radius; } Sphere16; // size = 0x08 -typedef struct { +typedef struct Spheref { Vec3f center; f32 radius; } Spheref; // size = 0x10 -typedef struct { +typedef struct Plane { Vec3f normal; f32 originDist; } Plane; // size = 0x10 -typedef struct { +typedef struct TriNorm { Vec3f vtx[3]; Plane plane; } TriNorm; // size = 0x34 -typedef struct { +typedef struct Cylinder16 { /* 0x0000 */ s16 radius; /* 0x0002 */ s16 height; /* 0x0004 */ s16 yShift; /* 0x0006 */ Vec3s pos; } Cylinder16; // size = 0x0C -typedef struct { +typedef struct Cylinderf { /* 0x00 */ f32 radius; /* 0x04 */ f32 height; /* 0x08 */ f32 yShift; /* 0x0C */ Vec3f pos; } Cylinderf; // size = 0x18 -typedef struct { +typedef struct InfiniteLine { /* 0x0000 */ Vec3f point; /* 0x000C */ Vec3f dir; } InfiniteLine; // size = 0x18 -typedef struct { +typedef struct Linef { /* 0x0000 */ Vec3f a; /* 0x000C */ Vec3f b; } Linef; // size = 0x18 // Defines a point in the spherical coordinate system -typedef struct { +typedef struct VecSph { /* 0x00 */ f32 r; // radius /* 0x04 */ s16 pitch; // polar (zenith) angle /* 0x06 */ s16 yaw; // azimuthal angle } VecSph; // size = 0x08 +/** + * Macros + */ + +// General number macros +#define SQ(x) ((x)*(x)) +#define ABS(x) ((x) >= 0 ? (x) : -(x)) +#define DECR(x) ((x) == 0 ? 0 : --(x)) +#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) +#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) +#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) + +// LERP macros #define LERP(x, y, scale) (((y) - (x)) * (scale) + (x)) #define LERP32(x, y, scale) ((s32)(((y) - (x)) * (scale)) + (x)) #define LERP16(x, y, scale) ((s16)(((y) - (x)) * (scale)) + (x)) diff --git a/soh/include/z64save.h b/soh/include/z64save.h index ee35859013b..121f44ff8d2 100644 --- a/soh/include/z64save.h +++ b/soh/include/z64save.h @@ -447,12 +447,63 @@ typedef enum { #define IS_CUTSCENE_LAYER (gSaveContext.sceneLayer >= SCENE_LAYER_CUTSCENE_FIRST) -typedef enum { +typedef enum LinkAge { /* 0 */ LINK_AGE_ADULT, /* 1 */ LINK_AGE_CHILD } LinkAge; +#define LINK_IS_ADULT (gSaveContext.linkAge == LINK_AGE_ADULT) +#define LINK_IS_CHILD (gSaveContext.linkAge == LINK_AGE_CHILD) + +#define YEARS_CHILD 5 +#define YEARS_ADULT 17 +#define LINK_AGE_IN_YEARS (!LINK_IS_ADULT ? YEARS_CHILD : YEARS_ADULT) + +#define CLOCK_TIME(hr, min) ((s32)(((hr) * 60 + (min)) * (f32)0x10000 / (24 * 60) + 0.5f)) + +#define IS_DAY (gSaveContext.nightFlag == 0) +#define IS_NIGHT (gSaveContext.nightFlag == 1) + +#define SLOT(item) gItemSlots[item] +#define INV_CONTENT(item) gSaveContext.inventory.items[SLOT(item)] +#define AMMO(item) gSaveContext.inventory.ammo[SLOT(item)] +#define BEANS_BOUGHT AMMO(ITEM_BEAN + 1) + +#define ALL_EQUIP_VALUE(equip) ((s32)(gSaveContext.inventory.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) +#define CUR_EQUIP_VALUE(equip) ((s32)(gSaveContext.equips.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) +#define OWNED_EQUIP_FLAG(equip, value) (gBitFlags[value] << gEquipShifts[equip]) +#define OWNED_EQUIP_FLAG_ALT(equip, value) ((1 << (value)) << gEquipShifts[equip]) +#define CHECK_OWNED_EQUIP(equip, value) (OWNED_EQUIP_FLAG(equip, value) & gSaveContext.inventory.equipment) +#define CHECK_OWNED_EQUIP_ALT(equip, value) (gBitFlags[(value) + (equip) * 4] & gSaveContext.inventory.equipment) + +#define SWORD_EQUIP_TO_PLAYER(swordEquip) (swordEquip) +#define SHIELD_EQUIP_TO_PLAYER(shieldEquip) (shieldEquip) +#define TUNIC_EQUIP_TO_PLAYER(tunicEquip) ((tunicEquip) - 1) +#define BOOTS_EQUIP_TO_PLAYER(bootsEquip) ((bootsEquip) - 1) + +#define CUR_UPG_VALUE(upg) ((s32)(gSaveContext.inventory.upgrades & gUpgradeMasks[upg]) >> gUpgradeShifts[upg]) +#define CAPACITY(upg, value) gUpgradeCapacities[upg][value] +#define CUR_CAPACITY(upg) CAPACITY(upg, CUR_UPG_VALUE(upg)) + +#define CHECK_QUEST_ITEM(item) (gBitFlags[item] & gSaveContext.inventory.questItems) +#define CHECK_DUNGEON_ITEM(item, dungeonIndex) (gSaveContext.inventory.dungeonItems[dungeonIndex] & gBitFlags[item]) + +#define GET_GS_FLAGS(index) \ + ((gSaveContext.gsFlags[(index) >> 2] & gGsFlagsMasks[(index) & 3]) >> gGsFlagsShifts[(index) & 3]) +#define SET_GS_FLAGS(index, value) \ + (gSaveContext.gsFlags[(index) >> 2] |= (value) << gGsFlagsShifts[(index) & 3]) + +#define HIGH_SCORE(score) (gSaveContext.highScores[score]) + +#define B_BTN_ITEM ((gSaveContext.buttonStatus[0] == ITEM_NONE) \ + ? ITEM_NONE \ + : (gSaveContext.equips.buttonItems[0] == ITEM_SWORD_KNIFE) \ + ? ITEM_SWORD_BGS \ + : gSaveContext.equips.buttonItems[0]) +#define C_BTN_ITEM(button) ((gSaveContext.buttonStatus[(button) + 1] != BTN_DISABLED) \ + ? gSaveContext.equips.buttonItems[(button) + 1] \ + : ITEM_NONE) /* * diff --git a/soh/soh/Enhancements/Graphics/DisableFixedCamera.cpp b/soh/soh/Enhancements/Graphics/DisableFixedCamera.cpp index 55e1674b6b3..1c86766e360 100644 --- a/soh/soh/Enhancements/Graphics/DisableFixedCamera.cpp +++ b/soh/soh/Enhancements/Graphics/DisableFixedCamera.cpp @@ -116,6 +116,8 @@ static void DisableFixedCamera_RestoreCameraData(CollisionHeader* colHeader) { it->second.active = false; } +extern "C" CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); + extern "C" void DisableFixedCamera_SetNormalCamera(PlayState* play) { CollisionHeader* colHeader = BgCheck_GetCollisionHeader(&play->colCtx, BGCHECK_SCENE); if (colHeader != nullptr && colHeader->cameraDataList != nullptr && colHeader->cameraDataListLen > 0) { diff --git a/soh/soh/Enhancements/debugger/colViewer.cpp b/soh/soh/Enhancements/debugger/colViewer.cpp index 42302d19cec..4974786d7e4 100644 --- a/soh/soh/Enhancements/debugger/colViewer.cpp +++ b/soh/soh/Enhancements/debugger/colViewer.cpp @@ -7,6 +7,8 @@ #include #include "soh/Enhancements/game-interactor/GameInteractor.h" +#include "skin_matrix.h" + extern "C" { #include #include "variables.h" diff --git a/soh/src/boot/z_locale.c b/soh/src/boot/z_locale.c index 8ee57ba83ea..de6c5bdb170 100644 --- a/soh/src/boot/z_locale.c +++ b/soh/src/boot/z_locale.c @@ -1,4 +1,5 @@ #include "global.h" +#include "padmgr.h" #include "vt.h" u32 gCurrentRegion = 0; diff --git a/soh/src/code/code_800430A0.c b/soh/src/code/code_800430A0.c index d1ccacc0dc2..8d9d5ec081e 100644 --- a/soh/src/code/code_800430A0.c +++ b/soh/src/code/code_800430A0.c @@ -1,4 +1,5 @@ #include "global.h" +#include "skin_matrix.h" #include "vt.h" void func_800430A0(CollisionContext* colCtx, s32 bgId, Actor* actor) { diff --git a/soh/src/code/code_800A9F30.c b/soh/src/code/code_800A9F30.c index 512ad49408e..c752aef22b9 100644 --- a/soh/src/code/code_800A9F30.c +++ b/soh/src/code/code_800A9F30.c @@ -1,4 +1,5 @@ #include "global.h" +#include "padmgr.h" UnkRumbleStruct D_80160FD0; diff --git a/soh/src/code/code_800D2E30.c b/soh/src/code/code_800D2E30.c index 725df18cce4..f58ac251c47 100644 --- a/soh/src/code/code_800D2E30.c +++ b/soh/src/code/code_800D2E30.c @@ -1,4 +1,5 @@ #include "global.h" +#include "padmgr.h" #include void func_800D2E30(UnkRumbleStruct* arg0) { diff --git a/soh/src/code/code_800D31A0.c b/soh/src/code/code_800D31A0.c index 8e8a438c617..36fbafa0bcb 100644 --- a/soh/src/code/code_800D31A0.c +++ b/soh/src/code/code_800D31A0.c @@ -1,4 +1,6 @@ #include "global.h" +#include "padmgr.h" +#include "libc64/sleep.h" #include "vt.h" u32 gIsCtrlr2Valid = false; diff --git a/soh/src/code/code_800EC960.c b/soh/src/code/code_800EC960.c index 20cd7127dd3..8ffb6964183 100644 --- a/soh/src/code/code_800EC960.c +++ b/soh/src/code/code_800EC960.c @@ -1,6 +1,7 @@ #include #include #include "global.h" +#include "padmgr.h" #include "soh/OTRGlobals.h" #include "soh/Enhancements/audio/AudioEditor.h" #include "soh/Enhancements/game-interactor/GameInteractor.h" diff --git a/soh/src/code/db_camera.c b/soh/src/code/db_camera.c index 3647211604b..a111ef73e08 100644 --- a/soh/src/code/db_camera.c +++ b/soh/src/code/db_camera.c @@ -1,5 +1,8 @@ #include #include "global.h" +#include "debug_display.h" +#include "mempak.h" +#include "olib.h" static PlayState* sPlayState; diff --git a/soh/src/code/fault.c b/soh/src/code/fault.c index c5331fabbeb..0a50cc887ca 100644 --- a/soh/src/code/fault.c +++ b/soh/src/code/fault.c @@ -1,5 +1,7 @@ #include "global.h" +#include "padmgr.h" #include "vt.h" +#include "libc64/sleep.h" #include // data diff --git a/soh/src/code/game.c b/soh/src/code/game.c index 354c6ce67cd..01fc12d5bd2 100644 --- a/soh/src/code/game.c +++ b/soh/src/code/game.c @@ -1,5 +1,6 @@ #include #include "global.h" +#include "padmgr.h" #include "vt.h" #include #include "soh/Enhancements/game-interactor/GameInteractor.h" diff --git a/soh/src/code/graph.c b/soh/src/code/graph.c index be406ce1ece..d925679b164 100644 --- a/soh/src/code/graph.c +++ b/soh/src/code/graph.c @@ -1,4 +1,6 @@ #include "global.h" +#include "padmgr.h" +#include "prenmi_buff.h" #include "vt.h" #include "regs.h" diff --git a/soh/src/code/jpegdecoder.c b/soh/src/code/jpegdecoder.c index 5261264c7cc..cdfc7b68945 100644 --- a/soh/src/code/jpegdecoder.c +++ b/soh/src/code/jpegdecoder.c @@ -1,11 +1,18 @@ #include "global.h" +#include +#include "jpeg.h" + u8* sJpegBitStreamPtr; u32 sJpegBitStreamByteIdx; u8 sJpegBitStreamBitIdx; u8 sJpegBitStreamDontSkip; u32 sJpegBitStreamCurWord; +s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1, u16* mcu, s16* unk); +s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, s8* outZeroCount); +u16 JpegDecoder_ReadBits(u8 len); + s32 JpegDecoder_Decode(JpegDecoder* decoder, u16* mcuBuff, s32 count, u8 isFollowing, JpegDecoderState* state) { s16 pad; s16 unk0; diff --git a/soh/src/code/jpegutils.c b/soh/src/code/jpegutils.c index 00c0406096d..4e0b0986377 100644 --- a/soh/src/code/jpegutils.c +++ b/soh/src/code/jpegutils.c @@ -1,5 +1,8 @@ #include "global.h" +#include +#include "jpeg.h" + void JpegUtils_ProcessQuantizationTable(u8* dqt, JpegQuantizationTable* qt, u8 count) { u8 i; diff --git a/soh/src/code/main.c b/soh/src/code/main.c index 98c632665b7..d900f55258f 100644 --- a/soh/src/code/main.c +++ b/soh/src/code/main.c @@ -4,6 +4,8 @@ #endif #include "global.h" +#include "padmgr.h" +#include "prenmi_buff.h" #include "vt.h" #include "stdio.h" #include diff --git a/soh/src/code/mempak.c b/soh/src/code/mempak.c index 1b9d95ee8df..89722429a5b 100644 --- a/soh/src/code/mempak.c +++ b/soh/src/code/mempak.c @@ -1,4 +1,5 @@ #include "global.h" +#include "padmgr.h" OSPfs sMempakPfsHandle; s32 sMempakFreeBytes; diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index 173b03394bb..891cf9f3006 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -1,4 +1,5 @@ #include "global.h" +#include "padmgr.h" #include "vt.h" #include diff --git a/soh/src/code/sys_math3d.c b/soh/src/code/sys_math3d.c index 66ec88316b3..239f03cdb46 100644 --- a/soh/src/code/sys_math3d.c +++ b/soh/src/code/sys_math3d.c @@ -1,4 +1,5 @@ #include "global.h" +#include "sys_math3d.h" #include "vt.h" s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, diff --git a/soh/src/code/z_bgcheck.c b/soh/src/code/z_bgcheck.c index 7339ef9d636..d6616ca33e6 100644 --- a/soh/src/code/z_bgcheck.c +++ b/soh/src/code/z_bgcheck.c @@ -29,6 +29,9 @@ #define COLPOLY_IGNORE_ENTITY (1 << 1) #define COLPOLY_IGNORE_PROJECTILES (1 << 2) +void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* arg2); +s32 BgCheck_PosInStaticBoundingBox(CollisionContext* colCtx, Vec3f* pos); + // func_80041DB8, SurfaceType wall properties s32 D_80119D90[32] = { 0, 1, 3, 5, 8, 16, 32, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/soh/src/code/z_debug_display.c b/soh/src/code/z_debug_display.c index aa76cba7ee2..d643e85dd7e 100644 --- a/soh/src/code/z_debug_display.c +++ b/soh/src/code/z_debug_display.c @@ -1,4 +1,5 @@ #include "global.h" +#include "debug_display.h" #include "objects/gameplay_keep/gameplay_keep.h" #include "soh/Enhancements/game-interactor/GameInteractor.h" diff --git a/soh/src/code/z_jpeg.c b/soh/src/code/z_jpeg.c index 89abf3e73d9..73ec51c18c1 100644 --- a/soh/src/code/z_jpeg.c +++ b/soh/src/code/z_jpeg.c @@ -1,4 +1,5 @@ #include "global.h" +#include "jpeg.h" #include "vt.h" #include diff --git a/soh/src/code/z_play.c b/soh/src/code/z_play.c index db5c8cb0ea4..3434a50f506 100644 --- a/soh/src/code/z_play.c +++ b/soh/src/code/z_play.c @@ -352,6 +352,8 @@ u8 CheckBridgeRewardCount() { return bridgeRewardCount; } +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); + void Play_Init(GameState* thisx) { PlayState* play = (PlayState*)thisx; GraphicsContext* gfxCtx = play->state.gfxCtx; diff --git a/soh/src/code/z_prenmi_buff.c b/soh/src/code/z_prenmi_buff.c index c00d0513c02..81927c37936 100644 --- a/soh/src/code/z_prenmi_buff.c +++ b/soh/src/code/z_prenmi_buff.c @@ -1,4 +1,5 @@ #include "global.h" +#include "prenmi_buff.h" #define COLD_RESET 0 #define NMI 1 diff --git a/soh/src/code/z_quake.c b/soh/src/code/z_quake.c index 4cb9b7aa586..f9b5b84af81 100644 --- a/soh/src/code/z_quake.c +++ b/soh/src/code/z_quake.c @@ -3,6 +3,13 @@ #include +s16 Quake_Callback1(QuakeRequest* req, ShakeInfo* shake); +s16 Quake_Callback2(QuakeRequest* req, ShakeInfo* shake); +s16 Quake_Callback3(QuakeRequest* req, ShakeInfo* shake); +s16 Quake_Callback4(QuakeRequest* req, ShakeInfo* shake); +s16 Quake_Callback5(QuakeRequest* req, ShakeInfo* shake); +s16 Quake_Callback6(QuakeRequest* req, ShakeInfo* shake); + QuakeRequest sQuakeRequest[4]; s16 D_80126250 = 1; s16 sQuakeRequestCount = 0; diff --git a/soh/src/code/z_vr_box.c b/soh/src/code/z_vr_box.c index 26bbb98358c..24343e891c6 100644 --- a/soh/src/code/z_vr_box.c +++ b/soh/src/code/z_vr_box.c @@ -4,7 +4,7 @@ #include #include -#include "z64environment.h" +#include "environment.h" #include "assets/textures/backgrounds/vr_ALVR_static.h" #include "assets/textures/backgrounds/vr_ALVR_pal_static.h" #include "assets/textures/backgrounds/vr_DGVR_static.h"