From 4e5a067a7bd8cdbc3fe7fa3128dd1b366be759bf Mon Sep 17 00:00:00 2001 From: tomvita <68505331+tomvita@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:59:43 +0800 Subject: [PATCH] Type 9 extension for floating point math --- docs/features/cheats.md | 9 +++--- .../dmnt/source/cheat/impl/dmnt_cheat_vm.cpp | 32 ++++++++++++------- .../dmnt/source/cheat/impl/dmnt_cheat_vm.hpp | 6 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/docs/features/cheats.md b/docs/features/cheats.md index 5f5ec10e0..6412bf14e 100644 --- a/docs/features/cheats.md +++ b/docs/features/cheats.md @@ -271,11 +271,10 @@ Code type 0x9 allows performing arithmetic on registers. + 7: Logical Not (discards right-hand operand) + 8: Logical Xor + 9: None/Move (discards right-hand operand) -+ 10: Float Addition, Width force to 4 bytes -+ 11: Float Multiplication, Width force to 4 bytes -+ 12: Double Addition, Width force to 8 bytes -+ 13: Double Multiplication, Width force to 8 bytes - ++ 10: Float Addition, T==4 single T==8 double ++ 11: Float Subtraction, T==4 single T==8 double ++ 12: Float Multiplication, T==4 single T==8 double ++ 13: Float Division, T==4 single T==8 double --- ### Code Type 0xA: Store Register to Memory Address diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp index 8945205fa..70b14fe8d 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp @@ -1060,21 +1060,29 @@ namespace ams::dmnt::cheat::impl { case RegisterArithmeticType_None: res_val = operand_1_value; break; - case RegisterArithmeticType_FloatAddition: { - cur_opcode.perform_math_reg.bit_width = 4; - *(float *)&res_val = *(float *)&operand_1_value + *(float *)&operand_2_value; + case RegisterArithmeticType_FloatAddition: + if (cur_opcode.perform_math_reg.bit_width == 4) + *(float *)&res_val = *(float *)&operand_1_value + *(float *)&operand_2_value; + if (cur_opcode.perform_math_reg.bit_width == 8) + *(double *)&res_val = *(double *)&operand_1_value + *(double *)&operand_2_value; + break; + case RegisterArithmeticType_FloatSubtraction: { + if (cur_opcode.perform_math_reg.bit_width == 4) + *(float *)&res_val = *(float *)&operand_1_value - *(float *)&operand_2_value; + if (cur_opcode.perform_math_reg.bit_width == 8) + *(double *)&res_val = *(double *)&operand_1_value - *(double *)&operand_2_value; } break; case RegisterArithmeticType_FloatMultiplication: { - cur_opcode.perform_math_reg.bit_width = 4; - *(float *)&res_val = *(float *)&operand_1_value * *(float *)&operand_2_value; + if (cur_opcode.perform_math_reg.bit_width == 4) + *(float *)&res_val = *(float *)&operand_1_value * *(float *)&operand_2_value; + if (cur_opcode.perform_math_reg.bit_width == 8) + *(double *)&res_val = *(double *)&operand_1_value * *(double *)&operand_2_value; } break; - case RegisterArithmeticType_DoubleAddition: { - cur_opcode.perform_math_reg.bit_width = 8; - *(double *)&res_val = *(double *)&operand_1_value + *(double *)&operand_2_value; - } break; - case RegisterArithmeticType_DoubleMultiplication: { - cur_opcode.perform_math_reg.bit_width = 8; - *(double *)&res_val = *(double *)&operand_1_value * *(double *)&operand_2_value; + case RegisterArithmeticType_FloatDivision: { + if (cur_opcode.perform_math_reg.bit_width == 4) + *(float *)&res_val = *(float *)&operand_1_value / *(float *)&operand_2_value; + if (cur_opcode.perform_math_reg.bit_width == 8) + *(double *)&res_val = *(double *)&operand_1_value / *(double *)&operand_2_value; } break; } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.hpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.hpp index d9688938e..573d7796d 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.hpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.hpp @@ -87,9 +87,9 @@ namespace ams::dmnt::cheat::impl { RegisterArithmeticType_None = 9, RegisterArithmeticType_FloatAddition = 10, - RegisterArithmeticType_FloatMultiplication = 11, - RegisterArithmeticType_DoubleAddition = 12, - RegisterArithmeticType_DoubleMultiplication = 13, + RegisterArithmeticType_FloatSubtraction = 11, + RegisterArithmeticType_FloatMultiplication = 12, + RegisterArithmeticType_FloatDivision = 13, }; enum StoreRegisterOffsetType : u32 {