From 11367e6a17f8991b51c204fe25866630d7be05b3 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 18 Sep 2017 09:27:51 +0200 Subject: [PATCH] 1x snapshots now support all 4 phosphor/Blargg combinations --- src/emucore/TIASurface.cxx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 5ef01fe28..b2b41c18b 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -17,6 +17,7 @@ #include #include +#include #include "FrameBuffer.hxx" #include "Settings.hxx" @@ -111,29 +112,27 @@ void TIASurface::setPalette(const uInt32* tia_palette, const uInt32* rgb_palette // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const FBSurface& TIASurface::baseSurface(GUI::Rect& rect) const { - uInt32 tiaw = myTIA->width(), width = tiaw*2, height = myTIA->height(); + uInt32 tiaw = myTIA->width(), width = tiaw * 2, height = myTIA->height(); rect.setBounds(0, 0, width, height); - // Fill the surface with pixels from the TIA, scaled 2x horizontally - uInt32 *buf_ptr, pitch, idx; - myBaseTiaSurface->basePtr(buf_ptr, pitch); + // Get Blargg buffer and width + uInt32 *blarggBuf, blarggPitch; + myTiaSurface->basePtr(blarggBuf, blarggPitch); + double blarggXFactor = (double)blarggPitch / width; bool useBlargg = ntscEnabled(); + // Fill the surface with pixels from the TIA, scaled 2x horizontally + uInt32 *buf_ptr, pitch; + myBaseTiaSurface->basePtr(buf_ptr, pitch); + for(uInt32 y = 0; y < height; ++y) { for(uInt32 x = 0; x < width; ++x) { - idx = y * myTIA->width() + (x >> 1); - if (myUsePhosphor) - { - if (useBlargg) - // just some odd formula to convert to Blargg index (reversed 7:2 conversion) - idx = (y * (myTIA->width() * 7 + 10) >> 1) + y * 5 * 0 + (x * 7 >> 2); - - *buf_ptr++ = myRGBFramebuffer[idx]; - } + if (useBlargg) + *buf_ptr++ = blarggBuf[y * blarggPitch + (uInt32)nearbyint(x * blarggXFactor)]; else - *buf_ptr++ = myPalette[*(myTIA->frameBuffer() + idx)]; + *buf_ptr++ = myPalette[*(myTIA->frameBuffer() + y * tiaw + x / 2)]; } }