From 2d0141298f1a6b6e9a8d2bb8f6f44d49bf11a44f Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 27 Oct 2018 23:26:00 +0100 Subject: [PATCH] Improve performance of scanline count register: Titles spend less time spinning on scanline counter now --- src/devices/video/EmuNV2A_PCRTC.cpp | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/devices/video/EmuNV2A_PCRTC.cpp b/src/devices/video/EmuNV2A_PCRTC.cpp index 1d5c83e4f..471fd67af 100644 --- a/src/devices/video/EmuNV2A_PCRTC.cpp +++ b/src/devices/video/EmuNV2A_PCRTC.cpp @@ -57,17 +57,29 @@ DEVICE_READ32(PCRTC) break; case NV_PCRTC_RASTER: { // Test case: Alter Echo - // Hack: Increment on every call, up-to the framebuffer height, satisfying titles waiting for any value - // TODO: Implement this in a better/more accurate way - static int scanline = 0; + // Hack: Alternate between 0, mid-frame, and end-of-frame, this is enough to satisfy any title + // that waits for VBlank using D3DDevice_GetRasterStatus, but not harm performance as much as + // the previous implementation - // The exact range of the timer needs verifying on hardware, but it must exceed the frame-height to account for VBlank time - // For now, we use a constant of 100 and Alter Echo seems happy enough. - if (scanline > NV2ADevice::GetFrameHeight(d) + 100) { - scanline = 0; + static int stage = 0; + + switch (stage) { + case 0: + result = 0; + break; + case 1: + result = NV2ADevice::GetFrameHeight(d) / 2; + break; + case 2: + result = NV2ADevice::GetFrameHeight(d) + 1; + break; + } + + stage++; + + if (stage > 2) { + stage = 0; } - - result = scanline++; } break; default: result = 0;