Search
lxdream.org :: lxdream :: r689:9868667e3525
lxdream 0.9.1
released Jun 29
Download Now
changeset689:9868667e3525
parent688:8a13dabbdced
child690:1e8fd13a67ef
authornkeynes
dateMon Jun 16 10:58:41 2008 +0000 (15 years ago)
Unbreak and finish cleaning up the 'run for limited time' feature
src/dreamcast.c
src/dreamcast.h
src/main.c
1.1 --- a/src/dreamcast.c Sat Jun 14 11:57:11 2008 +0000
1.2 +++ b/src/dreamcast.c Mon Jun 16 10:58:41 2008 +0000
1.3 @@ -39,9 +39,11 @@
1.4
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.12
1.13 #define MAX_MODULES 32
1.14 static int num_modules = 0;
1.15 @@ -124,6 +126,15 @@
1.16 module->init();
1.17 }
1.18
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.28
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; // Finished
1.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.81
1.82 + }
1.83 }
1.84
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.96
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.132
1.133 void dreamcast_stop( void )
2.1 --- a/src/dreamcast.h Sat Jun 14 11:57:11 2008 +0000
2.2 +++ b/src/dreamcast.h Mon Jun 16 10:58:41 2008 +0000
2.3 @@ -40,7 +40,8 @@
2.4 void dreamcast_init(void);
2.5 void dreamcast_reset(void);
2.6 void dreamcast_run(void);
2.7 -void dreamcast_run_for( unsigned int seconds, unsigned int nanosecs );
2.8 +void dreamcast_set_run_time( unsigned int seconds, unsigned int nanosecs );
2.9 +void dreamcast_set_exit_on_stop( gboolean flag );
2.10 void dreamcast_stop(void);
2.11 void dreamcast_shutdown(void);
2.12 void dreamcast_config_changed(void);
3.1 --- a/src/main.c Sat Jun 14 11:57:11 2008 +0000
3.2 +++ b/src/main.c Mon Jun 16 10:58:41 2008 +0000
3.3 @@ -49,8 +49,6 @@
3.4 gboolean without_bios = FALSE;
3.5 gboolean use_xlat = TRUE;
3.6 gboolean show_debugger = FALSE;
3.7 -uint32_t time_secs = 0;
3.8 -uint32_t time_nanos = 0;
3.9 extern uint32_t sh4_cpu_multiplier;
3.10
3.11 int main (int argc, char *argv[])
3.12 @@ -58,6 +56,7 @@
3.13 int opt;
3.14 double t;
3.15 gboolean display_ok;
3.16 + uint32_t time_secs, time_nanos;
3.17
3.18 install_crash_handler();
3.19 gdrom_get_native_devices();
3.20 @@ -112,10 +111,12 @@
3.21 case 'h': /* Headless */
3.22 headless = TRUE;
3.23 break;
3.24 - case 't': /* Time limit */
3.25 + case 't': /* Time limit + auto quit */
3.26 t = strtod(optarg, NULL);
3.27 time_secs = (uint32_t)t;
3.28 time_nanos = (int)((t - time_secs) * 1000000000);
3.29 + dreamcast_set_run_time( time_secs, time_nanos );
3.30 + dreamcast_set_exit_on_stop( TRUE );
3.31 break;
3.32 case 'T': /* trace regions */
3.33 trace_regions = optarg;
3.34 @@ -204,22 +205,9 @@
3.35
3.36 sh4_set_use_xlat( use_xlat );
3.37
3.38 - /*
3.39 - if( start_immediately ) {
3.40 - if( dreamcast_can_run() ) {
3.41 - if( time_nanos != 0 || time_secs != 0 ) {
3.42 - dreamcast_run_for(time_secs, time_nanos);
3.43 - dreamcast_shutdown();
3.44 - return 0;
3.45 - } else {
3.46 - dreamcast_run();
3.47 - }
3.48 - } else {
3.49 - ERROR( "Unable to start dreamcast: no program/bios loaded" );
3.50 - }
3.51 - }
3.52 - */
3.53 - if( !headless ) {
3.54 + if( headless ) {
3.55 + dreamcast_run();
3.56 + } else {
3.57 gui_main_loop( start_immediately && dreamcast_can_run() );
3.58 }
3.59 dreamcast_shutdown();
.