diff --git a/asm/link.s b/asm/link.s index 11018c943..9a617995f 100644 --- a/asm/link.s +++ b/asm/link.s @@ -5,57 +5,6 @@ .text - thumb_func_start HandleLinkConnection -HandleLinkConnection: @ 800B40C - push {r4,r5,lr} - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - bne _0800B45C - ldr r0, =gShouldAdvanceLinkState - ldr r1, =gSendCmd - ldr r2, =gRecvCmds - bl sub_800B638 - ldr r4, =gLinkStatus - str r0, [r4] - ldr r0, =gMain+0x2c - bl LinkMain2 - ldr r0, [r4] - movs r1, 0x80 - lsls r1, 1 - ands r0, r1 - cmp r0, 0 - beq _0800B480 - bl sub_808766C - cmp r0, 0x1 - bne _0800B480 -_0800B43E: - movs r0, 0x1 - b _0800B482 - .pool -_0800B45C: - bl sub_8010EC0 - adds r4, r0, 0 - bl sub_8010F1C - adds r5, r0, 0 - bl sub_808766C - cmp r0, 0x1 - bne _0800B480 - cmp r4, 0x1 - beq _0800B43E - bl sub_800F0B8 - cmp r0, 0 - bne _0800B43E - cmp r5, 0 - bne _0800B43E -_0800B480: - movs r0, 0 -_0800B482: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end HandleLinkConnection - thumb_func_start sub_800B488 sub_800B488: @ 800B488 push {lr} diff --git a/include/agb_flash.h b/include/agb_flash.h new file mode 100644 index 000000000..27e45e8fa --- /dev/null +++ b/include/agb_flash.h @@ -0,0 +1,12 @@ +#ifndef GUARD_AGB_FLASH_H +#define GUARD_AGB_FLASH_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations + +u16 SetFlashTimerIntr(u8 timerNum, void (**intrFunc)(void)); + +#endif //GUARD_AGB_FLASH_H diff --git a/include/crt0.h b/include/crt0.h new file mode 100644 index 000000000..3121eeaed --- /dev/null +++ b/include/crt0.h @@ -0,0 +1,11 @@ +#ifndef GUARD_CRT0_H +#define GUARD_CRT0_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations +extern u32 IntrMain[]; + +#endif //GUARD_CRT0_H diff --git a/include/intro.h b/include/intro.h new file mode 100644 index 000000000..3a0fee07f --- /dev/null +++ b/include/intro.h @@ -0,0 +1,11 @@ +#ifndef GUARD_INTRO_H +#define GUARD_INTRO_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations +void c2_copyright_1(void); + +#endif //GUARD_INTRO_H diff --git a/include/link.h b/include/link.h index 60f7a27fa..50a74e612 100644 --- a/include/link.h +++ b/include/link.h @@ -159,7 +159,6 @@ extern u16 gLinkType; extern u32 gLinkStatus; extern u16 gBlockRecvBuffer[MAX_RFU_PLAYERS][BLOCK_BUFFER_SIZE / 2]; extern u16 gSendCmd[CMD_LENGTH]; -extern u8 gShouldAdvanceLinkState; extern struct LinkPlayer gLinkPlayers[]; extern u16 word_3002910[]; extern bool8 gReceivedRemoteLinkPlayers; @@ -200,7 +199,6 @@ void LinkVSync(void); void Timer3Intr(void); void SerialCB(void); u8 GetLinkPlayerCount(void); - void sub_800E0E8(void); bool8 sub_800A520(void); void sub_800DFB4(u8, u8); @@ -210,7 +208,7 @@ void sub_800A620(void); void sub_8011BD0(void); u8 IsLinkMaster(void); void sub_800AC34(void); - +bool8 HandleLinkConnection(void); void SetLinkDebugValues(u32 seed, u32 flags); void sub_800A418(void); void SetSuppressLinkErrorMessage(bool8 flag); @@ -218,6 +216,7 @@ void sub_800B524(struct LinkPlayer *linkPlayer); u8 sub_800B2E8(void); u8 sub_800B320(void); u8 sub_800B33C(void); +void sub_800B9B8(void); extern u16 gUnknown_03003020[6]; extern u32 gLinkDebugSeed; diff --git a/include/link_rfu.h b/include/link_rfu.h index 1f29d863d..a63e07745 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -25,5 +25,10 @@ bool8 Rfu_IsMaster(void); void task_add_05_task_del_08FA224_when_no_RfuFunc(void); void sub_8010434(void); void sub_800E604(void); +void sub_800E174(void); +void sub_800E6D0(void); +bool32 sub_8010EC0(void); +bool32 sub_8010F1C(void); +bool32 sub_800F0B8(void); #endif //GUARD_LINK_RFU_H diff --git a/include/load_save.h b/include/load_save.h index 1f406bbad..92c99fd90 100644 --- a/include/load_save.h +++ b/include/load_save.h @@ -2,6 +2,8 @@ #define GUARD_LOAD_SAVE_H extern bool32 gFlashMemoryPresent; +extern struct SaveBlock2 gSaveblock2; +extern struct PokemonStorage gPokemonStorage; void ClearSav2(void); void ClearSav1(void); @@ -19,6 +21,5 @@ void LoadSerializedGame(void); void LoadPlayerBag(void); void SavePlayerBag(void); void SetSaveBlocksPointers(u16); -void MoveSaveBlocks_ResetHeap(void); #endif // GUARD_LOAD_SAVE_H diff --git a/include/m4a.h b/include/m4a.h index 316b85082..ad81028f7 100644 --- a/include/m4a.h +++ b/include/m4a.h @@ -20,5 +20,6 @@ void m4aMPlayImmInit(struct MusicPlayerInfo *mplayInfo); extern struct MusicPlayerInfo gMPlay_SE1; extern struct MusicPlayerInfo gMPlay_SE2; extern struct MusicPlayerInfo gMPlay_SE3; +extern struct SoundInfo gSoundInfo; #endif //GUARD_M4A_H diff --git a/include/overworld.h b/include/overworld.h index 45723c3e9..11aadaf0e 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -66,4 +66,8 @@ void c2_load_new_map(void); void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); void mapldr_default(void); +bool32 sub_80875C8(void); +bool32 sub_8087634(void); +bool32 sub_808766C(void); + #endif //GUARD_ROM4_H diff --git a/src/link.c b/src/link.c index af31b37f6..ecaeafd97 100644 --- a/src/link.c +++ b/src/link.c @@ -152,6 +152,7 @@ static void sub_800AE5C(void); static void sub_800AEB4(void); static void sub_800B1A0(void); u8 sub_800B2F8(void); +u32 sub_800B638(bool8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[8]); void sub_800B4A4(void); void DisableSerial(void); void EnableSerial(void); @@ -1812,3 +1813,32 @@ void sub_800B3A4(u8 who) SetMainCallback2(CB2_LinkError); } } + +bool8 HandleLinkConnection(void) +{ + bool32 r4; + bool32 r5; + + if (gWirelessCommType == 0) + { + gLinkStatus = sub_800B638(&gShouldAdvanceLinkState, gSendCmd, gRecvCmds); + LinkMain2(&gMain.heldKeys); + if ((gLinkStatus & LINK_STAT_RECEIVED_NOTHING) && sub_808766C() == TRUE) + { + return TRUE; + } + } + else + { + r4 = sub_8010EC0(); + r5 = sub_8010F1C(); + if (sub_808766C() == TRUE) + { + if (r4 == TRUE || sub_800F0B8() || r5) + { + return TRUE; + } + } + } + return FALSE; +} diff --git a/src/main.c b/src/main.c index c2baa23af..00dd99dc3 100644 --- a/src/main.c +++ b/src/main.c @@ -1,50 +1,30 @@ #include "global.h" -#include "main.h" +#include "crt0.h" +#include "malloc.h" #include "link.h" +#include "link_rfu.h" +#include "librfu.h" #include "m4a.h" +#include "bg.h" #include "rtc.h" +#include "unknown_task.h" #include "rng.h" +#include "overworld.h" +#include "play_time.h" #include "dma3.h" #include "gba/flash_internal.h" +#include "load_save.h" +#include "gpu_regs.h" +#include "agb_flash.h" +#include "sound.h" #include "battle.h" +#include "battle_controllers.h" +#include "text.h" +#include "intro.h" +#include "main.h" -extern u16 GetGpuReg(u8); -extern void SetGpuReg(u8, u16); -extern void LinkVSync(void); -extern void sub_800E174(void); -extern void sub_800B9B8(void); -extern void InitGpuRegManager(void); -extern void sub_800E6D0(void); -extern void CheckForFlashMemory(void); -extern void InitMapMusic(void); -extern void ResetBgs(void); -extern void SetDefaultFontsPointer(void); -extern void InitHeap(void *heapStart, u32 heapSize); // malloc.h -extern void rfu_REQ_stopMode(void); -extern void rfu_waitREQComplete(void); -extern bool32 sub_8087634(void); -extern bool32 sub_80875C8(void); -extern void ClearSpriteCopyRequests(void); -extern void PlayTimeCounter_Update(void); -extern void MapMusicMain(void); -extern void EnableInterrupts(u16); -extern void sub_8033648(void); -extern u16 SetFlashTimerIntr(u8 timerNum, void (**intrFunc)(void)); -extern void remove_some_task(void); - -extern struct SoundInfo gSoundInfo; -extern u32 gFlashMemoryPresent; -extern u32 IntrMain[]; -extern u8 gHeap[]; -extern struct SaveBlock2 gSaveblock2; -extern struct PokemonStorage gPokemonStorage; -extern u32 gBattleTypeFlags; extern u32 *gUnknown_0203CF5C; -void Timer3Intr(void); -bool8 HandleLinkConnection(void); -void c2_copyright_1(void); - static void VBlankIntr(void); static void HBlankIntr(void); static void VCountIntr(void);