X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fcommon%2Femu.c;h=5b6935780b83618a1299c3578b72a4e535d70117;hb=39230401af19770c5470a7470f632fa66c8de3fd;hp=e4cce672d70f188718d329d10a8e365025306132;hpb=602133e1c66666f9152b1edb3014e137a9768cad;p=picodrive.git diff --git a/platform/common/emu.c b/platform/common/emu.c index e4cce67..5b69357 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -18,6 +18,7 @@ #include #include +#include #include #if defined(__GP2X__) @@ -42,6 +43,7 @@ int state_slot = 0; int config_slot = 0, config_slot_current = 0; char lastRomFile[512]; int kb_combo_keys = 0, kb_combo_acts = 0; // keys and actions which need button combos +int pico_inp_mode = 0; unsigned char *movie_data = NULL; static int movie_size = 0; @@ -163,9 +165,24 @@ int emu_cdCheck(int *pregion) { unsigned char buf[32]; pm_file *cd_f; - int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe + int region = 4; // 1: Japan, 4: US, 8: Europe + char ext[5], *fname = romFileName; + cue_track_type type = CT_UNKNOWN; + cue_data_t *cue_data = NULL; + + get_ext(romFileName, ext); + if (strcasecmp(ext, ".cue") == 0) { + cue_data = cue_parse(romFileName); + if (cue_data != NULL) { + fname = cue_data->tracks[1].fname; + type = cue_data->tracks[1].type; + } + } + + cd_f = pm_open(fname); + if (cue_data != NULL) + cue_destroy(cue_data); - cd_f = pm_open(romFileName); if (!cd_f) return 0; // let the upper level handle this if (pm_read(buf, 32, cd_f) != 32) { @@ -173,18 +190,27 @@ int emu_cdCheck(int *pregion) return 0; } - if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO) - if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN) - if (type == 0) { + if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) { + if (type && type != CT_ISO) + elprintf(EL_STATUS, ".cue has wrong type: %i", type); + type = CT_ISO; // Sega CD (ISO) + } + if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) { + if (type && type != CT_BIN) + elprintf(EL_STATUS, ".cue has wrong type: %i", type); + type = CT_BIN; // Sega CD (BIN) + } + + if (type == CT_UNKNOWN) { pm_close(cd_f); return 0; } - pm_seek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET); + pm_seek(cd_f, (type == CT_ISO) ? 0x100 : 0x110, SEEK_SET); pm_read(id_header, sizeof(id_header), cd_f); /* it seems we have a CD image here. Try to detect region now.. */ - pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); + pm_seek(cd_f, (type == CT_ISO) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); pm_read(buf, 1, cd_f); pm_close(cd_f); @@ -192,14 +218,14 @@ int emu_cdCheck(int *pregion) if (buf[0] == 0xa1) region = 1; // JAP lprintf("detected %s Sega/Mega CD image with %s region\n", - type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); + type == CT_BIN ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); if (pregion != NULL) *pregion = region; return type; } -static int extract_text(char *dest, unsigned char *src, int len, int swab) +static int extract_text(char *dest, const unsigned char *src, int len, int swab) { char *p = dest; int i; @@ -330,7 +356,7 @@ int emu_ReloadRom(void) // check for MegaCD image cd_state = emu_cdCheck(&cd_region); - if (cd_state > 0) + if (cd_state != CIT_NOT_CD) { PicoAHW |= PAHW_MCD; // valid CD image, check for BIOS.. @@ -402,11 +428,9 @@ int emu_ReloadRom(void) return 0; } - Pico.m.frame_count = 0; - // insert CD if it was detected - if (cd_state > 0) { - ret = Insert_CD(romFileName, cd_state == 2); + if (cd_state != CIT_NOT_CD) { + ret = Insert_CD(romFileName, cd_state); if (ret != 0) { sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?"); lprintf("%s\n", menuErrorMsg); @@ -427,7 +451,7 @@ int emu_ReloadRom(void) if(movie_data[0x14] == '6') PicoOpt |= POPT_6BTN_PAD; // 6 button pad else PicoOpt &= ~POPT_6BTN_PAD; - PicoOpt |= POPT_DIS_VDP_FIFO|POPT_ACC_TIMING; // accurate timing, no VDP fifo timing + PicoOpt |= POPT_DIS_VDP_FIFO; // no VDP fifo timing if(movie_data[0xF] >= 'A') { if(movie_data[0x16] & 0x80) { PicoRegionOverride = 8; @@ -572,6 +596,7 @@ int emu_ReadConfig(int game, int no_defaults) if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200; #ifdef PSP if (currentConfig.gamma < -4 || currentConfig.gamma > 16) currentConfig.gamma = 0; + if (currentConfig.gamma2 < 0 || currentConfig.gamma2 > 2) currentConfig.gamma2 = 0; #else if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100; #endif @@ -672,6 +697,12 @@ void emu_textOut16(int x, int y, const char *text) } } +#ifdef PSP +#define MAX_COMBO_KEY 23 +#else +#define MAX_COMBO_KEY 31 +#endif + void emu_findKeyBindCombos(void) { int act, u; @@ -684,15 +715,15 @@ void emu_findKeyBindCombos(void) if (act == 16 || act == 17) continue; // player2 flag if (act > 17) { - for (u = 0; u < 32; u++) + for (u = 0; u <= MAX_COMBO_KEY; u++) if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; } else { - for (u = 0; u < 32; u++) + for (u = 0; u <= MAX_COMBO_KEY; u++) if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 (currentConfig.KeyBinds[u] & (1 << act))) keyc++; - for (u = 0; u < 32; u++) + for (u = 0; u <= MAX_COMBO_KEY; u++) if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; if (keyc2 > keyc) keyc = keyc2; @@ -700,7 +731,7 @@ void emu_findKeyBindCombos(void) if (keyc > 1) { // loop again and mark those keys and actions as combo - for (u = 0; u < 32; u++) + for (u = 0; u <= MAX_COMBO_KEY; u++) { if (currentConfig.KeyBinds[u] & (1 << act)) { kb_combo_keys |= 1 << u; @@ -929,10 +960,10 @@ int emu_SaveLoadGame(int load, int sram) } else ret = -1; if (!ret) - strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED "); + strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED "); else { - strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED "); + strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED "); ret = -1; } @@ -941,3 +972,81 @@ int emu_SaveLoadGame(int load, int sram) } } +void emu_changeFastForward(int set_on) +{ + static void *set_PsndOut = NULL; + static int set_Frameskip, set_EmuOpt, is_on = 0; + + if (set_on && !is_on) { + set_PsndOut = PsndOut; + set_Frameskip = currentConfig.Frameskip; + set_EmuOpt = currentConfig.EmuOpt; + PsndOut = NULL; + currentConfig.Frameskip = 8; + currentConfig.EmuOpt &= ~4; + currentConfig.EmuOpt |= 0x40000; + is_on = 1; + strcpy(noticeMsg, "FAST FORWARD "); + emu_noticeMsgUpdated(); + } + else if (!set_on && is_on) { + PsndOut = set_PsndOut; + currentConfig.Frameskip = set_Frameskip; + currentConfig.EmuOpt = set_EmuOpt; + PsndRerate(1); + is_on = 0; + } +} + +void emu_RunEventsPico(unsigned int events) +{ + if (events & (1 << 3)) { + pico_inp_mode++; + if (pico_inp_mode > 2) pico_inp_mode = 0; + switch (pico_inp_mode) { + case 2: strcpy(noticeMsg, "Input: Pen on Pad "); break; + case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break; + case 0: strcpy(noticeMsg, "Input: Joytick "); + PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000; + break; + } + emu_noticeMsgUpdated(); + } + if (events & (1 << 4)) { + PicoPicohw.page--; + if (PicoPicohw.page < 0) PicoPicohw.page = 0; + sprintf(noticeMsg, "Page %i ", PicoPicohw.page); + emu_noticeMsgUpdated(); + } + if (events & (1 << 5)) { + PicoPicohw.page++; + if (PicoPicohw.page > 6) PicoPicohw.page = 6; + sprintf(noticeMsg, "Page %i ", PicoPicohw.page); + emu_noticeMsgUpdated(); + } +} + +void emu_DoTurbo(int *pad, int acts) +{ + static int turbo_pad = 0; + static unsigned char turbo_cnt[3] = { 0, 0, 0 }; + int inc = currentConfig.turbo_rate * 2; + + if (acts & 0x1000) { + turbo_cnt[0] += inc; + if (turbo_cnt[0] >= 60) + turbo_pad ^= 0x10, turbo_cnt[0] = 0; + } + if (acts & 0x2000) { + turbo_cnt[1] += inc; + if (turbo_cnt[1] >= 60) + turbo_pad ^= 0x20, turbo_cnt[1] = 0; + } + if (acts & 0x4000) { + turbo_cnt[2] += inc; + if (turbo_cnt[2] >= 60) + turbo_pad ^= 0x40, turbo_cnt[2] = 0; + } + *pad |= turbo_pad & (acts >> 8); +} +