From 8613e8a54d1981dc8f204ecae139726144e640ed Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 28 Oct 2017 16:09:31 -0400 Subject: [PATCH] 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 cf6c6d3d93..43a99dad0f 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 f249d0a512..3eb995d27b 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; +}