diff --git a/include/cpu.h b/include/cpu.h index f8429d7d..16e0d4ca 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -43,6 +43,7 @@ extern Bit32s CPU_CycleMax; extern Bit32s CPU_OldCycleMax; extern Bit32s CPU_CyclePercUsed; extern Bit32s CPU_CycleLimit; +extern Bit64s CPU_IODelayRemoved; extern bool CPU_CycleAutoAdjust; extern Bitu CPU_AutoDetermineMode; diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp index 359c43db..1f0be6e3 100644 --- a/src/cpu/cpu.cpp +++ b/src/cpu/cpu.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: cpu.cpp,v 1.96 2007-01-21 18:14:52 c2woody Exp $ */ +/* $Id: cpu.cpp,v 1.97 2007-02-04 11:10:22 qbix79 Exp $ */ #include #include @@ -54,6 +54,7 @@ Bit32s CPU_CyclePercUsed = 100; Bit32s CPU_CycleLimit = -1; Bit32s CPU_CycleUp = 0; Bit32s CPU_CycleDown = 0; +Bit64s CPU_IODelayRemoved = 0; CPU_Decoder * cpudecoder; bool CPU_CycleAutoAdjust; Bitu CPU_AutoDetermineMode; diff --git a/src/dosbox.cpp b/src/dosbox.cpp index c4ae9c41..8a3e7f0e 100644 --- a/src/dosbox.cpp +++ b/src/dosbox.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dosbox.cpp,v 1.113 2007-01-21 18:14:40 c2woody Exp $ */ +/* $Id: dosbox.cpp,v 1.114 2007-02-04 11:10:22 qbix79 Exp $ */ #include #include @@ -162,19 +162,37 @@ increaseticks: ticksRemain = 20; } ticksAdded = ticksRemain; - if (CPU_CycleAutoAdjust && (ticksAdded > 15 || ticksScheduled >= 250 || ticksDone >= 250) ) { - /* ratio we are aiming for is around 90% usage*/ - Bits ratio = (ticksScheduled * (CPU_CyclePercUsed*90*1024/100/100)) / ticksDone; -// LOG_MSG("Done %d schedulded %d ratio %d cycles %d", ticksDone, ticksScheduled, ratio, CPU_CycleMax); - if (ratio <= 1024) - CPU_CycleMax = (CPU_CycleMax * ratio) / 1024; - else - CPU_CycleMax = 1 + (CPU_CycleMax >> 1) + (CPU_CycleMax * ratio) / 2048; - if (CPU_CycleLimit>0) { - if (CPU_CycleMax>CPU_CycleLimit) CPU_CycleMax=CPU_CycleLimit; + if (CPU_CycleAutoAdjust) { + if(ticksScheduled >= 250 || ticksDone >= 250 || (ticksAdded > 15 && ticksScheduled >= 5) ) { + /* ratio we are aiming for is around 90% usage*/ + Bits ratio = (ticksScheduled * (CPU_CyclePercUsed*90*1024/100/100)) / ticksDone; + Bit32s new_cmax = CPU_CycleMax; + Bit64s cproc = (Bit64s)CPU_CycleMax * (Bit64s)ticksScheduled; + if(cproc > 0) { + double ratioremoved = (double) CPU_IODelayRemoved / (double) cproc; + if(ratioremoved < 1.0) { + ratio = (Bits)((double)ratio * (1 - ratioremoved)); + if (ratio <= 1024) + new_cmax = (CPU_CycleMax * ratio) / 1024; + else + new_cmax = 1 + (CPU_CycleMax >> 1) + (CPU_CycleMax * ratio) / 2048; + } + } + + // maybe care about not going negative + if (new_cmax > 0) + CPU_CycleMax = new_cmax; + if (CPU_CycleLimit > 0) { + if (CPU_CycleMax>CPU_CycleLimit) CPU_CycleMax = CPU_CycleLimit; + } + CPU_IODelayRemoved = 0; + ticksDone = 0; + ticksScheduled = 0; + } else if (ticksAdded > 15) { + CPU_CycleMax /= 3; + if (CPU_CycleMax < 100) + CPU_CycleMax = 100; } - ticksDone = 0; - ticksScheduled = 0; } } else { ticksAdded = 0; diff --git a/src/hardware/iohandler.cpp b/src/hardware/iohandler.cpp index ce1ba9c2..5fc3f19a 100644 --- a/src/hardware/iohandler.cpp +++ b/src/hardware/iohandler.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: iohandler.cpp,v 1.24 2007-01-13 10:43:40 qbix79 Exp $ */ +/* $Id: iohandler.cpp,v 1.25 2007-02-04 11:10:22 qbix79 Exp $ */ #include #include "dosbox.h" @@ -167,12 +167,11 @@ static Bits IOFaultCore(void) { * games with their timing of certain operations */ -extern Bit32s CPU_CycleMax; #define IODELAY_READ_MICROS 1.0 #define IODELAY_WRITE_MICROS 0.75 -inline void IO_USEC_read_delay() { +inline void IO_USEC_read_delay_old() { if(CPU_CycleMax > static_cast((IODELAY_READ_MICROS*1000.0))) { // this could be calculated whenever CPU_CycleMax changes Bitu delaycyc = static_cast((CPU_CycleMax/1000)*IODELAY_READ_MICROS); @@ -181,7 +180,7 @@ inline void IO_USEC_read_delay() { } } -inline void IO_USEC_write_delay() { +inline void IO_USEC_write_delay_old() { if(CPU_CycleMax > static_cast((IODELAY_WRITE_MICROS*1000.0))) { // this could be calculated whenever CPU_CycleMax changes Bitu delaycyc = static_cast((CPU_CycleMax/1000)*IODELAY_WRITE_MICROS); @@ -190,6 +189,27 @@ inline void IO_USEC_write_delay() { } } + +#define IODELAY_READ_MICROSk (Bit32u)(1024/1.0) +#define IODELAY_WRITE_MICROSk (Bit32u)(1024/0.75) + +inline void IO_USEC_read_delay() { + Bitu delaycyc = CPU_CycleMax/IODELAY_READ_MICROSk; + if(CPU_Cycles > delaycyc) { + CPU_Cycles -= delaycyc; + CPU_IODelayRemoved += delaycyc; + } else CPU_Cycles = 0; +} + +inline void IO_USEC_write_delay() { + Bitu delaycyc = CPU_CycleMax/IODELAY_WRITE_MICROSk; + if(CPU_Cycles > delaycyc) { + CPU_Cycles -= delaycyc; + CPU_IODelayRemoved += delaycyc; + } else CPU_Cycles = 0; +} + + void IO_WriteB(Bitu port,Bitu val) { if (GCC_UNLIKELY(GETFLAG(VM) && (CPU_IO_Exception(port,1)))) { LazyFlags old_lflags;