1
0
Fork 0
forked from suyu/suyu

cmd: Support passing game arguments from command line

Uses -p (--program) and following string as args.
This commit is contained in:
Zach Hilman 2018-09-30 14:28:17 -04:00
parent 8bbc12b9c2
commit 081f5c1dbf
4 changed files with 14 additions and 10 deletions

View file

@ -155,7 +155,7 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
if (!Settings::values.program_args.empty()) { if (!Settings::values.program_args.empty()) {
const auto arg_data = Settings::values.program_args; const auto arg_data = Settings::values.program_args;
codeset->DataSegment().size += 0x9000; codeset->DataSegment().size += 0x9000;
NSOArgumentHeader args_header{0x9000, arg_data.size(), {}}; NSOArgumentHeader args_header{0x9000, static_cast<u32_le>(arg_data.size()), {}};
program_image.resize(static_cast<u32>(program_image.size()) + 0x9000); program_image.resize(static_cast<u32>(program_image.size()) + 0x9000);
std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header, std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header,
sizeof(NSOArgumentHeader)); sizeof(NSOArgumentHeader));

View file

@ -130,7 +130,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
if (should_pass_arguments && !Settings::values.program_args.empty()) { if (should_pass_arguments && !Settings::values.program_args.empty()) {
const auto arg_data = Settings::values.program_args; const auto arg_data = Settings::values.program_args;
codeset->DataSegment().size += 0x9000; codeset->DataSegment().size += 0x9000;
NSOArgumentHeader args_header{0x9000, arg_data.size(), {}}; NSOArgumentHeader args_header{0x9000, static_cast<u32_le>(arg_data.size()), {}};
program_image.resize(static_cast<u32>(program_image.size()) + 0x9000); program_image.resize(static_cast<u32>(program_image.size()) + 0x9000);
std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header, std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header,
sizeof(NSOArgumentHeader)); sizeof(NSOArgumentHeader));

View file

@ -138,6 +138,7 @@ void Config::ReadValues() {
Settings::values.use_gdbstub = sdl2_config->GetBoolean("Debugging", "use_gdbstub", false); Settings::values.use_gdbstub = sdl2_config->GetBoolean("Debugging", "use_gdbstub", false);
Settings::values.gdbstub_port = Settings::values.gdbstub_port =
static_cast<u16>(sdl2_config->GetInteger("Debugging", "gdbstub_port", 24689)); static_cast<u16>(sdl2_config->GetInteger("Debugging", "gdbstub_port", 24689));
Settings::values.program_args = sdl2_config->Get("Debugging", "program_args", "");
// Web Service // Web Service
Settings::values.enable_telemetry = Settings::values.enable_telemetry =

View file

@ -56,9 +56,10 @@ static void PrintHelp(const char* argv0) {
std::cout << "Usage: " << argv0 std::cout << "Usage: " << argv0
<< " [options] <filename>\n" << " [options] <filename>\n"
"-g, --gdbport=NUMBER Enable gdb stub on port NUMBER\n" "-g, --gdbport=NUMBER Enable gdb stub on port NUMBER\n"
"-f, --fullscreen Start in fullscreen mode\n" "-f, --fullscreen Start in fullscreen mode\n"
"-h, --help Display this help and exit\n" "-h, --help Display this help and exit\n"
"-v, --version Output version information and exit\n"; "-v, --version Output version information and exit\n"
"-p, --program Pass following string as arguments to executable\n";
} }
static void PrintVersion() { static void PrintVersion() {
@ -103,15 +104,13 @@ int main(int argc, char** argv) {
bool fullscreen = false; bool fullscreen = false;
static struct option long_options[] = { static struct option long_options[] = {
{"gdbport", required_argument, 0, 'g'}, {"gdbport", required_argument, 0, 'g'}, {"fullscreen", no_argument, 0, 'f'},
{"fullscreen", no_argument, 0, 'f'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'}, {"program", optional_argument, 0, 'p'}, {0, 0, 0, 0},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0},
}; };
while (optind < argc) { while (optind < argc) {
char arg = getopt_long(argc, argv, "g:fhv", long_options, &option_index); char arg = getopt_long(argc, argv, "g:fhvp::", long_options, &option_index);
if (arg != -1) { if (arg != -1) {
switch (arg) { switch (arg) {
case 'g': case 'g':
@ -135,6 +134,10 @@ int main(int argc, char** argv) {
case 'v': case 'v':
PrintVersion(); PrintVersion();
return 0; return 0;
case 'p':
Settings::values.program_args = argv[optind];
++optind;
break;
} }
} else { } else {
#ifdef _WIN32 #ifdef _WIN32