From 0f72d512b385666b69357878f9435b782483d5b8 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Thu, 12 Nov 2020 00:44:10 -0500 Subject: [PATCH] item decomp --- .../code_13CAF0/pause_items_comparator.s | 13 ------- .../code_13CAF0/pause_items_get_column.s | 24 ------------- .../code_13CAF0/pause_items_get_pos_x.s | 28 --------------- .../code_13CAF0/pause_items_get_pos_y.s | 34 ------------------ .../code_13CAF0/pause_items_get_row.s | 26 -------------- .../code_13CAF0/pause_items_is_visible.s | 15 -------- .../code_13CAF0/pause_items_scroll_offset_y.s | 8 ----- include/macros.h | 1 + src/code_135EE0.c | 3 +- src/code_13CAF0.c | 35 +++++++++++++++---- 10 files changed, 31 insertions(+), 156 deletions(-) delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_comparator.s delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_get_column.s delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_get_pos_x.s delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_get_pos_y.s delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_get_row.s delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_is_visible.s delete mode 100644 asm/nonmatchings/code_13CAF0/pause_items_scroll_offset_y.s diff --git a/asm/nonmatchings/code_13CAF0/pause_items_comparator.s b/asm/nonmatchings/code_13CAF0/pause_items_comparator.s deleted file mode 100644 index f962d919a0..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_comparator.s +++ /dev/null @@ -1,13 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_comparator -/* 13CAF0 802497B0 84840000 */ lh $a0, ($a0) -/* 13CAF4 802497B4 84A30000 */ lh $v1, ($a1) -/* 13CAF8 802497B8 0064182A */ slt $v1, $v1, $a0 -/* 13CAFC 802497BC 14600002 */ bnez $v1, .L802497C8 -/* 13CB00 802497C0 24020001 */ addiu $v0, $zero, 1 -/* 13CB04 802497C4 2402FFFF */ addiu $v0, $zero, -1 -.L802497C8: -/* 13CB08 802497C8 03E00008 */ jr $ra -/* 13CB0C 802497CC 00000000 */ nop diff --git a/asm/nonmatchings/code_13CAF0/pause_items_get_column.s b/asm/nonmatchings/code_13CAF0/pause_items_get_column.s deleted file mode 100644 index 34afe73c97..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_get_column.s +++ /dev/null @@ -1,24 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_get_column -/* 13CBD8 80249898 00041040 */ sll $v0, $a0, 1 -/* 13CBDC 8024989C 00441021 */ addu $v0, $v0, $a0 -/* 13CBE0 802498A0 00021080 */ sll $v0, $v0, 2 -/* 13CBE4 802498A4 3C018027 */ lui $at, 0x8027 -/* 13CBE8 802498A8 00220821 */ addu $at, $at, $v0 -/* 13CBEC 802498AC 902204D2 */ lbu $v0, 0x4d2($at) -/* 13CBF0 802498B0 14400002 */ bnez $v0, .L802498BC -/* 13CBF4 802498B4 00A2001A */ div $zero, $a1, $v0 -/* 13CBF8 802498B8 0007000D */ break 7 -.L802498BC: -/* 13CBFC 802498BC 2401FFFF */ addiu $at, $zero, -1 -/* 13CC00 802498C0 14410004 */ bne $v0, $at, .L802498D4 -/* 13CC04 802498C4 3C018000 */ lui $at, 0x8000 -/* 13CC08 802498C8 14A10002 */ bne $a1, $at, .L802498D4 -/* 13CC0C 802498CC 00000000 */ nop -/* 13CC10 802498D0 0006000D */ break 6 -.L802498D4: -/* 13CC14 802498D4 00001010 */ mfhi $v0 -/* 13CC18 802498D8 03E00008 */ jr $ra -/* 13CC1C 802498DC 00000000 */ nop diff --git a/asm/nonmatchings/code_13CAF0/pause_items_get_pos_x.s b/asm/nonmatchings/code_13CAF0/pause_items_get_pos_x.s deleted file mode 100644 index ee0e2a64b0..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_get_pos_x.s +++ /dev/null @@ -1,28 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_get_pos_x -/* 13CB10 802497D0 00041040 */ sll $v0, $a0, 1 -/* 13CB14 802497D4 00441021 */ addu $v0, $v0, $a0 -/* 13CB18 802497D8 00021080 */ sll $v0, $v0, 2 -/* 13CB1C 802497DC 3C018027 */ lui $at, 0x8027 -/* 13CB20 802497E0 00220821 */ addu $at, $at, $v0 -/* 13CB24 802497E4 902204D2 */ lbu $v0, 0x4d2($at) -/* 13CB28 802497E8 14400002 */ bnez $v0, .L802497F4 -/* 13CB2C 802497EC 00A2001A */ div $zero, $a1, $v0 -/* 13CB30 802497F0 0007000D */ break 7 -.L802497F4: -/* 13CB34 802497F4 2401FFFF */ addiu $at, $zero, -1 -/* 13CB38 802497F8 14410004 */ bne $v0, $at, .L8024980C -/* 13CB3C 802497FC 3C018000 */ lui $at, 0x8000 -/* 13CB40 80249800 14A10002 */ bne $a1, $at, .L8024980C -/* 13CB44 80249804 00000000 */ nop -/* 13CB48 80249808 0006000D */ break 6 -.L8024980C: -/* 13CB4C 8024980C 00001810 */ mfhi $v1 -/* 13CB50 80249810 00031040 */ sll $v0, $v1, 1 -/* 13CB54 80249814 00431021 */ addu $v0, $v0, $v1 -/* 13CB58 80249818 00021100 */ sll $v0, $v0, 4 -/* 13CB5C 8024981C 00431021 */ addu $v0, $v0, $v1 -/* 13CB60 80249820 03E00008 */ jr $ra -/* 13CB64 80249824 00021040 */ sll $v0, $v0, 1 diff --git a/asm/nonmatchings/code_13CAF0/pause_items_get_pos_y.s b/asm/nonmatchings/code_13CAF0/pause_items_get_pos_y.s deleted file mode 100644 index 6b1c236cd6..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_get_pos_y.s +++ /dev/null @@ -1,34 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_get_pos_y -/* 13CB68 80249828 3C028027 */ lui $v0, %hi(gItemMenuPages) -/* 13CB6C 8024982C 244204D0 */ addiu $v0, $v0, %lo(gItemMenuPages) -/* 13CB70 80249830 00041840 */ sll $v1, $a0, 1 -/* 13CB74 80249834 00641821 */ addu $v1, $v1, $a0 -/* 13CB78 80249838 00031880 */ sll $v1, $v1, 2 -/* 13CB7C 8024983C 00621821 */ addu $v1, $v1, $v0 -/* 13CB80 80249840 90620002 */ lbu $v0, 2($v1) -/* 13CB84 80249844 14400002 */ bnez $v0, .L80249850 -/* 13CB88 80249848 00A2001A */ div $zero, $a1, $v0 -/* 13CB8C 8024984C 0007000D */ break 7 -.L80249850: -/* 13CB90 80249850 2401FFFF */ addiu $at, $zero, -1 -/* 13CB94 80249854 14410004 */ bne $v0, $at, .L80249868 -/* 13CB98 80249858 3C018000 */ lui $at, 0x8000 -/* 13CB9C 8024985C 14A10002 */ bne $a1, $at, .L80249868 -/* 13CBA0 80249860 00000000 */ nop -/* 13CBA4 80249864 0006000D */ break 6 -.L80249868: -/* 13CBA8 80249868 00002812 */ mflo $a1 -/* 13CBAC 8024986C 24840001 */ addiu $a0, $a0, 1 -/* 13CBB0 80249870 90630001 */ lbu $v1, 1($v1) -/* 13CBB4 80249874 00041040 */ sll $v0, $a0, 1 -/* 13CBB8 80249878 00441021 */ addu $v0, $v0, $a0 -/* 13CBBC 8024987C 00021080 */ sll $v0, $v0, 2 -/* 13CBC0 80249880 00441023 */ subu $v0, $v0, $a0 -/* 13CBC4 80249884 00031900 */ sll $v1, $v1, 4 -/* 13CBC8 80249888 00431021 */ addu $v0, $v0, $v1 -/* 13CBCC 8024988C 00052900 */ sll $a1, $a1, 4 -/* 13CBD0 80249890 03E00008 */ jr $ra -/* 13CBD4 80249894 00451021 */ addu $v0, $v0, $a1 diff --git a/asm/nonmatchings/code_13CAF0/pause_items_get_row.s b/asm/nonmatchings/code_13CAF0/pause_items_get_row.s deleted file mode 100644 index 6e2446ee0b..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_get_row.s +++ /dev/null @@ -1,26 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_get_row -/* 13CC20 802498E0 3C038027 */ lui $v1, %hi(gItemMenuPages) -/* 13CC24 802498E4 246304D0 */ addiu $v1, $v1, %lo(gItemMenuPages) -/* 13CC28 802498E8 00041040 */ sll $v0, $a0, 1 -/* 13CC2C 802498EC 00441021 */ addu $v0, $v0, $a0 -/* 13CC30 802498F0 00021080 */ sll $v0, $v0, 2 -/* 13CC34 802498F4 00431021 */ addu $v0, $v0, $v1 -/* 13CC38 802498F8 90430002 */ lbu $v1, 2($v0) -/* 13CC3C 802498FC 14600002 */ bnez $v1, .L80249908 -/* 13CC40 80249900 00A3001A */ div $zero, $a1, $v1 -/* 13CC44 80249904 0007000D */ break 7 -.L80249908: -/* 13CC48 80249908 2401FFFF */ addiu $at, $zero, -1 -/* 13CC4C 8024990C 14610004 */ bne $v1, $at, .L80249920 -/* 13CC50 80249910 3C018000 */ lui $at, 0x8000 -/* 13CC54 80249914 14A10002 */ bne $a1, $at, .L80249920 -/* 13CC58 80249918 00000000 */ nop -/* 13CC5C 8024991C 0006000D */ break 6 -.L80249920: -/* 13CC60 80249920 00002812 */ mflo $a1 -/* 13CC64 80249924 90420001 */ lbu $v0, 1($v0) -/* 13CC68 80249928 03E00008 */ jr $ra -/* 13CC6C 8024992C 00451021 */ addu $v0, $v0, $a1 diff --git a/asm/nonmatchings/code_13CAF0/pause_items_is_visible.s b/asm/nonmatchings/code_13CAF0/pause_items_is_visible.s deleted file mode 100644 index 3ccac10346..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_is_visible.s +++ /dev/null @@ -1,15 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_is_visible -/* 13CC70 80249930 3C038027 */ lui $v1, %hi(gItemMenuCurrentScrollPos) -/* 13CC74 80249934 8C6305D4 */ lw $v1, %lo(gItemMenuCurrentScrollPos)($v1) -/* 13CC78 80249938 2462FFE0 */ addiu $v0, $v1, -0x20 -/* 13CC7C 8024993C 0082102A */ slt $v0, $a0, $v0 -/* 13CC80 80249940 14400003 */ bnez $v0, .L80249950 -/* 13CC84 80249944 24620080 */ addiu $v0, $v1, 0x80 -/* 13CC88 80249948 03E00008 */ jr $ra -/* 13CC8C 8024994C 0082102A */ slt $v0, $a0, $v0 -.L80249950: -/* 13CC90 80249950 03E00008 */ jr $ra -/* 13CC94 80249954 0000102D */ daddu $v0, $zero, $zero diff --git a/asm/nonmatchings/code_13CAF0/pause_items_scroll_offset_y.s b/asm/nonmatchings/code_13CAF0/pause_items_scroll_offset_y.s deleted file mode 100644 index 0aabdf6cb4..0000000000 --- a/asm/nonmatchings/code_13CAF0/pause_items_scroll_offset_y.s +++ /dev/null @@ -1,8 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel pause_items_scroll_offset_y -/* 13CC98 80249958 3C028027 */ lui $v0, %hi(gItemMenuCurrentScrollPos) -/* 13CC9C 8024995C 8C4205D4 */ lw $v0, %lo(gItemMenuCurrentScrollPos)($v0) -/* 13CCA0 80249960 03E00008 */ jr $ra -/* 13CCA4 80249964 00821023 */ subu $v0, $a0, $v0 diff --git a/include/macros.h b/include/macros.h index 5dc8a24c15..b9e260db5d 100644 --- a/include/macros.h +++ b/include/macros.h @@ -24,6 +24,7 @@ #define CURRENT_CAM (&gCameras[gCurrentCameraID]) #define BADGE_MENU_PAGE(index) (&gBadgeMenuPages[index]) +#define ITEM_MENU_PAGE(index) (&gItemMenuPages[index]) #define MAX_MAPVARS 16 #define MAX_MAPFLAGS 3 diff --git a/src/code_135EE0.c b/src/code_135EE0.c index b04277de28..a76329be3f 100644 --- a/src/code_135EE0.c +++ b/src/code_135EE0.c @@ -149,7 +149,8 @@ INCLUDE_ASM(s32, "code_135EE0", pause_cleanup); INCLUDE_ASM(s32, "code_135EE0", pause_get_total_equipped_bp_cost); -INCLUDE_ASM(void, "code_135EE0", pause_draw_rect, s32 ulx, s32 uly, s32 lrx, s32 lry, s32 tileDescriptor, s32 uls, s32 ult, s32 dsdx, s32 dtdy); +INCLUDE_ASM(void, "code_135EE0", pause_draw_rect, s32 ulx, s32 uly, s32 lrx, s32 lry, s32 tileDescriptor, s32 uls, + s32 ult, s32 dsdx, s32 dtdy); INCLUDE_ASM(s32, "code_135EE0", pause_sort_item_list); diff --git a/src/code_13CAF0.c b/src/code_13CAF0.c index fc0856706e..0aa8c32695 100644 --- a/src/code_13CAF0.c +++ b/src/code_13CAF0.c @@ -1,18 +1,39 @@ #include "common.h" -INCLUDE_ASM(s32, "code_13CAF0", pause_items_comparator); +s32 pause_items_comparator(s16* a, s16* b) { + if (*a > *b) { + return 1; + } else { + return -1; + } +} -INCLUDE_ASM(s32, "code_13CAF0", pause_items_get_pos_x); +s32 pause_items_get_pos_x(s32 page, s32 itemIndex) { + return (itemIndex % ITEM_MENU_PAGE(page)->numCols) * 98; +} -INCLUDE_ASM(s32, "code_13CAF0", pause_items_get_pos_y); +s32 pause_items_get_pos_y(s32 page, s32 itemIndex) { + return ((page + 1) * 11) + (ITEM_MENU_PAGE(page)->listStart * 16) + ((itemIndex / ITEM_MENU_PAGE(page)->numCols) * 16); +} -INCLUDE_ASM(s32, "code_13CAF0", pause_items_get_column); +s32 pause_items_get_column(s32 page, s32 itemIdx) { + return itemIdx % ITEM_MENU_PAGE(page)->numCols; +} -INCLUDE_ASM(s32, "code_13CAF0", pause_items_get_row); +s32 pause_items_get_row(s32 page, s32 itemIdx) { + return ITEM_MENU_PAGE(page)->listStart + (itemIdx / ITEM_MENU_PAGE(page)->numCols); +} -INCLUDE_ASM(s32, "code_13CAF0", pause_items_is_visible); +s32 pause_items_is_visible(s32 y) { + if (y < gItemMenuCurrentScrollPos - 32) { + return FALSE; + } + return y < gItemMenuCurrentScrollPos + 128; +} -INCLUDE_ASM(s32, "code_13CAF0", pause_items_scroll_offset_y); +s32 pause_items_scroll_offset_y(s32 beforeY) { + return beforeY - gItemMenuCurrentScrollPos; +} s32 pause_items_scroll_offset_x(s32 beforeX) { return beforeX;