Skip to content

Commit 221ff83

Browse files
committed
working on ui
1 parent 5b8aac7 commit 221ff83

File tree

8 files changed

+45
-69
lines changed

8 files changed

+45
-69
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ If something goes wrong, run `mingw32-make clean` to clean up and start again.
5757

5858
## Command-line arguments
5959

60-
Each argument should have one of these two formats:
60+
Each argument should have the format:
6161

6262
* `key=value` where `key` does not contain any equal signs.
63-
* `path`: equivalent to `model=path`.
6463

6564
Supported values of `key` are: (if `value` is not mentioned then it does not matter)
6665

emulator/src/Emulator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ namespace casioemu {
4343
height = interface_background.dest.h;
4444
try {
4545
std::size_t pos;
46-
4746
auto width_iter = argv_map.find("width");
4847
if (width_iter != argv_map.end()) {
4948
width = std::stoi(width_iter->second, &pos, 0);
5049
if (pos != width_iter->second.size())
5150
PANIC("width parameter has extraneous trailing characters\n");
5251
}
53-
5452
auto height_iter = argv_map.find("height");
5553
if (height_iter != argv_map.end()) {
5654
height = std::stoi(height_iter->second, &pos, 0);

emulator/src/Gui/CodeViewer.cpp

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818

1919
casioemu::Emulator *m_emu = nullptr;
2020

21+
size_t get_real_pc(const CodeElem& e) {
22+
return get_real_pc(e.segment, e.offset);
23+
}
24+
25+
size_t get_real_pc(uint8_t seg, uint16_t off) {
26+
return (seg << 16) | off;
27+
}
28+
2129
CodeViewer::CodeViewer(std::string path) {
2230
src_path = path;
2331
std::ifstream f(src_path, std::ios::in);
@@ -51,10 +59,7 @@ CodeViewer::CodeViewer(std::string path) {
5159
}
5260

5361
bool operator<(const CodeElem &a, const CodeElem &b) {
54-
if (a.segment != b.segment)
55-
return a.segment < b.segment;
56-
else
57-
return a.offset < b.offset;
62+
return get_real_pc(a) < get_real_pc(b);
5863
}
5964

6065
CodeViewer::~CodeViewer() {
@@ -81,7 +86,7 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
8186
int idx = 0;
8287
LookUp(seg, offset, &idx);
8388
cur_row = idx;
84-
bp = idx;
89+
triggered_bp_line = idx;
8590
need_roll = true;
8691
return true;
8792
}
@@ -90,7 +95,7 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
9095
CodeElem e = codes[it->first];
9196
if (e.segment == seg && e.offset == offset) {
9297
cur_row = it->first;
93-
bp = it->first;
98+
triggered_bp_line = it->first;
9499
need_roll = true;
95100
return true;
96101
}
@@ -106,7 +111,7 @@ void CodeViewer::DrawContent() {
106111
for (int line_i = c.DisplayStart; line_i < c.DisplayEnd; line_i++) {
107112
CodeElem e = codes[line_i];
108113
auto it = break_points.find(line_i);
109-
if (line_i == bp) {
114+
if (line_i == triggered_bp_line) {
110115
// the break point is triggered!
111116
ImGui::TextColored(ImVec4(0.0, 1.0, 0.0, 1.0), "[ > ]");
112117
} else if (it == break_points.end() || !break_points[line_i]) {
@@ -121,36 +126,14 @@ void CodeViewer::DrawContent() {
121126
}
122127
}
123128
ImGui::SameLine();
124-
ImGui::TextColored(ImVec4(1.0, 1.0, 0.0, 1.0), "%d:%04x", e.segment, e.offset);
129+
ImGui::TextColored(ImVec4(1.0, 1.0, 0.0, 1.0), "%05zX", get_real_pc(e));
125130
ImGui::SameLine();
126-
if (selected_addr != (int64_t)e.segment * 0x10000 + e.offset) { // not selected
127-
ImGui::Text("%s", e.srcbuf);
128-
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) {
129-
cur_row = line_i;
130-
selected_addr = codes[cur_row].segment * 0x10000 + codes[cur_row].offset;
131-
}
132-
} else { // selected
133-
ImGui::InputText("##data", e.srcbuf, strlen(e.srcbuf), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AlwaysOverwrite);
134-
if (ImGui::IsWindowFocused()) {
135-
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow))) {
136-
cur_row++;
137-
if (cur_row >= max_row)
138-
cur_row = max_row;
139-
need_roll = true;
140-
} else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) {
141-
cur_row--;
142-
if (cur_row < 0)
143-
cur_row = 0;
144-
need_roll = true;
145-
}
146-
}
147-
}
131+
ImGui::Text("%s", e.srcbuf);
148132
}
149133
}
150134
if (need_roll) {
151135
float v = (float)cur_row / max_row * ImGui::GetScrollMaxY();
152136
ImGui::SetScrollY(v);
153-
selected_addr = codes[cur_row].segment * 0x10000 + codes[cur_row].offset;
154137
need_roll = false;
155138
}
156139
}
@@ -171,13 +154,13 @@ void CodeViewer::DrawWindow() {
171154
if (!is_loaded) {
172155
ImGui::SetNextWindowSize(ImVec2(w * 50, h * 10), ImGuiCond_FirstUseEver);
173156
ImGui::SetNextWindowContentSize(ImVec2(w * 50, h * 10));
174-
ImGui::Begin("Disassemble Window");
157+
ImGui::Begin("Disassembly");
175158
ImGui::SetCursorPos(ImVec2(w * 2, h * 5));
176-
ImGui::Text("Please wait loading...");
159+
ImGui::Text("Loading...");
177160
ImGui::End();
178161
return;
179162
}
180-
ImGui::Begin("Disassemble Window", 0);
163+
ImGui::Begin("Disassembly", 0);
181164
ImGui::BeginChild("##scrolling", ImVec2(0, -ImGui::GetWindowHeight() / 2));
182165
DrawContent();
183166
ImGui::EndChild();
@@ -187,29 +170,23 @@ void CodeViewer::DrawWindow() {
187170
ImGui::SetNextItemWidth(ImGui::CalcTextSize("000000").x);
188171
ImGui::InputText("##input", adrbuf, 8);
189172
if (adrbuf[0] != '\0' && ImGui::IsItemFocused()) {
190-
try {
191-
uint32_t addr = std::stoi(adrbuf, 0, 16);
173+
size_t addr;
174+
if (sscanf(adrbuf, "%zX", &addr) == 1)
192175
JumpTo(addr >> 16, addr & 0x0ffff);
193-
} catch (std::invalid_argument const &ex) {
194-
// do nothing
195-
} catch (std::out_of_range const &ex) {
196-
// do nothing
197-
}
198176
}
199177
ImGui::SameLine();
200178
ImGui::Checkbox("STEP", &step_debug);
201179
ImGui::SameLine();
202180
ImGui::Checkbox("TRACE", &trace_debug);
203-
if (bp != -1) {
181+
if (triggered_bp_line != -1) {
204182
ImGui::SameLine();
205183
if (ImGui::Button("Continue")) {
206184
if (!step_debug && !trace_debug)
207-
break_points[bp] = 0;
185+
break_points[triggered_bp_line] = 0;
208186
m_emu->SetPaused(false);
209-
bp = -1;
187+
triggered_bp_line = -1;
210188
}
211189
}
212-
213190
DrawMonitor();
214191
ImGui::End();
215192
debug_flags = DEBUG_BREAKPOINT | (step_debug ? DEBUG_STEP : 0) | (trace_debug ? DEBUG_RET_TRACE : 0);

emulator/src/Gui/CodeViewer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ struct CodeElem {
1414
CodeElem(uint8_t seg, uint16_t off) : segment(seg), offset(off) {}
1515
};
1616

17+
size_t get_real_pc(const CodeElem&);
18+
size_t get_real_pc(uint8_t, uint16_t);
19+
1720
enum EmuDebugFlag {
1821
DEBUG_BREAKPOINT = 1,
1922
DEBUG_STEP = 2,
@@ -33,8 +36,7 @@ class CodeViewer {
3336

3437
bool is_loaded = false;
3538
bool need_roll = false;
36-
int64_t selected_addr = -1;
37-
int64_t bp = -1;
39+
int64_t triggered_bp_line = -1;
3840

3941
public:
4042
uint8_t debug_flags = DEBUG_BREAKPOINT;

emulator/src/Gui/hex.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,13 @@ struct MemoryEditor {
322322
UserData user_data;
323323
user_data.CursorPos = -1;
324324
sprintf(user_data.CurrentBufOverwrite, format_byte, ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]);
325-
ImGuiInputTextFlags flags = ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_CallbackAlways;
326-
#if IMGUI_VERSION_NUM >= 18104
327-
flags |= ImGuiInputTextFlags_AlwaysOverwrite;
328-
#else
329-
flags |= ImGuiInputTextFlags_AlwaysInsertMode;
330-
#endif
325+
ImGuiInputTextFlags flags =
326+
ImGuiInputTextFlags_CharsHexadecimal |
327+
ImGuiInputTextFlags_EnterReturnsTrue |
328+
ImGuiInputTextFlags_AutoSelectAll |
329+
ImGuiInputTextFlags_NoHorizontalScroll |
330+
ImGuiInputTextFlags_CallbackAlways |
331+
ImGuiInputTextFlags_AlwaysOverwrite;
331332
ImGui::SetNextItemWidth(s.GlyphWidth * 2);
332333
if (ImGui::InputText("##data", DataInputBuf, IM_ARRAYSIZE(DataInputBuf), flags, UserData::Callback, &user_data))
333334
data_write = data_next = true;
@@ -452,7 +453,7 @@ struct MemoryEditor {
452453
ImGui::SetNextItemWidth((s.AddrDigitsCount + 1) * s.GlyphWidth + style.FramePadding.x * 2.0f);
453454
if (ImGui::InputText("##addr", AddrInputBuf, IM_ARRAYSIZE(AddrInputBuf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue)) {
454455
size_t goto_addr;
455-
if (sscanf(AddrInputBuf, "%" _PRISizeT "X", &goto_addr) == 1) {
456+
if (sscanf(AddrInputBuf, "%zX", &goto_addr) == 1) {
456457
GotoAddr = goto_addr - base_display_addr;
457458
HighlightMin = HighlightMax = (size_t)-1;
458459
}

emulator/src/Gui/ui.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static SDL_Window *window;
1818
static SDL_Renderer *renderer;
1919
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
2020

21-
void gui_loop() {
21+
void debugger_gui_loop() {
2222
if (!m_emu->Running())
2323
return;
2424

@@ -32,7 +32,7 @@ void gui_loop() {
3232
if (n_ram_buffer != nullptr) {
3333
size_t base = m_emu->hardware_id == casioemu::HW_ES_PLUS ? 0x8000 : 0xD000;
3434
size_t size = m_emu->hardware_id == casioemu::HW_ES_PLUS ? 0x0E00 : 0x2000;
35-
mem_edit.DrawWindow("RAM Editor", n_ram_buffer, base, size);
35+
mem_edit.DrawWindow("RAM Editor", n_ram_buffer, size, base);
3636
}
3737
code_viewer->DrawWindow();
3838

@@ -45,8 +45,8 @@ void gui_loop() {
4545
SDL_RenderPresent(renderer);
4646
}
4747

48-
int test_gui() {
49-
window = SDL_CreateWindow("CasioEmuX", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 900, 600, window_flags);
48+
int init_debugger_window() {
49+
window = SDL_CreateWindow("CasioEmuX Debugger", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 900, 600, window_flags);
5050
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
5151
if (renderer == nullptr) {
5252
SDL_Log("Error creating SDL_Renderer!");

emulator/src/Gui/ui.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#include "../Emulator.hpp"
33
#include "CodeViewer.hpp"
44

5-
int test_gui();
6-
void gui_cleanup();
7-
void gui_loop();
5+
int init_debugger_window();
6+
void debugger_gui_loop();
87
extern char *n_ram_buffer;
98
extern casioemu::Emulator *m_emu;
109
extern CodeViewer *code_viewer;

emulator/src/casioemu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ int main(int argc, char *argv[]) {
4141
key = std::string(argv[ix], eq_pos);
4242
value = eq_pos + 1;
4343
} else {
44-
key = "model";
45-
value = argv[ix];
44+
key = argv[ix];
45+
value = "";
4646
}
4747

4848
if (argv_map.find(key) == argv_map.end())
@@ -84,7 +84,7 @@ int main(int argc, char *argv[]) {
8484
// Used to signal to the console input thread when to stop.
8585
static std::atomic<bool> running(true);
8686

87-
test_gui();
87+
init_debugger_window();
8888
std::thread console_input_thread([&] {
8989
struct terminate_thread {};
9090
rl_event_hook = []() {
@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
147147
});
148148
std::thread t1([&]() {
149149
while (1) {
150-
gui_loop();
150+
debugger_gui_loop();
151151
}
152152
});
153153
t1.detach();

0 commit comments

Comments
 (0)