--- nono/vm/tvram.cpp 2026/04/29 17:04:39 1.1.1.4 +++ nono/vm/tvram.cpp 2026/04/29 17:04:56 1.1.1.6 @@ -17,12 +17,8 @@ #endif #if defined(PERF) -// テキスト画面合成のパフォーマンス測定。PERF をどっかで有効にしてビルド。 -// X68030 IPLROM で起動してくるあたりの画面更新で測定する。 -#include -static int total_elapsed; -static int total_count; -static std::list fpsarray; +#include "perfcounter.h" +static PerfCounter perf(100); #endif // @@ -33,9 +29,8 @@ static std::list fpsarray; std::unique_ptr gTVRAM; TVRAMDevice::TVRAMDevice() + : inherited("TVRAM") { - logname = "tvram"; - devname = "TVRAM"; devaddr = baseaddr; devlen = 512 * 1024; @@ -79,6 +74,7 @@ TVRAMDevice::Decoder(uint32 addr) const uint64 TVRAMDevice::Read8(uint32 addr) { + gMPU->AddCycle(9); // Inside/Out p.135 uint32 offset = Decoder(addr); return mem[HB(offset)]; } @@ -86,6 +82,7 @@ TVRAMDevice::Read8(uint32 addr) uint64 TVRAMDevice::Read16(uint32 addr) { + gMPU->AddCycle(9); // Inside/Out p.135 uint32 offset = Decoder(addr); return *(uint16 *)&mem[offset]; } @@ -95,6 +92,8 @@ TVRAMDevice::Write8(uint32 addr, uint32 { uint32 offset = Decoder(addr); + gMPU->AddCycle(9); // Inside/Out p.135 + // XXX とりあえずね putlog(3, "Write $%06x <- $%02x", addr, data); @@ -119,6 +118,8 @@ TVRAMDevice::Write16(uint32 addr, uint32 { uint32 offset = Decoder(addr); + gMPU->AddCycle(9); // Inside/Out p.135 + // XXX とりあえずね putlog(3, "Write $%06x <- $%04x", addr, data); @@ -205,7 +206,7 @@ TVRAMDevice::Render(uint8 *imagebuf) bool updated; #if defined(PERF) - auto start = std::chrono::system_clock::now(); + perf.Start(); #endif dst0 = imagebuf; @@ -411,33 +412,7 @@ TVRAMDevice::Render(uint8 *imagebuf) } #if defined(PERF) - auto end = std::chrono::system_clock::now(); - total_elapsed += std::chrono::duration_cast - (end - start).count(); - if (++total_count >= 100) { - int fps = 1000 * 1000 / (total_elapsed / total_count); - total_elapsed = 0; - total_count = 0; - printf("%d fps", fps); - fpsarray.push_back(fps); - if (fpsarray.size() > 4) { - fpsarray.pop_front(); - } - if (fpsarray.size() > 2) { - int minv = 1e9; - int sum = 0; - for (auto v : fpsarray) { - if (v < minv) - minv = v; - sum += v; - } - // 最悪値1つを除いた移動平均 - sum -= minv; - int avg = sum / (fpsarray.size() - 1); - printf(" (avg %d)", avg); - } - printf("\n"); - } + perf.End(); #endif return updated;