mirror of
https://github.com/pret/pmd-sky.git
synced 2026-09-26 12:17:30 -05:00
Decomp CountNbItemsOfTypeInBag and HasStorableItems
Decompile from asm: CountNbItemsOfTypeInBag 0x0200EE4C HasStorableItems 0x0200F0FC CountNbItemsOfTypeInBag counts every slot whose id matches, without checking the existence flag, so empty slots are counted when the caller asks for whatever id they hold. That is what the target does; it is not an omission here. HasStorableItems checks the existence flag through the same explicit bool8 the other bag walkers use, then calls IsStorableItem, which is already decompiled in item_util_4.c, and returns on the first slot satisfying both. HasStorableItems sits at a lower address than GetItemIndex, so it is prepended to that file. The extern for BAG_ITEMS_PTR_MIRROR was below the existing function and is moved to the top, above both, since the new first function needs it too. No comments are added to any pmd-sky file. Authored by Claude (Opus 5) under human direction. Confirmed by a matching build: build/pmdsky.us/pmdsky.us.nds: OK. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,4 +2,3 @@
|
||||
.public AreItemsEquivalent
|
||||
.public BAG_ITEMS_PTR_MIRROR
|
||||
.public GetItemCategoryVeneer
|
||||
.public IsStorableItem
|
||||
|
||||
@@ -1,29 +1,8 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "main_0200EE4C.inc"
|
||||
.include "main_0200EE88.inc"
|
||||
|
||||
.text
|
||||
|
||||
arm_func_start CountNbItemsOfTypeInBag
|
||||
CountNbItemsOfTypeInBag: ; 0x0200EE4C
|
||||
ldr r1, _0200EE84 ; =BAG_ITEMS_PTR_MIRROR
|
||||
mov r3, #0
|
||||
ldr r1, [r1]
|
||||
mov ip, r3
|
||||
ldr r2, [r1, #0x384]
|
||||
_0200EE60:
|
||||
ldrsh r1, [r2, #4]
|
||||
add ip, ip, #1
|
||||
add r2, r2, #6
|
||||
cmp r1, r0
|
||||
addeq r3, r3, #1
|
||||
cmp ip, #0x32
|
||||
blt _0200EE60
|
||||
mov r0, r3
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_0200EE84: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end CountNbItemsOfTypeInBag
|
||||
|
||||
arm_func_start CountItemTypeInBag
|
||||
CountItemTypeInBag: ; 0x0200EE88
|
||||
stmdb sp!, {r3, r4, r5, r6, r7, lr}
|
||||
@@ -122,37 +122,3 @@ _0200F0D0:
|
||||
.align 2, 0
|
||||
_0200F0E0: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end IsItemForSpecialSpawnInBag
|
||||
|
||||
arm_func_start HasStorableItems
|
||||
HasStorableItems: ; 0x0200F0E4
|
||||
stmdb sp!, {r3, r4, r5, r6, r7, lr}
|
||||
ldr r0, _0200F148 ; =BAG_ITEMS_PTR_MIRROR
|
||||
mov r7, #0
|
||||
ldr r0, [r0]
|
||||
mov r4, r7
|
||||
ldr r6, [r0, #0x384]
|
||||
mov r5, #1
|
||||
b _0200F138
|
||||
_0200F104:
|
||||
ldrb r0, [r6]
|
||||
tst r0, #1
|
||||
movne r0, r5
|
||||
moveq r0, r4
|
||||
tst r0, #0xff
|
||||
beq _0200F130
|
||||
ldrsh r0, [r6, #4]
|
||||
bl IsStorableItem
|
||||
cmp r0, #0
|
||||
movne r0, #1
|
||||
ldmneia sp!, {r3, r4, r5, r6, r7, pc}
|
||||
_0200F130:
|
||||
add r7, r7, #1
|
||||
add r6, r6, #6
|
||||
_0200F138:
|
||||
cmp r7, #0x32
|
||||
blt _0200F104
|
||||
mov r0, #0
|
||||
ldmia sp!, {r3, r4, r5, r6, r7, pc}
|
||||
.align 2, 0
|
||||
_0200F148: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end HasStorableItems
|
||||
|
||||
@@ -7,5 +7,6 @@ s32 GetCurrentBagCapacity();
|
||||
// Implements SPECIAL_PROC_IS_BAG_FULL (see ScriptSpecialProcessCall).
|
||||
bool8 IsBagFull();
|
||||
u32 GetNbItemsInBag(void);
|
||||
u32 CountNbItemsOfTypeInBag(s16 id);
|
||||
|
||||
#endif //PMDSKY_MAIN_0200EDC0_H
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "item.h"
|
||||
|
||||
u32 HasStorableItems(void);
|
||||
s16 GetItemIndex(struct item* item);
|
||||
|
||||
#endif
|
||||
|
||||
2
main.lsf
2
main.lsf
@@ -70,7 +70,7 @@ Static main
|
||||
Object asm/main_0200EB30.o
|
||||
Object src/main_0200ECFC.o
|
||||
Object src/main_0200EDC0.o
|
||||
Object asm/main_0200EE4C.o
|
||||
Object asm/main_0200EE88.o
|
||||
Object src/main_0200EEE0.o
|
||||
Object asm/main_0200EF6C.o
|
||||
Object src/main_0200F14C.o
|
||||
|
||||
@@ -43,3 +43,17 @@ u32 GetNbItemsInBag(void)
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
u32 CountNbItemsOfTypeInBag(s16 id)
|
||||
{
|
||||
struct item *item = BAG_ITEMS_PTR_MIRROR->bag_items->bag_items;
|
||||
s32 count = 0;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < INVENTORY_SIZE; i++, item++) {
|
||||
if (item->id == id) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
#include "main_0200F14C.h"
|
||||
#include "item_util_4.h"
|
||||
#include "item.h"
|
||||
|
||||
extern struct bag_items *BAG_ITEMS_PTR_MIRROR;
|
||||
|
||||
u32 HasStorableItems(void)
|
||||
{
|
||||
struct item *item = BAG_ITEMS_PTR_MIRROR->bag_items->bag_items;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < INVENTORY_SIZE; i++, item++) {
|
||||
bool8 exists = (item->flags & ITEM_FLAG_EXISTS) != 0;
|
||||
|
||||
if (exists && IsStorableItem(item->id)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
s16 GetItemIndex(struct item* item)
|
||||
{
|
||||
struct item *cur = BAG_ITEMS_PTR_MIRROR->bag_items->bag_items;
|
||||
|
||||
Reference in New Issue
Block a user