mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 14:57:46 -04:00
starting SMS work
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@756 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
3d792006ac
commit
2f3ca01638
4 changed files with 144 additions and 60 deletions
188
common/emu.c
188
common/emu.c
|
@ -174,8 +174,7 @@ static int emu_isBios(const char *name)
|
||||||
|
|
||||||
static unsigned char id_header[0x100];
|
static unsigned char id_header[0x100];
|
||||||
|
|
||||||
/* checks if fname points to valid MegaCD image
|
/* checks if fname points to valid MegaCD image */
|
||||||
* if so, checks for suitable BIOS */
|
|
||||||
static int emu_cd_check(int *pregion, const char *fname_in)
|
static int emu_cd_check(int *pregion, const char *fname_in)
|
||||||
{
|
{
|
||||||
const char *fname = fname_in;
|
const char *fname = fname_in;
|
||||||
|
@ -243,6 +242,58 @@ static int emu_cd_check(int *pregion, const char *fname_in)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int detect_media(const char *fname)
|
||||||
|
{
|
||||||
|
static const short sms_offsets[] = { 0x7ff0, 0x3ff0, 0x1ff0 };
|
||||||
|
pm_file *pmf;
|
||||||
|
char buff[32];
|
||||||
|
char ext[5];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
get_ext(fname, ext);
|
||||||
|
|
||||||
|
// detect wrong extensions
|
||||||
|
if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) // s.gz ~ .mds.gz
|
||||||
|
return PM_BAD;
|
||||||
|
|
||||||
|
/* don't believe in extensions, except .cue */
|
||||||
|
if (strcasecmp(ext, ".cue") == 0)
|
||||||
|
return PM_CD;
|
||||||
|
|
||||||
|
pmf = pm_open(fname);
|
||||||
|
if (pmf == NULL)
|
||||||
|
return PM_BAD;
|
||||||
|
|
||||||
|
if (pm_read(buff, 32, pmf) != 32) {
|
||||||
|
pm_close(pmf);
|
||||||
|
return PM_BAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncasecmp("SEGADISCSYSTEM", buff + 0x00, 14) == 0 ||
|
||||||
|
strncasecmp("SEGADISCSYSTEM", buff + 0x10, 14) == 0) {
|
||||||
|
pm_close(pmf);
|
||||||
|
return PM_CD;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 */
|
||||||
|
|
||||||
|
if (pm_read(buff, 16, pmf) != 16)
|
||||||
|
goto not_mark3;
|
||||||
|
|
||||||
|
if (strncasecmp("TMR SEGA", buff, 8) == 0) {
|
||||||
|
pm_close(pmf);
|
||||||
|
return PM_MARK3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
not_mark3:
|
||||||
|
pm_close(pmf);
|
||||||
|
/* the main emu function is to emulate MD, so assume MD */
|
||||||
|
return PM_MD_CART;
|
||||||
|
}
|
||||||
|
|
||||||
static int extract_text(char *dest, const unsigned char *src, int len, int swab)
|
static int extract_text(char *dest, const unsigned char *src, int len, int swab)
|
||||||
{
|
{
|
||||||
char *p = dest;
|
char *p = dest;
|
||||||
|
@ -321,6 +372,7 @@ static void shutdown_MCD(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: this function might mangle rom_fname
|
// note: this function might mangle rom_fname
|
||||||
|
// XXX: portions of this code should move to pico/
|
||||||
int emu_reload_rom(char *rom_fname)
|
int emu_reload_rom(char *rom_fname)
|
||||||
{
|
{
|
||||||
unsigned int rom_size = 0;
|
unsigned int rom_size = 0;
|
||||||
|
@ -328,20 +380,14 @@ int emu_reload_rom(char *rom_fname)
|
||||||
unsigned char *rom_data = NULL;
|
unsigned char *rom_data = NULL;
|
||||||
char ext[5];
|
char ext[5];
|
||||||
pm_file *rom = NULL;
|
pm_file *rom = NULL;
|
||||||
int ret, cd_state, cd_region, cfg_loaded = 0;
|
int cd_state = CIT_NOT_CD;
|
||||||
|
int ret, media_type, cd_region;
|
||||||
|
int cfg_loaded = 0, bad_rom = 0;
|
||||||
|
|
||||||
lprintf("emu_ReloadRom(%s)\n", rom_fname);
|
lprintf("emu_ReloadRom(%s)\n", rom_fname);
|
||||||
|
|
||||||
get_ext(rom_fname, ext);
|
get_ext(rom_fname, ext);
|
||||||
|
|
||||||
// detect wrong extensions
|
|
||||||
if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz
|
|
||||||
me_update_msg("Not a ROM/CD selected.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PicoPatchUnload();
|
|
||||||
|
|
||||||
// check for movie file
|
// check for movie file
|
||||||
if (movie_data) {
|
if (movie_data) {
|
||||||
free(movie_data);
|
free(movie_data);
|
||||||
|
@ -396,46 +442,53 @@ int emu_reload_rom(char *rom_fname)
|
||||||
get_ext(rom_fname, ext);
|
get_ext(rom_fname, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
media_type = detect_media(rom_fname);
|
||||||
|
if (media_type == PM_BAD) {
|
||||||
|
me_update_msg("Not a ROM/CD img selected.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
shutdown_MCD();
|
shutdown_MCD();
|
||||||
|
PicoPatchUnload();
|
||||||
|
|
||||||
// check for MegaCD image
|
if (media_type == PM_CD)
|
||||||
cd_state = emu_cd_check(&cd_region, rom_fname);
|
|
||||||
if (cd_state >= 0 && cd_state != CIT_NOT_CD)
|
|
||||||
{
|
{
|
||||||
PicoAHW |= PAHW_MCD;
|
// check for MegaCD image
|
||||||
// valid CD image, check for BIOS..
|
cd_state = emu_cd_check(&cd_region, rom_fname);
|
||||||
|
if (cd_state >= 0 && cd_state != CIT_NOT_CD)
|
||||||
|
{
|
||||||
|
// valid CD image, check for BIOS..
|
||||||
|
|
||||||
// we need to have config loaded at this point
|
// we need to have config loaded at this point
|
||||||
ret = emu_read_config(1, 0);
|
ret = emu_read_config(1, 0);
|
||||||
if (!ret) emu_read_config(0, 0);
|
if (!ret) emu_read_config(0, 0);
|
||||||
cfg_loaded = 1;
|
cfg_loaded = 1;
|
||||||
|
|
||||||
if (PicoRegionOverride) {
|
if (PicoRegionOverride) {
|
||||||
cd_region = PicoRegionOverride;
|
cd_region = PicoRegionOverride;
|
||||||
lprintf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA");
|
lprintf("override region to %s\n", cd_region != 4 ?
|
||||||
|
(cd_region == 8 ? "EU" : "JAP") : "USA");
|
||||||
|
}
|
||||||
|
if (!find_bios(cd_region, &used_rom_name))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
get_ext(used_rom_name, ext);
|
||||||
|
PicoAHW |= PAHW_MCD;
|
||||||
}
|
}
|
||||||
if (!find_bios(cd_region, &used_rom_name)) {
|
else {
|
||||||
PicoAHW &= ~PAHW_MCD;
|
me_update_msg("Invalid CD image");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_ext(used_rom_name, ext);
|
|
||||||
}
|
}
|
||||||
else
|
else if (media_type == PM_MARK3) {
|
||||||
{
|
lprintf("detected SMS ROM\n");
|
||||||
if (PicoAHW & PAHW_MCD) Stop_CD();
|
PicoAHW = PAHW_SMS;
|
||||||
PicoAHW &= ~PAHW_MCD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rom = pm_open(used_rom_name);
|
rom = pm_open(used_rom_name);
|
||||||
if (!rom) {
|
if (rom == NULL) {
|
||||||
me_update_msg("Failed to open ROM/CD image");
|
me_update_msg("Failed to open ROM");
|
||||||
goto fail;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (cd_state < 0) {
|
|
||||||
me_update_msg("Invalid CD image");
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu_romload_prepare(used_rom_name); // also CD load
|
menu_romload_prepare(used_rom_name); // also CD load
|
||||||
|
@ -443,21 +496,29 @@ int emu_reload_rom(char *rom_fname)
|
||||||
PicoCartUnload();
|
PicoCartUnload();
|
||||||
rom_loaded = 0;
|
rom_loaded = 0;
|
||||||
|
|
||||||
if ( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) {
|
ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoAHW & PAHW_SMS) ? 1 : 0);
|
||||||
|
pm_close(rom);
|
||||||
|
if (ret != 0) {
|
||||||
if (ret == 2) me_update_msg("Out of memory");
|
if (ret == 2) me_update_msg("Out of memory");
|
||||||
else if (ret == 3) me_update_msg("Read failed");
|
else if (ret == 3) me_update_msg("Read failed");
|
||||||
else me_update_msg("PicoCartLoad() failed.");
|
else me_update_msg("PicoCartLoad() failed.");
|
||||||
goto fail2;
|
goto fail;
|
||||||
}
|
}
|
||||||
pm_close(rom);
|
|
||||||
rom = NULL;
|
|
||||||
|
|
||||||
// detect wrong files (Pico crashes on very small files), also see if ROM EP is good
|
// detect wrong files
|
||||||
if (rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||
|
if (strncmp((char *)rom_data, "Pico", 4) == 0)
|
||||||
((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {
|
bad_rom = 1;
|
||||||
if (rom_data) free(rom_data);
|
else if (!(PicoAHW & PAHW_SMS)) {
|
||||||
me_update_msg("Not a ROM selected.");
|
unsigned short *d = (unsigned short *)(rom_data + 4);
|
||||||
goto fail2;
|
if ((((d[0] << 16) | d[1]) & 0xffffff) >= (int)rom_size) {
|
||||||
|
lprintf("bad reset vector\n");
|
||||||
|
bad_rom = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bad_rom) {
|
||||||
|
me_update_msg("Bad ROM detected.");
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load config for this ROM (do this before insert to get correct region)
|
// load config for this ROM (do this before insert to get correct region)
|
||||||
|
@ -468,18 +529,19 @@ int emu_reload_rom(char *rom_fname)
|
||||||
if (!ret) emu_read_config(0, 0);
|
if (!ret) emu_read_config(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);
|
|
||||||
if (PicoCartInsert(rom_data, rom_size)) {
|
if (PicoCartInsert(rom_data, rom_size)) {
|
||||||
me_update_msg("Failed to load ROM.");
|
me_update_msg("Failed to load ROM.");
|
||||||
goto fail2;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert CD if it was detected
|
// insert CD if it was detected
|
||||||
if (cd_state != CIT_NOT_CD) {
|
if (cd_state != CIT_NOT_CD) {
|
||||||
ret = Insert_CD(rom_fname, cd_state);
|
ret = Insert_CD(rom_fname, cd_state);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
PicoCartUnload();
|
||||||
|
rom_data = NULL; // freed by unload
|
||||||
me_update_msg("Insert_CD() failed, invalid CD image?");
|
me_update_msg("Insert_CD() failed, invalid CD image?");
|
||||||
goto fail2;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,8 +573,22 @@ int emu_reload_rom(char *rom_fname)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
const char *sys_name, *tv_standard;
|
||||||
|
int fps;
|
||||||
|
|
||||||
|
if (PicoAHW & PAHW_SMS) {
|
||||||
|
sys_name = "Master System";
|
||||||
|
} else {
|
||||||
|
sys_name = "MegaDrive";
|
||||||
|
if ((Pico.m.hardware&0xc0) == 0x80)
|
||||||
|
sys_name = "Genesis";
|
||||||
|
}
|
||||||
|
tv_standard = Pico.m.pal ? "PAL" : "NTSC";
|
||||||
|
fps = Pico.m.pal ? 50 : 60;
|
||||||
|
|
||||||
|
emu_status_msg("%s %s / %dFPS", tv_standard, sys_name, fps);
|
||||||
|
|
||||||
PicoOpt &= ~POPT_DIS_VDP_FIFO;
|
PicoOpt &= ~POPT_DIS_VDP_FIFO;
|
||||||
emu_status_msg(Pico.m.pal ? "PAL SYSTEM / 50 FPS" : "NTSC SYSTEM / 60 FPS");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);
|
strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);
|
||||||
|
@ -525,10 +601,10 @@ int emu_reload_rom(char *rom_fname)
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
fail2:
|
|
||||||
menu_romload_end();
|
|
||||||
fail:
|
fail:
|
||||||
if (rom != NULL) pm_close(rom);
|
if (rom_data)
|
||||||
|
free(rom_data);
|
||||||
|
menu_romload_end();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define array_size(x) (sizeof(x) / sizeof(x[0]))
|
||||||
|
|
||||||
extern void *g_screen_ptr;
|
extern void *g_screen_ptr;
|
||||||
|
|
||||||
#if SCREEN_SIZE_FIXED
|
#if SCREEN_SIZE_FIXED
|
||||||
|
@ -97,6 +99,13 @@ enum TPicoGameState {
|
||||||
PGS_SuspendWake, /* PSP */
|
PGS_SuspendWake, /* PSP */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// media types
|
||||||
|
enum {
|
||||||
|
PM_BAD = 0,
|
||||||
|
PM_MD_CART, /* also 32x */
|
||||||
|
PM_MARK3,
|
||||||
|
PM_CD,
|
||||||
|
};
|
||||||
|
|
||||||
void emu_init(void);
|
void emu_init(void);
|
||||||
void emu_finish(void);
|
void emu_finish(void);
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#include <pico/pico_int.h>
|
#include <pico/pico_int.h>
|
||||||
#include <pico/patch.h>
|
#include <pico/patch.h>
|
||||||
|
|
||||||
#define array_size(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
|
|
||||||
static char static_buff[64];
|
static char static_buff[64];
|
||||||
static char menu_error_msg[64] = { 0, };
|
static char menu_error_msg[64] = { 0, };
|
||||||
static int menu_error_time = 0;
|
static int menu_error_time = 0;
|
||||||
|
|
|
@ -12,7 +12,7 @@ CFLAGS += -O3 -Wall
|
||||||
CFLAGS += -ftracer -fstrength-reduce -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math
|
CFLAGS += -ftracer -fstrength-reduce -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math
|
||||||
CFLAGS += -fprofile-generate
|
CFLAGS += -fprofile-generate
|
||||||
else
|
else
|
||||||
CFLAGS = -ggdb -Wall
|
CFLAGS = -ggdb -Wall -falign-functions=2
|
||||||
endif
|
endif
|
||||||
DEFINES = _UNZIP_SUPPORT IO_STATS IN_EVDEV
|
DEFINES = _UNZIP_SUPPORT IO_STATS IN_EVDEV
|
||||||
CFLAGS += -I../.. -I.
|
CFLAGS += -I../.. -I.
|
||||||
|
@ -38,7 +38,8 @@ endif
|
||||||
|
|
||||||
# Pico
|
# Pico
|
||||||
OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o \
|
OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o \
|
||||||
pico/videoport.o pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o pico/debug.o
|
pico/videoport.o pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o \
|
||||||
|
pico/sms.o pico/debug.o
|
||||||
# Pico - CD
|
# Pico - CD
|
||||||
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \
|
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \
|
||||||
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/cue.o pico/cd/gfx_cd.o \
|
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/cue.o pico/cd/gfx_cd.o \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue