diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e5fb1c5bf..3d93639630 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,7 +359,7 @@ if(EMSCRIPTEN) set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF) endif() -if(VITA OR PSP OR PS2 OR N3DS) +if(VITA OR PSP OR PS2 OR N3DS OR PLAYDATE) set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF) endif() @@ -1412,6 +1412,44 @@ if(ANDROID) set(HAVE_CLOCK_GETTIME 1) endif() +elseif(PLAYDATE) + file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/playdate/*.c) + file(GLOB PD_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/playdate/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${PD_CORE_SOURCES}) + + if(SDL_JOYSTICK) + set(SDL_JOYSTICK_PLAYDATE 1) + file(GLOB PD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/playdate/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${PD_JOYSTICK_SOURCES}) + set(HAVE_SDL_JOYSTICK TRUE) + endif() + if(SDL_POWER) + set(SDL_POWER_PLAYDATE 1) + file(GLOB PD_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/playdate/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${PD_POWER_SOURCES}) + set(HAVE_SDL_POWER TRUE) + endif() + if(SDL_VIDEO) + set(SDL_VIDEO_DRIVER_PLAYDATE 1) + file(GLOB PD_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/playdate/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${PD_VIDEO_SOURCES}) + set(HAVE_SDL_VIDEO TRUE) + endif() + if(SDL_SENSOR) + set(SDL_SENSOR_PLAYDATE 1) + set(HAVE_SDL_SENSORS TRUE) + file(GLOB PD_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/playdate/*.m) + set(SOURCE_FILES ${SOURCE_FILES} ${PD_SENSOR_SOURCES}) + endif() + if(SDL_TIMERS) + set(SDL_TIMER_PLAYDATE 1) + file(GLOB PD_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/playdate/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${PD_TIMER_SOURCES}) + set(HAVE_SDL_TIMERS TRUE) + endif() + + CheckPTHREAD() + elseif(EMSCRIPTEN) # Hide noisy warnings that intend to aid mostly during initial stages of porting a new # project. Uncomment at will for verbose cross-compiling -I/../ path info. @@ -3456,6 +3494,10 @@ if(APPLE) endforeach() endif() +if(PLAYDATE) + target_include_directories(sdl-build-options INTERFACE "${PLAYDATE_SDK_PATH}/C_API") +endif() + if(SDL_SHARED) add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES}) add_dependencies(SDL2 sdl_headers_copy) diff --git a/include/SDL_config.h b/include/SDL_config.h index a628d86252..cb86aba4b0 100644 --- a/include/SDL_config.h +++ b/include/SDL_config.h @@ -27,7 +27,9 @@ /* WIKI CATEGORY: - */ /* Add any platform that doesn't build using the configure system. */ -#if defined(__WIN32__) +#if defined(PLAYDATE) +#include "SDL_config_playdate.h" +#elif defined(__WIN32__) #include "SDL_config_windows.h" #elif defined(__WINRT__) #include "SDL_config_winrt.h" diff --git a/include/SDL_config_playdate.h b/include/SDL_config_playdate.h new file mode 100644 index 0000000000..0b3bd71b29 --- /dev/null +++ b/include/SDL_config_playdate.h @@ -0,0 +1,123 @@ +#ifndef SDL2_SDL_CONFIG_PLAYDATE_H +#define SDL2_SDL_CONFIG_PLAYDATE_H + +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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_playdate_h_ +#define SDL_config_playdate_h_ +#define SDL_config_h_ + +#include + +#include "SDL_platform.h" + +/* Most everything except Visual Studio 2008 and earlier has stdint.h now */ +#if defined(_MSC_VER) && (_MSC_VER < 1600) +/* Here are some reasonable defaults */ +typedef unsigned int size_t; +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; +typedef unsigned long uintptr_t; +#else +#define HAVE_STDINT_H 1 +#endif /* Visual Studio 2008 */ + +#ifdef __GNUC__ +#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1 +#endif + +// Disable dynamic lookup, needs investigation. +#ifdef SDL_DYNAMIC_API +#undef SDL_DYNAMIC_API +#define SDL_DYNAMIC_API 0 +#endif + +// Must un-define osx bc it gets picked up when compiling for simulator. +#ifdef TARGET_SIMULATOR +#undef __APPLE__ +#undef __MACOSX__ +#endif /* TARGET_SIMULATOR */ + +#ifdef SDL_LEAN_AND_MEAN +#undef SDL_LEAN_AND_MEAN +#define SDL_LEAN_AND_MEAN 1 +#endif + +#define HAVE_STDIO_H 1 +#define LACKS_SYS_MMAN_H 1 +#define HAVE_LIBC 0 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDDEF_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_MATH_H 1 +#define HAVE_LIMITS_H 1 +#define LACKS_SYS_MMAN_H 1 + +#ifdef HAVE_MMAP +#undef HAVE_MMAP +#define HAVE_MMAP 0 +#endif + +#define HAVE_MALLOC 0 +#define HAVE_MORECORE 0 + +#undef SDL_VIDEO_RENDER_SW +#define SDL_VIDEO_RENDER_SW 1 + +/* Enable the dummy audio driver (src/audio/dummy/\*.c) */ +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable the joystick driver */ +#define SDL_JOYSTICK_PLAYDATE 1 + +/* No haptics on Playdate */ +#define SDL_HAPTIC_DISABLED 1 + +/* Enable the sensor driver */ +#define SDL_SENSOR_PLAYDATE 1 + +/* TODO: investigate */ +#define SDL_LOADSO_DISABLED 1 + +/* TODO: investigate */ +#define SDL_THREADS_DISABLED 1 + +/* TODO: investigation, but i think is bc of timers */ +#define SDL_TIMER_PLAYDATE 1 + +/* Enable the video driver */ +#define SDL_VIDEO_DRIVER_PLAYDATE 1 + +/* Enable system power support */ +#define SDL_POWER_PLAYDATE 1 + +#endif /* SDL_config_playdate_h_ */ + +#endif //SDL2_SDL_CONFIG_PLAYDATE_H diff --git a/include/SDL_platform.h b/include/SDL_platform.h index 36df782a4e..74c7f278ef 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -136,6 +136,11 @@ #undef __OSF__ #define __OSF__ 1 #endif +#if defined(PLAYDATE) || defined(TARGET_PLAYDATE) +#undef TARGET_PLAYDATE +#undef PLAYDATE +#define PLAYDATE 1 +#endif #if defined(__QNXNTO__) #undef __QNXNTO__ #define __QNXNTO__ 1 diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 73df518fb0..fa7e210804 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -428,7 +428,7 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); /** \cond */ #ifndef DOXYGEN_SHOULD_IGNORE_THIS -#if !defined(__VITA__) && !defined(__3DS__) +#if !defined(__VITA__) && !defined(__3DS__) && !defined(PLAYDATE) /* TODO: include/SDL_stdinc.h:422: error: size of array 'SDL_dummy_enum' is negative */ typedef enum { diff --git a/src/core/playdate/SDL_playdate.c b/src/core/playdate/SDL_playdate.c new file mode 100644 index 0000000000..60432e76c6 --- /dev/null +++ b/src/core/playdate/SDL_playdate.c @@ -0,0 +1,126 @@ +#include "../../SDL_internal.h" + +#include +#include +#include + +#ifdef PLAYDATE + +#include "pd_api.h" + +#define MAX_DESCRIPTORS 64 +#define RESERVED_DESCRIPTORS 3 + +static FILE *file_descriptors[MAX_DESCRIPTORS]; + +#ifndef TARGET_SIMULATOR +extern int _start; + +void* _sbrk(int incr) +{ + static unsigned char *heap = NULL; + unsigned char *prev_heap; + + if (heap == NULL) { + heap = (unsigned char *)&_start; + } + + prev_heap = heap; + heap += incr; + + return prev_heap; +} +#endif + +extern int _write(SDFile *file, char *ptr, int len) +{ + return pd->file->write(file, ptr, len); +} + +extern int _read(SDFile *file, char *ptr, int len) +{ + return pd->file->read(file, ptr, len); +} + +extern SDFile* _open(const char *filename, const char *mode) +{ + return pd->file->open(filename, kFileRead|kFileReadData|kFileWrite|kFileAppend); +} + +extern int _close(SDFile *file) +{ + return pd->file->close(file); +} + +extern int _fstat(const char *file, struct stat *st) +{ + FileStat result; + struct tm ltm; + + int rc = pd->file->stat(file, &result); + + if (!rc) { + ltm.tm_sec = result.m_second; + ltm.tm_min = result.m_minute; + ltm.tm_hour = result.m_hour; + ltm.tm_mday = result.m_day; + ltm.tm_mon = result.m_month; + ltm.tm_year = result.m_year; + + st->st_dev = 0; + st->st_ino = 0; + st->st_mode = 0; + st->st_nlink = 0; + st->st_uid = 0; + st->st_gid = 0; + st->st_rdev = 0; + st->st_size = result.size; + st->st_atime = st->st_mtime = st->st_ctime = mktime(<m); + st->st_blksize = 0; + st->st_blocks = 0; + } + + return rc; +} + +extern int _isatty(int file) +{ + if (file < RESERVED_DESCRIPTORS) { + return 1; + } + if (file >= MAX_DESCRIPTORS || file_descriptors[file] == NULL) { + errno = EBADF; + return -1; + } + return 0; +} + +extern int _lseek(SDFile *file, int pos, int whence) +{ + return pd->file->seek(file, pos, whence); +} + +extern void _exit(int code) +{ + while(1) { /* noop */ } +} + +extern void* realloc(void* ptr, size_t size) { + return pd->system->realloc(ptr, size); +} + +extern void* malloc(size_t size) { + return pd->system->realloc(NULL, size); +} + +extern void* calloc(size_t count, size_t size) { + return memset(malloc(count * size), 0, count * size); +} + +extern void free(void* ptr) { + if (realloc(ptr, 0)) { /* noop */ } +} + +#endif /* PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/dynapi/SDL_dynapi.h b/src/dynapi/SDL_dynapi.h index 178218c053..c15a9178e2 100644 --- a/src/dynapi/SDL_dynapi.h +++ b/src/dynapi/SDL_dynapi.h @@ -67,6 +67,8 @@ #define SDL_DYNAMIC_API 0 /* The N-Gage doesn't support dynamic linking either */ #elif defined(__3DS__) #define SDL_DYNAMIC_API 0 /* devkitARM doesn't support dynamic linking */ +#elif defined(PLAYDATE) || defined(TARGET_PLAYDATE) +#define SDL_DYNAMIC_API 0 /* playdate doesn't support dynamic linking */ #elif defined(DYNAPI_NEEDS_DLOPEN) && !defined(HAVE_DLOPEN) #define SDL_DYNAMIC_API 0 /* we need dlopen(), but don't have it.... */ #endif diff --git a/src/joystick/SDL_gamecontrollerdb.h b/src/joystick/SDL_gamecontrollerdb.h index 9c1ec660c6..8de84f6b0f 100644 --- a/src/joystick/SDL_gamecontrollerdb.h +++ b/src/joystick/SDL_gamecontrollerdb.h @@ -1000,6 +1000,9 @@ static const char *s_ControllerMappings[] = { #endif #ifdef SDL_JOYSTICK_N3DS "000000004e696e74656e646f20334400,Nintendo 3DS,crc:3210,a:b0,b:b1,back:b2,dpdown:b7,dpleft:b5,dpright:b4,dpup:b6,leftshoulder:b9,lefttrigger:b14,leftx:a0,lefty:a1,rightshoulder:b8,righttrigger:b15,rightx:a2,righty:a3,start:b3,x:b10,y:b11,", +#endif +#if defined(SDL_JOYSTICK_PLAYDATE) + "default,Playdate Controller,a:b4,b:b5,dpdown:b3,dpleft:b0,dpright:b1,dpup:b2,", #endif "hidapi,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,", NULL diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 84cc0621bc..2c5708aac7 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -104,10 +104,13 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = { &SDL_VITA_JoystickDriver, #endif #ifdef SDL_JOYSTICK_N3DS - &SDL_N3DS_JoystickDriver + &SDL_N3DS_JoystickDriver, +#endif +#ifdef SDL_JOYSTICK_PLAYDATE + &SDL_PLAYDATE_JoystickDriver, #endif #if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED) - &SDL_DUMMY_JoystickDriver + &SDL_DUMMY_JoystickDriver #endif }; diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index d36f784143..a7fdfe0049 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -253,6 +253,7 @@ extern SDL_JoystickDriver SDL_PS2_JoystickDriver; extern SDL_JoystickDriver SDL_PSP_JoystickDriver; extern SDL_JoystickDriver SDL_VITA_JoystickDriver; extern SDL_JoystickDriver SDL_N3DS_JoystickDriver; +extern SDL_JoystickDriver SDL_PLAYDATE_JoystickDriver; /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/joystick/playdate/SDL_sysjoystick.c b/src/joystick/playdate/SDL_sysjoystick.c new file mode 100644 index 0000000000..a7f1f8e2ee --- /dev/null +++ b/src/joystick/playdate/SDL_sysjoystick.c @@ -0,0 +1,217 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifdef SDL_JOYSTICK_PLAYDATE + +/* This is the playdate implementation of the SDL joystick API */ + +#include "SDL_joystick.h" +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" +#include "../../events/SDL_keyboard_c.h" + +#include "pd_api.h" + +static int running = 0; +static const unsigned int button_map[] = { + kButtonLeft, + kButtonRight, + kButtonUp, + kButtonDown, + kButtonA, + kButtonB +}; + +static void +PLAYDATE_JoystickUpdate(SDL_Joystick *joystick) +{ + int i; + PDButtons buttons; + PDButtons changed; + static PDButtons old_buttons; + + if (running) { + PDButtons current; + pd->system->getButtonState(¤t, NULL, NULL); + buttons = current; + + changed = old_buttons ^ buttons; + old_buttons = buttons; + if (changed) { + for(i=0;i<6;i++) { + if (changed & button_map[i]) { + SDL_PrivateJoystickButton( + joystick, i, + (buttons & button_map[i]) ? + SDL_PRESSED : SDL_RELEASED); + } + } + } + } +} + +static int +PLAYDATE_JoystickInit(void) +{ + running = 1; + SDL_PrivateJoystickAdded(0); + return 0; +} + +static int +PLAYDATE_JoystickOpen(SDL_Joystick *joystick, int device_index) +{ + joystick->nbuttons = 6; + joystick->naxes = 0; // maybe support... + joystick->nhats = 0; + + return 0; +} + +static int +PLAYDATE_JoystickGetCount(void) +{ + return 1; +} + +static void +PLAYDATE_JoystickDetect(void) +{ +} + +static const char * +PLAYDATE_JoystickGetDeviceName(int device_index) +{ + if (device_index == 0) + return "Playdate Controller"; + + SDL_SetError("No joystick available with that index"); + return(NULL); +} + +static int +PLAYDATE_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + +static void +PLAYDATE_JoystickSetDevicePlayerIndex(int device_index, int player_index) +{ +} + +static SDL_JoystickGUID +PLAYDATE_JoystickGetDeviceGUID(int device_index) +{ + SDL_JoystickGUID guid; + const char *name = PLAYDATE_JoystickGetDeviceName(device_index); + SDL_zero(guid); + SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name))); + return guid; +} + +static SDL_JoystickID +PLAYDATE_JoystickGetDeviceInstanceID(int device_index) +{ + return device_index; +} + +static int +PLAYDATE_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +{ + return SDL_Unsupported(); +} + +static int +PLAYDATE_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +{ + return SDL_Unsupported(); +} + +static Uint32 +PLAYDATE_JoystickGetCapabilities(SDL_Joystick *joystick) +{ + return 0; +} + +static int +PLAYDATE_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +{ + return SDL_Unsupported(); +} + +static int +PLAYDATE_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +{ + return SDL_Unsupported(); +} + +static int +PLAYDATE_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled) +{ + // i think we may need this + return SDL_Unsupported(); +} + +static void +PLAYDATE_JoystickClose(SDL_Joystick *joystick) +{ +} + +static void +PLAYDATE_JoystickQuit(void) +{ + running = 0; +} + +static SDL_bool +PLAYDATE_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out) +{ + return SDL_FALSE; +} + +SDL_JoystickDriver SDL_PLAYDATE_JoystickDriver = +{ + PLAYDATE_JoystickInit, + PLAYDATE_JoystickGetCount, + PLAYDATE_JoystickDetect, + PLAYDATE_JoystickGetDeviceName, + PLAYDATE_JoystickGetDevicePlayerIndex, + PLAYDATE_JoystickSetDevicePlayerIndex, + PLAYDATE_JoystickGetDeviceGUID, + PLAYDATE_JoystickGetDeviceInstanceID, + PLAYDATE_JoystickOpen, + PLAYDATE_JoystickRumble, + PLAYDATE_JoystickRumbleTriggers, + PLAYDATE_JoystickGetCapabilities, + PLAYDATE_JoystickSetLED, + PLAYDATE_JoystickSendEffect, + PLAYDATE_JoystickSetSensorsEnabled, + PLAYDATE_JoystickUpdate, + PLAYDATE_JoystickClose, + PLAYDATE_JoystickQuit, + PLAYDATE_JoystickGetGamepadMapping +}; + +#endif /* SDL_JOYSTICK_PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/libm/math_private.h b/src/libm/math_private.h index ee67c444ea..c6f170ba88 100644 --- a/src/libm/math_private.h +++ b/src/libm/math_private.h @@ -27,7 +27,7 @@ #define libm_hidden_def(x) #define strong_alias(x, y) -#if !defined(__HAIKU__) && !defined(__PSP__) && !defined(__3DS__) && !defined(__PS2__) /* already defined in a system header. */ +#if !defined(__HAIKU__) && !defined(__PSP__) && !defined(__3DS__) && !defined(__PS2__) && !defined(PLAYDATE) /* already defined in a system header. */ typedef unsigned int u_int32_t; #endif diff --git a/src/main/playdate/SDL_playdate_main.c b/src/main/playdate/SDL_playdate_main.c new file mode 100644 index 0000000000..7b93728327 --- /dev/null +++ b/src/main/playdate/SDL_playdate_main.c @@ -0,0 +1,35 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ + +/* We only need to build syscalls for playdate and this seemed a logical place */ + +#include "../../SDL_internal.h" + +#if defined(SDL_VIDEO_DRIVER_PLAYDATE) && !defined(TARGET_SIMULATOR) + +/* noop - just a stub */ +int +main(int argc, char *argv[]) +{ + return 0; +} + +#endif \ No newline at end of file diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index 2ae2f9fe3f..06bab52ebe 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -78,6 +78,9 @@ static SDL_GetPowerInfo_Impl implementations[] = { #ifdef SDL_POWER_EMSCRIPTEN /* handles Emscripten */ SDL_GetPowerInfo_Emscripten, #endif +#ifdef SDL_POWER_PLAYDATE /* handles Playdate */ + SDL_GetPowerInfo_Playdate, +#endif #ifdef SDL_POWER_HARDWIRED SDL_GetPowerInfo_Hardwired, diff --git a/src/power/SDL_syspower.h b/src/power/SDL_syspower.h index 627b91eb9e..192c190c6c 100644 --- a/src/power/SDL_syspower.h +++ b/src/power/SDL_syspower.h @@ -42,6 +42,7 @@ SDL_bool SDL_GetPowerInfo_VITA(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_N3DS(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *); +SDL_bool SDL_GetPowerInfo_Playdate(SDL_PowerState *, int *, int *); /* this one is static in SDL_power.c */ /* SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *, int *, int *);*/ diff --git a/src/power/playdate/SDL_syspower.c b/src/power/playdate/SDL_syspower.c new file mode 100644 index 0000000000..b4a740f7e4 --- /dev/null +++ b/src/power/playdate/SDL_syspower.c @@ -0,0 +1,44 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifndef SDL_POWER_DISABLED +#ifdef SDL_POWER_PLAYDATE + +#include "SDL_power.h" +#include "../SDL_syspower.h" + +#include "pd_api.h" + +SDL_bool +SDL_GetPowerInfo_Playdate(SDL_PowerState * state, int *seconds, int *percent) +{ + *state = SDL_POWERSTATE_UNKNOWN; + *seconds = -1; + *percent = pd->system->getBatteryPercentage(); + + return SDL_TRUE; +} + +#endif /* SDL_POWER_PLAYDATE */ +#endif /* SDL_POWER_DISABLED */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c index 852ca62fa9..d5fb3a33cd 100644 --- a/src/sensor/SDL_sensor.c +++ b/src/sensor/SDL_sensor.c @@ -50,6 +50,12 @@ static SDL_SensorDriver *SDL_sensor_drivers[] = { #if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED) &SDL_DUMMY_SensorDriver #endif +#if defined(SDL_SENSOR_VITA) + &SDL_VITA_SensorDriver +#endif +#if defined(SDL_SENSOR_PLAYDATE) + &SDL_PLAYDATE_SensorDriver +#endif }; static SDL_mutex *SDL_sensor_lock = NULL; /* This needs to support recursive locks */ static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL; diff --git a/src/sensor/SDL_syssensor.h b/src/sensor/SDL_syssensor.h index 8695ea93dd..beafc41abd 100644 --- a/src/sensor/SDL_syssensor.h +++ b/src/sensor/SDL_syssensor.h @@ -103,6 +103,7 @@ extern SDL_SensorDriver SDL_WINDOWS_SensorDriver; extern SDL_SensorDriver SDL_DUMMY_SensorDriver; extern SDL_SensorDriver SDL_VITA_SensorDriver; extern SDL_SensorDriver SDL_N3DS_SensorDriver; +extern SDL_SensorDriver SDL_PLAYDATE_SensorDriver; #endif /* SDL_syssensor_h_ */ diff --git a/src/sensor/playdate/SDL_playdatesensor.c b/src/sensor/playdate/SDL_playdatesensor.c new file mode 100644 index 0000000000..1ebb8cff57 --- /dev/null +++ b/src/sensor/playdate/SDL_playdatesensor.c @@ -0,0 +1,159 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#include "SDL_config.h" + +#ifdef SDL_SENSOR_PLAYDATE + +#include "SDL_error.h" +#include "SDL_sensor.h" +#include "SDL_playdatesensor.h" +#include "../SDL_syssensor.h" + +#include "pd_api.h" + +typedef struct +{ + SDL_SensorType type; + SDL_SensorID instance_id; +} SDL_PlaydateSensor; + +static SDL_PlaydateSensor *SDL_sensors; +static int SDL_sensors_count; + +static int +SDL_PLAYDATE_SensorInit(void) +{ + SDL_sensors_count = 1; + SDL_sensors = (SDL_PlaydateSensor *)SDL_calloc(1, sizeof(*SDL_sensors)); + SDL_sensors[0].type = SDL_SENSOR_ACCEL; + SDL_sensors[0].instance_id = SDL_GetNextSensorInstanceID(); + return 0; +} + +static int +SDL_PLAYDATE_SensorGetCount(void) +{ + return SDL_sensors_count; +} + +static void +SDL_PLAYDATE_SensorDetect(void) +{ +} + +static const char * +SDL_PLAYDATE_SensorGetDeviceName(int device_index) +{ + switch (SDL_sensors[device_index].type) { + case SDL_SENSOR_ACCEL: + return "Accelerometer"; + default: + return "Unknown"; + } +} + +static SDL_SensorType +SDL_PLAYDATE_SensorGetDeviceType(int device_index) +{ + return SDL_sensors[device_index].type; +} + +static int +SDL_PLAYDATE_SensorGetDeviceNonPortableType(int device_index) +{ + return SDL_sensors[device_index].type; +} + +static SDL_SensorID +SDL_PLAYDATE_SensorGetDeviceInstanceID(int device_index) +{ + return SDL_sensors[device_index].instance_id; +} + +static int +SDL_PLAYDATE_SensorOpen(SDL_Sensor *sensor, int device_index) +{ + switch (sensor->type) { + case SDL_SENSOR_ACCEL: + pd->system->setPeripheralsEnabled(kAccelerometer); + break; + default: + break; + } + return 0; +} + +static void +SDL_PLAYDATE_SensorUpdate(SDL_Sensor *sensor) +{ + switch (sensor->type) { + case SDL_SENSOR_ACCEL: + { + float data[3]; + pd->system->getAccelerometer(&data[0], &data[1], &data[2]); + data[0] = data[0] * SDL_STANDARD_GRAVITY; + data[1] = data[1] * SDL_STANDARD_GRAVITY; + data[2] = data[2] * SDL_STANDARD_GRAVITY; + SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data)); + } + break; + default: + break; + } +} + +static void +SDL_PLAYDATE_SensorClose(SDL_Sensor *sensor) +{ + switch (sensor->type) { + case SDL_SENSOR_ACCEL: + pd->system->setPeripheralsEnabled(kNone); + break; + default: + break; + } +} + +static void +SDL_PLAYDATE_SensorQuit(void) +{ +} + +SDL_SensorDriver SDL_PLAYDATE_SensorDriver = +{ + SDL_PLAYDATE_SensorInit, + SDL_PLAYDATE_SensorGetCount, + SDL_PLAYDATE_SensorDetect, + SDL_PLAYDATE_SensorGetDeviceName, + SDL_PLAYDATE_SensorGetDeviceType, + SDL_PLAYDATE_SensorGetDeviceNonPortableType, + SDL_PLAYDATE_SensorGetDeviceInstanceID, + SDL_PLAYDATE_SensorOpen, + SDL_PLAYDATE_SensorUpdate, + SDL_PLAYDATE_SensorClose, + SDL_PLAYDATE_SensorQuit, +}; + +#endif /* SDL_SENSOR_PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/sensor/playdate/SDL_playdatesensor.h b/src/sensor/playdate/SDL_playdatesensor.h new file mode 100644 index 0000000000..1f35136293 --- /dev/null +++ b/src/sensor/playdate/SDL_playdatesensor.h @@ -0,0 +1,23 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "SDL_config.h" + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/playdate/SDL_systimer.c b/src/timer/playdate/SDL_systimer.c new file mode 100644 index 0000000000..39eb1688e2 --- /dev/null +++ b/src/timer/playdate/SDL_systimer.c @@ -0,0 +1,77 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifdef SDL_TIMER_PLAYDATE + +#include "SDL_timer.h" +#include "pd_api.h" + +static SDL_bool ticks_started = SDL_FALSE; + +void +SDL_TicksInit(void) +{ + if (ticks_started) { + return; + } + ticks_started = SDL_TRUE; +} + +void +SDL_TicksQuit(void) +{ + ticks_started = SDL_FALSE; +} + +Uint64 +SDL_GetTicks64(void) +{ + if (!ticks_started) { + SDL_TicksInit(); + } + return pd->system->getCurrentTimeMilliseconds(); +} + +Uint64 +SDL_GetPerformanceCounter(void) +{ + return SDL_GetTicks(); +} + +Uint64 +SDL_GetPerformanceFrequency(void) +{ + return 10000; +} + +void +SDL_Delay(Uint32 ms) +{ + unsigned int startTime = pd->system->getCurrentTimeMilliseconds(); + while(pd->system->getCurrentTimeMilliseconds() - startTime < ms) { + // just spin. + } +} + +#endif /* SDL_TIMER_PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index badb1a3edc..efa30246c1 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -481,6 +481,7 @@ extern VideoBootStrap NACL_bootstrap; extern VideoBootStrap VIVANTE_bootstrap; extern VideoBootStrap Emscripten_bootstrap; extern VideoBootStrap QNX_bootstrap; +extern VideoBootStrap PLAYDATE_bootstrap; extern VideoBootStrap OFFSCREEN_bootstrap; extern VideoBootStrap NGAGE_bootstrap; extern VideoBootStrap OS2DIVE_bootstrap; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index e4f54c65ce..b18f427038 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -139,6 +139,9 @@ static VideoBootStrap *bootstrap[] = { #ifdef SDL_VIDEO_DRIVER_QNX &QNX_bootstrap, #endif +#ifdef SDL_VIDEO_DRIVER_PLAYDATE + &PLAYDATE_bootstrap, +#endif #ifdef SDL_VIDEO_DRIVER_OS2 &OS2DIVE_bootstrap, &OS2VMAN_bootstrap, diff --git a/src/video/playdate/SDL_playdate_events.c b/src/video/playdate/SDL_playdate_events.c new file mode 100644 index 0000000000..3aa72da3d8 --- /dev/null +++ b/src/video/playdate/SDL_playdate_events.c @@ -0,0 +1,41 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifdef SDL_VIDEO_DRIVER_PLAYDATE + +/* Being a null driver, there's no event stream. We just define stubs for + most of the API. */ + +#include "../../events/SDL_events_c.h" + +#include "SDL_playdate_video.h" +#include "SDL_playdate_events_c.h" + +void +PLAYDATE_PumpEvents(_THIS) +{ + /* do nothing. */ +} + +#endif /* SDL_VIDEO_DRIVER_PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/playdate/SDL_playdate_events_c.h b/src/video/playdate/SDL_playdate_events_c.h new file mode 100644 index 0000000000..e23fe3cf07 --- /dev/null +++ b/src/video/playdate/SDL_playdate_events_c.h @@ -0,0 +1,33 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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_playdate_events_c_h_ +#define SDL_playdate_events_c_h_ + +#include "../../SDL_internal.h" + +#include "SDL_playdate_video.h" + +extern void PLAYDATE_PumpEvents(_THIS); + +#endif /* SDL_playdate_events_c_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/playdate/SDL_playdate_framebuffer.c b/src/video/playdate/SDL_playdate_framebuffer.c new file mode 100644 index 0000000000..d11c6b27ea --- /dev/null +++ b/src/video/playdate/SDL_playdate_framebuffer.c @@ -0,0 +1,144 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifdef SDL_VIDEO_DRIVER_PLAYDATE + +#include + +#include "../SDL_sysvideo.h" +#include "SDL_playdate_framebuffer_c.h" + +#include "pd_api.h" + +#define PLAYDATE_SURFACE "_SDL_PlaydateSurface" + +static const uint8_t bayer2[2][2] = { + { 51, 206 }, + { 153, 102 } +}; + +typedef struct { + uint16_t i; + uint8_t black_mask; + uint8_t white_mask; + int x; + int y; +} SDL_PD_Pixel; + +static const int number_of_bytes = LCD_ROWS * LCD_COLUMNS; + +static uint8_t bayer2_rows[LCD_ROWS]; +static uint8_t bayer2_cols[LCD_COLUMNS]; + +static SDL_PD_Pixel SDL_pd_pixels[LCD_ROWS * LCD_COLUMNS]; + +static const float r_d = 0.212671f * 2; +static const float g_d = 0.715160f * 2; +static const float b_d = 0.072169f * 2; + +int SDL_PLAYDATE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) +{ + SDL_Surface *surface; + const Uint32 surface_format = SDL_PIXELFORMAT_RGB888; + + for(int y = 0; y < LCD_ROWS; y++){ + bayer2_rows[y] = y % 2; + for(int x = 0; x < LCD_COLUMNS; x++){ + bayer2_cols[x] = x % 2; + + int i = y * LCD_COLUMNS + x; + int block_x = x / 8; + int block_i = y * LCD_ROWSIZE + block_x; + int n = 7 - x % 8; + SDL_PD_Pixel pixel = { + .i = block_i, + .black_mask = ~(1 << n), + .white_mask = (1 << n), + .x = x, + .y = y, + }; + + SDL_pd_pixels[i] = pixel; + } + } + + /* Free the old framebuffer surface */ + SDL_PLAYDATE_DestroyWindowFramebuffer(_this, window); + + /* Create a new one */ + surface = SDL_CreateRGBSurfaceWithFormat(0, LCD_COLUMNS, LCD_ROWS, 0, surface_format); + + if (!surface) { + return -1; + } + + /* Save the info and return! */ + SDL_SetWindowData(window, PLAYDATE_SURFACE, surface); + *format = surface_format; + *pixels = surface->pixels; + *pitch = surface->pitch; + + return 0; +} + +int SDL_PLAYDATE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) +{ + if (!window->surface) { + return SDL_SetError("Couldn't find surface for window"); + } + + Uint32* pixels = window->surface->pixels; + Uint8* frame = pd->graphics->getFrame(); + + for (int i = 0;isurface->format, &r, &g, &b); + Uint8 intensity = r_d * r + g_d * g + b_d * b; + Uint8 previous = frame[pixel.i]; + if (intensity < bayer2[d_col][d_row]) { + frame[pixel.i] &= pixel.black_mask; + } else { + frame[pixel.i] |= pixel.white_mask; + } + int isDirty = previous != frame[pixel.i]; + if (isDirty) { + pd->graphics->markUpdatedRows(pixel.y, pixel.y); + } + } + + return 0; +} + +void SDL_PLAYDATE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) +{ + SDL_Surface *surface; + surface = (SDL_Surface *) SDL_SetWindowData(window, PLAYDATE_SURFACE, NULL); + SDL_FreeSurface(surface); +} + +#endif /* SDL_VIDEO_DRIVER_PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/playdate/SDL_playdate_framebuffer_c.h b/src/video/playdate/SDL_playdate_framebuffer_c.h new file mode 100644 index 0000000000..53bb5ee0c7 --- /dev/null +++ b/src/video/playdate/SDL_playdate_framebuffer_c.h @@ -0,0 +1,35 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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_playdate_framebuffer_c_h_ +#define SDL_playdate_framebuffer_c_h_ + +#define BYTES_PER_LINE 50 + +#include "../../SDL_internal.h" + +extern int SDL_PLAYDATE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); +extern int SDL_PLAYDATE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); +extern void SDL_PLAYDATE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); + +#endif /* SDL_playdate_framebuffer_c_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/playdate/SDL_playdate_video.c b/src/video/playdate/SDL_playdate_video.c new file mode 100644 index 0000000000..d07f6084dd --- /dev/null +++ b/src/video/playdate/SDL_playdate_video.c @@ -0,0 +1,144 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifdef SDL_VIDEO_DRIVER_PLAYDATE + +/* Dummy SDL video driver implementation; this is just enough to make an + * SDL-based application THINK it's got a working video driver, for + * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it, + * and also for use as a collection of stubs when porting SDL to a new + * platform for which you haven't yet written a valid video driver. + * + * This is also a great way to determine bottlenecks: if you think that SDL + * is a performance problem for a given platform, enable this driver, and + * then see if your application runs faster without video overhead. + * + * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion + * of this was cut-and-pasted from Stephane Peter's work in the AAlib + * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. + */ + +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "../SDL_sysvideo.h" +#include "../SDL_pixels_c.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_playdate_video.h" +#include "SDL_playdate_events_c.h" +#include "SDL_playdate_framebuffer_c.h" + +#include "pd_api.h" + +#define PLAYDATEVID_DRIVER_NAME "playdate" + +/* Initialization/Query functions */ +static int PLAYDATE_VideoInit(_THIS); +static int PLAYDATE_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); +static void PLAYDATE_VideoQuit(_THIS); + +/* playdate driver bootstrap functions */ + +static int +PLAYDATE_Available(void) +{ + return 1; +} + +static void +PLAYDATE_DeleteDevice(SDL_VideoDevice * device) +{ + SDL_free(device); +} + +static SDL_VideoDevice * +PLAYDATE_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + + if (!PLAYDATE_Available()) { + return (0); + } + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (!device) { + SDL_OutOfMemory(); + return (0); + } + device->is_dummy = SDL_FALSE; + + /* Set the function pointers */ + device->VideoInit = PLAYDATE_VideoInit; + device->VideoQuit = PLAYDATE_VideoQuit; + device->SetDisplayMode = PLAYDATE_SetDisplayMode; + device->PumpEvents = PLAYDATE_PumpEvents; + device->CreateWindowFramebuffer = SDL_PLAYDATE_CreateWindowFramebuffer; + device->UpdateWindowFramebuffer = SDL_PLAYDATE_UpdateWindowFramebuffer; + device->DestroyWindowFramebuffer = SDL_PLAYDATE_DestroyWindowFramebuffer; + + device->free = PLAYDATE_DeleteDevice; + + return device; +} + +VideoBootStrap PLAYDATE_bootstrap = { + PLAYDATEVID_DRIVER_NAME, "SDL playdate video driver", + PLAYDATE_CreateDevice +}; + + +int +PLAYDATE_VideoInit(_THIS) +{ + SDL_DisplayMode mode; + /* Use a fake 32-bpp desktop mode */ + SDL_zero(mode); + mode.format = SDL_PIXELFORMAT_ARGB8888; + mode.w = 400; + mode.h = 240; + mode.refresh_rate = 50; + mode.driverdata = NULL; + if (SDL_AddBasicVideoDisplay(&mode) < 0) { + return -1; + } + + SDL_AddDisplayMode(&_this->displays[0], &mode); + + /* We're done! */ + return 0; +} + +static int +PLAYDATE_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) +{ + return 0; +} + +void +PLAYDATE_VideoQuit(_THIS) +{ +} + +#endif /* SDL_VIDEO_DRIVER_PLAYDATE */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/playdate/SDL_playdate_video.h b/src/video/playdate/SDL_playdate_video.h new file mode 100644 index 0000000000..9956bcb05b --- /dev/null +++ b/src/video/playdate/SDL_playdate_video.h @@ -0,0 +1,30 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2022 Sam Lantinga + + 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. +*/ +#include "../../SDL_internal.h" + +#ifndef SDL_playdate_video_h_ +#define SDL_playdate_video_h_ + +#include "../SDL_sysvideo.h" + +#endif /* SDL_playdate_video_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */