Merge pull request #14 from pixel-stuck/master

match find_item
This commit is contained in:
Ethan Roseman 2020-08-09 01:03:37 -04:00 committed by GitHub
commit 8a7a17c4ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 48 deletions

View File

@ -1,47 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
.include "include/macro.inc"
glabel find_item
/* 080AF4 800E7644 00041140 */ sll $v0, $a0, 5
/* 080AF8 800E7648 3C018008 */ lui $at, 0x8008
/* 080AFC 800E764C 00220821 */ addu $at, $at, $v0
/* 080B00 800E7650 942278F8 */ lhu $v0, 0x78f8($at)
/* 080B04 800E7654 3C038011 */ lui $v1, 0x8011
/* 080B08 800E7658 2463F290 */ addiu $v1, $v1, -0xd70
/* 080B0C 800E765C 30420008 */ andi $v0, $v0, 8
/* 080B10 800E7660 1040000D */ beqz $v0, .L800E7698
/* 080B14 800E7664 0000282D */ daddu $a1, $zero, $zero
.L800E7668:
/* 080B18 800E7668 84620074 */ lh $v0, 0x74($v1)
/* 080B1C 800E766C 50440006 */ beql $v0, $a0, .L800E7688
/* 080B20 800E7670 28A30020 */ slti $v1, $a1, 0x20
/* 080B24 800E7674 24A50001 */ addiu $a1, $a1, 1
/* 080B28 800E7678 28A20020 */ slti $v0, $a1, 0x20
/* 080B2C 800E767C 1440FFFA */ bnez $v0, .L800E7668
/* 080B30 800E7680 24630002 */ addiu $v1, $v1, 2
/* 080B34 800E7684 28A30020 */ slti $v1, $a1, 0x20
.L800E7688:
/* 080B38 800E7688 1060000E */ beqz $v1, .L800E76C4
/* 080B3C 800E768C 2402FFFF */ addiu $v0, $zero, -1
/* 080B40 800E7690 03E00008 */ jr $ra
/* 080B44 800E7694 00A0102D */ daddu $v0, $a1, $zero
.L800E7698:
/* 080B48 800E7698 846201B4 */ lh $v0, 0x1b4($v1)
/* 080B4C 800E769C 50440006 */ beql $v0, $a0, .L800E76B8
/* 080B50 800E76A0 2403000A */ addiu $v1, $zero, 0xa
/* 080B54 800E76A4 24A50001 */ addiu $a1, $a1, 1
/* 080B58 800E76A8 28A2000A */ slti $v0, $a1, 0xa
/* 080B5C 800E76AC 1440FFFA */ bnez $v0, .L800E7698
/* 080B60 800E76B0 24630002 */ addiu $v1, $v1, 2
/* 080B64 800E76B4 2403000A */ addiu $v1, $zero, 0xa
.L800E76B8:
/* 080B68 800E76B8 10A30002 */ beq $a1, $v1, .L800E76C4
/* 080B6C 800E76BC 2402FFFF */ addiu $v0, $zero, -1
/* 080B70 800E76C0 00A0102D */ daddu $v0, $a1, $zero
.L800E76C4:
/* 080B74 800E76C4 03E00008 */ jr $ra
/* 080B78 800E76C8 00000000 */ nop

View File

@ -39,6 +39,21 @@ typedef struct {
/* 0x168 */ s32 unk_168;
} game_status;
typedef struct {
/* 0x00 */ s32 nameString;
/* 0x04 */ s16 iconID;
/* 0x06 */ s16 badgeSortPriority;
/* 0x08 */ s32 targetFlags;
/* 0x0C */ s16 sellValue;
/* 0x10 */ s32 menuString;
/* 0x14 */ s32 itemString;
/* 0x18 */ s16 typeFlags;
/* 0x1A */ s8 moveID;
/* 0x1B */ s8 potencyA;
/* 0x1C */ s8 potencyB;
/* 0x1D */ char unk_1D[3];
} item_table_entry;
typedef struct {
/* 0x0 */ s8 enabled;
/* 0x1 */ s8 level;

View File

@ -7,6 +7,7 @@
extern ui_status gUIStatus;
extern player_data gPlayerData;
extern game_status* gGameStatusPtr[1];
extern item_table_entry gItemTable[364];
extern s16* D_80151328;
extern s16 D_8010CD10;
extern s16 D_8010CD12;

View File

@ -137,7 +137,35 @@ s32 get_item_empty_count(void) {
return ARRAY_COUNT(gPlayerData.invItems) - get_item_count();
}
INCLUDE_ASM(code_80850_len_3060, find_item);
s32 find_item(s32 itemID) {
player_data *playerData = &gPlayerData;
s32 i;
if((gItemTable[itemID].typeFlags & 8) != 0) {
for(i = 0; i < ARRAY_COUNT(playerData->keyItems); i++) {
if (playerData->keyItems[i] == itemID) {
break;
}
}
if (i >= ARRAY_COUNT(playerData->keyItems)) {
return -1;
}
return i;
} else {
for(i = 0; i < ARRAY_COUNT(playerData->invItems); i++) {
if (playerData->invItems[i] == itemID)
break;
}
if (i == ARRAY_COUNT(playerData->invItems)) {
return -1;
}
return i;
}
}
INCLUDE_ASM(code_80850_len_3060, sort_items);

View File

@ -1,6 +1,7 @@
gGameStatusPtr = 0x8007419C;
gUIStatus = 0x8010EF58;
gPlayerData = 0x8010F290;
gItemTable = 0x800878E0;
D_8010CD10 = 0x8010CD10;
D_8010CD12 = 0x8010CD12;