--- nono/vm/vm.cpp 2026/04/29 17:04:32 1.1.1.3 +++ nono/vm/vm.cpp 2026/04/29 17:04:50 1.1.1.6 @@ -1,14 +1,17 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "vm.h" #include "bus.h" #include "mainapp.h" #include "mpu.h" +#include "mythread.h" #include "ram.h" #include "renderer.h" +#include "rtc.h" #include "scheduler.h" std::unique_ptr gVM; @@ -18,10 +21,9 @@ VM::VM() { // どこでやるのがいいかわからんけど、このコンストラクタはメインスレッドで // 作られるので、ここでメインスレッドの名前を設定。 - pthread_setname_np("Main"); + PTHREAD_SETNAME("Main"); - // Scheduler は必ず先頭。(Scheduler::Init のコメント参照) - gScheduler.reset(new Scheduler()); + // バスエラーデバイスだけここで作成。 buserr.reset(new BusErrDevice()); // まず全域をバスエラーで初期化。 @@ -34,12 +36,21 @@ VM::VM() // デストラクタ VM::~VM() { - // スケジューラを停止。 - // スケジューラ(VMスレッド)からのアクセスさえなくなれば - // 後の有象無象はグローバルデストラクタにお任せでもいいか。 - // だめだったらもっと頑張る。 - gScheduler->Terminate(); - gScheduler.reset(); + Dispose(); +} + +// 終了 +void +VM::Dispose() +{ + if ((bool)gScheduler) { + // スケジューラを停止。 + // スケジューラ(VMスレッド)からのアクセスさえなくなれば + // 後の有象無象はグローバルデストラクタにお任せでもいいか。 + // だめだったらもっと頑張る。 + gScheduler->Terminate(); + gScheduler.reset(); + } } // コンストラクタ後の初期化 @@ -85,6 +96,12 @@ VM::Apply() bool VM::DevicePowerOn() { + // 時刻開始 + // RTC::PowerOn() でもいいかも知れないけど念のため全 PowerOn より先に。 + if (!gRTC->InitRTC()) { + return false; + } + for (const auto& d : gDevices) { if (!d->PowerOn()) { return false; @@ -95,7 +112,6 @@ VM::DevicePowerOn() ResetHard(); // スケジューラを開始 - // (MPU の ResetHard() より後で起動時に1回だけ呼び出す) gScheduler->Run(); return true; @@ -133,12 +149,3 @@ VM::ResetHard() d->ResetHard(); } } - -// MPU の RESET 命令によるリセット -void -VM::ResetSoft() -{ - for (const auto& d : gDevices) { - d->ResetSoft(); - } -}