Since window is singleton anyway, get rid of window* parameters

This commit is contained in:
Ilari Liusvaara 2011-09-17 01:05:41 +03:00
parent d38da1b04b
commit 35d1875b44
38 changed files with 476 additions and 554 deletions

View file

@ -2,6 +2,7 @@
#include "avidump.hpp"
#include "sox.hpp"
#include "settings.hpp"
#include "window.hpp"
#include <iomanip>
#include <cassert>
#include <cstring>
@ -106,7 +107,7 @@ namespace
{
public:
dump_video_command() throw(std::bad_alloc) : command("dump-avi") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
std::string level = t;
@ -139,7 +140,7 @@ namespace
x << "Error starting dump: " << e.what();
throw std::runtime_error(x.str());
}
out(win) << "Dumping to " << prefix << " at level " << level2 << std::endl;
window::out() << "Dumping to " << prefix << " at level " << level2 << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Start AVI capture"; }
std::string get_long_help() throw(std::bad_alloc)
@ -154,7 +155,7 @@ namespace
{
public:
end_video_command() throw(std::bad_alloc) : command("end-avi") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
@ -162,11 +163,11 @@ namespace
throw std::runtime_error("No video dump in progress");
try {
vid_dumper->end();
out(win) << "Dump finished" << std::endl;
window::out() << "Dump finished" << std::endl;
} catch(std::bad_alloc& e) {
throw;
} catch(std::exception& e) {
out(win) << "Error ending dump: " << e.what() << std::endl;
window::out() << "Error ending dump: " << e.what() << std::endl;
}
delete vid_dumper;
vid_dumper = NULL;

View file

@ -1,5 +1,6 @@
#include "avsnoop.hpp"
#include "misc.hpp"
#include "window.hpp"
namespace
{
@ -34,7 +35,7 @@ av_snooper::~av_snooper() throw()
(*i)->dump_ending();
}
void av_snooper::frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, std::ostream& os) throw(std::bad_alloc)
void av_snooper::frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, bool dummy) throw(std::bad_alloc)
{
if(!snoopers)
return;
@ -45,13 +46,13 @@ void av_snooper::frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d,
throw;
} catch(std::exception& e) {
try {
os << "Error dumping frame: " << e.what() << std::endl;
window::out() << "Error dumping frame: " << e.what() << std::endl;
} catch(...) {
}
}
}
void av_snooper::sample(short l, short r, std::ostream& os) throw(std::bad_alloc)
void av_snooper::sample(short l, short r, bool dummy) throw(std::bad_alloc)
{
if(!snoopers)
return;
@ -62,13 +63,13 @@ void av_snooper::sample(short l, short r, std::ostream& os) throw(std::bad_alloc
throw;
} catch(std::exception& e) {
try {
os << "Error dumping sample: " << e.what() << std::endl;
window::out() << "Error dumping sample: " << e.what() << std::endl;
} catch(...) {
}
}
}
void av_snooper::end(std::ostream& os) throw(std::bad_alloc)
void av_snooper::end(bool dummy) throw(std::bad_alloc)
{
if(!snoopers)
return;
@ -79,14 +80,14 @@ void av_snooper::end(std::ostream& os) throw(std::bad_alloc)
throw;
} catch(std::exception& e) {
try {
os << "Error ending dump: " << e.what() << std::endl;
window::out() << "Error ending dump: " << e.what() << std::endl;
} catch(...) {
}
}
}
void av_snooper::gameinfo(const std::string& gamename, const std::list<std::pair<std::string, std::string>>&
authors, double gametime, const std::string& rerecords, std::ostream& os) throw(std::bad_alloc)
authors, double gametime, const std::string& rerecords, bool dummy) throw(std::bad_alloc)
{
if(!snoopers)
return;

View file

@ -4,7 +4,6 @@
#include "render.hpp"
#include <list>
#include <string>
#include <iostream>
#include <stdexcept>
/**
@ -43,10 +42,9 @@ public:
* parameter _frame: The frame to dump.
* parameter fps_n: Current fps numerator.
* parameter fps_d: Current fps denomerator.
* parameter os: Print messages here
* throws std::bad_alloc: Not enough memory.
*/
static void frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, std::ostream& os)
static void frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, bool dummy)
throw(std::bad_alloc);
/**
@ -64,10 +62,9 @@ public:
*
* parameter l: Left channel sample.
* parameter r: Right channel sample.
* parameter os: Print messages here
* throws std::bad_alloc: Not enough memory.
*/
static void sample(short l, short r, std::ostream& os) throw(std::bad_alloc);
static void sample(short l, short r, bool dummy) throw(std::bad_alloc);
/**
* End dump.
@ -80,10 +77,9 @@ public:
/**
* End dump.
*
* parameter os: Print messages here.
* throws std::bad_alloc: Not enough memory.
*/
static void end(std::ostream& os) throw(std::bad_alloc);
static void end(bool dummy) throw(std::bad_alloc);
/**
* Notify game information.
@ -105,11 +101,10 @@ public:
* parameter authors: Authors of the run.
* parameter gametime: Game time.
* parameter rercords: Rerecord count.
* parameter os: Print messages here
* throws std::bad_alloc Not enough memory.
*/
static void gameinfo(const std::string& gamename, const std::list<std::pair<std::string, std::string>>&
authors, double gametime, const std::string& rerecords, std::ostream& os) throw(std::bad_alloc);
authors, double gametime, const std::string& rerecords, bool dummy) throw(std::bad_alloc);
/**
* Send game info. This causes gameinfo method to be called on object this method is called on.

View file

@ -13,16 +13,16 @@ namespace
function_ptr_command run_script("run-script", "run file as a script",
"Syntax: run-script <file>\nRuns file <file> just as it would have been entered in the command line\n",
[](const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error) {
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
if(args == "")
throw std::runtime_error("Filename needed");
std::istream* o = NULL;
try {
o = &open_file_relative(args, "");
out(win) << "Running '" << args << "'" << std::endl;
window::out() << "Running '" << args << "'" << std::endl;
std::string line;
while(std::getline(*o, line))
command::invokeC(line, win);
command::invokeC(line);
delete o;
} catch(std::exception& e) {
if(o)
@ -33,17 +33,17 @@ namespace
function_ptr_command show_aliases("show-aliases", "show aliases",
"Syntax: show-aliases\nShow expansions of all aliases\n",
[](const std::string& args, std::ostream& os) throw(std::bad_alloc, std::runtime_error) {
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
if(args != "")
throw std::runtime_error("This command does not take parameters");
for(auto i = aliases.begin(); i != aliases.end(); i++)
for(auto j = i->second.begin(); j != i->second.end(); j++)
os << "alias " << i->first << " " << *j << std::endl;
window::out() << "alias " << i->first << " " << *j << std::endl;
});
function_ptr_command unalias_command("unalias-command", "unalias a command",
"Syntax: unalias-command <aliasname>\nClear expansion of alias <aliasname>\n",
[](const std::string& args, std::ostream& os) throw(std::bad_alloc, std::runtime_error) {
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
tokensplitter t(args);
std::string aliasname = t;
if(t)
@ -51,13 +51,13 @@ namespace
if(aliasname.length() == 0 || aliasname[0] == '?' || aliasname[0] == '*')
throw std::runtime_error("Illegal alias name");
aliases[aliasname].clear();
os << "Command '" << aliasname << "' unaliased" << std::endl;
window::out() << "Command '" << aliasname << "' unaliased" << std::endl;
});
function_ptr_command alias_command("alias-command", "alias a command",
"Syntax: alias-command <aliasname> <command>\nAppend <command> to expansion of alias <aliasname>\n"
"Valid alias names can't be empty nor start with '*' or '?'\n",
[](const std::string& args, std::ostream& os) throw(std::bad_alloc, std::runtime_error) {
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
tokensplitter t(args);
std::string aliasname = t;
std::string command = t.tail();
@ -66,7 +66,7 @@ namespace
if(aliasname.length() == 0 || aliasname[0] == '?' || aliasname[0] == '*')
throw std::runtime_error("Illegal alias name");
aliases[aliasname].push_back(command);
os << "Command '" << aliasname << "' aliased to '" << command << "'" << std::endl;
window::out() << "Command '" << aliasname << "' aliased to '" << command << "'" << std::endl;
});
}
@ -86,11 +86,11 @@ command::~command() throw()
commands->erase(commandname);
}
void command::invokeC(const std::string& cmd, window* win) throw()
void command::invokeC(const std::string& cmd) throw()
{
try {
if(command_stack.count(cmd)) {
out(win) << "Can not invoke recursively: " << cmd << std::endl;
window::out() << "Can not invoke recursively: " << cmd << std::endl;
return;
}
command_stack.insert(cmd);
@ -99,7 +99,7 @@ void command::invokeC(const std::string& cmd, window* win) throw()
//The special ? command.
if(commands) {
for(auto i = commands->begin(); i != commands->end(); ++i)
out(win) << i->first << ": " << i->second->get_short_help() << std::endl;
window::out() << i->first << ": " << i->second->get_short_help() << std::endl;
}
command_stack.erase(cmd);
return;
@ -117,10 +117,10 @@ void command::invokeC(const std::string& cmd, window* win) throw()
std::string aname = cmd2.substr(1);
if(aliases.count(aname)) {
//Yup.
out(win) << aname << " is an alias for: " << std::endl;
window::out() << aname << " is an alias for: " << std::endl;
size_t j = 0;
for(auto i = aliases[aname].begin(); i != aliases[aname].end(); ++i, ++j)
out(win) << "#" + (j + 1) << ": " << *i << std::endl;
window::out() << "#" + (j + 1) << ": " << *i << std::endl;
command_stack.erase(cmd);
return;
}
@ -129,11 +129,11 @@ void command::invokeC(const std::string& cmd, window* win) throw()
rcmd = rcmd.substr(1);
if(!commands || !commands->count(rcmd)) {
if(rcmd != "")
out(win) << "Unknown command '" << rcmd << "'" << std::endl;
window::out() << "Unknown command '" << rcmd << "'" << std::endl;
command_stack.erase(cmd);
return;
}
out(win) << (*commands)[rcmd]->get_long_help() << std::endl;
window::out() << (*commands)[rcmd]->get_long_help() << std::endl;
command_stack.erase(cmd);
return;
}
@ -144,7 +144,7 @@ void command::invokeC(const std::string& cmd, window* win) throw()
}
if(may_be_alias_expanded && aliases.count(cmd2)) {
for(auto i = aliases[cmd2].begin(); i != aliases[cmd2].end(); ++i)
invokeC(*i, win);
invokeC(*i);
command_stack.erase(cmd);
return;
}
@ -163,22 +163,22 @@ void command::invokeC(const std::string& cmd, window* win) throw()
if(commands && commands->count(rcmd))
cmdh = (*commands)[rcmd];
if(!cmdh) {
out(win) << "Unknown command '" << rcmd << "'" << std::endl;
window::out() << "Unknown command '" << rcmd << "'" << std::endl;
command_stack.erase(cmd);
return;
}
cmdh->invoke(args, win);
cmdh->invoke(args);
command_stack.erase(cmd);
return;
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
out(win) << "Error: " << e.what() << std::endl;
window::out() << "Error: " << e.what() << std::endl;
command_stack.erase(cmd);
return;
}
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
}
}
@ -224,31 +224,17 @@ std::string tokensplitter::tail() throw(std::bad_alloc)
}
function_ptr_command::function_ptr_command(const std::string& name, const std::string& _description,
const std::string& _help, void (*_fn)(const std::string& arguments, window* win)) throw(std::bad_alloc)
const std::string& _help, void (*_fn)(const std::string& arguments)) throw(std::bad_alloc)
: command(name)
{
description = _description;
help = _help;
fn = _fn;
fn2 = NULL;
}
function_ptr_command::function_ptr_command(const std::string& name, const std::string& _description,
const std::string& _help, void (*_fn)(const std::string& arguments, std::ostream& win)) throw(std::bad_alloc)
: command(name)
void function_ptr_command::invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
description = _description;
help = _help;
fn = NULL;
fn2 = _fn;
}
void function_ptr_command::invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
if(fn)
fn(args, win);
else if(fn2)
fn2(args, out(win));
fn(args);
}
std::string function_ptr_command::get_short_help() throw(std::bad_alloc)
@ -263,4 +249,4 @@ std::string function_ptr_command::get_long_help() throw(std::bad_alloc)
function_ptr_command::~function_ptr_command() throw()
{
}
}

View file

@ -5,8 +5,6 @@
#include <string>
class window;
/**
* A command.
*/
@ -30,19 +28,17 @@ public:
* Invoke a command.
*
* parameter arguments: Arguments to command.
* parameter window: Handle to graphics system.
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Command execution failed.
*/
virtual void invoke(const std::string& arguments, window* win) throw(std::bad_alloc, std::runtime_error) = 0;
virtual void invoke(const std::string& arguments) throw(std::bad_alloc, std::runtime_error) = 0;
/**
* Look up and invoke a command. The command will undergo alias expansion and recursion checking.
*
* parameter cmd: Command to exeucte.
* parameter window: Handle to graphics system.
*/
static void invokeC(const std::string& cmd, window* win) throw();
static void invokeC(const std::string& cmd) throw();
/**
* Get short help for command.
@ -113,17 +109,7 @@ public:
* parameter fn: Function to call on command.
*/
function_ptr_command(const std::string& name, const std::string& description, const std::string& help,
void (*fn)(const std::string& arguments, window* win)) throw(std::bad_alloc);
/**
* Create a new command.
*
* parameter name: Name of the command
* parameter description Description for the command
* parameter help: Help for the command.
* parameter fn: Function to call on command.
*/
function_ptr_command(const std::string& name, const std::string& description, const std::string& help,
void (*fn)(const std::string& arguments, std::ostream& os)) throw(std::bad_alloc);
void (*fn)(const std::string& arguments)) throw(std::bad_alloc);
/**
* Destroy a commnad.
*/
@ -132,9 +118,8 @@ public:
* Invoke a command.
*
* parameter args: Arguments to function.
* parameter win: Handle to graphics context.
*/
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error);
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error);
/**
* Get short description.
*
@ -150,8 +135,7 @@ public:
*/
std::string get_long_help() throw(std::bad_alloc);
private:
void (*fn)(const std::string& arguments, window* win);
void (*fn2)(const std::string& arguments, std::ostream& os);
void (*fn)(const std::string& arguments);
std::string description;
std::string help;
};

View file

@ -1,5 +1,6 @@
#include "framebuffer.hpp"
#include "lua.hpp"
#include "window.hpp"
#include "render.hpp"
lcscreen framebuffer;
@ -102,7 +103,7 @@ void init_special_screens() throw(std::bad_alloc)
screen_corrupt = lcscreen(buf, 512, 448);
}
void redraw_framebuffer(window* win)
void redraw_framebuffer()
{
uint32_t hscl = 1, vscl = 1;
if(framebuffer.width < 512)
@ -126,7 +127,7 @@ void redraw_framebuffer(window* win)
lrc.top_gap + lrc.bottom_gap, lrc.left_gap, lrc.top_gap);
main_screen.copy_from(framebuffer, hscl, vscl);
//We would want divide by 2, but we'll do it ourselves in order to do mouse.
win->set_window_compensation(lrc.left_gap, lrc.top_gap, 1, 1);
window::set_window_compensation(lrc.left_gap, lrc.top_gap, 1, 1);
rq.run(main_screen);
win->notify_screen_update();
window::notify_screen_update();
}

View file

@ -2,7 +2,6 @@
#define _framebuffer__hpp__included__
#include "render.hpp"
#include "window.hpp"
/**
* The main framebuffer.
@ -28,9 +27,7 @@ extern screen main_screen;
void init_special_screens() throw(std::bad_alloc);
/**
* Redraw the framebuffer on screen.
*
* parameter win: The graphics system handle.
*/
void redraw_framebuffer(window* win);
void redraw_framebuffer();
#endif

View file

@ -15,7 +15,7 @@ namespace
{
public:
bind_key() throw(std::bad_alloc) : command("bind-key") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
std::string mod, modmask, keyname, command;
tokensplitter t(args);
@ -33,10 +33,7 @@ namespace
command = t.tail();
if(command == "")
throw std::runtime_error("Expected command");
if(!win)
throw std::runtime_error("Bindings require graphics context");
else
win->bind(mod, modmask, keyname, command);
window::bind(mod, modmask, keyname, command);
}
std::string get_short_help() throw(std::bad_alloc) { return "Bind a (pseudo-)key"; }
std::string get_long_help() throw(std::bad_alloc)
@ -50,7 +47,7 @@ namespace
{
public:
unbind_key() throw(std::bad_alloc) : command("unbind-key") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
std::string mod, modmask, keyname, command;
tokensplitter t(args);
@ -68,10 +65,7 @@ namespace
command = t.tail();
if(command != "")
throw std::runtime_error("Unexpected argument");
if(!win)
throw std::runtime_error("Bindings require graphics context");
else
win->unbind(mod, modmask, keyname);
window::unbind(mod, modmask, keyname);
}
std::string get_short_help() throw(std::bad_alloc) { return "Unbind a (pseudo-)key"; }
std::string get_long_help() throw(std::bad_alloc)
@ -85,14 +79,11 @@ namespace
{
public:
shbind_key() throw(std::bad_alloc) : command("show-bindings") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
if(!win)
throw std::runtime_error("Bindings require graphics context");
else
win->dumpbindings();
window::dumpbindings();
}
std::string get_short_help() throw(std::bad_alloc) { return "Show active bindings"; }
std::string get_long_help() throw(std::bad_alloc)

View file

@ -131,13 +131,12 @@ public:
/**
* \brief Dump list of bindigns as messages to specified graphics handle.
*
* \param win The graphics system handle.
* \throws std::bad_alloc Not enough memory.
*/
void dumpbindings(window* win) throw(std::bad_alloc)
void dumpbindings() throw(std::bad_alloc)
{
for(auto i = bindings.begin(); i != bindings.end(); i++)
out(win) << "bind " << T::name_key(i->mod, i->modmask, i->symbol) << " " << i->command
window::out() << "bind " << T::name_key(i->mod, i->modmask, i->symbol) << " " << i->command
<< std::endl;
}
private:

View file

@ -24,7 +24,7 @@ class my_interfaced : public SNES::Interface
}
};
struct moviefile generate_movie_template(std::vector<std::string> cmdline, loaded_rom& r, window* win)
struct moviefile generate_movie_template(std::vector<std::string> cmdline, loaded_rom& r)
{
struct moviefile movie;
movie.gametype = gtype::togametype(r.rtype, r.region);
@ -78,44 +78,44 @@ int main(int argc, char** argv)
x << snes_library_id() << " (" << SNES::Info::Profile << " core)";
bsnes_core_version = x.str();
}
window win;
init_lua(&win);
window::init();
init_lua();
win.out() << "BSNES version: " << bsnes_core_version << std::endl;
win.out() << "lsnes version: lsnes rr" << lsnes_version << std::endl;
win.out() << "Command line is: ";
window::out() << "BSNES version: " << bsnes_core_version << std::endl;
window::out() << "lsnes version: lsnes rr" << lsnes_version << std::endl;
window::out() << "Command line is: ";
for(auto k = cmdline.begin(); k != cmdline.end(); k++)
win.out() << "\"" << *k << "\" ";
win.out() << std::endl;
window::out() << "\"" << *k << "\" ";
window::out() << std::endl;
std::string cfgpath = get_config_path(&win);
create_lsnesrc(&win);
out(&win) << "Saving per-user data to: " << get_config_path(&win) << std::endl;
out(&win) << "--- Running lsnesrc --- " << std::endl;
command::invokeC("run-script " + cfgpath + "/lsnes.rc", &win);
out(&win) << "--- End running lsnesrc --- " << std::endl;
std::string cfgpath = get_config_path();
create_lsnesrc();
window::out() << "Saving per-user data to: " << get_config_path() << std::endl;
window::out() << "--- Running lsnesrc --- " << std::endl;
command::invokeC("run-script " + cfgpath + "/lsnes.rc");
window::out() << "--- End running lsnesrc --- " << std::endl;
out(&win) << "--- Loading ROM ---" << std::endl;
window::out() << "--- Loading ROM ---" << std::endl;
struct loaded_rom r;
try {
r = load_rom_from_commandline(cmdline, &win);
r = load_rom_from_commandline(cmdline);
r.load();
} catch(std::bad_alloc& e) {
OOM_panic(&win);
OOM_panic();
} catch(std::exception& e) {
win.out() << "FATAL: Can't load ROM: " << e.what() << std::endl;
win.fatal_error();
window::out() << "FATAL: Can't load ROM: " << e.what() << std::endl;
window::fatal_error();
exit(1);
}
win.out() << "Detected region: " << gtype::tostring(r.rtype, r.region) << std::endl;
window::out() << "Detected region: " << gtype::tostring(r.rtype, r.region) << std::endl;
if(r.region == REGION_PAL)
set_nominal_framerate(322445.0/6448.0);
else if(r.region == REGION_NTSC)
set_nominal_framerate(10738636.0/178683.0);
out(&win) << "--- Internal memory mappings ---" << std::endl;
dump_region_map(&win);
out(&win) << "--- End of Startup --- " << std::endl;
window::out() << "--- Internal memory mappings ---" << std::endl;
dump_region_map();
window::out() << "--- End of Startup --- " << std::endl;
try {
moviefile movie;
bool loaded = false;
@ -125,15 +125,16 @@ int main(int argc, char** argv)
loaded = true;
}
if(!loaded)
movie = generate_movie_template(cmdline, r, &win);
main_loop(&win, r, movie);
movie = generate_movie_template(cmdline, r);
main_loop(r, movie);
} catch(std::bad_alloc& e) {
OOM_panic(&win);
OOM_panic();
} catch(std::exception& e) {
win.message(std::string("Fatal: ") + e.what());
win.fatal_error();
window::message(std::string("Fatal: ") + e.what());
window::fatal_error();
return 1;
}
rrdata::close();
window::quit();
return 0;
}

View file

@ -17,6 +17,6 @@ void lua_callback_err_save(const std::string& name) throw() {}
void lua_callback_post_save(const std::string& name, bool is_state) throw() {}
void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw() {}
void lua_callback_quit() throw() {}
void init_lua(window* win) throw() {}
void init_lua() throw() {}
bool lua_requests_repaint = false;
bool lua_requests_subframe_paint = false;

37
lua.cpp
View file

@ -4,6 +4,7 @@
#include "misc.hpp"
#include "memorymanip.hpp"
#include "mainloop.hpp"
#include "window.hpp"
#include <map>
#include <string>
extern "C" {
@ -11,19 +12,16 @@ extern "C" {
#include <lualib.h>
}
#include <iostream>
#include "fieldsplit.hpp"
namespace
{
std::map<std::string, lua_function*>* functions;
lua_State* lua_initialized;
window* lua_win;
int lua_trampoline_function(lua_State* L)
{
void* ptr = lua_touserdata(L, lua_upvalueindex(1));
lua_function* f = reinterpret_cast<lua_function*>(ptr);
return f->invoke(L, lua_win);
return f->invoke(L);
}
//Pushes given table to top of stack, creating if needed.
@ -185,12 +183,12 @@ namespace
return;
int t = lua_load(L, read_lua_fragment, NULL, "run_lua_fragment");
if(t == LUA_ERRSYNTAX) {
out(lua_win) << "Can't run Lua: Internal syntax error: " << lua_tostring(L, -1) << std::endl;
window::out() << "Can't run Lua: Internal syntax error: " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1);
return;
}
if(t == LUA_ERRMEM) {
out(lua_win) << "Can't run Lua: Out of memory" << std::endl;
window::out() << "Can't run Lua: Out of memory" << std::endl;
lua_pop(L, 1);
return;
}
@ -198,20 +196,20 @@ namespace
int r = lua_pcall(L, 0, 0, 0);
recursive_flag = false;
if(r == LUA_ERRRUN) {
out(lua_win) << "Error running Lua hunk: " << lua_tostring(L, -1) << std::endl;
window::out() << "Error running Lua hunk: " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1);
}
if(r == LUA_ERRMEM) {
out(lua_win) << "Error running Lua hunk: Out of memory" << std::endl;
window::out() << "Error running Lua hunk: Out of memory" << std::endl;
lua_pop(L, 1);
}
if(r == LUA_ERRERR) {
out(lua_win) << "Error running Lua hunk: Double Fault???" << std::endl;
window::out() << "Error running Lua hunk: Double Fault???" << std::endl;
lua_pop(L, 1);
}
if(lua_requests_repaint) {
lua_requests_repaint = false;
command::invokeC("repaint", lua_win);
command::invokeC("repaint");
}
}
@ -237,20 +235,20 @@ namespace
int r = lua_pcall(L, args, 0, 0);
recursive_flag = false;
if(r == LUA_ERRRUN) {
out(lua_win) << "Error running Lua callback: " << lua_tostring(L, -1) << std::endl;
window::out() << "Error running Lua callback: " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1);
}
if(r == LUA_ERRMEM) {
out(lua_win) << "Error running Lua callback: Out of memory" << std::endl;
window::out() << "Error running Lua callback: Out of memory" << std::endl;
lua_pop(L, 1);
}
if(r == LUA_ERRERR) {
out(lua_win) << "Error running Lua callback: Double Fault???" << std::endl;
window::out() << "Error running Lua callback: Double Fault???" << std::endl;
lua_pop(L, 1);
}
if(lua_requests_repaint) {
lua_requests_repaint = false;
command::invokeC("repaint", lua_win);
command::invokeC("repaint");
}
}
}
@ -372,7 +370,7 @@ namespace
{
public:
evallua() throw(std::bad_alloc) : command("evaluate-lua") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Expected expression to evaluate");
@ -390,7 +388,7 @@ namespace
{
public:
runlua() throw(std::bad_alloc) : command("run-lua") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Expected script to run");
@ -412,13 +410,12 @@ void lua_callback_quit() throw()
run_lua_cb(0);
}
void init_lua(window* win) throw()
void init_lua() throw()
{
lua_win = win;
L = lua_newstate(alloc, NULL);
if(!L) {
out(lua_win) << "Can't initialize Lua." << std::endl;
fatal_error(lua_win);
window::out() << "Can't initialize Lua." << std::endl;
window::fatal_error();
}
luaL_openlibs(L);

View file

@ -2,7 +2,6 @@
#define _lua__hpp__included__
#include "render.hpp"
#include "window.hpp"
#include "controllerdata.hpp"
struct lua_State;
@ -25,7 +24,7 @@ public:
/**
* Invoke function.
*/
virtual int invoke(lua_State* L, window* win) = 0;
virtual int invoke(lua_State* L) = 0;
protected:
std::string fname;
};
@ -44,7 +43,7 @@ struct lua_render_context
uint32_t bshift;
};
void init_lua(window* win) throw();
void init_lua() throw();
void lua_callback_do_paint(struct lua_render_context* ctx) throw();
void lua_callback_do_video(struct lua_render_context* ctx) throw();
void lua_callback_do_input(controls_t& data, bool subframe) throw();

View file

@ -71,7 +71,7 @@ namespace
{
public:
lua_symmetric_bitwise(const std::string& s) : lua_function(s) {};
int invoke(lua_State* L, window* win)
int invoke(lua_State* L)
{
int stacksize = 0;
while(!lua_isnone(L, stacksize + 1))
@ -89,7 +89,7 @@ namespace
{
public:
lua_shifter(const std::string& s) : lua_function(s) {};
int invoke(lua_State* L, window* win)
int invoke(lua_State* L)
{
uint64_t base;
uint64_t amount = 1;

View file

@ -1,5 +1,6 @@
#include "lua-int.hpp"
#include "command.hpp"
#include "window.hpp"
namespace
{
@ -7,7 +8,7 @@ namespace
{
public:
lua_print() : lua_function("print") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
int stacksize = 0;
while(!lua_isnone(LS, stacksize + 1))
@ -40,7 +41,7 @@ namespace
toprint = toprint + "\t" + localmsg;
first = false;
}
win->message(toprint);
window::message(toprint);
return 0;
}
} print;
@ -49,10 +50,10 @@ namespace
{
public:
lua_exec() : lua_function("exec") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
std::string text = get_string_argument(LS, 1, fname.c_str());
command::invokeC(text, win);
command::invokeC(text);
return 0;
}
} exec;

View file

@ -6,7 +6,7 @@ namespace
{
public:
lua_gui_resolution() : lua_function("gui.resolution") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
if(!lua_render_ctx)
return 0;
@ -24,7 +24,7 @@ namespace
{
public:
lua_gui_set_gap(const std::string& name) : lua_function(name) {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
if(!lua_render_ctx)
return 0;
@ -45,7 +45,7 @@ namespace
{
public:
lua_gui_repaint() : lua_function("gui.repaint") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
lua_requests_repaint = true;
return 0;
@ -56,7 +56,7 @@ namespace
{
public:
lua_gui_update_subframe() : lua_function("gui.subframe_update") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
lua_requests_subframe_paint = get_boolean_argument(LS, 1, "gui.subframe_update");
return 0;

View file

@ -38,7 +38,7 @@ namespace
{
public:
lua_gui_text() : lua_function("gui.text") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
if(!lua_render_ctx)
return 0;

View file

@ -1,5 +1,5 @@
#include "lua-int.hpp"
#include "mainloop.hpp"
#include "moviedata.hpp"
namespace
{
@ -7,7 +7,7 @@ namespace
{
public:
lua_hostmemory_read() : lua_function("hostmemory.read") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
size_t address = get_numeric_argument<size_t>(LS, 1, fname.c_str());
auto& h = get_host_memory();
@ -24,7 +24,7 @@ namespace
{
public:
lua_hostmemory_write() : lua_function("hostmemory.write") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
size_t address = get_numeric_argument<size_t>(LS, 1, fname.c_str());
uint8_t value = get_numeric_argument<uint8_t>(LS, 2, fname.c_str());

View file

@ -6,7 +6,7 @@ namespace
{
public:
lua_input_set() : lua_function("input.set") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
if(!lua_input_controllerdata)
return 0;
@ -24,7 +24,7 @@ namespace
{
public:
lua_input_get() : lua_function("input.get") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
if(!lua_input_controllerdata)
return 0;
@ -41,7 +41,7 @@ namespace
{
public:
lua_input_reset() : lua_function("input.reset") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
if(!lua_input_controllerdata)
return 0;

View file

@ -8,7 +8,7 @@ namespace
{
public:
lua_read_memory(const std::string& name) : lua_function(name) {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
uint32_t addr = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
lua_pushnumber(LS, static_cast<T>(rfun(addr)));
@ -21,7 +21,7 @@ namespace
{
public:
lua_write_memory(const std::string& name) : lua_function(name) {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
uint32_t addr = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
T value = get_numeric_argument<T>(LS, 2, fname.c_str());

View file

@ -1,6 +1,6 @@
#include "lua-int.hpp"
#include "movie.hpp"
#include "mainloop.hpp"
#include "moviedata.hpp"
namespace
{
@ -8,7 +8,7 @@ namespace
{
public:
lua_movie_currentframe() : lua_function("movie.currentframe") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
auto& m = get_movie();
lua_pushnumber(LS, m.get_current_frame());
@ -20,7 +20,7 @@ namespace
{
public:
lua_movie_framecount() : lua_function("movie.framecount") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
auto& m = get_movie();
lua_pushnumber(LS, m.get_frame_count());
@ -32,7 +32,7 @@ namespace
{
public:
lua_movie_readonly() : lua_function("movie.readonly") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
auto& m = get_movie();
lua_pushboolean(LS, m.readonly_mode() ? 1 : 0);
@ -44,7 +44,7 @@ namespace
{
public:
lua_movie_set_readwrite() : lua_function("movie.set_readwrite") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
auto& m = get_movie();
m.readonly_mode(false);
@ -56,7 +56,7 @@ namespace
{
public:
lua_movie_frame_subframes() : lua_function("movie.frame_subframes") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
uint64_t frame = get_numeric_argument<uint64_t>(LS, 1, "movie.frame_subframes");
auto& m = get_movie();
@ -69,7 +69,7 @@ namespace
{
public:
lua_movie_read_subframe() : lua_function("movie.read_subframe") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
uint64_t frame = get_numeric_argument<uint64_t>(LS, 1, "movie.frame_subframes");
uint64_t subframe = get_numeric_argument<uint64_t>(LS, 2, "movie.frame_subframes");

View file

@ -7,7 +7,7 @@ namespace
{
public:
lua_settings_set() : lua_function("settings.set") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
std::string name = get_string_argument(LS, 1, fname.c_str());
std::string value = get_string_argument(LS, 2, fname.c_str());
@ -27,7 +27,7 @@ namespace
{
public:
lua_settings_get() : lua_function("settings.get") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
std::string name = get_string_argument(LS, 1, fname.c_str());
try {
@ -50,7 +50,7 @@ namespace
{
public:
lua_settings_blank() : lua_function("settings.blank") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
std::string name = get_string_argument(LS, 1, fname.c_str());
try {
@ -69,7 +69,7 @@ namespace
{
public:
lua_settings_is_set() : lua_function("settings.is_set") {}
int invoke(lua_State* LS, window* win)
int invoke(lua_State* LS)
{
std::string name = get_string_argument(LS, 1, fname.c_str());
try {

View file

@ -73,8 +73,6 @@ namespace
//Flags related to repeating advance.
bool advanced_once;
bool cancel_advance;
//Handle to the graphics system.
window* win;
//Emulator advance mode. Detemines pauses at start of frame / subframe, etc..
enum advance_mode amode;
//Mode and filename of pending load, one of LOAD_* constants.
@ -108,7 +106,7 @@ namespace
}
int aindex = controller_index_by_analog(index);
if(aindex < 0) {
out(win) << "No analog controller in slot #" << (index + 1) << std::endl;
window::out() << "No analog controller in slot #" << (index + 1) << std::endl;
return;
}
curcontrols(aindex >> 2, aindex & 3, 0) = x;
@ -155,23 +153,23 @@ private:
controls_t movie_logic::update_controls(bool subframe) throw(std::bad_alloc, std::runtime_error)
{
if(lua_requests_subframe_paint)
redraw_framebuffer(win);
redraw_framebuffer();
if(subframe) {
if(amode == ADVANCE_SUBFRAME) {
if(!cancel_advance && !advanced_once) {
win->wait_msec(advance_timeout_first);
window::wait_msec(advance_timeout_first);
advanced_once = true;
}
if(cancel_advance) {
amode = ADVANCE_PAUSE;
cancel_advance = false;
}
win->paused(amode == ADVANCE_PAUSE);
window::paused(amode == ADVANCE_PAUSE);
} else if(amode == ADVANCE_FRAME) {
;
} else {
win->paused(amode == ADVANCE_SKIPLAG || amode == ADVANCE_PAUSE);
window::paused(amode == ADVANCE_SKIPLAG || amode == ADVANCE_PAUSE);
cancel_advance = false;
}
if(amode == ADVANCE_SKIPLAG)
@ -183,7 +181,7 @@ controls_t movie_logic::update_controls(bool subframe) throw(std::bad_alloc, std
amode = ADVANCE_SKIPLAG;
if(amode == ADVANCE_FRAME || amode == ADVANCE_SUBFRAME) {
if(!cancel_advance) {
win->wait_msec(advanced_once ? to_wait_frame(get_ticks_msec()) :
window::wait_msec(advanced_once ? to_wait_frame(get_ticks_msec()) :
advance_timeout_first);
advanced_once = true;
}
@ -191,16 +189,16 @@ controls_t movie_logic::update_controls(bool subframe) throw(std::bad_alloc, std
amode = ADVANCE_PAUSE;
cancel_advance = false;
}
win->paused(amode == ADVANCE_PAUSE);
window::paused(amode == ADVANCE_PAUSE);
} else {
win->paused((amode == ADVANCE_PAUSE));
window::paused((amode == ADVANCE_PAUSE));
cancel_advance = false;
}
location_special = SPECIAL_FRAME_START;
update_movie_state();
}
win->notify_screen_update();
win->poll_inputs();
window::notify_screen_update();
window::poll_inputs();
if(!subframe && pending_reset_cycles >= 0) {
curcontrols(CONTROL_SYSTEM_RESET) = 1;
curcontrols(CONTROL_SYSTEM_RESET_CYCLES_HI) = pending_reset_cycles / 10000;
@ -246,7 +244,7 @@ namespace
int bid = -1;
switch(p) {
case DT_NONE:
out(win) << "No such controller #" << (ui_id + 1) << std::endl;
window::out() << "No such controller #" << (ui_id + 1) << std::endl;
return;
case DT_GAMEPAD:
switch(button) {
@ -263,7 +261,7 @@ namespace
case BUTTON_SELECT: bid = SNES_DEVICE_ID_JOYPAD_SELECT; break;
case BUTTON_START: bid = SNES_DEVICE_ID_JOYPAD_START; break;
default:
out(win) << "Invalid button for gamepad" << std::endl;
window::out() << "Invalid button for gamepad" << std::endl;
return;
};
break;
@ -272,7 +270,7 @@ namespace
case BUTTON_L: bid = SNES_DEVICE_ID_MOUSE_LEFT; break;
case BUTTON_R: bid = SNES_DEVICE_ID_MOUSE_RIGHT; break;
default:
out(win) << "Invalid button for mouse" << std::endl;
window::out() << "Invalid button for mouse" << std::endl;
return;
};
break;
@ -281,7 +279,7 @@ namespace
case BUTTON_START: bid = SNES_DEVICE_ID_JUSTIFIER_START; break;
case BUTTON_TRIGGER: bid = SNES_DEVICE_ID_JUSTIFIER_TRIGGER; break;
default:
out(win) << "Invalid button for justifier" << std::endl;
window::out() << "Invalid button for justifier" << std::endl;
return;
};
break;
@ -292,7 +290,7 @@ namespace
case BUTTON_PAUSE: bid = SNES_DEVICE_ID_SUPER_SCOPE_PAUSE; break;
case BUTTON_TURBO: bid = SNES_DEVICE_ID_SUPER_SCOPE_TURBO; break;
default:
out(win) << "Invalid button for superscope" << std::endl;
window::out() << "Invalid button for superscope" << std::endl;
return;
};
break;
@ -310,8 +308,8 @@ namespace
loadmode = lmode;
pending_load = filename;
amode = ADVANCE_AUTO;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
}
//Mark pending save (movies save immediately).
@ -319,11 +317,11 @@ namespace
{
if(smode == SAVE_MOVIE) {
//Just do this immediately.
do_save_movie(win, filename);
do_save_movie(filename);
return;
}
queued_saves.insert(filename);
win->message("Pending save on '" + filename + "'");
window::message("Pending save on '" + filename + "'");
}
class dump_watch : public av_snooper::dump_notification
@ -341,7 +339,7 @@ namespace
void update_movie_state()
{
auto& _status = win->get_emustatus();
auto& _status = window::get_emustatus();
{
std::ostringstream x;
x << movb.get_movie().get_current_frame() << "(";
@ -438,7 +436,7 @@ class my_interface : public SNES::Interface
void video_refresh(const uint16_t *data, bool hires, bool interlace, bool overscan)
{
if(stepping_into_save)
win->message("Got video refresh in runtosave, expect desyncs!");
window::message("Got video refresh in runtosave, expect desyncs!");
video_refresh_done = true;
bool region = (SNES::system.region() == SNES::System::Region::PAL);
//std::cerr << "Frame: hires flag is " << (hires ? " " : "un") << "set." << std::endl;
@ -449,7 +447,7 @@ class my_interface : public SNES::Interface
framebuffer = ls;
location_special = SPECIAL_FRAME_VIDEO;
update_movie_state();
redraw_framebuffer(win);
redraw_framebuffer();
uint32_t fps_n, fps_d;
if(region) {
fps_n = 322445;
@ -458,22 +456,22 @@ class my_interface : public SNES::Interface
fps_n = 10738636;
fps_d = 178683;
}
av_snooper::frame(ls, fps_n, fps_d, out(win));
av_snooper::frame(ls, fps_n, fps_d, true);
}
void audio_sample(int16_t l_sample, int16_t r_sample)
{
uint16_t _l = l_sample;
uint16_t _r = r_sample;
win->play_audio_sample(_l + 32768, _r + 32768);
av_snooper::sample(_l, _r, out(win));
window::play_audio_sample(_l + 32768, _r + 32768);
av_snooper::sample(_l, _r, true);
}
void audio_sample(uint16_t l_sample, uint16_t r_sample)
{
//Yes, this interface is broken. The samples are signed but are passed as unsigned!
win->play_audio_sample(l_sample + 32768, r_sample + 32768);
av_snooper::sample(l_sample, r_sample, out(win));
window::play_audio_sample(l_sample + 32768, r_sample + 32768);
av_snooper::sample(l_sample, r_sample, true);
}
int16_t input_poll(bool port, SNES::Input::Device device, unsigned index, unsigned id)
@ -493,12 +491,12 @@ namespace
{
public:
quit_emulator_cmd() throw(std::bad_alloc) : command("quit-emulator") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "/y" || win->modal_message("Really quit?", true)) {
if(args == "/y" || window::modal_message("Really quit?", true)) {
amode = ADVANCE_QUIT;
win->paused(false);
win->cancel_wait();
window::paused(false);
window::cancel_wait();
}
}
std::string get_short_help() throw(std::bad_alloc) { return "Quit the emulator"; }
@ -513,20 +511,20 @@ namespace
{
public:
pause_emulator_cmd() throw(std::bad_alloc) : command("pause-emulator") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
if(amode != ADVANCE_AUTO) {
amode = ADVANCE_AUTO;
win->paused(false);
win->cancel_wait();
win->message("Unpaused");
window::paused(false);
window::cancel_wait();
window::message("Unpaused");
} else {
win->cancel_wait();
window::cancel_wait();
cancel_advance = false;
amode = ADVANCE_PAUSE;
win->message("Paused");
window::message("Paused");
}
}
std::string get_short_help() throw(std::bad_alloc) { return "(Un)pause the emulator"; }
@ -541,15 +539,15 @@ namespace
{
public:
padvance_frame_cmd() throw(std::bad_alloc) : command("+advance-frame") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
amode = ADVANCE_FRAME;
cancel_advance = false;
advanced_once = false;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
}
std::string get_short_help() throw(std::bad_alloc) { return "Advance one frame"; }
std::string get_long_help() throw(std::bad_alloc)
@ -563,13 +561,13 @@ namespace
{
public:
nadvance_frame_cmd() throw(std::bad_alloc) : command("-advance-frame") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
cancel_advance = true;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
}
} nadvancef;
@ -577,15 +575,15 @@ namespace
{
public:
padvance_poll_cmd() throw(std::bad_alloc) : command("+advance-poll") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
amode = ADVANCE_SUBFRAME;
cancel_advance = false;
advanced_once = false;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
}
std::string get_short_help() throw(std::bad_alloc) { return "Advance one subframe"; }
std::string get_long_help() throw(std::bad_alloc)
@ -600,13 +598,13 @@ namespace
public:
nadvance_poll_cmd() throw(std::bad_alloc) : command("-advance-poll") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
cancel_advance = true;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
}
} nadvancep;
@ -614,13 +612,13 @@ namespace
{
public:
advance_skiplag_cmd() throw(std::bad_alloc) : command("advance-skiplag") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
amode = ADVANCE_SKIPLAG;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
}
std::string get_short_help() throw(std::bad_alloc) { return "Skip to next poll"; }
std::string get_long_help() throw(std::bad_alloc)
@ -634,7 +632,7 @@ namespace
{
public:
reset_cmd() throw(std::bad_alloc) : command("reset") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
@ -652,7 +650,7 @@ namespace
{
public:
load_state_cmd() throw(std::bad_alloc) : command("load-state") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
@ -670,7 +668,7 @@ namespace
{
public:
load_readonly_cmd() throw(std::bad_alloc) : command("load-readonly") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
@ -688,7 +686,7 @@ namespace
{
public:
load_preserve_cmd() throw(std::bad_alloc) : command("load-preserve") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
@ -706,7 +704,7 @@ namespace
{
public:
load_movie_cmd() throw(std::bad_alloc) : command("load-movie") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
@ -724,7 +722,7 @@ namespace
{
public:
save_state_cmd() throw(std::bad_alloc) : command("save-state") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
@ -743,7 +741,7 @@ namespace
{
public:
save_movie_cmd() throw(std::bad_alloc) : command("save-movie") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
@ -761,14 +759,14 @@ namespace
{
public:
set_rwmode_cmd() throw(std::bad_alloc) : command("set-rwmode") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
movb.get_movie().readonly_mode(false);
lua_callback_do_readwrite();
update_movie_state();
win->notify_screen_update();
window::notify_screen_update();
}
std::string get_short_help() throw(std::bad_alloc) { return "Switch to read/write mode"; }
std::string get_long_help() throw(std::bad_alloc)
@ -782,11 +780,11 @@ namespace
{
public:
repainter() throw(std::bad_alloc) : command("repaint") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
redraw_framebuffer(win);
redraw_framebuffer();
}
std::string get_short_help() throw(std::bad_alloc) { return "Redraw the screen"; }
std::string get_long_help() throw(std::bad_alloc)
@ -800,10 +798,10 @@ namespace
{
public:
set_gamename_cmd() throw(std::bad_alloc) : command("set-gamename") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
our_movie.gamename = args;
out(win) << "Game name changed to '" << our_movie.gamename << "'" << std::endl;
window::out() << "Game name changed to '" << our_movie.gamename << "'" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Set the game name"; }
std::string get_long_help() throw(std::bad_alloc)
@ -817,7 +815,7 @@ namespace
{
public:
add_watch_command() throw(std::bad_alloc) : command("add-watch") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
std::string name = t;
@ -839,17 +837,17 @@ namespace
{
public:
remove_watch_command() throw(std::bad_alloc) : command("remove-watch") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
std::string name = t;
if(name == "" || t.tail() != "") {
out(win) << "syntax: remove-watch <name>" << std::endl;
window::out() << "syntax: remove-watch <name>" << std::endl;
return;
}
std::cerr << "Erase watch: '" << name << "'" << std::endl;
memory_watches.erase(name);
auto& _status = win->get_emustatus();
auto& _status = window::get_emustatus();
_status.erase("M[" + name + "]");
update_movie_state(); }
std::string get_short_help() throw(std::bad_alloc) { return "Remove a memory watch"; }
@ -864,10 +862,10 @@ namespace
{
public:
test_1() throw(std::bad_alloc) : command("test-1") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
framebuffer = screen_nosignal;
redraw_framebuffer(win);
redraw_framebuffer();
}
} test1c;
@ -875,10 +873,10 @@ namespace
{
public:
test_2() throw(std::bad_alloc) : command("test-2") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
framebuffer = screen_corrupt;
redraw_framebuffer(win);
redraw_framebuffer();
}
} test2c;
@ -886,7 +884,7 @@ namespace
{
public:
test_3() throw(std::bad_alloc) : command("test-3") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
while(1);
}
@ -896,12 +894,12 @@ namespace
{
public:
screenshot_command() throw(std::bad_alloc) : command("take-screenshot") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args == "")
throw std::runtime_error("Filename required");
framebuffer.save_png(args);
out(win) << "Saved PNG screenshot" << std::endl;
window::out() << "Saved PNG screenshot" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Takes a screenshot"; }
std::string get_long_help() throw(std::bad_alloc)
@ -915,7 +913,7 @@ namespace
{
public:
mouse_button_handler() throw(std::bad_alloc) : command("mouse_button") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
std::string x = t;
@ -947,7 +945,7 @@ namespace
button = _button;
}
~button_action() throw() {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
@ -957,7 +955,7 @@ namespace
auto i = buttonmap[button];
do_button_action(i.first, i.second, (type != 1) ? 1 : 0, (type == 2));
update_movie_state();
win->notify_screen_update();
window::notify_screen_update();
}
std::string get_short_help() throw(std::bad_alloc)
{
@ -1007,18 +1005,18 @@ namespace
bool handle_load()
{
if(pending_load != "") {
do_load_state(win, pending_load, loadmode);
redraw_framebuffer(win);
do_load_state(pending_load, loadmode);
redraw_framebuffer();
pending_load = "";
pending_reset_cycles = -1;
amode = ADVANCE_AUTO;
win->cancel_wait();
win->paused(false);
window::cancel_wait();
window::paused(false);
if(!system_corrupt) {
location_special = SPECIAL_SAVEPOINT;
update_movie_state();
win->notify_screen_update();
win->poll_inputs();
window::notify_screen_update();
window::poll_inputs();
}
return true;
}
@ -1033,7 +1031,7 @@ namespace
SNES::system.runtosave();
stepping_into_save = false;
for(auto i = queued_saves.begin(); i != queued_saves.end(); i++)
do_save_state(win, *i);
do_save_state(*i);
}
queued_saves.clear();
}
@ -1042,27 +1040,27 @@ namespace
bool handle_reset(long cycles)
{
if(cycles == 0) {
win->message("SNES reset");
window::message("SNES reset");
SNES::system.reset();
framebuffer = screen_nosignal;
lua_callback_do_reset();
redraw_framebuffer(win);
redraw_framebuffer();
} else if(cycles > 0) {
video_refresh_done = false;
long cycles_executed = 0;
out(win) << "Executing delayed reset... This can take some time!" << std::endl;
window::out() << "Executing delayed reset... This can take some time!" << std::endl;
while(cycles_executed < cycles && !video_refresh_done) {
SNES::cpu.op_step();
cycles_executed++;
}
if(!video_refresh_done)
out(win) << "SNES reset (delayed " << cycles_executed << ")" << std::endl;
window::out() << "SNES reset (delayed " << cycles_executed << ")" << std::endl;
else
out(win) << "SNES reset (forced at " << cycles_executed << ")" << std::endl;
window::out() << "SNES reset (forced at " << cycles_executed << ")" << std::endl;
SNES::system.reset();
framebuffer = screen_nosignal;
lua_callback_do_reset();
redraw_framebuffer(win);
redraw_framebuffer();
if(video_refresh_done) {
to_wait_frame(get_ticks_msec());
return false;
@ -1076,10 +1074,10 @@ namespace
if(!system_corrupt)
return false;
while(system_corrupt) {
redraw_framebuffer(win);
win->cancel_wait();
win->paused(true);
win->poll_inputs();
redraw_framebuffer();
window::cancel_wait();
window::paused(true);
window::poll_inputs();
handle_load();
if(amode == ADVANCE_QUIT)
return true;
@ -1101,36 +1099,35 @@ namespace
type = "superscope";
if(controller_type_by_logical(i) == DT_JUSTIFIER)
type = "justifier";
out(win) << "Physical controller mapping: Logical " << (i + 1) << " is physical " <<
window::out() << "Physical controller mapping: Logical " << (i + 1) << " is physical " <<
controller_index_by_logical(i) << " (" << type << ")" << std::endl;
}
}
}
void main_loop(window* _win, struct loaded_rom& rom, struct moviefile& initial) throw(std::bad_alloc,
void main_loop(struct loaded_rom& rom, struct moviefile& initial) throw(std::bad_alloc,
std::runtime_error)
{
//Basic initialization.
win = _win;
init_special_screens();
our_rom = &rom;
my_interface intrf;
auto old_inteface = SNES::system.interface;
SNES::system.interface = &intrf;
status = &win->get_emustatus();
status = &window::get_emustatus();
//Load our given movie.
bool first_round = false;
bool just_did_loadstate = false;
try {
do_load_state(win, initial, LOAD_STATE_DEFAULT);
do_load_state(initial, LOAD_STATE_DEFAULT);
first_round = our_movie.is_savestate;
just_did_loadstate = first_round;
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
win->message(std::string("FATAL: Can't load initial state: ") + e.what());
win->fatal_error();
window::message(std::string("FATAL: Can't load initial state: ") + e.what());
window::fatal_error();
return;
}
@ -1138,9 +1135,9 @@ void main_loop(window* _win, struct loaded_rom& rom, struct moviefile& initial)
//print_controller_mappings();
av_snooper::add_dump_notifier(dumpwatch);
win->set_main_surface(main_screen);
redraw_framebuffer(win);
win->paused(false);
window::set_main_surface(main_screen);
redraw_framebuffer();
window::paused(false);
amode = ADVANCE_PAUSE;
while(amode != ADVANCE_QUIT) {
if(handle_corrupt()) {
@ -1176,17 +1173,17 @@ void main_loop(window* _win, struct loaded_rom& rom, struct moviefile& initial)
if(amode == ADVANCE_QUIT)
break;
amode = ADVANCE_PAUSE;
redraw_framebuffer(win);
win->cancel_wait();
win->paused(true);
win->poll_inputs();
redraw_framebuffer();
window::cancel_wait();
window::paused(true);
window::poll_inputs();
just_did_loadstate = false;
}
SNES::system.run();
if(amode == ADVANCE_AUTO)
win->wait_msec(to_wait_frame(get_ticks_msec()));
window::wait_msec(to_wait_frame(get_ticks_msec()));
first_round = false;
}
av_snooper::end(out(win));
av_snooper::end(true);
SNES::system.interface = old_inteface;
}

View file

@ -9,10 +9,7 @@
/**
* \brief Emulator main loop.
*/
void main_loop(window* _win, struct loaded_rom& rom, struct moviefile& settings) throw(std::bad_alloc,
void main_loop(struct loaded_rom& rom, struct moviefile& settings) throw(std::bad_alloc,
std::runtime_error);
std::vector<char>& get_host_memory();
movie& get_movie();
#endif

View file

@ -761,7 +761,7 @@ namespace
_command = cmd;
}
~memorymanip_command() throw() {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
firstword = static_cast<std::string>(t);
@ -798,9 +798,9 @@ namespace
value_bad = false;
} catch(...) {
}
invoke2(win);
invoke2();
}
virtual void invoke2(window* win) throw(std::bad_alloc, std::runtime_error) = 0;
virtual void invoke2() throw(std::bad_alloc, std::runtime_error) = 0;
std::string firstword;
std::string secondword;
uint32_t address;
@ -822,7 +822,7 @@ namespace
rfn = _rfn;
}
~read_command() throw() {}
void invoke2(window* win) throw(std::bad_alloc, std::runtime_error)
void invoke2() throw(std::bad_alloc, std::runtime_error)
{
if(address_bad || has_value || has_tail)
throw std::runtime_error("Syntax: " + _command + " <address>");
@ -830,7 +830,7 @@ namespace
std::ostringstream x;
x << "0x" << std::hex << address << " -> " << std::dec
<< static_cast<outer>(static_cast<inner>(rfn(address)));
out(win) << x.str() << std::endl;
window::out() << x.str() << std::endl;
}
}
std::string get_short_help() throw(std::bad_alloc) { return "Read memory"; }
@ -853,7 +853,7 @@ namespace
wfn = _wfn;
}
~write_command() throw() {}
void invoke2(window* win) throw(std::bad_alloc, std::runtime_error)
void invoke2() throw(std::bad_alloc, std::runtime_error)
{
if(address_bad || value_bad || has_tail)
throw std::runtime_error("Syntax: " + _command + " <address> <value>");
@ -874,7 +874,7 @@ namespace
{
public:
memorysearch_command() throw(std::bad_alloc) : memorymanip_command("search-memory") {}
void invoke2(window* win) throw(std::bad_alloc, std::runtime_error)
void invoke2() throw(std::bad_alloc, std::runtime_error)
{
if(!isrch)
isrch = new memorysearch();
@ -997,11 +997,11 @@ namespace
for(auto ci = c.begin(); ci != c.end(); ci++) {
std::ostringstream x;
x << "0x" << std::hex << std::setw(8) << std::setfill('0') << *ci;
out(win) << x.str() << std::endl;
window::out() << x.str() << std::endl;
}
} else
throw std::runtime_error("Unknown memorysearch subcommand '" + firstword + "'");
out(win) << isrch->get_candidate_count() << " candidates remain." << std::endl;
window::out() << isrch->get_candidate_count() << " candidates remain." << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Search memory addresses"; }
std::string get_long_help() throw(std::bad_alloc)

View file

@ -1,7 +1,6 @@
#ifndef _memorymanip__hpp__included__
#define _memorymanip__hpp__included__
#include "window.hpp"
#include <string>
#include <list>
#include <vector>

View file

@ -1,5 +1,6 @@
#include "lsnes.hpp"
#include "memorymanip.hpp"
#include "window.hpp"
#include "misc.hpp"
#include "rom.hpp"
#include <sstream>
@ -170,74 +171,70 @@ std::string sha256::tostring(const uint8_t* hashout) throw(std::bad_alloc)
return str.str();
}
struct loaded_rom load_rom_from_commandline(std::vector<std::string> cmdline, window* win) throw(std::bad_alloc,
struct loaded_rom load_rom_from_commandline(std::vector<std::string> cmdline) throw(std::bad_alloc,
std::runtime_error)
{
struct rom_files f;
try {
f = rom_files(cmdline, win);
f = rom_files(cmdline);
f.resolve_relative();
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
throw std::runtime_error(std::string("Can't resolve ROM files: ") + e.what());
}
out(win) << "ROM type: " << gtype::tostring(f.rtype, f.region) << std::endl;
if(f.rom != "") out(win) << name_subrom(f.rtype, 0) << " file: '" << f.rom << "'" << std::endl;
if(f.rom_xml != "") out(win) << name_subrom(f.rtype, 1) << " file: '" << f.rom_xml << "'" << std::endl;
if(f.slota != "") out(win) << name_subrom(f.rtype, 2) << " file: '" << f.slota << "'" << std::endl;
if(f.slota_xml != "") out(win) << name_subrom(f.rtype, 3) << " file: '" << f.slota_xml << "'" << std::endl;
if(f.slotb != "") out(win) << name_subrom(f.rtype, 4) << " file: '" << f.slotb << "'" << std::endl;
if(f.slotb_xml != "") out(win) << name_subrom(f.rtype, 5) << " file: '" << f.slotb_xml << "'" << std::endl;
window::out() << "ROM type: " << gtype::tostring(f.rtype, f.region) << std::endl;
if(f.rom != "") window::out() << name_subrom(f.rtype, 0) << " file: '" << f.rom << "'" << std::endl;
if(f.rom_xml != "") window::out() << name_subrom(f.rtype, 1) << " file: '" << f.rom_xml << "'"
<< std::endl;
if(f.slota != "") window::out() << name_subrom(f.rtype, 2) << " file: '" << f.slota << "'" << std::endl;
if(f.slota_xml != "") window::out() << name_subrom(f.rtype, 3) << " file: '" << f.slota_xml << "'"
<< std::endl;
if(f.slotb != "") window::out() << name_subrom(f.rtype, 4) << " file: '" << f.slotb << "'" << std::endl;
if(f.slotb_xml != "") window::out() << name_subrom(f.rtype, 5) << " file: '" << f.slotb_xml << "'"
<< std::endl;
struct loaded_rom r;
try {
r = loaded_rom(f, win);
r.do_patch(cmdline, win);
r = loaded_rom(f);
r.do_patch(cmdline);
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
throw std::runtime_error(std::string("Can't load ROM: ") + e.what());
}
std::string not_present = "N/A";
if(r.rom.valid) out(win) << name_subrom(f.rtype, 0) << " hash: " << r.rom.sha256 << std::endl;
if(r.rom_xml.valid) out(win) << name_subrom(f.rtype, 1) << " hash: " << r.rom_xml.sha256 << std::endl;
if(r.slota.valid) out(win) << name_subrom(f.rtype, 2) << " hash: " << r.slota.sha256 << std::endl;
if(r.slota_xml.valid) out(win) << name_subrom(f.rtype, 3) << " hash: " << r.slota_xml.sha256 << std::endl;
if(r.slotb.valid) out(win) << name_subrom(f.rtype, 4) << " hash: " << r.slotb.sha256 << std::endl;
if(r.slotb_xml.valid) out(win) << name_subrom(f.rtype, 5) << " hash: " << r.slotb_xml.sha256 << std::endl;
if(r.rom.valid) window::out() << name_subrom(f.rtype, 0) << " hash: " << r.rom.sha256 << std::endl;
if(r.rom_xml.valid) window::out() << name_subrom(f.rtype, 1) << " hash: " << r.rom_xml.sha256 << std::endl;
if(r.slota.valid) window::out() << name_subrom(f.rtype, 2) << " hash: " << r.slota.sha256 << std::endl;
if(r.slota_xml.valid) window::out() << name_subrom(f.rtype, 3) << " hash: " << r.slota_xml.sha256
<< std::endl;
if(r.slotb.valid) window::out() << name_subrom(f.rtype, 4) << " hash: " << r.slotb.sha256 << std::endl;
if(r.slotb_xml.valid) window::out() << name_subrom(f.rtype, 5) << " hash: " << r.slotb_xml.sha256
<< std::endl;
return r;
}
void dump_region_map(window* win) throw(std::bad_alloc)
void dump_region_map() throw(std::bad_alloc)
{
std::vector<struct memory_region> regions = get_regions();
for(auto i = regions.begin(); i != regions.end(); ++i) {
char buf[256];
sprintf(buf, "Region: %08X-%08X %08X %s%c %s", i->baseaddr, i->lastaddr, i->size,
i->readonly ? "R-" : "RW", i->native_endian ? 'N' : 'B', i->region_name.c_str());
out(win) << buf << std::endl;
window::out() << buf << std::endl;
}
}
std::ostream& out(window* win) throw(std::bad_alloc)
void fatal_error() throw()
{
if(!win)
return std::cout;
else
return win->out();
}
void fatal_error(window* win) throw()
{
if(win)
win->fatal_error();
window::fatal_error();
std::cout << "PANIC: Fatal error, can't continue." << std::endl;
exit(1);
}
std::string get_config_path(window* win) throw(std::bad_alloc)
std::string get_config_path() throw(std::bad_alloc)
{
const char* tmp;
std::string basedir;
@ -258,16 +255,16 @@ std::string get_config_path(window* win) throw(std::bad_alloc)
std::string lsnes_path = basedir + "/lsnes";
boost::filesystem::path p(lsnes_path);
if(!boost::filesystem::create_directories(p) && !boost::filesystem::is_directory(p)) {
out(win) << "FATAL: Can't create configuration directory '" << lsnes_path << "'" << std::endl;
fatal_error(win);
window::out() << "FATAL: Can't create configuration directory '" << lsnes_path << "'" << std::endl;
fatal_error();
}
//Yes, this is racy, but portability is more important than being absolutely correct...
std::string tfile = lsnes_path + "/test";
remove(tfile.c_str());
FILE* x;
if(!(x = fopen(tfile.c_str(), "w+"))) {
out(win) << "FATAL: Configuration directory '" << lsnes_path << "' is not writable" << std::endl;
fatal_error(win);
window::out() << "FATAL: Configuration directory '" << lsnes_path << "' is not writable" << std::endl;
fatal_error();
}
fclose(x);
remove(tfile.c_str());
@ -276,9 +273,9 @@ std::string get_config_path(window* win) throw(std::bad_alloc)
extern const char* lsnesrc_file;
void create_lsnesrc(window* win)
void create_lsnesrc()
{
std::string rcfile = get_config_path(win) + "/lsnes.rc";
std::string rcfile = get_config_path() + "/lsnes.rc";
std::ifstream x(rcfile.c_str());
if(x) {
x.close();
@ -286,18 +283,18 @@ void create_lsnesrc(window* win)
}
std::ofstream y(rcfile.c_str());
if(!y) {
out(win) << "FATAL: lsnes.rc (" << rcfile << ") doesn't exist nor it can be created" << std::endl;
fatal_error(win);
window::out() << "FATAL: lsnes.rc (" << rcfile << ") doesn't exist nor it can be created" << std::endl;
fatal_error();
}
y.write(lsnesrc_file, strlen(lsnesrc_file));
y.close();
}
void OOM_panic(window* win)
void OOM_panic()
{
out(win) << "FATAL: Out of memory!" << std::endl;
fatal_error(win);
window::out() << "FATAL: Out of memory!" << std::endl;
fatal_error();
}
std::string bsnes_core_version;

View file

@ -3,7 +3,6 @@
#include <string>
#include <vector>
#include "window.hpp"
#include <boost/lexical_cast.hpp>
/**
@ -52,51 +51,39 @@ void set_random_seed() throw(std::bad_alloc);
* Given commandline arguments, load a ROM.
*
* \param cmdline The command line.
* \param win Handle to send the messages to.
* \return The loaded ROM set.
* \throws std::bad_alloc Not enough memory.
* \throws std::runtime_error Can't load the ROMset.
*/
struct loaded_rom load_rom_from_commandline(std::vector<std::string> cmdline, window* win) throw(std::bad_alloc,
struct loaded_rom load_rom_from_commandline(std::vector<std::string> cmdline) throw(std::bad_alloc,
std::runtime_error);
/**
* \brief Dump listing of regions to graphics system messages.
*
* \param win Handle to send the messages to.
* \throws std::bad_alloc Not enough memory.
*/
void dump_region_map(window* win) throw(std::bad_alloc);
/**
* \brief Return printing stream.
*
* \param win Handle to graphics system.
* \return Stream. If win is NULL, this is std::cout. Otherwise it is win->out().
* \throws std::bad_alloc Not enough memory.
*/
std::ostream& out(window* win) throw(std::bad_alloc);
void dump_region_map() throw(std::bad_alloc);
/**
* \brief Fatal error.
*
* Fatal error. If win is non-NULL, it calls win->fatal_error(). Otherwise just immediately quits with error.
* Fatal error.
*/
void fatal_error(window* win) throw();
void fatal_error() throw();
/**
* \brief Get path to config directory.
*
* \param win Graphics system handle.
* \return The config directory path.
* \throw std::bad_alloc Not enough memory.
*/
std::string get_config_path(window* win) throw(std::bad_alloc);
std::string get_config_path() throw(std::bad_alloc);
/**
* \brief Panic on OOM.
*/
void OOM_panic(window* win);
void OOM_panic();
/**
* \brief Typeconvert string.
@ -119,7 +106,7 @@ template<> inline std::string parse_value(const std::string& value) throw(std::b
return value;
}
void create_lsnesrc(window* win);
void create_lsnesrc();
/**
* \brief Opaque internal state of SHA256

View file

@ -1,4 +1,5 @@
#include "moviedata.hpp"
#include "window.hpp"
#include "command.hpp"
#include "lua.hpp"
#include "framebuffer.hpp"
@ -33,11 +34,11 @@ namespace
{
public:
get_gamename_cmd() throw(std::bad_alloc) : command("get-gamename") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
out(win) << "Game name is '" << our_movie.gamename << "'" << std::endl;
window::out() << "Game name is '" << our_movie.gamename << "'" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Get the game name"; }
std::string get_long_help() throw(std::bad_alloc)
@ -51,15 +52,15 @@ namespace
{
public:
print_authors_cmd() throw(std::bad_alloc) : command("show-authors") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
size_t idx = 0;
for(auto i = our_movie.authors.begin(); i != our_movie.authors.end(); i++) {
out(win) << (idx++) << ": " << i->first << "|" << i->second << std::endl;
window::out() << (idx++) << ": " << i->first << "|" << i->second << std::endl;
}
out(win) << "End of authors list" << std::endl;
window::out() << "End of authors list" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Show the run authors"; }
std::string get_long_help() throw(std::bad_alloc)
@ -73,7 +74,7 @@ namespace
{
public:
add_author_command() throw(std::bad_alloc) : command("add-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
fieldsplitter f(t.tail());
@ -82,7 +83,7 @@ namespace
if(full == "" && nick == "")
throw std::runtime_error("Bad author name");
our_movie.authors.push_back(std::make_pair(full, nick));
out(win) << (our_movie.authors.size() - 1) << ": " << full << "|" << nick << std::endl;
window::out() << (our_movie.authors.size() - 1) << ": " << full << "|" << nick << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Add an author"; }
std::string get_long_help() throw(std::bad_alloc)
@ -98,7 +99,7 @@ namespace
{
public:
remove_author_command() throw(std::bad_alloc) : command("remove-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
uint64_t index = parse_value<uint64_t>(t.tail());
@ -118,7 +119,7 @@ namespace
{
public:
edit_author_command() throw(std::bad_alloc) : command("edit-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
uint64_t index = parse_value<uint64_t>(t);
@ -128,7 +129,7 @@ namespace
std::string full = f;
std::string nick = f;
if(full == "" && nick == "") {
out(win) << "syntax: edit-author <authornum> <author>" << std::endl;
window::out() << "syntax: edit-author <authornum> <author>" << std::endl;
return;
}
our_movie.authors[index] = std::make_pair(full, nick);
@ -143,11 +144,11 @@ namespace
}
} editauthorc;
void warn_hash_mismatch(window* win, const std::string& mhash, const loaded_slot& slot,
void warn_hash_mismatch(const std::string& mhash, const loaded_slot& slot,
const std::string& name)
{
if(mhash != slot.sha256) {
out(win) << "WARNING: " << name << " hash mismatch!" << std::endl
window::out() << "WARNING: " << name << " hash mismatch!" << std::endl
<< "\tMovie: " << mhash << std::endl
<< "\tOur ROM: " << slot.sha256 << std::endl;
}
@ -155,7 +156,7 @@ namespace
}
//Save state.
void do_save_state(window* win, const std::string& filename) throw(std::bad_alloc,
void do_save_state(const std::string& filename) throw(std::bad_alloc,
std::runtime_error)
{
lua_callback_pre_save(filename, true);
@ -171,18 +172,18 @@ void do_save_state(window* win, const std::string& filename) throw(std::bad_allo
our_movie.input = movb.get_movie().save();
our_movie.save(filename, savecompression);
uint64_t took = get_ticks_msec() - origtime;
out(win) << "Saved state '" << filename << "' in " << took << "ms." << std::endl;
window::out() << "Saved state '" << filename << "' in " << took << "ms." << std::endl;
lua_callback_post_save(filename, true);
} catch(std::bad_alloc& e) {
throw;
} catch(std::exception& e) {
win->message(std::string("Save failed: ") + e.what());
window::message(std::string("Save failed: ") + e.what());
lua_callback_err_save(filename);
}
}
//Save movie.
void do_save_movie(window* win, const std::string& filename) throw(std::bad_alloc, std::runtime_error)
void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runtime_error)
{
lua_callback_pre_save(filename, false);
try {
@ -191,18 +192,18 @@ void do_save_movie(window* win, const std::string& filename) throw(std::bad_allo
our_movie.input = movb.get_movie().save();
our_movie.save(filename, savecompression);
uint64_t took = get_ticks_msec() - origtime;
out(win) << "Saved movie '" << filename << "' in " << took << "ms." << std::endl;
window::out() << "Saved movie '" << filename << "' in " << took << "ms." << std::endl;
lua_callback_post_save(filename, false);
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
win->message(std::string("Save failed: ") + e.what());
window::message(std::string("Save failed: ") + e.what());
lua_callback_err_save(filename);
}
}
//Load state from loaded movie file (does not catch errors).
void do_load_state(window* win, struct moviefile& _movie, int lmode)
void do_load_state(struct moviefile& _movie, int lmode)
{
bool will_load_state = _movie.is_savestate && lmode != LOAD_STATE_MOVIE;
if(gtype::toromtype(_movie.gametype) != our_rom->rtype)
@ -218,16 +219,16 @@ void do_load_state(window* win, struct moviefile& _movie, int lmode)
<< "\tFile is from: " << _movie.coreversion << std::endl;
throw std::runtime_error(x.str());
} else
out(win) << "WARNING: Emulator core version mismatch!" << std::endl
window::out() << "WARNING: Emulator core version mismatch!" << std::endl
<< "\tThis version: " << bsnes_core_version << std::endl
<< "\tFile is from: " << _movie.coreversion << std::endl;
}
warn_hash_mismatch(win, _movie.rom_sha256, our_rom->rom, "ROM #1");
warn_hash_mismatch(win, _movie.romxml_sha256, our_rom->rom_xml, "XML #1");
warn_hash_mismatch(win, _movie.slota_sha256, our_rom->slota, "ROM #2");
warn_hash_mismatch(win, _movie.slotaxml_sha256, our_rom->slota_xml, "XML #2");
warn_hash_mismatch(win, _movie.slotb_sha256, our_rom->slotb, "ROM #3");
warn_hash_mismatch(win, _movie.slotbxml_sha256, our_rom->slotb_xml, "XML #3");
warn_hash_mismatch(_movie.rom_sha256, our_rom->rom, "ROM #1");
warn_hash_mismatch(_movie.romxml_sha256, our_rom->rom_xml, "XML #1");
warn_hash_mismatch(_movie.slota_sha256, our_rom->slota, "ROM #2");
warn_hash_mismatch(_movie.slotaxml_sha256, our_rom->slota_xml, "XML #2");
warn_hash_mismatch(_movie.slotb_sha256, our_rom->slotb, "ROM #3");
warn_hash_mismatch(_movie.slotbxml_sha256, our_rom->slotb_xml, "XML #3");
SNES::config.random = false;
SNES::config.expansion_port = SNES::System::ExpansionPortDevice::None;
@ -259,13 +260,13 @@ void do_load_state(window* win, struct moviefile& _movie, int lmode)
load_core_state(_movie.savestate);
framebuffer.load(_movie.screenshot);
} else {
load_sram(_movie.movie_sram, win);
load_sram(_movie.movie_sram);
controller_set_port_type(0, _movie.port1);
controller_set_port_type(1, _movie.port2);
framebuffer = screen_nosignal;
}
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
system_corrupt = true;
framebuffer = screen_corrupt;
@ -284,40 +285,40 @@ void do_load_state(window* win, struct moviefile& _movie, int lmode)
movb.get_movie().readonly_mode(false);
if(lmode == LOAD_STATE_DEFAULT && !(movb.get_movie().get_frame_count()))
movb.get_movie().readonly_mode(false);
out(win) << "ROM Type ";
window::out() << "ROM Type ";
switch(our_rom->rtype) {
case ROMTYPE_SNES:
out(win) << "SNES";
window::out() << "SNES";
break;
case ROMTYPE_BSX:
out(win) << "BS-X";
window::out() << "BS-X";
break;
case ROMTYPE_BSXSLOTTED:
out(win) << "BS-X slotted";
window::out() << "BS-X slotted";
break;
case ROMTYPE_SUFAMITURBO:
out(win) << "Sufami Turbo";
window::out() << "Sufami Turbo";
break;
case ROMTYPE_SGB:
out(win) << "Super Game Boy";
window::out() << "Super Game Boy";
break;
default:
out(win) << "Unknown";
window::out() << "Unknown";
break;
}
out(win) << " region ";
window::out() << " region ";
switch(our_rom->region) {
case REGION_PAL:
out(win) << "PAL";
window::out() << "PAL";
break;
case REGION_NTSC:
out(win) << "NTSC";
window::out() << "NTSC";
break;
default:
out(win) << "Unknown";
window::out() << "Unknown";
break;
}
out(win) << std::endl;
window::out() << std::endl;
uint64_t mlength = _movie.get_movie_length();
{
mlength += 999999;
@ -331,18 +332,18 @@ void do_load_state(window* win, struct moviefile& _movie, int lmode)
x << std::setfill('0') << std::setw(2) << mlength / 1000000000 << ".";
mlength %= 1000000000;
x << std::setfill('0') << std::setw(3) << mlength / 1000000;
out(win) << "Rerecords " << _movie.rerecords << " length " << x.str() << " ("
window::out() << "Rerecords " << _movie.rerecords << " length " << x.str() << " ("
<< _movie.get_frame_count() << " frames)" << std::endl;
}
if(_movie.gamename != "")
out(win) << "Game Name: " << _movie.gamename << std::endl;
window::out() << "Game Name: " << _movie.gamename << std::endl;
for(size_t i = 0; i < _movie.authors.size(); i++)
out(win) << "Author: " << _movie.authors[i].first << "(" << _movie.authors[i].second << ")"
window::out() << "Author: " << _movie.authors[i].first << "(" << _movie.authors[i].second << ")"
<< std::endl;
}
//Load state
void do_load_state(window* win, const std::string& filename, int lmode)
void do_load_state(const std::string& filename, int lmode)
{
uint64_t origtime = get_ticks_msec();
lua_callback_pre_load(filename);
@ -350,21 +351,21 @@ void do_load_state(window* win, const std::string& filename, int lmode)
try {
mfile = moviefile(filename);
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
win->message("Can't read movie/savestate '" + filename + "': " + e.what());
window::message("Can't read movie/savestate '" + filename + "': " + e.what());
lua_callback_err_load(filename);
return;
}
try {
do_load_state(win, mfile, lmode);
do_load_state(mfile, lmode);
uint64_t took = get_ticks_msec() - origtime;
out(win) << "Loaded '" << filename << "' in " << took << "ms." << std::endl;
window::out() << "Loaded '" << filename << "' in " << took << "ms." << std::endl;
lua_callback_post_load(filename, our_movie.is_savestate);
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
win->message("Can't load movie/savestate '" + filename + "': " + e.what());
window::message("Can't load movie/savestate '" + filename + "': " + e.what());
lua_callback_err_load(filename);
return;
}

View file

@ -18,11 +18,10 @@ extern bool system_corrupt;
std::vector<char>& get_host_memory();
movie& get_movie();
void do_save_state(window* win, const std::string& filename) throw(std::bad_alloc, std::runtime_error);
void do_save_movie(window* win, const std::string& filename) throw(std::bad_alloc, std::runtime_error);
void do_load_state(window* win, struct moviefile& _movie, int lmode);
void do_load_state(window* win, const std::string& filename, int lmode);
void do_save_state(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
void do_load_state(struct moviefile& _movie, int lmode);
void do_load_state(const std::string& filename, int lmode);
extern movie_logic movb;

33
rom.cpp
View file

@ -14,6 +14,7 @@ using SNES::cartridge;
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include "window.hpp"
#include "rom.hpp"
#include "command.hpp"
#include "fieldsplit.hpp"
@ -350,7 +351,7 @@ rom_files::rom_files() throw()
}
rom_files::rom_files(const std::vector<std::string>& cmdline, window* win) throw(std::bad_alloc, std::runtime_error)
rom_files::rom_files(const std::vector<std::string>& cmdline) throw(std::bad_alloc, std::runtime_error)
{
rom = rom_xml = slota = slota_xml = slotb = slotb_xml = "";
std::string arr[sizeof(romtypes_to_recognize) / sizeof(romtypes_to_recognize[0])];
@ -404,7 +405,7 @@ loaded_rom::loaded_rom() throw()
region = orig_region = REGION_AUTO;
}
loaded_rom::loaded_rom(const rom_files& files, window* win) throw(std::bad_alloc, std::runtime_error)
loaded_rom::loaded_rom(const rom_files& files) throw(std::bad_alloc, std::runtime_error)
{
std::string _slota = files.slota;
std::string _slota_xml = files.slota_xml;
@ -416,23 +417,23 @@ loaded_rom::loaded_rom(const rom_files& files, window* win) throw(std::bad_alloc
return;
}
if((_slota != "" || _slota_xml != "") && files.rtype == ROMTYPE_SNES) {
out(win) << "WARNING: SNES takes only 1 ROM image" << std::endl;
window::out() << "WARNING: SNES takes only 1 ROM image" << std::endl;
_slota = "";
_slota_xml = "";
}
if((_slotb != "" || _slotb_xml != "") && files.rtype != ROMTYPE_SUFAMITURBO) {
out(win) << "WARNING: Only Sufami Turbo takes 3 ROM images" << std::endl;
window::out() << "WARNING: Only Sufami Turbo takes 3 ROM images" << std::endl;
_slotb = "";
_slotb_xml = "";
}
if(files.rom_xml != "" && files.rom == "")
out(win) << "WARNING: " << name_subrom(files.rtype, 0) << " specified without corresponding "
window::out() << "WARNING: " << name_subrom(files.rtype, 0) << " specified without corresponding "
<< name_subrom(files.rtype, 1) << std::endl;
if(_slota_xml != "" && _slota == "")
out(win) << "WARNING: " << name_subrom(files.rtype, 2) << " specified without corresponding "
window::out() << "WARNING: " << name_subrom(files.rtype, 2) << " specified without corresponding "
<< name_subrom(files.rtype, 3) << std::endl;
if(_slotb_xml != "" && _slotb == "")
out(win) << "WARNING: " << name_subrom(files.rtype, 4) << " specified without corresponding "
window::out() << "WARNING: " << name_subrom(files.rtype, 4) << " specified without corresponding "
<< name_subrom(files.rtype, 5) << std::endl;
rtype = files.rtype;
@ -506,7 +507,7 @@ void loaded_rom::load() throw(std::bad_alloc, std::runtime_error)
refresh_cart_mappings();
}
void loaded_rom::do_patch(const std::vector<std::string>& cmdline, window* win) throw(std::bad_alloc,
void loaded_rom::do_patch(const std::vector<std::string>& cmdline) throw(std::bad_alloc,
std::runtime_error)
{
int32_t offset = 0;
@ -527,12 +528,12 @@ void loaded_rom::do_patch(const std::vector<std::string>& cmdline, window* win)
throw std::runtime_error("Invalid IPS patch argument '" + opt + "'");
std::string kind = opt.substr(6, split - 6);
std::string filename = opt.substr(split + 1);
out(win) << "Patching " << kind << " using '" << filename << "'" << std::endl;
window::out() << "Patching " << kind << " using '" << filename << "'" << std::endl;
std::vector<char> ips;
try {
ips = read_file_relative(filename, "");
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
throw std::runtime_error("Can't read IPS '" + filename + "': " + e.what());
}
@ -548,7 +549,7 @@ void loaded_rom::do_patch(const std::vector<std::string>& cmdline, window* win)
throw std::runtime_error("Invalid subROM '" + kind + "' to patch");
}
} catch(std::bad_alloc& e) {
OOM_panic(win);
OOM_panic();
} catch(std::exception& e) {
throw std::runtime_error("Can't Patch with IPS '" + filename + "': " + e.what());
}
@ -582,7 +583,7 @@ std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc)
return out;
}
void load_sram(std::map<std::string, std::vector<char>>& sram, window* win) throw(std::bad_alloc)
void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc)
{
std::set<std::string> used;
if(sram.empty())
@ -593,16 +594,16 @@ void load_sram(std::map<std::string, std::vector<char>>& sram, window* win) thro
if(sram.count(savename)) {
std::vector<char>& x = sram[savename];
if(r.size != x.size())
out(win) << "WARNING: SRAM '" << savename << "': Loaded " << x.size() << " bytes, "
<< " but the SRAM is " << r.size << "." << std::endl;
window::out() << "WARNING: SRAM '" << savename << "': Loaded " << x.size()
<< " bytes, but the SRAM is " << r.size << "." << std::endl;
memcpy(r.data, &x[0], (r.size < x.size()) ? r.size : x.size());
used.insert(savename);
} else
out(win) << "WARNING: SRAM '" << savename << ": No data." << std::endl;
window::out() << "WARNING: SRAM '" << savename << ": No data." << std::endl;
}
for(auto i = sram.begin(); i != sram.end(); ++i)
if(!used.count(i->first))
out(win) << "WARNING: SRAM '" << i->first << ": Not found on cartridge." << std::endl;
window::out() << "WARNING: SRAM '" << i->first << ": Not found on cartridge." << std::endl;
}
std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline)

13
rom.hpp
View file

@ -2,7 +2,6 @@
#define _rom__hpp__included__
#include <string>
#include "window.hpp"
#include <map>
#include <vector>
#include <stdexcept>
@ -193,11 +192,10 @@ struct rom_files
* Reads the filenames out of command line arguments given.
*
* parameter cmdline: The commmand line
* parameter win: Window system handle.
* throws std::bad_alloc: Not enough memory
* throws std::runtime_error: Failed to load ROM filenames.
*/
rom_files(const std::vector<std::string>& cmdline, window* win) throw(std::bad_alloc, std::runtime_error);
rom_files(const std::vector<std::string>& cmdline) throw(std::bad_alloc, std::runtime_error);
/**
* Resolve relative references.
@ -338,11 +336,10 @@ struct loaded_rom
* Takes in collection of ROM filenames and loads them into memory.
*
* parameter files: The files to load
* parameter win: Window system handle.
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Loading ROM files failed.
*/
loaded_rom(const rom_files& files, window* win) throw(std::bad_alloc, std::runtime_error);
loaded_rom(const rom_files& files) throw(std::bad_alloc, std::runtime_error);
/**
* ROM type
*/
@ -384,11 +381,10 @@ struct loaded_rom
* Patch the ROM.
*
* parameter cmdline: The command line.
* parameter win: Graphics system handle.
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Failed to patch the ROM.
*/
void do_patch(const std::vector<std::string>& cmdline, window* win) throw(std::bad_alloc, std::runtime_error);
void do_patch(const std::vector<std::string>& cmdline) throw(std::bad_alloc, std::runtime_error);
/**
* Switches the active cartridge to this cartridge. The compatiblity between selected region and original region
@ -449,10 +445,9 @@ std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc);
* Write contents of saved SRAMs into current system SRAMs.
*
* parameter sram: Saved SRAM contents.
* parameter win: Window system handle.
* throws std::bad_alloc: Out of memory.
*/
void load_sram(std::map<std::string, std::vector<char>>& sram, window* win) throw(std::bad_alloc);
void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc);
/**
* Read SRAMs from command-line and and load the files.

View file

@ -80,7 +80,7 @@ void rrdata::read_base(const std::string& project) throw(std::bad_alloc)
if(project == current_project)
return;
std::set<rrdata::instance> new_rrset;
std::string filename = get_config_path(NULL) + "/" + project + ".rr";
std::string filename = get_config_path() + "/" + project + ".rr";
if(handle_open) {
ohandle.close();
handle_open = false;

View file

@ -1,5 +1,6 @@
#include "settings.hpp"
#include "misc.hpp"
#include "window.hpp"
#include <map>
#include <sstream>
#include "misc.hpp"
@ -14,7 +15,7 @@ namespace
{
public:
set_command() throw(std::bad_alloc) : command("set-setting") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
std::string syntax = "Syntax: set-setting <setting> [<value>]";
tokensplitter t(args);
@ -23,7 +24,8 @@ namespace
if(settingname == "")
throw std::runtime_error("Setting name required.");
setting::set(settingname, settingvalue);
out(win) << "Setting '" << settingname << "' set to '" << settingvalue << "'" << std::endl;
window::out() << "Setting '" << settingname << "' set to '" << settingvalue << "'"
<< std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "set a setting"; }
std::string get_long_help() throw(std::bad_alloc)
@ -37,7 +39,7 @@ namespace
{
public:
unset_command() throw(std::bad_alloc) : command("unset-setting") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
std::string syntax = "Syntax: unset-setting <setting>";
tokensplitter t(args);
@ -45,7 +47,7 @@ namespace
if(settingname == "" || t)
throw std::runtime_error("Expected setting name and nothing else");
setting::blank(settingname);
out(win) << "Setting '" << settingname << "' unset" << std::endl;
window::out() << "Setting '" << settingname << "' unset" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "unset a setting"; }
std::string get_long_help() throw(std::bad_alloc)
@ -59,17 +61,17 @@ namespace
{
public:
get_command() throw(std::bad_alloc) : command("get-setting") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
std::string settingname = t;
if(settingname == "" || t.tail() != "")
throw std::runtime_error("Expected setting name and nothing else");
if(setting::is_set(settingname))
out(win) << "Setting '" << settingname << "' has value '" << setting::get(settingname)
<< "'" << std::endl;
window::out() << "Setting '" << settingname << "' has value '"
<< setting::get(settingname) << "'" << std::endl;
else
out(win) << "Setting '" << settingname << "' unset" << std::endl;
window::out() << "Setting '" << settingname << "' unset" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "get value of a setting"; }
std::string get_long_help() throw(std::bad_alloc)
@ -83,11 +85,11 @@ namespace
{
public:
shsettings_command() throw(std::bad_alloc) : command("show-settings") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
setting::print_all(out(win));
setting::print_all();
}
std::string get_short_help() throw(std::bad_alloc) { return "Show value of all settings"; }
std::string get_long_help() throw(std::bad_alloc)
@ -152,15 +154,15 @@ bool setting::is_set(const std::string& _setting) throw(std::bad_alloc, std::run
return (*settings)[_setting]->is_set();
}
void setting::print_all(std::ostream& os) throw(std::bad_alloc)
void setting::print_all() throw(std::bad_alloc)
{
if(!settings)
return;
for(auto i = settings->begin(); i != settings->end(); i++) {
if(!i->second->is_set())
os << i->first << ": (unset)" << std::endl;
window::out() << i->first << ": (unset)" << std::endl;
else
os << i->first << ": " << i->second->get() << std::endl;
window::out() << i->first << ": " << i->second->get() << std::endl;
}
}

View file

@ -97,10 +97,9 @@ public:
/**
* Print all settings and values.
*
* parameter os: Stream to print to.
* throws std::bad_alloc: Not enough memory.
*/
static void print_all(std::ostream& os) throw(std::bad_alloc);
static void print_all() throw(std::bad_alloc);
protected:
std::string settingname;
};

View file

@ -875,7 +875,6 @@ namespace
uint32_t vc_hscl = 1;
uint32_t vc_vscl = 1;
bool sdl_init;
window* win;
bool modconfirm;
bool modal_return_flag;
bool delayed_close_flag;
@ -988,9 +987,9 @@ namespace
void identify()
{
state = WINSTATE_IDENTIFY;
win->message("Press key to identify.");
win->notify_screen_update();
win->poll_inputs();
window::message("Press key to identify.");
window::notify_screen_update();
window::poll_inputs();
}
std::string decode_string(std::string e)
@ -1234,11 +1233,11 @@ namespace
switch(k.sym) {
case SDLK_INSERT:
command_overwrite = !command_overwrite;
win->notify_screen_update();
window::notify_screen_update();
return;
case SDLK_END:
command_cursor = command_buf.length();
win->notify_screen_update();
window::notify_screen_update();
return;
case SDLK_DOWN:
case SDLK_PAGEDOWN:
@ -1248,20 +1247,20 @@ namespace
if(command_cursor > command_buf.length())
command_cursor = command_buf.length();
}
win->notify_screen_update();
window::notify_screen_update();
return;
case SDLK_LEFT:
command_cursor = (command_cursor > 0) ? (command_cursor - 4) : 0;
win->notify_screen_update();
window::notify_screen_update();
return;
case SDLK_RIGHT:
command_cursor = (command_cursor < command_buf.length()) ? (command_cursor + 4) :
command_buf.length();
win->notify_screen_update();
window::notify_screen_update();
return;
case SDLK_HOME:
command_cursor = 0;
win->notify_screen_update();
window::notify_screen_update();
return;
case SDLK_UP:
case SDLK_PAGEUP: {
@ -1272,14 +1271,14 @@ namespace
if(command_cursor > command_buf.length())
command_cursor = command_buf.length();
}
win->notify_screen_update();
window::notify_screen_update();
return;
}
case SDLK_DELETE:
if(command_cursor < command_buf.length())
command_buf = command_buf.substr(0, command_cursor) +
command_buf.substr(command_cursor + 4);
win->notify_screen_update();
window::notify_screen_update();
*commandhistory_itr = command_buf;
return;
case SDLK_BACKSPACE:
@ -1288,7 +1287,7 @@ namespace
command_buf.substr(command_cursor);
command_cursor -= 4;
}
win->notify_screen_update();
window::notify_screen_update();
*commandhistory_itr = command_buf;
return;
default:
@ -1319,7 +1318,7 @@ namespace
command_cursor += 4;
}
*commandhistory_itr = command_buf;
win->notify_screen_update();
window::notify_screen_update();
}
void do_event(SDL_Event& e) throw(std::bad_alloc)
@ -1330,12 +1329,12 @@ namespace
exit(1);
if(e.type == SDL_USEREVENT && e.user.code == 0) {
if(screen_is_dirty)
win->notify_screen_update();
window::notify_screen_update();
}
SDLKey key;
get_ticks_msec();
if(e.type == SDL_ACTIVEEVENT && e.active.gain && e.active.state == SDL_APPACTIVE) {
win->notify_screen_update();
window::notify_screen_update();
return;
}
if(e.type == SDL_KEYDOWN || e.type == SDL_KEYUP)
@ -1348,7 +1347,7 @@ namespace
return;
}
if(e.type == SDL_QUIT) {
command::invokeC("quit-emulator", win);
command::invokeC("quit-emulator");
state = WINSTATE_NORMAL;
return;
}
@ -1381,7 +1380,7 @@ namespace
{
std::ostringstream x;
x << "mouse_button " << xc << " " << yc << " " << mouse_mask;
command::invokeC(x.str(), win);
command::invokeC(x.str());
}
}
if(e.type == SDL_KEYDOWN && key == SDLK_ESCAPE)
@ -1394,7 +1393,7 @@ namespace
if(commandhistory.size() > MAXHISTORY)
commandhistory.pop_back();
commandhistory_itr = commandhistory.begin();
win->notify_screen_update();
window::notify_screen_update();
return;
}
{
@ -1405,7 +1404,7 @@ namespace
if(i.symbol.device != SDL_DEV_NONE)
cmd = mapper.map(i.symbol, i.polarity);
if(cmd != "")
command::invokeC(cmd, win);
command::invokeC(cmd);
more = i.more;
}
return;
@ -1417,14 +1416,14 @@ namespace
modconfirm = false;
modal_return_flag = true;
modmsg = "";
win->notify_screen_update(true);
window::notify_screen_update(true);
return;
}
if(e.type == SDL_KEYUP && (key == SDLK_RETURN || key == SDLK_KP_ENTER)) {
state = WINSTATE_NORMAL;
modal_return_flag = true;
modmsg = "";
win->notify_screen_update(true);
window::notify_screen_update(true);
return;
}
break;
@ -1432,7 +1431,7 @@ namespace
if(e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_ESCAPE) {
state = WINSTATE_NORMAL;
command_buf = "";
win->notify_screen_update();
window::notify_screen_update();
if(commandhistory.front() == "")
commandhistory.pop_front();
return;
@ -1442,9 +1441,9 @@ namespace
state = WINSTATE_NORMAL;
if(commandhistory.front() == "")
commandhistory.pop_front();
command::invokeC(decode_string(command_buf), win);
command::invokeC(decode_string(command_buf));
command_buf = "";
win->notify_screen_update();
window::notify_screen_update();
autorepeat_phase = 0;
return;
}
@ -1471,13 +1470,13 @@ namespace
case WINSTATE_IDENTIFY:
auto i = keymapper_helper_sdl::translate_event(e);
if(!i.polarity && i.symbol.device != SDL_DEV_NONE)
win->modal_message(keymapper_helper_sdl::print_key_info(i.symbol), false);
window::modal_message(keymapper_helper_sdl::print_key_info(i.symbol), false);
break;
};
}
}
window::window()
void window::init()
{
signal(SIGALRM, sigalrm_handler);
alarm(WATCHDOG_TIMEOUT);
@ -1495,8 +1494,6 @@ window::window()
sdl_init = true;
tid = SDL_AddTimer(MIN_UPDATE_TIME, timer_cb, NULL);
}
i = NULL;
win = this;
state = WINSTATE_NORMAL;
current_screen = NULL;
pause_active = false;
@ -1539,7 +1536,7 @@ window::window()
SDL_PauseAudio(0);
}
window::~window()
void window::quit()
{
time_t curtime = time(NULL);
struct tm* tm = localtime(&curtime);
@ -1566,7 +1563,7 @@ bool window::modal_message(const std::string& msg, bool confirm) throw(std::bad_
bool ret = modconfirm;
if(delayed_close_flag) {
delayed_close_flag = false;
command::invokeC("quit-emulator", win);
command::invokeC("quit-emulator");
}
return ret;
}
@ -1792,7 +1789,7 @@ std::map<std::string, std::string>& window::get_emustatus() throw()
void window::dumpbindings() throw(std::bad_alloc)
{
mapper.dumpbindings(this);
mapper.dumpbindings();
}
void window::paused(bool enable) throw()
@ -1813,13 +1810,13 @@ namespace
{
public:
enable_sound_cmd() throw(std::bad_alloc) : command("enable-sound") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
std::string s = args;
if(s == "on" || s == "true" || s == "1" || s == "enable" || s == "enabled")
win->sound_enable(true);
window::sound_enable(true);
else if(s == "off" || s == "false" || s == "0" || s == "disable" || s == "disabled")
win->sound_enable(false);
window::sound_enable(false);
else
throw std::runtime_error("Bad sound setting");
}
@ -1835,7 +1832,7 @@ namespace
{
public:
identify_cmd() throw(std::bad_alloc) : command("identify-key") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
@ -1853,7 +1850,7 @@ namespace
{
public:
scrollup_cmd() throw(std::bad_alloc) : command("scroll-up") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
@ -1863,7 +1860,7 @@ namespace
messagebuffer_first_show = 0;
if(messagebuffer_first_show < messagebuffer_first_seq)
messagebuffer_first_show = messagebuffer_first_seq;
win->notify_screen_update();
window::notify_screen_update();
}
std::string get_short_help() throw(std::bad_alloc) { return "Scroll console back one page"; }
std::string get_long_help() throw(std::bad_alloc)
@ -1877,12 +1874,12 @@ namespace
{
public:
scrollfullup_cmd() throw(std::bad_alloc) : command("scroll-fullup") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
messagebuffer_first_show = messagebuffer_first_seq;
win->notify_screen_update();
window::notify_screen_update();
}
std::string get_short_help() throw(std::bad_alloc) { return "Scroll console to beginning"; }
std::string get_long_help() throw(std::bad_alloc)
@ -1896,7 +1893,7 @@ namespace
{
public:
scrollfulldown_cmd() throw(std::bad_alloc) : command("scroll-fulldown") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
@ -1904,7 +1901,7 @@ namespace
messagebuffer_first_show = 0;
else
messagebuffer_first_show = messagebuffer_next_seq - maxmessages;
win->notify_screen_update();
window::notify_screen_update();
}
std::string get_short_help() throw(std::bad_alloc) { return "Scroll console to end"; }
std::string get_long_help() throw(std::bad_alloc)
@ -1918,7 +1915,7 @@ namespace
{
public:
scrolldown_cmd() throw(std::bad_alloc) : command("scroll-down") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
@ -1927,7 +1924,7 @@ namespace
messagebuffer_first_show = 0;
else if(messagebuffer_next_seq < messagebuffer_first_show + maxmessages)
messagebuffer_first_show = messagebuffer_next_seq - maxmessages;
win->notify_screen_update();
window::notify_screen_update();
}
std::string get_short_help() throw(std::bad_alloc) { return "Scroll console one page forward"; }
std::string get_long_help() throw(std::bad_alloc)
@ -1941,7 +1938,7 @@ namespace
{
public:
toggleconsole_cmd() throw(std::bad_alloc) : command("toggle-console") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take arguments");
@ -1954,7 +1951,7 @@ namespace
messagebuffer_first_show = 0;
else
messagebuffer_first_show = messagebuffer_next_seq - maxmessages;
win->notify_screen_update(true);
window::notify_screen_update(true);
}
std::string get_short_help() throw(std::bad_alloc) { return "Toggle console between small and full "
"window"; }

View file

@ -15,8 +15,7 @@ namespace
public:
typedef char char_type;
typedef boost::iostreams::sink_tag category;
window_output(window* _win)
: win(_win)
window_output(window* win)
{
}
@ -39,7 +38,7 @@ namespace
if(lf == stream.size())
break;
std::string foo(stream.begin(), stream.begin() + lf);
win->message(foo);
window::message(foo);
if(lf + 1 < stream.size())
memmove(&stream[0], &stream[lf + 1], stream.size() - lf - 1);
stream.resize(stream.size() - lf - 1);
@ -48,14 +47,14 @@ namespace
}
protected:
std::vector<char> stream;
window* win;
};
}
std::ostream& window::out() throw(std::bad_alloc)
{
static std::ostream* cached = NULL;
window* win = NULL;
if(!cached)
cached = new boost::iostreams::stream<window_output>(this);
cached = new boost::iostreams::stream<window_output>(win);
return *cached;
}

View file

@ -13,7 +13,6 @@
#define WINSTATE_MODAL 2
#define WINSTATE_IDENTIFY 3
class window_internal;
class window;
/**
@ -22,15 +21,17 @@ class window;
class window
{
public:
window() throw() {}
/**
* Create a graphics system handle, initializing the graphics system.
* Initialize the graphics system.
*/
window();
static void init();
/**
* Destroy a graphics system handle, shutting down the graphics system.
* Shut down the graphics system.
*/
~window();
static void quit();
/**
* Adds a messages to mesage queue to be shown.
@ -38,7 +39,7 @@ public:
* parameter msg: The messages to add (split by '\n').
* throws std::bad_alloc: Not enough memory.
*/
void message(const std::string& msg) throw(std::bad_alloc);
static void message(const std::string& msg) throw(std::bad_alloc);
/**
* Get output stream printing into message queue.
@ -48,7 +49,7 @@ public:
* returns: The output stream.
* throws std::bad_alloc: Not enough memory.
*/
std::ostream& out() throw(std::bad_alloc);
static std::ostream& out() throw(std::bad_alloc);
/**
* Displays a modal message, not returning until the message is acknowledged. Keybindings are not available, but
@ -59,12 +60,12 @@ public:
* returns: If confirm is true, true if ok was chosen, false if cancel was chosen. Otherwise always false.
* throws std::bad_alloc: Not enough memory.
*/
bool modal_message(const std::string& msg, bool confirm = false) throw(std::bad_alloc);
static bool modal_message(const std::string& msg, bool confirm = false) throw(std::bad_alloc);
/**
* Displays fatal error message, quitting after the user acks it.
*/
void fatal_error() throw();
static void fatal_error() throw();
/**
* Bind a key.
@ -76,7 +77,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Invalid key or modifier name, or conflict.
*/
void bind(std::string mod, std::string modmask, std::string keyname, std::string command)
static void bind(std::string mod, std::string modmask, std::string keyname, std::string command)
throw(std::bad_alloc, std::runtime_error);
/**
@ -88,7 +89,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Invalid key or modifier name, or not bound.
*/
void unbind(std::string mod, std::string modmask, std::string keyname) throw(std::bad_alloc,
static void unbind(std::string mod, std::string modmask, std::string keyname) throw(std::bad_alloc,
std::runtime_error);
/**
@ -96,7 +97,7 @@ public:
*
* throws std::bad_alloc: Not enough memory.
*/
void dumpbindings() throw(std::bad_alloc);
static void dumpbindings() throw(std::bad_alloc);
/**
* Processes inputs. If in non-modal mode (normal mode without pause), this returns quickly. Otherwise it waits
@ -104,35 +105,35 @@ public:
*
* throws std::bad_alloc: Not enough memory.
*/
void poll_inputs() throw(std::bad_alloc);
static void poll_inputs() throw(std::bad_alloc);
/**
* Get emulator status area
*
* returns: Emulator status area.
*/
std::map<std::string, std::string>& get_emustatus() throw();
static std::map<std::string, std::string>& get_emustatus() throw();
/**
* Notify that the screen has been updated.
*
* parameter full: Do full refresh if true.
*/
void notify_screen_update(bool full = false) throw();
static void notify_screen_update(bool full = false) throw();
/**
* Set the screen to use as main surface.
*
* parameter scr: The screen to use.
*/
void set_main_surface(screen& scr) throw();
static void set_main_surface(screen& scr) throw();
/**
* Enable/Disable pause mode.
*
* parameter enable: Enable pause if true, disable otherwise.
*/
void paused(bool enable) throw();
static void paused(bool enable) throw();
/**
* Wait specified number of milliseconds (polling for input).
@ -140,19 +141,19 @@ public:
* parameter msec: Number of ms to wait.
* throws std::bad_alloc: Not enough memory.
*/
void wait_msec(uint64_t msec) throw(std::bad_alloc);
static void wait_msec(uint64_t msec) throw(std::bad_alloc);
/**
* Cancel pending wait_msec, making it return now.
*/
void cancel_wait() throw();
static void cancel_wait() throw();
/**
* Enable or disable sound.
*
* parameter enable: Enable sounds if true, otherwise disable sounds.
*/
void sound_enable(bool enable) throw();
static void sound_enable(bool enable) throw();
/**
* Input audio sample (at 32040.5Hz).
@ -160,8 +161,7 @@ public:
* parameter left: Left sample.
* parameter right: Right sample.
*/
void play_audio_sample(uint16_t left, uint16_t right) throw();
static void play_audio_sample(uint16_t left, uint16_t right) throw();
/**
* Set window main screen compensation parameters. This is used for mouse click reporting.
@ -171,9 +171,8 @@ public:
* parameter hscl: Horizontal scaling factor.
* parameter vscl: Vertical scaling factor.
*/
void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl);
static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl);
private:
window_internal* i;
window(const window&);
window& operator==(const window&);
};