--- nono/m88xx0/m88100.h 2026/04/29 17:04:44 1.1.1.5 +++ nono/m88xx0/m88100.h 2026/04/29 17:04:49 1.1.1.7 @@ -175,7 +175,7 @@ class m88kcpu : public m88100reg void RequestReset(); // 仮想時刻を返す - uint64 GetVTime(); + uint64 GetVTime() const { return total_vtime + Cycle2Vtime(used_cycle); } // 割り込み信号線が変化したことの通知を受ける。 // level は 0 か 1。 @@ -210,7 +210,7 @@ class m88kcpu : public m88100reg void AddCycle(int32 wait) { used_cycle += wait; } // MPU クロックを設定 - void SetClockSpeed(uint32 clock_khz_) { clock_khz = clock_khz_; } + void SetClockSpeed(uint32 clock_khz_); std::atomic atomic_reqflag {}; // リクエストフラグ @@ -297,22 +297,22 @@ OP_PROTO(illegal); // サイクル数を仮想時間 [nsec] に変換 uint64 Cycle2Vtime(int32 cycle) const { - return (int64)cycle * 1000 * 1000 / clock_khz; + return (int64)cycle * c2v; } // 仮想時間 [nsec] をサイクル数に変換 uint32 Vtime2Cycle(uint32 vtime) const { - return (uint32)((uint64)vtime * clock_khz / (1000 * 1000)); + return ((uint64)vtime * v2c_factor) >> v2c_shift; } - // 仕掛中のサイクルを仮想時刻に反映させる - void UpdateVTime(); - // 今のところサイクルを正確に実装するのは無理なので // 適当に全部積み上げてある。 uint32 used_cycle {}; // 現在のターンでこれまでに消費したサイクル数 uint32 goal_cycle {}; // 現在のターンで消費すべきサイクル数 uint32 clock_khz {}; // MPU クロック [kHz] + uint32 c2v {}; // サイクル数を nsec に変換する際の係数 + uint64 v2c_factor {}; // nsec をサイクル数に変換する際の乗算係数 + uint32 v2c_shift {}; // nsec をサイクル数に変換する際のシフト係数 // ペンディング中の割り込みレベル int intr_pending {};