diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/librfu_sio32id.c (renamed from src/librfu_s32id.c) | 68 | ||||
-rw-r--r-- | src/main.c | 57 | ||||
-rw-r--r-- | src/vs_seeker.c | 261 |
3 files changed, 74 insertions, 312 deletions
diff --git a/src/librfu_s32id.c b/src/librfu_sio32id.c index ed51dcd12..fc5701986 100644 --- a/src/librfu_s32id.c +++ b/src/librfu_sio32id.c @@ -4,7 +4,7 @@ static void Sio32IDIntr(void); static void Sio32IDInit(void); static s32 Sio32IDMain(void); -struct RfuS32Id gRfuS32Id; +struct RfuSIO32Id gRfuSIO32Id; static const u16 Sio32ConnectionData[] = { 0x494e, 0x544e, 0x4e45, 0x4f44 }; // NINTENDO static const char Sio32IDLib_Var[] = "Sio32ID_030820"; @@ -52,7 +52,7 @@ static void Sio32IDInit(void) REG_RCNT = 0; REG_SIOCNT = SIO_32BIT_MODE; REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE; - CpuFill32(0, &gRfuS32Id, sizeof(struct RfuS32Id)); + CpuFill32(0, &gRfuSIO32Id, sizeof(struct RfuSIO32Id)); REG_IF = INTR_FLAG_SERIAL; } @@ -60,39 +60,39 @@ static s32 Sio32IDMain(void) { u8 r12; - switch (r12 = gRfuS32Id.unk1) + switch (r12 = gRfuSIO32Id.unk1) { case 0: - gRfuS32Id.unk0 = 1; + gRfuSIO32Id.unk0 = 1; REG_SIOCNT |= SIO_38400_BPS; REG_IME = r12; REG_IE |= INTR_FLAG_SERIAL; REG_IME = 1; - gRfuS32Id.unk1 = 1; + gRfuSIO32Id.unk1 = 1; *(vu8 *)®_SIOCNT |= SIO_ENABLE; break; case 1: - if (gRfuS32Id.unkA == 0) + if (gRfuSIO32Id.unkA == 0) { - if (gRfuS32Id.unk0 == 1) + if (gRfuSIO32Id.unk0 == 1) { - if (gRfuS32Id.unk2 == 0) + if (gRfuSIO32Id.unk2 == 0) { - REG_IME = gRfuS32Id.unk2; + REG_IME = gRfuSIO32Id.unk2; REG_SIOCNT |= SIO_ENABLE; REG_IME = r12; } } - else if (gRfuS32Id.unk4 != 0x8001 && !gRfuS32Id.unk2) + else if (gRfuSIO32Id.unk4 != 0x8001 && !gRfuSIO32Id.unk2) { - REG_IME = gRfuS32Id.unk2; + REG_IME = gRfuSIO32Id.unk2; REG_IE &= ~INTR_FLAG_SERIAL; REG_IME = r12; - REG_SIOCNT = gRfuS32Id.unk2; + REG_SIOCNT = gRfuSIO32Id.unk2; REG_SIOCNT = SIO_32BIT_MODE; REG_IF = INTR_FLAG_SERIAL; REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE; - REG_IME = gRfuS32Id.unk2; + REG_IME = gRfuSIO32Id.unk2; REG_IE |= INTR_FLAG_SERIAL; REG_IME = r12; } @@ -100,11 +100,11 @@ static s32 Sio32IDMain(void) } else { - gRfuS32Id.unk1 = 2; + gRfuSIO32Id.unk1 = 2; // fallthrough } default: - return gRfuS32Id.unkA; + return gRfuSIO32Id.unkA; } return 0; } @@ -122,43 +122,43 @@ static void Sio32IDIntr(void) #endif r5 = REG_SIODATA32; - if (gRfuS32Id.unk0 != 1) + if (gRfuSIO32Id.unk0 != 1) REG_SIOCNT |= SIO_ENABLE; - r1 = 16 * gRfuS32Id.unk0; // to handle side effect of inline asm + r1 = 16 * gRfuSIO32Id.unk0; // to handle side effect of inline asm r1 = (r5 << r1) >> 16; - r5 = (r5 << 16 * (1 - gRfuS32Id.unk0)) >> 16; - if (gRfuS32Id.unkA == 0) + r5 = (r5 << 16 * (1 - gRfuSIO32Id.unk0)) >> 16; + if (gRfuSIO32Id.unkA == 0) { - if (r1 == gRfuS32Id.unk6) + if (r1 == gRfuSIO32Id.unk6) { - if (gRfuS32Id.unk2 > 3) + if (gRfuSIO32Id.unk2 > 3) { - gRfuS32Id.unkA = r5; + gRfuSIO32Id.unkA = r5; } - else if (r1 == (u16)~gRfuS32Id.unk4) + else if (r1 == (u16)~gRfuSIO32Id.unk4) { - r0_ = ~gRfuS32Id.unk6; + r0_ = ~gRfuSIO32Id.unk6; if (r5 == r0_) - ++gRfuS32Id.unk2; + ++gRfuSIO32Id.unk2; } } else { - gRfuS32Id.unk2 = gRfuS32Id.unkA; + gRfuSIO32Id.unk2 = gRfuSIO32Id.unkA; } } - if (gRfuS32Id.unk2 < 4) - gRfuS32Id.unk4 = *(gRfuS32Id.unk2 + Sio32ConnectionData); + if (gRfuSIO32Id.unk2 < 4) + gRfuSIO32Id.unk4 = *(gRfuSIO32Id.unk2 + Sio32ConnectionData); else - gRfuS32Id.unk4 = 0x8001; - gRfuS32Id.unk6 = ~r5; - REG_SIODATA32 = (gRfuS32Id.unk4 << 16 * (1 - gRfuS32Id.unk0)) - + (gRfuS32Id.unk6 << 16 * gRfuS32Id.unk0); - if (gRfuS32Id.unk0 == 1 && (gRfuS32Id.unk2 || r5 == 0x494E)) + gRfuSIO32Id.unk4 = 0x8001; + gRfuSIO32Id.unk6 = ~r5; + REG_SIODATA32 = (gRfuSIO32Id.unk4 << 16 * (1 - gRfuSIO32Id.unk0)) + + (gRfuSIO32Id.unk6 << 16 * gRfuSIO32Id.unk0); + if (gRfuSIO32Id.unk0 == 1 && (gRfuSIO32Id.unk2 || r5 == 0x494E)) { for (r0 = 0; r0 < 600; ++r0) ; - if (gRfuS32Id.unkA == 0) + if (gRfuSIO32Id.unkA == 0) REG_SIOCNT |= SIO_ENABLE; } } diff --git a/src/main.c b/src/main.c index 60f762a62..5d2db95be 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,9 @@ #include "global.h" +#include "bg.h" +#include "gpu_regs.h" +#include "link.h" +#include "link_rfu.h" +#include "load_save.h" #include "main.h" #include "m4a.h" #include "random.h" @@ -6,48 +11,20 @@ #include "gba/flash_internal.h" #include "battle.h" #include "help_system.h" +#include "sound.h" +#include "new_menu_helpers.h" +#include "malloc.h" +#include "overworld.h" +#include "sprite.h" +#include "play_time.h" +#include "pokemon.h" +#include "intro.h" +#include "battle_controllers.h" +#include "scanline_effect.h" +#include "save_failed_screen.h" +#include "battle.h" -extern u16 GetGpuReg(u8); -extern void SetGpuReg(u8, u16); -extern void RFUVSync(void); -extern void LinkVSync(void); -extern void sub_80FCF34(void); -extern void LinkVSync(void); -extern void InitGpuRegManager(void); -extern void InitRFU(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_80582E0(void); -extern bool32 sub_8058274(void); -extern void ClearSpriteCopyRequests(void); -extern void PlayTimeCounter_Update(void); -extern void MapMusicMain(void); -extern void EnableInterrupts(u16); -extern void sub_800DD28(void); -extern u16 SetFlashTimerIntr(u8 timerNum, void (**intrFunc)(void)); -extern void ScanlineEffect_Stop(void); -extern void sub_80F50F4(void); -extern bool32 sub_80F5118(void); - -extern struct SoundInfo gSoundInfo; -extern u32 gFlashMemoryPresent; extern u32 intr_main[]; -extern u8 gHeap[]; -extern struct SaveBlock1 gSaveBlock1; -extern struct SaveBlock2 gSaveBlock2; -extern struct PokemonStorage gPokemonStorage; -extern u32 gBattleTypeFlags; -extern u8 gUnknown_03002748; -extern u32 *gUnknown_0203CF5C; - -void Timer3Intr(void); -bool8 HandleLinkConnection(void); -void c2_copyright_1(void); static void VBlankIntr(void); static void HBlankIntr(void); diff --git a/src/vs_seeker.c b/src/vs_seeker.c index 6c4dba398..87d15488a 100644 --- a/src/vs_seeker.c +++ b/src/vs_seeker.c @@ -845,13 +845,17 @@ u8 CanUseVsSeeker(void) } } -// Nonmatching due to register roulette -#ifdef NONMATCHING static u8 GetVsSeekerResponseInArea(const VsSeekerData * a0) { u16 r8 = 0; u8 sp0 = 0; s32 vsSeekerIdx; + u8 *r2; +#ifndef NONMATCHING + register u32 r3 asm("r3"); + register s32 r0_ asm("r0"); + asm("":::"r10", "r8", "r6", "r4"); +#endif for (vsSeekerIdx = 0; sVsSeeker->trainerInfo[vsSeekerIdx].localId != 0xFF; vsSeekerIdx++) { @@ -861,6 +865,7 @@ static u8 GetVsSeekerResponseInArea(const VsSeekerData * a0) if (!HasTrainerBeenFought(r8)) { StartTrainerObjectMovementScript(&sVsSeeker->trainerInfo[vsSeekerIdx], gUnknown_8453F60); + sVsSeeker->trainerInfo[vsSeekerIdx].trainerIdx += 0; sVsSeeker->trainerHasNotYetBeenFought = 1; } else @@ -869,7 +874,15 @@ static u8 GetVsSeekerResponseInArea(const VsSeekerData * a0) if (r7 == 0) { StartTrainerObjectMovementScript(&sVsSeeker->trainerInfo[vsSeekerIdx], sMovementScript_TrainerNoRematch); + #ifdef NONMATCHING sVsSeeker->trainerDoesNotWantRematch = 1; + #else + r2 = (u8 *)sVsSeeker; + r3 = 0x431; + asm("":::"r1"); + r2 = &r2[r3]; + *(r2) |= 2; + #endif } else { @@ -882,7 +895,15 @@ static u8 GetVsSeekerResponseInArea(const VsSeekerData * a0) if (rval < 30) { StartTrainerObjectMovementScript(&sVsSeeker->trainerInfo[vsSeekerIdx], sMovementScript_TrainerNoRematch); + #ifdef NONMATCHING sVsSeeker->trainerDoesNotWantRematch = 1; + #else + r2 = (u8 *)sVsSeeker; + r0_ = 0x431; + asm("":::"r1"); + r2 = &r2[r0_]; + *(r2) |= 2; + #endif } else { @@ -910,242 +931,6 @@ static u8 GetVsSeekerResponseInArea(const VsSeekerData * a0) return 1; return 0; } -#else -NAKED -static u8 GetVsSeekerResponseInArea(const VsSeekerData * a0) -{ - asm_unified("\tpush {r4-r7,lr}\n" - "\tmov r7, r10\n" - "\tmov r6, r9\n" - "\tmov r5, r8\n" - "\tpush {r5-r7}\n" - "\tsub sp, 0x8\n" - "\tstr r0, [sp, 0x4]\n" - "\tmovs r0, 0\n" - "\tmov r8, r0\n" - "\tmov r0, sp\n" - "\tmov r1, r8\n" - "\tstrb r1, [r0]\n" - "\tmovs r2, 0\n" - "\tmov r9, r2\n" - "\tldr r4, _0810CA14 @ =sVsSeeker\n" - "\tldr r0, [r4]\n" - "\tldrb r0, [r0, 0x6]\n" - "\tcmp r0, 0xFF\n" - "\tbne _0810C9D0\n" - "\tb _0810CB2C\n" - "_0810C9D0:\n" - "\tadds r6, r4, 0\n" - "\tmovs r3, 0x86\n" - "\tlsls r3, 3\n" - "\tmov r10, r3\n" - "\tmovs r5, 0\n" - "_0810C9DA:\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tbl IsTrainerVisibleOnScreen\n" - "\tlsls r0, 24\n" - "\tlsrs r0, 24\n" - "\tcmp r0, 0x1\n" - "\tbeq _0810C9EC\n" - "\tb _0810CB18\n" - "_0810C9EC:\n" - "\tldr r0, [r4]\n" - "\tadds r0, r5\n" - "\tldrh r0, [r0, 0x4]\n" - "\tmov r8, r0\n" - "\tbl HasTrainerBeenFought\n" - "\tlsls r0, 24\n" - "\tcmp r0, 0\n" - "\tbne _0810CA20\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tldr r1, _0810CA18 @ =gUnknown_8453F60\n" - "\tbl StartTrainerObjectMovementScript\n" - "\tldr r2, [r6]\n" - "\tldr r0, _0810CA1C @ =0x00000431\n" - "\tadds r2, r0\n" - "\tldrb r0, [r2]\n" - "\tmovs r1, 0x1\n" - "\tb _0810CB14\n" - "\t.align 2, 0\n" - "_0810CA14: .4byte sVsSeeker\n" - "_0810CA18: .4byte gUnknown_8453F60\n" - "_0810CA1C: .4byte 0x00000431\n" - "_0810CA20:\n" - "\tldr r0, [sp, 0x4]\n" - "\tmov r1, r8\n" - "\tmov r2, sp\n" - "\tbl GetNextAvailableRematchTrainer\n" - "\tlsls r0, 24\n" - "\tlsrs r7, r0, 24\n" - "\tcmp r7, 0\n" - "\tbne _0810CA50\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tldr r1, _0810CA48 @ =sMovementScript_TrainerNoRematch\n" - "\tbl StartTrainerObjectMovementScript\n" - "\tldr r2, [r6]\n" - "\tldr r3, _0810CA4C @ =0x00000431\n" - "\tadds r2, r3\n" - "\tldrb r0, [r2]\n" - "\tmovs r1, 0x2\n" - "\tb _0810CB14\n" - "\t.align 2, 0\n" - "_0810CA48: .4byte sMovementScript_TrainerNoRematch\n" - "_0810CA4C: .4byte 0x00000431\n" - "_0810CA50:\n" - "\tbl Random\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tmovs r1, 0x64\n" - "\tbl __umodsi3\n" - "\tlsls r0, 16\n" - "\tlsrs r4, r0, 16\n" - "\tmov r0, r9\n" - "\tmov r1, r8\n" - "\tbl GetCurVsSeekerResponse\n" - "\tlsls r0, 24\n" - "\tlsrs r0, 24\n" - "\tcmp r0, 0x2\n" - "\tbne _0810CA76\n" - "\tmovs r4, 0x64\n" - "\tb _0810CA7C\n" - "_0810CA76:\n" - "\tcmp r0, 0x1\n" - "\tbne _0810CA7C\n" - "\tmovs r4, 0\n" - "_0810CA7C:\n" - "\tcmp r4, 0x1D\n" - "\tbhi _0810CAA0\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tldr r1, _0810CA98 @ =sMovementScript_TrainerNoRematch\n" - "\tbl StartTrainerObjectMovementScript\n" - "\tldr r2, [r6]\n" - "\tldr r0, _0810CA9C @ =0x00000431\n" - "\tadds r2, r0\n" - "\tldrb r0, [r2]\n" - "\tmovs r1, 0x2\n" - "\tb _0810CB14\n" - "\t.align 2, 0\n" - "_0810CA98: .4byte sMovementScript_TrainerNoRematch\n" - "_0810CA9C: .4byte 0x00000431\n" - "_0810CAA0:\n" - "\tldr r0, _0810CB54 @ =gSaveBlock1Ptr\n" - "\tldr r1, [r0]\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tldr r2, _0810CB58 @ =0x0000063a\n" - "\tadds r1, r2\n" - "\tldrb r0, [r0, 0x6]\n" - "\tadds r1, r0\n" - "\tstrb r7, [r1]\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tldrb r1, [r0, 0x7]\n" - "\tlsls r0, r1, 3\n" - "\tadds r0, r1\n" - "\tlsls r0, 2\n" - "\tldr r1, _0810CB5C @ =gObjectEvents\n" - "\tadds r0, r1\n" - "\tbl npc_coords_shift_still\n" - "\tldr r0, [r6]\n" - "\tadds r0, r5\n" - "\tldr r1, _0810CB60 @ =gUnknown_8453F64\n" - "\tbl StartTrainerObjectMovementScript\n" - "\tldr r2, [r6]\n" - "\tmov r3, r10\n" - "\tadds r0, r2, r3\n" - "\tldrb r1, [r0]\n" - "\tlsls r1, 1\n" - "\tmovs r3, 0x80\n" - "\tlsls r3, 3\n" - "\tadds r0, r2, r3\n" - "\tadds r0, r1\n" - "\tmov r1, r8\n" - "\tstrh r1, [r0]\n" - "\tadds r2, r5\n" - "\tldrb r0, [r2, 0xC]\n" - "\tbl GetRunningBehaviorFromGraphicsId\n" - "\tldr r1, [r6]\n" - "\tmov r3, r10\n" - "\tadds r2, r1, r3\n" - "\tmovs r3, 0x84\n" - "\tlsls r3, 3\n" - "\tadds r1, r3\n" - "\tldrb r2, [r2]\n" - "\tadds r1, r2\n" - "\tstrb r0, [r1]\n" - "\tldr r1, [r6]\n" - "\tadd r1, r10\n" - "\tldrb r0, [r1]\n" - "\tadds r0, 0x1\n" - "\tstrb r0, [r1]\n" - "\tldr r2, [r6]\n" - "\tldr r0, _0810CB64 @ =0x00000431\n" - "\tadds r2, r0\n" - "\tldrb r0, [r2]\n" - "\tmovs r1, 0x4\n" - "_0810CB14:\n" - "\torrs r0, r1\n" - "\tstrb r0, [r2]\n" - "_0810CB18:\n" - "\tadds r5, 0x10\n" - "\tmovs r1, 0x1\n" - "\tadd r9, r1\n" - "\tldr r4, _0810CB68 @ =sVsSeeker\n" - "\tldr r0, [r4]\n" - "\tadds r0, r5\n" - "\tldrb r0, [r0, 0x6]\n" - "\tcmp r0, 0xFF\n" - "\tbeq _0810CB2C\n" - "\tb _0810C9DA\n" - "_0810CB2C:\n" - "\tldr r2, _0810CB68 @ =sVsSeeker\n" - "\tldr r0, [r2]\n" - "\tldr r3, _0810CB64 @ =0x00000431\n" - "\tadds r0, r3\n" - "\tldrb r1, [r0]\n" - "\tmovs r0, 0x4\n" - "\tands r0, r1\n" - "\tcmp r0, 0\n" - "\tbeq _0810CB70\n" - "\tmovs r0, 0x15\n" - "\tbl PlaySE\n" - "\tldr r0, _0810CB6C @ =0x00000801\n" - "\tbl FlagSet\n" - "\tbl sub_810C640\n" - "\tmovs r0, 0x2\n" - "\tb _0810CB7E\n" - "\t.align 2, 0\n" - "_0810CB54: .4byte gSaveBlock1Ptr\n" - "_0810CB58: .4byte 0x0000063a\n" - "_0810CB5C: .4byte gObjectEvents\n" - "_0810CB60: .4byte gUnknown_8453F64\n" - "_0810CB64: .4byte 0x00000431\n" - "_0810CB68: .4byte sVsSeeker\n" - "_0810CB6C: .4byte 0x00000801\n" - "_0810CB70:\n" - "\tmovs r0, 0x1\n" - "\tands r0, r1\n" - "\tcmp r0, 0\n" - "\tbne _0810CB7C\n" - "\tmovs r0, 0\n" - "\tb _0810CB7E\n" - "_0810CB7C:\n" - "\tmovs r0, 0x1\n" - "_0810CB7E:\n" - "\tadd sp, 0x8\n" - "\tpop {r3-r5}\n" - "\tmov r8, r3\n" - "\tmov r9, r4\n" - "\tmov r10, r5\n" - "\tpop {r4-r7}\n" - "\tpop {r1}\n" - "\tbx r1"); -} -#endif void sub_810CB90(void) { |