Creado register view

This commit is contained in:
2025-06-28 17:57:20 -04:00
parent a803e733da
commit a477a21d7f
6 changed files with 94 additions and 2 deletions

View File

@@ -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)

View File

@@ -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;

57
src/UI/RegisterView.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include "RegisterView.h"
#include "imgui.h"
#include "../Interpreter/MachineState.h"
RegisterView::RegisterView(
std::shared_ptr<Graphics> graphics,
std::shared_ptr<MachineState> machine_state,
std::shared_ptr<CallbackManager> 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();
}

28
src/UI/RegisterView.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef REGISTERVIEW_H
#define REGISTERVIEW_H
#include <memory>
#include "CallbackManager.h"
#include "../Graphics/Graphics.h"
struct MachineState;
class RegisterView
{
std::shared_ptr<Graphics> graphics;
std::shared_ptr<MachineState> machine_state;
std::shared_ptr<CallbackManager> callback_manager;
public:
RegisterView(
std::shared_ptr<Graphics> graphics,
std::shared_ptr<MachineState> machine_state,
std::shared_ptr<CallbackManager> callback_manager
);
void render();
};
#endif //REGISTERVIEW_H

View File

@@ -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<MemoryViewer>(this->graphics, this->machine_state, this->callback_manager)},
disassembler{
std::make_unique<Disassembler>(this->graphics, this->machine_state, this->interpreter, this->callback_manager)
}
},
register_view{std::make_unique<RegisterView>(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();
}

View File

@@ -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<RomInfo> rom_info;
std::unique_ptr<MemoryViewer> memory_viewer;
std::unique_ptr<Disassembler> disassembler;
std::unique_ptr<RegisterView> register_view;
public:
UIManager(