X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Femu.c;h=494484bdc2cb01de22cca5cca44940adcb4e9fca;hb=fe01739339fe177363948c6fd518352243d5cf37;hp=1d57e226e08eafc6d41d55271fbbb4c1e9b7e5b0;hpb=a479005630268d6f2adfcc0f9562593f643c4c2c;p=libpicofe.git diff --git a/common/emu.c b/common/emu.c index 1d57e22..494484b 100644 --- a/common/emu.c +++ b/common/emu.c @@ -15,25 +15,13 @@ #include "fonts.h" #include "lprintf.h" #include "config.h" +#include "common.h" #include #include #include #include -#if defined(__GP2X__) - #include "../gp2x/gp2x.h" - #define SCREEN_WIDTH 320 - #define SCREEN_BUFFER gp2x_screen -#elif defined(__GIZ__) - #include "../gizmondo/giz.h" - #define SCREEN_WIDTH 321 - #define SCREEN_BUFFER giz_screen -#elif defined(PSP) - #include "../psp/psp.h" - #define SCREEN_WIDTH 512 - #define SCREEN_BUFFER psp_screen -#endif char *PicoConfigFile = "config.cfg"; currentConfig_t currentConfig, defaultConfig; @@ -43,6 +31,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; @@ -176,17 +165,19 @@ int emu_cdCheck(int *pregion) fname = cue_data->tracks[1].fname; type = cue_data->tracks[1].type; } + else + return -1; } cd_f = pm_open(fname); if (cue_data != NULL) cue_destroy(cue_data); - if (!cd_f) return 0; // let the upper level handle this + if (cd_f == NULL) return 0; // let the upper level handle this if (pm_read(buf, 32, cd_f) != 32) { pm_close(cd_f); - return 0; + return -1; } if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) { @@ -283,7 +274,7 @@ int emu_ReloadRom(void) char *used_rom_name = romFileName; unsigned char *rom_data = NULL; char ext[5]; - pm_file *rom; + pm_file *rom = NULL; int ret, cd_state, cd_region, cfg_loaded = 0; lprintf("emu_ReloadRom(%s)\n", romFileName); @@ -292,7 +283,7 @@ int emu_ReloadRom(void) // detect wrong extensions if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz - sprintf(menuErrorMsg, "Not a ROM selected."); + sprintf(menuErrorMsg, "Not a ROM/CD selected."); return 0; } @@ -355,7 +346,7 @@ int emu_ReloadRom(void) // check for MegaCD image cd_state = emu_cdCheck(&cd_region); - if (cd_state != CIT_NOT_CD) + if (cd_state >= 0 && cd_state != CIT_NOT_CD) { PicoAHW |= PAHW_MCD; // valid CD image, check for BIOS.. @@ -385,8 +376,13 @@ int emu_ReloadRom(void) rom = pm_open(used_rom_name); if (!rom) { - sprintf(menuErrorMsg, "Failed to open rom."); - return 0; + sprintf(menuErrorMsg, "Failed to open ROM/CD image"); + goto fail; + } + + if (cd_state < 0) { + sprintf(menuErrorMsg, "Invalid CD image"); + goto fail; } menu_romload_prepare(used_rom_name); // also CD load @@ -397,19 +393,17 @@ int emu_ReloadRom(void) if ( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { sprintf(menuErrorMsg, "PicoCartLoad() failed."); lprintf("%s\n", menuErrorMsg); - pm_close(rom); - menu_romload_end(); - return 0; + goto fail2; } pm_close(rom); + rom = NULL; // detect wrong files (Pico crashes on very small files), also see if ROM EP is good if (rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) { if (rom_data) free(rom_data); sprintf(menuErrorMsg, "Not a ROM selected."); - menu_romload_end(); - return 0; + goto fail2; } // load config for this ROM (do this before insert to get correct region) @@ -423,8 +417,7 @@ int emu_ReloadRom(void) lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); if (PicoCartInsert(rom_data, rom_size)) { sprintf(menuErrorMsg, "Failed to load ROM."); - menu_romload_end(); - return 0; + goto fail2; } // insert CD if it was detected @@ -433,8 +426,7 @@ int emu_ReloadRom(void) if (ret != 0) { sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?"); lprintf("%s\n", menuErrorMsg); - menu_romload_end(); - return 0; + goto fail2; } } @@ -446,13 +438,14 @@ int emu_ReloadRom(void) } // additional movie stuff - if (movie_data) { - if(movie_data[0x14] == '6') + if (movie_data) + { + if (movie_data[0x14] == '6') PicoOpt |= POPT_6BTN_PAD; // 6 button pad else PicoOpt &= ~POPT_6BTN_PAD; PicoOpt |= POPT_DIS_VDP_FIFO; // no VDP fifo timing - if(movie_data[0xF] >= 'A') { - if(movie_data[0x16] & 0x80) { + if (movie_data[0xF] >= 'A') { + if (movie_data[0x16] & 0x80) { PicoRegionOverride = 8; } else { PicoRegionOverride = 4; @@ -466,7 +459,7 @@ int emu_ReloadRom(void) else { PicoOpt &= ~POPT_DIS_VDP_FIFO; - if(Pico.m.pal) { + if (Pico.m.pal) { strcpy(noticeMsg, "PAL SYSTEM / 50 FPS"); } else { strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS"); @@ -482,6 +475,12 @@ int emu_ReloadRom(void) lastRomFile[sizeof(lastRomFile)-1] = 0; rom_loaded = 1; return 1; + +fail2: + menu_romload_end(); +fail: + if (rom != NULL) pm_close(rom); + return 0; } @@ -959,10 +958,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; } @@ -971,3 +970,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); +} +