--- nono/vm/mpu.cpp 2026/04/29 17:04:55 1.1.1.7 +++ nono/vm/mpu.cpp 2026/04/29 17:05:17 1.1.1.11 @@ -4,29 +4,62 @@ // Licensed under nono-license.txt // -// MPU 共通部 +// +// メイン MPU (680x0/88xx0) 共通部 +// + +// Device +// | +-----------+ +// +--| MPUDevice | (680x0/88xx0 の共通部) +// | +-----------+ +// | | +// | +-- MPU680x0Device +// | +-- MPU88xx0Device +// | +// +-------- MPU64180Device #include "mpu.h" #include "config.h" +#include "debugger.h" +#include "mainbus.h" +#include "scheduler.h" +#include "syncer.h" -std::unique_ptr gMPU; +// グローバル参照用 +MPUDevice *gMPU; // コンストラクタ -MPUDevice::MPUDevice(const std::string& objname_) - : inherited(objname_) +MPUDevice::MPUDevice() + : inherited(OBJ_MPU) { - ClearAlias(); - AddAlias("MPU"); + exec_event.Regist("MPU Execute"); } // デストラクタ MPUDevice::~MPUDevice() { + gMPU = NULL; } +// 初期化 bool MPUDevice::Init() { + if (inherited::Init() == false) { + return false; + } + + // XXX 主に m680x0 配下がグローバル変数じゃないと色々解決できない。 + // そのうちなんとかする。 + gMPU = this; + + debugger = GetDebugger(); + mainbus = GetMainbusDevice(); + syncer = GetSyncer(); + + scheduler->ConnectMessage(MessageID::MPU_TRACE_MAIN, this, + ToMessageCallback(&MPUDevice::TraceMessage)); + // MPU クロック const ConfigItem& item = gConfig->Find("mpu-clock"); const std::string& val = item.AsString(); @@ -49,6 +82,35 @@ MPUDevice::Init() item.Err(); return false; } + clock_nsec = 1000 * 1000 / clock_khz; return true; } + +void +MPUDevice::PowerOff() +{ + scheduler->StopEvent(exec_event); +} + +// MPU トレース状態設定要求メッセージ +void +MPUDevice::TraceMessage(MessageID msgid, uint32 arg) +{ + // リセット中は SetTrace しない + if (resetting) { + return; + } + + // デバッガから MPU のトレース状態を設定してくれと言われた + SetTrace((bool)arg); +} + +// Round Mode (モニタ表示用) +/*static*/ const char * const +MPUDevice::rmstr[4] = { + "Near", + "Zero", + "Minus", + "Plus", +};