Skip to content

Commit b45fbd3

Browse files
committed
added Watcher
1 parent 221ff83 commit b45fbd3

File tree

8 files changed

+56
-16
lines changed

8 files changed

+56
-16
lines changed

emulator/src/Chipset/CPU.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <sstream>
1111

1212
namespace casioemu {
13+
size_t CPU::GetCurrentRealPC() {
14+
return (reg_csr << 16) | reg_pc;
15+
}
16+
1317
CPU::OpcodeSource CPU::opcode_sources[] = {
1418
// function hints opcode operand {size, mask, shift} x2
1519
// * Arithmetic Instructions

emulator/src/Chipset/CPU.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace casioemu {
8080
CPU(Emulator &emulator);
8181
~CPU();
8282
void SetupInternals();
83+
size_t GetCurrentRealPC();
8384

8485
/**
8586
* See 1.2.2.1 in the nX-U8 manual.

emulator/src/Gui/CodeViewer.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ void CodeViewer::DrawContent() {
128128
ImGui::SameLine();
129129
ImGui::TextColored(ImVec4(1.0, 1.0, 0.0, 1.0), "%05zX", get_real_pc(e));
130130
ImGui::SameLine();
131-
ImGui::Text("%s", e.srcbuf);
131+
if (m_emu->chipset.cpu.GetCurrentRealPC() == get_real_pc(e))
132+
ImGui::TextColored(ImVec4(0.0, 1.0, 0.0, 1.0), "%s", e.srcbuf);
133+
else
134+
ImGui::Text("%s", e.srcbuf);
132135
}
133136
}
134137
if (need_roll) {
@@ -138,14 +141,6 @@ void CodeViewer::DrawContent() {
138141
}
139142
}
140143

141-
void CodeViewer::DrawMonitor() {
142-
if (m_emu != nullptr) {
143-
casioemu::Chipset &chipset = m_emu->chipset;
144-
std::string s = chipset.cpu.GetBacktrace();
145-
ImGui::InputTextMultiline("##as", (char *)s.c_str(), s.size(), ImVec2(ImGui::GetWindowWidth(), 0), ImGuiInputTextFlags_ReadOnly);
146-
}
147-
}
148-
149144
static bool step_debug = false, trace_debug = false;
150145

151146
void CodeViewer::DrawWindow() {
@@ -161,10 +156,9 @@ void CodeViewer::DrawWindow() {
161156
return;
162157
}
163158
ImGui::Begin("Disassembly", 0);
164-
ImGui::BeginChild("##scrolling", ImVec2(0, -ImGui::GetWindowHeight() / 2));
159+
ImGui::BeginChild("##scrolling", ImVec2(0, -ImGui::GetTextLineHeight() * 1.8f));
165160
DrawContent();
166161
ImGui::EndChild();
167-
ImGui::Separator();
168162
ImGui::Text("Go to Addr:");
169163
ImGui::SameLine();
170164
ImGui::SetNextItemWidth(ImGui::CalcTextSize("000000").x);
@@ -187,7 +181,6 @@ void CodeViewer::DrawWindow() {
187181
triggered_bp_line = -1;
188182
}
189183
}
190-
DrawMonitor();
191184
ImGui::End();
192185
debug_flags = DEBUG_BREAKPOINT | (step_debug ? DEBUG_STEP : 0) | (trace_debug ? DEBUG_RET_TRACE : 0);
193186
}

emulator/src/Gui/Watcher.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "Watcher.hpp"
2+
#include "../Chipset/CPU.hpp"
3+
#include "../Chipset/Chipset.hpp"
4+
#include "../Peripheral/BatteryBackedRAM.hpp"
5+
#include "imgui/imgui.h"
6+
#include <cstdint>
7+
#include <cstdio>
8+
9+
void Watcher::DrawWindow() {
10+
ImGui::Begin("Watcher");
11+
ImGui::Text("Stack Trace");
12+
ImGui::BeginChild("##stack_trace", ImVec2(0, 8 * ImGui::GetTextLineHeight()));
13+
casioemu::Chipset &chipset = emu->chipset;
14+
casioemu::CPU &cpu = chipset.cpu;
15+
std::string s = cpu.GetBacktrace();
16+
ImGui::InputTextMultiline("##as", (char *)s.c_str(), s.size(), ImVec2(ImGui::GetWindowWidth(), 0), ImGuiInputTextFlags_ReadOnly);
17+
ImGui::EndChild();
18+
ImGui::Text("Registers");
19+
ImGui::BeginChild("##registers");
20+
ImGui::Text("r0 %02X | r1 %02X | r2 %02X | r3 %02X | PSW %02X | LR %01X:%04X", cpu.reg_r[ 0] & 0xff, cpu.reg_r[ 1] & 0xff, cpu.reg_r[ 2] & 0xff, cpu.reg_r[ 3] & 0xff, cpu.reg_psw & 0xff, cpu.reg_lcsr & 0xf, cpu.reg_lr & 0xffff);
21+
ImGui::Text("r4 %02X | r5 %02X | r6 %02X | r7 %02X | EPSW1 %02X | ELR1 %01X:%04X", cpu.reg_r[ 4] & 0xff, cpu.reg_r[ 5] & 0xff, cpu.reg_r[ 6] & 0xff, cpu.reg_r[ 7] & 0xff, cpu.reg_epsw[1] & 0xff, cpu.reg_ecsr[1] & 0xf, cpu.reg_elr[1] & 0xffff);
22+
ImGui::Text("r8 %02X | r9 %02X | r10 %02X | r11 %02X | EPSW2 %02X | ELR2 %01X:%04X", cpu.reg_r[ 8] & 0xff, cpu.reg_r[ 9] & 0xff, cpu.reg_r[10] & 0xff, cpu.reg_r[11] & 0xff, cpu.reg_epsw[2] & 0xff, cpu.reg_ecsr[2] & 0xf, cpu.reg_elr[2] & 0xffff);
23+
ImGui::Text("r12 %02X | r13 %02X | r14 %02X | r15 %02X | EPSW3 %02X | ELR3 %01X:%04X", cpu.reg_r[12] & 0xff, cpu.reg_r[13] & 0xff, cpu.reg_r[14] & 0xff, cpu.reg_r[15] & 0xff, cpu.reg_epsw[3] & 0xff, cpu.reg_ecsr[3] & 0xf, cpu.reg_elr[3] & 0xffff);
24+
ImGui::Text("SP %04X, EA %04X, ELVL %01X, PC %01X:%04X", cpu.reg_sp & 0xffff, cpu.reg_ea & 0xffff, cpu.reg_psw & 3, cpu.reg_csr & 0xf, cpu.reg_pc & 0xffff);
25+
ImGui::EndChild();
26+
ImGui::End();
27+
}

emulator/src/Gui/Watcher.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include "../Emulator.hpp"
4+
5+
class Watcher {
6+
private:
7+
casioemu::Emulator* emu;
8+
public:
9+
Watcher(casioemu::Emulator *_emu): emu(_emu) {}
10+
void DrawWindow();
11+
};

emulator/src/Gui/hex.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct MemoryEditor {
7373
};
7474

7575
// Settings
76-
bool Open; // = true // set to false when DrawWindow() was closed. ignore if not using DrawWindow().
7776
bool ReadOnly; // = false // disable any editing.
7877
int Cols; // = 16 // number of columns to display.
7978
bool OptShowOptions; // = true // display options button/context menu. when disabled, options will be locked unless you provide your own UI for them.
@@ -104,7 +103,6 @@ struct MemoryEditor {
104103

105104
MemoryEditor() {
106105
// Settings
107-
Open = true;
108106
ReadOnly = false;
109107
Cols = 16;
110108
OptShowOptions = true;
@@ -183,8 +181,7 @@ struct MemoryEditor {
183181
ImGui::SetNextWindowSize(ImVec2(s.WindowWidth, s.WindowWidth * 0.60f), ImGuiCond_FirstUseEver);
184182
ImGui::SetNextWindowSizeConstraints(ImVec2(0.0f, 0.0f), ImVec2(s.WindowWidth, FLT_MAX));
185183

186-
Open = true;
187-
if (ImGui::Begin(title, &Open, ImGuiWindowFlags_NoScrollbar)) {
184+
if (ImGui::Begin(title, nullptr, ImGuiWindowFlags_NoScrollbar)) {
188185
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows) && ImGui::IsMouseReleased(ImGuiMouseButton_Right))
189186
ImGui::OpenPopup("context");
190187
DrawContents(mem_data, mem_size, base_display_addr);

emulator/src/Gui/ui.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../Data/HardwareId.hpp"
22
#include "CodeViewer.hpp"
3+
#include "Watcher.hpp"
34
#include "SDL_timer.h"
45
#include "imgui/imgui.h"
56
#include "imgui/imgui_impl_sdl2.h"
@@ -13,6 +14,8 @@
1314

1415
char *n_ram_buffer = nullptr;
1516
CodeViewer *code_viewer = nullptr;
17+
Watcher *watcher = nullptr;
18+
1619
static SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
1720
static SDL_Window *window;
1821
static SDL_Renderer *renderer;
@@ -35,6 +38,7 @@ void debugger_gui_loop() {
3538
mem_edit.DrawWindow("RAM Editor", n_ram_buffer, size, base);
3639
}
3740
code_viewer->DrawWindow();
41+
watcher->DrawWindow();
3842

3943
// Rendering
4044
ImGui::Render();
@@ -68,6 +72,7 @@ int init_debugger_window() {
6872
ImGui_ImplSDLRenderer2_Init(renderer);
6973

7074
code_viewer = new CodeViewer(m_emu->GetModelFilePath("_disas.txt"));
75+
watcher = new Watcher(m_emu);
7176

7277
return 0;
7378
}

emulator/src/Gui/ui.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22
#include "../Emulator.hpp"
33
#include "CodeViewer.hpp"
4+
#include "Watcher.hpp"
45

56
int init_debugger_window();
67
void debugger_gui_loop();
78
extern char *n_ram_buffer;
89
extern casioemu::Emulator *m_emu;
910
extern CodeViewer *code_viewer;
11+
extern Watcher *watcher;

0 commit comments

Comments
 (0)