finish fade.c

This commit is contained in:
theo3
2021-12-18 23:46:04 -08:00
parent d3fa739c94
commit 227703e496
20 changed files with 163 additions and 307 deletions
+1 -1
View File
@@ -143,7 +143,7 @@ void SoundReq(Sound sound) {
}
}
void SoundLoop(void) {
void AudioMain(void) {
s32 fadeValue;
SoundPlayingInfo* ptr = &gSoundPlayingInfo;
+1 -1
View File
@@ -34,7 +34,7 @@ void sub_080A2E40(void) {
MemClear((void*)VRAM, 0x80);
MessageInitialize();
EraseAllEntities();
sub_080ADD30();
ResetPalettes();
sub_0801CFA8(0);
MemClear(&gUnk_02032EC0, sizeof gUnk_02032EC0);
MemClear(&gChooseFileState, sizeof gChooseFileState);
+108 -5
View File
@@ -8,22 +8,26 @@ typedef struct {
u8 field_0x1;
u8 spritesOffset;
} struct_03000000;
extern struct_03000000 gUnk_03000000;
static u32 sub_080501C0(FadeControl* ctl);
static u32 sub_08050230(FadeControl* ctl);
static u32 sub_080502A4(FadeControl* ctl);
extern u32 gUsedPalettes;
extern u16 gPaletteBuffer[];
extern u16 gUnk_080FC3C4[];
// function pointer to overlay (0x03005e98) in ram calls rom function MakeFadeBuff256
extern u32 gMakeFadeBuff256;
typedef void (*fptrMakeFadeBuff256)(u8*, u8*, u16, u8);
void sub_0804FF84(u32 arg0) {
void SetBrightness(u32 arg0) {
gSaveHeader->brightnessPref = arg0;
gUsedPalettes = 0xffffffff;
}
void FadeMain() {
void FadeVBlank(void) {
fptrMakeFadeBuff256 func;
u32 usedPalettesTmp, palIdx;
@@ -40,11 +44,11 @@ void FadeMain() {
palIdx += 0x20;
ptrUnk++;
usedPalettesTmp /= 2;
usedPalettesTmp >>= 1;
}
}
void sub_0804FFE4() {
void InitFade() {
MemClear(&gFadeControl, sizeof(gFadeControl));
MemClear(&gUnk_020354C0, sizeof(gUnk_020354C0));
gFadeControl.mask = 0xffffffff;
@@ -115,3 +119,102 @@ void sub_08050110(u32 param_1, u32 param_2, u32 fadeType, u32 fadeSpeed) {
gFadeControl.field_0x18 = 0;
DoFade(fadeType, fadeSpeed);
}
void FadeMain(void) {
FadeControl* ctl = &gFadeControl;
u32 flags = ctl->fadeType & 0x1C;
u32 active = 0;
u32 bit;
if (ctl->active) {
ctl->fadeDuration -= ctl->fadeSpeed;
if ((s16)ctl->fadeDuration <= (s16)ctl->field_0xe)
ctl->fadeDuration = ctl->field_0xe;
while (flags) {
bit = (~flags + 1) & flags;
flags ^= bit;
switch (bit) {
case 4:
active |= sub_080501C0(ctl);
break;
case 8:
active |= sub_08050230(ctl);
break;
case 16:
active |= sub_080502A4(ctl);
break;
}
}
ctl->active = active;
}
}
static u32 sub_080501C0(FadeControl* ctl) {
u32 v1;
u32 v2;
struct_020354C0* v3;
u32 i;
if (ctl->fadeType & 1) {
v1 = 256 - (s16)ctl->fadeDuration;
} else {
v1 = (s16)ctl->fadeDuration;
}
v2 = gFadeControl.mask;
v3 = gUnk_020354C0;
for (i = 0; i < 0x20; ++i, ++v3) {
if (v2 & 1) {
v3->unk0 = 1;
v3->unk2 = v1;
} else {
v3->unk0 = 0;
v3->unk2 = 0;
}
v3->unk1 = ctl->field_0x2;
v2 >>= 1;
}
gUsedPalettes = 0xffffffff;
return !!((s16)ctl->field_0xe ^ (s16)ctl->fadeDuration);
}
static u32 sub_08050230(FadeControl* ctl) {
u32 type = ctl->fadeType;
u32 idx = ((s16)ctl->fadeDuration >> 4) & 0xF;
if (type & 1)
idx = 0xF - idx;
gScreen.controls.mosaicSize = gUnk_080FC3C4[idx];
if (ctl->fadeDuration != 0)
return 1;
// fade is finished
gUnk_03000000.spritesOffset = 0;
if ((type & 1) == 0) {
// reset registers if fading in
gScreen.bg0.control &= ~BGCNT_MOSAIC;
gScreen.bg1.control &= ~BGCNT_MOSAIC;
gScreen.bg2.control &= ~BGCNT_MOSAIC;
gScreen.bg3.control &= ~BGCNT_MOSAIC;
}
return 0;
}
static u32 sub_080502A4(FadeControl* ctl) {
if (ctl->fadeType & 1) {
s32 delta = (u16)gFadeControl.field_0x10 - gFadeControl.fadeSpeed;
gFadeControl.field_0x10 -= gFadeControl.fadeSpeed;
if (delta << 16 <= 0)
gFadeControl.field_0x10 = 0;
sub_0801E1EC(gFadeControl.field_0x12, gFadeControl.field_0x14, gFadeControl.field_0x10);
if (!gFadeControl.field_0x10)
return 0;
} else {
gFadeControl.field_0x10 += gFadeControl.fadeSpeed;
sub_0801E1EC(gFadeControl.field_0x12, gFadeControl.field_0x14, gFadeControl.field_0x10);
if (gFadeControl.field_0x10 > 150) {
sub_0801E104();
return 0;
}
}
return 1;
}
+1 -1
View File
@@ -197,7 +197,7 @@ static void HandleFileScreenEnter(void) {
MessageInitialize();
EraseAllEntities();
sub_08080668();
sub_080ADD30();
ResetPalettes();
sub_0801CFA8(0);
MemClear(&gUnk_0200AF00, sizeof(gUnk_0200AF00));
MemClear(&gUnk_02019EE0, sizeof(gUnk_02019EE0));
+3 -3
View File
@@ -29,7 +29,7 @@ extern void sub_080ADD70();
extern void sub_0801C25C();
extern void UpdateDisplayControls();
extern void LoadResources();
extern void FadeMain();
extern void FadeVBlank();
extern void HandlePlayerLife();
extern void DoPlayerAction();
extern void sub_080171F0();
@@ -156,7 +156,7 @@ void LoadResources(void) {
}
}
void PrepNextFrame(void) {
void WaitForNextFrame(void) {
gMain.interruptFlag = 0;
VBlankIntrWait();
do {
@@ -176,7 +176,7 @@ void PrepNextFrame(void) {
if (gUnk_0200B650 != NULL)
DmaCopy32(3, &gBG2Buffer, VRAM + (*gUnk_0200B650 & 0x1f00) * 8, 0x5C0);
}
FadeMain();
FadeVBlank();
}
void PlayerUpdate(Entity* this) {
+1 -1
View File
@@ -145,7 +145,7 @@ static void HandleTitlescreen(void) {
gIntroState.gameLanguage = 7;
EraseAllEntities();
sub_0801CFA8(0);
sub_080ADD30();
ResetPalettes();
gGFXSlots.unk0 = 1;
LoadGfxGroup(2);
if (gSaveHeader->gameLanguage == 0) {
+21 -22
View File
@@ -38,8 +38,6 @@ void (*const sScreenHandlers[])(void) = {
static void sub_080560B8(void);
void AgbMain(void) {
int var0;
InitOverlays();
InitSound();
InitDMA();
@@ -47,11 +45,11 @@ void AgbMain(void) {
sub_080560B8();
sub_08056208();
gUnk_02000010.field_0x4 = 193;
sub_0804FFE4();
InitFade();
DmaCopy32(3, BG_PLTT, gPaletteBuffer, BG_PLTT_SIZE);
sub_0804FF84(1);
SetBrightness(1);
MessageInitialize();
sub_080ADD30();
ResetPalettes();
gRand = 0x1234567;
MemClear(&gMain, sizeof(gMain));
InitScreen(SCREEN_INTRO);
@@ -61,22 +59,23 @@ void AgbMain(void) {
DoSoftReset();
}
switch (gMain.field_0x1) {
case 1:
sub_08056260();
switch (gMain.sleepStatus) {
case SLEEP:
SetSleepMode();
break;
case 0:
case DEFAULT:
default:
if (gMain.countdown != 0) {
if (gMain.pauseFrames != 0) {
do {
VBlankIntrWait();
} while (--gMain.countdown);
} while (--gMain.pauseFrames);
}
if (gMain.field_0x9 != 0) {
gMain.field_0x9--;
var0 = gMain.field_0xa;
while (var0-- > 0) {
if (gMain.pauseCount != 0) {
int cnt;
gMain.pauseCount--;
cnt = gMain.pauseInterval;
while (cnt-- > 0) {
VBlankIntrWait();
}
}
@@ -84,11 +83,11 @@ void AgbMain(void) {
gMain.ticks++;
sScreenHandlers[gMain.screen]();
MessageMain();
UpdateFade();
SoundLoop();
FadeMain();
AudioMain();
break;
}
PrepNextFrame();
WaitForNextFrame();
}
}
@@ -200,7 +199,7 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) {
}
temp = gUnk_02000010.signature ^ SIGNATURE;
b = !!temp;
b = BOOLCAST(temp);
if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) {
b = TRUE;
@@ -257,7 +256,7 @@ void sub_08056250() {
gScreen._6c = 0;
}
void sub_08056260(void) {
void SetSleepMode(void) {
u32 restore;
Main* m;
@@ -272,8 +271,8 @@ void sub_08056260(void) {
REG_IE = restore;
REG_IME = 1;
m = &gMain;
*(vu8*)&m->field_0x1; // force a read
m->field_0x1 = 0;
*(vu8*)&m->sleepStatus; // force a read
m->sleepStatus = 0;
}
// Convert AABB to screen coordinates and check if it's within the viewport
+2 -2
View File
@@ -513,7 +513,7 @@ void sub_0805289C(void) {
u32 sub_080528B4(void) {
if (gScreenTransition.field_0x4[1]) {
sub_0804FFE4();
InitFade();
gMain.funcIndex = 3;
gMain.transition = 0;
DoFade(5, 8);
@@ -564,7 +564,7 @@ u32 HandleRoomExit(void) {
}
RoomExitCallback();
gMain.transition = 3;
*(&gMain.field_0xa + 1) = 1;
*(&gMain.pauseInterval + 1) = 1;
return 1;
}
return 0;
+1
View File
@@ -2,6 +2,7 @@
#include "gba/eeprom.h"
#include "audio.h"
#include "menu.h"
#include "main.h"
#include "functions.h"
typedef struct SaveFileStatus {