1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-29 23:32:23 +00:00

dmnt-cheat: Implement static math opcode.

This commit is contained in:
Michael Scire 2019-02-27 18:46:53 -08:00
parent 2552c0327c
commit 68af2c1c2a
2 changed files with 46 additions and 14 deletions

View file

@ -68,19 +68,19 @@ void DmntCheatVm::Execute(const CheatProcessMetadata *metadata) {
case CheatVmOpcodeType_ControlLoop: case CheatVmOpcodeType_ControlLoop:
if (cur_opcode.ctrl_loop.start_loop) { if (cur_opcode.ctrl_loop.start_loop) {
/* Start a loop. */ /* Start a loop. */
this->registers[cur_opcode.ctrl_loop.register_index] = cur_opcode.ctrl_loop.num_iters; this->registers[cur_opcode.ctrl_loop.reg_index] = cur_opcode.ctrl_loop.num_iters;
this->loop_tops[cur_opcode.ctrl_loop.register_index] = this->instruction_ptr; this->loop_tops[cur_opcode.ctrl_loop.reg_index] = this->instruction_ptr;
} else { } else {
/* End a loop. */ /* End a loop. */
this->registers[cur_opcode.ctrl_loop.register_index]--; this->registers[cur_opcode.ctrl_loop.reg_index]--;
if (this->registers[cur_opcode.ctrl_loop.register_index] != 0) { if (this->registers[cur_opcode.ctrl_loop.reg_index] != 0) {
this->instruction_ptr = this->loop_tops[cur_opcode.ctrl_loop.register_index]; this->instruction_ptr = this->loop_tops[cur_opcode.ctrl_loop.reg_index];
} }
} }
break; break;
case CheatVmOpcodeType_LoadRegisterStatic: case CheatVmOpcodeType_LoadRegisterStatic:
/* Set a register to a static value. */ /* Set a register to a static value. */
this->registers[cur_opcode.ldr_static.register_index] = cur_opcode.ldr_static.value; this->registers[cur_opcode.ldr_static.reg_index] = cur_opcode.ldr_static.value;
break; break;
case CheatVmOpcodeType_LoadRegisterMemory: case CheatVmOpcodeType_LoadRegisterMemory:
{ {
@ -92,9 +92,41 @@ void DmntCheatVm::Execute(const CheatProcessMetadata *metadata) {
/* TODO */ /* TODO */
} }
break; break;
case CheatVmOpcodeType_PerformArithmetic: case CheatVmOpcodeType_PerformArithmeticStatic:
{ {
/* TODO */ /* Do requested math. */
switch (cur_opcode.perform_math_static.math_type) {
case RegisterArithmeticType_Addition:
this->registers[cur_opcode.perform_math_static.reg_index] += (u64)cur_opcode.perform_math_static.value;
break;
case RegisterArithmeticType_Subtraction:
this->registers[cur_opcode.perform_math_static.reg_index] -= (u64)cur_opcode.perform_math_static.value;
break;
case RegisterArithmeticType_Multiplication:
this->registers[cur_opcode.perform_math_static.reg_index] *= (u64)cur_opcode.perform_math_static.value;
break;
case RegisterArithmeticType_LeftShift:
this->registers[cur_opcode.perform_math_static.reg_index] <<= (u64)cur_opcode.perform_math_static.value;
break;
case RegisterArithmeticType_RightShift:
this->registers[cur_opcode.perform_math_static.reg_index] >>= (u64)cur_opcode.perform_math_static.value;
break;
}
/* Apply bit width. */
switch (cur_opcode.perform_math_static.bit_width) {
case 1:
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u8>(this->registers[cur_opcode.perform_math_static.reg_index]);
break;
case 2:
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u16>(this->registers[cur_opcode.perform_math_static.reg_index]);
break;
case 4:
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u32>(this->registers[cur_opcode.perform_math_static.reg_index]);
break;
case 8:
this->registers[cur_opcode.perform_math_static.reg_index] = static_cast<u64>(this->registers[cur_opcode.perform_math_static.reg_index]);
break;
}
} }
break; break;
case CheatVmOpcodeType_BeginKeypressConditionalBlock: case CheatVmOpcodeType_BeginKeypressConditionalBlock:

View file

@ -28,7 +28,7 @@ enum CheatVmOpcodeType : u32 {
CheatVmOpcodeType_LoadRegisterStatic = 4, CheatVmOpcodeType_LoadRegisterStatic = 4,
CheatVmOpcodeType_LoadRegisterMemory = 5, CheatVmOpcodeType_LoadRegisterMemory = 5,
CheatVmOpcodeType_StoreToRegisterAddress = 6, CheatVmOpcodeType_StoreToRegisterAddress = 6,
CheatVmOpcodeType_PerformArithmetic = 7, CheatVmOpcodeType_PerformArithmeticStatic = 7,
CheatVmOpcodeType_BeginKeypressConditionalBlock = 8, CheatVmOpcodeType_BeginKeypressConditionalBlock = 8,
}; };
@ -81,12 +81,12 @@ struct EndConditionalOpcode {};
struct ControlLoopOpcode { struct ControlLoopOpcode {
bool start_loop; bool start_loop;
u32 register_index; u32 reg_index;
u32 num_iters; u32 num_iters;
}; };
struct LoadRegisterStaticOpcode { struct LoadRegisterStaticOpcode {
u32 register_index; u32 reg_index;
u64 value; u64 value;
}; };
@ -107,11 +107,11 @@ struct StoreToRegisterAddressOpcode {
u64 value; u64 value;
}; };
struct PerformArithmeticOpcode { struct PerformArithmeticStaticOpcode {
u32 bit_width; u32 bit_width;
u32 reg_index; u32 reg_index;
RegisterArithmeticType math_type; RegisterArithmeticType math_type;
VmInt value; u32 value;
}; };
struct BeginKeypressConditionalOpcode { struct BeginKeypressConditionalOpcode {
@ -128,7 +128,7 @@ struct CheatVmOpcode {
LoadRegisterStaticOpcode ldr_static; LoadRegisterStaticOpcode ldr_static;
LoadRegisterMemoryOpcode ldr_memory; LoadRegisterMemoryOpcode ldr_memory;
StoreToRegisterAddressOpcode str_regaddr; StoreToRegisterAddressOpcode str_regaddr;
PerformArithmeticOpcode perform_math; PerformArithmeticStaticOpcode perform_math_static;
BeginKeypressConditionalOpcode begin_keypress_cond; BeginKeypressConditionalOpcode begin_keypress_cond;
}; };
}; };