2012-07-09 23:14:35 +02:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
#include <stddef.h>
|
2012-07-10 19:15:26 +02:00
|
|
|
#include <stdarg.h>
|
2012-07-09 23:14:35 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
2012-08-15 19:45:17 +02:00
|
|
|
#ifdef _XBOX1
|
|
|
|
#include <xtl.h>
|
|
|
|
#endif
|
|
|
|
|
2014-07-20 23:07:58 +02:00
|
|
|
#define RETRO_DEVICE_MDPAD_3B RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0)
|
|
|
|
#define RETRO_DEVICE_MDPAD_6B RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
|
|
|
|
#define RETRO_DEVICE_MSPAD_2B RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 2)
|
|
|
|
#define RETRO_DEVICE_MDPAD_3B_WAYPLAY RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 3)
|
|
|
|
#define RETRO_DEVICE_MDPAD_6B_WAYPLAY RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 4)
|
|
|
|
#define RETRO_DEVICE_MDPAD_3B_TEAMPLAYER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 5)
|
|
|
|
#define RETRO_DEVICE_MDPAD_6B_TEAMPLAYER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 6)
|
|
|
|
#define RETRO_DEVICE_MSPAD_2B_MASTERTAP RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 7)
|
2014-08-09 19:14:31 +02:00
|
|
|
#define RETRO_DEVICE_PADDLE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 0)
|
|
|
|
#define RETRO_DEVICE_SPORTSPAD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1)
|
|
|
|
#define RETRO_DEVICE_XE_1AP RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 2)
|
|
|
|
#define RETRO_DEVICE_PHASER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 0)
|
|
|
|
#define RETRO_DEVICE_MENACER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 1)
|
|
|
|
#define RETRO_DEVICE_JUSTIFIERS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 2)
|
2014-10-10 18:06:16 +02:00
|
|
|
#define RETRO_DEVICE_GRAPHIC_BOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_POINTER, 0)
|
2014-05-02 03:13:37 +02:00
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
#include "shared.h"
|
|
|
|
#include "libretro.h"
|
|
|
|
#include "md_ntsc.h"
|
|
|
|
#include "sms_ntsc.h"
|
|
|
|
|
|
|
|
sms_ntsc_t *sms_ntsc;
|
|
|
|
md_ntsc_t *md_ntsc;
|
|
|
|
|
|
|
|
char GG_ROM[256];
|
|
|
|
char AR_ROM[256];
|
|
|
|
char SK_ROM[256];
|
|
|
|
char SK_UPMEM[256];
|
|
|
|
char GG_BIOS[256];
|
|
|
|
char MS_BIOS_EU[256];
|
|
|
|
char MS_BIOS_JP[256];
|
|
|
|
char MS_BIOS_US[256];
|
|
|
|
char CD_BIOS_EU[256];
|
|
|
|
char CD_BIOS_US[256];
|
|
|
|
char CD_BIOS_JP[256];
|
|
|
|
char CD_BRAM_JP[256];
|
|
|
|
char CD_BRAM_US[256];
|
|
|
|
char CD_BRAM_EU[256];
|
|
|
|
char CART_BRAM[256];
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
static int vwidth;
|
|
|
|
static int vheight;
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
static uint32_t brm_crc[2];
|
|
|
|
static uint8_t brm_format[0x40] =
|
|
|
|
{
|
|
|
|
0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x00,0x00,0x00,0x00,0x40,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x53,0x45,0x47,0x41,0x5f,0x43,0x44,0x5f,0x52,0x4f,0x4d,0x00,0x01,0x00,0x00,0x00,
|
|
|
|
0x52,0x41,0x4d,0x5f,0x43,0x41,0x52,0x54,0x52,0x49,0x44,0x47,0x45,0x5f,0x5f,0x5f
|
|
|
|
};
|
|
|
|
|
2014-11-29 20:09:43 +01:00
|
|
|
static bool is_running = 0;
|
2013-11-27 23:09:54 +01:00
|
|
|
static uint8_t temp[0x10000];
|
|
|
|
static int16 soundbuffer[3068];
|
2014-03-02 17:51:00 +01:00
|
|
|
static uint16_t bitmap_data_[720 * 576];
|
2013-11-27 23:09:54 +01:00
|
|
|
static const double pal_fps = 53203424.0 / (3420.0 * 313.0);
|
|
|
|
static const double ntsc_fps = 53693175.0 / (3420.0 * 262.0);
|
|
|
|
|
|
|
|
static char g_rom_dir[1024];
|
|
|
|
|
2013-12-16 12:28:19 +01:00
|
|
|
static retro_log_printf_t log_cb;
|
2013-11-27 23:09:54 +01:00
|
|
|
static retro_video_refresh_t video_cb;
|
|
|
|
static retro_input_poll_t input_poll_cb;
|
|
|
|
static retro_input_state_t input_state_cb;
|
|
|
|
static retro_environment_t environ_cb;
|
|
|
|
static retro_audio_sample_batch_t audio_cb;
|
|
|
|
|
2014-12-06 16:27:19 +01:00
|
|
|
/* Cheat Support */
|
|
|
|
#define MAX_CHEATS (150)
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2014-12-07 19:25:38 +01:00
|
|
|
bool enable;
|
2014-12-06 16:27:19 +01:00
|
|
|
uint16_t data;
|
|
|
|
uint16_t old;
|
|
|
|
uint32_t address;
|
|
|
|
uint8_t *prev;
|
|
|
|
} CHEATENTRY;
|
|
|
|
|
|
|
|
static int maxcheats = 0;
|
|
|
|
static int maxROMcheats = 0;
|
|
|
|
static int maxRAMcheats = 0;
|
|
|
|
|
|
|
|
static CHEATENTRY cheatlist[MAX_CHEATS];
|
|
|
|
static uint8_t cheatIndexes[MAX_CHEATS];
|
|
|
|
|
|
|
|
static char ggvalidchars[] = "ABCDEFGHJKLMNPRSTVWXYZ0123456789";
|
|
|
|
|
|
|
|
static char arvalidchars[] = "0123456789ABCDEF";
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
/************************************
|
2013-11-27 23:09:54 +01:00
|
|
|
* Genesis Plus GX implementation
|
2012-07-09 23:14:35 +02:00
|
|
|
************************************/
|
2014-04-29 23:49:47 +02:00
|
|
|
#undef CHUNKSIZE
|
2012-07-09 23:14:35 +02:00
|
|
|
#define CHUNKSIZE (0x10000)
|
|
|
|
|
2014-03-05 03:26:01 +01:00
|
|
|
void error(char * fmt, ...)
|
2012-07-10 19:15:26 +02:00
|
|
|
{
|
2014-03-05 03:26:01 +01:00
|
|
|
char buffer[256];
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
2014-03-05 03:26:01 +01:00
|
|
|
log_cb(RETRO_LOG_ERROR, "%s\n", buffer);
|
|
|
|
va_end(ap);
|
2012-07-10 19:15:26 +02:00
|
|
|
}
|
|
|
|
|
2012-07-26 13:53:24 +02:00
|
|
|
int load_archive(char *filename, unsigned char *buffer, int maxsize, char *extension)
|
2012-07-09 23:14:35 +02:00
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
int size, left;
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
/* Open file */
|
|
|
|
FILE *fd = fopen(filename, "rb");
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
if (!fd)
|
2012-07-26 13:53:24 +02:00
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
/* Master System & Game Gear BIOS are optional files */
|
|
|
|
if (!strcmp(filename,MS_BIOS_US) || !strcmp(filename,MS_BIOS_EU) || !strcmp(filename,MS_BIOS_JP) || !strcmp(filename,GG_BIOS))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-26 13:53:24 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/* Mega CD BIOS are required files */
|
|
|
|
if (!strcmp(filename,CD_BIOS_US) || !strcmp(filename,CD_BIOS_EU) || !strcmp(filename,CD_BIOS_JP))
|
|
|
|
{
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_ERROR, "Unable to open CD BIOS: %s.\n", filename);
|
2014-07-20 23:07:58 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_ERROR, "Unable to open file.\n");
|
2012-07-09 23:14:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/* Get file size */
|
|
|
|
fseek(fd, 0, SEEK_END);
|
|
|
|
size = ftell(fd);
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/* size limit */
|
|
|
|
if(size > maxsize)
|
2012-07-09 23:14:35 +02:00
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
fclose(fd);
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_ERROR, "File is too large.\n");
|
2013-11-27 23:09:54 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_INFO, "INFORMATION - Loading %d bytes ...\n", size);
|
2012-07-26 13:53:24 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/* filename extension */
|
|
|
|
if (extension)
|
|
|
|
{
|
|
|
|
memcpy(extension, &filename[strlen(filename) - 3], 3);
|
|
|
|
extension[3] = 0;
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/* Read into buffer */
|
|
|
|
left = size;
|
|
|
|
fseek(fd, 0, SEEK_SET);
|
|
|
|
while (left > CHUNKSIZE)
|
|
|
|
{
|
|
|
|
fread(buffer, CHUNKSIZE, 1, fd);
|
|
|
|
buffer += CHUNKSIZE;
|
|
|
|
left -= CHUNKSIZE;
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/* Read remaining bytes */
|
|
|
|
fread(buffer, left, 1, fd);
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
/* Close file */
|
|
|
|
fclose(fd);
|
|
|
|
|
|
|
|
/* Return loaded ROM size */
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2014-12-07 19:25:38 +01:00
|
|
|
static void RAMCheatUpdate(void);
|
2014-12-06 16:27:19 +01:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
void osd_input_update(void)
|
|
|
|
{
|
2014-08-09 19:14:31 +02:00
|
|
|
int i, player = 0;
|
2013-11-27 23:09:54 +01:00
|
|
|
unsigned int temp;
|
|
|
|
|
|
|
|
input_poll_cb();
|
|
|
|
|
2014-12-06 16:27:19 +01:00
|
|
|
/* Update RAM patches */
|
|
|
|
RAMCheatUpdate();
|
|
|
|
|
2014-07-20 23:07:58 +02:00
|
|
|
for (i = 0; i < MAX_INPUTS; i++)
|
2013-11-27 23:09:54 +01:00
|
|
|
{
|
|
|
|
temp = 0;
|
|
|
|
switch (input.dev[i])
|
|
|
|
{
|
|
|
|
case DEVICE_PAD6B:
|
|
|
|
{
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_X;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_Y;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_Z;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_PAD3B:
|
|
|
|
{
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_A;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_PAD2B:
|
|
|
|
{
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_B;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_C;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_START;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_UP;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_DOWN;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_LEFT;
|
2014-08-09 19:14:31 +02:00
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
2013-11-27 23:09:54 +01:00
|
|
|
temp |= INPUT_RIGHT;
|
|
|
|
|
2014-08-09 19:14:31 +02:00
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_MOUSE:
|
|
|
|
{
|
|
|
|
input.analog[i][0] = input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
|
2014-08-17 18:37:52 +02:00
|
|
|
if (config.invert_mouse)
|
|
|
|
input.analog[i][1] = input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
|
|
|
|
else
|
|
|
|
input.analog[i][1] = -input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input.analog[i][0] < -255)
|
|
|
|
input.analog[i][0] = -255;
|
|
|
|
else if (input.analog[i][0] > 255)
|
|
|
|
input.analog[i][0] = 255;
|
|
|
|
if (input.analog[i][1] < -255)
|
|
|
|
input.analog[i][1] = -255;
|
|
|
|
else if (input.analog[i][1] > 255)
|
|
|
|
input.analog[i][1] = 255;
|
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT))
|
|
|
|
temp |= INPUT_MOUSE_LEFT;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT))
|
|
|
|
temp |= INPUT_MOUSE_RIGHT;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN))
|
|
|
|
temp |= INPUT_MOUSE_CENTER;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE))
|
|
|
|
temp |= INPUT_START;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_LIGHTGUN:
|
|
|
|
{
|
2014-08-17 13:16:45 +02:00
|
|
|
input.analog[i][0] = ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X) + 0x7fff) * bitmap.viewport.w) / 0xfffe;
|
|
|
|
input.analog[i][1] = ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y) + 0x7fff) * bitmap.viewport.h) / 0xfffe;
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER))
|
|
|
|
temp |= INPUT_A;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TURBO))
|
|
|
|
temp |= INPUT_B;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_PAUSE))
|
|
|
|
temp |= INPUT_C;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START))
|
|
|
|
temp |= INPUT_START;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_PADDLE:
|
|
|
|
{
|
2014-08-17 17:22:15 +02:00
|
|
|
input.analog[i][0] = (input_state_cb(player, RETRO_DEVICE_ANALOG, 0, RETRO_DEVICE_ID_ANALOG_X) + 0x8000) >> 8;
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B))
|
|
|
|
temp |= INPUT_BUTTON1;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START))
|
|
|
|
temp |= INPUT_START;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_SPORTSPAD:
|
|
|
|
{
|
2014-08-17 17:22:15 +02:00
|
|
|
input.analog[i][0] = (input_state_cb(player, RETRO_DEVICE_ANALOG, 0, RETRO_DEVICE_ID_ANALOG_X) + 0x8000) >> 8;
|
|
|
|
input.analog[i][1] = (input_state_cb(player, RETRO_DEVICE_ANALOG, 0, RETRO_DEVICE_ID_ANALOG_Y) + 0x8000) >> 8;
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B))
|
|
|
|
temp |= INPUT_BUTTON1;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A))
|
|
|
|
temp |= INPUT_BUTTON2;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START))
|
|
|
|
temp |= INPUT_START;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_PICO:
|
|
|
|
{
|
2014-08-17 13:16:45 +02:00
|
|
|
input.analog[i][0] = 0x03c + ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X) + 0x7fff) * (0x17c-0x03c)) / 0xfffe;
|
|
|
|
input.analog[i][1] = 0x1fc + ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y) + 0x7fff) * (0x2f7-0x1fc)) / 0xfffe;
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT))
|
|
|
|
temp |= INPUT_PICO_PEN;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT))
|
|
|
|
temp |= INPUT_PICO_RED;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP))
|
|
|
|
pico_current = (pico_current - 1) & 7;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN))
|
|
|
|
pico_current = (pico_current + 1) & 7;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
|
|
|
|
temp |= INPUT_UP;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))
|
|
|
|
temp |= INPUT_DOWN;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))
|
|
|
|
temp |= INPUT_LEFT;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
|
|
|
temp |= INPUT_RIGHT;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DEVICE_TEREBI:
|
|
|
|
{
|
2014-08-17 13:16:45 +02:00
|
|
|
input.analog[i][0] = ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X) + 0x7fff) * 250) / 0xfffe;
|
|
|
|
input.analog[i][1] = ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y) + 0x7fff) * 250) / 0xfffe;
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT))
|
|
|
|
temp |= INPUT_BUTTON1;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE))
|
|
|
|
temp |= INPUT_START;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-10 18:06:16 +02:00
|
|
|
case DEVICE_GRAPHIC_BOARD:
|
|
|
|
{
|
|
|
|
input.analog[i][0] = ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X) + 0x7fff) * 255) / 0xfffe;
|
|
|
|
input.analog[i][1] = ((input_state_cb(player, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y) + 0x7fff) * 255) / 0xfffe;
|
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT))
|
|
|
|
temp |= INPUT_GRAPHIC_PEN;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE))
|
|
|
|
temp |= INPUT_GRAPHIC_DO;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT))
|
|
|
|
temp |= INPUT_GRAPHIC_MENU;
|
|
|
|
|
|
|
|
player++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-09 19:14:31 +02:00
|
|
|
case DEVICE_XE_1AP:
|
|
|
|
{
|
2014-08-17 17:22:15 +02:00
|
|
|
int rx = input.analog[i][0] = input_state_cb(player, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X);
|
|
|
|
int ry = input.analog[i][1] = input_state_cb(player, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y);
|
|
|
|
if (abs(rx) > abs(ry))
|
|
|
|
{
|
|
|
|
input.analog[i+1][0] = (rx + 0x8000) >> 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input.analog[i+1][0] = (0x7fff - ry) >> 8;
|
|
|
|
}
|
|
|
|
input.analog[i][0] = (input_state_cb(player, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) + 0x8000) >> 8;
|
|
|
|
input.analog[i][1] = (input_state_cb(player, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) + 0x8000) >> 8;
|
2014-08-09 19:14:31 +02:00
|
|
|
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R))
|
|
|
|
temp |= INPUT_XE_A;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2))
|
|
|
|
temp |= INPUT_XE_B;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L))
|
|
|
|
temp |= INPUT_XE_C;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2))
|
|
|
|
temp |= INPUT_XE_D;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y))
|
|
|
|
temp |= INPUT_XE_E1;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B))
|
|
|
|
temp |= INPUT_XE_E2;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT))
|
|
|
|
temp |= INPUT_XE_SELECT;
|
|
|
|
if (input_state_cb(player, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START))
|
|
|
|
temp |= INPUT_XE_START;
|
|
|
|
|
|
|
|
player++;
|
2013-11-27 23:09:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
input.pad[i] = temp;
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2015-04-26 18:28:24 +02:00
|
|
|
static void draw_cursor(int16_t x, int16_t y, uint16_t color)
|
|
|
|
{
|
|
|
|
uint16_t *ptr = (uint16_t *)bitmap.data + ((bitmap.viewport.y + y) * bitmap.width) + x + bitmap.viewport.x;
|
|
|
|
ptr[-3*bitmap.width] = ptr[-bitmap.width] = ptr[bitmap.width] = ptr[3*bitmap.width] = ptr[-3] = ptr[-1] = ptr[1] = ptr[3] = color;
|
|
|
|
ptr[-2*bitmap.width] = ptr[2*bitmap.width] = ptr[-2] = ptr[2] = ptr[0] = 0xffff;
|
|
|
|
}
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
static void init_bitmap(void)
|
|
|
|
{
|
|
|
|
memset(&bitmap, 0, sizeof(bitmap));
|
2014-03-02 17:51:00 +01:00
|
|
|
bitmap.width = 720;
|
|
|
|
bitmap.height = 576;
|
|
|
|
bitmap.pitch = 720 * 2;
|
2012-07-09 23:14:35 +02:00
|
|
|
bitmap.data = (uint8_t *)bitmap_data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void config_default(void)
|
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
int i;
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
/* sound options */
|
|
|
|
config.psg_preamp = 150;
|
|
|
|
config.fm_preamp = 100;
|
2013-11-27 23:09:54 +01:00
|
|
|
config.hq_fm = 1; /* high-quality resampling */
|
2012-10-14 19:16:31 +02:00
|
|
|
config.psgBoostNoise = 1;
|
2013-11-27 23:09:54 +01:00
|
|
|
config.filter = 0; /* no filter */
|
2013-06-17 02:08:00 +02:00
|
|
|
config.lp_range = 0x9999; /* 0.6 in 16.16 fixed point */
|
2012-07-09 23:14:35 +02:00
|
|
|
config.low_freq = 880;
|
|
|
|
config.high_freq = 5000;
|
|
|
|
config.lg = 1.0;
|
|
|
|
config.mg = 1.0;
|
|
|
|
config.hg = 1.0;
|
2013-11-27 23:09:54 +01:00
|
|
|
config.dac_bits = 14; /* MAX DEPTH */
|
2012-07-09 23:14:35 +02:00
|
|
|
config.ym2413 = 2; /* AUTO */
|
2013-11-27 23:09:54 +01:00
|
|
|
config.mono = 0; /* STEREO output */
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
/* system options */
|
|
|
|
config.system = 0; /* AUTO */
|
|
|
|
config.region_detect = 0; /* AUTO */
|
|
|
|
config.vdp_mode = 0; /* AUTO */
|
|
|
|
config.master_clock = 0; /* AUTO */
|
|
|
|
config.force_dtack = 0;
|
|
|
|
config.addr_error = 1;
|
|
|
|
config.bios = 0;
|
|
|
|
config.lock_on = 0;
|
2014-11-26 14:32:32 +01:00
|
|
|
config.lcd = 0; /* 0.8 fixed point */
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
/* video options */
|
2013-11-27 23:09:54 +01:00
|
|
|
config.overscan = 0;
|
|
|
|
config.gg_extra = 0;
|
2013-04-08 00:28:25 +02:00
|
|
|
config.ntsc = 0;
|
2014-11-26 23:14:56 +01:00
|
|
|
config.lcd = 0;
|
2012-07-09 23:14:35 +02:00
|
|
|
config.render = 0;
|
2014-07-20 23:07:58 +02:00
|
|
|
|
|
|
|
/* input options */
|
|
|
|
input.system[0] = SYSTEM_GAMEPAD;
|
|
|
|
input.system[1] = SYSTEM_GAMEPAD;
|
|
|
|
for (i=0; i<MAX_INPUTS; i++)
|
|
|
|
{
|
|
|
|
config.input[i].padtype = DEVICE_PAD2B | DEVICE_PAD3B | DEVICE_PAD6B;
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
2013-06-17 02:08:00 +02:00
|
|
|
static void bram_load(void)
|
2012-07-09 23:14:35 +02:00
|
|
|
{
|
2013-06-17 02:08:00 +02:00
|
|
|
FILE *fp;
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
/* automatically load internal backup RAM */
|
2013-06-17 02:08:00 +02:00
|
|
|
switch (region_code)
|
2012-07-09 23:14:35 +02:00
|
|
|
{
|
2013-06-17 02:08:00 +02:00
|
|
|
case REGION_JAPAN_NTSC:
|
|
|
|
fp = fopen(CD_BRAM_JP, "rb");
|
2012-07-09 23:14:35 +02:00
|
|
|
break;
|
2013-06-17 02:08:00 +02:00
|
|
|
case REGION_EUROPE:
|
|
|
|
fp = fopen(CD_BRAM_EU, "rb");
|
2012-07-09 23:14:35 +02:00
|
|
|
break;
|
2013-06-17 02:08:00 +02:00
|
|
|
case REGION_USA:
|
|
|
|
fp = fopen(CD_BRAM_US, "rb");
|
2012-07-09 23:14:35 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fread(scd.bram, 0x2000, 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* update CRC */
|
|
|
|
brm_crc[0] = crc32(0, scd.bram, 0x2000);
|
|
|
|
}
|
2012-07-26 13:53:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* force internal backup RAM format (does not use previous region backup RAM) */
|
|
|
|
scd.bram[0x1fff] = 0;
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
/* check if internal backup RAM is correctly formatted */
|
|
|
|
if (memcmp(scd.bram + 0x2000 - 0x20, brm_format + 0x20, 0x20))
|
|
|
|
{
|
|
|
|
/* clear internal backup RAM */
|
2012-07-26 13:53:24 +02:00
|
|
|
memset(scd.bram, 0x00, 0x2000 - 0x40);
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
/* internal Backup RAM size fields */
|
|
|
|
brm_format[0x10] = brm_format[0x12] = brm_format[0x14] = brm_format[0x16] = 0x00;
|
|
|
|
brm_format[0x11] = brm_format[0x13] = brm_format[0x15] = brm_format[0x17] = (sizeof(scd.bram) / 64) - 3;
|
|
|
|
|
|
|
|
/* format internal backup RAM */
|
|
|
|
memcpy(scd.bram + 0x2000 - 0x40, brm_format, 0x40);
|
2012-07-26 13:53:24 +02:00
|
|
|
|
|
|
|
/* clear CRC to force file saving (in case previous region backup RAM was also formatted) */
|
|
|
|
brm_crc[0] = 0;
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* automatically load cartridge backup RAM (if enabled) */
|
|
|
|
if (scd.cartridge.id)
|
|
|
|
{
|
|
|
|
fp = fopen(CART_BRAM, "rb");
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
2012-07-26 13:53:24 +02:00
|
|
|
int filesize = scd.cartridge.mask + 1;
|
|
|
|
int done = 0;
|
|
|
|
|
|
|
|
/* Read into buffer (2k blocks) */
|
|
|
|
while (filesize > CHUNKSIZE)
|
|
|
|
{
|
|
|
|
fread(scd.cartridge.area + done, CHUNKSIZE, 1, fp);
|
|
|
|
done += CHUNKSIZE;
|
|
|
|
filesize -= CHUNKSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read remaining bytes */
|
|
|
|
if (filesize)
|
|
|
|
{
|
|
|
|
fread(scd.cartridge.area + done, filesize, 1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close file */
|
2012-07-09 23:14:35 +02:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* update CRC */
|
|
|
|
brm_crc[1] = crc32(0, scd.cartridge.area, scd.cartridge.mask + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if cartridge backup RAM is correctly formatted */
|
|
|
|
if (memcmp(scd.cartridge.area + scd.cartridge.mask + 1 - 0x20, brm_format + 0x20, 0x20))
|
|
|
|
{
|
|
|
|
/* clear cartridge backup RAM */
|
|
|
|
memset(scd.cartridge.area, 0x00, scd.cartridge.mask + 1);
|
|
|
|
|
|
|
|
/* Cartridge Backup RAM size fields */
|
|
|
|
brm_format[0x10] = brm_format[0x12] = brm_format[0x14] = brm_format[0x16] = (((scd.cartridge.mask + 1) / 64) - 3) >> 8;
|
|
|
|
brm_format[0x11] = brm_format[0x13] = brm_format[0x15] = brm_format[0x17] = (((scd.cartridge.mask + 1) / 64) - 3) & 0xff;
|
|
|
|
|
|
|
|
/* format cartridge backup RAM */
|
|
|
|
memcpy(scd.cartridge.area + scd.cartridge.mask + 1 - 0x40, brm_format, 0x40);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 02:08:00 +02:00
|
|
|
static void bram_save(void)
|
2012-07-09 23:14:35 +02:00
|
|
|
{
|
2013-06-17 02:08:00 +02:00
|
|
|
FILE *fp;
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
/* verify that internal backup RAM has been modified */
|
|
|
|
if (crc32(0, scd.bram, 0x2000) != brm_crc[0])
|
|
|
|
{
|
|
|
|
/* check if it is correctly formatted before saving */
|
|
|
|
if (!memcmp(scd.bram + 0x2000 - 0x20, brm_format + 0x20, 0x20))
|
|
|
|
{
|
2013-06-17 02:08:00 +02:00
|
|
|
switch (region_code)
|
2013-11-27 23:09:54 +01:00
|
|
|
{
|
|
|
|
case REGION_JAPAN_NTSC:
|
|
|
|
fp = fopen(CD_BRAM_JP, "wb");
|
|
|
|
break;
|
|
|
|
case REGION_EUROPE:
|
|
|
|
fp = fopen(CD_BRAM_EU, "wb");
|
|
|
|
break;
|
|
|
|
case REGION_USA:
|
|
|
|
fp = fopen(CD_BRAM_US, "wb");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fwrite(scd.bram, 0x2000, 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* update CRC */
|
|
|
|
brm_crc[0] = crc32(0, scd.bram, 0x2000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* verify that cartridge backup RAM has been modified */
|
|
|
|
if (scd.cartridge.id && (crc32(0, scd.cartridge.area, scd.cartridge.mask + 1) != brm_crc[1]))
|
|
|
|
{
|
|
|
|
/* check if it is correctly formatted before saving */
|
|
|
|
if (!memcmp(scd.cartridge.area + scd.cartridge.mask + 1 - 0x20, brm_format + 0x20, 0x20))
|
|
|
|
{
|
2013-06-17 02:08:00 +02:00
|
|
|
fp = fopen(CART_BRAM, "wb");
|
2012-07-09 23:14:35 +02:00
|
|
|
if (fp != NULL)
|
|
|
|
{
|
2012-07-26 13:53:24 +02:00
|
|
|
int filesize = scd.cartridge.mask + 1;
|
|
|
|
int done = 0;
|
|
|
|
|
|
|
|
/* Write to file (2k blocks) */
|
|
|
|
while (filesize > CHUNKSIZE)
|
|
|
|
{
|
|
|
|
fwrite(scd.cartridge.area + done, CHUNKSIZE, 1, fp);
|
|
|
|
done += CHUNKSIZE;
|
|
|
|
filesize -= CHUNKSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write remaining bytes */
|
|
|
|
if (filesize)
|
|
|
|
{
|
|
|
|
fwrite(scd.cartridge.area + done, filesize, 1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close file */
|
2012-07-09 23:14:35 +02:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* update CRC */
|
|
|
|
brm_crc[1] = crc32(0, scd.cartridge.area, scd.cartridge.mask + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_directory(char *buf, const char *path, size_t size)
|
|
|
|
{
|
2012-07-10 01:51:14 +02:00
|
|
|
char *base;
|
2012-07-09 23:14:35 +02:00
|
|
|
strncpy(buf, path, size - 1);
|
|
|
|
buf[size - 1] = '\0';
|
|
|
|
|
2012-07-10 01:51:14 +02:00
|
|
|
base = strrchr(buf, '/');
|
2012-07-09 23:14:35 +02:00
|
|
|
if (!base)
|
|
|
|
base = strrchr(buf, '\\');
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
*base = '\0';
|
|
|
|
else
|
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2014-04-05 00:46:30 +02:00
|
|
|
static bool update_viewport(void)
|
2012-07-09 23:14:35 +02:00
|
|
|
{
|
2014-04-05 00:46:30 +02:00
|
|
|
int ow = vwidth;
|
|
|
|
int oh = vheight;
|
|
|
|
|
|
|
|
vwidth = bitmap.viewport.w + (bitmap.viewport.x * 2);
|
|
|
|
vheight = bitmap.viewport.h + (bitmap.viewport.y * 2);
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
if (config.ntsc)
|
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
if (reg[12] & 1)
|
2012-07-09 23:14:35 +02:00
|
|
|
vwidth = MD_NTSC_OUT_WIDTH(vwidth);
|
|
|
|
else
|
|
|
|
vwidth = SMS_NTSC_OUT_WIDTH(vwidth);
|
|
|
|
}
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
if (config.render && interlaced)
|
2012-10-14 17:45:00 +02:00
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
vheight = vheight * 2;
|
2012-10-14 17:45:00 +02:00
|
|
|
}
|
2014-04-05 00:46:30 +02:00
|
|
|
|
2014-07-20 23:10:29 +02:00
|
|
|
return ((ow != vwidth) || (oh != vheight));
|
2012-10-14 17:45:00 +02:00
|
|
|
}
|
|
|
|
|
2013-04-08 00:28:25 +02:00
|
|
|
static void check_variables(void)
|
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
unsigned orig_value;
|
|
|
|
bool update_viewports = false;
|
|
|
|
bool reinit = false;
|
|
|
|
struct retro_variable var = {0};
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_system_hw";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.system;
|
|
|
|
if (!strcmp(var.value, "sg-1000"))
|
|
|
|
config.system = SYSTEM_SG;
|
2014-03-02 17:51:00 +01:00
|
|
|
else if (!strcmp(var.value, "sg-1000 II"))
|
|
|
|
config.system = SYSTEM_SGII;
|
2013-11-27 23:09:54 +01:00
|
|
|
else if (!strcmp(var.value, "mark-III"))
|
|
|
|
config.system = SYSTEM_MARKIII;
|
|
|
|
else if (!strcmp(var.value, "master system"))
|
|
|
|
config.system = SYSTEM_SMS;
|
|
|
|
else if (!strcmp(var.value, "master system II"))
|
|
|
|
config.system = SYSTEM_SMS2;
|
|
|
|
else if (!strcmp(var.value, "game gear"))
|
|
|
|
config.system = SYSTEM_GG;
|
|
|
|
else if (!strcmp(var.value, "mega drive / genesis"))
|
|
|
|
config.system = SYSTEM_MD;
|
|
|
|
else
|
|
|
|
config.system = 0;
|
2013-04-08 00:28:25 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
if (orig_value != config.system)
|
|
|
|
{
|
|
|
|
if (system_hw)
|
|
|
|
{
|
|
|
|
switch (config.system)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
system_hw = romtype; /* AUTO */
|
|
|
|
break;
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
case SYSTEM_MD:
|
|
|
|
system_hw = (romtype & SYSTEM_MD) ? romtype : SYSTEM_PBC;
|
|
|
|
break;
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
case SYSTEM_GG:
|
|
|
|
system_hw = (romtype == SYSTEM_GG) ? SYSTEM_GG : SYSTEM_GGMS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
system_hw = config.system;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
reinit = true;
|
2013-04-08 00:58:24 +02:00
|
|
|
}
|
2013-11-27 23:09:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_region_detect";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.region_detect;
|
|
|
|
if (!strcmp(var.value, "ntsc-u"))
|
|
|
|
config.region_detect = 1;
|
|
|
|
else if (!strcmp(var.value, "pal"))
|
|
|
|
config.region_detect = 2;
|
|
|
|
else if (!strcmp(var.value, "ntsc-j"))
|
|
|
|
config.region_detect = 3;
|
|
|
|
else
|
|
|
|
config.region_detect = 0;
|
|
|
|
|
|
|
|
if (orig_value != config.region_detect)
|
|
|
|
{
|
|
|
|
if (system_hw)
|
2013-04-08 00:58:24 +02:00
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
get_region(NULL);
|
|
|
|
reinit = true;
|
2013-04-08 00:58:24 +02:00
|
|
|
}
|
2013-11-27 23:09:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_force_dtack";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
if (!strcmp(var.value, "enabled"))
|
|
|
|
config.force_dtack = 1;
|
|
|
|
else
|
|
|
|
config.force_dtack = 0;
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_addr_error";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
if (!strcmp(var.value, "enabled"))
|
|
|
|
m68k.aerr_enabled = config.addr_error = 1;
|
|
|
|
else
|
|
|
|
m68k.aerr_enabled = config.addr_error = 0;
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_lock_on";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.lock_on;
|
|
|
|
if (!strcmp(var.value, "game genie"))
|
|
|
|
config.lock_on = TYPE_GG;
|
|
|
|
else if (!strcmp(var.value, "action replay (pro)"))
|
|
|
|
config.lock_on = TYPE_AR;
|
|
|
|
else if (!strcmp(var.value, "sonic & knuckles"))
|
|
|
|
config.lock_on = TYPE_SK;
|
|
|
|
else
|
|
|
|
config.lock_on = 0;
|
|
|
|
|
|
|
|
if (orig_value != config.lock_on)
|
|
|
|
{
|
|
|
|
if (system_hw == SYSTEM_MD)
|
|
|
|
reinit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_ym2413";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.ym2413;
|
|
|
|
if (!strcmp(var.value, "enabled"))
|
|
|
|
config.ym2413 = 1;
|
|
|
|
else if (!strcmp(var.value, "disabled"))
|
|
|
|
config.ym2413 = 0;
|
|
|
|
else
|
|
|
|
config.ym2413 = 2;
|
|
|
|
|
|
|
|
if (orig_value != config.ym2413)
|
|
|
|
{
|
|
|
|
if (system_hw && (config.ym2413 & 2) && ((system_hw & SYSTEM_PBC) != SYSTEM_MD))
|
2013-04-08 00:58:24 +02:00
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
memcpy(temp, sram.sram, sizeof(temp));
|
|
|
|
sms_cart_init();
|
|
|
|
memcpy(sram.sram, temp, sizeof(temp));
|
2013-04-08 00:58:24 +02:00
|
|
|
}
|
2013-11-27 23:09:54 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-08 00:28:25 +02:00
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_dac_bits";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
2013-12-01 13:33:14 +01:00
|
|
|
if (!strcmp(var.value, "enabled"))
|
2013-11-27 23:09:54 +01:00
|
|
|
config.dac_bits = 9;
|
|
|
|
else
|
|
|
|
config.dac_bits = 14;
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
YM2612Config(config.dac_bits);
|
|
|
|
}
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_blargg_ntsc_filter";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.ntsc;
|
|
|
|
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
config.ntsc = 0;
|
|
|
|
else if (strcmp(var.value, "monochrome") == 0)
|
|
|
|
{
|
|
|
|
config.ntsc = 1;
|
|
|
|
sms_ntsc_init(sms_ntsc, &sms_ntsc_monochrome);
|
|
|
|
md_ntsc_init(md_ntsc, &md_ntsc_monochrome);
|
|
|
|
}
|
|
|
|
else if (strcmp(var.value, "composite") == 0)
|
|
|
|
{
|
|
|
|
config.ntsc = 1;
|
|
|
|
sms_ntsc_init(sms_ntsc, &sms_ntsc_composite);
|
|
|
|
md_ntsc_init(md_ntsc, &md_ntsc_composite);
|
|
|
|
}
|
|
|
|
else if (strcmp(var.value, "svideo") == 0)
|
|
|
|
{
|
|
|
|
config.ntsc = 1;
|
|
|
|
sms_ntsc_init(sms_ntsc, &sms_ntsc_svideo);
|
|
|
|
md_ntsc_init(md_ntsc, &md_ntsc_svideo);
|
|
|
|
}
|
|
|
|
else if (strcmp(var.value, "rgb") == 0)
|
|
|
|
{
|
|
|
|
config.ntsc = 1;
|
|
|
|
sms_ntsc_init(sms_ntsc, &sms_ntsc_rgb);
|
|
|
|
md_ntsc_init(md_ntsc, &md_ntsc_rgb);
|
|
|
|
}
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
if (orig_value != config.ntsc)
|
|
|
|
update_viewports = true;
|
|
|
|
}
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_lcd_filter";
|
2014-11-26 23:14:56 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
config.lcd = 0;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
config.lcd = (uint8)(0.80 * 256);
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_overscan";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.overscan;
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
config.overscan = 0;
|
|
|
|
else if (strcmp(var.value, "top/bottom") == 0)
|
|
|
|
config.overscan = 1;
|
|
|
|
else if (strcmp(var.value, "left/right") == 0)
|
|
|
|
config.overscan = 2;
|
|
|
|
else if (strcmp(var.value, "full") == 0)
|
|
|
|
config.overscan = 3;
|
|
|
|
if (orig_value != config.overscan)
|
|
|
|
update_viewports = true;
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_gg_extra";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.gg_extra;
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
config.gg_extra = 0;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
config.gg_extra = 1;
|
|
|
|
if (orig_value != config.gg_extra)
|
|
|
|
update_viewports = true;
|
|
|
|
}
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_render";
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
|
|
|
orig_value = config.render;
|
2015-05-07 00:37:23 +02:00
|
|
|
if (strcmp(var.value, "single field") == 0)
|
2013-11-27 23:09:54 +01:00
|
|
|
config.render = 0;
|
|
|
|
else
|
|
|
|
config.render = 1;
|
|
|
|
if (orig_value != config.render)
|
|
|
|
update_viewports = true;
|
|
|
|
}
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_gun_cursor";
|
2014-08-17 18:37:52 +02:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
2015-05-07 00:37:23 +02:00
|
|
|
if (strcmp(var.value, "no") == 0)
|
2014-08-17 18:37:52 +02:00
|
|
|
config.gun_cursor = 0;
|
|
|
|
else
|
|
|
|
config.gun_cursor = 1;
|
|
|
|
}
|
|
|
|
|
2014-12-05 23:42:06 +01:00
|
|
|
var.key = "genesis_plus_gx_invert_mouse";
|
2014-08-17 18:37:52 +02:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
|
|
|
|
{
|
2015-05-07 00:37:23 +02:00
|
|
|
if (strcmp(var.value, "no") == 0)
|
2014-08-17 18:37:52 +02:00
|
|
|
config.invert_mouse = 0;
|
|
|
|
else
|
|
|
|
config.invert_mouse = 1;
|
|
|
|
}
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
if (reinit)
|
|
|
|
{
|
|
|
|
audio_init(44100, snd.frame_rate);
|
|
|
|
memcpy(temp, sram.sram, sizeof(temp));
|
|
|
|
system_init();
|
|
|
|
system_reset();
|
|
|
|
memcpy(sram.sram, temp, sizeof(temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_viewports)
|
|
|
|
{
|
|
|
|
bitmap.viewport.changed = 3;
|
|
|
|
if ((system_hw == SYSTEM_GG) && !config.gg_extra)
|
|
|
|
bitmap.viewport.x = (config.overscan & 2) ? 14 : -48;
|
|
|
|
else
|
|
|
|
bitmap.viewport.x = (config.overscan & 2) * 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-06 16:27:19 +01:00
|
|
|
/* Cheat Support */
|
|
|
|
static uint32_t decode_cheat(char *string, int index)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int i,n;
|
|
|
|
uint32_t len = 0;
|
|
|
|
uint32_t address = 0;
|
|
|
|
uint16_t data = 0;
|
|
|
|
uint8_t ref = 0;
|
|
|
|
/* 16-bit Game Genie code (ABCD-EFGH) */
|
|
|
|
if ((strlen(string) >= 9) && (string[4] == '-'))
|
|
|
|
{
|
|
|
|
/* 16-bit system only */
|
|
|
|
if ((system_hw & SYSTEM_PBC) != SYSTEM_MD)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (i == 4) string++;
|
|
|
|
p = strchr (ggvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = p - ggvalidchars;
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
data |= n << 3;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
data |= n >> 2;
|
|
|
|
address |= (n & 3) << 14;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
address |= n << 9;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
address |= (n & 0xF) << 20 | (n >> 4) << 8;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
data |= (n & 1) << 12;
|
|
|
|
address |= (n >> 1) << 16;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
data |= (n & 1) << 15 | (n >> 1) << 8;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
data |= (n >> 3) << 13;
|
|
|
|
address |= (n & 7) << 5;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
address |= n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* code length */
|
|
|
|
len = 9;
|
|
|
|
}
|
|
|
|
/* 8-bit Game Genie code (DDA-AAA-XXX) */
|
|
|
|
else if ((strlen(string) >= 11) && (string[3] == '-') && (string[7] == '-'))
|
|
|
|
{
|
|
|
|
/* 8-bit system only */
|
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* decode 8-bit data */
|
|
|
|
for (i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
data |= (n << ((1 - i) * 4));
|
|
|
|
}
|
|
|
|
/* decode 16-bit address (low 12-bits) */
|
|
|
|
for (i=0; i<3; i++)
|
|
|
|
{
|
|
|
|
if (i==1) string++; /* skip separator */
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
address |= (n << ((2 - i) * 4));
|
|
|
|
}
|
|
|
|
/* decode 16-bit address (high 4-bits) */
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
n ^= 0xF; /* bits inversion */
|
|
|
|
address |= (n << 12);
|
|
|
|
/* RAM address are also supported */
|
|
|
|
if (address >= 0xC000)
|
|
|
|
{
|
|
|
|
/* convert to 24-bit Work RAM address */
|
|
|
|
address = 0xFF0000 | (address & 0x1FFF);
|
|
|
|
}
|
|
|
|
/* decode reference 8-bit data */
|
|
|
|
for (i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
string++; /* skip separator and 2nd digit */
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
ref |= (n << ((1 - i) * 4));
|
|
|
|
}
|
|
|
|
ref = (ref >> 2) | ((ref & 0x03) << 6); /* 2-bit right rotation */
|
|
|
|
ref ^= 0xBA; /* XOR */
|
|
|
|
/* update old data value */
|
|
|
|
cheatlist[index].old = ref;
|
|
|
|
/* code length */
|
|
|
|
len = 11;
|
|
|
|
}
|
|
|
|
/* Action Replay code */
|
|
|
|
else if (string[6] == ':')
|
|
|
|
{
|
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
|
|
|
{
|
|
|
|
/* 16-bit code (AAAAAA:DDDD) */
|
|
|
|
if (strlen(string) < 11) return 0;
|
|
|
|
/* decode 24-bit address */
|
|
|
|
for (i=0; i<6; i++)
|
|
|
|
{
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
address |= (n << ((5 - i) * 4));
|
|
|
|
}
|
|
|
|
/* decode 16-bit data */
|
|
|
|
string++;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
data |= (n << ((3 - i) * 4));
|
|
|
|
}
|
|
|
|
/* code length */
|
|
|
|
len = 11;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 8-bit code (xxAAAA:DD) */
|
|
|
|
if (strlen(string) < 9) return 0;
|
|
|
|
/* decode 16-bit address */
|
|
|
|
string+=2;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
address |= (n << ((3 - i) * 4));
|
|
|
|
}
|
|
|
|
/* ROM addresses are not supported */
|
|
|
|
if (address < 0xC000) return 0;
|
|
|
|
/* convert to 24-bit Work RAM address */
|
|
|
|
address = 0xFF0000 | (address & 0x1FFF);
|
|
|
|
/* decode 8-bit data */
|
|
|
|
string++;
|
|
|
|
for (i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
p = strchr (arvalidchars, *string++);
|
|
|
|
if (p == NULL) return 0;
|
|
|
|
n = (p - arvalidchars) & 0xF;
|
|
|
|
data |= (n << ((1 - i) * 4));
|
|
|
|
}
|
|
|
|
/* code length */
|
|
|
|
len = 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Valid code found ? */
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
/* update cheat address & data values */
|
|
|
|
cheatlist[index].address = address;
|
|
|
|
cheatlist[index].data = data;
|
|
|
|
}
|
|
|
|
/* return code length (0 = invalid) */
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void apply_cheats(void)
|
|
|
|
{
|
|
|
|
uint8_t *ptr;
|
2014-12-23 20:34:04 +01:00
|
|
|
int i;
|
2014-12-06 16:27:19 +01:00
|
|
|
/* clear ROM&RAM patches counter */
|
|
|
|
maxROMcheats = maxRAMcheats = 0;
|
2014-12-23 20:34:04 +01:00
|
|
|
|
2014-12-06 16:27:19 +01:00
|
|
|
for (i = 0; i < maxcheats; i++)
|
|
|
|
{
|
|
|
|
if (cheatlist[i].enable)
|
|
|
|
{
|
|
|
|
if (cheatlist[i].address < cart.romsize)
|
|
|
|
{
|
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
|
|
|
{
|
|
|
|
/* patch ROM data */
|
|
|
|
cheatlist[i].old = *(uint16_t *)(cart.rom + (cheatlist[i].address & 0xFFFFFE));
|
|
|
|
*(uint16_t *)(cart.rom + (cheatlist[i].address & 0xFFFFFE)) = cheatlist[i].data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* add ROM patch */
|
|
|
|
maxROMcheats++;
|
|
|
|
cheatIndexes[MAX_CHEATS - maxROMcheats] = i;
|
|
|
|
/* get current banked ROM address */
|
|
|
|
ptr = &z80_readmap[(cheatlist[i].address) >> 10][cheatlist[i].address & 0x03FF];
|
|
|
|
/* check if reference matches original ROM data */
|
|
|
|
if (((uint8_t)cheatlist[i].old) == *ptr)
|
|
|
|
{
|
|
|
|
/* patch data */
|
|
|
|
*ptr = cheatlist[i].data;
|
|
|
|
/* save patched ROM address */
|
|
|
|
cheatlist[i].prev = ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no patched ROM address yet */
|
|
|
|
cheatlist[i].prev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cheatlist[i].address >= 0xFF0000)
|
|
|
|
{
|
|
|
|
/* add RAM patch */
|
|
|
|
cheatIndexes[maxRAMcheats++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_cheats(void)
|
|
|
|
{
|
|
|
|
int i = maxcheats;
|
|
|
|
/* disable cheats in reversed order in case the same address is used by multiple patches */
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
if (cheatlist[i-1].enable)
|
|
|
|
{
|
|
|
|
if (cheatlist[i-1].address < cart.romsize)
|
|
|
|
{
|
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
|
|
|
{
|
|
|
|
/* restore original ROM data */
|
|
|
|
*(uint16_t *)(cart.rom + (cheatlist[i-1].address & 0xFFFFFE)) = cheatlist[i-1].old;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* check if previous banked ROM address has been patched */
|
|
|
|
if (cheatlist[i-1].prev != NULL)
|
|
|
|
{
|
|
|
|
/* restore original data */
|
|
|
|
*cheatlist[i-1].prev = cheatlist[i-1].old;
|
|
|
|
/* no more patched ROM address */
|
|
|
|
cheatlist[i-1].prev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* RAMCheatUpdate
|
|
|
|
*
|
|
|
|
* Apply RAM patches (this should be called once per frame)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-12-07 19:25:38 +01:00
|
|
|
static void RAMCheatUpdate(void)
|
2014-12-06 16:27:19 +01:00
|
|
|
{
|
|
|
|
int index, cnt = maxRAMcheats;
|
|
|
|
while (cnt)
|
|
|
|
{
|
|
|
|
/* get cheat index */
|
|
|
|
index = cheatIndexes[--cnt];
|
|
|
|
/* apply RAM patch */
|
2014-12-07 19:25:38 +01:00
|
|
|
if (cheatlist[index].data & 0xFF00)
|
2014-12-06 16:27:19 +01:00
|
|
|
{
|
2014-12-07 19:25:38 +01:00
|
|
|
/* 16-bit patch */
|
2014-12-06 16:27:19 +01:00
|
|
|
*(uint16_t *)(work_ram + (cheatlist[index].address & 0xFFFE)) = cheatlist[index].data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-07 19:25:38 +01:00
|
|
|
/* 8-bit patch */
|
2014-12-06 16:27:19 +01:00
|
|
|
work_ram[cheatlist[index].address & 0xFFFF] = cheatlist[index].data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-07 19:25:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* ROMCheatUpdate
|
|
|
|
*
|
|
|
|
* Apply ROM patches (this should be called each time banking is changed)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
void ROMCheatUpdate(void)
|
|
|
|
{
|
|
|
|
int index, cnt = maxROMcheats;
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
while (cnt)
|
|
|
|
{
|
|
|
|
/* get cheat index */
|
|
|
|
index = cheatIndexes[MAX_CHEATS - cnt];
|
|
|
|
|
|
|
|
/* check if previous banked ROM address was patched */
|
|
|
|
if (cheatlist[index].prev != NULL)
|
|
|
|
{
|
|
|
|
/* restore original data */
|
|
|
|
*cheatlist[index].prev = cheatlist[index].old;
|
|
|
|
|
|
|
|
/* no more patched ROM address */
|
|
|
|
cheatlist[index].prev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get current banked ROM address */
|
|
|
|
ptr = &z80_readmap[(cheatlist[index].address) >> 10][cheatlist[index].address & 0x03FF];
|
|
|
|
|
|
|
|
/* check if reference matches original ROM data */
|
|
|
|
if (((uint8_t)cheatlist[index].old) == *ptr)
|
|
|
|
{
|
|
|
|
/* patch data */
|
|
|
|
*ptr = cheatlist[index].data;
|
|
|
|
|
|
|
|
/* save patched ROM address */
|
|
|
|
cheatlist[index].prev = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next ROM patch */
|
|
|
|
cnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
/************************************
|
|
|
|
* libretro implementation
|
|
|
|
************************************/
|
|
|
|
unsigned retro_api_version(void) { return RETRO_API_VERSION; }
|
|
|
|
|
|
|
|
void retro_set_environment(retro_environment_t cb)
|
|
|
|
{
|
|
|
|
static const struct retro_variable vars[] = {
|
2014-12-05 23:42:06 +01:00
|
|
|
{ "genesis_plus_gx_system_hw", "System hardware; auto|sg-1000|sg-1000 II|mark-III|master system|master system II|game gear|mega drive / genesis" },
|
|
|
|
{ "genesis_plus_gx_region_detect", "System region; auto|ntsc-u|pal|ntsc-j" },
|
|
|
|
{ "genesis_plus_gx_force_dtack", "System lockups; enabled|disabled" },
|
|
|
|
{ "genesis_plus_gx_addr_error", "68k address error; enabled|disabled" },
|
|
|
|
{ "genesis_plus_gx_lock_on", "Cartridge lock-on; disabled|game genie|action replay (pro)|sonic & knuckles" },
|
|
|
|
{ "genesis_plus_gx_ym2413", "Master System FM; auto|disabled|enabled" },
|
|
|
|
{ "genesis_plus_gx_dac_bits", "YM2612 DAC quantization; disabled|enabled" },
|
|
|
|
{ "genesis_plus_gx_blargg_ntsc_filter", "Blargg NTSC filter; disabled|monochrome|composite|svideo|rgb" },
|
|
|
|
{ "genesis_plus_gx_lcd_filter", "LCD Ghosting filter; disabled|enabled" },
|
|
|
|
{ "genesis_plus_gx_overscan", "Borders; disabled|top/bottom|left/right|full" },
|
|
|
|
{ "genesis_plus_gx_gg_extra", "Game Gear extended screen; disabled|enabled" },
|
|
|
|
{ "genesis_plus_gx_render", "Interlaced mode 2 output; single field|double field" },
|
|
|
|
{ "genesis_plus_gx_gun_cursor", "Show Lightgun crosshair; no|yes" },
|
|
|
|
{ "genesis_plus_gx_invert_mouse", "Invert Mouse Y-axis; no|yes" },
|
2013-11-27 23:09:54 +01:00
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2014-05-02 03:13:37 +02:00
|
|
|
static const struct retro_controller_description port_1[] = {
|
2014-07-20 23:07:58 +02:00
|
|
|
{ "Joypad Auto", RETRO_DEVICE_JOYPAD },
|
|
|
|
{ "Joypad Port Empty", RETRO_DEVICE_NONE },
|
2014-05-02 03:13:37 +02:00
|
|
|
{ "MD Joypad 3 Button", RETRO_DEVICE_MDPAD_3B },
|
|
|
|
{ "MD Joypad 6 Button", RETRO_DEVICE_MDPAD_6B },
|
2014-07-20 23:07:58 +02:00
|
|
|
{ "MS Joypad 2 Button", RETRO_DEVICE_MSPAD_2B },
|
|
|
|
{ "MD Joypad 3 Button + 4-WayPlay", RETRO_DEVICE_MDPAD_3B_WAYPLAY },
|
|
|
|
{ "MD Joypad 6 Button + 4-WayPlay", RETRO_DEVICE_MDPAD_6B_WAYPLAY },
|
2014-05-02 03:13:37 +02:00
|
|
|
{ "MD Joypad 3 Button + Teamplayer", RETRO_DEVICE_MDPAD_3B_TEAMPLAYER },
|
|
|
|
{ "MD Joypad 6 Button + Teamplayer", RETRO_DEVICE_MDPAD_6B_TEAMPLAYER },
|
2014-07-20 23:07:58 +02:00
|
|
|
{ "MS Joypad 2 Button + Master Tap", RETRO_DEVICE_MSPAD_2B_MASTERTAP },
|
2014-08-09 19:14:31 +02:00
|
|
|
{ "MS Light Phaser", RETRO_DEVICE_PHASER },
|
|
|
|
{ "MS Paddle Control", RETRO_DEVICE_PADDLE },
|
|
|
|
{ "MS Sports Pad", RETRO_DEVICE_SPORTSPAD },
|
2014-10-10 18:06:16 +02:00
|
|
|
{ "MS Graphic Board", RETRO_DEVICE_GRAPHIC_BOARD },
|
2014-08-09 19:14:31 +02:00
|
|
|
{ "MD XE-1AP", RETRO_DEVICE_XE_1AP },
|
|
|
|
{ "MD Mouse", RETRO_DEVICE_MOUSE },
|
2014-05-02 03:13:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct retro_controller_description port_2[] = {
|
2014-07-20 23:07:58 +02:00
|
|
|
{ "Joypad Auto", RETRO_DEVICE_JOYPAD },
|
|
|
|
{ "Joypad Port Empty", RETRO_DEVICE_NONE },
|
2014-05-02 03:13:37 +02:00
|
|
|
{ "MD Joypad 3 Button", RETRO_DEVICE_MDPAD_3B },
|
|
|
|
{ "MD Joypad 6 Button", RETRO_DEVICE_MDPAD_6B },
|
2014-07-20 23:07:58 +02:00
|
|
|
{ "MS Joypad 2 Button", RETRO_DEVICE_MSPAD_2B },
|
|
|
|
{ "MD Joypad 3 Button + 4-WayPlay", RETRO_DEVICE_MDPAD_3B_WAYPLAY },
|
|
|
|
{ "MD Joypad 6 Button + 4-WayPlay", RETRO_DEVICE_MDPAD_6B_WAYPLAY },
|
2014-05-02 03:13:37 +02:00
|
|
|
{ "MD Joypad 3 Button + Teamplayer", RETRO_DEVICE_MDPAD_3B_TEAMPLAYER },
|
|
|
|
{ "MD Joypad 6 Button + Teamplayer", RETRO_DEVICE_MDPAD_6B_TEAMPLAYER },
|
2014-07-20 23:07:58 +02:00
|
|
|
{ "MS Joypad 2 Button + Master Tap", RETRO_DEVICE_MSPAD_2B_MASTERTAP },
|
2014-08-09 19:14:31 +02:00
|
|
|
{ "MD Menacer", RETRO_DEVICE_MENACER },
|
|
|
|
{ "MD Justifiers", RETRO_DEVICE_JUSTIFIERS },
|
|
|
|
{ "MS Light Phaser", RETRO_DEVICE_PHASER },
|
|
|
|
{ "MS Paddle Control", RETRO_DEVICE_PADDLE },
|
|
|
|
{ "MS Sports Pad", RETRO_DEVICE_SPORTSPAD },
|
2014-10-10 18:06:16 +02:00
|
|
|
{ "MS Graphic Board", RETRO_DEVICE_GRAPHIC_BOARD },
|
2014-08-09 19:14:31 +02:00
|
|
|
{ "MD XE-1AP", RETRO_DEVICE_XE_1AP },
|
|
|
|
{ "MD Mouse", RETRO_DEVICE_MOUSE },
|
|
|
|
};
|
2014-05-02 03:13:37 +02:00
|
|
|
|
|
|
|
static const struct retro_controller_info ports[] = {
|
2014-10-10 18:06:16 +02:00
|
|
|
{ port_1, 16 },
|
|
|
|
{ port_2, 18 },
|
2014-05-02 03:13:37 +02:00
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb = cb;
|
|
|
|
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
|
2014-07-20 23:07:58 +02:00
|
|
|
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
|
2013-11-27 23:09:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
|
|
|
|
void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
|
|
|
|
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_cb = cb; }
|
|
|
|
void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
|
|
|
|
void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
|
|
|
|
|
|
|
|
void retro_get_system_info(struct retro_system_info *info)
|
|
|
|
{
|
|
|
|
info->library_name = "Genesis Plus GX";
|
|
|
|
info->library_version = "v1.7.4";
|
|
|
|
info->valid_extensions = "mdx|md|smd|gen|bin|cue|iso|sms|gg|sg";
|
|
|
|
info->block_extract = false;
|
|
|
|
info->need_fullpath = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_get_system_av_info(struct retro_system_av_info *info)
|
|
|
|
{
|
|
|
|
info->geometry.base_width = vwidth;
|
|
|
|
info->geometry.base_height = vheight;
|
2014-03-02 17:51:00 +01:00
|
|
|
info->geometry.max_width = 720;
|
|
|
|
info->geometry.max_height = 576;
|
2013-11-27 23:09:54 +01:00
|
|
|
info->geometry.aspect_ratio = 4.0 / 3.0;
|
|
|
|
info->timing.fps = snd.frame_rate;
|
|
|
|
info->timing.sample_rate = 44100;
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_controller_port_device(unsigned port, unsigned device)
|
|
|
|
{
|
2014-05-02 03:13:37 +02:00
|
|
|
switch(device)
|
|
|
|
{
|
2014-07-20 23:07:58 +02:00
|
|
|
case RETRO_DEVICE_NONE:
|
|
|
|
input.system[port] = NO_SYSTEM;
|
|
|
|
break;
|
2014-05-02 03:13:37 +02:00
|
|
|
case RETRO_DEVICE_MDPAD_3B:
|
2014-07-20 23:07:58 +02:00
|
|
|
config.input[port*4].padtype = DEVICE_PAD3B;
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[port] = SYSTEM_GAMEPAD;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_MDPAD_6B:
|
2014-07-20 23:07:58 +02:00
|
|
|
config.input[port*4].padtype = DEVICE_PAD6B;
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[port] = SYSTEM_GAMEPAD;
|
|
|
|
break;
|
2014-07-20 23:07:58 +02:00
|
|
|
case RETRO_DEVICE_MSPAD_2B:
|
|
|
|
config.input[port*4].padtype = DEVICE_PAD2B;
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[port] = SYSTEM_GAMEPAD;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_MDPAD_3B_WAYPLAY:
|
2014-07-20 23:07:58 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
2014-08-09 19:14:31 +02:00
|
|
|
config.input[i].padtype = DEVICE_PAD3B;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[0] = input.system[1] = SYSTEM_WAYPLAY;
|
|
|
|
break;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
case RETRO_DEVICE_MDPAD_6B_WAYPLAY:
|
2014-07-20 23:07:58 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
2014-08-09 19:14:31 +02:00
|
|
|
config.input[i].padtype = DEVICE_PAD6B;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[0] = input.system[1] = SYSTEM_WAYPLAY;
|
|
|
|
break;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
case RETRO_DEVICE_MDPAD_3B_TEAMPLAYER:
|
2014-07-20 23:07:58 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
config.input[port*4 + i].padtype = DEVICE_PAD3B;
|
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[port] = SYSTEM_TEAMPLAYER;
|
|
|
|
break;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
case RETRO_DEVICE_MDPAD_6B_TEAMPLAYER:
|
2014-07-20 23:07:58 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
config.input[port*4 + i].padtype = DEVICE_PAD6B;
|
|
|
|
}
|
2014-05-02 03:13:37 +02:00
|
|
|
input.system[port] = SYSTEM_TEAMPLAYER;
|
|
|
|
break;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
|
|
|
case RETRO_DEVICE_MSPAD_2B_MASTERTAP:
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
config.input[port*4 + i].padtype = DEVICE_PAD2B;
|
|
|
|
}
|
|
|
|
input.system[port] = SYSTEM_MASTERTAP;
|
2014-05-02 03:13:37 +02:00
|
|
|
break;
|
2014-07-20 23:07:58 +02:00
|
|
|
}
|
2014-08-09 19:14:31 +02:00
|
|
|
case RETRO_DEVICE_MENACER:
|
|
|
|
input.system[1] = SYSTEM_MENACER;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_JUSTIFIERS:
|
|
|
|
input.system[1] = SYSTEM_JUSTIFIER;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_PHASER:
|
|
|
|
input.system[port] = SYSTEM_LIGHTPHASER;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_PADDLE:
|
|
|
|
input.system[port] = SYSTEM_PADDLE;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_SPORTSPAD:
|
|
|
|
input.system[port] = SYSTEM_SPORTSPAD;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_XE_1AP:
|
|
|
|
input.system[port] = SYSTEM_XE_1AP;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_MOUSE:
|
|
|
|
input.system[port] = SYSTEM_MOUSE;
|
|
|
|
break;
|
2014-10-10 18:06:16 +02:00
|
|
|
case RETRO_DEVICE_GRAPHIC_BOARD:
|
|
|
|
input.system[port] = SYSTEM_GRAPHIC_BOARD;
|
|
|
|
break;
|
2014-05-02 03:20:17 +02:00
|
|
|
case RETRO_DEVICE_JOYPAD:
|
|
|
|
default:
|
2014-07-20 23:07:58 +02:00
|
|
|
config.input[port*4].padtype = DEVICE_PAD2B | DEVICE_PAD6B | DEVICE_PAD3B;
|
2014-05-02 03:20:17 +02:00
|
|
|
input.system[port] = SYSTEM_GAMEPAD;
|
|
|
|
break;
|
2014-05-02 03:13:37 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 23:07:58 +02:00
|
|
|
old_system[0] = input.system[0];
|
|
|
|
old_system[1] = input.system[1];
|
|
|
|
|
|
|
|
io_init();
|
|
|
|
input_reset();
|
2013-11-27 23:09:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t retro_serialize_size(void) { return STATE_SIZE; }
|
|
|
|
|
|
|
|
bool retro_serialize(void *data, size_t size)
|
|
|
|
{
|
|
|
|
if (size != STATE_SIZE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
state_save(data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool retro_unserialize(const void *data, size_t size)
|
|
|
|
{
|
|
|
|
if (size != STATE_SIZE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!state_load((uint8_t*)data))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-04-08 00:58:24 +02:00
|
|
|
|
2014-12-06 16:27:19 +01:00
|
|
|
void retro_cheat_reset(void)
|
|
|
|
{
|
|
|
|
/* clear existing ROM patches */
|
|
|
|
clear_cheats();
|
2014-12-07 19:25:38 +01:00
|
|
|
/* delete all cheats */
|
|
|
|
maxcheats = maxROMcheats = maxRAMcheats = 0;
|
2014-12-06 16:27:19 +01:00
|
|
|
}
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
void retro_cheat_set(unsigned index, bool enabled, const char *code)
|
|
|
|
{
|
2014-12-06 16:27:19 +01:00
|
|
|
/* clear existing ROM patches */
|
|
|
|
clear_cheats();
|
2014-12-07 19:25:38 +01:00
|
|
|
|
|
|
|
/* interpret code and check if this is a valid cheat code */
|
|
|
|
if (decode_cheat((char *)code, maxcheats))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* check if cheat code already exists */
|
|
|
|
for (i=0; i<maxcheats; i++)
|
|
|
|
{
|
|
|
|
if ((cheatlist[i].address == cheatlist[maxcheats].address)
|
|
|
|
&& (cheatlist[i].data == cheatlist[maxcheats].data))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cheat can be enabled or disabled */
|
|
|
|
cheatlist[i].enable = enabled;
|
|
|
|
|
|
|
|
/* if new cheat code, check current cheat count */
|
|
|
|
if ((i == maxcheats) && (i < MAX_CHEATS))
|
|
|
|
{
|
|
|
|
/* increment cheat count */
|
|
|
|
maxcheats++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-06 16:27:19 +01:00
|
|
|
/* apply ROM patches */
|
|
|
|
apply_cheats();
|
2013-04-08 00:28:25 +02:00
|
|
|
}
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
bool retro_load_game(const struct retro_game_info *info)
|
|
|
|
{
|
2013-11-27 23:09:54 +01:00
|
|
|
int i;
|
2012-08-14 21:46:30 +02:00
|
|
|
const char *dir;
|
2013-11-27 23:09:54 +01:00
|
|
|
#if defined(_WIN32)
|
|
|
|
char slash = '\\';
|
|
|
|
#else
|
|
|
|
char slash = '/';
|
|
|
|
#endif
|
2012-10-26 20:46:07 +02:00
|
|
|
|
2014-12-04 17:01:01 +01:00
|
|
|
struct retro_input_descriptor desc[] = {
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "C" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "A" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "X" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Z" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" },
|
|
|
|
{ 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
extract_directory(g_rom_dir, info->path, sizeof(g_rom_dir));
|
|
|
|
|
2012-09-23 01:33:36 +02:00
|
|
|
if (!environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) || !dir)
|
2012-08-14 21:46:30 +02:00
|
|
|
{
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_INFO, "[genplus]: Defaulting system directory to %s.\n", g_rom_dir);
|
2012-09-23 01:33:36 +02:00
|
|
|
dir = g_rom_dir;
|
|
|
|
}
|
2012-08-14 21:46:30 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
snprintf(GG_ROM, sizeof(GG_ROM), "%s%cggenie.bin", dir, slash);
|
|
|
|
snprintf(AR_ROM, sizeof(AR_ROM), "%s%careplay.bin", dir, slash);
|
|
|
|
snprintf(SK_ROM, sizeof(SK_ROM), "%s%csk.bin", dir, slash);
|
2015-01-07 23:38:06 +01:00
|
|
|
snprintf(SK_UPMEM, sizeof(SK_UPMEM), "%s%csk2chip.bin", dir, slash);
|
2012-10-29 05:39:01 +01:00
|
|
|
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_JP, sizeof(CD_BIOS_JP), "%s%cbios_CD_J.bin", dir, slash);
|
2013-06-17 02:08:00 +02:00
|
|
|
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(CART_BRAM, sizeof(CART_BRAM), "%s%ccart.brm", dir, slash);
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
{
|
|
|
|
log_cb(RETRO_LOG_INFO, "Game Genie ROM should be located at: %s\n", GG_ROM);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Action Replay (Pro) ROM should be located at: %s\n", AR_ROM);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Sonic & Knuckles (2 MB) ROM should be located at: %s\n", SK_ROM);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Sonic & Knuckles UPMEM (256 KB) ROM should be located at: %s\n", SK_UPMEM);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Mega CD PAL BIOS should be located at: %s\n", CD_BIOS_EU);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Sega CD NTSC-U BIOS should be located at: %s\n", CD_BIOS_US);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Mega CD NTSC-J BIOS should be located at: %s\n", CD_BIOS_JP);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Mega CD PAL BRAM is located at: %s\n", CD_BRAM_EU);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Sega CD NTSC-U BRAM is located at: %s\n", CD_BRAM_US);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Mega CD NTSC-J BRAM is located at: %s\n", CD_BRAM_JP);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Mega CD RAM CART is located at: %s\n", CART_BRAM);
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
check_variables();
|
|
|
|
if (!load_rom((char *)info->path))
|
2012-07-09 23:14:35 +02:00
|
|
|
return false;
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
audio_init(44100, vdp_pal ? pal_fps : ntsc_fps);
|
2012-07-09 23:14:35 +02:00
|
|
|
system_init();
|
|
|
|
system_reset();
|
2014-11-29 20:09:43 +01:00
|
|
|
is_running = false;
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
if (system_hw == SYSTEM_MCD)
|
2013-11-27 23:09:54 +01:00
|
|
|
bram_load();
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
update_viewport();
|
2013-04-08 00:28:25 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
return true;
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
|
|
|
|
{
|
|
|
|
(void)game_type;
|
|
|
|
(void)info;
|
|
|
|
(void)num_info;
|
2012-07-10 01:51:14 +02:00
|
|
|
return FALSE;
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_unload_game(void)
|
|
|
|
{
|
|
|
|
if (system_hw == SYSTEM_MCD)
|
2013-06-17 02:08:00 +02:00
|
|
|
bram_save();
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned retro_get_region(void) { return vdp_pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC; }
|
|
|
|
|
|
|
|
void *retro_get_memory_data(unsigned id)
|
|
|
|
{
|
|
|
|
if (!sram.on)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_MEMORY_SAVE_RAM:
|
|
|
|
return sram.sram;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t retro_get_memory_size(unsigned id)
|
|
|
|
{
|
2014-12-23 20:34:04 +01:00
|
|
|
int i;
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
if (!sram.on)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_MEMORY_SAVE_RAM:
|
2014-11-29 20:09:43 +01:00
|
|
|
{
|
|
|
|
/* if emulation is not running, we assume the frontend is requesting SRAM size for loading */
|
|
|
|
if (!is_running)
|
|
|
|
{
|
|
|
|
/* max supported size is returned */
|
|
|
|
return 0x10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise, we assume this is for saving and we need to check if SRAM data has been modified */
|
|
|
|
/* this is obviously not %100 safe since the frontend could still be trying to load SRAM while emulation is running */
|
|
|
|
/* a better solution would be that the frontend itself checks if data has been modified before writing it to a file */
|
2014-11-29 20:12:57 +01:00
|
|
|
for (i=0xffff; i>=0; i--)
|
2014-11-29 20:09:43 +01:00
|
|
|
{
|
|
|
|
if (sram.sram[i] != 0xff)
|
|
|
|
{
|
|
|
|
/* only save modified size */
|
|
|
|
return (i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 15:03:17 +02:00
|
|
|
static void check_system_specs(void)
|
|
|
|
{
|
|
|
|
unsigned level = 7;
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
|
|
|
|
}
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
void retro_init(void)
|
|
|
|
{
|
2013-12-16 12:28:19 +01:00
|
|
|
struct retro_log_callback log;
|
2012-10-26 20:46:07 +02:00
|
|
|
unsigned level, rgb565;
|
2012-07-09 23:14:35 +02:00
|
|
|
sms_ntsc = calloc(1, sizeof(sms_ntsc_t));
|
|
|
|
md_ntsc = calloc(1, sizeof(md_ntsc_t));
|
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
init_bitmap();
|
|
|
|
config_default();
|
|
|
|
|
2012-07-10 01:51:14 +02:00
|
|
|
level = 1;
|
2012-07-09 23:14:35 +02:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
|
2012-10-22 06:43:45 +02:00
|
|
|
|
2014-03-05 03:26:01 +01:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
|
2013-12-16 12:50:46 +01:00
|
|
|
log_cb = log.log;
|
2014-03-05 03:26:01 +01:00
|
|
|
else
|
|
|
|
log_cb = NULL;
|
2013-12-16 12:28:19 +01:00
|
|
|
|
2012-10-22 07:09:35 +02:00
|
|
|
#ifdef FRONTEND_SUPPORTS_RGB565
|
2012-10-26 20:46:07 +02:00
|
|
|
rgb565 = RETRO_PIXEL_FORMAT_RGB565;
|
2012-10-22 21:55:48 +02:00
|
|
|
if(environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565))
|
2013-12-16 12:50:46 +01:00
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_INFO, "Frontend supports RGB565 - will use that instead of XRGB1555.\n");
|
2012-10-22 07:09:35 +02:00
|
|
|
#endif
|
2014-06-23 15:03:17 +02:00
|
|
|
check_system_specs();
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_deinit(void)
|
|
|
|
{
|
2012-10-14 19:16:31 +02:00
|
|
|
audio_shutdown();
|
2014-05-02 03:13:37 +02:00
|
|
|
if (md_ntsc)
|
|
|
|
free(md_ntsc);
|
|
|
|
if (sms_ntsc)
|
|
|
|
free(sms_ntsc);
|
|
|
|
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
|
|
|
|
2013-04-01 14:06:28 +02:00
|
|
|
void retro_reset(void) { system_reset(); }
|
2012-07-09 23:14:35 +02:00
|
|
|
|
|
|
|
void retro_run(void)
|
|
|
|
{
|
2013-04-12 16:30:44 +02:00
|
|
|
bool updated = false;
|
2014-11-29 20:09:43 +01:00
|
|
|
is_running = true;
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2012-07-26 13:53:24 +02:00
|
|
|
if (system_hw == SYSTEM_MCD)
|
|
|
|
system_frame_scd(0);
|
|
|
|
else if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
|
|
|
system_frame_gen(0);
|
|
|
|
else
|
|
|
|
system_frame_sms(0);
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
if (bitmap.viewport.changed & 1)
|
|
|
|
{
|
|
|
|
bitmap.viewport.changed &= ~1;
|
2014-04-05 00:46:30 +02:00
|
|
|
if (update_viewport())
|
|
|
|
{
|
|
|
|
struct retro_system_av_info info;
|
|
|
|
retro_get_system_av_info(&info);
|
2014-07-20 23:10:29 +02:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &info.geometry);
|
2014-04-05 00:46:30 +02:00
|
|
|
}
|
2013-11-27 23:09:54 +01:00
|
|
|
}
|
2012-07-09 23:14:35 +02:00
|
|
|
|
2015-04-26 18:28:24 +02:00
|
|
|
if (config.gun_cursor)
|
|
|
|
{
|
|
|
|
if (input.system[0] == SYSTEM_LIGHTPHASER)
|
|
|
|
{
|
|
|
|
draw_cursor(input.analog[0][0], input.analog[0][1], 0x001f);
|
|
|
|
}
|
|
|
|
else if (input.dev[4] == DEVICE_LIGHTGUN)
|
|
|
|
{
|
|
|
|
draw_cursor(input.analog[4][0], input.analog[4][1], 0x001f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.system[1] == SYSTEM_LIGHTPHASER)
|
|
|
|
{
|
|
|
|
draw_cursor(input.analog[4][0], input.analog[4][1], 0xf800);
|
|
|
|
}
|
|
|
|
else if (input.dev[5] == DEVICE_LIGHTGUN)
|
|
|
|
{
|
|
|
|
draw_cursor(input.analog[5][0], input.analog[5][1], 0xf800);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-02 17:51:00 +01:00
|
|
|
video_cb(bitmap.data, vwidth, vheight, 720 * 2);
|
2013-11-27 23:09:54 +01:00
|
|
|
audio_cb(soundbuffer, audio_update(soundbuffer));
|
2013-04-08 00:28:25 +02:00
|
|
|
|
2013-11-27 23:09:54 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated);
|
|
|
|
if (updated)
|
2013-04-08 00:28:25 +02:00
|
|
|
check_variables();
|
2012-07-09 23:14:35 +02:00
|
|
|
}
|
2014-04-29 23:49:47 +02:00
|
|
|
|
|
|
|
#undef CHUNKSIZE
|