review sysutils/code_80AE86C

This commit is contained in:
MokhaLeee 2024-07-10 14:58:13 +08:00
parent 57f7e50f3d
commit 45d31f3b91
13 changed files with 566 additions and 601 deletions

View File

@ -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);

View File

@ -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(???);

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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;

161
src/bonusclaim_helpbox.c Normal file
View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -38,6 +38,7 @@
#include "mapanim.h"
#include "muctrl.h"
#include "scene.h"
#include "sysutil.h"
#include "eventcall.h"

View File

@ -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[] =

View File

@ -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;
}

View File

@ -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;
}