X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fcommon%2Femu.c;h=4a95a3fff8bacf5edc7354a400699b69f1845720;hb=19954be1966a04304b16d9180b003ec8ca3bc532;hp=1cecc39f6476f1ee7f7d757a1a23b34cd75cc681;hpb=3e49ffd0bf13f3a889cfb5196c2a61962dff6d0b;p=picodrive.git diff --git a/platform/common/emu.c b/platform/common/emu.c index 1cecc39..4a95a3f 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -245,8 +245,11 @@ static int emu_cd_check(int *pregion, const char *fname_in) static int detect_media(const char *fname) { static const short sms_offsets[] = { 0x7ff0, 0x3ff0, 0x1ff0 }; + static const char *sms_exts[] = { "sms", "gg", "sg" }; + static const char *md_exts[] = { "gen", "bin", "smd" }; + char buff0[32], buff[32]; + unsigned short *d16; pm_file *pmf; - char buff[32]; char ext[5]; int i; @@ -264,34 +267,69 @@ static int detect_media(const char *fname) if (pmf == NULL) return PM_BAD; - if (pm_read(buff, 32, pmf) != 32) { + if (pm_read(buff0, 32, pmf) != 32) { pm_close(pmf); return PM_BAD; } - if (strncasecmp("SEGADISCSYSTEM", buff + 0x00, 14) == 0 || - strncasecmp("SEGADISCSYSTEM", buff + 0x10, 14) == 0) { + if (strncasecmp("SEGADISCSYSTEM", buff0 + 0x00, 14) == 0 || + strncasecmp("SEGADISCSYSTEM", buff0 + 0x10, 14) == 0) { pm_close(pmf); return PM_CD; } + /* check for SMD evil */ + if (pmf->size >= 0x4200 && (pmf->size & 0x3fff) == 0x200) { + if (pm_seek(pmf, sms_offsets[0] + 0x200, SEEK_SET) == sms_offsets[0] + 0x200 && + pm_read(buff, 16, pmf) == 16 && + strncmp("TMR SEGA", buff, 8) == 0) + goto looks_like_sms; + + /* could parse further but don't bother */ + goto extension_check; + } + + /* MD header? Act as TMSS BIOS here */ + if (pm_seek(pmf, 0x100, SEEK_SET) == 0x100 && pm_read(buff, 16, pmf) == 16) { + if (strncmp(buff, "SEGA", 4) == 0 || strncmp(buff, " SEG", 4) == 0) + goto looks_like_md; + } + for (i = 0; i < array_size(sms_offsets); i++) { if (pm_seek(pmf, sms_offsets[i], SEEK_SET) != sms_offsets[i]) - goto not_mark3; /* actually it could be but can't be detected */ + continue; if (pm_read(buff, 16, pmf) != 16) - goto not_mark3; + continue; - if (strncasecmp("TMR SEGA", buff, 8) == 0) { - pm_close(pmf); - return PM_MARK3; - } + if (strncmp("TMR SEGA", buff, 8) == 0) + goto looks_like_sms; + } + +extension_check: + /* probably some headerless thing. Maybe check the extension after all. */ + for (i = 0; i < array_size(md_exts); i++) + if (strcasecmp(pmf->ext, md_exts[i]) == 0) + goto looks_like_md; + + for (i = 0; i < array_size(sms_exts); i++) + if (strcasecmp(pmf->ext, sms_exts[i]) == 0) + goto looks_like_sms; + + /* If everything else fails, make a guess on the reset vector */ + d16 = (unsigned short *)(buff0 + 4); + if ((((d16[0] << 16) | d16[1]) & 0xffffff) >= pmf->size) { + lprintf("bad MD reset vector, assuming SMS\n"); + goto looks_like_sms; } -not_mark3: +looks_like_md: pm_close(pmf); - /* the main emu function is to emulate MD, so assume MD */ return PM_MD_CART; + +looks_like_sms: + pm_close(pmf); + return PM_MARK3; } static int extract_text(char *dest, const unsigned char *src, int len, int swab) @@ -450,6 +488,7 @@ int emu_reload_rom(char *rom_fname) shutdown_MCD(); PicoPatchUnload(); + PicoAHW = 0; if (media_type == PM_CD) { @@ -1293,7 +1332,7 @@ void emu_loop(void) { int pframes_done; /* "period" frames, used for sync */ int frames_done, frames_shown; /* actual frames for fps counter */ - int oldmodes, target_fps, target_frametime; + int target_fps, target_frametime; unsigned int timestamp_base = 0, timestamp_fps; char *notice_msg = NULL; char fpsbuff[24]; @@ -1302,8 +1341,8 @@ void emu_loop(void) fpsbuff[0] = 0; /* make sure we are in correct mode */ - oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; Pico.m.dirtyPal = 1; + rendstatus_old = -1; /* number of ticks per frame */ if (Pico.m.pal) { @@ -1332,7 +1371,6 @@ void emu_loop(void) { unsigned int timestamp; int diff, diff_lim; - int modes; timestamp = get_ticks(); if (reset_timing) { @@ -1359,13 +1397,6 @@ void emu_loop(void) } } - // check for mode changes - modes = ((Pico.video.reg[12]&1)<<2) | (Pico.video.reg[1]&8); - if (modes != oldmodes) { - oldmodes = modes; - pemu_video_mode_change(!(modes & 4), (modes & 8)); - } - // second changed? if (timestamp - timestamp_fps >= ms_to_ticks(1000)) {