Merge pull request #4473 from lioncash/cheat-desig
dmnt_cheat_vm: Make use of designated initializers
This commit is contained in:
commit
c6e5a36452
|
@ -313,30 +313,32 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
|
|
||||||
switch (opcode_type) {
|
switch (opcode_type) {
|
||||||
case CheatVmOpcodeType::StoreStatic: {
|
case CheatVmOpcodeType::StoreStatic: {
|
||||||
StoreStaticOpcode store_static{};
|
|
||||||
// 0TMR00AA AAAAAAAA YYYYYYYY (YYYYYYYY)
|
// 0TMR00AA AAAAAAAA YYYYYYYY (YYYYYYYY)
|
||||||
// Read additional words.
|
// Read additional words.
|
||||||
const u32 second_dword = GetNextDword();
|
const u32 second_dword = GetNextDword();
|
||||||
store_static.bit_width = (first_dword >> 24) & 0xF;
|
const u32 bit_width = (first_dword >> 24) & 0xF;
|
||||||
store_static.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF);
|
|
||||||
store_static.offset_register = ((first_dword >> 16) & 0xF);
|
opcode.opcode = StoreStaticOpcode{
|
||||||
store_static.rel_address =
|
.bit_width = bit_width,
|
||||||
(static_cast<u64>(first_dword & 0xFF) << 32ul) | static_cast<u64>(second_dword);
|
.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF),
|
||||||
store_static.value = GetNextVmInt(store_static.bit_width);
|
.offset_register = (first_dword >> 16) & 0xF,
|
||||||
opcode.opcode = store_static;
|
.rel_address = (static_cast<u64>(first_dword & 0xFF) << 32) | second_dword,
|
||||||
|
.value = GetNextVmInt(bit_width),
|
||||||
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::BeginConditionalBlock: {
|
case CheatVmOpcodeType::BeginConditionalBlock: {
|
||||||
BeginConditionalOpcode begin_cond{};
|
|
||||||
// 1TMC00AA AAAAAAAA YYYYYYYY (YYYYYYYY)
|
// 1TMC00AA AAAAAAAA YYYYYYYY (YYYYYYYY)
|
||||||
// Read additional words.
|
// Read additional words.
|
||||||
const u32 second_dword = GetNextDword();
|
const u32 second_dword = GetNextDword();
|
||||||
begin_cond.bit_width = (first_dword >> 24) & 0xF;
|
const u32 bit_width = (first_dword >> 24) & 0xF;
|
||||||
begin_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF);
|
|
||||||
begin_cond.cond_type = static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF);
|
opcode.opcode = BeginConditionalOpcode{
|
||||||
begin_cond.rel_address =
|
.bit_width = bit_width,
|
||||||
(static_cast<u64>(first_dword & 0xFF) << 32ul) | static_cast<u64>(second_dword);
|
.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF),
|
||||||
begin_cond.value = GetNextVmInt(begin_cond.bit_width);
|
.cond_type = static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF),
|
||||||
opcode.opcode = begin_cond;
|
.rel_address = (static_cast<u64>(first_dword & 0xFF) << 32) | second_dword,
|
||||||
|
.value = GetNextVmInt(bit_width),
|
||||||
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::EndConditionalBlock: {
|
case CheatVmOpcodeType::EndConditionalBlock: {
|
||||||
// 20000000
|
// 20000000
|
||||||
|
@ -344,12 +346,14 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
opcode.opcode = EndConditionalOpcode{};
|
opcode.opcode = EndConditionalOpcode{};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::ControlLoop: {
|
case CheatVmOpcodeType::ControlLoop: {
|
||||||
ControlLoopOpcode ctrl_loop{};
|
|
||||||
// 300R0000 VVVVVVVV
|
// 300R0000 VVVVVVVV
|
||||||
// 310R0000
|
// 310R0000
|
||||||
// Parse register, whether loop start or loop end.
|
// Parse register, whether loop start or loop end.
|
||||||
ctrl_loop.start_loop = ((first_dword >> 24) & 0xF) == 0;
|
ControlLoopOpcode ctrl_loop{
|
||||||
ctrl_loop.reg_index = ((first_dword >> 20) & 0xF);
|
.start_loop = ((first_dword >> 24) & 0xF) == 0,
|
||||||
|
.reg_index = (first_dword >> 20) & 0xF,
|
||||||
|
.num_iters = 0,
|
||||||
|
};
|
||||||
|
|
||||||
// Read number of iters if loop start.
|
// Read number of iters if loop start.
|
||||||
if (ctrl_loop.start_loop) {
|
if (ctrl_loop.start_loop) {
|
||||||
|
@ -358,66 +362,65 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
opcode.opcode = ctrl_loop;
|
opcode.opcode = ctrl_loop;
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::LoadRegisterStatic: {
|
case CheatVmOpcodeType::LoadRegisterStatic: {
|
||||||
LoadRegisterStaticOpcode ldr_static{};
|
|
||||||
// 400R0000 VVVVVVVV VVVVVVVV
|
// 400R0000 VVVVVVVV VVVVVVVV
|
||||||
// Read additional words.
|
// Read additional words.
|
||||||
ldr_static.reg_index = ((first_dword >> 16) & 0xF);
|
opcode.opcode = LoadRegisterStaticOpcode{
|
||||||
ldr_static.value =
|
.reg_index = (first_dword >> 16) & 0xF,
|
||||||
(static_cast<u64>(GetNextDword()) << 32ul) | static_cast<u64>(GetNextDword());
|
.value = (static_cast<u64>(GetNextDword()) << 32) | GetNextDword(),
|
||||||
opcode.opcode = ldr_static;
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::LoadRegisterMemory: {
|
case CheatVmOpcodeType::LoadRegisterMemory: {
|
||||||
LoadRegisterMemoryOpcode ldr_memory{};
|
|
||||||
// 5TMRI0AA AAAAAAAA
|
// 5TMRI0AA AAAAAAAA
|
||||||
// Read additional words.
|
// Read additional words.
|
||||||
const u32 second_dword = GetNextDword();
|
const u32 second_dword = GetNextDword();
|
||||||
ldr_memory.bit_width = (first_dword >> 24) & 0xF;
|
opcode.opcode = LoadRegisterMemoryOpcode{
|
||||||
ldr_memory.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF);
|
.bit_width = (first_dword >> 24) & 0xF,
|
||||||
ldr_memory.reg_index = ((first_dword >> 16) & 0xF);
|
.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF),
|
||||||
ldr_memory.load_from_reg = ((first_dword >> 12) & 0xF) != 0;
|
.reg_index = ((first_dword >> 16) & 0xF),
|
||||||
ldr_memory.rel_address =
|
.load_from_reg = ((first_dword >> 12) & 0xF) != 0,
|
||||||
(static_cast<u64>(first_dword & 0xFF) << 32ul) | static_cast<u64>(second_dword);
|
.rel_address = (static_cast<u64>(first_dword & 0xFF) << 32) | second_dword,
|
||||||
opcode.opcode = ldr_memory;
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::StoreStaticToAddress: {
|
case CheatVmOpcodeType::StoreStaticToAddress: {
|
||||||
StoreStaticToAddressOpcode str_static{};
|
|
||||||
// 6T0RIor0 VVVVVVVV VVVVVVVV
|
// 6T0RIor0 VVVVVVVV VVVVVVVV
|
||||||
// Read additional words.
|
// Read additional words.
|
||||||
str_static.bit_width = (first_dword >> 24) & 0xF;
|
opcode.opcode = StoreStaticToAddressOpcode{
|
||||||
str_static.reg_index = ((first_dword >> 16) & 0xF);
|
.bit_width = (first_dword >> 24) & 0xF,
|
||||||
str_static.increment_reg = ((first_dword >> 12) & 0xF) != 0;
|
.reg_index = (first_dword >> 16) & 0xF,
|
||||||
str_static.add_offset_reg = ((first_dword >> 8) & 0xF) != 0;
|
.increment_reg = ((first_dword >> 12) & 0xF) != 0,
|
||||||
str_static.offset_reg_index = ((first_dword >> 4) & 0xF);
|
.add_offset_reg = ((first_dword >> 8) & 0xF) != 0,
|
||||||
str_static.value =
|
.offset_reg_index = (first_dword >> 4) & 0xF,
|
||||||
(static_cast<u64>(GetNextDword()) << 32ul) | static_cast<u64>(GetNextDword());
|
.value = (static_cast<u64>(GetNextDword()) << 32) | GetNextDword(),
|
||||||
opcode.opcode = str_static;
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::PerformArithmeticStatic: {
|
case CheatVmOpcodeType::PerformArithmeticStatic: {
|
||||||
PerformArithmeticStaticOpcode perform_math_static{};
|
|
||||||
// 7T0RC000 VVVVVVVV
|
// 7T0RC000 VVVVVVVV
|
||||||
// Read additional words.
|
// Read additional words.
|
||||||
perform_math_static.bit_width = (first_dword >> 24) & 0xF;
|
opcode.opcode = PerformArithmeticStaticOpcode{
|
||||||
perform_math_static.reg_index = ((first_dword >> 16) & 0xF);
|
.bit_width = (first_dword >> 24) & 0xF,
|
||||||
perform_math_static.math_type =
|
.reg_index = ((first_dword >> 16) & 0xF),
|
||||||
static_cast<RegisterArithmeticType>((first_dword >> 12) & 0xF);
|
.math_type = static_cast<RegisterArithmeticType>((first_dword >> 12) & 0xF),
|
||||||
perform_math_static.value = GetNextDword();
|
.value = GetNextDword(),
|
||||||
opcode.opcode = perform_math_static;
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::BeginKeypressConditionalBlock: {
|
case CheatVmOpcodeType::BeginKeypressConditionalBlock: {
|
||||||
BeginKeypressConditionalOpcode begin_keypress_cond{};
|
|
||||||
// 8kkkkkkk
|
// 8kkkkkkk
|
||||||
// Just parse the mask.
|
// Just parse the mask.
|
||||||
begin_keypress_cond.key_mask = first_dword & 0x0FFFFFFF;
|
opcode.opcode = BeginKeypressConditionalOpcode{
|
||||||
opcode.opcode = begin_keypress_cond;
|
.key_mask = first_dword & 0x0FFFFFFF,
|
||||||
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::PerformArithmeticRegister: {
|
case CheatVmOpcodeType::PerformArithmeticRegister: {
|
||||||
PerformArithmeticRegisterOpcode perform_math_reg{};
|
|
||||||
// 9TCRSIs0 (VVVVVVVV (VVVVVVVV))
|
// 9TCRSIs0 (VVVVVVVV (VVVVVVVV))
|
||||||
perform_math_reg.bit_width = (first_dword >> 24) & 0xF;
|
PerformArithmeticRegisterOpcode perform_math_reg{
|
||||||
perform_math_reg.math_type = static_cast<RegisterArithmeticType>((first_dword >> 20) & 0xF);
|
.bit_width = (first_dword >> 24) & 0xF,
|
||||||
perform_math_reg.dst_reg_index = ((first_dword >> 16) & 0xF);
|
.math_type = static_cast<RegisterArithmeticType>((first_dword >> 20) & 0xF),
|
||||||
perform_math_reg.src_reg_1_index = ((first_dword >> 12) & 0xF);
|
.dst_reg_index = (first_dword >> 16) & 0xF,
|
||||||
perform_math_reg.has_immediate = ((first_dword >> 8) & 0xF) != 0;
|
.src_reg_1_index = (first_dword >> 12) & 0xF,
|
||||||
|
.src_reg_2_index = 0,
|
||||||
|
.has_immediate = ((first_dword >> 8) & 0xF) != 0,
|
||||||
|
.value = {},
|
||||||
|
};
|
||||||
if (perform_math_reg.has_immediate) {
|
if (perform_math_reg.has_immediate) {
|
||||||
perform_math_reg.src_reg_2_index = 0;
|
perform_math_reg.src_reg_2_index = 0;
|
||||||
perform_math_reg.value = GetNextVmInt(perform_math_reg.bit_width);
|
perform_math_reg.value = GetNextVmInt(perform_math_reg.bit_width);
|
||||||
|
@ -427,7 +430,6 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
opcode.opcode = perform_math_reg;
|
opcode.opcode = perform_math_reg;
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::StoreRegisterToAddress: {
|
case CheatVmOpcodeType::StoreRegisterToAddress: {
|
||||||
StoreRegisterToAddressOpcode str_register{};
|
|
||||||
// ATSRIOxa (aaaaaaaa)
|
// ATSRIOxa (aaaaaaaa)
|
||||||
// A = opcode 10
|
// A = opcode 10
|
||||||
// T = bit width
|
// T = bit width
|
||||||
|
@ -439,20 +441,23 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
// Relative Address
|
// Relative Address
|
||||||
// x = offset register (for offset type 1), memory type (for offset type 3)
|
// x = offset register (for offset type 1), memory type (for offset type 3)
|
||||||
// a = relative address (for offset type 2+3)
|
// a = relative address (for offset type 2+3)
|
||||||
str_register.bit_width = (first_dword >> 24) & 0xF;
|
StoreRegisterToAddressOpcode str_register{
|
||||||
str_register.str_reg_index = ((first_dword >> 20) & 0xF);
|
.bit_width = (first_dword >> 24) & 0xF,
|
||||||
str_register.addr_reg_index = ((first_dword >> 16) & 0xF);
|
.str_reg_index = (first_dword >> 20) & 0xF,
|
||||||
str_register.increment_reg = ((first_dword >> 12) & 0xF) != 0;
|
.addr_reg_index = (first_dword >> 16) & 0xF,
|
||||||
str_register.ofs_type = static_cast<StoreRegisterOffsetType>(((first_dword >> 8) & 0xF));
|
.increment_reg = ((first_dword >> 12) & 0xF) != 0,
|
||||||
str_register.ofs_reg_index = ((first_dword >> 4) & 0xF);
|
.ofs_type = static_cast<StoreRegisterOffsetType>(((first_dword >> 8) & 0xF)),
|
||||||
|
.mem_type = MemoryAccessType::MainNso,
|
||||||
|
.ofs_reg_index = (first_dword >> 4) & 0xF,
|
||||||
|
.rel_address = 0,
|
||||||
|
};
|
||||||
switch (str_register.ofs_type) {
|
switch (str_register.ofs_type) {
|
||||||
case StoreRegisterOffsetType::None:
|
case StoreRegisterOffsetType::None:
|
||||||
case StoreRegisterOffsetType::Reg:
|
case StoreRegisterOffsetType::Reg:
|
||||||
// Nothing more to do
|
// Nothing more to do
|
||||||
break;
|
break;
|
||||||
case StoreRegisterOffsetType::Imm:
|
case StoreRegisterOffsetType::Imm:
|
||||||
str_register.rel_address =
|
str_register.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword();
|
||||||
((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword()));
|
|
||||||
break;
|
break;
|
||||||
case StoreRegisterOffsetType::MemReg:
|
case StoreRegisterOffsetType::MemReg:
|
||||||
str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
||||||
|
@ -460,8 +465,7 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
case StoreRegisterOffsetType::MemImm:
|
case StoreRegisterOffsetType::MemImm:
|
||||||
case StoreRegisterOffsetType::MemImmReg:
|
case StoreRegisterOffsetType::MemImmReg:
|
||||||
str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
||||||
str_register.rel_address =
|
str_register.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword();
|
||||||
((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword()));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
str_register.ofs_type = StoreRegisterOffsetType::None;
|
str_register.ofs_type = StoreRegisterOffsetType::None;
|
||||||
|
@ -470,7 +474,6 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
opcode.opcode = str_register;
|
opcode.opcode = str_register;
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::BeginRegisterConditionalBlock: {
|
case CheatVmOpcodeType::BeginRegisterConditionalBlock: {
|
||||||
BeginRegisterConditionalOpcode begin_reg_cond{};
|
|
||||||
// C0TcSX##
|
// C0TcSX##
|
||||||
// C0TcS0Ma aaaaaaaa
|
// C0TcS0Ma aaaaaaaa
|
||||||
// C0TcS1Mr
|
// C0TcS1Mr
|
||||||
|
@ -492,11 +495,19 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
// r = offset register.
|
// r = offset register.
|
||||||
// X = other register.
|
// X = other register.
|
||||||
// V = value.
|
// V = value.
|
||||||
begin_reg_cond.bit_width = (first_dword >> 20) & 0xF;
|
|
||||||
begin_reg_cond.cond_type =
|
BeginRegisterConditionalOpcode begin_reg_cond{
|
||||||
static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF);
|
.bit_width = (first_dword >> 20) & 0xF,
|
||||||
begin_reg_cond.val_reg_index = ((first_dword >> 12) & 0xF);
|
.cond_type = static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF),
|
||||||
begin_reg_cond.comp_type = static_cast<CompareRegisterValueType>((first_dword >> 8) & 0xF);
|
.val_reg_index = (first_dword >> 12) & 0xF,
|
||||||
|
.comp_type = static_cast<CompareRegisterValueType>((first_dword >> 8) & 0xF),
|
||||||
|
.mem_type = MemoryAccessType::MainNso,
|
||||||
|
.addr_reg_index = 0,
|
||||||
|
.other_reg_index = 0,
|
||||||
|
.ofs_reg_index = 0,
|
||||||
|
.rel_address = 0,
|
||||||
|
.value = {},
|
||||||
|
};
|
||||||
|
|
||||||
switch (begin_reg_cond.comp_type) {
|
switch (begin_reg_cond.comp_type) {
|
||||||
case CompareRegisterValueType::StaticValue:
|
case CompareRegisterValueType::StaticValue:
|
||||||
|
@ -508,26 +519,25 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
case CompareRegisterValueType::MemoryRelAddr:
|
case CompareRegisterValueType::MemoryRelAddr:
|
||||||
begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
||||||
begin_reg_cond.rel_address =
|
begin_reg_cond.rel_address =
|
||||||
((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword()));
|
(static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword();
|
||||||
break;
|
break;
|
||||||
case CompareRegisterValueType::MemoryOfsReg:
|
case CompareRegisterValueType::MemoryOfsReg:
|
||||||
begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
||||||
begin_reg_cond.ofs_reg_index = (first_dword & 0xF);
|
begin_reg_cond.ofs_reg_index = (first_dword & 0xF);
|
||||||
break;
|
break;
|
||||||
case CompareRegisterValueType::RegisterRelAddr:
|
case CompareRegisterValueType::RegisterRelAddr:
|
||||||
begin_reg_cond.addr_reg_index = ((first_dword >> 4) & 0xF);
|
begin_reg_cond.addr_reg_index = (first_dword >> 4) & 0xF;
|
||||||
begin_reg_cond.rel_address =
|
begin_reg_cond.rel_address =
|
||||||
((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword()));
|
(static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword();
|
||||||
break;
|
break;
|
||||||
case CompareRegisterValueType::RegisterOfsReg:
|
case CompareRegisterValueType::RegisterOfsReg:
|
||||||
begin_reg_cond.addr_reg_index = ((first_dword >> 4) & 0xF);
|
begin_reg_cond.addr_reg_index = (first_dword >> 4) & 0xF;
|
||||||
begin_reg_cond.ofs_reg_index = (first_dword & 0xF);
|
begin_reg_cond.ofs_reg_index = first_dword & 0xF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
opcode.opcode = begin_reg_cond;
|
opcode.opcode = begin_reg_cond;
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::SaveRestoreRegister: {
|
case CheatVmOpcodeType::SaveRestoreRegister: {
|
||||||
SaveRestoreRegisterOpcode save_restore_reg{};
|
|
||||||
// C10D0Sx0
|
// C10D0Sx0
|
||||||
// C1 = opcode 0xC1
|
// C1 = opcode 0xC1
|
||||||
// D = destination index.
|
// D = destination index.
|
||||||
|
@ -535,36 +545,37 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
// x = 3 if clearing reg, 2 if clearing saved value, 1 if saving a register, 0 if restoring
|
// x = 3 if clearing reg, 2 if clearing saved value, 1 if saving a register, 0 if restoring
|
||||||
// a register.
|
// a register.
|
||||||
// NOTE: If we add more save slots later, current encoding is backwards compatible.
|
// NOTE: If we add more save slots later, current encoding is backwards compatible.
|
||||||
save_restore_reg.dst_index = (first_dword >> 16) & 0xF;
|
opcode.opcode = SaveRestoreRegisterOpcode{
|
||||||
save_restore_reg.src_index = (first_dword >> 8) & 0xF;
|
.dst_index = (first_dword >> 16) & 0xF,
|
||||||
save_restore_reg.op_type = static_cast<SaveRestoreRegisterOpType>((first_dword >> 4) & 0xF);
|
.src_index = (first_dword >> 8) & 0xF,
|
||||||
opcode.opcode = save_restore_reg;
|
.op_type = static_cast<SaveRestoreRegisterOpType>((first_dword >> 4) & 0xF),
|
||||||
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::SaveRestoreRegisterMask: {
|
case CheatVmOpcodeType::SaveRestoreRegisterMask: {
|
||||||
SaveRestoreRegisterMaskOpcode save_restore_regmask{};
|
|
||||||
// C2x0XXXX
|
// C2x0XXXX
|
||||||
// C2 = opcode 0xC2
|
// C2 = opcode 0xC2
|
||||||
// x = 3 if clearing reg, 2 if clearing saved value, 1 if saving, 0 if restoring.
|
// x = 3 if clearing reg, 2 if clearing saved value, 1 if saving, 0 if restoring.
|
||||||
// X = 16-bit bitmask, bit i --> save or restore register i.
|
// X = 16-bit bitmask, bit i --> save or restore register i.
|
||||||
save_restore_regmask.op_type =
|
SaveRestoreRegisterMaskOpcode save_restore_regmask{
|
||||||
static_cast<SaveRestoreRegisterOpType>((first_dword >> 20) & 0xF);
|
.op_type = static_cast<SaveRestoreRegisterOpType>((first_dword >> 20) & 0xF),
|
||||||
|
.should_operate = {},
|
||||||
|
};
|
||||||
for (std::size_t i = 0; i < NumRegisters; i++) {
|
for (std::size_t i = 0; i < NumRegisters; i++) {
|
||||||
save_restore_regmask.should_operate[i] = (first_dword & (1u << i)) != 0;
|
save_restore_regmask.should_operate[i] = (first_dword & (1U << i)) != 0;
|
||||||
}
|
}
|
||||||
opcode.opcode = save_restore_regmask;
|
opcode.opcode = save_restore_regmask;
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::ReadWriteStaticRegister: {
|
case CheatVmOpcodeType::ReadWriteStaticRegister: {
|
||||||
ReadWriteStaticRegisterOpcode rw_static_reg{};
|
|
||||||
// C3000XXx
|
// C3000XXx
|
||||||
// C3 = opcode 0xC3.
|
// C3 = opcode 0xC3.
|
||||||
// XX = static register index.
|
// XX = static register index.
|
||||||
// x = register index.
|
// x = register index.
|
||||||
rw_static_reg.static_idx = ((first_dword >> 4) & 0xFF);
|
opcode.opcode = ReadWriteStaticRegisterOpcode{
|
||||||
rw_static_reg.idx = (first_dword & 0xF);
|
.static_idx = (first_dword >> 4) & 0xFF,
|
||||||
opcode.opcode = rw_static_reg;
|
.idx = first_dword & 0xF,
|
||||||
|
};
|
||||||
} break;
|
} break;
|
||||||
case CheatVmOpcodeType::DebugLog: {
|
case CheatVmOpcodeType::DebugLog: {
|
||||||
DebugLogOpcode debug_log{};
|
|
||||||
// FFFTIX##
|
// FFFTIX##
|
||||||
// FFFTI0Ma aaaaaaaa
|
// FFFTI0Ma aaaaaaaa
|
||||||
// FFFTI1Mr
|
// FFFTI1Mr
|
||||||
|
@ -583,31 +594,36 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
|
||||||
// a = relative address.
|
// a = relative address.
|
||||||
// r = offset register.
|
// r = offset register.
|
||||||
// X = value register.
|
// X = value register.
|
||||||
debug_log.bit_width = (first_dword >> 16) & 0xF;
|
DebugLogOpcode debug_log{
|
||||||
debug_log.log_id = ((first_dword >> 12) & 0xF);
|
.bit_width = (first_dword >> 16) & 0xF,
|
||||||
debug_log.val_type = static_cast<DebugLogValueType>((first_dword >> 8) & 0xF);
|
.log_id = (first_dword >> 12) & 0xF,
|
||||||
|
.val_type = static_cast<DebugLogValueType>((first_dword >> 8) & 0xF),
|
||||||
|
.mem_type = MemoryAccessType::MainNso,
|
||||||
|
.addr_reg_index = 0,
|
||||||
|
.val_reg_index = 0,
|
||||||
|
.ofs_reg_index = 0,
|
||||||
|
.rel_address = 0,
|
||||||
|
};
|
||||||
|
|
||||||
switch (debug_log.val_type) {
|
switch (debug_log.val_type) {
|
||||||
case DebugLogValueType::RegisterValue:
|
case DebugLogValueType::RegisterValue:
|
||||||
debug_log.val_reg_index = ((first_dword >> 4) & 0xF);
|
debug_log.val_reg_index = (first_dword >> 4) & 0xF;
|
||||||
break;
|
break;
|
||||||
case DebugLogValueType::MemoryRelAddr:
|
case DebugLogValueType::MemoryRelAddr:
|
||||||
debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
||||||
debug_log.rel_address =
|
debug_log.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword();
|
||||||
((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword()));
|
|
||||||
break;
|
break;
|
||||||
case DebugLogValueType::MemoryOfsReg:
|
case DebugLogValueType::MemoryOfsReg:
|
||||||
debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF);
|
||||||
debug_log.ofs_reg_index = (first_dword & 0xF);
|
debug_log.ofs_reg_index = first_dword & 0xF;
|
||||||
break;
|
break;
|
||||||
case DebugLogValueType::RegisterRelAddr:
|
case DebugLogValueType::RegisterRelAddr:
|
||||||
debug_log.addr_reg_index = ((first_dword >> 4) & 0xF);
|
debug_log.addr_reg_index = (first_dword >> 4) & 0xF;
|
||||||
debug_log.rel_address =
|
debug_log.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword();
|
||||||
((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword()));
|
|
||||||
break;
|
break;
|
||||||
case DebugLogValueType::RegisterOfsReg:
|
case DebugLogValueType::RegisterOfsReg:
|
||||||
debug_log.addr_reg_index = ((first_dword >> 4) & 0xF);
|
debug_log.addr_reg_index = (first_dword >> 4) & 0xF;
|
||||||
debug_log.ofs_reg_index = (first_dword & 0xF);
|
debug_log.ofs_reg_index = first_dword & 0xF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
opcode.opcode = debug_log;
|
opcode.opcode = debug_log;
|
||||||
|
|
Reference in New Issue