--- nono/vm/mpu.cpp 2026/04/29 17:05:09 1.1.1.9 +++ nono/vm/mpu.cpp 2026/04/29 17:05:28 1.1.1.13 @@ -5,40 +5,105 @@ // // -// MPU 共通部 +// MPU (共通部分) // +// Device +// | +-----------+ +// +--| MPUDevice | (全 MPU の共通部) +// +-----------+ +// | +// | +---------------+ +// +--| MainMPUDevice | (680x0/88xx0 の共通部) +// | +---------------+ +// | | +// | +-- MPU680x0Device +// | +-- MPU88xx0Device +// | +// +-- MPU64180Device + #include "mpu.h" #include "config.h" +#include "debugger.h" +#include "mainbus.h" #include "scheduler.h" +#include "syncer.h" -// グローバル参照用 -MPUDevice *gMPU; +// +// 全 MPU 共通 +// // コンストラクタ -MPUDevice::MPUDevice(const std::string& objname_) - : inherited(objname_) +MPUDevice::MPUDevice(uint objid_) + : inherited(objid_) { - ClearAlias(); - AddAlias("MPU"); - - exec_event.Regist("MPU Execute"); } // デストラクタ MPUDevice::~MPUDevice() { - gMPU = NULL; } +// 初期化 bool MPUDevice::Init() { - gScheduler->ConnectMessage(MessageID::MPU_TRACE, this, - ToMessageCallback(&MPUDevice::TraceMessage)); + if (inherited::Init() == false) { + return false; + } + + debugger = GetDebugger(); + + // パラメータは継承側でセットしている。 + scheduler->RegistEvent(exec_event); + + return true; +} + +void +MPUDevice::PowerOff() +{ + scheduler->StopEvent(exec_event); +} + + +// +// メイン MPU (680x0/88xx0) 共通部 +// + +// コンストラクタ +MainMPUDevice::MainMPUDevice() + : inherited(OBJ_MPU) +{ +} + +// デストラクタ +MainMPUDevice::~MainMPUDevice() +{ +} + +// 初期化 +bool +MainMPUDevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + mainbus = GetMainbusDevice(); + syncer = GetSyncer(); // MPU クロック const ConfigItem& item = gConfig->Find("mpu-clock"); + +#if 1 + int val; + 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(); @@ -53,7 +118,8 @@ MPUDevice::Init() return false; } // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。 - clock_khz = (int)(f * 1000); + clock_khz = (uint)(f * 1000 + 0.9); +#endif // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど if (clock_khz < 1000) { item.Err(); @@ -61,26 +127,30 @@ MPUDevice::Init() } clock_nsec = 1000 * 1000 / clock_khz; - return true; -} + scheduler->ConnectMessage(MessageID::MPU_TRACE_MAIN, this, + ToMessageCallback(&MainMPUDevice::TraceMessage)); -void -MPUDevice::PowerOff() -{ - gScheduler->StopEvent(exec_event); + exec_event.SetName("MPU Execute"); + + return true; } // MPU トレース状態設定要求メッセージ void -MPUDevice::TraceMessage(MessageID msgid, uint32 arg) +MainMPUDevice::TraceMessage(MessageID msgid, uint32 arg) { + // リセット中は SetTrace しない + if (resetting) { + return; + } + // デバッガから MPU のトレース状態を設定してくれと言われた SetTrace((bool)arg); } // Round Mode (モニタ表示用) /*static*/ const char * const -MPUDevice::rmstr[4] = { +MainMPUDevice::rmstr[4] = { "Near", "Zero", "Minus",