summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/berry_pouch.c2
-rw-r--r--src/bg.c20
-rw-r--r--src/box_party_pokemon_dropdown.c180
-rw-r--r--src/field_specials.c10
-rw-r--r--src/graphics.c4
-rw-r--r--src/item_menu.c2
-rw-r--r--src/naming_screen.c2
-rw-r--r--src/pokemon.c4
-rw-r--r--src/pokemon_storage_system.c172
-rw-r--r--src/pokemon_storage_system_2.c653
-rw-r--r--src/pokemon_storage_system_3.c2779
-rw-r--r--src/pokemon_storage_system_4.c1489
-rw-r--r--src/pokemon_storage_system_5.c2036
-rw-r--r--src/pokemon_storage_system_6.c147
-rw-r--r--src/pokemon_storage_system_7.c582
-rw-r--r--src/pokemon_storage_system_8.c755
-rw-r--r--src/pokemon_storage_system_9.c87
-rw-r--r--src/quest_log.c8
-rw-r--r--src/string_util.c6
-rw-r--r--src/strings.c160
-rw-r--r--src/tm_case.c2
-rw-r--r--src/trade.c14
-rw-r--r--src/window_8bpp.c4
23 files changed, 8909 insertions, 209 deletions
diff --git a/src/berry_pouch.c b/src/berry_pouch.c
index a0b2c03a3..01a94c075 100644
--- a/src/berry_pouch.c
+++ b/src/berry_pouch.c
@@ -1258,7 +1258,7 @@ static void Task_ContextMenu_FromPartyGiveMenu(u8 taskId)
static void Task_ContextMenu_FromPokemonPC(u8 taskId)
{
- sResources->exitCallback = sub_808CE60;
+ sResources->exitCallback = Cb2_ReturnToPSS;
gTasks[taskId].func = BerryPouch_StartFadeToExitCallback;
}
diff --git a/src/bg.c b/src/bg.c
index 4ad2bebd6..2acba9d26 100644
--- a/src/bg.c
+++ b/src/bg.c
@@ -553,21 +553,21 @@ u16 GetBgAttribute(u8 bg, u8 attributeId)
{
switch (attributeId)
{
- case 1:
+ case BG_ATTR_CHARBASEINDEX:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX);
- case 2:
+ case BG_ATTR_MAPBASEINDEX:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_MAPBASEINDEX);
- case 3:
+ case BG_ATTR_SCREENSIZE:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE);
- case 4:
+ case BG_ATTR_PALETTEMODE:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE);
- case 7:
+ case BG_ATTR_PRIORITY:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_PRIORITY);
- case 5:
+ case BG_ATTR_MOSAIC:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_MOSAIC);
- case 6:
+ case BG_ATTR_WRAPAROUND:
return GetBgControlAttribute(bg, BG_CTRL_ATTR_WRAPAROUND);
- case 8:
+ case BG_ATTR_TEXTORAFFINEMODE:
switch (GetBgType(bg))
{
case 0:
@@ -577,9 +577,9 @@ u16 GetBgAttribute(u8 bg, u8 attributeId)
default:
return 0;
}
- case 9:
+ case BG_ATTR_BGTYPE:
return GetBgType(bg);
- case 10:
+ case BG_ATTR_BASETILE:
return sGpuBgConfigs2[bg].baseTile;
default:
return -1;
diff --git a/src/box_party_pokemon_dropdown.c b/src/box_party_pokemon_dropdown.c
index a74f1611c..b194777f3 100644
--- a/src/box_party_pokemon_dropdown.c
+++ b/src/box_party_pokemon_dropdown.c
@@ -3,7 +3,7 @@
#include "box_party_pokemon_dropdown.h"
#include "malloc.h"
-struct UnkStruct_203ABE4_Sub
+struct BPPD_MapRect
{
s16 destX;
s16 destY;
@@ -13,27 +13,27 @@ struct UnkStruct_203ABE4_Sub
s16 destY2;
};
-struct UnkStruct_203ABE4
+struct BPPD_Struct
{
- struct UnkStruct_203ABE4_Sub map1Rect;
- struct UnkStruct_203ABE4_Sub map2Rect;
+ struct BPPD_MapRect map1Rect;
+ struct BPPD_MapRect map2Rect;
const void * src1;
const void * src2;
u16 src1Height;
u16 src1Width;
+ u16 src2Width;
u16 src2Height;
- u16 unk_26;
- u16 unk_28;
+ u16 bytesPerRow;
u8 mapSize;
u8 bgId;
bool8 bgUpdateScheduled;
};
-static EWRAM_DATA struct UnkStruct_203ABE4 * sBoxPartyPokemonDropdownPtr = NULL;
+static EWRAM_DATA struct BPPD_Struct * sBoxPartyPokemonDropdownPtr = NULL;
static EWRAM_DATA u16 sBoxPartyPokemonDropdownCount = 0;
-static void PushMap1(u8 a0);
-static void PushMap2(u8 a0);
+static void PushMap1(u8 idx);
+static void PushMap2(u8 idx);
static const struct {
u16 height;
@@ -52,10 +52,10 @@ static const struct {
}
};
-void sub_80F7AD8(u8 num)
+void AllocBoxPartyPokemonDropdowns(u8 num)
{
u16 i;
- sBoxPartyPokemonDropdownPtr = Alloc(num * sizeof(struct UnkStruct_203ABE4));
+ sBoxPartyPokemonDropdownPtr = Alloc(num * sizeof(struct BPPD_Struct));
sBoxPartyPokemonDropdownCount = sBoxPartyPokemonDropdownPtr == NULL ? 0 : num;
for (i = 0; i < sBoxPartyPokemonDropdownCount; i++)
{
@@ -64,149 +64,149 @@ void sub_80F7AD8(u8 num)
}
}
-void sub_80F7B2C(void)
+void FreeBoxPartyPokemonDropdowns(void)
{
Free(sBoxPartyPokemonDropdownPtr);
}
-void sub_80F7B40(void)
+void CopyAllBoxPartyPokemonDropdownsToVram(void)
{
int i;
for (i = 0; i < sBoxPartyPokemonDropdownCount; i++)
{
if (sBoxPartyPokemonDropdownPtr[i].bgUpdateScheduled == TRUE)
- sub_80F7E54(i);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(i);
}
}
-void sub_80F7B80(u8 a0, u8 a1, const void * a2, u16 a3, u16 a4)
+void SetBoxPartyPokemonDropdownMap2(u8 idx, u8 bgId, const void * src, u16 width, u16 height)
{
u16 screenSize;
u16 bgType;
- if (a0 < sBoxPartyPokemonDropdownCount)
+ if (idx < sBoxPartyPokemonDropdownCount)
{
- sBoxPartyPokemonDropdownPtr[a0].src1 = NULL;
- sBoxPartyPokemonDropdownPtr[a0].src2 = a2;
- sBoxPartyPokemonDropdownPtr[a0].bgId = a1;
- sBoxPartyPokemonDropdownPtr[a0].src2Height = a3;
- sBoxPartyPokemonDropdownPtr[a0].unk_26 = a4;
- screenSize = GetBgAttribute(a1, BG_ATTR_SCREENSIZE);
- bgType = GetBgAttribute(a1, BG_ATTR_BGTYPE);
- sBoxPartyPokemonDropdownPtr[a0].src1Height = sBGdims[bgType][screenSize].height;
- sBoxPartyPokemonDropdownPtr[a0].src1Width = sBGdims[bgType][screenSize].width;
+ sBoxPartyPokemonDropdownPtr[idx].src1 = NULL;
+ sBoxPartyPokemonDropdownPtr[idx].src2 = src;
+ sBoxPartyPokemonDropdownPtr[idx].bgId = bgId;
+ sBoxPartyPokemonDropdownPtr[idx].src2Width = width;
+ sBoxPartyPokemonDropdownPtr[idx].src2Height = height;
+ screenSize = GetBgAttribute(bgId, BG_ATTR_SCREENSIZE);
+ bgType = GetBgAttribute(bgId, BG_ATTR_BGTYPE);
+ sBoxPartyPokemonDropdownPtr[idx].src1Height = sBGdims[bgType][screenSize].height;
+ sBoxPartyPokemonDropdownPtr[idx].src1Width = sBGdims[bgType][screenSize].width;
if (bgType != 0)
- sBoxPartyPokemonDropdownPtr[a0].mapSize = 1;
+ sBoxPartyPokemonDropdownPtr[idx].mapSize = 1;
else
- sBoxPartyPokemonDropdownPtr[a0].mapSize = 2;
- sBoxPartyPokemonDropdownPtr[a0].unk_28 = a3 * sBoxPartyPokemonDropdownPtr[a0].mapSize;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.width = a3;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.height = a4;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX = 0;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY = 0;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 = 0;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 = 0;
- sBoxPartyPokemonDropdownPtr[a0].map1Rect = sBoxPartyPokemonDropdownPtr[a0].map2Rect;
- sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
+ sBoxPartyPokemonDropdownPtr[idx].mapSize = 2;
+ sBoxPartyPokemonDropdownPtr[idx].bytesPerRow = width * sBoxPartyPokemonDropdownPtr[idx].mapSize;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.width = width;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.height = height;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX = 0;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY = 0;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 = 0;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 = 0;
+ sBoxPartyPokemonDropdownPtr[idx].map1Rect = sBoxPartyPokemonDropdownPtr[idx].map2Rect;
+ sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE;
}
}
-void sub_80F7C7C(u8 a0, const void * a1)
+void SetBoxPartyPokemonDropdownMap1Tiles(u8 idx, const void * src)
{
- if (a0 < sBoxPartyPokemonDropdownCount)
+ if (idx < sBoxPartyPokemonDropdownCount)
{
- sBoxPartyPokemonDropdownPtr[a0].src1 = a1;
- sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
+ sBoxPartyPokemonDropdownPtr[idx].src1 = src;
+ sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE;
}
}
-void sub_80F7CAC(u8 a0, u16 a1, u16 a2)
+void SetBoxPartyPokemonDropdownMap2Pos(u8 idx, u16 x, u16 y)
{
- if (a0 < sBoxPartyPokemonDropdownCount)
+ if (idx < sBoxPartyPokemonDropdownCount)
{
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 = a1;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 = a2;
- sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 = x;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 = y;
+ sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE;
}
}
-void sub_80F7CE8(u8 a0, u16 a1, u16 a2, u16 a3, u16 a4)
+void SetBoxPartyPokemonDropdownMap2Rect(u8 idx, u16 x, u16 y, u16 width, u16 height)
{
- if (a0 < sBoxPartyPokemonDropdownCount)
+ if (idx < sBoxPartyPokemonDropdownCount)
{
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX = a1;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY = a2;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.width = a3;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.height = a4;
- sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX = x;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY = y;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.width = width;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.height = height;
+ sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE;
}
}
-void sub_80F7D30(u8 a0, u8 a1, s8 a2)
+void AdjustBoxPartyPokemonDropdownPos(u8 idx, u8 op, s8 param)
{
- if (a0 < sBoxPartyPokemonDropdownCount)
+ if (idx < sBoxPartyPokemonDropdownCount)
{
- switch (a1)
+ switch (op)
{
- case 0:
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 += a2;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.width -= a2;
+ case BPPD_MOVE_INNER_LEFT:
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 += param;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.width -= param;
break;
- case 1:
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX += a2;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.width += a2;
+ case BPPD_MOVE_OUTER_LEFT:
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX += param;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.width += param;
break;
- case 2:
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 += a2;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.height -= a2;
+ case BPPD_MOVE_INNER_TOP:
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 += param;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.height -= param;
break;
- case 3:
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY -= a2;
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.height += a2;
+ case BPPD_MOVE_OUTER_TOP:
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY -= param;
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.height += param;
break;
- case 4:
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 += a2;
+ case BPPD_MOVE_INNER_X:
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 += param;
break;
- case 5:
- sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 += a2;
+ case BPPD_MOVE_INNER_Y:
+ sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 += param;
break;
}
- sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
+ sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE;
}
}
-void sub_80F7E54(u8 a0)
+void CopyBoxPartyPokemonDropdownToBgTilemapBuffer(u8 idx)
{
- if (a0 < sBoxPartyPokemonDropdownCount)
+ if (idx < sBoxPartyPokemonDropdownCount)
{
- if (sBoxPartyPokemonDropdownPtr[a0].src1 != NULL)
- PushMap1(a0);
- PushMap2(a0);
- sBoxPartyPokemonDropdownPtr[a0].map1Rect = sBoxPartyPokemonDropdownPtr[a0].map2Rect;
+ if (sBoxPartyPokemonDropdownPtr[idx].src1 != NULL)
+ PushMap1(idx);
+ PushMap2(idx);
+ sBoxPartyPokemonDropdownPtr[idx].map1Rect = sBoxPartyPokemonDropdownPtr[idx].map2Rect;
}
}
-static void PushMap1(u8 a0)
+static void PushMap1(u8 idx)
{
int i;
- int r9 = sBoxPartyPokemonDropdownPtr[a0].mapSize * sBoxPartyPokemonDropdownPtr[a0].src1Height;
- const void * addr = sBoxPartyPokemonDropdownPtr[a0].src1 + r9 * sBoxPartyPokemonDropdownPtr[a0].map1Rect.destY2 + sBoxPartyPokemonDropdownPtr[a0].map1Rect.destX2 * sBoxPartyPokemonDropdownPtr[a0].mapSize;
- for (i = 0; i < sBoxPartyPokemonDropdownPtr[a0].map1Rect.height; i++)
+ int run = sBoxPartyPokemonDropdownPtr[idx].mapSize * sBoxPartyPokemonDropdownPtr[idx].src1Height;
+ const void * addr = sBoxPartyPokemonDropdownPtr[idx].src1 + run * sBoxPartyPokemonDropdownPtr[idx].map1Rect.destY2 + sBoxPartyPokemonDropdownPtr[idx].map1Rect.destX2 * sBoxPartyPokemonDropdownPtr[idx].mapSize;
+ for (i = 0; i < sBoxPartyPokemonDropdownPtr[idx].map1Rect.height; i++)
{
- CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[a0].bgId, addr, sBoxPartyPokemonDropdownPtr[a0].map1Rect.destX2, sBoxPartyPokemonDropdownPtr[a0].map1Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[a0].map1Rect.width, 1);
- addr += r9;
+ CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[idx].bgId, addr, sBoxPartyPokemonDropdownPtr[idx].map1Rect.destX2, sBoxPartyPokemonDropdownPtr[idx].map1Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[idx].map1Rect.width, 1);
+ addr += run;
}
}
-static void PushMap2(u8 a0)
+static void PushMap2(u8 idx)
{
int i;
- int r9 = sBoxPartyPokemonDropdownPtr[a0].mapSize * sBoxPartyPokemonDropdownPtr[a0].src2Height;
- const void * addr = sBoxPartyPokemonDropdownPtr[a0].src2 + r9 * sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY + sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX * sBoxPartyPokemonDropdownPtr[a0].mapSize;
- for (i = 0; i < sBoxPartyPokemonDropdownPtr[a0].map2Rect.height; i++)
+ int run = sBoxPartyPokemonDropdownPtr[idx].mapSize * sBoxPartyPokemonDropdownPtr[idx].src2Width;
+ const void * addr = sBoxPartyPokemonDropdownPtr[idx].src2 + run * sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY + sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX * sBoxPartyPokemonDropdownPtr[idx].mapSize;
+ for (i = 0; i < sBoxPartyPokemonDropdownPtr[idx].map2Rect.height; i++)
{
- CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[a0].bgId, addr, sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2, sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[a0].map2Rect.width, 1);
- addr += r9;
+ CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[idx].bgId, addr, sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2, sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[idx].map2Rect.width, 1);
+ addr += run;
}
}
diff --git a/src/field_specials.c b/src/field_specials.c
index 5be7a4d1c..474fcd081 100644
--- a/src/field_specials.c
+++ b/src/field_specials.c
@@ -442,7 +442,7 @@ bool8 IsThereRoomInAnyBoxForMorePokemon(void)
{
for (j = 0; j < IN_BOX_COUNT; j++)
{
- if (GetBoxMonDataFromAnyBox(i, j, MON_DATA_SPECIES) == SPECIES_NONE)
+ if (GetBoxMonDataAt(i, j, MON_DATA_SPECIES) == SPECIES_NONE)
return TRUE;
}
}
@@ -1642,7 +1642,7 @@ void ChangeBoxPokemonNickname(void)
static void ChangeBoxPokemonNickname_CB(void)
{
- SetBoxMonNickFromAnyBox(gSpecialVar_MonBoxId, gSpecialVar_MonBoxPos, gStringVar2);
+ SetBoxMonNickAt(gSpecialVar_MonBoxId, gSpecialVar_MonBoxPos, gStringVar2);
CB2_ReturnToFieldContinueScriptPlayMapMusic();
}
@@ -1980,11 +1980,11 @@ u16 GetPCBoxToSendMon(void)
bool8 ShouldShowBoxWasFullMessage(void)
{
- if (FlagGet(FLAG_SYS_CHANGED_BOX_TO_STORE_MON))
+ if (FlagGet(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE))
return FALSE;
if (StorageGetCurrentBox() == VarGet(VAR_PC_BOX_TO_SEND_MON))
return FALSE;
- FlagSet(FLAG_SYS_CHANGED_BOX_TO_STORE_MON);
+ FlagSet(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE);
return TRUE;
}
@@ -2001,7 +2001,7 @@ bool8 IsDestinationBoxFull(void)
if (GetBoxMonData(GetBoxedMonPtr(i, j), MON_DATA_SPECIES, NULL) == SPECIES_NONE)
{
if (GetPCBoxToSendMon() != i)
- FlagClear(FLAG_SYS_CHANGED_BOX_TO_STORE_MON);
+ FlagClear(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE);
VarSet(VAR_PC_BOX_TO_SEND_MON, i);
return ShouldShowBoxWasFullMessage();
}
diff --git a/src/graphics.c b/src/graphics.c
index 69e804fd9..5a802cd35 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -1247,10 +1247,10 @@ const u32 gUnknown_8E9BF48[] = INCBIN_U32("graphics/interface/link_rfu_status.4b
const u16 gUnknown_8E9C14C[] = INCBIN_U16("graphics/interface/pokedex_abc.gbapal");
const u32 gUnknown_8E9C16C[] = INCBIN_U32("graphics/interface/pokedex_abc.4bpp.lz");
-const u16 gUnknown_8E9C3D8[] = INCBIN_U16("graphics/interface/box_tiles_pal1.gbapal");
+const u16 gPSSMenu_Pal[] = INCBIN_U16("graphics/interface/box_tiles_pal1.gbapal");
const u16 gUnknown_8E9C3F8[] = INCBIN_U16("graphics/interface/box_tiles_pal2.gbapal");
const u16 gUnknown_8E9C418[] = INCBIN_U16("graphics/interface/box_tiles_pal3.gbapal");
-const u32 gUnknown_8E9C438[] = INCBIN_U32("graphics/interface/box_tiles.4bpp.lz");
+const u32 gPSSMenu_Gfx[] = INCBIN_U32("graphics/interface/box_tiles.4bpp.lz");
const u32 gUnknown_8E9CAEC[] = INCBIN_U32("graphics/unknown/unknown_E9CAEC.bin.lz");
diff --git a/src/item_menu.c b/src/item_menu.c
index 4131e7fd5..e048b4b78 100644
--- a/src/item_menu.c
+++ b/src/item_menu.c
@@ -1784,7 +1784,7 @@ static void GoToBerryPouch_PCBox(void)
static void ReturnToBagMenuFromSubmenu_PCBox(void)
{
- GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_LAST, sub_808CE60);
+ GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_LAST, Cb2_ReturnToPSS);
}
static void Task_ItemContext_Sell(u8 taskId)
diff --git a/src/naming_screen.c b/src/naming_screen.c
index 364fc3fe6..b8b121535 100644
--- a/src/naming_screen.c
+++ b/src/naming_screen.c
@@ -1986,7 +1986,7 @@ static const struct NamingScreenTemplate sPlayerNamingScreenTemplate = {
static const struct NamingScreenTemplate sPcBoxNamingScreenTemplate = {
.copyExistingString = FALSE,
- .maxChars = 8/*BOX_NAME_LENGTH*/,
+ .maxChars = BOX_NAME_LENGTH,
.iconFunction = 2,
.addGenderIcon = 0,
.initialPage = KBPAGE_LETTERS_UPPER,
diff --git a/src/pokemon.c b/src/pokemon.c
index f1f7834b1..b9e62502d 100644
--- a/src/pokemon.c
+++ b/src/pokemon.c
@@ -3661,7 +3661,7 @@ static u8 SendMonToPC(struct Pokemon* mon)
gSpecialVar_MonBoxId = boxNo;
gSpecialVar_MonBoxPos = boxPos;
if (GetPCBoxToSendMon() != boxNo)
- FlagClear(FLAG_SYS_CHANGED_BOX_TO_STORE_MON);
+ FlagClear(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE);
VarSet(VAR_PC_BOX_TO_SEND_MON, boxNo);
return MON_GIVEN_TO_PC;
}
@@ -3806,7 +3806,7 @@ static bool8 IsPokemonStorageFull(void)
for (i = 0; i < 14; i++)
for (j = 0; j < 30; j++)
- if (GetBoxMonDataFromAnyBox(i, j, MON_DATA_SPECIES) == SPECIES_NONE)
+ if (GetBoxMonDataAt(i, j, MON_DATA_SPECIES) == SPECIES_NONE)
return FALSE;
return TRUE;
diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c
new file mode 100644
index 000000000..b69fe7de4
--- /dev/null
+++ b/src/pokemon_storage_system.c
@@ -0,0 +1,172 @@
+#include "global.h"
+#include "gflib.h"
+#include "pokemon_storage_system_internal.h"
+#include "constants/species.h"
+
+void BackupPokemonStorage(struct PokemonStorage * dest)
+{
+ *dest = *gPokemonStoragePtr;
+}
+
+void RestorePokemonStorage(struct PokemonStorage * src)
+{
+ *gPokemonStoragePtr = *src;
+}
+
+// Functions here are general utility functions.
+u8 StorageGetCurrentBox(void)
+{
+ return gPokemonStoragePtr->currentBox;
+}
+
+void SetCurrentBox(u8 boxId)
+{
+ if (boxId < TOTAL_BOXES_COUNT)
+ gPokemonStoragePtr->currentBox = boxId;
+}
+
+u32 GetBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ return GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], request);
+ else
+ return 0;
+}
+
+void SetBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request, const void *value)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ SetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], request, value);
+}
+
+u32 GetCurrentBoxMonData(u8 boxPosition, s32 request)
+{
+ return GetBoxMonDataAt(gPokemonStoragePtr->currentBox, boxPosition, request);
+}
+
+void SetCurrentBoxMonData(u8 boxPosition, s32 request, const void *value)
+{
+ SetBoxMonDataAt(gPokemonStoragePtr->currentBox, boxPosition, request, value);
+}
+
+void GetBoxMonNickAt(u8 boxId, u8 boxPosition, u8 *dst)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], MON_DATA_NICKNAME, dst);
+ else
+ *dst = EOS;
+}
+
+void SetBoxMonNickAt(u8 boxId, u8 boxPosition, const u8 *nick)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ SetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], MON_DATA_NICKNAME, nick);
+}
+
+u32 GetAndCopyBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request, void *dst)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ return GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], request, dst);
+ else
+ return 0;
+}
+
+void SetBoxMonAt(u8 boxId, u8 boxPosition, struct BoxPokemon * src)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ gPokemonStoragePtr->boxes[boxId][boxPosition] = *src;
+}
+
+void CopyBoxMonAt(u8 boxId, u8 boxPosition, struct BoxPokemon * dst)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ *dst = gPokemonStoragePtr->boxes[boxId][boxPosition];
+}
+
+void CreateBoxMonAt(u8 boxId, u8 boxPosition, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 personality, u8 otIDType, u32 otID)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ {
+ CreateBoxMon(&gPokemonStoragePtr->boxes[boxId][boxPosition],
+ species,
+ level,
+ fixedIV,
+ hasFixedPersonality, personality,
+ otIDType, otID);
+ }
+}
+
+void ZeroBoxMonAt(u8 boxId, u8 boxPosition)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ ZeroBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition]);
+}
+
+void BoxMonAtToMon(u8 boxId, u8 boxPosition, struct Pokemon * dst)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ BoxMonToMon(&gPokemonStoragePtr->boxes[boxId][boxPosition], dst);
+}
+
+struct BoxPokemon * GetBoxedMonPtr(u8 boxId, u8 boxPosition)
+{
+ if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
+ return &gPokemonStoragePtr->boxes[boxId][boxPosition];
+ else
+ return NULL;
+}
+
+u8 *GetBoxNamePtr(u8 boxId)
+{
+ if (boxId < TOTAL_BOXES_COUNT)
+ return gPokemonStoragePtr->boxNames[boxId];
+ else
+ return NULL;
+}
+
+u8 GetBoxWallpaper(u8 boxId)
+{
+ if (boxId < TOTAL_BOXES_COUNT)
+ return gPokemonStoragePtr->boxWallpapers[boxId];
+ else
+ return 0;
+}
+
+void SetBoxWallpaper(u8 boxId, u8 wallpaperId)
+{
+ if (boxId < TOTAL_BOXES_COUNT && wallpaperId < WALLPAPER_COUNT)
+ gPokemonStoragePtr->boxWallpapers[boxId] = wallpaperId;
+}
+
+s16 SeekToNextMonInBox(struct BoxPokemon * boxMons, s8 currIndex, u8 maxIndex, u8 flags)
+{
+ // flags:
+ // bit 0: Allow eggs
+ // bit 1: Search backwards
+ s16 i;
+ s16 adder;
+ if (flags == 0 || flags == 1)
+ adder = 1;
+ else
+ adder = -1;
+
+ if (flags == 1 || flags == 3)
+ {
+ for (i = currIndex + adder; i >= 0 && i <= maxIndex; i += adder)
+ {
+ if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE)
+ return i;
+ }
+ }
+ else
+ {
+ for (i = currIndex + adder; i >= 0 && i <= maxIndex; i += adder)
+ {
+ if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE
+ && !GetBoxMonData(&boxMons[i], MON_DATA_IS_EGG))
+ return i;
+ }
+ }
+
+ return -1;
+}
diff --git a/src/pokemon_storage_system_2.c b/src/pokemon_storage_system_2.c
new file mode 100644
index 000000000..b964d3385
--- /dev/null
+++ b/src/pokemon_storage_system_2.c
@@ -0,0 +1,653 @@
+#include "global.h"
+#include "gflib.h"
+#include "event_data.h"
+#include "field_fadetransition.h"
+#include "field_weather.h"
+#include "help_system.h"
+#include "menu.h"
+#include "new_menu_helpers.h"
+#include "overworld.h"
+#include "pokemon_storage_system_internal.h"
+#include "script.h"
+#include "strings.h"
+#include "task.h"
+#include "constants/species.h"
+#include "constants/songs.h"
+#include "constants/field_weather.h"
+#include "constants/help_system.h"
+
+struct PSS_MenuStringPtrs
+{
+ const u8 *text;
+ const u8 *desc;
+};
+
+static EWRAM_DATA u8 sPreviousBoxOption = 0;
+static EWRAM_DATA struct UnkPSSStruct_2002370 *sBoxSelectionPopupSpriteManager = NULL;
+
+static void PSS_CreatePCMenu(u8 whichMenu, s16 *windowIdPtr);
+static void sub_808C9C4(u8 curBox);
+static void sub_808CBA4(void);
+static void UpdateBoxNameAndCountSprite_WraparoundRight(void);
+static void UpdateBoxNameAndCountSprite_WraparoundLeft(void);
+static void PrintBoxNameAndCountToSprite(void);
+static void PrintToSpriteWithTagUnk0240(const u8 *a0, u16 x, u16 y);
+static void sub_808CD64(struct Sprite * sprite);
+
+// Forward declarations
+
+static const u16 gBoxSelectionPopupPalette[];
+static const u16 gBoxSelectionPopupCenterTiles[];
+static const u16 gBoxSelectionPopupSidesTiles[];
+
+static const struct PSS_MenuStringPtrs gUnknown_83CDA20[] = {
+ {gText_WithdrawPokemon, gText_WithdrawMonDescription},
+ {gText_DepositPokemon, gText_DepositMonDescription },
+ {gText_MovePokemon, gText_MoveMonDescription },
+ {gText_MoveItems, gText_MoveItemsDescription },
+ {gText_SeeYa, gText_SeeYaDescription }
+};
+
+void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, u8 *buffer, s32 bytesToBuffer)
+{
+ s32 i, tileBytesToBuffer, remainingBytes;
+ u16 windowId;
+ u8 txtColor[3];
+ u8 *tileData1, *tileData2;
+ struct WindowTemplate winTemplate = {0};
+
+ winTemplate.width = 24;
+ winTemplate.height = 2;
+ windowId = AddWindow(&winTemplate);
+ FillWindowPixelBuffer(windowId, PIXEL_FILL(zero2));
+ tileData1 = (u8*) GetWindowAttribute(windowId, WINDOW_TILE_DATA);
+ tileData2 = (winTemplate.width * 32) + tileData1;
+
+ if (!zero1)
+ txtColor[0] = TEXT_COLOR_TRANSPARENT;
+ else
+ txtColor[0] = zero2;
+ txtColor[1] = TEXT_DYNAMIC_COLOR_6;
+ txtColor[2] = TEXT_DYNAMIC_COLOR_5;
+ AddTextPrinterParameterized4(windowId, 1, 0, 2, 0, 0, txtColor, -1, string);
+
+ tileBytesToBuffer = bytesToBuffer;
+ if (tileBytesToBuffer > 6)
+ tileBytesToBuffer = 6;
+ remainingBytes = bytesToBuffer - 6;
+ if (tileBytesToBuffer > 0)
+ {
+ for (i = tileBytesToBuffer; i != 0; i--)
+ {
+ CpuCopy16(tileData1, dst, 0x80);
+ CpuCopy16(tileData2, dst + 0x80, 0x80);
+ tileData1 += 0x80;
+ tileData2 += 0x80;
+ dst += 0x100;
+ }
+ }
+
+ // Never used. bytesToBuffer is always passed <= 6, so remainingBytes is always <= 0 here
+ if (remainingBytes > 0)
+ CpuFill16((zero2 << 4) | zero2, dst, (u32)(remainingBytes) * 0x100);
+
+ RemoveWindow(windowId);
+}
+
+static void PrintStringToBufferCopyNow(const u8 *string, void *dst, u16 rise, u8 bgClr, u8 fgClr, u8 shClr, u8 *buffer)
+{
+ u32 var;
+ u8 windowId;
+ u8 txtColor[3];
+ u8 *tileData1, *tileData2;
+ struct WindowTemplate winTemplate = {0};
+
+ winTemplate.width = StringLength_Multibyte(string);
+ winTemplate.height = 2;
+ var = winTemplate.width * 32;
+ windowId = AddWindow(&winTemplate);
+ FillWindowPixelBuffer(windowId, PIXEL_FILL(bgClr));
+ tileData1 = (u8*) GetWindowAttribute(windowId, WINDOW_TILE_DATA);
+ tileData2 = (winTemplate.width * 32) + tileData1;
+ txtColor[0] = bgClr;
+ txtColor[1] = fgClr;
+ txtColor[2] = shClr;
+ AddTextPrinterParameterized4(windowId, 1, 0, 2, 0, 0, txtColor, -1, string);
+ CpuCopy16(tileData1, dst, var);
+ CpuCopy16(tileData2, dst + rise, var);
+ RemoveWindow(windowId);
+}
+
+static u8 CountMonsInBox(u8 boxId)
+{
+ u16 i, count;
+
+ for (i = 0, count = 0; i < IN_BOX_COUNT; i++)
+ {
+ if (GetBoxMonDataAt(boxId, i, MON_DATA_SPECIES) != SPECIES_NONE)
+ count++;
+ }
+
+ return count;
+}
+
+s16 GetFirstFreeBoxSpot(u8 boxId)
+{
+ u16 i;
+
+ for (i = 0; i < IN_BOX_COUNT; i++)
+ {
+ if (GetBoxMonDataAt(boxId, i, MON_DATA_SPECIES) == SPECIES_NONE)
+ return i;
+ }
+
+ return -1; // all spots are taken
+}
+
+u8 CountPartyNonEggMons(void)
+{
+ u16 i, count;
+
+ for (i = 0, count = 0; i < PARTY_SIZE; i++)
+ {
+ if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE
+ && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG))
+ {
+ count++;
+ }
+ }
+
+ return count;
+}
+
+u8 CountPartyAliveNonEggMonsExcept(u8 slotToIgnore)
+{
+ u16 i, count;
+
+ for (i = 0, count = 0; i < PARTY_SIZE; i++)
+ {
+ if (i != slotToIgnore
+ && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE
+ && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)
+ && GetMonData(&gPlayerParty[i], MON_DATA_HP) != 0)
+ {
+ count++;
+ }
+ }
+
+ return count;
+}
+
+u16 CountPartyAliveNonEggMons_IgnoreVar0x8004Slot(void)
+{
+ return CountPartyAliveNonEggMonsExcept(gSpecialVar_0x8004);
+}
+
+u8 CountPartyMons(void)
+{
+ u16 i, count;
+
+ for (i = 0, count = 0; i < PARTY_SIZE; i++)
+ {
+ if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE)
+ {
+ count++;
+ }
+ }
+
+ return count;
+}
+
+static u8 *StringCopyAndFillWithSpaces(u8 *dst, const u8 *src, u16 n)
+{
+ u8 *str;
+
+ for (str = StringCopy(dst, src); str < dst + n; str++)
+ *str = CHAR_SPACE;
+
+ *str = EOS;
+ return str;
+}
+
+static void sub_808C25C(u16 *dest, u16 dest_left, u16 dest_top, const u16 *src, u16 src_left, u16 src_top, u16 dest_width, u16 dest_height, u16 src_width)
+{
+ u16 i;
+
+ dest_width *= 2;
+ dest += dest_top * 0x20 + dest_left;
+ src += src_top * src_width + src_left;
+ for (i = 0; i < dest_height; i++)
+ {
+ CpuCopy16(src, dest, dest_width);
+ dest += 0x20;
+ src += src_width;
+ }
+}
+
+static void sub_808C2D8(u16 *dest, u16 dest_left, u16 dest_top, u16 width, u16 height)
+{
+ u16 i;
+
+ dest += dest_top * 0x20 + dest_left;
+ width *= 2;
+ for (i = 0; i < height; dest += 0x20, i++)
+ Dma3FillLarge16_(0, dest, width);
+}
+
+static void Task_PokemonStorageSystemPC(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+
+ switch (task->data[0])
+ {
+ case 0:
+ SetHelpContext(HELPCONTEXT_BILLS_PC);
+ PSS_CreatePCMenu(task->data[1], &task->data[15]);
+ LoadStdWindowFrameGfx();
+ DrawDialogueFrame(0, 0);
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gUnknown_83CDA20[task->data[1]].desc, TEXT_SPEED_FF, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ CopyWindowToVram(0, 3);
+ CopyWindowToVram(task->data[15], 3);
+ task->data[0]++;
+ break;
+ case 1:
+ if (IsWeatherNotFadingIn())
+ {
+ task->data[0]++;
+ }
+ break;
+ case 2:
+ task->data[2] = Menu_ProcessInput();
+ switch(task->data[2])
+ {
+ case MENU_NOTHING_CHOSEN:
+ task->data[3] = task->data[1];
+ if (gMain.newKeys & DPAD_UP && --task->data[3] < 0)
+ task->data[3] = 4;
+
+ if (gMain.newKeys & DPAD_DOWN && ++task->data[3] > 4)
+ task->data[3] = 0;
+ if (task->data[1] != task->data[3])
+ {
+ task->data[1] = task->data[3];
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gUnknown_83CDA20[task->data[1]].desc, 0, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ }
+ break;
+ case MENU_B_PRESSED:
+ case 4:
+ ClearStdWindowAndFrame(0, TRUE);
+ ClearStdWindowAndFrame(task->data[15], TRUE);
+ ScriptContext2_Disable();
+ EnableBothScriptContexts();
+ DestroyTask(taskId);
+ break;
+ default:
+ if (task->data[2] == 0 && CountPartyMons() == PARTY_SIZE)
+ {
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gText_PartyFull, 0, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ task->data[0] = 3;
+ }
+ else if (task->data[2] == 1 && CountPartyMons() == 1)
+ {
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gText_JustOnePkmn, 0, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ task->data[0] = 3;
+ }
+ else
+ {
+ FadeScreen(FADE_TO_BLACK, 0);
+ task->data[0] = 4;
+ }
+ break;
+ }
+ break;
+ case 3:
+ if (gMain.newKeys & (A_BUTTON | B_BUTTON))
+ {
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gUnknown_83CDA20[task->data[1]].desc, 0, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ task->data[0] = 2;
+ }
+ else if (gMain.newKeys & DPAD_UP)
+ {
+ if (--task->data[1] < 0)
+ task->data[1] = 4;
+ Menu_MoveCursor(-1);
+ task->data[1] = Menu_GetCursorPos();
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gUnknown_83CDA20[task->data[1]].desc, 0, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ task->data[0] = 2;
+ }
+ else if (gMain.newKeys & DPAD_DOWN)
+ {
+ if (++task->data[1] > 3)
+ task->data[1] = 0;
+ Menu_MoveCursor(1);
+ task->data[1] = Menu_GetCursorPos();
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ AddTextPrinterParameterized2(0, 2, gUnknown_83CDA20[task->data[1]].desc, 0, NULL, TEXT_COLOR_DARK_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GREY);
+ task->data[0] = 2;
+ }
+ break;
+ case 4:
+ if (!gPaletteFade.active)
+ {
+ CleanupOverworldWindowsAndTilemaps();
+ Cb2_EnterPSS(task->data[2]);
+ DestroyTask(taskId);
+ }
+ break;
+ }
+}
+
+void ShowPokemonStorageSystemPC(void)
+{
+ u8 taskId = CreateTask(Task_PokemonStorageSystemPC, 80);
+ gTasks[taskId].data[0] = 0;
+ gTasks[taskId].data[1] = 0;
+ ScriptContext2_Enable();
+}
+
+static void FieldCb_ReturnToPcMenu(void)
+{
+ u8 taskId;
+ MainCallback vblankCb = gMain.vblankCallback;
+
+ SetVBlankCallback(NULL);
+ taskId = CreateTask(Task_PokemonStorageSystemPC, 80);
+ gTasks[taskId].data[0] = 0;
+ gTasks[taskId].data[1] = sPreviousBoxOption;
+ Task_PokemonStorageSystemPC(taskId);
+ SetVBlankCallback(vblankCb);
+ FadeInFromBlack();
+}
+
+static const struct WindowTemplate gUnknown_83CDA48 = {
+ .bg = 0,
+ .tilemapLeft = 1,
+ .tilemapTop = 1,
+ .width = 17,
+ .height = 10,
+ .paletteNum = 15,
+ .baseBlock = 0x001
+};
+
+static void PSS_CreatePCMenu(u8 whichMenu, s16 *windowIdPtr)
+{
+ s16 windowId;
+ windowId = AddWindow(&gUnknown_83CDA48);
+
+ DrawStdWindowFrame(windowId, FALSE);
+ PrintTextArray(windowId, 2, GetMenuCursorDimensionByFont(2, 0), 2, 16, NELEMS(gUnknown_83CDA20), (void *)gUnknown_83CDA20);
+ Menu_InitCursor(windowId, 2, 0, 2, 16, NELEMS(gUnknown_83CDA20), whichMenu);
+ *windowIdPtr = windowId;
+}
+
+void Cb2_ExitPSS(void)
+{
+ sPreviousBoxOption = GetCurrentBoxOption();
+ gFieldCallback = FieldCb_ReturnToPcMenu;
+ SetMainCallback2(CB2_ReturnToField);
+}
+
+void ResetPokemonStorageSystem(void)
+{
+ u16 boxId, boxPosition;
+
+ SetCurrentBox(0);
+ for (boxId = 0; boxId < TOTAL_BOXES_COUNT; boxId++)
+ {
+ for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++)
+ ZeroBoxMonAt(boxId, boxPosition);
+ }
+ for (boxId = 0; boxId < TOTAL_BOXES_COUNT; boxId++)
+ {
+ u8 *dest = StringCopy(GetBoxNamePtr(boxId), gText_Box);
+ ConvertIntToDecimalStringN(dest, boxId + 1, STR_CONV_MODE_LEFT_ALIGN, 2);
+ }
+ for (boxId = 0; boxId < TOTAL_BOXES_COUNT; boxId++)
+ {
+ SetBoxWallpaper(boxId, boxId % 4);
+ }
+}
+
+void LoadBoxSelectionPopupSpriteGfx(struct UnkPSSStruct_2002370 *a0, u16 tileTag, u16 palTag, u8 a3, bool32 loadPal)
+{
+ struct SpritePalette palette = {
+ gBoxSelectionPopupPalette, palTag
+ };
+ struct SpriteSheet sheets[] = {
+ {gBoxSelectionPopupCenterTiles, 0x800, tileTag},
+ {gBoxSelectionPopupSidesTiles, 0x180, tileTag + 1},
+ {}
+ };
+
+ if (loadPal)
+ LoadSpritePalette(&palette);
+
+ LoadSpriteSheets(sheets);
+ sBoxSelectionPopupSpriteManager = a0;
+ a0->tilesTag = tileTag;
+ a0->paletteTag = palTag;
+ a0->subpriority = a3;
+ a0->loadPal = loadPal;
+}
+
+void FreeBoxSelectionPopupSpriteGfx(void)
+{
+ if (sBoxSelectionPopupSpriteManager->loadPal)
+ FreeSpritePaletteByTag(sBoxSelectionPopupSpriteManager->paletteTag);
+ FreeSpriteTilesByTag(sBoxSelectionPopupSpriteManager->tilesTag);
+ FreeSpriteTilesByTag(sBoxSelectionPopupSpriteManager->tilesTag + 1);
+}
+
+void sub_808C940(u8 curBox)
+{
+ sub_808C9C4(curBox);
+}
+
+void sub_808C950(void)
+{
+ sub_808CBA4();
+}
+
+u8 HandleBoxChooseSelectionInput(void)
+{
+ if (gMain.newKeys & B_BUTTON)
+ {
+ PlaySE(SE_SELECT);
+ return 201;
+ }
+ if (gMain.newKeys & A_BUTTON)
+ {
+ PlaySE(SE_SELECT);
+ return sBoxSelectionPopupSpriteManager->curBox;
+ }
+ if (gMain.newKeys & DPAD_LEFT)
+ {
+ PlaySE(SE_SELECT);
+ UpdateBoxNameAndCountSprite_WraparoundLeft();
+ }
+ else if (gMain.newKeys & DPAD_RIGHT)
+ {
+ PlaySE(SE_SELECT);
+ UpdateBoxNameAndCountSprite_WraparoundRight();
+ }
+ return 200;
+}
+
+static const union AnimCmd gUnknown_83CDA50[] = {
+ ANIMCMD_FRAME( 0, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83CDA58[] = {
+ ANIMCMD_FRAME( 4, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83CDA60[] = {
+ ANIMCMD_FRAME( 6, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83CDA68[] = {
+ ANIMCMD_FRAME(10, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd *const gUnknown_83CDA70[] = {
+ gUnknown_83CDA50,
+ gUnknown_83CDA58,
+ gUnknown_83CDA60,
+ gUnknown_83CDA68
+};
+
+static const union AffineAnimCmd gUnknown_83CDA80[] = {
+ AFFINEANIMCMD_FRAME(224, 224, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const gUnknown_83CDA90[] = {
+ gUnknown_83CDA80
+};
+
+static void sub_808C9C4(u8 curBox)
+{
+ u16 i;
+ u8 spriteId;
+ struct SpriteTemplate template;
+ struct OamData oamData = {};
+ oamData.size = SPRITE_SIZE(64x64);
+ oamData.paletteNum = 1;
+ template = (struct SpriteTemplate){
+ 0, 0, &oamData, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy
+ };
+ {
+ const u8 gUnknown_83CDA94[] = _("/30");
+
+ sBoxSelectionPopupSpriteManager->curBox = curBox;
+ template.tileTag = sBoxSelectionPopupSpriteManager->tilesTag;
+ template.paletteTag = sBoxSelectionPopupSpriteManager->paletteTag;
+
+ spriteId = CreateSprite(&template, 160, 96, 0);
+ sBoxSelectionPopupSpriteManager->unk_0000 = gSprites + spriteId;
+
+ // Manual subsprites
+ oamData.shape = SPRITE_SHAPE(8x32);
+ oamData.size = SPRITE_SIZE(8x32);
+ template.tileTag = sBoxSelectionPopupSpriteManager->tilesTag + 1;
+ template.anims = gUnknown_83CDA70;
+ for (i = 0; i < 4; i++)
+ {
+ u16 r5;
+ spriteId = CreateSprite(&template, 124, 80, sBoxSelectionPopupSpriteManager->subpriority);
+ sBoxSelectionPopupSpriteManager->unk_0004[i] = gSprites + spriteId;
+ r5 = 0;
+ if (i & 2)
+ {
+ sBoxSelectionPopupSpriteManager->unk_0004[i]->pos1.x = 196;
+ r5 = 2;
+ }
+ if (i & 1)
+ {
+ sBoxSelectionPopupSpriteManager->unk_0004[i]->pos1.y = 112;
+ sBoxSelectionPopupSpriteManager->unk_0004[i]->oam.size = SPRITE_SIZE(8x16);
+ r5++;
+ }
+ StartSpriteAnim(sBoxSelectionPopupSpriteManager->unk_0004[i], r5);
+ }
+ for (i = 0; i < 2; i++)
+ {
+ sBoxSelectionPopupSpriteManager->unk_0020[i] = sub_809223C(72 * i + 0x7c, 0x58, i, 0, sBoxSelectionPopupSpriteManager->subpriority);
+ if (sBoxSelectionPopupSpriteManager->unk_0020[i])
+ {
+ sBoxSelectionPopupSpriteManager->unk_0020[i]->data[0] = (i == 0 ? -1 : 1);
+ sBoxSelectionPopupSpriteManager->unk_0020[i]->callback = sub_808CD64;
+ }
+ }
+ PrintBoxNameAndCountToSprite();
+ PrintToSpriteWithTagUnk0240(gUnknown_83CDA94, 5, 3);
+ }
+}
+
+static void sub_808CBA4(void)
+{
+ u16 i;
+ if (sBoxSelectionPopupSpriteManager->unk_0000)
+ {
+ DestroySprite(sBoxSelectionPopupSpriteManager->unk_0000);
+ sBoxSelectionPopupSpriteManager->unk_0000 = NULL;
+ }
+ for (i = 0; i < 4; i++)
+ {
+ if (sBoxSelectionPopupSpriteManager->unk_0004[i])
+ {
+ DestroySprite(sBoxSelectionPopupSpriteManager->unk_0004[i]);
+ sBoxSelectionPopupSpriteManager->unk_0004[i] = NULL;
+ }
+ }
+ for (i = 0; i < 2; i++)
+ {
+ if (sBoxSelectionPopupSpriteManager->unk_0020[i])
+ DestroySprite(sBoxSelectionPopupSpriteManager->unk_0020[i]);
+ }
+}
+
+static void UpdateBoxNameAndCountSprite_WraparoundRight(void)
+{
+ if (++sBoxSelectionPopupSpriteManager->curBox >= TOTAL_BOXES_COUNT)
+ sBoxSelectionPopupSpriteManager->curBox = 0;
+ PrintBoxNameAndCountToSprite();
+}
+
+static void UpdateBoxNameAndCountSprite_WraparoundLeft(void)
+{
+ sBoxSelectionPopupSpriteManager->curBox = (sBoxSelectionPopupSpriteManager->curBox == 0 ? TOTAL_BOXES_COUNT - 1 : sBoxSelectionPopupSpriteManager->curBox - 1);
+ PrintBoxNameAndCountToSprite();
+}
+
+static void PrintBoxNameAndCountToSprite(void)
+{
+ u8 nPokemonInBox = CountMonsInBox(sBoxSelectionPopupSpriteManager->curBox);
+ u8 *boxName = StringCopy(sBoxSelectionPopupSpriteManager->strbuf, GetBoxNamePtr(sBoxSelectionPopupSpriteManager->curBox));
+
+ while (boxName < sBoxSelectionPopupSpriteManager->strbuf + BOX_NAME_LENGTH)
+ *boxName++ = CHAR_SPACE;
+ *boxName = EOS;
+
+ PrintToSpriteWithTagUnk0240(sBoxSelectionPopupSpriteManager->strbuf, 0, 1);
+
+ ConvertIntToDecimalStringN(sBoxSelectionPopupSpriteManager->strbuf, nPokemonInBox, STR_CONV_MODE_RIGHT_ALIGN, 2);
+
+ PrintToSpriteWithTagUnk0240(sBoxSelectionPopupSpriteManager->strbuf, 3, 3);
+}
+
+static void PrintToSpriteWithTagUnk0240(const u8 *str, u16 x, u16 y)
+{
+ u16 tileStart = GetSpriteTileStartByTag(sBoxSelectionPopupSpriteManager->tilesTag);
+ PrintStringToBufferCopyNow(str, (void *)(OBJ_VRAM0 + tileStart * 32 + 256 * y + 32 * x), 0x100, TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5, sBoxSelectionPopupSpriteManager->buffer);
+}
+
+static void sub_808CD64(struct Sprite *sprite)
+{
+ if (++sprite->data[1] > 3)
+ {
+ sprite->data[1] = 0;
+ sprite->pos2.x += sprite->data[0];
+ if (++sprite->data[2] > 5)
+ {
+ sprite->data[2] = 0;
+ sprite->pos2.x = 0;
+ }
+ }
+}
+
+// Forward-declared rodata
+
+static const u16 gBoxSelectionPopupPalette[] = INCBIN_U16("graphics/interface/pss_unk_83CDA98.gbapal");
+static const u16 gBoxSelectionPopupCenterTiles[] = INCBIN_U16("graphics/interface/pss_unk_83CDAB8.4bpp");
+static const u16 gBoxSelectionPopupSidesTiles[] = INCBIN_U16("graphics/interface/pss_unk_83CE2B8.4bpp");
diff --git a/src/pokemon_storage_system_3.c b/src/pokemon_storage_system_3.c
new file mode 100644
index 000000000..48007ad0f
--- /dev/null
+++ b/src/pokemon_storage_system_3.c
@@ -0,0 +1,2779 @@
+#include "global.h"
+#include "gflib.h"
+#include "box_party_pokemon_dropdown.h"
+#include "data.h"
+#include "decompress.h"
+#include "dynamic_placeholder_text_util.h"
+#include "event_data.h"
+#include "graphics.h"
+#include "help_system.h"
+#include "item.h"
+#include "item_menu.h"
+#include "mail_data.h"
+#include "menu.h"
+#include "naming_screen.h"
+#include "new_menu_helpers.h"
+#include "pc_screen_effect.h"
+#include "pokemon_icon.h"
+#include "pokemon_storage_system_internal.h"
+#include "pokemon_summary_screen.h"
+#include "quest_log.h"
+#include "strings.h"
+#include "task.h"
+#include "text_window.h"
+#include "trig.h"
+#include "constants/items.h"
+#include "constants/help_system.h"
+#include "constants/songs.h"
+#include "constants/flags.h"
+#include "constants/vars.h"
+
+EWRAM_DATA struct PokemonStorageSystemData *sPSSData = NULL;
+static EWRAM_DATA bool8 sInPartyMenu = 0;
+static EWRAM_DATA u8 sCurrentBoxOption = 0;
+static EWRAM_DATA u8 gUnknown_20397B6 = 0;
+static EWRAM_DATA u8 sWhichToReshow = 0;
+static EWRAM_DATA u8 sLastUsedBox = 0;
+static EWRAM_DATA u16 gUnknown_20397BA = ITEM_NONE;
+
+static void Cb_InitPSS(u8 taskId);
+static void Cb_ShowPSS(u8 taskId);
+static void Cb_ReshowPSS(u8 taskId);
+static void Cb_MainPSS(u8 taskId);
+static void Cb_ShowPartyPokemon(u8 taskId);
+static void Cb_HidePartyPokemon(u8 taskId);
+static void Cb_OnSelectedMon(u8 taskId);
+static void Cb_MoveMon(u8 taskId);
+static void Cb_PlaceMon(u8 taskId);
+static void Cb_ShiftMon(u8 taskId);
+static void Cb_WithdrawMon(u8 taskId);
+static void Cb_DepositMenu(u8 taskId);
+static void Cb_ReleaseMon(u8 taskId);
+static void Cb_ShowMarkMenu(u8 taskId);
+static void Cb_TakeItemForMoving(u8 taskId);
+static void Cb_GiveMovingItemToMon(u8 taskId);
+static void Cb_ItemToBag(u8 taskId);
+static void Cb_SwitchSelectedItem(u8 taskId);
+static void Cb_ShowItemInfo(u8 taskId);
+static void Cb_HandleMovingMonFromParty(u8 taskId);
+static void Cb_PrintCantStoreMail(u8 taskId);
+static void Cb_HandleBoxOptions(u8 taskId);
+static void Cb_HandleWallpapers(u8 taskId);
+static void Cb_JumpBox(u8 taskId);
+static void Cb_NameBox(u8 taskId);
+static void Cb_ShowMonSummary(u8 taskId);
+static void Cb_GiveItemFromBag(u8 taskId);
+static void Cb_OnCloseBoxPressed(u8 taskId);
+static void Cb_OnBPressed(u8 taskId);
+static void Cb_ChangeScreen(u8 taskId);
+static void GiveChosenBagItem(void);
+static void FreePSSData(void);
+static void SetScrollingBackground(void);
+static void ScrollBackground(void);
+static void LoadPSSMenuGfx(void);
+static bool8 InitPSSWindows(void);
+static void LoadWaveformSpritePalette(void);
+static void sub_808F078(void);
+static void sub_808F0F4(void);
+static void sub_808F164(void);
+static void RefreshCursorMonData(void);
+static void BoxSetMosaic(void);
+static void SpriteCB_CursorMon_Mosaic(struct Sprite * sprite);
+static bool8 BoxGetMosaic(void);
+static void LoadCursorMonSprite(void);
+static void LoadCursorMonGfx(u16 species, u32 pid);
+static void PrintCursorMonInfo(void);
+static void sub_808F5E8(void);
+static void sub_808F68C(void);
+static void SetUpHidePartyMenu(void);
+static bool8 HidePartyMenu(void);
+static void sub_808F90C(bool8 species);
+static void sub_808F948(void);
+static void sub_808F974(void);
+static void sub_808F99C(void);
+static void sub_808F9FC(void);
+static void sub_808FA30(u8 pos, bool8 isPartyMon);
+static void sub_808FAA8(void);
+static void SetUpDoShowPartyMenu(void);
+static bool8 DoShowPartyMenu(void);
+static void sub_808FB68(void);
+static void PrintStorageActionText(u8 textId);
+static void ShowYesNoWindow(s8 species);
+static void ClearBottomWindow(void);
+static void AddWallpaperSetsMenu(void);
+static void AddWallpapersMenu(u8 wallpaperSet);
+static void sub_808FDFC(void);
+static void sub_808FE54(u8 species);
+static void sub_808FF70(void);
+
+static const u32 gPokemonStorageScrollingBGTileset[] = INCBIN_U32("graphics/interface/pss_unk_83CE438.4bpp.lz");
+static const u32 gPokemonStorageScrollingBGTilemap[] = INCBIN_U32("graphics/interface/pss_unk_83CE4D0.bin.lz");
+static const u16 gPokemonStorageScrollingBGPalette[] = INCBIN_U16("graphics/interface/pss_unk_83CE5DC.gbapal");
+static const u32 gUnknown_83CE5FC[] = INCBIN_U32("graphics/interface/pss_unk_83CE5FC.bin.lz");
+
+static const u16 gUnknown_83CE6F8[] = {
+ 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108,
+ 0x0111, 0x0112, 0x0113, 0x0114, 0x0115, 0x0116, 0x0117, 0x0118,
+ 0x2101, 0x2102, 0x2103, 0x2104, 0x2105, 0x2106, 0x2107, 0x2108,
+ 0x2111, 0x2112, 0x2113, 0x2114, 0x2115, 0x2116, 0x2117, 0x2118,
+};
+
+static const u16 gUnknown_83CE738[] = INCBIN_U16("graphics/interface/pss_unk_83CE738.gbapal");
+static const u16 gUnknown_83CE758[] = INCBIN_U16("graphics/interface/pss_unk_83CE758.gbapal");
+
+static const u16 gUnknown_83CE778[] = {
+ 0x014c, 0x014d, 0x014e, 0x014f, 0x0170, 0x0171, 0x0172, 0x0173, 0x0174,
+ 0x015c, 0x015d, 0x015e, 0x015f, 0x0180, 0x0181, 0x0182, 0x0183, 0x0184,
+ 0x0175, 0x0176, 0x0177, 0x0178, 0x0179, 0x017a, 0x017b, 0x017c, 0x017d,
+ 0x0185, 0x0186, 0x0187, 0x0188, 0x0189, 0x018a, 0x018b, 0x018c, 0x018d,
+};
+
+static const u16 gUnknown_83CE7C0[] = {
+ 0x1140, 0x1141, 0x1141, 0x1142,
+ 0x1150, 0x1151, 0x1151, 0x1152,
+ 0x1160, 0x1161, 0x1161, 0x1162,
+};
+
+static const u16 gUnknown_83CE7D8[] = {
+ 0x1143, 0x1144, 0x1144, 0x1145,
+ 0x1153, 0x1154, 0x1154, 0x1155,
+ 0x1163, 0x1164, 0x1164, 0x1165,
+};
+
+static const u16 gUnknown_83CE7F0[] = INCBIN_U16("graphics/interface/pss_unk_83CE810.gbapal");
+static const u16 gUnknown_83CE810[] = INCBIN_U16("graphics/interface/pss_unk_83CE810.4bpp");
+static const u16 gUnknown_83CE9D0[] = INCBIN_U16("graphics/interface/pss_unk_83CE9D0.gbapal");
+static const u16 gUnknown_83CEA10[] = INCBIN_U16("graphics/interface/pss_unk_83CEA10.gbapal");
+
+static const struct WindowTemplate gUnknown_83CEA30[] = {
+ {
+ .bg = 1,
+ .tilemapLeft = 0,
+ .tilemapTop = 11,
+ .width = 9,
+ .height = 7,
+ .paletteNum = 3,
+ .baseBlock = 0x0c0
+ }, {
+ .bg = 0,
+ .tilemapLeft = 11,
+ .tilemapTop = 17,
+ .width = 18,
+ .height = 2,
+ .paletteNum = 13,
+ .baseBlock = 0x014
+ }, {
+ .bg = 0,
+ .tilemapLeft = 0,
+ .tilemapTop = 12,
+ .width = 25,
+ .height = 8,
+ .paletteNum = 15,
+ .baseBlock = 0x014
+ }, DUMMY_WIN_TEMPLATE
+};
+
+static const struct BgTemplate gUnknown_83CEA50[] = {
+ {
+ .bg = 0,
+ .charBaseIndex = 0,
+ .mapBaseIndex = 29,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 0,
+ .baseTile = 0x000
+ }, {
+ .bg = 1,
+ .charBaseIndex = 1,
+ .mapBaseIndex = 30,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 1,
+ .baseTile = 0x100
+ }, {
+ .bg = 2,
+ .charBaseIndex = 2,
+ .mapBaseIndex = 27,
+ .screenSize = 1,
+ .paletteMode = 0,
+ .priority = 2,
+ .baseTile = 0x000
+ }, {
+ .bg = 3,
+ .charBaseIndex = 3,
+ .mapBaseIndex = 31,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 3,
+ .baseTile = 0x000
+ }
+};
+
+static const struct SpritePalette gWaveformSpritePalette = {
+ gUnknown_83CE7F0, TAG_PAL_WAVEFORM
+};
+
+static const struct SpriteSheet gWaveformSpriteSheet = {
+ gUnknown_83CE810, 0x01c0, TAG_TILE_WAVEFORM
+};
+
+static const struct OamData gUnknown_83CEB88;
+
+static const struct SpriteTemplate sSpriteTemplate_CursorMon = {
+ .tileTag = TAG_TILE_2,
+ .paletteTag = TAG_PAL_DAC6,
+ .oam = &gUnknown_83CEB88,
+ .anims = gDummySpriteAnimTable,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCallbackDummy
+};
+
+static const struct StorageAction gPCStorageActionTexts[] = {
+ [PC_TEXT_EXIT_BOX] = {gText_ExitFromBox, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_PICK_A_THEME] = {gText_PleasePickATheme, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_IS_SELECTED] = {gText_PkmnIsSelected, PC_TEXT_FMT_MON_NAME_1},
+ [PC_TEXT_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_WAS_DEPOSITED] = {gText_PkmnWasDeposited, PC_TEXT_FMT_MON_NAME_1},
+ [PC_TEXT_BOX_IS_FULL] = {gText_BoxIsFull2, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_RELEASE_POKE] = {gText_ReleaseThisPokemon, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_WAS_RELEASED] = {gText_PkmnWasReleased, PC_TEXT_FMT_MON_NAME_4},
+ [PC_TEXT_BYE_BYE] = {gText_ByeByePkmn, PC_TEXT_FMT_MON_NAME_6},
+ [PC_TEXT_MARK_POKE] = {gText_MarkYourPkmn, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_LAST_POKE] = {gText_ThatsYourLastPkmn, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_PARTY_FULL] = {gText_YourPartysFull, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_HOLDING_POKE] = {gText_YoureHoldingAPkmn, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_CONTINUE_BOX] = {gText_ContinueBoxOperations, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_CAME_BACK] = {gText_PkmnCameBack, PC_TEXT_FMT_MON_NAME_1},
+ [PC_TEXT_WORRIED] = {gText_WasItWorriedAboutYou, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_SURPRISE] = {gText_FourEllipsesExclamation, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_IS_SELECTED2] = {gText_PkmnIsSelected, PC_TEXT_FMT_ITEM_NAME},
+ [PC_TEXT_GIVE_TO_MON] = {gText_GiveToAPkmn, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_PLACED_IN_BAG] = {gText_PlacedItemInBag, PC_TEXT_FMT_ITEM_NAME},
+ [PC_TEXT_BAG_FULL] = {gText_BagIsFull2, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_PUT_IN_BAG] = {gText_PutItemInBag, PC_TEXT_FMT_NORMAL},
+ [PC_TEXT_ITEM_IS_HELD] = {gText_ItemIsNowHeld, PC_TEXT_FMT_ITEM_NAME},
+ [PC_TEXT_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, PC_TEXT_FMT_ITEM_NAME},
+ [PC_TEXT_CANT_STORE_MAIL] = {gText_MailCantBeStored, PC_TEXT_FMT_NORMAL},
+};
+
+// Yes/No menu
+static const struct WindowTemplate sYesNoWindowTemplate = {
+ .bg = 0,
+ .tilemapLeft = 24,
+ .tilemapTop = 11,
+ .width = 5,
+ .height = 4,
+ .paletteNum = 15,
+ .baseBlock = 0x05c
+};
+
+static const struct OamData gUnknown_83CEB88 = {
+ .y = 0,
+ .affineMode = ST_OAM_AFFINE_OFF,
+ .objMode = ST_OAM_OBJ_NORMAL,
+ .mosaic = FALSE,
+ .bpp = ST_OAM_4BPP,
+ .shape = SPRITE_SHAPE(64x64),
+ .x = 0,
+ .matrixNum = 0,
+ .size = SPRITE_SIZE(64x64),
+ .tileNum = 0x000,
+ .priority = 0,
+ .paletteNum = 0
+};
+
+// Waveform
+
+static const struct OamData gUnknown_83CEB90 = {
+ .y = 0,
+ .affineMode = ST_OAM_AFFINE_OFF,
+ .objMode = ST_OAM_OBJ_NORMAL,
+ .mosaic = FALSE,
+ .bpp = ST_OAM_4BPP,
+ .shape = SPRITE_SHAPE(16x8),
+ .x = 0,
+ .matrixNum = 0,
+ .size = SPRITE_SIZE(16x8),
+ .tileNum = 0x000,
+ .priority = 0,
+ .paletteNum = 0
+};
+
+static const union AnimCmd gUnknown_83CEB98[] = {
+ ANIMCMD_FRAME(0, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83CEBA0[] = {
+ ANIMCMD_FRAME(2, 8),
+ ANIMCMD_FRAME(4, 8),
+ ANIMCMD_FRAME(6, 8),
+ ANIMCMD_JUMP(0)
+};
+
+static const union AnimCmd gUnknown_83CEBB0[] = {
+ ANIMCMD_FRAME(8, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83CEBB8[] = {
+ ANIMCMD_FRAME(10, 8),
+ ANIMCMD_FRAME(4, 8),
+ ANIMCMD_FRAME(12, 8),
+ ANIMCMD_JUMP(0)
+};
+
+static const union AnimCmd *const gUnknown_83CEBC8[] = {
+ gUnknown_83CEB98,
+ gUnknown_83CEBA0,
+ gUnknown_83CEBB0,
+ gUnknown_83CEBB8
+};
+
+static const struct SpriteTemplate sSpriteTemplate_Waveform = {
+ .tileTag = TAG_TILE_WAVEFORM,
+ .paletteTag = TAG_PAL_WAVEFORM,
+ .oam = &gUnknown_83CEB90,
+ .anims = gUnknown_83CEBC8,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCallbackDummy,
+};
+
+static void VblankCb_PSS(void)
+{
+ LoadOam();
+ ProcessSpriteCopyRequests();
+ sub_8096BF8();
+ TransferPlttBuffer();
+ SetGpuReg(REG_OFFSET_BG2HOFS, sPSSData->bg2_X);
+}
+
+static void Cb2_PSS(void)
+{
+ RunTasks();
+ DoScheduledBgTilemapCopiesToVram();
+ ScrollBackground();
+ sub_808F99C();
+ AnimateSprites();
+ BuildOamBuffer();
+}
+
+void Cb2_EnterPSS(u8 boxOption)
+{
+ ResetTasks();
+ sCurrentBoxOption = boxOption;
+ sPSSData = Alloc(sizeof(struct PokemonStorageSystemData));
+ if (sPSSData == NULL)
+ SetMainCallback2(Cb2_ExitPSS);
+ else
+ {
+ sPSSData->boxOption = boxOption;
+ sPSSData->isReshowingPSS = FALSE;
+ gUnknown_20397BA = 0;
+ sPSSData->state = 0;
+ sPSSData->taskId = CreateTask(Cb_InitPSS, 3);
+ SetHelpContext(HELPCONTEXT_BILLS_PC);
+ sLastUsedBox = StorageGetCurrentBox();
+ SetMainCallback2(Cb2_PSS);
+ }
+}
+
+void Cb2_ReturnToPSS(void)
+{
+ ResetTasks();
+ sPSSData = Alloc(sizeof(struct PokemonStorageSystemData));
+ if (sPSSData == NULL)
+ SetMainCallback2(Cb2_ExitPSS);
+ else
+ {
+ sPSSData->boxOption = sCurrentBoxOption;
+ sPSSData->isReshowingPSS = TRUE;
+ sPSSData->state = 0;
+ sPSSData->taskId = CreateTask(Cb_InitPSS, 3);
+ SetHelpContext(HELPCONTEXT_BILLS_PC);
+ SetMainCallback2(Cb2_PSS);
+ }
+}
+
+static void ResetAllBgCoords(void)
+{
+ SetGpuReg(REG_OFFSET_BG0HOFS, 0);
+ SetGpuReg(REG_OFFSET_BG0VOFS, 0);
+ SetGpuReg(REG_OFFSET_BG1HOFS, 0);
+ SetGpuReg(REG_OFFSET_BG1VOFS, 0);
+ SetGpuReg(REG_OFFSET_BG2HOFS, 0);
+ SetGpuReg(REG_OFFSET_BG2VOFS, 0);
+ SetGpuReg(REG_OFFSET_BG3HOFS, 0);
+ SetGpuReg(REG_OFFSET_BG3VOFS, 0);
+}
+
+static void sub_808CF10(void)
+{
+ ResetPaletteFade();
+ ResetSpriteData();
+ FreeSpriteTileRanges();
+ FreeAllSpritePalettes();
+ ClearDma3Requests();
+ gReservedSpriteTileCount = 0x280;
+ sub_8096BE4(&sPSSData->unk_0020, sPSSData->unk_0028, 8);
+ gKeyRepeatStartDelay = 20;
+ ClearScheduledBgCopiesToVram();
+ AllocBoxPartyPokemonDropdowns(3);
+ SetBoxPartyPokemonDropdownMap2(0, 1, gUnknown_83CE6F8, 8, 4);
+ SetBoxPartyPokemonDropdownMap2Pos(0, 1, 0);
+ sPSSData->unk_02C7 = FALSE;
+}
+
+static void sub_808CF94(void)
+{
+ sub_8092B50();
+ sInPartyMenu = sPSSData->boxOption == BOX_OPTION_DEPOSIT;
+ gUnknown_20397B6 = 0;
+}
+
+static void sub_808CFC4(void)
+{
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL);
+ SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(7, 11));
+ }
+ SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_1D_MAP);
+}
+
+static void SetPSSCallback(TaskFunc newFunc)
+{
+ gTasks[sPSSData->taskId].func = newFunc;
+ sPSSData->state = 0;
+}
+
+static void Cb_InitPSS(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ SetVBlankCallback(NULL);
+ SetGpuReg(REG_OFFSET_DISPCNT, 0);
+ sub_808CF10();
+ if (sPSSData->isReshowingPSS)
+ {
+ switch (sWhichToReshow)
+ {
+ case 1:
+ sub_8093660();
+ break;
+ case 0:
+ sub_80937B4();
+ break;
+ case 2:
+ GiveChosenBagItem();
+ break;
+ }
+ }
+ LoadPSSMenuGfx();
+ LoadWaveformSpritePalette();
+ break;
+ case 1:
+ if (!InitPSSWindows())
+ {
+ SetPSSCallback(Cb_ChangeScreen);
+ return;
+ }
+ break;
+ case 2:
+ PutWindowTilemap(0);
+ ClearWindowTilemap(1);
+ CpuFill32(0, (void *)VRAM, 0x200);
+ TextWindow_SetUserSelectedFrame(1, 0xB, 0xE0);
+ break;
+ case 3:
+ ResetAllBgCoords();
+ if (!sPSSData->isReshowingPSS)
+ sub_808CF94();
+ break;
+ case 4:
+ sub_808FFAC();
+ if (!sPSSData->isReshowingPSS)
+ sub_80922C0();
+ else
+ sub_8092340();
+ break;
+ case 5:
+ if (!sub_8095050())
+ {
+ SetPSSCallback(Cb_ChangeScreen);
+ return;
+ }
+ else
+ {
+ SetScrollingBackground();
+ sub_808FB68();
+ }
+ break;
+ case 6:
+ sub_808F078();
+ break;
+ case 7:
+ sub_808F68C();
+ break;
+ case 8:
+ sub_80913DC(StorageGetCurrentBox());
+ break;
+ case 9:
+ if (sub_809140C())
+ return;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ sPSSData->field_DA4.baseTileTag = TAG_TILE_D;
+ sPSSData->field_DA4.basePaletteTag = TAG_PAL_DACE;
+ SetMonMarkingsMenuPointer(&sPSSData->field_DA4);
+ LoadMonMarkingsFrameGfx();
+ }
+ else
+ {
+ sub_8095B5C();
+ sub_808FDFC();
+ }
+ break;
+ case 10:
+ sub_808CFC4();
+ if (!sPSSData->isReshowingPSS)
+ {
+ BlendPalettes(0xFFFFFFFF, 0x10, RGB_BLACK);
+ SetPSSCallback(Cb_ShowPSS);
+ }
+ else
+ {
+ BlendPalettes(0xFFFFFFFF, 0x10, RGB_BLACK);
+ SetPSSCallback(Cb_ReshowPSS);
+ }
+ SetVBlankCallback(VblankCb_PSS);
+ return;
+ default:
+ return;
+ }
+
+ sPSSData->state++;
+}
+
+static void Cb_ShowPSS(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PlaySE(SE_PC_LOGIN);
+ sub_80A0A48(0x14, 0, 1);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!sub_80A0A98())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_ReshowPSS(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ BeginNormalPaletteFade(0xFFFFFFFF, -1, 0x10, 0, RGB_BLACK);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!UpdatePaletteFade())
+ {
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_MainPSS(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ switch (HandleInput())
+ {
+ case 1:
+ PlaySE(SE_SELECT);
+ sPSSData->state = 1;
+ break;
+ case 5:
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_MONS && sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ PrintStorageActionText(PC_TEXT_WHICH_ONE_WILL_TAKE);
+ sPSSData->state = 3;
+ }
+ else
+ {
+ sub_8092B50();
+ SetPSSCallback(Cb_ShowPartyPokemon);
+ }
+ break;
+ case 6:
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_MONS)
+ {
+ if (IsMonBeingMoved() && ItemIsMail(sPSSData->cursorMonItem))
+ sPSSData->state = 5;
+ else
+ SetPSSCallback(Cb_HidePartyPokemon);
+ }
+ else if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ SetPSSCallback(Cb_HidePartyPokemon);
+ }
+ break;
+ case 4:
+ SetPSSCallback(Cb_OnCloseBoxPressed);
+ break;
+ case 19:
+ SetPSSCallback(Cb_OnBPressed);
+ break;
+ case 7:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_HandleBoxOptions);
+ break;
+ case 8:
+ SetPSSCallback(Cb_OnSelectedMon);
+ break;
+ case 9:
+ PlaySE(SE_SELECT);
+ sPSSData->newCurrBoxId = StorageGetCurrentBox() + 1;
+ if (sPSSData->newCurrBoxId >= TOTAL_BOXES_COUNT)
+ sPSSData->newCurrBoxId = 0;
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ SetUpScrollToBox(sPSSData->newCurrBoxId);
+ sPSSData->state = 2;
+ }
+ else
+ {
+ sub_8094D60();
+ sPSSData->state = 10;
+ }
+ break;
+ case 10:
+ PlaySE(SE_SELECT);
+ sPSSData->newCurrBoxId = StorageGetCurrentBox() - 1;
+ if (sPSSData->newCurrBoxId < 0)
+ sPSSData->newCurrBoxId = TOTAL_BOXES_COUNT - 1;
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ SetUpScrollToBox(sPSSData->newCurrBoxId);
+ sPSSData->state = 2;
+ }
+ else
+ {
+ sub_8094D60();
+ sPSSData->state = 10;
+ }
+ break;
+ case 11:
+ if (!CanMovePartyMon())
+ {
+ if (ItemIsMail(sPSSData->cursorMonItem))
+ {
+ sPSSData->state = 5;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_DepositMenu);
+ }
+ }
+ else
+ {
+ sPSSData->state = 4;
+ }
+ break;
+ case 13:
+ if (CanMovePartyMon())
+ {
+ sPSSData->state = 4;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_MoveMon);
+ }
+ break;
+ case 14:
+ if (!CanShiftMon())
+ {
+ sPSSData->state = 4;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_ShiftMon);
+ }
+ break;
+ case 12:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_WithdrawMon);
+ break;
+ case 15:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_PlaceMon);
+ break;
+ case 16:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_TakeItemForMoving);
+ break;
+ case 17:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_GiveMovingItemToMon);
+ break;
+ case 18:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_SwitchSelectedItem);
+ break;
+ case 20:
+ PlaySE(SE_SELECT);
+ sub_80950BC(0);
+ sPSSData->state = 7;
+ break;
+ case 22:
+ sub_80950BC(1);
+ sPSSData->state = 8;
+ break;
+ case 21:
+ PlaySE(SE_SELECT);
+ sub_80950BC(2);
+ sPSSData->state = 9;
+ break;
+ case 23:
+ sub_80950BC(3);
+ sPSSData->state = 7;
+ break;
+ case 25:
+ PlaySE(SE_SELECT);
+ sub_80950BC(4);
+ sPSSData->state = 9;
+ break;
+ case 26:
+ PlaySE(SE_SELECT);
+ sub_808FE54(3);
+ sub_80950BC(5);
+ sPSSData->state = 7;
+ break;
+ case 24:
+ PlaySE(SE_HAZURE);
+ break;
+ }
+ break;
+ case 1:
+ if (!sub_80924A8())
+ {
+ if (IsCursorOnCloseBox())
+ sub_808F948();
+ else
+ sub_808F974();
+
+ if (sPSSData->setMosaic)
+ BoxSetMosaic();
+ sPSSData->state = 0;
+ }
+ break;
+ case 2:
+ if (!ScrollToBox())
+ {
+ SetCurrentBox(sPSSData->newCurrBoxId);
+ if (!sInPartyMenu && !IsMonBeingMoved())
+ {
+ sub_8092F54();
+ BoxSetMosaic();
+ }
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ sub_8094D84();
+ sPSSData->state = 11;
+ }
+ else
+ {
+ sPSSData->state = 0;
+ }
+ }
+ break;
+ case 3:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sPSSData->state = 0;
+ }
+ break;
+ case 4:
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_LAST_POKE);
+ sPSSData->state = 6;
+ break;
+ case 5:
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL);
+ sPSSData->state = 6;
+ break;
+ case 6:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ case 7:
+ if (!sub_80950D0())
+ sPSSData->state = 0;
+ break;
+ case 8:
+ if (!sub_80950D0())
+ SetPSSCallback(Cb_MoveMon);
+ break;
+ case 9:
+ if (!sub_80950D0())
+ {
+ if (sPSSData->setMosaic)
+ BoxSetMosaic();
+ sPSSData->state = 0;
+ }
+ break;
+ case 10:
+ if (!sub_809610C())
+ {
+ SetUpScrollToBox(sPSSData->newCurrBoxId);
+ sPSSData->state = 2;
+ }
+ break;
+ case 11:
+ if (!sub_809610C())
+ sPSSData->state = 0;
+ break;
+ }
+}
+
+static void Cb_ShowPartyPokemon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ SetUpDoShowPartyMenu();
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!DoShowPartyMenu())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_HidePartyPokemon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PlaySE(SE_SELECT);
+ SetUpHidePartyMenu();
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!HidePartyMenu())
+ {
+ sub_8092B3C(sub_8092B70());
+ sPSSData->state++;
+ }
+ break;
+ case 2:
+ if (!sub_80924A8())
+ {
+ if (sPSSData->setMosaic)
+ BoxSetMosaic();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_OnSelectedMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (!BoxGetMosaic())
+ {
+ PlaySE(SE_SELECT);
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ PrintStorageActionText(PC_TEXT_IS_SELECTED);
+ else if (IsActiveItemMoving() || sPSSData->cursorMonItem != 0)
+ PrintStorageActionText(PC_TEXT_IS_SELECTED2);
+ else
+ PrintStorageActionText(PC_TEXT_GIVE_TO_MON);
+
+ AddMenu();
+ sPSSData->state = 1;
+ }
+ break;
+ case 1: // debug?
+ if (!sub_8094F90())
+ sPSSData->state = 2;
+ break;
+ case 2:
+ switch (sub_8094F94())
+ {
+ case -1:
+ case 0:
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 3:
+ if (CanMovePartyMon())
+ {
+ sPSSData->state = 3;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MoveMon);
+ }
+ break;
+ case 5:
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_PlaceMon);
+ break;
+ case 4:
+ if (!CanShiftMon())
+ {
+ sPSSData->state = 3;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_ShiftMon);
+ }
+ break;
+ case 2:
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_WithdrawMon);
+ break;
+ case 1:
+ if (CanMovePartyMon())
+ {
+ sPSSData->state = 3;
+ }
+ else if (ItemIsMail(sPSSData->cursorMonItem))
+ {
+ sPSSData->state = 4;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_DepositMenu);
+ }
+ break;
+ case 7:
+ if (CanMovePartyMon())
+ {
+ sPSSData->state = 3;
+ }
+ else if (sPSSData->cursorMonIsEgg)
+ {
+ sPSSData->state = 5; // Cannot release an Egg.
+ }
+ else if (ItemIsMail(sPSSData->cursorMonItem))
+ {
+ sPSSData->state = 4;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_ReleaseMon);
+ }
+ break;
+ case 6:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_ShowMonSummary);
+ break;
+ case 8:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_ShowMarkMenu);
+ break;
+ case 12:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_TakeItemForMoving);
+ break;
+ case 13:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_GiveMovingItemToMon);
+ break;
+ case 16:
+ SetPSSCallback(Cb_ItemToBag);
+ break;
+ case 15:
+ SetPSSCallback(Cb_SwitchSelectedItem);
+ break;
+ case 14:
+ SetPSSCallback(Cb_GiveItemFromBag);
+ break;
+ case 17:
+ SetPSSCallback(Cb_ShowItemInfo);
+ break;
+ }
+ break;
+ case 3:
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_LAST_POKE);
+ sPSSData->state = 6;
+ break;
+ case 5:
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_CANT_RELEASE_EGG);
+ sPSSData->state = 6;
+ break;
+ case 4:
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL);
+ sPSSData->state = 6;
+ break;
+ case 6:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_MoveMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ InitMonPlaceChange(0);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!DoMonPlaceChange())
+ {
+ if (sInPartyMenu)
+ SetPSSCallback(Cb_HandleMovingMonFromParty);
+ else
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_PlaceMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ sub_808FE54(1);
+ InitMonPlaceChange(1);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!DoMonPlaceChange())
+ {
+ if (sInPartyMenu)
+ SetPSSCallback(Cb_HandleMovingMonFromParty);
+ else
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_ShiftMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ sub_808FE54(0);
+ InitMonPlaceChange(2);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!DoMonPlaceChange())
+ {
+ BoxSetMosaic();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_WithdrawMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (CalculatePlayerPartyCount() == PARTY_SIZE)
+ {
+ PrintStorageActionText(PC_TEXT_PARTY_FULL);
+ sPSSData->state = 1;
+ }
+ else
+ {
+ sub_8092B5C();
+ InitMonPlaceChange(0);
+ sPSSData->state = 2;
+ }
+ break;
+ case 1:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ case 2:
+ if (!DoMonPlaceChange())
+ {
+ SetMovingMonPriority(1);
+ SetUpDoShowPartyMenu();
+ sPSSData->state++;
+ }
+ break;
+ case 3:
+ if (!DoShowPartyMenu())
+ {
+ sub_808FE54(1);
+ InitMonPlaceChange(1);
+ sPSSData->state++;
+ }
+ break;
+ case 4:
+ if (!DoMonPlaceChange())
+ {
+ sub_808FAA8();
+ sPSSData->state++;
+ }
+ break;
+ case 5:
+ SetPSSCallback(Cb_HidePartyPokemon);
+ break;
+ }
+}
+
+static void Cb_DepositMenu(u8 taskId)
+{
+ u8 boxId;
+
+ switch (sPSSData->state)
+ {
+ case 0:
+ PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX);
+ LoadBoxSelectionPopupSpriteGfx(&sPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE);
+ sub_808C940(gUnknown_20397B6);
+ sPSSData->state++;
+ break;
+ case 1:
+ boxId = HandleBoxChooseSelectionInput();
+ if (boxId == 200)
+ {
+ // no box chosen yet
+ }
+ else if (boxId == 201)
+ {
+ ClearBottomWindow();
+ sub_808C950();
+ FreeBoxSelectionPopupSpriteGfx();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ else
+ {
+ if (TryStorePartyMonInBox(boxId))
+ {
+ gUnknown_20397B6 = boxId;
+ sub_808FE54(2);
+ ClearBottomWindow();
+ sub_808C950();
+ FreeBoxSelectionPopupSpriteGfx();
+ sPSSData->state = 2;
+ }
+ else
+ {
+ PrintStorageActionText(PC_TEXT_BOX_IS_FULL);
+ sPSSData->state = 4;
+ }
+ }
+ break;
+ case 2:
+ CompactPartySlots();
+ sub_80909F4();
+ sPSSData->state++;
+ break;
+ case 3:
+ if (!sub_8090A60())
+ {
+ sub_8093174();
+ BoxSetMosaic();
+ sub_808FAA8();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ case 4:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX);
+ sPSSData->state = 1;
+ }
+ break;
+ }
+}
+
+static void Cb_ReleaseMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PrintStorageActionText(PC_TEXT_RELEASE_POKE);
+ ShowYesNoWindow(1);
+ sPSSData->state++;
+ // fallthrough
+ case 1:
+ switch (Menu_ProcessInputNoWrapClearOnChoose())
+ {
+ case MENU_B_PRESSED:
+ case 1:
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 0:
+ ClearBottomWindow();
+ InitCanReleaseMonVars();
+ sub_8093194();
+ sPSSData->state++;
+ break;
+ }
+ break;
+ case 2:
+ RunCanReleaseMon();
+ if (!sub_80931EC())
+ {
+ while (1)
+ {
+ s8 r0 = RunCanReleaseMon();
+ if (r0 == 1)
+ {
+ sPSSData->state++;
+ break;
+ }
+ else if (r0 == 0)
+ {
+ sPSSData->state = 8; // Can't release the mon.
+ break;
+ }
+ }
+ }
+ break;
+ case 3:
+ ReleaseMon();
+ RefreshCursorMonData();
+ PrintStorageActionText(PC_TEXT_WAS_RELEASED);
+ sPSSData->state++;
+ break;
+ case 4:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ PrintStorageActionText(PC_TEXT_BYE_BYE);
+ sPSSData->state++;
+ }
+ break;
+ case 5:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ if (sInPartyMenu)
+ {
+ CompactPartySlots();
+ sub_80909F4();
+ sPSSData->state++;
+ }
+ else
+ {
+ sPSSData->state = 7;
+ }
+ }
+ break;
+ case 6:
+ if (!sub_8090A60())
+ {
+ sub_8092F54();
+ BoxSetMosaic();
+ sub_808FAA8();
+ sPSSData->state++;
+ }
+ break;
+ case 7:
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 8:
+ PrintStorageActionText(PC_TEXT_WAS_RELEASED);
+ sPSSData->state++;
+ break;
+ case 9:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ PrintStorageActionText(PC_TEXT_SURPRISE);
+ sPSSData->state++;
+ }
+ break;
+ case 10:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sub_8091114();
+ sPSSData->state++;
+ }
+ break;
+ case 11:
+ if (!sub_8091150())
+ {
+ sub_8093264();
+ PrintStorageActionText(PC_TEXT_CAME_BACK);
+ sPSSData->state++;
+ }
+ break;
+ case 12:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ PrintStorageActionText(PC_TEXT_WORRIED);
+ sPSSData->state++;
+ }
+ break;
+ case 13:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_ShowMarkMenu(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PrintStorageActionText(PC_TEXT_MARK_POKE);
+ sPSSData->field_DA4.markings = sPSSData->cursorMonMarkings;
+ DrawMonMarkingsMenu(sPSSData->cursorMonMarkings, 0xb0, 0x10);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!MonMarkingsHandleInput())
+ {
+ TeardownMonMarkingsMenu();
+ ClearBottomWindow();
+ SetMonMarkings(sPSSData->field_DA4.markings);
+ RefreshCursorMonData();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_TakeItemForMoving(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (!ItemIsMail(sPSSData->cursorMonItem))
+ {
+ ClearBottomWindow();
+ sPSSData->state++;
+ }
+ else
+ {
+ SetPSSCallback(Cb_PrintCantStoreMail);
+ }
+ break;
+ case 1:
+ sub_8094D14(2);
+ Item_FromMonToMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition());
+ sPSSData->state++;
+ break;
+ case 2:
+ if (!sub_809610C())
+ {
+ sub_8094D14(3);
+ ClearBottomWindow();
+ sub_8092F54();
+ PrintCursorMonInfo();
+ sPSSData->state++;
+ }
+ break;
+ case 3:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_GiveMovingItemToMon(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ ClearBottomWindow();
+ sPSSData->state++;
+ break;
+ case 1:
+ sub_8094D14(2);
+ Item_GiveMovingToMon((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition());
+ sPSSData->state++;
+ break;
+ case 2:
+ if (!sub_809610C())
+ {
+ sub_8094D14(0);
+ sub_8092F54();
+ PrintCursorMonInfo();
+ PrintStorageActionText(PC_TEXT_ITEM_IS_HELD);
+ sPSSData->state++;
+ }
+ break;
+ case 3:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sPSSData->state++;
+ }
+ break;
+ case 4:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_ItemToBag(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (!AddBagItem(sPSSData->cursorMonItem, 1))
+ {
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_BAG_FULL);
+ sPSSData->state = 3;
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ Item_TakeMons((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition());
+ sPSSData->state = 1;
+ }
+ break;
+ case 1:
+ if (!sub_809610C())
+ {
+ PrintStorageActionText(PC_TEXT_PLACED_IN_BAG);
+ sPSSData->state = 2;
+ }
+ break;
+ case 2:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sub_8092F54();
+ PrintCursorMonInfo();
+ sPSSData->state = 4;
+ }
+ break;
+ case 4:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 3:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_SwitchSelectedItem(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (!ItemIsMail(sPSSData->cursorMonItem))
+ {
+ ClearBottomWindow();
+ sPSSData->state++;
+ }
+ else
+ {
+ SetPSSCallback(Cb_PrintCantStoreMail);
+ }
+ break;
+ case 1:
+ sub_8094D14(2);
+ Item_SwitchMonsWithMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition());
+ sPSSData->state++;
+ break;
+ case 2:
+ if (!sub_809610C())
+ {
+ sub_8094D14(3);
+ sub_8092F54();
+ PrintCursorMonInfo();
+ PrintStorageActionText(PC_TEXT_CHANGED_TO_ITEM);
+ sPSSData->state++;
+ }
+ break;
+ case 3:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sPSSData->state++;
+ }
+ break;
+ case 4:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_ShowItemInfo(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ ClearBottomWindow();
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ {
+ PlaySE(SE_WIN_OPEN);
+ PrintItemDescription();
+ sub_80966F4();
+ sPSSData->state++;
+ }
+ break;
+ case 2:
+ if (!sub_8096728())
+ sPSSData->state++;
+ break;
+ case 3:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ sPSSData->state++;
+ break;
+ case 4:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ PlaySE(SE_WIN_OPEN);
+ sPSSData->state++;
+ }
+ break;
+ case 5:
+ if (!sub_80967C0())
+ sPSSData->state++;
+ break;
+ case 6:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_CloseBoxWhileHoldingItem(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PlaySE(SE_SELECT);
+ PrintStorageActionText(PC_TEXT_PUT_IN_BAG);
+ ShowYesNoWindow(0);
+ sPSSData->state = 1;
+ break;
+ case 1:
+ switch (Menu_ProcessInputNoWrapClearOnChoose())
+ {
+ case MENU_B_PRESSED:
+ case 1:
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 0:
+ if (AddBagItem(sPSSData->movingItem, 1) == TRUE)
+ {
+ ClearBottomWindow();
+ sPSSData->state = 3;
+ }
+ else
+ {
+ PrintStorageActionText(PC_TEXT_BAG_FULL);
+ sPSSData->state = 2;
+ }
+ break;
+ }
+ break;
+ case 2:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sPSSData->state = 5;
+ }
+ break;
+ case 3:
+ sub_8096088();
+ sPSSData->state = 4;
+ break;
+ case 4:
+ if (!sub_809610C())
+ {
+ sub_8094D14(0);
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ case 5:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_HandleMovingMonFromParty(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ CompactPartySlots();
+ sub_80909F4();
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!sub_8090A60())
+ {
+ sub_808FAA8();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_PrintCantStoreMail(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PrintStorageActionText(PC_TEXT_CANT_STORE_MAIL);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ sPSSData->state++;
+ break;
+ case 2:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ sPSSData->state++;
+ }
+ break;
+ case 3:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ }
+}
+
+static void Cb_HandleBoxOptions(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PrintStorageActionText(PC_TEXT_WHAT_YOU_DO);
+ AddMenu();
+ sPSSData->state++;
+ break;
+ case 1:
+ if (sub_8094F90())
+ return;
+ sPSSData->state++;
+ case 2:
+ switch (sub_8094F94())
+ {
+ case -1:
+ case 0:
+ sub_80920FC(TRUE);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 11:
+ PlaySE(SE_SELECT);
+ SetPSSCallback(Cb_NameBox);
+ break;
+ case 10:
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_HandleWallpapers);
+ break;
+ case 9:
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_JumpBox);
+ break;
+ }
+ break;
+ }
+}
+
+static void Cb_HandleWallpapers(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ AddWallpaperSetsMenu();
+ PrintStorageActionText(PC_TEXT_PICK_A_THEME);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!sub_8094F90())
+ sPSSData->state++;
+ break;
+ case 2:
+ sPSSData->wallpaperSetId = sub_8094F94();
+ switch (sPSSData->wallpaperSetId)
+ {
+ case -1:
+ sub_80920FC(TRUE);
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 18 ... 21:
+ PlaySE(SE_SELECT);
+ sub_8095024();
+ sPSSData->wallpaperSetId -= 18;
+ sPSSData->state++;
+ break;
+ }
+ break;
+ case 3:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ {
+ AddWallpapersMenu(sPSSData->wallpaperSetId);
+ PrintStorageActionText(PC_TEXT_PICK_A_WALLPAPER);
+ sPSSData->state++;
+ }
+ break;
+ case 4:
+ sPSSData->wallpaperId = sub_8094F94();
+ switch (sPSSData->wallpaperId)
+ {
+ case MENU_NOTHING_CHOSEN:
+ break;
+ case MENU_B_PRESSED:
+ ClearBottomWindow();
+ sPSSData->state = 0;
+ break;
+ default:
+ PlaySE(SE_SELECT);
+ ClearBottomWindow();
+ sPSSData->wallpaperId -= 22;
+ SetWallpaperForCurrentBox(sPSSData->wallpaperId);
+ sPSSData->state++;
+ break;
+ }
+ break;
+ case 5:
+ if (!DoWallpaperGfxChange())
+ {
+ sub_80920FC(TRUE);
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_JumpBox(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ PrintStorageActionText(PC_TEXT_JUMP_TO_WHICH_BOX);
+ LoadBoxSelectionPopupSpriteGfx(&sPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE);
+ sub_808C940(StorageGetCurrentBox());
+ sPSSData->state++;
+ break;
+ case 1:
+ sPSSData->newCurrBoxId = HandleBoxChooseSelectionInput();
+ switch (sPSSData->newCurrBoxId)
+ {
+ case 200:
+ break;
+ default:
+ ClearBottomWindow();
+ sub_808C950();
+ FreeBoxSelectionPopupSpriteGfx();
+ if (sPSSData->newCurrBoxId == 201 || sPSSData->newCurrBoxId == StorageGetCurrentBox())
+ {
+ sub_80920FC(TRUE);
+ SetPSSCallback(Cb_MainPSS);
+ }
+ else
+ {
+ sPSSData->state++;
+ }
+ break;
+ }
+ break;
+ case 2:
+ SetUpScrollToBox(sPSSData->newCurrBoxId);
+ sPSSData->state++;
+ break;
+ case 3:
+ if (!ScrollToBox())
+ {
+ SetCurrentBox(sPSSData->newCurrBoxId);
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ }
+}
+
+static void Cb_NameBox(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ sub_8093630();
+ BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!UpdatePaletteFade())
+ {
+ sWhichToReshow = 1;
+ sPSSData->screenChangeType = SCREEN_CHANGE_NAME_BOX;
+ SetPSSCallback(Cb_ChangeScreen);
+ }
+ break;
+ }
+}
+
+static void Cb_ShowMonSummary(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ sub_80936B8();
+ BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!UpdatePaletteFade())
+ {
+ sWhichToReshow = 0;
+ sPSSData->screenChangeType = SCREEN_CHANGE_SUMMARY_SCREEN;
+ SetPSSCallback(Cb_ChangeScreen);
+ }
+ break;
+ }
+}
+
+static void Cb_GiveItemFromBag(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
+ sPSSData->state++;
+ break;
+ case 1:
+ if (!UpdatePaletteFade())
+ {
+ sWhichToReshow = 2;
+ sPSSData->screenChangeType = SCREEN_CHANGE_ITEM_FROM_BAG;
+ SetPSSCallback(Cb_ChangeScreen);
+ }
+ break;
+ }
+}
+
+static void Cb_OnCloseBoxPressed(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (IsMonBeingMoved())
+ {
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_HOLDING_POKE);
+ sPSSData->state = 1;
+ }
+ else if (IsActiveItemMoving())
+ {
+ SetPSSCallback(Cb_CloseBoxWhileHoldingItem);
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ PrintStorageActionText(PC_TEXT_EXIT_BOX);
+ ShowYesNoWindow(0);
+ sPSSData->state = 2;
+ }
+ break;
+ case 1:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ case 2:
+ switch (Menu_ProcessInputNoWrapClearOnChoose())
+ {
+ case MENU_B_PRESSED:
+ case 1:
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 0:
+ PlaySE(SE_PC_OFF);
+ ClearBottomWindow();
+ sPSSData->state++;
+ break;
+ }
+ break;
+ case 3:
+ sub_80A0A70(0x14, 0, 1);
+ sPSSData->state++;
+ break;
+ case 4:
+ if (!sub_80A0AAC())
+ {
+ sub_808FF70();
+ gPlayerPartyCount = CalculatePlayerPartyCount();
+ sPSSData->screenChangeType = SCREEN_CHANGE_EXIT_BOX;
+ SetPSSCallback(Cb_ChangeScreen);
+ }
+ break;
+ }
+}
+
+static void Cb_OnBPressed(u8 taskId)
+{
+ switch (sPSSData->state)
+ {
+ case 0:
+ if (IsMonBeingMoved())
+ {
+ PlaySE(SE_HAZURE);
+ PrintStorageActionText(PC_TEXT_HOLDING_POKE);
+ sPSSData->state = 1;
+ }
+ else if (IsActiveItemMoving())
+ {
+ SetPSSCallback(Cb_CloseBoxWhileHoldingItem);
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ PrintStorageActionText(PC_TEXT_CONTINUE_BOX);
+ ShowYesNoWindow(0);
+ sPSSData->state = 2;
+ }
+ break;
+ case 1:
+ if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY))
+ {
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ }
+ break;
+ case 2:
+ switch (Menu_ProcessInputNoWrapClearOnChoose())
+ {
+ case 0:
+ ClearBottomWindow();
+ SetPSSCallback(Cb_MainPSS);
+ break;
+ case 1:
+ case MENU_B_PRESSED:
+ PlaySE(SE_PC_OFF);
+ ClearBottomWindow();
+ sPSSData->state++;
+ break;
+ }
+ break;
+ case 3:
+ sub_80A0A70(0x14, 0, 0);
+ sPSSData->state++;
+ break;
+ case 4:
+ if (!sub_80A0AAC())
+ {
+ sub_808FF70();
+ gPlayerPartyCount = CalculatePlayerPartyCount();
+ sPSSData->screenChangeType = SCREEN_CHANGE_EXIT_BOX;
+ SetPSSCallback(Cb_ChangeScreen);
+ }
+ break;
+ }
+}
+
+static void Cb_ChangeScreen(u8 taskId)
+{
+ struct Pokemon * partyMon;
+ u8 mode, monIndex, maxMonIndex;
+ u8 screenChangeType = sPSSData->screenChangeType;
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS && IsActiveItemMoving() == TRUE)
+ gUnknown_20397BA = GetMovingItem();
+ else
+ gUnknown_20397BA = ITEM_NONE;
+
+ switch (screenChangeType)
+ {
+ case SCREEN_CHANGE_EXIT_BOX:
+ default:
+ FreePSSData();
+ SetMainCallback2(Cb2_ExitPSS);
+ break;
+ case SCREEN_CHANGE_SUMMARY_SCREEN:
+ partyMon = sPSSData->field_218C.mon;
+ monIndex = sPSSData->field_2187;
+ maxMonIndex = sPSSData->field_2186;
+ mode = sPSSData->field_2188;
+ FreePSSData();
+ ShowPokemonSummaryScreen(partyMon, monIndex, maxMonIndex, Cb2_ReturnToPSS, mode);
+ break;
+ case SCREEN_CHANGE_NAME_BOX:
+ FreePSSData();
+ DoNamingScreen(NAMING_SCREEN_BOX, GetBoxNamePtr(StorageGetCurrentBox()), 0, 0, 0, Cb2_ReturnToPSS);
+ break;
+ case SCREEN_CHANGE_ITEM_FROM_BAG:
+ FreePSSData();
+ GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_ITEMS, Cb2_ReturnToPSS);
+ break;
+ }
+
+ DestroyTask(taskId);
+}
+
+static void GiveChosenBagItem(void)
+{
+ u16 item = gSpecialVar_ItemId;
+
+ if (item != 0)
+ {
+ u8 id = GetBoxCursorPosition();
+
+ if (sInPartyMenu)
+ SetMonData(&gPlayerParty[id], MON_DATA_HELD_ITEM, &item);
+ else
+ SetCurrentBoxMonData(id, MON_DATA_HELD_ITEM, &item);
+
+ RemoveBagItem(item, 1);
+ }
+}
+
+static void FreePSSData(void)
+{
+ FreeBoxPartyPokemonDropdowns();
+ sub_80950A4();
+ FREE_AND_SET_NULL(sPSSData);
+ FreeAllWindowBuffers();
+}
+
+// ******************************************************************
+// Graphics util
+// ******************************************************************
+
+static void SetScrollingBackground(void)
+{
+ SetGpuReg(REG_OFFSET_BG3CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3) | BGCNT_16COLOR | BGCNT_SCREENBASE(31));
+ DecompressAndLoadBgGfxUsingHeap(3, gPokemonStorageScrollingBGTileset, 0, 0, 0);
+ LZ77UnCompVram(gPokemonStorageScrollingBGTilemap, (void *)BG_SCREEN_ADDR(31));
+}
+
+static void ScrollBackground(void)
+{
+ ChangeBgX(3, 128, 1);
+ ChangeBgY(3, 128, 2);
+}
+
+static void LoadPSSMenuGfx(void)
+{
+ InitBgsFromTemplates(0, gUnknown_83CEA50, NELEMS(gUnknown_83CEA50));
+ DecompressAndLoadBgGfxUsingHeap(1, gPSSMenu_Gfx, 0, 0, 0);
+ LZ77UnCompWram(gUnknown_83CE5FC, sPSSData->field_5AC4);
+ SetBgTilemapBuffer(1, sPSSData->field_5AC4);
+ ShowBg(1);
+ ScheduleBgCopyTilemapToVram(1);
+}
+
+static bool8 InitPSSWindows(void)
+{
+ if (!InitWindows(gUnknown_83CEA30))
+ {
+ return FALSE;
+ }
+ else
+ {
+ DeactivateAllTextPrinters();
+ return TRUE;
+ }
+}
+
+static void LoadWaveformSpritePalette(void)
+{
+ LoadSpritePalette(&gWaveformSpritePalette);
+}
+
+static void sub_808F078(void)
+{
+ LoadPalette(gUnknown_8E9C3F8, 0, 0x20);
+ LoadPalette(gUnknown_8E9C418, 0x20, 0x20);
+ LoadPalette(gUnknown_83CEA10, 0xF0, 0x20);
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ LoadPalette(gUnknown_83CE738, 0x30, 0x20);
+ else
+ LoadPalette(gUnknown_83CE758, 0x30, 0x20);
+
+ SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_16COLOR | BGCNT_SCREENBASE(30));
+ LoadCursorMonSprite();
+ sub_808F0F4();
+ sub_808F164();
+ RefreshCursorMonData();
+}
+
+static void sub_808F0F4(void)
+{
+ sPSSData->field_D94 = CreateMonMarkingSprite_AllOff(TAG_TILE_10, TAG_PAL_DAC8, NULL);
+ sPSSData->field_D94->oam.priority = 1;
+ sPSSData->field_D94->subpriority = 1;
+ sPSSData->field_D94->pos1.x = 40;
+ sPSSData->field_D94->pos1.y = 150;
+ sPSSData->field_DA0 = (void *)OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(TAG_TILE_10);
+}
+
+static void sub_808F164(void)
+{
+ u16 i;
+ struct SpriteSheet sheet = gWaveformSpriteSheet;
+
+ LoadSpriteSheet(&sheet);
+ for (i = 0; i < 2; i++)
+ {
+ u8 spriteId = CreateSprite(&sSpriteTemplate_Waveform, i * 63 + 8, 9, 2);
+ sPSSData->field_D98[i] = &gSprites[spriteId];
+ }
+}
+
+static void RefreshCursorMonData(void)
+{
+ LoadCursorMonGfx(sPSSData->cursorMonSpecies, sPSSData->cursorMonPersonality);
+ PrintCursorMonInfo();
+ sub_808F5E8();
+ ScheduleBgCopyTilemapToVram(0);
+}
+
+static void BoxSetMosaic(void)
+{
+ RefreshCursorMonData();
+ if (sPSSData->cursorMonSprite)
+ {
+ sPSSData->cursorMonSprite->oam.mosaic = TRUE;
+ sPSSData->cursorMonSprite->data[0] = 10;
+ sPSSData->cursorMonSprite->data[1] = 1;
+ sPSSData->cursorMonSprite->callback = SpriteCB_CursorMon_Mosaic;
+ SetGpuReg(REG_OFFSET_MOSAIC, (sPSSData->cursorMonSprite->data[0] << 12) | (sPSSData->cursorMonSprite->data[0] << 8));
+ }
+}
+
+static u8 BoxGetMosaic(void)
+{
+ return sPSSData->cursorMonSprite->oam.mosaic;
+}
+
+static void SpriteCB_CursorMon_Mosaic(struct Sprite *sprite)
+{
+ sprite->data[0] -= sprite->data[1];
+ if (sprite->data[0] < 0)
+ sprite->data[0] = 0;
+ SetGpuReg(REG_OFFSET_MOSAIC, (sprite->data[0] << 12) | (sprite->data[0] << 8));
+ if (sprite->data[0] == 0)
+ {
+ sprite->oam.mosaic = FALSE;
+ sprite->callback = SpriteCallbackDummy;
+ }
+}
+
+static void LoadCursorMonSprite(void)
+{
+ u16 i;
+ u16 tileStart;
+ u8 palSlot;
+ u8 spriteId;
+ struct SpriteSheet sheet = {sPSSData->field_22C4, 0x800, TAG_TILE_2};
+ struct SpritePalette palette = {sPSSData->field_2244, TAG_PAL_DAC6};
+ struct SpriteTemplate template = sSpriteTemplate_CursorMon;
+
+ for (i = 0; i < 0x800; i++)
+ sPSSData->field_22C4[i] = 0;
+ for (i = 0; i < 0x10; i++)
+ sPSSData->field_2244[i] = 0;
+
+ sPSSData->cursorMonSprite = NULL;
+
+ do
+ {
+ tileStart = LoadSpriteSheet(&sheet);
+ if (tileStart == 0)
+ break;
+
+ palSlot = LoadSpritePalette(&palette);
+ if (palSlot == 0xFF)
+ break;
+
+ spriteId = CreateSprite(&template, 40, 48, 0);
+ if (spriteId == MAX_SPRITES)
+ break;
+
+ sPSSData->cursorMonSprite = &gSprites[spriteId];
+ sPSSData->field_223A = palSlot * 16 + 0x100;
+ sPSSData->field_223C = (void *)OBJ_VRAM0 + tileStart * 32;
+ } while (0);
+
+ if (sPSSData->cursorMonSprite == NULL)
+ {
+ FreeSpriteTilesByTag(TAG_TILE_2);
+ FreeSpritePaletteByTag(TAG_PAL_DAC6);
+ }
+}
+
+static void LoadCursorMonGfx(u16 species, u32 pid)
+{
+ if (sPSSData->cursorMonSprite == NULL)
+ return;
+
+ if (species != SPECIES_NONE)
+ {
+ HandleLoadSpecialPokePic(&gMonFrontPicTable[species], sPSSData->field_22C4, species, pid);
+ LZ77UnCompWram(sPSSData->cursorMonPalette, sPSSData->field_2244);
+ CpuCopy32(sPSSData->field_22C4, sPSSData->field_223C, 0x800);
+ LoadPalette(sPSSData->field_2244, sPSSData->field_223A, 0x20);
+ sPSSData->cursorMonSprite->invisible = FALSE;
+ }
+ else
+ {
+ sPSSData->cursorMonSprite->invisible = TRUE;
+ }
+}
+
+static void PrintCursorMonInfo(void)
+{
+ u16 i;
+ u16 y;
+ FillWindowPixelBuffer(0, PIXEL_FILL(1));
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ for (i = 0, y = 0; i < 3; i++, y += 14)
+ {
+ AddTextPrinterParameterized(0, 2, sPSSData->cursorMonTexts[i], i == 2 ? 10 : 6, y, TEXT_SPEED_FF, NULL);
+ }
+ AddTextPrinterParameterized(0, 0, sPSSData->cursorMonTexts[3], 6, y + 2, TEXT_SPEED_FF, NULL);
+ }
+ else
+ {
+ AddTextPrinterParameterized(0, 0, sPSSData->cursorMonTexts[3], 6, 0, TEXT_SPEED_FF, NULL);
+ for (i = 0, y = 15; i < 3; i++, y += 14)
+ {
+ AddTextPrinterParameterized(0, 2, sPSSData->cursorMonTexts[i], i == 2 ? 10 : 6, y, TEXT_SPEED_FF, NULL);
+ }
+ }
+
+ CopyWindowToVram(0, 2);
+ if (sPSSData->cursorMonSpecies != SPECIES_NONE)
+ {
+ sub_80BEBD0(sPSSData->cursorMonMarkings, sPSSData->field_DA0);
+ sPSSData->field_D94->invisible = FALSE;
+ }
+ else
+ {
+ sPSSData->field_D94->invisible = TRUE;
+ }
+}
+
+static void sub_808F5E8(void)
+{
+ u16 i;
+
+ if (sPSSData->cursorMonSpecies != SPECIES_NONE)
+ {
+ SetBoxPartyPokemonDropdownMap2Rect(0, 0, 0, 8, 2);
+ for (i = 0; i < 2; i++)
+ StartSpriteAnimIfDifferent(sPSSData->field_D98[i], i * 2 + 1);
+ }
+ else
+ {
+ SetBoxPartyPokemonDropdownMap2Rect(0, 0, 2, 8, 2);
+ for (i = 0; i < 2; i++)
+ StartSpriteAnim(sPSSData->field_D98[i], i * 2);
+ }
+
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(0);
+ ScheduleBgCopyTilemapToVram(1);
+}
+
+static void sub_808F68C(void)
+{
+ LZ77UnCompWram(gUnknown_8E9CAEC, sPSSData->field_B0);
+ LoadPalette(gPSSMenu_Pal, 0x10, 0x20);
+ SetBoxPartyPokemonDropdownMap2(1, 1, sPSSData->field_B0, 12, 22);
+ SetBoxPartyPokemonDropdownMap2(2, 1, gUnknown_83CE778, 9, 4);
+ SetBoxPartyPokemonDropdownMap2Pos(1, 10, 0);
+ SetBoxPartyPokemonDropdownMap2Pos(2, 21, 0);
+ sub_808F9FC();
+ if (sInPartyMenu)
+ {
+ sub_808F90C(TRUE);
+ CreatePartyMonsSprites(TRUE);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1);
+ }
+ else
+ {
+ SetBoxPartyPokemonDropdownMap2Rect(1, 0, 20, 12, 2);
+ sub_808F90C(TRUE);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2);
+ }
+
+ ScheduleBgCopyTilemapToVram(1);
+ sPSSData->unk_02C7 = FALSE;
+}
+
+static void SetUpShowPartyMenu(void)
+{
+ sPSSData->field_2C0 = 20;
+ sPSSData->field_2C2 = 2;
+ sPSSData->field_2C5 = 0;
+ CreatePartyMonsSprites(FALSE);
+}
+
+static bool8 ShowPartyMenu(void)
+{
+ if (sPSSData->field_2C5 == 20)
+ return FALSE;
+
+ sPSSData->field_2C0--;
+ sPSSData->field_2C2++;
+ AdjustBoxPartyPokemonDropdownPos(1, 3, 1);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1);
+ ScheduleBgCopyTilemapToVram(1);
+ sub_8090B98(8);
+ if (++sPSSData->field_2C5 == 20)
+ {
+ sInPartyMenu = TRUE;
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
+
+static void SetUpHidePartyMenu(void)
+{
+ sPSSData->field_2C0 = 0;
+ sPSSData->field_2C2 = 22;
+ sPSSData->field_2C5 = 0;
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ sub_80960C0();
+}
+
+static bool8 HidePartyMenu(void)
+{
+ if (sPSSData->field_2C5 != 20)
+ {
+ sPSSData->field_2C0++;
+ sPSSData->field_2C2--;
+ AdjustBoxPartyPokemonDropdownPos(1, 3, -1);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1);
+ FillBgTilemapBufferRect_Palette0(1, 0x100, 10, sPSSData->field_2C2, 12, 1);
+ sub_8090B98(-8);
+ if (++sPSSData->field_2C5 != 20)
+ {
+ ScheduleBgCopyTilemapToVram(1);
+ return TRUE;
+ }
+ else
+ {
+ sInPartyMenu = FALSE;
+ DestroyAllPartyMonIcons();
+ CompactPartySlots();
+ SetBoxPartyPokemonDropdownMap2Rect(2, 0, 0, 9, 2);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2);
+ ScheduleBgCopyTilemapToVram(1);
+ return FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
+static void sub_808F90C(bool8 arg0)
+{
+ if (arg0)
+ SetBoxPartyPokemonDropdownMap2Rect(2, 0, 0, 9, 2);
+ else
+ SetBoxPartyPokemonDropdownMap2Rect(2, 0, 2, 9, 2);
+
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2);
+ ScheduleBgCopyTilemapToVram(1);
+}
+
+static void sub_808F948(void)
+{
+ sPSSData->unk_02C7 = TRUE;
+ sPSSData->unk_02C8 = 30;
+ sPSSData->unk_02C9 = TRUE;
+}
+
+static void sub_808F974(void)
+{
+ if (sPSSData->unk_02C7)
+ {
+ sPSSData->unk_02C7 = FALSE;
+ sub_808F90C(TRUE);
+ }
+}
+
+static void sub_808F99C(void)
+{
+ if (sPSSData->unk_02C7 && ++sPSSData->unk_02C8 > 30)
+ {
+ sPSSData->unk_02C8 = 0;
+ sPSSData->unk_02C9 = (sPSSData->unk_02C9 == FALSE);
+ sub_808F90C(sPSSData->unk_02C9);
+ }
+}
+
+static void sub_808F9FC(void)
+{
+ u8 i;
+
+ for (i = 1; i < PARTY_SIZE; i++)
+ {
+ s32 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES);
+ sub_808FA30(i, (species != SPECIES_NONE));
+ }
+}
+
+static void sub_808FA30(u8 pos, bool8 isPartyMon)
+{
+ u16 i, j, index;
+ const u16 *data;
+
+ if (isPartyMon)
+ data = gUnknown_83CE7C0;
+ else
+ data = gUnknown_83CE7D8;
+
+ index = 3 * (3 * (pos - 1) + 1);
+ index *= 4;
+ index += 7;
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 4; j++)
+ {
+ sPSSData->field_B0[index + j] = data[j];
+ }
+ data += 4;
+ index += 12;
+ }
+}
+
+static void sub_808FAA8(void)
+{
+ sub_808F9FC();
+ SetBoxPartyPokemonDropdownMap2Rect(1, 0, 0, 12, 22);
+ CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1);
+ ScheduleBgCopyTilemapToVram(1);
+}
+
+static void SetUpDoShowPartyMenu(void)
+{
+ sPSSData->showPartyMenuState = 0;
+ PlaySE(SE_WIN_OPEN);
+ SetUpShowPartyMenu();
+}
+
+static bool8 DoShowPartyMenu(void)
+{
+ switch (sPSSData->showPartyMenuState)
+ {
+ case 0:
+ if (!ShowPartyMenu())
+ {
+ sub_8092AE4();
+ sPSSData->showPartyMenuState++;
+ }
+ break;
+ case 1:
+ if (!sub_80924A8())
+ {
+ if (sPSSData->setMosaic)
+ BoxSetMosaic();
+ sPSSData->showPartyMenuState++;
+ }
+ break;
+ case 2:
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void sub_808FB68(void)
+{
+ SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(29));
+ TextWindow_SetStdFrame0_WithPal(1, 2, 208);
+ FillBgTilemapBufferRect(0, 0, 0, 0, 32, 20, 17);
+ CopyBgTilemapBufferToVram(0);
+}
+
+static void PrintStorageActionText(u8 id)
+{
+ u8 *txtPtr;
+
+ DynamicPlaceholderTextUtil_Reset();
+ switch (gPCStorageActionTexts[id].format)
+ {
+ case PC_TEXT_FMT_NORMAL:
+ break;
+ case PC_TEXT_FMT_MON_NAME_1:
+ case PC_TEXT_FMT_MON_NAME_2:
+ case PC_TEXT_FMT_MON_NAME_3:
+ DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->cursorMonNick);
+ break;
+ case PC_TEXT_FMT_MON_NAME_4:
+ case PC_TEXT_FMT_MON_NAME_5:
+ case PC_TEXT_FMT_MON_NAME_6:
+ DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->field_21E0);
+ break;
+ case PC_TEXT_FMT_ITEM_NAME:
+ if (IsActiveItemMoving())
+ txtPtr = StringCopy(sPSSData->itemName, GetMovingItemName());
+ else
+ txtPtr = StringCopy(sPSSData->itemName, sPSSData->cursorMonTexts[3]);
+
+ while (*(txtPtr - 1) == CHAR_SPACE)
+ txtPtr--;
+
+ *txtPtr = EOS;
+ DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->itemName);
+ break;
+ }
+
+ DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->field_2190, gPCStorageActionTexts[id].text);
+ FillWindowPixelBuffer(1, PIXEL_FILL(1));
+ AddTextPrinterParameterized(1, 1, sPSSData->field_2190, 0, 2, TEXT_SPEED_FF, NULL);
+ DrawTextBorderOuter(1, 2, 13);
+ PutWindowTilemap(1);
+ CopyWindowToVram(1, 2);
+ ScheduleBgCopyTilemapToVram(0);
+}
+
+static void ShowYesNoWindow(s8 cursorPos)
+{
+ CreateYesNoMenu(&sYesNoWindowTemplate, 1, 0, 2, 0x00b, 14, 1);
+ Menu_MoveCursorNoWrapAround(cursorPos);
+}
+
+static void ClearBottomWindow(void)
+{
+ ClearStdWindowAndFrameToTransparent(1, FALSE);
+ ScheduleBgCopyTilemapToVram(0);
+}
+
+static void AddWallpaperSetsMenu(void)
+{
+ InitMenu();
+ SetMenuText(PC_TEXT_SCENERY1);
+ SetMenuText(PC_TEXT_SCENERY2);
+ SetMenuText(PC_TEXT_SCENERY3);
+ SetMenuText(PC_TEXT_ETCETERA);
+ AddMenu();
+}
+
+static void AddWallpapersMenu(u8 wallpaperSet)
+{
+ InitMenu();
+ switch (wallpaperSet)
+ {
+ case 0:
+ SetMenuText(PC_TEXT_FOREST);
+ SetMenuText(PC_TEXT_CITY);
+ SetMenuText(PC_TEXT_DESERT);
+ SetMenuText(PC_TEXT_SAVANNA);
+ break;
+ case 1:
+ SetMenuText(PC_TEXT_CRAG);
+ SetMenuText(PC_TEXT_VOLCANO);
+ SetMenuText(PC_TEXT_SNOW);
+ SetMenuText(PC_TEXT_CAVE);
+ break;
+ case 2:
+ SetMenuText(PC_TEXT_BEACH);
+ SetMenuText(PC_TEXT_SEAFLOOR);
+ SetMenuText(PC_TEXT_RIVER);
+ SetMenuText(PC_TEXT_SKY);
+ break;
+ case 3:
+ SetMenuText(PC_TEXT_POLKADOT);
+ SetMenuText(PC_TEXT_POKECENTER);
+ SetMenuText(PC_TEXT_MACHINE);
+ SetMenuText(PC_TEXT_SIMPLE);
+ break;
+ }
+ AddMenu();
+}
+
+u8 GetCurrentBoxOption(void)
+{
+ return sCurrentBoxOption;
+}
+
+static void sub_808FDFC(void)
+{
+ if (!IsCursorOnBox())
+ {
+ if (sInPartyMenu)
+ sub_8095C84(CURSOR_AREA_IN_PARTY, GetBoxCursorPosition());
+ else
+ sub_8095C84(CURSOR_AREA_IN_BOX, GetBoxCursorPosition());
+ }
+
+ if (gUnknown_20397BA != ITEM_NONE)
+ {
+ sub_8095E2C(gUnknown_20397BA);
+ sub_8094D14(3);
+ }
+}
+
+static void sub_808FE54(u8 action)
+{
+ u16 event;
+ u8 fromBox = sub_8094D34();
+ u16 species = sPSSData->cursorMonSpecies;
+ u16 species2;
+ u8 toBox;
+ struct PssQuestLogBuffer * qlogBuffer;
+ if (sInPartyMenu)
+ {
+ toBox = TOTAL_BOXES_COUNT;
+ species2 = GetMonData(&gPlayerParty[GetBoxCursorPosition()], MON_DATA_SPECIES2);
+ }
+ else
+ {
+ toBox = StorageGetCurrentBox();
+ species2 = GetCurrentBoxMonData(GetBoxCursorPosition(), MON_DATA_SPECIES2);
+ }
+ qlogBuffer = &sPSSData->qlogBuffer;
+
+ switch (action)
+ {
+ default:
+ return;
+ case 0:
+ if (sInPartyMenu)
+ {
+ if (fromBox == TOTAL_BOXES_COUNT)
+ return;
+ else
+ event = QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON;
+ }
+ else
+ {
+ if (fromBox == TOTAL_BOXES_COUNT)
+ // Should upmerge but doesn't
+ event = QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON;
+ else
+ event = fromBox != toBox ? QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES : QL_EVENT_SWITCHED_MONS_WITHIN_BOX;
+ }
+ qlogBuffer->species = species;
+ qlogBuffer->species2 = species2;
+ qlogBuffer->fromBox = fromBox;
+ qlogBuffer->toBox = toBox;
+ break;
+ case 1:
+ qlogBuffer->species = species;
+ qlogBuffer->species2 = SPECIES_NONE;
+ qlogBuffer->fromBox = fromBox;
+ qlogBuffer->toBox = 0xFF;
+ if (sInPartyMenu)
+ {
+ if (fromBox == TOTAL_BOXES_COUNT)
+ return;
+ else
+ event = QL_EVENT_WITHDREW_MON_PC;
+ }
+ else
+ {
+ if (fromBox == TOTAL_BOXES_COUNT)
+ {
+ event = QL_EVENT_DEPOSITED_MON_PC;
+ qlogBuffer->fromBox = toBox;
+ }
+ else if (fromBox != toBox)
+ {
+ event = QL_EVENT_MOVED_MON_BETWEEN_BOXES;
+ qlogBuffer->toBox = toBox;
+ }
+ else
+ event = QL_EVENT_MOVED_MON_WITHIN_BOX;
+ }
+ break;
+ case 2:
+ event = QL_EVENT_DEPOSITED_MON_PC;
+ qlogBuffer->species = species;
+ qlogBuffer->species2 = SPECIES_NONE;
+ qlogBuffer->fromBox = gUnknown_20397B6;
+ qlogBuffer->toBox = 0xFF;
+ break;
+ case 3:
+ event = QL_EVENT_SWITCHED_MULTIPLE_MONS;
+ qlogBuffer->species = SPECIES_NONE;
+ qlogBuffer->species2 = SPECIES_NONE;
+ qlogBuffer->fromBox = fromBox;
+ qlogBuffer->toBox = toBox;
+ break;
+ }
+ SetQuestLogEvent(event, (const void *)qlogBuffer);
+}
+
+static void sub_808FF70(void)
+{
+ if (sLastUsedBox != StorageGetCurrentBox())
+ {
+ FlagClear(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE);
+ VarSet(VAR_PC_BOX_TO_SEND_MON, StorageGetCurrentBox());
+ }
+}
diff --git a/src/pokemon_storage_system_4.c b/src/pokemon_storage_system_4.c
new file mode 100644
index 000000000..05226838e
--- /dev/null
+++ b/src/pokemon_storage_system_4.c
@@ -0,0 +1,1489 @@
+#include "global.h"
+#include "gflib.h"
+#include "event_data.h"
+#include "graphics.h"
+#include "new_menu_helpers.h"
+#include "pokemon_icon.h"
+#include "pokemon_storage_system_internal.h"
+#include "strings.h"
+#include "task.h"
+#include "trig.h"
+#include "constants/species.h"
+#include "constants/vars.h"
+#include "constants/flags.h"
+
+static void sub_8090324(struct Sprite * sprite);
+static void SetBoxSpeciesAndPersonalities(u8 boxId);
+static void sub_8090A74(struct Sprite * sprite, u16 idx);
+static void sub_8090AE0(struct Sprite * sprite);
+static void DestroyBoxMonIcon(struct Sprite * sprite);
+static void sub_80911B0(struct Sprite * sprite);
+static void sub_8091420(u8 taskId);
+static s8 sub_80916F4(u8 boxId);
+static void LoadWallpaperGfx(u8 wallpaperId, s8 direction);
+static bool32 WaitForWallpaperGfxLoad(void);
+static void sub_8091984(void *buffer, const void *buffer2, s8 direction, u8 baseBlock);
+static void sub_8091A24(void *buffer);
+static void sub_8091A94(u8 wallpaperId);
+static void sub_8091C48(u8 wallpaperId, s8 direction);
+static void sub_8091E84(struct Sprite * sprite);
+static void sub_8091EB8(struct Sprite * sprite);
+static s16 sub_8091F60(const u8 *boxName);
+static void sub_8091E34(void);
+static void sub_8091EF0(void);
+static void sub_8091F80(void);
+static void sub_809200C(s8 direction);
+static void sub_80920AC(void);
+static void sub_8092164(struct Sprite * sprite);
+
+static const struct OamData gUnknown_83CEC08;
+
+static const struct SpriteTemplate gUnknown_83CEBF0 = {
+ .tileTag = TAG_TILE_12,
+ .paletteTag = TAG_PAL_DAC0,
+ .oam = &gUnknown_83CEC08,
+ .anims = gDummySpriteAnimTable,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCallbackDummy
+};
+
+static const struct OamData gUnknown_83CEC08 = {
+ .y = 0,
+ .affineMode = ST_OAM_AFFINE_OFF,
+ .objMode = ST_OAM_OBJ_NORMAL,
+ .mosaic = FALSE,
+ .bpp = ST_OAM_4BPP,
+ .shape = SPRITE_SHAPE(32x32),
+ .x = 0,
+ .matrixNum = 0,
+ .size = SPRITE_SIZE(32x32),
+ .tileNum = 0x000,
+ .priority = 0,
+ .paletteNum = 0
+};
+
+static const union AffineAnimCmd gUnknown_83CEC10[] = {
+ AFFINEANIMCMD_FRAME(-2, -2, 0, 120),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83CEC20[] = {
+ AFFINEANIMCMD_FRAME(16, 16, 0, 0),
+ AFFINEANIMCMD_FRAME(16, 16, 0, 15),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const gUnknown_83CEC38[] = {
+ gUnknown_83CEC10,
+ gUnknown_83CEC20
+};
+
+static const u16 gUnknown_83CEC40[] = INCBIN_U16("graphics/interface/pss_unk_83CEC40.gbapal");
+static const u32 gUnknown_83CEC80[] = INCBIN_U32("graphics/interface/pss_unk_83CEC80.4bpp.lz");
+static const u32 gUnknown_83CF050[] = INCBIN_U32("graphics/interface/pss_unk_83CF050.bin.lz");
+static const u16 gUnknown_83CF12C[] = INCBIN_U16("graphics/interface/pss_unk_83CF12C.gbapal");
+static const u32 gUnknown_83CF16C[] = INCBIN_U32("graphics/interface/pss_unk_83CF16C.4bpp.lz");
+static const u32 gUnknown_83CF374[] = INCBIN_U32("graphics/interface/pss_unk_83CF374.bin.lz");
+static const u16 gUnknown_83CF424[] = INCBIN_U16("graphics/interface/pss_unk_83CF424.gbapal");
+static const u32 gUnknown_83CF464[] = INCBIN_U32("graphics/interface/pss_unk_83CF464.4bpp.lz");
+static const u32 gUnknown_83CF750[] = INCBIN_U32("graphics/interface/pss_unk_83CF750.bin.lz");
+static const u16 gUnknown_83CF834[] = INCBIN_U16("graphics/interface/pss_unk_83CF834.gbapal");
+static const u32 gUnknown_83CF874[] = INCBIN_U32("graphics/interface/pss_unk_83CF874.4bpp.lz");
+static const u32 gUnknown_83CFA94[] = INCBIN_U32("graphics/interface/pss_unk_83CFA94.bin.lz");
+static const u16 gUnknown_83CFB60[] = INCBIN_U16("graphics/interface/pss_unk_83CFB60.gbapal");
+static const u32 gUnknown_83CFBA0[] = INCBIN_U32("graphics/interface/pss_unk_83CFBA0.4bpp.lz");
+static const u32 gUnknown_83CFEF0[] = INCBIN_U32("graphics/interface/pss_unk_83CFEF0.bin.lz");
+static const u16 gUnknown_83CFFC8[] = INCBIN_U16("graphics/interface/pss_unk_83CFFC8.gbapal");
+static const u32 gUnknown_83D0008[] = INCBIN_U32("graphics/interface/pss_unk_83D0008.4bpp.lz");
+static const u8 sSpace_83D0338[4] = {};
+static const u32 gUnknown_83D033C[] = INCBIN_U32("graphics/interface/pss_unk_83D033C.bin.lz");
+static const u16 gUnknown_83D0414[] = INCBIN_U16("graphics/interface/pss_unk_83D0414.gbapal");
+static const u32 gUnknown_83D0454[] = INCBIN_U32("graphics/interface/pss_unk_83D0454.4bpp.lz");
+static const u32 gUnknown_83D070C[] = INCBIN_U32("graphics/interface/pss_unk_83D070C.bin.lz");
+static const u16 gUnknown_83D07D8[] = INCBIN_U16("graphics/interface/pss_unk_83D07D8.gbapal");
+static const u32 gUnknown_83D0818[] = INCBIN_U32("graphics/interface/pss_unk_83D0818.4bpp.lz");
+static const u32 gUnknown_83D0B5C[] = INCBIN_U32("graphics/interface/pss_unk_83D0B5C.bin.lz");
+static const u16 gUnknown_83D0C38[] = INCBIN_U16("graphics/interface/pss_unk_83D0C38.gbapal");
+static const u32 gUnknown_83D0C78[] = INCBIN_U32("graphics/interface/pss_unk_83D0C78.4bpp.lz");
+static const u32 gUnknown_83D0FFC[] = INCBIN_U32("graphics/interface/pss_unk_83D0FFC.bin.lz");
+static const u16 gUnknown_83D10E4[] = INCBIN_U16("graphics/interface/pss_unk_83D10E4.gbapal");
+static const u32 gUnknown_83D1124[] = INCBIN_U32("graphics/interface/pss_unk_83D1124.4bpp.lz");
+static const u32 gUnknown_83D13D8[] = INCBIN_U32("graphics/interface/pss_unk_83D13D8.bin.lz");
+static const u16 gUnknown_83D14B4[] = INCBIN_U16("graphics/interface/pss_unk_83D14B4.gbapal");
+static const u32 gUnknown_83D14F4[] = INCBIN_U32("graphics/interface/pss_unk_83D14F4.4bpp.lz");
+static const u32 gUnknown_83D1788[] = INCBIN_U32("graphics/interface/pss_unk_83D1788.bin.lz");
+static const u16 gUnknown_83D1874[] = INCBIN_U16("graphics/interface/pss_unk_83D1874.gbapal");
+static const u32 gUnknown_83D18B4[] = INCBIN_U32("graphics/interface/pss_unk_83D18B4.4bpp.lz");
+static const u32 gUnknown_83D1B4C[] = INCBIN_U32("graphics/interface/pss_unk_83D1B4C.bin.lz");
+static const u16 gUnknown_83D1C2C[] = INCBIN_U16("graphics/interface/pss_unk_83D1C2C.gbapal");
+static const u8 sSpace_83D1C6C[32] = {};
+static const u32 gUnknown_83D1C8C[] = INCBIN_U32("graphics/interface/pss_unk_83D1C8C.4bpp.lz");
+static const u32 gUnknown_83D1EC4[] = INCBIN_U32("graphics/interface/pss_unk_83D1EC4.bin.lz");
+static const u16 gUnknown_83D1F94[] = INCBIN_U16("graphics/interface/pss_unk_83D1F94.gbapal");
+static const u32 gUnknown_83D1FD4[] = INCBIN_U32("graphics/interface/pss_unk_83D1FD4.4bpp.lz");
+static const u32 gUnknown_83D22B8[] = INCBIN_U32("graphics/interface/pss_unk_83D22B8.bin.lz");
+static const u16 gUnknown_83D239C[] = INCBIN_U16("graphics/interface/pss_unk_83D239C.gbapal");
+static const u32 gUnknown_83D23DC[] = INCBIN_U32("graphics/interface/pss_unk_83D23DC.4bpp.lz");
+static const u32 gUnknown_83D256C[] = INCBIN_U32("graphics/interface/pss_unk_83D256C.bin.lz");
+static const u16 gUnknown_83D2614[] = INCBIN_U16("graphics/interface/pss_unk_83D2614.gbapal");
+static const u32 gUnknown_83D2654[] = INCBIN_U32("graphics/interface/pss_unk_83D2654.4bpp.lz");
+static const u32 gUnknown_83D277C[] = INCBIN_U32("graphics/interface/pss_unk_83D277C.bin.lz");
+static const u16 gUnknown_83D2820[] = INCBIN_U16("graphics/interface/pss_unk_83D2820.bin");
+
+static const u16 gUnknown_83D29D0[][2] = {
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)},
+ {RGB( 7, 7, 7), RGB(31, 31, 31)}
+};
+
+static const struct WallpaperTable gWallpaperTable[] = {
+ {gUnknown_83CEC80, gUnknown_83CF050, gUnknown_83CEC40},
+ {gUnknown_83CF16C, gUnknown_83CF374, gUnknown_83CF12C},
+ {gUnknown_83CF464, gUnknown_83CF750, gUnknown_83CF424},
+ {gUnknown_83CF874, gUnknown_83CFA94, gUnknown_83CF834},
+ {gUnknown_83CFBA0, gUnknown_83CFEF0, gUnknown_83CFB60},
+ {gUnknown_83D0008, gUnknown_83D033C, gUnknown_83CFFC8},
+ {gUnknown_83D0454, gUnknown_83D070C, gUnknown_83D0414},
+ {gUnknown_83D0818, gUnknown_83D0B5C, gUnknown_83D07D8},
+ {gUnknown_83D0C78, gUnknown_83D0FFC, gUnknown_83D0C38},
+ {gUnknown_83D1124, gUnknown_83D13D8, gUnknown_83D10E4},
+ {gUnknown_83D14F4, gUnknown_83D1788, gUnknown_83D14B4},
+ {gUnknown_83D18B4, gUnknown_83D1B4C, gUnknown_83D1874},
+ {gUnknown_83D1C8C, gUnknown_83D1EC4, gUnknown_83D1C2C},
+ {gUnknown_83D1FD4, gUnknown_83D22B8, gUnknown_83D1F94},
+ {gUnknown_83D23DC, gUnknown_83D256C, gUnknown_83D239C},
+ {gUnknown_83D2654, gUnknown_83D277C, gUnknown_83D2614},
+};
+
+static const u16 gUnknown_83D2AD0[] = INCBIN_U16("graphics/interface/pss_unk_83D2AD0.4bpp");
+static const u8 sUnref_83D2B50[] = {0xba, 0x23};
+
+static const struct SpriteSheet gUnknown_83D2B54 = {
+ gUnknown_83D2AD0, 0x0080, TAG_TILE_6
+};
+
+static const struct OamData gUnknown_83D2B5C = {
+ .y = 0,
+ .affineMode = ST_OAM_AFFINE_OFF,
+ .objMode = ST_OAM_OBJ_NORMAL,
+ .mosaic = FALSE,
+ .bpp = ST_OAM_4BPP,
+ .shape = SPRITE_SHAPE(32x16),
+ .x = 0,
+ .matrixNum = 0,
+ .size = SPRITE_SIZE(32x16),
+ .tileNum = 0,
+ .priority = 2,
+ .paletteNum = 0
+};
+
+static const union AnimCmd gUnknown_83D2B64[] = {
+ ANIMCMD_FRAME(0, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83D2B6C[] = {
+ ANIMCMD_FRAME(8, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd *const gUnknown_83D2B74[] = {
+ gUnknown_83D2B64,
+ gUnknown_83D2B6C
+};
+
+static const struct SpriteTemplate gUnknown_83D2B7C = {
+ .tileTag = TAG_TILE_3,
+ .paletteTag = TAG_PAL_DAC9,
+ .oam = &gUnknown_83D2B5C,
+ .anims = gUnknown_83D2B74,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCallbackDummy
+};
+
+static const struct OamData gUnknown_83D2B94 = {
+ .y = 0,
+ .affineMode = ST_OAM_AFFINE_OFF,
+ .objMode = ST_OAM_OBJ_NORMAL,
+ .mosaic = FALSE,
+ .bpp = ST_OAM_4BPP,
+ .shape = SPRITE_SHAPE(8x16),
+ .x = 0,
+ .matrixNum = 0,
+ .size = SPRITE_SIZE(8x16),
+ .tileNum = 0x000,
+ .priority = 2,
+ .paletteNum = 0
+};
+
+static const union AnimCmd gUnknown_83D2B9C[] = {
+ ANIMCMD_FRAME(0, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd gUnknown_83D2BA4[] = {
+ ANIMCMD_FRAME(2, 5),
+ ANIMCMD_END
+};
+
+static const union AnimCmd *const gUnknown_83D2BAC[] = {
+ gUnknown_83D2B9C,
+ gUnknown_83D2BA4
+};
+
+static const struct SpriteTemplate gUnknown_83D2BB4 = {
+ .tileTag = TAG_TILE_6,
+ .paletteTag = TAG_PAL_WAVEFORM,
+ .oam = &gUnknown_83D2B94,
+ .anims = gUnknown_83D2BAC,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = sub_8092164
+};
+
+void sub_808FFAC(void)
+{
+ u16 i;
+
+ LoadMonIconPalettes();
+ for (i = 0; i < MAX_MON_ICONS; i++)
+ sPSSData->field_B08[i] = 0;
+ for (i = 0; i < MAX_MON_ICONS; i++)
+ sPSSData->field_B58[i] = 0;
+ for (i = 0; i < PARTY_SIZE; i++)
+ sPSSData->partySprites[i] = NULL;
+ for (i = 0; i < IN_BOX_COUNT; i++)
+ sPSSData->boxMonsSprites[i] = NULL;
+
+ sPSSData->movingMonSprite = NULL;
+ sPSSData->field_78C = 0;
+}
+
+static u8 sub_8090058(void)
+{
+ return (IsCursorInBox() ? 2 : 1);
+}
+
+void CreateMovingMonIcon(void)
+{
+ u32 personality = GetMonData(&sPSSData->movingMon, MON_DATA_PERSONALITY);
+ u16 species = GetMonData(&sPSSData->movingMon, MON_DATA_SPECIES2);
+ u8 priority = sub_8090058();
+
+ sPSSData->movingMonSprite = CreateMonIconSprite(species, personality, 0, 0, priority, 7);
+ sPSSData->movingMonSprite->callback = sub_80911B0;
+}
+
+static void sub_80900D4(u8 boxId)
+{
+ u8 boxPosition;
+ u16 i, j, count;
+ u16 species;
+ u32 personality;
+
+ count = 0;
+ boxPosition = 0;
+ for (i = 0; i < IN_BOX_COLUMNS; i++)
+ {
+ for (j = 0; j < IN_BOX_ROWS; j++)
+ {
+ species = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2);
+ if (species != SPECIES_NONE)
+ {
+ personality = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY);
+ sPSSData->boxMonsSprites[count] = CreateMonIconSprite(species, personality, 8 * (3 * j) + 100, 8 * (3 * i) + 44, 2, 19 - j);
+ }
+ else
+ {
+ sPSSData->boxMonsSprites[count] = NULL;
+ }
+ boxPosition++;
+ count++;
+ }
+ }
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++)
+ {
+ if (GetBoxMonDataAt(boxId, boxPosition, MON_DATA_HELD_ITEM) == 0)
+ sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND;
+ }
+ }
+}
+
+void sub_80901EC(u8 boxPosition)
+{
+ u16 species = GetCurrentBoxMonData(boxPosition, MON_DATA_SPECIES2);
+
+ if (species != SPECIES_NONE)
+ {
+ s16 x = 8 * (3 * (boxPosition % IN_BOX_ROWS)) + 100;
+ s16 y = 8 * (3 * (boxPosition / IN_BOX_ROWS)) + 44;
+ u32 personality = GetCurrentBoxMonData(boxPosition, MON_DATA_PERSONALITY);
+
+ sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_ROWS));
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND;
+ }
+}
+
+static void sub_809029C(s16 arg0)
+{
+ u16 i;
+
+ for (i = 0; i < IN_BOX_COUNT; i++)
+ {
+ if (sPSSData->boxMonsSprites[i] != NULL)
+ {
+ sPSSData->boxMonsSprites[i]->data[2] = arg0;
+ sPSSData->boxMonsSprites[i]->data[4] = 1;
+ sPSSData->boxMonsSprites[i]->callback = sub_8090324;
+ }
+ }
+}
+
+static void sub_80902E0(struct Sprite *sprite)
+{
+ if (sprite->data[1] != 0)
+ {
+ sprite->data[1]--;
+ sprite->pos1.x += sprite->data[2];
+ }
+ else
+ {
+ sPSSData->field_C66--;
+ sprite->pos1.x = sprite->data[3];
+ sprite->callback = SpriteCallbackDummy;
+ }
+}
+
+static void sub_8090324(struct Sprite *sprite)
+{
+ if (sprite->data[4] != 0)
+ {
+ sprite->data[4]--;
+ }
+ else
+ {
+ sprite->pos1.x += sprite->data[2];
+ sprite->data[5] = sprite->pos1.x + sprite->pos2.x;
+ if (sprite->data[5] <= 68 || sprite->data[5] >= 252)
+ sprite->callback = SpriteCallbackDummy;
+ }
+}
+
+static void DestroyAllIconsInRow(u8 row)
+{
+ u16 column;
+ u8 boxPosition = row;
+
+ for (column = 0; column < IN_BOX_COLUMNS; column++)
+ {
+ if (sPSSData->boxMonsSprites[boxPosition] != NULL)
+ {
+ DestroyBoxMonIcon(sPSSData->boxMonsSprites[boxPosition]);
+ sPSSData->boxMonsSprites[boxPosition] = NULL;
+ }
+ boxPosition += IN_BOX_ROWS;
+ }
+}
+
+static u8 sub_80903A4(u8 row, u16 times, s16 xDelta)
+{
+ s32 i;
+ u16 y = 44;
+ s16 xDest = 8 * (3 * row) + 100;
+ u16 x = xDest - ((times + 1) * xDelta);
+ u8 subpriority = 19 - row;
+ u8 count = 0;
+ u8 boxPosition = row;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ for (i = 0; i < IN_BOX_COLUMNS; i++)
+ {
+ if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE)
+ {
+ sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(sPSSData->boxSpecies[boxPosition],
+ sPSSData->boxPersonalities[boxPosition],
+ x, y, 2, subpriority);
+ if (sPSSData->boxMonsSprites[boxPosition] != NULL)
+ {
+ sPSSData->boxMonsSprites[boxPosition]->data[1] = times;
+ sPSSData->boxMonsSprites[boxPosition]->data[2] = xDelta;
+ sPSSData->boxMonsSprites[boxPosition]->data[3] = xDest;
+ sPSSData->boxMonsSprites[boxPosition]->callback = sub_80902E0;
+ count++;
+ }
+ }
+ boxPosition += IN_BOX_ROWS;
+ y += 24;
+ }
+ }
+ else
+ {
+ for (i = 0; i < IN_BOX_COLUMNS; i++)
+ {
+ if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE)
+ {
+ sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(sPSSData->boxSpecies[boxPosition],
+ sPSSData->boxPersonalities[boxPosition],
+ x, y, 2, subpriority);
+ if (sPSSData->boxMonsSprites[boxPosition] != NULL)
+ {
+ sPSSData->boxMonsSprites[boxPosition]->data[1] = times;
+ sPSSData->boxMonsSprites[boxPosition]->data[2] = xDelta;
+ sPSSData->boxMonsSprites[boxPosition]->data[3] = xDest;
+ sPSSData->boxMonsSprites[boxPosition]->callback = sub_80902E0;
+ if (GetBoxMonDataAt(sPSSData->field_C5C, boxPosition, MON_DATA_HELD_ITEM) == 0)
+ sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND;
+ count++;
+ }
+ }
+ boxPosition += IN_BOX_ROWS;
+ y += 24;
+ }
+ }
+
+ return count;
+}
+
+static void sub_8090574(u8 boxId, s8 direction)
+{
+ sPSSData->field_C6A = 0;
+ sPSSData->field_C6B = boxId;
+ sPSSData->field_C69 = direction;
+ sPSSData->field_C60 = 32;
+ sPSSData->field_C64 = -(6 * direction);
+ sPSSData->field_C66 = 0;
+ SetBoxSpeciesAndPersonalities(boxId);
+ if (direction > 0)
+ sPSSData->field_C68 = 0;
+ else
+ sPSSData->field_C68 = IN_BOX_ROWS - 1;
+
+ sPSSData->field_C62 = (24 * sPSSData->field_C68) + 100;
+ sub_809029C(sPSSData->field_C64);
+}
+
+static bool8 sub_809062C(void)
+{
+ if (sPSSData->field_C60 != 0)
+ sPSSData->field_C60--;
+
+ switch (sPSSData->field_C6A)
+ {
+ case 0:
+ sPSSData->field_C62 += sPSSData->field_C64;
+ if (sPSSData->field_C62 <= 64 || sPSSData->field_C62 >= 252)
+ {
+ DestroyAllIconsInRow(sPSSData->field_C68);
+ sPSSData->field_C62 += sPSSData->field_C69 * 24;
+ sPSSData->field_C6A++;
+ }
+ break;
+ case 1:
+ sPSSData->field_C62 += sPSSData->field_C64;
+ sPSSData->field_C66 += sub_80903A4(sPSSData->field_C68, sPSSData->field_C60, sPSSData->field_C64);
+ if ((sPSSData->field_C69 > 0 && sPSSData->field_C68 == IN_BOX_ROWS - 1)
+ || (sPSSData->field_C69 < 0 && sPSSData->field_C68 == 0))
+ {
+ sPSSData->field_C6A++;
+ }
+ else
+ {
+ sPSSData->field_C68 += sPSSData->field_C69;
+ sPSSData->field_C6A = 0;
+ }
+ break;
+ case 2:
+ if (sPSSData->field_C66 == 0)
+ {
+ sPSSData->field_C60++;
+ return FALSE;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void SetBoxSpeciesAndPersonalities(u8 boxId)
+{
+ s32 i, j, boxPosition;
+
+ boxPosition = 0;
+ for (i = 0; i < IN_BOX_COLUMNS; i++)
+ {
+ for (j = 0; j < IN_BOX_ROWS; j++)
+ {
+ sPSSData->boxSpecies[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2);
+ if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE)
+ sPSSData->boxPersonalities[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY);
+ boxPosition++;
+ }
+ }
+
+ sPSSData->field_C5C = boxId;
+}
+
+void DestroyBoxMonIconAtPosition(u8 boxPosition)
+{
+ if (sPSSData->boxMonsSprites[boxPosition] != NULL)
+ {
+ DestroyBoxMonIcon(sPSSData->boxMonsSprites[boxPosition]);
+ sPSSData->boxMonsSprites[boxPosition] = NULL;
+ }
+}
+
+void SetBoxMonIconObjMode(u8 boxPosition, u8 objMode)
+{
+ if (sPSSData->boxMonsSprites[boxPosition] != NULL)
+ {
+ sPSSData->boxMonsSprites[boxPosition]->oam.objMode = objMode;
+ }
+}
+
+void CreatePartyMonsSprites(bool8 arg0)
+{
+ u16 i, count;
+ u16 species = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES2);
+ u32 personality = GetMonData(&gPlayerParty[0], MON_DATA_PERSONALITY);
+
+ sPSSData->partySprites[0] = CreateMonIconSprite(species, personality, 104, 64, 1, 12);
+ count = 1;
+ for (i = 1; i < PARTY_SIZE; i++)
+ {
+ species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
+ if (species != SPECIES_NONE)
+ {
+ personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY);
+ sPSSData->partySprites[i] = CreateMonIconSprite(species, personality, 152, 8 * (3 * (i - 1)) + 16, 1, 12);
+ count++;
+ }
+ else
+ {
+ sPSSData->partySprites[i] = NULL;
+ }
+ }
+
+ if (!arg0)
+ {
+ for (i = 0; i < count; i++)
+ {
+ sPSSData->partySprites[i]->pos1.y -= 160;
+ sPSSData->partySprites[i]->invisible = TRUE;
+ }
+ }
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ if (sPSSData->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == 0)
+ sPSSData->partySprites[i]->oam.objMode = ST_OAM_OBJ_BLEND;
+ }
+ }
+}
+
+void sub_80909F4(void)
+{
+ u16 i, count;
+
+ sPSSData->field_C5E = 0;
+ for (i = 0, count = 0; i < PARTY_SIZE; i++)
+ {
+ if (sPSSData->partySprites[i] != NULL)
+ {
+ if (i != count)
+ {
+ sub_8090A74(sPSSData->partySprites[i], count);
+ sPSSData->partySprites[i] = NULL;
+ sPSSData->field_C5E++;
+ }
+ count++;
+ }
+ }
+}
+
+u8 sub_8090A60(void)
+{
+ return sPSSData->field_C5E;
+}
+
+static void sub_8090A74(struct Sprite *sprite, u16 partyId)
+{
+ s16 x, y;
+
+ sprite->data[1] = partyId;
+ if (partyId == 0)
+ x = 104, y = 64;
+ else
+ x = 152, y = 8 * (3 * (partyId - 1)) + 16;
+
+ sprite->data[2] = (u16)(sprite->pos1.x) * 8;
+ sprite->data[3] = (u16)(sprite->pos1.y) * 8;
+ sprite->data[4] = ((x * 8) - sprite->data[2]) / 8;
+ sprite->data[5] = ((y * 8) - sprite->data[3]) / 8;
+ sprite->data[6] = 8;
+ sprite->callback = sub_8090AE0;
+}
+
+static void sub_8090AE0(struct Sprite *sprite)
+{
+ if (sprite->data[6] != 0)
+ {
+ s16 x = sprite->data[2] += sprite->data[4];
+ s16 y = sprite->data[3] += sprite->data[5];
+ sprite->pos1.x = x / 8u;
+ sprite->pos1.y = y / 8u;
+ sprite->data[6]--;
+ }
+ else
+ {
+ if (sprite->data[1] == 0)
+ {
+ sprite->pos1.x = 104;
+ sprite->pos1.y = 64;
+ }
+ else
+ {
+ sprite->pos1.x = 152;
+ sprite->pos1.y = 8 * (3 * (sprite->data[1] - 1)) + 16;
+ }
+ sprite->callback = SpriteCallbackDummy;
+ sPSSData->partySprites[sprite->data[1]] = sprite;
+ sPSSData->field_C5E--;
+ }
+}
+
+void DestroyMovingMonIcon(void)
+{
+ if (sPSSData->movingMonSprite != NULL)
+ {
+ DestroyBoxMonIcon(sPSSData->movingMonSprite);
+ sPSSData->movingMonSprite = NULL;
+ }
+}
+
+void sub_8090B98(s16 yDelta)
+{
+ u16 i, posY;
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ if (sPSSData->partySprites[i] != NULL)
+ {
+ sPSSData->partySprites[i]->pos1.y += yDelta;
+ posY = sPSSData->partySprites[i]->pos1.y + sPSSData->partySprites[i]->pos2.y + sPSSData->partySprites[i]->centerToCornerVecY;
+ posY += 16;
+ if (posY > 192)
+ sPSSData->partySprites[i]->invisible = TRUE;
+ else
+ sPSSData->partySprites[i]->invisible = FALSE;
+ }
+ }
+}
+
+void DestroyPartyMonIcon(u8 partyId)
+{
+ if (sPSSData->partySprites[partyId] != NULL)
+ {
+ DestroyBoxMonIcon(sPSSData->partySprites[partyId]);
+ sPSSData->partySprites[partyId] = NULL;
+ }
+}
+
+void DestroyAllPartyMonIcons(void)
+{
+ u16 i;
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ if (sPSSData->partySprites[i] != NULL)
+ {
+ DestroyBoxMonIcon(sPSSData->partySprites[i]);
+ sPSSData->partySprites[i] = NULL;
+ }
+ }
+}
+
+void SetPartyMonIconObjMode(u8 partyId, u8 objMode)
+{
+ if (sPSSData->partySprites[partyId] != NULL)
+ {
+ sPSSData->partySprites[partyId]->oam.objMode = objMode;
+ }
+}
+
+void sub_8090CC0(u8 mode, u8 id)
+{
+ if (mode == MODE_PARTY)
+ {
+ sPSSData->movingMonSprite = sPSSData->partySprites[id];
+ sPSSData->partySprites[id] = NULL;
+ }
+ else if (mode == MODE_BOX)
+ {
+ sPSSData->movingMonSprite = sPSSData->boxMonsSprites[id];
+ sPSSData->boxMonsSprites[id] = NULL;
+ }
+ else
+ {
+ return;
+ }
+
+ sPSSData->movingMonSprite->callback = sub_80911B0;
+ sPSSData->movingMonSprite->oam.priority = sub_8090058();
+ sPSSData->movingMonSprite->subpriority = 7;
+}
+
+void sub_8090D58(u8 boxId, u8 position)
+{
+ if (boxId == TOTAL_BOXES_COUNT) // party mon
+ {
+ sPSSData->partySprites[position] = sPSSData->movingMonSprite;
+ sPSSData->partySprites[position]->oam.priority = 1;
+ sPSSData->partySprites[position]->subpriority = 12;
+ }
+ else
+ {
+ sPSSData->boxMonsSprites[position] = sPSSData->movingMonSprite;
+ sPSSData->boxMonsSprites[position]->oam.priority = 2;
+ sPSSData->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_ROWS);
+ }
+ sPSSData->movingMonSprite->callback = SpriteCallbackDummy;
+ sPSSData->movingMonSprite = NULL;
+}
+
+void sub_8090E08(u8 boxId, u8 position)
+{
+ if (boxId == TOTAL_BOXES_COUNT) // party mon
+ sPSSData->field_B00 = &sPSSData->partySprites[position];
+ else
+ sPSSData->field_B00 = &sPSSData->boxMonsSprites[position];
+
+ sPSSData->movingMonSprite->callback = SpriteCallbackDummy;
+ sPSSData->field_C5D = 0;
+}
+
+bool8 sub_8090E74(void)
+{
+ if (sPSSData->field_C5D == 16)
+ return FALSE;
+
+ sPSSData->field_C5D++;
+ if (sPSSData->field_C5D & 1)
+ {
+ (*sPSSData->field_B00)->pos1.y--;
+ sPSSData->movingMonSprite->pos1.y++;
+ }
+
+ (*sPSSData->field_B00)->pos2.x = gSineTable[sPSSData->field_C5D * 8] / 16;
+ sPSSData->movingMonSprite->pos2.x = -(gSineTable[sPSSData->field_C5D * 8] / 16);
+ if (sPSSData->field_C5D == 8)
+ {
+ sPSSData->movingMonSprite->oam.priority = (*sPSSData->field_B00)->oam.priority;
+ sPSSData->movingMonSprite->subpriority = (*sPSSData->field_B00)->subpriority;
+ (*sPSSData->field_B00)->oam.priority = sub_8090058();
+ (*sPSSData->field_B00)->subpriority = 7;
+ }
+
+ if (sPSSData->field_C5D == 16)
+ {
+ struct Sprite *sprite = sPSSData->movingMonSprite;
+ sPSSData->movingMonSprite = (*sPSSData->field_B00);
+ *sPSSData->field_B00 = sprite;
+
+ sPSSData->movingMonSprite->callback = sub_80911B0;
+ (*sPSSData->field_B00)->callback = SpriteCallbackDummy;
+ }
+
+ return TRUE;
+}
+
+void sub_8090FC4(u8 mode, u8 position)
+{
+ switch (mode)
+ {
+ case MODE_PARTY:
+ sPSSData->field_B04 = &sPSSData->partySprites[position];
+ break;
+ case MODE_BOX:
+ sPSSData->field_B04 = &sPSSData->boxMonsSprites[position];
+ break;
+ case MODE_2:
+ sPSSData->field_B04 = &sPSSData->movingMonSprite;
+ break;
+ default:
+ return;
+ }
+
+ if (*sPSSData->field_B04 != NULL)
+ {
+ InitSpriteAffineAnim(*sPSSData->field_B04);
+ (*sPSSData->field_B04)->oam.affineMode = ST_OAM_AFFINE_NORMAL;
+ (*sPSSData->field_B04)->affineAnims = gUnknown_83CEC38;
+ StartSpriteAffineAnim(*sPSSData->field_B04, 0);
+ }
+}
+
+bool8 sub_8091084(void)
+{
+ if (*sPSSData->field_B04 == NULL || (*sPSSData->field_B04)->invisible)
+ return FALSE;
+
+ if ((*sPSSData->field_B04)->affineAnimEnded)
+ (*sPSSData->field_B04)->invisible = TRUE;
+
+ return TRUE;
+}
+
+void sub_80910CC(void)
+{
+ if (*sPSSData->field_B04 != NULL)
+ {
+ FreeOamMatrix((*sPSSData->field_B04)->oam.matrixNum);
+ DestroyBoxMonIcon(*sPSSData->field_B04);
+ *sPSSData->field_B04 = NULL;
+ }
+}
+
+void sub_8091114(void)
+{
+ if (*sPSSData->field_B04 != NULL)
+ {
+ (*sPSSData->field_B04)->invisible = FALSE;
+ StartSpriteAffineAnim(*sPSSData->field_B04, 1);
+ }
+}
+
+bool8 sub_8091150(void)
+{
+ if (sPSSData->field_B04 == NULL)
+ return FALSE;
+
+ if ((*sPSSData->field_B04)->affineAnimEnded)
+ sPSSData->field_B04 = NULL;
+
+ return TRUE;
+}
+
+void SetMovingMonPriority(u8 priority)
+{
+ sPSSData->movingMonSprite->oam.priority = priority;
+}
+
+static void sub_80911B0(struct Sprite *sprite)
+{
+ sprite->pos1.x = sPSSData->field_CB4->pos1.x;
+ sprite->pos1.y = sPSSData->field_CB4->pos1.y + sPSSData->field_CB4->pos2.y + 4;
+}
+
+static u16 sub_80911D4(u16 species)
+{
+ u16 i, var;
+
+ // Find the currently-allocated slot
+ for (i = 0; i < MAX_MON_ICONS; i++)
+ {
+ if (sPSSData->field_B58[i] == species)
+ break;
+ }
+
+ if (i == MAX_MON_ICONS)
+ {
+ // Find the first empty slot
+ for (i = 0; i < MAX_MON_ICONS; i++)
+ {
+ if (sPSSData->field_B58[i] == SPECIES_NONE)
+ break;
+ }
+ if (i == MAX_MON_ICONS)
+ return 0xFFFF;
+ }
+
+ sPSSData->field_B58[i] = species;
+ sPSSData->field_B08[i]++;
+ var = 16 * i;
+ CpuCopy32(GetMonIconTiles(species, TRUE), (void*)(OBJ_VRAM0) + var * 32, 0x200);
+
+ return var;
+}
+
+static void sub_8091290(u16 species)
+{
+ u16 i;
+
+ for (i = 0; i < MAX_MON_ICONS; i++)
+ {
+ if (sPSSData->field_B58[i] == species)
+ {
+ if (--sPSSData->field_B08[i] == 0)
+ sPSSData->field_B58[i] = 0;
+ break;
+ }
+ }
+}
+
+struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 oamPriority, u8 subpriority)
+{
+ u16 tileNum;
+ u8 spriteId;
+ struct SpriteTemplate template = gUnknown_83CEBF0;
+
+ species = GetIconSpecies(species, personality);
+ template.paletteTag = 0xDAC0 + gMonIconPaletteIndices[species];
+ tileNum = sub_80911D4(species);
+ if (tileNum == 0xFFFF)
+ return NULL;
+
+ spriteId = CreateSprite(&template, x, y, subpriority);
+ if (spriteId == MAX_SPRITES)
+ {
+ sub_8091290(species);
+ return NULL;
+ }
+
+ gSprites[spriteId].oam.tileNum = tileNum;
+ gSprites[spriteId].oam.priority = oamPriority;
+ gSprites[spriteId].data[0] = species;
+ return &gSprites[spriteId];
+}
+
+static void DestroyBoxMonIcon(struct Sprite *sprite)
+{
+ sub_8091290(sprite->data[0]);
+ DestroySprite(sprite);
+}
+
+void sub_80913DC(u8 boxId)
+{
+ u8 taskId = CreateTask(sub_8091420, 2);
+
+ gTasks[taskId].data[2] = boxId;
+}
+
+bool8 sub_809140C(void)
+{
+ return FuncIsActiveTask(sub_8091420);
+}
+
+static void sub_8091420(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+
+ switch (task->data[0])
+ {
+ case 0:
+ sPSSData->field_2D2 = 0;
+ sPSSData->bg2_X = 0;
+ task->data[1] = RequestDma3Fill(0, sPSSData->field_4AC4, 0x1000, 1);
+ break;
+ case 1:
+ if (CheckForSpaceForDma3Request(task->data[1]) == -1)
+ return;
+
+ SetBgTilemapBuffer(2, sPSSData->field_4AC4);
+ ShowBg(2);
+ break;
+ case 2:
+ LoadWallpaperGfx(task->data[2], 0);
+ break;
+ case 3:
+ if (!WaitForWallpaperGfxLoad())
+ return;
+
+ sub_8091A94(task->data[2]);
+ sub_8091F80();
+ sub_80900D4(task->data[2]);
+ SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(27) | BGCNT_TXT512x256);
+ break;
+ case 4:
+ DestroyTask(taskId);
+ break;
+ default:
+ task->data[0] = 0;
+ return;
+ }
+
+ task->data[0]++;
+}
+
+void SetUpScrollToBox(u8 boxId)
+{
+ s8 direction = sub_80916F4(boxId);
+
+ sPSSData->field_2CE = (direction > 0) ? 6 : -6;
+ sPSSData->field_2D3 = (direction > 0) ? 1 : 2;
+ sPSSData->field_2D0 = 32;
+ sPSSData->field_2D4 = boxId;
+ sPSSData->field_2D6 = (direction <= 0) ? 5 : 0;
+ sPSSData->field_2D8 = direction;
+ sPSSData->field_2DA = (direction > 0) ? 264 : 56;
+ sPSSData->field_2DC = (direction <= 0) ? 5 : 0;
+ sPSSData->field_2DE = 0;
+ sPSSData->field_2E0 = 2;
+ sPSSData->field_A64 = boxId;
+ sPSSData->field_A65 = direction;
+ sPSSData->field_A63 = 0;
+}
+
+bool8 ScrollToBox(void)
+{
+ bool8 var;
+
+ switch (sPSSData->field_A63)
+ {
+ case 0:
+ LoadWallpaperGfx(sPSSData->field_A64, sPSSData->field_A65);
+ sPSSData->field_A63++;
+ case 1:
+ if (!WaitForWallpaperGfxLoad())
+ return TRUE;
+
+ sub_8090574(sPSSData->field_A64, sPSSData->field_A65);
+ sub_8091C48(sPSSData->field_A64, sPSSData->field_A65);
+ sub_809200C(sPSSData->field_A65);
+ break;
+ case 2:
+ var = sub_809062C();
+ if (sPSSData->field_2D0 != 0)
+ {
+ sPSSData->bg2_X += sPSSData->field_2CE;
+ if (--sPSSData->field_2D0 != 0)
+ return TRUE;
+ sub_8091E34();
+ sub_80920AC();
+ }
+ return var;
+ }
+
+ sPSSData->field_A63++;
+ return TRUE;
+}
+
+static s8 sub_80916F4(u8 boxId)
+{
+ u8 i;
+ u8 currentBox = StorageGetCurrentBox();
+
+ for (i = 0; currentBox != boxId; i++)
+ {
+ currentBox++;
+ if (currentBox >= TOTAL_BOXES_COUNT)
+ currentBox = 0;
+ }
+
+ return (i < TOTAL_BOXES_COUNT / 2) ? 1 : -1;
+}
+
+void SetWallpaperForCurrentBox(u8 wallpaperId)
+{
+ u8 boxId = StorageGetCurrentBox();
+ SetBoxWallpaper(boxId, wallpaperId);
+ sPSSData->wallpaperChangeState = 0;
+}
+
+bool8 DoWallpaperGfxChange(void)
+{
+ switch (sPSSData->wallpaperChangeState)
+ {
+ case 0:
+ BeginNormalPaletteFade(sPSSData->field_738, 1, 0, 16, RGB_WHITEALPHA);
+ sPSSData->wallpaperChangeState++;
+ break;
+ case 1:
+ if (!UpdatePaletteFade())
+ {
+ u8 curBox = StorageGetCurrentBox();
+ LoadWallpaperGfx(curBox, 0);
+ sPSSData->wallpaperChangeState++;
+ }
+ break;
+ case 2:
+ if (WaitForWallpaperGfxLoad() == TRUE)
+ {
+ sub_8091EF0();
+ BeginNormalPaletteFade(sPSSData->field_738, 1, 16, 0, RGB_WHITEALPHA);
+ sPSSData->wallpaperChangeState++;
+ }
+ break;
+ case 3:
+ if (!UpdatePaletteFade())
+ sPSSData->wallpaperChangeState++;
+ break;
+ case 4:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void LoadWallpaperGfx(u8 boxId, s8 direction)
+{
+ u8 wallpaperId;
+ const struct WallpaperTable *wallpaperGfx;
+ void *iconGfx;
+ u32 size1, size2;
+
+ sPSSData->field_6F9 = 0;
+ sPSSData->field_6FA = boxId;
+ sPSSData->field_6FB = direction;
+ if (sPSSData->field_6FB != 0)
+ {
+ sPSSData->field_2D2 = (sPSSData->field_2D2 == 0);
+ sub_8091A24(sPSSData->field_4AC4);
+ }
+
+ wallpaperId = GetBoxWallpaper(sPSSData->field_6FA);
+ wallpaperGfx = &gWallpaperTable[wallpaperId];
+ LZ77UnCompWram(wallpaperGfx->tileMap, sPSSData->field_792);
+ sub_8091984(sPSSData->field_4AC4, sPSSData->field_792, sPSSData->field_6FB, sPSSData->field_2D2);
+
+ if (sPSSData->field_6FB != 0)
+ LoadPalette(wallpaperGfx->palettes, (sPSSData->field_2D2 * 32) + 0x40, 0x40);
+ else
+ CpuCopy16(wallpaperGfx->palettes, &gPlttBufferUnfaded[(sPSSData->field_2D2 * 32) + 0x40], 0x40);
+
+ DecompressAndLoadBgGfxUsingHeap(2, wallpaperGfx->tiles, 0, 256 * sPSSData->field_2D2, 0);
+
+ CopyBgTilemapBufferToVram(2);
+}
+
+static bool32 WaitForWallpaperGfxLoad(void)
+{
+ if (IsDma3ManagerBusyWithBgCopy() == TRUE)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void sub_8091984(void *buffer, const void *tilemap, s8 direction, u8 arg2)
+{
+ s16 var = (arg2 * 2) + 3;
+ s16 x = ((sPSSData->bg2_X / 8 + 10) + (direction * 24)) & 0x3F;
+
+ CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, arg2 << 8, var);
+
+ if (direction == 0)
+ return;
+ else if (direction > 0)
+ x *= 1, x += 0x14; // x * 1 is needed to match, but can be safely removed as it makes no functional difference
+ else
+ x -= 4;
+
+ FillBgTilemapBufferRect(2, 0, x, 2, 4, 0x12, 0x11);
+}
+
+static void sub_8091A24(void *arg0)
+{
+ u16 i;
+ u16 *dest = arg0;
+ s16 r3 = ((sPSSData->bg2_X / 8) + 30) & 0x3F;
+
+ if (r3 <= 31)
+ dest += r3 + 0x260;
+ else
+ dest += r3 + 0x640;
+
+ for (i = 0; i < 0x2C; i++)
+ {
+ *dest++ = 0;
+ r3 = (r3 + 1) & 0x3F;
+ if (r3 == 0)
+ dest -= 0x420;
+ if (r3 == 0x20)
+ dest += 0x3e0;
+ }
+}
+
+static void sub_8091A94(u8 boxId)
+{
+ u8 tagIndex;
+ s16 r6;
+ u16 i;
+
+ struct SpriteSheet spriteSheet = {sPSSData->field_2F8, 0x200, TAG_TILE_3};
+ struct SpritePalette palettes[] = {
+ {sPSSData->field_6FC, TAG_PAL_DAC9},
+ {}
+ };
+
+ u16 wallpaperId = GetBoxWallpaper(boxId);
+
+ sPSSData->field_6FC[14] = gUnknown_83D29D0[wallpaperId][0];
+ sPSSData->field_6FC[15] = gUnknown_83D29D0[wallpaperId][1];
+ LoadSpritePalettes(palettes);
+ sPSSData->field_738 = 0x3f0;
+
+ tagIndex = IndexOfSpritePaletteTag(TAG_PAL_DAC9);
+ sPSSData->field_71C = 0x10e + 16 * tagIndex;
+ sPSSData->field_738 |= 0x10000 << tagIndex;
+
+ tagIndex = IndexOfSpritePaletteTag(TAG_PAL_DAC9);
+ sPSSData->field_71E = 0x10e + 16 * tagIndex;
+ sPSSData->field_738 |= 0x10000 << tagIndex;
+
+ StringCopyPadded(sPSSData->field_21B8, GetBoxNamePtr(boxId), 0, 8);
+ DrawTextWindowAndBufferTiles(sPSSData->field_21B8, sPSSData->field_2F8, 0, 0, sPSSData->field_4F8, 2);
+ LoadSpriteSheet(&spriteSheet);
+ r6 = sub_8091F60(GetBoxNamePtr(boxId));
+
+ for (i = 0; i < 2; i++)
+ {
+ u8 spriteId = CreateSprite(&gUnknown_83D2B7C, r6 + i * 32, 28, 24);
+ sPSSData->field_720[i] = &gSprites[spriteId];
+ StartSpriteAnim(sPSSData->field_720[i], i);
+ }
+ sPSSData->field_6F8 = 0;
+}
+
+static void sub_8091C48(u8 boxId, s8 direction)
+{
+ u16 r8;
+ s16 x, x2;
+ u16 i;
+ struct SpriteSheet spriteSheet = {sPSSData->field_2F8, 0x200, TAG_TILE_3};
+ struct SpriteTemplate template = gUnknown_83D2B7C;
+
+ sPSSData->field_6F8 = (sPSSData->field_6F8 == 0);
+ if (sPSSData->field_6F8 == 0)
+ {
+ spriteSheet.tag = TAG_TILE_3;
+ r8 = sPSSData->field_71C;
+ }
+ else
+ {
+ spriteSheet.tag = TAG_TILE_4;
+ r8 = sPSSData->field_71C;
+ template.tileTag = TAG_TILE_4;
+ template.paletteTag = TAG_PAL_DAC9;
+ }
+
+ StringCopyPadded(sPSSData->field_21B8, GetBoxNamePtr(boxId), 0, 8);
+ DrawTextWindowAndBufferTiles(sPSSData->field_21B8, sPSSData->field_2F8, 0, 0, sPSSData->field_4F8, 2);
+ LoadSpriteSheet(&spriteSheet);
+ LoadPalette(gUnknown_83D29D0[GetBoxWallpaper(boxId)], r8, 4);
+ x = sub_8091F60(GetBoxNamePtr(boxId));
+ x2 = x;
+ x2 += direction * 192;
+
+ for (i = 0; i < 2; i++)
+ {
+ u8 spriteId = CreateSprite(&template, i * 32 + x2, 28, 24);
+
+ sPSSData->field_728[i] = &gSprites[spriteId];
+ sPSSData->field_728[i]->data[0] = (-direction) * 6;
+ sPSSData->field_728[i]->data[1] = i * 32 + x;
+ sPSSData->field_728[i]->data[2] = 0;
+ sPSSData->field_728[i]->callback = sub_8091E84;
+ StartSpriteAnim(sPSSData->field_728[i], i);
+
+ sPSSData->field_720[i]->data[0] = (-direction) * 6;
+ sPSSData->field_720[i]->data[1] = 1;
+ sPSSData->field_720[i]->callback = sub_8091EB8;
+ }
+}
+
+static void sub_8091E34(void)
+{
+ if (sPSSData->field_6F8 == 0)
+ FreeSpriteTilesByTag(TAG_TILE_4);
+ else
+ FreeSpriteTilesByTag(TAG_TILE_3);
+
+ sPSSData->field_720[0] = sPSSData->field_728[0];
+ sPSSData->field_720[1] = sPSSData->field_728[1];
+}
+
+static void sub_8091E84(struct Sprite *sprite)
+{
+ if (sprite->data[2] != 0)
+ sprite->data[2]--;
+ else if ((sprite->pos1.x += sprite->data[0]) == sprite->data[1])
+ sprite->callback = SpriteCallbackDummy;
+}
+
+static void sub_8091EB8(struct Sprite *sprite)
+{
+ if (sprite->data[1] != 0)
+ {
+ sprite->data[1]--;
+ }
+ else
+ {
+ sprite->pos1.x += sprite->data[0];
+ sprite->data[2] = sprite->pos1.x + sprite->pos2.x;
+ if (sprite->data[2] < 0x40 || sprite->data[2] > 0x100)
+ DestroySprite(sprite);
+ }
+}
+
+static void sub_8091EF0(void)
+{
+ u8 boxId = StorageGetCurrentBox();
+ u8 wallpaperId = GetBoxWallpaper(boxId);
+ if (sPSSData->field_6F8 == 0)
+ CpuCopy16(gUnknown_83D29D0[wallpaperId], gPlttBufferUnfaded + sPSSData->field_71C, 4);
+ else
+ CpuCopy16(gUnknown_83D29D0[wallpaperId], gPlttBufferUnfaded + sPSSData->field_71E, 4);
+}
+
+static s16 sub_8091F60(const u8 *string)
+{
+ return 0xB0 - GetStringWidth(1, string, 0) / 2;
+}
+
+static void sub_8091F80(void)
+{
+ u16 i;
+
+ LoadSpriteSheet(&gUnknown_83D2B54);
+ for (i = 0; i < 2; i++)
+ {
+ u8 spriteId = CreateSprite(&gUnknown_83D2BB4, 0x5c + i * 0x88, 28, 22);
+ if (spriteId != MAX_SPRITES)
+ {
+ struct Sprite *sprite = &gSprites[spriteId];
+ StartSpriteAnim(sprite, i);
+ sprite->data[3] = (i == 0) ? -1 : 1;
+ sPSSData->field_730[i] = sprite;
+ }
+ }
+ if (IsCursorOnBox())
+ sub_80920FC(TRUE);
+}
+
+static void sub_809200C(s8 direction)
+{
+ u16 i;
+
+ for (i = 0; i < 2; i++)
+ {
+ sPSSData->field_730[i]->pos2.x = 0;
+ sPSSData->field_730[i]->data[0] = 2;
+ }
+ if (direction < 0)
+ {
+ sPSSData->field_730[0]->data[1] = 29;
+ sPSSData->field_730[1]->data[1] = 5;
+ sPSSData->field_730[0]->data[2] = 0x48;
+ sPSSData->field_730[1]->data[2] = 0x48;
+ }
+ else
+ {
+ sPSSData->field_730[0]->data[1] = 5;
+ sPSSData->field_730[1]->data[1] = 29;
+ sPSSData->field_730[0]->data[2] = 0xF8;
+ sPSSData->field_730[1]->data[2] = 0xF8;
+ }
+ sPSSData->field_730[0]->data[7] = 0;
+ sPSSData->field_730[1]->data[7] = 1;
+}
+
+static void sub_80920AC(void)
+{
+ u16 i;
+
+ for (i = 0; i < 2; i++)
+ {
+ sPSSData->field_730[i]->pos1.x = 0x88 * i + 0x5c;
+ sPSSData->field_730[i]->pos2.x = 0;
+ sPSSData->field_730[i]->invisible = FALSE;
+ }
+ sub_80920FC(TRUE);
+}
+
+void sub_80920FC(bool8 a0)
+{
+ u16 i;
+
+ if (a0)
+ {
+ for (i = 0; i < 2; i++)
+ {
+ sPSSData->field_730[i]->data[0] = 1;
+ sPSSData->field_730[i]->data[1] = 0;
+ sPSSData->field_730[i]->data[2] = 0;
+ sPSSData->field_730[i]->data[4] = 0;
+ }
+ }
+ else
+ {
+ for (i = 0; i < 2; i++)
+ {
+ sPSSData->field_730[i]->data[0] = 0;
+ }
+ }
+}
+
+static void sub_8092164(struct Sprite *sprite)
+{
+ switch (sprite->data[0])
+ {
+ case 0:
+ sprite->pos2.x = 0;
+ break;
+ case 1:
+ if (++sprite->data[1] > 3)
+ {
+ sprite->data[1] = 0;
+ sprite->pos2.x += sprite->data[3];
+ if (++sprite->data[2] > 5)
+ {
+ sprite->data[2] = 0;
+ sprite->pos2.x = 0;
+ }
+ }
+ break;
+ case 2:
+ sprite->data[0] = 3;
+ break;
+ case 3:
+ sprite->pos1.x -= sPSSData->field_2CE;
+ if (sprite->pos1.x < 73 || sprite->pos1.x > 247)
+ sprite->invisible = TRUE;
+ if (--sprite->data[1] == 0)
+ {
+ sprite->pos1.x = sprite->data[2];
+ sprite->invisible = FALSE;
+ sprite->data[0] = 4;
+ }
+ break;
+ case 4:
+ sprite->pos1.x -= sPSSData->field_2CE;
+ break;
+ }
+}
+
+struct Sprite *sub_809223C(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority)
+{
+ u8 spriteId = CreateSprite(&gUnknown_83D2BB4, x, y, subpriority);
+ if (spriteId == MAX_SPRITES)
+ return NULL;
+
+ animId %= 2;
+ StartSpriteAnim(&gSprites[spriteId], animId);
+ gSprites[spriteId].oam.priority = priority;
+ gSprites[spriteId].callback = SpriteCallbackDummy;
+ return &gSprites[spriteId];
+}
diff --git a/src/pokemon_storage_system_5.c b/src/pokemon_storage_system_5.c
new file mode 100644
index 000000000..0b707537e
--- /dev/null
+++ b/src/pokemon_storage_system_5.c
@@ -0,0 +1,2036 @@
+#include "global.h"
+#include "gflib.h"
+#include "data.h"
+#include "item.h"
+#include "mail_data.h"
+#include "pokemon_storage_system_internal.h"
+#include "pokemon_summary_screen.h"
+#include "strings.h"
+#include "constants/items.h"
+#include "constants/moves.h"
+
+static EWRAM_DATA struct Pokemon gUnknown_20397BC = {};
+static EWRAM_DATA s8 sBoxCursorArea = 0;
+static EWRAM_DATA s8 sBoxCursorPosition = 0;
+static EWRAM_DATA bool8 sIsMonBeingMoved = FALSE;
+static EWRAM_DATA u8 sMovingMonOrigBoxId = 0;
+static EWRAM_DATA u8 sMovingMonOrigBoxPos = 0;
+static EWRAM_DATA bool8 sCanOnlyMove = FALSE;
+static EWRAM_DATA u8 gUnknown_2039826 = 0;
+
+static void sub_80929B0(void);
+static bool8 MonPlaceChange_Move(void);
+static bool8 MonPlaceChange_Place(void);
+static bool8 MonPlaceChange_Shift(void);
+static bool8 sub_8092E00(void);
+static bool8 sub_8092E10(void);
+static bool8 sub_8092E20(void);
+static bool8 sub_8092E54(void);
+static void MoveMon(void);
+static void PlaceMon(void);
+static void SetMovedMonData(u8 boxId, u8 cursorPos);
+static void SetPlacedMonData(u8 boxId, u8 cursorPos);
+static void PurgeMonOrBoxMon(u8 boxId, u8 cursorPos);
+static void SetShiftedMonData(u8 boxId, u8 cursorPos);
+static void sub_8093A10(void);
+static void SetCursorMonData(void * cursorMon, u8 mode);
+static void sub_8093AAC(void);
+static u8 InBoxInput_Normal(void);
+static u8 InBoxInput_GrabbingMultiple(void);
+static u8 InBoxInput_MovingMultiple(void);
+static void AddBoxMenu(void);
+static bool8 sub_8094924(void);
+static bool8 sub_809494C(void);
+static bool8 sub_8094A0C(void);
+static void sub_8094AD8(void);
+static void sub_8094C84(void);
+
+static const u16 gHandCursorPalette[] = INCBIN_U16("graphics/interface/pss_unk_83D2BCC.gbapal");
+static const u16 gHandCursorTiles[] = INCBIN_U16("graphics/interface/pss_unk_83D2BEC.4bpp");
+static const u16 gHandCursorShadowTiles[] = INCBIN_U16("graphics/interface/pss_unk_83D33EC.4bpp");
+
+void sub_80922C0(void)
+{
+ if (sPSSData->boxOption != BOX_OPTION_DEPOSIT)
+ sBoxCursorArea = CURSOR_AREA_IN_BOX;
+ else
+ sBoxCursorArea = CURSOR_AREA_IN_PARTY;
+
+ sBoxCursorPosition = 0;
+ sIsMonBeingMoved = FALSE;
+ sMovingMonOrigBoxId = 0;
+ sMovingMonOrigBoxPos = 0;
+ sCanOnlyMove = FALSE;
+ sub_8092B50();
+ sub_8094AD8();
+ sPSSData->field_CD6 = 1;
+ sPSSData->inBoxMovingMode = 0;
+ sub_8093A10();
+}
+
+void sub_8092340(void)
+{
+ sub_8094AD8();
+ sub_8093AAC();
+ sPSSData->field_CD6 = 1;
+ sPSSData->inBoxMovingMode = 0;
+ if (sIsMonBeingMoved)
+ {
+ sPSSData->movingMon = gUnknown_20397BC;
+ CreateMovingMonIcon();
+ }
+}
+
+static void sub_8092398(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y)
+{
+ switch (cursorArea)
+ {
+ case CURSOR_AREA_IN_BOX:
+ *x = (cursorPosition % IN_BOX_ROWS) * 24 + 100;
+ *y = (cursorPosition / IN_BOX_ROWS) * 24 + 32;
+ break;
+ case CURSOR_AREA_IN_PARTY:
+ if (cursorPosition == 0)
+ {
+ *x = 0x68;
+ *y = 0x34;
+ }
+ else if (cursorPosition == PARTY_SIZE)
+ {
+ *x = 0x98;
+ *y = 0x84;
+ }
+ else
+ {
+ *x = 0x98;
+ *y = (cursorPosition - 1) * 24 + 4;
+ }
+ break;
+ case CURSOR_AREA_BOX:
+ *x = 0xa2;
+ *y = 0x0c;
+ break;
+ case CURSOR_AREA_BUTTONS:
+ *y = sIsMonBeingMoved ? 8 : 14;
+ *x = cursorPosition * 0x58 + 0x78;
+ break;
+ case 4:
+ *x = 0xa0;
+ *y = 0x60;
+ break;
+ }
+}
+
+static u16 sub_8092458(void)
+{
+ switch (sBoxCursorArea)
+ {
+ case CURSOR_AREA_IN_PARTY:
+ return GetMonData(&gPlayerParty[sBoxCursorPosition], MON_DATA_SPECIES);
+ case CURSOR_AREA_IN_BOX:
+ return GetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_SPECIES);
+ default:
+ return SPECIES_NONE;
+ }
+}
+
+bool8 sub_80924A8(void)
+{
+ s16 tmp;
+
+ if (sPSSData->field_CD0 == 0)
+ {
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return FALSE;
+ else
+ return sub_809610C();
+ }
+ else if (--sPSSData->field_CD0 != 0)
+ {
+ sPSSData->field_CBC += sPSSData->field_CC4;
+ sPSSData->field_CC0 += sPSSData->field_CC8;
+ sPSSData->field_CB4->pos1.x = sPSSData->field_CBC >> 8;
+ sPSSData->field_CB4->pos1.y = sPSSData->field_CC0 >> 8;
+ if (sPSSData->field_CB4->pos1.x > 0x100)
+ {
+ tmp = sPSSData->field_CB4->pos1.x - 0x100;
+ sPSSData->field_CB4->pos1.x = tmp + 0x40;
+ }
+ if (sPSSData->field_CB4->pos1.x < 0x40)
+ {
+ tmp = 0x40 - sPSSData->field_CB4->pos1.x;
+ sPSSData->field_CB4->pos1.x = 0x100 - tmp;
+ }
+ if (sPSSData->field_CB4->pos1.y > 0xb0)
+ {
+ tmp = sPSSData->field_CB4->pos1.y - 0xb0;
+ sPSSData->field_CB4->pos1.y = tmp - 0x10;
+ }
+ if (sPSSData->field_CB4->pos1.y < -0x10)
+ {
+ tmp = -0x10 - sPSSData->field_CB4->pos1.y;
+ sPSSData->field_CB4->pos1.y = 0xb0 - tmp;
+ }
+ if (sPSSData->field_CD7 && --sPSSData->field_CD7 == 0)
+ sPSSData->field_CB4->vFlip = (sPSSData->field_CB4->vFlip == FALSE);
+ }
+ else
+ {
+ sPSSData->field_CB4->pos1.x = sPSSData->field_CCC;
+ sPSSData->field_CB4->pos1.y = sPSSData->field_CCE;
+ sub_80929B0();
+ }
+
+ return TRUE;
+}
+
+static void sub_8092604(u8 newCurosrArea, u8 newCursorPosition)
+{
+ u16 x, y;
+
+ sub_8092398(newCurosrArea, newCursorPosition, &x, &y);
+ sPSSData->field_CD4 = newCurosrArea;
+ sPSSData->field_CD5 = newCursorPosition;
+ sPSSData->field_CCC = x;
+ sPSSData->field_CCE = y;
+}
+
+static void sub_8092660(void)
+{
+ int r7, r0;
+
+ if (sPSSData->field_CD2 != 0 || sPSSData->field_CD3 != 0)
+ sPSSData->field_CD0 = 12;
+ else
+ sPSSData->field_CD0 = 6;
+
+ if (sPSSData->field_CD7)
+ sPSSData->field_CD7 = sPSSData->field_CD0 >> 1;
+
+ switch (sPSSData->field_CD2)
+ {
+ default:
+ r7 = sPSSData->field_CCE - sPSSData->field_CB4->pos1.y;
+ break;
+ case -1:
+ r7 = sPSSData->field_CCE - 0xc0 - sPSSData->field_CB4->pos1.y;
+ break;
+ case 1:
+ r7 = sPSSData->field_CCE + 0xc0 - sPSSData->field_CB4->pos1.y;
+ break;
+ }
+
+ switch (sPSSData->field_CD3)
+ {
+ default:
+ r0 = sPSSData->field_CCC - sPSSData->field_CB4->pos1.x;
+ break;
+ case -1:
+ r0 = sPSSData->field_CCC - 0xc0 - sPSSData->field_CB4->pos1.x;
+ break;
+ case 1:
+ r0 = sPSSData->field_CCC + 0xc0 - sPSSData->field_CB4->pos1.x;
+ break;
+ }
+
+ r7 <<= 8;
+ r0 <<= 8;
+ sPSSData->field_CC4 = r0 / sPSSData->field_CD0;
+ sPSSData->field_CC8 = r7 / sPSSData->field_CD0;
+ sPSSData->field_CBC = sPSSData->field_CB4->pos1.x << 8;
+ sPSSData->field_CC0 = sPSSData->field_CB4->pos1.y << 8;
+}
+
+static void sub_80927E8(u8 newCurosrArea, u8 newCursorPosition)
+{
+ sub_8092604(newCurosrArea, newCursorPosition);
+ sub_8092660();
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved)
+ StartSpriteAnim(sPSSData->field_CB4, 1);
+ }
+ else
+ {
+ if (!IsActiveItemMoving())
+ StartSpriteAnim(sPSSData->field_CB4, 1);
+ }
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ if (sBoxCursorArea == CURSOR_AREA_IN_BOX)
+ sub_8095D44(CURSOR_AREA_IN_BOX, sBoxCursorPosition);
+ else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ sub_8095D44(CURSOR_AREA_IN_PARTY, sBoxCursorPosition);
+
+ if (newCurosrArea == CURSOR_AREA_IN_BOX)
+ sub_8095C84(newCurosrArea, newCursorPosition);
+ else if (newCurosrArea == CURSOR_AREA_IN_PARTY)
+ sub_8095C84(newCurosrArea, newCursorPosition);
+ }
+
+ if (newCurosrArea == CURSOR_AREA_IN_PARTY && sBoxCursorArea != CURSOR_AREA_IN_PARTY)
+ {
+ sPSSData->field_CD6 = newCurosrArea;
+ sPSSData->field_CB8->invisible = TRUE;
+ }
+
+ switch (newCurosrArea)
+ {
+ case CURSOR_AREA_IN_PARTY:
+ case CURSOR_AREA_BOX:
+ case CURSOR_AREA_BUTTONS:
+ sPSSData->field_CB4->oam.priority = 1;
+ sPSSData->field_CB8->invisible = TRUE;
+ sPSSData->field_CB8->oam.priority = 1;
+ break;
+ case CURSOR_AREA_IN_BOX:
+ if (sPSSData->inBoxMovingMode != 0)
+ {
+ sPSSData->field_CB4->oam.priority = 0;
+ sPSSData->field_CB8->invisible = TRUE;
+ }
+ else
+ {
+ sPSSData->field_CB4->oam.priority = 2;
+ if (sBoxCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved)
+ SetMovingMonPriority(2);
+ }
+ break;
+ }
+}
+
+static void sub_80929B0(void)
+{
+ sBoxCursorArea = sPSSData->field_CD4;
+ sBoxCursorPosition = sPSSData->field_CD5;
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ {
+ if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved)
+ StartSpriteAnim(sPSSData->field_CB4, 1);
+ }
+ else
+ {
+ if (!IsActiveItemMoving())
+ StartSpriteAnim(sPSSData->field_CB4, 1);
+ }
+
+ sub_8093A10();
+ switch (sBoxCursorArea)
+ {
+ case CURSOR_AREA_BUTTONS:
+ SetMovingMonPriority(1);
+ break;
+ case CURSOR_AREA_BOX:
+ sub_80920FC(TRUE);
+ break;
+ case CURSOR_AREA_IN_PARTY:
+ sPSSData->field_CB8->subpriority = 13;
+ SetMovingMonPriority(1);
+ break;
+ case CURSOR_AREA_IN_BOX:
+ if (sPSSData->inBoxMovingMode == 0)
+ {
+ sPSSData->field_CB4->oam.priority = 1;
+ sPSSData->field_CB8->oam.priority = 2;
+ sPSSData->field_CB8->subpriority = 21;
+ sPSSData->field_CB8->invisible = FALSE;
+ SetMovingMonPriority(2);
+ }
+ break;
+ }
+}
+
+void sub_8092AE4(void)
+{
+ u8 partyCount;
+
+ if (!sIsMonBeingMoved)
+ {
+ partyCount = 0;
+ }
+ else
+ {
+ partyCount = CalculatePlayerPartyCount();
+ if (partyCount >= PARTY_SIZE)
+ partyCount = PARTY_SIZE - 1;
+ }
+ if (sPSSData->field_CB4->vFlip)
+ sPSSData->field_CD7 = 1;
+ sub_80927E8(CURSOR_AREA_IN_PARTY, partyCount);
+}
+
+void sub_8092B3C(u8 cursorBoxPosition)
+{
+ sub_80927E8(CURSOR_AREA_IN_BOX, cursorBoxPosition);
+}
+
+void sub_8092B50(void)
+{
+ gUnknown_2039826 = 0;
+}
+
+void sub_8092B5C(void)
+{
+ gUnknown_2039826 = sBoxCursorPosition;
+}
+
+u8 sub_8092B70(void)
+{
+ return gUnknown_2039826;
+}
+
+void InitMonPlaceChange(u8 a0)
+{
+ static bool8 (*const placeChangeFuncs[])(void) = {
+ MonPlaceChange_Move,
+ MonPlaceChange_Place,
+ MonPlaceChange_Shift,
+ };
+
+ sPSSData->monPlaceChangeFunc = placeChangeFuncs[a0];
+ sPSSData->monPlaceChangeState = 0;
+}
+
+void sub_8092BAC(bool8 arg0)
+{
+ if (!arg0)
+ sPSSData->monPlaceChangeFunc = sub_8092E00;
+ else
+ sPSSData->monPlaceChangeFunc = sub_8092E10;
+
+ sPSSData->monPlaceChangeState = 0;
+}
+
+bool8 DoMonPlaceChange(void)
+{
+ return sPSSData->monPlaceChangeFunc();
+}
+
+static bool8 MonPlaceChange_Move(void)
+{
+ switch (sPSSData->monPlaceChangeState)
+ {
+ case 0:
+ if (sIsMonBeingMoved)
+ return FALSE;
+ StartSpriteAnim(sPSSData->field_CB4, 2);
+ sPSSData->monPlaceChangeState++;
+ break;
+ case 1:
+ if (!sub_8092E20())
+ {
+ StartSpriteAnim(sPSSData->field_CB4, 3);
+ MoveMon();
+ sPSSData->monPlaceChangeState++;
+ }
+ break;
+ case 2:
+ if (!sub_8092E54())
+ sPSSData->monPlaceChangeState++;
+ break;
+ case 3:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static bool8 MonPlaceChange_Place(void)
+{
+ switch (sPSSData->monPlaceChangeState)
+ {
+ case 0:
+ if (!sub_8092E20())
+ {
+ StartSpriteAnim(sPSSData->field_CB4, 2);
+ PlaceMon();
+ sPSSData->monPlaceChangeState++;
+ }
+ break;
+ case 1:
+ if (!sub_8092E54())
+ {
+ StartSpriteAnim(sPSSData->field_CB4, 0);
+ sPSSData->monPlaceChangeState++;
+ }
+ break;
+ case 2:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static bool8 MonPlaceChange_Shift(void)
+{
+ switch (sPSSData->monPlaceChangeState)
+ {
+ case 0:
+ switch (sBoxCursorArea)
+ {
+ case CURSOR_AREA_IN_PARTY:
+ sPSSData->field_D91 = TOTAL_BOXES_COUNT;
+ break;
+ case CURSOR_AREA_IN_BOX:
+ sPSSData->field_D91 = StorageGetCurrentBox();
+ break;
+ default:
+ return FALSE;
+ }
+ StartSpriteAnim(sPSSData->field_CB4, 2);
+ sub_8090E08(sPSSData->field_D91, sBoxCursorPosition);
+ sPSSData->monPlaceChangeState++;
+ break;
+ case 1:
+ if (!sub_8090E74())
+ {
+ StartSpriteAnim(sPSSData->field_CB4, 3);
+ SetShiftedMonData(sPSSData->field_D91, sBoxCursorPosition);
+ sPSSData->monPlaceChangeState++;
+ }
+ break;
+ case 2:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static bool8 sub_8092E00(void)
+{
+ return sub_8092E20();
+}
+
+static bool8 sub_8092E10(void)
+{
+ return sub_8092E54();
+}
+
+static bool8 sub_8092E20(void)
+{
+ switch (sPSSData->field_CB4->pos2.y)
+ {
+ default:
+ sPSSData->field_CB4->pos2.y++;
+ break;
+ case 0:
+ sPSSData->field_CB4->pos2.y++;
+ break;
+ case 8:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static bool8 sub_8092E54(void)
+{
+ switch (sPSSData->field_CB4->pos2.y)
+ {
+ case 0:
+ return FALSE;
+ default:
+ sPSSData->field_CB4->pos2.y--;
+ break;
+ }
+
+ return TRUE;
+}
+
+static void MoveMon(void)
+{
+ switch (sBoxCursorArea)
+ {
+ case CURSOR_AREA_IN_PARTY:
+ SetMovedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition);
+ sub_8090CC0(MODE_PARTY, sBoxCursorPosition);
+ break;
+ case CURSOR_AREA_IN_BOX:
+ if (sPSSData->inBoxMovingMode == 0)
+ {
+ SetMovedMonData(StorageGetCurrentBox(), sBoxCursorPosition);
+ sub_8090CC0(MODE_BOX, sBoxCursorPosition);
+ }
+ break;
+ default:
+ return;
+ }
+
+ sIsMonBeingMoved = TRUE;
+}
+
+static void PlaceMon(void)
+{
+ u8 boxId;
+
+ switch (sBoxCursorArea)
+ {
+ case CURSOR_AREA_IN_PARTY:
+ SetPlacedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition);
+ sub_8090D58(TOTAL_BOXES_COUNT, sBoxCursorPosition);
+ break;
+ case CURSOR_AREA_IN_BOX:
+ boxId = StorageGetCurrentBox();
+ SetPlacedMonData(boxId, sBoxCursorPosition);
+ sub_8090D58(boxId, sBoxCursorPosition);
+ break;
+ default:
+ return;
+ }
+
+ sIsMonBeingMoved = FALSE;
+}
+
+void sub_8092F54(void)
+{
+ sub_8093A10();
+}
+
+static void SetMovedMonData(u8 boxId, u8 position)
+{
+ if (boxId == TOTAL_BOXES_COUNT)
+ sPSSData->movingMon = gPlayerParty[sBoxCursorPosition];
+ else
+ BoxMonAtToMon(boxId, position, &sPSSData->movingMon);
+
+ PurgeMonOrBoxMon(boxId, position);
+ sMovingMonOrigBoxId = boxId;
+ sMovingMonOrigBoxPos = position;
+}
+
+static void SetPlacedMonData(u8 boxId, u8 position)
+{
+ if (boxId == TOTAL_BOXES_COUNT)
+ {
+ gPlayerParty[position] = sPSSData->movingMon;
+ }
+ else
+ {
+ BoxMonRestorePP(&sPSSData->movingMon.box);
+ SetBoxMonAt(boxId, position, &sPSSData->movingMon.box);
+ }
+}
+
+static void PurgeMonOrBoxMon(u8 boxId, u8 position)
+{
+ if (boxId == TOTAL_BOXES_COUNT)
+ ZeroMonData(&gPlayerParty[position]);
+ else
+ ZeroBoxMonAt(boxId, position);
+}
+
+static void SetShiftedMonData(u8 boxId, u8 position)
+{
+ if (boxId == TOTAL_BOXES_COUNT)
+ sPSSData->field_2108 = gPlayerParty[position];
+ else
+ BoxMonAtToMon(boxId, position, &sPSSData->field_2108);
+
+ SetPlacedMonData(boxId, position);
+ sPSSData->movingMon = sPSSData->field_2108;
+ SetCursorMonData(&sPSSData->movingMon, MODE_PARTY);
+ sMovingMonOrigBoxId = boxId;
+ sMovingMonOrigBoxPos = position;
+}
+
+bool8 TryStorePartyMonInBox(u8 boxId)
+{
+ s16 boxPosition = GetFirstFreeBoxSpot(boxId);
+ if (boxPosition == -1)
+ return FALSE;
+
+ if (sIsMonBeingMoved)
+ {
+ SetPlacedMonData(boxId, boxPosition);
+ DestroyMovingMonIcon();
+ sIsMonBeingMoved = FALSE;
+ }
+ else
+ {
+ SetMovedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition);
+ SetPlacedMonData(boxId, boxPosition);
+ DestroyPartyMonIcon(sBoxCursorPosition);
+ }
+
+ if (boxId == StorageGetCurrentBox())
+ sub_80901EC(boxPosition);
+
+ StartSpriteAnim(sPSSData->field_CB4, 1);
+ return TRUE;
+}
+
+void sub_8093174(void)
+{
+ StartSpriteAnim(sPSSData->field_CB4, 0);
+ sub_8093A10();
+}
+
+void sub_8093194(void)
+{
+ u8 mode;
+
+ if (sIsMonBeingMoved)
+ mode = MODE_2;
+ else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ mode = MODE_PARTY;
+ else
+ mode = MODE_BOX;
+
+ sub_8090FC4(mode, sBoxCursorPosition);
+ StringCopy(sPSSData->field_21E0, sPSSData->cursorMonNick);
+}
+
+bool8 sub_80931EC(void)
+{
+ if (!sub_8091084())
+ {
+ StartSpriteAnim(sPSSData->field_CB4, 0);
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
+
+void ReleaseMon(void)
+{
+ u8 boxId;
+
+ sub_80910CC();
+ if (sIsMonBeingMoved)
+ {
+ sIsMonBeingMoved = FALSE;
+ }
+ else
+ {
+ if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ boxId = TOTAL_BOXES_COUNT;
+ else
+ boxId = StorageGetCurrentBox();
+
+ PurgeMonOrBoxMon(boxId, sBoxCursorPosition);
+ }
+ sub_8093A10();
+}
+
+void sub_8093264(void)
+{
+ if (sIsMonBeingMoved)
+ StartSpriteAnim(sPSSData->field_CB4, 3);
+}
+
+void InitCanReleaseMonVars(void)
+{
+ u16 knownIdx;
+ if (sIsMonBeingMoved)
+ {
+ sPSSData->field_2108 = sPSSData->movingMon;
+ sPSSData->field_2170 = -1;
+ sPSSData->field_2171 = -1;
+ }
+ else
+ {
+ if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ {
+ sPSSData->field_2108 = gPlayerParty[sBoxCursorPosition];
+ sPSSData->field_2170 = TOTAL_BOXES_COUNT;
+ }
+ else
+ {
+ BoxMonAtToMon(StorageGetCurrentBox(), sBoxCursorPosition, &sPSSData->field_2108);
+ sPSSData->field_2170 = StorageGetCurrentBox();
+ }
+ sPSSData->field_2171 = sBoxCursorPosition;
+ }
+
+ sPSSData->isSurfMon = FALSE;
+ sPSSData->isDiveMon = FALSE;
+ sPSSData->field_2176[0] = MOVE_SURF;
+ sPSSData->field_2176[1] = MOVE_DIVE;
+ sPSSData->field_2176[2] = MOVES_COUNT;
+ knownIdx = GetMonData(&sPSSData->field_2108, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176);
+ sPSSData->isSurfMon = knownIdx & 1;
+ sPSSData->isDiveMon = (knownIdx >> 1) & 1;
+ if (sPSSData->isSurfMon || sPSSData->isDiveMon)
+ {
+ sPSSData->field_216D = 0;
+ }
+ else
+ {
+ sPSSData->field_216D = 1;
+ sPSSData->field_216C = 1;
+ }
+
+ sPSSData->field_2172 = 0;
+}
+
+s8 RunCanReleaseMon(void)
+{
+ u16 i;
+ u16 knownMoves;
+
+ if (sPSSData->field_216D)
+ return sPSSData->field_216C;
+
+ switch (sPSSData->field_2172)
+ {
+ case 0:
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ if (sPSSData->field_2170 != TOTAL_BOXES_COUNT || sPSSData->field_2171 != i)
+ {
+ knownMoves = GetMonData(gPlayerParty + i, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176);
+ if (knownMoves & 1)
+ sPSSData->isSurfMon = FALSE;
+ if (knownMoves & 2)
+ sPSSData->isDiveMon = FALSE;
+ }
+ }
+ if (!(sPSSData->isSurfMon || sPSSData->isDiveMon))
+ {
+ sPSSData->field_216D = 1;
+ sPSSData->field_216C = 1;
+ }
+ else
+ {
+ sPSSData->field_216E = 0;
+ sPSSData->field_216F = 0;
+ sPSSData->field_2172++;
+ }
+ break;
+ case 1:
+ for (i = 0; i < 5; i++)
+ {
+ knownMoves = GetAndCopyBoxMonDataAt(sPSSData->field_216E, sPSSData->field_216F, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176);
+ if (knownMoves != 0
+ && !(sPSSData->field_2170 == sPSSData->field_216E && sPSSData->field_2171 == sPSSData->field_216F))
+ {
+ if (knownMoves & 1)
+ sPSSData->isSurfMon = FALSE;
+ if (knownMoves & 2)
+ sPSSData->isDiveMon = FALSE;
+ }
+ if (++sPSSData->field_216F >= IN_BOX_COUNT)
+ {
+ sPSSData->field_216F = 0;
+ if (++sPSSData->field_216E >= TOTAL_BOXES_COUNT)
+ {
+ sPSSData->field_216D = 1;
+ sPSSData->field_216C = 0;
+ break;
+ }
+ }
+ }
+ if (!(sPSSData->isSurfMon || sPSSData->isDiveMon))
+ {
+ sPSSData->field_216D = 1;
+ sPSSData->field_216C = 1;
+ }
+ break;
+ }
+
+ return -1;
+}
+
+void sub_8093630(void)
+{
+ if (sIsMonBeingMoved)
+ gUnknown_20397BC = sPSSData->movingMon;
+}
+
+void sub_8093660(void)
+{
+ if (sIsMonBeingMoved)
+ {
+ if (sMovingMonOrigBoxId == TOTAL_BOXES_COUNT)
+ sPSSData->movingMon = gUnknown_20397BC;
+ else
+ sPSSData->movingMon.box = gUnknown_20397BC.box;
+ }
+}
+
+void sub_80936B8(void)
+{
+ if (sIsMonBeingMoved)
+ {
+ sub_8093630();
+ sPSSData->field_218C.mon = &gUnknown_20397BC;
+ sPSSData->field_2187 = 0;
+ sPSSData->field_2186 = 0;
+ sPSSData->field_2188 = 0;
+ }
+ else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ {
+ sPSSData->field_218C.mon = gPlayerParty;
+ sPSSData->field_2187 = sBoxCursorPosition;
+ sPSSData->field_2186 = CountPartyMons() - 1;
+ sPSSData->field_2188 = 0;
+ }
+ else
+ {
+ sPSSData->field_218C.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0);
+ sPSSData->field_2187 = sBoxCursorPosition;
+ sPSSData->field_2186 = IN_BOX_COUNT - 1;
+ sPSSData->field_2188 = 5;
+ }
+}
+
+void sub_80937B4(void)
+{
+ if (sIsMonBeingMoved)
+ sub_8093660();
+ else
+ sBoxCursorPosition = GetLastViewedMonIndex();
+}
+
+// file boundary maybe?
+
+s16 CompactPartySlots(void)
+{
+ s16 retVal = -1;
+ u16 i, last;
+
+ for (i = 0, last = 0; i < PARTY_SIZE; i++)
+ {
+ u16 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES);
+ if (species != SPECIES_NONE)
+ {
+ if (i != last)
+ gPlayerParty[last] = gPlayerParty[i];
+ last++;
+ }
+ else if (retVal == -1)
+ {
+ retVal = i;
+ }
+ }
+ for (; last < PARTY_SIZE; last++)
+ ZeroMonData(gPlayerParty + last);
+
+ return retVal;
+}
+
+void SetMonMarkings(u8 markings)
+{
+ sPSSData->cursorMonMarkings = markings;
+ if (sIsMonBeingMoved)
+ {
+ SetMonData(&sPSSData->movingMon, MON_DATA_MARKINGS, &markings);
+ }
+ else
+ {
+ if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ SetMonData(gPlayerParty + sBoxCursorPosition, MON_DATA_MARKINGS, &markings);
+ if (sBoxCursorArea == CURSOR_AREA_IN_BOX)
+ SetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_MARKINGS, &markings);
+ }
+}
+
+bool8 CanMovePartyMon(void)
+{
+ if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && !sIsMonBeingMoved && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+bool8 CanShiftMon(void)
+{
+ if (sIsMonBeingMoved)
+ {
+ if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0)
+ {
+ if (sPSSData->cursorMonIsEgg || GetMonData(&sPSSData->movingMon, MON_DATA_HP) == 0)
+ return FALSE;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 IsMonBeingMoved(void)
+{
+ return sIsMonBeingMoved;
+}
+
+bool8 IsCursorOnBox(void)
+{
+ return (sBoxCursorArea == CURSOR_AREA_BOX);
+}
+
+bool8 IsCursorOnCloseBox(void)
+{
+ return (sBoxCursorArea == CURSOR_AREA_BUTTONS && sBoxCursorPosition == 1);
+}
+
+bool8 IsCursorInBox(void)
+{
+ return (sBoxCursorArea == CURSOR_AREA_IN_BOX);
+}
+
+static void sub_8093A10(void)
+{
+ sPSSData->setMosaic = (sIsMonBeingMoved == FALSE);
+ if (!sIsMonBeingMoved)
+ {
+ switch (sBoxCursorArea)
+ {
+ case CURSOR_AREA_IN_PARTY:
+ if (sBoxCursorPosition < PARTY_SIZE)
+ {
+ SetCursorMonData(&gPlayerParty[sBoxCursorPosition], MODE_PARTY);
+ break;
+ }
+ // fallthrough
+ case CURSOR_AREA_BUTTONS:
+ case CURSOR_AREA_BOX:
+ SetCursorMonData(NULL, MODE_2);
+ break;
+ case CURSOR_AREA_IN_BOX:
+ SetCursorMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sBoxCursorPosition), MODE_BOX);
+ break;
+ }
+ }
+}
+
+static void sub_8093AAC(void)
+{
+ if (sIsMonBeingMoved)
+ SetCursorMonData(&gUnknown_20397BC, MODE_PARTY);
+ else
+ sub_8093A10();
+}
+
+static void SetCursorMonData(void *pokemon, u8 mode)
+{
+ u8 *txtPtr;
+ u16 gender;
+ bool8 sanityIsBagEgg;
+
+ sPSSData->cursorMonItem = 0;
+ gender = MON_MALE;
+ sanityIsBagEgg = FALSE;
+ if (mode == MODE_PARTY)
+ {
+ struct Pokemon *mon = (struct Pokemon *)pokemon;
+
+ sPSSData->cursorMonSpecies = GetMonData(mon, MON_DATA_SPECIES2);
+ if (sPSSData->cursorMonSpecies != SPECIES_NONE)
+ {
+ sanityIsBagEgg = GetMonData(mon, MON_DATA_SANITY_IS_BAD_EGG);
+ if (sanityIsBagEgg)
+ sPSSData->cursorMonIsEgg = TRUE;
+ else
+ sPSSData->cursorMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG);
+
+ GetMonData(mon, MON_DATA_NICKNAME, sPSSData->cursorMonNick);
+ StringGetEnd10(sPSSData->cursorMonNick);
+ sPSSData->cursorMonLevel = GetMonData(mon, MON_DATA_LEVEL);
+ sPSSData->cursorMonMarkings = GetMonData(mon, MON_DATA_MARKINGS);
+ sPSSData->cursorMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY);
+ sPSSData->cursorMonPalette = GetMonFrontSpritePal(mon);
+ gender = GetMonGender(mon);
+ sPSSData->cursorMonItem = GetMonData(mon, MON_DATA_HELD_ITEM);
+ }
+ }
+ else if (mode == MODE_BOX)
+ {
+ struct BoxPokemon *boxMon = (struct BoxPokemon *)pokemon;
+
+ sPSSData->cursorMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2);
+ if (sPSSData->cursorMonSpecies != SPECIES_NONE)
+ {
+ u32 otId = GetBoxMonData(boxMon, MON_DATA_OT_ID);
+ sanityIsBagEgg = GetBoxMonData(boxMon, MON_DATA_SANITY_IS_BAD_EGG);
+ if (sanityIsBagEgg)
+ sPSSData->cursorMonIsEgg = TRUE;
+ else
+ sPSSData->cursorMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG);
+
+
+ GetBoxMonData(boxMon, MON_DATA_NICKNAME, sPSSData->cursorMonNick);
+ StringGetEnd10(sPSSData->cursorMonNick);
+ sPSSData->cursorMonLevel = GetLevelFromBoxMonExp(boxMon);
+ sPSSData->cursorMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS);
+ sPSSData->cursorMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY);
+ sPSSData->cursorMonPalette = GetMonSpritePalFromSpeciesAndPersonality(sPSSData->cursorMonSpecies, otId, sPSSData->cursorMonPersonality);
+ gender = GetGenderFromSpeciesAndPersonality(sPSSData->cursorMonSpecies, sPSSData->cursorMonPersonality);
+ sPSSData->cursorMonItem = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM);
+ }
+ }
+ else
+ {
+ sPSSData->cursorMonSpecies = SPECIES_NONE;
+ sPSSData->cursorMonItem = 0;
+ }
+
+ if (sPSSData->cursorMonSpecies == SPECIES_NONE)
+ {
+ StringFill(sPSSData->cursorMonNick, CHAR_SPACE, 5);
+ StringFill(sPSSData->cursorMonTexts[0], CHAR_SPACE, 8);
+ StringFill(sPSSData->cursorMonTexts[1], CHAR_SPACE, 8);
+ StringFill(sPSSData->cursorMonTexts[2], CHAR_SPACE, 8);
+ StringFill(sPSSData->cursorMonTexts[3], CHAR_SPACE, 8);
+ }
+ else if (sPSSData->cursorMonIsEgg)
+ {
+ if (sanityIsBagEgg)
+ StringCopyPadded(sPSSData->cursorMonTexts[0], sPSSData->cursorMonNick, CHAR_SPACE, 5);
+ else
+ StringCopyPadded(sPSSData->cursorMonTexts[0], gText_EggNickname, CHAR_SPACE, 8);
+
+ StringFill(sPSSData->cursorMonTexts[1], CHAR_SPACE, 8);
+ StringFill(sPSSData->cursorMonTexts[2], CHAR_SPACE, 8);
+ StringFill(sPSSData->cursorMonTexts[3], CHAR_SPACE, 8);
+ }
+ else
+ {
+ if (sPSSData->cursorMonSpecies == SPECIES_NIDORAN_F || sPSSData->cursorMonSpecies == SPECIES_NIDORAN_M)
+ gender = MON_GENDERLESS;
+
+ StringCopyPadded(sPSSData->cursorMonTexts[0], sPSSData->cursorMonNick, CHAR_SPACE, 5);
+
+ txtPtr = sPSSData->cursorMonTexts[1];
+ *(txtPtr)++ = CHAR_SLASH;
+ StringCopyPadded(txtPtr, gSpeciesNames[sPSSData->cursorMonSpecies], CHAR_SPACE, 5);
+
+ txtPtr = sPSSData->cursorMonTexts[2];
+ *(txtPtr)++ = EXT_CTRL_CODE_BEGIN;
+ *(txtPtr)++ = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW;
+ switch (gender)
+ {
+ case MON_MALE:
+ *(txtPtr)++ = TEXT_COLOR_RED;
+ *(txtPtr)++ = TEXT_COLOR_WHITE;
+ *(txtPtr)++ = TEXT_COLOR_LIGHT_RED;
+ *(txtPtr)++ = CHAR_MALE;
+ break;
+ case MON_FEMALE:
+ *(txtPtr)++ = TEXT_COLOR_GREEN;
+ *(txtPtr)++ = TEXT_COLOR_WHITE;
+ *(txtPtr)++ = TEXT_COLOR_LIGHT_GREEN;
+ *(txtPtr)++ = CHAR_FEMALE;
+ break;
+ default:
+ *(txtPtr)++ = TEXT_COLOR_DARK_GREY;
+ *(txtPtr)++ = TEXT_COLOR_WHITE;
+ *(txtPtr)++ = TEXT_COLOR_LIGHT_GREY;
+ *(txtPtr)++ = CHAR_SPACE;
+ break;
+ }
+
+ *(txtPtr++) = EXT_CTRL_CODE_BEGIN;
+ *(txtPtr++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW;
+ *(txtPtr++) = TEXT_COLOR_DARK_GREY;
+ *(txtPtr++) = TEXT_COLOR_WHITE;
+ *(txtPtr++) = TEXT_COLOR_LIGHT_GREY;
+ *(txtPtr++) = CHAR_SPACE;
+ *(txtPtr++) = CHAR_EXTRA_EMOJI;
+ *(txtPtr++) = 5; // LV_2
+
+ txtPtr = ConvertIntToDecimalStringN(txtPtr, sPSSData->cursorMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3);
+ txtPtr[0] = CHAR_SPACE;
+ txtPtr[1] = EOS;
+
+ if (sPSSData->cursorMonItem != 0)
+ StringCopyPadded(sPSSData->cursorMonTexts[3], ItemId_GetName(sPSSData->cursorMonItem), CHAR_SPACE, 8);
+ else
+ StringFill(sPSSData->cursorMonTexts[3], CHAR_SPACE, 8);
+ }
+}
+
+static u8 HandleInput_InBox(void)
+{
+ switch (sPSSData->inBoxMovingMode)
+ {
+ case 0:
+ default:
+ return InBoxInput_Normal();
+ case 1:
+ return InBoxInput_GrabbingMultiple();
+ case 2:
+ return InBoxInput_MovingMultiple();
+ }
+}
+
+static u8 InBoxInput_Normal(void)
+{
+ u8 retVal;
+ s8 cursorArea;
+ s8 cursorPosition;
+
+ do
+ {
+ cursorArea = sBoxCursorArea;
+ cursorPosition = sBoxCursorPosition;
+ sPSSData->field_CD2 = 0;
+ sPSSData->field_CD3 = 0;
+ sPSSData->field_CD7 = 0;
+ if (JOY_REPT(DPAD_UP))
+ {
+ retVal = TRUE;
+ if (sBoxCursorPosition >= IN_BOX_ROWS)
+ {
+ cursorPosition -= IN_BOX_ROWS;
+ }
+ else
+ {
+ cursorArea = CURSOR_AREA_BOX;
+ cursorPosition = 0;
+ }
+ break;
+ }
+ else if (JOY_REPT(DPAD_DOWN))
+ {
+ retVal = TRUE;
+ cursorPosition += IN_BOX_ROWS;
+ if (cursorPosition >= IN_BOX_COUNT)
+ {
+ cursorArea = CURSOR_AREA_BUTTONS;
+ cursorPosition -= IN_BOX_COUNT;
+ cursorPosition /= 3;
+ sPSSData->field_CD2 = 1;
+ sPSSData->field_CD7 = 1;
+ }
+ break;
+ }
+ else if (JOY_REPT(DPAD_LEFT))
+ {
+ retVal = TRUE;
+ if (sBoxCursorPosition % IN_BOX_ROWS != 0)
+ {
+ cursorPosition--;
+ }
+ else
+ {
+ sPSSData->field_CD3 = -1;
+ cursorPosition += (IN_BOX_ROWS - 1);
+ }
+ break;
+ }
+ else if (JOY_REPT(DPAD_RIGHT))
+ {
+ retVal = TRUE;
+ if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0)
+ {
+ cursorPosition++;
+ }
+ else
+ {
+ sPSSData->field_CD3 = 1;
+ cursorPosition -= (IN_BOX_ROWS - 1);
+ }
+ break;
+ }
+ else if (JOY_NEW(START_BUTTON))
+ {
+ retVal = TRUE;
+ cursorArea = CURSOR_AREA_BOX;
+ cursorPosition = 0;
+ break;
+ }
+
+ if ((JOY_NEW(A_BUTTON)) && sub_8094924())
+ {
+ if (!sCanOnlyMove)
+ return 8;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE)
+ {
+ switch (sub_8094E50(0))
+ {
+ case PC_TEXT_STORE:
+ return 11;
+ case PC_TEXT_WITHDRAW:
+ return 12;
+ case PC_TEXT_MOVE:
+ return 13;
+ case PC_TEXT_SHIFT:
+ return 14;
+ case PC_TEXT_PLACE:
+ return 15;
+ case PC_TEXT_TAKE:
+ return 16;
+ case PC_TEXT_GIVE:
+ return 17;
+ case PC_TEXT_SWITCH:
+ return 18;
+ }
+ }
+ else
+ {
+ sPSSData->inBoxMovingMode = 1;
+ return 20;
+ }
+ }
+
+ if (JOY_NEW(B_BUTTON))
+ return 19;
+
+ if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)
+ {
+ if (JOY_HELD(L_BUTTON))
+ return 10;
+ if (JOY_HELD(R_BUTTON))
+ return 9;
+ }
+
+ if (JOY_NEW(SELECT_BUTTON))
+ {
+ sub_8094C84();
+ return 0;
+ }
+
+ retVal = 0;
+
+ } while (0);
+
+ if (retVal)
+ sub_80927E8(cursorArea, cursorPosition);
+
+ return retVal;
+}
+
+static u8 InBoxInput_GrabbingMultiple(void)
+{
+ if (JOY_HELD(A_BUTTON))
+ {
+ if (JOY_REPT(DPAD_UP))
+ {
+ if (sBoxCursorPosition / IN_BOX_ROWS != 0)
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS);
+ return 21;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else if (JOY_REPT(DPAD_DOWN))
+ {
+ if (sBoxCursorPosition + IN_BOX_ROWS < IN_BOX_COUNT)
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS);
+ return 21;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else if (JOY_REPT(DPAD_LEFT))
+ {
+ if (sBoxCursorPosition % IN_BOX_ROWS != 0)
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1);
+ return 21;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else if (JOY_REPT(DPAD_RIGHT))
+ {
+ if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0)
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1);
+ return 21;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ if (sub_8095AA0() == sBoxCursorPosition)
+ {
+ sPSSData->inBoxMovingMode = 0;
+ sPSSData->field_CB8->invisible = FALSE;
+ return 22;
+ }
+ else
+ {
+ sIsMonBeingMoved = (sPSSData->cursorMonSpecies != SPECIES_NONE);
+ sPSSData->inBoxMovingMode = 2;
+ sMovingMonOrigBoxId = StorageGetCurrentBox();
+ return 23;
+ }
+ }
+}
+
+static u8 InBoxInput_MovingMultiple(void)
+{
+ if (JOY_REPT(DPAD_UP))
+ {
+ if (sub_8095474(0))
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS);
+ return 25;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else if (JOY_REPT(DPAD_DOWN))
+ {
+ if (sub_8095474(1))
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS);
+ return 25;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else if (JOY_REPT(DPAD_LEFT))
+ {
+ if (sub_8095474(2))
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1);
+ return 25;
+ }
+ else
+ {
+ return 10;
+ }
+ }
+ else if (JOY_REPT(DPAD_RIGHT))
+ {
+ if (sub_8095474(3))
+ {
+ sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1);
+ return 25;
+ }
+ else
+ {
+ return 9;
+ }
+ }
+ else if (JOY_NEW(A_BUTTON))
+ {
+ if (sub_8095ABC())
+ {
+ sIsMonBeingMoved = FALSE;
+ sPSSData->inBoxMovingMode = 0;
+ return 26;
+ }
+ else
+ {
+ return 24;
+ }
+ }
+ else if (JOY_NEW(B_BUTTON))
+ {
+ return 24;
+ }
+ else
+ {
+ if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)
+ {
+ if (JOY_HELD(L_BUTTON))
+ return 10;
+ if (JOY_HELD(R_BUTTON))
+ return 9;
+ }
+
+ return 0;
+ }
+}
+
+static u8 HandleInput_InParty(void)
+{
+ u8 retVal;
+ bool8 gotoBox;
+ s8 cursorArea;
+ s8 cursorPosition;
+
+ do
+ {
+ cursorArea = sBoxCursorArea;
+ cursorPosition = sBoxCursorPosition;
+ sPSSData->field_CD3 = 0;
+ sPSSData->field_CD2 = 0;
+ sPSSData->field_CD7 = 0;
+ gotoBox = FALSE;
+ retVal = 0;
+
+ if (JOY_REPT(DPAD_UP))
+ {
+ if (--cursorPosition < 0)
+ cursorPosition = PARTY_SIZE;
+ if (cursorPosition != sBoxCursorPosition)
+ retVal = 1;
+ break;
+ }
+ else if (JOY_REPT(DPAD_DOWN))
+ {
+ if (++cursorPosition > PARTY_SIZE)
+ cursorPosition = 0;
+ if (cursorPosition != sBoxCursorPosition)
+ retVal = 1;
+ break;
+ }
+ else if (JOY_REPT(DPAD_LEFT) && sBoxCursorPosition != 0)
+ {
+ retVal = 1;
+ sPSSData->field_CD6 = sBoxCursorPosition;
+ cursorPosition = 0;
+ break;
+ }
+ else if (JOY_REPT(DPAD_RIGHT))
+ {
+ if (sBoxCursorPosition == 0)
+ {
+ retVal = 1;
+ cursorPosition = sPSSData->field_CD6;
+ }
+ else
+ {
+ retVal = 6;
+ cursorArea = CURSOR_AREA_IN_BOX;
+ cursorPosition = 0;
+ }
+ break;
+ }
+
+ if (JOY_NEW(A_BUTTON))
+ {
+ if (sBoxCursorPosition == PARTY_SIZE)
+ {
+ if (sPSSData->boxOption == BOX_OPTION_DEPOSIT)
+ return 4;
+
+ gotoBox = TRUE;
+ }
+ else if (sub_8094924())
+ {
+ if (!sCanOnlyMove)
+ return 8;
+
+ switch (sub_8094E50(0))
+ {
+ case PC_TEXT_STORE:
+ return 11;
+ case PC_TEXT_WITHDRAW:
+ return 12;
+ case PC_TEXT_MOVE:
+ return 13;
+ case PC_TEXT_SHIFT:
+ return 14;
+ case PC_TEXT_PLACE:
+ return 15;
+ case PC_TEXT_TAKE:
+ return 16;
+ case PC_TEXT_GIVE:
+ return 17;
+ case PC_TEXT_SWITCH:
+ return 18;
+ }
+ }
+ }
+
+ if (JOY_NEW(B_BUTTON))
+ {
+ if (sPSSData->boxOption == BOX_OPTION_DEPOSIT)
+ return 19;
+
+ gotoBox = TRUE;
+ }
+
+ if (gotoBox)
+ {
+ retVal = 6;
+ cursorArea = CURSOR_AREA_IN_BOX;
+ cursorPosition = 0;
+ }
+ else if (JOY_NEW(SELECT_BUTTON))
+ {
+ sub_8094C84();
+ return 0;
+ }
+
+ } while (0);
+
+ if (retVal != 0)
+ {
+ if (retVal != 6)
+ sub_80927E8(cursorArea, cursorPosition);
+ }
+
+ return retVal;
+}
+
+static u8 HandleInput_OnBox(void)
+{
+ u8 retVal;
+ s8 cursorArea;
+ s8 cursorPosition;
+
+ do
+ {
+ sPSSData->field_CD3 = 0;
+ sPSSData->field_CD2 = 0;
+ sPSSData->field_CD7 = 0;
+
+ if (JOY_REPT(DPAD_UP))
+ {
+ retVal = 1;
+ cursorArea = CURSOR_AREA_BUTTONS;
+ cursorPosition = 0;
+ sPSSData->field_CD7 = 1;
+ break;
+ }
+ else if (JOY_REPT(DPAD_DOWN))
+ {
+ retVal = 1;
+ cursorArea = CURSOR_AREA_IN_BOX;
+ cursorPosition = 2;
+ break;
+ }
+
+ if (JOY_HELD(DPAD_LEFT))
+ return 10;
+ if (JOY_HELD(DPAD_RIGHT))
+ return 9;
+
+ if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)
+ {
+ if (JOY_HELD(L_BUTTON))
+ return 10;
+ if (JOY_HELD(R_BUTTON))
+ return 9;
+ }
+
+ if (JOY_NEW(A_BUTTON))
+ {
+ sub_80920FC(FALSE);
+ AddBoxMenu();
+ return 7;
+ }
+
+ if (JOY_NEW(B_BUTTON))
+ return 19;
+
+ if (JOY_NEW(SELECT_BUTTON))
+ {
+ sub_8094C84();
+ return 0;
+ }
+
+ retVal = 0;
+
+ } while (0);
+
+ if (retVal)
+ {
+ if (cursorArea != CURSOR_AREA_BOX)
+ sub_80920FC(FALSE);
+ sub_80927E8(cursorArea, cursorPosition);
+ }
+
+ return retVal;
+}
+
+static u8 HandleInput_OnButtons(void)
+{
+ u8 retVal;
+ s8 cursorArea;
+ s8 cursorPosition;
+ s8 prevPos;
+
+ do
+ {
+ cursorArea = sBoxCursorArea;
+ cursorPosition = sBoxCursorPosition;
+ sPSSData->field_CD3 = 0;
+ sPSSData->field_CD2 = 0;
+ sPSSData->field_CD7 = 0;
+
+ if (JOY_REPT(DPAD_UP))
+ {
+ retVal = 1;
+ cursorArea = CURSOR_AREA_IN_BOX;
+ sPSSData->field_CD2 = -1;
+ if (sBoxCursorPosition == 0)
+ cursorPosition = IN_BOX_COUNT - 1 - 5;
+ else
+ cursorPosition = IN_BOX_COUNT - 1;
+ sPSSData->field_CD7 = 1;
+ break;
+ }
+ else if (JOY_REPT(DPAD_DOWN | START_BUTTON))
+ {
+ retVal = 1;
+ cursorArea = CURSOR_AREA_BOX;
+ cursorPosition = 0;
+ sPSSData->field_CD7 = 1;
+ break;
+ }
+
+ if (JOY_REPT(DPAD_LEFT))
+ {
+ retVal = 1;
+ if (--cursorPosition < 0)
+ cursorPosition = 1;
+ break;
+ }
+ else if (JOY_REPT(DPAD_RIGHT))
+ {
+ retVal = 1;
+ if (++cursorPosition > 1)
+ cursorPosition = 0;
+ break;
+ }
+
+ if (JOY_NEW(A_BUTTON))
+ {
+ return cursorPosition == 0 ? 5 : 4;
+ }
+ if (JOY_NEW(B_BUTTON))
+ return 19;
+
+ if (JOY_NEW(SELECT_BUTTON))
+ {
+ sub_8094C84();
+ return 0;
+ }
+
+ retVal = 0;
+ } while (0);
+
+ if (retVal != 0)
+ sub_80927E8(cursorArea, cursorPosition);
+
+ return retVal;
+}
+
+u8 HandleInput(void)
+{
+ struct
+ {
+ u8 (*func)(void);
+ s8 area;
+ }
+ static const inputFuncs[] = {
+ {HandleInput_InBox, CURSOR_AREA_IN_BOX},
+ {HandleInput_InParty, CURSOR_AREA_IN_PARTY},
+ {HandleInput_OnBox, CURSOR_AREA_BOX},
+ {HandleInput_OnButtons, CURSOR_AREA_BUTTONS},
+ {NULL, 0},
+ };
+
+ u16 i = 0;
+ while (inputFuncs[i].func != NULL)
+ {
+ if (inputFuncs[i].area == sBoxCursorArea)
+ return inputFuncs[i].func();
+ i++;
+ }
+
+ return 0;
+}
+
+static void AddBoxMenu(void)
+{
+ InitMenu();
+ SetMenuText(PC_TEXT_JUMP);
+ SetMenuText(PC_TEXT_WALLPAPER);
+ SetMenuText(PC_TEXT_NAME);
+ SetMenuText(PC_TEXT_CANCEL);
+}
+
+static bool8 sub_8094924(void)
+{
+ InitMenu();
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return sub_809494C();
+ else
+ return sub_8094A0C();
+}
+
+static bool8 sub_809494C(void)
+{
+ u16 var0 = sub_8092458();
+
+ switch (sPSSData->boxOption)
+ {
+ case BOX_OPTION_DEPOSIT:
+ if (var0)
+ SetMenuText(PC_TEXT_STORE);
+ else
+ return FALSE;
+ break;
+ case BOX_OPTION_WITHDRAW:
+ if (var0)
+ SetMenuText(PC_TEXT_WITHDRAW);
+ else
+ return FALSE;
+ break;
+ case BOX_OPTION_MOVE_MONS:
+ if (sIsMonBeingMoved)
+ {
+ if (var0)
+ SetMenuText(PC_TEXT_SHIFT);
+ else
+ SetMenuText(PC_TEXT_PLACE);
+ }
+ else
+ {
+ if (var0)
+ SetMenuText(PC_TEXT_MOVE);
+ else
+ return FALSE;
+ }
+ break;
+ case BOX_OPTION_MOVE_ITEMS:
+ default:
+ return FALSE;
+ }
+
+ SetMenuText(PC_TEXT_SUMMARY);
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_MONS)
+ {
+ if (!sBoxCursorArea)
+ SetMenuText(PC_TEXT_WITHDRAW);
+ else
+ SetMenuText(PC_TEXT_STORE);
+ }
+
+ SetMenuText(PC_TEXT_MARK);
+ SetMenuText(PC_TEXT_RELEASE);
+ SetMenuText(PC_TEXT_CANCEL);
+ return TRUE;
+}
+
+static bool8 sub_8094A0C(void)
+{
+ if (sPSSData->cursorMonSpecies == SPECIES_EGG)
+ return FALSE;
+
+ if (!IsActiveItemMoving())
+ {
+ if (sPSSData->cursorMonItem == ITEM_NONE)
+ {
+ if (sPSSData->cursorMonSpecies == SPECIES_NONE)
+ return FALSE;
+
+ SetMenuText(PC_TEXT_GIVE2);
+ }
+ else
+ {
+ if (!ItemIsMail(sPSSData->cursorMonItem))
+ {
+ SetMenuText(PC_TEXT_TAKE);
+ SetMenuText(PC_TEXT_BAG);
+ }
+ SetMenuText(PC_TEXT_INFO);
+ }
+ }
+ else
+ {
+ if (sPSSData->cursorMonItem == ITEM_NONE)
+ {
+ if (sPSSData->cursorMonSpecies == SPECIES_NONE)
+ return FALSE;
+
+ SetMenuText(PC_TEXT_GIVE);
+ }
+ else
+ {
+ if (ItemIsMail(sPSSData->cursorMonItem) == TRUE)
+ return FALSE;
+
+ SetMenuText(PC_TEXT_SWITCH);
+ }
+ }
+
+ SetMenuText(PC_TEXT_CANCEL);
+ return TRUE;
+}
+
+static void sub_8094AB8(struct Sprite *sprite)
+{
+ sprite->pos1.x = sPSSData->field_CB4->pos1.x;
+ sprite->pos1.y = sPSSData->field_CB4->pos1.y + 20;
+}
+
+static void sub_8094AD8(void)
+{
+ u16 x, y;
+ u8 spriteId;
+ u8 priority, subpriority;
+ struct SpriteSheet spriteSheets[] = {
+ {gHandCursorTiles, 0x800, TAG_TILE_0},
+ {gHandCursorShadowTiles, 0x80, TAG_TILE_1},
+ {}
+ };
+
+ struct SpritePalette spritePalettes[] = {
+ {gHandCursorPalette, TAG_PAL_DAC7},
+ {}
+ };
+
+ static const struct OamData sOamData_857BA0C = {
+ .shape = SPRITE_SHAPE(32x32),
+ .size = SPRITE_SIZE(32x32),
+ .priority = 1,
+ };
+ static const struct OamData sOamData_857BA14 = {
+ .shape = SPRITE_SHAPE(16x16),
+ .size = SPRITE_SIZE(16x16),
+ .priority = 1,
+ };
+
+ static const union AnimCmd sSpriteAnim_857BA1C[] = {
+ ANIMCMD_FRAME(0, 30),
+ ANIMCMD_FRAME(16, 30),
+ ANIMCMD_JUMP(0)
+ };
+ static const union AnimCmd sSpriteAnim_857BA28[] = {
+ ANIMCMD_FRAME(0, 5),
+ ANIMCMD_END
+ };
+ static const union AnimCmd sSpriteAnim_857BA30[] = {
+ ANIMCMD_FRAME(32, 5),
+ ANIMCMD_END
+ };
+ static const union AnimCmd sSpriteAnim_857BA38[] = {
+ ANIMCMD_FRAME(48, 5),
+ ANIMCMD_END
+ };
+
+ static const union AnimCmd *const sSpriteAnimTable_857BA40[] = {
+ sSpriteAnim_857BA1C,
+ sSpriteAnim_857BA28,
+ sSpriteAnim_857BA30,
+ sSpriteAnim_857BA38
+ };
+
+ static const struct SpriteTemplate gSpriteTemplate_857BA50 = {
+ .tileTag = TAG_TILE_0,
+ .paletteTag = TAG_PAL_WAVEFORM,
+ .oam = &sOamData_857BA0C,
+ .anims = sSpriteAnimTable_857BA40,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCallbackDummy,
+ };
+
+ static const struct SpriteTemplate gSpriteTemplate_857BA68 = {
+ .tileTag = TAG_TILE_1,
+ .paletteTag = TAG_PAL_WAVEFORM,
+ .oam = &sOamData_857BA14,
+ .anims = gDummySpriteAnimTable,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = sub_8094AB8,
+ };
+
+ LoadSpriteSheets(spriteSheets);
+ LoadSpritePalettes(spritePalettes);
+ sPSSData->field_CD8[0] = IndexOfSpritePaletteTag(TAG_PAL_WAVEFORM);
+ sPSSData->field_CD8[1] = IndexOfSpritePaletteTag(TAG_PAL_DAC7);
+
+ sub_8092398(sBoxCursorArea, sBoxCursorPosition, &x, &y);
+ spriteId = CreateSprite(&gSpriteTemplate_857BA50, x, y, 6);
+ if (spriteId != MAX_SPRITES)
+ {
+ sPSSData->field_CB4 = &gSprites[spriteId];
+ sPSSData->field_CB4->oam.paletteNum = sPSSData->field_CD8[sCanOnlyMove];
+ sPSSData->field_CB4->oam.priority = 1;
+ if (sIsMonBeingMoved)
+ StartSpriteAnim(sPSSData->field_CB4, 3);
+ }
+ else
+ {
+ sPSSData->field_CB4 = NULL;
+ }
+
+ if (sBoxCursorArea == CURSOR_AREA_IN_PARTY)
+ {
+ subpriority = 13;
+ priority = 1;
+ }
+ else
+ {
+ subpriority = 21;
+ priority = 2;
+ }
+
+ spriteId = CreateSprite(&gSpriteTemplate_857BA68, 0, 0, subpriority);
+ if (spriteId != MAX_SPRITES)
+ {
+ sPSSData->field_CB8 = &gSprites[spriteId];
+ sPSSData->field_CB8->oam.priority = priority;
+ if (sBoxCursorArea)
+ sPSSData->field_CB8->invisible = 1;
+ }
+ else
+ {
+ sPSSData->field_CB8 = NULL;
+ }
+}
+
+static void sub_8094C84(void)
+{
+ sCanOnlyMove = !sCanOnlyMove;
+ sPSSData->field_CB4->oam.paletteNum = sPSSData->field_CD8[sCanOnlyMove];
+}
+
+u8 GetBoxCursorPosition(void)
+{
+ return sBoxCursorPosition;
+}
+
+void sub_8094CD4(u8 *arg0, u8 *arg1)
+{
+ if (sBoxCursorArea == CURSOR_AREA_IN_BOX)
+ {
+ *arg0 = sBoxCursorPosition % IN_BOX_ROWS;
+ *arg1 = sBoxCursorPosition / IN_BOX_ROWS;
+ }
+ else
+ {
+ *arg0 = 0;
+ *arg1 = 0;
+ }
+}
+
+void sub_8094D14(u8 animNum)
+{
+ StartSpriteAnim(sPSSData->field_CB4, animNum);
+}
+
+u8 sub_8094D34(void)
+{
+ return sMovingMonOrigBoxId;
+}
+
+void sub_8094D40(void)
+{
+ sPSSData->field_CB4->oam.priority = 1;
+}
+
+void sub_8094D60(void)
+{
+ if (sBoxCursorArea == CURSOR_AREA_IN_BOX)
+ sub_8095D44(CURSOR_AREA_IN_BOX, sBoxCursorPosition);
+}
+
+void sub_8094D84(void)
+{
+ if (sBoxCursorArea == CURSOR_AREA_IN_BOX)
+ sub_8095C84(CURSOR_AREA_IN_BOX, sBoxCursorPosition);
+}
diff --git a/src/pokemon_storage_system_6.c b/src/pokemon_storage_system_6.c
new file mode 100644
index 000000000..a8cca28d5
--- /dev/null
+++ b/src/pokemon_storage_system_6.c
@@ -0,0 +1,147 @@
+#include "global.h"
+#include "gflib.h"
+#include "menu.h"
+#include "new_menu_helpers.h"
+#include "pokemon_storage_system_internal.h"
+#include "strings.h"
+#include "constants/songs.h"
+
+void InitMenu(void)
+{
+ sPSSData->menuItemsCount = 0;
+ sPSSData->menuWidth = 0;
+ sPSSData->menuWindow.bg = 0;
+ sPSSData->menuWindow.paletteNum = 15;
+ sPSSData->menuWindow.baseBlock = 92;
+}
+
+static const u8 *const sMenuTexts[] = {
+ [PC_TEXT_CANCEL] = gPCText_Cancel,
+ [PC_TEXT_STORE] = gPCText_Store,
+ [PC_TEXT_WITHDRAW] = gPCText_Withdraw,
+ [PC_TEXT_MOVE] = gPCText_Move,
+ [PC_TEXT_SHIFT] = gPCText_Shift,
+ [PC_TEXT_PLACE] = gPCText_Place,
+ [PC_TEXT_SUMMARY] = gPCText_Summary,
+ [PC_TEXT_RELEASE] = gPCText_Release,
+ [PC_TEXT_MARK] = gPCText_Mark,
+ [PC_TEXT_JUMP] = gPCText_Jump,
+ [PC_TEXT_WALLPAPER] = gPCText_Wallpaper,
+ [PC_TEXT_NAME] = gPCText_Name,
+ [PC_TEXT_TAKE] = gPCText_Take,
+ [PC_TEXT_GIVE] = gPCText_Give,
+ [PC_TEXT_GIVE2] = gPCText_Give,
+ [PC_TEXT_SWITCH] = gPCText_Switch,
+ [PC_TEXT_BAG] = gPCText_Bag,
+ [PC_TEXT_INFO] = gPCText_Info,
+ [PC_TEXT_SCENERY1] = gPCText_Scenery1,
+ [PC_TEXT_SCENERY2] = gPCText_Scenery2,
+ [PC_TEXT_SCENERY3] = gPCText_Scenery3,
+ [PC_TEXT_ETCETERA] = gPCText_Etcetera,
+ [PC_TEXT_FOREST] = gPCText_Forest,
+ [PC_TEXT_CITY] = gPCText_City,
+ [PC_TEXT_DESERT] = gPCText_Desert,
+ [PC_TEXT_SAVANNA] = gPCText_Savanna,
+ [PC_TEXT_CRAG] = gPCText_Crag,
+ [PC_TEXT_VOLCANO] = gPCText_Volcano,
+ [PC_TEXT_SNOW] = gPCText_Snow,
+ [PC_TEXT_CAVE] = gPCText_Cave,
+ [PC_TEXT_BEACH] = gPCText_Beach,
+ [PC_TEXT_SEAFLOOR] = gPCText_Seafloor,
+ [PC_TEXT_RIVER] = gPCText_River,
+ [PC_TEXT_SKY] = gPCText_Sky,
+ [PC_TEXT_POLKADOT] = gPCText_PolkaDot,
+ [PC_TEXT_POKECENTER] = gPCText_Pokecenter,
+ [PC_TEXT_MACHINE] = gPCText_Machine,
+ [PC_TEXT_SIMPLE] = gPCText_Simple,
+};
+
+void SetMenuText(u8 textId)
+{
+ if (sPSSData->menuItemsCount < MAX_MENU_ITEMS)
+ {
+ u8 len;
+ struct StorageMenu *menu = &sPSSData->menuItems[sPSSData->menuItemsCount];
+
+ menu->text = sMenuTexts[textId];
+ menu->textId = textId;
+ len = StringLength(menu->text);
+ if (len > sPSSData->menuWidth)
+ sPSSData->menuWidth = len;
+
+ sPSSData->menuItemsCount++;
+ }
+}
+
+s8 sub_8094E50(u8 arg0)
+{
+ if (arg0 >= sPSSData->menuItemsCount)
+ return -1;
+ else
+ return sPSSData->menuItems[arg0].textId;
+}
+
+void AddMenu(void)
+{
+ sPSSData->menuWindow.width = sPSSData->menuWidth + 2;
+ sPSSData->menuWindow.height = 2 * sPSSData->menuItemsCount;
+ sPSSData->menuWindow.tilemapLeft = 29 - sPSSData->menuWindow.width;
+ sPSSData->menuWindow.tilemapTop = 15 - sPSSData->menuWindow.height;
+ sPSSData->field_CB0 = AddWindow(&sPSSData->menuWindow);
+ ClearWindowTilemap(sPSSData->field_CB0);
+ DrawStdFrameWithCustomTileAndPalette(sPSSData->field_CB0, FALSE, 0x00b, 14);
+ PrintTextArray(sPSSData->field_CB0, 1, 8, 2, 16, sPSSData->menuItemsCount, (void*)sPSSData->menuItems);
+ Menu_InitCursor(sPSSData->field_CB0, 1, 0, 2, 16, sPSSData->menuItemsCount, 0);
+ ScheduleBgCopyTilemapToVram(0);
+ sPSSData->field_CAE = 0;
+}
+
+bool8 sub_8094F90(void)
+{
+ // Some debug flag?
+ return FALSE;
+}
+
+s16 sub_8094F94(void)
+{
+ s32 textId = -2;
+
+ do
+ {
+ if (JOY_NEW(A_BUTTON))
+ {
+ textId = Menu_GetCursorPos();
+ break;
+ }
+ else if (JOY_NEW(B_BUTTON))
+ {
+ PlaySE(SE_SELECT);
+ textId = -1;
+ }
+
+ if (JOY_NEW(DPAD_UP))
+ {
+ PlaySE(SE_SELECT);
+ Menu_MoveCursor(-1);
+ }
+ else if (JOY_NEW(DPAD_DOWN))
+ {
+ PlaySE(SE_SELECT);
+ Menu_MoveCursor(1);
+ }
+ } while (0);
+
+ if (textId != -2)
+ sub_8095024();
+
+ if (textId >= 0)
+ textId = sPSSData->menuItems[textId].textId;
+
+ return textId;
+}
+
+void sub_8095024(void)
+{
+ ClearStdWindowAndFrameToTransparent(sPSSData->field_CB0, TRUE);
+ RemoveWindow(sPSSData->field_CB0);
+}
diff --git a/src/pokemon_storage_system_7.c b/src/pokemon_storage_system_7.c
new file mode 100644
index 000000000..1b2bc045a
--- /dev/null
+++ b/src/pokemon_storage_system_7.c
@@ -0,0 +1,582 @@
+#include <stdlib.h> // to declare abs
+#include "global.h"
+#include "gflib.h"
+#include "pokemon_icon.h"
+#include "pokemon_storage_system_internal.h"
+#include "text_window.h"
+#include "constants/species.h"
+
+struct MoveMons
+{
+ u8 field_0;
+ u8 state;
+ u8 fromRow;
+ u8 fromColumn;
+ u8 toRow;
+ u8 toColumn;
+ u8 field_6;
+ u8 field_7;
+ u8 minRow;
+ u8 minColumn;
+ u8 rowsTotal;
+ u8 columsTotal;
+ u16 bgX;
+ u16 bgY;
+ u16 field_10;
+ struct BoxPokemon boxMons[IN_BOX_COUNT];
+};
+
+static EWRAM_DATA struct MoveMons *sMoveMonsPtr = NULL;
+
+static bool8 sub_8095138(void);
+static bool8 sub_8095234(void);
+static bool8 sub_80952A0(void);
+static bool8 sub_8095314(void);
+static bool8 sub_8095394(void);
+static bool8 sub_80953BC(void);
+static void sub_8095520(void);
+static void sub_80955C4(u8 arg0, u8 arg1, u8 arg2);
+static void sub_80955FC(u8 arg0, u8 arg1, u8 arg2);
+static void sub_8095634(u8 arg0, u8 arg1, u8 arg2);
+static void sub_809566C(u8 arg0, u8 arg1, u8 arg2);
+static void sub_80956A4(u8 x, u8 y);
+static void sub_809572C(u8 x, u8 y);
+static void sub_8095780(u16 bgX, u16 bgY, u16 duration);
+static u8 sub_8095790(void);
+static void sub_80957C8(void);
+static void sub_80958A0(void);
+static void sub_8095918(void);
+static void sub_80959A8(void);
+static void sub_8095A58(void);
+
+static const struct WindowTemplate gUnknown_83D35D4 = {
+ .bg = 0,
+ .tilemapLeft = 10,
+ .tilemapTop = 3,
+ .width = 20,
+ .height = 18,
+ .paletteNum = 9,
+ .baseBlock = 0x00a
+};
+
+bool8 sub_8095050(void)
+{
+ sMoveMonsPtr = Alloc(sizeof(*sMoveMonsPtr));
+ if (sMoveMonsPtr != NULL)
+ {
+ sPSSData->field_2200 = AddWindow8Bit(&gUnknown_83D35D4);
+ if (sPSSData->field_2200 != 0xFF)
+ {
+ FillWindowPixelBuffer(sPSSData->field_2200, PIXEL_FILL(0));
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void sub_80950A4(void)
+{
+ if (sMoveMonsPtr != NULL)
+ Free(sMoveMonsPtr);
+}
+
+void sub_80950BC(u8 arg0)
+{
+ sMoveMonsPtr->field_0 = arg0;
+ sMoveMonsPtr->state = 0;
+}
+
+bool8 sub_80950D0(void)
+{
+ switch (sMoveMonsPtr->field_0)
+ {
+ case 0:
+ return sub_8095138();
+ case 1:
+ return sub_8095234();
+ case 2:
+ return sub_80952A0();
+ case 3:
+ return sub_8095314();
+ case 4:
+ return sub_8095394();
+ case 5:
+ return sub_80953BC();
+ }
+
+ return FALSE;
+}
+
+static bool8 sub_8095138(void)
+{
+ switch (sMoveMonsPtr->state)
+ {
+ case 0:
+ HideBg(0);
+ LoadMonIconPalettesAt(0x80);
+ sMoveMonsPtr->state++;
+ break;
+ case 1:
+ sub_8094CD4(&sMoveMonsPtr->fromRow, &sMoveMonsPtr->fromColumn);
+ sMoveMonsPtr->toRow = sMoveMonsPtr->fromRow;
+ sMoveMonsPtr->toColumn = sMoveMonsPtr->fromColumn;
+ ChangeBgX(0, -1024, 0);
+ ChangeBgY(0, -1024, 0);
+ FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20);
+ FillWindowPixelBuffer8Bit(sPSSData->field_2200, PIXEL_FILL(0));
+ sub_80956A4(sMoveMonsPtr->fromRow, sMoveMonsPtr->fromColumn);
+ SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1);
+ PutWindowTilemap(sPSSData->field_2200);
+ CopyWindowToVram8Bit(sPSSData->field_2200, 3);
+ BlendPalettes(0x3F00, 8, RGB_WHITE);
+ sub_8094D14(2);
+ SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR);
+ sMoveMonsPtr->state++;
+ break;
+ case 2:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ {
+ ShowBg(0);
+ return FALSE;
+ }
+ break;
+ }
+
+ return TRUE;
+}
+
+static bool8 sub_8095234(void)
+{
+ switch (sMoveMonsPtr->state)
+ {
+ case 0:
+ HideBg(0);
+ sMoveMonsPtr->state++;
+ break;
+ case 1:
+ sub_8095A58();
+ sub_8094D14(0);
+ sMoveMonsPtr->state++;
+ break;
+ case 2:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ {
+ sub_8094D40();
+ LoadPalette(stdpal_get(3), 0xD0, 0x20);
+ ShowBg(0);
+ return FALSE;
+ }
+ break;
+ }
+
+ return TRUE;
+}
+
+static bool8 sub_80952A0(void)
+{
+ switch (sMoveMonsPtr->state)
+ {
+ case 0:
+ if (!sub_80924A8())
+ {
+ sub_8094CD4(&sMoveMonsPtr->field_6, &sMoveMonsPtr->field_7);
+ sub_8095520();
+ sMoveMonsPtr->toRow = sMoveMonsPtr->field_6;
+ sMoveMonsPtr->toColumn = sMoveMonsPtr->field_7;
+ CopyWindowToVram8Bit(sPSSData->field_2200, 2);
+ sMoveMonsPtr->state++;
+ }
+ break;
+ case 1:
+ return IsDma3ManagerBusyWithBgCopy();
+ }
+
+ return TRUE;
+}
+
+static bool8 sub_8095314(void)
+{
+ u8 var1, var2;
+
+ switch (sMoveMonsPtr->state)
+ {
+ case 0:
+ sub_80957C8();
+ sub_80958A0();
+ sub_8092BAC(FALSE);
+ sMoveMonsPtr->state++;
+ break;
+ case 1:
+ if (!DoMonPlaceChange())
+ {
+ sub_8094D14(3);
+ sub_8095780(0, 256, 8);
+ sub_8092BAC(TRUE);
+ sMoveMonsPtr->state++;
+ }
+ break;
+ case 2:
+ var1 = sub_8095790();
+ var2 = DoMonPlaceChange();
+ if (!var1 && !var2)
+ return FALSE;
+ break;
+ }
+
+ return TRUE;
+}
+
+static bool8 sub_8095394(void)
+{
+ u8 var1 = sub_80924A8();
+ u8 var2 = sub_8095790();
+
+ if (!var1 && !var2)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+static bool8 sub_80953BC(void)
+{
+ switch (sMoveMonsPtr->state)
+ {
+ case 0:
+ sub_80959A8();
+ sub_8095780(0, -256, 8);
+ sub_8092BAC(FALSE);
+ sMoveMonsPtr->state++;
+ break;
+ case 1:
+ if (!DoMonPlaceChange() && !sub_8095790())
+ {
+ sub_8095918();
+ sub_8094D14(2);
+ sub_8092BAC(TRUE);
+ HideBg(0);
+ sMoveMonsPtr->state++;
+ }
+ break;
+ case 2:
+ if (!DoMonPlaceChange())
+ {
+ sub_8094D14(0);
+ sub_8095A58();
+ sMoveMonsPtr->state++;
+ }
+ break;
+ case 3:
+ if (!IsDma3ManagerBusyWithBgCopy())
+ {
+ LoadPalette(stdpal_get(3), 0xD0, 0x20);
+ sub_8094D40();
+ ShowBg(0);
+ return FALSE;
+ }
+ break;
+ }
+
+ return TRUE;
+}
+
+bool8 sub_8095474(u8 arg0)
+{
+ switch (arg0)
+ {
+ case 0: // up
+ if (sMoveMonsPtr->minColumn == 0)
+ return FALSE;
+ sMoveMonsPtr->minColumn--;
+ sub_8095780(0, 1024, 6);
+ break;
+ case 1: // down
+ if (sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal >= 5)
+ return FALSE;
+ sMoveMonsPtr->minColumn++;
+ sub_8095780(0, -1024, 6);
+ break;
+ case 2: // left
+ if (sMoveMonsPtr->minRow == 0)
+ return FALSE;
+ sMoveMonsPtr->minRow--;
+ sub_8095780(1024, 0, 6);
+ break;
+ case 3: // right
+ if (sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal > 5)
+ return FALSE;
+ sMoveMonsPtr->minRow++;
+ sub_8095780(-1024, 0, 6);
+ break;
+ }
+
+ return TRUE;
+}
+
+static void sub_8095520(void)
+{
+ s16 var = (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->field_6)) - (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow));
+ s16 var2 = (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->field_7)) - (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn));
+
+ if (var > 0)
+ sub_80955C4(sMoveMonsPtr->field_6, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn);
+
+ if (var < 0)
+ {
+ sub_8095634(sMoveMonsPtr->toRow, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn);
+ sub_80955C4(sMoveMonsPtr->field_6, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn);
+ }
+
+ if (var2 > 0)
+ sub_80955FC(sMoveMonsPtr->field_7, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow);
+
+ if (var2 < 0)
+ {
+ sub_809566C(sMoveMonsPtr->toColumn, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow);
+ sub_80955FC(sMoveMonsPtr->field_7, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow);
+ }
+}
+
+static void sub_80955C4(u8 arg0, u8 arg1, u8 arg2)
+{
+ u8 var1 = arg1;
+
+ if (arg1 > arg2)
+ {
+ arg1 = arg2;
+ arg2 = var1;
+ }
+
+ while (arg1 <= arg2)
+ sub_80956A4(arg0, arg1++);
+}
+
+static void sub_80955FC(u8 arg0, u8 arg1, u8 arg2)
+{
+ u8 var1 = arg1;
+
+ if (arg1 > arg2)
+ {
+ arg1 = arg2;
+ arg2 = var1;
+ }
+
+ while (arg1 <= arg2)
+ sub_80956A4(arg1++, arg0);
+}
+
+static void sub_8095634(u8 arg0, u8 arg1, u8 arg2)
+{
+ u8 var1 = arg1;
+
+ if (arg1 > arg2)
+ {
+ arg1 = arg2;
+ arg2 = var1;
+ }
+
+ while (arg1 <= arg2)
+ sub_809572C(arg0, arg1++);
+}
+
+static void sub_809566C(u8 arg0, u8 arg1, u8 arg2)
+{
+ u8 var1 = arg1;
+
+ if (arg1 > arg2)
+ {
+ arg1 = arg2;
+ arg2 = var1;
+ }
+
+ while (arg1 <= arg2)
+ sub_809572C(arg1++, arg0);
+}
+
+static void sub_80956A4(u8 x, u8 y)
+{
+ u8 position = x + (IN_BOX_ROWS * y);
+ u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2);
+ u32 personality = GetCurrentBoxMonData(position, MON_DATA_PERSONALITY);
+
+ if (species != SPECIES_NONE)
+ {
+ const u8 *iconGfx = GetMonIconPtr(species, personality, 1);
+ u8 index = GetValidMonIconPalIndex(species) + 8;
+
+ BlitBitmapRectToWindow4BitTo8Bit(sPSSData->field_2200,
+ iconGfx,
+ 0,
+ 0,
+ 32,
+ 32,
+ 24 * x,
+ 24 * y,
+ 32,
+ 32,
+ index);
+ }
+}
+
+static void sub_809572C(u8 x, u8 y)
+{
+ u8 position = x + (IN_BOX_ROWS * y);
+ u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2);
+
+ if (species != SPECIES_NONE)
+ {
+ FillWindowPixelRect8Bit(sPSSData->field_2200,
+ PIXEL_FILL(0),
+ 24 * x,
+ 24 * y,
+ 32,
+ 32);
+ }
+}
+
+static void sub_8095780(u16 bgX, u16 bgY, u16 duration)
+{
+ sMoveMonsPtr->bgX = bgX;
+ sMoveMonsPtr->bgY = bgY;
+ sMoveMonsPtr->field_10 = duration;
+}
+
+static u8 sub_8095790(void)
+{
+ if (sMoveMonsPtr->field_10 != 0)
+ {
+ ChangeBgX(0, sMoveMonsPtr->bgX, 1);
+ ChangeBgY(0, sMoveMonsPtr->bgY, 1);
+ sMoveMonsPtr->field_10--;
+ }
+
+ return sMoveMonsPtr->field_10;
+}
+
+static void sub_80957C8(void)
+{
+ s32 i, j;
+ s32 rowCount, columnCount;
+ u8 boxId;
+ u8 monArrayId;
+
+ sMoveMonsPtr->minRow = min(sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow);
+ sMoveMonsPtr->minColumn = min(sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn);
+ sMoveMonsPtr->rowsTotal = abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow) + 1;
+ sMoveMonsPtr->columsTotal = abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn) + 1;
+ boxId = StorageGetCurrentBox();
+ monArrayId = 0;
+ rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal;
+ columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal;
+ for (i = sMoveMonsPtr->minColumn; i < columnCount; i++)
+ {
+ u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow;
+ for (j = sMoveMonsPtr->minRow; j < rowCount; j++)
+ {
+ struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition);
+
+ sMoveMonsPtr->boxMons[monArrayId] = *boxMon;
+ monArrayId++;
+ boxPosition++;
+ }
+ }
+}
+
+static void sub_80958A0(void)
+{
+ s32 i, j;
+ s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal;
+ s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal;
+ u8 boxId = StorageGetCurrentBox();
+
+ for (i = sMoveMonsPtr->minColumn; i < columnCount; i++)
+ {
+ u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow;
+ for (j = sMoveMonsPtr->minRow; j < rowCount; j++)
+ {
+ DestroyBoxMonIconAtPosition(boxPosition);
+ ZeroBoxMonAt(boxId, boxPosition);
+ boxPosition++;
+ }
+ }
+}
+
+static void sub_8095918(void)
+{
+ s32 i, j;
+ s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal;
+ s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal;
+ u8 monArrayId = 0;
+
+ for (i = sMoveMonsPtr->minColumn; i < columnCount; i++)
+ {
+ u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow;
+ for (j = sMoveMonsPtr->minRow; j < rowCount; j++)
+ {
+ if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES))
+ sub_80901EC(boxPosition);
+ monArrayId++;
+ boxPosition++;
+ }
+ }
+}
+
+static void sub_80959A8(void)
+{
+ s32 i, j;
+ s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal;
+ s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal;
+ u8 boxId = StorageGetCurrentBox();
+ u8 monArrayId = 0;
+
+ for (i = sMoveMonsPtr->minColumn; i < columnCount; i++)
+ {
+ u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow;
+ for (j = sMoveMonsPtr->minRow; j < rowCount; j++)
+ {
+ if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES))
+ SetBoxMonAt(boxId, boxPosition, &sMoveMonsPtr->boxMons[monArrayId]);
+ boxPosition++;
+ monArrayId++;
+ }
+ }
+}
+
+static void sub_8095A58(void)
+{
+ ChangeBgX(0, 0, 0);
+ ChangeBgY(0, 0, 0);
+ SetBgAttribute(0, BG_ATTR_PALETTEMODE, 0);
+ ClearGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR);
+ FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32);
+ CopyBgTilemapBufferToVram(0);
+}
+
+u8 sub_8095AA0(void)
+{
+ return (IN_BOX_ROWS * sMoveMonsPtr->fromColumn) + sMoveMonsPtr->fromRow;
+}
+
+bool8 sub_8095ABC(void)
+{
+ s32 i, j;
+ s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal;
+ s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal;
+ u8 monArrayId = 0;
+
+ for (i = sMoveMonsPtr->minColumn; i < columnCount; i++)
+ {
+ u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow;
+ for (j = sMoveMonsPtr->minRow; j < rowCount; j++)
+ {
+ if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)
+ && GetCurrentBoxMonData(boxPosition, MON_DATA_SANITY_HAS_SPECIES))
+ return FALSE;
+
+ monArrayId++;
+ boxPosition++;
+ }
+ }
+
+ return TRUE;
+}
diff --git a/src/pokemon_storage_system_8.c b/src/pokemon_storage_system_8.c
new file mode 100644
index 000000000..39bec436e
--- /dev/null
+++ b/src/pokemon_storage_system_8.c
@@ -0,0 +1,755 @@
+#include "global.h"
+#include "gflib.h"
+#include "decompress.h"
+#include "item.h"
+#include "item_menu_icons.h"
+#include "menu.h"
+#include "new_menu_helpers.h"
+#include "pokemon_storage_system_internal.h"
+#include "trig.h"
+#include "constants/items.h"
+
+static u8 sub_80961D8(void);
+static bool32 sub_8096210(u8 cursorArea, u8 cursorPos);
+static u8 sub_8096258(u8 cursorArea, u8 cursorPos);
+static void sub_80962F0(u8 id, u8 cursorArea, u8 cursorPos);
+static void sub_8096408(u8 id, const u32 * tiles, const u32 * pal);
+static void sub_80964B8(u8 id, u8 affineAnimNo);
+static void sub_80964E8(u8 id, u8 command, u8 cursorArea, u8 cursorPos);
+static void sub_8096624(u8 id, bool8 show);
+static const u32 *GetItemIconPic(u16 itemId);
+static const u32 *GetItemIconPalette(u16 itemId);
+static void sub_8096898(u32 x);
+static void sub_809692C(struct Sprite * sprite);
+static void sub_8096958(struct Sprite * sprite);
+static void sub_80969BC(struct Sprite * sprite);
+static void sub_80969F4(struct Sprite * sprite);
+static void sub_8096A74(struct Sprite * sprite);
+static void sub_8096B10(struct Sprite * sprite);
+static void sub_8096BAC(struct Sprite * sprite);
+
+static const u32 gUnknown_83D35DC[] = INCBIN_U32("graphics/interface/pss_unk_83D35DC.4bpp");
+
+static const struct OamData gUnknown_83D365C = {
+ .y = 0,
+ .affineMode = ST_OAM_AFFINE_NORMAL,
+ .objMode = ST_OAM_OBJ_NORMAL,
+ .mosaic = 0,
+ .bpp = ST_OAM_4BPP,
+ .shape = SPRITE_SHAPE(32x32),
+ .x = 0,
+ .matrixNum = 0,
+ .size = SPRITE_SIZE(32x32),
+ .tileNum = 0,
+ .priority = 1,
+ .paletteNum = 0,
+ .affineParam = 0
+};
+
+static const union AffineAnimCmd gUnknown_83D3664[] = {
+ AFFINEANIMCMD_FRAME(128, 128, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83D3674[] = {
+ AFFINEANIMCMD_FRAME(88, 88, 0, 0),
+ AFFINEANIMCMD_FRAME(5, 5, 0, 8),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83D368C[] = {
+ AFFINEANIMCMD_FRAME(128, 128, 0, 0),
+ AFFINEANIMCMD_FRAME(-5, -5, 0, 8),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83D36A4[] = {
+ AFFINEANIMCMD_FRAME(128, 128, 0, 0),
+ AFFINEANIMCMD_FRAME(10, 10, 0, 12),
+ AFFINEANIMCMD_FRAME(256, 256, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83D36C4[] = {
+ AFFINEANIMCMD_FRAME(256, 256, 0, 0),
+ AFFINEANIMCMD_FRAME(-10, -10, 0, 12),
+ AFFINEANIMCMD_FRAME(128, 128, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83D36E4[] = {
+ AFFINEANIMCMD_FRAME(256, 256, 0, 0),
+ AFFINEANIMCMD_FRAME(-5, -5, 0, 16),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd gUnknown_83D36FC[] = {
+ AFFINEANIMCMD_FRAME(256, 256, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const gUnknown_83D370C[] = {
+ gUnknown_83D3664,
+ gUnknown_83D3674,
+ gUnknown_83D368C,
+ gUnknown_83D36A4,
+ gUnknown_83D36C4,
+ gUnknown_83D36E4,
+ gUnknown_83D36FC
+};
+
+static const struct SpriteTemplate gUnknown_83D3728 = {
+ .tileTag = TAG_TILE_7,
+ .paletteTag = TAG_PAL_DACB,
+ .oam = &gUnknown_83D365C,
+ .anims = gDummySpriteAnimTable,
+ .images = NULL,
+ .affineAnims = gUnknown_83D370C,
+ .callback = SpriteCallbackDummy,
+};
+
+void sub_8095B5C(void)
+{
+ s32 i;
+ u8 spriteId;
+ struct CompressedSpriteSheet spriteSheet;
+ struct SpriteTemplate spriteTemplate;
+ static u32 gUnknown_3000FE8[0x61];
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ spriteSheet.data = gUnknown_3000FE8;
+ spriteSheet.size = 0x200;
+ spriteTemplate = gUnknown_83D3728;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ spriteSheet.tag = TAG_TILE_7 + i;
+ LoadCompressedSpriteSheet(&spriteSheet);
+ sPSSData->itemIconSprites[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * 32 + (void*)(OBJ_VRAM0);
+ sPSSData->itemIconSprites[i].palIndex = AllocSpritePalette(TAG_PAL_DACB + i);
+ sPSSData->itemIconSprites[i].palIndex *= 16;
+ sPSSData->itemIconSprites[i].palIndex += 0x100;
+ spriteTemplate.tileTag = TAG_TILE_7 + i;
+ spriteTemplate.paletteTag = TAG_PAL_DACB + i;
+ spriteId = CreateSprite(&spriteTemplate, 0, 0, 11);
+ sPSSData->itemIconSprites[i].sprite = &gSprites[spriteId];
+ sPSSData->itemIconSprites[i].sprite->invisible = TRUE;
+ sPSSData->itemIconSprites[i].active = 0;
+ }
+ }
+ sPSSData->movingItem = ITEM_NONE;
+}
+
+void sub_8095C84(u8 cursorArea, u8 cursorPos)
+{
+ u16 heldItem;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+ if (sub_8096210(cursorArea, cursorPos))
+ return;
+
+ switch (cursorArea)
+ {
+ case CURSOR_AREA_IN_BOX:
+ if (!GetCurrentBoxMonData(cursorPos, MON_DATA_SANITY_HAS_SPECIES))
+ return;
+ heldItem = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM);
+ break;
+ case CURSOR_AREA_IN_PARTY:
+ if (!GetMonData(&gPlayerParty[cursorPos], MON_DATA_SANITY_HAS_SPECIES))
+ return;
+ heldItem = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM);
+ break;
+ default:
+ return;
+ }
+
+ if (heldItem != ITEM_NONE)
+ {
+ const u32 *tiles = GetItemIconPic(heldItem);
+ const u32 *pal = GetItemIconPalette(heldItem);
+ u8 id = sub_80961D8();
+
+ sub_80962F0(id, cursorArea, cursorPos);
+ sub_8096408(id, tiles, pal);
+ sub_80964B8(id, 1);
+ sub_8096624(id, TRUE);
+ }
+}
+
+void sub_8095D44(u8 cursorArea, u8 cursorPos)
+{
+ u8 id;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+
+ id = sub_8096258(cursorArea, cursorPos);
+ sub_80964B8(id, 2);
+ sub_80964E8(id, 0, cursorArea, cursorPos);
+}
+
+void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos)
+{
+ u8 id;
+ u16 item;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+
+ id = sub_8096258(cursorArea, cursorPos);
+ item = 0;
+ sub_80964B8(id, 3);
+ sub_80964E8(id, 1, cursorArea, cursorPos);
+ sub_80962F0(id, 2, 0);
+ if (cursorArea == CURSOR_AREA_IN_BOX)
+ {
+ SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item);
+ SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND);
+ }
+ else
+ {
+ SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item);
+ SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND);
+ }
+
+ sPSSData->movingItem = sPSSData->cursorMonItem;
+}
+
+void sub_8095E2C(u16 item)
+{
+ const u32 *tiles = GetItemIconPic(item);
+ const u32 *pal = GetItemIconPalette(item);
+ u8 id = sub_80961D8();
+
+ sub_8096408(id, tiles, pal);
+ sub_80964B8(id, 6);
+ sub_80964E8(id, 1, CURSOR_AREA_IN_BOX, 0);
+ sub_80962F0(id, CURSOR_AREA_BOX, 0);
+ sub_8096624(id, TRUE);
+ sPSSData->movingItem = item;
+}
+
+void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos)
+{
+ u8 id;
+ u16 item;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+
+ id = sub_8096258(cursorArea, cursorPos);
+ sub_80964B8(id, 3);
+ sub_80964E8(id, 3, CURSOR_AREA_BOX, 0);
+ if (cursorArea == CURSOR_AREA_IN_BOX)
+ {
+ item = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM);
+ SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItem);
+ sPSSData->movingItem = item;
+ }
+ else
+ {
+ item = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM);
+ SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItem);
+ sPSSData->movingItem = item;
+ }
+
+ id = sub_8096258(2, 0);
+ sub_80964B8(id, 4);
+ sub_80964E8(id, 4, cursorArea, cursorPos);
+}
+
+void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos)
+{
+ u8 id;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+
+ id = sub_8096258(2, 0);
+ sub_80964B8(id, 4);
+ sub_80964E8(id, 2, cursorArea, cursorPos);
+ if (cursorArea == CURSOR_AREA_IN_BOX)
+ {
+ SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItem);
+ SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_NORMAL);
+ }
+ else
+ {
+ SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItem);
+ SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_NORMAL);
+ }
+}
+
+void Item_TakeMons(u8 cursorArea, u8 cursorPos)
+{
+ u8 id;
+ u16 item;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+
+ item = 0;
+ id = sub_8096258(cursorArea, cursorPos);
+ sub_80964B8(id, 2);
+ sub_80964E8(id, 0, cursorArea, cursorPos);
+ if (cursorArea == CURSOR_AREA_IN_BOX)
+ {
+ SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item);
+ SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND);
+ }
+ else
+ {
+ SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item);
+ SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND);
+ }
+}
+
+void sub_8096088(void)
+{
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ u8 id = sub_8096258(2, 0);
+ sub_80964B8(id, 5);
+ sub_80964E8(id, 0, CURSOR_AREA_BOX, 0);
+ }
+}
+
+void sub_80960C0(void)
+{
+ s32 i;
+
+ if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS)
+ return;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (sPSSData->itemIconSprites[i].active && sPSSData->itemIconSprites[i].cursorArea == CURSOR_AREA_IN_PARTY)
+ sub_80964E8(i, 7, CURSOR_AREA_BOX, 0);
+ }
+}
+
+bool8 sub_809610C(void)
+{
+ s32 i;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (sPSSData->itemIconSprites[i].active)
+ {
+ if (!sPSSData->itemIconSprites[i].sprite->affineAnimEnded && sPSSData->itemIconSprites[i].sprite->affineAnimBeginning)
+ return TRUE;
+ if (sPSSData->itemIconSprites[i].sprite->callback != SpriteCallbackDummy && sPSSData->itemIconSprites[i].sprite->callback != sub_80969BC)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+bool8 IsActiveItemMoving(void)
+{
+ s32 i;
+
+ if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS)
+ {
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (sPSSData->itemIconSprites[i].active && sPSSData->itemIconSprites[i].cursorArea == CURSOR_AREA_BOX)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+const u8 *GetMovingItemName(void)
+{
+ return ItemId_GetName(sPSSData->movingItem);
+}
+
+u16 GetMovingItem(void)
+{
+ return sPSSData->movingItem;
+}
+
+static u8 sub_80961D8(void)
+{
+ u8 i;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (!sPSSData->itemIconSprites[i].active)
+ {
+ sPSSData->itemIconSprites[i].active = TRUE;
+ return i;
+ }
+ }
+
+ return MAX_ITEM_ICONS;
+}
+
+static bool32 sub_8096210(u8 cursorArea, u8 cursorPos)
+{
+ s32 i;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (sPSSData->itemIconSprites[i].active
+ && sPSSData->itemIconSprites[i].cursorArea == cursorArea
+ && sPSSData->itemIconSprites[i].cursorPos == cursorPos)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static u8 sub_8096258(u8 cursorArea, u8 cursorPos)
+{
+ u8 i;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (sPSSData->itemIconSprites[i].active
+ && sPSSData->itemIconSprites[i].cursorArea == cursorArea
+ && sPSSData->itemIconSprites[i].cursorPos == cursorPos)
+ return i;
+ }
+
+ return MAX_ITEM_ICONS;
+}
+
+static u8 sub_80962A8(struct Sprite *sprite)
+{
+ u8 i;
+
+ for (i = 0; i < MAX_ITEM_ICONS; i++)
+ {
+ if (sPSSData->itemIconSprites[i].active
+ && sPSSData->itemIconSprites[i].sprite == sprite)
+ return i;
+ }
+
+ return MAX_ITEM_ICONS;
+}
+
+static void sub_80962F0(u8 id, u8 cursorArea, u8 cursorPos)
+{
+ u8 row, column;
+
+ if (id >= MAX_ITEM_ICONS)
+ return;
+
+ switch (cursorArea)
+ {
+ case CURSOR_AREA_IN_BOX:
+ row = cursorPos % IN_BOX_ROWS;
+ column = cursorPos / IN_BOX_ROWS;
+ sPSSData->itemIconSprites[id].sprite->pos1.x = (24 * row) + 112;
+ sPSSData->itemIconSprites[id].sprite->pos1.y = (24 * column) + 56;
+ sPSSData->itemIconSprites[id].sprite->oam.priority = 2;
+ break;
+ case CURSOR_AREA_IN_PARTY:
+ if (cursorPos == 0)
+ {
+ sPSSData->itemIconSprites[id].sprite->pos1.x = 116;
+ sPSSData->itemIconSprites[id].sprite->pos1.y = 76;
+ }
+ else
+ {
+ sPSSData->itemIconSprites[id].sprite->pos1.x = 164;
+ sPSSData->itemIconSprites[id].sprite->pos1.y = 24 * (cursorPos - 1) + 28;
+ }
+ sPSSData->itemIconSprites[id].sprite->oam.priority = 1;
+ break;
+ }
+
+ sPSSData->itemIconSprites[id].cursorArea = cursorArea;
+ sPSSData->itemIconSprites[id].cursorPos = cursorPos;
+}
+
+static void sub_8096408(u8 id, const u32 *itemTiles, const u32 *itemPal)
+{
+ s32 i;
+
+ if (id >= MAX_ITEM_ICONS)
+ return;
+
+ CpuFastFill(0, sPSSData->field_42C4, 0x200);
+ LZ77UnCompWram(itemTiles, sPSSData->field_22C4);
+ for (i = 0; i < 3; i++)
+ CpuFastCopy(sPSSData->field_22C4 + (i * 0x60), sPSSData->field_42C4 + (i * 0x80), 0x60);
+
+ CpuFastCopy(sPSSData->field_42C4, sPSSData->itemIconSprites[id].tiles, 0x200);
+ LZ77UnCompWram(itemPal, sPSSData->field_42C4);
+ LoadPalette(sPSSData->field_42C4, sPSSData->itemIconSprites[id].palIndex, 0x20);
+}
+
+static void sub_80964B8(u8 id, u8 animNum)
+{
+ if (id >= MAX_ITEM_ICONS)
+ return;
+
+ StartSpriteAffineAnim(sPSSData->itemIconSprites[id].sprite, animNum);
+}
+
+static void sub_80964E8(u8 id, u8 command, u8 cursorArea, u8 cursorPos)
+{
+ if (id >= MAX_ITEM_ICONS)
+ return;
+
+ switch (command)
+ {
+ case 0:
+ sPSSData->itemIconSprites[id].sprite->data[0] = id;
+ sPSSData->itemIconSprites[id].sprite->callback = sub_809692C;
+ break;
+ case 1:
+ sPSSData->itemIconSprites[id].sprite->data[0] = 0;
+ sPSSData->itemIconSprites[id].sprite->callback = sub_8096958;
+ break;
+ case 2:
+ sPSSData->itemIconSprites[id].sprite->data[0] = 0;
+ sPSSData->itemIconSprites[id].sprite->data[6] = cursorArea;
+ sPSSData->itemIconSprites[id].sprite->data[7] = cursorPos;
+ sPSSData->itemIconSprites[id].sprite->callback = sub_80969F4;
+ break;
+ case 3:
+ sPSSData->itemIconSprites[id].sprite->data[0] = 0;
+ sPSSData->itemIconSprites[id].sprite->callback = sub_8096A74;
+ sPSSData->itemIconSprites[id].sprite->data[6] = cursorArea;
+ sPSSData->itemIconSprites[id].sprite->data[7] = cursorPos;
+ break;
+ case 4:
+ sPSSData->itemIconSprites[id].sprite->data[0] = 0;
+ sPSSData->itemIconSprites[id].sprite->data[6] = cursorArea;
+ sPSSData->itemIconSprites[id].sprite->data[7] = cursorPos;
+ sPSSData->itemIconSprites[id].sprite->callback = sub_8096B10;
+ break;
+ case 7:
+ sPSSData->itemIconSprites[id].sprite->callback = sub_8096BAC;
+ break;
+ }
+}
+
+static void sub_8096624(u8 id, bool8 show)
+{
+ if (id >= MAX_ITEM_ICONS)
+ return;
+
+ sPSSData->itemIconSprites[id].active = show;
+ sPSSData->itemIconSprites[id].sprite->invisible = (show == FALSE);
+}
+
+static const u32 *GetItemIconPic(u16 itemId)
+{
+ return GetItemIconGfxPtr(itemId, 0);
+}
+
+static const u32 *GetItemIconPalette(u16 itemId)
+{
+ return GetItemIconGfxPtr(itemId, 1);
+}
+
+void PrintItemDescription(void)
+{
+ const u8 *description;
+
+ if (IsActiveItemMoving())
+ description = ItemId_GetDescription(sPSSData->movingItem);
+ else
+ description = ItemId_GetDescription(sPSSData->cursorMonItem);
+
+ FillWindowPixelBuffer(2, PIXEL_FILL(1));
+ AddTextPrinterParameterized5(2, 2, description, 2, 0, 0, NULL, 0, 0);
+}
+
+void sub_80966F4(void)
+{
+ sPSSData->field_2236 = 25;
+ LoadBgTiles(0, gUnknown_83D35DC, 0x80, 0x1A4);
+ sub_8096898(0);
+}
+
+bool8 sub_8096728(void)
+{
+ s32 i, var;
+
+ if (sPSSData->field_2236 == 0)
+ return FALSE;
+
+ sPSSData->field_2236--;
+ var = 25 - sPSSData->field_2236;
+ for (i = 0; i < var; i++)
+ {
+ WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 12, 1, 8, 15, 25);
+ }
+
+ sub_8096898(var);
+ return (sPSSData->field_2236 != 0);
+}
+
+bool8 sub_80967C0(void)
+{
+ s32 i, var;
+
+ if (sPSSData->field_2236 == 25)
+ return FALSE;
+
+ if (sPSSData->field_2236 == 0)
+ FillBgTilemapBufferRect(0, 0, 25, 11, 1, 10, 17);
+
+ sPSSData->field_2236++;
+ var = 25 - sPSSData->field_2236;
+ for (i = 0; i < var; i++)
+ {
+ WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 12, 1, 8, 15, 25);
+ }
+
+ sub_8096898(var);
+
+ FillBgTilemapBufferRect(0, 0, var, 11, 1, 10, 0x11);
+ return (sPSSData->field_2236 != 25);
+}
+
+static void sub_8096898(u32 x)
+{
+ if (x != 0)
+ {
+ FillBgTilemapBufferRect(0, 0x1A4, 0, 0xB, x, 1, 0xFu);
+ FillBgTilemapBufferRect(0, 0x9A4, 0, 0x14, x, 1, 0xFu);
+ }
+ FillBgTilemapBufferRect(0, 0x1A5, x, 0xC, 1, 8, 0xFu);
+ FillBgTilemapBufferRect(0, 0x1A6, x, 0xB, 1, 1, 0xFu);
+ FillBgTilemapBufferRect(0, 0x1A7, x, 0x14, 1, 1, 0xFu);
+ ScheduleBgCopyTilemapToVram(0);
+}
+
+static void sub_809692C(struct Sprite *sprite)
+{
+ if (sprite->affineAnimEnded)
+ {
+ sub_8096624(sprite->data[0], FALSE);
+ sprite->callback = SpriteCallbackDummy;
+ }
+}
+
+static void sub_8096958(struct Sprite *sprite)
+{
+ switch (sprite->data[0])
+ {
+ case 0:
+ sprite->data[1] = sprite->pos1.x << 4;
+ sprite->data[2] = sprite->pos1.y << 4;
+ sprite->data[3] = 10;
+ sprite->data[4] = 21;
+ sprite->data[5] = 0;
+ sprite->data[0]++;
+ case 1:
+ sprite->data[1] -= sprite->data[3];
+ sprite->data[2] -= sprite->data[4];
+ sprite->pos1.x = sprite->data[1] >> 4;
+ sprite->pos1.y = sprite->data[2] >> 4;
+ if (++sprite->data[5] > 11)
+ sprite->callback = sub_80969BC;
+ break;
+ }
+}
+
+static void sub_80969BC(struct Sprite *sprite)
+{
+ sprite->pos1.x = sPSSData->field_CB4->pos1.x + 4;
+ sprite->pos1.y = sPSSData->field_CB4->pos1.y + sPSSData->field_CB4->pos2.y + 8;
+ sprite->oam.priority = sPSSData->field_CB4->oam.priority;
+}
+
+static void sub_80969F4(struct Sprite *sprite)
+{
+ switch (sprite->data[0])
+ {
+ case 0:
+ sprite->data[1] = sprite->pos1.x << 4;
+ sprite->data[2] = sprite->pos1.y << 4;
+ sprite->data[3] = 10;
+ sprite->data[4] = 21;
+ sprite->data[5] = 0;
+ sprite->data[0]++;
+ case 1:
+ sprite->data[1] += sprite->data[3];
+ sprite->data[2] += sprite->data[4];
+ sprite->pos1.x = sprite->data[1] >> 4;
+ sprite->pos1.y = sprite->data[2] >> 4;
+ if (++sprite->data[5] > 11)
+ {
+ sub_80962F0(sub_80962A8(sprite), sprite->data[6], sprite->data[7]);
+ sprite->callback = SpriteCallbackDummy;
+ }
+ break;
+ }
+}
+
+static void sub_8096A74(struct Sprite *sprite)
+{
+ switch (sprite->data[0])
+ {
+ case 0:
+ sprite->data[1] = sprite->pos1.x << 4;
+ sprite->data[2] = sprite->pos1.y << 4;
+ sprite->data[3] = 10;
+ sprite->data[4] = 21;
+ sprite->data[5] = 0;
+ sprite->data[0]++;
+ case 1:
+ sprite->data[1] -= sprite->data[3];
+ sprite->data[2] -= sprite->data[4];
+ sprite->pos1.x = sprite->data[1] >> 4;
+ sprite->pos1.y = sprite->data[2] >> 4;
+ sprite->pos2.x = gSineTable[sprite->data[5] * 8] >> 4;
+ if (++sprite->data[5] > 11)
+ {
+ sub_80962F0(sub_80962A8(sprite), sprite->data[6], sprite->data[7]);
+ sprite->pos2.x = 0;
+ sprite->callback = sub_80969BC;
+ }
+ break;
+ }
+}
+
+static void sub_8096B10(struct Sprite *sprite)
+{
+ switch (sprite->data[0])
+ {
+ case 0:
+ sprite->data[1] = sprite->pos1.x << 4;
+ sprite->data[2] = sprite->pos1.y << 4;
+ sprite->data[3] = 10;
+ sprite->data[4] = 21;
+ sprite->data[5] = 0;
+ sprite->data[0]++;
+ case 1:
+ sprite->data[1] += sprite->data[3];
+ sprite->data[2] += sprite->data[4];
+ sprite->pos1.x = sprite->data[1] >> 4;
+ sprite->pos1.y = sprite->data[2] >> 4;
+ sprite->pos2.x = -(gSineTable[sprite->data[5] * 8] >> 4);
+ if (++sprite->data[5] > 11)
+ {
+ sub_80962F0(sub_80962A8(sprite), sprite->data[6], sprite->data[7]);
+ sprite->callback = SpriteCallbackDummy;
+ sprite->pos2.x = 0;
+ }
+ break;
+ }
+}
+
+static void sub_8096BAC(struct Sprite *sprite)
+{
+ sprite->pos1.y -= 8;
+ if (sprite->pos1.y + sprite->pos2.y < -16)
+ {
+ sprite->callback = SpriteCallbackDummy;
+ sub_8096624(sub_80962A8(sprite), FALSE);
+ }
+}
diff --git a/src/pokemon_storage_system_9.c b/src/pokemon_storage_system_9.c
new file mode 100644
index 000000000..0f3078127
--- /dev/null
+++ b/src/pokemon_storage_system_9.c
@@ -0,0 +1,87 @@
+#include "global.h"
+#include "gflib.h"
+#include "pokemon_storage_system_internal.h"
+
+static EWRAM_DATA struct UnkStruct_2000020 *gUnknown_203982C = NULL;
+
+static void sub_8096CDC(struct UnkStruct_2000028 *unkStruct);
+static void sub_8096D70(struct UnkStruct_2000028 *unkStruct);
+
+void sub_8096BE4(struct UnkStruct_2000020 *arg0, struct UnkStruct_2000028 *arg1, u32 arg2)
+{
+ gUnknown_203982C = arg0;
+ arg0->unk_00 = arg1;
+ arg0->unk_05 = arg2;
+ arg0->unk_04 = 0;
+}
+
+void sub_8096BF8(void)
+{
+ u16 i;
+
+ if (gUnknown_203982C->unk_04)
+ {
+ for (i = 0; i < gUnknown_203982C->unk_04; i++)
+ {
+ struct UnkStruct_2000028 *unkStruct = &gUnknown_203982C->unk_00[i];
+ unkStruct->unk_0c(unkStruct);
+ }
+
+ gUnknown_203982C->unk_04 = 0;
+ }
+}
+
+static bool8 sub_8096C40(u8 *dest, u16 dLeft, u16 dTop, const u8 *src, u16 sLeft, u16 sTop, u16 width, u16 height, u16 unkArg)
+{
+ struct UnkStruct_2000028 *unkStruct;
+
+ if (gUnknown_203982C->unk_04 >= gUnknown_203982C->unk_05)
+ return FALSE;
+
+ unkStruct = &gUnknown_203982C->unk_00[gUnknown_203982C->unk_04++];
+ unkStruct->unk_08 = width * 2;
+ unkStruct->unk_04 = dest + 2 * (dTop * 32 + dLeft);
+ unkStruct->unk_00 = src + 2 * (sTop * unkArg + sLeft);
+ unkStruct->newField = height;
+ unkStruct->unk_0a = unkArg;
+ unkStruct->unk_0c = sub_8096CDC;
+ return TRUE;
+}
+
+static void sub_8096CDC(struct UnkStruct_2000028 *unkStruct)
+{
+ u16 i;
+
+ for (i = 0; i < unkStruct->newField; i++)
+ {
+ CpuSet(unkStruct->unk_00, unkStruct->unk_04, (unkStruct->unk_08 / 2));
+ unkStruct->unk_04 += 64;
+ unkStruct->unk_00 += (unkStruct->unk_0a * 2);
+ }
+}
+
+static bool8 sub_8096D14(void *dest, u16 dLeft, u16 dTop, u16 width, u16 height)
+{
+ struct UnkStruct_2000028 *unkStruct;
+
+ if (gUnknown_203982C->unk_04 >= gUnknown_203982C->unk_05)
+ return FALSE;
+
+ unkStruct = &gUnknown_203982C->unk_00[gUnknown_203982C->unk_04++];
+ unkStruct->unk_08 = width * 2;
+ unkStruct->unk_04 = dest + ((dTop * 32) + dLeft) * 2;
+ unkStruct->newField = height;
+ unkStruct->unk_0c = sub_8096D70;
+ return TRUE;
+}
+
+static void sub_8096D70(struct UnkStruct_2000028 *unkStruct)
+{
+ u16 i;
+
+ for (i = 0; i < unkStruct->newField; i++)
+ {
+ Dma3FillLarge_(0, unkStruct->unk_04, unkStruct->unk_08, 16);
+ unkStruct->unk_04 += 64;
+ }
+}
diff --git a/src/quest_log.c b/src/quest_log.c
index 91c07223e..bc8e67a6b 100644
--- a/src/quest_log.c
+++ b/src/quest_log.c
@@ -752,7 +752,7 @@ void sub_8111438(void)
{
for (r3 = 0; r3 < 5; r3++)
{
- sub_808BCB4(0, r3);
+ ZeroBoxMonAt(0, r3);
}
for (r3 = r5; r3 < r9->sanePartyCount; r3++)
{
@@ -767,9 +767,9 @@ void sub_8111438(void)
{
for (r6 = 0; r6 < 30; r6++)
{
- if (GetBoxMonDataFromAnyBox(r3, r6, MON_DATA_SANITY_HAS_SPECIES))
+ if (GetBoxMonDataAt(r3, r6, MON_DATA_SANITY_HAS_SPECIES))
{
- sub_808BCB4(r3, r6);
+ ZeroBoxMonAt(r3, r6);
r5--;
if (r5 == r9->saneBoxesCount)
break;
@@ -832,7 +832,7 @@ static u16 QuestLog_GetSaneBoxCount(void)
{
for (j = 0; j < IN_BOX_COUNT; j++)
{
- if (GetBoxMonDataFromAnyBox(i, j, MON_DATA_SANITY_HAS_SPECIES))
+ if (GetBoxMonDataAt(i, j, MON_DATA_SANITY_HAS_SPECIES))
count++;
}
}
diff --git a/src/string_util.c b/src/string_util.c
index 4c1106df8..0a2365d25 100644
--- a/src/string_util.c
+++ b/src/string_util.c
@@ -532,11 +532,11 @@ u8 *StringFillWithTerminator(u8 *dest, u16 n)
return StringFill(dest, EOS, n);
}
-u8 *StringCopyN_Multibyte(u8 *dest, u8 *src, u32 n)
+u8 *StringCopyN_Multibyte(u8 *dest, const u8 *src, u32 n)
{
u32 i;
- for (i = n - 1; i != (u32)-1; i--)
+ for (i = n - 1; i != -1u; i--)
{
if (*src == EOS)
{
@@ -554,7 +554,7 @@ u8 *StringCopyN_Multibyte(u8 *dest, u8 *src, u32 n)
return dest;
}
-u32 StringLength_Multibyte(u8 *str)
+u32 StringLength_Multibyte(const u8 *str)
{
u32 length = 0;
diff --git a/src/strings.c b/src/strings.c
index f5040838a..faf42c86a 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -601,87 +601,87 @@ const u8 gString_BattleRecords_4Dashes[] = _("----");
const u8 gFameCheckerText_FameCheckerWillBeClosed[] = _("The FAME CHECKER will be closed.");
const u8 gFameCheckerText_ClearTextbox[] = _("\n ");
const u8 gUnknown_8418204[] = _("やめる");
-const u8 gUnknown_8418208[] = _("Exit from the BOX.");
-const u8 gUnknown_841821B[] = _("What do you want to do?");
-const u8 gUnknown_8418233[] = _("Please pick a theme.");
-const u8 gUnknown_8418248[] = _("Pick the wallpaper.");
-const u8 gUnknown_841825C[] = _("{DYNAMIC 0x00} is selected.");
-const u8 gUnknown_841826C[] = _("Jump to which BOX?");
-const u8 gUnknown_841827F[] = _("Deposit in which BOX?");
-const u8 gUnknown_8418295[] = _("{DYNAMIC 0x00} was deposited.");
-const u8 gUnknown_84182A7[] = _("The BOX is full.");
-const u8 gUnknown_84182B8[] = _("Release this POKéMON?");
-const u8 gUnknown_84182CE[] = _("{DYNAMIC 0x00} was released.");
-const u8 gUnknown_84182DF[] = _("Bye-bye, {DYNAMIC 0x00}!");
-const u8 gUnknown_84182EC[] = _("Mark your POKéMON.");
-const u8 gUnknown_84182FF[] = _("That's your last POKéMON!");
-const u8 gUnknown_8418319[] = _("Your party's full!");
-const u8 gUnknown_841832C[] = _("You're holding a POKéMON!");
-const u8 gUnknown_8418346[] = _("Which one will you take?");
-const u8 gUnknown_841835F[] = _("You can't release an EGG.");
-const u8 gUnknown_8418379[] = _("Continue BOX operations?");
-const u8 gUnknown_8418392[] = _("{DYNAMIC 0x00} came back!");
-const u8 gUnknown_84183A0[] = _("Was it worried about you?");
-const u8 gUnknown_84183BA[] = _("‥ ‥ ‥ ‥ ‥!");
-const u8 gUnknown_84183C5[] = _("Please remove the MAIL.");
-const u8 gUnknown_84183DD[] = _("GIVE to a POKéMON?");
-const u8 gUnknown_84183F0[] = _("Placed item in the BAG.");
-const u8 gUnknown_8418408[] = _("The BAG is full.");
-const u8 gUnknown_8418419[] = _("Put this item in the BAG?");
-const u8 gUnknown_8418433[] = _("{DYNAMIC 0x00} is now held.");
-const u8 gUnknown_8418443[] = _("Changed to {DYNAMIC 0x00}.");
-const u8 gUnknown_8418452[] = _("MAIL can't be stored!");
-const u8 gUnknown_8418468[] = _("CANCEL");
-const u8 gUnknown_841846F[] = _("STORE");
-const u8 gUnknown_8418475[] = _("WITHDRAW");
-const u8 gUnknown_841847E[] = _("SHIFT");
-const u8 gUnknown_8418484[] = _("MOVE");
-const u8 gUnknown_8418489[] = _("PLACE");
-const u8 gUnknown_841848F[] = _("SUMMARY");
-const u8 gUnknown_8418497[] = _("RELEASE");
-const u8 gUnknown_841849F[] = _("MARK");
-const u8 gUnknown_84184A4[] = _("NAME");
-const u8 gUnknown_84184A9[] = _("JUMP");
-const u8 gUnknown_84184AE[] = _("WALLPAPER");
-const u8 gUnknown_84184B8[] = _("TAKE");
-const u8 gUnknown_84184BD[] = _("GIVE");
-const u8 gUnknown_84184C2[] = _("SWITCH");
-const u8 gUnknown_84184C9[] = _("BAG");
-const u8 gUnknown_84184CD[] = _("INFO");
-const u8 gUnknown_84184D2[] = _("SCENERY 1");
-const u8 gUnknown_84184DC[] = _("SCENERY 2");
-const u8 gUnknown_84184E6[] = _("SCENERY 3");
-const u8 gUnknown_84184F0[] = _("ETCETERA");
-const u8 gUnknown_84184F9[] = _("FOREST");
-const u8 gUnknown_8418500[] = _("CITY");
-const u8 gUnknown_8418505[] = _("DESERT");
-const u8 gUnknown_841850C[] = _("SAVANNA");
-const u8 gUnknown_8418514[] = _("CRAG");
-const u8 gUnknown_8418519[] = _("VOLCANO");
-const u8 gUnknown_8418521[] = _("SNOW");
-const u8 gUnknown_8418526[] = _("CAVE");
-const u8 gUnknown_841852B[] = _("BEACH");
-const u8 gUnknown_8418531[] = _("SEAFLOOR");
-const u8 gUnknown_841853A[] = _("RIVER");
-const u8 gUnknown_8418540[] = _("SKY");
-const u8 gUnknown_8418544[] = _("STARS");
-const u8 gUnknown_841854A[] = _("POKéCENTER");
-const u8 gUnknown_8418555[] = _("TILES");
-const u8 gUnknown_841855B[] = _("SIMPLE");
+const u8 gText_ExitFromBox[] = _("Exit from the BOX.");
+const u8 gText_WhatDoYouWantToDo[] = _("What do you want to do?");
+const u8 gText_PleasePickATheme[] = _("Please pick a theme.");
+const u8 gText_PickTheWallpaper[] = _("Pick the wallpaper.");
+const u8 gText_PkmnIsSelected[] = _("{DYNAMIC 0x00} is selected.");
+const u8 gText_JumpToWhichBox[] = _("Jump to which BOX?");
+const u8 gText_DepositInWhichBox[] = _("Deposit in which BOX?");
+const u8 gText_PkmnWasDeposited[] = _("{DYNAMIC 0x00} was deposited.");
+const u8 gText_BoxIsFull2[] = _("The BOX is full.");
+const u8 gText_ReleaseThisPokemon[] = _("Release this POKéMON?");
+const u8 gText_PkmnWasReleased[] = _("{DYNAMIC 0x00} was released.");
+const u8 gText_ByeByePkmn[] = _("Bye-bye, {DYNAMIC 0x00}!");
+const u8 gText_MarkYourPkmn[] = _("Mark your POKéMON.");
+const u8 gText_ThatsYourLastPkmn[] = _("That's your last POKéMON!");
+const u8 gText_YourPartysFull[] = _("Your party's full!");
+const u8 gText_YoureHoldingAPkmn[] = _("You're holding a POKéMON!");
+const u8 gText_WhichOneWillYouTake[] = _("Which one will you take?");
+const u8 gText_YouCantReleaseAnEgg[] = _("You can't release an EGG.");
+const u8 gText_ContinueBoxOperations[] = _("Continue BOX operations?");
+const u8 gText_PkmnCameBack[] = _("{DYNAMIC 0x00} came back!");
+const u8 gText_WasItWorriedAboutYou[] = _("Was it worried about you?");
+const u8 gText_FourEllipsesExclamation[] = _("‥ ‥ ‥ ‥ ‥!");
+const u8 gText_PleaseRemoveTheMail[] = _("Please remove the MAIL.");
+const u8 gText_GiveToAPkmn[] = _("GIVE to a POKéMON?");
+const u8 gText_PlacedItemInBag[] = _("Placed item in the BAG.");
+const u8 gText_BagIsFull2[] = _("The BAG is full.");
+const u8 gText_PutItemInBag[] = _("Put this item in the BAG?");
+const u8 gText_ItemIsNowHeld[] = _("{DYNAMIC 0x00} is now held.");
+const u8 gText_ChangedToNewItem[] = _("Changed to {DYNAMIC 0x00}.");
+const u8 gText_MailCantBeStored[] = _("MAIL can't be stored!");
+const u8 gPCText_Cancel[] = _("CANCEL");
+const u8 gPCText_Store[] = _("STORE");
+const u8 gPCText_Withdraw[] = _("WITHDRAW");
+const u8 gPCText_Shift[] = _("SHIFT");
+const u8 gPCText_Move[] = _("MOVE");
+const u8 gPCText_Place[] = _("PLACE");
+const u8 gPCText_Summary[] = _("SUMMARY");
+const u8 gPCText_Release[] = _("RELEASE");
+const u8 gPCText_Mark[] = _("MARK");
+const u8 gPCText_Name[] = _("NAME");
+const u8 gPCText_Jump[] = _("JUMP");
+const u8 gPCText_Wallpaper[] = _("WALLPAPER");
+const u8 gPCText_Take[] = _("TAKE");
+const u8 gPCText_Give[] = _("GIVE");
+const u8 gPCText_Switch[] = _("SWITCH");
+const u8 gPCText_Bag[] = _("BAG");
+const u8 gPCText_Info[] = _("INFO");
+const u8 gPCText_Scenery1[] = _("SCENERY 1");
+const u8 gPCText_Scenery2[] = _("SCENERY 2");
+const u8 gPCText_Scenery3[] = _("SCENERY 3");
+const u8 gPCText_Etcetera[] = _("ETCETERA");
+const u8 gPCText_Forest[] = _("FOREST");
+const u8 gPCText_City[] = _("CITY");
+const u8 gPCText_Desert[] = _("DESERT");
+const u8 gPCText_Savanna[] = _("SAVANNA");
+const u8 gPCText_Crag[] = _("CRAG");
+const u8 gPCText_Volcano[] = _("VOLCANO");
+const u8 gPCText_Snow[] = _("SNOW");
+const u8 gPCText_Cave[] = _("CAVE");
+const u8 gPCText_Beach[] = _("BEACH");
+const u8 gPCText_Seafloor[] = _("SEAFLOOR");
+const u8 gPCText_River[] = _("RIVER");
+const u8 gPCText_Sky[] = _("SKY");
+const u8 gPCText_PolkaDot[] = _("STARS");
+const u8 gPCText_Pokecenter[] = _("POKéCENTER");
+const u8 gPCText_Machine[] = _("TILES");
+const u8 gPCText_Simple[] = _("SIMPLE");
const u8 gUnknown_8418562[] = _("なにを しますか?");
-const u8 gUnknown_841856C[] = _("WITHDRAW POKéMON");
-const u8 gUnknown_841857D[] = _("DEPOSIT POKéMON");
-const u8 gUnknown_841858D[] = _("MOVE POKéMON");
-const u8 gUnknown_841859A[] = _("MOVE ITEMS");
-const u8 gUnknown_84185A5[] = _("SEE YA!");
-const u8 gUnknown_84185AD[] = _("You can withdraw a POKéMON if you\nhave any in a BOX.");
-const u8 gUnknown_84185E2[] = _("You can deposit your party\nPOKéMON in any BOX.");
-const u8 gUnknown_8418611[] = _("You can move POKéMON that are\nstored in any BOX.");
-const u8 gUnknown_8418642[] = _("You can move items held by any\nPOKéMON in a BOX or your party.");
-const u8 gUnknown_8418681[] = _("See you later!");
-const u8 gUnknown_8418690[] = _("Can't deposit the last POKéMON!");
-const u8 gUnknown_84186B0[] = _("Can't take any more POKéMON.");
-const u8 gUnknown_84186CD[] = _("BOX");
+const u8 gText_WithdrawPokemon[] = _("WITHDRAW POKéMON");
+const u8 gText_DepositPokemon[] = _("DEPOSIT POKéMON");
+const u8 gText_MovePokemon[] = _("MOVE POKéMON");
+const u8 gText_MoveItems[] = _("MOVE ITEMS");
+const u8 gText_SeeYa[] = _("SEE YA!");
+const u8 gText_WithdrawMonDescription[] = _("You can withdraw a POKéMON if you\nhave any in a BOX.");
+const u8 gText_DepositMonDescription[] = _("You can deposit your party\nPOKéMON in any BOX.");
+const u8 gText_MoveMonDescription[] = _("You can move POKéMON that are\nstored in any BOX.");
+const u8 gText_MoveItemsDescription[] = _("You can move items held by any\nPOKéMON in a BOX or your party.");
+const u8 gText_SeeYaDescription[] = _("See you later!");
+const u8 gText_JustOnePkmn[] = _("Can't deposit the last POKéMON!");
+const u8 gText_PartyFull[] = _("Can't take any more POKéMON.");
+const u8 gText_Box[] = _("BOX");
const u8 gUnknown_84186D1[] = _("Combine four words or phrases");
const u8 gUnknown_84186EF[] = _("and make your profile.");
const u8 gUnknown_8418706[] = _("Make a message of six phrases.");
diff --git a/src/tm_case.c b/src/tm_case.c
index 2f27cc0db..7bb471719 100644
--- a/src/tm_case.c
+++ b/src/tm_case.c
@@ -959,7 +959,7 @@ static void Task_SelectTMAction_Type3(u8 taskId)
if (!itemid_is_unique(BagGetItemIdByPocketPosition(POCKET_TM_CASE, data[1])))
{
- sTMCaseDynamicResources->savedCallback = sub_808CE60;
+ sTMCaseDynamicResources->savedCallback = Cb2_ReturnToPSS;
Task_BeginFadeOutFromTMCase(taskId);
}
else
diff --git a/src/trade.c b/src/trade.c
index 30bfa8389..bd6860e85 100644
--- a/src/trade.c
+++ b/src/trade.c
@@ -882,10 +882,10 @@ static void sub_804C728(void)
gMain.state++;
break;
case 10:
- PSS_RenderTextToVramViaBuffer(gSaveBlock2Ptr->playerName, sSpriteTextTilePtrs[0], 0, 0, gDecompressionBuffer, 3);
+ DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sSpriteTextTilePtrs[0], 0, 0, gDecompressionBuffer, 3);
id = GetMultiplayerId();
- PSS_RenderTextToVramViaBuffer(gLinkPlayers[id ^ 1].name, sSpriteTextTilePtrs[3], 0, 0, gDecompressionBuffer, 3);
- PSS_RenderTextToVramViaBuffer(sTradeUITextPtrs[TRADEUITEXT_CANCEL], sSpriteTextTilePtrs[6], 0, 0, gDecompressionBuffer, 2);
+ DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sSpriteTextTilePtrs[3], 0, 0, gDecompressionBuffer, 3);
+ DrawTextWindowAndBufferTiles(sTradeUITextPtrs[TRADEUITEXT_CANCEL], sSpriteTextTilePtrs[6], 0, 0, gDecompressionBuffer, 2);
RenderTextToVramViaBuffer(sTradeUITextPtrs[TRADEUITEXT_CHOOSE], sSpriteTextTilePtrs[8], 24);
gMain.state++;
sTradeMenuResourcesPtr->unk_A8 = 0;
@@ -1080,10 +1080,10 @@ void sub_804CF14(void)
gMain.state++;
break;
case 10:
- PSS_RenderTextToVramViaBuffer(gSaveBlock2Ptr->playerName, sSpriteTextTilePtrs[0], 0, 0, gDecompressionBuffer, 3);
+ DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sSpriteTextTilePtrs[0], 0, 0, gDecompressionBuffer, 3);
id = GetMultiplayerId();
- PSS_RenderTextToVramViaBuffer(gLinkPlayers[id ^ 1].name, sSpriteTextTilePtrs[3], 0, 0, gDecompressionBuffer, 3);
- PSS_RenderTextToVramViaBuffer(sTradeUITextPtrs[TRADEUITEXT_CANCEL], sSpriteTextTilePtrs[6], 0, 0, gDecompressionBuffer, 2);
+ DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sSpriteTextTilePtrs[3], 0, 0, gDecompressionBuffer, 3);
+ DrawTextWindowAndBufferTiles(sTradeUITextPtrs[TRADEUITEXT_CANCEL], sSpriteTextTilePtrs[6], 0, 0, gDecompressionBuffer, 2);
RenderTextToVramViaBuffer(sTradeUITextPtrs[TRADEUITEXT_CHOOSE], sSpriteTextTilePtrs[8], 24);
gMain.state++;
sTradeMenuResourcesPtr->unk_A8 = 0;
@@ -2502,7 +2502,7 @@ static bool8 sub_804F610(void)
static void RenderTextToVramViaBuffer(const u8 *name, u8 *dest, u8 unused)
{
- PSS_RenderTextToVramViaBuffer(name, dest, 0, 0, gDecompressionBuffer, 6);
+ DrawTextWindowAndBufferTiles(name, dest, 0, 0, gDecompressionBuffer, 6);
}
static void sub_804F748(u8 who)
diff --git a/src/window_8bpp.c b/src/window_8bpp.c
index c58c13802..8977d61e4 100644
--- a/src/window_8bpp.c
+++ b/src/window_8bpp.c
@@ -13,7 +13,7 @@ static void nullsub_9(void)
{
}
-u16 AddWindow8Bit(struct WindowTemplate *template)
+u16 AddWindow8Bit(const struct WindowTemplate *template)
{
u16 windowId;
u8* memAddress;
@@ -81,7 +81,7 @@ void FillWindowPixelRect8Bit(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width,
FillBitmapRect8Bit(&pixelRect, x, y, width, height, fillValue);
}
-void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight, u8 paletteNum)
+void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight, u8 paletteNum)
{
struct Bitmap sourceRect;
struct Bitmap destRect;