--- nono/vm/device.cpp 2026/04/29 17:04:55 1.1.1.7 +++ nono/vm/device.cpp 2026/04/29 17:05:11 1.1.1.8 @@ -4,11 +4,13 @@ // Licensed under nono-license.txt // -#include "device.h" -#include "vm.h" +// +// デバイスの基本クラスなど +// -// 全デバイスリスト -std::vector gDevices; +#include "device.h" +#include "mpu.h" +#include "scheduler.h" // // Device @@ -18,20 +20,11 @@ std::vector gDevices; Device::Device(const std::string& objname_) : inherited(objname_) { - gDevices.push_back(this); } // デストラクタ Device::~Device() { - // 自分自身をリストから削除する - // XXX マルチスレッドな状況からは呼ばれないはず? - for (auto it = gDevices.begin(); it != gDevices.end(); ++it) { - if (*it == this) { - gDevices.erase(it); - break; - } - } } bool @@ -52,22 +45,40 @@ Device::Apply() return true; } -bool -Device::PowerOn() +void +Device::ResetHard(bool poweron) { - return true; } -bool +void Device::PowerOff() { - return true; } -// 本体リセットスイッチによるリセット +// ログ表示。 +// VM デバイスでは、仮想時間、PC、オブジェクト名を表示する。 void -Device::ResetHard() +Device::putlogn(const char *fmt, ...) const { + char buf[1024]; + va_list ap; + uint64 vt; + int len; + + vt = gScheduler->GetVirtTime(); + len = snprintf(buf, sizeof(buf), "%4d.%03d'%03d'%03d %08x %s ", + (int)(vt / 1000 / 1000 / 1000), + (int)((vt / 1000 / 1000) % 1000), + (int)((vt / 1000) % 1000), + (int)(vt % 1000), + gMPU->GetPPC(), + GetName().c_str()); + + va_start(ap, fmt); + vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); + va_end(ap); + + WriteLog(buf); } @@ -151,7 +162,8 @@ IODevice::Peek8(uint32 addr) // バスエラー // -std::unique_ptr gBusErr; +// グローバル参照用 +BusErrDevice *gBusErr; // コンストラクタ BusErrDevice::BusErrDevice() @@ -163,8 +175,10 @@ BusErrDevice::BusErrDevice() devaddr = -1; // XXX どうしたもんか } +// デストラクタ BusErrDevice::~BusErrDevice() { + gBusErr = NULL; } uint64 @@ -220,7 +234,8 @@ BusErrDevice::Peek8(uint32 addr) // 何もしないデバイス // -std::unique_ptr gNopIO; +// グローバル参照用 +NopIODevice *gNopIO; // コンストラクタ NopIODevice::NopIODevice() @@ -230,8 +245,10 @@ NopIODevice::NopIODevice() AddAlias("NopIO"); } +// デストラクタ NopIODevice::~NopIODevice() { + gNopIO = NULL; } uint64