From 387f3c8f0776138dd7b257db8f3bad59002fc2d8 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Wed, 13 Sep 2023 04:15:16 +0530 Subject: [PATCH] chore: minor changes Signed-off-by: Amneesh Singh --- apps/target/main.cc | 4 ++-- flake.nix | 2 +- src/bus.cc | 4 ++-- src/bus.hh | 2 +- src/cpu/cpu.cc | 4 ++-- src/cpu/cpu.hh | 2 +- src/cpu/instruction.cc | 16 ++++++++-------- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/target/main.cc b/apps/target/main.cc index d70eb01..2efe183 100644 --- a/apps/target/main.cc +++ b/apps/target/main.cc @@ -79,8 +79,8 @@ main(int argc, const char* argv[]) { { Memory memory(std::move(bios), std::move(rom)); - Bus bus(std::make_shared(memory)); - Cpu cpu(std::make_shared(bus)); + Bus bus(memory); + Cpu cpu(bus); cpu.step(); } return 0; diff --git a/flake.nix b/flake.nix index 88745c5..6eaa4af 100644 --- a/flake.nix +++ b/flake.nix @@ -38,7 +38,7 @@ ".cc" ".build" ]; - outputs = [ "dev" "out" ]; + outputs = [ "out" "dev" ]; inherit nativeBuildInputs; diff --git a/src/bus.cc b/src/bus.cc index bddda01..8b4d939 100644 --- a/src/bus.cc +++ b/src/bus.cc @@ -1,8 +1,8 @@ #include "bus.hh" #include -Bus::Bus(std::shared_ptr memory) - : memory(memory) {} +Bus::Bus(Memory& memory) + : memory(std::make_shared(memory)) {} uint8_t Bus::read_byte(size_t address) { diff --git a/src/bus.hh b/src/bus.hh index 5c8b815..badadb7 100644 --- a/src/bus.hh +++ b/src/bus.hh @@ -5,7 +5,7 @@ class Bus { public: - Bus(std::shared_ptr memory); + Bus(Memory& memory); uint8_t read_byte(size_t address); void write_byte(size_t address, uint8_t byte); diff --git a/src/cpu/cpu.cc b/src/cpu/cpu.cc index b1fd50f..9873fbc 100644 --- a/src/cpu/cpu.cc +++ b/src/cpu/cpu.cc @@ -6,11 +6,11 @@ using namespace logger; -Cpu::Cpu(std::shared_ptr bus) +Cpu::Cpu(Bus& bus) : gpr(0) , cpsr(0) , spsr(0) - , bus(bus) + , bus(std::make_shared(bus)) , gpr_banked({ { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 } }) , spsr_banked({ 0, 0, 0, 0, 0 }) { cpsr.set_mode(Mode::System); diff --git a/src/cpu/cpu.hh b/src/cpu/cpu.hh index 9d12b56..c329417 100644 --- a/src/cpu/cpu.hh +++ b/src/cpu/cpu.hh @@ -9,7 +9,7 @@ using std::size_t; class Cpu { public: - Cpu(std::shared_ptr bus); + Cpu(Bus& bus); void step(); private: diff --git a/src/cpu/instruction.cc b/src/cpu/instruction.cc index 2985ad2..261c94b 100644 --- a/src/cpu/instruction.cc +++ b/src/cpu/instruction.cc @@ -22,7 +22,7 @@ Cpu::exec_arm(uint32_t insn) { }; // Branch and exhcange - if ((insn & 0x0ffffff0) == 0x012fff10) { + if ((insn & 0x0FFFFFF0) == 0x012FFF10) { static constexpr char syn[] = "BX"; uint8_t rn = insn & 0b1111; @@ -46,7 +46,7 @@ Cpu::exec_arm(uint32_t insn) { rst_nth_bit(gpr[15], 1); } // Branch - } else if ((insn & 0x0e000000) == 0x0a000000) { + } else if ((insn & 0x0E000000) == 0x0A000000) { static constexpr char syn[] = "B"; bool link = get_nth_bit(insn, 24); @@ -69,7 +69,7 @@ Cpu::exec_arm(uint32_t insn) { } // Multiply - } else if ((insn & 0x0fc000f0) == 0x00000090) { + } else if ((insn & 0x0FC000F0) == 0x00000090) { static constexpr char syn[2][4] = { "MUL", "MLA" }; uint8_t rm = get_bit_range(insn, 0, 3); @@ -116,7 +116,7 @@ Cpu::exec_arm(uint32_t insn) { } } // Multiply long - } else if ((insn & 0x0f8000f0) == 0x00800090) { + } else if ((insn & 0x0F8000F0) == 0x00800090) { static constexpr char syn[2][2][6] = { { "SMULL", "SMLAL" }, { "UMULL", "UMLAL" } }; @@ -177,7 +177,7 @@ Cpu::exec_arm(uint32_t insn) { } // Single data swap - } else if ((insn & 0x0fb00ff0) == 0x01000090) { + } else if ((insn & 0x0FB00FF0) == 0x01000090) { static constexpr char syn[] = "SWP"; uint8_t rm = get_bit_range(insn, 0, 3); @@ -205,7 +205,7 @@ Cpu::exec_arm(uint32_t insn) { // Halfword transfer // TODO: create abstraction to reuse for block data and single data // transfer - } else if ((insn & 0x0e000090) == 0x00000090) { + } else if ((insn & 0x0E000090) == 0x00000090) { static constexpr char syn[2][4] = { "STR", "LDR" }; uint8_t rm = get_bit_range(insn, 0, 3); @@ -265,13 +265,13 @@ Cpu::exec_arm(uint32_t insn) { gpr[rd] = bus->read_halfword(address); // sign extend the halfword if (get_nth_bit(gpr[rd], 15)) - gpr[rd] |= 0xffff0000; + gpr[rd] |= 0xFFFF0000; // byte } else { // sign extend the byte gpr[rd] = bus->read_byte(address); if (get_nth_bit(gpr[rd], 7)) - gpr[rd] |= 0xffffff00; + gpr[rd] |= 0xFFFFFF00; } // unsigned halfword } else if (h) {