diff --git a/src/GBACartMotionPak.cpp b/src/GBACartMotionPak.cpp index 9d564622..2d77022f 100644 --- a/src/GBACartMotionPak.cpp +++ b/src/GBACartMotionPak.cpp @@ -59,15 +59,23 @@ u16 CartMotionPakHomebrew::ROMRead(u32 addr) const static int AccelerationToMotionPak(float accel) { const float GRAVITY_M_S2 = 9.80665f; - const int COUNTS_PER_G = 819; - const int CENTER = 2048; return std::clamp( - (int) ((accel / GRAVITY_M_S2 * COUNTS_PER_G) + CENTER + 0.5), + (int) ((accel / (5 * GRAVITY_M_S2) + 0.5) * 4096), 0, 4095 ); } +static int AccelerationToMotionPakRetail(float accel) +{ + const float GRAVITY_M_S2 = 9.80665f; + + return std::clamp( + (int) ((accel / (5 * GRAVITY_M_S2) + 0.5) * 256), + 0, 254 + ); +} + static int RotationToMotionPak(float rot) { const float DEGREES_PER_RAD = 180 / M_PI; @@ -129,18 +137,6 @@ u8 CartMotionPakHomebrew::SRAMRead(u32 addr) return val; } -static int AccelerationToMotionPakRetail(float accel) -{ - // Formula provided by xperia64 (melonDS/#74) - const float GRAVITY_M_S2 = 9.80665f; - const float VOLTAGE = 3.3f; - - return std::clamp( - (int) ((accel * (VOLTAGE / 5) / GRAVITY_M_S2 + (VOLTAGE / 2)) * 256 / VOLTAGE), - 0, 254 - ); -} - CartMotionPakRetail::CartMotionPakRetail(void* userdata) : CartCommon(MotionPakRetail), UserData(userdata)