--- nono/m88xx0/m88100.h 2026/04/29 17:04:46 1.1.1.6 +++ nono/m88xx0/m88100.h 2026/04/29 17:04:49 1.1.1.7 @@ -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,12 +297,12 @@ 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; } // 今のところサイクルを正確に実装するのは無理なので @@ -310,6 +310,9 @@ OP_PROTO(illegal); 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 {};