--- nono/lib/config.cpp 2026/04/29 17:04:30 1.1.1.1 +++ nono/lib/config.cpp 2026/04/29 17:04:57 1.1.1.8 @@ -1,6 +1,7 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "config.h" @@ -24,24 +25,79 @@ Config::Config() // 以下概ねアルファベット順に並べる - // デバッガの TCP 待ち受けポート - Add("debugger-port", 9999); - Add("ethernet-hostdriver", "none"); + // VM 内の時計を同期する時間軸。 + // [ real, virtual ] + Add("clock-sync", "real"); + + // デバッガの TCP 待ち受けポート + Add("debugger-port", 0); + + // MAC アドレス Add("ethernet-macaddr", "auto"); - // LUNA の DIPSW (1 が UP、0 が DOWN) - Add("luna-dipsw1", "11110111"); - Add("luna-dipsw2", "11111111"); - // MPU クロック (MHz 単位の実数、小数点以下は3桁まで)。 - // 初期値は機種ごとに異なるためここでは何もせず - // Scheduler で初期値を代入している。 + + // ネットワークのホスト側設定。 + Add("hostnet-driver", "auto"); + Add("hostnet-fallback", 0); + Add("hostnet-afpacket-ifname", "auto"); + Add("hostnet-bpf-ifname", "auto"); + Add("hostnet-tap-devpath", "auto"); + + // LUNA の DIPSW (1 が UP、0 が DOWN) + // 初期値は機種によって異なるため pio.cpp で設定している。 + Add("luna-dipsw1"); + Add("luna-dipsw2"); + + // LUNA の RTC(MK48T02) がうるう年でない 1970 をエポックとして + // 設定しているので、そちらに合わせてうるう年を補正する + Add("luna-adjust-misused-epoch", 1); + + // m88100 の別名ニーモニックを併記する。 + Add(".m88k-altname", 0); + + // モニタウィンドウの更新頻度 [Hz] + Add("monitor-rate", 20); + + // MPU クロック (MHz 単位の実数、小数点以下は3桁まで)。 + // 初期値は各 VM クラスで設定している。 Add("mpu-clock"); + + // X68030 時の FPU の有無。 + // LUNA-I では VM 初期化時に削除する。 Add("mpu-has-fpu", 0); + + // M88100 で疑似 STOP 状態をサポートする + Add("mpu-pseudo-stop", 1); + + // PROM ファイルパス。なければ内蔵 ROM 起動。 + Add("prom-image", ""); + + // PROM のデバッグオプション。 + // PROM 中の SCSI デバッグビットを立てる。 Add(".prom-scsi-debug", 0); - Add("prom-use-rom", 0); + + // RAM サイズ (MB 単位の整数)。 + // 初期値は機種ごとの VM クラスで設定している。 + Add("ram-size", 0); + + // RTC のデバッグ用オプション。 Add(".rtc-force-fixed", 0); + Add(".rtc-date"); + Add(".rtc-time"); + + // ステータスパネルを表示する。 + Add("show-statuspanel", 1); + + // SCSI 設定。 for (int id = 0; id < 8; id++) { + // 種別とイメージパス Add(string_format("spc0-id%d-image", id)); + // エミュレータ的に書き込みを禁止するか + Add(string_format("spc0-id%d-writeignore", id), 0); + // エミュレータ的に書き込みを禁止するか + // (後方互換、十分不要になった頃に削除する) Add(string_format("spc0-id%d-writeprotect", id), 0); + // シークタイム [msec] + Add(string_format("spc0-id%d-seektime", id), 0); } } @@ -69,15 +125,33 @@ bool Config::Add(const std::string& key, const std::string& value) { assert(FindItem(key) == NULL); + assert(fixed == false); list.emplace_back(key, value, ConfigItem::FromInitial, ""); return true; } +// 項目を削除 +// key が見付からなくても何もしない。key は複数登録されていることはないはず。 +void +Config::Delete(const std::string& key) +{ + for (auto it = list.begin(); it != list.end(); ++it) { + auto item = *it; + if (key == item.key) { + list.erase(it); + return; + } + } + assert(FindItem(key) == NULL); +} + // 設定ファイルの内容で上書きする bool Config::Update(const ConfigFile& file) { + assert(fixed == false); + for (const auto& pair : file.lines) { const std::string& line = pair.first; int lineno = pair.second; @@ -95,6 +169,8 @@ Config::Update(const ConfigFile& file) bool Config::Update(const std::vector& options) { + assert(fixed == false); + for (const auto& line : options) { if (UpdateLine(line, ConfigItem::FromOption, "") == false) { return false; @@ -159,21 +235,27 @@ Config::SplitKeyVal(std::string *keyp, s auto key = line.substr(0, pos++); auto val = line.substr(pos, line.size() - pos); - string_rtrim(key); - string_rtrim(val); - *keyp = string_ltrim(key); - *valp = string_ltrim(val); + *keyp = string_trim(key); + *valp = string_trim(val); return true; } -// 内容を表示する +// 内容を表示する。 +// all なら隠し設定も含めて表示。 void -Config::Show() const +Config::Show(bool all) const { + assert(fixed); + for (const auto& item : list) { + // '!' から始まるのは内部用変数なので隠す + if (!all && item.key[0] == '!') { + continue; + } // ドットから始まるのは隠し設定で、初期値のままなら隠す - if (item.key[0] == '.' && item.from == ConfigItem::FromInitial) { + if (!all && + item.key[0] == '.' && item.from == ConfigItem::FromInitial) { continue; } @@ -207,26 +289,37 @@ Config::Show() const // key から ConfigItem を取得する。見付からなければ assert する。 const ConfigItem& -Config::Get(const std::string& key) const +Config::Find(const std::string& key) const { for (const auto& item : list) { if (key == item.key) { return item; } } - assertmsg(0, "Config::Get() \"%s\" not found\n", key.c_str()); + assertmsg(0, "Config::Find() \"%s\" not found\n", key.c_str()); +} + +// key のデフォルト値を差し替える。key が見付からなければ assert する。 +void +Config::SetDefault(const std::string& key, int val) +{ + std::string valstr = std::to_string(val); + SetDefault(key, valstr); } -// key から ConfigItem (編集可能) を取得する。見付からなければ assert する。 -ConfigItem& -Config::Get(const std::string& key) +// key のデフォルト値を差し替える。key が見付からなければ assert する。 +void +Config::SetDefault(const std::string& key, const std::string& val) { + assert(fixed == false); + for (auto& item : list) { if (key == item.key) { - return item; + item.SetDefault(val); + return; } } - assertmsg(0, "Config::Get() \"%s\" not found\n", key.c_str()); + assertmsg(0, "Config::SetDefault() \"%s\" not found\n", key.c_str()); } // key から ConfigItem を返す。見付からなければ NULL を返す。 @@ -242,6 +335,15 @@ Config::FindItem(const std::string& key) return NULL; } +// これ以降は書き込み禁止 +void +Config::Fix() +{ + assert(fixed == false); + + fixed = true; +} + // // 設定項目 @@ -249,14 +351,6 @@ Config::FindItem(const std::string& key) // デフォルト値を差し替える void -ConfigItem::SetDefault(int val) -{ - std::string valstr = std::to_string(val); - SetDefault(valstr); -} - -// デフォルト値を差し替える -void ConfigItem::SetDefault(const std::string& val) { if (from == FromInitial) {