diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 699c645..8c71fd1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,6 +30,8 @@ target_sources( UI/UIManager.h UI/Disassembler.cpp UI/Disassembler.h + UI/RegisterView.cpp + UI/RegisterView.h ) target_link_libraries(${PROJECT_NAME} PRIVATE vendor) diff --git a/src/Interpreter/Interpreter.cpp b/src/Interpreter/Interpreter.cpp index 01575ce..0057773 100644 --- a/src/Interpreter/Interpreter.cpp +++ b/src/Interpreter/Interpreter.cpp @@ -495,7 +495,7 @@ void Interpreter::drw_vx_vy_nibble(const Instruction& instruction) const const auto& vx = this->machine_state->v[instruction.x]; const auto& vy = this->machine_state->v[instruction.y]; auto& vf = this->machine_state->v[0xF]; - auto& i = this->machine_state->i; + const auto& i = this->machine_state->i; const uint8_t start_x = vx & 63; const uint8_t start_y = vy & 31; diff --git a/src/UI/RegisterView.cpp b/src/UI/RegisterView.cpp new file mode 100644 index 0000000..6034cd2 --- /dev/null +++ b/src/UI/RegisterView.cpp @@ -0,0 +1,57 @@ +#include "RegisterView.h" + +#include "imgui.h" +#include "../Interpreter/MachineState.h" + +RegisterView::RegisterView( + std::shared_ptr graphics, + std::shared_ptr machine_state, + std::shared_ptr callback_manager) : + graphics{std::move(graphics)}, + machine_state{std::move(machine_state)}, + callback_manager{std::move(callback_manager)} +{ +} + +void RegisterView::render() +{ + if (ImGui::Begin("Chip8 - Registers")) + { + if (ImGui::BeginTable("Registers", 4, ImGuiTableFlags_Borders)) + { + ImGui::TableNextRow(); + + ImGui::TableSetColumnIndex(0); + ImGui::Text("PC"); + ImGui::Text("0x%04X", this->machine_state->pc); + ImGui::TableSetColumnIndex(1); + ImGui::Text("I"); + ImGui::Text("0x%02X", this->machine_state->i); + + ImGui::TableSetColumnIndex(2); + ImGui::Text("DT"); + ImGui::Text("0x%04X", this->machine_state->dt); + + ImGui::TableSetColumnIndex(3); + ImGui::Text("ST"); + ImGui::Text("0x%04X", this->machine_state->st); + } + ImGui::EndTable(); + + if (ImGui::BeginTable("Registers", 8, ImGuiTableFlags_Borders)) + { + for (int i = 0; i < 2; i++) + { + ImGui::TableNextRow(); + for (int j = 0; j < 8; j++) + { + ImGui::TableSetColumnIndex(j); + ImGui::Text("V%i", i * 8 + j); + ImGui::Text("0x%02X", this->machine_state->v[i * 8 + j]); + } + } + } + ImGui::EndTable(); + } + ImGui::End(); +} diff --git a/src/UI/RegisterView.h b/src/UI/RegisterView.h new file mode 100644 index 0000000..7b66394 --- /dev/null +++ b/src/UI/RegisterView.h @@ -0,0 +1,28 @@ +#ifndef REGISTERVIEW_H +#define REGISTERVIEW_H +#include + +#include "CallbackManager.h" +#include "../Graphics/Graphics.h" + + +struct MachineState; + +class RegisterView +{ + std::shared_ptr graphics; + std::shared_ptr machine_state; + std::shared_ptr callback_manager; + +public: + RegisterView( + std::shared_ptr graphics, + std::shared_ptr machine_state, + std::shared_ptr callback_manager + ); + + void render(); +}; + + +#endif //REGISTERVIEW_H diff --git a/src/UI/UIManager.cpp b/src/UI/UIManager.cpp index c9e05a8..98fefa2 100644 --- a/src/UI/UIManager.cpp +++ b/src/UI/UIManager.cpp @@ -2,6 +2,7 @@ #include "Disassembler.h" #include "MemoryViewer.h" +#include "RegisterView.h" #include "RomInfo.h" UIManager::UIManager( @@ -21,7 +22,8 @@ UIManager::UIManager( memory_viewer{std::make_unique(this->graphics, this->machine_state, this->callback_manager)}, disassembler{ std::make_unique(this->graphics, this->machine_state, this->interpreter, this->callback_manager) - } + }, + register_view{std::make_unique(this->graphics, this->machine_state, this->callback_manager)} { } @@ -32,4 +34,5 @@ void UIManager::render() this->rom_info->render(); this->memory_viewer->render(); this->disassembler->render(); + this->register_view->render(); } diff --git a/src/UI/UIManager.h b/src/UI/UIManager.h index 9b01e01..d9696e7 100644 --- a/src/UI/UIManager.h +++ b/src/UI/UIManager.h @@ -7,6 +7,7 @@ #include "Disassembler.h" #include "Display.h" #include "MemoryViewer.h" +#include "RegisterView.h" #include "RomInfo.h" #include "../Graphics/Graphics.h" #include "../Interpreter/Interpreter.h" @@ -22,6 +23,7 @@ class UIManager std::unique_ptr rom_info; std::unique_ptr memory_viewer; std::unique_ptr disassembler; + std::unique_ptr register_view; public: UIManager(