#endif
#ifndef NO_FRONTEND
+#include <sys/stat.h>
#include "libpicofe/input.h"
#include "libpicofe/plat.h"
#include "libpicofe/readpng.h"
static void toggle_fast_forward(int force_off);
static void check_profile(void);
static void check_memcards(void);
+static int get_gameid_filename(char *buf, int size, const char *fmt, int i);
+static const char *get_home_dir(void);
+#define MAKE_PATH(buf, dir, fname) \
+ emu_make_path(buf, sizeof(buf), dir, fname)
+
#endif
#ifndef BOOT_MSG
#define BOOT_MSG "Booting up..."
char hud_msg[64];
int hud_new_msg;
-static inline void make_path(char *buf, size_t size, const char *dir, const char *fname)
-{
- if (fname)
- snprintf(buf, size, ".%s%s", dir, fname);
- else
- snprintf(buf, size, ".%s", dir);
-}
-#define MAKE_PATH(buf, dir, fname) \
- make_path(buf, sizeof(buf), dir, fname)
-
-static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
- char trimlabel[33];
- int j;
-
- strncpy(trimlabel, CdromLabel, 32);
- trimlabel[32] = 0;
- for (j = 31; j >= 0; j--)
- if (trimlabel[j] == ' ')
- trimlabel[j] = 0;
- else
- continue;
-
- snprintf(buf, size, fmt, trimlabel, CdromId, i);
-
- return 0;
-}
-
void set_cd_image(const char *fname)
{
SetIsoFile(fname);
static void set_default_paths(void)
{
#ifndef NO_FRONTEND
- snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR);
+ const char *home = get_home_dir();
+ struct stat st;
+ MAKE_PATH(Config.PatchesDir, PATCHES_DIR, NULL);
MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
- strcpy(Config.BiosDir, "bios");
+ MAKE_PATH(Config.BiosDir, BIOS_DIR, NULL);
+
+ emu_make_data_path(Config.PluginsDir, "plugins", sizeof(Config.PluginsDir));
+
+ // prefer bios in working dir for compatibility
+ if (!strcmp(home, ".") && !stat("bios", &st))
+ strcpy(Config.BiosDir, "bios");
+
+ SysPrintf("dirs: profile=%s" PCSX_DOT_DIR ", bios=%s, plugins=%s\n",
+ home, Config.BiosDir, Config.PluginsDir);
#endif
- strcpy(Config.PluginsDir, "plugins");
strcpy(Config.Gpu, "builtin_gpu");
strcpy(Config.Spu, "builtin_spu");
}
scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
get_gameid_filename(buf, sizeof(buf),
- "screenshots/%.32s-%.9s.%d.png", ti);
- ret = -1;
+ "%s" SCREENSHOTS_DIR "%.32s-%.9s.%d.png", ti);
+ ret = -2;
if (scrbuf != 0 && bpp == 16)
ret = writepng(buf, scrbuf, w, h);
if (ret == 0)
snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
+ else
+ SysPrintf("writepng %s: %d\n", buf, ret);
break;
}
case SACTION_VOLUME_UP:
#include <sys/stat.h>
#include <sys/types.h>
+static const char *get_home_dir(void)
+{
+#if defined(PANDORA) || !defined(__unix__)
+ return ".";
+#else
+ static const char *home = NULL;
+ struct stat st;
+ if (home)
+ return home;
+ // for compatibility with older versions, look for .pcsx in the working dir
+ if (stat(PCSX_DOT_DIR + 1, &st) != 0)
+ home = getenv("HOME");
+ if (home == NULL)
+ home = ".";
+ return home;
+#endif
+}
+
+void emu_make_path(char *buf, size_t size, const char *dir, const char *fname)
+{
+ const char *home = get_home_dir();
+ if (fname)
+ snprintf(buf, size, "%s%s%s", home, dir, fname);
+ else
+ snprintf(buf, size, "%s%s", home, dir);
+}
+
+void emu_make_data_path(char *buff, const char *end, int size)
+{
+ int pos, end_len;
+
+ end_len = strlen(end);
+ pos = plat_get_root_dir(buff, size);
+ strncpy(buff + pos, end, size - pos);
+ buff[size - 1] = 0;
+ if (pos + end_len > size - 1)
+ printf("Warning: path truncated: %s\n", buff);
+}
+
static void create_profile_dir(const char *directory) {
char path[MAXPATHLEN];
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/");
+ create_profile_dir(CFG_DIR);
+ create_profile_dir(SCREENSHOTS_DIR);
}
static void check_memcards(void)
int i;
for (i = 1; i <= 9; i++) {
- snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
+ snprintf(buf, sizeof(buf), "%s%scard%d.mcd",
+ get_home_dir(), MEMCARD_DIR, i);
f = fopen(buf, "rb");
if (f == NULL) {
// FIXME: this recovery doesn't work, just delete bad config and bail out
// SysMessage("could not load plugins, retrying with defaults\n");
set_default_paths();
- snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
+ snprintf(path, sizeof(path), "%s" PCSX_DOT_DIR "%s",
+ get_home_dir(), cfgfile_basename);
remove(path);
SysMessage("Failed loading plugins!");
return 1;
}
static void SignalExit(int sig) {
+ SysPrintf("got signal %d\n", sig);
// only to restore framebuffer/resolution on some devices
plat_finish();
_exit(1);
}
-#endif
-
-void SysRunGui() {
- printf("SysRunGui\n");
-}
-
-static void CALLBACK dummy_lace(void)
-{
-}
-
-void SysReset() {
- // rearmed hack: EmuReset() runs some code when real BIOS is used,
- // but we usually do reset from menu while GPU is not open yet,
- // so we need to prevent updateLace() call..
- void *real_lace = GPU_updateLace;
- GPU_updateLace = dummy_lace;
- g_emu_resetting = 1;
-
- // reset can run code, timing must be set
- pl_timing_prepare(Config.PsxType);
- EmuReset();
-
- GPU_updateLace = real_lace;
- g_emu_resetting = 0;
-}
+static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
+ char trimlabel[33];
+ int j;
-void SysClose() {
- EmuShutdown();
- ReleasePlugins();
+ strncpy(trimlabel, CdromLabel, 32);
+ trimlabel[32] = 0;
+ for (j = 31; j >= 0; j--)
+ if (trimlabel[j] == ' ')
+ trimlabel[j] = 0;
+ else
+ continue;
- StopDebugger();
+ snprintf(buf, size, fmt, get_home_dir(), trimlabel, CdromId, i);
- if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
- fclose(emuLog);
- emuLog = NULL;
- }
+ return 0;
}
int get_state_filename(char *buf, int size, int i) {
return get_gameid_filename(buf, size,
- "." STATES_DIR "%.32s-%.9s.%3.3d", i);
+ "%s" STATES_DIR "%.32s-%.9s.%3.3d", i);
}
int emu_check_state(int slot)
return LoadState(fname);
}
+#endif // NO_FRONTEND
+
+static void CALLBACK dummy_lace(void)
+{
+}
+
+void SysReset() {
+ // rearmed hack: EmuReset() runs some code when real BIOS is used,
+ // but we usually do reset from menu while GPU is not open yet,
+ // so we need to prevent updateLace() call..
+ void *real_lace = GPU_updateLace;
+ GPU_updateLace = dummy_lace;
+ g_emu_resetting = 1;
+
+ // reset can run code, timing must be set
+ pl_timing_prepare(Config.PsxType);
+
+ EmuReset();
+
+ GPU_updateLace = real_lace;
+ g_emu_resetting = 0;
+}
+
+void SysClose() {
+ EmuShutdown();
+ ReleasePlugins();
+
+ StopDebugger();
+
+ if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
+ fclose(emuLog);
+ emuLog = NULL;
+ }
+}
+
#ifndef HAVE_LIBRETRO
#ifndef ANDROID
#ifndef __FRONTEND_MAIN_H__
#define __FRONTEND_MAIN_H__
+#include <stdlib.h>
#include "config.h"
-#define DEFAULT_MEM_CARD_1 "/.pcsx/memcards/card1.mcd"
-#define DEFAULT_MEM_CARD_2 "/.pcsx/memcards/card2.mcd"
-#define MEMCARD_DIR "/.pcsx/memcards/"
-#define PLUGINS_DIR "/.pcsx/plugins/"
-#define PLUGINS_CFG_DIR "/.pcsx/plugins/cfg/"
#define PCSX_DOT_DIR "/.pcsx/"
-#define STATES_DIR "/.pcsx/sstates/"
-#define CHEATS_DIR "/.pcsx/cheats/"
-#define PATCHES_DIR "/.pcsx/patches/"
-#define BIOS_DIR "/bios/"
+#define DEFAULT_MEM_CARD_1 PCSX_DOT_DIR "memcards/card1.mcd"
+#define DEFAULT_MEM_CARD_2 PCSX_DOT_DIR "memcards/card2.mcd"
+#define MEMCARD_DIR PCSX_DOT_DIR "memcards/"
+#define STATES_DIR PCSX_DOT_DIR "sstates/"
+#define CHEATS_DIR PCSX_DOT_DIR "cheats/"
+#define PATCHES_DIR PCSX_DOT_DIR "patches/"
+#define CFG_DIR PCSX_DOT_DIR "cfg/"
+#ifndef PANDORA
+#define BIOS_DIR PCSX_DOT_DIR "bios/"
+#define SCREENSHOTS_DIR PCSX_DOT_DIR "screenshots/"
+#else
+#define BIOS_DIR "/bios/"
+#define SCREENSHOTS_DIR "/screenshots/"
+#endif
extern char cfgfile_basename[MAXPATHLEN];
void emu_set_default_config(void);
void emu_on_new_cd(int show_hud_msg);
+void emu_make_path(char *buf, size_t size, const char *dir, const char *fname);
+void emu_make_data_path(char *buff, const char *end, int size);
+
int get_state_filename(char *buf, int size, int i);
int emu_check_state(int slot);
int emu_save_state(int slot);
static int bios_sel, gpu_plugsel, spu_plugsel;
#ifndef UI_FEATURES_H
-#define MENU_BIOS_PATH "bios/"
#define MENU_SHOW_VOUTMODE 1
#define MENU_SHOW_SCALER2 0
#define MENU_SHOW_NUBS_BTNS 0
static int min(int x, int y) { return x < y ? x : y; }
static int max(int x, int y) { return x > y ? x : y; }
-void emu_make_path(char *buff, const char *end, int size)
-{
- int pos, end_len;
-
- end_len = strlen(end);
- pos = plat_get_root_dir(buff, size);
- strncpy(buff + pos, end, size - pos);
- buff[size - 1] = 0;
- if (pos + end_len > size - 1)
- printf("Warning: path truncated: %s\n", buff);
-}
-
static int emu_check_save_file(int slot, int *time)
{
char fname[MAXPATHLEN];
static void make_cfg_fname(char *buf, size_t size, int is_game)
{
- if (is_game)
- snprintf(buf, size, "." PCSX_DOT_DIR "cfg/%.32s-%.9s.cfg", get_cd_label(), CdromId);
+ char id_buf[64];
+ if (is_game) {
+ snprintf(id_buf, sizeof(id_buf), "%.32s-%.9s.cfg",
+ get_cd_label(), CdromId);
+ emu_make_path(buf, size, CFG_DIR, id_buf);
+ }
else
- snprintf(buf, size, "." PCSX_DOT_DIR "%s", cfgfile_basename);
+ emu_make_path(buf, size, PCSX_DOT_DIR, cfgfile_basename);
}
static void keys_write_all(FILE *f);
FILE *f;
int i, ret = -1;
- snprintf(path, sizeof(path), "." PCSX_DOT_DIR "lastcdimg.txt");
+ emu_make_path(path, sizeof(path), PCSX_DOT_DIR, "lastcdimg.txt");
f = fopen(path, is_get ? "r" : "w");
if (f == NULL) {
ret = -1;
{
strcpy(Config.Mcd1, "none");
if (memcard1_sel != 0)
- snprintf(Config.Mcd1, sizeof(Config.Mcd1), ".%s%s", MEMCARD_DIR, memcards[memcard1_sel]);
+ emu_make_path(Config.Mcd1, sizeof(Config.Mcd1), MEMCARD_DIR, memcards[memcard1_sel]);
strcpy(Config.Mcd2, "none");
if (memcard2_sel != 0)
- snprintf(Config.Mcd2, sizeof(Config.Mcd2), ".%s%s", MEMCARD_DIR, memcards[memcard2_sel]);
+ emu_make_path(Config.Mcd2, sizeof(Config.Mcd2), MEMCARD_DIR, memcards[memcard2_sel]);
LoadMcds(Config.Mcd1, Config.Mcd2);
draw_mc_bg();
}
int inp;
static const char msg[] =
"You don't seem to have copied any BIOS\n"
- "files to\n"
- MENU_BIOS_PATH "\n\n"
+ "files to\n%s\n\n"
"While many games work fine with fake\n"
"(HLE) BIOS, others (like MGS and FF8)\n"
"Press %s or %s to continue";
char tmp_msg[sizeof(msg) + 64];
- snprintf(tmp_msg, sizeof(tmp_msg), msg,
+ snprintf(tmp_msg, sizeof(tmp_msg), msg, Config.BiosDir,
in_get_key_name(-1, -PBTN_MOK), in_get_key_name(-1, -PBTN_MBACK));
while (1)
{
#endif
do_memcards:
- dir = opendir("." MEMCARD_DIR);
+ emu_make_path(fname, sizeof(fname), MEMCARD_DIR, NULL);
+ dir = opendir(fname);
if (dir == NULL) {
perror("scan_bios_plugins memcards opendir");
return;
if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
continue;
- snprintf(fname, sizeof(fname), "." MEMCARD_DIR "%s", ent->d_name);
+ emu_make_path(fname, sizeof(fname), MEMCARD_DIR, ent->d_name);
if (stat(fname, &st) != 0) {
printf("bad memcard file: %s\n", ent->d_name);
continue;
exit(1);
}
- emu_make_path(buff, "skin/background.png", sizeof(buff));
+ emu_make_data_path(buff, "skin/background.png", sizeof(buff));
readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
i = plat_target.cpu_clock_set != NULL