21#include "imgui_stdlib.h"
34using namespace std::literals;
36static constexpr int MidColsCount = 8;
37static constexpr auto HighlightColor = IM_COL32(255, 255, 255, 50);
38static constexpr auto HighlightSymbolColor = IM_COL32(148, 95, 35, 255);
42 , symbolManager(manager.getReactor().getSymbolManager())
43 , title(
std::move(debuggableName_))
45 debuggableNameSize = title.size();
59 parseSearchString(searchString);
67DebuggableEditor::Sizes DebuggableEditor::calcSizes(
unsigned memSize)
const
70 const auto& style = ImGui::GetStyle();
72 s.addrDigitsCount = 0;
73 for (
unsigned n = memSize - 1; n > 0; n >>= 4) {
77 s.lineHeight = ImGui::GetTextLineHeight();
79 s.hexCellWidth = truncf(s.glyphWidth * 2.5f);
80 s.spacingBetweenMidCols = truncf(s.hexCellWidth * 0.25f);
81 s.posHexStart = float(s.addrDigitsCount + 2) * s.glyphWidth;
82 auto posHexEnd = s.posHexStart + (s.hexCellWidth * float(columns));
83 s.posAsciiStart = s.posAsciiEnd = posHexEnd;
85 int numMacroColumns = (columns + MidColsCount - 1) / MidColsCount;
86 s.posAsciiStart = posHexEnd + s.glyphWidth + float(numMacroColumns) * s.spacingBetweenMidCols;
87 s.posAsciiEnd = s.posAsciiStart + float(columns) * s.glyphWidth;
89 s.windowWidth = s.posAsciiEnd + style.ScrollbarSize + style.WindowPadding.x * 2 + s.glyphWidth;
95 if (!
open || !motherBoard)
return;
98 if (!debuggable)
return;
102 unsigned memSize = debuggable->getSize();
103 columns = std::min(columns, narrow<int>(memSize));
104 auto s = calcSizes(memSize);
105 ImGui::SetNextWindowSize(ImVec2(s.windowWidth, s.windowWidth * 0.60f), ImGuiCond_FirstUseEver);
107 im::Window(title.c_str(), &
open, ImGuiWindowFlags_NoScrollbar, [&]{
108 if (ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows) &&
109 ImGui::IsMouseReleased(ImGuiMouseButton_Right)) {
110 ImGui::OpenPopup(
"context");
112 drawContents(s, *debuggable, memSize);
116[[nodiscard]]
static unsigned DataTypeGetSize(ImGuiDataType dataType)
118 std::array<unsigned, 8> sizes = { 1, 1, 2, 2, 4, 4, 8, 8 };
119 assert(dataType >= 0 && dataType < 8);
120 return sizes[dataType];
123[[nodiscard]]
static std::optional<int> parseHexDigit(
char c)
125 if (
'0' <= c && c <=
'9')
return c -
'0';
126 if (
'a' <= c && c <=
'f')
return c -
'a' + 10;
127 if (
'A' <= c && c <=
'F')
return c -
'A' + 10;
131[[nodiscard]]
static std::optional<uint8_t> parseDataValue(std::string_view str)
133 if (str.size() == 1) {
134 return parseHexDigit(str[0]);
135 }
else if (str.size() == 2) {
136 if (
auto digit0 = parseHexDigit(str[0])) {
137 if (
auto digit1 = parseHexDigit(str[1])) {
138 return 16 * *digit0 + *digit1;
145[[nodiscard]]
static std::expected<unsigned, std::string> parseAddressExpr(
146 std::string_view str,
const SymbolManager& symbolManager, Interpreter& interp)
148 if (str.empty())
return 0;
152 if (
auto addr = symbolManager.parseSymbolOrValue(str)) {
157 return TclObject(str).eval(interp).getInt(interp);
158 }
catch (CommandException& e) {
159 return std::unexpected(
e.getMessage());
163[[nodiscard]]
static std::string formatData(uint8_t val)
165 return strCat(hex_string<2, HexCase::upper>(val));
168[[nodiscard]]
static char formatAsciiData(uint8_t val)
170 return (val < 32 || val >= 128) ?
'.' : char(val);
173[[nodiscard]] std::string DebuggableEditor::formatAddr(
const Sizes& s,
unsigned addr)
const
175 return strCat(hex_string<HexCase::upper>(
Digits{size_t(s.addrDigitsCount)}, addr));
177void DebuggableEditor::setStrings(
const Sizes& s, Debuggable& debuggable)
179 addrStr =
strCat(
"0x", formatAddr(s, currentAddr));
180 auto b = debuggable.read(currentAddr);
181 if (dataEditingActive == HEX ) dataInput = formatData(b);
182 if (dataEditingActive == ASCII) dataInput = std::string(1, formatAsciiData(b));
184bool DebuggableEditor::setAddr(
const Sizes& s, Debuggable& debuggable,
unsigned memSize,
unsigned addr)
186 addr = std::min(addr, memSize - 1);
187 if (currentAddr == addr)
return false;
189 setStrings(s, debuggable);
192void DebuggableEditor::scrollAddr(
const Sizes& s, Debuggable& debuggable,
unsigned memSize,
unsigned addr,
bool forceScroll)
194 if (setAddr(s, debuggable, memSize, addr) || forceScroll) {
196 int row = narrow<int>(currentAddr) / columns;
197 ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y +
float(row) * ImGui::GetTextLineHeight());
202void DebuggableEditor::drawContents(
const Sizes& s, Debuggable& debuggable,
unsigned memSize)
204 const auto& style = ImGui::GetStyle();
207 scrollAddr(s, debuggable, memSize, currentAddr,
true);
210 setAddr(s, debuggable, memSize, currentAddr);
213 float footerHeight = 0.0f;
215 footerHeight += style.ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
218 footerHeight += style.ItemSpacing.y + 2 * ImGui::GetFrameHeightWithSpacing();
220 if (showDataPreview) {
221 footerHeight += style.ItemSpacing.y + ImGui::GetFrameHeightWithSpacing() + 3 * ImGui::GetTextLineHeightWithSpacing();
223 if (showSymbolInfo) {
224 footerHeight += style.ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
228 int cFlags = ImGuiWindowFlags_NoMove;
233 cFlags |= ImGuiWindowFlags_HorizontalScrollbar;
234 ImGui::BeginChild(
"##scrolling", ImVec2(0, -footerHeight), ImGuiChildFlags_None, cFlags);
235 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
236 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
238 std::optional<unsigned> nextAddr;
241 auto* drawList = ImGui::GetWindowDrawList();
242 ImVec2 windowPos = ImGui::GetWindowPos();
244 drawList->AddLine(ImVec2(windowPos.x + s.posAsciiStart - s.glyphWidth, windowPos.y),
245 ImVec2(windowPos.x + s.posAsciiStart - s.glyphWidth, windowPos.y + 9999),
246 ImGui::GetColorU32(ImGuiCol_Border));
249 auto handleInput = [&](
unsigned addr,
int width,
auto formatData,
auto parseData,
int extraFlags = 0) {
251 if (dataEditingTakeFocus) {
252 ImGui::SetKeyboardFocusHere();
253 setStrings(s, debuggable);
257 static int Callback(ImGuiInputTextCallbackData* data) {
258 auto* userData =
static_cast<UserData*
>(data->UserData);
259 if (userData->cursorPos != -1) {
260 data->CursorPos = userData->cursorPos;
262 if (!data->HasSelection()) {
263 userData->cursorPos = data->CursorPos;
265 if (data->SelectionStart == 0 && data->SelectionEnd == data->BufTextLen) {
268 data->DeleteChars(0, data->BufTextLen);
269 userData->format(data);
272 data->SelectionStart = 0;
277 std::function<void(ImGuiInputTextCallbackData* data)>
format;
281 userData.format = formatData;
284 userData.cursorPos = 0;
286 ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue
287 | ImGuiInputTextFlags_AutoSelectAll
288 | ImGuiInputTextFlags_NoHorizontalScroll
289 | ImGuiInputTextFlags_CallbackAlways
290 | ImGuiInputTextFlags_AlwaysOverwrite
292 ImGui::SetNextItemWidth(s.glyphWidth *
float(width));
293 bool dataWrite =
false;
295 if (ImGui::InputText(
"##data", &dataInput, flags, UserData::Callback, &userData)) {
297 }
else if (!ImGui::IsItemActive()) {
298 setStrings(s, debuggable);
302 if (addrMode == CURSOR && ImGui::IsItemActive()) {
303 if (ImGui::IsKeyChordPressed(ImGuiKey_Home | ImGuiMod_Ctrl)) {
306 }
else if (ImGui::IsKeyPressed(ImGuiKey_Home)) {
307 nextAddr = currentAddr - (currentAddr % unsigned(columns));
309 if (ImGui::IsKeyChordPressed(ImGuiKey_End | ImGuiMod_Ctrl)) {
310 nextAddr = memSize - 1;
315 }
else if (ImGui::IsKeyPressed(ImGuiKey_End)) {
316 auto tmp = currentAddr - (currentAddr % unsigned(columns)) + columns - 1;
317 nextAddr = std::min(tmp, memSize - 1);
320 if ((
int(currentAddr) >= columns) &&
321 ImGui::IsKeyPressed(ImGuiKey_UpArrow)) {
322 nextAddr = currentAddr - columns;
324 if ((
int(currentAddr) <
int(memSize - columns)) &&
325 ImGui::IsKeyPressed(ImGuiKey_DownArrow)) {
326 nextAddr = currentAddr + columns;
328 if ((
int(currentAddr) > 0) &&
329 ImGui::IsKeyPressed(ImGuiKey_LeftArrow)) {
330 nextAddr = currentAddr - 1;
332 if (ImGui::IsKeyPressed(ImGuiKey_RightArrow)) {
335 nextAddr = std::min(currentAddr + 1, memSize - 1);
338 if (!switchedTab && ImGui::IsKeyPressed(ImGuiKey_Tab)) {
339 dataEditingActive = (dataEditingActive == HEX) ? ASCII : HEX;
340 nextAddr = currentAddr;
346 dataEditingTakeFocus =
false;
347 dataWrite |= userData.cursorPos >= width;
350 dataEditingTakeFocus =
true;
353 if (
auto value = parseData(dataInput)) {
354 debuggable.write(addr, *value);
356 nextAddr = currentAddr + 1;
361 const auto totalLineCount = int((memSize + columns - 1) / columns);
363 auto addr = unsigned(line) * columns;
364 ImGui::StrCat(formatAddr(s, addr),
':');
366 auto previewDataTypeSize = DataTypeGetSize(previewDataType);
367 auto inside = [](unsigned a, unsigned start, unsigned size) {
368 return (start <= a) && (a < (start + size));
370 auto highLightDataPreview = [&](
unsigned a) {
371 return inside(a, currentAddr, previewDataTypeSize);
373 auto highLightSearch = [&](
unsigned a) {
374 if (!searchPattern)
return false;
375 auto len = narrow<unsigned>(searchPattern->size());
376 if (searchHighlight ==
static_cast<int>(SearchHighlight::SINGLE)) {
378 return inside(a, *searchResult, len);
380 }
else if (searchHighlight ==
static_cast<int>(SearchHighlight::ALL)) {
381 int start = std::max(0,
int(a - len + 1));
382 for (
unsigned i = start; i <= a; ++i) {
383 if (
match(debuggable, memSize, i))
return true;
388 auto highLight = [&](
unsigned a) {
389 return highLightDataPreview(a) || highLightSearch(a);
393 for (
int n = 0; n < columns && addr < memSize; ++n, ++addr) {
394 int macroColumn = n / MidColsCount;
395 float bytePosX = s.posHexStart + float(n) * s.hexCellWidth
396 + float(macroColumn) * s.spacingBetweenMidCols;
397 ImGui::SameLine(bytePosX);
400 if (highLight(addr)) {
401 ImVec2 pos = ImGui::GetCursorScreenPos();
402 float highlightWidth = s.glyphWidth * 2;
403 if (highLight(addr + 1)) {
404 highlightWidth = s.hexCellWidth;
405 if (n > 0 && (n + 1) < columns && ((n + 1) % MidColsCount) == 0) {
406 highlightWidth += s.spacingBetweenMidCols;
409 drawList->AddRectFilled(pos, ImVec2(pos.x + highlightWidth, pos.y + s.lineHeight), HighlightColor);
413 if (showSymbolInfo) {
414 auto symbol = symbolManager.lookupValue(narrow_cast<uint16_t>(addr));
415 if (!symbol.empty()) {
416 float highlightWidth = s.glyphWidth * 2;
417 ImVec2 pos = ImGui::GetCursorScreenPos();
418 drawList->AddRectFilled(pos, ImVec2(pos.x + highlightWidth, pos.y + s.lineHeight), HighlightSymbolColor);
422 if (currentAddr == addr && (dataEditingActive == HEX)) {
424 [&](ImGuiInputTextCallbackData* data) {
425 auto valStr = formatData(debuggable.read(addr));
426 data->InsertChars(0, valStr.data(), valStr.data() + valStr.size());
427 data->SelectionEnd = 2;
429 [&](std::string_view data) {
430 return parseDataValue(data);
432 ImGuiInputTextFlags_CharsHexadecimal);
434 uint8_t b = debuggable.read(addr);
438 if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) {
439 dataEditingActive = HEX;
440 dataEditingTakeFocus =
true;
448 ImGui::SameLine(s.posAsciiStart);
449 gl::vec2 pos = ImGui::GetCursorPos();
450 gl::vec2 scrnPos = ImGui::GetCursorScreenPos();
451 addr = unsigned(line) * columns;
456 if (ImGui::InvisibleButton(
"ascii", ImVec2(s.posAsciiEnd - s.posAsciiStart, s.lineHeight))) {
457 dataEditingActive = ASCII;
458 dataEditingTakeFocus = true;
459 nextAddr = addr + unsigned((ImGui::GetIO().MousePos.x - scrnPos.x) / s.glyphWidth);
463 for (
int n = 0; n < columns && addr < memSize; ++n, ++addr) {
464 if (highLight(addr)) {
465 auto start = scrnPos +
gl::vec2(
float(n) * s.glyphWidth, 0.0f);
466 drawList->AddRectFilled(start, start +
gl::vec2(s.glyphWidth, s.lineHeight), ImGui::GetColorU32(HighlightColor));
469 ImGui::SetCursorPos(pos);
470 if (currentAddr == addr && (dataEditingActive == ASCII)) {
472 [&](ImGuiInputTextCallbackData* data) {
473 char valChar = formatAsciiData(debuggable.read(addr));
474 data->InsertChars(0, &valChar, &valChar + 1);
475 data->SelectionEnd = 1;
477 [&](std::string_view data) -> std::optional<uint8_t> {
478 if (data.empty())
return {};
480 if (b < 32 || b >= 128)
return {};
484 uint8_t c = debuggable.read(addr);
485 char display = formatAsciiData(c);
490 pos.x += s.glyphWidth;
494 ImGui::PopStyleVar(2);
498 setAddr(s, debuggable, memSize, *nextAddr);
499 dataEditingTakeFocus =
true;
504 bool forceScroll = ImGui::IsWindowAppearing();
507 ImGui::AlignTextToFramePadding();
510 ImGui::SetNextItemWidth(2.0f * style.FramePadding.x +
ImGui::CalcTextSize(
"Expression").x + ImGui::GetFrameHeight());
511 if (ImGui::Combo(
"##mode", &addrMode,
"Cursor\0Expression\0Link BC\0Link DE\0Link HL\0")) {
512 dataEditingTakeFocus =
true;
515 static constexpr std::array linkExpr = {
516 "[reg bc]",
"[reg de]",
"[reg hl]"
518 addrExpr = linkExpr[addrMode - 2];
519 addrMode = EXPRESSION;
524 std::string* as = addrMode == CURSOR ? &addrStr : &addrExpr;
525 auto addr = parseAddressExpr(*as, symbolManager, manager.getInterpreter());
527 if (addrMode == EXPRESSION && addr) {
528 scrollAddr(s, debuggable, memSize, *addr, forceScroll);
530 if (manager.getShortcuts().checkShortcut(Shortcuts::ID::HEX_GOTO_ADDR)) {
531 ImGui::SetKeyboardFocusHere();
533 ImGui::SetNextItemWidth(15.0f * ImGui::GetFontSize());
534 if (ImGui::InputText(
"##addr", as, ImGuiInputTextFlags_EnterReturnsTrue)) {
535 if (
auto addr2 = parseAddressExpr(addrStr, symbolManager, manager.getInterpreter())) {
536 scrollAddr(s, debuggable, memSize, *addr2, forceScroll);
537 dataEditingTakeFocus =
true;
541 return addr ?
strCat(
"0x", formatAddr(s, *addr))
546 HelpMarker(
"Address-mode:\n"
547 " Cursor: view the cursor position\n"
548 " Expression: continuously re-evaluate an expression and view that address\n"
550 "Addresses can be entered as:\n"
551 " Decimal or hexadecimal values (e.g. 0x1234)\n"
552 " A calculation like 0x1234 + 7*22\n"
553 " The name of a label (e.g. CHPUT)\n"
554 " A Tcl expression (e.g. [reg hl] to follow the content of register HL)\n"
556 "Right-click to configure this view.");
561 drawSearch(s, debuggable, memSize);
563 if (showDataPreview) {
565 drawPreviewLine(s, debuggable, memSize);
567 if (showSymbolInfo) {
569 ImGui::AlignTextToFramePadding();
570 auto symbol = symbolManager.lookupValue(narrow_cast<uint16_t>(currentAddr));
571 if (!symbol.empty()) {
572 ImGui::Text(
"Current symbol: %s", symbol[0]->name.c_str());
579 ImGui::SetNextItemWidth(7.5f * s.glyphWidth + 2.0f * style.FramePadding.x);
580 if (ImGui::InputInt(
"Columns", &columns, 1, 0)) {
581 columns = std::clamp(columns, 1, MAX_COLUMNS);
583 ImGui::Checkbox(
"Show Address bar", &showAddress);
584 ImGui::Checkbox(
"Show Search pane", &showSearch);
585 ImGui::Checkbox(
"Show Data Preview", &showDataPreview);
586 ImGui::Checkbox(
"Show Ascii", &showAscii);
587 ImGui::Checkbox(
"Show Symbol info", &showSymbolInfo);
588 ImGui::Checkbox(
"Grey out zeroes", &greyOutZeroes);
595[[nodiscard]]
static const char* DataTypeGetDesc(ImGuiDataType dataType)
597 std::array<const char*, 8> desc = {
598 "Int8",
"Uint8",
"Int16",
"Uint16",
"Int32",
"Uint32",
"Int64",
"Uint64"
600 assert(dataType >= 0 && dataType < 8);
601 return desc[dataType];
605[[nodiscard]]
static T read(std::span<const uint8_t> buf)
607 assert(buf.size() >=
sizeof(T));
609 memcpy(&
t, buf.data(),
sizeof(T));
613static void formatDec(std::span<const uint8_t> buf, ImGuiDataType dataType)
616 case ImGuiDataType_S8:
619 case ImGuiDataType_U8:
622 case ImGuiDataType_S16:
625 case ImGuiDataType_U16:
628 case ImGuiDataType_S32:
631 case ImGuiDataType_U32:
634 case ImGuiDataType_S64:
637 case ImGuiDataType_U64:
645static void formatHex(std::span<const uint8_t> buf, ImGuiDataType data_type)
648 case ImGuiDataType_S8:
649 case ImGuiDataType_U8:
652 case ImGuiDataType_S16:
653 case ImGuiDataType_U16:
656 case ImGuiDataType_S32:
657 case ImGuiDataType_U32:
660 case ImGuiDataType_S64:
661 case ImGuiDataType_U64:
669static void formatBin(std::span<const uint8_t> buf)
671 for (
int i =
int(buf.size()) - 1; i >= 0; --i) {
673 if (i != 0) ImGui::SameLine();
677void DebuggableEditor::parseSearchString(std::string_view str)
679 searchPattern.reset();
680 searchResult.reset();
681 std::vector<uint8_t> result;
683 if (searchType ==
static_cast<int>(SearchType::ASCII)) {
684 const auto*
begin = std::bit_cast<const uint8_t*>(str.data());
685 const auto*
end =
begin + str.size();
688 assert(searchType ==
static_cast<int>(SearchType::HEX));
689 std::optional<int> partial;
691 if (c ==
' ')
continue;
692 auto digit = parseHexDigit(c);
695 result.push_back(narrow<uint8_t>(16 * *partial + *digit));
704 searchPattern = std::move(result);
707void DebuggableEditor::drawSearch(
const Sizes& s, Debuggable& debuggable,
unsigned memSize)
709 const auto& style = ImGui::GetStyle();
711 bool doSearch =
false;
713 ImGui::SetNextItemWidth(-(buttonSize + style.WindowPadding.x));
715 auto callback = [](ImGuiInputTextCallbackData* data) {
716 if (data->EventFlag == ImGuiInputTextFlags_CallbackEdit) {
717 auto& self = *
static_cast<DebuggableEditor*
>(data->UserData);
718 self.parseSearchString(std::string_view(data->Buf, data->BufTextLen));
722 ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue
723 | ImGuiInputTextFlags_CallbackEdit;
724 if (ImGui::InputText(
"##search_string", &searchString, flags, callback,
this)) {
730 doSearch |= ImGui::Button(
"Search");
732 if (!searchPattern) {
733 simpleToolTip(
"Must be an even number of hex digits, optionally separated by spaces");
735 if (searchPattern && doSearch) {
736 search(s, debuggable, memSize);
739 auto arrowSize = ImGui::GetFrameHeight();
740 auto extra = arrowSize + 2.0f * style.FramePadding.x;
741 ImGui::AlignTextToFramePadding();
745 if (ImGui::Combo(
"##search_type", &searchType,
"Hex\0Ascii\0\0")) {
746 parseSearchString(searchString);
749 ImGui::SameLine(0.0f, 2 * ImGui::GetFontSize());
753 ImGui::Combo(
"##search_direction", &searchDirection,
"Forwards\0Backwards\0\0");
755 ImGui::SameLine(0.0f, 2 * ImGui::GetFontSize());
759 ImGui::Combo(
"##search_highlight", &searchHighlight,
"None\0Single\0All\0\0");
762bool DebuggableEditor::match(Debuggable& debuggable,
unsigned memSize,
unsigned addr)
764 assert(searchPattern);
765 if ((addr + searchPattern->size()) > memSize)
return false;
766 for (
auto [i, c] :
enumerate(*searchPattern)) {
767 if (debuggable.read(narrow<unsigned>(addr + i)) != c)
return false;
772void DebuggableEditor::search(
const Sizes& s, Debuggable& debuggable,
unsigned memSize)
774 std::optional<unsigned> found;
775 auto test = [&](
unsigned addr) {
776 if (
match(debuggable, memSize, addr)) {
782 if (searchDirection ==
static_cast<int>(SearchDirection::FWD)) {
783 for (
unsigned addr = currentAddr + 1; addr < memSize; ++addr) {
784 if (
test(addr))
break;
787 for (
unsigned addr = 0; addr <= currentAddr; ++addr) {
788 if (
test(addr))
break;
792 for (
int addr = currentAddr - 1; addr > 0; --addr) {
793 if (
test(
unsigned(addr)))
break;
796 for (
int addr = memSize - 1; addr >= int(currentAddr); --addr) {
797 if (
test(
unsigned(addr)))
break;
802 searchResult = *found;
803 scrollAddr(s, debuggable, memSize, *found,
false);
804 dataEditingTakeFocus =
true;
807 searchResult.reset();
808 ImGui::OpenPopup(
"NotFound");
812void DebuggableEditor::drawPreviewLine(
const Sizes& s, Debuggable& debuggable,
unsigned memSize)
814 const auto& style = ImGui::GetStyle();
815 ImGui::AlignTextToFramePadding();
818 ImGui::SetNextItemWidth((s.glyphWidth * 10.0f) + style.FramePadding.x * 2.0f + style.ItemInnerSpacing.x);
819 if (ImGui::BeginCombo(
"##combo_type", DataTypeGetDesc(previewDataType), ImGuiComboFlags_HeightLargest)) {
820 for (ImGuiDataType n = 0; n < 8; ++n) {
821 if (ImGui::Selectable(DataTypeGetDesc(n), previewDataType == n)) {
828 ImGui::SetNextItemWidth((s.glyphWidth * 6.0f) + style.FramePadding.x * 2.0f + style.ItemInnerSpacing.x);
829 ImGui::Combo(
"##combo_endianess", &previewEndianess,
"LE\0BE\0\0");
831 std::array<uint8_t, 8> dataBuf = {};
832 auto elemSize = DataTypeGetSize(previewDataType);
833 for (
auto i :
xrange(elemSize)) {
834 auto addr = currentAddr + i;
835 dataBuf[i] = (addr < memSize) ? debuggable.read(addr) : 0;
838 static constexpr bool nativeIsLittle = std::endian::native == std::endian::little;
839 if (
bool previewIsLittle = previewEndianess == LE;
840 nativeIsLittle != previewIsLittle) {
841 std::reverse(dataBuf.begin(), dataBuf.begin() + elemSize);
846 formatDec(dataBuf, previewDataType);
850 formatHex(dataBuf, previewDataType);
854 formatBin(
subspan(dataBuf, 0, elemSize));
void test(const IterableBitSet< N > &s, std::initializer_list< size_t > list)
void paint(MSXMotherBoard *motherBoard) override
DebuggableEditor(ImGuiManager &manager_, std::string debuggableName, size_t index)
std::string_view getDebuggableName() const
void loadLine(std::string_view name, zstring_view value) override
void save(ImGuiTextBuffer &buf) override
Debuggable * findDebuggable(std::string_view name)
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....
auto CalcTextSize(std::string_view str)
void TextUnformatted(const std::string &str)
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 StyleColor(bool active, Args &&...args)
void Child(const char *str_id, const ImVec2 &size, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags, std::invocable<> auto next)
void Disabled(bool b, std::invocable<> auto next)
void Font(ImFont *font, 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)
void format(SectorAccessibleDisk &disk, MSXBootSectorType bootType)
Format the given disk (= a single partition).
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)
std::optional< bool > match(const BooleanInput &binding, const Event &event, function_ref< int(JoystickId)> getJoyDeadZone)
ImU32 getColor(imColor col)
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
void strAppend(std::string &result, Ts &&...ts)
constexpr auto xrange(T e)
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)