diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/3ds/3ds_utils.h | 35 | ||||
-rw-r--r-- | frontend/3ds/pthread.h | 63 | ||||
-rw-r--r-- | frontend/libretro.c | 19 |
3 files changed, 51 insertions, 66 deletions
diff --git a/frontend/3ds/3ds_utils.h b/frontend/3ds/3ds_utils.h index c9b9d7f..7f5c64a 100644 --- a/frontend/3ds/3ds_utils.h +++ b/frontend/3ds/3ds_utils.h @@ -3,50 +3,19 @@ #include <stdio.h> #include <stdbool.h> +#include <3ds.h> #define MEMOP_PROT 6 #define MEMOP_MAP 4 #define MEMOP_UNMAP 5 -#define GET_VERSION_MAJOR(version) ((version) >>24) - -void* linearMemAlign(size_t size, size_t alignment); -void linearFree(void* mem); - -int32_t svcDuplicateHandle(uint32_t* out, uint32_t original); -int32_t svcCloseHandle(uint32_t handle); -int32_t svcControlMemory(void* addr_out, void* addr0, void* addr1, uint32_t size, uint32_t op, uint32_t perm); -int32_t svcControlProcessMemory(uint32_t process, void* addr0, void* addr1, uint32_t size, uint32_t op, uint32_t perm); - -int32_t threadCreate(void *(*entrypoint)(void*), void* arg, size_t stack_size, int32_t prio, int32_t affinity, bool detached); -int32_t threadJoin(int32_t thread, int64_t timeout_ns); -void threadFree(int32_t thread); -void threadExit(int32_t rc) __attribute__((noreturn)); - -int32_t svcGetSystemInfo(int64_t* out, uint32_t type, int32_t param); - -int32_t svcCreateSemaphore(uint32_t *sem, int32_t initial_count, uint32_t max_count); -int32_t svcReleaseSemaphore(int32_t *count, uint32_t sem, int32_t release_count); -int32_t svcWaitSynchronization(uint32_t handle, int64_t nanoseconds); - -typedef int32_t LightLock; - -void LightLock_Init(LightLock* lock); -void LightLock_Lock(LightLock* lock); -int LightLock_TryLock(LightLock* lock); -void LightLock_Unlock(LightLock* lock); - -int32_t APT_CheckNew3DS(bool *out); - -int32_t svcBackdoor(int32_t (*callback)(void)); - #define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0) void wait_for_input(void); extern __attribute__((weak)) int __ctr_svchax; -bool has_rosalina; +static bool has_rosalina; static void check_rosalina() { int64_t version; diff --git a/frontend/3ds/pthread.h b/frontend/3ds/pthread.h index cc3c965..4c58fe5 100644 --- a/frontend/3ds/pthread.h +++ b/frontend/3ds/pthread.h @@ -11,20 +11,26 @@ #define CTR_PTHREAD_STACK_SIZE 0x10000 #define FALSE 0 -typedef int32_t pthread_t; -typedef int pthread_attr_t; - -typedef LightLock pthread_mutex_t; -typedef int pthread_mutexattr_t; - typedef struct { uint32_t semaphore; LightLock lock; uint32_t waiting; -} pthread_cond_t; +} cond_t; + +#if !defined(PTHREAD_SCOPE_PROCESS) +/* An earlier version of devkitARM does not define the pthread types. Can remove in r54+. */ + +typedef uint32_t pthread_t; +typedef int pthread_attr_t; +typedef LightLock pthread_mutex_t; +typedef int pthread_mutexattr_t; + +typedef uint32_t pthread_cond_t; typedef int pthread_condattr_t; +#endif + static inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) { @@ -80,41 +86,56 @@ static inline int pthread_mutex_destroy(pthread_mutex_t *mutex) { } static inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { - if (svcCreateSemaphore(&cond->semaphore, 0, 1)) + cond_t *cond_data = calloc(1, sizeof(cond_t)); + if (!cond_data) goto error; - LightLock_Init(&cond->lock); - cond->waiting = 0; + if (svcCreateSemaphore(&cond_data->semaphore, 0, 1)) + goto error; + + LightLock_Init(&cond_data->lock); + cond_data->waiting = 0; + *cond = cond_data; return 0; error: - svcCloseHandle(cond->semaphore); + svcCloseHandle(cond_data->semaphore); + if (cond_data) + free(cond_data); return -1; } static inline int pthread_cond_signal(pthread_cond_t *cond) { int32_t count; - LightLock_Lock(&cond->lock); - if (cond->waiting) { - cond->waiting--; - svcReleaseSemaphore(&count, cond->semaphore, 1); + cond_t *cond_data = (cond_t *)*cond; + LightLock_Lock(&cond_data->lock); + if (cond_data->waiting) { + cond_data->waiting--; + svcReleaseSemaphore(&count, cond_data->semaphore, 1); } - LightLock_Unlock(&cond->lock); + LightLock_Unlock(&cond_data->lock); return 0; } static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *lock) { - LightLock_Lock(&cond->lock); - cond->waiting++; + cond_t *cond_data = (cond_t *)*cond; + LightLock_Lock(&cond_data->lock); + cond_data->waiting++; LightLock_Unlock(lock); - LightLock_Unlock(&cond->lock); - svcWaitSynchronization(cond->semaphore, INT64_MAX); + LightLock_Unlock(&cond_data->lock); + svcWaitSynchronization(cond_data->semaphore, INT64_MAX); LightLock_Lock(lock); return 0; } static inline int pthread_cond_destroy(pthread_cond_t *cond) { - svcCloseHandle(cond->semaphore); + if (*cond) { + cond_t *cond_data = (cond_t *)*cond; + + svcCloseHandle(cond_data->semaphore); + free(*cond); + } + *cond = 0; return 0; } diff --git a/frontend/libretro.c b/frontend/libretro.c index 699cbce..b473436 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -2270,40 +2270,35 @@ static void update_input_guncon(int port, int ret) //RETRO_DEVICE_ID_LIGHTGUN_AUX_B //Though not sure these are hooked up properly on the Pi - //ToDo - //Put the controller index back to port instead of hardcoding to 1 when the libretro overlay crash bug is fixed - //This is required for 2 player - //GUNCON has 3 controls, Trigger,A,B which equal Circle,Start,Cross // Trigger //The 1 is hardcoded instead of port to prevent the overlay mouse button libretro crash bug - if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) { in_keystate[port] |= (1 << DKEY_CIRCLE); } // A - if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) { in_keystate[port] |= (1 << DKEY_START); } // B - if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE)) + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE)) { in_keystate[port] |= (1 << DKEY_CROSS); } - //The 1 is hardcoded instead of port to prevent the overlay mouse button libretro crash bug - int gunx = input_state_cb(1, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X); - int guny = input_state_cb(1, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y); + int gunx = input_state_cb(port, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X); + int guny = input_state_cb(port, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y); //Mouse range is -32767 -> 32767 //1% is about 655 //Use the left analog stick field to store the absolute coordinates - in_analog_left[0][0] = (gunx * GunconAdjustRatioX) + (GunconAdjustX * 655); - in_analog_left[0][1] = (guny * GunconAdjustRatioY) + (GunconAdjustY * 655); + in_analog_left[port][0] = (gunx * GunconAdjustRatioX) + (GunconAdjustX * 655); + in_analog_left[port][1] = (guny * GunconAdjustRatioY) + (GunconAdjustY * 655); } static void update_input_negcon(int port, int ret) |