2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "libco.h"
|
2014-12-09 00:17:28 +01:00
|
|
|
#include "libretro.h"
|
2014-12-13 05:50:15 +01:00
|
|
|
#include "memmap.h"
|
2014-12-09 00:17:28 +01:00
|
|
|
|
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 +
|
|
|
|
RAM_TRANSLATION_CACHE_SIZE +
|
|
|
|
BIOS_TRANSLATION_CACHE_SIZE;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
static retro_log_printf_t log_cb;
|
|
|
|
static retro_video_refresh_t video_cb;
|
|
|
|
static retro_input_poll_t input_poll_cb;
|
|
|
|
static retro_environment_t environ_cb;
|
|
|
|
|
|
|
|
struct retro_perf_callback perf_cb;
|
|
|
|
|
|
|
|
static cothread_t main_thread;
|
|
|
|
static cothread_t cpu_thread;
|
2014-12-10 17:06:09 +01:00
|
|
|
int dynarec_enable;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-10 17:27:18 +01:00
|
|
|
u32 idle_loop_target_pc = 0xFFFFFFFF;
|
|
|
|
u32 iwram_stack_optimize = 1;
|
|
|
|
u32 translation_gate_target_pc[MAX_TRANSLATION_GATES];
|
|
|
|
u32 translation_gate_targets = 0;
|
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
void switch_to_main_thread(void)
|
|
|
|
{
|
|
|
|
co_switch(main_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void switch_to_cpu_thread(void)
|
|
|
|
{
|
|
|
|
co_switch(cpu_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_thread_entry(void)
|
|
|
|
{
|
2014-12-10 17:06:09 +01:00
|
|
|
#ifdef HAVE_DYNAREC
|
|
|
|
if (dynarec_enable)
|
|
|
|
execute_arm_translate(execute_cycles);
|
|
|
|
#endif
|
2014-12-09 02:43:59 +01:00
|
|
|
execute_arm(execute_cycles);
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void init_context_switch(void)
|
|
|
|
{
|
|
|
|
main_thread = co_active();
|
|
|
|
cpu_thread = co_create(0x20000, cpu_thread_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void deinit_context_switch(void)
|
|
|
|
{
|
|
|
|
co_delete(cpu_thread);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
info->valid_extensions = "gba|bin|agb|gbz" ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
info->geometry.aspect_ratio = 0;
|
2014-12-09 09:54:33 +01:00
|
|
|
// 59.72750057 hz
|
2014-12-10 11:06:17 +01:00
|
|
|
info->timing.fps = ((float) GBC_BASE_RATE) / (308 * 228 * 4);
|
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
|
|
|
{
|
2016-08-08 00:31:21 +02:00
|
|
|
|
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)
|
2015-04-08 11:20:32 +02:00
|
|
|
{
|
2015-09-11 23:02:04 +02:00
|
|
|
uint32_t currentHandle;
|
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);
|
|
|
|
bios_translation_cache_ptr = memalign(0x1000, BIOS_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);
|
|
|
|
svcControlProcessMemory(currentHandle,
|
|
|
|
bios_translation_cache, bios_translation_cache_ptr,
|
|
|
|
BIOS_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;
|
|
|
|
bios_translation_ptr = bios_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
|
|
|
}
|
2016-08-08 00:31:21 +02:00
|
|
|
#endif
|
|
|
|
|
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){
|
|
|
|
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;
|
|
|
|
bios_translation_cache = ram_translation_cache + RAM_TRANSLATION_CACHE_SIZE;
|
|
|
|
rom_translation_ptr = rom_translation_cache;
|
|
|
|
ram_translation_ptr = ram_translation_cache;
|
|
|
|
bios_translation_ptr = bios_translation_cache;
|
2016-10-04 09:32:54 +02:00
|
|
|
sceKernelOpenVMDomain();
|
2016-08-08 00:31:21 +02:00
|
|
|
translation_caches_inited = 1;
|
|
|
|
}
|
|
|
|
|
2015-04-08 11:20:32 +02:00
|
|
|
#endif
|
2014-12-09 09:54:33 +01:00
|
|
|
|
2015-11-04 15:46:27 +01:00
|
|
|
if (!gamepak_rom)
|
|
|
|
init_gamepak_buffer();
|
|
|
|
init_sound(1);
|
|
|
|
|
|
|
|
if(!gba_screen_pixels)
|
2015-04-13 03:43:42 +02:00
|
|
|
#ifdef _3DS
|
2015-11-04 15:46:27 +01:00
|
|
|
gba_screen_pixels = (uint16_t*)linearMemAlign(GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT * sizeof(uint16_t), 128);
|
2015-04-13 03:43:42 +02:00
|
|
|
#else
|
2015-11-04 15:46:27 +01:00
|
|
|
gba_screen_pixels = (uint16_t*)malloc(GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT * sizeof(uint16_t));
|
2015-04-13 03:43:42 +02:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2014-12-10 17:06:09 +01:00
|
|
|
#if defined(HAVE_MMAP) && defined(HAVE_DYNAREC)
|
2014-12-09 09:54:33 +01:00
|
|
|
munmap(rom_translation_cache, ROM_TRANSLATION_CACHE_SIZE);
|
|
|
|
munmap(ram_translation_cache, RAM_TRANSLATION_CACHE_SIZE);
|
|
|
|
munmap(bios_translation_cache, BIOS_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);
|
|
|
|
svcControlProcessMemory(currentHandle,
|
|
|
|
bios_translation_cache, bios_translation_cache_ptr,
|
|
|
|
BIOS_TRANSLATION_CACHE_SIZE, MEMOP_UNMAP, 0b111);
|
|
|
|
svcCloseHandle(currentHandle);
|
|
|
|
free(rom_translation_cache_ptr);
|
|
|
|
free(ram_translation_cache_ptr);
|
|
|
|
free(bios_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);
|
|
|
|
#else
|
|
|
|
free(gba_screen_pixels);
|
|
|
|
#endif
|
2015-11-04 15:46:27 +01:00
|
|
|
gba_screen_pixels = NULL;
|
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;
|
|
|
|
|
2015-11-04 15:46:27 +01:00
|
|
|
static struct retro_variable vars[] = {
|
2014-12-10 17:48:43 +01:00
|
|
|
#ifdef HAVE_DYNAREC
|
|
|
|
{ "gpsp_drc", "Dynamic recompiler (restart); enabled|disabled" },
|
|
|
|
#endif
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2015-11-04 15:46:27 +01:00
|
|
|
#if defined(_3DS) && (HAVE_DYNAREC)
|
|
|
|
if(!__ctr_svchax)
|
|
|
|
{
|
|
|
|
vars[0].key = 0;
|
|
|
|
vars[0].value = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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);
|
2014-12-10 17:48:43 +01:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
|
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;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
|
|
|
deinit_context_switch();
|
|
|
|
|
|
|
|
update_backup();
|
|
|
|
reset_gba();
|
|
|
|
|
|
|
|
init_context_switch();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-12-10 11:06:17 +01:00
|
|
|
gba_load_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-10 17:48:43 +01:00
|
|
|
void retro_cheat_reset(void)
|
|
|
|
{
|
|
|
|
}
|
2014-12-09 09:54:33 +01:00
|
|
|
void retro_cheat_set(unsigned index, bool enabled, const char* code) {}
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void error_msg(const char* text)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
if (log_cb)
|
2014-12-10 12:00:12 +01:00
|
|
|
log_cb(RETRO_LOG_ERROR, "[gpSP]: %s\n", text);
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
void info_msg(const char* text)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
|
|
|
if (log_cb)
|
2014-12-10 12:00:12 +01:00
|
|
|
log_cb(RETRO_LOG_INFO, "[gpSP]: %s\n", text);
|
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);
|
|
|
|
}
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
static void check_variables(int started_from_load)
|
|
|
|
{
|
2014-12-11 19:47:36 +01:00
|
|
|
#ifdef HAVE_DYNAREC
|
2014-12-10 17:48:43 +01:00
|
|
|
struct retro_variable var;
|
|
|
|
|
|
|
|
var.key = "gpsp_drc";
|
|
|
|
var.value = NULL;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (started_from_load)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "disabled") == 0)
|
|
|
|
dynarec_enable = 0;
|
|
|
|
else if (strcmp(var.value, "enabled") == 0)
|
|
|
|
dynarec_enable = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dynarec_enable = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-27 05:35:31 +02:00
|
|
|
static void set_input_descriptors()
|
|
|
|
{
|
|
|
|
struct retro_input_descriptor descriptors[] = {
|
|
|
|
{ 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_SELECT, "Select" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
2018-05-03 16:34:34 +02:00
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
|
2015-09-27 05:35:31 +02:00
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2014-12-10 17:48:43 +01:00
|
|
|
check_variables(1);
|
2015-09-27 05:35:31 +02:00
|
|
|
set_input_descriptors();
|
2014-12-10 17:48:43 +01:00
|
|
|
|
|
|
|
#if defined(HAVE_DYNAREC)
|
|
|
|
if (dynarec_enable)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_MMAP)
|
|
|
|
|
|
|
|
rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE,
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
|
ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE,
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
|
bios_translation_cache = mmap(NULL, BIOS_TRANSLATION_CACHE_SIZE,
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
|
|
|
|
|
rom_translation_ptr = rom_translation_cache;
|
|
|
|
ram_translation_ptr = ram_translation_cache;
|
|
|
|
bios_translation_ptr = bios_translation_cache;
|
2015-04-08 11:20:32 +02:00
|
|
|
#elif defined(_3DS)
|
2015-11-04 15:46:27 +01:00
|
|
|
dynarec_enable = __ctr_svchax;
|
|
|
|
rom_translation_ptr = rom_translation_cache;
|
|
|
|
ram_translation_ptr = ram_translation_cache;
|
|
|
|
bios_translation_ptr = bios_translation_cache;
|
2016-10-03 20:19:11 +02:00
|
|
|
#elif defined(VITA)
|
|
|
|
dynarec_enable = 1;
|
|
|
|
rom_translation_ptr = rom_translation_cache;
|
|
|
|
ram_translation_ptr = ram_translation_cache;
|
|
|
|
bios_translation_ptr = bios_translation_cache;
|
2014-12-10 17:48:43 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dynarec_enable = 0;
|
|
|
|
#else
|
|
|
|
dynarec_enable = 0;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
|
|
|
|
strncpy(filename_bios, dir, sizeof(filename_bios));
|
|
|
|
else
|
|
|
|
strncpy(filename_bios, main_path, sizeof(filename_bios));
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
strncat(filename_bios, "/gba_bios.bin", sizeof(filename_bios));
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
|
2014-12-10 12:00:12 +01:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir)
|
|
|
|
strncpy(save_path, dir, sizeof(save_path));
|
|
|
|
else
|
|
|
|
strncpy(save_path, main_path, sizeof(save_path));
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 05:16:09 +01:00
|
|
|
if (load_bios(filename_bios) != 0)
|
2014-12-08 22:56:33 +01:00
|
|
|
{
|
2014-12-10 12:00:12 +01:00
|
|
|
error_msg("Could not load BIOS image file.");
|
2014-12-09 09:54:33 +01:00
|
|
|
return false;
|
2014-12-08 22:56:33 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
if (bios_rom[0] != 0x18)
|
2014-12-09 05:16:09 +01:00
|
|
|
{
|
2014-12-10 12:00:12 +01:00
|
|
|
info_msg("You have an incorrect BIOS image.");
|
|
|
|
info_msg("While many games will work fine, some will not.");
|
|
|
|
info_msg("It is strongly recommended that you obtain the correct BIOS file.");
|
2014-12-09 05:16:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
gamepak_filename[0] = 0;
|
2014-12-20 08:35:53 +01:00
|
|
|
if (load_gamepak(info, info->path) != 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
|
|
|
}
|
|
|
|
|
|
|
|
reset_gba();
|
|
|
|
|
|
|
|
init_context_switch();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
deinit_context_switch();
|
|
|
|
update_backup();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-08-11 20:35:49 +02:00
|
|
|
if ( id == RETRO_MEMORY_SYSTEM_RAM )
|
|
|
|
return ewram ;
|
2014-12-09 09:54:33 +01:00
|
|
|
// switch (id)
|
|
|
|
// {
|
|
|
|
// case RETRO_MEMORY_SAVE_RAM:
|
|
|
|
// return gamepak_backup;
|
|
|
|
// }
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t retro_get_memory_size(unsigned id)
|
|
|
|
{
|
2018-08-11 20:35:49 +02:00
|
|
|
|
|
|
|
if ( id == RETRO_MEMORY_SYSTEM_RAM )
|
|
|
|
return 1024 * 256 * 2 ;
|
|
|
|
// switch (id)
|
2014-12-09 09:54:33 +01:00
|
|
|
// {
|
|
|
|
// case RETRO_MEMORY_SAVE_RAM:
|
|
|
|
// switch(backup_type)
|
|
|
|
// {
|
|
|
|
// case BACKUP_SRAM:
|
|
|
|
// return sram_size;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
// case BACKUP_FLASH:
|
|
|
|
// return flash_size;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
// case BACKUP_EEPROM:
|
|
|
|
// return eeprom_size;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
// case BACKUP_NONE:
|
|
|
|
// return 0x0;
|
2014-12-08 22:56:33 +01:00
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
// default:
|
|
|
|
// return 0x8000;
|
|
|
|
// }
|
|
|
|
// }
|
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;
|
|
|
|
|
2018-01-06 17:27:48 +01:00
|
|
|
update_input();
|
|
|
|
|
2014-12-08 22:56:33 +01:00
|
|
|
input_poll_cb();
|
|
|
|
|
|
|
|
switch_to_cpu_thread();
|
|
|
|
|
|
|
|
render_audio();
|
|
|
|
|
2014-12-09 09:54:33 +01:00
|
|
|
video_cb(gba_screen_pixels, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT,
|
|
|
|
GBA_SCREEN_PITCH * 2);
|
2014-12-08 22:56:33 +01:00
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
2014-12-10 17:48:43 +01:00
|
|
|
check_variables(0);
|
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;
|
|
|
|
}
|