#include "fonts.h"\r
#include "lprintf.h"\r
#include "config.h"\r
+#include "common.h"\r
\r
#include <Pico/PicoInt.h>\r
#include <Pico/Patch.h>\r
+#include <Pico/cd/cue.h>\r
#include <zlib/zlib.h>\r
\r
-#if defined(__GP2X__)\r
- #include "../gp2x/gp2x.h"\r
- #define SCREEN_WIDTH 320\r
- #define SCREEN_BUFFER gp2x_screen\r
-#elif defined(__GIZ__)\r
- #include "../gizmondo/giz.h"\r
- #define SCREEN_WIDTH 321\r
- #define SCREEN_BUFFER giz_screen\r
-#elif defined(PSP)\r
- #include "../psp/psp.h"\r
- #define SCREEN_WIDTH 512\r
- #define SCREEN_BUFFER psp_screen\r
-#endif\r
\r
char *PicoConfigFile = "config.cfg";\r
currentConfig_t currentConfig, defaultConfig;\r
int rom_loaded = 0;\r
-char noticeMsg[64];\r
+char noticeMsg[64] = { 0, };\r
int state_slot = 0;\r
int config_slot = 0, config_slot_current = 0;\r
+char loadedRomFName[512] = { 0, };\r
+int kb_combo_keys = 0, kb_combo_acts = 0; // keys and actions which need button combos\r
+int pico_inp_mode = 0;\r
\r
unsigned char *movie_data = NULL;\r
static int movie_size = 0;\r
\r
// provided by platform code:\r
-extern char romFileName[];\r
extern void emu_noticeMsgUpdated(void);\r
-extern void emu_getMainDir(char *dst, int len);\r
-extern void emu_setDefaultConfig(void);\r
+extern int emu_getMainDir(char *dst, int len);\r
extern void menu_romload_prepare(const char *rom_name);\r
extern void menu_romload_end(void);\r
\r
\r
// utilities\r
-static void strlwr_(char* string)\r
+static void strlwr_(char *string)\r
{\r
- while ( (*string++ = (char)tolower(*string)) );\r
+ char *p;\r
+ for (p = string; *p; p++)\r
+ *p = (char)tolower(*p);\r
}\r
\r
-static int try_rfn_cut(void)\r
+static int try_rfn_cut(char *fname)\r
{\r
FILE *tmp;\r
char *p;\r
\r
- p = romFileName + strlen(romFileName) - 1;\r
- for (; p > romFileName; p--)\r
+ p = fname + strlen(fname) - 1;\r
+ for (; p > fname; p--)\r
if (*p == '.') break;\r
*p = 0;\r
\r
- if((tmp = fopen(romFileName, "rb"))) {\r
+ if((tmp = fopen(fname, "rb"))) {\r
fclose(tmp);\r
return 1;\r
}\r
strlwr_(ext);\r
}\r
\r
-char *biosfiles_us[] = { "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210" };\r
-char *biosfiles_eu[] = { "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210" };\r
+char *biosfiles_us[] = { "us_scd1_9210", "us_scd2_9306", "SegaCDBIOS9303" };\r
+char *biosfiles_eu[] = { "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303" };\r
char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
\r
int emu_findBios(int region, char **bios_file)\r
}\r
\r
/* check if the name begins with BIOS name */\r
+/*\r
static int emu_isBios(const char *name)\r
{\r
int i;\r
if (strstr(name, biosfiles_jp[i]) != NULL) return 1;\r
return 0;\r
}\r
+*/\r
\r
-static unsigned char scd_id_header[0x100];\r
+static unsigned char id_header[0x100];\r
\r
-/* checks if romFileName points to valid MegaCD image\r
+/* checks if fname points to valid MegaCD image\r
* if so, checks for suitable BIOS */\r
-int emu_cdCheck(int *pregion)\r
+int emu_cdCheck(int *pregion, char *fname_in)\r
{\r
unsigned char buf[32];\r
pm_file *cd_f;\r
- int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe\r
+ int region = 4; // 1: Japan, 4: US, 8: Europe\r
+ char ext[5], *fname = fname_in;\r
+ cue_track_type type = CT_UNKNOWN;\r
+ cue_data_t *cue_data = NULL;\r
+\r
+ get_ext(fname_in, ext);\r
+ if (strcasecmp(ext, ".cue") == 0) {\r
+ cue_data = cue_parse(fname_in);\r
+ if (cue_data != NULL) {\r
+ fname = cue_data->tracks[1].fname;\r
+ type = cue_data->tracks[1].type;\r
+ }\r
+ else\r
+ return -1;\r
+ }\r
+\r
+ cd_f = pm_open(fname);\r
+ if (cue_data != NULL)\r
+ cue_destroy(cue_data);\r
\r
- cd_f = pm_open(romFileName);\r
- if (!cd_f) return 0; // let the upper level handle this\r
+ if (cd_f == NULL) return 0; // let the upper level handle this\r
\r
if (pm_read(buf, 32, cd_f) != 32) {\r
pm_close(cd_f);\r
- return 0;\r
+ return -1;\r
}\r
\r
- if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO)\r
- if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN)\r
- if (type == 0) {\r
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) {\r
+ if (type && type != CT_ISO)\r
+ elprintf(EL_STATUS, ".cue has wrong type: %i", type);\r
+ type = CT_ISO; // Sega CD (ISO)\r
+ }\r
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) {\r
+ if (type && type != CT_BIN)\r
+ elprintf(EL_STATUS, ".cue has wrong type: %i", type);\r
+ type = CT_BIN; // Sega CD (BIN)\r
+ }\r
+\r
+ if (type == CT_UNKNOWN) {\r
pm_close(cd_f);\r
return 0;\r
}\r
\r
- pm_seek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET);\r
- pm_read(scd_id_header, sizeof(scd_id_header), cd_f);\r
+ pm_seek(cd_f, (type == CT_ISO) ? 0x100 : 0x110, SEEK_SET);\r
+ pm_read(id_header, sizeof(id_header), cd_f);\r
\r
/* it seems we have a CD image here. Try to detect region now.. */\r
- pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
+ pm_seek(cd_f, (type == CT_ISO) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
pm_read(buf, 1, cd_f);\r
pm_close(cd_f);\r
\r
if (buf[0] == 0xa1) region = 1; // JAP\r
\r
lprintf("detected %s Sega/Mega CD image with %s region\n",\r
- type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+ type == CT_BIN ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
\r
if (pregion != NULL) *pregion = region;\r
\r
return type;\r
}\r
\r
-static int extract_text(char *dest, unsigned char *src, int len, int swab)\r
+static int extract_text(char *dest, const unsigned char *src, int len, int swab)\r
{\r
char *p = dest;\r
int i;\r
\r
char *emu_makeRomId(void)\r
{\r
- static char id_string[3+0x11+0x11+0x30+16];\r
- unsigned char *id_header;\r
- int pos;\r
-\r
- if (Pico.rom == NULL) {\r
- id_string[0] = 0;\r
- return id_string;\r
- }\r
+ static char id_string[3+0xe*3+0x3*3+0x30*3+3];\r
+ int pos, swab = 1;\r
\r
- if (PicoMCD & 1) {\r
- id_header = scd_id_header;\r
+ if (PicoAHW & PAHW_MCD) {\r
strcpy(id_string, "CD|");\r
- } else {\r
- id_header = Pico.rom + 0x100;\r
- strcpy(id_string, "MD|");\r
+ swab = 0;\r
}\r
+ else strcpy(id_string, "MD|");\r
pos = 3;\r
\r
- pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, 1); // serial\r
+ pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, swab); // serial\r
id_string[pos] = '|'; pos++;\r
- pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, 1); // region\r
+ pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, swab); // region\r
id_string[pos] = '|'; pos++;\r
- pos += extract_text(id_string + pos, id_header + 0x50, 0x30, 1); // overseas name\r
+ pos += extract_text(id_string + pos, id_header + 0x50, 0x30, swab); // overseas name\r
id_string[pos] = 0;\r
\r
- printf("id_string: %s\n", id_string);\r
return id_string;\r
}\r
\r
-int emu_ReloadRom(void)\r
+// buffer must be at least 150 byte long\r
+void emu_getGameName(char *str150)\r
+{\r
+ int ret, swab = (PicoAHW & PAHW_MCD) ? 0 : 1;\r
+ char *s, *d;\r
+\r
+ ret = extract_text(str150, id_header + 0x50, 0x30, swab); // overseas name\r
+\r
+ for (s = d = str150 + 1; s < str150+ret; s++)\r
+ {\r
+ if (*s == 0) break;\r
+ if (*s != ' ' || d[-1] != ' ')\r
+ *d++ = *s;\r
+ }\r
+ *d = 0;\r
+}\r
+\r
+// note: this function might mangle rom_fname\r
+int emu_ReloadRom(char *rom_fname)\r
{\r
unsigned int rom_size = 0;\r
- char *used_rom_name = romFileName;\r
+ char *used_rom_name = rom_fname;\r
unsigned char *rom_data = NULL;\r
char ext[5];\r
- pm_file *rom;\r
+ pm_file *rom = NULL;\r
int ret, cd_state, cd_region, cfg_loaded = 0;\r
\r
- lprintf("emu_ReloadRom(%s)\n", romFileName);\r
+ lprintf("emu_ReloadRom(%s)\n", rom_fname);\r
\r
- get_ext(romFileName, ext);\r
+ get_ext(rom_fname, ext);\r
\r
// detect wrong extensions\r
if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz\r
- sprintf(menuErrorMsg, "Not a ROM selected.");\r
+ sprintf(menuErrorMsg, "Not a ROM/CD selected.");\r
return 0;\r
}\r
\r
free(movie_data);\r
movie_data = 0;\r
}\r
- if (!strcmp(ext, ".gmv")) {\r
+ if (!strcmp(ext, ".gmv"))\r
+ {\r
// check for both gmv and rom\r
int dummy;\r
- FILE *movie_file = fopen(romFileName, "rb");\r
+ FILE *movie_file = fopen(rom_fname, "rb");\r
if(!movie_file) {\r
sprintf(menuErrorMsg, "Failed to open movie.");\r
return 0;\r
sprintf(menuErrorMsg, "Invalid GMV file.");\r
return 0;\r
}\r
- dummy = try_rfn_cut() || try_rfn_cut();\r
+ dummy = try_rfn_cut(rom_fname) || try_rfn_cut(rom_fname);\r
if (!dummy) {\r
sprintf(menuErrorMsg, "Could't find a ROM for movie.");\r
return 0;\r
}\r
- get_ext(romFileName, ext);\r
+ get_ext(rom_fname, ext);\r
+ lprintf("gmv loaded for %s\n", rom_fname);\r
}\r
- else if (!strcmp(ext, ".pat")) {\r
+ else if (!strcmp(ext, ".pat"))\r
+ {\r
int dummy;\r
- PicoPatchLoad(romFileName);\r
- dummy = try_rfn_cut() || try_rfn_cut();\r
+ PicoPatchLoad(rom_fname);\r
+ dummy = try_rfn_cut(rom_fname) || try_rfn_cut(rom_fname);\r
if (!dummy) {\r
sprintf(menuErrorMsg, "Could't find a ROM to patch.");\r
return 0;\r
}\r
- get_ext(romFileName, ext);\r
+ get_ext(rom_fname, ext);\r
}\r
\r
- if ((PicoMCD & 1) && Pico_mcd != NULL)\r
- Stop_CD();\r
+ emu_shutdownMCD();\r
\r
// check for MegaCD image\r
- cd_state = emu_cdCheck(&cd_region);\r
- if (cd_state > 0)\r
+ cd_state = emu_cdCheck(&cd_region, rom_fname);\r
+ if (cd_state >= 0 && cd_state != CIT_NOT_CD)\r
{\r
+ PicoAHW |= PAHW_MCD;\r
// valid CD image, check for BIOS..\r
\r
// we need to have config loaded at this point\r
}\r
if (!emu_findBios(cd_region, &used_rom_name)) {\r
// bios_help() ?\r
+ PicoAHW &= ~PAHW_MCD;\r
return 0;\r
}\r
\r
- PicoMCD |= 1;\r
get_ext(used_rom_name, ext);\r
}\r
else\r
{\r
- if (PicoMCD & 1) Stop_CD();\r
- PicoMCD &= ~1;\r
+ if (PicoAHW & PAHW_MCD) Stop_CD();\r
+ PicoAHW &= ~PAHW_MCD;\r
}\r
\r
rom = pm_open(used_rom_name);\r
if (!rom) {\r
- sprintf(menuErrorMsg, "Failed to open rom.");\r
- return 0;\r
+ sprintf(menuErrorMsg, "Failed to open ROM/CD image");\r
+ goto fail;\r
+ }\r
+\r
+ if (cd_state < 0) {\r
+ sprintf(menuErrorMsg, "Invalid CD image");\r
+ goto fail;\r
}\r
\r
menu_romload_prepare(used_rom_name); // also CD load\r
rom_loaded = 0;\r
\r
if ( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) {\r
- sprintf(menuErrorMsg, "PicoCartLoad() failed.");\r
+ if (ret == 2) sprintf(menuErrorMsg, "Out of memory");\r
+ else if (ret == 3) sprintf(menuErrorMsg, "Read failed");\r
+ else sprintf(menuErrorMsg, "PicoCartLoad() failed.");\r
lprintf("%s\n", menuErrorMsg);\r
- pm_close(rom);\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
pm_close(rom);\r
+ rom = NULL;\r
\r
// detect wrong files (Pico crashes on very small files), also see if ROM EP is good\r
if (rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||\r
((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {\r
if (rom_data) free(rom_data);\r
sprintf(menuErrorMsg, "Not a ROM selected.");\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
\r
// load config for this ROM (do this before insert to get correct region)\r
+ if (!(PicoAHW & PAHW_MCD))\r
+ memcpy(id_header, rom_data + 0x100, sizeof(id_header));\r
if (!cfg_loaded) {\r
ret = emu_ReadConfig(1, 1);\r
if (!ret) emu_ReadConfig(0, 1);\r
lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
if (PicoCartInsert(rom_data, rom_size)) {\r
sprintf(menuErrorMsg, "Failed to load ROM.");\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
\r
- Pico.m.frame_count = 0;\r
-\r
// insert CD if it was detected\r
- if (cd_state > 0) {\r
- ret = Insert_CD(romFileName, cd_state == 2);\r
+ if (cd_state != CIT_NOT_CD) {\r
+ ret = Insert_CD(rom_fname, cd_state);\r
if (ret != 0) {\r
sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
lprintf("%s\n", menuErrorMsg);\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
}\r
\r
menu_romload_end();\r
\r
- if (!emu_isBios(romFileName))\r
- {\r
- // emu_ReadConfig() might have messed currentConfig.lastRomFile\r
- strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
- currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
- }\r
-\r
if (PicoPatches) {\r
PicoPatchPrepare();\r
PicoPatchApply();\r
}\r
\r
// additional movie stuff\r
- if (movie_data) {\r
- if(movie_data[0x14] == '6')\r
- PicoOpt |= 0x20; // 6 button pad\r
- else PicoOpt &= ~0x20;\r
- PicoOpt |= 0x10040; // accurate timing, no VDP fifo timing\r
- if(movie_data[0xF] >= 'A') {\r
- if(movie_data[0x16] & 0x80) {\r
+ if (movie_data)\r
+ {\r
+ if (movie_data[0x14] == '6')\r
+ PicoOpt |= POPT_6BTN_PAD; // 6 button pad\r
+ else PicoOpt &= ~POPT_6BTN_PAD;\r
+ PicoOpt |= POPT_DIS_VDP_FIFO; // no VDP fifo timing\r
+ if (movie_data[0xF] >= 'A') {\r
+ if (movie_data[0x16] & 0x80) {\r
PicoRegionOverride = 8;\r
} else {\r
PicoRegionOverride = 4;\r
}\r
- PicoReset(0);\r
+ PicoReset();\r
// TODO: bits 6 & 5\r
}\r
movie_data[0x18+30] = 0;\r
}\r
else\r
{\r
- PicoOpt &= ~0x10000;\r
- if(Pico.m.pal) {\r
+ PicoOpt &= ~POPT_DIS_VDP_FIFO;\r
+ if (Pico.m.pal) {\r
strcpy(noticeMsg, "PAL SYSTEM / 50 FPS");\r
} else {\r
strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS");\r
emu_noticeMsgUpdated();\r
\r
// load SRAM for this ROM\r
- if (currentConfig.EmuOpt & 1)\r
+ if (currentConfig.EmuOpt & EOPT_USE_SRAM)\r
emu_SaveLoadGame(1, 1);\r
\r
+ strncpy(loadedRomFName, rom_fname, sizeof(loadedRomFName)-1);\r
+ loadedRomFName[sizeof(loadedRomFName)-1] = 0;\r
rom_loaded = 1;\r
return 1;\r
+\r
+fail2:\r
+ menu_romload_end();\r
+fail:\r
+ if (rom != NULL) pm_close(rom);\r
+ return 0;\r
}\r
\r
\r
+void emu_shutdownMCD(void)\r
+{\r
+ if ((PicoAHW & PAHW_MCD) && Pico_mcd != NULL)\r
+ Stop_CD();\r
+ PicoAHW &= ~PAHW_MCD;\r
+}\r
+\r
static void romfname_ext(char *dst, const char *prefix, const char *ext)\r
{\r
char *p;\r
int prefix_len = 0;\r
\r
// make save filename\r
- for (p = romFileName+strlen(romFileName)-1; p >= romFileName && *p != '/'; p--); p++;\r
+ p = loadedRomFName+strlen(loadedRomFName)-1;\r
+ for (; p >= loadedRomFName && *p != PATH_SEP_C; p--); p++;\r
*dst = 0;\r
if (prefix) {\r
- strcpy(dst, prefix);\r
- prefix_len = strlen(prefix);\r
+ int len = emu_getMainDir(dst, 512);\r
+ strcpy(dst + len, prefix);\r
+ prefix_len = len + strlen(prefix);\r
}\r
+#ifdef UIQ3\r
+ else p = loadedRomFName; // backward compatibility\r
+#endif\r
strncpy(dst + prefix_len, p, 511-prefix_len);\r
dst[511-8] = 0;\r
if (dst[strlen(dst)-4] == '.') dst[strlen(dst)-4] = 0;\r
}\r
\r
\r
+static void make_config_cfg(char *cfg)\r
+{\r
+ int len;\r
+ len = emu_getMainDir(cfg, 512);\r
+ strncpy(cfg + len, PicoConfigFile, 512-6-1-len);\r
+ if (config_slot != 0)\r
+ {\r
+ char *p = strrchr(cfg, '.');\r
+ if (p == NULL) p = cfg + strlen(cfg);\r
+ sprintf(p, ".%i.cfg", config_slot);\r
+ }\r
+ cfg[511] = 0;\r
+}\r
+\r
+void emu_packConfig(void)\r
+{\r
+ currentConfig.s_PicoOpt = PicoOpt;\r
+ currentConfig.s_PsndRate = PsndRate;\r
+ currentConfig.s_PicoRegion = PicoRegionOverride;\r
+ currentConfig.s_PicoAutoRgnOrder = PicoAutoRgnOrder;\r
+ currentConfig.s_PicoCDBuffers = PicoCDBuffers;\r
+}\r
+\r
+void emu_unpackConfig(void)\r
+{\r
+ PicoOpt = currentConfig.s_PicoOpt;\r
+ PsndRate = currentConfig.s_PsndRate;\r
+ PicoRegionOverride = currentConfig.s_PicoRegion;\r
+ PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
+ PicoCDBuffers = currentConfig.s_PicoCDBuffers;\r
+}\r
+\r
+static void emu_setDefaultConfig(void)\r
+{\r
+ memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig));\r
+ emu_unpackConfig();\r
+}\r
+\r
+\r
int emu_ReadConfig(int game, int no_defaults)\r
{\r
char cfg[512];\r
- FILE *f;\r
int ret;\r
\r
if (!game)\r
{\r
if (!no_defaults)\r
emu_setDefaultConfig();\r
- strncpy(cfg, PicoConfigFile, 511);\r
- if (config_slot != 0)\r
- {\r
- char *p = strrchr(cfg, '.');\r
- if (p == NULL) p = cfg + strlen(cfg);\r
- sprintf(p, ".%i.cfg", config_slot);\r
- }\r
- cfg[511] = 0;\r
+ make_config_cfg(cfg);\r
ret = config_readsect(cfg, NULL);\r
}\r
else\r
{\r
- if (!no_defaults)\r
- emu_setDefaultConfig();\r
+ char *sect = emu_makeRomId();\r
\r
// try new .cfg way\r
if (config_slot != 0)\r
sprintf(cfg, "game.%i.cfg", config_slot);\r
else strcpy(cfg, "game.cfg");\r
- ret = config_readsect(cfg, emu_makeRomId());\r
\r
- if (ret != 0)\r
+ ret = -1;\r
+ if (config_havesect(cfg, sect))\r
{\r
- // fall back to old\r
- char extbuf[16];\r
- if (config_slot != 0)\r
- sprintf(extbuf, ".%i.pbcfg", config_slot);\r
- else strcpy(extbuf, ".pbcfg");\r
- romfname_ext(cfg, "cfg/", extbuf);\r
- f = fopen(cfg, "rb");\r
- if (!f) {\r
- romfname_ext(cfg, NULL, ".pbcfg");\r
- f = fopen(cfg, "rb");\r
- }\r
- if (f) {\r
- int bread = fread(¤tConfig, 1, sizeof(currentConfig), f);\r
- lprintf("emu_ReadConfig: %s %s\n", cfg, bread > 0 ? "(ok)" : "(failed)");\r
- fclose(f);\r
- ret = 0;\r
- }\r
-\r
- if (ret == 0) {\r
- PicoOpt = currentConfig.s_PicoOpt;\r
- PsndRate = currentConfig.s_PsndRate;\r
- PicoRegionOverride = currentConfig.s_PicoRegion;\r
- PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
- PicoCDBuffers = currentConfig.s_PicoCDBuffers;\r
- }\r
+ // read user's config\r
+ int vol = currentConfig.volume;\r
+ emu_setDefaultConfig();\r
+ ret = config_readsect(cfg, sect);\r
+ currentConfig.volume = vol; // make vol global (bah)\r
}\r
else\r
{\r
- lprintf("loaded cf from game sect\n");\r
+ // read global config, and apply game_def.cfg on top\r
+ make_config_cfg(cfg);\r
+ config_readsect(cfg, NULL);\r
+ ret = config_readsect("game_def.cfg", sect);\r
+ }\r
+\r
+ if (ret == 0)\r
+ {\r
+ lprintf("loaded cfg from sect \"%s\"\n", sect);\r
}\r
}\r
\r
if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
#ifdef PSP\r
if (currentConfig.gamma < -4 || currentConfig.gamma > 16) currentConfig.gamma = 0;\r
+ if (currentConfig.gamma2 < 0 || currentConfig.gamma2 > 2) currentConfig.gamma2 = 0;\r
#else\r
if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
#endif\r
\r
if (!is_game)\r
{\r
- strncpy(cfg, PicoConfigFile, 511);\r
- if (config_slot != 0)\r
- {\r
- char *p = strrchr(cfg, '.');\r
- if (p == NULL) p = cfg + strlen(cfg);\r
- sprintf(p, ".%i.cfg", config_slot);\r
- }\r
- cfg[511] = 0;\r
+ make_config_cfg(cfg);\r
write_lrom = 1;\r
} else {\r
if (config_slot != 0)\r
sprintf(cfg, "game.%i.cfg", config_slot);\r
else strcpy(cfg, "game.cfg");\r
game_sect = emu_makeRomId();\r
+ lprintf("emu_WriteConfig: sect \"%s\"\n", game_sect);\r
}\r
\r
lprintf("emu_WriteConfig: %s ", cfg);\r
ret = config_writesect(cfg, game_sect);\r
+ if (write_lrom) config_writelrom(cfg);\r
#ifndef NO_SYNC\r
sync();\r
#endif\r
}\r
\r
\r
+#ifndef UIQ3\r
void emu_textOut8(int x, int y, const char *text)\r
{\r
int i,l,len=strlen(text);\r
screen += 8;\r
}\r
}\r
+#endif\r
+\r
+#ifdef PSP\r
+#define MAX_COMBO_KEY 23\r
+#else\r
+#define MAX_COMBO_KEY 31\r
+#endif\r
+\r
+void emu_findKeyBindCombos(void)\r
+{\r
+ int act, u;\r
+\r
+ // find out which keys and actions are combos\r
+ kb_combo_keys = kb_combo_acts = 0;\r
+ for (act = 0; act < 32; act++)\r
+ {\r
+ int keyc = 0, keyc2 = 0;\r
+ if (act == 16 || act == 17) continue; // player2 flag\r
+ if (act > 17)\r
+ {\r
+ for (u = 0; u <= MAX_COMBO_KEY; u++)\r
+ if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;\r
+ }\r
+ else\r
+ {\r
+ for (u = 0; u <= MAX_COMBO_KEY; u++)\r
+ if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1\r
+ (currentConfig.KeyBinds[u] & (1 << act))) keyc++;\r
+ for (u = 0; u <= MAX_COMBO_KEY; u++)\r
+ if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2\r
+ (currentConfig.KeyBinds[u] & (1 << act))) keyc2++;\r
+ if (keyc2 > keyc) keyc = keyc2;\r
+ }\r
+ if (keyc > 1)\r
+ {\r
+ // loop again and mark those keys and actions as combo\r
+ for (u = 0; u <= MAX_COMBO_KEY; u++)\r
+ {\r
+ if (currentConfig.KeyBinds[u] & (1 << act)) {\r
+ kb_combo_keys |= 1 << u;\r
+ kb_combo_acts |= 1 << act;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ // printf("combo keys/acts: %08x %08x\n", kb_combo_keys, kb_combo_acts);\r
+}\r
\r
\r
void emu_updateMovie(void)\r
} else {\r
// MXYZ SACB RLDU\r
PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU\r
- if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // A\r
- if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // B\r
- if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // A\r
+ if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // C\r
+ if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // A\r
+ if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // B\r
PicoPad[1] = ~movie_data[offs+1] & 0x8f; // ! SCBA RLDU\r
- if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // A\r
- if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // B\r
- if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // A\r
+ if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // C\r
+ if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // A\r
+ if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // B\r
PicoPad[0] |= (~movie_data[offs+2] & 0x0A) << 8; // ! MZYX\r
if(!(movie_data[offs+2] & 0x01)) PicoPad[0] |= 0x0400; // X\r
if(!(movie_data[offs+2] & 0x04)) PicoPad[0] |= 0x0100; // Z\r
\r
if (is_sram)\r
{\r
- romfname_ext(saveFname, (PicoMCD&1) ? "brm/" : "srm/", (PicoMCD&1) ? ".brm" : ".srm");\r
+ romfname_ext(saveFname, (PicoAHW&1) ? "brm"PATH_SEP : "srm"PATH_SEP, (PicoAHW&1) ? ".brm" : ".srm");\r
if (load) {\r
if (try_ropen_file(saveFname)) return saveFname;\r
// try in current dir..\r
- romfname_ext(saveFname, NULL, (PicoMCD&1) ? ".brm" : ".srm");\r
+ romfname_ext(saveFname, NULL, (PicoAHW & PAHW_MCD) ? ".brm" : ".srm");\r
if (try_ropen_file(saveFname)) return saveFname;\r
return NULL; // give up\r
}\r
{\r
ext[0] = 0;\r
if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);\r
- strcat(ext, (currentConfig.EmuOpt & 8) ? ".mds.gz" : ".mds");\r
+ strcat(ext, (currentConfig.EmuOpt & EOPT_GZIP_SAVES) ? ".mds.gz" : ".mds");\r
\r
- romfname_ext(saveFname, "mds/", ext);\r
+ romfname_ext(saveFname, "mds" PATH_SEP, ext);\r
if (load) {\r
if (try_ropen_file(saveFname)) return saveFname;\r
romfname_ext(saveFname, NULL, ext);\r
if (try_ropen_file(saveFname)) return saveFname;\r
- if (currentConfig.EmuOpt & 8) {\r
+ // no gzipped states, search for non-gzipped\r
+ if (currentConfig.EmuOpt & EOPT_GZIP_SAVES)\r
+ {\r
ext[0] = 0;\r
if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);\r
strcat(ext, ".mds");\r
\r
- romfname_ext(saveFname, "mds/", ext);\r
+ romfname_ext(saveFname, "mds"PATH_SEP, ext);\r
if (try_ropen_file(saveFname)) return saveFname;\r
romfname_ext(saveFname, NULL, ext);\r
if (try_ropen_file(saveFname)) return saveFname;\r
int sram_size;\r
unsigned char *sram_data;\r
int truncate = 1;\r
- if (PicoMCD&1) {\r
- if (PicoOpt&0x8000) { // MCD RAM cart?\r
+ if (PicoAHW & PAHW_MCD)\r
+ {\r
+ if (PicoOpt&POPT_EN_MCD_RAMCART) {\r
sram_size = 0x12000;\r
sram_data = SRam.data;\r
if (sram_data)\r
}\r
if (!sram_data) return 0; // SRam forcefully disabled for this game\r
\r
- if (load) {\r
+ if (load)\r
+ {\r
sramFile = fopen(saveFname, "rb");\r
if(!sramFile) return -1;\r
fread(sram_data, 1, sram_size, sramFile);\r
fclose(sramFile);\r
- if ((PicoMCD&1) && (PicoOpt&0x8000))\r
+ if ((PicoAHW & PAHW_MCD) && (PicoOpt&POPT_EN_MCD_RAMCART))\r
memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4);\r
} else {\r
// sram save needs some special processing\r
}\r
else ret = -1;\r
if (!ret)\r
- strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED ");\r
+ strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED ");\r
else\r
{\r
- strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED ");\r
+ strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED ");\r
ret = -1;\r
}\r
\r
return ret;\r
}\r
}\r
+\r
+void emu_changeFastForward(int set_on)\r
+{\r
+ static void *set_PsndOut = NULL;\r
+ static int set_Frameskip, set_EmuOpt, is_on = 0;\r
+\r
+ if (set_on && !is_on) {\r
+ set_PsndOut = PsndOut;\r
+ set_Frameskip = currentConfig.Frameskip;\r
+ set_EmuOpt = currentConfig.EmuOpt;\r
+ PsndOut = NULL;\r
+ currentConfig.Frameskip = 8;\r
+ currentConfig.EmuOpt &= ~4;\r
+ currentConfig.EmuOpt |= 0x40000;\r
+ is_on = 1;\r
+ strcpy(noticeMsg, "FAST FORWARD ");\r
+ emu_noticeMsgUpdated();\r
+ }\r
+ else if (!set_on && is_on) {\r
+ PsndOut = set_PsndOut;\r
+ currentConfig.Frameskip = set_Frameskip;\r
+ currentConfig.EmuOpt = set_EmuOpt;\r
+ PsndRerate(1);\r
+ is_on = 0;\r
+ }\r
+}\r
+\r
+void emu_RunEventsPico(unsigned int events)\r
+{\r
+ if (events & (1 << 3)) {\r
+ pico_inp_mode++;\r
+ if (pico_inp_mode > 2) pico_inp_mode = 0;\r
+ switch (pico_inp_mode) {\r
+ case 2: strcpy(noticeMsg, "Input: Pen on Pad "); break;\r
+ case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break;\r
+ case 0: strcpy(noticeMsg, "Input: Joytick ");\r
+ PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
+ break;\r
+ }\r
+ emu_noticeMsgUpdated();\r
+ }\r
+ if (events & (1 << 4)) {\r
+ PicoPicohw.page--;\r
+ if (PicoPicohw.page < 0) PicoPicohw.page = 0;\r
+ sprintf(noticeMsg, "Page %i ", PicoPicohw.page);\r
+ emu_noticeMsgUpdated();\r
+ }\r
+ if (events & (1 << 5)) {\r
+ PicoPicohw.page++;\r
+ if (PicoPicohw.page > 6) PicoPicohw.page = 6;\r
+ sprintf(noticeMsg, "Page %i ", PicoPicohw.page);\r
+ emu_noticeMsgUpdated();\r
+ }\r
+}\r
+\r
+void emu_DoTurbo(int *pad, int acts)\r
+{\r
+ static int turbo_pad = 0;\r
+ static unsigned char turbo_cnt[3] = { 0, 0, 0 };\r
+ int inc = currentConfig.turbo_rate * 2;\r
+\r
+ if (acts & 0x1000) {\r
+ turbo_cnt[0] += inc;\r
+ if (turbo_cnt[0] >= 60)\r
+ turbo_pad ^= 0x10, turbo_cnt[0] = 0;\r
+ }\r
+ if (acts & 0x2000) {\r
+ turbo_cnt[1] += inc;\r
+ if (turbo_cnt[1] >= 60)\r
+ turbo_pad ^= 0x20, turbo_cnt[1] = 0;\r
+ }\r
+ if (acts & 0x4000) {\r
+ turbo_cnt[2] += inc;\r
+ if (turbo_cnt[2] >= 60)\r
+ turbo_pad ^= 0x40, turbo_cnt[2] = 0;\r
+ }\r
+ *pad |= turbo_pad & (acts >> 8);\r
+}\r
+\r