Reintroduce delay reset support

Doing delay reset via instruction stepping hook seems to work.
This commit is contained in:
Ilari Liusvaara 2012-05-09 20:56:29 +03:00
parent 8645a1fee3
commit 2327483fb1

View file

@ -76,6 +76,17 @@ namespace
//Last frame params. //Last frame params.
bool last_hires = false; bool last_hires = false;
bool last_interlace = false; bool last_interlace = false;
//Delay reset.
unsigned long long delayreset_cycles_run;
unsigned long long delayreset_cycles_target;
bool delayreset_fn()
{
if(delayreset_cycles_run == delayreset_cycles_target || video_refresh_done)
return true;
delayreset_cycles_run++;
return false;
}
std::string save_jukebox_name(size_t i) std::string save_jukebox_name(size_t i)
{ {
@ -505,10 +516,13 @@ namespace
platform::set_paused(false); platform::set_paused(false);
}); });
function_ptr_command<> reset_c("reset", "Reset the SNES", function_ptr_command<const std::string&> reset_c("reset", "Reset the SNES",
"Syntax: reset\nResets the SNES in beginning of the next frame.\n", "Syntax: reset\nReset <delay>\nResets the SNES in beginning of the next frame.\n",
[]() throw(std::bad_alloc, std::runtime_error) { [](const std::string& x) throw(std::bad_alloc, std::runtime_error) {
pending_reset_cycles = 0; if(x == "")
pending_reset_cycles = 0;
else
pending_reset_cycles = parse_value<uint32_t>(x);
}); });
function_ptr_command<arg_filename> load_c("load", "Load savestate (current mode)", function_ptr_command<arg_filename> load_c("load", "Load savestate (current mode)",
@ -789,22 +803,16 @@ namespace
if(cycles == 0) if(cycles == 0)
messages << "SNES reset" << std::endl; messages << "SNES reset" << std::endl;
else if(cycles > 0) { else if(cycles > 0) {
messages << "SNES delayed reset not implemented (doing immediate reset)" << std::endl;
/* ... This code is just too buggy.
long cycles_executed = 0;
messages << "Executing delayed reset... This can take some time!" << std::endl; messages << "Executing delayed reset... This can take some time!" << std::endl;
while(cycles_executed < cycles && !video_refresh_done) { delayreset_cycles_run = 0;
//Poll inputs once in a while to prevent activating watchdog. delayreset_cycles_target = cycles;
if(cycles_executed % 100 == 0) SNES::cpu.step_event = delayreset_fn;
platform::flush_command_queue(); SNES::system.run();
SNES::cpu.op_step(); SNES::cpu.step_event = nall::function<bool()>();
cycles_executed++;
}
if(!video_refresh_done) if(!video_refresh_done)
messages << "SNES reset (delayed " << cycles_executed << ")" << std::endl; messages << "SNES reset (delayed " << delayreset_cycles_run << ")" << std::endl;
else else
messages << "SNES reset (forced at " << cycles_executed << ")" << std::endl; messages << "SNES reset (forced at " << delayreset_cycles_run << ")" << std::endl;
*/
} }
SNES::system.reset(); SNES::system.reset();
lua_callback_do_reset(); lua_callback_do_reset();