--- nono/vm/vm.h 2026/04/29 17:04:32 1.1.1.2 +++ nono/vm/vm.h 2026/04/29 17:05:16 1.1.1.11 @@ -1,20 +1,23 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// VM (基本クラス) // #pragma once #include "device.h" -// VM 種別 -enum vmtype_t { - VMTYPE_NONE = 0, - VMTYPE_X68030, - VMTYPE_LUNA, - VMTYPE_RXZ, // Human68k .r .x .z console emulation - VMTYPE_LUNA88K, -}; +// デバイスを作成して代入するマクロ。 +// …だったが今となってはあまり意味がなくなっている。 +#define NEWDV(NAME, NEW_CTOR) do { \ + __CONCAT(p,NAME).reset(NEW_CTOR); \ + assert(__CONCAT(p,NAME)); \ +} while (0) class VM { @@ -22,44 +25,46 @@ class VM VM(); virtual ~VM(); + // 明示的な後始末 + void Dispose(); + // 動的なコンストラクション bool Create(); // 初期化 virtual bool Init(); + // スレッド開始 + bool StartThread(); + // 設定の適用 bool Apply(); - // 電源ボタンを押す。 - // XXX この辺はもうちょっと検討したほうがいい - virtual void PowerButton() = 0; - - // 電源ボタンの状態を取得する。 - // モーメンタリスイッチの場合は常に false。 - virtual bool IsPowerButton() const { return false; } - - // VM の全デバイスの電源をオフ - bool DevicePowerOff(); - - // VM 電源オフ時のコールバックを設定する。(GUI から呼ばれる) - void SetPowerOffCallback(void (*callback)()); - - // 外部リセットボタンを押す。 - void ResetButton() { ResetHard(); } - - // ハードウェアリセット - void ResetHard(); + // ブートページを ROM に切り替える + void SwitchBootPageToROM(Device *parent) { SwitchBootPage(parent, true); } + // ブートページを RAM に切り替える + void SwitchBootPageToRAM(Device *parent) { SwitchBootPage(parent, false); } - // MPU の RESET 命令によるリセット - void ResetSoft(); + // MPU の RESET 命令によるリセット (機種ごとに異なるため) + virtual void ResetByMPU(); protected: - // VM の全デバイスの電源をオン - bool DevicePowerOn(); + // ブートページを切り替える (内部用) + virtual void SwitchBootPage(Device *parent, bool isrom); - std::unique_ptr buserr; - void (*poweroff_callback)() = NULL; + std::unique_ptr pBusErr {}; + std::unique_ptr pDebugger {}; + std::unique_ptr pInterrupt {}; + std::unique_ptr pKeyboard {}; + std::unique_ptr pMainbus {}; + std::unique_ptr pMainRAM {}; + std::unique_ptr pMPU {}; + std::unique_ptr pNMI {}; + std::unique_ptr pPower {}; + std::unique_ptr pRenderer {}; + std::unique_ptr pScheduler {}; + std::unique_ptr pSignalThread {}; + std::unique_ptr pSyncer {}; }; -extern std::unique_ptr gVM; +extern VM *gVM;