start money.s decomp

This commit is contained in:
DizzyEggg 2017-09-09 00:45:25 +02:00
parent 5eff1d5bdb
commit 307278374b
11 changed files with 91 additions and 122 deletions

View File

@ -15535,7 +15535,7 @@ _0804E6FC:
lsls r1, 3
adds r0, r1
adds r1, r4, 0
bl add_money
bl AddMoney
ldr r1, =gBattleTextBuff1
movs r0, 0xFD
strb r0, [r1]
@ -20931,7 +20931,7 @@ atk91_givepaydaymoney: @ 80515C8
lsls r1, 3
adds r0, r1
adds r1, r4, 0
bl add_money
bl AddMoney
ldr r1, =gBattleTextBuff1
movs r0, 0xFD
strb r0, [r1]

View File

@ -5,100 +5,9 @@
.text
thumb_func_start DecryptMoney
@ int DecryptMoney(u32 *moneyPointer)
DecryptMoney: @ 80E5114
ldr r1, =gSaveBlock2Ptr
ldr r1, [r1]
adds r1, 0xAC
ldr r0, [r0]
ldr r1, [r1]
eors r0, r1
bx lr
.pool
thumb_func_end DecryptMoney
thumb_func_start SetMoney
@ void SetMoney(u32 *moneyPointer, u32 moneyAmount)
SetMoney: @ 80E5128
ldr r2, =gSaveBlock2Ptr
ldr r2, [r2]
adds r2, 0xAC
ldr r2, [r2]
eors r2, r1
str r2, [r0]
bx lr
.pool
thumb_func_end SetMoney
thumb_func_start IsEnoughMoney
@ bool8 IsEnoughMoney(u32 *moneyPointer, u32 price)
IsEnoughMoney: @ 80E513C
push {r4,lr}
adds r4, r1, 0
bl DecryptMoney
cmp r0, r4
bcs _080E514C
movs r0, 0
b _080E514E
_080E514C:
movs r0, 0x1
_080E514E:
pop {r4}
pop {r1}
bx r1
thumb_func_end IsEnoughMoney
thumb_func_start add_money
@ void add_money(int *money_ptr, int amount)
add_money: @ 80E5154
push {r4-r6,lr}
adds r6, r0, 0
adds r4, r1, 0
bl DecryptMoney
adds r5, r0, 0
adds r0, r5, r4
ldr r5, =0x000f423f
adds r4, r5, 0
cmp r0, r5
bhi _080E5178
adds r5, r0, 0
adds r0, r6, 0
bl DecryptMoney
cmp r5, r0
bcs _080E5178
adds r5, r4, 0
_080E5178:
adds r0, r6, 0
adds r1, r5, 0
bl SetMoney
pop {r4-r6}
pop {r0}
bx r0
.pool
thumb_func_end add_money
thumb_func_start subtract_money
@ void subtract_money(int *money_ptr, int amount)
subtract_money: @ 80E518C
push {r4,r5,lr}
adds r5, r0, 0
adds r4, r1, 0
bl DecryptMoney
adds r1, r0, 0
cmp r1, r4
bcs _080E51A0
movs r1, 0
b _080E51A2
_080E51A0:
subs r1, r4
_080E51A2:
adds r0, r5, 0
bl SetMoney
pop {r4,r5}
pop {r0}
bx r0
thumb_func_end subtract_money
thumb_func_start sub_80E51B0
sub_80E51B0: @ 80E51B0
@ -128,7 +37,7 @@ sub_80E51D4: @ 80E51D4
adds r0, r1
ldr r1, =gSpecialVar_0x8005
ldrh r1, [r1]
bl subtract_money
bl SubtractMoney
pop {r0}
bx r0
.pool

View File

@ -16,7 +16,7 @@ sub_8084620: @ 8084620
lsls r0, 3
adds r4, r0
adds r0, r4, 0
bl DecryptMoney
bl GetMoney
adds r1, r0, 0
lsrs r1, 1
adds r0, r4, 0

View File

@ -58826,7 +58826,7 @@ _081AD634:
ldrsh r0, [r4, r1]
cmp r0, 0x1
bne _081AD64C
bl bag_menu_add_money_window
bl bag_menu_AddMoney_window
adds r0, r5, 0
bl sub_81AD680
b _081AD66A
@ -58958,7 +58958,7 @@ sub_81AD730: @ 81AD730
adds r0, r5, 0
movs r1, 0x1
bl sub_81ABCC0
bl bag_menu_add_money_window
bl bag_menu_AddMoney_window
subs r6, 0x8
adds r4, r6
ldr r0, =sub_81AD794
@ -59144,7 +59144,7 @@ sub_81AD8C8: @ 81AD8C8
ldrsh r1, [r3, r2]
muls r1, r0
adds r0, r4, 0
bl add_money
bl AddMoney
mov r3, r10
ldrb r0, [r3]
mov r1, r9
@ -59177,7 +59177,7 @@ sub_81AD8C8: @ 81AD8C8
movs r3, 0x92
lsls r3, 3
adds r0, r3
bl DecryptMoney
bl GetMoney
adds r1, r0, 0
adds r0, r4, 0
movs r2, 0
@ -60220,8 +60220,8 @@ bag_menu_yes_no: @ 81AE238
.pool
thumb_func_end bag_menu_yes_no
thumb_func_start bag_menu_add_money_window
bag_menu_add_money_window: @ 81AE268
thumb_func_start bag_menu_AddMoney_window
bag_menu_AddMoney_window: @ 81AE268
push {r4,lr}
movs r0, 0x9
bl bag_menu_add_window
@ -60233,7 +60233,7 @@ bag_menu_add_money_window: @ 81AE268
movs r1, 0x92
lsls r1, 3
adds r0, r1
bl DecryptMoney
bl GetMoney
adds r3, r0, 0
adds r0, r4, 0
movs r1, 0x1
@ -60246,7 +60246,7 @@ bag_menu_add_money_window: @ 81AE268
pop {r0}
bx r0
.pool
thumb_func_end bag_menu_add_money_window
thumb_func_end bag_menu_AddMoney_window
thumb_func_start bag_menu_remove_money_window
bag_menu_remove_money_window: @ 81AE2A4

View File

@ -4356,9 +4356,9 @@ _0809B44A:
.pool
thumb_func_end sub_809B3DC
thumb_func_start s90_add_money
@ int s90_add_money(script_env *env)
s90_add_money: @ 809B458
thumb_func_start s90_AddMoney
@ int s90_AddMoney(script_env *env)
s90_AddMoney: @ 809B458
push {r4,lr}
adds r4, r0, 0
bl script_read_word
@ -4375,18 +4375,18 @@ s90_add_money: @ 809B458
lsls r1, 3
adds r0, r1
adds r1, r2, 0
bl add_money
bl AddMoney
_0809B47E:
movs r0, 0
pop {r4}
pop {r1}
bx r1
.pool
thumb_func_end s90_add_money
thumb_func_end s90_AddMoney
thumb_func_start s91_subtract_money
@ int s91_subtract_money(script_env *env)
s91_subtract_money: @ 809B48C
thumb_func_start s91_SubtractMoney
@ int s91_SubtractMoney(script_env *env)
s91_SubtractMoney: @ 809B48C
push {r4,lr}
adds r4, r0, 0
bl script_read_word
@ -4403,14 +4403,14 @@ s91_subtract_money: @ 809B48C
lsls r1, 3
adds r0, r1
adds r1, r2, 0
bl subtract_money
bl SubtractMoney
_0809B4B2:
movs r0, 0
pop {r4}
pop {r1}
bx r1
.pool
thumb_func_end s91_subtract_money
thumb_func_end s91_SubtractMoney
thumb_func_start s92_check_money
@ int s92_check_money(script_env *env)
@ -4465,7 +4465,7 @@ s93_display_money: @ 809B500
movs r1, 0x92
lsls r1, 3
adds r0, r1
bl DecryptMoney
bl GetMoney
adds r1, r5, 0
adds r2, r4, 0
bl sub_80E52EC
@ -4504,7 +4504,7 @@ s95_update_money: @ 809B548
movs r1, 0x92
lsls r1, 3
adds r0, r1
bl DecryptMoney
bl GetMoney
bl sub_80E52D4
_0809B56E:
movs r0, 0

View File

@ -1254,7 +1254,7 @@ BuyMenuDrawGraphics: @ 80E0524
movs r1, 0x92
lsls r1, 3
adds r0, r1
bl DecryptMoney
bl GetMoney
adds r3, r0, 0
movs r0, 0
movs r1, 0x1
@ -2198,7 +2198,7 @@ Task_BuyHowManyDialogueInit: @ 80E0CA4
movs r1, 0x92
lsls r1, 3
adds r0, r1
bl DecryptMoney
bl GetMoney
ldr r1, =gUnknown_02039F70
ldr r4, [r1]
movs r2, 0x80
@ -2465,12 +2465,12 @@ BuyMenuSubtractMoney: @ 80E0F88
lsls r2, 6
adds r1, r2
ldr r1, [r1]
bl subtract_money
bl SubtractMoney
movs r0, 0x5F
bl PlaySE
ldr r0, [r5]
adds r0, r4
bl DecryptMoney
bl GetMoney
adds r1, r0, 0
movs r0, 0
movs r2, 0

View File

@ -998,7 +998,7 @@ _080C2F14:
movs r1, 0x92
lsls r1, 3
adds r0, r1
bl DecryptMoney
bl GetMoney
str r0, [r5, 0x24]
movs r2, 0
adds r7, r5, 0

View File

@ -144,8 +144,8 @@ gEventScriptCommandFunctionTable:: @ 81DB67C
.4byte sub_809B7A4
.4byte sub_809B7B4
.4byte s8F_get_random_val
.4byte s90_add_money
.4byte s91_subtract_money
.4byte s90_AddMoney
.4byte s91_SubtractMoney
.4byte s92_check_money
.4byte s93_display_money
.4byte s94_hide_money

View File

@ -1,6 +1,10 @@
#ifndef GUARD_MONEY_H
#define GUARD_MONEY_H
u32 GetMoney(u32* moneyPtr);
void SetMoney(u32* moneyPtr, u32 newValue);
bool8 IsEnoughMoney(u32* moneyPtr, u32 cost);
void AddMoney(u32* moneyPtr, u32 toAdd);
void SubtractMoney(u32* moneyPtr, u32 toSub);
#endif // GUARD_MONEY_H

View File

@ -138,6 +138,7 @@ SECTIONS {
asm/berry.o(.text);
asm/script_menu.o(.text);
asm/naming_screen.o(.text);
src/money.o(.text);
asm/money.o(.text);
asm/contest_effect.o(.text);
asm/record_mixing.o(.text);

55
src/money.c Normal file
View File

@ -0,0 +1,55 @@
#include "global.h"
#include "money.h"
#define MAX_MONEY 999999
u32 GetMoney(u32* moneyPtr)
{
return *moneyPtr ^ gSaveBlock2Ptr->encryptionKey;
}
void SetMoney(u32* moneyPtr, u32 newValue)
{
*moneyPtr = gSaveBlock2Ptr->encryptionKey ^ newValue;
}
bool8 IsEnoughMoney(u32* moneyPtr, u32 cost)
{
if (GetMoney(moneyPtr) >= cost)
return TRUE;
else
return FALSE;
}
void AddMoney(u32* moneyPtr, u32 toAdd)
{
u32 toSet = GetMoney(moneyPtr);
// can't have more money than MAX
if (toSet + toAdd > MAX_MONEY)
{
toSet = MAX_MONEY;
}
else
{
toSet += toAdd;
// check overflow, can't have less money after you receive more
if (toSet < GetMoney(moneyPtr))
toSet = MAX_MONEY;
}
SetMoney(moneyPtr, toSet);
}
void SubtractMoney(u32* moneyPtr, u32 toSub)
{
u32 toSet = GetMoney(moneyPtr);
// can't subtract more than you already have
if (toSet < toSub)
toSet = 0;
else
toSet -= toSub;
SetMoney(moneyPtr, toSet);
}