Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gDecompressionBuffer #6029

Open
wants to merge 12 commits into
base: upcoming
Choose a base branch
from
2 changes: 1 addition & 1 deletion asm/macros/event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@
.4byte \text
.endm

@ Equivalent to fadescreen but copies gPlttBufferUnfaded to gDecompressionBuffer on the fade out
@ Equivalent to fadescreen but copies gPlttBufferUnfaded to an allocated buffer on the fade out
@ and the reverse on the fade in, in effect saving gPlttBufferUnfaded to restore it.
.macro fadescreenswapbuffers mode:req
.byte 0xdc
Expand Down
3 changes: 2 additions & 1 deletion include/bg.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ u8 Unused_AdjustBgMosaic(u8 val, u32 mode);
void SetBgTilemapBuffer(u32 bg, void *tilemap);
void UnsetBgTilemapBuffer(u32 bg);
void *GetBgTilemapBuffer(u32 bg);
void CopyToBgTilemapBuffer(u32 bg, const void *src, u16 mode, u16 destOffset);
void CopyToBgTilemapBuffer(u32 bg, const void *src, u32 mode, u32 destOffset);
void DecompressAndCopyToBgTilemapBuffer(u32 bg, const u32 *src, u32 mode, u32 destOffset);
void CopyBgTilemapBufferToVram(u32 bg);
void CopyToBgTilemapBufferRect(u32 bg, const void *src, u8 destX, u8 destY, u8 width, u8 height);
void CopyToBgTilemapBufferRect_ChangePalette(u32 bg, const void *src, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette);
Expand Down
12 changes: 6 additions & 6 deletions include/decompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

#include "sprite.h"

extern u8 ALIGNED(4) gDecompressionBuffer[0x4000];
#define MAX_DECOMPRESSION_BUFFER_SIZE 0x4000

void LZDecompressWram(const u32 *src, void *dest);
void LZDecompressVram(const u32 *src, void *dest);

u32 IsLZ77Data(const void *ptr, u32 minSize, u32 maxSize);

u16 LoadCompressedSpriteSheet(const struct CompressedSpriteSheet *src);
u16 LoadCompressedSpriteSheetByTemplate(const struct SpriteTemplate *template, s32 offset);
void LoadCompressedSpriteSheetOverrideBuffer(const struct CompressedSpriteSheet *src, void *buffer);
u32 LoadCompressedSpriteSheet(const struct CompressedSpriteSheet *src);
u32 LoadCompressedSpriteSheetByTemplate(const struct SpriteTemplate *template, s32 offset);
u32 LoadCompressedSpriteSheetOverrideBuffer(const struct CompressedSpriteSheet *src, void *buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this return an u32?
The single call to this function doesn't store the result, and the final function called in the chain return an u16

bool8 LoadCompressedSpriteSheetUsingHeap(const struct CompressedSpriteSheet *src);

void LoadCompressedSpritePalette(const struct CompressedSpritePalette *src);
void LoadCompressedSpritePaletteWithTag(const u32 *pal, u16 tag);
u32 LoadCompressedSpritePalette(const struct CompressedSpritePalette *src);
u32 LoadCompressedSpritePaletteWithTag(const u32 *pal, u16 tag);
hedara90 marked this conversation as resolved.
Show resolved Hide resolved
void LoadCompressedSpritePaletteOverrideBuffer(const struct CompressedSpritePalette *src, void *buffer);
bool8 LoadCompressedSpritePaletteUsingHeap(const struct CompressedSpritePalette *src);

Expand Down
17 changes: 17 additions & 0 deletions include/hall_of_fame.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#ifndef GUARD_HALL_OF_FAME_H
#define GUARD_HALL_OF_FAME_H

struct HallofFameMon
{
u32 tid;
u32 personality;
u16 isShiny:1;
u16 species:15;
u8 lvl;
u8 nickname[POKEMON_NAME_LENGTH];
};

struct HallofFameTeam
{
struct HallofFameMon mon[PARTY_SIZE];
};

extern struct HallofFameTeam *gHoFSaveBuffer;

void CB2_DoHallOfFameScreen(void);
void CB2_DoHallOfFameScreenDontSaveData(void);
void CB2_DoHallOfFamePC(void);
Expand Down
16 changes: 13 additions & 3 deletions include/item_menu_icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ void RemoveBagItemIconSprite(u8 id);
void CreateItemMenuSwapLine(void);
void SetItemMenuSwapLineInvisibility(bool8 invisible);
void UpdateItemMenuSwapLinePos(u8 y);
u8 CreateBerryTagSprite(u8 id, s16 x, s16 y);
void FreeBerryTagSpritePalette(void);
u8 CreateSpinningBerrySprite(u8 berryId, u8 x, u8 y, bool8 startAffine);

// Note: Because of removing gDecompressionBuffer and allowing to create more than one berry sprite at a time, the memory for gfx is allocated dynamically.
// For CreateBerryTagSprite and CreateSpinningBerrySprite, the allocated ptr is stored in two last data fields(data[6], data[7]), so make sure to NOT put anything in there!
// The corresponding code has already been edited in berry_tag_screen.c and berry_blender.c
#define BERRY_ICON_GFX_PTR_DATA_ID 6
u32 CreateBerryTagSprite(u32 id, s32 x, s32 y);
u32 CreateSpinningBerrySprite(u32 berryId, s32 x, s32 y, bool32 startAffine);
// Needs to always call either of these after creating a Berry Icon sprite, because it frees allocated memory!
void DestroyBerryIconSprite(u32 spriteId, u32 berryId, bool32 freePal);
void DestroyBerryIconSpritePtr(struct Sprite *sprite, u32 berryId, bool32 freePal);

void FreeBerryIconSpritePalette(u32 berryId); // Unused atm, because it's also handled by DestroyBerryIconSprite. Leaving it as it is, because it may still be useful in some custom cases.

u8 CreateBerryFlavorCircleSprite(s16 x);

#endif // GUARD_ITEM_MENU_ICONS_H
1 change: 1 addition & 0 deletions include/mystery_gift_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct MysteryGiftClient
void * msg;
struct MysteryGiftLink link;
bool32 isWonderNews;
ALIGNED(4) u8 bufferScript[MG_LINK_BUFFER_SIZE];
};

void MysteryGiftClient_Create(bool32 isWonderNews);
Expand Down
6 changes: 3 additions & 3 deletions include/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ u16 GetSpriteTileTagByTileStart(u16 start);
void RequestSpriteSheetCopy(const struct SpriteSheet *sheet);
u16 LoadSpriteSheetDeferred(const struct SpriteSheet *sheet);
void FreeAllSpritePalettes(void);
u8 LoadSpritePalette(const struct SpritePalette *palette);
u32 LoadSpritePalette(const struct SpritePalette *palette);
void LoadSpritePalettes(const struct SpritePalette *palettes);
u8 AllocSpritePalette(u16 tag);
u8 IndexOfSpritePaletteTag(u16 tag);
u32 AllocSpritePalette(u16 tag);
u32 IndexOfSpritePaletteTag(u16 tag);
u16 GetSpritePaletteTagByPaletteNum(u8 paletteNum);
void FreeSpritePaletteByTag(u16 tag);
void SetSubspriteTables(struct Sprite *sprite, const struct SubspriteTable *subspriteTables);
Expand Down
15 changes: 7 additions & 8 deletions src/battle_anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "gpu_regs.h"
#include "graphics.h"
#include "main.h"
#include "malloc.h"
#include "m4a.h"
#include "palette.h"
#include "pokemon.h"
Expand Down Expand Up @@ -1570,17 +1571,15 @@ void LoadMoveBg(u16 bgId)
{
if (IsContest())
{
void *decompressionBuffer = Alloc(0x800);
const u32 *tilemap = gBattleAnimBackgroundTable[bgId].tilemap;
void *dmaSrc;
void *dmaDest;

LZDecompressWram(tilemap, gDecompressionBuffer);
RelocateBattleBgPal(GetBattleBgPaletteNum(), (void *)gDecompressionBuffer, 0x100, FALSE);
dmaSrc = gDecompressionBuffer;
dmaDest = (void *)BG_SCREEN_ADDR(26);
DmaCopy32(3, dmaSrc, dmaDest, 0x800);

LZDecompressWram(tilemap, decompressionBuffer);
RelocateBattleBgPal(GetBattleBgPaletteNum(), decompressionBuffer, 0x100, FALSE);
DmaCopy32(3, decompressionBuffer, (void *)BG_SCREEN_ADDR(26), 0x800);
LZDecompressVram(gBattleAnimBackgroundTable[bgId].image, (void *)BG_SCREEN_ADDR(4));
LoadCompressedPalette(gBattleAnimBackgroundTable[bgId].palette, BG_PLTT_ID(GetBattleBgPaletteNum()), PLTT_SIZE_4BPP);
Free(decompressionBuffer);
}
else
{
Expand Down
13 changes: 8 additions & 5 deletions src/battle_gfx_sfx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "constants/battle_anim.h"
#include "battle_interface.h"
#include "main.h"
#include "menu.h"
#include "dma3.h"
#include "malloc.h"
#include "graphics.h"
Expand Down Expand Up @@ -655,9 +656,10 @@ void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battler)
else
lzPaletteData = GetMonSpritePalFromSpeciesAndPersonality(species, isShiny, personalityValue);

LZDecompressWram(lzPaletteData, gDecompressionBuffer);
LoadPalette(gDecompressionBuffer, paletteOffset, PLTT_SIZE_4BPP);
LoadPalette(gDecompressionBuffer, BG_PLTT_ID(8) + BG_PLTT_ID(battler), PLTT_SIZE_4BPP);
void *buffer = malloc_and_decompress(lzPaletteData, NULL);
LoadPalette(buffer, paletteOffset, PLTT_SIZE_4BPP);
LoadPalette(buffer, BG_PLTT_ID(8) + BG_PLTT_ID(battler), PLTT_SIZE_4BPP);
Free(buffer);

// transform's pink color
if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies != SPECIES_NONE)
Expand Down Expand Up @@ -975,8 +977,9 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool32 megaEvo, bo
DmaCopy32(3, src, dst, MON_PIC_SIZE);
paletteOffset = OBJ_PLTT_ID(battlerAtk);
lzPaletteData = GetMonSpritePalFromSpeciesAndPersonality(targetSpecies, isShiny, personalityValue);
LZDecompressWram(lzPaletteData, gDecompressionBuffer);
LoadPalette(gDecompressionBuffer, paletteOffset, PLTT_SIZE_4BPP);
void *buffer = malloc_and_decompress(lzPaletteData, NULL);
LoadPalette(buffer, paletteOffset, PLTT_SIZE_4BPP);
Free(buffer);

if (!megaEvo)
{
Expand Down
67 changes: 0 additions & 67 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ static void HandleEndTurn_BattleLost(void);
static void HandleEndTurn_RanFromBattle(void);
static void HandleEndTurn_MonFled(void);
static void HandleEndTurn_FinishBattle(void);
static void SpriteCB_UnusedBattleInit(struct Sprite *sprite);
static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite);
static u32 Crc32B (const u8 *data, u32 size);
static u32 GeneratePartyHash(const struct Trainer *trainer, u32 i);
static s32 Factorial(s32);
Expand Down Expand Up @@ -255,17 +253,6 @@ static const struct ScanlineEffectParams sIntroScanlineParams32Bit =
&REG_BG3HOFS, SCANLINE_EFFECT_DMACNT_32BIT, 1
};

const struct SpriteTemplate gUnusedBattleInitSprite =
{
.tileTag = 0,
.paletteTag = 0,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_UnusedBattleInit,
};

static const u8 sText_ShedinjaJpnName[] = _("ヌケニン"); // Nukenin

const struct OamData gOamData_BattleSpriteOpponentSide =
Expand Down Expand Up @@ -1788,60 +1775,6 @@ void CB2_QuitRecordedBattle(void)
}
}

#define sState data[0]
#define sDelay data[4]

static void SpriteCB_UnusedBattleInit(struct Sprite *sprite)
{
sprite->sState = 0;
sprite->callback = SpriteCB_UnusedBattleInit_Main;
}

static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite)
{
u16 *arr = (u16 *)gDecompressionBuffer;

switch (sprite->sState)
{
case 0:
sprite->sState++;
sprite->data[1] = 0;
sprite->data[2] = 0x281;
sprite->data[3] = 0;
sprite->sDelay = 1;
// fall through
case 1:
sprite->sDelay--;
if (sprite->sDelay == 0)
{
s32 i;
s32 r2;
s32 r0;

sprite->sDelay = 2;
r2 = sprite->data[1] + sprite->data[3] * 32;
r0 = sprite->data[2] - sprite->data[3] * 32;
for (i = 0; i < 29; i += 2)
{
arr[r2 + i] = 0x3D;
arr[r0 + i] = 0x3D;
}
sprite->data[3]++;
if (sprite->data[3] == 21)
{
sprite->sState++;
sprite->data[1] = 32;
}
}
break;
case 2:
sprite->data[1]--;
if (sprite->data[1] == 20)
SetMainCallback2(CB2_InitBattle);
break;
}
}

static u32 Crc32B (const u8 *data, u32 size)
{
s32 i, j;
Expand Down
4 changes: 2 additions & 2 deletions src/battle_transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -2526,13 +2526,13 @@ static void Mugshots_CreateTrainerPics(struct Task *task)
task->tOpponentSpriteId = CreateTrainerSprite(trainerPicId,
gTrainerSprites[trainerPicId].mugshotCoords.x - 32,
gTrainerSprites[trainerPicId].mugshotCoords.y + 42,
0, gDecompressionBuffer);
0, NULL);
gReservedSpritePaletteCount = 12;

task->tPlayerSpriteId = CreateTrainerSprite(PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender),
DISPLAY_WIDTH + 32,
106,
0, gDecompressionBuffer);
0, NULL);

opponentSprite = &gSprites[task->tOpponentSpriteId];
playerSprite = &gSprites[task->tPlayerSpriteId];
Expand Down
Loading
Loading