Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ extern u8 gIwramHeap[TASK_HEAP_SIZE];

extern void *gVramHeapStartAddr;
extern u16 gVramHeapMaxTileSlots;
extern u16 gVramHeapState[256];
extern u16 gVramHeapState[OBJ_VRAM_TOTAL_SIZE / VRAM_HEAP_SEGMENT_SIZE];

extern bool8 gExecSoundMain;

Expand All @@ -264,11 +264,18 @@ extern u16 gDispCnt;
#define WINREG_WININ 4
#define WINREG_WINOUT 5

#define PALETTE_LEN_4BPP 16u
#define GET_PALETTE_COLOR_OBJ(_paletteId, _colorId) gObjPalette[(_paletteId)*PALETTE_LEN_4BPP + (_colorId)]
#define GET_PALETTE_COLOR_BG(_paletteId, _colorId) gBgPalette[(_paletteId)*PALETTE_LEN_4BPP + (_colorId)]
#define SET_PALETTE_COLOR_OBJ(_paletteId, _colorId, _color) GET_PALETTE_COLOR_OBJ(_paletteId, _colorId) = (_color);
#define SET_PALETTE_COLOR_BG(_paletteId, _colorId, _color) GET_PALETTE_COLOR_BG(_paletteId, _colorId) = (_color);

extern winreg_t gWinRegs[6];
extern struct BlendRegs gBldRegs;
extern BgAffineReg gBgAffineRegs[NUM_AFFINE_BACKGROUNDS];
extern u16 gObjPalette[OBJ_PLTT_SIZE / sizeof(u16)];
extern u16 gBgPalette[BG_PLTT_SIZE / sizeof(u16)];
extern u16 gObjPalette[16 * PALETTE_LEN_4BPP];
extern u16 gBgPalette[16 * PALETTE_LEN_4BPP];

extern u16 gBgCntRegs[4];

// TODO: Turn this into a struct-array?
Expand Down
3 changes: 3 additions & 0 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ extern uint8_t OAM[OAM_SIZE];
#define OBJ_VRAM0 &VRAM[0x10000]
#define OBJ_VRAM1 &VRAM[0x14000]

#define OBJ_VRAM_TOTAL_SIZE (VRAM_SIZE - BG_VRAM_SIZE)
#else
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 160
Expand Down Expand Up @@ -118,8 +119,10 @@ extern uint8_t OAM[OAM_SIZE];
#define OAM 0x7000000
#define OAM_SIZE (OAM_ENTRY_COUNT*sizeof(OamData))

#define OBJ_VRAM_TOTAL_SIZE (VRAM_SIZE - BG_VRAM_SIZE)
#endif


#if WIDESCREEN_HACK
#define WIN_REG_SIZE 4
#define WIN_RANGE(a, b) (((a) << 16) | (b))
Expand Down
2 changes: 2 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
#if !PLATFORM_GBA
#ifdef _WIN32
void *Platform_malloc(size_t numBytes);
void *Platform_realloc(void *ptr, size_t numBytes);
void Platform_free(void *ptr);
#define malloc(numBytes) Platform_malloc(numBytes)
#define calloc(count, size) Platform_malloc(count *size)
#define realloc(ptr, size) Platform_realloc(ptr, size)
#define free(numBytes) Platform_free(numBytes)
#endif
#endif
Expand Down
5 changes: 3 additions & 2 deletions include/malloc_vram.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include "global.h"

#define VRAM_HEAP_SEGMENT_SIZE 0x80
#define VRAM_TILE_SLOTS_PER_SEGMENT (VRAM_HEAP_SEGMENT_SIZE / TILE_SIZE_4BPP)
#define VRAM_HEAP_TILE_SIZE TILE_SIZE_4BPP
#define VRAM_HEAP_SEGMENT_SIZE (4 * VRAM_HEAP_TILE_SIZE)
#define VRAM_TILE_SLOTS_PER_SEGMENT (VRAM_HEAP_SEGMENT_SIZE / VRAM_HEAP_TILE_SIZE)

// TODO: Find out where these numbers come from
#if (ENGINE == ENGINE_1)
Expand Down
3 changes: 3 additions & 0 deletions include/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ extern void Platform_LZDecompressUnsafe(unsigned char *src, unsigned char *dest)
extern void Platform_RLDecompressUnsafe(unsigned char *src, unsigned char *dest);

extern void Platform_QueueAudio(const void *data, u32 numBytes);
extern void Platform_ProcessBackgroundsCopyQueue(void);
// TODO: Re-enable once #include-ing global.h/core.h/sprite.h does not result in compilation errors.
// void Platform_TransformSprite(Sprite *s, SpriteTransform *transform);

#endif // GUARD_SA2_PLATFORM_H
2 changes: 2 additions & 0 deletions include/platform/shared/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "sprite.h" // for Sprite

void OpenGL_OnInit();
void OpenGL_ProcessBackgroundsCopyQueue();
void OpenGL_DisplaySprite(Sprite *sprite, u8 oamPaletteNum);
void OpenGL_TransformSprite(Sprite *sprite, SpriteTransform *transform);
void OpenGL_Render(void *tempBufferPixels, int windowWidth, int windowHeight);

#endif // GUARD_PLATFORM_SHARED_OPENGL_H
2 changes: 1 addition & 1 deletion include/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ typedef struct {
/* 0x36 */ u16 prevScrollY;

/* Only used by stage maps (they are encoded as Tilemaps) */
/* 0x38 */ const u16 *metatileMap;
/* 0x38 */ const MetatileIndexType *metatileMap;
/* 0x3C */ u16 mapWidth;
/* 0x3E */ u16 mapHeight;
} Background; /* size = 0x40 */
Expand Down
12 changes: 10 additions & 2 deletions src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sprite.h"
#include "trig.h"
#include "lib/m4a/m4a.h"
#include "platform/platform.h"

#include "animation_commands.h"

Expand Down Expand Up @@ -54,7 +55,7 @@ void DrawBackground(Background *background)
background->paletteOffset = mapHeader->tileset.palOffset;

if (!(background->flags & BACKGROUND_DISABLE_PALETTE_UPDATE)) {
DmaCopy16(3, pal, gBgPalette + background->paletteOffset, palSize * sizeof(*pal));
DmaCopy16(3, pal, &GET_PALETTE_COLOR_BG(0, background->paletteOffset), palSize * sizeof(*pal));
gFlags |= FLAGS_UPDATE_BACKGROUND_PALETTES;
background->flags ^= BACKGROUND_DISABLE_PALETTE_UPDATE;
}
Expand All @@ -72,6 +73,7 @@ void DrawBackground(Background *background)

// (85.37%) https://decomp.me/scratch/617Jb
// (87.46%) https://decomp.me/scratch/1CFim
// TODO: ProcessBackgroundsCopyQueue might be a good name for this function?
NONMATCH("asm/non_matching/engine/sub_8002B20.inc", bool32 sub_8002B20(void))
{
u16 sp00;
Expand All @@ -90,6 +92,7 @@ NONMATCH("asm/non_matching/engine/sub_8002B20.inc", bool32 sub_8002B20(void))

#if (RENDERER == RENDERER_OPENGL)
// TEMP
Platform_ProcessBackgroundsCopyQueue();
return TRUE;
#endif

Expand Down Expand Up @@ -1289,7 +1292,12 @@ static AnimCmdResult animCmd_GetPalette_BG(void *cursor, Sprite *s)
if (!(s->frameFlags & SPRITE_FLAG_MASK_18)) {
s32 paletteIndex = cmd->palId;

DmaCopy32(3, &gRefSpriteTables->palettes[paletteIndex * 16], &gBgPalette[s->palId * 16 + cmd->insertOffset], cmd->numColors * 2);
// NOTE:
// For some reason, this only matches with a size of:
// (cmd->numColors * 2), not (cmd->numColors * sizeof(u16))
// Same goes for sprite.c version called animCmd_GetPalette()...
DmaCopy32(3, &gRefSpriteTables->palettes[paletteIndex * 16], &GET_PALETTE_COLOR_BG(s->palId, cmd->insertOffset),
cmd->numColors * 2);

gFlags |= FLAGS_UPDATE_BACKGROUND_PALETTES;
}
Expand Down
8 changes: 4 additions & 4 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,12 @@ void UpdateScreenDma(void)
DmaCopy32(3, gBgCntRegs, (void *)REG_ADDR_BG0CNT, sizeof(gBgCntRegs));

if (gFlags & FLAGS_UPDATE_BACKGROUND_PALETTES) {
DmaCopy32(3, gBgPalette, (void *)BG_PLTT, BG_PLTT_SIZE);
DmaCopy32(3, gBgPalette, (void *)BG_PLTT, sizeof(gBgPalette));
gFlags ^= FLAGS_UPDATE_BACKGROUND_PALETTES;
}

if (gFlags & FLAGS_UPDATE_SPRITE_PALETTES) {
DmaCopy32(3, gObjPalette, (void *)OBJ_PLTT, OBJ_PLTT_SIZE);
DmaCopy32(3, gObjPalette, (void *)OBJ_PLTT, sizeof(gObjPalette));
gFlags ^= FLAGS_UPDATE_SPRITE_PALETTES;
}

Expand Down Expand Up @@ -761,12 +761,12 @@ void UpdateScreenCpuSet(void)
CpuCopy32(gBgCntRegs, (void *)REG_ADDR_BG0CNT, sizeof(gBgCntRegs));

if (gFlags & FLAGS_UPDATE_BACKGROUND_PALETTES) {
CpuFastCopy(gBgPalette, (void *)BG_PLTT, BG_PLTT_SIZE);
CpuFastCopy(gBgPalette, (void *)BG_PLTT, sizeof(gBgPalette));
gFlags ^= FLAGS_UPDATE_BACKGROUND_PALETTES;
}

if (gFlags & FLAGS_UPDATE_SPRITE_PALETTES) {
CpuFastCopy(gObjPalette, (void *)OBJ_PLTT, OBJ_PLTT_SIZE);
CpuFastCopy(gObjPalette, (void *)OBJ_PLTT, sizeof(gObjPalette));
gFlags ^= FLAGS_UPDATE_SPRITE_PALETTES;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/boost_effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static inline void sub_8015B64_inline(AnimId anim, u16 palId)
#endif
numColors = *pAnim % 256u;

DmaCopy32(3, &gRefSpriteTables->palettes[animPalId * 16], &gObjPalette[insertOffset], numColors * sizeof(u16));
DmaCopy32(3, &gRefSpriteTables->palettes[animPalId * 16], &GET_PALETTE_COLOR_OBJ(0, insertOffset), numColors * sizeof(u16));

gFlags |= FLAGS_UPDATE_SPRITE_PALETTES;
}
Expand Down
6 changes: 3 additions & 3 deletions src/game/bosses/boss_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static const HammertankFunc sBossStateHandlers[] = {
[EGG_HAMMER_TANK_II_STATE_DRAG] = StateHandler_HammerDrag, [EGG_HAMMER_TANK_II_STATE_RETRACT] = StateHandler_HammerRetract,
};

static const u16 gUnknown_080D7AD0[][16] = {
static const u16 gUnknown_080D7AD0[][PALETTE_LEN_4BPP] = {
INCBIN_U16("graphics/80D7AD0.gbapal"),
INCBIN_U16("graphics/80D7AF0.gbapal"),
};
Expand Down Expand Up @@ -1613,8 +1613,8 @@ static void HandleBossHitPalette(EggHammerTankII *boss)
if (boss->timerInvulnerability > 0) {
u8 i;

for (i = 0; i < 16; i++) {
gObjPalette[8 * 16 + i] = gUnknown_080D7AD0[(boss->timerInvulnerability & 4) >> 2][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7AD0[(boss->timerInvulnerability & 4) >> 2][i]);
}

gFlags |= FLAGS_UPDATE_SPRITE_PALETTES;
Expand Down
18 changes: 9 additions & 9 deletions src/game/bosses/boss_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static const u16 gUnknown_080D7B4E[][2] = {

static const BossFunction sBossModeTasks[] = { HandleCannonBombTrigger, HandleCannonlessBombTrigger };

static const u16 gUnknown_080D7B70[][16] = {
static const u16 gUnknown_080D7B70[][PALETTE_LEN_4BPP] = {
INCBIN_U16("graphics/80D7B70.gbapal"),
INCBIN_U16("graphics/80D7B90.gbapal"),
};
Expand Down Expand Up @@ -575,23 +575,23 @@ static void UpdateBomberTankPalette(EggBomberTank *boss)
{
u8 i;
if (boss->bossHitTimer != 0) {
for (i = 0; i < 16; i++) {
gObjPalette[i + 0x80] = gUnknown_080D7B70[(gStageTime & 2) >> 1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7B70[(gStageTime & 2) >> 1][i]);
}
} else {
for (i = 0; i < 16; i++) {
gObjPalette[i + 0x80] = gUnknown_080D7B70[1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7B70[1][i]);
}
}

if (boss->cannonHitTimer != 0) {
boss->cannonHitTimer--;
for (i = 0; i < 16; i++) {
gObjPalette[i + 0xD0] = gUnknown_080D7B70[(gStageTime & 2) >> 1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(13, i, gUnknown_080D7B70[(gStageTime & 2) >> 1][i]);
}
} else {
for (i = 0; i < 16; i++) {
gObjPalette[i + 0xD0] = gUnknown_080D7B70[1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(13, i, gUnknown_080D7B70[1][i]);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/game/bosses/boss_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const u8 *const gUnknown_080D7ED4[] = {

const s8 gUnknown_080D7F10[EGGTOTEM_NUM_PLATFORMS] = { 14, 14, 8 };

const s16 gUnknown_080D7F14[2][16] = {
const s16 gUnknown_080D7F14[2][PALETTE_LEN_4BPP] = {
INCBIN_U16("graphics/boss_3_a.gbapal"),
INCBIN_U16("graphics/boss_3_b.gbapal"),
};
Expand Down Expand Up @@ -1504,24 +1504,24 @@ void sub_8040F14(EggTotem *totem)
u8 i;

if (totem->unk35 != 0) {
for (i = 0; i < 16; i++) {
gObjPalette[128 + i] = gUnknown_080D7F14[((gStageTime & 0x2) / 2u)][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7F14[((gStageTime & 0x2) / 2u)][i]);
}
} else {
for (i = 0; i < 16; i++) {
gObjPalette[128 + i] = gUnknown_080D7F14[1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7F14[1][i]);
}
}

if (totem->unk36 > 0) {
totem->unk36--;

for (i = 0; i < 16; i++) {
gObjPalette[176 + i] = gUnknown_080D7F14[((gStageTime & 0x2) / 2u)][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(11, i, gUnknown_080D7F14[((gStageTime & 0x2) / 2u)][i]);
}
} else {
for (i = 0; i < 16; i++) {
gObjPalette[176 + i] = gUnknown_080D7F14[1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(11, i, gUnknown_080D7F14[1][i]);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/game/bosses/boss_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#define RESERVED_EXPLOSION_TILES_VRAM (void *)(OBJ_VRAM0 + 0x2980)

static const u16 sPalAeroEggHit[2][16] = {
static const u16 sPalAeroEggHit[2][PALETTE_LEN_4BPP] = {
[PAL_BOSS_4_DEFAULT] = INCBIN_U16("graphics/boss_4_a.gbapal"),
[PAL_BOSS_4_HIT] = INCBIN_U16("graphics/boss_4_b.gbapal"),
};
Expand Down Expand Up @@ -761,12 +761,12 @@ static void sub_8042560(AeroEgg *boss)
u8 i;

if (boss->main.unk16 != 0) {
for (i = 0; i < ARRAY_COUNT(sPalAeroEggHit[PAL_BOSS_4_DEFAULT]); i++) {
gObjPalette[128 + i] = sPalAeroEggHit[((gStageTime & 0x2) >> 1)][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, sPalAeroEggHit[((gStageTime & 0x2) >> 1)][i]);
}
} else {
for (i = 0; i < ARRAY_COUNT(sPalAeroEggHit[PAL_BOSS_4_HIT]); i++) {
gObjPalette[128 + i] = sPalAeroEggHit[PAL_BOSS_4_HIT][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, sPalAeroEggHit[PAL_BOSS_4_HIT][i]);
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/game/bosses/boss_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static const TileInfo gUnknown_080D7FB0[] = {
{ 2, SA2_ANIM_EGG_SAUCER_SMACK_PARTICLE_UP, 0 }, { 4, SA2_ANIM_EGG_SAUCER_SMACK_PARTICLE_UP_RIGHT, 0 },
};

static const u16 gUnknown_080D7FF0[][16] = {
static const u16 gUnknown_080D7FF0[][PALETTE_LEN_4BPP] = {
INCBIN_U16("graphics/80D7FF0.gbapal"),
INCBIN_U16("graphics/80D8010.gbapal"),
};
Expand Down Expand Up @@ -1293,6 +1293,7 @@ static void sub_8044CBC(EggSaucer *boss)
s->prevVariant = -1;
}
}

boss->unk36[0][boss->unkB6] = boss->unkB8;
boss->unk36[1][boss->unkB6] = boss->unkBA;

Expand Down Expand Up @@ -1756,27 +1757,27 @@ void sub_8045898(EggSaucer *boss)
if (boss->unk15 == 0) {
val = (gStageTime & 2) >> 1;
if (boss->unk13 != 0) {
for (i = 0; i < 0x10; i++) {
gObjPalette[i + 0x80] = gUnknown_080D7FF0[val][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7FF0[val][i]);
}
} else {
for (i = 0; i < 0x10; i++) {
gObjPalette[i + 0x80] = gUnknown_080D7FF0[1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(8, i, gUnknown_080D7FF0[1][i]);
}
}

if (boss->unk1F != 0) {
boss->unk1F--;
for (i = 0; i < 0x10; i++) {
gObjPalette[i + 0x90] = gUnknown_080D7FF0[val][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(9, i, gUnknown_080D7FF0[val][i]);
}
} else {
for (i = 0; i < 0x10; i++) {
gObjPalette[i + 0x90] = gUnknown_080D7FF0[1][i];
for (i = 0; i < PALETTE_LEN_4BPP; i++) {
SET_PALETTE_COLOR_OBJ(9, i, gUnknown_080D7FF0[1][i]);
}
}

gFlags |= 2;
gFlags |= FLAGS_UPDATE_SPRITE_PALETTES;
}
}

Expand Down
Loading
Loading