Search
lxdream.org :: lxdream :: r1038:f220d18c0615
lxdream 0.9.1
released Jun 29
Download Now
changeset1038:f220d18c0615
parent1037:297a73940eb6
child1039:98b9f0791bff
authornkeynes
dateThu Jun 25 01:15:25 2009 +0000 (14 years ago)
Move configuration to .lxdream/lxdreamrc on *nix, Library/Application Support/Lxdream on OS X
Create standard directories on first run
Add current quick state to config file
Refactor quick-state handling into dreamcast.c, and use the save directory
src/cocoaui/paths_osx.m
src/config.c
src/config.h
src/dreamcast.c
src/dreamcast.h
src/guiutil.c
src/hotkeys.c
src/lxdream.h
src/main.c
src/paths_unix.c
1.1 --- a/src/cocoaui/paths_osx.m Thu Jun 25 01:09:42 2009 +0000
1.2 +++ b/src/cocoaui/paths_osx.m Thu Jun 25 01:15:25 2009 +0000
1.3 @@ -26,6 +26,7 @@
1.4
1.5 static char *bundle_resource_path = NULL;
1.6 static char *bundle_plugin_path = NULL;
1.7 +static char *user_data_path = NULL;
1.8
1.9 static char *get_bundle_resource_path()
1.10 {
1.11 @@ -58,3 +59,13 @@
1.12 }
1.13 return bundle_plugin_path;
1.14 }
1.15 +
1.16 +
1.17 +const char *get_user_data_path()
1.18 +{
1.19 + if( user_data_path == NULL ) {
1.20 + char *home = getenv("HOME");
1.21 + user_data_path = g_strdup_printf( "%s/Library/Application Support/Lxdream", home );
1.22 + }
1.23 + return user_data_path;
1.24 +}
1.25 \ No newline at end of file
2.1 --- a/src/config.c Thu Jun 25 01:09:42 2009 +0000
2.2 +++ b/src/config.c Thu Jun 25 01:15:25 2009 +0000
2.3 @@ -25,6 +25,8 @@
2.4 #include <wordexp.h>
2.5 #include <glib/gmem.h>
2.6 #include <glib/gstrfuncs.h>
2.7 +#include <sys/types.h>
2.8 +#include <sys/stat.h>
2.9 #include "dream.h"
2.10 #include "config.h"
2.11 #include "maple/maple.h"
2.12 @@ -40,15 +42,16 @@
2.13 gboolean lxdream_save_config_stream( FILE *f );
2.14
2.15 static struct lxdream_config_entry global_config[] =
2.16 - {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, "dcboot.rom" },
2.17 - { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, "dcflash.rom" },
2.18 + {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, NULL },
2.19 + { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, NULL },
2.20 { "default path", N_("Default disc path"), CONFIG_TYPE_PATH, "." },
2.21 - { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, "save" },
2.22 - { "vmu path", N_("VMU path"), CONFIG_TYPE_PATH, "vmu" },
2.23 - { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, "IP.BIN" },
2.24 + { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, NULL },
2.25 + { "vmu path", N_("VMU path"), CONFIG_TYPE_PATH, NULL },
2.26 + { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, NULL },
2.27 { "gdrom", NULL, CONFIG_TYPE_FILE, NULL },
2.28 { "recent", NULL, CONFIG_TYPE_FILELIST, NULL },
2.29 { "vmu", NULL, CONFIG_TYPE_FILELIST, NULL },
2.30 + { "quick state", NULL, CONFIG_TYPE_INTEGER, "0" },
2.31 { NULL, CONFIG_TYPE_NONE }};
2.32
2.33 static struct lxdream_config_entry serial_config[] =
2.34 @@ -85,7 +88,15 @@
2.35 gboolean result = TRUE;
2.36 char *home = getenv("HOME");
2.37 if( lxdream_config_save_filename == NULL ) {
2.38 + /* For compatibility, look for the old ~/.lxdreamrc first. Use it if
2.39 + * found, otherwise use the new ~/.lxdream/lxdreamrc.
2.40 + */
2.41 lxdream_config_save_filename = g_strdup_printf("%s/.%s", home, DEFAULT_CONFIG_FILENAME);
2.42 + if( access(lxdream_config_save_filename, R_OK) != 0 ) {
2.43 + g_free(lxdream_config_save_filename);
2.44 + const char *user_path = get_user_data_path();
2.45 + lxdream_config_save_filename = g_strdup_printf("%s/%s", user_path, DEFAULT_CONFIG_FILENAME);
2.46 + }
2.47 }
2.48 if( lxdream_config_load_filename == NULL ) {
2.49 char *sysconfig = g_strdup_printf("%s/%s", get_sysconf_path(), DEFAULT_CONFIG_FILENAME);
2.50 @@ -94,9 +105,6 @@
2.51 g_free(sysconfig);
2.52 } else if( access( sysconfig, R_OK ) == 0 ) {
2.53 lxdream_config_load_filename = sysconfig;
2.54 - } else if( access( "./" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) {
2.55 - lxdream_config_load_filename = g_strdup("./" DEFAULT_CONFIG_FILENAME);
2.56 - g_free(sysconfig);
2.57 } else {
2.58 lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
2.59 g_free(sysconfig);
2.60 @@ -120,6 +128,15 @@
2.61
2.62 void lxdream_set_default_config( )
2.63 {
2.64 + /* Construct platform dependent defaults */
2.65 + const gchar *user_path = get_user_data_path();
2.66 + global_config[CONFIG_BIOS_PATH].default_value = g_strdup_printf( "%s/dcboot.rom", user_path );
2.67 + global_config[CONFIG_FLASH_PATH].default_value = g_strdup_printf( "%s/dcflash.rom", user_path );
2.68 + global_config[CONFIG_SAVE_PATH].default_value = g_strdup_printf( "%s/save", user_path );
2.69 + global_config[CONFIG_VMU_PATH].default_value = g_strdup_printf( "%s/vmu", user_path );
2.70 + global_config[CONFIG_BOOTSTRAP].default_value = g_strdup_printf( "%s/IP.BIN", user_path );
2.71 +
2.72 + /* Copy defaults into main values */
2.73 struct lxdream_config_group *group = lxdream_config_root;
2.74 while( group->key != NULL ) {
2.75 struct lxdream_config_entry *param = group->params;
2.76 @@ -493,3 +510,28 @@
2.77 }
2.78 return TRUE;
2.79 }
2.80 +
2.81 +void lxdream_make_config_dir( )
2.82 +{
2.83 + const char *user_path = get_user_data_path();
2.84 + struct stat st;
2.85 +
2.86 + if( access( user_path, R_OK|X_OK ) == 0 && lstat( user_path, &st ) == 0 &&
2.87 + (st.st_mode & S_IFDIR) != 0 ) {
2.88 + /* All good */
2.89 + return;
2.90 + }
2.91 +
2.92 + if( mkdir( user_path, 0777 ) != 0 ) {
2.93 + ERROR( "Unable to create user configuration directory %s: %s", user_path, strerror(errno) );
2.94 + return;
2.95 + }
2.96 +
2.97 + char *vmupath = g_strdup_printf( "%s/vmu", user_path );
2.98 + mkdir( vmupath, 0777 );
2.99 + g_free( vmupath );
2.100 +
2.101 + char *savepath = g_strdup_printf( "%s/save", user_path );
2.102 + mkdir( savepath, 0777 );
2.103 + g_free( vmupath );
2.104 +}
3.1 --- a/src/config.h Thu Jun 25 01:09:42 2009 +0000
3.2 +++ b/src/config.h Thu Jun 25 01:15:25 2009 +0000
3.3 @@ -32,6 +32,7 @@
3.4 #define CONFIG_TYPE_PATH 2
3.5 #define CONFIG_TYPE_KEY 3
3.6 #define CONFIG_TYPE_FILELIST 4
3.7 +#define CONFIG_TYPE_INTEGER 5
3.8
3.9 #define DEFAULT_CONFIG_FILENAME "lxdreamrc"
3.10
3.11 @@ -57,7 +58,8 @@
3.12 #define CONFIG_GDROM 6
3.13 #define CONFIG_RECENT 7
3.14 #define CONFIG_VMU 8
3.15 -#define CONFIG_KEY_MAX CONFIG_VMU
3.16 +#define CONFIG_QUICK_STATE 9
3.17 +#define CONFIG_KEY_MAX CONFIG_QUICK_STATE
3.18
3.19 extern struct lxdream_config_group lxdream_config_root[];
3.20
3.21 @@ -124,6 +126,11 @@
3.22 gboolean lxdream_save_config( );
3.23
3.24 /**
3.25 + * Make the user configuration directories if they don't already exist.
3.26 + */
3.27 +void lxdream_make_config_dir( );
3.28 +
3.29 +/**
3.30 * Escape a pathname if needed to prevent shell substitution.
3.31 * @return a newly allocated string (or NULL if the input is NULL)
3.32 */
4.1 --- a/src/dreamcast.c Thu Jun 25 01:09:42 2009 +0000
4.2 +++ b/src/dreamcast.c Thu Jun 25 01:15:25 2009 +0000
4.3 @@ -19,6 +19,7 @@
4.4
4.5 #include <errno.h>
4.6 #include <glib.h>
4.7 +#include <unistd.h>
4.8 #include "lxdream.h"
4.9 #include "dream.h"
4.10 #include "mem.h"
4.11 @@ -48,6 +49,7 @@
4.12 static sh4addr_t dreamcast_entry_point = 0xA0000000;
4.13 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;
4.14 static uint64_t run_time_nanosecs = 0;
4.15 +static unsigned int quick_save_state = -1;
4.16
4.17 #define MAX_MODULES 32
4.18 static int num_modules = 0;
4.19 @@ -118,7 +120,7 @@
4.20 dreamcast_register_module( &aica_module );
4.21 dreamcast_register_module( &maple_module );
4.22 dreamcast_register_module( &ide_module );
4.23 -
4.24 +
4.25 g_free(bios_path);
4.26 g_free(flash_path);
4.27 }
4.28 @@ -502,6 +504,77 @@
4.29 return 0;
4.30 }
4.31
4.32 +/********************** Quick save state support ***********************/
4.33 +/* This section doesn't necessarily belong here, but it probably makes the
4.34 + * most sense here next to the regular save/load functions
4.35 + */
4.36 +
4.37 +static gchar *get_quick_state_filename( int state )
4.38 +{
4.39 + gchar *path = lxdream_get_global_config_path_value(CONFIG_SAVE_PATH);
4.40 + gchar *str = g_strdup_printf( QUICK_STATE_FILENAME, path, state );
4.41 + g_free( path );
4.42 + return str;
4.43 +}
4.44 +
4.45 +
4.46 +static void dreamcast_quick_state_init()
4.47 +{
4.48 + const char *state = lxdream_get_global_config_value(CONFIG_QUICK_STATE);
4.49 + if( state != NULL ) {
4.50 + quick_save_state = atoi(state);
4.51 + if( quick_save_state > MAX_QUICK_STATE ) {
4.52 + quick_save_state = 0;
4.53 + }
4.54 + } else {
4.55 + quick_save_state = 0;
4.56 + }
4.57 +}
4.58 +
4.59 +void dreamcast_quick_save()
4.60 +{
4.61 + if( quick_save_state == -1 )
4.62 + dreamcast_quick_state_init();
4.63 + gchar *str = get_quick_state_filename(quick_save_state);
4.64 + dreamcast_save_state(str);
4.65 + g_free(str);
4.66 +}
4.67 +
4.68 +void dreamcast_quick_load()
4.69 +{
4.70 + if( quick_save_state == -1 )
4.71 + dreamcast_quick_state_init();
4.72 + gchar *str = get_quick_state_filename(quick_save_state);
4.73 + dreamcast_load_state(str);
4.74 + g_free(str);
4.75 +}
4.76 +
4.77 +unsigned int dreamcast_get_quick_state( )
4.78 +{
4.79 + if( quick_save_state == -1 )
4.80 + dreamcast_quick_state_init();
4.81 + return quick_save_state;
4.82 +}
4.83 +
4.84 +void dreamcast_set_quick_state( unsigned int state )
4.85 +{
4.86 + if( state <= MAX_QUICK_STATE && state != quick_save_state ) {
4.87 + quick_save_state = state;
4.88 + char buf[3];
4.89 + sprintf( buf, "%d", quick_save_state );
4.90 + lxdream_set_global_config_value(CONFIG_QUICK_STATE, buf);
4.91 + lxdream_save_config();
4.92 + }
4.93 +}
4.94 +
4.95 +gboolean dreamcast_has_quick_state( unsigned int state )
4.96 +{
4.97 + gchar *str = get_quick_state_filename(state);
4.98 + int result = access(str, R_OK);
4.99 + g_free(str);
4.100 + return result == 0 ? TRUE : FALSE;
4.101 +}
4.102 +
4.103 /********************* The Boot ROM address space **********************/
4.104 static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
4.105 {
5.1 --- a/src/dreamcast.h Thu Jun 25 01:09:42 2009 +0000
5.2 +++ b/src/dreamcast.h Thu Jun 25 01:15:25 2009 +0000
5.3 @@ -66,6 +66,16 @@
5.4 int dreamcast_save_state( const gchar *filename );
5.5 int dreamcast_load_state( const gchar *filename );
5.6
5.7 +/* Quick saves */
5.8 +#define MAX_QUICK_STATE 9
5.9 +#define QUICK_STATE_FILENAME "quicksave%d.dst"
5.10 +
5.11 +void dreamcast_quick_save();
5.12 +void dreamcast_quick_load();
5.13 +unsigned int dreamcast_get_quick_state();
5.14 +void dreamcast_set_quick_state( unsigned int state );
5.15 +gboolean dreamcast_has_quick_state( unsigned int state );
5.16 +
5.17 /**
5.18 * Load the front-buffer image from the specified file.
5.19 * If the file is not a valid save state, returns NULL. Otherwise,
6.1 --- a/src/guiutil.c Thu Jun 25 01:09:42 2009 +0000
6.2 +++ b/src/guiutil.c Thu Jun 25 01:15:25 2009 +0000
6.3 @@ -16,6 +16,7 @@
6.4 * GNU General Public License for more details.
6.5 */
6.6
6.7 +#include <unistd.h>
6.8 #include <glib/gstrfuncs.h>
6.9 #include <glib/gutils.h>
6.10
7.1 --- a/src/hotkeys.c Thu Jun 25 01:09:42 2009 +0000
7.2 +++ b/src/hotkeys.c Thu Jun 25 01:15:25 2009 +0000
7.3 @@ -35,9 +35,6 @@
7.4 static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
7.5 static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
7.6
7.7 -static char *set_current_state_filename(int filenum);
7.8 -
7.9 -static char *current_save_state;
7.10
7.11 struct lxdream_config_entry hotkeys_config[] = {
7.12 {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY},
7.13 @@ -46,6 +43,7 @@
7.14 {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY},
7.15 {"save", N_("Save current quick save"), CONFIG_TYPE_KEY},
7.16 {"load", N_("Load current quick save"), CONFIG_TYPE_KEY},
7.17 + {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY},
7.18 {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY},
7.19 {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY},
7.20 {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY},
7.21 @@ -58,15 +56,8 @@
7.22 {NULL, CONFIG_TYPE_NONE}
7.23 };
7.24
7.25 -void hotkeys_init() {
7.26 -
7.27 - char *home = getenv("HOME");
7.28 - char *save_path = g_strdup_printf("%s/.lxdream", home);
7.29 - mkdir(save_path, S_IRWXU);
7.30 - g_free(save_path);
7.31 -
7.32 - set_current_state_filename(1);
7.33 -
7.34 +void hotkeys_init()
7.35 +{
7.36 hotkeys_register_keys();
7.37 }
7.38
7.39 @@ -78,7 +69,7 @@
7.40 input_register_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
7.41 input_register_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
7.42 input_register_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
7.43 - for (int i = 0; i < 9; i++)
7.44 + for (int i = 0; i < 10; i++)
7.45 {
7.46 input_register_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
7.47 }
7.48 @@ -92,7 +83,7 @@
7.49 input_unregister_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
7.50 input_unregister_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
7.51 input_unregister_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
7.52 - for (int i = 0; i < 9; i++)
7.53 + for (int i = 0; i < 10; i++)
7.54 {
7.55 input_unregister_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
7.56 }
7.57 @@ -136,33 +127,22 @@
7.58 static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
7.59 {
7.60 if (isKeyDown) {
7.61 - INFO("state select callback called (%d)", value);
7.62 - assert(value > 0 && value <= 9);
7.63 - set_current_state_filename(value);
7.64 + dreamcast_set_quick_state(value);
7.65 }
7.66 }
7.67
7.68 static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
7.69 {
7.70 if (isKeyDown) {
7.71 - if (current_save_state != NULL)
7.72 - dreamcast_save_state(current_save_state);
7.73 + dreamcast_quick_save();
7.74 }
7.75 }
7.76
7.77 static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
7.78 {
7.79 if (isKeyDown) {
7.80 - if (current_save_state != NULL)
7.81 - dreamcast_load_state(current_save_state);
7.82 + dreamcast_quick_load();
7.83 }
7.84 }
7.85
7.86 -static char *set_current_state_filename(int filenum)
7.87 -{
7.88 - char *home = getenv("HOME");
7.89 - if (current_save_state != NULL)
7.90 - g_free(current_save_state);
7.91 - current_save_state = g_strdup_printf("%s/.lxdream/quicksave%d.dst", home, filenum);
7.92 -}
7.93
8.1 --- a/src/lxdream.h Thu Jun 25 01:09:42 2009 +0000
8.2 +++ b/src/lxdream.h Thu Jun 25 01:15:25 2009 +0000
8.3 @@ -91,6 +91,7 @@
8.4 const char *get_sysconf_path();
8.5 const char *get_locale_path();
8.6 const char *get_plugin_path();
8.7 +const char *get_user_data_path();
8.8
8.9 #ifdef HAVE_FASTCALL
8.10 #define FASTCALL __attribute__((regparm(2)))
9.1 --- a/src/main.c Thu Jun 25 01:09:42 2009 +0000
9.2 +++ b/src/main.c Thu Jun 25 01:15:25 2009 +0000
9.3 @@ -202,6 +202,7 @@
9.4 plugin_init();
9.5 #endif
9.6
9.7 + lxdream_make_config_dir( );
9.8 lxdream_load_config( );
9.9
9.10 if( audio_driver_name != NULL && strcmp(audio_driver_name, "?") == 0 ) {
10.1 --- a/src/paths_unix.c Thu Jun 25 01:09:42 2009 +0000
10.2 +++ b/src/paths_unix.c Thu Jun 25 01:15:25 2009 +0000
10.3 @@ -17,8 +17,11 @@
10.4 */
10.5
10.6 #include <string.h>
10.7 +#include <stdlib.h>
10.8 +#include <glib/gstrfuncs.h>
10.9
10.10 #include "lxdream.h"
10.11 +#include "config.h"
10.12
10.13 const char *get_sysconf_path()
10.14 {
10.15 @@ -34,3 +37,14 @@
10.16 {
10.17 return PACKAGE_PLUGIN_DIR;
10.18 }
10.19 +
10.20 +static char *user_data_path = NULL;
10.21 +
10.22 +const char *get_user_data_path()
10.23 +{
10.24 + if( user_data_path == NULL ) {
10.25 + char *home = getenv("HOME");
10.26 + user_data_path = g_strdup_printf( "%s/.lxdream", home );
10.27 + }
10.28 + return user_data_path;
10.29 +}
10.30 \ No newline at end of file
.