2017-02-04 00:44:06 +00:00
|
|
|
#include "global.h"
|
2017-11-13 06:01:27 +00:00
|
|
|
#include "crt0.h"
|
2019-09-09 02:07:54 +01:00
|
|
|
#include "malloc.h"
|
2017-11-09 00:29:37 +00:00
|
|
|
#include "link.h"
|
2017-11-13 06:01:27 +00:00
|
|
|
#include "link_rfu.h"
|
|
|
|
#include "librfu.h"
|
2017-03-05 07:35:03 +00:00
|
|
|
#include "m4a.h"
|
2017-11-13 06:01:27 +00:00
|
|
|
#include "bg.h"
|
2017-03-05 07:35:03 +00:00
|
|
|
#include "rtc.h"
|
2018-02-03 14:42:19 +00:00
|
|
|
#include "scanline_effect.h"
|
2017-11-13 06:01:27 +00:00
|
|
|
#include "overworld.h"
|
|
|
|
#include "play_time.h"
|
2017-12-05 18:27:33 +00:00
|
|
|
#include "random.h"
|
2017-03-05 07:35:03 +00:00
|
|
|
#include "dma3.h"
|
2017-02-04 00:44:06 +00:00
|
|
|
#include "gba/flash_internal.h"
|
2017-11-13 06:01:27 +00:00
|
|
|
#include "load_save.h"
|
|
|
|
#include "gpu_regs.h"
|
|
|
|
#include "agb_flash.h"
|
|
|
|
#include "sound.h"
|
2017-09-05 19:13:34 +01:00
|
|
|
#include "battle.h"
|
2017-11-13 06:01:27 +00:00
|
|
|
#include "battle_controllers.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "intro.h"
|
|
|
|
#include "main.h"
|
2019-01-13 12:15:23 +00:00
|
|
|
#include "trainer_hill.h"
|
2023-12-30 10:10:40 +00:00
|
|
|
#include "test_runner.h"
|
2021-03-01 19:19:41 +00:00
|
|
|
#include "constants/rgb.h"
|
2017-02-04 00:44:06 +00:00
|
|
|
|
|
|
|
static void VBlankIntr(void);
|
|
|
|
static void HBlankIntr(void);
|
|
|
|
static void VCountIntr(void);
|
|
|
|
static void SerialIntr(void);
|
|
|
|
static void IntrDummy(void);
|
|
|
|
|
2022-12-24 05:13:42 +00:00
|
|
|
// Defined in the linker script so that the test build can override it.
|
|
|
|
extern void gInitialMainCB2(void);
|
|
|
|
|
2018-10-06 06:57:39 +01:00
|
|
|
const u8 gGameVersion = GAME_VERSION;
|
2017-02-04 00:44:06 +00:00
|
|
|
|
|
|
|
const u8 gGameLanguage = GAME_LANGUAGE; // English
|
|
|
|
|
|
|
|
const char BuildDateTime[] = "2005 02 21 11:10";
|
|
|
|
|
|
|
|
const IntrFunc gIntrTableTemplate[] =
|
|
|
|
{
|
|
|
|
VCountIntr, // V-count interrupt
|
|
|
|
SerialIntr, // Serial interrupt
|
|
|
|
Timer3Intr, // Timer 3 interrupt
|
|
|
|
HBlankIntr, // H-blank interrupt
|
|
|
|
VBlankIntr, // V-blank interrupt
|
|
|
|
IntrDummy, // Timer 0 interrupt
|
|
|
|
IntrDummy, // Timer 1 interrupt
|
|
|
|
IntrDummy, // Timer 2 interrupt
|
|
|
|
IntrDummy, // DMA 0 interrupt
|
|
|
|
IntrDummy, // DMA 1 interrupt
|
|
|
|
IntrDummy, // DMA 2 interrupt
|
|
|
|
IntrDummy, // DMA 3 interrupt
|
|
|
|
IntrDummy, // Key interrupt
|
|
|
|
IntrDummy, // Game Pak interrupt
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INTR_COUNT ((int)(sizeof(gIntrTableTemplate)/sizeof(IntrFunc)))
|
|
|
|
|
2017-11-08 04:53:30 +00:00
|
|
|
u16 gKeyRepeatStartDelay;
|
2017-11-11 05:05:44 +00:00
|
|
|
bool8 gLinkTransferringData;
|
2017-11-08 04:53:30 +00:00
|
|
|
struct Main gMain;
|
|
|
|
u16 gKeyRepeatContinueDelay;
|
|
|
|
bool8 gSoftResetDisabled;
|
|
|
|
IntrFunc gIntrTable[INTR_COUNT];
|
2017-11-11 05:05:44 +00:00
|
|
|
u8 gLinkVSyncDisabled;
|
2017-11-08 04:53:30 +00:00
|
|
|
u32 IntrMain_Buffer[0x200];
|
2018-11-28 16:14:32 +00:00
|
|
|
s8 gPcmDmaCounter;
|
2022-12-24 05:13:42 +00:00
|
|
|
void *gAgbMainLoop_sp;
|
2017-02-04 00:44:06 +00:00
|
|
|
|
2022-05-17 18:51:54 +01:00
|
|
|
static EWRAM_DATA u16 sTrainerId = 0;
|
2017-02-04 00:44:06 +00:00
|
|
|
|
2017-11-08 04:53:30 +00:00
|
|
|
//EWRAM_DATA void (**gFlashTimerIntrFunc)(void) = NULL;
|
2017-02-04 00:44:06 +00:00
|
|
|
|
|
|
|
static void UpdateLinkAndCallCallbacks(void);
|
|
|
|
static void InitMainCallbacks(void);
|
|
|
|
static void CallCallbacks(void);
|
2023-09-20 23:01:08 +01:00
|
|
|
#ifdef BUGFIX
|
2021-01-11 15:36:53 +00:00
|
|
|
static void SeedRngWithRtc(void);
|
2023-09-20 23:01:08 +01:00
|
|
|
#endif
|
2017-02-04 00:44:06 +00:00
|
|
|
static void ReadKeys(void);
|
2017-02-15 21:25:21 +00:00
|
|
|
void InitIntrHandlers(void);
|
2017-02-04 00:44:06 +00:00
|
|
|
static void WaitForVBlank(void);
|
2017-03-05 07:35:03 +00:00
|
|
|
void EnableVCountIntrAtLine150(void);
|
2017-02-04 00:44:06 +00:00
|
|
|
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 08:22:50 +01:00
|
|
|
#define B_START_SELECT (B_BUTTON | START_BUTTON | SELECT_BUTTON)
|
|
|
|
|
2017-02-04 00:44:06 +00:00
|
|
|
void AgbMain()
|
|
|
|
{
|
2021-03-01 18:23:03 +00:00
|
|
|
*(vu16 *)BG_PLTT = RGB_WHITE; // Set the backdrop to white on startup
|
2017-02-04 00:44:06 +00:00
|
|
|
InitGpuRegManager();
|
2024-05-13 18:19:37 +01:00
|
|
|
REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3;
|
2017-02-04 00:44:06 +00:00
|
|
|
InitKeys();
|
|
|
|
InitIntrHandlers();
|
|
|
|
m4aSoundInit();
|
|
|
|
EnableVCountIntrAtLine150();
|
2020-06-06 21:46:19 +01:00
|
|
|
InitRFU();
|
2017-02-04 00:44:06 +00:00
|
|
|
RtcInit();
|
|
|
|
CheckForFlashMemory();
|
|
|
|
InitMainCallbacks();
|
|
|
|
InitMapMusic();
|
2021-01-11 15:36:53 +00:00
|
|
|
#ifdef BUGFIX
|
|
|
|
SeedRngWithRtc(); // see comment at SeedRngWithRtc definition below
|
|
|
|
#endif
|
2017-02-04 00:44:06 +00:00
|
|
|
ClearDma3Requests();
|
|
|
|
ResetBgs();
|
|
|
|
SetDefaultFontsPointer();
|
2018-01-06 06:35:48 +00:00
|
|
|
InitHeap(gHeap, HEAP_SIZE);
|
2017-02-04 00:44:06 +00:00
|
|
|
|
|
|
|
gSoftResetDisabled = FALSE;
|
|
|
|
|
|
|
|
if (gFlashMemoryPresent != TRUE)
|
|
|
|
SetMainCallback2(NULL);
|
|
|
|
|
2017-11-11 05:05:44 +00:00
|
|
|
gLinkTransferringData = FALSE;
|
2017-02-04 00:44:06 +00:00
|
|
|
|
2022-09-06 12:40:29 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#if (LOG_HANDLER == LOG_HANDLER_MGBA_PRINT)
|
|
|
|
(void) MgbaOpen();
|
|
|
|
#elif (LOG_HANDLER == LOG_HANDLER_AGB_PRINT)
|
|
|
|
AGBPrintfInit();
|
|
|
|
#endif
|
|
|
|
#endif
|
2022-12-24 05:13:42 +00:00
|
|
|
gAgbMainLoop_sp = __builtin_frame_address(0);
|
|
|
|
AgbMainLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AgbMainLoop(void)
|
|
|
|
{
|
2017-02-04 00:44:06 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ReadKeys();
|
|
|
|
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 08:22:50 +01:00
|
|
|
if (gSoftResetDisabled == FALSE
|
2022-09-23 01:43:33 +01:00
|
|
|
&& JOY_HELD_RAW(A_BUTTON)
|
|
|
|
&& JOY_HELD_RAW(B_START_SELECT) == B_START_SELECT)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
|
|
|
rfu_REQ_stopMode();
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
DoSoftReset();
|
|
|
|
}
|
|
|
|
|
2021-03-29 23:32:22 +01:00
|
|
|
if (Overworld_SendKeysToLinkIsRunning() == TRUE)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
2017-11-11 05:05:44 +00:00
|
|
|
gLinkTransferringData = TRUE;
|
2017-02-04 00:44:06 +00:00
|
|
|
UpdateLinkAndCallCallbacks();
|
2017-11-11 05:05:44 +00:00
|
|
|
gLinkTransferringData = FALSE;
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 05:05:44 +00:00
|
|
|
gLinkTransferringData = FALSE;
|
2017-02-04 00:44:06 +00:00
|
|
|
UpdateLinkAndCallCallbacks();
|
|
|
|
|
2021-03-29 23:32:22 +01:00
|
|
|
if (Overworld_RecvKeysFromLinkIsRunning() == TRUE)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
|
|
|
gMain.newKeys = 0;
|
2017-09-01 18:43:26 +01:00
|
|
|
ClearSpriteCopyRequests();
|
2017-11-11 05:05:44 +00:00
|
|
|
gLinkTransferringData = TRUE;
|
2017-02-04 00:44:06 +00:00
|
|
|
UpdateLinkAndCallCallbacks();
|
2017-11-11 05:05:44 +00:00
|
|
|
gLinkTransferringData = FALSE;
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayTimeCounter_Update();
|
|
|
|
MapMusicMain();
|
|
|
|
WaitForVBlank();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateLinkAndCallCallbacks(void)
|
|
|
|
{
|
|
|
|
if (!HandleLinkConnection())
|
|
|
|
CallCallbacks();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitMainCallbacks(void)
|
|
|
|
{
|
|
|
|
gMain.vblankCounter1 = 0;
|
2019-03-01 06:49:11 +00:00
|
|
|
gTrainerHillVBlankCounter = NULL;
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.vblankCounter2 = 0;
|
|
|
|
gMain.callback1 = NULL;
|
2022-12-24 05:13:42 +00:00
|
|
|
SetMainCallback2(gInitialMainCB2);
|
2021-11-14 02:41:16 +00:00
|
|
|
gSaveBlock2Ptr = &gSaveblock2.block;
|
|
|
|
gPokemonStoragePtr = &gPokemonStorage.block;
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CallCallbacks(void)
|
|
|
|
{
|
|
|
|
if (gMain.callback1)
|
|
|
|
gMain.callback1();
|
|
|
|
|
|
|
|
if (gMain.callback2)
|
|
|
|
gMain.callback2();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMainCallback2(MainCallback callback)
|
|
|
|
{
|
|
|
|
gMain.callback2 = callback;
|
|
|
|
gMain.state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartTimer1(void)
|
|
|
|
{
|
2024-02-28 06:04:47 +00:00
|
|
|
if (HQ_RANDOM)
|
|
|
|
{
|
|
|
|
REG_TM2CNT_L = 0;
|
|
|
|
REG_TM2CNT_H = TIMER_ENABLE | TIMER_COUNTUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG_TM1CNT_H = TIMER_ENABLE;
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SeedRngAndSetTrainerId(void)
|
|
|
|
{
|
2024-02-28 06:04:47 +00:00
|
|
|
u32 val;
|
|
|
|
|
|
|
|
if (HQ_RANDOM)
|
|
|
|
{
|
|
|
|
REG_TM1CNT_H = 0;
|
|
|
|
REG_TM2CNT_H = 0;
|
|
|
|
val = ((u32)REG_TM2CNT_L) << 16;
|
|
|
|
val |= REG_TM1CNT_L;
|
|
|
|
SeedRng(val);
|
|
|
|
sTrainerId = Random();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Do it exactly like it was originally done, including not stopping
|
|
|
|
// the timer beforehand.
|
|
|
|
val = REG_TM1CNT_L;
|
|
|
|
SeedRng((u16)val);
|
|
|
|
REG_TM1CNT_H = 0;
|
|
|
|
sTrainerId = val;
|
|
|
|
}
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
2017-09-03 21:50:17 +01:00
|
|
|
u16 GetGeneratedTrainerIdLower(void)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
2022-05-17 18:51:54 +01:00
|
|
|
return sTrainerId;
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 21:25:21 +00:00
|
|
|
void EnableVCountIntrAtLine150(void)
|
|
|
|
{
|
2017-02-17 18:56:19 +00:00
|
|
|
u16 gpuReg = (GetGpuReg(REG_OFFSET_DISPSTAT) & 0xFF) | (150 << 8);
|
|
|
|
SetGpuReg(REG_OFFSET_DISPSTAT, gpuReg | DISPSTAT_VCOUNT_INTR);
|
|
|
|
EnableInterrupts(INTR_FLAG_VCOUNT);
|
2017-02-15 21:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 15:36:53 +00:00
|
|
|
// FRLG commented this out to remove RTC, however Emerald didn't undo this!
|
|
|
|
#ifdef BUGFIX
|
|
|
|
static void SeedRngWithRtc(void)
|
|
|
|
{
|
2024-01-19 10:27:42 +00:00
|
|
|
#if HQ_RANDOM == FALSE
|
|
|
|
u32 seed = RtcGetMinuteCount();
|
|
|
|
seed = (seed >> 16) ^ (seed & 0xFFFF);
|
|
|
|
SeedRng(seed);
|
|
|
|
#else
|
|
|
|
#define BCD8(x) ((((x) >> 4) & 0xF) * 10 + ((x) & 0xF))
|
|
|
|
u32 seconds;
|
|
|
|
struct SiiRtcInfo rtc;
|
|
|
|
RtcGetInfo(&rtc);
|
|
|
|
seconds =
|
|
|
|
((HOURS_PER_DAY * RtcGetDayCount(&rtc) + BCD8(rtc.hour))
|
|
|
|
* MINUTES_PER_HOUR + BCD8(rtc.minute))
|
|
|
|
* SECONDS_PER_MINUTE + BCD8(rtc.second);
|
|
|
|
SeedRng(seconds);
|
|
|
|
#undef BCD8
|
|
|
|
#endif
|
2021-01-11 15:36:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-05-14 21:33:19 +01:00
|
|
|
|
2017-02-04 00:44:06 +00:00
|
|
|
void InitKeys(void)
|
|
|
|
{
|
|
|
|
gKeyRepeatContinueDelay = 5;
|
|
|
|
gKeyRepeatStartDelay = 40;
|
2017-02-17 18:52:03 +00:00
|
|
|
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.heldKeys = 0;
|
|
|
|
gMain.newKeys = 0;
|
|
|
|
gMain.newAndRepeatedKeys = 0;
|
|
|
|
gMain.heldKeysRaw = 0;
|
|
|
|
gMain.newKeysRaw = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReadKeys(void)
|
|
|
|
{
|
|
|
|
u16 keyInput = REG_KEYINPUT ^ KEYS_MASK;
|
|
|
|
gMain.newKeysRaw = keyInput & ~gMain.heldKeysRaw;
|
|
|
|
gMain.newKeys = gMain.newKeysRaw;
|
|
|
|
gMain.newAndRepeatedKeys = gMain.newKeysRaw;
|
|
|
|
|
|
|
|
// BUG: Key repeat won't work when pressing L using L=A button mode
|
|
|
|
// because it compares the raw key input with the remapped held keys.
|
|
|
|
// Note that newAndRepeatedKeys is never remapped either.
|
|
|
|
|
|
|
|
if (keyInput != 0 && gMain.heldKeys == keyInput)
|
|
|
|
{
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 08:22:50 +01:00
|
|
|
gMain.keyRepeatCounter--;
|
|
|
|
|
|
|
|
if (gMain.keyRepeatCounter == 0)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
|
|
|
gMain.newAndRepeatedKeys = keyInput;
|
|
|
|
gMain.keyRepeatCounter = gKeyRepeatContinueDelay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If there is no input or the input has changed, reset the counter.
|
|
|
|
gMain.keyRepeatCounter = gKeyRepeatStartDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
gMain.heldKeysRaw = keyInput;
|
|
|
|
gMain.heldKeys = gMain.heldKeysRaw;
|
|
|
|
|
|
|
|
// Remap L to A if the L=A option is enabled.
|
2020-07-14 10:13:03 +01:00
|
|
|
if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
2020-11-03 01:02:39 +00:00
|
|
|
if (JOY_NEW(L_BUTTON))
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.newKeys |= A_BUTTON;
|
|
|
|
|
2020-11-03 01:02:39 +00:00
|
|
|
if (JOY_HELD(L_BUTTON))
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.heldKeys |= A_BUTTON;
|
|
|
|
}
|
|
|
|
|
2022-09-23 01:43:33 +01:00
|
|
|
if (JOY_NEW(gMain.watchedKeysMask))
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.watchedKeysPressed = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:25:21 +00:00
|
|
|
void InitIntrHandlers(void)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < INTR_COUNT; i++)
|
|
|
|
gIntrTable[i] = gIntrTableTemplate[i];
|
|
|
|
|
|
|
|
DmaCopy32(3, IntrMain, IntrMain_Buffer, sizeof(IntrMain_Buffer));
|
|
|
|
|
|
|
|
INTR_VECTOR = IntrMain_Buffer;
|
|
|
|
|
|
|
|
SetVBlankCallback(NULL);
|
|
|
|
SetHBlankCallback(NULL);
|
|
|
|
SetSerialCallback(NULL);
|
|
|
|
|
|
|
|
REG_IME = 1;
|
2017-02-17 18:52:03 +00:00
|
|
|
|
2021-01-26 02:37:04 +00:00
|
|
|
EnableInterrupts(INTR_FLAG_VBLANK);
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetVBlankCallback(IntrCallback callback)
|
|
|
|
{
|
|
|
|
gMain.vblankCallback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetHBlankCallback(IntrCallback callback)
|
|
|
|
{
|
|
|
|
gMain.hblankCallback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetVCountCallback(IntrCallback callback)
|
|
|
|
{
|
|
|
|
gMain.vcountCallback = callback;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:25:21 +00:00
|
|
|
void RestoreSerialTimer3IntrHandlers(void)
|
|
|
|
{
|
|
|
|
gIntrTable[1] = SerialIntr;
|
|
|
|
gIntrTable[2] = Timer3Intr;
|
|
|
|
}
|
|
|
|
|
2017-02-04 00:44:06 +00:00
|
|
|
void SetSerialCallback(IntrCallback callback)
|
|
|
|
{
|
|
|
|
gMain.serialCallback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void VBlankIntr(void)
|
|
|
|
{
|
2017-11-14 13:44:32 +00:00
|
|
|
if (gWirelessCommType != 0)
|
|
|
|
RfuVSync();
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 08:22:50 +01:00
|
|
|
else if (gLinkVSyncDisabled == FALSE)
|
2017-11-14 13:44:32 +00:00
|
|
|
LinkVSync();
|
2017-02-04 00:44:06 +00:00
|
|
|
|
2017-02-17 18:52:03 +00:00
|
|
|
gMain.vblankCounter1++;
|
|
|
|
|
2019-03-01 06:49:11 +00:00
|
|
|
if (gTrainerHillVBlankCounter && *gTrainerHillVBlankCounter < 0xFFFFFFFF)
|
|
|
|
(*gTrainerHillVBlankCounter)++;
|
2017-02-04 00:44:06 +00:00
|
|
|
|
|
|
|
if (gMain.vblankCallback)
|
|
|
|
gMain.vblankCallback();
|
|
|
|
|
|
|
|
gMain.vblankCounter2++;
|
2017-02-17 18:52:03 +00:00
|
|
|
|
2017-02-15 21:25:21 +00:00
|
|
|
CopyBufferedValuesToGpuRegs();
|
|
|
|
ProcessDma3Requests();
|
2017-02-04 00:44:06 +00:00
|
|
|
|
|
|
|
gPcmDmaCounter = gSoundInfo.pcmDmaCounter;
|
|
|
|
|
|
|
|
m4aSoundMain();
|
2021-01-22 07:48:22 +00:00
|
|
|
TryReceiveLinkBattleData();
|
2017-02-15 21:25:21 +00:00
|
|
|
|
2023-12-30 10:10:40 +00:00
|
|
|
if (!gTestRunnerEnabled && (!gMain.inBattle || !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_RECORDED))))
|
2023-12-22 17:39:15 +00:00
|
|
|
AdvanceRandom();
|
2017-02-04 00:44:06 +00:00
|
|
|
|
2020-06-07 22:37:09 +01:00
|
|
|
UpdateWirelessStatusIndicatorSprite();
|
2017-02-15 21:25:21 +00:00
|
|
|
|
2017-02-17 18:52:03 +00:00
|
|
|
INTR_CHECK |= INTR_FLAG_VBLANK;
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.intrCheck |= INTR_FLAG_VBLANK;
|
|
|
|
}
|
|
|
|
|
2017-09-04 17:26:39 +01:00
|
|
|
void InitFlashTimer(void)
|
2017-02-04 00:44:06 +00:00
|
|
|
{
|
2017-02-15 21:25:21 +00:00
|
|
|
SetFlashTimerIntr(2, gIntrTable + 0x7);
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void HBlankIntr(void)
|
|
|
|
{
|
|
|
|
if (gMain.hblankCallback)
|
|
|
|
gMain.hblankCallback();
|
|
|
|
|
|
|
|
INTR_CHECK |= INTR_FLAG_HBLANK;
|
|
|
|
gMain.intrCheck |= INTR_FLAG_HBLANK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void VCountIntr(void)
|
|
|
|
{
|
|
|
|
if (gMain.vcountCallback)
|
|
|
|
gMain.vcountCallback();
|
|
|
|
|
2017-02-15 21:25:21 +00:00
|
|
|
m4aSoundVSync();
|
2017-02-17 18:52:03 +00:00
|
|
|
INTR_CHECK |= INTR_FLAG_VCOUNT;
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.intrCheck |= INTR_FLAG_VCOUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SerialIntr(void)
|
|
|
|
{
|
|
|
|
if (gMain.serialCallback)
|
|
|
|
gMain.serialCallback();
|
|
|
|
|
2017-02-17 18:52:03 +00:00
|
|
|
INTR_CHECK |= INTR_FLAG_SERIAL;
|
2017-02-04 00:44:06 +00:00
|
|
|
gMain.intrCheck |= INTR_FLAG_SERIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void IntrDummy(void)
|
|
|
|
{}
|
|
|
|
|
|
|
|
static void WaitForVBlank(void)
|
|
|
|
{
|
|
|
|
gMain.intrCheck &= ~INTR_FLAG_VBLANK;
|
2024-03-19 11:29:47 +00:00
|
|
|
|
|
|
|
if (gWirelessCommType != 0)
|
|
|
|
{
|
|
|
|
// Desynchronization may occur if wireless adapter is connected
|
|
|
|
// and we call VBlankIntrWait();
|
|
|
|
while (!(gMain.intrCheck & INTR_FLAG_VBLANK))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VBlankIntrWait();
|
|
|
|
}
|
2017-02-15 21:25:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 06:49:11 +00:00
|
|
|
void SetTrainerHillVBlankCounter(u32 *counter)
|
2017-02-15 21:25:21 +00:00
|
|
|
{
|
2019-03-01 06:49:11 +00:00
|
|
|
gTrainerHillVBlankCounter = counter;
|
2017-02-15 21:25:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 06:49:11 +00:00
|
|
|
void ClearTrainerHillVBlankCounter(void)
|
2017-02-15 21:25:21 +00:00
|
|
|
{
|
2019-03-01 06:49:11 +00:00
|
|
|
gTrainerHillVBlankCounter = NULL;
|
2017-02-04 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoSoftReset(void)
|
|
|
|
{
|
|
|
|
REG_IME = 0;
|
|
|
|
m4aSoundVSyncOff();
|
2018-01-16 17:59:06 +00:00
|
|
|
ScanlineEffect_Stop();
|
2017-02-04 00:44:06 +00:00
|
|
|
DmaStop(1);
|
|
|
|
DmaStop(2);
|
|
|
|
DmaStop(3);
|
|
|
|
SiiRtcProtect();
|
|
|
|
SoftReset(RESET_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPokemonCrySongs(void)
|
|
|
|
{
|
|
|
|
CpuFill16(0, gPokemonCrySongs, MAX_POKEMON_CRIES * sizeof(struct PokemonCrySong));
|
|
|
|
}
|