summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-08-09 20:51:25 -0400
committerGitHub <noreply@github.com>2023-08-09 20:51:25 -0400
commitc7729c05c07cf0d60a70cd6c4f456069604a1f43 (patch)
tree00b8cfc29935ffad5d4081fc9e65c21d3059f8e0
parentcfa703f013a1e595a418e47ac05df06e9ae4f9b8 (diff)
`game.c` OK (#37)
* C file * game_dt * game_ct * fix offsets and building * game_init_hyral and SetGameFrame * more funcs * game_main * game_get_controller and func_800D2E00_jp * Input * game_draw_last * a few attempts * game_draw_first * improve func_800D2E58_jp a bit * format * migrate data and bss * what * whoops * name bss * minor cleanup * match game.c Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * fix malloc function wrongly named * Update src/code/game.c Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * review --------- Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
-rw-r--r--.vscode/c_cpp_properties.json1
-rw-r--r--Makefile2
-rw-r--r--include/67E840.h8
-rw-r--r--include/69E2C0.h7
-rw-r--r--include/6E0F50.h2
-rw-r--r--include/6EDD10.h2
-rw-r--r--include/TwoHeadArena.h3
-rw-r--r--include/attributes.h12
-rw-r--r--include/code_variables.h18
-rw-r--r--include/debug.h3
-rw-r--r--include/game.h104
-rw-r--r--include/gfx.h39
-rw-r--r--include/gfxalloc.h4
-rw-r--r--include/graph.h6
-rw-r--r--include/m_controller.h6
-rw-r--r--include/padmgr.h5
-rw-r--r--include/speed_meter.h18
-rw-r--r--include/unknown_structs.h7
-rw-r--r--linker_scripts/jp/symbol_addrs_code.txt16
-rw-r--r--linker_scripts/jp/symbol_addrs_overlays.txt4
-rw-r--r--src/code/game.c329
-rw-r--r--src/code/sys_matrix.c1
-rw-r--r--src/overlays/gamestates/ovl_famicom_emu/famicom_emu.h15
-rw-r--r--src/overlays/gamestates/ovl_play/m_play.h15
-rwxr-xr-xtools/m2ctx.py1
-rw-r--r--tools/permuter_settings.toml12
-rw-r--r--yamls/jp/code.yaml11
27 files changed, 564 insertions, 87 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 3aa0c3c..d0aaafe 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -5,6 +5,7 @@
"includePath": [
"${workspaceFolder}/**",
"include",
+ "src",
".",
"lib/ultralib/include",
"lib/ultralib/include/PR"
diff --git a/Makefile b/Makefile
index c703b54..fe56337 100644
--- a/Makefile
+++ b/Makefile
@@ -106,7 +106,7 @@ SPLAT_YAML ?= $(TARGET).$(VERSION).yaml
-IINC := -Iinclude -Ibin/$(VERSION) -I.
+IINC := -Iinclude -Isrc -Ibin/$(VERSION) -I.
IINC += -Ilib/ultralib/include -Ilib/ultralib/include/PR
ifeq ($(KEEP_MDEBUG),0)
diff --git a/include/67E840.h b/include/67E840.h
index aa16414..cefd38d 100644
--- a/include/67E840.h
+++ b/include/67E840.h
@@ -3,6 +3,8 @@
#include "ultra64.h"
+struct GameState;
+
// void func_8005ABA0_jp();
// void func_8005ABE0_jp();
// void func_8005ACA8_jp();
@@ -176,10 +178,10 @@
// void func_8005EE00_jp();
// void func_8005EE20_jp();
// void func_8005EEA0_jp();
-// void mBGM_main();
+void mBGM_main(struct GameState* gameState);
// void mBGM_ct();
-// void func_8005F020_jp();
-// void func_8005F13C_jp();
+void func_8005F020_jp(void);
+void mBGM_cleanup(void);
// void func_8005F250_jp();
#endif
diff --git a/include/69E2C0.h b/include/69E2C0.h
index 313f773..f95158e 100644
--- a/include/69E2C0.h
+++ b/include/69E2C0.h
@@ -3,15 +3,18 @@
#include "ultra64.h"
+struct Input;
+struct GraphicsContext;
+
// void func_8007A620_jp();
// void func_8007A630_jp();
// void Debug_Print_output();
// void func_8007A74C_jp();
// void Debug_Print2_output();
-// void Debug_mode_input();
+void Debug_mode_input(struct Input *input);
// void Debug_mode_output_sub();
// void Debug_mode_zelda_malloc_info_output();
-// void Debug_mode_output();
+void Debug_mode_output(struct GraphicsContext* gfxCtx);
// void func_8007B410_jp();
// void func_8007B44C_jp();
// void func_8007B49C_jp();
diff --git a/include/6E0F50.h b/include/6E0F50.h
index f9b1c52..888d213 100644
--- a/include/6E0F50.h
+++ b/include/6E0F50.h
@@ -38,7 +38,7 @@
// void fade_black_draw();
// void func_800BE094_jp();
// void func_800BE0E4_jp();
-// void func_800BE12C_jp();
+Gfx *func_800BE12C_jp(Gfx *gfx, s32 arg1, s32 arg2, s32 arg3, s32 arg4);
// void func_800BE184_jp();
// void func_800BE1D4_jp();
// void func_800BE27C_jp();
diff --git a/include/6EDD10.h b/include/6EDD10.h
index 1aa2f79..087c3af 100644
--- a/include/6EDD10.h
+++ b/include/6EDD10.h
@@ -13,6 +13,6 @@
// void func_800CA2DC_jp();
// void func_800CA350_jp();
// void func_800CA570_jp();
-// void mTM_time();
+void mTM_time(void);
#endif
diff --git a/include/TwoHeadArena.h b/include/TwoHeadArena.h
index d5d0e0e..e5b62e2 100644
--- a/include/TwoHeadArena.h
+++ b/include/TwoHeadArena.h
@@ -2,8 +2,9 @@
#define TWO_HEAD_ARENA_H
#include "ultra64.h"
+#include "libc/stdint.h"
-typedef struct {
+typedef struct TwoHeadArena {
/* 0x00 */ size_t size;
/* 0x04 */ void* start;
/* 0x08 */ void* head;
diff --git a/include/attributes.h b/include/attributes.h
index c2045fa..69ce0b9 100644
--- a/include/attributes.h
+++ b/include/attributes.h
@@ -10,7 +10,9 @@
#ifndef FALLTHROUGH
- #if __STDC_VERSION__ >= 202000L
+ #ifdef PERMUTER
+ #define FALLTHROUGH
+ #elif __STDC_VERSION__ >= 202000L
#define FALLTHROUGH [[fallthrough]]
#else
#define FALLTHROUGH __attribute__((fallthrough))
@@ -18,7 +20,9 @@
#endif
#ifndef NORETURN
- #if __STDC_VERSION__ >= 202000L
+ #ifdef PERMUTER
+ #define NORETURN
+ #elif __STDC_VERSION__ >= 202000L
#define NORETURN [[noreturn]]
#elif __STDC_VERSION__ >= 201112L
#define NORETURN _Noreturn
@@ -28,7 +32,9 @@
#endif
#ifndef UNUSED
- #if __STDC_VERSION__ >= 202000L
+ #ifdef PERMUTER
+ #define UNUSED
+ #elif __STDC_VERSION__ >= 202000L
#define UNUSED [[maybe_unused]]
#else
#define UNUSED __attribute__((unused))
diff --git a/include/code_variables.h b/include/code_variables.h
index 111a6a6..6ed39f3 100644
--- a/include/code_variables.h
+++ b/include/code_variables.h
@@ -810,7 +810,7 @@
// extern UNK_TYPE D_8010EF60_jp;
// extern UNK_TYPE D_8010EF70_jp;
// extern UNK_TYPE D_8010EF80_jp;
-// extern UNK_TYPE gamePT;
+
// extern UNK_TYPE D_8010EFA0_jp;
extern vs32 D_8010EFB0_jp; // TODO: Determine where this goes
// extern UNK_TYPE D_8010EFB8_jp;
@@ -842,7 +842,7 @@ extern vs32 D_8010EFB0_jp; // TODO: Determine where this goes
// extern UNK_TYPE D_8010FD54_jp;
// extern UNK_TYPE D_8010FD58_jp;
// extern UNK_TYPE D_8010FD5C_jp;
-// extern UNK_TYPE D_8010FD60_jp;
+extern s32 zurumode_flag;
// extern UNK_TYPE D_8010FD70_jp;
// extern UNK_TYPE D_80110000_jp;
// extern UNK_TYPE D_80110D70_jp;
@@ -1512,9 +1512,7 @@ extern vs32 D_8010EFB0_jp; // TODO: Determine where this goes
// extern UNK_TYPE RO_STR_80117C80_jp;
// extern UNK_TYPE RO_STR_80117CA0_jp;
// extern UNK_TYPE RO_STR_80117CC0_jp;
-// extern UNK_TYPE RO_80117CE0_jp;
-// extern UNK_TYPE RO_STR_80117D00_jp;
-// extern UNK_TYPE RO_STR_80117D0C_jp;
+
// extern UNK_TYPE RO_STR_80117D20_jp;
// extern UNK_TYPE RO_STR_80117D3C_jp;
// extern UNK_TYPE RO_STR_80117D50_jp;
@@ -1848,7 +1846,7 @@ extern vs32 D_8010EFB0_jp; // TODO: Determine where this goes
// extern UNK_TYPE B_80138818_jp;
// extern UNK_TYPE B_80138E40_jp;
// extern UNK_TYPE B_80138E44_jp;
-// extern UNK_TYPE B_80138E50_jp;
+extern struct_debug_mode *debug_mode;
// extern UNK_TYPE debug_display;
// extern UNK_TYPE B_80138E70_jp;
// extern UNK_TYPE B_80138E73_jp;
@@ -2006,13 +2004,7 @@ extern vs32 D_8010EFB0_jp; // TODO: Determine where this goes
// extern UNK_TYPE B_80144FB8_jp;
// extern UNK_TYPE B_80144FC0_jp;
// extern UNK_TYPE B_80145014_jp;
-// extern UNK_TYPE B_80145020_jp;
-// extern UNK_TYPE B_80145040_jp;
-// extern UNK_TYPE B_80145044_jp;
-// extern UNK_TYPE B_80145048_jp;
-// extern UNK_TYPE B_FLT_8014504C_jp;
-// extern UNK_TYPE B_FLT_80145050_jp;
-// extern UNK_TYPE B_FLT_80145054_jp;
+
// extern UNK_TYPE B_80145060_jp;
// extern UNK_TYPE B_80145070_jp;
// extern UNK_TYPE B_80145080_jp;
diff --git a/include/debug.h b/include/debug.h
index 81e2cf9..6769129 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -2,8 +2,9 @@
#define DEBUG_H
#include "ultra64.h"
+#include "attributes.h"
-// void _dbg_hungup();
+void _dbg_hungup(const char *filename, int line) NORETURN;
// void Reset();
#endif
diff --git a/include/game.h b/include/game.h
index 49eca3f..3795c9c 100644
--- a/include/game.h
+++ b/include/game.h
@@ -2,31 +2,87 @@
#define GAME_H
#include "ultra64.h"
-#include "gfx.h"
+#include "TwoHeadArena.h"
+#include "gamealloc.h"
+#include "padutils.h"
+#include "unk.h"
+
+struct GameState;
+struct GraphicsContext;
+struct struct_80145020_jp;
+
+
+typedef void (*GameStateFunc)(struct GameState* gameState);
typedef struct GameState {
- /* 0x00 */ GraphicsContext* gfxCtx;
- /* 0x04 */ char pad[0x74];
- /* 0x74 */ TwoHeadArena heap;
-} GameState; // size = ??
-
-// void func_800D2E00_jp();
-// void func_800D2E58_jp();
-// void game_debug_draw_last();
-// void game_draw_first();
-// void game_draw_last();
-// void game_get_controller();
-// void SetGameFrame();
-// void game_main();
-// void game_init_hyral();
-// void game_resize_hyral();
-// void game_ct();
-// void game_dt();
-// void game_get_next_game_init();
-// void game_get_next_game_class_size();
-// void game_is_doing();
-// void game_getFreeBytes();
-// void game_goto_next_game_play();
-// void game_goto_next_game_name_famicom_emu();
+ /* 0x00 */ struct GraphicsContext* gfxCtx;
+ /* 0x04 */ GameStateFunc main;
+ /* 0x08 */ GameStateFunc destroy;
+ /* 0x0C */ GameStateFunc init;
+ /* 0x10 */ size_t size;
+ /* 0x14 */ Input input[MAXCONTROLLERS];
+ /* 0x74 */ s32 unk_74;
+ /* 0x78 */ TwoHeadArena heap;
+ /* 0x88 */ GameAlloc alloc;
+ /* 0x9C */ UNK_TYPE1 unk_9C[0x3];
+ /* 0x9F */ u8 running;
+ /* 0xA0 */ s32 unk_A0;
+} GameState; // size >= 0xA4, size <= 0xE0
+
+void func_800D2E00_jp(GameState* gameState);
+void func_800D2E58_jp(u16 button, Gfx** gfxP);
+void game_debug_draw_last(GameState* gameState, struct GraphicsContext* gfxCtx);
+void game_draw_first(struct GraphicsContext* gfxCtx);
+void game_draw_last(struct GraphicsContext* gfxCtx);
+void game_get_controller(GameState* gameState);
+void SetGameFrame(s32 divisor);
+void game_main(GameState* gameState);
+void game_init_hyral(GameState* gameState, size_t size);
+void game_resize_hyral(GameState* gameState, size_t size);
+void game_ct(GameState* gameState, GameStateFunc init, struct GraphicsContext* gfxCtx);
+void game_dt(GameState* gameState);
+GameStateFunc game_get_next_game_init(GameState* gameState);
+size_t game_get_next_game_class_size(GameState* gameState);
+s32 game_is_doing(GameState* gameState);
+s32 game_getFreeBytes(GameState* gameState);
+void game_goto_next_game_play(GameState* gameState);
+void game_goto_next_game_name_famicom_emu(GameState* gameState);
+
+
+// .data
+
+extern GameState* gamePT;
+
+// .bss
+
+extern struct struct_80145020_jp B_80145020_jp;
+extern s16 B_80145040_jp;
+extern GameState* game_class_p;
+extern u8 game_GameFrame;
+extern f32 game_GameFrameF;
+extern f32 game_GameFrame_2F;
+extern f32 game_GameFrame__1F;
+
+
+#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; \
+ \
+ state->running = false; \
+ } while(0)
+
+#define SET_NEXT_GAMESTATE(curState, nextInit, nextSize) \
+ do { \
+ GameState* state = curState; \
+ \
+ (state)->init = nextInit; \
+ (state)->size = nextSize; \
+ } while (0)
+
#endif
diff --git a/include/gfx.h b/include/gfx.h
index 8d46a1a..3d693fe 100644
--- a/include/gfx.h
+++ b/include/gfx.h
@@ -2,28 +2,51 @@
#define GFX_H
#include "ultra64.h"
+#include "attributes.h"
+#include "alignment.h"
#include "THA_GA.h"
+#include "unk.h"
#define GRAPH_ALLOC(gfxCtx, size) ((void*)((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - ALIGN16(size))))
typedef struct GraphicsContext {
- /* 0x000 */ char pad[0x290];
- /* 0x298 */ TwoHeadGfxArena polyOpa;
- /* 0x2A8 */ TwoHeadGfxArena polyXlu;
-} GraphicsContext; // size = ??
+ /* 0x000 */ UNK_TYPE1 unk_000[0x8];
+ /* 0x008 */ UNK_PTR unk_008;
+ /* 0x00C */ UNK_TYPE1 unk_00C[0x250];
+ /* 0x25C */ OSViMode* unk_25C;
+ /* 0x260 */ UNK_TYPE1 unk_260[0x20];
+ /* 0x280 */ TwoHeadGfxArena overlay;
+ /* 0x290 */ TwoHeadGfxArena polyOpa;
+ /* 0x2A0 */ TwoHeadGfxArena polyXlu;
+ /* 0x2B0 */ TwoHeadGfxArena unk_2B0;
+ /* 0x2C0 */ TwoHeadGfxArena unk_2C0;
+ /* 0x2D0 */ TwoHeadGfxArena unk_2D0;
+ /* 0x2E0 */ UNK_TYPE1 unk_2E0[0x4];
+ /* 0x2E4 */ s32 unk_2E4;
+ /* 0x2E8 */ UNK_TYPE1 unk_2E8[0x4];
+ /* 0x2EC */ s32 unk_2EC;
+ /* 0x2F0 */ u8 unk_2F0;
+ /* 0x2F1 */ UNK_TYPE1 unk_2F1[0x1];
+ /* 0x2F2 */ u8 unk_2F2;
+ /* 0x2F3 */ UNK_TYPE1 unk_2F3[0x1];
+ /* 0x2F4 */ UNK_TYPE1 unk_2F4[0x8];
+ /* 0x2FC */ f32 unk_2FC;
+ /* 0x300 */ f32 unk_300;
+} GraphicsContext; // size >= 0x304
-#define WORK_DISP __gfxCtx->work.p
+#define OVERLAY_DISP __gfxCtx->overlay.p
#define POLY_OPA_DISP __gfxCtx->polyOpa.p
#define POLY_XLU_DISP __gfxCtx->polyXlu.p
-#define OVERLAY_DISP __gfxCtx->overlay.p
-#define DEBUG_DISP __gfxCtx->debug.p
+#define UNK_2B0_DISP __gfxCtx->unk_2B0.p
+#define UNK_2C0_DISP __gfxCtx->unk_2C0.p
+#define UNK_2D0_DISP __gfxCtx->unk_2D0.p
// __gfxCtx shouldn't be used directly.
// Use the DISP macros defined above when writing to display buffers.
#define OPEN_DISPS(gfxCtx) \
{ \
GraphicsContext* __gfxCtx = gfxCtx; \
- s32 __dispPad
+ s32 __dispPad UNUSED
#define CLOSE_DISPS(gfxCtx) \
(void)0; \
diff --git a/include/gfxalloc.h b/include/gfxalloc.h
index 1b48ada..dab0fb6 100644
--- a/include/gfxalloc.h
+++ b/include/gfxalloc.h
@@ -3,8 +3,8 @@
#include "ultra64.h"
-// void gfxopen();
-// void gfxclose();
+Gfx* gfxopen(Gfx* gfxHead);
+void gfxclose(Gfx* gfxHead, Gfx* gfx);
// void gfxalloc();
#endif
diff --git a/include/graph.h b/include/graph.h
index 053f558..210aea4 100644
--- a/include/graph.h
+++ b/include/graph.h
@@ -3,14 +3,16 @@
#include "ultra64.h"
+struct GraphicsContext;
+
// void func_800D38E0_jp();
// void graph_setup_double_buffer();
// void game_get_next_game_dlftbl();
// void func_800D3C94_jp();
// void graph_ct();
// void graph_dt();
-// void func_800D3E14_jp();
-// void func_800D3E40_jp();
+void func_800D3E14_jp(struct GraphicsContext *gfxCtx);
+void func_800D3E40_jp(struct GraphicsContext *gfxCtx);
// void graph_task_set00();
// void graph_draw_finish();
// void graph_main();
diff --git a/include/m_controller.h b/include/m_controller.h
index 72bf692..7370fdc 100644
--- a/include/m_controller.h
+++ b/include/m_controller.h
@@ -3,8 +3,10 @@
#include "ultra64.h"
-// void mCon_ct();
-// void mCon_dt();
+struct GameState;
+
+void mCon_ct(struct GameState* gameState);
+void mCon_dt(struct GameState* gameState);
// void mCon_calc();
// void mCon_main();
// void chkButton();
diff --git a/include/padmgr.h b/include/padmgr.h
index 27f10d2..887188c 100644
--- a/include/padmgr.h
+++ b/include/padmgr.h
@@ -2,6 +2,7 @@
#define PADMGR_H
#include "ultra64.h"
+#include "padutils.h"
// void padmgr_LockSerialMesgQ();
// void padmgr_UnlockSerialMesgQ();
@@ -17,8 +18,8 @@
// void padmgr_HandleRetraceMsg();
// void padmgr_HandlePreNMIMsg();
// void padmgr_RequestPadData_NonLock();
-// void padmgr_RequestPadData();
-// void padmgr_ClearPadData();
+void padmgr_RequestPadData(Input inputs[4], s32 arg1);
+void padmgr_ClearPadData(Input inputs[4]);
// void padmgr_MainProc();
// void padmgr_Init();
// void func_800D763C_jp();
diff --git a/include/speed_meter.h b/include/speed_meter.h
index 16772bf..09b9dcc 100644
--- a/include/speed_meter.h
+++ b/include/speed_meter.h
@@ -2,15 +2,23 @@
#define SPEED_METER_H
#include "ultra64.h"
+#include "unk.h"
+
+struct GameState;
+struct GraphicsContext;
+
+typedef struct struct_80145020_jp {
+ /* 0x00 */ UNK_TYPE1 unk_00[0x20];
+} struct_80145020_jp; // size <= 0x20
// void func_800D88A0_jp();
-// void func_800D88B0_jp();
-// void func_800D88D4_jp();
-// void func_800D88E0_jp();
-// void func_800D8A54_jp();
+void func_800D88B0_jp(struct_80145020_jp *arg0);
+void func_800D88D4_jp(struct_80145020_jp *arg0);
+void func_800D88E0_jp(struct_80145020_jp *arg0);
+void func_800D8A54_jp(struct_80145020_jp *arg0, struct GraphicsContext* gfxCtx);
// void func_800D8DD4_jp();
// void func_800D8E18_jp();
-// void func_800D9018_jp();
+void func_800D9018_jp(struct_80145020_jp *arg0, struct GraphicsContext* gfxCtx, struct GameState *gameState);
// void func_800D93F4_jp();
#endif
diff --git a/include/unknown_structs.h b/include/unknown_structs.h
index a10218f..9564498 100644
--- a/include/unknown_structs.h
+++ b/include/unknown_structs.h
@@ -6,5 +6,12 @@
#include "libc/stdbool.h"
#include "unk.h"
+typedef struct struct_debug_mode {
+ /* 0x000 */ UNK_TYPE1 unk_000[0xD4];
+ /* 0x0D4 */ s16 unk_0D4;
+ /* 0x0D6 */ UNK_TYPE1 unk_0D6[0x2];
+ /* 0x0D8 */ UNK_TYPE1 unk_0D8[0x38];
+ /* 0x110 */ s16 gameframe;
+} struct_debug_mode; // size >= 0x114
#endif
diff --git a/linker_scripts/jp/symbol_addrs_code.txt b/linker_scripts/jp/symbol_addrs_code.txt
index 2a0dbb2..74fd08e 100644
--- a/linker_scripts/jp/symbol_addrs_code.txt
+++ b/linker_scripts/jp/symbol_addrs_code.txt
@@ -345,7 +345,7 @@ func_8005EEA0_jp = 0x8005EEA0; // type:func
mBGM_main = 0x8005EEE8; // type:func
mBGM_ct = 0x8005EF9C; // type:func
func_8005F020_jp = 0x8005F020; // type:func
-func_8005F13C_jp = 0x8005F13C; // type:func
+mBGM_cleanup = 0x8005F13C; // type:func
func_8005F250_jp = 0x8005F250; // type:func
func_8005F390_jp = 0x8005F390; // type:func
func_8005F3DC_jp = 0x8005F3DC; // type:func
@@ -5020,7 +5020,7 @@ D_8010FD50_jp = 0x8010FD50; //
D_8010FD54_jp = 0x8010FD54; //
D_8010FD58_jp = 0x8010FD58; //
D_8010FD5C_jp = 0x8010FD5C; //
-D_8010FD60_jp = 0x8010FD60; //
+zurumode_flag = 0x8010FD60; //
D_8010FD70_jp = 0x8010FD70; //
D_80110000_jp = 0x80110000; // type:s16
D_80110D70_jp = 0x80110D70; // type:s16
@@ -6033,7 +6033,7 @@ B_80137C48_jp = 0x80137C48; //
B_80138818_jp = 0x80138818; //
B_80138E40_jp = 0x80138E40; //
B_80138E44_jp = 0x80138E44; //
-B_80138E50_jp = 0x80138E50; //
+debug_mode = 0x80138E50; //
debug_display = 0x80138E60; //
B_80138E70_jp = 0x80138E70; // type:s8
B_80138E73_jp = 0x80138E73; //
@@ -6193,11 +6193,11 @@ B_80144FC0_jp = 0x80144FC0; // type:u8
B_80145014_jp = 0x80145014; //
B_80145020_jp = 0x80145020; //
B_80145040_jp = 0x80145040; // type:s16
-B_80145044_jp = 0x80145044; //
-B_80145048_jp = 0x80145048; // type:u8
-B_FLT_8014504C_jp = 0x8014504C; // type:f32
-B_FLT_80145050_jp = 0x80145050; // type:f32
-B_FLT_80145054_jp = 0x80145054; // type:f32
+game_class_p = 0x80145044; //
+game_GameFrame = 0x80145048; // type:u8
+game_GameFrameF = 0x8014504C; // type:f32
+game_GameFrame_2F = 0x80145050; // type:f32
+game_GameFrame__1F = 0x80145054; // type:f32
B_80145060_jp = 0x80145060; //
B_80145070_jp = 0x80145070; //
B_80145080_jp = 0x80145080; //
diff --git a/linker_scripts/jp/symbol_addrs_overlays.txt b/linker_scripts/jp/symbol_addrs_overlays.txt
index c3c1e6f..ec88207 100644
--- a/linker_scripts/jp/symbol_addrs_overlays.txt
+++ b/linker_scripts/jp/symbol_addrs_overlays.txt
@@ -198,7 +198,7 @@ func_808030D0_jp = 0x808030D0; // type:func
func_80803124_jp = 0x80803124; // type:func
func_80803174_jp = 0x80803174; // type:func
func_80803210_jp = 0x80803210; // type:func
-func_808032F8_jp = 0x808032F8; // type:func
+play_init = 0x808032F8; // type:func
func_80803544_jp = 0x80803544; // type:func
func_8080367C_jp = 0x8080367C; // type:func
func_80803810_jp = 0x80803810; // type:func
@@ -465,7 +465,7 @@ func_8082D4E0_jp = 0x8082D4E0; // type:func
func_8082D98C_jp = 0x8082D98C; // type:func
func_8082DA58_jp = 0x8082DA58; // type:func
func_8082DA64_jp = 0x8082DA64; // type:func
-func_8082DF6C_jp = 0x8082DF6C; // type:func
+famicom_emu_init = 0x8082DF6C; // type:func
func_8082E470_jp = 0x8082E470; // type:func
func_8082E4E0_jp = 0x8082E4E0; // type:func
func_8082E590_jp = 0x8082E590; // type:func
diff --git a/src/code/game.c b/src/code/game.c
new file mode 100644
index 0000000..706b5c9
--- /dev/null
+++ b/src/code/game.c
@@ -0,0 +1,329 @@
+#include "game.h"
+#include "gfx.h"
+#include "m_controller.h"
+#include "67E840.h"
+#include "speed_meter.h"
+#include "graph.h"
+#include "debug.h"
+#include "libc64/malloc.h"
+#include "6EDD10.h"
+#include "padmgr.h"
+#include "69E2C0.h"
+#include "gfxalloc.h"
+#include "6E0F50.h"
+#include "code_variables.h"
+#include "overlays/gamestates/ovl_play/m_play.h"
+#include "overlays/gamestates/ovl_famicom_emu/famicom_emu.h"
+#include "macros.h"
+
+GameState* gamePT = NULL;
+
+struct_80145020_jp B_80145020_jp;
+s16 B_80145040_jp;
+GameState* game_class_p;
+u8 game_GameFrame;
+f32 game_GameFrameF;
+f32 game_GameFrame_2F;
+f32 game_GameFrame__1F;
+
+void func_800D2E00_jp(GameState* gameState) {
+ if (zurumode_flag >= 2) {
+ Debug_mode_input(CONTROLLER2(gameState));
+ }
+
+ if (debug_mode->unk_0D4 != 0) {
+ func_800D88E0_jp(&B_80145020_jp);
+ }
+}
+
+const u16 RO_80117CE0_jp[0x10] = {
+ GPACK_RGBA5551(255, 255, 0, 1), // R_CBUTTONS
+ GPACK_RGBA5551(255, 255, 0, 1), // L_CBUTTONS
+ GPACK_RGBA5551(255, 255, 0, 1), // D_CBUTTONS
+ GPACK_RGBA5551(255, 255, 0, 1), // U_CBUTTONS
+ GPACK_RGBA5551(127, 127, 127, 1), // R_TRIG
+ GPACK_RGBA5551(127, 127, 127, 1), // L_TRIG
+ GPACK_RGBA5551(0, 255, 255, 1), //
+ GPACK_RGBA5551(255, 0, 255, 1), //
+ GPACK_RGBA5551(127, 127, 127, 1), // R_JPAD
+ GPACK_RGBA5551(127, 127, 127, 1), // L_JPAD
+ GPACK_RGBA5551(127, 127, 127, 1), // D_JPAD
+ GPACK_RGBA5551(127, 127, 127, 1), // U_JPAD
+ GPACK_RGBA5551(255, 0, 0, 1), // START_BUTTON
+ GPACK_RGBA5551(127, 127, 127, 1), // Z_TRIG
+ GPACK_RGBA5551(0, 255, 0, 1), // B_BUTTON
+ GPACK_RGBA5551(0, 0, 255, 1), // A_BUTTON
+};
+
+void func_800D2E58_jp(u16 button, Gfx** gfxP) {
+ Gfx* gfx;
+ u32 i;
+ u32 j;
+
+ gfx = *gfxP;
+
+ gDPPipeSync(gfx++);
+ gDPSetOtherMode(gfx++,
+ G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
+ G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE,
+ G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
+
+ for (i = 0; i < ARRAY_COUNT(RO_80117CE0_jp); i++) {
+ if (button & (1 << i)) {
+ j = i + 1;
+ gDPSetFillColor(gfx++, (RO_80117CE0_jp[i] << 0x10) | RO_80117CE0_jp[i]);
+ gfx = func_800BE12C_jp(gfx, (i * 4) + 226, 220, (j * 4) + 226, 224);
+
+ gDPPipeSync(gfx++);
+ }
+ }
+
+ *gfxP = gfx;
+}
+
+void game_debug_draw_last(GameState* gameState, GraphicsContext* gfxCtx) {
+ Gfx* gfx;
+ Gfx* gfxHead;
+
+ if (zurumode_flag != 0) {
+ OPEN_DISPS(gfxCtx);
+
+ {
+ UNUSED s32 requiredScopeTemp;
+
+ gfxHead = POLY_OPA_DISP;
+ gfx = gfxopen(gfxHead);
+
+ gSPDisplayList(OVERLAY_DISP++, gfx);
+ }
+
+ B_80145040_jp = CONTROLLER1(gameState)->press.button | CONTROLLER1(gameState)->cur.button;
+
+ func_800D2E58_jp(B_80145040_jp, &gfx);
+
+ gSPEndDisplayList(gfx++);
+
+ gfxclose(gfxHead, gfx);
+ POLY_OPA_DISP = gfx;
+
+ CLOSE_DISPS(gfxCtx);
+ }
+
+ if (zurumode_flag != 0) {
+ Debug_mode_output(gfxCtx);
+ }
+
+ if (debug_mode->unk_0D4 != 0) {
+ func_800D8A54_jp(&B_80145020_jp, gfxCtx);
+ func_800D9018_jp(&B_80145020_jp, gfxCtx, gameState);
+ }
+}
+
+void game_draw_first(GraphicsContext* gfxCtx) {
+ void* temp_v0 = gfxCtx->unk_008;
+
+ OPEN_DISPS(gfxCtx);
+
+ gSPSegment(POLY_OPA_DISP++, 0x00, NULL);
+ gSPSegment(POLY_OPA_DISP++, 0x0F, gfxCtx->unk_2E4);
+ gSPSegment(POLY_OPA_DISP++, 0x0E, temp_v0);
+
+ gSPSegment(POLY_XLU_DISP++, 0x00, NULL);
+ gSPSegment(POLY_XLU_DISP++, 0x0F, gfxCtx->unk_2E4);
+ gSPSegment(POLY_XLU_DISP++, 0x0E, temp_v0);
+
+ gSPSegment(OVERLAY_DISP++, 0x00, NULL);
+ gSPSegment(OVERLAY_DISP++, 0x0F, gfxCtx->unk_2E4);
+ gSPSegment(OVERLAY_DISP++, 0x0E, temp_v0);
+
+ gSPSegment(UNK_2B0_DISP++, 0x00, NULL);
+ gSPSegment(UNK_2B0_DISP++, 0x0F, gfxCtx->unk_2E4);
+ gSPSegment(UNK_2B0_DISP++, 0x0E, temp_v0);
+
+ gSPSegment(UNK_2C0_DISP++, 0x00, NULL);
+ gSPSegment(UNK_2C0_DISP++, 0x0F, gfxCtx->unk_2E4);
+ gSPSegment(UNK_2C0_DISP++, 0x0E, temp_v0);
+
+ gSPSegment(UNK_2D0_DISP++, 0x00, NULL);
+ gSPSegment(UNK_2D0_DISP++, 0x0F, gfxCtx->unk_2E4);
+ gSPSegment(UNK_2D0_DISP++, 0x0E, temp_v0);
+
+ CLOSE_DISPS(gfxCtx);
+}
+
+void game_draw_last(GraphicsContext* gfxCtx) {
+ Gfx* gfx;
+ Gfx* gfxHead;
+
+ OPEN_DISPS(gfxCtx);
+
+ gfx = gfxopen(gfxHead = POLY_OPA_DISP);
+
+ gSPDisplayList(OVERLAY_DISP++, gfx);
+ gSPEndDisplayList(gfx++);
+
+ gfxclose(gfxHead, gfx);
+ POLY_OPA_DISP = gfx;
+
+ CLOSE_DISPS(gfxCtx);
+}
+
+void game_get_controller(GameState* gameState) {
+ if (gameState->unk_74 == 1) {
+ padmgr_RequestPadData(gameState->input, 1);
+ } else {
+ padmgr_ClearPadData(gameState->input);
+ }
+}
+
+void SetGameFrame(s32 divisor) {
+ if (divisor != game_GameFrame) {
+ game_GameFrame = divisor;
+ game_GameFrameF = (divisor & 0xFF);
+ game_GameFrame_2F = game_GameFrameF / 2.0f;
+ game_GameFrame__1F = 1.0f / game_GameFrameF;
+ debug_mode->gameframe = divisor;
+ }
+}
+
+void game_main(GameState* gameState) {
+ GraphicsContext* gfxCtx = gameState->gfxCtx;
+ u8 gameframe = game_GameFrame;
+
+ if (debug_mode->gameframe != gameframe) {
+ SetGameFrame(debug_mode->gameframe);
+ }
+
+ game_draw_first(gfxCtx);
+ gfxCtx->unk_2F0 = 5;
+ mTM_time();
+ gfxCtx->unk_2F0 = 7;
+
+ gameState->main(gameState);
+
+ gfxCtx->unk_2F0 = 9;
+ mBGM_main(gameState);
+ gfxCtx->unk_2F0 = 0xA;
+ func_800D2E00_jp(gameState);
+
+ gameState->unk_A0++;
+}
+
+void game_init_hyral(GameState* gameState, size_t size) {
+ void* buf = gamealloc_malloc(&gameState->alloc, size);
+
+ if (buf != NULL) {
+ THA_ct(&gameState->heap, buf, size);
+ return;
+ }
+
+ THA_ct(&gameState->heap, NULL, 0);
+ _dbg_hungup("../game.c", 462);
+}
+
+void game_resize_hyral(GameState* gameState, size_t size) {
+ GameAlloc* alloc = &gameState->alloc;
+ void* gameArena;
+ size_t maxFree;
+ size_t bytesFree;
+ size_t bytesAllocated;
+ void* heapStart = gameState->heap.start;
+
+ THA_dt(&gameState->heap);
+
+ gamealloc_free(alloc, heapStart);
+
+ GetFreeArena(&maxFree, &bytesFree, &bytesAllocated);
+ if (size == 0x7D0000) {
+ size = maxFree - sizeof(GameAllocEntry);
+ } else {
+ size = (maxFree - sizeof(GameAllocEntry) < size) ? maxFree - sizeof(GameAllocEntry) : size;
+ }
+
+ gameArena = gamealloc_malloc(alloc, size);
+ if (gameArena != NULL) {
+ THA_ct(&gameState->heap, gameArena, size);
+ return;
+ }
+
+ THA_ct(&gameState->heap, NULL, 0);
+ _dbg_hungup("../game.c", 508);
+}
+
+void game_ct(GameState* gameState, GameStateFunc init, GraphicsContext* gfxCtx) {
+ gamePT = gameState;
+
+ gfxCtx->unk_2F2 = 1;
+ gfxCtx->unk_25C = &osViModeNtscLan1;
+ gfxCtx->unk_2EC = 0x42;
+ gfxCtx->unk_2FC = 1.0f;
+ gfxCtx->unk_300 = 1.0f;
+
+ mCon_ct(gameState);
+
+ gameState->unk_A0 = 0;
+ gameState->main = NULL;
+ gameState->destroy = NULL;
+ gameState->running = true;
+ gameState->unk_74 = 1;
+
+ {
+ s32 requiredScopeTemp UNUSED;
+
+ gameState->gfxCtx = gfxCtx;
+ gameState->init = NULL;
+ gameState->size = 0;
+ }
+
+ gamealloc_init(&gameState->alloc);
+
+ game_init_hyral(gameState, 0x100000); // 1 MiB
+ SetGameFrame(2);
+
+ init(gameState);
+
+ func_8005F020_jp();
+ func_800D88B0_jp(&B_80145020_jp);
+ func_800D3E14_jp(gameState->gfxCtx);
+}
+
+void game_dt(GameState* gameState) {
+ mCon_dt(gameState);
+ func_800D3E40_jp(gameState->gfxCtx);
+ mBGM_cleanup();
+
+ if (gameState->destroy != NULL) {
+ gameState->destroy(gameState);
+ }
+
+ func_800D88D4_jp(&B_80145020_jp);
+ THA_dt(&gameState->heap);
+ gamealloc_cleanup(&gameState->alloc);
+ gamePT = NULL;
+}
+
+GameStateFunc game_get_next_game_init(GameState* gameState) {
+ return gameState->init;
+}
+
+size_t game_get_next_game_class_size(GameState* gameState) {
+ return gameState->size;
+}
+
+s32 game_is_doing(GameState* gameState) {
+ return gameState->running;
+}
+
+s32 game_getFreeBytes(GameState* gameState) {
+ return THA_getFreeBytes(&gameState->heap);
+}
+
+void game_goto_next_game_play(GameState* gameState) {
+ STOP_GAMESTATE(gameState);
+ SET_NEXT_GAMESTATE(gameState, play_init, sizeof(PlayState));
+}
+
+void game_goto_next_game_name_famicom_emu(GameState* gameState) {
+ STOP_GAMESTATE(gameState);
+ SET_NEXT_GAMESTATE(gameState, famicom_emu_init, sizeof(FamicomEmuState));
+}
diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c
index c13ed58..b2af7fd 100644
--- a/src/code/sys_matrix.c
+++ b/src/code/sys_matrix.c
@@ -39,7 +39,6 @@
* (APPLY), or to just overwrite it (NEW).
*/
-#include "global.h"
#include "sys_matrix.h"
#include "game.h"
#include "z64math.h"
diff --git a/src/overlays/gamestates/ovl_famicom_emu/famicom_emu.h b/src/overlays/gamestates/ovl_famicom_emu/famicom_emu.h
new file mode 100644
index 0000000..a8c22d3
--- /dev/null
+++ b/src/overlays/gamestates/ovl_famicom_emu/famicom_emu.h
@@ -0,0 +1,15 @@
+#ifndef FAMICOM_EMU_H
+#define FAMICOM_EMU_H
+
+#include "ultra64.h"
+#include "game.h"
+#include "unk.h"
+
+typedef struct FamicomEmuState {
+ /* 0x00 */ GameState state;
+ /* 0xA4 */ UNK_TYPE1 unk_00[0x3C];
+} FamicomEmuState; // size = 0xE0
+
+void famicom_emu_init(GameState *thisx);
+
+#endif
diff --git a/src/overlays/gamestates/ovl_play/m_play.h b/src/overlays/gamestates/ovl_play/m_play.h
new file mode 100644
index 0000000..fb8872d
--- /dev/null
+++ b/src/overlays/gamestates/ovl_play/m_play.h
@@ -0,0 +1,15 @@
+#ifndef M_PLAY_H
+#define M_PLAY_H
+
+#include "ultra64.h"
+#include "game.h"
+#include "unk.h"
+
+typedef struct PlayState {
+ /* 0x00 */ GameState state;
+ /* 0xA4 */ UNK_TYPE1 unk_00[0x236C];
+} PlayState; // size = 0x2410
+
+void play_init(GameState *thisx);
+
+#endif
diff --git a/tools/m2ctx.py b/tools/m2ctx.py
index 60cae1a..e21bf5a 100755
--- a/tools/m2ctx.py
+++ b/tools/m2ctx.py
@@ -13,6 +13,7 @@ root_dir = os.path.abspath(os.path.join(script_dir, ".."))
CPP_FLAGS = [
"-I.",
"-Iinclude",
+ "-Isrc",
"-Ibin",
"-Ilib/ultralib/include",
"-Ilib/ultralib/include/PR",
diff --git a/tools/permuter_settings.toml b/tools/permuter_settings.toml
index b08f38f..f91c9cb 100644
--- a/tools/permuter_settings.toml
+++ b/tools/permuter_settings.toml
@@ -6,4 +6,16 @@ NULL = "int"
"gs[DS]P.*" = "void"
"gDma.*" = "void"
"G_IM_SIZ_.*" = "int"
+"G_IM_FMT_.*" = "int"
+"G_TX_.*" = "int"
"G_[AC]C.*" = "int"
+OPEN_DISPS = "void"
+CLOSE_DISPS = "void"
+
+[decompme.compilers]
+"tools/ido/linux/7.1/cc" = "ido7.1"
+"tools/ido/macos/7.1/cc" = "ido7.1"
+"tools/ido/windows/7.1/cc" = "ido7.1"
+"tools/ido/linux/5.3/cc" = "ido5.3"
+"tools/ido/macos/5.3/cc" = "ido5.3"
+"tools/ido/windows/5.3/cc" = "ido5.3"
diff --git a/yamls/jp/code.yaml b/yamls/jp/code.yaml
index 30d1e17..ab60c9d 100644
--- a/yamls/jp/code.yaml
+++ b/yamls/jp/code.yaml
@@ -83,7 +83,7 @@
- [0x6F5550, asm, code/6F5550]
- [0x6F6230, asm, code/audioMgr]
- [0x6F68B0, asm, code/cfbinfo]
- - [0x6F6AA0, asm, code/game]
+ - [0x6F6AA0, c, code/game]
- [0x6F73C0, c, code/gamealloc]
- [0x6F7500, asm, code/gfxalloc]
- [0x6F7580, asm, code/graph]
@@ -134,13 +134,14 @@
- [0x726260, data, code/m_actor_shadow]
- [0x72B7A0, data, code/m_lib]
- [0x72B7D0, data, code/72B7D0]
+ - [0x732C30, .data, code/game]
+ - [0x732C40, data, code/732C40]
- [0x732C50, .data, code/irqmgr]
- [0x732C70, data, code/732C70]
- [0x733970, .data, code/sys_matrix]
- [0x7339F0, data, code/sys_ucode]
- [0x733A00, data, code/m_nmi_buff]
- [0x733A10, data, code/733A10]
-
- [0x739DB0, .rodata, code/c_keyframe]
- [0x739E00, rodata, code/739E00]
@@ -202,7 +203,7 @@
- [0x73B890, rodata, code/73B890]
- [0x73B920, rodata, code/73B920]
- [0x73B960, rodata, code/73B960]
- - [0x73B980, rodata, code/73B980]
+ - [0x73B980, .rodata, code/game]
- [0x73B9C0, rodata, code/73B9C0]
- [0x73BA50, .rodata, code/irqmgr]
- [0x73BA70, rodata, code/73BA70]
@@ -232,11 +233,11 @@
- { start: 0x75B600, type: bss, vram: 0x80137960, name: code/80137960 }
- { start: 0x73F4D0, type: bss, vram: 0x80143900, name: code/m_player_call }
- { start: 0x73F4D0, type: bss, vram: 0x80143910, name: code/80143910 }
+ - { start: 0x73F4D0, type: .bss, vram: 0x80145020, name: code/game }
+ - { start: 0x73F4D0, type: bss, vram: 0x80145060, name: code/80145060 }
- { start: 0x73F4D0, type: .bss, vram: 0x80145390, name: code/irqmgr }
- { start: 0x73F4D0, type: bss, vram: 0x80145620, name: code/80145620}
- { start: 0x73F4D0, type: .bss, vram: 0x801458A0, name: code/c_keyframe }
- { start: 0x73F4D0, type: bss, vram: 0x801458B0, name: code/801458B0 }
- { start: 0x73F4D0, type: .bss, vram: 0x801462B0, name: code/sys_matrix }
- { start: 0x73F4D0, type: bss, vram: 0x801462C0, name: code/801462C0 }
-
-