Remove more old crapola
This commit is contained in:
parent
f41e3000bc
commit
a25f546417
14 changed files with 325 additions and 1346 deletions
|
@ -2,9 +2,7 @@
|
|||
#define _settings__hpp__included__
|
||||
|
||||
#include "library/settings.hpp"
|
||||
#include "library/settings-cmd-bridge.hpp"
|
||||
|
||||
extern setting_group lsnes_set;
|
||||
extern settings_command_bridge cmd_bridge;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,7 +69,7 @@ private:
|
|||
mutex_class int_mutex;
|
||||
std::ostream* output;
|
||||
void (*oom_panic_routine)();
|
||||
command* builtin[4];
|
||||
command* builtin[1];
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef _library__settings_cmd_bridge__hpp__included__
|
||||
#define _library__settings_cmd_bridge__hpp__included__
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
/**
|
||||
* Bridge between command group and settings group.
|
||||
*/
|
||||
class settings_command_bridge
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a bridge.
|
||||
*/
|
||||
settings_command_bridge(setting_group& sgroup, command_group& cgroup, const std::string& set_cmd,
|
||||
const std::string& unset_cmd, const std::string& get_cmd, const std::string& show_cmd);
|
||||
/**
|
||||
* Destroy a bridge.
|
||||
*/
|
||||
~settings_command_bridge() throw();
|
||||
/**
|
||||
* Set output to use.
|
||||
*/
|
||||
void set_output(std::ostream& out);
|
||||
private:
|
||||
command* c1;
|
||||
command* c2;
|
||||
command* c3;
|
||||
command* c4;
|
||||
std::ostream* output;
|
||||
};
|
||||
|
||||
#endif
|
401
manual.lyx
401
manual.lyx
|
@ -496,223 +496,6 @@ If command starts with '+' (after possible '*'), the command is executed
|
|||
Commands without '+' execute only on negative edge (release).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Settings:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Settings control various aspects of emulator behaviour.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
set-setting <setting> <value>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Sets setting <setting> to value <value> (may be empty).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
unset-setting <setting>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Try to unset setting <setting> (not all settings can be unset).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
get-setting <setting>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Read value of setting <setting>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
show-settings
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print names and values of all settings.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Keybindings
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Keybindings bind commands or aliases to keys (or pseudo-keys).
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Notes:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Do not bind edge active (+/-) commands to keys with modifiers, that won't
|
||||
work right!
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Names of keys and modifiers are platform-dependent.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Be careful before binding pseudo-keys (such as joystick axes, buttons or
|
||||
hats) with modifiers.
|
||||
That may or may not work right.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
bind-key [<mod>/<modmask>] <key> <command>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Bind <command> to key <key> (activating if modifiers in <modmask> (comma-seperat
|
||||
ed list) are set as <mod> (comma-seperated list).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
The names of keys and modifiers are platform-dependent.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
unbind-key [<mod>/<modmask>] <key>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Unbind command from <key> (with specified <mod> and <modmask>).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
set-axis <axis> [disabled | axis | axis-inverse | pressure0- | pressure0+
|
||||
| pressure-0 | pressure-+ | pressure+0 | pressure+-] [minus=<val>] [zero=<val>]
|
||||
[plus=<val>] [tolerance=<val>]
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Set axis parameters for axis <axis>.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
disabled: Disable axis
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
axis: Normal axis
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
axis-inverse: Inverse axis
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure0-: Pressure sensitive.
|
||||
Released at 0, pressed at -.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure0+: Pressure sensitive.
|
||||
Released at 0, pressed at +.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure-0: Pressure sensitive.
|
||||
Released at -, pressed at 0.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure-+: Pressure sensitive.
|
||||
Released at -, pressed at +.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure+0: Pressure sensitive.
|
||||
Released at +, pressed at 0.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure+-: Pressure sensitive.
|
||||
Released at +, pressed at -.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
minus=<val>: Calibration at extreme minus position (-32768-32767)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
zero=<val>: Calibration at neutral position (-32768-32767)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
plus=<val>: Calibration at extreme plus position (-32768-32767)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
tolerance=<value>: Center band tolerance (0<x<1).
|
||||
The smaller the value, the more sensitive the control is.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
show-bindings
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print all key bindings in effect.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Aliases
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Aliases bind command to sequence of commands.
|
||||
After alias has been defined, it replaces the command it shadows.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Notes:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
You can't alias command to itself.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Aliases starting with +/- are edge active just like ordinary commands starting
|
||||
with +/-.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
One command can be aliased to multiple commands.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
alias-command <command> <expansion>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Append <expansion> to alias <command>.
|
||||
If alias does not already exist, it is created.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
unalias-command <command>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Clear alias expansion for <command>.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
show-aliases
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print all aliases and their expansions in effect.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
run-script <script>
|
||||
\end_layout
|
||||
|
@ -782,107 +565,6 @@ write-<size> <address> <value>
|
|||
Write <value> to byte in address <address>.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
search-memory reset
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Reset the memory search
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
search-memory count
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print number of candidates remaining
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
search-memory print
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print all candidates remaining
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
search-memory <usflag><sizeflag><op>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Searches memory for addresses satisfying criteria.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
<usflag> can be:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
u: unsigned
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
s: signed
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
<sizeflag> can be:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
b: byte
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
w: word
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
d: dword
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
q: qword
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
<op> can be:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
lt: < previous value.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
le: <= previous value.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
eq: = previous value.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
ne: != previous value.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
ge: >= previous value.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
gt: > previous value.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
search-memory <sizeflag> <value>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Searches for addresses that currently have value <value>.
|
||||
<sizeflag> is as in previous command.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Main commands
|
||||
\end_layout
|
||||
|
@ -1025,57 +707,6 @@ toggle-rwmode
|
|||
Toggle between read-only and read-write modes.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
set-gamename <name>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Set name of the game to <name>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
get-gamename
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print the name of the game.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
add-author <author>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Adds new author <author>.
|
||||
If <author> does not contain '|' it is full name.
|
||||
If it contains '|', '|' splits the full name and nickname.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
edit-author <num> <author>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Edit the author in slot <num> (0-based) to be <author> (see add-author for
|
||||
format)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
remove-author <num>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Remove author in slot <num>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
print-authors
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Print authors.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
test-1, test-2, test-3
|
||||
\end_layout
|
||||
|
@ -2604,6 +2235,38 @@ Return the physical index, physical port and controller number in port for
|
|||
specified (1-based) logical controller.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Table keyboard
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Various keybinding-related functions
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
keyboard.bind(string mod, string mask, string key, string cmd)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Bind specified key with specified modifers to specified command.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
keyboard.unbind(string mod, string mask, string key)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Unbind specified key with specified modifers.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
keyboard.alias(string alias, string expansion)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Set expansion of given command.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Table subtitle
|
||||
\end_layout
|
||||
|
|
491
manual.txt
491
manual.txt
File diff suppressed because it is too large
Load diff
|
@ -18,44 +18,6 @@
|
|||
|
||||
keyboard lsnes_kbd;
|
||||
|
||||
namespace
|
||||
{
|
||||
function_ptr_command<const std::string&> bind_key(lsnes_cmd, "bind-key", "Bind a (pseudo-)key",
|
||||
"Syntax: bind-key [<mod>/<modmask>] <key> <command>\nBind command to specified key (with specified "
|
||||
" modifiers)\n",
|
||||
[](const std::string& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
auto r = regex("(([^ /\t]*)/([^ /\t]*)[ \t]+)?([^ \t]+)[ \t]+([^ \t].*)", t,
|
||||
"Key and command required");
|
||||
keymapper::bind(r[2], r[3], r[4], r[5]);
|
||||
if(r[2] != "" || r[3] != "")
|
||||
messages << r[2] << "/" << r[3] << " ";
|
||||
messages << r[4] << " bound to '" << r[5] << "'" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<const std::string&> unbind_key(lsnes_cmd, "unbind-key", "Unbind a (pseudo-)key",
|
||||
"Syntax: unbind-key [<mod>/<modmask>] <key>\nUnbind specified key (with specified modifiers)\n",
|
||||
[](const std::string& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
auto r = regex("(([^ /\t]*)/([^ /\t]*)[ \t]+)?([^ \t]+)[ \t]*", t, "Key required");
|
||||
keymapper::unbind(r[2], r[3], r[4]);
|
||||
if(r[2] != "" || r[3] != "")
|
||||
messages << r[2] << "/" << r[3] << " ";
|
||||
messages << r[4] << " unbound" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<> show_bindings(lsnes_cmd, "show-bindings", "Show active bindings",
|
||||
"Syntax: show-bindings\nShow bindings that are currently active.\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
keymapper::dumpbindings();
|
||||
});
|
||||
|
||||
function_ptr_command<> show_inverse(lsnes_cmd, "show-inverse", "Show inverse bindings",
|
||||
"Syntax: show-inverse\nShow inversebindings that are currently active.\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
for(auto i : inverse_key::get_ikeys())
|
||||
messages << i->getname() << ":" << i->get(true) << ":" << i->get(false) << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
std::string fixup_command_polarity(std::string cmd, bool polarity) throw(std::bad_alloc)
|
||||
{
|
||||
if(cmd == "" || cmd == "*")
|
||||
|
@ -96,90 +58,6 @@ namespace
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_command<const std::string&> set_axis(lsnes_cmd, "set-axis", "Set mode of Joystick axis",
|
||||
"Syntax: set-axis <axis> <options>...\nKnown options: disabled, axis, axis-inverse, pressure0-\n"
|
||||
"pressure0+, pressure-0, pressure-+, pressure+0, pressure+-\nminus=<val>, zero=<val>, plus=<val>\n"
|
||||
"tolerance=<val>\n",
|
||||
[](const std::string& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
auto r = regex("([^ \t]+)[ \t]+([^ \t].*)", t, "Axis name and option(s) required");
|
||||
auto axis = lsnes_kbd.try_lookup_key(r[1]);
|
||||
if(!axis)
|
||||
throw std::runtime_error("Unknown axis name");
|
||||
keyboard_key_axis* _axis = axis->cast_axis();
|
||||
if(!_axis)
|
||||
throw std::runtime_error("Not an axis");
|
||||
auto p = _axis->get_calibration();
|
||||
regex_results r2;
|
||||
std::string options = r[2];
|
||||
unsigned found_mask = 0;
|
||||
while(options != "") {
|
||||
std::string option;
|
||||
extract_token(options, option, " \t", true);
|
||||
unsigned optmask = 0;
|
||||
if(option == "disabled") {
|
||||
p.mode = -1;
|
||||
optmask = 1;
|
||||
} else if(option == "axis") {
|
||||
p.mode = 1; p.esign_a = -1; p.esign_b = 1;
|
||||
optmask = 1;
|
||||
} else if(option == "axis-inverse") {
|
||||
p.mode = 1; p.esign_a = 1; p.esign_b = -1;
|
||||
optmask = 1;
|
||||
} else if(option == "pressure0-") {
|
||||
p.mode = 0; p.esign_a = 0; p.esign_b = -1;
|
||||
optmask = 1;
|
||||
} else if(option == "pressure0+") {
|
||||
p.mode = 0; p.esign_a = 0; p.esign_b = 1;
|
||||
optmask = 1;
|
||||
} else if(option == "pressure-0") {
|
||||
p.mode = 0; p.esign_a = -1; p.esign_b = 0;
|
||||
optmask = 1;
|
||||
} else if(option == "pressure-+") {
|
||||
p.mode = 0; p.esign_a = -1; p.esign_b = 1;
|
||||
optmask = 1;
|
||||
} else if(option == "pressure+-") {
|
||||
p.mode = 0; p.esign_a = 1; p.esign_b = -1;
|
||||
optmask = 1;
|
||||
} else if(option == "pressure+0") {
|
||||
p.mode = 0; p.esign_a = 1; p.esign_b = 0;
|
||||
optmask = 1;
|
||||
} else if(r2 = regex("minus=([+-]?[0-9]+)", option)) {
|
||||
p.left = parse_value<int32_t>(r2[1]);
|
||||
optmask = 2;
|
||||
} else if(r2 = regex("zero=([+-]?[0-9]+)", option)) {
|
||||
p.center = parse_value<int32_t>(r2[1]);
|
||||
optmask = 4;
|
||||
} else if(r2 = regex("plus=([+-]?[0-9]+)", option)) {
|
||||
p.right = parse_value<int32_t>(r2[1]);
|
||||
optmask = 8;
|
||||
} else if(r2 = regex("tolerance=0?(\\.[0-9]+)", option)) {
|
||||
p.nullwidth = parse_value<double>(r2[1]);
|
||||
optmask = 16;
|
||||
} else
|
||||
throw std::runtime_error("Unknown axis option");
|
||||
if(found_mask & optmask)
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_mask |= optmask;
|
||||
}
|
||||
_axis->set_calibration(p);
|
||||
});
|
||||
|
||||
function_ptr_command<> set_axismode(lsnes_cmd, "show-axes", "Show all joystick axes",
|
||||
"Syntax: show-axes\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
for(auto i : lsnes_kbd.all_keys()) {
|
||||
keyboard_key_axis* j = i->cast_axis();
|
||||
if(!j)
|
||||
continue;
|
||||
auto p = j->get_calibration();
|
||||
std::string type = calibration_to_mode(p);
|
||||
messages << i->get_name() << " " << type << " -:" << p.left << " 0:"
|
||||
<< p.center << " +:" << p.right << " t:" << p.nullwidth
|
||||
<< std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
struct triple
|
||||
{
|
||||
triple(const std::string& _a, const std::string& _b, const std::string& _c)
|
||||
|
|
|
@ -255,155 +255,6 @@ namespace
|
|||
}
|
||||
};
|
||||
|
||||
struct simple_mem_commands
|
||||
{
|
||||
simple_mem_commands()
|
||||
{
|
||||
cmds["sblt"] = &memory_search::byte_slt;
|
||||
cmds["sble"] = &memory_search::byte_sle;
|
||||
cmds["sbeq"] = &memory_search::byte_seq;
|
||||
cmds["sbne"] = &memory_search::byte_sne;
|
||||
cmds["sbge"] = &memory_search::byte_sge;
|
||||
cmds["sbgt"] = &memory_search::byte_sgt;
|
||||
cmds["ublt"] = &memory_search::byte_ult;
|
||||
cmds["uble"] = &memory_search::byte_ule;
|
||||
cmds["ubeq"] = &memory_search::byte_ueq;
|
||||
cmds["ubne"] = &memory_search::byte_une;
|
||||
cmds["ubge"] = &memory_search::byte_uge;
|
||||
cmds["ubgt"] = &memory_search::byte_ugt;
|
||||
cmds["bseqlt"] = &memory_search::byte_seqlt;
|
||||
cmds["bseqle"] = &memory_search::byte_seqle;
|
||||
cmds["bseqge"] = &memory_search::byte_seqge;
|
||||
cmds["bseqgt"] = &memory_search::byte_seqgt;
|
||||
cmds["swlt"] = &memory_search::word_slt;
|
||||
cmds["swle"] = &memory_search::word_sle;
|
||||
cmds["sweq"] = &memory_search::word_seq;
|
||||
cmds["swne"] = &memory_search::word_sne;
|
||||
cmds["swge"] = &memory_search::word_sge;
|
||||
cmds["swgt"] = &memory_search::word_sgt;
|
||||
cmds["uwlt"] = &memory_search::word_ult;
|
||||
cmds["uwle"] = &memory_search::word_ule;
|
||||
cmds["uweq"] = &memory_search::word_ueq;
|
||||
cmds["uwne"] = &memory_search::word_une;
|
||||
cmds["uwge"] = &memory_search::word_uge;
|
||||
cmds["uwgt"] = &memory_search::word_ugt;
|
||||
cmds["wseqlt"] = &memory_search::word_seqlt;
|
||||
cmds["wseqle"] = &memory_search::word_seqle;
|
||||
cmds["wseqge"] = &memory_search::word_seqge;
|
||||
cmds["wseqgt"] = &memory_search::word_seqgt;
|
||||
cmds["sdlt"] = &memory_search::dword_slt;
|
||||
cmds["sdle"] = &memory_search::dword_sle;
|
||||
cmds["sdeq"] = &memory_search::dword_seq;
|
||||
cmds["sdne"] = &memory_search::dword_sne;
|
||||
cmds["sdge"] = &memory_search::dword_sge;
|
||||
cmds["sdgt"] = &memory_search::dword_sgt;
|
||||
cmds["udlt"] = &memory_search::dword_ult;
|
||||
cmds["udle"] = &memory_search::dword_ule;
|
||||
cmds["udeq"] = &memory_search::dword_ueq;
|
||||
cmds["udne"] = &memory_search::dword_une;
|
||||
cmds["udge"] = &memory_search::dword_uge;
|
||||
cmds["udgt"] = &memory_search::dword_ugt;
|
||||
cmds["dseqlt"] = &memory_search::dword_seqlt;
|
||||
cmds["dseqle"] = &memory_search::dword_seqle;
|
||||
cmds["dseqge"] = &memory_search::dword_seqge;
|
||||
cmds["dseqgt"] = &memory_search::dword_seqgt;
|
||||
cmds["sqlt"] = &memory_search::qword_slt;
|
||||
cmds["sqle"] = &memory_search::qword_sle;
|
||||
cmds["sqeq"] = &memory_search::qword_seq;
|
||||
cmds["sqne"] = &memory_search::qword_sne;
|
||||
cmds["sqge"] = &memory_search::qword_sge;
|
||||
cmds["sqgt"] = &memory_search::qword_sgt;
|
||||
cmds["uqlt"] = &memory_search::qword_ult;
|
||||
cmds["uqle"] = &memory_search::qword_ule;
|
||||
cmds["uqeq"] = &memory_search::qword_ueq;
|
||||
cmds["uqne"] = &memory_search::qword_une;
|
||||
cmds["uqge"] = &memory_search::qword_uge;
|
||||
cmds["uqgt"] = &memory_search::qword_ugt;
|
||||
cmds["qseqlt"] = &memory_search::qword_seqlt;
|
||||
cmds["qseqle"] = &memory_search::qword_seqle;
|
||||
cmds["qseqge"] = &memory_search::qword_seqge;
|
||||
cmds["qseqgt"] = &memory_search::qword_seqgt;
|
||||
}
|
||||
std::map<std::string, void (memory_search::*)()> cmds;
|
||||
} simple_cmds;
|
||||
|
||||
class memorysearch_command : public memorymanip_command
|
||||
{
|
||||
public:
|
||||
memorysearch_command() throw(std::bad_alloc) : memorymanip_command("search-memory") {}
|
||||
void invoke2() throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(!isrch)
|
||||
isrch = new memory_search(lsnes_memory);
|
||||
if(simple_cmds.cmds.count(firstword) && !has_value)
|
||||
(isrch->*(simple_cmds.cmds[firstword]))();
|
||||
else if(firstword == "b" && has_value) {
|
||||
if(static_cast<int64_t>(value) < -128 || value > 255)
|
||||
throw std::runtime_error("Value to compare out of range");
|
||||
isrch->byte_value(value & 0xFF);
|
||||
} else if(firstword == "bdiff" && has_value) {
|
||||
if(static_cast<int64_t>(value) < -128 || value > 255)
|
||||
throw std::runtime_error("Value to compare out of range");
|
||||
isrch->byte_difference(value & 0xFF);
|
||||
} else if(firstword == "w" && has_value) {
|
||||
if(static_cast<int64_t>(value) < -32768 || value > 65535)
|
||||
throw std::runtime_error("Value to compare out of range");
|
||||
isrch->word_value(value & 0xFFFF);
|
||||
} else if(firstword == "wdiff" && has_value) {
|
||||
if(static_cast<int64_t>(value) < -32768 || value > 65535)
|
||||
throw std::runtime_error("Value to compare out of range");
|
||||
isrch->word_difference(value & 0xFFFF);
|
||||
} else if(firstword == "d" && has_value) {
|
||||
if(static_cast<int64_t>(value) < -2147483648LL || value > 4294967295ULL)
|
||||
throw std::runtime_error("Value to compare out of range");
|
||||
isrch->dword_value(value & 0xFFFFFFFFULL);
|
||||
} else if(firstword == "ddiff" && has_value) {
|
||||
if(static_cast<int64_t>(value) < -2147483648LL || value > 4294967295ULL)
|
||||
throw std::runtime_error("Value to compare out of range");
|
||||
isrch->dword_difference(value & 0xFFFFFFFFULL);
|
||||
} else if(firstword == "q" && has_value)
|
||||
isrch->qword_value(value);
|
||||
else if(firstword == "qdiff" && has_value)
|
||||
isrch->qword_difference(value);
|
||||
else if(firstword == "disqualify" && has_value)
|
||||
isrch->dq_range(value, value);
|
||||
else if(firstword == "disqualify_vma" && has_value) {
|
||||
auto r = lsnes_memory.lookup(value);
|
||||
if(r.first)
|
||||
isrch->dq_range(r.first->base, r.first->last_address());
|
||||
} else if(firstword == "update" && !has_value)
|
||||
isrch->update();
|
||||
else if(firstword == "reset" && !has_value)
|
||||
isrch->reset();
|
||||
else if(firstword == "count" && !has_value)
|
||||
;
|
||||
else if(firstword == "print" && !has_value) {
|
||||
auto c = isrch->get_candidates();
|
||||
for(auto ci : c) {
|
||||
std::ostringstream x;
|
||||
x << "0x" << std::hex << std::setw(8) << std::setfill('0') << ci;
|
||||
messages << x.str() << std::endl;
|
||||
}
|
||||
} else
|
||||
throw std::runtime_error("Unknown memorysearch subcommand '" + firstword + "'");
|
||||
messages << 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)
|
||||
{
|
||||
return "Syntax: " + _command + " {s,u}{b,w,d,q}{lt,le,eq,ne,ge,gt}\n"
|
||||
"Syntax: " + _command + " {b,w,d,q}seq{lt,le,ge,gt}\n"
|
||||
"Syntax: " + _command + " {b,w,d,q} <value>\n"
|
||||
"Syntax: " + _command + " {b,w,d,q}diff <value>\n"
|
||||
"Syntax: " + _command + " disqualify{,_vma} <address>\n"
|
||||
"Syntax: " + _command + " update\n"
|
||||
"Syntax: " + _command + " reset\n"
|
||||
"Syntax: " + _command + " count\n"
|
||||
"Syntax: " + _command + " print\n"
|
||||
"Searches addresses from memory.\n";
|
||||
}
|
||||
} memorysearch_o;
|
||||
|
||||
read_command<uint8_t, &memory_space::read<uint8_t>> ru1("read-byte");
|
||||
read_command<uint16_t, &memory_space::read<uint16_t>> ru2("read-word");
|
||||
read_command<uint32_t, &memory_space::read<uint32_t>> ru4("read-dword");
|
||||
|
|
|
@ -254,7 +254,6 @@ void reached_main()
|
|||
init_threaded_malloc();
|
||||
lsnes_cmd.set_oom_panic(OOM_panic);
|
||||
lsnes_cmd.set_output(platform::out());
|
||||
cmd_bridge.set_output(platform::out());
|
||||
}
|
||||
|
||||
std::string bsnes_core_version;
|
||||
|
|
|
@ -98,60 +98,6 @@ namespace
|
|||
}
|
||||
} mprefix;
|
||||
|
||||
function_ptr_command<> get_gamename(lsnes_cmd, "get-gamename", "Get the game name",
|
||||
"Syntax: get-gamename\nPrints the game name\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
messages << "Game name is '" << our_movie.gamename << "'" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<const std::string&> set_gamename(lsnes_cmd, "set-gamename", "Set the game name",
|
||||
"Syntax: set-gamename <name>\nSets the game name to <name>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
our_movie.gamename = args;
|
||||
messages << "Game name changed to '" << our_movie.gamename << "'" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<> show_authors(lsnes_cmd, "show-authors", "Show the run authors",
|
||||
"Syntax: show-authors\nShows the run authors\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
size_t idx = 0;
|
||||
for(auto i : our_movie.authors) {
|
||||
messages << (idx++) << ": " << i.first << "|" << i.second << std::endl;
|
||||
}
|
||||
messages << "End of authors list" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<const std::string&> add_author(lsnes_cmd, "add-author", "Add an author",
|
||||
"Syntax: add-author <fullname>\nSyntax: add-author |<nickname>\n"
|
||||
"Syntax: add-author <fullname>|<nickname>\nAdds a new author\n",
|
||||
[](const std::string& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
auto g = split_author(t);
|
||||
our_movie.authors.push_back(g);
|
||||
messages << (our_movie.authors.size() - 1) << ": " << g.first << "|" << g.second << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<const std::string&> remove_author(lsnes_cmd, "remove-author", "Remove an author",
|
||||
"Syntax: remove-author <id>\nRemoves author with ID <id>\n",
|
||||
[](const std::string& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
uint64_t index = parse_value<uint64_t>(t);
|
||||
if(index >= our_movie.authors.size())
|
||||
throw std::runtime_error("No such author");
|
||||
our_movie.authors.erase(our_movie.authors.begin() + index);
|
||||
});
|
||||
|
||||
function_ptr_command<const std::string&> edit_author(lsnes_cmd, "edit-author", "Edit an author",
|
||||
"Syntax: edit-author <authorid> <fullname>\nSyntax: edit-author <authorid> |<nickname>\n"
|
||||
"Syntax: edit-author <authorid> <fullname>|<nickname>\nEdits author name\n",
|
||||
[](const std::string& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
auto r = regex("([^ \t]+)[ \t]+(|[^ \t].*)", t, "Index and author required.");
|
||||
uint64_t index = parse_value<uint64_t>(r[1]);
|
||||
if(index >= our_movie.authors.size())
|
||||
throw std::runtime_error("No such author");
|
||||
auto g = split_author(r[2]);
|
||||
our_movie.authors[index] = g;
|
||||
});
|
||||
|
||||
function_ptr_command<const std::string&> dump_coresave(lsnes_cmd, "dump-coresave", "Dump bsnes core state",
|
||||
"Syntax: dump-coresave <name>\nDumps core save to <name>\n",
|
||||
[](const std::string& name) throw(std::bad_alloc, std::runtime_error) {
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
#include "core/command.hpp"
|
||||
#include "core/settings.hpp"
|
||||
#include "library/settings-cmd-bridge.hpp"
|
||||
|
||||
setting_group lsnes_set;
|
||||
settings_command_bridge cmd_bridge(lsnes_set, lsnes_cmd, "set-setting", "unset-setting", "get-setting",
|
||||
"show-settings");
|
||||
|
|
|
@ -55,120 +55,6 @@ namespace
|
|||
std::ostream*& output;
|
||||
};
|
||||
|
||||
struct show_aliases : public command
|
||||
{
|
||||
show_aliases(command_group& group, std::ostream*& _output)
|
||||
: command(group, "show-aliases"), in_group(group), output(_output)
|
||||
{
|
||||
}
|
||||
|
||||
~show_aliases() throw()
|
||||
{
|
||||
}
|
||||
|
||||
void invoke(const std::string& filename) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(filename != "") {
|
||||
(*output) << "Syntax: show-aliases" << std::endl;
|
||||
return;
|
||||
}
|
||||
auto aliases = in_group.get_aliases();
|
||||
for(auto i : aliases) {
|
||||
std::string acmd = in_group.get_alias_for(i);
|
||||
while(acmd != "") {
|
||||
std::string j;
|
||||
extract_token(acmd, j, "\n");
|
||||
if(j != "")
|
||||
(*output) << "alias " << i << " " << j << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_short_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Show aliases";
|
||||
}
|
||||
|
||||
std::string get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Syntax: show-aliases\nShow expansions of all aliases\n";
|
||||
}
|
||||
|
||||
command_group& in_group;
|
||||
std::ostream*& output;
|
||||
};
|
||||
|
||||
struct unalias_command : public command
|
||||
{
|
||||
unalias_command(command_group& group, std::ostream*& _output)
|
||||
: command(group, "unalias-command"), in_group(group), output(_output)
|
||||
{
|
||||
}
|
||||
|
||||
~unalias_command() throw()
|
||||
{
|
||||
}
|
||||
|
||||
void invoke(const std::string& t) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
auto r = regex("([^ \t]+)[ \t]*", t, "This command only takes one argument");
|
||||
if(!in_group.valid_alias_name(r[1]))
|
||||
throw std::runtime_error("Illegal alias name");
|
||||
in_group.set_alias_for(r[1], "");
|
||||
(*output) << "Command '" << r[1] << "' unaliased" << std::endl;
|
||||
}
|
||||
|
||||
std::string get_short_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Unalias a command";
|
||||
}
|
||||
|
||||
std::string get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Syntax: unalias-command <aliasname>\nClear expansion of alias <aliasname>\n";
|
||||
}
|
||||
|
||||
command_group& in_group;
|
||||
std::ostream*& output;
|
||||
};
|
||||
|
||||
struct alias_command : public command
|
||||
{
|
||||
alias_command(command_group& group, std::ostream*& _output)
|
||||
: command(group, "alias-command"), in_group(group), output(_output)
|
||||
{
|
||||
}
|
||||
|
||||
~alias_command() throw()
|
||||
{
|
||||
}
|
||||
|
||||
void invoke(const std::string& t) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
auto r = regex("([^ \t]+)[ \t]+([^ \t].*)", t, "Alias name and command needed");
|
||||
if(!in_group.valid_alias_name(r[1]))
|
||||
throw std::runtime_error("Illegal alias name");
|
||||
std::string tmp = in_group.get_alias_for(r[1]);
|
||||
tmp = tmp + r[2] + "\n";
|
||||
in_group.set_alias_for(r[1], tmp);
|
||||
(*output) << "Command '" << r[1] << "' aliased to '" << r[2] << "'" << std::endl;
|
||||
}
|
||||
|
||||
std::string get_short_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Alias a command";
|
||||
}
|
||||
|
||||
std::string get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Syntax: alias-command <aliasname> <command>\nAppend <command> to expansion of alias "
|
||||
"<aliasname>\nValid alias names can't be empty nor start with '*' or '?'\n";
|
||||
}
|
||||
|
||||
command_group& in_group;
|
||||
std::ostream*& output;
|
||||
};
|
||||
|
||||
void default_oom_panic()
|
||||
{
|
||||
std::cerr << "PANIC: Fatal error, can't continue: Out of memory." << std::endl;
|
||||
|
@ -207,9 +93,6 @@ command_group::command_group() throw(std::bad_alloc)
|
|||
regqueue_t::do_ready(*this, true);
|
||||
//The builtin commands.
|
||||
builtin[0] = new run_script(*this, output);
|
||||
builtin[1] = new show_aliases(*this, output);
|
||||
builtin[2] = new unalias_command(*this, output);
|
||||
builtin[3] = new alias_command(*this, output);
|
||||
}
|
||||
|
||||
command_group::~command_group() throw()
|
||||
|
|
|
@ -1,147 +0,0 @@
|
|||
#include "settings-cmd-bridge.hpp"
|
||||
#include "string.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct set_setting_cmd : public command
|
||||
{
|
||||
set_setting_cmd(setting_group& _sgroup, command_group& _cgroup, const std::string& _cmd,
|
||||
std::ostream*& out)
|
||||
: command(_cgroup, _cmd), sgroup(_sgroup), output(out), cmd(_cmd)
|
||||
{
|
||||
}
|
||||
~set_setting_cmd() throw() {}
|
||||
void invoke(const std::string& t) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
auto r = regex("([^ \t]+)([ \t]+(|[^ \t].*))?", t, "Setting name required.");
|
||||
sgroup.set(r[1], r[3]);
|
||||
(*output) << "Setting '" << r[1] << "' set to '" << r[3] << "'" << std::endl;
|
||||
}
|
||||
std::string get_short_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Set a setting";
|
||||
}
|
||||
std::string get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Syntax: " + cmd + " <setting> [<value>]\nSet setting to a new value. Omit <value> "
|
||||
"to set to ''\n";
|
||||
}
|
||||
setting_group& sgroup;
|
||||
std::ostream*& output;
|
||||
std::string cmd;
|
||||
};
|
||||
|
||||
struct unset_setting_cmd : public command
|
||||
{
|
||||
unset_setting_cmd(setting_group& _sgroup, command_group& _cgroup, const std::string& _cmd,
|
||||
std::ostream*& out)
|
||||
: command(_cgroup, _cmd), sgroup(_sgroup), output(out), cmd(_cmd)
|
||||
{
|
||||
}
|
||||
~unset_setting_cmd() throw() {}
|
||||
void invoke(const std::string& t) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
auto r = regex("([^ \t]+)[ \t]*", t, "Expected setting name and nothing else");
|
||||
sgroup.blank(r[1]);
|
||||
(*output) << "Setting '" << r[1] << "' 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)
|
||||
{
|
||||
return "Syntax: " + cmd + " <setting>\nTry to unset a setting. Note that not all settings "
|
||||
"can be unset\n";
|
||||
}
|
||||
setting_group& sgroup;
|
||||
std::ostream*& output;
|
||||
std::string cmd;
|
||||
};
|
||||
|
||||
struct get_setting_cmd : public command
|
||||
{
|
||||
get_setting_cmd(setting_group& _sgroup, command_group& _cgroup, const std::string& _cmd,
|
||||
std::ostream*& out)
|
||||
: command(_cgroup, _cmd), sgroup(_sgroup), output(out), cmd(_cmd)
|
||||
{
|
||||
}
|
||||
~get_setting_cmd() throw() {}
|
||||
void invoke(const std::string& t) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
auto r = regex("([^ \t]+)[ \t]*", t, "Expected setting name and nothing else");
|
||||
if(sgroup.is_set(r[1]))
|
||||
(*output) << "Setting '" << r[1] << "' has value '"
|
||||
<< sgroup.get(r[1]) << "'" << std::endl;
|
||||
else
|
||||
(*output) << "Setting '" << r[1] << "' is 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)
|
||||
{
|
||||
return "Syntax: " + cmd + " <setting>\nShow value of setting\n";
|
||||
}
|
||||
setting_group& sgroup;
|
||||
std::ostream*& output;
|
||||
std::string cmd;
|
||||
};
|
||||
|
||||
struct show_setting_cmd : public command
|
||||
{
|
||||
show_setting_cmd(setting_group& _sgroup, command_group& _cgroup, const std::string& _cmd,
|
||||
std::ostream*& out)
|
||||
: command(_cgroup, _cmd), sgroup(_sgroup), output(out), cmd(_cmd)
|
||||
{
|
||||
}
|
||||
~show_setting_cmd() throw() {}
|
||||
void invoke(const std::string& t) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(t != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
for(auto i : sgroup.get_settings_set()) {
|
||||
if(!sgroup.is_set(i))
|
||||
(*output) << i << ": (unset)" << std::endl;
|
||||
else
|
||||
(*output) << i << ": " << sgroup.get(i) << std::endl;
|
||||
}
|
||||
}
|
||||
std::string get_short_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Sghow values of all settings";
|
||||
}
|
||||
std::string get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return "Syntax: " + cmd + "\nShow value of all settings\n";
|
||||
}
|
||||
setting_group& sgroup;
|
||||
std::ostream*& output;
|
||||
std::string cmd;
|
||||
};
|
||||
}
|
||||
|
||||
settings_command_bridge::settings_command_bridge(setting_group& sgroup, command_group& cgroup,
|
||||
const std::string& set_cmd, const std::string& unset_cmd, const std::string& get_cmd,
|
||||
const std::string& show_cmd)
|
||||
{
|
||||
output = &std::cerr;
|
||||
c1 = new set_setting_cmd(sgroup, cgroup, set_cmd, output);
|
||||
c2 = new unset_setting_cmd(sgroup, cgroup, unset_cmd, output);
|
||||
c3 = new get_setting_cmd(sgroup, cgroup, get_cmd, output);
|
||||
c4 = new show_setting_cmd(sgroup, cgroup, show_cmd, output);
|
||||
}
|
||||
|
||||
settings_command_bridge::~settings_command_bridge() throw()
|
||||
{
|
||||
delete c1;
|
||||
delete c2;
|
||||
delete c3;
|
||||
delete c4;
|
||||
}
|
||||
|
||||
void settings_command_bridge::set_output(std::ostream& out)
|
||||
{
|
||||
output = &out;
|
||||
}
|
46
src/lua/bind.cpp
Normal file
46
src/lua/bind.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "core/keymapper.hpp"
|
||||
#include "core/command.hpp"
|
||||
#include "lua/internal.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun kbind(LS, "keyboard.bind", [](lua_state& L, const std::string& fname) -> int {
|
||||
std::string mod = L.get_string(1, fname.c_str());
|
||||
std::string mask = L.get_string(2, fname.c_str());
|
||||
std::string key = L.get_string(3, fname.c_str());
|
||||
std::string cmd = L.get_string(4, fname.c_str());
|
||||
try {
|
||||
keymapper::bind(mod, mask, key, cmd);
|
||||
} catch(std::exception& e) {
|
||||
L.pushstring(e.what());
|
||||
L.error();
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
function_ptr_luafun kunbind(LS, "keyboard.unbind", [](lua_state& L, const std::string& fname) -> int {
|
||||
std::string mod = L.get_string(1, fname.c_str());
|
||||
std::string mask = L.get_string(2, fname.c_str());
|
||||
std::string key = L.get_string(3, fname.c_str());
|
||||
try {
|
||||
keymapper::unbind(mod, mask, key);
|
||||
} catch(std::exception& e) {
|
||||
L.pushstring(e.what());
|
||||
L.error();
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
function_ptr_luafun kalias(LS, "keyboard.alias", [](lua_state& L, const std::string& fname) -> int {
|
||||
std::string alias = L.get_string(1, fname.c_str());
|
||||
std::string cmds = L.get_string(2, fname.c_str());
|
||||
try {
|
||||
lsnes_cmd.set_alias_for(alias, cmds);
|
||||
} catch(std::exception& e) {
|
||||
L.pushstring(e.what());
|
||||
L.error();
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
|
@ -32,6 +32,7 @@
|
|||
#include <wx/control.h>
|
||||
#include <wx/combobox.h>
|
||||
#include <wx/cmdline.h>
|
||||
#include <iostream>
|
||||
|
||||
#define UISERV_RESIZED 9991
|
||||
#define UISERV_UIFUN 9992
|
||||
|
@ -167,9 +168,83 @@ end:
|
|||
wxPostEvent(ui_services, uic);
|
||||
}
|
||||
|
||||
void handle_config_line(std::string line)
|
||||
{
|
||||
regex_results r;
|
||||
if(r = regex("AXIS[ \t]+([^ \t]+)[ \t]+(-?[0-9])[ \t]+(-?[0-9])[ \t]+(-?[0-9])[ \t]+"
|
||||
"(-?[0-9]+)[ \t]+(-?[0-9]+)[ \t]+(-?[0-9]+)[ \t]+(0?.[0-9]+)[ \t]*", line)) {
|
||||
keyboard_axis_calibration c;
|
||||
c.mode = parse_value<int>(r[2]);
|
||||
if(c.mode < -1 || c.mode > 1) {
|
||||
messages << "Illegal axis mode " << c.mode << std::endl;
|
||||
return;
|
||||
}
|
||||
c.esign_a = parse_value<int>(r[3]);
|
||||
c.esign_b = parse_value<int>(r[4]);
|
||||
if(c.esign_a < -1 || c.esign_a > 1 || c.esign_b < -1 || c.esign_b > 1 ||
|
||||
c.esign_a == c.esign_b || (c.mode == 1 && (c.esign_a == 0 || c.esign_b == 0))) {
|
||||
messages << "Illegal axis endings " << c.esign_a << "/" << c.esign_b << std::endl;
|
||||
return;
|
||||
}
|
||||
c.left = parse_value<int32_t>(r[5]);
|
||||
c.center = parse_value<int32_t>(r[6]);
|
||||
c.right = parse_value<int32_t>(r[7]);
|
||||
c.nullwidth = parse_value<double>(r[8]);
|
||||
keyboard_key* _k = lsnes_kbd.try_lookup_key(r[1]);
|
||||
keyboard_key_axis* k = NULL;
|
||||
if(_k)
|
||||
k = _k->cast_axis();
|
||||
if(!k)
|
||||
return;
|
||||
k->set_calibration(c);
|
||||
messages << "Calibration of " << r[1] << " changed: mode=" << calibration_to_mode(c)
|
||||
<< " limits=" << c.left << "(" << c.center << ")" << c.right
|
||||
<< " null=" << c.nullwidth << std::endl;
|
||||
} else if(r = regex("UNSET[ \t]+([^ \t]+)[ \t]*", line)) {
|
||||
try {
|
||||
lsnes_set.blank(r[1]);
|
||||
messages << "Setting " << r[1] << " unset" << std::endl;
|
||||
} catch(std::exception& e) {
|
||||
messages << "Can't unset " << r[1] << ": " << e.what() << std::endl;
|
||||
}
|
||||
} else if(r = regex("SET[ \t]+([^ \t]+)[ \t]+(.*)", line)) {
|
||||
try {
|
||||
lsnes_set.set(r[1], r[2]);
|
||||
messages << "Setting " << r[1] << " set to " << r[2] << std::endl;
|
||||
} catch(std::exception& e) {
|
||||
messages << "Can't set " << r[1] << ": " << e.what() << std::endl;
|
||||
}
|
||||
} else if(r = regex("ALIAS[ \t]+([^ \t]+)[ \t]+(.*)", line)) {
|
||||
if(!lsnes_cmd.valid_alias_name(r[1])) {
|
||||
messages << "Illegal alias name " << r[1] << std::endl;
|
||||
return;
|
||||
}
|
||||
std::string tmp = lsnes_cmd.get_alias_for(r[1]);
|
||||
tmp = tmp + r[2] + "\n";
|
||||
lsnes_cmd.set_alias_for(r[1], tmp);
|
||||
messages << r[1] << " aliased to " << r[2] << std::endl;
|
||||
} else if(r = regex("BIND[ \t]+([^/]*)/([^|]*)\\|([^ \t]+)[ \t]+(.*)", line)) {
|
||||
keymapper::bind(r[1], r[2], r[3], r[4]);
|
||||
if(r[1] != "" || r[2] != "")
|
||||
messages << r[1] << "/" << r[2] << " ";
|
||||
messages << r[3] << " bound to '" << r[4] << "'" << std::endl;
|
||||
|
||||
} else
|
||||
messages << "Unrecognized directive: " << line << std::endl;
|
||||
}
|
||||
|
||||
void load_configuration()
|
||||
{
|
||||
std::string cfg = get_config_path() + "/lsneswxw.cfg";
|
||||
std::ifstream cfgfile(cfg.c_str());
|
||||
std::string line;
|
||||
while(std::getline(cfgfile, line))
|
||||
handle_config_line(line);
|
||||
}
|
||||
|
||||
void save_configuration()
|
||||
{
|
||||
std::string cfg = get_config_path() + "/lsneswxw.rc";
|
||||
std::string cfg = get_config_path() + "/lsneswxw.cfg";
|
||||
std::ofstream cfgfile(cfg.c_str());
|
||||
//Joystick axis.
|
||||
for(auto i : lsnes_kbd.all_keys()) {
|
||||
|
@ -177,19 +252,19 @@ end:
|
|||
if(!j)
|
||||
continue;
|
||||
auto p = j->get_calibration();
|
||||
cfgfile << "set-axis " << i->get_name() << " " << calibration_to_mode(p);
|
||||
cfgfile << " minus=" << p.left << " zero=" << p.center << " plus=" << p.right
|
||||
<< " tolerance=" << p.nullwidth << std::endl;
|
||||
cfgfile << "AXIS " << i->get_name() << " " << p.mode << " " << p.esign_a << " " << p.esign_b
|
||||
<< " " << p.left << " " << p.center << " " << p.right << " " << p.nullwidth
|
||||
<< std::endl;
|
||||
}
|
||||
//Settings.
|
||||
for(auto i : lsnes_set.get_settings_set()) {
|
||||
if(!lsnes_set.is_set(i))
|
||||
cfgfile << "unset-setting " << i << std::endl;
|
||||
cfgfile << "UNSET " << i << std::endl;
|
||||
else
|
||||
cfgfile << "set-setting " << i << " " << lsnes_set.get(i) << std::endl;
|
||||
cfgfile << "SET " << i << " " << lsnes_set.get(i) << std::endl;
|
||||
}
|
||||
for(auto i : lsnes_set.get_invalid_values())
|
||||
cfgfile << "set-setting " << i.first << " " << i.second << std::endl;
|
||||
cfgfile << "SET " << i.first << " " << i.second << std::endl;
|
||||
//Aliases.
|
||||
for(auto i : lsnes_cmd.get_aliases()) {
|
||||
std::string old_alias_value = lsnes_cmd.get_alias_for(i);
|
||||
|
@ -203,7 +278,7 @@ end:
|
|||
aliasline = old_alias_value;
|
||||
old_alias_value = "";
|
||||
}
|
||||
cfgfile << "alias-command " << i << " " << aliasline << std::endl;
|
||||
cfgfile << "ALIAS " << i << " " << aliasline << std::endl;
|
||||
}
|
||||
}
|
||||
//Keybindings.
|
||||
|
@ -217,11 +292,8 @@ end:
|
|||
std::string mod = i2.substr(0, s2);
|
||||
std::string modspec = i2.substr(s2 + 1, s - s2 - 1);
|
||||
std::string old_command_value = keymapper::get_command_for(i);
|
||||
if(mod != "" || modspec != "")
|
||||
cfgfile << "bind-key " << mod << "/" << modspec << " " << key << " "
|
||||
<< old_command_value << std::endl;
|
||||
else
|
||||
cfgfile << "bind-key " << key << " " << old_command_value << std::endl;
|
||||
cfgfile << "BIND " << mod << "/" << modspec << "|" << key << " "
|
||||
<< old_command_value << std::endl;
|
||||
}
|
||||
//Last save.
|
||||
std::ofstream lsave(get_config_path() + "/" + our_rom_name + ".ls");
|
||||
|
@ -367,9 +439,9 @@ bool lsnes_app::OnInit()
|
|||
|
||||
std::string cfgpath = get_config_path();
|
||||
messages << "Saving per-user data to: " << get_config_path() << std::endl;
|
||||
messages << "--- Running lsnesrc --- " << std::endl;
|
||||
messages << "--- Loading configuration --- " << std::endl;
|
||||
lsnes_set.set_storage_mode(true);
|
||||
lsnes_cmd.invoke("run-script " + cfgpath + "/lsneswxw.rc");
|
||||
load_configuration();
|
||||
lsnes_set.set_storage_mode(false);
|
||||
messages << "--- End running lsnesrc --- " << std::endl;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue