summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-08-12 11:44:35 -0400
committerGitHub <noreply@github.com>2023-08-12 11:44:35 -0400
commit656fd08ee828024f5a0e888f293ca95b7a83cd64 (patch)
tree394a0e9870c1eb946187ef388b23596fcccde1c1 /include
parent138dd55662181b7de82f003c6b46ba3d0611b258 (diff)
Gamestate table (#1354)
* gamestate_table.h * move macros * bss * format
Diffstat (limited to 'include')
-rw-r--r--include/macros.h10
-rw-r--r--include/segment_symbols.h5
-rw-r--r--include/tables/gamestate_table.h17
-rw-r--r--include/variables.h3
-rw-r--r--include/z64game.h21
5 files changed, 38 insertions, 18 deletions
diff --git a/include/macros.h b/include/macros.h
index f28315815..b03d01b3e 100644
--- a/include/macros.h
+++ b/include/macros.h
@@ -53,21 +53,11 @@
// To be used with `Magic_Add`, but ensures enough magic is added to fill the magic bar to capacity
#define MAGIC_FILL_TO_CAPACITY (((void)0, gSaveContext.magicFillTarget) + (gSaveContext.save.saveInfo.playerData.isDoubleMagicAcquired + 1) * MAGIC_NORMAL_METER)
-#define CONTROLLER1(gameState) (&(gameState)->input[0])
-#define CONTROLLER2(gameState) (&(gameState)->input[1])
-#define CONTROLLER3(gameState) (&(gameState)->input[2])
-#define CONTROLLER4(gameState) (&(gameState)->input[3])
-
#define CHECK_BTN_ALL(state, combo) (~((state) | ~(combo)) == 0)
#define CHECK_BTN_ANY(state, combo) (((state) & (combo)) != 0)
#define CHECK_FLAG_ALL(flags, mask) (((flags) & (mask)) == (mask))
-#define ALIGN8(val) (((val) + 7) & ~7)
-#define ALIGN16(val) (((val) + 0xF) & ~0xF)
-#define ALIGN64(val) (((val) + 0x3F) & ~0x3F)
-#define ALIGN256(val) (((val) + 0xFF) & ~0xFF)
-
#define BIT_FLAG_TO_SHIFT(flag) \
((flag & 0x80) ? 7 : \
(flag & 0x40) ? 6 : \
diff --git a/include/segment_symbols.h b/include/segment_symbols.h
index 214970933..6bf163379 100644
--- a/include/segment_symbols.h
+++ b/include/segment_symbols.h
@@ -71,11 +71,6 @@ DECLARE_SEGMENT(code)
DECLARE_ROM_SEGMENT(code)
DECLARE_BSS_SEGMENT(code)
-DECLARE_OVERLAY_SEGMENT(title)
-DECLARE_OVERLAY_SEGMENT(select)
-DECLARE_OVERLAY_SEGMENT(opening)
-DECLARE_OVERLAY_SEGMENT(file_choose)
-DECLARE_OVERLAY_SEGMENT(daytelop)
DECLARE_OVERLAY_SEGMENT(kaleido_scope)
DECLARE_OVERLAY_SEGMENT(player_actor)
diff --git a/include/tables/gamestate_table.h b/include/tables/gamestate_table.h
new file mode 100644
index 000000000..958e2fa4a
--- /dev/null
+++ b/include/tables/gamestate_table.h
@@ -0,0 +1,17 @@
+/**
+ * Gamestate Table
+ *
+ * DEFINE_GAMESTATE should be used for gamestates with code loaded from an overlay
+ * - Argument 0: Gamestate type name (without State suffix, also used for Init and Destroy function names)
+ * - Argument 1: Gamestate id enum name
+ * - Argument 2: Gamestate overlay segment name without the `ovl_` prefix
+ *
+ * DEFINE_GAMESTATE_INTERNAL should be used for gamestates that aren't an overlay, the first two arguments are the same as for DEFINE_GAMESTATE
+ */
+/* 0x00 */ DEFINE_GAMESTATE_INTERNAL(Setup, GAMESTATE_SETUP)
+/* 0x01 */ DEFINE_GAMESTATE(MapSelect, GAMESTATE_MAP_SELECT, select)
+/* 0x02 */ DEFINE_GAMESTATE(ConsoleLogo, GAMESTATE_CONSOLE_LOGO, title)
+/* 0x03 */ DEFINE_GAMESTATE_INTERNAL(Play, GAMESTATE_PLAY)
+/* 0x04 */ DEFINE_GAMESTATE(TitleSetup, GAMESTATE_TITLE_SETUP, opening)
+/* 0x05 */ DEFINE_GAMESTATE(FileSelect, GAMESTATE_FILE_SELECT, file_choose)
+/* 0x06 */ DEFINE_GAMESTATE(DayTelop, GAMESTATE_DAYTELOP, daytelop)
diff --git a/include/variables.h b/include/variables.h
index 0afe12864..e1fa8b491 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -226,9 +226,6 @@ extern ActorId gMaxActorId;
extern BgCheckSceneSubdivisionEntry sSceneSubdivisionList[];
extern BgSpecialSceneMaxObjects sCustomDynapolyMem[];
-extern GameStateOverlay gGameStateOverlayTable[];
-extern s32 gGraphNumGameStates;
-
// extern UNK_TYPE4 D_801BDAC0;
// extern UNK_TYPE4 D_801BDAC4;
// extern UNK_TYPE4 D_801BDAC8;
diff --git a/include/z64game.h b/include/z64game.h
index 87dc80764..87dffe5c3 100644
--- a/include/z64game.h
+++ b/include/z64game.h
@@ -12,6 +12,18 @@ struct GraphicsContext;
struct GameState;
+#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) enumName,
+#define DEFINE_GAMESTATE(typeName, enumName, name) DEFINE_GAMESTATE_INTERNAL(typeName, enumName)
+
+typedef enum GameStateId {
+#include "tables/gamestate_table.h"
+ /* 0x07 */ GAMESTATE_ID_MAX
+} GameStateId;
+
+#undef DEFINE_GAMESTATE
+#undef DEFINE_GAMESTATE_INTERNAL
+
+
typedef void (*GameStateFunc)(struct GameState* gameState);
typedef struct {
@@ -85,6 +97,15 @@ extern f32 gFramerateDivisorHalf;
extern f32 gFramerateDivisorThird;
+extern GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX];
+extern GameStateId gGraphNumGameStates;
+
+
+#define CONTROLLER1(gameState) (&(gameState)->input[0])
+#define CONTROLLER2(gameState) (&(gameState)->input[1])
+#define CONTROLLER3(gameState) (&(gameState)->input[2])
+#define CONTROLLER4(gameState) (&(gameState)->input[3])
+
#define STOP_GAMESTATE(curState) \
do { \
GameState* state = curState; \