--- nono/lib/config.cpp 2026/04/29 17:04:30 1.1.1.1 +++ nono/lib/config.cpp 2026/04/29 17:04:37 1.1.1.3 @@ -1,6 +1,7 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "config.h" @@ -29,15 +30,21 @@ Config::Config() Add("ethernet-hostdriver", "none"); Add("ethernet-macaddr", "auto"); // LUNA の DIPSW (1 が UP、0 が DOWN) - Add("luna-dipsw1", "11110111"); - Add("luna-dipsw2", "11111111"); + // 機種によって初期値を変えるため pio.cpp で設定。 + Add("luna-dipsw1"); + Add("luna-dipsw2"); + // モニタウィンドウの更新頻度。(Hz) + Add("monitor-rate", 20); // MPU クロック (MHz 単位の実数、小数点以下は3桁まで)。 - // 初期値は機種ごとに異なるためここでは何もせず - // Scheduler で初期値を代入している。 + // 各 VM クラスで初期値を設定している。 Add("mpu-clock"); Add("mpu-has-fpu", 0); + // PROM ファイルパス。なければ内蔵 ROM 起動。 + Add("prom-image", ""); Add(".prom-scsi-debug", 0); - Add("prom-use-rom", 0); + // RAM サイズ (MB 単位の整数)。 + // 各 VM クラスで初期値を設定している。 + Add("ram-size", 0); Add(".rtc-force-fixed", 0); for (int id = 0; id < 8; id++) { Add(string_format("spc0-id%d-image", id)); @@ -69,6 +76,7 @@ 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; @@ -78,6 +86,8 @@ Config::Add(const std::string& key, cons 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 +105,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; @@ -167,13 +179,21 @@ Config::SplitKeyVal(std::string *keyp, s 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 +227,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 +273,15 @@ Config::FindItem(const std::string& key) return NULL; } +// これ以降は書き込み禁止 +void +Config::Fix() +{ + assert(fixed == false); + + fixed = true; +} + // // 設定項目 @@ -249,14 +289,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) {