From e41b9cbbb37c908f77a9ce440f33b76b35139311 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 29 Sep 2017 00:11:42 +0200 Subject: [PATCH] decompile money --- asm/item_menu.s | 2 +- asm/money.s | 311 ------------------------------------------- asm/scrcmd.s | 6 +- asm/shop.s | 8 +- data/graphics.s | 11 +- data/money.s | 13 -- data/naming_screen.s | 2 +- include/menu.h | 5 +- include/money.h | 10 ++ ld_script.txt | 3 +- src/coins.c | 3 +- src/money.c | 145 ++++++++++++++++++++ sym_ewram.txt | 9 +- 13 files changed, 180 insertions(+), 348 deletions(-) delete mode 100644 asm/money.s delete mode 100644 data/money.s diff --git a/asm/item_menu.s b/asm/item_menu.s index abac409bc..c1f94b4e9 100755 --- a/asm/item_menu.s +++ b/asm/item_menu.s @@ -6237,7 +6237,7 @@ bag_menu_AddMoney_window: @ 81AE268 adds r0, r4, 0 movs r1, 0x1 movs r2, 0xE - bl set_window_border_style_and_print_money_box + bl PrintMoneyAmountInMoneyBoxWithBorder movs r0, 0x13 movs r1, 0xB bl AddMoneyLabelObject diff --git a/asm/money.s b/asm/money.s deleted file mode 100644 index 53e795714..000000000 --- a/asm/money.s +++ /dev/null @@ -1,311 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - - - thumb_func_start sub_80E51B0 -sub_80E51B0: @ 80E51B0 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0x92 - lsls r1, 3 - adds r0, r1 - ldr r1, =gSpecialVar_0x8005 - ldrh r1, [r1] - bl IsEnoughMoney - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .pool - thumb_func_end sub_80E51B0 - - thumb_func_start sub_80E51D4 -sub_80E51D4: @ 80E51D4 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0x92 - lsls r1, 3 - adds r0, r1 - ldr r1, =gSpecialVar_0x8005 - ldrh r1, [r1] - bl SubtractMoney - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E51D4 - - thumb_func_start PrintMoneyAmountInMoneyBox -@ void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, s8 a3) -PrintMoneyAmountInMoneyBox: @ 80E51F4 - push {lr} - sub sp, 0x4 - adds r3, r1, 0 - lsls r0, 24 - lsrs r0, 24 - lsls r2, 24 - lsrs r2, 24 - str r2, [sp] - movs r1, 0x26 - movs r2, 0x1 - bl PrintMoneyAmount - add sp, 0x4 - pop {r0} - bx r0 - thumb_func_end PrintMoneyAmountInMoneyBox - - thumb_func_start PrintMoneyAmount -@ void PrintMoneyAmount(u8 windowId, char x, char y, int amount, u8 a5) -PrintMoneyAmount: @ 80E5214 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0xC - ldr r4, [sp, 0x24] - lsls r0, 24 - lsrs r7, r0, 24 - lsls r1, 24 - lsrs r1, 24 - mov r8, r1 - lsls r2, 24 - lsrs r6, r2, 24 - lsls r4, 24 - lsrs r5, r4, 24 - ldr r4, =gStringVar1 - adds r0, r4, 0 - adds r1, r3, 0 - movs r2, 0 - movs r3, 0x6 - bl ConvertIntToDecimalStringN - adds r0, r4, 0 - bl StringLength - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x6 - subs r1, r0 - ldr r2, =gStringVar4 - adds r0, r1, 0 - subs r1, 0x1 - cmp r0, 0 - ble _080E5264 - movs r3, 0x77 -_080E5258: - strb r3, [r2] - adds r2, 0x1 - adds r0, r1, 0 - subs r1, 0x1 - cmp r0, 0 - bgt _080E5258 -_080E5264: - ldr r1, =gText_PokedollarVar1 - adds r0, r2, 0 - bl StringExpandPlaceholders - ldr r2, =gStringVar4 - str r6, [sp] - str r5, [sp, 0x4] - movs r0, 0 - str r0, [sp, 0x8] - adds r0, r7, 0 - movs r1, 0x1 - mov r3, r8 - bl PrintTextOnWindow - add sp, 0xC - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end PrintMoneyAmount - - thumb_func_start set_window_border_style_and_print_money_box -@ void set_window_border_style_and_print_money_box(u8 windowId, u16 tileStart, u8 palette, int amount) -set_window_border_style_and_print_money_box: @ 80E5298 - push {r4-r6,lr} - mov r6, r8 - push {r6} - adds r6, r0, 0 - adds r4, r1, 0 - adds r5, r2, 0 - mov r8, r3 - lsls r6, 24 - lsrs r6, 24 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 24 - lsrs r5, 24 - adds r0, r6, 0 - movs r1, 0 - adds r2, r4, 0 - adds r3, r5, 0 - bl SetWindowBorderStyle - adds r0, r6, 0 - mov r1, r8 - movs r2, 0 - bl PrintMoneyAmountInMoneyBox - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end set_window_border_style_and_print_money_box - - thumb_func_start sub_80E52D4 -sub_80E52D4: @ 80E52D4 - push {lr} - adds r1, r0, 0 - ldr r0, =gUnknown_02039F98 - ldrb r0, [r0] - movs r2, 0 - bl PrintMoneyAmountInMoneyBox - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E52D4 - - thumb_func_start sub_80E52EC -@ void sub_80E52EC(int money, int x, int y) -sub_80E52EC: @ 80E52EC - push {r4-r6,lr} - mov r6, r8 - push {r6} - sub sp, 0x18 - mov r8, r0 - adds r4, r1, 0 - adds r3, r2, 0 - lsls r4, 24 - lsls r3, 24 - lsrs r6, r4, 24 - movs r0, 0x80 - lsls r0, 17 - adds r4, r0 - lsrs r4, 24 - lsrs r5, r3, 24 - adds r3, r0 - lsrs r3, 24 - movs r0, 0xA - str r0, [sp] - movs r0, 0x2 - str r0, [sp, 0x4] - movs r0, 0xF - str r0, [sp, 0x8] - movs r0, 0x8 - str r0, [sp, 0xC] - add r0, sp, 0x10 - movs r1, 0 - adds r2, r4, 0 - bl SetWindowTemplateFields - ldr r4, =gUnknown_02039F98 - add r0, sp, 0x10 - bl AddWindow - strb r0, [r4] - ldrb r0, [r4] - movs r1, 0 - bl FillWindowPixelBuffer - ldrb r0, [r4] - bl PutWindowTilemap - ldrb r0, [r4] - movs r1, 0x1 - bl CopyWindowToVram - ldrb r0, [r4] - movs r1, 0x85 - lsls r1, 2 - movs r2, 0xE - mov r3, r8 - bl set_window_border_style_and_print_money_box - lsls r6, 19 - movs r0, 0x98 - lsls r0, 13 - adds r6, r0 - lsrs r6, 16 - lsls r5, 19 - movs r0, 0xB0 - lsls r0, 12 - adds r5, r0 - lsrs r5, 16 - adds r0, r6, 0 - adds r1, r5, 0 - bl AddMoneyLabelObject - add sp, 0x18 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E52EC - - thumb_func_start sub_80E5384 -sub_80E5384: @ 80E5384 - push {r4,lr} - bl RemoveMoneyLabelObject - ldr r4, =gUnknown_02039F98 - ldrb r0, [r4] - movs r1, 0 - bl sub_8198070 - ldrb r0, [r4] - movs r1, 0x2 - bl CopyWindowToVram - ldrb r0, [r4] - bl RemoveWindow - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E5384 - - thumb_func_start AddMoneyLabelObject -AddMoneyLabelObject: @ 80E53AC - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - ldr r0, =gUnknown_0858C2A4 - bl LoadCompressedObjectPic - ldr r0, =gUnknown_0858C2AC - bl LoadCompressedObjectPalette - ldr r0, =gUnknown_0858C28C - lsls r4, 16 - asrs r4, 16 - lsls r5, 16 - asrs r5, 16 - adds r1, r4, 0 - adds r2, r5, 0 - movs r3, 0 - bl CreateSprite - ldr r1, =gUnknown_02039F99 - strb r0, [r1] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end AddMoneyLabelObject - - thumb_func_start RemoveMoneyLabelObject -RemoveMoneyLabelObject: @ 80E53F4 - push {lr} - ldr r0, =gUnknown_02039F99 - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - ldr r1, =gSprites - adds r0, r1 - bl DestroySpriteAndFreeResources - pop {r0} - bx r0 - .pool - thumb_func_end RemoveMoneyLabelObject - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/scrcmd.s b/asm/scrcmd.s index 7980ba564..1772c563f 100644 --- a/asm/scrcmd.s +++ b/asm/scrcmd.s @@ -4468,7 +4468,7 @@ s93_display_money: @ 809B500 bl GetMoney adds r1, r5, 0 adds r2, r4, 0 - bl sub_80E52EC + bl DrawMoneyBox _0809B530: movs r0, 0 pop {r4,r5} @@ -4480,7 +4480,7 @@ _0809B530: thumb_func_start s94_hide_money s94_hide_money: @ 809B53C push {lr} - bl sub_80E5384 + bl HideMoneyBox movs r0, 0 pop {r1} bx r1 @@ -4505,7 +4505,7 @@ s95_update_money: @ 809B548 lsls r1, 3 adds r0, r1 bl GetMoney - bl sub_80E52D4 + bl ChangeAmountInMoneyBox _0809B56E: movs r0, 0 pop {r1} diff --git a/asm/shop.s b/asm/shop.s index f4dacaa76..08e935bb1 100644 --- a/asm/shop.s +++ b/asm/shop.s @@ -1125,7 +1125,7 @@ BuyMenuInitBgs: @ 80E036C BuyMenuDecompressBgGraphics: @ 80E0424 push {lr} sub sp, 0x4 - ldr r1, =gUnknown_08D9AFBC + ldr r1, =gBuyMenuFrame_Gfx movs r2, 0xE8 lsls r2, 2 ldr r3, =0x000003e3 @@ -1133,11 +1133,11 @@ BuyMenuDecompressBgGraphics: @ 80E0424 str r0, [sp] movs r0, 0x1 bl decompress_and_copy_tile_data_to_vram - ldr r0, =gUnknown_08D9B0F0 + ldr r0, =gBuyMenuFrame_Tilemap ldr r1, =gUnknown_02039F70 ldr r1, [r1] bl LZDecompressWram - ldr r0, =gUnknown_08D9B0C8 + ldr r0, =gMenuMoneyPal movs r1, 0xC0 movs r2, 0x20 bl LoadCompressedPalette @@ -1259,7 +1259,7 @@ BuyMenuDrawGraphics: @ 80E0524 movs r0, 0 movs r1, 0x1 movs r2, 0xD - bl set_window_border_style_and_print_money_box + bl PrintMoneyAmountInMoneyBoxWithBorder movs r0, 0 bl schedule_bg_copy_tilemap_to_vram movs r0, 0x1 diff --git a/data/graphics.s b/data/graphics.s index 96aaf3911..26842d4ba 100644 --- a/data/graphics.s +++ b/data/graphics.s @@ -512,14 +512,17 @@ gUnknown_08D9AE04:: @ 8D9AE04 gUnknown_08D9AF44:: @ 8D9AF44 .incbin "baserom.gba", 0xd9af44, 0x78 -gUnknown_08D9AFBC:: @ 8D9AFBC +gBuyMenuFrame_Gfx:: @ 8D9AFBC .incbin "baserom.gba", 0xd9afbc, 0x10c -gUnknown_08D9B0C8:: @ 8D9B0C8 +gMenuMoneyPal:: @ 8D9B0C8 .incbin "baserom.gba", 0xd9b0c8, 0x28 -gUnknown_08D9B0F0:: @ 8D9B0F0 - .incbin "baserom.gba", 0xd9b0f0, 0x1c4 +gBuyMenuFrame_Tilemap:: @ 8D9B0F0 + .incbin "baserom.gba", 0xd9b0f0, 0x140 + +gMenuMoneyGfx:: @ 8D9B230 + .incbin "baserom.gba", 0xd9b230, 0x84 gUnknown_08D9B2B4:: @ 8D9B2B4 .incbin "baserom.gba", 0xd9b2b4, 0x1bc diff --git a/data/money.s b/data/money.s deleted file mode 100644 index d7457be46..000000000 --- a/data/money.s +++ /dev/null @@ -1,13 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_0858C28C:: @ 858C28C - .incbin "baserom.gba", 0x58c28c, 0x18 - -gUnknown_0858C2A4:: @ 858C2A4 - .incbin "baserom.gba", 0x58c2a4, 0x8 - -gUnknown_0858C2AC:: @ 858C2AC - .incbin "baserom.gba", 0x58c2ac, 0x8 diff --git a/data/naming_screen.s b/data/naming_screen.s index 352fac8e4..80cbd0b09 100644 --- a/data/naming_screen.s +++ b/data/naming_screen.s @@ -148,4 +148,4 @@ gUnknown_0858C1C8:: @ 858C1C8 .incbin "baserom.gba", 0x58c1c8, 0x68 gUnknown_0858C230:: @ 858C230 - .incbin "baserom.gba", 0x58c230, 0x5c + .incbin "baserom.gba", 0x58c230, 0x48 diff --git a/include/menu.h b/include/menu.h index 9a23401e0..766aa9d39 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,7 +1,7 @@ #ifndef GUARD_MENU_H #define GUARD_MENU_H -#include "text.h" +#include "window.h" struct MenuAction { @@ -16,5 +16,8 @@ struct MenuAction2 }; void box_print(u8, u8, u8, u8, const void *, s8, const u8 *); +void sub_8198070(u8 windowId, bool8 copyToVram); +void SetWindowTemplateFields(struct WindowTemplate* template, u8 priority, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 palNum, u16 baseBlock); +void SetWindowBorderStyle(u8 windowId, bool8 copyToVram, u16 tileStart, u8 palette); #endif // GUARD_MENU_H diff --git a/include/money.h b/include/money.h index 316dbd697..22a3657f6 100644 --- a/include/money.h +++ b/include/money.h @@ -6,5 +6,15 @@ void SetMoney(u32* moneyPtr, u32 newValue); bool8 IsEnoughMoney(u32* moneyPtr, u32 cost); void AddMoney(u32* moneyPtr, u32 toAdd); void SubtractMoney(u32* moneyPtr, u32 toSub); +bool8 IsEnoughForCostInVar0x8005(void); +void SubtractMoneyFromVar0x8005(void); +void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed); +void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed); +void PrintMoneyAmountInMoneyBoxWithBorder(u8 windowId, u16 tileStart, u8 pallete, int amount); +void ChangeAmountInMoneyBox(int amount); +void DrawMoneyBox(int amount, u8 x, u8 y); +void HideMoneyBox(void); +void AddMoneyLabelObject(u16 x, u16 y); +void RemoveMoneyLabelObject(void); #endif // GUARD_MONEY_H diff --git a/ld_script.txt b/ld_script.txt index 64a43d573..37c8a3933 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -148,7 +148,6 @@ SECTIONS { 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); asm/secret_base.o(.text); @@ -386,7 +385,7 @@ SECTIONS { src/berry.o(.rodata); data/script_menu.o(.rodata); data/naming_screen.o(.rodata); - data/money.o(.rodata); + src/money.o(.rodata); data/contest_effect.o(.rodata); data/record_mixing.o(.rodata); data/secret_base.o(.rodata); diff --git a/src/coins.c b/src/coins.c index 84a79f5f2..4ee601b22 100644 --- a/src/coins.c +++ b/src/coins.c @@ -4,14 +4,13 @@ #include "window.h" #include "text_window.h" #include "string_util.h" +#include "menu.h" #define MAX_COINS 9999 EWRAM_DATA u8 sCoinsWindowId = 0; extern s32 GetStringRightAlignXOffset(u8 fontId, u8 *str, s32 totalWidth); -extern void SetWindowTemplateFields(struct WindowTemplate* template, u8 priority, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 palNum, u16 baseBlock); -extern void SetWindowBorderStyle(u8 windowId, bool8 copyToVram, s16 tileStart, s8 palette); extern void sub_819746C(u8 windowId, bool8 copyToVram); extern const u8 gText_Coins[]; diff --git a/src/money.c b/src/money.c index be64d9633..65a45b158 100644 --- a/src/money.c +++ b/src/money.c @@ -1,8 +1,77 @@ #include "global.h" #include "money.h" +#include "event_data.h" +#include "string_util.h" +#include "text.h" +#include "menu.h" +#include "window.h" +#include "sprite.h" +#include "decompress.h" + +extern const u8 gText_PokedollarVar1[]; + +extern const u8 gMenuMoneyGfx[]; +extern const u8 gMenuMoneyPal[]; #define MAX_MONEY 999999 +EWRAM_DATA static u8 sMoneyBoxWindowId = 0; +EWRAM_DATA static u8 sMoneyLabelSpriteId = 0; + +#define MONEY_LABEL_TAG 0x2722 + +static const struct OamData sOamData_MoneyLabel = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 1, + .x = 0, + .matrixNum = 0, + .size = 2, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0, +}; + +static const union AnimCmd sSpriteAnim_MoneyLabel[] = +{ + ANIMCMD_FRAME(0, 0), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_MoneyLabel[] = +{ + sSpriteAnim_MoneyLabel, +}; + +static const struct SpriteTemplate sSpriteTemplate_MoneyLabel = +{ + .tileTag = MONEY_LABEL_TAG, + .paletteTag = MONEY_LABEL_TAG, + .oam = &sOamData_MoneyLabel, + .anims = sSpriteAnimTable_MoneyLabel, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + +static const struct CompressedSpriteSheet sSpriteSheet_MoneyLabel = +{ + .data = gMenuMoneyGfx, + .size = 256, + .tag = MONEY_LABEL_TAG, +}; + +static const struct CompressedSpritePalette sSpritePalette_MoneyLabel = +{ + .data = gMenuMoneyPal, + .tag = MONEY_LABEL_TAG +}; + u32 GetMoney(u32* moneyPtr) { return *moneyPtr ^ gSaveBlock2Ptr->encryptionKey; @@ -53,3 +122,79 @@ void SubtractMoney(u32* moneyPtr, u32 toSub) SetMoney(moneyPtr, toSet); } + +bool8 IsEnoughForCostInVar0x8005(void) +{ + return IsEnoughMoney(&gSaveBlock1Ptr->money, gSpecialVar_0x8005); +} + +void SubtractMoneyFromVar0x8005(void) +{ + SubtractMoney(&gSaveBlock1Ptr->money, gSpecialVar_0x8005); +} + +void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed) +{ + PrintMoneyAmount(windowId, 0x26, 1, amount, speed); +} + +void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed) +{ + u8 *txtPtr; + s32 strLength; + + ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_LEFT_ALIGN, 6); + + strLength = 6 - StringLength(gStringVar1); + txtPtr = gStringVar4; + + while (strLength-- > 0) + *(txtPtr++) = 0x77; + + StringExpandPlaceholders(txtPtr, gText_PokedollarVar1); + PrintTextOnWindow(windowId, 1, gStringVar4, x, y, speed, NULL); +} + +void PrintMoneyAmountInMoneyBoxWithBorder(u8 windowId, u16 tileStart, u8 pallete, int amount) +{ + SetWindowBorderStyle(windowId, FALSE, tileStart, pallete); + PrintMoneyAmountInMoneyBox(windowId, amount, 0); +} + +void ChangeAmountInMoneyBox(int amount) +{ + PrintMoneyAmountInMoneyBox(sMoneyBoxWindowId, amount, 0); +} + +void DrawMoneyBox(int amount, u8 x, u8 y) +{ + struct WindowTemplate template; + + SetWindowTemplateFields(&template, 0, x + 1, y + 1, 10, 2, 15, 8); + sMoneyBoxWindowId = AddWindow(&template); + FillWindowPixelBuffer(sMoneyBoxWindowId, 0); + PutWindowTilemap(sMoneyBoxWindowId); + CopyWindowToVram(sMoneyBoxWindowId, 1); + PrintMoneyAmountInMoneyBoxWithBorder(sMoneyBoxWindowId, 0x214, 14, amount); + AddMoneyLabelObject((8 * x) + 19, (8 * y) + 11); +} + +void HideMoneyBox(void) +{ + RemoveMoneyLabelObject(); + sub_8198070(sMoneyBoxWindowId, FALSE); + CopyWindowToVram(sMoneyBoxWindowId, 2); + RemoveWindow(sMoneyBoxWindowId); +} + +void AddMoneyLabelObject(u16 x, u16 y) +{ + LoadCompressedObjectPic(&sSpriteSheet_MoneyLabel); + LoadCompressedObjectPalette(&sSpritePalette_MoneyLabel); + sMoneyLabelSpriteId = CreateSprite(&sSpriteTemplate_MoneyLabel, x, y, 0); +} + +void RemoveMoneyLabelObject(void) +{ + DestroySpriteAndFreeResources(&gSprites[sMoneyLabelSpriteId]); +} diff --git a/sym_ewram.txt b/sym_ewram.txt index d8cc646db..1cd5a1a60 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -1148,12 +1148,9 @@ gUnknown_02039F90: @ 2039F90 gUnknown_02039F94: @ 2039F94 .space 0x4 -gUnknown_02039F98: @ 2039F98 - .space 0x1 - -gUnknown_02039F99: @ 2039F99 - .space 0x3 - + .include "src/money.o" + + .align 2 gUnknown_02039F9C: @ 2039F9C .space 0x78