From 45d31f3b910fee99c8662cf57a7670f2652d8de3 Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Wed, 10 Jul 2024 14:58:13 +0800 Subject: [PATCH] review sysutils/code_80AE86C --- include/ap.h | 2 +- include/functions.h | 10 -- include/sysutil.h | 25 ++- include/variables.h | 2 +- ldscript.txt | 6 +- src/ap.c | 2 +- src/bonusclaim_helpbox.c | 161 +++++++++++++++++ src/code_80AE86C.c | 330 ---------------------------------- src/ending_details.c | 8 +- src/eventcall.c | 1 + src/sprite-animfx.c | 1 + src/sysutil-bmbgfx.c | 249 -------------------------- src/sysutil.c | 370 +++++++++++++++++++++++++++++++++++++++ 13 files changed, 566 insertions(+), 601 deletions(-) create mode 100644 src/bonusclaim_helpbox.c delete mode 100644 src/code_80AE86C.c delete mode 100644 src/sysutil-bmbgfx.c diff --git a/include/ap.h b/include/ap.h index fbc43704..d6eba456 100644 --- a/include/ap.h +++ b/include/ap.h @@ -38,7 +38,7 @@ void AP_LoadDefinition(struct APHandle *, const u16 *); void AP_ExecDummyFrame(struct APHandle *); void AP_Init(struct APHandle *, const u16 *, u16); struct APHandle * AP_Find(const u16 * definition); -ProcPtr APProc_Create(const void * apDefinition, int xPos, int yPos, int tileBase, int anim, u16 aObjNode); +ProcPtr APProc_Create(const void * apDefinition, int xPos, int yPos, int tileBase, int anim, int aObjNode); // ??? APProc_OnUpdate(???); // ??? APProc_OnEnd(???); void APProc_SetParameters(struct APProc * proc, int x, int y, int tileBase); diff --git a/include/functions.h b/include/functions.h index 55b64d9e..e2145a28 100644 --- a/include/functions.h +++ b/include/functions.h @@ -472,16 +472,6 @@ void SetUiSpinningArrowPositions(int, int, int, int); void SetUiSpinningArrowFastMaybe(int); void EndUiSpinningArrows(void); -// ??? sub_80AE86C(???); -// ??? sub_80AE930(???); -// ??? sub_80AE938(???); -// ??? sub_80AE964(???); -// ??? sub_80AE99C(???); -ProcPtr StartSpriteAnimfx(const u8 * gfx, const u16 * pal, const void * apDef, int x, int y, int animId, int palId, int palCount, u16 chr, int aObjNode); -int GetBgXOffset(int); -// ??? GetBgYOffset(???); -char* AppendTextBuffer_80AEABC(const char*, char*); -char* AppendCharAndTerminate(int, char*); // ??? sub_80AEAE8(???); // ??? sub_80AEB1C(???); // ??? sub_80AEB28(???); diff --git a/include/sysutil.h b/include/sysutil.h index f245112e..96bf7cf6 100644 --- a/include/sysutil.h +++ b/include/sysutil.h @@ -247,6 +247,8 @@ struct ProcBmBgfx { /* 58 */ s8 (* callback)(ProcPtr); }; +extern struct ProcCmd ProcScr_BmBgfx[]; + void BmBgfx_Init(struct ProcBmBgfx * proc); void BmBgfx_Loop(struct ProcBmBgfx * proc); void BmBgfx_End(struct ProcBmBgfx * proc); @@ -256,4 +258,25 @@ void EndBmBgfx(void); void BmBgfxSetLoopEN(u8); void StartBmBgfx(struct BmBgxConf * input, int bg, int x, int y, int e, int f, int g, void * func, ProcPtr parent); -extern struct ProcCmd ProcScr_BmBgfx[]; +struct ProcMixPalette +{ + /* 00 */ PROC_HEADER; + /* 2C */ int speed; + /* 30 */ int targetPalId; + /* 34 */ int palCount; + /* 38 */ int timer; + /* 3C */ u16 * srcA; + /* 40 */ u16 * srcB; +}; + +void MixPaletteCore(struct ProcMixPalette * proc, int val); +void MixPalette_Init(struct ProcMixPalette * proc); +void MixPalette_Loop(struct ProcMixPalette * proc); +void StartMixPalette(u16 * palA, u16 * palB, int speed, int targetPalId, int palCount, ProcPtr parent); +void EndMixPalette(void); + +ProcPtr StartSpriteAnimfx(const u8 * gfx, const u16 * pal, const void * apDef, int x, int y, int animId, int palId, int palCount, u16 chr, int aObjNode); +int GetBgXOffset(int bg); +int GetBgYOffset(int bg); +char * AppendString(const char * src, char * dst); +char * AppendCharacter(int character, char * str); diff --git a/include/variables.h b/include/variables.h index 419487da..7c38df0e 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1070,7 +1070,7 @@ extern struct ProcCmd CONST_DATA gProcScr_DrawDifficultyMenuSprites[]; // extern ??? gSprite_UiSpinningArrows_Vertical // extern ??? gProcScr_UiSpinningArrows -// extern ??? gProcScr_08A20E24 +// extern ??? ProcScr_MixPalette // extern ??? gProcScr_BonusClaimHelpBox // extern ??? gSoundRoomTable // extern ??? gUnknown_08A212D4 diff --git a/ldscript.txt b/ldscript.txt index f71910fb..2e721030 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -550,8 +550,7 @@ SECTIONS src/cursor_hand.o(.text); src/spinning_arrow.o(.text); src/sysutil.o(.text); - src/sysutil-bmbgfx.o(.text); - src/code_80AE86C.o(.text); + src/bonusclaim_helpbox.o(.text); src/soundroom.o(.text); src/extramenu_unk.o(.text); src/bonusclaim.o(.text); @@ -1161,8 +1160,7 @@ SECTIONS . = ALIGN(4); src/cursor_hand.o(.data); . = ALIGN(4); src/spinning_arrow.o(.data); . = ALIGN(4); src/sysutil.o(.data); - . = ALIGN(4); src/sysutil-bmbgfx.o(.data); - . = ALIGN(4); src/code_80AE86C.o(.data); + . = ALIGN(4); src/bonusclaim_helpbox.o(.data); . = ALIGN(4); src/soundroom_data.o(.data); . = ALIGN(4); src/soundroom.o(.data); . = ALIGN(4); src/extramenu_unk.o(.data); diff --git a/src/ap.c b/src/ap.c index 71ca1d52..9c676f94 100644 --- a/src/ap.c +++ b/src/ap.c @@ -337,7 +337,7 @@ struct APHandle* AP_Find(const u16* definition) { return NULL; } -ProcPtr APProc_Create(const void* apDefinition, int xPos, int yPos, int tileBase, int anim, u16 aObjNode) { +ProcPtr APProc_Create(const void* apDefinition, int xPos, int yPos, int tileBase, int anim, int aObjNode) { struct APHandle* handle; struct APProc* proc; diff --git a/src/bonusclaim_helpbox.c b/src/bonusclaim_helpbox.c new file mode 100644 index 00000000..e1ffe535 --- /dev/null +++ b/src/bonusclaim_helpbox.c @@ -0,0 +1,161 @@ +#include "global.h" + +#include "hardware.h" +#include "bmlib.h" +#include "ctc.h" +#include "fontgrp.h" +#include "soundwrapper.h" +#include "statscreen.h" +#include "bmsave.h" +#include "ap.h" +#include "sysutil.h" + +struct BonusClaimHelpBoxProc +{ + /* 00 */ PROC_HEADER; + /* 2C */ int x; + /* 30 */ int y; + /* 34 */ STRUCT_PAD(0x34, 0x58); + + /* 58 */ int msgId; +}; + +//! FE8U = 0x080AEAE8 +const char * sub_80AEAE8(char ** src, char ** dst) +{ + const char * result; + int len; + + result = GetCharTextLen(*src, &len); + result -= (uintptr_t)*src; + + memcpy(*dst, *src, (uintptr_t)result); + + *src = *src + (uintptr_t)result; + *dst = *dst + (uintptr_t)result; + + return result; +} + +//! FE8U = 0x080AEB1C +void sub_80AEB1C(void) +{ + SetPrimaryHBlankHandler(NULL); + return; +} + +//! FE8U = 0x080AEB28 +void sub_80AEB28(int unk) +{ + CallSomeSoundMaybe(0, 0x100, 0, unk, NULL); + return; +} + +//! FE8U = 0x080AEB44 +void sub_80AEB44(int songId) +{ + CallSomeSoundMaybe(songId, 0x100, 0x100, 0x20, NULL); + return; +} + +//! FE8U = 0x080AEB60 +void BonusClaimHelp_Init(struct BonusClaimHelpBoxProc * proc) +{ + PlaySoundEffect(0x70); + StartHelpBox_Unk(proc->x, proc->y, proc->msgId); + return; +} + +//! FE8U = 0x080AEB8C +void BonusClaimHelp_Loop(struct BonusClaimHelpBoxProc * proc) +{ + if (gKeyStatusPtr->newKeys & (A_BUTTON | B_BUTTON | START_BUTTON | L_BUTTON | R_BUTTON)) + { + Proc_Break(proc); + PlaySoundEffect(0x71); + CloseHelpBox(); + } + + return; +} + +// clang-format off + +struct ProcCmd CONST_DATA gProcScr_BonusClaimHelpBox[] = +{ + PROC_YIELD, + + PROC_CALL(BonusClaimHelp_Init), + PROC_SLEEP(8), + + PROC_REPEAT(BonusClaimHelp_Loop), + PROC_SLEEP(8), + + PROC_END, +}; + +// clang-format on + +//! FE8U = 0x080AEBCC +void StartBonusClaimHelpBox(int x, int y, int msgId, ProcPtr parent) +{ + struct BonusClaimHelpBoxProc * proc = Proc_StartBlocking(gProcScr_BonusClaimHelpBox, parent); + proc->x = x; + proc->y = y; + proc->msgId = msgId; + + return; +} + +//! FE8U = 0x080AEBEC +int CountDigits(int number) +{ + int remainingDigits = number; + int digitCount = 0; + + do + { + digitCount++; + remainingDigits = (remainingDigits / 10); + } while (remainingDigits != 0); + + return digitCount; +} + +//! FE8U = 0x080AEC04 +bool sub_80AEC04(int a, int b, int c, int d, int e, int f, int g, int h) +{ + + if (((c - a) * (f - b) - (d - b) * (e - a)) < 0) + { + return FALSE; + } + + if (((e - a) * (h - b) - (f - b) * (g - a)) < 0) + { + return FALSE; + } + + if (((g - a) * (d - b) - (h - b) * (c - a)) < 0) + { + return FALSE; + } + + return TRUE; +} + +//! FE8U = 0x080AEC54 +bool sub_80AEC54(void) +{ + struct GlobalSaveInfo saveInfo; + ReadGlobalSaveInfo(&saveInfo); + return FALSE; +} + +//! FE8U = 0x080AEC68 +bool sub_80AEC68(void) +{ + struct GlobalSaveInfo saveInfo; + ReadGlobalSaveInfo(&saveInfo); + return FALSE; +} diff --git a/src/code_80AE86C.c b/src/code_80AE86C.c deleted file mode 100644 index 0ee5bd88..00000000 --- a/src/code_80AE86C.c +++ /dev/null @@ -1,330 +0,0 @@ -#include "global.h" - -#include "hardware.h" -#include "bmlib.h" -#include "ctc.h" -#include "fontgrp.h" -#include "soundwrapper.h" -#include "statscreen.h" -#include "bmsave.h" - -struct Proc08A20E24 -{ - /* 00 */ PROC_HEADER; - /* 2C */ int unk_2c; - /* 30 */ int targetPalId; - /* 34 */ int palCount; - /* 38 */ int unk_38; - /* 3C */ u16 * srcA; - /* 40 */ u16 * srcB; -}; - -struct BonusClaimHelpBoxProc -{ - /* 00 */ PROC_HEADER; - /* 2C */ int x; - /* 30 */ int y; - /* 34 */ STRUCT_PAD(0x34, 0x58); - - /* 58 */ int msgId; -}; - -// TODO: Implicit declaration -ProcPtr APProc_Create(const void * apDefinition, int xPos, int yPos, int tileBase, int anim, int aObjNode); - -//! FE8U = 0x080AE86C -void sub_80AE86C(struct Proc08A20E24 * proc, int val) -{ - int i; - int j; - - u16 * dst = gPaletteBuffer + PAL_COLOR_OFFSET(proc->targetPalId, 0); - u16 * ptrA = proc->srcA; - u16 * ptrB = proc->srcB; - - for (i = 0; i < proc->palCount; i++) - { - for (j = 0; j < 0x10; j++) - { - *dst = ((((*ptrA & RED_MASK) * (0x80 - val) + val * (*ptrB & RED_MASK)) >> 7) & RED_MASK) + - ((((*ptrA & GREEN_MASK) * (0x80 - val) + val * (*ptrB & GREEN_MASK)) >> 7) & GREEN_MASK) + - ((((*ptrA & BLUE_MASK) * (0x80 - val) + val * (*ptrB & BLUE_MASK)) >> 7) & BLUE_MASK); - - dst++; - - ptrA++; - ptrB++; - } - } - - EnablePaletteSync(); - - return; -} - -//! FE8U = 0x080AE930 -void sub_80AE930(struct Proc08A20E24 * proc) -{ - proc->unk_38 = 0; - return; -} - -//! FE8U = 0x080AE938 -void sub_80AE938(struct Proc08A20E24 * proc) -{ - proc->unk_38 += proc->unk_2c; - - if (proc->unk_38 > 0x100) - { - proc->unk_38 = 0; - } - - sub_80AE86C(proc, proc->unk_38 < 0x80 ? proc->unk_38 : 0x100 - proc->unk_38); - - return; -} - -// clang-format off - -struct ProcCmd CONST_DATA gProcScr_08A20E24[] = -{ - PROC_YIELD, - PROC_CALL(sub_80AE930), - PROC_REPEAT(sub_80AE938), - - PROC_END, -}; - -// clang-format on - -//! FE8U = 0x080AE964 -void sub_80AE964(u16 * palA, u16 * palB, int c, int targetPalId, int palCount, ProcPtr parent) -{ - struct Proc08A20E24 * proc = Proc_Start(gProcScr_08A20E24, parent); - - proc->unk_2c = c; - proc->targetPalId = targetPalId; - proc->palCount = palCount; - - proc->srcA = palA; - proc->srcB = palB; - - return; -} - -//! FE8U = 0x080AE99C -void sub_80AE99C(void) -{ - Proc_End(Proc_Find(gProcScr_08A20E24)); - return; -} - -//! FE8U = 0x080AE9B0 -ProcPtr StartSpriteAnimfx(const u8 * gfx, const u16 * pal, const void * apDef, int x, int y, int animId, int palId, int palCount, u16 chr, int aObjNode) -{ - if (gfx != NULL) - { - Decompress(gfx, (void *)(0x06010000 + OAM2_CHR(chr) * CHR_SIZE)); - } - - if (pal != NULL) - { - ApplyPalettes(pal, (palId + 0x10), palCount); - } - - return APProc_Create(apDef, x, y, OAM2_PAL(palId) + chr, animId, aObjNode); -} - -//! FE8U = 0x080AEA24 -int GetBgXOffset(int bg) -{ - switch (bg) - { - case BG_0: - return gLCDControlBuffer.bgoffset[BG_0].x; - - case BG_1: - return gLCDControlBuffer.bgoffset[BG_1].x; - - case BG_2: - return gLCDControlBuffer.bgoffset[BG_2].x; - - case BG_3: - return gLCDControlBuffer.bgoffset[BG_3].x; - } -} - -//! FE8U = 0x080AEA70 -int GetBgYOffset(int bg) -{ - switch (bg) - { - case BG_0: - return gLCDControlBuffer.bgoffset[BG_0].y; - - case BG_1: - return gLCDControlBuffer.bgoffset[BG_1].y; - - case BG_2: - return gLCDControlBuffer.bgoffset[BG_2].y; - - case BG_3: - return gLCDControlBuffer.bgoffset[BG_3].y; - } -} - -//! FE8U = 0x080AEABC -char * AppendTextBuffer_80AEABC(const char * srcStr, char * dstStr) -{ - strcpy(dstStr, srcStr); - return dstStr + strlen(srcStr); -} - -//! FE8U = 0x080AEADC -char * AppendCharAndTerminate(int character, char * str) -{ - *str = character; - str++; - *str = 0; - return str; -} - -//! FE8U = 0x080AEAE8 -const char * sub_80AEAE8(char ** src, char ** dst) -{ - const char * result; - int len; - - result = GetCharTextLen(*src, &len); - result -= (uintptr_t)*src; - - memcpy(*dst, *src, (uintptr_t)result); - - *src = *src + (uintptr_t)result; - *dst = *dst + (uintptr_t)result; - - return result; -} - -//! FE8U = 0x080AEB1C -void sub_80AEB1C(void) -{ - SetPrimaryHBlankHandler(NULL); - return; -} - -//! FE8U = 0x080AEB28 -void sub_80AEB28(int unk) -{ - CallSomeSoundMaybe(0, 0x100, 0, unk, NULL); - return; -} - -//! FE8U = 0x080AEB44 -void sub_80AEB44(int songId) -{ - CallSomeSoundMaybe(songId, 0x100, 0x100, 0x20, NULL); - return; -} - -//! FE8U = 0x080AEB60 -void BonusClaimHelp_Init(struct BonusClaimHelpBoxProc * proc) -{ - PlaySoundEffect(0x70); - StartHelpBox_Unk(proc->x, proc->y, proc->msgId); - return; -} - -//! FE8U = 0x080AEB8C -void BonusClaimHelp_Loop(struct BonusClaimHelpBoxProc * proc) -{ - if (gKeyStatusPtr->newKeys & (A_BUTTON | B_BUTTON | START_BUTTON | L_BUTTON | R_BUTTON)) - { - Proc_Break(proc); - PlaySoundEffect(0x71); - CloseHelpBox(); - } - - return; -} - -// clang-format off - -struct ProcCmd CONST_DATA gProcScr_BonusClaimHelpBox[] = -{ - PROC_YIELD, - - PROC_CALL(BonusClaimHelp_Init), - PROC_SLEEP(8), - - PROC_REPEAT(BonusClaimHelp_Loop), - PROC_SLEEP(8), - - PROC_END, -}; - -// clang-format on - -//! FE8U = 0x080AEBCC -void StartBonusClaimHelpBox(int x, int y, int msgId, ProcPtr parent) -{ - struct BonusClaimHelpBoxProc * proc = Proc_StartBlocking(gProcScr_BonusClaimHelpBox, parent); - proc->x = x; - proc->y = y; - proc->msgId = msgId; - - return; -} - -//! FE8U = 0x080AEBEC -int CountDigits(int number) -{ - int remainingDigits = number; - int digitCount = 0; - - do - { - digitCount++; - remainingDigits = (remainingDigits / 10); - } while (remainingDigits != 0); - - return digitCount; -} - -//! FE8U = 0x080AEC04 -bool sub_80AEC04(int a, int b, int c, int d, int e, int f, int g, int h) -{ - - if (((c - a) * (f - b) - (d - b) * (e - a)) < 0) - { - return FALSE; - } - - if (((e - a) * (h - b) - (f - b) * (g - a)) < 0) - { - return FALSE; - } - - if (((g - a) * (d - b) - (h - b) * (c - a)) < 0) - { - return FALSE; - } - - return TRUE; -} - -//! FE8U = 0x080AEC54 -bool sub_80AEC54(void) -{ - struct GlobalSaveInfo saveInfo; - ReadGlobalSaveInfo(&saveInfo); - return FALSE; -} - -//! FE8U = 0x080AEC68 -bool sub_80AEC68(void) -{ - struct GlobalSaveInfo saveInfo; - ReadGlobalSaveInfo(&saveInfo); - return FALSE; -} diff --git a/src/ending_details.c b/src/ending_details.c index 45646ac0..041757dc 100644 --- a/src/ending_details.c +++ b/src/ending_details.c @@ -336,8 +336,8 @@ char* PrepareUnitDefeatLocationString(u16 textIdA, u16 defeatedChapter, u16 text u8 count = 0; - str = AppendTextBuffer_80AEABC(GetStringFromIndex(textIdA), str); - str = AppendCharAndTerminate(1, str); + str = AppendString(GetStringFromIndex(textIdA), str); + str = AppendCharacter(1, str); if (defeatedChapter & 0x8000) { defeatedChapter &= 0x7FFF; @@ -362,9 +362,9 @@ char* PrepareUnitDefeatLocationString(u16 textIdA, u16 defeatedChapter, u16 text locationStr = GetStringFromIndex(GetROMChapterStruct(defeatedChapter)->chapTitleTextId); } - str = AppendTextBuffer_80AEABC(locationStr, str); + str = AppendString(locationStr, str); - str = AppendTextBuffer_80AEABC(GetStringFromIndex(textIdB) + count, str); + str = AppendString(GetStringFromIndex(textIdB) + count, str); return str; } diff --git a/src/eventcall.c b/src/eventcall.c index df0642f3..bb3e16d5 100644 --- a/src/eventcall.c +++ b/src/eventcall.c @@ -38,6 +38,7 @@ #include "mapanim.h" #include "muctrl.h" #include "scene.h" +#include "sysutil.h" #include "eventcall.h" diff --git a/src/sprite-animfx.c b/src/sprite-animfx.c index dc830a1c..b0c46cda 100644 --- a/src/sprite-animfx.c +++ b/src/sprite-animfx.c @@ -2,6 +2,7 @@ #include "proc.h" #include "ap.h" #include "ctc.h" +#include "sysutil.h" #include "sprite-animfx.h" struct ProcCmd CONST_DATA ProcScr_EventSpriteAnim[] = diff --git a/src/sysutil-bmbgfx.c b/src/sysutil-bmbgfx.c deleted file mode 100644 index a1f7341e..00000000 --- a/src/sysutil-bmbgfx.c +++ /dev/null @@ -1,249 +0,0 @@ -#include "global.h" - -#include "hardware.h" -#include "bmlib.h" - -#include "sysutil.h" - -//! FE8U = 0x080AE4D8 -void BmBgfx_Init(struct ProcBmBgfx * proc) -{ - proc->conf = 0; - proc->bg = 0; - proc->vram_base = 0; - proc->vram_free_space = 0; - proc->vram_base_offset = 0; - proc->size_per_fx = 0; - proc->flip = 0; - proc->timer = 0; - proc->total_duration = 0; - proc->counter_procloop = 0; - proc->callback = 0; - proc->func_call_type = 0; - proc->counter_functioncall = 0; - proc->x = 0; - proc->y = 0; - proc->loop_en = 1; - proc->counter = 0; -} - -//! FE8U = 0x080AE518 -void BmBgfx_Loop(struct ProcBmBgfx * proc) -{ - struct BmBgxConf * conf = proc->conf; - - if (proc->callback != NULL) - { - proc->func_call_type = 0; - if (proc->callback(proc) != 0) - return; - } - else - { - proc->callback = NULL; - } - - while (1) - { - if (conf->type == BMFX_CONFT_LOOP_START) - conf++; - - /* Loop identifier */ - if (conf->type == BMFX_CONFT_LOOP) - { - if (proc->loop_en != false) - { - if (proc->counter == 0) - proc->counter = conf->duration; - else if (proc->counter > 0) - proc->counter = proc->counter - 1; - - if (proc->counter != 0) - { - int i; - struct BmBgxConf * conf_ = conf - 1; - for (i = conf_->type; i != BMFX_CONFT_LOOP_START; i = conf_->type) - { - conf = conf_; - conf_--; - } - } - else - { - conf++; - } - } - else - { - proc->counter = 0; - conf++; - } - } - - if (conf->type == BMFX_CONFT_CALL_IDLE) - { - if (proc->callback != NULL) - { - proc->counter_functioncall++; - proc->func_call_type = 1; - proc->callback(proc); - } - conf++; - } - - if (conf->type == BMFX_CONFT_BLOCKING) - break; - - if (conf->type < 11 && conf->type > 8) - { - Proc_Break(proc); - break; - } - - if (proc->timer == 0) - { - switch (conf->type) - { - case BMFX_CONFT_IMG: - case BMFX_CONFT_ZIMG: - if (proc->vram_free_space == 0) - proc->flip = 1 - proc->flip; - break; - } - - switch (conf->type) - { - case BMFX_CONFT_IMG: - CpuFastCopy( - conf->data, - (void *)(0x6000000 + proc->vram_base + proc->vram_base_offset + proc->vram_free_space + proc->flip * proc->size_per_fx), - conf->size); - - proc->vram_free_space = proc->vram_free_space + conf->size; - break; - - case BMFX_CONFT_ZIMG: - Decompress( - conf->data, - (void *)(0x6000000 + proc->vram_base + proc->vram_base_offset + proc->vram_free_space + proc->flip * proc->size_per_fx)); - - proc->vram_free_space = proc->vram_free_space + conf->size; - - break; - - case BMFX_CONFT_TSA: - if (proc->size_per_fx == 0x8000) - SetBackgroundTileDataOffset(proc->bg, (proc->vram_base + (proc->flip << 0xf)) & 0xFFFF); - - CallARM_FillTileRect( - BG_GetMapBuffer(proc->bg), conf->data, - (u16)((proc->pal_bank << 0xc) + - (((proc->vram_base_offset + proc->flip * proc->size_per_fx) << 0x11) >> 0x16))); - - proc->vram_free_space = 0; - BG_EnableSyncByMask(1 << proc->bg); - - break; - - case BMFX_CONFT_PAL: - ApplyPalettes(conf->data, proc->pal_bank, conf->size); - break; - } - } - - proc->timer++; - if (proc->timer <= conf->duration) - break; - - conf++; - proc->timer = 0; - } - - proc->conf = conf; - proc->counter_procloop++; -} - -//! FE8U = 0x080AE71C -void BmBgfx_End(struct ProcBmBgfx * proc) -{ - if (proc->conf->type == 10) - { - SetBackgroundTileDataOffset(proc->bg, proc->vram_base); - BG_Fill(BG_GetMapBuffer(proc->bg), 0); - BG_EnableSyncByMask(1 << proc->bg); - } -} - -struct ProcCmd CONST_DATA ProcScr_BmBgfx[] = -{ - PROC_CALL(BmBgfx_Init), - PROC_YIELD, - PROC_REPEAT(BmBgfx_Loop), - PROC_CALL(BmBgfx_End), - PROC_END, -}; - -//! FE8U = 0x080AE750 -bool CheckBmBgfxDone(void) -{ - if (Proc_Find(ProcScr_BmBgfx)) - return true; - - return false; -} - -//! FE8U = 0x080AE76C -void BmBgfxAdvance(void) -{ - struct ProcBmBgfx * proc = Proc_Find(ProcScr_BmBgfx); - if ((proc != NULL) && (proc->conf->type == BMFX_CONFT_BLOCKING)) - proc->conf++; -} - -//! FE8U = 0x080AE790 -void EndBmBgfx(void) -{ - Proc_End(Proc_Find(ProcScr_BmBgfx)); -} - -//! FE8U = 0x080AE7A4 -void BmBgfxSetLoopEN(u8 loop_en) -{ - struct ProcBmBgfx * proc = Proc_Find(ProcScr_BmBgfx); - if (proc != NULL) - proc->loop_en = loop_en; -} - -//! FE8U = 0x080AE7C4 -void StartBmBgfx(struct BmBgxConf * input, int bg, int x, int y, int vram_off, int size, int pal_bank, void * func, ProcPtr parent) -{ - struct ProcBmBgfx * proc; - - if (parent == NULL) - proc = Proc_Start(ProcScr_BmBgfx, PROC_TREE_3); - else - proc = Proc_Start(ProcScr_BmBgfx, parent); - - proc->conf = input; - proc->bg = bg; - proc->pal_bank = pal_bank; - - if (size < 0) - size = 0x4000; - - if (vram_off < 0) - vram_off = 0; - - proc->vram_base = GetBackgroundTileDataOffset(bg); - proc->vram_base_offset = vram_off; - proc->size_per_fx = size; - proc->x = x; - proc->y = y; - - proc->callback = func; - - BG_SetPosition(bg, -x & 0xff, -y & 0xff); - - for (; input->type < BMFX_CONFT_END; input++) - proc->total_duration += input->duration; -} diff --git a/src/sysutil.c b/src/sysutil.c index ba386855..5234670d 100644 --- a/src/sysutil.c +++ b/src/sysutil.c @@ -1,6 +1,7 @@ #include "global.h" #include "bm.h" +#include "ap.h" #include "ctc.h" #include "bmlib.h" #include "hardware.h" @@ -1296,3 +1297,372 @@ void EndFadeInOut(void) Proc_End(Proc_Find(ProcScr_BmFadeIN)); Proc_End(Proc_Find(ProcScr_BmFadeOUT)); } + +//! FE8U = 0x080AE4D8 +void BmBgfx_Init(struct ProcBmBgfx * proc) +{ + proc->conf = 0; + proc->bg = 0; + proc->vram_base = 0; + proc->vram_free_space = 0; + proc->vram_base_offset = 0; + proc->size_per_fx = 0; + proc->flip = 0; + proc->timer = 0; + proc->total_duration = 0; + proc->counter_procloop = 0; + proc->callback = 0; + proc->func_call_type = 0; + proc->counter_functioncall = 0; + proc->x = 0; + proc->y = 0; + proc->loop_en = 1; + proc->counter = 0; +} + +//! FE8U = 0x080AE518 +void BmBgfx_Loop(struct ProcBmBgfx * proc) +{ + struct BmBgxConf * conf = proc->conf; + + if (proc->callback != NULL) + { + proc->func_call_type = 0; + if (proc->callback(proc) != 0) + return; + } + else + { + proc->callback = NULL; + } + + while (1) + { + if (conf->type == BMFX_CONFT_LOOP_START) + conf++; + + /* Loop identifier */ + if (conf->type == BMFX_CONFT_LOOP) + { + if (proc->loop_en != false) + { + if (proc->counter == 0) + proc->counter = conf->duration; + else if (proc->counter > 0) + proc->counter = proc->counter - 1; + + if (proc->counter != 0) + { + int i; + struct BmBgxConf * conf_ = conf - 1; + for (i = conf_->type; i != BMFX_CONFT_LOOP_START; i = conf_->type) + { + conf = conf_; + conf_--; + } + } + else + { + conf++; + } + } + else + { + proc->counter = 0; + conf++; + } + } + + if (conf->type == BMFX_CONFT_CALL_IDLE) + { + if (proc->callback != NULL) + { + proc->counter_functioncall++; + proc->func_call_type = 1; + proc->callback(proc); + } + conf++; + } + + if (conf->type == BMFX_CONFT_BLOCKING) + break; + + if (conf->type < 11 && conf->type > 8) + { + Proc_Break(proc); + break; + } + + if (proc->timer == 0) + { + switch (conf->type) + { + case BMFX_CONFT_IMG: + case BMFX_CONFT_ZIMG: + if (proc->vram_free_space == 0) + proc->flip = 1 - proc->flip; + break; + } + + switch (conf->type) + { + case BMFX_CONFT_IMG: + CpuFastCopy( + conf->data, + (void *)(0x6000000 + proc->vram_base + proc->vram_base_offset + proc->vram_free_space + proc->flip * proc->size_per_fx), + conf->size); + + proc->vram_free_space = proc->vram_free_space + conf->size; + break; + + case BMFX_CONFT_ZIMG: + Decompress( + conf->data, + (void *)(0x6000000 + proc->vram_base + proc->vram_base_offset + proc->vram_free_space + proc->flip * proc->size_per_fx)); + + proc->vram_free_space = proc->vram_free_space + conf->size; + + break; + + case BMFX_CONFT_TSA: + if (proc->size_per_fx == 0x8000) + SetBackgroundTileDataOffset(proc->bg, (proc->vram_base + (proc->flip << 0xf)) & 0xFFFF); + + CallARM_FillTileRect( + BG_GetMapBuffer(proc->bg), conf->data, + (u16)((proc->pal_bank << 0xc) + + (((proc->vram_base_offset + proc->flip * proc->size_per_fx) << 0x11) >> 0x16))); + + proc->vram_free_space = 0; + BG_EnableSyncByMask(1 << proc->bg); + + break; + + case BMFX_CONFT_PAL: + ApplyPalettes(conf->data, proc->pal_bank, conf->size); + break; + } + } + + proc->timer++; + if (proc->timer <= conf->duration) + break; + + conf++; + proc->timer = 0; + } + + proc->conf = conf; + proc->counter_procloop++; +} + +//! FE8U = 0x080AE71C +void BmBgfx_End(struct ProcBmBgfx * proc) +{ + if (proc->conf->type == 10) + { + SetBackgroundTileDataOffset(proc->bg, proc->vram_base); + BG_Fill(BG_GetMapBuffer(proc->bg), 0); + BG_EnableSyncByMask(1 << proc->bg); + } +} + +struct ProcCmd CONST_DATA ProcScr_BmBgfx[] = +{ + PROC_CALL(BmBgfx_Init), + PROC_YIELD, + PROC_REPEAT(BmBgfx_Loop), + PROC_CALL(BmBgfx_End), + PROC_END, +}; + +//! FE8U = 0x080AE750 +bool CheckBmBgfxDone(void) +{ + if (Proc_Find(ProcScr_BmBgfx)) + return true; + + return false; +} + +//! FE8U = 0x080AE76C +void BmBgfxAdvance(void) +{ + struct ProcBmBgfx * proc = Proc_Find(ProcScr_BmBgfx); + if ((proc != NULL) && (proc->conf->type == BMFX_CONFT_BLOCKING)) + proc->conf++; +} + +//! FE8U = 0x080AE790 +void EndBmBgfx(void) +{ + Proc_End(Proc_Find(ProcScr_BmBgfx)); +} + +//! FE8U = 0x080AE7A4 +void BmBgfxSetLoopEN(u8 loop_en) +{ + struct ProcBmBgfx * proc = Proc_Find(ProcScr_BmBgfx); + if (proc != NULL) + proc->loop_en = loop_en; +} + +//! FE8U = 0x080AE7C4 +void StartBmBgfx(struct BmBgxConf * input, int bg, int x, int y, int vram_off, int size, int pal_bank, void * func, ProcPtr parent) +{ + struct ProcBmBgfx * proc; + + if (parent == NULL) + proc = Proc_Start(ProcScr_BmBgfx, PROC_TREE_3); + else + proc = Proc_Start(ProcScr_BmBgfx, parent); + + proc->conf = input; + proc->bg = bg; + proc->pal_bank = pal_bank; + + if (size < 0) + size = 0x4000; + + if (vram_off < 0) + vram_off = 0; + + proc->vram_base = GetBackgroundTileDataOffset(bg); + proc->vram_base_offset = vram_off; + proc->size_per_fx = size; + proc->x = x; + proc->y = y; + + proc->callback = func; + + BG_SetPosition(bg, -x & 0xff, -y & 0xff); + + for (; input->type < BMFX_CONFT_END; input++) + proc->total_duration += input->duration; +} + +void MixPaletteCore(struct ProcMixPalette * proc, int val) +{ + int i, j; + + u16 * dst = gPaletteBuffer + PAL_COLOR_OFFSET(proc->targetPalId, 0); + u16 * ptrA = proc->srcA; + u16 * ptrB = proc->srcB; + + for (i = 0; i < proc->palCount; i++) + { + for (j = 0; j < 0x10; j++) + { + *dst = ((((*ptrA & RED_MASK) * (0x80 - val) + val * (*ptrB & RED_MASK)) >> 7) & RED_MASK) + + ((((*ptrA & GREEN_MASK) * (0x80 - val) + val * (*ptrB & GREEN_MASK)) >> 7) & GREEN_MASK) + + ((((*ptrA & BLUE_MASK) * (0x80 - val) + val * (*ptrB & BLUE_MASK)) >> 7) & BLUE_MASK); + + dst++; + ptrA++; + ptrB++; + } + } + EnablePaletteSync(); +} + +void MixPalette_Init(struct ProcMixPalette * proc) +{ + proc->timer = 0; +} + +void MixPalette_Loop(struct ProcMixPalette * proc) +{ + proc->timer += proc->speed; + + if (proc->timer > 0x100) + proc->timer = 0; + + MixPaletteCore(proc, proc->timer < 0x80 ? proc->timer : 0x100 - proc->timer); +} + +struct ProcCmd CONST_DATA ProcScr_MixPalette[] = +{ + PROC_YIELD, + PROC_CALL(MixPalette_Init), + PROC_REPEAT(MixPalette_Loop), + + PROC_END, +}; + +void StartMixPalette(u16 * palA, u16 * palB, int speed, int targetPalId, int palCount, ProcPtr parent) +{ + struct ProcMixPalette * proc = Proc_Start(ProcScr_MixPalette, parent); + + proc->speed = speed; + proc->targetPalId = targetPalId; + proc->palCount = palCount; + + proc->srcA = palA; + proc->srcB = palB; +} + +void EndMixPalette(void) +{ + Proc_End(Proc_Find(ProcScr_MixPalette)); +} + +ProcPtr StartSpriteAnimfx(const u8 * gfx, const u16 * pal, const void * apDef, int x, int y, int animId, int palId, int palCount, u16 chr, int aObjNode) +{ + if (gfx != NULL) + Decompress(gfx, (void *)(0x06010000 + OAM2_CHR(chr) * CHR_SIZE)); + + if (pal != NULL) + { + ApplyPalettes(pal, (palId + 0x10), palCount); + } + + return APProc_Create(apDef, x, y, OAM2_PAL(palId) + chr, animId, aObjNode); +} + +int GetBgXOffset(int bg) +{ + switch (bg) { + case BG_0: + return gLCDControlBuffer.bgoffset[BG_0].x; + + case BG_1: + return gLCDControlBuffer.bgoffset[BG_1].x; + + case BG_2: + return gLCDControlBuffer.bgoffset[BG_2].x; + + case BG_3: + return gLCDControlBuffer.bgoffset[BG_3].x; + } +} + +int GetBgYOffset(int bg) +{ + switch (bg) { + case BG_0: + return gLCDControlBuffer.bgoffset[BG_0].y; + + case BG_1: + return gLCDControlBuffer.bgoffset[BG_1].y; + + case BG_2: + return gLCDControlBuffer.bgoffset[BG_2].y; + + case BG_3: + return gLCDControlBuffer.bgoffset[BG_3].y; + } +} + +char * AppendString(const char * src, char * dst) +{ + strcpy(dst, src); + return dst + strlen(src); +} + +char * AppendCharacter(int character, char * str) +{ + *str = character; + str++; + *str = '\0'; + return str; +}