2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
2021-09-30 23:30:03 +02:00
|
|
|
|
|
|
|
#include <streams/file_stream.h>
|
|
|
|
#include <libretro.h>
|
|
|
|
|
|
|
|
#include "../common.h"
|
|
|
|
#include "../memmap.h"
|
2020-09-21 18:50:21 +02:00
|
|
|
#include "libretro_core_options.h"
|
2014-12-09 00:17:28 +01:00
|
|
|
|
2021-09-30 23:30:03 +02:00
|
|
|
#include "../gba_memory.h"
|
|
|
|
#include "../gba_cc_lut.h"
|
2016-08-08 00:31:21 +02:00
|
|
|
|
2016-08-14 18:28:25 +02:00
|
|
|
#if defined(VITA) && defined(HAVE_DYNAREC)
|
2016-08-08 00:31:21 +02:00
|
|
|
#include <psp2/kernel/sysmem.h>
|
|
|
|
static int translation_caches_inited = 0;
|
2016-08-08 13:13:22 +02:00
|
|
|
static inline int align(int x, int n) {
|
|
|
|
return (((x >> n) + 1) << n );
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FOUR_KB_ALIGN(x) align(x, 12)
|
|
|
|
#define MB_ALIGN(x) align(x, 20)
|
|
|
|
|
2016-10-03 20:19:11 +02:00
|
|
|
int _newlib_vm_size_user = ROM_TRANSLATION_CACHE_SIZE +
|
2021-03-17 18:33:02 +01:00
|
|
|
RAM_TRANSLATION_CACHE_SIZE;
|
2016-10-03 20:19:11 +02:00
|
|
|
|
|
|
|
int getVMBlock();
|
|
|
|
|
2016-08-08 00:31:21 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-13 03:43:42 +02:00
|
|
|
#if defined(_3DS)
|
|
|
|
void* linearMemAlign(size_t size, size_t alignment);
|
|
|
|
void linearFree(void* mem);
|
|
|
|
#if defined(HAVE_DYNAREC)
|
2015-11-04 15:46:27 +01:00
|
|
|
#include <malloc.h>
|
2015-09-11 23:02:04 +02:00
|
|
|
#include "3ds/3ds_utils.h"
|
|
|
|
#define MEMOP_PROT 6
|
2015-11-04 15:46:27 +01:00
|
|
|
#define MEMOP_MAP 4
|
|
|
|
#define MEMOP_UNMAP 5
|
2015-09-11 23:02:04 +02:00
|
|
|
int32_t svcDuplicateHandle(uint32_t* out, uint32_t original);
|
2015-09-27 15:47:06 +02:00
|
|
|
int32_t svcCloseHandle(uint32_t handle);
|
2015-09-11 23:02:04 +02:00
|
|
|
int32_t svcControlProcessMemory(uint32_t process, void* addr0, void* addr1, uint32_t size, uint32_t type, uint32_t perm);
|
2015-11-04 15:46:27 +01:00
|
|
|
static int translation_caches_inited = 0;
|
2015-04-08 11:20:32 +02:00
|
|
|
#endif
|
2015-04-13 03:43:42 +02:00
|
|
|
#endif
|
2015-04-08 11:20:32 +02:00
|
|
|
|
2014-12-09 00:17:28 +01:00
|
|
|
#ifndef MAX_PATH
|
|
|
|
#define MAX_PATH (512)
|
|
|
|
#endif
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2021-10-20 01:15:40 +02:00
|
|
|
// Usually 59.72750057 Hz, unless GBC_RATE is overclocked (for 60FPS)
|
2020-03-10 18:51:03 +01:00
|
|
|
#define GBA_FPS ((float) GBC_BASE_RATE) / (308 * 228 * 4)
|
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
static s16 *audio_sample_buffer = NULL;
|
|
|
|
static float audio_samples_per_frame = 0.0f;
|
|
|
|
static float audio_samples_accumulator = 0.0f;
|
2021-11-29 16:04:57 +01:00
|
|
|
|
|
|
|
/* Workaround for a RetroArch audio driver
|
|
|
|
* limitation: a maximum of 1024 frames
|
|
|
|
* can be written per call of audio_batch_cb() */
|
|
|
|
#define AUDIO_BATCH_FRAMES_MAX 1024
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
/* Maximum number of consecutive frames that
|
|
|
|
* can be skipped */
|
|
|
|
#define FRAMESKIP_MAX 30
|
|
|
|
|
|
|
|
u32 skip_next_frame = 0;
|
|
|
|
static frameskip_type current_frameskip_type = no_frameskip;
|
|
|
|
static u32 frameskip_threshold = 0;
|
|
|
|
static u32 frameskip_interval = 0;
|
|
|
|
static u32 frameskip_counter = 0;
|
|
|
|
static bool audio_buff_active = false;
|
|
|
|
static unsigned audio_buff_occupancy = 0;
|
|
|
|
static bool audio_buff_underrun = false;
|
|
|
|
static unsigned audio_latency = 0;
|
|
|
|
static bool update_audio_latency = false;
|
2021-03-22 21:45:52 +01:00
|
|
|
static bios_type selected_bios = auto_detect;
|
2020-03-10 18:51:03 +01:00
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
static retro_log_printf_t log_cb;
|
|
|
|
static retro_video_refresh_t video_cb;
|
2021-11-29 16:04:57 +01:00
|
|
|
static retro_audio_sample_batch_t audio_batch_cb;
|
2014-12-08 22:56:33 +01:00
|
|
|
static retro_input_poll_t input_poll_cb;
|
|
|
|
static retro_environment_t environ_cb;
|
2023-09-20 22:46:06 +02:00
|
|
|
static retro_set_rumble_state_t rumble_cb;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
struct retro_perf_callback perf_cb;
|
|
|
|
|
2014-12-10 17:06:09 +01:00
|
|
|
int dynarec_enable;
|
2021-03-22 21:45:52 +01:00
|
|
|
boot_mode selected_boot_mode = boot_game;
|
2023-09-01 23:57:57 +02:00
|
|
|
int sprite_limit = 1;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2023-09-20 22:46:06 +02:00
|
|
|
static int rtc_mode = FEAT_AUTODETECT, rumble_mode = FEAT_AUTODETECT;
|
|
|
|
|
2014-12-10 17:27:18 +01:00
|
|
|
u32 idle_loop_target_pc = 0xFFFFFFFF;
|
|
|
|
u32 translation_gate_target_pc[MAX_TRANSLATION_GATES];
|
|
|
|
u32 translation_gate_targets = 0;
|
|
|
|
|
2020-09-21 18:50:21 +02:00
|
|
|
static u16 *gba_screen_pixels_prev = NULL;
|
|
|
|
static u16 *gba_processed_pixels = NULL;
|
|
|
|
|
|
|
|
static void (*video_post_process)(void) = NULL;
|
|
|
|
static bool post_process_cc = false;
|
|
|
|
static bool post_process_mix = false;
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
static void error_msg(const char* text)
|
|
|
|
{
|
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_ERROR, "[gpSP]: %s\n", text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void info_msg(const char* text)
|
|
|
|
{
|
|
|
|
if (log_cb)
|
|
|
|
log_cb(RETRO_LOG_INFO, "[gpSP]: %s\n", text);
|
|
|
|
}
|
|
|
|
|
2021-03-22 21:45:52 +01:00
|
|
|
static void show_warning_message(const char* text, unsigned durationms) {
|
|
|
|
unsigned ifversion = 0;
|
|
|
|
if (!environ_cb(RETRO_ENVIRONMENT_GET_MESSAGE_INTERFACE_VERSION, &ifversion) || ifversion >= 1) {
|
|
|
|
/* Use the new API to display messages */
|
|
|
|
struct retro_message_ext msg = {
|
|
|
|
.msg = text, .duration = durationms,
|
|
|
|
.priority = 2, .level = RETRO_LOG_WARN,
|
|
|
|
.target = RETRO_MESSAGE_TARGET_ALL,
|
|
|
|
.type = RETRO_MESSAGE_TYPE_NOTIFICATION,
|
|
|
|
.progress = -1,
|
|
|
|
};
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct retro_message msg = {.msg = text, .frames = durationms / 17};
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-24 06:11:20 +01:00
|
|
|
static void set_screen_pixels() {
|
|
|
|
struct retro_framebuffer fbufr;
|
|
|
|
fbufr.width = GBA_SCREEN_WIDTH;
|
|
|
|
fbufr.height = GBA_SCREEN_HEIGHT;
|
|
|
|
fbufr.access_flags = RETRO_MEMORY_ACCESS_WRITE | RETRO_MEMORY_ACCESS_READ;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fbufr)) {
|
|
|
|
gba_screen_pixels = fbufr.data;
|
|
|
|
gba_screen_pitch = fbufr.pitch / sizeof(uint16_t);
|
|
|
|
} else if (!gba_screen_pixels) {
|
|
|
|
gba_screen_pitch = GBA_SCREEN_WIDTH;
|
|
|
|
#ifdef _3DS
|
|
|
|
gba_screen_pixels = (uint16_t*)linearMemAlign(GBA_SCREEN_BUFFER_SIZE, 128);
|
|
|
|
#else
|
|
|
|
gba_screen_pixels = (uint16_t*)malloc(GBA_SCREEN_BUFFER_SIZE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
/* Frameskip START */
|
|
|
|
|
|
|
|
static void audio_buff_status_cb(
|
|
|
|
bool active, unsigned occupancy, bool underrun_likely)
|
|
|
|
{
|
|
|
|
audio_buff_active = active;
|
|
|
|
audio_buff_occupancy = occupancy;
|
|
|
|
audio_buff_underrun = underrun_likely;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_frameskip(void)
|
|
|
|
{
|
|
|
|
if (current_frameskip_type == no_frameskip)
|
|
|
|
{
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL);
|
|
|
|
audio_latency = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool calculate_audio_latency = true;
|
|
|
|
|
|
|
|
if (current_frameskip_type == fixed_interval_frameskip)
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct retro_audio_buffer_status_callback buff_status_cb;
|
|
|
|
buff_status_cb.callback = audio_buff_status_cb;
|
|
|
|
|
|
|
|
if (!environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, &buff_status_cb))
|
|
|
|
{
|
|
|
|
error_msg("Frameskip disabled - frontend does not support audio buffer status monitoring");
|
|
|
|
|
|
|
|
audio_buff_active = false;
|
|
|
|
audio_buff_occupancy = 0;
|
|
|
|
audio_buff_underrun = false;
|
|
|
|
audio_latency = 0;
|
|
|
|
calculate_audio_latency = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calculate_audio_latency)
|
|
|
|
{
|
|
|
|
/* Frameskip is enabled - increase frontend
|
|
|
|
* audio latency to minimise potential
|
|
|
|
* buffer underruns */
|
|
|
|
float frame_time_msec = 1000.0f / ((float) GBA_FPS);
|
|
|
|
|
|
|
|
/* Set latency to 6x current frame time... */
|
|
|
|
audio_latency = (unsigned)((6.0f * frame_time_msec) + 0.5f);
|
|
|
|
|
|
|
|
/* ...then round up to nearest multiple of 32 */
|
|
|
|
audio_latency = (audio_latency + 0x1F) & ~0x1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
update_audio_latency = true;
|
|
|
|
frameskip_counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Frameskip END */
|
|
|
|
|
2020-09-21 18:50:21 +02:00
|
|
|
/* Video post processing START */
|
|
|
|
|
|
|
|
/* Note: This code is intentionally W.E.T.
|
|
|
|
* (Write Everything Twice). These functions
|
|
|
|
* are performance critical, and we cannot
|
|
|
|
* afford to do unnecessary comparisons/switches
|
|
|
|
* inside the inner for loops */
|
|
|
|
|
|
|
|
static void video_post_process_cc(void)
|
|
|
|
{
|
|
|
|
uint16_t *src = gba_screen_pixels;
|
|
|
|
uint16_t *dst = gba_processed_pixels;
|
|
|
|
size_t x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < GBA_SCREEN_HEIGHT; y++)
|
|
|
|
{
|
2023-12-24 06:11:20 +01:00
|
|
|
for (x = 0; x < gba_screen_pitch; x++)
|
2020-09-21 18:50:21 +02:00
|
|
|
{
|
|
|
|
u16 src_color = *(src + x);
|
|
|
|
|
|
|
|
/* Convert colour to RGB555 and perform lookup */
|
|
|
|
*(dst + x) = *(gba_cc_lut + (((src_color & 0xFFC0) >> 1) | (src_color & 0x1F)));
|
|
|
|
}
|
|
|
|
|
2023-12-24 06:11:20 +01:00
|
|
|
src += gba_screen_pitch;
|
|
|
|
dst += gba_screen_pitch;
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void video_post_process_mix(void)
|
|
|
|
{
|
|
|
|
uint16_t *src_curr = gba_screen_pixels;
|
|
|
|
uint16_t *src_prev = gba_screen_pixels_prev;
|
|
|
|
uint16_t *dst = gba_processed_pixels;
|
|
|
|
size_t x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < GBA_SCREEN_HEIGHT; y++)
|
|
|
|
{
|
2023-12-24 06:11:20 +01:00
|
|
|
for (x = 0; x < gba_screen_pitch; x++)
|
2020-09-21 18:50:21 +02:00
|
|
|
{
|
|
|
|
/* Get colours from current + previous frames (RGB565) */
|
|
|
|
uint16_t rgb_curr = *(src_curr + x);
|
|
|
|
uint16_t rgb_prev = *(src_prev + x);
|
|
|
|
|
|
|
|
/* Store colours for next frame */
|
|
|
|
*(src_prev + x) = rgb_curr;
|
|
|
|
|
2020-11-09 14:04:00 +01:00
|
|
|
/* Mix colours
|
|
|
|
* > "Mixing Packed RGB Pixels Efficiently"
|
|
|
|
* http://blargg.8bitalley.com/info/rgb_mixing.html */
|
|
|
|
*(dst + x) = (rgb_curr + rgb_prev + ((rgb_curr ^ rgb_prev) & 0x821)) >> 1;
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
|
2023-12-24 06:11:20 +01:00
|
|
|
src_curr += gba_screen_pitch;
|
|
|
|
src_prev += gba_screen_pitch;
|
|
|
|
dst += gba_screen_pitch;
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void video_post_process_cc_mix(void)
|
|
|
|
{
|
|
|
|
uint16_t *src_curr = gba_screen_pixels;
|
|
|
|
uint16_t *src_prev = gba_screen_pixels_prev;
|
|
|
|
uint16_t *dst = gba_processed_pixels;
|
|
|
|
size_t x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < GBA_SCREEN_HEIGHT; y++)
|
|
|
|
{
|
2023-12-24 06:11:20 +01:00
|
|
|
for (x = 0; x < gba_screen_pitch; x++)
|
2020-09-21 18:50:21 +02:00
|
|
|
{
|
|
|
|
/* Get colours from current + previous frames (RGB565) */
|
|
|
|
uint16_t rgb_curr = *(src_curr + x);
|
|
|
|
uint16_t rgb_prev = *(src_prev + x);
|
|
|
|
|
|
|
|
/* Store colours for next frame */
|
|
|
|
*(src_prev + x) = rgb_curr;
|
|
|
|
|
2020-11-09 14:04:00 +01:00
|
|
|
/* Mix colours
|
|
|
|
* > "Mixing Packed RGB Pixels Efficiently"
|
|
|
|
* http://blargg.8bitalley.com/info/rgb_mixing.html */
|
|
|
|
uint16_t rgb_mix = (rgb_curr + rgb_prev + ((rgb_curr ^ rgb_prev) & 0x821)) >> 1;
|
2020-09-21 18:50:21 +02:00
|
|
|
|
2020-11-09 14:04:00 +01:00
|
|
|
/* Convert colour to RGB555 and perform lookup */
|
|
|
|
*(dst + x) = *(gba_cc_lut + (((rgb_mix & 0xFFC0) >> 1) | (rgb_mix & 0x1F)));
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
|
2023-12-24 06:11:20 +01:00
|
|
|
src_curr += gba_screen_pitch;
|
|
|
|
src_prev += gba_screen_pitch;
|
|
|
|
dst += gba_screen_pitch;
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_post_processing(void)
|
|
|
|
{
|
|
|
|
video_post_process = NULL;
|
|
|
|
|
|
|
|
/* If post processing is disabled, return
|
|
|
|
* immediately */
|
|
|
|
if (!post_process_cc && !post_process_mix)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Initialise output buffer, if required */
|
|
|
|
if (!gba_processed_pixels &&
|
|
|
|
(post_process_cc || post_process_mix))
|
|
|
|
{
|
|
|
|
#ifdef _3DS
|
2023-07-28 19:35:33 +02:00
|
|
|
gba_processed_pixels = (u16*)linearMemAlign(GBA_SCREEN_BUFFER_SIZE, 128);
|
2020-09-21 18:50:21 +02:00
|
|
|
#else
|
2023-07-28 19:35:33 +02:00
|
|
|
gba_processed_pixels = (u16*)malloc(GBA_SCREEN_BUFFER_SIZE);
|
2020-09-21 18:50:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!gba_processed_pixels)
|
|
|
|
return;
|
|
|
|
|
2023-07-28 19:35:33 +02:00
|
|
|
memset(gba_processed_pixels, 0xFFFF, GBA_SCREEN_BUFFER_SIZE);
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialise 'history' buffer, if required */
|
|
|
|
if (!gba_screen_pixels_prev &&
|
|
|
|
post_process_mix)
|
|
|
|
{
|
2023-07-28 19:35:33 +02:00
|
|
|
gba_screen_pixels_prev = (u16*)malloc(GBA_SCREEN_BUFFER_SIZE);
|
2020-09-21 18:50:21 +02:00
|
|
|
|
|
|
|
if (!gba_screen_pixels_prev)
|
|
|
|
return;
|
|
|
|
|
2023-07-28 19:35:33 +02:00
|
|
|
memset(gba_screen_pixels_prev, 0xFFFF, GBA_SCREEN_BUFFER_SIZE);
|
2020-09-21 18:50:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign post processing function */
|
|
|
|
if (post_process_cc && post_process_mix)
|
|
|
|
video_post_process = video_post_process_cc_mix;
|
|
|
|
else if (post_process_cc)
|
|
|
|
video_post_process = video_post_process_cc;
|
|
|
|
else if (post_process_mix)
|
|
|
|
video_post_process = video_post_process_mix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Video post processing END */
|
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
/* Fast forward override */
|
|
|
|
void set_fastforward_override(bool fastforward)
|
|
|
|
{
|
|
|
|
struct retro_fastforwarding_override ff_override;
|
|
|
|
|
|
|
|
if (!libretro_supports_ff_override)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ff_override.ratio = -1.0f;
|
|
|
|
ff_override.notification = true;
|
|
|
|
|
|
|
|
if (fastforward)
|
|
|
|
{
|
|
|
|
ff_override.fastforward = true;
|
|
|
|
ff_override.inhibit_toggle = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ff_override.fastforward = false;
|
|
|
|
ff_override.inhibit_toggle = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERRIDE, &ff_override);
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:04:57 +01:00
|
|
|
static void audio_run(void)
|
|
|
|
{
|
2021-11-29 18:45:06 +01:00
|
|
|
s16 *audio_buffer_ptr;
|
|
|
|
u32 samples_to_read;
|
|
|
|
u32 samples_produced;
|
2021-11-29 16:04:57 +01:00
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
/* audio_samples_per_frame is decimal;
|
|
|
|
* get integer component */
|
|
|
|
samples_to_read = (u32)audio_samples_per_frame;
|
|
|
|
|
|
|
|
/* Account for fractional component */
|
|
|
|
audio_samples_accumulator += audio_samples_per_frame -
|
|
|
|
(float)samples_to_read;
|
|
|
|
|
|
|
|
if (audio_samples_accumulator >= 1.0f)
|
2021-11-29 16:04:57 +01:00
|
|
|
{
|
2021-11-29 18:45:06 +01:00
|
|
|
samples_to_read++;
|
|
|
|
audio_samples_accumulator -= 1.0f;
|
|
|
|
}
|
2021-11-29 16:04:57 +01:00
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
samples_produced = sound_read_samples(audio_sample_buffer, samples_to_read);
|
2021-11-29 16:04:57 +01:00
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
/* Workaround for a RetroArch audio driver
|
|
|
|
* limitation: a maximum of 1024 frames
|
|
|
|
* can be written per call of audio_batch_cb(),
|
|
|
|
* so we have to send samples in chunks */
|
|
|
|
audio_buffer_ptr = audio_sample_buffer;
|
|
|
|
while (samples_produced > 0)
|
|
|
|
{
|
|
|
|
u32 samples_to_write = (samples_produced > AUDIO_BATCH_FRAMES_MAX) ?
|
|
|
|
AUDIO_BATCH_FRAMES_MAX : samples_produced;
|
2021-11-29 16:04:57 +01:00
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
audio_batch_cb(audio_buffer_ptr, samples_to_write);
|
2021-11-29 16:04:57 +01:00
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
samples_produced -= samples_to_write;
|
|
|
|
audio_buffer_ptr += samples_to_write << 1;
|
2021-11-29 16:04:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
static void video_run(void)
|
|
|
|
{
|
2020-09-21 18:50:21 +02:00
|
|
|
u16 *gba_screen_pixels_buf = gba_screen_pixels;
|
2020-10-24 15:58:40 +02:00
|
|
|
|
|
|
|
if (skip_next_frame)
|
|
|
|
{
|
|
|
|
video_cb(NULL, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT,
|
2023-12-24 06:11:20 +01:00
|
|
|
gba_screen_pitch * 2);
|
2020-10-24 15:58:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-21 18:50:21 +02:00
|
|
|
if (video_post_process)
|
|
|
|
{
|
|
|
|
video_post_process();
|
|
|
|
gba_screen_pixels_buf = gba_processed_pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
video_cb(gba_screen_pixels_buf, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT,
|
2023-12-24 06:11:20 +01:00
|
|
|
gba_screen_pitch * 2);
|
|
|
|
set_screen_pixels();
|
2019-11-23 17:34:35 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 00:17:28 +01:00
|
|
|
#ifdef PERF_TEST
|
|
|
|
|
|
|
|
extern struct retro_perf_callback perf_cb;
|
|
|
|
|
|
|
|
#define RETRO_PERFORMANCE_INIT(X) \
|
|
|
|
static struct retro_perf_counter X = {#X}; \
|
|
|
|
do { \
|
|
|
|
if (!(X).registered) \
|
|
|
|
perf_cb.perf_register(&(X)); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define RETRO_PERFORMANCE_START(X) perf_cb.perf_start(&(X))
|
|
|
|
#define RETRO_PERFORMANCE_STOP(X) perf_cb.perf_stop(&(X))
|
|
|
|
#else
|
|
|
|
#define RETRO_PERFORMANCE_INIT(X)
|
|
|
|
#define RETRO_PERFORMANCE_START(X)
|
|
|
|
#define RETRO_PERFORMANCE_STOP(X)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void retro_get_system_info(struct retro_system_info* info)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2014-12-09 10:18:05 +01:00
|
|
|
info->library_name = "gpSP";
|
2016-12-10 00:42:12 +01:00
|
|
|
#ifndef GIT_VERSION
|
|
|
|
#define GIT_VERSION ""
|
|
|
|
#endif
|
|
|
|
info->library_version = "v0.91" GIT_VERSION;
|
2014-12-08 22:56:33 +01:00
|
|
|
info->need_fullpath = true;
|
|
|
|
info->block_extract = false;
|
2023-07-31 16:46:12 +02:00
|
|
|
info->valid_extensions = "gba|bin|agb|gbz|u1" ;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void retro_get_system_av_info(struct retro_system_av_info* info)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
info->geometry.base_width = GBA_SCREEN_WIDTH;
|
|
|
|
info->geometry.base_height = GBA_SCREEN_HEIGHT;
|
|
|
|
info->geometry.max_width = GBA_SCREEN_WIDTH;
|
|
|
|
info->geometry.max_height = GBA_SCREEN_HEIGHT;
|
2023-01-09 04:21:23 +01:00
|
|
|
info->geometry.aspect_ratio = 3.0f / 2.0f;
|
2020-03-10 18:51:03 +01:00
|
|
|
info->timing.fps = ((float) GBA_FPS);
|
2014-12-09 05:36:30 +01:00
|
|
|
info->timing.sample_rate = GBA_SOUND_FREQUENCY;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
void retro_init(void)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2021-11-29 18:45:06 +01:00
|
|
|
u32 audio_sample_buffer_size;
|
|
|
|
audio_samples_per_frame = (float)(GBA_SOUND_FREQUENCY) / (float)(GBA_FPS);
|
|
|
|
audio_samples_accumulator = 0.0f;
|
|
|
|
audio_sample_buffer_size = ((u32)audio_samples_per_frame + 1) * 2;
|
|
|
|
audio_sample_buffer = (s16*)malloc(audio_sample_buffer_size * sizeof(s16));
|
2021-11-29 16:04:57 +01:00
|
|
|
|
2021-03-17 21:05:49 +01:00
|
|
|
#if defined(HAVE_DYNAREC)
|
2021-11-05 18:23:05 +01:00
|
|
|
#if defined(MMAP_JIT_CACHE)
|
|
|
|
rom_translation_cache = map_jit_block(ROM_TRANSLATION_CACHE_SIZE + RAM_TRANSLATION_CACHE_SIZE);
|
2021-10-29 22:51:39 +02:00
|
|
|
ram_translation_cache = &rom_translation_cache[ROM_TRANSLATION_CACHE_SIZE];
|
2021-03-17 21:05:49 +01:00
|
|
|
#elif defined(_3DS)
|
2015-11-04 15:46:27 +01:00
|
|
|
if (__ctr_svchax && !translation_caches_inited)
|
2015-04-08 11:20:32 +02:00
|
|
|
{
|
2015-09-11 23:02:04 +02:00
|
|
|
uint32_t currentHandle;
|
2020-02-29 19:50:30 +01:00
|
|
|
check_rosalina();
|
|
|
|
|
2015-11-04 15:46:27 +01:00
|
|
|
rom_translation_cache_ptr = memalign(0x1000, ROM_TRANSLATION_CACHE_SIZE);
|
|
|
|
ram_translation_cache_ptr = memalign(0x1000, RAM_TRANSLATION_CACHE_SIZE);
|
|
|
|
|
2015-09-11 23:02:04 +02:00
|
|
|
svcDuplicateHandle(¤tHandle, 0xFFFF8001);
|
2015-11-04 15:46:27 +01:00
|
|
|
svcControlProcessMemory(currentHandle,
|
|
|
|
rom_translation_cache, rom_translation_cache_ptr,
|
|
|
|
ROM_TRANSLATION_CACHE_SIZE, MEMOP_MAP, 0b111);
|
|
|
|
svcControlProcessMemory(currentHandle,
|
|
|
|
ram_translation_cache, ram_translation_cache_ptr,
|
|
|
|
RAM_TRANSLATION_CACHE_SIZE, MEMOP_MAP, 0b111);
|
2015-09-27 15:47:06 +02:00
|
|
|
svcCloseHandle(currentHandle);
|
2015-11-04 15:46:27 +01:00
|
|
|
rom_translation_ptr = rom_translation_cache;
|
|
|
|
ram_translation_ptr = ram_translation_cache;
|
2015-09-11 23:02:04 +02:00
|
|
|
ctr_flush_invalidate_cache();
|
2015-11-04 15:46:27 +01:00
|
|
|
translation_caches_inited = 1;
|
2015-04-08 11:20:32 +02:00
|
|
|
}
|
2021-03-17 21:05:49 +01:00
|
|
|
#elif defined(VITA)
|
|
|
|
if(!translation_caches_inited){
|
2016-08-08 00:31:21 +02:00
|
|
|
void* currentHandle;
|
|
|
|
|
2016-10-03 20:19:11 +02:00
|
|
|
sceBlock = getVMBlock();
|
|
|
|
|
2016-08-08 00:31:21 +02:00
|
|
|
if (sceBlock < 0)
|
|
|
|
{
|
2016-08-08 13:13:22 +02:00
|
|
|
return;
|
2016-08-08 00:31:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// get base address
|
|
|
|
int ret = sceKernelGetMemBlockBase(sceBlock, ¤tHandle);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-08-08 13:13:22 +02:00
|
|
|
return;
|
2016-08-08 00:31:21 +02:00
|
|
|
}
|
2016-08-08 13:13:22 +02:00
|
|
|
|
2016-08-08 00:31:21 +02:00
|
|
|
rom_translation_cache = (u8*)currentHandle;
|
|
|
|
ram_translation_cache = rom_translation_cache + ROM_TRANSLATION_CACHE_SIZE;
|
|
|
|
rom_translation_ptr = rom_translation_cache;
|
|
|
|
ram_translation_ptr = ram_translation_cache;
|
2016-10-04 09:32:54 +02:00
|
|
|
sceKernelOpenVMDomain();
|
2016-08-08 00:31:21 +02:00
|
|
|
translation_caches_inited = 1;
|
2021-03-17 21:05:49 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-04-08 11:20:32 +02:00
|
|
|
#endif
|
2014-12-09 09:54:33 +01:00
|
|
|
|
2021-07-14 01:17:55 +02:00
|
|
|
init_gamepak_buffer();
|
2023-06-12 20:24:18 +02:00
|
|
|
init_sound();
|
2015-11-04 15:46:27 +01:00
|
|
|
|
2023-12-24 06:11:20 +01:00
|
|
|
set_screen_pixels();
|
2015-04-13 03:43:42 +02:00
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
libretro_supports_bitmasks = false;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
|
|
|
|
libretro_supports_bitmasks = true;
|
|
|
|
|
|
|
|
libretro_supports_ff_override = false;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERRIDE, NULL))
|
|
|
|
libretro_supports_ff_override = true;
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
current_frameskip_type = no_frameskip;
|
|
|
|
frameskip_threshold = 0;
|
|
|
|
frameskip_interval = 0;
|
|
|
|
frameskip_counter = 0;
|
|
|
|
audio_buff_active = false;
|
|
|
|
audio_buff_occupancy = 0;
|
|
|
|
audio_buff_underrun = false;
|
|
|
|
audio_latency = 0;
|
|
|
|
update_audio_latency = false;
|
2021-03-22 21:45:52 +01:00
|
|
|
selected_bios = auto_detect;
|
|
|
|
selected_boot_mode = boot_game;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
void retro_deinit(void)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
perf_cb.perf_log();
|
2014-12-09 00:17:28 +01:00
|
|
|
memory_term();
|
2014-12-09 09:54:33 +01:00
|
|
|
|
2021-11-05 18:23:05 +01:00
|
|
|
#if defined(MMAP_JIT_CACHE) && defined(HAVE_DYNAREC)
|
|
|
|
unmap_jit_block(rom_translation_cache, ROM_TRANSLATION_CACHE_SIZE + RAM_TRANSLATION_CACHE_SIZE);
|
2014-12-10 12:29:19 +01:00
|
|
|
#endif
|
2015-04-08 11:20:32 +02:00
|
|
|
#if defined(_3DS) && defined(HAVE_DYNAREC)
|
2015-11-04 15:46:27 +01:00
|
|
|
|
|
|
|
if (__ctr_svchax && translation_caches_inited)
|
|
|
|
{
|
|
|
|
uint32_t currentHandle;
|
|
|
|
svcDuplicateHandle(¤tHandle, 0xFFFF8001);
|
|
|
|
svcControlProcessMemory(currentHandle,
|
|
|
|
rom_translation_cache, rom_translation_cache_ptr,
|
|
|
|
ROM_TRANSLATION_CACHE_SIZE, MEMOP_UNMAP, 0b111);
|
|
|
|
svcControlProcessMemory(currentHandle,
|
|
|
|
ram_translation_cache, ram_translation_cache_ptr,
|
|
|
|
RAM_TRANSLATION_CACHE_SIZE, MEMOP_UNMAP, 0b111);
|
|
|
|
svcCloseHandle(currentHandle);
|
|
|
|
free(rom_translation_cache_ptr);
|
|
|
|
free(ram_translation_cache_ptr);
|
|
|
|
translation_caches_inited = 0;
|
|
|
|
}
|
2015-04-08 11:20:32 +02:00
|
|
|
#endif
|
2016-08-08 00:31:21 +02:00
|
|
|
|
2016-08-14 18:28:25 +02:00
|
|
|
#if defined(VITA) && defined(HAVE_DYNAREC)
|
2016-08-08 00:31:21 +02:00
|
|
|
if(translation_caches_inited){
|
2016-10-03 20:19:11 +02:00
|
|
|
translation_caches_inited = 0;
|
2016-08-08 00:31:21 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-13 03:43:42 +02:00
|
|
|
#ifdef _3DS
|
|
|
|
linearFree(gba_screen_pixels);
|
2020-09-21 18:50:21 +02:00
|
|
|
if (gba_processed_pixels)
|
|
|
|
linearFree(gba_processed_pixels);
|
2015-04-13 03:43:42 +02:00
|
|
|
#else
|
|
|
|
free(gba_screen_pixels);
|
2020-09-21 18:50:21 +02:00
|
|
|
if (gba_processed_pixels)
|
|
|
|
free(gba_processed_pixels);
|
2015-04-13 03:43:42 +02:00
|
|
|
#endif
|
2020-09-21 18:50:21 +02:00
|
|
|
if (gba_screen_pixels_prev)
|
|
|
|
free(gba_screen_pixels_prev);
|
|
|
|
|
|
|
|
gba_screen_pixels = NULL;
|
|
|
|
gba_processed_pixels = NULL;
|
|
|
|
gba_screen_pixels_prev = NULL;
|
|
|
|
video_post_process = NULL;
|
2021-03-16 14:14:21 +01:00
|
|
|
post_process_cc = false;
|
|
|
|
post_process_mix = false;
|
2021-11-29 16:04:57 +01:00
|
|
|
|
|
|
|
if (audio_sample_buffer)
|
|
|
|
free(audio_sample_buffer);
|
|
|
|
|
2021-11-29 18:45:06 +01:00
|
|
|
audio_sample_buffer = NULL;
|
|
|
|
audio_samples_per_frame = 0.0f;
|
|
|
|
audio_samples_accumulator = 0.0f;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-11 23:21:07 +01:00
|
|
|
static retro_time_t retro_perf_dummy_get_time_usec() { return 0; }
|
|
|
|
static retro_perf_tick_t retro_perf_dummy_get_counter() { return 0; }
|
|
|
|
static uint64_t retro_perf_dummy_get_cpu_features() { return 0; }
|
|
|
|
static void retro_perf_dummy_log() {}
|
|
|
|
static void retro_perf_dummy_counter(struct retro_perf_counter *counter) {};
|
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
void retro_set_environment(retro_environment_t cb)
|
|
|
|
{
|
|
|
|
struct retro_log_callback log;
|
2021-09-30 18:31:11 +02:00
|
|
|
struct retro_vfs_interface_info vfs_iface_info;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
environ_cb = cb;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
|
|
|
|
log_cb = log.log;
|
|
|
|
else
|
|
|
|
log_cb = NULL;
|
|
|
|
|
2014-12-11 23:21:07 +01:00
|
|
|
perf_cb = (struct retro_perf_callback){
|
|
|
|
retro_perf_dummy_get_time_usec,
|
|
|
|
retro_perf_dummy_get_counter,
|
|
|
|
retro_perf_dummy_get_cpu_features,
|
|
|
|
retro_perf_dummy_counter,
|
|
|
|
retro_perf_dummy_counter,
|
|
|
|
retro_perf_dummy_counter,
|
|
|
|
retro_perf_dummy_log,
|
|
|
|
};
|
2014-12-08 22:56:33 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb);
|
2020-09-21 18:50:21 +02:00
|
|
|
|
2023-01-30 19:39:52 +01:00
|
|
|
vfs_iface_info.required_interface_version = 2;
|
2021-09-30 18:31:11 +02:00
|
|
|
vfs_iface_info.iface = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info))
|
|
|
|
filestream_vfs_init(&vfs_iface_info);
|
|
|
|
|
2020-09-21 18:50:21 +02:00
|
|
|
libretro_set_core_options(environ_cb);
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void retro_set_video_refresh(retro_video_refresh_t cb)
|
|
|
|
{
|
|
|
|
video_cb = cb;
|
|
|
|
}
|
2021-11-29 16:04:57 +01:00
|
|
|
|
|
|
|
void retro_set_audio_sample(retro_audio_sample_t cb) { }
|
|
|
|
|
|
|
|
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb)
|
|
|
|
{
|
|
|
|
audio_batch_cb = cb;
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void retro_set_input_poll(retro_input_poll_t cb)
|
|
|
|
{
|
|
|
|
input_poll_cb = cb;
|
|
|
|
}
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
void retro_set_controller_port_device(unsigned port, unsigned device) {}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
void retro_reset(void)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
reset_gba();
|
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
size_t retro_serialize_size(void)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2014-12-10 11:06:17 +01:00
|
|
|
return GBA_STATE_MEM_SIZE;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
bool retro_serialize(void* data, size_t size)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2014-12-10 11:06:17 +01:00
|
|
|
if (size != GBA_STATE_MEM_SIZE)
|
|
|
|
return false;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-10 11:06:17 +01:00
|
|
|
memset (data,0, GBA_STATE_MEM_SIZE);
|
|
|
|
gba_save_state(data);
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-10 11:06:17 +01:00
|
|
|
return true;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
bool retro_unserialize(const void* data, size_t size)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2014-12-10 11:06:17 +01:00
|
|
|
if (size != GBA_STATE_MEM_SIZE)
|
|
|
|
return false;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2021-08-24 17:15:27 +02:00
|
|
|
return gba_load_state(data);
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
void retro_cheat_reset(void)
|
|
|
|
{
|
2021-05-05 02:20:00 +02:00
|
|
|
cheat_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_cheat_set(unsigned index, bool enabled, const char* code)
|
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
|
|
|
|
2021-05-05 18:07:55 +02:00
|
|
|
switch (cheat_parse(index, code))
|
|
|
|
{
|
|
|
|
case CheatErrorTooMany:
|
|
|
|
show_warning_message("Too many active cheats!", 2500);
|
|
|
|
break;
|
|
|
|
case CheatErrorTooBig:
|
|
|
|
show_warning_message("Cheats are too big!", 2500);
|
|
|
|
break;
|
|
|
|
case CheatErrorEncrypted:
|
|
|
|
show_warning_message("Encrypted cheats are not supported!", 2500);
|
|
|
|
break;
|
|
|
|
case CheatErrorNotSupported:
|
|
|
|
show_warning_message("Cheat type is not supported!", 2500);
|
|
|
|
break;
|
|
|
|
case CheatNoError:
|
|
|
|
break;
|
|
|
|
};
|
2014-12-10 17:48:43 +01:00
|
|
|
}
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
static void extract_directory(char* buf, const char* path, size_t size)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
strncpy(buf, path, size - 1);
|
|
|
|
buf[size - 1] = '\0';
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
char* base = strrchr(buf, '/');
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
if (base)
|
|
|
|
*base = '\0';
|
|
|
|
else
|
|
|
|
strncpy(buf, ".", size);
|
|
|
|
}
|
|
|
|
|
2023-09-20 22:46:06 +02:00
|
|
|
static void check_variables(bool started_from_load)
|
2014-12-10 17:48:43 +01:00
|
|
|
{
|
|
|
|
struct retro_variable var;
|
2020-10-24 15:58:40 +02:00
|
|
|
bool frameskip_type_prev;
|
2020-09-21 18:50:21 +02:00
|
|
|
bool post_process_cc_prev;
|
|
|
|
bool post_process_mix_prev;
|
2014-12-10 17:48:43 +01:00
|
|
|
|
2019-11-11 20:03:13 +01:00
|
|
|
#ifdef HAVE_DYNAREC
|
2014-12-10 17:48:43 +01:00
|
|
|
var.key = "gpsp_drc";
|
|
|
|
var.value = NULL;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
2021-03-17 21:05:49 +01:00
|
|
|
int prevvalue = dynarec_enable;
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
dynarec_enable = 0;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
dynarec_enable = 1;
|
|
|
|
|
2023-06-09 20:21:35 +02:00
|
|
|
/* Flush dynarec cache to ensure we do not execute old code */
|
2021-03-17 21:05:49 +01:00
|
|
|
if (dynarec_enable != prevvalue)
|
2023-06-09 20:21:35 +02:00
|
|
|
flush_dynarec_caches();
|
2014-12-10 17:48:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
dynarec_enable = 1;
|
2021-03-17 21:05:49 +01:00
|
|
|
#else
|
|
|
|
dynarec_enable = 0;
|
2014-12-10 17:48:43 +01:00
|
|
|
#endif
|
2019-11-11 20:03:13 +01:00
|
|
|
|
2021-03-22 21:45:52 +01:00
|
|
|
if (started_from_load) {
|
|
|
|
var.key = "gpsp_bios";
|
|
|
|
var.value = 0;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (!strcmp(var.value, "auto"))
|
|
|
|
selected_bios = auto_detect;
|
|
|
|
else if (!strcmp(var.value, "builtin"))
|
|
|
|
selected_bios = builtin_bios;
|
|
|
|
else if (!strcmp(var.value, "official"))
|
|
|
|
selected_bios = official_bios;
|
|
|
|
}
|
|
|
|
|
|
|
|
var.key = "gpsp_boot_mode";
|
|
|
|
var.value = 0;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (!strcmp(var.value, "game"))
|
|
|
|
selected_boot_mode = boot_game;
|
|
|
|
else if (!strcmp(var.value, "bios"))
|
|
|
|
selected_boot_mode = boot_bios;
|
|
|
|
}
|
2023-09-20 22:46:06 +02:00
|
|
|
|
|
|
|
var.key = "gpsp_rtc";
|
|
|
|
var.value = 0;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (!strcmp(var.value, "disabled"))
|
|
|
|
rtc_mode = FEAT_DISABLE;
|
|
|
|
else if (!strcmp(var.value, "enabled"))
|
|
|
|
rtc_mode = FEAT_ENABLE;
|
|
|
|
else
|
|
|
|
rtc_mode = FEAT_AUTODETECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
var.key = "gpsp_rumble";
|
|
|
|
var.value = 0;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (!strcmp(var.value, "disabled"))
|
|
|
|
rumble_mode = FEAT_DISABLE;
|
|
|
|
else if (!strcmp(var.value, "enabled"))
|
|
|
|
rumble_mode = FEAT_ENABLE;
|
|
|
|
else
|
|
|
|
rumble_mode = FEAT_AUTODETECT;
|
|
|
|
}
|
2021-03-22 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2023-09-01 23:57:57 +02:00
|
|
|
var.key = "gpsp_sprlim";
|
|
|
|
var.value = 0;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
sprite_limit = 1;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
sprite_limit = 0;
|
|
|
|
}
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
var.key = "gpsp_frameskip";
|
|
|
|
var.value = 0;
|
|
|
|
frameskip_type_prev = current_frameskip_type;
|
|
|
|
current_frameskip_type = no_frameskip;
|
2019-11-11 20:03:13 +01:00
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
2020-10-24 15:58:40 +02:00
|
|
|
if (!strcmp(var.value, "auto"))
|
2020-03-10 18:51:03 +01:00
|
|
|
current_frameskip_type = auto_frameskip;
|
2020-10-24 15:58:40 +02:00
|
|
|
else if (!strcmp(var.value, "auto_threshold"))
|
|
|
|
current_frameskip_type = auto_threshold_frameskip;
|
|
|
|
else if (!strcmp(var.value, "fixed_interval"))
|
|
|
|
current_frameskip_type = fixed_interval_frameskip;
|
2019-11-11 20:03:13 +01:00
|
|
|
}
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
var.key = "gpsp_frameskip_threshold";
|
|
|
|
var.value = 0;
|
|
|
|
frameskip_threshold = 33;
|
|
|
|
|
2019-11-11 20:03:13 +01:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
2020-10-24 15:58:40 +02:00
|
|
|
frameskip_threshold = strtol(var.value, NULL, 10);
|
|
|
|
|
|
|
|
var.key = "gpsp_frameskip_interval";
|
|
|
|
var.value = 0;
|
|
|
|
|
|
|
|
frameskip_interval = 0;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
frameskip_interval = strtol(var.value, NULL, 10);
|
|
|
|
|
|
|
|
/* (Re)Initialise frame skipping, if required */
|
|
|
|
if (started_from_load ||
|
|
|
|
(current_frameskip_type != frameskip_type_prev))
|
|
|
|
init_frameskip();
|
2020-09-05 14:40:15 +02:00
|
|
|
|
2020-09-21 18:50:21 +02:00
|
|
|
var.key = "gpsp_color_correction";
|
|
|
|
var.value = NULL;
|
|
|
|
post_process_cc_prev = post_process_cc;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
post_process_cc = false;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
post_process_cc = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var.key = "gpsp_frame_mixing";
|
|
|
|
var.value = NULL;
|
|
|
|
post_process_mix_prev = post_process_mix;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
post_process_mix = false;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
post_process_mix = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether post processing options
|
|
|
|
* have changed */
|
|
|
|
if ((post_process_cc != post_process_cc_prev) ||
|
|
|
|
(post_process_mix != post_process_mix_prev))
|
|
|
|
init_post_processing();
|
|
|
|
|
2021-05-17 14:02:41 +02:00
|
|
|
var.key = "gpsp_turbo_period";
|
|
|
|
var.value = NULL;
|
|
|
|
turbo_period = TURBO_PERIOD_MIN;
|
|
|
|
turbo_pulse_width = TURBO_PULSE_WIDTH_MIN;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
turbo_period = atoi(var.value);
|
|
|
|
turbo_period = (turbo_period < TURBO_PERIOD_MIN) ?
|
|
|
|
TURBO_PERIOD_MIN : turbo_period;
|
|
|
|
turbo_period = (turbo_period > TURBO_PERIOD_MAX) ?
|
|
|
|
TURBO_PERIOD_MAX : turbo_period;
|
|
|
|
|
|
|
|
turbo_pulse_width = turbo_period >> 1;
|
|
|
|
turbo_pulse_width = (turbo_pulse_width < TURBO_PULSE_WIDTH_MIN) ?
|
|
|
|
TURBO_PULSE_WIDTH_MIN : turbo_pulse_width;
|
|
|
|
turbo_pulse_width = (turbo_pulse_width > TURBO_PULSE_WIDTH_MAX) ?
|
|
|
|
TURBO_PULSE_WIDTH_MAX : turbo_pulse_width;
|
|
|
|
|
|
|
|
turbo_a_counter = 0;
|
|
|
|
turbo_b_counter = 0;
|
|
|
|
}
|
2014-12-10 17:48:43 +01:00
|
|
|
}
|
|
|
|
|
2015-09-27 05:35:31 +02:00
|
|
|
static void set_input_descriptors()
|
|
|
|
{
|
|
|
|
struct retro_input_descriptor descriptors[] = {
|
2020-11-10 13:03:10 +01: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" },
|
2021-05-17 14:02:41 +02:00
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Turbo B" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Turbo A" },
|
2020-11-10 13:03:10 +01:00
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
struct retro_input_descriptor descriptors_ff[] = {
|
|
|
|
{ 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" },
|
2021-05-17 14:02:41 +02:00
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Turbo B" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Turbo A" },
|
2020-11-10 13:03:10 +01:00
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
{ 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_R2, "Fast Forward" },
|
2015-09-27 05:35:31 +02:00
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
if (libretro_supports_ff_override)
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_ff);
|
|
|
|
else
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors);
|
2015-09-27 05:35:31 +02:00
|
|
|
}
|
|
|
|
|
2020-04-05 08:21:40 +02:00
|
|
|
static void set_memory_descriptors(void)
|
|
|
|
{
|
|
|
|
const uint64_t mem = RETRO_MEMORY_SYSTEM_RAM;
|
2021-04-27 20:39:44 +02:00
|
|
|
struct retro_memory_descriptor desc[2] = {
|
2021-03-23 19:05:35 +01:00
|
|
|
{ mem, iwram, 0x00000 + 0x8000, 0x3000000, 0, 0, 0x8000, NULL },
|
|
|
|
{ mem, ewram, 0x00000, 0x2000000, 0, 0, 0x40000, NULL },
|
2020-04-05 08:21:40 +02:00
|
|
|
};
|
|
|
|
struct retro_memory_map retromap = {
|
|
|
|
desc,
|
|
|
|
sizeof(desc) / sizeof(desc[0])
|
|
|
|
};
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &retromap);
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
bool retro_load_game(const struct retro_game_info* info)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2017-01-24 18:24:03 +01:00
|
|
|
if (!info)
|
|
|
|
return false;
|
|
|
|
|
2023-09-20 22:46:06 +02:00
|
|
|
check_variables(true);
|
2015-09-27 05:35:31 +02:00
|
|
|
set_input_descriptors();
|
2014-12-10 17:48:43 +01:00
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
char filename_bios[MAX_PATH];
|
2014-12-09 09:54:33 +01:00
|
|
|
const char* dir = NULL;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
|
|
|
|
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
|
2014-12-10 12:00:12 +01:00
|
|
|
info_msg("RGB565 is not supported.");
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
extract_directory(main_path, info->path, sizeof(main_path));
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2021-03-22 21:45:52 +01:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
|
|
|
|
strcpy(filename_bios, dir);
|
|
|
|
else
|
|
|
|
strcpy(filename_bios, main_path);
|
|
|
|
|
|
|
|
bool bios_loaded = false;
|
|
|
|
if (selected_bios == auto_detect || selected_bios == official_bios)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2021-03-22 21:45:52 +01:00
|
|
|
bios_loaded = true;
|
|
|
|
strcat(filename_bios, "/gba_bios.bin");
|
|
|
|
|
|
|
|
if (load_bios(filename_bios) != 0)
|
|
|
|
{
|
|
|
|
if (selected_bios == official_bios)
|
|
|
|
show_warning_message("Could not load BIOS image file, using built-in BIOS", 2500);
|
|
|
|
bios_loaded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bios_loaded && bios_rom[0] != 0x18)
|
|
|
|
{
|
|
|
|
if (selected_bios == official_bios)
|
|
|
|
show_warning_message("BIOS image seems incorrect, using built-in BIOS", 2500);
|
|
|
|
bios_loaded = false;
|
|
|
|
}
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-22 21:45:52 +01:00
|
|
|
if (!bios_loaded) {
|
|
|
|
/* Load the built-in BIOS */
|
|
|
|
memcpy(bios_rom, open_gba_bios_rom, sizeof(bios_rom));
|
2014-12-09 05:16:09 +01:00
|
|
|
}
|
|
|
|
|
2023-09-14 21:46:57 +02:00
|
|
|
memset(gamepak_backup, 0xff, sizeof(gamepak_backup));
|
2023-09-20 22:46:06 +02:00
|
|
|
if (load_gamepak(info, info->path, rtc_mode, rumble_mode) != 0)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2014-12-10 12:00:12 +01:00
|
|
|
error_msg("Could not load the game file.");
|
2014-12-09 09:54:33 +01:00
|
|
|
return false;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2023-09-20 22:46:06 +02:00
|
|
|
struct retro_rumble_interface rumbleif;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumbleif))
|
|
|
|
rumble_cb = rumbleif.set_rumble_state;
|
|
|
|
else
|
|
|
|
rumble_cb = NULL;
|
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
reset_gba();
|
|
|
|
|
2020-04-05 08:21:40 +02:00
|
|
|
set_memory_descriptors();
|
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
bool retro_load_game_special(unsigned game_type,
|
|
|
|
const struct retro_game_info* info, size_t num_info)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
void retro_unload_game(void)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2020-11-10 13:03:10 +01:00
|
|
|
if (libretro_ff_enabled)
|
|
|
|
set_fastforward_override(false);
|
|
|
|
|
|
|
|
libretro_supports_bitmasks = false;
|
|
|
|
libretro_supports_ff_override = false;
|
|
|
|
libretro_ff_enabled = false;
|
|
|
|
libretro_ff_enabled_prev = false;
|
2021-05-17 14:02:41 +02:00
|
|
|
|
|
|
|
turbo_period = TURBO_PERIOD_MIN;
|
|
|
|
turbo_pulse_width = TURBO_PULSE_WIDTH_MIN;
|
|
|
|
turbo_a_counter = 0;
|
|
|
|
turbo_b_counter = 0;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
unsigned retro_get_region(void)
|
2014-12-09 09:54:33 +01:00
|
|
|
{
|
|
|
|
return RETRO_REGION_NTSC;
|
|
|
|
}
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void* retro_get_memory_data(unsigned id)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2023-09-14 21:46:57 +02:00
|
|
|
if (id == RETRO_MEMORY_SAVE_RAM)
|
|
|
|
return gamepak_backup;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2023-09-14 21:46:57 +02:00
|
|
|
return NULL;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t retro_get_memory_size(unsigned id)
|
|
|
|
{
|
2023-09-14 21:46:57 +02:00
|
|
|
if (id == RETRO_MEMORY_SAVE_RAM)
|
|
|
|
return 0x20000; /* Assume 128KiB, biggest possible save */
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
void retro_run(void)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
bool updated = false;
|
|
|
|
|
|
|
|
input_poll_cb();
|
2021-05-17 14:02:41 +02:00
|
|
|
update_input();
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2023-09-20 22:46:06 +02:00
|
|
|
rumble_frame_reset();
|
|
|
|
|
2021-03-22 21:45:52 +01:00
|
|
|
/* Check whether current frame should
|
|
|
|
* be skipped */
|
2019-11-11 20:03:13 +01:00
|
|
|
skip_next_frame = 0;
|
|
|
|
|
2020-10-24 15:58:40 +02:00
|
|
|
if (current_frameskip_type != no_frameskip)
|
2020-03-10 18:51:03 +01:00
|
|
|
{
|
2020-10-24 15:58:40 +02:00
|
|
|
switch (current_frameskip_type)
|
2020-03-10 18:51:03 +01:00
|
|
|
{
|
2020-10-24 15:58:40 +02:00
|
|
|
case auto_frameskip:
|
|
|
|
|
|
|
|
skip_next_frame =
|
|
|
|
(audio_buff_active && audio_buff_underrun) ?
|
|
|
|
1 : 0;
|
|
|
|
|
|
|
|
if (!skip_next_frame ||
|
|
|
|
(frameskip_counter >= FRAMESKIP_MAX))
|
|
|
|
{
|
|
|
|
skip_next_frame = 0;
|
|
|
|
frameskip_counter = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
frameskip_counter++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case auto_threshold_frameskip:
|
|
|
|
|
|
|
|
skip_next_frame =
|
|
|
|
(audio_buff_active &&
|
|
|
|
(audio_buff_occupancy < frameskip_threshold)) ?
|
|
|
|
1 : 0;
|
|
|
|
|
|
|
|
if (!skip_next_frame ||
|
|
|
|
(frameskip_counter >= FRAMESKIP_MAX))
|
|
|
|
{
|
|
|
|
skip_next_frame = 0;
|
|
|
|
frameskip_counter = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
frameskip_counter++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case fixed_interval_frameskip:
|
|
|
|
|
|
|
|
if (frameskip_counter < frameskip_interval)
|
|
|
|
{
|
|
|
|
skip_next_frame = 1;
|
|
|
|
frameskip_counter++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
skip_next_frame = 0;
|
|
|
|
frameskip_counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skip_next_frame = 0;
|
|
|
|
break;
|
2020-03-10 18:51:03 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-24 15:58:40 +02:00
|
|
|
|
|
|
|
/* If frameskip settings have changed, update
|
|
|
|
* frontend audio latency */
|
|
|
|
if (update_audio_latency)
|
2019-11-11 20:03:13 +01:00
|
|
|
{
|
2020-10-24 15:58:40 +02:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_MINIMUM_AUDIO_LATENCY,
|
|
|
|
&audio_latency);
|
|
|
|
update_audio_latency = false;
|
2019-11-11 20:03:13 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 18:44:03 +01:00
|
|
|
/* This runs just a frame */
|
|
|
|
#ifdef HAVE_DYNAREC
|
|
|
|
if (dynarec_enable)
|
|
|
|
execute_arm_translate(execute_cycles);
|
|
|
|
else
|
|
|
|
#endif
|
2021-07-14 01:17:55 +02:00
|
|
|
{
|
|
|
|
/* Sticky bits only used in interpreter */
|
|
|
|
clear_gamepak_stickybits();
|
2021-03-08 18:44:03 +01:00
|
|
|
execute_arm(execute_cycles);
|
2021-07-14 01:17:55 +02:00
|
|
|
}
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2023-09-20 22:46:06 +02:00
|
|
|
if (rumble_cb) {
|
|
|
|
// TODO: Add some user-option to select a rumble policy
|
|
|
|
u32 strength = 0xffff * rumble_active_pct();
|
|
|
|
rumble_cb(0, RETRO_RUMBLE_WEAK, MIN(strength, 0xffff));
|
|
|
|
rumble_cb(0, RETRO_RUMBLE_STRONG, MIN(strength, 0xffff) / 2);
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:04:57 +01:00
|
|
|
audio_run();
|
2020-10-24 15:58:40 +02:00
|
|
|
video_run();
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
2023-09-20 22:46:06 +02:00
|
|
|
check_variables(false);
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
unsigned retro_api_version(void)
|
2014-12-09 09:54:33 +01:00
|
|
|
{
|
|
|
|
return RETRO_API_VERSION;
|
|
|
|
}
|