Lightly refactor max CPU speed checks

- Better naming of the pivot point (@4.0x CPU)
    - Use floating point values divisible by 2 as the constants
This commit is contained in:
Aaron Culliney 2016-04-16 14:08:00 -07:00
parent f53dbea81e
commit dcb35226b7
5 changed files with 34 additions and 36 deletions

View File

@ -796,24 +796,18 @@ void c_interface_parameters()
switch (i + cur_off)
{
case OPT_CPU:
if (cpu_scale_factor >= CPU_SCALE_FASTEST)
{
if (cpu_scale_factor > CPU_SCALE_FASTEST_PIVOT) {
snprintf(temp, TEMPSIZE, "Fastest");
}
else
{
snprintf(temp, TEMPSIZE, "%d%%", (int)(cpu_scale_factor * 100.0));
} else {
snprintf(temp, TEMPSIZE, "%d%%", (int)roundf((cpu_scale_factor * 100.0)));
}
break;
case OPT_ALTCPU:
if (cpu_altscale_factor >= CPU_SCALE_FASTEST)
{
if (cpu_altscale_factor > CPU_SCALE_FASTEST_PIVOT) {
snprintf(temp, TEMPSIZE, "Fastest");
}
else
{
snprintf(temp, TEMPSIZE, "%d%%", (int)(cpu_altscale_factor * 100.0));
} else {
snprintf(temp, TEMPSIZE, "%d%%", (int)roundf((cpu_altscale_factor * 100.0)));
}
break;
@ -966,19 +960,25 @@ void c_interface_parameters()
switch (option)
{
case OPT_CPU:
cpu_scale_factor -= (cpu_scale_factor <= 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP;
if (cpu_scale_factor < CPU_SCALE_SLOWEST)
{
cpu_scale_factor = CPU_SCALE_SLOWEST;
if (cpu_scale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_scale_factor = CPU_SCALE_FASTEST_PIVOT;
} else {
cpu_scale_factor = roundf((cpu_scale_factor - ((cpu_scale_factor <= 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP)) * 100.f) / 100.f;
if (cpu_scale_factor < CPU_SCALE_SLOWEST) {
cpu_scale_factor = CPU_SCALE_SLOWEST;
}
}
prefs_setFloatValue(PREF_DOMAIN_VM, PREF_CPU_SCALE, roundf(cpu_scale_factor * 100.f));
break;
case OPT_ALTCPU:
cpu_altscale_factor -= (cpu_altscale_factor <= 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP;
if (cpu_altscale_factor < CPU_SCALE_SLOWEST)
{
cpu_altscale_factor = CPU_SCALE_SLOWEST;
if (cpu_altscale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_altscale_factor = CPU_SCALE_FASTEST_PIVOT;
} else {
cpu_altscale_factor = roundf((cpu_altscale_factor - ((cpu_altscale_factor <= 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP)) * 100.f) / 100.f;
if (cpu_altscale_factor < CPU_SCALE_SLOWEST) {
cpu_altscale_factor = CPU_SCALE_SLOWEST;
}
}
prefs_setFloatValue(PREF_DOMAIN_VM, PREF_CPU_SCALE_ALT, roundf(cpu_altscale_factor * 100.f));
break;
@ -1051,18 +1051,16 @@ void c_interface_parameters()
switch (option)
{
case OPT_CPU:
cpu_scale_factor += (cpu_scale_factor < 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP;
if (cpu_scale_factor >= CPU_SCALE_FASTEST)
{
cpu_scale_factor = roundf((cpu_scale_factor + ((cpu_scale_factor < 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP)) * 100.f) / 100.f;
if (cpu_scale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_scale_factor = CPU_SCALE_FASTEST;
}
prefs_setFloatValue(PREF_DOMAIN_VM, PREF_CPU_SCALE, roundf(cpu_scale_factor * 100.f));
break;
case OPT_ALTCPU:
cpu_altscale_factor += (cpu_altscale_factor < 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP;
if (cpu_altscale_factor >= CPU_SCALE_FASTEST)
{
cpu_altscale_factor = roundf((cpu_altscale_factor + ((cpu_altscale_factor < 1.0) ? CPU_SCALE_STEP_DIV : CPU_SCALE_STEP)) * 100.f) / 100.f;
if (cpu_altscale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_altscale_factor = CPU_SCALE_FASTEST;
}
prefs_setFloatValue(PREF_DOMAIN_VM, PREF_CPU_SCALE_ALT, roundf(cpu_altscale_factor * 100.f));

View File

@ -261,8 +261,8 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
double scale = (alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor);
int percent_scale = (int)round(scale * 100);
if (scale == CPU_SCALE_FASTEST) {
scale = CPU_SCALE_FASTEST0;
if (scale > CPU_SCALE_FASTEST_PIVOT) {
scale = CPU_SCALE_FASTEST_PIVOT;
percent_scale = (int)round(scale * 100);
} else {
if (percent_scale > 100) {

View File

@ -132,7 +132,7 @@ struct timespec timespec_add(struct timespec start, unsigned long nsecs) {
}
static void _timing_initialize(double scale) {
is_fullspeed = (scale >= CPU_SCALE_FASTEST);
is_fullspeed = (scale > CPU_SCALE_FASTEST_PIVOT);
if (!is_fullspeed) {
cycles_persec_target = CLK_6502 * scale;
}
@ -249,7 +249,7 @@ bool cpu_isPaused(void) {
#if !MOBILE_DEVICE
bool timing_shouldAutoAdjustSpeed(void) {
double speed = alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor;
return auto_adjust_speed && (speed < CPU_SCALE_FASTEST);
return auto_adjust_speed && (speed <= CPU_SCALE_FASTEST_PIVOT);
}
#endif
@ -505,7 +505,7 @@ static void *cpu_thread(void *dummyptr) {
video_isDirty(A2_DIRTY_FLAG) || (disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS))) )
{
double speed = alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor;
if (speed < CPU_SCALE_FASTEST) {
if (speed <= CPU_SCALE_FASTEST_PIVOT) {
TIMING_LOG("auto switching to configured speed");
_timing_initialize(speed);
}
@ -599,14 +599,14 @@ static void vm_prefsChanged(const char *domain) {
if (cpu_scale_factor < CPU_SCALE_SLOWEST) {
cpu_scale_factor = CPU_SCALE_SLOWEST;
}
if (cpu_scale_factor > CPU_SCALE_FASTEST) {
if (cpu_scale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_scale_factor = CPU_SCALE_FASTEST;
}
cpu_altscale_factor = prefs_parseFloatValue(PREF_DOMAIN_VM, PREF_CPU_SCALE_ALT, &fVal) ? fVal / 100.f : 1.f;
if (cpu_altscale_factor < CPU_SCALE_SLOWEST) {
cpu_altscale_factor = CPU_SCALE_SLOWEST;
}
if (cpu_altscale_factor > CPU_SCALE_FASTEST) {
if (cpu_altscale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_altscale_factor = CPU_SCALE_FASTEST;
}
#ifdef AUDIO_ENABLED

View File

@ -44,8 +44,8 @@
#define CLK_6502_INT ((unsigned int)CLK_6502)
#define CPU_SCALE_SLOWEST 0.25
#define CPU_SCALE_FASTEST0 4.0
#define CPU_SCALE_FASTEST 4.05
#define CPU_SCALE_FASTEST_PIVOT 4.0
#define CPU_SCALE_FASTEST (CPU_SCALE_FASTEST_PIVOT + 0.0625)
#ifdef INTERFACE_CLASSIC
# define CPU_SCALE_STEP_DIV 0.01
# define CPU_SCALE_STEP 0.05

View File

@ -286,7 +286,7 @@ static void _animation_showCPUSpeed(void) {
cpuTemplate[0][1] = ' ';
cpuTemplate[0][2] = buf[0];
cpuTemplate[0][3] = buf[1];
} else if (scale >= CPU_SCALE_FASTEST) {
} else if (scale > CPU_SCALE_FASTEST_PIVOT) {
cpuTemplate[0][1] = 'm';
cpuTemplate[0][2] = 'a';
cpuTemplate[0][3] = 'x';