From f57776c74cded4b10f974828c991c095faaa6d67 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 28 Oct 2017 15:58:07 -0400 Subject: [PATCH 1/3] through sub_8151574 --- asm/math_util.s | 74 ------------------------------------------------- ld_script.txt | 1 + src/math_util.c | 43 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 74 deletions(-) create mode 100644 src/math_util.c diff --git a/asm/math_util.s b/asm/math_util.s index 906706d61..cf6c6d3d9 100644 --- a/asm/math_util.s +++ b/asm/math_util.s @@ -5,80 +5,6 @@ .text - thumb_func_start sub_8151534 -sub_8151534: @ 8151534 - push {lr} - lsls r0, 16 - asrs r0, 16 - lsls r1, 16 - asrs r1, 16 - muls r0, r1 - adds r1, r0, 0 - cmp r0, 0 - bge _08151548 - adds r1, 0xFF -_08151548: - lsls r0, r1, 8 - asrs r0, 16 - pop {r1} - bx r1 - thumb_func_end sub_8151534 - - thumb_func_start sub_8151550 -sub_8151550: @ 8151550 - push {lr} - adds r3, r1, 0 - lsls r0, 24 - lsrs r0, 24 - lsls r3, 16 - asrs r3, 16 - lsls r2, 16 - asrs r2, 16 - muls r3, r2 - movs r1, 0x1 - lsls r1, r0 - adds r0, r3, 0 - bl __divsi3 - lsls r0, 16 - asrs r0, 16 - pop {r1} - bx r1 - thumb_func_end sub_8151550 - - thumb_func_start sub_8151574 -sub_8151574: @ 8151574 - push {r4-r7,lr} - adds r2, r1, 0 - adds r4, r0, 0 - asrs r5, r0, 31 - asrs r3, r2, 31 - adds r1, r5, 0 - adds r0, r4, 0 - bl __muldi3 - adds r5, r1, 0 - adds r4, r0, 0 - adds r7, r5, 0 - adds r6, r4, 0 - cmp r5, 0 - bge _0815159A - movs r6, 0xFF - movs r7, 0 - adds r6, r4 - adcs r7, r5 -_0815159A: - lsls r3, r7, 24 - lsrs r2, r6, 8 - adds r0, r3, 0 - orrs r0, r2 - asrs r1, r7, 8 - adds r5, r1, 0 - adds r4, r0, 0 - adds r0, r4, 0 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8151574 - thumb_func_start sub_81515B0 sub_81515B0: @ 81515B0 push {lr} diff --git a/ld_script.txt b/ld_script.txt index f655711dd..bf0186b9d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -191,6 +191,7 @@ SECTIONS { asm/battle_controller_linkpartner.o(.text); src/battle_message.o(.text); asm/cable_car.o(.text); + src/math_util.o(.text); asm/math_util.o(.text); asm/roulette_util.o(.text); asm/cable_car_util.o(.text); diff --git a/src/math_util.c b/src/math_util.c new file mode 100644 index 000000000..f249d0a51 --- /dev/null +++ b/src/math_util.c @@ -0,0 +1,43 @@ + +// Includes +#include "global.h" + +// Static type declarations + +// Static RAM declarations + +// Static ROM declarations + +// .rodata + +// .text + +s16 sub_8151534(s16 x, s16 y) +{ + s32 result; + + result = x; + result *= y; + result /= 256; + return result; +} + +s16 sub_8151550(u8 s, s16 x, s16 y) +{ + s32 result; + + result = x; + result *= y; + result /= (1 << s); + return result; +} + +s32 sub_8151574(s32 x, s32 y) +{ + s64 result; + + result = x; + result *= y; + result /= 256; + return result; +} From 8613e8a54d1981dc8f204ecae139726144e640ed Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 28 Oct 2017 16:09:31 -0400 Subject: [PATCH 2/3] through sub_81515FC --- asm/math_util.s | 72 ------------------------------------------------- src/math_util.c | 43 ++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 84 deletions(-) diff --git a/asm/math_util.s b/asm/math_util.s index cf6c6d3d9..43a99dad0 100644 --- a/asm/math_util.s +++ b/asm/math_util.s @@ -5,78 +5,6 @@ .text - thumb_func_start sub_81515B0 -sub_81515B0: @ 81515B0 - push {lr} - lsls r0, 16 - lsrs r0, 16 - lsls r1, 16 - asrs r1, 16 - cmp r1, 0 - beq _081515CC - lsls r0, 16 - asrs r0, 8 - bl __divsi3 - lsls r0, 16 - asrs r0, 16 - b _081515CE -_081515CC: - movs r0, 0 -_081515CE: - pop {r1} - bx r1 - thumb_func_end sub_81515B0 - - thumb_func_start sub_81515D4 -sub_81515D4: @ 81515D4 - push {lr} - lsls r0, 24 - lsrs r3, r0, 24 - lsls r1, 16 - lsrs r0, r1, 16 - lsls r2, 16 - asrs r1, r2, 16 - cmp r1, 0 - beq _081515F6 - lsls r0, 16 - asrs r0, 16 - lsls r0, r3 - bl __divsi3 - lsls r0, 16 - asrs r0, 16 - b _081515F8 -_081515F6: - movs r0, 0 -_081515F8: - pop {r1} - bx r1 - thumb_func_end sub_81515D4 - - thumb_func_start sub_81515FC -sub_81515FC: @ 81515FC - push {r4-r6,lr} - adds r6, r1, 0 - cmp r6, 0 - beq _0815161C - adds r2, r0, 0 - asrs r3, r0, 31 - lsrs r5, r2, 24 - lsls r4, r3, 8 - adds r1, r5, 0 - orrs r1, r4 - lsls r0, r2, 8 - adds r2, r6, 0 - asrs r3, r6, 31 - bl __divdi3 - b _0815161E -_0815161C: - movs r0, 0 -_0815161E: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_81515FC - thumb_func_start sub_8151624 sub_8151624: @ 8151624 push {lr} diff --git a/src/math_util.c b/src/math_util.c index f249d0a51..3eb995d27 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -1,17 +1,5 @@ - -// Includes #include "global.h" -// Static type declarations - -// Static RAM declarations - -// Static ROM declarations - -// .rodata - -// .text - s16 sub_8151534(s16 x, s16 y) { s32 result; @@ -41,3 +29,34 @@ s32 sub_8151574(s32 x, s32 y) result /= 256; return result; } + +s16 sub_81515B0(s16 x, s16 y) +{ + if (y == 0) + { + return 0; + } + return (x << 8) / y; +} + +s16 sub_81515D4(u8 s, s16 x, s16 y) +{ + if (y == 0) + { + return 0; + } + return (x << s) / y; +} + +s32 sub_81515FC(s32 x, s32 y) +{ + s64 _x; + + if (y == 0) + { + return 0; + } + _x = x; + _x *= 256; + return _x / y; +} From 6d3778948d39884d5d5069837b047cd95c9f5a31 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 28 Oct 2017 16:15:36 -0400 Subject: [PATCH 3/3] finish math_util --- asm/math_util.s | 56 ------------------------------------------------- ld_script.txt | 1 - src/math_util.c | 24 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 57 deletions(-) delete mode 100644 asm/math_util.s diff --git a/asm/math_util.s b/asm/math_util.s deleted file mode 100644 index 43a99dad0..000000000 --- a/asm/math_util.s +++ /dev/null @@ -1,56 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_8151624 -sub_8151624: @ 8151624 - push {lr} - adds r1, r0, 0 - movs r0, 0x80 - lsls r0, 9 - lsls r1, 16 - asrs r1, 16 - bl __divsi3 - lsls r0, 16 - asrs r0, 16 - pop {r1} - bx r1 - thumb_func_end sub_8151624 - - thumb_func_start sub_815163C -sub_815163C: @ 815163C - push {lr} - lsls r0, 24 - lsrs r0, 24 - movs r2, 0x80 - lsls r2, 1 - lsls r2, r0 - lsls r1, 16 - asrs r1, 16 - adds r0, r2, 0 - bl __divsi3 - lsls r0, 16 - asrs r0, 16 - pop {r1} - bx r1 - thumb_func_end sub_815163C - - thumb_func_start sub_815165C -sub_815165C: @ 815165C - push {lr} - adds r2, r0, 0 - ldr r1, _08151674 - ldr r0, _08151670 - asrs r3, r2, 31 - bl __divdi3 - pop {r1} - bx r1 - .align 2, 0 -_08151670: .4byte 0x00010000 -_08151674: .4byte 0x00000000 - thumb_func_end sub_815165C - - .align 2, 0 @ Don't pad with nop. diff --git a/ld_script.txt b/ld_script.txt index bf0186b9d..2a33431b9 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -192,7 +192,6 @@ SECTIONS { src/battle_message.o(.text); asm/cable_car.o(.text); src/math_util.o(.text); - asm/math_util.o(.text); asm/roulette_util.o(.text); asm/cable_car_util.o(.text); src/save.o(.text); diff --git a/src/math_util.c b/src/math_util.c index 3eb995d27..83935454a 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -60,3 +60,27 @@ s32 sub_81515FC(s32 x, s32 y) _x *= 256; return _x / y; } + +s16 sub_8151624(s16 y) +{ + s32 x; + + x = 0x10000; + return x / y; +} + +s16 sub_815163C(u8 s, s16 y) +{ + s32 x; + + x = 0x100 << s; + return x / y; +} + +s32 sub_815165C(s32 y) +{ + s64 x; + + x = 0x10000; + return x / y; +}