filename | src/dreamcast.c |
changeset | 689:9868667e3525 |
prev | 671:a530ea88eebd |
next | 727:f934967b77a3 |
author | nkeynes |
date | Thu Jun 19 04:40:37 2008 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Refactor the gd-rom list management out of the GUI (devices, recent files, etc). Add gd-rom list to the cocoa UI. |
file | annotate | diff | log | raw |
1.1 --- a/src/dreamcast.c Thu May 15 10:22:39 2008 +00001.2 +++ b/src/dreamcast.c Thu Jun 19 04:40:37 2008 +00001.3 @@ -39,9 +39,11 @@1.5 static volatile dreamcast_state_t dreamcast_state = STATE_UNINIT;1.6 static gboolean dreamcast_has_bios = FALSE;1.7 +static gboolean dreamcast_exit_on_stop = FALSE;1.8 static gchar *dreamcast_program_name = NULL;1.9 static sh4addr_t dreamcast_entry_point = 0xA0000000;1.10 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;1.11 +static uint64_t run_time_nanosecs = 0;1.13 #define MAX_MODULES 321.14 static int num_modules = 0;1.15 @@ -124,6 +126,15 @@1.16 module->init();1.17 }1.19 +void dreamcast_set_run_time( uint32_t secs, uint32_t nanosecs )1.20 +{1.21 + run_time_nanosecs = (((uint64_t)secs) * 1000000000) + nanosecs;1.22 +}1.23 +1.24 +void dreamcast_set_exit_on_stop( gboolean flag )1.25 +{1.26 + dreamcast_exit_on_stop = flag;1.27 +}1.29 void dreamcast_init( void )1.30 {1.31 @@ -146,63 +157,56 @@1.32 void dreamcast_run( void )1.33 {1.34 int i;1.35 +1.36 if( dreamcast_state != STATE_RUNNING ) {1.37 - for( i=0; i<num_modules; i++ ) {1.38 - if( modules[i]->start != NULL )1.39 - modules[i]->start();1.40 - }1.41 + for( i=0; i<num_modules; i++ ) {1.42 + if( modules[i]->start != NULL )1.43 + modules[i]->start();1.44 + }1.45 }1.46 +1.47 dreamcast_state = STATE_RUNNING;1.48 - while( dreamcast_state == STATE_RUNNING ) {1.49 - int time_to_run = timeslice_length;1.50 - for( i=0; i<num_modules; i++ ) {1.51 - if( modules[i]->run_time_slice != NULL )1.52 - time_to_run = modules[i]->run_time_slice( time_to_run );1.53 - }1.54 +1.55 + if( run_time_nanosecs != 0 ) {1.56 + while( dreamcast_state == STATE_RUNNING ) {1.57 + uint32_t time_to_run = timeslice_length;1.58 + if( run_time_nanosecs < time_to_run ) {1.59 + time_to_run = (uint32_t)run_time_nanosecs;1.60 + }1.61 +1.62 + for( i=0; i<num_modules; i++ ) {1.63 + if( modules[i]->run_time_slice != NULL )1.64 + time_to_run = modules[i]->run_time_slice( time_to_run );1.65 + }1.66 +1.67 + if( run_time_nanosecs > time_to_run ) {1.68 + run_time_nanosecs -= time_to_run;1.69 + } else {1.70 + run_time_nanosecs = 0; // Finished1.71 + break;1.72 + }1.73 + }1.74 + } else {1.75 + while( dreamcast_state == STATE_RUNNING ) {1.76 + int time_to_run = timeslice_length;1.77 + for( i=0; i<num_modules; i++ ) {1.78 + if( modules[i]->run_time_slice != NULL )1.79 + time_to_run = modules[i]->run_time_slice( time_to_run );1.80 + }1.82 + }1.83 }1.85 for( i=0; i<num_modules; i++ ) {1.86 - if( modules[i]->stop != NULL )1.87 - modules[i]->stop();1.88 + if( modules[i]->stop != NULL )1.89 + modules[i]->stop();1.90 }1.91 dreamcast_state = STATE_STOPPED;1.92 -}1.93 -1.94 -void dreamcast_run_for( unsigned int seconds, unsigned int nanosecs )1.95 -{1.97 - int i;1.98 - if( dreamcast_state != STATE_RUNNING ) {1.99 - for( i=0; i<num_modules; i++ ) {1.100 - if( modules[i]->start != NULL )1.101 - modules[i]->start();1.102 - }1.103 + if( dreamcast_exit_on_stop ) {1.104 + dreamcast_shutdown();1.105 + exit(0);1.106 }1.107 - dreamcast_state = STATE_RUNNING;1.108 - uint32_t nanos = 0;1.109 - if( nanosecs != 0 ) {1.110 - nanos = 1000000000 - nanosecs;1.111 - seconds++;1.112 - }1.113 - while( dreamcast_state == STATE_RUNNING && seconds != 0 ) {1.114 - int time_to_run = timeslice_length;1.115 - for( i=0; i<num_modules; i++ ) {1.116 - if( modules[i]->run_time_slice != NULL )1.117 - time_to_run = modules[i]->run_time_slice( time_to_run );1.118 - }1.119 - nanos += time_to_run;1.120 - if( nanos >= 1000000000 ) {1.121 - nanos -= 1000000000;1.122 - seconds--;1.123 - }1.124 - }1.125 -1.126 - for( i=0; i<num_modules; i++ ) {1.127 - if( modules[i]->stop != NULL )1.128 - modules[i]->stop();1.129 - }1.130 - dreamcast_state = STATE_STOPPED;1.131 }1.133 void dreamcast_stop( void )
.