From 1d06ebbd5f4fd53ce2f4502032ef21ab8213991e Mon Sep 17 00:00:00 2001 From: CT56567 <126840265+CT56567@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:06:51 +1100 Subject: [PATCH 1/4] Update CPU.h --- PSEMU/CPU.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PSEMU/CPU.h b/PSEMU/CPU.h index 28118cc..f954703 100644 --- a/PSEMU/CPU.h +++ b/PSEMU/CPU.h @@ -88,6 +88,8 @@ class CPU { void op_cop3(Instruction instruction); void reset(); + void op_cop2(Instruction instruction); + // HELPER FUNCTIONS void set_reg(uint32_t index, uint32_t value) { out_regs[index] = value; From 85e52eb3c70fb26d9086d1147fc146d489dd77d9 Mon Sep 17 00:00:00 2001 From: CT56567 <126840265+CT56567@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:10:30 +1100 Subject: [PATCH 2/4] Update CPU.cpp --- PSEMU/CPU.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/PSEMU/CPU.cpp b/PSEMU/CPU.cpp index 798c469..4565917 100644 --- a/PSEMU/CPU.cpp +++ b/PSEMU/CPU.cpp @@ -334,6 +334,11 @@ void CPU::decode_execute(Instruction instruction) { op_cop3(instruction); std::cout << "[CPU] INFO: COP3 (I-Type)\n"; break; + + case (0b010010): + op_cop2(instruction); + std::cout << "[CPU] INFO: COP2 (I-Type)\n"; + break; default: std::cout << "[CPU] ERROR: Unhandled Instruction \n"; @@ -1095,3 +1100,6 @@ void CPU::op_cop3(Instruction) { exception(Exception::CoprocessorError); } +void CPU::op_cop2(Instruction instruction) { + std::cout << "Unhandled GTE instruction: {" << std::to_string(instruction); +} From c66a5ac241a80e642d9f4e2395263f871b915bf4 Mon Sep 17 00:00:00 2001 From: CT56567 <126840265+CT56567@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:11:57 +1100 Subject: [PATCH 3/4] Update CPU.h --- PSEMU/CPU.h | 1 + 1 file changed, 1 insertion(+) diff --git a/PSEMU/CPU.h b/PSEMU/CPU.h index f954703..5f1a444 100644 --- a/PSEMU/CPU.h +++ b/PSEMU/CPU.h @@ -89,6 +89,7 @@ class CPU { void reset(); void op_cop2(Instruction instruction); + void op_lwl(Instruction instruction); // HELPER FUNCTIONS void set_reg(uint32_t index, uint32_t value) { From b32096f9f54bf2fb97421c50103e3a37f3cce528 Mon Sep 17 00:00:00 2001 From: CT56567 <126840265+CT56567@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:58:21 +1100 Subject: [PATCH 4/4] Update CPU.cpp --- PSEMU/CPU.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/PSEMU/CPU.cpp b/PSEMU/CPU.cpp index 4565917..071f372 100644 --- a/PSEMU/CPU.cpp +++ b/PSEMU/CPU.cpp @@ -339,6 +339,11 @@ void CPU::decode_execute(Instruction instruction) { op_cop2(instruction); std::cout << "[CPU] INFO: COP2 (I-Type)\n"; break; + + case (0b100010): + op_lwl(instruction); + std::cout << "[CPU] INFO: LWL (I-Type)\n"; + break; default: std::cout << "[CPU] ERROR: Unhandled Instruction \n"; @@ -1103,3 +1108,37 @@ void CPU::op_cop3(Instruction) { void CPU::op_cop2(Instruction instruction) { std::cout << "Unhandled GTE instruction: {" << std::to_string(instruction); } + +void CPU::op_lwl(Instruction instruction) { + uint32_t i = instruction.imm_s(); + uint32_t t = instruction.rt(); + uint32_t s = instruction.rs(); + + uint32_t value = 0; + uint32_t addr = regs[s] + i; + + uint32_t cur_v = out_regs[t]; + + uint32_t aligned_addr = addr & 0xFFFFFFFC; + uint32_t aligned_word = bus->read(aligned_addr); + + switch (addr & 0b11){ + case 0: + value = (cur_v & 0x00ffffff) | (aligned_word << 24); + break; + + case 1: + value = (cur_v & 0x0000ffff) | (aligned_word << 16); + break; + + case 2: + value = (cur_v & 0x000000ff) | (aligned_word << 8); + break; + + case 3: + value = (cur_v & 0x00000000) | (aligned_word << 0); + break; + } + + load = std::make_tuple(t, value); +}