Tidy up overclock code

Also use full available precision for overclock ratio.
This commit is contained in:
Brian Koropoff 2017-10-05 17:31:34 -07:00
parent da0ee599a0
commit fe21bb5950
9 changed files with 78 additions and 56 deletions

View File

@ -440,9 +440,8 @@ LIBRETRO_CFLAGS += $(BPP_DEFINES) \
$(ENDIANNESS_DEFINES) \
$(PLATFORM_DEFINES) \
-D__LIBRETRO__ \
-DM68K_ALLOW_OVERCLOCK \
-DZ80_ALLOW_OVERCLOCK \
-DCYCLE_SHIFT=10
-DM68K_OVERCLOCK_SHIFT=20 \
-DZ80_OVERCLOCK_SHIFT=20
ifneq (,$(findstring msvc,$(platform)))
LIBRETRO_CFLAGS += -DINLINE="static _inline"

View File

@ -268,7 +268,7 @@ typedef struct
uint address_space; /* Current FC code */
#ifdef M68K_ALLOW_OVERCLOCK
#ifdef M68K_OVERCLOCK_SHIFT
int cycle_ratio;
#endif

View File

@ -319,8 +319,8 @@ void m68k_init(void)
}
#endif
#ifdef M68K_ALLOW_OVERCLOCK
m68k.cycle_ratio = 1 << CYCLE_SHIFT;
#ifdef M68K_OVERCLOCK_SHIFT
m68k.cycle_ratio = 1 << M68K_OVERCLOCK_SHIFT;
#endif
#if M68K_EMULATE_INT_ACK == OPT_ON

View File

@ -514,8 +514,8 @@
/* ---------------------------- Cycle Counting ---------------------------- */
#ifdef M68K_ALLOW_OVERCLOCK
#define USE_CYCLES(A) m68ki_cpu.cycles += ((A) * m68ki_cpu.cycle_ratio) >> CYCLE_SHIFT
#ifdef M68K_OVERCLOCK_SHIFT
#define USE_CYCLES(A) m68ki_cpu.cycles += ((A) * m68ki_cpu.cycle_ratio) >> M68K_OVERCLOCK_SHIFT
#else
#define USE_CYCLES(A) m68ki_cpu.cycles += (A)
#endif

View File

@ -284,8 +284,8 @@ void s68k_init(void)
}
#endif
#ifdef M68K_ALLOW_OVERCLOCK
s68k.cycle_ratio = 1 << CYCLE_SHIFT;
#ifdef M68K_OVERCLOCK_SHIFT
s68k.cycle_ratio = 1 << M68K_OVERCLOCK_SHIFT;
#endif
#if M68K_EMULATE_INT_ACK == OPT_ON

View File

@ -201,18 +201,15 @@
#define IFF2 Z80.iff2
#define HALT Z80.halt
#ifdef Z80_ALLOW_OVERCLOCK
#define USE_CYCLES(A) Z80.cycles += ((A) * z80_cycle_ratio) >> CYCLE_SHIFT
#ifdef Z80_OVERCLOCK_SHIFT
#define USE_CYCLES(A) Z80.cycles += ((A) * z80_cycle_ratio) >> Z80_OVERCLOCK_SHIFT
UINT32 z80_cycle_ratio;
#else
#define USE_CYCLES(A) Z80.cycles += (A)
#endif
Z80_Regs Z80;
#ifdef Z80_ALLOW_OVERCLOCK
UINT32 z80_cycle_ratio;
#endif
unsigned char *z80_readmap[64];
unsigned char *z80_writemap[64];
@ -3368,8 +3365,8 @@ void z80_init(const void *config, int (*irqcallback)(int))
memset(&Z80, 0, sizeof(Z80));
Z80.daisy = config;
Z80.irq_callback = irqcallback;
#ifdef Z80_ALLOW_OVERCLOCK
z80_cycle_ratio = 1 << CYCLE_SHIFT;
#ifdef Z80_OVERCLOCK_SHIFT
z80_cycle_ratio = 1 << Z80_OVERCLOCK_SHIFT;
#endif
/* Clear registers values (NB: should be random on real hardware ?) */

View File

@ -51,7 +51,7 @@ typedef struct
extern Z80_Regs Z80;
#ifdef Z80_ALLOW_OVERCLOCK
#ifdef Z80_OVERCLOCK_SHIFT
extern UINT32 z80_cycle_ratio;
#endif

View File

@ -54,12 +54,6 @@
#include <xtl.h>
#endif
#if defined(M68K_ALLOW_OVERCLOCK) || defined(Z80_ALLOW_OVERCLOCK)
#define HAVE_OVERCLOCK
/* Overclocking frame delay (hack) */
#define OVERCLOCK_FRAME_DELAY 100
#endif
#define RETRO_DEVICE_MDPAD_3B RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0)
#define RETRO_DEVICE_MDPAD_6B RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
#define RETRO_DEVICE_MSPAD_2B RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 2)
@ -82,6 +76,25 @@
#include "sms_ntsc.h"
#include <streams/file_stream.h>
#define STATIC_ASSERT(name, test) typedef struct { int assert_[(test)?1:-1]; } assert_ ## name ## _
#define M68K_MAX_CYCLES 1107
#define Z80_MAX_CYCLES 345
#define OVERCLOCK_FRAME_DELAY 100
#ifdef M68K_OVERCLOCK_SHIFT
#define HAVE_OVERCLOCK
STATIC_ASSERT(m68k_overflow,
M68K_MAX_CYCLES <= UINT_MAX >> (M68K_OVERCLOCK_SHIFT + 1));
#endif
#ifdef Z80_OVERCLOCK_SHIFT
#ifndef HAVE_OVERCLOCK
#define HAVE_OVERCLOCK
#endif
STATIC_ASSERT(z80_overflow,
Z80_MAX_CYCLES <= UINT_MAX >> (Z80_OVERCLOCK_SHIFT + 1));
#endif
sms_ntsc_t *sms_ntsc;
md_ntsc_t *md_ntsc;
@ -541,7 +554,7 @@ static void config_default(void)
config.lock_on = 0;
config.lcd = 0; /* 0.8 fixed point */
#ifdef HAVE_OVERCLOCK
config.overclock = 0;
config.overclock = 100;
#endif
config.no_sprite_limit = 0;
@ -812,6 +825,31 @@ static bool update_viewport(void)
return ((ow != vwidth) || (oh != vheight) || (oar != vaspect_ratio));
}
#ifdef HAVE_OVERCLOCK
static void update_overclock(void)
{
#ifdef M68K_OVERCLOCK_SHIFT
m68k.cycle_ratio = 1 << M68K_OVERCLOCK_SHIFT;
#endif
#ifdef Z80_OVERCLOCK_SHIFT
z80_cycle_ratio = 1 << Z80_OVERCLOCK_SHIFT;
#endif
if (overclock_delay == 0)
{
/* Cycle ratios multiply per-instruction cycle counts, so use
reciprocals */
#ifdef M68K_OVERCLOCK_SHIFT
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
m68k.cycle_ratio = (100 << M68K_OVERCLOCK_SHIFT) / config.overclock;
#endif
#ifdef Z80_OVERCLOCK_SHIFT
if ((system_hw & SYSTEM_PBC) != SYSTEM_MD)
z80_cycle_ratio = (100 << Z80_OVERCLOCK_SHIFT) / config.overclock;
#endif
}
}
#endif
static void check_variables(void)
{
unsigned orig_value;
@ -1258,17 +1296,19 @@ static void check_variables(void)
var.key = "genesis_plus_gx_overclock";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{
/* Cycle ratios multiply cycle count, so use reciprocal */
if (strcmp(var.value, "100%") == 0)
config.overclock = (100 << CYCLE_SHIFT)/100;
config.overclock = 100;
else if (strcmp(var.value, "125%") == 0)
config.overclock = (100 << CYCLE_SHIFT)/125;
config.overclock = 125;
else if (strcmp(var.value, "150%") == 0)
config.overclock = (100 << CYCLE_SHIFT)/150;
config.overclock = 150;
else if (strcmp(var.value, "175%") == 0)
config.overclock = (100 << CYCLE_SHIFT)/175;
config.overclock = 175;
else if (strcmp(var.value, "200%") == 0)
config.overclock = (100 << CYCLE_SHIFT)/200;
config.overclock = 200;
if (system_hw)
update_overclock();
}
#endif
@ -2074,6 +2114,7 @@ bool retro_unserialize(const void *data, size_t size)
#ifdef HAVE_OVERCLOCK
overclock_delay = OVERCLOCK_FRAME_DELAY;
update_overclock();
#endif
return TRUE;
@ -2240,9 +2281,6 @@ bool retro_load_game(const struct retro_game_info *info)
}
}
#ifdef HAVE_OVERCLOCK
overclock_delay = OVERCLOCK_FRAME_DELAY;
#endif
audio_init(SOUND_FREQUENCY, 0);
system_init();
system_reset();
@ -2253,6 +2291,11 @@ bool retro_load_game(const struct retro_game_info *info)
update_viewport();
#ifdef HAVE_OVERCLOCK
overclock_delay = OVERCLOCK_FRAME_DELAY;
update_overclock();
#endif
return true;
}
@ -2360,6 +2403,7 @@ void retro_reset(void)
{
#ifdef HAVE_OVERCLOCK
overclock_delay = OVERCLOCK_FRAME_DELAY;
update_overclock();
#endif
gen_reset(0);
}
@ -2371,38 +2415,20 @@ void retro_run(void)
#ifdef HAVE_OVERCLOCK
/* update overclock delay */
if (overclock_delay)
overclock_delay--;
if (overclock_delay && --overclock_delay == 0)
update_overclock();
#endif
if (system_hw == SYSTEM_MCD)
{
#ifdef M68K_ALLOW_OVERCLOCK
if (overclock_delay == 0)
m68k.cycle_ratio = config.overclock;
else
m68k.cycle_ratio = 1 << CYCLE_SHIFT;
#endif
system_frame_scd(0);
}
else if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
{
#ifdef M68K_ALLOW_OVERCLOCK
if (overclock_delay == 0)
m68k.cycle_ratio = config.overclock;
else
m68k.cycle_ratio = 1 << CYCLE_SHIFT;
#endif
system_frame_gen(0);
}
else
{
#ifdef Z80_ALLOW_OVERCLOCK
if (overclock_delay == 0)
z80_cycle_ratio = config.overclock;
else
z80_cycle_ratio = 1 << CYCLE_SHIFT;
#endif
system_frame_sms(0);
}

View File

@ -83,7 +83,7 @@ typedef unsigned char bool;
#define MODE5_MAX_SPRITES_PER_LINE (config.no_sprite_limit ? MAX_SPRITES_PER_LINE : (bitmap.viewport.w >> 4))
#define MODE5_MAX_SPRITE_PIXELS (config.no_sprite_limit ? MAX_SPRITES_PER_LINE * 32 : max_sprite_pixels)
typedef struct
typedef struct
{
int8 device;
uint8 port;