allow to disable SH2 dynarec on runtime

This commit is contained in:
notaz 2013-08-31 20:02:59 +03:00
parent 835122bc0c
commit 0185b67736
9 changed files with 80 additions and 24 deletions

View file

@ -45,7 +45,6 @@ asm_mix ?= 1
else # if not arm else # if not arm
use_fame ?= 1 use_fame ?= 1
use_cz80 ?= 1 use_cz80 ?= 1
use_sh2mame ?= 1
endif endif
-include Makefile.local -include Makefile.local

View file

@ -52,7 +52,6 @@ else ifeq ($(platform), ios)
use_fame = 1 use_fame = 1
use_drz80 = 0 use_drz80 = 0
use_cz80 = 1 use_cz80 = 1
use_sh2mame = 0
use_sh2drc = 1 use_sh2drc = 1
use_svpdrc = 1 use_svpdrc = 1

View file

@ -20,6 +20,7 @@ void drc_cmn_init(void)
tcache, sizeof(tcache), ret); tcache, sizeof(tcache), ret);
#ifdef __arm__ #ifdef __arm__
if (PicoOpt & POPT_EN_DRC)
{ {
static int test_done; static int test_done;
if (!test_done) if (!test_done)

View file

@ -3111,12 +3111,10 @@ void sh2_drc_wcheck_da(unsigned int a, int val, int cpuid)
1 + cpuid, SH2_DRCBLK_DA_SHIFT, 0xfff); 1 + cpuid, SH2_DRCBLK_DA_SHIFT, 0xfff);
} }
int sh2_execute(SH2 *sh2c, int cycles) int sh2_execute_drc(SH2 *sh2c, int cycles)
{ {
int ret_cycles; int ret_cycles;
sh2c->cycles_timeslice = cycles;
// cycles are kept in SHR_SR unused bits (upper 20) // cycles are kept in SHR_SR unused bits (upper 20)
// bit11 contains T saved for delay slot // bit11 contains T saved for delay slot
// others are usual SH2 flags // others are usual SH2 flags
@ -3130,7 +3128,7 @@ int sh2_execute(SH2 *sh2c, int cycles)
dbg(1, "warning: drc returned with cycles: %d", ret_cycles); dbg(1, "warning: drc returned with cycles: %d", ret_cycles);
sh2c->sr &= 0x3f3; sh2c->sr &= 0x3f3;
return sh2c->cycles_timeslice - ret_cycles; return ret_cycles;
} }
#if (DRC_DEBUG & 2) #if (DRC_DEBUG & 2)

View file

@ -17,6 +17,38 @@ typedef unsigned short UINT16;
typedef unsigned char UINT8; typedef unsigned char UINT8;
#endif #endif
#ifdef DRC_SH2
// this nasty conversion is needed for drc-expecting memhandlers
#define MAKE_READFUNC(name, cname) \
static inline unsigned int name(SH2 *sh2, unsigned int a) \
{ \
unsigned int ret; \
sh2->sr |= sh2->icount << 12; \
ret = cname(a, sh2); \
sh2->icount = (signed int)sh2->sr >> 12; \
sh2->sr &= 0x3f3; \
return ret; \
}
#define MAKE_WRITEFUNC(name, cname) \
static inline void name(SH2 *sh2, unsigned int a, unsigned int d) \
{ \
sh2->sr |= sh2->icount << 12; \
cname(a, d, sh2); \
sh2->icount = (signed int)sh2->sr >> 12; \
sh2->sr &= 0x3f3; \
}
MAKE_READFUNC(RB, p32x_sh2_read8)
MAKE_READFUNC(RW, p32x_sh2_read16)
MAKE_READFUNC(RL, p32x_sh2_read32)
MAKE_WRITEFUNC(WB, p32x_sh2_write8)
MAKE_WRITEFUNC(WW, p32x_sh2_write16)
MAKE_WRITEFUNC(WL, p32x_sh2_write32)
#else
#define RB(sh2, a) p32x_sh2_read8(a, sh2) #define RB(sh2, a) p32x_sh2_read8(a, sh2)
#define RW(sh2, a) p32x_sh2_read16(a, sh2) #define RW(sh2, a) p32x_sh2_read16(a, sh2)
#define RL(sh2, a) p32x_sh2_read32(a, sh2) #define RL(sh2, a) p32x_sh2_read32(a, sh2)
@ -24,6 +56,8 @@ typedef unsigned char UINT8;
#define WW(sh2, a, d) p32x_sh2_write16(a, d, sh2) #define WW(sh2, a, d) p32x_sh2_write16(a, d, sh2)
#define WL(sh2, a, d) p32x_sh2_write32(a, d, sh2) #define WL(sh2, a, d) p32x_sh2_write32(a, d, sh2)
#endif
// some stuff from sh2comn.h // some stuff from sh2comn.h
#define T 0x00000001 #define T 0x00000001
#define S 0x00000002 #define S 0x00000002
@ -71,14 +105,13 @@ static unsigned int op_refs[0x10000];
#include "sh2.c" #include "sh2.c"
#ifndef DRC_SH2
#ifndef DRC_CMP #ifndef DRC_CMP
int sh2_execute(SH2 *sh2, int cycles) int sh2_execute_interpreter(SH2 *sh2, int cycles)
{ {
UINT32 opcode; UINT32 opcode;
sh2->icount = sh2->cycles_timeslice = cycles; sh2->icount = cycles;
if (sh2->icount <= 0) if (sh2->icount <= 0)
goto out; goto out;
@ -134,12 +167,12 @@ int sh2_execute(SH2 *sh2, int cycles)
while (sh2->icount > 0 || sh2->delay); /* can't interrupt before delay */ while (sh2->icount > 0 || sh2->delay); /* can't interrupt before delay */
out: out:
return sh2->cycles_timeslice - sh2->icount; return sh2->icount;
} }
#else // if DRC_CMP #else // if DRC_CMP
int sh2_execute(SH2 *sh2, int cycles) int sh2_execute_interpreter(SH2 *sh2, int cycles)
{ {
static unsigned int base_pc_[2] = { 0, 0 }; static unsigned int base_pc_[2] = { 0, 0 };
static unsigned int end_pc_[2] = { 0, 0 }; static unsigned int end_pc_[2] = { 0, 0 };
@ -233,11 +266,10 @@ int sh2_execute(SH2 *sh2, int cycles)
while (1); while (1);
out: out:
return sh2->cycles_timeslice - sh2->icount; return sh2->icount;
} }
#endif // DRC_CMP #endif // DRC_CMP
#endif // DRC_SH2
#ifdef SH2_STATS #ifdef SH2_STATS
#include <stdio.h> #include <stdio.h>

View file

@ -89,7 +89,23 @@ void sh2_do_irq(SH2 *sh2, int level, int vector);
void sh2_pack(const SH2 *sh2, unsigned char *buff); void sh2_pack(const SH2 *sh2, unsigned char *buff);
void sh2_unpack(SH2 *sh2, const unsigned char *buff); void sh2_unpack(SH2 *sh2, const unsigned char *buff);
int sh2_execute(SH2 *sh2, int cycles); int sh2_execute_drc(SH2 *sh2c, int cycles);
int sh2_execute_interpreter(SH2 *sh2c, int cycles);
static inline int sh2_execute(SH2 *sh2, int cycles, int use_drc)
{
int ret;
sh2->cycles_timeslice = cycles;
#ifdef DRC_SH2
if (use_drc)
ret = sh2_execute_drc(sh2, cycles);
else
#endif
ret = sh2_execute_interpreter(sh2, cycles);
return sh2->cycles_timeslice - ret;
}
// regs, pending_int*, cycles, reserved // regs, pending_int*, cycles, reserved
#define SH2_STATE_SIZE ((24 + 2 + 2 + 12) * 4) #define SH2_STATE_SIZE ((24 + 2 + 2 + 12) * 4)

View file

@ -371,7 +371,7 @@ static inline void run_sh2(SH2 *sh2, int m68k_cycles)
elprintf_sh2(sh2, EL_32X, "+run %u %d @%08x", elprintf_sh2(sh2, EL_32X, "+run %u %d @%08x",
sh2->m68krcycles_done, cycles, sh2->pc); sh2->m68krcycles_done, cycles, sh2->pc);
done = sh2_execute(sh2, cycles); done = sh2_execute(sh2, cycles, PicoOpt & POPT_EN_DRC);
sh2->m68krcycles_done += C_SH2_TO_M68K(*sh2, done); sh2->m68krcycles_done += C_SH2_TO_M68K(*sh2, done);
sh2->state &= ~SH2_STATE_RUN; sh2->state &= ~SH2_STATE_RUN;

View file

@ -165,10 +165,7 @@ SRCS_COMMON += $(R)platform/libpicofe/linux/host_dasm.c
LDFLAGS += -lbfd -lopcodes -liberty LDFLAGS += -lbfd -lopcodes -liberty
endif endif
endif # use_sh2drc endif # use_sh2drc
#
ifeq "$(use_sh2mame)" "1"
SRCS_COMMON += $(R)cpu/sh2/mame/sh2pico.c SRCS_COMMON += $(R)cpu/sh2/mame/sh2pico.c
endif
endif # !no_32x endif # !no_32x
OBJS_COMMON := $(SRCS_COMMON:.c=.o) OBJS_COMMON := $(SRCS_COMMON:.c=.o)

View file

@ -185,6 +185,9 @@ void retro_set_environment(retro_environment_t cb)
//{ "region", "Region; Auto|NTSC|PAL" }, //{ "region", "Region; Auto|NTSC|PAL" },
{ "picodrive_input1", "Input device 1; 3 button pad|6 button pad|None" }, { "picodrive_input1", "Input device 1; 3 button pad|6 button pad|None" },
{ "picodrive_input2", "Input device 2; 3 button pad|6 button pad|None" }, { "picodrive_input2", "Input device 2; 3 button pad|6 button pad|None" },
#ifdef DRC_SH2
{ "picodrive_drc", "Dynamic recompilers; enabled|disabled" },
#endif
{ NULL, NULL }, { NULL, NULL },
}; };
@ -688,6 +691,17 @@ static void update_variables(void)
var.key = "picodrive_input2"; var.key = "picodrive_input2";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
PicoSetInputDevice(1, input_name_to_val(var.value)); PicoSetInputDevice(1, input_name_to_val(var.value));
#ifdef DRC_SH2
var.value = NULL;
var.key = "picodrive_drc";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
if (strcmp(var.value, "enabled") == 0)
PicoOpt |= POPT_EN_DRC;
else
PicoOpt &= ~POPT_EN_DRC;
}
#endif
} }
void retro_run(void) void retro_run(void)