--- nono/lib/config.cpp 2026/04/29 17:05:12 1.1.1.11 +++ nono/lib/config.cpp 2026/04/29 17:05:15 1.1.1.12 @@ -40,8 +40,15 @@ Config::Config() // デバッガコンソールの fallback は常に不可とする。hostcom.cpp 参照。 // "debugger-fallback" + // DIPSW エイリアス + Add("dipsw-autoboot", "", VMCap::LUNA | VMCap::NEWS); + Add("dipsw-serial", "", VMCap::LUNA | VMCap::NEWS); + // MAC アドレス - Add("ethernet-macaddr", "auto", VMCap::LUNA); + Add("ethernet-macaddr", "auto", VMCap::LUNA | VMCap::NEWS); + + // X68030 の拡張メモリサイズ + Add("extram-size", "0", VMCap::X68030); // フロッピーディスク Add("fd-drive", 2, VMCap::X68030); @@ -55,6 +62,9 @@ Config::Config() // X68030 時の FPU の有無。 Add("fpu-type", "68881", VMCap::X68030); + // 高速モード。 + Add("fast-mode", "0"); + // シリアルポートのホスト側設定 Add("hostcom-driver", "none"); Add("hostcom-fallback", 0); @@ -87,11 +97,17 @@ Config::Config() Add("luna-dipsw2", VMCap::LUNA); // LUNA ビデオボードプレーン数 - Add("luna-video-plane", 1, VMCap::LUNA); + Add("luna-video-plane", 4, VMCap::LUNA); // m88100 の別名ニーモニックを併記する。 Add(".m88k-altname", 0, VMCap::M88K); + // 画面サイズ。 + Add("mainview-scale", "1"); + + // モニタウィンドウ(等)のフォントサイズ + Add("monitor-fontsize", 12); + // モニタウィンドウの更新頻度 [Hz] Add("monitor-rate", 20); @@ -102,6 +118,13 @@ Config::Config() // M88100 で疑似 STOP 状態をサポートする Add("mpu-pseudo-stop", 1, VMCap::M88K); + // NEWS の DIPSW (1 がオン、0 がオフ)。 + Add("news-dipsw", "00001000", VMCap::NEWS); + + // NEWS の SIC を無視する。(暫定) + Add("xxx-news-sic-ignore", "0", VMCap::NEWS); + Add("xxx-news-sci-ignore", "", VMCap::NEWS); + // PROM ファイルパス。なければ内蔵 ROM 起動。 Add("prom-image", "", VMCap::LUNA); @@ -119,7 +142,7 @@ Config::Config() Add(".rtc-time"); // RTC の epoch。初期値は各 VM クラスで設定している。 - Add("rtc-epoch-year", VMCap::LUNA); + Add("rtc-epoch-year", VMCap::LUNA | VMCap::NEWS); // ステータスパネルを表示する。 Add("show-statuspanel", 1); @@ -208,17 +231,11 @@ Config::Update(const ConfigFile& file) // コマンドラインオプションで更新 bool -Config::Update(const std::vector& options) +Config::Update(const std::string& line, const std::string& optname) { assert(fixed == false); - for (const auto& line : options) { - if (UpdateLine(line, ConfigItem::FromOption, "") == false) { - return false; - } - } - - return true; + return UpdateLine(line, ConfigItem::FromOption, optname); } // 更新1行分の共通処理。 @@ -234,7 +251,7 @@ Config::UpdateLine(const std::string& li // キーと値に分解 if (SplitKeyVal(&key, &val, line) == false) { - ConfigItem::PrintErr(from, where, "", line, "syntax error"); + ConfigItem::PrintErr(from, where, "", line, "Syntax error"); return false; } @@ -243,11 +260,11 @@ Config::UpdateLine(const std::string& li if (itemptr == NULL) { // コマンドラインからの場合はエラーにする if (from == ConfigItem::FromOption) { - ConfigItem::PrintErr(from, where, key, val, "unknown key"); + ConfigItem::PrintErr(from, where, key, val, "Unknown key"); return false; } // コマンドライン以外の場合は警告のみで無視する - ConfigItem::PrintErr(from, where, key, val, "unknown key, ignored"); + ConfigItem::PrintErr(from, where, key, val, "Unknown key, ignored"); return true; } @@ -320,10 +337,11 @@ Config::Show(bool all) const fromstr = item.where; break; case ConfigItem::FromOption: - fromstr = "-V option"; + fromstr = "option " + item.where; break; default: - __unreachable(); + fromstr = string_format("corrupted item.from=%d", (int)item.from); + break; } printf("%s(%s)\n", buf.c_str(), fromstr.c_str()); @@ -378,17 +396,26 @@ Config::FindItem(const std::string& key) return NULL; } -// これ以降は書き込み禁止 -void +// これ以降は書き込み禁止。 +bool Config::Fix() { assert(fixed == false); // ここで、この機種に不要な変数を削除する。 + // が、その前にその変数がユーザから指定されていればエラーにする。 for (auto it = list.begin(); it != list.end(); ) { ConfigItem& item = *it; VMCap vmcap = item.GetVMCap(); if (gMainApp.Has(vmcap) == false) { + // この機種用ではない + + if (item.from != ConfigItem::FromInitial) { + // 更新されていればエラー + item.Err("Not supported in this vmtype"); + return false; + } + it = list.erase(it); } else { ++it; @@ -396,6 +423,7 @@ Config::Fix() } fixed = true; + return true; } @@ -422,6 +450,25 @@ ConfigItem::TryInt(int *val) const return true; } +// 値を double 値として取得してみる。 +bool +ConfigItem::TryDouble(double *val) const +{ + char *endp; + + if (value.empty()) { + return false; + } + + errno = 0; + double res = strtod(value.c_str(), &endp); + if (errno) { + return false; + } + *val = res; + return true; +} + // デフォルト値を差し替える void ConfigItem::SetDefault(const std::string& val) @@ -435,7 +482,7 @@ void ConfigItem::Err() const { // 定型文 - Err("invalid argument"); + Err("Invalid argument"); } void @@ -458,34 +505,52 @@ ConfigItem::Err(const std::string& msg) PrintErr(from, where, key, value, msg); } +// この item についてエラーを表示する。 +// key=val の '=' がない場合のみ key を空、value を行全体として呼ぶ。 /*static*/ void ConfigItem::PrintErr(ConfigItem::from_t from, const std::string& where, const std::string& key, const std::string& value, const std::string& msg) { std::string fromstr; - std::string keyvalue; switch (from) { case FromInitial: - fromstr = "initial value:"; + // 初期値の場合 key が空なことは起きないはず。 + // というか初期値でエラーが起きることも普通はないはず。 + fromstr = "initial value: " + key + "=" + value; break; + case FromConfig: - fromstr = where + ":"; + // 設定ファイルでのエラー。where はファイル名と行番号。 + fromstr = where + ": "; + if (key.empty() == false) { + fromstr += key; + fromstr + "="; + } + fromstr += value; break; + case FromOption: - fromstr = "option -V"; + // コマンドラインオプションの場合は where は + // "--fontsize" とか "-V" なので、 + // "-V" なら (key =) value を追加し、 + // それ以外なら value のみ追加がいいか。 + fromstr = "option " + where + " "; + if (where == "-V") { + if (key.empty() == false) { + fromstr += key; + fromstr += "="; + } + } + fromstr += value; break; - default: - __unreachable(); - } - if (key.empty()) { - keyvalue = value; - } else { - keyvalue = key + "=" + value; + default: + fromstr = string_format("corrupted item.from=%d", (int)from); + break; } - warnx("%s %s: %s", fromstr.c_str(), keyvalue.c_str(), msg.c_str()); + warnx("%s: %s", fromstr.c_str(), msg.c_str()); } @@ -504,7 +569,10 @@ ConfigFile::~ConfigFile() { } -// ファイルの読み込み +// ファイルの読み込み。 +// 成功すれば true を、失敗すればメッセージを出力して false を返す。 +// ファイルがないのは正常とする (なければスルーするため)。 +// ファイルがあって読めなければ失敗 (エラー終了したいので)。 bool ConfigFile::Load() { @@ -513,6 +581,9 @@ ConfigFile::Load() fp = fopen(filepath.c_str(), "r"); if (fp == NULL) { + if (errno == ENOENT) { + return true; + } warn("%s", filepath.c_str()); return false; }