[libretro] fixed compilation issues & removed unused code

This commit is contained in:
EkeEke 2013-06-17 02:08:00 +02:00
parent f2800e6a2a
commit 4c46cc7833
2 changed files with 37 additions and 325 deletions

View File

@ -26,8 +26,6 @@ md_ntsc_t *md_ntsc;
static int vwidth; static int vwidth;
static int vheight; static int vheight;
char rom_filename[256];
unsigned retro_api_version(void) { return RETRO_API_VERSION; } unsigned retro_api_version(void) { return RETRO_API_VERSION; }
static retro_video_refresh_t video_cb; static retro_video_refresh_t video_cb;
@ -79,8 +77,6 @@ static struct bind_conv binds[] = {
static char g_rom_dir[1024]; static char g_rom_dir[1024];
extern uint8 system_hw;
char GG_ROM[256]; char GG_ROM[256];
char AR_ROM[256]; char AR_ROM[256];
char SK_ROM[256]; char SK_ROM[256];
@ -213,7 +209,7 @@ static void init_bitmap(void)
bitmap.viewport.y = 0; bitmap.viewport.y = 0;
} }
#define CONFIG_VERSION "GENPLUS-GX 1.6.1" #define CONFIG_VERSION "GENPLUS-GX 1.7.4"
static void config_default(void) static void config_default(void)
{ {
@ -226,7 +222,7 @@ static void config_default(void)
config.hq_fm = 1; config.hq_fm = 1;
config.psgBoostNoise = 1; config.psgBoostNoise = 1;
config.filter = 0; config.filter = 0;
config.lp_range = 50; config.lp_range = 0x9999; /* 0.6 in 16.16 fixed point */
config.low_freq = 880; config.low_freq = 880;
config.high_freq = 5000; config.high_freq = 5000;
config.lg = 1.0; config.lg = 1.0;
@ -234,6 +230,7 @@ static void config_default(void)
config.hg = 1.0; config.hg = 1.0;
config.dac_bits = 14; config.dac_bits = 14;
config.ym2413 = 2; /* AUTO */ config.ym2413 = 2; /* AUTO */
config.mono = 0;
/* system options */ /* system options */
config.system = 0; /* AUTO */ config.system = 0; /* AUTO */
@ -247,38 +244,10 @@ static void config_default(void)
config.hot_swap = 0; config.hot_swap = 0;
/* video options */ /* video options */
config.xshift = 0;
config.yshift = 0;
config.xscale = 0;
config.yscale = 0;
config.aspect = 0;
config.overscan = 0; /* 3 == FULL */ config.overscan = 0; /* 3 == FULL */
config.gg_extra = 0; /* 1 = show extended Game Gear screen (256x192) */ config.gg_extra = 0; /* 1 = show extended Game Gear screen (256x192) */
config.ntsc = 0; config.ntsc = 0;
config.vsync = 1; /* AUTO */
config.render = 0; config.render = 0;
config.bilinear = 0;
/* controllers options */
config.gun_cursor[0] = 1;
config.gun_cursor[1] = 1;
config.invert_mouse = 0;
/* menu options */
config.autoload = 0;
config.autocheat = 0;
config.s_auto = 0;
config.s_default = 1;
config.s_device = 0;
config.l_device = 0;
config.bg_overlay = 0;
config.screen_w = 658;
config.bgm_volume = 100.0;
config.sfx_volume = 100.0;
/* hot swap requires at least a first initialization */
config.hot_swap &= 1;
} }
/* these values are used for libretro reporting too */ /* these values are used for libretro reporting too */
@ -315,225 +284,28 @@ static void configure_controls(void)
} }
} }
static int slot_load(int slot)
/* Mega CD backup RAM specific */
static void bram_load(void)
{ {
char filename[MAXPATHLEN];
unsigned long filesize, done = 0;
uint8_t *buffer;
/* File Type */
if (slot > 0)
{
fprintf(stderr, "INFORMATION - Loading State ...\n");
}
else
{
if (!sram.on || (system_hw == SYSTEM_MCD))
{
fprintf(stderr, "ERROR - SRAM is disabled.\n");
return 0;
}
fprintf(stderr, "INFORMATION - Loading SRAM ...\n");
}
/* Device Type */
{
FILE *fp; FILE *fp;
/* FAT file */
if (slot > 0)
{
sprintf (filename,"%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1);
}
else
{
sprintf (filename,"%s/saves/%s.srm", DEFAULT_PATH, rom_filename);
}
/* Open file */
fp = fopen(filename, "rb");
if (!fp)
{
fprintf(stderr, "ERROR - Unable to open file.\n");
return 0;
}
/* Get file size */
fseek(fp, 0, SEEK_END);
filesize = ftell(fp);
fseek(fp, 0, SEEK_SET);
/* allocate buffer */
buffer = (uint8_t *)malloc(filesize);
if (!buffer)
{
fprintf(stderr, "ERROR - Unable to allocate memory.\n");
fclose(fp);
return 0;
}
/* Read into buffer (2k blocks) */
while (filesize > CHUNKSIZE)
{
fread(buffer + done, CHUNKSIZE, 1, fp);
done += CHUNKSIZE;
filesize -= CHUNKSIZE;
}
/* Read remaining bytes */
fread(buffer + done, filesize, 1, fp);
done += filesize;
/* Close file */
fclose(fp);
}
if (slot > 0)
{
/* Load state */
if (state_load(buffer) <= 0)
{
free(buffer);
fprintf(stderr, "Invalid state file.\n");
return 0;
}
}
else
{
/* load SRAM */
memcpy(sram.sram, buffer, 0x10000);
/* update CRC */
sram.crc = crc32(0, sram.sram, 0x10000);
}
free(buffer);
return 1;
}
static int slot_save(int slot)
{
FILE *fp;
char filename[MAXPATHLEN];
unsigned long filesize, done = 0;
uint8_t *buffer;
if (slot > 0)
{
fprintf(stderr, "INFORMATION - Saving State ...\n");
/* allocate buffer */
buffer = (uint8_t *)malloc(STATE_SIZE);
if (!buffer)
{
fprintf(stderr, "ERROR - Unable to allocate memory.\n");
return 0;
}
filesize = state_save(buffer);
}
else
{
/* only save if SRAM is enabled */
if (!sram.on || (system_hw == SYSTEM_MCD))
{
fprintf(stderr, "ERROR - SRAM is disabled.\n");
return 0;
}
/* only save if SRAM has been modified */
if (crc32(0, &sram.sram[0], 0x10000) == sram.crc)
{
fprintf(stderr, "WARNING - SRAM not modified.\n");
return 0;
}
fprintf(stderr, "INFORMATION - Saving SRAM ...\n");
/* allocate buffer */
buffer = (uint8_t *)malloc(0x10000);
if (!buffer)
{
fprintf(stderr, "ERROR - Unable to allocate memory.\n");
return 0;
}
/* copy SRAM data */
memcpy(buffer, sram.sram, 0x10000);
filesize = 0x10000;
/* update CRC */
sram.crc = crc32(0, sram.sram, 0x10000);
}
/* Device Type */
{
/* FAT filename */
if (slot > 0)
{
sprintf(filename, "%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1);
}
else
{
sprintf(filename, "%s/saves/%s.srm", DEFAULT_PATH, rom_filename);
}
/* Open file */
fp = fopen(filename, "wb");
if (!fp)
{
fprintf(stderr, "ERROR - Unable to open file.\n");
free(buffer);
return 0;
}
/* Write from buffer (2k blocks) */
while (filesize > CHUNKSIZE)
{
fwrite(buffer + done, CHUNKSIZE, 1, fp);
done += CHUNKSIZE;
filesize -= CHUNKSIZE;
}
/* Write remaining bytes */
fwrite(buffer + done, filesize, 1, fp);
done += filesize;
/* Close file */
fclose(fp);
free(buffer);
}
return 1;
}
static void slot_autoload(int slot)
{
FILE *fp;
/* Mega CD backup RAM specific */
if (!slot && (system_hw == SYSTEM_MCD))
{
/* automatically load internal backup RAM */ /* automatically load internal backup RAM */
unsigned i = ((region_code ^ 0x40) >> 6) - 1; switch (region_code)
const char *path = NULL;
switch(i)
{ {
case 0: case REGION_JAPAN_NTSC:
path = CD_BRAM_JP; fp = fopen(CD_BRAM_JP, "rb");
break; break;
case 1: case REGION_EUROPE:
path = CD_BRAM_EU; fp = fopen(CD_BRAM_EU, "rb");
break; break;
case 2: case REGION_USA:
path = CD_BRAM_US; fp = fopen(CD_BRAM_US, "rb");
break; break;
default: default:
return; return;
} }
fp = fopen(path, "rb");
if (fp != NULL) if (fp != NULL)
{ {
fread(scd.bram, 0x2000, 1, fp); fread(scd.bram, 0x2000, 1, fp);
@ -609,46 +381,32 @@ static void slot_autoload(int slot)
memcpy(scd.cartridge.area + scd.cartridge.mask + 1 - 0x40, brm_format, 0x40); memcpy(scd.cartridge.area + scd.cartridge.mask + 1 - 0x40, brm_format, 0x40);
} }
} }
return;
}
if (strlen(rom_filename))
{
slot_load(slot);
}
} }
static void slot_autosave(int slot) static void bram_save(void)
{ {
FILE *fp; FILE *fp;
/* Mega CD backup RAM specific */
if (!slot && (system_hw == SYSTEM_MCD))
{
/* verify that internal backup RAM has been modified */ /* verify that internal backup RAM has been modified */
if (crc32(0, scd.bram, 0x2000) != brm_crc[0]) if (crc32(0, scd.bram, 0x2000) != brm_crc[0])
{ {
/* check if it is correctly formatted before saving */ /* check if it is correctly formatted before saving */
if (!memcmp(scd.bram + 0x2000 - 0x20, brm_format + 0x20, 0x20)) if (!memcmp(scd.bram + 0x2000 - 0x20, brm_format + 0x20, 0x20))
{ {
unsigned i = ((region_code ^ 0x40) >> 6) - 1; switch (region_code)
const char *path = NULL;
switch(i)
{ {
case 0: case REGION_JAPAN_NTSC:
path = CD_BRAM_JP; fp = fopen(CD_BRAM_JP, "wb");
break; break;
case 1: case REGION_EUROPE:
path = CD_BRAM_EU; fp = fopen(CD_BRAM_EU, "wb");
break; break;
case 2: case REGION_USA:
path = CD_BRAM_US; fp = fopen(CD_BRAM_US, "wb");
break; break;
default: default:
return; return;
} }
fp = fopen(path, "wb");
if (fp != NULL) if (fp != NULL)
{ {
fwrite(scd.bram, 0x2000, 1, fp); fwrite(scd.bram, 0x2000, 1, fp);
@ -666,7 +424,7 @@ static void slot_autosave(int slot)
/* check if it is correctly formatted before saving */ /* check if it is correctly formatted before saving */
if (!memcmp(scd.cartridge.area + scd.cartridge.mask + 1 - 0x20, brm_format + 0x20, 0x20)) if (!memcmp(scd.cartridge.area + scd.cartridge.mask + 1 - 0x20, brm_format + 0x20, 0x20))
{ {
FILE *fp = fopen(CART_BRAM, "wb"); fp = fopen(CART_BRAM, "wb");
if (fp != NULL) if (fp != NULL)
{ {
int filesize = scd.cartridge.mask + 1; int filesize = scd.cartridge.mask + 1;
@ -694,12 +452,6 @@ static void slot_autosave(int slot)
} }
} }
} }
return;
}
if (strlen(rom_filename))
slot_save(slot);
} }
/************************************ /************************************
@ -948,39 +700,22 @@ bool retro_load_game(const struct retro_game_info *info)
slash = '/'; slash = '/';
#endif #endif
snprintf(CD_BRAM_EU, sizeof(CD_BRAM_EU), "%s%cscd_E.brm", dir, slash);
snprintf(CD_BRAM_US, sizeof(CD_BRAM_US), "%s%cscd_U.brm", dir, slash);
snprintf(CD_BRAM_JP, sizeof(CD_BRAM_JP), "%s%cscd_J.brm", dir, slash);
snprintf(CD_BIOS_EU, sizeof(CD_BIOS_EU), "%s%cbios_CD_E.bin", dir, slash); snprintf(CD_BIOS_EU, sizeof(CD_BIOS_EU), "%s%cbios_CD_E.bin", dir, slash);
snprintf(CD_BIOS_US, sizeof(CD_BIOS_US), "%s%cbios_CD_U.bin", dir, slash); snprintf(CD_BIOS_US, sizeof(CD_BIOS_US), "%s%cbios_CD_U.bin", dir, slash);
snprintf(CD_BIOS_JP, sizeof(CD_BIOS_JP), "%s%cbios_CD_J.bin", dir, slash); snprintf(CD_BIOS_JP, sizeof(CD_BIOS_JP), "%s%cbios_CD_J.bin", dir, slash);
snprintf(MS_BIOS_EU, sizeof(MS_BIOS_EU), "%s%cbios_E.sms", dir, slash); snprintf(CD_BRAM_EU, sizeof(CD_BRAM_EU), "%s%cscd_E.brm", dir, slash);
snprintf(MS_BIOS_US, sizeof(MS_BIOS_US), "%s%cbios_U.sms", dir, slash); snprintf(CD_BRAM_US, sizeof(CD_BRAM_US), "%s%cscd_U.brm", dir, slash);
snprintf(MS_BIOS_JP, sizeof(MS_BIOS_JP), "%s%cbios_J.sms", dir, slash); snprintf(CD_BRAM_JP, sizeof(CD_BRAM_JP), "%s%cscd_J.brm", dir, slash);
snprintf(GG_BIOS, sizeof(GG_BIOS), "%s%cbios.gg", dir, slash); snprintf(CART_BRAM, sizeof(CART_BRAM), "%s%ccart.brm", dir, slash);
snprintf(SK_ROM, sizeof(SK_ROM), "%s%csk.bin", dir, slash);
snprintf(SK_UPMEM, sizeof(SK_UPMEM), "%s%csk2chip.bin", dir, slash);
snprintf(GG_ROM, sizeof(GG_ROM), "%s%cggenie.bin", dir, slash);
snprintf(AR_ROM, sizeof(AR_ROM), "%s%careplay.bin", dir, slash);
fprintf(stderr, "Sega CD EU BRAM should be located at: %s\n", CD_BRAM_EU);
fprintf(stderr, "Sega CD US BRAM should be located at: %s\n", CD_BRAM_US);
fprintf(stderr, "Sega CD JP BRAM should be located at: %s\n", CD_BRAM_JP);
fprintf(stderr, "Sega CD EU BIOS should be located at: %s\n", CD_BIOS_EU); fprintf(stderr, "Sega CD EU BIOS should be located at: %s\n", CD_BIOS_EU);
fprintf(stderr, "Sega CD US BIOS should be located at: %s\n", CD_BIOS_US); fprintf(stderr, "Sega CD US BIOS should be located at: %s\n", CD_BIOS_US);
fprintf(stderr, "Sega CD JP BIOS should be located at: %s\n", CD_BIOS_JP); fprintf(stderr, "Sega CD JP BIOS should be located at: %s\n", CD_BIOS_JP);
fprintf(stderr, "Master System EU BIOS should be located at: %s\n", MS_BIOS_EU); fprintf(stderr, "Sega CD EU BRAM is located at: %s\n", CD_BRAM_EU);
fprintf(stderr, "Master System US BIOS should be located at: %s\n", MS_BIOS_US); fprintf(stderr, "Sega CD US BRAM is located at: %s\n", CD_BRAM_US);
fprintf(stderr, "Master System JP BIOS should be located at: %s\n", MS_BIOS_JP); fprintf(stderr, "Sega CD JP BRAM is located at: %s\n", CD_BRAM_JP);
fprintf(stderr, "Game Gear BIOS should be located at: %s\n", GG_BIOS); fprintf(stderr, "Sega CD RAM CART is located at: %s\n", CART_BRAM);
fprintf(stderr, "S&K upmem ROM should be located at: %s\n", SK_UPMEM);
fprintf(stderr, "S&K ROM should be located at: %s\n", SK_ROM);
fprintf(stderr, "Game Genie ROM should be located at: %s\n", GG_ROM);
fprintf(stderr, "Action Replay ROM should be located at: %s\n", AR_ROM);
snprintf(DEFAULT_PATH, sizeof(DEFAULT_PATH), g_rom_dir); snprintf(DEFAULT_PATH, sizeof(DEFAULT_PATH), g_rom_dir);
snprintf(CART_BRAM, sizeof(CART_BRAM), "%s%ccart.brm", g_rom_dir, slash);
fprintf(stderr, "BRAM file is located at: %s\n", CART_BRAM);
config_default(); config_default();
init_bitmap(); init_bitmap();
@ -998,7 +733,7 @@ bool retro_load_game(const struct retro_game_info *info)
system_reset(); system_reset();
if (system_hw == SYSTEM_MCD) if (system_hw == SYSTEM_MCD)
slot_autoload(0); bram_load();
retro_set_viewport_dimensions(); retro_set_viewport_dimensions();
@ -1018,7 +753,7 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i
void retro_unload_game(void) void retro_unload_game(void)
{ {
if (system_hw == SYSTEM_MCD) if (system_hw == SYSTEM_MCD)
slot_autosave(0); bram_save();
} }
unsigned retro_get_region(void) { return vdp_pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC; } unsigned retro_get_region(void) { return vdp_pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC; }

View File

@ -42,6 +42,7 @@ typedef struct
uint8 psgBoostNoise; uint8 psgBoostNoise;
uint8 dac_bits; uint8 dac_bits;
uint8 ym2413; uint8 ym2413;
uint8 mono;
int16 psg_preamp; int16 psg_preamp;
int16 fm_preamp; int16 fm_preamp;
int16 lp_range; int16 lp_range;
@ -50,44 +51,20 @@ typedef struct
int16 lg; int16 lg;
int16 mg; int16 mg;
int16 hg; int16 hg;
float rolloff;
uint8 system; uint8 system;
uint8 region_detect; uint8 region_detect;
uint8 master_clock; uint8 master_clock;
uint8 vdp_mode; uint8 vdp_mode;
uint8 force_dtack; uint8 force_dtack;
uint8 addr_error; uint8 addr_error;
uint8 tmss;
uint8 bios; uint8 bios;
uint8 lock_on; uint8 lock_on;
uint8 hot_swap; uint8 hot_swap;
uint8 invert_mouse;
uint8 gun_cursor[2];
uint8 overscan; uint8 overscan;
uint8 ntsc; uint8 ntsc;
uint8 vsync;
uint8 render;
uint8 tv_mode;
uint8 bilinear;
uint8 aspect;
int16 xshift;
int16 yshift;
int16 xscale;
int16 yscale;
t_input_config input[MAX_INPUTS];
uint16 pad_keymap[4][MAX_KEYS];
uint8 autoload;
uint8 autocheat;
uint8 s_auto;
uint8 s_default;
uint8 s_device;
uint8 l_device;
uint8 bg_overlay;
int16 screen_w;
float bgm_volume;
float sfx_volume;
char lastdir[4][2][MAXPATHLEN];
uint8 gg_extra; uint8 gg_extra;
uint8 render;
t_input_config input[MAX_INPUTS];
} t_config; } t_config;
/* Global data */ /* Global data */