From 25dc50d83cea22d68332e6538e8bb6ceaeb0f3b3 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Thu, 1 Apr 2021 16:04:50 +0100 Subject: [PATCH] Add settings / diagnostics about disks. Signed-off-by: Andrea Odetti --- source/frontends/sdl/imgui/sdlsettings.cpp | 75 +++++++++++++++++----- source/frontends/sdl/sdlframe.cpp | 43 +++++++++++-- source/frontends/sdl/sdlframe.h | 6 ++ 3 files changed, 101 insertions(+), 23 deletions(-) diff --git a/source/frontends/sdl/imgui/sdlsettings.cpp b/source/frontends/sdl/imgui/sdlsettings.cpp index b113977a..9034f229 100644 --- a/source/frontends/sdl/imgui/sdlsettings.cpp +++ b/source/frontends/sdl/imgui/sdlsettings.cpp @@ -250,7 +250,7 @@ namespace sa2 CardManager & manager = GetCardMgr(); for (size_t slot = 1; slot < 8; ++slot) { - const SS_CARDTYPE current = manager.QuerySlot(slot);; + const SS_CARDTYPE current = manager.QuerySlot(slot); if (ImGui::BeginCombo(std::to_string(slot).c_str(), getCardName(current).c_str())) { const std::vector & cards = getCardsForSlot(slot); @@ -299,8 +299,12 @@ namespace sa2 if (ImGui::BeginTabItem("Disks")) { + size_t dragAndDropSlot; + size_t dragAndDropDrive; + frame->getDragDropSlotAndDrive(dragAndDropSlot, dragAndDropDrive); + CardManager & cardManager = GetCardMgr(); - if (ImGui::BeginTable("Disk2", 11, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) + if (ImGui::BeginTable("Disk2", 12, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) { ImGui::TableSetupColumn("Slot", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("Drive", ImGuiTableColumnFlags_WidthFixed); @@ -311,6 +315,7 @@ namespace sa2 ImGui::TableSetupColumn("Status", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("Eject", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("Swap", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("D&D", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("Filename", ImGuiTableColumnFlags_WidthStretch); ImGui::TableHeadersRow(); @@ -326,7 +331,7 @@ namespace sa2 card2->GetLightStatus(statuses + 0, statuses + 1); const UINT firmware = card2->GetCurrentFirmware(); - for (size_t drive = 0; drive < NUM_DRIVES; ++drive) + for (size_t drive = DRIVE_1; drive < NUM_DRIVES; ++drive) { ImGui::PushID(drive); ImGui::TableNextRow(); @@ -363,6 +368,12 @@ namespace sa2 card2->DriveSwap(); } + ImGui::TableNextColumn(); + if (ImGui::RadioButton("", (dragAndDropSlot == slot) && (dragAndDropDrive == drive))) + { + frame->setDragDropSlotAndDrive(slot, drive); + } + ImGui::TableNextColumn(); ImGui::TextUnformatted(card2->GetFullDiskFilename(drive).c_str()); ImGui::PopID(); @@ -370,22 +381,52 @@ namespace sa2 } ImGui::PopID(); } + + if (HD_CardIsEnabled()) + { + ImGui::PushID(7); + Disk_Status_e disk1Status_; + HD_GetLightStatus(&disk1Status_); + for (size_t drive = HARDDISK_1; drive < NUM_HARDDISKS; ++drive) + { + ImGui::PushID(drive); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("%d", SLOT7); + ImGui::TableNextColumn(); + ImGui::Text("%d", drive + 1); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("HD"); + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + + ImGui::Text("%d", disk1Status_); + ImGui::TableNextColumn(); + if (ImGui::SmallButton("Eject")) + { + HD_Unplug(drive); + } + ImGui::TableNextColumn(); + if (ImGui::SmallButton("Swap")) + { + HD_ImageSwap(); + } + ImGui::TableNextColumn(); + if (ImGui::RadioButton("", (dragAndDropSlot == SLOT7) && (dragAndDropDrive == drive))) + { + frame->setDragDropSlotAndDrive(SLOT7, drive); + } + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(HD_GetFullName(drive).c_str()); + ImGui::PopID(); + } + ImGui::PopID(); + } ImGui::EndTable(); } - - bool hdEnabled = HD_CardIsEnabled(); - if (ImGui::Checkbox("HD card", &hdEnabled)) - { - HD_SetEnabled(hdEnabled); - } - ImGui::Button("Hard disk 1"); - ImGui::SameLine(); - ImGui::TextUnformatted(HD_GetFullName(HARDDISK_1).c_str()); - - ImGui::Button("Hard disk 2"); - ImGui::SameLine(); - ImGui::TextUnformatted(HD_GetFullName(HARDDISK_2).c_str()); - ImGui::EndTabItem(); } diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index 3b3792a0..6888b669 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -124,6 +124,8 @@ namespace sa2 , myMultiplier(1) , myFullscreen(false) , mySpeed(options.fixedSpeed) + , myDragAndDropSlot(SLOT6) + , myDragAndDropDrive(DRIVE_1) { } @@ -264,14 +266,31 @@ namespace sa2 else { CardManager & cardManager = GetCardMgr(); - if (cardManager.QuerySlot(SLOT6) == CT_Disk2) + SS_CARDTYPE cardInSlot = cardManager.QuerySlot(myDragAndDropSlot); + switch (cardInSlot) { - // for now we insert in DRIVE_1 - Disk2InterfaceCard * card2 = dynamic_cast(cardManager.GetObj(SLOT6)); - const ImageError_e error = card2->InsertDisk(DRIVE_1, drop.file, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); - if (error != eIMAGE_ERROR_NONE) + case CT_Disk2: { - card2->NotifyInvalidImage(DRIVE_1, drop.file, error); + // for now we insert in DRIVE_1 + Disk2InterfaceCard * card2 = dynamic_cast(cardManager.GetObj(myDragAndDropSlot)); + const ImageError_e error = card2->InsertDisk(myDragAndDropDrive, drop.file, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + if (error != eIMAGE_ERROR_NONE) + { + card2->NotifyInvalidImage(myDragAndDropDrive, drop.file, error); + } + break; + } + case CT_GenericHDD: + { + if (!HD_Insert(myDragAndDropDrive, drop.file)) + { + FrameMessageBox("Invalid HD image", "ERROR", MB_OK); + } + break; + } + default: + { + FrameMessageBox("Invalid D&D target", "ERROR", MB_OK); } } } @@ -476,4 +495,16 @@ namespace sa2 } } + void SDLFrame::getDragDropSlotAndDrive(size_t & slot, size_t & drive) const + { + slot = myDragAndDropSlot; + drive = myDragAndDropDrive; + } + + void SDLFrame::setDragDropSlotAndDrive(const size_t slot, const size_t drive) + { + myDragAndDropSlot = slot; + myDragAndDropDrive = drive; + } + } diff --git a/source/frontends/sdl/sdlframe.h b/source/frontends/sdl/sdlframe.h index 9be7ed91..4397d1d8 100644 --- a/source/frontends/sdl/sdlframe.h +++ b/source/frontends/sdl/sdlframe.h @@ -36,6 +36,9 @@ namespace sa2 const std::shared_ptr & GetWindow() const; + void getDragDropSlotAndDrive(size_t & slot, size_t & drive) const; + void setDragDropSlotAndDrive(const size_t slot, const size_t drive); + protected: void SetApplicationIcon(); @@ -52,6 +55,9 @@ namespace sa2 int myMultiplier; bool myFullscreen; + size_t myDragAndDropSlot; + size_t myDragAndDropDrive; + common2::Speed mySpeed; };