Move Bitmap struct and clear sprite/text files

This commit is contained in:
DizzyEggg 2018-10-18 21:24:37 +02:00
parent b23dc9a123
commit dfee5deca8
8 changed files with 68 additions and 74 deletions

View File

@ -1,6 +1,13 @@
#ifndef GUARD_BLIT_H #ifndef GUARD_BLIT_H
#define GUARD_BLIT_H #define GUARD_BLIT_H
struct Bitmap
{
u8* pixels;
u32 width:16;
u32 height:16;
};
void BlitBitmapRect4BitWithoutColorKey(struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height); void BlitBitmapRect4BitWithoutColorKey(struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height);
void BlitBitmapRect4Bit(struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height, u8 colorKey); void BlitBitmapRect4Bit(struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height, u8 colorKey);
void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue); void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue);

View File

@ -976,13 +976,4 @@ struct UnkStruct_8054FF8
u16 field_C; u16 field_C;
}; };
struct Bitmap // TODO: Find a better spot for this
{
u8* pixels;
u32 width:16;
u32 height:16;
};
extern u8 gReservedSpritePaletteCount;
#endif // GUARD_GLOBAL_H #endif // GUARD_GLOBAL_H

View File

@ -235,11 +235,15 @@ extern const struct OamData gDummyOamData;
extern const union AnimCmd *const gDummySpriteAnimTable[]; extern const union AnimCmd *const gDummySpriteAnimTable[];
extern const union AffineAnimCmd *const gDummySpriteAffineAnimTable[]; extern const union AffineAnimCmd *const gDummySpriteAffineAnimTable[];
extern const struct SpriteTemplate gDummySpriteTemplate; extern const struct SpriteTemplate gDummySpriteTemplate;
extern u8 gReservedSpritePaletteCount;
extern struct Sprite gSprites[];
extern u8 gOamLimit;
extern u16 gReservedSpriteTileCount;
extern s16 gSpriteCoordOffsetX; extern s16 gSpriteCoordOffsetX;
extern s16 gSpriteCoordOffsetY; extern s16 gSpriteCoordOffsetY;
extern struct Sprite gSprites[];
extern struct OamMatrix gOamMatrices[]; extern struct OamMatrix gOamMatrices[];
extern bool8 gAffineAnimsDisabled;
void ResetSpriteData(void); void ResetSpriteData(void);
void AnimateSprites(void); void AnimateSprites(void);

View File

@ -27,6 +27,7 @@
#include "link.h" #include "link.h"
#include "util.h" #include "util.h"
#include "trig.h" #include "trig.h"
#include "data2.h"
struct EvoInfo struct EvoInfo
{ {
@ -48,8 +49,6 @@ extern u16 gBattle_BG2_X;
extern u16 gBattle_BG2_Y; extern u16 gBattle_BG2_Y;
extern u16 gBattle_BG3_X; extern u16 gBattle_BG3_X;
extern u16 gBattle_BG3_Y; extern u16 gBattle_BG3_Y;
extern bool8 gAffineAnimsDisabled;
extern const u8 gSpeciesNames[][11];
#define sEvoCursorPos gBattleCommunication[1] // when learning a new move #define sEvoCursorPos gBattleCommunication[1] // when learning a new move
#define sEvoGraphicsTaskID gBattleCommunication[2] #define sEvoGraphicsTaskID gBattleCommunication[2]
@ -60,12 +59,9 @@ extern const struct CompressedSpriteSheet gMonFrontPicTable[];
// strings // strings
extern const u8 gText_CommunicationStandby5[]; extern const u8 gText_CommunicationStandby5[];
extern void sub_80356D0(void);
extern void sub_807B154(void); extern void sub_807B154(void);
extern void sub_807F19C(void); extern void sub_807F19C(void);
extern void sub_807B140(void); extern void sub_807B140(void);
extern void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies);
extern void Overworld_PlaySpecialMapMusic(void);
extern void ShowSelectMovePokemonSummaryScreen(struct Pokemon *party, u8 monId, u8 partyCount, void *CB2_ptr, u16 move); extern void ShowSelectMovePokemonSummaryScreen(struct Pokemon *party, u8 monId, u8 partyCount, void *CB2_ptr, u16 move);
extern u8 sub_81C1B94(void); extern u8 sub_81C1B94(void);
extern void sub_807F1A8(u8 arg0, const u8 *arg1, u8 arg2); extern void sub_807F1A8(u8 arg0, const u8 *arg1, u8 arg2);

View File

@ -25,8 +25,6 @@
#include "bg.h" #include "bg.h"
#include "window.h" #include "window.h"
extern u8 gOamLimit;
// Text // Text
extern const u8 gText_YouDontHaveThreeCoins[]; extern const u8 gText_YouDontHaveThreeCoins[];
extern const u8 gText_QuitTheGame[]; extern const u8 gText_QuitTheGame[];

View File

@ -15,15 +15,15 @@
#define ALLOC_SPRITE_TILE(n) \ #define ALLOC_SPRITE_TILE(n) \
{ \ { \
gSpriteTileAllocBitmap[(n) / 8] |= (1 << ((n) % 8)); \ sSpriteTileAllocBitmap[(n) / 8] |= (1 << ((n) % 8)); \
} }
#define FREE_SPRITE_TILE(n) \ #define FREE_SPRITE_TILE(n) \
{ \ { \
gSpriteTileAllocBitmap[(n) / 8] &= ~(1 << ((n) % 8)); \ sSpriteTileAllocBitmap[(n) / 8] &= ~(1 << ((n) % 8)); \
} }
#define SPRITE_TILE_IS_ALLOCATED(n) ((gSpriteTileAllocBitmap[(n) / 8] >> ((n) % 8)) & 1) #define SPRITE_TILE_IS_ALLOCATED(n) ((sSpriteTileAllocBitmap[(n) / 8] >> ((n) % 8)) & 1)
struct SpriteCopyRequest struct SpriteCopyRequest
@ -295,18 +295,18 @@ u32 gOamMatrixAllocBitmap;
u8 gReservedSpritePaletteCount; u8 gReservedSpritePaletteCount;
EWRAM_DATA struct Sprite gSprites[MAX_SPRITES + 1] = {0}; EWRAM_DATA struct Sprite gSprites[MAX_SPRITES + 1] = {0};
EWRAM_DATA u16 gSpritePriorities[MAX_SPRITES] = {0}; EWRAM_DATA static u16 sSpritePriorities[MAX_SPRITES] = {0};
EWRAM_DATA u8 gSpriteOrder[MAX_SPRITES] = {0}; EWRAM_DATA static u8 sSpriteOrder[MAX_SPRITES] = {0};
EWRAM_DATA bool8 gShouldProcessSpriteCopyRequests = 0; EWRAM_DATA static bool8 sShouldProcessSpriteCopyRequests = 0;
EWRAM_DATA u8 gSpriteCopyRequestCount = 0; EWRAM_DATA static u8 sSpriteCopyRequestCount = 0;
EWRAM_DATA struct SpriteCopyRequest gSpriteCopyRequests[MAX_SPRITES] = {0}; EWRAM_DATA static struct SpriteCopyRequest sSpriteCopyRequests[MAX_SPRITES] = {0};
EWRAM_DATA u8 gOamLimit = 0; EWRAM_DATA u8 gOamLimit = 0;
EWRAM_DATA u16 gReservedSpriteTileCount = 0; EWRAM_DATA u16 gReservedSpriteTileCount = 0;
EWRAM_DATA u8 gSpriteTileAllocBitmap[128] = {0}; EWRAM_DATA static u8 sSpriteTileAllocBitmap[128] = {0};
EWRAM_DATA s16 gSpriteCoordOffsetX = 0; EWRAM_DATA s16 gSpriteCoordOffsetX = 0;
EWRAM_DATA s16 gSpriteCoordOffsetY = 0; EWRAM_DATA s16 gSpriteCoordOffsetY = 0;
EWRAM_DATA struct OamMatrix gOamMatrices[OAM_MATRIX_COUNT] = {0}; EWRAM_DATA struct OamMatrix gOamMatrices[OAM_MATRIX_COUNT] = {0};
EWRAM_DATA bool8 gAffineAnimsDisabled = 0; EWRAM_DATA bool8 gAffineAnimsDisabled = FALSE;
void ResetSpriteData(void) void ResetSpriteData(void)
{ {
@ -350,7 +350,7 @@ void BuildOamBuffer(void)
AddSpritesToOamBuffer(); AddSpritesToOamBuffer();
CopyMatricesToOamBuffer(); CopyMatricesToOamBuffer();
gMain.oamLoadDisabled = temp; gMain.oamLoadDisabled = temp;
gShouldProcessSpriteCopyRequests = TRUE; sShouldProcessSpriteCopyRequests = TRUE;
} }
void UpdateOamCoords(void) void UpdateOamCoords(void)
@ -382,7 +382,7 @@ void BuildSpritePriorities(void)
{ {
struct Sprite *sprite = &gSprites[i]; struct Sprite *sprite = &gSprites[i];
u16 priority = sprite->subpriority | (sprite->oam.priority << 8); u16 priority = sprite->subpriority | (sprite->oam.priority << 8);
gSpritePriorities[i] = priority; sSpritePriorities[i] = priority;
} }
} }
@ -392,10 +392,10 @@ void SortSprites(void)
for (i = 1; i < MAX_SPRITES; i++) for (i = 1; i < MAX_SPRITES; i++)
{ {
u8 j = i; u8 j = i;
struct Sprite *sprite1 = &gSprites[gSpriteOrder[i - 1]]; struct Sprite *sprite1 = &gSprites[sSpriteOrder[i - 1]];
struct Sprite *sprite2 = &gSprites[gSpriteOrder[i]]; struct Sprite *sprite2 = &gSprites[sSpriteOrder[i]];
u16 sprite1Priority = gSpritePriorities[gSpriteOrder[i - 1]]; u16 sprite1Priority = sSpritePriorities[sSpriteOrder[i - 1]];
u16 sprite2Priority = gSpritePriorities[gSpriteOrder[i]]; u16 sprite2Priority = sSpritePriorities[sSpriteOrder[i]];
s16 sprite1Y = sprite1->oam.y; s16 sprite1Y = sprite1->oam.y;
s16 sprite2Y = sprite2->oam.y; s16 sprite2Y = sprite2->oam.y;
@ -431,20 +431,20 @@ void SortSprites(void)
&& ((sprite1Priority > sprite2Priority) && ((sprite1Priority > sprite2Priority)
|| (sprite1Priority == sprite2Priority && sprite1Y < sprite2Y))) || (sprite1Priority == sprite2Priority && sprite1Y < sprite2Y)))
{ {
u8 temp = gSpriteOrder[j]; u8 temp = sSpriteOrder[j];
gSpriteOrder[j] = gSpriteOrder[j - 1]; sSpriteOrder[j] = sSpriteOrder[j - 1];
gSpriteOrder[j - 1] = temp; sSpriteOrder[j - 1] = temp;
// UB: If j equals 1, then j-- makes j equal 0. // UB: If j equals 1, then j-- makes j equal 0.
// Then, gSpriteOrder[-1] gets accessed below. // Then, sSpriteOrder[-1] gets accessed below.
// Although this doesn't result in a bug in the ROM, // Although this doesn't result in a bug in the ROM,
// the behavior is undefined. // the behavior is undefined.
j--; j--;
sprite1 = &gSprites[gSpriteOrder[j - 1]]; sprite1 = &gSprites[sSpriteOrder[j - 1]];
sprite2 = &gSprites[gSpriteOrder[j]]; sprite2 = &gSprites[sSpriteOrder[j]];
sprite1Priority = gSpritePriorities[gSpriteOrder[j - 1]]; sprite1Priority = sSpritePriorities[sSpriteOrder[j - 1]];
sprite2Priority = gSpritePriorities[gSpriteOrder[j]]; sprite2Priority = sSpritePriorities[sSpriteOrder[j]];
sprite1Y = sprite1->oam.y; sprite1Y = sprite1->oam.y;
sprite2Y = sprite2->oam.y; sprite2Y = sprite2->oam.y;
@ -499,7 +499,7 @@ void AddSpritesToOamBuffer(void)
while (i < MAX_SPRITES) while (i < MAX_SPRITES)
{ {
struct Sprite *sprite = &gSprites[gSpriteOrder[i]]; struct Sprite *sprite = &gSprites[sSpriteOrder[i]];
if (sprite->inUse && !sprite->invisible && AddSpriteToOamBuffer(sprite, &oamIndex)) if (sprite->inUse && !sprite->invisible && AddSpriteToOamBuffer(sprite, &oamIndex))
return; return;
i++; i++;
@ -664,14 +664,14 @@ void ClearSpriteCopyRequests(void)
{ {
u8 i; u8 i;
gShouldProcessSpriteCopyRequests = FALSE; sShouldProcessSpriteCopyRequests = FALSE;
gSpriteCopyRequestCount = 0; sSpriteCopyRequestCount = 0;
for (i = 0; i < MAX_SPRITE_COPY_REQUESTS; i++) for (i = 0; i < MAX_SPRITE_COPY_REQUESTS; i++)
{ {
gSpriteCopyRequests[i].src = 0; sSpriteCopyRequests[i].src = 0;
gSpriteCopyRequests[i].dest = 0; sSpriteCopyRequests[i].dest = 0;
gSpriteCopyRequests[i].size = 0; sSpriteCopyRequests[i].size = 0;
} }
} }
@ -779,17 +779,17 @@ u8 SpriteTileAllocBitmapOp(u16 bit, u8 op)
if (op == 0) if (op == 0)
{ {
val = ~(1 << val); val = ~(1 << val);
gSpriteTileAllocBitmap[index] &= val; sSpriteTileAllocBitmap[index] &= val;
} }
else if (op == 1) else if (op == 1)
{ {
val = (1 << val); val = (1 << val);
gSpriteTileAllocBitmap[index] |= val; sSpriteTileAllocBitmap[index] |= val;
} }
else else
{ {
retVal = 1 << shift; retVal = 1 << shift;
retVal &= gSpriteTileAllocBitmap[index]; retVal &= sSpriteTileAllocBitmap[index];
} }
return retVal; return retVal;
@ -801,40 +801,40 @@ void SpriteCallbackDummy(struct Sprite *sprite)
void ProcessSpriteCopyRequests(void) void ProcessSpriteCopyRequests(void)
{ {
if (gShouldProcessSpriteCopyRequests) if (sShouldProcessSpriteCopyRequests)
{ {
u8 i = 0; u8 i = 0;
while (gSpriteCopyRequestCount > 0) while (sSpriteCopyRequestCount > 0)
{ {
CpuCopy16(gSpriteCopyRequests[i].src, gSpriteCopyRequests[i].dest, gSpriteCopyRequests[i].size); CpuCopy16(sSpriteCopyRequests[i].src, sSpriteCopyRequests[i].dest, sSpriteCopyRequests[i].size);
gSpriteCopyRequestCount--; sSpriteCopyRequestCount--;
i++; i++;
} }
gShouldProcessSpriteCopyRequests = FALSE; sShouldProcessSpriteCopyRequests = FALSE;
} }
} }
void RequestSpriteFrameImageCopy(u16 index, u16 tileNum, const struct SpriteFrameImage *images) void RequestSpriteFrameImageCopy(u16 index, u16 tileNum, const struct SpriteFrameImage *images)
{ {
if (gSpriteCopyRequestCount < MAX_SPRITE_COPY_REQUESTS) if (sSpriteCopyRequestCount < MAX_SPRITE_COPY_REQUESTS)
{ {
gSpriteCopyRequests[gSpriteCopyRequestCount].src = images[index].data; sSpriteCopyRequests[sSpriteCopyRequestCount].src = images[index].data;
gSpriteCopyRequests[gSpriteCopyRequestCount].dest = (u8 *)OBJ_VRAM0 + TILE_SIZE_4BPP * tileNum; sSpriteCopyRequests[sSpriteCopyRequestCount].dest = (u8 *)OBJ_VRAM0 + TILE_SIZE_4BPP * tileNum;
gSpriteCopyRequests[gSpriteCopyRequestCount].size = images[index].size; sSpriteCopyRequests[sSpriteCopyRequestCount].size = images[index].size;
gSpriteCopyRequestCount++; sSpriteCopyRequestCount++;
} }
} }
void RequestSpriteCopy(const u8 *src, u8 *dest, u16 size) void RequestSpriteCopy(const u8 *src, u8 *dest, u16 size)
{ {
if (gSpriteCopyRequestCount < MAX_SPRITE_COPY_REQUESTS) if (sSpriteCopyRequestCount < MAX_SPRITE_COPY_REQUESTS)
{ {
gSpriteCopyRequests[gSpriteCopyRequestCount].src = src; sSpriteCopyRequests[sSpriteCopyRequestCount].src = src;
gSpriteCopyRequests[gSpriteCopyRequestCount].dest = dest; sSpriteCopyRequests[sSpriteCopyRequestCount].dest = dest;
gSpriteCopyRequests[gSpriteCopyRequestCount].size = size; sSpriteCopyRequests[sSpriteCopyRequestCount].size = size;
gSpriteCopyRequestCount++; sSpriteCopyRequestCount++;
} }
} }
@ -869,7 +869,7 @@ void ResetAllSprites(void)
for (i = 0; i < MAX_SPRITES; i++) for (i = 0; i < MAX_SPRITES; i++)
{ {
ResetSprite(&gSprites[i]); ResetSprite(&gSprites[i]);
gSpriteOrder[i] = i; sSpriteOrder[i] = i;
} }
ResetSprite(&gSprites[i]); ResetSprite(&gSprites[i]);
@ -1414,7 +1414,7 @@ void ResetAffineAnimData(void)
{ {
u8 i; u8 i;
gAffineAnimsDisabled = 0; gAffineAnimsDisabled = FALSE;
gOamMatrixAllocBitmap = 0; gOamMatrixAllocBitmap = 0;
ResetOamMatrices(); ResetOamMatrices();

View File

@ -9,11 +9,11 @@
#include "window.h" #include "window.h"
#include "text.h" #include "text.h"
#include "blit.h" #include "blit.h"
#include "dynamic_placeholder_text_util.h"
extern u8 GetKeypadIconWidth(u8 keypadIconId); extern u8 GetKeypadIconWidth(u8 keypadIconId);
extern u16 Font6Func(struct TextPrinter *textPrinter); extern u16 Font6Func(struct TextPrinter *textPrinter);
extern u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese); extern u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese);
extern u8* DynamicPlaceholderTextUtil_GetPlaceholderPtr(u8 a1);
extern int sub_8197964(); extern int sub_8197964();
EWRAM_DATA struct TextPrinter gTempTextPrinter = {0}; EWRAM_DATA struct TextPrinter gTempTextPrinter = {0};
@ -24,8 +24,6 @@ static u16 gLastTextBgColor;
static u16 gLastTextFgColor; static u16 gLastTextFgColor;
static u16 gLastTextShadowColor; static u16 gLastTextShadowColor;
extern struct MusicPlayerInfo gMPlayInfo_BGM;
const struct FontInfo *gFonts; const struct FontInfo *gFonts;
u8 gUnknown_03002F84; u8 gUnknown_03002F84;
u8 gUnknown_03002F90[0x20]; u8 gUnknown_03002F90[0x20];
@ -3170,7 +3168,7 @@ u32 (*GetFontWidthFunc(u8 glyphId))(u16, bool32)
return gGlyphWidthFuncs[i].func; return gGlyphWidthFuncs[i].func;
} }
return 0; return NULL;
} }
u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
@ -3181,7 +3179,7 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
s32 result; s32 result;
int localLetterSpacing; int localLetterSpacing;
u32 lineWidth; u32 lineWidth;
u8 *bufferPointer; const u8 *bufferPointer;
int glyphWidth; int glyphWidth;
u32 width; u32 width;

View File

@ -20,7 +20,7 @@ EWRAM_DATA static u16 sWindowSize = 0;
static u8 GetNumActiveWindowsOnBg(u8 bgId); static u8 GetNumActiveWindowsOnBg(u8 bgId);
static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId); static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId);
static const struct WindowTemplate sDummyWindowTemplate = {0xFF, 0, 0, 0, 0, 0, 0}; static const struct WindowTemplate sDummyWindowTemplate = DUMMY_WIN_TEMPLATE;
static void nullsub_8(void) static void nullsub_8(void)
{ {