Add a ssnes_main wrapper for more simple code.

This commit is contained in:
Themaister 2012-01-30 17:50:00 +01:00
parent 734afe2058
commit ef280919d3
2 changed files with 106 additions and 0 deletions

71
console/main_wrap.c Normal file
View File

@ -0,0 +1,71 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "main_wrap.h"
#include "../strl.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#define MAX_ARGS 32
#define MAX_ARG_LENGTH PATH_MAX
int ssnes_main(int argc, char **argv);
int ssnes_main_init_wrap(const struct ssnes_main_wrap *args)
{
int argc = 0;
char *argv[MAX_ARGS] = {NULL};
argv[argc++] = strdup("ssnes");
if (args->rom_path)
argv[argc++] = strdup(args->rom_path);
if (args->sram_path)
{
argv[argc++] = strdup("-s");
argv[argc++] = strdup(args->sram_path);
}
if (args->state_path)
{
argv[argc++] = strdup("-S");
argv[argc++] = strdup(args->state_path);
}
if (args->config_path)
{
argv[argc++] = strdup("-c");
argv[argc++] = strdup(args->config_path);
}
if (args->verbose)
argv[argc++] = strdup("-v");
int ret = ssnes_main(argc, argv);
char **tmp = argv;
while (*tmp)
{
free(tmp);
tmp++;
}
return ret;
}

35
console/main_wrap.h Normal file
View File

@ -0,0 +1,35 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAIN_WRAP_H__
#define MAIN_WRAP_H__
// Builds argc/argv and calls ssnes_main_init().
struct ssnes_main_wrap
{
const char *rom_path;
const char *sram_path;
const char *state_path;
const char *config_path;
bool verbose;
};
int ssnes_main_init_wrap(const struct ssnes_main_wrap *args);
#endif