Search
lxdream.org :: lxdream/src/dreamcast.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 736:a02d1475ccfd
prev727:f934967b77a3
next740:dd11269ee48b
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/dreamcast.c Sun Jul 06 04:52:37 2008 +0000
1.2 +++ b/src/dreamcast.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -35,8 +35,8 @@
1.4 * Current state of the DC virtual machine
1.5 */
1.6 typedef enum { STATE_UNINIT=0, STATE_RUNNING,
1.7 - STATE_STOPPING, STATE_STOPPED } dreamcast_state_t;
1.8 -
1.9 + STATE_STOPPING, STATE_STOPPED } dreamcast_state_t;
1.10 +
1.11 static volatile dreamcast_state_t dreamcast_state = STATE_UNINIT;
1.12 static gboolean dreamcast_has_bios = FALSE;
1.13 static gboolean dreamcast_exit_on_stop = FALSE;
1.14 @@ -54,7 +54,7 @@
1.15 * declaration
1.16 */
1.17 struct dreamcast_module unknown_module = { "****", NULL, NULL, NULL, NULL,
1.18 - NULL, NULL, NULL };
1.19 + NULL, NULL, NULL };
1.20
1.21 /**
1.22 * This function is responsible for defining how all the pieces of the
1.23 @@ -75,11 +75,11 @@
1.24 mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH );
1.25 mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
1.26 dreamcast_has_bios = mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.27 - 0x00000000, 0x00200000, 0x89f2b1a1,
1.28 - MEM_REGION_BIOS );
1.29 + 0x00000000, 0x00200000, 0x89f2b1a1,
1.30 + MEM_REGION_BIOS );
1.31 mem_create_ram_region( 0x00200000, 0x00020000, MEM_REGION_FLASH );
1.32 mem_load_block( lxdream_get_config_value(CONFIG_FLASH_PATH),
1.33 - 0x00200000, 0x00020000 );
1.34 + 0x00200000, 0x00020000 );
1.35
1.36 /* Load in the rest of the core modules */
1.37 dreamcast_register_module( &sh4_module );
1.38 @@ -93,10 +93,10 @@
1.39 void dreamcast_config_changed(void)
1.40 {
1.41 dreamcast_has_bios = mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.42 - 0x00000000, 0x00200000, 0x89f2b1a1,
1.43 - MEM_REGION_BIOS );
1.44 + 0x00000000, 0x00200000, 0x89f2b1a1,
1.45 + MEM_REGION_BIOS );
1.46 mem_load_block( lxdream_get_config_value(CONFIG_FLASH_PATH),
1.47 - 0x00200000, 0x00020000 );
1.48 + 0x00200000, 0x00020000 );
1.49 }
1.50
1.51 void dreamcast_save_flash()
1.52 @@ -123,7 +123,7 @@
1.53 {
1.54 modules[num_modules++] = module;
1.55 if( module->init != NULL )
1.56 - module->init();
1.57 + module->init();
1.58 }
1.59
1.60 void dreamcast_set_run_time( uint32_t secs, uint32_t nanosecs )
1.61 @@ -146,39 +146,39 @@
1.62 {
1.63 int i;
1.64 if( sh4_xlat_is_running() ) {
1.65 - sh4_translate_exit( XLAT_EXIT_SYSRESET );
1.66 + sh4_translate_exit( XLAT_EXIT_SYSRESET );
1.67 }
1.68 for( i=0; i<num_modules; i++ ) {
1.69 - if( modules[i]->reset != NULL )
1.70 - modules[i]->reset();
1.71 + if( modules[i]->reset != NULL )
1.72 + modules[i]->reset();
1.73 }
1.74 }
1.75
1.76 void dreamcast_run( void )
1.77 {
1.78 int i;
1.79 -
1.80 +
1.81 if( dreamcast_state != STATE_RUNNING ) {
1.82 for( i=0; i<num_modules; i++ ) {
1.83 if( modules[i]->start != NULL )
1.84 modules[i]->start();
1.85 }
1.86 }
1.87 -
1.88 +
1.89 dreamcast_state = STATE_RUNNING;
1.90 -
1.91 +
1.92 if( run_time_nanosecs != 0 ) {
1.93 while( dreamcast_state == STATE_RUNNING ) {
1.94 uint32_t time_to_run = timeslice_length;
1.95 if( run_time_nanosecs < time_to_run ) {
1.96 time_to_run = (uint32_t)run_time_nanosecs;
1.97 }
1.98 -
1.99 +
1.100 for( i=0; i<num_modules; i++ ) {
1.101 if( modules[i]->run_time_slice != NULL )
1.102 time_to_run = modules[i]->run_time_slice( time_to_run );
1.103 }
1.104 -
1.105 +
1.106 if( run_time_nanosecs > time_to_run ) {
1.107 run_time_nanosecs -= time_to_run;
1.108 } else {
1.109 @@ -202,7 +202,7 @@
1.110 modules[i]->stop();
1.111 }
1.112 dreamcast_state = STATE_STOPPED;
1.113 -
1.114 +
1.115 if( dreamcast_exit_on_stop ) {
1.116 dreamcast_shutdown();
1.117 exit(0);
1.118 @@ -212,10 +212,10 @@
1.119 void dreamcast_stop( void )
1.120 {
1.121 if( sh4_xlat_is_running() ) {
1.122 - sh4_translate_exit( XLAT_EXIT_HALT );
1.123 + sh4_translate_exit( XLAT_EXIT_HALT );
1.124 }
1.125 if( dreamcast_state == STATE_RUNNING )
1.126 - dreamcast_state = STATE_STOPPING;
1.127 + dreamcast_state = STATE_STOPPING;
1.128 }
1.129
1.130 void dreamcast_shutdown()
1.131 @@ -251,7 +251,7 @@
1.132 gboolean dreamcast_can_run(void)
1.133 {
1.134 return dreamcast_state != STATE_UNINIT &&
1.135 - (dreamcast_has_bios || dreamcast_program_name != NULL);
1.136 + (dreamcast_has_bios || dreamcast_program_name != NULL);
1.137 }
1.138
1.139 /********************************* Save States *****************************/
1.140 @@ -277,19 +277,19 @@
1.141 {
1.142 struct save_state_header header;
1.143 if( fread( &header, sizeof(header), 1, f ) != 1 ) {
1.144 - return 0;
1.145 + return 0;
1.146 }
1.147 if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
1.148 - ERROR( "Not a %s save state file", APP_NAME );
1.149 - return 0;
1.150 + ERROR( "Not a %s save state file", APP_NAME );
1.151 + return 0;
1.152 }
1.153 if( header.version != DREAMCAST_SAVE_VERSION ) {
1.154 - ERROR( "%s save state version not supported", APP_NAME );
1.155 - return 0;
1.156 + ERROR( "%s save state version not supported", APP_NAME );
1.157 + return 0;
1.158 }
1.159 if( header.module_count > MAX_MODULES ) {
1.160 - ERROR( "%s save state is corrupted (bad module count)", APP_NAME );
1.161 - return 0;
1.162 + ERROR( "%s save state is corrupted (bad module count)", APP_NAME );
1.163 + return 0;
1.164 }
1.165 return header.module_count;
1.166 }
1.167 @@ -311,37 +311,37 @@
1.168 int i;
1.169 FILE *f = fopen( filename, "r" );
1.170 if( f == NULL ) return NULL;
1.171 -
1.172 +
1.173 int module_count = dreamcast_read_save_state_header(f);
1.174 if( module_count <= 0 ) {
1.175 - fclose(f);
1.176 - return NULL;
1.177 + fclose(f);
1.178 + return NULL;
1.179 }
1.180 for( i=0; i<module_count; i++ ) {
1.181 - struct chunk_header head;
1.182 - if( fread( &head, sizeof(head), 1, f ) != 1 ) {
1.183 - fclose(f);
1.184 - return NULL;
1.185 - }
1.186 - if( memcmp("BLCK", head.marker, 4) != 0 ) {
1.187 - fclose(f);
1.188 - return NULL;
1.189 - }
1.190 + struct chunk_header head;
1.191 + if( fread( &head, sizeof(head), 1, f ) != 1 ) {
1.192 + fclose(f);
1.193 + return NULL;
1.194 + }
1.195 + if( memcmp("BLCK", head.marker, 4) != 0 ) {
1.196 + fclose(f);
1.197 + return NULL;
1.198 + }
1.199
1.200 - if( strcmp("PVR2", head.name) == 0 ) {
1.201 - uint32_t buf_count;
1.202 - int has_front;
1.203 - fread( &buf_count, sizeof(buf_count), 1, f );
1.204 - fread( &has_front, sizeof(has_front), 1, f );
1.205 - if( buf_count != 0 && has_front ) {
1.206 - frame_buffer_t result = read_png_from_stream(f);
1.207 - fclose(f);
1.208 - return result;
1.209 - }
1.210 - break;
1.211 - } else {
1.212 - fseek( f, head.block_length, SEEK_CUR );
1.213 - }
1.214 + if( strcmp("PVR2", head.name) == 0 ) {
1.215 + uint32_t buf_count;
1.216 + int has_front;
1.217 + fread( &buf_count, sizeof(buf_count), 1, f );
1.218 + fread( &has_front, sizeof(has_front), 1, f );
1.219 + if( buf_count != 0 && has_front ) {
1.220 + frame_buffer_t result = read_png_from_stream(f);
1.221 + fclose(f);
1.222 + return result;
1.223 + }
1.224 + break;
1.225 + } else {
1.226 + fseek( f, head.block_length, SEEK_CUR );
1.227 + }
1.228 }
1.229 return NULL;
1.230 }
1.231 @@ -357,54 +357,54 @@
1.232
1.233 module_count = dreamcast_read_save_state_header(f);
1.234 if( module_count <= 0 ) {
1.235 - fclose(f);
1.236 - return 1;
1.237 + fclose(f);
1.238 + return 1;
1.239 }
1.240
1.241 for( i=0; i<MAX_MODULES; i++ ) {
1.242 - have_read[i] = 0;
1.243 + have_read[i] = 0;
1.244 }
1.245
1.246 for( i=0; i<module_count; i++ ) {
1.247 - struct chunk_header chunk;
1.248 - fread( &chunk, sizeof(chunk), 1, f );
1.249 - if( strncmp(chunk.marker, "BLCK", 4) != 0 ) {
1.250 - ERROR( "%s save state is corrupted (missing block header %d)", APP_NAME, i );
1.251 - fclose(f);
1.252 - return 2;
1.253 - }
1.254 -
1.255 - /* Find the matching module by name */
1.256 - for( j=0; j<num_modules; j++ ) {
1.257 - if( strcmp(modules[j]->name,chunk.name) == 0 ) {
1.258 - have_read[j] = 1;
1.259 - if( modules[j]->load == NULL ) {
1.260 - ERROR( "%s save state is corrupted (no loader for %s)", APP_NAME, modules[j]->name );
1.261 - fclose(f);
1.262 - return 2;
1.263 - } else if( modules[j]->load(f) != 0 ) {
1.264 - ERROR( "%s save state is corrupted (%s failed)", APP_NAME, modules[j]->name );
1.265 - fclose(f);
1.266 - return 2;
1.267 - }
1.268 - break;
1.269 - }
1.270 - }
1.271 - if( j == num_modules ) {
1.272 - fclose(f);
1.273 - ERROR( "%s save state contains unrecognized section", APP_NAME );
1.274 - return 2;
1.275 - }
1.276 + struct chunk_header chunk;
1.277 + fread( &chunk, sizeof(chunk), 1, f );
1.278 + if( strncmp(chunk.marker, "BLCK", 4) != 0 ) {
1.279 + ERROR( "%s save state is corrupted (missing block header %d)", APP_NAME, i );
1.280 + fclose(f);
1.281 + return 2;
1.282 + }
1.283 +
1.284 + /* Find the matching module by name */
1.285 + for( j=0; j<num_modules; j++ ) {
1.286 + if( strcmp(modules[j]->name,chunk.name) == 0 ) {
1.287 + have_read[j] = 1;
1.288 + if( modules[j]->load == NULL ) {
1.289 + ERROR( "%s save state is corrupted (no loader for %s)", APP_NAME, modules[j]->name );
1.290 + fclose(f);
1.291 + return 2;
1.292 + } else if( modules[j]->load(f) != 0 ) {
1.293 + ERROR( "%s save state is corrupted (%s failed)", APP_NAME, modules[j]->name );
1.294 + fclose(f);
1.295 + return 2;
1.296 + }
1.297 + break;
1.298 + }
1.299 + }
1.300 + if( j == num_modules ) {
1.301 + fclose(f);
1.302 + ERROR( "%s save state contains unrecognized section", APP_NAME );
1.303 + return 2;
1.304 + }
1.305 }
1.306 -
1.307 +
1.308 /* Any modules that we didn't load - reset to the default state.
1.309 * (ie it's not an error to skip a module if you don't actually
1.310 * care about its state).
1.311 */
1.312 for( j=0; j<num_modules; j++ ) {
1.313 - if( have_read[j] == 0 && modules[j]->reset != NULL ) {
1.314 - modules[j]->reset();
1.315 - }
1.316 + if( have_read[j] == 0 && modules[j]->reset != NULL ) {
1.317 + modules[j]->reset();
1.318 + }
1.319 }
1.320 fclose(f);
1.321 INFO( "Save state read from %s", filename );
1.322 @@ -416,31 +416,31 @@
1.323 int i;
1.324 FILE *f;
1.325 struct save_state_header header;
1.326 -
1.327 +
1.328 f = fopen( filename, "w" );
1.329 if( f == NULL )
1.330 - return errno;
1.331 + return errno;
1.332 strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
1.333 header.version = DREAMCAST_SAVE_VERSION;
1.334 header.module_count = 0;
1.335
1.336 for( i=0; i<num_modules; i++ ) {
1.337 - if( modules[i]->save != NULL )
1.338 - header.module_count++;
1.339 + if( modules[i]->save != NULL )
1.340 + header.module_count++;
1.341 }
1.342 fwrite( &header, sizeof(header), 1, f );
1.343 for( i=0; i<num_modules; i++ ) {
1.344 - if( modules[i]->save != NULL ) {
1.345 - uint32_t blocklen, posn1, posn2;
1.346 - dreamcast_write_chunk_header( modules[i]->name, 0, f );
1.347 - posn1 = ftell(f);
1.348 - modules[i]->save(f);
1.349 - posn2 = ftell(f);
1.350 - blocklen = posn2 - posn1;
1.351 - fseek( f, posn1-4, SEEK_SET );
1.352 - fwrite( &blocklen, sizeof(blocklen), 1, f );
1.353 - fseek( f, posn2, SEEK_SET );
1.354 - }
1.355 + if( modules[i]->save != NULL ) {
1.356 + uint32_t blocklen, posn1, posn2;
1.357 + dreamcast_write_chunk_header( modules[i]->name, 0, f );
1.358 + posn1 = ftell(f);
1.359 + modules[i]->save(f);
1.360 + posn2 = ftell(f);
1.361 + blocklen = posn2 - posn1;
1.362 + fseek( f, posn1-4, SEEK_SET );
1.363 + fwrite( &blocklen, sizeof(blocklen), 1, f );
1.364 + fseek( f, posn2, SEEK_SET );
1.365 + }
1.366 }
1.367 fclose( f );
1.368 INFO( "Save state written to %s", filename );
.