--- nono/vm/syncer.h 2026/04/29 17:05:42 1.1.1.6 +++ nono/vm/syncer.h 2026/04/29 17:06:00 1.1.1.9 @@ -10,12 +10,12 @@ #pragma once -#include "event.h" #include "fixedqueue.h" #include "message.h" #include "stopwatch.h" class MPU680x0Device; +class ThreadManager; class Syncer : public Device { @@ -27,13 +27,13 @@ class Syncer : public Device // ビットがすべて %0 なら高速モード、どれかでも %1 なら通常モードになる。 // // | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | - // mode | |POFF|KEY |BOOT|SYNC|HALT|IDLE| + // mode | |SND |POFF|KEY |SYNC|HALT|IDLE| // | | | | | +---- CPU & DMAC アイドル // | | | | +--------- CPU HALT // | | | +-------------- 高速モード抑制 - // | | +------------------- ブートページ実行中 - // | +------------------------ キー入力中 - // +----------------------------- 電源オフ + // | | +------------------- キー入力中 + // | +------------------------ 電源オフ + // +----------------------------- サウンド再生中 // // bit1,0 は CPU から来るが、このうち bit0 だけ DMAC からのアイドル // ビットとの積(AND) になっているので、mode 中の bit0 は CPU も DMAC も @@ -47,9 +47,9 @@ class Syncer : public Device static const uint32 SYNCMODE_IDLE = 0x0001; // CPU & DMAC アイドル static const uint32 SYNCMODE_CPU_HALT = 0x0002; // CPU が HALT 状態 static const uint32 SYNCMODE_SYNC = 0x0004; // 等速モード指示(UI) - static const uint32 SYNCMODE_BOOT = 0x0008; // ブートページ実行中 - static const uint32 SYNCMODE_KEY = 0x0010; // キー入力中 - static const uint32 SYNCMODE_POWEROFF = 0x0020; // 電源オフ + static const uint32 SYNCMODE_KEY = 0x0008; // キー入力中 + static const uint32 SYNCMODE_POWEROFF = 0x0010; // 電源オフ + static const uint32 SYNCMODE_SOUND = 0x0020; // サウンド再生中 // 便宜上用意しておく static const uint32 SYNCMODE_CPU_NORMAL = 0x0000; // CPU が通常状態 @@ -76,10 +76,10 @@ class Syncer : public Device uint32 GetRunMode() const { return mode; } // CPU 状態変更を指示する。 - void RequestCPUMode(uint32 mode_); + void NotifyCPUMode(uint32 mode_); // DMAC のアクティブ状態を指示する。 - void RequestDMACActive(bool active); + void NotifyDMACActive(bool active); // 高速モード(UIによる指示)なら true を返す。 // ここでいう高速モードは STOP 状態中でも高速モード。 @@ -87,16 +87,16 @@ class Syncer : public Device // 高速モードを指示する。 // true なら高速モード、false なら同期モード。 - void RequestFullSpeed(bool enable); - - // ブートページモードの変更を指示する。 - void RequestBootPageMode(bool isrom); + void NotifyFullSpeed(bool enable); // キー入力状態の変更を指示する。 - void RequestKeyPressed(bool pressed); + void NotifyKeyPressed(bool pressed); // 電源オフの状態の変更を指示する。オフになったとき true。 - void RequestPowerOffMode(bool poweroff); + void NotifyPowerOffMode(bool poweroff); + + // サウンド出力状態の変更を指示するう。 + void NotifySoundRunning(bool running); // パフォーマンス測定用に実時間をログ出力 void PutlogRealtime(); @@ -105,13 +105,13 @@ class Syncer : public Device uint GetPerfCounter() const { return perf_counter; } // モニタ更新の下請け - int MonitorUpdateSub(TextScreen& screen, uint64 vtime); + int MonitorScreenSub(TextScreen& screen, uint64 vtime); private: void ChangeMode(uint32 newmode); // 同期イベント - void SyncCallback(Event& ev); + void SyncCallback(Event *); // 動作モード変更メッセージ void ChangeModeMessage(MessageID, uint32); @@ -148,6 +148,9 @@ class Syncer : public Device uint sync_count {}; // 現在の1秒間での同期回数 uint last_sync_count {}; // 前回の1秒間での同期回数 + uint64 last_mpu_exec {}; + uint64 last_mpu_exec_per_sec {}; + // パフォーマンスカウンタ // perfq が移動平均用のバッファ。四捨五入用に10倍値を持っておく // (100% なら 1000)。perf_counter は perfq から求めた実行率で @@ -157,13 +160,15 @@ class Syncer : public Device uint64 next_perf_rtime {}; // 次回測定予定の実経過時間 uint64 last_perf_rtime {}; // 前回測定時の実経過時間 uint64 last_perf_vtime {}; // 前回測定時の仮想経過時間 + uint clock_khz {}; // MHz 表示用の定格クロック数 MPU680x0Device *mpu680x0 {}; + ThreadManager *thman {}; // 同期イベント - Event sync_event { this }; + Event *sync_event {}; }; -static inline Syncer *GetSyncer() { +inline Syncer *GetSyncer() { return Object::GetObject(OBJ_SYNCER); }