From a371a37854d25cd47e85d77a9d028c0f0c34478c Mon Sep 17 00:00:00 2001 From: Cameron Hall Date: Fri, 4 Nov 2016 10:31:15 -0500 Subject: decompile coins.c (#85) * decompile coins.c * fix PrintCoins --- src/coins.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/coins.c (limited to 'src/coins.c') diff --git a/src/coins.c b/src/coins.c new file mode 100644 index 000000000..871d1873c --- /dev/null +++ b/src/coins.c @@ -0,0 +1,87 @@ +#include "global.h" +#include "menu.h" +#include "string_util.h" + +#define MAX_COINS 9999 + +extern u8 gOtherText_Coins2[]; + +void PrintCoins(s32, u8, u8, u8); + +void UpdateCoinsWindow(s32 a, u8 b, u8 c) +{ + PrintCoins(a, 4, b + 2, c + 1); +} + +void ShowCoinsWindow(u32 a, u8 b, u8 c) +{ + MenuDrawTextWindow(b, c, b + 9, c + 3); + UpdateCoinsWindow(a, b, c); +} + +void HideCoinsWindow(u8 a, u8 b) +{ + MenuZeroFillWindowRect(a, b, a + 9, b + 3); +} + +void PrintCoins(s32 a, u8 b, u8 c, u8 d) +{ + u8 string[16]; + u8 *ptr; + u8 r1; + u8 r6; + u8 foo; + + ConvertIntToDecimalString(string, a); + r1 = (b * 6 + 0x21 - 8 * (b + 2)); + c = c - r1 / 8; + foo = r1 % 8; + ptr = gStringVar1; + if(foo) + { + ptr[0] = 0xFC; + ptr[1] = 0x11; + ptr[2] = 8 - (foo); + ptr += 3; + } + ptr[0] = 0xFC; + ptr[1] = 0x11; + ptr[2] = (b - StringLength(string)) * 6; + ptr += 3; + StringCopy(ptr, string); + MenuPrint(gOtherText_Coins2, c, d); +} + +u16 GetCoins(void) +{ + return gSaveBlock1.coins; +} + +bool8 GiveCoins(u16 coins) +{ + u32 newCoins; + + if(GetCoins() >= MAX_COINS) + return FALSE; + newCoins = coins + gSaveBlock1.coins; + if(gSaveBlock1.coins > (u16)newCoins) + gSaveBlock1.coins = MAX_COINS; + else + { + gSaveBlock1.coins = newCoins; + if((u16)newCoins > MAX_COINS) + gSaveBlock1.coins = MAX_COINS; + } + return TRUE; +} + +bool8 TakeCoins(u16 coins) +{ + if(GetCoins() >= coins) + { + gSaveBlock1.coins -= coins; + return TRUE; + } + else + return FALSE; +} \ No newline at end of file -- cgit v1.2.3