From a4d5738767c4fd5127adc544ec78cc687c28cfb7 Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 10 Jan 2006 02:09:34 +0000 Subject: [PATCH] First pass at adding the z26 'phosphor effect', which is used in 30Hz ROMs to eliminate flicker. Right now is disabled by default, and when enabled only works in OpenGL mode. It's not yet configurable either, so it's either on or off. It looks like crap on ROMs that don't need it, but is really nice for those that do. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@947 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/common/FrameBufferGL.cxx | 7 +++-- stella/src/emucore/FrameBuffer.cxx | 46 ++++++++++++++++++++++++----- stella/src/emucore/FrameBuffer.hxx | 21 ++++++++++--- 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/stella/src/common/FrameBufferGL.cxx b/stella/src/common/FrameBufferGL.cxx index d091e63eb..f6382e735 100644 --- a/stella/src/common/FrameBufferGL.cxx +++ b/stella/src/common/FrameBufferGL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferGL.cxx,v 1.43 2005-09-15 19:43:36 stephena Exp $ +// $Id: FrameBufferGL.cxx,v 1.44 2006-01-10 02:09:33 stephena Exp $ //============================================================================ #ifdef DISPLAY_OPENGL @@ -231,7 +231,9 @@ void FrameBufferGL::drawMediaSource() { const uInt32 bufofs = bufofsY + x; uInt8 v = currentFrame[bufofs]; - if(v != previousFrame[bufofs] || theRedrawTIAIndicator) + uInt8 w = previousFrame[bufofs]; + + if(v != w || theRedrawTIAIndicator) { // If we ever get to this point, we know the current and previous // buffers differ. In that case, make sure the changes are @@ -241,6 +243,7 @@ void FrameBufferGL::drawMediaSource() // x << 1 is times 2 ( doubling width ) const uInt32 pos = screenofsY + (x << 1); buffer[pos] = buffer[pos+1] = (uInt16) myPalette[v]; +// buffer[pos] = buffer[pos+1] = (uInt16) myAvgPalette[v][w]; } } } diff --git a/stella/src/emucore/FrameBuffer.cxx b/stella/src/emucore/FrameBuffer.cxx index 956ef013f..73ce448c3 100644 --- a/stella/src/emucore/FrameBuffer.cxx +++ b/stella/src/emucore/FrameBuffer.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBuffer.cxx,v 1.69 2006-01-08 02:28:03 stephena Exp $ +// $Id: FrameBuffer.cxx,v 1.70 2006-01-10 02:09:34 stephena Exp $ //============================================================================ #include @@ -256,17 +256,38 @@ void FrameBuffer::pause(bool status) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameBuffer::setPalette(const uInt32* palette) { - for(uInt32 i = 0; i < 256; ++i) - { - Uint8 r, g, b; + int i, j; - r = (Uint8) ((palette[i] & 0x00ff0000) >> 16); - g = (Uint8) ((palette[i] & 0x0000ff00) >> 8); - b = (Uint8) (palette[i] & 0x000000ff); + // Set palette for normal fill + for(i = 0; i < 256; ++i) + { + Uint8 r = (Uint8) ((palette[i] & 0x00ff0000) >> 16); + Uint8 g = (Uint8) ((palette[i] & 0x0000ff00) >> 8); + Uint8 b = (Uint8) (palette[i] & 0x000000ff); myPalette[i] = mapRGB(r, g, b); } + // Set palette for phosphor effect + for(i = 0; i < 256; ++i) + { + for(j = 0; j < 256; ++j) + { + uInt8 ri = (uInt8) ((palette[i] & 0x00ff0000) >> 16); + uInt8 gi = (uInt8) ((palette[i] & 0x0000ff00) >> 8); + uInt8 bi = (uInt8) (palette[i] & 0x000000ff); + uInt8 rj = (uInt8) ((palette[j] & 0x00ff0000) >> 16); + uInt8 gj = (uInt8) ((palette[j] & 0x0000ff00) >> 8); + uInt8 bj = (uInt8) (palette[j] & 0x000000ff); + + Uint8 r = (Uint8) getPhosphor(ri, rj); + Uint8 g = (Uint8) getPhosphor(gi, gj); + Uint8 b = (Uint8) getPhosphor(bi, bj); + + myAvgPalette[i][j] = mapRGB(r, g, b); + } + } + theRedrawTIAIndicator = true; } @@ -626,6 +647,17 @@ void FrameBuffer::drawString(const GUI::Font* font, const string& s, } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 FrameBuffer::getPhosphor(uInt8 c1, uInt8 c2) +{ +int PHOSPHOR = 77; // FIXME - make this configurable + + if(c2 > c1) + SWAP(c1, c2); + + return ((c1 - c2) * PHOSPHOR)/100 + c2; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8 FrameBuffer::ourGUIColors[kNumColors-256][3] = { { 104, 104, 104 }, // kColor diff --git a/stella/src/emucore/FrameBuffer.hxx b/stella/src/emucore/FrameBuffer.hxx index cbefe9aec..487b11a58 100644 --- a/stella/src/emucore/FrameBuffer.hxx +++ b/stella/src/emucore/FrameBuffer.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBuffer.hxx,v 1.60 2006-01-08 02:28:03 stephena Exp $ +// $Id: FrameBuffer.hxx,v 1.61 2006-01-10 02:09:34 stephena Exp $ //============================================================================ #ifndef FRAMEBUFFER_HXX @@ -51,7 +51,7 @@ enum FrameStyle { All GUI elements (ala ScummVM) are drawn here as well. @author Stephen Anthony - @version $Id: FrameBuffer.hxx,v 1.60 2006-01-08 02:28:03 stephena Exp $ + @version $Id: FrameBuffer.hxx,v 1.61 2006-01-10 02:09:34 stephena Exp $ */ class FrameBuffer { @@ -191,7 +191,7 @@ class FrameBuffer /** Calculate the maximum window size that the current screen can hold. - Only works in X11/Win32 for now, otherwise always return 4. + If not supported by platform, always return 4. */ uInt32 maxWindowSizeForScreen(); @@ -421,9 +421,12 @@ class FrameBuffer // SDL initialization flags uInt32 mySDLFlags; - // SDL palette + // SDL palette, with the first 256 colors representing normal fill Uint32 myPalette[kNumColors]; + // SDL palette representing phosphor effect + Uint32 myAvgPalette[256][256]; + // Indicates the current zoom level of the SDL screen uInt32 theZoomLevel; @@ -450,6 +453,16 @@ class FrameBuffer */ void drawMessage(); + /** + Used to calculate an averaged color for the 'phosphor' effect. + + @param c1 Color 1 + @param c2 Color 2 + + @return Averaged value of the two colors + */ + uInt8 getPhosphor(uInt8 c1, uInt8 c2); + private: // Indicates the current framerate of the system uInt32 myFrameRate;