From 26bc8da23d7d75a3cbd92bd2b7b6321852b7c8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Tue, 14 Nov 2006 14:12:00 +0000 Subject: [PATCH] favoured use of old simple core; default to automatic core selection; some processor usage limiting capabilities for max cycles Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2721 --- include/cpu.h | 8 ++-- include/pic.h | 6 +-- src/cpu/core_simple.cpp | 4 ++ src/cpu/cpu.cpp | 87 +++++++++++++++++++++++++---------------- src/cpu/paging.cpp | 2 +- src/dos/dos_execute.cpp | 16 +++++--- src/dosbox.cpp | 14 +++++-- src/gui/render.cpp | 4 +- src/gui/sdlmain.cpp | 16 +++++--- 9 files changed, 99 insertions(+), 58 deletions(-) diff --git a/include/cpu.h b/include/cpu.h index 90ab3d95..ada9d691 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -37,9 +37,11 @@ #define CPU_AUTODETERMINE_MASK 0x03 /* CPU Cycle Timing */ -extern Bits CPU_Cycles; -extern Bits CPU_CycleLeft; -extern Bits CPU_CycleMax; +extern Bit32s CPU_Cycles; +extern Bit32s CPU_CycleLeft; +extern Bit32s CPU_CycleMax; +extern Bit32s CPU_OldCycleMax; +extern Bit32s CPU_CyclePercUsed; extern bool CPU_CycleAutoAdjust; extern Bitu CPU_AutoDetermineMode; diff --git a/include/pic.h b/include/pic.h index 37e61c9d..e74a3f32 100644 --- a/include/pic.h +++ b/include/pic.h @@ -21,9 +21,9 @@ /* CPU Cycle Timing */ -extern Bits CPU_Cycles; -extern Bits CPU_CycleLeft; -extern Bits CPU_CycleMax; +extern Bit32s CPU_Cycles; +extern Bit32s CPU_CycleLeft; +extern Bit32s CPU_CycleMax; typedef void (PIC_EOIHandler) (void); typedef void (* PIC_EventHandler)(Bitu val); diff --git a/src/cpu/core_simple.cpp b/src/cpu/core_simple.cpp index e79514ab..a7d9c188 100644 --- a/src/cpu/core_simple.cpp +++ b/src/cpu/core_simple.cpp @@ -83,7 +83,11 @@ static const Bit32u AddrMaskTable[2]={0x0000ffff,0xffffffff}; static struct { Bitu opcode_index; +#if defined (_MSC_VER) + volatile HostPt cseip; +#else HostPt cseip; +#endif PhysPt base_ds,base_ss; SegNames base_val_ds; bool rep_zero; diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp index 243966be..2d8bddc8 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.87 2006-10-12 15:18:31 c2woody Exp $ */ +/* $Id: cpu.cpp,v 1.88 2006-11-14 14:11:59 c2woody Exp $ */ #include #include "dosbox.h" @@ -29,7 +29,7 @@ #include "support.h" Bitu DEBUG_EnableDebugger(void); -extern void GFX_SetTitle(Bits cycles ,Bits frameskip,bool paused); +extern void GFX_SetTitle(Bit32s cycles ,Bits frameskip,bool paused); #if 1 #undef LOG @@ -41,11 +41,13 @@ CPU_Regs cpu_regs; CPUBlock cpu; Segments Segs; -Bits CPU_Cycles = 0; -Bits CPU_CycleLeft = 0; -Bits CPU_CycleMax = 2500; -Bits CPU_CycleUp = 0; -Bits CPU_CycleDown = 0; +Bit32s CPU_Cycles = 0; +Bit32s CPU_CycleLeft = 0; +Bit32s CPU_CycleMax = 2500; +Bit32s CPU_OldCycleMax = 2500; +Bit32s CPU_CyclePercUsed = 100; +Bit32s CPU_CycleUp = 0; +Bit32s CPU_CycleDown = 0; CPU_Decoder * cpudecoder; bool CPU_CycleAutoAdjust; Bitu CPU_AutoDetermineMode; @@ -1450,7 +1452,11 @@ void CPU_SET_CRX(Bitu cr,Bitu value) { CPU_CycleAutoAdjust=true; CPU_CycleLeft=0; CPU_Cycles=0; + CPU_OldCycleMax=CPU_CycleMax; CPU_CycleMax=0; + GFX_SetTitle(CPU_CyclePercUsed,-1,false); + } else { + GFX_SetTitle(-1,-1,false); } #if (C_DYNAMIC_X86) if (CPU_AutoDetermineMode&CPU_AUTODETERMINE_CORE) { @@ -1459,7 +1465,6 @@ void CPU_SET_CRX(Bitu cr,Bitu value) { } #endif CPU_AutoDetermineMode<<=CPU_AUTODETERMINE_SHIFT; - GFX_SetTitle(-1,-1,false); } else { cpu.pmode=false; if (value & CR0_PAGING) LOG_MSG("Paging requested without PE=1"); @@ -1944,33 +1949,45 @@ void CPU_ENTER(bool use32,Bitu bytes,Bitu level) { } static void CPU_CycleIncrease(bool pressed) { - if (!pressed || CPU_CycleAutoAdjust) - return; - Bits old_cycles=CPU_CycleMax; - if(CPU_CycleUp < 100){ - CPU_CycleMax = (Bits)(CPU_CycleMax * (1 + (float)CPU_CycleUp / 100.0)); + if (!pressed) return; + if (CPU_CycleAutoAdjust) { + CPU_CyclePercUsed+=5; + if (CPU_CyclePercUsed>100) CPU_CyclePercUsed=100; + LOG_MSG("CPU:%d percent",CPU_CyclePercUsed); + GFX_SetTitle(CPU_CyclePercUsed,-1,false); } else { - CPU_CycleMax = (Bits)(CPU_CycleMax + CPU_CycleUp); + Bit32s old_cycles=CPU_CycleMax; + if (CPU_CycleUp < 100) { + CPU_CycleMax = (Bit32s)(CPU_CycleMax * (1 + (float)CPU_CycleUp / 100.0)); + } else { + CPU_CycleMax = (Bit32s)(CPU_CycleMax + CPU_CycleUp); + } + + CPU_CycleLeft=0;CPU_Cycles=0; + if (CPU_CycleMax==old_cycles) CPU_CycleMax++; + LOG_MSG("CPU:%d cycles",CPU_CycleMax); + GFX_SetTitle(CPU_CycleMax,-1,false); } - - CPU_CycleLeft=0;CPU_Cycles=0; - if (CPU_CycleMax==old_cycles) CPU_CycleMax++; - LOG_MSG("CPU:%d cycles",CPU_CycleMax); - GFX_SetTitle(CPU_CycleMax,-1,false); } static void CPU_CycleDecrease(bool pressed) { - if (!pressed || CPU_CycleAutoAdjust) - return; - if(CPU_CycleDown < 100){ - CPU_CycleMax = (Bits)(CPU_CycleMax / (1 + (float)CPU_CycleDown / 100.0)); + if (!pressed) return; + if (CPU_CycleAutoAdjust) { + CPU_CyclePercUsed-=5; + if (CPU_CyclePercUsed<=0) CPU_CyclePercUsed=1; + LOG_MSG("CPU:%d percent",CPU_CyclePercUsed); + GFX_SetTitle(CPU_CyclePercUsed,-1,false); } else { - CPU_CycleMax = (Bits)(CPU_CycleMax - CPU_CycleDown); + if (CPU_CycleDown < 100) { + CPU_CycleMax = (Bit32s)(CPU_CycleMax / (1 + (float)CPU_CycleDown / 100.0)); + } else { + CPU_CycleMax = (Bit32s)(CPU_CycleMax - CPU_CycleDown); + } + CPU_CycleLeft=0;CPU_Cycles=0; + if (CPU_CycleMax <= 0) CPU_CycleMax=1; + LOG_MSG("CPU:%d cycles",CPU_CycleMax); + GFX_SetTitle(CPU_CycleMax,-1,false); } - CPU_CycleLeft=0;CPU_Cycles=0; - if (CPU_CycleMax <= 0) CPU_CycleMax=1; - LOG_MSG("CPU:%d cycles",CPU_CycleMax); - GFX_SetTitle(CPU_CycleMax,-1,false); } class CPU: public Module_base { @@ -2037,11 +2054,14 @@ public: const char *cyclesLine = section->Get_string("cycles"); if (!strcasecmp(cyclesLine,"max")) { CPU_CycleMax=0; + CPU_CyclePercUsed=100; CPU_CycleAutoAdjust=true; } else { if (!strcasecmp(cyclesLine,"auto")) { CPU_AutoDetermineMode|=CPU_AUTODETERMINE_CYCLES; CPU_CycleMax=3000; + CPU_OldCycleMax=3000; + CPU_CyclePercUsed=100; } else { CPU_CycleMax=atoi(cyclesLine); } @@ -2050,11 +2070,11 @@ public: CPU_CycleUp=section->Get_int("cycleup"); CPU_CycleDown=section->Get_int("cycledown"); const char * core=section->Get_string("core"); - cpudecoder=&CPU_Core_Normal_Run; + cpudecoder=&CPU_Core_Simple_Run; if (!strcasecmp(core,"normal")) { - cpudecoder=&CPU_Core_Normal_Run; - } else if (!strcasecmp(core,"simple")) { cpudecoder=&CPU_Core_Simple_Run; + } else if (!strcasecmp(core,"force_normal")) { + cpudecoder=&CPU_Core_Normal_Run; } else if (!strcasecmp(core,"full")) { cpudecoder=&CPU_Core_Full_Run; } @@ -2066,7 +2086,7 @@ public: cpudecoder=&CPU_Core_Dyn_X86_Run; CPU_Core_Dyn_X86_SetFPUMode(false); } else if (!strcasecmp(core,"auto")) { - cpudecoder=&CPU_Core_Normal_Run; + cpudecoder=&CPU_Core_Simple_Run; CPU_AutoDetermineMode|=CPU_AUTODETERMINE_CORE; } #endif @@ -2081,7 +2101,8 @@ public: if(CPU_CycleMax <= 0) CPU_CycleMax = 2500; if(CPU_CycleUp <= 0) CPU_CycleUp = 500; if(CPU_CycleDown <= 0) CPU_CycleDown = 20; - GFX_SetTitle(CPU_CycleMax,-1,false); + if (CPU_CycleAutoAdjust) GFX_SetTitle(CPU_CyclePercUsed,-1,false); + else GFX_SetTitle(CPU_CycleMax,-1,false); return true; } ~CPU(){ /* empty */}; diff --git a/src/cpu/paging.cpp b/src/cpu/paging.cpp index 0fdb6dca..c2d1f934 100644 --- a/src/cpu/paging.cpp +++ b/src/cpu/paging.cpp @@ -395,7 +395,7 @@ void PAGING_Enable(bool enabled) { // LOG(LOG_PAGING,LOG_NORMAL)("Disabled"); } else { if (cpudecoder==CPU_Core_Simple_Run) { - LOG_MSG("CPU core simple won't run this game,switching to normal"); +// LOG_MSG("CPU core simple won't run this game,switching to normal"); cpudecoder=CPU_Core_Normal_Run; CPU_CycleLeft+=CPU_Cycles; CPU_Cycles=0; diff --git a/src/dos/dos_execute.cpp b/src/dos/dos_execute.cpp index e938537d..bc8e1c21 100644 --- a/src/dos/dos_execute.cpp +++ b/src/dos/dos_execute.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_execute.cpp,v 1.56 2006-06-29 09:10:09 c2woody Exp $ */ +/* $Id: dos_execute.cpp,v 1.57 2006-11-14 14:11:59 c2woody Exp $ */ #include #include @@ -27,6 +27,7 @@ #include "callback.h" #include "debug.h" #include "cpu.h" +#include "paging.h" const char * RunningProgram="DOSBOX"; @@ -94,7 +95,7 @@ static void RestoreRegisters(void) { reg_sp+=18; } -extern void GFX_SetTitle(Bits cycles,Bits frameskip,bool paused); +extern void GFX_SetTitle(Bit32s cycles,Bits frameskip,bool paused); void DOS_UpdatePSPName(void) { DOS_MCB mcb(dos.psp()-1); static char name[9]; @@ -146,16 +147,19 @@ bool DOS_Terminate(bool tsr) { CPU_CycleAutoAdjust=false; CPU_CycleLeft=0; CPU_Cycles=0; - CPU_CycleMax=3000; + CPU_CycleMax=CPU_OldCycleMax; + GFX_SetTitle(CPU_OldCycleMax,-1,false); + } else { + GFX_SetTitle(-1,-1,false); } - #if (C_DYNAMIC_X86) +#if (C_DYNAMIC_X86) if (CPU_AutoDetermineMode&CPU_AUTODETERMINE_CORE) { - cpudecoder=&CPU_Core_Normal_Run; + if (PAGING_Enabled()) cpudecoder=&CPU_Core_Normal_Run; + else cpudecoder=&CPU_Core_Simple_Run; CPU_CycleLeft=0; CPU_Cycles=0; } #endif - GFX_SetTitle(-1,-1,false); return true; } diff --git a/src/dosbox.cpp b/src/dosbox.cpp index 54c4c33b..25ea6d1b 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.103 2006-10-27 13:37:14 c2woody Exp $ */ +/* $Id: dosbox.cpp,v 1.104 2006-11-14 14:11:59 c2woody Exp $ */ #include #include @@ -101,6 +101,8 @@ void MSCDEX_Init(Section*); void EMS_Init(Section*); void XMS_Init(Section*); +void DOS_KeyboardLayout_Init(Section*); + void AUTOEXEC_Init(Section*); void SHELL_Init(void); @@ -148,7 +150,7 @@ increaseticks: ticksScheduled = 0; } else { Bit32u ticksNew; - ticksNew=GetTicks(); + ticksNew=GetTicks(); ticksScheduled += ticksAdded; if (ticksNew > ticksLast) { ticksRemain = ticksNew-ticksLast; @@ -160,7 +162,7 @@ increaseticks: ticksAdded = ticksRemain; if (CPU_CycleAutoAdjust && (ticksAdded > 15 || ticksScheduled >= 250 || ticksDone >= 250) ) { /* ratio we are aiming for is around 90% usage*/ - Bits ratio = (ticksScheduled * (90*1024/100)) / ticksDone ; + 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; @@ -277,12 +279,16 @@ void DOSBOX_Init(void) { ); secprop=control->AddSection_prop("cpu",&CPU_Init,true);//done +#if (C_DYNAMIC_X86) + secprop->Add_string("core","auto"); +#else secprop->Add_string("core","normal"); +#endif secprop->Add_string("cycles","auto"); secprop->Add_int("cycleup",500); secprop->Add_int("cycledown",20); MSG_Add("CPU_CONFIGFILE_HELP", - "core -- CPU Core used in emulation: simple,normal,full" + "core -- CPU Core used in emulation: normal" #if (C_DYNAMIC_X86) ",dynamic,auto.\n" " auto switches from normal to dynamic if appropriate" diff --git a/src/gui/render.cpp b/src/gui/render.cpp index 180c0417..a1e476e5 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: render.cpp,v 1.47 2006-08-05 09:06:44 qbix79 Exp $ */ +/* $Id: render.cpp,v 1.48 2006-11-14 14:12:00 c2woody Exp $ */ #include #include @@ -425,7 +425,7 @@ void RENDER_SetSize(Bitu width,Bitu height,Bitu bpp,float fps,double ratio,bool RENDER_CallBack( GFX_CallBackReset ); } -extern void GFX_SetTitle(Bits cycles, Bits frameskip,bool paused); +extern void GFX_SetTitle(Bit32s cycles, Bits frameskip,bool paused); static void IncreaseFrameSkip(bool pressed) { if (!pressed) return; diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index f4268761..bb6480d0 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: sdlmain.cpp,v 1.123 2006-10-31 17:29:32 qbix79 Exp $ */ +/* $Id: sdlmain.cpp,v 1.124 2006-11-14 14:12:00 c2woody Exp $ */ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -216,16 +216,20 @@ extern bool CPU_CycleAutoAdjust; //Globals for keyboard initialisation bool startup_state_numlock=false; bool startup_state_capslock=false; -void GFX_SetTitle(Bits cycles,Bits frameskip,bool paused){ +void GFX_SetTitle(Bit32s cycles,Bits frameskip,bool paused){ char title[200]={0}; - static Bits internal_cycles=0; + static Bit32s internal_cycles=0; static Bits internal_frameskip=0; if(cycles != -1) internal_cycles = cycles; if(frameskip != -1) internal_frameskip = frameskip; - if(CPU_CycleAutoAdjust) - sprintf(title,"DOSBox %s, Cpu Cycles: max, Frameskip %2d, Program: %8s",VERSION,internal_frameskip,RunningProgram); - else + if(CPU_CycleAutoAdjust) { + if (internal_cycles>=100) + sprintf(title,"DOSBox %s, Cpu Cycles: max, Frameskip %2d, Program: %8s",VERSION,internal_frameskip,RunningProgram); + else + sprintf(title,"DOSBox %s, Cpu Cycles: [%3d%%], Frameskip %2d, Program: %8s",VERSION,internal_cycles,internal_frameskip,RunningProgram); + } else { sprintf(title,"DOSBox %s, Cpu Cycles: %8d, Frameskip %2d, Program: %8s",VERSION,internal_cycles,internal_frameskip,RunningProgram); + } if(paused) strcat(title," PAUSED"); SDL_WM_SetCaption(title,VERSION);