--- nono/vm/mpu.cpp 2026/04/29 17:04:42 1.1.1.4 +++ nono/vm/mpu.cpp 2026/04/29 17:04:55 1.1.1.7 @@ -7,20 +7,16 @@ // MPU 共通部 #include "mpu.h" +#include "config.h" std::unique_ptr gMPU; // コンストラクタ -MPUDevice::MPUDevice() +MPUDevice::MPUDevice(const std::string& objname_) + : inherited(objname_) { - logname = "mpu"; - devname = "MPU"; - - // リセット例外を起こすイベント - // ハンドラは MPU ごとに異なるので継承クラス側で用意している - reset_event.dev = this; - reset_event.time = 0; - reset_event.SetName("MPU Reset"); + ClearAlias(); + AddAlias("MPU"); } // デストラクタ @@ -28,10 +24,31 @@ MPUDevice::~MPUDevice() { } -// リセット -void -MPUDevice::ResetHard() +bool +MPUDevice::Init() { - // 0 サイクル後にリセット例外を起こす - reset_event.Start(); + // MPU クロック + const ConfigItem& item = gConfig->Find("mpu-clock"); + const std::string& val = item.AsString(); + if (val.empty()) { + item.Err(); + return false; + } + // 文字列を double に変換 + char *end; + errno = 0; + double f = strtod(val.c_str(), &end); + if (end == val.c_str() || end[0] != '\0' || errno == ERANGE) { + item.Err(); + return false; + } + // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。 + clock_khz = (int)(f * 1000); + // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど + if (clock_khz < 1000) { + item.Err(); + return false; + } + + return true; }