From e462ac656d01a8de117b2bb25818719f60e125ac Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 10 Apr 2002 23:51:18 +0000 Subject: [PATCH] Added (probably useless :>) screen tinting to the X11 and SDL versions. Now when you press pause, the screen colors are tinted by half. Probably not very useful, but I saw it in other emulators and liked the look of it. Various cleanups to X11 and SDL code, such as initially setting pointers to NULL, etc. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@68 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/ui/sdl/mainSDL.cxx | 53 ++++++++++++------ stella/src/ui/x11/mainX11.cxx | 101 +++++++++++++++++++++------------- 2 files changed, 100 insertions(+), 54 deletions(-) diff --git a/stella/src/ui/sdl/mainSDL.cxx b/stella/src/ui/sdl/mainSDL.cxx index 8df461bb5..f65f38348 100644 --- a/stella/src/ui/sdl/mainSDL.cxx +++ b/stella/src/ui/sdl/mainSDL.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: mainSDL.cxx,v 1.20 2002-04-10 04:09:59 bwmott Exp $ +// $Id: mainSDL.cxx,v 1.21 2002-04-10 23:51:18 stephena Exp $ //============================================================================ #include @@ -79,19 +79,19 @@ static void handleRCFile(); static void usage(); // Globals for the SDL stuff -static SDL_Surface* screen; +static SDL_Surface* screen = (SDL_Surface*) NULL; static Uint32 palette[256]; static int bpp; -static Display* theX11Display; -static Window theX11Window; -static int theX11Screen; +static Display* theX11Display = (Display*) NULL; +static Window theX11Window = 0; +static int theX11Screen = 0; static int mouseX = 0; static bool x11Available = false; static SDL_SysWMinfo info; static int sdlflags; -static RectList* rectList; -static SDL_Joystick* theLeftJoystick; -static SDL_Joystick* theRightJoystick; +static RectList* rectList = (RectList*) NULL; +static SDL_Joystick* theLeftJoystick = (SDL_Joystick*) NULL; +static SDL_Joystick* theRightJoystick = (SDL_Joystick*) NULL; #ifdef HAVE_PNG static Snapshot* snapshot; @@ -171,10 +171,10 @@ static Event theEvent; static Event keyboardEvent; // Pointer to the console object or the null pointer -static Console* theConsole; +static Console* theConsole = (Console*) NULL; // Pointer to the settings object or the null pointer -static Settings* settings; +static Settings* settings = (Settings*) NULL; // Indicates if the user wants to quit static bool theQuitIndicator = false; @@ -357,6 +357,11 @@ void recalculate8BitPalette() if(bpp != 8) return; + // Make the palette be half-bright if pause is selected + uInt8 shift = 0; + if(thePauseIndicator) + shift = 1; + // Map 2600 colors to the current screen const uInt32* gamePalette = theConsole->mediaSource().palette(); SDL_Color colors[256]; @@ -364,9 +369,9 @@ void recalculate8BitPalette() { Uint8 r, g, b; - r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16); - g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8); - b = (Uint8) (gamePalette[i] & 0x000000ff); + r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16) >> shift; + g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8) >> shift; + b = (Uint8) (gamePalette[i] & 0x000000ff) >> shift; colors[i].r = r; colors[i].g = g; @@ -390,21 +395,30 @@ void recalculate8BitPalette() /** - Set up the palette for a screen with > 8 bits + Set up the palette for a screen of any depth. + Calls recalculate8BitPalette if necessary. */ void setupPalette() { if(bpp == 8) + { + recalculate8BitPalette(); return; + } + + // Make the palette be half-bright if pause is selected + uInt8 shift = 0; + if(thePauseIndicator) + shift = 1; const uInt32* gamePalette = theConsole->mediaSource().palette(); for(uInt32 i = 0; i < 256; ++i) { Uint8 r, g, b; - r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16); - g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8); - b = (Uint8) (gamePalette[i] & 0x000000ff); + r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16) >> shift; + g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8) >> shift; + b = (Uint8) (gamePalette[i] & 0x000000ff) >> shift; switch(bpp) { @@ -560,7 +574,12 @@ void togglePause() thePauseIndicator = true; } + // Pause the console theConsole->mediaSource().pause(thePauseIndicator); + + // Show a different palette depending on pause state + setupPalette(); + theRedrawEntireFrameIndicator = true; } diff --git a/stella/src/ui/x11/mainX11.cxx b/stella/src/ui/x11/mainX11.cxx index 33e2d6584..3c2c8b494 100644 --- a/stella/src/ui/x11/mainX11.cxx +++ b/stella/src/ui/x11/mainX11.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: mainX11.cxx,v 1.21 2002-04-10 04:09:59 bwmott Exp $ +// $Id: mainX11.cxx,v 1.22 2002-04-10 23:51:18 stephena Exp $ //============================================================================ #include @@ -60,6 +60,7 @@ static GC theGCTable[256]; static bool setupDisplay(); static bool setupJoystick(); static bool createCursors(); +static void setupPalette(); static void cleanup(); static void updateDisplay(MediaSource& mediaSource); @@ -81,14 +82,14 @@ static void handleRCFile(); static void usage(); // Globals for X windows stuff -static Display* theDisplay; +static Display* theDisplay = (Display*) NULL; static string theDisplayName = ""; -static int theScreen; -static Visual* theVisual; -static Window theWindow; -static Colormap thePrivateColormap; -static Cursor normalCursor; -static Cursor blankCursor; +static int theScreen = 0; +static Visual* theVisual = (Visual*) NULL; +static Window theWindow = 0; +static Colormap thePrivateColormap = 0; +static Cursor normalCursor = 0; +static Cursor blankCursor = 0; static uInt32 eventMask; static Atom wm_delete_window; @@ -177,10 +178,10 @@ static Event theEvent; static Event keyboardEvent; // Pointer to the console object or the null pointer -static Console* theConsole; +static Console* theConsole = (Console*) NULL; // Pointer to the settings object or the null pointer -static Settings* settings; +static Settings* settings = (Settings*) NULL; // Indicates if the user wants to quit static bool theQuitIndicator = false; @@ -265,13 +266,6 @@ bool setupDisplay() return false; } - // If requested create a private colormap for the window - if(settings->theUsePrivateColormapFlag) - { - thePrivateColormap = XCreateColormap(theDisplay, theWindow, - theVisual, AllocNone); - } - XSizeHints hints; hints.flags = PSize | PMinSize | PMaxSize; hints.min_width = hints.max_width = hints.width = width; @@ -283,26 +277,8 @@ bool setupDisplay() theConsole->properties().get("Cartridge.Name").c_str()); XmbSetWMProperties(theDisplay, theWindow, name, "stella", 0, 0, &hints, None, None); - // Allocate colors in the default colormap - const uInt32* palette = theConsole->mediaSource().palette(); - for(uInt32 t = 0; t < 256; ++t) - { - XColor color; - - color.red = (palette[t] & 0x00ff0000) >> 8 ; - color.green = (palette[t] & 0x0000ff00) ; - color.blue = (palette[t] & 0x000000ff) << 8; - color.flags = DoRed | DoGreen | DoBlue; - - if(settings->theUsePrivateColormapFlag) - XAllocColor(theDisplay, thePrivateColormap, &color); - else - XAllocColor(theDisplay, DefaultColormap(theDisplay, theScreen), &color); - - XGCValues values; - values.foreground = color.pixel; - theGCTable[t] = XCreateGC(theDisplay, theWindow, GCForeground, &values); - } + // Set up the palette for the screen + setupPalette(); // Set up the delete window stuff ... wm_delete_window = XInternAtom(theDisplay, "WM_DELETE_WINDOW", False); @@ -374,6 +350,52 @@ bool setupJoystick() return true; } +/** + Set up the palette for a screen of any depth. +*/ +void setupPalette() +{ + // If we're using a private colormap then let's free it to be safe + if(settings->theUsePrivateColormapFlag && theDisplay) + { + if(thePrivateColormap) + XFreeColormap(theDisplay, thePrivateColormap); + + thePrivateColormap = XCreateColormap(theDisplay, theWindow, + theVisual, AllocNone); + } + + // Make the palette be half-bright if pause is selected + uInt8 shift = 0; + if(thePauseIndicator) + shift = 1; + + // Allocate colors in the default colormap + const uInt32* palette = theConsole->mediaSource().palette(); + for(uInt32 t = 0; t < 256; ++t) + { + XColor color; + + color.red = ((palette[t] & 0x00ff0000) >> 8) >> shift; + color.green = (palette[t] & 0x0000ff00) >> shift; + color.blue = ((palette[t] & 0x000000ff) << 8) >> shift; + color.flags = DoRed | DoGreen | DoBlue; + + if(settings->theUsePrivateColormapFlag) + XAllocColor(theDisplay, thePrivateColormap, &color); + else + XAllocColor(theDisplay, DefaultColormap(theDisplay, theScreen), &color); + + XGCValues values; + values.foreground = color.pixel; + + if(theGCTable[t]) + XFreeGC(theDisplay, theGCTable[t]); + + theGCTable[t] = XCreateGC(theDisplay, theWindow, GCForeground, &values); + } +} + /** This routine should be called anytime the display needs to be updated */ @@ -883,7 +905,12 @@ void togglePause() thePauseIndicator = true; } + // Pause the console theConsole->mediaSource().pause(thePauseIndicator); + + // Show a different palette depending on pause state + setupPalette(); + theRedrawEntireFrameIndicator = true; } /**