X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=gp2x%2Femu.c;h=96150138f6a308b72ecc04f4ae22236763e75202;hb=0ad6c561aab998313765afd8ba43dee818f40662;hp=939ba93c447447673ab51ec6522fa8dbb6814fb9;hpb=13059a606f2ffeb411101101ddcac47be73ad625;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index 939ba93..9615013 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -18,14 +18,15 @@ #include "gp2x.h" #include "usbjoy.h" #include "menu.h" -#include "asmutils.h" +#include "../common/arm_utils.h" +#include "../common/fonts.h" #include "cpuctrl.h" -#include "fonts.h" #include #include #include +//#define PFRAMES #ifdef BENCHMARK #define OSD_FPS_X 220 @@ -52,7 +53,7 @@ static int combo_keys = 0, combo_acts = 0; // keys and actions which need button static int gp2x_old_gamma = 100; static unsigned char *movie_data = NULL; static int movie_size = 0; -unsigned char *framebuff = 0; // temporary buffer for alt renderer +unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer int state_slot = 0; int reset_timing = 0; int config_slot = 0, config_slot_current = 0; @@ -150,7 +151,7 @@ int find_bios(int region, char **bios_file) /* checks if romFileName points to valid MegaCD image * if so, checks for suitable BIOS */ -int emu_cd_check(char **bios_file) +int emu_cd_check(int *pregion) { unsigned char buf[32]; pm_file *cd_f; @@ -182,17 +183,9 @@ int emu_cd_check(char **bios_file) printf("detected %s Sega/Mega CD image with %s region\n", type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); - if (PicoRegionOverride) { - region = PicoRegionOverride; - printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); - } - - if (bios_file == NULL) return type; - - if (find_bios(region, bios_file)) - return type; // CD and BIOS detected + if (pregion != NULL) *pregion = region; - return -1; // CD detected but load failed + return type; } int emu_ReloadRom(void) @@ -201,7 +194,7 @@ int emu_ReloadRom(void) char *used_rom_name = romFileName; char ext[5]; pm_file *rom; - int ret, cd_state; + int ret, cd_state, cd_region, cfg_loaded = 0; printf("emu_ReloadRom(%s)\n", romFileName); @@ -270,15 +263,31 @@ int emu_ReloadRom(void) Stop_CD(); // check for MegaCD image - cd_state = emu_cd_check(&used_rom_name); - if (cd_state > 0) { + cd_state = emu_cd_check(&cd_region); + if (cd_state > 0) + { + // valid CD image, check for BIOS.. + + // we need to have config loaded at this point + ret = emu_ReadConfig(1, 1); + if (!ret) emu_ReadConfig(0, 1); + cfg_loaded = 1; + + if (PicoRegionOverride) { + cd_region = PicoRegionOverride; + printf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA"); + } + if (!find_bios(cd_region, &used_rom_name)) { + // bios_help() ? + return 0; + } + PicoMCD |= 1; get_ext(used_rom_name, ext); - } else if (cd_state == -1) { - // bios_help() ? - return 0; - } else { - if (PicoMCD & 1) PicoExitMCD(); + } + else + { + if (PicoMCD & 1) Stop_CD(); PicoMCD &= ~1; } @@ -316,9 +325,10 @@ int emu_ReloadRom(void) } // load config for this ROM (do this before insert to get correct region) - ret = emu_ReadConfig(1, 1); - if (!ret) - emu_ReadConfig(0, 1); + if (!cfg_loaded) { + ret = emu_ReadConfig(1, 1); + if (!ret) emu_ReadConfig(0, 1); + } printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); if(PicoCartInsert(rom_data, rom_size)) { @@ -348,11 +358,11 @@ int emu_ReloadRom(void) } // additional movie stuff - if(movie_data) { + if (movie_data) { if(movie_data[0x14] == '6') PicoOpt |= 0x20; // 6 button pad else PicoOpt &= ~0x20; - PicoOpt |= 0x40; // accurate timing + PicoOpt |= 0x10040; // accurate timing, no VDP fifo timing if(movie_data[0xF] >= 'A') { if(movie_data[0x16] & 0x80) { PicoRegionOverride = 8; @@ -367,6 +377,7 @@ int emu_ReloadRom(void) } else { + PicoOpt &= ~0x10000; if(Pico.m.pal) { strcpy(noticeMsg, "PAL SYSTEM / 50 FPS"); } else { @@ -389,10 +400,10 @@ static void emu_msg_tray_open(void); void emu_Init(void) { // make temp buffer for alt renderer - framebuff = malloc((8+320)*(8+240+8)); - if (!framebuff) + PicoDraw2FB = malloc((8+320)*(8+240+8)); + if (!PicoDraw2FB) { - printf("framebuff == 0\n"); + printf("PicoDraw2FB == 0\n"); } // make dirs for saves, cfgs, etc. @@ -626,7 +637,7 @@ void emu_Deinit(void) } } - free(framebuff); + free(PicoDraw2FB); PicoExit(); @@ -768,7 +779,7 @@ static void blit(const char *fps, const char *notice) // feed new palette to our device gp2x_video_setpalette(localPal, 0x40); } - vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); + vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); } else if (!(emu_opt&0x80)) { // 8bit accurate renderer if (Pico.m.dirtyPal) { @@ -1112,7 +1123,7 @@ void emu_forced_frame(void) clearArea(1); } else vidCpyM2 = vidCpyM2_40col; - vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); + vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); */ @@ -1185,17 +1196,18 @@ void emu_Loop(void) // prepare sound stuff if(currentConfig.EmuOpt & 4) { int snd_excess_add; - if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) { + if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || + ((PicoOpt&0x200) && crashed_940)) { /* if 940 is turned off, we need it to be put back to sleep */ if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) { Reset940(1, 2); Pause940(1); } - sound_rerate(1); + sound_rerate(Pico.m.frame_count ? 1 : 0); } - //excess_samples = PsndRate - PsndLen*target_fps; snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; - printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); + printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", + PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3); gp2x_sound_volume(currentConfig.volume, currentConfig.volume); PicoWriteSound = updateSound; @@ -1307,6 +1319,9 @@ void emu_Loop(void) if (frames_shown > frames_done) frames_shown = frames_done; } } +#ifdef PFRAMES + sprintf(fpsbuff, "%i", Pico.m.frame_count); +#endif lim_time = (frames_done+1) * target_frametime + vsync_offset; if(currentConfig.Frameskip >= 0) { // frameskip enabled @@ -1571,7 +1586,7 @@ int emu_SaveLoadGame(int load, int sram) } } else { sram_size = SRam.end-SRam.start+1; - if(SRam.reg_back & 4) sram_size=0x2000; + if(Pico.m.sram_reg & 4) sram_size=0x2000; sram_data = SRam.data; } if (!sram_data) return 0; // SRam forcefully disabled for this game