openMSX
ImGuiDebugger.cc
Go to the documentation of this file.
1#include "ImGuiDebugger.hh"
2
4#include "ImGuiBreakPoints.hh"
5#include "ImGuiCharacter.hh"
6#include "ImGuiCpp.hh"
7#include "ImGuiManager.hh"
8#include "ImGuiPalette.hh"
10#include "ImGuiSymbols.hh"
11#include "ImGuiUtils.hh"
12#include "ImGuiVdpRegs.hh"
13#include "ImGuiWatchExpr.hh"
14
15#include "CPURegs.hh"
16#include "Dasm.hh"
17#include "Debuggable.hh"
18#include "Debugger.hh"
19#include "MSXCPU.hh"
20#include "MSXCPUInterface.hh"
22#include "MSXMotherBoard.hh"
23#include "RomPlain.hh"
24#include "RomInfo.hh"
25#include "SymbolManager.hh"
26
27#include "narrow.hh"
28#include "join.hh"
29#include "ranges.hh"
30#include "stl.hh"
31#include "strCat.hh"
32#include "StringOp.hh"
33#include "view.hh"
34
35#include <imgui.h>
36#include <imgui_stdlib.h>
37
38#include <cstdint>
39#include <vector>
40
41using namespace std::literals;
42
43namespace openmsx {
44
46 : ImGuiPart(manager_)
47 , symbolManager(manager.getReactor().getSymbolManager())
48{
49}
50
52
53// TODO quick and dirty, doesn't look right yet
54// Created from a .ttf file via:
55// binary_to_compressed_c openmsx-debugger-icons.ttf myIcons > myfont.cpp
56// https://github.com/ocornut/imgui/blob/master/misc/fonts/binary_to_compressed_c.cpp
57static const char icons_compressed_base85[1815+1] =
58 "7])#######;9u/('/###W),##.f1$#Q6>##%[n42)[KU%G5)=-<NE/1aNV=BZrPSb]->>#ICi9.o`(*HGsO2(b6O3L+lQS%,5LsCC,H3AnAMeNA*&#Gb';9Cs3BMNvSN`sr1dD4Eo3R/"
59 "w/)8eXHkG2V3dW.;h^`I@cj`W)a4&>ZW%q/o6Q<Bou@GMQuuoJH`;-*0iR/Go%fr6jMWVRReK?-qmnUCC'Hv'<J]p]`;`Y5@C=GH?o6O+j#)*Mp]G&#70lQ#;0xfLQ7wj#O?DX-@1>F%"
60 "5[)<#8JFgL6SgV-xew@'uB5X7If]8QR3O%b'kS`a)%vW-iXx6*BfW>-'lB#$1fs-$R'Mk+(lB#$ckf&,peu.:J/PQ'-MYY#jFs9)*lXJgaDe8Qw(Y:v47Y&#*r[w'WQ1x'1/V:m^U4+3"
61 "7GJcM604,NJ:-##O]-x-e:k(NX@$##]jP]4ACh^X0(^fLHl/o#g]L7#N'+&#L)Qv$t@0+*I5^+4]77<.aQ9k0$g`,3$+h,3Pqji06rs-$=uG=3tq$>MOAQY>@'.`&K8P>#g>AvL9q*<#"
62 ")EEjLr^PA#m.Us-KRb'4g)Cb4%IuD#GKRL2KkRP/N7R20t3wK#-8/$jJA5U;0viS&[5AC>uIVS%3^oh24GbM(hIL>#xP%U#WE323lpd].B[A30GK_+,sX/D=dn5q&0####GBO&#.1d7$"
63 "3g1$#prgo.-<Tv->;gF4LZ>x#<)]L(/p^I*^nr?#&Y@C#cF&@'wvPJ(?nU^#pRpQ0gF*j0EPtdVN'+9%k*l)*0qi<%>=+dVKrdx0Iu(kLgk4DWX?/YGZv9dMb/q8/+fMO#W+WBOM>#`Q"
64 "xR--3bO1F*.D,G4rFuG-hwhH-AI7q.3B3I):[(cJ[pl6&]3KI%)B1se0fv]M6T3kuGSoBJNCZY#q+er?Y,8v,5cNY5*`$s$#]YV-[@i?#=@[s$G+TC4P#l8./=]s$1Pev6jlje3&-Xf-"
65 "e](jr145d3?;Rv$ZUvC%h5%fqxC$Y@8^CY$O,@H),W'Z-W-Rh27<C[Krsf;$.wg<L9br,4%.6v,>=+dVIIx:/@JJH)Z:Nu.iUkJ2tpPm:t0(Q$@OEp%Upn;%j&5QCa)iS0%5YY#IX$_]"
66 "2^x^]Zrju5Fhf-*i+YV-6'PA#(cK+*mtq;/qwkj1?f6<.0MbI),VW/23>%&4m$ie3%&AA4l'eq7+jkA#dlfj-&$+&^S8VTd.^AN-,CeM0l,'hoodPir`IofLX=$##5C.%T=UYF%^Yk*$"
67 "/)m<-]'LS-&%.20'>uu#OYU7#euQ['GPSw8P`&:)AF14+&YF&#WW`>$Mbk-$I&l-$Bp0.$eo4wLW(I3#Ys%(#U-4&#MXN1#EIc>#ik*$M0xSfLRq)$#@>[A-$Mg;-'Spr-gN<;Ni;-##"
68 "Jer=--`/,Mv_d##tg`=-5X`=-8sG<-*fG<-+C`T.3f1$#mrG<-8X`=-/#XN0Ht*A#e5>##_RFgLX%1kLF=`T.3xL$#)6xU.R,_'#RA`T.T5$C#<rG<-M2(@-xrG<-DKx>-#EfT%8nT`3"
69 "]kU.G-i@+H=DpTCuAo6D<B?hD-rI+HXhdxFL7-AFY'auGt$EJ1m,(@'un@VHdt6L#s[DYGB0-gD.X`'/4+auGpkn+H5-xF-^%/(#B_=?-kQU@-QRt7/uJ6(#Cm[*b[^es/c:@bHdN4/#"
70 "d>?L-NNei.Fn@-#afh]%mxtLF//5UCvs.>B,(rE-i<cM:^0[eF/1u'#.mk.#[5C/#-)IqLR`4rL;wXrLX.lrL1x.qLf.K-#J#`5/%$S-#c7]nLNM-X.Q####F/LMTxS&=u<7L8#";
71
72static constexpr ImWchar DEBUGGER_ICON_MIN = 0xead1;
73static constexpr ImWchar DEBUGGER_ICON_MAX = 0xeb8f;
74static constexpr ImWchar DEBUGGER_ICON_RUN = 0xead3;
75static constexpr ImWchar DEBUGGER_ICON_BREAK = 0xead1;
76static constexpr ImWchar DEBUGGER_ICON_STEP_IN = 0xead4;
77static constexpr ImWchar DEBUGGER_ICON_STEP_OUT = 0xead5;
78static constexpr ImWchar DEBUGGER_ICON_STEP_OVER = 0xead6;
79static constexpr ImWchar DEBUGGER_ICON_STEP_BACK = 0xeb8f;
80
82{
83 auto& io = ImGui::GetIO();
84 ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
85 static constexpr std::array<ImWchar, 3> ranges = {DEBUGGER_ICON_MIN, DEBUGGER_ICON_MAX, 0};
86 io.Fonts->AddFontFromMemoryCompressedBase85TTF(icons_compressed_base85, 20.0f, &icons_config, ranges.data());
87}
88
90{
91 syncDisassemblyWithPC = true;
92}
93
94void ImGuiDebugger::save(ImGuiTextBuffer& buf)
95{
96 savePersistent(buf, *this, persistentElements);
97
98 // TODO in the future use c++23 std::chunk_by
99 auto it = hexEditors.begin();
100 auto et = hexEditors.end();
101 while (it != et) {
102 int count = 0;
103 auto name = std::string((*it)->getDebuggableName());
104 do {
105 ++it;
106 ++count;
107 } while (it != et && (*it)->getDebuggableName() == name);
108 buf.appendf("hexEditor.%s=%d\n", name.c_str(), count);
109 }
110
111}
112
114{
115 hexEditors.clear();
116}
117
118void ImGuiDebugger::loadLine(std::string_view name, zstring_view value)
119{
120 static constexpr std::string_view prefix = "hexEditor.";
121
122 if (loadOnePersistent(name, value, *this, persistentElements)) {
123 // already handled
124 } else if (name.starts_with(prefix)) {
125 if (auto r = StringOp::stringTo<unsigned>(value)) {
126 auto debuggableName = std::string(name.substr(prefix.size()));
127 auto [b, e] = ranges::equal_range(hexEditors, debuggableName, {}, &DebuggableEditor::getDebuggableName);
128 auto index = std::distance(b, e); // expected to be 0, but be robust against imgui.ini changes
129 for (auto i : xrange(*r)) {
130 e = hexEditors.insert(e, std::make_unique<DebuggableEditor>(manager, debuggableName, index + i));
131 ++e;
132 }
133 }
134 }
135}
136
138{
139 setDisassemblyScrollY = disassemblyScrollY;
140}
141
143{
144 auto createHexEditor = [&](const std::string& name) {
145 // prefer to reuse a previously closed editor
146 auto [b, e] = ranges::equal_range(hexEditors, name, {}, &DebuggableEditor::getDebuggableName);
147 for (auto it = b; it != e; ++it) {
148 if (!(*it)->open) {
149 (*it)->open = true;
150 return;
151 }
152 }
153 // or create a new one
154 auto index = std::distance(b, e);
155 auto it = hexEditors.insert(e, std::make_unique<DebuggableEditor>(manager, name, index));
156 (*it)->open = true;
157 };
158
159 im::Menu("Debugger", motherBoard != nullptr, [&]{
160 ImGui::MenuItem("Tool bar", nullptr, &showControl);
161 ImGui::MenuItem("Disassembly", nullptr, &showDisassembly);
162 ImGui::MenuItem("CPU registers", nullptr, &showRegisters);
163 ImGui::MenuItem("CPU flags", nullptr, &showFlags);
164 ImGui::MenuItem("Slots", nullptr, &showSlots);
165 ImGui::MenuItem("Stack", nullptr, &showStack);
166 auto it = ranges::lower_bound(hexEditors, "memory", {}, &DebuggableEditor::getDebuggableName);
167 bool memoryOpen = (it != hexEditors.end()) && (*it)->open;
168 if (ImGui::MenuItem("Memory", nullptr, &memoryOpen)) {
169 if (memoryOpen) {
170 createHexEditor("memory");
171 } else {
172 assert(it != hexEditors.end());
173 (*it)->open = false;
174 }
175 }
176 ImGui::Separator();
177 ImGui::MenuItem("Breakpoints", nullptr, &manager.breakPoints->show);
178 ImGui::MenuItem("Symbol manager", nullptr, &manager.symbols->show);
179 ImGui::MenuItem("Watch expression", nullptr, &manager.watchExpr->show);
180 ImGui::Separator();
181 ImGui::MenuItem("VDP bitmap viewer", nullptr, &manager.bitmap->showBitmapViewer);
182 ImGui::MenuItem("VDP tile viewer", nullptr, &manager.character->show);
183 ImGui::MenuItem("VDP sprite viewer", nullptr, &manager.sprite->show);
184 ImGui::MenuItem("VDP register viewer", nullptr, &manager.vdpRegs->show);
185 ImGui::MenuItem("Palette editor", nullptr, &manager.palette->window.open);
186 ImGui::Separator();
187 im::Menu("Add hex editor", [&]{
188 const auto& debugger = motherBoard->getDebugger();
189 auto debuggables = to_vector<std::pair<std::string, Debuggable*>>(debugger.getDebuggables());
190 ranges::sort(debuggables, StringOp::caseless{}, [](const auto& p) { return p.first; }); // sort on name
191 for (const auto& [name, debuggable] : debuggables) {
192 if (ImGui::Selectable(strCat(name, " ...").c_str())) {
193 createHexEditor(name);
194 }
195 }
196 });
197 });
198}
199
200void ImGuiDebugger::setGotoTarget(uint16_t target)
201{
202 gotoTarget = target;
203 showDisassembly = true;
204 setDisassemblyScrollY.reset(); // don't restore initial scroll position
205}
206
208{
209 if (!motherBoard) return;
210
211 auto& regs = motherBoard->getCPU().getRegisters();
212 auto& cpuInterface = motherBoard->getCPUInterface();
213 auto& debugger = motherBoard->getDebugger();
214 auto time = motherBoard->getCurrentTime();
215 drawControl(cpuInterface, *motherBoard);
216 drawDisassembly(regs, cpuInterface, debugger, *motherBoard, time);
217 drawSlots(cpuInterface, debugger);
218 drawStack(regs, cpuInterface, time);
219 drawRegisters(regs);
220 drawFlags(regs);
221}
222
223void ImGuiDebugger::actionBreakContinue(MSXCPUInterface& cpuInterface)
224{
226 cpuInterface.doContinue();
227 } else {
228 cpuInterface.doBreak();
229 }
230}
231void ImGuiDebugger::actionStepIn(MSXCPUInterface& cpuInterface)
232{
233 cpuInterface.doStep();
234}
235void ImGuiDebugger::actionStepOver()
236{
237 manager.executeDelayed(TclObject("step_over"));
238}
239void ImGuiDebugger::actionStepOut()
240{
241 manager.executeDelayed(TclObject("step_out"));
242}
243void ImGuiDebugger::actionStepBack()
244{
245 manager.executeDelayed(TclObject("step_back"),
246 [&](const TclObject&) { syncDisassemblyWithPC = true; });
247}
248
249void ImGuiDebugger::checkShortcuts(MSXCPUInterface& cpuInterface, MSXMotherBoard& motherBoard)
250{
251 using enum Shortcuts::ID;
252 const auto& shortcuts = manager.getShortcuts();
253
254 if (shortcuts.checkShortcut(DEBUGGER_BREAK_CONTINUE)) {
255 actionBreakContinue(cpuInterface);
256 } else if (shortcuts.checkShortcut(DEBUGGER_STEP_IN)) {
257 actionStepIn(cpuInterface);
258 } else if (shortcuts.checkShortcut(DEBUGGER_STEP_OVER)) {
259 actionStepOver();
260 } else if (shortcuts.checkShortcut(DEBUGGER_STEP_OUT)) {
261 actionStepOut();
262 } else if (shortcuts.checkShortcut(DEBUGGER_STEP_BACK)) {
263 actionStepBack();
264 } else if (shortcuts.checkShortcut(DISASM_TOGGLE_BREAKPOINT)) {
265 actionToggleBp(motherBoard);
266 }
267}
268
269void ImGuiDebugger::drawControl(MSXCPUInterface& cpuInterface, MSXMotherBoard& motherBoard)
270{
271 if (!showControl) return;
272 im::Window("Debugger tool bar", &showControl, [&]{
273 checkShortcuts(cpuInterface, motherBoard);
274
275 gl::vec2 maxIconSize;
276 const auto* font = ImGui::GetFont();
277 for (auto c : {
278 DEBUGGER_ICON_RUN, DEBUGGER_ICON_BREAK,
279 DEBUGGER_ICON_STEP_IN, DEBUGGER_ICON_STEP_OVER,
280 DEBUGGER_ICON_STEP_OUT, DEBUGGER_ICON_STEP_BACK,
281 }) {
282 const auto* g = font->FindGlyph(c);
283 maxIconSize = max(maxIconSize, gl::vec2{g->X1 - g->X0, g->Y1 - g->Y0});
284 }
285
286 auto ButtonGlyph = [&](const char* id, ImWchar glyph, Shortcuts::ID sid) {
287 bool result = ButtonWithCenteredGlyph(glyph, maxIconSize);
288 simpleToolTip([&]() -> std::string {
289 const auto& shortcuts = manager.getShortcuts();
290 const auto& shortcut = shortcuts.getShortcut(sid);
291 if (shortcut.keyChord == ImGuiKey_None) return id;
292 return strCat(id, " (", getKeyChordName(shortcut.keyChord), ')');
293 });
294 return result;
295 };
296
297 bool breaked = MSXCPUInterface::isBreaked();
298 using enum Shortcuts::ID;
299 if (auto breakContinueIcon = breaked ? DEBUGGER_ICON_RUN : DEBUGGER_ICON_BREAK;
300 ButtonGlyph("run", breakContinueIcon, DEBUGGER_BREAK_CONTINUE)) {
301 actionBreakContinue(cpuInterface);
302 }
303 const auto& style = ImGui::GetStyle();
304 ImGui::SameLine(0.0f, 2.0f * style.ItemSpacing.x);
305
306 im::Disabled(!breaked, [&]{
307 if (ButtonGlyph("step-in", DEBUGGER_ICON_STEP_IN, DEBUGGER_STEP_IN)) {
308 actionStepIn(cpuInterface);
309 }
310 ImGui::SameLine();
311
312 if (ButtonGlyph("step-over", DEBUGGER_ICON_STEP_OVER, DEBUGGER_STEP_OVER)) {
313 actionStepOver();
314 }
315 ImGui::SameLine();
316
317 if (ButtonGlyph("step-out", DEBUGGER_ICON_STEP_OUT, DEBUGGER_STEP_OUT)) {
318 actionStepOut();
319 }
320 ImGui::SameLine();
321
322 if (ButtonGlyph("step-back", DEBUGGER_ICON_STEP_BACK, DEBUGGER_STEP_BACK)) {
323 actionStepBack();
324 }
325 });
326 });
327}
328
329[[nodiscard]] static std::pair<const MSXRom*, Debuggable*> getRomBlocks(Debugger& debugger, const MSXDevice* device)
330{
331 Debuggable* debuggable = nullptr;
332 const auto* rom = dynamic_cast<const MSXRom*>(device);
333 if (rom && !dynamic_cast<const RomPlain*>(rom)) {
334 debuggable = debugger.findDebuggable(rom->getName() + " romblocks");
335 }
336 return {rom, debuggable};
337}
338
340 int ps;
341 std::optional<int> ss;
342 std::optional<int> seg;
343};
344[[nodiscard]] static CurrentSlot getCurrentSlot(
345 MSXCPUInterface& cpuInterface, Debugger& debugger,
346 uint16_t addr, bool wantSs = true, bool wantSeg = true)
347{
348 CurrentSlot result;
349 int page = addr / 0x4000;
350 result.ps = cpuInterface.getPrimarySlot(page);
351
352 if (wantSs && cpuInterface.isExpanded(result.ps)) {
353 result.ss = cpuInterface.getSecondarySlot(page);
354 }
355 if (wantSeg) {
356 const auto* device = cpuInterface.getVisibleMSXDevice(page);
357 if (const auto* mapper = dynamic_cast<const MSXMemoryMapperBase*>(device)) {
358 result.seg = mapper->getSelectedSegment(narrow<uint8_t>(page));
359 } else if (auto [_, romBlocks] = getRomBlocks(debugger, device); romBlocks) {
360 result.seg = romBlocks->read(addr);
361 }
362 }
363 return result;
364}
365
366[[nodiscard]] static TclObject toTclExpression(const CurrentSlot& slot)
367{
368 std::string result = strCat("[pc_in_slot ", slot.ps);
369 if (slot.ss) {
370 strAppend(result, ' ', *slot.ss);
371 } else {
372 if (slot.seg) strAppend(result, " X");
373 }
374 if (slot.seg) strAppend(result, ' ', *slot.seg);
375 strAppend(result, ']');
376 return TclObject(result);
377}
378
379[[nodiscard]] static bool addrInSlot(
380 const ParsedSlotCond& slot, MSXCPUInterface& cpuInterface, Debugger& debugger, uint16_t addr)
381{
382 if (!slot.hasPs) return true; // no ps specified -> always ok
383
384 auto current = getCurrentSlot(cpuInterface, debugger, addr, slot.hasSs, slot.hasSeg);
385 if (slot.ps != current.ps) return false;
386 if (slot.hasSs && current.ss && (slot.ss != current.ss)) return false;
387 if (slot.hasSeg && current.seg && (slot.seg != current.seg)) return false;
388 return true;
389}
390
391struct BpLine {
392 int count = 0;
393 int idx = -1; // only valid when count=1
394 bool anyEnabled = false;
395 bool anyDisabled = false;
396 bool anyInSlot = false;
397 bool anyComplex = false;
398};
399static BpLine examineBpLine(uint16_t addr, std::span<const ImGuiBreakPoints::GuiItem> bps, MSXCPUInterface& cpuInterface, Debugger& debugger)
400{
401 BpLine result;
402 for (auto [i, bp] : enumerate(bps)) {
403 if (!bp.addr || *bp.addr != addr) continue;
404 ++result.count;
405 result.idx = int(i);
406
407 bool enabled = (bp.id > 0) && bp.wantEnable;
408 result.anyEnabled |= enabled;
409 result.anyDisabled |= !enabled;
410
411 ParsedSlotCond bpSlot("pc_in_slot", bp.cond.getString());
412 result.anyInSlot |= addrInSlot(bpSlot, cpuInterface, debugger, addr);
413
414 result.anyComplex |= !bpSlot.rest.empty() || (bp.cmd.getString() != "debug break");
415 }
416 return result;
417}
418
419static void toggleBp(uint16_t addr, const BpLine& bpLine, std::vector<ImGuiBreakPoints::GuiItem>& guiBps,
420 MSXCPUInterface& cpuInterface, Debugger& debugger,
421 std::optional<BreakPoint>& addBp, std::optional<unsigned>& removeBpId)
422{
423 if (bpLine.count != 0) {
424 // only allow to remove single breakpoints,
425 // others can be edited via the breakpoint viewer
426 if (bpLine.count == 1) {
427 auto& bp = guiBps[bpLine.idx];
428 if (bp.id > 0) {
429 removeBpId = bp.id; // schedule removal
430 } else {
431 guiBps.erase(guiBps.begin() + bpLine.idx);
432 }
433 }
434 } else {
435 // schedule creation of new bp
436 auto slot = getCurrentSlot(cpuInterface, debugger, addr);
437 addBp.emplace(addr, TclObject("debug break"), toTclExpression(slot), false);
438 }
439}
440void ImGuiDebugger::actionToggleBp(MSXMotherBoard& motherBoard)
441{
442 auto pc = motherBoard.getCPU().getRegisters().getPC();
443 auto& cpuInterface = motherBoard.getCPUInterface();
444 auto& debugger = motherBoard.getDebugger();
445 auto& guiBps = manager.breakPoints->getBps();
446
447 auto bpLine = examineBpLine(pc, guiBps, cpuInterface, debugger);
448
449 std::optional<BreakPoint> addBp;
450 std::optional<unsigned> removeBpId;
451 toggleBp(pc, bpLine, guiBps, cpuInterface, debugger, addBp, removeBpId);
452 if (addBp) {
453 cpuInterface.insertBreakPoint(std::move(*addBp));
454 }
455 if (removeBpId) {
456 cpuInterface.removeBreakPoint(*removeBpId);
457 }
458}
459
460void ImGuiDebugger::drawDisassembly(CPURegs& regs, MSXCPUInterface& cpuInterface, Debugger& debugger,
461 MSXMotherBoard& motherBoard, EmuTime::param time)
462{
463 if (!showDisassembly) return;
464 ImGui::SetNextWindowSize({340, 540}, ImGuiCond_FirstUseEver);
465 im::Window("Disassembly", &showDisassembly, [&]{
466 checkShortcuts(cpuInterface, motherBoard);
467
468 std::optional<BreakPoint> addBp;
469 std::optional<unsigned> removeBpId;
470
471 auto pc = regs.getPC();
472 if (followPC && !MSXCPUInterface::isBreaked()) {
473 gotoTarget = pc;
474 }
475
476 auto widthOpcode = ImGui::CalcTextSize("12 34 56 78"sv).x;
477 int flags = ImGuiTableFlags_RowBg |
478 ImGuiTableFlags_BordersV |
479 ImGuiTableFlags_BordersOuterV |
480 ImGuiTableFlags_Resizable |
481 ImGuiTableFlags_Hideable |
482 ImGuiTableFlags_Reorderable |
483 ImGuiTableFlags_ScrollY |
484 ImGuiTableFlags_ScrollX;
485 im::Table("table", 4, flags, [&]{
486 ImGui::TableSetupScrollFreeze(0, 1); // Make top row always visible
487 ImGui::TableSetupColumn("bp", ImGuiTableColumnFlags_WidthFixed);
488 ImGui::TableSetupColumn("address", ImGuiTableColumnFlags_NoHide);
489 ImGui::TableSetupColumn("opcode", ImGuiTableColumnFlags_WidthFixed, widthOpcode);
490 ImGui::TableSetupColumn("mnemonic", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_NoHide);
491 ImGui::TableHeadersRow();
492
493 auto& guiBps = manager.breakPoints->getBps();
494 auto textSize = ImGui::GetTextLineHeight();
495
496 std::string mnemonic;
497 std::string opcodesStr;
498 std::vector<std::string_view> candidates;
499 std::array<uint8_t, 4> opcodes;
500 ImGuiListClipper clipper; // only draw the actually visible rows
501 clipper.Begin(0x10000);
502 if (gotoTarget) {
503 clipper.IncludeItemsByIndex(*gotoTarget, *gotoTarget + 4);
504 }
505 std::optional<unsigned> nextGotoTarget;
506 while (clipper.Step()) {
507 auto addr16 = instructionBoundary(cpuInterface, narrow<uint16_t>(clipper.DisplayStart), time);
508 for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) {
509 unsigned addr = addr16;
510 ImGui::TableNextRow();
511 if (addr >= 0x10000) continue;
512 im::ID(narrow<int>(addr), [&]{
513 if (gotoTarget && addr >= *gotoTarget) {
514 gotoTarget = {};
515 ImGui::SetScrollHereY(0.25f);
516 }
517
518 if (bool rowAtPc = !syncDisassemblyWithPC && (addr == pc);
519 rowAtPc) {
520 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg1, getColor(imColor::YELLOW_BG));
521 }
522 bool bpRightClick = false;
523 if (ImGui::TableNextColumn()) { // bp
524 auto bpLine = examineBpLine(addr16, guiBps, cpuInterface, debugger);
525 bool hasBp = bpLine.count != 0;
526 bool multi = bpLine.count > 1;
527 if (hasBp) {
528 auto calcColor = [](bool enabled, bool inSlot) {
529 auto [r,g,b] = enabled ? std::tuple{0xE0, 0x00, 0x00}
530 : std::tuple{0x70, 0x70, 0x70};
531 auto a = inSlot ? 0xFF : 0x60;
532 return IM_COL32(r, g, b, a);
533 };
534 auto colIn = calcColor(bpLine.anyEnabled, bpLine.anyInSlot);
535 auto colOut = ImGui::GetColorU32(ImGuiCol_WindowBg);
536
537 auto* drawList = ImGui::GetWindowDrawList();
538 gl::vec2 scrn = ImGui::GetCursorScreenPos();
539 auto center = scrn + textSize * gl::vec2(multi ? 0.3f : 0.5f, 0.5f);
540 auto radiusIn = 0.4f * textSize;
541 auto radiusOut = 0.5f * textSize;
542
543 if (multi) {
544 auto center2 = center + textSize * gl::vec2(0.4f, 0.0f);
545 drawList->AddCircleFilled(center2, radiusOut, colOut);
546 auto colIn2 = calcColor(!bpLine.anyDisabled, bpLine.anyInSlot);
547 drawList->AddCircleFilled(center2, radiusIn, colIn2);
548 }
549 drawList->AddCircleFilled(center, radiusOut, colOut);
550 drawList->AddCircleFilled(center, radiusIn, colIn);
551 if (bpLine.anyComplex) {
552 auto d = 0.3f * textSize;
553 auto c = IM_COL32(0, 0, 0, 192);
554 auto t = 0.2f * textSize;
555 drawList->AddLine(center - gl::vec2(d, 0.0f), center + gl::vec2(d, 0.0f), c, t);
556 drawList->AddLine(center - gl::vec2(0.0f, d), center + gl::vec2(0.0f, d), c, t);
557 }
558 }
559 if (ImGui::InvisibleButton("##bp-button", {-FLT_MIN, textSize})) {
560 toggleBp(addr16, bpLine, guiBps, cpuInterface, debugger, addBp, removeBpId);
561 } else {
562 bpRightClick = hasBp && ImGui::IsItemClicked(ImGuiMouseButton_Right);
563 if (bpRightClick) ImGui::OpenPopup("bp-context");
564 im::Popup("bp-context", [&]{
565 manager.breakPoints->paintBpTab(cpuInterface, debugger, addr16);
566 });
567 }
568 }
569
570 mnemonic.clear();
571 std::optional<uint16_t> mnemonicAddr;
572 std::span<const Symbol* const> mnemonicLabels;
573 auto len = dasm(cpuInterface, addr16, opcodes, mnemonic, time,
574 [&](std::string& output, uint16_t a) {
575 mnemonicAddr = a;
576 mnemonicLabels = symbolManager.lookupValue(a);
577 if (!mnemonicLabels.empty()) {
578 strAppend(output, mnemonicLabels[cycleLabelsCounter % mnemonicLabels.size()]->name);
579 } else {
580 appendAddrAsHex(output, a);
581 }
582 });
583 assert(len >= 1);
584 if ((addr < pc) && (pc < (addr + len))) {
585 // pc is strictly inside current instruction,
586 // replace the just disassembled instruction with "db #..."
587 mnemonicAddr.reset();
588 mnemonicLabels = {};
589 len = pc - addr;
590 assert((1 <= len) && (len <= 3));
591 mnemonic = strCat("db ", join(
593 [&](unsigned i) { return strCat('#', hex_string<2>(opcodes[i])); }),
594 ','));
595 }
596
597 if (ImGui::TableNextColumn()) { // addr
598 bool focusScrollToAddress = false;
599 bool focusRunToAddress = false;
600
601 // do the full-row-selectable stuff in a column that cannot be hidden
602 auto pos = ImGui::GetCursorPos();
603 ImGui::Selectable("##row", false,
604 ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap);
605 using enum Shortcuts::ID;
606 auto& shortcuts = manager.getShortcuts();
607 if (shortcuts.checkShortcut(DISASM_GOTO_ADDR)) {
608 ImGui::OpenPopup("disassembly-context");
609 focusScrollToAddress = true;
610 }
611 if (shortcuts.checkShortcut(DISASM_RUN_TO_ADDR)) {
612 ImGui::OpenPopup("disassembly-context");
613 focusRunToAddress = true;
614 }
615 if (!bpRightClick && ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
616 ImGui::OpenPopup("disassembly-context");
617 }
618
619 auto addrStr = tmpStrCat(hex_string<4>(addr));
620 im::Popup("disassembly-context", [&]{
621 auto addrToolTip = [&](const std::string& str) {
622 simpleToolTip([&]{
623 if (auto a = symbolManager.parseSymbolOrValue(str)) {
624 return strCat("0x", hex_string<4>(*a));
625 }
626 return std::string{};
627 });
628 };
629
630 if (ImGui::MenuItem("Scroll to PC")) {
631 nextGotoTarget = pc;
632 }
633
634 im::Indent([&]{
635 ImGui::Checkbox("Follow PC while running", &followPC);
636 });
637
638 ImGui::AlignTextToFramePadding();
639 ImGui::TextUnformatted("Scroll to address:"sv);
640 ImGui::SameLine();
641 if (focusScrollToAddress) ImGui::SetKeyboardFocusHere();
642 if (ImGui::InputText("##goto", &gotoAddr, ImGuiInputTextFlags_EnterReturnsTrue)) {
643 if (auto a = symbolManager.parseSymbolOrValue(gotoAddr)) {
644 nextGotoTarget = *a;
645 }
646 }
647 addrToolTip(gotoAddr);
648
649 ImGui::Separator();
650
651 auto runTo = strCat("Run to here (address 0x", addrStr, ')');
652 if (ImGui::MenuItem(runTo.c_str())) {
653 manager.executeDelayed(makeTclList("run_to", addr));
654 }
655
656 ImGui::AlignTextToFramePadding();
657 ImGui::TextUnformatted("Run to address:"sv);
658 ImGui::SameLine();
659 if (focusRunToAddress) ImGui::SetKeyboardFocusHere();
660 if (ImGui::InputText("##run", &runToAddr, ImGuiInputTextFlags_EnterReturnsTrue)) {
661 if (auto a = symbolManager.parseSymbolOrValue(runToAddr)) {
662 manager.executeDelayed(makeTclList("run_to", *a));
663 }
664 }
665 addrToolTip(runToAddr);
666
667 ImGui::Separator();
668
669 auto setPc = strCat("Set PC to 0x", addrStr);
670 if (ImGui::MenuItem(setPc.c_str())) {
671 regs.setPC(addr16);
672 }
673 });
674
675 enum class Priority {
676 MISSING_BOTH = 0, // from lowest to highest
677 MISSING_ONE,
678 SLOT_AND_SEGMENT
679 };
680 using enum Priority;
681 Priority currentPriority = MISSING_BOTH;
682 candidates.clear();
683 auto add = [&](const Symbol* sym, Priority newPriority) {
684 if (newPriority < currentPriority) return; // we already have a better candidate
685 if (newPriority > currentPriority) candidates.clear(); // drop previous candidates, we found a better one
686 currentPriority = newPriority;
687 candidates.push_back(sym->name); // cycle symbols in the same priority level
688 };
689
690 auto slot = getCurrentSlot(cpuInterface, debugger, addr16);
691 auto psss = (slot.ss.value_or(0) << 2) + slot.ps;
692 auto addrLabels = symbolManager.lookupValue(addr16);
693 for (const Symbol* symbol: addrLabels) {
694 // skip symbols with any mismatch
695 if (symbol->slot && *symbol->slot != psss) continue;
696 if (symbol->segment && *symbol->segment != slot.seg) continue;
697 // the info that's present does match
698 if (symbol->slot && symbol->segment == slot.seg) {
699 add(symbol, SLOT_AND_SEGMENT);
700 } else if (!symbol->slot && !symbol->segment) {
701 add(symbol, MISSING_BOTH);
702 } else {
703 add(symbol, MISSING_ONE);
704 }
705 }
706 ImGui::SetCursorPos(pos);
708 ImGui::TextUnformatted(candidates.empty() ? addrStr : candidates[cycleLabelsCounter % candidates.size()]);
709 });
710 if (!addrLabels.empty()) {
711 simpleToolTip([&]{
712 std::string tip(addrStr);
713 if (addrLabels.size() > 1) {
714 strAppend(tip, "\nmultiple possibilities (click to cycle):\n",
715 join(view::transform(addrLabels, &Symbol::name), ' '));
716 }
717 return tip;
718 });
719 ImGui::SetCursorPos(pos);
720 if (ImGui::InvisibleButton("##addrButton", {-FLT_MIN, textSize})) {
721 ++cycleLabelsCounter;
722 }
723 }
724 }
725
726 if (ImGui::TableNextColumn()) { // opcode
727 opcodesStr.clear();
728 for (auto i : xrange(len)) {
729 strAppend(opcodesStr, hex_string<2>(opcodes[i]), ' ');
730 }
732 ImGui::TextUnformatted(opcodesStr.data(), opcodesStr.data() + 3 * len - 1);
733 });
734 }
735
736 if (ImGui::TableNextColumn()) { // mnemonic
737 auto pos = ImGui::GetCursorPos();
739 ImGui::TextUnformatted(mnemonic);
740 });
741 if (mnemonicAddr) {
742 ImGui::SetCursorPos(pos);
743 if (ImGui::InvisibleButton("##mnemonicButton", {-FLT_MIN, textSize})) {
744 if (!mnemonicLabels.empty()) {
745 ++cycleLabelsCounter;
746 }
747 }
748 if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
749 nextGotoTarget = *mnemonicAddr;
750 }
751 if (!mnemonicLabels.empty()) {
752 simpleToolTip([&]{
753 auto tip = strCat('#', hex_string<4>(*mnemonicAddr));
754 if (mnemonicLabels.size() > 1) {
755 strAppend(tip, "\nmultiple possibilities (click to cycle):\n",
756 join(view::transform(mnemonicLabels, &Symbol::name), ' '));
757 }
758 return tip;
759 });
760 }
761 }
762 }
763 addr16 += len;
764 });
765 }
766 }
767 gotoTarget = nextGotoTarget;
768 if (syncDisassemblyWithPC) {
769 syncDisassemblyWithPC = false; // only once
770
771 auto itemHeight = ImGui::GetTextLineHeightWithSpacing();
772 auto winHeight = ImGui::GetWindowHeight();
773 auto lines = std::max(1, int(winHeight / itemHeight) - 1); // approx
774
775 auto topAddr = nInstructionsBefore(cpuInterface, pc, time, narrow<int>(lines / 4) + 1);
776
777 ImGui::SetScrollY(topAddr * itemHeight);
778 } else if (setDisassemblyScrollY) {
779 ImGui::SetScrollY(*setDisassemblyScrollY);
780 setDisassemblyScrollY.reset();
781 }
782 disassemblyScrollY = ImGui::GetScrollY();
783 });
784 // only add/remove bp's after drawing (can't change list of bp's while iterating over it)
785 if (addBp) {
786 cpuInterface.insertBreakPoint(std::move(*addBp));
787 }
788 if (removeBpId) {
789 cpuInterface.removeBreakPoint(*removeBpId);
790 }
791 });
792}
793
794void ImGuiDebugger::drawSlots(MSXCPUInterface& cpuInterface, Debugger& debugger)
795{
796 if (!showSlots) return;
797 im::Window("Slots", &showSlots, [&]{
798 int flags = ImGuiTableFlags_BordersInnerV |
799 ImGuiTableFlags_Resizable |
800 ImGuiTableFlags_Reorderable |
801 ImGuiTableFlags_Hideable |
802 ImGuiTableFlags_ContextMenuInBody;
803 im::Table("table", 4, flags, [&]{
804 ImGui::TableSetupColumn("Page");
805 ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_DefaultHide);
806 ImGui::TableSetupColumn("Slot");
807 ImGui::TableSetupColumn("Segment");
808 ImGui::TableHeadersRow();
809
810 for (auto page : xrange(uint8_t(4))) {
811 auto addr = 0x4000 * page;
812 if (ImGui::TableNextColumn()) { // page
813 ImGui::StrCat(page);
814 }
815 if (ImGui::TableNextColumn()) { // address
816 ImGui::StrCat("0x", hex_string<4>(addr));
817 }
818 if (ImGui::TableNextColumn()) { // slot
819 int ps = cpuInterface.getPrimarySlot(page);
820 if (cpuInterface.isExpanded(ps)) {
821 int ss = cpuInterface.getSecondarySlot(page);
822 ImGui::StrCat(ps, '-', ss);
823 } else {
824 ImGui::StrCat(' ', ps);
825 }
826 }
827 if (ImGui::TableNextColumn()) { // segment
828 const auto* device = cpuInterface.getVisibleMSXDevice(page);
829 if (const auto* mapper = dynamic_cast<const MSXMemoryMapperBase*>(device)) {
830 ImGui::StrCat(mapper->getSelectedSegment(page));
831 } else if (auto [rom, romBlocks] = getRomBlocks(debugger, device); romBlocks) {
832 if (unsigned blockSize = RomInfo::getBlockSize(rom->getRomType())) {
833 std::string text;
834 char separator = 'R';
835 for (int offset = 0; offset < 0x4000; offset += blockSize) {
836 strAppend(text, separator, romBlocks->read(addr + offset));
837 separator = '/';
838 }
840 } else {
842 }
843 } else {
845 }
846 }
847 }
848 });
849 });
850}
851
852void ImGuiDebugger::drawStack(const CPURegs& regs, const MSXCPUInterface& cpuInterface, EmuTime::param time)
853{
854 if (!showStack) return;
855
856 auto line = ImGui::GetTextLineHeightWithSpacing();
857 ImGui::SetNextWindowSize(ImVec2(0.0f, 12 * line), ImGuiCond_FirstUseEver);
858 im::Window("stack", &showStack, [&]{
859 auto sp = regs.getSP();
860
861 int flags = ImGuiTableFlags_ScrollY |
862 ImGuiTableFlags_BordersInnerV |
863 ImGuiTableFlags_Resizable |
864 ImGuiTableFlags_Reorderable |
865 ImGuiTableFlags_Hideable |
866 ImGuiTableFlags_ContextMenuInBody;
867 im::Table("table", 3, flags, [&]{
868 ImGui::TableSetupScrollFreeze(0, 1); // Make top row always visible
869 ImGui::TableSetupColumn("Address");
870 ImGui::TableSetupColumn("Offset", ImGuiTableColumnFlags_DefaultHide);
871 ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoHide);
872 ImGui::TableHeadersRow();
873
875 im::ListClipper(std::min(128, (0x10000 - sp) / 2), [&](int row) {
876 auto offset = 2 * row;
877 auto addr = sp + offset;
878 if (ImGui::TableNextColumn()) { // address
879 ImGui::StrCat(hex_string<4>(addr));
880 }
881 if (ImGui::TableNextColumn()) { // offset
882 ImGui::Text("SP+%X", offset);
883 }
884 if (ImGui::TableNextColumn()) { // value
885 auto l = cpuInterface.peekMem(narrow_cast<uint16_t>(addr + 0), time);
886 auto h = cpuInterface.peekMem(narrow_cast<uint16_t>(addr + 1), time);
887 auto value = narrow<uint16_t>(256 * h + l);
888 ImGui::StrCat(hex_string<4>(value));
889 }
890 });
891 });
892 });
893}
894
895void ImGuiDebugger::drawRegisters(CPURegs& regs)
896{
897 if (!showRegisters) return;
898 im::Window("CPU registers", &showRegisters, [&]{
900
901 const auto& style = ImGui::GetStyle();
902 auto padding = 2 * style.FramePadding.x;
903 auto width16 = ImGui::CalcTextSize("FFFF"sv).x + padding;
904 auto edit16 = [&](std::string_view label, std::string_view high, std::string_view low, auto getter, auto setter) {
905 uint16_t value = getter();
906 im::Group([&]{
907 ImGui::AlignTextToFramePadding();
909 ImGui::SameLine();
910 ImGui::SetNextItemWidth(width16);
911 if (ImGui::InputScalar(tmpStrCat("##", label).c_str(), ImGuiDataType_U16, &value, nullptr, nullptr, "%04X")) {
912 setter(value);
913 }
914 });
915 simpleToolTip([&]{
916 return strCat(
917 "Bin: ", bin_string<4>(value >> 12), ' ', bin_string<4>(value >> 8), ' ',
918 bin_string<4>(value >> 4), ' ', bin_string<4>(value >> 0), "\n"
919 "Dec: ", dec_string<5>(value), '\n',
920 high, ": ", dec_string<3>(value >> 8), " ", low, ": ", dec_string<3>(value & 0xff));
921 });
922 };
923 auto edit8 = [&](std::string_view label, auto getter, auto setter) {
924 uint8_t value = getter();
925 im::Group([&]{
926 ImGui::AlignTextToFramePadding();
928 ImGui::SameLine();
929 ImGui::SetNextItemWidth(width16);
930 if (ImGui::InputScalar(tmpStrCat("##", label).c_str(), ImGuiDataType_U8, &value, nullptr, nullptr, "%02X")) {
931 setter(value);
932 }
933 });
934 simpleToolTip([&]{
935 return strCat(
936 "Bin: ", bin_string<4>(value >> 4), ' ', bin_string<4>(value >> 0), "\n"
937 "Dec: ", dec_string<3>(value), '\n');
938 });
939 };
940
941 edit16("AF", "A", "F", [&]{ return regs.getAF(); }, [&](uint16_t value) { regs.setAF(value); });
942 ImGui::SameLine(0.0f, 20.0f);
943 edit16("AF'", "A'", "F'", [&]{ return regs.getAF2(); }, [&](uint16_t value) { regs.setAF2(value); });
944
945 edit16("BC", "B", "C", [&]{ return regs.getBC(); }, [&](uint16_t value) { regs.setBC(value); });
946 ImGui::SameLine(0.0f, 20.0f);
947 edit16("BC'", "B'", "C'", [&]{ return regs.getBC2(); }, [&](uint16_t value) { regs.setBC2(value); });
948
949 edit16("DE", "D", "E", [&]{ return regs.getDE(); }, [&](uint16_t value) { regs.setDE(value); });
950 ImGui::SameLine(0.0f, 20.0f);
951 edit16("DE'", "D'", "E'", [&]{ return regs.getDE2(); }, [&](uint16_t value) { regs.setDE2(value); });
952
953 edit16("HL", "H", "L", [&]{ return regs.getHL(); }, [&](uint16_t value) { regs.setHL(value); });
954 ImGui::SameLine(0.0f, 20.0f);
955 edit16("HL'", "H'", "L'", [&]{ return regs.getHL2(); }, [&](uint16_t value) { regs.setHL2(value); });
956
957 edit16("IX", "IXh", "IXl", [&]{ return regs.getIX(); }, [&](uint16_t value) { regs.setIX(value); });
958 ImGui::SameLine(0.0f, 20.0f);
959 edit16("IY ", "IYh", "IYl", [&]{ return regs.getIY(); }, [&](uint16_t value) { regs.setIY(value); });
960
961 edit16("PC", "PCh", "PCl", [&]{ return regs.getPC(); }, [&](uint16_t value) { regs.setPC(value); });
962 ImGui::SameLine(0.0f, 20.0f);
963 edit16("SP ", "SPh", "SPl", [&]{ return regs.getSP(); }, [&](uint16_t value) { regs.setSP(value); });
964
965 edit8("I ", [&]{ return regs.getI(); }, [&](uint8_t value) { regs.setI(value); });
966 ImGui::SameLine(0.0f, 20.0f);
967 edit8("R ", [&]{ return regs.getR(); }, [&](uint8_t value) { regs.setR(value); });
968
969 ImGui::AlignTextToFramePadding();
971 ImGui::SameLine();
972 ImGui::SetNextItemWidth(width16);
973 if (uint8_t im = regs.getIM();
974 ImGui::InputScalar("##IM", ImGuiDataType_U8, &im, nullptr, nullptr, "%d")) {
975 if (im <= 2) regs.setIM(im);
976 }
977
978 ImGui::SameLine(0.0f, 20.0f);
979 ImGui::AlignTextToFramePadding();
980 if (bool ei = regs.getIFF1();
981 ImGui::Selectable(ei ? "EI" : "DI", false, ImGuiSelectableFlags_AllowDoubleClick)) {
982 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
983 regs.setIFF1(!ei);
984 regs.setIFF2(!ei);
985 }
986 }
987 simpleToolTip("double-click to toggle");
988 });
989}
990
991void ImGuiDebugger::drawFlags(CPURegs& regs)
992{
993 if (!showFlags) return;
994 im::Window("CPU flags", &showFlags, [&]{
995 auto [sizeH1_, sizeH2_, sizeV_] = [&]{
997 return std::tuple{
998 ImGui::CalcTextSize("NC"sv),
999 ImGui::CalcTextSize("X:0"sv),
1000 ImGui::CalcTextSize("C 0 (NC)"sv)
1001 };
1002 }();
1003 // clang workaround
1004 auto sizeH1 = sizeH1_; auto sizeH2 = sizeH2_; auto sizeV = sizeV_;
1005
1006 auto f = regs.getF();
1007
1008 auto draw = [&](const char* name, uint8_t bit, const char* val0 = nullptr, const char* val1 = nullptr) {
1009 std::string s;
1010 ImVec2 sz;
1011 if (flagsLayout == 0) {
1012 // horizontal
1013 if (val0) {
1014 s = (f & bit) ? val1 : val0;
1015 sz = sizeH1;
1016 } else {
1017 s = strCat(name, ':', (f & bit) ? '1' : '0');
1018 sz = sizeH2;
1019 }
1020 } else {
1021 // vertical
1022 s = strCat(name, ' ', (f & bit) ? '1' : '0');
1023 if (val0) {
1024 strAppend(s, " (", (f & bit) ? val1 : val0, ')');
1025 }
1026 sz = sizeV;
1027 }
1029 if (ImGui::Selectable(s.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick, sz)) {
1030 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
1031 regs.setF(f ^ bit);
1032 }
1033 }
1034 });
1035 simpleToolTip("double-click to toggle, right-click to configure");
1036 if (flagsLayout == 0) {
1037 // horizontal
1038 ImGui::SameLine(0.0f, sizeH1.x);
1039 }
1040 };
1041
1042 draw("S", 0x80, " P", " M");
1043 draw("Z", 0x40, "NZ", " Z");
1044 if (showXYFlags) draw("Y", 0x20);
1045 draw("H", 0x10);
1046 if (showXYFlags) draw("X", 0x08);
1047 draw("P", 0x04, "PO", "PE");
1048 draw("N", 0x02);
1049 draw("C", 0x01, "NC", " C");
1050
1052 ImGui::TextUnformatted("Layout"sv);
1053 ImGui::RadioButton("horizontal", &flagsLayout, 0);
1054 ImGui::RadioButton("vertical", &flagsLayout, 1);
1055 ImGui::Separator();
1056 ImGui::Checkbox("show undocumented", &showXYFlags);
1057 });
1058 });
1059}
1060
1061} // namespace openmsx
uintptr_t id
int g
TclObject t
std::string_view getDebuggableName() const
void loadEnd() override
void loadStart() override
void showMenu(MSXMotherBoard *motherBoard) override
ImGuiDebugger(ImGuiManager &manager)
void loadLine(std::string_view name, zstring_view value) override
void setGotoTarget(uint16_t target)
void paint(MSXMotherBoard *motherBoard) override
void save(ImGuiTextBuffer &buf) override
std::unique_ptr< ImGuiBreakPoints > breakPoints
std::unique_ptr< ImGuiVdpRegs > vdpRegs
std::unique_ptr< ImGuiWatchExpr > watchExpr
std::unique_ptr< ImGuiPalette > palette
std::unique_ptr< ImGuiSpriteViewer > sprite
Shortcuts & getShortcuts()
std::unique_ptr< ImGuiBitmapViewer > bitmap
std::unique_ptr< ImGuiCharacter > character
void executeDelayed(std::function< void()> action)
std::unique_ptr< ImGuiSymbols > symbols
ImGuiManager & manager
Definition ImGuiPart.hh:30
auto getPrimarySlot(int page) const
MSXDevice * getVisibleMSXDevice(int page)
bool isExpanded(int ps) const
auto getSecondarySlot(int page) const
CPURegs & getRegisters()
Definition MSXCPU.cc:343
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
MSXCPUInterface & getCPUInterface()
static unsigned getBlockSize(RomType type)
Definition RomInfo.cc:201
const Shortcut & getShortcut(ID id) const
Definition Shortcuts.cc:91
std::span< Symbol const *const > lookupValue(uint16_t value)
std::optional< uint16_t > parseSymbolOrValue(std::string_view s) const
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr auto enumerate(Iterable &&iterable)
Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta....
Definition enumerate.hh:28
detail::Joiner< Collection, Separator > join(Collection &&col, Separator &&sep)
Definition join.hh:60
void StrCat(Ts &&...ts)
Definition ImGuiUtils.hh:44
auto CalcTextSize(std::string_view str)
Definition ImGuiUtils.hh:38
void TextUnformatted(const std::string &str)
Definition ImGuiUtils.hh:25
vecN< 2, float > vec2
Definition gl_vec.hh:382
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition gl_vec.hh:449
Definition ImGuiCpp.hh:60
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)
Definition ImGuiCpp.hh:455
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:63
void ID(const char *str_id, std::invocable<> auto next)
Definition ImGuiCpp.hh:244
void PopupContextWindow(const char *str_id, ImGuiPopupFlags popup_flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:438
bool Menu(const char *label, bool enabled, std::invocable<> auto next)
Definition ImGuiCpp.hh:359
void Disabled(bool b, std::invocable<> auto next)
Definition ImGuiCpp.hh:506
void Group(std::invocable<> auto next)
Definition ImGuiCpp.hh:236
void Font(ImFont *font, std::invocable<> auto next)
Definition ImGuiCpp.hh:131
void Indent(float indent_w, std::invocable<> auto next)
Definition ImGuiCpp.hh:224
void ListClipper(size_t count, int forceIndex, float lineHeight, std::invocable< int > auto next)
Definition ImGuiCpp.hh:538
void Popup(const char *str_id, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:391
This file implemented 3 utility functions:
Definition Autofire.cc:11
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void simpleToolTip(std::string_view desc)
Definition ImGuiUtils.hh:78
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
ImU32 getColor(imColor col)
std::string getKeyChordName(ImGuiKeyChord keyChord)
uint16_t instructionBoundary(const MSXCPUInterface &interface, uint16_t addr, EmuTime::param time)
This is only an heuristic to display instructions in a debugger disassembly view.
Definition Dasm.cc:196
uint16_t nInstructionsBefore(const MSXCPUInterface &interface, uint16_t addr, EmuTime::param time, int n)
Get the start address of the 'n'th instruction before the instruction containing the byte at the give...
Definition Dasm.cc:203
bool ButtonWithCenteredGlyph(ImWchar glyph, gl::vec2 maxGlyphSize)
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293
unsigned dasm(std::span< const uint8_t > opcode, uint16_t pc, std::string &dest, function_ref< void(std::string &, uint16_t)> appendAddr)
Disassemble.
Definition Dasm.cc:38
auto equal_range(ForwardRange &&range, const T &value, Compare comp={})
Definition ranges.hh:135
constexpr void sort(RandomAccessRange &&range)
Definition ranges.hh:51
auto lower_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
Definition ranges.hh:117
constexpr auto transform(Range &&range, UnaryOp op)
Definition view.hh:520
std::string strCat()
Definition strCat.hh:703
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742
void strAppend(std::string &result, Ts &&...ts)
Definition strCat.hh:752
std::optional< int > seg
std::optional< int > ss
std::string name
constexpr auto xrange(T e)
Definition xrange.hh:132