summaryrefslogtreecommitdiff
path: root/arm9/src
diff options
context:
space:
mode:
authorCleverking2003 <30466983+Cleverking2003@users.noreply.github.com>2020-08-16 21:35:27 +0300
committerGitHub <noreply@github.com>2020-08-16 21:35:27 +0300
commit133a7967098a49cebc68c395df88d87485328175 (patch)
treeb60434a70296a13034d6c92440fff837b4b5bed5 /arm9/src
parenta82d0d55a67b12757b185fd149d6a14dcc7cad02 (diff)
parentf249e22e6cfd180492054f8ef321fa75495f2daf (diff)
Merge pull request #262 from PikalaxALT/pikalax_work
Decompile bag.s
Diffstat (limited to 'arm9/src')
-rw-r--r--arm9/src/bag.c463
-rw-r--r--arm9/src/main.c24
-rw-r--r--arm9/src/pokemon.c10
-rw-r--r--arm9/src/sound.c2
4 files changed, 482 insertions, 17 deletions
diff --git a/arm9/src/bag.c b/arm9/src/bag.c
new file mode 100644
index 00000000..57609a8f
--- /dev/null
+++ b/arm9/src/bag.c
@@ -0,0 +1,463 @@
+#include "global.h"
+#include "MI_memory.h"
+#include "bag.h"
+#include "itemtool.h"
+#include "heap.h"
+
+#pragma thumb on
+
+u32 Sav2_Bag_sizeof(void)
+{
+ return sizeof(struct Bag);
+}
+
+struct Bag * Sav2_Bag_new(u32 heap_id)
+{
+ struct Bag * ret = (struct Bag *)AllocFromHeap(heap_id, sizeof(struct Bag));
+ Sav2_Bag_init(ret);
+ return ret;
+}
+
+void Sav2_Bag_init(struct Bag * bag)
+{
+ MI_CpuClear16(bag, sizeof(struct Bag));
+}
+
+void Sav2_Bag_copy(const struct Bag * src, struct Bag * dest)
+{
+ MI_CpuCopy8(src, dest, sizeof(struct Bag));
+}
+
+u32 Bag_GetRegisteredItem(struct Bag * bag)
+{
+ return bag->registeredItem;
+}
+
+void Bag_SetRegisteredItem(struct Bag * bag, u32 item)
+{
+ bag->registeredItem = item;
+}
+
+u32 Bag_GetItemPocket(struct Bag * bag, u16 item_id, struct ItemSlot ** slot_p, u32 * count_p, u32 heap_id)
+{
+ u32 pocket = GetItemAttr(item_id, 5, heap_id);
+ switch (pocket)
+ {
+ case POCKET_KEY_ITEMS:
+ *slot_p = bag->keyItems;
+ *count_p = NUM_BAG_KEY_ITEMS;
+ break;
+ case POCKET_ITEMS:
+ *slot_p = bag->items;
+ *count_p = NUM_BAG_ITEMS;
+ break;
+ case POCKET_BERRIES:
+ *slot_p = bag->berries;
+ *count_p = NUM_BAG_BERRIES;
+ break;
+ case POCKET_MEDICINE:
+ *slot_p = bag->medicine;
+ *count_p = NUM_BAG_MEDICINE;
+ break;
+ case POCKET_BALLS:
+ *slot_p = bag->balls;
+ *count_p = NUM_BAG_BALLS;
+ break;
+ case POCKET_BATTLE_ITEMS:
+ *slot_p = bag->battleItems;
+ *count_p = NUM_BAG_BATTLE_ITEMS;
+ break;
+ case POCKET_MAIL:
+ *slot_p = bag->mail;
+ *count_p = NUM_BAG_MAIL;
+ break;
+ case POCKET_TMHMS:
+ *slot_p = bag->TMsHMs;
+ *count_p = NUM_BAG_TMS_HMS;
+ break;
+ }
+ return pocket;
+}
+
+struct ItemSlot * Pocket_GetItemSlotForAdd(struct ItemSlot * slots, u32 count, u16 item_id, u16 quantity, u16 maxquantity)
+{
+ int i;
+ int found = -1;
+ for (i = 0; i < count; i++)
+ {
+ if (slots[i].id == item_id)
+ {
+ if (quantity + slots[i].quantity > maxquantity)
+ return NULL;
+ return &slots[i];
+ }
+ if (found == -1 && slots[i].id == ITEM_NONE && slots[i].quantity == 0)
+ {
+ found = i;
+ }
+ }
+ if (found == -1)
+ return NULL;
+ return &slots[found];
+}
+
+struct ItemSlot * Bag_GetItemSlotForAdd(struct Bag * bag, u16 item_id, u16 quantity, u32 heap_id)
+{
+ struct ItemSlot * slots;
+ u32 count;
+ u32 pocket = Bag_GetItemPocket(bag, item_id, &slots, &count, heap_id);
+ if (pocket == POCKET_TMHMS)
+ {
+ return Pocket_GetItemSlotForAdd(slots, count, item_id, quantity, 99);
+ }
+ else
+ {
+ return Pocket_GetItemSlotForAdd(slots, count, item_id, quantity, 999);
+ }
+}
+
+BOOL Bag_HasSpaceForItem(struct Bag * bag, u16 item_id, u16 quantity, u32 heap_id)
+{
+ return Bag_GetItemSlotForAdd(bag, item_id, quantity, heap_id) != NULL;
+}
+
+BOOL Bag_AddItem(struct Bag * bag, u16 item_id, u16 quantity, u32 heap_id)
+{
+ struct ItemSlot * slots = Bag_GetItemSlotForAdd(bag, item_id, quantity, heap_id);
+ if (slots == NULL)
+ return FALSE;
+ slots->id = item_id;
+ slots->quantity += quantity;
+ u32 count;
+ u32 pocket = Bag_GetItemPocket(bag, item_id, &slots, &count, heap_id);
+ if (pocket == POCKET_TMHMS || pocket == POCKET_BERRIES)
+ {
+ SortPocket(slots, count);
+ }
+ return TRUE;
+}
+
+struct ItemSlot * Pocket_GetItemSlotForRemove(struct ItemSlot * slots, u32 count, u16 item_id, u16 quantity)
+{
+ int i;
+ for (i = 0; i < count; i++)
+ {
+ if (slots[i].id == item_id)
+ {
+ if (slots[i].quantity >= quantity)
+ return &slots[i];
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+struct ItemSlot * Bag_GetItemSlotForRemove(struct Bag * bag, u16 item_id, u16 quantity, u32 heap_id)
+{
+ struct ItemSlot * slots;
+ u32 count;
+ (void)Bag_GetItemPocket(bag, item_id, &slots, &count, heap_id);
+ return Pocket_GetItemSlotForRemove(slots, count, item_id, quantity);
+}
+
+BOOL Bag_TakeItem(struct Bag * bag, u16 item_id, u16 quantity, u32 heap_id)
+{
+ struct ItemSlot * slots = Bag_GetItemSlotForRemove(bag, item_id, quantity, heap_id);
+ if (slots == NULL)
+ return FALSE;
+ slots->quantity -= quantity;
+ if (slots->quantity == 0)
+ slots->id = ITEM_NONE;
+ u32 count;
+ (void)Bag_GetItemPocket(bag, item_id, &slots, &count, heap_id);
+ PocketCompaction(slots, count);
+ return TRUE;
+}
+
+BOOL Pocket_TakeItem(struct ItemSlot * slots, u32 count, u16 item_id, u16 quantity)
+{
+ struct ItemSlot * slot = Pocket_GetItemSlotForRemove(slots, count, item_id, quantity);
+ if (slot == NULL)
+ return FALSE;
+ slot->quantity -= quantity;
+ if (slot->quantity == 0)
+ slot->id = ITEM_NONE;
+ PocketCompaction(slots, count);
+ return TRUE;
+}
+
+BOOL Bag_HasItem(struct Bag * bag, u16 item_id, u16 quantity, u32 heap_id)
+{
+ return Bag_GetItemSlotForRemove(bag, item_id, quantity, heap_id) != NULL;
+}
+
+BOOL Bag_PocketNotEmpty(struct Bag * bag, u32 pocket)
+{
+ struct ItemSlot * slots;
+ u32 count;
+ switch (pocket)
+ {
+ case POCKET_KEY_ITEMS:
+ slots = bag->keyItems;
+ count = NUM_BAG_KEY_ITEMS;
+ break;
+ case POCKET_ITEMS:
+ slots = bag->items;
+ count = NUM_BAG_ITEMS;
+ break;
+ case POCKET_BERRIES:
+ slots = bag->berries;
+ count = NUM_BAG_BERRIES;
+ break;
+ case POCKET_MEDICINE:
+ slots = bag->medicine;
+ count = NUM_BAG_MEDICINE;
+ break;
+ case POCKET_BALLS:
+ slots = bag->balls;
+ count = NUM_BAG_BALLS;
+ break;
+ case POCKET_BATTLE_ITEMS:
+ slots = bag->battleItems;
+ count = NUM_BAG_BATTLE_ITEMS;
+ break;
+ case POCKET_MAIL:
+ slots = bag->mail;
+ count = NUM_BAG_MAIL;
+ break;
+ case POCKET_TMHMS:
+ slots = bag->TMsHMs;
+ count = NUM_BAG_TMS_HMS;
+ break;
+ default:
+ return FALSE;
+ }
+ int i;
+ for (i = 0; i < count; i++)
+ {
+ if (slots[i].id != ITEM_NONE)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+u16 Bag_GetQuantity(struct Bag * bag, u16 item_id, u32 heap_id)
+{
+ struct ItemSlot * slot = Bag_GetItemSlotForRemove(bag, item_id, 1, heap_id);
+ if (slot == NULL)
+ return 0;
+ return slot->quantity;
+}
+
+u16 Pocket_GetQuantity(struct ItemSlot * slots, u32 count, u16 item_id)
+{
+ struct ItemSlot * slot = Pocket_GetItemSlotForRemove(slots, count, item_id, 1);
+ if (slot == NULL)
+ return 0;
+ return slot->quantity;
+}
+
+void SwapItemSlots(struct ItemSlot * a, struct ItemSlot * b)
+{
+ struct ItemSlot tmp;
+
+ tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
+
+void PocketCompaction(struct ItemSlot * slots, u32 count)
+{
+ int i, j;
+ for (i = 0; i < count - 1; i++)
+ {
+ for (j = i + 1; j < count; j++)
+ {
+ if (slots[i].quantity == 0)
+ {
+ SwapItemSlots(&slots[i], &slots[j]);
+ }
+ }
+ }
+}
+
+void SortPocket(struct ItemSlot * slots, u32 count)
+{
+ int i, j;
+ for (i = 0; i < count - 1; i++)
+ {
+ for (j = i + 1; j < count; j++)
+ {
+ if (slots[i].quantity == 0 || (slots[j].quantity != 0 && slots[i].id > slots[j].id))
+ {
+ SwapItemSlots(&slots[i], &slots[j]);
+ }
+ }
+ }
+}
+
+extern struct BagView * BagView_new(u8 heap_id);
+extern void BagView_setitem(struct BagView * view, struct ItemSlot * slot, u8 pocket, u8 idx);
+
+struct BagView * CreateBagView(struct Bag * bag, const u8 * pockets, u32 heap_id)
+{
+ struct BagView * view = BagView_new((u8)heap_id);
+ int i;
+ for (i = 0; pockets[i] != 0xFF; i++)
+ {
+ switch (pockets[i])
+ {
+ case POCKET_KEY_ITEMS:
+ BagView_setitem(view, bag->keyItems, POCKET_KEY_ITEMS, (u8)i);
+ break;
+ case POCKET_ITEMS:
+ BagView_setitem(view, bag->items, POCKET_ITEMS, (u8)i);
+ break;
+ case POCKET_BERRIES:
+ BagView_setitem(view, bag->berries, POCKET_BERRIES, (u8)i);
+ break;
+ case POCKET_MEDICINE:
+ BagView_setitem(view, bag->medicine, POCKET_MEDICINE, (u8)i);
+ break;
+ case POCKET_BALLS:
+ BagView_setitem(view, bag->balls, POCKET_BALLS, (u8)i);
+ break;
+ case POCKET_BATTLE_ITEMS:
+ BagView_setitem(view, bag->battleItems, POCKET_BATTLE_ITEMS, (u8)i);
+ break;
+ case POCKET_MAIL:
+ BagView_setitem(view, bag->mail, POCKET_MAIL, (u8)i);
+ break;
+ case POCKET_TMHMS:
+ BagView_setitem(view, bag->TMsHMs, POCKET_TMHMS, (u8)i);
+ break;
+ }
+ }
+ return view;
+}
+
+struct ItemSlot * Bag_GetPocketSlotN(struct Bag * bag, u32 pocket, u32 slot)
+{
+ struct ItemSlot * slots;
+ u32 count;
+ switch (pocket)
+ {
+ case POCKET_KEY_ITEMS:
+ slots = bag->keyItems;
+ count = NUM_BAG_KEY_ITEMS;
+ break;
+ case POCKET_ITEMS:
+ slots = bag->items;
+ count = NUM_BAG_ITEMS;
+ break;
+ case POCKET_BERRIES:
+ slots = bag->berries;
+ count = NUM_BAG_BERRIES;
+ break;
+ case POCKET_MEDICINE:
+ slots = bag->medicine;
+ count = NUM_BAG_MEDICINE;
+ break;
+ case POCKET_BALLS:
+ slots = bag->balls;
+ count = NUM_BAG_BALLS;
+ break;
+ case POCKET_BATTLE_ITEMS:
+ slots = bag->battleItems;
+ count = NUM_BAG_BATTLE_ITEMS;
+ break;
+ case POCKET_MAIL:
+ slots = bag->mail;
+ count = NUM_BAG_MAIL;
+ break;
+ case POCKET_TMHMS:
+ slots = bag->TMsHMs;
+ count = NUM_BAG_TMS_HMS;
+ break;
+ }
+ if (slot >= count)
+ return NULL;
+ return &slots[slot];
+}
+
+struct Bag * Sav2_Bag_get(struct SaveBlock2 * sav2)
+{
+ return (struct Bag *)SavArray_get(sav2, 3);
+}
+
+struct UnkStruct_0206F164 * FUN_0206F164(u32 heap_id)
+{
+ struct UnkStruct_0206F164 * ret = (struct UnkStruct_0206F164 *)AllocFromHeap(heap_id, sizeof(struct UnkStruct_0206F164));
+ MI_CpuClear16(ret, sizeof(struct UnkStruct_0206F164));
+ return ret;
+}
+
+void FUN_0206F17C(struct UnkStruct_0206F164 * a0, u32 a1, u8 * a2, u8 * a3)
+{
+ *a2 = a0->unk_08[a1];
+ *a3 = a0->unk_00[a1];
+}
+
+u16 FUN_0206F18C(struct UnkStruct_0206F164 * a0)
+{
+ return a0->unk_10;
+}
+
+void FUN_0206F190(struct UnkStruct_0206F164 * a0, u32 a1, u8 a2, u8 a3)
+{
+ a0->unk_08[a1] = a2;
+ a0->unk_00[a1] = a3;
+}
+
+void FUN_0206F19C(struct UnkStruct_0206F164 * a0, u16 a1)
+{
+ a0->unk_10 = a1;
+}
+
+void FUN_0206F1A0(struct UnkStruct_0206F164 * a0, u32 a1, u8 * a2, u8 * a3)
+{
+ *a2 = a0->unk_19[a1];
+ *a3 = a0->unk_14[a1];
+}
+
+u16 FUN_0206F1AC(struct UnkStruct_0206F164 * a0)
+{
+ return a0->unk_1e;
+}
+
+u16 FUN_0206F1B0(struct UnkStruct_0206F164 * a0)
+{
+ return a0->unk_20;
+}
+
+u16 FUN_0206F1B4(struct UnkStruct_0206F164 * a0)
+{
+ return a0->unk_22;
+}
+
+void FUN_0206F1B8(struct UnkStruct_0206F164 * a0, u32 a1, u8 a2, u8 a3)
+{
+ a0->unk_19[a1] = a2;
+ a0->unk_14[a1] = a3;
+}
+
+void FUN_0206F1C0(struct UnkStruct_0206F164 * a0)
+{
+ u32 i;
+ for (i = 0; i < 5; i++)
+ {
+ FUN_0206F1B8(a0, i, 0, 0);
+ }
+ FUN_0206F1EC(a0, 0);
+}
+
+void FUN_0206F1E4(struct UnkStruct_0206F164 * a0, u16 a1, u16 a2)
+{
+ a0->unk_1e = a1;
+ a0->unk_20 = a2;
+}
+
+void FUN_0206F1EC(struct UnkStruct_0206F164 * a0, u16 a1)
+{
+ a0->unk_22 = a1;
+}
diff --git a/arm9/src/main.c b/arm9/src/main.c
index 3de65c45..a81db33d 100644
--- a/arm9/src/main.c
+++ b/arm9/src/main.c
@@ -32,8 +32,8 @@ extern void FUN_02022294(void);
extern void FUN_0201259C(void);
extern void FUN_02002C14(void);
extern void FUN_02002C50(int, int);
-extern struct SaveBlock2 * FUN_0202254C(void);
-extern u32 FUN_02029EF8(struct SaveBlock2 *);
+extern struct SaveBlock2 * SaveBlock2_new(void);
+extern void * FUN_02029EF8(struct SaveBlock2 *);
extern void FUN_02020AFC(void);
extern int FUN_020337E8(int);
extern void FUN_02034188(int, int);
@@ -73,7 +73,7 @@ THUMB_FUNC void NitroMain(void)
FUN_02002C50(1, 3);
FUN_02002C50(3, 3);
gBacklightTop.unk18 = -1;
- gBacklightTop.unk20 = FUN_0202254C();
+ gBacklightTop.unk20 = SaveBlock2_new();
InitSoundData(FUN_02029EF8(gBacklightTop.unk20), Sav2_PlayerData_GetOptionsAddr(gBacklightTop.unk20));
FUN_02020AFC();
if (FUN_020337E8(3) == 3)
@@ -87,15 +87,17 @@ THUMB_FUNC void NitroMain(void)
switch (OS_GetResetParameter())
{
case 0:
+ // Title Demo
gBacklightTop.unk1C = 0;
FUN_02000E7C(FS_OVERLAY_ID(MODULE_63), &MOD63_021DBE18);
break;
case 1:
+ // Reset transition?
gBacklightTop.unk1C = 1;
FUN_02000E7C(FS_OVERLAY_ID(MODULE_52), &MOD52_021D76C8);
break;
default:
- ErrorHandling();
+ GF_ASSERT(0);
break;
}
}
@@ -108,7 +110,7 @@ THUMB_FUNC void NitroMain(void)
for (;;)
{
FUN_02000EE8();
- FUN_02000FE8();
+ HandleDSLidAction();
FUN_02016464();
if ((gMain.unk38 & SOFT_RESET_KEY) == SOFT_RESET_KEY && !gUnk021C4918.unk8) // soft reset?
{
@@ -215,7 +217,7 @@ THUMB_FUNC void FUN_02000EE8(void)
}
}
-extern void FUN_0200E3A0(int, int);
+extern void FUN_0200E3A0(PMLCDTarget, int);
extern BOOL FUN_02032DAC(void);
extern void FUN_020225F8(void);
extern void FUN_0202287C(void);
@@ -223,8 +225,8 @@ extern void FUN_0202287C(void);
// No Return
THUMB_FUNC void DoSoftReset(u32 parameter)
{
- FUN_0200E3A0(0, 0x7FFF);
- FUN_0200E3A0(1, 0x7FFF);
+ FUN_0200E3A0(PM_LCD_TOP, 0x7FFF);
+ FUN_0200E3A0(PM_LCD_BOTTOM, 0x7FFF);
if (FUN_02032DAC())
{
FUN_020225F8();
@@ -232,7 +234,7 @@ THUMB_FUNC void DoSoftReset(u32 parameter)
}
do
{
- FUN_02000FE8();
+ HandleDSLidAction();
FUN_02000EC8(parameter);
} while (1);
}
@@ -256,7 +258,7 @@ THUMB_FUNC void FUN_02000F4C(u32 arg0, u32 arg1)
FUN_02032DAC();
while (1)
{
- FUN_02000FE8();
+ HandleDSLidAction();
FUN_02016464();
if (gMain.unk48 & 1)
break;
@@ -285,7 +287,7 @@ THUMB_FUNC void InitializeMainRNG(void)
extern void FUN_0201CE04(void);
extern void FUN_0201CDD0(void);
-THUMB_FUNC void FUN_02000FE8(void)
+THUMB_FUNC void HandleDSLidAction(void)
{
PMBackLightSwitch top, bottom;
if (PAD_DetectFold())
diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c
index 05df8811..dbf86d8a 100644
--- a/arm9/src/pokemon.c
+++ b/arm9/src/pokemon.c
@@ -32,7 +32,7 @@ u8 CalcShininessByOtIdAndPersonality(u32 otid, u32 pid);
void InitBoxMonMoveset(struct BoxPokemon * boxmon);
u32 FUN_020696A8(struct BoxPokemon * boxmon, u16 move);
void FUN_02069718(struct BoxPokemon * boxmon, u16 move);
-void FUN_020697D4(struct BoxPokemon * boxmon, u16 move, u8 slot);
+void BoxMonSetMoveInSlot(struct BoxPokemon * boxmon, u16 move, u8 slot);
void FUN_020698E8(struct BoxPokemon * boxmon, int slot1, int slot2);
s8 FUN_02069BD0(struct BoxPokemon * boxmon, int flavor);
s8 FUN_02069BE4(u32 personality, int flavor);
@@ -2825,7 +2825,7 @@ u32 FUN_020696A8(struct BoxPokemon * boxmon, u16 move)
cur_move = (u16)GetBoxMonData(boxmon, MON_DATA_MOVE1 + i, NULL);
if (cur_move == MOVE_NONE)
{
- FUN_020697D4(boxmon, move, (u8)i);
+ BoxMonSetMoveInSlot(boxmon, move, (u8)i);
ret = move;
break;
}
@@ -2873,12 +2873,12 @@ void FUN_02069718(struct BoxPokemon * boxmon, u16 move)
ReleaseBoxMonLock(boxmon, decry);
}
-void FUN_020697CC(struct Pokemon * pokemon, u16 move, u8 slot)
+void MonSetMoveInSlot(struct Pokemon * pokemon, u16 move, u8 slot)
{
- FUN_020697D4(&pokemon->box, move, slot);
+ BoxMonSetMoveInSlot(&pokemon->box, move, slot);
}
-void FUN_020697D4(struct BoxPokemon * boxmon, u16 move, u8 slot)
+void BoxMonSetMoveInSlot(struct BoxPokemon * boxmon, u16 move, u8 slot)
{
u8 ppUp;
u8 pp;
diff --git a/arm9/src/sound.c b/arm9/src/sound.c
index d971872f..dd928287 100644
--- a/arm9/src/sound.c
+++ b/arm9/src/sound.c
@@ -25,7 +25,7 @@ extern void FUN_0200538C(int, int, int);
extern BOOL FUN_02005404(void);
extern void FUN_02005CFC(void);
-void InitSoundData(u32 a0, struct Options * a1)
+void InitSoundData(void * a0, struct Options * a1)
{
struct SoundData * sdat = GetSoundDataPointer();
SDAT_Init();