diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/battle/anim/psychic.c | 900 | ||||
-rw-r--r-- | src/battle/anim/rock.c | 602 | ||||
-rw-r--r-- | src/engine/naming_screen.c | 2 | ||||
-rw-r--r-- | src/field/choose_party.c | 3 | ||||
-rw-r--r-- | src/field/daycare.c | 2 | ||||
-rw-r--r-- | src/field/field_effect.c | 1 | ||||
-rw-r--r-- | src/field/pc_screen_effect.c | 17 | ||||
-rw-r--r-- | src/field/pokedex_area_screen.c | 20 | ||||
-rw-r--r-- | src/field/pokenav.c | 16 | ||||
-rw-r--r-- | src/field/use_pokeblock.c | 1 | ||||
-rw-r--r-- | src/libs/m4a_1.s | 6 | ||||
-rw-r--r-- | src/pokemon/mon_markings.c | 20 | ||||
-rw-r--r-- | src/pokemon/pokemon_1.c | 2 | ||||
-rw-r--r-- | src/pokemon/pokemon_2.c | 3 | ||||
-rw-r--r-- | src/pokemon/pokemon_storage_system.c | 635 | ||||
-rw-r--r-- | src/pokemon/pokemon_storage_system_2.c | 2063 | ||||
-rw-r--r-- | src/pokemon/pokemon_storage_system_3.c | 655 | ||||
-rw-r--r-- | src/pokemon/pokemon_storage_system_4.c | 2844 | ||||
-rw-r--r-- | src/pokemon/pokemon_storage_system_5.c | 16 | ||||
-rw-r--r-- | src/pokemon/pokemon_summary_screen.c | 31 | ||||
-rw-r--r-- | src/pokenav_before.c | 1 | ||||
-rw-r--r-- | src/rom_8077ABC.c | 2 | ||||
-rw-r--r-- | src/scene/hall_of_fame.c | 44 |
23 files changed, 7737 insertions, 149 deletions
diff --git a/src/battle/anim/psychic.c b/src/battle/anim/psychic.c new file mode 100644 index 000000000..6617183cb --- /dev/null +++ b/src/battle/anim/psychic.c @@ -0,0 +1,900 @@ +#include "global.h" +#include "battle.h" +#include "battle_anim.h" +#include "palette.h" +#include "rom_8077ABC.h" +#include "scanline_effect.h" +#include "sound.h" +#include "task.h" +#include "trig.h" +#include "constants/songs.h" + +extern s16 gBattleAnimArgs[]; +extern u8 gAnimBankAttacker; +extern u8 gAnimBankTarget; +extern u16 gBattle_BG1_X; +extern u16 gBattle_BG2_X; +extern u8 gObjectBankIDs[]; + +extern const union AffineAnimCmd *const gUnknown_083DA888[]; +extern struct AffineAnimFrameCmd gUnknown_083DA8A4; +extern struct AffineAnimFrameCmd gUnknown_083DA8C4; +extern const struct SpriteTemplate gSpriteTemplate_83DA8DC; +extern const struct SpriteTemplate gSpriteTemplate_83DA9AC; + +static void sub_80DB88C(struct Sprite *sprite); +static void sub_80DB8C0(struct Sprite *sprite); +static void sub_80DB92C(struct Sprite *sprite); +static void sub_80DB9E4(struct Sprite *sprite); +static void sub_80DBC00(struct Sprite *sprite); +static void sub_80DBC34(struct Sprite *sprite); +static void sub_80DBCD0(u8 taskId); +static void sub_80DBD58(u8 taskId); +static void sub_80DBE98(u8 taskId); +static void sub_80DC1FC(u8 taskId); +static void sub_80DC3F4(u8 taskId); +void sub_80DC5F4(u8 taskId); + + +void sub_80DB74C(struct Sprite *sprite) +{ + if (GetBankSide(gAnimBankAttacker) == SIDE_PLAYER || IsContest()) + { + sprite->oam.priority = 2; + sprite->subpriority = 200; + } + + if (!IsContest()) + { + u8 bankCopy; + u8 bank = bankCopy = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + u8 identity = GetBankIdentity_permutated(bank); + int var0 = 1; + u8 toBG_2 = (identity ^ var0) != 0; + + if (IsAnimBankSpriteVisible(bank)) + sub_8076034(bank, toBG_2); + + bank = bankCopy ^ 2; + if (IsAnimBankSpriteVisible(bank)) + sub_8076034(bank, toBG_2 ^ var0); + } + + if (!IsContest() && IsDoubleBattle()) + { + if (GetBankSide(gAnimBankAttacker) == SIDE_PLAYER) + { + sprite->pos1.x = 72; + sprite->pos1.y = 80; + } + else + { + sprite->pos1.x = 176; + sprite->pos1.y = 40; + } + } + else + { + if (GetBankSide(gAnimBankAttacker) != SIDE_PLAYER) + gBattleAnimArgs[0] = -gBattleAnimArgs[0]; + + sprite->pos1.x = GetBankPosition(gAnimBankAttacker, 0) + gBattleAnimArgs[0]; + sprite->pos1.y = GetBankPosition(gAnimBankAttacker, 1) + gBattleAnimArgs[1]; + } + + if (IsContest()) + sprite->pos1.y += 9; + + sprite->data[0] = 256 + IndexOfSpritePaletteTag(gBattleAnimArgs[2]) * 16; + sprite->callback = sub_80DB88C; + sprite->callback(sprite); +} + +static void sub_80DB88C(struct Sprite *sprite) +{ + REG_BLDALPHA = ((16 - sprite->data[3]) << 8) | sprite->data[3]; + + if (sprite->data[3] == 13) + sprite->callback = sub_80DB8C0; + else + sprite->data[3]++; +} + +static void sub_80DB8C0(struct Sprite *sprite) +{ + u16 color; + u16 startOffset; + int i; + + if (++sprite->data[1] == 2) + { + sprite->data[1] = 0; + startOffset = sprite->data[0]; + color = gPlttBufferFaded[startOffset + 8]; + + for (i = 8; i > 0; i--) + gPlttBufferFaded[startOffset + i] = gPlttBufferFaded[startOffset + i - 1]; + + gPlttBufferFaded[startOffset + 1] = color; + + if (++sprite->data[2] == 16) + sprite->callback = sub_80DB92C; + } +} + +static void sub_80DB92C(struct Sprite *sprite) +{ + REG_BLDALPHA = ((16 - sprite->data[3]) << 8) | sprite->data[3]; + + if (--sprite->data[3] == -1) + { + if (!IsContest()) + { + u8 bankCopy; + u8 bank = bankCopy = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + + if (IsAnimBankSpriteVisible(bank)) + gSprites[gObjectBankIDs[bank]].invisible = 0; + + bank = bankCopy ^ 2; + if (IsAnimBankSpriteVisible(bank)) + gSprites[gObjectBankIDs[bank]].invisible = 0; + } + + sprite->invisible = 1; + sprite->callback = sub_80DB9E4; + } +} + +static void sub_80DB9E4(struct Sprite *sprite) +{ + if (!IsContest()) + { + u8 bankCopy; + u8 bank = bankCopy = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + u8 identity = GetBankIdentity_permutated(bank); + int var0 = 1; + u8 toBG_2 = (identity ^ var0) != 0; + + if (IsAnimBankSpriteVisible(bank)) + sub_8076464(toBG_2); + + bank = bankCopy ^ 2; + if (IsAnimBankSpriteVisible(bank)) + sub_8076464(toBG_2 ^ var0); + } + + sprite->callback = DestroyAnimSprite; +} + +void sub_80DBA4C(struct Sprite *sprite) +{ + if (sprite->data[0] == 0) + { + int arg3 = gBattleAnimArgs[3]; + u8 var0 = 0; + if (arg3 == 0) + var0 = 1; + + if (!IsContest() && IsDoubleBattle()) + { + if (GetBankSide(gAnimBankAttacker) == SIDE_PLAYER) + { + sprite->pos1.x = 72 - gBattleAnimArgs[0]; + sprite->pos1.y = gBattleAnimArgs[1] + 80; + } + else + { + sprite->pos1.x = gBattleAnimArgs[0] + 176; + sprite->pos1.y = gBattleAnimArgs[1] + 40; + } + } + else + { + if (gBattleAnimArgs[2] == 0) + sub_80787B0(sprite, var0); + else + sub_8078764(sprite, var0); + } + + sprite->data[0]++; + } + else + { + if (sprite->animEnded || sprite->affineAnimEnded) + move_anim_8074EE0(sprite); + } +} + +void sub_80DBAF4(struct Sprite *sprite) +{ + sprite->pos1.x = GetBankPosition(gAnimBankAttacker, 2); + sprite->pos1.y = GetBankPosition(gAnimBankAttacker, 3); + + if (GetBankSide(gAnimBankAttacker) != SIDE_PLAYER) + { + StartSpriteAnim(sprite, 1); + sprite->pos1.x -= 40; + sprite->pos1.y += 10; + sprite->data[1] = -1; + } + else + { + sprite->pos1.x += 40; + sprite->pos1.y -= 10; + sprite->data[1] = 1; + } + + StoreSpriteCallbackInData(sprite, DestroyAnimSprite); + sprite->callback = sub_8078600; +} + +void sub_80DBB70(struct Sprite *sprite) +{ + s16 x = sub_807A100(gAnimBankAttacker, 1) / 2; + s16 y = sub_807A100(gAnimBankAttacker, 0) / -2; + + if (GetBankSide(gAnimBankAttacker) == SIDE_OPPONENT) + { + x = -x; + } + + sprite->pos1.x = GetBankPosition(gAnimBankAttacker, 2) + x; + sprite->pos1.y = GetBankPosition(gAnimBankAttacker, 3) + y; + + if (sprite->pos1.y < 16) + { + sprite->pos1.y = 16; + } + + StoreSpriteCallbackInData(sprite, sub_80DBC00); + sprite->callback = sub_8078600; +} + +static void sub_80DBC00(struct Sprite *sprite) +{ + sprite->oam.affineMode = 1; + sprite->affineAnims = gUnknown_083DA888; + sprite->data[0] = 0; + InitSpriteAffineAnim(sprite); + sprite->callback = sub_80DBC34; +} + +static void sub_80DBC34(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + if (sprite->affineAnimEnded) + { + FreeOamMatrix(sprite->oam.matrixNum); + sprite->oam.affineMode = 0; + sprite->data[1] = 18; + sprite->data[0]++; + } + break; + case 1: + if (--sprite->data[1] == -1) + { + DestroyAnimSprite(sprite); + } + break; + } +} + +void sub_80DBC94(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + u8 spriteId = GetAnimBankSpriteId(0); + task->data[0] = spriteId; + sub_80798F4(task, spriteId, &gUnknown_083DA8A4); + task->func = sub_80DBCD0; +} + +static void sub_80DBCD0(u8 taskId) +{ + if (!sub_807992C(&gTasks[taskId])) + { + DestroyAnimVisualTask(taskId); + } +} + +void sub_80DBCFC(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + u8 spriteId = GetAnimBankSpriteId(0); + task->data[0] = spriteId; + task->data[1] = 0; + task->data[2] = 0; + task->data[3] = GetBankSide(gAnimBankAttacker) != SIDE_PLAYER ? 4 : 8; + + sub_80798F4(task, task->data[0], &gUnknown_083DA8C4); + task->func = sub_80DBD58; +} + +static void sub_80DBD58(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + switch (task->data[1]) + { + case 0: + sub_807992C(task); + if (++task->data[2] > 19) + task->data[1]++; + break; + case 1: + if (task->data[3] != 0) + { + gSprites[task->data[0]].pos2.y -= 8; + task->data[3]--; + } + else + { + gSprites[task->data[0]].invisible = 1; + gSprites[task->data[0]].pos1.x = 272; + sub_8078F40(task->data[0]); + DestroyAnimVisualTask(taskId); + } + break; + } +} + +void sub_80DBE00(u8 taskId) +{ + u16 var0, var1; + + struct Task *task = &gTasks[taskId]; + + task->data[3] = 16; + task->data[4] = 0; + task->data[13] = GetBankPosition(gAnimBankAttacker, 2); + task->data[14] = GetBankPosition(gAnimBankAttacker, 3); + + var0 = sub_807A100(gAnimBankAttacker, 1) / 3; + var1 = sub_807A100(gAnimBankAttacker, 0) / 3; + task->data[12] = var0 > var1 ? var0 : var1; + + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = 0x10; + + task->func = sub_80DBE98; +} + +static void sub_80DBE98(u8 taskId) +{ + u16 i; + u8 spriteId; + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + if (++task->data[1] > 8) + { + task->data[1] = 0; + spriteId = CreateSprite(&gSpriteTemplate_83DA8DC, task->data[13], task->data[14], 0); + task->data[task->data[2] + 8] = spriteId; + + if (spriteId != 64) + { + switch (task->data[2]) + { + case 0: + gSprites[spriteId].pos2.x = task->data[12]; + gSprites[spriteId].pos2.y = -task->data[12]; + break; + case 1: + gSprites[spriteId].pos2.x = -task->data[12]; + gSprites[spriteId].pos2.y = task->data[12]; + break; + case 2: + gSprites[spriteId].pos2.x = task->data[12]; + gSprites[spriteId].pos2.y = task->data[12]; + break; + case 3: + gSprites[spriteId].pos2.x = -task->data[12]; + gSprites[spriteId].pos2.y = -task->data[12]; + break; + } + } + + if (++task->data[2] == 5) + task->data[0]++; + } + break; + case 1: + if (task->data[1] & 1) + task->data[3]--; + else + task->data[4]++; + + REG_BLDALPHA = (task->data[4] << 8) | task->data[3]; + + if (++task->data[1] == 32) + { + for (i = 8; i < 13; i++) + { + if (task->data[i] != 64) + DestroySprite(&gSprites[task->data[i]]); + } + + task->data[0]++; + } + break; + case 2: + task->data[0]++; + break; + case 3: + REG_BLDALPHA = 0; + REG_BLDCNT = 0; + DestroyAnimVisualTask(taskId); + break; + } +} + +static void sub_80DC020(struct Sprite *sprite) +{ + if (sprite->data[1] > sprite->data[0] - 10) + sprite->invisible = sprite->data[1] & 1; + + if (sprite->data[1] == sprite->data[0]) + DestroyAnimSprite(sprite); + + sprite->data[1]++; +} + +void sub_80DC068(struct Sprite *sprite) +{ + if (gBattleAnimArgs[0] == 0) + { + sprite->pos1.x = GetBankPosition(gAnimBankAttacker, 2); + sprite->pos1.y = GetBankPosition(gAnimBankAttacker, 3); + } + + sprite->data[0] = gBattleAnimArgs[1]; + sprite->callback = sub_80DC020; +} + +void sub_80DC0B0(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + if (IsContest()) + { + if (gBattleAnimArgs[0] == 1) + { + task->data[10] = -10; + task->data[11] = sub_807A100(gAnimBankTarget, 5) - 8; + task->data[12] = sub_807A100(gAnimBankTarget, 2) + 8; + task->data[13] = sub_807A100(gAnimBankAttacker, 5) - 8; + task->data[14] = sub_807A100(gAnimBankAttacker, 2) + 8; + } + else + { + task->data[10] = 10; + task->data[11] = sub_807A100(gAnimBankAttacker, 4) + 8; + task->data[12] = sub_807A100(gAnimBankAttacker, 3) - 8; + task->data[13] = sub_807A100(gAnimBankTarget, 4) + 8; + task->data[14] = sub_807A100(gAnimBankTarget, 3) - 8; + } + } + else + { + if (gBattleAnimArgs[0] == 1) + { + task->data[10] = -10; + task->data[11] = sub_807A100(gAnimBankTarget, 4) + 8; + task->data[12] = sub_807A100(gAnimBankTarget, 2) + 8; + task->data[13] = sub_807A100(gAnimBankAttacker, 4) + 8; + task->data[14] = sub_807A100(gAnimBankAttacker, 2) + 8; + } + else + { + task->data[10] = 10; + task->data[11] = sub_807A100(gAnimBankAttacker, 5) - 8; + task->data[12] = sub_807A100(gAnimBankAttacker, 3) - 8; + task->data[13] = sub_807A100(gAnimBankTarget, 5) - 8; + task->data[14] = sub_807A100(gAnimBankTarget, 3) - 8; + } + } + + task->data[1] = 6; + task->func = sub_80DC1FC; +} + +static void sub_80DC1FC(u8 taskId) +{ + u8 spriteId; + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + if (++task->data[1] > 6) + { + task->data[1] = 0; + spriteId = CreateSprite(&gSpriteTemplate_83DA9AC, task->data[11], task->data[12], 0); + if (spriteId != 64) + { + gSprites[spriteId].data[0] = 16; + gSprites[spriteId].data[2] = task->data[13]; + gSprites[spriteId].data[4] = task->data[14]; + gSprites[spriteId].data[5] = task->data[10]; + + sub_80786EC(&gSprites[spriteId]); + StartSpriteAffineAnim(&gSprites[spriteId], task->data[2] & 3); + } + + if (++task->data[2] == 12) + task->data[0]++; + } + break; + case 1: + if (++task->data[1] > 17) + DestroyAnimVisualTask(taskId); + break; + } +} + +void sub_80DC2B0(struct Sprite *sprite) +{ + if (sub_8078718(sprite)) + { + FreeOamMatrix(sprite->oam.matrixNum); + DestroySprite(sprite); + } +} + +void sub_80DC2D4(u8 taskId) +{ + s16 i; + u8 var1; + struct ScanlineEffectParams scanlineParams; + struct Task *task = &gTasks[taskId]; + + var1 = sub_8077FC0(gAnimBankTarget); + task->data[14] = var1 - 32; + + switch (gBattleAnimArgs[0]) + { + case 0: + task->data[11] = 2; + task->data[12] = 5; + task->data[13] = 64; + task->data[15] = var1 + 32; + break; + case 1: + task->data[11] = 2; + task->data[12] = 5; + task->data[13] = 192; + task->data[15] = var1 + 32; + break; + case 2: + task->data[11] = 4; + task->data[12] = 4; + task->data[13] = 0; + task->data[15] = var1 + 32; + break; + } + + if (task->data[14] < 0) + task->data[14] = 0; + + if (GetBankIdentity_permutated(gAnimBankTarget) == 1) + { + task->data[10] = gBattle_BG1_X; + scanlineParams.dmaDest = ®_BG1HOFS; + } + else + { + task->data[10] = gBattle_BG2_X; + scanlineParams.dmaDest = ®_BG2HOFS; + } + + i = task->data[14]; + while (i <= task->data[14] + 64) + { + gScanlineEffectRegBuffers[0][i] = task->data[10]; + gScanlineEffectRegBuffers[1][i] = task->data[10]; + i++; + } + + scanlineParams.dmaControl = 0XA2600001; + scanlineParams.initState = 1; + scanlineParams.unused9 = 0; + ScanlineEffect_SetParams(scanlineParams); + + task->func = sub_80DC3F4; +} + +static void sub_80DC3F4(u8 taskId) +{ + s16 sineIndex, i; + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + sineIndex = task->data[13]; + i = task->data[14]; + while (i <= task->data[15]) + { + s16 var2 = (gSineTable[sineIndex] >> task->data[12]); + if (var2 > 0) + { + var2 += (task->data[1] & 3); + } + else if (var2 < 0) + { + var2 -= (task->data[1] & 3); + } + + gScanlineEffectRegBuffers[0][i] = task->data[10] + var2; + gScanlineEffectRegBuffers[1][i] = task->data[10] + var2; + + sineIndex += task->data[11]; + i++; + } + + if (++task->data[1] > 23) + { + task->data[0]++; + } + break; + case 1: + gScanlineEffect.state = 3; + task->data[0]++; + break; + case 2: + DestroyAnimVisualTask(taskId); + break; + } +} + +#ifdef NONMATCHING +void sub_80DC4F4(u8 taskId) +{ + s16 spriteId; + u8 matrixNum; + register u8 matrixNum2 asm("r6"); + struct Task *task = &gTasks[taskId]; + + matrixNum = AllocOamMatrix(); + matrixNum2 = matrixNum; + if (matrixNum2 == 0xFF) + { + DestroyAnimVisualTask(taskId); + return; + } + + spriteId = duplicate_obj_of_side_rel2move_in_transparent_mode(gBattleAnimArgs[0]); + if (spriteId < 0) + { + FreeOamMatrix(matrixNum); + DestroyAnimVisualTask(taskId); + return; + } + + gSprites[spriteId].callback = SpriteCallbackDummy; + gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_DOUBLE; + gSprites[spriteId].oam.matrixNum = matrixNum2; + gSprites[spriteId].affineAnimPaused = 1; + gSprites[spriteId].subpriority++; + obj_id_set_rotscale(spriteId, 256, 256, 0); + CalcCenterToCornerVec(&gSprites[spriteId], gSprites[spriteId].oam.shape, gSprites[spriteId].oam.size, gSprites[spriteId].oam.affineMode); + + task->data[13] = GetAnimBankSpriteId(gBattleAnimArgs[0]); + task->data[14] = matrixNum; + task->data[15] = spriteId; + task->func = sub_80DC5F4; +} +#else +__attribute__((naked)) +void sub_80DC4F4(u8 taskId) +{ + asm(".syntax unified\n\ + push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + lsls r0, 24\n\ + lsrs r4, r0, 24\n\ + mov r8, r4\n\ + lsls r0, r4, 2\n\ + adds r0, r4\n\ + lsls r0, 3\n\ + ldr r1, _080DC528 @ =gTasks\n\ + adds r7, r0, r1\n\ + bl AllocOamMatrix\n\ + lsls r0, 24\n\ + lsrs r5, r0, 24\n\ + mov r10, r5\n\ + adds r6, r5, 0\n\ + cmp r6, 0xFF\n\ + bne _080DC52C\n\ + adds r0, r4, 0\n\ + bl DestroyAnimVisualTask\n\ + b _080DC5D6\n\ + .align 2, 0\n\ +_080DC528: .4byte gTasks\n\ +_080DC52C:\n\ + ldr r1, _080DC550 @ =gBattleAnimArgs\n\ + ldrb r0, [r1]\n\ + bl duplicate_obj_of_side_rel2move_in_transparent_mode\n\ + lsls r0, 16\n\ + lsrs r1, r0, 16\n\ + mov r9, r1\n\ + asrs r0, 16\n\ + cmp r0, 0\n\ + bge _080DC554\n\ + adds r0, r5, 0\n\ + bl FreeOamMatrix\n\ + mov r0, r8\n\ + bl DestroyAnimVisualTask\n\ + b _080DC5D6\n\ + .align 2, 0\n\ +_080DC550: .4byte gBattleAnimArgs\n\ +_080DC554:\n\ + ldr r2, _080DC5E4 @ =gSprites\n\ + lsls r4, r0, 4\n\ + adds r4, r0\n\ + lsls r4, 2\n\ + adds r0, r2, 0\n\ + adds r0, 0x1C\n\ + adds r0, r4, r0\n\ + ldr r1, _080DC5E8 @ =SpriteCallbackDummy\n\ + str r1, [r0]\n\ + adds r4, r2\n\ + ldrb r0, [r4, 0x1]\n\ + movs r1, 0x3\n\ + orrs r0, r1\n\ + strb r0, [r4, 0x1]\n\ + movs r0, 0x1F\n\ + ands r6, r0\n\ + lsls r2, r6, 1\n\ + ldrb r1, [r4, 0x3]\n\ + movs r0, 0x3F\n\ + negs r0, r0\n\ + ands r0, r1\n\ + orrs r0, r2\n\ + strb r0, [r4, 0x3]\n\ + adds r2, r4, 0\n\ + adds r2, 0x2C\n\ + ldrb r0, [r2]\n\ + movs r1, 0x80\n\ + orrs r0, r1\n\ + strb r0, [r2]\n\ + adds r1, r4, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + adds r0, 0x1\n\ + strb r0, [r1]\n\ + mov r1, r9\n\ + lsls r0, r1, 24\n\ + lsrs r0, 24\n\ + movs r2, 0x80\n\ + lsls r2, 1\n\ + adds r1, r2, 0\n\ + movs r3, 0\n\ + bl obj_id_set_rotscale\n\ + ldrb r3, [r4, 0x1]\n\ + lsrs r1, r3, 6\n\ + ldrb r2, [r4, 0x3]\n\ + lsrs r2, 6\n\ + lsls r3, 30\n\ + lsrs r3, 30\n\ + adds r0, r4, 0\n\ + bl CalcCenterToCornerVec\n\ + ldr r1, _080DC5EC @ =gBattleAnimArgs\n\ + ldrb r0, [r1]\n\ + bl GetAnimBankSpriteId\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + strh r0, [r7, 0x22]\n\ + mov r0, r10\n\ + strh r0, [r7, 0x24]\n\ + mov r1, r9\n\ + strh r1, [r7, 0x26]\n\ + ldr r0, _080DC5F0 @ =sub_80DC5F4\n\ + str r0, [r7]\n\ +_080DC5D6:\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .align 2, 0\n\ +_080DC5E4: .4byte gSprites\n\ +_080DC5E8: .4byte SpriteCallbackDummy\n\ +_080DC5EC: .4byte gBattleAnimArgs\n\ +_080DC5F0: .4byte sub_80DC5F4\n\ + .syntax divided\n"); +} +#endif // NONMATCHING + +void sub_80DC5F4(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + task->data[1] += 4; + task->data[2] = 256 - (gSineTable[task->data[1]] >> 1); + obj_id_set_rotscale(task->data[15], task->data[2], task->data[2], 0); + sub_8079AB8(task->data[15], task->data[13]); + if (task->data[1] == 48) + task->data[0]++; + break; + case 1: + task->data[1] -= 4; + task->data[2] = 256 - (gSineTable[task->data[1]] >> 1);; + obj_id_set_rotscale(task->data[15], task->data[2], task->data[2], 0); + sub_8079AB8(task->data[15], task->data[13]); + if (task->data[1] == 0) + task->data[0]++; + break; + case 2: + obj_delete_but_dont_free_vram(&gSprites[task->data[15]]); + task->data[0]++; + break; + case 3: + FreeOamMatrix(task->data[14]); + DestroyAnimVisualTask(taskId); + break; + } +} + +void sub_80DC700(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + sprite->pos1.x = GetBankPosition(gAnimBankAttacker, 0); + sprite->pos1.y = GetBankPosition(gAnimBankAttacker, 1); + + if (IsContest()) + sprite->pos1.y += 12; + + sprite->data[1] = 8; + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = ((16 - sprite->data[1]) << 8) | sprite->data[1]; + sprite->data[0]++; + break; + case 1: + if (sprite->affineAnimEnded) + { + PlaySE12WithPanning(SE_W100, BattleAnimAdjustPanning(-64)); + ChangeSpriteAffineAnim(sprite, 1); + sprite->data[0]++; + } + break; + case 2: + if (sprite->data[2]++ > 1) + { + sprite->data[2] = 0; + sprite->data[1]--; + REG_BLDALPHA = ((16 - sprite->data[1]) << 8) | sprite->data[1]; + + if (sprite->data[1] == 0) + { + sprite->data[0]++; + sprite->invisible = 1; + } + } + + sprite->data[3] += 896; + sprite->pos2.y -= sprite->data[3] >> 8; + sprite->data[3] &= 0xFF; + break; + case 3: + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + DestroyAnimSprite(sprite); + break; + } +} diff --git a/src/battle/anim/rock.c b/src/battle/anim/rock.c new file mode 100644 index 000000000..b113ce040 --- /dev/null +++ b/src/battle/anim/rock.c @@ -0,0 +1,602 @@ +#include "global.h" +#include "battle.h" +#include "battle_anim.h" +#include "decompress.h" +#include "palette.h" +#include "rom_8077ABC.h" +#include "sound.h" +#include "task.h" +#include "trig.h" +#include "constants/songs.h" + +extern s16 gBattleAnimArgs[]; +extern u8 gAnimBankAttacker; +extern u8 gAnimBankTarget; +extern u32 gAnimMoveDmg; +extern u16 gBattle_BG1_X; +extern u16 gBattle_BG1_Y; +extern u16 gBattle_BG3_Y; + +extern const u8 gBattleAnimBackgroundTilemap_SandstormBrew[]; +extern const u8 gBattleAnimBackgroundImage_SandstormBrew[]; +extern const u16 gBattleAnimSpritePalette_261[]; +extern const struct SpriteTemplate gSpriteTemplate_83DAD78; +extern const struct SpriteTemplate gSpriteTemplate_83DAD90; + +extern const struct SubspriteTable gUnknown_083DAD10; + +static void sub_80DCF1C(struct Sprite *sprite); +static void sub_80DD02C(struct Sprite *sprite); +static void sub_80DD190(u8 taskId); +static void sub_80DD604(u8 taskId); +static void sub_80DD774(struct Task *task); +static u8 sub_80DD8BC(void); +static void sub_80DD928(struct Sprite *sprite); +static void sub_80DD9FC(struct Sprite *sprite); + + +void sub_80DCE9C(struct Sprite *sprite) +{ + if (gBattleAnimArgs[3] != 0) + sub_807A3FC(gAnimBankTarget, 0, &sprite->pos1.x, &sprite->pos1.y); + + sprite->pos1.x += gBattleAnimArgs[0]; + sprite->pos1.y += 14; + + StartSpriteAnim(sprite, gBattleAnimArgs[1]); + AnimateSprite(sprite); + + sprite->data[0] = 0; + sprite->data[1] = 0; + sprite->data[2] = 4; + sprite->data[3] = 16; + sprite->data[4] = -70; + sprite->data[5] = gBattleAnimArgs[2]; + + StoreSpriteCallbackInData(sprite, sub_80DCF1C); + sprite->callback = sub_8078278; + sprite->callback(sprite); +} + +static void sub_80DCF1C(struct Sprite *sprite) +{ + sprite->pos1.x += sprite->data[5]; + + sprite->data[0] = 192; + sprite->data[1] = sprite->data[5]; + sprite->data[2] = 4; + sprite->data[3] = 32; + sprite->data[4] = -24; + + StoreSpriteCallbackInData(sprite, move_anim_8074EE0); + sprite->callback = sub_8078278; + sprite->callback(sprite); +} + +void sub_80DCF60(struct Sprite *sprite) +{ + StartSpriteAnim(sprite, gBattleAnimArgs[5]); + AnimateSprite(sprite); + + if (GetBankSide(gAnimBankAttacker) != SIDE_PLAYER) + sprite->pos1.x -= gBattleAnimArgs[0]; + else + sprite->pos1.x += gBattleAnimArgs[0]; + + sprite->pos1.y += gBattleAnimArgs[1]; + + sprite->data[0] = gBattleAnimArgs[4]; + sprite->data[1] = sprite->pos1.x; + sprite->data[2] = sprite->pos1.x + gBattleAnimArgs[2]; + sprite->data[3] = sprite->pos1.y; + sprite->data[4] = sprite->pos1.y + gBattleAnimArgs[3]; + + sub_8078A5C(sprite); + sprite->data[3] = 0; + sprite->data[4] = 0; + + sprite->callback = sub_8078394; + StoreSpriteCallbackInData(sprite, move_anim_8074EE0); +} + +void sub_80DCFE4(struct Sprite *sprite) +{ + if (gBattleAnimArgs[6] == 0) + sub_80787B0(sprite, 0); + else + sub_8078764(sprite, 0); + + sprite->data[0] = gBattleAnimArgs[3]; + sprite->data[1] = gBattleAnimArgs[2]; + sprite->data[2] = gBattleAnimArgs[4]; + sprite->data[3] = gBattleAnimArgs[5]; + + sprite->callback = sub_80DD02C; +} + +static void sub_80DD02C(struct Sprite *sprite) +{ + sprite->data[4] += sprite->data[1]; + sprite->pos2.y = -(sprite->data[4] >> 8); + sprite->pos2.x = Sin(sprite->data[5], sprite->data[3]); + sprite->data[5] = (sprite->data[5] + sprite->data[2]) & 0xFF; + + if (--sprite->data[0] == -1) + { + DestroyAnimSprite(sprite); + } +} + +void do_boulder_dust(u8 taskId) +{ + struct Struct_sub_8078914 subStruct; + int var0 = 0; + + REG_BLDCNT = 0x3F42; + REG_BLDALPHA = 0x1000; + REG_BG1CNT_BITFIELD.priority = 1; + REG_BG1CNT_BITFIELD.screenSize = 0; + + if (!IsContest()) + REG_BG1CNT_BITFIELD.charBaseBlock = 1; + + gBattle_BG1_X = 0; + gBattle_BG1_Y = 0; + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + + sub_8078914(&subStruct); + DmaFill32Defvars(3, 0, subStruct.field_4, 0x1000); + LZDecompressVram(&gBattleAnimBackgroundTilemap_SandstormBrew, subStruct.field_4); + LZDecompressVram(&gBattleAnimBackgroundImage_SandstormBrew, subStruct.field_0); + LoadCompressedPalette(&gBattleAnimSpritePalette_261, subStruct.field_8 << 4, 32); + + if (IsContest()) + sub_80763FC(subStruct.field_8, (u16 *)subStruct.field_4, 0, 0); + + if (gBattleAnimArgs[0] != 0 && GetBankSide(gAnimBankAttacker) != SIDE_PLAYER) + var0 = 1; + + gTasks[taskId].data[0] = var0; + gTasks[taskId].func = sub_80DD190; +} + +static void sub_80DD190(u8 taskId) +{ + struct Struct_sub_8078914 subStruct; + + if (gTasks[taskId].data[0] == 0) + gBattle_BG1_X += 0xFFFA; + else + gBattle_BG1_X += 6; + + gBattle_BG1_Y += -1; + + switch (gTasks[taskId].data[12]) + { + case 0: + if (++gTasks[taskId].data[10] == 4) + { + gTasks[taskId].data[10] = 0; + gTasks[taskId].data[11]++; + REG_BLDALPHA = gTasks[taskId].data[11] | ((16 - gTasks[taskId].data[11]) << 8); + if (gTasks[taskId].data[11] == 7) + { + gTasks[taskId].data[12]++; + gTasks[taskId].data[11] = 0; + } + } + break; + case 1: + if (++gTasks[taskId].data[11] == 101) + { + gTasks[taskId].data[11] = 7; + gTasks[taskId].data[12]++; + } + break; + case 2: + if (++gTasks[taskId].data[10] == 4) + { + gTasks[taskId].data[10] = 0; + gTasks[taskId].data[11]--; + REG_BLDALPHA = gTasks[taskId].data[11] | ((16 - gTasks[taskId].data[11]) << 8); + if (gTasks[taskId].data[11] == 0) + { + gTasks[taskId].data[12]++; + gTasks[taskId].data[11] = 0; + } + } + break; + case 3: + sub_8078914(&subStruct); + DmaFill32Large(3, 0, subStruct.field_0, 0x2000, 0x1000); + DmaClear32(3, subStruct.field_4, 0x800); + if (!IsContest()) + REG_BG1CNT_BITFIELD.charBaseBlock = 0; + + gTasks[taskId].data[12]++; + // fall through + case 4: + gBattle_BG1_X = 0; + gBattle_BG1_Y = 0; + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + REG_BG1CNT_BITFIELD.priority = 1; + DestroyAnimVisualTask(taskId); + break; + } +} + +void sub_80DD3AC(struct Sprite *sprite) +{ + if (sprite->data[0] == 0) + { + if (gBattleAnimArgs[3] != 0 && GetBankSide(gAnimBankAttacker) != SIDE_PLAYER) + { + sprite->pos1.x = 304; + gBattleAnimArgs[1] = -gBattleAnimArgs[1]; + sprite->data[5] = 1; + sprite->oam.matrixNum = 8; + } + else + { + sprite->pos1.x = -64; + } + + sprite->pos1.y = gBattleAnimArgs[0]; + SetSubspriteTables(sprite, &gUnknown_083DAD10); + sprite->data[1] = gBattleAnimArgs[1]; + sprite->data[2] = gBattleAnimArgs[2]; + sprite->data[0]++; + } + else + { + sprite->data[3] += sprite->data[1]; + sprite->data[4] += sprite->data[2]; + sprite->pos2.x += (sprite->data[3] >> 8); + sprite->pos2.y += (sprite->data[4] >> 8); + sprite->data[3] &= 0xFF; + sprite->data[4] &= 0xFF; + + if (sprite->data[5] == 0) + { + if (sprite->pos1.x + sprite->pos2.x > 272) + { + sprite->callback = DestroyAnimSprite; + } + } + else if (sprite->pos1.x + sprite->pos2.x < -32) + { + sprite->callback = DestroyAnimSprite; + } + } +} + +void sub_80DD490(struct Sprite *sprite) +{ + StartSpriteAnim(sprite, gBattleAnimArgs[4]); + sub_80787B0(sprite, 0); + + sprite->data[0] = gBattleAnimArgs[3]; + sprite->data[2] = sprite->pos1.x; + sprite->data[4] = sprite->pos1.y + gBattleAnimArgs[2]; + + sprite->callback = sub_8078B34; + StoreSpriteCallbackInData(sprite, DestroyAnimSprite); +} + +void sub_80DD4D4(u8 taskId) +{ + u16 var0, var1, var2, var3; + u8 var4; + int var5; + s16 pan1, pan2; + struct Task *task; + + task = &gTasks[taskId]; + + var0 = GetBankPosition(gAnimBankAttacker, 2); + var1 = GetBankPosition(gAnimBankAttacker, 1) + 24; + var2 = GetBankPosition(gAnimBankTarget, 2); + var3 = GetBankPosition(gAnimBankTarget, 1) + 24; + + if ((gAnimBankAttacker ^ 2) == gAnimBankTarget) + var3 = var1; + + var4 = sub_80DD8BC(); + if (var4 == 1) + task->data[8] = 32; + else + task->data[8] = 48 - (var4 * 8); + + task->data[0] = 0; + task->data[11] = 0; + task->data[9] = 0; + task->data[12] = 1; + + var5 = task->data[8]; + if (var5 < 0) + var5 += 7; + + task->data[10] = (var5 >> 3) - 1; + + task->data[2] = var0 * 8; + task->data[3] = var1 * 8; + task->data[4] = ((var2 - var0) * 8) / task->data[8]; + task->data[5] = ((var3 - var1) * 8) / task->data[8]; + task->data[6] = 0; + task->data[7] = 0; + + pan1 = BattleAnimAdjustPanning(-64); + pan2 = BattleAnimAdjustPanning(63); + + task->data[13] = pan1; + task->data[14] = (pan2 - pan1) / task->data[8]; + task->data[1] = var4; + task->data[15] = GetAnimBankSpriteId(0); + + task->func = sub_80DD604; +} + +static void sub_80DD604(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + task->data[6] -= task->data[4]; + task->data[7] -= task->data[5]; + gSprites[task->data[15]].pos2.x = task->data[6] >> 3; + gSprites[task->data[15]].pos2.y = task->data[7] >> 3; + + if (++task->data[9] == 10) + { + task->data[11] = 20; + task->data[0]++; + } + + PlaySE12WithPanning(SE_W029, task->data[13]); + break; + case 1: + if (--task->data[11] == 0) + task->data[0]++; + break; + case 2: + if (--task->data[9] != 0) + { + task->data[6] += task->data[4]; + task->data[7] += task->data[5]; + } + else + { + task->data[6] = 0; + task->data[7] = 0; + task->data[0]++; + } + + gSprites[task->data[15]].pos2.x = task->data[6] >> 3; + gSprites[task->data[15]].pos2.y = task->data[7] >> 3; + break; + case 3: + task->data[2] += task->data[4]; + task->data[3] += task->data[5]; + if (++task->data[9] >= task->data[10]) + { + task->data[9] = 0; + sub_80DD774(task); + task->data[13] += task->data[14]; + PlaySE12WithPanning(SE_W091, task->data[13]); + } + + if (--task->data[8] == 0) + { + task->data[0]++; + } + break; + case 4: + if (task->data[11] == 0) + DestroyAnimVisualTask(taskId); + break; + } +} + +static void sub_80DD774(struct Task *task) +{ + const struct SpriteTemplate *spriteTemplate; + int var0; + u16 x, y; + u8 spriteId; + + switch (task->data[1]) + { + case 1: + spriteTemplate = &gSpriteTemplate_83DAD78; + var0 = 0; + break; + case 2: + case 3: + spriteTemplate = &gSpriteTemplate_83DAD90; + var0 = 80; + break; + case 4: + spriteTemplate = &gSpriteTemplate_83DAD90; + var0 = 64; + break; + case 5: + spriteTemplate = &gSpriteTemplate_83DAD90; + var0 = 48; + break; + default: + return; + } + + x = task->data[2] >> 3; + y = task->data[3] >> 3; + x += (task->data[12] * 4); + + spriteId = CreateSprite(spriteTemplate, x, y, 35); + if (spriteId != 64) + { + gSprites[spriteId].data[0] = 18; + gSprites[spriteId].data[2] = ((task->data[12] * 20) + x) + (task->data[1] * 3); + gSprites[spriteId].data[4] = y; + gSprites[spriteId].data[5] = -16 - (task->data[1] * 2); + gSprites[spriteId].oam.tileNum += var0; + + sub_80786EC(&gSprites[spriteId]); + task->data[11]++; + } + + task->data[12] *= -1; +} + +void sub_80DD87C(struct Sprite *sprite) +{ + if (sub_8078718(sprite)) + { + u8 taskId = FindTaskIdByFunc(sub_80DD604); + if (taskId != 0xFF) + gTasks[taskId].data[11]--; + + DestroySprite(sprite); + } +} + +u8 sub_80DD8BC(void) +{ + u8 retVal = gAnimDisableStructPtr->rolloutTimer2 - gAnimDisableStructPtr->rolloutTimer1; + u8 var0 = retVal - 1; + if (var0 > 4) + { + retVal = 1; + } + + return retVal; +} + +void sub_80DD8E8(struct Sprite *sprite) +{ + StartSpriteAnim(sprite, gBattleAnimArgs[4]); + + sprite->pos2.x = gBattleAnimArgs[0]; + sprite->data[2] = gBattleAnimArgs[1]; + sprite->data[3] -= gBattleAnimArgs[2]; + sprite->data[0] = 3; + sprite->data[1] = gBattleAnimArgs[3]; + sprite->callback = sub_80DD928; + sprite->invisible = 1; +} + +static void sub_80DD928(struct Sprite *sprite) +{ + sprite->invisible = 0; + if (sprite->data[3] != 0) + { + sprite->pos2.y = sprite->data[2] + sprite->data[3]; + sprite->data[3] += sprite->data[0]; + sprite->data[0]++; + if (sprite->data[3] > 0) + { + sprite->data[3] = 0; + } + } + else + { + if (--sprite->data[1] == 0) + { + DestroyAnimSprite(sprite); + } + } +} + +void sub_80DD978(struct Sprite *sprite) +{ + if (GetBankSide(gAnimBankAttacker) == SIDE_OPPONENT) + StartSpriteAffineAnim(sprite, 1); + + sub_807941C(sprite); +} + +void sub_80DD9A4(struct Sprite *sprite) +{ + sprite->pos1.x = GetBankPosition(gAnimBankTarget, 0); + sprite->pos1.y = GetBankPosition(gAnimBankTarget, 1); + sprite->pos1.x += gBattleAnimArgs[0]; + sprite->pos1.y += gBattleAnimArgs[1]; + + sprite->data[1] = gBattleAnimArgs[0]; + sprite->data[2] = gBattleAnimArgs[1]; + sprite->data[5] = gBattleAnimArgs[2]; + + StartSpriteAnim(sprite, gBattleAnimArgs[3]); + sprite->callback = sub_80DD9FC; +} + +static void sub_80DD9FC(struct Sprite *sprite) +{ + sprite->data[0] += 8; + sprite->data[3] += sprite->data[1]; + sprite->data[4] += sprite->data[2]; + + sprite->pos2.x += sprite->data[3] / 40; + sprite->pos2.y -= Sin(sprite->data[0], sprite->data[5]); + + if (sprite->data[0] > 140) + DestroyAnimSprite(sprite); +} + +void sub_80DDA4C(u8 taskId) +{ + if ((s32)gAnimMoveDmg < 33) + gBattleAnimArgs[7] = 0; + if (gAnimMoveDmg - 33 < 33) + gBattleAnimArgs[7] = 1; + if ((s32)gAnimMoveDmg > 65) + gBattleAnimArgs[7] = 2; + + DestroyAnimVisualTask(taskId); +} + +void sub_80DDA8C(u8 taskId) +{ + if (gTasks[taskId].data[0] == 0) + { + sub_80789D4(0); + gTasks[taskId].data[1] = 200; + } + + gBattle_BG3_Y += gTasks[taskId].data[1] / 10; + gTasks[taskId].data[1] -= 3; + + if (gTasks[taskId].data[0] == 120) + { + sub_80789D4(1); + DestroyAnimVisualTask(taskId); + } + + gTasks[taskId].data[0]++; +} + +void sub_80DDAF0(u8 taskId) +{ + if (gTasks[taskId].data[0] == 0) + { + sub_80789D4(0); + gTasks[taskId].data[0]++; + gTasks[taskId].data[2] = gBattle_BG3_Y; + } + + gTasks[taskId].data[1] += 80; + gTasks[taskId].data[1] &= 0xFF; + gBattle_BG3_Y = gTasks[taskId].data[2] + Cos(4, gTasks[taskId].data[1]); + + if (gBattleAnimArgs[7] == 0xFFF) + { + gBattle_BG3_Y = 0; + sub_80789D4(1); + DestroyAnimVisualTask(taskId); + } +} diff --git a/src/engine/naming_screen.c b/src/engine/naming_screen.c index 97819322c..ca77c5483 100644 --- a/src/engine/naming_screen.c +++ b/src/engine/naming_screen.c @@ -26,8 +26,6 @@ #define COLUMN_COUNT 10 #endif -extern u16 gKeyRepeatStartDelay; - extern u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality); const u8 gSpriteImage_83CE094[] = INCBIN_U8("graphics/naming_screen/pc_icon/0.4bpp"); diff --git a/src/field/choose_party.c b/src/field/choose_party.c index 18d26f007..73470d3d2 100644 --- a/src/field/choose_party.c +++ b/src/field/choose_party.c @@ -1,5 +1,5 @@ #include "global.h" -#include "decoration.h" +#include "event_data.h" #include "field_fadetransition.h" #include "main.h" #include "menu.h" @@ -7,6 +7,7 @@ #include "palette.h" #include "party_menu.h" #include "pokemon_menu.h" +#include "field_weather.h" #include "pokemon.h" #include "pokemon_summary_screen.h" #include "overworld.h" diff --git a/src/field/daycare.c b/src/field/daycare.c index b80a0f69d..da0838d29 100644 --- a/src/field/daycare.c +++ b/src/field/daycare.c @@ -205,7 +205,7 @@ static u16 TakeSelectedPokemonFromDaycare(struct DayCare * daycare, u8 slot) GetBoxMonNick(&daycare->mons[slot], gStringVar1); species = GetBoxMonData(&daycare->mons[slot], MON_DATA_SPECIES); - sub_803B4B4(&daycare->mons[slot], &pokemon); + ExpandBoxMon(&daycare->mons[slot], &pokemon); if (GetMonData(&pokemon, MON_DATA_LEVEL) != MAX_LEVEL) { diff --git a/src/field/field_effect.c b/src/field/field_effect.c index ad570cf7f..e1389c378 100644 --- a/src/field/field_effect.c +++ b/src/field/field_effect.c @@ -25,6 +25,7 @@ #include "field_map_obj.h" #include "util.h" #include "field_effect_helpers.h" +#include "pokemon_storage_system.h" #define subsprite_table(ptr) {.subsprites = ptr, .subspriteCount = (sizeof ptr) / (sizeof(struct Subsprite))} diff --git a/src/field/pc_screen_effect.c b/src/field/pc_screen_effect.c index e0853e01d..dcc3bc9c9 100644 --- a/src/field/pc_screen_effect.c +++ b/src/field/pc_screen_effect.c @@ -2,18 +2,7 @@ #include "main.h" #include "palette.h" #include "sprite.h" - -struct UnkStruct -{ - /*0x00*/ u16 tileTag; - /*0x02*/ u16 paletteTag; - /*0x04*/ u16 unk04; - /*0x06*/ u16 unk06; - /*0x08*/ u16 unk08; - /*0x0A*/ u16 unk0A; - /*0x0C*/ s16 unk0C; - /*0x10*/ u32 selectedPalettes; -}; +#include "pc_screen_effect.h" void sub_80C603C(void); void sub_80C6078(void); @@ -30,7 +19,7 @@ extern const u16 gUnknownPal_083D18EC[16]; extern const u8 gUnknownGfx_083D190C[128]; -EWRAM_DATA struct UnkStruct *gUnknown_020387EC = NULL; +EWRAM_DATA struct PCScreenEffectStruct *gUnknown_020387EC = NULL; const struct SpriteSheet gUnknown_083D1898 = { gUnknownGfx_083D190C, sizeof(gUnknownGfx_083D190C), 0 }; @@ -58,7 +47,7 @@ const struct SpriteTemplate gSpriteTemplate_83D18C0 = sub_80C6130, }; -void sub_80C5CD4(struct UnkStruct *unkStruct) +void sub_80C5CD4(struct PCScreenEffectStruct *unkStruct) { u16 i; diff --git a/src/field/pokedex_area_screen.c b/src/field/pokedex_area_screen.c new file mode 100644 index 000000000..67ca276c4 --- /dev/null +++ b/src/field/pokedex_area_screen.c @@ -0,0 +1,20 @@ + +// Includes +#include "global.h" + +// Static type declarations + +// Static RAM declarations + +EWRAM_DATA u16 gUnknown_02039260 = 0; +EWRAM_DATA u16 gUnknown_02039262 = 0; +EWRAM_DATA u16 gUnknown_02039264 = 0; +EWRAM_DATA u16 gUnknown_02039266 = 0; +EWRAM_DATA u16 gUnknown_02039268 = 0; +EWRAM_DATA u16 gUnknown_0203926A = 0; + +// Static ROM declarations + +// .rodata + +// .text diff --git a/src/field/pokenav.c b/src/field/pokenav.c new file mode 100644 index 000000000..f57a98df6 --- /dev/null +++ b/src/field/pokenav.c @@ -0,0 +1,16 @@ + +// Includes +#include "global.h" + +// Static type declarations + +// Static RAM declarations + +EWRAM_DATA u8 gUnknown_020388B0[4] = {}; +EWRAM_DATA u16 gUnknown_020388B4 = 0; + +// Static ROM declarations + +// .rodata + +// .text diff --git a/src/field/use_pokeblock.c b/src/field/use_pokeblock.c index 42020c49a..8ea93aab8 100644 --- a/src/field/use_pokeblock.c +++ b/src/field/use_pokeblock.c @@ -104,7 +104,6 @@ static EWRAM_DATA struct Pokeblock *gUnknown_0203930C = NULL; EWRAM_DATA u8 gPokeblockMonID = 0; EWRAM_DATA s16 gPokeblockGain = 0; -extern u16 gKeyRepeatStartDelay; extern u16 gSpecialVar_ItemId; // FIXME: remove after merge of #349 Pokeblock static void launch_c3_walk_stairs_and_run_once(void (*const)(void)); diff --git a/src/libs/m4a_1.s b/src/libs/m4a_1.s index be8b44488..8dbcf7efd 100644 --- a/src/libs/m4a_1.s +++ b/src/libs/m4a_1.s @@ -4,7 +4,11 @@ .syntax unified - .lcomm gUnknown_030007B8, 0x770 + .bss + + .global gUnknown_030007B8 +gUnknown_030007B8: + .space 0x770 .text diff --git a/src/pokemon/mon_markings.c b/src/pokemon/mon_markings.c index 66c82a706..dcdc54434 100644 --- a/src/pokemon/mon_markings.c +++ b/src/pokemon/mon_markings.c @@ -5,6 +5,7 @@ #include "constants/songs.h" #include "sound.h" #include "sprite.h" +#include "mon_markings.h" #ifdef GERMAN #define MENU_TEXT_SPRITE_X_OFFSET 24 @@ -12,25 +13,6 @@ #define MENU_TEXT_SPRITE_X_OFFSET 32 #endif -struct PokemonMarkMenu -{ - /*0x0000*/ u16 baseTileTag; - /*0x0002*/ u16 basePaletteTag; - /*0x0004*/ u8 markings; // bit flags - /*0x0005*/ s8 cursorPos; - /*0x0006*/ bool8 markingsArray[4]; - /*0x000A*/ u8 cursorBaseY; - /*0x000B*/ bool8 spriteSheetLoadRequired; - /*0x000C*/ struct Sprite *menuWindowSprites[2]; // upper and lower halves of menu window - /*0x0014*/ struct Sprite *menuMarkingSprites[4]; - /*0x0024*/ struct Sprite *menuTextSprite; - /*0x0028*/ const u8 *frameTiles; - /*0x002C*/ const u16 *framePalette; - /*0x0030*/ u8 menuWindowSpriteTiles[0x1000]; - /*0x1030*/ u8 filler1030[0x80]; - /*0x10B0*/ u8 tileLoadState; -}; - extern u8 gPokenavConditionMenuMisc_Gfx[]; extern u16 gUnknown_08E966B8[]; diff --git a/src/pokemon/pokemon_1.c b/src/pokemon/pokemon_1.c index 0242e7444..06a088046 100644 --- a/src/pokemon/pokemon_1.c +++ b/src/pokemon/pokemon_1.c @@ -524,7 +524,7 @@ void CalculateMonStats(struct Pokemon *mon) SetMonData(mon, MON_DATA_HP, ¤tHP); } -void sub_803B4B4(const struct BoxPokemon *src, struct Pokemon *dest) +void ExpandBoxMon(const struct BoxPokemon *src, struct Pokemon *dest) { u32 value = 0; dest->box = *src; diff --git a/src/pokemon/pokemon_2.c b/src/pokemon/pokemon_2.c index b941ed2ab..7fd1aa7b2 100644 --- a/src/pokemon/pokemon_2.c +++ b/src/pokemon/pokemon_2.c @@ -1,5 +1,6 @@ #include "global.h" #include "constants/hold_effects.h" +#include "constants/moves.h" #include "battle.h" #include "battle_util.h" #include "data2.h" @@ -569,7 +570,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) u16 *moves = (u16 *)data; s32 i = 0; - while (moves[i] != 355) + while (moves[i] != NUM_MOVES) { u16 move = moves[i]; if (substruct1->moves[0] == move diff --git a/src/pokemon/pokemon_storage_system.c b/src/pokemon/pokemon_storage_system.c index 001cebe45..24c45247e 100644 --- a/src/pokemon/pokemon_storage_system.c +++ b/src/pokemon/pokemon_storage_system.c @@ -1,93 +1,606 @@ #include "global.h" -#include "pokemon_storage_system.h" +#include "palette.h" +#include "constants/songs.h" +#include "sound.h" +#include "field_weather.h" +#include "overworld.h" +#include "field_fadetransition.h" #include "menu.h" +#include "main.h" +#include "strings.h" #include "string_util.h" -#include "ewram.h" +#include "event_data.h" +#include "script.h" +#include "pokemon_storage_system.h" + +void StorageSystemCreatePrimaryMenu(u8 whichMenu); +void sub_80963D0(u8 curBox); +void sub_809658C(void); +void sub_80965F8(void); +void sub_809662C(void); +void sub_809665C(void); +void sub_80966F4(const u8 *sourceString, u16 x, u16 y); +void sub_8096784(struct Sprite *sprite); + +EWRAM_DATA struct PokemonStorage gPokemonStorage = {0}; +EWRAM_DATA u8 gUnknown_02038470[3] = {}; +EWRAM_DATA u8 gUnknown_02038473 = 0; +EWRAM_DATA u8 gUnknown_02038474 = 0; +EWRAM_DATA struct UnkPSSStruct_2002370 *gUnknown_02038478 = NULL; -struct StorageAction { - u8 *text; - u8 format; +const struct PSS_MenuStringPtrs gUnknown_083B600C[] = { + {PCText_WithdrawPoke, PCText_MovePokeToParty}, + {PCText_DepositPoke, PCText_StorePokeInBox}, + {PCText_MovePoke, PCText_OrganizeBoxesParty}, + {PCText_SeeYa, PCText_ReturnToPrevMenu} }; -extern const struct StorageAction gUnknown_083B6DF4[]; +const union AnimCmd gSpriteAnim_83B602C[] = { + ANIMCMD_FRAME( 0, 5), + ANIMCMD_END +}; -EWRAM_DATA struct PokemonStorage gPokemonStorage = {0}; +const union AnimCmd gSpriteAnim_83B6034[] = { + ANIMCMD_FRAME( 4, 5), + ANIMCMD_END +}; + +const union AnimCmd gSpriteAnim_83B603C[] = { + ANIMCMD_FRAME( 6, 5), + ANIMCMD_END +}; + +const union AnimCmd gSpriteAnim_83B6044[] = { + ANIMCMD_FRAME(10, 5), + ANIMCMD_END +}; + +const union AnimCmd *const gSpriteAnimTable_83B604C[] = { + gSpriteAnim_83B602C, + gSpriteAnim_83B6034, + gSpriteAnim_83B603C, + gSpriteAnim_83B6044 +}; + +const union AffineAnimCmd gSpriteAffineAnim_83B605C[] = { + AFFINEANIMCMD_FRAME(0xe0, 0xe0, 0, 0), + AFFINEANIMCMD_END +}; + +const union AffineAnimCmd *const gSpriteAffineAnimTable_83B606C[] = { + gSpriteAffineAnim_83B605C +}; + +const u16 gBoxSelectionPopupPalette[] = INCBIN_U16("graphics/pokemon_storage/box_selection_popup.gbapal"); + +const u8 gBoxSelectionPopupCenterTiles[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_center.4bpp"); + +const u8 gBoxSelectionPopupSidesTiles[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); + +u8 CountPokemonInBoxN(u8 boxId) +{ + u16 i; + u16 count; + + for (i = 0, count = 0; i < 30; i++) + { + if (GetBoxMonData(gPokemonStorage.boxes[boxId] + i, MON_DATA_SPECIES) != 0) + count++; + } + return count; +} + +s16 GetIndexOfFirstEmptySpaceInBoxN(u8 boxId) +{ + u16 i; + + for (i = 0; i < 30; i++) + { + if (GetBoxMonData(gPokemonStorage.boxes[boxId] + i, MON_DATA_SPECIES) == 0) + return i; + } + return -1; +} -void sub_8098898(u8 index) { - u8 *ptr; +u8 GetNumValidDaycarePartyMons(void) +{ + u16 i; + u16 count; - Menu_DrawStdWindowFrame(10, 16, 29, 19); + for (i = 0, count = 0; i < PARTY_SIZE; i++) + { + struct Pokemon *pokemon = gPlayerParty + i; + if (GetMonData(pokemon, MON_DATA_SPECIES) != 0 && !GetMonData(pokemon, MON_DATA_IS_EGG)) + count++; + } + return count; +} + +u8 CountAlivePartyMonsExceptOne(u8 toSkip) +{ + u16 i; + u16 count; - switch (gUnknown_083B6DF4[index].format) + for (i = 0, count = 0; i < PARTY_SIZE; i++) { + if (i != toSkip) + { + struct Pokemon *pokemon = gPlayerParty + i; + if (GetMonData(pokemon, MON_DATA_SPECIES) != 0 && !GetMonData(pokemon, MON_DATA_IS_EGG) && GetMonData(pokemon, MON_DATA_HP) != 0) + count++; + } + } + return count; +} + +u8 CountAlivePartyMonsExceptSelectedOne(void) +{ + return CountAlivePartyMonsExceptOne(gSpecialVar_0x8004); +} - case 2: - ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); - ptr = StringCopy(ptr, gUnk20011fa); - break; +u8 StorageSystemGetPartySize(void) +{ + u16 i; + u16 count; - case 5: - ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); - ptr = StringCopy(ptr, gUnk20026e4); - break; + for (i = 0, count = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(gPlayerParty + i, MON_DATA_SPECIES) != 0) + count++; + } + return count; +} - case 1: - // {var} + " is selected." - ptr = StringCopy(gUnk2002694, gUnk20011fa); - ptr = StringCopy(ptr, gUnknown_083B6DF4[index].text); - break; +u8 *unref_sub_8095C60(u8 *dest, const u8 *src, u16 pad) +{ + u8 *_dest = StringCopy(dest, src); + while (_dest < dest + pad) + { + *_dest++ = CHAR_SPACE; + } + *_dest = EOS; + return _dest; +} - case 4: - // {var} + " was released." - ptr = StringCopy(gUnk2002694, gUnk20026e4); -#if ENGLISH - ptr = StringCopy(ptr, gUnknown_083B6DF4[index].text); -#elif GERMAN - ptr = de_sub_8073174(gUnk2002694, gUnknown_083B6DF4[index].text); -#endif - break; +void sub_8095C8C(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; - case 3: + dest_width *= 2; + dest += dest_top * 0x20 + dest_left; + src += src_top * src_width + src_left; + for (i = 0; i < dest_height; i++) { - u8 *stringLength; - u8 *text; + CpuCopy16(src, dest, dest_width); + dest += 0x20; + src += src_width; + } +} + +#define MAX_DMA_BLOCK_SIZE 0x1000 +#define Dma3FillLarge_(value, dest, size, bit) \ +{ \ + void *_dest = dest; \ + u32 _size = size; \ + while (1) \ + { \ + if (_size <= MAX_DMA_BLOCK_SIZE) \ + { \ + DmaFill##bit(3, value, _dest, _size); \ + break; \ + } \ + DmaFill##bit(3, value, _dest, MAX_DMA_BLOCK_SIZE); \ + _dest += MAX_DMA_BLOCK_SIZE; \ + _size -= MAX_DMA_BLOCK_SIZE; \ + } \ +} + +#define Dma3FillLarge16_(value, dest, size) Dma3FillLarge_(value, dest, size, 16) +#define Dma3FillLarge32_(value, dest, size) Dma3FillLarge_(value, dest, size, 32) + +void unref_sub_8095D08(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); +} + +s16 StorageSystemGetNextMonIndex(struct BoxPokemon *box, s8 startIdx, u8 stopIdx, u8 mode) +{ + s16 i; + s16 direction; + if (mode == 0 || mode == 2) + { + direction = 1; + } + else + { + direction = -1; + } + if (mode == 2 || mode == 3) + { + for (i = startIdx + direction; i >= 0 && i <= stopIdx; i += direction) + { + if (GetBoxMonData(box + i, MON_DATA_SPECIES) != 0) + return i; + } + } + else + { + for (i = startIdx + direction; i >= 0 && i <= stopIdx; i += direction) + { + if (GetBoxMonData(box + i, MON_DATA_SPECIES) != 0 && !GetBoxMonData(box + i, MON_DATA_IS_EGG)) + return i; + } + } + return -1; +} + +void StorageSystemClearMessageWindow(void) +{ + Menu_BlankWindowRect(2, 15, 27, 18); +} - text = gUnknown_083B6DF4[index].text; - stringLength = &text[StringLength(text)] + 1; +void Task_PokemonStorageSystem(u8 taskId) +{ + struct Task *task = gTasks + taskId; + switch (task->data[0]) + { + case 0: + StorageSystemCreatePrimaryMenu(task->data[1]); + Menu_DisplayDialogueFrame(); + Menu_PrintText(gUnknown_083B600C[task->data[1]].desc, 2, 15); + task->data[0]++; + break; + case 1: + if (IsWeatherNotFadingIn()) + { + task->data[0]++; + } + break; + case 2: + task->data[2] = Menu_ProcessInput(); + switch(task->data[2]) + { + case -2: + task->data[3] = task->data[1]; + if (gMain.newKeys & DPAD_UP && --task->data[3] < 0) + task->data[3] = 3; - ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); - ptr = StringCopy(ptr, gUnk20011fa); - ptr = StringCopy(ptr, stringLength); + if (gMain.newKeys & DPAD_DOWN && ++task->data[3] > 3) + task->data[3] = 0; + if (task->data[1] != task->data[3]) + { + task->data[1] = task->data[3]; + StorageSystemClearMessageWindow(); + Menu_PrintText(gUnknown_083B600C[task->data[1]].desc, 2, 15); + } + break; + case -1: + case 3: + Menu_DestroyCursor(); + Menu_EraseWindowRect(0, 0, 13, 9); + ScriptContext2_Disable(); + EnableBothScriptContexts(); + DestroyTask(taskId); + break; + default: + if (task->data[2] == 0 && StorageSystemGetPartySize() == PARTY_SIZE) + { + StorageSystemClearMessageWindow(); + Menu_PrintText(gPCText_PartyFull2, 2, 15); + task->data[0] = 3; + } + else if (task->data[2] == 1 && StorageSystemGetPartySize() == 1) + { + StorageSystemClearMessageWindow(); + Menu_PrintText(gPCText_OnlyOne, 2, 15); + task->data[0] = 3; + } + else + { + FadeScreen(1, 0); + task->data[0] = 4; + } + break; + } + break; + case 3: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + StorageSystemClearMessageWindow(); + Menu_PrintText(gUnknown_083B600C[task->data[1]].desc, 2, 15); + task->data[0] = 2; + } + else if (gMain.newKeys & DPAD_UP) + { + if (--task->data[1] < 0) + task->data[1] = 3; + Menu_MoveCursor(-1); + task->data[1] = Menu_GetCursorPos(); + StorageSystemClearMessageWindow(); + Menu_PrintText(gUnknown_083B600C[task->data[1]].desc, 2, 15); + 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(); + StorageSystemClearMessageWindow(); + Menu_PrintText(gUnknown_083B600C[task->data[1]].desc, 2, 15); + task->data[0] = 2; + } + break; + case 4: + if (!gPaletteFade.active) + { + task_intro_29(task->data[2]); + DestroyTask(taskId); + } + break; } - break; +} + +void ShowPokemonStorageSystem(void) +{ + u8 taskId = CreateTask(Task_PokemonStorageSystem, 80); + gTasks[taskId].data[0] = 0; + gTasks[taskId].data[1] = 0; + ScriptContext2_Enable(); +} + +void FieldCB_ReturnToOverworld(void) +{ + u8 taskId = CreateTask(Task_PokemonStorageSystem, 80); + gTasks[taskId].data[0] = 0; + gTasks[taskId].data[1] = gUnknown_02038474; + pal_fill_black(); +} + +void StorageSystemCreatePrimaryMenu(u8 whichMenu) +{ + Menu_DrawStdWindowFrame(0, 0, 13, 9); + Menu_PrintItems(1, 1, 4, (const struct MenuAction *)gUnknown_083B600C); + InitMenu(0, 1, 1, 4, whichMenu, 12); +} + +void sub_80961A8(void) +{ + gUnknown_02038474 = gPokemonStorageSystemPtr->unk_0005; + gFieldCallback = FieldCB_ReturnToOverworld; + SetMainCallback2(c2_exit_to_overworld_2_switch); +} + +void ResetPokemonStorageSystem(void) +{ + u16 boxId; + u16 boxMon; - case 6: - // "Bye-bye, ".substr(0, -1) + {var} + "Bye-bye, !".substr(-1, 1) + gPokemonStorage.currentBox = 0; + for (boxId = 0; boxId < 14; boxId++) + { + for (boxMon = 0; boxMon < 30; boxMon++) + { + ZeroBoxMonData(gPokemonStorage.boxes[boxId] + boxMon); + } + } + for (boxId = 0; boxId < 14; boxId++) { - u8 *stringLength; - u8 *text; + u8 *dest = StringCopy(gPokemonStorage.boxNames[boxId], gPCText_BOX); + ConvertIntToDecimalStringN(dest, boxId + 1, STR_CONV_MODE_LEFT_ALIGN, 2); + } + for (boxId = 0; boxId < 14; boxId++) + { + gPokemonStorage.wallpaper[boxId] = boxId & 0x03; + } +} - text = gUnknown_083B6DF4[index].text; - stringLength = &text[StringLength(text)] - 1; +void sub_8096264(struct UnkPSSStruct_2002370 *a0, u16 tileTag, u16 palTag, u8 a3) +{ + struct SpritePalette palette = { + gBoxSelectionPopupPalette, palTag + }; + struct SpriteSheet sheets[] = { + {gBoxSelectionPopupCenterTiles, 0x800, tileTag}, + {gBoxSelectionPopupSidesTiles, 0x180, tileTag + 1}, + {} + }; + LoadSpritePalette(&palette); + LoadSpriteSheets(sheets); + gUnknown_02038478 = a0; + a0->unk_0240 = tileTag; + a0->unk_0242 = palTag; + a0->unk_023e = a3; +} + +void sub_8096310(void) +{ + FreeSpritePaletteByTag(gUnknown_02038478->unk_0242); + FreeSpriteTilesByTag(gUnknown_02038478->unk_0240); + FreeSpriteTilesByTag(gUnknown_02038478->unk_0240 + 1); +} - ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); - ptr = StringCopy(ptr - 1, gUnk20026e4); - ptr = StringCopy(ptr, stringLength); +void sub_809634C(u8 curBox) +{ + sub_80963D0(curBox); +} + +void sub_809635C(void) +{ + sub_809658C(); +} + +u8 sub_8096368(void) +{ + if (gMain.newKeys & B_BUTTON) + { + PlaySE(SE_SELECT); + return 201; + } + if (gMain.newKeys & A_BUTTON) + { + PlaySE(SE_SELECT); + return gUnknown_02038478->curBox; + } + if (gMain.newKeys & DPAD_LEFT) + { + PlaySE(SE_SELECT); + sub_809662C(); + } + else if (gMain.newKeys & DPAD_RIGHT) + { + PlaySE(SE_SELECT); + sub_80965F8(); } - break; + return 200; +} - case 0: - default: - ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); - break; +void sub_80963D0(u8 curBox) +{ + u16 i; + u8 spriteId; + struct SpriteTemplate template; + struct OamData oamData = {}; + oamData.size = 3; + oamData.paletteNum = 1; + template = (struct SpriteTemplate){ + 0, 0, &oamData, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy + }; + + gUnknown_02038478->curBox = curBox; + template.tileTag = gUnknown_02038478->unk_0240; + template.paletteTag = gUnknown_02038478->unk_0242; + + spriteId = CreateSprite(&template, 0xA0, 0x60, 0); + gUnknown_02038478->unk_0000 = gSprites + spriteId; + + oamData.shape = ST_OAM_V_RECTANGLE; + oamData.size = 1; + template.tileTag = gUnknown_02038478->unk_0240 + 1; + template.anims = gSpriteAnimTable_83B604C; + for (i = 0; i < 4; i++) + { + u16 r5; + spriteId = CreateSprite(&template, 0x7c, 0x50, gUnknown_02038478->unk_023e); + gUnknown_02038478->unk_0004[i] = gSprites + spriteId; + r5 = 0; + if (i & 2) + { + gUnknown_02038478->unk_0004[i]->pos1.x = 0xc4; + r5 = 2; + } + if (i & 1) + { + gUnknown_02038478->unk_0004[i]->pos1.y = 0x70; + gUnknown_02038478->unk_0004[i]->oam.size = 0; + r5++; + } + StartSpriteAnim(gUnknown_02038478->unk_0004[i], r5); } + for (i = 0; i < 2; i++) + { + gUnknown_02038478->unk_0020[i] = sub_809A9A0(72 * i + 0x7c, 0x58, i, 0, gUnknown_02038478->unk_023e); + if (gUnknown_02038478->unk_0020[i]) + { + gUnknown_02038478->unk_0020[i]->data[0] = (i == 0 ? -1 : 1); + gUnknown_02038478->unk_0020[i]->callback = sub_8096784; + } + } + sub_809665C(); +} - while (ptr < gUnk20026A6) +void sub_809658C(void) +{ + u16 i; + if (gUnknown_02038478->unk_0000) + { + DestroySprite(gUnknown_02038478->unk_0000); + gUnknown_02038478->unk_0000 = NULL; + } + for (i = 0; i < 4; i++) + { + if (gUnknown_02038478->unk_0004[i]) + { + DestroySprite(gUnknown_02038478->unk_0004[i]); + gUnknown_02038478->unk_0004[i] = NULL; + } + } + for (i = 0; i < 2; i++) { - ptr[0] = CHAR_SPACE; - ptr++; + if (gUnknown_02038478->unk_0020[i]) + DestroySprite(gUnknown_02038478->unk_0020[i]); } +} - ptr[0] = EOS; - Menu_PrintText(gUnk2002694, 11, 17); +void sub_80965F8(void) +{ + if (++gUnknown_02038478->curBox > 13) + gUnknown_02038478->curBox = 0; + sub_809665C(); +} + +void sub_809662C(void) +{ + gUnknown_02038478->curBox = (gUnknown_02038478->curBox == 0 ? 13 : gUnknown_02038478->curBox - 1); + sub_809665C(); +} + +void sub_809665C(void) +{ + u8 nPokemonInBox = CountPokemonInBoxN(gUnknown_02038478->curBox); + u8 *stringVar = gStringVar1; + + stringVar[0] = EXT_CTRL_CODE_BEGIN; + stringVar[1] = 0x04; // EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW + stringVar[2] = 0x0F; // TEXT_COLOR_WHITE2 + stringVar[3] = 0x01; // TEXT_COLOR_DARK_GREY + stringVar[4] = 0x0E; // TEXT_COLOR_LIGHT_BLUE + stringVar += 5; + + stringVar = StringCopy(stringVar, gPokemonStorage.boxNames[gUnknown_02038478->curBox]); + + stringVar[0] = CHAR_NEWLINE; + stringVar[1] = EXT_CTRL_CODE_BEGIN; + stringVar[2] = 0x11; // EXT_CTRL_CODE_CLEAR + if (nPokemonInBox < 10) + stringVar[3] = 0x28; + else + stringVar[3] = 0x22; + stringVar += 4; + + stringVar = ConvertIntToDecimalString(stringVar, nPokemonInBox); + + stringVar[0] = CHAR_SLASH; + stringVar[1] = CHAR_0 + 3; + stringVar[2] = CHAR_0 + 0; + stringVar[3] = EOS; + sub_80966F4(gStringVar1, 0, 1); +} + +void sub_80966F4(const u8 *sourceString, u16 x, u16 y) +{ + u16 *vdest = (u16 *)(BG_CHAR_ADDR(4) + (GetSpriteTileStartByTag(gUnknown_02038478->unk_0240) * 32) + y * 256 + x * 32); + u8 *tileBuff = gUnknown_083B6DB8; + DmaFill16(3, 0x1111, tileBuff, 0x400); + Text_InitWindow8004E3C(&gWindowTemplate_81E6D38, tileBuff, sourceString); + DmaCopy16(3, tileBuff, vdest, 0x400); +} + +void sub_8096784(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; + } + } } diff --git a/src/pokemon/pokemon_storage_system_2.c b/src/pokemon/pokemon_storage_system_2.c new file mode 100644 index 000000000..512bde5db --- /dev/null +++ b/src/pokemon/pokemon_storage_system_2.c @@ -0,0 +1,2063 @@ + +// Includes +#include "global.h" +#include "decompress.h" +#include "constants/songs.h" +#include "constants/species.h" +#include "data2.h" +#include "sound.h" +#include "ewram.h" +#include "task.h" +#include "main.h" +#include "palette.h" +#include "menu.h" +#include "graphics.h" +#include "strings.h" +#include "string_util.h" +#include "pokemon_summary_screen.h" +#include "mail_data.h" +#include "naming_screen.h" +#include "pokemon_storage_system.h" + +// Static type declarations + +// Static RAM declarations + +EWRAM_DATA u8 gUnknown_0203847C = 0; +EWRAM_DATA u8 gUnknown_0203847D = 0; +EWRAM_DATA u8 gUnknown_0203847E = 0; +EWRAM_DATA u8 gUnknown_0203847F = 0; + +// Static ROM declarations + +void sub_8096884(void); +void sub_8096AFC(void); +void sub_8096B38(void); +void SetPSSCallback(void (*func)(void)); +void sub_8096BF0(void); +void sub_8096C68(void); +void sub_8096C84(void); +void sub_8096FC8(void); +void sub_8097004(void); +void sub_8097078(void); +void sub_80972A8(void); +void sub_80972FC(void); +void c3_0808DC50(void); +void sub_8097390(void); +void sub_809746C(void); +void sub_8097594(void); +void sub_8097788(void); +void sub_80977E4(void); +void sub_8097858(void); +void sub_809789C(void); +void sub_8097974(void); +void sub_8097A64(void); +void sub_8097B44(void); +void sub_8097BA0(void); +void sub_8097CC0(void); +void sub_8097DE0(void); +void sub_8097E44(void); +void sub_8097E70(void); +void sub_8097F58(void); +void sub_8097FB8(void); +void sub_809801C(void); +void BoxSetMosaic(void); +void sub_8098090(struct Sprite *sprite); +void sub_80980D4(void); +void sub_80981F0(u16 species, u32 pid); +void sub_80982B4(void); +void sub_8098350(void); +void sub_8098400(void); +void add_to_c3_somehow(void); +void sub_8098780(void); +void sub_8098690(bool8 flag); +bool8 sub_80985CC(void); +void sub_80986E8(void); +void sub_8098710(void); +void sub_8098734(void); +void sub_80987DC(void); +void sub_809880C(void); +bool8 sub_8098830(void); +void PrintStorageActionText(u8 index); +void sub_8098A38(s8); +void sub_8098A5C(void); +void sub_8098A80(void); +void sub_8098AA8(u8 a0); + +// .rodata + +const u16 gPokemonStorageScrollingBGPalette[] = INCBIN_U16("graphics/pokemon_storage/scrolling_bg.gbapal"); + +const u16 gPokemonStorageScrollingBGTile[] = INCBIN_U16("graphics/pokemon_storage/scrolling_bg.4bpp"); + +const u8 gPokemonStorageScrollingBGTilemap[] = INCBIN_U8("graphics/pokemon_storage/scrolling_bg_map.bin.lz"); + +const u16 sUnknownTilemap[] = { + 0x1281, + 0x1282, + 0x1283, + 0x1284, + 0x1285, + 0x1286, + 0x1287, + 0x1288, + 0x128C, + 0x128D, + 0x128E, + 0x128F, + 0x1290, + 0x1291, + 0x1292, + 0x1293, + 0x0281, + 0x0282, + 0x0283, + 0x0284, + 0x0285, + 0x0286, + 0x0287, + 0x0288, + 0x028C, + 0x028D, + 0x028E, + 0x028F, + 0x0290, + 0x0291, + 0x0292, + 0x0293, + 0x12AD, + 0x12AE, + 0x12A8, + 0x12A8 +}; + +const u16 WaveformPalette[] = INCBIN_U16("graphics/pokemon_storage/waveform.gbapal"); + +const u8 WaveformTiles[] = INCBIN_U8("graphics/pokemon_storage/waveform.4bpp"); + +const u16 gUnknown_083B6D74[] = INCBIN_U16("graphics/pokemon_storage/83B6D74.gbapal"); + +const u16 gUnknown_083B6D94[] = INCBIN_U16("graphics/pokemon_storage/83B6D94.gbapal"); + +struct PokemonStorageSystemData *const gPokemonStorageSystemPtr = &ePokemonStorageSystem; + +u8 *const gUnknown_083B6DB8 = gTileBuffer; + +const struct SpritePalette gWaveformSpritePalette = { + WaveformPalette, 0xdacd +}; + +// .text + +void task_intro_29(u8 whichMenu) +{ + gUnknown_0203847D = whichMenu; + gPokemonStorageSystemPtr->unk_0005 = whichMenu; + SetMainCallback2(sub_8096884); +} + +void sub_80967DC(void) +{ + REG_BG0HOFS = 0; + REG_BG0VOFS = 0; + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + REG_BG2VOFS = 0; + REG_BG2HOFS = 0; + REG_BG3HOFS = 0; + REG_BG3VOFS = 0; +} + +void sub_8096804(void) +{ + ResetPaletteFade(); + ResetSpriteData(); + FreeSpriteTileRanges(); + FreeAllSpritePalettes(); + ResetTasks(); + gReservedSpriteTileCount = 0x280; + sub_809CFDC(&gPokemonStorageSystemPtr->unk_0020, gPokemonStorageSystemPtr->unk_0028, 8); + gKeyRepeatStartDelay = 20; +} + +void sub_8096848(void) +{ + sub_809B0D4(); + gUnknown_0203847C = (gPokemonStorageSystemPtr->unk_0005 == 1 ? 1 : 0); + gUnknown_0203847E = 0; +} + +void sub_8096874(void) +{ + REG_DISPCNT = DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON; +} + +void sub_8096884(void) +{ + switch (gMain.state) + { + case 0: + SetVBlankCallback(NULL); + REG_DISPCNT = 0; + sub_8096804(); + gMain.state++; + break; + case 1: + Text_LoadWindowTemplate(&gWindowTemplate_81E6D00); + gMain.state++; + break; + case 2: + InitMenuWindow(&gWindowTemplate_81E6D00); + Menu_EraseScreen(); + gMain.state++; + break; + case 3: + sub_80967DC(); + sub_8096848(); + gMain.state++; + break; + case 4: + ResetPSSMonIconSprites(); + sub_809AA24(); + gMain.state++; + break; + case 5: + sub_8097DE0(); + gMain.state++; + break; + case 6: + sub_8097E70(); + gMain.state++; + break; + case 7: + sub_8098400(); + gMain.state++; + break; + case 8: + sub_8099BF8(gPokemonStorage.currentBox); + gPokemonStorageSystemPtr->unk_12bc.baseTileTag = 0x000a; + gPokemonStorageSystemPtr->unk_12bc.basePaletteTag = 0xdacb; + sub_80F727C(&gPokemonStorageSystemPtr->unk_12bc); + sub_80F7404(); + gMain.state++; + break; + case 9: + sub_8096874(); + SetPSSCallback(sub_8096BF0); + SetMainCallback2(sub_8096B38); + SetVBlankCallback(sub_8096AFC); + gMain.state++; + break; + } +} + +void sub_80969A0(void) +{ + switch (gMain.state) + { + case 0: + SetVBlankCallback(NULL); + REG_DISPCNT = 0x0000; + gPokemonStorageSystemPtr->unk_0005 = gUnknown_0203847D; + sub_8096804(); + if (gUnknown_0203847F == 1) + sub_809BBC0(); + if (gUnknown_0203847F == 0) + sub_809BD14(); + gMain.state++; + break; + case 1: + Text_LoadWindowTemplate(&gWindowTemplate_81E6D00); + gMain.state++; + break; + case 2: + InitMenuWindow(&gWindowTemplate_81E6D00); + Menu_EraseScreen(); + gMain.state++; + break; + case 3: + sub_80967DC(); + gMain.state++; + break; + case 4: + ResetPSSMonIconSprites(); + sub_809AA98(); + gMain.state++; + break; + case 5: + sub_8097DE0(); + gMain.state++; + break; + case 6: + sub_8097E70(); + gMain.state++; + break; + case 7: + sub_8098400(); + gMain.state++; + break; + case 8: + sub_8099BF8(gPokemonStorage.currentBox); + gPokemonStorageSystemPtr->unk_12bc.baseTileTag = 0x000a; + gPokemonStorageSystemPtr->unk_12bc.basePaletteTag = 0xdacb; + sub_80F727C(&gPokemonStorageSystemPtr->unk_12bc); + sub_80F7404(); + gMain.state++; + break; + case 9: + BeginNormalPaletteFade(0xffffffff, 0, 16, 0, 0); + SetVBlankCallback(sub_8096AFC); + gMain.state++; + break; + case 10: + sub_8096874(); + SetPSSCallback(sub_8096C68); + SetMainCallback2(sub_8096B38); + gMain.state++; + break; + } +} + +void sub_8096AFC(void) +{ + REG_BG2HOFS = gPokemonStorageSystemPtr->unk_08b4; + REG_BG3HOFS = gPokemonStorageSystemPtr->unk_000a; + REG_BG3VOFS = gPokemonStorageSystemPtr->unk_0008; + LoadOam(); + ProcessSpriteCopyRequests(); + sub_809CFF0(); + TransferPlttBuffer(); +} + +void sub_8096B38(void) +{ + gPokemonStorageSystemPtr->unk_0000(); + sub_8097E44(); + sub_8098734(); + AnimateSprites(); + BuildOamBuffer(); +} + +void sub_8096B5C(void) +{ + switch (gPokemonStorageSystemPtr->unk_0006) + { + case 0: + ShowPokemonSummaryScreen(gPokemonStorageSystemPtr->unk_2690.pokemon, gPokemonStorageSystemPtr->unk_268d, gPokemonStorageSystemPtr->unk_268c, sub_80969A0, gPokemonStorageSystemPtr->unk_268e); + break; + case 1: + DoNamingScreen(1, gPokemonStorage.boxNames[gPokemonStorage.currentBox], 0, 0, 0, sub_80969A0); + break; + } +} + +void SetPSSCallback(void (*func)(void)) +{ + gPokemonStorageSystemPtr->unk_0000 = func; + gPokemonStorageSystemPtr->unk_0004 = 0; +} + +void sub_8096BF0(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + BlendPalettes(0xffffffff, 16, 0); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + PlaySE(SE_PC_LOGON); + gPokemonStorageSystemPtr->unk_000c.tileTag = 14; + gPokemonStorageSystemPtr->unk_000c.paletteTag = 0xdad0; + gPokemonStorageSystemPtr->unk_000c.unk04 = 0; + gPokemonStorageSystemPtr->unk_000c.unk06 = 0; + sub_80C5CD4(&gPokemonStorageSystemPtr->unk_000c); + BlendPalettes(0xffffffff, 0, 0); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 2: + if (sub_80C5DCC()) + SetPSSCallback(sub_8096C84); + break; + } +} + +void sub_8096C68(void) +{ + if (!UpdatePaletteFade()) + SetPSSCallback(sub_8096C84); +} + +void sub_8096C84(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + switch (sub_809CA40()) + { + case 1: + PlaySE(SE_SELECT); + gPokemonStorageSystemPtr->unk_0004 = 1; + break; + case 5: + if (gPokemonStorageSystemPtr->unk_0005 != 2) + { + PrintStorageActionText(PC_TEXT_WHICH_ONE_WILL_TAKE); + gPokemonStorageSystemPtr->unk_0004 = 3; + } + else + { + sub_809B0D4(); + SetPSSCallback(sub_8096FC8); + } + break; + case 6: + if (gPokemonStorageSystemPtr->unk_0005 == 2) + { + if (sub_809BF20() && ItemIsMail(gPokemonStorageSystemPtr->unk_11f2)) + { + gPokemonStorageSystemPtr->unk_0004 = 5; + } + else + { + SetPSSCallback(sub_8097004); + } + } + break; + case 4: + SetPSSCallback(sub_8097BA0); + break; + case 16: + SetPSSCallback(sub_8097CC0); + break; + case 7: + PlaySE(SE_SELECT); + SetPSSCallback(sub_809789C); + break; + case 8: + PlaySE(SE_SELECT); + SetPSSCallback(sub_8097078); + break; + case 9: + PlaySE(SE_SELECT); + gPokemonStorageSystemPtr->unk_08b2 = gPokemonStorage.currentBox + 1; + if (gPokemonStorageSystemPtr->unk_08b2 > 13) + gPokemonStorageSystemPtr->unk_08b2 = 0; + sub_8099C70(gPokemonStorageSystemPtr->unk_08b2); + gPokemonStorageSystemPtr->unk_0004 = 2; + break; + case 10: + PlaySE(SE_SELECT); + gPokemonStorageSystemPtr->unk_08b2 = gPokemonStorage.currentBox - 1; + if (gPokemonStorageSystemPtr->unk_08b2 < 0) + gPokemonStorageSystemPtr->unk_08b2 = 13; + sub_8099C70(gPokemonStorageSystemPtr->unk_08b2); + gPokemonStorageSystemPtr->unk_0004 = 2; + break; + case 11: + if (!sub_809BE80()) + { + if (ItemIsMail(gPokemonStorageSystemPtr->unk_11f2)) + { + gPokemonStorageSystemPtr->unk_0004 = 5; + } + else + { + PlaySE(SE_SELECT); + SetPSSCallback(sub_809746C); + } + } + else + { + gPokemonStorageSystemPtr->unk_0004 = 4; + } + break; + case 13: + if (sub_809BE80()) + { + gPokemonStorageSystemPtr->unk_0004 = 4; + } + else + { + PlaySE(SE_SELECT); + SetPSSCallback(sub_80972A8); + } + break; + case 14: + if (!sub_809BEBC()) + { + gPokemonStorageSystemPtr->unk_0004 = 4; + } + else + { + PlaySE(SE_SELECT); + SetPSSCallback(c3_0808DC50); + } + break; + case 12: + PlaySE(SE_SELECT); + SetPSSCallback(sub_8097390); + break; + case 15: + PlaySE(SE_SELECT); + SetPSSCallback(sub_80972FC); + break; + } + break; + case 1: + if (!sub_809AC00()) + { + if (sub_809BF48()) + sub_80986E8(); + else + sub_8098710(); + if (gPokemonStorageSystemPtr->unk_11f6) + BoxSetMosaic(); + gPokemonStorageSystemPtr->unk_0004 = 0; + } + break; + case 2: + if (!sub_8099D34()) + { + gPokemonStorage.currentBox = gPokemonStorageSystemPtr->unk_08b2; + if (!gUnknown_0203847C && !sub_809BF20()) + { + sub_809B440(); + BoxSetMosaic(); + } + gPokemonStorageSystemPtr->unk_0004 = 0; + } + break; + case 3: + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) + { + sub_8098A5C(); + gPokemonStorageSystemPtr->unk_0004 = 0; + } + break; + case 4: + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_LAST_POKE); + gPokemonStorageSystemPtr->unk_0004 = 6; + break; + case 5: + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL); + gPokemonStorageSystemPtr->unk_0004 = 6; + break; + case 6: + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) + { + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8096FC8(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_809880C(); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!sub_8098830()) + SetPSSCallback(sub_8096C84); + break; + } +} + +void sub_8097004(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PlaySE(SE_SELECT); + add_to_c3_somehow(); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!sub_80985CC()) + { + sub_809B0C0(sub_809B0F4()); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 2: + if (!sub_809AC00()) + { + if (gPokemonStorageSystemPtr->unk_11f6) + BoxSetMosaic(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8097078(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PrintStorageActionText(PC_TEXT_IS_SELECTED); + sub_809CE84(); + gPokemonStorageSystemPtr->unk_0004 = 1; + break; + case 1: + switch (sub_809CF30()) + { + case -1: + case 0: + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + break; + case 3: + if (sub_809BE80()) + { + gPokemonStorageSystemPtr->unk_0004 = 2; + } + else + { + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(sub_80972A8); + } + break; + case 5: + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(sub_80972FC); + break; + case 4: + if (!sub_809BEBC()) + { + gPokemonStorageSystemPtr->unk_0004 = 2; + } + else + { + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(c3_0808DC50); + } + break; + case 2: + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(sub_8097390); + break; + case 1: + if (sub_809BE80()) + { + gPokemonStorageSystemPtr->unk_0004 = 2; + } + else if (ItemIsMail(gPokemonStorageSystemPtr->unk_11f2)) + { + gPokemonStorageSystemPtr->unk_0004 = 3; + } + else + { + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(sub_809746C); + } + break; + case 7: + if (sub_809BE80()) + { + gPokemonStorageSystemPtr->unk_0004 = 2; + } + else if (gPokemonStorageSystemPtr->unk_11f9) + { + gPokemonStorageSystemPtr->unk_0004 = 4; + } + else if (ItemIsMail(gPokemonStorageSystemPtr->unk_11f2)) + { + gPokemonStorageSystemPtr->unk_0004 = 3; + } + else + { + PlaySE(SE_SELECT); + SetPSSCallback(sub_8097594); + } + break; + case 6: + PlaySE(SE_SELECT); + SetPSSCallback(sub_8097788); + break; + case 8: + PlaySE(SE_SELECT); + SetPSSCallback(sub_80977E4); + break; + } + break; + case 2: + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_LAST_POKE); + gPokemonStorageSystemPtr->unk_0004 = 5; + break; + case 4: + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_CANT_RELEASE_EGG); + gPokemonStorageSystemPtr->unk_0004 = 5; + break; + case 3: + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL); + gPokemonStorageSystemPtr->unk_0004 = 5; + break; + case 5: + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) + { + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_80972A8(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_809B100(0); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!sub_809B130()) + { + if (gUnknown_0203847C) + SetPSSCallback(sub_8097858); + else + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_80972FC(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_809B100(1); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!sub_809B130()) + { + if (gUnknown_0203847C) + SetPSSCallback(sub_8097858); + else + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void c3_0808DC50(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_809B100(2); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!sub_809B130()) + { + BoxSetMosaic(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8097390(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + if (CalculatePlayerPartyCount() == 6) + { + PrintStorageActionText(PC_TEXT_PARTY_FULL); + gPokemonStorageSystemPtr->unk_0004 = 1; + } + else + { + sub_809B0E0(); + sub_809B100(0); + gPokemonStorageSystemPtr->unk_0004 = 2; + } + break; + case 1: + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) + { + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + } + break; + case 2: + if (!sub_809B130()) + { + sub_809880C(); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 3: + if (!sub_8098830()) + { + sub_809B100(1); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 4: + if (!sub_809B130()) + { + sub_80987DC(); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 5: + SetPSSCallback(sub_8097004); + break; + } +} + +void sub_809746C(void) +{ + u8 r4; + + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); + sub_8096264(&gPokemonStorageSystemPtr->unk_2370, 0x0007, 0xdaca, 3); + sub_809634C(gUnknown_0203847E); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + r4 = sub_8096368(); + if (r4 == 200); + else if (r4 == 201) + { + sub_8098A5C(); + sub_809635C(); + sub_8096310(); + SetPSSCallback(sub_8096C84); + } + else + { + if (sub_809B62C(r4)) + { + sub_8098A5C(); + sub_809635C(); + sub_8096310(); + gPokemonStorageSystemPtr->unk_0004 = 2; + } + else + { + PrintStorageActionText(PC_TEXT_BOX_IS_FULL); + gPokemonStorageSystemPtr->unk_0004 = 4; + } + gUnknown_0203847E = r4; + } + break; + case 2: + party_compaction(); + sub_8099310(); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 3: + if (sub_8099374() == 0) + { + sub_809B6BC(); + BoxSetMosaic(); + sub_80987DC(); + SetPSSCallback(sub_8096C84); + } + break; + case 4: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); + gPokemonStorageSystemPtr->unk_0004 = 1; + } + break; + } +} + +void sub_8097594(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PrintStorageActionText(PC_TEXT_RELEASE_POKE); + sub_8098A38(1); + gPokemonStorageSystemPtr->unk_0004++; + // fallthrough + case 1: + switch (Menu_ProcessInputNoWrap()) + { + case -1: + case 1: + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + break; + case 0: + sub_8098A5C(); + sub_809B7D4(); + sub_809B6DC(); + gPokemonStorageSystemPtr->unk_0004++; + break; + } + break; + case 2: + sub_809B960(); + if (!sub_809B734()) + { + while (1) + { + s8 r0 = sub_809B960(); + if (r0 == 1) + { + gPokemonStorageSystemPtr->unk_0004++; + break; + } + if (r0 == 0) + { + gPokemonStorageSystemPtr->unk_0004 = 8; + break; + } + } + } + break; + case 3: + sub_809B760(); + sub_809801C(); + PrintStorageActionText(PC_TEXT_WAS_RELEASED); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 4: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + PrintStorageActionText(PC_TEXT_BYE_BYE); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 5: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + sub_8098A5C(); + if (gUnknown_0203847C) + { + party_compaction(); + sub_8099310(); + gPokemonStorageSystemPtr->unk_0004++; + } + else + { + gPokemonStorageSystemPtr->unk_0004 = 7; + } + } + break; + case 6: + if (sub_8099374() == 0) + { + sub_809B440(); + BoxSetMosaic(); + sub_80987DC(); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 7: + SetPSSCallback(sub_8096C84); + break; + case 8: + PrintStorageActionText(PC_TEXT_WAS_RELEASED); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 9: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + PrintStorageActionText(PC_TEXT_SURPRISE); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 10: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + sub_8098A5C(); + sub_8099958(); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 11: + if (!sub_8099990()) + { + sub_809B7AC(); + PrintStorageActionText(PC_TEXT_CAME_BACK); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 12: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + PrintStorageActionText(PC_TEXT_WORRIED); + gPokemonStorageSystemPtr->unk_0004++; + } + break; + case 13: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8097788(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_809BC18(); + BeginNormalPaletteFade(0xffffffff, 0, 0, 16, 0); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!UpdatePaletteFade()) + { + gUnknown_0203847F = 0; + gPokemonStorageSystemPtr->unk_0006 = 0; + SetMainCallback2(sub_8096B5C); + } + break; + } +} + +void sub_80977E4(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PrintStorageActionText(PC_TEXT_MARK_POKE); + gPokemonStorageSystemPtr->unk_12bc.markings = gPokemonStorageSystemPtr->unk_11f7; + sub_80F7418(gPokemonStorageSystemPtr->unk_11f7, 0xb0, 0x10); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!sub_80F7500()) + { + sub_80F7470(); + sub_8098A5C(); + sub_809BDD8(gPokemonStorageSystemPtr->unk_12bc.markings); + sub_809801C(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8097858(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + party_compaction(); + sub_8099310(); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (sub_8099374() == 0) + { + sub_80987DC(); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_809789C(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PrintStorageActionText(PC_TEXT_WHAT_YOU_DO); + sub_809CE84(); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + switch (sub_809CF30()) + { + case -1: + case 0: + sub_809A860(TRUE); + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + break; + case 11: + PlaySE(SE_SELECT); + SetPSSCallback(sub_8097B44); + break; + case 10: + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(sub_8097974); + break; + case 9: + PlaySE(SE_SELECT); + sub_8098A5C(); + SetPSSCallback(sub_8097A64); + break; + } + break; + } +} + +void sub_8097974(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_8098A80(); + PrintStorageActionText(PC_TEXT_PICK_A_THEME); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + gPokemonStorageSystemPtr->unk_0d5e = sub_809CF30(); + switch (gPokemonStorageSystemPtr->unk_0d5e) + { + case -1: + sub_809A860(TRUE); + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + break; + case 12 ... 15: + PlaySE(SE_SELECT); + gPokemonStorageSystemPtr->unk_0d5e -= 12; + sub_8098AA8(gPokemonStorageSystemPtr->unk_0d5e); + PrintStorageActionText(PC_TEXT_PICK_A_WALLPAPER); + gPokemonStorageSystemPtr->unk_0004++; + break; + } + break; + case 2: + gPokemonStorageSystemPtr->unk_0d60 = sub_809CF30(); + switch (gPokemonStorageSystemPtr->unk_0d60) + { + case -1: + sub_8098A5C(); + gPokemonStorageSystemPtr->unk_0004 = 0; + break; + case -2: + break; + default: + PlaySE(SE_SELECT); + sub_8098A5C(); + gPokemonStorageSystemPtr->unk_0d60 -= 16; + sub_8099DCC(gPokemonStorageSystemPtr->unk_0d60); + gPokemonStorageSystemPtr->unk_0004++; + break; + } + break; + case 3: + if (!sub_8099E08()) + { + sub_809A860(TRUE); + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8097A64(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + PrintStorageActionText(PC_TEXT_JUMP_TO_WHICH_BOX); + sub_8096264(&gPokemonStorageSystemPtr->unk_2370, 0x0007, 0xdaca, 3); + sub_809634C(gPokemonStorage.currentBox); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + gPokemonStorageSystemPtr->unk_08b2 = sub_8096368(); + switch (gPokemonStorageSystemPtr->unk_08b2) + { + case 200: + break; + default: + sub_8098A5C(); + sub_809635C(); + sub_8096310(); + if (gPokemonStorageSystemPtr->unk_08b2 == 201 || gPokemonStorageSystemPtr->unk_08b2 == gPokemonStorage.currentBox) + { + sub_809A860(TRUE); + SetPSSCallback(sub_8096C84); + } + else + { + gPokemonStorageSystemPtr->unk_0004++; + } + break; + } + break; + case 2: + sub_8099C70(gPokemonStorageSystemPtr->unk_08b2); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 3: + if (!sub_8099D34()) + { + gPokemonStorage.currentBox = gPokemonStorageSystemPtr->unk_08b2; + SetPSSCallback(sub_8096C84); + } + break; + } +} + +void sub_8097B44(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + sub_809BB90(); + BeginNormalPaletteFade(0xffffffff, 0, 0, 16, 0); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 1: + if (!UpdatePaletteFade()) + { + gUnknown_0203847F = 1; + gPokemonStorageSystemPtr->unk_0006 = 1; + SetMainCallback2(sub_8096B5C); + } + break; + } +} + +void sub_8097BA0(void) +{ + switch (gPokemonStorageSystemPtr->unk_0004) + { + case 0: + if (sub_809BF20()) + { + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_HOLDING_POKE); + gPokemonStorageSystemPtr->unk_0004 = 1; + } + else + { + PlaySE(SE_SELECT); + PrintStorageActionText(PC_TEXT_EXIT_BOX); + sub_8098A38(0); + gPokemonStorageSystemPtr->unk_0004 = 2; + } + break; + case 1: + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) + { + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + } + break; + case 2: + switch (Menu_ProcessInputNoWrap()) + { + case 1: + case -1: + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + break; + case 0: + PlaySE(SE_PC_OFF); + sub_8098A5C(); + gPokemonStorageSystemPtr->unk_0004++; + break; + } + break; + case 3: + gPokemonStorageSystemPtr->unk_000c.tileTag = 0x000e; + gPokemonStorageSystemPtr->unk_000c.paletteTag = 0xdad0; + gPokemonStorageSystemPtr->unk_000c.unk04 = 20; + gPokemonStorageSystemPtr->unk_000c.unk06 = 0; + sub_80C5E38(&gPokemonStorageSystemPtr->unk_000c); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 4: + if (sub_80C5F98()) + { + gPlayerPartyCount = CalculatePlayerPartyCount(); + SetMainCallback2(sub_80961A8); + } + break; + } +} + +void sub_8097CC0(void) { + switch (gPokemonStorageSystemPtr->unk_0004) { + case 0: + if (sub_809BF20()) { + PlaySE(SE_HAZURE); + PrintStorageActionText(PC_TEXT_HOLDING_POKE); + gPokemonStorageSystemPtr->unk_0004 = 1; + } + else { + PlaySE(SE_SELECT); + PrintStorageActionText(PC_TEXT_CONTINUE_BOX); + sub_8098A38(0); + gPokemonStorageSystemPtr->unk_0004 = 2; + } + break; + case 1: + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + } + break; + case 2: + switch (Menu_ProcessInputNoWrap()) { + case 0: + sub_8098A5C(); + SetPSSCallback(sub_8096C84); + break; + case -1: + case 1: + PlaySE(SE_PC_OFF); + sub_8098A5C(); + gPokemonStorageSystemPtr->unk_0004++; + break; + } + break; + case 3: + gPokemonStorageSystemPtr->unk_000c.tileTag = 0x000e; + gPokemonStorageSystemPtr->unk_000c.paletteTag = 0xdad0; + gPokemonStorageSystemPtr->unk_000c.unk04 = 20; + gPokemonStorageSystemPtr->unk_000c.unk06 = 0; + sub_80C5E38(&gPokemonStorageSystemPtr->unk_000c); + gPokemonStorageSystemPtr->unk_0004++; + break; + case 4: + if (sub_80C5F98()) { + gPlayerPartyCount = CalculatePlayerPartyCount(); + SetMainCallback2(sub_80961A8); + } + break; + } +} + +void sub_8097DE0(void) +{ + gPokemonStorageSystemPtr->unk_0007 = 0; + gPokemonStorageSystemPtr->unk_0008 = 0; + gPokemonStorageSystemPtr->unk_000a = 0; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3) | BGCNT_SCREENBASE(30); + DmaCopy16Defvars(3, gPokemonStorageScrollingBGTile, BG_SCREEN_ADDR(28), sizeof gPokemonStorageScrollingBGTile); + LZ77UnCompVram(gPokemonStorageScrollingBGTilemap, BG_SCREEN_ADDR(30)); + LoadPalette(gPokemonStorageScrollingBGPalette, 0xd0, 0x10); +} + +void sub_8097E44(void) +{ + if (++gPokemonStorageSystemPtr->unk_0007 >= 2) + { + gPokemonStorageSystemPtr->unk_0007 = 0; + gPokemonStorageSystemPtr->unk_0008--; + gPokemonStorageSystemPtr->unk_000a++; + } +} + +void sub_8097E70(void) +{ + LZ77UnCompVram(gPSSMenuHeader_Gfx, BG_SCREEN_ADDR(10)); + LZ77UnCompWram(gPSSMenuHeader_Tilemap, gUnknown_02039760); + sub_809D034(BG_SCREEN_ADDR(15), 0, 0, gUnknown_02039760, 0, 0, 10, 20); + LoadPalette(gPSSMenu1_Pal, 0x10, 0x20); + LoadPalette(gPSSMenu2_Pal, 0x00, 0x20); + LoadPalette(gUnknown_083B6D74, 0xB0, 0x20); + LoadPalette(gUnknown_083B6D94, 0xC0, 0x20); + LoadPalette(gUnknownPalette_81E6692 + 1, 0xF1, 0x02); + LoadPalette(gUnknownPalette_81E6692 + 1, 0xF2, 0x02); + LoadPalette(gUnknownPalette_81E6692 + 5, 0xF3, 0x02); + LoadPalette(gUnknownPalette_81E6692 + 12, 0xF4, 0x04); + LoadPalette(gUnknownPalette_81E6692 + 10, 0xF6, 0x04); + LoadPalette(gUnknownPalette_81E6692 + 2, 0xFF, 0x02); + LoadSpritePalette(&gWaveformSpritePalette); + sub_80980D4(); + sub_8097F58(); + sub_8097FB8(); + sub_809801C(); +} + +void sub_8097F58(void) +{ + gPokemonStorageSystemPtr->unk_12ac = sub_80F7940(0x000d, 0xdace, 0); + gPokemonStorageSystemPtr->unk_12ac->oam.priority = 0; + gPokemonStorageSystemPtr->unk_12ac->subpriority = 1; + gPokemonStorageSystemPtr->unk_12ac->pos1.x = 0x28; + gPokemonStorageSystemPtr->unk_12ac->pos1.y = 0x95; + gPokemonStorageSystemPtr->unk_12b8 = BG_CHAR_ADDR(4) + 32 * GetSpriteTileStartByTag(0x000d); +} + +const struct SpriteTemplate gSpriteTemplate_83B6EFC; + +void sub_8097FB8(void) +{ + u16 i; + struct SpriteSheet sheet = {WaveformTiles, 0x1c0, 0x0005}; + + LoadSpriteSheet(&sheet); + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&gSpriteTemplate_83B6EFC, i * 63 + 8, 9, 2); + gPokemonStorageSystemPtr->unk_12b0[i] = gSprites + spriteId; + } +} + +void sub_809801C(void) +{ + sub_80981F0(gPokemonStorageSystemPtr->unk_11f0, gPokemonStorageSystemPtr->unk_11ec); + sub_80982B4(); + sub_8098350(); +} + +void BoxSetMosaic(void) +{ + sub_809801C(); + if (gPokemonStorageSystemPtr->unk_2700) + { + gPokemonStorageSystemPtr->unk_2700->oam.mosaic = TRUE; + gPokemonStorageSystemPtr->unk_2700->data[0] = 10; + gPokemonStorageSystemPtr->unk_2700->data[1] = 1; + gPokemonStorageSystemPtr->unk_2700->callback = sub_8098090; + REG_MOSAIC = (gPokemonStorageSystemPtr->unk_2700->data[0] << 12) | (gPokemonStorageSystemPtr->unk_2700->data[0] << 8); + } +} + +void sub_8098090(struct Sprite *sprite) +{ + sprite->data[0] -= sprite->data[1]; + if (sprite->data[0] < 0) + sprite->data[0] = 0; + REG_MOSAIC = (sprite->data[0] << 12) | (sprite->data[0] << 8); + if (sprite->data[0] == 0) + { + sprite->oam.mosaic = FALSE; + sprite->callback = SpriteCallbackDummy; + } +} + +// sub_80980D4 + +const struct OamData gOamData_83B6EAC; + +#ifdef NONMATCHING +void sub_80980D4(void) +{ + u16 i; + u16 tileStart; + u8 palSlot; + u8 spriteId; + struct SpriteSheet sheet = {gPokemonStorageSystemPtr->unk_2784, 0x800, 0x0002}; + struct SpritePalette palette = {gPokemonStorageSystemPtr->unk_2704, 0xdac7}; + struct SpriteTemplate template = { + 0x0002, 0xdac7, &gOamData_83B6EAC, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy + }; + + for (i = 0; i < 0x800; i++) + gPokemonStorageSystemPtr->unk_2784[i] = 0; + for (i = 0; i < 0x10; i++) + gPokemonStorageSystemPtr->unk_2704[i] = 0; + + gPokemonStorageSystemPtr->unk_2700 = NULL; + if ((tileStart = LoadSpriteSheet(&sheet)) != 0 + && (palSlot = LoadSpritePalette(&palette)) != 0xff + && (spriteId = CreateSprite(&template, 0x28, 0x30, 0)) != MAX_SPRITES) + { + // FIXME this gets compiled as a separate block between the palSlot check and the spriteId check + gPokemonStorageSystemPtr->unk_2700 = gSprites + spriteId; + gPokemonStorageSystemPtr->unk_26fa = palSlot * 16 + 0x100; + gPokemonStorageSystemPtr->unk_26fc = BG_CHAR_ADDR(4) + tileStart * 32; + } + + if (gPokemonStorageSystemPtr->unk_2700 == NULL) + { + FreeSpriteTilesByTag(0x0002); + FreeSpritePaletteByTag(0xdac7); + } +} +#else + +const struct SpriteSheet gUnknown_083B6DCC = {ePokemonStorageSystem.unk_2784, 0x800, 0x0002}; +const struct SpritePalette gUnknown_083B6DD4 = {ePokemonStorageSystem.unk_2704, 0xdac7}; +const struct SpriteTemplate gSpriteTemplate_83B6DDC = { + 0x0002, 0xdac7, &gOamData_83B6EAC, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy +}; + +__attribute__((naked)) void sub_80980D4(void) +{ + asm_unified("\tpush {r4,r5,lr}\n" + "\tsub sp, 0x28\n" + "\tldr r0, _08098150 @ =gUnknown_083B6DCC\n" + "\tldr r1, [r0, 0x4]\n" + "\tldr r0, [r0]\n" + "\tstr r0, [sp, 0x18]\n" + "\tstr r1, [sp, 0x1C]\n" + "\tldr r0, _08098154 @ =gUnknown_083B6DD4\n" + "\tldr r1, [r0, 0x4]\n" + "\tldr r0, [r0]\n" + "\tstr r0, [sp, 0x20]\n" + "\tstr r1, [sp, 0x24]\n" + "\tmov r1, sp\n" + "\tldr r0, _08098158 @ =gSpriteTemplate_83B6DDC\n" + "\tldm r0!, {r2-r4}\n" + "\tstm r1!, {r2-r4}\n" + "\tldm r0!, {r2-r4}\n" + "\tstm r1!, {r2-r4}\n" + "\tmovs r1, 0\n" + "\tadd r5, sp, 0x18\n" + "\tldr r4, _0809815C @ =gSharedMem + 0x2784\n" + "\tmovs r3, 0\n" + "\tldr r2, _08098160 @ =0x000007ff\n" + "_08098102:\n" + "\tadds r0, r1, r4\n" + "\tstrb r3, [r0]\n" + "\tadds r0, r1, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r1, r0, 16\n" + "\tcmp r1, r2\n" + "\tbls _08098102\n" + "\tmovs r1, 0\n" + "\tldr r3, _08098164 @ =gSharedMem + 0x2704\n" + "\tmovs r2, 0\n" + "_08098116:\n" + "\tlsls r0, r1, 1\n" + "\tadds r0, r3\n" + "\tstrh r2, [r0]\n" + "\tadds r0, r1, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r1, r0, 16\n" + "\tcmp r1, 0xF\n" + "\tbls _08098116\n" + "\tldr r0, _08098168 @ =gSharedMem\n" + "\tmovs r1, 0x9C\n" + "\tlsls r1, 6\n" + "\tadds r0, r1\n" + "\tmovs r1, 0\n" + "\tstr r1, [r0]\n" + "\tadds r0, r5, 0\n" + "\tbl LoadSpriteSheet\n" + "\tlsls r0, 16\n" + "\tlsrs r5, r0, 16\n" + "\tcmp r5, 0\n" + "\tbeq _080981C4\n" + "\tadd r0, sp, 0x20\n" + "\tbl LoadSpritePalette\n" + "\tlsls r0, 24\n" + "\tlsrs r4, r0, 24\n" + "\tcmp r4, 0xFF\n" + "\tbeq _080981C4\n" + "\tb _080981B0\n" + "\t.align 2, 0\n" + "_08098150: .4byte gUnknown_083B6DCC\n" + "_08098154: .4byte gUnknown_083B6DD4\n" + "_08098158: .4byte gSpriteTemplate_83B6DDC\n" + "_0809815C: .4byte gSharedMem + 0x2784\n" + "_08098160: .4byte 0x000007ff\n" + "_08098164: .4byte gSharedMem + 0x2704\n" + "_08098168: .4byte gSharedMem\n" + "_0809816C:\n" + "\tldr r2, _0809819C @ =gSharedMem\n" + "\tmovs r0, 0x9C\n" + "\tlsls r0, 6\n" + "\tadds r3, r2, r0\n" + "\tlsls r0, r1, 4\n" + "\tadds r0, r1\n" + "\tlsls r0, 2\n" + "\tldr r1, _080981A0 @ =gSprites\n" + "\tadds r0, r1\n" + "\tstr r0, [r3]\n" + "\tlsls r0, r4, 4\n" + "\tmovs r1, 0x80\n" + "\tlsls r1, 1\n" + "\tadds r0, r1\n" + "\tldr r3, _080981A4 @ =0x000026fa\n" + "\tadds r1, r2, r3\n" + "\tstrh r0, [r1]\n" + "\tldr r4, _080981A8 @ =0x000026fc\n" + "\tadds r2, r4\n" + "\tlsls r0, r5, 5\n" + "\tldr r1, _080981AC @ =0x06010000\n" + "\tadds r0, r1\n" + "\tstr r0, [r2]\n" + "\tb _080981C4\n" + "\t.align 2, 0\n" + "_0809819C: .4byte gSharedMem\n" + "_080981A0: .4byte gSprites\n" + "_080981A4: .4byte 0x000026fa\n" + "_080981A8: .4byte 0x000026fc\n" + "_080981AC: .4byte 0x06010000\n" + "_080981B0:\n" + "\tmov r0, sp\n" + "\tmovs r1, 0x28\n" + "\tmovs r2, 0x30\n" + "\tmovs r3, 0\n" + "\tbl CreateSprite\n" + "\tlsls r0, 24\n" + "\tlsrs r1, r0, 24\n" + "\tcmp r1, 0x40\n" + "\tbne _0809816C\n" + "_080981C4:\n" + "\tldr r0, _080981E8 @ =gSharedMem\n" + "\tmovs r2, 0x9C\n" + "\tlsls r2, 6\n" + "\tadds r0, r2\n" + "\tldr r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _080981DE\n" + "\tmovs r0, 0x2\n" + "\tbl FreeSpriteTilesByTag\n" + "\tldr r0, _080981EC @ =0x0000dac7\n" + "\tbl FreeSpritePaletteByTag\n" + "_080981DE:\n" + "\tadd sp, 0x28\n" + "\tpop {r4,r5}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" + "_080981E8: .4byte gSharedMem\n" + "_080981EC: .4byte 0x0000dac7"); +} +#endif + +void sub_80981F0(u16 species, u32 pid) +{ + if (gPokemonStorageSystemPtr->unk_2700) + { + if (species != SPECIES_NONE) + { + HandleLoadSpecialPokePic(gMonFrontPicTable + species, gMonFrontPicCoords[species].coords, 1, (intptr_t)gPokemonStorageSystemPtr->unk_4784, gPokemonStorageSystemPtr->unk_2784, species, pid); + LZ77UnCompWram(gPokemonStorageSystemPtr->unk_11e8, gPokemonStorageSystemPtr->unk_2704); + CpuCopy32(gPokemonStorageSystemPtr->unk_2784, gPokemonStorageSystemPtr->unk_26fc, 0x800); + LoadPalette(gPokemonStorageSystemPtr->unk_2704, gPokemonStorageSystemPtr->unk_26fa, 0x20); + gPokemonStorageSystemPtr->unk_2700->invisible = FALSE; + } + else + { + gPokemonStorageSystemPtr->unk_2700->invisible = TRUE; + } + } +} + +void sub_80982B4(void) +{ + if (gPokemonStorageSystemPtr->unk_11f0) + { + sub_80F7A10(gPokemonStorageSystemPtr->unk_11f7, gPokemonStorageSystemPtr->unk_12b8); + gPokemonStorageSystemPtr->unk_12ac->invisible = FALSE; + } + else + { + gPokemonStorageSystemPtr->unk_12ac->invisible = TRUE; + } + Menu_EraseWindowRect(0, 11, 9, 17); + Menu_PrintText(gPokemonStorageSystemPtr->unk_127a, 1, 16); + Menu_PrintText(gPokemonStorageSystemPtr->unk_120f, 1, 11); + Menu_PrintText(gPokemonStorageSystemPtr->unk_1234, 0, 13); + Menu_PrintText(gPokemonStorageSystemPtr->unk_1259, 1, 15); +} + +void sub_8098350(void) +{ + u16 i; + + if (gPokemonStorageSystemPtr->unk_11f0) + { + sub_809D034(BG_SCREEN_ADDR(15), 1, 0, gUnknown_02039760, 1, 0, 8, 2); + for (i = 0; i < 2; i++) + StartSpriteAnimIfDifferent(gPokemonStorageSystemPtr->unk_12b0[i], i * 2 + 1); + } + else + { + sub_809D034(BG_SCREEN_ADDR(15), 1, 0, gUnknown_02039760, 10, 0, 8, 2); + for (i = 0; i < 2; i++) + StartSpriteAnim(gPokemonStorageSystemPtr->unk_12b0[i], i * 2); + } +} + +void sub_8098400(void) +{ + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_SCREENBASE(15); + LZ77UnCompVram(gPSSMenuMisc_Gfx, BG_SCREEN_ADDR(13)); + LZ77UnCompWram(gPSSMenuMisc_Tilemap, gPokemonStorageSystemPtr->unk_00a8); + LoadPalette(gPSSMenu3_Pal, 0x20, 0x20); + LoadPalette(gPSSMenu4_Pal, 0x30, 0x20); + DmaClear16(3, BG_SCREEN_ADDR(15), 0x800); + sub_8098780(); + if (gUnknown_0203847C) + { + sub_8098690(TRUE); + sub_8099200(TRUE); + sub_809D034(BG_SCREEN_ADDR(15), 10, 0, gPokemonStorageSystemPtr->unk_00a8, 0, 0, 12, 22); + } + else + { + sub_809D034(BG_SCREEN_ADDR(15), 10, 0, gPokemonStorageSystemPtr->unk_00a8, 0, 20, 12, 2); + sub_8098690(TRUE); + } + gPokemonStorageSystemPtr->unk_08af = 0; +} + +void sub_80984E8(void) +{ + gPokemonStorageSystemPtr->unk_08a8 = 20; + gPokemonStorageSystemPtr->unk_08aa = 2; + gPokemonStorageSystemPtr->unk_08ad = 0; + sub_8099200(FALSE); +} + +bool8 sub_8098520(void) +{ + if (gPokemonStorageSystemPtr->unk_08ad == 20) + return FALSE; + gPokemonStorageSystemPtr->unk_08a8--; + gPokemonStorageSystemPtr->unk_08aa++; + sub_809D034(BG_SCREEN_ADDR(15), 10, 0, gPokemonStorageSystemPtr->unk_00a8, 0, gPokemonStorageSystemPtr->unk_08a8, 12, gPokemonStorageSystemPtr->unk_08aa); + sub_80994A8(8); + if (++gPokemonStorageSystemPtr->unk_08ad == 20) + { + gUnknown_0203847C = 1; + return FALSE; + } + return TRUE; +} + +void add_to_c3_somehow(void) +{ + gPokemonStorageSystemPtr->unk_08a8 = 0; + gPokemonStorageSystemPtr->unk_08aa = 22; + gPokemonStorageSystemPtr->unk_08ad = 0; +} + +bool8 sub_80985CC(void) +{ + if (gPokemonStorageSystemPtr->unk_08ad == 20) + return FALSE; + gPokemonStorageSystemPtr->unk_08a8++; + gPokemonStorageSystemPtr->unk_08aa--; + sub_809D034(BG_SCREEN_ADDR(15), 10, 0, gPokemonStorageSystemPtr->unk_00a8, 0, gPokemonStorageSystemPtr->unk_08a8, 12, gPokemonStorageSystemPtr->unk_08aa); + sub_809D16C(BG_SCREEN_ADDR(15), 10, gPokemonStorageSystemPtr->unk_08aa, 12, 1); + sub_80994A8(-8); + if (++gPokemonStorageSystemPtr->unk_08ad == 20) + { + gUnknown_0203847C = 0; + sub_809954C(); + party_compaction(); + sub_809D034(BG_SCREEN_ADDR(15), 21, 0, gPokemonStorageSystemPtr->unk_00a8, 12, 0, 1, 2); + return FALSE; + } + return TRUE; +} + +void sub_8098690(bool8 flag) +{ + if (flag) + sub_809D034(BG_SCREEN_ADDR(15), 21, 0, gPokemonStorageSystemPtr->unk_00a8, 12, 0, 9, 2); + else + sub_809D034(BG_SCREEN_ADDR(15), 21, 0, gPokemonStorageSystemPtr->unk_00a8, 12, 2, 9, 2); +} + +void sub_80986E8(void) +{ + gPokemonStorageSystemPtr->unk_08af = 1; + gPokemonStorageSystemPtr->unk_08b0 = 30; + gPokemonStorageSystemPtr->unk_08b1 = 1; +} + +void sub_8098710(void) +{ + if (gPokemonStorageSystemPtr->unk_08af) + { + gPokemonStorageSystemPtr->unk_08af = 0; + sub_8098690(TRUE); + } +} + +void sub_8098734(void) +{ + if (gPokemonStorageSystemPtr->unk_08af && ++gPokemonStorageSystemPtr->unk_08b0 > 30) + { + gPokemonStorageSystemPtr->unk_08b0 = 0; + gPokemonStorageSystemPtr->unk_08b1 = gPokemonStorageSystemPtr->unk_08b1 ? FALSE : TRUE; + sub_8098690(gPokemonStorageSystemPtr->unk_08b1); + } +} + +void sub_8098780(void) +{ + int i; + + for (i = 1; i < PARTY_SIZE; i++) + { + u16 r1; + bool32 r0 = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); + if (r0) + r0 = TRUE; + r1 = r0 ? 12 : 16; + sub_809D104(gPokemonStorageSystemPtr->unk_00a8, 7, (i - 1) * 3 + 1, gPokemonStorageSystemPtr->unk_00a8, r1, 4, 4, 3); + } +} + +void sub_80987DC(void) +{ + sub_8098780(); + sub_809D034(BG_SCREEN_ADDR(15), 10, 0, gPokemonStorageSystemPtr->unk_00a8, 0, 0, 12, 22); +} + +void sub_809880C(void) +{ + gPokemonStorageSystemPtr->unk_08ae = 0; + PlaySE(SE_WIN_OPEN); + sub_80984E8(); +} + +bool8 sub_8098830(void) +{ + switch (gPokemonStorageSystemPtr->unk_08ae) + { + case 0: + if (!sub_8098520()) + { + sub_809B068(); + gPokemonStorageSystemPtr->unk_08ae++; + } + break; + case 1: + if (!sub_809AC00()) + { + if (gPokemonStorageSystemPtr->unk_11f6) + BoxSetMosaic(); + gPokemonStorageSystemPtr->unk_08ae++; + } + break; + case 2: + return FALSE; + } + return TRUE; +} + +const struct StorageAction gPCStorageActionTexts[] = { + {PCText_ExitBox, 0}, + {PCText_WhatYouDo, 0}, + {PCText_PickATheme, 0}, + {PCText_PickAWallpaper, 0}, + {PCText_IsSelected, 1}, + {PCText_JumpToWhichBox, 0}, + {PCText_DepositInWhichBox, 0}, + {PCText_WasDeposited, 1}, + {PCText_BoxIsFull, 0}, + {PCText_ReleasePoke, 0}, + {PCText_WasReleased, 4}, + {PCText_ByeBye, 6}, + {PCText_MarkPoke, 0}, + {PCText_LastPoke, 0}, + {PCText_PartyFull, 0}, + {PCText_HoldingPoke, 0}, + {PCText_WhichOneWillTake, 0}, + {PCText_CantReleaseEgg, 0}, + {PCText_ContinueBox, 0}, + {PCText_CameBack, 1}, + {PCText_Worried, 0}, + {PCText_Surprise, 0}, + {PCText_PleaseRemoveMail, 0} +}; + +void PrintStorageActionText(u8 index) { + u8 *ptr; + + Menu_DrawStdWindowFrame(10, 16, 29, 19); + + switch (gPCStorageActionTexts[index].format) + { + + case PC_TEXT_FMT_UNK_02: + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPCStorageActionTexts[index].text); + ptr = StringCopy(ptr, gPokemonStorageSystemPtr->unk_11fa); + break; + + case PC_TEXT_FMT_UNK_05: + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPCStorageActionTexts[index].text); + ptr = StringCopy(ptr, gPokemonStorageSystemPtr->unk_26e4); + break; + + case PC_TEXT_FMT_MON_NAME: + // {var} + " is selected." + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPokemonStorageSystemPtr->unk_11fa); + ptr = StringCopy(ptr, gPCStorageActionTexts[index].text); + break; + + case PC_TEXT_FMT_MON_NAME_2: + // {var} + " was released." + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPokemonStorageSystemPtr->unk_26e4); +#if ENGLISH + ptr = StringCopy(ptr, gPCStorageActionTexts[index].text); +#elif GERMAN + ptr = de_sub_8073174(gPokemonStorageSystemPtr->unk_2694, gPCStorageActionTexts[index].text); +#endif + break; + + case PC_TEXT_FMT_UNK_03: + { + const u8 *stringLength; + const u8 *text; + + text = gPCStorageActionTexts[index].text; + stringLength = &text[StringLength(text)] + 1; + + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPCStorageActionTexts[index].text); + ptr = StringCopy(ptr, gPokemonStorageSystemPtr->unk_11fa); + ptr = StringCopy(ptr, stringLength); + } + break; + + case PC_TEXT_FMT_MON_NAME_AFTER_EXCL_MARK: + // "Bye-bye, ".substr(0, -1) + {var} + "Bye-bye, !".substr(-1, 1) + { + const u8 *stringLength; + const u8 *text; + + text = gPCStorageActionTexts[index].text; + stringLength = &text[StringLength(text)] - 1; + + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPCStorageActionTexts[index].text); + ptr = StringCopy(ptr - 1, gPokemonStorageSystemPtr->unk_26e4); + ptr = StringCopy(ptr, stringLength); + } + break; + + case PC_TEXT_FMT_NORMAL: + default: + ptr = StringCopy(gPokemonStorageSystemPtr->unk_2694, gPCStorageActionTexts[index].text); + break; + } + + while (ptr < gPokemonStorageSystemPtr->unk_26a6) + { + ptr[0] = CHAR_SPACE; + ptr++; + } + + ptr[0] = EOS; + Menu_PrintText(gPokemonStorageSystemPtr->unk_2694, 11, 17); +} + +const struct OamData gOamData_83B6EAC = { + .size = 3 +}; + +const struct OamData gOamData_83B6EB4 = { + .shape = ST_OAM_H_RECTANGLE +}; + +const union AnimCmd gSpriteAnim_83B6EBC[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +const union AnimCmd gSpriteAnim_83B6EC4[] = { + ANIMCMD_FRAME(2, 8), + ANIMCMD_FRAME(4, 8), + ANIMCMD_FRAME(6, 8), + ANIMCMD_JUMP(0) +}; + +const union AnimCmd gSpriteAnim_83B6ED4[] = { + ANIMCMD_FRAME(8, 5), + ANIMCMD_END +}; + +const union AnimCmd gSpriteAnim_83B6EDC[] = { + ANIMCMD_FRAME(10, 8), + ANIMCMD_FRAME( 4, 8), + ANIMCMD_FRAME(12, 8), + ANIMCMD_JUMP(0) +}; + +const union AnimCmd *const gSpriteAnimTable_83B6EEC[] = { + gSpriteAnim_83B6EBC, + gSpriteAnim_83B6EC4, + gSpriteAnim_83B6ED4, + gSpriteAnim_83B6EDC +}; + +const struct SpriteTemplate gSpriteTemplate_83B6EFC = { + 0x0005, + 0xdacd, + &gOamData_83B6EB4, + gSpriteAnimTable_83B6EEC, + NULL, + gDummySpriteAffineAnimTable, + SpriteCallbackDummy +}; + +void sub_8098A38(s8 a0) +{ + DisplayYesNoMenu(23, 10, 0); + Menu_MoveCursor(a0); +} + +void sub_8098A5C(void) +{ + Menu_DestroyCursor(); + Menu_EraseWindowRect(10, 16, 29, 19); + Menu_EraseWindowRect(23, 10, 29, 15); +} + +void sub_8098A80(void) +{ + sub_809CDCC(); + sub_809CDEC(12); + sub_809CDEC(13); + sub_809CDEC(14); + sub_809CDEC(15); + sub_809CE84(); +} + +void sub_8098AA8(u8 a0) +{ + sub_809CDCC(); + switch (a0) + { + case 0: + sub_809CDEC(16); + sub_809CDEC(17); + sub_809CDEC(18); + sub_809CDEC(19); + break; + case 1: + sub_809CDEC(20); + sub_809CDEC(21); + sub_809CDEC(22); + sub_809CDEC(23); + break; + case 2: + sub_809CDEC(24); + sub_809CDEC(25); + sub_809CDEC(26); + sub_809CDEC(27); + break; + case 3: + sub_809CDEC(28); + sub_809CDEC(29); + sub_809CDEC(30); + sub_809CDEC(31); + break; + } + sub_809CE84(); +} diff --git a/src/pokemon/pokemon_storage_system_3.c b/src/pokemon/pokemon_storage_system_3.c new file mode 100644 index 000000000..da26c6fc5 --- /dev/null +++ b/src/pokemon/pokemon_storage_system_3.c @@ -0,0 +1,655 @@ + +// Includes +#include "global.h" +#include "constants/species.h" +#include "sprite.h" +#include "trig.h" +#include "pokemon_icon.h" +#include "pokemon_storage_system.h" + +// Static type declarations + +// Static RAM declarations + +// Static ROM declarations + +static void sub_8098E68(struct Sprite *sprite); +static void sub_8099388(struct Sprite *sprite, u16 a1); +static void sub_80993F4(struct Sprite *sprite); +static void sub_80999C4(struct Sprite *sprite); +static struct Sprite *PSS_SpawnMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 priority, u8 subpriority); +static void PSS_DestroyMonIconSprite(struct Sprite *sprite); + +// .rodata + +const struct OamData gOamData_83B6F2C; + +// .text + +u8 get_preferred_box(void) +{ + return gPokemonStorage.currentBox; +} + +void ResetPSSMonIconSprites(void) +{ + u16 i; + + sub_809D51C(); + for (i = 0; i < 40; i++) + gPokemonStorageSystemPtr->unk_10d0[i] = 0; + for (i = 0; i < 40; i++) + gPokemonStorageSystemPtr->unk_1120[i] = 0; + for (i = 0; i < 6; i++) + gPokemonStorageSystemPtr->unk_1038[i] = NULL; + for (i = 0; i < 30; i++) + gPokemonStorageSystemPtr->unk_1050[i] = NULL; + gPokemonStorageSystemPtr->unk_1034 = NULL; + gPokemonStorageSystemPtr->unk_0d5c = 0; +} + +void sub_8098BF0(void) +{ + u32 personality = GetMonData(&gPokemonStorageSystemPtr->unk_25b4, MON_DATA_PERSONALITY); + gPokemonStorageSystemPtr->unk_1034 = PSS_SpawnMonIconSprite(GetMonData(&gPokemonStorageSystemPtr->unk_25b4, MON_DATA_SPECIES2), personality, 0, 0, 1, 7); + gPokemonStorageSystemPtr->unk_1034->callback = sub_80999C4; +} + +void SpawnBoxIconSprites(u8 boxId) +{ + struct BoxPokemon *box = gPokemonStorage.boxes[boxId]; + u16 i; + u16 k = 0; + for (i = 0; i < 5; i++) + { + u16 j; + for (j = 0; j < 6; j++) + { + u16 species = GetBoxMonData(box, MON_DATA_SPECIES2); + if (species != SPECIES_NONE) + gPokemonStorageSystemPtr->unk_1050[k] = PSS_SpawnMonIconSprite(species, GetBoxMonData(box, MON_DATA_PERSONALITY), 24 * j + 0x64, 24 * i + 0x2c, 2, 18 - j); + else + gPokemonStorageSystemPtr->unk_1050[k] = NULL; + box++; + k++; + } + } +} + +void sub_8098D20(u8 monId) +{ + struct BoxPokemon *mon = gPokemonStorage.boxes[get_preferred_box()] + monId; + u16 species = GetBoxMonData(mon, MON_DATA_SPECIES2); + if (species != SPECIES_NONE) + { + s16 x = 24 * (monId % 6) + 0x64; + s16 y = 24 * (monId / 6) + 0x2c; + gPokemonStorageSystemPtr->unk_1050[monId] = PSS_SpawnMonIconSprite(species, GetBoxMonData(mon, MON_DATA_PERSONALITY), x, y, 2, 18 - (monId % 6)); + } +} + +static void sub_8098DE0(s16 a0) +{ + u16 monId; + for (monId = 0; monId < 30; monId++) + { + if (gPokemonStorageSystemPtr->unk_1050[monId]) + { + gPokemonStorageSystemPtr->unk_1050[monId]->data[2] = a0; + gPokemonStorageSystemPtr->unk_1050[monId]->data[4] = 1; + gPokemonStorageSystemPtr->unk_1050[monId]->callback = sub_8098E68; + } + } +} + +static void sub_8098E24(struct Sprite *sprite) +{ + if (sprite->data[1] != 0) + { + sprite->data[1]--; + sprite->pos1.x += sprite->data[2]; + } + else + { + gPokemonStorageSystemPtr->unk_1178--; + sprite->pos1.x = sprite->data[3]; + sprite->callback = SpriteCallbackDummy; + } +} + +static void sub_8098E68(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] < 0x45 || sprite->data[5] > 0xfb) + sprite->callback = SpriteCallbackDummy; + } +} + +static void sub_8098EA0(u8 col) +{ + u16 i; + + for (i = 0; i < 5; i++) + { + if (gPokemonStorageSystemPtr->unk_1050[col]) + { + PSS_DestroyMonIconSprite(gPokemonStorageSystemPtr->unk_1050[col]); + gPokemonStorageSystemPtr->unk_1050[col] = NULL; + } + col += 6; + } +} + +static u8 sub_8098EE0(u8 col, u16 a1, s16 a2) +{ + u16 i; + u16 x; + u16 y; + u8 count; + u8 x1; + u16 curX; + + y = 0x2c; + x = 24 * col + 0x64; + curX = x - (a1 + 1) * a2; + x1 = 18 - col; + count = 0; + + for (i = 0; i < 5; i++) + { + u16 species = GetBoxMonData(gPokemonStorage.boxes[gPokemonStorageSystemPtr->unk_117d] + col, MON_DATA_SPECIES2); + if (species != SPECIES_NONE) + { + gPokemonStorageSystemPtr->unk_1050[col] = PSS_SpawnMonIconSprite(species, GetBoxMonData(gPokemonStorage.boxes[gPokemonStorageSystemPtr->unk_117d] + col, MON_DATA_PERSONALITY), curX, y, 2, x1); + if (gPokemonStorageSystemPtr->unk_1050[col]) + { + gPokemonStorageSystemPtr->unk_1050[col]->data[1] = a1; + gPokemonStorageSystemPtr->unk_1050[col]->data[2] = a2; + gPokemonStorageSystemPtr->unk_1050[col]->data[3] = x; + gPokemonStorageSystemPtr->unk_1050[col]->callback = sub_8098E24; + count++; + } + } + col += 6; + y += 24; + } + return count; +} + +void sub_809900C(u8 a0, s8 a1) +{ + gPokemonStorageSystemPtr->unk_117c = 0; + gPokemonStorageSystemPtr->unk_117d = a0; + gPokemonStorageSystemPtr->unk_117b = a1; + gPokemonStorageSystemPtr->unk_1172 = 32; + gPokemonStorageSystemPtr->unk_1176 = -6 * a1; + gPokemonStorageSystemPtr->unk_1178 = 0; + if (a1 > 0) + gPokemonStorageSystemPtr->unk_117a = 0; + else + gPokemonStorageSystemPtr->unk_117a = 5; + gPokemonStorageSystemPtr->unk_1174 = 24 * gPokemonStorageSystemPtr->unk_117a + 0x64; + sub_8098DE0(gPokemonStorageSystemPtr->unk_1176); +} + +bool8 sub_80990AC(void) +{ + if (gPokemonStorageSystemPtr->unk_1172) + gPokemonStorageSystemPtr->unk_1172--; + switch (gPokemonStorageSystemPtr->unk_117c) + { + case 0: + gPokemonStorageSystemPtr->unk_1174 += gPokemonStorageSystemPtr->unk_1176; + if (gPokemonStorageSystemPtr->unk_1174 < 0x41 || gPokemonStorageSystemPtr->unk_1174 > 0xfb) + { + sub_8098EA0(gPokemonStorageSystemPtr->unk_117a); + gPokemonStorageSystemPtr->unk_1174 += 24 * gPokemonStorageSystemPtr->unk_117b; + gPokemonStorageSystemPtr->unk_117c++; + } + break; + case 1: + gPokemonStorageSystemPtr->unk_1174 += gPokemonStorageSystemPtr->unk_1176; + gPokemonStorageSystemPtr->unk_1178 += sub_8098EE0(gPokemonStorageSystemPtr->unk_117a, gPokemonStorageSystemPtr->unk_1172, gPokemonStorageSystemPtr->unk_1176); + if ((gPokemonStorageSystemPtr->unk_117b > 0 && gPokemonStorageSystemPtr->unk_117a == 5) || (gPokemonStorageSystemPtr->unk_117b < 0 && gPokemonStorageSystemPtr->unk_117a == 0)) + { + gPokemonStorageSystemPtr->unk_117c++; + } + else + { + gPokemonStorageSystemPtr->unk_117a += gPokemonStorageSystemPtr->unk_117b; + gPokemonStorageSystemPtr->unk_117c = 0; + } + break; + case 2: + if (gPokemonStorageSystemPtr->unk_1178 == 0) + { + gPokemonStorageSystemPtr->unk_1172++; + return FALSE; + } + break; + default: + return FALSE; + } + return TRUE; +} + +void sub_8099200(bool8 a0) +{ + u16 count; + u16 i; + u16 species = GetMonData(gPlayerParty + 0, MON_DATA_SPECIES2); + u32 personality = GetMonData(gPlayerParty + 0, MON_DATA_PERSONALITY); + gPokemonStorageSystemPtr->unk_1038[0] = PSS_SpawnMonIconSprite(species, personality, 0x68, 0x40, 1, 11); + 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); + gPokemonStorageSystemPtr->unk_1038[i] = PSS_SpawnMonIconSprite(species, personality, 0x98, (i - 1) * 24 + 0x10, 1, 11); + count++; + } + else + { + gPokemonStorageSystemPtr->unk_1038[i] = NULL; + } + } + if (!a0) + { + for (i = 0; i < count; i++) + { + // this routine assumes party_compaction has been called + gPokemonStorageSystemPtr->unk_1038[i]->pos1.y -= 0xa0; + gPokemonStorageSystemPtr->unk_1038[i]->invisible = TRUE; + } + } +} + +void sub_8099310(void) +{ + u16 i; + u16 count; + + gPokemonStorageSystemPtr->unk_1171 = 0; + for (i = 0, count = 0; i < PARTY_SIZE; i++) + { + if (gPokemonStorageSystemPtr->unk_1038[i]) + { + if (i != count) + { + sub_8099388(gPokemonStorageSystemPtr->unk_1038[i], count); + gPokemonStorageSystemPtr->unk_1038[i] = NULL; + gPokemonStorageSystemPtr->unk_1171++; + } + count++; + } + } +} + +u8 sub_8099374(void) +{ + return gPokemonStorageSystemPtr->unk_1171; +} + +static void sub_8099388(struct Sprite *sprite, u16 a1) +{ + s16 r3; + s16 r4; + + sprite->data[1] = a1; + if (a1 == 0) + { + r3 = 0x68; + r4 = 0x40; + } + else + { + r3 = 0x98; + r4 = 24 * (a1 - 1) + 0x10; + } + sprite->data[2] = sprite->pos1.x << 3; + sprite->data[3] = sprite->pos1.y << 3; + sprite->data[4] = (r3 * 8 - sprite->data[2]) / 8; + sprite->data[5] = (r4 * 8 - sprite->data[3]) / 8; + sprite->data[6] = 8; + sprite->callback = sub_80993F4; +} + +static void sub_80993F4(struct Sprite *sprite) +{ + if (sprite->data[6]) + { + sprite->data[2] += sprite->data[4]; + sprite->data[3] += sprite->data[5]; + sprite->pos1.x = sprite->data[2] >> 3; + sprite->pos1.y = sprite->data[3] >> 3; + sprite->data[6]--; + } + else + { + if (sprite->data[1] == 0) + { + sprite->pos1.x = 0x68; + sprite->pos1.y = 0x40; + } + else + { + sprite->pos1.x = 0x98; + sprite->pos1.y = (sprite->data[1] - 1) * 24 + 0x10; + } + sprite->callback = SpriteCallbackDummy; + gPokemonStorageSystemPtr->unk_1038[sprite->data[1]] = sprite; + gPokemonStorageSystemPtr->unk_1171--; + } +} + +void sub_8099480(void) +{ + if (gPokemonStorageSystemPtr->unk_1034) + { + PSS_DestroyMonIconSprite(gPokemonStorageSystemPtr->unk_1034); + gPokemonStorageSystemPtr->unk_1034 = NULL; + } +} + +void sub_80994A8(s16 y) +{ + u16 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (gPokemonStorageSystemPtr->unk_1038[i]) + { + s16 yy; + gPokemonStorageSystemPtr->unk_1038[i]->pos1.y += y; + yy = gPokemonStorageSystemPtr->unk_1038[i]->pos1.y + gPokemonStorageSystemPtr->unk_1038[i]->pos2.y + gPokemonStorageSystemPtr->unk_1038[i]->centerToCornerVecY; + if (yy < -0x10 || yy > 0xb0) + gPokemonStorageSystemPtr->unk_1038[i]->invisible = TRUE; + else + gPokemonStorageSystemPtr->unk_1038[i]->invisible = FALSE; + } + } +} + +void sub_8099520(u8 a0) +{ + if (gPokemonStorageSystemPtr->unk_1038[a0]) + { + PSS_DestroyMonIconSprite(gPokemonStorageSystemPtr->unk_1038[a0]); + gPokemonStorageSystemPtr->unk_1038[a0] = NULL; + } +} + +void sub_809954C(void) +{ + u16 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (gPokemonStorageSystemPtr->unk_1038[i]) + { + PSS_DestroyMonIconSprite(gPokemonStorageSystemPtr->unk_1038[i]); + gPokemonStorageSystemPtr->unk_1038[i] = NULL; + } + } +} + +void sub_8099584(u8 a0, u8 a1) +{ + if (a0 == 0) + { + gPokemonStorageSystemPtr->unk_1034 = gPokemonStorageSystemPtr->unk_1038[a1]; + gPokemonStorageSystemPtr->unk_1038[a1] = NULL; + } + else if (a0 == 1) + { + gPokemonStorageSystemPtr->unk_1034 = gPokemonStorageSystemPtr->unk_1050[a1]; + gPokemonStorageSystemPtr->unk_1050[a1] = NULL; + } + else + { + return; + } + gPokemonStorageSystemPtr->unk_1034->callback = sub_80999C4; + gPokemonStorageSystemPtr->unk_1034->oam.priority = 1; + gPokemonStorageSystemPtr->unk_1034->subpriority = 7; +} + +void sub_809960C(u8 a0, u8 a1) +{ + if (a0 == 14) + { + gPokemonStorageSystemPtr->unk_1038[a1] = gPokemonStorageSystemPtr->unk_1034; + gPokemonStorageSystemPtr->unk_1038[a1]->oam.priority = 1; + gPokemonStorageSystemPtr->unk_1038[a1]->subpriority = 11; + } + else + { + gPokemonStorageSystemPtr->unk_1050[a1] = gPokemonStorageSystemPtr->unk_1034; + gPokemonStorageSystemPtr->unk_1050[a1]->oam.priority = 2; + gPokemonStorageSystemPtr->unk_1050[a1]->subpriority = 18 - (a1 % 6); + } + gPokemonStorageSystemPtr->unk_1034->callback = SpriteCallbackDummy; + gPokemonStorageSystemPtr->unk_1034 = NULL; +} + +void sub_80996B0(u8 a0, u8 a1) +{ + if (a0 == 14) + gPokemonStorageSystemPtr->unk_10c8 = gPokemonStorageSystemPtr->unk_1038 + a1; + else + gPokemonStorageSystemPtr->unk_10c8 = gPokemonStorageSystemPtr->unk_1050 + a1; + gPokemonStorageSystemPtr->unk_1034->callback = SpriteCallbackDummy; + gPokemonStorageSystemPtr->unk_1170 = 0; +} + +bool8 sub_809971C(void) +{ + if (gPokemonStorageSystemPtr->unk_1170 == 16) + return FALSE; + gPokemonStorageSystemPtr->unk_1170++; + if (gPokemonStorageSystemPtr->unk_1170 & 1) + { + (*gPokemonStorageSystemPtr->unk_10c8)->pos1.y--; + gPokemonStorageSystemPtr->unk_1034->pos1.y++; + } + (*gPokemonStorageSystemPtr->unk_10c8)->pos2.x = gSineTable[gPokemonStorageSystemPtr->unk_1170 * 8] / 16; + gPokemonStorageSystemPtr->unk_1034->pos2.x = -(gSineTable[gPokemonStorageSystemPtr->unk_1170 * 8] / 16); + if (gPokemonStorageSystemPtr->unk_1170 == 8) + { + gPokemonStorageSystemPtr->unk_1034->oam.priority = (*gPokemonStorageSystemPtr->unk_10c8)->oam.priority; + gPokemonStorageSystemPtr->unk_1034->subpriority = (*gPokemonStorageSystemPtr->unk_10c8)->subpriority; + (*gPokemonStorageSystemPtr->unk_10c8)->oam.priority = 1; + (*gPokemonStorageSystemPtr->unk_10c8)->subpriority = 7; + } + if (gPokemonStorageSystemPtr->unk_1170 == 16) + { + struct Sprite *sprite = gPokemonStorageSystemPtr->unk_1034; + gPokemonStorageSystemPtr->unk_1034 = *(gPokemonStorageSystemPtr->unk_10c8); + (*gPokemonStorageSystemPtr->unk_10c8) = sprite; + gPokemonStorageSystemPtr->unk_1034->callback = sub_80999C4; + (*gPokemonStorageSystemPtr->unk_10c8)->callback = SpriteCallbackDummy; + } + return TRUE; +} + +const union AffineAnimCmd *const gSpriteAffineAnimTable_83B6F5C[]; + +void sub_809981C(u8 mode, u8 idx) +{ + switch (mode) + { + case 0: + gPokemonStorageSystemPtr->unk_10cc = gPokemonStorageSystemPtr->unk_1038 + idx; + break; + case 1: + gPokemonStorageSystemPtr->unk_10cc = gPokemonStorageSystemPtr->unk_1050 + idx; + break; + case 2: + gPokemonStorageSystemPtr->unk_10cc = &gPokemonStorageSystemPtr->unk_1034; + break; + default: + return; + } + if (*gPokemonStorageSystemPtr->unk_10cc) + { + InitSpriteAffineAnim(*gPokemonStorageSystemPtr->unk_10cc); + (*gPokemonStorageSystemPtr->unk_10cc)->oam.affineMode = ST_OAM_AFFINE_NORMAL; + (*gPokemonStorageSystemPtr->unk_10cc)->affineAnims = gSpriteAffineAnimTable_83B6F5C; + StartSpriteAffineAnim(*gPokemonStorageSystemPtr->unk_10cc, 0); + } +} + +bool8 sub_80998D8(void) +{ + if (*gPokemonStorageSystemPtr->unk_10cc == NULL || (*gPokemonStorageSystemPtr->unk_10cc)->invisible) + return FALSE; + if ((*gPokemonStorageSystemPtr->unk_10cc)->affineAnimEnded) + { + (*gPokemonStorageSystemPtr->unk_10cc)->invisible = TRUE; + } + return TRUE; +} + +void sub_8099920(void) +{ + if (*gPokemonStorageSystemPtr->unk_10cc) + { + FreeOamMatrix((*gPokemonStorageSystemPtr->unk_10cc)->oam.matrixNum); + PSS_DestroyMonIconSprite(*gPokemonStorageSystemPtr->unk_10cc); + *gPokemonStorageSystemPtr->unk_10cc = NULL; + } +} + +void sub_8099958(void) +{ + if (*gPokemonStorageSystemPtr->unk_10cc) + { + (*gPokemonStorageSystemPtr->unk_10cc)->invisible = FALSE; + StartSpriteAffineAnim(*gPokemonStorageSystemPtr->unk_10cc, 1); + } +} + +bool8 sub_8099990(void) +{ + if (gPokemonStorageSystemPtr->unk_10cc == NULL) + return FALSE; + if ((*gPokemonStorageSystemPtr->unk_10cc)->affineAnimEnded) + gPokemonStorageSystemPtr->unk_10cc = NULL; + return TRUE; +} + +static void sub_80999C4(struct Sprite *sprite) +{ + sprite->pos1.x = gPokemonStorageSystemPtr->unk_11c0->pos1.x; + sprite->pos1.y = gPokemonStorageSystemPtr->unk_11c0->pos1.y + gPokemonStorageSystemPtr->unk_11c0->pos2.y + 4; +} + +static u16 PSS_LoadSpeciesIconGfx(u16 a0) +{ + u16 i; + u16 retval; + + for (i = 0; i < 40; i++) + { + if (gPokemonStorageSystemPtr->unk_1120[i] == a0) + break; + } + if (i == 40) + { + for (i = 0; i < 40; i++) + { + if (gPokemonStorageSystemPtr->unk_1120[i] == 0) + break; + } + } + if (i != 40) + { + gPokemonStorageSystemPtr->unk_1120[i] = a0; + gPokemonStorageSystemPtr->unk_10d0[i]++; + retval = i * 16; + CpuCopy32(gMonIconTable[a0], BG_CHAR_ADDR(4) + 32 * retval, 0x200); + return retval; + } + return 0xFFFF; +} + +static void PSS_ForgetSpeciesIcon(u16 a0) +{ + u16 i; + + for (i = 0; i < 40; i++) + { + if (gPokemonStorageSystemPtr->unk_1120[i] == a0) + { + if (--gPokemonStorageSystemPtr->unk_10d0[i] == 0) + gPokemonStorageSystemPtr->unk_1120[i] = 0; + break; + } + } +} + +static struct Sprite *PSS_SpawnMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 priority, u8 subpriority) +{ + struct SpriteTemplate template = { + 0x000f, + 0xdac0, + &gOamData_83B6F2C, + gDummySpriteAnimTable, + NULL, + gDummySpriteAffineAnimTable, + SpriteCallbackDummy + }; + u16 tileNum; + u8 spriteId; + + species = mon_icon_convert_unown_species_id(species, personality); + template.paletteTag = 0xdac0 + gMonIconPaletteIndices[species]; + tileNum = PSS_LoadSpeciesIconGfx(species); + if (tileNum == 0xFFFF) + return NULL; + spriteId = CreateSprite(&template, x, y, subpriority); + if (spriteId == MAX_SPRITES) + { + PSS_ForgetSpeciesIcon(species); + return NULL; + } + gSprites[spriteId].oam.tileNum = tileNum; + gSprites[spriteId].oam.priority = priority; + gSprites[spriteId].data[0] = species; + return gSprites + spriteId; +} + +static void PSS_DestroyMonIconSprite(struct Sprite *sprite) +{ + PSS_ForgetSpeciesIcon(sprite->data[0]); + DestroySprite(sprite); +} + +const struct OamData gOamData_83B6F2C = { + .size = 2 +}; + +const union AffineAnimCmd gSpriteAffineAnim_83B6F34[] = { + AFFINEANIMCMD_FRAME(-2, -2, 0, 120), + AFFINEANIMCMD_END +}; + +const union AffineAnimCmd gSpriteAffineAnim_83B6F44[] = { + AFFINEANIMCMD_FRAME(16, 16, 0, 0), + AFFINEANIMCMD_FRAME(16, 16, 0, 15), + AFFINEANIMCMD_END +}; + +const union AffineAnimCmd *const gSpriteAffineAnimTable_83B6F5C[] = { + gSpriteAffineAnim_83B6F34, + gSpriteAffineAnim_83B6F44 +}; diff --git a/src/pokemon/pokemon_storage_system_4.c b/src/pokemon/pokemon_storage_system_4.c new file mode 100644 index 000000000..1cc9f7e3b --- /dev/null +++ b/src/pokemon/pokemon_storage_system_4.c @@ -0,0 +1,2844 @@ + +// Includes +#include "global.h" +#include "ewram.h" +#include "data2.h" +#include "constants/moves.h" +#include "constants/species.h" +#include "palette.h" +#include "string_util.h" +#include "text.h" +#include "menu.h" +#include "item.h" +#include "pokemon_summary_screen.h" +#include "pokemon_storage_system.h" + +// Static type declarations + +struct WallpaperTable { + const u8 *tiles; + u32 size; + const u8 *tileMap; + const u16 *palettes; +}; + +// Static RAM declarations + +EWRAM_DATA struct Pokemon gUnknown_02038480 = {}; +EWRAM_DATA s8 gUnknown_020384E4 = 0; +EWRAM_DATA s8 gUnknown_020384E5 = 0; +EWRAM_DATA bool8 gUnknown_020384E6 = FALSE; +EWRAM_DATA u8 gUnknown_020384E7 = 0; +EWRAM_DATA u8 gUnknown_020384E8 = 0; +EWRAM_DATA u8 gUnknown_020384E9 = 0; +EWRAM_DATA u8 gUnknown_020384EA = 0; + +// Static ROM declarations + +void sub_809900C(u8 boxId, s8 a1); +s8 sub_8099D90(u8 boxId); +void sub_8099EB0(u8 boxId, s8 a1); +void sub_8099F58(u16 *vdest, const u16 *src, s8 a2, u8 a3); +void sub_809A14C(u16 *vdest); +void sub_809A23C(u8 boxId); +void sub_809A3D0(u8 boxId, s8 a1); +void sub_809A598(void); +void sub_809A5E8(struct Sprite *sprite); +void sub_809A61C(struct Sprite *sprite); +void sub_809A654(void); +s16 sub_809A6D0(u8 width); +void sub_809A6DC(void); +void sub_809A774(s8 a0); +void sub_809A810(void); +void sub_809AFB8(void); +void sub_809A8C8(struct Sprite *sprite); +bool8 sub_809B150(void); +bool8 sub_809B1D8(void); +bool8 sub_809B24C(void); +bool8 sub_809B324(void); +bool8 sub_809B358(void); +void sub_809B384(void); +void sub_809B3E0(void); +void sub_809B44C(u8 a0, u8 a1); +void diegohint2(u8 a0, u8 a1); +void sub_809B548(u8 a0, u8 a1); +void diegohint1(u8 a0, u8 a1); +bool8 sub_809BF2C(void); +void sub_809BF74(void); +void sub_809C028(void); +void sub_809C04C(void *pokemon, u8 a1); +bool8 sub_809CAB0(void); +void sub_809CC04(void); +void sub_809CD88(void); +s8 sub_809CE4C(u8 a0); + +// .rodata + +const u16 gWallpaperPalettes_Forest[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Forest_2[] = INCBIN_U16("graphics/pokemon_storage/forest_frame.gbapal"); +const u16 gWallpaperPalettes_Forest_2_3[] = INCBIN_U16("graphics/pokemon_storage/forest_bg.gbapal"); + +const u8 gWallpaperTiles_Forest[] = INCBIN_U8("graphics/pokemon_storage/forest.4bpp.lz"); + +const u8 gWallpaperTilemap_Forest[] = INCBIN_U8("graphics/pokemon_storage/forest.bin.lz"); + +const u16 gWallpaperPalettes_City[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_City_2[] = INCBIN_U16("graphics/pokemon_storage/city_frame.gbapal"); +const u16 gWallpaperPalettes_City_2_3[] = INCBIN_U16("graphics/pokemon_storage/city_bg.gbapal"); + +const u8 gWallpaperTiles_City[] = INCBIN_U8("graphics/pokemon_storage/city.4bpp.lz"); + +const u8 gWallpaperTilemap_City[] = INCBIN_U8("graphics/pokemon_storage/city.bin.lz"); + +const u16 gWallpaperPalettes_Desert[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Desert_2[] = INCBIN_U16("graphics/pokemon_storage/desert_frame.gbapal"); +const u16 gWallpaperPalettes_Desert_2_3[] = INCBIN_U16("graphics/pokemon_storage/desert_bg.gbapal"); + +const u8 gWallpaperTiles_Desert[] = INCBIN_U8("graphics/pokemon_storage/desert.4bpp.lz"); + +const u8 gWallpaperTilemap_Desert[] = INCBIN_U8("graphics/pokemon_storage/desert.bin.lz"); + +const u16 gWallpaperPalettes_Savanna[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Savanna_2[] = INCBIN_U16("graphics/pokemon_storage/savanna_frame.gbapal"); +const u16 gWallpaperPalettes_Savanna_2_3[] = INCBIN_U16("graphics/pokemon_storage/savanna_bg.gbapal"); + +const u8 gWallpaperTiles_Savanna[] = INCBIN_U8("graphics/pokemon_storage/savanna.4bpp.lz"); + +const u8 gWallpaperTilemap_Savanna[] = INCBIN_U8("graphics/pokemon_storage/savanna.bin.lz"); + +const u16 gWallpaperPalettes_Crag[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Crag_2[] = INCBIN_U16("graphics/pokemon_storage/crag_frame.gbapal"); +const u16 gWallpaperPalettes_Crag_2_3[] = INCBIN_U16("graphics/pokemon_storage/crag_bg.gbapal"); + +const u8 gWallpaperTiles_Crag[] = INCBIN_U8("graphics/pokemon_storage/crag.4bpp.lz"); + +const u8 gWallpaperTilemap_Crag[] = INCBIN_U8("graphics/pokemon_storage/crag.bin.lz"); + +const u16 gWallpaperPalettes_Volcano[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Volcano_2[] = INCBIN_U16("graphics/pokemon_storage/volcano_frame.gbapal"); +const u16 gWallpaperPalettes_Volcano_2_3[] = INCBIN_U16("graphics/pokemon_storage/volcano_bg.gbapal"); + +const u8 gWallpaperTiles_Volcano[] = INCBIN_U8("graphics/pokemon_storage/volcano.4bpp.lz"); +const u32 filler_83b871c = 0; // needed to match but otherwise garbage + +const u8 gWallpaperTilemap_Volcano[] = INCBIN_U8("graphics/pokemon_storage/volcano.bin.lz"); + +const u16 gWallpaperPalettes_Snow[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Snow_2[] = INCBIN_U16("graphics/pokemon_storage/snow_frame.gbapal"); +const u16 gWallpaperPalettes_Snow_2_3[] = INCBIN_U16("graphics/pokemon_storage/snow_bg.gbapal"); + +const u8 gWallpaperTiles_Snow[] = INCBIN_U8("graphics/pokemon_storage/snow.4bpp.lz"); + +const u8 gWallpaperTilemap_Snow[] = INCBIN_U8("graphics/pokemon_storage/snow.bin.lz"); + +const u16 gWallpaperPalettes_Cave[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Cave_2[] = INCBIN_U16("graphics/pokemon_storage/cave_frame.gbapal"); +const u16 gWallpaperPalettes_Cave_2_3[] = INCBIN_U16("graphics/pokemon_storage/cave_bg.gbapal"); + +const u8 gWallpaperTiles_Cave[] = INCBIN_U8("graphics/pokemon_storage/cave.4bpp.lz"); + +const u8 gWallpaperTilemap_Cave[] = INCBIN_U8("graphics/pokemon_storage/cave.bin.lz"); + +const u16 gWallpaperPalettes_Beach[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Beach_2[] = INCBIN_U16("graphics/pokemon_storage/beach_frame.gbapal"); +const u16 gWallpaperPalettes_Beach_2_3[] = INCBIN_U16("graphics/pokemon_storage/beach_bg.gbapal"); + +const u8 gWallpaperTiles_Beach[] = INCBIN_U8("graphics/pokemon_storage/beach.4bpp.lz"); + +const u8 gWallpaperTilemap_Beach[] = INCBIN_U8("graphics/pokemon_storage/beach.bin.lz"); + +const u16 gWallpaperPalettes_Seafloor[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Seafloor_2[] = INCBIN_U16("graphics/pokemon_storage/seafloor_frame.gbapal"); +const u16 gWallpaperPalettes_Seafloor_2_3[] = INCBIN_U16("graphics/pokemon_storage/seafloor_bg.gbapal"); + +const u8 gWallpaperTiles_Seafloor[] = INCBIN_U8("graphics/pokemon_storage/seafloor.4bpp.lz"); + +const u8 gWallpaperTilemap_Seafloor[] = INCBIN_U8("graphics/pokemon_storage/seafloor.bin.lz"); + +const u16 gWallpaperPalettes_River[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_River_2[] = INCBIN_U16("graphics/pokemon_storage/river_frame.gbapal"); +const u16 gWallpaperPalettes_River_2_3[] = INCBIN_U16("graphics/pokemon_storage/river_bg.gbapal"); + +const u8 gWallpaperTiles_River[] = INCBIN_U8("graphics/pokemon_storage/river.4bpp.lz"); + +const u8 gWallpaperTilemap_River[] = INCBIN_U8("graphics/pokemon_storage/river.bin.lz"); + +const u16 gWallpaperPalettes_Sky[] = INCBIN_U16("graphics/pokemon_storage/box_bg1.gbapal"); +const u16 gWallpaperPalettes_Sky_2[] = INCBIN_U16("graphics/pokemon_storage/sky_frame.gbapal"); +const u16 gWallpaperPalettes_Sky_2_3[] = INCBIN_U16("graphics/pokemon_storage/sky_bg.gbapal"); + +const u8 gWallpaperTiles_Sky[] = INCBIN_U8("graphics/pokemon_storage/sky.4bpp.lz"); + +const u8 gWallpaperTilemap_Sky[] = INCBIN_U8("graphics/pokemon_storage/sky.bin.lz"); + +const u16 gWallpaperPalettes_Polkadot[] = INCBIN_U16("graphics/pokemon_storage/box_bg2.gbapal"); +const u16 gWallpaperPalettes_Polkadot_2[] = INCBIN_U16("graphics/pokemon_storage/polkadot_frame.gbapal"); +const u16 gWallpaperPalettes_Polkadot_2_3[] = INCBIN_U16("graphics/pokemon_storage/polkadot_bg.gbapal"); + +const u8 gWallpaperTiles_Polkadot[] = INCBIN_U8("graphics/pokemon_storage/polkadot.4bpp.lz"); + +const u8 gWallpaperTilemap_Polkadot[] = INCBIN_U8("graphics/pokemon_storage/polkadot.bin.lz"); + +const u16 gWallpaperPalettes_Pokecenter[] = INCBIN_U16("graphics/pokemon_storage/box_bg2.gbapal"); +const u16 gWallpaperPalettes_Pokecenter_2[] = INCBIN_U16("graphics/pokemon_storage/pokecenter_frame.gbapal"); +const u16 gWallpaperPalettes_Pokecenter_2_3[] = INCBIN_U16("graphics/pokemon_storage/pokecenter_bg.gbapal"); + +const u8 gWallpaperTiles_Pokecenter[] = INCBIN_U8("graphics/pokemon_storage/pokecenter.4bpp.lz"); + +const u8 gWallpaperTilemap_Pokecenter[] = INCBIN_U8("graphics/pokemon_storage/pokecenter.bin.lz"); + +const u16 gWallpaperPalettes_Machine[] = INCBIN_U16("graphics/pokemon_storage/box_bg3.gbapal"); +const u16 gWallpaperPalettes_Machine_2[] = INCBIN_U16("graphics/pokemon_storage/machine_frame.gbapal"); +const u16 gWallpaperPalettes_Machine_2_3[] = INCBIN_U16("graphics/pokemon_storage/machine_bg.gbapal"); + +const u8 gWallpaperTiles_Machine[] = INCBIN_U8("graphics/pokemon_storage/machine.4bpp.lz"); + +const u8 gWallpaperTilemap_Machine[] = INCBIN_U8("graphics/pokemon_storage/machine.bin.lz"); + +const u16 gWallpaperPalettes_Plain[] = INCBIN_U16("graphics/pokemon_storage/box_bg4.gbapal"); +const u16 gWallpaperPalettes_Plain_2[] = INCBIN_U16("graphics/pokemon_storage/plain_frame.gbapal"); +const u16 gWallpaperPalettes_Plain_2_3[] = INCBIN_U16("graphics/pokemon_storage/plain_bg.gbapal"); + +const u8 gWallpaperTiles_Plain[] = INCBIN_U8("graphics/pokemon_storage/plain.4bpp.lz"); + +const u8 gWallpaperTilemap_Plain[] = INCBIN_U8("graphics/pokemon_storage/plain.bin.lz"); + +const u16 gUnknown_083BAEF8[] = INCBIN_U16("graphics/unused/tilemap_3BAEF8.bin"); + +const u16 gUnknown_083BB0A8[][2] = { + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF}, + {0x1CE7, 0x7FFF} +}; + +const struct WallpaperTable gWallpaperTable[] = { + {gWallpaperTiles_Forest, 0x3D0, gWallpaperTilemap_Forest, gWallpaperPalettes_Forest}, // Forest + {gWallpaperTiles_City, 0x208, gWallpaperTilemap_City, gWallpaperPalettes_City}, // City + {gWallpaperTiles_Desert, 0x2EC, gWallpaperTilemap_Desert, gWallpaperPalettes_Desert}, // Desert + {gWallpaperTiles_Savanna, 0x220, gWallpaperTilemap_Savanna, gWallpaperPalettes_Savanna}, // Savanna + {gWallpaperTiles_Crag, 0x350, gWallpaperTilemap_Crag, gWallpaperPalettes_Crag}, // Crag + {gWallpaperTiles_Volcano, 0x334, gWallpaperTilemap_Volcano, gWallpaperPalettes_Volcano}, // Volcano + {gWallpaperTiles_Snow, 0x2B8, gWallpaperTilemap_Snow, gWallpaperPalettes_Snow}, // Snow + {gWallpaperTiles_Cave, 0x344, gWallpaperTilemap_Cave, gWallpaperPalettes_Cave}, // Cave + {gWallpaperTiles_Beach, 0x384, gWallpaperTilemap_Beach, gWallpaperPalettes_Beach}, // Beach + {gWallpaperTiles_Seafloor, 0x2B4, gWallpaperTilemap_Seafloor, gWallpaperPalettes_Seafloor}, // Seafloor + {gWallpaperTiles_River, 0x294, gWallpaperTilemap_River, gWallpaperPalettes_River}, // River + {gWallpaperTiles_Sky, 0x298, gWallpaperTilemap_Sky, gWallpaperPalettes_Sky}, // Sky + {gWallpaperTiles_Polkadot, 0x1FC, gWallpaperTilemap_Polkadot, gWallpaperPalettes_Polkadot}, // Polkadot + {gWallpaperTiles_Pokecenter, 0x3A4, gWallpaperTilemap_Pokecenter, gWallpaperPalettes_Pokecenter}, // Pokecenter + {gWallpaperTiles_Machine, 0x2F0, gWallpaperTilemap_Machine, gWallpaperPalettes_Machine}, // Machine + {gWallpaperTiles_Plain, 0xFC, gWallpaperTilemap_Plain, gWallpaperPalettes_Plain} // Plain +}; + +const u16 PCPal_Arrow[] = INCBIN_U16("graphics/pokemon_storage/arrow.gbapal"); +const u8 PCGfx_Arrow[] = INCBIN_U8("graphics/pokemon_storage/arrow.4bpp"); + +const struct SpriteSheet gUnknown_083BB288 = {PCGfx_Arrow, 0x80, 6}; +const struct SpritePalette gUnknown_083BB290 = {PCPal_Arrow, 0xdacf}; + +const struct OamData gOamData_83BB298 = { + .shape = ST_OAM_H_RECTANGLE, + .size = 2, + .priority = 2 +}; + +const union AnimCmd gSpriteAnim_83BB2A0[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +const union AnimCmd gSpriteAnim_83BB2A8[] = { + ANIMCMD_FRAME(8, 5), + ANIMCMD_END +}; + +const union AnimCmd *const gSpriteAnimTable_83BB2B0[] = { + gSpriteAnim_83BB2A0, + gSpriteAnim_83BB2A8 +}; + +const struct SpriteTemplate gSpriteTemplate_83BB2B8 = { + 3, + 0xdac8, + &gOamData_83BB298, + gSpriteAnimTable_83BB2B0, + NULL, + gDummySpriteAffineAnimTable, + SpriteCallbackDummy +}; + +const struct OamData gOamData_83BB2D0 = { + .shape = ST_OAM_V_RECTANGLE, + .priority = 2 +}; + +const union AnimCmd gSpriteAnim_83BB2D8[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +const union AnimCmd gSpriteAnim_83BB2E0[] = { + ANIMCMD_FRAME(2, 5), + ANIMCMD_END +}; + +const union AnimCmd *const gSpriteAnimTable_83BB2E8[] = { + gSpriteAnim_83BB2D8, + gSpriteAnim_83BB2E0 +}; + +const struct SpriteTemplate gSpriteTemplate_83BB2F0 = { + 6, + 0xdacf, + &gOamData_83BB2D0, + gSpriteAnimTable_83BB2E8, + NULL, + gDummySpriteAffineAnimTable, + sub_809A8C8 +}; + +const u16 HandCursorPalette[] = INCBIN_U16("graphics/pokemon_storage/hand_cursor_pal.bin"); +const u16 HandCursorAltPalette[] = INCBIN_U16("graphics/pokemon_storage/hand_cursor_alt_pal.bin"); +const u8 HandCursorTiles[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor.4bpp"); +const u8 HandCursorShadowTiles[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor_shadow.4bpp"); + +bool8 (*const gUnknown_083BBBC8[])(void) = { + sub_809B150, + sub_809B1D8, + sub_809B24C +}; +// .text + +void sub_8099BF8(u8 boxId) +{ + gPokemonStorageSystemPtr->unk_08ba = FALSE; + gPokemonStorageSystemPtr->unk_08b4 = 0; + DmaFill32(3, 0, BG_SCREEN_ADDR(26), 0x1000); + sub_8099EB0(boxId, 0); + sub_809A23C(boxId); + sub_809A6DC(); + SpawnBoxIconSprites(boxId); + REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(26) | BGCNT_TXT512x256; +} + +void sub_8099C70(u8 whichBox) +{ + s8 r4 = sub_8099D90(whichBox); + sub_8099EB0(whichBox, r4); + gPokemonStorageSystemPtr->unk_08b6 = r4 * 6; + gPokemonStorageSystemPtr->unk_08b8 = 0x20; + gPokemonStorageSystemPtr->unk_08bb = whichBox; + gPokemonStorageSystemPtr->unk_08bc = r4 > 0 ? 0 : 5; + gPokemonStorageSystemPtr->unk_08be = r4; + gPokemonStorageSystemPtr->unk_08c0 = r4 > 0 ? 0x108 : 0x38; + gPokemonStorageSystemPtr->unk_08c2 = r4 > 0 ? 0 : 5; + gPokemonStorageSystemPtr->unk_08c4 = r4; + gPokemonStorageSystemPtr->unk_08c6 = 0; + gPokemonStorageSystemPtr->unk_08c8 = 2; + sub_809900C(whichBox, r4); + sub_809A3D0(whichBox, r4); + sub_809A774(r4); +} + +bool8 sub_8099D34(void) +{ + bool8 retVal = sub_80990AC(); + if (gPokemonStorageSystemPtr->unk_08b8 != 0) + { + gPokemonStorageSystemPtr->unk_08b4 += gPokemonStorageSystemPtr->unk_08b6; + gPokemonStorageSystemPtr->unk_08b4 &= 0x1ff; + if (--gPokemonStorageSystemPtr->unk_08b8 == 0) + { + sub_809A598(); + sub_809A810(); + } + return TRUE; + } + return retVal; +} + +s8 sub_8099D90(u8 boxId) +{ + u8 curBox = get_preferred_box(); + u8 i; + + for (i = 0; curBox != boxId; i++) + { + if (++curBox >= 14) + curBox = 0; + } + return i <= 6 ? 1 : -1; +} + +void sub_8099DCC(u8 wallpaperId) +{ + u8 curBox = get_preferred_box(); + gPokemonStorage.wallpaper[curBox] = wallpaperId; + gPokemonStorageSystemPtr->unk_1032 = 0; +} + +bool8 sub_8099E08(void) +{ + switch (gPokemonStorageSystemPtr->unk_1032) + { + case 0: + BeginNormalPaletteFade(gPokemonStorageSystemPtr->unk_0d08, 1, 0, 0x10, 0xffff); + gPokemonStorageSystemPtr->unk_1032++; + break; + case 1: + if (!UpdatePaletteFade()) + { + u8 curBox = get_preferred_box(); + sub_8099EB0(curBox, 0); + sub_809A654(); + BeginNormalPaletteFade(gPokemonStorageSystemPtr->unk_0d08, 1, 0x10, 0, 0xffff); + gPokemonStorageSystemPtr->unk_1032++; + } + break; + case 2: + if (!UpdatePaletteFade()) + gPokemonStorageSystemPtr->unk_1032++; + break; + case 3: + return FALSE; + } + return TRUE; +} + +void sub_8099EB0(u8 boxId, s8 a1) +{ + const struct WallpaperTable *wallpaperTable; + + if (a1) + { + gPokemonStorageSystemPtr->unk_08ba = gPokemonStorageSystemPtr->unk_08ba ? FALSE : TRUE; + sub_809A14C(BG_SCREEN_ADDR(26)); + } + wallpaperTable = gWallpaperTable +gPokemonStorage.wallpaper[boxId]; + LoadPalette(wallpaperTable->palettes, gPokemonStorageSystemPtr->unk_08ba * 0x30 + 0x40, 0x60); + LZ77UnCompWram(wallpaperTable->tileMap, gPokemonStorageSystemPtr->unk_0d62); + sub_8099F58(BG_SCREEN_ADDR(26), gPokemonStorageSystemPtr->unk_0d62, a1, gPokemonStorageSystemPtr->unk_08ba); + LZ77UnCompVram(wallpaperTable->tiles, BG_CHAR_ADDR(2) + (gPokemonStorageSystemPtr->unk_08ba << 13)); +} + +#ifdef NONMATCHING +void sub_8099F58(u16 *vdest, const u16 *src, s8 a2, u8 a3) +{ + s16 r6; + s16 r3; + u16 sp0 = a3 << 8; + u16 sp4 = (a3 * 3 + 4) << 12; + u16 *r4; + u16 *r7; + u16 i; + u16 j; + s16 sp8 = ((gPokemonStorageSystemPtr->unk_08b4 >> 3) + 10 + a2 * 24) & 0x3f; + if (sp8 < 13) + { + r6 = 20; + r3 = 0; + r4 = vdest + sp8 + 0x40; + r7 = NULL; + } + else if (sp8 < 32) + { + r6 = 32 - sp8; + r3 = 20 - r6; + r4 = vdest + sp8 + 0x40; + r7 = vdest + 0x440; + } + else if (sp8 < 45) + { + r6 = 20; + r3 = 0; + r4 = vdest + sp8 + 0x420; + r7 = NULL; + } + else + { + r6 = 64 - sp8; + r3 = 20 - r6; + r4 = vdest + sp8 + 0x420; + r7 = vdest + 0x40; + } + for (i = 0; i < 18; i++) + { + for (j = 0; j < r6; j++) + { + u16 tile = ((*src & 0xfff) + sp0) | ((*src & 0xf000) + sp4); + r4[j] = tile; + src++; + } + for (j = 0; j < r3; j++) + { + u16 tile = ((*src & 0xfff) + sp0) | ((*src & 0xf000) + sp4); + r7[j] = tile; + src++; + } + r4 += 0x20; + r7 += 0x20; + } + if (a2) + { + s16 r4_2; + u16 *r2; + if (a2 > 0) + r4_2 = (sp8 + 20) & 0x3f; + else + r4_2 = (sp8 - 4) & 0x3f; + r2 = r4_2 < 0x20 ? vdest + r4_2 + 0x40 : vdest + r4_2 + 0x420; + for (i = 0; i < 4; i++) + { + for (j = 0; j < 18; j++) + { + *r2 = 0; + r2 += 0x20; + } + r4_2++; + r4_2 &= 0x3f; + r2 = r4_2 < 0x20 ? vdest + r4_2 + 0x40 : vdest + r4_2 + 0x420; + } + } +} +#else +__attribute__((naked)) void sub_8099F58(u16 *vdest, const u16 *src, s8 a2, u8 a3) +{ + asm_unified("\tpush {r4-r7,lr}\n" + "\tmov r7, r10\n" + "\tmov r6, r9\n" + "\tmov r5, r8\n" + "\tpush {r5-r7}\n" + "\tsub sp, 0x20\n" + "\tmov r9, r0\n" + "\tadds r5, r1, 0\n" + "\tlsls r2, 24\n" + "\tlsls r3, 24\n" + "\tlsrs r3, 24\n" + "\tlsls r0, r3, 8\n" + "\tstr r0, [sp]\n" + "\tlsls r0, r3, 1\n" + "\tadds r0, r3\n" + "\tadds r0, 0x4\n" + "\tlsls r0, 28\n" + "\tlsrs r0, 16\n" + "\tstr r0, [sp, 0x4]\n" + "\tldr r0, _08099FB8 @ =gPokemonStorageSystemPtr\n" + "\tldr r0, [r0]\n" + "\tldr r1, _08099FBC @ =0x000008b4\n" + "\tadds r0, r1\n" + "\tldrh r1, [r0]\n" + "\tlsrs r1, 3\n" + "\tadds r1, 0xA\n" + "\tlsrs r0, r2, 24\n" + "\tmov r8, r0\n" + "\tasrs r2, 24\n" + "\tlsls r0, r2, 1\n" + "\tadds r0, r2\n" + "\tlsls r0, 3\n" + "\tadds r1, r0\n" + "\tmovs r0, 0x3F\n" + "\tands r1, r0\n" + "\tstr r1, [sp, 0x8]\n" + "\tadds r2, r1, 0\n" + "\tcmp r2, 0xC\n" + "\tbgt _08099FC0\n" + "\tmovs r6, 0x14\n" + "\tmovs r3, 0\n" + "\tlsls r0, r2, 1\n" + "\tadds r0, 0x80\n" + "\tmov r1, r9\n" + "\tadds r4, r1, r0\n" + "\tmovs r7, 0\n" + "\tb _0809A020\n" + "\t.align 2, 0\n" + "_08099FB8: .4byte gPokemonStorageSystemPtr\n" + "_08099FBC: .4byte 0x000008b4\n" + "_08099FC0:\n" + "\tcmp r2, 0x1F\n" + "\tbgt _08099FE6\n" + "\tmovs r0, 0x20\n" + "\tsubs r0, r2\n" + "\tlsls r0, 16\n" + "\tmovs r1, 0x14\n" + "\tlsrs r6, r0, 16\n" + "\tasrs r0, 16\n" + "\tsubs r1, r0\n" + "\tlsls r1, 16\n" + "\tlsrs r3, r1, 16\n" + "\tlsls r0, r2, 1\n" + "\tadds r0, 0x80\n" + "\tmov r2, r9\n" + "\tadds r4, r2, r0\n" + "\tmovs r7, 0x88\n" + "\tlsls r7, 4\n" + "\tadd r7, r9\n" + "\tb _0809A020\n" + "_08099FE6:\n" + "\tcmp r2, 0x2C\n" + "\tbgt _08099FFE\n" + "\tmovs r6, 0x14\n" + "\tmovs r3, 0\n" + "\tlsls r0, r2, 1\n" + "\tmovs r1, 0x84\n" + "\tlsls r1, 4\n" + "\tadds r0, r1\n" + "\tmov r2, r9\n" + "\tadds r4, r2, r0\n" + "\tmovs r7, 0\n" + "\tb _0809A020\n" + "_08099FFE:\n" + "\tmovs r0, 0x40\n" + "\tsubs r0, r2\n" + "\tlsls r0, 16\n" + "\tmovs r1, 0x14\n" + "\tlsrs r6, r0, 16\n" + "\tasrs r0, 16\n" + "\tsubs r1, r0\n" + "\tlsls r1, 16\n" + "\tlsrs r3, r1, 16\n" + "\tlsls r0, r2, 1\n" + "\tmovs r1, 0x84\n" + "\tlsls r1, 4\n" + "\tadds r0, r1\n" + "\tmov r2, r9\n" + "\tadds r4, r2, r0\n" + "\tmov r7, r9\n" + "\tadds r7, 0x80\n" + "_0809A020:\n" + "\tmovs r1, 0\n" + "\tmov r0, r8\n" + "\tlsls r0, 24\n" + "\tstr r0, [sp, 0x14]\n" + "\tlsls r0, r6, 16\n" + "\tasrs r0, 16\n" + "\tmov r8, r0\n" + "\tlsls r3, 16\n" + "\tstr r3, [sp, 0xC]\n" + "\tasrs r2, r3, 16\n" + "\tstr r2, [sp, 0x10]\n" + "_0809A036:\n" + "\tmovs r3, 0\n" + "\tadds r0, r4, 0\n" + "\tadds r0, 0x40\n" + "\tstr r0, [sp, 0x18]\n" + "\tadds r2, r7, 0\n" + "\tadds r2, 0x40\n" + "\tstr r2, [sp, 0x1C]\n" + "\tadds r1, 0x1\n" + "\tmov r10, r1\n" + "\tcmp r3, r8\n" + "\tbge _0809A07A\n" + "\tldr r0, _0809A0D4 @ =0x00000fff\n" + "\tmov r12, r0\n" + "\tmovs r6, 0xF0\n" + "\tlsls r6, 8\n" + "_0809A054:\n" + "\tldrh r2, [r5]\n" + "\tmov r0, r12\n" + "\tands r0, r2\n" + "\tldr r1, [sp]\n" + "\tadds r0, r1, r0\n" + "\tadds r1, r6, 0\n" + "\tands r1, r2\n" + "\tldr r2, [sp, 0x4]\n" + "\tadds r1, r2, r1\n" + "\torrs r1, r0\n" + "\tlsls r0, r3, 1\n" + "\tadds r0, r4\n" + "\tstrh r1, [r0]\n" + "\tadds r5, 0x2\n" + "\tadds r0, r3, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r3, r0, 16\n" + "\tcmp r3, r8\n" + "\tblt _0809A054\n" + "_0809A07A:\n" + "\tmovs r3, 0\n" + "\tldr r0, [sp, 0x10]\n" + "\tcmp r3, r0\n" + "\tbge _0809A0B4\n" + "\tldr r1, _0809A0D4 @ =0x00000fff\n" + "\tmov r12, r1\n" + "\tmovs r6, 0xF0\n" + "\tlsls r6, 8\n" + "\tldr r2, [sp, 0xC]\n" + "\tasrs r4, r2, 16\n" + "_0809A08E:\n" + "\tldrh r2, [r5]\n" + "\tmov r0, r12\n" + "\tands r0, r2\n" + "\tldr r1, [sp]\n" + "\tadds r0, r1, r0\n" + "\tadds r1, r6, 0\n" + "\tands r1, r2\n" + "\tldr r2, [sp, 0x4]\n" + "\tadds r1, r2, r1\n" + "\torrs r1, r0\n" + "\tlsls r0, r3, 1\n" + "\tadds r0, r7\n" + "\tstrh r1, [r0]\n" + "\tadds r5, 0x2\n" + "\tadds r0, r3, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r3, r0, 16\n" + "\tcmp r3, r4\n" + "\tblt _0809A08E\n" + "_0809A0B4:\n" + "\tldr r4, [sp, 0x18]\n" + "\tldr r7, [sp, 0x1C]\n" + "\tmov r1, r10\n" + "\tlsls r0, r1, 16\n" + "\tlsrs r1, r0, 16\n" + "\tcmp r1, 0x11\n" + "\tbls _0809A036\n" + "\tldr r0, [sp, 0x14]\n" + "\tasrs r2, r0, 24\n" + "\tcmp r2, 0\n" + "\tbeq _0809A13A\n" + "\tcmp r2, 0\n" + "\tble _0809A0D8\n" + "\tldr r1, [sp, 0x8]\n" + "\tadds r1, 0x14\n" + "\tb _0809A0DC\n" + "\t.align 2, 0\n" + "_0809A0D4: .4byte 0x00000fff\n" + "_0809A0D8:\n" + "\tldr r1, [sp, 0x8]\n" + "\tsubs r1, 0x4\n" + "_0809A0DC:\n" + "\tmovs r0, 0x3F\n" + "\tands r1, r0\n" + "\tadds r4, r1, 0\n" + "\tadds r0, r4, 0\n" + "\tcmp r0, 0x1F\n" + "\tbgt _0809A0EE\n" + "\tlsls r0, 1\n" + "\tadds r0, 0x80\n" + "\tb _0809A0F6\n" + "_0809A0EE:\n" + "\tlsls r0, 1\n" + "\tmovs r2, 0x84\n" + "\tlsls r2, 4\n" + "\tadds r0, r2\n" + "_0809A0F6:\n" + "\tmov r1, r9\n" + "\tadds r2, r1, r0\n" + "\tmovs r3, 0\n" + "\tmovs r6, 0\n" + "_0809A0FE:\n" + "\tmovs r1, 0\n" + "\tadds r5, r3, 0x1\n" + "\tlsls r3, r4, 16\n" + "_0809A104:\n" + "\tstrh r6, [r2]\n" + "\tadds r2, 0x40\n" + "\tadds r0, r1, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r1, r0, 16\n" + "\tcmp r1, 0x11\n" + "\tbls _0809A104\n" + "\tasrs r0, r3, 16\n" + "\tadds r4, r0, 0x1\n" + "\tmovs r0, 0x3F\n" + "\tands r4, r0\n" + "\tadds r0, r4, 0\n" + "\tcmp r0, 0x1F\n" + "\tbgt _0809A126\n" + "\tlsls r0, 1\n" + "\tadds r0, 0x80\n" + "\tb _0809A12E\n" + "_0809A126:\n" + "\tlsls r0, 1\n" + "\tmovs r2, 0x84\n" + "\tlsls r2, 4\n" + "\tadds r0, r2\n" + "_0809A12E:\n" + "\tmov r1, r9\n" + "\tadds r2, r1, r0\n" + "\tlsls r0, r5, 16\n" + "\tlsrs r3, r0, 16\n" + "\tcmp r3, 0x3\n" + "\tbls _0809A0FE\n" + "_0809A13A:\n" + "\tadd sp, 0x20\n" + "\tpop {r3-r5}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tmov r10, r5\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0"); +} +#endif + +#ifdef NONMATCHING +void sub_809A14C(u16 *vdest) +{ + u16 *r2; + u16 i; + int r3 = ((gPokemonStorageSystemPtr->unk_08b4 >> 3) + 30) & 0x3f; + r2 = vdest + (r3 < 0x20 ? r3 + 0x260 : r3 + 0x640); + for (i = 0; i < 0x2b; i++) + { + *r2++ = 0; + r3++; + r3 &= 0x3f; + if (r3 == 0) + r2 -= 0x420; + if (r3 == 0x20) + r2 += 0x3e0; + } +} +#else +__attribute__((naked)) void sub_809A14C(u16 *vdest) +{ + asm_unified("\tpush {r4-r6,lr}\n" + "\tadds r2, r0, 0\n" + "\tldr r0, _0809A174 @ =gPokemonStorageSystemPtr\n" + "\tldr r0, [r0]\n" + "\tldr r1, _0809A178 @ =0x000008b4\n" + "\tadds r0, r1\n" + "\tldrh r0, [r0]\n" + "\tlsrs r0, 3\n" + "\tadds r3, r0, 0\n" + "\tadds r3, 0x1E\n" + "\tmovs r0, 0x3F\n" + "\tands r3, r0\n" + "\tadds r0, r3, 0\n" + "\tcmp r0, 0x1F\n" + "\tbgt _0809A17C\n" + "\tlsls r0, 1\n" + "\tmovs r6, 0x98\n" + "\tlsls r6, 3\n" + "\tadds r0, r6\n" + "\tb _0809A184\n" + "\t.align 2, 0\n" + "_0809A174: .4byte gPokemonStorageSystemPtr\n" + "_0809A178: .4byte 0x000008b4\n" + "_0809A17C:\n" + "\tlsls r0, 1\n" + "\tmovs r1, 0xC8\n" + "\tlsls r1, 4\n" + "\tadds r0, r1\n" + "_0809A184:\n" + "\tadds r2, r0\n" + "\tmovs r0, 0\n" + "\tmovs r5, 0\n" + "\tmovs r4, 0x3F\n" + "_0809A18C:\n" + "\tstrh r5, [r2]\n" + "\tadds r2, 0x2\n" + "\tadds r3, 0x1\n" + "\tands r3, r4\n" + "\tadds r1, r3, 0\n" + "\tcmp r1, 0\n" + "\tbne _0809A19E\n" + "\tldr r6, _0809A1B8 @ =0xfffff7c0\n" + "\tadds r2, r6\n" + "_0809A19E:\n" + "\tcmp r1, 0x20\n" + "\tbne _0809A1A8\n" + "\tmovs r1, 0xF8\n" + "\tlsls r1, 3\n" + "\tadds r2, r1\n" + "_0809A1A8:\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tcmp r0, 0x2B\n" + "\tbls _0809A18C\n" + "\tpop {r4-r6}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" + "_0809A1B8: .4byte 0xfffff7c0"); +} +#endif + +void sub_809A1BC(const u8 *a0, const u8 *text) +{ + u8 *r5 = gUnknown_083B6DB8; + DmaClear16(3, r5, 0x200); + Text_InitWindow8004E3C(&gWindowTemplate_81E6D38, r5, text); + DmaCopy16(3, r5 + 0x000, a0 + 0x000, 0x80); + DmaCopy16(3, r5 + 0x100, a0 + 0x080, 0x80); + DmaCopy16(3, r5 + 0x080, a0 + 0x100, 0x80); + DmaCopy16(3, r5 + 0x180, a0 + 0x180, 0x80); +} + +const struct SpriteTemplate gSpriteTemplate_83BB2B8; + +void sub_809A23C(u8 boxId) +{ + u8 tagIdx; + s16 r6; + u16 i; + + struct SpriteSheet spriteSheet = {gPokemonStorageSystemPtr->unk_08ca, 0x200, 3}; + struct SpritePalette palettes[] = { + {gPokemonStorageSystemPtr->unk_0ccc, 0xdac8}, + {gPokemonStorageSystemPtr->unk_0ccc, 0xdac9}, + {} + }; + + u16 wallpaper = gPokemonStorage.wallpaper[boxId]; + gPokemonStorageSystemPtr->unk_0ccc[14] = gUnknown_083BB0A8[wallpaper][0]; + gPokemonStorageSystemPtr->unk_0ccc[15] = gUnknown_083BB0A8[wallpaper][1]; + LoadSpritePalettes(palettes); + gPokemonStorageSystemPtr->unk_0d08 = 0x3f0; + tagIdx = IndexOfSpritePaletteTag(0xdac8); + gPokemonStorageSystemPtr->unk_0cec = 0x10e + 16 * tagIdx; + gPokemonStorageSystemPtr->unk_0d08 |= 0x10000 << tagIdx; + tagIdx = IndexOfSpritePaletteTag(0xdac9); + gPokemonStorageSystemPtr->unk_0cee = 0x10e + 16 * tagIdx; + gPokemonStorageSystemPtr->unk_0d08 |= 0x10000 << tagIdx; + sub_809A1BC(gPokemonStorageSystemPtr->unk_08ca, gPokemonStorage.boxNames[boxId]); + LoadSpriteSheet(&spriteSheet); + r6 = sub_809A6D0(sub_8072CA4(gPokemonStorage.boxNames[boxId])); + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&gSpriteTemplate_83BB2B8, r6 + i * 32, 0x1c, 23); + gPokemonStorageSystemPtr->unk_0cf0[i] = gSprites + spriteId; + StartSpriteAnim(gPokemonStorageSystemPtr->unk_0cf0[i], i); + } + gPokemonStorageSystemPtr->unk_0cca = 0; +} + +void sub_809A3D0(u8 boxId, s8 a1) +{ + u16 r8; + s16 x; + s16 x2; + u16 i; + struct SpriteSheet spriteSheet = {gPokemonStorageSystemPtr->unk_08ca, 0x200, 3}; + struct SpriteTemplate template = gSpriteTemplate_83BB2B8; + + gPokemonStorageSystemPtr->unk_0cca = gPokemonStorageSystemPtr->unk_0cca ? FALSE : TRUE; + if (gPokemonStorageSystemPtr->unk_0cca == 0) + { + spriteSheet.tag = 3; + r8 = gPokemonStorageSystemPtr->unk_0cec; + } + else + { + spriteSheet.tag = 4; + r8 = gPokemonStorageSystemPtr->unk_0cec; + template.tileTag = 4; + template.paletteTag = 0xdac9; + } + sub_809A1BC(gPokemonStorageSystemPtr->unk_08ca, gPokemonStorage.boxNames[boxId]); + LoadSpriteSheet(&spriteSheet); + LoadPalette(gUnknown_083BB0A8[gPokemonStorage.wallpaper[boxId]], r8, 0x04); + x = sub_809A6D0(sub_8072CA4(gPokemonStorage.boxNames[boxId])); + x2 = x + a1 * 192; + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&template, i * 32 + x2, 0x1c, 23); + gPokemonStorageSystemPtr->unk_0cf8[i] = gSprites + spriteId; + gPokemonStorageSystemPtr->unk_0cf8[i]->data[0] = (-a1) * 6; + gPokemonStorageSystemPtr->unk_0cf8[i]->data[1] = i * 32 + x; + gPokemonStorageSystemPtr->unk_0cf8[i]->data[2] = 1; + gPokemonStorageSystemPtr->unk_0cf8[i]->callback = sub_809A5E8; + StartSpriteAnim(gPokemonStorageSystemPtr->unk_0cf8[i], i); + gPokemonStorageSystemPtr->unk_0cf0[i]->data[0] = (-a1) * 6; + gPokemonStorageSystemPtr->unk_0cf0[i]->data[1] = 1; + gPokemonStorageSystemPtr->unk_0cf0[i]->callback = sub_809A61C; + } +} + +void sub_809A598(void) +{ + if (gPokemonStorageSystemPtr->unk_0cca == 0) + FreeSpriteTilesByTag(4); + else + FreeSpriteTilesByTag(3); + gPokemonStorageSystemPtr->unk_0cf0[0] = gPokemonStorageSystemPtr->unk_0cf8[0]; + gPokemonStorageSystemPtr->unk_0cf0[1] = gPokemonStorageSystemPtr->unk_0cf8[1]; +} + +void sub_809A5E8(struct Sprite *sprite) +{ + if (sprite->data[2]) + sprite->data[2]--; + else if ((sprite->pos1.x += sprite->data[0]) == sprite->data[1]) + sprite->callback = SpriteCallbackDummy; +} + +void sub_809A61C(struct Sprite *sprite) +{ + if (sprite->data[1]) + 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); + } +} + +void sub_809A654(void) +{ + u8 boxId = get_preferred_box(); + u8 wallpaperId = gPokemonStorage.wallpaper[boxId]; + if (gPokemonStorageSystemPtr->unk_0cca == 0) + CpuCopy16(gUnknown_083BB0A8[wallpaperId], gPlttBufferUnfaded + gPokemonStorageSystemPtr->unk_0cec, 4); + else + CpuCopy16(gUnknown_083BB0A8[wallpaperId], gPlttBufferUnfaded + gPokemonStorageSystemPtr->unk_0cee, 4); +} + +s16 sub_809A6D0(u8 width) +{ + return 0xb0 - width / 2; +} + +void sub_809A6DC(void) +{ + u16 i; + + LoadSpriteSheet(&gUnknown_083BB288); + LoadSpritePalette(&gUnknown_083BB290); + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&gSpriteTemplate_83BB2F0, 0x5c + i * 0x88, 0x1c, 21); + if (spriteId != MAX_SPRITES) + { + struct Sprite *sprite = gSprites + spriteId; + StartSpriteAnim(sprite, i); + sprite->data[3] = (i == 0) ? -1 : 1; + gPokemonStorageSystemPtr->unk_0d00[i] = sprite; + } + } + if (sub_809BF2C()) + sub_809A860(TRUE); +} + +void sub_809A774(s8 a0) +{ + u16 i; + + for (i = 0; i < 2; i++) + { + gPokemonStorageSystemPtr->unk_0d00[i]->pos2.x = 0; + gPokemonStorageSystemPtr->unk_0d00[i]->data[0] = 2; + } + if (a0 < 0) + { + gPokemonStorageSystemPtr->unk_0d00[0]->data[1] = 29; + gPokemonStorageSystemPtr->unk_0d00[1]->data[1] = 5; + gPokemonStorageSystemPtr->unk_0d00[0]->data[2] = 0x48; + gPokemonStorageSystemPtr->unk_0d00[1]->data[2] = 0x48; + } + else + { + gPokemonStorageSystemPtr->unk_0d00[0]->data[1] = 5; + gPokemonStorageSystemPtr->unk_0d00[1]->data[1] = 29; + gPokemonStorageSystemPtr->unk_0d00[0]->data[2] = 0xF8; + gPokemonStorageSystemPtr->unk_0d00[1]->data[2] = 0xF8; + } + gPokemonStorageSystemPtr->unk_0d00[0]->data[7] = 0; + gPokemonStorageSystemPtr->unk_0d00[1]->data[7] = 1; +} + +void sub_809A810(void) +{ + u16 i; + + for (i = 0; i < 2; i++) + { + gPokemonStorageSystemPtr->unk_0d00[i]->pos1.x = 0x88 * i + 0x5c; + gPokemonStorageSystemPtr->unk_0d00[i]->pos2.x = 0; + gPokemonStorageSystemPtr->unk_0d00[i]->invisible = FALSE; + } + sub_809A860(TRUE); +} + +void sub_809A860(bool8 a0) +{ + u16 i; + if (a0) + { + for (i = 0; i < 2; i++) + { + gPokemonStorageSystemPtr->unk_0d00[i]->data[0] = 1; + gPokemonStorageSystemPtr->unk_0d00[i]->data[1] = 0; + gPokemonStorageSystemPtr->unk_0d00[i]->data[2] = 0; + gPokemonStorageSystemPtr->unk_0d00[i]->data[4] = 0; + } + } + else + { + for (i = 0; i < 2; i++) + { + gPokemonStorageSystemPtr->unk_0d00[i]->data[0] = 0; + } + } +} + +void sub_809A8C8(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 -= gPokemonStorageSystemPtr->unk_08b6; + if (sprite->pos1.x < 0x49 || sprite->pos1.x > 0xf7) + 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 -= gPokemonStorageSystemPtr->unk_08b6; + break; + } +} + +struct Sprite *sub_809A9A0(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) +{ + u8 spriteId = CreateSprite(&gSpriteTemplate_83BB2F0, 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; +} + +void sub_809AA24(void) +{ + if (gPokemonStorageSystemPtr->unk_0005 != 1) + gUnknown_020384E4 = 0; + else + gUnknown_020384E4 = 1; + gUnknown_020384E5 = 0; + gUnknown_020384E6 = FALSE; + gUnknown_020384E7 = 0; + gUnknown_020384E8 = 0; + gUnknown_020384E9 = 0; + sub_809B0D4(); + sub_809CC04(); + gPokemonStorageSystemPtr->unk_11e2 = 1; + sub_809BF74(); +} + +void sub_809AA98(void) +{ + sub_809CC04(); + sub_809C028(); + gPokemonStorageSystemPtr->unk_11e2 = 1; + if (gUnknown_020384E6) + sub_8098BF0(); +} + +void sub_809AACC(u8 a0, u8 a1, u16 *a2, u16 *a3) +{ + switch (a0) + { + case 0: + *a2 = (a1 % 6) * 24 + 100; + *a3 = (a1 / 6) * 24 + 32; + break; + case 1: + if (a1 == 0) + { + *a2 = 0x68; + *a3 = 0x34; + } + else if (a1 == 6) + { + *a2 = 0x98; + *a3 = 0x84; + } + else + { + *a2 = 0x98; + *a3 = (a1 - 1) * 24 + 4; + } + break; + case 2: + *a2 = 0xa2; + *a3 = 0x0c; + break; + case 3: + *a3 = gUnknown_020384E6 ? 8 : 14; + *a2 = a1 * 0x58 + 0x78; + break; + case 4: + *a2 = 0xa0; + *a3 = 0x60; + break; + } +} + +u16 sub_809AB8C(void) +{ + switch (gUnknown_020384E4) + { + case 1: + return GetMonData(gPlayerParty + gUnknown_020384E5, MON_DATA_SPECIES); + case 0: + return GetBoxMonData(gPokemonStorage.boxes[get_preferred_box()] + gUnknown_020384E5, MON_DATA_SPECIES); + default: + return SPECIES_NONE; + } +} + +bool8 sub_809AC00(void) +{ + s16 tmp; + if (gPokemonStorageSystemPtr->unk_11dc == 0) + return FALSE; + if (--gPokemonStorageSystemPtr->unk_11dc) + { + gPokemonStorageSystemPtr->unk_11c8 += gPokemonStorageSystemPtr->unk_11d0; + gPokemonStorageSystemPtr->unk_11cc += gPokemonStorageSystemPtr->unk_11d4; + gPokemonStorageSystemPtr->unk_11c0->pos1.x = gPokemonStorageSystemPtr->unk_11c8 >> 8; + gPokemonStorageSystemPtr->unk_11c0->pos1.y = gPokemonStorageSystemPtr->unk_11cc >> 8; + if (gPokemonStorageSystemPtr->unk_11c0->pos1.x > 0x100) + { + tmp = gPokemonStorageSystemPtr->unk_11c0->pos1.x - 0x100; + gPokemonStorageSystemPtr->unk_11c0->pos1.x = tmp + 0x40; + } + if (gPokemonStorageSystemPtr->unk_11c0->pos1.x < 0x40) + { + tmp = 0x40 - gPokemonStorageSystemPtr->unk_11c0->pos1.x; + gPokemonStorageSystemPtr->unk_11c0->pos1.x = 0x100 - tmp; + } + if (gPokemonStorageSystemPtr->unk_11c0->pos1.y > 0xb0) + { + tmp = gPokemonStorageSystemPtr->unk_11c0->pos1.y - 0xb0; + gPokemonStorageSystemPtr->unk_11c0->pos1.y = tmp - 0x10; + } + if (gPokemonStorageSystemPtr->unk_11c0->pos1.y < -0x10) + { + tmp = -0x10 - gPokemonStorageSystemPtr->unk_11c0->pos1.y; + gPokemonStorageSystemPtr->unk_11c0->pos1.y = 0xb0 - tmp; + } + if (gPokemonStorageSystemPtr->unk_11e3 && --gPokemonStorageSystemPtr->unk_11e3 == 0) + gPokemonStorageSystemPtr->unk_11c0->vFlip = gPokemonStorageSystemPtr->unk_11c0->vFlip ? FALSE : TRUE; + } + else + { + gPokemonStorageSystemPtr->unk_11c0->pos1.x = gPokemonStorageSystemPtr->unk_11d8; + gPokemonStorageSystemPtr->unk_11c0->pos1.y = gPokemonStorageSystemPtr->unk_11da; + sub_809AFB8(); + } + return TRUE; +} + +void sub_809AD3C(u8 a0, u8 a1) +{ + u16 x; + u16 y; + + sub_809AACC(a0, a1, &x, &y); + gPokemonStorageSystemPtr->unk_11e0 = a0; + gPokemonStorageSystemPtr->unk_11e1 = a1; + gPokemonStorageSystemPtr->unk_11d8 = x; + gPokemonStorageSystemPtr->unk_11da = y; +} + +void sub_809AD94(void) +{ + int r7; + int r0; + + if (gPokemonStorageSystemPtr->unk_11de || gPokemonStorageSystemPtr->unk_11df) + gPokemonStorageSystemPtr->unk_11dc = 12; + else + gPokemonStorageSystemPtr->unk_11dc = 6; + if (gPokemonStorageSystemPtr->unk_11e3) + gPokemonStorageSystemPtr->unk_11e3 = gPokemonStorageSystemPtr->unk_11dc >> 1; + switch (gPokemonStorageSystemPtr->unk_11de) + { + default: + r7 = gPokemonStorageSystemPtr->unk_11da - gPokemonStorageSystemPtr->unk_11c0->pos1.y; + break; + case -1: + r7 = gPokemonStorageSystemPtr->unk_11da - 0xc0 - gPokemonStorageSystemPtr->unk_11c0->pos1.y; + break; + case 1: + r7 = gPokemonStorageSystemPtr->unk_11da + 0xc0 - gPokemonStorageSystemPtr->unk_11c0->pos1.y; + break; + } + switch (gPokemonStorageSystemPtr->unk_11df) + { + default: + r0 = gPokemonStorageSystemPtr->unk_11d8 - gPokemonStorageSystemPtr->unk_11c0->pos1.x; + break; + case -1: + r0 = gPokemonStorageSystemPtr->unk_11d8 - 0xc0 - gPokemonStorageSystemPtr->unk_11c0->pos1.x; + break; + case 1: + r0 = gPokemonStorageSystemPtr->unk_11d8 + 0xc0 - gPokemonStorageSystemPtr->unk_11c0->pos1.x; + break; + } + r7 <<= 8; + r0 <<= 8; + gPokemonStorageSystemPtr->unk_11d0 = r0 / gPokemonStorageSystemPtr->unk_11dc; + gPokemonStorageSystemPtr->unk_11d4 = r7 / gPokemonStorageSystemPtr->unk_11dc; + gPokemonStorageSystemPtr->unk_11c8 = gPokemonStorageSystemPtr->unk_11c0->pos1.x << 8; + gPokemonStorageSystemPtr->unk_11cc = gPokemonStorageSystemPtr->unk_11c0->pos1.y << 8; +} + +void sub_809AF18(u8 a0, u8 a1) +{ + sub_809AD3C(a0, a1); + sub_809AD94(); + if (!gUnknown_020384E6) + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 1); + if (a0 == 1 && gUnknown_020384E4 != 1) + { + gPokemonStorageSystemPtr->unk_11e2 = a0; + gPokemonStorageSystemPtr->unk_11c4->invisible = TRUE; + } + switch (a0) + { + case 0: + break; + case 1 ... 3: + gPokemonStorageSystemPtr->unk_11c4->invisible = TRUE; + gPokemonStorageSystemPtr->unk_11c4->oam.priority = 1; + break; + } +} + +void sub_809AFB8(void) +{ + gUnknown_020384E4 = gPokemonStorageSystemPtr->unk_11e0; + gUnknown_020384E5 = gPokemonStorageSystemPtr->unk_11e1; + if (!gUnknown_020384E6) + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 0); + sub_809BF74(); + switch (gUnknown_020384E4) + { + case 2: + sub_809A860(TRUE); + break; + case 1: + gPokemonStorageSystemPtr->unk_11c4->subpriority = 12; + break; + case 0: + gPokemonStorageSystemPtr->unk_11c4->oam.priority = 2; + gPokemonStorageSystemPtr->unk_11c4->subpriority = 20; + gPokemonStorageSystemPtr->unk_11c4->invisible = FALSE; + break; + } +} + +void sub_809B068(void) +{ + u8 partyCount; + if (!gUnknown_020384E6) + partyCount = 0; + else + { + partyCount = CalculatePlayerPartyCount(); + if (partyCount > PARTY_SIZE - 1) + partyCount = PARTY_SIZE - 1; + } + if (gPokemonStorageSystemPtr->unk_11c0->vFlip) + gPokemonStorageSystemPtr->unk_11e3 = 1; + sub_809AF18(1, partyCount); +} + +void sub_809B0C0(u8 a0) +{ + sub_809AF18(0, a0); +} + +void sub_809B0D4(void) +{ + gUnknown_020384EA = 0; +} + +void sub_809B0E0(void) +{ + gUnknown_020384EA = gUnknown_020384E5; +} + +u8 sub_809B0F4(void) +{ + return gUnknown_020384EA; +} + +void sub_809B100(u8 a0) +{ + gPokemonStorageSystemPtr->unk_12a4 = gUnknown_083BBBC8[a0]; + gPokemonStorageSystemPtr->unk_12a8 = 0; +} + +bool8 sub_809B130(void) +{ + return gPokemonStorageSystemPtr->unk_12a4(); +} + +bool8 sub_809B150(void) +{ + switch (gPokemonStorageSystemPtr->unk_12a8) + { + case 0: + if (gUnknown_020384E6) + return FALSE; + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 2); + gPokemonStorageSystemPtr->unk_12a8++; + break; + case 1: + if (!sub_809B324()) + { + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 3); + sub_809B384(); + gPokemonStorageSystemPtr->unk_12a8++; + } + break; + case 2: + if (!sub_809B358()) + gPokemonStorageSystemPtr->unk_12a8++; + break; + case 3: + return FALSE; + } + return TRUE; +} + +bool8 sub_809B1D8(void) +{ + switch (gPokemonStorageSystemPtr->unk_12a8) + { + case 0: + if (!sub_809B324()) + { + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 2); + sub_809B3E0(); + gPokemonStorageSystemPtr->unk_12a8++; + } + break; + case 1: + if (!sub_809B358()) + { + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 0); + gPokemonStorageSystemPtr->unk_12a8++; + } + break; + case 2: + return FALSE; + } + return TRUE; +} + +bool8 sub_809B24C(void) +{ + switch (gPokemonStorageSystemPtr->unk_12a8) + { + case 0: + switch (gUnknown_020384E4) + { + case 1: + gPokemonStorageSystemPtr->unk_12a9 = 14; + break; + case 0: + gPokemonStorageSystemPtr->unk_12a9 = get_preferred_box(); + break; + default: + return FALSE; + } + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 2); + sub_80996B0(gPokemonStorageSystemPtr->unk_12a9, gUnknown_020384E5); + gPokemonStorageSystemPtr->unk_12a8++; + break; + case 1: + if (!sub_809971C()) + { + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 3); + diegohint1(gPokemonStorageSystemPtr->unk_12a9, gUnknown_020384E5); + gPokemonStorageSystemPtr->unk_12a8++; + } + break; + case 2: + return FALSE; + } + return TRUE; +} + +bool8 sub_809B324(void) +{ + switch (gPokemonStorageSystemPtr->unk_11c0->pos2.y) + { + default: + gPokemonStorageSystemPtr->unk_11c0->pos2.y++; + break; + case 0: + gPokemonStorageSystemPtr->unk_11c0->pos2.y++; + break; + case 8: + return FALSE; + } + return TRUE; +} + +bool8 sub_809B358(void) +{ + switch (gPokemonStorageSystemPtr->unk_11c0->pos2.y) + { + case 0: + return FALSE; + default: + gPokemonStorageSystemPtr->unk_11c0->pos2.y--; + break; + } + return TRUE; +} + +void sub_809B384(void) +{ + switch (gUnknown_020384E4) + { + case 1: + sub_809B44C(14, gUnknown_020384E5); + sub_8099584(0, gUnknown_020384E5); + break; + case 0: + sub_809B44C(get_preferred_box(), gUnknown_020384E5); + sub_8099584(1, gUnknown_020384E5); + break; + default: + return; + } + gUnknown_020384E6 = TRUE; +} + +void sub_809B3E0(void) +{ + u8 boxId; + switch (gUnknown_020384E4) + { + case 1: + diegohint2(14, gUnknown_020384E5); + sub_809960C(14, gUnknown_020384E5); + break; + case 0: + boxId = get_preferred_box(); + diegohint2(boxId, gUnknown_020384E5); + sub_809960C(boxId, gUnknown_020384E5); + break; + default: + return; + } + gUnknown_020384E6 = FALSE; +} + +void sub_809B440(void) +{ + sub_809BF74(); +} + +void sub_809B44C(u8 a0, u8 a1) +{ + if (a0 == 14) + gPokemonStorageSystemPtr->unk_25b4 = gPlayerParty[gUnknown_020384E5]; + else + ExpandBoxMon(gPokemonStorage.boxes[a0] + a1, &gPokemonStorageSystemPtr->unk_25b4); + sub_809B548(a0, a1); + gUnknown_020384E7 = a0; + gUnknown_020384E8 = a1; +} + +void diegohint2(u8 a0, u8 a1) +{ + if (a0 == 14) + { + gPlayerParty[a1] = gPokemonStorageSystemPtr->unk_25b4; + } + else + { + BoxMonRestorePP(&gPokemonStorageSystemPtr->unk_25b4.box); + gPokemonStorage.boxes[a0][a1] = gPokemonStorageSystemPtr->unk_25b4.box; + } +} + +void sub_809B548(u8 a0, u8 a1) +{ + if (a0 == 14) + ZeroMonData(gPlayerParty + a1); + else + ZeroBoxMonData(gPokemonStorage.boxes[a0] + a1); +} + +void diegohint1(u8 a0, u8 a1) +{ + if (a0 == 14) + gPokemonStorageSystemPtr->unk_2618 = gPlayerParty[a1]; + else + ExpandBoxMon(gPokemonStorage.boxes[a0] + a1, &gPokemonStorageSystemPtr->unk_2618); + diegohint2(a0, a1); + gPokemonStorageSystemPtr->unk_25b4 = gPokemonStorageSystemPtr->unk_2618; + sub_809C04C(&gPokemonStorageSystemPtr->unk_25b4, 0); + gUnknown_020384E7 = a0; + gUnknown_020384E8 = a1; +} + +bool8 sub_809B62C(u8 boxId) +{ + s16 monIdx = GetIndexOfFirstEmptySpaceInBoxN(boxId); + if (monIdx == -1) + return FALSE; + if (gUnknown_020384E6) + { + diegohint2(boxId, monIdx); + sub_8099480(); + gUnknown_020384E6 = FALSE; + } + else + { + sub_809B44C(14, gUnknown_020384E5); + diegohint2(boxId, monIdx); + sub_8099520(gUnknown_020384E5); + } + if (boxId == get_preferred_box()) + sub_8098D20(monIdx); + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 1); + return TRUE; +} + +void sub_809B6BC(void) +{ + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 0); + sub_809BF74(); +} + +void sub_809B6DC(void) +{ + u8 mode; + + if (gUnknown_020384E6) + mode = 2; + else if (gUnknown_020384E4 == 1) + mode = 0; + else + mode = 1; + sub_809981C(mode, gUnknown_020384E5); + StringCopy(gPokemonStorageSystemPtr->unk_26e4, gPokemonStorageSystemPtr->unk_11fa); +} + +bool8 sub_809B734(void) +{ + if (!sub_80998D8()) + { + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 0); + return FALSE; + } + return TRUE; +} + +void sub_809B760(void) +{ + sub_8099920(); + if (gUnknown_020384E6) + gUnknown_020384E6 = FALSE; + else + { + u8 boxId; + if (gUnknown_020384E4 == 1) + boxId = 14; + else + boxId = get_preferred_box(); + sub_809B548(boxId, gUnknown_020384E5); + } + sub_809BF74(); +} + +void sub_809B7AC(void) +{ + if (gUnknown_020384E6) + StartSpriteAnim(gPokemonStorageSystemPtr->unk_11c0, 3); +} + +void sub_809B7D4(void) +{ + u16 knownMoves; + if (gUnknown_020384E6) + { + gPokemonStorageSystemPtr->unk_2618 = gPokemonStorageSystemPtr->unk_25b4; + gPokemonStorageSystemPtr->unk_2682 = -1; + gPokemonStorageSystemPtr->unk_2683 = -1; + } + else + { + if (gUnknown_020384E4 == 1) + { + gPokemonStorageSystemPtr->unk_2618 = gPlayerParty[gUnknown_020384E5]; + gPokemonStorageSystemPtr->unk_2682 = 14; + } + else + { + ExpandBoxMon(gPokemonStorage.boxes[gPokemonStorage.currentBox] + gUnknown_020384E5, &gPokemonStorageSystemPtr->unk_2618); + gPokemonStorageSystemPtr->unk_2682 = gPokemonStorage.currentBox; + } + gPokemonStorageSystemPtr->unk_2683 = gUnknown_020384E5; + } + gPokemonStorageSystemPtr->unk_267e = 0; + gPokemonStorageSystemPtr->unk_267f = 0; + gPokemonStorageSystemPtr->unk_2686[0] = MOVE_SURF; + gPokemonStorageSystemPtr->unk_2686[1] = MOVE_DIVE; + gPokemonStorageSystemPtr->unk_2686[2] = NUM_MOVES; + knownMoves = GetMonData(&gPokemonStorageSystemPtr->unk_2618, MON_DATA_KNOWN_MOVES, gPokemonStorageSystemPtr->unk_2686); + gPokemonStorageSystemPtr->unk_267e = knownMoves & 1; + gPokemonStorageSystemPtr->unk_267f = (knownMoves >> 1) & 1; + if (gPokemonStorageSystemPtr->unk_267e || gPokemonStorageSystemPtr->unk_267f) + gPokemonStorageSystemPtr->unk_267d = 0; + else + { + gPokemonStorageSystemPtr->unk_267d = 1; + gPokemonStorageSystemPtr->unk_267c = 1; + } + gPokemonStorageSystemPtr->unk_2684 = 0; +} + +s8 sub_809B960(void) +{ + u16 i; + u16 knownMoves; + + if (gPokemonStorageSystemPtr->unk_267d) + return gPokemonStorageSystemPtr->unk_267c; + switch (gPokemonStorageSystemPtr->unk_2684) + { + case 0: + for (i = 0; i < PARTY_SIZE; i++) + { + if (gPokemonStorageSystemPtr->unk_2682 != 14 || gPokemonStorageSystemPtr->unk_2683 != i) + { + knownMoves = GetMonData(gPlayerParty + i, MON_DATA_KNOWN_MOVES, gPokemonStorageSystemPtr->unk_2686); + if (knownMoves & 1) + gPokemonStorageSystemPtr->unk_267e = 0; + if (knownMoves & 2) + gPokemonStorageSystemPtr->unk_267f = 0; + } + } + if (gPokemonStorageSystemPtr->unk_267e == 0 && gPokemonStorageSystemPtr->unk_267f == 0) + { + gPokemonStorageSystemPtr->unk_267d = 1; + gPokemonStorageSystemPtr->unk_267c = 1; + } + else + { + gPokemonStorageSystemPtr->unk_2680 = 0; + gPokemonStorageSystemPtr->unk_2681 = 0; + gPokemonStorageSystemPtr->unk_2684++; + } + break; + case 1: + for (i = 0; i < 5; i++) + { + knownMoves = GetBoxMonData(gPokemonStorage.boxes[gPokemonStorageSystemPtr->unk_2680] + gPokemonStorageSystemPtr->unk_2681, MON_DATA_KNOWN_MOVES, gPokemonStorageSystemPtr->unk_2686); + if (knownMoves && (gPokemonStorageSystemPtr->unk_2682 != gPokemonStorageSystemPtr->unk_2680 || gPokemonStorageSystemPtr->unk_2683 != gPokemonStorageSystemPtr->unk_2681)) + { + if (knownMoves & 1) + gPokemonStorageSystemPtr->unk_267e = 0; + if (knownMoves & 2) + gPokemonStorageSystemPtr->unk_267f = 0; + } + if (++gPokemonStorageSystemPtr->unk_2681 >= 30) + { + gPokemonStorageSystemPtr->unk_2681 = 0; + if (++gPokemonStorageSystemPtr->unk_2680 >= 14) + { + gPokemonStorageSystemPtr->unk_267d = 1; + gPokemonStorageSystemPtr->unk_267c = 0; + break; + } + } + } + if (gPokemonStorageSystemPtr->unk_267e == 0 && gPokemonStorageSystemPtr->unk_267f == 0) + { + gPokemonStorageSystemPtr->unk_267d = 1; + gPokemonStorageSystemPtr->unk_267c = 1; + } + break; + } + return -1; +} + +void sub_809BB90(void) +{ + if (gUnknown_020384E6) + gUnknown_02038480 = gPokemonStorageSystemPtr->unk_25b4; +} + +void sub_809BBC0(void) +{ + if (gUnknown_020384E6) + { + if (gUnknown_020384E7 == 14) + gPokemonStorageSystemPtr->unk_25b4 = gUnknown_02038480; + else + gPokemonStorageSystemPtr->unk_25b4.box = gUnknown_02038480.box; + } +} + +void sub_809BC18(void) +{ + if (gUnknown_020384E6) + { + sub_809BB90(); + gPokemonStorageSystemPtr->unk_2690.pokemon = &gUnknown_02038480; + gPokemonStorageSystemPtr->unk_268d = 0; + gPokemonStorageSystemPtr->unk_268c = 0; + gPokemonStorageSystemPtr->unk_268e = 0; + } + else if (gUnknown_020384E4 == 1) + { + gPokemonStorageSystemPtr->unk_2690.pokemon = gPlayerParty; + gPokemonStorageSystemPtr->unk_268d = gUnknown_020384E5; + gPokemonStorageSystemPtr->unk_268c = StorageSystemGetPartySize() - 1; + gPokemonStorageSystemPtr->unk_268e = 0; + } + else + { + gPokemonStorageSystemPtr->unk_2690.box = gPokemonStorage.boxes[gPokemonStorage.currentBox]; + gPokemonStorageSystemPtr->unk_268d = gUnknown_020384E5; + gPokemonStorageSystemPtr->unk_268c = 30 - 1; + gPokemonStorageSystemPtr->unk_268e = 5; + } +} + +void sub_809BD14(void) +{ + if (gUnknown_020384E6) + sub_809BBC0(); + else + gUnknown_020384E5 = pssData.monIndex; +} + +s16 party_compaction(void) +{ + s16 retVal = -1; + u16 i; + u16 last; + + for (i = 0, last = 0; i < PARTY_SIZE; i++) + { + if ((u16)GetMonData(gPlayerParty + i, MON_DATA_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 sub_809BDD8(u8 markings) +{ + gPokemonStorageSystemPtr->unk_11f7 = markings; + if (gUnknown_020384E6) + SetMonData(&gPokemonStorageSystemPtr->unk_25b4, MON_DATA_MARKINGS, &markings); + else + { + if (gUnknown_020384E4 == 1) + SetMonData(gPlayerParty + gUnknown_020384E5, MON_DATA_MARKINGS, &markings); + if (gUnknown_020384E4 == 0) + SetBoxMonData(gPokemonStorage.boxes[get_preferred_box()] + gUnknown_020384E5, MON_DATA_MARKINGS, &markings); + } +} + +bool8 sub_809BE80(void) +{ + if (gUnknown_020384E4 == 1 && !gUnknown_020384E6 && CountAlivePartyMonsExceptOne(gUnknown_020384E5) == 0) + return TRUE; + return FALSE; +} + +bool8 sub_809BEBC(void) +{ + if (gUnknown_020384E6) + { + if (gUnknown_020384E4 == 1 && CountAlivePartyMonsExceptOne(gUnknown_020384E5) == 0) + { + if (gPokemonStorageSystemPtr->unk_11f9 || GetMonData(&gPokemonStorageSystemPtr->unk_25b4, MON_DATA_HP) == 0) + return FALSE; + } + return TRUE; + } + return FALSE; +} + +bool8 sub_809BF20(void) +{ + return gUnknown_020384E6; +} + +bool8 sub_809BF2C(void) +{ + return gUnknown_020384E4 == 2 ? TRUE : FALSE; +} + +bool8 sub_809BF48(void) +{ + return (gUnknown_020384E4 == 3 && gUnknown_020384E5 == 1) ? TRUE : FALSE; +} + +void sub_809BF74(void) +{ + gPokemonStorageSystemPtr->unk_11f6 = gUnknown_020384E6 ? 0 : 1; + if (!gUnknown_020384E6) + { + switch (gUnknown_020384E4) + { + case 1: + if (gUnknown_020384E5 < PARTY_SIZE) + { + sub_809C04C(gPlayerParty + gUnknown_020384E5, 0); + break; + } + // fallthrough + case 2: + case 3: + sub_809C04C(NULL, 2); + break; + case 0: + sub_809C04C(gPokemonStorage.boxes[get_preferred_box()] + gUnknown_020384E5, 1); + break; + } + } +} + +void sub_809C028(void) +{ + if (gUnknown_020384E6) + sub_809C04C(&gUnknown_02038480.box, 0); + else + sub_809BF74(); +} + +void sub_809C04C(void *pokemon, u8 a1) +{ + u8 *buf; + u16 gender = MON_MALE; + gPokemonStorageSystemPtr->unk_11f2 = 0; + if (a1 == 0) + { + struct Pokemon *pkmn = (struct Pokemon *)pokemon; + gPokemonStorageSystemPtr->unk_11f0 = GetMonData(pokemon, MON_DATA_SPECIES2); + if (gPokemonStorageSystemPtr->unk_11f0 != SPECIES_NONE) + { + gPokemonStorageSystemPtr->unk_11f9 = GetMonData(pkmn, MON_DATA_IS_EGG); + GetMonData(pkmn, MON_DATA_NICKNAME, gPokemonStorageSystemPtr->unk_11fa); + StringGetEnd10(gPokemonStorageSystemPtr->unk_11fa); + gPokemonStorageSystemPtr->unk_11f8 = GetMonData(pkmn, MON_DATA_LEVEL); + gPokemonStorageSystemPtr->unk_11f7 = GetMonData(pkmn, MON_DATA_MARKINGS); + gPokemonStorageSystemPtr->unk_11ec = GetMonData(pkmn, MON_DATA_PERSONALITY); + gPokemonStorageSystemPtr->unk_11e8 = GetMonSpritePal(pkmn); + gender = GetMonGender(pkmn); + gPokemonStorageSystemPtr->unk_11f2 = GetMonData(pkmn, MON_DATA_HELD_ITEM); + } + } + else if (a1 == 1) + { + struct BoxPokemon *boxmon = (struct BoxPokemon *)pokemon; + gPokemonStorageSystemPtr->unk_11f0 = GetBoxMonData(pokemon, MON_DATA_SPECIES2); + if (gPokemonStorageSystemPtr->unk_11f0 != SPECIES_NONE) + { + u32 otId = GetBoxMonData(boxmon, MON_DATA_OT_ID); + gPokemonStorageSystemPtr->unk_11f9 = GetBoxMonData(boxmon, MON_DATA_IS_EGG); + GetBoxMonData(boxmon, MON_DATA_NICKNAME, gPokemonStorageSystemPtr->unk_11fa); + StringGetEnd10(gPokemonStorageSystemPtr->unk_11fa); + gPokemonStorageSystemPtr->unk_11f8 = GetLevelFromBoxMonExp(boxmon); + gPokemonStorageSystemPtr->unk_11f7 = GetBoxMonData(boxmon, MON_DATA_MARKINGS); + gPokemonStorageSystemPtr->unk_11ec = GetBoxMonData(boxmon, MON_DATA_PERSONALITY); + gPokemonStorageSystemPtr->unk_11e8 = GetMonSpritePalFromOtIdPersonality(gPokemonStorageSystemPtr->unk_11f0, otId, gPokemonStorageSystemPtr->unk_11ec); + gender = GetGenderFromSpeciesAndPersonality(gPokemonStorageSystemPtr->unk_11f0, gPokemonStorageSystemPtr->unk_11ec); + gPokemonStorageSystemPtr->unk_11f2 = GetBoxMonData(boxmon, MON_DATA_HELD_ITEM); + } + } + else + { + gPokemonStorageSystemPtr->unk_11f0 = SPECIES_NONE; + } + if (gPokemonStorageSystemPtr->unk_11f0 == SPECIES_NONE) + { + gPokemonStorageSystemPtr->unk_11fa[0] = EOS; + gPokemonStorageSystemPtr->unk_120f[0] = EOS; + gPokemonStorageSystemPtr->unk_1234[0] = EOS; + gPokemonStorageSystemPtr->unk_1259[0] = EOS; + gPokemonStorageSystemPtr->unk_127a[0] = EOS; + } + else if (gPokemonStorageSystemPtr->unk_11f9) + { + buf = gPokemonStorageSystemPtr->unk_120f; + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x0F; // WHITE2 + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x01; // DARK_GREY + buf = gPokemonStorageSystemPtr->unk_120f + 5; + buf = StringCopy(buf, gPokemonStorageSystemPtr->unk_11fa); + gPokemonStorageSystemPtr->unk_1234[0] = EOS; + gPokemonStorageSystemPtr->unk_1259[0] = EOS; + gPokemonStorageSystemPtr->unk_127a[0] = EOS; + } + else + { + if (gPokemonStorageSystemPtr->unk_11f0 == SPECIES_NIDORAN_M || gPokemonStorageSystemPtr->unk_11f0 == SPECIES_NIDORAN_F) + gender = MON_GENDERLESS; + buf = gPokemonStorageSystemPtr->unk_120f; + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x0F; // WHITE2 + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x01; // DARK_GREY + buf = gPokemonStorageSystemPtr->unk_120f + 5; + buf = StringCopy(buf, gPokemonStorageSystemPtr->unk_11fa); + buf = gPokemonStorageSystemPtr->unk_1234; + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x0F; // WHITE2 + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x01; // DARK_GREY + buf[5] = EXT_CTRL_CODE_BEGIN; + buf[6] = 0x13; // CLEAR_TO + buf[7] = 7; + buf[8] = CHAR_SLASH; + buf = gPokemonStorageSystemPtr->unk_1234 + 9; + buf = StringCopy(buf, gSpeciesNames[gPokemonStorageSystemPtr->unk_11f0]); + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x13; // CLEAR_TO + buf[2] = 0x50; + buf[3] = EOS; + buf = gPokemonStorageSystemPtr->unk_1259; + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x0F; // WHITE2 + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x01; // DARK_GREY + buf[5] = EXT_CTRL_CODE_BEGIN; + buf[6] = 0x13; // CLEAR_TO + buf[7] = 8; + buf = gPokemonStorageSystemPtr->unk_1259 + 8; + buf[0] = 0x34; // LV + buf = gPokemonStorageSystemPtr->unk_1259 + 9; + buf = sub_8072C14(buf, gPokemonStorageSystemPtr->unk_11f8, 0x22, STR_CONV_MODE_RIGHT_ALIGN); + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x11; // CLEAR + buf[2] = 8; + buf += 3; + switch (gender) + { + case MON_MALE: + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x04; // BLUE + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x05; // YELLOW + buf[5] = CHAR_MALE; + buf += 6; + break; + case MON_FEMALE: + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x06; // CYAN + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x07; // MAGENTA + buf[5] = CHAR_FEMALE; + buf += 6; + break; + } + buf[0] = EOS; + buf = gPokemonStorageSystemPtr->unk_127a; + if (gPokemonStorageSystemPtr->unk_11f2) + { + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x04; // COLOR_HIGHLIGHT_SHADOW + buf[2] = 0x0F; // WHITE2 + buf[3] = 0x00; // TRANSPARENT + buf[4] = 0x01; // DARK_GREY + buf = gPokemonStorageSystemPtr->unk_127a + 5; + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x06; // size + buf[2] = 0x04; + buf = gPokemonStorageSystemPtr->unk_127a + 8; + buf = StringCopy(buf, ItemId_GetItem(gPokemonStorageSystemPtr->unk_11f2)->name); + buf[0] = EXT_CTRL_CODE_BEGIN; + buf[1] = 0x07; // UNKNOWN_7; + buf += 2; + } + buf[0] = EOS; + } +} + +#ifdef NONMATCHING +u8 sub_809C464(void) +{ + u8 r9; + s8 r8 = gUnknown_020384E4; + s8 r4 = gUnknown_020384E5; + gPokemonStorageSystemPtr->unk_11de = 0; + gPokemonStorageSystemPtr->unk_11df = 0; + gPokemonStorageSystemPtr->unk_11e3 = 0; + if (gMain.newAndRepeatedKeys & DPAD_UP) + { + r9 = 1; + if (gUnknown_020384E5 >= 6) + { + r4 -= 6; + } + else + { + r8 = 2; + r4 = 0; + } + } + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + { + r9 = 1; + r4 += 6; + if (r4 >= 30) + { + r8 = 3; + r4 -= 30; + r4 /= 3; + gPokemonStorageSystemPtr->unk_11de = 1; + gPokemonStorageSystemPtr->unk_11e3 = 1; + } + } + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) + { + r9 = 1; + if (gUnknown_020384E5 % 6) + r4--; + else + { + gPokemonStorageSystemPtr->unk_11df = -1; + r4 += 5; + } + } + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) + { + r9 = 1; + if ((gUnknown_020384E5 + 1) % 6) + r4++; + else + { + gPokemonStorageSystemPtr->unk_11df = 1; + r4 -= 5; + } + } + else if (gMain.newKeys & START_BUTTON) + { + r9 = 1; + r8 = 2; + r4 = 0; + } + else + { + if ((gMain.newKeys & A_BUTTON) && sub_809CAB0()) + { + if (gUnknown_020384E9 == 0) + return 8; + switch (sub_809CE4C(0)) + { + case 1: + return 11; + case 2: + return 12; + case 3: + return 13; + case 4: + return 14; + case 5: + return 15; + } + } + if (gMain.newKeys & B_BUTTON) + return 16; + if (gSaveBlock2.optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + { + if (gMain.heldKeys & L_BUTTON) + return 10; + if (gMain.heldKeys & R_BUTTON) + return 9; + } + if (gMain.newKeys & SELECT_BUTTON) + { + sub_809CD88(); + return 0; + } + r9 = 0; + } + if (r9) + sub_809AF18(r8, r4); + return r9; +} +#else +__attribute__((naked)) u8 sub_809C464(void) +{ + asm_unified("\tpush {r4-r7,lr}\n" + "\tmov r7, r9\n" + "\tmov r6, r8\n" + "\tpush {r6,r7}\n" + "\tldr r0, _0809C4D8 @ =gUnknown_020384E4\n" + "\tldrb r0, [r0]\n" + "\tmov r8, r0\n" + "\tldr r2, _0809C4DC @ =gUnknown_020384E5\n" + "\tldrb r4, [r2]\n" + "\tldr r0, _0809C4E0 @ =gPokemonStorageSystemPtr\n" + "\tldr r1, [r0]\n" + "\tldr r0, _0809C4E4 @ =0x000011de\n" + "\tadds r7, r1, r0\n" + "\tmovs r0, 0\n" + "\tstrb r0, [r7]\n" + "\tldr r3, _0809C4E8 @ =0x000011df\n" + "\tadds r5, r1, r3\n" + "\tstrb r0, [r5]\n" + "\tadds r3, 0x4\n" + "\tadds r6, r1, r3\n" + "\tstrb r0, [r6]\n" + "\tldr r0, _0809C4EC @ =gMain\n" + "\tmov r12, r0\n" + "\tldrh r1, [r0, 0x30]\n" + "\tmovs r0, 0x40\n" + "\tands r0, r1\n" + "\tadds r3, r2, 0\n" + "\tcmp r0, 0\n" + "\tbeq _0809C4A0\n" + "\tb _0809C62A\n" + "_0809C4A0:\n" + "\tmovs r0, 0x80\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C4F0\n" + "\tmovs r1, 0x1\n" + "\tmov r9, r1\n" + "\tlsls r0, r4, 24\n" + "\tmovs r3, 0xC0\n" + "\tlsls r3, 19\n" + "\tadds r0, r3\n" + "\tlsrs r4, r0, 24\n" + "\tasrs r0, 24\n" + "\tcmp r0, 0x1D\n" + "\tbgt _0809C4BE\n" + "\tb _0809C648\n" + "_0809C4BE:\n" + "\tmovs r1, 0x3\n" + "\tmov r8, r1\n" + "\tsubs r0, 0x1E\n" + "\tlsls r0, 24\n" + "\tasrs r0, 24\n" + "\tbl __divsi3\n" + "\tlsls r0, 24\n" + "\tlsrs r4, r0, 24\n" + "\tmov r3, r9\n" + "\tstrb r3, [r7]\n" + "\tstrb r3, [r6]\n" + "\tb _0809C648\n" + "\t.align 2, 0\n" + "_0809C4D8: .4byte gUnknown_020384E4\n" + "_0809C4DC: .4byte gUnknown_020384E5\n" + "_0809C4E0: .4byte gPokemonStorageSystemPtr\n" + "_0809C4E4: .4byte 0x000011de\n" + "_0809C4E8: .4byte 0x000011df\n" + "_0809C4EC: .4byte gMain\n" + "_0809C4F0:\n" + "\tmovs r0, 0x20\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C524\n" + "\tmovs r0, 0x1\n" + "\tmov r9, r0\n" + "\tmovs r0, 0\n" + "\tldrsb r0, [r3, r0]\n" + "\tmovs r1, 0x6\n" + "\tbl __modsi3\n" + "\tlsls r0, 24\n" + "\tcmp r0, 0\n" + "\tbeq _0809C514\n" + "\tlsls r0, r4, 24\n" + "\tmovs r1, 0xFF\n" + "\tlsls r1, 24\n" + "\tb _0809C63C\n" + "_0809C514:\n" + "\tmovs r0, 0xFF\n" + "\tstrb r0, [r5]\n" + "\tlsls r0, r4, 24\n" + "\tmovs r3, 0xA0\n" + "\tlsls r3, 19\n" + "\tadds r0, r3\n" + "\tlsrs r4, r0, 24\n" + "\tb _0809C648\n" + "_0809C524:\n" + "\tmovs r0, 0x10\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C554\n" + "\tmovs r0, 0x1\n" + "\tmov r9, r0\n" + "\tmovs r0, 0\n" + "\tldrsb r0, [r3, r0]\n" + "\tadds r0, 0x1\n" + "\tmovs r1, 0x6\n" + "\tbl __modsi3\n" + "\tcmp r0, 0\n" + "\tbeq _0809C548\n" + "\tlsls r0, r4, 24\n" + "\tmovs r1, 0x80\n" + "\tlsls r1, 17\n" + "\tb _0809C63C\n" + "_0809C548:\n" + "\tmov r3, r9\n" + "\tstrb r3, [r5]\n" + "\tlsls r0, r4, 24\n" + "\tmovs r1, 0xFB\n" + "\tlsls r1, 24\n" + "\tb _0809C63C\n" + "_0809C554:\n" + "\tmov r3, r12\n" + "\tldrh r1, [r3, 0x2E]\n" + "\tmovs r0, 0x8\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C56A\n" + "\tmovs r0, 0x1\n" + "\tmov r9, r0\n" + "\tmovs r1, 0x2\n" + "\tmov r8, r1\n" + "\tb _0809C646\n" + "_0809C56A:\n" + "\tmovs r0, 0x1\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C5D4\n" + "\tbl sub_809CAB0\n" + "\tlsls r0, 24\n" + "\tcmp r0, 0\n" + "\tbeq _0809C5D4\n" + "\tldr r0, _0809C588 @ =gUnknown_020384E9\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _0809C58C\n" + "\tmovs r0, 0x8\n" + "\tb _0809C658\n" + "\t.align 2, 0\n" + "_0809C588: .4byte gUnknown_020384E9\n" + "_0809C58C:\n" + "\tmovs r0, 0\n" + "\tbl sub_809CE4C\n" + "\tsubs r0, 0x1\n" + "\tlsls r0, 24\n" + "\tasrs r0, 24\n" + "\tcmp r0, 0x4\n" + "\tbhi _0809C5D4\n" + "\tlsls r0, 2\n" + "\tldr r1, _0809C5A8 @ =_0809C5AC\n" + "\tadds r0, r1\n" + "\tldr r0, [r0]\n" + "\tmov pc, r0\n" + "\t.align 2, 0\n" + "_0809C5A8: .4byte _0809C5AC\n" + "\t.align 2, 0\n" + "_0809C5AC:\n" + "\t.4byte _0809C5C0\n" + "\t.4byte _0809C5C4\n" + "\t.4byte _0809C5C8\n" + "\t.4byte _0809C5CC\n" + "\t.4byte _0809C5D0\n" + "_0809C5C0:\n" + "\tmovs r0, 0xB\n" + "\tb _0809C658\n" + "_0809C5C4:\n" + "\tmovs r0, 0xC\n" + "\tb _0809C658\n" + "_0809C5C8:\n" + "\tmovs r0, 0xD\n" + "\tb _0809C658\n" + "_0809C5CC:\n" + "\tmovs r0, 0xE\n" + "\tb _0809C658\n" + "_0809C5D0:\n" + "\tmovs r0, 0xF\n" + "\tb _0809C658\n" + "_0809C5D4:\n" + "\tldr r2, _0809C5E4 @ =gMain\n" + "\tldrh r1, [r2, 0x2E]\n" + "\tmovs r0, 0x2\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C5E8\n" + "\tmovs r0, 0x10\n" + "\tb _0809C658\n" + "\t.align 2, 0\n" + "_0809C5E4: .4byte gMain\n" + "_0809C5E8:\n" + "\tldr r0, _0809C600 @ =gSaveBlock2\n" + "\tldrb r0, [r0, 0x13]\n" + "\tcmp r0, 0x1\n" + "\tbne _0809C612\n" + "\tldrh r1, [r2, 0x2C]\n" + "\tmovs r0, 0x80\n" + "\tlsls r0, 2\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C604\n" + "\tmovs r0, 0xA\n" + "\tb _0809C658\n" + "\t.align 2, 0\n" + "_0809C600: .4byte gSaveBlock2\n" + "_0809C604:\n" + "\tmovs r0, 0x80\n" + "\tlsls r0, 1\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C612\n" + "\tmovs r0, 0x9\n" + "\tb _0809C658\n" + "_0809C612:\n" + "\tldrh r1, [r2, 0x2E]\n" + "\tmovs r0, 0x4\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C624\n" + "\tbl sub_809CD88\n" + "\tmovs r0, 0\n" + "\tb _0809C658\n" + "_0809C624:\n" + "\tmovs r3, 0\n" + "\tmov r9, r3\n" + "\tb _0809C656\n" + "_0809C62A:\n" + "\tmovs r0, 0x1\n" + "\tmov r9, r0\n" + "\tmovs r0, 0\n" + "\tldrsb r0, [r2, r0]\n" + "\tcmp r0, 0x5\n" + "\tble _0809C642\n" + "\tlsls r0, r4, 24\n" + "\tmovs r1, 0xFA\n" + "\tlsls r1, 24\n" + "_0809C63C:\n" + "\tadds r0, r1\n" + "\tlsrs r4, r0, 24\n" + "\tb _0809C648\n" + "_0809C642:\n" + "\tmovs r3, 0x2\n" + "\tmov r8, r3\n" + "_0809C646:\n" + "\tmovs r4, 0\n" + "_0809C648:\n" + "\tmov r0, r9\n" + "\tcmp r0, 0\n" + "\tbeq _0809C656\n" + "\tmov r0, r8\n" + "\tadds r1, r4, 0\n" + "\tbl sub_809AF18\n" + "_0809C656:\n" + "\tmov r0, r9\n" + "_0809C658:\n" + "\tpop {r3,r4}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tpop {r4-r7}\n" + "\tpop {r1}\n" + "\tbx r1"); +} +#endif + +#ifdef NONMATCHING +u8 sub_809C664(void) +{ + s8 r10 = gUnknown_020384E4; + s8 r4 = gUnknown_020384E5; + u8 r8; + u8 r9; + + gPokemonStorageSystemPtr->unk_11df = 0; + gPokemonStorageSystemPtr->unk_11de = 0; + gPokemonStorageSystemPtr->unk_11e3 = 0; + r9 = FALSE; + r8 = 0; + if (gMain.newAndRepeatedKeys & DPAD_UP) + { + if (--r4 < 0) + r4 = 6; + if (r4 != gUnknown_020384E5) + r8 = 1; + } + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + { + if (++r4 > 6) + r4 = 0; + if (r4 != gUnknown_020384E5) + r8 = 1; + } + else if ((gMain.newAndRepeatedKeys & DPAD_LEFT) && gUnknown_020384E5) + { + r8 = 1; + gPokemonStorageSystemPtr->unk_11e2 = gUnknown_020384E5; + r4 = 0; + } + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) + { + if (gUnknown_020384E5 == 0) + { + r8 = 1; + r4 = gPokemonStorageSystemPtr->unk_11e2; + } + else + { + r8 = 6; + r10 = 0; + r4 = 0; + } + } + else + { + if (gMain.newKeys & A_BUTTON) + { + if (gUnknown_020384E5 == 6) + { + if (gPokemonStorageSystemPtr->unk_0005 == 1) + return 4; + r9 = TRUE; + } + else if (sub_809CAB0()) + { + if (gUnknown_020384E9 == 0) + return 8; + switch (sub_809CE4C(0)) + { + case 1: + return 11; + case 2: + return 12; + case 3: + return 13; + case 4: + return 14; + case 5: + return 15; + } + } + } + if (gMain.newKeys & B_BUTTON) + { + if (gPokemonStorageSystemPtr->unk_0005 == 1) + return 16; + r9 = TRUE; + } + if (!r9) + { + r8 = 6; + r10 = 0; + r4 = 0; + } + else if (gMain.newKeys & SELECT_BUTTON) + { + sub_809CD88(); + return 0; + } + } + if (r8) + sub_809AF18(r10, r4); + return r8; +} +#else +__attribute__((naked)) u8 sub_809C664(void) +{ + asm_unified("\tpush {r4-r7,lr}\n" + "\tmov r7, r10\n" + "\tmov r6, r9\n" + "\tmov r5, r8\n" + "\tpush {r5-r7}\n" + "\tldr r0, _0809C6D8 @ =gUnknown_020384E4\n" + "\tldrb r0, [r0]\n" + "\tmov r10, r0\n" + "\tldr r7, _0809C6DC @ =gUnknown_020384E5\n" + "\tldrb r4, [r7]\n" + "\tldr r2, _0809C6E0 @ =gPokemonStorageSystemPtr\n" + "\tldr r5, [r2]\n" + "\tldr r1, _0809C6E4 @ =0x000011df\n" + "\tadds r0, r5, r1\n" + "\tmovs r1, 0\n" + "\tstrb r1, [r0]\n" + "\tldr r3, _0809C6E8 @ =0x000011de\n" + "\tadds r0, r5, r3\n" + "\tstrb r1, [r0]\n" + "\tadds r3, 0x5\n" + "\tadds r0, r5, r3\n" + "\tstrb r1, [r0]\n" + "\tmov r9, r1\n" + "\tmov r8, r1\n" + "\tldr r1, _0809C6EC @ =gMain\n" + "\tldrh r3, [r1, 0x30]\n" + "\tmovs r0, 0x40\n" + "\tands r0, r3\n" + "\tadds r6, r7, 0\n" + "\tmov r12, r2\n" + "\tadds r2, r1, 0\n" + "\tcmp r0, 0\n" + "\tbeq _0809C6A8\n" + "\tb _0809C81C\n" + "_0809C6A8:\n" + "\tmovs r0, 0x80\n" + "\tands r0, r3\n" + "\tcmp r0, 0\n" + "\tbeq _0809C6F0\n" + "\tlsls r0, r4, 24\n" + "\tmovs r1, 0x80\n" + "\tlsls r1, 17\n" + "\tadds r0, r1\n" + "\tlsrs r4, r0, 24\n" + "\tasrs r0, 24\n" + "\tcmp r0, 0x6\n" + "\tble _0809C6C2\n" + "\tmovs r4, 0\n" + "_0809C6C2:\n" + "\tlsls r0, r4, 24\n" + "\tasrs r0, 24\n" + "\tmovs r1, 0\n" + "\tldrsb r1, [r6, r1]\n" + "\tcmp r0, r1\n" + "\tbne _0809C6D0\n" + "\tb _0809C83C\n" + "_0809C6D0:\n" + "\tmovs r2, 0x1\n" + "\tmov r8, r2\n" + "\tb _0809C842\n" + "\t.align 2, 0\n" + "_0809C6D8: .4byte gUnknown_020384E4\n" + "_0809C6DC: .4byte gUnknown_020384E5\n" + "_0809C6E0: .4byte gPokemonStorageSystemPtr\n" + "_0809C6E4: .4byte 0x000011df\n" + "_0809C6E8: .4byte 0x000011de\n" + "_0809C6EC: .4byte gMain\n" + "_0809C6F0:\n" + "\tmovs r0, 0x20\n" + "\tands r0, r3\n" + "\tcmp r0, 0\n" + "\tbeq _0809C714\n" + "\tldrb r1, [r6]\n" + "\tmovs r0, 0\n" + "\tldrsb r0, [r6, r0]\n" + "\tcmp r0, 0\n" + "\tbeq _0809C714\n" + "\tmovs r3, 0x1\n" + "\tmov r8, r3\n" + "\tldr r2, _0809C710 @ =0x000011e2\n" + "\tadds r0, r5, r2\n" + "\tstrb r1, [r0]\n" + "\tmovs r4, 0\n" + "\tb _0809C83C\n" + "\t.align 2, 0\n" + "_0809C710: .4byte 0x000011e2\n" + "_0809C714:\n" + "\tldrh r1, [r2, 0x30]\n" + "\tmovs r0, 0x10\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C748\n" + "\tmovs r0, 0\n" + "\tldrsb r0, [r6, r0]\n" + "\tcmp r0, 0\n" + "\tbne _0809C73C\n" + "\tmovs r3, 0x1\n" + "\tmov r8, r3\n" + "\tmov r1, r12\n" + "\tldr r0, [r1]\n" + "\tldr r2, _0809C738 @ =0x000011e2\n" + "\tadds r0, r2\n" + "\tldrb r4, [r0]\n" + "\tb _0809C83C\n" + "\t.align 2, 0\n" + "_0809C738: .4byte 0x000011e2\n" + "_0809C73C:\n" + "\tmovs r3, 0x6\n" + "\tmov r8, r3\n" + "\tmovs r0, 0\n" + "\tmov r10, r0\n" + "\tmovs r4, 0\n" + "\tb _0809C83C\n" + "_0809C748:\n" + "\tldrh r1, [r2, 0x2E]\n" + "\tmovs r0, 0x1\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C7D0\n" + "\tmovs r0, 0\n" + "\tldrsb r0, [r6, r0]\n" + "\tcmp r0, 0x6\n" + "\tbne _0809C76E\n" + "\tmov r1, r12\n" + "\tldr r0, [r1]\n" + "\tldrb r0, [r0, 0x5]\n" + "\tcmp r0, 0x1\n" + "\tbne _0809C768\n" + "\tmovs r0, 0x4\n" + "\tb _0809C84C\n" + "_0809C768:\n" + "\tmovs r2, 0x1\n" + "\tmov r9, r2\n" + "\tb _0809C7D0\n" + "_0809C76E:\n" + "\tbl sub_809CAB0\n" + "\tlsls r0, 24\n" + "\tcmp r0, 0\n" + "\tbeq _0809C7D0\n" + "\tldr r0, _0809C784 @ =gUnknown_020384E9\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _0809C788\n" + "\tmovs r0, 0x8\n" + "\tb _0809C84C\n" + "\t.align 2, 0\n" + "_0809C784: .4byte gUnknown_020384E9\n" + "_0809C788:\n" + "\tmovs r0, 0\n" + "\tbl sub_809CE4C\n" + "\tsubs r0, 0x1\n" + "\tlsls r0, 24\n" + "\tasrs r0, 24\n" + "\tcmp r0, 0x4\n" + "\tbhi _0809C7D0\n" + "\tlsls r0, 2\n" + "\tldr r1, _0809C7A4 @ =_0809C7A8\n" + "\tadds r0, r1\n" + "\tldr r0, [r0]\n" + "\tmov pc, r0\n" + "\t.align 2, 0\n" + "_0809C7A4: .4byte _0809C7A8\n" + "\t.align 2, 0\n" + "_0809C7A8:\n" + "\t.4byte _0809C7BC\n" + "\t.4byte _0809C7C0\n" + "\t.4byte _0809C7C4\n" + "\t.4byte _0809C7C8\n" + "\t.4byte _0809C7CC\n" + "_0809C7BC:\n" + "\tmovs r0, 0xB\n" + "\tb _0809C84C\n" + "_0809C7C0:\n" + "\tmovs r0, 0xC\n" + "\tb _0809C84C\n" + "_0809C7C4:\n" + "\tmovs r0, 0xD\n" + "\tb _0809C84C\n" + "_0809C7C8:\n" + "\tmovs r0, 0xE\n" + "\tb _0809C84C\n" + "_0809C7CC:\n" + "\tmovs r0, 0xF\n" + "\tb _0809C84C\n" + "_0809C7D0:\n" + "\tldr r2, _0809C7EC @ =gMain\n" + "\tldrh r1, [r2, 0x2E]\n" + "\tmovs r0, 0x2\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C7F8\n" + "\tldr r0, _0809C7F0 @ =gPokemonStorageSystemPtr\n" + "\tldr r0, [r0]\n" + "\tldrb r0, [r0, 0x5]\n" + "\tcmp r0, 0x1\n" + "\tbne _0809C7F4\n" + "\tmovs r0, 0x10\n" + "\tb _0809C84C\n" + "\t.align 2, 0\n" + "_0809C7EC: .4byte gMain\n" + "_0809C7F0: .4byte gPokemonStorageSystemPtr\n" + "_0809C7F4:\n" + "\tmovs r3, 0x1\n" + "\tmov r9, r3\n" + "_0809C7F8:\n" + "\tmov r0, r9\n" + "\tcmp r0, 0\n" + "\tbeq _0809C80A\n" + "\tmovs r1, 0x6\n" + "\tmov r8, r1\n" + "\tmovs r2, 0\n" + "\tmov r10, r2\n" + "\tmovs r4, 0\n" + "\tb _0809C83C\n" + "_0809C80A:\n" + "\tldrh r1, [r2, 0x2E]\n" + "\tmovs r0, 0x4\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0809C83C\n" + "\tbl sub_809CD88\n" + "\tmovs r0, 0\n" + "\tb _0809C84C\n" + "_0809C81C:\n" + "\tlsls r0, r4, 24\n" + "\tmovs r3, 0xFF\n" + "\tlsls r3, 24\n" + "\tadds r0, r3\n" + "\tlsrs r4, r0, 24\n" + "\tcmp r0, 0\n" + "\tbge _0809C82C\n" + "\tmovs r4, 0x6\n" + "_0809C82C:\n" + "\tlsls r0, r4, 24\n" + "\tasrs r0, 24\n" + "\tmovs r1, 0\n" + "\tldrsb r1, [r7, r1]\n" + "\tcmp r0, r1\n" + "\tbeq _0809C83C\n" + "\tmovs r0, 0x1\n" + "\tmov r8, r0\n" + "_0809C83C:\n" + "\tmov r1, r8\n" + "\tcmp r1, 0\n" + "\tbeq _0809C84A\n" + "_0809C842:\n" + "\tmov r0, r10\n" + "\tadds r1, r4, 0\n" + "\tbl sub_809AF18\n" + "_0809C84A:\n" + "\tmov r0, r8\n" + "_0809C84C:\n" + "\tpop {r3-r5}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tmov r10, r5\n" + "\tpop {r4-r7}\n" + "\tpop {r1}\n" + "\tbx r1"); +} +#endif diff --git a/src/pokemon/pokemon_storage_system_5.c b/src/pokemon/pokemon_storage_system_5.c new file mode 100644 index 000000000..b7c3d42f5 --- /dev/null +++ b/src/pokemon/pokemon_storage_system_5.c @@ -0,0 +1,16 @@ + +// Includes +#include "global.h" +#include "pokemon_storage_system.h" + +// Static type declarations + +// Static RAM declarations + +EWRAM_DATA struct UnkStruct_2000020 *gUnknown_020384EC = NULL; + +// Static ROM declarations + +// .rodata + +// .text diff --git a/src/pokemon/pokemon_summary_screen.c b/src/pokemon/pokemon_summary_screen.c index 96f9c44f9..325a94117 100644 --- a/src/pokemon/pokemon_summary_screen.c +++ b/src/pokemon/pokemon_summary_screen.c @@ -144,7 +144,6 @@ extern const u8 gUnknown_08E74E88[]; extern const u8 gUnknown_08E73508[]; extern const u8 gStatusScreen_Gfx[]; extern const u8 gFontDefaultPalette[]; -extern const u8 gUnknownPalette_81E6692[]; extern const u8 gAbilityNames[][13]; extern const u8 * const gAbilityDescriptions[]; extern const u8 * const gContestEffectStrings[]; @@ -931,21 +930,21 @@ static bool8 LoadPokemonSummaryScreenGraphics(void) static void sub_809E044(void) { - LoadPalette(&gUnknownPalette_81E6692[28], 129, 2); - LoadPalette(&gUnknownPalette_81E6692[30], 136, 2); - LoadPalette(&gUnknownPalette_81E6692[28], 143, 2); - LoadPalette(&gUnknownPalette_81E6692[30], 137, 2); - LoadPalette(&gUnknownPalette_81E6692[12], 209, 4); - LoadPalette(&gUnknownPalette_81E6692[20], 211, 4); - LoadPalette(&gUnknownPalette_81E6692[28], 213, 4); - LoadPalette(&gUnknownPalette_81E6692[12], 215, 4); - LoadPalette(&gUnknownPalette_81E6692[8], 217, 4); - LoadPalette(&gUnknownPalette_81E6692[16], 219, 4); - LoadPalette(&gUnknownPalette_81E6692[4], 221, 2); - LoadPalette(&gUnknownPalette_81E6692[6], 222, 2); - LoadPalette(&gUnknownPalette_81E6692[2], 223, 2); + LoadPalette(gUnknownPalette_81E6692 + 14, 129, 2); + LoadPalette(gUnknownPalette_81E6692 + 15, 136, 2); + LoadPalette(gUnknownPalette_81E6692 + 14, 143, 2); + LoadPalette(gUnknownPalette_81E6692 + 15, 137, 2); + LoadPalette(gUnknownPalette_81E6692 + 6, 209, 4); + LoadPalette(gUnknownPalette_81E6692 + 10, 211, 4); + LoadPalette(gUnknownPalette_81E6692 + 14, 213, 4); + LoadPalette(gUnknownPalette_81E6692 + 6, 215, 4); + LoadPalette(gUnknownPalette_81E6692 + 4, 217, 4); + LoadPalette(gUnknownPalette_81E6692 + 8, 219, 4); + LoadPalette(gUnknownPalette_81E6692 + 2, 221, 2); + LoadPalette(gUnknownPalette_81E6692 + 3, 222, 2); + LoadPalette(gUnknownPalette_81E6692 + 1, 223, 2); LoadPalette(gFontDefaultPalette, 240, 32); - LoadPalette(&gUnknownPalette_81E6692[6], 249, 2); + LoadPalette(gUnknownPalette_81E6692 + 3, 249, 2); } static void SummaryScreenExit(u8 taskId) @@ -2245,7 +2244,7 @@ static void sub_809F678(struct Pokemon *mon) else { struct BoxPokemon *mons = pssData.monList.boxMons; - sub_803B4B4(&mons[pssData.monIndex], mon); + ExpandBoxMon(&mons[pssData.monIndex], mon); } } diff --git a/src/pokenav_before.c b/src/pokenav_before.c index b31be2ce1..600c5aba8 100644 --- a/src/pokenav_before.c +++ b/src/pokenav_before.c @@ -102,7 +102,6 @@ extern const u16 gPokenavConditionSearch2_Pal[]; extern const u8 gUnknown_083E0334[]; extern const u16 gUnknown_083E02B4[]; extern const u8 gPokenavConditionSearch2_Gfx[]; -extern const u8 gUnknownPalette_81E6692[]; extern const u8 gUnknown_083E0254[]; extern const u8 gUnknown_08E9FEB4[]; extern const u8 gUnknown_083E01AC[]; diff --git a/src/rom_8077ABC.c b/src/rom_8077ABC.c index 11a71155d..b84c431f7 100644 --- a/src/rom_8077ABC.c +++ b/src/rom_8077ABC.c @@ -1970,7 +1970,7 @@ void sub_807A0F4(struct Sprite *sprite) DestroySpriteAndFreeResources(sprite); } -int sub_807A100(u8 slot, u8 a2) +s16 sub_807A100(u8 slot, u8 a2) { u16 species; u32 personality; diff --git a/src/scene/hall_of_fame.c b/src/scene/hall_of_fame.c index e486c65a3..2b790e97d 100644 --- a/src/scene/hall_of_fame.c +++ b/src/scene/hall_of_fame.c @@ -18,6 +18,9 @@ #include "random.h" #include "scanline_effect.h" #include "trig.h" +#include "hof_pc.h" +#include "credits.h" +#include "pc_screen_effect.h" #include "ewram.h" static EWRAM_DATA u32 sUnknown_0203931C = 0; @@ -88,15 +91,6 @@ static u32 HallOfFame_LoadPokemonPic(u16 species, s16 posX, s16 posY, u16 pokeID static u32 HallOfFame_LoadTrainerPic(u16 trainerPicID, s16 posX, s16 posY, u16 a3); static bool8 sub_81438C4(void); -// functions from different files -void sub_81439D0(void); -void sub_80C5CD4(void*); // ? -void sub_80C5E38(void*); // ? -bool8 sub_80C5DCC(void); -bool8 sub_80C5F98(void); -void ReturnFromHallOfFamePC(void); -u16 SpeciesToPokedexNum(u16 species); - // data and gfx static const struct CompressedSpriteSheet sHallOfFame_ConfettiSpriteSheet = @@ -130,9 +124,9 @@ static const s16 sHallOfFame_MonsHalfTeamPositions[3][4] = {-41, 214, 184, 64} }; -static const struct HallofFameMon sDummyFameMon = -{ - 0x3EA03EA, 0, 0, 0, {0} +static const struct PCScreenEffectStruct sPCScreenEffectTemplate = { + .tileTag = 0x3ea, + .paletteTag = 0x3ea }; static const u8 sUnused2[6] = {2, 1, 3, 6, 4, 5}; @@ -800,20 +794,15 @@ void sub_81428CC(void) } break; case 3: - { - struct HallofFameMons* fameMons; - - REG_BLDCNT = 0; - REG_BLDALPHA = 0; - REG_BLDY = 0; - sub_81435B8(); + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + REG_BLDY = 0; + sub_81435B8(); - fameMons = eHallOfFameMons1; - fameMons->mons[0] = sDummyFameMon; + eHOFPCScreenEffect = sPCScreenEffectTemplate; - sub_80C5CD4(fameMons); - gMain.state++; - } + sub_80C5CD4(&eHOFPCScreenEffect); + gMain.state++; break; case 4: AnimateSprites(); @@ -1022,12 +1011,9 @@ static void sub_8142DF4(u8 taskID) static void sub_8142F78(u8 taskID) { - struct HallofFameMons* fameMons; - CpuSet(gPlttBufferFaded, gPlttBufferUnfaded, 0x200); - fameMons = eHallOfFameMons1; - fameMons->mons[0] = sDummyFameMon; - sub_80C5E38(fameMons); + eHOFPCScreenEffect = sPCScreenEffectTemplate; + sub_80C5E38(&eHOFPCScreenEffect); gTasks[taskID].func = sub_8142FCC; } |