Decomp NitroMain

This commit is contained in:
PikalaxALT 2022-02-01 16:57:59 -05:00
parent 92a2071677
commit 806c0564ac
21 changed files with 227 additions and 200 deletions

View File

@ -3,207 +3,11 @@
.public ov60_021EB030
.public ov36_021E5C04
.bss
gBacklightTop:
.space 0x4
.public gBacklightTop
.public _02111864
_02111864:
.space 0x4
_02111868:
.space 0x1C
.public _02111868
.text
; Entry point
thumb_func_start NitroMain
NitroMain: ; 0x02000CA4
push {r3, r4, r5, r6, r7, lr}
bl InitSystemForTheGame
bl InitGraphicMemory
bl InitKeypadAndTouchpad
mov r0, #0
bl sub_0201A4B0
ldr r0, _02000E48 ; =gBacklightTop
mov r1, #0
bl PM_GetBackLight
bl sub_02026E30
bl GF_InitRTCWork
bl Main_ResetOverlayManager
bl sub_02002CA8
mov r0, #0
mov r1, #3
bl sub_02002CEC
mov r0, #1
mov r1, #3
bl sub_02002CEC
mov r0, #3
add r1, r0, #0
bl sub_02002CEC
mov r1, #0
; Note to decompiler: the -ipa file switch causes most file-local symbol access to be compiled relative to the top symbol in that section. This is buggy in practice.
ldr r0, _02000E4C ; =_0211868-8
mvn r1, r1
str r1, [r0, #0x18]
bl SaveBlock2_new
ldr r1, _02000E4C ; =_0211868-8
str r0, [r1, #0x20]
bl sub_02005D00
ldr r0, _02000E4C ; =_0211868-8
ldr r0, [r0, #0x20]
bl Sav2_Chatot_get
add r4, r0, #0
ldr r0, _02000E4C ; =_0211868-8
ldr r0, [r0, #0x20]
bl Sav2_PlayerData_GetOptionsAddr
add r1, r0, #0
add r0, r4, #0
bl InitSoundData
bl Init_Timer3
mov r0, #3
bl sub_02039FFC
cmp r0, #3
bne _02000D2C
mov r0, #3
mov r1, #0
bl ShowWFCUserInfoWarning
_02000D2C:
ldr r0, _02000E4C ; =_0211868-8
ldr r0, [r0, #0x20]
bl sub_020274D0
cmp r0, #0
bne _02000D40
mov r0, #0
bl ShowSaveDataReadError
b _02000D82
_02000D40:
; static inline int OS_GetResetParameter();
ldr r0, _02000E50 ; =0x027FFC20
ldr r0, [r0]
cmp r0, #0
beq _02000D4E
cmp r0, #1
beq _02000D5E
b _02000D7E
_02000D4E:
; Title Demo
ldr r0, _02000E4C ; =_0211868-8
mov r1, #0
str r1, [r0, #0x1c]
ldr r0, _02000E54 ; =SDK_OVERLAY_OVY_60_ID
ldr r1, _02000E58 ; =ov60_021EB030
bl RegisterMainOverlay
b _02000D82
_02000D5E:
; Reset transition?
mov r0, #0
add r1, r0, #0
bl sub_0200FBF4
mov r0, #1
mov r1, #0
bl sub_0200FBF4
ldr r0, _02000E4C ; =_0211868-8
mov r1, #1
str r1, [r0, #0x1c]
ldr r0, _02000E5C ; =SDK_OVERLAY_OVY_36_ID
ldr r1, _02000E60 ; =ov36_021E5C04
bl RegisterMainOverlay
b _02000D82
_02000D7E:
bl GF_AssertFail
_02000D82:
ldr r0, _02000E64 ; =gSystem
mov r1, #1
str r1, [r0, #0x70]
mov r1, #0
str r1, [r0, #0x30]
bl InitializeMainRNG
bl sub_0200B528
bl sub_02018380
ldr r0, _02000E4C ; =_0211864-4
mov r1, #0
str r1, [r0, #4]
bl OS_InitTick
mov r7, #0xc3
ldr r6, _02000E68 ; =gSystem + 0x60
ldr r4, _02000E64 ; =gSystem
mov r5, #0
lsl r7, r7, #2
_02000DAC:
bl sub_02000F60
bl HandleDSLidAction
bl ReadKeypadAndTouchpad
mov r0, #0xc3
ldr r1, [r4, #0x38]
lsl r0, r0, #2
and r0, r1
cmp r0, r7
bne _02000DD0
ldrb r0, [r6, #0xc]
cmp r0, #0
bne _02000DD0
mov r0, #0
bl DoSoftReset
_02000DD0:
bl sub_02036144
cmp r0, #0
beq _02000E08
bl sub_02000F60
bl OS_GetTick
bl Main_RunOverlayManager
bl OS_GetTick
ldr r0, [r4, #0x18]
bl sub_0201F880
ldr r0, [r4, #0x24]
bl sub_0201F880
ldr r0, [r4, #0x30]
cmp r0, #0
bne _02000E08
mov r0, #1
add r1, r0, #0
bl OS_WaitIrq
ldr r0, [r4, #0x2c]
add r0, r0, #1
str r0, [r4, #0x2c]
_02000E08:
bl GF_RTC_UpdateOnFrame
bl sub_020183B0
bl sub_02026E60
ldr r0, [r4, #0x24]
bl sub_0201F880
mov r0, #1
add r1, r0, #0
bl OS_WaitIrq
ldr r0, [r4, #0x2c]
add r0, r0, #1
str r0, [r4, #0x2c]
str r5, [r4, #0x30]
bl sub_0200B594
bl sub_0200FB2C
ldr r1, [r4]
cmp r1, #0
beq _02000E3C
ldr r0, [r4, #4]
blx r1
_02000E3C:
bl DoSoundUpdateFrame
ldr r0, [r4, #0x20]
bl sub_0201F880
b _02000DAC
.balign 4, 0
_02000E48: .word gBacklightTop
_02000E4C: .word gBacklightTop
_02000E50: .word 0x027FFC20
_02000E54: .word SDK_OVERLAY_OVY_60_ID
_02000E58: .word ov60_021EB030
_02000E5C: .word SDK_OVERLAY_OVY_36_ID
_02000E60: .word ov36_021E5C04
_02000E64: .word gSystem
_02000E68: .word gSystem + 0x60
thumb_func_end NitroMain
thumb_func_start Main_ResetOverlayManager
Main_ResetOverlayManager: ; 0x02000E6C
mov r2, #0

View File

@ -4,5 +4,7 @@
typedef u8 FontID;
u32 FontI_GetGlyphWidth(FontID fontId, u16 character);
void sub_02002CA8(void);
void sub_02002CEC(int a0, HeapID heapId);
#endif //POKEHEARTGOLD_FONT_H

View File

@ -2,9 +2,17 @@
#define POKEHEARTGOLD_MAIN_H
#include "overlay_manager.h"
#include "save.h"
struct UnkStruct_02111868_sub {
int unk_00;
u32 unk_04;
SAVEDATA *savedata;
};
void Main_ResetOverlayManager(void);
void RegisterMainOverlay(FSOverlayID overlayId, const OVY_MGR_TEMPLATE *template);
void InitializeMainRNG(void);
void HandleDSLidAction(void);
#endif //POKEHEARTGOLD_MAIN_H

10
include/sav_chatot.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef POKEHEARTGOLD_SAV_CHATOT_H
#define POKEHEARTGOLD_SAV_CHATOT_H
#include "save.h"
typedef struct SOUND_CHATOT SOUND_CHATOT;
SOUND_CHATOT *Sav2_Chatot_get(SAVEDATA *saveData);
#endif //POKEHEARTGOLD_SAV_CHATOT_H

View File

@ -49,10 +49,12 @@
#ifndef PM_ASM
typedef struct SaveBlock2 SAVEDATA;
SAVEDATA *SaveBlock2_new(void);
void *SavArray_get(SAVEDATA *save, int idx);
const void *SavArray_const_get(const SAVEDATA *save, int idx);
void SaveSubstruct_UpdateCRC(int idx);
BOOL SaveSubstruct_AssertCRC(int idx);
BOOL sub_020274D0(SAVEDATA *save);
#endif //PM_ASM
#endif //POKEHEARTGOLD_SAVE_H

View File

@ -0,0 +1,6 @@
#ifndef POKEHEARTGOLD_SAVE_DATA_READ_ERROR_H
#define POKEHEARTGOLD_SAVE_DATA_READ_ERROR_H
void ShowSaveDataReadError(int a0);
#endif //POKEHEARTGOLD_SAVE_DATA_READ_ERROR_H

6
include/sound_02004A44.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef POKEHEARTGOLD_SOUND_02004A44_H
#define POKEHEARTGOLD_SOUND_02004A44_H
void sub_02005D00(void);
#endif //POKEHEARTGOLD_SOUND_02004A44_H

View File

@ -1,7 +1,7 @@
#ifndef POKEHEARTGOLD_SOUND_CHATOT_H
#define POKEHEARTGOLD_SOUND_CHATOT_H
typedef struct SOUND_CHATOT SOUND_CHATOT;
#include "sav_chatot.h"
void ChatotSoundMain(void);
extern void PlayCryEx(u32, u16, u32, u32, u32, u8);

View File

@ -35,9 +35,16 @@ struct System {
u8 unk67;
u8 softResetDisabled;
u8 padding_69[3]; // nice
s32 unk6C;
u8 unk6C;
int unk70;
};
extern struct System gSystem;
void InitSystemForTheGame(void);
void InitGraphicMemory(void);
void InitKeypadAndTouchpad(void);
void sub_0201A4B0(int a0);
void ReadKeypadAndTouchpad(void);
#endif //POKEHEARTGOLD_SYSTEM_H

6
include/timer_3.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef POKEHEARTGOLD_TIMER_3_H
#define POKEHEARTGOLD_TIMER_3_H
void Init_Timer3(void);
#endif //POKEHEARTGOLD_TIMER_3_H

7
include/unk_0200B150.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef POKEHEARTGOLD_UNK_0200B150_H
#define POKEHEARTGOLD_UNK_0200B150_H
void sub_0200B528(void);
void sub_0200B594(void);
#endif //POKEHEARTGOLD_UNK_0200B150_H

7
include/unk_0200FA24.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef POKEHEARTGOLD_UNK_0200FA24_H
#define POKEHEARTGOLD_UNK_0200FA24_H
void sub_0200FBF4(int a0, int a1);
void sub_0200FB2C(void);
#endif //POKEHEARTGOLD_UNK_0200FA24_H

7
include/unk_02018380.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef POKEHEARTGOLD_UNK_02018380_H
#define POKEHEARTGOLD_UNK_02018380_H
void sub_02018380(void);
void sub_020183B0(void);
#endif //POKEHEARTGOLD_UNK_02018380_H

6
include/unk_0201F79C.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef POKEHEARTGOLD_UNK_0201F79C_H
#define POKEHEARTGOLD_UNK_0201F79C_H
void sub_0201F880(void *a0);
#endif //POKEHEARTGOLD_UNK_0201F79C_H

7
include/unk_02026E30.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef POKEHEARTGOLD_UNK_02026E30_H
#define POKEHEARTGOLD_UNK_02026E30_H
void sub_02026E30(void);
void sub_02026E60(void);
#endif //POKEHEARTGOLD_UNK_02026E30_H

6
include/unk_02035900.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef POKEHEARTGOLD_UNK_02035900_H
#define POKEHEARTGOLD_UNK_02035900_H
BOOL sub_02036144(void);
#endif //POKEHEARTGOLD_UNK_02035900_H

View File

@ -2,5 +2,6 @@
#define POKEHEARTGOLD_UNK_02037C94_H
BOOL sub_02037D78(void);
int sub_02039FFC(int a0);
#endif //POKEHEARTGOLD_UNK_02037C94_H

View File

@ -0,0 +1,6 @@
#ifndef POKEHEARTGOLD_WFC_USER_INFO_WARNING_H
#define POKEHEARTGOLD_WFC_USER_INFO_WARNING_H
void ShowWFCUserInfoWarning(int a0, int a1);
#endif //POKEHEARTGOLD_WFC_USER_INFO_WARNING_H

View File

@ -16,4 +16,8 @@ void OS_ResetSystem(u32 parameter);
void OS_ResetSystem(void);
#endif
static inline u32 OS_GetResetParameter(void) {
return *(u32 *)HW_RESET_PARAMETER_BUF;
}
#endif //NITRO_OS_RESET_H

View File

@ -11,6 +11,7 @@ Static main
StackSize 0 2048
Object pm_version.o
Object main.o
Object main_s.o
Object list_menu.o
Object unk_02001AF4.o
Object string_util.o

124
src/main.c Normal file
View File

@ -0,0 +1,124 @@
#include "main.h"
#include "system.h"
#include "gf_rtc.h"
#include "sound.h"
#include "sound_02004A44.h"
#include "player_data.h"
#include "unk_02026E30.h"
#include "font.h"
#include "timer_3.h"
#include "unk_02037C94.h"
#include "wfc_user_info_warning.h"
#include "save_data_read_error.h"
#include "unk_0200FA24.h"
#include "unk_0200B150.h"
#include "unk_02018380.h"
#include "unk_02035900.h"
#include "unk_0201F79C.h"
FS_EXTERN_OVERLAY(OVY_60);
FS_EXTERN_OVERLAY(OVY_36);
extern const OVY_MGR_TEMPLATE ov60_021EB030;
extern const OVY_MGR_TEMPLATE ov36_021E5C04;
struct UnkStruct_02111868 {
FSOverlayID mainOverlayId;
OVY_MANAGER *overlayManager;
FSOverlayID queuedMainOverlayId;
const OVY_MGR_TEMPLATE *queuedMainOverlayTemplate;
struct UnkStruct_02111868_sub unk_10;
};
int _02111864;
PMBackLightSwitch gBacklightTop;
struct UnkStruct_02111868 _02111868;
void sub_02000F60(void);
void DoSoftReset(int a0);
void Main_RunOverlayManager(void);
void NitroMain(void) {
InitSystemForTheGame();
InitGraphicMemory();
InitKeypadAndTouchpad();
sub_0201A4B0(0);
PM_GetBackLight(&gBacklightTop, NULL);
sub_02026E30();
GF_InitRTCWork();
Main_ResetOverlayManager();
sub_02002CA8();
sub_02002CEC(0, 3);
sub_02002CEC(1, 3);
sub_02002CEC(3, 3);
_02111868.unk_10.unk_00 = -1;
_02111868.unk_10.savedata = SaveBlock2_new();
sub_02005D00();
InitSoundData(Sav2_Chatot_get(_02111868.unk_10.savedata), Sav2_PlayerData_GetOptionsAddr(_02111868.unk_10.savedata));
Init_Timer3();
if (sub_02039FFC(3) == 3) {
ShowWFCUserInfoWarning(3, 0);
}
if (!sub_020274D0(_02111868.unk_10.savedata)) {
ShowSaveDataReadError(0);
} else {
switch (OS_GetResetParameter()) {
case 0:
_02111868.unk_10.unk_04 = 0;
RegisterMainOverlay(FS_OVERLAY_ID(OVY_60), &ov60_021EB030);
break;
case 1:
sub_0200FBF4(0, 0);
sub_0200FBF4(1, 0);
_02111868.unk_10.unk_04 = 1;
RegisterMainOverlay(FS_OVERLAY_ID(OVY_36), &ov36_021E5C04);
break;
default:
GF_ASSERT(0);
break;
}
}
gSystem.unk70 = 1;
gSystem.unk30 = 0;
InitializeMainRNG();
sub_0200B528();
sub_02018380();
_02111864 = 0;
OS_InitTick();
while (1) {
sub_02000F60();
HandleDSLidAction();
ReadKeypadAndTouchpad();
if ((gSystem.heldKeysRaw & (PAD_BUTTON_START | PAD_BUTTON_SELECT | PAD_BUTTON_L | PAD_BUTTON_R)) == (PAD_BUTTON_START | PAD_BUTTON_SELECT | PAD_BUTTON_L | PAD_BUTTON_R)) {
if (!gSystem.unk6C) {
DoSoftReset(0); // no return
}
}
if (sub_02036144()) {
sub_02000F60();
OS_GetTick();
Main_RunOverlayManager();
OS_GetTick();
sub_0201F880(gSystem.unk18);
sub_0201F880(gSystem.unk24);
if (!gSystem.unk30) {
OS_WaitIrq(TRUE, OS_IE_VBLANK);
gSystem.unk2C++;
}
}
GF_RTC_UpdateOnFrame();
sub_020183B0();
sub_02026E60();
sub_0201F880(gSystem.unk24);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
gSystem.unk2C++;
gSystem.unk30 = 0;
sub_0200B594();
sub_0200FB2C();
if (gSystem.vBlankIntr != NULL) {
gSystem.vBlankIntr(gSystem.vBlankIntrArg);
}
DoSoundUpdateFrame();
sub_0201F880(gSystem.unk20);
}
}