Begin documenting berry_crush

This commit is contained in:
Kaz 2020-09-13 00:26:01 -04:00
parent d0fcb9168b
commit 449df5860d

View File

@ -149,7 +149,7 @@ struct BerryCrushGame
u8 unk8; u8 unk8;
u8 unk9; u8 unk9;
u8 unkA; u8 mainTask;
u8 unkB; u8 unkB;
u8 unkC; u8 unkC;
@ -199,10 +199,10 @@ struct BerryCrushGame
u8 unk31C0[0x1000]; u8 unk31C0[0x1000];
}; };
static void sub_8020F74(void); static void VBlankCB(void);
static void sub_8020F88(void); static void MainCB(void);
static void sub_8020FA0(u8); static void MainTask(u8);
void sub_8020FC4(struct BerryCrushGame *); static void InitGame(struct BerryCrushGame *);
void sub_8022BEC(u16, u8, u8 *); void sub_8022BEC(u16, u8, u8 *);
static void BerryCrush_SetPaletteFadeParams(u8 *, bool8, u32, s8, u8, u8, u16); static void BerryCrush_SetPaletteFadeParams(u8 *, bool8, u32, s8, u8, u8, u16);
static int sub_8021450(struct BerryCrushGame *); static int sub_8021450(struct BerryCrushGame *);
@ -243,7 +243,7 @@ static u32 sub_8024444(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1
static u32 sub_8024508(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1); static u32 sub_8024508(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1);
static u32 sub_8024568(__attribute__((unused)) struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1); static u32 sub_8024568(__attribute__((unused)) struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1);
static EWRAM_DATA struct BerryCrushGame *gUnknown_02022C90 = NULL; static EWRAM_DATA struct BerryCrushGame *gBerryCrushGame = NULL;
static const u8 gUnknown_082F325C[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; static const u8 gUnknown_082F325C[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
static const u8 gUnknown_082F3264[] = { 0, 1, 2, 3, 5, 0, 0, 0 }; static const u8 gUnknown_082F3264[] = { 0, 1, 2, 3, 5, 0, 0, 0 };
@ -816,22 +816,21 @@ static const u8 gUnknown_082F4434[][4] =
static const u8 gUnknown_082F4444[] = {5, 7, 9, 12}; static const u8 gUnknown_082F4444[] = {5, 7, 9, 12};
static const u8 gUnknown_082F4448[] = {3, 7, 15, 31}; static const u8 gUnknown_082F4448[] = {3, 7, 15, 31};
struct BerryCrushGame * GetBerryCrushGame(void)
struct BerryCrushGame *sub_8020C00(void)
{ {
return gUnknown_02022C90; return gBerryCrushGame;
} }
u32 sub_8020C0C(MainCallback callback) u32 QuitBerryCrush(MainCallback callback)
{ {
if (!gUnknown_02022C90) if (!gBerryCrushGame)
return 2; return 2;
if (!callback) if (!callback)
callback = gUnknown_02022C90->unk0; callback = gBerryCrushGame->unk0;
DestroyTask(gUnknown_02022C90->unkA); DestroyTask(gBerryCrushGame->mainTask);
FREE_AND_SET_NULL(gUnknown_02022C90); FREE_AND_SET_NULL(gBerryCrushGame);
SetMainCallback2(callback); SetMainCallback2(callback);
if (callback == CB2_ReturnToField) if (callback == CB2_ReturnToField)
{ {
@ -868,8 +867,8 @@ void StartBerryCrush(MainCallback callback)
return; return;
} }
gUnknown_02022C90 = AllocZeroed(sizeof(*gUnknown_02022C90)); gBerryCrushGame = AllocZeroed(sizeof(*gBerryCrushGame));
if (!gUnknown_02022C90) if (!gBerryCrushGame)
{ {
SetMainCallback2(callback); SetMainCallback2(callback);
Rfu.unk_10 = 0; Rfu.unk_10 = 0;
@ -878,110 +877,110 @@ void StartBerryCrush(MainCallback callback)
return; return;
} }
gUnknown_02022C90->unk0 = callback; gBerryCrushGame->unk0 = callback;
gUnknown_02022C90->unk8 = multiplayerId; gBerryCrushGame->unk8 = multiplayerId;
gUnknown_02022C90->unk9 = playerCount; gBerryCrushGame->unk9 = playerCount;
sub_8020FC4(gUnknown_02022C90); InitGame(gBerryCrushGame);
gUnknown_02022C90->unk12 = 1; gBerryCrushGame->unk12 = 1;
gUnknown_02022C90->unkE = 1; gBerryCrushGame->unkE = 1;
gUnknown_02022C90->unkF = 6; gBerryCrushGame->unkF = 6;
BerryCrush_SetPaletteFadeParams(gUnknown_02022C90->unk36, 1, -1, 0, 16, 0, 0); BerryCrush_SetPaletteFadeParams(gBerryCrushGame->unk36, 1, -1, 0, 16, 0, 0);
sub_8022BEC(4, 1, gUnknown_02022C90->unk36); sub_8022BEC(4, 1, gBerryCrushGame->unk36);
SetMainCallback2(sub_8020F88); SetMainCallback2(MainCB);
gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); gBerryCrushGame->mainTask = CreateTask(MainTask, 8);
gTextFlags.autoScroll = 0; gTextFlags.autoScroll = 0;
} }
static void sub_8020D8C(void) static void GetBerryFromBag(void)
{ {
if (gSpecialVar_ItemId < FIRST_BERRY_INDEX || gSpecialVar_ItemId > LAST_BERRY_INDEX + 1) if (gSpecialVar_ItemId < FIRST_BERRY_INDEX || gSpecialVar_ItemId > LAST_BERRY_INDEX + 1)
gSpecialVar_ItemId = ITEM_CHERI_BERRY; gSpecialVar_ItemId = ITEM_CHERI_BERRY;
else else
RemoveBagItem(gSpecialVar_ItemId, 1); RemoveBagItem(gSpecialVar_ItemId, 1);
gUnknown_02022C90->unk68.as_four_players.others[gUnknown_02022C90->unk8].unk0 = gSpecialVar_ItemId - FIRST_BERRY_INDEX; gBerryCrushGame->unk68.as_four_players.others[gBerryCrushGame->unk8].unk0 = gSpecialVar_ItemId - FIRST_BERRY_INDEX;
gUnknown_02022C90->unkE = 1; gBerryCrushGame->unkE = 1;
gUnknown_02022C90->unkF = 9; gBerryCrushGame->unkF = 9;
BerryCrush_SetPaletteFadeParams(gUnknown_02022C90->unk36, 0, -1, 0, 16, 0, 0); BerryCrush_SetPaletteFadeParams(gBerryCrushGame->unk36, 0, -1, 0, 16, 0, 0);
sub_8022BEC(4, 1, gUnknown_02022C90->unk36); sub_8022BEC(4, 1, gBerryCrushGame->unk36);
gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); gBerryCrushGame->mainTask = CreateTask(MainTask, 8);
SetMainCallback2(sub_8020F88); SetMainCallback2(MainCB);
} }
void sub_8020E1C(void) static void InitMainTask(void)
{ {
DestroyTask(gUnknown_02022C90->unkA); DestroyTask(gBerryCrushGame->mainTask);
ChooseBerryForMachine(sub_8020D8C); ChooseBerryForMachine(GetBerryFromBag);
} }
static void sub_8020E3C(void) static void SetVBlankCB(void)
{ {
SetVBlankCallback(sub_8020F74); SetVBlankCallback(VBlankCB);
} }
void sub_8020E4C(void) static void InitVBlankCB(void)
{ {
SetVBlankCallback(NULL); SetVBlankCallback(NULL);
} }
void sub_8020E58(void) static void SaveResults(void)
{ {
u32 var0, var1; u32 var0, var1;
var0 = gUnknown_02022C90->unk68.as_four_players.unk00.unk04; var0 = gBerryCrushGame->unk68.as_four_players.unk00.unk04;
var0 = Q_24_8(var0); var0 = Q_24_8(var0);
var0 = MathUtil_Div32(var0, Q_24_8(60)); var0 = MathUtil_Div32(var0, Q_24_8(60));
var1 = gUnknown_02022C90->unk68.as_four_players.unk00.unk0A; var1 = gBerryCrushGame->unk68.as_four_players.unk00.unk0A;
var1 = Q_24_8(var1); var1 = Q_24_8(var1);
var1 = MathUtil_Div32(var1, var0) & 0xFFFF; var1 = MathUtil_Div32(var1, var0) & 0xFFFF;
gUnknown_02022C90->unk16 = var1; gBerryCrushGame->unk16 = var1;
switch (gUnknown_02022C90->unk9) switch (gBerryCrushGame->unk9)
{ {
case 2: case 2:
if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[0]) if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[0])
{ {
gUnknown_02022C90->unk25_1 = 1; gBerryCrushGame->unk25_1 = 1;
gSaveBlock2Ptr->berryCrush.berryCrushResults[0] = gUnknown_02022C90->unk16; gSaveBlock2Ptr->berryCrush.berryCrushResults[0] = gBerryCrushGame->unk16;
} }
break; break;
case 3: case 3:
if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[1]) if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[1])
{ {
gUnknown_02022C90->unk25_1 = 1; gBerryCrushGame->unk25_1 = 1;
gSaveBlock2Ptr->berryCrush.berryCrushResults[1] = gUnknown_02022C90->unk16; gSaveBlock2Ptr->berryCrush.berryCrushResults[1] = gBerryCrushGame->unk16;
} }
break; break;
case 4: case 4:
if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[2]) if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[2])
{ {
gUnknown_02022C90->unk25_1 = 1; gBerryCrushGame->unk25_1 = 1;
gSaveBlock2Ptr->berryCrush.berryCrushResults[2] = gUnknown_02022C90->unk16; gSaveBlock2Ptr->berryCrush.berryCrushResults[2] = gBerryCrushGame->unk16;
} }
break; break;
case 5: case 5:
if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[3]) if (gBerryCrushGame->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[3])
{ {
gUnknown_02022C90->unk25_1 = 1; gBerryCrushGame->unk25_1 = 1;
gSaveBlock2Ptr->berryCrush.berryCrushResults[3] = gUnknown_02022C90->unk16; gSaveBlock2Ptr->berryCrush.berryCrushResults[3] = gBerryCrushGame->unk16;
} }
break; break;
} }
gUnknown_02022C90->unk1C = gUnknown_02022C90->unk68.as_four_players.unk00.unk00; gBerryCrushGame->unk1C = gBerryCrushGame->unk68.as_four_players.unk00.unk00;
if (GiveBerryPowder(gUnknown_02022C90->unk1C)) if (GiveBerryPowder(gBerryCrushGame->unk1C))
return; return;
gUnknown_02022C90->unk25_0 = 1; gBerryCrushGame->unk25_0 = 1;
} }
static void sub_8020F74(void) static void VBlankCB(void)
{ {
TransferPlttBuffer(); TransferPlttBuffer();
LoadOam(); LoadOam();
ProcessSpriteCopyRequests(); ProcessSpriteCopyRequests();
} }
static void sub_8020F88(void) static void MainCB(void)
{ {
RunTasks(); RunTasks();
RunTextPrinters(); RunTextPrinters();
@ -989,12 +988,12 @@ static void sub_8020F88(void)
BuildOamBuffer(); BuildOamBuffer();
} }
static void sub_8020FA0(u8 taskId) static void MainTask(u8 taskId)
{ {
if (gUnknown_02022C90->unk4) if (gBerryCrushGame->unk4)
gUnknown_02022C90->unk4(gUnknown_02022C90, gUnknown_02022C90->unk36); gBerryCrushGame->unk4(gBerryCrushGame, gBerryCrushGame->unk36);
sub_8021450(gUnknown_02022C90); sub_8021450(gBerryCrushGame);
} }
#define PLAYER_UNK14(game, i) \ #define PLAYER_UNK14(game, i) \
@ -1003,11 +1002,11 @@ static void sub_8020FA0(u8 taskId)
+ offsetof(struct BerryCrushGame_68_x, unk30) \ + offsetof(struct BerryCrushGame_68_x, unk30) \
+ sizeof(struct BerryCrushGame_Player) * (i)) + sizeof(struct BerryCrushGame_Player) * (i))
void sub_8020FC4(struct BerryCrushGame *arg0) static void InitGame(struct BerryCrushGame *arg0)
{ {
u8 i; u8 i = 0;
for (i = 0; i < arg0->unk9; i++) for (; i < arg0->unk9; i++)
StringCopy(PLAYER_UNK14(arg0, i), gLinkPlayers[i].name); StringCopy(PLAYER_UNK14(arg0, i), gLinkPlayers[i].name);
for (; i < 5; i++) for (; i < 5; i++)
{ {
@ -1029,13 +1028,14 @@ void sub_8020FC4(struct BerryCrushGame *arg0)
} }
} }
int sub_802104C(void) // TODO: Everything from here on is likely in a separate file.
s32 InitBerryCrushDisplay(void)
{ {
struct BerryCrushGame *var0 = sub_8020C00(); struct BerryCrushGame *game = GetBerryCrushGame();
if (!var0) if (!game)
return -1; return -1;
switch (var0->unkC) switch (game->unkC)
{ {
case 0: case 0:
SetVBlankCallback(NULL); SetVBlankCallback(NULL);
@ -1057,9 +1057,9 @@ int sub_802104C(void)
case 3: case 3:
ResetBgsAndClearDma3BusyFlags(0); ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, gUnknown_082F32C8, ARRAY_COUNT(gUnknown_082F32C8)); InitBgsFromTemplates(0, gUnknown_082F32C8, ARRAY_COUNT(gUnknown_082F32C8));
SetBgTilemapBuffer(1, var0->unk1C0); SetBgTilemapBuffer(1, game->unk1C0);
SetBgTilemapBuffer(2, var0->unk21C0); SetBgTilemapBuffer(2, game->unk21C0);
SetBgTilemapBuffer(3, var0->unk31C0); SetBgTilemapBuffer(3, game->unk31C0);
ChangeBgX(0, 0, 0); ChangeBgX(0, 0, 0);
ChangeBgY(0, 0, 0); ChangeBgY(0, 0, 0);
ChangeBgX(2, 0, 0); ChangeBgX(2, 0, 0);
@ -1088,8 +1088,8 @@ int sub_802104C(void)
InitStandardTextBoxWindows(); InitStandardTextBoxWindows();
InitTextBoxGfxAndPrinters(); InitTextBoxGfxAndPrinters();
sub_8022588(var0); sub_8022588(game);
sub_8022600(var0); sub_8022600(game);
gPaletteFade.bufferTransferDisabled = TRUE; gPaletteFade.bufferTransferDisabled = TRUE;
break; break;
case 7: case 7:
@ -1097,7 +1097,7 @@ int sub_802104C(void)
CopyToBgTilemapBuffer(1, gBerryCrushGrinderTopTilemap, 0, 0); CopyToBgTilemapBuffer(1, gBerryCrushGrinderTopTilemap, 0, 0);
CopyToBgTilemapBuffer(2, gBerryCrushContainerCapTilemap, 0, 0); CopyToBgTilemapBuffer(2, gBerryCrushContainerCapTilemap, 0, 0);
CopyToBgTilemapBuffer(3, gBerryCrushBackgroundTilemap, 0, 0); CopyToBgTilemapBuffer(3, gBerryCrushBackgroundTilemap, 0, 0);
sub_80226D0(var0); sub_80226D0(game);
CopyBgTilemapBufferToVram(1); CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2); CopyBgTilemapBufferToVram(2);
CopyBgTilemapBufferToVram(3); CopyBgTilemapBufferToVram(3);
@ -1105,7 +1105,7 @@ int sub_802104C(void)
case 8: case 8:
LoadWirelessStatusIndicatorSpriteGfx(); LoadWirelessStatusIndicatorSpriteGfx();
CreateWirelessStatusIndicatorSprite(0, 0); CreateWirelessStatusIndicatorSprite(0, 0);
sub_8022730(var0); sub_8022730(game);
SetGpuReg(REG_OFFSET_BG1VOFS, -gSpriteCoordOffsetY); SetGpuReg(REG_OFFSET_BG1VOFS, -gSpriteCoordOffsetY);
ChangeBgX(1, 0, 0); ChangeBgX(1, 0, 0);
ChangeBgY(1, 0, 0); ChangeBgY(1, 0, 0);
@ -1118,18 +1118,18 @@ int sub_802104C(void)
ShowBg(2); ShowBg(2);
ShowBg(3); ShowBg(3);
SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
sub_8020E3C(); SetVBlankCB();
var0->unkC = 0; game->unkC = 0;
return 1; return 1;
} }
var0->unkC++; game->unkC++;
return 0; return 0;
} }
int sub_802130C(void) int sub_802130C(void)
{ {
struct BerryCrushGame *var0 = sub_8020C00(); struct BerryCrushGame *var0 = GetBerryCrushGame();
if (!var0) if (!var0)
return -1; return -1;
@ -1960,7 +1960,7 @@ void sub_8022B28(struct Sprite *sprite)
void sub_8022BEC(u16 r5, u8 r4, u8 *r7) void sub_8022BEC(u16 r5, u8 r4, u8 *r7)
{ {
struct BerryCrushGame *r6 = sub_8020C00(); struct BerryCrushGame *r6 = GetBerryCrushGame();
if (r5 > 25) if (r5 > 25)
r5 = 0; r5 = 0;
@ -2097,7 +2097,7 @@ static u32 sub_8022D14(struct BerryCrushGame *r7, u8 *r5)
static u32 sub_8022E1C(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) static u32 sub_8022E1C(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1)
{ {
if (sub_802104C() != 0) if (InitBerryCrushDisplay() != 0)
sub_8022BEC(r4->unkE, 0, r4->unk36); sub_8022BEC(r4->unkE, 0, r4->unk36);
return 0; return 0;
} }
@ -2155,7 +2155,7 @@ static u32 sub_8022EAC(struct BerryCrushGame *r4, u8 *r5)
static u32 sub_8022F04(struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1) static u32 sub_8022F04(struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1)
{ {
r0->unk4 = NULL; r0->unk4 = NULL;
SetMainCallback2(sub_8020E1C); SetMainCallback2(InitMainTask);
return 0; return 0;
} }
@ -2942,7 +2942,7 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1
r7->unk10 = 0; r7->unk10 = 0;
break; break;
case 7: case 7:
sub_8020E58(); SaveResults();
sub_8022BEC(18, 1, NULL); sub_8022BEC(18, 1, NULL);
r7->unk12 = 11; r7->unk12 = 11;
r7->unkC = 0; r7->unkC = 0;
@ -3210,7 +3210,7 @@ static u32 sub_8024508(struct BerryCrushGame *r5, __attribute__((unused)) u8 *r1
static u32 sub_8024568(__attribute__((unused)) struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1) static u32 sub_8024568(__attribute__((unused)) struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1)
{ {
sub_8020C0C(NULL); QuitBerryCrush(NULL);
return 0; return 0;
} }