#include "main.h"
#include "plugin.h"
#include "plugin_lib.h"
+#include "arm_features.h"
#include "revision.h"
#include "libretro.h"
+#ifdef _3DS
+#include "3ds/3ds_utils.h"
+#endif
+
static retro_video_refresh_t video_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
{
}
-static void *pl_mmap(unsigned int size)
+#ifdef _3DS
+typedef struct
+{
+ void* buffer;
+ uint32_t target_map;
+ size_t size;
+ enum psxMapTag tag;
+}psx_map_t;
+
+psx_map_t custom_psx_maps[] = {
+ {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
+ {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
+ {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
+ {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
+ {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
+};
+
+void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag)
+{
+ (void)is_fixed;
+ (void)addr;
+
+ if (__ctr_svchax)
+ {
+ psx_map_t* custom_map = custom_psx_maps;
+
+ for (; custom_map->size; custom_map++)
+ {
+ if ((custom_map->size == size) && (custom_map->tag == tag))
+ {
+ uint32_t ptr_aligned, tmp;
+
+ custom_map->buffer = malloc(size + 0x1000);
+ ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
+
+ if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
+ {
+ SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
+ exit(1);
+ }
+
+ return (void*)custom_map->target_map;
+ }
+ }
+ }
+
+ return malloc(size);
+}
+
+void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
{
+ (void)tag;
+
+ if (__ctr_svchax)
+ {
+ psx_map_t* custom_map = custom_psx_maps;
+
+ for (; custom_map->size; custom_map++)
+ {
+ if ((custom_map->target_map == (uint32_t)ptr))
+ {
+ uint32_t ptr_aligned, tmp;
+
+ ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
+
+ svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3);
+
+ free(custom_map->buffer);
+ custom_map->buffer = NULL;
+ return;
+ }
+ }
+ }
+
+ free(ptr);
+}
+#endif
+
+static void *pl_mmap(unsigned int size)
+{
return psxMap(0, size, 0, MAP_TAG_VRAM);
}
static const struct retro_variable vars[] = {
{ "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
{ "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
- { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog" },
- { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog" },
+ { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog|negcon" },
+ { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog|negcon" },
#ifndef DRC_DISABLE
{ "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
#endif
in_type1 = PSE_PAD_TYPE_STANDARD;
if (strcmp(var.value, "analog") == 0)
in_type1 = PSE_PAD_TYPE_ANALOGPAD;
+ if (strcmp(var.value, "negcon") == 0)
+ in_type1 = PSE_PAD_TYPE_NEGCON;
}
var.value = NULL;
in_type2 = PSE_PAD_TYPE_STANDARD;
if (strcmp(var.value, "analog") == 0)
in_type2 = PSE_PAD_TYPE_ANALOGPAD;
+ if (strcmp(var.value, "negcon") == 0)
+ in_type2 = PSE_PAD_TYPE_NEGCON;
+
}
#ifdef __ARM_NEON__
{
R3000Acpu *prev_cpu = psxCpu;
+#ifdef _3DS
+ if(!__ctr_svchax)
+ Config.Cpu = CPU_INTERPRETER;
+ else
+#endif
if (strcmp(var.value, "disabled") == 0)
Config.Cpu = CPU_INTERPRETER;
else if (strcmp(var.value, "enabled") == 0)
void retro_run(void)
{
- int i;
+ int i, val;
input_poll_cb();
if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
in_keystate |= retro_psx_map[i];
+
if (in_type1 == PSE_PAD_TYPE_ANALOGPAD)
{
in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
in_a4[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
}
+
+ if (in_type1 == PSE_PAD_TYPE_NEGCON)
+ {
+ /* left brake */
+ if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, 12))
+ in_a1[1] = 255;
+ else
+ in_a1[1] = 0;
+
+ /* steer */
+ in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
+
+ /* thrust and fire */
+ val = ((input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 127));
+ if(val < -2) {
+ in_a1[0] = 256 - val;
+ }
+ if (val > 2) {
+ in_a2[1] = val;
+ }
+ if(val >= -2 && val <= 2)
+ {
+ in_a2[1] = 0;
+ in_a1[0] = 0;
+ }
+ }
+
+ if (in_type2 == PSE_PAD_TYPE_NEGCON)
+ {
+ /* left brake */
+ if(input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, 12))
+ in_a3[1] = 255;
+ else
+ in_a3[1] = 0;
+
+ /* steer */
+ in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
+
+ /* thrust and fire */
+ val = ((input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 127));
+ if(val < -2) {
+ in_a3[0] = 256 - val;
+ }
+ if (val > 2) {
+ in_a4[1] = val;
+ }
+ if(val >= -2 && val <= 2)
+ {
+ in_a4[1] = 0;
+ in_a3[0] = 0;
+ }
+ }
+
+
stop = 0;
psxCpu->Execute();
return true;
}
-#if 1
+#ifndef VITA
#include <sys/types.h>
#include <dirent.h>
int i, ret;
bool found_bios = false;
+#ifdef _3DS
+ psxMapHook = pl_3ds_mmap;
+ psxUnmapHook = pl_3ds_munmap;
+#endif
ret = emu_core_preinit();
+#ifdef _3DS
+ /* emu_core_preinit sets the cpu to dynarec */
+ if(!__ctr_svchax)
+ Config.Cpu = CPU_INTERPRETER;
+#endif
ret |= emu_core_init();
if (ret != 0) {
SysPrintf("PCSX init failed.\n");
exit(1);
}
-#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)
+#ifdef _3DS
+ vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
+#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
#else
vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
{
- snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s/", dir);
+ snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
/* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
* we have to do this because cache misses and some IO penalties
* are not emulated. Warning: changing this may break compatibility. */
-#if !defined(__arm__) || defined(__ARM_ARCH_7A__)
cycle_multiplier = 175;
-#else
+#ifdef HAVE_PRE_ARMV7
cycle_multiplier = 200;
#endif
pl_rearmed_cbs.gpu_peops.iUseDither = 1;
void retro_deinit(void)
{
SysClose();
+#ifdef _3DS
+ linearFree(vout_buf);
+#else
free(vout_buf);
+#endif
vout_buf = NULL;
}
+
+#ifdef VITA
+#include <psp2/kernel/threadmgr.h>
+int usleep (unsigned long us)
+{
+ sceKernelDelayThread(us);
+}
+#endif