Skip to content

Commit a7b1057

Browse files
committed
improved CodeViewer scrolling, goto addr, displaying
1 parent 81093f1 commit a7b1057

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

emulator/src/Chipset/CPU.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ namespace casioemu {
403403
for (size_t bx = 0; bx != impl_operands[0].register_size; ++bx)
404404
reg_r[impl_operands[0].register_index + bx] = (uint8_t)(impl_operands[0].value >> (bx * 8));
405405

406+
// It's impossible to pause right after a DSR prefix instruction, which can result in something like this:
407+
// [ o ] DSR<-...
408+
// [ > ] ... <--- this line is not highlighted
409+
// [ o ] ... <--- this line is highlighted instead
406410
if (code_viewer) {
407411
if ((code_viewer->debug_flags & DEBUG_BREAKPOINT) && code_viewer->TryTrigBP(reg_csr, reg_pc)) {
408412
emulator.SetPaused(true);

emulator/src/Gui/CodeViewer.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ CodeViewer::~CodeViewer() {
6767

6868
CodeElem CodeViewer::LookUp(uint8_t seg, uint16_t offset, int *idx) {
6969
// binary search
70-
CodeElem target;
71-
target.offset = offset;
72-
target.segment = seg;
73-
auto it = std::lower_bound(codes.begin(), codes.end(), target);
74-
if (it == codes.end())
75-
it = codes.begin();
70+
CodeElem target(seg, offset);
71+
auto it = std::upper_bound(codes.begin(), codes.end(), target);
72+
if (it != codes.begin())
73+
--it;
7674
if (idx)
7775
*idx = it - codes.begin();
7876
return CodeElem(it->segment, it->offset);
@@ -86,8 +84,8 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
8684
int idx = 0;
8785
LookUp(seg, offset, &idx);
8886
cur_row = idx;
89-
triggered_bp_line = idx;
90-
need_roll = true;
87+
triggered_bp_line = -1;
88+
try_roll = true;
9189
return true;
9290
}
9391
for (auto it = break_points.begin(); it != break_points.end(); it++) {
@@ -96,7 +94,7 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
9694
if (e.segment == seg && e.offset == offset) {
9795
cur_row = it->first;
9896
triggered_bp_line = it->first;
99-
need_roll = true;
97+
try_roll = true;
10098
return true;
10199
}
102100
}
@@ -133,11 +131,13 @@ void CodeViewer::DrawContent() {
133131
else
134132
ImGui::Text("%s", e.srcbuf);
135133
}
136-
}
137-
if (need_roll) {
138-
float v = (float)cur_row / max_row * ImGui::GetScrollMaxY();
139-
ImGui::SetScrollY(v);
140-
need_roll = false;
134+
if (try_roll) {
135+
try_roll = false;
136+
if (!(c.DisplayStart + 1 <= cur_row && cur_row < c.DisplayEnd - 5)) {
137+
float v = (float)cur_row / max_row * ImGui::GetScrollMaxY();
138+
ImGui::SetScrollY(v);
139+
}
140+
}
141141
}
142142
}
143143

@@ -162,8 +162,7 @@ void CodeViewer::DrawWindow() {
162162
ImGui::Text("Go to Addr:");
163163
ImGui::SameLine();
164164
ImGui::SetNextItemWidth(ImGui::CalcTextSize("000000").x);
165-
ImGui::InputText("##input", adrbuf, 8);
166-
if (adrbuf[0] != '\0' && ImGui::IsItemFocused()) {
165+
if (ImGui::InputText("##input", adrbuf, sizeof(adrbuf), ImGuiInputTextFlags_EnterReturnsTrue)) {
167166
size_t addr;
168167
if (sscanf(adrbuf, "%zX", &addr) == 1)
169168
JumpTo(addr >> 16, addr & 0x0ffff);
@@ -172,7 +171,7 @@ void CodeViewer::DrawWindow() {
172171
ImGui::Checkbox("STEP", &step_debug);
173172
ImGui::SameLine();
174173
ImGui::Checkbox("TRACE", &trace_debug);
175-
if (triggered_bp_line != -1) {
174+
if (m_emu->GetPaused()) {
176175
ImGui::SameLine();
177176
if (ImGui::Button("Continue")) {
178177
if (!step_debug && !trace_debug)
@@ -189,5 +188,5 @@ void CodeViewer::JumpTo(uint8_t seg, uint16_t offset) {
189188
int idx = 0;
190189
LookUp(seg, offset, &idx);
191190
cur_row = idx;
192-
need_roll = true;
191+
try_roll = true;
193192
}

emulator/src/Gui/CodeViewer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CodeViewer {
3535
int cur_row = 0;
3636

3737
bool is_loaded = false;
38-
bool need_roll = false;
38+
bool try_roll = false;
3939
int64_t triggered_bp_line = -1;
4040

4141
public:

0 commit comments

Comments
 (0)