filename | src/dreamcast.c |
changeset | 1038:f220d18c0615 |
prev | 1036:af7b0c5905dd |
next | 1041:5fcc39857c5c |
author | nkeynes |
date | Thu Jun 25 01:15:25 2009 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | 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 |
file | annotate | diff | log | raw |
1.1 --- a/src/dreamcast.c Wed Jun 24 06:06:40 2009 +00001.2 +++ b/src/dreamcast.c Thu Jun 25 01:15:25 2009 +00001.3 @@ -19,6 +19,7 @@1.5 #include <errno.h>1.6 #include <glib.h>1.7 +#include <unistd.h>1.8 #include "lxdream.h"1.9 #include "dream.h"1.10 #include "mem.h"1.11 @@ -48,6 +49,7 @@1.12 static sh4addr_t dreamcast_entry_point = 0xA0000000;1.13 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;1.14 static uint64_t run_time_nanosecs = 0;1.15 +static unsigned int quick_save_state = -1;1.17 #define MAX_MODULES 321.18 static int num_modules = 0;1.19 @@ -118,7 +120,7 @@1.20 dreamcast_register_module( &aica_module );1.21 dreamcast_register_module( &maple_module );1.22 dreamcast_register_module( &ide_module );1.23 -1.24 +1.25 g_free(bios_path);1.26 g_free(flash_path);1.27 }1.28 @@ -502,6 +504,77 @@1.29 return 0;1.30 }1.32 +/********************** Quick save state support ***********************/1.33 +/* This section doesn't necessarily belong here, but it probably makes the1.34 + * most sense here next to the regular save/load functions1.35 + */1.36 +1.37 +static gchar *get_quick_state_filename( int state )1.38 +{1.39 + gchar *path = lxdream_get_global_config_path_value(CONFIG_SAVE_PATH);1.40 + gchar *str = g_strdup_printf( QUICK_STATE_FILENAME, path, state );1.41 + g_free( path );1.42 + return str;1.43 +}1.44 +1.45 +1.46 +static void dreamcast_quick_state_init()1.47 +{1.48 + const char *state = lxdream_get_global_config_value(CONFIG_QUICK_STATE);1.49 + if( state != NULL ) {1.50 + quick_save_state = atoi(state);1.51 + if( quick_save_state > MAX_QUICK_STATE ) {1.52 + quick_save_state = 0;1.53 + }1.54 + } else {1.55 + quick_save_state = 0;1.56 + }1.57 +}1.58 +1.59 +void dreamcast_quick_save()1.60 +{1.61 + if( quick_save_state == -1 )1.62 + dreamcast_quick_state_init();1.63 + gchar *str = get_quick_state_filename(quick_save_state);1.64 + dreamcast_save_state(str);1.65 + g_free(str);1.66 +}1.67 +1.68 +void dreamcast_quick_load()1.69 +{1.70 + if( quick_save_state == -1 )1.71 + dreamcast_quick_state_init();1.72 + gchar *str = get_quick_state_filename(quick_save_state);1.73 + dreamcast_load_state(str);1.74 + g_free(str);1.75 +}1.76 +1.77 +unsigned int dreamcast_get_quick_state( )1.78 +{1.79 + if( quick_save_state == -1 )1.80 + dreamcast_quick_state_init();1.81 + return quick_save_state;1.82 +}1.83 +1.84 +void dreamcast_set_quick_state( unsigned int state )1.85 +{1.86 + if( state <= MAX_QUICK_STATE && state != quick_save_state ) {1.87 + quick_save_state = state;1.88 + char buf[3];1.89 + sprintf( buf, "%d", quick_save_state );1.90 + lxdream_set_global_config_value(CONFIG_QUICK_STATE, buf);1.91 + lxdream_save_config();1.92 + }1.93 +}1.94 +1.95 +gboolean dreamcast_has_quick_state( unsigned int state )1.96 +{1.97 + gchar *str = get_quick_state_filename(state);1.98 + int result = access(str, R_OK);1.99 + g_free(str);1.100 + return result == 0 ? TRUE : FALSE;1.101 +}1.102 +1.103 /********************* The Boot ROM address space **********************/1.104 static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )1.105 {
.