From 068d951791dc9899228eb886c9f1518ef134dca1 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Mon, 29 May 2023 10:54:50 -0400 Subject: [PATCH 1/2] Implement & link second_game.c --- config/rel_slices.yml | 3 ++ config/symbols.yml | 3 ++ include/dolphin/vi.h | 1 + include/jaudio_NES/game64.h | 3 ++ include/libultra/libultra.h | 1 + include/padmgr.h | 11 +++++ include/second_game.h | 4 +- include/sys_math.h | 1 + rel/second_game.c | 96 +++++++++++++++++++++++++++++++++++++ 9 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 rel/second_game.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 84f81a81..be3ac3d3 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -127,6 +127,9 @@ m_random_field/mRF_MakePerfectBit.c: .text: [0x8050B1AC, 0x8050B1D4] m_random_field/mRF_GetRandomStepMode.c: .text: [0x8050B284, 0x8050B2C0] +second_game.c: + .text: [0x8062B630, 0x8062B848] + .bss: [0x8148DA60, 0x8148DA68] m_trademark.c: .text: [0x8062B848, 0x8062C048] .rodata: [0x8064D1C0, 0x8064D1C8] diff --git a/config/symbols.yml b/config/symbols.yml index 233b2cf0..8a4733b9 100644 --- a/config/symbols.yml +++ b/config/symbols.yml @@ -52674,6 +52674,9 @@ global: 0x81361828: fbdemo 0x81361920: gxbuf 0x81361A60: prbuf + 0x8148DA60: sound_ok + 0x8148DA61: contpad_ok + 0x8148DA62: frame_count 0x8148DA68: famicom_done 0x8148DA6C: famicom_done_countdown 0x8148DA70: freeXfbBase diff --git a/include/dolphin/vi.h b/include/dolphin/vi.h index 7f065e0f..645cb5ec 100644 --- a/include/dolphin/vi.h +++ b/include/dolphin/vi.h @@ -12,6 +12,7 @@ void VIWaitForRetrace(); void VIConfigurePan(u16 x_origin, u16 y_origin, u16 width, u16 height); u32 VIGetRetraceCount(); u32 VIGetDTVStatus(); +void VIFlush(); #ifdef __cplusplus }; diff --git a/include/jaudio_NES/game64.h b/include/jaudio_NES/game64.h index c7430c6f..0efa9a34 100644 --- a/include/jaudio_NES/game64.h +++ b/include/jaudio_NES/game64.h @@ -10,6 +10,9 @@ extern "C" { extern void Na_InitAudio(void (*fatal_callback)(), u8* load_addr, size_t load_size, u8* bootsound, size_t bootsound_size, BOOL cut_flag); extern void Na_GameFrame(); extern u8 Na_CheckNeosBoot(); +extern void Na_RestartPrepare(); +extern u8 Na_CheckRestartReady(); +extern void Na_Restart(); #ifdef __cplusplus } diff --git a/include/libultra/libultra.h b/include/libultra/libultra.h index 8e992a2f..32c32e3a 100644 --- a/include/libultra/libultra.h +++ b/include/libultra/libultra.h @@ -9,6 +9,7 @@ #include "libultra/shutdown.h" #include "libultra/os_timer.h" #include "libultra/os_thread.h" +#include "libultra/initialize.h" #define N64_SCREEN_HEIGHT 240 #define N64_SCREEN_WIDTH 320 diff --git a/include/padmgr.h b/include/padmgr.h index 7270e3fb..436a81d4 100644 --- a/include/padmgr.h +++ b/include/padmgr.h @@ -12,6 +12,15 @@ extern "C" { #define PADMSGBUFCNT 8 +enum pads { + PAD0, + PAD1, + PAD2, + PAD3, + + PAD_NUM +}; + typedef struct { u8 last_intensity; u8 now_intensity; @@ -54,6 +63,8 @@ typedef struct { extern padmgr padmgr_class; +extern int padmgr_isConnectedController(int pad); + #define padmgr_setClient(callback, param) \ do { \ padmgr* mgr = &padmgr_class; \ diff --git a/include/second_game.h b/include/second_game.h index cb3f1ccb..11bdf2d6 100644 --- a/include/second_game.h +++ b/include/second_game.h @@ -13,8 +13,8 @@ typedef struct second_game_s { /* 0x00 */ GAME game; } GAME_SECOND; -extern void second_game_init(GAME_SECOND second); -extern void second_game_cleanup(GAME_SECOND* second); +extern void second_game_init(GAME* game); +extern void second_game_cleanup(GAME* game); #ifdef __cplusplus } diff --git a/include/sys_math.h b/include/sys_math.h index 2c5feaf5..7e4a0579 100644 --- a/include/sys_math.h +++ b/include/sys_math.h @@ -10,6 +10,7 @@ extern "C" { extern s16 atans_table(f32 x, f32 y); extern f32 atanf_table(f32 x, f32 y); +extern void init_rnd(); #ifdef __cplusplus } diff --git a/rel/second_game.c b/rel/second_game.c new file mode 100644 index 00000000..30049a7d --- /dev/null +++ b/rel/second_game.c @@ -0,0 +1,96 @@ +#include "second_game.h" + +#include "m_trademark.h" +#include "jaudio_NES/game64.h" +#include "padmgr.h" +#include "m_common_data.h" +#include "zurumode.h" +#include "libultra/libultra.h" +#include "dolphin/vi.h" +#include "dolphin/dvd.h" +#include "boot.h" +#include "sys_math.h" +#include "m_nmibuf.h" + +#pragma pool_data on +static u8 sound_ok; +static u8 contpad_ok; +static u8 frame_count; + +static void second_game_main(GAME* game) { + if (sound_ok == 0) { + sound_ok = 1; + Na_RestartPrepare(); + } + + if (Na_CheckRestartReady() == TRUE) { + sound_ok = 2; + } + + if (sound_ok == 2) { + Na_Restart(); + } + + if (padmgr_isConnectedController(PAD0)) { + contpad_ok = TRUE; + } + + if (sound_ok == 2 && (contpad_ok || frame_count > 3)) { + GAME_GOTO_NEXT(game, trademark, TRADEMARK); + } + + frame_count++; +} + +extern void second_game_cleanup(GAME* game) { + Common_Set(pad_connected, contpad_ok); +} + +extern void second_game_init(GAME* game) { + if (zurumode_flag != 0 && osShutdown >= 3) { + VISetBlack(TRUE); + VIFlush(); + VIWaitForRetrace(); + + switch (osShutdown) { + case 3: + { + osShutdownStart(OS_RESET_SHUTDOWN); + break; + } + + case 4: + { + HotResetIplMenu(); + break; + } + + default: + { + osShutdownStart(OS_RESET_RESTART); + break; + } + } + } + + if (osShutdown != 0) { + if (APPNMI_HOTRESET_GET()) { + osShutdownStart(OS_RESET_SHUTDOWN); + } + else { + if (DVDCheckDisk() == FALSE) { + osShutdownStart(OS_RESET_RESTART); + } + } + } + + sound_ok = 0; + contpad_ok = TRUE; + frame_count = 0; + + game->exec = &second_game_main; + game->cleanup = &second_game_cleanup; + init_rnd(); + __osInitialize_common(); +} +#pragma pool_data reset From bf9e2a3be4265c5cb8560b4bc10c3b452389dda5 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Mon, 29 May 2023 23:05:11 -0400 Subject: [PATCH 2/2] Implement & link first_game.c, sys_romcheck.c --- config/rel_slices.yml | 4 ++++ include/Famicom/famicom.h | 18 ++++++++++++++++++ include/first_game.h | 4 ++-- include/m_bgm.h | 1 + include/m_card.h | 3 +++ include/m_common_data.h | 1 + include/m_vibctl.h | 1 + include/sys_romcheck.h | 18 ++++++++++++++++++ rel/first_game.c | 26 ++++++++++++++++++++++++++ rel/sys_romcheck.c | 10 ++++++++++ 10 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 include/Famicom/famicom.h create mode 100644 include/sys_romcheck.h create mode 100644 rel/first_game.c create mode 100644 rel/sys_romcheck.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index be3ac3d3..bb60a7a1 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -127,6 +127,10 @@ m_random_field/mRF_MakePerfectBit.c: .text: [0x8050B1AC, 0x8050B1D4] m_random_field/mRF_GetRandomStepMode.c: .text: [0x8050B284, 0x8050B2C0] +first_game.c: + .text: [0x80629CA8, 0x80629D4C] +sys_romcheck.c: + .text: [0x80629D4C, 0x80629D8C] second_game.c: .text: [0x8062B630, 0x8062B848] .bss: [0x8148DA60, 0x8148DA68] diff --git a/include/Famicom/famicom.h b/include/Famicom/famicom.h new file mode 100644 index 00000000..c0795e2a --- /dev/null +++ b/include/Famicom/famicom.h @@ -0,0 +1,18 @@ +#ifndef FAMICOM_H +#define FAMICOM_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef u8 (*FAMICOM_GETSAVECHAN_PROC)(int* player_no, int* slot_card_result); + +extern void famicom_setCallback_getSaveChan(FAMICOM_GETSAVECHAN_PROC getSaveChan_proc); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/first_game.h b/include/first_game.h index 014968a1..67822f7d 100644 --- a/include/first_game.h +++ b/include/first_game.h @@ -13,8 +13,8 @@ typedef struct game_first_s { /* 0x00 */ GAME game; } GAME_FIRST; -extern void first_game_cleanup(GAME_FIRST* first_game); -extern void first_game_init(GAME_FIRST* first_game); +extern void first_game_cleanup(GAME* game); +extern void first_game_init(GAME* game); #ifdef __cplusplus } diff --git a/include/m_bgm.h b/include/m_bgm.h index 392f40d1..3c783e86 100644 --- a/include/m_bgm.h +++ b/include/m_bgm.h @@ -7,6 +7,7 @@ extern "C" { #endif +extern void mBGM_ct(); extern void mBGM_reset(); extern void mBGMPsComp_make_ps_lost_fanfare(u8 bgm_no, u16 unk); extern void mBGMPsComp_scene_mode(int scene_mode); diff --git a/include/m_card.h b/include/m_card.h index 44c393cf..738fb6b8 100644 --- a/include/m_card.h +++ b/include/m_card.h @@ -8,6 +8,9 @@ extern "C" { #endif +extern u8 mCD_GetThisLandSlotNo_code(int* player_no, int* slot_card_results); +extern void mCD_save_data_aram_malloc(); + extern void mCD_PrintErrInfo(gfxprint_t* gfxprint); extern void mCD_InitAll(); diff --git a/include/m_common_data.h b/include/m_common_data.h index 329c4752..6d7b3b43 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -216,6 +216,7 @@ extern common_data_t common_data; #define Save_GetPointer(name) (Common_GetPointer(save.save.name)) #define Save_Set(name, value) (Common_Set(save.save.name, value)) +extern void common_data_init(); extern void common_data_reinit(); #ifdef __cplusplus diff --git a/include/m_vibctl.h b/include/m_vibctl.h index 73625700..874bf34f 100644 --- a/include/m_vibctl.h +++ b/include/m_vibctl.h @@ -7,6 +7,7 @@ extern "C" { #endif +extern void mVibctl_ct(); extern void mVibctl_reset(); extern void mVibctl_init0(); diff --git a/include/sys_romcheck.h b/include/sys_romcheck.h new file mode 100644 index 00000000..cdc5be4d --- /dev/null +++ b/include/sys_romcheck.h @@ -0,0 +1,18 @@ +#ifndef SYS_ROMCHECK_H +#define SYS_ROMCHECK_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define SYS_ROMCHECK_DEBUG_ROM_VERSION 0x90 + +extern void sys_romcheck(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/rel/first_game.c b/rel/first_game.c new file mode 100644 index 00000000..0f45e49a --- /dev/null +++ b/rel/first_game.c @@ -0,0 +1,26 @@ +#include "first_game.h" + +#include "sys_romcheck.h" +#include "m_vibctl.h" +#include "m_bgm.h" +#include "m_card.h" +#include "m_common_data.h" +#include "second_game.h" +#include "Famicom/famicom.h" + +static void exit_game(GAME* game) { + famicom_setCallback_getSaveChan(&mCD_GetThisLandSlotNo_code); + mBGM_ct(); + mVibctl_ct(); + common_data_init(); + GAME_GOTO_NEXT(game, second_game, SECOND); +} + +extern void first_game_cleanup(GAME* game) { } + +extern void first_game_init(GAME* game) { + game->cleanup = &first_game_cleanup; + sys_romcheck(); + mCD_save_data_aram_malloc(); + exit_game(game); +} diff --git a/rel/sys_romcheck.c b/rel/sys_romcheck.c new file mode 100644 index 00000000..67642335 --- /dev/null +++ b/rel/sys_romcheck.c @@ -0,0 +1,10 @@ +#include "sys_romcheck.h" + +#include "dolphin/dvd.h" +#include "m_nmibuf.h" + +extern void sys_romcheck() { + if (DVDGetCurrentDiskID()->gameVersion >= SYS_ROMCHECK_DEBUG_ROM_VERSION) { + APPNMI_ZURUMODE2_SET(); + } +}