+ return 0;
+}
+
+int emu_core_init(void)
+{
+ SysPrintf("Starting PCSX-ReARMed " REV "%s\n", get_build_info());
+
+#ifndef NO_FRONTEND
+ check_profile();
+ check_memcards();
+#endif
+
+ if (EmuInit() == -1) {
+ SysPrintf("PSX emulator couldn't be initialized.\n");
+ return -1;
+ }
+
+ LoadMcds(Config.Mcd1, Config.Mcd2);
+
+ if (Config.Debug) {
+ StartDebugger();
+ }
+
+ return 0;
+}
+
+void emu_core_ask_exit(void)
+{
+ stop++;
+ g_emu_want_quit = 1;
+}
+
+#ifndef NO_FRONTEND
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+static void create_profile_dir(const char *directory) {
+ char path[MAXPATHLEN];
+
+ MAKE_PATH(path, directory, NULL);
+ mkdir(path, S_IRWXU | S_IRWXG);
+}
+
+static void check_profile(void) {
+ // make sure that ~/.pcsx exists
+ create_profile_dir(PCSX_DOT_DIR);
+
+ create_profile_dir(BIOS_DIR);
+ create_profile_dir(MEMCARD_DIR);
+ create_profile_dir(STATES_DIR);
+ create_profile_dir(PLUGINS_DIR);
+ create_profile_dir(PLUGINS_CFG_DIR);
+ create_profile_dir(CHEATS_DIR);
+ create_profile_dir(PATCHES_DIR);
+ create_profile_dir(PCSX_DOT_DIR "cfg");
+ create_profile_dir("/screenshots/");
+}
+
+static void check_memcards(void)
+{
+ char buf[MAXPATHLEN];
+ FILE *f;
+ int i;
+
+ for (i = 1; i <= 9; i++) {
+ snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
+
+ f = fopen(buf, "rb");
+ if (f == NULL) {
+ SysPrintf("Creating memcard: %s\n", buf);
+ CreateMcd(buf);
+ }
+ else
+ fclose(f);
+ }
+}
+
+int main(int argc, char *argv[])
+{