--- nono/vm/mpu.cpp 2026/04/29 17:05:28 1.1.1.13 +++ nono/vm/mpu.cpp 2026/04/29 17:05:54 1.1.1.18 @@ -25,6 +25,7 @@ #include "mpu.h" #include "config.h" #include "debugger.h" +#include "event.h" #include "mainbus.h" #include "scheduler.h" #include "syncer.h" @@ -48,14 +49,10 @@ MPUDevice::~MPUDevice() bool MPUDevice::Init() { - if (inherited::Init() == false) { - return false; - } - debugger = GetDebugger(); - // パラメータは継承側でセットしている。 - scheduler->RegistEvent(exec_event); + auto evman = GetEventManager(); + exec_event = evman->Regist(this, NULL, "MPU Execute"); return true; } @@ -93,45 +90,29 @@ MainMPUDevice::Init() mainbus = GetMainbusDevice(); syncer = GetSyncer(); - // MPU クロック - const ConfigItem& item = gConfig->Find("mpu-clock"); - -#if 1 + // MPU クロック。 + // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。 int val; + const ConfigItem& item = gConfig->Find("mpu-clock"); if (item.TryFixedDecimal(&val, 3) == false) { item.Err(); return false; } clock_khz = (uint)val; -#else - 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 = (uint)(f * 1000 + 0.9); -#endif // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど if (clock_khz < 1000) { item.Err(); return false; } clock_nsec = 1000 * 1000 / clock_khz; + if (clock_nsec < 1) { + item.Err("Clock speed too high"); + return false; + } scheduler->ConnectMessage(MessageID::MPU_TRACE_MAIN, this, ToMessageCallback(&MainMPUDevice::TraceMessage)); - exec_event.SetName("MPU Execute"); - return true; } @@ -148,6 +129,23 @@ MainMPUDevice::TraceMessage(MessageID ms SetTrace((bool)arg); } +void +MainMPUDevice::ChangeState(uint32 new_state) +{ + // new_mode (CPU_STATE_*) と + // NotifyCPUMode() の引数 Syncer::SYNCMODE_CPU_* は + // 実は同じ値なのでそのまま渡してよいことにする。 + static_assert(CPU_STATE_NORMAL == Syncer::SYNCMODE_CPU_NORMAL, ""); + static_assert(CPU_STATE_STOP == Syncer::SYNCMODE_CPU_STOP, ""); + static_assert(CPU_STATE_HALT == Syncer::SYNCMODE_CPU_HALT, ""); + + if (cpu_state != new_state) { + cpu_state = new_state; + // スケジューラに通知 + syncer->NotifyCPUMode(cpu_state); + } +} + // Round Mode (モニタ表示用) /*static*/ const char * const MainMPUDevice::rmstr[4] = {