--- nono/wx/wxstatuspanel.cpp 2026/04/29 17:05:08 1.1.1.4 +++ nono/wx/wxstatuspanel.cpp 2026/04/29 17:05:16 1.1.1.6 @@ -24,13 +24,12 @@ #include "wxmainview.h" #include "wxuimessage.h" #include "wxversion.h" -#include "ethernet.h" +#include "fdc.h" #include "hostnet.h" +#include "newsctlr.h" #include "power.h" #include "spc.h" -#include "sync.h" - -WXStatusPanel *gStatusPanel; +#include "syncer.h" wxBEGIN_EVENT_TABLE(WXStatusPanel, inherited) EVT_CLOSE(WXStatusPanel::OnClose) @@ -50,7 +49,8 @@ static const long STATUS_PANEL_STYLE = 0 // コンストラクタ WXStatusPanel::WXStatusPanel(wxWindow *parent) - : inherited(parent, wxDefaultSize, STATUS_PANEL_STYLE) + : inherited(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, + STATUS_PANEL_STYLE) { timer.SetOwner(this); @@ -65,14 +65,20 @@ WXStatusPanel::WXStatusPanel(wxWindow *p // 分かりづらくて、こっちがフォーカス持ってしまうと (というか起動後は // こっちにある) VM にキー入力が出来ずに焦ることになるので、ここへの // キー入力イベントは全部メインビューに飛ばす。 + auto mainframe = dynamic_cast(GetParent()); + auto mainview = mainframe->GetMainView(); Connect(wxEVT_KEY_UP, wxKeyEventHandler(WXMainView::OnKeyUp), NULL, - gMainView); + mainview); Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(WXMainView::OnKeyDown), NULL, - gMainView); + mainview); - // VM からのメディア変更通知を受け取る + // VM からの通知を受け取る WXUIMessage::Connect(UIMessage::SCSI_MEDIA_CHANGE, this, wxCommandEventHandler(WXStatusPanel::OnSCSIMediaChanged)); + WXUIMessage::Connect(UIMessage::FDD_MEDIA_CHANGE, this, + wxCommandEventHandler(WXStatusPanel::OnFDDMediaChanged)); + WXUIMessage::Connect(UIMessage::LED, this, + wxCommandEventHandler(WXStatusPanel::OnLEDChanged)); } // デストラクタ @@ -83,8 +89,13 @@ WXStatusPanel::~WXStatusPanel() indicators.pop_back(); delete ind; } - WXUIMessage::Disconnect(UIMessage::SCSI_MEDIA_CHANGE, + + WXUIMessage::Disconnect(UIMessage::SCSI_MEDIA_CHANGE, this, wxCommandEventHandler(WXStatusPanel::OnSCSIMediaChanged)); + WXUIMessage::Disconnect(UIMessage::FDD_MEDIA_CHANGE, this, + wxCommandEventHandler(WXStatusPanel::OnFDDMediaChanged)); + WXUIMessage::Disconnect(UIMessage::LED, this, + wxCommandEventHandler(WXStatusPanel::OnLEDChanged)); } // クローズイベント @@ -124,6 +135,23 @@ WXStatusPanel::FontChanged() { inherited::FontChanged(); + // アクセスマークをサイズに応じて作り直す + const uint8 *src; + switch (font_height) { + case 12: + src = AccessMark12; + break; + case 16: + src = AccessMark16; + break; + case 24: + src = AccessMark24; + break; + default: + PANIC("Unexpected font_height=%d", font_height); + } + accmark.reset(new BitmapI8(src, font_height, font_height)); + // インジケータを再レイアウト LayoutIndicators(); @@ -137,8 +165,8 @@ WXStatusPanel::FontChanged() void WXStatusPanel::OnSize(wxSizeEvent& event) { - // Mac ではウィンドウ作成時に 0 以下の値が来ることがある - // GTK では 1 で来ることがある + // Mac ではウィンドウ作成時に 0 以下の値が来ることがある。 + // GTK では 1 で来ることがある。 const wxSize& size = event.GetSize(); if (size.x <= 1 || size.y <= 1) { return; @@ -171,68 +199,99 @@ static const std::vector data = { void WXStatusPanel::InitIndicators() { - // パフォーマンスカウンタ - Indicator *perf = new Indicator(">>>9999%", &WXStatusPanel::DrawPerf); - perf->dclick = &WXStatusPanel::DClickPerf; - indicators.emplace_back(perf); + Indicator *ind; - // FD + // パフォーマンスカウンタ + syncer = GetSyncer(); + ind = new Indicator(Indicator::PERF, 8/* >>>9999% */, + &WXStatusPanel::DrawPerf); + ind->dclick = &WXStatusPanel::DClickPerf; + indicators.emplace_back(ind); // SCSI // SPC の接続済みデバイスリストから取得。 // (ホストアダプタ2つ目のことは考えてない) - const std::vector& conn = gSPC->GetConnectedDevices(); - for (const auto& dev : conn) { - SCSI::DevType devtype = dev->GetDevType(); - if (devtype == SCSI::DevType::Initiator) { - continue; - } - int id = dev->GetMyID(); - - SCSIIndicator *si = new SCSIIndicator(); - si->text = string_format("%s%d", SCSI::GetDevTypeName(devtype), id); - // 書き込み無視だけ、これによって shutdown が必要かどうかという - // オペレーションに違いが出るため表示する。 - // MO (と FD の) ライトプロテクト表示は必要になったら考える…。 - const SCSIDisk *disk = dynamic_cast(dev); - assert(disk); - if (disk->GetWriteMode() == SCSIDisk::RW::WriteIgnore) { - si->text += "\x02\x03"; - } - si->draw = &WXStatusPanel::DrawSCSI; - si->id = id; - si->dev = dev; - si->contextmenu = &WXStatusPanel::ContextMenuCD; - si->panel = new wxPanel(this); - // このパネルがフォーカスを受け取らないようにする。 - // StatusPanel がフォーカスを持っていてもキー入力を MainFrame に渡す - // ようにしているため、StatusPanel のフォーカスを奪ってはいけない。 - si->panel->SetCanFocus(false); + auto spc = gMainApp.FindObject(OBJ_SPC); + if (spc) { + const std::vector& conn = spc->GetConnectedDevices(); + for (const auto& dev : conn) { + SCSI::DevType devtype = dev->GetDevType(); + if (devtype == SCSI::DevType::Initiator) { + continue; + } + int scsiid = dev->GetMyID(); + + // 文字列は OnSCSIMediaChanged() でセットする。 + ind = new Indicator(Indicator::SCSI0 + scsiid, 3, + &WXStatusPanel::DrawSCSI); + ind->contextmenu = &WXStatusPanel::ContextMenuCD; + ind->dev = dev; + ind->panel = new wxPanel(this); + // このパネルがフォーカスを受け取らないようにする。 + // StatusPanel がフォーカスを持っていてもキー入力を MainFrame に渡す + // ようにしているため、StatusPanel のフォーカスを奪ってはいけない。 + ind->panel->SetCanFocus(false); - indicators.emplace_back(si); + indicators.emplace_back(ind); + } + // BSY 取得用 + scsibus = spc->GetSCSIBus(); } - // BSY 取得用 - scsibus = gSPC->GetSCSIBus(); // ネットワーク - if (gEthernet) { - hostnet = gEthernet->GetHostNet(); - assert(hostnet); + hostnet = gMainApp.FindObject(OBJ_HOSTNET); + if (hostnet) { if (hostnet->GetDriverName() == "none") { net_ok = DISABLE; } else { net_ok = ENABLE; } // \x1e は上向き矢印、\x1f は下向き矢印 - Indicator *net = new Indicator("LAN\x1e\x1f", &WXStatusPanel::DrawNet); - indicators.emplace_back(net); + ind = new Indicator(Indicator::LAN, 5, + &WXStatusPanel::DrawNet, "LAN\x1e\x1f"); + indicators.emplace_back(ind); } else { net_ok = NOT_AVAILABLE; } - // 電源 LED。点灯ロジックが分からないのでハリボテ。 - Indicator *power = new Indicator("POWER", &WXStatusPanel::DrawPower); - indicators.emplace_back(power); + // FD + for (int unit = 0; unit < FDCDevice::MAX_DRIVE; unit++) { + auto fdd = gMainApp.FindObject(OBJ_FDD(unit)); + if (fdd) { + // 存在するドライブのリスト + fdd_vector.push_back(fdd); + + // 文字列は OnFDDMediaChanged() でセットする。 + ind = new Indicator(Indicator::FDD0 + unit, 7, + &WXStatusPanel::DrawFD); + + ind->contextmenu = &WXStatusPanel::ContextMenuFD; + ind->dev = fdd; + ind->panel = new wxPanel(this); + // フォーカスを受け取らない。少し上の CD のところ参照。 + ind->panel->SetCanFocus(false); + + indicators.emplace_back(ind); + } + } + + // NEWS の LED (2->1 の順で並べる) + newsctlr = gMainApp.FindObject(OBJ_NEWSCTLR); + if (newsctlr) { + ind = new Indicator(Indicator::NEWSLED2, 2, + &WXStatusPanel::DrawNewsLED2, "LED2"); + indicators.emplace_back(ind); + + ind = new Indicator(Indicator::NEWSLED1, 2, + &WXStatusPanel::DrawNewsLED1, "LED1"); + indicators.emplace_back(ind); + } + + // 電源 LED + power = GetPowerDevice(); + ind = new Indicator(Indicator::POWER, 5, + &WXStatusPanel::DrawPower, "POWER"); + indicators.emplace_back(ind); // テスト用 if (__predict_false(0||(bool)*gHostInfo)) { @@ -273,7 +332,8 @@ WXStatusPanel::LayoutIndicators() x += 1; // 4 は、左右の外枠(1*2) と 枠と文字の間(1*2) - w = ind->text.length() * font_width + 2 + 2; + int len = std::max(ind->minlen, (int)ind->text.length()); + w = len * font_width + 2 + 2; ind->rect = Rect(x, y, w, h); x += w; @@ -304,12 +364,13 @@ WXStatusPanel::LayoutIndicators() // パネルをもっていれば、パネルをその位置に(再)設定。 for (auto ind : indicators) { - auto si = dynamic_cast(ind); - if (si && si->panel) { + if (ind->panel) { const auto& rect = ind->rect; - si->panel->SetSize(rect.x, rect.y, rect.w, rect.h); + ind->panel->SetSize(rect.x, rect.y, rect.w, rect.h); } } + + refresh_background = true; } // 状態をチェック。 @@ -329,20 +390,21 @@ WXStatusPanel::UpdateStat() }; // 電源オンか - MODIFY(ispower, gPower->IsPower()); + MODIFY(ispower, power->IsPower()); + MODIFY(powerled, power->GetPowerLED()); // パフォーマンスカウンタ - MODIFY(perf_mode, gSync->GetRunMode()); - MODIFY(perf_rate, gSync->GetPerfCounter()); - - // FD + MODIFY(perf_mode, syncer->GetRunMode()); + MODIFY(perf_rate, syncer->GetPerfCounter()); // SCSI アクセス - MODIFY(scsi_bsy, scsibus->GetBSY()); - // 転送フェーズで DataOut の時だけ書き込みとみなす - bool out = (scsibus->GetPhase() == SCSI::Phase::Transfer) - && (scsibus->GetXfer() == SCSI::XferPhase::DataOut); - MODIFY(scsi_out, out); + if ((bool)scsibus) { + MODIFY(scsi_bsy, scsibus->GetBSY()); + // 転送フェーズで DataOut の時だけ書き込みとみなす + bool out = (scsibus->GetPhase() == SCSI::Phase::Transfer) + && (scsibus->GetXfer() == SCSI::XferPhase::DataOut); + MODIFY(scsi_out, out); + } // ネットワーク // パケット数が変化したとき、 @@ -353,6 +415,18 @@ WXStatusPanel::UpdateStat() MODIFY(net_rx_active, MODIFY(net_rx_pkts, hostnet->GetRXPkts())); } + // FD + for (const auto fdd : fdd_vector) { + int unit = fdd->GetUnitNo(); + MODIFY(fdstat[unit].access_led, fdd->GetAccessLED()); + MODIFY(fdstat[unit].eject_led, fdd->GetEjectLED()); + } + + // NEWS LED + if (newsctlr) { + MODIFY(newsled, newsctlr->GetLED()); + } + // 電源 return updated; @@ -364,6 +438,12 @@ WXStatusPanel::Draw() { std::string text; + // 指定された時だけ背景を再描画 + if (refresh_background) { + refresh_background = false; + bitmap.Fill(BGPANEL); + } + // なんとなく見栄えのため上下に薄い線を引く。 // 四方を線で囲むとオーバーレイウィンドウのように見えるので上下だけ。 wxSize size = GetSize(); @@ -402,7 +482,7 @@ WXStatusPanel::DrawPerf(const Indicator // パフォーマンス表示は // o 高速モード指示中なら倍率表記 (115% なら 1.2x) // o 通常モード指示中ならパーセント表記 - if ((perf_mode & Sync::SCHED_SYNC) == 0) { + if ((perf_mode & Syncer::SCHED_SYNC) == 0) { // 高速モード指示 if (perf_mode == 0) { // 高速走行中 @@ -432,11 +512,12 @@ WXStatusPanel::DrawSCSI(const Indicator { Color fg; Color bg; + int scsiid; uint idmask; - const auto si = dynamic_cast(ind); - assert(si); - idmask = 1U << si->GetId(); + scsiid = ind->GetSCSIID(); + assertmsg(scsiid >= 0, "id=%d", ind->id); + idmask = 1U << scsiid; if ((scsi_loaded & idmask) != 0) { fg = UD_BLACK; @@ -506,11 +587,179 @@ WXStatusPanel::DrawNet(const Indicator * ResetTextColor(); } -// 電源LED? +// FD +void +WXStatusPanel::DrawFD(const Indicator *ind) +{ + Rect iconrect; + Color pal[3]; + enum { + BG = 0, + FG, + IN, + }; + int unit; + + unit = ind->GetFDUnit(); + const Rect& rect = ind->rect; + + pal[BG] = BGPANEL; + if (fdstat[unit].loaded) { + pal[FG] = UD_BLACK; + } else { + pal[FG] = UD_GREY; + } + + // まず枠とテキストを通常描画 + DrawTextLED(ind, pal[FG], pal[BG]); + + // 続いて 5,6文字目の空き地に四角いインジケータを描画。 + // 同じ色で済むので先に描画する。 + iconrect.x = rect.x + 2 + font_width * 5 + 1; + iconrect.y = rect.y + 2 + 1; + iconrect.w = font_width * 2 - 2; + iconrect.h = font_height - 2; + bitmap.DrawRect(pal[FG], iconrect); + // ディスク挿入(取り出し可)なら黄緑点灯 + if (fdstat[unit].eject_led) { + iconrect.x += 1; + iconrect.y += 1; + iconrect.w -= 2; + iconrect.h -= 2; + bitmap.FillRect(UD_YELLOW_GREEN, iconrect); + } + + // その後で 3,4文字目の空き地に丸いインジケータを描画。 + int dx = rect.x + 2 + font_width * 3; + int dy = rect.y + 2; + + // アクセス LED はディスク非挿入時に点滅するケースがあって、 + // その場合、フチがグレーのまま中を黄緑で塗りつぶすのは見えづらいので + // 中を塗りつぶす時はフチを濃くしたほうがいい。 + switch (fdstat[unit].access_led) { + case FDDDevice::LED::GREEN: + pal[FG] = UD_BLACK; + pal[IN] = UD_YELLOW_GREEN; + break; + case FDDDevice::LED::RED: + pal[FG] = UD_BLACK; + pal[IN] = UD_RED; + break; + default: + pal[IN] = pal[BG]; + break; + } + bitmap.DrawBitmap(dx, dy, *accmark, pal); +} + +/*static*/ const uint8 +WXStatusPanel::AccessMark12[] = { + 0,0,0,0,1,1,1,0,0,0,0,0, + 0,0,1,1,2,2,2,1,1,0,0,0, + 0,1,2,2,2,2,2,2,2,1,0,0, + 0,1,2,2,2,2,2,2,2,1,0,0, + 1,2,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2,2,1,0,0, + 0,1,2,2,2,2,2,2,2,1,0,0, + 0,0,1,1,2,2,2,1,1,0,0,0, + 0,0,0,0,1,1,1,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, +}; +/*static*/ const uint8 +WXStatusPanel::AccessMark16[] = { + 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, + 0,0,0,1,1,2,2,2,2,2,1,1,0,0,0,0, + 0,0,1,2,2,2,2,2,2,2,2,2,1,0,0,0, + 0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0, + 0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0, + 1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0, + 0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0, + 0,0,1,2,2,2,2,2,2,2,2,2,1,0,0,0, + 0,0,0,1,1,2,2,2,2,2,1,1,0,0,0,0, + 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; +/*static*/ const uint8 +WXStatusPanel::AccessMark24[] = { + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,1, 1,2,2,2,2,2,2,1, 1,0,0,0,0,0,0,0, + 0,0,0,0,0,1,1,2, 2,2,2,2,2,2,2,2, 2,1,1,0,0,0,0,0, + 0,0,0,0,1,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,1,0,0,0,0, + 0,0,0,1,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,1,0,0,0, + 0,0,0,1,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,1,0,0,0, + 0,0,1,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,1,0,0, + 0,0,1,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,1,0,0, + 0,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,1,0, + 0,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,1,0, + 0,0,1,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,1,0,0, + 0,0,1,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,1,0,0, + 0,0,0,1,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,1,0,0,0, + 0,0,0,1,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,1,0,0,0, + 0,0,0,0,1,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,1,0,0,0,0, + 0,0,0,0,0,1,1,2, 2,2,2,2,2,2,2,2, 2,1,1,0,0,0,0,0, + 0,0,0,0,0,0,0,1, 1,2,2,2,2,2,2,1, 1,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, +}; + +// NEWS LED1 +void +WXStatusPanel::DrawNewsLED1(const Indicator *ind) +{ + Color bg; + + if ((newsled & NewsCtlrDevice::LED_ORANGE) != 0) { + bg = UD_ORANGE; + } else { + bg = BGPANEL; + } + DrawTextLED(ind, UD_BLACK, bg); +} + +// NEWS LED2 +void +WXStatusPanel::DrawNewsLED2(const Indicator *ind) +{ + Color bg; + + if ((newsled & NewsCtlrDevice::LED_GREEN) != 0) { + bg = UD_GREEN; + } else { + bg = BGPANEL; + } + DrawTextLED(ind, UD_BLACK, bg); +} + +// 電源 LED void WXStatusPanel::DrawPower(const Indicator *ind) { - DrawTextLED(ind, UD_BLACK, UD_YELLOW_GREEN); + Color bg; + + if (ispower) { + if (powerled) { + bg = UD_YELLOW_GREEN; + } else { + bg = UD_GREY; + } + } else { + // XXX 電源オフが出来たら X68030 なら赤 + bg = BGPANEL; + } + + DrawTextLED(ind, UD_BLACK, bg); } // 共通の描画処理。 @@ -549,7 +798,7 @@ void WXStatusPanel::DClickPerf(const Indicator *ind) { // モードを切り替える - gSync->RequestFullSpeed(!gSync->GetFullSpeed()); + syncer->RequestFullSpeed(!syncer->GetFullSpeed()); } // コンテキストメニューイベント @@ -560,9 +809,8 @@ WXStatusPanel::OnContextMenu(wxContextMe for (auto ind : indicators) { // コンテキストメニューを処理できる枠内なら - const auto si = dynamic_cast(ind); - if (si && si->contextmenu && ind->rect.Contains(pos.x, pos.y)) { - (this->*(si->contextmenu))(ind); + if (ind->contextmenu && ind->rect.Contains(pos.x, pos.y)) { + (this->*(ind->contextmenu))(ind); break; } } @@ -572,10 +820,25 @@ WXStatusPanel::OnContextMenu(wxContextMe void WXStatusPanel::ContextMenuCD(const Indicator *ind) { - const auto si = dynamic_cast(ind); - assert(si); + int scsiid = ind->GetSCSIID(); + assertmsg(scsiid >= 0, "id=%d", ind->id); + + auto mainframe = dynamic_cast(GetParent()); + auto menu = mainframe->CreateSCSIRemovableMenu(scsiid); + if (menu) { + PopupMenu(menu); + } +} + +// FD 枠でのコンテキストメニュー +void +WXStatusPanel::ContextMenuFD(const Indicator *ind) +{ + int unit = ind->GetFDUnit(); + assertmsg(unit >= 0, "id=%d", ind->id); - auto menu = gMainFrame->CreateSCSIRemovableMenu(si->GetId()); + auto mainframe = dynamic_cast(GetParent()); + auto menu = mainframe->CreateFDMenu(unit); if (menu) { PopupMenu(menu); } @@ -585,35 +848,36 @@ WXStatusPanel::ContextMenuCD(const Indic void WXStatusPanel::OnSCSIMediaChanged(wxCommandEvent& event) { - SCSIIndicator *si = NULL; + Indicator *ind = NULL; uint8 new_loaded; // 該当の Indicator を探す (見付かるはず) - int id = event.GetInt(); - for (int i = 0; i < indicators.size(); i++) { - si = dynamic_cast(indicators[i]); - if (si && si->GetId() == id) { + int scsiid = event.GetInt(); + int id = Indicator::SCSI0 + scsiid; + for (auto i : indicators) { + if (i->id == id) { + ind = i; break; } } - assert(si); - const auto disk = dynamic_cast(si->dev); + assert(ind); + const auto disk = dynamic_cast(ind->dev); // メディアの状態を一旦クリア new_loaded = scsi_loaded; - new_loaded &= ~(1U << id); + new_loaded &= ~(1U << scsiid); // ツールチップを設定 SCSI::DevType devtype = disk->GetDevType(); std::string tip = string_format("%s%d: ", - SCSI::GetDevTypeName(devtype), id); + SCSI::GetDevTypeName(devtype), scsiid); const std::string& path = disk->GetPathName(); // 同時にメディア状態もセット if (path.empty()) { tip += "-"; } else { tip += path; - new_loaded |= (1U << id); + new_loaded |= (1U << scsiid); } switch (disk->GetWriteMode()) { case SCSIDisk::RW::ReadOnly: @@ -628,7 +892,18 @@ WXStatusPanel::OnSCSIMediaChanged(wxComm default: break; } - si->panel->SetToolTip(tip); + ind->panel->SetToolTip(tip); + + // 書き込み無視だけ、これによって shutdown が必要かどうかという + // オペレーションに違いが出るため表示する。 + // 無駄に幅を取らないためメディア挿入時のみ表示。 + // MO のライトプロテクト表示は必要になったら考える…。 + ind->text = string_format("%s%d", SCSI::GetDevTypeName(devtype), scsiid); + if ((new_loaded & (1U << scsiid))) { + if (disk->GetWriteMode() == SCSIDisk::RW::WriteIgnore) { + ind->text += "\x02\x03"; + } + } // メディアのロード状態が変われば (再配置して) 再描画。 // 通常周期のタイマーによる更新チェックではメディア状態はチェックして @@ -640,3 +915,108 @@ WXStatusPanel::OnSCSIMediaChanged(wxComm Refresh(); } } + +// FDD メディア変更イベント (UIMessage イベント) +void +WXStatusPanel::OnFDDMediaChanged(wxCommandEvent& event) +{ + Indicator *ind = NULL; + bool new_loaded; + + // 該当の Indicator を探す (見付かるはず) + int unit = event.GetInt(); + int id = Indicator::FDD0 + unit; + for (auto i : indicators) { + if (i->id == id) { + ind = i; + break; + } + } + assert(ind); + const auto fdd = dynamic_cast(ind->dev); + + // メディアの状態を一旦クリア + new_loaded = false; + + // ツールチップを設定 + std::string tip = string_format("FD%d: ", unit); + const std::string& path = fdd->GetPathName(); + // 同時にメディア状態もセット + if (path.empty()) { + tip += "-"; + } else { + tip += path; + new_loaded = true; + } + switch (fdd->GetWriteMode()) { + case FDDDevice::RW::WriteProtect: + tip += "\n(Write Protected)"; + break; + case FDDDevice::RW::WriteIgnore: + tip += "\n(Write Ignored)"; + break; + default: + break; + } + ind->panel->SetToolTip(tip); + + ind->text = string_format("FD%d", fdd->GetUnitNo()); + // 書き込み無視だけ表示する。無駄に幅を取らないためメディア挿入時のみ表示。 + // 4文字分のマークの後ろに "WI" を追加。 + if (new_loaded) { + if (fdd->GetWriteMode() == FDDDevice::RW::WriteIgnore) { + ind->text += " \x02\x03"; + } + } + + // メディアのロード状態が変われば (再配置して) 再描画。 + // 通常周期のタイマーによる更新チェックではメディア状態はチェックして + // いないので、ここで自発的に行う。 + if (fdstat[unit].loaded != new_loaded) { + fdstat[unit].loaded = new_loaded; + + LayoutIndicators(); + Refresh(); + } +} + +// LED 状態変更イベント (UIMessage イベント)。 +// +// 状態変更があったことをプッシュ通知する。主に、通常の更新頻度では +// 間に合わない X68030 の電源 LED の 16Hz 点滅用。 +void +WXStatusPanel::OnLEDChanged(wxCommandEvent& event) +{ + if (UpdateStat()) { + Refresh(); + } +} + + +// +// インジケータ情報 +// + +// SCSI なら SCSI ID を返す。そうでなければ -1 を返す。 +int +Indicator::GetSCSIID() const +{ + int scsiid = id - SCSI0; + if (0 <= scsiid && scsiid <= 7) { + return scsiid; + } else { + return -1; + } +} + +// FDD ならユニット番号を返す。そうでなければ -1 を返す。 +int +Indicator::GetFDUnit() const +{ + int unit = id - FDD0; + if (0 <= unit && unit <= 3) { + return unit; + } else { + return -1; + } +}