1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

add libretro port

This commit is contained in:
宋文武 2024-10-12 21:23:35 +08:00
parent b19611e841
commit e2eccdb216
11 changed files with 5733 additions and 0 deletions

3
.gitmodules vendored
View file

@ -16,3 +16,6 @@
[submodule "third_party/SheenBidi"] [submodule "third_party/SheenBidi"]
path = third_party/SheenBidi path = third_party/SheenBidi
url = https://github.com/Tehreer/SheenBidi url = https://github.com/Tehreer/SheenBidi
[submodule "third_party/SDL"]
path = third_party/SDL
url = https://github.com/libsdl-org/SDL.git

View file

@ -23,6 +23,8 @@ endif()
option(REMOVE_ABSOLUTE_PATHS "If supported by the compiler, replace all absolute paths to source directories compiled into the binary (if any) with relative paths" ON) option(REMOVE_ABSOLUTE_PATHS "If supported by the compiler, replace all absolute paths to source directories compiled into the binary (if any) with relative paths" ON)
option(BUILD_LIBRETRO "Build a libretro core" OFF)
option(LIBRETRO_STATIC "Statically link the libretro core" OFF)
# Architecture Flags # Architecture Flags
if(APPLE) if(APPLE)
@ -136,6 +138,30 @@ if(WIN32)
add_executable(VVVVVV WIN32 ${VVV_SRC} icon.rc) add_executable(VVVVVV WIN32 ${VVV_SRC} icon.rc)
elseif(ANDROID) elseif(ANDROID)
add_library(VVVVVV SHARED ${VVV_SRC}) add_library(VVVVVV SHARED ${VVV_SRC})
elseif(BUILD_LIBRETRO)
set(BUNDLE_DEPENDENCIES ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(libretro)
set(SDL2_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/third_party/SDL/include)
set(SDL2_LIBRARIES sdl2)
list(APPEND VVV_SRC libretro/libretro.c libretro/SDL_libretro.c)
if (LIBRETRO_STATIC)
add_library(VVVVVV STATIC ${VVV_SRC})
else()
add_library(VVVVVV SHARED ${VVV_SRC})
endif()
# Follow naming conventions for libretro cores
set_target_properties(VVVVVV PROPERTIES
PREFIX ""
OUTPUT_NAME "vvvvvv_libretro"
)
target_link_options(VVVVVV PRIVATE
-Wl,--version-script=${CMAKE_SOURCE_DIR}/libretro/link.T
-Wl,--no-undefined
-lm -ldl -pthread
)
else() else()
add_executable(VVVVVV ${VVV_SRC}) add_executable(VVVVVV ${VVV_SRC})
endif() endif()

View file

@ -0,0 +1,112 @@
# configure SDL2 for libretro
file(COPY SDL_config.h DESTINATION ${CMAKE_SOURCE_DIR}/../third_party/SDL/include)
file(COPY SDL_dynapi.h DESTINATION ${CMAKE_SOURCE_DIR}/../third_party/SDL/src/dynapi)
add_library(sdl2 STATIC
../../third_party/SDL/src/SDL.c
../../third_party/SDL/src/SDL_assert.c
../../third_party/SDL/src/SDL_dataqueue.c
../../third_party/SDL/src/SDL_error.c
../../third_party/SDL/src/SDL_guid.c
../../third_party/SDL/src/SDL_hints.c
../../third_party/SDL/src/SDL_list.c
../../third_party/SDL/src/SDL_log.c
../../third_party/SDL/src/SDL_utils.c
../../third_party/SDL/src/atomic/SDL_atomic.c
../../third_party/SDL/src/atomic/SDL_spinlock.c
../../third_party/SDL/src/audio/SDL_audio.c
../../third_party/SDL/src/audio/SDL_audiocvt.c
../../third_party/SDL/src/audio/SDL_audiodev.c
../../third_party/SDL/src/audio/SDL_audiotypecvt.c
../../third_party/SDL/src/audio/SDL_mixer.c
../../third_party/SDL/src/audio/SDL_wave.c
../../third_party/SDL/src/loadso/dlopen/SDL_sysloadso.c
../../third_party/SDL/src/core/linux/SDL_threadprio.c
../../third_party/SDL/src/filesystem/unix/SDL_sysfilesystem.c
../../third_party/SDL/src/cpuinfo/SDL_cpuinfo.c
../../third_party/SDL/src/dynapi/SDL_dynapi.c
../../third_party/SDL/src/events/SDL_clipboardevents.c
../../third_party/SDL/src/events/SDL_displayevents.c
../../third_party/SDL/src/events/SDL_dropevents.c
../../third_party/SDL/src/events/SDL_events.c
../../third_party/SDL/src/events/SDL_gesture.c
../../third_party/SDL/src/events/SDL_keyboard.c
../../third_party/SDL/src/events/SDL_keysym_to_scancode.c
../../third_party/SDL/src/events/SDL_mouse.c
../../third_party/SDL/src/events/SDL_quit.c
../../third_party/SDL/src/events/SDL_scancode_tables.c
../../third_party/SDL/src/events/SDL_touch.c
../../third_party/SDL/src/events/SDL_windowevents.c
../../third_party/SDL/src/events/imKStoUCS.c
../../third_party/SDL/src/file/SDL_rwops.c
../../third_party/SDL/src/joystick/SDL_gamecontroller.c
../../third_party/SDL/src/joystick/SDL_joystick.c
../../third_party/SDL/src/joystick/SDL_steam_virtual_gamepad.c
../../third_party/SDL/src/joystick/controller_type.c
../../third_party/SDL/src/joystick/dummy/SDL_sysjoystick.c
../../third_party/SDL/src/haptic/SDL_haptic.c
../../third_party/SDL/src/haptic/dummy/SDL_syshaptic.c
../../third_party/SDL/src/render/SDL_d3dmath.c
../../third_party/SDL/src/render/SDL_render.c
../../third_party/SDL/src/render/SDL_yuv_sw.c
../../third_party/SDL/src/render/opengl/SDL_render_gl.c
../../third_party/SDL/src/render/opengl/SDL_shaders_gl.c
../../third_party/SDL/src/render/opengles/SDL_render_gles.c
../../third_party/SDL/src/render/opengles2/SDL_render_gles2.c
../../third_party/SDL/src/render/opengles2/SDL_shaders_gles2.c
../../third_party/SDL/src/render/software/SDL_blendfillrect.c
../../third_party/SDL/src/render/software/SDL_blendline.c
../../third_party/SDL/src/render/software/SDL_blendpoint.c
../../third_party/SDL/src/render/software/SDL_drawline.c
../../third_party/SDL/src/render/software/SDL_drawpoint.c
../../third_party/SDL/src/render/software/SDL_render_sw.c
../../third_party/SDL/src/render/software/SDL_rotate.c
../../third_party/SDL/src/render/software/SDL_triangle.c
../../third_party/SDL/src/stdlib/SDL_crc16.c
../../third_party/SDL/src/stdlib/SDL_crc32.c
../../third_party/SDL/src/stdlib/SDL_getenv.c
../../third_party/SDL/src/stdlib/SDL_iconv.c
../../third_party/SDL/src/stdlib/SDL_malloc.c
../../third_party/SDL/src/stdlib/SDL_mslibc.c
../../third_party/SDL/src/stdlib/SDL_qsort.c
../../third_party/SDL/src/stdlib/SDL_stdlib.c
../../third_party/SDL/src/stdlib/SDL_string.c
../../third_party/SDL/src/stdlib/SDL_strtokr.c
../../third_party/SDL/src/thread/SDL_thread.c
../../third_party/SDL/src/thread/pthread/SDL_syscond.c
../../third_party/SDL/src/thread/pthread/SDL_sysmutex.c
../../third_party/SDL/src/thread/pthread/SDL_syssem.c
../../third_party/SDL/src/thread/pthread/SDL_systhread.c
../../third_party/SDL/src/thread/pthread/SDL_systls.c
../../third_party/SDL/src/timer/SDL_timer.c
../../third_party/SDL/src/timer/unix/SDL_systimer.c
../../third_party/SDL/src/video/SDL_RLEaccel.c
../../third_party/SDL/src/video/SDL_blit.c
../../third_party/SDL/src/video/SDL_blit_0.c
../../third_party/SDL/src/video/SDL_blit_1.c
../../third_party/SDL/src/video/SDL_blit_A.c
../../third_party/SDL/src/video/SDL_blit_N.c
../../third_party/SDL/src/video/SDL_blit_auto.c
../../third_party/SDL/src/video/SDL_blit_copy.c
../../third_party/SDL/src/video/SDL_blit_slow.c
../../third_party/SDL/src/video/SDL_bmp.c
../../third_party/SDL/src/video/SDL_clipboard.c
../../third_party/SDL/src/video/SDL_egl.c
../../third_party/SDL/src/video/SDL_fillrect.c
../../third_party/SDL/src/video/SDL_pixels.c
../../third_party/SDL/src/video/SDL_rect.c
../../third_party/SDL/src/video/SDL_shape.c
../../third_party/SDL/src/video/SDL_stretch.c
../../third_party/SDL/src/video/SDL_surface.c
../../third_party/SDL/src/video/SDL_video.c
../../third_party/SDL/src/video/SDL_vulkan_utils.c
../../third_party/SDL/src/video/SDL_yuv.c
../../third_party/SDL/src/video/yuv2rgb/yuv_rgb_lsx.c
../../third_party/SDL/src/video/yuv2rgb/yuv_rgb_sse.c
../../third_party/SDL/src/video/yuv2rgb/yuv_rgb_std.c
../../third_party/SDL/src/misc/SDL_url.c
../../third_party/SDL/src/misc/unix/SDL_sysurl.c
)
target_include_directories(sdl2 PUBLIC
../../third_party/SDL/include
)

View file

@ -0,0 +1,554 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_config_h_
#define SDL_config_h_
/**
* \file SDL_config.h.in
*
* This is a set of defines to configure the SDL features
*/
/* General platform specific identifiers */
#include "SDL_platform.h"
/* C language features */
/* #undef const */
/* #undef inline */
/* #undef volatile */
/* C datatypes */
/* Define SIZEOF_VOIDP for 64/32 architectures */
#if defined(__LP64__) || defined(_LP64) || defined(_WIN64)
#define SIZEOF_VOIDP 8
#else
#define SIZEOF_VOIDP 4
#endif
#define HAVE_GCC_ATOMICS 1
/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */
/* Comment this if you want to build without any C library requirements */
#define HAVE_LIBC 1
#ifdef HAVE_LIBC
/* Useful headers */
#define STDC_HEADERS 1
#define HAVE_ALLOCA_H 1
#define HAVE_CTYPE_H 1
#define HAVE_FLOAT_H 1
#define HAVE_ICONV_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_LIMITS_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MATH_H 1
#define HAVE_MEMORY_H 1
#define HAVE_SIGNAL_H 1
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDIO_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_WCHAR_H 1
/* #define HAVE_LINUX_INPUT_H 1 */
/* #undef HAVE_PTHREAD_NP_H */
/* #define HAVE_LIBUNWIND_H 1 */
/* C library functions */
/* #define HAVE_DLOPEN 1 */
#define HAVE_MALLOC 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
#define HAVE_ALLOCA 1
#ifndef __WIN32__ /* Don't use C runtime versions of these on Windows */
#define HAVE_GETENV 1
#define HAVE_SETENV 1
#define HAVE_PUTENV 1
#define HAVE_UNSETENV 1
#endif
#define HAVE_QSORT 1
#define HAVE_BSEARCH 1
#define HAVE_ABS 1
#define HAVE_BCOPY 1
#define HAVE_MEMSET 1
#define HAVE_MEMCPY 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMCMP 1
#define HAVE_WCSLEN 1
/* #define HAVE_WCSLCPY 1 */
/* #define HAVE_WCSLCAT 1 */
/* #undef HAVE__WCSDUP */
#define HAVE_WCSDUP 1
#define HAVE_WCSSTR 1
#define HAVE_WCSCMP 1
#define HAVE_WCSNCMP 1
#define HAVE_WCSCASECMP 1
/* #undef HAVE__WCSICMP */
#define HAVE_WCSNCASECMP 1
/* #undef HAVE__WCSNICMP */
#define HAVE_STRLEN 1
/* #define HAVE_STRLCPY 1 */
/* #define HAVE_STRLCAT 1 */
/* #undef HAVE__STRREV */
/* #undef HAVE__STRUPR */
/* #undef HAVE__STRLWR */
#define HAVE_INDEX 1
#define HAVE_RINDEX 1
#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
#define HAVE_STRTOK_R 1
/* #undef HAVE_ITOA */
/* #undef HAVE__LTOA */
/* #undef HAVE__UITOA */
/* #undef HAVE__ULTOA */
#define HAVE_STRTOL 1
#define HAVE_STRTOUL 1
/* #undef HAVE__I64TOA */
/* #undef HAVE__UI64TOA */
#define HAVE_STRTOLL 1
#define HAVE_STRTOULL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
/* #undef HAVE__STRICMP */
#define HAVE_STRCASECMP 1
/* #undef HAVE__STRNICMP */
#define HAVE_STRNCASECMP 1
#define HAVE_STRCASESTR 1
#define HAVE_SSCANF 1
#define HAVE_VSSCANF 1
#define HAVE_VSNPRINTF 1
#define HAVE_M_PI 1
#define HAVE_ACOS 1
#define HAVE_ACOSF 1
#define HAVE_ASIN 1
#define HAVE_ASINF 1
#define HAVE_ATAN 1
#define HAVE_ATANF 1
#define HAVE_ATAN2 1
#define HAVE_ATAN2F 1
#define HAVE_CEIL 1
#define HAVE_CEILF 1
#define HAVE_COPYSIGN 1
#define HAVE_COPYSIGNF 1
#define HAVE_COS 1
#define HAVE_COSF 1
#define HAVE_EXP 1
#define HAVE_EXPF 1
#define HAVE_FABS 1
#define HAVE_FABSF 1
#define HAVE_FLOOR 1
#define HAVE_FLOORF 1
#define HAVE_FMOD 1
#define HAVE_FMODF 1
#define HAVE_LOG 1
#define HAVE_LOGF 1
#define HAVE_LOG10 1
#define HAVE_LOG10F 1
#define HAVE_LROUND 1
#define HAVE_LROUNDF 1
#define HAVE_POW 1
#define HAVE_POWF 1
#define HAVE_ROUND 1
#define HAVE_ROUNDF 1
#define HAVE_SCALBN 1
#define HAVE_SCALBNF 1
#define HAVE_SIN 1
#define HAVE_SINF 1
#define HAVE_SQRT 1
#define HAVE_SQRTF 1
#define HAVE_TAN 1
#define HAVE_TANF 1
#define HAVE_TRUNC 1
#define HAVE_TRUNCF 1
#define HAVE_FOPEN64 1
#define HAVE_FSEEKO 1
#define HAVE_FSEEKO64 1
#define HAVE_MEMFD_CREATE 1
#define HAVE_POSIX_FALLOCATE 1
#define HAVE_SIGACTION 1
#define HAVE_SA_SIGACTION 1
#define HAVE_SETJMP 1
#define HAVE_NANOSLEEP 1
#define HAVE_SYSCONF 1
/* #undef HAVE_SYSCTLBYNAME */
#define HAVE_CLOCK_GETTIME 1
/* #undef HAVE_GETPAGESIZE */
#define HAVE_MPROTECT 1
#define HAVE_ICONV 1
/* #undef SDL_USE_LIBICONV */
#define HAVE_PTHREAD_SETNAME_NP 1
/* #undef HAVE_PTHREAD_SET_NAME_NP */
#define HAVE_SEM_TIMEDWAIT 1
#define HAVE_GETAUXVAL 1
/* #undef HAVE_ELF_AUX_INFO */
#define HAVE_POLL 1
#define HAVE__EXIT 1
#else
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
#define HAVE_STDINT_H 1
#define HAVE_FLOAT_H 1
#endif /* HAVE_LIBC */
/* #undef HAVE_ALTIVEC_H */
/* #define HAVE_DBUS_DBUS_H 0 */
/* #define HAVE_FCITX 0 */
/* #define HAVE_IBUS_IBUS_H 0 */
/* #define HAVE_SYS_INOTIFY_H 0 */
/* #define HAVE_INOTIFY_INIT 0 */
/* #define HAVE_INOTIFY_INIT1 0 */
/* #define HAVE_INOTIFY 0 */
/* #undef HAVE_LIBUSB */
#define HAVE_O_CLOEXEC 1
/* Apple platforms might be building universal binaries, where Intel builds
can use immintrin.h but other architectures can't. */
#ifdef __APPLE__
# if defined(__has_include) && (defined(__i386__) || defined(__x86_64))
# if __has_include(<immintrin.h>)
# define HAVE_IMMINTRIN_H 1
# endif
# endif
#else /* non-Apple platforms can use the normal CMake check for this. */
/* #define HAVE_IMMINTRIN_H 1 */
#endif
/* #define HAVE_LIBUDEV_H 1 */
/* #define HAVE_LIBSAMPLERATE_H 1 */
/* #define HAVE_LIBDECOR_H 1 */
/* #undef HAVE_D3D_H */
/* #undef HAVE_D3D11_H */
/* #undef HAVE_D3D12_H */
/* #undef HAVE_DDRAW_H */
/* #undef HAVE_DSOUND_H */
/* #undef HAVE_DINPUT_H */
/* #undef HAVE_XINPUT_H */
/* #undef HAVE_WINDOWS_GAMING_INPUT_H */
/* #undef HAVE_DXGI_H */
/* #undef HAVE_MMDEVICEAPI_H */
/* #undef HAVE_AUDIOCLIENT_H */
/* #undef HAVE_TPCSHRD_H */
/* #undef HAVE_SENSORSAPI_H */
/* #undef HAVE_ROAPI_H */
/* #undef HAVE_SHELLSCALINGAPI_H */
/* #undef USE_POSIX_SPAWN */
/* SDL internal assertion support */
#if 0
/* #undef SDL_DEFAULT_ASSERT_LEVEL */
#endif
/* Allow disabling of core subsystems */
/* #undef SDL_ATOMIC_DISABLED */
/* #undef SDL_AUDIO_DISABLED */
/* #undef SDL_CPUINFO_DISABLED */
/* #undef SDL_EVENTS_DISABLED */
/* #undef SDL_FILE_DISABLED */
/* #undef SDL_JOYSTICK_DISABLED */
/* #undef SDL_HAPTIC_DISABLED */
/* #undef SDL_HIDAPI_DISABLED */
/* #undef SDL_SENSOR_DISABLED */
/* #undef SDL_LOADSO_DISABLED */
/* #undef SDL_RENDER_DISABLED */
/* #undef SDL_THREADS_DISABLED */
/* #undef SDL_TIMERS_DISABLED */
/* #undef SDL_VIDEO_DISABLED */
/* #undef SDL_POWER_DISABLED */
/* #undef SDL_FILESYSTEM_DISABLED */
/* #undef SDL_LOCALE_DISABLED */
/* #undef SDL_MISC_DISABLED */
#define SDL_HAPTIC_DISABLED 1
#define SDL_HIDAPI_DISABLED 1
#define SDL_SENSOR_DISABLED 1
#define SDL_POWER_DISABLED 1
/* Enable various audio drivers */
/* #define SDL_AUDIO_DRIVER_ALSA 1 */
/* #define SDL_AUDIO_DRIVER_ALSA_DYNAMIC "libasound.so.2" */
/* #undef SDL_AUDIO_DRIVER_ANDROID */
/* #undef SDL_AUDIO_DRIVER_OPENSLES */
/* #undef SDL_AUDIO_DRIVER_AAUDIO */
/* #undef SDL_AUDIO_DRIVER_ARTS */
/* #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_COREAUDIO */
/* #define SDL_AUDIO_DRIVER_DISK 1 */
/* #undef SDL_AUDIO_DRIVER_DSOUND */
#define SDL_AUDIO_DRIVER_DUMMY 1
/* #undef SDL_AUDIO_DRIVER_EMSCRIPTEN */
/* #undef SDL_AUDIO_DRIVER_ESD */
/* #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND */
/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_HAIKU */
/* #define SDL_AUDIO_DRIVER_JACK 1 */
/* #define SDL_AUDIO_DRIVER_JACK_DYNAMIC "libjack.so.0" */
/* #undef SDL_AUDIO_DRIVER_NAS */
/* #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_NETBSD */
/* #define SDL_AUDIO_DRIVER_OSS 1 */
/* #undef SDL_AUDIO_DRIVER_PAUDIO */
/* #define SDL_AUDIO_DRIVER_PIPEWIRE 1 */
/* #define SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "libpipewire-0.3.so.0" */
/* #define SDL_AUDIO_DRIVER_PULSEAUDIO 1 */
/* #define SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "libpulse.so.0" */
/* #undef SDL_AUDIO_DRIVER_QSA */
/* #undef SDL_AUDIO_DRIVER_SNDIO */
/* #undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_SUNAUDIO */
/* #undef SDL_AUDIO_DRIVER_WASAPI */
/* #undef SDL_AUDIO_DRIVER_WINMM */
/* #undef SDL_AUDIO_DRIVER_OS2 */
/* #undef SDL_AUDIO_DRIVER_VITA */
/* #undef SDL_AUDIO_DRIVER_PSP */
/* #undef SDL_AUDIO_DRIVER_PS2 */
/* #undef SDL_AUDIO_DRIVER_N3DS */
/* Enable various input drivers */
/* #define SDL_INPUT_LINUXEV 1 */
/* #define SDL_INPUT_LINUXKD 1 */
/* #undef SDL_INPUT_FBSDKBIO */
/* #undef SDL_INPUT_WSCONS */
/* #undef SDL_JOYSTICK_ANDROID */
/* #undef SDL_JOYSTICK_HAIKU */
/* #undef SDL_JOYSTICK_WGI */
/* #undef SDL_JOYSTICK_DINPUT */
/* #undef SDL_JOYSTICK_XINPUT */
#define SDL_JOYSTICK_DUMMY 1
/* #undef SDL_JOYSTICK_IOKIT */
/* #undef SDL_JOYSTICK_MFI */
/* #define SDL_JOYSTICK_LINUX 1 */
/* #undef SDL_JOYSTICK_OS2 */
/* #undef SDL_JOYSTICK_USBHID */
/* #undef SDL_HAVE_MACHINE_JOYSTICK_H */
/* #define SDL_JOYSTICK_HIDAPI 1 */
/* #undef SDL_JOYSTICK_RAWINPUT */
/* #undef SDL_JOYSTICK_EMSCRIPTEN */
/* #define SDL_JOYSTICK_VIRTUAL 1 */
/* #undef SDL_JOYSTICK_VITA */
/* #undef SDL_JOYSTICK_PSP */
/* #undef SDL_JOYSTICK_PS2 */
/* #undef SDL_JOYSTICK_N3DS */
/* #undef SDL_HAPTIC_DUMMY */
/* #define SDL_HAPTIC_LINUX 1 */
/* #undef SDL_HAPTIC_IOKIT */
/* #undef SDL_HAPTIC_DINPUT */
/* #undef SDL_HAPTIC_XINPUT */
/* #undef SDL_HAPTIC_ANDROID */
/* #undef SDL_LIBUSB_DYNAMIC */
/* #define SDL_UDEV_DYNAMIC "libudev.so.1" */
/* Enable various sensor drivers */
/* #undef SDL_SENSOR_ANDROID */
/* #undef SDL_SENSOR_COREMOTION */
/* #undef SDL_SENSOR_WINDOWS */
/* #define SDL_SENSOR_DUMMY 1 */
/* #undef SDL_SENSOR_VITA */
/* #undef SDL_SENSOR_N3DS */
/* Enable various shared object loading systems */
/* #define SDL_LOADSO_DLOPEN 1 */
#define SDL_LOADSO_DLOPEN 1
/* #undef SDL_LOADSO_DUMMY */
/* #undef SDL_LOADSO_LDG */
/* #undef SDL_LOADSO_WINDOWS */
/* #undef SDL_LOADSO_OS2 */
/* Enable various threading systems */
/* #undef SDL_THREAD_GENERIC_COND_SUFFIX */
#define SDL_THREAD_PTHREAD 1
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP */
/* #undef SDL_THREAD_WINDOWS */
/* #undef SDL_THREAD_OS2 */
/* #undef SDL_THREAD_VITA */
/* #undef SDL_THREAD_PSP */
/* #undef SDL_THREAD_PS2 */
/* #undef SDL_THREAD_N3DS */
/* Enable various timer systems */
/* #undef SDL_TIMER_HAIKU */
/* #undef SDL_TIMER_DUMMY */
#define SDL_TIMER_UNIX 1
/* #undef SDL_TIMER_WINDOWS */
/* #undef SDL_TIMER_OS2 */
/* #undef SDL_TIMER_VITA */
/* #undef SDL_TIMER_PSP */
/* #undef SDL_TIMER_PS2 */
/* #undef SDL_TIMER_N3DS */
/* Enable various video drivers */
/* #undef SDL_VIDEO_DRIVER_ANDROID */
/* #undef SDL_VIDEO_DRIVER_EMSCRIPTEN */
/* #undef SDL_VIDEO_DRIVER_HAIKU */
/* #undef SDL_VIDEO_DRIVER_COCOA */
/* #undef SDL_VIDEO_DRIVER_UIKIT */
/* #undef SDL_VIDEO_DRIVER_DIRECTFB */
/* #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC */
#define SDL_VIDEO_DRIVER_DUMMY 1
/* #define SDL_VIDEO_DRIVER_OFFSCREEN 1 */
/* #undef SDL_VIDEO_DRIVER_WINDOWS */
/* #undef SDL_VIDEO_DRIVER_WINRT */
/* #define SDL_VIDEO_DRIVER_WAYLAND 1 */
/* #undef SDL_VIDEO_DRIVER_RPI */
/* #undef SDL_VIDEO_DRIVER_VIVANTE */
/* #undef SDL_VIDEO_DRIVER_VIVANTE_VDK */
/* #undef SDL_VIDEO_DRIVER_OS2 */
/* #undef SDL_VIDEO_DRIVER_QNX */
/* #undef SDL_VIDEO_DRIVER_RISCOS */
/* #undef SDL_VIDEO_DRIVER_PSP */
/* #undef SDL_VIDEO_DRIVER_PS2 */
/* #define SDL_VIDEO_DRIVER_KMSDRM 1 */
/* #define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "libdrm.so.2" */
/* #define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "libgbm.so.1" */
/* #define SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1 */
/* #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "libwayland-client.so.0" */
/* #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "libwayland-egl.so.1" */
/* #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "libwayland-cursor.so.0" */
/* #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "libxkbcommon.so.0" */
/* #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "libdecor-0.so.0" */
/* #define SDL_VIDEO_DRIVER_X11 1 */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC "libX11.so.6" */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "libXext.so.6" */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "libXcursor.so.1" */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "libXi.so.6" */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES "libXfixes.so.3" */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "libXrandr.so.2" */
/* #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "libXss.so.1" */
/* #define SDL_VIDEO_DRIVER_X11_XCURSOR 1 */
/* #define SDL_VIDEO_DRIVER_X11_XDBE 1 */
/* #define SDL_VIDEO_DRIVER_X11_XINPUT2 1 */
/* #define SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1 */
/* #define SDL_VIDEO_DRIVER_X11_XFIXES 1 */
/* #define SDL_VIDEO_DRIVER_X11_XRANDR 1 */
/* #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1 */
/* #define SDL_VIDEO_DRIVER_X11_XSHAPE 1 */
/* #define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1 */
/* #define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1 */
/* #undef SDL_VIDEO_DRIVER_VITA */
/* #undef SDL_VIDEO_DRIVER_N3DS */
/* #undef SDL_VIDEO_RENDER_D3D */
/* #undef SDL_VIDEO_RENDER_D3D11 */
/* #undef SDL_VIDEO_RENDER_D3D12 */
/* #define SDL_VIDEO_RENDER_OGL 1 */
/* #undef SDL_VIDEO_RENDER_OGL_ES */
/* #define SDL_VIDEO_RENDER_OGL_ES2 1 */
/* #undef SDL_VIDEO_RENDER_DIRECTFB */
/* #undef SDL_VIDEO_RENDER_METAL */
/* #undef SDL_VIDEO_RENDER_VITA_GXM */
/* #undef SDL_VIDEO_RENDER_PS2 */
/* #undef SDL_VIDEO_RENDER_PSP */
/* Enable OpenGL support */
/* #define SDL_VIDEO_OPENGL 1 */
/* #undef SDL_VIDEO_OPENGL_ES */
/* #define SDL_VIDEO_OPENGL_ES2 1 */
/* #undef SDL_VIDEO_OPENGL_BGL */
/* #undef SDL_VIDEO_OPENGL_CGL */
/* #define SDL_VIDEO_OPENGL_GLX 1 */
/* #undef SDL_VIDEO_OPENGL_WGL */
/* #define SDL_VIDEO_OPENGL_EGL 1 */
/* #undef SDL_VIDEO_OPENGL_OSMESA */
/* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */
/* Enable Vulkan support */
/* #define SDL_VIDEO_VULKAN 1 */
/* Enable Metal support */
/* #undef SDL_VIDEO_METAL */
/* Enable system power support */
/* #undef SDL_POWER_ANDROID */
/* #define SDL_POWER_LINUX 1 */
/* #undef SDL_POWER_WINDOWS */
/* #undef SDL_POWER_WINRT */
/* #undef SDL_POWER_MACOSX */
/* #undef SDL_POWER_UIKIT */
/* #undef SDL_POWER_HAIKU */
/* #undef SDL_POWER_EMSCRIPTEN */
/* #undef SDL_POWER_HARDWIRED */
/* #undef SDL_POWER_VITA */
/* #undef SDL_POWER_PSP */
/* #undef SDL_POWER_N3DS */
/* Enable system filesystem support */
/* #undef SDL_FILESYSTEM_ANDROID */
/* #undef SDL_FILESYSTEM_HAIKU */
/* #undef SDL_FILESYSTEM_COCOA */
/* #undef SDL_FILESYSTEM_DUMMY */
/* #undef SDL_FILESYSTEM_RISCOS */
#define SDL_FILESYSTEM_UNIX 1
/* #undef SDL_FILESYSTEM_WINDOWS */
/* #undef SDL_FILESYSTEM_EMSCRIPTEN */
/* #undef SDL_FILESYSTEM_OS2 */
/* #undef SDL_FILESYSTEM_VITA */
/* #undef SDL_FILESYSTEM_PSP */
/* #undef SDL_FILESYSTEM_PS2 */
/* #undef SDL_FILESYSTEM_N3DS */
/* Enable misc subsystem */
/* #undef SDL_MISC_DUMMY */
/* Enable locale subsystem */
/* #undef SDL_LOCALE_DUMMY */
/* Enable assembly routines */
/* #undef SDL_ALTIVEC_BLITTERS */
/* #undef SDL_ARM_SIMD_BLITTERS */
/* #undef SDL_ARM_NEON_BLITTERS */
/* Whether SDL_DYNAMIC_API needs dlopen */
/* #define DYNAPI_NEEDS_DLOPEN 1 */
/* Enable dynamic libsamplerate support */
/* #define SDL_LIBSAMPLERATE_DYNAMIC "libsamplerate.so.0" */
/* Enable ime support */
/* #define SDL_USE_IME 1 */
/* Platform specific definitions */
/* #undef SDL_IPHONE_KEYBOARD */
/* #undef SDL_IPHONE_LAUNCHSCREEN */
/* #undef SDL_VIDEO_VITA_PIB */
/* #undef SDL_VIDEO_VITA_PVR */
/* #undef SDL_VIDEO_VITA_PVR_OGL */
/* #define SDL_HAVE_LIBDECOR_GET_MIN_MAX 1 */
#endif /* SDL_config_h_ */

View file

@ -0,0 +1,6 @@
#ifndef SDL_dynapi_h_
#define SDL_dynapi_h_
#define SDL_DYNAMIC_API 0
#endif

View file

@ -0,0 +1,330 @@
#include "SDL_libretro.h"
#include "../../third_party/SDL/src/audio/SDL_sysaudio.h"
#include "../../third_party/SDL/src/events/SDL_keyboard_c.h"
#include "../../third_party/SDL/src/video/SDL_sysvideo.h"
static SDL_Surface* _surface = NULL;
static SDL_Surface* _surface_real = NULL;
static SDL_AudioDevice* _audio = NULL;
static int
VideoInit(SDL_VideoDevice* device)
{
SDL_DisplayMode mode;
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 320;
mode.h = 240;
mode.refresh_rate = 60;
mode.driverdata = NULL;
SDL_AddBasicVideoDisplay(&mode);
return 0;
}
static void
VideoQuit(SDL_VideoDevice* device)
{
}
static void
VideoFree(SDL_VideoDevice* device)
{
SDL_free(device);
}
static void
PumpEvents(SDL_VideoDevice* device)
{
}
void
DestroyWindowFramebuffer(SDL_VideoDevice* device, SDL_Window* window)
{
if (_surface != NULL) {
SDL_FreeSurface(_surface);
_surface = NULL;
}
if (_surface_real != NULL) {
SDL_FreeSurface(_surface_real);
_surface_real = NULL;
}
}
int
CreateWindowFramebuffer(SDL_VideoDevice* device,
SDL_Window* window,
Uint32* format,
void** pixels,
int* pitch)
{
const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
int w, h;
/* Free the old framebuffer surface */
DestroyWindowFramebuffer(device, window);
/* Create a new one */
SDL_GetWindowSizeInPixels(window, &w, &h);
_surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
_surface_real = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format);
if (!_surface_real) {
return -1;
}
/* Save the info and return! */
*format = surface_format;
*pixels = _surface->pixels;
*pitch = _surface->pitch;
return 0;
}
int
UpdateWindowFramebuffer(SDL_VideoDevice* device,
SDL_Window* window,
const SDL_Rect* rects,
int numrects)
{
for (int i = 0; i < numrects; i += 1) {
SDL_BlitSurface(_surface, (SDL_Rect*)&rects[i], _surface_real, (SDL_Rect*)&rects[i]);
}
return 0;
}
static SDL_VideoDevice*
VideoCreate(void)
{
SDL_VideoDevice* device = SDL_malloc(sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(device);
device->is_dummy = SDL_FALSE;
device->VideoInit = VideoInit;
device->VideoQuit = VideoQuit;
device->PumpEvents = PumpEvents;
device->CreateWindowFramebuffer = CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = DestroyWindowFramebuffer;
device->free = VideoFree;
return device;
}
VideoBootStrap DUMMY_bootstrap = {
"libretro",
"SDL libretro video driver",
VideoCreate,
NULL,
};
static int
AudioOpen(SDL_AudioDevice* device, const char* devname)
{
device->hidden = (void*)0x1;
device->spec.freq = 44100;
device->spec.format = AUDIO_S16SYS;
device->spec.channels = 2;
device->spec.silence = 0;
device->spec.samples = 44100 / 60;
SDL_CalculateAudioSpec(&device->spec);
_audio = device;
return 0;
}
static void
AudioClose(SDL_AudioDevice* device)
{
_audio = NULL;
}
static SDL_bool
AudioInit(SDL_AudioDriverImpl* impl)
{
impl->OpenDevice = AudioOpen;
impl->CloseDevice = AudioClose;
impl->HasCaptureSupport = SDL_FALSE;
impl->AllowsArbitraryDeviceNames = SDL_TRUE;
impl->ProvidesOwnCallbackThread = SDL_TRUE;
impl->OnlyHasDefaultOutputDevice = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE;
}
AudioBootStrap DUMMYAUDIO_bootstrap = { "libretro",
"SDL libretro audio driver",
AudioInit,
SDL_FALSE };
void
SDL_libretro_RefreshVideo(retro_video_refresh_t video_cb)
{
if (_surface_real == NULL)
return;
video_cb(_surface_real->pixels,
_surface_real->w,
_surface_real->h,
_surface_real->pitch);
}
void
SDL_libretro_ProduceAudio(retro_audio_sample_batch_t audio_batch_cb)
{
if (_audio == NULL)
return;
while (SDL_AudioStreamAvailable(_audio->stream) < _audio->spec.size) {
_audio->callbackspec.callback(_audio->callbackspec.userdata,
_audio->work_buffer,
_audio->callbackspec.size);
SDL_AudioStreamPut(_audio->stream, _audio->work_buffer, _audio->callbackspec.size);
}
SDL_AudioStreamGet(_audio->stream, _audio->work_buffer, _audio->spec.size);
audio_batch_cb((const int16_t *)_audio->work_buffer, _audio->spec.samples);
}
void
SDL_libretro_KeyboardCallback(bool down,
unsigned keycode,
uint32_t character,
uint16_t key_modifiers)
{
static const SDL_Keycode keycodes[RETROK_LAST] = {
[RETROK_UNKNOWN] = SDLK_UNKNOWN,
[RETROK_BACKSPACE] = SDLK_BACKSPACE,
[RETROK_TAB] = SDLK_TAB,
[RETROK_CLEAR] = SDLK_CLEAR,
[RETROK_RETURN] = SDLK_RETURN,
[RETROK_PAUSE] = SDLK_PAUSE,
[RETROK_ESCAPE] = SDLK_ESCAPE,
[RETROK_SPACE] = SDLK_SPACE,
[RETROK_EXCLAIM] = SDLK_EXCLAIM,
[RETROK_QUOTEDBL] = SDLK_QUOTEDBL,
[RETROK_HASH] = SDLK_HASH,
[RETROK_DOLLAR] = SDLK_DOLLAR,
[RETROK_AMPERSAND] = SDLK_AMPERSAND,
[RETROK_QUOTE] = SDLK_QUOTE,
[RETROK_LEFTPAREN] = SDLK_LEFTPAREN,
[RETROK_RIGHTPAREN] = SDLK_RIGHTPAREN,
[RETROK_ASTERISK] = SDLK_ASTERISK,
[RETROK_PLUS] = SDLK_PLUS,
[RETROK_COMMA] = SDLK_COMMA,
[RETROK_MINUS] = SDLK_MINUS,
[RETROK_PERIOD] = SDLK_PERIOD,
[RETROK_SLASH] = SDLK_SLASH,
[RETROK_0] = SDLK_0,
[RETROK_1] = SDLK_1,
[RETROK_2] = SDLK_2,
[RETROK_3] = SDLK_3,
[RETROK_4] = SDLK_4,
[RETROK_5] = SDLK_5,
[RETROK_6] = SDLK_6,
[RETROK_7] = SDLK_7,
[RETROK_8] = SDLK_8,
[RETROK_9] = SDLK_9,
[RETROK_COLON] = SDLK_COLON,
[RETROK_SEMICOLON] = SDLK_SEMICOLON,
[RETROK_LESS] = SDLK_LESS,
[RETROK_EQUALS] = SDLK_EQUALS,
[RETROK_GREATER] = SDLK_GREATER,
[RETROK_QUESTION] = SDLK_QUESTION,
[RETROK_AT] = SDLK_AT,
[RETROK_LEFTBRACKET] = SDLK_LEFTBRACKET,
[RETROK_BACKSLASH] = SDLK_BACKSLASH,
[RETROK_RIGHTBRACKET] = SDLK_RIGHTBRACKET,
[RETROK_CARET] = SDLK_CARET,
[RETROK_UNDERSCORE] = SDLK_UNDERSCORE,
[RETROK_BACKQUOTE] = SDLK_BACKQUOTE,
[RETROK_a] = SDLK_a,
[RETROK_b] = SDLK_b,
[RETROK_c] = SDLK_c,
[RETROK_d] = SDLK_d,
[RETROK_e] = SDLK_e,
[RETROK_f] = SDLK_f,
[RETROK_g] = SDLK_g,
[RETROK_h] = SDLK_h,
[RETROK_i] = SDLK_i,
[RETROK_j] = SDLK_j,
[RETROK_k] = SDLK_k,
[RETROK_l] = SDLK_l,
[RETROK_m] = SDLK_m,
[RETROK_n] = SDLK_n,
[RETROK_o] = SDLK_o,
[RETROK_p] = SDLK_p,
[RETROK_q] = SDLK_q,
[RETROK_r] = SDLK_r,
[RETROK_s] = SDLK_s,
[RETROK_t] = SDLK_t,
[RETROK_u] = SDLK_u,
[RETROK_v] = SDLK_v,
[RETROK_w] = SDLK_w,
[RETROK_x] = SDLK_x,
[RETROK_y] = SDLK_y,
[RETROK_z] = SDLK_z,
[RETROK_DELETE] = SDLK_DELETE,
[RETROK_KP0] = SDLK_KP_0,
[RETROK_KP1] = SDLK_KP_1,
[RETROK_KP2] = SDLK_KP_2,
[RETROK_KP3] = SDLK_KP_3,
[RETROK_KP4] = SDLK_KP_4,
[RETROK_KP5] = SDLK_KP_5,
[RETROK_KP6] = SDLK_KP_6,
[RETROK_KP7] = SDLK_KP_7,
[RETROK_KP8] = SDLK_KP_8,
[RETROK_KP9] = SDLK_KP_9,
[RETROK_KP_PERIOD] = SDLK_KP_PERIOD,
[RETROK_KP_DIVIDE] = SDLK_KP_DIVIDE,
[RETROK_KP_MULTIPLY] = SDLK_KP_MULTIPLY,
[RETROK_KP_MINUS] = SDLK_KP_MINUS,
[RETROK_KP_PLUS] = SDLK_KP_PLUS,
[RETROK_KP_ENTER] = SDLK_KP_ENTER,
[RETROK_KP_EQUALS] = SDLK_KP_EQUALS,
[RETROK_UP] = SDLK_UP,
[RETROK_DOWN] = SDLK_DOWN,
[RETROK_RIGHT] = SDLK_RIGHT,
[RETROK_LEFT] = SDLK_LEFT,
[RETROK_INSERT] = SDLK_INSERT,
[RETROK_HOME] = SDLK_HOME,
[RETROK_END] = SDLK_END,
[RETROK_PAGEUP] = SDLK_PAGEUP,
[RETROK_PAGEDOWN] = SDLK_PAGEDOWN,
[RETROK_F1] = SDLK_F1,
[RETROK_F2] = SDLK_F2,
[RETROK_F3] = SDLK_F3,
[RETROK_F4] = SDLK_F4,
[RETROK_F5] = SDLK_F5,
[RETROK_F6] = SDLK_F6,
[RETROK_F7] = SDLK_F7,
[RETROK_F8] = SDLK_F8,
[RETROK_F9] = SDLK_F9,
[RETROK_F10] = SDLK_F10,
[RETROK_F11] = SDLK_F11,
[RETROK_F12] = SDLK_F12,
[RETROK_F13] = SDLK_F13,
[RETROK_F14] = SDLK_F14,
[RETROK_F15] = SDLK_F15,
[RETROK_NUMLOCK] = SDLK_NUMLOCKCLEAR,
[RETROK_CAPSLOCK] = SDLK_CAPSLOCK,
[RETROK_SCROLLOCK] = SDLK_SCROLLLOCK,
[RETROK_RSHIFT] = SDLK_RSHIFT,
[RETROK_LSHIFT] = SDLK_LSHIFT,
[RETROK_RCTRL] = SDLK_RCTRL,
[RETROK_LCTRL] = SDLK_LCTRL,
[RETROK_RALT] = SDLK_RALT,
[RETROK_LALT] = SDLK_LALT,
[RETROK_LSUPER] = SDLK_LGUI,
[RETROK_RSUPER] = SDLK_RGUI,
[RETROK_MODE] = SDLK_MODE,
[RETROK_HELP] = SDLK_HELP,
[RETROK_PRINT] = SDLK_PRINTSCREEN,
[RETROK_SYSREQ] = SDLK_SYSREQ,
[RETROK_BREAK] = SDLK_PAUSE,
[RETROK_MENU] = SDLK_MENU,
[RETROK_POWER] = SDLK_POWER,
[RETROK_UNDO] = SDLK_UNDO,
[RETROK_OEM_102] = SDLK_LESS,
};
SDL_Scancode scancode = SDL_GetScancodeFromKey(keycodes[keycode]);
SDL_SendKeyboardKey(down ? SDL_PRESSED : SDL_RELEASED, scancode);
}

View file

@ -0,0 +1,22 @@
#ifndef SDL_LIBRETO_H
#define SDL_LIBRETO_H
#include "SDL.h"
#include "libretro.h"
#ifdef __cplusplus
extern "C" {
#endif
void SDL_libretro_RefreshVideo(retro_video_refresh_t video_cb);
void SDL_libretro_ProduceAudio(retro_audio_sample_batch_t audio_batch_t);
void SDL_libretro_KeyboardCallback(bool down, unsigned keycode,
uint32_t character, uint16_t key_modifiers);
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,270 @@
#include <libgen.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include "SDL_libretro.h"
static void fallback_log(enum retro_log_level level, const char* fmt, ...);
static retro_log_printf_t log_cb = fallback_log;
static retro_environment_t environ_cb;
static retro_video_refresh_t video_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static SDL_Thread* game_thread;
static void
fallback_log(enum retro_log_level level, const char* fmt, ...)
{
(void)level;
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}
unsigned
retro_api_version(void)
{
return RETRO_API_VERSION;
}
void
retro_set_environment(retro_environment_t cb)
{
static struct retro_log_callback log;
environ_cb = cb;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
log_cb = log.log;
}
void
retro_set_video_refresh(retro_video_refresh_t cb)
{
video_cb = cb;
}
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;
}
void
retro_set_input_poll(retro_input_poll_t cb)
{
input_poll_cb = cb;
}
void
retro_set_input_state(retro_input_state_t cb)
{
input_state_cb = cb;
}
void
retro_get_system_info(struct retro_system_info* info)
{
info->need_fullpath = true;
info->valid_extensions = "zip";
info->library_version = "0.1";
info->library_name = "vvvvvv";
info->block_extract = false;
}
void
retro_get_system_av_info(struct retro_system_av_info* info)
{
int width = 320;
int height = 240;
info->geometry.base_width = width;
info->geometry.base_height = height;
info->geometry.max_width = width;
info->geometry.max_height = height;
info->geometry.aspect_ratio = 0.0;
info->timing.fps = 60.0;
info->timing.sample_rate = 44100.0;
}
void
retro_init(void)
{
bool yes = true;
enum retro_pixel_format pixfmt = RETRO_PIXEL_FORMAT_XRGB8888;
environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &pixfmt);
environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &yes);
}
int main(int argc, char *argv[]);
static int
game_main(void* data)
{
char buf[1024];
char *pwd = SDL_strdup(getcwd(buf, 1024));
char *argv[] = {
SDL_strdup(""),
SDL_strdup("-basedir"),
SDL_strdup(pwd),
SDL_strdup("-langdir"),
SDL_strdup((SDL_snprintf(buf, 1024, "%s/lang", pwd), buf)),
SDL_strdup("-fontsdir"),
SDL_strdup((SDL_snprintf(buf, 1024, "%s/fonts", pwd), buf)),
SDL_strdup("-assets"),
SDL_strdup((SDL_snprintf(buf, 1024, "%s/data.zip", pwd), buf)),
};
int argc = sizeof(argv) / sizeof(argv[0]);
return main(argc, argv);
}
bool
retro_load_game(const struct retro_game_info* game)
{
char *systemdir;
environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &systemdir);
if (game == NULL) {
chdir(systemdir);
chdir("vvvvvv");
} else {
chdir(game->path);
}
game_thread = SDL_CreateThread(game_main, "VVVVVV", NULL);
if (game_thread == NULL)
return false;
struct retro_keyboard_callback keyboard = {
.callback = SDL_libretro_KeyboardCallback,
};
environ_cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &keyboard);
return true;
}
void
retro_set_controller_port_device(unsigned port, unsigned device)
{
}
void
retro_deinit(void)
{
}
void
retro_reset(void)
{
}
static void
PumpJoypadEvents(void)
{
static int16_t buttons[16] = { 0 };
static const int bkeys[16] = {
[RETRO_DEVICE_ID_JOYPAD_B] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_Y] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_SELECT] = SDLK_BACKSPACE,
[RETRO_DEVICE_ID_JOYPAD_START] = SDLK_RETURN,
[RETRO_DEVICE_ID_JOYPAD_UP] = SDLK_UP,
[RETRO_DEVICE_ID_JOYPAD_DOWN] = SDLK_DOWN,
[RETRO_DEVICE_ID_JOYPAD_LEFT] = SDLK_LEFT,
[RETRO_DEVICE_ID_JOYPAD_RIGHT] = SDLK_RIGHT,
[RETRO_DEVICE_ID_JOYPAD_A] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_X] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_L] = SDLK_BACKSPACE,
[RETRO_DEVICE_ID_JOYPAD_R] = SDLK_RETURN,
[RETRO_DEVICE_ID_JOYPAD_L2] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_R2] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_L3] = SDLK_v,
[RETRO_DEVICE_ID_JOYPAD_R3] = SDLK_v,
};
for (int i = 0; i < 16; ++i) {
int16_t state = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i);
int k = bkeys[i];
if (buttons[i] != state) {
buttons[i] = state;
SDL_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED,
SDL_GetScancodeFromKey(k));
}
}
}
void
retro_run(void)
{
input_poll_cb();
PumpJoypadEvents();
SDL_libretro_RefreshVideo(video_cb);
SDL_libretro_ProduceAudio(audio_batch_cb);
}
size_t
retro_serialize_size(void)
{
return 0;
}
bool
retro_serialize(void* data, size_t size)
{
return false;
}
bool
retro_unserialize(const void* data, size_t size)
{
return false;
}
void
retro_cheat_reset(void)
{
}
void
retro_cheat_set(unsigned index, bool enabled, const char* code)
{
}
bool
retro_load_game_special(unsigned game_type,
const struct retro_game_info* info,
size_t num_info)
{
return false;
}
void
retro_unload_game(void)
{
SDL_Event event = { SDL_QUIT };
SDL_PushEvent(&event);
SDL_WaitThread(game_thread, NULL);
}
unsigned
retro_get_region(void)
{
return RETRO_REGION_NTSC;
}
void*
retro_get_memory_data(unsigned id)
{
return NULL;
}
size_t
retro_get_memory_size(unsigned id)
{
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
{
global: retro_*; lodepng_malloc; lodepng_realloc; lodepng_free;
local: *;
};

1
third_party/SDL vendored Submodule

@ -0,0 +1 @@
Subproject commit 79ec168f3c1e2fe27335cb8886439f7ef676fb49