--- nono/lib/monitor.h 2026/04/29 17:05:08 1.1.1.2 +++ nono/lib/monitor.h 2026/04/29 17:05:56 1.1.1.12 @@ -11,9 +11,9 @@ #pragma once #include "geometric.h" -#include "object.h" +#include "mainapp.h" #include "textscreen.h" -#include "vm.h" +#include // モニタ識別子 // @@ -24,67 +24,133 @@ enum { }; // 識別子 (n番目で指定) -static constexpr int ID_MONITOR_ATC(int n) { - return ID_MONITOR_ATC0 + n; +constexpr uint ID_MONITOR_ATC(uint n) { return ID_MONITOR_ATC0 + n; } +constexpr uint ID_MONITOR_CMMU(uint n) { return ID_MONITOR_CMMU0 + n; } +constexpr uint ID_MONITOR_HOSTCOM(uint n) { return ID_MONITOR_HOSTCOM0 + n; } +constexpr uint ID_MONITOR_HOSTNET(uint n) { return ID_MONITOR_HOSTNET0 + n; } +constexpr uint ID_SUBWIN_CACHE(uint n) { return ID_SUBWIN_CACHE0 + n; } +constexpr uint ID_MONITOR_MEMDUMP(uint n) { return ID_MONITOR_MEMDUMP0 + n; } +constexpr uint ID_MONITOR_RTL8019AS(uint n) { + return ID_MONITOR_RTL8019AS0 + n; } -static constexpr int ID_MONITOR_CMMU(int n) { - return ID_MONITOR_CMMU0 + n; +constexpr uint ID_MONITOR_VIRTIO_BLOCK(uint n) { + return ID_MONITOR_VIRTIO_BLOCK0 + n; } -static constexpr int ID_SUBWIN_CACHE(int n) { - return ID_SUBWIN_CACHE0 + n; -} -static constexpr int ID_MONITOR_MEMDUMP(int n) { - return ID_MONITOR_MEMDUMP0 + n; +constexpr uint ID_MONITOR_XPMEMDUMP(uint n) { + return ID_MONITOR_XPMEMDUMP0 + n; } // 判定 -static constexpr bool IS_MONITOR_MEMDUMP(int id) { +constexpr bool IS_MONITOR_MEMDUMP(uint id) { return (ID_MONITOR_MEMDUMP0 <= id && - id < (ID_MONITOR_MEMDUMP0 + MAX_MEMDUMP_MONITOR)); + id < ID_MONITOR_MEMDUMP(MAX_MEMDUMP_MONITOR)); +} +constexpr bool IS_MONITOR_XPMEMDUMP(uint id) { + return (ID_MONITOR_XPMEMDUMP0 <= id && + id < ID_MONITOR_XPMEMDUMP(MAX_XPMEMDUMP_MONITOR)); } +class BitmapRGBX; class Monitor; -using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&); -#define ToMonitorCallback(f) static_cast(f) - -// モニタコールバックを宣言するマクロ。 -// 強制力はないけどヘッダで宣言するところで使うこと。 -// コールバック関数の型が変わった時にコンパイルエラーで検出させるため。 -#define DECLARE_MONITOR_CALLBACK(name) void name (Monitor *, TextScreen&) -// モニタ更新を呼び出すマクロ -#define MONITOR_UPDATE(m, scr) ((((m).obj)->*((m).func))(&(m), (scr))) +class Object; +using MonitorScreenCallback_t = void (Object::*)(Monitor *, TextScreen&); +using MonitorBitmapCallback_t = void (Object::*)(Monitor *, BitmapRGBX&); // モニタ class Monitor { public: Monitor(); - Monitor(Object *obj_); + Monitor(uint id_, Object *obj_); virtual ~Monitor(); - Object *obj {}; // オブジェクト - MonitorCallback_t func {}; // コールバック関数 - - int GetId() const { return id; } + uint GetId() const { return id; } + // モニターの表示サイズを設定・取得。 void SetSize(nnSize size_) { size = size_; } void SetSize(int col_, int row_) { SetSize(nnSize(col_, row_)); } - virtual nnSize GetSize() const { return size; } + nnSize GetSize() const { return size; } + int GetCol() const noexcept { return size.width; } + int GetRow() const noexcept { return size.height; } + + // 行を増やす。 + void AddHeight(int h) { size.height += h; } + + // モニターが縦に可変長の場合の最大表示行数。(固定長なら 0) + void SetMaxHeight(int maxh_) { maxh = maxh_; } + int GetMaxHeight() const { return maxh; } + + // ID を表示用文字列にして返す。 + static const char *GetIdText(uint id); + + // このモニターの ID を表示用文字列にして返す。 + const char *GetIdText() const { return GetIdText(id); } + + // コールバック関数(テキストのみ)をセットする。 + template + void SetCallback(void (T::*func_)(Monitor *, TextScreen&)) { + screen_func = static_cast(func_); + } + // コールバック関数(テキスト、ビットマップ両方)をセットする。 + template + void SetCallback(void (T::*screen_func_)(Monitor *, TextScreen&), + void (T::*bitmap_func_)(Monitor *, BitmapRGBX&)) { + SetCallback(screen_func_); + bitmap_func = static_cast(bitmap_func_); + } - // 登録。 - // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。 - // Create() の後、Init() より前に -M オプションの処理があるため。 - // see wx/wxapp.cpp - void Regist(int id); + // ビットマップオーバーレイ用にパディング情報をセットする。 + void SetPadding(uint padding_) { + padding = padding_; + } + // ビットマップオーバーレイ用にフォントサイズをセットする。 + void SetFontSize(uint width, uint height) { + font_width = width; + font_height = height; + } - // 削除。 - void Unregist(); + uint GetFontWidth() const noexcept { return font_width; } + uint GetFontHeight() const noexcept { return font_height; } + // テキスト座標をビットマップ座標に変換する便利関数。 + uint BX(uint col) const noexcept { return padding + col * font_width; } + uint BY(uint row) const noexcept { return padding + row * font_height; } + + // モニタを更新する。 + void UpdateScreen(TextScreen& screen) { + (obj->*(screen_func))(this, screen); + } + // (あれば)ビットマップでモニタ更新する。 + bool UpdateBitmap(BitmapRGBX& bitmap) { + if (__predict_false(bitmap_func != NULL)) { + (obj->*(bitmap_func))(this, bitmap); + return true; + } else { + return false; + } + } + + Object *obj {}; // オブジェクト private: + // コールバック関数 + MonitorScreenCallback_t screen_func {}; + MonitorBitmapCallback_t bitmap_func {}; + // モニター識別子 - int id; + uint id {}; // モニターサイズ nnSize size {}; + + // 縦に可変長の場合の最大表示行数 (固定長なら 0) + int maxh {}; + + // ビットマップ描画用。 + uint font_width {}; + uint font_height {}; + uint padding {}; + + // ID を表示用のテキストにしたものとの対応表。 + static const std::vector> idtext; }; // @@ -92,12 +158,10 @@ class Monitor // class MonitorManager { - friend class Monitor; - // モニター情報 (事前定義) struct MonitorInfo { - int id; - vmf_t feature; + uint id; + VMCap vmcap; std::vector aliases; }; @@ -105,65 +169,60 @@ class MonitorManager MonitorManager(); ~MonitorManager(); - // 現在登録されているモニターのリストを返す。 - const std::vector& GetList() const { return list; } + // 登録。 + // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。 + // Create() の後、Init() より前に -M オプションの処理があるため。 + // see wx/wxapp.cpp + Monitor *Regist(uint id_, Object *parent_); + Monitor *Regist(Monitor *monitor_); + + // 削除 + void Unregist(Monitor *mon_); + + // 現在登録されているモニターの(穴空きでない)リストを返す。 + const std::vector GetList() const; // 指定された id を持つモニターを返す。 // こっちは、なければ assert する。 - Monitor& Get(int id) const { - for (auto mon : list) { - if (mon->GetId() == id) { - return *mon; - } - } - PANIC("id=%d not found", id); - } + Monitor *Get(uint id) const; // 指定された id を持つモニターを返す。 // こっちは、なければ NULL を返す。 - Monitor *Find(int id) const { - for (auto mon : list) { - if (mon->GetId() == id) { - return mon; - } - } - return NULL; + Monitor *Find(uint id) const { + return monitors[id].get(); } - // 指定された id に対応する機種フラグを返す。 - vmf_t GetFeature(int id) const { - assert(0 <= id && id < info.size()); - return info[id].feature; + // 指定された id に対応する機種ケーパビリティを返す。 + VMCap GetVMCap(uint id) const { + assertmsg(id < info.size(), "id=%u < %zu", id, info.size()); + return info[id].vmcap; } // 指定された id に対応する名前のリストを返す。 // id が範囲外だと assert する。 - const std::vector& GetAliases(int id) const { - assert(0 <= id && id < info.size()); + const std::vector& GetAliases(uint id) const { + assertmsg(id < info.size(), "id=%u < %zu", id, info.size()); return info[id].aliases; } - // id リストから一覧表示用の文字列を生成して返す - static std::string MakeListString(std::vector list); + // id リストから一覧表示用の文字列リストを生成して返す + std::vector MakeListString(std::vector list) const; // 以降の追加を禁止する (プログラムミスを避けるため) void Fix(); private: - // 登録 (friend の Monitor からのみ呼べる) - void Regist(Monitor *mon); + // Regist() の実体。 + Monitor *RegistCommon(uint id_, Object *parent_, Monitor *monitor_); - // 削除 (friend の Monitor からのみ呼べる) - void Unregist(Monitor *mon); + // モニターインスタンスの配列。添字はモニター ID なので歯抜け。 + std::array, ID_SUBWIN_MAX> monitors /*{}*/; - // 現在登録されているモニターのリスト - std::vector list {}; + // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。 + bool fixed {}; // 事前に設定されているモニター情報 static const std::vector info; - - // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。 - bool fixed {}; }; extern MonitorManager *gMonitorManager;