2017-01-14 21:09:57 +00:00
|
|
|
#include "copyright"
|
2014-10-28 02:13:05 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "snes9x.h"
|
|
|
|
#include "soundux.h"
|
|
|
|
#include "memmap.h"
|
|
|
|
#include "apu.h"
|
|
|
|
#include "cheats.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "cpuexec.h"
|
|
|
|
#include "spc7110.h"
|
2014-10-30 05:43:08 +00:00
|
|
|
#include "srtc.h"
|
2014-11-01 11:58:18 +00:00
|
|
|
#include "sa1.h"
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2014-10-31 08:12:09 +00:00
|
|
|
#ifdef PSP
|
|
|
|
#include <pspkernel.h>
|
|
|
|
#include <pspgu.h>
|
|
|
|
#endif
|
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
#include <libretro.h>
|
2018-02-21 12:49:45 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2019-08-02 06:29:11 +00:00
|
|
|
#include "libretro_core_options.h"
|
|
|
|
|
2015-10-21 02:14:35 +00:00
|
|
|
#ifdef _3DS
|
|
|
|
void* linearMemAlign(size_t size, size_t alignment);
|
|
|
|
void linearFree(void* mem);
|
|
|
|
#endif
|
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
static retro_log_printf_t log_cb = NULL;
|
|
|
|
static retro_video_refresh_t video_cb = NULL;
|
|
|
|
static retro_input_poll_t poll_cb = NULL;
|
|
|
|
static retro_input_state_t input_cb = NULL;
|
|
|
|
static retro_audio_sample_batch_t audio_batch_cb = NULL;
|
|
|
|
static retro_environment_t environ_cb = NULL;
|
|
|
|
struct retro_perf_callback perf_cb;
|
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
static bool libretro_supports_option_categories = false;
|
2020-09-14 00:38:42 +00:00
|
|
|
static bool libretro_supports_bitmasks = false;
|
|
|
|
|
2018-02-21 12:49:45 +00:00
|
|
|
char retro_save_directory[PATH_MAX_LENGTH];
|
|
|
|
char retro_base_name[PATH_MAX_LENGTH];
|
2018-02-08 11:23:53 +00:00
|
|
|
bool overclock_cycles = false;
|
2018-02-09 17:44:47 +00:00
|
|
|
bool reduce_sprite_flicker = false;
|
2018-02-12 23:44:51 +00:00
|
|
|
int one_c, slow_one_c, two_c;
|
2015-09-14 04:14:51 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2017-06-18 14:42:11 +00:00
|
|
|
char slash = '\\';
|
2015-09-14 04:14:51 +00:00
|
|
|
#else
|
2017-06-18 14:42:11 +00:00
|
|
|
char slash = '/';
|
2015-09-14 04:14:51 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-12 02:40:43 +00:00
|
|
|
static int32_t samples_per_frame = 0;
|
|
|
|
static int32_t samplerate = (((SNES_CLOCK_SPEED * 6) / (32 * ONE_APU_CYCLE)));
|
2014-11-01 07:59:27 +00:00
|
|
|
|
2020-10-17 14:07:44 +00:00
|
|
|
static unsigned frameskip_type = 0;
|
2020-10-20 14:45:38 +00:00
|
|
|
static unsigned frameskip_threshold = 0;
|
2020-10-17 14:07:44 +00:00
|
|
|
static uint16_t frameskip_counter = 0;
|
2020-10-20 14:45:38 +00:00
|
|
|
|
2020-10-17 14:07:44 +00:00
|
|
|
static bool retro_audio_buff_active = false;
|
|
|
|
static unsigned retro_audio_buff_occupancy = 0;
|
|
|
|
static bool retro_audio_buff_underrun = false;
|
|
|
|
/* Maximum number of consecutive frames that
|
|
|
|
* can be skipped */
|
|
|
|
#define FRAMESKIP_MAX 30
|
|
|
|
|
2020-10-20 14:45:38 +00:00
|
|
|
static unsigned retro_audio_latency = 0;
|
|
|
|
static bool update_audio_latency = false;
|
|
|
|
|
2014-10-31 06:47:19 +00:00
|
|
|
#ifdef PERF_TEST
|
|
|
|
#define RETRO_PERFORMANCE_INIT(name) \
|
2017-06-18 14:42:11 +00:00
|
|
|
retro_perf_tick_t current_ticks; \
|
|
|
|
static struct retro_perf_counter name = {#name}; \
|
|
|
|
if (!name.registered) \
|
|
|
|
perf_cb.perf_register(&(name)); \
|
|
|
|
current_ticks = name.total
|
2014-10-31 06:47:19 +00:00
|
|
|
|
2017-08-14 05:03:05 +00:00
|
|
|
#define RETRO_PERFORMANCE_START(name) \
|
|
|
|
perf_cb.perf_start(&(name))
|
|
|
|
|
2014-10-31 06:47:19 +00:00
|
|
|
#define RETRO_PERFORMANCE_STOP(name) \
|
2017-06-18 14:42:11 +00:00
|
|
|
perf_cb.perf_stop(&(name)); \
|
|
|
|
current_ticks = name.total - current_ticks;
|
2014-10-31 06:47:19 +00:00
|
|
|
#else
|
|
|
|
#define RETRO_PERFORMANCE_INIT(name)
|
|
|
|
#define RETRO_PERFORMANCE_START(name)
|
|
|
|
#define RETRO_PERFORMANCE_STOP(name)
|
|
|
|
#endif
|
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
void retro_set_environment(retro_environment_t cb)
|
|
|
|
{
|
|
|
|
struct retro_log_callback log;
|
|
|
|
environ_cb = cb;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
|
|
|
|
log_cb = log.log;
|
|
|
|
else
|
|
|
|
log_cb = NULL;
|
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
libretro_supports_option_categories = false;
|
|
|
|
libretro_set_core_options(environ_cb,
|
|
|
|
&libretro_supports_option_categories);
|
2014-10-28 02:13:05 +00:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_video_refresh(retro_video_refresh_t cb)
|
|
|
|
{
|
|
|
|
video_cb = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_audio_sample(retro_audio_sample_t cb)
|
2017-01-16 22:39:57 +00:00
|
|
|
{
|
2017-08-16 16:59:11 +00:00
|
|
|
(void) cb;
|
2017-01-16 22:39:57 +00:00
|
|
|
}
|
2014-10-28 02:13:05 +00:00
|
|
|
|
|
|
|
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb)
|
|
|
|
{
|
|
|
|
audio_batch_cb = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_input_poll(retro_input_poll_t cb)
|
|
|
|
{
|
|
|
|
poll_cb = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_input_state(retro_input_state_t cb)
|
|
|
|
{
|
|
|
|
input_cb = cb;
|
|
|
|
}
|
|
|
|
|
2017-06-18 14:42:11 +00:00
|
|
|
void retro_set_controller_port_device(unsigned in_port, unsigned device)
|
2014-10-29 23:23:30 +00:00
|
|
|
{
|
2017-08-16 16:59:11 +00:00
|
|
|
(void) in_port;
|
|
|
|
(void) device;
|
2014-10-29 23:23:30 +00:00
|
|
|
}
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2021-06-07 16:32:34 +00:00
|
|
|
unsigned retro_api_version(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-06-18 14:42:11 +00:00
|
|
|
return RETRO_API_VERSION;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 14:07:44 +00:00
|
|
|
static void retro_audio_buff_status_cb(
|
|
|
|
bool active, unsigned occupancy, bool underrun_likely)
|
|
|
|
{
|
|
|
|
retro_audio_buff_active = active;
|
|
|
|
retro_audio_buff_occupancy = occupancy;
|
|
|
|
retro_audio_buff_underrun = underrun_likely;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void retro_set_audio_buff_status_cb(void)
|
|
|
|
{
|
|
|
|
if (frameskip_type > 0)
|
|
|
|
{
|
|
|
|
struct retro_audio_buffer_status_callback buf_status_cb;
|
|
|
|
|
|
|
|
buf_status_cb.callback = retro_audio_buff_status_cb;
|
|
|
|
if (!environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK,
|
|
|
|
&buf_status_cb))
|
|
|
|
{
|
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_WARN, "Frameskip disabled - frontend does not support audio buffer status monitoring.\n");
|
|
|
|
|
|
|
|
retro_audio_buff_active = false;
|
|
|
|
retro_audio_buff_occupancy = 0;
|
|
|
|
retro_audio_buff_underrun = false;
|
2020-10-20 14:45:38 +00:00
|
|
|
retro_audio_latency = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Frameskip is enabled - increase frontend
|
|
|
|
* audio latency to minimise potential
|
|
|
|
* buffer underruns */
|
|
|
|
uint32_t frame_time_usec = Settings.FrameTime;
|
|
|
|
|
|
|
|
if (Settings.ForceNTSC)
|
|
|
|
frame_time_usec = Settings.FrameTimeNTSC;
|
|
|
|
if (Settings.ForcePAL)
|
|
|
|
frame_time_usec = Settings.FrameTimePAL;
|
|
|
|
|
|
|
|
/* Set latency to 6x current frame time... */
|
|
|
|
retro_audio_latency = (unsigned)(6 * frame_time_usec / 1000);
|
|
|
|
|
|
|
|
/* ...then round up to nearest multiple of 32 */
|
|
|
|
retro_audio_latency = (retro_audio_latency + 0x1F) & ~0x1F;
|
2020-10-17 14:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-10-20 14:45:38 +00:00
|
|
|
{
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL);
|
|
|
|
retro_audio_latency = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_audio_latency = true;
|
2020-10-17 14:07:44 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
void S9xDeinitDisplay(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
|
|
|
#ifdef DS2_DMA
|
2017-06-18 14:42:11 +00:00
|
|
|
if (GFX.Screen_buffer)
|
|
|
|
AlignedFree(GFX.Screen, PtrAdj.GFXScreen);
|
2015-10-21 02:14:35 +00:00
|
|
|
#elif defined(_3DS)
|
2017-06-18 14:42:11 +00:00
|
|
|
if (GFX.Screen_buffer)
|
|
|
|
linearFree(GFX.Screen_buffer);
|
2014-10-28 02:13:05 +00:00
|
|
|
#else
|
2017-06-18 14:42:11 +00:00
|
|
|
if (GFX.Screen_buffer)
|
|
|
|
free(GFX.Screen_buffer);
|
2014-10-28 02:13:05 +00:00
|
|
|
#endif
|
2017-06-18 14:42:11 +00:00
|
|
|
if (GFX.SubScreen_buffer)
|
|
|
|
free(GFX.SubScreen_buffer);
|
|
|
|
if (GFX.ZBuffer_buffer)
|
|
|
|
free(GFX.ZBuffer_buffer);
|
|
|
|
if (GFX.SubZBuffer_buffer)
|
|
|
|
free(GFX.SubZBuffer_buffer);
|
2014-10-30 00:51:26 +00:00
|
|
|
|
|
|
|
GFX.Screen = NULL;
|
|
|
|
GFX.Screen_buffer = NULL;
|
|
|
|
GFX.SubScreen = NULL;
|
|
|
|
GFX.SubScreen_buffer = NULL;
|
|
|
|
GFX.ZBuffer = NULL;
|
|
|
|
GFX.ZBuffer_buffer = NULL;
|
|
|
|
GFX.SubZBuffer = NULL;
|
|
|
|
GFX.SubZBuffer_buffer = NULL;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
void S9xInitDisplay(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-01-29 04:55:23 +00:00
|
|
|
int32_t h = IMAGE_HEIGHT;
|
|
|
|
int32_t safety = 32;
|
2014-10-28 02:13:05 +00:00
|
|
|
|
|
|
|
GFX.Pitch = IMAGE_WIDTH * 2;
|
|
|
|
#ifdef DS2_DMA
|
2017-01-29 04:55:23 +00:00
|
|
|
GFX.Screen_buffer = (uint8_t *) AlignedMalloc(GFX.Pitch * h + safety, 32, &PtrAdj.GFXScreen);
|
2015-10-21 02:14:35 +00:00
|
|
|
#elif defined(_3DS)
|
|
|
|
safety = 0x80;
|
2017-01-29 04:55:23 +00:00
|
|
|
GFX.Screen_buffer = (uint8_t *) linearMemAlign(GFX.Pitch * h + safety, 0x80);
|
2014-10-28 02:13:05 +00:00
|
|
|
#else
|
2017-01-29 04:55:23 +00:00
|
|
|
GFX.Screen_buffer = (uint8_t *) malloc(GFX.Pitch * h + safety);
|
2014-10-28 02:13:05 +00:00
|
|
|
#endif
|
2017-01-29 04:55:23 +00:00
|
|
|
GFX.SubScreen_buffer = (uint8_t *) malloc(GFX.Pitch * h + safety);
|
|
|
|
GFX.ZBuffer_buffer = (uint8_t *) malloc((GFX.Pitch >> 1) * h + safety);
|
|
|
|
GFX.SubZBuffer_buffer = (uint8_t *) malloc((GFX.Pitch >> 1) * h + safety);
|
2014-10-30 00:51:26 +00:00
|
|
|
|
|
|
|
GFX.Screen = GFX.Screen_buffer + safety;
|
|
|
|
GFX.SubScreen = GFX.SubScreen_buffer + safety;
|
|
|
|
GFX.ZBuffer = GFX.ZBuffer_buffer + safety;
|
|
|
|
GFX.SubZBuffer = GFX.SubZBuffer_buffer + safety;
|
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
|
|
|
|
}
|
|
|
|
|
2021-06-07 16:22:52 +00:00
|
|
|
static void init_sfc_setting(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2014-10-30 22:55:51 +00:00
|
|
|
memset(&Settings, 0, sizeof(Settings));
|
2014-11-03 14:26:54 +00:00
|
|
|
Settings.JoystickEnabled = false;
|
2017-01-24 20:32:46 +00:00
|
|
|
Settings.SoundPlaybackRate = samplerate;
|
2014-10-29 23:23:30 +00:00
|
|
|
Settings.CyclesPercentage = 100;
|
2014-11-01 07:59:27 +00:00
|
|
|
|
2014-11-03 14:26:54 +00:00
|
|
|
Settings.DisableSoundEcho = false;
|
|
|
|
Settings.InterpolatedSound = true;
|
2017-01-24 20:32:46 +00:00
|
|
|
Settings.APUEnabled = true;
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
Settings.H_Max = SNES_CYCLES_PER_SCANLINE;
|
|
|
|
Settings.FrameTimePAL = 20000;
|
|
|
|
Settings.FrameTimeNTSC = 16667;
|
2014-11-03 14:26:54 +00:00
|
|
|
Settings.DisableMasterVolume = false;
|
|
|
|
Settings.Mouse = true;
|
|
|
|
Settings.SuperScope = true;
|
|
|
|
Settings.MultiPlayer5 = true;
|
2014-10-29 23:23:30 +00:00
|
|
|
Settings.ControllerOption = SNES_JOYPAD;
|
2014-11-03 10:38:35 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
2014-11-03 14:26:54 +00:00
|
|
|
Settings.SoundSync = false;
|
2014-11-03 10:38:35 +00:00
|
|
|
#endif
|
2014-12-20 06:59:41 +00:00
|
|
|
Settings.ApplyCheats = true;
|
2014-10-28 02:13:05 +00:00
|
|
|
Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX;
|
|
|
|
}
|
|
|
|
|
2014-11-03 10:38:35 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
2021-06-07 16:22:52 +00:00
|
|
|
static void S9xAudioCallback(void)
|
2014-11-03 10:38:35 +00:00
|
|
|
{
|
|
|
|
size_t avail;
|
|
|
|
/* Just pick a big buffer. We won't use it all. */
|
2016-10-16 17:52:04 +00:00
|
|
|
static int16_t audio_buf[0x20000];
|
2014-11-03 10:38:35 +00:00
|
|
|
|
|
|
|
S9xFinalizeSamples();
|
|
|
|
avail = S9xGetSampleCount();
|
|
|
|
S9xMixSamples(audio_buf, avail);
|
|
|
|
audio_batch_cb(audio_buf, avail >> 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
void retro_init(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
|
|
|
struct retro_log_callback log;
|
|
|
|
enum retro_pixel_format rgb565;
|
2017-08-16 17:23:32 +00:00
|
|
|
bool achievements = true;
|
2017-08-14 05:03:05 +00:00
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
|
|
|
|
log_cb = log.log;
|
|
|
|
else
|
|
|
|
log_cb = NULL;
|
|
|
|
|
2017-08-16 03:20:50 +00:00
|
|
|
/* State that the core supports achievements. */
|
2017-06-18 14:42:11 +00:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &achievements);
|
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
rgb565 = RETRO_PIXEL_FORMAT_RGB565;
|
2014-10-29 23:23:30 +00:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565) && log_cb)
|
2017-08-14 05:03:05 +00:00
|
|
|
log_cb(RETRO_LOG_INFO, "Frontend supports RGB565 - will use that instead of XRGB1555.\n");
|
2014-10-28 02:13:05 +00:00
|
|
|
|
|
|
|
init_sfc_setting();
|
2014-11-02 06:52:33 +00:00
|
|
|
S9xInitMemory();
|
2014-10-30 02:10:39 +00:00
|
|
|
S9xInitAPU();
|
2014-10-29 23:23:30 +00:00
|
|
|
S9xInitDisplay();
|
2014-11-02 06:52:33 +00:00
|
|
|
S9xInitGFX();
|
2014-11-03 10:11:05 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
2017-08-16 03:20:50 +00:00
|
|
|
S9xInitSound(1000, 0); /* just give it a 1 second buffer */
|
2014-11-03 10:38:35 +00:00
|
|
|
S9xSetSamplesAvailableCallback(S9xAudioCallback);
|
2014-11-03 10:11:05 +00:00
|
|
|
#else
|
2016-10-16 18:07:08 +00:00
|
|
|
S9xInitSound();
|
2014-11-03 10:11:05 +00:00
|
|
|
#endif
|
2017-06-18 15:16:19 +00:00
|
|
|
CPU.SaveStateVersion = 0;
|
2020-09-14 00:38:42 +00:00
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
|
|
|
|
libretro_supports_bitmasks = true;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 02:41:40 +00:00
|
|
|
void retro_deinit(void)
|
|
|
|
{
|
2014-11-03 10:11:05 +00:00
|
|
|
if (Settings.SPC7110)
|
2017-08-13 05:02:24 +00:00
|
|
|
Del7110Gfx();
|
2014-11-02 06:52:33 +00:00
|
|
|
|
|
|
|
S9xDeinitGFX();
|
2014-10-30 02:41:40 +00:00
|
|
|
S9xDeinitDisplay();
|
|
|
|
S9xDeinitAPU();
|
2014-11-02 06:52:33 +00:00
|
|
|
S9xDeinitMemory();
|
2014-10-31 06:47:19 +00:00
|
|
|
|
|
|
|
#ifdef PERF_TEST
|
|
|
|
perf_cb.perf_log();
|
|
|
|
#endif
|
2020-09-14 00:38:42 +00:00
|
|
|
|
2020-10-20 14:45:38 +00:00
|
|
|
/* Reset globals (required for static builds) */
|
2021-08-12 13:51:40 +00:00
|
|
|
libretro_supports_option_categories = false;
|
2020-09-14 00:38:42 +00:00
|
|
|
libretro_supports_bitmasks = false;
|
2020-10-20 14:45:38 +00:00
|
|
|
frameskip_type = 0;
|
|
|
|
frameskip_threshold = 0;
|
|
|
|
frameskip_counter = 0;
|
|
|
|
retro_audio_buff_active = false;
|
|
|
|
retro_audio_buff_occupancy = 0;
|
|
|
|
retro_audio_buff_underrun = false;
|
|
|
|
retro_audio_latency = 0;
|
|
|
|
update_audio_latency = false;
|
2014-10-30 02:41:40 +00:00
|
|
|
}
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2017-01-29 04:55:23 +00:00
|
|
|
uint32_t S9xReadJoypad(int32_t port)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2014-11-03 14:26:54 +00:00
|
|
|
static const uint32_t snes_lut[] =
|
2014-10-29 23:23:30 +00:00
|
|
|
{
|
|
|
|
SNES_B_MASK,
|
|
|
|
SNES_Y_MASK,
|
|
|
|
SNES_SELECT_MASK,
|
|
|
|
SNES_START_MASK,
|
|
|
|
SNES_UP_MASK,
|
|
|
|
SNES_DOWN_MASK,
|
|
|
|
SNES_LEFT_MASK,
|
|
|
|
SNES_RIGHT_MASK,
|
|
|
|
SNES_A_MASK,
|
|
|
|
SNES_X_MASK,
|
|
|
|
SNES_TL_MASK,
|
|
|
|
SNES_TR_MASK
|
2014-10-28 02:13:05 +00:00
|
|
|
};
|
|
|
|
|
2017-01-29 04:55:23 +00:00
|
|
|
int32_t i;
|
2014-11-03 14:26:54 +00:00
|
|
|
uint32_t joypad = 0;
|
2020-09-14 00:38:42 +00:00
|
|
|
uint32_t joy_bits = 0;
|
|
|
|
|
|
|
|
if (libretro_supports_bitmasks)
|
|
|
|
joy_bits = input_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < (RETRO_DEVICE_ID_JOYPAD_R3+1); i++)
|
|
|
|
joy_bits |= input_cb(port, RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
|
|
|
|
}
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
for (i = RETRO_DEVICE_ID_JOYPAD_B; i <= RETRO_DEVICE_ID_JOYPAD_R; i++)
|
2020-09-14 00:38:42 +00:00
|
|
|
if (joy_bits & (1 << i))
|
2014-10-28 02:13:05 +00:00
|
|
|
joypad |= snes_lut[i];
|
|
|
|
|
|
|
|
return joypad;
|
|
|
|
}
|
|
|
|
|
2020-10-20 14:45:38 +00:00
|
|
|
static void check_variables(bool first_run)
|
2015-10-06 00:24:03 +00:00
|
|
|
{
|
|
|
|
struct retro_variable var;
|
2020-10-20 14:45:38 +00:00
|
|
|
bool prev_force_ntsc;
|
|
|
|
bool prev_force_pal;
|
2020-10-17 14:07:44 +00:00
|
|
|
bool prev_frameskip_type;
|
2015-10-06 00:24:03 +00:00
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
var.key = "snes9x_2005_region";
|
2015-11-01 22:32:10 +00:00
|
|
|
var.value = NULL;
|
2020-10-17 14:07:44 +00:00
|
|
|
|
2020-10-20 14:45:38 +00:00
|
|
|
prev_force_ntsc = Settings.ForceNTSC;
|
|
|
|
prev_force_pal = Settings.ForcePAL;
|
|
|
|
|
2015-11-01 22:32:10 +00:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
Settings.ForceNTSC = !strcmp(var.value, "NTSC");
|
|
|
|
Settings.ForcePAL = !strcmp(var.value, "PAL");
|
|
|
|
}
|
2018-02-08 11:23:53 +00:00
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
var.key = "snes9x_2005_frameskip";
|
2020-10-17 14:07:44 +00:00
|
|
|
var.value = NULL;
|
|
|
|
|
|
|
|
prev_frameskip_type = frameskip_type;
|
|
|
|
frameskip_type = 0;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "auto") == 0)
|
|
|
|
frameskip_type = 1;
|
2020-10-20 14:45:38 +00:00
|
|
|
else if (strcmp(var.value, "manual") == 0)
|
2020-10-17 14:07:44 +00:00
|
|
|
frameskip_type = 2;
|
|
|
|
}
|
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
var.key = "snes9x_2005_frameskip_threshold";
|
2020-10-20 14:45:38 +00:00
|
|
|
var.value = NULL;
|
|
|
|
|
|
|
|
frameskip_threshold = 33;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
frameskip_threshold = strtol(var.value, NULL, 10);
|
2020-10-17 14:07:44 +00:00
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
var.key = "snes9x_2005_overclock_cycles";
|
2018-02-08 11:23:53 +00:00
|
|
|
var.value = NULL;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
2020-10-17 14:07:44 +00:00
|
|
|
{
|
|
|
|
if (strcmp(var.value, "compatible") == 0)
|
|
|
|
{
|
|
|
|
overclock_cycles = true;
|
|
|
|
one_c = 4;
|
|
|
|
slow_one_c = 5;
|
|
|
|
two_c = 6;
|
|
|
|
}
|
|
|
|
else if (strcmp(var.value, "max") == 0)
|
2018-02-08 11:23:53 +00:00
|
|
|
{
|
2020-10-17 14:07:44 +00:00
|
|
|
overclock_cycles = true;
|
|
|
|
one_c = 3;
|
|
|
|
slow_one_c = 3;
|
|
|
|
two_c = 3;
|
2018-02-08 11:23:53 +00:00
|
|
|
}
|
2020-10-17 14:07:44 +00:00
|
|
|
else
|
|
|
|
overclock_cycles = false;
|
|
|
|
}
|
2018-02-09 17:44:47 +00:00
|
|
|
|
2021-08-12 13:51:40 +00:00
|
|
|
var.key = "snes9x_2005_reduce_sprite_flicker";
|
2018-02-09 17:44:47 +00:00
|
|
|
var.value = NULL;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
2020-10-17 14:07:44 +00:00
|
|
|
{
|
|
|
|
if (strcmp(var.value, "enabled") == 0)
|
|
|
|
reduce_sprite_flicker = true;
|
|
|
|
else
|
|
|
|
reduce_sprite_flicker = false;
|
|
|
|
}
|
2020-10-20 14:45:38 +00:00
|
|
|
|
|
|
|
/* Reinitialise frameskipping, if required */
|
|
|
|
if (!first_run &&
|
|
|
|
((frameskip_type != prev_frameskip_type) ||
|
|
|
|
(Settings.ForceNTSC != prev_force_ntsc) ||
|
|
|
|
(Settings.ForcePAL != prev_force_pal)))
|
|
|
|
retro_set_audio_buff_status_cb();
|
2015-10-06 00:24:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 02:40:43 +00:00
|
|
|
static int32_t samples_to_play = 0;
|
2014-10-29 23:23:30 +00:00
|
|
|
void retro_run(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2015-10-06 00:24:03 +00:00
|
|
|
bool updated = false;
|
2018-03-31 03:35:35 +00:00
|
|
|
int result;
|
|
|
|
bool okay;
|
2017-08-16 16:59:11 +00:00
|
|
|
#ifndef USE_BLARGG_APU
|
|
|
|
static int16_t audio_buf[2048];
|
|
|
|
#endif
|
2015-10-06 00:24:03 +00:00
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
2020-10-20 14:45:38 +00:00
|
|
|
check_variables(false);
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2014-11-01 12:25:00 +00:00
|
|
|
#ifdef NO_VIDEO_OUTPUT
|
|
|
|
video_cb(NULL, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, GFX.Pitch);
|
|
|
|
IPPU.RenderThisFrame = false;
|
|
|
|
#endif
|
2014-11-01 11:58:18 +00:00
|
|
|
|
2018-03-31 03:35:35 +00:00
|
|
|
result = -1;
|
|
|
|
okay = environ_cb(RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE, &result);
|
|
|
|
if (okay)
|
|
|
|
{
|
|
|
|
bool audioEnabled = 0 != (result & 2);
|
|
|
|
bool videoEnabled = 0 != (result & 1);
|
|
|
|
bool hardDisableAudio = 0 != (result & 8);
|
|
|
|
IPPU.RenderThisFrame = videoEnabled;
|
2018-03-31 12:02:58 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
2018-03-31 03:35:35 +00:00
|
|
|
S9xSetSoundMute(!audioEnabled || hardDisableAudio);
|
2018-03-31 12:02:58 +00:00
|
|
|
#endif
|
2018-03-31 03:35:35 +00:00
|
|
|
Settings.HardDisableAudio = hardDisableAudio;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-31 03:40:23 +00:00
|
|
|
IPPU.RenderThisFrame = true;
|
2018-03-31 12:02:58 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
2018-03-31 03:35:35 +00:00
|
|
|
S9xSetSoundMute(false);
|
2018-03-31 12:02:58 +00:00
|
|
|
#endif
|
2018-03-31 03:35:35 +00:00
|
|
|
Settings.HardDisableAudio = false;
|
|
|
|
}
|
|
|
|
|
2020-10-17 14:07:44 +00:00
|
|
|
/* Check whether current frame should
|
|
|
|
* be skipped */
|
|
|
|
if ((frameskip_type > 0) &&
|
|
|
|
retro_audio_buff_active &&
|
|
|
|
IPPU.RenderThisFrame)
|
|
|
|
{
|
|
|
|
bool skip_frame;
|
|
|
|
|
|
|
|
switch (frameskip_type)
|
|
|
|
{
|
|
|
|
case 1: /* auto */
|
|
|
|
skip_frame = retro_audio_buff_underrun;
|
|
|
|
break;
|
2020-10-20 14:45:38 +00:00
|
|
|
case 2: /* manual */
|
|
|
|
skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
|
2020-10-17 14:07:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skip_frame = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip_frame)
|
|
|
|
{
|
|
|
|
if(frameskip_counter < FRAMESKIP_MAX)
|
|
|
|
{
|
|
|
|
IPPU.RenderThisFrame = false;
|
|
|
|
frameskip_counter++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
frameskip_counter = 0;
|
|
|
|
}
|
2020-10-22 11:13:05 +00:00
|
|
|
else
|
|
|
|
frameskip_counter = 0;
|
2020-10-17 14:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 14:45:38 +00:00
|
|
|
/* If frameskip/timing settings have changed,
|
|
|
|
* update frontend audio latency
|
|
|
|
* > Can do this before or after the frameskip
|
|
|
|
* check, but doing it after means we at least
|
|
|
|
* retain the current frame's audio output */
|
|
|
|
if (update_audio_latency)
|
|
|
|
{
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_MINIMUM_AUDIO_LATENCY,
|
|
|
|
&retro_audio_latency);
|
|
|
|
update_audio_latency = false;
|
|
|
|
}
|
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
poll_cb();
|
|
|
|
|
2014-10-31 06:47:19 +00:00
|
|
|
RETRO_PERFORMANCE_INIT(S9xMainLoop_func);
|
|
|
|
RETRO_PERFORMANCE_START(S9xMainLoop_func);
|
2014-10-28 02:13:05 +00:00
|
|
|
S9xMainLoop();
|
2014-10-31 06:47:19 +00:00
|
|
|
RETRO_PERFORMANCE_STOP(S9xMainLoop_func);
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2014-11-03 10:38:35 +00:00
|
|
|
#ifndef USE_BLARGG_APU
|
2014-11-01 07:59:27 +00:00
|
|
|
samples_to_play += samples_per_frame;
|
|
|
|
|
|
|
|
if (samples_to_play > 512)
|
|
|
|
{
|
2017-02-12 02:40:43 +00:00
|
|
|
S9xMixSamples(audio_buf, samples_to_play * 2);
|
|
|
|
audio_batch_cb(audio_buf, samples_to_play);
|
|
|
|
samples_to_play = 0;
|
2014-11-01 07:59:27 +00:00
|
|
|
}
|
2018-03-14 21:24:26 +00:00
|
|
|
#else
|
|
|
|
S9xAudioCallback();
|
2014-11-03 10:38:35 +00:00
|
|
|
#endif
|
2014-11-01 07:59:27 +00:00
|
|
|
|
2017-02-12 02:40:43 +00:00
|
|
|
#ifdef NO_VIDEO_OUTPUT
|
2014-11-01 12:25:00 +00:00
|
|
|
return;
|
|
|
|
#endif
|
2014-11-01 11:58:18 +00:00
|
|
|
|
2014-11-01 09:27:16 +00:00
|
|
|
if (IPPU.RenderThisFrame)
|
|
|
|
{
|
2014-10-31 08:12:09 +00:00
|
|
|
#ifdef PSP
|
2014-11-01 09:27:16 +00:00
|
|
|
static unsigned int __attribute__((aligned(16))) d_list[32];
|
2017-08-16 03:20:50 +00:00
|
|
|
void* const texture_vram_p = (void*)(0x44200000 - (512 * 512)); /* max VRAM address - frame size */
|
2017-08-14 05:03:05 +00:00
|
|
|
sceKernelDcacheWritebackRange(GFX.Screen, GFX.Pitch * IPPU.RenderedScreenHeight);
|
2014-11-01 09:27:16 +00:00
|
|
|
sceGuStart(GU_DIRECT, d_list);
|
2017-08-14 05:03:05 +00:00
|
|
|
sceGuCopyImage(GU_PSM_4444, 0, 0, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, GFX.Pitch >> 1, GFX.Screen, 0, 0, 512, texture_vram_p);
|
2014-11-01 09:27:16 +00:00
|
|
|
sceGuTexSync();
|
|
|
|
sceGuTexImage(0, 512, 512, 512, texture_vram_p);
|
|
|
|
sceGuTexMode(GU_PSM_5551, 0, 0, GU_FALSE);
|
|
|
|
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
|
|
|
|
sceGuDisable(GU_BLEND);
|
|
|
|
sceGuFinish();
|
2017-08-14 05:03:05 +00:00
|
|
|
video_cb(texture_vram_p, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, GFX.Pitch);
|
2014-10-31 08:12:09 +00:00
|
|
|
#else
|
2017-08-14 05:03:05 +00:00
|
|
|
video_cb(GFX.Screen, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, GFX.Pitch);
|
2014-10-31 08:12:09 +00:00
|
|
|
#endif
|
2014-11-01 09:27:16 +00:00
|
|
|
}
|
2014-10-28 02:13:05 +00:00
|
|
|
else
|
2014-11-01 09:27:16 +00:00
|
|
|
video_cb(NULL, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, GFX.Pitch);
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 04:55:23 +00:00
|
|
|
bool S9xReadMousePosition(int32_t which1, int32_t* x, int32_t* y, uint32_t* buttons)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-08-16 16:59:11 +00:00
|
|
|
(void) which1;
|
|
|
|
(void) x;
|
|
|
|
(void) y;
|
|
|
|
(void) buttons;
|
2017-08-14 05:03:05 +00:00
|
|
|
return false;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 04:55:23 +00:00
|
|
|
bool S9xReadSuperScopePosition(int32_t* x, int32_t* y, uint32_t* buttons)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-08-16 16:59:11 +00:00
|
|
|
(void) x;
|
|
|
|
(void) y;
|
|
|
|
(void) buttons;
|
2017-08-14 05:03:05 +00:00
|
|
|
return true;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 16:59:11 +00:00
|
|
|
bool JustifierOffscreen(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-08-14 05:03:05 +00:00
|
|
|
return false;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 14:26:54 +00:00
|
|
|
void JustifierButtons(uint32_t* justifiers)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-08-16 16:59:11 +00:00
|
|
|
(void) justifiers;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 16:59:11 +00:00
|
|
|
unsigned retro_get_region(void)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
|
|
|
return Settings.PAL ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
|
|
|
|
}
|
2017-01-16 22:39:57 +00:00
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
void retro_get_system_info(struct retro_system_info* info)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2021-06-04 20:37:50 +00:00
|
|
|
#ifdef LOAD_FROM_MEMORY
|
2016-08-05 16:27:32 +00:00
|
|
|
info->need_fullpath = false;
|
2014-11-02 05:31:17 +00:00
|
|
|
#else
|
2016-08-05 16:27:32 +00:00
|
|
|
info->need_fullpath = true;
|
2014-11-02 05:31:17 +00:00
|
|
|
#endif
|
2014-10-28 02:13:05 +00:00
|
|
|
info->valid_extensions = "smc|fig|sfc|gd3|gd7|dx2|bsx|swc";
|
2016-12-09 22:34:44 +00:00
|
|
|
#ifndef GIT_VERSION
|
|
|
|
#define GIT_VERSION ""
|
|
|
|
#endif
|
|
|
|
info->library_version = "v1.36" GIT_VERSION;
|
2015-09-21 05:26:11 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
2016-08-05 16:37:11 +00:00
|
|
|
info->library_name = "Snes9x 2005 Plus";
|
2015-09-21 05:26:11 +00:00
|
|
|
#else
|
2016-08-05 16:37:11 +00:00
|
|
|
info->library_name = "Snes9x 2005";
|
2015-09-21 05:26:11 +00:00
|
|
|
#endif
|
2016-08-05 16:27:32 +00:00
|
|
|
info->block_extract = false;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
2014-11-01 07:59:27 +00:00
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
void retro_get_system_av_info(struct retro_system_av_info* info)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
|
|
|
info->geometry.base_width = 256;
|
|
|
|
info->geometry.base_height = 224;
|
|
|
|
info->geometry.max_width = 512;
|
|
|
|
info->geometry.max_height = 512;
|
|
|
|
info->geometry.aspect_ratio = 4.0 / 3.0;
|
|
|
|
|
2014-11-01 07:59:27 +00:00
|
|
|
if (!Settings.PAL)
|
2017-08-13 05:02:24 +00:00
|
|
|
info->timing.fps = (SNES_CLOCK_SPEED * 6.0 / (SNES_CYCLES_PER_SCANLINE * SNES_MAX_NTSC_VCOUNTER));
|
2014-11-01 07:59:27 +00:00
|
|
|
else
|
2017-08-13 05:02:24 +00:00
|
|
|
info->timing.fps = (SNES_CLOCK_SPEED * 6.0 / (SNES_CYCLES_PER_SCANLINE * SNES_MAX_PAL_VCOUNTER));
|
2014-10-28 02:13:05 +00:00
|
|
|
|
2017-01-24 20:32:46 +00:00
|
|
|
info->timing.sample_rate = samplerate;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_reset(void)
|
|
|
|
{
|
2014-10-30 02:41:40 +00:00
|
|
|
CPU.Flags = 0;
|
|
|
|
S9xReset();
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t retro_serialize_size(void)
|
|
|
|
{
|
2014-10-30 23:32:12 +00:00
|
|
|
return sizeof(CPU) + sizeof(ICPU) + sizeof(PPU) + sizeof(DMA) +
|
2014-11-03 10:11:05 +00:00
|
|
|
0x10000 + 0x20000 + 0x20000 + 0x8000 +
|
|
|
|
#ifndef USE_BLARGG_APU
|
2020-10-18 14:34:52 +00:00
|
|
|
sizeof(APU) + sizeof(IAPU) + 0x10000 + sizeof(SoundData) +
|
2015-11-02 10:25:46 +00:00
|
|
|
#else
|
2017-08-13 05:02:24 +00:00
|
|
|
SPC_SAVE_STATE_BLOCK_SIZE +
|
2014-11-03 10:11:05 +00:00
|
|
|
#endif
|
2017-08-13 05:02:24 +00:00
|
|
|
sizeof(SA1) + sizeof(s7r) + sizeof(rtc_f9);
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
bool retro_serialize(void* data, size_t size)
|
|
|
|
{
|
2017-01-29 04:55:23 +00:00
|
|
|
int32_t i;
|
2017-08-16 16:59:11 +00:00
|
|
|
uint8_t* buffer = data;
|
|
|
|
(void) size;
|
2017-08-16 03:20:50 +00:00
|
|
|
#ifdef LAGFIX
|
|
|
|
S9xPackStatus();
|
|
|
|
#ifndef USE_BLARGG_APU
|
|
|
|
S9xAPUPackStatus();
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-10-30 06:44:28 +00:00
|
|
|
S9xUpdateRTC();
|
|
|
|
S9xSRTCPreSaveState();
|
|
|
|
memcpy(buffer, &CPU, sizeof(CPU));
|
|
|
|
buffer += sizeof(CPU);
|
|
|
|
memcpy(buffer, &ICPU, sizeof(ICPU));
|
|
|
|
buffer += sizeof(ICPU);
|
|
|
|
memcpy(buffer, &PPU, sizeof(PPU));
|
|
|
|
buffer += sizeof(PPU);
|
|
|
|
memcpy(buffer, &DMA, sizeof(DMA));
|
|
|
|
buffer += sizeof(DMA);
|
|
|
|
memcpy(buffer, Memory.VRAM, 0x10000);
|
|
|
|
buffer += 0x10000;
|
|
|
|
memcpy(buffer, Memory.RAM, 0x20000);
|
|
|
|
buffer += 0x20000;
|
|
|
|
memcpy(buffer, Memory.SRAM, 0x20000);
|
|
|
|
buffer += 0x20000;
|
|
|
|
memcpy(buffer, Memory.FillRAM, 0x8000);
|
|
|
|
buffer += 0x8000;
|
2014-11-03 10:11:05 +00:00
|
|
|
#ifndef USE_BLARGG_APU
|
2014-10-30 06:44:28 +00:00
|
|
|
memcpy(buffer, &APU, sizeof(APU));
|
|
|
|
buffer += sizeof(APU);
|
2014-10-30 07:36:43 +00:00
|
|
|
memcpy(buffer, &IAPU, sizeof(IAPU));
|
|
|
|
buffer += sizeof(IAPU);
|
2014-10-30 06:44:28 +00:00
|
|
|
memcpy(buffer, IAPU.RAM, 0x10000);
|
|
|
|
buffer += 0x10000;
|
2020-10-18 14:34:52 +00:00
|
|
|
memcpy(buffer, &SoundData, sizeof(SoundData));
|
|
|
|
buffer += sizeof(SoundData);
|
2015-11-02 10:25:46 +00:00
|
|
|
#else
|
|
|
|
S9xAPUSaveState(buffer);
|
|
|
|
buffer += SPC_SAVE_STATE_BLOCK_SIZE;
|
2014-11-03 10:11:05 +00:00
|
|
|
#endif
|
2014-10-30 06:44:28 +00:00
|
|
|
|
|
|
|
SA1.Registers.PC = SA1.PC - SA1.PCBase;
|
|
|
|
S9xSA1PackStatus();
|
|
|
|
|
|
|
|
memcpy(buffer, &SA1, sizeof(SA1));
|
|
|
|
buffer += sizeof(SA1);
|
|
|
|
memcpy(buffer, &s7r, sizeof(s7r));
|
|
|
|
buffer += sizeof(s7r);
|
|
|
|
memcpy(buffer, &rtc_f9, sizeof(rtc_f9));
|
2014-10-30 05:43:08 +00:00
|
|
|
|
|
|
|
return true;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
2017-01-16 22:39:57 +00:00
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
bool retro_unserialize(const void* data, size_t size)
|
2014-11-01 12:25:00 +00:00
|
|
|
{
|
2014-10-30 06:44:28 +00:00
|
|
|
const uint8_t* buffer = data;
|
2017-08-16 16:59:11 +00:00
|
|
|
#ifndef USE_BLARGG_APU
|
|
|
|
uint8_t* IAPU_RAM_current = IAPU.RAM;
|
|
|
|
uintptr_t IAPU_RAM_offset;
|
|
|
|
#endif
|
2020-10-19 11:28:54 +00:00
|
|
|
uint32_t sa1_old_flags = SA1.Flags;
|
|
|
|
SSA1 sa1_state;
|
2014-10-30 23:56:05 +00:00
|
|
|
|
|
|
|
if (size != retro_serialize_size())
|
|
|
|
return false;
|
|
|
|
|
2014-10-30 06:44:28 +00:00
|
|
|
S9xReset();
|
|
|
|
memcpy(&CPU, buffer, sizeof(CPU));
|
|
|
|
buffer += sizeof(CPU);
|
|
|
|
memcpy(&ICPU, buffer, sizeof(ICPU));
|
|
|
|
buffer += sizeof(ICPU);
|
|
|
|
memcpy(&PPU, buffer, sizeof(PPU));
|
|
|
|
buffer += sizeof(PPU);
|
|
|
|
memcpy(&DMA, buffer, sizeof(DMA));
|
|
|
|
buffer += sizeof(DMA);
|
|
|
|
memcpy(Memory.VRAM, buffer, 0x10000);
|
|
|
|
buffer += 0x10000;
|
|
|
|
memcpy(Memory.RAM, buffer, 0x20000);
|
|
|
|
buffer += 0x20000;
|
|
|
|
memcpy(Memory.SRAM, buffer, 0x20000);
|
|
|
|
buffer += 0x20000;
|
|
|
|
memcpy(Memory.FillRAM, buffer, 0x8000);
|
|
|
|
buffer += 0x8000;
|
2014-11-03 10:11:05 +00:00
|
|
|
#ifndef USE_BLARGG_APU
|
2014-10-30 06:44:28 +00:00
|
|
|
memcpy(&APU, buffer, sizeof(APU));
|
|
|
|
buffer += sizeof(APU);
|
2014-10-30 07:36:43 +00:00
|
|
|
memcpy(&IAPU, buffer, sizeof(IAPU));
|
|
|
|
buffer += sizeof(IAPU);
|
2015-11-02 10:25:46 +00:00
|
|
|
IAPU_RAM_offset = IAPU_RAM_current - IAPU.RAM;
|
|
|
|
IAPU.PC += IAPU_RAM_offset;
|
|
|
|
IAPU.DirectPage += IAPU_RAM_offset;
|
|
|
|
IAPU.WaitAddress1 += IAPU_RAM_offset;
|
|
|
|
IAPU.WaitAddress2 += IAPU_RAM_offset;
|
2014-10-30 23:32:12 +00:00
|
|
|
IAPU.RAM = IAPU_RAM_current;
|
2014-10-30 06:44:28 +00:00
|
|
|
memcpy(IAPU.RAM, buffer, 0x10000);
|
|
|
|
buffer += 0x10000;
|
2020-10-18 14:34:52 +00:00
|
|
|
memcpy(&SoundData, buffer, sizeof(SoundData));
|
|
|
|
buffer += sizeof(SoundData);
|
2015-11-02 10:25:46 +00:00
|
|
|
#else
|
|
|
|
S9xAPULoadState(buffer);
|
|
|
|
buffer += SPC_SAVE_STATE_BLOCK_SIZE;
|
2014-11-03 10:11:05 +00:00
|
|
|
#endif
|
2014-10-30 06:44:28 +00:00
|
|
|
|
2020-10-19 11:28:54 +00:00
|
|
|
memcpy(&sa1_state, buffer, sizeof(sa1_state));
|
|
|
|
buffer += sizeof(sa1_state);
|
|
|
|
|
|
|
|
/* SA1 state must be restored 'by hand' */
|
|
|
|
SA1.Flags = sa1_state.Flags;
|
|
|
|
SA1.NMIActive = sa1_state.NMIActive;
|
|
|
|
SA1.IRQActive = sa1_state.IRQActive;
|
|
|
|
SA1.WaitingForInterrupt = sa1_state.WaitingForInterrupt;
|
|
|
|
SA1.op1 = sa1_state.op1;
|
|
|
|
SA1.op2 = sa1_state.op2;
|
|
|
|
SA1.arithmetic_op = sa1_state.arithmetic_op;
|
|
|
|
SA1.sum = sa1_state.sum;
|
|
|
|
SA1.overflow = sa1_state.overflow;
|
|
|
|
memcpy(&SA1.Registers, &sa1_state.Registers, sizeof(SA1.Registers));
|
|
|
|
|
2014-10-30 06:44:28 +00:00
|
|
|
memcpy(&s7r, buffer, sizeof(s7r));
|
|
|
|
buffer += sizeof(s7r);
|
|
|
|
memcpy(&rtc_f9, buffer, sizeof(rtc_f9));
|
|
|
|
|
|
|
|
S9xFixSA1AfterSnapshotLoad();
|
2020-10-19 11:28:54 +00:00
|
|
|
SA1.Flags |= sa1_old_flags & (TRACE_FLAG);
|
|
|
|
|
2014-10-30 07:36:43 +00:00
|
|
|
FixROMSpeed();
|
2014-11-03 14:26:54 +00:00
|
|
|
IPPU.ColorsChanged = true;
|
|
|
|
IPPU.OBJChanged = true;
|
|
|
|
CPU.InDMA = false;
|
2014-10-30 07:36:43 +00:00
|
|
|
S9xFixColourBrightness();
|
2014-11-03 10:11:05 +00:00
|
|
|
#ifndef USE_BLARGG_APU
|
|
|
|
S9xAPUUnpackStatus();
|
2014-10-30 07:36:43 +00:00
|
|
|
S9xFixSoundAfterSnapshotLoad();
|
2014-11-03 10:11:05 +00:00
|
|
|
#endif
|
2014-10-30 07:36:43 +00:00
|
|
|
ICPU.ShiftedPB = ICPU.Registers.PB << 16;
|
|
|
|
ICPU.ShiftedDB = ICPU.Registers.DB << 16;
|
|
|
|
S9xSetPCBase(ICPU.ShiftedPB + ICPU.Registers.PC);
|
|
|
|
S9xUnpackStatus();
|
|
|
|
S9xFixCycles();
|
|
|
|
S9xReschedule();
|
2014-10-30 06:44:28 +00:00
|
|
|
return true;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_cheat_reset(void)
|
|
|
|
{
|
2014-12-06 20:55:19 +00:00
|
|
|
S9xDeleteCheats();
|
|
|
|
S9xApplyCheats();
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
2014-12-06 20:55:19 +00:00
|
|
|
|
|
|
|
extern SCheatData Cheat;
|
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
void retro_cheat_set(unsigned index, bool enabled, const char* code)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2014-12-06 20:55:19 +00:00
|
|
|
uint32_t address;
|
|
|
|
uint8_t val;
|
2017-06-18 14:42:11 +00:00
|
|
|
|
2014-12-06 20:55:19 +00:00
|
|
|
bool sram;
|
2017-08-16 03:20:50 +00:00
|
|
|
uint8_t bytes[3];/* used only by GoldFinger, ignored for now */
|
2017-06-18 14:42:11 +00:00
|
|
|
|
2017-08-14 05:03:05 +00:00
|
|
|
if (S9xGameGenieToRaw(code, &address, &val) && S9xProActionReplayToRaw(code, &address, &val) && S9xGoldFingerToRaw(code, &address, &sram, &val, bytes))
|
2017-08-16 03:20:50 +00:00
|
|
|
return; /* bad code, ignore */
|
2014-12-06 20:55:19 +00:00
|
|
|
if (index > Cheat.num_cheats)
|
2017-08-16 03:20:50 +00:00
|
|
|
return; /* cheat added in weird order, ignore */
|
2014-12-06 20:55:19 +00:00
|
|
|
if (index == Cheat.num_cheats)
|
|
|
|
Cheat.num_cheats++;
|
2017-06-18 14:42:11 +00:00
|
|
|
|
2014-12-06 20:55:19 +00:00
|
|
|
Cheat.c[index].address = address;
|
|
|
|
Cheat.c[index].byte = val;
|
|
|
|
Cheat.c[index].enabled = enabled;
|
2017-08-16 03:20:50 +00:00
|
|
|
Cheat.c[index].saved = false; /* it'll be saved next time cheats run anyways */
|
2017-06-18 14:42:11 +00:00
|
|
|
|
2017-02-12 02:40:43 +00:00
|
|
|
Settings.ApplyCheats = true;
|
2014-12-06 20:55:19 +00:00
|
|
|
S9xApplyCheats();
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 14:54:31 +00:00
|
|
|
static void init_descriptors(void)
|
|
|
|
{
|
2017-08-14 05:03:05 +00:00
|
|
|
struct retro_input_descriptor desc[] =
|
|
|
|
{
|
2017-06-18 14:42:11 +00:00
|
|
|
{ 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, "A" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 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, "A" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
|
|
|
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 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, "A" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
|
|
|
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 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, "A" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
|
|
|
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 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, "A" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
2014-12-05 14:54:31 +00:00
|
|
|
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
|
|
|
|
}
|
|
|
|
|
2014-10-29 23:23:30 +00:00
|
|
|
bool retro_load_game(const struct retro_game_info* game)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-01-24 01:18:38 +00:00
|
|
|
struct retro_system_av_info av_info;
|
|
|
|
if (!game)
|
|
|
|
return false;
|
|
|
|
|
2014-10-30 02:41:40 +00:00
|
|
|
CPU.Flags = 0;
|
2017-01-24 01:18:38 +00:00
|
|
|
init_descriptors();
|
2020-10-20 14:45:38 +00:00
|
|
|
check_variables(true);
|
2014-10-31 04:29:24 +00:00
|
|
|
|
2021-06-04 20:37:50 +00:00
|
|
|
#ifdef LOAD_FROM_MEMORY
|
2014-11-02 05:31:17 +00:00
|
|
|
if (!LoadROM(game))
|
|
|
|
#else
|
2017-06-18 14:42:11 +00:00
|
|
|
if (!LoadROM(game->path))
|
2014-11-02 05:31:17 +00:00
|
|
|
#endif
|
2017-06-18 14:42:11 +00:00
|
|
|
return false;
|
2014-10-30 02:41:40 +00:00
|
|
|
|
2017-06-18 14:42:11 +00:00
|
|
|
Settings.FrameTime = (Settings.PAL ? Settings.FrameTimePAL : Settings.FrameTimeNTSC);
|
2014-10-30 02:41:40 +00:00
|
|
|
|
2020-10-17 14:07:44 +00:00
|
|
|
retro_set_audio_buff_status_cb();
|
2014-11-01 07:59:27 +00:00
|
|
|
retro_get_system_av_info(&av_info);
|
|
|
|
|
2014-11-03 10:11:05 +00:00
|
|
|
#ifdef USE_BLARGG_APU
|
|
|
|
Settings.SoundPlaybackRate = av_info.timing.sample_rate;
|
|
|
|
#else
|
2015-11-09 12:40:42 +00:00
|
|
|
samples_per_frame = av_info.timing.sample_rate / av_info.timing.fps;
|
2017-01-24 20:32:46 +00:00
|
|
|
S9xSetPlaybackRate(Settings.SoundPlaybackRate);
|
2014-11-03 10:11:05 +00:00
|
|
|
#endif
|
2014-10-31 08:19:24 +00:00
|
|
|
return true;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 14:42:11 +00:00
|
|
|
bool retro_load_game_special(unsigned game_type, const struct retro_game_info* info, size_t num_info)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-08-16 16:59:11 +00:00
|
|
|
(void) game_type;
|
|
|
|
(void) info;
|
|
|
|
(void) num_info;
|
2014-10-28 02:13:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 22:39:57 +00:00
|
|
|
|
2014-10-28 02:13:05 +00:00
|
|
|
void retro_unload_game(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-05 22:49:32 +00:00
|
|
|
void* retro_get_memory_data(unsigned type)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-06-18 14:42:11 +00:00
|
|
|
uint8_t* data;
|
2016-08-05 22:49:32 +00:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RETRO_MEMORY_SAVE_RAM:
|
|
|
|
data = Memory.SRAM;
|
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_SYSTEM_RAM:
|
|
|
|
data = Memory.RAM;
|
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_VIDEO_RAM:
|
|
|
|
data = Memory.VRAM;
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-18 14:42:11 +00:00
|
|
|
data = NULL;
|
2016-08-05 22:49:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 22:49:32 +00:00
|
|
|
size_t retro_get_memory_size(unsigned type)
|
2014-10-28 02:13:05 +00:00
|
|
|
{
|
2017-01-29 04:55:23 +00:00
|
|
|
uint32_t size;
|
2016-08-05 22:49:32 +00:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RETRO_MEMORY_SAVE_RAM:
|
2017-01-29 04:55:23 +00:00
|
|
|
size = (uint32_t) (Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0);
|
2016-08-05 22:49:32 +00:00
|
|
|
if (size > 0x20000)
|
|
|
|
size = 0x20000;
|
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_RTC:
|
2017-01-16 22:39:57 +00:00
|
|
|
size = (Settings.SRTC || Settings.SPC7110RTC) ? 20 : 0;
|
2016-08-05 22:49:32 +00:00
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_SYSTEM_RAM:
|
|
|
|
size = 128 * 1024;
|
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_VIDEO_RAM:
|
|
|
|
size = 64 * 1024;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
size = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2014-10-28 02:13:05 +00:00
|
|
|
}
|