filename | src/sh4/sh4core.c |
changeset | 30:89b30313d757 |
prev | 27:1ef09a52cd1e |
next | 32:bf0bc2c524b8 |
author | nkeynes |
date | Sun Dec 25 05:57:00 2005 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Change timeslice to nanoseconds (was microseconds) Generize single step (now steps through active CPU) Add lots of header blocks |
file | annotate | diff | log | raw |
1.1 --- a/src/sh4/sh4core.c Sun Dec 25 01:28:39 2005 +00001.2 +++ b/src/sh4/sh4core.c Sun Dec 25 05:57:00 2005 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: sh4core.c,v 1.10 2005-12-25 01:28:39 nkeynes Exp $1.6 + * $Id: sh4core.c,v 1.11 2005-12-25 05:57:00 nkeynes Exp $1.7 *1.8 * SH4 emulation core, and parent module for all the SH4 peripheral1.9 * modules.1.10 @@ -41,11 +41,15 @@1.11 uint32_t sh4_bus_freq = SH4_BASE_RATE;1.12 uint32_t sh4_peripheral_freq = SH4_BASE_RATE / 2;1.14 +uint32_t sh4_cpu_period = 1000 / SH4_BASE_RATE; /* in nanoseconds */1.15 +uint32_t sh4_bus_period = 1000 / SH4_BASE_RATE;1.16 +uint32_t sh4_peripheral_period = 2000 / SH4_BASE_RATE;1.17 +1.18 /********************** SH4 Module Definition ****************************/1.20 void sh4_init( void );1.21 void sh4_reset( void );1.22 -int sh4_run_slice( int );1.23 +uint32_t sh4_run_slice( uint32_t );1.24 void sh4_start( void );1.25 void sh4_stop( void );1.26 void sh4_save_state( FILE *f );1.27 @@ -85,9 +89,9 @@1.28 intc_reset();1.29 }1.31 -int sh4_run_slice( int microsecs )1.32 +uint32_t sh4_run_slice( uint32_t nanosecs )1.33 {1.34 - int target = sh4r.icount + sh4_freq * microsecs;1.35 + int target = sh4r.icount + nanosecs / sh4_cpu_period;1.36 int start = sh4r.icount;1.37 int i;1.39 @@ -101,15 +105,20 @@1.40 if( !sh4_execute_instruction() )1.41 break;1.42 }1.43 - if( target != sh4r.icount ) {1.44 +1.45 + /* If we aborted early, but the cpu is still technically running,1.46 + * we're doing a hard abort - cut the timeslice back to what we1.47 + * actually executed1.48 + */1.49 + if( target != sh4r.icount && sh4r.sh4_state == SH4_STATE_RUNNING ) {1.50 /* Halted - compute time actually executed */1.51 - microsecs = (sh4r.icount - start) / sh4_freq;1.52 + nanosecs = (sh4r.icount - start) * sh4_cpu_period;1.53 }1.54 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {1.55 - TMU_run_slice( microsecs );1.56 - SCIF_run_slice( microsecs );1.57 + TMU_run_slice( nanosecs );1.58 + SCIF_run_slice( nanosecs );1.59 }1.60 - return microsecs;1.61 + return nanosecs;1.62 }1.64 void sh4_stop(void)
.