Reduce overlay dependencies on global.h (8) (#2478)

* move variables into z64environment.h

* z_room.h

* z64sram.h, z64ss_sram.h, z64font.h, kanread.h

* z64lifemeter.h, z64debug.h, debug_arena.h

* buffers.h

* remove z_bgcheck global

* gamealloc.h

* suggestions

* .bdd
This commit is contained in:
mzxrules
2025-02-19 05:54:39 -05:00
committed by GitHub
parent 3d61fb85ef
commit 981af4b6af
72 changed files with 578 additions and 392 deletions

15
include/buffers.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef BUFFERS_H
#define BUFFERS_H
#include "gfx.h"
#include "macros.h"
#include "ultra64.h"
extern u16 gZBuffer[SCREEN_HEIGHT][SCREEN_WIDTH]; // 0x25800 bytes
extern u64 gGfxSPTaskOutputBuffer[0x3000]; // 0x18000 bytes
extern u64 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE / sizeof(u64)]; // 0xC00 bytes
extern u64 gGfxSPTaskStack[SP_DRAM_STACK_SIZE64]; // 0x400 bytes
extern GfxPool gGfxPools[2]; // 0x24820 bytes
extern u8 gAudioHeap[0x38000]; // 0x38000 bytes
#endif

38
include/debug_arena.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef DEBUG_ARENA_H
#define DEBUG_ARENA_H
#include "ultra64/ultratypes.h"
void* DebugArena_Malloc(u32 size);
void* DebugArena_MallocR(u32 size);
void* DebugArena_Realloc(void* ptr, u32 newSize);
void DebugArena_Free(void* ptr);
void* DebugArena_Calloc(u32 num, u32 size);
void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc);
void DebugArena_Check(void);
void DebugArena_Init(void* start, u32 size);
void DebugArena_Cleanup(void);
s32 DebugArena_IsInitialized(void);
#if DEBUG_FEATURES
#define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_MallocDebug(size, file, line)
#define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocRDebug(size, file, line)
#define DEBUG_ARENA_FREE(size, file, line) DebugArena_FreeDebug(size, file, line)
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action);
void* DebugArena_MallocDebug(u32 size, const char* file, int line);
void* DebugArena_MallocRDebug(u32 size, const char* file, int line);
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line);
void DebugArena_FreeDebug(void* ptr, const char* file, int line);
void DebugArena_Display(void);
#else
#define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_Malloc(size)
#define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocR(size)
#define DEBUG_ARENA_FREE(size, file, line) DebugArena_Free(size)
#endif
#endif

View File

@@ -36,32 +36,9 @@ void ActorOverlayTable_Init(void);
void ActorOverlayTable_Cleanup(void);
void SaveContext_Init(void);
s32 func_800635D0(s32);
void Regs_Init(void);
void DebugCamera_ScreenText(u8 x, u8 y, const char* text);
void DebugCamera_ScreenTextColored(u8 x, u8 y, u8 colorIndex, const char* text);
#if DEBUG_FEATURES
void Regs_UpdateEditor(Input* input);
#endif
void Debug_DrawText(GraphicsContext* gfxCtx);
void* MemCpy(void* dest, const void* src, s32 len);
s32 Kanji_OffsetFromShiftJIS(s32 character);
#if PLATFORM_IQUE
void Font_LoadCharCHN(Font* font, u16 character, u16 codePointIndex);
#endif
void Font_LoadCharWide(Font* font, u16 character, u16 codePointIndex);
void Font_LoadChar(Font* font, u8 character, u16 codePointIndex);
void Font_LoadMessageBoxIcon(Font* font, u16 icon);
void Font_LoadOrderedFont(Font* font);
void Health_InitMeter(PlayState* play);
void Health_UpdateMeter(PlayState* play);
void Health_DrawMeter(PlayState* play);
void Health_UpdateBeatingHeart(PlayState* play);
u32 Health_IsCritical(void);
void MapMark_Init(PlayState* play);
void MapMark_ClearPointers(PlayState* play);
void MapMark_Draw(PlayState* play);
@@ -72,35 +49,9 @@ void Sched_FlushTaskQueue(void);
void PreNMI_Init(GameState* thisx);
void func_80095AA0(PlayState* play, Room* room, Input* input, s32 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);
void Room_Init(PlayState* play, Room* room);
u32 Room_SetupFirstRoom(PlayState* play, RoomContext* roomCtx);
s32 Room_RequestNewRoom(PlayState* play, RoomContext* roomCtx, s32 roomNum);
s32 Room_ProcessRoomRequest(PlayState* play, RoomContext* roomCtx);
void Room_Draw(PlayState* play, Room* room, u32 flags);
void Room_FinishRoomChange(PlayState* play, RoomContext* roomCtx);
void Sample_Destroy(GameState* thisx);
void Sample_Init(GameState* thisx);
void Sram_InitNewSave(void);
void Sram_InitDebugSave(void);
void Sram_OpenSave(SramContext* sramCtx);
void Sram_WriteSave(SramContext* sramCtx);
void Sram_VerifyAndLoadAllSaves(FileSelectState* fileSelect, SramContext* sramCtx);
void Sram_InitSave(FileSelectState* fileSelect, SramContext* sramCtx);
void Sram_EraseSave(FileSelectState* fileSelect, SramContext* sramCtx);
void Sram_CopySave(FileSelectState* fileSelect, SramContext* sramCtx);
void Sram_WriteSramHeader(SramContext* sramCtx);
void Sram_InitSram(GameState* gameState, SramContext* sramCtx);
void Sram_Alloc(GameState* gameState, SramContext* sramCtx);
void Sram_Init(PlayState* play, SramContext* sramCtx);
void SsSram_Init(s32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed);
void SsSram_Dma(void* dramAddr, size_t size, s32 direction);
void SsSram_ReadWrite(s32 addr, void* dramAddr, size_t size, s32 direction);
void ViMode_LogPrint(OSViMode* osViMode);
void ViMode_Configure(ViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 antialiasOff, s32 modeN, s32 fb16Bit,
s32 width, s32 height, s32 leftAdjust, s32 rightAdjust, s32 upperAdjust, s32 lowerAdjust);
@@ -168,13 +119,6 @@ void func_800C213C(PreRender* this, Gfx** gfxP);
void PreRender_RestoreFramebuffer(PreRender* this, Gfx** gfxP);
void PreRender_CopyImageRegion(PreRender* this, Gfx** gfxP);
void PreRender_ApplyFilters(PreRender* this);
#if DEBUG_FEATURES
void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, int line);
#endif
void* GameAlloc_Malloc(GameAlloc* this, u32 size);
void GameAlloc_Free(GameAlloc* this, void* data);
void GameAlloc_Cleanup(GameAlloc* this);
void GameAlloc_Init(GameAlloc* this);
void Graph_InitTHGA(GraphicsContext* gfxCtx);
GameStateOverlay* Graph_GetNextGameState(GameState* gameState);
void Graph_Init(GraphicsContext* gfxCtx);
@@ -195,24 +139,6 @@ void* SysCfb_GetFbEnd(void);
NORETURN void func_800D31A0(void);
void func_800D31F0(void);
void func_800D3210(void);
void* DebugArena_Malloc(u32 size);
void* DebugArena_MallocR(u32 size);
void* DebugArena_Realloc(void* ptr, u32 newSize);
void DebugArena_Free(void* ptr);
void* DebugArena_Calloc(u32 num, u32 size);
void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc);
void DebugArena_Check(void);
void DebugArena_Init(void* start, u32 size);
void DebugArena_Cleanup(void);
s32 DebugArena_IsInitialized(void);
#if DEBUG_FEATURES
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action);
void* DebugArena_MallocDebug(u32 size, const char* file, int line);
void* DebugArena_MallocRDebug(u32 size, const char* file, int line);
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line);
void DebugArena_FreeDebug(void* ptr, const char* file, int line);
void DebugArena_Display(void);
#endif
void RcpUtils_PrintRegisterStatus(void);
void RcpUtils_Reset(void);

31
include/gamealloc.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef GAMEALLOC_H
#define GAMEALLOC_H
#include "ultra64/ultratypes.h"
typedef struct GameAllocEntry {
/* 0x00 */ struct GameAllocEntry* next;
/* 0x04 */ struct GameAllocEntry* prev;
/* 0x08 */ u32 size;
/* 0x0C */ u32 unk_0C;
} GameAllocEntry; // size = 0x10
typedef struct GameAlloc {
/* 0x00 */ GameAllocEntry base;
/* 0x10 */ GameAllocEntry* head;
} GameAlloc; // size = 0x14
#if DEBUG_FEATURES
#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_MallocDebug(alloc, size, file, line)
void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, int line);
#else
#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_Malloc(alloc, size)
#endif
void* GameAlloc_Malloc(GameAlloc* this, u32 size);
void GameAlloc_Free(GameAlloc* this, void* data);
void GameAlloc_Cleanup(GameAlloc* this);
void GameAlloc_Init(GameAlloc* this);
#endif

8
include/kanread.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef KANREAD_H
#define KANREAD_H
#include "ultra64/ultratypes.h"
s32 Kanji_OffsetFromShiftJIS(s32 sjis);
#endif

View File

@@ -16,11 +16,19 @@ void SystemArena_Cleanup(void);
s32 SystemArena_IsInitialized(void);
#if DEBUG_FEATURES
#define SYSTEM_ARENA_MALLOC(size, file, line) SystemArena_MallocDebug(size, file, line)
#define SYSTEM_ARENA_MALLOC_R(size, file, line) SystemArena_MallocRDebug(size, file, line)
#define SYSTEM_ARENA_FREE(size, file, line) SystemArena_FreeDebug(size, file, line)
void* SystemArena_MallocDebug(u32 size, const char* file, int line);
void* SystemArena_MallocRDebug(u32 size, const char* file, int line);
void* SystemArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line);
void SystemArena_FreeDebug(void* ptr, const char* file, int line);
void SystemArena_Display(void);
#else
#define SYSTEM_ARENA_MALLOC(size, file, line) SystemArena_Malloc(size)
#define SYSTEM_ARENA_MALLOC_R(size, file, line) SystemArena_MallocR(size)
#define SYSTEM_ARENA_FREE(size, file, line) SystemArena_Free(size)
#endif
extern Arena gSystemArena;

View File

@@ -3,12 +3,33 @@
#include "ultra64.h"
#if DEBUG_FEATURES
#define LOG(exp, value, format, file, line) \
do { \
LogUtils_LogThreadId(file, line); \
osSyncPrintf(exp " = " format "\n", value); \
} while (0)
#else
#define LOG(exp, value, format, file, line) (void)(value)
#endif
#define LOG_STRING(string, file, line) LOG(#string, string, "%s", file, line)
#define LOG_ADDRESS(exp, value, file, line) LOG(exp, value, "%08x", file, line)
#define LOG_TIME(exp, value, file, line) LOG(exp, value, "%lld", file, line)
#define LOG_NUM(exp, value, file, line) LOG(exp, value, "%d", file, line)
#define LOG_HEX(exp, value, file, line) LOG(exp, value, "%x", file, line)
#define LOG_HEX32(exp, value, file, line) LOG(exp, value, "%08x", file, line)
#define LOG_FLOAT(exp, value, file, line) LOG(exp, value, "%f", file, line)
#if PLATFORM_N64 || DEBUG_FEATURES
f32 LogUtils_CheckFloatRange(const char* exp, int line, const char* valueName, f32 value, const char* minName, f32 min,
const char* maxName, f32 max);
#endif
#if DEBUG_FEATURES
#define LOG_UTILS_CHECK_NULL_POINTER(exp, ptr, file, line) LogUtils_CheckNullPointer(exp, ptr, file, line)
#define LOG_UTILS_CHECK_VALID_POINTER(exp, ptr, file, line) LogUtils_CheckValidPointer(exp, ptr, file, line)
s32 LogUtils_CheckIntRange(const char* exp, int line, const char* valueName, s32 value, const char* minName, s32 min,
const char* maxName, s32 max);
void LogUtils_LogHexDump(void* ptr, s32 size0);
@@ -17,6 +38,11 @@ void LogUtils_CheckBoundary(const char* name, s32 value, s32 unk, const char* fi
void LogUtils_CheckNullPointer(const char* exp, void* ptr, const char* file, int line);
void LogUtils_CheckValidPointer(const char* exp, void* ptr, const char* file, int line);
void LogUtils_LogThreadId(const char* name, int line);
#else
#define LOG_UTILS_CHECK_NULL_POINTER(exp, ptr, file, line) (void)0
#define LOG_UTILS_CHECK_VALID_POINTER(exp, ptr, file, line) (void)0
#endif
void LogUtils_HungupThread(const char* name, int line);

View File

@@ -89,24 +89,6 @@
#define PRINTF_RST() (void)0
#endif
#if DEBUG_FEATURES
#define LOG(exp, value, format, file, line) \
do { \
LogUtils_LogThreadId(file, line); \
osSyncPrintf(exp " = " format "\n", value); \
} while (0)
#else
#define LOG(exp, value, format, file, line) (void)(value)
#endif
#define LOG_STRING(string, file, line) LOG(#string, string, "%s", file, line)
#define LOG_ADDRESS(exp, value, file, line) LOG(exp, value, "%08x", file, line)
#define LOG_TIME(exp, value, file, line) LOG(exp, value, "%lld", file, line)
#define LOG_NUM(exp, value, file, line) LOG(exp, value, "%d", file, line)
#define LOG_HEX(exp, value, file, line) LOG(exp, value, "%x", file, line)
#define LOG_HEX32(exp, value, file, line) LOG(exp, value, "%08x", file, line)
#define LOG_FLOAT(exp, value, file, line) LOG(exp, value, "%f", file, line)
#define SET_NEXT_GAMESTATE(curState, newInit, newStruct) \
if (1) { \
GameState* state = curState; \
@@ -116,33 +98,11 @@
} (void)0
#if DEBUG_FEATURES
#define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSyncDebug(ram, vrom, size, file, line)
#define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsyncDebug(req, ram, vrom, size, unk5, queue, msg, file, line)
#define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_MallocDebug(size, file, line)
#define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocRDebug(size, file, line)
#define DEBUG_ARENA_FREE(size, file, line) DebugArena_FreeDebug(size, file, line)
#define SYSTEM_ARENA_MALLOC(size, file, line) SystemArena_MallocDebug(size, file, line)
#define SYSTEM_ARENA_MALLOC_R(size, file, line) SystemArena_MallocRDebug(size, file, line)
#define SYSTEM_ARENA_FREE(size, file, line) SystemArena_FreeDebug(size, file, line)
#define LOG_UTILS_CHECK_NULL_POINTER(exp, ptr, file, line) LogUtils_CheckNullPointer(exp, ptr, file, line)
#define LOG_UTILS_CHECK_VALID_POINTER(exp, ptr, file, line) LogUtils_CheckValidPointer(exp, ptr, file, line)
#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_MallocDebug(alloc, size, file, line)
#else
#define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSync(ram, vrom, size)
#define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsync(req, ram, vrom, size, unk5, queue, msg)
#define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_Malloc(size)
#define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocR(size)
#define DEBUG_ARENA_FREE(size, file, line) DebugArena_Free(size)
#define SYSTEM_ARENA_MALLOC(size, file, line) SystemArena_Malloc(size)
#define SYSTEM_ARENA_MALLOC_R(size, file, line) SystemArena_MallocR(size)
#define SYSTEM_ARENA_FREE(size, file, line) SystemArena_Free(size)
#define LOG_UTILS_CHECK_NULL_POINTER(exp, ptr, file, line) (void)0
#define LOG_UTILS_CHECK_VALID_POINTER(exp, ptr, file, line) (void)0
#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_Malloc(alloc, size)
#endif
#if PLATFORM_N64 || DEBUG_FEATURES

View File

@@ -68,7 +68,6 @@ extern u32 __osTimerCounter;
extern EffectSsOverlay gEffectSsOverlayTable[EFFECT_SS_TYPE_MAX];
extern ActorOverlay gActorOverlayTable[ACTOR_ID_MAX]; // original name: "actor_dlftbls" 801162A0
extern s32 gMaxActorId; // original name: "MaxProfile"
extern s32 gDebugCamEnabled;
extern GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX];
extern s32 gZeldaArenaLogSeverity;
extern MapData gMapDataTable;
@@ -149,18 +148,6 @@ extern u8 gSequenceFontTable[];
extern u8 gSequenceTable[];
extern AudioTable gSampleBankTable;
extern 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.
extern s16 sLightningFlashAlpha;
extern s16 sSunDepthTestX;
extern s16 sSunDepthTestY;
extern u8 gCustomLensFlareOn;
extern Vec3f gCustomLensFlarePos;
extern s16 gLensFlareScale;
extern f32 gLensFlareColorIntensity;
extern s16 gLensFlareGlareStrength;
extern MapData* gMapData;
extern f32 gBossMarkScale;
extern u32 D_8016139C;
@@ -205,11 +192,5 @@ extern u8 __osContLastCmd;
extern u8 __osMaxControllers;
extern __OSInode __osPfsInodeCache;
extern OSPifRam __osPfsPifRam;
extern u16 gZBuffer[SCREEN_HEIGHT][SCREEN_WIDTH]; // 0x25800 bytes
extern u64 gGfxSPTaskOutputBuffer[0x3000]; // 0x18000 bytes
extern u64 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE / sizeof(u64)]; // 0xC00 bytes
extern u64 gGfxSPTaskStack[SP_DRAM_STACK_SIZE64]; // 0x400 bytes
extern GfxPool gGfxPools[2]; // 0x24820 bytes
extern u8 gAudioHeap[0x38000]; // 0x38000 bytes
#endif

View File

@@ -58,11 +58,6 @@
#include "libc64/sprintf.h"
#include "libu64/debug.h"
typedef enum LensMode {
/* 0 */ LENS_MODE_SHOW_ACTORS, // lens actors are invisible by default, and shown by using lens (for example, invisible enemies)
/* 1 */ LENS_MODE_HIDE_ACTORS // lens actors are visible by default, and hidden by using lens (for example, fake walls)
} LensMode;
typedef struct SetupState {
/* 0x00 */ GameState state;
} SetupState; // size = 0xA4

View File

@@ -1698,6 +1698,8 @@ typedef enum DebugCamTextColor {
/* 7 */ DEBUG_CAM_TEXT_GREEN
} DebugCamTextColor;
extern s32 gDebugCamEnabled;
void Camera_Init(Camera* camera, struct View* view, struct CollisionContext* colCtx, struct PlayState* play);
void Camera_InitDataUsingPlayer(Camera* camera, struct Player* player);
s16 Camera_ChangeStatus(Camera* camera, s16 status);

17
include/z64debug.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef Z64DEBUG_H
#define Z64DEBUG_H
#include "ultra64.h"
struct GraphicsContext;
struct Input;
void Regs_Init(void);
void DebugCamera_ScreenText(u8 x, u8 y, const char* text);
void DebugCamera_ScreenTextColored(u8 x, u8 y, u8 colorIndex, const char* text);
#if DEBUG_FEATURES
void Regs_UpdateEditor(struct Input* input);
#endif
void Debug_DrawText(struct GraphicsContext* gfxCtx);
#endif

View File

@@ -242,6 +242,19 @@ extern u8 gLightConfigAfterUnderwater;
extern u8 gInterruptSongOfStorms;
extern u16 gTimeSpeed;
extern 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.
extern s16 sLightningFlashAlpha;
extern s16 sSunDepthTestX;
extern s16 sSunDepthTestY;
extern u8 gCustomLensFlareOn;
extern Vec3f gCustomLensFlarePos;
extern s16 gLensFlareScale;
extern f32 gLensFlareColorIntensity;
extern s16 gLensFlareGlareStrength;
void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, struct SkyboxContext* skyboxCtx);
void Environment_DrawSkyboxFilters(struct PlayState* play);

41
include/z64font.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef Z64FONT_H
#define Z64FONT_H
#include "ultra64.h"
// 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
typedef struct Font {
/* 0x0000 */ u32 msgOffset;
/* 0x0004 */ u32 msgLength;
union {
/* 0x0008 */ u8 charTexBuf[FONT_CHAR_TEX_SIZE * 120];
/* 0x0008 */ u64 force_structure_alignment_charTex;
};
union {
/* 0x3C08 */ u8 iconBuf[FONT_CHAR_TEX_SIZE];
/* 0x3C08 */ u64 force_structure_alignment_icon;
};
union {
/* 0x3C88 */ u8 fontBuf[FONT_CHAR_TEX_SIZE * 320];
/* 0x3C88 */ u64 force_structure_alignment_font;
};
union {
/* 0xDC88 */ u8 msgBuf[1280];
/* 0xDC88 */ u16 msgBufWide[640];
/* 0xDC88 */ u64 force_structure_alignment_msg;
};
} Font; // size = 0xE188
#if PLATFORM_IQUE
void Font_LoadCharCHN(Font* font, u16 character, u16 codePointIndex);
#endif
void Font_LoadCharWide(Font* font, u16 character, u16 codePointIndex);
void Font_LoadChar(Font* font, u8 character, u16 codePointIndex);
void Font_LoadMessageBoxIcon(Font* font, u16 icon);
void Font_LoadOrderedFont(Font* font);
#endif

View File

@@ -4,22 +4,11 @@
#include "ultra64/ultratypes.h"
#include "libu64/pad.h"
#include "gamealloc.h"
#include "tha.h"
struct GraphicsContext;
typedef struct GameAllocEntry {
/* 0x00 */ struct GameAllocEntry* next;
/* 0x04 */ struct GameAllocEntry* prev;
/* 0x08 */ u32 size;
/* 0x0C */ u32 unk_0C;
} GameAllocEntry; // size = 0x10
typedef struct GameAlloc {
/* 0x00 */ GameAllocEntry base;
/* 0x10 */ GameAllocEntry* head;
} GameAlloc; // size = 0x14
// Used in Graph_GetNextGameState in graph.c
#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) enumName,
#define DEFINE_GAMESTATE(typeName, enumName, name) DEFINE_GAMESTATE_INTERNAL(typeName, enumName)

14
include/z64lifemeter.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef Z64LIFEMETER_H
#define Z64LIFEMETER_H
#include "ultra64/ultratypes.h"
struct PlayState;
void Health_InitMeter(struct PlayState* play);
void Health_UpdateMeter(struct PlayState* play);
void Health_DrawMeter(struct PlayState* play);
void Health_UpdateBeatingHeart(struct PlayState* play);
u32 Health_IsCritical(void);
#endif

View File

@@ -3,6 +3,7 @@
#include "z64view.h"
#include "versions.h"
#include "z64font.h"
struct OcarinaStaff;
struct Actor;
@@ -14,11 +15,6 @@ typedef enum TextBoxIcon {
/* 2 */ TEXTBOX_ICON_ARROW
} TextBoxIcon;
// 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 get these properties from the textures themselves
#define MESSAGE_STATIC_TEX_SIZE 0x1000
@@ -129,28 +125,6 @@ typedef enum TextState {
/* 10 */ TEXT_STATE_AWAITING_NEXT
} TextState;
typedef struct Font {
/* 0x0000 */ u32 msgOffset;
/* 0x0004 */ u32 msgLength;
union {
/* 0x0008 */ u8 charTexBuf[FONT_CHAR_TEX_SIZE * 120];
/* 0x0008 */ u64 force_structure_alignment_charTex;
};
union {
/* 0x3C08 */ u8 iconBuf[FONT_CHAR_TEX_SIZE];
/* 0x3C08 */ u64 force_structure_alignment_icon;
};
union {
/* 0x3C88 */ u8 fontBuf[FONT_CHAR_TEX_SIZE * 320];
/* 0x3C88 */ u64 force_structure_alignment_font;
};
union {
/* 0xDC88 */ u8 msgBuf[1280];
/* 0xDC88 */ u16 msgBufWide[640];
/* 0xDC88 */ u64 force_structure_alignment_msg;
};
} Font; // size = 0xE188
#define TEXTBOX_ENDTYPE_DEFAULT 0x00
#define TEXTBOX_ENDTYPE_2_CHOICE 0x10
#define TEXTBOX_ENDTYPE_3_CHOICE 0x20

View File

@@ -17,6 +17,7 @@
#include "z64message.h"
#include "z64object.h"
#include "z64pause.h"
#include "z64room.h"
#include "z64scene.h"
#include "z64sfx_source.h"
#include "z64skybox.h"

174
include/z64room.h Normal file
View File

@@ -0,0 +1,174 @@
#ifndef Z64ROOM_H
#define Z64ROOM_H
#include "ultra64.h"
#include "z64dma.h"
#include "z64math.h"
struct Input;
struct PlayState;
// Room shapes
typedef enum RoomShapeType {
/* 0 */ ROOM_SHAPE_TYPE_NORMAL,
/* 1 */ ROOM_SHAPE_TYPE_IMAGE,
/* 2 */ ROOM_SHAPE_TYPE_CULLABLE,
/* 3 */ ROOM_SHAPE_TYPE_MAX
} RoomShapeType;
typedef struct RoomShapeBase {
/* 0x00 */ u8 type;
} RoomShapeBase; // size = 0x01
typedef struct RoomShapeDListsEntry {
/* 0x00 */ Gfx* opa;
/* 0x04 */ Gfx* xlu;
} RoomShapeDListsEntry; // size = 0x08
typedef struct RoomShapeNormal {
/* 0x00 */ RoomShapeBase base;
/* 0x01 */ u8 numEntries;
/* 0x04 */ RoomShapeDListsEntry* entries;
/* 0x08 */ RoomShapeDListsEntry* entriesEnd;
} RoomShapeNormal; // size = 0x0C
typedef enum RoomShapeImageAmountType {
/* 1 */ ROOM_SHAPE_IMAGE_AMOUNT_SINGLE = 1,
/* 2 */ ROOM_SHAPE_IMAGE_AMOUNT_MULTI
} RoomShapeImageAmountType;
typedef struct RoomShapeImageBase {
/* 0x00 */ RoomShapeBase base;
/* 0x01 */ u8 amountType; // RoomShapeImageAmountType
/* 0x04 */ RoomShapeDListsEntry* entry;
} RoomShapeImageBase; // size = 0x08
typedef struct RoomShapeImageSingle {
/* 0x00 */ RoomShapeImageBase base;
/* 0x08 */ void* source;
/* 0x0C */ u32 unk_0C;
/* 0x10 */ void* tlut;
/* 0x14 */ u16 width;
/* 0x16 */ u16 height;
/* 0x18 */ u8 fmt;
/* 0x19 */ u8 siz;
/* 0x1A */ u16 tlutMode;
/* 0x1C */ u16 tlutCount;
} RoomShapeImageSingle; // size = 0x20
typedef struct RoomShapeImageMultiBgEntry {
/* 0x00 */ u16 unk_00;
/* 0x02 */ u8 bgCamIndex; // for which bg cam index is this entry for
/* 0x04 */ void* source;
/* 0x08 */ u32 unk_0C;
/* 0x0C */ void* tlut;
/* 0x10 */ u16 width;
/* 0x12 */ u16 height;
/* 0x14 */ u8 fmt;
/* 0x15 */ u8 siz;
/* 0x16 */ u16 tlutMode;
/* 0x18 */ u16 tlutCount;
} RoomShapeImageMultiBgEntry; // size = 0x1C
typedef struct RoomShapeImageMulti {
/* 0x00 */ RoomShapeImageBase base;
/* 0x08 */ u8 numBackgrounds;
/* 0x0C */ RoomShapeImageMultiBgEntry* backgrounds;
} RoomShapeImageMulti; // size = 0x10
typedef struct RoomShapeCullableEntry {
/* 0x00 */ Vec3s boundsSphereCenter;
/* 0x06 */ s16 boundsSphereRadius;
/* 0x08 */ Gfx* opa;
/* 0x0C */ Gfx* xlu;
} RoomShapeCullableEntry; // size = 0x10
#define ROOM_SHAPE_CULLABLE_MAX_ENTRIES 64
typedef struct RoomShapeCullable {
/* 0x00 */ RoomShapeBase base;
/* 0x01 */ u8 numEntries;
/* 0x04 */ RoomShapeCullableEntry* entries;
/* 0x08 */ RoomShapeCullableEntry* entriesEnd;
} RoomShapeCullable; // size = 0x0C
typedef union RoomShape {
RoomShapeBase base;
RoomShapeNormal normal;
union {
RoomShapeImageBase base;
RoomShapeImageSingle single;
RoomShapeImageMulti multi;
} image;
RoomShapeCullable cullable;
} RoomShape; // "Ground Shape"
typedef enum RoomType {
/* 0 */ ROOM_TYPE_NORMAL,
/* 1 */ ROOM_TYPE_DUNGEON, // Blocks Sun's Song's time advance effect. Not exclusively used by typical dungeon rooms.
/* 2 */ ROOM_TYPE_INDOORS, // Reduces player run speed and blocks player from attacking or jumping.
/* 3 */ ROOM_TYPE_3, // Unused. Color dithering is turned off when drawing the room and other things.
/* 4 */ ROOM_TYPE_4, // Unused. Prevents switching to CAM_SET_HORSE when mounting a horse.
/* 5 */ ROOM_TYPE_BOSS // Disables Environment_AdjustLights
} RoomType;
typedef enum RoomEnvironmentType {
/* 0 */ ROOM_ENV_DEFAULT,
/* 1 */ ROOM_ENV_COLD,
/* 2 */ ROOM_ENV_WARM,
/* 3 */ ROOM_ENV_HOT, // Enables hot room timer for the current room
/* 4 */ ROOM_ENV_UNK_STRETCH_1,
/* 5 */ ROOM_ENV_UNK_STRETCH_2,
/* 6 */ ROOM_ENV_UNK_STRETCH_3
} RoomEnvironmentType;
typedef enum LensMode {
/* 0 */ LENS_MODE_SHOW_ACTORS, // lens actors are invisible by default, and shown by using lens (for example, invisible enemies)
/* 1 */ LENS_MODE_HIDE_ACTORS // lens actors are visible by default, and hidden by using lens (for example, fake walls)
} LensMode;
typedef struct Room {
/* 0x00 */ s8 num; // -1 is invalid room
/* 0x01 */ u8 unk_01;
/* 0x02 */ u8 environmentType;
/* 0x03 */ u8 type;
/* 0x04 */ s8 echo;
/* 0x05 */ u8 lensMode;
/* 0x08 */ RoomShape* roomShape; // original name: "ground_shape"
/* 0x0C */ void* segment;
/* 0x10 */ char unk_10[0x4];
} Room; // size = 0x14
typedef struct RoomContext {
/* 0x00 */ Room curRoom;
/* 0x14 */ Room prevRoom;
/* 0x28 */ void* bufPtrs[2]; // Start and end pointers for the room buffer. Can be split into two pages, where page 0 is allocated from the start pointer and page 1 is allocated from the end pointer.
/* 0x30 */ u8 activeBufPage; // 0 - First page in memory, 1 - Last page in memory
/* 0x31 */ s8 status; // 0 - Free for new room request, 1 - DmaRequest for a new room is in progress
/* 0x34 */ void* roomRequestAddr; // Pointer to where the requested room segment will be stored
/* 0x38 */ DmaRequest dmaRequest;
/* 0x58 */ OSMesgQueue loadQueue;
/* 0x70 */ OSMesg loadMsg;
/* 0x74 */ s16 drawParams[2]; // context-specific data used by the current scene draw config
} RoomContext; // size = 0x78
typedef struct RoomList {
/* 0x00 */ u8 count;
/* 0x04 */ RomFile* romFiles; // Array of rom addresses for each room in a scene
} RoomList;
#define ROOM_DRAW_OPA (1 << 0)
#define ROOM_DRAW_XLU (1 << 1)
void func_80095AA0(struct PlayState* play, Room* room, struct Input* input, s32 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);
void Room_Init(struct PlayState* play, Room* room);
u32 Room_SetupFirstRoom(struct PlayState* play, RoomContext* roomCtx);
s32 Room_RequestNewRoom(struct PlayState* play, RoomContext* roomCtx, s32 roomNum);
s32 Room_ProcessRoomRequest(struct PlayState* play, RoomContext* roomCtx);
void Room_Draw(struct PlayState* play, Room* room, u32 flags);
void Room_FinishRoomChange(struct PlayState* play, RoomContext* roomCtx);
#endif

View File

@@ -4,7 +4,6 @@
#include "macros.h"
#include "ultra64.h"
#include "z64bgcheck.h"
#include "z64dma.h"
#include "z64environment.h"
#include "z64light.h"
#include "z64math.h"
@@ -14,6 +13,7 @@
struct GameState;
struct PlayState;
struct RoomShapeBase;
typedef struct SceneTableEntry {
/* 0x00 */ RomFile sceneFile;
@@ -52,154 +52,6 @@ typedef struct Spawn {
/* 0x01 */ u8 room;
} Spawn;
// Room shapes
typedef enum RoomShapeType {
/* 0 */ ROOM_SHAPE_TYPE_NORMAL,
/* 1 */ ROOM_SHAPE_TYPE_IMAGE,
/* 2 */ ROOM_SHAPE_TYPE_CULLABLE,
/* 3 */ ROOM_SHAPE_TYPE_MAX
} RoomShapeType;
typedef struct RoomShapeBase {
/* 0x00 */ u8 type;
} RoomShapeBase; // size = 0x01
typedef struct RoomShapeDListsEntry {
/* 0x00 */ Gfx* opa;
/* 0x04 */ Gfx* xlu;
} RoomShapeDListsEntry; // size = 0x08
typedef struct RoomShapeNormal {
/* 0x00 */ RoomShapeBase base;
/* 0x01 */ u8 numEntries;
/* 0x04 */ RoomShapeDListsEntry* entries;
/* 0x08 */ RoomShapeDListsEntry* entriesEnd;
} RoomShapeNormal; // size = 0x0C
typedef enum RoomShapeImageAmountType {
/* 1 */ ROOM_SHAPE_IMAGE_AMOUNT_SINGLE = 1,
/* 2 */ ROOM_SHAPE_IMAGE_AMOUNT_MULTI
} RoomShapeImageAmountType;
typedef struct RoomShapeImageBase {
/* 0x00 */ RoomShapeBase base;
/* 0x01 */ u8 amountType; // RoomShapeImageAmountType
/* 0x04 */ RoomShapeDListsEntry* entry;
} RoomShapeImageBase; // size = 0x08
typedef struct RoomShapeImageSingle {
/* 0x00 */ RoomShapeImageBase base;
/* 0x08 */ void* source;
/* 0x0C */ u32 unk_0C;
/* 0x10 */ void* tlut;
/* 0x14 */ u16 width;
/* 0x16 */ u16 height;
/* 0x18 */ u8 fmt;
/* 0x19 */ u8 siz;
/* 0x1A */ u16 tlutMode;
/* 0x1C */ u16 tlutCount;
} RoomShapeImageSingle; // size = 0x20
typedef struct RoomShapeImageMultiBgEntry {
/* 0x00 */ u16 unk_00;
/* 0x02 */ u8 bgCamIndex; // for which bg cam index is this entry for
/* 0x04 */ void* source;
/* 0x08 */ u32 unk_0C;
/* 0x0C */ void* tlut;
/* 0x10 */ u16 width;
/* 0x12 */ u16 height;
/* 0x14 */ u8 fmt;
/* 0x15 */ u8 siz;
/* 0x16 */ u16 tlutMode;
/* 0x18 */ u16 tlutCount;
} RoomShapeImageMultiBgEntry; // size = 0x1C
typedef struct RoomShapeImageMulti {
/* 0x00 */ RoomShapeImageBase base;
/* 0x08 */ u8 numBackgrounds;
/* 0x0C */ RoomShapeImageMultiBgEntry* backgrounds;
} RoomShapeImageMulti; // size = 0x10
typedef struct RoomShapeCullableEntry {
/* 0x00 */ Vec3s boundsSphereCenter;
/* 0x06 */ s16 boundsSphereRadius;
/* 0x08 */ Gfx* opa;
/* 0x0C */ Gfx* xlu;
} RoomShapeCullableEntry; // size = 0x10
#define ROOM_SHAPE_CULLABLE_MAX_ENTRIES 64
typedef struct RoomShapeCullable {
/* 0x00 */ RoomShapeBase base;
/* 0x01 */ u8 numEntries;
/* 0x04 */ RoomShapeCullableEntry* entries;
/* 0x08 */ RoomShapeCullableEntry* entriesEnd;
} RoomShapeCullable; // size = 0x0C
typedef union RoomShape {
RoomShapeBase base;
RoomShapeNormal normal;
union {
RoomShapeImageBase base;
RoomShapeImageSingle single;
RoomShapeImageMulti multi;
} image;
RoomShapeCullable cullable;
} RoomShape; // "Ground Shape"
typedef enum RoomType {
/* 0 */ ROOM_TYPE_NORMAL,
/* 1 */ ROOM_TYPE_DUNGEON, // Blocks Sun's Song's time advance effect. Not exclusively used by typical dungeon rooms.
/* 2 */ ROOM_TYPE_INDOORS, // Reduces player run speed and blocks player from attacking or jumping.
/* 3 */ ROOM_TYPE_3, // Unused. Color dithering is turned off when drawing the room and other things.
/* 4 */ ROOM_TYPE_4, // Unused. Prevents switching to CAM_SET_HORSE when mounting a horse.
/* 5 */ ROOM_TYPE_BOSS // Disables Environment_AdjustLights
} RoomType;
typedef enum RoomEnvironmentType {
/* 0 */ ROOM_ENV_DEFAULT,
/* 1 */ ROOM_ENV_COLD,
/* 2 */ ROOM_ENV_WARM,
/* 3 */ ROOM_ENV_HOT, // Enables hot room timer for the current room
/* 4 */ ROOM_ENV_UNK_STRETCH_1,
/* 5 */ ROOM_ENV_UNK_STRETCH_2,
/* 6 */ ROOM_ENV_UNK_STRETCH_3
} RoomEnvironmentType;
typedef struct Room {
/* 0x00 */ s8 num; // -1 is invalid room
/* 0x01 */ u8 unk_01;
/* 0x02 */ u8 environmentType;
/* 0x03 */ u8 type;
/* 0x04 */ s8 echo;
/* 0x05 */ u8 lensMode;
/* 0x08 */ RoomShape* roomShape; // original name: "ground_shape"
/* 0x0C */ void* segment;
/* 0x10 */ char unk_10[0x4];
} Room; // size = 0x14
typedef struct RoomContext {
/* 0x00 */ Room curRoom;
/* 0x14 */ Room prevRoom;
/* 0x28 */ void* bufPtrs[2]; // Start and end pointers for the room buffer. Can be split into two pages, where page 0 is allocated from the start pointer and page 1 is allocated from the end pointer.
/* 0x30 */ u8 activeBufPage; // 0 - First page in memory, 1 - Last page in memory
/* 0x31 */ s8 status; // 0 - Free for new room request, 1 - DmaRequest for a new room is in progress
/* 0x34 */ void* roomRequestAddr; // Pointer to where the requested room segment will be stored
/* 0x38 */ DmaRequest dmaRequest;
/* 0x58 */ OSMesgQueue loadQueue;
/* 0x70 */ OSMesg loadMsg;
/* 0x74 */ s16 drawParams[2]; // context-specific data used by the current scene draw config
} RoomContext; // size = 0x78
typedef struct RoomList {
/* 0x00 */ u8 count;
/* 0x04 */ RomFile* romFiles; // Array of rom addresses for each room in a scene
} RoomList;
#define ROOM_DRAW_OPA (1 << 0)
#define ROOM_DRAW_XLU (1 << 1)
// Scene commands
typedef struct SCmdBase {
@@ -269,7 +121,7 @@ typedef struct SCmdRoomBehavior {
typedef struct SCmdMesh {
/* 0x00 */ u8 code;
/* 0x01 */ u8 data1;
/* 0x04 */ RoomShapeBase* data;
/* 0x04 */ struct RoomShapeBase* data;
} SCmdMesh;
typedef struct SCmdObjectList {

Some files were not shown because too many files have changed in this diff Show More