From 89d938ea9e10a637563a5b4d0d19ddb4535bcf8e Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 13:53:51 -0500 Subject: [PATCH 1/4] Finish decompiling coins --- asm/coins.s | 74 --------------------------------------------------- ld_script.txt | 1 - src/coins.c | 21 +++++++++++---- 3 files changed, 16 insertions(+), 80 deletions(-) delete mode 100644 asm/coins.s diff --git a/asm/coins.s b/asm/coins.s deleted file mode 100644 index d2b6cbb47e..0000000000 --- a/asm/coins.s +++ /dev/null @@ -1,74 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start GiveCoins -@ bool8 GiveCoins(u16 toAdd) -GiveCoins: @ 8145C80 - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - bl GetCoins - lsls r0, 16 - lsrs r1, r0, 16 - ldr r0, =0x0000270e - cmp r1, r0 - bls _08145C9C - movs r0, 0 - b _08145CC0 - .pool -_08145C9C: - adds r0, r1, r4 - cmp r1, r0 - ble _08145CAC - ldr r0, =0x0000270f - b _08145CBA - .pool -_08145CAC: - lsls r0, 16 - lsrs r1, r0, 16 - ldr r0, =0x0000270f - cmp r1, r0 - bls _08145CB8 - adds r1, r0, 0 -_08145CB8: - adds r0, r1, 0 -_08145CBA: - bl SetCoins - movs r0, 0x1 -_08145CC0: - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GiveCoins - - thumb_func_start TakeCoins -@ bool8 TakeCoins(u16 toSub) -TakeCoins: @ 8145CCC - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - bl GetCoins - lsls r0, 16 - lsrs r0, 16 - cmp r0, r4 - bcs _08145CE2 - movs r0, 0 - b _08145CEE -_08145CE2: - subs r0, r4 - lsls r0, 16 - lsrs r0, 16 - bl SetCoins - movs r0, 0x1 -_08145CEE: - pop {r4} - pop {r1} - bx r1 - thumb_func_end TakeCoins - - .align 2, 0 @ Don't pad with nop. diff --git a/ld_script.txt b/ld_script.txt index e9c810adcf..5292183c31 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -186,7 +186,6 @@ SECTIONS { asm/roulette.o(.text); asm/pokedex_cry_screen.o(.text); src/coins.o(.text); - asm/coins.o(.text); asm/landmark.o(.text); asm/fldeff_strength.o(.text); asm/battle_transition.o(.text); diff --git a/src/coins.c b/src/coins.c index e1694b29ca..e313a42219 100644 --- a/src/coins.c +++ b/src/coins.c @@ -53,7 +53,6 @@ void SetCoins(u16 coinAmount) gSaveBlock1Ptr->coins = coinAmount ^ gSaveBlock2Ptr->encryptionKey; } -/* Can't match it lol bool8 GiveCoins(u16 toAdd) { u16 newAmount; @@ -67,10 +66,22 @@ bool8 GiveCoins(u16 toAdd) } else { - newAmount = ownedCoins + toAdd; - if (newAmount > MAX_COINS) - newAmount = MAX_COINS; + ownedCoins += toAdd; + if (ownedCoins > MAX_COINS) + ownedCoins = MAX_COINS; + newAmount = ownedCoins; } SetCoins(newAmount); return TRUE; -}*/ +} + +bool8 TakeCoins(u16 toSub) +{ + u16 ownedCoins = GetCoins(); + if (ownedCoins >= toSub) + { + SetCoins(ownedCoins - toSub); + return TRUE; + } + return FALSE; +} From c5dcbb78ce0a2fc423190aa743907164b72997a7 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 21:04:15 -0500 Subject: [PATCH 2/4] unk_81BAD84 --- asm/unk_81BAD84.s | 57 ----------------------------------------------- ld_script.txt | 2 +- src/unk_81BAD84.c | 20 +++++++++++++++++ 3 files changed, 21 insertions(+), 58 deletions(-) delete mode 100644 asm/unk_81BAD84.s create mode 100644 src/unk_81BAD84.c diff --git a/asm/unk_81BAD84.s b/asm/unk_81BAD84.s deleted file mode 100644 index 2a95feed49..0000000000 --- a/asm/unk_81BAD84.s +++ /dev/null @@ -1,57 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_81BAD84 -sub_81BAD84: @ 81BAD84 - push {r4-r6,lr} - movs r6, 0x80 - lsls r6, 19 - movs r2, 0 - strh r2, [r6] - ldr r1, =0x04000010 - strh r2, [r1] - adds r1, 0x2 - strh r2, [r1] - adds r1, 0x3E - strh r2, [r1] - ldr r5, =gUnknown_08617128 - lsls r4, r0, 1 - adds r4, r0 - lsls r4, 2 - adds r0, r4, r5 - ldr r0, [r0] - movs r1, 0xC0 - lsls r1, 19 - bl LZ77UnCompVram - adds r0, r5, 0x4 - adds r0, r4, r0 - ldr r0, [r0] - ldr r1, =0x0600f800 - bl LZ77UnCompVram - adds r5, 0x8 - adds r4, r5 - ldr r0, [r4] - movs r1, 0xA0 - lsls r1, 19 - movs r4, 0x80 - lsls r4, 1 - adds r2, r4, 0 - bl CpuSet - ldr r1, =0x04000008 - movs r2, 0xF8 - lsls r2, 5 - adds r0, r2, 0 - strh r0, [r1] - strh r4, [r6] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BAD84 - - - .align 2, 0 @ Don't pad with nop. diff --git a/ld_script.txt b/ld_script.txt index e9c810adcf..76125e9e26 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -251,7 +251,7 @@ SECTIONS { asm/battle_tent.o(.text); src/unk_text_util_2.o(.text); src/multiboot.o(.text); - asm/unk_81BAD84.o(.text); + src/unk_81BAD84.o(.text); src/battle_controller_player_partner.o(.text); asm/fldeff_groundshake.o(.text); asm/fossil_specials.o(.text); diff --git a/src/unk_81BAD84.c b/src/unk_81BAD84.c new file mode 100644 index 0000000000..43cb9a4b0c --- /dev/null +++ b/src/unk_81BAD84.c @@ -0,0 +1,20 @@ +#include "global.h" + +extern const struct { + const u8 *unk_0; + const u8 *unk_4; + const u8 *unk_8; +} gUnknown_08617128[]; + +void sub_81BAD84(u32 idx) +{ + REG_DISPCNT = 0x0000; + REG_BG0HOFS = 0x0000; + REG_BG0VOFS = 0x0000; + REG_BLDCNT = 0x0000; + LZ77UnCompVram(gUnknown_08617128[idx].unk_0, (void *)BG_CHAR_ADDR(0)); + LZ77UnCompVram(gUnknown_08617128[idx].unk_4, (void *)BG_SCREEN_ADDR(31)); + CpuCopy16(gUnknown_08617128[idx].unk_8, (void *)PLTT, 0x200); + REG_BG0CNT = 0x1f00; + REG_DISPCNT = DISPCNT_BG0_ON; +} From 772da493f9ea0dcd8838dd927f1b70ff63228c21 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 21:15:57 -0500 Subject: [PATCH 3/4] data/unk_81BAD84 --- data/unk_81BAD84.s | 7 ------- include/graphics.h | 18 ++++++++++++++++++ ld_script.txt | 2 +- src/unk_81BAD84.c | 43 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 54 insertions(+), 16 deletions(-) delete mode 100644 data/unk_81BAD84.s diff --git a/data/unk_81BAD84.s b/data/unk_81BAD84.s deleted file mode 100644 index de88365ac3..0000000000 --- a/data/unk_81BAD84.s +++ /dev/null @@ -1,7 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_08617128:: @ 8617128 - .incbin "baserom.gba", 0x617128, 0x48 diff --git a/include/graphics.h b/include/graphics.h index c50fdef3f4..4c5a0952b2 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -91,5 +91,23 @@ extern const u8 gUnknown_08DB9F08[]; extern const u8 gUnknown_08DB9FFC[]; extern const u8 gUnknown_08DBA020[]; extern const u8 gUnknown_08DBA12C[]; +extern const u8 gUnknown_08DD87C0[]; +extern const u8 gUnknown_08DD8EE0[]; +extern const u16 gUnknown_08DD8780[]; +extern const u8 gUnknown_08DD90E0[]; +extern const u8 gUnknown_08DD9718[]; +extern const u16 gUnknown_08DD9080[]; +extern const u8 gUnknown_08DD98B4[]; +extern const u8 gUnknown_08DD9E58[]; +extern const u16 gUnknown_08DD9874[]; +extern const u8 gUnknown_08DDA02C[]; +extern const u8 gUnknown_08DDA63C[]; +extern const u16 gUnknown_08DD9FEC[]; +extern const u8 gUnknown_08DDA840[]; +extern const u8 gUnknown_08DDAE40[]; +extern const u16 gUnknown_08DDA800[]; +extern const u8 gUnknown_08DDB020[]; +extern const u8 gUnknown_08DDB2C4[]; +extern const u16 gUnknown_08DDAFE0[]; #endif //GUARD_GRAPHICS_H diff --git a/ld_script.txt b/ld_script.txt index 76125e9e26..ee423ccf3d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -472,7 +472,7 @@ SECTIONS { data/party_menu.o(.rodata); data/battle_tent.o(.rodata); src/unk_text_util_2.o(.rodata); - data/unk_81BAD84.o(.rodata); + src/unk_81BAD84.o(.rodata); src/battle_controller_player_partner.o(.rodata); data/fossil_special_fldeff_groundshake.o(.rodata); src/berry_fix_program.o(.rodata); diff --git a/src/unk_81BAD84.c b/src/unk_81BAD84.c index 43cb9a4b0c..9ba98dd87a 100644 --- a/src/unk_81BAD84.c +++ b/src/unk_81BAD84.c @@ -1,10 +1,37 @@ #include "global.h" +#include "graphics.h" -extern const struct { - const u8 *unk_0; - const u8 *unk_4; - const u8 *unk_8; -} gUnknown_08617128[]; +const struct { + const u8 *gfx; + const u8 *tileMap; + const u16 *pltt; +} gUnknown_08617128[] = { + { + gUnknown_08DD87C0, + gUnknown_08DD8EE0, + gUnknown_08DD8780 + }, { + gUnknown_08DD90E0, + gUnknown_08DD9718, + gUnknown_08DD9080 + }, { + gUnknown_08DD98B4, + gUnknown_08DD9E58, + gUnknown_08DD9874 + }, { + gUnknown_08DDA02C, + gUnknown_08DDA63C, + gUnknown_08DD9FEC + }, { + gUnknown_08DDA840, + gUnknown_08DDAE40, + gUnknown_08DDA800 + }, { + gUnknown_08DDB020, + gUnknown_08DDB2C4, + gUnknown_08DDAFE0 + } +}; void sub_81BAD84(u32 idx) { @@ -12,9 +39,9 @@ void sub_81BAD84(u32 idx) REG_BG0HOFS = 0x0000; REG_BG0VOFS = 0x0000; REG_BLDCNT = 0x0000; - LZ77UnCompVram(gUnknown_08617128[idx].unk_0, (void *)BG_CHAR_ADDR(0)); - LZ77UnCompVram(gUnknown_08617128[idx].unk_4, (void *)BG_SCREEN_ADDR(31)); - CpuCopy16(gUnknown_08617128[idx].unk_8, (void *)PLTT, 0x200); + LZ77UnCompVram(gUnknown_08617128[idx].gfx, (void *)BG_CHAR_ADDR(0)); + LZ77UnCompVram(gUnknown_08617128[idx].tileMap, (void *)BG_SCREEN_ADDR(31)); + CpuCopy16(gUnknown_08617128[idx].pltt, (void *)PLTT, 0x200); REG_BG0CNT = 0x1f00; REG_DISPCNT = DISPCNT_BG0_ON; } From da04898840083653835db7ca997b6d57f1d3c353 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 23:10:51 -0500 Subject: [PATCH 4/4] Clean up includes --- include/strings.h | 1 + src/coins.c | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/strings.h b/include/strings.h index 08e2b4bba8..a32ba4c83d 100644 --- a/include/strings.h +++ b/include/strings.h @@ -82,5 +82,6 @@ extern const u8 gText_NoRegistry[]; extern const u8 gText_OkayToDeleteFromRegistry[]; extern const u8 gText_RegisteredDataDeleted[]; extern const u8 gUnknown_085EA79D[]; +extern const u8 gText_Coins[]; #endif //GUARD_STRINGS_H diff --git a/src/coins.c b/src/coins.c index e313a42219..50c31cac01 100644 --- a/src/coins.c +++ b/src/coins.c @@ -2,8 +2,9 @@ #include "coins.h" #include "text.h" #include "window.h" -#include "text_window.h" +#include "strings.h" #include "string_util.h" +#include "new_menu_helpers.h" #include "menu.h" #include "international_string_util.h" @@ -11,10 +12,6 @@ EWRAM_DATA u8 sCoinsWindowId = 0; -extern void sub_819746C(u8 windowId, bool8 copyToVram); - -extern const u8 gText_Coins[]; - void PrintCoinsString(u32 coinAmount) { u32 xAlign;