Added the ability to configure shortcuts and the NES pad from the command line.

This commit is contained in:
Fabio Cavallo 2024-02-10 14:14:15 +01:00
parent c3605836ca
commit 275865a75b
No known key found for this signature in database
GPG key ID: 35BA493A350CD00E
8 changed files with 200 additions and 121 deletions

View file

@ -10,6 +10,9 @@ Changelog:
- Rewritten the audio of the VRC7.
Implemented the project "A YM2413 emulator written in C" of okaxaki :
* https://github.com/digital-sound-antiques/emu2413
- Rewritten NSF player.
Added support to NSF2 format.
- Added the ability to configure shortcuts and the NES pad from the command line.
- Added support to Quick Disk format.
- Added an option for RAM initialization (#276).
It's possible to choose between three values:

View file

@ -100,12 +100,14 @@ static struct _cl_option {
{ "shader", req_arg, nullptr },
{ "overscan-blk-brd", req_arg, nullptr },
{ "rewind-minutes", req_arg, nullptr },
{ "hidden-gui", no_arg, nullptr }
{ "hidden-gui", no_arg, nullptr },
{ "shortcut.", req_arg, nullptr },
{ "input.", req_arg, nullptr }
};
BYTE cmd_line_parse(int argc, uTCHAR **argv) {
QStringList splitted;
QString arg, key, skey, value, exe = QFileInfo(uQString(argv[0])).baseName();
QString arg, key, value, exe = QFileInfo(uQString(argv[0])).baseName();
int opt = 0;
for (int a = 1; a < argc; a++) {
@ -124,9 +126,11 @@ BYTE cmd_line_parse(int argc, uTCHAR **argv) {
if (elaborate) {
unsigned int b;
QString skey;
for (b = 0; b < LENGTH(opt_long); b++) {
if ((opt_long[b].lopt == key) || (opt_long[b].sopt == key)) {
if ((opt_long[b].lopt == key) || (opt_long[b].sopt == key) ||
(opt_long[b].lopt.endsWith(".") && key.startsWith(opt_long[b].lopt))) {
skey = opt_long[b].sopt;
if (opt_long[b].ra == req_arg) {
if (splitted.count() > 1) {
@ -221,6 +225,67 @@ BYTE cmd_line_parse(int argc, uTCHAR **argv) {
#endif
} else if (key == "hidden-gui") {
info.start_with_hidden_gui = TRUE;
} else if (key.startsWith("shortcut.")) {
QStringList list = key.toLower().split(".");
if (list.length() == 2) {
key = QString(list.at(1));
for (int i = SET_INP_SC_OPEN; i < SET_INP_SC_OPEN + SET_MAX_NUM_SC; i++) {
const _settings *s = &inp_cfg[i];
QString skey = uQString(s->key).toLower().replace(" ", "_");
if (key == skey) {
list = value.split(",");
if (!list.length()) {
break;
}
if (list.length() >= 1) {
settings_inp_wr_sc((void *)&list.at(0), i, KEYBOARD);
}
if (list.length() >= 2) {
settings_inp_wr_sc((void *)&list.at(0), i, JOYSTICK);
}
}
}
}
} else if (key.startsWith("input.")) {
QStringList list = key.toLower().split(".");
struct _range {
int port;
int start;
int end;
} const range[4] = {
{ 0, SET_INP_P1K_A, SET_INP_P1K_TURBOB },
{ 1, SET_INP_P2K_A, SET_INP_P2K_TURBOB },
{ 2, SET_INP_P3K_A, SET_INP_P3K_TURBOB },
{ 3, SET_INP_P4K_A, SET_INP_P4K_TURBOB }
};
if (list.length() == 2) {
key = QString(list.at(1));
for (unsigned int r = 0; r < LENGTH(range); r++) {
for (int i = range[r].start; i <= range[r].end ; i++) {
const _settings *s = &inp_cfg[i];
QString skey = uQString(s->key).toLower().replace(" ", "_");
if (key == skey) {
list = value.split(",");
if (!list.length()) {
break;
}
if (list.length() >= 1) {
port[range[r].port].input[KEYBOARD][i - range[r].start] =
settings_inp_wr_port((void *)&list.at(0), i, KEYBOARD);
}
if (list.length() >= 2) {
port[range[r].port].input[JOYSTICK][i - range[r].start] =
settings_inp_wr_port((void *)&list.at(1), i, JOYSTICK);
}
}
}
}
}
}
break;
case 'a':

View file

@ -28,113 +28,127 @@ dlgCmdLineHelp::dlgCmdLineHelp(QWidget *parent, const QString name, const QStrin
dlgCmdLineHelp::dlgCmdLineHelp(QWidget *parent, const QString name) : QDialog(parent) {
uTCHAR *usage_string;
const uTCHAR *istructions = {
uL("Usage: %%1 [options] file...\n\n")
uL("Options:\n")
uL("-h, --help print this help\n")
uL("-V, --version print the version\n")
uL(" --portable start in portable mode\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("Usage: %%1 [options] file...\n\n")
uL("Options:\n")
uL("-h, --help print this help\n")
uL("-V, --version print the version\n")
uL(" --portable start in portable mode\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
#if defined (WITH_OPENGL)
uL("" uPs("") "\n")
uL("" uPs("") "\n")
#endif
#if defined (FULLSCREEN_RESFREQ)
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
#endif
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
};
const uTCHAR *sch_input = {
uL(" --shurtcut.[desc] set up the shortcut : [keyboard],[joystick]" NEWLINE)
uL(" descriptions can be found in the puNES.cfg" NEWLINE)
uL(" e.g." NEWLINE)
uL(" --shurtcut.open=Alt+O" NEWLINE)
uL(" --shurtcut.hard_reset=F11" NEWLINE)
uL(" --input.[desc] input sequence : [keyboard],[joystick]" NEWLINE)
uL(" descriptions can be found in the input.cfg" NEWLINE)
uL(" e.g." NEWLINE)
uL(" --input.p1k_up=Up" NEWLINE)
uL(" --input.p1k_turboa=W")
};
usage_string = (uTCHAR *)malloc(1024 * 9);
usnprintf(usage_string, 1024 * 9, istructions,
main_cfg[SET_MODE].hlp,
main_cfg[SET_SCALE].hlp,
main_cfg[SET_PAR].hlp,
main_cfg[SET_PAR_SOFT_STRETCH].hlp,
main_cfg[SET_OVERSCAN_BLACK_BORDERS].hlp,
main_cfg[SET_OVERSCAN_BLACK_BORDERS_FSCR].hlp,
main_cfg[SET_OVERSCAN_DEFAULT].hlp,
main_cfg[SET_FILTER].hlp,
main_cfg[SET_NTSC_FORMAT].hlp,
main_cfg[SET_SHADER].hlp,
main_cfg[SET_PALETTE].hlp,
main_cfg[SET_SWAP_EMPHASIS_PAL].hlp,
main_cfg[SET_VSYNC].hlp,
main_cfg[SET_INTERPOLATION].hlp,
main_cfg[SET_TEXT_ON_SCREEN].hlp,
main_cfg[SET_INPUT_DISPLAY].hlp,
main_cfg[SET_DISABLE_TV_NOISE].hlp,
main_cfg[SET_DISABLE_SEPIA_PAUSE].hlp,
main_cfg[SET_MODE].hlp,
main_cfg[SET_SCALE].hlp,
main_cfg[SET_PAR].hlp,
main_cfg[SET_PAR_SOFT_STRETCH].hlp,
main_cfg[SET_OVERSCAN_BLACK_BORDERS].hlp,
main_cfg[SET_OVERSCAN_BLACK_BORDERS_FSCR].hlp,
main_cfg[SET_OVERSCAN_DEFAULT].hlp,
main_cfg[SET_FILTER].hlp,
main_cfg[SET_NTSC_FORMAT].hlp,
main_cfg[SET_SHADER].hlp,
main_cfg[SET_PALETTE].hlp,
main_cfg[SET_SWAP_EMPHASIS_PAL].hlp,
main_cfg[SET_VSYNC].hlp,
main_cfg[SET_INTERPOLATION].hlp,
main_cfg[SET_TEXT_ON_SCREEN].hlp,
main_cfg[SET_INPUT_DISPLAY].hlp,
main_cfg[SET_DISABLE_TV_NOISE].hlp,
main_cfg[SET_DISABLE_SEPIA_PAUSE].hlp,
#if defined (WITH_OPENGL)
main_cfg[SET_DISABLE_SRGB_FBO].hlp,
main_cfg[SET_DISABLE_SRGB_FBO].hlp,
#endif
main_cfg[SET_OVERSCAN_BRD_NTSC].hlp,
main_cfg[SET_OVERSCAN_BRD_PAL].hlp,
main_cfg[SET_FULLSCREEN].hlp,
main_cfg[SET_FULLSCREEN_IN_WINDOW].hlp,
main_cfg[SET_INTEGER_FULLSCREEN].hlp,
main_cfg[SET_STRETCH_FULLSCREEN].hlp,
main_cfg[SET_OVERSCAN_BRD_NTSC].hlp,
main_cfg[SET_OVERSCAN_BRD_PAL].hlp,
main_cfg[SET_FULLSCREEN].hlp,
main_cfg[SET_FULLSCREEN_IN_WINDOW].hlp,
main_cfg[SET_INTEGER_FULLSCREEN].hlp,
main_cfg[SET_STRETCH_FULLSCREEN].hlp,
#if defined (FULLSCREEN_RESFREQ)
main_cfg[SET_ADAPTIVE_RRATE_FULLSCREEN].hlp,
main_cfg[SET_RESOLUTION_FULLSCREEN].hlp,
main_cfg[SET_ADAPTIVE_RRATE_FULLSCREEN].hlp,
main_cfg[SET_RESOLUTION_FULLSCREEN].hlp,
#endif
main_cfg[SET_HORIZONTAL_FLIP_SCREEN].hlp,
main_cfg[SET_SCREEN_ROTATION].hlp,
main_cfg[SET_AUDIO_OUTPUT_DEVICE].hlp,
main_cfg[SET_AUDIO].hlp,
main_cfg[SET_AUDIO_BUFFER_FACTOR].hlp,
main_cfg[SET_SAMPLERATE].hlp,
main_cfg[SET_CHANNELS].hlp,
main_cfg[SET_STEREO_DELAY].hlp,
main_cfg[SET_REVERSE_BITS_DPCM].hlp,
main_cfg[SET_SWAP_DUTY].hlp,
main_cfg[SET_HIDE_SPRITES].hlp,
main_cfg[SET_HIDE_BACKGROUND].hlp,
main_cfg[SET_UNLIMITED_SPRITES].hlp,
main_cfg[SET_BCK_PAUSE].hlp,
main_cfg[SET_CHEAT_MODE].hlp,
main_cfg[SET_GUI_LANGUAGE].hlp,
main_cfg[SET_REWIND_MINUTES].hlp,
main_cfg[SET_ONLYCMDLINE_HIDDEN_GUI].hlp
main_cfg[SET_HORIZONTAL_FLIP_SCREEN].hlp,
main_cfg[SET_SCREEN_ROTATION].hlp,
main_cfg[SET_AUDIO_OUTPUT_DEVICE].hlp,
main_cfg[SET_AUDIO].hlp,
main_cfg[SET_AUDIO_BUFFER_FACTOR].hlp,
main_cfg[SET_SAMPLERATE].hlp,
main_cfg[SET_CHANNELS].hlp,
main_cfg[SET_STEREO_DELAY].hlp,
main_cfg[SET_REVERSE_BITS_DPCM].hlp,
main_cfg[SET_SWAP_DUTY].hlp,
main_cfg[SET_HIDE_SPRITES].hlp,
main_cfg[SET_HIDE_BACKGROUND].hlp,
main_cfg[SET_UNLIMITED_SPRITES].hlp,
main_cfg[SET_BCK_PAUSE].hlp,
main_cfg[SET_CHEAT_MODE].hlp,
main_cfg[SET_GUI_LANGUAGE].hlp,
main_cfg[SET_REWIND_MINUTES].hlp,
main_cfg[SET_ONLYCMDLINE_HIDDEN_GUI].hlp,
sch_input
);
init(name, uQString(uL("" NAME " Command Line Help")), usage_string);
free(usage_string);

View file

@ -1843,6 +1843,15 @@ void objInp::sc_qstring_pntr_to_val(void *str, int index, int type) {
split.replace(type, (QString(*(QString *)str)));
val.replace(index, QString("%1,%2").arg(split.at(KEYBOARD), split.at(JOYSTICK)));
}
DBWORD objInp::kbd_keyval_from_name(int index, const QString &name) {
DBWORD value = 0;
if ((name != "NULL") && !(value = _kbd_keyval_from_name(name))) {
value = _kbd_keyval_from_name(uQString(set->cfg[index].def));
}
return (value);
}
QString objInp::kbd_keyval_to_name(const DBWORD value) {
bool ok = false;
int index = 0;
@ -2018,15 +2027,6 @@ DBWORD objInp::_kbd_keyval_from_name(const QString &name) {
return (value);
}
DBWORD objInp::kbd_keyval_from_name(int index, const QString &name) {
DBWORD value = 0;
if ((name != "NULL") && !(value = _kbd_keyval_from_name(name))) {
value = _kbd_keyval_from_name(uQString(set->cfg[index].def));
}
return (value);
}
int objInp::kbd_keyval_to_int(int index) {
if (val.at(index).isEmpty()) {
val.replace(index, uQString(set->cfg[index].def));

View file

@ -178,6 +178,7 @@ class objInp : public objSettings {
void set_all_input_defaults(_config_input *config_input, _array_pointers_port *array);
void *sc_val_to_qstring_pntr(int index, int type);
void sc_qstring_pntr_to_val(void *str, int index, int type);
DBWORD kbd_keyval_from_name(int index, const QString &name);
static QString kbd_keyval_to_name(DBWORD value);
static DBWORD kbd_keyval_decode(QKeyEvent *keyEvent);
void kbd_default(int button, _port *prt, int index);
@ -192,7 +193,6 @@ class objInp : public objSettings {
void kbd_rd(int index, int pIndex);
void kbd_wr(int index, int pIndex);
DBWORD _kbd_keyval_from_name(const QString &name);
DBWORD kbd_keyval_from_name(int index, const QString &name);
int kbd_keyval_to_int(int index);
int nes_keyboard_index(const QString &name);

View file

@ -88,6 +88,15 @@ void *settings_inp_rd_sc(int index, int type) {
void settings_inp_wr_sc(void *str, int index, int type) {
s.inp->sc_qstring_pntr_to_val(str, index, type);
}
DBWORD settings_inp_wr_port(void *str, int index, int type) {
QString sstr = (*(QString *)str);
if (type == KEYBOARD) {
return (s.inp->kbd_keyval_from_name(index, sstr));
} else {
return (js_joyval_from_name(uQStringCD(sstr)));
}
}
void settings_inp_all_defaults(_config_input *config_input, _array_pointers_port *array) {
s.inp->set_all_input_defaults(config_input, array);
}

View file

@ -2048,6 +2048,7 @@ EXTERNC void settings_resolution_val_to_int(int *w, int *h, const uTCHAR *buffer
EXTERNC void *settings_inp_rd_sc(int index, int type);
EXTERNC void settings_inp_wr_sc(void *str, int index, int type);
EXTERNC DBWORD settings_inp_wr_port(void *str, int index, int type);
EXTERNC void settings_inp_all_defaults(_config_input *config_input, _array_pointers_port *array);
EXTERNC void settings_inp_port_defaults(_port *port, int index, int mode);
EXTERNC void settings_inp_port_button_default(int button, _port *port, int index, int mode);

View file

@ -1119,16 +1119,3 @@ void wdgSettingsInput::s_et_update_joy_combo(void) {
}
gui_dlgjsc_emit_update_joy_combo();
}