diff --git a/.idea/misc.xml b/.idea/misc.xml
index 0b76fe5..1b3a82a 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,4 +4,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2c93305..46a169d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,10 +1,13 @@
-add_executable(${PROJECT_NAME}
+add_executable(${PROJECT_NAME})
+target_sources(${PROJECT_NAME} PRIVATE main.cpp
+ bitops.h
+ Graphics.cpp
+ Graphics.h
Chip8.cpp
Chip8.h
Interpreter.cpp
- Interpreter.h)
-target_sources(${PROJECT_NAME} PRIVATE main.cpp
- Graphics.cpp
- Graphics.h
+ Interpreter.h
+ Chip8ControlPanel.cpp
+ Chip8ControlPanel.h
)
target_link_libraries(${PROJECT_NAME} PRIVATE vendor)
\ No newline at end of file
diff --git a/src/Chip8ControlPanel.cpp b/src/Chip8ControlPanel.cpp
new file mode 100644
index 0000000..dd1cb7b
--- /dev/null
+++ b/src/Chip8ControlPanel.cpp
@@ -0,0 +1,41 @@
+#include "Chip8ControlPanel.h"
+
+#include
+
+#include "imgui.h"
+
+void Chip8ControlPanel::render() {
+ constexpr auto full_width = ImVec2(-FLT_MIN, 0.0f);
+
+ if (ImGui::Begin("Chip-8 - Controls")) {
+ ImGui::Button("Load Rom", full_width);
+ if (ImGui::Button(run ? "Pause" : "Run", full_width)) {
+ run = !run;
+ }
+
+ ImGui::Text("Status: %s", "Stopped");
+
+ ImGui::SeparatorText("Debug");
+
+ ImGui::Button("Step One", full_width);
+ ImGui::Button(std::format("Step +{}", steps).data(), full_width);
+ ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
+ ImGui::InputInt("##steps", &steps);
+ ImGui::PopItemWidth();
+
+
+ ImGui::SeparatorText("Emulation speed (IPS)");
+
+ ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
+ ImGui::InputInt("##speed", &speed);
+ ImGui::PopItemWidth();
+
+ ImGui::SeparatorText("");
+
+ ImGui::Button("Reset", full_width);
+ ImGui::Button("Reload ROM", full_width);
+ }
+
+
+ ImGui::End();
+}
diff --git a/src/Chip8ControlPanel.h b/src/Chip8ControlPanel.h
new file mode 100644
index 0000000..5ecd428
--- /dev/null
+++ b/src/Chip8ControlPanel.h
@@ -0,0 +1,14 @@
+#ifndef CHIP8CONTROLPANEL_H
+#define CHIP8CONTROLPANEL_H
+
+
+class Chip8ControlPanel {
+ bool run = false;
+ int steps = 10;
+ int speed = 700;
+public:
+ void render();
+};
+
+
+#endif //CHIP8CONTROLPANEL_H
diff --git a/src/Graphics.cpp b/src/Graphics.cpp
index 193ea2a..f2ec2e3 100644
--- a/src/Graphics.cpp
+++ b/src/Graphics.cpp
@@ -3,6 +3,7 @@
//
#include "Graphics.h"
+#include "Chip8ControlPanel.h"
#include
#include
@@ -32,6 +33,7 @@ Graphics::Graphics(std::shared_ptr machine_state): machine_state{s
chip8_width(64),
chip8_height(32),
main_scale(1.0f) {}
+
bool Graphics::init_sdl() {
SDL_SetAppMetadata("CHIP-8 Emulator", "0.0.1", "fun.skrd.chip8");
@@ -104,7 +106,6 @@ void Graphics::draw() {
build_chip8_texture();
-
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDLRenderer3_NewFrame();
@@ -113,6 +114,7 @@ void Graphics::draw() {
ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport());
draw_chip8_widget();
+ ctrPanel.render();
ImGui::Render();
SDL_SetRenderScale(renderer.get(), io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
@@ -153,20 +155,19 @@ void Graphics::build_chip8_texture() {
}
void Graphics::draw_chip8_widget() {
- ImGui::Begin("CHIP-8");
+ ImGui::Begin("CHIP-8 - Display");
const ImVec2 available_size = ImGui::GetContentRegionAvail();
- int scale_x = static_cast(available_size.x / chip8_width);
- int scale_y = static_cast(available_size.y / chip8_height);
- int scale = std::max(1, std::min(scale_x, scale_y));
- ImVec2 scaled_size(chip8_width * scale, chip8_height * scale);
+ const int scale_x = static_cast(static_cast(available_size.x) / static_cast(chip8_width));
+ const int scale_y = static_cast(static_cast(available_size.y) / static_cast(chip8_height));
+ const int scale = std::max(1, std::min(scale_x, scale_y));
+ const ImVec2 scaled_size(static_cast(chip8_width * scale), static_cast(chip8_height * scale));
- ImVec2 cursor_pos = ImGui::GetCursorPos();
- ImVec2 center_offset((available_size.x - scaled_size.x) / 2, (available_size.y - scaled_size.y) / 2);
+ const ImVec2 cursor_pos = ImGui::GetCursorPos();
+ const ImVec2 center_offset((available_size.x - scaled_size.x) / 2, (available_size.y - scaled_size.y) / 2);
ImGui::SetCursorPos(ImVec2(cursor_pos.x + center_offset.x, cursor_pos.y + center_offset.y));
- ImGui::Image((ImTextureID)(intptr_t)texture.get(), scaled_size);
+ ImGui::Image(static_cast(reinterpret_cast(texture.get())), scaled_size);
ImGui::End();
}
-
diff --git a/src/Graphics.h b/src/Graphics.h
index 7c143b5..ec02a2c 100644
--- a/src/Graphics.h
+++ b/src/Graphics.h
@@ -7,6 +7,7 @@
#include
#include
+#include "Chip8ControlPanel.h"
#include "imgui.h"
#include "MachineState.h"
#include "SDL3/SDL.h"
@@ -28,6 +29,8 @@ class Graphics {
std::unique_ptr renderer;
std::unique_ptr texture;
+ Chip8ControlPanel ctrPanel;
+
int window_width;
int window_height;