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
This commit is contained in:
stephena 2002-04-10 23:51:18 +00:00
parent ab1d10bf3a
commit e462ac656d
2 changed files with 100 additions and 54 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <fstream> #include <fstream>
@ -79,19 +79,19 @@ static void handleRCFile();
static void usage(); static void usage();
// Globals for the SDL stuff // Globals for the SDL stuff
static SDL_Surface* screen; static SDL_Surface* screen = (SDL_Surface*) NULL;
static Uint32 palette[256]; static Uint32 palette[256];
static int bpp; static int bpp;
static Display* theX11Display; static Display* theX11Display = (Display*) NULL;
static Window theX11Window; static Window theX11Window = 0;
static int theX11Screen; static int theX11Screen = 0;
static int mouseX = 0; static int mouseX = 0;
static bool x11Available = false; static bool x11Available = false;
static SDL_SysWMinfo info; static SDL_SysWMinfo info;
static int sdlflags; static int sdlflags;
static RectList* rectList; static RectList* rectList = (RectList*) NULL;
static SDL_Joystick* theLeftJoystick; static SDL_Joystick* theLeftJoystick = (SDL_Joystick*) NULL;
static SDL_Joystick* theRightJoystick; static SDL_Joystick* theRightJoystick = (SDL_Joystick*) NULL;
#ifdef HAVE_PNG #ifdef HAVE_PNG
static Snapshot* snapshot; static Snapshot* snapshot;
@ -171,10 +171,10 @@ static Event theEvent;
static Event keyboardEvent; static Event keyboardEvent;
// Pointer to the console object or the null pointer // 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 // Pointer to the settings object or the null pointer
static Settings* settings; static Settings* settings = (Settings*) NULL;
// Indicates if the user wants to quit // Indicates if the user wants to quit
static bool theQuitIndicator = false; static bool theQuitIndicator = false;
@ -357,6 +357,11 @@ void recalculate8BitPalette()
if(bpp != 8) if(bpp != 8)
return; 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 // Map 2600 colors to the current screen
const uInt32* gamePalette = theConsole->mediaSource().palette(); const uInt32* gamePalette = theConsole->mediaSource().palette();
SDL_Color colors[256]; SDL_Color colors[256];
@ -364,9 +369,9 @@ void recalculate8BitPalette()
{ {
Uint8 r, g, b; Uint8 r, g, b;
r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16); r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16) >> shift;
g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8); g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8) >> shift;
b = (Uint8) (gamePalette[i] & 0x000000ff); b = (Uint8) (gamePalette[i] & 0x000000ff) >> shift;
colors[i].r = r; colors[i].r = r;
colors[i].g = g; 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() void setupPalette()
{ {
if(bpp == 8) if(bpp == 8)
{
recalculate8BitPalette();
return; return;
}
// Make the palette be half-bright if pause is selected
uInt8 shift = 0;
if(thePauseIndicator)
shift = 1;
const uInt32* gamePalette = theConsole->mediaSource().palette(); const uInt32* gamePalette = theConsole->mediaSource().palette();
for(uInt32 i = 0; i < 256; ++i) for(uInt32 i = 0; i < 256; ++i)
{ {
Uint8 r, g, b; Uint8 r, g, b;
r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16); r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16) >> shift;
g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8); g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8) >> shift;
b = (Uint8) (gamePalette[i] & 0x000000ff); b = (Uint8) (gamePalette[i] & 0x000000ff) >> shift;
switch(bpp) switch(bpp)
{ {
@ -560,7 +574,12 @@ void togglePause()
thePauseIndicator = true; thePauseIndicator = true;
} }
// Pause the console
theConsole->mediaSource().pause(thePauseIndicator); theConsole->mediaSource().pause(thePauseIndicator);
// Show a different palette depending on pause state
setupPalette();
theRedrawEntireFrameIndicator = true;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <fstream> #include <fstream>
@ -60,6 +60,7 @@ static GC theGCTable[256];
static bool setupDisplay(); static bool setupDisplay();
static bool setupJoystick(); static bool setupJoystick();
static bool createCursors(); static bool createCursors();
static void setupPalette();
static void cleanup(); static void cleanup();
static void updateDisplay(MediaSource& mediaSource); static void updateDisplay(MediaSource& mediaSource);
@ -81,14 +82,14 @@ static void handleRCFile();
static void usage(); static void usage();
// Globals for X windows stuff // Globals for X windows stuff
static Display* theDisplay; static Display* theDisplay = (Display*) NULL;
static string theDisplayName = ""; static string theDisplayName = "";
static int theScreen; static int theScreen = 0;
static Visual* theVisual; static Visual* theVisual = (Visual*) NULL;
static Window theWindow; static Window theWindow = 0;
static Colormap thePrivateColormap; static Colormap thePrivateColormap = 0;
static Cursor normalCursor; static Cursor normalCursor = 0;
static Cursor blankCursor; static Cursor blankCursor = 0;
static uInt32 eventMask; static uInt32 eventMask;
static Atom wm_delete_window; static Atom wm_delete_window;
@ -177,10 +178,10 @@ static Event theEvent;
static Event keyboardEvent; static Event keyboardEvent;
// Pointer to the console object or the null pointer // 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 // Pointer to the settings object or the null pointer
static Settings* settings; static Settings* settings = (Settings*) NULL;
// Indicates if the user wants to quit // Indicates if the user wants to quit
static bool theQuitIndicator = false; static bool theQuitIndicator = false;
@ -265,13 +266,6 @@ bool setupDisplay()
return false; return false;
} }
// If requested create a private colormap for the window
if(settings->theUsePrivateColormapFlag)
{
thePrivateColormap = XCreateColormap(theDisplay, theWindow,
theVisual, AllocNone);
}
XSizeHints hints; XSizeHints hints;
hints.flags = PSize | PMinSize | PMaxSize; hints.flags = PSize | PMinSize | PMaxSize;
hints.min_width = hints.max_width = hints.width = width; hints.min_width = hints.max_width = hints.width = width;
@ -283,26 +277,8 @@ bool setupDisplay()
theConsole->properties().get("Cartridge.Name").c_str()); theConsole->properties().get("Cartridge.Name").c_str());
XmbSetWMProperties(theDisplay, theWindow, name, "stella", 0, 0, &hints, None, None); XmbSetWMProperties(theDisplay, theWindow, name, "stella", 0, 0, &hints, None, None);
// Allocate colors in the default colormap // Set up the palette for the screen
const uInt32* palette = theConsole->mediaSource().palette(); setupPalette();
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 delete window stuff ... // Set up the delete window stuff ...
wm_delete_window = XInternAtom(theDisplay, "WM_DELETE_WINDOW", False); wm_delete_window = XInternAtom(theDisplay, "WM_DELETE_WINDOW", False);
@ -374,6 +350,52 @@ bool setupJoystick()
return true; 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 This routine should be called anytime the display needs to be updated
*/ */
@ -883,7 +905,12 @@ void togglePause()
thePauseIndicator = true; thePauseIndicator = true;
} }
// Pause the console
theConsole->mediaSource().pause(thePauseIndicator); theConsole->mediaSource().pause(thePauseIndicator);
// Show a different palette depending on pause state
setupPalette();
theRedrawEntireFrameIndicator = true;
} }
/** /**