diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index 306d7db1..42117698 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -129,27 +129,36 @@ bool SoftRenderer::DoTimings(s32 cycles, bool odd) return true; } -s32 SoftRenderer::DoTimingsPixels(u32 pixels, bool odd) +u32 SoftRenderer::DoTimingsPixels(u32 pixels, bool odd) { // return the difference between the old span and the new span if (pixels <= 4) return 0; - u32 pixeltiming = (pixels - 4) * RasterFrac; + u32 pixelsremain = pixels-4; + u32 timinglimit = RasterTimingCap - RasterTimingCounterPrev; + //todo: do this without a for loop somehow. if (odd) { - u32 rasterend = RasterTimingCap - (RasterTimingCounterOdd + RasterTimingCounterPrev); - pixeltiming = rasterend - pixeltiming; + for (; pixelsremain > 0; pixelsremain--) + { + RasterTimingCounterOdd += RasterFrac; + if (RasterTimingCounterOdd >= timinglimit) break; + } } else { - u32 rasterend = RasterTimingCap - (RasterTimingCounterEven + RasterTimingCounterPrev); - pixeltiming = rasterend - pixeltiming; + for (; pixelsremain > 0; pixelsremain--) + { + RasterTimingCounterEven += RasterFrac; + if (RasterTimingCounterEven >= timinglimit) break; + } } - if (pixeltiming > 0) return 0; + + if (pixelsremain <= 0) return 0; GPU.GPU3D.DispCnt |= (1<<12); - return pixels - (((pixeltiming + (RasterFrac-1)) / RasterFrac) + 4); + return pixelsremain; } void SoftRenderer::EndScanline(bool odd) diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index 43037281..1e6846c2 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -455,7 +455,7 @@ private: melonDS::GPU& GPU; RendererPolygon PolygonList[2048]; bool DoTimings(s32 cycles, bool odd); - s32 DoTimingsPixels(u32 pixels, bool odd); + u32 DoTimingsPixels(u32 pixels, bool odd); void EndScanline(bool odd); void TextureLookup(u32 texparam, u32 texpal, s16 s, s16 t, u16* color, u8* alpha); u32 RenderPixel(Polygon* polygon, u8 vr, u8 vg, u8 vb, s16 s, s16 t);