diff --git a/asm/include/main_02001C80.inc b/asm/include/main_02001CB0.inc similarity index 100% rename from asm/include/main_02001C80.inc rename to asm/include/main_02001CB0.inc diff --git a/asm/main_02001C80.s b/asm/main_02001CB0.s similarity index 96% rename from asm/main_02001C80.s rename to asm/main_02001CB0.s index d091a675..9d25f97e 100644 --- a/asm/main_02001C80.s +++ b/asm/main_02001CB0.s @@ -1,24 +1,8 @@ .include "asm/macros.inc" - .include "main_02001C80.inc" + .include "main_02001CB0.inc" .text - arm_func_start IntToFixedPoint64 -IntToFixedPoint64: ; 0x02001C80 - mov r2, #0x10000 - rsb r2, r2, #0 - and r3, r1, r2 - mov r3, r3, lsr #0x10 - str r3, [r0] - mov r3, r1, lsl #0x10 - str r3, [r0, #4] - tst r1, #0x8000 - ldrne r1, [r0] - orrne r1, r1, r2 - strne r1, [r0] - bx lr - arm_func_end IntToFixedPoint64 - arm_func_start FixedPoint64ToInt FixedPoint64ToInt: ; 0x02001CB0 ldmia r0, {r1, r2} diff --git a/include/main_02001BB4.h b/include/main_02001BB4.h index 4b282b12..3573a59f 100644 --- a/include/main_02001BB4.h +++ b/include/main_02001BB4.h @@ -4,5 +4,6 @@ #include "util.h" u32 sub_02001BB4(s32 x, s32 y); +void IntToFixedPoint64(struct fixed_point_64* out, s32 x); #endif //PMDSKY_MAIN_02001BB4_H diff --git a/include/util.h b/include/util.h index c700f204..0c8843ab 100644 --- a/include/util.h +++ b/include/util.h @@ -32,6 +32,13 @@ struct fixed_point { s16 fractional; }; +// 64-bit signed fixed-point number with 16 fraction bits. +// Represents the number ((upper << 16) + (lower >> 16) + (lower & 0xFFFF) * 2^-16) +struct fixed_point_64 { + s32 upper; // sign bit, plus the 31 most significant integer bits + u32 lower; // the 32 least significant bits (16 integer + 16 fraction) +}; + // Compares two numbers and return the minimum #define MIN(A, B) ((A > B) ? B : A) diff --git a/main.lsf b/main.lsf index ff617db3..a00b20ee 100644 --- a/main.lsf +++ b/main.lsf @@ -21,7 +21,7 @@ Static main Object src/main_02001A54.o Object asm/main_02001B0C.o Object src/main_02001BB4.o - Object asm/main_02001C80.o + Object asm/main_02001CB0.o Object src/main_0200224C.o Object asm/main_020022C4.o Object src/main_0200330C.o diff --git a/src/main_02001BB4.c b/src/main_02001BB4.c index 8bbc0f6c..8032a27b 100644 --- a/src/main_02001BB4.c +++ b/src/main_02001BB4.c @@ -61,3 +61,12 @@ u32 sub_02001BB4(s32 x, s32 y) return var_r8; } + +void IntToFixedPoint64(struct fixed_point_64* out, s32 x) +{ + out->upper = (u32) (x & ~0xFFFF) >> 0x10; + out->lower = x << 0x10; + if (x & 0x8000) { + out->upper = out->upper | ~0xFFFF; + } +}