36#include <imgui_stdlib.h>
41using namespace std::literals;
47 , symbolManager(manager.getReactor().getSymbolManager())
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]GFlQ#;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#";
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;
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());
91 syncDisassemblyWithPC =
true;
99 auto it = hexEditors.begin();
100 auto et = hexEditors.end();
103 auto name = std::string((*it)->getDebuggableName());
107 }
while (it != et && (*it)->getDebuggableName() == name);
108 buf.appendf(
"hexEditor.%s=%d\n", name.c_str(), count);
120 static constexpr std::string_view prefix =
"hexEditor.";
124 }
else if (name.starts_with(prefix)) {
125 if (
auto r = StringOp::stringTo<unsigned>(value)) {
126 auto debuggableName = std::string(name.substr(prefix.size()));
128 auto index = std::distance(b, e);
129 for (
auto i :
xrange(*r)) {
130 e = hexEditors.insert(e, std::make_unique<DebuggableEditor>(
manager, debuggableName, index + i));
139 setDisassemblyScrollY = disassemblyScrollY;
144 auto createHexEditor = [&](
const std::string& name) {
147 for (
auto it = b; it != e; ++it) {
154 auto index = std::distance(b, e);
155 auto it = hexEditors.insert(e, std::make_unique<DebuggableEditor>(
manager, name, index));
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);
167 bool memoryOpen = (it != hexEditors.end()) && (*it)->open;
168 if (ImGui::MenuItem(
"Memory",
nullptr, &memoryOpen)) {
170 createHexEditor(
"memory");
172 assert(it != hexEditors.end());
178 ImGui::MenuItem(
"Symbol manager",
nullptr, &
manager.
symbols->show);
181 ImGui::MenuItem(
"VDP bitmap viewer",
nullptr, &
manager.
bitmap->showBitmapViewer);
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);
189 auto debuggables = to_vector<std::pair<std::string, Debuggable*>>(debugger.getDebuggables());
191 for (
const auto& [name, debuggable] : debuggables) {
192 if (ImGui::Selectable(
strCat(name,
" ...").c_str())) {
193 createHexEditor(name);
203 showDisassembly =
true;
204 setDisassemblyScrollY.reset();
209 if (!motherBoard)
return;
215 drawControl(cpuInterface);
216 drawDisassembly(regs, cpuInterface, debugger, time);
217 drawSlots(cpuInterface, debugger);
218 drawStack(regs, cpuInterface, time);
231void ImGuiDebugger::actionStepIn(MSXCPUInterface& cpuInterface)
233 cpuInterface.doStep();
235void ImGuiDebugger::actionStepOver()
239void ImGuiDebugger::actionStepOut()
243void ImGuiDebugger::actionStepBack()
246 [&](
const TclObject&) { syncDisassemblyWithPC =
true; });
249void ImGuiDebugger::checkShortcuts(MSXCPUInterface& cpuInterface)
254 if (shortcuts.checkShortcut(DEBUGGER_BREAK_CONTINUE)) {
255 actionBreakContinue(cpuInterface);
257 if (shortcuts.checkShortcut(DEBUGGER_STEP_IN)) {
258 actionStepIn(cpuInterface);
260 if (shortcuts.checkShortcut(DEBUGGER_STEP_OVER)) {
263 if (shortcuts.checkShortcut(DEBUGGER_STEP_OUT)) {
266 if (shortcuts.checkShortcut(DEBUGGER_STEP_BACK)) {
271void ImGuiDebugger::drawControl(MSXCPUInterface& cpuInterface)
273 if (!showControl)
return;
274 im::Window(
"Debugger tool bar", &showControl, [&]{
275 checkShortcuts(cpuInterface);
278 const auto* font = ImGui::GetFont();
279 auto texId = font->ContainerAtlas->TexID;
280 const auto*
g = font->FindGlyph(c);
281 bool result = ImGui::ImageButton(
id, texId, {
g->X1 -
g->X0,
g->Y1 -
g->Y0}, {
g->U0,
g->V0}, {
g->U1,
g->V1});
285 if (shortcut.keyChord == ImGuiKey_None)
return id;
293 if (
auto breakContinueIcon = breaked ? DEBUGGER_ICON_RUN : DEBUGGER_ICON_BREAK;
294 ButtonGlyph(
"run", breakContinueIcon, DEBUGGER_BREAK_CONTINUE)) {
295 actionBreakContinue(cpuInterface);
298 ImGui::SetCursorPosX(50.0f);
301 if (ButtonGlyph(
"step-in", DEBUGGER_ICON_STEP_IN, DEBUGGER_STEP_IN)) {
302 actionStepIn(cpuInterface);
306 if (ButtonGlyph(
"step-over", DEBUGGER_ICON_STEP_OVER, DEBUGGER_STEP_OVER)) {
311 if (ButtonGlyph(
"step-out", DEBUGGER_ICON_STEP_OUT, DEBUGGER_STEP_OUT)) {
316 if (ButtonGlyph(
"step-back", DEBUGGER_ICON_STEP_BACK, DEBUGGER_STEP_BACK)) {
323[[nodiscard]]
static std::pair<const MSXRom*, Debuggable*> getRomBlocks(Debugger& debugger,
const MSXDevice* device)
325 Debuggable* debuggable =
nullptr;
326 const auto* rom =
dynamic_cast<const MSXRom*
>(device);
327 if (rom && !
dynamic_cast<const RomPlain*
>(rom)) {
328 debuggable = debugger.findDebuggable(rom->getName() +
" romblocks");
330 return {rom, debuggable};
335 std::optional<int>
ss;
340 uint16_t addr,
bool wantSs =
true,
bool wantSeg =
true)
343 int page = addr / 0x4000;
351 if (
const auto* mapper =
dynamic_cast<const MSXMemoryMapperBase*
>(device)) {
352 result.
seg = mapper->getSelectedSegment(narrow<uint8_t>(page));
353 }
else if (
auto [_, romBlocks] = getRomBlocks(debugger, device); romBlocks) {
354 result.
seg = romBlocks->read(addr);
360[[nodiscard]]
static TclObject toTclExpression(
const CurrentSlot& slot)
362 std::string result =
strCat(
"[pc_in_slot ", slot.ps);
368 if (slot.seg)
strAppend(result,
' ', *slot.seg);
370 return TclObject(result);
373[[nodiscard]]
static bool addrInSlot(
374 const ParsedSlotCond& slot, MSXCPUInterface& cpuInterface, Debugger& debugger, uint16_t addr)
376 if (!slot.hasPs)
return true;
378 auto current = getCurrentSlot(cpuInterface, debugger, addr, slot.hasSs, slot.hasSeg);
379 if (slot.ps != current.ps)
return false;
380 if (slot.hasSs && current.ss && (slot.ss != current.ss))
return false;
381 if (slot.hasSeg && current.seg && (slot.seg != current.seg))
return false;
397 if (!bp.addr || *bp.addr != addr)
continue;
401 bool enabled = (bp.id > 0) && bp.wantEnable;
406 result.
anyInSlot |= addrInSlot(bpSlot, cpuInterface, debugger, addr);
408 result.
anyComplex |= !bpSlot.
rest.empty() || (bp.cmd.getString() !=
"debug break");
413void ImGuiDebugger::drawDisassembly(CPURegs& regs, MSXCPUInterface& cpuInterface, Debugger& debugger, EmuTime::param time)
415 if (!showDisassembly)
return;
416 ImGui::SetNextWindowSize({340, 540}, ImGuiCond_FirstUseEver);
417 im::Window(
"Disassembly", &showDisassembly, [&]{
418 checkShortcuts(cpuInterface);
420 std::optional<BreakPoint> addBp;
421 std::optional<unsigned> removeBpId;
423 auto pc = regs.getPC();
429 int flags = ImGuiTableFlags_RowBg |
430 ImGuiTableFlags_BordersV |
431 ImGuiTableFlags_BordersOuterV |
432 ImGuiTableFlags_Resizable |
433 ImGuiTableFlags_Hideable |
434 ImGuiTableFlags_Reorderable |
435 ImGuiTableFlags_ScrollY |
436 ImGuiTableFlags_ScrollX;
438 ImGui::TableSetupScrollFreeze(0, 1);
439 ImGui::TableSetupColumn(
"bp", ImGuiTableColumnFlags_WidthFixed);
440 ImGui::TableSetupColumn(
"address", ImGuiTableColumnFlags_NoHide);
441 ImGui::TableSetupColumn(
"opcode", ImGuiTableColumnFlags_WidthFixed, widthOpcode);
442 ImGui::TableSetupColumn(
"mnemonic", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_NoHide);
443 ImGui::TableHeadersRow();
446 auto textSize = ImGui::GetTextLineHeight();
448 std::string mnemonic;
449 std::string opcodesStr;
450 std::vector<std::string_view> candidates;
451 std::array<uint8_t, 4> opcodes;
452 ImGuiListClipper clipper;
453 clipper.Begin(0x10000);
455 clipper.IncludeItemsByIndex(*gotoTarget, *gotoTarget + 4);
457 std::optional<unsigned> nextGotoTarget;
458 while (clipper.Step()) {
459 auto addr16 =
instructionBoundary(cpuInterface, narrow<uint16_t>(clipper.DisplayStart), time);
460 for (
int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) {
461 unsigned addr = addr16;
462 ImGui::TableNextRow();
463 if (addr >= 0x10000)
continue;
464 im::ID(narrow<int>(addr), [&]{
465 if (gotoTarget && addr >= *gotoTarget) {
467 ImGui::SetScrollHereY(0.25f);
470 if (
bool rowAtPc = !syncDisassemblyWithPC && (addr == pc);
474 bool bpRightClick =
false;
475 if (ImGui::TableNextColumn()) {
476 auto bpLine = examineBpLine(addr16, guiBps, cpuInterface, debugger);
477 bool hasBp = bpLine.count != 0;
478 bool multi = bpLine.count > 1;
480 auto calcColor = [](
bool enabled,
bool inSlot) {
481 auto [r,
g,b] = enabled ? std::tuple{0xE0, 0x00, 0x00}
482 : std::tuple{0x70, 0x70, 0x70};
483 auto a = inSlot ? 0xFF : 0x60;
484 return IM_COL32(r,
g, b, a);
486 auto colIn = calcColor(bpLine.anyEnabled, bpLine.anyInSlot);
487 auto colOut = ImGui::GetColorU32(ImGuiCol_WindowBg);
489 auto* drawList = ImGui::GetWindowDrawList();
490 gl::vec2 scrn = ImGui::GetCursorScreenPos();
491 auto center = scrn + textSize *
gl::vec2(multi ? 0.3f : 0.5f, 0.5f);
492 auto radiusIn = 0.4f * textSize;
493 auto radiusOut = 0.5f * textSize;
496 auto center2 = center + textSize *
gl::vec2(0.4f, 0.0f);
497 drawList->AddCircleFilled(center2, radiusOut, colOut);
498 auto colIn2 = calcColor(!bpLine.anyDisabled, bpLine.anyInSlot);
499 drawList->AddCircleFilled(center2, radiusIn, colIn2);
501 drawList->AddCircleFilled(center, radiusOut, colOut);
502 drawList->AddCircleFilled(center, radiusIn, colIn);
503 if (bpLine.anyComplex) {
504 auto d = 0.3f * textSize;
505 auto c = IM_COL32(0, 0, 0, 192);
506 auto t = 0.2f * textSize;
511 if (ImGui::InvisibleButton(
"##bp-button", {-FLT_MIN, textSize})) {
516 auto& bp = guiBps[bpLine.idx];
520 guiBps.erase(guiBps.begin() + bpLine.idx);
525 auto slot = getCurrentSlot(cpuInterface, debugger, addr16);
526 addBp.emplace(addr, TclObject(
"debug break"), toTclExpression(slot),
false);
529 bpRightClick = hasBp && ImGui::IsItemClicked(ImGuiMouseButton_Right);
530 if (bpRightClick) ImGui::OpenPopup(
"bp-context");
538 std::optional<uint16_t> mnemonicAddr;
539 std::span<const Symbol* const> mnemonicLabels;
540 auto len =
dasm(cpuInterface, addr16, opcodes, mnemonic, time,
541 [&](std::string& output, uint16_t a) {
544 if (!mnemonicLabels.empty()) {
545 strAppend(output, mnemonicLabels[cycleLabelsCounter % mnemonicLabels.size()]->name);
547 appendAddrAsHex(output, a);
551 if ((addr < pc) && (pc < (addr + len))) {
554 mnemonicAddr.reset();
557 assert((1 <= len) && (len <= 3));
560 [&](
unsigned i) {
return strCat(
'#', hex_string<2>(opcodes[i])); }),
564 if (ImGui::TableNextColumn()) {
565 bool focusScrollToAddress =
false;
566 bool focusRunToAddress =
false;
569 auto pos = ImGui::GetCursorPos();
570 ImGui::Selectable(
"##row",
false,
571 ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap);
573 ImGui::OpenPopup(
"disassembly-context");
574 focusScrollToAddress =
true;
577 ImGui::OpenPopup(
"disassembly-context");
578 focusRunToAddress =
true;
580 if (!bpRightClick && ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
581 ImGui::OpenPopup(
"disassembly-context");
584 auto addrStr =
tmpStrCat(hex_string<4>(addr));
586 auto addrToolTip = [&](
const std::string& str) {
589 return strCat(
"0x", hex_string<4>(*a));
591 return std::string{};
595 if (ImGui::MenuItem(
"Scroll to PC")) {
600 ImGui::Checkbox(
"Follow PC while running", &followPC);
603 ImGui::AlignTextToFramePadding();
606 if (focusScrollToAddress) ImGui::SetKeyboardFocusHere();
607 if (ImGui::InputText(
"##goto", &gotoAddr, ImGuiInputTextFlags_EnterReturnsTrue)) {
612 addrToolTip(gotoAddr);
616 auto runTo =
strCat(
"Run to here (address 0x", addrStr,
')');
617 if (ImGui::MenuItem(runTo.c_str())) {
621 ImGui::AlignTextToFramePadding();
624 if (focusRunToAddress) ImGui::SetKeyboardFocusHere();
625 if (ImGui::InputText(
"##run", &runToAddr, ImGuiInputTextFlags_EnterReturnsTrue)) {
630 addrToolTip(runToAddr);
634 auto setPc =
strCat(
"Set PC to 0x", addrStr);
635 if (ImGui::MenuItem(setPc.c_str())) {
645 Priority currentPriority = Priority::MISSING_BOTH;
647 auto add = [&](
const Symbol* sym, Priority newPriority) {
648 if (newPriority < currentPriority)
return;
649 if (newPriority > currentPriority) candidates.clear();
650 currentPriority = newPriority;
651 candidates.push_back(sym->name);
654 auto slot = getCurrentSlot(cpuInterface, debugger, addr16);
655 auto psss = (slot.ss.value_or(0) << 2) + slot.ps;
656 auto addrLabels = symbolManager.
lookupValue(addr16);
657 for (
const Symbol* symbol: addrLabels) {
659 if (symbol->slot && *symbol->slot != psss)
continue;
660 if (symbol->segment && *symbol->segment != slot.seg)
continue;
662 if (symbol->slot && symbol->segment == slot.seg) {
663 add(symbol, Priority::SLOT_AND_SEGMENT);
664 }
else if (!symbol->slot && !symbol->segment) {
665 add(symbol, Priority::MISSING_BOTH);
667 add(symbol, Priority::MISSING_ONE);
670 ImGui::SetCursorPos(pos);
672 ImGui::TextUnformatted(candidates.empty() ? addrStr : candidates[cycleLabelsCounter % candidates.size()]);
674 if (!addrLabels.empty()) {
676 std::string tip(addrStr);
677 if (addrLabels.size() > 1) {
678 strAppend(tip,
"\nmultiple possibilities (click to cycle):\n",
683 ImGui::SetCursorPos(pos);
684 if (ImGui::InvisibleButton(
"##addrButton", {-FLT_MIN, textSize})) {
685 ++cycleLabelsCounter;
690 if (ImGui::TableNextColumn()) {
692 for (
auto i :
xrange(len)) {
693 strAppend(opcodesStr, hex_string<2>(opcodes[i]),
' ');
696 ImGui::TextUnformatted(opcodesStr.data(), opcodesStr.data() + 3 * len - 1);
700 if (ImGui::TableNextColumn()) {
701 auto pos = ImGui::GetCursorPos();
703 ImGui::TextUnformatted(mnemonic);
706 ImGui::SetCursorPos(pos);
707 if (ImGui::InvisibleButton(
"##mnemonicButton", {-FLT_MIN, textSize})) {
708 if (!mnemonicLabels.empty()) {
709 ++cycleLabelsCounter;
712 if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
713 nextGotoTarget = *mnemonicAddr;
715 if (!mnemonicLabels.empty()) {
717 auto tip =
strCat(
'#', hex_string<4>(*mnemonicAddr));
718 if (mnemonicLabels.size() > 1) {
719 strAppend(tip,
"\nmultiple possibilities (click to cycle):\n",
731 gotoTarget = nextGotoTarget;
732 if (syncDisassemblyWithPC) {
733 syncDisassemblyWithPC =
false;
735 auto itemHeight = ImGui::GetTextLineHeightWithSpacing();
736 auto winHeight = ImGui::GetWindowHeight();
737 auto lines = std::max(1,
int(winHeight / itemHeight) - 1);
741 ImGui::SetScrollY(topAddr * itemHeight);
742 }
else if (setDisassemblyScrollY) {
743 ImGui::SetScrollY(*setDisassemblyScrollY);
744 setDisassemblyScrollY.reset();
746 disassemblyScrollY = ImGui::GetScrollY();
750 cpuInterface.insertBreakPoint(std::move(*addBp));
753 cpuInterface.removeBreakPoint(*removeBpId);
758void ImGuiDebugger::drawSlots(MSXCPUInterface& cpuInterface, Debugger& debugger)
760 if (!showSlots)
return;
762 int flags = ImGuiTableFlags_BordersInnerV |
763 ImGuiTableFlags_Resizable |
764 ImGuiTableFlags_Reorderable |
765 ImGuiTableFlags_Hideable |
766 ImGuiTableFlags_ContextMenuInBody;
768 ImGui::TableSetupColumn(
"Page");
769 ImGui::TableSetupColumn(
"Address", ImGuiTableColumnFlags_DefaultHide);
770 ImGui::TableSetupColumn(
"Slot");
771 ImGui::TableSetupColumn(
"Segment");
772 ImGui::TableHeadersRow();
774 for (
auto page :
xrange(uint8_t(4))) {
775 auto addr = 0x4000 * page;
776 if (ImGui::TableNextColumn()) {
779 if (ImGui::TableNextColumn()) {
782 if (ImGui::TableNextColumn()) {
783 int ps = cpuInterface.getPrimarySlot(page);
784 if (cpuInterface.isExpanded(ps)) {
785 int ss = cpuInterface.getSecondarySlot(page);
791 if (ImGui::TableNextColumn()) {
792 const auto* device = cpuInterface.getVisibleMSXDevice(page);
795 }
else if (
auto [rom, romBlocks] = getRomBlocks(debugger, device); romBlocks) {
798 char separator =
'R';
799 for (
int offset = 0; offset < 0x4000; offset += blockSize) {
800 strAppend(text, separator, romBlocks->read(addr + offset));
816void ImGuiDebugger::drawStack(
const CPURegs& regs,
const MSXCPUInterface& cpuInterface, EmuTime::param time)
818 if (!showStack)
return;
820 auto line = ImGui::GetTextLineHeightWithSpacing();
821 ImGui::SetNextWindowSize(ImVec2(0.0f, 12 * line), ImGuiCond_FirstUseEver);
823 auto sp = regs.getSP();
825 int flags = ImGuiTableFlags_ScrollY |
826 ImGuiTableFlags_BordersInnerV |
827 ImGuiTableFlags_Resizable |
828 ImGuiTableFlags_Reorderable |
829 ImGuiTableFlags_Hideable |
830 ImGuiTableFlags_ContextMenuInBody;
832 ImGui::TableSetupScrollFreeze(0, 1);
833 ImGui::TableSetupColumn(
"Address");
834 ImGui::TableSetupColumn(
"Offset", ImGuiTableColumnFlags_DefaultHide);
835 ImGui::TableSetupColumn(
"Value", ImGuiTableColumnFlags_NoHide);
836 ImGui::TableHeadersRow();
840 auto offset = 2 * row;
841 auto addr = sp + offset;
842 if (ImGui::TableNextColumn()) {
845 if (ImGui::TableNextColumn()) {
846 ImGui::Text(
"SP+%X", offset);
848 if (ImGui::TableNextColumn()) {
849 auto l = cpuInterface.peekMem(narrow_cast<uint16_t>(addr + 0), time);
850 auto h = cpuInterface.peekMem(narrow_cast<uint16_t>(addr + 1), time);
851 auto value = narrow<uint16_t>(256 * h + l);
859void ImGuiDebugger::drawRegisters(CPURegs& regs)
861 if (!showRegisters)
return;
862 im::Window(
"CPU registers", &showRegisters, [&]{
865 const auto& style = ImGui::GetStyle();
866 auto padding = 2 * style.FramePadding.x;
868 auto edit16 = [&](std::string_view label, std::string_view high, std::string_view low,
auto getter,
auto setter) {
869 uint16_t value = getter();
871 ImGui::AlignTextToFramePadding();
874 ImGui::SetNextItemWidth(width16);
875 if (ImGui::InputScalar(
tmpStrCat(
"##", label).c_str(), ImGuiDataType_U16, &value,
nullptr,
nullptr,
"%04X")) {
881 "Bin: ", bin_string<4>(value >> 12),
' ', bin_string<4>(value >> 8),
' ',
882 bin_string<4>(value >> 4),
' ', bin_string<4>(value >> 0),
"\n"
883 "Dec: ", dec_string<5>(value),
'\n',
884 high,
": ", dec_string<3>(value >> 8),
" ", low,
": ", dec_string<3>(value & 0xff));
887 auto edit8 = [&](std::string_view label,
auto getter,
auto setter) {
888 uint8_t value = getter();
890 ImGui::AlignTextToFramePadding();
893 ImGui::SetNextItemWidth(width16);
894 if (ImGui::InputScalar(
tmpStrCat(
"##", label).c_str(), ImGuiDataType_U8, &value,
nullptr,
nullptr,
"%02X")) {
900 "Bin: ", bin_string<4>(value >> 4),
' ', bin_string<4>(value >> 0),
"\n"
901 "Dec: ", dec_string<3>(value),
'\n');
905 edit16(
"AF",
"A",
"F", [&]{
return regs.getAF(); }, [&](uint16_t value) { regs.setAF(value); });
906 ImGui::SameLine(0.0f, 20.0f);
907 edit16(
"AF'",
"A'",
"F'", [&]{
return regs.getAF2(); }, [&](uint16_t value) { regs.setAF2(value); });
909 edit16(
"BC",
"B",
"C", [&]{
return regs.getBC(); }, [&](uint16_t value) { regs.setBC(value); });
910 ImGui::SameLine(0.0f, 20.0f);
911 edit16(
"BC'",
"B'",
"C'", [&]{
return regs.getBC2(); }, [&](uint16_t value) { regs.setBC2(value); });
913 edit16(
"DE",
"D",
"E", [&]{
return regs.getDE(); }, [&](uint16_t value) { regs.setDE(value); });
914 ImGui::SameLine(0.0f, 20.0f);
915 edit16(
"DE'",
"D'",
"E'", [&]{
return regs.getDE2(); }, [&](uint16_t value) { regs.setDE2(value); });
917 edit16(
"HL",
"H",
"L", [&]{
return regs.getHL(); }, [&](uint16_t value) { regs.setHL(value); });
918 ImGui::SameLine(0.0f, 20.0f);
919 edit16(
"HL'",
"H'",
"L'", [&]{
return regs.getHL2(); }, [&](uint16_t value) { regs.setHL2(value); });
921 edit16(
"IX",
"IXh",
"IXl", [&]{
return regs.getIX(); }, [&](uint16_t value) { regs.setIX(value); });
922 ImGui::SameLine(0.0f, 20.0f);
923 edit16(
"IY ",
"IYh",
"IYl", [&]{
return regs.getIY(); }, [&](uint16_t value) { regs.setIY(value); });
925 edit16(
"PC",
"PCh",
"PCl", [&]{
return regs.getPC(); }, [&](uint16_t value) { regs.setPC(value); });
926 ImGui::SameLine(0.0f, 20.0f);
927 edit16(
"SP ",
"SPh",
"SPl", [&]{
return regs.getSP(); }, [&](uint16_t value) { regs.setSP(value); });
929 edit8(
"I ", [&]{
return regs.getI(); }, [&](uint8_t value) { regs.setI(value); });
930 ImGui::SameLine(0.0f, 20.0f);
931 edit8(
"R ", [&]{
return regs.getR(); }, [&](uint8_t value) { regs.setR(value); });
933 ImGui::AlignTextToFramePadding();
936 ImGui::SetNextItemWidth(width16);
937 if (uint8_t
im = regs.getIM();
938 ImGui::InputScalar(
"##IM", ImGuiDataType_U8, &
im,
nullptr,
nullptr,
"%d")) {
939 if (
im <= 2) regs.setIM(
im);
942 ImGui::SameLine(0.0f, 20.0f);
943 ImGui::AlignTextToFramePadding();
944 if (
bool ei = regs.getIFF1();
945 ImGui::Selectable(ei ?
"EI" :
"DI", false, ImGuiSelectableFlags_AllowDoubleClick)) {
946 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
955void ImGuiDebugger::drawFlags(CPURegs& regs)
957 if (!showFlags)
return;
959 auto [sizeH1_, sizeH2_, sizeV_] = [&]{
968 auto sizeH1 = sizeH1_;
auto sizeH2 = sizeH2_;
auto sizeV = sizeV_;
970 auto f = regs.getF();
972 auto draw = [&](
const char* name, uint8_t bit,
const char* val0 =
nullptr,
const char* val1 =
nullptr) {
975 if (flagsLayout == 0) {
978 s = (f & bit) ? val1 : val0;
981 s =
strCat(name,
':', (f & bit) ?
'1' :
'0');
986 s =
strCat(name,
' ', (f & bit) ?
'1' :
'0');
988 strAppend(s,
" (", (f & bit) ? val1 : val0,
')');
993 if (ImGui::Selectable(s.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick, sz)) {
994 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
999 simpleToolTip(
"double-click to toggle, right-click to configure");
1000 if (flagsLayout == 0) {
1002 ImGui::SameLine(0.0f, sizeH1.x);
1006 draw(
"S", 0x80,
" P",
" M");
1007 draw(
"Z", 0x40,
"NZ",
" Z");
1008 if (showXYFlags) draw(
"Y", 0x20);
1010 if (showXYFlags) draw(
"X", 0x08);
1011 draw(
"P", 0x04,
"PO",
"PE");
1013 draw(
"C", 0x01,
"NC",
" C");
1017 ImGui::RadioButton(
"horizontal", &flagsLayout, 0);
1018 ImGui::RadioButton(
"vertical", &flagsLayout, 1);
1020 ImGui::Checkbox(
"show undocumented", &showXYFlags);
std::string_view getDebuggableName() const
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
auto getPrimarySlot(int page) const
MSXDevice * getVisibleMSXDevice(int page)
bool isExpanded(int ps) const
auto getSecondarySlot(int page) const
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
MSXCPUInterface & getCPUInterface()
static unsigned getBlockSize(RomType type)
bool checkShortcut(const ShortcutWithRepeat &shortcut) const
const Shortcut & getShortcut(ID id) const
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....
detail::Joiner< Collection, Separator > join(Collection &&col, Separator &&sep)
auto CalcTextSize(std::string_view str)
void TextUnformatted(const std::string &str)
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
void ID(const char *str_id, std::invocable<> auto next)
void PopupContextWindow(const char *str_id, ImGuiPopupFlags popup_flags, std::invocable<> auto next)
bool Menu(const char *label, bool enabled, std::invocable<> auto next)
void Disabled(bool b, std::invocable<> auto next)
void Group(std::invocable<> auto next)
void Font(ImFont *font, std::invocable<> auto next)
void Indent(float indent_w, std::invocable<> auto next)
void ListClipper(size_t count, int forceIndex, float lineHeight, std::invocable< int > auto next)
void Popup(const char *str_id, ImGuiWindowFlags flags, std::invocable<> auto next)
This file implemented 3 utility functions:
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void simpleToolTip(std::string_view desc)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
unsigned dasm(const MSXCPUInterface &interface, uint16_t pc, std::span< uint8_t, 4 > buf, std::string &dest, EmuTime::param time, function_ref< void(std::string &, uint16_t)> appendAddr)
Disassemble.
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.
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...
TclObject makeTclList(Args &&... args)
auto equal_range(ForwardRange &&range, const T &value, Compare comp={})
constexpr void sort(RandomAccessRange &&range)
auto lower_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
constexpr auto transform(Range &&range, UnaryOp op)
TemporaryString tmpStrCat(Ts &&... ts)
void strAppend(std::string &result, Ts &&...ts)
constexpr auto xrange(T e)