Search
lxdream.org :: lxdream/src/dreamcast.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 450:207461e79f21
prev422:61a0598e07ff
next461:63d4de8dcec6
author nkeynes
date Wed Oct 17 11:26:45 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Split config management out to config.[ch]
Manage config filename
Check home dir + sysconfdir for conf file
Initial work on a path settings dialog
file annotate diff log raw
1.1 --- a/src/dreamcast.c Sat Oct 06 09:03:24 2007 +0000
1.2 +++ b/src/dreamcast.c Wed Oct 17 11:26:45 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: dreamcast.c,v 1.23 2007-10-06 08:59:42 nkeynes Exp $
1.6 + * $Id: dreamcast.c,v 1.24 2007-10-17 11:26:45 nkeynes Exp $
1.7 * Central switchboard for the system. This pulls all the individual modules
1.8 * together into some kind of coherent structure. This is also where you'd
1.9 * add Naomi support, if I ever get a board to play with...
1.10 @@ -18,8 +18,8 @@
1.11 */
1.12
1.13 #include <errno.h>
1.14 -#include <glib/gstrfuncs.h>
1.15 #include "dream.h"
1.16 +#include "config.h"
1.17 #include "mem.h"
1.18 #include "aica/aica.h"
1.19 #include "asic.h"
1.20 @@ -67,13 +67,13 @@
1.21 mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
1.22 mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH );
1.23 mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
1.24 - if( mem_load_rom( dreamcast_get_config_value(CONFIG_BIOS_PATH),
1.25 + if( mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.26 0x00000000, 0x00200000, 0x89f2b1a1 ) == NULL ) {
1.27 /* Bios wasn't found. Dump an empty ram region in there for something to do */
1.28 mem_create_ram_region( 0x00000000, 0x00200000, MEM_REGION_BIOS );
1.29 }
1.30 mem_create_ram_region( 0x00200000, 0x00020000, MEM_REGION_FLASH );
1.31 - mem_load_block( dreamcast_get_config_value(CONFIG_FLASH_PATH),
1.32 + mem_load_block( lxdream_get_config_value(CONFIG_FLASH_PATH),
1.33 0x00200000, 0x00020000 );
1.34
1.35 /* Load in the rest of the core modules */
1.36 @@ -87,7 +87,7 @@
1.37
1.38 void dreamcast_save_flash()
1.39 {
1.40 - const char *file = dreamcast_get_config_value(CONFIG_FLASH_PATH);
1.41 + const char *file = lxdream_get_config_value(CONFIG_FLASH_PATH);
1.42 mem_save_block( file, 0x00200000, 0x00020000 );
1.43 }
1.44
1.45 @@ -207,204 +207,6 @@
1.46 return dreamcast_state == STATE_RUNNING;
1.47 }
1.48
1.49 -/***************************** User Configuration **************************/
1.50 -
1.51 -
1.52 -static struct dreamcast_config_entry global_config[] =
1.53 - {{ "bios", CONFIG_TYPE_FILE, "dcboot.rom" },
1.54 - { "flash", CONFIG_TYPE_FILE, "dcflash.rom" },
1.55 - { "default path", CONFIG_TYPE_PATH, "." },
1.56 - { "save path", CONFIG_TYPE_PATH, "save" },
1.57 - { "bootstrap", CONFIG_TYPE_FILE, "IP.BIN" },
1.58 - { NULL, CONFIG_TYPE_NONE }};
1.59 -
1.60 -static struct dreamcast_config_entry serial_config[] =
1.61 - {{ "device", CONFIG_TYPE_FILE, "/dev/ttyS1" },
1.62 - { NULL, CONFIG_TYPE_NONE }};
1.63 -
1.64 -struct dreamcast_config_group dreamcast_config_root[] =
1.65 - {{ "global", global_config },
1.66 - { "controllers", NULL },
1.67 - { "serial", serial_config },
1.68 - { NULL, CONFIG_TYPE_NONE }};
1.69 -
1.70 -void dreamcast_set_default_config( )
1.71 -{
1.72 - struct dreamcast_config_group *group = dreamcast_config_root;
1.73 - while( group->key != NULL ) {
1.74 - struct dreamcast_config_entry *param = group->params;
1.75 - if( param != NULL ) {
1.76 - while( param->key != NULL ) {
1.77 - if( param->value != param->default_value ) {
1.78 - if( param->value != NULL )
1.79 - free( param->value );
1.80 - param->value = (gchar *)param->default_value;
1.81 - }
1.82 - param++;
1.83 - }
1.84 - }
1.85 - group++;
1.86 - }
1.87 - maple_detach_all();
1.88 -}
1.89 -
1.90 -const gchar *dreamcast_get_config_value( int key )
1.91 -{
1.92 - return global_config[key].value;
1.93 -}
1.94 -
1.95 -gboolean dreamcast_load_config( const gchar *filename )
1.96 -{
1.97 - FILE *f = fopen(filename, "ro");
1.98 - gboolean result;
1.99 -
1.100 - if( f == NULL ) {
1.101 - ERROR( "Unable to open '%s': %s", filename, strerror(errno) );
1.102 - return FALSE;
1.103 - }
1.104 -
1.105 - result = dreamcast_load_config_stream( f );
1.106 - fclose(f);
1.107 - return result;
1.108 -}
1.109 -
1.110 -gboolean dreamcast_load_config_stream( FILE *f )
1.111 -{
1.112 -
1.113 - char buf[512];
1.114 - int maple_device = -1, maple_subdevice = -1;
1.115 - struct dreamcast_config_group devgroup;
1.116 - struct dreamcast_config_group *group = NULL;
1.117 - maple_device_t device = NULL;
1.118 - dreamcast_set_default_config();
1.119 -
1.120 - while( fgets( buf, sizeof(buf), f ) != NULL ) {
1.121 - g_strstrip(buf);
1.122 - if( buf[0] == '#' )
1.123 - continue;
1.124 - if( *buf == '[' ) {
1.125 - char *p = strchr(buf, ']');
1.126 - if( p != NULL ) {
1.127 - struct dreamcast_config_group *tmp_group;
1.128 - maple_device = maple_subdevice = -1;
1.129 - *p = '\0';
1.130 - g_strstrip(buf+1);
1.131 - tmp_group = &dreamcast_config_root[0];
1.132 - while( tmp_group->key != NULL ) {
1.133 - if( strcasecmp(tmp_group->key, buf+1) == 0 ) {
1.134 - group = tmp_group;
1.135 - break;
1.136 - }
1.137 - tmp_group++;
1.138 - }
1.139 - }
1.140 - } else if( group != NULL ) {
1.141 - char *value = strchr( buf, '=' );
1.142 - if( value != NULL ) {
1.143 - struct dreamcast_config_entry *param = group->params;
1.144 - *value = '\0';
1.145 - value++;
1.146 - g_strstrip(buf);
1.147 - g_strstrip(value);
1.148 - if( strcmp(group->key,"controllers") == 0 ) {
1.149 - if( g_strncasecmp( buf, "device ", 7 ) == 0 ) {
1.150 - maple_device = strtoul( buf+7, NULL, 0 );
1.151 - if( maple_device < 0 || maple_device > 3 ) {
1.152 - ERROR( "Device number must be between 0..3 (not '%s')", buf+7);
1.153 - continue;
1.154 - }
1.155 - maple_subdevice = 0;
1.156 - device = maple_new_device( value );
1.157 - if( device == NULL ) {
1.158 - ERROR( "Unrecognized device '%s'", value );
1.159 - } else {
1.160 - devgroup.key = "controllers";
1.161 - devgroup.params = maple_get_device_config(device);
1.162 - maple_attach_device( device, maple_device, maple_subdevice );
1.163 - group = &devgroup;
1.164 - }
1.165 - continue;
1.166 - } else if( g_strncasecmp( buf, "subdevice ", 10 ) == 0 ) {
1.167 - maple_subdevice = strtoul( buf+10, NULL, 0 );
1.168 - if( maple_device == -1 ) {
1.169 - ERROR( "Subdevice not allowed without primary device" );
1.170 - } else if( maple_subdevice < 1 || maple_subdevice > 5 ) {
1.171 - ERROR( "Subdevice must be between 1..5 (not '%s')", buf+10 );
1.172 - } else if( (device = maple_new_device(value)) == NULL ) {
1.173 - ERROR( "Unrecognized subdevice '%s'", value );
1.174 - } else {
1.175 - devgroup.key = "controllers";
1.176 - devgroup.params = maple_get_device_config(device);
1.177 - maple_attach_device( device, maple_device, maple_subdevice );
1.178 - group = &devgroup;
1.179 - }
1.180 - continue;
1.181 - }
1.182 - }
1.183 - while( param->key != NULL ) {
1.184 - if( strcasecmp( param->key, buf ) == 0 ) {
1.185 - param->value = g_strdup(value);
1.186 - break;
1.187 - }
1.188 - param++;
1.189 - }
1.190 - }
1.191 - }
1.192 - }
1.193 - return TRUE;
1.194 -}
1.195 -
1.196 -gboolean dreamcast_save_config( const gchar *filename )
1.197 -{
1.198 - FILE *f = fopen(filename, "wo");
1.199 - gboolean result;
1.200 - if( f == NULL ) {
1.201 - ERROR( "Unable to open '%s': %s", filename, strerror(errno) );
1.202 - return FALSE;
1.203 - }
1.204 - result = dreamcast_save_config_stream(f);
1.205 - fclose(f);
1.206 - return TRUE;
1.207 -}
1.208 -
1.209 -gboolean dreamcast_save_config_stream( FILE *f )
1.210 -{
1.211 - struct dreamcast_config_group *group = &dreamcast_config_root[0];
1.212 -
1.213 - while( group->key != NULL ) {
1.214 - struct dreamcast_config_entry *entry = group->params;
1.215 - fprintf( f, "[%s]\n", group->key );
1.216 -
1.217 - if( entry != NULL ) {
1.218 - while( entry->key != NULL ) {
1.219 - fprintf( f, "%s = %s\n", entry->key, entry->value );
1.220 - entry++;
1.221 - }
1.222 - } else if( strcmp(group->key, "controllers") == 0 ) {
1.223 - int i,j;
1.224 - for( i=0; i<4; i++ ) {
1.225 - for( j=0; j<6; j++ ) {
1.226 - maple_device_t dev = maple_get_device( i, j );
1.227 - if( dev != NULL ) {
1.228 - if( j == 0 )
1.229 - fprintf( f, "Device %d = %s\n", i, dev->device_class->name );
1.230 - else
1.231 - fprintf( f, "Subdevice %d = %s\n", j, dev->device_class->name );
1.232 - entry = dev->get_config(dev);
1.233 - while( entry->key != NULL ) {
1.234 - fprintf( f, "%*c%s = %s\n", j==0?4:8, ' ',entry->key, entry->value );
1.235 - entry++;
1.236 - }
1.237 - }
1.238 - }
1.239 - }
1.240 - }
1.241 - fprintf( f, "\n" );
1.242 - group++;
1.243 - }
1.244 - return TRUE;
1.245 -}
1.246 -
1.247 /********************************* Save States *****************************/
1.248
1.249 struct save_state_header {
.