Search
lxdream.org :: lxdream :: r372:86aa060ddcec
lxdream 0.9.1
released Jun 29
Download Now
changeset372:86aa060ddcec
parent371:f2fe152cfc9b
child373:0ac2ac96a4c5
authornkeynes
dateSat Sep 08 04:38:38 2007 +0000 (16 years ago)
Add time-limited run option (for time trials)
src/dreamcast.c
src/dreamcast.h
src/main.c
1.1 --- a/src/dreamcast.c Sat Sep 08 04:38:11 2007 +0000
1.2 +++ b/src/dreamcast.c Sat Sep 08 04:38:38 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: dreamcast.c,v 1.21 2007-01-16 10:34:46 nkeynes Exp $
1.6 + * $Id: dreamcast.c,v 1.22 2007-09-08 04:38:38 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 @@ -154,6 +154,42 @@
1.11 dreamcast_state = STATE_STOPPED;
1.12 }
1.13
1.14 +void dreamcast_run_for( unsigned int seconds, unsigned int nanosecs )
1.15 +{
1.16 +
1.17 + int i;
1.18 + if( dreamcast_state != STATE_RUNNING ) {
1.19 + for( i=0; i<num_modules; i++ ) {
1.20 + if( modules[i]->start != NULL )
1.21 + modules[i]->start();
1.22 + }
1.23 + }
1.24 + dreamcast_state = STATE_RUNNING;
1.25 + uint32_t nanos = 0;
1.26 + if( nanosecs != 0 ) {
1.27 + nanos = 1000000000 - nanosecs;
1.28 + seconds++;
1.29 + }
1.30 + while( dreamcast_state == STATE_RUNNING && seconds != 0 ) {
1.31 + int time_to_run = timeslice_length;
1.32 + for( i=0; i<num_modules; i++ ) {
1.33 + if( modules[i]->run_time_slice != NULL )
1.34 + time_to_run = modules[i]->run_time_slice( time_to_run );
1.35 + }
1.36 + nanos += time_to_run;
1.37 + if( nanos >= 1000000000 ) {
1.38 + nanos -= 1000000000;
1.39 + seconds--;
1.40 + }
1.41 + }
1.42 +
1.43 + for( i=0; i<num_modules; i++ ) {
1.44 + if( modules[i]->stop != NULL )
1.45 + modules[i]->stop();
1.46 + }
1.47 + dreamcast_state = STATE_STOPPED;
1.48 +}
1.49 +
1.50 void dreamcast_stop( void )
1.51 {
1.52 if( dreamcast_state == STATE_RUNNING )
2.1 --- a/src/dreamcast.h Sat Sep 08 04:38:11 2007 +0000
2.2 +++ b/src/dreamcast.h Sat Sep 08 04:38:38 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: dreamcast.h,v 1.13 2007-08-23 12:33:27 nkeynes Exp $
2.6 + * $Id: dreamcast.h,v 1.14 2007-09-08 04:38:38 nkeynes Exp $
2.7 *
2.8 * Public interface for dreamcast.c -
2.9 * Central switchboard for the system. This pulls all the individual modules
2.10 @@ -62,6 +62,7 @@
2.11 void dreamcast_init(void);
2.12 void dreamcast_reset(void);
2.13 void dreamcast_run(void);
2.14 +void dreamcast_run_for( unsigned int seconds, unsigned int nanosecs );
2.15 void dreamcast_stop(void);
2.16
2.17 gboolean dreamcast_load_config( const gchar *filename );
3.1 --- a/src/main.c Sat Sep 08 04:38:11 2007 +0000
3.2 +++ b/src/main.c Sat Sep 08 04:38:38 2007 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: main.c,v 1.21 2007-09-08 04:05:35 nkeynes Exp $
3.6 + * $Id: main.c,v 1.22 2007-09-08 04:38:38 nkeynes Exp $
3.7 *
3.8 * Main program, initializes dreamcast and gui, then passes control off to
3.9 * the gtk main loop (currently).
3.10 @@ -35,7 +35,7 @@
3.11
3.12 #define S3M_PLAYER "s3mplay.bin"
3.13
3.14 -char *option_list = "a:s:A:V:puhbd:c:";
3.15 +char *option_list = "a:s:A:V:puhbd:c:t:";
3.16 struct option longopts[1] = { { NULL, 0, 0, 0 } };
3.17 char *aica_program = NULL;
3.18 char *s3m_file = NULL;
3.19 @@ -46,6 +46,8 @@
3.20 gboolean start_immediately = FALSE;
3.21 gboolean headless = FALSE;
3.22 gboolean without_bios = FALSE;
3.23 +uint32_t time_secs = 0;
3.24 +uint32_t time_nanos = 0;
3.25
3.26 audio_driver_t audio_driver_list[] = { &audio_null_driver,
3.27 &audio_esd_driver,
3.28 @@ -58,6 +60,7 @@
3.29 int main (int argc, char *argv[])
3.30 {
3.31 int opt, i;
3.32 + double t;
3.33 #ifdef ENABLE_NLS
3.34 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
3.35 textdomain (PACKAGE);
3.36 @@ -96,6 +99,10 @@
3.37 case 'h': /* Headless */
3.38 headless = TRUE;
3.39 break;
3.40 + case 't': /* Time limit */
3.41 + t = strtod(optarg, NULL);
3.42 + time_secs = (uint32_t)t;
3.43 + time_nanos = (int)((t - time_secs) * 1000000000);
3.44 }
3.45 }
3.46
3.47 @@ -172,8 +179,14 @@
3.48 gdrom_mount_image( disc_file );
3.49 }
3.50
3.51 - if( start_immediately )
3.52 - dreamcast_run();
3.53 + if( start_immediately ) {
3.54 + if( time_nanos != 0 || time_secs != 0 ) {
3.55 + dreamcast_run_for(time_secs, time_nanos);
3.56 + return 0;
3.57 + } else {
3.58 + dreamcast_run();
3.59 + }
3.60 + }
3.61 if( !headless ) {
3.62 gtk_main ();
3.63 }
.