vblankCounter1 to non-pointer

This commit is contained in:
cawtds 2024-08-22 22:47:17 +02:00
parent 782a8252b9
commit 4afb2c96cb
9 changed files with 58 additions and 46 deletions

View File

@ -23,7 +23,7 @@ struct Main
/*0x01C*/ vu16 intrCheck;
/*0x020*/ u32 *vblankCounter1;
/*0x020*/ u32 vblankCounter1;
/*0x024*/ u32 vblankCounter2;
/*0x028*/ u16 heldKeysRaw; // held keys without L=A remapping
@ -63,8 +63,8 @@ void InitFlashTimer(void);
void DoSoftReset(void);
void ClearPokemonCrySongs(void);
void RestoreSerialTimer3IntrHandlers(void);
void SetVBlankCounter1Ptr(u32 *ptr);
void DisableVBlankCounter1(void);
void SetTrainerTowerVBlankCounter(u32 *ptr);
void ClearTrainerTowerVBlankCounter(void);
void StartTimer1(void);
void SeedRngAndSetTrainerId(void);
u16 GetGeneratedTrainerIdLower(void);

View File

@ -1,6 +1,9 @@
#ifndef GUARD_TRAINER_TOWER_H
#define GUARD_TRAINER_TOWER_H
extern u32 *gTrainerTowerVBlankCounter;
void PrintTrainerTowerRecords(void);
void InitTrainerTowerBattleStruct(void);
void FreeTrainerTowerBattleStruct(void);

View File

@ -472,7 +472,7 @@ void SetAiLogicDataForTurn(struct AiLogicData *aiData)
return;
// Set delay timer to count how long it takes for AI to choose action/move
gBattleStruct->aiDelayTimer = *gMain.vblankCounter1;
gBattleStruct->aiDelayTimer = gMain.vblankCounter1;
aiData->weatherHasEffect = WEATHER_HAS_EFFECT;
// get/assume all battler data and simulate AI damage

View File

@ -1945,7 +1945,7 @@ static void HandleChooseActionAfterDma3(u32 battler)
gBattle_BG0_Y = DISPLAY_HEIGHT;
if (gBattleStruct->aiDelayTimer != 0)
{
gBattleStruct->aiDelayFrames = *gMain.vblankCounter1 - gBattleStruct->aiDelayTimer;
gBattleStruct->aiDelayFrames = gMain.vblankCounter1 - gBattleStruct->aiDelayTimer;
gBattleStruct->aiDelayTimer = 0;
#if DEBUG_AI_DELAY_TIMER
{

View File

@ -74,19 +74,21 @@ static void Task_RunPerStepCallback(u8 taskId)
#define tAmbientCryState data[1]
#define tAmbientCryDelay data[2]
#define TIME_UPDATE_INTERVAL (1 << 12)
static void RunTimeBasedEvents(s16 *data)
{
switch (tState)
{
case 0:
if (*gMain.vblankCounter1 & 0x1000)
if (gMain.vblankCounter1 & TIME_UPDATE_INTERVAL)
{
DoTimeBasedEvents();
tState++;
}
break;
case 1:
if (!(*gMain.vblankCounter1 & 0x1000))
if (!(gMain.vblankCounter1 & TIME_UPDATE_INTERVAL))
{
tState--;
}

View File

@ -1,15 +1,16 @@
#include "global.h"
#include "gflib.h"
#include "gba/flash_internal.h"
#include "gflib.h"
#include "berry_powder.h"
#include "item.h"
#include "load_save.h"
#include "overworld.h"
#include "pokemon.h"
#include "pokemon_storage_system.h"
#include "random.h"
#include "item.h"
#include "save_location.h"
#include "berry_powder.h"
#include "overworld.h"
#include "quest_log.h"
#include "random.h"
#include "save_location.h"
#include "trainer_tower.h"
#include "constants/event_objects.h"
#define SAVEBLOCK_MOVE_RANGE 128
@ -102,7 +103,7 @@ void MoveSaveBlocks_ResetHeap(void)
hblankCB = gMain.hblankCallback;
gMain.vblankCallback = NULL;
gMain.hblankCallback = NULL;
gMain.vblankCounter1 = NULL;
gTrainerTowerVBlankCounter = NULL;
saveBlock2Copy = (struct SaveBlock2 *)(gHeap);
saveBlock1Copy = (struct SaveBlock1 *)(gHeap + sizeof(struct SaveBlock2));

View File

@ -1,22 +1,23 @@
#include "global.h"
#include "gba/flash_internal.h"
#include "gflib.h"
#include "battle_controllers.h"
#include "help_system.h"
#include "intro.h"
#include "link.h"
#include "link_rfu.h"
#include "load_save.h"
#include "m4a.h"
#include "rtc.h"
#include "random.h"
#include "gba/flash_internal.h"
#include "help_system.h"
#include "new_menu_helpers.h"
#include "overworld.h"
#include "play_time.h"
#include "intro.h"
#include "battle_controllers.h"
#include "scanline_effect.h"
#include "save_failed_screen.h"
#include "test_runner.h"
#include "quest_log.h"
#include "random.h"
#include "rtc.h"
#include "save_failed_screen.h"
#include "scanline_effect.h"
#include "test_runner.h"
#include "trainer_tower.h"
extern u32 intr_main[];
@ -212,6 +213,7 @@ static void UpdateLinkAndCallCallbacks(void)
static void InitMainCallbacks(void)
{
gMain.vblankCounter1 = 0;
gTrainerTowerVBlankCounter = NULL;
gMain.vblankCounter2 = 0;
gMain.callback1 = NULL;
SetMainCallback2(gInitialMainCB2);
@ -395,8 +397,10 @@ static void VBlankIntr(void)
else if (!gLinkVSyncDisabled)
LinkVSync();
if (gMain.vblankCounter1)
(*gMain.vblankCounter1)++;
gMain.vblankCounter1++;
if (gTrainerTowerVBlankCounter && *gTrainerTowerVBlankCounter < 0xFFFFFFFF)
(*gTrainerTowerVBlankCounter)++;
if (gMain.vblankCallback)
gMain.vblankCallback();
@ -478,14 +482,14 @@ static void WaitForVBlank(void)
;
}
void SetVBlankCounter1Ptr(u32 *ptr)
void SetTrainerTowerVBlankCounter(u32 *ptr)
{
gMain.vblankCounter1 = ptr;
gTrainerTowerVBlankCounter = ptr;
}
void DisableVBlankCounter1(void)
void ClearTrainerTowerVBlankCounter(void)
{
gMain.vblankCounter1 = NULL;
gTrainerTowerVBlankCounter = NULL;
}
void DoSoftReset(void)

View File

@ -1,14 +1,15 @@
#include "global.h"
#include "save.h"
#include "decompress.h"
#include "overworld.h"
#include "load_save.h"
#include "task.h"
#include "link.h"
#include "save_failed_screen.h"
#include "fieldmap.h"
#include "pokemon_storage_system.h"
#include "gba/flash_internal.h"
#include "decompress.h"
#include "fieldmap.h"
#include "link.h"
#include "load_save.h"
#include "overworld.h"
#include "pokemon_storage_system.h"
#include "save.h"
#include "save_failed_screen.h"
#include "task.h"
#include "trainer_tower.h"
static u8 HandleWriteSector(u16 sectorId, const struct SaveSectorLocation *locations);
static u8 TryWriteSector(u8 sectorNum, u8 *data);
@ -645,10 +646,10 @@ static void UpdateSaveAddresses(void)
u8 HandleSavingData(u8 saveType)
{
u8 i;
u32 *backupPtr = gMain.vblankCounter1;
u32 *backupPtr = gTrainerTowerVBlankCounter;
u8 *tempAddr;
gMain.vblankCounter1 = NULL;
gTrainerTowerVBlankCounter = NULL;
UpdateSaveAddresses();
switch (saveType)
{
@ -686,7 +687,7 @@ u8 HandleSavingData(u8 saveType)
WriteSaveSectorOrSlot(FULL_SAVE_SLOT, gRamSaveSectorLocations);
break;
}
gMain.vblankCounter1 = backupPtr;
gTrainerTowerVBlankCounter = backupPtr;
return 0;
}

View File

@ -64,6 +64,7 @@ struct TrainerEncounterMusicPairs
static EWRAM_DATA struct TrainerTowerState * sTrainerTowerState = NULL;
static EWRAM_DATA struct TrainerTowerOpponent * sTrainerTowerOpponent = NULL;
EWRAM_DATA u32 *gTrainerTowerVBlankCounter = NULL;
static void SetUpTrainerTowerDataStruct(void);
static void FreeTrainerTowerDataStruct(void);
@ -481,7 +482,7 @@ void InitTrainerTowerBattleStruct(void)
sTrainerTowerOpponent->battleType = CURR_FLOOR.challengeType;
sTrainerTowerOpponent->facilityClass = CURR_FLOOR.trainers[trainerId].facilityClass;
sTrainerTowerOpponent->textColor = CURR_FLOOR.trainers[trainerId].textColor;
SetVBlankCounter1Ptr(&TRAINER_TOWER.timer);
SetTrainerTowerVBlankCounter(&TRAINER_TOWER.timer);
FreeTrainerTowerDataStruct();
}
@ -776,7 +777,7 @@ static void StartTrainerTowerChallenge(void)
else
TRAINER_TOWER.validated = FALSE;
TRAINER_TOWER.floorsCleared = 0;
SetVBlankCounter1Ptr(&TRAINER_TOWER.timer);
SetTrainerTowerVBlankCounter(&TRAINER_TOWER.timer);
TRAINER_TOWER.timer = 0;
TRAINER_TOWER.spokeToOwner = FALSE;
TRAINER_TOWER.checkedFinalTime = FALSE;
@ -784,7 +785,7 @@ static void StartTrainerTowerChallenge(void)
static void GetOwnerState(void)
{
DisableVBlankCounter1();
ClearTrainerTowerVBlankCounter();
gSpecialVar_Result = 0;
if (TRAINER_TOWER.spokeToOwner)
@ -841,7 +842,7 @@ static void TrainerTowerResumeTimer(void)
if (TRAINER_TOWER.timer >= TRAINER_TOWER_MAX_TIME)
TRAINER_TOWER.timer = TRAINER_TOWER_MAX_TIME;
else
SetVBlankCounter1Ptr(&TRAINER_TOWER.timer);
SetTrainerTowerVBlankCounter(&TRAINER_TOWER.timer);
}
}
@ -888,7 +889,7 @@ static void GetCurrentTime(void)
{
if (TRAINER_TOWER.timer >= TRAINER_TOWER_MAX_TIME)
{
DisableVBlankCounter1();
ClearTrainerTowerVBlankCounter();
TRAINER_TOWER.timer = TRAINER_TOWER_MAX_TIME;
}