34#include <CustomFont.h>
36#include <imgui_stdlib.h>
43using namespace std::literals;
52 if (item.
name.empty())
return;
53 buf.appendf(
"%s.name=%s\n", name.c_str(), item.
name.c_str());
55 buf.appendf(
"%s.patch=%s\n", name.c_str(), patch.c_str());
58 buf.appendf(
"%s.romType=%s\n", name.c_str(),
63 saveItem(group.
edit, name);
64 auto recentName =
tmpStrCat(name,
".recent");
65 for (
const auto& item : group.
recent) {
66 saveItem(item, recentName);
73 for (
const auto& info : diskMediaInfo) {
78 if (info.show) buf.appendf(
"%s.show=1\n", name.c_str());
83 for (
const auto& info : cartridgeMediaInfo) {
87 if (info.show) buf.appendf(
"%s.show=1\n", name.c_str());
92 for (
const auto& info : hdMediaInfo) {
93 saveGroup(info, name);
98 for (
const auto& info : cdMediaInfo) {
99 saveGroup(info, name);
103 if (cassetteMediaInfo.
show) buf.append(
"cassette.show=1\n");
104 saveGroup(cassetteMediaInfo.
group,
"cassette");
106 saveGroup(extensionMediaInfo,
"extension");
107 saveGroup(laserdiscMediaInfo,
"laserdisc");
112 auto get = [&](std::string_view prefix,
auto& array) -> std::remove_reference_t<
decltype(array[0])>* {
113 if ((name.size() >= (prefix.size() + 2)) && name.starts_with(prefix) && (name[prefix.size() + 1] ==
'.')) {
114 char c = name[prefix.size()];
115 if ((
'a' <= c) && (c < char(
'a' + array.size()))) {
116 return &array[c -
'a'];
121 auto loadItem = [&](
MediaItem& item, std::string_view suffix) {
122 if (suffix ==
"name") {
124 }
else if (suffix ==
"patch") {
126 }
else if (suffix ==
"romType") {
132 auto loadGroup = [&](
ItemGroup& group, std::string_view suffix) {
133 if (suffix.starts_with(
"recent.")) {
134 if (suffix ==
"recent.name" && !group.
recent.full()) {
137 if (!group.
recent.empty()) {
138 loadItem(group.
recent.back(), suffix.substr(7));
141 loadItem(group.
edit, suffix);
147 }
else if (
auto* disk = get(
"disk", diskMediaInfo)) {
149 auto suffix = name.substr(6);
150 if (suffix.starts_with(
"image.")) {
151 loadGroup(disk->groups[
IMAGE], suffix.substr(6));
152 }
else if (suffix.starts_with(
"dirAsDsk.")) {
153 loadGroup(disk->groups[
DIR_AS_DISK], suffix.substr(9));
154 }
else if (suffix ==
"select") {
155 if (
auto i = StringOp::stringTo<unsigned>(value)) {
160 }
else if (suffix ==
"show") {
163 }
else if (
auto* cart = get(
"cart", cartridgeMediaInfo)) {
165 auto suffix = name.substr(6);
166 if (suffix.starts_with(
"rom.")) {
167 loadGroup(cart->groups[
IMAGE], suffix.substr(4));
168 }
else if (suffix.starts_with(
"extension.")) {
169 loadGroup(cart->groups[
EXTENSION], suffix.substr(10));
170 }
else if (suffix ==
"select") {
171 if (
auto i = StringOp::stringTo<unsigned>(value)) {
176 }
else if (suffix ==
"show") {
179 }
else if (
auto* hd = get(
"hd", hdMediaInfo)) {
180 loadGroup(*hd, name.substr(4));
181 }
else if (
auto* cd = get(
"cd", cdMediaInfo)) {
182 loadGroup(*cd, name.substr(4));
183 }
else if (name.starts_with(
"cassette.")) {
184 auto suffix = name.substr(9);
185 if (suffix ==
"show") {
188 loadGroup(cassetteMediaInfo.
group, suffix);
190 }
else if (name.starts_with(
"extension.")) {
191 loadGroup(extensionMediaInfo, name.substr(10));
192 }
else if (name.starts_with(
"laserdisc.")) {
193 loadGroup(laserdiscMediaInfo, name.substr(10));
197static std::string buildFilter(std::string_view description, std::span<const std::string_view> extensions)
199 auto formatExtensions = [&]() -> std::string {
200 if (extensions.size() <= 3) {
202 [](
const auto& ext) {
return strCat(
"*.", ext); }),
205 return join(extensions,
',');
209 description,
" (", formatExtensions(),
"){",
211 [](
const auto& ext) {
return strCat(
'.', ext); }),
221static std::string romFilter()
226static std::string cassetteFilter()
231static std::string hdFilter()
233 return buildFilter(
"Hard disk images", std::array{
"dsk"sv});
236static std::string cdFilter()
238 return buildFilter(
"CDROM images", std::array{
"iso"sv});
241template<std::invocable<const std::
string&> DisplayFunc = std::
identity>
242static std::string display(
const ImGuiMedia::MediaItem& item, DisplayFunc displayFunc = {})
244 std::string result = displayFunc(item.name);
248 if (
auto n = item.ipsPatches.size()) {
249 strAppend(result,
" (+", n,
" patch", (n == 1 ?
"" :
"es"),
')');
256 if (extensionInfo.empty()) {
257 extensionInfo = parseAllConfigFiles<ExtensionInfo>(
manager,
"extensions", {
"Manufacturer"sv,
"Product code"sv,
"Name"sv});
259 return extensionInfo;
264 extensionInfo.clear();
281 std::optional<MSXMotherBoard> mb;
285 mb->getMSXCliComm().setSuppressMessages(
true);
287 mb->loadMachine(
"C-BIOS_MSX1");
292 if (
const auto* current = reactor.getMotherBoard()) {
294 mb->getMSXCliComm().setSuppressMessages(true);
295 mb->loadMachine(std::string(current->getMachineName()));
304 auto ext = mb->loadExtension(info.
configName,
"any");
305 mb->insertExtension(info.
configName, std::move(ext));
320 return (it != allExtensions.end()) ? std::to_address(it) :
nullptr;
326 return info ? info->displayName
327 : std::string(config);
333 if (
auto sha1 = reactor.getFilePool().getSha1Sum(filename)) {
335 if (
const auto* romInfo = database.fetchRomInfo(*sha1)) {
336 if (
auto title = romInfo->getTitle(database.getBufferStart());
338 return std::string(title);
366 std::string result = slot
376 std::string_view display;
378 display = result->getListIndexUnchecked(1).getString();
380 return display.empty() ?
"Empty"
385void ImGuiMedia::printExtensionInfo(ExtensionInfo& info)
388 bool ok =
test.empty();
391 ImGui::TableSetupColumn(
"description", ImGuiTableColumnFlags_WidthFixed);
392 ImGui::TableSetupColumn(
"value", ImGuiTableColumnFlags_WidthStretch);
394 for (
const auto& [desc, value_] : info.configInfo) {
395 const auto& value = value_;
396 if (ImGui::TableNextColumn()) {
399 if (ImGui::TableNextColumn()) {
415void ImGuiMedia::extensionTooltip(ExtensionInfo& info)
418 printExtensionInfo(info);
422bool ImGuiMedia::drawExtensionFilter()
424 std::string filterDisplay =
"filter";
425 if (!filterType.empty() || !filterString.empty())
strAppend(filterDisplay,
':');
426 if (!filterType.empty())
strAppend(filterDisplay,
' ', filterType);
427 if (!filterString.empty())
strAppend(filterDisplay,
' ', filterString);
429 bool newFilterOpen = filterOpen;
430 im::TreeNode(filterDisplay.c_str(), &newFilterOpen, [&]{
431 displayFilterCombo(filterType,
"Type", getAllExtensions());
432 ImGui::InputText(ICON_IGFD_FILTER, &filterString);
433 simpleToolTip(
"A list of substrings that must be part of the extension.\n"
435 "For example: enter 'ko' to search for 'Konami' extensions. "
436 "Then refine the search by appending '<space>sc' to find the 'Konami SCC' extension.");
438 bool changed = filterOpen != newFilterOpen;
439 filterOpen = newFilterOpen;
445 im::Menu(
"Media", motherBoard !=
nullptr, [&]{
448 enum class Status {
NONE, ITEM, SEPARATOR };
450 Status status =
NONE;
452 auto endGroup = [&] {
453 if (status == ITEM) status = SEPARATOR;
455 auto elementInGroup = [&] {
456 if (status == SEPARATOR) {
462 auto showCurrent = [&](
const TclObject& current, std::string_view type) {
463 if (current.
empty()) {
471 auto showRecent = [&](std::string_view mediaName,
ItemGroup& group,
472 function_ref<std::string(
const std::string&)> displayFunc = std::identity{},
473 const std::function<void(
const std::string&)>& toolTip = {}) {
474 if (!group.recent.empty()) {
478 for (
const auto& item : group.recent) {
479 auto d =
strCat(display(item, displayFunc),
"##", count++);
480 if (ImGui::MenuItem(d.c_str())) {
482 insertMedia(mediaName, group.edit);
484 if (toolTip) toolTip(item.name);
494 bool anySlot =
false;
496 if (!slotManager.slotExists(i))
continue;
498 auto [ps, ss] = slotManager.
getPsSs(i);
499 std::string extraInfo = ss == -1 ?
"" :
strCat(
" (", slotManager.getPsSsString(i),
")");
500 auto displayName =
strCat(
"Cartridge Slot ",
char(
'A' + i), extraInfo);
501 ImGui::MenuItem(displayName.c_str(),
nullptr, &cartridgeMediaInfo[i].show);
505 ImGui::TextDisabled(
"No cartridge slots present");
512 auto mediaName =
"ext"sv;
513 auto& group = extensionMediaInfo;
516 HelpMarker(
"Note that some extensions are I/O only and will not occupy any cartridge slot when inserted. "
517 "These can only be removed via the 'Media > Extensions > Remove' menu. "
518 "To insert (non I/O-only) extensions in a specific slot, use the 'Media > Cartridge Slot' menu.");
519 drawExtensionFilter();
526 float width = 40.0f * ImGui::GetFontSize();
527 float height = 10.25f * ImGui::GetTextLineHeightWithSpacing();
530 auto& ext = allExtensions[filteredExtensions[i]];
531 bool ok = getTestResult(ext).empty();
532 im::StyleColor(!ok, ImGuiCol_Text, getColor(imColor::ERROR), [&]{
533 if (ImGui::Selectable(ext.displayName.c_str())) {
534 group.edit.name = ext.configName;
535 insertMedia(mediaName, group.edit);
536 ImGui::CloseCurrentPopup();
538 extensionTooltip(ext);
544 showRecent(mediaName, group,
545 [
this](
const std::string& config) {
548 [
this](
const std::string& e) {
550 extensionTooltip(*info);
558 im::Menu(
"Remove", [&]{
560 for (const auto& ext : extensions) {
561 auto name = strCat(slotAndNameForHardwareConfig(slotManager, *ext),
"##", count++);
562 if (ImGui::Selectable(name.c_str())) {
563 manager.executeDelayed(makeTclList(
"remove_extension", ext->getName()));
565 if (auto* info = findExtensionInfo(ext->getConfigName())) {
566 extensionTooltip(*info);
577 bool anyDrive =
false;
579 if (!(*drivesInUse)[i])
continue;
581 auto displayName =
strCat(
"Disk Drive ",
char(
'A' + i));
582 ImGui::MenuItem(displayName.c_str(),
nullptr, &diskMediaInfo[i].show);
583 simpleToolTip([&] {
return displayNameForDriveContent(i); });
586 ImGui::TextDisabled(
"No disk drives present");
592 if (
auto* player = motherBoard->getCassettePort().getCassettePlayer()) {
593 ImGui::MenuItem(
"Tape Deck",
nullptr, &cassetteMediaInfo.show);
595 auto current = player->getImageName().getResolved();
596 return current.empty() ?
"Empty" : current;
599 ImGui::TextDisabled(
"No cassette port present");
605 std::string hdName =
"hdX";
607 if (!(*hdInUse)[i])
continue;
608 hdName.back() = char(
'a' + i);
609 auto displayName =
strCat(
"Hard Disk ",
char(
'A' + i));
610 if (
auto cmdResult = manager.execute(TclObject(hdName))) {
612 auto& group = hdMediaInfo[i];
614 auto currentImage = cmdResult->getListIndex(interp, 1);
615 showCurrent(currentImage,
"hard disk");
616 bool powered = motherBoard->isPowered();
617 im::Disabled(powered, [&]{
618 if (ImGui::MenuItem(
"Select hard disk image...")) {
619 manager.openFile->selectFile(
620 "Select image for " + displayName,
622 [this, &group, hdName](const auto& fn) {
623 group.edit.name = fn;
624 this->insertMedia(hdName, group.edit);
626 currentImage.getString());
630 HelpMarker(
"Hard disk image cannot be switched while the MSX is powered on.");
633 showRecent(hdName, group);
641 auto cdInUse = IDECDROM::getDrivesInUse(*motherBoard);
642 std::string cdName =
"cdX";
644 if (!(*cdInUse)[i])
continue;
645 cdName.back() = char(
'a' + i);
646 auto displayName =
strCat(
"CDROM Drive ",
char(
'A' + i));
647 if (
auto cmdResult = manager.execute(TclObject(cdName))) {
649 auto& group = cdMediaInfo[i];
651 auto currentImage = cmdResult->getListIndex(interp, 1);
652 showCurrent(currentImage,
"CDROM");
653 if (ImGui::MenuItem(
"Eject", nullptr, false, !currentImage.empty())) {
654 manager.executeDelayed(makeTclList(cdName,
"eject"));
656 if (ImGui::MenuItem(
"Insert CDROM image...")) {
657 manager.openFile->selectFile(
658 "Select CDROM image for " + displayName,
660 [
this, &group, cdName](
const auto& fn) {
661 group.edit.name = fn;
662 this->insertMedia(cdName, group.edit);
664 currentImage.getString());
666 showRecent(cdName, group);
673 if (
auto cmdResult = manager.execute(TclObject(
"laserdiscplayer"))) {
676 auto currentImage = cmdResult->getListIndex(interp, 1);
677 showCurrent(currentImage,
"laserdisc");
678 if (ImGui::MenuItem(
"eject",
nullptr,
false, !currentImage.empty())) {
679 manager.executeDelayed(
makeTclList(
"laserdiscplayer",
"eject"));
681 if (ImGui::MenuItem(
"Insert LaserDisc image...")) {
682 manager.openFile->selectFile(
683 "Select LaserDisc image",
684 buildFilter(
"LaserDisc images", std::array<std::string_view, 1>{
"ogv"}),
685 [
this](
const auto& fn) {
686 laserdiscMediaInfo.edit.name = fn;
687 this->insertMedia(
"laserdiscplayer", laserdiscMediaInfo.edit);
689 currentImage.getString());
691 showRecent(
"laserdiscplayer", laserdiscMediaInfo);
700 if (!motherBoard)
return;
702 auto drivesInUse = RealDrive::getDrivesInUse(*motherBoard);
703 for (
auto i :
xrange(RealDrive::MAX_DRIVES)) {
704 if (!(*drivesInUse)[i])
continue;
705 if (diskMediaInfo[i].show) {
711 for (
auto i :
xrange(CartridgeSlotManager::MAX_SLOTS)) {
712 if (!slotManager.slotExists(i))
continue;
713 if (cartridgeMediaInfo[i].show) {
718 if (cassetteMediaInfo.show) {
720 cassetteMenu(*player);
730static void printPatches(
const TclObject& patches)
732 if (!patches.empty()) {
735 for (
const auto& patch : patches) {
742static std::string leftClip(std::string_view s,
float maxWidth)
745 if (fullWidth <= maxWidth)
return std::string(s);
748 if (maxWidth <= 0.0f)
return "...";
753 return strCat(
"...", s.substr(len - num));
756bool ImGuiMedia::selectRecent(ItemGroup& group,
function_ref<std::string(
const std::string&)> displayFunc,
float width)
const
758 bool interacted =
false;
759 ImGui::SetNextItemWidth(-width);
760 const auto& style = ImGui::GetStyle();
761 auto textWidth = ImGui::GetContentRegionAvail().x - (3.0f * style.FramePadding.x + ImGui::GetFrameHeight() + width);
762 auto preview = leftClip(displayFunc(group.edit.name), textWidth);
763 im::Combo(
"##recent", preview.c_str(), [&]{
765 for (const auto& item : group.recent) {
766 auto d = strCat(display(item, displayFunc),
"##", count++);
767 if (ImGui::Selectable(d.c_str())) {
773 interacted |= ImGui::IsItemActive();
777static float calcButtonWidth(std::string_view text1,
const char* text2)
779 const auto& style = ImGui::GetStyle();
780 float width = style.ItemSpacing.x + 2.0f * style.FramePadding.x +
ImGui::CalcTextSize(text1).x;
787bool ImGuiMedia::selectImage(ItemGroup& group,
const std::string& title,
789 function_ref<std::string(
const std::string&)> displayFunc,
790 const std::function<
void()>& createNewCallback)
792 bool interacted =
false;
794 auto width = calcButtonWidth(ICON_IGFD_FOLDER_OPEN, createNewCallback ? ICON_IGFD_ADD : nullptr);
795 interacted |= selectRecent(group, displayFunc, width);
796 if (createNewCallback) {
798 if (ImGui::Button(ICON_IGFD_ADD)) {
805 if (ImGui::Button(ICON_IGFD_FOLDER_OPEN)) {
807 manager.openFile->selectFile(
810 [&](
const auto& fn) { group.edit.name = fn; },
818bool ImGuiMedia::selectDirectory(ItemGroup& group,
const std::string& title,
zstring_view current,
819 const std::function<
void()>& createNewCallback)
821 bool interacted =
false;
823 auto width = calcButtonWidth(ICON_IGFD_FOLDER_OPEN, createNewCallback ? ICON_IGFD_ADD : nullptr);
824 interacted |= selectRecent(group, std::identity{}, width);
825 if (createNewCallback) {
827 if (ImGui::Button(ICON_IGFD_ADD)) {
834 if (ImGui::Button(ICON_IGFD_FOLDER_OPEN)) {
836 manager.openFile->selectDirectory(
838 [&](
const auto& fn) { group.edit.name = fn; },
846bool ImGuiMedia::selectMapperType(
const char* label,
RomType& romType)
848 bool interacted =
false;
849 bool isAutoDetect = romType == RomType::UNKNOWN;
850 constexpr const char* autoStr =
"auto detect";
851 std::string current = isAutoDetect ? autoStr : std::string(RomInfo::romTypeToName(romType));
853 if (ImGui::Selectable(autoStr, isAutoDetect)) {
855 romType = RomType::UNKNOWN;
858 for (
const auto& romInfo : RomInfo::getRomTypeInfo()) {
859 bool selected = romType ==
static_cast<RomType>(count);
860 if (ImGui::Selectable(romInfo.name.c_str(), selected)) {
862 romType =
static_cast<RomType>(count);
868 interacted |= ImGui::IsItemActive();
872bool ImGuiMedia::selectPatches(MediaItem& item,
int& patchIndex)
874 bool interacted =
false;
875 std::string patchesTitle =
"IPS patches";
876 if (!item.ipsPatches.empty()) {
877 strAppend(patchesTitle,
" (", item.ipsPatches.size(),
')');
881 const auto& style = ImGui::GetStyle();
882 auto width = style.ItemSpacing.x + 2.0f * style.FramePadding.x + ImGui::CalcTextSize(
"Remove"sv).x;
883 ImGui::SetNextItemWidth(-width);
885 im::ListBox(
"##", [&]{
887 for (const auto& patch : item.ipsPatches) {
888 auto preview = leftClip(patch, ImGui::GetContentRegionAvail().x);
889 if (ImGui::Selectable(strCat(preview,
"##", count).c_str(), count == patchIndex)) {
899 if (ImGui::Button(
"Add")) {
901 manager.openFile->selectFile(
902 "Select disk IPS patch",
903 buildFilter(
"IPS patches", std::array<std::string_view, 1>{
"ips"}),
904 [&](
const std::string& ips) {
905 patchIndex = narrow<int>(item.ipsPatches.size());
906 item.ipsPatches.push_back(ips);
909 auto size = narrow<int>(item.ipsPatches.size());
910 im::Disabled(patchIndex < 0 || patchIndex >= size, [&] {
911 if (ImGui::Button(
"Remove")) {
913 item.ipsPatches.erase(item.ipsPatches.begin() + patchIndex);
916 if (ImGui::ArrowButton(
"up", ImGuiDir_Up)) {
917 std::swap(item.ipsPatches[patchIndex], item.ipsPatches[patchIndex - 1]);
922 if (ImGui::ArrowButton(
"down", ImGuiDir_Down)) {
923 std::swap(item.ipsPatches[patchIndex], item.ipsPatches[patchIndex + 1]);
933bool ImGuiMedia::insertMediaButton(std::string_view mediaName,
const ItemGroup& group,
bool* showWindow)
935 bool clicked =
false;
936 im::Disabled(group.edit.name.empty() && !group.edit.isEject(), [&]{
937 const auto& style = ImGui::GetStyle();
938 auto width = 4.0f * style.FramePadding.x + style.ItemSpacing.x +
939 ImGui::CalcTextSize(
"Apply"sv).x + ImGui::CalcTextSize(
"Ok"sv).x;
940 ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - width + style.WindowPadding.x);
941 clicked |= ImGui::Button(
"Apply");
943 if (ImGui::Button(
"Ok")) {
948 insertMedia(mediaName, group.edit);
954TclObject ImGuiMedia::showDiskInfo(std::string_view mediaName, DiskMediaInfo& info)
956 TclObject currentTarget;
957 auto cmdResult = manager.execute(
makeTclList(
"machine_info",
"media", mediaName));
958 if (!cmdResult)
return currentTarget;
960 using enum SelectDiskType;
961 auto selectType = [&]{
964 auto s = type->getString();
967 }
else if (s ==
"ramdsk") {
969 }
else if (s ==
"dirasdisk") {
976 std::string_view typeStr = [&]{
977 switch (selectType) {
978 case IMAGE:
return "Disk image:";
979 case DIR_AS_DISK:
return "Dir as disk:";
980 case RAMDISK:
return "RAM disk";
981 case EMPTY:
return "No disk inserted";
985 bool detailedInfo = selectType ==
one_of(DIR_AS_DISK, IMAGE);
986 auto currentPatches = getPatches(*cmdResult);
988 bool copyCurrent = ImGui::SmallButton(
"Current disk");
989 HelpMarker(
"Press to copy current disk to 'Select new disk' section.");
995 currentTarget = *target;
998 ImGui::GetContentRegionAvail().x));
1000 std::string statusLine;
1001 auto add = [&](std::string_view s) {
1002 if (statusLine.empty()) {
1009 if (ro->getOptionalBool().value_or(
false)) {
1014 add(doubleSided->getOptionalBool().value_or(
true) ?
"double-sided" :
"single-sided");
1017 add(
tmpStrCat(
size->getOptionalInt().value_or(0) / 1024,
"kB"));
1019 if (!statusLine.empty()) {
1022 printPatches(currentPatches);
1026 info.select = selectType;
1027 auto& edit = info.groups[selectType].edit;
1028 edit.name = currentTarget.getString();
1029 edit.ipsPatches = to_vector<std::string>(currentPatches);
1032 return currentTarget;
1035void ImGuiMedia::printDatabase(
const RomInfo& romInfo,
const char* buf)
1037 auto printRow = [](std::string_view description, std::string_view value) {
1038 if (value.empty())
return;
1039 if (ImGui::TableNextColumn()) {
1042 if (ImGui::TableNextColumn()) {
1047 printRow(
"Title", romInfo.
getTitle(buf));
1048 printRow(
"Year", romInfo.
getYear(buf));
1049 printRow(
"Company", romInfo.
getCompany(buf));
1050 printRow(
"Country", romInfo.
getCountry(buf));
1054 std::string result =
"Unmodified dump";
1056 strAppend(result,
" (confirmed by ", str,
')');
1060 return std::string(str);
1063 printRow(
"Status", status);
1064 printRow(
"Remark", romInfo.
getRemark(buf));
1070 ImGui::TableSetupColumn(
"description", ImGuiTableColumnFlags_WidthFixed);
1071 ImGui::TableSetupColumn(
"value", ImGuiTableColumnFlags_WidthStretch);
1073 if (ImGui::TableNextColumn()) {
1076 if (ImGui::TableNextColumn()) {
1081 const auto* romInfo = [&]() ->
const RomInfo* {
1083 if (
const auto* info = database.fetchRomInfo(Sha1Sum(actual->getString()))) {
1088 if (
const auto* info = database.fetchRomInfo(Sha1Sum(original->getString()))) {
1095 ImGuiMedia::printDatabase(*romInfo, database.getBufferStart());
1098 std::string mapperStr{RomInfo::romTypeToName(romType)};
1100 if (
auto dbType = romInfo->getRomType();
1101 dbType != RomType::UNKNOWN && dbType != romType) {
1102 strAppend(mapperStr,
" (database: ", RomInfo::romTypeToName(dbType),
')');
1105 if (ImGui::TableNextColumn()) {
1108 if (ImGui::TableNextColumn()) {
1114TclObject ImGuiMedia::showCartridgeInfo(std::string_view mediaName, CartridgeMediaInfo& info,
int slot)
1116 TclObject currentTarget;
1118 if (!cmdResult)
return currentTarget;
1120 using enum SelectCartridgeType;
1121 auto selectType = [&]{
1123 auto s = type->getString();
1124 if (s ==
"extension") {
1134 auto currentPatches = getPatches(*cmdResult);
1136 bool copyCurrent = ImGui::SmallButton(
"Current cartridge");
1141 RomType currentRomType = RomType::UNKNOWN;
1143 if (selectType == EMPTY) {
1146 currentTarget = *target;
1147 if (selectType == EXTENSION) {
1148 if (
auto* i = findExtensionInfo(target->getString())) {
1149 printExtensionInfo(*i);
1151 }
else if (selectType == IMAGE) {
1153 currentRomType = RomInfo::nameToRomType(mapper->getString());
1155 printRomInfo(manager, *cmdResult, target->getString(), currentRomType);
1156 printPatches(currentPatches);
1161 info.select = selectType;
1162 auto& edit = info.groups[selectType].edit;
1163 edit.name = currentTarget.getString();
1164 edit.ipsPatches = to_vector<std::string>(currentPatches);
1165 edit.romType = currentRomType;
1168 return currentTarget;
1171void ImGuiMedia::diskMenu(
int i)
1173 auto& info = diskMediaInfo[i];
1174 auto mediaName =
strCat(
"disk",
char(
'a' + i));
1175 auto displayName =
strCat(
"Disk Drive ",
char(
'A' + i));
1176 ImGui::SetNextWindowSize(
gl::vec2{29, 22} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
1177 im::Window(displayName.c_str(), &info.show, [&]{
1178 auto current = showDiskInfo(mediaName, info);
1179 im::Child(
"select", {0, -ImGui::GetFrameHeightWithSpacing()}, [&]{
1180 using enum SelectDiskType;
1181 ImGui::TextUnformatted(
"Select new disk"sv);
1183 ImGui::RadioButton(
"disk image", std::bit_cast<int*>(&info.select), to_underlying(IMAGE));
1184 im::VisuallyDisabled(info.select != IMAGE, [&]{
1186 auto& group = info.groups[IMAGE];
1187 auto createNew = [&]{
1188 manager.openFile->selectNewFile(
1189 "Select name for new blank disk image",
1190 "Disk images (*.dsk){.dsk}",
1191 [&](const auto& fn) {
1192 group.edit.name = fn;
1193 auto& diskManipulator = manager.getReactor().getDiskManipulator();
1195 diskManipulator.create(fn, MSXBootSectorType::DOS2, {1440});
1196 } catch (MSXException& e) {
1197 manager.printError(
"Couldn't create new disk image: ", e.getMessage());
1200 current.getString());
1202 bool interacted = selectImage(
1203 group, strCat(
"Select disk image for ", displayName), &diskFilter,
1204 current.getString(), std::identity{}, createNew);
1205 interacted |= selectPatches(group.edit, group.patchIndex);
1206 if (interacted) info.select = IMAGE;
1209 ImGui::RadioButton(
"dir as disk", std::bit_cast<int*>(&info.select),
to_underlying(DIR_AS_DISK));
1212 auto& group = info.groups[DIR_AS_DISK];
1213 auto createNew = [&]{
1214 manager.openFile->selectNewFile(
1215 "Select name for new empty directory",
1217 [&](const auto& fn) {
1218 group.edit.name = fn;
1220 FileOperations::mkdirp(fn);
1221 } catch (MSXException& e) {
1222 manager.printError(
"Couldn't create directory: ", e.getMessage());
1225 current.getString());
1227 bool interacted = selectDirectory(
1228 group, strCat(
"Select directory for ", displayName),
1229 current.getString(), createNew);
1230 if (interacted) info.select = DIR_AS_DISK;
1233 ImGui::RadioButton(
"RAM disk", std::bit_cast<int*>(&info.select),
to_underlying(RAMDISK));
1234 if (!current.
empty()) {
1235 ImGui::RadioButton(
"Eject", std::bit_cast<int*>(&info.select),
to_underlying(EMPTY));
1238 insertMediaButton(mediaName, info.groups[info.select], &info.show);
1242void ImGuiMedia::cartridgeMenu(
int cartNum)
1244 auto& info = cartridgeMediaInfo[cartNum];
1245 auto displayName =
strCat(
"Cartridge Slot ",
char(
'A' + cartNum));
1246 ImGui::SetNextWindowSize(
gl::vec2{37, 30} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
1247 im::Window(displayName.c_str(), &info.show, [&]{
1248 using enum SelectCartridgeType;
1249 auto cartName = strCat(
"cart", char(
'a' + cartNum));
1250 auto extName = strCat(
"ext", char(
'a' + cartNum));
1252 auto current = showCartridgeInfo(cartName, info, cartNum);
1254 im::Child(
"select", {0, -ImGui::GetFrameHeightWithSpacing()}, [&]{
1255 ImGui::TextUnformatted(
"Select new cartridge:"sv);
1257 ImGui::RadioButton(
"ROM image", std::bit_cast<int*>(&info.select), to_underlying(IMAGE));
1258 im::VisuallyDisabled(info.select != IMAGE, [&]{
1260 auto& group = info.groups[IMAGE];
1261 auto& item = group.edit;
1262 bool interacted = selectImage(
1263 group, strCat(
"Select ROM image for ", displayName), &romFilter, current.getString());
1265 const auto& style = ImGui::GetStyle();
1266 ImGui::SetNextItemWidth(-(ImGui::CalcTextSize(
"mapper-type").x + style.ItemInnerSpacing.x));
1267 interacted |= selectMapperType(
"mapper-type", item.romType);
1268 interacted |= selectPatches(item, group.patchIndex);
1269 if (interacted) info.select = IMAGE;
1272 ImGui::RadioButton(
"extension", std::bit_cast<int*>(&info.select),
to_underlying(EXTENSION));
1275 auto& allExtensions = getAllExtensions();
1276 auto& group = info.groups[EXTENSION];
1277 auto& item = group.edit;
1279 bool interacted = drawExtensionFilter();
1281 auto drawExtensions = [&]{
1282 auto filteredExtensions = to_vector(xrange(allExtensions.size()));
1283 applyComboFilter(
"Type", filterType, allExtensions, filteredExtensions);
1284 applyDisplayNameFilter(filterString, allExtensions, filteredExtensions);
1286 im::ListClipper(filteredExtensions.size(), [&](int i) {
1287 auto& ext = allExtensions[filteredExtensions[i]];
1288 bool ok = getTestResult(ext).empty();
1289 im::StyleColor(!ok, ImGuiCol_Text, getColor(imColor::ERROR), [&]{
1290 if (ImGui::Selectable(ext.displayName.c_str(), item.name == ext.configName)) {
1292 item.name = ext.configName;
1294 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
1295 insertMedia(extName, group.edit);
1297 extensionTooltip(ext);
1302 im::ListBox(
"##list", [&]{
1306 im::Combo(
"##extension", displayNameForExtension(item.name).c_str(), [&]{
1311 interacted |= ImGui::IsItemActive();
1312 if (interacted) info.select = EXTENSION;
1315 if (!current.
empty()) {
1316 ImGui::RadioButton(
"Eject", std::bit_cast<int*>(&info.select),
to_underlying(EMPTY));
1318 ImGui::Checkbox(
"Reset MSX on changes", &resetOnCartChanges);
1320 if (insertMediaButton(info.select == EXTENSION ? extName : cartName,
1321 info.groups[info.select], &info.show)) {
1322 if (resetOnCartChanges) {
1329static void RenderPlay(
gl::vec2 center, ImDrawList* drawList)
1331 float half = 0.4f * ImGui::GetTextLineHeight();
1332 auto p1 = center +
gl::vec2(half, 0.0f);
1333 auto p2 = center +
gl::vec2(-half, half);
1335 drawList->AddTriangleFilled(p1, p2,
p3,
getColor(imColor::TEXT));
1337static void RenderRewind(
gl::vec2 center, ImDrawList* drawList)
1339 float size = 0.8f * ImGui::GetTextLineHeight();
1340 float half =
size * 0.5f;
1341 auto color =
getColor(imColor::TEXT);
1342 auto p1 = center +
gl::vec2(-size, 0.0f);
1343 auto p2 = center +
gl::vec2(0.0f, -half);
1345 drawList->AddTriangleFilled(p1, p2,
p3, color);
1350 drawList->AddTriangleFilled(p1, p2,
p3, color);
1352static void RenderStop(
gl::vec2 center, ImDrawList* drawList)
1354 gl::vec2 half{0.4f * ImGui::GetTextLineHeight()};
1355 drawList->AddRectFilled(center - half, center + half,
getColor(imColor::TEXT));
1357static void RenderRecord(
gl::vec2 center, ImDrawList* drawList)
1359 float radius = 0.4f * ImGui::GetTextLineHeight();
1360 drawList->AddCircleFilled(center, radius,
getColor(imColor::TEXT));
1364void ImGuiMedia::cassetteMenu(CassettePlayer& cassettePlayer)
1366 ImGui::SetNextWindowSize(
gl::vec2{29, 21} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
1367 auto& info = cassetteMediaInfo;
1368 auto& group = info.group;
1370 ImGui::TextUnformatted(
"Current tape"sv);
1371 auto current = cassettePlayer.getImageName().getResolved();
1373 if (current.empty()) {
1374 ImGui::TextUnformatted(
"No tape inserted"sv);
1376 ImGui::TextUnformatted(
"Tape image:"sv);
1378 ImGui::TextUnformatted(leftClip(current, ImGui::GetContentRegionAvail().x));
1382 if (ImGui::Button(
"Eject")) {
1383 manager.executeDelayed(makeTclList(
"cassetteplayer",
"eject"));
1390 auto status = cassettePlayer.getState();
1391 auto size = ImGui::GetFrameHeightWithSpacing();
1406 "Select new wav file for record",
1407 "Tape images (*.wav){.wav}",
1408 [&](
const auto& fn) {
1409 group.edit.name = fn;
1411 [&group](
const TclObject&) {
1419 const auto& style = ImGui::GetStyle();
1420 ImGui::SameLine(0.0f, 3.0f * style.ItemSpacing.x);
1424 auto length = cassettePlayer.getTapeLength(now);
1425 auto pos = cassettePlayer.getTapePos(now);
1426 auto format = [](
double time) {
1427 int t = narrow_cast<int>(time);
1428 int s =
t % 60;
t /= 60;
1429 int m =
t % 60;
t /= 60;
1430 std::ostringstream os;
1431 os << std::setfill(
'0');
1432 if (
t) os << std::setw(2) <<
t <<
':';
1433 os << std::setw(2) << m <<
':';
1434 os << std::setw(2) << s;
1437 auto parse = [](std::string_view str) -> std::optional<unsigned> {
1439 auto s = StringOp::stringTo<unsigned>(seconds);
1441 unsigned result = *s;
1443 if (!head.empty()) {
1445 auto m = StringOp::stringTo<unsigned>(minutes);
1449 if (!hours.empty()) {
1450 auto h = StringOp::stringTo<unsigned>(hours);
1452 result += *h * 60 * 60;
1457 auto posStr =
format(pos);
1458 ImGui::SetNextItemWidth(
ImGui::CalcTextSize(std::string_view(posStr)).x + 2.0f * style.FramePadding.x);
1459 if (ImGui::InputText(
"##pos", &posStr, ImGuiInputTextFlags_EnterReturnsTrue)) {
1460 if (
auto newPos =
parse(posStr)) {
1464 simpleToolTip(
"Indicates the current position of the tape, but can be edited to change the position manual (like fast forward)");
1467 ImGui::Text(
"/ %s",
format(length).c_str());
1469 const auto& controller = motherBoard->getMSXCommandController();
1470 const auto& hotKey = reactor.getHotKey();
1471 if (
auto* autoRun =
dynamic_cast<BooleanSetting*
>(controller.findSetting(
"autoruncassettes"))) {
1472 Checkbox(hotKey,
"(try to) Auto Run", *autoRun);
1474 if (
auto* mute =
dynamic_cast<BooleanSetting*
>(controller.findSetting(
"cassetteplayer_ch1_mute"))) {
1475 Checkbox(hotKey,
"Mute tape audio", *mute, [](
const Setting&) {
return std::string{}; });
1477 bool enabled = cassettePlayer.isMotorControlEnabled();
1478 bool changed = ImGui::Checkbox(
"Motor control enabled", &enabled);
1480 manager.
execute(
makeTclList(
"cassetteplayer",
"motorcontrol", enabled ?
"on" :
"off"));
1482 simpleToolTip(
"Enable or disable motor control. Disable in some rare cases where you don't want the motor of the player to be controlled by the MSX, e.g. for CD-Sequential.");
1487 im::Child(
"select", {0, -ImGui::GetFrameHeightWithSpacing()}, [&]{
1490 selectImage(group,
"Select tape image", &cassetteFilter, current);
1493 insertMediaButton(
"cassetteplayer", group, &info.show);
1497void ImGuiMedia::insertMedia(std::string_view mediaName,
const MediaItem& item)
1500 if (item.isEject()) {
1501 cmd.addListElement(
"eject");
1503 if (item.name.empty())
return;
1504 cmd.addListElement(
"insert", item.name);
1505 for (
const auto& patch : item.ipsPatches) {
1506 cmd.addListElement(
"-ips", patch);
1508 if (item.romType != RomType::UNKNOWN) {
1509 cmd.addListElement(
"-romtype", RomInfo::romTypeToName(item.romType));
1513 [
this, cmd](
const TclObject&) {
1521 auto n = cmd.
size();
1527 if (mediaName.starts_with(
"cart")) {
1528 if (
int i = mediaName[4] -
'a'; 0 <= i && i < int(CartridgeSlotManager::MAX_SLOTS)) {
1529 return &cartridgeMediaInfo[i].groups[SelectCartridgeType::IMAGE];
1531 }
else if (mediaName.starts_with(
"disk")) {
1532 if (
int i = mediaName[4] -
'a'; 0 <= i && i < int(RealDrive::MAX_DRIVES)) {
1533 return &diskMediaInfo[i].groups[SelectDiskType::IMAGE];
1535 }
else if (mediaName.starts_with(
"hd")) {
1536 if (
int i = mediaName[2] -
'a'; 0 <= i && i < int(HD::MAX_HD)) {
1537 return &hdMediaInfo[i];
1539 }
else if (mediaName.starts_with(
"cd")) {
1540 if (
int i = mediaName[2] -
'a'; 0 <= i && i < int(IDECDROM::MAX_CD)) {
1541 return &cdMediaInfo[i];
1543 }
else if (mediaName ==
"cassetteplayer") {
1544 return &cassetteMediaInfo.group;
1545 }
else if (mediaName ==
"laserdiscplayer") {
1546 return &laserdiscMediaInfo;
1547 }
else if (mediaName ==
"ext") {
1548 return &extensionMediaInfo;
1550 return static_cast<ItemGroup*
>(
nullptr);
1560 if (option ==
"-ips" && i < n) {
1564 if (option ==
"-romtype" && i < n) {
void test(const IterableBitSet< N > &s, std::initializer_list< size_t > list)
static constexpr unsigned MAX_SLOTS
std::pair< int, int > getPsSs(unsigned slot) const
std::optional< unsigned > findSlotWith(const HardwareConfig &config) const
std::string getPsSsString(unsigned slot) const
const HardwareConfig * getConfigForSlot(unsigned slot) const
static std::span< const std::string_view > getExtensions()
virtual CassettePlayer * getCassettePlayer()=0
Get the cassette player (if available)
static std::span< const std::string_view > getExtensions()
static std::shared_ptr< HDInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
const std::string & getConfigName() const
std::string_view getRomFilename() const
std::optional< TclObject > execute(TclObject command)
Interpreter & getInterpreter()
std::unique_ptr< ImGuiOpenFile > openFile
void executeDelayed(std::function< void()> action)
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
CartridgeSlotManager & getSlotManager()
const Extensions & getExtensions() const
CassettePortInterface & getCassettePort()
static std::span< const std::string_view > getExtensions()
MSXMotherBoard * getMotherBoard() const
RomDatabase & getSoftwareDatabase()
This class implements a real drive, single or double sided.
static std::shared_ptr< DrivesInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
std::string_view getYear(const char *buf) const
std::string_view getTitle(const char *buf) const
static zstring_view romTypeToName(RomType type)
std::string_view getCompany(const char *buf) const
std::string_view getRemark(const char *buf) const
std::string_view getCountry(const char *buf) const
static RomType nameToRomType(std::string_view name)
std::string_view getOrigType(const char *buf) const
TclObject getListIndexUnchecked(unsigned index) const
std::optional< TclObject > getOptionalDictValue(const TclObject &key) const
zstring_view getString() const
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr auto empty() const
mat3 p3(vec3(1, 2, 3), vec3(4, 5, 6), vec3(7, 0, 9))
detail::Joiner< Collection, Separator > join(Collection &&col, Separator &&sep)
auto CalcTextSize(std::string_view str)
void TextUnformatted(const std::string &str)
bool stringToBool(string_view str)
std::pair< string_view, string_view > splitOnLast(string_view str, string_view chars)
T length(const vecN< N, T > &x)
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 VisuallyDisabled(bool b, std::invocable<> auto next)
void ID(const char *str_id, std::invocable<> auto next)
bool TreeNode(const char *label, ImGuiTreeNodeFlags flags, std::invocable<> auto next)
void Combo(const char *label, const char *preview_value, ImGuiComboFlags flags, std::invocable<> auto next)
void ListBox(const char *label, const ImVec2 &size, 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 TextWrapPos(float wrap_local_pos_x, 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 Indent(float indent_w, std::invocable<> auto next)
void ListClipper(size_t count, int forceIndex, float lineHeight, std::invocable< int > auto next)
void ItemTooltip(std::invocable<> auto next)
void format(SectorAccessibleDisk &disk, MSXBootSectorType bootType)
Format the given disk (= a single partition).
string_view getFilename(string_view path)
Returns the file portion of a path name.
This file implemented 3 utility functions:
bool Checkbox(const HotKey &hotKey, BooleanSetting &setting)
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void applyComboFilter(std::string_view key, std::string_view value, const std::vector< T > &items, std::vector< size_t > &indices)
void addRecentItem(circular_buffer< T > &recentItems, const T &item)
void simpleToolTip(std::string_view desc)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
void HelpMarker(std::string_view desc)
ImU32 getColor(imColor col)
void applyDisplayNameFilter(std::string_view filterString, const std::vector< T > &items, std::vector< size_t > &indices)
TclObject makeTclList(Args &&... args)
bool ButtonWithCustomRendering(const char *label, gl::vec2 size, bool pressed, std::invocable< gl::vec2, ImDrawList * > auto render)
auto find(InputRange &&range, const T &value)
auto lower_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
void parse(HANDLER &handler, char *xml)
size_t size(std::string_view utf8)
constexpr auto transform(Range &&range, UnaryOp op)
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))> >
constexpr auto to_underlying(E e) noexcept
TemporaryString tmpStrCat(Ts &&... ts)
void strAppend(std::string &result, Ts &&...ts)
constexpr auto xrange(T e)