Get rid of most absolute refs to lsnes_instance in src/core

This commit is contained in:
Ilari Liusvaara 2014-05-18 12:57:58 +03:00
parent 0b8e2f0a6b
commit 2ffe0066c9
14 changed files with 162 additions and 150 deletions

View file

@ -93,6 +93,7 @@ struct emulator_instance
cart_mappings_refresher cmapper; cart_mappings_refresher cmapper;
controller_state controls; controller_state controls;
project_state project; project_state project;
threads::id emu_thread;
//Queue stuff. //Queue stuff.
threads::lock queue_lock; threads::lock queue_lock;
threads::cv queue_condition; threads::cv queue_condition;

View file

@ -90,33 +90,33 @@ namespace
{ {
keyboard::ctrlrkey* k; keyboard::ctrlrkey* k;
if(binding.mode == 0) { if(binding.mode == 0) {
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "+controller " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "+controller "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name).str()); << binding.number << "" << binding.name).str());
promote_key(*k); promote_key(*k);
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "hold-controller " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "hold-controller "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name << "‣hold").str()); << binding.number << "" << binding.name << "‣hold").str());
promote_key(*k); promote_key(*k);
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "type-controller " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "type-controller "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name << "‣type").str()); << binding.number << "" << binding.name << "‣type").str());
promote_key(*k); promote_key(*k);
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "+autofire-controller " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "+autofire-controller "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name << "‣autofire").str()); << binding.number << "" << binding.name << "‣autofire").str());
promote_key(*k); promote_key(*k);
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "autofire-controller " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "autofire-controller "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name << "‣autofire toggle").str()); << binding.number << "" << binding.name << "‣autofire toggle").str());
promote_key(*k); promote_key(*k);
} else if(binding.mode == 1) { } else if(binding.mode == 1) {
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "designate-position " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "designate-position "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name).str()); << binding.number << "" << binding.name).str());
promote_key(*k); promote_key(*k);
} else if(binding.mode == 2) { } else if(binding.mode == 2) {
k = new keyboard::ctrlrkey(lsnes_instance.mapper, (stringfmt() << "controller-analog " k = new keyboard::ctrlrkey(CORE().mapper, (stringfmt() << "controller-analog "
<< name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#" << name).str(), (stringfmt() << "Controller‣" << binding.cclass << "‣#"
<< binding.number << "" << binding.name << " (axis)").str(), true); << binding.number << "" << binding.name << " (axis)").str(), true);
promote_key(*k); promote_key(*k);
@ -277,9 +277,9 @@ namespace
//This isn't active. check if there are any other active buttons on the thingy and don't complain //This isn't active. check if there are any other active buttons on the thingy and don't complain
//if there are. //if there are.
bool complain = true; bool complain = true;
auto ckey = lsnes_instance.keyboard.get_current_key(); auto ckey = CORE().keyboard.get_current_key();
if(ckey) { if(ckey) {
auto cb = lsnes_instance.mapper.get_controllerkeys_kbdkey(ckey); auto cb = CORE().mapper.get_controllerkeys_kbdkey(ckey);
for(auto i : cb) { for(auto i : cb) {
regex_results r = regex("[^ \t]+[ \t]+([^ \t]+)([ \t]+.*)?", i->get_command()); regex_results r = regex("[^ \t]+[ \t]+([^ \t]+)([ \t]+.*)?", i->get_command());
if(!r) if(!r)
@ -532,10 +532,10 @@ void reread_active_buttons()
std::map<std::string, unsigned> classnum; std::map<std::string, unsigned> classnum;
active_buttons.clear(); active_buttons.clear();
for(unsigned i = 0;; i++) { for(unsigned i = 0;; i++) {
auto x = lsnes_instance.controls.lcid_to_pcid(i); auto x = CORE().controls.lcid_to_pcid(i);
if(x.first < 0) if(x.first < 0)
break; break;
const port_type& pt = lsnes_instance.controls.get_blank().get_port_type(x.first); const port_type& pt = CORE().controls.get_blank().get_port_type(x.first);
const port_controller& ctrl = pt.controller_info->controllers[x.second]; const port_controller& ctrl = pt.controller_info->controllers[x.second];
if(!classnum.count(ctrl.cclass)) if(!classnum.count(ctrl.cclass))
classnum[ctrl.cclass] = 1; classnum[ctrl.cclass] = 1;
@ -578,9 +578,9 @@ void load_macros(controller_state& ctrlstate)
for(auto i : s) { for(auto i : s) {
if(!macro_binds.count(i)) { if(!macro_binds.count(i)) {
//New macro, create inverse bind. //New macro, create inverse bind.
macro_binds[i] = new keyboard::invbind(lsnes_instance.mapper, "macro " + i , "Macro‣" + i + macro_binds[i] = new keyboard::invbind(CORE().mapper, "macro " + i , "Macro‣" + i +
" (toggle)"); " (toggle)");
macro_binds2[i] = new keyboard::invbind(lsnes_instance.mapper, "+macro " + i , "Macro‣" + i + macro_binds2[i] = new keyboard::invbind(CORE().mapper, "+macro " + i , "Macro‣" + i +
" (hold)"); " (hold)");
} }
} }

View file

@ -77,7 +77,7 @@ void controller_state::autofire2(unsigned port, unsigned controller, unsigned pb
{ {
unsigned idx = _input.porttypes().triple_to_index(port, controller, pbid); unsigned idx = _input.porttypes().triple_to_index(port, controller, pbid);
if(duty) { if(duty) {
_autofire[idx].first_frame = lsnes_instance.mlogic.get_movie().get_current_frame(); _autofire[idx].first_frame = CORE().mlogic.get_movie().get_current_frame();
_autofire[idx].duty = duty; _autofire[idx].duty = duty;
_autofire[idx].cyclelen = cyclelen; _autofire[idx].cyclelen = cyclelen;
} else } else

View file

@ -201,8 +201,8 @@ void render_framebuffer()
ri.rq.run(main_screen); ri.rq.run(main_screen);
notify_set_screen(main_screen); notify_set_screen(main_screen);
//We would want divide by 2, but we'll do it ourselves in order to do mouse. //We would want divide by 2, but we'll do it ourselves in order to do mouse.
keyboard::key* mouse_x = lsnes_instance.keyboard.try_lookup_key("mouse_x"); keyboard::key* mouse_x = CORE().keyboard.try_lookup_key("mouse_x");
keyboard::key* mouse_y = lsnes_instance.keyboard.try_lookup_key("mouse_y"); keyboard::key* mouse_y = CORE().keyboard.try_lookup_key("mouse_y");
keyboard::mouse_calibration xcal; keyboard::mouse_calibration xcal;
keyboard::mouse_calibration ycal; keyboard::mouse_calibration ycal;
xcal.offset = ri.lgap; xcal.offset = ri.lgap;

View file

@ -3,6 +3,9 @@
#include "core/command.hpp" #include "core/command.hpp"
#include "core/keymapper.hpp" #include "core/keymapper.hpp"
#include "core/random.hpp" #include "core/random.hpp"
#ifdef __linux__
#include <execinfo.h>
#endif
emulator_instance::emulator_instance() emulator_instance::emulator_instance()
: setcache(settings), subtitles(&mlogic), mbranch(&mlogic), mteditor(&mlogic), : setcache(settings), subtitles(&mlogic), mbranch(&mlogic), mteditor(&mlogic),
@ -23,6 +26,13 @@ emulator_instance lsnes_instance;
emulator_instance& CORE() emulator_instance& CORE()
{ {
if(threads::id() != lsnes_instance.emu_thread) {
std::cerr << "WARNING: CORE() called in wrong thread." << std::endl;
#ifdef __linux__
void* arr[256];
backtrace_symbols_fd(arr, 256, 2);
#endif
}
return lsnes_instance; return lsnes_instance;
} }
@ -103,7 +113,7 @@ void emulator_instance::run_queue(bool unlocked) throw()
std::string c = commands.front(); std::string c = commands.front();
commands.pop_front(); commands.pop_front();
queue_lock.unlock(); queue_lock.unlock();
lsnes_instance.command.invoke(c); CORE().command.invoke(c);
queue_lock.lock(); queue_lock.lock();
queue_function_run = true; queue_function_run = true;
} }

View file

@ -1226,6 +1226,7 @@ void init_main_callbacks()
void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_to_succeed) throw(std::bad_alloc, void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_to_succeed) throw(std::bad_alloc,
std::runtime_error) std::runtime_error)
{ {
lsnes_instance.emu_thread = threads::id();
CORE().system_thread_available = true; CORE().system_thread_available = true;
//Basic initialization. //Basic initialization.
dispatch_set_error_streams(&messages.getstream()); dispatch_set_error_streams(&messages.getstream());

View file

@ -228,7 +228,7 @@ memwatch_item::memwatch_item()
scale_div = 1; scale_div = 1;
addr_base = 0; addr_base = 0;
addr_size = 0; addr_size = 0;
mspace = &lsnes_instance.memory; mspace = &CORE().memory;
} }
JSON::node memwatch_item::serialize() JSON::node memwatch_item::serialize()
@ -306,7 +306,7 @@ void memwatch_item::compatiblity_unserialize(const std::string& item)
case 'F': bytes = 8; signed_flag = true; float_flag = true; break; case 'F': bytes = 8; signed_flag = true; float_flag = true; break;
default: bytes = 0; break; default: bytes = 0; break;
} }
auto mdata = lsnes_instance.memory.lookup(addr); auto mdata = CORE().memory.lookup(addr);
if(mdata.first) { if(mdata.first) {
addr = mdata.second; addr = mdata.second;
addr_base = mdata.first->base; addr_base = mdata.first->base;
@ -328,7 +328,7 @@ void memwatch_item::compatiblity_unserialize(const std::string& item)
format = ""; format = "";
expr = (stringfmt() << "0x" << std::hex << addr).str(); expr = (stringfmt() << "0x" << std::hex << addr).str();
scale_div = 1; scale_div = 1;
mspace = &lsnes_instance.memory; mspace = &CORE().memory;
printer.position = memwatch_printer::PC_MEMORYWATCH; printer.position = memwatch_printer::PC_MEMORYWATCH;
printer.cond_enable = false; printer.cond_enable = false;
printer.enabled = "true"; printer.enabled = "true";

View file

@ -75,8 +75,8 @@ namespace
command::fnptr<const std::string&> test4(lsnes_cmds, "panicsave-movie", "", "", command::fnptr<const std::string&> test4(lsnes_cmds, "panicsave-movie", "", "",
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) { [](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
if(lsnes_instance.mlogic) emerg_save_movie(lsnes_instance.mlogic.get_mfile(), if(CORE().mlogic) emerg_save_movie(CORE().mlogic.get_mfile(),
lsnes_instance.mlogic.get_rrdata()); CORE().mlogic.get_rrdata());
}); });
//% is intentionally missing. //% is intentionally missing.
@ -134,7 +134,7 @@ struct loaded_rom load_rom_from_commandline(std::vector<std::string> cmdline) th
void dump_region_map() throw(std::bad_alloc) void dump_region_map() throw(std::bad_alloc)
{ {
std::list<struct memory_region*> regions = lsnes_instance.memory.get_regions(); std::list<struct memory_region*> regions = CORE().memory.get_regions();
for(auto i : regions) { for(auto i : regions) {
std::ostringstream x; std::ostringstream x;
x << hex::to(i->base) << "-" << hex::to(i->last_address()) << " " << hex::to(i->size) << " "; x << hex::to(i->base) << "-" << hex::to(i->last_address()) << " " << hex::to(i->size) << " ";

View file

@ -116,7 +116,7 @@ namespace
std::string get_mprefix_for_project() std::string get_mprefix_for_project()
{ {
return get_mprefix_for_project(lsnes_instance.mlogic ? lsnes_instance.mlogic.get_mfile().projectid : ""); return get_mprefix_for_project(CORE().mlogic ? CORE().mlogic.get_mfile().projectid : "");
} }
void set_mprefix_for_project(const std::string& prjid, const std::string& pfx) void set_mprefix_for_project(const std::string& prjid, const std::string& pfx)
@ -128,7 +128,7 @@ void set_mprefix_for_project(const std::string& prjid, const std::string& pfx)
void set_mprefix_for_project(const std::string& pfx) void set_mprefix_for_project(const std::string& pfx)
{ {
set_mprefix_for_project(lsnes_instance.mlogic ? lsnes_instance.mlogic.get_mfile().projectid : "", pfx); set_mprefix_for_project(CORE().mlogic ? CORE().mlogic.get_mfile().projectid : "", pfx);
set_mprefix(pfx); set_mprefix(pfx);
} }
@ -138,7 +138,7 @@ std::string translate_name_mprefix(std::string original, int& binary, int save)
regex_results r = regex("\\$SLOT:(.*)", original); regex_results r = regex("\\$SLOT:(.*)", original);
if(r) { if(r) {
if(binary < 0) if(binary < 0)
binary = jukebox_dflt_binary(lsnes_instance.settings) ? 1 : 0; binary = jukebox_dflt_binary(CORE().settings) ? 1 : 0;
if(p) { if(p) {
uint64_t branch = p->get_current_branch(); uint64_t branch = p->get_current_branch();
std::string branch_str; std::string branch_str;
@ -154,13 +154,13 @@ std::string translate_name_mprefix(std::string original, int& binary, int save)
} }
return filename; return filename;
} else { } else {
std::string pprf = lsnes_instance.setcache.get("slotpath") + "/"; std::string pprf = CORE().setcache.get("slotpath") + "/";
return pprf + get_mprefix() + r[1] + ".lsmv"; return pprf + get_mprefix() + r[1] + ".lsmv";
} }
} else { } else {
if(binary < 0) if(binary < 0)
binary = (save ? save_dflt_binary(lsnes_instance.settings) : binary = (save ? save_dflt_binary(CORE().settings) :
movie_dflt_binary(lsnes_instance.settings)) ? 1 : 0; movie_dflt_binary(CORE().settings)) ? 1 : 0;
return original; return original;
} }
} }
@ -197,12 +197,12 @@ std::string resolve_relative_path(const std::string& path)
void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc, void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc,
std::runtime_error) std::runtime_error)
{ {
if(!lsnes_instance.mlogic || !lsnes_instance.mlogic.get_mfile().gametype) { if(!CORE().mlogic || !CORE().mlogic.get_mfile().gametype) {
platform::error_message("Can't save movie without a ROM"); platform::error_message("Can't save movie without a ROM");
messages << "Can't save movie without a ROM" << std::endl; messages << "Can't save movie without a ROM" << std::endl;
return; return;
} }
auto& target = lsnes_instance.mlogic.get_mfile(); auto& target = CORE().mlogic.get_mfile();
std::string filename2 = translate_name_mprefix(filename, binary, 1); std::string filename2 = translate_name_mprefix(filename, binary, 1);
lua_callback_pre_save(filename2, true); lua_callback_pre_save(filename2, true);
try { try {
@ -216,7 +216,7 @@ void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc
} }
target.savestate = our_rom.save_core_state(); target.savestate = our_rom.save_core_state();
get_framebuffer().save(target.screenshot); get_framebuffer().save(target.screenshot);
lsnes_instance.mlogic.get_movie().save_state(target.projectid, target.save_frame, CORE().mlogic.get_movie().save_state(target.projectid, target.save_frame,
target.lagged_frames, target.pollcounters); target.lagged_frames, target.pollcounters);
target.poll_flag = our_rom.rtype->get_pflag(); target.poll_flag = our_rom.rtype->get_pflag();
auto prj = CORE().project.get(); auto prj = CORE().project.get();
@ -226,7 +226,7 @@ void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc
} }
target.active_macros = CORE().controls.get_macro_frames(); target.active_macros = CORE().controls.get_macro_frames();
target.save(filename2, savecompression(CORE().settings), binary > 0, target.save(filename2, savecompression(CORE().settings), binary > 0,
lsnes_instance.mlogic.get_rrdata()); CORE().mlogic.get_rrdata());
uint64_t took = get_utime() - origtime; uint64_t took = get_utime() - origtime;
std::string kind = (binary > 0) ? "(binary format)" : "(zip format)"; std::string kind = (binary > 0) ? "(binary format)" : "(zip format)";
messages << "Saved state " << kind << " '" << filename2 << "' in " << took << " microseconds." messages << "Saved state " << kind << " '" << filename2 << "' in " << took << " microseconds."
@ -250,12 +250,12 @@ void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc
//Save movie. //Save movie.
void do_save_movie(const std::string& filename, int binary) throw(std::bad_alloc, std::runtime_error) void do_save_movie(const std::string& filename, int binary) throw(std::bad_alloc, std::runtime_error)
{ {
if(!lsnes_instance.mlogic || !lsnes_instance.mlogic.get_mfile().gametype) { if(!CORE().mlogic || !CORE().mlogic.get_mfile().gametype) {
platform::error_message("Can't save movie without a ROM"); platform::error_message("Can't save movie without a ROM");
messages << "Can't save movie without a ROM" << std::endl; messages << "Can't save movie without a ROM" << std::endl;
return; return;
} }
auto& target = lsnes_instance.mlogic.get_mfile(); auto& target = CORE().mlogic.get_mfile();
std::string filename2 = translate_name_mprefix(filename, binary, 0); std::string filename2 = translate_name_mprefix(filename, binary, 0);
lua_callback_pre_save(filename2, false); lua_callback_pre_save(filename2, false);
try { try {
@ -267,8 +267,8 @@ void do_save_movie(const std::string& filename, int binary) throw(std::bad_alloc
target.authors = prj->authors; target.authors = prj->authors;
} }
target.active_macros.clear(); target.active_macros.clear();
target.save(filename2, savecompression(lsnes_instance.settings), binary > 0, target.save(filename2, savecompression(CORE().settings), binary > 0,
lsnes_instance.mlogic.get_rrdata()); CORE().mlogic.get_rrdata());
uint64_t took = get_utime() - origtime; uint64_t took = get_utime() - origtime;
std::string kind = (binary > 0) ? "(binary format)" : "(zip format)"; std::string kind = (binary > 0) ? "(binary format)" : "(zip format)";
messages << "Saved movie " << kind << " '" << filename2 << "' in " << took << " microseconds." messages << "Saved movie " << kind << " '" << filename2 << "' in " << took << " microseconds."
@ -395,7 +395,7 @@ namespace
random_seed_value = _movie.movie_rtc_second; random_seed_value = _movie.movie_rtc_second;
if(will_load_state) { if(will_load_state) {
//If settings possibly change, reload the ROM. //If settings possibly change, reload the ROM.
if(!lsnes_instance.mlogic || lsnes_instance.mlogic.get_mfile().projectid != _movie.projectid) if(!CORE().mlogic || CORE().mlogic.get_mfile().projectid != _movie.projectid)
our_rom.load(_movie.settings, _movie.movie_rtc_second, _movie.movie_rtc_subsecond); our_rom.load(_movie.settings, _movie.movie_rtc_second, _movie.movie_rtc_subsecond);
//Load the savestate and movie state. //Load the savestate and movie state.
//Set the core ports in order to avoid port state being reinitialized when loading. //Set the core ports in order to avoid port state being reinitialized when loading.
@ -425,35 +425,35 @@ namespace
void do_load_rom() throw(std::bad_alloc, std::runtime_error) void do_load_rom() throw(std::bad_alloc, std::runtime_error)
{ {
bool load_readwrite = !lsnes_instance.mlogic || !lsnes_instance.mlogic.get_movie().readonly_mode(); bool load_readwrite = !CORE().mlogic || !CORE().mlogic.get_movie().readonly_mode();
if(lsnes_instance.mlogic) { if(CORE().mlogic) {
port_type_set& portset = construct_movie_portset(lsnes_instance.mlogic.get_mfile(), our_rom); port_type_set& portset = construct_movie_portset(CORE().mlogic.get_mfile(), our_rom);
//If portset or gametype changes, force readwrite with new movie. //If portset or gametype changes, force readwrite with new movie.
if(lsnes_instance.mlogic.get_mfile().input->get_types() != portset) load_readwrite = true; if(CORE().mlogic.get_mfile().input->get_types() != portset) load_readwrite = true;
if(our_rom.rtype != &lsnes_instance.mlogic.get_mfile().gametype->get_type()) load_readwrite = true; if(our_rom.rtype != &CORE().mlogic.get_mfile().gametype->get_type()) load_readwrite = true;
} }
if(!load_readwrite) { if(!load_readwrite) {
//Read-only load. This is pretty simple. //Read-only load. This is pretty simple.
//Force unlazying of rrdata and count a rerecord. //Force unlazying of rrdata and count a rerecord.
if(lsnes_instance.mlogic.get_rrdata().is_lazy()) if(CORE().mlogic.get_rrdata().is_lazy())
lsnes_instance.mlogic.get_rrdata().read_base(rrdata::filename( CORE().mlogic.get_rrdata().read_base(rrdata::filename(
lsnes_instance.mlogic.get_mfile().projectid), false); CORE().mlogic.get_mfile().projectid), false);
lsnes_instance.mlogic.get_rrdata().add(lsnes_instance.nrrdata()); CORE().mlogic.get_rrdata().add(CORE().nrrdata());
port_type_set& portset = construct_movie_portset(lsnes_instance.mlogic.get_mfile(), our_rom); port_type_set& portset = construct_movie_portset(CORE().mlogic.get_mfile(), our_rom);
try { try {
handle_load_core(lsnes_instance.mlogic.get_mfile(), portset, false); handle_load_core(CORE().mlogic.get_mfile(), portset, false);
lsnes_instance.mlogic.get_mfile().gametype = &our_rom.rtype->combine_region(*our_rom.region); CORE().mlogic.get_mfile().gametype = &our_rom.rtype->combine_region(*our_rom.region);
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
lsnes_instance.mlogic.get_mfile().namehint[i] = our_rom.romimg[i].namehint; CORE().mlogic.get_mfile().namehint[i] = our_rom.romimg[i].namehint;
lsnes_instance.mlogic.get_mfile().romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); CORE().mlogic.get_mfile().romimg_sha256[i] = our_rom.romimg[i].sha_256.read();
lsnes_instance.mlogic.get_mfile().romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); CORE().mlogic.get_mfile().romxml_sha256[i] = our_rom.romxml[i].sha_256.read();
} }
lsnes_instance.mlogic.get_mfile().is_savestate = false; CORE().mlogic.get_mfile().is_savestate = false;
lsnes_instance.mlogic.get_mfile().host_memory.clear(); CORE().mlogic.get_mfile().host_memory.clear();
lsnes_instance.mlogic.get_movie().reset_state(); CORE().mlogic.get_movie().reset_state();
redraw_framebuffer(our_rom.rtype->draw_cover()); redraw_framebuffer(our_rom.rtype->draw_cover());
lua_callback_do_rewind(); lua_callback_do_rewind();
} catch(std::bad_alloc& e) { } catch(std::bad_alloc& e) {
@ -500,7 +500,7 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error)
//Force new lazy rrdata and count a rerecord. //Force new lazy rrdata and count a rerecord.
temporary_handle<rrdata_set> rrd; temporary_handle<rrdata_set> rrd;
rrd.get()->read_base(rrdata::filename(_movie.get()->projectid), true); rrd.get()->read_base(rrdata::filename(_movie.get()->projectid), true);
rrd.get()->add(lsnes_instance.nrrdata()); rrd.get()->add(CORE().nrrdata());
//Movie data is lost. //Movie data is lost.
lua_callback_movie_lost("reload"); lua_callback_movie_lost("reload");
try { try {
@ -517,37 +517,37 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error)
} }
//Set up stuff. //Set up stuff.
lsnes_instance.mlogic.set_movie(*(newmovie()), true); CORE().mlogic.set_movie(*(newmovie()), true);
lsnes_instance.mlogic.set_mfile(*(_movie()), true); CORE().mlogic.set_mfile(*(_movie()), true);
lsnes_instance.mlogic.set_rrdata(*(rrd()), true); CORE().mlogic.set_rrdata(*(rrd()), true);
set_mprefix(get_mprefix_for_project(lsnes_instance.mlogic.get_mfile().projectid)); set_mprefix(get_mprefix_for_project(CORE().mlogic.get_mfile().projectid));
} }
notify_mode_change(lsnes_instance.mlogic.get_movie().readonly_mode()); notify_mode_change(CORE().mlogic.get_movie().readonly_mode());
notify_mbranch_change(); notify_mbranch_change();
messages << "ROM reloaded." << std::endl; messages << "ROM reloaded." << std::endl;
} }
void do_load_rewind() throw(std::bad_alloc, std::runtime_error) void do_load_rewind() throw(std::bad_alloc, std::runtime_error)
{ {
if(!lsnes_instance.mlogic || !lsnes_instance.mlogic.get_mfile().gametype) if(!CORE().mlogic || !CORE().mlogic.get_mfile().gametype)
throw std::runtime_error("Can't rewind movie without existing movie"); throw std::runtime_error("Can't rewind movie without existing movie");
port_type_set& portset = construct_movie_portset(lsnes_instance.mlogic.get_mfile(), our_rom); port_type_set& portset = construct_movie_portset(CORE().mlogic.get_mfile(), our_rom);
//Force unlazying of rrdata and count a rerecord. //Force unlazying of rrdata and count a rerecord.
if(lsnes_instance.mlogic.get_rrdata().is_lazy()) if(CORE().mlogic.get_rrdata().is_lazy())
lsnes_instance.mlogic.get_rrdata().read_base(rrdata::filename( CORE().mlogic.get_rrdata().read_base(rrdata::filename(
lsnes_instance.mlogic.get_mfile().projectid), false); CORE().mlogic.get_mfile().projectid), false);
lsnes_instance.mlogic.get_rrdata().add(lsnes_instance.nrrdata()); CORE().mlogic.get_rrdata().add(CORE().nrrdata());
//Enter readonly mode. //Enter readonly mode.
lsnes_instance.mlogic.get_movie().readonly_mode(true); CORE().mlogic.get_movie().readonly_mode(true);
notify_mode_change(true); notify_mode_change(true);
try { try {
handle_load_core(lsnes_instance.mlogic.get_mfile(), portset, false); handle_load_core(CORE().mlogic.get_mfile(), portset, false);
lsnes_instance.mlogic.get_mfile().is_savestate = false; CORE().mlogic.get_mfile().is_savestate = false;
lsnes_instance.mlogic.get_mfile().host_memory.clear(); CORE().mlogic.get_mfile().host_memory.clear();
lsnes_instance.mlogic.get_movie().reset_state(); CORE().mlogic.get_movie().reset_state();
redraw_framebuffer(our_rom.rtype->draw_cover()); redraw_framebuffer(our_rom.rtype->draw_cover());
lua_callback_do_rewind(); lua_callback_do_rewind();
} catch(std::bad_alloc& e) { } catch(std::bad_alloc& e) {
@ -563,17 +563,17 @@ void do_load_rewind() throw(std::bad_alloc, std::runtime_error)
//Load state preserving input. Does not do checks. //Load state preserving input. Does not do checks.
void do_load_state_preserve(struct moviefile& _movie) void do_load_state_preserve(struct moviefile& _movie)
{ {
if(!lsnes_instance.mlogic || !lsnes_instance.mlogic.get_mfile().gametype) if(!CORE().mlogic || !CORE().mlogic.get_mfile().gametype)
throw std::runtime_error("Can't load movie preserving input without previous movie"); throw std::runtime_error("Can't load movie preserving input without previous movie");
if(lsnes_instance.mlogic.get_mfile().projectid != _movie.projectid) if(CORE().mlogic.get_mfile().projectid != _movie.projectid)
throw std::runtime_error("Savestate is from different movie"); throw std::runtime_error("Savestate is from different movie");
bool will_load_state = _movie.is_savestate; bool will_load_state = _movie.is_savestate;
port_type_set& portset = construct_movie_portset(lsnes_instance.mlogic.get_mfile(), our_rom); port_type_set& portset = construct_movie_portset(CORE().mlogic.get_mfile(), our_rom);
//Construct a new movie sharing the input data. //Construct a new movie sharing the input data.
temporary_handle<movie> newmovie; temporary_handle<movie> newmovie;
newmovie.get()->set_movie_data(lsnes_instance.mlogic.get_mfile().input); newmovie.get()->set_movie_data(CORE().mlogic.get_mfile().input);
newmovie.get()->readonly_mode(true); newmovie.get()->readonly_mode(true);
newmovie.get()->set_pflag_handler(&lsnes_pflag_handler); newmovie.get()->set_pflag_handler(&lsnes_pflag_handler);
@ -583,9 +583,9 @@ void do_load_state_preserve(struct moviefile& _movie)
_movie.input, _movie.projectid); _movie.input, _movie.projectid);
//Count a rerecord. //Count a rerecord.
if(lsnes_instance.mlogic.get_rrdata().is_lazy() && !_movie.lazy_project_create) if(CORE().mlogic.get_rrdata().is_lazy() && !_movie.lazy_project_create)
lsnes_instance.mlogic.get_rrdata().read_base(rrdata::filename(_movie.projectid), false); CORE().mlogic.get_rrdata().read_base(rrdata::filename(_movie.projectid), false);
lsnes_instance.mlogic.get_rrdata().add(lsnes_instance.nrrdata()); CORE().mlogic.get_rrdata().add(CORE().nrrdata());
//Negative return. //Negative return.
try { try {
@ -599,15 +599,15 @@ void do_load_state_preserve(struct moviefile& _movie)
} }
//Set new movie. //Set new movie.
lsnes_instance.mlogic.set_movie(*(newmovie()), true); CORE().mlogic.set_movie(*(newmovie()), true);
//Some fields MUST be taken from movie or one gets desyncs. //Some fields MUST be taken from movie or one gets desyncs.
lsnes_instance.mlogic.get_mfile().is_savestate = _movie.is_savestate; CORE().mlogic.get_mfile().is_savestate = _movie.is_savestate;
lsnes_instance.mlogic.get_mfile().rtc_second = _movie.rtc_second; CORE().mlogic.get_mfile().rtc_second = _movie.rtc_second;
lsnes_instance.mlogic.get_mfile().rtc_subsecond = _movie.rtc_subsecond; CORE().mlogic.get_mfile().rtc_subsecond = _movie.rtc_subsecond;
std::swap(lsnes_instance.mlogic.get_mfile().host_memory, _movie.host_memory); std::swap(CORE().mlogic.get_mfile().host_memory, _movie.host_memory);
if(!will_load_state) if(!will_load_state)
lsnes_instance.mlogic.get_mfile().host_memory.clear(); CORE().mlogic.get_mfile().host_memory.clear();
try { try {
//Paint the screen. //Paint the screen.
@ -620,7 +620,7 @@ void do_load_state_preserve(struct moviefile& _movie)
} catch(...) { } catch(...) {
} }
delete &_movie; delete &_movie;
notify_mode_change(lsnes_instance.mlogic.get_movie().readonly_mode()); notify_mode_change(CORE().mlogic.get_movie().readonly_mode());
messages << "Loadstated at earlier point of movie." << std::endl; messages << "Loadstated at earlier point of movie." << std::endl;
} }
@ -628,7 +628,7 @@ void do_load_state_preserve(struct moviefile& _movie)
void do_load_state(struct moviefile& _movie, int lmode, bool& used) void do_load_state(struct moviefile& _movie, int lmode, bool& used)
{ {
//Some basic sanity checks. //Some basic sanity checks.
bool current_mode = lsnes_instance.mlogic ? lsnes_instance.mlogic.get_movie().readonly_mode() : false; bool current_mode = CORE().mlogic ? CORE().mlogic.get_movie().readonly_mode() : false;
bool will_load_state = _movie.is_savestate && lmode != LOAD_STATE_MOVIE; bool will_load_state = _movie.is_savestate && lmode != LOAD_STATE_MOVIE;
//Load state all branches and load state initial are the same. //Load state all branches and load state initial are the same.
@ -648,7 +648,7 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used)
if(lmode == LOAD_STATE_CURRENT && current_mode && readonly_load_preserves(CORE().settings)) if(lmode == LOAD_STATE_CURRENT && current_mode && readonly_load_preserves(CORE().settings))
lmode = LOAD_STATE_PRESERVE; lmode = LOAD_STATE_PRESERVE;
//If movie file changes, turn LOAD_STATE_CURRENT into LOAD_STATE_RO //If movie file changes, turn LOAD_STATE_CURRENT into LOAD_STATE_RO
if(lmode == LOAD_STATE_CURRENT && lsnes_instance.mlogic.get_mfile().projectid != _movie.projectid) if(lmode == LOAD_STATE_CURRENT && CORE().mlogic.get_mfile().projectid != _movie.projectid)
lmode = LOAD_STATE_RO; lmode = LOAD_STATE_RO;
//Handle preserving load specially. //Handle preserving load specially.
@ -668,11 +668,11 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used)
NULL, _movie.projectid); NULL, _movie.projectid);
//Copy the other branches. //Copy the other branches.
if(lmode != LOAD_STATE_INITIAL && lsnes_instance.mlogic.get_mfile().projectid == _movie.projectid) { if(lmode != LOAD_STATE_INITIAL && CORE().mlogic.get_mfile().projectid == _movie.projectid) {
newmovie.get()->set_movie_data(NULL); newmovie.get()->set_movie_data(NULL);
auto& oldm = lsnes_instance.mlogic.get_mfile().branches; auto& oldm = CORE().mlogic.get_mfile().branches;
auto& newm = _movie.branches; auto& newm = _movie.branches;
auto oldd = lsnes_instance.mlogic.get_mfile().input; auto oldd = CORE().mlogic.get_mfile().input;
auto newd = _movie.input; auto newd = _movie.input;
std::string dflt_name; std::string dflt_name;
//What was the old default name? //What was the old default name?
@ -702,16 +702,16 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used)
temporary_handle<rrdata_set> rrd; temporary_handle<rrdata_set> rrd;
bool new_rrdata = false; bool new_rrdata = false;
//Count a rerecord (against new or old movie). //Count a rerecord (against new or old movie).
if(!lsnes_instance.mlogic || _movie.projectid != lsnes_instance.mlogic.get_mfile().projectid) { if(!CORE().mlogic || _movie.projectid != CORE().mlogic.get_mfile().projectid) {
rrd.get()->read_base(rrdata::filename(_movie.projectid), _movie.lazy_project_create); rrd.get()->read_base(rrdata::filename(_movie.projectid), _movie.lazy_project_create);
rrd.get()->read(_movie.c_rrdata); rrd.get()->read(_movie.c_rrdata);
rrd.get()->add(lsnes_instance.nrrdata()); rrd.get()->add(CORE().nrrdata());
new_rrdata = true; new_rrdata = true;
} else { } else {
//Unlazy rrdata if needed. //Unlazy rrdata if needed.
if(lsnes_instance.mlogic.get_rrdata().is_lazy() && !_movie.lazy_project_create) if(CORE().mlogic.get_rrdata().is_lazy() && !_movie.lazy_project_create)
lsnes_instance.mlogic.get_rrdata().read_base(rrdata::filename(_movie.projectid), false); CORE().mlogic.get_rrdata().read_base(rrdata::filename(_movie.projectid), false);
lsnes_instance.mlogic.get_rrdata().add(lsnes_instance.nrrdata()); CORE().mlogic.get_rrdata().add(CORE().nrrdata());
} }
//Negative return. //Negative return.
try { try {
@ -734,15 +734,15 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used)
lua_callback_movie_lost("load"); lua_callback_movie_lost("load");
//Copy the data. //Copy the data.
if(new_rrdata) lsnes_instance.mlogic.set_rrdata(*(rrd()), true); if(new_rrdata) CORE().mlogic.set_rrdata(*(rrd()), true);
lsnes_instance.mlogic.set_movie(*newmovie(), true); CORE().mlogic.set_movie(*newmovie(), true);
lsnes_instance.mlogic.set_mfile(_movie, true); CORE().mlogic.set_mfile(_movie, true);
used = true; used = true;
set_mprefix(get_mprefix_for_project(lsnes_instance.mlogic.get_mfile().projectid)); set_mprefix(get_mprefix_for_project(CORE().mlogic.get_mfile().projectid));
//Activate RW mode if needed. //Activate RW mode if needed.
auto& m = lsnes_instance.mlogic.get_movie(); auto& m = CORE().mlogic.get_movie();
if(lmode == LOAD_STATE_RW) if(lmode == LOAD_STATE_RW)
m.readonly_mode(false); m.readonly_mode(false);
if(lmode == LOAD_STATE_DEFAULT && !current_mode && m.get_frame_count() <= m.get_current_frame()) if(lmode == LOAD_STATE_DEFAULT && !current_mode && m.get_frame_count() <= m.get_current_frame())
@ -763,7 +763,7 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used)
} }
notify_mode_change(m.readonly_mode()); notify_mode_change(m.readonly_mode());
print_movie_info(_movie, our_rom, lsnes_instance.mlogic.get_rrdata()); print_movie_info(_movie, our_rom, CORE().mlogic.get_rrdata());
notify_mbranch_change(); notify_mbranch_change();
} }
@ -835,7 +835,7 @@ bool do_load_state(const std::string& filename, int lmode)
do_load_state(*mfile, lmode, used); do_load_state(*mfile, lmode, used);
uint64_t took = get_utime() - origtime; uint64_t took = get_utime() - origtime;
messages << "Loaded '" << filename2 << "' in " << took << " microseconds." << std::endl; messages << "Loaded '" << filename2 << "' in " << took << " microseconds." << std::endl;
lua_callback_post_load(filename2, lsnes_instance.mlogic.get_mfile().is_savestate); lua_callback_post_load(filename2, CORE().mlogic.get_mfile().is_savestate);
} catch(std::bad_alloc& e) { } catch(std::bad_alloc& e) {
OOM_panic(); OOM_panic();
} catch(std::exception& e) { } catch(std::exception& e) {
@ -852,11 +852,11 @@ bool do_load_state(const std::string& filename, int lmode)
void mainloop_restore_state(const std::vector<char>& state, uint64_t secs, uint64_t ssecs) void mainloop_restore_state(const std::vector<char>& state, uint64_t secs, uint64_t ssecs)
{ {
//Force unlazy rrdata. //Force unlazy rrdata.
lsnes_instance.mlogic.get_rrdata().read_base(rrdata::filename(lsnes_instance.mlogic.get_mfile().projectid), CORE().mlogic.get_rrdata().read_base(rrdata::filename(CORE().mlogic.get_mfile().projectid),
false); false);
lsnes_instance.mlogic.get_rrdata().add(lsnes_instance.nrrdata()); CORE().mlogic.get_rrdata().add(CORE().nrrdata());
lsnes_instance.mlogic.get_mfile().rtc_second = secs; CORE().mlogic.get_mfile().rtc_second = secs;
lsnes_instance.mlogic.get_mfile().rtc_subsecond = ssecs; CORE().mlogic.get_mfile().rtc_subsecond = ssecs;
our_rom.load_core_state(state, true); our_rom.load_core_state(state, true);
} }

View file

@ -325,7 +325,7 @@ bool project_state::set(project_info* p, bool current)
{ {
if(!p) { if(!p) {
if(active_project) if(active_project)
lsnes_instance.commentary.unload_collection(); CORE().commentary.unload_collection();
active_project = p; active_project = p;
notify_core_change(); notify_core_change();
notify_branch_change(); notify_branch_change();
@ -381,19 +381,19 @@ skip_rom_movie:
active_project = p; active_project = p;
switched = true; switched = true;
//Calculate union of old and new. //Calculate union of old and new.
std::set<std::string> _watches = lsnes_instance.mwatch.enumerate(); std::set<std::string> _watches = CORE().mwatch.enumerate();
for(auto i : p->watches) _watches.insert(i.first); for(auto i : p->watches) _watches.insert(i.first);
for(auto i : _watches) for(auto i : _watches)
try { try {
if(p->watches.count(i)) if(p->watches.count(i))
lsnes_instance.mwatch.set(i, p->watches[i]); CORE().mwatch.set(i, p->watches[i]);
else else
lsnes_instance.mwatch.clear(i); CORE().mwatch.clear(i);
} catch(std::exception& e) { } catch(std::exception& e) {
messages << "Can't set/clear watch '" << i << "': " << e.what() << std::endl; messages << "Can't set/clear watch '" << i << "': " << e.what() << std::endl;
} }
lsnes_instance.commentary.load_collection(p->directory + "/" + p->prefix + ".lsvs"); CORE().commentary.load_collection(p->directory + "/" + p->prefix + ".lsvs");
CORE().command.invoke("reset-lua"); CORE().command.invoke("reset-lua");
for(auto i : p->luascripts) for(auto i : p->luascripts)
CORE().command.invoke("run-lua " + i); CORE().command.invoke("run-lua " + i);
@ -443,7 +443,7 @@ std::string project_state::moviepath()
if(active_project) if(active_project)
return active_project->directory; return active_project->directory;
else else
return lsnes_instance.setcache.get("moviepath"); return CORE().setcache.get("moviepath");
} }
std::string project_state::otherpath() std::string project_state::otherpath()
@ -461,9 +461,9 @@ std::string project_state::savestate_ext()
void project_state::copy_watches(project_info& p) void project_state::copy_watches(project_info& p)
{ {
for(auto i : lsnes_instance.mwatch.enumerate()) { for(auto i : CORE().mwatch.enumerate()) {
try { try {
p.watches[i] = lsnes_instance.mwatch.get_string(i); p.watches[i] = CORE().mwatch.get_string(i);
} catch(std::exception& e) { } catch(std::exception& e) {
messages << "Can't read memory watch '" << i << "': " << e.what() << std::endl; messages << "Can't read memory watch '" << i << "': " << e.what() << std::endl;
} }

View file

@ -264,7 +264,7 @@ loaded_rom::loaded_rom(const std::string& file, core_type& ctype) throw(std::bad
if((bios = ctype.get_biosname()) != "") { if((bios = ctype.get_biosname()) != "") {
//This thing has a BIOS. //This thing has a BIOS.
romidx = 1; romidx = 1;
std::string basename = lsnes_instance.setcache.get("firmwarepath") + "/" + bios; std::string basename = CORE().setcache.get("firmwarepath") + "/" + bios;
romimg[0] = fileimage::image(lsnes_image_hasher, basename, "", xlate_info(ctype.get_image_info(0))); romimg[0] = fileimage::image(lsnes_image_hasher, basename, "", xlate_info(ctype.get_image_info(0)));
if(zip::file_exists(basename + ".xml")) if(zip::file_exists(basename + ".xml"))
romxml[0] = fileimage::image(lsnes_image_hasher, basename + ".xml", "", get_xml_info()); romxml[0] = fileimage::image(lsnes_image_hasher, basename + ".xml", "", get_xml_info());
@ -305,7 +305,7 @@ loaded_rom::loaded_rom(const std::string& file, const std::string& tmpprefer) th
if((bios = coretype->get_biosname()) != "") { if((bios = coretype->get_biosname()) != "") {
//This thing has a BIOS. //This thing has a BIOS.
romidx = 1; romidx = 1;
std::string basename = lsnes_instance.setcache.get("firmwarepath") + "/" + bios; std::string basename = CORE().setcache.get("firmwarepath") + "/" + bios;
romimg[0] = fileimage::image(lsnes_image_hasher, basename, "", romimg[0] = fileimage::image(lsnes_image_hasher, basename, "",
xlate_info(coretype->get_image_info(0))); xlate_info(coretype->get_image_info(0)));
if(zip::file_exists(basename + ".xml")) if(zip::file_exists(basename + ".xml"))
@ -506,7 +506,7 @@ loaded_rom::loaded_rom(const std::string& file, const std::string& core, const s
std::string bios = t->get_biosname(); std::string bios = t->get_biosname();
unsigned romidx = (bios != "") ? 1 : 0; unsigned romidx = (bios != "") ? 1 : 0;
if(bios != "") { if(bios != "") {
std::string basename = lsnes_instance.setcache.get("firmwarepath") + "/" + bios; std::string basename = CORE().setcache.get("firmwarepath") + "/" + bios;
romimg[0] = fileimage::image(lsnes_image_hasher, basename, "", xlate_info(t->get_image_info(0))); romimg[0] = fileimage::image(lsnes_image_hasher, basename, "", xlate_info(t->get_image_info(0)));
if(zip::file_exists(basename + ".xml")) if(zip::file_exists(basename + ".xml"))
romxml[0] = fileimage::image(lsnes_image_hasher, basename + ".xml", "", get_xml_info()); romxml[0] = fileimage::image(lsnes_image_hasher, basename + ".xml", "", get_xml_info());
@ -606,7 +606,7 @@ void loaded_rom::load(std::map<std::string, std::string>& settings, uint64_t rtc
old_core->debug_reset(); old_core->debug_reset();
old_core->unload_cartridge(); old_core->unload_cartridge();
} catch(...) {} } catch(...) {}
lsnes_instance.cmapper(); CORE().cmapper();
notify_core_changed(old_type != current_rom_type); notify_core_changed(old_type != current_rom_type);
} }

View file

@ -150,8 +150,8 @@ namespace
const std::set<std::string>& extensions, uint64_t headersize, bool bios) const std::set<std::string>& extensions, uint64_t headersize, bool bios)
{ {
std::string x; std::string x;
std::string romdir = lsnes_instance.setcache.get("rompath"); std::string romdir = CORE().setcache.get("rompath");
std::string biosdir = lsnes_instance.setcache.get("firmwarepath"); std::string biosdir = CORE().setcache.get("firmwarepath");
if((x = try_scan_hint_dir(hint, hash, xhash, romdir, extensions, headersize)) != "") return x; if((x = try_scan_hint_dir(hint, hash, xhash, romdir, extensions, headersize)) != "") return x;
if(bios && (x = try_scan_hint_dir(hint, hash, xhash, biosdir, extensions, headersize)) != "") if(bios && (x = try_scan_hint_dir(hint, hash, xhash, biosdir, extensions, headersize)) != "")
return x; return x;

View file

@ -17,11 +17,11 @@ bool load_null_rom()
} }
loaded_rom newrom; loaded_rom newrom;
our_rom = newrom; our_rom = newrom;
if(lsnes_instance.mlogic) if(CORE().mlogic)
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
lsnes_instance.mlogic.get_mfile().romimg_sha256[i] = ""; CORE().mlogic.get_mfile().romimg_sha256[i] = "";
lsnes_instance.mlogic.get_mfile().romxml_sha256[i] = ""; CORE().mlogic.get_mfile().romxml_sha256[i] = "";
lsnes_instance.mlogic.get_mfile().namehint[i] = ""; CORE().mlogic.get_mfile().namehint[i] = "";
} }
notify_core_change(); notify_core_change();
return true; return true;
@ -96,11 +96,11 @@ bool _load_new_rom(const romload_request& req)
} }
try { try {
load_new_rom_inner(req); load_new_rom_inner(req);
if(lsnes_instance.mlogic) if(CORE().mlogic)
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
lsnes_instance.mlogic.get_mfile().romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); CORE().mlogic.get_mfile().romimg_sha256[i] = our_rom.romimg[i].sha_256.read();
lsnes_instance.mlogic.get_mfile().romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); CORE().mlogic.get_mfile().romxml_sha256[i] = our_rom.romxml[i].sha_256.read();
lsnes_instance.mlogic.get_mfile().namehint[i] = our_rom.romimg[i].namehint; CORE().mlogic.get_mfile().namehint[i] = our_rom.romimg[i].namehint;
} }
} catch(std::exception& e) { } catch(std::exception& e) {
platform::error_message(std::string("Can't load ROM: ") + e.what()); platform::error_message(std::string("Can't load ROM: ") + e.what());
@ -201,7 +201,7 @@ loaded_rom construct_rom_multifile(core_type* ctype, const moviefile::brief_info
//Try to use hint. //Try to use hint.
std::set<std::string> exts = img.extensions; std::set<std::string> exts = img.extensions;
for(auto j : exts) { for(auto j : exts) {
std::string candidate = lsnes_instance.setcache.get(psetting) + "/" + info.hint[i] + std::string candidate = CORE().setcache.get(psetting) + "/" + info.hint[i] +
"." + j; "." + j;
if(zip::file_exists(candidate)) { if(zip::file_exists(candidate)) {
roms[i] = candidate; roms[i] = candidate;
@ -211,7 +211,7 @@ loaded_rom construct_rom_multifile(core_type* ctype, const moviefile::brief_info
} }
if(isbios && roms[i] == "" && i == 0) { if(isbios && roms[i] == "" && i == 0) {
//Fallback default. //Fallback default.
roms[0] = lsnes_instance.setcache.get("firmwarepath") + "/" + bios; roms[0] = CORE().setcache.get("firmwarepath") + "/" + bios;
} }
if(roms[i] == "" && info.hash[i] != "") if(roms[i] == "" && info.hash[i] != "")
roms[i] = try_to_guess_rom(info.hint[i], info.hash[i], info.hashxml[i], *ctype, i); roms[i] = try_to_guess_rom(info.hint[i], info.hash[i], info.hashxml[i], *ctype, i);

View file

@ -242,7 +242,7 @@ namespace
{ {
on_idle_time = lua_timed_hook(LUA_TIMED_HOOK_IDLE); on_idle_time = lua_timed_hook(LUA_TIMED_HOOK_IDLE);
on_timer_time = lua_timed_hook(LUA_TIMED_HOOK_TIMER); on_timer_time = lua_timed_hook(LUA_TIMED_HOOK_TIMER);
lsnes_instance.queue_function_run = false; CORE().queue_function_run = false;
} }
} }
@ -251,9 +251,9 @@ namespace
void platform::dummy_event_loop() throw() void platform::dummy_event_loop() throw()
{ {
while(!do_exit_dummy_event_loop) { while(!do_exit_dummy_event_loop) {
threads::alock h(lsnes_instance.queue_lock); threads::alock h(CORE().queue_lock);
lsnes_instance.run_queue(true); CORE().run_queue(true);
threads::cv_timed_wait(lsnes_instance.queue_condition, h, threads::ustime(MAXWAIT)); threads::cv_timed_wait(CORE().queue_condition, h, threads::ustime(MAXWAIT));
random_mix_timing_entropy(); random_mix_timing_entropy();
} }
} }
@ -261,15 +261,15 @@ void platform::dummy_event_loop() throw()
void platform::exit_dummy_event_loop() throw() void platform::exit_dummy_event_loop() throw()
{ {
do_exit_dummy_event_loop = true; do_exit_dummy_event_loop = true;
threads::alock h(lsnes_instance.queue_lock); threads::alock h(CORE().queue_lock);
lsnes_instance.queue_condition.notify_all(); CORE().queue_condition.notify_all();
usleep(200000); usleep(200000);
} }
void platform::flush_command_queue() throw() void platform::flush_command_queue() throw()
{ {
reload_lua_timers(); reload_lua_timers();
lsnes_instance.queue_function_run = false; CORE().queue_function_run = false;
if(modal_pause || normal_pause) if(modal_pause || normal_pause)
freeze_time(get_utime()); freeze_time(get_utime());
bool run_idle = false; bool run_idle = false;
@ -284,11 +284,11 @@ void platform::flush_command_queue() throw()
reload_lua_timers(); reload_lua_timers();
run_idle = false; run_idle = false;
} }
threads::alock h(lsnes_instance.queue_lock); threads::alock h(CORE().queue_lock);
lsnes_instance.run_queue(true); CORE().run_queue(true);
if(!pausing_allowed) if(!pausing_allowed)
break; break;
if(lsnes_instance.queue_function_run) if(CORE().queue_function_run)
reload_lua_timers(); reload_lua_timers();
now = get_utime(); now = get_utime();
uint64_t waitleft = 0; uint64_t waitleft = 0;
@ -305,7 +305,7 @@ void platform::flush_command_queue() throw()
if(on_timer_time >= now) if(on_timer_time >= now)
waitleft = min(waitleft, on_timer_time - now); waitleft = min(waitleft, on_timer_time - now);
if(waitleft > 0) { if(waitleft > 0) {
threads::cv_timed_wait(lsnes_instance.queue_condition, h, threads::ustime(waitleft)); threads::cv_timed_wait(CORE().queue_condition, h, threads::ustime(waitleft));
random_mix_timing_entropy(); random_mix_timing_entropy();
} }
} else } else
@ -337,9 +337,9 @@ void platform::wait(uint64_t usec) throw()
run_idle = false; run_idle = false;
reload_lua_timers(); reload_lua_timers();
} }
threads::alock h(lsnes_instance.queue_lock); threads::alock h(CORE().queue_lock);
lsnes_instance.run_queue(true); CORE().run_queue(true);
if(lsnes_instance.queue_function_run) if(CORE().queue_function_run)
reload_lua_timers(); reload_lua_timers();
//If usec is 0, never wait (waitleft can be nonzero if time counting screws up). //If usec is 0, never wait (waitleft can be nonzero if time counting screws up).
if(!usec) if(!usec)
@ -358,7 +358,7 @@ void platform::wait(uint64_t usec) throw()
if(on_timer_time >= now) if(on_timer_time >= now)
waitleft = min(waitleft, on_timer_time - now); waitleft = min(waitleft, on_timer_time - now);
if(waitleft > 0) { if(waitleft > 0) {
threads::cv_timed_wait(lsnes_instance.queue_condition, h, threads::ustime(waitleft)); threads::cv_timed_wait(CORE().queue_condition, h, threads::ustime(waitleft));
random_mix_timing_entropy(); random_mix_timing_entropy();
} }
} else } else
@ -369,8 +369,8 @@ void platform::wait(uint64_t usec) throw()
void platform::cancel_wait() throw() void platform::cancel_wait() throw()
{ {
continue_time = 0; continue_time = 0;
threads::alock h(lsnes_instance.queue_lock); threads::alock h(CORE().queue_lock);
lsnes_instance.queue_condition.notify_all(); CORE().queue_condition.notify_all();
} }
void platform::set_modal_pause(bool enable) throw() void platform::set_modal_pause(bool enable) throw()
@ -380,7 +380,7 @@ void platform::set_modal_pause(bool enable) throw()
void platform::run_queues() throw() void platform::run_queues() throw()
{ {
lsnes_instance.run_queue(false); CORE().run_queue(false);
} }
namespace namespace