summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDizzyEggg <jajkodizzy@wp.pl>2017-09-09 14:24:18 +0200
committerDizzyEggg <jajkodizzy@wp.pl>2017-09-09 14:24:18 +0200
commit3355389eab7e689ec1bbabe941303b478f6457af (patch)
tree0d23cdf093e54abd4d189930856dda78d90c101c
parent307278374b57d11b85b419df9ac994967781657b (diff)
start coins decomp
-rw-r--r--asm/coins.s144
-rw-r--r--asm/link.s2
-rw-r--r--asm/money.s2
-rw-r--r--asm/rom_818E9AC.s14
-rw-r--r--data/strings.s2
-rw-r--r--include/coins.h8
-rw-r--r--ld_script.txt1
-rw-r--r--src/coins.c77
-rw-r--r--sym_ewram.txt6
9 files changed, 100 insertions, 156 deletions
diff --git a/asm/coins.s b/asm/coins.s
index afb84c61f..ea55dd85c 100644
--- a/asm/coins.s
+++ b/asm/coins.s
@@ -5,148 +5,8 @@
.text
- thumb_func_start PrintCoinsString
-@ void PrintCoinsString(s32 coinAmount)
-PrintCoinsString: @ 8145B54
- push {r4,lr}
- sub sp, 0xC
- adds r1, r0, 0
- ldr r0, =gStringVar1
- movs r2, 0x1
- movs r3, 0x4
- bl ConvertIntToDecimalStringN
- ldr r4, =gStringVar4
- ldr r1, =gUnknown_085E8DAB
- adds r0, r4, 0
- bl StringExpandPlaceholders
- movs r0, 0x1
- adds r1, r4, 0
- movs r2, 0x40
- bl GetStringRightAlignXOffset
- adds r3, r0, 0
- ldr r0, =gUnknown_0203AB9C
- ldrb r0, [r0]
- lsls r3, 24
- lsrs r3, 24
- movs r1, 0x1
- str r1, [sp]
- movs r1, 0
- str r1, [sp, 0x4]
- str r1, [sp, 0x8]
- movs r1, 0x1
- adds r2, r4, 0
- bl PrintTextOnWindow
- add sp, 0xC
- pop {r4}
- pop {r0}
- bx r0
- .pool
- thumb_func_end PrintCoinsString
-
- thumb_func_start ShowCoinsWindow
-@ void ShowCoinsWindow(s32 coinAmount, u8 x, u8 y)
-ShowCoinsWindow: @ 8145BAC
- push {r4,r5,lr}
- sub sp, 0x18
- adds r5, r0, 0
- adds r4, r1, 0
- adds r3, r2, 0
- lsls r4, 24
- lsrs r4, 24
- lsls r3, 24
- lsrs r3, 24
- movs r0, 0x8
- str r0, [sp]
- movs r0, 0x2
- str r0, [sp, 0x4]
- movs r0, 0xF
- str r0, [sp, 0x8]
- ldr r0, =0x00000141
- str r0, [sp, 0xC]
- add r0, sp, 0x10
- movs r1, 0
- adds r2, r4, 0
- bl rbox_template_set
- ldr r4, =gUnknown_0203AB9C
- 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 r2, 0x85
- lsls r2, 2
- movs r1, 0
- movs r3, 0xE
- bl SetWindowBorderStyle
- adds r0, r5, 0
- bl PrintCoinsString
- add sp, 0x18
- pop {r4,r5}
- pop {r0}
- bx r0
- .pool
- thumb_func_end ShowCoinsWindow
-
- thumb_func_start HideCoinsWindow
-@ void HideCoinsWindow()
-HideCoinsWindow: @ 8145C14
- push {r4,lr}
- ldr r4, =gUnknown_0203AB9C
- ldrb r0, [r4]
- movs r1, 0x1
- bl sub_819746C
- ldrb r0, [r4]
- bl RemoveWindow
- pop {r4}
- pop {r0}
- bx r0
- .pool
- thumb_func_end HideCoinsWindow
-
- thumb_func_start GetCoins
-@ u16 GetCoins()
-GetCoins: @ 8145C30
- ldr r0, =gSaveBlock1Ptr
- ldr r1, [r0]
- ldr r0, =0x00000494
- adds r1, r0
- ldr r0, =gSaveBlock2Ptr
- ldr r0, [r0]
- adds r0, 0xAC
- ldr r0, [r0]
- ldrh r1, [r1]
- eors r0, r1
- lsls r0, 16
- lsrs r0, 16
- bx lr
- .pool
- thumb_func_end GetCoins
-
- thumb_func_start SetCoins
-@ void SetCoins(u16 amount)
-SetCoins: @ 8145C58
- lsls r0, 16
- lsrs r0, 16
- ldr r1, =gSaveBlock1Ptr
- ldr r2, [r1]
- ldr r1, =gSaveBlock2Ptr
- ldr r1, [r1]
- adds r1, 0xAC
- ldr r1, [r1]
- eors r0, r1
- ldr r1, =0x00000494
- adds r2, r1
- strh r0, [r2]
- bx lr
- .pool
- thumb_func_end SetCoins
-
thumb_func_start AddCoins
-@ bool8 AddCoins(u16 amount)
+@ bool8 AddCoins(u16 toAdd)
AddCoins: @ 8145C80
push {r4,lr}
lsls r0, 16
@@ -187,7 +47,7 @@ _08145CC0:
thumb_func_end AddCoins
thumb_func_start SubtractCoins
-@ bool8 SubtractCoins(u16 amount)
+@ bool8 SubtractCoins(u16 toSub)
SubtractCoins: @ 8145CCC
push {r4,lr}
lsls r0, 16
diff --git a/asm/link.s b/asm/link.s
index f925d355a..1fd881b99 100644
--- a/asm/link.s
+++ b/asm/link.s
@@ -52968,7 +52968,7 @@ sub_80248B0: @ 80248B0
movs r1, 0
movs r2, 0x1
movs r3, 0x1
- bl rbox_template_set
+ bl SetWindowTemplateFields
ldr r4, =gUnknown_02022C94
add r0, sp, 0x10
bl AddWindow
diff --git a/asm/money.s b/asm/money.s
index 2dcc06fd7..0d7cf569f 100644
--- a/asm/money.s
+++ b/asm/money.s
@@ -202,7 +202,7 @@ sub_80E52EC: @ 80E52EC
add r0, sp, 0x10
movs r1, 0
adds r2, r4, 0
- bl rbox_template_set
+ bl SetWindowTemplateFields
ldr r4, =gUnknown_02039F98
add r0, sp, 0x10
bl AddWindow
diff --git a/asm/rom_818E9AC.s b/asm/rom_818E9AC.s
index a8202abaa..e785eebde 100644
--- a/asm/rom_818E9AC.s
+++ b/asm/rom_818E9AC.s
@@ -19160,9 +19160,9 @@ sub_81989B8: @ 81989B8
bx r0
thumb_func_end sub_81989B8
- thumb_func_start rbox_template_set
-@ void rbox_template_set(WindowTemplate *template, char bg_id, char x, char y, char w, char h, char a7, s16 a8)
-rbox_template_set: @ 8198A24
+ thumb_func_start SetWindowTemplateFields
+@ void SetWindowTemplateFields(WindowTemplate *template, char bg_id, char x, char y, char w, char h, char a7, s16 a8)
+SetWindowTemplateFields: @ 8198A24
push {r4-r7,lr}
mov r7, r8
push {r7}
@@ -19184,7 +19184,7 @@ rbox_template_set: @ 8198A24
pop {r4-r7}
pop {r0}
bx r0
- thumb_func_end rbox_template_set
+ thumb_func_end SetWindowTemplateFields
thumb_func_start sub_8198A50
sub_8198A50: @ 8198A50
@@ -19216,7 +19216,7 @@ sub_8198A50: @ 8198A50
str r5, [sp, 0x8]
str r6, [sp, 0xC]
add r0, sp, 0x10
- bl rbox_template_set
+ bl SetWindowTemplateFields
ldr r0, [sp, 0x10]
ldr r1, [sp, 0x14]
mov r2, r8
@@ -19263,7 +19263,7 @@ sub_8198AA4: @ 8198AA4
adds r1, r4, 0
adds r2, r5, 0
adds r3, r6, 0
- bl rbox_template_set
+ bl SetWindowTemplateFields
add r0, sp, 0x10
bl AddWindow
lsls r0, 16
@@ -70120,7 +70120,7 @@ _081B31D2:
add r0, sp, 0x14
movs r1, 0x2
movs r2, 0x13
- bl rbox_template_set
+ bl SetWindowTemplateFields
b _081B3226
.pool
_081B320C:
diff --git a/data/strings.s b/data/strings.s
index bd09345da..94cf82c59 100644
--- a/data/strings.s
+++ b/data/strings.s
@@ -420,7 +420,7 @@ gUnknown_085E8DA0:: @ 85E8DA0
.string "×{STR_VAR_1}$"
.string " BERRY$"
-gUnknown_085E8DAB:: @ 85E8DAB
+gOtherText_Coins2:: @ 85E8DAB
.string "{STR_VAR_1} COINS$"
diff --git a/include/coins.h b/include/coins.h
index 0cfd3db6a..43434b227 100644
--- a/include/coins.h
+++ b/include/coins.h
@@ -1,6 +1,12 @@
#ifndef GUARD_COINS_H
#define GUARD_COINS_H
-void SetCoins(u16 newValue);
+void PrintCoinsString(u32 coinAmount);
+void ShowCoinsWindow(u32 coinAmount, u8 x, u8 y);
+void HideCoinsWindow(void);
+u16 GetCoins(void);
+void SetCoins(u16 coinAmount);
+bool8 AddCoins(u16 toAdd);
+bool8 SubtractCoins(u16 toSub);
#endif // GUARD_COINS_H
diff --git a/ld_script.txt b/ld_script.txt
index b898ae8a8..eae182d93 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -180,6 +180,7 @@ SECTIONS {
asm/evolution_scene.o(.text);
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);
diff --git a/src/coins.c b/src/coins.c
new file mode 100644
index 000000000..f43b5b336
--- /dev/null
+++ b/src/coins.c
@@ -0,0 +1,77 @@
+#include "global.h"
+#include "coins.h"
+#include "text.h"
+#include "window.h"
+#include "text_window.h"
+#include "string_util.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 gOtherText_Coins2[];
+
+void PrintCoinsString(u32 coinAmount)
+{
+ u32 xAlign;
+
+ ConvertIntToDecimalStringN(gStringVar1, coinAmount, STR_CONV_MODE_RIGHT_ALIGN, 4);
+ StringExpandPlaceholders(gStringVar4, gOtherText_Coins2);
+
+ xAlign = GetStringRightAlignXOffset(1, gStringVar4, 0x40);
+ PrintTextOnWindow(sCoinsWindowId, 1, gStringVar4, xAlign, 1, 0, NULL);
+}
+
+void ShowCoinsWindow(u32 coinAmount, u8 x, u8 y)
+{
+ struct WindowTemplate template;
+ SetWindowTemplateFields(&template, 0, x, y, 8, 2, 0xF, 0x141);
+ sCoinsWindowId = AddWindow(&template);
+ FillWindowPixelBuffer(sCoinsWindowId, 0);
+ PutWindowTilemap(sCoinsWindowId);
+ SetWindowBorderStyle(sCoinsWindowId, FALSE, 0x214, 0xE);
+ PrintCoinsString(coinAmount);
+}
+
+void HideCoinsWindow(void)
+{
+ sub_819746C(sCoinsWindowId, TRUE);
+ RemoveWindow(sCoinsWindowId);
+}
+
+u16 GetCoins(void)
+{
+ return gSaveBlock1Ptr->coins ^ gSaveBlock2Ptr->encryptionKey;
+}
+
+void SetCoins(u16 coinAmount)
+{
+ gSaveBlock1Ptr->coins = coinAmount ^ gSaveBlock2Ptr->encryptionKey;
+}
+
+/* Can't match it lol
+bool8 AddCoins(u16 toAdd)
+{
+ u16 newAmount;
+ u16 ownedCoins = GetCoins();
+ if (ownedCoins >= MAX_COINS)
+ return FALSE;
+ // check overflow, can't have less coins than previously
+ if (ownedCoins > ownedCoins + toAdd)
+ {
+ newAmount = MAX_COINS;
+ }
+ else
+ {
+ newAmount = ownedCoins + toAdd;
+ if (newAmount > MAX_COINS)
+ newAmount = MAX_COINS;
+ }
+ SetCoins(newAmount);
+ return TRUE;
+}*/
diff --git a/sym_ewram.txt b/sym_ewram.txt
index 5c6070ad3..b1f2a8eaf 100644
--- a/sym_ewram.txt
+++ b/sym_ewram.txt
@@ -1514,9 +1514,9 @@ gUnknown_0203AB94: @ 203AB94
gUnknown_0203AB98: @ 203AB98
.space 0x4
-gUnknown_0203AB9C: @ 203AB9C
- .space 0x4
-
+ .include "src/coins.o"
+
+ .align 2
sTransitionStructPtr: @ 203ABA0
.space 0x4