From 4a0acfb45a9c1ddc948724d441543dd971d1318f Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Sun, 12 Feb 2006 23:28:21 +0000 Subject: [PATCH] New format for mapper handlers to support keeping keys pressed. Add unlocked speed hotkey Add some sort of auto cycle guessing Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2490 --- include/cpu.h | 1 + src/cpu/callback.cpp | 7 ++-- src/cpu/cpu.cpp | 21 ++++++++--- src/dosbox.cpp | 84 ++++++++++++++++++++++++++++++++------------ 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/include/cpu.h b/include/cpu.h index 5c07092a..9e755a12 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -33,6 +33,7 @@ extern Bits CPU_Cycles; extern Bits CPU_CycleLeft; extern Bits CPU_CycleMax; +extern bool CPU_CycleAuto; /* Some common Defines */ /* A CPU Handler */ diff --git a/src/cpu/callback.cpp b/src/cpu/callback.cpp index 29a14244..91f13f49 100644 --- a/src/cpu/callback.cpp +++ b/src/cpu/callback.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: callback.cpp,v 1.30 2006-02-09 11:47:48 qbix79 Exp $ */ +/* $Id: callback.cpp,v 1.31 2006-02-12 23:28:21 harekiet Exp $ */ #include #include @@ -31,7 +31,6 @@ far return or and IRET */ - CallBack_Handler CallBack_Handlers[CB_MAX]; char* CallBack_Description[CB_MAX]; @@ -58,6 +57,7 @@ void CALLBACK_DeAllocate(Bitu in) { CallBack_Handlers[in]=&illegal_handler; } + void CALLBACK_Idle(void) { /* this makes the cpu execute instructions to handle irq's and then come back */ Bitu oldIF=GETFLAG(IF); @@ -70,7 +70,8 @@ void CALLBACK_Idle(void) { reg_eip=oldeip; SegSet16(cs,oldcs); SETFLAGBIT(IF,oldIF); - if (CPU_Cycles>0) CPU_Cycles=0; + if (!CPU_CycleAuto && CPU_Cycles>0) + CPU_Cycles=0; } static Bitu default_handler(void) { diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp index a4f87ad0..ff74d7af 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.76 2006-02-09 11:47:48 qbix79 Exp $ */ +/* $Id: cpu.cpp,v 1.77 2006-02-12 23:28:21 harekiet Exp $ */ #include #include "dosbox.h" @@ -45,6 +45,7 @@ Bits CPU_CycleMax = 2500; Bits CPU_CycleUp = 0; Bits CPU_CycleDown = 0; CPU_Decoder * cpudecoder; +bool CPU_CycleAuto; void CPU_Core_Full_Init(void); void CPU_Core_Normal_Init(void); @@ -52,7 +53,6 @@ void CPU_Core_Simple_Init(void); void CPU_Core_Dyn_X86_Init(void); void CPU_Core_Dyn_X86_Cache_Init(bool enable_cache); - /* In debug mode exceptions are tested and dosbox exits when * a unhandled exception state is detected. * USE CHECK_EXCEPT to raise an exception in that case to see if that exception @@ -1876,7 +1876,9 @@ void CPU_ENTER(bool use32,Bitu bytes,Bitu level) { } extern void GFX_SetTitle(Bits cycles ,Bits frameskip,bool paused); -static void CPU_CycleIncrease(void) { +static void CPU_CycleIncrease(bool pressed) { + if (!pressed) + return; Bits old_cycles=CPU_CycleMax; if(CPU_CycleUp < 100){ CPU_CycleMax = (Bits)(CPU_CycleMax * (1 + (float)CPU_CycleUp / 100.0)); @@ -1890,7 +1892,9 @@ static void CPU_CycleIncrease(void) { GFX_SetTitle(CPU_CycleMax,-1,false); } -static void CPU_CycleDecrease(void) { +static void CPU_CycleDecrease(bool pressed) { + if (!pressed) + return; if(CPU_CycleDown < 100){ CPU_CycleMax = (Bits)(CPU_CycleMax / (1 + (float)CPU_CycleDown / 100.0)); } else { @@ -1958,7 +1962,14 @@ public: Section_prop * section=static_cast(newconfig); CPU_CycleLeft=0;//needed ? CPU_Cycles=0; - CPU_CycleMax=section->Get_int("cycles");; + const char *cyclesLine = section->Get_string("cycles"); + if (!strcasecmp(cyclesLine,"auto")) { + CPU_CycleMax=0; + CPU_CycleAuto=true; + } else { + CPU_CycleMax=atoi(cyclesLine); + CPU_CycleAuto=false; + } CPU_CycleUp=section->Get_int("cycleup"); CPU_CycleDown=section->Get_int("cycledown"); const char * core=section->Get_string("core"); diff --git a/src/dosbox.cpp b/src/dosbox.cpp index cc51cef0..c6ffdf33 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.93 2006-02-09 11:47:48 qbix79 Exp $ */ +/* $Id: dosbox.cpp,v 1.94 2006-02-12 23:28:21 harekiet Exp $ */ #include #include @@ -38,6 +38,7 @@ #include "cross.h" #include "programs.h" #include "support.h" +#include "mapper.h" Config * control; MachineType machine; @@ -109,11 +110,15 @@ static LoopHandler * loop; bool SDLNetInited; -Bits RemainTicks; -Bits LastTicks; +static Bit32u ticksRemain; +static Bit32u ticksLast; +static Bit32u ticksAdded; +static Bit32u ticksDone; +static Bit32u ticksScheduled; +static bool ticksLocked; static Bitu Normal_Loop(void) { - Bits ret,NewTicks; + Bits ret; while (1) { if (PIC_RunQueue()) { ret=(*cpudecoder)(); @@ -126,27 +131,51 @@ static Bitu Normal_Loop(void) { if (DEBUG_ExitLoop()) return 0; #endif } else { - if (RemainTicks>0) { + GFX_Events(); + if (ticksRemain>0) { TIMER_AddTick(); - RemainTicks--; + ticksRemain--; } else goto increaseticks; } } increaseticks: - GFX_Events(); - NewTicks=GetTicks(); - if (NewTicks>LastTicks) { - RemainTicks=NewTicks-LastTicks; - if (RemainTicks>20) { -// LOG_MSG("Ticks to handle overflow %d",RemainTicks); - RemainTicks=20; + if (GCC_UNLIKELY(ticksLocked)) { + ticksRemain=5; + /* Reset any auto cycle guessing for this frame */ + ticksLast = GetTicks(); + ticksAdded = 0; + ticksDone = 0; + ticksScheduled = 0; + } else { + Bit32u ticksNew; + ticksNew=GetTicks(); + ticksScheduled += ticksAdded; + if (ticksNew > ticksLast) { + ticksRemain = ticksNew-ticksLast; + ticksLast = ticksNew; + ticksDone += ticksRemain; + if ( ticksRemain > 20 ) { + ticksRemain = 20; + } + ticksAdded = ticksRemain; + if (CPU_CycleAuto && (ticksScheduled >= 1000 || ticksDone >= 1000) ) { + /* ratio we are aiming for is around 90% usage*/ + Bits ratio = (ticksScheduled * (90*1024/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; + ticksDone = 0; + ticksScheduled = 0; + } + } else { + ticksAdded = 0; + SDL_Delay(1); + ticksDone -= GetTicks() - ticksNew; + if (ticksDone < 0) + ticksDone = 0; } - LastTicks=NewTicks; - } - //TODO Make this selectable in the config file, since it gives some lag */ - if (RemainTicks<=0) { - SDL_Delay(1); - return 0; } return 0; } @@ -166,16 +195,27 @@ void DOSBOX_RunMachine(void){ } while (!ret); } +static void DOSBOX_UnlockSpeed( bool pressed ) { + if (pressed) + ticksLocked = true; + else + ticksLocked = false; +} + static void DOSBOX_RealInit(Section * sec) { Section_prop * section=static_cast(sec); /* Initialize some dosbox internals */ - RemainTicks=0;LastTicks=GetTicks(); + ticksRemain=0; + ticksLast=GetTicks(); + ticksLocked = false; DOSBOX_SetLoop(&Normal_Loop); MSG_Init(section); + MAPPER_AddHandler(DOSBOX_UnlockSpeed, MK_f12, MMOD2,"speedlock","Speedlock"); svgaCard = SVGA_S3Trio; - machine=MCH_VGA;std::string cmd_machine; + machine=MCH_VGA; + std::string cmd_machine; const char * mtype; if (control->cmdline->FindString("-machine",cmd_machine,true)) mtype=cmd_machine.c_str(); else mtype=section->Get_string("machine"); @@ -236,7 +276,7 @@ void DOSBOX_Init(void) { secprop=control->AddSection_prop("cpu",&CPU_Init,true);//done secprop->Add_string("core","normal"); - secprop->Add_int("cycles",3000); + secprop->Add_string("cycles","3000"); secprop->Add_int("cycleup",500); secprop->Add_int("cycledown",20); MSG_Add("CPU_CONFIGFILE_HELP",