Skip to content

Commit

Permalink
somewhat document bg palette effects
Browse files Browse the repository at this point in the history
  • Loading branch information
freshollie committed Jan 29, 2025
1 parent 45f3056 commit a342d22
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 397 deletions.
12 changes: 10 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4 }",
"C_Cpp.files.exclude": {
"build/**": true,
"**/ext/**": true,
"ctx.c": true
},
"files.associations": {
"multi_sio.h": "c",
"global.h": "c",
Expand Down Expand Up @@ -356,11 +361,14 @@
"boss_9.h": "c",
"xlocale": "c",
"xiosbase": "c",
"magnetic_ring.h": "c"
"magnetic_ring.h": "c",
"recordings.h": "c",
"bg_palette_effects.h": "c",
"palettes.h": "c"
},
"asm-code-lens.donated": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "xaver.clang-format",
"clang-format.executable": "clang-format-13",
"git.ignoreLimitWarning": true
"git.ignoreLimitWarning": true,
}
8 changes: 4 additions & 4 deletions include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ extern void *gBgOffsetsHBlank;
extern u16 gUnknown_030017F0;
extern s16 gUnknown_030017F4[2];
extern u8 gUnknown_03001850[32];
extern FuncType_030053A0 gUnknown_03001870[4];
extern FuncType_030053A0 gVBlankCallbacks[4];

extern u8 gOamFreeIndex;
extern u16 gUnknown_03001944;
extern u8 gUnknown_03001948;
extern u8 gNumVBlankIntrs;
extern u16 gUnknown_0300194C;

extern Tilemap **gTilemapsRef;
Expand Down Expand Up @@ -353,15 +353,15 @@ extern u16 gUnknown_03002A8C;
extern u8 gOamFirstPausedIndex;
extern u8 gBackgroundsCopyQueueCursor;
extern Sprite *gUnknown_03004D10[16];
extern u8 gUnknown_03004D50;
extern u8 gNumVBlankCallbacks;
extern void *gUnknown_03004D54;
extern u16 gUnknown_03004D58;
extern u8 gVramGraphicsCopyCursor;
extern u8 gUnknown_03004D60[0x20];
extern u8 gUnknown_03005390;
extern u16 gUnknown_03005394;
extern u16 gUnknown_03005398;
extern FuncType_030053A0 gUnknown_030053A0[4];
extern FuncType_030053A0 gVBlankIntrs[4];
extern s32 gPseudoRandom;
extern u8 gUnknown_03002710[128];
extern struct MultiBootParam gMultiBootParam;
Expand Down
2 changes: 1 addition & 1 deletion include/data/palettes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define GUARD_PALETTES_H
#include "global.h"

extern const u8 gUnknown_08C8796C[];
extern const u16 gBgGradientPalette[];

#endif // GUARD_PALETTES_H
44 changes: 0 additions & 44 deletions include/game/backgrounds.h

This file was deleted.

42 changes: 42 additions & 0 deletions include/game/bg_palette_effects.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef GUARD_BACKGROUNDS_H
#define GUARD_BACKGROUNDS_H

#include "global.h"
#include "sprite.h"

typedef struct {
u8 unk0;
u8 bgPalId;
u8 cursor;

const u8 *pattern;

const u16 *palette;

u8 unkC;
u8 unkD;
u8 unkE;

s8 rShift;
s8 gShift;
s8 bShift;
s8 unk12;

u8 unk13;

u16 palBuffer[16];

s16 offset;
u8 unk36;
} BgPaletteEffectState;

typedef struct {
BgPaletteEffectState *state;
Background *background;
} BackgroundPaletteEffects;

extern BackgroundPaletteEffects gBgPaletteEffects;

void BgPaletteEffectGradient(int_vcount vcount);

#endif // GUARD_BACKGROUNDS_H
10 changes: 5 additions & 5 deletions include/game/sa1_sa2_shared/rings_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#define RESERVED_RING_EFFECT_TILES_VRAM (void *)(OBJ_VRAM0 + 0x2100)

#define PLAYER_TOUCHING_RING(p, rect, ringIntX, ringIntY) \
((((ringIntX - TILE_WIDTH) <= RECT_LEFT(I(p->qWorldX), rect) && (ringIntX + TILE_WIDTH) >= RECT_LEFT(I(p->qWorldX), rect)) \
|| ((ringIntX - TILE_WIDTH) >= RECT_LEFT(I(p->qWorldX), rect) && RECT_RIGHT(I(p->qWorldX), rect) >= (ringIntX - TILE_WIDTH))) \
&& ((((ringIntY - (TILE_WIDTH * 2)) <= RECT_TOP(I(p->qWorldY), rect) && ringIntY >= RECT_TOP(I(p->qWorldY), rect)) \
|| ((ringIntY - (TILE_WIDTH * 2)) >= RECT_TOP(I(p->qWorldY), rect) \
&& RECT_BOTTOM(I(p->qWorldY), rect) >= (ringIntY - (TILE_WIDTH * 2))))))
((((ringIntX - TILE_WIDTH) <= RECT_LEFT(I((p)->qWorldX), rect) && (ringIntX + TILE_WIDTH) >= RECT_LEFT(I((p)->qWorldX), rect)) \
|| ((ringIntX - TILE_WIDTH) >= RECT_LEFT(I((p)->qWorldX), rect) && RECT_RIGHT(I((p)->qWorldX), rect) >= (ringIntX - TILE_WIDTH))) \
&& ((((ringIntY - (TILE_WIDTH * 2)) <= RECT_TOP(I((p)->qWorldY), rect) && ringIntY >= RECT_TOP(I((p)->qWorldY), rect)) \
|| ((ringIntY - (TILE_WIDTH * 2)) >= RECT_TOP(I((p)->qWorldY), rect) \
&& RECT_BOTTOM(I((p)->qWorldY), rect) >= (ringIntY - (TILE_WIDTH * 2))))))

#define MP_PLAYER_TOUCHING_RING(mp, rect, ringIntX, ringIntY) \
((((ringIntX - TILE_WIDTH) <= RECT_LEFT(mp->pos.x, rect) && (ringIntX + TILE_WIDTH) >= RECT_LEFT(mp->pos.x, rect)) \
Expand Down
4 changes: 2 additions & 2 deletions ldscript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SECTIONS
src/game/multiboot/collect_rings/time_display.o(.data);
src/game/math.o(.data);
src/game/multiplayer/mp_attack_1_effect.o(.data);
src/game/backgrounds.o(.data);
src/game/bg_palette_effects.o(.data);

/* libs */
. = ALIGN(16);
Expand Down Expand Up @@ -331,7 +331,7 @@ SECTIONS

src/game/sound_test.o(.text);
src/game/title_screen.o(.text);
src/game/backgrounds.o(.text);
src/game/bg_palette_effects.o(.text);

src/game/cutscenes/level_endings.o(.text);
src/game/cutscenes/endings.o(.text);
Expand Down
56 changes: 28 additions & 28 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ s16 gUnknown_030017F4[2] ALIGNED(4) = {};
Background *gBackgroundsCopyQueue[] ALIGNED(16) = {};
u32 gFlags = 0;
u8 gUnknown_03001850[] ALIGNED(16) = {};
FuncType_030053A0 gUnknown_03001870[] = {};
FuncType_030053A0 gVBlankCallbacks[] = {};
u16 gPhysicalInput = 0;

void *gBgOffsetsHBlank = NULL;
Expand All @@ -43,7 +43,7 @@ u8 gNextFreeAffineIndex = 0;
BgAffineReg gBgAffineRegs[NUM_AFFINE_BACKGROUNDS] ALIGNED(8) = {};
void *gVramHeapStartAddr = NULL;
u16 gUnknown_03001944 ALIGNED(4) = 0;
u8 gUnknown_03001948 ALIGNED(4) = 0;
u8 gNumVBlankIntrs ALIGNED(4) = 0;
u16 gUnknown_0300194C ALIGNED(4) = 0;

u32 gMultiSioStatusFlags = 0;
Expand Down Expand Up @@ -93,13 +93,13 @@ u8 gKeysContinuedRepeatIntervals[10] ALIGNED(16) = {};
union MultiSioData gMultiSioSend ALIGNED(8) = {};
u8 gUnknown_03002874 = 0;

// gComputedBgTarget
// gHBlankCopyTarget
void *gUnknown_03002878 ALIGNED(4) = NULL;

u8 gBackgroundsCopyQueueIndex = 0;
u16 gBgPalette[] ALIGNED(16) = {};

// gComputedBgSectorSize
// gHBlankCopySize
u8 gUnknown_03002A80 ALIGNED(4) = 0;

u8 gVramGraphicsCopyQueueIndex ALIGNED(4) = 0;
Expand All @@ -116,7 +116,7 @@ HBlankFunc gHBlankIntrs[4] ALIGNED(16) = {};
u8 gIwramHeap[0x2204] = {};

Sprite *gUnknown_03004D10[] ALIGNED(16) = {};
u8 gUnknown_03004D50 ALIGNED(4) = 0;
u8 gNumVBlankCallbacks ALIGNED(4) = 0;
void *gUnknown_03004D54 = NULL;
u16 gUnknown_03004D58 ALIGNED(4) = 0;
u8 gVramGraphicsCopyCursor ALIGNED(4) = 0;
Expand All @@ -127,7 +127,7 @@ u16 gVramHeapState[] = {};
u8 gUnknown_03005390 ALIGNED(4) = 0;
u16 gUnknown_03005394 ALIGNED(4) = 0;
u16 gUnknown_03005398 ALIGNED(4) = 0;
FuncType_030053A0 gUnknown_030053A0[] ALIGNED(16) = {};
FuncType_030053A0 gVBlankIntrs[] ALIGNED(16) = {};
const u8 *gInputPlaybackData = NULL;
bool8 gExecSoundMain ALIGNED(4) = FALSE;
s32 gPseudoRandom = 0;
Expand Down Expand Up @@ -319,11 +319,11 @@ void EngineInit(void)
DmaFill32(3, 0, gHBlankCallbacks, sizeof(gHBlankCallbacks));
DmaFill32(3, 0, gHBlankIntrs, sizeof(gHBlankCallbacks));

gUnknown_03004D50 = 0;
gUnknown_03001948 = 0;
gNumVBlankCallbacks = 0;
gNumVBlankIntrs = 0;

DmaFill32(3, 0, gUnknown_03001870, sizeof(gUnknown_03001870));
DmaFill32(3, 0, gUnknown_030053A0, sizeof(gUnknown_030053A0));
DmaFill32(3, 0, gVBlankCallbacks, sizeof(gVBlankCallbacks));
DmaFill32(3, 0, gVBlankIntrs, sizeof(gVBlankIntrs));

m4aSoundInit();
m4aSoundMode(DEFAULT_SOUND_MODE);
Expand Down Expand Up @@ -478,23 +478,23 @@ static void UpdateScreenDma(void)
DmaCopy16(3, gOamBuffer + 0x60, (void *)OAM + 0x300, 0x100);
}

for (i = 0; i < gUnknown_03001948; i++) {
for (i = 0; i < gNumVBlankIntrs; i++) {
#ifdef BUG_FIX
if (gUnknown_030053A0[i] != NULL)
if (gVBlankIntrs[i] != NULL)
#endif
{
gUnknown_030053A0[i]();
gVBlankIntrs[i]();
}
}

if (gFlags & FLAGS_10) {
DmaFill32(3, 0, gUnknown_030053A0, sizeof(gUnknown_030053A0));
if (gUnknown_03004D50 != 0) {
DmaCopy32(3, gUnknown_03001870, gUnknown_030053A0, gUnknown_03004D50 * sizeof(FuncType_030053A0));
DmaFill32(3, 0, gVBlankIntrs, sizeof(gVBlankIntrs));
if (gNumVBlankCallbacks != 0) {
DmaCopy32(3, gVBlankCallbacks, gVBlankIntrs, gNumVBlankCallbacks * sizeof(FuncType_030053A0));
}
gUnknown_03001948 = gUnknown_03004D50;
gNumVBlankIntrs = gNumVBlankCallbacks;
} else {
gUnknown_03001948 = 0;
gNumVBlankIntrs = 0;
}

j = sLastCalledVblankFuncId;
Expand Down Expand Up @@ -556,7 +556,7 @@ static void ClearOamBufferDma(void)
DmaFill16(3, 0x200, gOamBuffer + 0x40, 0x100);
DmaFill16(3, 0x200, gOamBuffer + 0x60, 0x100);

gUnknown_03004D50 = 0;
gNumVBlankCallbacks = 0;
gFlags &= ~FLAGS_10;
}

Expand Down Expand Up @@ -607,18 +607,18 @@ static void UpdateScreenCpuSet(void)
CpuFastCopy(gOamBuffer, (void *)OAM, OAM_SIZE);
}

for (i = 0; i < gUnknown_03001948; i++) {
gUnknown_030053A0[i]();
for (i = 0; i < gNumVBlankIntrs; i++) {
gVBlankIntrs[i]();
}

if (gFlags & 0x10) {
CpuFastFill(NULL, gUnknown_030053A0, sizeof(gUnknown_030053A0));
if (gUnknown_03004D50 != 0) {
CpuFastSet(gUnknown_03001870, gUnknown_030053A0, gUnknown_03004D50);
CpuFastFill(NULL, gVBlankIntrs, sizeof(gVBlankIntrs));
if (gNumVBlankCallbacks != 0) {
CpuFastSet(gVBlankCallbacks, gVBlankIntrs, gNumVBlankCallbacks);
}
gUnknown_03001948 = gUnknown_03004D50;
gNumVBlankIntrs = gNumVBlankCallbacks;
} else {
gUnknown_03001948 = 0;
gNumVBlankIntrs = 0;
}

j = sLastCalledVblankFuncId;
Expand Down Expand Up @@ -866,7 +866,7 @@ static void ClearOamBufferCpuSet(void)
}
gFlags &= ~4;
CpuFastFill(0x200, gOamBuffer, sizeof(gOamBuffer));
gUnknown_03004D50 = 0;
gNumVBlankCallbacks = 0;
gFlags &= ~FLAGS_10;
}
#else
Expand All @@ -886,7 +886,7 @@ static void ClearOamBufferCpuSet(void)
}
gFlags &= ~4;
CpuFastFill(0x200, gOamBuffer, sizeof(gOamBuffer));
gUnknown_03004D50 = 0;
gNumVBlankCallbacks = 0;
gFlags &= ~FLAGS_10;
}
#endif
2 changes: 1 addition & 1 deletion src/data/palettes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#include "data/palettes.h"

// TODO: move to data and include as asm
const u8 gUnknown_08C8796C[] = INCBIN_U8("graphics/8C8796C.gbapal");
const u16 gBgGradientPalette[] = INCBIN_U16("graphics/8C8796C.gbapal");
Loading

0 comments on commit a342d22

Please sign in to comment.