added command line argurments for exiting on button pushes and

autoloading/autosaving

various other small changes around the source, but the big changes
to the program are the command line arguments
--abstartselectexit (0 or 1)
--autoload (0-9 or greater than 9 for no autoload)
--autosave (0-9 or greater than 9 for no autosave)

autosaving only occurs when sdl.cpp:CloseGame() is called, which
doesn't appear to happen when the window is "X'd out"
This commit is contained in:
xhainingx 2013-04-10 20:58:01 +00:00
parent f645cc891e
commit 0ad7a6ed08
9 changed files with 166 additions and 100 deletions

View File

@ -1,13 +1,12 @@
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <csignal>
#include <sys/time.h>
#include <sys/stat.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include "main.h"
#include "throttle.h"
@ -26,6 +25,7 @@
#include <windows.h>
#endif
/**
* Read a custom pallete from a file and load it into the core.
*/
@ -235,7 +235,9 @@ InitConfig()
config->addOption("mute", "SDL.MuteCapture", 0);
#endif
config->addOption("autoloadstate", "SDL.AutoLoadState", INVALID_STATE);
config->addOption("autosavestate", "SDL.AutoSaveState", INVALID_STATE);
#ifdef _GTK
char* home_dir = getenv("HOME");
@ -255,7 +257,9 @@ InitConfig()
// enable new PPU core
config->addOption("newppu", "SDL.NewPPU", 0);
// quit when a+b+select+start is pressed
config->addOption("abstartselectexit", "SDL.ABStartSelectExit", 0);
// GamePad 0 - 3
for(unsigned int i = 0; i < GAMEPAD_NUM_DEVICES; i++) {

View File

@ -9,18 +9,20 @@ int LoadCPalette(const std::string &file);
// hotkey definitions
// TODO: encapsulate this in an improved data structure
enum HOTKEY { HK_CHEAT_MENU, HK_BIND_STATE, HK_LOAD_LUA, HK_TOGGLE_BG,
enum HOTKEY { HK_CHEAT_MENU=0, HK_BIND_STATE, HK_LOAD_LUA, HK_TOGGLE_BG,
HK_SAVE_STATE, HK_FDS_SELECT, HK_LOAD_STATE, HK_FDS_EJECT ,
HK_VS_INSERT_COIN, HK_VS_TOGGLE_DIPSWITCH,
HK_TOGGLE_FRAME_DISPLAY, HK_TOGGLE_SUBTITLE, HK_RESET, HK_SCREENSHOT,
HK_PAUSE, HK_DECREASE_SPEED, HK_INCREASE_SPEED, HK_FRAME_ADVANCE, HK_TURBO,
HK_TOGGLE_INPUT_DISPLAY, HK_MOVIE_TOGGLE_RW, HK_MUTE_CAPTURE, HK_QUIT, HK_FA_LAG_SKIP, HK_LAG_COUNTER_DISPLAY,
HK_TOGGLE_INPUT_DISPLAY, HK_MOVIE_TOGGLE_RW, HK_MUTE_CAPTURE, HK_QUIT,
HK_FA_LAG_SKIP, HK_LAG_COUNTER_DISPLAY,
HK_SELECT_STATE_0, HK_SELECT_STATE_1, HK_SELECT_STATE_2, HK_SELECT_STATE_3,
HK_SELECT_STATE_4, HK_SELECT_STATE_5, HK_SELECT_STATE_6, HK_SELECT_STATE_7,
HK_SELECT_STATE_8, HK_SELECT_STATE_9,
HK_SELECT_STATE_NEXT, HK_SELECT_STATE_PREV};
HK_SELECT_STATE_NEXT, HK_SELECT_STATE_PREV, HK_MAX};
const int INVALID_STATE = 99;
const int HK_MAX = 37;
static const char* HotkeyStrings[HK_MAX] = {
"CheatMenu",

View File

@ -5,7 +5,6 @@
extern CFGSTRUCT DriverConfig[];
extern ARGPSTRUCT DriverArgs[];
extern char *DriverUsage;
void DoDriverArgs(void);

View File

@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include "main.h"
#include "dface.h"
@ -320,9 +320,12 @@ std::string GetFilename (const char *title, bool save, const char *filter)
std::string GetUserText (const char *title)
{
#ifdef _GTK
/* prg318 - 10/13/11 - this is broken in recent build and causes segfaults/very weird behavior
i'd rather remove it for now than it cause accidental segfaults
TODO fix it
/* prg318 - 10/13/11 - this is broken in recent build and causes
* segfaults/very weird behavior i'd rather remove it for now than it cause
* accidental segfaults
* TODO fix it
*/
#if 0
GtkWidget* d;
GtkWidget* entry;
@ -370,7 +373,7 @@ std::string GetUserText (const char *title)
break;
input += c;
}
pclose(fpipe);*//*
pclose(fpipe);
gtk_widget_destroy(d);
@ -379,7 +382,7 @@ std::string GetUserText (const char *title)
FCEUI_ToggleEmulationPause(); // unpause emulation
return input;
*/
#endif // #if 0
#endif
return "";
}
@ -495,8 +498,10 @@ static void KeyboardCommands ()
{
is_alt = 1;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
// workaround for GDK->SDL in GTK problems where ALT release is never getting sent
// i know this is sort of an ugly hack to fix this, but the bug is rather annoying
// workaround for GDK->SDL in GTK problems where ALT release is never
// getting sent
// I know this is sort of an ugly hack to fix this, but the bug is
// rather annoying
// prg318 10/23/11
int fullscreen;
g_config->getOption ("SDL.Fullscreen", &fullscreen);
@ -627,7 +632,7 @@ static void KeyboardCommands ()
}
else
{
FCEUI_LoadState (NULL);
FCEUI_LoadState(NULL);
}
}
}
@ -1119,7 +1124,7 @@ ButtConfig GamePadConfig[4][10] = {
* Update the status of the gamepad input devices.
*/
static void
UpdateGamepad (void)
UpdateGamepad(void)
{
// don't update during movie playback
if (FCEUMOV_Mode (MOVIEMODE_PLAY))
@ -1150,19 +1155,33 @@ UpdateGamepad (void)
if(opposite_dirs == 0)
{
// test for left+right and up+down
if(x == 4)
if(x == 4){
up = true;
if((x == 5) && (up == true))
}
if((x == 5) && (up == true)){
continue;
if(x == 6)
}
if(x == 6){
left = true;
if((x == 7) && (left == true))
}
if((x == 7) && (left == true)){
continue;
}
}
JS |= (1 << x) << (wg << 3);
}
}
int four_button_exit;
g_config->getOption("SDL.ABStartSelectExit", &four_button_exit);
// if a+b+start+select is pressed, exit
if (four_button_exit && JS == 15) {
FCEUI_printf("all buttons pressed, exiting\n");
CloseGame();
FCEUI_Kill();
exit(0);
}
// rapid-fire a, rapid-fire b
if (rapid)
{

View File

@ -21,9 +21,9 @@
/// \file
/// \brief Handles the graphical game display for the SDL implementation.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "sdl.h"
#include "sdl-opengl.h"

View File

@ -1,17 +1,16 @@
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <csignal>
#include <sys/time.h>
#include <sys/stat.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <limits.h>
#include <math.h>
#include <climits>
#include <cmath>
#ifdef _GTK
#include <gtk/gtk.h>
@ -72,53 +71,64 @@ int mutecapture;
static int noconfig;
// -Video Modes Tag- : See --special
char *DriverUsage="\
Option Value Description\n\
--pal {0|1} Use PAL timing.\n\
--newppu {0|1} Enable the new PPU core. (WARNING: May break savestates)\n\
--inputcfg d Configures input device d on startup.\n\
--input(1,2) d Set which input device to emulate for input 1 or 2.\n\
Devices: gamepad zapper powerpad.0 powerpad.1 arkanoid\n\
--input(3,4) d Set the famicom expansion device to emulate for input(3, 4)\n\
Devices: quizking hypershot mahjong toprider ftrainer\n\
familykeyboard oekakids arkanoid shadow bworld 4player\n\
--gamegenie {0|1} Enable emulated Game Genie.\n\
--frameskip x Set # of frames to skip per emulated frame.\n\
--xres x Set horizontal resolution for full screen mode.\n\
--yres x Set vertical resolution for full screen mode.\n\
--autoscale {0|1} Enable autoscaling in fullscreen. \n\
--keepratio {0|1} Keep native NES aspect ratio when autoscaling. \n\
--(x/y)scale x Multiply width/height by x. \n\
(Real numbers >0 with OpenGL, otherwise integers >0).\n\
--(x/y)stretch {0|1} Stretch to fill surface on x/y axis (OpenGL only).\n\
--bpp {8|16|32} Set bits per pixel.\n\
--opengl {0|1} Enable OpenGL support.\n\
--fullscreen {0|1} Enable full screen mode.\n\
--noframe {0|1} Hide title bar and window decorations.\n\
--special {1-4} Use special video scaling filters\n\
(1 = hq2x 2 = Scale2x 3 = NTSC 2x 4 = hq3x 5 = Scale3x)\n\
--palette f Load custom global palette from file f.\n\
--sound {0|1} Enable sound.\n\
--soundrate x Set sound playback rate to x Hz.\n\
--soundq {0|1|2} Set sound quality. (0 = Low 1 = High 2 = Very High)\n\
--soundbufsize x Set sound buffer size to x ms.\n\
--volume {0-256} Set volume to x.\n\
--soundrecord f Record sound to file f.\n\
--playmov f Play back a recorded FCM/FM2/FM3 movie from filename f.\n\
--pauseframe x Pause movie playback at frame x.\n\
--fcmconvert f Convert fcm movie file f to fm2.\n\
--ripsubs f Convert movie's subtitles to srt\n\
--subtitles {0,1} Enable subtitle display\n\
--fourscore {0,1} Enable fourscore emulation\n\
--no-config {0,1} Use default config file and do not save\n\
--net s Connect to server 's' for TCP/IP network play.\n\
--port x Use TCP/IP port x for network play.\n\
--user x Set the nickname to use in network play.\n\
--pass x Set password to use for connecting to the server.\n\
--netkey s Use string 's' to create a unique session for the game loaded.\n\
--players x Set the number of local players in a network play session.\n\
--rp2mic {0,1} Replace Port 2 Start with microphone (Famicom).\n\
--nogui Don't load the GTK GUI";
static const char *DriverUsage=
"Option Value Description\n"
"--pal {0|1} Use PAL timing.\n"
"--newppu {0|1} Enable the new PPU core. (WARNING: May break savestates)\n"
"--inputcfg d Configures input device d on startup.\n"
"--input(1,2) d Set which input device to emulate for input 1 or 2.\n"
" Devices: gamepad zapper powerpad.0 powerpad.1\n"
" arkanoid\n"
"--input(3,4) d Set the famicom expansion device to emulate for\n"
" input(3, 4)\n"
" Devices: quizking hypershot mahjong toprider ftrainer\n"
" familykeyboard oekakids arkanoid shadow bworld\n"
" 4player\n"
"--gamegenie {0|1} Enable emulated Game Genie.\n"
"--frameskip x Set # of frames to skip per emulated frame.\n"
"--xres x Set horizontal resolution for full screen mode.\n"
"--yres x Set vertical resolution for full screen mode.\n"
"--autoscale {0|1} Enable autoscaling in fullscreen. \n"
"--keepratio {0|1} Keep native NES aspect ratio when autoscaling. \n"
"--(x/y)scale x Multiply width/height by x. \n"
" (Real numbers >0 with OpenGL, otherwise integers >0).\n"
"--(x/y)stretch {0|1} Stretch to fill surface on x/y axis (OpenGL only).\n"
"--bpp {8|16|32} Set bits per pixel.\n"
"--opengl {0|1} Enable OpenGL support.\n"
"--fullscreen {0|1} Enable full screen mode.\n"
"--noframe {0|1} Hide title bar and window decorations.\n"
"--special {1-4} Use special video scaling filters\n"
" (1 = hq2x 2 = Scale2x 3 = NTSC 2x 4 = hq3x\n"
" 5 = Scale3x)\n"
"--palette f Load custom global palette from file f.\n"
"--sound {0|1} Enable sound.\n"
"--soundrate x Set sound playback rate to x Hz.\n"
"--soundq {0|1|2} Set sound quality. (0 = Low 1 = High 2 = Very High)\n"
"--soundbufsize x Set sound buffer size to x ms.\n"
"--volume {0-256} Set volume to x.\n"
"--soundrecord f Record sound to file f.\n"
"--playmov f Play back a recorded FCM/FM2/FM3 movie from filename f.\n"
"--pauseframe x Pause movie playback at frame x.\n"
"--fcmconvert f Convert fcm movie file f to fm2.\n"
"--ripsubs f Convert movie's subtitles to srt\n"
"--subtitles {0|1} Enable subtitle display\n"
"--fourscore {0|1} Enable fourscore emulation\n"
"--no-config {0|1} Use default config file and do not save\n"
"--net s Connect to server 's' for TCP/IP network play.\n"
"--port x Use TCP/IP port x for network play.\n"
"--user x Set the nickname to use in network play.\n"
"--pass x Set password to use for connecting to the server.\n"
"--netkey s Use string 's' to create a unique session for the\n"
" game loaded.\n"
"--players x Set the number of local players in a network play\n"
" session.\n"
"--rp2mic {0|1} Replace Port 2 Start with microphone (Famicom).\n"
"--nogui Don't load the GTK GUI\n"
"--abstartselectexit {0|1} exit the emulator when A+B+Select+Start is pressed\n"
"--autosavestate {0-9|>9} load from the given state when the game is loaded\n"
"--autoloadstate {0-9|>9} save to the given state when the game is closed\n"
" to not save/load automatically provide a number\n"
" greater than 9\n";
// these should be moved to the man file
@ -175,10 +185,20 @@ static void ShowUsage(char *prog)
*/
int LoadGame(const char *path)
{
CloseGame();
if (isloaded){
CloseGame();
}
if(!FCEUI_LoadGame(path, 1)) {
return 0;
}
int state_to_load;
g_config->getOption("SDL.AutoLoadState", &state_to_load);
if (state_to_load != INVALID_STATE){
FCEUI_SelectState(state_to_load, 0);
FCEUI_LoadState(NULL);
}
ParseGIInput(GameInfo);
RefreshThrottleFPS();
@ -218,7 +238,15 @@ CloseGame()
if(!isloaded) {
return(0);
}
int state_to_save;
g_config->getOption("SDL.AutoSaveState", &state_to_save);
if (state_to_save != INVALID_STATE){
FCEUI_SelectState(state_to_save, 0);
FCEUI_SaveState(NULL);
}
FCEUI_CloseGame();
DriverKill();
isloaded = 0;
GameInfo = 0;
@ -499,7 +527,7 @@ int main(int argc, char *argv[])
{
if(!strcmp(argv[1], "--help") || !strcmp(argv[1],"-h"))
{
ShowUsage(argv[0]);
ShowUsage(argv[0]);
return 0;
}
}
@ -943,7 +971,8 @@ void FCEUD_PrintError(const char *errormsg)
if(gtkIsStarted == true && noGui == 0)
{
GtkWidget* d;
d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, errormsg);
d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, errormsg);
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(d);
}
@ -955,7 +984,11 @@ void FCEUD_PrintError(const char *errormsg)
// dummy functions
#define DUMMY(__f) void __f(void) {printf("%s\n", #__f); FCEU_DispMessage("Not implemented.",0);}
#define DUMMY(__f) \
void __f(void) {\
printf("%s\n", #__f);\
FCEU_DispMessage("Not implemented.",0);\
}
DUMMY(FCEUD_HideMenuToggle)
DUMMY(FCEUD_MovieReplayFrom)
DUMMY(FCEUD_ToggleStatusIcon)

View File

@ -162,7 +162,7 @@ static void FCEU_CloseGame(void)
if (GameInfo->name) {
free(GameInfo->name);
GameInfo->name = 0;
GameInfo->name = NULL;
}
if (GameInfo->type != GIT_NSF) {
@ -263,8 +263,8 @@ void FlushGenieRW(void) {
}
free(AReadG);
free(BWriteG);
AReadG = 0;
BWriteG = 0;
AReadG = NULL;
BWriteG = NULL;
RWWrap = 0;
}
}
@ -330,6 +330,7 @@ static void AllocBuffers() {
static void FreeBuffers() {
FCEU_free(RAM);
RAM = NULL;
}
//------
@ -964,6 +965,7 @@ void UpdateAutosave(void) {
FCEUSS_Save(f);
AutoSS = true; //Flag that an auto-savestate was made
free(f);
f = NULL;
AutosaveStatus[AutosaveIndex] = 1;
}
}
@ -977,6 +979,7 @@ void FCEUI_Autosave(void) {
f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str());
FCEUSS_Load(f);
free(f);
f = NULL;
//Set pointer to previous available slot
if (AutosaveStatus[(AutosaveIndex + AutosaveQty - 1) % AutosaveQty] == 1) {

View File

@ -299,7 +299,7 @@ static void StrobeGP(int w)
joy_readbit[w]=0;
}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^6
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
static INPUTC GPC={ReadGP,0,StrobeGP,UpdateGP,0,0,LogGP,LoadGP};
@ -319,8 +319,9 @@ void FCEU_UpdateInput(void)
//tell all drivers to poll input and set up their logical states
if(!FCEUMOV_Mode(MOVIEMODE_PLAY))
{
for(int port=0;port<2;port++)
for(int port=0;port<2;port++){
joyports[port].driver->Update(port,joyports[port].ptr,joyports[port].attrib);
}
portFC.driver->Update(portFC.ptr,portFC.attrib);
}
@ -333,8 +334,9 @@ void FCEU_UpdateInput(void)
FCEUMOV_AddInputState();
//TODO - should this apply to the movie data? should this be displayed in the input hud?
if(GameInfo->type==GIT_VSUNI)
if(GameInfo->type==GIT_VSUNI){
FCEU_VSUniSwap(&joy[0],&joy[1]);
}
}
static DECLFR(VSUNIRead0)
@ -371,16 +373,18 @@ void InputScanlineHook(uint8 *bg, uint8 *spr, uint32 linets, int final)
portFC.driver->SLHook(bg,spr,linets,final);
}
#include <iostream>
//binds JPorts[pad] to the driver specified in JPType[pad]
static void SetInputStuff(int port)
{
switch(joyports[port].type)
{
case SI_GAMEPAD:
if(GameInfo->type==GIT_VSUNI)
if(GameInfo->type==GIT_VSUNI){
joyports[port].driver = &GPCVS;
else
} else {
joyports[port].driver= &GPC;
}
break;
case SI_ARKANOID:
joyports[port].driver=FCEU_InitArkanoid(port);

View File

@ -959,7 +959,8 @@ void FCEUI_LoadState(const char *fname)
if(FCEUSS_Load(fname))
{
//mbg todo netplay
/*if(FCEUnetplay)
#if 0
if(FCEUnetplay)
{
char *fn = strdup(FCEU_MakeFName(FCEUMKF_NPTEMP, 0, 0).c_str());
FILE *fp;
@ -980,7 +981,8 @@ void FCEUI_LoadState(const char *fname)
}
free(fn);
}*/
}
#endif
freshMovie = false; //The movie has been altered so it is no longer fresh
}
else