diff options
| author | Derek Hensley <hensley.derek58@gmail.com> | 2025-01-03 12:05:50 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-03 13:05:50 -0700 |
| commit | f319c8125023f966901131c7ebe479a6f15a750d (patch) | |
| tree | 4d0fb626927306305408e4b19b35fa786cd91192 | |
| parent | cb54eb49e47301ca806a754954bee17e23fe6f40 (diff) | |
Graph OK (#236)
* graph_proc
* game_get_next_game_dlftbl
* graph_ct
* func_800D38E0_jp
* func_800D3C94_jp
* graph_dt
* graph_main
* graph_setup_double_buffer
* graph_task_set00 WIP
* graph_draw_finish
* func_800D3E40_jp
* func_800D3E14_jp
* Some cleanup
* Fix m2ctx.py
* graph_task_set00
| -rw-r--r-- | include/6FB340.h | 4 | ||||
| -rw-r--r-- | include/6FD410.h | 2 | ||||
| -rw-r--r-- | include/buffers.h | 12 | ||||
| -rw-r--r-- | include/cfbinfo.h | 16 | ||||
| -rw-r--r-- | include/code_variables.h | 5 | ||||
| -rw-r--r-- | include/game.h | 2 | ||||
| -rw-r--r-- | include/gfx.h | 49 | ||||
| -rw-r--r-- | include/graph.h | 16 | ||||
| -rw-r--r-- | include/speed_meter.h | 2 | ||||
| -rw-r--r-- | include/sys_ucode.h | 10 | ||||
| -rw-r--r-- | linker_scripts/jp/symbol_addrs_buffers.txt | 2 | ||||
| -rw-r--r-- | linker_scripts/jp/symbol_addrs_code.txt | 13 | ||||
| -rw-r--r-- | linker_scripts/jp/undefined_syms.ld | 2 | ||||
| -rw-r--r-- | src/code/6FD410.c | 2 | ||||
| -rw-r--r-- | src/code/graph.c | 449 | ||||
| -rw-r--r-- | src/code/main.c | 9 | ||||
| -rw-r--r-- | src/code/sys_ucode.c | 10 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_play/m_play.c | 4 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_prenmi/m_prenmi.c | 3 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_second_game/second_game.c | 3 | ||||
| -rwxr-xr-x | tools/m2ctx.py | 4 | ||||
| -rw-r--r-- | yamls/jp/code.yaml | 8 |
22 files changed, 567 insertions, 60 deletions
diff --git a/include/6FB340.h b/include/6FB340.h index ec13f92..f2df10e 100644 --- a/include/6FB340.h +++ b/include/6FB340.h @@ -8,7 +8,7 @@ // void func_800D78F4_jp(); // void func_800D7948_jp(); // void func_800D79BC_jp(); -// void func_800D79F4_jp(); +void func_800D79F4_jp(void); // void func_800D7AE0_jp(); // void func_800D7B60_jp(); // void func_800D7BAC_jp(); @@ -22,7 +22,7 @@ // void func_800D8500_jp(); void func_800D85EC_jp(void); void func_800D8618_jp(void); -// void func_800D8644_jp(); +void func_800D8644_jp(void); // void func_800D8670_jp(); void func_800D87C0_jp(void*, OSPri); diff --git a/include/6FD410.h b/include/6FD410.h index 3420caf..71e347a 100644 --- a/include/6FD410.h +++ b/include/6FD410.h @@ -10,7 +10,7 @@ UNK_PTR func_800D97A0_jp(u32 arg0); UNK_PTR func_800D97F8_jp(u32 arg0); void func_800D986C_jp(s32 arg0); -extern u32 B_80146080_jp; +extern s32 B_80146080_jp; extern UNK_PTR B_80146084_jp; #endif diff --git a/include/buffers.h b/include/buffers.h new file mode 100644 index 0000000..bf8d815 --- /dev/null +++ b/include/buffers.h @@ -0,0 +1,12 @@ +#ifndef BUFFERS_H +#define BUFFERS_H + +#include "gfx.h" +#include "stack.h" + +extern STACK(D_80153CC0_jp, 0x400); +extern STACK(D_801530C0_jp, 0xC00); +extern STACK(D_801524C0_jp, 0xC00); +extern GfxPool gGfxPools[2]; + +#endif diff --git a/include/cfbinfo.h b/include/cfbinfo.h index 4f099ac..b8241da 100644 --- a/include/cfbinfo.h +++ b/include/cfbinfo.h @@ -2,8 +2,22 @@ #define CFBINFO_H #include "ultra64.h" +#include "unk.h" -// void func_800D2C10_jp(); +typedef struct cfbStruct { + /* 0x00 */ void* unk_00; + /* 0x04 */ UNK_PTR unk_04; + /* 0x08 */ UNK_TYPE1 unk_08[0x1]; + /* 0x09 */ u8 unk_09; + /* 0x0A */ u8 unk_0A; + /* 0x0B */ s8 unk_0B; + /* 0x0C */ OSViMode* unk_0C; + /* 0x10 */ s32 unk_10; + /* 0x14 */ f32 unk_14; + /* 0x18 */ f32 unk_18; +} cfbStruct; // size >= 0x1C + +cfbStruct* func_800D2C10_jp(void); // void func_800D2CB4_jp(); // void func_800D2CDC_jp(); diff --git a/include/code_variables.h b/include/code_variables.h index fd72184..e7d8a9f 100644 --- a/include/code_variables.h +++ b/include/code_variables.h @@ -766,7 +766,6 @@ extern s32 fuusen_DEBUG_mode_flag; // extern UNK_TYPE D_8010EF60_jp; // extern UNK_TYPE D_8010EF70_jp; -// extern UNK_TYPE D_8010EFA0_jp; extern vs32 D_8010EFB0_jp; // TODO: Determine where this goes // extern UNK_TYPE D_8010EFB8_jp; // extern UNK_TYPE D_8010EFC0_jp; @@ -1927,10 +1926,6 @@ extern u16 D_80000400[]; // extern UNK_TYPE B_80144FC0_jp; // extern UNK_TYPE B_80145014_jp; -// extern UNK_TYPE B_80145060_jp; -// extern UNK_TYPE B_80145070_jp; -// extern UNK_TYPE B_80145080_jp; -extern u8 B_80145370_jp; // extern UNK_TYPE B_80145390_jp; // extern UNK_TYPE B_80145610_jp; extern OSThread graphThread; diff --git a/include/game.h b/include/game.h index 4cb109a..92a873c 100644 --- a/include/game.h +++ b/include/game.h @@ -56,7 +56,7 @@ typedef struct Game { /* 0x88 */ GameAlloc alloc; /* 0x9C */ u8 unk_9C; /* 0x9D */ u8 unk_9D; - /* 0x9E */ s8 unk9E; + /* 0x9E */ u8 unk_9E; /* 0x9F */ u8 running; /* 0xA0 */ s32 frameCounter; /* 0xA4 */ s32 unk_A4; diff --git a/include/gfx.h b/include/gfx.h index 3a30c4b..e9a9674 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -2,6 +2,7 @@ #define GFX_H #include "ultra64.h" +#include "PR/sched.h" #include "attributes.h" #include "alignment.h" #include "THA_GA.h" @@ -12,10 +13,42 @@ #define TMEM_SIZE 0x1000 +#define GFXPOOL_HEAD_MAGIC 0x1234 +#define GFXPOOL_TAIL_MAGIC 0x5678 + +typedef struct GfxPool { + /* 0x00000 */ u16 headMagic; + /* 0x00004 */ UNK_TYPE1 unk00004[0x4]; + /* 0x00008 */ Gfx polyOpaBuffer[0x29E0]; + /* 0x14F08 */ Gfx polyXluBuffer[0x800]; + /* 0x18F08 */ Gfx overlayBuffer[0x400]; + /* 0x1AF08 */ Gfx workBuffer[0x80]; + /* 0x1B308 */ UNK_TYPE1 unk1B308[0x100]; + /* 0x1B408 */ Gfx fontBuffer[0x700]; + /* 0x1EC08 */ Gfx shadowBuffer[0x200]; + /* 0x1FC08 */ Gfx lightBuffer[0x100]; + /* 0x20408 */ u16 tailMagic; +} GfxPool; // size = 0x20410 + typedef struct GraphicsContext { - /* 0x000 */ UNK_TYPE1 unk_000[0x8]; + /* 0x000 */ Gfx* polyOpaBuffer; + /* 0x004 */ Gfx* polyXluBuffer; /* 0x008 */ UNK_PTR unk_008; - /* 0x00C */ UNK_TYPE1 unk_00C[0x250]; + /* 0x00C */ UNK_TYPE1 unk_00C[0x4]; + /* 0x010 */ Gfx* overlayBuffer; + /* 0x014 */ Gfx* fontBuffer; + /* 0x018 */ Gfx* shadowBuffer; + /* 0x01C */ Gfx* lightBuffer; + /* 0x020 */ s32 unk_20; + /* 0x024 */ UNK_TYPE1 unk_024[0x20]; + /* 0x044 */ OSMesg msgBuff[8]; + /* 0x064 */ OSMesgQueue* unk_064; + /* 0x068 */ OSMesgQueue queue; + /* 0x080 */ OSScTask task; + /* 0x0D8 */ UNK_TYPE1 unk_0E8[0x188 - 0xD8]; + /* 0x188 */ Gfx* workBuffer; + /* 0x18C */ TwoHeadGfxArena work; + /* 0x19C */ UNK_TYPE1 unk_19C[0xC0]; /* 0x25C */ OSViMode* unk_25C; /* 0x260 */ UNK_TYPE1 unk_260[0x20]; /* 0x280 */ TwoHeadGfxArena overlay; @@ -24,19 +57,20 @@ typedef struct GraphicsContext { /* 0x2B0 */ TwoHeadGfxArena font; /* 0x2C0 */ TwoHeadGfxArena shadow; /* 0x2D0 */ TwoHeadGfxArena light; - /* 0x2E0 */ UNK_TYPE1 unk_2E0[0x4]; + /* 0x2E0 */ u32 gfxPoolIndex; /* 0x2E4 */ UNK_PTR 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 */ s32 unk_2F4; - /* 0x2F8 */ s32 unk_2F8; + /* 0x2F3 */ u8 unk_2F3; + /* 0x2F4 */ void (*callback)(struct GraphicsContext*, void*); + /* 0x2F8 */ void* callbackArg; /* 0x2FC */ f32 unk_2FC; /* 0x300 */ f32 unk_300; -} GraphicsContext; // size >= 0x304 + /* 0x304 */ Gfx* unk_304; +} GraphicsContext; // size = 0x308 #define OVERLAY_DISP __gfxCtx->overlay.p #define POLY_OPA_DISP __gfxCtx->polyOpa.p @@ -44,6 +78,7 @@ typedef struct GraphicsContext { #define FONT_DISP __gfxCtx->font.p #define SHADOW_DISP __gfxCtx->shadow.p #define LIGHT_DISP __gfxCtx->light.p +#define WORK_DISP __gfxCtx->work.p // __gfxCtx shouldn't be used directly. // Use the DISP macros defined above when writing to display buffers. diff --git a/include/graph.h b/include/graph.h index fe4cc41..7873648 100644 --- a/include/graph.h +++ b/include/graph.h @@ -3,20 +3,18 @@ #include "ultra64.h" +#include "fault.h" + struct GraphicsContext; extern OSThread graphThread; -// 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(struct GraphicsContext *gfxCtx); void func_800D3E40_jp(struct GraphicsContext *gfxCtx); -// void graph_task_set00(); -// void graph_draw_finish(); -// void graph_main(); + void graph_proc(void* arg); +extern FaultClient sGraphFaultClient; +extern FaultAddrConvClient sGraphFaultAddrConvClient; +extern struct GraphicsContext graph_class; + #endif diff --git a/include/speed_meter.h b/include/speed_meter.h index d63d843..57e5ea2 100644 --- a/include/speed_meter.h +++ b/include/speed_meter.h @@ -19,6 +19,6 @@ void func_800D8A54_jp(struct_80145020_jp *arg0, struct GraphicsContext* gfxCtx); // void func_800D8DD4_jp(); // void func_800D8E18_jp(); void func_800D9018_jp(struct_80145020_jp *arg0, struct GraphicsContext* gfxCtx, struct Game *game); -// void func_800D93F4_jp(); +void func_800D93F4_jp(void); #endif diff --git a/include/sys_ucode.h b/include/sys_ucode.h index 8fc3eb4..8152939 100644 --- a/include/sys_ucode.h +++ b/include/sys_ucode.h @@ -3,18 +3,18 @@ #include "ultra64.h" -extern s64 gspF3DZEX2_NoN_PosLight_fifoTextStart[]; -extern s64 gspF3DZEX2_NoN_PosLight_fifoDataStart[]; +extern u64 gspF3DZEX2_NoN_PosLight_fifoTextStart[]; +extern u64 gspF3DZEX2_NoN_PosLight_fifoDataStart[]; extern u64 gspS2DEX2_fifoTextStart[]; extern u64 gspS2DEX2_fifoDataStart[]; -s64* ucode_GetRspBootTextStart(void); +u64* ucode_GetRspBootTextStart(void); size_t ucode_GetRspBootTextSize(void); -s64* ucode_GetPolyTextStart(void); -s64* ucode_GetPolyDataStart(void); +u64* ucode_GetPolyTextStart(void); +u64* ucode_GetPolyDataStart(void); u64* ucode_GetSpriteTextStart(void); u64* ucode_GetSpriteDataStart(void); diff --git a/linker_scripts/jp/symbol_addrs_buffers.txt b/linker_scripts/jp/symbol_addrs_buffers.txt index f9d0ef7..551e0fb 100644 --- a/linker_scripts/jp/symbol_addrs_buffers.txt +++ b/linker_scripts/jp/symbol_addrs_buffers.txt @@ -1,5 +1,5 @@ D_801524C0_jp = 0x801524C0; // D_801530C0_jp = 0x801530C0; // D_80153CC0_jp = 0x80153CC0; // -D_801540C0_jp = 0x801540C0; // +gGfxPools = 0x801540C0; // D_801948E0_jp = 0x801948E0; // diff --git a/linker_scripts/jp/symbol_addrs_code.txt b/linker_scripts/jp/symbol_addrs_code.txt index 37e0054..21b9ba8 100644 --- a/linker_scripts/jp/symbol_addrs_code.txt +++ b/linker_scripts/jp/symbol_addrs_code.txt @@ -3424,10 +3424,10 @@ gamealloc_init = 0x800D3848; // type:func gfxopen = 0x800D3860; // type:func gfxclose = 0x800D386C; // type:func gfxalloc = 0x800D38A0; // type:func -func_800D38E0_jp = 0x800D38E0; // type:func +graph_FaultClient = 0x800D38E0; // type:func graph_setup_double_buffer = 0x800D39AC; // type:func game_get_next_game_dlftbl = 0x800D3B84; // type:func -func_800D3C94_jp = 0x800D3C94; // type:func +graph_FaultAddrConv = 0x800D3C94; // type:func graph_ct = 0x800D3D04; // type:func graph_dt = 0x800D3DD8; // type:func func_800D3E14_jp = 0x800D3E14; // type:func @@ -4965,7 +4965,7 @@ D_8010EF60_jp = 0x8010EF60; // D_8010EF70_jp = 0x8010EF70; // S_ongenpos_refuse_fg = 0x8010EF80; // gamePT = 0x8010EF90; // -D_8010EFA0_jp = 0x8010EFA0; // +sRetryCount = 0x8010EFA0; // ResetStatus = 0x8010EFB0; // ResetTime = 0x8010EFB8; // RetraceTime = 0x8010EFC0; // @@ -6160,10 +6160,9 @@ 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; // -B_80145370_jp = 0x80145370; // type:s8 +sGraphFaultAddrConvClient = 0x80145060; // +sGraphFaultClient = 0x80145070; // +graph_class = 0x80145080; // size:0x308 irqmgr_class = 0x80145390; // B_80145610_jp = 0x80145610; // B_80145620_jp = 0x80145620; // diff --git a/linker_scripts/jp/undefined_syms.ld b/linker_scripts/jp/undefined_syms.ld index 61812c4..b76c1c1 100644 --- a/linker_scripts/jp/undefined_syms.ld +++ b/linker_scripts/jp/undefined_syms.ld @@ -5661,5 +5661,5 @@ obj_e_koinobori_shadowT_model = 0x06001E48; // D_801524C0_jp = 0x801524C0; // D_801530C0_jp = 0x801530C0; // D_80153CC0_jp = 0x80153CC0; // -D_801540C0_jp = 0x801540C0; // +gGfxPools = 0x801540C0; // D_801948E0_jp = 0x801948E0; // diff --git a/src/code/6FD410.c b/src/code/6FD410.c index ab5ecc7..0908332 100644 --- a/src/code/6FD410.c +++ b/src/code/6FD410.c @@ -2,7 +2,7 @@ #include "libc/stdbool.h" -u32 B_80146080_jp; +s32 B_80146080_jp; UNK_PTR B_80146084_jp; void func_800D9770_jp(void) { diff --git a/src/code/graph.c b/src/code/graph.c new file mode 100644 index 0000000..1fe2a06 --- /dev/null +++ b/src/code/graph.c @@ -0,0 +1,449 @@ +#include "graph.h" +#include "global.h" + +#include "audio.h" +#include "buffers.h" +#include "cfbinfo.h" +#include "fault.h" +#include "game.h" +#include "getcurrentms.h" +#include "gfx.h" +#include "idle.h" +#include "irqmgr.h" +#include "m_debug.h" +#include "m_DLF.h" +#include "speed_meter.h" +#include "sys_ucode.h" +#include "zurumode.h" +#include "6FB340.h" +#include "6FD190.h" +#include "6FD410.h" + +#include "overlays/gamestates/ovl_first_game/first_game.h" +#include "overlays/gamestates/ovl_select/m_select.h" +#include "overlays/gamestates/ovl_play/m_play.h" +#include "overlays/gamestates/ovl_second_game/second_game.h" +#include "overlays/gamestates/ovl_cpedit/m_cpedit.h" +#include "overlays/gamestates/ovl_trademark/m_trademark.h" +#include "overlays/gamestates/ovl_player_select/player_select.h" +#include "overlays/gamestates/ovl_save_menu/save_menu.h" +#include "overlays/gamestates/ovl_famicom_emu/famicom_emu.h" +#include "overlays/gamestates/ovl_prenmi/m_prenmi.h" + +void graph_FaultClient(void) { + s32 i; + void* fb; + + FaultDrawer_DrawText(30, 100, "ShowFrameBuffer PAGE 0/1/2"); + + for (i = 0; i < 3; i++) { + fb = func_800D96E8_jp(i); + if (fb != NULL) { + osViSwapBuffer(fb); + osViSetMode(&gViConfigMode); + osViSetSpecialFeatures(gViConfigFeatures); + osViSetXScale(gViConfigXScale); + osViSetYScale(gViConfigYScale); + fault_WaitForInput(); + } + } +} + +void graph_setup_double_buffer(GraphicsContext* gfxCtx) { + GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIndex % 2]; + + pool->headMagic = GFXPOOL_HEAD_MAGIC; + pool->tailMagic = GFXPOOL_TAIL_MAGIC; + + THA_GA_ct(&gfxCtx->polyOpa, pool->polyOpaBuffer, sizeof(pool->polyOpaBuffer)); + THA_GA_ct(&gfxCtx->polyXlu, pool->polyXluBuffer, sizeof(pool->polyXluBuffer)); + THA_GA_ct(&gfxCtx->overlay, pool->overlayBuffer, sizeof(pool->overlayBuffer)); + THA_GA_ct(&gfxCtx->work, pool->workBuffer, sizeof(pool->workBuffer)); + THA_GA_ct(&gfxCtx->font, pool->fontBuffer, sizeof(pool->fontBuffer)); + THA_GA_ct(&gfxCtx->shadow, pool->shadowBuffer, sizeof(pool->shadowBuffer)); + THA_GA_ct(&gfxCtx->light, pool->lightBuffer, sizeof(pool->lightBuffer)); + + gfxCtx->polyOpaBuffer = pool->polyOpaBuffer; + gfxCtx->polyXluBuffer = pool->polyXluBuffer; + gfxCtx->overlayBuffer = pool->overlayBuffer; + gfxCtx->workBuffer = pool->workBuffer; + gfxCtx->fontBuffer = pool->fontBuffer; + gfxCtx->shadowBuffer = pool->shadowBuffer; + gfxCtx->lightBuffer = pool->lightBuffer; + + while (gfxCtx->unk_2E4 == NULL) { + s32 temp_s1_2 = func_800D9700_jp(); + + gfxCtx->unk_2E4 = func_800D96E8_jp(gfxCtx->unk_2F3); + if (gfxCtx->unk_2E4 == B_80146084_jp) { + gfxCtx->unk_2E4 = NULL; + } + + gfxCtx->unk_2F3 = ((gfxCtx->unk_2F3 + 1) < temp_s1_2) ? gfxCtx->unk_2F3 + 1 : 0; + } + + gfxCtx->unk_008 = func_800D9750_jp(); + gfxCtx->unk_20 = 0; +} + +GameStateOverlay* game_get_next_game_dlftbl(Game* game) { + GameStateFunc init = game_get_next_game_init(game); + + if (init == first_game_init) { + return &game_dlftbls[0]; + } + if (init == select_init) { + return &game_dlftbls[1]; + } + if (init == play_init) { + return &game_dlftbls[2]; + } + if (init == second_game_init) { + return &game_dlftbls[3]; + } + if (init == cpedit_init) { + return &game_dlftbls[4]; + } + if (init == trademark_init) { + return &game_dlftbls[5]; + } + if (init == player_select_init) { + return &game_dlftbls[6]; + } + if (init == save_menu_init) { + return &game_dlftbls[7]; + } + if (init == famicom_emu_init) { + return &game_dlftbls[8]; + } + if (init == prenmi_init) { + return &game_dlftbls[9]; + } + + return NULL; +} + +uintptr_t graph_FaultAddrConv(uintptr_t address, UNUSED void* param) { + uintptr_t addr = address; + GameStateOverlay* gameStateOvl = &game_dlftbls[0]; + uintptr_t ramConv; + void* ramStart; + size_t diff; + s32 i; + + for (i = 0; i < game_dlftbls_num; i++, gameStateOvl++) { + diff = (uintptr_t)gameStateOvl->vramEnd - (uintptr_t)gameStateOvl->vramStart; + ramStart = gameStateOvl->loadedRamAddr; + ramConv = (uintptr_t)gameStateOvl->vramStart - (uintptr_t)ramStart; + + if (ramStart != NULL) { + if ((addr >= (uintptr_t)ramStart) && (addr < (uintptr_t)ramStart + diff)) { + return addr + ramConv; + } + } + } + return 0; +} + +void graph_ct(GraphicsContext* gfxCtx) { + bzero(gfxCtx, sizeof(GraphicsContext)); + gfxCtx->gfxPoolIndex = 0; + gfxCtx->unk_2F3 = 0; + gfxCtx->unk_25C = &osViModeNtscLan1; + gfxCtx->unk_2EC = 66; + gfxCtx->unk_2FC = 1.0f; + gfxCtx->unk_300 = 1.0f; + osCreateMesgQueue(&gfxCtx->queue, gfxCtx->msgBuff, ARRAY_COUNT(gfxCtx->msgBuff)); + SREG(33) &= ~2; + SREG(33) &= ~1; + zurumode_init(); + fault_AddClient(&sGraphFaultClient, (void*)graph_FaultClient, NULL, NULL); + fault_AddressConverterAddClient(&sGraphFaultAddrConvClient, graph_FaultAddrConv, NULL); + gfxCtx->unk_2F0 = 1; +} + +void graph_dt(GraphicsContext* gfxCtx) { + gfxCtx->unk_2F0 = 0x15; + zurumode_cleanup(); + fault_RemoveClient(&sGraphFaultClient); + fault_AddressConverterRemoveClient(&sGraphFaultAddrConvClient); +} + +void func_800D3E14_jp(GraphicsContext* gfxCtx) { + osSendMesg(&gfxCtx->queue, NULL, OS_MESG_BLOCK); +} + +void func_800D3E40_jp(GraphicsContext* gfxCtx) { + static s32 sRetryCount = 100; + UNUSED s32 pad; + OSTimer timer; + OSMesg msg; + +retry: + osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &gfxCtx->queue, (OSMesg)666); + osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK); + osStopTimer(&timer); + if ((ResetStatus < 2) && (msg == (OSMesg)666)) { + if (sRetryCount >= 0) { + if (1) { + sRetryCount--; + func_800D8644_jp(); + } + goto retry; + } + fault_AddHungupAndCrashImpl("RCP is HUNG UP!!", "Oh! MY GOD!!"); + } +} + +void graph_task_set00(GraphicsContext* gfxCtx) { + UNUSED s32 pad; + OSTask* task = &gfxCtx->task.list; + OSScTask* scTask = &gfxCtx->task; + uintptr_t temp_a1; + uintptr_t temp_a0; + uintptr_t temp_a2; + + gfxCtx->unk_2F0 = 0xD; + + func_800D3E40_jp(gfxCtx); + gfxCtx->unk_2F0 = 0xE; + + if (ResetStatus < 2) { + gfxCtx->unk_304 = gfxCtx->workBuffer; + if (gfxCtx->callback != NULL) { + gfxCtx->callback(gfxCtx, gfxCtx->callbackArg); + } + if (SREG(33) & 2) { + SREG(33) &= ~2; + task->t.type = 0; + } else { + task->t.type = M_GFXTASK; + task->t.flags = OS_SC_DRAM_DLIST; + + OPEN_DISPS(gfxCtx); + + task->t.ucode_boot = ucode_GetRspBootTextStart(); + task->t.ucode_boot_size = ucode_GetRspBootTextSize(); + task->t.ucode = ucode_GetPolyTextStart(); + task->t.ucode_data = ucode_GetPolyDataStart(); + task->t.ucode_size = SP_UCODE_SIZE; + task->t.ucode_data_size = SP_UCODE_DATA_SIZE; + task->t.dram_stack = D_80153CC0_jp; + task->t.dram_stack_size = sizeof(D_80153CC0_jp); + + temp_a1 = (uintptr_t)POLY_OPA_DISP; + temp_a0 = ALIGN16(temp_a1); + temp_a2 = ALIGN16(THA_GA_getFreeBytes(&gfxCtx->polyOpa) - temp_a0 + temp_a1 - 0xF); + + if (((uintptr_t)(D_801524C0_jp + ARRAY_COUNT(D_801524C0_jp)) - (uintptr_t)D_801524C0_jp) < temp_a2) { + task->t.output_buff = (u64*)temp_a0; + task->t.output_buff_size = (u64*)(temp_a0 + temp_a2); + } else { + task->t.output_buff = D_801524C0_jp; + task->t.output_buff_size = D_801524C0_jp + ARRAY_COUNT(D_801524C0_jp); + } + CLOSE_DISPS(gfxCtx); + + task->t.data_ptr = (u64*)gfxCtx->workBuffer; + + OPEN_DISPS(gfxCtx); + task->t.data_size = (uintptr_t)WORK_DISP - (uintptr_t)gfxCtx->workBuffer; + CLOSE_DISPS(gfxCtx); + + task->t.yield_data_ptr = D_801530C0_jp; + task->t.yield_data_size = sizeof(D_801530C0_jp); + } + scTask->next = NULL; + + if (SREG(33) & 1) { + scTask->flags = OS_SC_NEEDS_RSP | OS_SC_NEEDS_RDP | OS_SC_LAST_TASK; + } else { + scTask->flags = OS_SC_NEEDS_RSP | OS_SC_NEEDS_RDP | OS_SC_SWAPBUFFER | OS_SC_LAST_TASK; + } + scTask->msgQ = &gfxCtx->queue; + scTask->msg = NULL; + + { + cfbStruct* cfb = func_800D2C10_jp(); + + cfb->unk_00 = gfxCtx->unk_2E4; + cfb->unk_04 = NULL; + cfb->unk_09 = game_GameFrame; + cfb->unk_0C = NULL; + if (scTask->flags & OS_SC_SWAPBUFFER) { + cfb->unk_04 = gfxCtx->unk_2E4; + if (gfxCtx->unk_2F2 != 0) { + gfxCtx->unk_2F2 = 0; + cfb->unk_0C = gfxCtx->unk_25C; + cfb->unk_10 = gfxCtx->unk_2EC; + cfb->unk_14 = gfxCtx->unk_2FC; + cfb->unk_18 = gfxCtx->unk_300; + } + if (B_80146080_jp == 1) { + B_80146084_jp = cfb->unk_04; + cfb->unk_0B = 1; + B_80146080_jp = 2; + } + } + + scTask->framebuffer = cfb; + } + + while (gfxCtx->queue.validCount != 0) { + osRecvMesg(&gfxCtx->queue, NULL, OS_MESG_NOBLOCK); + } + + if (ResetStatus < 2) { + gfxCtx->unk_064 = &B_80145DB8_jp; + osSendMesg(&B_80145DB8_jp, (OSMesg)scTask, OS_MESG_BLOCK); + func_800D85EC_jp(); + } + } +} + +u32 graph_draw_finish(GraphicsContext* gfxCtx) { + u32 err; + UNUSED s32 pad[2]; + + OPEN_DISPS(gfxCtx); + + gSPBranchList(WORK_DISP++, gfxCtx->polyOpaBuffer); + gSPBranchList(POLY_OPA_DISP++, gfxCtx->shadowBuffer); + gSPBranchList(SHADOW_DISP++, gfxCtx->polyXluBuffer); + gSPBranchList(POLY_XLU_DISP++, gfxCtx->lightBuffer); + gSPBranchList(LIGHT_DISP++, gfxCtx->fontBuffer); + gSPBranchList(FONT_DISP++, gfxCtx->overlayBuffer); + + gDPPipeSync(OVERLAY_DISP++); + gDPFullSync(OVERLAY_DISP++); + gSPEndDisplayList(OVERLAY_DISP++); + + CLOSE_DISPS(gfxCtx); + + err = false; + { + GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIndex & 1]; + + if (pool->headMagic != GFXPOOL_HEAD_MAGIC) { + fault_AddHungupAndCrash("../graph.c", 606); + } + if (pool->tailMagic != GFXPOOL_TAIL_MAGIC) { + err = true; + fault_AddHungupAndCrash("../graph.c", 614); + } + } + + if (THA_GA_isCrash(&gfxCtx->polyOpa)) { + err = true; + } + if (THA_GA_isCrash(&gfxCtx->polyXlu)) { + err = true; + } + if (THA_GA_isCrash(&gfxCtx->overlay)) { + err = true; + } + if (THA_GA_isCrash(&gfxCtx->font)) { + err = true; + } + if (THA_GA_isCrash(&gfxCtx->shadow)) { + err = true; + } + if (THA_GA_isCrash(&gfxCtx->light)) { + err = true; + } + + return err; +} + +void graph_main(GraphicsContext* gfxCtx, Game* game) { + game->unk_A4 = false; + graph_setup_double_buffer(gfxCtx); + game_get_controller(game); + game->unk_9E = false; + gfxCtx->unk_2F0 = 4; + + game_main(game); + + gfxCtx->unk_2F0 = 0xB; + + if ((ResetStatus < 2) && !game->unk_9E && !graph_draw_finish(gfxCtx)) { + gfxCtx->unk_2F0 = 0xC; + + graph_task_set00(gfxCtx); + gfxCtx->unk_2F0 = 0xF; + + gfxCtx->gfxPoolIndex++; + if (SREG(33) & 1) { + SREG(33) &= ~1; + } else { + gfxCtx->unk_2E4 = NULL; + } + } + if (SREG(20) < 2) { + gfxCtx->unk_2F0 = 0x10; + + sAdo_GameFrame(); + gfxCtx->unk_2F0 = 0x11; + } + + func_800D93F4_jp(); + + if ((ResetStatus == 1) && !game->unk_A4) { + STOP_GAMESTATE(game); + SET_NEXT_GAMESTATE(game, prenmi_init, sizeof(Game_Prenmi)); + } +} + +void graph_proc(UNUSED void* arg) { + s32 state; + GameStateOverlay* nextOvl = &game_dlftbls[0]; + GameStateOverlay* ovl; + size_t size; + Game* game; + char msg[80]; + + graph_ct(&graph_class); + + while (nextOvl != NULL) { + ovl = nextOvl; + + Overlay_LoadGameState(ovl); + + state = 2; + size = ovl->instanceSize; + game = malloc(size); + game_class_p = game; + if (game == NULL) { + sprintf(msg, "CLASS SIZE= %d bytes", size); + fault_AddHungupAndCrashImpl("GAME CLASS MALLOC FAILED", msg); + } + bzero(game, size); + graph_class.unk_2F0 = state; + + state = 3; + game_ct(game, ovl->init, &graph_class); + graph_class.unk_2F0 = state; + + state = 0x12; + while (game_is_doing(game)) { + graph_main(&graph_class, game); + B_80145FF8_jp = GetCurrentMilliseconds(); + } + nextOvl = game_get_next_game_dlftbl(game); + graph_class.unk_2F0 = state; + + state = 0x13; + func_800D79F4_jp(); + graph_class.unk_2F0 = state; + + state = 0x14; + game_dt(game); + graph_class.unk_2F0 = state; + + free(game); + game_class_p = NULL; + Overlay_FreeGameState(ovl); + } + + graph_dt(&graph_class); +} diff --git a/src/code/main.c b/src/code/main.c index 0cd4e26..d602fa9 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -1,11 +1,11 @@ #include "main.h" -#include "6FB340.h" -#include "6FD190.h" + #include "audioMgr.h" #include "code_variables.h" #include "fault.h" #include "game.h" #include "getcurrentms.h" +#include "gfx.h" #include "graph.h" #include "irqmgr.h" #include "libu64/stackcheck.h" @@ -19,6 +19,8 @@ #include "sys_stacks.h" #include "system_heap.h" #include "zurumode.h" +#include "6FB340.h" +#include "6FD190.h" OSThread graphThread; StackEntry graphStackInfo; @@ -66,7 +68,8 @@ void func_800D64E0_jp(void) { unk9C = (game_class_p != NULL) ? game_class_p->unk_9C : 0; - FaultDrawer_DrawText(24, 16, "GRAPH INF.LOOP %2d %3d %3d %6lu", B_80145370_jp, unk9D, unk9C, graphTime); + FaultDrawer_DrawText(24, 16, "GRAPH INF.LOOP %2d %3d %3d %6lu", graph_class.unk_2F0, unk9D, unk9C, + graphTime); fault_DrawStackTrace(&graphThread, 32, 26, 10); } if (audioReg != 0) { diff --git a/src/code/sys_ucode.c b/src/code/sys_ucode.c index 73fd5a6..9e0915b 100644 --- a/src/code/sys_ucode.c +++ b/src/code/sys_ucode.c @@ -2,23 +2,23 @@ #include "sys_ucode.h" -s64* poly_tbl[] = { gspF3DZEX2_NoN_PosLight_fifoTextStart, gspF3DZEX2_NoN_PosLight_fifoDataStart }; +u64* poly_tbl[] = { gspF3DZEX2_NoN_PosLight_fifoTextStart, gspF3DZEX2_NoN_PosLight_fifoDataStart }; u64* sprite_tbl[] = { gspS2DEX2_fifoTextStart, gspS2DEX2_fifoDataStart }; -s64* ucode_GetRspBootTextStart() { - return rspbootTextStart; +u64* ucode_GetRspBootTextStart() { + return (u64*)rspbootTextStart; } size_t ucode_GetRspBootTextSize() { return ((uintptr_t)rspbootTextEnd - (uintptr_t)rspbootTextStart); } -s64* ucode_GetPolyTextStart() { +u64* ucode_GetPolyTextStart() { return poly_tbl[0]; } -s64* ucode_GetPolyDataStart() { +u64* ucode_GetPolyDataStart() { return poly_tbl[1]; } diff --git a/src/overlays/gamestates/ovl_play/m_play.c b/src/overlays/gamestates/ovl_play/m_play.c index 44dea63..d3201e5 100644 --- a/src/overlays/gamestates/ovl_play/m_play.c +++ b/src/overlays/gamestates/ovl_play/m_play.c @@ -337,8 +337,8 @@ void play_cleanup(Game* game) { Game_Play* game_play = (Game_Play*)game; func_800A3304_jp(game_play); - game_play->state.gfxCtx->unk_2F4 = 0; - game_play->state.gfxCtx->unk_2F8 = 0; + game_play->state.gfxCtx->callback = NULL; + game_play->state.gfxCtx->callbackArg = NULL; game_play->submenu.unk_00 = 0; PreRender_cleanup(&game_play->unk_1DC0); CollisionCheck_dt(game_play, &game_play->unk_2138); diff --git a/src/overlays/gamestates/ovl_prenmi/m_prenmi.c b/src/overlays/gamestates/ovl_prenmi/m_prenmi.c index 122e1ef..cbd567d 100644 --- a/src/overlays/gamestates/ovl_prenmi/m_prenmi.c +++ b/src/overlays/gamestates/ovl_prenmi/m_prenmi.c @@ -1,4 +1,5 @@ #include "m_prenmi.h" +#include "libc/stdbool.h" #include "irqmgr.h" #include "viconfig.h" #include "gfx.h" @@ -54,7 +55,7 @@ void prenmi_main(Game* game) { prenmi_move(prenmi); prenmi_draw(prenmi); - prenmi->state.unk_A4 = 1; + prenmi->state.unk_A4 = true; { UNUSED s32 scopedTemp; } graph = game->gfxCtx; diff --git a/src/overlays/gamestates/ovl_second_game/second_game.c b/src/overlays/gamestates/ovl_second_game/second_game.c index 3fe3dcd..c823089 100644 --- a/src/overlays/gamestates/ovl_second_game/second_game.c +++ b/src/overlays/gamestates/ovl_second_game/second_game.c @@ -1,4 +1,5 @@ #include "second_game.h" +#include "libc/stdbool.h" #include "overlays/gamestates/ovl_trademark/m_trademark.h" #include "overlays/gamestates/ovl_cpedit/m_cpedit.h" #include "69CB30.h" @@ -30,7 +31,7 @@ void second_game_main(Game* game) { SET_NEXT_GAMESTATE(&secondGame->state, trademark_init, sizeof(Game_Trademark)); } - secondGame->state.unk9E = 1; + secondGame->state.unk_9E = true; } void second_game_cleanup(UNUSED Game* game) { diff --git a/tools/m2ctx.py b/tools/m2ctx.py index 2d3af5c..6de20af 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -39,10 +39,10 @@ CPP_FLAGS = [ def import_c_file(in_file) -> str: in_file = os.path.relpath(in_file, root_dir) - cpp_command = ["gcc", "-E", "-P", "-dD", *CPP_FLAGS, in_file] + cpp_command = ["gcc", "-E", "-P", "-undef", "-dD", *CPP_FLAGS, in_file] with tempfile.NamedTemporaryFile(suffix=".c") as tmp: - stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") + stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-undef", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") try: out_text = subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") diff --git a/yamls/jp/code.yaml b/yamls/jp/code.yaml index 32f3aff..1f7eceb 100644 --- a/yamls/jp/code.yaml +++ b/yamls/jp/code.yaml @@ -98,7 +98,7 @@ - [0x6F6AA0, c, code/game] - [0x6F73C0, c, code/gamealloc] - [0x6F7500, c, code/gfxalloc] - - [0x6F7580, asm, code/graph] + - [0x6F7580, c, code/graph] - [0x6F83B0, c, code/irqmgr] - [0x6F8A60, c, code/lb_rtc] - [0x6F9B10, c, code/lb_reki] @@ -198,7 +198,7 @@ - [0x732BB0, data, code/732BB0] - [0x732C20, .data, code/audio] - [0x732C30, .data, code/game] - - [0x732C40, data, code/732C40] + - [0x732C40, .data, code/main] - [0x732C50, .data, code/irqmgr] - [0x732C70, .data, code/lb_rtc] - [0x732C80, .data, code/lb_reki] @@ -273,7 +273,7 @@ - [0x73B920, .rodata, code/audioMgr] - [0x73B960, rodata, code/73B960] - [0x73B980, .rodata, code/game] - - [0x73B9C0, rodata, code/73B9C0] + - [0x73B9C0, .rodata, code/graph] - [0x73BA50, .rodata, code/irqmgr] - [0x73BA70, .rodata, code/lb_rtc] - [0x73BB10, .rodata, code/main] @@ -327,7 +327,7 @@ - { start: 0x73F4D0, type: .bss, vram: 0x80144D20, name: code/audioMgr } - { start: 0x73F4D0, type: bss, vram: 0x80144FC0, name: code/80144FC0 } - { start: 0x73F4D0, type: .bss, vram: 0x80145020, name: code/game } - - { start: 0x73F4D0, type: bss, vram: 0x80145060, name: code/80145060 } + - { start: 0x73F4D0, type: bss, vram: 0x80145060, name: code/graph } - { start: 0x73F4D0, type: .bss, vram: 0x80145390, name: code/irqmgr } - { start: 0x73F4D0, type: .bss, vram: 0x80145620, name: code/lb_rtc} - { start: 0x73F4D0, type: .bss, vram: 0x80145630, name: code/main} |
