Add load rom file to emulator ui
This commit is contained in:
@@ -727,7 +727,6 @@ class Cpu : public Loggable, public core::ExperimentFlags {
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
uint16_t SP() const { return memory.SP(); }
|
uint16_t SP() const { return memory.SP(); }
|
||||||
void SetSP(uint16_t value) { memory.SetSP(value); }
|
void SetSP(uint16_t value) { memory.SetSP(value); }
|
||||||
void set_next_pc(uint16_t value) { next_pc_ = value; }
|
|
||||||
|
|
||||||
bool IsBreakpoint(uint32_t address) {
|
bool IsBreakpoint(uint32_t address) {
|
||||||
return std::find(breakpoints_.begin(), breakpoints_.end(), address) !=
|
return std::find(breakpoints_.begin(), breakpoints_.end(), address) !=
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "app/core/constants.h"
|
#include "app/core/constants.h"
|
||||||
|
#include "app/core/platform/file_dialog.h"
|
||||||
#include "app/emu/snes.h"
|
#include "app/emu/snes.h"
|
||||||
#include "app/gui/icons.h"
|
#include "app/gui/icons.h"
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
@@ -58,9 +59,10 @@ void Emulator::Run() {
|
|||||||
printf("Failed to create texture: %s\n", SDL_GetError());
|
printf("Failed to create texture: %s\n", SDL_GetError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snes_.Init(*rom());
|
rom_data_ = rom()->vector();
|
||||||
wanted_frames_ = 1.0 / 60.0;
|
snes_.Init(rom_data_);
|
||||||
wanted_samples_ = 48000 /60;
|
wanted_frames_ = 1.0 / (snes_.Memory().pal_timing() ? 50.0 : 60.0);
|
||||||
|
wanted_samples_ = 48000 / (snes_.Memory().pal_timing() ? 50 : 60);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
||||||
countFreq = SDL_GetPerformanceFrequency();
|
countFreq = SDL_GetPerformanceFrequency();
|
||||||
@@ -110,9 +112,9 @@ void Emulator::Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::RenderSnesPpu() {
|
void Emulator::RenderSnesPpu() {
|
||||||
ImVec2 size = ImVec2(320, 480);
|
ImVec2 size = ImVec2(512, 480);
|
||||||
if (snes_.running()) {
|
if (snes_.running()) {
|
||||||
ImGui::BeginChild("EmulatorOutput", ImVec2(0, 240), true,
|
ImGui::BeginChild("EmulatorOutput", ImVec2(0, 480), true,
|
||||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar);
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar);
|
||||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x - size.x) * 0.5f);
|
ImGui::SetCursorPosX((ImGui::GetWindowSize().x - size.x) * 0.5f);
|
||||||
ImGui::SetCursorPosY((ImGui::GetWindowSize().y - size.y) * 0.5f);
|
ImGui::SetCursorPosY((ImGui::GetWindowSize().y - size.y) * 0.5f);
|
||||||
@@ -121,7 +123,7 @@ void Emulator::RenderSnesPpu() {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Emulator output not available.");
|
ImGui::Text("Emulator output not available.");
|
||||||
ImGui::BeginChild("EmulatorOutput", ImVec2(0, 240), true,
|
ImGui::BeginChild("EmulatorOutput", ImVec2(0, 480), true,
|
||||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar);
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar);
|
||||||
ImGui::SetCursorPosX(((ImGui::GetWindowSize().x * 0.5f) - size.x) * 0.5f);
|
ImGui::SetCursorPosX(((ImGui::GetWindowSize().x * 0.5f) - size.x) * 0.5f);
|
||||||
ImGui::SetCursorPosY(((ImGui::GetWindowSize().y * 0.5f) - size.y) * 0.5f);
|
ImGui::SetCursorPosY(((ImGui::GetWindowSize().y * 0.5f) - size.y) * 0.5f);
|
||||||
@@ -141,7 +143,8 @@ void Emulator::RenderNavBar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
auto navbar_node = gui::zeml::Parse(navbar_layout);
|
|
||||||
|
static auto navbar_node = gui::zeml::Parse(navbar_layout);
|
||||||
gui::zeml::Render(navbar_node);
|
gui::zeml::Render(navbar_node);
|
||||||
|
|
||||||
if (ImGui::Button(ICON_MD_PLAY_ARROW)) {
|
if (ImGui::Button(ICON_MD_PLAY_ARROW)) {
|
||||||
@@ -210,14 +213,16 @@ void Emulator::RenderNavBar() {
|
|||||||
ImGui::SetTooltip("Settings");
|
ImGui::SetTooltip("Settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool open_file = false;
|
||||||
SameLine();
|
SameLine();
|
||||||
if (ImGui::Button(ICON_MD_INFO)) {
|
if (ImGui::Button(ICON_MD_INFO)) {
|
||||||
|
open_file = true;
|
||||||
|
|
||||||
|
// About Debugger logic
|
||||||
|
}
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::SetTooltip("About Debugger");
|
ImGui::SetTooltip("About Debugger");
|
||||||
}
|
}
|
||||||
// About Debugger logic
|
|
||||||
}
|
|
||||||
|
|
||||||
SameLine();
|
SameLine();
|
||||||
ImGui::Checkbox("Logging", snes_.cpu().mutable_log_instructions());
|
ImGui::Checkbox("Logging", snes_.cpu().mutable_log_instructions());
|
||||||
|
|
||||||
@@ -239,6 +244,18 @@ void Emulator::RenderNavBar() {
|
|||||||
RenderMemoryViewer();
|
RenderMemoryViewer();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (open_file) {
|
||||||
|
auto file_name = FileDialogWrapper::ShowOpenFileDialog();
|
||||||
|
if (!file_name.empty()) {
|
||||||
|
std::ifstream file(file_name, std::ios::binary);
|
||||||
|
// Load the data directly into rom_data
|
||||||
|
rom_data_.assign(std::istreambuf_iterator<char>(file),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
|
snes_.Init(rom_data_);
|
||||||
|
open_file = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::HandleEvents() {
|
void Emulator::HandleEvents() {
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ class Emulator : public SharedRom {
|
|||||||
SNES snes_;
|
SNES snes_;
|
||||||
SDL_Texture* ppu_texture_;
|
SDL_Texture* ppu_texture_;
|
||||||
|
|
||||||
|
std::vector<uint8_t> rom_data_;
|
||||||
|
|
||||||
gui::zeml::Node emulator_node_;
|
gui::zeml::Node emulator_node_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ add_executable(
|
|||||||
app/core/labeling.cc
|
app/core/labeling.cc
|
||||||
app/gui/pipeline.cc
|
app/gui/pipeline.cc
|
||||||
app/editor/context/gfx_context.cc
|
app/editor/context/gfx_context.cc
|
||||||
|
app/core/platform/file_dialog.mm
|
||||||
${YAZE_APP_EMU_SRC}
|
${YAZE_APP_EMU_SRC}
|
||||||
${YAZE_APP_GFX_SRC}
|
${YAZE_APP_GFX_SRC}
|
||||||
${YAZE_APP_ZELDA3_SRC}
|
${YAZE_APP_ZELDA3_SRC}
|
||||||
|
|||||||
Reference in New Issue
Block a user