mirror of
https://github.com/pret/pmd-sky.git
synced 2026-09-29 21:57:42 -05:00
Decomp GetNbItemsInBag and IsItemInBag
Decompile from asm: GetNbItemsInBag 0x0200EDFC IsItemInBag 0x0200EEE0 Both walk the active inventory with a cursor rather than indexing, with the index and the cursor both advanced in the for clause, which is what puts the two adds at the top of the loop body as the target has them. GetNbItemsInBag's existence test goes through an explicit boolean: (item->flags & ITEM_FLAG_EXISTS) != 0 assigned to a bool8 before the branch. That is what produces the target's tst / movne / moveq / tst #0xff sequence; testing the masked value directly collapses it. IsItemInBag returns early on the first match, which the target reaches with bxeq lr mid-loop, and falls through to a single return of zero. GetNbItemsInBag lands in the existing src/main_0200EDC0.c, which already includes item.h; IsItemInBag needs a new file and declares BAG_ITEMS_PTR_MIRROR alongside it, matching how the other bag sources in this tree declare it. 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:
3
asm/include/main_0200EE4C.inc
Normal file
3
asm/include/main_0200EE4C.inc
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
.public BAG_ITEMS_PTR_MIRROR
|
||||
.public IsThrownItem
|
||||
@@ -3,5 +3,4 @@
|
||||
.public BAG_ITEMS_PTR_MIRROR
|
||||
.public GetItemCategoryVeneer
|
||||
.public IsStorableItem
|
||||
.public IsThrownItem
|
||||
.public ItemZInit
|
||||
54
asm/main_0200EE4C.s
Normal file
54
asm/main_0200EE4C.s
Normal file
@@ -0,0 +1,54 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "main_0200EE4C.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}
|
||||
ldr r1, _0200EEDC ; =BAG_ITEMS_PTR_MIRROR
|
||||
mov r5, #0
|
||||
ldr r1, [r1]
|
||||
mov r7, r0
|
||||
ldr r4, [r1, #0x384]
|
||||
mov r6, r5
|
||||
_0200EEA4:
|
||||
ldrsh r0, [r4, #4]
|
||||
cmp r0, r7
|
||||
bne _0200EEC4
|
||||
bl IsThrownItem
|
||||
cmp r0, #0
|
||||
ldrneh r0, [r4, #2]
|
||||
addne r5, r5, r0
|
||||
addeq r5, r5, #1
|
||||
_0200EEC4:
|
||||
add r6, r6, #1
|
||||
cmp r6, #0x32
|
||||
add r4, r4, #6
|
||||
blt _0200EEA4
|
||||
mov r0, r5
|
||||
ldmia sp!, {r3, r4, r5, r6, r7, pc}
|
||||
.align 2, 0
|
||||
_0200EEDC: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end CountItemTypeInBag
|
||||
@@ -1,107 +1,8 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "main_0200EDFC.inc"
|
||||
.include "main_0200EF20.inc"
|
||||
|
||||
.text
|
||||
|
||||
arm_func_start GetNbItemsInBag
|
||||
GetNbItemsInBag: ; 0x0200EDFC
|
||||
stmdb sp!, {r3, lr}
|
||||
ldr r1, _0200EE48 ; =BAG_ITEMS_PTR_MIRROR
|
||||
mov r0, #0
|
||||
ldr r1, [r1]
|
||||
mov lr, r0
|
||||
ldr ip, [r1, #0x384]
|
||||
mov r1, r0
|
||||
mov r2, #1
|
||||
_0200EE1C:
|
||||
ldrb r3, [ip]
|
||||
add lr, lr, #1
|
||||
add ip, ip, #6
|
||||
tst r3, #1
|
||||
movne r3, r2
|
||||
moveq r3, r1
|
||||
tst r3, #0xff
|
||||
addne r0, r0, #1
|
||||
cmp lr, #0x32
|
||||
blt _0200EE1C
|
||||
ldmia sp!, {r3, pc}
|
||||
.align 2, 0
|
||||
_0200EE48: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end GetNbItemsInBag
|
||||
|
||||
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}
|
||||
ldr r1, _0200EEDC ; =BAG_ITEMS_PTR_MIRROR
|
||||
mov r5, #0
|
||||
ldr r1, [r1]
|
||||
mov r7, r0
|
||||
ldr r4, [r1, #0x384]
|
||||
mov r6, r5
|
||||
_0200EEA4:
|
||||
ldrsh r0, [r4, #4]
|
||||
cmp r0, r7
|
||||
bne _0200EEC4
|
||||
bl IsThrownItem
|
||||
cmp r0, #0
|
||||
ldrneh r0, [r4, #2]
|
||||
addne r5, r5, r0
|
||||
addeq r5, r5, #1
|
||||
_0200EEC4:
|
||||
add r6, r6, #1
|
||||
cmp r6, #0x32
|
||||
add r4, r4, #6
|
||||
blt _0200EEA4
|
||||
mov r0, r5
|
||||
ldmia sp!, {r3, r4, r5, r6, r7, pc}
|
||||
.align 2, 0
|
||||
_0200EEDC: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end CountItemTypeInBag
|
||||
|
||||
arm_func_start IsItemInBag
|
||||
IsItemInBag: ; 0x0200EEE0
|
||||
ldr r1, _0200EF1C ; =BAG_ITEMS_PTR_MIRROR
|
||||
mov r3, #0
|
||||
ldr r1, [r1]
|
||||
ldr r2, [r1, #0x384]
|
||||
b _0200EF0C
|
||||
_0200EEF4:
|
||||
ldrsh r1, [r2, #4]
|
||||
cmp r1, r0
|
||||
moveq r0, #1
|
||||
bxeq lr
|
||||
add r3, r3, #1
|
||||
add r2, r2, #6
|
||||
_0200EF0C:
|
||||
cmp r3, #0x32
|
||||
blt _0200EEF4
|
||||
mov r0, #0
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_0200EF1C: .word BAG_ITEMS_PTR_MIRROR
|
||||
arm_func_end IsItemInBag
|
||||
|
||||
arm_func_start IsItemWithFlagsInBag
|
||||
IsItemWithFlagsInBag: ; 0x0200EF20
|
||||
ldr r2, _0200EF68 ; =BAG_ITEMS_PTR_MIRROR
|
||||
@@ -6,5 +6,6 @@
|
||||
s32 GetCurrentBagCapacity();
|
||||
// Implements SPECIAL_PROC_IS_BAG_FULL (see ScriptSpecialProcessCall).
|
||||
bool8 IsBagFull();
|
||||
u32 GetNbItemsInBag(void);
|
||||
|
||||
#endif //PMDSKY_MAIN_0200EDC0_H
|
||||
|
||||
6
include/main_0200EEE0.h
Normal file
6
include/main_0200EEE0.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef PMDSKY_MAIN_0200EEE0_H
|
||||
#define PMDSKY_MAIN_0200EEE0_H
|
||||
|
||||
u32 IsItemInBag(s16 id);
|
||||
|
||||
#endif
|
||||
4
main.lsf
4
main.lsf
@@ -70,7 +70,9 @@ Static main
|
||||
Object asm/main_0200EB30.o
|
||||
Object src/main_0200ECFC.o
|
||||
Object src/main_0200EDC0.o
|
||||
Object asm/main_0200EDFC.o
|
||||
Object asm/main_0200EE4C.o
|
||||
Object src/main_0200EEE0.o
|
||||
Object asm/main_0200EF20.o
|
||||
Object src/main_0200F370.o
|
||||
Object asm/main_0200F390.o
|
||||
Object src/main_0200F798.o
|
||||
|
||||
@@ -27,3 +27,19 @@ bool8 IsBagFull()
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
u32 GetNbItemsInBag(void)
|
||||
{
|
||||
struct item *item = BAG_ITEMS_PTR_MIRROR->bag_items->bag_items;
|
||||
s32 count = 0;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < INVENTORY_SIZE; i++, item++) {
|
||||
bool8 exists = (item->flags & ITEM_FLAG_EXISTS) != 0;
|
||||
|
||||
if (exists) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
17
src/main_0200EEE0.c
Normal file
17
src/main_0200EEE0.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "main_0200EEE0.h"
|
||||
#include "item.h"
|
||||
|
||||
extern struct bag_items *BAG_ITEMS_PTR_MIRROR;
|
||||
|
||||
u32 IsItemInBag(s16 id)
|
||||
{
|
||||
struct item *item = BAG_ITEMS_PTR_MIRROR->bag_items->bag_items;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < INVENTORY_SIZE; i++, item++) {
|
||||
if (item->id == id) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
Reference in New Issue
Block a user