Skip to content

Commit

Permalink
Use u32 in gflib functions and remove unused (#4250)
Browse files Browse the repository at this point in the history
  • Loading branch information
DizzyEggg authored Mar 6, 2024
1 parent c91af31 commit 3b45fda
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 265 deletions.
145 changes: 64 additions & 81 deletions gflib/bg.c

Large diffs are not rendered by default.

71 changes: 35 additions & 36 deletions gflib/bg.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,47 @@ struct BgTemplate
};

void ResetBgs(void);
u8 GetBgMode(void);
u32 GetBgMode(void);
void ResetBgControlStructs(void);
void Unused_ResetBgControlStruct(u8 bg);
u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode);
void Unused_ResetBgControlStruct(u32 bg);
u8 LoadBgVram(u32 bg, const void *src, u16 size, u16 destOffset, u32 mode);
void SetTextModeAndHideBgs(void);
bool8 IsInvalidBg(u8 bg);
bool32 IsInvalidBg(u32 bg);
int BgTileAllocOp(int bg, int offset, int count, int mode);
void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable);
void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates);
void InitBgsFromTemplates(u32 bgMode, const struct BgTemplate *templates, u8 numTemplates);
void InitBgFromTemplate(const struct BgTemplate *template);
void SetBgMode(u8 bgMode);
u16 LoadBgTiles(u8 bg, const void *src, u16 size, u16 destOffset);
u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset);
u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset);
bool8 IsDma3ManagerBusyWithBgCopy(void);
void ShowBg(u8 bg);
void HideBg(u8 bg);
void SetBgAttribute(u8 bg, u8 attributeId, u8 value);
u16 GetBgAttribute(u8 bg, u8 attributeId);
s32 ChangeBgX(u8 bg, s32 value, u8 op);
s32 GetBgX(u8 bg);
s32 ChangeBgY(u8 bg, s32 value, u8 op);
s32 ChangeBgY_ScreenOff(u8 bg, s32 value, u8 op);
s32 GetBgY(u8 bg);
void SetBgAffine(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle);
u8 Unused_AdjustBgMosaic(u8 val, u8 mode);
void SetBgTilemapBuffer(u8 bg, void *tilemap);
void UnsetBgTilemapBuffer(u8 bg);
void *GetBgTilemapBuffer(u8 bg);
void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset);
void CopyBgTilemapBufferToVram(u8 bg);
void CopyToBgTilemapBufferRect(u8 bg, const void *src, u8 destX, u8 destY, u8 width, u8 height);
void CopyToBgTilemapBufferRect_ChangePalette(u8 bg, const void *src, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette);
void CopyRectToBgTilemapBufferRect(u8 bg, const void *src, u8 srcX, u8 srcY, u8 srcWidth, u8 srcHeight, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette1, s16 tileOffset, s16 palette2);
void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height);
void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette);
void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, s16 tileNumDelta);
u16 GetBgMetricTextMode(u8 bg, u8 whichMetric);
u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric);
void SetBgMode(u32 bgMode);
u16 LoadBgTiles(u32 bg, const void *src, u16 size, u16 destOffset);
u16 LoadBgTilemap(u32 bg, const void *src, u16 size, u16 destOffset);
u16 Unused_LoadBgPalette(u32 bg, const void *src, u16 size, u16 destOffset);
bool32 IsDma3ManagerBusyWithBgCopy(void);
void ShowBg(u32 bg);
void HideBg(u32 bg);
void SetBgAttribute(u32 bg, u32 attributeId, u8 value);
u16 GetBgAttribute(u32 bg, u32 attributeId);
s32 ChangeBgX(u32 bg, s32 value, u8 op);
s32 GetBgX(u32 bg);
s32 ChangeBgY(u32 bg, s32 value, u8 op);
s32 ChangeBgY_ScreenOff(u32 bg, s32 value, u8 op);
s32 GetBgY(u32 bg);
void SetBgAffine(u32 bg, s32 srcCenterX, s32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle);
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 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);
void CopyRectToBgTilemapBufferRect(u32 bg, const void *src, u8 srcX, u8 srcY, u8 srcWidth, u8 srcHeight, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette1, s16 tileOffset, s16 palette2);
void FillBgTilemapBufferRect_Palette0(u32 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height);
void FillBgTilemapBufferRect(u32 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette);
void WriteSequenceToBgTilemapBuffer(u32 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, s16 tileNumDelta);
u16 GetBgMetricTextMode(u32 bg, u32 whichMetric);
u32 GetBgMetricAffineMode(u32 bg, u32 whichMetric);
u32 GetTileMapIndexFromCoords(s32 x, s32 y, s32 screenSize, u32 screenWidth, u32 screenHeight);
void CopyTileMapEntry(const u16 *src, u16 *dest, s32 palette1, s32 tileOffset, s32 palette2);
bool32 IsInvalidBg32(u8 bg);
bool32 IsTileMapOutsideWram(u8 bg);
bool32 IsTileMapOutsideWram(u32 bg);

#endif // GUARD_BG_H
4 changes: 2 additions & 2 deletions gflib/dma3.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

void ClearDma3Requests(void);
void ProcessDma3Requests(void);
s16 RequestDma3Copy(const void *src, void *dest, u16 size, u8 mode);
s16 RequestDma3Fill(s32 value, void *dest, u16 size, u8 mode);
s16 RequestDma3Copy(const void *src, void *dest, u16 size, u32 mode);
s16 RequestDma3Fill(s32 value, void *dest, u16 size, u32 mode);
s16 CheckForSpaceForDma3Request(s16 index);

#endif // GUARD_DMA3_H
4 changes: 2 additions & 2 deletions gflib/dma3_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void ProcessDma3Requests(void)
}
}

s16 RequestDma3Copy(const void *src, void *dest, u16 size, u8 mode)
s16 RequestDma3Copy(const void *src, void *dest, u16 size, u32 mode)
{
int cursor;
int i = 0;
Expand Down Expand Up @@ -127,7 +127,7 @@ s16 RequestDma3Copy(const void *src, void *dest, u16 size, u8 mode)
return -1; // no free DMA request was found
}

s16 RequestDma3Fill(s32 value, void *dest, u16 size, u8 mode)
s16 RequestDma3Fill(s32 value, void *dest, u16 size, u32 mode)
{
int cursor;
int i = 0;
Expand Down
19 changes: 0 additions & 19 deletions gflib/io_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@
#include "io_reg.h"
#include "gba/io_reg.h"

static const u32 sUnused[] = {
0,
0,
(1 << 26) | (1 << 3),
(1 << 26) | (1 << 3) | (1 << 1),
(1 << 26) | (1 << 3) | (1 << 2),
(1 << 26) | (1 << 3) | (1 << 2) | (1 << 1),
(1 << 26) | (1 << 4),
(1 << 26) | (1 << 4) | (1 << 2),
(1 << 26) | (1 << 4) | (1 << 3),
(1 << 26) | (1 << 4) | (1 << 3) | (1 << 2),
(1 << 26) | (1 << 4) | (1 << 1),
(1 << 26) | (1 << 4) | (1 << 2) | (1 << 1),
(1 << 26) | (1 << 4) | (1 << 3) | (1 << 1),
(1 << 26) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1),
(1 << 25) | (1 << 8),
(1 << 27) | (1 << 10),
};

const u16 gOverworldBackgroundLayerFlags[] = {
BLDCNT_TGT2_BG0,
BLDCNT_TGT2_BG1,
Expand Down
63 changes: 26 additions & 37 deletions gflib/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct OamDimensions
};

static void SortSprites(u32 *spritePriorities, s32 n);
static u8 CreateSpriteAt(u8 index, const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority);
static u32 CreateSpriteAt(u32 index, const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority);
static void ResetOamMatrices(void);
static void ResetSprite(struct Sprite *sprite);
static s16 AllocSpriteTiles(u16 tileCount);
Expand Down Expand Up @@ -121,17 +121,6 @@ const union AnimCmd * const gDummySpriteAnimTable[];
const union AffineAnimCmd * const gDummySpriteAffineAnimTable[];
const struct SpriteTemplate gDummySpriteTemplate;

// Unreferenced data. Also unreferenced in R/S.
static const u8 sUnknownData[24] =
{
0x01, 0x04, 0x10, 0x40,
0x02, 0x04, 0x08, 0x20,
0x02, 0x04, 0x08, 0x20,
0x01, 0x04, 0x10, 0x40,
0x02, 0x04, 0x08, 0x20,
0x02, 0x04, 0x08, 0x20,
};

static const u8 sCenterToCornerVecTable[3][4][2] =
{
{ // square
Expand Down Expand Up @@ -306,7 +295,7 @@ void ResetSpriteData(void)

void AnimateSprites(void)
{
u8 i;
u32 i;
for (i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
Expand Down Expand Up @@ -447,9 +436,9 @@ static void SortSprites(u32 *spritePriorities, s32 n)
InsertionSort(spritePriorities, n);
}

u8 CreateSprite(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority)
u32 CreateSprite(const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority)
{
u8 i;
u32 i;

for (i = 0; i < MAX_SPRITES; i++)
if (!gSprites[i].inUse)
Expand All @@ -458,9 +447,9 @@ u8 CreateSprite(const struct SpriteTemplate *template, s16 x, s16 y, u8 subprior
return MAX_SPRITES;
}

u8 CreateSpriteAtEnd(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority)
u32 CreateSpriteAtEnd(const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority)
{
s16 i;
s32 i;

for (i = MAX_SPRITES - 1; i > -1; i--)
if (!gSprites[i].inUse)
Expand All @@ -469,9 +458,9 @@ u8 CreateSpriteAtEnd(const struct SpriteTemplate *template, s16 x, s16 y, u8 sub
return MAX_SPRITES;
}

u8 CreateInvisibleSprite(void (*callback)(struct Sprite *))
u32 CreateInvisibleSprite(void (*callback)(struct Sprite *))
{
u8 index = CreateSprite(&gDummySpriteTemplate, 0, 0, 31);
u32 index = CreateSprite(&gDummySpriteTemplate, 0, 0, 31);

if (index == MAX_SPRITES)
{
Expand All @@ -485,7 +474,7 @@ u8 CreateInvisibleSprite(void (*callback)(struct Sprite *))
}
}

u8 CreateSpriteAt(u8 index, const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority)
u32 CreateSpriteAt(u32 index, const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority)
{
struct Sprite *sprite = &gSprites[index];

Expand Down Expand Up @@ -536,17 +525,17 @@ u8 CreateSpriteAt(u8 index, const struct SpriteTemplate *template, s16 x, s16 y,
return index;
}

u8 CreateSpriteAndAnimate(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority)
u32 CreateSpriteAndAnimate(const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority)
{
u8 i;
u32 i;

for (i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];

if (!gSprites[i].inUse)
{
u8 index = CreateSpriteAt(i, template, x, y, subpriority);
u32 index = CreateSpriteAt(i, template, x, y, subpriority);

if (index == MAX_SPRITES)
return MAX_SPRITES;
Expand Down Expand Up @@ -578,11 +567,11 @@ void DestroySprite(struct Sprite *sprite)
}
}

void ResetOamRange(u8 start, u8 end)
void ResetOamRange(u32 start, u32 end)
{
u8 i;
u32 i;
for (i = start; i < end; i++)
gMain.oamBuffer[i] = *(struct OamData *)&gDummyOamData;
gMain.oamBuffer[i] = gDummyOamData;
}

void LoadOam(void)
Expand All @@ -593,7 +582,7 @@ void LoadOam(void)

void ClearSpriteCopyRequests(void)
{
u8 i;
u32 i;

sShouldProcessSpriteCopyRequests = FALSE;
sSpriteCopyRequestCount = 0;
Expand All @@ -608,7 +597,7 @@ void ClearSpriteCopyRequests(void)

void ResetOamMatrices(void)
{
u8 i;
u32 i;
for (i = 0; i < OAM_MATRIX_COUNT; i++)
{
// set to identity matrix
Expand Down Expand Up @@ -1365,7 +1354,7 @@ void SetSpriteSheetFrameTileNum(struct Sprite *sprite)

void ResetAffineAnimData(void)
{
u8 i;
u32 i;

gAffineAnimsDisabled = FALSE;
gOamMatrixAllocBitmap = 0;
Expand Down Expand Up @@ -1453,7 +1442,7 @@ u16 LoadSpriteSheet(const struct SpriteSheet *sheet)

void LoadSpriteSheets(const struct SpriteSheet *sheets)
{
u8 i;
u32 i;
for (i = 0; sheets[i].data != NULL; i++)
LoadSpriteSheet(&sheets[i]);
}
Expand Down Expand Up @@ -1482,7 +1471,7 @@ void FreeSpriteTilesByTag(u16 tag)

void FreeSpriteTileRanges(void)
{
u8 i;
u32 i;

for (i = 0; i < MAX_SPRITES; i++)
{
Expand All @@ -1501,7 +1490,7 @@ u16 GetSpriteTileStartByTag(u16 tag)

u8 IndexOfSpriteTileTag(u16 tag)
{
u8 i;
u32 i;

for (i = 0; i < MAX_SPRITES; i++)
if (sSpriteTileRangeTags[i] == tag)
Expand All @@ -1512,7 +1501,7 @@ u8 IndexOfSpriteTileTag(u16 tag)

u16 GetSpriteTileTagByTileStart(u16 start)
{
u8 i;
u32 i;

for (i = 0; i < MAX_SPRITES; i++)
{
Expand All @@ -1532,7 +1521,7 @@ void AllocSpriteTileRange(u16 tag, u16 start, u16 count)

void FreeAllSpritePalettes(void)
{
u8 i;
u32 i;
gReservedSpritePaletteCount = 0;
for (i = 0; i < 16; i++)
sSpritePaletteTags[i] = TAG_NONE;
Expand Down Expand Up @@ -1561,7 +1550,7 @@ u8 LoadSpritePalette(const struct SpritePalette *palette)

void LoadSpritePalettes(const struct SpritePalette *palettes)
{
u8 i;
u32 i;
for (i = 0; palettes[i].data != NULL; i++)
if (LoadSpritePalette(&palettes[i]) == 0xFF)
break;
Expand All @@ -1588,7 +1577,7 @@ u8 AllocSpritePalette(u16 tag)

u8 IndexOfSpritePaletteTag(u16 tag)
{
u8 i;
u32 i;
for (i = gReservedSpritePaletteCount; i < 16; i++)
if (sSpritePaletteTags[i] == tag)
return i;
Expand Down Expand Up @@ -1657,7 +1646,7 @@ bool8 AddSubspritesToOamBuffer(struct Sprite *sprite, struct OamData *destOam, u
u8 subspriteCount;
u8 hFlip;
u8 vFlip;
u8 i;
u32 i;

tileNum = oam->tileNum;
subspriteCount = subspriteTable->subspriteCount;
Expand Down
10 changes: 5 additions & 5 deletions gflib/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ extern bool8 gAffineAnimsDisabled;
void ResetSpriteData(void);
void AnimateSprites(void);
void BuildOamBuffer(void);
u8 CreateSprite(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority);
u8 CreateSpriteAtEnd(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority);
u8 CreateInvisibleSprite(void (*callback)(struct Sprite *));
u8 CreateSpriteAndAnimate(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority);
u32 CreateSprite(const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority);
u32 CreateSpriteAtEnd(const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority);
u32 CreateInvisibleSprite(void (*callback)(struct Sprite *));
u32 CreateSpriteAndAnimate(const struct SpriteTemplate *template, s16 x, s16 y, u32 subpriority);
void DestroySprite(struct Sprite *sprite);
void ResetOamRange(u8 start, u8 end);
void ResetOamRange(u32 start, u32 end);
void LoadOam(void);
void SetOamMatrix(u8 matrixNum, u16 a, u16 b, u16 c, u16 d);
void CalcCenterToCornerVec(struct Sprite *sprite, u8 shape, u8 size, u8 affineMode);
Expand Down
Loading

0 comments on commit 3b45fda

Please sign in to comment.