diff --git a/console/main_wrap.c b/console/main_wrap.c
new file mode 100644
index 0000000000..4271946111
--- /dev/null
+++ b/console/main_wrap.c
@@ -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 .
+ */
+
+#include "main_wrap.h"
+#include "../strl.h"
+#include
+#include
+#include
+
+#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;
+}
+
diff --git a/console/main_wrap.h b/console/main_wrap.h
new file mode 100644
index 0000000000..41771c8b56
--- /dev/null
+++ b/console/main_wrap.h
@@ -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 .
+ */
+
+#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
+