summaryrefslogtreecommitdiff
path: root/src/field/slot_machine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/field/slot_machine.c')
-rw-r--r--src/field/slot_machine.c1965
1 files changed, 1953 insertions, 12 deletions
diff --git a/src/field/slot_machine.c b/src/field/slot_machine.c
index 89ec68b0a..fbc89133a 100644
--- a/src/field/slot_machine.c
+++ b/src/field/slot_machine.c
@@ -1,15 +1,20 @@
#include "global.h"
+#include "constants/songs.h"
+#include "strings2.h"
+#include "overworld.h"
+#include "menu_cursor.h"
+#include "random.h"
+#include "sound.h"
+#include "main.h"
#include "slot_machine.h"
#include "decompress.h"
#include "palette.h"
#include "task.h"
+#include "util.h"
+#include "text.h"
+#include "menu.h"
#include "ewram.h"
-struct UnkStruct2000000 {
- /*0x00*/ u8 filler00[61];
- /*0x3D*/ u8 unk3D;
-};
-
struct UnkStruct1 {
/*0x00*/ u8 unk00;
/*0x01*/ u8 unk01;
@@ -31,6 +36,1946 @@ extern const u16 gUnknown_08E95A18[];
extern u16 gUnknown_08E95AB8[];
extern u16 gUnknown_08E95FB8[];
+static void sub_81018B8(void);
+static void sub_8101954(void);
+static void sub_81019B0(u8 arg0, void *ptr);
+static void nullsub_67(u8 taskId);
+static void sub_8101A28(void);
+static void sub_8101A44(void);
+static void sub_8101A8C(void);
+static void sub_8101AE0(void);
+static void sub_8101B04(void);
+static void sub_8101BA4(void);
+static void sub_8101C84(void);
+static void sub_8101CA0(void);
+static void sub_8101CC0(void);
+static void sub_8101CD4(void);
+static void sub_8101CEC(void);
+static void sub_8101D04(void);
+static void sub_8101D24(u8 taskId);
+static bool8 sub_8101D5C(struct Task *task);
+static bool8 sub_8101D8C(struct Task *task);
+static bool8 sub_8101DB0(struct Task *task);
+static bool8 sub_8101DF4(struct Task *task);
+static bool8 sub_8101E10(struct Task *task);
+static bool8 sub_8101E3C(struct Task *task);
+static bool8 sub_8101F44(struct Task *task);
+static bool8 sub_8101F60(struct Task *task);
+static bool8 sub_8101F88(struct Task *task);
+static bool8 sub_8101FA4(struct Task *task);
+static bool8 sub_8102008(struct Task *task);
+static bool8 sub_8102034(struct Task *task);
+static bool8 sub_8102058(struct Task *task);
+static bool8 sub_8102090(struct Task *task);
+static bool8 sub_81020C8(struct Task *task);
+static bool8 sub_81021E0(struct Task *task);
+static bool8 sub_81021FC(struct Task *task);
+static bool8 sub_8102264(struct Task *task);
+static bool8 sub_81022A0(struct Task *task);
+static bool8 sub_81022CC(struct Task *task);
+static bool8 sub_81022F0(struct Task *task);
+static bool8 sub_8102318(struct Task *task);
+static bool8 sub_8102344(struct Task *task);
+static bool8 sub_810239C(struct Task *task);
+static bool8 sub_81023B8(struct Task *task);
+static bool8 sub_81023E0(struct Task *task);
+static bool8 sub_81023FC(struct Task *task);
+static bool8 sub_8102424(struct Task *task);
+static bool8 sub_8102460(struct Task *task);
+static void sub_8102484(void);
+static void sub_81024F0(void);
+static bool8 sub_8102540(void);
+static u8 sub_8102578(void);
+u16 dp15_jump_random_unknown(void);
+static u8 sub_81025BC(void);
+static void sub_81027A0(void);
+static void sub_81027D0(void);
+static void sub_8102840(void);
+static void sub_810290C(void);
+static u8 sub_81029D4(u8 c1, u8 c2, u8 c3);
+static void sub_8102A24(void);
+static void sub_8102A64(u8 taskId);
+bool8 sub_8102A44(void);
+u8 sub_8102BA4(u8 x, s16 y);
+static void sub_8102DA8(void);
+static void sub_8102DEC(u8 a0);
+static void sub_8102E1C(u8 a0);
+bool8 sub_8102E40(u8 a0);
+void sub_8102E68(u8 taskId);
+void sub_8103C14(u8 a0);
+void sub_8103D50(u8 a0);
+void sub_8103D8C(u8 a0);
+void sub_8103DC8(void);
+void sub_8103E04(u8 a0);
+bool8 sub_8103E38(void);
+bool8 sub_8103E7C(void);
+void sub_8103F70(void);
+bool8 sub_8103FA0(void);
+void sub_8104048(void);
+void sub_8104064(u8 a0);
+bool8 sub_81040C8(void);
+void sub_810423C(u8 a0);
+void sub_810430C(void);
+bool8 sub_810432C(void);
+void sub_8104AB8(u8 a0);
+bool8 sub_8104AEC(void);
+void sub_8104C5C(void);
+void sub_8104CAC(u8 arg0);
+bool8 sub_8104E18(void);
+void sub_8104EA8(void);
+void sub_8104F8C(void);
+void sub_81050C4(void);
+void sub_81063C0(void);
+static void sub_8106448(void);
+void sub_81064B8(void);
+
+static bool8 (*const gUnknown_083ECAAC[])(struct Task *task) = {
+ sub_8101D5C,
+ sub_8101D8C,
+ sub_8101DB0,
+ sub_8101DF4,
+ sub_8101E10,
+ sub_8101E3C,
+ sub_8101F44,
+ sub_8101F60,
+ sub_8101F88,
+ sub_8101FA4,
+ sub_8102008,
+ sub_8102034,
+ sub_8102058,
+ sub_8102090,
+ sub_81020C8,
+ sub_81021E0,
+ sub_81021FC,
+ sub_8102264,
+ sub_81022A0,
+ sub_81022CC,
+ sub_81022F0,
+ sub_8102318,
+ sub_8102344,
+ sub_810239C,
+ sub_81023B8,
+ sub_81023E0,
+ sub_81023FC,
+ sub_8102424,
+ sub_8102460
+};
+
+extern const u8 gUnknown_083ECD04[][3];
+extern const u8 gUnknown_083ECE3A[];
+extern const u16 gUnknown_083ECE42[];
+extern const u16 gUnknown_083ECE48[];
+
+void PlaySlotMachine(u8 arg0, void *ptr)
+{
+ sub_81019B0(arg0, ptr);
+ SetMainCallback2(sub_81018B8);
+}
+
+static void sub_81018B8(void)
+{
+ switch (gMain.state)
+ {
+ case 0:
+ sub_8101A28();
+ sub_8101BA4();
+ gMain.state++;
+ break;
+ case 1:
+ sub_8101A8C();
+ gMain.state++;
+ break;
+ case 2:
+ sub_8101AE0();
+ sub_8101B04();
+ gMain.state++;
+ break;
+ case 3:
+ sub_8101C84();
+ gMain.state++;
+ break;
+ case 4:
+ sub_8101CA0();
+ gMain.state++;
+ break;
+ case 5:
+ sub_8101CC0();
+ gMain.state++;
+ break;
+ case 6:
+ sub_8101CD4();
+ sub_8101CEC();
+ sub_8101A44();
+ SetMainCallback2(sub_8101954);
+ break;
+ }
+}
+
+static void sub_8101954(void)
+{
+ RunTasks();
+ AnimateSprites();
+ BuildOamBuffer();
+ UpdatePaletteFade();
+}
+
+void sub_810196C(void)
+{
+ LoadOam();
+ ProcessSpriteCopyRequests();
+ TransferPlttBuffer();
+ REG_WIN0H = eSlotMachine->win0h;
+ REG_WIN0V = eSlotMachine->win0v;
+ REG_WININ = eSlotMachine->winIn;
+ REG_WINOUT = eSlotMachine->winOut;
+}
+
+static void sub_81019B0(u8 arg0, void *ptr)
+{
+ struct Task *task = &gTasks[CreateTask(nullsub_67, 0xFF)];
+ task->data[0] = arg0;
+ StoreWordInTwoHalfwords(task->data + 1, (intptr_t)ptr);
+}
+
+void sub_81019EC(void)
+{
+ struct Task *task = &gTasks[FindTaskIdByFunc(nullsub_67)];
+ eSlotMachine->unk01 = task->data[0];
+ LoadWordFromTwoHalfwords((u16 *)(task->data + 1), (u32 *)&eSlotMachine->prevMainCb);
+}
+
+static void nullsub_67(u8 taskId)
+{
+}
+
+static void sub_8101A28(void)
+{
+ SetVBlankCallback(NULL);
+ SetHBlankCallback(NULL);
+ REG_DISPCNT = 0;
+}
+
+static void sub_8101A44(void)
+{
+ u16 imeBak;
+ SetVBlankCallback(sub_810196C);
+ imeBak = REG_IME;
+ REG_IME = 0;
+ REG_IE |= INTR_FLAG_VBLANK;
+ REG_IME = imeBak;
+ REG_DISPSTAT |= DISPSTAT_VBLANK_INTR;
+ REG_DISPCNT = DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON | DISPCNT_WIN0_ON;
+}
+
+static void sub_8101A8C(void)
+{
+ DmaClearLarge16(3, (u16 *)(BG_VRAM), BG_VRAM_SIZE, 0x1000);
+}
+
+static void sub_8101AE0(void)
+{
+ DmaClear16(3, (u16 *)OAM, OAM_SIZE);
+}
+
+static void sub_8101B04(void)
+{
+ REG_BG0CNT = 0;
+ REG_BG1CNT = 0;
+ REG_BG2CNT = 0;
+ REG_BG3CNT = 0;
+ REG_BG0HOFS = 0;
+ REG_BG0VOFS = 0;
+ REG_BG1HOFS = 0;
+ REG_BG1VOFS = 0;
+ REG_BG2HOFS = 0;
+ REG_BG2VOFS = 0;
+ REG_BG3HOFS = 0;
+ REG_BG3VOFS = 0;
+ REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_SCREENBASE(31) | BGCNT_CHARBASE(2);
+ REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_SCREENBASE(28);
+ REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_SCREENBASE(29);
+ REG_BG3CNT = BGCNT_PRIORITY(2) | BGCNT_SCREENBASE(30);
+ REG_WININ = 0x3f;
+ REG_WINOUT = 0x3f;
+ REG_BLDCNT = BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_OBJ;
+ REG_BLDALPHA = 0x809;
+}
+
+extern const s16 gUnknown_083ECCF8[3][2];
+
+static void sub_8101BA4(void)
+{
+ u8 i;
+
+ sub_81019EC();
+ eSlotMachine->state = 0;
+ eSlotMachine->unk02 = 0;
+ eSlotMachine->unk03 = Random() & 1;
+ eSlotMachine->unk04 = 0;
+ eSlotMachine->unk08 = 0;
+ eSlotMachine->unk0A = 0;
+ eSlotMachine->unk0B = 0;
+ eSlotMachine->coins = gSaveBlock1.coins;
+ eSlotMachine->unk0E = 0;
+ eSlotMachine->unk10 = 0;
+ eSlotMachine->bet = 0;
+ eSlotMachine->unk18 = 0;
+ eSlotMachine->unk1A = 8;
+ eSlotMachine->win0h = 0xf0;
+ eSlotMachine->win0v = 0xa0;
+ eSlotMachine->winIn = 0x3f;
+ eSlotMachine->winOut = 0x3f;
+ eSlotMachine->backupMapMusic = GetCurrentMapMusic();
+ for (i = 0; i < 3; i++)
+ {
+ eSlotMachine->unk22[i] = 0;
+ eSlotMachine->unk28[i] = gUnknown_083ECCF8[i][eSlotMachine->unk03] % 21;
+ eSlotMachine->unk1C[i] = 0x1f8 - eSlotMachine->unk28[i] * 24;
+ eSlotMachine->unk1C[i] %= 0x1f8;
+ }
+}
+
+static void sub_8101C84(void)
+{
+ SetUpWindowConfig(&gWindowConfig_81E7128);
+ InitMenuWindow(&gWindowConfig_81E7128);
+}
+
+static void sub_8101CA0(void)
+{
+ ResetPaletteFade();
+ ResetSpriteData();
+ gOamLimit = 128;
+ FreeAllSpritePalettes();
+ ResetTasks();
+}
+
+static void sub_8101CC0(void)
+{
+ sub_8106448();
+ sub_81064B8();
+ sub_81063C0();
+}
+
+static void sub_8101CD4(void)
+{
+ sub_8104EA8();
+ sub_8104F8C();
+ sub_8103DC8();
+ sub_81050C4();
+}
+
+static void sub_8101CEC(void)
+{
+ sub_8104048();
+ sub_8102DA8();
+ sub_8104C5C();
+ sub_8101D04();
+}
+
+static void sub_8101D04(void)
+{
+ sub_8101D24(CreateTask(sub_8101D24, 0));
+}
+
+static void sub_8101D24(u8 taskId)
+{
+ while (gUnknown_083ECAAC[eSlotMachine->state](gTasks + taskId));
+}
+
+static bool8 sub_8101D5C(struct Task *task)
+{
+ BeginNormalPaletteFade(-1, 0, 16, 0, 0);
+ sub_810423C(eSlotMachine->unk02);
+ eSlotMachine->state++;
+ return FALSE;
+}
+
+static bool8 sub_8101D8C(struct Task *task)
+{
+ if (!gPaletteFade.active)
+ {
+ eSlotMachine->state++;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8101DB0(struct Task *task)
+{
+ eSlotMachine->unk0E = 0;
+ eSlotMachine->bet = 0;
+ eSlotMachine->unk18 = 0;
+ eSlotMachine->unk04 &= 0xc0;
+ eSlotMachine->state = 4;
+ if (eSlotMachine->coins <= 0)
+ {
+ eSlotMachine->state = 25;
+ }
+ else if (eSlotMachine->unk0A)
+ {
+ eSlotMachine->state = 3;
+ sub_8104CAC(4);
+ }
+ return TRUE;
+}
+
+static bool8 sub_8101DF4(struct Task *task)
+{
+ if (sub_8104E18())
+ {
+ eSlotMachine->state = 4;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8101E10(struct Task *task)
+{
+ sub_8104CAC(0);
+ eSlotMachine->state = 5;
+ if (eSlotMachine->coins >= 9999)
+ {
+ eSlotMachine->state = 23;
+ }
+ return TRUE;
+}
+
+static bool8 sub_8101E3C(struct Task *task)
+{
+ s16 i;
+
+ if (gMain.newKeys & SELECT_BUTTON)
+ {
+ sub_8104AB8(0);
+ eSlotMachine->state = 8;
+ }
+ else if (gMain.newKeys & R_BUTTON)
+ {
+ if (eSlotMachine->coins - (3 - eSlotMachine->bet) >= 0)
+ {
+ for (i = eSlotMachine->bet; i < 3; i++)
+ {
+ sub_8103D50(i);
+ }
+ eSlotMachine->coins -= (3 - eSlotMachine->bet);
+ eSlotMachine->bet = 3;
+ eSlotMachine->state = 9;
+ PlaySE(SE_REGI);
+ }
+ else
+ {
+ eSlotMachine->state = 6;
+ }
+ }
+ else
+ {
+ if (gMain.newKeys & DPAD_DOWN && eSlotMachine->coins != 0)
+ {
+ PlaySE(SE_REGI);
+ sub_8103D50(eSlotMachine->bet);
+ eSlotMachine->coins--;
+ eSlotMachine->bet++;
+ }
+ if (eSlotMachine->bet >= 3 || (eSlotMachine->bet != 0 && gMain.newKeys & A_BUTTON))
+ {
+ eSlotMachine->state = 9;
+ }
+ if (gMain.newKeys & B_BUTTON)
+ {
+ eSlotMachine->state = 21;
+ }
+ }
+ return FALSE;
+}
+
+void sub_8101F2C(const u8 *str)
+{
+ MenuDisplayMessageBox();
+ MenuPrint(str, 2, 15);
+}
+
+static bool8 sub_8101F44(struct Task *task)
+{
+ sub_8101F2C(gOtherText_DontHaveThreeCoins);
+ eSlotMachine->state = 7;
+ return FALSE;
+}
+
+static bool8 sub_8101F60(struct Task *task)
+{
+ if (gMain.newKeys & (A_BUTTON | B_BUTTON))
+ {
+ MenuZeroFillScreen();
+ eSlotMachine->state = 5;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8101F88(struct Task *task)
+{
+ if (sub_8104AEC())
+ {
+ eSlotMachine->state = 5;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8101FA4(struct Task *task)
+{
+ sub_8102484();
+ sub_8104DA4();
+ sub_8102DEC(0);
+ sub_8102DEC(1);
+ sub_8102DEC(2);
+ task->data[0] = 0;
+ if (eSlotMachine->unk04 & 0x20)
+ {
+ sub_810430C();
+ eSlotMachine->state = 10;
+ }
+ else
+ {
+ sub_8104CAC(1);
+ eSlotMachine->state = 11;
+ }
+ eSlotMachine->unk1A = 8;
+ if (eSlotMachine->unk0A)
+ {
+ eSlotMachine->unk1A = dp15_jump_random_unknown();
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102008(struct Task *task)
+{
+ if (sub_810432C())
+ {
+ sub_8104CAC(1);
+ eSlotMachine->unk04 &= 0xDF;
+ eSlotMachine->state = 11;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102034(struct Task *task)
+{
+ if (++task->data[0] >= 30)
+ {
+ sub_81024F0();
+ eSlotMachine->state = 12;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102058(struct Task *task)
+{
+ if (gMain.newKeys & A_BUTTON)
+ {
+ PlaySE(SE_JYUNI);
+ sub_8102E1C(eSlotMachine->unk18);
+ sub_8103C14(eSlotMachine->unk18);
+ eSlotMachine->state = 13;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102090(struct Task *task)
+{
+ if (!sub_8102E40(eSlotMachine->unk18))
+ {
+ eSlotMachine->unk18++;
+ eSlotMachine->state = 12;
+ if (eSlotMachine->unk18 > 2)
+ {
+ eSlotMachine->state = 14;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static bool8 sub_81020C8(struct Task *task)
+{
+ eSlotMachine->unk04 &= 0xc0;
+ sub_81027A0();
+ if (eSlotMachine->unk0A)
+ {
+ eSlotMachine->unk0A--;
+ eSlotMachine->unk0B++;
+ }
+ if (eSlotMachine->unk08)
+ {
+ eSlotMachine->state = 15;
+ sub_8102A24();
+ sub_8103F70();
+ if ((eSlotMachine->unk10 -= eSlotMachine->unk0E) < 0)
+ {
+ eSlotMachine->unk10 = 0;
+ }
+ if (eSlotMachine->unk08 & 0x180)
+ {
+ PlayFanfare(BGM_ME_B_BIG);
+ sub_8104CAC(6);
+ }
+ else if (eSlotMachine->unk08 & 0x40)
+ {
+ PlayFanfare(BGM_ME_B_BIG);
+ sub_8104CAC(5);
+ }
+ else
+ {
+ PlayFanfare(BGM_ME_B_SMALL);
+ sub_8104CAC(2);
+ }
+ if (eSlotMachine->unk08 & 0x1c0)
+ {
+ eSlotMachine->unk04 &= 0x3f;
+ if (eSlotMachine->unk08 & 0x180)
+ {
+ eSlotMachine->unk0A = 0;
+ eSlotMachine->unk0B = 0;
+ eSlotMachine->unk03 = 0;
+ if (eSlotMachine->unk08 & 0x100)
+ {
+ eSlotMachine->unk03 = 1;
+ }
+ }
+ }
+ if (eSlotMachine->unk08 & 0x20 && eSlotMachine->unk02 < 16)
+ {
+ eSlotMachine->unk02++;
+ sub_8104064(eSlotMachine->unk02);
+ }
+ }
+ else
+ {
+ sub_8104CAC(3);
+ eSlotMachine->state = 20;
+ if ((eSlotMachine->unk10 += eSlotMachine->bet) > 9999)
+ {
+ eSlotMachine->unk10 = 9999;
+ }
+ }
+ return FALSE;
+}
+
+static bool8 sub_81021E0(struct Task *task)
+{
+ if (sub_8102A44())
+ {
+ eSlotMachine->state = 16;
+ }
+ return FALSE;
+}
+
+static bool8 sub_81021FC(struct Task *task)
+{
+ if (sub_8103FA0())
+ {
+ eSlotMachine->state = 19;
+ if (eSlotMachine->unk08 & 0x180)
+ {
+ IncrementGameStat(GAME_STAT_SLOT_JACKPOTS);
+ }
+ if (eSlotMachine->unk08 & 0x04)
+ {
+ eSlotMachine->unk18 = 0;
+ eSlotMachine->state = 9;
+ }
+ if (eSlotMachine->unk08 & 0x20)
+ {
+ eSlotMachine->state = 17;
+ }
+ if (eSlotMachine->unk0A && eSlotMachine->unk08 & 0x04)
+ {
+ sub_8104CAC(4);
+ eSlotMachine->state = 18;
+ }
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102264(struct Task *task)
+{
+ if (!sub_81040C8())
+ {
+ eSlotMachine->state = 19;
+ if (eSlotMachine->unk08 & 0x04)
+ {
+ eSlotMachine->state = 9;
+ if (eSlotMachine->unk0A)
+ {
+ sub_8104CAC(4);
+ eSlotMachine->state = 18;
+ }
+ }
+ }
+ return FALSE;
+}
+
+static bool8 sub_81022A0(struct Task *task)
+{
+ if (sub_8104E18())
+ {
+ eSlotMachine->state = 19;
+ if (eSlotMachine->unk08 & 0x04)
+ {
+ eSlotMachine->state = 9;
+ }
+ }
+ return FALSE;
+}
+
+static bool8 sub_81022CC(struct Task *task)
+{
+ sub_8103D8C(0);
+ sub_8103D8C(1);
+ sub_8103D8C(2);
+ eSlotMachine->state = 2;
+ return FALSE;
+}
+
+static bool8 sub_81022F0(struct Task *task)
+{
+ if (++task->data[1] > 64)
+ {
+ task->data[1] = 0;
+ eSlotMachine->state = 19;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102318(struct Task *task)
+{
+ sub_8101F2C(gOtherText_QuitGamePrompt);
+ DisplayYesNoMenu(21, 7, 1);
+ sub_814AB84();
+ eSlotMachine->state = 22;
+ return FALSE;
+}
+
+static bool8 sub_8102344(struct Task *task)
+{
+ s8 input = ProcessMenuInputNoWrap_();
+ if (input == 0)
+ {
+ MenuZeroFillScreen();
+ sub_8103D8C(0);
+ sub_8103D8C(1);
+ sub_8103D8C(2);
+ eSlotMachine->coins += eSlotMachine->bet;
+ eSlotMachine->state = 27;
+ }
+ else if (input == 1 || input == -1)
+ {
+ MenuZeroFillScreen();
+ eSlotMachine->state = 5;
+ }
+ return FALSE;
+}
+
+static bool8 sub_810239C(struct Task *task)
+{
+ sub_8101F2C(gOtherText_MaxCoins);
+ eSlotMachine->state = 24;
+ return FALSE;
+}
+
+static bool8 sub_81023B8(struct Task *task)
+{
+ if (gMain.newKeys & (A_BUTTON | B_BUTTON))
+ {
+ MenuZeroFillScreen();
+ eSlotMachine->state = 5;
+ }
+ return FALSE;
+}
+
+static bool8 sub_81023E0(struct Task *task)
+{
+ sub_8101F2C(gOtherText_OutOfCoins);
+ eSlotMachine->state = 26;
+ return FALSE;
+}
+
+static bool8 sub_81023FC(struct Task *task)
+{
+ if (gMain.newKeys & (A_BUTTON | B_BUTTON))
+ {
+ MenuZeroFillScreen();
+ eSlotMachine->state = 27;
+ }
+ return FALSE;
+}
+
+static bool8 sub_8102424(struct Task *task)
+{
+ gSaveBlock1.coins = eSlotMachine->coins;
+ BeginNormalPaletteFade(-1, 0, 0, 16, 0);
+ eSlotMachine->state++;
+ return FALSE;
+}
+
+static bool8 sub_8102460(struct Task *task)
+{
+ if (!gPaletteFade.active)
+ {
+ SetMainCallback2(eSlotMachine->prevMainCb);
+ }
+ return FALSE;
+}
+
+static void sub_8102484(void)
+{
+ u8 r3;
+
+ if (eSlotMachine->unk0A == 0 && !(eSlotMachine->unk04 & 0xc0))
+ {
+ if (sub_8102540())
+ {
+ r3 = sub_8102578();
+ if (r3 != 3)
+ {
+ eSlotMachine->unk04 |= gUnknown_083ECE42[r3];
+ if (r3 != 1)
+ {
+ return;
+ }
+ }
+ }
+ r3 = sub_81025BC();
+ if (r3 != 5)
+ {
+ eSlotMachine->unk04 |= gUnknown_083ECE48[r3];
+ }
+ }
+}
+
+static void sub_81024F0(void)
+{
+ eSlotMachine->unk06 = 0;
+ if (eSlotMachine->unk04)
+ {
+ eSlotMachine->unk06 = 1;
+ }
+}
+
+u8 sub_810250C(u8 a0)
+{
+ u8 i;
+
+ for (i = 0; i < 8; i++)
+ {
+ if (a0 & 1)
+ {
+ return gUnknown_083ECE3A[i];
+ }
+ a0 >>= 1;
+ }
+ return 0;
+}
+
+static bool8 sub_8102540(void)
+{
+ u8 rval = Random();
+ if (gUnknown_083ECD04[eSlotMachine->unk01][eSlotMachine->bet - 1] > rval)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+extern const u8 gUnknown_083ECD16[][6];
+
+static u8 sub_8102578(void)
+{
+ s16 i;
+
+ for (i = 0; i < 3; i++)
+ {
+ s16 rval = Random() & 0xff;
+ s16 value = gUnknown_083ECD16[i][eSlotMachine->unk01];
+ if (value > rval)
+ {
+ break;
+ }
+ }
+ return i;
+}
+
+extern const u8 gUnknown_083ECD28[][6];
+
+static u8 sub_81025BC(void)
+{
+ s16 i;
+
+ for (i = 0; i < 5; i++)
+ {
+ s16 rval = Random() & 0xff;
+ s16 r3 = gUnknown_083ECD28[i][eSlotMachine->unk01];
+ if (i == 0 && eSlotMachine->unk03 == 1)
+ {
+ r3 += 10;
+ if (r3 > 0x100)
+ {
+ r3 = 0x100;
+ }
+ }
+ else if (i == 4 && eSlotMachine->unk03 == 1)
+ {
+ r3 -= 10;
+ if (r3 < 0)
+ {
+ r3 = 0;
+ }
+ }
+ if (r3 > rval)
+ {
+ break;
+ }
+ }
+ return i;
+}
+
+extern const u8 gUnknown_083ECDAC[][17];
+extern const u8 gUnknown_083ECD46[][17];
+
+u8 sub_810264C(u8 a0)
+{
+ if (eSlotMachine->unk03 == 0)
+ {
+ return gUnknown_083ECD46[a0][eSlotMachine->unk02];
+ }
+ return gUnknown_083ECDAC[a0][eSlotMachine->unk02];
+}
+
+void sub_8102680(void)
+{
+ u8 rval;
+ s16 i;
+
+ eSlotMachine->unk05 = 0;
+ rval = Random();
+ if (rval < sub_810264C(0))
+ {
+ return;
+ }
+ for (i = 5; i > 0; i--)
+ {
+ rval = Random();
+ if (rval < sub_810264C(i))
+ {
+ break;
+ }
+ }
+ eSlotMachine->unk05 = i;
+}
+
+extern const u16 gUnknown_083ECE12[];
+
+bool8 sub_81026DC(u16 a0)
+{
+ u16 rval = Random() & 0xff;
+ if (rval < gUnknown_083ECE12[a0])
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+extern const u16 gUnknown_083ECE1C[][2];
+extern const u16 gUnknown_083ECE30[];
+
+u16 dp15_jump_random_unknown(void)
+{
+ u8 r4 = 0;
+ u8 rval;
+ u8 value;
+ if (eSlotMachine->unk10 >= 300)
+ {
+ r4 = 4;
+ }
+ else if (eSlotMachine->unk10 >= 250)
+ {
+ r4 = 3;
+ }
+ else if (eSlotMachine->unk10 >= 200)
+ {
+ r4 = 2;
+ }
+ else if (eSlotMachine->unk10 >= 150)
+ {
+ r4 = 1;
+ }
+ rval = Random() % 100;
+ value = gUnknown_083ECE1C[r4][0];
+ if (rval < value)
+ {
+ return 4;
+ }
+ rval = Random() % 100;
+ value = gUnknown_083ECE1C[r4][1] + gUnknown_083ECE30[eSlotMachine->unk0B];
+ if (rval < value)
+ {
+ return 2;
+ }
+ return 8;
+}
+
+static void sub_81027A0(void)
+{
+ eSlotMachine->unk08 = 0;
+ sub_81027D0();
+ if (eSlotMachine->bet > 1)
+ {
+ sub_8102840();
+ }
+ if (eSlotMachine->bet > 2)
+ {
+ sub_810290C();
+ }
+}
+
+extern const u16 gUnknown_083ECE6C[];
+extern const u16 gUnknown_083ECE5A[];
+
+static void sub_81027D0(void)
+{
+ u8 c1, c2, c3, payout;
+
+ c1 = sub_8102BA4(0, 2);
+ c2 = sub_8102BA4(1, 2);
+ c3 = sub_8102BA4(2, 2);
+ payout = sub_81029D4(c1, c2, c3);
+ if (payout != 9)
+ {
+ eSlotMachine->unk0E += gUnknown_083ECE6C[payout];
+ eSlotMachine->unk08 |= gUnknown_083ECE5A[payout];
+ sub_8103E04(0);
+ }
+}
+
+static void sub_8102840(void)
+{
+ u8 c1, c2, c3, payout;
+
+ c1 = sub_8102BA4(0, 1);
+ c2 = sub_8102BA4(1, 1);
+ c3 = sub_8102BA4(2, 1);
+ payout = sub_81029D4(c1, c2, c3);
+ if (payout != 9)
+ {
+ if (payout == 0)
+ {
+ payout = 1;
+ }
+ eSlotMachine->unk0E += gUnknown_083ECE6C[payout];
+ eSlotMachine->unk08 |= gUnknown_083ECE5A[payout];
+ sub_8103E04(1);
+ }
+ c1 = sub_8102BA4(0, 3);
+ c2 = sub_8102BA4(1, 3);
+ c3 = sub_8102BA4(2, 3);
+ payout = sub_81029D4(c1, c2, c3);
+ if (payout != 9)
+ {
+ if (payout == 0)
+ {
+ payout = 1;
+ }
+ eSlotMachine->unk0E += gUnknown_083ECE6C[payout];
+ eSlotMachine->unk08 |= gUnknown_083ECE5A[payout];
+ sub_8103E04(2);
+ }
+}
+
+static void sub_810290C(void)
+{
+ u8 c1, c2, c3, payout;
+
+ c1 = sub_8102BA4(0, 1);
+ c2 = sub_8102BA4(1, 2);
+ c3 = sub_8102BA4(2, 3);
+ payout = sub_81029D4(c1, c2, c3);
+ if (payout != 9)
+ {
+ if (payout != 0)
+ {
+ eSlotMachine->unk0E += gUnknown_083ECE6C[payout];
+ eSlotMachine->unk08 |= gUnknown_083ECE5A[payout];
+ }
+ sub_8103E04(3);
+ }
+ c1 = sub_8102BA4(0, 3);
+ c2 = sub_8102BA4(1, 2);
+ c3 = sub_8102BA4(2, 1);
+ payout = sub_81029D4(c1, c2, c3);
+ if (payout != 9)
+ {
+ if (payout != 0)
+ {
+ eSlotMachine->unk0E += gUnknown_083ECE6C[payout];
+ eSlotMachine->unk08 |= gUnknown_083ECE5A[payout];
+ }
+ sub_8103E04(4);
+ }
+}
+
+extern const u8 gUnknown_083ECE52[];
+
+static u8 sub_81029D4(u8 c1, u8 c2, u8 c3)
+{
+ if (c1 == c2 && c1 == c3)
+ {
+ return gUnknown_083ECE52[c1];
+ }
+ if (c1 == 0 && c2 == 0 && c3 == 1)
+ {
+ return 6;
+ }
+ if (c1 == 1 && c2 == 1 && c3 == 0)
+ {
+ return 6;
+ }
+ if (c1 == 4)
+ {
+ return 0;
+ }
+ return 9;
+}
+
+static void sub_8102A24(void)
+{
+ sub_8102A64(CreateTask(sub_8102A64, 4));
+}
+
+bool8 sub_8102A44(void)
+{
+ if (FindTaskIdByFunc(sub_8102A64) == 0xff)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+extern bool8 (*const gUnknown_083ECB20[])(struct Task *task);
+
+static void sub_8102A64(u8 taskId)
+{
+ while (gUnknown_083ECB20[gTasks[taskId].data[0]](gTasks + taskId));
+}
+
+bool8 sub_8102A9C(struct Task *task)
+{
+ if (sub_8103E38())
+ {
+ task->data[0]++;
+ if (eSlotMachine->unk0E == 0)
+ {
+ task->data[0] = 2;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool8 sub_8102AD0(struct Task *task)
+{
+ if (!task->data[1]--)
+ {
+ if (IsFanfareTaskInactive())
+ {
+ PlaySE(SE_PIN);
+ }
+ eSlotMachine->unk0E--;
+ if (eSlotMachine->coins < 9999)
+ {
+ eSlotMachine->coins++;
+ }
+ task->data[1] = 8;
+ if (gMain.heldKeys & A_BUTTON)
+ {
+ task->data[1] = 4;
+ }
+ }
+ if (IsFanfareTaskInactive() && gMain.newKeys & START_BUTTON)
+ {
+ PlaySE(SE_PIN);
+ eSlotMachine->coins += eSlotMachine->unk0E;
+ if (eSlotMachine->coins > 9999)
+ {
+ eSlotMachine->coins = 9999;
+ }
+ eSlotMachine->unk0E = 0;
+ }
+ if (eSlotMachine->unk0E == 0)
+ {
+ task->data[0]++;
+ }
+ return FALSE;
+}
+
+bool8 sub_8102B80(struct Task *task)
+{
+ if (sub_8103E7C())
+ {
+ DestroyTask(FindTaskIdByFunc(sub_8102A64));
+ }
+ return FALSE;
+}
+
+extern const u8 gUnknown_083ECCB2[][21];
+
+u8 sub_8102BA4(u8 x, s16 y)
+{
+ s16 offset = (eSlotMachine->unk28[x] + y) % 21;
+ if (offset < 0)
+ {
+ offset += 21;
+ }
+ return gUnknown_083ECCB2[x][offset];
+}
+
+u8 sub_8102BF8(u8 x, s16 y)
+{
+ s16 r6 = 0;
+ if ((eSlotMachine->unk1C[x]) % 24)
+ r6 = -1;
+ return sub_8102BA4(x, y + r6);
+}
+
+extern const u8 gUnknown_083ECCF1[];
+
+u8 sub_8102C48(s16 a0)
+{
+ s16 r1 = (eSlotMachine->unk16 + a0) % 6;
+ if (r1 < 0)
+ r1 += 6;
+ return gUnknown_083ECCF1[r1];
+}
+
+void sub_8102C84(u8 a0, s16 a1)
+{
+ eSlotMachine->unk1C[a0] += a1;
+ eSlotMachine->unk1C[a0] %= 504;
+ eSlotMachine->unk28[a0] = 21 - eSlotMachine->unk1C[a0] / 24;
+}
+
+s16 sub_8102CCC(u8 a0, s16 a1)
+{
+ s16 r1 = eSlotMachine->unk1C[a0] % 24;
+ if (r1 != 0)
+ {
+ if (r1 < a1)
+ a1 = r1;
+ sub_8102C84(a0, a1);
+ r1 = eSlotMachine->unk1C[a0] % 24;
+ }
+ return r1;
+}
+
+void sub_8102D28(s16 a0)
+{
+ eSlotMachine->unk14 += a0;
+ eSlotMachine->unk14 %= 120;
+ eSlotMachine->unk16 = 6 - eSlotMachine->unk14 / 20;
+}
+
+s16 sub_8102D5C(s16 a0)
+{
+ s16 r1 = eSlotMachine->unk14 % 20;
+ if (r1 != 0)
+ {
+ if (r1 < a0)
+ a0 = r1;
+ sub_8102D28(a0);
+ r1 = eSlotMachine->unk14 % 20;
+ }
+ return r1;
+}
+
+static void sub_8102DA8(void)
+{
+ u8 i;
+ for (i = 0; i < 3; i++)
+ {
+ u8 taskId = CreateTask(sub_8102E68, 2);
+ gTasks[taskId].data[15] = i;
+ eSlotMachine->unk3A[i] = taskId;
+ sub_8102E68(taskId);
+ }
+}
+
+static void sub_8102DEC(u8 a0)
+{
+ gTasks[eSlotMachine->unk3A[a0]].data[0] = 1;
+ gTasks[eSlotMachine->unk3A[a0]].data[14] = 1;
+}
+
+static void sub_8102E1C(u8 a0)
+{
+ gTasks[eSlotMachine->unk3A[a0]].data[0] = 2;
+}
+
+bool8 sub_8102E40(u8 a0)
+{
+ return gTasks[eSlotMachine->unk3A[a0]].data[14];
+}
+
+extern bool8 (*const gUnknown_083ECB2C[])(struct Task *task);
+
+void sub_8102E68(u8 taskId)
+{
+ while (gUnknown_083ECB2C[gTasks[taskId].data[0]](gTasks + taskId));
+}
+
+bool8 sub_8102EA0(struct Task *task)
+{
+ return FALSE;
+}
+
+bool8 sub_8102EA4(struct Task *task)
+{
+ sub_8102C84(task->data[15], eSlotMachine->unk1A);
+ return FALSE;
+}
+
+extern bool8 (*const gUnknown_083ECB40[])(void);
+extern void (*const gUnknown_083ECB4C[])(void);
+
+bool8 sub_8102EC0(struct Task *task)
+{
+ task->data[0]++;
+ eSlotMachine->unk34[task->data[15]] = 0;
+ eSlotMachine->unk2E[task->data[15]] = 0;
+ if (eSlotMachine->unk0A == 0 && (eSlotMachine->unk04 == 0 || eSlotMachine->unk06 == 0 || !gUnknown_083ECB40[task->data[15]]()))
+ {
+ eSlotMachine->unk06 = 0;
+ gUnknown_083ECB4C[task->data[15]]();
+ }
+ task->data[1] = eSlotMachine->unk2E[task->data[15]];
+ return TRUE;
+}
+
+extern const u16 gUnknown_083ECB58[5]; // don't move this
+
+bool8 sub_8102F4C(struct Task *task)
+{
+ s16 r2;
+ u16 sp[5];
+ memcpy(sp, gUnknown_083ECB58, sizeof gUnknown_083ECB58);
+ // u16 sp[] = {2, 4, 4, 4, 8};
+ r2 = eSlotMachine->unk1C[task->data[15]] % 24;
+ if (r2 != 0)
+ {
+ r2 = sub_8102CCC(task->data[15], eSlotMachine->unk1A);
+ }
+ else if (eSlotMachine->unk2E[task->data[15]])
+ {
+ eSlotMachine->unk2E[task->data[15]]--;
+ sub_8102C84(task->data[15], eSlotMachine->unk1A);
+ r2 = eSlotMachine->unk1C[task->data[15]] % 24;
+ }
+ if (r2 == 0 && eSlotMachine->unk2E[task->data[15]] == 0)
+ {
+ task->data[0]++;
+ task->data[1] = sp[task->data[1]];
+ task->data[2] = 0;
+ }
+ return FALSE;
+}
+
+bool8 sub_8103008(struct Task *task)
+{
+ eSlotMachine->unk22[task->data[15]] = task->data[1];
+ task->data[1] = -task->data[1];
+ task->data[2]++;
+ if ((task->data[2] & 0x3) == 0)
+ {
+ task->data[1] >>= 1;
+ }
+ if (task->data[1] == 0)
+ {
+ task->data[0] = 0;
+ task->data[14] = 0;
+ eSlotMachine->unk22[task->data[15]] = 0;
+ }
+ return FALSE;
+}
+
+extern bool8 (*const gUnknown_083ECB64[])(u8 a0, u8 a1);
+
+bool8 sub_810305C(void)
+{
+ u8 r3 = sub_810250C(eSlotMachine->unk04);
+ u8 r5 = r3;
+ if (eSlotMachine->unk04 & 0xc0)
+ {
+ r5 = 0;
+ r3 = 1;
+ }
+ return gUnknown_083ECB64[eSlotMachine->bet - 1](r5, r3);
+}
+
+bool8 sub_81030A4(s16 a0, u8 a1, u8 a2)
+{
+ u8 r1 = sub_8102BF8(0, a0);
+ if (r1 == a1 || r1 == a2)
+ {
+ eSlotMachine->unk07 = r1;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 sub_81030E0(s16 a0)
+{
+ if (sub_8102BF8(0, 1 - a0) == 4 || sub_8102BF8(0, 2 - a0) == 4 || sub_8102BF8(0, 3 - a0) == 4)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 sub_8103134(void)
+{
+ if (eSlotMachine->unk04 & 0xc2)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 sub_8103154(u8 a0, u8 a1)
+{
+ s16 i;
+
+ for (i = 0; i < 5; i++)
+ {
+ if (sub_81030A4(2 - i, a0, a1))
+ {
+ eSlotMachine->unk34[0] = 2;
+ eSlotMachine->unk2E[0] = i;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool8 sub_81031B4(u8 a0, u8 a1)
+{
+ s16 i;
+ bool8 r6 = sub_8103134();
+ if (r6 || !sub_81030E0(0))
+ {
+ for (i = 1; i < 4; i++)
+ {
+ if (sub_81030A4(i, a0, a1))
+ {
+ eSlotMachine->unk34[0] = i;
+ eSlotMachine->unk2E[0] = 0;
+ return TRUE;
+ }
+ }
+ }
+ for (i = 1; i < 5; i++)
+ {
+ bool8 r7 = r6;
+ if (r7 || !sub_81030E0(i))
+ {
+ if (sub_81030A4(1 - i, a0, a1))
+ {
+ if (i == 1 && (r7 || !sub_81030E0(3)))
+ {
+ eSlotMachine->unk34[0] = 3;
+ eSlotMachine->unk2E[0] = 3;
+ return TRUE;
+ }
+ if (i < 4 && (r7 || !sub_81030E0(i + 1)))
+ {
+ eSlotMachine->unk34[0] = 2;
+ eSlotMachine->unk2E[0] = i + 1;
+ return TRUE;
+ }
+ eSlotMachine->unk34[0] = 1;
+ eSlotMachine->unk2E[0] = i;
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+extern bool8 (*const gUnknown_083ECB70[])(void);
+
+bool8 sub_81032C0(void)
+{
+ return gUnknown_083ECB70[eSlotMachine->bet - 1]();
+}
+
+bool8 sub_81032E8(void)
+{
+ s16 i;
+ s16 unk34_0 = eSlotMachine->unk34[0];
+
+ for (i = 0; i < 5; i++)
+ {
+ if (sub_8102BF8(1, unk34_0 - i) == eSlotMachine->unk07)
+ {
+ eSlotMachine->unk34[1] = unk34_0;
+ eSlotMachine->unk2E[1] = i;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool8 sub_810333C(void)
+{
+ s16 i;
+ if (sub_81032E8())
+ {
+ if (eSlotMachine->unk34[0] != 2 && eSlotMachine->unk2E[1] > 1 && eSlotMachine->unk2E[1] != 4)
+ {
+ for (i = 0; i < 5; i++)
+ {
+ if (sub_8102BF8(1, 2 - i) == eSlotMachine->unk07)
+ {
+ eSlotMachine->unk34[1] = 2;
+ eSlotMachine->unk2E[1] = i;
+ break;
+ }
+ }
+ }
+ return TRUE;
+ }
+ if (eSlotMachine->unk34[0] != 2)
+ {
+ for (i = 0; i < 5; i++)
+ {
+ if (sub_8102BF8(1, 2 - i) == eSlotMachine->unk07)
+ {
+ eSlotMachine->unk34[1] = 2;
+ eSlotMachine->unk2E[1] = i;
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+extern bool8 (*const gUnknown_083ECB7C[])(u8 a0);
+
+bool8 sub_81033DC(void)
+{
+ u8 r3 = eSlotMachine->unk07;
+ if (eSlotMachine->unk04 & 0x40)
+ {
+ r3 = 0;
+ if (eSlotMachine->unk07 == 0)
+ {
+ r3 = 1;
+ }
+ }
+ return gUnknown_083ECB7C[eSlotMachine->bet - 1](r3);
+}
+
+bool8 sub_810341C(u8 a0)
+{
+ s16 i;
+ s16 unk34_1 = eSlotMachine->unk34[1];
+
+ for (i = 0; i < 5; i++)
+ {
+ if (sub_8102BF8(2, unk34_1 - i) == a0)
+ {
+ eSlotMachine->unk34[2] = unk34_1;
+ eSlotMachine->unk2E[2] = i;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool8 sub_810347C(u8 a0)
+{
+ s16 i;
+ s16 r8;
+ if (eSlotMachine->unk34[0] == eSlotMachine->unk34[1])
+ {
+ return sub_810341C(a0);
+ }
+ r8 = 1;
+ if (eSlotMachine->unk34[0] == 1)
+ {
+ r8 = 3;
+ }
+ for (i = 0; i < 5; i++)
+ {
+ if (sub_8102BF8(2, r8 - i) == a0)
+ {
+ eSlotMachine->unk2E[2] = i;
+ eSlotMachine->unk34[2] = r8;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void sub_81034F4(void)
+{
+ s16 i;
+ for (i = 0; sub_81030E0(i); i++);
+ eSlotMachine->unk2E[0] = i;
+}
+
+bool8 sub_8103520(u8 *a0)
+{
+ if (*a0 == 0)
+ {
+ *a0 = 1;
+ return TRUE;
+ }
+ if (*a0 == 1)
+ {
+ *a0 = 0;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+extern void (*gUnknown_083ECB88[])(void);
+
+void sub_8103540(void)
+{
+ gUnknown_083ECB88[eSlotMachine->bet - 1]();
+}
+
+void sub_8103564(void)
+{
+ if (eSlotMachine->unk34[0] != 0 && eSlotMachine->unk04 & 0x80)
+ {
+ u8 sp0 = sub_8102BF8(0, 2 - eSlotMachine->unk2E[0]);
+ if (sub_8103520(&sp0))
+ {
+ s16 i;
+ for (i = 0; i < 5; i++)
+ {
+ if (sp0 == sub_8102BF8(1, 2 - i))
+ {
+ eSlotMachine->unk34[1] = 2;
+ eSlotMachine->unk2E[1] = i;
+ break;
+ }
+ }
+ }
+ }
+}
+
+void j5_08111E84(void)
+{
+ if (eSlotMachine->unk34[0] != 0 && eSlotMachine->unk04 & 0x80)
+ {
+ u8 sp0 = sub_8102BF8(0, eSlotMachine->unk34[0] - eSlotMachine->unk2E[0]);
+ if (sub_8103520(&sp0))
+ {
+ s16 i;
+ for (i = 0; i < 5; i++)
+ {
+ if (sp0 == sub_8102BF8(1, eSlotMachine->unk34[0] - i))
+ {
+ eSlotMachine->unk34[1] = eSlotMachine->unk34[0];
+ eSlotMachine->unk2E[1] = i;
+ break;
+ }
+ }
+ }
+ }
+}
+
+#ifdef NONMATCHING // variable r6 is mistakenly plopped into r5,
+ // and variable i is mistakenly plopped into r6
+void sub_8103668(void)
+{
+ if (eSlotMachine->unk34[0] != 0 && eSlotMachine->unk04 & 0x80)
+ {
+ if (eSlotMachine->unk34[0] == 2)
+ {
+ j5_08111E84();
+ }
+ else
+ {
+ u8 sp0 = sub_8102BF8(0, eSlotMachine->unk34[0] - eSlotMachine->unk2E[0]);
+ if (sub_8103520(&sp0))
+ {
+ s16 i;
+ s16 r6 = 2;
+ if (eSlotMachine->unk34[0] == 3)
+ r6 = 3;
+ for (i = 0; i < 2; i++, r6--)
+ {
+ if (sp0 == sub_8102BF8(1, r6))
+ {
+ eSlotMachine->unk34[1] = r6;
+ eSlotMachine->unk2E[1] = 0;
+ return;
+ }
+ }
+ for (i = 1; i < 5; i++)
+ {
+ if (sp0 == sub_8102BF8(1, eSlotMachine->unk34[0] - i))
+ {
+ if (eSlotMachine->unk34[0] == 1)
+ {
+ if (i < 3)
+ {
+ eSlotMachine->unk34[1] = 2;
+ eSlotMachine->unk2E[1] = i + 1;
+ }
+ else
+ {
+ eSlotMachine->unk34[1] = 1;
+ eSlotMachine->unk2E[1] = i;
+ }
+ }
+ else
+ {
+ if (i < 3)
+ {
+ eSlotMachine->unk34[1] = 3;
+ eSlotMachine->unk2E[1] = i;
+ }
+ else
+ {
+ eSlotMachine->unk34[1] = 2;
+ eSlotMachine->unk2E[1] = i - 1;
+ }
+ }
+ return;
+ }
+ }
+ }
+ }
+ }
+}
+#else
+__attribute__((naked)) void sub_8103668(void)
+{
+ asm_unified("\tpush {r4-r7,lr}\n"
+ "\tsub sp, 0x4\n"
+ "\tldr r4, _0810368C @ =gSharedMem\n"
+ "\tldrh r3, [r4, 0x34]\n"
+ "\tmovs r0, 0x34\n"
+ "\tldrsh r2, [r4, r0]\n"
+ "\tcmp r2, 0\n"
+ "\tbeq _0810375A\n"
+ "\tldrb r1, [r4, 0x4]\n"
+ "\tmovs r0, 0x80\n"
+ "\tands r0, r1\n"
+ "\tcmp r0, 0\n"
+ "\tbeq _0810375A\n"
+ "\tcmp r2, 0x2\n"
+ "\tbne _081036AE\n"
+ "\tbl j5_08111E84\n"
+ "\tb _0810375A\n"
+ "\t.align 2, 0\n"
+ "_0810368C: .4byte gSharedMem\n"
+ "_08103690:\n"
+ "\tldr r0, _0810369C @ =gSharedMem\n"
+ "\tmovs r1, 0\n"
+ "\tstrh r6, [r0, 0x36]\n"
+ "\tstrh r1, [r0, 0x30]\n"
+ "\tb _0810375A\n"
+ "\t.align 2, 0\n"
+ "_0810369C: .4byte gSharedMem\n"
+ "_081036A0:\n"
+ "\tmovs r0, 0x2\n"
+ "\tstrh r0, [r5, 0x36]\n"
+ "\tadds r0, r4, 0x1\n"
+ "\tstrh r0, [r5, 0x30]\n"
+ "\tb _0810375A\n"
+ "_081036AA:\n"
+ "\tmovs r0, 0x3\n"
+ "\tb _08103736\n"
+ "_081036AE:\n"
+ "\tldrh r1, [r4, 0x2E]\n"
+ "\tsubs r1, r3, r1\n"
+ "\tlsls r1, 16\n"
+ "\tasrs r1, 16\n"
+ "\tmovs r0, 0\n"
+ "\tbl sub_8102BF8\n"
+ "\tmov r1, sp\n"
+ "\tstrb r0, [r1]\n"
+ "\tmov r0, sp\n"
+ "\tbl sub_8103520\n"
+ "\tlsls r0, 24\n"
+ "\tcmp r0, 0\n"
+ "\tbeq _0810375A\n"
+ "\tmovs r6, 0x2\n"
+ "\tmovs r1, 0x34\n"
+ "\tldrsh r0, [r4, r1]\n"
+ "\tcmp r0, 0x3\n"
+ "\tbne _081036D8\n"
+ "\tmovs r6, 0x3\n"
+ "_081036D8:\n"
+ "\tmovs r5, 0\n"
+ "\tmov r7, sp\n"
+ "_081036DC:\n"
+ "\tlsls r0, r6, 16\n"
+ "\tasrs r4, r0, 16\n"
+ "\tmovs r0, 0x1\n"
+ "\tadds r1, r4, 0\n"
+ "\tbl sub_8102BF8\n"
+ "\tldrb r1, [r7]\n"
+ "\tlsls r0, 24\n"
+ "\tlsrs r0, 24\n"
+ "\tcmp r1, r0\n"
+ "\tbeq _08103690\n"
+ "\tlsls r1, r5, 16\n"
+ "\tmovs r0, 0x80\n"
+ "\tlsls r0, 9\n"
+ "\tadds r1, r0\n"
+ "\tsubs r0, r4, 0x1\n"
+ "\tlsls r0, 16\n"
+ "\tlsrs r6, r0, 16\n"
+ "\tlsrs r5, r1, 16\n"
+ "\tasrs r1, 16\n"
+ "\tcmp r1, 0x1\n"
+ "\tble _081036DC\n"
+ "\tmovs r6, 0x1\n"
+ "\tmov r7, sp\n"
+ "\tldr r5, _0810373C @ =gSharedMem\n"
+ "_0810370E:\n"
+ "\tldrh r1, [r5, 0x34]\n"
+ "\tlsls r0, r6, 16\n"
+ "\tasrs r4, r0, 16\n"
+ "\tsubs r1, r4\n"
+ "\tlsls r1, 16\n"
+ "\tasrs r1, 16\n"
+ "\tmovs r0, 0x1\n"
+ "\tbl sub_8102BF8\n"
+ "\tldrb r1, [r7]\n"
+ "\tlsls r0, 24\n"
+ "\tlsrs r0, 24\n"
+ "\tcmp r1, r0\n"
+ "\tbne _0810374E\n"
+ "\tmovs r1, 0x34\n"
+ "\tldrsh r0, [r5, r1]\n"
+ "\tcmp r0, 0x1\n"
+ "\tbne _08103740\n"
+ "\tcmp r4, 0x2\n"
+ "\tble _081036A0\n"
+ "_08103736:\n"
+ "\tstrh r0, [r5, 0x36]\n"
+ "\tstrh r6, [r5, 0x30]\n"
+ "\tb _0810375A\n"
+ "\t.align 2, 0\n"
+ "_0810373C: .4byte gSharedMem\n"
+ "_08103740:\n"
+ "\tcmp r4, 0x2\n"
+ "\tble _081036AA\n"
+ "\tmovs r0, 0x2\n"
+ "\tstrh r0, [r5, 0x36]\n"
+ "\tsubs r0, r4, 0x1\n"
+ "\tstrh r0, [r5, 0x30]\n"
+ "\tb _0810375A\n"
+ "_0810374E:\n"
+ "\tadds r0, r4, 0x1\n"
+ "\tlsls r0, 16\n"
+ "\tlsrs r6, r0, 16\n"
+ "\tasrs r0, 16\n"
+ "\tcmp r0, 0x4\n"
+ "\tble _0810370E\n"
+ "_0810375A:\n"
+ "\tadd sp, 0x4\n"
+ "\tpop {r4-r7}\n"
+ "\tpop {r0}\n"
+ "\tbx r0");
+}
+#endif // NONMATCHING
+
+bool8 sub_8103764(u8 a0, u8 a1)
+{
+ if ((a0 == 0 && a1 == 1) || (a0 == 1 && a1 == 0))
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 sub_810378C(u8 a0, u8 a1, u8 a2)
+{
+ if ((a0 == 0 && a1 == 1 && a2 == 0) || (a0 == 1 && a1 == 0 && a2 == 1))
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 sub_81037BC(u8 a0, u8 a1, u8 a2)
+{
+ if ((a0 == 0 && a1 == 1 && a2 == 0) ||
+ (a0 == 1 && a1 == 0 && a2 == 1) ||
+ (a0 == 0 && a1 == 0 && a2 == 1) ||
+ (a0 == 1 && a1 == 1 && a2 == 0) ||
+ (a0 == a1 && a0 == a2))
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+extern void (*const gUnknown_083ECB94[])(void);
+
+void sub_810380C(void)
+{
+ gUnknown_083ECB94[eSlotMachine->bet - 1]();
+}
+
+void sub_8103830(void)
+{
+ s16 i = 0;
+ u8 r5 = sub_8102BF8(0, 2 - eSlotMachine->unk2E[0]);
+ u8 r1 = sub_8102BF8(1, 2 - eSlotMachine->unk2E[1]);
+ if (r5 == r1)
+ {
+ while (1)
+ {
+ u8 r0;
+ if (!(r5 == (r0 = sub_8102BF8(2, 2 - i)) || (r5 == 0 && r0 == 1) || (r5 == 1 && r0 == 0)))
+ {
+ break;
+ }
+ i++;
+ }
+ }
+ else if (sub_8103764(r5, r1))
+ {
+ if (eSlotMachine->unk04 & 0x80)
+ {
+ for (i = 0; i < 5; i++)
+ {
+ if (r5 == sub_8102BF8(2, 2 - i))
+ {
+ eSlotMachine->unk2E[2] = i;
+ return;
+ }
+ }
+ }
+ i = 0;
+ while (1)
+ {
+ if (r5 != sub_8102BF8(2, 2 - i))
+ {
+ break;
+ }
+ i++;
+ }
+ }
+ eSlotMachine->unk2E[2] = i;
+}
+
+asm(".section .text_a");
+
static void LoadSlotMachineWheelOverlay(void);
void sub_8104CAC(u8 arg0) {
@@ -39,11 +1984,10 @@ void sub_8104CAC(u8 arg0) {
sub_8104DA4();
- task = &gTasks[ewram0_8->unk3D];
+ task = &gTasks[eSlotMachine->unk3D];
task->data[1] = arg0;
- i = 0;
- while (gUnknown_083ED048[arg0][i].unk00 != 0xFF)
+ for (i = 0; gUnknown_083ED048[arg0][i].unk00 != 0xFF; i++)
{
u8 spriteId;
spriteId = sub_8105BB4(
@@ -59,14 +2003,11 @@ void sub_8104CAC(u8 arg0) {
gSprites[spriteId].invisible = TRUE;
}
#endif
-
- i += 1;
}
}
-
asm(".section .text_b");
-void sub_8106448(void) {
+static void sub_8106448(void) {
u32 offsetRead, offsetWrite;
u32 size;