From 301198e98fca6e4b03a620d7cbc3f64f93fad0be Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Jun 2014 04:15:01 +0300 Subject: [PATCH] Instancefy currently loaded ROM --- include/core/debug.hpp | 4 +- include/core/filedownload.hpp | 6 +- include/core/framebuffer.hpp | 4 +- include/core/instance.hpp | 2 + include/core/memorymanip.hpp | 4 +- include/core/moviedata.hpp | 1 - include/core/project.hpp | 3 +- src/core/actions.cpp | 9 ++- src/core/debug.cpp | 20 +++--- src/core/filedownload.cpp | 14 ++-- src/core/framebuffer.cpp | 6 +- src/core/instance.cpp | 9 +-- src/core/mainloop.cpp | 26 ++++---- src/core/memorymanip.cpp | 8 +-- src/core/moviedata.cpp | 98 ++++++++++++++-------------- src/core/project.cpp | 6 +- src/core/romloader.cpp | 32 ++++----- src/interface/cover.cpp | 4 +- src/lua/actions.cpp | 8 ++- src/lua/core.cpp | 11 ++-- src/lua/disassemble.cpp | 9 ++- src/lua/memory.cpp | 3 +- src/lua/movie.cpp | 3 +- src/platform/wxwidgets/editor-movie.cpp | 2 +- src/platform/wxwidgets/editor-tasinput.cpp | 2 +- src/platform/wxwidgets/main.cpp | 2 +- src/platform/wxwidgets/mainwindow.cpp | 31 +++++---- src/platform/wxwidgets/mouse.cpp | 2 +- src/platform/wxwidgets/romselect.cpp | 24 +++---- src/platform/wxwidgets/tracelogmenu.cpp | 2 +- src/platform/wxwidgets/window-fileupload.cpp | 2 +- src/util/lsnes-dumpavi.cpp | 10 +-- src/video/avi.cpp | 2 +- src/video/raw.cpp | 4 +- 34 files changed, 205 insertions(+), 168 deletions(-) diff --git a/include/core/debug.hpp b/include/core/debug.hpp index 0e81873e..513f8750 100644 --- a/include/core/debug.hpp +++ b/include/core/debug.hpp @@ -7,6 +7,7 @@ #include "library/dispatch.hpp" class emulator_dispatch; +class loaded_rom; /** * Debugging context. @@ -14,7 +15,7 @@ class emulator_dispatch; class debug_context { public: - debug_context(emulator_dispatch& _dispatch); + debug_context(emulator_dispatch& _dispatch, loaded_rom& _rom); /** * Type of event. */ @@ -157,6 +158,7 @@ private: uint64_t xmask = 1; std::function tracelog_change_cb; emulator_dispatch& edispatch; + loaded_rom& rom; struct dispatch::target<> corechange; bool corechange_r = false; bool requesting_break = false; diff --git a/include/core/filedownload.hpp b/include/core/filedownload.hpp index 78f35f31..eb7fe99d 100644 --- a/include/core/filedownload.hpp +++ b/include/core/filedownload.hpp @@ -8,6 +8,8 @@ #include #include +class loaded_rom; + struct file_download { //Variables. @@ -17,7 +19,7 @@ struct file_download file_download(); ~file_download(); //Lauch. - void do_async(); + void do_async(loaded_rom& rom); void cancel(); //Status. volatile bool finished; //This signals download finishing, call finish(). @@ -27,7 +29,7 @@ struct file_download threads::cv cond; threads::lock m; //Internal. - void _do_async(); + void _do_async(loaded_rom& rom); std::string tempname; std::string tempname2; }; diff --git a/include/core/framebuffer.hpp b/include/core/framebuffer.hpp index 0f8b4c9d..6080aacf 100644 --- a/include/core/framebuffer.hpp +++ b/include/core/framebuffer.hpp @@ -11,6 +11,7 @@ class subtitle_commentary; class memwatch_set; class emulator_dispatch; class lua_state; +class loaded_rom; namespace settingvar { class group; @@ -27,7 +28,7 @@ class emu_framebuffer { public: emu_framebuffer(subtitle_commentary& _subtitles, settingvar::group& _settings, memwatch_set& _mwatch, - keyboard::keyboard& _keyboard, emulator_dispatch& _dispatch, lua_state& _lua2); + keyboard::keyboard& _keyboard, emulator_dispatch& _dispatch, lua_state& _lua2, loaded_rom& _rom); /** * The main framebuffer. */ @@ -102,6 +103,7 @@ private: keyboard::keyboard& keyboard; emulator_dispatch& edispatch; lua_state& lua2; + loaded_rom& rom; }; #endif diff --git a/include/core/instance.hpp b/include/core/instance.hpp index 93b9d2aa..24c409e4 100644 --- a/include/core/instance.hpp +++ b/include/core/instance.hpp @@ -26,6 +26,7 @@ class emulator_dispatch; class slotinfo_cache; class lua_state; class audioapi_instance; +class loaded_rom; namespace command { class group; } namespace lua { class state; } namespace settingvar { class group; } @@ -119,6 +120,7 @@ struct emulator_instance master_dumper* mdumper; slotinfo_cache* slotcache; audioapi_instance* audio; + loaded_rom* rom; threads::id emu_thread; time_t random_seed_value; dtor_list D; diff --git a/include/core/memorymanip.hpp b/include/core/memorymanip.hpp index 87c31cae..73ce51e9 100644 --- a/include/core/memorymanip.hpp +++ b/include/core/memorymanip.hpp @@ -9,15 +9,17 @@ class memory_space; class movie_logic; +class loaded_rom; class cart_mappings_refresher { public: - cart_mappings_refresher(memory_space& _mspace, movie_logic& _mlogic); + cart_mappings_refresher(memory_space& _mspace, movie_logic& _mlogic, loaded_rom& _rom); void operator()() throw(std::bad_alloc); private: memory_space& mspace; movie_logic& mlogic; + loaded_rom& rom; }; #endif diff --git a/include/core/moviedata.hpp b/include/core/moviedata.hpp index f576769c..2639aaf6 100644 --- a/include/core/moviedata.hpp +++ b/include/core/moviedata.hpp @@ -29,7 +29,6 @@ #define SAVE_STATE 0 #define SAVE_MOVIE 1 -extern struct loaded_rom our_rom; extern bool system_corrupt; std::string resolve_relative_path(const std::string& path); diff --git a/include/core/project.hpp b/include/core/project.hpp index 873e3871..e4a03321 100644 --- a/include/core/project.hpp +++ b/include/core/project.hpp @@ -170,7 +170,7 @@ class project_state public: project_state(voice_commentary& _commentary, memwatch_set& _mwatch, command::group& _command, controller_state& _controls, settingvar::cache& _setcache, button_mapping& _buttons, - emulator_dispatch& _edispatch, input_queue& _iqueue); + emulator_dispatch& _edispatch, input_queue& _iqueue, loaded_rom& _rom); ~project_state(); /** * Get currently active project. @@ -234,6 +234,7 @@ private: button_mapping& buttons; emulator_dispatch& edispatch; input_queue& iqueue; + loaded_rom& rom; }; #endif diff --git a/src/core/actions.cpp b/src/core/actions.cpp index e37de2b4..1c8e0362 100644 --- a/src/core/actions.cpp +++ b/src/core/actions.cpp @@ -1,12 +1,15 @@ #include "core/command.hpp" +#include "core/instance.hpp" #include "core/messages.hpp" #include "core/moviedata.hpp" +#include "core/rom.hpp" namespace { command::fnptr CMD_action(lsnes_cmds, "action", "Execute core action", "Syntax: action [...]\nExecutes core action.\n", [](const std::string& _args) throw(std::bad_alloc, std::runtime_error) { + auto& core = CORE(); if(_args == "") { messages << "Action name required." << std::endl; return; @@ -15,7 +18,7 @@ namespace token_iterator itre; std::string sym = *itr++; const interface_action* act = NULL; - for(auto i : our_rom.rtype->get_actions()) + for(auto i : core.rom->rtype->get_actions()) if(i->get_symbol() == sym) { act = i; break; @@ -24,7 +27,7 @@ namespace messages << "No such action." << std::endl; return; } - if(!(our_rom.rtype->action_flags(act->id) & 1)) { + if(!(core.rom->rtype->action_flags(act->id) & 1)) { messages << "Action not enabled." << std::endl; return; } @@ -121,6 +124,6 @@ out: messages << "Excess parameters for action." << std::endl; return; } - our_rom.rtype->execute_action(act->id, params); + core.rom->rtype->execute_action(act->id, params); }); } diff --git a/src/core/debug.cpp b/src/core/debug.cpp index 4485cd44..cc4049a4 100644 --- a/src/core/debug.cpp +++ b/src/core/debug.cpp @@ -47,8 +47,8 @@ namespace } } -debug_context::debug_context(emulator_dispatch& _dispatch) - : edispatch(_dispatch) +debug_context::debug_context(emulator_dispatch& _dispatch, loaded_rom& _rom) + : edispatch(_dispatch), rom(_rom) { } @@ -60,13 +60,14 @@ const uint64_t debug_context::all_addresses = 0xFFFFFFFFFFFFFFFFULL; void debug_context::add_callback(uint64_t addr, debug_context::etype type, debug_context::callback_base& cb) { + auto& core = CORE(); std::map& xcb = get_lists(type); if(!corechange_r) { corechange.set(edispatch.core_change, [this]() { this->core_change(); }); corechange_r = true; } if(!xcb.count(addr) && type != DEBUG_FRAME) - our_rom.rtype->set_debug_flags(addr, debug_flag(type), 0); + core.rom->rtype->set_debug_flags(addr, debug_flag(type), 0); auto& lst = xcb[addr]; lst.push_back(&cb); } @@ -86,7 +87,7 @@ void debug_context::remove_callback(uint64_t addr, debug_context::etype type, de if(xcb[addr].empty()) { xcb.erase(addr); if(type != DEBUG_FRAME) - our_rom.rtype->set_debug_flags(addr, 0, debug_flag(type)); + rom.rtype->set_debug_flags(addr, 0, debug_flag(type)); } } @@ -175,12 +176,12 @@ void debug_context::do_callback_frame(uint64_t frame, bool loadstate) void debug_context::set_cheat(uint64_t addr, uint64_t value) { - our_rom.rtype->set_cheat(addr, value, true); + rom.rtype->set_cheat(addr, value, true); } void debug_context::clear_cheat(uint64_t addr) { - our_rom.rtype->set_cheat(addr, 0, false); + rom.rtype->set_cheat(addr, 0, false); } void debug_context::setxmask(uint64_t mask) @@ -200,7 +201,7 @@ void debug_context::set_tracelog_change_cb(std::function cb) void debug_context::core_change() { - our_rom.rtype->debug_reset(); + rom.rtype->debug_reset(); kill_hooks(read_cb, DEBUG_READ); kill_hooks(write_cb, DEBUG_WRITE); kill_hooks(exec_cb, DEBUG_EXEC); @@ -335,17 +336,18 @@ namespace "End tracing", [](const std::string& args) throw(std::bad_alloc, std::runtime_error) { regex_results r = regex("([^ \t]+)([ \t]+(.+))?", args); if(!r) throw std::runtime_error("tracelog: Bad arguments"); + auto& core = CORE(); std::string cpu = r[1]; std::string filename = r[3]; uint64_t _cpu = 0; - for(auto i : our_rom.rtype->get_trace_cpus()) { + for(auto i : core.rom->rtype->get_trace_cpus()) { if(cpu == i) goto out; _cpu++; } throw std::runtime_error("tracelog: Invalid CPU"); out: - CORE().dbg->tracelog(_cpu, filename); + core.dbg->tracelog(_cpu, filename); }); } diff --git a/src/core/filedownload.cpp b/src/core/filedownload.cpp index 4efc0ffe..6f92cc6e 100644 --- a/src/core/filedownload.cpp +++ b/src/core/filedownload.cpp @@ -8,9 +8,9 @@ namespace { - void file_download_thread_trampoline(file_download* d) + void file_download_thread_trampoline(file_download* d, loaded_rom* rom) { - d->_do_async(); + d->_do_async(*rom); } class file_download_handler : public http_request::output_handler @@ -57,7 +57,7 @@ void file_download::cancel() finished = true; } -void file_download::do_async() +void file_download::do_async(loaded_rom& rom) { tempname = get_temp_file(); req.ihandler = NULL; @@ -66,7 +66,7 @@ void file_download::do_async() req.url = url; try { req.lauch_async(); - (new threads::thread(file_download_thread_trampoline, this))->detach(); + (new threads::thread(file_download_thread_trampoline, this, &rom))->detach(); } catch(std::exception& e) { req.cancel(); threads::alock h(m); @@ -92,7 +92,7 @@ std::string file_download::statusmsg() return (stringfmt() << "Downloading finished").str(); } -void file_download::_do_async() +void file_download::_do_async(loaded_rom& rom) { while(!req.finished) { threads::alock h(req.m); @@ -143,8 +143,8 @@ void file_download::_do_async() if(tempname != tempname2) remove(tempname.c_str()); try { core_type* gametype = NULL; - if(!our_rom.rtype->isnull()) - gametype = our_rom.rtype; + if(!rom.rtype->isnull()) + gametype = rom.rtype; else { moviefile::brief_info info(tempname2); auto sysregs = core_sysregion::find_matching(info.sysregion); diff --git a/src/core/framebuffer.cpp b/src/core/framebuffer.cpp index 576009dc..0071b1ca 100644 --- a/src/core/framebuffer.cpp +++ b/src/core/framebuffer.cpp @@ -98,9 +98,9 @@ namespace framebuffer::raw emu_framebuffer::screen_corrupt; emu_framebuffer::emu_framebuffer(subtitle_commentary& _subtitles, settingvar::group& _settings, memwatch_set& _mwatch, - keyboard::keyboard& _keyboard, emulator_dispatch& _dispatch, lua_state& _lua2) + keyboard::keyboard& _keyboard, emulator_dispatch& _dispatch, lua_state& _lua2, loaded_rom& _rom) : buffering(buffer1, buffer2, buffer3), subtitles(_subtitles), settings(_settings), mwatch(_mwatch), - keyboard(_keyboard), edispatch(_dispatch), lua2(_lua2) + keyboard(_keyboard), edispatch(_dispatch), lua2(_lua2), rom(_rom) { last_redraw_no_lua = false; } @@ -137,7 +137,7 @@ void emu_framebuffer::init_special_screens() throw(std::bad_alloc) void emu_framebuffer::redraw_framebuffer(framebuffer::raw& todraw, bool no_lua, bool spontaneous) { uint32_t hscl, vscl; - auto g = our_rom.rtype->get_scale_factors(todraw.get_width(), todraw.get_height()); + auto g = rom.rtype->get_scale_factors(todraw.get_width(), todraw.get_height()); hscl = g.first; vscl = g.second; render_info& ri = buffering.get_write(); diff --git a/src/core/instance.cpp b/src/core/instance.cpp index ba602665..7d1827df 100644 --- a/src/core/instance.cpp +++ b/src/core/instance.cpp @@ -88,7 +88,8 @@ emulator_instance::emulator_instance() D.init(controls, *project, *mlogic, *buttons, *dispatch); D.init(keyboard); D.init(mapper, *keyboard, *command); - D.init(fbuf, *subtitles, *settings, *mwatch, *keyboard, *dispatch, *lua2); + D.init(rom); + D.init(fbuf, *subtitles, *settings, *mwatch, *keyboard, *dispatch, *lua2, *rom); D.init(buttons, *controls, *mapper, *keyboard, *fbuf, *dispatch, *lua2); D.init(mteditor, *mlogic, *controls, *dispatch); D.init(status_A); @@ -97,9 +98,9 @@ emulator_instance::emulator_instance() D.init(status, *status_A, *status_B, *status_C); D.init(abindmanager, *mapper, *command); D.init(nrrdata); - D.init(cmapper, *memory, *mlogic); - D.init(project, *commentary, *mwatch, *command, *controls, *setcache, *buttons, *dispatch, *iqueue); - D.init(dbg, *dispatch); + D.init(cmapper, *memory, *mlogic, *rom); + D.init(project, *commentary, *mwatch, *command, *controls, *setcache, *buttons, *dispatch, *iqueue, *rom); + D.init(dbg, *dispatch, *rom); D.init(framerate); D.init(mdumper, *lua2); diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index da1261cc..9ed6bdd1 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -220,7 +220,7 @@ controller_frame movie_logic::update_controls(bool subframe) throw(std::bad_allo } platform::flush_command_queue(); controller_frame tmp = core.controls->get(core.mlogic->get_movie().get_current_frame()); - our_rom.rtype->pre_emulate_frame(tmp); //Preset controls, the lua will override if needed. + core.rom->rtype->pre_emulate_frame(tmp); //Preset controls, the lua will override if needed. core.lua2->callback_do_input(tmp, subframe); core.mteditor->process_frame(tmp); core.controls->commit(tmp); @@ -288,7 +288,7 @@ void update_movie_state() bool readonly = false; { uint64_t magic[4]; - our_rom.region->fill_framerate_magic(magic); + core.rom->region->fill_framerate_magic(magic); if(*core.mlogic) core.commentary->frame_number(core.mlogic->get_movie().get_current_frame(), 1.0 * magic[1] / magic[0]); @@ -468,7 +468,7 @@ public: std::string get_base_path() { - return our_rom.msu1_base; + return CORE().rom->msu1_base; } time_t get_time() @@ -488,7 +488,7 @@ public: core.lua2->callback_do_frame_emulated(); location_special = SPECIAL_FRAME_VIDEO; core.fbuf->redraw_framebuffer(screen, false, true); - auto rate = our_rom.rtype->get_audio_rate(); + auto rate = core.rom->rtype->get_audio_rate(); uint32_t gv = gcd(fps_n, fps_d); uint32_t ga = gcd(rate.first, rate.second); core.mdumper->on_rate_change(rate.first / ga, rate.second / ga); @@ -726,25 +726,27 @@ namespace command::fnptr<> CMD_reset_c(lsnes_cmds, "reset", "Reset the system", "Syntax: reset\nReset\nResets the system in beginning of the next frame.\n", []() throw(std::bad_alloc, std::runtime_error) { - int sreset_action = our_rom.rtype->reset_action(false); + auto& core = CORE(); + int sreset_action = core.rom->rtype->reset_action(false); if(sreset_action < 0) { platform::error_message("Core does not support resets"); messages << "Emulator core does not support resets" << std::endl; return; } - our_rom.rtype->execute_action(sreset_action, std::vector()); + core.rom->rtype->execute_action(sreset_action, std::vector()); }); command::fnptr<> CMD_hreset_c(lsnes_cmds, "reset-hard", "Reset the system", "Syntax: reset-hard\nReset-hard\nHard resets the system in beginning of the next frame.\n", []() throw(std::bad_alloc, std::runtime_error) { - int hreset_action = our_rom.rtype->reset_action(true); + auto& core = CORE(); + int hreset_action = core.rom->rtype->reset_action(true); if(hreset_action < 0) { platform::error_message("Core does not support hard resets"); messages << "Emulator core does not support hard resets" << std::endl; return; } - our_rom.rtype->execute_action(hreset_action, std::vector()); + core.rom->rtype->execute_action(hreset_action, std::vector()); }); command::fnptr CMD_load_c(lsnes_cmds, "load", "Load savestate (current mode)", @@ -1168,7 +1170,7 @@ nothing_to_do: if(!*core.mlogic) return; if(!queued_saves.empty() || (do_unsafe_rewind && !unsafe_rewind_obj)) { - our_rom.rtype->runtosave(); + core.rom->rtype->runtosave(); for(auto i : queued_saves) { do_save_state(i.first, i.second); int tmp = -1; @@ -1176,7 +1178,7 @@ nothing_to_do: } if(do_unsafe_rewind && !unsafe_rewind_obj) { uint64_t t = framerate_regulator::get_utime(); - std::vector s = our_rom.save_core_state(true); + std::vector s = core.rom->save_core_state(true); uint64_t secs = core.mlogic->get_mfile().rtc_second; uint64_t ssecs = core.mlogic->get_mfile().rtc_subsecond; core.lua2->callback_do_unsafe_rewind(s, secs, ssecs, core.mlogic->get_movie(), @@ -1220,7 +1222,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_ jukebox_size_listener jlistener(*core.settings); core.commentary->init(); core.fbuf->init_special_screens(); - our_rom = rom; + *core.rom = rom; init_main_callbacks(); initialize_all_builtin_c_cores(); core_core::install_all_handlers(); @@ -1314,7 +1316,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_ just_did_loadstate = false; } core.dbg->do_callback_frame(core.mlogic->get_movie().get_current_frame(), false); - our_rom.rtype->emulate(); + core.rom->rtype->emulate(); random_mix_timing_entropy(); if(amode == ADVANCE_AUTO) platform::wait(core.framerate->to_wait_frame(framerate_regulator::get_utime())); diff --git a/src/core/memorymanip.cpp b/src/core/memorymanip.cpp index 45fe8372..52e9f78b 100644 --- a/src/core/memorymanip.cpp +++ b/src/core/memorymanip.cpp @@ -87,19 +87,19 @@ namespace }; } -cart_mappings_refresher::cart_mappings_refresher(memory_space& _mspace, movie_logic& _mlogic) - : mspace(_mspace), mlogic(_mlogic) +cart_mappings_refresher::cart_mappings_refresher(memory_space& _mspace, movie_logic& _mlogic, loaded_rom& _rom) + : mspace(_mspace), mlogic(_mlogic), rom(_rom) { } void cart_mappings_refresher::operator()() throw(std::bad_alloc) { - if(!our_rom.rtype) + if(!rom.rtype) return; std::list cur_regions = mspace.get_regions(); std::list regions; memory_region* tmp = NULL; - auto vmalist = our_rom.rtype->vma_list(); + auto vmalist = rom.rtype->vma_list(); auto _mlogic = &mlogic; try { tmp = new iospace_region("LSNESMMIO", 0xFFFFFFFF00000000ULL, 32, true, diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index ce5d4553..5e6ce264 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -23,7 +23,6 @@ #include #include -struct loaded_rom our_rom; bool system_corrupt; std::string last_save; void update_movie_state(); @@ -50,7 +49,8 @@ namespace command::fnptr CMD_dump_coresave(lsnes_cmds, "dump-coresave", "Dump bsnes core state", "Syntax: dump-coresave \nDumps core save to \n", [](const std::string& name) throw(std::bad_alloc, std::runtime_error) { - auto x = our_rom.save_core_state(); + auto& core = CORE(); + auto x = core.rom->save_core_state(); x.resize(x.size() - 32); std::ofstream y(name.c_str(), std::ios::out | std::ios::binary); y.write(&x[0], x.size()); @@ -116,11 +116,11 @@ namespace } int get_pflag() { - return our_rom.rtype->get_pflag(); + return CORE().rom->rtype->get_pflag(); } void set_pflag(int flag) { - our_rom.rtype->set_pflag(flag); + CORE().rom->rtype->set_pflag(flag); } } lsnes_pflag_handler; } @@ -223,17 +223,17 @@ void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc try { uint64_t origtime = framerate_regulator::get_utime(); target.is_savestate = true; - target.sram = our_rom.rtype->save_sram(); + target.sram = core.rom->rtype->save_sram(); for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { - target.romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); - target.romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); - target.namehint[i] = our_rom.romimg[i].namehint; + target.romimg_sha256[i] = core.rom->romimg[i].sha_256.read(); + target.romxml_sha256[i] = core.rom->romxml[i].sha_256.read(); + target.namehint[i] = core.rom->romimg[i].namehint; } - target.savestate = our_rom.save_core_state(); + target.savestate = core.rom->save_core_state(); core.fbuf->get_framebuffer().save(target.screenshot); core.mlogic->get_movie().save_state(target.projectid, target.save_frame, target.lagged_frames, target.pollcounters); - target.poll_flag = our_rom.rtype->get_pflag(); + target.poll_flag = core.rom->rtype->get_pflag(); auto prj = core.project->get(); if(prj) { target.gamename = prj->gamename; @@ -411,28 +411,28 @@ namespace if(will_load_state) { //If settings possibly change, reload the ROM. if(!*core.mlogic || core.mlogic->get_mfile().projectid != _movie.projectid) - our_rom.load(_movie.settings, _movie.movie_rtc_second, _movie.movie_rtc_subsecond); + core.rom->load(_movie.settings, _movie.movie_rtc_second, _movie.movie_rtc_subsecond); //Load the savestate and movie state. //Set the core ports in order to avoid port state being reinitialized when loading. core.controls->set_ports(portset); - our_rom.load_core_state(_movie.savestate); - our_rom.rtype->set_pflag(_movie.poll_flag); + core.rom->load_core_state(_movie.savestate); + core.rom->rtype->set_pflag(_movie.poll_flag); core.controls->set_macro_frames(_movie.active_macros); } else { //Reload the ROM in order to rewind to the beginning. - our_rom.load(_movie.settings, _movie.movie_rtc_second, _movie.movie_rtc_subsecond); + core.rom->load(_movie.settings, _movie.movie_rtc_second, _movie.movie_rtc_subsecond); //Load the SRAM and volatile RAM. Or anchor savestate if any. core.controls->set_ports(portset); _movie.rtc_second = _movie.movie_rtc_second; _movie.rtc_subsecond = _movie.movie_rtc_subsecond; if(!_movie.anchor_savestate.empty()) { - our_rom.load_core_state(_movie.anchor_savestate); + core.rom->load_core_state(_movie.anchor_savestate); } else { - our_rom.rtype->load_sram(_movie.movie_sram); - std::list vmas = our_rom.rtype->vma_list(); + core.rom->rtype->load_sram(_movie.movie_sram); + std::list vmas = core.rom->rtype->vma_list(); populate_volatile_ram(_movie, vmas); } - our_rom.rtype->set_pflag(0); + core.rom->rtype->set_pflag(0); core.controls->set_macro_frames(std::map()); } } @@ -443,10 +443,10 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error) auto& core = CORE(); bool load_readwrite = !*core.mlogic || !core.mlogic->get_movie().readonly_mode(); if(*core.mlogic) { - port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), our_rom); + port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), *core.rom); //If portset or gametype changes, force readwrite with new movie. if(core.mlogic->get_mfile().input->get_types() != portset) load_readwrite = true; - if(our_rom.rtype != &core.mlogic->get_mfile().gametype->get_type()) load_readwrite = true; + if(core.rom->rtype != &core.mlogic->get_mfile().gametype->get_type()) load_readwrite = true; } if(!load_readwrite) { @@ -457,20 +457,20 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error) core.mlogic->get_mfile().projectid), false); core.mlogic->get_rrdata().add((*core.nrrdata)()); - port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), our_rom); + port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), *core.rom); try { handle_load_core(core.mlogic->get_mfile(), portset, false); - core.mlogic->get_mfile().gametype = &our_rom.rtype->combine_region(*our_rom.region); + core.mlogic->get_mfile().gametype = &core.rom->rtype->combine_region(*core.rom->region); for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { - core.mlogic->get_mfile().namehint[i] = our_rom.romimg[i].namehint; - core.mlogic->get_mfile().romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); - core.mlogic->get_mfile().romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); + core.mlogic->get_mfile().namehint[i] = core.rom->romimg[i].namehint; + core.mlogic->get_mfile().romimg_sha256[i] = core.rom->romimg[i].sha_256.read(); + core.mlogic->get_mfile().romxml_sha256[i] = core.rom->romxml[i].sha_256.read(); } core.mlogic->get_mfile().is_savestate = false; core.mlogic->get_mfile().host_memory.clear(); core.mlogic->get_movie().reset_state(); - core.fbuf->redraw_framebuffer(our_rom.rtype->draw_cover()); + core.fbuf->redraw_framebuffer(core.rom->rtype->draw_cover()); core.lua2->callback_do_rewind(); } catch(std::bad_alloc& e) { OOM_panic(); @@ -485,14 +485,14 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error) temporary_handle _movie; _movie.get()->force_corrupt = false; _movie.get()->gametype = NULL; //Not yet known. - _movie.get()->coreversion = our_rom.rtype->get_core_identifier(); + _movie.get()->coreversion = core.rom->rtype->get_core_identifier(); _movie.get()->projectid = get_random_hexstring(40); _movie.get()->rerecords = "0"; _movie.get()->rerecords_mem = 0; for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { - _movie.get()->namehint[i] = our_rom.romimg[i].namehint; - _movie.get()->romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); - _movie.get()->romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); + _movie.get()->namehint[i] = core.rom->romimg[i].namehint; + _movie.get()->romimg_sha256[i] = core.rom->romimg[i].sha_256.read(); + _movie.get()->romxml_sha256[i] = core.rom->romxml[i].sha_256.read(); } _movie.get()->is_savestate = false; _movie.get()->save_frame = 0; @@ -502,7 +502,7 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error) _movie.get()->movie_rtc_subsecond = _movie.get()->rtc_subsecond = 0; _movie.get()->start_paused = false; _movie.get()->lazy_project_create = true; - port_type_set& portset2 = construct_movie_portset(*_movie.get(), our_rom); + port_type_set& portset2 = construct_movie_portset(*_movie.get(), *core.rom); _movie.get()->input = NULL; _movie.get()->create_default_branch(portset2); @@ -521,8 +521,8 @@ void do_load_rom() throw(std::bad_alloc, std::runtime_error) core.lua2->callback_movie_lost("reload"); try { handle_load_core(*_movie.get(), portset2, false); - _movie.get()->gametype = &our_rom.rtype->combine_region(*our_rom.region); - core.fbuf->redraw_framebuffer(our_rom.rtype->draw_cover()); + _movie.get()->gametype = &core.rom->rtype->combine_region(*core.rom->region); + core.fbuf->redraw_framebuffer(core.rom->rtype->draw_cover()); core.lua2->callback_do_rewind(); } catch(std::bad_alloc& e) { OOM_panic(); @@ -550,7 +550,7 @@ void do_load_rewind() throw(std::bad_alloc, std::runtime_error) if(!*core.mlogic || !core.mlogic->get_mfile().gametype) throw std::runtime_error("Can't rewind movie without existing movie"); - port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), our_rom); + port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), *core.rom); //Force unlazying of rrdata and count a rerecord. if(core.mlogic->get_rrdata().is_lazy()) @@ -566,7 +566,7 @@ void do_load_rewind() throw(std::bad_alloc, std::runtime_error) core.mlogic->get_mfile().is_savestate = false; core.mlogic->get_mfile().host_memory.clear(); core.mlogic->get_movie().reset_state(); - core.fbuf->redraw_framebuffer(our_rom.rtype->draw_cover()); + core.fbuf->redraw_framebuffer(core.rom->rtype->draw_cover()); core.lua2->callback_do_rewind(); } catch(std::bad_alloc& e) { OOM_panic(); @@ -588,7 +588,7 @@ void do_load_state_preserve(struct moviefile& _movie) throw std::runtime_error("Savestate is from different movie"); bool will_load_state = _movie.is_savestate; - port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), our_rom); + port_type_set& portset = construct_movie_portset(core.mlogic->get_mfile(), *core.rom); //Construct a new movie sharing the input data. temporary_handle newmovie; @@ -635,7 +635,7 @@ void do_load_state_preserve(struct moviefile& _movie) tmp.load(_movie.screenshot); core.fbuf->redraw_framebuffer(tmp); } else - core.fbuf->redraw_framebuffer(our_rom.rtype->draw_cover()); + core.fbuf->redraw_framebuffer(core.rom->rtype->draw_cover()); } catch(...) { } delete &_movie; @@ -657,12 +657,12 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used) //Various checks. if(_movie.force_corrupt) throw std::runtime_error("Movie file invalid"); - if(&(_movie.gametype->get_type()) != our_rom.rtype) + if(&(_movie.gametype->get_type()) != core.rom->rtype) throw std::runtime_error("ROM types of movie and loaded ROM don't match"); - if(our_rom.orig_region && !our_rom.orig_region->compatible_with(_movie.gametype->get_region())) + if(core.rom->orig_region && !core.rom->orig_region->compatible_with(_movie.gametype->get_region())) throw std::runtime_error("NTSC/PAL select of movie and loaded ROM don't match"); - warn_coretype(_movie.coreversion, our_rom, will_load_state); - warn_roms(_movie, our_rom, will_load_state); + warn_coretype(_movie.coreversion, *core.rom, will_load_state); + warn_roms(_movie, *core.rom, will_load_state); //In certain conditions, trun LOAD_STATE_CURRENT into LOAD_STATE_PRESERVE. if(lmode == LOAD_STATE_CURRENT && current_mode && SET_readonly_load_preserves(*core.settings)) @@ -717,7 +717,7 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used) newmovie.get()->set_movie_data(_movie.input); } - port_type_set& portset = construct_movie_portset(_movie, our_rom); + port_type_set& portset = construct_movie_portset(_movie, *core.rom); temporary_handle rrd; bool new_rrdata = false; @@ -735,7 +735,7 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used) } //Negative return. try { - our_rom.region = _movie.gametype ? &(_movie.gametype->get_region()) : NULL; + core.rom->region = _movie.gametype ? &(_movie.gametype->get_region()) : NULL; handle_load_core(_movie, portset, will_load_state); } catch(std::bad_alloc& e) { OOM_panic(); @@ -779,11 +779,11 @@ void do_load_state(struct moviefile& _movie, int lmode, bool& used) tmp.load(_movie.screenshot); core.fbuf->redraw_framebuffer(tmp); } else - core.fbuf->redraw_framebuffer(our_rom.rtype->draw_cover()); + core.fbuf->redraw_framebuffer(core.rom->rtype->draw_cover()); } core.dispatch->mode_change(m.readonly_mode()); - print_movie_info(_movie, our_rom, core.mlogic->get_rrdata()); + print_movie_info(_movie, *core.rom, core.mlogic->get_rrdata()); core.dispatch->mbranch_change(); set_gameinfo(core.mlogic->get_mfile()); } @@ -828,7 +828,7 @@ void try_request_rom(const std::string& moviefile) throw std::runtime_error("Invalid ROM type selected"); core_type* selected_core = req.cores[req.selected]; loaded_rom newrom(req.filename, selected_core->get_core_identifier(), selected_core->get_iname(), ""); - our_rom = newrom; + *core.rom = newrom; core.dispatch->core_change(); } @@ -843,9 +843,9 @@ bool do_load_state(const std::string& filename, int lmode) struct moviefile* mfile = NULL; bool used = false; try { - if(our_rom.rtype->isnull()) + if(core.rom->rtype->isnull()) try_request_rom(filename2); - mfile = new moviefile(filename2, *our_rom.rtype); + mfile = new moviefile(filename2, *core.rom->rtype); } catch(std::bad_alloc& e) { OOM_panic(); } catch(std::exception& e) { @@ -881,7 +881,7 @@ void mainloop_restore_state(const std::vector& state, uint64_t secs, uint6 core.mlogic->get_rrdata().add((*core.nrrdata)()); core.mlogic->get_mfile().rtc_second = secs; core.mlogic->get_mfile().rtc_subsecond = ssecs; - our_rom.load_core_state(state, true); + core.rom->load_core_state(state, true); } rrdata::rrdata() diff --git a/src/core/project.cpp b/src/core/project.cpp index ef6c5462..de9f1a7b 100644 --- a/src/core/project.cpp +++ b/src/core/project.cpp @@ -189,9 +189,9 @@ namespace project_state::project_state(voice_commentary& _commentary, memwatch_set& _mwatch, command::group& _command, controller_state& _controls, settingvar::cache& _setcache, button_mapping& _buttons, - emulator_dispatch& _edispatch, input_queue& _iqueue) + emulator_dispatch& _edispatch, input_queue& _iqueue, loaded_rom& _rom) : commentary(_commentary), mwatch(_mwatch), command(_command), controls(_controls), setcache(_setcache), - buttons(_buttons), edispatch(_edispatch), iqueue(_iqueue) + buttons(_buttons), edispatch(_edispatch), iqueue(_iqueue), rom(_rom) { active_project = NULL; } @@ -379,7 +379,7 @@ bool project_state::set(project_info* p, bool current) } //Okay, loaded, load into core. newrom.load(p->settings, p->movie_rtc_second, p->movie_rtc_subsecond); - our_rom = newrom; + rom = newrom; do_load_state(*newmovie, LOAD_STATE_DEFAULT, used); skip_rom_movie: active_project = p; diff --git a/src/core/romloader.cpp b/src/core/romloader.cpp index b24c2d4a..ec56d8dd 100644 --- a/src/core/romloader.cpp +++ b/src/core/romloader.cpp @@ -16,7 +16,7 @@ bool load_null_rom() return false; } loaded_rom newrom; - our_rom = newrom; + *core.rom = newrom; if(*core.mlogic) for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { core.mlogic->get_mfile().romimg_sha256[i] = ""; @@ -31,20 +31,21 @@ namespace { void load_new_rom_inner(const romload_request& req) { + auto& core = CORE(); if(req.packfile != "") { messages << "Loading ROM " << req.packfile << std::endl; loaded_rom newrom(req.packfile); - our_rom = newrom; + *core.rom = newrom; return; } else if(req.singlefile != "") { messages << "Loading ROM " << req.singlefile << std::endl; loaded_rom newrom(req.singlefile, req.core, req.system, req.region); - our_rom = newrom; + *core.rom = newrom; return; } else { messages << "Loading multi-file ROM." << std::endl; loaded_rom newrom(req.files, req.core, req.system, req.region); - our_rom = newrom; + *core.rom = newrom; return; } } @@ -99,16 +100,16 @@ bool _load_new_rom(const romload_request& req) load_new_rom_inner(req); if(*core.mlogic) for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { - core.mlogic->get_mfile().romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); - core.mlogic->get_mfile().romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); - core.mlogic->get_mfile().namehint[i] = our_rom.romimg[i].namehint; + core.mlogic->get_mfile().romimg_sha256[i] = core.rom->romimg[i].sha_256.read(); + core.mlogic->get_mfile().romxml_sha256[i] = core.rom->romxml[i].sha_256.read(); + core.mlogic->get_mfile().namehint[i] = core.rom->romimg[i].namehint; } } catch(std::exception& e) { platform::error_message(std::string("Can't load ROM: ") + e.what()); messages << "Can't reload ROM: " << e.what() << std::endl; return false; } - messages << "Using core: " << our_rom.rtype->get_core_identifier() << std::endl; + messages << "Using core: " << core.rom->rtype->get_core_identifier() << std::endl; core.dispatch->core_change(); return true; } @@ -116,22 +117,23 @@ bool _load_new_rom(const romload_request& req) bool reload_active_rom() { + auto& core = CORE(); romload_request req; - if(our_rom.rtype->isnull()) { + if(core.rom->rtype->isnull()) { platform::error_message("Can't reload ROM: No existing ROM"); messages << "No ROM loaded" << std::endl; return false; } - if(our_rom.load_filename != "") { - req.packfile = our_rom.load_filename; + if(core.rom->load_filename != "") { + req.packfile = core.rom->load_filename; return _load_new_rom(req); } //This is composite ROM. - req.core = our_rom.rtype->get_core_identifier(); - req.system = our_rom.rtype->get_iname(); - req.region = our_rom.orig_region->get_iname(); + req.core = core.rom->rtype->get_core_identifier(); + req.system = core.rom->rtype->get_iname(); + req.region = core.rom->orig_region->get_iname(); for(unsigned i = 0; i < ROM_SLOT_COUNT; i++) - req.files[i] = our_rom.romimg[i].filename; + req.files[i] = core.rom->romimg[i].filename; return _load_new_rom(req); } diff --git a/src/interface/cover.cpp b/src/interface/cover.cpp index 316c57b4..99fc5354 100644 --- a/src/interface/cover.cpp +++ b/src/interface/cover.cpp @@ -1,3 +1,4 @@ +#include "core/instance.hpp" #include "core/moviedata.hpp" #include "core/memorymanip.hpp" #include "interface/cover.hpp" @@ -102,7 +103,8 @@ void cover_next_position(const std::string& str, unsigned& x, unsigned& y) std::vector cover_information() { + auto& core = CORE(); std::vector ret; - ret.push_back("System: " + our_rom.rtype->get_hname() + " (" + our_rom.region->get_hname() + ")"); + ret.push_back("System: " + core.rom->rtype->get_hname() + " (" + core.rom->region->get_hname() + ")"); return ret; } diff --git a/src/lua/actions.cpp b/src/lua/actions.cpp index 4ed700d9..e7d802df 100644 --- a/src/lua/actions.cpp +++ b/src/lua/actions.cpp @@ -1,5 +1,6 @@ #include "lua/internal.hpp" #include "interface/romtype.hpp" +#include "core/instance.hpp" #include "core/moviedata.hpp" #include "core/messages.hpp" @@ -7,19 +8,20 @@ namespace { int action(lua::state& L, lua::parameters& P) { + auto& core = CORE(); std::string name; P(name); const interface_action* act = NULL; - for(auto i : our_rom.rtype->get_actions()) + for(auto i : core.rom->rtype->get_actions()) if(i->get_symbol() == name) { act = i; break; } if(!act) throw std::runtime_error("No such action"); - if(!(our_rom.rtype->action_flags(act->id) & 1)) + if(!(core.rom->rtype->action_flags(act->id) & 1)) throw std::runtime_error("Action not enabled."); std::vector params; for(auto i : act->params) { @@ -91,7 +93,7 @@ out: } if(P.more()) throw std::runtime_error("Excess arguments for action"); - our_rom.rtype->execute_action(act->id, params); + core.rom->rtype->execute_action(act->id, params); return 0; } diff --git a/src/lua/core.cpp b/src/lua/core.cpp index ef0e409a..83560b09 100644 --- a/src/lua/core.cpp +++ b/src/lua/core.cpp @@ -170,11 +170,12 @@ namespace int bus_address(lua::state& L, lua::parameters& P) { + auto& core = CORE(); uint64_t addr; P(addr); - auto busrange = our_rom.rtype->get_bus_map(); + auto busrange = core.rom->rtype->get_bus_map(); if(!busrange.second) throw std::runtime_error("This platform does not have bus mapping"); L.pushnumber(busrange.first + (addr % busrange.second)); @@ -183,18 +184,20 @@ namespace int get_lag_flag(lua::state& L, lua::parameters& P) { - L.pushboolean(!(our_rom.rtype && our_rom.rtype->get_pflag())); + auto& core = CORE(); + L.pushboolean(!(core.rom->rtype && core.rom->rtype->get_pflag())); return 1; } int set_lag_flag(lua::state& L, lua::parameters& P) { + auto& core = CORE(); bool flag; P(flag); - if(our_rom.rtype) - our_rom.rtype->set_pflag(!flag); + if(core.rom->rtype) + core.rom->rtype->set_pflag(!flag); return 0; } diff --git a/src/lua/disassemble.cpp b/src/lua/disassemble.cpp index 9a4892eb..9541994c 100644 --- a/src/lua/disassemble.cpp +++ b/src/lua/disassemble.cpp @@ -48,11 +48,12 @@ namespace int getregister(lua::state& L, lua::parameters& P) { + auto& core = CORE(); std::string r; P(r); - const interface_device_reg* regs = our_rom.rtype->get_registers(); + const interface_device_reg* regs = core.rom->rtype->get_registers(); if(!regs) { L.pushnil(); return 1; @@ -72,7 +73,8 @@ namespace int getregisters(lua::state& L, lua::parameters& P) { - const interface_device_reg* regs = our_rom.rtype->get_registers(); + auto& core = CORE(); + const interface_device_reg* regs = core.rom->rtype->get_registers(); if(!regs) { L.pushnil(); return 1; @@ -91,11 +93,12 @@ namespace int setregister(lua::state& L, lua::parameters& P) { + auto& core = CORE(); std::string r; P(r); - const interface_device_reg* regs = our_rom.rtype->get_registers(); + const interface_device_reg* regs = core.rom->rtype->get_registers(); if(!regs) { return 0; } diff --git a/src/lua/memory.cpp b/src/lua/memory.cpp index 31e6d8c1..ec6d9d9a 100644 --- a/src/lua/memory.cpp +++ b/src/lua/memory.cpp @@ -644,7 +644,8 @@ namespace int hash_state(lua::state& L, lua::parameters& P) { - auto x = our_rom.save_core_state(); + auto& core = CORE(); + auto x = core.rom->save_core_state(); size_t offset = x.size() - 32; L.pushlstring(hex::b_to((uint8_t*)&x[offset], 32)); return 1; diff --git a/src/lua/movie.cpp b/src/lua/movie.cpp index 12194c56..5526e68d 100644 --- a/src/lua/movie.cpp +++ b/src/lua/movie.cpp @@ -103,11 +103,12 @@ namespace int to_rewind(lua::state& L, lua::parameters& P) { + auto& core = CORE(); std::string filename; P(filename); - moviefile mfile(filename, *our_rom.rtype); + moviefile mfile(filename, *core.rom->rtype); if(!mfile.is_savestate) throw std::runtime_error("movie.to_rewind only allows savestates"); lua_unsaferewind* u2 = lua::_class::create(L); diff --git a/src/platform/wxwidgets/editor-movie.cpp b/src/platform/wxwidgets/editor-movie.cpp index 27dc2668..9f6509da 100644 --- a/src/platform/wxwidgets/editor-movie.cpp +++ b/src/platform/wxwidgets/editor-movie.cpp @@ -1456,7 +1456,7 @@ void wxeditor_movie::_moviepanel::popup_axis_panel(uint64_t row, control_info ci framebuffer::raw& _fb = inst.fbuf->render_get_latest_screen(); framebuffer::fb fb; auto osize = std::make_pair(_fb.get_width(), _fb.get_height()); - auto size = our_rom.rtype->lightgun_scale(); + auto size = inst.rom->rtype->lightgun_scale(); fb.reallocate(osize.first, osize.second, false); fb.copy_from(_fb, 1, 1); inst.fbuf->render_get_latest_screen_end(); diff --git a/src/platform/wxwidgets/editor-tasinput.cpp b/src/platform/wxwidgets/editor-tasinput.cpp index 43049c23..b5d562cd 100644 --- a/src/platform/wxwidgets/editor-tasinput.cpp +++ b/src/platform/wxwidgets/editor-tasinput.cpp @@ -272,7 +272,7 @@ void wxeditor_tasinput::xypanel::on_paint(wxPaintEvent& e) framebuffer::raw& _fb = inst.fbuf->render_get_latest_screen(); framebuffer::fb fb; auto osize = std::make_pair(_fb.get_width(), _fb.get_height()); - auto size = our_rom.rtype->lightgun_scale(); + auto size = inst.rom->rtype->lightgun_scale(); fb.reallocate(osize.first, osize.second, false); fb.copy_from(_fb, 1, 1); inst.fbuf->render_get_latest_screen_end(); diff --git a/src/platform/wxwidgets/main.cpp b/src/platform/wxwidgets/main.cpp index ed94a1c1..13edfc01 100644 --- a/src/platform/wxwidgets/main.cpp +++ b/src/platform/wxwidgets/main.cpp @@ -549,7 +549,7 @@ bool lsnes_app::OnInit() else { mov = new moviefile(rom, c_settings, DEFAULT_RTC_SECOND, DEFAULT_RTC_SUBSECOND); } - our_rom = rom; + *lsnes_instance.rom = rom; mov->start_paused = start_unpaused ? !(rom.rtype && !rom.rtype->isnull()) : true; for(auto i : c_lua) lsnes_instance.lua2->add_startup_script(i); diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index b437ccdb..a9f0ffe9 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -388,7 +388,7 @@ namespace return; unsigned act_id = action_by_id[e.GetId()]; const interface_action* act = NULL; - for(auto i : our_rom.rtype->get_actions()) + for(auto i : inst.rom->rtype->get_actions()) if(i->id == act_id) { act = i; break; @@ -397,7 +397,7 @@ namespace return; try { auto p = prompt_action_params(pwin, act->get_title(), act->params); - inst.iqueue->run([act_id,p]() { our_rom.rtype->execute_action(act_id, p); }); + inst.iqueue->run([this, act_id,p]() { this->inst.rom->rtype->execute_action(act_id, p); }); } catch(canceled_exception& e) { } catch(std::bad_alloc& e) { OOM_panic(); @@ -423,13 +423,13 @@ namespace submenui_by_name.clear(); toggles.clear(); - for(auto i : our_rom.rtype->get_actions()) + for(auto i : inst.rom->rtype->get_actions()) insert_act(i->id, i->get_title(), !i->params.empty(), i->is_toggle()); } for(auto i : item_by_action) - i.second->Enable(our_rom.rtype->action_flags(i.first) & 1); + i.second->Enable(inst.rom->rtype->action_flags(i.first) & 1); for(auto i : toggles) - item_by_action[i]->Check(our_rom.rtype->action_flags(i) & 2); + item_by_action[i]->Check(inst.rom->rtype->action_flags(i) & 2); } std::string munge_name(const std::string& orig) @@ -588,13 +588,14 @@ namespace if(p) windowname = windowname + p->name; else - windowname = windowname + our_rom.rtype->get_core_identifier(); + windowname = windowname + inst.rom->rtype->get_core_identifier(); windowname = windowname + "]"; return towxstring(windowname); } struct emu_args { + emulator_instance* inst; struct loaded_rom rom; struct moviefile* initial; bool load_has_to_succeed; @@ -603,13 +604,14 @@ namespace void* emulator_main(void* _args) { struct emu_args* args = reinterpret_cast(_args); + auto& inst = *args->inst; try { - our_rom = args->rom; - messages << "Using core: " << our_rom.rtype->get_core_identifier() << std::endl; + *inst.rom = args->rom; + messages << "Using core: " << inst.rom->rtype->get_core_identifier() << std::endl; struct moviefile* movie = args->initial; bool has_to_succeed = args->load_has_to_succeed; platform::flush_command_queue(); - main_loop(our_rom, *movie, has_to_succeed); + main_loop(*inst.rom, *movie, has_to_succeed); signal_program_exit(); } catch(std::bad_alloc& e) { OOM_panic(); @@ -756,6 +758,7 @@ void boot_emulator(emulator_instance& inst, loaded_rom& rom, moviefile& movie, b a->rom = rom; a->initial = &movie; a->load_has_to_succeed = false; + a->inst = &inst; modal_pause_holder hld; emulation_thread = new threads::thread(emulator_main, a); main_window = new wxwin_mainwindow(inst, fscreen); @@ -895,8 +898,8 @@ void wxwin_mainwindow::panel::on_paint(wxPaintEvent& e) wxPaintDC dc(this); uint32_t tw, th; bool aux = hflip_enabled || vflip_enabled || rotate_enabled; - auto sfactors = calc_scale_factors(video_scale_factor, arcorrect_enabled, our_rom.rtype ? - our_rom.rtype->get_PAR() : 1.0); + auto sfactors = calc_scale_factors(video_scale_factor, arcorrect_enabled, inst.rom->rtype ? + inst.rom->rtype->get_PAR() : 1.0); if(rotate_enabled) { tw = inst.fbuf->main_screen.get_height() * sfactors.second + 0.5; th = inst.fbuf->main_screen.get_width() * sfactors.first + 0.5; @@ -1187,7 +1190,7 @@ wxwin_mainwindow::wxwin_mainwindow(emulator_instance& _inst, bool fscreen) spanel->SetDropTarget(new loadfile(this, inst)); set_hasher_callback(hash_callback); reinterpret_cast(sysmenu)->update(false); - menubar->SetMenuLabel(1, towxstring(our_rom.rtype->get_systemmenu_name())); + menubar->SetMenuLabel(1, towxstring(inst.rom->rtype->get_systemmenu_name())); focus_timer = new _focus_timer; status_timer = new _status_timer; if(fscreen) { @@ -1355,7 +1358,7 @@ void wxwin_mainwindow::refresh_title() throw() menu_enable(wxID_CLOSE_PROJECT, p != NULL); menu_enable(wxID_CLOSE_ROM, p == NULL); reinterpret_cast(sysmenu)->update(false); - menubar->SetMenuLabel(1, towxstring(our_rom.rtype->get_systemmenu_name())); + menubar->SetMenuLabel(1, towxstring(inst.rom->rtype->get_systemmenu_name())); } namespace @@ -1790,7 +1793,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) download_in_progress = new file_download(); download_in_progress->url = lsnes_uri_rewrite(filename); download_in_progress->target_slot = "wxwidgets_download_tmp"; - download_in_progress->do_async(); + download_in_progress->do_async(*inst.rom); new download_timer(this, inst); return; } diff --git a/src/platform/wxwidgets/mouse.cpp b/src/platform/wxwidgets/mouse.cpp index f5cf89b0..a1176c2f 100644 --- a/src/platform/wxwidgets/mouse.cpp +++ b/src/platform/wxwidgets/mouse.cpp @@ -40,7 +40,7 @@ void handle_wx_mouse(emulator_instance& inst, wxMouseEvent& e) auto s = mkeys.lookup(inst); if(!s) return; auto sfactors = calc_scale_factors(video_scale_factor, arcorrect_enabled, - (our_rom.rtype) ? our_rom.rtype->get_PAR() : 1.0); + (inst.rom->rtype) ? inst.rom->rtype->get_PAR() : 1.0); inst.iqueue->queue(keypress_info(keyboard::modifier_set(), s->mouse_x, e.GetX() / sfactors.first)); inst.iqueue->queue(keypress_info(keyboard::modifier_set(), s->mouse_y, e.GetY() / diff --git a/src/platform/wxwidgets/romselect.cpp b/src/platform/wxwidgets/romselect.cpp index da18f209..30e503c5 100644 --- a/src/platform/wxwidgets/romselect.cpp +++ b/src/platform/wxwidgets/romselect.cpp @@ -248,7 +248,7 @@ namespace project_info pinfo(*inst.dispatch); pinfo.id = generate_project_id(); pinfo.name = tostdstring(projname->GetValue()); - pinfo.rom = our_rom.load_filename; + pinfo.rom = inst.rom->load_filename; pinfo.last_save = ""; pinfo.directory = tostdstring(projdir->GetValue()); pinfo.prefix = tostdstring(projpfx->GetValue()); @@ -268,7 +268,7 @@ namespace inst.project->copy_watches(pinfo); inst.project->copy_macros(pinfo, *inst.controls); for(unsigned i = 0; i < ROM_SLOT_COUNT; i++) { - pinfo.roms[i] = our_rom.romimg[i].filename; + pinfo.roms[i] = inst.rom->romimg[i].filename; pinfo.romimg_sha256[i] = m.romimg_sha256[i]; pinfo.romxml_sha256[i] = m.romxml_sha256[i]; pinfo.namehint[i] = m.namehint[i]; @@ -474,7 +474,7 @@ private: void show_projectwindow(wxWindow* modwin, emulator_instance& inst) { - if(!our_rom.rtype) { + if(!inst.rom->rtype) { show_message_ok(modwin, "Can't start new movie", "No ROM loaded", wxICON_EXCLAMATION); return; } @@ -491,7 +491,7 @@ wxwin_project::wxwin_project(emulator_instance& _inst) { std::vector cchoices; - std::set sram_set = our_rom.rtype->srams(); + std::set sram_set = inst.rom->rtype->srams(); Centre(); //2 Top-level block. @@ -509,7 +509,7 @@ wxwin_project::wxwin_project(emulator_instance& _inst) wxFlexGridSizer* new_sizer = new wxFlexGridSizer(3, 1, 0, 0); new_panel->SetSizer(new_sizer); //Controllertypes/Gamename/initRTC/SRAMs. - auto settingblock = our_rom.rtype->get_settings().settings; + auto settingblock = inst.rom->rtype->get_settings().settings; wxFlexGridSizer* mainblock = new wxFlexGridSizer(4 + settingblock.size() + sram_set.size(), 2, 0, 0); auto _settingblock = sort_settingblock(settingblock); for(auto i : _settingblock) { @@ -645,21 +645,21 @@ struct moviefile& wxwin_project::make_movie() { moviefile& f = *new moviefile; f.force_corrupt = false; - f.gametype = &our_rom.rtype->combine_region(*our_rom.region); + f.gametype = &inst.rom->rtype->combine_region(*inst.rom->region); for(auto i : settings) { f.settings[i.first] = i.second.read(); if(!i.second.get_setting().validate(f.settings[i.first])) throw std::runtime_error((stringfmt() << "Bad value for setting " << i.first).str()); } - f.coreversion = our_rom.rtype->get_core_identifier(); + f.coreversion = inst.rom->rtype->get_core_identifier(); f.gamename = tostdstring(projectname->GetValue()); f.projectid = get_random_hexstring(40); set_mprefix_for_project(f.projectid, tostdstring(prefix->GetValue())); f.rerecords = "0"; for(size_t i = 0; i < ROM_SLOT_COUNT; i++) { - f.romimg_sha256[i] = our_rom.romimg[i].sha_256.read(); - f.romxml_sha256[i] = our_rom.romxml[i].sha_256.read(); - f.namehint[i] = our_rom.romimg[i].namehint; + f.romimg_sha256[i] = inst.rom->romimg[i].sha_256.read(); + f.romxml_sha256[i] = inst.rom->romxml[i].sha_256.read(); + f.namehint[i] = inst.rom->romimg[i].namehint; } size_t lines = authors->GetNumberOfLines(); for(size_t i = 0; i < lines; i++) { @@ -682,7 +682,7 @@ struct moviefile& wxwin_project::make_movie() f.movie_rtc_subsecond = f.rtc_subsecond = boost::lexical_cast(tostdstring(rtc_subsec->GetValue())); if(f.movie_rtc_subsecond < 0) throw std::runtime_error("RTC subsecond must be positive"); - auto ctrldata = our_rom.rtype->controllerconfig(f.settings); + auto ctrldata = inst.rom->rtype->controllerconfig(f.settings); port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex()); f.create_default_branch(ports); return f; @@ -690,7 +690,7 @@ struct moviefile& wxwin_project::make_movie() void open_new_project_window(wxWindow* parent, emulator_instance& inst) { - if(our_rom.rtype->isnull()) { + if(inst.rom->rtype->isnull()) { show_message_ok(parent, "Can't start new project", "No ROM loaded", wxICON_EXCLAMATION); return; } diff --git a/src/platform/wxwidgets/tracelogmenu.cpp b/src/platform/wxwidgets/tracelogmenu.cpp index 3445ea4c..4e040d79 100644 --- a/src/platform/wxwidgets/tracelogmenu.cpp +++ b/src/platform/wxwidgets/tracelogmenu.cpp @@ -50,7 +50,7 @@ void tracelog_menu::on_select(wxCommandEvent& e) void tracelog_menu::update() { - auto _items = our_rom.rtype->get_trace_cpus(); + auto _items = inst.rom->rtype->get_trace_cpus(); for(auto i : items) Delete(i); items.clear(); diff --git a/src/platform/wxwidgets/window-fileupload.cpp b/src/platform/wxwidgets/window-fileupload.cpp index 903819d1..6e00c5cb 100644 --- a/src/platform/wxwidgets/window-fileupload.cpp +++ b/src/platform/wxwidgets/window-fileupload.cpp @@ -638,7 +638,7 @@ wxeditor_uploaddialog::wxeditor_uploaddialog(wxWindow* parent, emulator_instance wxCommandEventHandler(wxeditor_uploaddialog::on_source_sel), NULL, this); file->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(wxeditor_uploaddialog::on_source_sel), NULL, this); - if(!inst.mlogic || !our_rom.rtype || our_rom.rtype->isnull()) { + if(!inst.mlogic || !inst.rom->rtype || inst.rom->rtype->isnull()) { current->Enable(false); file->SetValue(true); } diff --git a/src/util/lsnes-dumpavi.cpp b/src/util/lsnes-dumpavi.cpp index efcb70be..e7749368 100644 --- a/src/util/lsnes-dumpavi.cpp +++ b/src/util/lsnes-dumpavi.cpp @@ -45,7 +45,7 @@ namespace if(download_in_progress->url != origname) messages << "Internally redirecting to " << download_in_progress->url << std::endl; download_in_progress->target_slot = "dumpavi_download_tmp"; - download_in_progress->do_async(); + download_in_progress->do_async(*lsnes_instance.rom); messages << "Downloading " << download_in_progress->url << ":" << std::endl; while(!download_in_progress->finished) { messages << download_in_progress->statusmsg() << std::endl; @@ -417,10 +417,10 @@ int main(int argc, char** argv) try { movie = new moviefile(movfn, *r.rtype); //Load ROM before starting the dumper. - our_rom = r; - messages << "Using core: " << our_rom.rtype->get_core_identifier() << std::endl; - our_rom.region = &movie->gametype->get_region(); - our_rom.load(movie->settings, movie->movie_rtc_second, movie->movie_rtc_subsecond); + *lsnes_instance.rom = r; + messages << "Using core: " << lsnes_instance.rom->rtype->get_core_identifier() << std::endl; + lsnes_instance.rom->region = &movie->gametype->get_region(); + lsnes_instance.rom->load(movie->settings, movie->movie_rtc_second, movie->movie_rtc_subsecond); startup_lua_scripts(cmdline); if(overdump_mode) length = overdump_length + movie->get_frame_count(); diff --git a/src/video/avi.cpp b/src/video/avi.cpp index ec840f18..9c6f0615 100644 --- a/src/video/avi.cpp +++ b/src/video/avi.cpp @@ -408,7 +408,7 @@ again: hscl = fxfact; vscl = fyfact; } else if(dump_large(*core.settings)) { - rpair(hscl, vscl) = our_rom.rtype->get_scale_factors(_frame.get_width(), + rpair(hscl, vscl) = core.rom->rtype->get_scale_factors(_frame.get_width(), _frame.get_height()); } if(!render_video_hud(dscr, _frame, fps_n, fps_d, hscl, vscl, dlb(*core.settings), diff --git a/src/video/raw.cpp b/src/video/raw.cpp index d31b40a5..e167bc60 100644 --- a/src/video/raw.cpp +++ b/src/video/raw.cpp @@ -97,10 +97,12 @@ namespace } void on_frame(struct framebuffer::raw& _frame, uint32_t fps_n, uint32_t fps_d) { + auto& core = CORE(); if(!video) return; uint32_t hscl, vscl; - rpair(hscl, vscl) = our_rom.rtype->get_scale_factors(_frame.get_width(), _frame.get_height()); + rpair(hscl, vscl) = core.rom->rtype->get_scale_factors(_frame.get_width(), + _frame.get_height()); if(bits64) { size_t w = dscr2.get_width(); size_t h = dscr2.get_height(); -- 2.11.4.GIT