diff --git a/payload/data/all.s b/payload/data/all.s index 1b442db..a2711cb 100644 --- a/payload/data/all.s +++ b/payload/data/all.s @@ -113,7 +113,7 @@ gUnknown_0201F3AC:: .space 256 .align 2, 0 -gUnknown_0201F4AC:: +gTimer1InterruptFunction:: .4byte gIntrTable + 0x18 gUnknown_0201F4B0:: diff --git a/payload/include/gflib/bg.h b/payload/include/gflib/bg.h index 1d22b9b..b4f0573 100644 --- a/payload/include/gflib/bg.h +++ b/payload/include/gflib/bg.h @@ -9,12 +9,12 @@ extern bool8 gBgTilemapBufferTransferScheduled[]; void ResetGpuBuffers(void); void DoGpuUpdateAndTilemapTransfers(void); -void CopyToBgTilemapBufferRect(int bgNum, int left, int top, int width, int height, const u16 * src); -void CopyFromBgTilemapBufferRect(int bgNum, int left, int top, int width, int height, u16 * dest); -void SetBgTilemapBufferPaletteRect(int bgNum, int left, int top, int width, int height, int paletteNum); -void SetBgTilemapBufferTileAt(int bgNum, int x, int y, u16 tileNum); -void FillBgTilemapBufferRect(int bgNum, int left, int top, int width, int height, u16 tileNum); -void CopyRectWithinBgTilemapBuffer(int bgNum, int srcLeft, int srcTop, int width, int height, int destLeft, int destTop); -void SetBgPos(int bgNum, s32 x, s32 y); +void CopyToBgTilemapBufferRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, const u16 * src); +void UNUSED CopyFromBgTilemapBufferRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, u16 * dest); +void SetBgTilemapBufferPaletteRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, u32 paletteNum); +void SetBgTilemapBufferTileAt(u32 bgNum, u32 x, u32 y, u16 tileNum); +void FillBgTilemapBufferRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, u16 tileNum); +void CopyRectWithinBgTilemapBuffer(u32 bgNum, u32 srcLeft, u32 srcTop, s32 width, u32 height, u32 destLeft, u32 destTop); +void SetBgPos(u32 bgNum, s32 x, s32 y); #endif //GFLIB_BG_H diff --git a/payload/include/gflib/init.h b/payload/include/gflib/init.h index c8f1fc6..bba995d 100644 --- a/payload/include/gflib/init.h +++ b/payload/include/gflib/init.h @@ -9,9 +9,9 @@ void AgbMain(void); extern IntrFunc gIntrTable[14u]; -void SetIntrFunc(int i, IntrFunc func); +void SetIntrFunc(u32 i, IntrFunc func); void SetVBlankCallback(IntrFunc cb); u32 GetFrameTotal(void); -void DelayFrames(u32 a0); +void DelayFrames(u32 frames); #endif //GFLIB_INIT_H diff --git a/payload/include/gflib/sound.h b/payload/include/gflib/sound.h index c14d9c6..19daaf8 100644 --- a/payload/include/gflib/sound.h +++ b/payload/include/gflib/sound.h @@ -7,13 +7,13 @@ bool32 EnableSoundVSync(bool32 enable); void InitSound(void); void PauseSoundVSync(void); void PlaySE(u16 song); -void StopSE(u16 song); -void StopAllSound(void); -bool8 sub_020093AC(void); -void FadeOutSE(u16 song, u16 _speed); -void SetSEVolume(u16 song, u16 volume); -void SetSETempo(u16 song, u16 tempo); -void SetSEPitch(u16 song, s16 pitch); +void UNUSED StopSE(u16 song); +void UNUSED StopAllSound(void); +bool8 UNUSED ReturnTrue(void); +void UNUSED FadeOutSE(u16 song, u16 _speed); +void UNUSED SetSEVolume(u16 song, u16 volume); +void UNUSED SetSETempo(u16 song, u16 tempo); +void UNUSED SetSEPitch(u16 song, s16 pitch); void SoundVSyncOff(void); void SoundVSyncOn(void); diff --git a/payload/include/gflib/sprite.h b/payload/include/gflib/sprite.h index f3ba7cd..b1cf8de 100644 --- a/payload/include/gflib/sprite.h +++ b/payload/include/gflib/sprite.h @@ -21,7 +21,7 @@ struct Sprite s16 y; const struct Subsprites * spriteTemplates; void (*callback)(struct Sprite *); - u32 unk14[4]; + u32 data[4]; }; struct SpriteSheet @@ -54,11 +54,11 @@ void ResetSprites(void); void UpdateSprites(void); void DoOamBufferTransfer(void); struct Sprite * AddSprite(s32 x, s32 y, const struct Subsprites * subsprites); -void MoveSpriteToHead(struct Sprite * a0); -void SetSpritePos(struct Sprite * r0, s32 r1, s32 r2); -void AddSpritePos(struct Sprite * r0, s32 r1, s32 r2); -void SetSpritePaletteNum(struct Sprite * r0, s32 r1); -void SetSpriteTileOffset(struct Sprite * r0, s32 r1); -void SetSpriteInvisible(struct Sprite * r0, s32 r1); +void MoveSpriteToHead(struct Sprite * sprite); +void SetSpritePos(struct Sprite * sprite, s32 x, s32 y); +void AddSpritePos(struct Sprite * sprite, s32 x, s32 y); +void SetSpritePaletteNum(struct Sprite * sprite, s32 paletteNum); +void SetSpriteTileOffset(struct Sprite * sprite, s32 tileOffset); +void SetSpriteInvisible(struct Sprite * sprite, s32 invisible); #endif //GFLIB_SPRITE_H diff --git a/payload/include/gflib/text.h b/payload/include/gflib/text.h index 76e1859..b57f057 100644 --- a/payload/include/gflib/text.h +++ b/payload/include/gflib/text.h @@ -34,13 +34,13 @@ void DrawGlyphOnWindow_NoShadow(struct Window *window, u32 glyphId, u32 fgColor) void DrawGlyphOnWindow_WithShadow(struct Window *window, u32 glyphId, u32 fgColor, u32 shadowColor); struct Window *AddWindow(u32 windowId, const struct Window *template); void GenerateFontHalfrowLookupTable(u32 * buffer); -void ClearWindowCharBuffer(struct Window * window, u32 a1); +void ClearWindowCharBuffer(struct Window * window, u32 tile); void FillWindowCharBufferRect(struct Window * window, s32 x, s32 y, s32 width, s32 height, u32 fillValue); void SetTextColor(struct Window * window, u8 fg, u8 shadow); void TextWindowNextLine(struct Window * window); void TextWindowSetXY(struct Window * window, u32 x, u32 y); void TextWindowShiftXY(struct Window * window, s32 dx, s32 dy); -void TextWindowPrintSimpleString(struct Window * window, const u8 * glyphs); +void UNUSED TextWindowPrintSimpleString(struct Window * window, const u8 * glyphs); void TextWindowFillTileBufferForText(struct Window * window); #ifdef __cplusplus diff --git a/payload/include/libpmagb/agb_rom.h b/payload/include/libpmagb/agb_rom.h index 972af9a..7a1f01b 100644 --- a/payload/include/libpmagb/agb_rom.h +++ b/payload/include/libpmagb/agb_rom.h @@ -1,85 +1,86 @@ #ifndef PMAGB_AGB_ROM_H #define PMAGB_AGB_ROM_H -struct RomInfo +struct GFRomHeader { - /*0x00*/ int gameVersion; - /*0x04*/ int gameLanguage; - /*0x08*/ char gameTitle[32]; - /*0x28*/ const struct CompressedSpriteSheet *monFrontPicTable; - /*0x2C*/ const struct CompressedSpriteSheet *monBackPicTable; - /*0x30*/ const struct CompressedSpritePalette *monPaletteTable; - /*0x34*/ const struct CompressedSpritePalette *monShinyPaletteTable; - /*0x38*/ const u8 *const *monIconTable; - /*0x3C*/ const u8 *gMonIconPaletteIndices; - /*0x40*/ const struct SpritePalette *monIconPaletteTable; - /*0x44*/ const u8 (*speciesNames)[][POKEMON_NAME_LENGTH + 1]; - /*0x48*/ const u8 (*moveNames)[][MOVE_NAME_LENGTH + 1]; - /*0x4C*/ const struct Decoration *decorations; - /*0x50*/ u32 flagsOffs; - /*0x54*/ u32 varsOffs; - /*0x58*/ u32 pokedexOffs; - /*0x5C*/ u32 dexSeen2Offs; - /*0x60*/ u32 dexSeen3Offs; - /*0x64*/ u32 pokedexVar; - /*0x68*/ u32 pokedexFlag; - /*0x6C*/ u32 mysteryEventFlag; - /*0x70*/ u32 pokedexCount; - /*0x74*/ u8 playerNameLength; - /*0x75*/ u8 unk75; - /*0x76*/ u8 pokemonNameLength_1; - /*0x77*/ u8 pokemonNameLength_2; - /*0x78*/ u8 unk78; - /*0x79*/ u8 unk79; - /*0x7A*/ u8 unk7A; - /*0x7B*/ u8 unk7B; - /*0x7C*/ u8 unk7C; - /*0x7D*/ u8 unk7D; - /*0x7E*/ u8 unk7E; - /*0x7F*/ u8 unk7F; - /*0x80*/ u8 unk80; - /*0x81*/ u8 unk81; - /*0x82*/ u8 unk82; - /*0x83*/ u8 unk83; - /*0x84*/ u8 unk84; - /*0x88*/ size_t saveBlock2Size; - /*0x8C*/ size_t saveBlock1Size; - /*0x90*/ u32 playerPartyCountOffs; - /*0x94*/ u32 playerPartyOffs; - /*0x98*/ u32 sb2SpecialSaveWarpOffs; - /*0x9C*/ u32 sb2PlayerIdOffs; - /*0xA0*/ u32 sb2PlayerNameOffs; - /*0xA4*/ u32 sb2PlayerGenderOffs; - /*0xA8*/ u32 unkA8; - /*0xAC*/ u32 unkAC; - /*0xB0*/ u32 externalEventFlagsOffs; - /*0xB4*/ u32 externalEventDataOffs; - /*0xB8*/ u32 unkB8_0:1; - /*0xB8*/ u32 unkB8_1:1; - /*0xBC*/ const struct SpeciesInfo *baseStats; - /*0xC0*/ const u8 (*abilityNames)[][ABILITY_NAME_LENGTH + 1]; - /*0xC4*/ const u8 **abilityDescriptions; - /*0xC8*/ const struct Item *items; - /*0xCC*/ const struct BattleMove *battleMoves; - /*0xD0*/ const struct CompressedSpriteSheet *ballSpriteSheets; - /*0xD4*/ const struct CompressedSpritePalette *ballSpritePalettes; - /*0xD8*/ u32 gcnLinkFlagsOffs; - /*0xDC*/ s32 sysGameClearFlagIdx; - /*0xE0*/ u32 sysRibbonGetFlagIdx; - /*0xE4*/ u8 bagCountItems; - /*0xE5*/ u8 bagCountKeyItems; - /*0xE6*/ u8 bagCountPokeballs; - /*0xE7*/ u8 bagCountTMHMs; - /*0xE8*/ u8 bagCountBerries; - /*0xE9*/ u8 pcItemsCount; - /*0xEC*/ u32 pcItemsOffs; - /*0xF0*/ u32 giftRibbonsOffs; - /*0xF4*/ u32 enigmaBerryOffs; - /*0xF8*/ size_t enigmaBerrySize; - /*0xFC*/ const u8 *moveDescriptions; + u32 version; + u32 language; + u8 gameName[32]; + const struct CompressedSpriteSheet * monFrontPics; + const struct CompressedSpriteSheet * monBackPics; + const struct CompressedSpritePalette * monNormalPalettes; + const struct CompressedSpritePalette * monShinyPalettes; + const u8 * const * monIcons; + const u8 * monIconPaletteIds; + const struct SpritePalette * monIconPalettes; + const u8 (* monSpeciesNames)[][POKEMON_NAME_LENGTH + 1]; + const u8 (* moveNames)[][MOVE_NAME_LENGTH + 1]; + const struct Decoration * decorations; + u32 flagsOffset; + u32 varsOffset; + u32 pokedexOffset; + u32 seen1Offset; + u32 seen2Offset; + u32 pokedexVar; + u32 pokedexFlag; + u32 mysteryEventFlag; + u32 pokedexCount; + u8 playerNameLength; + u8 trainerNameLength; + u8 pokemonNameLength1; + u8 pokemonNameLength2; + u8 moveNameLength; + u8 itemNameLength; // No use case has been documented, purpose derived from leaks + u8 berryNameLength; //No use case has been documented, purpose derived from leaks + u8 abilityNameLength; //No use case has been documented, purpose derived from leaks + u8 typeNameLength; // No use case has been documented, purpose derived from leaks + u8 mapNameLength1; // No use case has been documented, purpose derived from leaks + u8 mapNameLength2; // No use case has been documented, purpose derived from leaks + u8 trainerClassNameLength; // No use case has been documented, purpose derived from leaks + u8 decorationNameLength; // No use case has been documented, purpose derived from leaks + u8 dexCategoryNameLength; // No use case has been documented, purpose derived from leaks + u8 endOfStringLength; + u8 frontierTrainerNameLength; // No use case has been documented, purpose derived from leaks + u8 easyChatWordLength; // No use case has been documented, purpose derived from leaks + u32 saveBlock2Size; + u32 saveBlock1Size; + u32 partyCountOffset; + u32 partyOffset; + u32 warpFlagsOffset; + u32 trainerIdOffset; + u32 playerNameOffset; + u32 playerGenderOffset; + u32 frontierStatusOffset; + u32 frontierStatusOffset2; + u32 externalEventFlagsOffset; + u32 externalEventDataOffset; + u32 blockLinkBoxRS:1; + u32 blockLinkColoXD:1; + u32 blockLinkUnused:30; + const struct SpeciesInfo * speciesInfo; + const u8 (* abilityNames)[][ABILITY_NAME_LENGTH + 1]; + const u8 **abilityDescriptions; + const struct Item * items; + const struct BattleMove * moves; + const struct CompressedSpriteSheet * ballGfx; + const struct CompressedSpritePalette * ballPalettes; + u32 gcnLinkFlagsOffset; + s32 gameClearFlag; + u32 ribbonFlag; + u8 bagCountItems; + u8 bagCountKeyItems; + u8 bagCountPokeballs; + u8 bagCountTMHMs; + u8 bagCountBerries; + u8 pcItemsCount; + u32 pcItemsOffset; + u32 giftRibbonsOffset; + u32 enigmaBerryOffset; + u32 enigmaBerrySize; + const u8 * moveDescriptions; }; -const struct RomInfo * gAgbPmRomParams; +const struct GFRomHeader * gAgbPmRomParams; extern void * gSaveBlock1Ptr; extern void * gSaveBlock1BakPtr; diff --git a/payload/include/libpmagb/berry.h b/payload/include/libpmagb/berry.h index 3ddbe4f..7e449b2 100644 --- a/payload/include/libpmagb/berry.h +++ b/payload/include/libpmagb/berry.h @@ -1,10 +1,10 @@ #ifndef PMAGB_BERRY_H #define PMAGB_BERRY_H -u32 GetEnigmaBerryChecksum(struct EnigmaBerry * enigmaBerry); +u32 UNUSED GetEnigmaBerryChecksum(struct EnigmaBerry * enigmaBerry); bool32 IsEnigmaBerryValid(void); const struct Berry *GetBerryInfo(u8 berry); const u8 *ItemId_GetName(u16 itemId); -void CopyItemName(u32 itemId, u8 *string, const u8 * berry_str); +void CopyItemName(u32 itemId, u8 *string, const u8 * berryString); #endif //PMAGB_BERRY_H diff --git a/payload/include/libpmagb/save.h b/payload/include/libpmagb/save.h index b7be5a0..c2eed79 100644 --- a/payload/include/libpmagb/save.h +++ b/payload/include/libpmagb/save.h @@ -14,6 +14,6 @@ bool32 sub_0200A2C8(s32 a); u8* ReadFirstSaveSector(void); void SetSaveSectorPtrs(void); u32 ReadSaveBlockChunks(void); -s32 sub_020098D8(u32 timerNum, IntrFunc * intrFunc); +s32 InitFlash(u32 timerNum, IntrFunc * intrFunc); #endif //PMAGB_SAVE_H diff --git a/payload/include/rom_info.h b/payload/include/rom_info.h index 1495dd8..f10e2be 100644 --- a/payload/include/rom_info.h +++ b/payload/include/rom_info.h @@ -1,9 +1,9 @@ #ifndef GUARD_ROM_INFO_H #define GUARD_ROM_INFO_H -extern struct RomInfo gAgbPmRomParams_AXVE_rev0; -extern struct RomInfo gAgbPmRomParams_AXVE_rev2; -extern struct RomInfo gAgbPmRomParams_AXPE_rev0; -extern struct RomInfo gAgbPmRomParams_AXPE_rev2; +extern struct GFRomHeader gAgbPmRomParams_AXVE_rev0; +extern struct GFRomHeader gAgbPmRomParams_AXVE_rev2; +extern struct GFRomHeader gAgbPmRomParams_AXPE_rev0; +extern struct GFRomHeader gAgbPmRomParams_AXPE_rev2; #endif // GUARD_ROM_INFO_H diff --git a/payload/src/all.c b/payload/src/all.c index 8996e7d..05bf86f 100644 --- a/payload/src/all.c +++ b/payload/src/all.c @@ -588,7 +588,7 @@ inline void PutMonGenderOnBgTilemap(int x, int y, u32 monId) inline void CopyMonIconToVram(struct UnkSpriteMonIconStruct *ptr, u32 a1) { - CpuCopy16(&gAgbPmRomParams->monIconTable[ptr->speciesIcon][a1 * 512], (void *)VRAM + 0x10000 + (ptr->unk8 * 32), 512); + CpuCopy16(&gAgbPmRomParams->monIcons[ptr->speciesIcon][a1 * 512], (void *)VRAM + 0x10000 + (ptr->unk8 * 32), 512); } inline void sub_2002E70(s32 a0) @@ -630,25 +630,25 @@ inline void sub_02002EE0(struct Window *win, struct UnkSpriteMonIconStruct *r9) void CreateMonIcon(struct Sprite *sprite) { u32 r1; - if (sprite->unk14[1] == 7 || sprite->unk14[1] == 20) + if (sprite->data[1] == 7 || sprite->data[1] == 20) { - struct UnkSpriteMonIconStruct *ptr = (void *)sprite->unk14[0]; + struct UnkSpriteMonIconStruct *ptr = (void *)sprite->data[0]; if (ptr->statusPrimary != STATUS_PRIMARY_FAINTED) { - sprite->unk14[1] = 0; - sprite->unk14[2]++; + sprite->data[1] = 0; + sprite->data[2]++; } - else if (sprite->unk14[1] == 7) + else if (sprite->data[1] == 7) { - sprite->unk14[1]++; + sprite->data[1]++; return; } else { - sprite->unk14[1] = 0; + sprite->data[1] = 0; } - r1 = sprite->unk14[2] & 1; + r1 = sprite->data[2] & 1; CopyMonIconToVram(ptr, r1); SetSpritePos(sprite, ptr->unk1, ptr->unk2); if (gUnknown_02021860.unk11B == ptr->monId) @@ -662,7 +662,7 @@ void CreateMonIcon(struct Sprite *sprite) } else { - sprite->unk14[1]++; + sprite->data[1]++; } } @@ -715,9 +715,9 @@ u32 sub_02000CA4(struct UnkSpriteMonIconStruct *a0, u32 monId, s32 x, s32 y) personality = GetMonData(&gPlayerPartyPtr[monId], MON_DATA_PERSONALITY, NULL); a0->speciesIcon = FixUnownSpecies(a0->species, personality); sprite = AddSprite(x, y, gUnknown_0201F9F4); - sprite->unk14[0] = (uintptr_t)(a0); + sprite->data[0] = (uintptr_t)(a0); sprite->callback = CreateMonIcon; - SetSpritePaletteNum(sprite, gAgbPmRomParams->gMonIconPaletteIndices[a0->species]); + SetSpritePaletteNum(sprite, gAgbPmRomParams->monIconPaletteIds[a0->species]); SetSpriteTileOffset(sprite, a0->unk8); CopyMonIconToVram(a0, 1); a0->monSprite = sprite; @@ -755,7 +755,7 @@ void sub_02000D74(struct Unk02021860Struct *a0, const struct Unk02000D74Struct * SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 5); } - r9->unk14 = CreateSomeWindowParameterized(1, coords->x + 4, coords->y + 1, gAgbPmRomParams->pokemonNameLength_2, 2, 8); + r9->unk14 = CreateSomeWindowParameterized(1, coords->x + 4, coords->y + 1, gAgbPmRomParams->pokemonNameLength2, 2, 8); GetMonData(&gPlayerPartyPtr[monId], MON_DATA_NICKNAME, monName); SomeMonNameStrMagic(monName, sp32, GetStringSizeHandleExtCtrlCodes(monName)); if (GetMonData(&gPlayerPartyPtr[monId], MON_DATA_LANGUAGE, monName) != LANGUAGE_JAPANESE) @@ -847,7 +847,7 @@ void sub_02001258(struct Unk02021860Struct *a0, const struct Unk02000D74Struct * SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 5); } - r9->unk14 = CreateSomeWindowParameterized(1, coords->x + 3, coords->y, gAgbPmRomParams->pokemonNameLength_2, 2, 8); + r9->unk14 = CreateSomeWindowParameterized(1, coords->x + 3, coords->y, gAgbPmRomParams->pokemonNameLength2, 2, 8); GetMonData(&gPlayerPartyPtr[monId], MON_DATA_NICKNAME, monName); SomeMonNameStrMagic(monName, sp32, GetStringSizeHandleExtCtrlCodes(monName)); if (GetMonData(&gPlayerPartyPtr[monId], MON_DATA_LANGUAGE, monName) != LANGUAGE_JAPANESE) @@ -941,7 +941,7 @@ void sub_020017E8(struct Unk02021860Struct *a0) { s32 i; const struct Unk02000D74Struct *coords; - const struct SpritePalette *monIconPaletteTable; + const struct SpritePalette *monIconPalettes; sSomeWindowBaseBlock = 0x80; ClearVram(); @@ -960,8 +960,8 @@ void sub_020017E8(struct Unk02021860Struct *a0) AutoUnCompVram(gTypeStatusIcons_Gfx, (void *) VRAM + 0x10000); sub_2002E70(gUnknown_02021860.unk118); gBgTilemapBufferTransferScheduled[1] = TRUE; - monIconPaletteTable = gAgbPmRomParams->monIconPaletteTable; - DmaCopy16(3, monIconPaletteTable[0].data, (void *) PLTT + 0x200, 0x60); + monIconPalettes = gAgbPmRomParams->monIconPalettes; + DmaCopy16(3, monIconPalettes[0].data, (void *) PLTT + 0x200, 0x60); AutoUnCompVram(gPartySlots_Tilemap, (void *) VRAM + 0x14000); if (a0->unk11A == 0) coords = gUnknown_0201F9BC; diff --git a/payload/src/all2.c b/payload/src/all2.c index 31cb33e..15063b7 100644 --- a/payload/src/all2.c +++ b/payload/src/all2.c @@ -66,7 +66,7 @@ extern const struct Subsprites gUnknown_0201FA5C[]; extern const struct Subsprites gUnknown_0201FA74[]; static void sub_02003D80(u32 monId, bool32 a1); -static void sub_0200461C(struct Sprite *sprite); +static void SpriteCB_MoveSelector(struct Sprite *sprite); // This file's functions static void sub_02002FEC(void) @@ -102,7 +102,7 @@ static void CreatePartyMonFrontPic(struct UnkStruct02021990 *a0, u32 monId, s32 const struct CompressedSpritePalette *frontPicPal; u32 personality; bool32 noFlip; - const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats; + const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->speciesInfo; a0->species = GetMonData(&gPlayerPartyPtr[monId], MON_DATA_SPECIES, NULL); if (a0->species == SPECIES_NONE) @@ -116,7 +116,7 @@ static void CreatePartyMonFrontPic(struct UnkStruct02021990 *a0, u32 monId, s32 noFlip = speciesInfo[a0->species].noFlip; DelayFrames(1); - frontPicSheet = &gAgbPmRomParams->monFrontPicTable[a0->speciesPic]; + frontPicSheet = &gAgbPmRomParams->monFrontPics[a0->speciesPic]; bufferPic = GetPicUncompPtr(); LZ77UnCompVram(frontPicSheet->data, bufferPic); DrawSpindasSpots(a0->species, personality, bufferPic); @@ -295,7 +295,7 @@ static void sub_0200378C(u32 monId) u32 move, moveType; s32 ppCurr, ppBonuses, ppMax; struct Pokemon *mon = &gPlayerPartyPtr[monId]; - const struct BattleMove *battleMoves = gAgbPmRomParams->battleMoves; + const struct BattleMove *moves = gAgbPmRomParams->moves; SetTextColor(gUnknown_02021990.unk24, 1, 8); SetBgTilemapBufferPaletteRect(0, 24, 4, 5, 8, 15); @@ -307,7 +307,7 @@ static void sub_0200378C(u32 monId) ppCurr = GetBoxMonPPByMoveSlot(&mon->box, i); ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); ppMax = CalculatePPWithBonus(move, ppBonuses, i); - moveType = battleMoves[move].type; + moveType = moves[move].type; gUnknown_02021990.unk44[i] = move; if (gUnknown_02021990.unk2C[i] == NULL) @@ -372,7 +372,7 @@ static void sub_02003A70(u32 monId, u32 moveSlot) { u8 text[8]; struct Pokemon *mon = &gPlayerPartyPtr[monId]; - const struct BattleMove *battleMoves = gAgbPmRomParams->battleMoves; + const struct BattleMove *moves = gAgbPmRomParams->moves; FillWindowCharBufferRect(gUnknown_02021990.unk20, 6, 3, 3, 4, 0); SetBgTilemapBufferPaletteRect(0, 7, 15, 3, 4, 15); @@ -390,25 +390,25 @@ static void sub_02003A70(u32 monId, u32 moveSlot) { TextWindowSetXY(gUnknown_02021990.unk20, 52, 24); gUnknown_02021990.unk20->glyphWidth = 6; - if (battleMoves[move].power <= 1) + if (moves[move].power <= 1) { RenderText(gUnknown_02021990.unk20, gText_3Dashes); } else { - NumToPmString3RightAlign(text, battleMoves[move].power); + NumToPmString3RightAlign(text, moves[move].power); RenderText(gUnknown_02021990.unk20, text); } TextWindowSetXY(gUnknown_02021990.unk20, 52, 40); gUnknown_02021990.unk20->glyphWidth = 6; - if (battleMoves[move].accuracy == 0) + if (moves[move].accuracy == 0) { RenderText(gUnknown_02021990.unk20, gText_3Dashes); } else { - NumToPmString3RightAlign(text, battleMoves[move].accuracy); + NumToPmString3RightAlign(text, moves[move].accuracy); RenderText(gUnknown_02021990.unk20, text); } } @@ -682,7 +682,7 @@ static s32 sub_020040FC(s32 monId) gUnknown_02021990.unk4E = 0; gUnknown_02021990.unk40 = AddSprite(80, 32, gUnknown_0201FA74); SetSpritePaletteNum(gUnknown_02021990.unk40, 5); - gUnknown_02021990.unk40->callback = sub_0200461C; + gUnknown_02021990.unk40->callback = SpriteCB_MoveSelector; CopyRectWithinBgTilemapBuffer(2, 0, 20, 20, 3, 10, 11); TextWindowSetXY(gUnknown_02021990.unk24, 32, 72); RenderText(gUnknown_02021990.unk24, gText_Cancel3); @@ -827,9 +827,9 @@ static void sub_20045B8_(s32 monId, u32 moveSlot) } } -static void sub_0200461C(struct Sprite *sprite) +static void SpriteCB_MoveSelector(struct Sprite *sprite) { - switch (sprite->unk14[0]) + switch (sprite->data[0]) { case 1: SetSpriteInvisible(sprite, FALSE); @@ -838,9 +838,9 @@ static void sub_0200461C(struct Sprite *sprite) SetSpriteInvisible(sprite, TRUE); break; case 39: - sprite->unk14[0] = 0; + sprite->data[0] = 0; break; } - sprite->unk14[0]++; + sprite->data[0]++; } diff --git a/payload/src/all4.c b/payload/src/all4.c index a14c49f..b5036f2 100644 --- a/payload/src/all4.c +++ b/payload/src/all4.c @@ -128,7 +128,7 @@ u32 sub_020047D4(void) gUnknown_02024960.unk_87B = 4; sub_0200465C(); - if (gAgbPmRomParams->unkB8_1 || !gRomDetection_IsEnglishROM) + if (gAgbPmRomParams->blockLinkColoXD || !gRomDetection_IsEnglishROM) { u8 UNUSED buff[8]; // Needed to match stack. OverrideScreenFadeState(TRUE); @@ -257,7 +257,7 @@ void sub_02004BEC(struct Unk2021A20Str *a0, u32 monId, s32 x, s32 y) void *buffer; u32 personality; const struct CompressedSpriteSheet *monFrontSheet; - const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats; + const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->speciesInfo; a0->unkC = gUnknown_02024960.unk10; if (a0->unkC == SPECIES_NONE) @@ -270,7 +270,7 @@ void sub_02004BEC(struct Unk2021A20Str *a0, u32 monId, s32 x, s32 y) a0->unk0 = AddSprite(x, y, gUnknown_0201FC44[speciesInfo[a0->unkC].noFlip]); SetSpritePaletteNum(a0->unk0, 4); - monFrontSheet = &gAgbPmRomParams->monFrontPicTable[a0->unkE]; + monFrontSheet = &gAgbPmRomParams->monFrontPics[a0->unkE]; buffer = GetPicUncompPtr(); LZ77UnCompVram(monFrontSheet->data, buffer); if (a0->unkC == SPECIES_CASTFORM) @@ -544,11 +544,11 @@ void sub_02005168(s32 id) u8 text[16]; s32 ppBonuses, ppTotal, ppCurr, type; struct Pokemon *mon = &gPlayerPartyPtr[gUnknown_02020A48]; - const struct BattleMove *battleMoves = gAgbPmRomParams->battleMoves; + const struct BattleMove *moves = gAgbPmRomParams->moves; u32 move = gUnknown_02024960.unk14[id]; FillWindowCharBufferRect(gUnknown_02021A20.unk18, 22, 2, 6, 2, 0); - type = battleMoves[move].type; + type = moves[move].type; RenderTextAt(gUnknown_02021A20.unk18, 176, 16, gTypeNames[type]); FillWindowCharBufferRect(gUnknown_02021A20.unk18, 24, 0, 4, 2, 0); @@ -625,7 +625,7 @@ u8 *sub_0200531C(s32 id) txtPtr[5] = 0x15; len = 6; } - for (i = 0; i < gAgbPmRomParams->pokemonNameLength_2; i++) + for (i = 0; i < gAgbPmRomParams->pokemonNameLength2; i++) { if (gUnknown_02024960.unk81C[id].str[i] == EOS) break; @@ -1074,15 +1074,15 @@ bool32 sub_02005FCC(void) extern u8 gRomDetection_IsRubySapphire; -static inline u16 Test(const struct RomInfo *rom, void *sav2) +static inline u16 Test(const struct GFRomHeader *rom, void *sav2) { - u16 *ptr = sav2 + rom->gcnLinkFlagsOffs; + u16 *ptr = sav2 + rom->gcnLinkFlagsOffset; return *ptr; } -static inline u8 Test2(const struct RomInfo *rom, void *sav2) +static inline u8 Test2(const struct GFRomHeader *rom, void *sav2) { - u8 *ptr = sav2 + rom->sb2SpecialSaveWarpOffs; + u8 *ptr = sav2 + rom->warpFlagsOffset; return *ptr; } diff --git a/payload/src/gflib/bg.c b/payload/src/gflib/bg.c index b1ded6d..e4be7d4 100644 --- a/payload/src/gflib/bg.c +++ b/payload/src/gflib/bg.c @@ -1,9 +1,9 @@ #include "global.h" #include "gflib/bg.h" -u16 gBgHofsBuffer[4]; -u16 gBgVofsBuffer[4]; -bool8 gBgTilemapBufferTransferScheduled[4]; +u16 gBgHofsBuffer[NUM_BACKGROUNDS]; +u16 gBgVofsBuffer[NUM_BACKGROUNDS]; +bool8 gBgTilemapBufferTransferScheduled[NUM_BACKGROUNDS]; u32 filler1; u32 filler2; u32 filler3; @@ -13,8 +13,9 @@ void DoGpuUpdateAndTilemapTransfers(void) s32 i; u16 bgCnt; void * screenBase; - size_t size; + u32 size; s32 r2; + REG_BG0HOFS = gBgHofsBuffer[0]; REG_BG1HOFS = gBgHofsBuffer[1]; REG_BG2HOFS = gBgHofsBuffer[2]; @@ -23,7 +24,7 @@ void DoGpuUpdateAndTilemapTransfers(void) REG_BG1VOFS = gBgVofsBuffer[1]; REG_BG2VOFS = gBgVofsBuffer[2]; REG_BG3VOFS = gBgVofsBuffer[3]; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BACKGROUNDS; i++) { if (gBgTilemapBufferTransferScheduled[i]) { @@ -47,9 +48,9 @@ void ResetGpuBuffers(void) gBgTilemapBufferTransferScheduled[0] = 0; } -void CopyToBgTilemapBufferRect(int bgNum, int left, int top, int width, int height, const u16 * src) +void CopyToBgTilemapBufferRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, const u16 * src) { - int x; + s32 x; u16 * ptr = (void *)(gBGTilemapBuffers + (bgNum << 12) + (top << 6) + (left << 1)); while (height) @@ -63,9 +64,9 @@ void CopyToBgTilemapBufferRect(int bgNum, int left, int top, int width, int heig } } -void CopyFromBgTilemapBufferRect(int bgNum, int left, int top, int width, int height, u16 * dest) +void UNUSED CopyFromBgTilemapBufferRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, u16 * dest) { - int x; + s32 x; u16 * ptr = (void *)(gBGTilemapBuffers + (bgNum << 12) + (top << 6) + (left << 1)); while (height) @@ -79,9 +80,9 @@ void CopyFromBgTilemapBufferRect(int bgNum, int left, int top, int width, int he } } -void SetBgTilemapBufferPaletteRect(int bgNum, int left, int top, int width, int height, int paletteNum) +void SetBgTilemapBufferPaletteRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, u32 paletteNum) { - int x; + s32 x; u16 * ptr = (void *)(gBGTilemapBuffers + (bgNum << 12) + (top << 6) + (left << 1)); while (height) @@ -96,15 +97,15 @@ void SetBgTilemapBufferPaletteRect(int bgNum, int left, int top, int width, int } } -void SetBgTilemapBufferTileAt(int bgNum, int x, int y, u16 tileNum) +void SetBgTilemapBufferTileAt(u32 bgNum, u32 x, u32 y, u16 tileNum) { u16 * ptr = (void *)(gBGTilemapBuffers + (bgNum << 12) + (y << 6) + (x << 1)); *ptr = tileNum; } -void FillBgTilemapBufferRect(int bgNum, int left, int top, int width, int height, u16 tileNum) +void FillBgTilemapBufferRect(u32 bgNum, u32 left, u32 top, s32 width, u32 height, u16 tileNum) { - int x; + s32 x; u16 * ptr = (void *)(gBGTilemapBuffers + (bgNum << 12) + (top << 6) + (left << 1)); while (height) @@ -118,9 +119,9 @@ void FillBgTilemapBufferRect(int bgNum, int left, int top, int width, int height } } -void CopyRectWithinBgTilemapBuffer(int bgNum, int srcLeft, int srcTop, int width, int height, int destLeft, int destTop) +void CopyRectWithinBgTilemapBuffer(u32 bgNum, u32 srcLeft, u32 srcTop, s32 width, u32 height, u32 destLeft, u32 destTop) { - int x; + s32 x; const u16 * srcPtr; u16 * destPtr; @@ -139,7 +140,7 @@ void CopyRectWithinBgTilemapBuffer(int bgNum, int srcLeft, int srcTop, int width } } -void SetBgPos(int bgNum, s32 x, s32 y) +void SetBgPos(u32 bgNum, s32 x, s32 y) { gBgHofsBuffer[bgNum] = x; gBgVofsBuffer[bgNum] = y; diff --git a/payload/src/gflib/init.c b/payload/src/gflib/init.c index 5514d64..8e7f203 100644 --- a/payload/src/gflib/init.c +++ b/payload/src/gflib/init.c @@ -13,9 +13,9 @@ IntrFunc gIntrTable[14u]; u32 gVBlankCounter; IntrFunc gVBlankCallback; -void InitIntr(void); -void VBlankIntr(void); -void IntrDummy(void); +static void InitIntr(void); +static void VBlankIntr(void); +static void IntrDummy(void); #define SR_KEYS (A_BUTTON | B_BUTTON | SELECT_BUTTON | START_BUTTON) @@ -37,9 +37,9 @@ u32 GetFrameTotal(void) return gVBlankCounter; } -void DelayFrames(u32 a0) +void DelayFrames(u32 frames) { - for (; a0 != 0; a0--) + for (; frames != 0; frames--) { UpdateSprites(); VBlankIntrWait(); @@ -49,19 +49,22 @@ void DelayFrames(u32 a0) } } -void InitIntr(void) +static void InitIntr(void) { - int i; + u32 i; + gVBlankCallback = NULL; + for (i = 0; i < 14u; i++) gIntrTable[i] = IntrDummy; + if (VBlankIntr != NULL) gIntrTable[1] = VBlankIntr; else gIntrTable[1] = IntrDummy; } -void SetIntrFunc(int i, IntrFunc func) +void SetIntrFunc(u32 i, IntrFunc func) { if (func != NULL) gIntrTable[i] = func; @@ -77,21 +80,24 @@ void SetVBlankCallback(IntrFunc cb) REG_IME = imeBak; } -void VBlankIntr(void) +static void VBlankIntr(void) { if (EnableSoundVSync(0)) m4aSoundVSync(); + DoOamBufferTransfer(); DoGpuUpdateAndTilemapTransfers(); gVBlankCounter++; INTR_CHECK = INTR_FLAG_VBLANK; + if (gVBlankCallback != NULL) gVBlankCallback(); + if (EnableSoundVSync(1)) m4aSoundMain(); } -void IntrDummy(void) +static void IntrDummy(void) { } diff --git a/payload/src/gflib/keys.c b/payload/src/gflib/keys.c index 1871d2e..f2102c4 100644 --- a/payload/src/gflib/keys.c +++ b/payload/src/gflib/keys.c @@ -12,9 +12,10 @@ static u16 sKeyRepeatTimer; void ReadKeys(void) { u32 keyInput; - u16 * prevKeys_p = &gHeldKeys; - u16 newKeys = (keyInput = REG_KEYINPUT ^ KEYS_MASK) & ~*prevKeys_p; + u16 * prevKeys = &gHeldKeys; + u16 newKeys = (keyInput = REG_KEYINPUT ^ KEYS_MASK) & ~*prevKeys; gNewKeys = newKeys; + if (gHeldKeys != keyInput) { gNewAndRepeatedKeys = keyInput; @@ -29,6 +30,7 @@ void ReadKeys(void) { gNewAndRepeatedKeys = 0; } + gHeldKeys = keyInput; } diff --git a/payload/src/gflib/sound.c b/payload/src/gflib/sound.c index 4871cd0..b75fabb 100644 --- a/payload/src/gflib/sound.c +++ b/payload/src/gflib/sound.c @@ -1,27 +1,28 @@ #include "global.h" #include "gflib/sound.h" -static u8 gUnknown_02021368; -static bool8 isSoundVsync; +static bool8 sIsSoundVSyncPaused; +static bool8 sIsSoundVsync; void InitSound(void) { - gUnknown_02021368 = 0; - isSoundVsync = 0; + sIsSoundVSyncPaused = 0; + sIsSoundVsync = FALSE; m4aSoundInit(); } void PauseSoundVSync(void) { - gUnknown_02021368 = 1; - isSoundVsync = 0; + sIsSoundVSyncPaused = 1; + sIsSoundVsync = FALSE; } -bool32 EnableSoundVSync(u32 a0) +bool32 EnableSoundVSync(u32 enable) { - if (a0 && gUnknown_02021368) - isSoundVsync = 1; - return isSoundVsync; + if (enable && sIsSoundVSyncPaused) + sIsSoundVsync = TRUE; + + return sIsSoundVsync; } void PlaySE(u16 song) @@ -33,7 +34,7 @@ void PlaySE(u16 song) m4aMPlayImmInit(mPlayInfo); } -void StopSE(u16 song) +void UNUSED StopSE(u16 song) { struct MusicPlayerInfo * mPlayInfo; @@ -41,21 +42,21 @@ void StopSE(u16 song) m4aMPlayStop(mPlayInfo); } -void StopAllSound(void) +void UNUSED StopAllSound(void) { m4aMPlayAllStop(); } -bool8 sub_020093AC(void) +bool8 UNUSED ReturnTrue(void) { return TRUE; } -void FadeOutSE(u16 song, u16 _speed) +void UNUSED FadeOutSE(u16 song, u16 _speed) { struct MusicPlayerInfo * mPlayInfo; - u16 speed = _speed >> 4; + if (speed == 0) speed = 1; @@ -63,7 +64,7 @@ void FadeOutSE(u16 song, u16 _speed) m4aMPlayFadeOut(mPlayInfo, speed); } -void SetSEVolume(u16 song, u16 volume) +void UNUSED SetSEVolume(u16 song, u16 volume) { struct MusicPlayerInfo * mPlayInfo; @@ -71,7 +72,7 @@ void SetSEVolume(u16 song, u16 volume) m4aMPlayVolumeControl(mPlayInfo, 0xFF, volume); } -void SetSETempo(u16 song, u16 tempo) +void UNUSED SetSETempo(u16 song, u16 tempo) { struct MusicPlayerInfo * mPlayInfo; @@ -79,7 +80,7 @@ void SetSETempo(u16 song, u16 tempo) m4aMPlayTempoControl(mPlayInfo, tempo); } -void SetSEPitch(u16 song, s16 pitch) +void UNUSED SetSEPitch(u16 song, s16 pitch) { struct MusicPlayerInfo * mPlayInfo; @@ -89,12 +90,12 @@ void SetSEPitch(u16 song, s16 pitch) void SoundVSyncOff(void) { - isSoundVsync = 0; + sIsSoundVsync = FALSE; m4aSoundVSyncOff(); } void SoundVSyncOn(void) { m4aSoundVSyncOn(); - isSoundVsync = 1; + sIsSoundVsync = TRUE; } diff --git a/payload/src/gflib/sprite.c b/payload/src/gflib/sprite.c index 86d44d8..dda5f5d 100644 --- a/payload/src/gflib/sprite.c +++ b/payload/src/gflib/sprite.c @@ -11,36 +11,37 @@ struct OamBuffer static struct OamBuffer sOamBuffer; -void InsertSprite(struct Sprite * a0, struct Sprite * a1) +static void InsertSprite(struct Sprite * sprite1, struct Sprite * sprite2) { - a1->next = a0->next; - a1->prev = a0 - sSprites; - a0->next = sSprites[a0->next].prev = a1 - sSprites; + sprite2->next = sprite1->next; + sprite2->prev = sprite1 - sSprites; + sprite1->next = sSprites[sprite1->next].prev = sprite2 - sSprites; } struct Sprite * AddSprite(s32 x, s32 y, const struct Subsprites * subsprites) { s32 i; - struct Sprite * r7 = &sSprites[sSprites[0].next]; - sSprites[r7->prev].next = r7->next; - sSprites[r7->next].prev = r7->prev; - InsertSprite(&sSprites[1], r7); - r7->x = x; - r7->y = y; - r7->spriteTemplates = subsprites; - r7->flag = 0; - r7->paletteNum = 0; - r7->tileOffset = 0; - r7->callback = NULL; + struct Sprite * newSprite = &sSprites[sSprites[0].next]; + + sSprites[newSprite->prev].next = newSprite->next; + sSprites[newSprite->next].prev = newSprite->prev; + InsertSprite(&sSprites[1], newSprite); + newSprite->x = x; + newSprite->y = y; + newSprite->spriteTemplates = subsprites; + newSprite->flag = 0; + newSprite->paletteNum = 0; + newSprite->tileOffset = 0; + newSprite->callback = NULL; for (i = 0; i < 4; i++) - r7->unk14[i] = 0; - return r7; + newSprite->data[i] = 0; + return newSprite; } -void BufferSpriteOAM(struct Sprite * ptr) +static void BufferSpriteOAM(struct Sprite * sprite) { - u32 num_sprites; - struct OamData * oam_p; + u32 numSprites; + struct OamData * oam; const struct Subsprites * templates; s32 width; s32 left; @@ -49,16 +50,16 @@ void BufferSpriteOAM(struct Sprite * ptr) u32 size; u32 flags; - num_sprites = sOamBuffer.numSprites; - oam_p = &sOamBuffer.oamBuffer[num_sprites]; + numSprites = sOamBuffer.numSprites; + oam = &sOamBuffer.oamBuffer[numSprites]; + templates = sprite->spriteTemplates; - templates = ptr->spriteTemplates; while (templates->oam != 0xFFFF) { - if (num_sprites == 0x80) + if (numSprites == 0x80) return; - if ((left = templates->x + ptr->x) < 0xF0 && (top = templates->y + ptr->y) < 0xA0) + if ((left = templates->x + sprite->x) < 0xF0 && (top = templates->y + sprite->y) < 0xA0) { size = ((templates->oam & 0xC000) >> 12) + (templates->oam >> 30); flags = templates->oam; @@ -117,43 +118,43 @@ void BufferSpriteOAM(struct Sprite * ptr) { left &= 0x1FF; top &= 0xFF; - *(u32 *)oam_p = top | ((left << 16) | flags); - *((u16 *)oam_p + 2) = ((templates->baseBlock & 0xFFF) | ptr->paletteNum) + ptr->tileOffset; - oam_p++; - num_sprites++; + *(u32 *)oam = top | ((left << 16) | flags); + *((u16 *)oam + 2) = ((templates->baseBlock & 0xFFF) | sprite->paletteNum) + sprite->tileOffset; + oam++; + numSprites++; } } } templates++; } - sOamBuffer.numSprites = num_sprites; + sOamBuffer.numSprites = numSprites; } void UpdateSprites(void) { - s32 r2; + s32 numSprites; s32 i; - struct OamData * r4; - struct Sprite * ptr; + struct OamData * oam; + struct Sprite * sprite; i = sSprites[1].next; while (i != 1) { - ptr = &sSprites[i]; + sprite = &sSprites[i]; - if (ptr->callback != NULL) - ptr->callback(ptr); + if (sprite->callback != NULL) + sprite->callback(sprite); - if (!(ptr->flag & 1)) - BufferSpriteOAM(ptr); - i = ptr->next; + if (!(sprite->flag & 1)) + BufferSpriteOAM(sprite); + i = sprite->next; } - r4 = &sOamBuffer.oamBuffer[sOamBuffer.numSprites]; - for (r2 = sOamBuffer.numSprites; r2 < 0x80 && *(u16 *)r4 != 0x200; r2++, r4++) + oam = &sOamBuffer.oamBuffer[sOamBuffer.numSprites]; + for (numSprites = sOamBuffer.numSprites; numSprites < 0x80 && *(u16 *)oam != 0x200; numSprites++, oam++) { - *(u16 *)r4 = 0x200; + *(u16 *)oam = 0x200; } sOamBuffer.numSprites = 0; } @@ -161,8 +162,8 @@ void UpdateSprites(void) void ResetSprites(void) { s32 i; - struct OamData * r2; - struct Sprite * r4; + struct OamData * oam; + struct Sprite * sprite; CpuFill16(0, sSprites, sizeof(sSprites)); sSprites[0].next = 0; @@ -175,16 +176,16 @@ void ResetSprites(void) InsertSprite(&sSprites[0], &sSprites[i]); } sOamBuffer.numSprites = 0; - r2 = &sOamBuffer.oamBuffer[0]; - for (i = 0; i < 0x80; i++, r2++) - *(u16 *)r2 = 0x200; + oam = &sOamBuffer.oamBuffer[0]; + for (i = 0; i < 0x80; i++, oam++) + *(u16 *)oam = 0x200; } -void MoveSpriteToHead(struct Sprite * a0) +void MoveSpriteToHead(struct Sprite * sprite) { - sSprites[a0->prev].next = a0->next; - sSprites[a0->next].prev = a0->prev; - InsertSprite(&sSprites[0], a0); + sSprites[sprite->prev].next = sprite->next; + sSprites[sprite->next].prev = sprite->prev; + InsertSprite(&sSprites[0], sprite); } void DoOamBufferTransfer(void) @@ -192,29 +193,29 @@ void DoOamBufferTransfer(void) DmaCopy32(3, sOamBuffer.oamBuffer, (void *)OAM, OAM_SIZE); } -void SetSpritePos(struct Sprite * r0, s32 r1, s32 r2) +void SetSpritePos(struct Sprite * sprite, s32 x, s32 y) { - r0->x = r1; - r0->y = r2; + sprite->x = x; + sprite->y = y; } -void AddSpritePos(struct Sprite * r0, s32 r1, s32 r2) +void AddSpritePos(struct Sprite * sprite, s32 x, s32 y) { - r0->x += r1; - r0->y += r2; + sprite->x += x; + sprite->y += y; } -void SetSpritePaletteNum(struct Sprite * r0, s32 r1) +void SetSpritePaletteNum(struct Sprite * sprite, s32 paletteNum) { - r0->paletteNum = r1 << 12; + sprite->paletteNum = paletteNum << 12; } -void SetSpriteTileOffset(struct Sprite * r0, s32 r1) +void SetSpriteTileOffset(struct Sprite * sprite, s32 tileOffset) { - r0->tileOffset = r1; + sprite->tileOffset = tileOffset; } -void SetSpriteInvisible(struct Sprite * r0, s32 r1) +void SetSpriteInvisible(struct Sprite * sprite, s32 invisible) { - r0->flag = ((r0->flag & ~1) | r1); + sprite->flag = ((sprite->flag & ~1) | invisible); } diff --git a/payload/src/gflib/text.c b/payload/src/gflib/text.c index d9b523a..981e8d9 100644 --- a/payload/src/gflib/text.c +++ b/payload/src/gflib/text.c @@ -11,9 +11,12 @@ static inline void *GetAddr(struct Window *window) { void *vaddr = window->vramCharBase + (window->currentY / 8) * window->width * 32; u32 x = window->currentX; + vaddr += 32 * (x / 8); // Needed to match. - x++;x--; + x++; + x--; + return vaddr; } @@ -30,6 +33,7 @@ void DrawGlyphOnWindow_NoShadow(struct Window * window, u32 glyphId, u32 fgColor xpixel = 8 - (window->currentX & 7); glyphData = window->glyphGfx + glyphId * window->glyphSize; curpos--; + for (i = 0; i < window->glyphSize; i++) { if (i != 8) @@ -66,6 +70,7 @@ void DrawGlyphOnWindow_WithShadow(struct Window *window, u32 glyphId, u32 fgColo xpixel = 8 - (window->currentX & 7); glyphData = window->glyphGfx + (glyphId * window->glyphSize * 2); + for (i = 0; i < window->glyphSize; i++) { vaddr = window->vramCharBase + ((window->currentY + i) >> 3) * window->width * 32 + (32 * (window->currentX >> 3)); @@ -101,9 +106,9 @@ void DrawGlyphOnWindow_WithShadow(struct Window *window, u32 glyphId, u32 fgColo static inline void TextWindowFillTileBufferForText_Inline(struct Window *win) { s32 i, j; - u16 *addr = (void *) IWRAM_START + (win->bg << 12); u16 blockVal = win->baseBlock; + for (i = win->top; i < win->top + win->height; i++) { for (j = win->left; j < win->left + win->width; j++) @@ -153,6 +158,7 @@ void GenerateFontHalfrowLookupTable(u32 *ptr) s32 i; sFontHalfrowLookupTablePtr = ptr; + for (i = 0; i <= 0xFF; i++) { u32 r1 = 0; @@ -178,9 +184,9 @@ void GenerateFontHalfrowLookupTable(u32 *ptr) } } -void ClearWindowCharBuffer(struct Window *window, u32 a1) +void ClearWindowCharBuffer(struct Window *window, u32 fillValue) { - CpuFill16(a1, window->vramCharBase, (window->width * window->height) * 32); + CpuFill16(fillValue, window->vramCharBase, (window->width * window->height) * 32); TextWindowSetXY(window, 0, 0); } @@ -220,7 +226,7 @@ void TextWindowShiftXY(struct Window * window, s32 dx, s32 dy) window->currentY += dy; } -void TextWindowPrintSimpleString(struct Window * window, const u8 * glyphs) +void UNUSED TextWindowPrintSimpleString(struct Window * window, const u8 * glyphs) { while (*glyphs != 0) { diff --git a/payload/src/libpmagb/agb_rom.c b/payload/src/libpmagb/agb_rom.c index 7971f23..2484f20 100644 --- a/payload/src/libpmagb/agb_rom.c +++ b/payload/src/libpmagb/agb_rom.c @@ -19,7 +19,7 @@ u16 * gVarsPtr; u8 * gGiftRibbonsPtr; struct EnigmaBerry * gEnigmaBerryPtr; -u16 SaveRandom(void); +static u16 SaveRandom(void); void * gLastSaveBlockPtr; u8 gSaveBlockLoadRegions[0xE000]; @@ -36,8 +36,10 @@ static inline void SeedSaveRng(void) { sum += firstSector[i]; } + gLastSaveBlockPtr = gSaveBlockLoadRegions + 4 * (sum & 0xFF); gSaveRngValue = sum; + for (i = 0; i < (sum & 0xFF); i++) { SaveRandom(); @@ -47,7 +49,9 @@ static inline void SeedSaveRng(void) static inline void * UpdateSaveBlockPtr(u32 size) { void * ret = gLastSaveBlockPtr; + gLastSaveBlockPtr = (gLastSaveBlockPtr + size) + ((SaveRandom() & 15) * 4); + return ret; } @@ -60,6 +64,7 @@ static inline void SetSaveBlock1Ptr(void) { void ** ptr = (void**)&gSaveBlock1Ptr; u32 size = gAgbPmRomParams->saveBlock1Size; + SetSaveBlockPtr(ptr, size); } @@ -67,6 +72,7 @@ static inline void SetSaveBlock1BakPtr(void) { void ** ptr = (void**)&gSaveBlock1BakPtr; u32 size = gAgbPmRomParams->saveBlock1Size; + SetSaveBlockPtr(ptr, size); } @@ -74,6 +80,7 @@ static inline void SetSaveBlock2Ptr(void) { void ** ptr = (void**)&gSaveBlock2Ptr; u32 size = gAgbPmRomParams->saveBlock2Size; + SetSaveBlockPtr(ptr, size); } @@ -81,12 +88,14 @@ static inline void SetPokemonStoragePtr(void) { void ** ptr = (void**)&gPokemonStoragePtr; u32 size = sizeof(struct PokemonStorage); + SetSaveBlockPtr(ptr, size); } void SaveBlocksInit(void) { SeedSaveRng(); + switch (SaveRandom() & 3) { case 0: @@ -114,26 +123,28 @@ void SaveBlocksInit(void) SetSaveBlock1Ptr(); break; } - gPlayerPartyPtr = gSaveBlock1Ptr + gAgbPmRomParams->playerPartyOffs; - gPlayerPartyBakPtr = gSaveBlock1BakPtr + gAgbPmRomParams->playerPartyOffs; - gPlayerPartyCountPtr = gSaveBlock1Ptr + gAgbPmRomParams->playerPartyCountOffs; - gPokedexPtr = gSaveBlock2Ptr + gAgbPmRomParams->pokedexOffs; - gDexSeen2Ptr = gSaveBlock1Ptr + gAgbPmRomParams->dexSeen2Offs; - gDexSeen3Ptr = gSaveBlock1Ptr + gAgbPmRomParams->dexSeen3Offs; - gFlagsPtr = gSaveBlock1Ptr + gAgbPmRomParams->flagsOffs; - gVarsPtr = gSaveBlock1Ptr + gAgbPmRomParams->varsOffs; - gGiftRibbonsPtr = gSaveBlock1Ptr + gAgbPmRomParams->giftRibbonsOffs; - gEnigmaBerryPtr = gSaveBlock1Ptr + gAgbPmRomParams->enigmaBerryOffs; - gPcItemsPtr = gSaveBlock1Ptr + gAgbPmRomParams->pcItemsOffs; + + gPlayerPartyPtr = gSaveBlock1Ptr + gAgbPmRomParams->partyOffset; + gPlayerPartyBakPtr = gSaveBlock1BakPtr + gAgbPmRomParams->partyOffset; + gPlayerPartyCountPtr = gSaveBlock1Ptr + gAgbPmRomParams->partyCountOffset; + gPokedexPtr = gSaveBlock2Ptr + gAgbPmRomParams->pokedexOffset; + gDexSeen2Ptr = gSaveBlock1Ptr + gAgbPmRomParams->seen1Offset; + gDexSeen3Ptr = gSaveBlock1Ptr + gAgbPmRomParams->seen2Offset; + gFlagsPtr = gSaveBlock1Ptr + gAgbPmRomParams->flagsOffset; + gVarsPtr = gSaveBlock1Ptr + gAgbPmRomParams->varsOffset; + gGiftRibbonsPtr = gSaveBlock1Ptr + gAgbPmRomParams->giftRibbonsOffset; + gEnigmaBerryPtr = gSaveBlock1Ptr + gAgbPmRomParams->enigmaBerryOffset; + gPcItemsPtr = gSaveBlock1Ptr + gAgbPmRomParams->pcItemsOffset; } -u16 SaveRandom(void) +static u16 SaveRandom(void) { gSaveRngValue = gSaveRngValue * 2061 + 7; + return gSaveRngValue; } -void * UpdateSaveBlockPtr_(u32 size) +void * UNUSED UpdateSaveBlockPtr_(u32 size) { return UpdateSaveBlockPtr(size); } diff --git a/payload/src/libpmagb/berry.c b/payload/src/libpmagb/berry.c index 616ebb7..4e40dbe 100644 --- a/payload/src/libpmagb/berry.c +++ b/payload/src/libpmagb/berry.c @@ -25,32 +25,32 @@ struct Item u8 secondaryId; }; -u32 GetEnigmaBerryChecksum(struct EnigmaBerry * enigmaBerry) +u32 UNUSED GetEnigmaBerryChecksum(struct EnigmaBerry * enigmaBerry) { - u32 i, csum; + u32 i, checksum; u8 * dest; // the description pointers could be pointing to anywhere in memory. we do not want these // pointers to factor into the checksum as it will produce a different result every time: so // back the pointers up and set them to null so the checksum is safe to calculate. - const u8 * desc1bak = gEnigmaBerryPtr->berry.description1; - const u8 * desc2bak = gEnigmaBerryPtr->berry.description2; + const u8 * desc1Bak = gEnigmaBerryPtr->berry.description1; + const u8 * desc2Bak = gEnigmaBerryPtr->berry.description2; gEnigmaBerryPtr->berry.description1 = NULL; gEnigmaBerryPtr->berry.description2 = NULL; dest = (u8 *)enigmaBerry; - csum = 0; + checksum = 0; for (i = 0; i < gAgbPmRomParams->enigmaBerrySize - 4; i++) { - csum += dest[i]; + checksum += dest[i]; } // the checksum is calculated: the descriptions are safe to restore now. - gEnigmaBerryPtr->berry.description1 = desc1bak; - gEnigmaBerryPtr->berry.description2 = desc2bak; + gEnigmaBerryPtr->berry.description1 = desc1Bak; + gEnigmaBerryPtr->berry.description2 = desc2Bak; - return csum; + return checksum; } // due to e-reader scans being particularly volatile to failure, it is a requirement to check for @@ -102,13 +102,14 @@ const u8 *ItemId_GetName(u16 itemId) return items[SanitizeItemId(itemId)].name; } -void CopyItemName(u32 itemId, u8 *string, const u8 * berry_str) +void CopyItemName(u32 itemId, u8 *string, const u8 * berryString) { u16 itemId_ = itemId; + if (itemId_ == ITEM_ENIGMA_BERRY) { StringCopy(string, GetBerryInfo(ITEM_TO_BERRY(ITEM_ENIGMA_BERRY))->name); - StringAppend(string, berry_str); + StringAppend(string, berryString); } else { diff --git a/payload/src/libpmagb/save.c b/payload/src/libpmagb/save.c index 89c57c6..4f61b06 100644 --- a/payload/src/libpmagb/save.c +++ b/payload/src/libpmagb/save.c @@ -29,71 +29,74 @@ struct SaveSector // Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer #define SECTOR_DATA_SIZE 3968u #define SECTOR_FOOTER_SIZE 128 +#define SECTOR_SIGNATURE_OFFSET offsetof(struct SaveSector, signature) #define HALL_OF_FAME_SECTOR 28 #define NUM_SECTORS_PER_SAVE_SLOT 14 // Number of sectors occupied by a save slot #define NUM_HALL_OF_FAME_SECTORS 2 -#define SAVEBLOCK_CHUNK_EX(structure, size, chunkNum) \ -{ \ - (u8 *)structure + chunkNum * SECTOR_DATA_SIZE, \ - min(size - chunkNum * SECTOR_DATA_SIZE, SECTOR_DATA_SIZE) \ -} \ +#define SAVEBLOCK_CHUNK(structure, chunkNum) \ +{ \ + (u8 *)&structure + chunkNum * SECTOR_DATA_SIZE, SECTOR_DATA_SIZE \ +} \ -#define SAVEBLOCK_CHUNK(structure, chunkNum) SAVEBLOCK_CHUNK_EX(&structure, sizeof(structure), chunkNum) +#define SAVEBLOCK_CHUNK_FALSE_SIZE(structure, chunkNum, size) \ +{ \ + (u8 *)&structure + chunkNum * SECTOR_DATA_SIZE, size \ +} \ -u16 gFirstSaveSector; -u32 gPrevSaveCounter; +u16 gLastWrittenSector; +u32 gLastSaveCounter; u16 gLastKnownGoodSector; u32 gDamagedSaveSectors; u32 gSaveCounter; -struct SaveSector *gFastSaveSection; // the pointer is in fast IWRAM but may sometimes point to the slower EWRAM. +struct SaveSector *gReadWriteSector; // the pointer is in fast IWRAM but may sometimes point to the slower EWRAM. EWRAM_DATA struct SaveSector gSaveReadBuffer = {0}; -u16 gUnknown_03005EB4; +u16 unused; u16 gSaveFileStatus; u32 gGameContinueCallback; -u16 gUnknown_02023F40; +u16 gIncrementalSectorId; struct { - u8 unk_0; - u8 unk_1; - u8 unk_2; - u8 unk_3; - u8 unk_4; - u8 unk_5; - u8 unk_6; - u8 unk_7; - u32 unk_8; - u8 fill12; - u8 fill13; - u8 fill14; - u8 fill15; - u16 unk16; -} gUnknown_02022F10; + u8 unused1; + u8 neverRead1; + u8 unused2; + u8 unused3; + u8 failedSectorsWiped; + u8 unused4; + u8 unused5; + u8 unused6; + u32 neverRead2; + u8 unused7; + u8 unused8; + u8 unused9; + u8 unused10; + u16 neverRead3; +} gSaveStatusFlags; static u8 sWipeTries; static u32 gSaveValidStatus; -bool8 WipeFailedSectors(void); +static bool8 WipeFailedSectors(void); struct SaveBlockChunk sSaveBlockChunks[] = { - {(u8 *)&gSaveBlock2Ptr, 0x00000004}, - {(u8 *)&gSaveBlock1Ptr + SECTOR_DATA_SIZE * 0, SECTOR_DATA_SIZE}, - {(u8 *)&gSaveBlock1Ptr + SECTOR_DATA_SIZE * 1, SECTOR_DATA_SIZE}, - {(u8 *)&gSaveBlock1Ptr + SECTOR_DATA_SIZE * 2, SECTOR_DATA_SIZE}, - {(u8 *)&gSaveBlock1Ptr + SECTOR_DATA_SIZE * 3, 0x0c40}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 0, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 1, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 2, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 3, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 4, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 5, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 6, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 7, SECTOR_DATA_SIZE}, - {(u8 *)&gPokemonStoragePtr + SECTOR_DATA_SIZE * 8, 0x0004}, + SAVEBLOCK_CHUNK_FALSE_SIZE(gSaveBlock2Ptr, 0, 0x0004), + SAVEBLOCK_CHUNK(gSaveBlock1Ptr, 0), + SAVEBLOCK_CHUNK(gSaveBlock1Ptr, 1), + SAVEBLOCK_CHUNK(gSaveBlock1Ptr, 2), + SAVEBLOCK_CHUNK_FALSE_SIZE(gSaveBlock1Ptr, 3, 0x0C40), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 0), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 1), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 2), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 3), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 4), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 5), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 6), + SAVEBLOCK_CHUNK(gPokemonStoragePtr, 7), + SAVEBLOCK_CHUNK_FALSE_SIZE(gPokemonStoragePtr, 8, 0x0004), }; -struct SaveBlockChunk gUnknown_020205BC[] = { +struct SaveBlockChunk sSaveBlockChunkBuffer[] = { {(void *)&gSaveReadBuffer, SECTOR_DATA_SIZE}, {(void *)&gSaveReadBuffer, SECTOR_DATA_SIZE}, {(void *)&gSaveReadBuffer, SECTOR_DATA_SIZE}, @@ -110,15 +113,15 @@ struct SaveBlockChunk gUnknown_020205BC[] = { {(void *)&gSaveReadBuffer, SECTOR_DATA_SIZE}, }; -inline void sub_200A5C8_Inline(void) +inline void ResetSaveCounters(void) { gSaveCounter = 0; - gFirstSaveSector = 0; + gLastWrittenSector = 0; gDamagedSaveSectors = 0; gSaveValidStatus = 0x80; } -inline void sub_200A5F0_Inline(void) +inline void ClearSaveData(void) { s32 i; @@ -126,10 +129,10 @@ inline void sub_200A5F0_Inline(void) { EraseFlashSector(i); } - sub_200A5C8_Inline(); + ResetSaveCounters(); } -s32 sub_020098D8(u32 timerNum, IntrFunc * intrFunc) +s32 InitFlash(u32 timerNum, IntrFunc * intrFunc) { sSaveBlockChunks[0].size = gAgbPmRomParams->saveBlock2Size; sSaveBlockChunks[4].size = gAgbPmRomParams->saveBlock1Size % SECTOR_DATA_SIZE; @@ -137,7 +140,7 @@ s32 sub_020098D8(u32 timerNum, IntrFunc * intrFunc) if (!IdentifyFlash() && !SetFlashTimerIntr(timerNum, intrFunc)) { - sub_200A5C8_Inline(); + ResetSaveCounters(); return 0; } @@ -226,15 +229,15 @@ u16 GetSaveValidStatus(const struct SaveBlockChunk *chunks) signatureValid = FALSE; for (sector = 0; sector < NUM_SECTORS_PER_SAVE_SLOT; sector++) { - DoReadFlashWholeSection(sector, gFastSaveSection); - if (gFastSaveSection->signature == FILE_SIGNATURE) + DoReadFlashWholeSection(sector, gReadWriteSector); + if (gReadWriteSector->signature == FILE_SIGNATURE) { signatureValid = TRUE; - checksum = CalculateChecksum(gFastSaveSection->data, chunks[gFastSaveSection->id].size); - if (gFastSaveSection->checksum == checksum) + checksum = CalculateChecksum(gReadWriteSector->data, chunks[gReadWriteSector->id].size); + if (gReadWriteSector->checksum == checksum) { - slot1saveCounter = gFastSaveSection->counter; - validSectors |= 1 << gFastSaveSection->id; + slot1saveCounter = gReadWriteSector->counter; + validSectors |= 1 << gReadWriteSector->id; } } } @@ -254,17 +257,18 @@ u16 GetSaveValidStatus(const struct SaveBlockChunk *chunks) // check save slot 2. validSectors = 0; signatureValid = FALSE; + for (sector = 0; sector < NUM_SECTORS_PER_SAVE_SLOT; sector++) { - DoReadFlashWholeSection(NUM_SECTORS_PER_SAVE_SLOT + sector, gFastSaveSection); - if (gFastSaveSection->signature == FILE_SIGNATURE) + DoReadFlashWholeSection(NUM_SECTORS_PER_SAVE_SLOT + sector, gReadWriteSector); + if (gReadWriteSector->signature == FILE_SIGNATURE) { signatureValid = TRUE; - checksum = CalculateChecksum(gFastSaveSection->data, chunks[gFastSaveSection->id].size); - if (gFastSaveSection->checksum == checksum) + checksum = CalculateChecksum(gReadWriteSector->data, chunks[gReadWriteSector->id].size); + if (gReadWriteSector->checksum == checksum) { - slot2saveCounter = gFastSaveSection->counter; - validSectors |= 1 << gFastSaveSection->id; + slot2saveCounter = gReadWriteSector->counter; + validSectors |= 1 << gReadWriteSector->id; } } } @@ -286,7 +290,7 @@ u16 GetSaveValidStatus(const struct SaveBlockChunk *chunks) // Choose counter of the most recent save file if ((slot1saveCounter == -1 && slot2saveCounter == 0) || (slot1saveCounter == 0 && slot2saveCounter == -1)) { - if ((unsigned)(slot1saveCounter + 1) < (unsigned)(slot2saveCounter + 1)) + if ((u32)(slot1saveCounter + 1) < (u32)(slot2saveCounter + 1)) gSaveCounter = slot2saveCounter; else gSaveCounter = slot1saveCounter; @@ -322,56 +326,65 @@ u16 GetSaveValidStatus(const struct SaveBlockChunk *chunks) if (slot1Status == SAVE_STATUS_EMPTY && slot2Status == SAVE_STATUS_EMPTY) { gSaveCounter = 0; - gFirstSaveSector = 0; + gLastWrittenSector = 0; return SAVE_STATUS_EMPTY; } gSaveCounter = 0; - gFirstSaveSector = 0; + gLastWrittenSector = 0; + return 2; } -void ReadSaveChunkI(u32 sector, u32 chunk, const struct SaveBlockChunk * chunks) +void ReadSaveChunk(u32 sector, u32 chunk, const struct SaveBlockChunk * chunks) { s32 i; u32 checksum; u16 sectorId; - DoReadFlashWholeSection(sector, gFastSaveSection); - sectorId = gFastSaveSection->id; + + DoReadFlashWholeSection(sector, gReadWriteSector); + sectorId = gReadWriteSector->id; + if (sectorId == 0) { - gFirstSaveSector = chunk; + gLastWrittenSector = chunk; } - checksum = CalculateChecksum(gFastSaveSection->data, chunks[sectorId].size); - if (gFastSaveSection->signature == FILE_SIGNATURE && gFastSaveSection->checksum == checksum) + + checksum = CalculateChecksum(gReadWriteSector->data, chunks[sectorId].size); + + if (gReadWriteSector->signature == FILE_SIGNATURE && gReadWriteSector->checksum == checksum) { for (i = 0; i < chunks[sectorId].size; i++) - chunks[sectorId].data[i] = gFastSaveSection->data[i]; + chunks[sectorId].data[i] = gReadWriteSector->data[i]; } } -inline bool32 sub_200A634_Inline(const struct SaveBlockChunk * chunks) +inline bool32 ReadAllSaveChunks(const struct SaveBlockChunk * chunks) { s32 i; u32 firstSector = (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; + for (i = 0; i < NUM_SECTORS_PER_SAVE_SLOT; i++) { - ReadSaveChunkI(i + firstSector, i, chunks); + ReadSaveChunk(i + firstSector, i, chunks); } return TRUE; } -inline u32 sub_200A664_Inline(s32 a0, const struct SaveBlockChunk *chunks) +inline UNUSED u32 UnusedReadSaveData(s32 allChunks, const struct SaveBlockChunk *chunks) { - gFastSaveSection = &gSaveReadBuffer; - switch (a0) + gReadWriteSector = &gSaveReadBuffer; + + switch (allChunks) { - case 0: + case FALSE: gSaveValidStatus = GetSaveValidStatus(chunks); - ReadSaveChunkI((gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT, 0, chunks); + ReadSaveChunk((gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT, 0, chunks); + return gSaveValidStatus; - case 1: - sub_200A634_Inline(chunks); + case TRUE: + ReadAllSaveChunks(chunks); + return gSaveValidStatus; } } @@ -380,19 +393,23 @@ u32 ReadSaveBlockChunks(void) { u32 status; const struct SaveBlockChunk * chunks = sSaveBlockChunks; - gFastSaveSection = &gSaveReadBuffer; - sub_200A634_Inline(chunks); + + gReadWriteSector = &gSaveReadBuffer; + ReadAllSaveChunks(chunks); status = gSaveValidStatus; CpuCopy16(gSaveBlock1Ptr, gSaveBlock1BakPtr, gAgbPmRomParams->saveBlock1Size); + return status; } u8 * ReadFirstSaveSector(void) { - const struct SaveBlockChunk * chunks = gUnknown_020205BC; - gFastSaveSection = &gSaveReadBuffer; + const struct SaveBlockChunk * chunks = sSaveBlockChunkBuffer; + + gReadWriteSector = &gSaveReadBuffer; gSaveValidStatus = GetSaveValidStatus(chunks); - ReadSaveChunkI((gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT, 0, chunks); + ReadSaveChunk((gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT, 0, chunks); + return gSaveReadBuffer.data; } @@ -403,6 +420,7 @@ static inline u32 TryWriteSector(u8 sectorNum, void * data) SoundVSyncOff(); ret = ProgramFlashSectorAndVerify(sectorNum, data); SoundVSyncOn(); + if (ret != 0) { SetSectorDamagedStatus(SECTOR_DAMAGED, sectorNum); @@ -415,64 +433,67 @@ static inline u32 TryWriteSector(u8 sectorNum, void * data) } } -u32 WriteSingleChunk(u16 chunk, const struct SaveBlockChunk * chunks) +static u32 HandleWriteSector(u16 sectorId, const struct SaveBlockChunk * chunks) { u16 i; - u16 r5; - u8 * data; - u16 size; + u16 sector; + u8 * chunkData; + u16 chunkSize; - r5 = gFirstSaveSector + chunk; - r5 %= NUM_SECTORS_PER_SAVE_SLOT; - r5 += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; - data = chunks[chunk].data; - size = chunks[chunk].size; + sector = sectorId + gLastWrittenSector; + sector %= NUM_SECTORS_PER_SAVE_SLOT; + sector += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; + chunkData = chunks[sectorId].data; + chunkSize = chunks[sectorId].size; for (i = 0; i < sizeof(struct SaveSector); i++) { - ((u8 *)gFastSaveSection)[i] = 0; + ((u8 *)gReadWriteSector)[i] = 0; } - gFastSaveSection->id = chunk; - gFastSaveSection->signature = FILE_SIGNATURE; - gFastSaveSection->counter = gSaveCounter; - for (i = 0; i < size; i++) + + gReadWriteSector->id = sectorId; + gReadWriteSector->signature = FILE_SIGNATURE; + gReadWriteSector->counter = gSaveCounter; + + for (i = 0; i < chunkSize; i++) { - gFastSaveSection->data[i] = data[i]; + gReadWriteSector->data[i] = chunkData[i]; } - gFastSaveSection->checksum = CalculateChecksum(data, size); - return TryWriteSector(r5, (void *)gFastSaveSection); + gReadWriteSector->checksum = CalculateChecksum(chunkData, chunkSize); + + return TryWriteSector(sector, (void *)gReadWriteSector); } -inline u32 WriteSaveBlockChunksInternal(u16 chunkId, const struct SaveBlockChunk * chunks) +inline u32 WriteSaveSectorOrSlot(u16 sectorId, const struct SaveBlockChunk * chunks) { u32 retVal; s32 i; - gFastSaveSection = &gSaveReadBuffer; + gReadWriteSector = &gSaveReadBuffer; - if (chunkId != 0xFFFF) // write single chunk + if (sectorId != 0xFFFF) // write single chunk { - retVal = WriteSingleChunk(chunkId, chunks); + retVal = HandleWriteSector(sectorId, chunks); } else // write all chunks { - gLastKnownGoodSector = gFirstSaveSector; - gPrevSaveCounter = gSaveCounter; - gFirstSaveSector++; - gFirstSaveSector %= NUM_SECTORS_PER_SAVE_SLOT; + gLastKnownGoodSector = gLastWrittenSector; + gLastSaveCounter = gSaveCounter; + gLastWrittenSector++; + gLastWrittenSector %= NUM_SECTORS_PER_SAVE_SLOT; gSaveCounter++; retVal = SAVE_STATUS_OK; for (i = 0; i < NUM_SECTORS_PER_SAVE_SLOT; i++) - WriteSingleChunk(i, chunks); + HandleWriteSector(i, chunks); // Check for any bad sectors if (gDamagedSaveSectors != 0) // skip the damaged sector. { retVal = SAVE_STATUS_ERROR; - gFirstSaveSector = gLastKnownGoodSector; - gSaveCounter = gPrevSaveCounter; + gLastWrittenSector = gLastKnownGoodSector; + gSaveCounter = gLastSaveCounter; } } @@ -481,49 +502,53 @@ inline u32 WriteSaveBlockChunksInternal(u16 chunkId, const struct SaveBlockChunk u32 WriteSaveBlockChunks(void) { - return WriteSaveBlockChunksInternal(0xFFFF, sSaveBlockChunks); + return WriteSaveSectorOrSlot(0xFFFF, sSaveBlockChunks); } -u8 sub_02009F4C(u16 chunk, const struct SaveBlockChunk * chunks) +static u8 HandleReplaceSector(u16 sectorId, const struct SaveBlockChunk * chunks) { u16 i; - u16 sectorId; - u8 * data; - u16 size; + u16 sector; + u8 * chunkData; + u16 chunkSize; u8 ret; - sectorId = chunk + gFirstSaveSector; - sectorId %= NUM_SECTORS_PER_SAVE_SLOT; - sectorId += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; - data = chunks[chunk].data; - size = chunks[chunk].size; + sector = sectorId + gLastWrittenSector; + sector %= NUM_SECTORS_PER_SAVE_SLOT; + sector += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; + chunkData = chunks[sectorId].data; + chunkSize = chunks[sectorId].size; for (i = 0; i < sizeof(struct SaveSector); i++) { - ((u8 *)gFastSaveSection)[i] = 0; + ((u8 *)gReadWriteSector)[i] = 0; } - gFastSaveSection->id = chunk; - gFastSaveSection->signature = FILE_SIGNATURE; - gFastSaveSection->counter = gSaveCounter; - for (i = 0; i < size; i++) + gReadWriteSector->id = sectorId; + gReadWriteSector->signature = FILE_SIGNATURE; + gReadWriteSector->counter = gSaveCounter; + + for (i = 0; i < chunkSize; i++) { - gFastSaveSection->data[i] = data[i]; + gReadWriteSector->data[i] = chunkData[i]; } - gFastSaveSection->checksum = CalculateChecksum(data, size); - EraseFlashSector(sectorId); + + gReadWriteSector->checksum = CalculateChecksum(chunkData, chunkSize); + EraseFlashSector(sector); ret = SAVE_STATUS_OK; + for (i = 0; i < 0xFF8; i++) { - if (ProgramFlashByte(sectorId, i, gFastSaveSection->data[i]) != 0) + if (ProgramFlashByte(sector, i, gReadWriteSector->data[i]) != 0) { ret = SAVE_STATUS_ERROR; break; } } + if (ret == SAVE_STATUS_ERROR) { - SetSectorDamagedStatus(SECTOR_DAMAGED, sectorId); + SetSectorDamagedStatus(SECTOR_DAMAGED, sector); return SAVE_STATUS_ERROR; } else @@ -531,7 +556,7 @@ u8 sub_02009F4C(u16 chunk, const struct SaveBlockChunk * chunks) ret = SAVE_STATUS_OK; for (i = 0; i < 7; i++) { - if (ProgramFlashByte(sectorId, i + 0xFF9, ((u8 *)gFastSaveSection)[i + 0xFF9]) != 0) + if (ProgramFlashByte(sector, i + 0xFF9, ((u8 *)gReadWriteSector)[i + 0xFF9]) != 0) { ret = SAVE_STATUS_ERROR; break; @@ -539,137 +564,147 @@ u8 sub_02009F4C(u16 chunk, const struct SaveBlockChunk * chunks) } if (ret == SAVE_STATUS_ERROR) { - SetSectorDamagedStatus(SECTOR_DAMAGED, sectorId); + SetSectorDamagedStatus(SECTOR_DAMAGED, sector); return SAVE_STATUS_ERROR; } else { - SetSectorDamagedStatus(SECTOR_OK, sectorId); + SetSectorDamagedStatus(SECTOR_OK, sector); return SAVE_STATUS_OK; } } } -u8 sub_0200A118(u16 sectorNum, const struct SaveBlockChunk * chunks) +static u8 WriteSectorSignatureByte(u16 sectorId, const struct SaveBlockChunk * chunks) { - u16 r4 = sectorNum + gFirstSaveSector - 1; - r4 %= NUM_SECTORS_PER_SAVE_SLOT; - r4 += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; + u16 sector = sectorId + gLastWrittenSector - 1; + sector %= NUM_SECTORS_PER_SAVE_SLOT; + sector += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; SoundVSyncOff(); - if (ProgramFlashByte(r4, 0xFF8, ((u8 *)gFastSaveSection)[0xFF8])) + + if (ProgramFlashByte(sector, SECTOR_SIGNATURE_OFFSET, ((u8 *)gReadWriteSector)[SECTOR_SIGNATURE_OFFSET]) != 0) { - SetSectorDamagedStatus(SECTOR_DAMAGED, r4); + SetSectorDamagedStatus(SECTOR_DAMAGED, sector); SoundVSyncOn(); return SAVE_STATUS_ERROR; } else { - SetSectorDamagedStatus(SECTOR_OK, r4); + SetSectorDamagedStatus(SECTOR_OK, sector); SoundVSyncOn(); return SAVE_STATUS_OK; } } -u8 sub_0200A1B8(u16 sectorNum, const struct SaveBlockChunk * chunks) +static u8 WriteSectorSignatureByteInverse(u16 sectorId, const struct SaveBlockChunk * chunks) { - u16 r4 = sectorNum + gFirstSaveSector - 1; - r4 %= NUM_SECTORS_PER_SAVE_SLOT; - r4 += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; + u16 sector = sectorId + gLastWrittenSector - 1; + sector %= NUM_SECTORS_PER_SAVE_SLOT; + sector += (gSaveCounter % 2) * NUM_SECTORS_PER_SAVE_SLOT; SoundVSyncOff(); - if (ProgramFlashByte(r4, 0xFF8, ~((u8 *)gFastSaveSection)[0xFF8])) + + if (ProgramFlashByte(sector, SECTOR_SIGNATURE_OFFSET, ~((u8 *)gReadWriteSector)[SECTOR_SIGNATURE_OFFSET]) != 0) { - SetSectorDamagedStatus(SECTOR_DAMAGED, r4); + SetSectorDamagedStatus(SECTOR_DAMAGED, sector); SoundVSyncOn(); return SAVE_STATUS_ERROR; } else { - SetSectorDamagedStatus(SECTOR_OK, r4); + SetSectorDamagedStatus(SECTOR_OK, sector); SoundVSyncOn(); return SAVE_STATUS_OK; } } -inline bool32 sub_200A77C_Inline(void) +inline u32 RestoreSaveBackupVarsAndIncrement(void) { - gFastSaveSection = &gSaveReadBuffer; - gLastKnownGoodSector = gFirstSaveSector; - gPrevSaveCounter = gSaveCounter; - gFirstSaveSector++; - gFirstSaveSector %= NUM_SECTORS_PER_SAVE_SLOT; + gReadWriteSector = &gSaveReadBuffer; + gLastKnownGoodSector = gLastWrittenSector; + gLastSaveCounter = gSaveCounter; + gLastWrittenSector++; + gLastWrittenSector %= NUM_SECTORS_PER_SAVE_SLOT; gSaveCounter++; - gUnknown_02023F40 = 0; + gIncrementalSectorId = 0; gDamagedSaveSectors = 0; - return FALSE; + + return 0; } -inline bool32 sub_200A7D8_Inline(void) +inline UNUSED u32 RestoreSaveBackupVars(void) { - gFastSaveSection = &gSaveReadBuffer; - gLastKnownGoodSector = gFirstSaveSector; - gPrevSaveCounter = gSaveCounter; - gUnknown_02023F40 = 0; + gReadWriteSector = &gSaveReadBuffer; + gLastKnownGoodSector = gLastWrittenSector; + gLastSaveCounter = gSaveCounter; + gIncrementalSectorId = 0; gDamagedSaveSectors = 0; - return FALSE; + + return 0; } -inline u32 sub_200A81C_Inline(void) +inline UNUSED u32 RevertSaveCounters(void) { - gFirstSaveSector = gLastKnownGoodSector; - gSaveCounter = gPrevSaveCounter; + gLastWrittenSector = gLastKnownGoodSector; + gSaveCounter = gLastSaveCounter; + return gSaveCounter; } -inline u8 sub_0200A260_sub(u16 limit, const struct SaveBlockChunk * chunks) +inline u8 HandleWriteIncrementalSector(u16 numSectors, const struct SaveBlockChunk * chunks) { - u8 ret; + u8 status; - if (gUnknown_02023F40 < limit - 1) + if (gIncrementalSectorId < numSectors - 1) { - WriteSingleChunk(gUnknown_02023F40, chunks); + HandleWriteSector(gIncrementalSectorId, chunks); if (gDamagedSaveSectors) - ret = SAVE_STATUS_ERROR; + status = SAVE_STATUS_ERROR; else { - ret = SAVE_STATUS_OK; - gUnknown_02023F40++; + status = SAVE_STATUS_OK; + gIncrementalSectorId++; } } else { - ret = SAVE_STATUS_ERROR; + status = SAVE_STATUS_ERROR; } - return ret; + + return status; } -inline u32 sub_200A880_Inline(u16 chunk, const struct SaveBlockChunk * chunks) +inline u32 HandleReplaceSectorAndVerify(u16 chunk, const struct SaveBlockChunk * chunks) { - u32 ret = 1; + u32 status = SAVE_STATUS_OK; SoundVSyncOff(); - sub_02009F4C(chunk - 1, chunks); + HandleReplaceSector(chunk - 1, chunks); SoundVSyncOn(); + if (gDamagedSaveSectors != 0) - ret = 0xFF; - return ret; + status = SAVE_STATUS_ERROR; + + return status; } -bool32 sub_0200A260(void) +static bool32 FullSaveAndLoopOverFailedSectors(void) { u8 status; retry: - status = sub_0200A260_sub(NUM_SECTORS_PER_SAVE_SLOT, sSaveBlockChunks); + status = HandleWriteIncrementalSector(NUM_SECTORS_PER_SAVE_SLOT, sSaveBlockChunks); + if (gDamagedSaveSectors != 0) { if (!WipeFailedSectors()) { goto retry; } - gUnknown_02022F10.unk_4 |= 1; + gSaveStatusFlags.failedSectorsWiped |= 1; } + if (status == SAVE_STATUS_ERROR) return TRUE; else @@ -690,87 +725,99 @@ bool32 sub_0200A2C8(s32 a) s32 j; u8 *sav2; - gUnknown_02022F10.unk_8 |= 1; - gUnknown_02022F10.unk_4 &= ~(1); - gUnknown_02022F10.unk_8 &= ~(2 | 4); + gSaveStatusFlags.neverRead2 |= 1; + gSaveStatusFlags.failedSectorsWiped &= ~(1); + gSaveStatusFlags.neverRead2 &= ~(2 | 4); sav2 = gSaveBlock2Ptr; + for (i = 0; i < gAgbPmRomParams->saveBlock2Size; i++) { if (sav2[i] != 0) - goto _0200A354; + goto _DontClearSaveData; } - sub_200A5F0_Inline(); - gUnknown_02022F10.unk_8 |= 8; - gUnknown_02022F10.unk_1 = 4; - gUnknown_02022F10.unk16 = 0; - _0200A354: - sub_200A77C_Inline(); - gUnknown_02022F10.unk_1++; - gUnknown_02022F10.unk16 = 0; + + ClearSaveData(); + gSaveStatusFlags.neverRead2 |= 8; + gSaveStatusFlags.neverRead1 = 4; + gSaveStatusFlags.neverRead3 = 0; + _DontClearSaveData: + RestoreSaveBackupVarsAndIncrement(); + gSaveStatusFlags.neverRead1++; + gSaveStatusFlags.neverRead3 = 0; DelayFrames(5); + while (1) { - if (sub_0200A260() != 0) + if (FullSaveAndLoopOverFailedSectors() != FALSE) break; - if (gUnknown_02022F10.unk_4 & 1) + if (gSaveStatusFlags.failedSectorsWiped & 1) return TRUE; } + sWipeTries = 0; + while (1) { - sub_200A880_Inline(14, sSaveBlockChunks); + HandleReplaceSectorAndVerify(14, sSaveBlockChunks); if (gDamagedSaveSectors != 0) { if (WipeFailedSectors()) { - gUnknown_02022F10.unk_4 |= 1; + gSaveStatusFlags.failedSectorsWiped |= 1; break; } continue; } break; } - if (gUnknown_02022F10.unk_4 & 1) + + if (gSaveStatusFlags.failedSectorsWiped & 1) return TRUE; else return FALSE; } case 1: i = 0; + while (1) { const struct SaveBlockChunk *chunks = sSaveBlockChunks; - sub_0200A118(14, chunks); + WriteSectorSignatureByte(14, chunks); + if (gDamagedSaveSectors != 0) { if (++i >= 4) { - gUnknown_02022F10.unk_4 |= 1; + gSaveStatusFlags.failedSectorsWiped |= 1; break; } + gDamagedSaveSectors = 0; continue; } break; } - if (gUnknown_02022F10.unk_4 & 1) + if (gSaveStatusFlags.failedSectorsWiped & 1) return TRUE; else return FALSE; case 2: i = 0; + while (1) { const struct SaveBlockChunk *chunks = sSaveBlockChunks; - sub_0200A1B8(14, chunks); + WriteSectorSignatureByteInverse(14, chunks); + if (gDamagedSaveSectors != 0) { if (++i >= 4) { - gUnknown_02022F10.unk_4 |= 1; + gSaveStatusFlags.failedSectorsWiped |= 1; break; } + gDamagedSaveSectors = 0; continue; } @@ -802,7 +849,7 @@ _0200A2DA:\t\n\ _0200A2E0:\t\n\ b _0200A4AE\t\n\ _0200A2E2:\t\n\ - ldr r2, =gUnknown_02022F10\t\n\ + ldr r2, =gSaveStatusFlags\t\n\ ldr r1, [r2, #8]\t\n\ movs r0, #1\t\n\ orrs r1, r0\t\n\ @@ -846,14 +893,14 @@ _0200A320:\t\n\ ldr r0, =gSaveCounter\t\n\ movs r3, #0\t\n\ str r3, [r0]\t\n\ - ldr r0, =gFirstSaveSector\t\n\ + ldr r0, =gLastWrittenSector\t\n\ strh r3, [r0]\t\n\ ldr r0, =gDamagedSaveSectors\t\n\ str r3, [r0]\t\n\ ldr r1, =gSaveValidStatus\t\n\ movs r0, #0x80\t\n\ str r0, [r1]\t\n\ - ldr r2, =gUnknown_02022F10\t\n\ + ldr r2, =gSaveStatusFlags\t\n\ ldr r0, [r2, #8]\t\n\ movs r1, #8\t\n\ orrs r0, r1\t\n\ @@ -862,14 +909,14 @@ _0200A320:\t\n\ strb r0, [r2, #1]\t\n\ strh r3, [r2, #0x10]\t\n\ _0200A354:\t\n\ - ldr r1, =gFastSaveSection\t\n\ + ldr r1, =gReadWriteSector\t\n\ ldr r0, =gSaveReadBuffer\t\n\ str r0, [r1]\t\n\ ldr r0, =gLastKnownGoodSector\t\n\ - ldr r4, =gFirstSaveSector\t\n\ + ldr r4, =gLastWrittenSector\t\n\ ldrh r1, [r4]\t\n\ strh r1, [r0]\t\n\ - ldr r2, =gPrevSaveCounter\t\n\ + ldr r2, =gLastSaveCounter\t\n\ ldr r5, =gSaveCounter\t\n\ ldr r0, [r5]\t\n\ str r0, [r2]\t\n\ @@ -882,13 +929,13 @@ _0200A354:\t\n\ ldr r0, [r5]\t\n\ adds r0, #1\t\n\ str r0, [r5]\t\n\ - ldr r1, =gUnknown_02023F40\t\n\ + ldr r1, =gIncrementalSectorId\t\n\ movs r0, #0\t\n\ strh r0, [r1]\t\n\ ldr r0, =gDamagedSaveSectors\t\n\ movs r1, #0\t\n\ str r1, [r0]\t\n\ - ldr r4, =gUnknown_02022F10\t\n\ + ldr r4, =gSaveStatusFlags\t\n\ ldrb r0, [r4, #1]\t\n\ adds r0, #1\t\n\ strb r0, [r4, #1]\t\n\ @@ -906,7 +953,7 @@ _0200A3D4:\t\n\ cmp r0, #0\t\n\ bne _0200A46E\t\n\ _0200A3DE:\t\n\ - bl sub_0200A260\t\n\ + bl FullSaveAndLoopOverFailedSectors\t\n\ cmp r0, #0\t\n\ beq _0200A3D4\t\n\ ldr r1, =sWipeTries\t\n\ @@ -917,7 +964,7 @@ _0200A3EC:\t\n\ bl SoundVSyncOff\t\n\ movs r0, #0xd\t\n\ adds r1, r4, #0\t\n\ - bl sub_02009F4C\t\n\ + bl HandleReplaceSector\t\n\ bl SoundVSyncOn\t\n\ ldr r0, =gDamagedSaveSectors\t\n\ ldr r0, [r0]\t\n\ @@ -927,7 +974,7 @@ _0200A3EC:\t\n\ lsls r0, r0, #0x18\t\n\ cmp r0, #0\t\n\ beq _0200A3EC\t\n\ - ldr r0, =gUnknown_02022F10\t\n\ + ldr r0, =gSaveStatusFlags\t\n\ movs r1, #1\t\n\ ldrb r2, [r0, #4]\t\n\ orrs r1, r2\t\n\ @@ -939,7 +986,7 @@ _0200A42C:\t\n\ _0200A42E:\t\n\ ldr r1, =sSaveBlockChunks\t\n\ movs r0, #0xe\t\n\ - bl sub_0200A118\t\n\ + bl WriteSectorSignatureByte\t\n\ ldr r1, =gDamagedSaveSectors\t\n\ ldr r0, [r1]\t\n\ cmp r0, #0\t\n\ @@ -955,14 +1002,14 @@ _0200A42E:\t\n\ .align 2, 0\t\n\ .pool\t\n\ _0200A458:\t\n\ - ldr r0, =gUnknown_02022F10\t\n\ + ldr r0, =gSaveStatusFlags\t\n\ movs r1, #1\t\n\ ldrb r3, [r0, #4]\t\n\ orrs r1, r3\t\n\ _0200A460:\t\n\ strb r1, [r0, #4]\t\n\ _0200A462:\t\n\ - ldr r1, =gUnknown_02022F10\t\n\ + ldr r1, =gSaveStatusFlags\t\n\ movs r0, #1\t\n\ ldrb r1, [r1, #4]\t\n\ ands r0, r1\t\n\ @@ -978,7 +1025,7 @@ _0200A478:\t\n\ _0200A47A:\t\n\ ldr r1, =sSaveBlockChunks\t\n\ movs r0, #0xe\t\n\ - bl sub_0200A1B8\t\n\ + bl WriteSectorSignatureByteInverse\t\n\ ldr r1, =gDamagedSaveSectors\t\n\ ldr r0, [r1]\t\n\ cmp r0, #0\t\n\ @@ -994,7 +1041,7 @@ _0200A47A:\t\n\ .align 2, 0\t\n\ .pool\t\n\ _0200A4A4:\t\n\ - ldr r0, =gUnknown_02022F10\t\n\ + ldr r0, =gSaveStatusFlags\t\n\ movs r1, #1\t\n\ ldrb r2, [r0, #4]\t\n\ orrs r1, r2\t\n\ @@ -1014,23 +1061,25 @@ _0200A4B0:\t\n\ static inline bool8 WipeSector_Sub(void) { u16 i; - u32 *ptr = (void *)&gSaveReadBuffer; + for (i = 0; i < sizeof(struct SaveSector) / 4; i++, ptr++) { if (*ptr != 0) return TRUE; } + return FALSE; } -bool8 WipeSector(u16 sectorNum) +static bool8 WipeSector(u16 sectorNum) { u16 i; bool8 ret; u16 r5 = 0; SoundVSyncOff(); + while (r5 < 130) { for (i = 0; i < sizeof(struct SaveSector); i++) @@ -1045,19 +1094,22 @@ bool8 WipeSector(u16 sectorNum) } SoundVSyncOn(); + return ret; } -bool8 WipeFailedSectors(void) +static bool8 WipeFailedSectors(void) { u32 bits; u16 i; - gUnknown_02022F10.unk_8 |= 2; + gSaveStatusFlags.neverRead2 |= 2; + if (gDamagedSaveSectors != 0 && sWipeTries <= 2) { bits = gDamagedSaveSectors; - bits++;bits--; // Needed to match; + bits++; + bits--; // Needed to match; for (i = 0; i < NUM_SECTORS; i++) { @@ -1073,15 +1125,18 @@ bool8 WipeFailedSectors(void) bits &= ~(currBits); } } + gDamagedSaveSectors = bits; sWipeTries++; + if (bits == 0) return FALSE; } + return TRUE; } -static UNUSED void *sub_200A5C0(void) +static UNUSED void *GetSaveReadBufferPointer(void) { return &gSaveReadBuffer; } diff --git a/payload/src/main.c b/payload/src/main.c index 3f87486..d9ecd2c 100644 --- a/payload/src/main.c +++ b/payload/src/main.c @@ -28,7 +28,7 @@ extern const struct RomHeader gRomHeader; extern u8 gUnknown_020217B4; extern u8 gUnknown_020217B8; -extern IntrFunc *gUnknown_0201F4AC; +extern IntrFunc *gTimer1InterruptFunction; extern struct Unk02021860Struct gUnknown_02021860; extern s32 sub_020063FC(void); extern s32 sub_020064BC(u32 a0, u32 a1); @@ -72,7 +72,7 @@ inline u32 sub_0200043C(void) u8 buffer[64]; u32 var18 = 0; u32 r4 = 0; - u32 language = gAgbPmRomParams->gameLanguage; + u32 language = gAgbPmRomParams->language; if (language != LANGUAGE_ENGLISH) return 0; @@ -101,7 +101,7 @@ void GF_Main(void) u16 monStatus; DetectROM(); - sub_020098D8(2, gUnknown_0201F4AC); + InitFlash(2, gTimer1InterruptFunction); SaveBlocksInit(); SetSaveSectorPtrs(); gUnknown_020217B4 = ReadSaveBlockChunks(); @@ -158,10 +158,10 @@ NAKED void GF_Main(void) asm_unified("push {r4, r5, r6, r7, lr}\t\n\ sub sp, #0x48\t\n\ bl DetectROM\t\n\ - ldr r0, =gUnknown_0201F4AC\t\n\ + ldr r0, =gTimer1InterruptFunction\t\n\ ldr r1, [r0]\t\n\ movs r0, #2\t\n\ - bl sub_020098D8\t\n\ + bl InitFlash\t\n\ bl SaveBlocksInit\t\n\ bl SetSaveSectorPtrs\t\n\ ldr r4, =gUnknown_020217B4\t\n\ diff --git a/payload/src/pokemon.c b/payload/src/pokemon.c index 4501d20..75d7ce6 100644 --- a/payload/src/pokemon.c +++ b/payload/src/pokemon.c @@ -527,19 +527,19 @@ const struct CompressedSpritePalette *GetBoxMonPalettePtr(u32 partyId) u32 personality = GetMonDataInline(&gPlayerPartyPtr[partyId], MON_DATA_PERSONALITY, NULL); if (species > NUM_SPECIES) - return &gAgbPmRomParams->monPaletteTable[SPECIES_NONE]; + return &gAgbPmRomParams->monNormalPalettes[SPECIES_NONE]; shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); if (shinyValue > 7) - return &gAgbPmRomParams->monPaletteTable[species]; + return &gAgbPmRomParams->monNormalPalettes[species]; else - return &gAgbPmRomParams->monShinyPaletteTable[species]; + return &gAgbPmRomParams->monShinyPalettes[species]; } u32 GetBoxMonAbility(struct BoxPokemon *boxMon) { u32 ability; - const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats; + const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->speciesInfo; u32 species = GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL); u32 abilityNum = GetBoxMonData(boxMon, MON_DATA_ALT_ABILITY, NULL); @@ -573,7 +573,7 @@ const u32 *BoxMonCaughtBallToItemId(struct BoxPokemon *boxMon) default: id = 0; break; } - return gAgbPmRomParams->ballSpriteSheets[id].data; + return gAgbPmRomParams->ballGfx[id].data; } const u32 *BoxMonGetCaughtBallItemPalette(struct BoxPokemon *boxMon) @@ -598,7 +598,7 @@ const u32 *BoxMonGetCaughtBallItemPalette(struct BoxPokemon *boxMon) default: id = 0; break; } - return gAgbPmRomParams->ballSpritePalettes[id].data; + return gAgbPmRomParams->ballPalettes[id].data; } u32 GetBoxMonMoveBySlot(struct BoxPokemon *boxMon, s32 slot) @@ -812,7 +812,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) case MON_DATA_NICKNAME: { s32 i; - for (i = 0; i < gAgbPmRomParams->pokemonNameLength_1; i++) + for (i = 0; i < gAgbPmRomParams->pokemonNameLength1; i++) boxMon->nickname[i] = data[i]; break; } @@ -1123,7 +1123,7 @@ void GiveGiftRibbonToParty(s32 index_, s32 ribbonId_) gotRibbon = TRUE; } if (gotRibbon) - SetFlag(gAgbPmRomParams->giftRibbonsOffs); + SetFlag(gAgbPmRomParams->giftRibbonsOffset); } } @@ -1150,7 +1150,7 @@ static inline u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality u8 GetMonGender(struct Pokemon *mon) { - const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats; + const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->speciesInfo; u16 species = GetMonDataInline(mon, MON_DATA_SPECIES, NULL); u32 personality = GetMonDataInline(mon, MON_DATA_PERSONALITY, NULL); return GetGenderFromSpeciesAndPersonality(species, personality, speciesInfo); @@ -1161,13 +1161,13 @@ const struct CompressedSpritePalette *GetMonPalettePtrBySpeciesIdPersonality(u16 u32 shinyValue = 0; if (species > NUM_SPECIES) - return &gAgbPmRomParams->monPaletteTable[SPECIES_NONE]; + return &gAgbPmRomParams->monNormalPalettes[SPECIES_NONE]; shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); if (shinyValue <= 7) - return &gAgbPmRomParams->monShinyPaletteTable[species]; + return &gAgbPmRomParams->monShinyPalettes[species]; else - return &gAgbPmRomParams->monPaletteTable[species]; + return &gAgbPmRomParams->monNormalPalettes[species]; } inline u16 GetUnownLetterByPersonality(u32 personality) @@ -1202,14 +1202,14 @@ u16 FixUnownSpecies(u16 species, u32 personality) void GetSpeciesName(u8 *name, s32 species) { s32 i; - const u8 (*speciesNames)[][POKEMON_NAME_LENGTH + 1] = gAgbPmRomParams->speciesNames; + const u8 (*monSpeciesNames)[][POKEMON_NAME_LENGTH + 1] = gAgbPmRomParams->monSpeciesNames; - for (i = 0; i < gAgbPmRomParams->pokemonNameLength_1 + gAgbPmRomParams->unk82; i++) + for (i = 0; i < gAgbPmRomParams->pokemonNameLength1 + gAgbPmRomParams->endOfStringLength; i++) { if (species > NUM_SPECIES) - name[i] = (*speciesNames)[0][i]; + name[i] = (*monSpeciesNames)[0][i]; else - name[i] = (*speciesNames)[species][i]; + name[i] = (*monSpeciesNames)[species][i]; if (name[i] == EOS) break; @@ -1220,7 +1220,7 @@ void GetSpeciesName(u8 *name, s32 species) u32 GetMonType(struct Pokemon *mon, u32 which) { - const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats; + const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->speciesInfo; u32 species = GetMonDataInline(mon, MON_DATA_SPECIES, NULL); switch (which) @@ -1253,7 +1253,7 @@ const u8 *GetAbilityDescription(u32 ability) s32 CalculatePPWithBonus(u32 move, s32 ppBonuses, u32 moveIndex) { - const struct BattleMove *moves = gAgbPmRomParams->battleMoves; + const struct BattleMove *moves = gAgbPmRomParams->moves; s32 basePP = moves[move].pp; return basePP + ((basePP * 20 * ((gPPUpReadMasks[moveIndex] & ppBonuses) >> (2 * moveIndex))) / 100); } @@ -1261,9 +1261,9 @@ s32 CalculatePPWithBonus(u32 move, s32 ppBonuses, u32 moveIndex) void CopyMoveName(u8 *dst, u32 move) { s32 i; - const u8 (*moveNames)[][ABILITY_NAME_LENGTH + 1] = gAgbPmRomParams->moveNames; + const u8 (*moveNames)[][MOVE_NAME_LENGTH + 1] = gAgbPmRomParams->moveNames; - for (i = 0; i < gAgbPmRomParams->unk78 + gAgbPmRomParams->unk82; i++) + for (i = 0; i < gAgbPmRomParams->moveNameLength + gAgbPmRomParams->endOfStringLength; i++) { dst[i] = (*moveNames)[move][i]; if (dst[i] == EOS) @@ -1284,7 +1284,7 @@ struct Pokemon *GetPtrToEmptyPartySlot(void) // The same as GetMonGender except GetGenderFromSpeciesAndPersonality isn't called by copied. static UNUSED u8 GetMonGender2(struct Pokemon *mon) { - const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats; + const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->speciesInfo; u16 species = GetMonDataInline(mon, MON_DATA_SPECIES, NULL); u32 personality = GetMonDataInline(mon, MON_DATA_PERSONALITY, NULL); diff --git a/payload/src/rom_info.c b/payload/src/rom_info.c index 10988d3..6345ca7 100644 --- a/payload/src/rom_info.c +++ b/payload/src/rom_info.c @@ -3,309 +3,309 @@ #include "rom_info.h" // Ruby rev0 -struct RomInfo gAgbPmRomParams_AXVE_rev0 = { - .gameVersion = VERSION_RUBY, - .gameLanguage = LANGUAGE_ENGLISH, - .gameTitle = "pokemon ruby version", - .monFrontPicTable = (const struct CompressedSpriteSheet *)0x081e8354, - .monBackPicTable = (const struct CompressedSpriteSheet *)0x081e97f4, - .monPaletteTable = (const struct CompressedSpritePalette *)0x081ea5b4, - .monShinyPaletteTable = (const struct CompressedSpritePalette *)0x081eb374, - .monIconTable = (const u8 *const *)0x083bbd20, - .gMonIconPaletteIndices = (const u8 *)0x083bc400, - .monIconPaletteTable = (const struct SpritePalette *)0x083bc5b8, - .speciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f716c, +struct GFRomHeader gAgbPmRomParams_AXVE_rev0 = { + .version = VERSION_RUBY, + .language = LANGUAGE_ENGLISH, + .gameName = "pokemon ruby version", + .monFrontPics = (const struct CompressedSpriteSheet *)0x081e8354, + .monBackPics = (const struct CompressedSpriteSheet *)0x081e97f4, + .monNormalPalettes = (const struct CompressedSpritePalette *)0x081ea5b4, + .monShinyPalettes = (const struct CompressedSpritePalette *)0x081eb374, + .monIcons = (const u8 *const *)0x083bbd20, + .monIconPaletteIds = (const u8 *)0x083bc400, + .monIconPalettes = (const struct SpritePalette *)0x083bc5b8, + .monSpeciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f716c, .moveNames = (const u8 (*)[][MOVE_NAME_LENGTH + 1])0x081f8320, .decorations = (const struct Decoration *)0x083eb6c4, - .flagsOffs = offsetof(struct SaveBlock1, flags), - .varsOffs = offsetof(struct SaveBlock1, vars), - .pokedexOffs = offsetof(struct SaveBlock2, pokedex), - .dexSeen2Offs = offsetof(struct SaveBlock1, dexSeen2), - .dexSeen3Offs = offsetof(struct SaveBlock1, dexSeen3), + .flagsOffset = offsetof(struct SaveBlock1, flags), + .varsOffset = offsetof(struct SaveBlock1, vars), + .pokedexOffset = offsetof(struct SaveBlock2, pokedex), + .seen1Offset = offsetof(struct SaveBlock1, dexSeen2), + .seen2Offset = offsetof(struct SaveBlock1, dexSeen3), .pokedexVar = VAR_NATIONAL_DEX - VARS_START, .pokedexFlag = FLAG_SYS_NATIONAL_DEX, .mysteryEventFlag = FLAG_SYS_EXDATA_ENABLE, .pokedexCount = NATIONAL_DEX_COUNT, .playerNameLength = PLAYER_NAME_LENGTH, - .unk75 = 10, - .pokemonNameLength_1 = POKEMON_NAME_LENGTH, - .pokemonNameLength_2 = POKEMON_NAME_LENGTH, - .unk78 = 12, - .unk79 = 12, - .unk7A = 6, - .unk7B = 12, - .unk7C = 6, - .unk7D = 16, - .unk7E = 18, - .unk7F = 12, - .unk80 = 15, - .unk81 = 11, - .unk82 = 1, - .unk83 = 8, - .unk84 = 12, + .trainerNameLength = 10, + .pokemonNameLength1 = POKEMON_NAME_LENGTH, + .pokemonNameLength2 = POKEMON_NAME_LENGTH, + .moveNameLength = 12, + .itemNameLength = 12, + .berryNameLength = 6, + .abilityNameLength = 12, + .typeNameLength = 6, + .mapNameLength1 = 16, + .mapNameLength2 = 18, + .trainerClassNameLength = 12, + .decorationNameLength = 15, + .dexCategoryNameLength = 11, + .endOfStringLength = 1, + .frontierTrainerNameLength = 8, + .easyChatWordLength = 12, .saveBlock2Size = sizeof(struct SaveBlock2), .saveBlock1Size = sizeof(struct SaveBlock1), - .playerPartyCountOffs = offsetof(struct SaveBlock1, playerPartyCount), - .playerPartyOffs = offsetof(struct SaveBlock1, playerParty), - .sb2SpecialSaveWarpOffs = offsetof(struct SaveBlock2, specialSaveWarp), - .sb2PlayerIdOffs = offsetof(struct SaveBlock2, playerTrainerId), - .sb2PlayerNameOffs = offsetof(struct SaveBlock2, playerName), - .sb2PlayerGenderOffs = offsetof(struct SaveBlock2, playerGender), - .unkA8 = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), - .unkAC = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), - .externalEventFlagsOffs = offsetof(struct SaveBlock1, externalEventFlags), - .externalEventDataOffs = offsetof(struct SaveBlock1, externalEventData), - .unkB8_0 = FALSE, - .unkB8_1 = FALSE, - .baseStats = (const struct SpeciesInfo *)0x081fec18, + .partyCountOffset = offsetof(struct SaveBlock1, playerPartyCount), + .partyOffset = offsetof(struct SaveBlock1, playerParty), + .warpFlagsOffset = offsetof(struct SaveBlock2, specialSaveWarp), + .trainerIdOffset = offsetof(struct SaveBlock2, playerTrainerId), + .playerNameOffset = offsetof(struct SaveBlock2, playerName), + .playerGenderOffset = offsetof(struct SaveBlock2, playerGender), + .frontierStatusOffset = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), + .frontierStatusOffset2 = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), + .externalEventFlagsOffset = offsetof(struct SaveBlock1, externalEventFlags), + .externalEventDataOffset = offsetof(struct SaveBlock1, externalEventData), + .blockLinkBoxRS = FALSE, + .blockLinkColoXD = FALSE, + .speciesInfo = (const struct SpeciesInfo *)0x081fec18, .abilityNames = (const u8 (*)[][ABILITY_NAME_LENGTH + 1])0x081fa248, .abilityDescriptions = (const u8 **)0x081fa110, .items = (const struct Item *)0x083c5564, - .battleMoves = (const struct BattleMove *)0x081fb12c, - .ballSpriteSheets = (const struct CompressedSpriteSheet *)0x0820a92c, - .ballSpritePalettes = (const struct CompressedSpritePalette *)0x0820a98c, - .sysGameClearFlagIdx = FLAG_SYS_GAME_CLEAR, - .sysRibbonGetFlagIdx = FLAG_SYS_RIBBON_GET, + .moves = (const struct BattleMove *)0x081fb12c, + .ballGfx = (const struct CompressedSpriteSheet *)0x0820a92c, + .ballPalettes = (const struct CompressedSpritePalette *)0x0820a98c, + .gameClearFlag = FLAG_SYS_GAME_CLEAR, + .ribbonFlag = FLAG_SYS_RIBBON_GET, .bagCountItems = BAG_ITEMS_COUNT, .bagCountKeyItems = BAG_KEYITEMS_COUNT, .bagCountPokeballs = BAG_POKEBALLS_COUNT, .bagCountTMHMs = BAG_TMHM_COUNT, .bagCountBerries = BAG_BERRIES_COUNT, .pcItemsCount = PC_ITEMS_COUNT, - .pcItemsOffs = offsetof(struct SaveBlock1, pcItems), - .giftRibbonsOffs = offsetof(struct SaveBlock1, giftRibbons), - .enigmaBerryOffs = offsetof(struct SaveBlock1, enigmaBerry), + .pcItemsOffset = offsetof(struct SaveBlock1, pcItems), + .giftRibbonsOffset = offsetof(struct SaveBlock1, giftRibbons), + .enigmaBerryOffset = offsetof(struct SaveBlock1, enigmaBerry), .enigmaBerrySize = sizeof(struct EnigmaBerry), .moveDescriptions = (const u8 *)0x083c09d8, }; // Ruby rev1 -struct RomInfo gAgbPmRomParams_AXVE_rev2 = { - .gameVersion = VERSION_RUBY, - .gameLanguage = LANGUAGE_ENGLISH, - .gameTitle = "pokemon ruby version", - .monFrontPicTable = (const struct CompressedSpriteSheet *)0x081e836c, - .monBackPicTable = (const struct CompressedSpriteSheet *)0x081e980c, - .monPaletteTable = (const struct CompressedSpritePalette *)0x081ea5cc, - .monShinyPaletteTable = (const struct CompressedSpritePalette *)0x081eb38c, - .monIconTable = (const u8 *const *)0x083bbd3c, - .gMonIconPaletteIndices = (const u8 *)0x083bc41c, - .monIconPaletteTable = (const struct SpritePalette *)0x083bc5d4, - .speciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f7184, +struct GFRomHeader gAgbPmRomParams_AXVE_rev2 = { + .version = VERSION_RUBY, + .language = LANGUAGE_ENGLISH, + .gameName = "pokemon ruby version", + .monFrontPics = (const struct CompressedSpriteSheet *)0x081e836c, + .monBackPics = (const struct CompressedSpriteSheet *)0x081e980c, + .monNormalPalettes = (const struct CompressedSpritePalette *)0x081ea5cc, + .monShinyPalettes = (const struct CompressedSpritePalette *)0x081eb38c, + .monIcons = (const u8 *const *)0x083bbd3c, + .monIconPaletteIds = (const u8 *)0x083bc41c, + .monIconPalettes = (const struct SpritePalette *)0x083bc5d4, + .monSpeciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f7184, .moveNames = (const u8 (*)[][MOVE_NAME_LENGTH + 1])0x081f8338, .decorations = (const struct Decoration *)0x083eb6e0, - .flagsOffs = offsetof(struct SaveBlock1, flags), - .varsOffs = offsetof(struct SaveBlock1, vars), - .pokedexOffs = offsetof(struct SaveBlock2, pokedex), - .dexSeen2Offs = offsetof(struct SaveBlock1, dexSeen2), - .dexSeen3Offs = offsetof(struct SaveBlock1, dexSeen3), + .flagsOffset = offsetof(struct SaveBlock1, flags), + .varsOffset = offsetof(struct SaveBlock1, vars), + .pokedexOffset = offsetof(struct SaveBlock2, pokedex), + .seen1Offset = offsetof(struct SaveBlock1, dexSeen2), + .seen2Offset = offsetof(struct SaveBlock1, dexSeen3), .pokedexVar = VAR_NATIONAL_DEX - VARS_START, .pokedexFlag = FLAG_SYS_NATIONAL_DEX, .mysteryEventFlag = FLAG_SYS_EXDATA_ENABLE, .pokedexCount = NATIONAL_DEX_COUNT, .playerNameLength = PLAYER_NAME_LENGTH, - .unk75 = 10, - .pokemonNameLength_1 = POKEMON_NAME_LENGTH, - .pokemonNameLength_2 = POKEMON_NAME_LENGTH, - .unk78 = 12, - .unk79 = 12, - .unk7A = 6, - .unk7B = 12, - .unk7C = 6, - .unk7D = 16, - .unk7E = 18, - .unk7F = 12, - .unk80 = 15, - .unk81 = 11, - .unk82 = 1, - .unk83 = 8, - .unk84 = 12, + .trainerNameLength = 10, + .pokemonNameLength1 = POKEMON_NAME_LENGTH, + .pokemonNameLength2 = POKEMON_NAME_LENGTH, + .moveNameLength = 12, + .itemNameLength = 12, + .berryNameLength = 6, + .abilityNameLength = 12, + .typeNameLength = 6, + .mapNameLength1 = 16, + .mapNameLength2 = 18, + .trainerClassNameLength = 12, + .decorationNameLength = 15, + .dexCategoryNameLength = 11, + .endOfStringLength = 1, + .frontierTrainerNameLength = 8, + .easyChatWordLength = 12, .saveBlock2Size = sizeof(struct SaveBlock2), .saveBlock1Size = sizeof(struct SaveBlock1), - .playerPartyCountOffs = offsetof(struct SaveBlock1, playerPartyCount), - .playerPartyOffs = offsetof(struct SaveBlock1, playerParty), - .sb2SpecialSaveWarpOffs = offsetof(struct SaveBlock2, specialSaveWarp), - .sb2PlayerIdOffs = offsetof(struct SaveBlock2, playerTrainerId), - .sb2PlayerNameOffs = offsetof(struct SaveBlock2, playerName), - .sb2PlayerGenderOffs = offsetof(struct SaveBlock2, playerGender), - .unkA8 = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), - .unkAC = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), - .externalEventFlagsOffs = offsetof(struct SaveBlock1, externalEventFlags), - .externalEventDataOffs = offsetof(struct SaveBlock1, externalEventData), - .unkB8_0 = FALSE, - .unkB8_1 = FALSE, - .baseStats = (const struct SpeciesInfo *)0x081fec30, + .partyCountOffset = offsetof(struct SaveBlock1, playerPartyCount), + .partyOffset = offsetof(struct SaveBlock1, playerParty), + .warpFlagsOffset = offsetof(struct SaveBlock2, specialSaveWarp), + .trainerIdOffset = offsetof(struct SaveBlock2, playerTrainerId), + .playerNameOffset = offsetof(struct SaveBlock2, playerName), + .playerGenderOffset = offsetof(struct SaveBlock2, playerGender), + .frontierStatusOffset = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), + .frontierStatusOffset2 = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), + .externalEventFlagsOffset = offsetof(struct SaveBlock1, externalEventFlags), + .externalEventDataOffset = offsetof(struct SaveBlock1, externalEventData), + .blockLinkBoxRS = FALSE, + .blockLinkColoXD = FALSE, + .speciesInfo = (const struct SpeciesInfo *)0x081fec30, .abilityNames = (const u8 (*)[][ABILITY_NAME_LENGTH + 1])0x081fa260, .abilityDescriptions = (const u8 **)0x081fa128, .items = (const struct Item *)0x083c5580, - .battleMoves = (const struct BattleMove *)0x081fb144, - .ballSpriteSheets = (const struct CompressedSpriteSheet *)0x0820a944, - .ballSpritePalettes = (const struct CompressedSpritePalette *)0x0820a9a4, - .sysGameClearFlagIdx = FLAG_SYS_GAME_CLEAR, - .sysRibbonGetFlagIdx = FLAG_SYS_RIBBON_GET, + .moves = (const struct BattleMove *)0x081fb144, + .ballGfx = (const struct CompressedSpriteSheet *)0x0820a944, + .ballPalettes = (const struct CompressedSpritePalette *)0x0820a9a4, + .gameClearFlag = FLAG_SYS_GAME_CLEAR, + .ribbonFlag = FLAG_SYS_RIBBON_GET, .bagCountItems = BAG_ITEMS_COUNT, .bagCountKeyItems = BAG_KEYITEMS_COUNT, .bagCountPokeballs = BAG_POKEBALLS_COUNT, .bagCountTMHMs = BAG_TMHM_COUNT, .bagCountBerries = BAG_BERRIES_COUNT, .pcItemsCount = PC_ITEMS_COUNT, - .pcItemsOffs = offsetof(struct SaveBlock1, pcItems), - .giftRibbonsOffs = offsetof(struct SaveBlock1, giftRibbons), - .enigmaBerryOffs = offsetof(struct SaveBlock1, enigmaBerry), + .pcItemsOffset = offsetof(struct SaveBlock1, pcItems), + .giftRibbonsOffset = offsetof(struct SaveBlock1, giftRibbons), + .enigmaBerryOffset = offsetof(struct SaveBlock1, enigmaBerry), .enigmaBerrySize = sizeof(struct EnigmaBerry), .moveDescriptions = (const u8 *)0x083c09f4, }; // Sapphire rev0 -struct RomInfo gAgbPmRomParams_AXPE_rev0 = { - .gameVersion = VERSION_SAPPHIRE, - .gameLanguage = LANGUAGE_ENGLISH, - .gameTitle = "pokemon sapphire version", - .monFrontPicTable = (const struct CompressedSpriteSheet *)0x081e82e4, - .monBackPicTable = (const struct CompressedSpriteSheet *)0x081e9784, - .monPaletteTable = (const struct CompressedSpritePalette *)0x081ea544, - .monShinyPaletteTable = (const struct CompressedSpritePalette *)0x081eb304, - .monIconTable = (const u8 *const *)0x083bbd78, - .gMonIconPaletteIndices = (const u8 *)0x083bc458, - .monIconPaletteTable = (const struct SpritePalette *)0x083bc610, - .speciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f70fc, +struct GFRomHeader gAgbPmRomParams_AXPE_rev0 = { + .version = VERSION_SAPPHIRE, + .language = LANGUAGE_ENGLISH, + .gameName = "pokemon sapphire version", + .monFrontPics = (const struct CompressedSpriteSheet *)0x081e82e4, + .monBackPics = (const struct CompressedSpriteSheet *)0x081e9784, + .monNormalPalettes = (const struct CompressedSpritePalette *)0x081ea544, + .monShinyPalettes = (const struct CompressedSpritePalette *)0x081eb304, + .monIcons = (const u8 *const *)0x083bbd78, + .monIconPaletteIds = (const u8 *)0x083bc458, + .monIconPalettes = (const struct SpritePalette *)0x083bc610, + .monSpeciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f70fc, .moveNames = (const u8 (*)[][MOVE_NAME_LENGTH + 1])0x081f82b0, .decorations = (const struct Decoration *)0x083eb71c, - .flagsOffs = offsetof(struct SaveBlock1, flags), - .varsOffs = offsetof(struct SaveBlock1, vars), - .pokedexOffs = offsetof(struct SaveBlock2, pokedex), - .dexSeen2Offs = offsetof(struct SaveBlock1, dexSeen2), - .dexSeen3Offs = offsetof(struct SaveBlock1, dexSeen3), + .flagsOffset = offsetof(struct SaveBlock1, flags), + .varsOffset = offsetof(struct SaveBlock1, vars), + .pokedexOffset = offsetof(struct SaveBlock2, pokedex), + .seen1Offset = offsetof(struct SaveBlock1, dexSeen2), + .seen2Offset = offsetof(struct SaveBlock1, dexSeen3), .pokedexVar = VAR_NATIONAL_DEX - VARS_START, .pokedexFlag = FLAG_SYS_NATIONAL_DEX, .mysteryEventFlag = FLAG_SYS_EXDATA_ENABLE, .pokedexCount = NATIONAL_DEX_COUNT, .playerNameLength = PLAYER_NAME_LENGTH, - .unk75 = 10, - .pokemonNameLength_1 = POKEMON_NAME_LENGTH, - .pokemonNameLength_2 = POKEMON_NAME_LENGTH, - .unk78 = 12, - .unk79 = 12, - .unk7A = 6, - .unk7B = 12, - .unk7C = 6, - .unk7D = 16, - .unk7E = 18, - .unk7F = 12, - .unk80 = 15, - .unk81 = 11, - .unk82 = 1, - .unk83 = 8, - .unk84 = 12, + .trainerNameLength = 10, + .pokemonNameLength1 = POKEMON_NAME_LENGTH, + .pokemonNameLength2 = POKEMON_NAME_LENGTH, + .moveNameLength = 12, + .itemNameLength = 12, + .berryNameLength = 6, + .abilityNameLength = 12, + .typeNameLength = 6, + .mapNameLength1 = 16, + .mapNameLength2 = 18, + .trainerClassNameLength = 12, + .decorationNameLength = 15, + .dexCategoryNameLength = 11, + .endOfStringLength = 1, + .frontierTrainerNameLength = 8, + .easyChatWordLength = 12, .saveBlock2Size = sizeof(struct SaveBlock2), .saveBlock1Size = sizeof(struct SaveBlock1), - .playerPartyCountOffs = offsetof(struct SaveBlock1, playerPartyCount), - .playerPartyOffs = offsetof(struct SaveBlock1, playerParty), - .sb2SpecialSaveWarpOffs = offsetof(struct SaveBlock2, specialSaveWarp), - .sb2PlayerIdOffs = offsetof(struct SaveBlock2, playerTrainerId), - .sb2PlayerNameOffs = offsetof(struct SaveBlock2, playerName), - .sb2PlayerGenderOffs = offsetof(struct SaveBlock2, playerGender), - .unkA8 = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), - .unkAC = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), - .externalEventFlagsOffs = offsetof(struct SaveBlock1, externalEventFlags), - .externalEventDataOffs = offsetof(struct SaveBlock1, externalEventData), - .unkB8_0 = FALSE, - .unkB8_1 = FALSE, - .baseStats = (const struct SpeciesInfo *)0x081feba8, + .partyCountOffset = offsetof(struct SaveBlock1, playerPartyCount), + .partyOffset = offsetof(struct SaveBlock1, playerParty), + .warpFlagsOffset = offsetof(struct SaveBlock2, specialSaveWarp), + .trainerIdOffset = offsetof(struct SaveBlock2, playerTrainerId), + .playerNameOffset = offsetof(struct SaveBlock2, playerName), + .playerGenderOffset = offsetof(struct SaveBlock2, playerGender), + .frontierStatusOffset = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), + .frontierStatusOffset2 = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), + .externalEventFlagsOffset = offsetof(struct SaveBlock1, externalEventFlags), + .externalEventDataOffset = offsetof(struct SaveBlock1, externalEventData), + .blockLinkBoxRS = FALSE, + .blockLinkColoXD = FALSE, + .speciesInfo = (const struct SpeciesInfo *)0x081feba8, .abilityNames = (const u8 (*)[][ABILITY_NAME_LENGTH + 1])0x081fa1d8, .abilityDescriptions = (const u8 **)0x081fa0a0, .items = (const struct Item *)0x083c55bc, - .battleMoves = (const struct BattleMove *)0x081fb0bc, - .ballSpriteSheets = (const struct CompressedSpriteSheet *)0x0820a8bc, - .ballSpritePalettes = (const struct CompressedSpritePalette *)0x0820a91c, - .sysGameClearFlagIdx = FLAG_SYS_GAME_CLEAR, - .sysRibbonGetFlagIdx = FLAG_SYS_RIBBON_GET, + .moves = (const struct BattleMove *)0x081fb0bc, + .ballGfx = (const struct CompressedSpriteSheet *)0x0820a8bc, + .ballPalettes = (const struct CompressedSpritePalette *)0x0820a91c, + .gameClearFlag = FLAG_SYS_GAME_CLEAR, + .ribbonFlag = FLAG_SYS_RIBBON_GET, .bagCountItems = BAG_ITEMS_COUNT, .bagCountKeyItems = BAG_KEYITEMS_COUNT, .bagCountPokeballs = BAG_POKEBALLS_COUNT, .bagCountTMHMs = BAG_TMHM_COUNT, .bagCountBerries = BAG_BERRIES_COUNT, .pcItemsCount = PC_ITEMS_COUNT, - .pcItemsOffs = offsetof(struct SaveBlock1, pcItems), - .giftRibbonsOffs = offsetof(struct SaveBlock1, giftRibbons), - .enigmaBerryOffs = offsetof(struct SaveBlock1, enigmaBerry), + .pcItemsOffset = offsetof(struct SaveBlock1, pcItems), + .giftRibbonsOffset = offsetof(struct SaveBlock1, giftRibbons), + .enigmaBerryOffset = offsetof(struct SaveBlock1, enigmaBerry), .enigmaBerrySize = sizeof(struct EnigmaBerry), .moveDescriptions = (const u8 *)0x083c0a30, }; // Sapphire rev2 -struct RomInfo gAgbPmRomParams_AXPE_rev2 = { - .gameVersion = VERSION_SAPPHIRE, - .gameLanguage = LANGUAGE_ENGLISH, - .gameTitle = "pokemon sapphire version", - .monFrontPicTable = (const struct CompressedSpriteSheet *)0x081e82fc, - .monBackPicTable = (const struct CompressedSpriteSheet *)0x081e979c, - .monPaletteTable = (const struct CompressedSpritePalette *)0x081ea55c, - .monShinyPaletteTable = (const struct CompressedSpritePalette *)0x081eb31c, - .monIconTable = (const u8 *const *)0x083bbd98, - .gMonIconPaletteIndices = (const u8 *)0x083bc478, - .monIconPaletteTable = (const struct SpritePalette *)0x083bc630, - .speciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f7114, +struct GFRomHeader gAgbPmRomParams_AXPE_rev2 = { + .version = VERSION_SAPPHIRE, + .language = LANGUAGE_ENGLISH, + .gameName = "pokemon sapphire version", + .monFrontPics = (const struct CompressedSpriteSheet *)0x081e82fc, + .monBackPics = (const struct CompressedSpriteSheet *)0x081e979c, + .monNormalPalettes = (const struct CompressedSpritePalette *)0x081ea55c, + .monShinyPalettes = (const struct CompressedSpritePalette *)0x081eb31c, + .monIcons = (const u8 *const *)0x083bbd98, + .monIconPaletteIds = (const u8 *)0x083bc478, + .monIconPalettes = (const struct SpritePalette *)0x083bc630, + .monSpeciesNames = (const u8 (*)[][POKEMON_NAME_LENGTH + 1])0x081f7114, .moveNames = (const u8 (*)[][MOVE_NAME_LENGTH + 1])0x081f82c8, .decorations = (const struct Decoration *)0x083eb73c, - .flagsOffs = offsetof(struct SaveBlock1, flags), - .varsOffs = offsetof(struct SaveBlock1, vars), - .pokedexOffs = offsetof(struct SaveBlock2, pokedex), - .dexSeen2Offs = offsetof(struct SaveBlock1, dexSeen2), - .dexSeen3Offs = offsetof(struct SaveBlock1, dexSeen3), + .flagsOffset = offsetof(struct SaveBlock1, flags), + .varsOffset = offsetof(struct SaveBlock1, vars), + .pokedexOffset = offsetof(struct SaveBlock2, pokedex), + .seen1Offset = offsetof(struct SaveBlock1, dexSeen2), + .seen2Offset = offsetof(struct SaveBlock1, dexSeen3), .pokedexVar = VAR_NATIONAL_DEX - VARS_START, .pokedexFlag = FLAG_SYS_NATIONAL_DEX, .mysteryEventFlag = FLAG_SYS_EXDATA_ENABLE, .pokedexCount = NATIONAL_DEX_COUNT, .playerNameLength = PLAYER_NAME_LENGTH, - .unk75 = 10, - .pokemonNameLength_1 = POKEMON_NAME_LENGTH, - .pokemonNameLength_2 = POKEMON_NAME_LENGTH, - .unk78 = 12, - .unk79 = 12, - .unk7A = 6, - .unk7B = 12, - .unk7C = 6, - .unk7D = 16, - .unk7E = 18, - .unk7F = 12, - .unk80 = 15, - .unk81 = 11, - .unk82 = 1, - .unk83 = 8, - .unk84 = 12, + .trainerNameLength = 10, + .pokemonNameLength1 = POKEMON_NAME_LENGTH, + .pokemonNameLength2 = POKEMON_NAME_LENGTH, + .moveNameLength = 12, + .itemNameLength = 12, + .berryNameLength = 6, + .abilityNameLength = 12, + .typeNameLength = 6, + .mapNameLength1 = 16, + .mapNameLength2 = 18, + .trainerClassNameLength = 12, + .decorationNameLength = 15, + .dexCategoryNameLength = 11, + .endOfStringLength = 1, + .frontierTrainerNameLength = 8, + .easyChatWordLength = 12, .saveBlock2Size = sizeof(struct SaveBlock2), .saveBlock1Size = sizeof(struct SaveBlock1), - .playerPartyCountOffs = offsetof(struct SaveBlock1, playerPartyCount), - .playerPartyOffs = offsetof(struct SaveBlock1, playerParty), - .sb2SpecialSaveWarpOffs = offsetof(struct SaveBlock2, specialSaveWarp), - .sb2PlayerIdOffs = offsetof(struct SaveBlock2, playerTrainerId), - .sb2PlayerNameOffs = offsetof(struct SaveBlock2, playerName), - .sb2PlayerGenderOffs = offsetof(struct SaveBlock2, playerGender), - .unkA8 = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), - .unkAC = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), - .externalEventFlagsOffs = offsetof(struct SaveBlock1, externalEventFlags), - .externalEventDataOffs = offsetof(struct SaveBlock1, externalEventData), - .unkB8_0 = FALSE, - .unkB8_1 = FALSE, - .baseStats = (const struct SpeciesInfo *)0x081febc0, + .partyCountOffset = offsetof(struct SaveBlock1, playerPartyCount), + .partyOffset = offsetof(struct SaveBlock1, playerParty), + .warpFlagsOffset = offsetof(struct SaveBlock2, specialSaveWarp), + .trainerIdOffset = offsetof(struct SaveBlock2, playerTrainerId), + .playerNameOffset = offsetof(struct SaveBlock2, playerName), + .playerGenderOffset = offsetof(struct SaveBlock2, playerGender), + .frontierStatusOffset = offsetof(struct SaveBlock2, battleTower.var_4AE[0]), + .frontierStatusOffset2 = offsetof(struct SaveBlock2, battleTower.var_4AE[1]), + .externalEventFlagsOffset = offsetof(struct SaveBlock1, externalEventFlags), + .externalEventDataOffset = offsetof(struct SaveBlock1, externalEventData), + .blockLinkBoxRS = FALSE, + .blockLinkColoXD = FALSE, + .speciesInfo = (const struct SpeciesInfo *)0x081febc0, .abilityNames = (const u8 (*)[][ABILITY_NAME_LENGTH + 1])0x081fa1f0, .abilityDescriptions = (const u8 **)0x081fa0b8, .items = (const struct Item *)0x083c55dc, - .battleMoves = (const struct BattleMove *)0x081fb0d4, - .ballSpriteSheets = (const struct CompressedSpriteSheet *)0x0820a8d4, - .ballSpritePalettes = (const struct CompressedSpritePalette *)0x0820a934, - .sysGameClearFlagIdx = FLAG_SYS_GAME_CLEAR, - .sysRibbonGetFlagIdx = FLAG_SYS_RIBBON_GET, + .moves = (const struct BattleMove *)0x081fb0d4, + .ballGfx = (const struct CompressedSpriteSheet *)0x0820a8d4, + .ballPalettes = (const struct CompressedSpritePalette *)0x0820a934, + .gameClearFlag = FLAG_SYS_GAME_CLEAR, + .ribbonFlag = FLAG_SYS_RIBBON_GET, .bagCountItems = BAG_ITEMS_COUNT, .bagCountKeyItems = BAG_KEYITEMS_COUNT, .bagCountPokeballs = BAG_POKEBALLS_COUNT, .bagCountTMHMs = BAG_TMHM_COUNT, .bagCountBerries = BAG_BERRIES_COUNT, .pcItemsCount = PC_ITEMS_COUNT, - .pcItemsOffs = offsetof(struct SaveBlock1, pcItems), - .giftRibbonsOffs = offsetof(struct SaveBlock1, giftRibbons), - .enigmaBerryOffs = offsetof(struct SaveBlock1, enigmaBerry), + .pcItemsOffset = offsetof(struct SaveBlock1, pcItems), + .giftRibbonsOffset = offsetof(struct SaveBlock1, giftRibbons), + .enigmaBerryOffset = offsetof(struct SaveBlock1, enigmaBerry), .enigmaBerrySize = sizeof(struct EnigmaBerry), .moveDescriptions = (const u8 *)0x083c0a50, }; diff --git a/payload/src/unk_200C5DC.c b/payload/src/unk_200C5DC.c index 933b5d5..5afda06 100644 --- a/payload/src/unk_200C5DC.c +++ b/payload/src/unk_200C5DC.c @@ -187,21 +187,21 @@ struct Struct_gUnknown_02023F50 *sub_0200C9C0(u8 *sav2, u8 *sav1, u32 arg2) { u8 *saveData; - if (!gAgbPmRomParams->unkB8_1) + if (!gAgbPmRomParams->blockLinkColoXD) { structPtr->field0_0 = sub_0200CD88(); structPtr->field0_1 = ((GetPlayerMapType() & 2) != 0); structPtr->field0_2 = IsFRLG(); structPtr->field0_3 = ((GetPlayerMapType() & 0x80) != 0); - structPtr->field0_4 = gAgbPmRomParams->gameLanguage; + structPtr->field0_4 = gAgbPmRomParams->language; } - saveData = &sav2[gAgbPmRomParams->sb2PlayerNameOffs]; + saveData = &sav2[gAgbPmRomParams->playerNameOffset]; StringCopy(structPtr->field4, saveData); - saveData = &sav2[gAgbPmRomParams->sb2PlayerGenderOffs]; + saveData = &sav2[gAgbPmRomParams->playerGenderOffset]; structPtr->field12 = *saveData; - saveData = &sav2[gAgbPmRomParams->sb2PlayerIdOffs]; + saveData = &sav2[gAgbPmRomParams->trainerIdOffset]; for (i = 0; i < 4; i++) structPtr->field16[i] = saveData[i]; @@ -352,7 +352,7 @@ void DetectROM(void) if (r3 == 1) { - if (gAgbPmRomParams->gameLanguage == LANGUAGE_ENGLISH) + if (gAgbPmRomParams->language == LANGUAGE_ENGLISH) gRomDetection_IsEnglishROM = TRUE; else gRomDetection_IsEnglishROM = FALSE; @@ -364,7 +364,7 @@ u8 GetPlayerMapType(void) u8 ret; if (!gRomDetection_IsRubySapphire) { - ret = *((u8 *)(gSaveBlock2Ptr) + gAgbPmRomParams->sb2SpecialSaveWarpOffs); + ret = *((u8 *)(gSaveBlock2Ptr) + gAgbPmRomParams->warpFlagsOffset); } else { @@ -384,7 +384,7 @@ u8 sub_0200CD88(void) { bool32 val; if (!gRomDetection_IsRubySapphire) - val = ((*((u8 *)(gSaveBlock2Ptr) + gAgbPmRomParams->gcnLinkFlagsOffs) & 1)); + val = ((*((u8 *)(gSaveBlock2Ptr) + gAgbPmRomParams->gcnLinkFlagsOffset) & 1)); else val = CheckFlag(0x801); @@ -396,7 +396,7 @@ u8 sub_0200CD88(void) bool32 IsFRLG(void) { - if (gAgbPmRomParams->gameVersion == VERSION_FIRE_RED || gAgbPmRomParams->gameVersion == VERSION_LEAF_GREEN) + if (gAgbPmRomParams->version == VERSION_FIRE_RED || gAgbPmRomParams->version == VERSION_LEAF_GREEN) return TRUE; else return FALSE; @@ -404,8 +404,8 @@ bool32 IsFRLG(void) bool32 CheckGameClear(void) { - u8 *flagsPtr = gSaveBlock1Ptr + gAgbPmRomParams->flagsOffs + (gAgbPmRomParams->sysGameClearFlagIdx / 8); - return (*flagsPtr & (1 << (gAgbPmRomParams->sysGameClearFlagIdx % 8))) != 0; + u8 *flagsPtr = gSaveBlock1Ptr + gAgbPmRomParams->flagsOffset + (gAgbPmRomParams->gameClearFlag / 8); + return (*flagsPtr & (1 << (gAgbPmRomParams->gameClearFlag % 8))) != 0; } u16 GetStringSizeHandleExtCtrlCodes(u8 *str) @@ -596,7 +596,7 @@ static inline void CopyN(s32 n, u8 *dst, const u8 *src) void sub_0200D1AC(u32 val) { - u8 *ptr = (u8 *)(gSaveBlock1Ptr) + gAgbPmRomParams->externalEventDataOffs; + u8 *ptr = (u8 *)(gSaveBlock1Ptr) + gAgbPmRomParams->externalEventDataOffset; // Note: cast is needed here to make the code match. The whole struct is declared as volatile, but unkStruct isn't treated as volatile in this function. // It's possible only certain members of gUnknown_02024960 were volatile. struct UnkStruct868 *unkStruct = (struct UnkStruct868 *) &gUnknown_02024960.unk868; @@ -824,7 +824,7 @@ void sub_0200D624(void) { bool32 gameClear; u32 joyTransVal; - u8 *ptr = (u8 *)(gSaveBlock1Ptr) + gAgbPmRomParams->externalEventDataOffs; + u8 *ptr = (u8 *)(gSaveBlock1Ptr) + gAgbPmRomParams->externalEventDataOffset; struct UnkStruct868 *unkStruct = (struct UnkStruct868 *) &gUnknown_02024960.unk868; switch (gUnknown_020251F0.field10) diff --git a/payload/sym_common.txt b/payload/sym_common.txt index f2d48e8..9e109c3 100644 --- a/payload/sym_common.txt +++ b/payload/sym_common.txt @@ -104,13 +104,13 @@ gLastSaveBlockPtr: .space 0x4 @ gflib/save.o -gFirstSaveSector: +gLastWrittenSector: .space 0x4 -gPrevSaveCounter: +gLastSaveCounter: .space 0xc -gUnknown_02022F10: +gSaveStatusFlags: .space 0x14 gLastKnownGoodSector: @@ -122,13 +122,13 @@ gDamagedSaveSectors: gSaveCounter: .space 0x4 -gFastSaveSection: +gReadWriteSector: .space 0x10 gSaveReadBuffer: .space 0x1000 -gUnknown_02023F40: +gIncrementalSectorId: .space 0x10 @ gflib/trade.o