switch between interpreter and dynarec at runtime

This commit is contained in:
Flyinghead 2018-11-11 23:49:41 +01:00
parent fb92d8d8c5
commit 9ccf0efdea
3 changed files with 51 additions and 14 deletions

View File

@ -47,6 +47,7 @@ extern bool naomi_test_button;
void dc_stop(void); void dc_stop(void);
bool dc_loadstate(void); bool dc_loadstate(void);
bool dc_savestate(void); bool dc_savestate(void);
void dc_enable_dynarec(bool enable);
enum enum
{ {
@ -446,6 +447,10 @@ void input_x11_handle()
naomi_test_button = e.type == KeyPress; naomi_test_button = e.type == KeyPress;
} }
#endif #endif
else if (e.type == KeyRelease && e.xkey.keycode == KEY_F6)
{
dc_enable_dynarec(settings.dynarec.Enable == 0);
}
else else
{ {
int dc_key = x11_keymap[e.xkey.keycode]; int dc_key = x11_keymap[e.xkey.keycode];

View File

@ -23,9 +23,10 @@
void FlushCache(); void FlushCache();
settings_t settings; settings_t settings;
static bool performed_serialization = false; static bool continue_running = false;
static cMutex mtx_serialization ; static cMutex mtx_serialization ;
static cMutex mtx_mainloop ; static cMutex mtx_mainloop ;
static int new_dynarec_setting = -1;
/* /*
libndc libndc
@ -356,21 +357,24 @@ int dc_init()
#endif #endif
#if FEAT_SHREC != DYNAREC_NONE #if FEAT_SHREC != DYNAREC_NONE
Get_Sh4Recompiler(&sh4_cpu);
sh4_cpu.Init(); // Also initialize the interpreter
if(settings.dynarec.Enable) if(settings.dynarec.Enable)
{ {
Get_Sh4Recompiler(&sh4_cpu);
printf("Using Recompiler\n"); printf("Using Recompiler\n");
} }
else else
#endif #endif
{ {
Get_Sh4Interpreter(&sh4_cpu); Get_Sh4Interpreter(&sh4_cpu);
#if FEAT_SHREC == DYNAREC_NONE
sh4_cpu.Init();
#endif
printf("Using Interpreter\n"); printf("Using Interpreter\n");
} }
InitAudio(); InitAudio();
sh4_cpu.Init();
mem_Init(); mem_Init();
mem_map_default(); mem_map_default();
@ -398,7 +402,7 @@ void dc_run()
{ {
while ( true ) while ( true )
{ {
performed_serialization = false ; continue_running = false ;
mtx_mainloop.Lock() ; mtx_mainloop.Lock() ;
sh4_cpu.Run(); sh4_cpu.Run();
mtx_mainloop.Unlock() ; mtx_mainloop.Unlock() ;
@ -406,7 +410,22 @@ void dc_run()
mtx_serialization.Lock() ; mtx_serialization.Lock() ;
mtx_serialization.Unlock() ; mtx_serialization.Unlock() ;
if (!performed_serialization) if (new_dynarec_setting != -1 && new_dynarec_setting != settings.dynarec.Enable)
{
settings.dynarec.Enable = new_dynarec_setting;
if (settings.dynarec.Enable)
{
Get_Sh4Recompiler(&sh4_cpu);
printf("Using Recompiler\n");
}
else
{
Get_Sh4Interpreter(&sh4_cpu);
printf("Using Interpreter\n");
}
sh4_cpu.ResetCache();
}
if (!continue_running)
break ; break ;
} }
} }
@ -620,13 +639,21 @@ bool acquire_mainloop_lock()
return result ; return result ;
} }
void dc_enable_dynarec(bool enable)
{
#if FEAT_SHREC != DYNAREC_NONE
continue_running = true;
new_dynarec_setting = enable;
dc_stop();
#endif
}
void cleanup_serialize(void *data) void cleanup_serialize(void *data)
{ {
if ( data != NULL ) if ( data != NULL )
free(data) ; free(data) ;
performed_serialization = true ; continue_running = true ;
dc_start() ;
mtx_serialization.Unlock() ; mtx_serialization.Unlock() ;
mtx_mainloop.Unlock() ; mtx_mainloop.Unlock() ;
@ -667,8 +694,7 @@ void* dc_savestate_thread(void* p)
if ( !acquire_mainloop_lock() ) if ( !acquire_mainloop_lock() )
{ {
printf("Failed to save state - could not acquire main loop lock\n") ; printf("Failed to save state - could not acquire main loop lock\n") ;
performed_serialization = true ; continue_running = true ;
dc_start() ;
mtx_serialization.Unlock() ; mtx_serialization.Unlock() ;
return NULL; return NULL;
} }
@ -736,8 +762,7 @@ void* dc_loadstate_thread(void* p)
if ( !acquire_mainloop_lock() ) if ( !acquire_mainloop_lock() )
{ {
printf("Failed to load state - could not acquire main loop lock\n") ; printf("Failed to load state - could not acquire main loop lock\n") ;
performed_serialization = true ; continue_running = true ;
dc_start() ;
mtx_serialization.Unlock() ; mtx_serialization.Unlock() ;
return NULL; return NULL;
} }

View File

@ -104,6 +104,9 @@ PCHAR*
} }
void dc_stop(void); void dc_stop(void);
void dc_savestate();
void dc_loadstate();
void dc_enable_dynarec(bool enable);
bool VramLockedWrite(u8* address); bool VramLockedWrite(u8* address);
bool ngen_Rewrite(unat& addr,unat retadr,unat acc); bool ngen_Rewrite(unat& addr,unat retadr,unat acc);
@ -253,8 +256,13 @@ void UpdateInputState(u32 port)
if (GetAsyncKeyState(VK_F1)) if (GetAsyncKeyState(VK_F1))
settings.pvr.ta_skip = 100; settings.pvr.ta_skip = 100;
// if (GetAsyncKeyState(VK_F2))
// settings.pvr.ta_skip = 0;
if (GetAsyncKeyState(VK_F2)) if (GetAsyncKeyState(VK_F2))
settings.pvr.ta_skip = 0; dc_savestate();
if (GetAsyncKeyState(VK_F4))
dc_loadstate();
if (GetAsyncKeyState(VK_F10)) if (GetAsyncKeyState(VK_F10))
DiscSwap(); DiscSwap();
@ -264,9 +272,8 @@ void UpdateInputState(u32 port)
coin_chute = GetAsyncKeyState(VK_F8); coin_chute = GetAsyncKeyState(VK_F8);
naomi_test_button = GetAsyncKeyState(VK_F7); naomi_test_button = GetAsyncKeyState(VK_F7);
#endif #endif
// also Naomi service button
if (GetAsyncKeyState(VK_F6)) if (GetAsyncKeyState(VK_F6))
kcode[port] &= ~key_CONT_C; dc_enable_dynarec(settings.dynarec.Enable == 0);
} }
void UpdateController(u32 port) void UpdateController(u32 port)