Add step mode to snes emulator

This commit is contained in:
scawful
2023-12-05 03:47:06 -05:00
parent 5755e2e867
commit dad4a38f59
4 changed files with 41 additions and 33 deletions

View File

@@ -35,20 +35,17 @@ using ImGui::Text;
void Emulator::Run() { void Emulator::Run() {
if (!snes_.running() && rom()->isLoaded()) { if (!snes_.running() && rom()->isLoaded()) {
snes_.SetupMemory(*rom()); snes_.SetupMemory(*rom());
}
// Setup and initialize memory
if (loading_ && !running_) {
snes_.Init(*rom()); snes_.Init(*rom());
running_ = true;
} }
RenderNavBar(); RenderNavBar();
if (running_) { if (running_) {
HandleEvents(); HandleEvents();
if (!step_) {
snes_.Run(); snes_.Run();
} }
}
RenderEmulator(); RenderEmulator();
} }
@@ -69,7 +66,7 @@ void Emulator::RenderNavBar() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Start Emulation"); ImGui::SetTooltip("Start Emulation");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_PAUSE)) { if (ImGui::Button(ICON_MD_PAUSE)) {
snes_.SetCpuMode(1); snes_.SetCpuMode(1);
@@ -77,15 +74,16 @@ void Emulator::RenderNavBar() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Pause Emulation"); ImGui::SetTooltip("Pause Emulation");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_SKIP_NEXT)) { if (ImGui::Button(ICON_MD_SKIP_NEXT)) {
// Step through Code logic // Step through Code logic
snes_.StepRun();
} }
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Step Through Code"); ImGui::SetTooltip("Step Through Code");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_REFRESH)) { if (ImGui::Button(ICON_MD_REFRESH)) {
// Reset Emulator logic // Reset Emulator logic
@@ -93,7 +91,7 @@ void Emulator::RenderNavBar() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Reset Emulator"); ImGui::SetTooltip("Reset Emulator");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_STOP)) { if (ImGui::Button(ICON_MD_STOP)) {
// Stop Emulation logic // Stop Emulation logic
@@ -102,7 +100,7 @@ void Emulator::RenderNavBar() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Stop Emulation"); ImGui::SetTooltip("Stop Emulation");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_SAVE)) { if (ImGui::Button(ICON_MD_SAVE)) {
// Save State logic // Save State logic
@@ -110,7 +108,7 @@ void Emulator::RenderNavBar() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Save State"); ImGui::SetTooltip("Save State");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_SYSTEM_UPDATE_ALT)) { if (ImGui::Button(ICON_MD_SYSTEM_UPDATE_ALT)) {
} }
@@ -119,7 +117,7 @@ void Emulator::RenderNavBar() {
} }
// Additional elements // Additional elements
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_SETTINGS)) { if (ImGui::Button(ICON_MD_SETTINGS)) {
// Settings logic // Settings logic
} }
@@ -127,7 +125,7 @@ void Emulator::RenderNavBar() {
ImGui::SetTooltip("Settings"); ImGui::SetTooltip("Settings");
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_INFO)) { if (ImGui::Button(ICON_MD_INFO)) {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("About Debugger"); ImGui::SetTooltip("About Debugger");
@@ -136,7 +134,7 @@ void Emulator::RenderNavBar() {
} }
static bool show_memory_viewer = false; static bool show_memory_viewer = false;
ImGui::SameLine(); SameLine();
if (ImGui::Button(ICON_MD_MEMORY)) { if (ImGui::Button(ICON_MD_MEMORY)) {
show_memory_viewer = !show_memory_viewer; show_memory_viewer = !show_memory_viewer;
} }
@@ -329,7 +327,7 @@ void Emulator::RenderMemoryViewer() {
mem_edit.GotoAddrAndHighlight(static_cast<ImU64>(bookmark.value), mem_edit.GotoAddrAndHighlight(static_cast<ImU64>(bookmark.value),
1); 1);
} }
ImGui::SameLine(); SameLine();
if (ImGui::Button("Delete")) { if (ImGui::Button("Delete")) {
// Logic to delete the bookmark // Logic to delete the bookmark
bookmarks.erase(std::remove_if(bookmarks.begin(), bookmarks.end(), bookmarks.erase(std::remove_if(bookmarks.begin(), bookmarks.end(),
@@ -358,7 +356,7 @@ void Emulator::RenderCpuInstructionLog(
// Filtering options // Filtering options
static char filterBuf[256]; static char filterBuf[256];
ImGui::InputText("Filter", filterBuf, IM_ARRAYSIZE(filterBuf)); ImGui::InputText("Filter", filterBuf, IM_ARRAYSIZE(filterBuf));
ImGui::SameLine(); SameLine();
if (ImGui::Button("Clear")) { /* Clear filter logic */ if (ImGui::Button("Clear")) { /* Clear filter logic */
} }
@@ -367,9 +365,8 @@ void Emulator::RenderCpuInstructionLog(
ImGui::Checkbox("Show All Opcodes", &showAllOpcodes); ImGui::Checkbox("Show All Opcodes", &showAllOpcodes);
// Instruction list // Instruction list
ImGui::BeginChild( ImGui::BeginChild("InstructionList", ImVec2(0, 0),
"InstructionList", ImVec2(0, 0), ImGuiChildFlags_None);
ImGuiChildFlags_AlwaysAutoResize | ImGuiChildFlags_AutoResizeY);
for (const auto& entry : instructionLog) { for (const auto& entry : instructionLog) {
if (ShouldDisplay(entry, filterBuf, showAllOpcodes)) { if (ShouldDisplay(entry, filterBuf, showAllOpcodes)) {
if (ImGui::Selectable( if (ImGui::Selectable(

View File

@@ -43,6 +43,7 @@ class Emulator : public SharedROM {
bool power_ = false; bool power_ = false;
bool loading_ = false; bool loading_ = false;
bool running_ = false; bool running_ = false;
bool step_ = true;
}; };
} // namespace emu } // namespace emu

View File

@@ -211,6 +211,9 @@ void SNES::Init(ROM& rom) {
// Misc // Misc
memory_.WriteByte(0x2133, 0x00); // SETINI memory_.WriteByte(0x2133, 0x00); // SETINI
// Psuedo-Init
memory_.WriteWord(0x2140, 0xBBAA);
running_ = true; running_ = true;
scanline = 0; scanline = 0;
} }
@@ -251,6 +254,22 @@ void SNES::Run() {
} }
} }
void SNES::StepRun() {
// Update the CPU
cpu_.UpdateClock(0.0);
cpu_.Update(CPU::UpdateMode::Step);
// Update the PPU
ppu_.UpdateClock(0.0);
ppu_.Update();
// Update the APU
apu_.UpdateClock(0.0);
apu_.Update();
HandleInput();
}
// Enable NMI Interrupts // Enable NMI Interrupts
void SNES::EnableVBlankInterrupts() { void SNES::EnableVBlankInterrupts() {
v_blank_flag_ = false; v_blank_flag_ = false;
@@ -363,14 +382,6 @@ void SNES::LoadState(const std::string& path) {
// ... // ...
} }
void SNES::Debug() {
// ...
}
void SNES::Breakpoint(uint16_t address) {
// ...
}
} // namespace emu } // namespace emu
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -33,6 +33,9 @@ class SNES : public DMA {
// Main emulation loop // Main emulation loop
void Run(); void Run();
// Step through a single instruction
void StepRun();
// Enable NMI Interrupts // Enable NMI Interrupts
void EnableVBlankInterrupts(); void EnableVBlankInterrupts();
@@ -56,10 +59,6 @@ class SNES : public DMA {
void SaveState(const std::string& path); void SaveState(const std::string& path);
void LoadState(const std::string& path); void LoadState(const std::string& path);
// Debugger
void Debug();
void Breakpoint(uint16_t address);
bool running() const { return running_; } bool running() const { return running_; }
auto cpu() -> CPU& { return cpu_; } auto cpu() -> CPU& { return cpu_; }