Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkcgen <1557255+kcgen@users.noreply.github.com>2020-08-10 06:07:26 +0300
committerkcgen <kcgen@users.noreply.github.com>2022-11-04 06:12:49 +0300
commite9489b0763ce743f240c53ad06d2b54349b7d52a (patch)
tree34f110094adf9952634bd59f419a84be48a22e85
parentb5d657dd4bf174a8fb18c627dae912afa39bab92 (diff)
[WIP] Low-latency cycle control
-rw-r--r--src/cpu/cpu.cpp5
-rw-r--r--src/dosbox.cpp50
2 files changed, 22 insertions, 33 deletions
diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index ab1240393..334ccb868 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -2128,10 +2128,7 @@ static void CPU_CycleIncrease(bool pressed) {
CPU_CycleLeft=0;CPU_Cycles=0;
if (CPU_CycleMax==old_cycles) CPU_CycleMax++;
- if(CPU_CycleMax > 15000 )
- LOG_MSG("CPU speed: fixed %d cycles. If you need more than 20000, try core=dynamic in DOSBox's options.",CPU_CycleMax);
- else
- LOG_MSG("CPU speed: fixed %d cycles.",CPU_CycleMax);
+ LOG_MSG("CPU speed: fixed %d cycles.",CPU_CycleMax);
GFX_SetTitle(CPU_CycleMax,-1,false);
}
}
diff --git a/src/dosbox.cpp b/src/dosbox.cpp
index 688609a71..de0ee3cb1 100644
--- a/src/dosbox.cpp
+++ b/src/dosbox.cpp
@@ -160,6 +160,9 @@ bool mono_cga=false;
void increaseticks_fixed();
static constexpr auto frame_pace_us = usT(1000 * 1000 / 60);
+static constexpr uint32_t frame_pace_ms = frame_pace_us.count() / 1000;
+static int32_t target_cycles;
+
static int frame_balance = 0;
static int pic_balance = 0;
static std::thread pic_pacer;
@@ -223,39 +226,27 @@ static Bitu Normal_Loop()
void increaseticks_fixed()
{
const auto ticksNew = GetTicks();
- if (ticksNew <= ticksLast) {
-
- while (pic_balance < 1)
- std::this_thread::sleep_for(usT(50));
- std::lock_guard<std::mutex> guard(pic_balance_mutex);
- pic_balance = 0;
+ if (ticksNew > ticksLast) {
+ ticksRemain = ticksNew - ticksLast;
+ ticksLast = ticksNew;
+
+ if (ticksRemain > frame_pace_ms) {
+ CPU_CycleMax -= CPU_CycleMax / 10;
+ ticksRemain = frame_pace_ms;
+ LOG_MSG("Dropped cycles to %u", CPU_CycleMax);
+ }
+ else if (ticksRemain > 3 && CPU_CycleMax < target_cycles) {
+ CPU_CycleMax += CPU_CycleMax / 25;
+ LOG_MSG("Bumped cycles to %u", CPU_CycleMax);
+ }
return;
}
-
- constexpr long int max_ticks_remaing = 20;
- ticksRemain = std::min(max_ticks_remaing, ticksNew - ticksLast);
- ticksLast = ticksNew;
- /* if (ticksRemain > 20)
- ticksRemain = 20; */
+ while (pic_balance < 1)
+ std::this_thread::sleep_for(usT(50));
+ std::lock_guard<std::mutex> guard(pic_balance_mutex);
+ pic_balance = 0;
}
-/* uint32_t t_remain = 0;
-uint32_t t_last = 0;
-
-void increaseticks_fixed()
-{
- const uint32_t t_new = GetTicks();
- if (t_new <= t_last) {
- while (pic_balance < 1)
- std::this_thread::sleep_for(usT(50));
- std::lock_guard<std::mutex> guard(pic_balance_mutex);
- pic_balance = 0;
- return;
- }
- t_remain = std::min(20u, t_new - t_last);
- t_last = t_new;
-} */
-
// For trying other delays
#define wrap_delay(a) SDL_Delay(a)
@@ -406,6 +397,7 @@ void DOSBOX_RunMachine()
pic_pacer.detach();
frame_pacer = std::thread(&pace_frame);
frame_pacer.detach();
+ target_cycles = CPU_CycleMax;
started = true;
}