diff --git a/.vscode/settings.json b/.vscode/settings.json index 32f543851..fd05a0ac3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", @@ -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, } diff --git a/include/core.h b/include/core.h index cdf91f193..332879bd8 100644 --- a/include/core.h +++ b/include/core.h @@ -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; @@ -353,7 +353,7 @@ 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; @@ -361,7 +361,7 @@ 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; diff --git a/include/data/palettes.h b/include/data/palettes.h index 2a3f7e089..0d12f9b54 100644 --- a/include/data/palettes.h +++ b/include/data/palettes.h @@ -2,6 +2,6 @@ #define GUARD_PALETTES_H #include "global.h" -extern const u8 gUnknown_08C8796C[]; +extern const u16 gBgGradientPalette[]; #endif // GUARD_PALETTES_H diff --git a/include/game/backgrounds.h b/include/game/backgrounds.h deleted file mode 100644 index f76216577..000000000 --- a/include/game/backgrounds.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef GUARD_BACKGROUNDS_H -#define GUARD_BACKGROUNDS_H - -#include "global.h" -#include "sprite.h" - -struct UNK_3005B80_UNK4 { - u8 unk0; - u8 unk1; - u8 unk2; - u8 filler3; - - const u8 *unk4; - - const void *unk8; - - u8 unkC; - u8 unkD; - u8 unkE; - - s8 unkF; - s8 unk10; - s8 unk11; - s8 unk12; - - u8 unk13; - - u16 unk14[16]; - - s16 unk34; - u8 unk36; -}; - -struct UNK_3005B80 { - struct UNK_3005B80_UNK4 *unk0; - Background *unk4; -}; - -// Used outside of this module I think, so declared here -extern struct UNK_3005B80 gUnknown_03005B80; - -void sub_808DB2C(int_vcount vcount); - -#endif // GUARD_BACKGROUNDS_H diff --git a/include/game/bg_palette_effects.h b/include/game/bg_palette_effects.h new file mode 100644 index 000000000..8bdd58746 --- /dev/null +++ b/include/game/bg_palette_effects.h @@ -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 diff --git a/include/game/sa1_sa2_shared/rings_manager.h b/include/game/sa1_sa2_shared/rings_manager.h index 23554a317..bd512f474 100644 --- a/include/game/sa1_sa2_shared/rings_manager.h +++ b/include/game/sa1_sa2_shared/rings_manager.h @@ -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)) \ diff --git a/ldscript.txt b/ldscript.txt index 350db8d23..41f67b068 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -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); @@ -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); diff --git a/src/core.c b/src/core.c index 6e6c73bf2..4746e1a2e 100644 --- a/src/core.c +++ b/src/core.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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; @@ -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; } @@ -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; @@ -866,7 +866,7 @@ static void ClearOamBufferCpuSet(void) } gFlags &= ~4; CpuFastFill(0x200, gOamBuffer, sizeof(gOamBuffer)); - gUnknown_03004D50 = 0; + gNumVBlankCallbacks = 0; gFlags &= ~FLAGS_10; } #else @@ -886,7 +886,7 @@ static void ClearOamBufferCpuSet(void) } gFlags &= ~4; CpuFastFill(0x200, gOamBuffer, sizeof(gOamBuffer)); - gUnknown_03004D50 = 0; + gNumVBlankCallbacks = 0; gFlags &= ~FLAGS_10; } #endif diff --git a/src/data/palettes.c b/src/data/palettes.c index 54e15889c..ad69d4ff8 100644 --- a/src/data/palettes.c +++ b/src/data/palettes.c @@ -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"); diff --git a/src/game/backgrounds.c b/src/game/backgrounds.c deleted file mode 100644 index e5febd352..000000000 --- a/src/game/backgrounds.c +++ /dev/null @@ -1,216 +0,0 @@ -#include "global.h" -#include "game/backgrounds.h" - -struct UNK_3005B80_UNK4_UNK8 { - s8 unk0; - u8 unk1; - u16 unk2; - - u16 unk4; - s8 unk6; - - s8 unk7; - s8 unk8; - s8 unk9; - s8 unkA; - - u8 unkB; - - u8 unkC[BG_PLTT_SIZE]; -}; - -struct UNK_808DB78 { - u8 unk0; - u8 unk1; - u16 unk2; - u16 unk4; - u8 unk6; - u8 unk7; - u8 unk8; - - u16 filler9; - - u8 unkC[BG_PLTT_SIZE]; -}; - -struct UNK_3005B80 ALIGNED(16) gUnknown_03005B80 = {}; - -UNUSED void sub_808D8A0(struct UNK_3005B80_UNK4_UNK8 *unk0) -{ - u16 i; - u16 array[BG_PLTT_SIZE / sizeof(u16)]; - u16 *colors = (u16 *)unk0->unkC; - u16 temp5; - s16 temp2; - u16 color; - - for (i = 0; i < (BG_PLTT_SIZE / sizeof(u16)); i++) { - if (i & 1) - color = colors[i]; - else - color = colors[i]; - temp2 = (color & 0x1F) + unk0->unk6 * unk0->unk1; - if (temp2 > 0x1F) { - temp2 = 0x1F; - } - - if (temp2 < 0) { - temp2 = 0; - } - temp5 = temp2; - - temp2 = ((color & 0x3E0) >> 5) + (unk0->unk7 * unk0->unk1); - if (temp2 > 0x1F) { - temp2 = 0x1F; - } - - if (temp2 < 0) { - temp2 = 0; - } - - temp5 |= temp2 << 5; - - temp2 = ((color & 0x7C00) >> 10) + (unk0->unk8 * unk0->unk1); - if (temp2 > 0x1F) { - temp2 = 0x1F; - } - - if (temp2 < 0) { - temp2 = 0; - } - - temp5 |= temp2 << 10; - array[i] = temp5; - } - - CpuFastSet(array, (void *)BG_PLTT, (sizeof(array) / 4)); - unk0->unk4 += unk0->unk2; - unk0->unk1 = unk0->unk4 >> 8; -} - -UNUSED void sub_808D988(u8 vcount) -{ - u8 i; - u16 array[16]; - - struct UNK_3005B80_UNK4 *unk0 = gUnknown_03005B80.unk0; - - if (vcount == unk0->unk13 + unk0->unk34) { - if (unk0->unk0 == 0) { - CpuFastSet((void *)BG_PLTT, unk0->unk14, 1); - unk0->unk0 = 1; - } - if (unk0->unk2 == 0) { - CpuFastSet(unk0->unk14, (void *)BG_PLTT + (unk0->unk1 * 16), 1); - } else { - for (i = 0; i < 16; i++) { - u16 temp5 = 0; - s16 temp2 = (unk0->unk14[i] & 0x1F) + unk0->unkF; - if (temp2 > 0x1F) { - temp2 = 0x1F; - } - temp5 |= temp2; - - temp2 = ((unk0->unk14[i] & 0x3E0) >> 5) + unk0->unk10; - if (temp2 > 0x1F) { - temp2 = 0x1F; - } - temp5 |= temp2 << 5; - - temp2 = ((unk0->unk14[i] & 0x7C00) >> 10) + unk0->unk11; - if (temp2 > 0x1F) { - temp2 = 0x1F; - } - temp5 |= temp2 << 10; - - array[i] = temp5; - } - CpuFastSet(array, (void *)BG_PLTT + unk0->unk1 * 16, 1); - } - - unk0->unkF += unk0->unkC; - unk0->unk10 += unk0->unkD; - unk0->unk11 += unk0->unkE; - unk0->unk13 += unk0->unk12; - - unk0->unk2++; - - if (unk0->unk4[unk0->unk2] == 0xFF) { - unk0->unk2 = 0; - } - } - - if (vcount == 0x9F) { - unk0->unk2 = 0; - unk0->unkF = 0; - unk0->unk10 = 0; - unk0->unk11 = 0; - unk0->unk13 = 0; - } -} - -UNUSED void sub_808DAC8(u8 a, const u8 *b, const void *c, struct UNK_3005B80_UNK4 *d) -{ - d->unk0 = 0; - d->unk2 = 0; - d->unkC = 0; - d->unkD = 0; - d->unkE = 0; - - d->unk34 = 0; - d->unk1 = a; - d->unk4 = b; - d->unk8 = c; - gUnknown_03005B80.unk0 = d; -} - -UNUSED void sub_808DAEC(u8 a, u8 b, u8 c, u8 d, u32 e, struct UNK_3005B80_UNK4 *f) -{ - f->unk0 = 1; - f->unk2 = 0; - f->unkC = b; - f->unkD = c; - f->unkE = d; - - f->unkF = 0; - f->unk10 = 0; - f->unk11 = 0; - f->unk13 = 0; - - f->unk34 = 0; - f->unk1 = a; - f->unk4 = NULL; - f->unk8 = NULL; - - CpuFastSet((void *)BG_PLTT, &f->unk14, 1); - gUnknown_03005B80.unk0 = f; -} - -void sub_808DB2C(int_vcount vcount) -{ - struct UNK_3005B80_UNK4 *unk0 = gUnknown_03005B80.unk0; - - if (vcount >= (DISPLAY_HEIGHT - 1)) { - unk0->unk2 = 0; - return; - } - - if (vcount < (unk0->unk4[unk0->unk2]) + unk0->unk34) { - return; - } - - CpuFastSet(unk0->unk8 + (unk0->unk2 * 32), (void *)BG_PLTT + (unk0->unk1 * 32), 1); - unk0->unk2++; -} - -UNUSED void sub_808DB78(u32 a, u16 b, u8 c, u8 d, u8 e, struct UNK_808DB78 *f) -{ - f->unk0 = 0; - f->unk1 = 0; - f->unk2 = b; - f->unk4 = 0; - f->unk6 = c; - f->unk7 = d; - f->unk8 = e; - CpuFastCopy((void *)BG_PLTT, &f->unkC, BG_PLTT_SIZE); -} diff --git a/src/game/bg_palette_effects.c b/src/game/bg_palette_effects.c new file mode 100644 index 000000000..4c5a0ce18 --- /dev/null +++ b/src/game/bg_palette_effects.c @@ -0,0 +1,201 @@ +#include "global.h" +#include "game/bg_palette_effects.h" + +struct UNK_808DB78 { + u8 unk0; + u8 shiftFactor; + u16 unk2; + u16 unk4; + s8 rShift; + s8 gShift; + s8 bShift; + s8 unk12; + + u8 unk13; + + u16 palBuffer[BG_PLTT_SIZE / sizeof(u16)]; +}; + +BackgroundPaletteEffects gBgPaletteEffects = {}; + +UNUSED void sub_808D8A0(struct UNK_808DB78 *unk0) +{ + u16 i; + u16 *colors = unk0->palBuffer; + u16 palette[ARRAY_COUNT(unk0->palBuffer)]; + + u16 newColor; + s16 component; + u16 color; + + for (i = 0; i < ARRAY_COUNT(palette); i++) { + if (i & 1) + color = colors[i]; + else + color = colors[i]; + component = (color & 31) + unk0->rShift * unk0->shiftFactor; + if (component > 31) { + component = 31; + } + + if (component < 0) { + component = 0; + } + newColor = component; + + component = ((color & 31 << 5) >> 5) + (unk0->gShift * unk0->shiftFactor); + if (component > 0x1F) { + component = 0x1F; + } + + if (component < 0) { + component = 0; + } + + newColor |= component << 5; + + component = ((color & 31 << 10) >> 10) + (unk0->bShift * unk0->shiftFactor); + if (component > 0x1F) { + component = 0x1F; + } + + if (component < 0) { + component = 0; + } + + newColor |= component << 10; + palette[i] = newColor; + } + + CpuFastCopy(palette, (void *)BG_PLTT, sizeof(palette)); + unk0->unk4 += unk0->unk2; + unk0->shiftFactor = unk0->unk4 >> 8; +} + +UNUSED void sub_808D988(int_vcount vcount) +{ + u8 i; + + BgPaletteEffectState *unk0 = gBgPaletteEffects.state; + u16 palette[ARRAY_COUNT(unk0->palBuffer)]; + + if (vcount == unk0->unk13 + unk0->offset) { + if (unk0->unk0 == 0) { + CpuFastCopy((void *)BG_PLTT, unk0->palBuffer, sizeof(u16) * 2); + unk0->unk0 = 1; + } + if (unk0->cursor == 0) { + CpuFastCopy(unk0->palBuffer, (u16 *)BG_PLTT + (unk0->bgPalId * 8), sizeof(u16) * 2); + } else { + for (i = 0; i < ARRAY_COUNT(unk0->palBuffer); i++) { + u16 color = 0; + s16 component = (unk0->palBuffer[i] & 31) + unk0->rShift; + if (component > 31) { + component = 31; + } + color |= component; + + component = ((unk0->palBuffer[i] & (31 << 5)) >> 5) + unk0->gShift; + if (component > 31) { + component = 31; + } + color |= component << 5; + + component = ((unk0->palBuffer[i] & 31 << 10) >> 10) + unk0->bShift; + if (component > 31) { + component = 31; + } + color |= component << 10; + + palette[i] = color; + } + CpuFastCopy(palette, (u16 *)BG_PLTT + unk0->bgPalId * 8, sizeof(u16) * 2); + } + + unk0->rShift += unk0->unkC; + unk0->gShift += unk0->unkD; + unk0->bShift += unk0->unkE; + unk0->unk13 += unk0->unk12; + + unk0->cursor++; + + if (unk0->pattern[unk0->cursor] == 0xFF) { + unk0->cursor = 0; + } + } + + if (vcount == (DISPLAY_HEIGHT - 1)) { + unk0->cursor = 0; + unk0->rShift = 0; + unk0->gShift = 0; + unk0->bShift = 0; + unk0->unk13 = 0; + } +} + +UNUSED void sub_808DAC8(u8 a, const u8 *b, const void *c, BgPaletteEffectState *d) +{ + d->unk0 = 0; + d->cursor = 0; + d->unkC = 0; + d->unkD = 0; + d->unkE = 0; + + d->offset = 0; + d->bgPalId = a; + d->pattern = b; + d->palette = c; + gBgPaletteEffects.state = d; +} + +UNUSED void sub_808DAEC(u8 a, u8 b, u8 c, u8 d, u32 e, BgPaletteEffectState *f) +{ + f->unk0 = 1; + f->cursor = 0; + f->unkC = b; + f->unkD = c; + f->unkE = d; + + f->rShift = 0; + f->gShift = 0; + f->bShift = 0; + f->unk13 = 0; + + f->offset = 0; + f->bgPalId = a; + f->pattern = NULL; + f->palette = NULL; + + CpuFastCopy((u16 *)BG_PLTT, f->palBuffer, sizeof(u16) * 2); + gBgPaletteEffects.state = f; +} + +void BgPaletteEffectGradient(int_vcount vcount) +{ + BgPaletteEffectState *state = gBgPaletteEffects.state; + + if (vcount >= (DISPLAY_HEIGHT - 1)) { + state->cursor = 0; + return; + } + + if (vcount < state->pattern[state->cursor] + state->offset) { + return; + } + + CpuFastCopy(&state->palette[state->cursor * 16], (u16 *)BG_PLTT + (state->bgPalId * 16), sizeof(u16) * 2); + + state->cursor++; +} + +UNUSED void sub_808DB78(u32 a, u16 b, u8 c, u8 d, u8 e, struct UNK_808DB78 *f) +{ + f->unk0 = 0; + f->shiftFactor = 0; + f->unk2 = b; + f->unk4 = 0; + f->rShift = c; + f->gShift = d; + f->bShift = e; + CpuFastCopy((void *)BG_PLTT, &f->palBuffer, BG_PLTT_SIZE); +} diff --git a/src/game/sound_test.c b/src/game/sound_test.c index a0180880d..7864ac6ac 100644 --- a/src/game/sound_test.c +++ b/src/game/sound_test.c @@ -6,7 +6,7 @@ #include "lib/m4a/m4a.h" #include "flags.h" #include "trig.h" -#include "game/backgrounds.h" +#include "game/bg_palette_effects.h" #include "game/stage/screen_fade.h" #include "data/palettes.h" @@ -20,7 +20,7 @@ struct SoundTestScreen { struct OptionsScreen *optionsScreen; ScreenFade fade; - struct UNK_3005B80_UNK4 unk10; + BgPaletteEffectState bgPaletteEffect; // Only 1 used, but fits 2 Background background[2]; @@ -230,8 +230,10 @@ static const u8 sDigitTransitionAnim[8] = { 0, 1, 1, 1, 2, 2, 3, 4, }; -static const u8 gUnknown_080E0C38[12] = { - 0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 0, +static const u8 sBgGradient[] = { + (u8)(0.0 * DISPLAY_HEIGHT), (u8)(0.1 * DISPLAY_HEIGHT), (u8)(0.2 * DISPLAY_HEIGHT), (u8)(0.3 * DISPLAY_HEIGHT), + (u8)(0.4 * DISPLAY_HEIGHT), (u8)(0.5 * DISPLAY_HEIGHT), (u8)(0.6 * DISPLAY_HEIGHT), (u8)(0.7 * DISPLAY_HEIGHT), + (u8)(0.8 * DISPLAY_HEIGHT), (u8)(0.9 * DISPLAY_HEIGHT), (u8)(1.0 * DISPLAY_HEIGHT), }; static const u32 sTitleText[NUM_LANGUAGES * 3] = { @@ -257,11 +259,11 @@ void CreateSoundTestScreen(struct OptionsScreen *optionsScreen) = TaskCreate(Task_SoundTestScreenInOutTransition, sizeof(struct SoundTestScreen), 0x1800, TASK_x0004, SoundTestScreenOnDestroy); struct SoundTestScreen *soundTestScreen = TASK_DATA(t); ScreenFade *fade; - struct UNK_3005B80_UNK4 *unk10; + BgPaletteEffectState *bgPaletteEffect; u32 i; fade = &soundTestScreen->fade; - unk10 = &soundTestScreen->unk10; + bgPaletteEffect = &soundTestScreen->bgPaletteEffect; m4aMPlayAllStop(); soundTestScreen->optionsScreen = optionsScreen; @@ -295,19 +297,19 @@ void CreateSoundTestScreen(struct OptionsScreen *optionsScreen) fade->bldAlpha = 0; fade->bldCnt = (BLDCNT_EFFECT_DARKEN | BLDCNT_TGT1_ALL); - unk10->unk0 = 0; - unk10->unk2 = 0; - unk10->unkC = 1; - unk10->unkD = 1; - unk10->unkE = 1; - unk10->unk1 = 0; + bgPaletteEffect->unk0 = 0; + bgPaletteEffect->cursor = 0; + bgPaletteEffect->unkC = 1; + bgPaletteEffect->unkD = 1; + bgPaletteEffect->unkE = 1; + bgPaletteEffect->bgPalId = 0; - unk10->unk4 = gUnknown_080E0C38; - unk10->unk8 = gUnknown_08C8796C; + bgPaletteEffect->pattern = sBgGradient; + bgPaletteEffect->palette = gBgGradientPalette; - unk10->unk34 = 0; + bgPaletteEffect->offset = 0; - gUnknown_03005B80.unk0 = unk10; + gBgPaletteEffects.state = bgPaletteEffect; } static void SoundTestScreenCreateUI(struct Task *t) @@ -558,7 +560,7 @@ static void SoundTestScreenRenderUI(void) #ifdef BUG_FIX soundTestScreen->hblankIrqIndex = gNumHBlankCallbacks; #endif - gHBlankCallbacks[gNumHBlankCallbacks++] = sub_808DB2C; + gHBlankCallbacks[gNumHBlankCallbacks++] = BgPaletteEffectGradient; gFlags |= FLAGS_EXECUTE_HBLANK_CALLBACKS; for (i = 0; i < 2; i++, numberDisplayDigit++) { diff --git a/src/game/title_screen.c b/src/game/title_screen.c index 92527383b..0cc40932b 100644 --- a/src/game/title_screen.c +++ b/src/game/title_screen.c @@ -1,4 +1,3 @@ -#include "game/title_screen.h" #include "core.h" #include "flags.h" #include "global.h" @@ -9,12 +8,13 @@ #include "sprite.h" #include "lib/m4a/m4a.h" #include "input_recorder.h" -#include "game/backgrounds.h" + +#include "game/title_screen.h" +#include "game/bg_palette_effects.h" #include "game/character_select.h" #include "game/math.h" #include "game/multiplayer/mode_select.h" #include "game/options_screen.h" -#include "data/recordings.h" #include "game/sa1_sa2_shared/demo_manager.h" #include "game/save.h" #include "game/stage/stage.h" @@ -22,6 +22,8 @@ #include "game/time_attack/lobby.h" #include "game/time_attack/mode_select.h" +#include "data/recordings.h" + // Temp hack to allow playing the special stages from the chao garden #if PORTABLE #include "game/sa1_sa2_shared/unused_level_select.h" @@ -57,12 +59,12 @@ typedef struct { // fade s ScreenFade unk270; - struct UNK_3005B80_UNK4 unk27C; + BgPaletteEffectState bgEffect; // Something to do with the wave effects - u16 wavesTranslationX[DISPLAY_HEIGHT]; - u32 unk3F4[DISPLAY_HEIGHT][4]; - u16 wavesTranslationY[DISPLAY_HEIGHT]; + u16 wavesTransformX[DISPLAY_HEIGHT]; + BgAffineReg unk3F4[DISPLAY_HEIGHT]; + u16 wavesTransformY[DISPLAY_HEIGHT]; u16 unkF34; u16 unkF36; @@ -115,7 +117,7 @@ typedef struct { u8 unk207; } LensFlare; /* size 0x208 */ -static void sub_808D874(void); +static void ResetWavesPalette(void); static void InitTitleScreenBackgrounds(TitleScreen *); static void InitTitleScreenUI(TitleScreen *); @@ -243,7 +245,7 @@ static const TileInfo sMenuTiles[] = { { 0x28, SA2_ANIM_SOME_JAPANESE_TXT, SA2_ANIM_VARIANT_SOME_JAPANESE_TXT_7 }, }; -static const u8 sUnknown_080E0EF4[] = INCBIN_U8("graphics/80E0EF4.gbapal"); +static const u16 sWavesBrightnessPalette[] = INCBIN_U16("graphics/80E0EF4.gbapal"); // Each value is scan line which the brightness should be increased // 0 being top 160 being bottom @@ -293,7 +295,7 @@ void CreateTitleScreen(void) struct Task *t; TitleScreen *titleScreen; ScreenFade *fade; - struct UNK_3005B80_UNK4 *config27C; + BgPaletteEffectState *bgEffect; s32 i, val; s16 denom; @@ -317,14 +319,13 @@ void CreateTitleScreen(void) for (i = 0; i < DISPLAY_HEIGHT; i++) { denom = Div(65536, (i + 1) * 8); - // I.E: (512 * demon) - Not sure why it uses this when it's constant val = (titleScreen->unkF34 * denom) >> 8; // Goes from 16384 -> 102 in an log curve \_ - titleScreen->wavesTranslationX[i] = val; + titleScreen->wavesTransformX[i] = val; // Goes from 4 -> 642 in steps of 4 but becomes // a slightly more jagged line as i increases - titleScreen->wavesTranslationY[i] = Div(65536, val); + titleScreen->wavesTransformY[i] = Div(65536, val); }; fade = &titleScreen->unk270; @@ -335,17 +336,17 @@ void CreateTitleScreen(void) fade->bldCnt = (BLDCNT_EFFECT_LIGHTEN | BLDCNT_TGT1_ALL | BLDCNT_TGT2_ALL); fade->bldAlpha = 0; - config27C = &titleScreen->unk27C; - config27C->unk0 = 0; - config27C->unk2 = 0; - config27C->unk34 = titleScreen->wavesTopOffset; - config27C->unk1 = 0xE; - config27C->unk4 = sWavesVerticalBrightnessGradiant; - config27C->unk8 = sUnknown_080E0EF4; - config27C->unk36 = 0; + bgEffect = &titleScreen->bgEffect; + bgEffect->unk0 = 0; + bgEffect->cursor = 0; + bgEffect->offset = titleScreen->wavesTopOffset; + bgEffect->bgPalId = 14; + bgEffect->pattern = sWavesVerticalBrightnessGradiant; + bgEffect->palette = sWavesBrightnessPalette; + bgEffect->unk36 = 0; - gUnknown_03005B80.unk0 = config27C; - gUnknown_03005B80.unk4 = &titleScreen->unk0; + gBgPaletteEffects.state = bgEffect; + gBgPaletteEffects.background = &titleScreen->unk0; InitTitleScreenBackgrounds(titleScreen); m4aSongNumStart(MUS_INTRO); @@ -960,7 +961,7 @@ static void Task_IntroSkyAnim(void) bg0->unk20 = 0; bg0->unk22 = 0; bg0->unk24 = 0; - bg0->targetTilesX = 0x1A; + bg0->targetTilesX = 26; bg0->targetTilesY = 10; bg0->paletteOffset = 0; bg0->flags = BACKGROUND_FLAG_4 | BACKGROUND_FLAGS_BG_ID(2); @@ -1458,12 +1459,12 @@ static void WavesBackgroundAnim(TitleScreen *titleScreen) titleScreen->unkF3A = 7680; } - gUnknown_03001870[gUnknown_03004D50++] = sub_808D874; + gVBlankCallbacks[gNumVBlankCallbacks++] = ResetWavesPalette; gFlags |= FLAGS_10; - titleScreen->unk27C.unk34 = (titleScreen->wavesTopOffset - 2); + titleScreen->bgEffect.offset = (titleScreen->wavesTopOffset - 2); - gHBlankCallbacks[gNumHBlankCallbacks++] = sub_808DB2C; + gHBlankCallbacks[gNumHBlankCallbacks++] = BgPaletteEffectGradient; gFlags |= FLAGS_EXECUTE_HBLANK_CALLBACKS; gFlags |= FLAGS_4; @@ -1471,17 +1472,17 @@ static void WavesBackgroundAnim(TitleScreen *titleScreen) gUnknown_03002878 = (void *)REG_ADDR_BG2PA; // TODO: not sure unk3F4 is the correct type - gBgOffsetsHBlank = &titleScreen->unk3F4[0][0]; - pointer = &titleScreen->unk3F4[0][0]; + gBgOffsetsHBlank = titleScreen->unk3F4; + pointer = (void *)titleScreen->unk3F4; for (i = 0, j = 0; i < DISPLAY_HEIGHT; i++) { s32 temp, r3; if (titleScreen->wavesTopOffset <= i) { - r3 = titleScreen->wavesTranslationX[i - titleScreen->wavesTopOffset]; + r3 = titleScreen->wavesTransformX[i - titleScreen->wavesTopOffset]; *pointer++ = r3; *pointer++ = 0; // * DISPLAY_WIDTH - temp = (titleScreen->wavesTranslationY[i - titleScreen->wavesTopOffset] * 0xF000) >> 8; + temp = (titleScreen->wavesTransformY[i - titleScreen->wavesTopOffset] * 0xF000) >> 8; temp = (0xF000 - (temp)) >> 1; temp = ((temp)*r3) >> 8; @@ -1995,9 +1996,8 @@ UNUSED void sub_808D824(void) TaskDestroy(gCurTask); } -// Might not in game/title_screen -static void sub_808D874(void) +static void ResetWavesPalette(void) { - CpuFastSet(sUnknown_080E0EF4, (void *)(BG_PLTT + 0x1C0), 1); + CpuFastSet(sWavesBrightnessPalette, (u16 *)BG_PLTT + 224, 1); REG_SIOCNT |= SIO_INTR_ENABLE; } diff --git a/src/game/water_effects.c b/src/game/water_effects.c index 9d70b197c..42fa8b34a 100644 --- a/src/game/water_effects.c +++ b/src/game/water_effects.c @@ -208,7 +208,7 @@ static void Task_StageWaterTask(void) water->unk2 = 0xFF; } - gUnknown_03001870[gUnknown_03004D50++] = sub_8011A4C; + gVBlankCallbacks[gNumVBlankCallbacks++] = sub_8011A4C; gFlags |= FLAGS_10; unk1 = water->unk1 - 1; diff --git a/src/sprite.c b/src/sprite.c index 555286db1..f67a0247b 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -13,8 +13,6 @@ extern void Platform_DisplaySprite(Sprite *sprite, u8 oamPaletteNum); #endif -extern const AnimationCommandFunc animCmdTable[]; - #define ReadInstruction(script, cursor) ((void *)(script) + (cursor * sizeof(s32))) static AnimCmdResult animCmd_GetTiles(void *cursor, Sprite *s); @@ -30,44 +28,6 @@ static AnimCmdResult animCmd_10(void *cursor, Sprite *s); static AnimCmdResult animCmd_SetSpritePriority(void *cursor, Sprite *s); static AnimCmdResult animCmd_SetOamOrder(void *cursor, Sprite *s); -static const u8 unkFractions[8] = { - /* 0x00 */ I(Q(0.5 * 2)), - /* 0x01 */ I(Q(0.0 * 2)), - /* 0x02 */ I(Q(1.0 * 2)), - /* 0x03 */ I(Q(1.5 * 2)), - /* 0x04 */ I(Q(3.0 * 2)), - /* 0x05 */ I(Q(3.5 * 2)), - /* 0x06 */ I(Q(2.5 * 2)), - /* 0x07 */ I(Q(2.0 * 2)), -}; - -// TODO: Make static -const AnimationCommandFunc animCmdTable[] = { - // 0x080984AC - animCmd_GetTiles, animCmd_GetPalette, animCmd_JumpBack, animCmd_End, animCmd_PlaySoundEffect, animCmd_AddHitbox, - animCmd_TranslateSprite, animCmd_8, animCmd_SetIdAndVariant, animCmd_10, animCmd_SetSpritePriority, animCmd_SetOamOrder, -}; - -const u8 gOamShapesSizes[12][2] = { - // Square - { 8, 8 }, - { 16, 16 }, - { 32, 32 }, - { 64, 64 }, - - // Horizontal - { 16, 8 }, - { 32, 8 }, - { 32, 16 }, - { 64, 32 }, - - // Vertical - { 8, 16 }, - { 8, 32 }, - { 16, 32 }, - { 32, 64 }, -}; - // This function gets called as long as an enemy is on-screen. // Potentially something to do with collision/distance? // @@ -77,8 +37,16 @@ s16 sub_8004418(s16 x, s16 y) s16 fraction; s32 result; u8 index = 0; - u8 array[8]; - memcpy(array, unkFractions, sizeof(array)); + u8 array[] = { + /* 0x00 */ I(Q(0.5 * 2)), + /* 0x01 */ I(Q(0.0 * 2)), + /* 0x02 */ I(Q(1.0 * 2)), + /* 0x03 */ I(Q(1.5 * 2)), + /* 0x04 */ I(Q(3.0 * 2)), + /* 0x05 */ I(Q(3.5 * 2)), + /* 0x06 */ I(Q(2.5 * 2)), + /* 0x07 */ I(Q(2.0 * 2)), + }; if ((x | y) == 0) { result = -1; @@ -167,6 +135,11 @@ u32 Base10DigitsToHexNibbles(u16 num) AnimCmdResult UpdateSpriteAnimation(Sprite *s) { + static const AnimationCommandFunc animCmdTable[] = { + // 0x080984AC + animCmd_GetTiles, animCmd_GetPalette, animCmd_JumpBack, animCmd_End, animCmd_PlaySoundEffect, animCmd_AddHitbox, + animCmd_TranslateSprite, animCmd_8, animCmd_SetIdAndVariant, animCmd_10, animCmd_SetSpritePriority, animCmd_SetOamOrder, + }; SPRITE_INIT_ANIM_IF_CHANGED(s); if (s->frameFlags & SPRITE_FLAG_MASK_ANIM_OVER) @@ -529,6 +502,27 @@ NONMATCH("asm/non_matching/engine/sub_8004E14.inc", void sub_8004E14(Sprite *spr } END_NONMATCH +// used in background.c +const u8 gOamShapesSizes[12][2] = { + // Square + { 8, 8 }, + { 16, 16 }, + { 32, 32 }, + { 64, 64 }, + + // Horizontal + { 16, 8 }, + { 32, 8 }, + { 32, 16 }, + { 64, 32 }, + + // Vertical + { 8, 16 }, + { 8, 32 }, + { 16, 32 }, + { 32, 64 }, +}; + void DisplaySprite(Sprite *sprite) { OamData *oam;