Merge from libretro/master:7ff457f for repo synchronization

This commit is contained in:
kub 2022-04-19 23:58:59 +02:00
parent 45d0add214
commit a5085db3ea
19 changed files with 1015 additions and 311 deletions

View file

@ -451,7 +451,7 @@ int emu_reload_rom(const char *rom_fname_in)
emu_make_path(carthw_path, "carthw.cfg", sizeof(carthw_path));
media_type = PicoLoadMedia(rom_fname, carthw_path,
media_type = PicoLoadMedia(rom_fname, NULL, 0, carthw_path,
find_bios, do_region_override);
switch (media_type) {

View file

@ -9,6 +9,10 @@
#include <stdio.h>
#include <pico/pico_int.h>
// Ugh, drmp3 tries to use wfopen on windows, which breaks libretro VFS...
#define __acrt_iob_func __acrt_iob_func2
#define _wfopen_s(p,m) NULL
#define _wfopen(p,m) NULL
#define DR_MP3_IMPLEMENTATION
#include "dr_libs/dr_mp3.h"
#include "mp3.h"

View file

@ -69,7 +69,7 @@ extern "C" {
# endif
# endif
# else
# if defined(__GNUC__) && __GNUC__ >= 4
# if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__PS3__)
# define RETRO_API RETRO_CALLCONV __attribute__((__visibility__("default")))
# else
# define RETRO_API RETRO_CALLCONV

View file

@ -0,0 +1,35 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_assert.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __RETRO_ASSERT_H
#define __RETRO_ASSERT_H
#include <assert.h>
#ifdef RARCH_INTERNAL
#include <stdio.h>
#define retro_assert(cond) ((void)( (cond) || (printf("Assertion failed at %s:%d.\n", __FILE__, __LINE__), abort(), 0) ))
#else
#define retro_assert(cond) assert(cond)
#endif
#endif

View file

@ -75,8 +75,10 @@ static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count)
}
#ifndef PATH_MAX_LENGTH
#if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) || defined(ORBIS) || defined(__PSL1GHT__) || defined(__PS3__)
#if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) || defined(ORBIS)
#define PATH_MAX_LENGTH 512
#elif defined(__PS3__)
#define PATH_MAX_LENGTH 1024
#else
#define PATH_MAX_LENGTH 4096
#endif

View file

@ -0,0 +1,48 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rtime.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_RTIME_H__
#define __LIBRETRO_SDK_RTIME_H__
#include <retro_common_api.h>
#include <stdint.h>
#include <stddef.h>
#include <time.h>
RETRO_BEGIN_DECLS
/* TODO/FIXME: Move all generic time handling functions
* to this file */
/* Must be called before using rtime_localtime() */
void rtime_init(void);
/* Must be called upon program termination */
void rtime_deinit(void);
/* Thread-safe wrapper for localtime() */
struct tm *rtime_localtime(const time_t *timep, struct tm *result);
RETRO_END_DECLS
#endif

View file

@ -0,0 +1,81 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rtime.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#include <retro_assert.h>
#include <stdlib.h>
#endif
#include <string.h>
#include <time/rtime.h>
#ifdef HAVE_THREADS
/* TODO/FIXME - global */
slock_t *rtime_localtime_lock = NULL;
#endif
/* Must be called before using rtime_localtime() */
void rtime_init(void)
{
rtime_deinit();
#ifdef HAVE_THREADS
if (!rtime_localtime_lock)
rtime_localtime_lock = slock_new();
retro_assert(rtime_localtime_lock);
#endif
}
/* Must be called upon program termination */
void rtime_deinit(void)
{
#ifdef HAVE_THREADS
if (rtime_localtime_lock)
{
slock_free(rtime_localtime_lock);
rtime_localtime_lock = NULL;
}
#endif
}
/* Thread-safe wrapper for localtime() */
struct tm *rtime_localtime(const time_t *timep, struct tm *result)
{
struct tm *time_info = NULL;
/* Lock mutex */
#ifdef HAVE_THREADS
slock_lock(rtime_localtime_lock);
#endif
time_info = localtime(timep);
if (time_info)
memcpy(result, time_info, sizeof(struct tm));
/* Unlock mutex */
#ifdef HAVE_THREADS
slock_unlock(rtime_localtime_lock);
#endif
return result;
}

View file

@ -14,22 +14,23 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#ifndef _WIN32
#ifdef __SWITCH__
#include "switch/mman.h"
#else
#include <sys/mman.h>
#endif
#else
#include <io.h>
#include <windows.h>
#include <sys/types.h>
#endif
#include <errno.h>
#ifdef __MACH__
#include <libkern/OSCacheControl.h>
#endif
#include "libretro-common/include/memmap.h"
/* Ouf, libretro-common defines replacement functions, but not the flags :-| */
#ifndef PROT_READ
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_READWRITE 0x3
#define PROT_EXEC 0x4
#define MAP_FAILED ((void *) -1)
#define MAP_ANONYMOUS 0x1
#define MAP_PRIVATE 0x2
#endif
#if defined(RENDER_GSKIT_PS2)
#include <malloc.h>
#include "libretro-common/include/libretro_gskit_ps2.h"
@ -72,6 +73,7 @@ int _newlib_vm_size_user = 1 << TARGET_SIZE_2;
#include "../common/input_pico.h"
#include "../common/version.h"
#include <libretro.h>
#include <compat/strcasestr.h>
static retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb;
@ -86,6 +88,10 @@ static retro_audio_sample_batch_t audio_batch_cb;
#define SND_RATE_DEFAULT 44100
#define SND_RATE_MAX 53267
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
static const float VOUT_PAR = 0.0;
static const float VOUT_4_3 = (4.0f / 3.0f);
static const float VOUT_CRT = (1.29911f);
@ -141,6 +147,9 @@ static bool retro_audio_buff_underrun = false;
static unsigned audio_latency = 0;
static bool update_audio_latency = false;
static uint16_t pico_events;
int pico_inp_mode;
int pico_pen_x = 320/2, pico_pen_y = 240/2;
static void retro_audio_buff_status_cb(
bool active, unsigned occupancy, bool underrun_likely)
@ -214,8 +223,8 @@ void cache_flush_d_inval_i(void *start, void *end)
}
#ifdef RENDER_GSKIT_PS2
/* ee-gcc is version 3.2, where these aren't yet defined */
void __builtin___clear_cache(void *b, void *e)
/* In PS2 toolchain these aren't yet defined */
void _flush_cache(void *b, void *e)
{
#if 0 /* which of these is overall faster for lots of small cache updates? */
SyncDCache(b, e);
@ -233,6 +242,14 @@ int __builtin_parity(unsigned v)
v ^= v >> 4;
return (0x6996 >> (v&0xf)) & 1;
}
#elif defined(PSP)
int _flush_cache(char *addr, const int size, const int op)
{
//sceKernelDcacheWritebackAll();
sceKernelDcacheWritebackRange(addr, size);
sceKernelIcacheInvalidateRange(addr, size);
return 0;
}
#endif
#ifdef __MACH__
@ -245,105 +262,6 @@ void __clear_cache(void *start, void *end)
}
#endif
#ifdef _WIN32
/* mmap() replacement for Windows
*
* Author: Mike Frysinger <vapier@gentoo.org>
* Placed into the public domain
*/
/* References:
* CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
* CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx
* MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx
* UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx
*/
#define PROT_READ 0x1
#define PROT_WRITE 0x2
/* This flag is only available in WinXP+ */
#ifdef FILE_MAP_EXECUTE
#define PROT_EXEC 0x4
#else
#define PROT_EXEC 0x0
#define FILE_MAP_EXECUTE 0
#endif
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void *) -1)
#ifdef __USE_FILE_OFFSET64
# define DWORD_HI(x) (x >> 32)
# define DWORD_LO(x) ((x) & 0xffffffff)
#else
# define DWORD_HI(x) (0)
# define DWORD_LO(x) (x)
#endif
static void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
{
uint32_t flProtect, dwDesiredAccess;
off_t end;
HANDLE mmap_fd, h;
void *ret;
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
return MAP_FAILED;
if (fd == -1) {
if (!(flags & MAP_ANON) || offset)
return MAP_FAILED;
} else if (flags & MAP_ANON)
return MAP_FAILED;
if (prot & PROT_WRITE) {
if (prot & PROT_EXEC)
flProtect = PAGE_EXECUTE_READWRITE;
else
flProtect = PAGE_READWRITE;
} else if (prot & PROT_EXEC) {
if (prot & PROT_READ)
flProtect = PAGE_EXECUTE_READ;
else if (prot & PROT_EXEC)
flProtect = PAGE_EXECUTE;
} else
flProtect = PAGE_READONLY;
end = length + offset;
if (fd == -1)
mmap_fd = INVALID_HANDLE_VALUE;
else
mmap_fd = (HANDLE)_get_osfhandle(fd);
h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL);
if (h == NULL)
return MAP_FAILED;
if (prot & PROT_WRITE)
dwDesiredAccess = FILE_MAP_WRITE;
else
dwDesiredAccess = FILE_MAP_READ;
if (prot & PROT_EXEC)
dwDesiredAccess |= FILE_MAP_EXECUTE;
if (flags & MAP_PRIVATE)
dwDesiredAccess |= FILE_MAP_COPY;
ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length);
if (ret == NULL) {
CloseHandle(h);
ret = MAP_FAILED;
}
return ret;
}
static void munmap(void *addr, size_t length)
{
UnmapViewOfFile(addr);
/* ruh-ro, we leaked handle from CreateFileMapping() ... */
}
#endif
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
@ -696,10 +614,25 @@ void retro_set_environment(retro_environment_t cb)
struct retro_vfs_interface_info vfs_iface_info;
#endif
static const struct retro_system_content_info_override content_overrides[] = {
{
"gen|smd|md|32x|sms|68k|sgd|pco", /* extensions */
#if defined(LOW_MEMORY)
true, /* need_fullpath */
#else
false, /* need_fullpath */
#endif
false /* persistent_data */
},
{ NULL, false, false }
};
environ_cb = cb;
libretro_set_core_options(environ_cb,
&option_categories_supported);
environ_cb(RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE,
(void*)content_overrides);
#ifdef USE_LIBRETRO_VFS
vfs_iface_info.required_interface_version = 1;
@ -734,7 +667,7 @@ void retro_get_system_info(struct retro_system_info *info)
#define _GIT_VERSION "-" GIT_VERSION
#endif
info->library_version = VERSION _GIT_VERSION;
info->valid_extensions = "bin|gen|smd|md|32x|cue|iso|chd|sms|gg|sg";
info->valid_extensions = "bin|gen|smd|md|32x|cue|iso|chd|sms|gg|m3u|68k|sgd|pco";
info->need_fullpath = true;
}
@ -967,13 +900,61 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code)
}
/* multidisk support */
static unsigned int disk_initial_index;
static bool disk_ejected;
static unsigned int disk_current_index;
static unsigned int disk_count;
static char disk_initial_path[PATH_MAX];
static struct disks_state {
char *fname;
char *flabel;
} disks[8];
static void get_disk_label(char *disk_label, const char *disk_path, size_t len)
{
const char *base = NULL;
if (!disk_path || (*disk_path == '\0'))
return;
base = strrchr(disk_path, SLASH);
if (!base)
base = disk_path;
if (*base == SLASH)
base++;
strncpy(disk_label, base, len - 1);
disk_label[len - 1] = '\0';
char *ext = strrchr(disk_label, '.');
if (ext)
*ext = '\0';
}
static void disk_init(void)
{
size_t i;
disk_ejected = false;
disk_current_index = 0;
disk_count = 0;
for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++)
{
if (disks[i].fname != NULL)
{
free(disks[i].fname);
disks[i].fname = NULL;
}
if (disks[i].flabel != NULL)
{
free(disks[i].flabel);
disks[i].flabel = NULL;
}
}
}
static bool disk_set_eject_state(bool ejected)
{
// TODO?
@ -1035,21 +1016,43 @@ static unsigned int disk_get_num_images(void)
static bool disk_replace_image_index(unsigned index,
const struct retro_game_info *info)
{
bool ret = true;
char *old_fname = NULL;
char *old_flabel = NULL;
bool ret = true;
if (index >= sizeof(disks) / sizeof(disks[0]))
return false;
old_fname = disks[index].fname;
old_flabel = disks[index].flabel;
if (disks[index].fname != NULL)
free(disks[index].fname);
disks[index].fname = NULL;
if (disks[index].flabel != NULL)
free(disks[index].flabel);
disks[index].flabel = NULL;
if (info != NULL) {
char disk_label[PATH_MAX];
disk_label[0] = '\0';
disks[index].fname = strdup(info->path);
get_disk_label(disk_label, info->path, PATH_MAX);
disks[index].flabel = strdup(disk_label);
if (index == disk_current_index)
ret = disk_set_image_index(index);
}
if (old_fname != NULL)
free(old_fname);
if (old_flabel != NULL)
free(old_flabel);
return ret;
}
@ -1062,6 +1065,64 @@ static bool disk_add_image_index(void)
return true;
}
static bool disk_set_initial_image(unsigned index, const char *path)
{
if (index >= sizeof(disks) / sizeof(disks[0]))
return false;
if (!path || (*path == '\0'))
return false;
disk_initial_index = index;
strncpy(disk_initial_path, path, sizeof(disk_initial_path) - 1);
disk_initial_path[sizeof(disk_initial_path) - 1] = '\0';
return true;
}
static bool disk_get_image_path(unsigned index, char *path, size_t len)
{
const char *fname = NULL;
if (len < 1)
return false;
if (index >= sizeof(disks) / sizeof(disks[0]))
return false;
fname = disks[index].fname;
if (!fname || (*fname == '\0'))
return false;
strncpy(path, fname, len - 1);
path[len - 1] = '\0';
return true;
}
static bool disk_get_image_label(unsigned index, char *label, size_t len)
{
const char *flabel = NULL;
if (len < 1)
return false;
if (index >= sizeof(disks) / sizeof(disks[0]))
return false;
flabel = disks[index].flabel;
if (!flabel || (*flabel == '\0'))
return false;
strncpy(label, flabel, len - 1);
label[len - 1] = '\0';
return true;
}
static struct retro_disk_control_callback disk_control = {
disk_set_eject_state,
disk_get_eject_state,
@ -1072,6 +1133,19 @@ static struct retro_disk_control_callback disk_control = {
disk_add_image_index,
};
static struct retro_disk_control_ext_callback disk_control_ext = {
.set_eject_state = disk_set_eject_state,
.get_eject_state = disk_get_eject_state,
.get_image_index = disk_get_image_index,
.set_image_index = disk_set_image_index,
.get_num_images = disk_get_num_images,
.replace_image_index = disk_replace_image_index,
.add_image_index = disk_add_image_index,
.set_initial_image = disk_set_initial_image,
.get_image_path = disk_get_image_path,
.get_image_label = disk_get_image_label,
};
static void disk_tray_open(void)
{
if (log_cb)
@ -1086,6 +1160,85 @@ static void disk_tray_close(void)
disk_ejected = 0;
}
static char base_dir[1024];
static void extract_directory(char *buf, const char *path, size_t size)
{
char *base;
strncpy(buf, path, size - 1);
buf[size - 1] = '\0';
base = strrchr(buf, '/');
if (!base)
base = strrchr(buf, '\\');
if (base)
*base = '\0';
else
{
buf[0] = '.';
buf[1] = '\0';
}
}
static void extract_basename(char *buf, const char *path, size_t size)
{
const char *base = strrchr(path, '/');
if (!base)
base = strrchr(path, '\\');
if (!base)
base = path;
if (*base == '\\' || *base == '/')
base++;
strncpy(buf, base, size - 1);
buf[size - 1] = '\0';
char *ext = strrchr(buf, '.');
if (ext)
*ext = '\0';
}
static bool read_m3u(const char *file)
{
char line[1024];
char name[PATH_MAX];
FILE *f = fopen(file, "r");
if (!f)
return false;
while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0]))
{
if (line[0] == '#')
continue;
char *carrige_return = strchr(line, '\r');
if (carrige_return)
*carrige_return = '\0';
char *newline = strchr(line, '\n');
if (newline)
*newline = '\0';
if (line[0] != '\0')
{
char disk_label[PATH_MAX];
disk_label[0] = '\0';
snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
disks[disk_count].fname = strdup(name);
get_disk_label(disk_label, name, PATH_MAX);
disks[disk_count].flabel = strdup(disk_label);
disk_count++;
}
}
fclose(f);
return (disk_count != 0);
}
/* end of multi disk support */
static const char * const biosfiles_us[] = {
"us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210", "bios_CD_U"
@ -1175,10 +1328,28 @@ static void set_memory_maps(void)
bool retro_load_game(const struct retro_game_info *info)
{
const struct retro_game_info_ext *info_ext = NULL;
const unsigned char *content_data = NULL;
size_t content_size = 0;
char content_path[PATH_MAX];
char content_ext[8];
char carthw_path[PATH_MAX];
enum media_type_e media_type;
static char carthw_path[256];
size_t i;
#if defined(_WIN32)
char slash = '\\';
#else
char slash = '/';
#endif
content_path[0] = '\0';
content_ext[0] = '\0';
carthw_path[0] = '\0';
unsigned int cd_index = 0;
bool is_m3u = false;
struct retro_input_descriptor desc[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
@ -1257,6 +1428,73 @@ bool retro_load_game(const struct retro_game_info *info)
{ 0 },
};
struct retro_input_descriptor desc_pico[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left (violet)" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up (white)" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down (orange)" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right (green)" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Red Button" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Pen Button" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT,"Switch input" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Previous page" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Next page" },
{ 0 },
};
/* Attempt to fetch extended game info */
if (environ_cb(RETRO_ENVIRONMENT_GET_GAME_INFO_EXT, &info_ext))
{
#if !defined(LOW_MEMORY)
content_data = (const unsigned char *)info_ext->data;
content_size = info_ext->size;
#endif
strncpy(base_dir, info_ext->dir, sizeof(base_dir));
base_dir[sizeof(base_dir) - 1] = '\0';
strncpy(content_ext, info_ext->ext, sizeof(content_ext));
content_ext[sizeof(content_ext) - 1] = '\0';
if (info_ext->file_in_archive)
{
/* We don't have a 'physical' file in this
* case, but the core still needs a filename
* in order to detect media type. We therefore
* fake it, using the content directory,
* canonical content name, and content file
* extension */
snprintf(content_path, sizeof(content_path), "%s%c%s.%s",
base_dir, slash, info_ext->name, content_ext);
}
else
{
strncpy(content_path, info_ext->full_path, sizeof(content_path));
content_path[sizeof(content_path) - 1] = '\0';
}
}
else
{
const char *ext = NULL;
if (!info || !info->path)
{
if (log_cb)
log_cb(RETRO_LOG_ERROR, "info->path required\n");
return false;
}
extract_directory(base_dir, info->path, sizeof(base_dir));
strncpy(content_path, info->path, sizeof(content_path));
content_path[sizeof(content_path) - 1] = '\0';
if ((ext = strrchr(info->path, '.')))
{
strncpy(content_ext, ext + 1, sizeof(content_ext));
content_ext[sizeof(content_ext) - 1] = '\0';
}
}
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
if (log_cb)
@ -1264,27 +1502,59 @@ bool retro_load_game(const struct retro_game_info *info)
return false;
}
if (info == NULL || info->path == NULL) {
if (log_cb)
log_cb(RETRO_LOG_ERROR, "info->path required\n");
return false;
disk_init();
is_m3u = (strcasestr(content_ext, "m3u") != NULL);
if (is_m3u)
{
if (!read_m3u(content_path))
{
log_cb(RETRO_LOG_INFO, "failed to read m3u file\n");
return false;
}
strncpy(content_path, disks[0].fname, sizeof(content_path));
content_path[sizeof(content_path) - 1] = '\0';
}
else
{
char disk_label[PATH_MAX];
disk_label[0] = '\0';
disk_current_index = 0;
disk_count = 1;
disks[0].fname = strdup(content_path);
get_disk_label(disk_label, content_path, PATH_MAX);
disks[0].flabel = strdup(disk_label);
}
for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
if (disks[i].fname != NULL) {
free(disks[i].fname);
disks[i].fname = NULL;
/* If this is an M3U file, attempt to set the
* initial disk image */
if (is_m3u && (disk_initial_index > 0) && (disk_initial_index < disk_count))
{
const char *fname = disks[disk_initial_index].fname;
if (fname && (*fname != '\0'))
if (strcmp(disk_initial_path, fname) == 0)
cd_index = disk_initial_index;
/* If we are not loading the first disk in the
* M3U list, update the content_path string
* that will be passed to PicoLoadMedia() */
if (cd_index != 0)
{
strncpy(content_path, disks[cd_index].fname, sizeof(content_path));
content_path[sizeof(content_path) - 1] = '\0';
}
}
disk_current_index = 0;
disk_count = 1;
disks[0].fname = strdup(info->path);
make_system_path(carthw_path, sizeof(carthw_path), "carthw", ".cfg");
media_type = PicoLoadMedia(info->path, carthw_path,
find_bios, NULL);
media_type = PicoLoadMedia(content_path, content_data, content_size,
carthw_path, find_bios, NULL);
disk_current_index = cd_index;
switch (media_type) {
case PM_BAD_DETECT:
@ -1307,7 +1577,9 @@ bool retro_load_game(const struct retro_game_info *info)
break;
}
if (media_type == PM_MARK3)
if (PicoIn.AHW & PAHW_PICO)
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc_pico);
else if (PicoIn.AHW & PAHW_SMS)
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc_sms);
else
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
@ -1736,12 +2008,85 @@ static void update_variables(bool first_run)
init_frameskip();
}
void emu_status_msg(const char *format, ...)
{
va_list vl;
int ret;
static char msg[512];
memset (msg, 0, sizeof(msg));
va_start(vl, format);
ret = vsnprintf(msg, sizeof(msg), format, vl);
va_end(vl);
static struct retro_message rmsg;
rmsg.msg = msg;
rmsg.frames = 600;
environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &rmsg);
}
void run_events_pico(unsigned int events)
{
int lim_x;
if (events & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT)) {
pico_inp_mode++;
if (pico_inp_mode > 2)
pico_inp_mode = 0;
switch (pico_inp_mode) {
case 2: emu_status_msg("Input: Pen on Pad"); break;
case 1: emu_status_msg("Input: Pen on Storyware"); break;
case 0: emu_status_msg("Input: Joystick");
PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
break;
}
}
if (events & (1 << RETRO_DEVICE_ID_JOYPAD_L)) {
PicoPicohw.page--;
if (PicoPicohw.page < 0)
PicoPicohw.page = 0;
emu_status_msg("Page %i", PicoPicohw.page);
}
if (events & (1 << RETRO_DEVICE_ID_JOYPAD_R)) {
PicoPicohw.page++;
if (PicoPicohw.page > 6)
PicoPicohw.page = 6;
emu_status_msg("Page %i", PicoPicohw.page);
}
if (pico_inp_mode == 0)
return;
/* handle other input modes */
if (PicoIn.pad[0] & 1) pico_pen_y--;
if (PicoIn.pad[0] & 2) pico_pen_y++;
if (PicoIn.pad[0] & 4) pico_pen_x--;
if (PicoIn.pad[0] & 8) pico_pen_x++;
PicoIn.pad[0] &= ~0x0f; // release UDLR
lim_x = (Pico.video.reg[12]&1) ? 319 : 255;
if (pico_pen_y < 8)
pico_pen_y = 8;
if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)
pico_pen_y = 224 - PICO_PEN_ADJUST_Y;
if (pico_pen_x < 0)
pico_pen_x = 0;
if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)
pico_pen_x = lim_x - PICO_PEN_ADJUST_X;
PicoPicohw.pen_pos[0] = pico_pen_x;
if (!(Pico.video.reg[12] & 1))
PicoPicohw.pen_pos[0] += pico_pen_x / 4;
PicoPicohw.pen_pos[0] += 0x3c;
PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
}
void retro_run(void)
{
bool updated = false;
int pad, i, padcount;
static void *buff;
int16_t input;
PicoIn.skipFrame = 0;
@ -1751,20 +2096,45 @@ void retro_run(void)
input_poll_cb();
PicoIn.pad[0] = PicoIn.pad[1] = PicoIn.pad[2] = PicoIn.pad[3] = 0;
padcount = has_4_pads && !(PicoIn.AHW & (PAHW_SMS|PAHW_PICO)) ? 4 : 2;
for (pad = 0; pad < padcount; pad++) {
if (libretro_supports_bitmasks) {
input = input_state_cb(pad, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
for (i = 0; i < RETRO_PICO_MAP_LEN; i++)
if (input & (1 << i))
PicoIn.pad[pad] |= retro_pico_map[i];
} else {
if (PicoIn.AHW & PAHW_PICO)
padcount = 1;
else if (PicoIn.AHW & PAHW_SMS)
padcount = 2;
else
padcount = has_4_pads ? 4 : 2;
int16_t input[4] = {0, 0};
if (libretro_supports_bitmasks)
{
for (pad = 0; pad < padcount; pad++)
{
input[pad] = input_state_cb(
pad, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
}
}
else
{
for (pad = 0; pad < padcount; pad++)
{
for (i = 0; i < RETRO_PICO_MAP_LEN; i++)
if (input_state_cb(pad, RETRO_DEVICE_JOYPAD, 0, i))
PicoIn.pad[pad] |= retro_pico_map[i];
input[pad] |= 1 << i;
}
}
for (pad = 0; pad < padcount; pad++)
for (i = 0; i < RETRO_PICO_MAP_LEN; i++)
if (input[pad] & (1 << i))
PicoIn.pad[pad] |= retro_pico_map[i];
if (PicoIn.AHW == PAHW_PICO) {
uint16_t ev = input[0] & ((1 << RETRO_DEVICE_ID_JOYPAD_L) | (1 << RETRO_DEVICE_ID_JOYPAD_R) | (1 << RETRO_DEVICE_ID_JOYPAD_SELECT));
uint16_t new_ev = ev & ~pico_events;
pico_events = ev;
run_events_pico(new_ev);
}
if (PicoPatches)
PicoPatchApply();
@ -1906,12 +2276,12 @@ void retro_run(void)
buff = (char*)vout_buf + vout_offset;
#endif
video_cb((short *)buff,
vout_width, vout_height, vout_width * 2);
video_cb((short *)buff, vout_width, vout_height, vout_width * 2);
}
void retro_init(void)
{
unsigned dci_version = 0;
struct retro_log_callback log;
int level;
@ -1928,6 +2298,13 @@ void retro_init(void)
if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
libretro_supports_bitmasks = true;
disk_initial_index = 0;
disk_initial_path[0] = '\0';
if (environ_cb(RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION, &dci_version) && (dci_version >= 1))
environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE, &disk_control_ext);
else
environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
#ifdef _3DS
ctr_svchack_successful = ctr_svchack_init();
check_rosalina();
@ -2004,12 +2381,7 @@ void retro_deinit(void)
PicoExit();
for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
if (disks[i].fname != NULL) {
free(disks[i].fname);
disks[i].fname = NULL;
}
}
disk_init();
libretro_supports_bitmasks = false;
}

View file

@ -266,7 +266,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
"picodrive_audio_filter",
"Audio Filter",
NULL,
"Enable a low pass audio filter to better simulate the characteristic sound of a Model 1 Mega Drive/Genesis. Note that although only the Genesis and its add-on hardware (Sega CD, 32X) employed a physical low pass filter, the filter setting is not restricted to that.",
"Enable a low pass audio filter to better simulate the characteristic sound of a Model 1 Mega Drive/Genesis. Note that only Model 1 and its add-ons (Sega CD, 32X) employed a physical low pass filter.",
NULL,
"audio",
{

View file

@ -35,7 +35,7 @@ void pemu_prep_defconfig(void)
void pemu_validate_config(void)
{
#if !defined(__arm__) && !defined(__aarch64__) && !defined(__mips__) && !defined(__riscv__) && !defined(__riscv) && !defined(__powerpc__) && !defined(__ppc__) && !defined(__i386__) && !defined(__x86_64__)
#if !defined(__arm__) && !defined(__aarch64__) && !defined(__mips__) && !defined(__riscv__) && !defined(__riscv) && !defined(__powerpc__) && !defined(__ppc__) && !defined(__PPC__) && !defined(__i386__) && !defined(__x86_64__)
PicoIn.opt &= ~POPT_EN_DRC;
#endif
}