diff --git a/papermario/asm/nonmatchings/code_80850_len_3060/add_coins.s b/papermario/asm/nonmatchings/code_80850_len_3060/add_coins.s deleted file mode 100644 index 7aba01f469..0000000000 --- a/papermario/asm/nonmatchings/code_80850_len_3060/add_coins.s +++ /dev/null @@ -1,36 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -.include "include/macro.inc" - -glabel add_coins -/* 083570 800EA0C0 3C038011 */ lui $v1, 0x8011 -/* 083574 800EA0C4 2463F290 */ addiu $v1, $v1, -0xd70 -/* 083578 800EA0C8 9462000C */ lhu $v0, 0xc($v1) -/* 08357C 800EA0CC 00441021 */ addu $v0, $v0, $a0 -/* 083580 800EA0D0 A462000C */ sh $v0, 0xc($v1) -/* 083584 800EA0D4 00021400 */ sll $v0, $v0, 0x10 -/* 083588 800EA0D8 00021403 */ sra $v0, $v0, 0x10 -/* 08358C 800EA0DC 284203E8 */ slti $v0, $v0, 0x3e8 -/* 083590 800EA0E0 14400002 */ bnez $v0, .L800EA0EC -/* 083594 800EA0E4 240203E7 */ addiu $v0, $zero, 0x3e7 -/* 083598 800EA0E8 A462000C */ sh $v0, 0xc($v1) -.L800EA0EC: -/* 08359C 800EA0EC 8462000C */ lh $v0, 0xc($v1) -/* 0835A0 800EA0F0 04420001 */ bltzl $v0, .L800EA0F8 -/* 0835A4 800EA0F4 A460000C */ sh $zero, 0xc($v1) -.L800EA0F8: -/* 0835A8 800EA0F8 18800008 */ blez $a0, .L800EA11C -/* 0835AC 800EA0FC 3C050001 */ lui $a1, 1 -/* 0835B0 800EA100 8C6202B4 */ lw $v0, 0x2b4($v1) -/* 0835B4 800EA104 34A5869F */ ori $a1, $a1, 0x869f -/* 0835B8 800EA108 00441021 */ addu $v0, $v0, $a0 -/* 0835BC 800EA10C AC6202B4 */ sw $v0, 0x2b4($v1) -/* 0835C0 800EA110 00A2102B */ sltu $v0, $a1, $v0 -/* 0835C4 800EA114 54400001 */ bnezl $v0, .L800EA11C -/* 0835C8 800EA118 AC6502B4 */ sw $a1, 0x2b4($v1) -.L800EA11C: -/* 0835CC 800EA11C 8462000C */ lh $v0, 0xc($v1) -/* 0835D0 800EA120 03E00008 */ jr $ra -/* 0835D4 800EA124 00000000 */ nop - diff --git a/papermario/asm/nonmatchings/code_80850_len_3060/add_star_points.s b/papermario/asm/nonmatchings/code_80850_len_3060/add_star_points.s deleted file mode 100644 index 272475ceaf..0000000000 --- a/papermario/asm/nonmatchings/code_80850_len_3060/add_star_points.s +++ /dev/null @@ -1,27 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -.include "include/macro.inc" - -glabel add_star_points -/* 0835D8 800EA128 3C038011 */ lui $v1, 0x8011 -/* 0835DC 800EA12C 2463F290 */ addiu $v1, $v1, -0xd70 -/* 0835E0 800EA130 90620010 */ lbu $v0, 0x10($v1) -/* 0835E4 800EA134 00441021 */ addu $v0, $v0, $a0 -/* 0835E8 800EA138 A0620010 */ sb $v0, 0x10($v1) -/* 0835EC 800EA13C 00021600 */ sll $v0, $v0, 0x18 -/* 0835F0 800EA140 00021603 */ sra $v0, $v0, 0x18 -/* 0835F4 800EA144 28420065 */ slti $v0, $v0, 0x65 -/* 0835F8 800EA148 14400003 */ bnez $v0, .L800EA158 -/* 0835FC 800EA14C 0060202D */ daddu $a0, $v1, $zero -/* 083600 800EA150 24020064 */ addiu $v0, $zero, 0x64 -/* 083604 800EA154 A0620010 */ sb $v0, 0x10($v1) -.L800EA158: -/* 083608 800EA158 80620010 */ lb $v0, 0x10($v1) -/* 08360C 800EA15C 04420001 */ bltzl $v0, .L800EA164 -/* 083610 800EA160 A0600010 */ sb $zero, 0x10($v1) -.L800EA164: -/* 083614 800EA164 80820010 */ lb $v0, 0x10($a0) -/* 083618 800EA168 03E00008 */ jr $ra -/* 08361C 800EA16C 00000000 */ nop - diff --git a/papermario/include/common_structs.h b/papermario/include/common_structs.h index 791abec0bd..22a3a678d6 100644 --- a/papermario/include/common_structs.h +++ b/papermario/include/common_structs.h @@ -63,7 +63,7 @@ typedef struct { /* 0x00C */ s16 coins; /* 0x00E */ s8 fortressKeyCount; /* 0x00F */ u8 starPieces; - /* 0x010 */ s8 starPoints; + /* 0x010 */ u8 starPoints; /* 0x011 */ char unk_11; /* 0x012 */ s8 currentPartner; /* 0x013 */ char unk_13; diff --git a/papermario/src/code_80850_len_3060.c b/papermario/src/code_80850_len_3060.c index 2ea8b24d1e..7bd51d164d 100644 --- a/papermario/src/code_80850_len_3060.c +++ b/papermario/src/code_80850_len_3060.c @@ -7,6 +7,26 @@ player_data* get_player_data(void) { } INCLUDE_ASM(code_80850_len_3060, add_item); +//Mostly matches. Just regalloc left. +/*s32 add_item(s16 item) { + player_data* playerData = &gPlayerData; + s32 i; + + sort_items(); + + for(i = 0; i < 10; i++) { + if (playerData->invItems[i] == 0) { + break; + } + } + + if (i == 10) { + return -1; + } + + playerData->invItems[i] = item; + return i; +}*/ INCLUDE_ASM(code_80850_len_3060, get_item_count); @@ -108,15 +128,56 @@ INCLUDE_ASM(code_80850_len_3060, sync_status_menu); INCLUDE_ASM(code_80850_len_3060, reset_status_menu); +// uses a jumptable, which we need .rodata support for. INCLUDE_ASM(code_80850_len_3060, is_ability_active); s32 is_partner_ability_active(void) { return 0; } -INCLUDE_ASM(code_80850_len_3060, add_coins); +s16 add_coins(s32 amt) { + player_data *playerData = &gPlayerData; + s16 temp_v0; -INCLUDE_ASM(code_80850_len_3060, add_star_points); + temp_v0 = playerData->coins + amt; + playerData->coins = temp_v0; + if (temp_v0 >= 1000) { + playerData->coins = 999; + } + if (playerData->coins < 0) { + playerData->coins = 0; + } + + if (amt > 0) { + u32 temp_v0_2 = playerData->totalCoinsEarned + amt; + playerData->totalCoinsEarned = temp_v0_2; + if (temp_v0_2 > 99999) { + playerData->totalCoinsEarned = 99999; + } + } + return playerData->coins; +} + +s8 add_star_points(s32 amt) { + player_data *playerData = &gPlayerData; + player_data *playerData2 = &gPlayerData; + s8 temp_v0; + + temp_v0 = playerData->starPoints + amt; + + //TODO: probably a macro! + playerData2->starPoints = temp_v0; + if (temp_v0 >= 0x65) { + playerData2->starPoints = 0x64; + } + + //TODO: probably a macro! + temp_v0 = playerData2->starPoints; + if (temp_v0 < 0) { + playerData2->starPoints = 0; + } + return gPlayerData.starPoints; +} u8 add_star_pieces(s32 amt) { player_data *playerData = &gPlayerData;