Clean up some uses of lsnes_instance

This commit is contained in:
Ilari Liusvaara 2014-05-10 13:55:07 +03:00
parent ee0d0089dc
commit 3e4c03d114
19 changed files with 208 additions and 201 deletions

View file

@ -22,4 +22,6 @@ struct emulator_instance
extern emulator_instance lsnes_instance;
emulator_instance& CORE();
#endif

View file

@ -51,7 +51,7 @@ namespace
dres x;
x.addr = laddr;
x.disasm = d->disassemble(laddr, [&bytes, laddr]() -> unsigned char {
return lsnes_instance.memory.read<uint8_t>(laddr + bytes++);
return CORE().memory.read<uint8_t>(laddr + bytes++);
});
x.len = bytes;
result.push_back(x);
@ -69,7 +69,7 @@ namespace
for(auto i : result) {
std::vector<unsigned char> tmp;
tmp.resize(i.len);
lsnes_instance.memory.read_range(i.addr, &tmp[0], i.len);
CORE().memory.read_range(i.addr, &tmp[0], i.len);
std::string l = hex::to(i.addr) + " " + hex::b_to(&tmp[0], i.len) + " " + i.disasm;
(*strm) << l << std::endl;
}

View file

@ -165,7 +165,7 @@ void redraw_framebuffer(framebuffer::raw& todraw, bool no_lua, bool spontaneous)
lrc.height = todraw.get_height() * vscl;
if(!no_lua) {
lua_callback_do_paint(&lrc, spontaneous);
lsnes_instance.subtitles.render(lrc);
CORE().subtitles.render(lrc);
}
ri.fbuf = todraw;
ri.hscl = hscl;
@ -174,7 +174,7 @@ void redraw_framebuffer(framebuffer::raw& todraw, bool no_lua, bool spontaneous)
ri.rgap = max(lrc.right_gap, (unsigned)drb);
ri.tgap = max(lrc.top_gap, (unsigned)dtb);
ri.bgap = max(lrc.bottom_gap, (unsigned)dbb);
lsnes_instance.mwatch.watch(ri.rq);
CORE().mwatch.watch(ri.rq);
buffering.put_write();
notify_screen_update();
last_redraw_no_lua = no_lua;

View file

@ -7,3 +7,8 @@ emulator_instance::emulator_instance()
}
emulator_instance lsnes_instance;
emulator_instance& CORE()
{
return lsnes_instance;
}

View file

@ -1701,12 +1701,12 @@ out:
command::fnptr<> ptangent(lsnes_cmd, "+tangent", "Voice tangent",
"Syntax: +tangent\nVoice tangent.\n",
[]() throw(std::bad_alloc, std::runtime_error) {
lsnes_instance.commentary.set_active_flag(true);
CORE().commentary.set_active_flag(true);
});
command::fnptr<> ntangent(lsnes_cmd, "-tangent", "Voice tangent",
"Syntax: -tangent\nVoice tangent.\n",
[]() throw(std::bad_alloc, std::runtime_error) {
lsnes_instance.commentary.set_active_flag(false);
CORE().commentary.set_active_flag(false);
});
keyboard::invbind itangent(lsnes_mapper, "+tangent", "Movie‣Voice tangent");
}

View file

@ -130,9 +130,9 @@ namespace
std::ostringstream out;
try {
moviefile::brief_info info(filename);
if(!lsnes_instance.mlogic)
if(!CORE().mlogic)
out << "No movie";
else if(lsnes_instance.mlogic.get_mfile().projectid == info.projectid)
else if(CORE().mlogic.get_mfile().projectid == info.projectid)
out << info.rerecords << "R/" << info.current_frame << "F";
else
out << "Wrong movie";
@ -218,16 +218,16 @@ controller_frame movie_logic::update_controls(bool subframe) throw(std::bad_allo
cancel_advance = false;
}
platform::set_paused(amode == ADVANCE_PAUSE);
} else if(amode == ADVANCE_AUTO && lsnes_instance.mlogic.get_movie().readonly_mode() &&
} else if(amode == ADVANCE_AUTO && CORE().mlogic.get_movie().readonly_mode() &&
pause_on_end && !stop_at_frame_active) {
if(lsnes_instance.mlogic.get_movie().get_current_frame() ==
lsnes_instance.mlogic.get_movie().get_frame_count()) {
if(CORE().mlogic.get_movie().get_current_frame() ==
CORE().mlogic.get_movie().get_frame_count()) {
stop_at_frame_active = false;
amode = ADVANCE_PAUSE;
platform::set_paused(true);
}
} else if(amode == ADVANCE_AUTO && stop_at_frame_active) {
if(lsnes_instance.mlogic.get_movie().get_current_frame() >= stop_at_frame) {
if(CORE().mlogic.get_movie().get_current_frame() >= stop_at_frame) {
stop_at_frame_active = false;
amode = ADVANCE_PAUSE;
platform::set_paused(true);
@ -240,7 +240,7 @@ controller_frame movie_logic::update_controls(bool subframe) throw(std::bad_allo
update_movie_state();
}
platform::flush_command_queue();
controller_frame tmp = controls.get(lsnes_instance.mlogic.get_movie().get_current_frame());
controller_frame tmp = controls.get(CORE().mlogic.get_movie().get_current_frame());
our_rom.rtype->pre_emulate_frame(tmp); //Preset controls, the lua will override if needed.
lua_callback_do_input(tmp, subframe);
multitrack_editor.process_frame(tmp);
@ -305,19 +305,19 @@ void update_movie_state()
{
uint64_t magic[4];
our_rom.region->fill_framerate_magic(magic);
if(lsnes_instance.mlogic)
lsnes_instance.commentary.frame_number(lsnes_instance.mlogic.get_movie().get_current_frame(),
if(CORE().mlogic)
CORE().commentary.frame_number(CORE().mlogic.get_movie().get_current_frame(),
1.0 * magic[1] / magic[0]);
else
lsnes_instance.commentary.frame_number(0, 60.0); //Default.
CORE().commentary.frame_number(0, 60.0); //Default.
}
auto& _status = lsnes_status.get_write();
try {
if(lsnes_instance.mlogic && !system_corrupt) {
if(CORE().mlogic && !system_corrupt) {
_status.movie_valid = true;
_status.curframe = lsnes_instance.mlogic.get_movie().get_current_frame();
_status.length = lsnes_instance.mlogic.get_movie().get_frame_count();
_status.lag = lsnes_instance.mlogic.get_movie().get_lag_frames();
_status.curframe = CORE().mlogic.get_movie().get_current_frame();
_status.length = CORE().mlogic.get_movie().get_frame_count();
_status.lag = CORE().mlogic.get_movie().get_lag_frames();
if(location_special == SPECIAL_FRAME_START)
_status.subframe = 0;
else if(location_special == SPECIAL_SAVEPOINT)
@ -325,7 +325,7 @@ void update_movie_state()
else if(location_special == SPECIAL_FRAME_VIDEO)
_status.subframe = _lsnes_status::subframe_video;
else
_status.subframe = lsnes_instance.mlogic.get_movie().next_poll_number();
_status.subframe = CORE().mlogic.get_movie().next_poll_number();
} else {
_status.movie_valid = false;
_status.curframe = 0;
@ -340,8 +340,8 @@ void update_movie_state()
_status.pause = _lsnes_status::pause_normal;
else
_status.pause = _lsnes_status::pause_none;
if(lsnes_instance.mlogic) {
auto& mo = lsnes_instance.mlogic.get_movie();
if(CORE().mlogic) {
auto& mo = CORE().mlogic.get_movie();
readonly = mo.readonly_mode();
if(system_corrupt)
_status.mode = 'C';
@ -364,15 +364,15 @@ void update_movie_state()
_status.branch_valid = (p != NULL);
if(p) _status.branch = utf8::to32(p->get_branch_string());
std::string cur_branch = lsnes_instance.mlogic ? lsnes_instance.mlogic.get_mfile().current_branch() :
std::string cur_branch = CORE().mlogic ? CORE().mlogic.get_mfile().current_branch() :
"";
_status.mbranch_valid = (cur_branch != "");
_status.mbranch = utf8::to32(cur_branch);
_status.speed = (unsigned)(100 * get_realized_multiplier() + 0.5);
if(lsnes_instance.mlogic && !system_corrupt) {
time_t timevalue = static_cast<time_t>(lsnes_instance.mlogic.get_mfile().rtc_second);
if(CORE().mlogic && !system_corrupt) {
time_t timevalue = static_cast<time_t>(CORE().mlogic.get_mfile().rtc_second);
struct tm* time_decompose = gmtime(&timevalue);
char datebuffer[512];
strftime(datebuffer, 511, "%Y%m%d(%a)T%H%M%S", time_decompose);
@ -394,7 +394,7 @@ void update_movie_state()
controller_frame c;
if(!multitrack_editor.any_records())
c = lsnes_instance.mlogic.get_movie().get_controls();
c = CORE().mlogic.get_movie().get_controls();
else
c = controls.get_committed();
_status.inputs.clear();
@ -423,7 +423,7 @@ void update_movie_state()
//Lua variables.
_status.lvars = get_lua_watch_vars();
//Memory watches.
_status.mvars = lsnes_instance.mwatch.get_window_vars();
_status.mvars = CORE().mwatch.get_window_vars();
_status.valid = true;
} catch(...) {
@ -447,19 +447,19 @@ public:
int16_t get_input(unsigned port, unsigned index, unsigned control)
{
int16_t x;
x = lsnes_instance.mlogic.input_poll(port, index, control);
x = CORE().mlogic.input_poll(port, index, control);
lua_callback_snoop_input(port, index, control, x);
return x;
}
int16_t set_input(unsigned port, unsigned index, unsigned control, int16_t value)
{
if(!lsnes_instance.mlogic.get_movie().readonly_mode()) {
controller_frame f = lsnes_instance.mlogic.get_movie().get_controls();
if(!CORE().mlogic.get_movie().readonly_mode()) {
controller_frame f = CORE().mlogic.get_movie().get_controls();
f.axis3(port, index, control, value);
lsnes_instance.mlogic.get_movie().set_controls(f);
CORE().mlogic.get_movie().set_controls(f);
}
return lsnes_instance.mlogic.get_movie().next_input(port, index, control);
return CORE().mlogic.get_movie().next_input(port, index, control);
}
void notify_latch(std::list<std::string>& args)
@ -469,9 +469,9 @@ public:
void timer_tick(uint32_t increment, uint32_t per_second)
{
if(!lsnes_instance.mlogic)
if(!CORE().mlogic)
return;
auto& m = lsnes_instance.mlogic.get_mfile();
auto& m = CORE().mlogic.get_mfile();
m.rtc_subsecond += increment;
while(m.rtc_subsecond >= per_second) {
m.rtc_second++;
@ -481,7 +481,7 @@ public:
std::string get_firmware_path()
{
return lsnes_instance.setcache.get("firmwarepath");
return CORE().setcache.get("firmwarepath");
}
std::string get_base_path()
@ -491,7 +491,7 @@ public:
time_t get_time()
{
return lsnes_instance.mlogic ? lsnes_instance.mlogic.get_mfile().rtc_second : 0;
return CORE().mlogic ? CORE().mlogic.get_mfile().rtc_second : 0;
}
time_t get_randomseed()
@ -552,7 +552,7 @@ namespace
"Syntax: count-rerecords\nCounts rerecords.\n",
[]() throw(std::bad_alloc, std::runtime_error) {
std::vector<char> tmp;
uint64_t x = lsnes_instance.mlogic.get_rrdata().write(tmp);
uint64_t x = CORE().mlogic.get_rrdata().write(tmp);
messages << x << " rerecord(s)" << std::endl;
});
@ -836,7 +836,7 @@ namespace
"Syntax: set-rwmode\nSwitches to read/write mode\n",
[]() throw(std::bad_alloc, std::runtime_error) {
lua_callback_movie_lost("readwrite");
lsnes_instance.mlogic.get_movie().readonly_mode(false);
CORE().mlogic.get_movie().readonly_mode(false);
notify_mode_change(false);
lua_callback_do_readwrite();
update_movie_state();
@ -845,7 +845,7 @@ namespace
command::fnptr<> set_romode(lsnes_cmd, "set-romode", "Switch to read-only mode",
"Syntax: set-romode\nSwitches to read-only mode\n",
[]() throw(std::bad_alloc, std::runtime_error) {
lsnes_instance.mlogic.get_movie().readonly_mode(true);
CORE().mlogic.get_movie().readonly_mode(true);
notify_mode_change(true);
update_movie_state();
});
@ -853,10 +853,10 @@ namespace
command::fnptr<> toggle_rwmode(lsnes_cmd, "toggle-rwmode", "Toggle read/write mode",
"Syntax: toggle-rwmode\nToggles read/write mode\n",
[]() throw(std::bad_alloc, std::runtime_error) {
bool c = lsnes_instance.mlogic.get_movie().readonly_mode();
bool c = CORE().mlogic.get_movie().readonly_mode();
if(c)
lua_callback_movie_lost("readwrite");
lsnes_instance.mlogic.get_movie().readonly_mode(!c);
CORE().mlogic.get_movie().readonly_mode(!c);
notify_mode_change(!c);
if(c)
lua_callback_do_readwrite();
@ -1085,17 +1085,17 @@ namespace
//failing.
int handle_load()
{
std::string old_project = lsnes_instance.mlogic ? lsnes_instance.mlogic.get_mfile().projectid : "";
std::string old_project = CORE().mlogic ? CORE().mlogic.get_mfile().projectid : "";
jumpback:
if(do_unsafe_rewind && unsafe_rewind_obj) {
if(!lsnes_instance.mlogic)
if(!CORE().mlogic)
return 0;
uint64_t t = get_utime();
std::vector<char> s;
lua_callback_do_unsafe_rewind(s, 0, 0, lsnes_instance.mlogic.get_movie(), unsafe_rewind_obj);
lua_callback_do_unsafe_rewind(s, 0, 0, CORE().mlogic.get_movie(), unsafe_rewind_obj);
notify_mode_change(false);
do_unsafe_rewind = false;
lsnes_instance.mlogic.get_mfile().is_savestate = true;
CORE().mlogic.get_mfile().is_savestate = true;
location_special = SPECIAL_SAVEPOINT;
update_movie_state();
messages << "Rewind done in " << (get_utime() - t) << " usec." << std::endl;
@ -1161,7 +1161,7 @@ nothing_to_do:
if(amode == ADVANCE_LOAD)
goto jumpback;
}
if(old_project != (lsnes_instance.mlogic ? lsnes_instance.mlogic.get_mfile().projectid : ""))
if(old_project != (CORE().mlogic ? CORE().mlogic.get_mfile().projectid : ""))
flush_slotinfo(); //Wrong movie may be stale.
return 1;
}
@ -1171,7 +1171,7 @@ nothing_to_do:
//If there are pending saves, perform them.
void handle_saves()
{
if(!lsnes_instance.mlogic)
if(!CORE().mlogic)
return;
if(!queued_saves.empty() || (do_unsafe_rewind && !unsafe_rewind_obj)) {
our_rom.rtype->runtosave();
@ -1183,9 +1183,9 @@ nothing_to_do:
if(do_unsafe_rewind && !unsafe_rewind_obj) {
uint64_t t = get_utime();
std::vector<char> s = our_rom.save_core_state(true);
uint64_t secs = lsnes_instance.mlogic.get_mfile().rtc_second;
uint64_t ssecs = lsnes_instance.mlogic.get_mfile().rtc_subsecond;
lua_callback_do_unsafe_rewind(s, secs, ssecs, lsnes_instance.mlogic.get_movie(),
uint64_t secs = CORE().mlogic.get_mfile().rtc_second;
uint64_t ssecs = CORE().mlogic.get_mfile().rtc_subsecond;
lua_callback_do_unsafe_rewind(s, secs, ssecs, CORE().mlogic.get_movie(),
NULL);
do_unsafe_rewind = false;
messages << "Rewind point set in " << (get_utime() - t) << " usec." << std::endl;
@ -1222,7 +1222,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
dispatch_set_error_streams(&messages.getstream());
emulation_thread = threads::this_id();
jukebox_size_listener jlistener;
lsnes_instance.commentary.init();
CORE().commentary.init();
init_special_screens();
our_rom = rom;
init_main_callbacks();
@ -1237,7 +1237,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
do_load_state(initial, LOAD_STATE_INITIAL, used);
location_special = SPECIAL_SAVEPOINT;
update_movie_state();
first_round = lsnes_instance.mlogic.get_mfile().is_savestate;
first_round = CORE().mlogic.get_mfile().is_savestate;
just_did_loadstate = first_round;
} catch(std::bad_alloc& e) {
OOM_panic();
@ -1263,7 +1263,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
uint64_t time_x = get_utime();
while(amode != ADVANCE_QUIT || !queued_saves.empty()) {
if(handle_corrupt()) {
first_round = lsnes_instance.mlogic && lsnes_instance.mlogic.get_mfile().is_savestate;
first_round = CORE().mlogic && CORE().mlogic.get_mfile().is_savestate;
just_did_loadstate = first_round;
continue;
}
@ -1277,9 +1277,9 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
controls.advance_macros();
}
macro_hold_2 = false;
lsnes_instance.mlogic.get_movie().get_pollcounters().set_framepflag(false);
lsnes_instance.mlogic.new_frame_starting(amode == ADVANCE_SKIPLAG);
lsnes_instance.mlogic.get_movie().get_pollcounters().set_framepflag(true);
CORE().mlogic.get_movie().get_pollcounters().set_framepflag(false);
CORE().mlogic.new_frame_starting(amode == ADVANCE_SKIPLAG);
CORE().mlogic.get_movie().get_pollcounters().set_framepflag(true);
if(amode == ADVANCE_QUIT && queued_saves.empty())
break;
handle_saves();
@ -1287,9 +1287,9 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
if(queued_saves.empty())
r = handle_load();
if(r > 0 || system_corrupt) {
lsnes_instance.mlogic.get_movie().get_pollcounters().set_framepflag(
lsnes_instance.mlogic.get_mfile().is_savestate);
first_round = lsnes_instance.mlogic.get_mfile().is_savestate;
CORE().mlogic.get_movie().get_pollcounters().set_framepflag(
CORE().mlogic.get_mfile().is_savestate);
first_round = CORE().mlogic.get_mfile().is_savestate;
if(system_corrupt)
amode = ADVANCE_PAUSE;
else
@ -1297,7 +1297,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
stop_at_frame_active = false;
just_did_loadstate = first_round;
controls.reset_framehold();
debug_fire_callback_frame(lsnes_instance.mlogic.get_movie().get_current_frame(),
debug_fire_callback_frame(CORE().mlogic.get_movie().get_current_frame(),
true);
continue;
} else if(r < 0) {
@ -1315,12 +1315,12 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
platform::set_paused(amode == ADVANCE_PAUSE);
platform::flush_command_queue();
//We already have done the reset this frame if we are going to do one at all.
lsnes_instance.mlogic.get_movie().set_controls(lsnes_instance.mlogic.update_controls(true));
lsnes_instance.mlogic.get_movie().set_all_DRDY();
CORE().mlogic.get_movie().set_controls(CORE().mlogic.update_controls(true));
CORE().mlogic.get_movie().set_all_DRDY();
just_did_loadstate = false;
}
frame_irq_time = get_utime() - time_x;
debug_fire_callback_frame(lsnes_instance.mlogic.get_movie().get_current_frame(), false);
debug_fire_callback_frame(CORE().mlogic.get_movie().get_current_frame(), false);
our_rom.rtype->emulate();
random_mix_timing_entropy();
time_x = get_utime();
@ -1331,12 +1331,12 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
}
information_dispatch::do_dump_end();
core_core::uninstall_all_handlers();
lsnes_instance.commentary.kill();
CORE().commentary.kill();
platform::system_thread_available(false);
//Kill some things to avoid crashes.
debug_core_change();
project_set(NULL, true);
lsnes_instance.mwatch.clear_multi(lsnes_instance.mwatch.enumerate());
CORE().mwatch.clear_multi(CORE().mwatch.enumerate());
}
void set_stop_at_frame(uint64_t frame)

View file

@ -25,19 +25,19 @@ namespace
try {
if(offset >= 0 && offset < 8) {
//Frame counter.
uint64_t x = lsnes_instance.mlogic.get_movie().get_current_frame();
uint64_t x = CORE().mlogic.get_movie().get_current_frame();
return x >> (8 * (offset & 7));
} else if(offset >= 8 && offset < 16) {
//Movie length.
uint64_t x = lsnes_instance.mlogic.get_movie().get_frame_count();
uint64_t x = CORE().mlogic.get_movie().get_frame_count();
return x >> (8 * (offset & 7));
} else if(offset >= 16 && offset < 24) {
//Lag counter.
uint64_t x = lsnes_instance.mlogic.get_movie().get_lag_frames();
uint64_t x = CORE().mlogic.get_movie().get_lag_frames();
return x >> (8 * (offset & 7));
} else if(offset >= 24 && offset < 32) {
//Rerecord counter.
uint64_t x = lsnes_instance.mlogic.get_rrdata().count();
uint64_t x = CORE().mlogic.get_rrdata().count();
return x >> (8 * (offset & 7));
} else
return 0;
@ -90,7 +90,7 @@ void refresh_cart_mappings() throw(std::bad_alloc)
{
if(!our_rom.rtype)
return;
std::list<memory_region*> cur_regions = lsnes_instance.memory.get_regions();
std::list<memory_region*> cur_regions = CORE().memory.get_regions();
std::list<memory_region*> regions;
memory_region* tmp = NULL;
auto vmalist = our_rom.rtype->vma_list();
@ -108,7 +108,7 @@ void refresh_cart_mappings() throw(std::bad_alloc)
regions.push_back(tmp);
tmp = NULL;
}
lsnes_instance.memory.set_regions(regions);
CORE().memory.set_regions(regions);
} catch(...) {
if(tmp)
delete tmp;
@ -133,7 +133,7 @@ namespace
std::string vma = r[1];
std::string _offset = r[2];
uint64_t offset = parse_value<uint64_t>("0x" + _offset);
for(auto i : lsnes_instance.memory.get_regions())
for(auto i : CORE().memory.get_regions())
if(i->name == vma) {
if(offset >= i->size)
throw std::runtime_error("Offset out of range");
@ -146,7 +146,7 @@ namespace
std::string format_address(uint64_t addr)
{
for(auto i : lsnes_instance.memory.get_regions())
for(auto i : CORE().memory.get_regions())
if(i->base <= addr && i->base + i->size > addr) {
//Hit.
unsigned hcount = 1;
@ -232,13 +232,13 @@ namespace
std::ostringstream x;
if(hexd)
x << format_address(address) << " -> "
<< hex::to((lsnes_instance.memory.*_rfn)(address), true);
<< hex::to((CORE().memory.*_rfn)(address), true);
else if(sizeof(ret) > 1)
x << format_address(address) << " -> " << std::dec
<< (lsnes_instance.memory.*_rfn)(address);
<< (CORE().memory.*_rfn)(address);
else
x << format_address(address) << " -> " << std::dec
<< (int)(lsnes_instance.memory.*_rfn)(address);
<< (int)(CORE().memory.*_rfn)(address);
messages << x.str() << std::endl;
}
}
@ -267,7 +267,7 @@ namespace
int64_t value2 = static_cast<int64_t>(value);
if(value2 < low || (value > high && value2 >= 0))
throw std::runtime_error("Value to write out of range");
(lsnes_instance.memory.*_wfn)(address, value & high);
(CORE().memory.*_wfn)(address, value & high);
}
std::string get_short_help() throw(std::bad_alloc) { return "Write memory"; }
std::string get_long_help() throw(std::bad_alloc)
@ -291,7 +291,7 @@ namespace
{
if(address_bad || !has_valuef || has_tail)
throw std::runtime_error("Syntax: " + _command + " <address> <value>");
(lsnes_instance.memory.*_wfn)(address, valuef);
(CORE().memory.*_wfn)(address, valuef);
}
std::string get_short_help() throw(std::bad_alloc) { return "Write memory"; }
std::string get_long_help() throw(std::bad_alloc)

View file

@ -108,9 +108,9 @@ namespace
std::string text = r[4];
moviefile_subtiming key(frame, length);
if(text == "")
lsnes_instance.mlogic.get_mfile().subtitles.erase(key);
CORE().mlogic.get_mfile().subtitles.erase(key);
else
lsnes_instance.mlogic.get_mfile().subtitles[key] =
CORE().mlogic.get_mfile().subtitles[key] =
subtitle_commentary::s_unescape(text);
notify_subtitle_change();
redraw_framebuffer();
@ -119,8 +119,8 @@ namespace
command::fnptr<> list_subtitle(lsnes_cmd, "list-subtitle", "List the subtitles",
"Syntax: list-subtitle\nList the subtitles.\n",
[]() throw(std::bad_alloc, std::runtime_error) {
for(auto i = lsnes_instance.mlogic.get_mfile().subtitles.rbegin(); i !=
lsnes_instance.mlogic.get_mfile().subtitles.rend();
for(auto i = CORE().mlogic.get_mfile().subtitles.rbegin(); i !=
CORE().mlogic.get_mfile().subtitles.rend();
i++) {
messages << i->first.get_frame() << " " << i->first.get_length() << " "
<< subtitle_commentary::s_escape(i->second) << std::endl;
@ -130,9 +130,9 @@ namespace
command::fnptr<command::arg_filename> save_s(lsnes_cmd, "save-subtitle", "Save subtitles in .sub format",
"Syntax: save-subtitle <file>\nSaves subtitles in .sub format to <file>\n",
[](command::arg_filename args) throw(std::bad_alloc, std::runtime_error) {
if(lsnes_instance.mlogic.get_mfile().subtitles.empty())
if(CORE().mlogic.get_mfile().subtitles.empty())
return;
auto i = lsnes_instance.mlogic.get_mfile().subtitles.begin();
auto i = CORE().mlogic.get_mfile().subtitles.begin();
uint64_t lastframe = i->first.get_frame() + i->first.get_length();
std::ofstream y(std::string(args).c_str());
if(!y)
@ -141,8 +141,8 @@ namespace
uint64_t since = 0;
for(uint64_t i = 1; i < lastframe; i++) {
moviefile_subtiming posmarker(i);
auto j = lsnes_instance.mlogic.get_mfile().subtitles.upper_bound(posmarker);
if(j == lsnes_instance.mlogic.get_mfile().subtitles.end())
auto j = CORE().mlogic.get_mfile().subtitles.upper_bound(posmarker);
if(j == CORE().mlogic.get_mfile().subtitles.end())
continue;
if(lasttxt != j->second || !j->first.inrange(i)) {
if(lasttxt != "")

View file

@ -29,13 +29,13 @@ namespace
L.pushstring("disasm");
L.pushlstring(d->disassemble(laddr, [&bytes, laddr]() -> unsigned char {
return lsnes_instance.memory.read<uint8_t>(laddr + bytes++);
return CORE().memory.read<uint8_t>(laddr + bytes++);
}));
L.settable(-3);
std::vector<unsigned char> tmp;
tmp.resize(bytes);
lsnes_instance.memory.read_range(laddr, &tmp[0], bytes);
CORE().memory.read_range(laddr, &tmp[0], bytes);
L.pushstring("bytes");
L.pushlstring(hex::b_to(&tmp[0], bytes));
L.settable(-3);

View file

@ -13,7 +13,7 @@ namespace
P(address);
auto& h = lsnes_instance.mlogic.get_mfile().host_memory;
auto& h = CORE().mlogic.get_mfile().host_memory;
if(address + sizeof(S) > h.size()) {
L.pushboolean(0);
return 1;
@ -30,7 +30,7 @@ namespace
P(address, value);
auto& h = lsnes_instance.mlogic.get_mfile().host_memory;
auto& h = CORE().mlogic.get_mfile().host_memory;
if(address + sizeof(S) > h.size())
h.resize(address + sizeof(S));
serialization::write_endian<S>(&h[address], value, 1);

View file

@ -28,7 +28,7 @@ namespace
int input_controllertype(lua::state& L, unsigned port, unsigned controller)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
controller_frame f = m.read_subframe(m.get_current_frame(), 0);
if(port >= f.get_port_count()) {
L.pushnil();
@ -90,7 +90,7 @@ namespace
const port_controller_set* lookup_ps(unsigned port)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
controller_frame f = m.read_subframe(m.get_current_frame(), 0);
const port_type& p = f.get_port_type(port);
return p.controller_info;
@ -189,7 +189,7 @@ namespace
P(controller);
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
const port_type_set& s = m.read_subframe(m.get_current_frame(), 0).porttypes();
auto _controller = s.legacy_pcid_to_pair(controller);
return input_controllertype(L, _controller.first, _controller.second);
@ -373,7 +373,7 @@ namespace
P(port);
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
const port_type_set& s = m.read_subframe(m.get_current_frame(), 0).porttypes();
try {
const port_type& p = s.port_type(port);

View file

@ -98,7 +98,7 @@ namespace
int32_t get_pc_for(unsigned port, unsigned controller, unsigned button, bool extra0 = false);
int32_t get_pc_for(unsigned port, unsigned controller, unsigned button, bool extra0)
{
movie& m = lsnes_instance.mlogic.get_movie();
movie& m = CORE().mlogic.get_movie();
if(port == 0 && controller == 0 && button == 0)
return m.get_pollcounters().max_polls() + (extra0 ? 1 : 0);
if(port == 0 && controller == 0 && m.get_pollcounters().get_framepflag())
@ -112,17 +112,17 @@ namespace
void check_can_edit(unsigned port, unsigned controller, unsigned button, uint64_t frame,
bool allow_past_end)
{
movie& m = lsnes_instance.mlogic.get_movie();
movie& m = CORE().mlogic.get_movie();
if(!m.readonly_mode())
throw std::runtime_error("Not in read-only mode");
if(!allow_past_end && frame >= lsnes_instance.mlogic.get_mfile().input->size())
if(!allow_past_end && frame >= CORE().mlogic.get_mfile().input->size())
throw std::runtime_error("Index out of movie");
int32_t pc = get_pc_for(port, controller, button, true);
if(pc < 0)
throw std::runtime_error("Invalid control to edit");
uint64_t firstframe = m.get_current_frame_first_subframe();
uint64_t minframe = firstframe + pc;
uint64_t msize = lsnes_instance.mlogic.get_mfile().input->size();
uint64_t msize = CORE().mlogic.get_mfile().input->size();
if(minframe > msize || firstframe >= msize)
throw std::runtime_error("Can not edit finished movie");
if(frame < minframe)
@ -131,7 +131,7 @@ namespace
int current_first_subframe(lua::state& L, lua::parameters& P)
{
movie& m = lsnes_instance.mlogic.get_movie();
movie& m = CORE().mlogic.get_movie();
L.pushnumber(m.get_current_frame_first_subframe());
return 1;
}
@ -183,12 +183,12 @@ namespace
if(n >= v.size())
throw std::runtime_error("Requested frame outside movie");
//Checks if requested frame is from movie.
if(&v == lsnes_instance.mlogic.get_mfile().input)
if(&v == CORE().mlogic.get_mfile().input)
check_can_edit(0, 0, 0, n);
v[n] = f->get_frame();
if(&v == lsnes_instance.mlogic.get_mfile().input) {
if(&v == CORE().mlogic.get_mfile().input) {
//This can't add frames, so no need to adjust the movie.
update_movie_state();
platform::notify_status();
@ -244,7 +244,7 @@ namespace
for(uint64_t i = 0; i < count; i++)
v.append(v.blank_frame(true));
}
if(&v == lsnes_instance.mlogic.get_mfile().input) {
if(&v == CORE().mlogic.get_mfile().input) {
update_movie_state();
platform::notify_status();
}
@ -259,13 +259,13 @@ namespace
P(f);
v.append(v.blank_frame(true));
if(&v == lsnes_instance.mlogic.get_mfile().input) {
if(&v == CORE().mlogic.get_mfile().input) {
update_movie_state();
platform::notify_status();
check_can_edit(0, 0, 0, v.size() - 1);
}
v[v.size() - 1] = f->get_frame();
if(&v == lsnes_instance.mlogic.get_mfile().input) {
if(&v == CORE().mlogic.get_mfile().input) {
if(!v[v.size() - 1].sync()) {
update_movie_state();
}
@ -283,10 +283,10 @@ namespace
if(n > v.size())
throw std::runtime_error("Requested truncate length longer than existing");
if(&v == lsnes_instance.mlogic.get_mfile().input)
if(&v == CORE().mlogic.get_mfile().input)
check_can_edit(0, 0, 0, n);
v.resize(n);
if(&v == lsnes_instance.mlogic.get_mfile().input) {
if(&v == CORE().mlogic.get_mfile().input) {
update_movie_state();
platform::notify_status();
}
@ -306,11 +306,11 @@ namespace
else
P.expected("number or boolean");
if(&v == lsnes_instance.mlogic.get_mfile().input)
if(&v == CORE().mlogic.get_mfile().input)
check_can_edit(port, controller, button, frame);
v[frame].axis3(port, controller, button, value);
if(&v == lsnes_instance.mlogic.get_mfile().input) {
if(&v == CORE().mlogic.get_mfile().input) {
update_movie_state();
platform::notify_status();
}
@ -334,7 +334,7 @@ namespace
if(dst > dstv.size() || dst + count < dst)
throw std::runtime_error("Destination index out of movie");
if(&dstv == lsnes_instance.mlogic.get_mfile().input)
if(&dstv == CORE().mlogic.get_mfile().input)
check_can_edit(0, 0, 0, dst, true);
{
@ -346,7 +346,7 @@ namespace
for(uint64_t i = backwards ? (count - 1) : 0; i < count; i = backwards ? (i - 1) : (i + 1))
dstv[dst + i] = srcv[src + i];
}
if(&dstv == lsnes_instance.mlogic.get_mfile().input) {
if(&dstv == CORE().mlogic.get_mfile().input) {
update_movie_state();
platform::notify_status();
}
@ -583,32 +583,32 @@ namespace
int current_branch(lua::state& L, lua::parameters& P)
{
L.pushlstring(lsnes_instance.mlogic.get_mfile().current_branch());
L.pushlstring(CORE().mlogic.get_mfile().current_branch());
return 1;
}
int get_branches(lua::state& L, lua::parameters& P)
{
for(auto& i : lsnes_instance.mlogic.get_mfile().branches)
for(auto& i : CORE().mlogic.get_mfile().branches)
L.pushlstring(i.first);
return lsnes_instance.mlogic.get_mfile().branches.size();
return CORE().mlogic.get_mfile().branches.size();
}
controller_frame_vector& framevector(lua::state& L, lua::parameters& P)
{
if(P.is_nil()) {
P.skip();
return *lsnes_instance.mlogic.get_mfile().input;
return *CORE().mlogic.get_mfile().input;
} else if(P.is_string()) {
std::string x;
P(x);
if(!lsnes_instance.mlogic.get_mfile().branches.count(x))
if(!CORE().mlogic.get_mfile().branches.count(x))
throw std::runtime_error("No such branch");
return lsnes_instance.mlogic.get_mfile().branches[x];
return CORE().mlogic.get_mfile().branches[x];
} else if(P.is<lua_inputmovie>())
return *(P.arg<lua_inputmovie*>()->get_frame_vector());
else
return *lsnes_instance.mlogic.get_mfile().input;
return *CORE().mlogic.get_mfile().input;
}
lua::_class<lua_inputmovie> class_inputmovie(lua_class_movie, "INPUTMOVIE", {}, {

View file

@ -259,7 +259,7 @@ namespace
lua_renderq_run(ctx, synchronous_paint_ctx);
}
#define DEFINE_CB(X) lua::state::callback_list on_##X (lsnes_instance.lua, #X , "on_" #X )
#define DEFINE_CB(X) lua::state::callback_list on_##X (CORE().lua, #X , "on_" #X )
DEFINE_CB(paint);
DEFINE_CB(video);
@ -399,7 +399,7 @@ namespace
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
if(args == "")
throw std::runtime_error("Expected expression to evaluate");
do_eval_lua(lsnes_instance.lua, args);
do_eval_lua(CORE().lua, args);
});
command::fnptr<const std::string&> evaluate_lua2(lsnes_cmd, "L", "Evaluate expression in "
@ -407,25 +407,25 @@ namespace
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
if(args == "")
throw std::runtime_error("Expected expression to evaluate");
do_eval_lua(lsnes_instance.lua, args);
do_eval_lua(CORE().lua, args);
});
command::fnptr<command::arg_filename> run_lua(lsnes_cmd, "run-lua", "Run Lua script in Lua VM",
"Syntax: run-lua <file>\nRuns <file> in Lua VM.\n",
[](command::arg_filename args) throw(std::bad_alloc, std::runtime_error)
{
do_run_lua(lsnes_instance.lua, args);
do_run_lua(CORE().lua, args);
});
command::fnptr<> reset_lua(lsnes_cmd, "reset-lua", "Reset the Lua VM",
"Syntax: reset-lua\nReset the Lua VM.\n",
[]() throw(std::bad_alloc, std::runtime_error)
{
lsnes_instance.lua.reset();
luaL_openlibs(lsnes_instance.lua.handle());
CORE().lua.reset();
luaL_openlibs(CORE().lua.handle());
run_sysrc_lua(lsnes_instance.lua);
copy_system_tables(lsnes_instance.lua);
run_sysrc_lua(CORE().lua);
copy_system_tables(CORE().lua);
messages << "Lua VM reset" << std::endl;
});
@ -445,32 +445,32 @@ void lua_callback_keyhook(const std::string& key, keyboard::key& p) throw()
void init_lua() throw()
{
lsnes_instance.lua.set_oom_handler(OOM_panic);
CORE().lua.set_oom_handler(OOM_panic);
try {
lsnes_instance.lua.reset();
lsnes_instance.lua.add_function_group(lua_func_bit);
lsnes_instance.lua.add_function_group(lua_func_load);
lsnes_instance.lua.add_function_group(lua_func_misc);
lsnes_instance.lua.add_function_group(lua_func_zip);
lsnes_instance.lua.add_class_group(lua_class_callback);
lsnes_instance.lua.add_class_group(lua_class_gui);
lsnes_instance.lua.add_class_group(lua_class_bind);
lsnes_instance.lua.add_class_group(lua_class_pure);
lsnes_instance.lua.add_class_group(lua_class_movie);
lsnes_instance.lua.add_class_group(lua_class_memory);
lsnes_instance.lua.add_class_group(lua_class_fileio);
CORE().lua.reset();
CORE().lua.add_function_group(lua_func_bit);
CORE().lua.add_function_group(lua_func_load);
CORE().lua.add_function_group(lua_func_misc);
CORE().lua.add_function_group(lua_func_zip);
CORE().lua.add_class_group(lua_class_callback);
CORE().lua.add_class_group(lua_class_gui);
CORE().lua.add_class_group(lua_class_bind);
CORE().lua.add_class_group(lua_class_pure);
CORE().lua.add_class_group(lua_class_movie);
CORE().lua.add_class_group(lua_class_memory);
CORE().lua.add_class_group(lua_class_fileio);
} catch(std::exception& e) {
messages << "Can't initialize Lua." << std::endl;
fatal_error();
}
luaL_openlibs(lsnes_instance.lua.handle());
run_sysrc_lua(lsnes_instance.lua);
copy_system_tables(lsnes_instance.lua);
luaL_openlibs(CORE().lua.handle());
run_sysrc_lua(CORE().lua);
copy_system_tables(CORE().lua);
}
void quit_lua() throw()
{
lsnes_instance.lua.deinit();
CORE().lua.deinit();
}
@ -498,7 +498,7 @@ void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs,
run_callback(on_movie_lost, "unsaferewind");
mainloop_restore_state(u2->state, u2->secs, u2->ssecs);
mov.fast_load(u2->frame, u2->ptr, u2->lag, u2->pollcounters);
try { lsnes_instance.mlogic.get_mfile().host_memory = u2->hostmemory; } catch(...) {}
try { CORE().mlogic.get_mfile().host_memory = u2->hostmemory; } catch(...) {}
run_callback(on_post_rewind);
delete reinterpret_cast<lua::objpin<lua_unsaferewind>*>(u);
} catch(...) {
@ -507,11 +507,11 @@ void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs,
} else {
//Save
run_callback(on_set_rewind, lua::state::fn_tag([save, secs, ssecs, &mov](lua::state& L) -> int {
lua_unsaferewind* u2 = lua::_class<lua_unsaferewind>::create(lsnes_instance.lua);
lua_unsaferewind* u2 = lua::_class<lua_unsaferewind>::create(CORE().lua);
u2->state = save;
u2->secs = secs,
u2->ssecs = ssecs;
u2->hostmemory = lsnes_instance.mlogic.get_mfile().host_memory;
u2->hostmemory = CORE().mlogic.get_mfile().host_memory;
mov.fast_save(u2->frame, u2->ptr, u2->lag, u2->pollcounters);
return 1;
}));
@ -539,7 +539,7 @@ void lua_run_startup_scripts()
{
for(auto i : startup_scripts) {
messages << "Trying to run Lua script: " << i << std::endl;
do_run_lua(lsnes_instance.lua, i);
do_run_lua(CORE().lua, i);
}
}

View file

@ -79,7 +79,7 @@ namespace
int compare_obj::call(lua::state& L, lua::parameters& P)
{
bool equals = true;
char* pbuffer = try_map ? lsnes_instance.memory.get_physical_mapping(minaddr, maxaddr - minaddr + 1) :
char* pbuffer = try_map ? CORE().memory.get_physical_mapping(minaddr, maxaddr - minaddr + 1) :
NULL;
if(pbuffer) {
//Mapable.
@ -97,7 +97,7 @@ namespace
uint64_t addr1 = addr + i * stride;
uint64_t addr2 = i * size;
for(uint64_t j = 0; j < size; j++) {
uint8_t byte = lsnes_instance.memory.read<uint8_t>(addr1 + j);
uint8_t byte = CORE().memory.read<uint8_t>(addr1 + j);
bool eq = prev[addr2 + j] == (char)byte;
if(!eq)
prev[addr2 + j] = byte;

View file

@ -16,7 +16,7 @@
uint64_t lua_get_vmabase(const std::string& vma)
{
for(auto i : lsnes_instance.memory.get_regions())
for(auto i : CORE().memory.get_regions())
if(i->name == vma)
return i->base;
throw std::runtime_error("No such VMA");
@ -46,16 +46,16 @@ namespace
{
if(wrflag) {
T value = L.get_numeric_argument<T>(3, "aperture(write)");
(lsnes_instance.memory.*wfun)(addr, value);
(CORE().memory.*wfun)(addr, value);
} else
L.pushnumber(static_cast<T>((lsnes_instance.memory.*rfun)(addr)));
L.pushnumber(static_cast<T>((CORE().memory.*rfun)(addr)));
}
template<typename T, T (memory_space::*rfun)(uint64_t addr)>
int lua_read_memory(lua::state& L, lua::parameters& P)
{
auto addr = lua_get_read_address(P);
L.pushnumber(static_cast<T>((lsnes_instance.memory.*rfun)(addr)));
L.pushnumber(static_cast<T>((CORE().memory.*rfun)(addr)));
return 1;
}
@ -64,7 +64,7 @@ namespace
{
auto addr = lua_get_read_address(P);
T value = P.arg<T>();
(lsnes_instance.memory.*wfun)(addr, value);
(CORE().memory.*wfun)(addr, value);
return 0;
}
}
@ -150,7 +150,7 @@ namespace
return 1;
}
addr += base;
L.pushnumber(static_cast<T>((lsnes_instance.memory.*rfun)(addr)));
L.pushnumber(static_cast<T>((CORE().memory.*rfun)(addr)));
return 1;
}
@ -169,7 +169,7 @@ namespace
return 0;
addr += base;
T value = L.get_numeric_argument<T>(3, "aperture(write)");
(lsnes_instance.memory.*wfun)(addr, value);
(CORE().memory.*wfun)(addr, value);
return 0;
}
@ -449,9 +449,9 @@ namespace
if(!have_vmabase && L.do_once(&deprecation))
messages << P.get_fname() << ": Global memory form is deprecated." << std::endl;
if(write)
lsnes_instance.memory.write<uint8_t>(addr + vmabase, val >> shift);
CORE().memory.write<uint8_t>(addr + vmabase, val >> shift);
else
val = val + ((uint64_t)lsnes_instance.memory.read<uint8_t>(addr + vmabase) << shift);
val = val + ((uint64_t)CORE().memory.read<uint8_t>(addr + vmabase) << shift);
shift += 8;
}
if(!write) {
@ -466,7 +466,7 @@ namespace
int vma_count(lua::state& L, lua::parameters& P)
{
L.pushnumber(lsnes_instance.memory.get_regions().size());
L.pushnumber(CORE().memory.get_regions().size());
return 1;
}
@ -498,7 +498,7 @@ namespace
P(num);
std::list<memory_region*> regions = lsnes_instance.memory.get_regions();
std::list<memory_region*> regions = CORE().memory.get_regions();
uint32_t j = 0;
for(auto i = regions.begin(); i != regions.end(); i++, j++)
if(j == num)
@ -513,7 +513,7 @@ namespace
P(addr);
auto r = lsnes_instance.memory.lookup(addr);
auto r = CORE().memory.lookup(addr);
if(r.first)
return handle_push_vma(L, *r.first);
L.pushnil();
@ -550,7 +550,7 @@ namespace
if(low > high || high - low + 1 == 0)
mappable = false;
char* pbuffer = mappable ? lsnes_instance.memory.get_physical_mapping(low, high - low + 1) : NULL;
char* pbuffer = mappable ? CORE().memory.get_physical_mapping(low, high - low + 1) : NULL;
if(low > high) {
} else if(pbuffer) {
uint64_t offset = addr - low;
@ -565,7 +565,7 @@ namespace
while(sz > 0) {
size_t ssz = min(sz, static_cast<size_t>(BLOCKSIZE));
for(size_t i = 0; i < ssz; i++)
buffer[i] = lsnes_instance.memory.read<uint8_t>(offset + i);
buffer[i] = CORE().memory.read<uint8_t>(offset + i);
offset += ssz;
sz -= ssz;
update(state, buffer, ssz);
@ -633,13 +633,13 @@ namespace
if((size_t)(daddr + rows * size) < daddr)
throw std::runtime_error("Size to copy too large");
auto& h = lsnes_instance.mlogic.get_mfile().host_memory;
auto& h = CORE().mlogic.get_mfile().host_memory;
if(daddr + rows * size > h.size()) {
equals = false;
h.resize(daddr + rows * size);
}
char* pbuffer = mappable ? lsnes_instance.memory.get_physical_mapping(low, high - low + 1) : NULL;
char* pbuffer = mappable ? CORE().memory.get_physical_mapping(low, high - low + 1) : NULL;
if(!size && !rows) {
} else if(pbuffer) {
//Mapable.
@ -657,7 +657,7 @@ namespace
uint64_t addr1 = addr + i * stride;
uint64_t addr2 = daddr + i * size;
for(uint64_t j = 0; j < size; j++) {
uint8_t byte = lsnes_instance.memory.read<uint8_t>(addr1 + j);
uint8_t byte = CORE().memory.read<uint8_t>(addr1 + j);
bool eq = (cmp && h[addr2 + j] == (char)byte);
if(!eq)
h[addr2 + j] = byte;
@ -682,7 +682,7 @@ namespace
uint64_t ctr = 0;
while(size > 0) {
size_t rsize = min(size, static_cast<uint64_t>(BLOCKSIZE));
lsnes_instance.memory.read_range(addr, buffer, rsize);
CORE().memory.read_range(addr, buffer, rsize);
for(size_t i = 0; i < rsize; i++) {
L.pushnumber(ctr++);
L.pushnumber(static_cast<unsigned char>(buffer[i]));
@ -712,7 +712,7 @@ namespace
buffer[i] = L.tointeger(-1);
L.pop(1);
}
lsnes_instance.memory.write_range(addr, buffer, rsize);
CORE().memory.write_range(addr, buffer, rsize);
addr += rsize;
size -= rsize;
}

View file

@ -185,7 +185,7 @@ namespace
int lua_vma::info(lua::state& L, lua::parameters& P)
{
for(auto i : lsnes_instance.memory.get_regions())
for(auto i : CORE().memory.get_regions())
if(i->name == vma)
return handle_push_vma(L, *i);
(stringfmt() << P.get_fname() << ": Stale region").throwex();
@ -203,7 +203,7 @@ namespace
throw std::runtime_error("VMA::rw<T>: Address outside VMA bounds");
if(P.is_novalue()) {
//Read.
T val = lsnes_instance.memory.read<T>(addr + vmabase);
T val = CORE().memory.read<T>(addr + vmabase);
if(_bswap) val = bswap(val);
L.pushnumber(val);
return 1;
@ -213,7 +213,7 @@ namespace
(stringfmt() << P.get_fname() << ": VMA is read-only").throwex();
P(val);
if(_bswap) val = bswap(val);
lsnes_instance.memory.write<T>(addr + vmabase, val);
CORE().memory.write<T>(addr + vmabase, val);
return 0;
} else
P.expected("number or nil");
@ -239,9 +239,9 @@ namespace
} else
addr = P.arg<uint64_t>();
if(write)
lsnes_instance.memory.write<uint8_t>(addr + vmabase, val >> shift);
CORE().memory.write<uint8_t>(addr + vmabase, val >> shift);
else
val = val + ((uint64_t)lsnes_instance.memory.read<uint8_t>(addr + vmabase) << shift);
val = val + ((uint64_t)CORE().memory.read<uint8_t>(addr + vmabase) << shift);
shift += 8;
}
if(!write) {
@ -265,7 +265,7 @@ namespace
auto hstate = T::create();
//Try to map the VMA.
char* vmabuf = lsnes_instance.memory.get_physical_mapping(vmabase, vmasize);
char* vmabuf = CORE().memory.get_physical_mapping(vmabase, vmasize);
if(vmabuf) {
for(uint64_t i = 0; i < rows; i++) {
T::write(hstate, vmabuf + addr, size);
@ -276,7 +276,7 @@ namespace
unsigned bf = 0;
for(uint64_t i = 0; i < rows; i++) {
for(uint64_t j = 0; j < size; j++) {
buf[bf] = lsnes_instance.memory.read<uint8_t>(vmabase + addr + j);
buf[bf] = CORE().memory.read<uint8_t>(vmabase + addr + j);
bf = (bf + 1) & (sizeof(buf) - 1);
if(!bf)
T::write(hstate, buf, sizeof(buf));
@ -300,7 +300,7 @@ namespace
throw std::runtime_error("Read out of range");
L.newtable();
char* vmabuf = lsnes_instance.memory.get_physical_mapping(vmabase, vmasize);
char* vmabuf = CORE().memory.get_physical_mapping(vmabase, vmasize);
if(vmabuf) {
uint64_t ctr = 1;
for(size_t i = 0; i < size; i++) {
@ -312,7 +312,7 @@ namespace
uint64_t ctr = 1;
for(size_t i = 0; i < size; i++) {
L.pushnumber(ctr++);
L.pushnumber(lsnes_instance.memory.read<uint8_t>(addr + i));
L.pushnumber(CORE().memory.read<uint8_t>(addr + i));
L.settable(-3);
}
}
@ -326,14 +326,14 @@ namespace
P(P.skipped(), addr, P.table(ltbl));
auto g = lsnes_instance.memory.lookup(vmabase);
auto g = CORE().memory.lookup(vmabase);
if(!g.first || g.first->readonly)
throw std::runtime_error("Memory address is read-only");
if(addr >= vmasize)
throw std::runtime_error("Write out of range");
uint64_t ctr = 1;
char* vmabuf = lsnes_instance.memory.get_physical_mapping(vmabase, vmasize);
char* vmabuf = CORE().memory.get_physical_mapping(vmabase, vmasize);
if(vmabuf) {
for(size_t i = 0;; i++) {
L.pushnumber(ctr++);
@ -353,7 +353,7 @@ namespace
break;
if(addr + i >= vmasize)
throw std::runtime_error("Write out of range");
lsnes_instance.memory.write<uint8_t>(vmabase + addr + i, L.tointeger(-1));
CORE().memory.write<uint8_t>(vmabase + addr + i, L.tointeger(-1));
L.pop(1);
}
}
@ -373,7 +373,7 @@ namespace
throw std::runtime_error("Source out of range");
//Calculate new size of target.
auto& h = lsnes_instance.mlogic.get_mfile().host_memory;
auto& h = CORE().mlogic.get_mfile().host_memory;
size_t rsize = size * rows;
if(size && rsize / size != rows)
throw std::runtime_error("Copy size out of range");
@ -385,7 +385,7 @@ namespace
}
//Try to map the VMA.
char* vmabuf = lsnes_instance.memory.get_physical_mapping(vmabase, vmasize);
char* vmabuf = CORE().memory.get_physical_mapping(vmabase, vmasize);
if(vmabuf) {
for(uint64_t i = 0; i < rows; i++) {
bool eq = (cmp && !memcmp(&h[daddr], vmabuf + addr, size));
@ -398,7 +398,7 @@ namespace
} else {
for(uint64_t i = 0; i < rows; i++) {
for(uint64_t j = 0; j < size; j++) {
uint8_t byte = lsnes_instance.memory.read<uint8_t>(vmabase + addr + j);
uint8_t byte = CORE().memory.read<uint8_t>(vmabase + addr + j);
bool eq = (cmp && ((uint8_t)h[daddr + j] == byte));
h[daddr + j] = byte;
equals &= eq;
@ -457,7 +457,7 @@ namespace
{
L.newtable();
size_t key = 1;
for(auto i : lsnes_instance.memory.get_regions()) {
for(auto i : CORE().memory.get_regions()) {
L.pushnumber(key++);
L.pushlstring(i->name);
L.rawset(-3);
@ -471,7 +471,7 @@ namespace
P(P.skipped(), vma);
auto l = lsnes_instance.memory.get_regions();
auto l = CORE().memory.get_regions();
size_t j;
std::list<memory_region*>::iterator i;
for(i = l.begin(), j = 0; i != l.end(); i++, j++)

View file

@ -8,41 +8,41 @@ namespace
{
int currentframe(lua::state& L, lua::parameters& P)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
L.pushnumber(m.get_current_frame());
return 1;
}
int lagcounter(lua::state& L, lua::parameters& P)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
L.pushnumber(m.get_lag_frames());
return 1;
}
int framecount(lua::state& L, lua::parameters& P)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
L.pushnumber(m.get_frame_count());
return 1;
}
int rerecords(lua::state& L, lua::parameters& P)
{
L.pushnumber(lsnes_instance.mlogic.get_rrdata().count());
L.pushnumber(CORE().mlogic.get_rrdata().count());
return 1;
}
int readonly(lua::state& L, lua::parameters& P)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
L.pushboolean(m.readonly_mode() ? 1 : 0);
return 1;
}
int readwrite(lua::state& L, lua::parameters& P)
{
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
m.readonly_mode(false);
return 0;
}
@ -53,7 +53,7 @@ namespace
P(frame);
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
L.pushnumber(m.frame_subframes(frame));
return 1;
}
@ -64,7 +64,7 @@ namespace
P(frame, subframe);
auto& m = lsnes_instance.mlogic.get_movie();
auto& m = CORE().mlogic.get_movie();
controller_frame r = m.read_subframe(frame, subframe);
L.newtable();
@ -78,8 +78,8 @@ namespace
int read_rtc(lua::state& L, lua::parameters& P)
{
L.pushnumber(lsnes_instance.mlogic.get_mfile().rtc_second);
L.pushnumber(lsnes_instance.mlogic.get_mfile().rtc_subsecond);
L.pushnumber(CORE().mlogic.get_mfile().rtc_second);
L.pushnumber(CORE().mlogic.get_mfile().rtc_subsecond);
return 2;
}

View file

@ -10,7 +10,7 @@ namespace
P(name, value);
try {
lsnes_instance.setcache.set(name, value);
CORE().setcache.set(name, value);
} catch(std::exception& e) {
L.pushnil();
L.pushstring(e.what());
@ -27,7 +27,7 @@ namespace
P(name);
try {
std::string value = lsnes_instance.setcache.get(name);
std::string value = CORE().setcache.get(name);
L.pushlstring(value.c_str(), value.length());
return 1;
} catch(std::exception& e) {

View file

@ -7,7 +7,7 @@ namespace
{
auto n = P.arg<uint64_t>();
uint64_t j = 0;
for(auto i : lsnes_instance.subtitles.get_all()) {
for(auto i : CORE().subtitles.get_all()) {
if(j == n) {
L.pushnumber(i.first);
L.pushnumber(i.second);
@ -22,7 +22,7 @@ namespace
{
auto frame = P.arg<uint64_t>();
auto length = P.arg<uint64_t>();
std::string x = lsnes_instance.subtitles.get(frame, length);
std::string x = CORE().subtitles.get(frame, length);
L.pushstring(x.c_str());
return 1;
}
@ -32,7 +32,7 @@ namespace
auto frame = P.arg<uint64_t>();
auto length = P.arg<uint64_t>();
std::string text = P.arg<std::string>();
lsnes_instance.subtitles.set(frame, length, text);
CORE().subtitles.set(frame, length, text);
return 0;
}
@ -40,7 +40,7 @@ namespace
{
auto frame = P.arg<uint64_t>();
auto length = P.arg<uint64_t>();
lsnes_instance.subtitles.set(frame, length, "");
CORE().subtitles.set(frame, length, "");
return 0;
}