Reworked snapshot support for the SDL version. Imlib is no longer needed

for SDL version, just the PNG library.  Fullscreen snapshot support is
working again.

Removed choice of adding snapshot to SDL version; now it is always added.
As a result, the 'libpng' library is needed to compile SDL version.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@42 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2002-02-17 04:41:42 +00:00
parent 24050a1ce6
commit 5a8ca97c59
5 changed files with 377 additions and 152 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: makefile,v 1.7 2002-02-03 16:51:21 stephena Exp $ ## $Id: makefile,v 1.8 2002-02-17 04:41:41 stephena Exp $
##============================================================================ ##============================================================================
##============================================================================ ##============================================================================
@ -23,16 +23,20 @@
## Comment a line out to disable that option, remove comment to enable it. ## Comment a line out to disable that option, remove comment to enable it.
##============================================================================ ##============================================================================
### this should work with all compilers
OPTIMIZATIONS =
### for normal optimization, full warnings ### for normal optimization, full warnings
# OPTIMIZATIONS = -O -Wall # OPTIMIZATIONS = -O -Wall
### for common optimizations, full warnings except unused vars ### for common optimizations, full warnings except unused vars
# OPTIMIZATIONS = -O2 -Wall -Wno-unused # OPTIMIZATIONS = -O2 -Wall -Wno-unused
### this should work with all compilers
OPTIMIZATIONS =
### to get full optimization under gcc/x Intel based OS's.. ### to get full optimization under gcc/x Intel based OS's..
# OPTIMIZATIONS = -O3 -mcpu=pentiumpro -march=pentiumpro -Wall -Wno-unused \ # OPTIMIZATIONS = -O3 -mcpu=pentiumpro -march=pentiumpro -Wall -Wno-unused \
# -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \ # -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \
# -malign-functions=2 -malign-jumps=2 -malign-loops=2 # -malign-functions=2 -malign-jumps=2 -malign-loops=2
### to get full optimization under gcc/x Athlon based OS's..
# OPTIMIZATIONS = -O3 -march=athlon -Wall -Wno-unused \
# -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \
# -malign-functions=2 -malign-jumps=2 -malign-loops=2
### if your C++ compiler doesn't support the bool type ### if your C++ compiler doesn't support the bool type
@ -49,9 +53,8 @@ OPTIMIZATIONS =
# LINUX_JOYSTICK = 1 # LINUX_JOYSTICK = 1
### to include support for saving snapshots in png format ### to include support for saving snapshots in png format
### (X and SDL versions only) ### (X version requires Imlib)
### (requires you to install Imlib) # X11_SNAPSHOT = 1
# IMLIB_SNAPSHOT = 1
##============================================================================ ##============================================================================
## All done, type make to get a list of frontends ## All done, type make to get a list of frontends
@ -104,16 +107,12 @@ ifdef LINUX_JOYSTICK
OPTS.X11 += -DLINUX_JOYSTICK OPTS.X11 += -DLINUX_JOYSTICK
endif endif
ifdef IMLIB_SNAPSHOT ifdef X11_SNAPSHOT
OPTS.X11 += -DIMLIB_SNAPSHOT OPTS.X11 += -DHAVE_IMLIB
LIBS.X11 += `imlib-config --libs` LIBS.X11 += `imlib-config --libs`
CFLAGS.X11 += `imlib-config --cflags` CFLAGS.X11 += `imlib-config --cflags`
OPTS.SDL += -DIMLIB_SNAPSHOT
LIBS.SDL += `imlib-config --libs`
CFLAGS.SDL += `imlib-config --cflags`
endif endif
default: default:
@echo "" @echo ""
@echo "To build Stella type: 'make <version>'" @echo "To build Stella type: 'make <version>'"
@ -174,9 +173,9 @@ linux-sdl:
OPTIONS+="$(OPTS.SDL)" \ OPTIONS+="$(OPTS.SDL)" \
LDFLAGS="-L/usr/X11R6/lib" \ LDFLAGS="-L/usr/X11R6/lib" \
LDFLAGS+="$(CFLAGS.SDL)" \ LDFLAGS+="$(CFLAGS.SDL)" \
LDLIBS="-lX11 -lXext" \ LDLIBS="-lX11 -lXext -lpng" \
LDLIBS+="$(LIBS.SDL)" \ LDLIBS+="$(LIBS.SDL)" \
OBJS="mainSDL.o SndUnix.o" OBJS="mainSDL.o SndUnix.o SnapSDL.o"
bsdi-x: bsdi-x:
make stella.x11 \ make stella.x11 \
@ -383,6 +382,9 @@ mainX11.o: $(UI)/x11/mainX11.cxx
mainSDL.o: $(UI)/sdl/mainSDL.cxx mainSDL.o: $(UI)/sdl/mainSDL.cxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(LDFLAGS) $(UI)/sdl/mainSDL.cxx $(CXX) -c $(CXXFLAGS) $(OPTIONS) $(LDFLAGS) $(UI)/sdl/mainSDL.cxx
SnapSDL.o: $(UI)/sdl/SnapSDL.cxx $(UI)/sdl/SnapSDL.hxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(LDFLAGS) $(UI)/sdl/SnapSDL.cxx
SndUnix.o: $(UI)/sound/SndUnix.cxx SndUnix.o: $(UI)/sound/SndUnix.cxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(UI)/sound/SndUnix.cxx $(CXX) -c $(CXXFLAGS) $(OPTIONS) $(UI)/sound/SndUnix.cxx

View File

@ -0,0 +1,178 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-1999 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SnapSDL.cxx,v 1.1 2002-02-17 04:41:41 stephena Exp $
//============================================================================
#include <SDL.h>
#include <png.h>
#include <stdlib.h>
#include <iostream>
#include "SnapSDL.hxx"
SnapshotSDL::SnapshotSDL()
{
}
SnapshotSDL::~SnapshotSDL()
{
}
int SnapshotSDL::savePNG(SDL_Surface *surface, const char *file)
{
SDL_RWops *out = SDL_RWFromFile(file, "wb");
if(!out)
return -1;
int ret = IMG_SavePNG_RW(surface, out);
SDL_RWclose(out);
return ret;
}
/* Save a PNG type image to an SDL datasource */
void SnapshotSDL::png_write_data(png_structp ctx, png_bytep area, png_size_t size)
{
SDL_RWops *src;
src = (SDL_RWops *) png_get_io_ptr(ctx);
SDL_RWwrite(src, area, size, 1);
}
void SnapshotSDL::png_io_flush(png_structp ctx)
{
SDL_RWops *src;
src = (SDL_RWops *)png_get_io_ptr(ctx);
/* how do I flush src? */
}
int SnapshotSDL::png_colortype_from_surface(SDL_Surface *surface)
{
int colortype = PNG_COLOR_MASK_COLOR; /* grayscale not supported */
if (surface->format->palette)
colortype |= PNG_COLOR_MASK_PALETTE;
else if (surface->format->Amask)
colortype |= PNG_COLOR_MASK_ALPHA;
return colortype;
}
void SnapshotSDL::png_user_warn(png_structp ctx, png_const_charp str)
{
cerr << "SnapshotSDL: libpng warning: " << str << endl;
}
void SnapshotSDL::png_user_error(png_structp ctx, png_const_charp str)
{
cerr << "SnapshotSDL: libpng error: " << str << endl;
}
int SnapshotSDL::IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *src)
{
png_structp png_ptr = 0;
png_infop info_ptr = 0;
png_colorp palette = 0;
png_bytep *row_pointers = 0;
int i;
int colortype;
int result = 0;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_user_error, png_user_warn);
if(png_ptr == NULL)
{
cerr << "SnapshotSDL: Couldn't allocate memory for PNG file\n";
return -1;
}
/* Allocate/initialize the image information data. REQUIRED */
info_ptr = png_create_info_struct(png_ptr);
if(info_ptr == NULL)
{
cerr << "SnapshotSDL: Couldn't create image information for PNG file\n";
goto done;
}
png_set_write_fn(png_ptr, src, png_write_data, png_io_flush);
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
*/
colortype = png_colortype_from_surface(surface);
png_set_IHDR(png_ptr, info_ptr, surface->w, surface->h, 8,
colortype, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
/* set the palette if there is one. REQUIRED for indexed-color images */
if(colortype & PNG_COLOR_MASK_PALETTE)
{
palette = (png_colorp)malloc(surface->format->palette->ncolors * sizeof (png_color));
if(!palette)
{
cerr << "SnapshotSDL: Couldn't allocate memory for PNG palette\n";
goto done;
}
for(i = 0; i < surface->format->palette->ncolors; i++)
{
palette[i].red = surface->format->palette->colors[i].r;
palette[i].green = surface->format->palette->colors[i].g;
palette[i].blue = surface->format->palette->colors[i].b;
}
png_set_PLTE(png_ptr, info_ptr, palette, surface->format->palette->ncolors);
}
// Write the file header information. REQUIRED
png_write_info(png_ptr, info_ptr);
// pack pixels into bytes
png_set_packing(png_ptr);
// Create the array of pointers to image data
row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*surface->h);
if((row_pointers == NULL))
{
cerr << "SnapshotSDL: Couldn't allocate PNG row pointers\n";
goto done;
}
for(i = 0; i < surface->h; i++)
row_pointers[i] = (png_bytep)(Uint8 *)surface->pixels + i*surface->pitch;
// write out the entire image data in one call
png_write_image(png_ptr, row_pointers);
png_write_end(png_ptr, info_ptr);
result = 1;
done:
if(row_pointers)
free(row_pointers);
if(info_ptr->palette)
free(info_ptr->palette);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return result;
}

View File

@ -0,0 +1,48 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-1999 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SnapSDL.hxx,v 1.1 2002-02-17 04:41:41 stephena Exp $
//============================================================================
#ifndef SNAPSHOTSDL_HXX
#define SNAPSHOTSDL_HXX
#include <SDL.h>
#include <png.h>
class SnapshotSDL
{
public:
SnapshotSDL();
~SnapshotSDL();
int savePNG(SDL_Surface *surface, const char *file);
private:
static void png_write_data(png_structp ctx, png_bytep area, png_size_t size);
static void png_io_flush(png_structp ctx);
static void png_user_warn(png_structp ctx, png_const_charp str);
static void png_user_error(png_structp ctx, png_const_charp str);
int png_colortype_from_surface(SDL_Surface *surface);
int IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *src);
};
#endif

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.8 2002-02-06 00:59:36 stephena Exp $ // $Id: mainSDL.cxx,v 1.9 2002-02-17 04:41:41 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -39,18 +39,8 @@
#include "PropsSet.hxx" #include "PropsSet.hxx"
#include "System.hxx" #include "System.hxx"
#include "SndUnix.hxx" #include "SndUnix.hxx"
#include "SnapSDL.hxx"
#ifdef IMLIB_SNAPSHOT
#include <Imlib.h>
ImlibData* imlibData;
// The path to save snapshot files
string theSnapShotDir = "";
// What the snapshot should be called (romname or md5sum)
string theSnapShotName = "";
#endif
SDL_Joystick* theLeftJoystick; SDL_Joystick* theLeftJoystick;
SDL_Joystick* theRightJoystick; SDL_Joystick* theRightJoystick;
@ -58,6 +48,7 @@ SDL_Joystick* theRightJoystick;
// function prototypes // function prototypes
bool setupDisplay(); bool setupDisplay();
bool setupJoystick(); bool setupJoystick();
bool createScreen(int width, int height);
void cleanup(); void cleanup();
void updateDisplay(MediaSource& mediaSource); void updateDisplay(MediaSource& mediaSource);
@ -81,6 +72,7 @@ void usage();
// Globals for the SDL stuff // Globals for the SDL stuff
static SDL_Surface* screen; static SDL_Surface* screen;
static Uint32 palette[256];
static int bpp; static int bpp;
static Display* theX11Display; static Display* theX11Display;
static Window theX11Window; static Window theX11Window;
@ -88,9 +80,9 @@ static int theX11Screen;
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 SnapshotSDL* snapshot;
// SDL colors palette
static Uint32 colors[256];
struct Switches struct Switches
{ {
@ -203,12 +195,12 @@ bool theShowInfoFlag = false;
// Indicates whether to show cursor in the game window // Indicates whether to show cursor in the game window
bool theHideCursorFlag = false; bool theHideCursorFlag = false;
// Indicates whether the game is currently in fullscreen
bool isFullscreen = false;
// Indicates whether to allocate colors from a private color map // Indicates whether to allocate colors from a private color map
bool theUsePrivateColormapFlag = false; bool theUsePrivateColormapFlag = false;
// Indicates whether the game is currently in fullscreen
bool isFullscreen = false;
// Indicates whether the window is currently centered // Indicates whether the window is currently centered
bool isCentered = false; bool isCentered = false;
@ -229,6 +221,12 @@ uInt32 thePaddleMode = 0;
// An alternate properties file to use // An alternate properties file to use
string theAlternateProFile = ""; string theAlternateProFile = "";
// The path to save snapshot files
string theSnapShotDir = "";
// What the snapshot should be called (romname or md5sum)
string theSnapShotName = "";
/** /**
This routine should be called once the console is created to setup This routine should be called once the console is created to setup
@ -250,8 +248,12 @@ bool setupDisplay()
if(info.subsystem == SDL_SYSWM_X11) if(info.subsystem == SDL_SYSWM_X11)
x11Available = true; x11Available = true;
int sdlflags = SDL_HWSURFACE | SDL_HWPALETTE; sdlflags = SDL_HWSURFACE;
sdlflags |= theUseFullScreenFlag ? SDL_FULLSCREEN : 0; sdlflags |= theUseFullScreenFlag ? SDL_FULLSCREEN : 0;
sdlflags |= theUsePrivateColormapFlag ? SDL_HWPALETTE : 0;
// Always use an 8-bit screen since the Atari 2600 had less than 256 colors
bpp = 8;
// Get the desired width and height of the display // Get the desired width and height of the display
theWidth = theConsole->mediaSource().width(); theWidth = theConsole->mediaSource().width();
@ -283,13 +285,9 @@ bool setupDisplay()
int width = theWidth * 2 * theWindowSize; int width = theWidth * 2 * theWindowSize;
int height = theHeight * theWindowSize; int height = theHeight * theWindowSize;
screen = SDL_SetVideoMode(width, height, 0, sdlflags); // Create the screen
if(screen == NULL) if(!createScreen(width, height))
{
cerr << "ERROR: Unable to open SDL window: " << SDL_GetError() << endl;
return false; return false;
}
bpp = screen->format->BitsPerPixel;
// set the window title and icon name // set the window title and icon name
char name[512]; char name[512];
@ -297,44 +295,6 @@ bool setupDisplay()
theConsole->properties().get("Cartridge.Name").c_str()); theConsole->properties().get("Cartridge.Name").c_str());
SDL_WM_SetCaption(name, "stella"); SDL_WM_SetCaption(name, "stella");
// Create the color palette based on screen bpp
const uInt32* palette = theConsole->mediaSource().palette();
for(uInt32 i = 0; i < 256; i += 2)
{
Uint8 r, g, b;
r = (Uint8) ((palette[i] & 0x00ff0000) >> 16);
g = (Uint8) ((palette[i] & 0x0000ff00) >> 8);
b = (Uint8) (palette[i] & 0x000000ff);
switch(bpp)
{
case 8:
SDL_Color color;
color.r = r;
color.g = g;
color.b = b;
SDL_SetColors(screen, &color, i, 1);
break;
case 15:
colors[i] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
colors[i + 1] = colors[i];
break;
case 16:
colors[i] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
colors[i + 1] = colors[i];
break;
case 32:
colors[i] = (r << 16) | (g << 8) | b;
colors[i + 1] = colors[i];
break;
}
}
// Make sure that theUseFullScreenFlag sets up fullscreen mode correctly // Make sure that theUseFullScreenFlag sets up fullscreen mode correctly
if(theUseFullScreenFlag) if(theUseFullScreenFlag)
{ {
@ -355,25 +315,15 @@ bool setupDisplay()
if(theCenterWindowFlag && !theUseFullScreenFlag) if(theCenterWindowFlag && !theUseFullScreenFlag)
centerWindow(); centerWindow();
#ifdef IMLIB_SNAPSHOT // Take care of the snapshot stuff
if(x11Available) snapshot = new SnapshotSDL();
{
info.info.x11.lock_func();
theX11Display = info.info.x11.display;
theX11Window = info.info.x11.wmwindow;
theX11Screen = DefaultScreen(theX11Display);
info.info.x11.unlock_func();
imlibData = Imlib_init(theX11Display); // By default, snapshot dir is HOME and name is ROMNAME, assuming that
// they haven't been specified on the commandline
// By default, snapshot dir is HOME and name is ROMNAME, assuming that if(theSnapShotDir == "")
// they haven't been specified on the commandline theSnapShotDir = getenv("HOME");
if(theSnapShotDir == "") if(theSnapShotName == "")
theSnapShotDir = getenv("HOME"); theSnapShotName = "romname";
if(theSnapShotName == "")
theSnapShotName = "romname";
}
#endif
return true; return true;
} }
@ -409,6 +359,55 @@ bool setupJoystick()
} }
/**
This routine is called whenever the screen needs to be recreated.
It updates the global screen variable. When this happens, the
palette has to be recalculated as well.
*/
bool createScreen(int w, int h)
{
screen = SDL_SetVideoMode(w, h, bpp, sdlflags);
if(screen == NULL)
{
cerr << "ERROR: Unable to open SDL window: " << SDL_GetError() << endl;
return false;
}
// Now set the screen palette
const uInt32* gamePalette = theConsole->mediaSource().palette();
SDL_Color colors[256];
for(uInt32 i = 0; i < 256; i += 2)
{
Uint8 r, g, b;
r = (Uint8) ((gamePalette[i] & 0x00ff0000) >> 16);
g = (Uint8) ((gamePalette[i] & 0x0000ff00) >> 8);
b = (Uint8) (gamePalette[i] & 0x000000ff);
colors[i].r = colors[i+1].r = r;
colors[i].g = colors[i+1].g = g;
colors[i].b = colors[i+1].b = b;
}
SDL_SetColors(screen, colors, 0, 256);
// Now see which colors we actually got
SDL_PixelFormat* format = screen->format;
for(uInt32 i = 0; i < 256; i += 2)
{
Uint8 r, g, b;
r = format->palette->colors[i].r;
g = format->palette->colors[i].g;
b = format->palette->colors[i].b;
palette[i] = SDL_MapRGB(format, r, g, b);
palette[i+1] = palette[i];
}
return true;
}
/** /**
This routine is called when the program is about to quit. This routine is called when the program is about to quit.
*/ */
@ -449,13 +448,8 @@ void resizeWindow(int mode)
int width = theWidth * 2 * theWindowSize; int width = theWidth * 2 * theWindowSize;
int height = theHeight * theWindowSize; int height = theHeight * theWindowSize;
screen = SDL_SetVideoMode(width, height, 0, SDL_HWSURFACE | SDL_HWPALETTE); if(!createScreen(width, height))
if(screen == NULL)
{
cerr << "Unable to resize SDL window: " << SDL_GetError() << endl;
return; return;
}
bpp = screen->format->BitsPerPixel;
theRedrawEntireFrameFlag = true; theRedrawEntireFrameFlag = true;
@ -507,17 +501,15 @@ void toggleFullscreen()
{ {
int width = theWidth * 2 * theWindowSize; int width = theWidth * 2 * theWindowSize;
int height = theHeight * theWindowSize; int height = theHeight * theWindowSize;
int sdlflags = SDL_HWSURFACE | SDL_HWPALETTE;
isFullscreen = !isFullscreen;
sdlflags |= isFullscreen ? SDL_FULLSCREEN : 0;
screen = SDL_SetVideoMode(width, height, 0, sdlflags); isFullscreen = !isFullscreen;
if(screen == NULL) if(isFullscreen)
{ sdlflags |= SDL_FULLSCREEN;
cerr << "Unable to switch screenmode: " << SDL_GetError() << endl; else
sdlflags &= ~SDL_FULLSCREEN;
if(!createScreen(width, height))
return; return;
}
bpp = screen->format->BitsPerPixel;
if(isFullscreen) // now in fullscreen mode if(isFullscreen) // now in fullscreen mode
{ {
@ -680,7 +672,7 @@ void updateDisplay(MediaSource& mediaSource)
rect.y = active.y * screenMultiple; rect.y = active.y * screenMultiple;
rect.w = active.width * 2 * screenMultiple; rect.w = active.width * 2 * screenMultiple;
rect.h = active.height * screenMultiple; rect.h = active.height * screenMultiple;
SDL_FillRect(screen, &rect, colors[active.color]); SDL_FillRect(screen, &rect, palette[active.color]);
++activeIndex; ++activeIndex;
} }
@ -695,7 +687,7 @@ void updateDisplay(MediaSource& mediaSource)
rect.y = active.y * screenMultiple; rect.y = active.y * screenMultiple;
rect.w = active.width * 2 * screenMultiple; rect.w = active.width * 2 * screenMultiple;
rect.h = active.height * screenMultiple; rect.h = active.height * screenMultiple;
SDL_FillRect(screen, &rect, colors[active.color]); SDL_FillRect(screen, &rect, palette[active.color]);
} }
// We can now make the current rectangles into the active rectangles // We can now make the current rectangles into the active rectangles
@ -717,7 +709,7 @@ void updateDisplay(MediaSource& mediaSource)
rect.y = active.y * screenMultiple; rect.y = active.y * screenMultiple;
rect.w = active.width * 2 * screenMultiple; rect.w = active.width * 2 * screenMultiple;
rect.h = active.height * screenMultiple; rect.h = active.height * screenMultiple;
SDL_FillRect(screen, &rect, colors[active.color]); SDL_FillRect(screen, &rect, palette[active.color]);
} }
SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
@ -777,7 +769,7 @@ void handleEvents()
} }
else if(key == SDLK_g) else if(key == SDLK_g)
{ {
// don't turn off grabmouse in fullscreen or we may lose the keyboard // don't change grabmouse in fullscreen mode
if(!isFullscreen) if(!isFullscreen)
{ {
theGrabMouseFlag = !theGrabMouseFlag; theGrabMouseFlag = !theGrabMouseFlag;
@ -786,8 +778,12 @@ void handleEvents()
} }
else if(key == SDLK_h) else if(key == SDLK_h)
{ {
theHideCursorFlag = !theHideCursorFlag; // don't change hidecursor in fullscreen mode
showCursor(!theHideCursorFlag); if(!isFullscreen)
{
theHideCursorFlag = !theHideCursorFlag;
showCursor(!theHideCursorFlag);
}
} }
else // check all the other keys else // check all the other keys
{ {
@ -1037,29 +1033,20 @@ void handleEvents()
*/ */
void takeSnapshot() void takeSnapshot()
{ {
#ifdef IMLIB_SNAPSHOT if(!snapshot)
if(!x11Available)
{ {
cerr << "Snapshot support only available under X11.\n"; cerr << "Snapshot support disabled.\n";
return; return;
} }
else if(isFullscreen) /* else if(isFullscreen)
{ {
cerr << "Snapshot support unavailable in fullscreen (for now).\n"; cerr << "Snapshot support unavailable in fullscreen (for now).\n";
return; return;
} }
*/
int width = screen->w; int width = screen->w;
int height = screen->h; int height = screen->h;
ImlibImage* image = Imlib_create_image_from_drawable(imlibData, theX11Window,
0, 0, 0, width, height);
if(image == NULL)
{
cerr << "Could not create snapshot!!\n";
return;
}
// Now find the correct name for the snapshot // Now find the correct name for the snapshot
string filename = theSnapShotDir; string filename = theSnapShotDir;
if(theSnapShotName == "romname") if(theSnapShotName == "romname")
@ -1096,16 +1083,12 @@ void takeSnapshot()
filename = extFilename; filename = extFilename;
// Now save the snapshot file // Now save the snapshot file
Imlib_save_image(imlibData, image, (char*)filename.c_str(), NULL); snapshot->savePNG(screen, filename.c_str());
Imlib_kill_image(imlibData, image);
if(access(filename.c_str(), F_OK) == 0) if(access(filename.c_str(), F_OK) == 0)
cerr << "Snapshot saved as " << filename << endl; cerr << "Snapshot saved as " << filename << endl;
else else
cerr << "Couldn't create snapshot " << filename << endl; cerr << "Couldn't create snapshot " << filename << endl;
#else
cerr << "Snapshot mode not supported.\n";
#endif
} }
@ -1166,6 +1149,7 @@ void usage()
"Valid options are:", "Valid options are:",
"", "",
" -fps <number> Display the given number of frames per second", " -fps <number> Display the given number of frames per second",
" -owncmap Install a private colormap",
" -winsize <size> Makes initial window be 'size' times normal", " -winsize <size> Makes initial window be 'size' times normal",
" -fullscreen Play the game in fullscreen mode", " -fullscreen Play the game in fullscreen mode",
" -grabmouse Keeps the mouse in the game window", " -grabmouse Keeps the mouse in the game window",
@ -1175,10 +1159,8 @@ void usage()
" -paddle <0|1|2|3|real> Indicates which paddle the mouse should emulate", " -paddle <0|1|2|3|real> Indicates which paddle the mouse should emulate",
" or that real Atari 2600 paddles are being used", " or that real Atari 2600 paddles are being used",
" -showinfo Shows some game info on exit", " -showinfo Shows some game info on exit",
#ifdef IMLIB_SNAPSHOT
" -ssdir <path> The directory to save snapshot files to", " -ssdir <path> The directory to save snapshot files to",
" -ssname <name> How to name the snapshot (romname or md5sum)", " -ssname <name> How to name the snapshot (romname or md5sum)",
#endif
" -pro <props file> Use the given properties file instead of stella.pro", " -pro <props file> Use the given properties file instead of stella.pro",
"", "",
0 0
@ -1283,6 +1265,10 @@ void handleCommandLineArguments(int argc, char* argv[])
} }
++i; ++i;
} }
else if(string(argv[i]) == "-owncmap")
{
theUsePrivateColormapFlag = true;
}
else if(string(argv[i]) == "-fullscreen") else if(string(argv[i]) == "-fullscreen")
{ {
theUseFullScreenFlag = true; theUseFullScreenFlag = true;
@ -1319,7 +1305,6 @@ void handleCommandLineArguments(int argc, char* argv[])
theDesiredVolume = volume; theDesiredVolume = volume;
} }
#ifdef IMLIB_SNAPSHOT
else if(string(argv[i]) == "-ssdir") else if(string(argv[i]) == "-ssdir")
{ {
theSnapShotDir = argv[++i]; theSnapShotDir = argv[++i];
@ -1328,7 +1313,6 @@ void handleCommandLineArguments(int argc, char* argv[])
{ {
theSnapShotName = argv[++i]; theSnapShotName = argv[++i];
} }
#endif
else if(string(argv[i]) == "-pro") else if(string(argv[i]) == "-pro")
{ {
theAlternateProFile = argv[++i]; theAlternateProFile = argv[++i];
@ -1425,6 +1409,14 @@ void parseRCOptions(istream& in)
thePaddleMode = pMode; thePaddleMode = pMode;
} }
} }
else if(key == "owncmap")
{
uInt32 option = atoi(value.c_str());
if(option == 1)
theUsePrivateColormapFlag = true;
else if(option == 0)
theUsePrivateColormapFlag = false;
}
else if(key == "fullscreen") else if(key == "fullscreen")
{ {
uInt32 option = atoi(value.c_str()); uInt32 option = atoi(value.c_str());
@ -1483,7 +1475,6 @@ void parseRCOptions(istream& in)
theDesiredVolume = volume; theDesiredVolume = volume;
} }
#ifdef IMLIB_SNAPSHOT
else if(key == "ssdir") else if(key == "ssdir")
{ {
theSnapShotDir = value; theSnapShotDir = value;
@ -1492,7 +1483,6 @@ void parseRCOptions(istream& in)
{ {
theSnapShotName = value; theSnapShotName = value;
} }
#endif
} }
} }
@ -1505,6 +1495,9 @@ void cleanup()
if(theConsole) if(theConsole)
delete theConsole; delete theConsole;
if(snapshot)
delete snapshot;
if(SDL_JoystickOpened(0)) if(SDL_JoystickOpened(0))
SDL_JoystickClose(theLeftJoystick); SDL_JoystickClose(theLeftJoystick);
if(SDL_JoystickOpened(1)) if(SDL_JoystickOpened(1))

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.8 2002-02-06 00:59:36 stephena Exp $ // $Id: mainX11.cxx,v 1.9 2002-02-17 04:41:42 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -43,7 +43,7 @@
#include "SndUnix.hxx" #include "SndUnix.hxx"
#include "System.hxx" #include "System.hxx"
#ifdef IMLIB_SNAPSHOT #ifdef HAVE_IMLIB
#include <Imlib.h> #include <Imlib.h>
ImlibData* imlibData; ImlibData* imlibData;
@ -217,12 +217,12 @@ bool theShowInfoFlag = false;
// Indicates whether to show cursor in the game window // Indicates whether to show cursor in the game window
bool theHideCursorFlag = false; bool theHideCursorFlag = false;
// Indicates whether the game is currently in fullscreen
bool isFullscreen = false;
// Indicates whether to allocate colors from a private color map // Indicates whether to allocate colors from a private color map
bool theUsePrivateColormapFlag = false; bool theUsePrivateColormapFlag = false;
// Indicates whether the game is currently in fullscreen
bool isFullscreen = false;
// Indicates whether the window is currently centered // Indicates whether the window is currently centered
bool isCentered = false; bool isCentered = false;
@ -390,7 +390,7 @@ bool setupDisplay()
XSelectInput(theDisplay, theWindow, eventMask); XSelectInput(theDisplay, theWindow, eventMask);
// If imlib snapshots are enabled, set up some imlib stuff // If imlib snapshots are enabled, set up some imlib stuff
#ifdef IMLIB_SNAPSHOT #ifdef HAVE_IMLIB
imlibData = Imlib_init(theDisplay); imlibData = Imlib_init(theDisplay);
// By default, snapshot dir is HOME and name is ROMNAME, assuming that // By default, snapshot dir is HOME and name is ROMNAME, assuming that
@ -598,7 +598,7 @@ void handleEvents()
} }
else if((key == XK_g) && (event.type == KeyPress)) else if((key == XK_g) && (event.type == KeyPress))
{ {
// don't turn off grabmouse in fullscreen or we may lose the keyboard // don't change grabmouse in fullscreen mode
if(!isFullscreen) if(!isFullscreen)
{ {
theGrabMouseFlag = !theGrabMouseFlag; theGrabMouseFlag = !theGrabMouseFlag;
@ -607,8 +607,12 @@ void handleEvents()
} }
else if((key == XK_h) && (event.type == KeyPress)) else if((key == XK_h) && (event.type == KeyPress))
{ {
theHideCursorFlag = !theHideCursorFlag; // don't change hidecursor in fullscreen mode
showCursor(!theHideCursorFlag); if(!isFullscreen)
{
theHideCursorFlag = !theHideCursorFlag;
showCursor(!theHideCursorFlag);
}
} }
else else
{ {
@ -1008,7 +1012,7 @@ bool createCursors()
*/ */
void takeSnapshot() void takeSnapshot()
{ {
#ifdef IMLIB_SNAPSHOT #ifdef HAVE_IMLIB
// Figure out the actual size of the window // Figure out the actual size of the window
int width = theWidth * 2 * theWindowSize; int width = theWidth * 2 * theWindowSize;
int height = theHeight * theWindowSize; int height = theHeight * theWindowSize;
@ -1127,7 +1131,7 @@ void usage()
" -paddle <0|1|2|3> Indicates which paddle the mouse should emulate", " -paddle <0|1|2|3> Indicates which paddle the mouse should emulate",
#endif #endif
" -showinfo Shows some game info on exit", " -showinfo Shows some game info on exit",
#ifdef IMLIB_SNAPSHOT #ifdef HAVE_IMLIB
" -ssdir <path> The directory to save snapshot files to", " -ssdir <path> The directory to save snapshot files to",
" -ssname <name> How to name the snapshot (romname or md5sum)", " -ssname <name> How to name the snapshot (romname or md5sum)",
#endif #endif
@ -1277,7 +1281,7 @@ void handleCommandLineArguments(int argc, char* argv[])
theDesiredVolume = volume; theDesiredVolume = volume;
} }
#ifdef IMLIB_SNAPSHOT #ifdef HAVE_IMLIB
else if(string(argv[i]) == "-ssdir") else if(string(argv[i]) == "-ssdir")
{ {
theSnapShotDir = argv[++i]; theSnapShotDir = argv[++i];
@ -1451,7 +1455,7 @@ void parseRCOptions(istream& in)
theDesiredVolume = volume; theDesiredVolume = volume;
} }
#ifdef IMLIB_SNAPSHOT #ifdef HAVE_IMLIB
else if(key == "ssdir") else if(key == "ssdir")
{ {
theSnapShotDir = value; theSnapShotDir = value;