# HG changeset patch # User nkeynes # Date 1189226318 0 # Node ID 86aa060ddcecb03b71b3d26e73d64d69aeac3b7f # Parent f2fe152cfc9b52e5e576b2aa63ddaa42c3947371 Add time-limited run option (for time trials) --- a/src/dreamcast.c Sat Sep 08 04:38:11 2007 +0000 +++ b/src/dreamcast.c Sat Sep 08 04:38:38 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: dreamcast.c,v 1.21 2007-01-16 10:34:46 nkeynes Exp $ + * $Id: dreamcast.c,v 1.22 2007-09-08 04:38:38 nkeynes Exp $ * Central switchboard for the system. This pulls all the individual modules * together into some kind of coherent structure. This is also where you'd * add Naomi support, if I ever get a board to play with... @@ -154,6 +154,42 @@ dreamcast_state = STATE_STOPPED; } +void dreamcast_run_for( unsigned int seconds, unsigned int nanosecs ) +{ + + int i; + if( dreamcast_state != STATE_RUNNING ) { + for( i=0; istart != NULL ) + modules[i]->start(); + } + } + dreamcast_state = STATE_RUNNING; + uint32_t nanos = 0; + if( nanosecs != 0 ) { + nanos = 1000000000 - nanosecs; + seconds++; + } + while( dreamcast_state == STATE_RUNNING && seconds != 0 ) { + int time_to_run = timeslice_length; + for( i=0; irun_time_slice != NULL ) + time_to_run = modules[i]->run_time_slice( time_to_run ); + } + nanos += time_to_run; + if( nanos >= 1000000000 ) { + nanos -= 1000000000; + seconds--; + } + } + + for( i=0; istop != NULL ) + modules[i]->stop(); + } + dreamcast_state = STATE_STOPPED; +} + void dreamcast_stop( void ) { if( dreamcast_state == STATE_RUNNING ) --- a/src/dreamcast.h Sat Sep 08 04:38:11 2007 +0000 +++ b/src/dreamcast.h Sat Sep 08 04:38:38 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: dreamcast.h,v 1.13 2007-08-23 12:33:27 nkeynes Exp $ + * $Id: dreamcast.h,v 1.14 2007-09-08 04:38:38 nkeynes Exp $ * * Public interface for dreamcast.c - * Central switchboard for the system. This pulls all the individual modules @@ -62,6 +62,7 @@ void dreamcast_init(void); void dreamcast_reset(void); void dreamcast_run(void); +void dreamcast_run_for( unsigned int seconds, unsigned int nanosecs ); void dreamcast_stop(void); gboolean dreamcast_load_config( const gchar *filename ); --- a/src/main.c Sat Sep 08 04:38:11 2007 +0000 +++ b/src/main.c Sat Sep 08 04:38:38 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: main.c,v 1.21 2007-09-08 04:05:35 nkeynes Exp $ + * $Id: main.c,v 1.22 2007-09-08 04:38:38 nkeynes Exp $ * * Main program, initializes dreamcast and gui, then passes control off to * the gtk main loop (currently). @@ -35,7 +35,7 @@ #define S3M_PLAYER "s3mplay.bin" -char *option_list = "a:s:A:V:puhbd:c:"; +char *option_list = "a:s:A:V:puhbd:c:t:"; struct option longopts[1] = { { NULL, 0, 0, 0 } }; char *aica_program = NULL; char *s3m_file = NULL; @@ -46,6 +46,8 @@ gboolean start_immediately = FALSE; gboolean headless = FALSE; gboolean without_bios = FALSE; +uint32_t time_secs = 0; +uint32_t time_nanos = 0; audio_driver_t audio_driver_list[] = { &audio_null_driver, &audio_esd_driver, @@ -58,6 +60,7 @@ int main (int argc, char *argv[]) { int opt, i; + double t; #ifdef ENABLE_NLS bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR); textdomain (PACKAGE); @@ -96,6 +99,10 @@ case 'h': /* Headless */ headless = TRUE; break; + case 't': /* Time limit */ + t = strtod(optarg, NULL); + time_secs = (uint32_t)t; + time_nanos = (int)((t - time_secs) * 1000000000); } } @@ -172,8 +179,14 @@ gdrom_mount_image( disc_file ); } - if( start_immediately ) - dreamcast_run(); + if( start_immediately ) { + if( time_nanos != 0 || time_secs != 0 ) { + dreamcast_run_for(time_secs, time_nanos); + return 0; + } else { + dreamcast_run(); + } + } if( !headless ) { gtk_main (); }