From 9340285829dd00e17757486a14b372631c6a1ed7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 21 Feb 2016 13:19:33 -0500 Subject: [PATCH 01/32] 1.2 stdlib: Updated qsort with licensing resolved (thanks, Gareth!). --HG-- branch : SDL-1.2 --- src/stdlib/SDL_qsort.c | 236 +++++++++++++++++++++++++++-------------- 1 file changed, 155 insertions(+), 81 deletions(-) diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 2b5abea8ab..05736f1dce 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -1,54 +1,25 @@ -/* qsort.c - * (c) 1998 Gareth McCaughan - * - * This is a drop-in replacement for the C library's |qsort()| routine. - * - * Features: - * - Median-of-three pivoting (and more) - * - Truncation and final polishing by a single insertion sort - * - Early truncation when no swaps needed in pivoting step - * - Explicit recursion, guaranteed not to overflow - * - A few little wrinkles stolen from the GNU |qsort()|. - * - separate code for non-aligned / aligned / word-size objects - * - * This code may be reproduced freely provided - * - this file is retained unaltered apart from minor - * changes for portability and efficiency - * - no changes are made to this comment - * - any changes that *are* made are clearly flagged - * - the _ID string below is altered by inserting, after - * the date, the string " altered" followed at your option - * by other material. (Exceptions: you may change the name - * of the exported routine without changing the ID string. - * You may change the values of the macros TRUNC_* and - * PIVOT_THRESHOLD without changing the ID string, provided - * they remain constants with TRUNC_nonaligned, TRUNC_aligned - * and TRUNC_words/WORD_BYTES between 8 and 24, and - * PIVOT_THRESHOLD between 32 and 200.) - * - * You may use it in anything you like; you may make money - * out of it; you may distribute it in object form or as - * part of an executable without including source code; - * you don't have to credit me. (But it would be nice if - * you did.) - * - * If you find problems with this code, or find ways of - * making it significantly faster, please let me know! - * My e-mail address, valid as of early 1998 and certainly - * OK for at least the next 18 months, is - * gjm11@dpmms.cam.ac.uk - * Thanks! - * - * Gareth McCaughan Peterhouse Cambridge 1998 - */ -#include "SDL_config.h" - /* -#include -#include -#include + Simple DirectMedia Layer + Copyright (C) 1997-2016 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_stdinc.h" + +#ifndef HAVE_QSORT #ifdef assert #undef assert @@ -57,28 +28,118 @@ #ifdef malloc #undef malloc #endif -#define malloc SDL_malloc +#define malloc SDL_malloc #ifdef free #undef free #endif -#define free SDL_free +#define free SDL_free #ifdef memcpy #undef memcpy #endif -#define memcpy SDL_memcpy +#define memcpy SDL_memcpy #ifdef memmove #undef memmove #endif -#define memmove SDL_memmove -#ifdef qsort -#undef qsort +#define memmove SDL_memmove +#ifdef qsortG +#undef qsortG #endif -#define qsort SDL_qsort +#define qsortG SDL_qsort + +/* +This code came from Gareth McCaughan, under the zlib license. +Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.14 +Everything below this comment until the HAVE_QSORT #endif was from Gareth +(any minor changes will be noted inline). -#ifndef HAVE_QSORT +Thank you to Gareth for relicensing this code under the zlib license for our +benefit! + +--ryan. +*/ + +/* This is a drop-in replacement for the C library's |qsort()| routine. + * + * It is intended for use where you know or suspect that your + * platform's qsort is bad. If that isn't the case, then you + * should probably use the qsort your system gives you in preference + * to mine -- it will likely have been tested and tuned better. + * + * Features: + * - Median-of-three pivoting (and more) + * - Truncation and final polishing by a single insertion sort + * - Early truncation when no swaps needed in pivoting step + * - Explicit recursion, guaranteed not to overflow + * - A few little wrinkles stolen from the GNU |qsort()|. + * (For the avoidance of doubt, no code was stolen, only + * broad ideas.) + * - separate code for non-aligned / aligned / word-size objects + * + * Earlier releases of this code used an idiosyncratic licence + * I wrote myself, because I'm an idiot. The code is now released + * under the "zlib/libpng licence"; you will find the actual + * terms in the next comment. I request (but do not require) + * that if you make any changes beyond the name of the exported + * routine and reasonable tweaks to the TRUNC_* and + * PIVOT_THRESHOLD values, you modify the _ID string so as + * to make it clear that you have changed the code. + * + * If you find problems with this code, or find ways of + * making it significantly faster, please let me know! + * My e-mail address, valid as of early 2016 and for the + * foreseeable future, is + * gareth.mccaughan@pobox.com + * Thanks! + * + * Gareth McCaughan + */ + +/* Copyright (c) 1998-2016 Gareth McCaughan + * + * 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. + */ + +/* Revision history since release: + * 1998-03-19 v1.12 First release I have any records of. + * 2007-09-02 v1.13 Fix bug kindly reported by Dan Bodoh + * (premature termination of recursion). + * Add a few clarifying comments. + * Minor improvements to debug output. + * 2016-02-21 v1.14 Replace licence with 2-clause BSD, + * and clarify a couple of things in + * comments. No code changes. + */ -static char _ID[]=""; +/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */ +#if 0 +#include +#include +#include + +#define DEBUG_QSORT + +static char _ID[]=""; +#endif +/* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */ /* How many bytes are there per word? (Must be a power of 2, * and must in fact equal sizeof(int).) @@ -182,7 +243,9 @@ typedef struct { char * first; char * last; } stack_entry; * 16-bit |int|s and 4096-bit |size_t|s. :-) */ -/* The recursion logic is the same in each case: */ +/* The recursion logic is the same in each case. + * We keep chopping up until we reach subarrays of size + * strictly less than Trunc; we leave these unsorted. */ #define Recurse(Trunc) \ { size_t l=last-ffirst,r=llast-first; \ if (lPIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\ + if (last-first>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\ else { \ if (compare(first,mid)<0) { \ if (compare(mid,last)>0) { \ @@ -220,26 +283,28 @@ typedef struct { char * first; char * last; } stack_entry; /* and so is the partitioning logic: */ #define Partition(swapper,sz) { \ - int swapped=0; \ do { \ while (compare(first,pivot)<0) first+=sz; \ while (compare(pivot,last)<0) last-=sz; \ if (firstlimit ? limit : nmemb-1)*sz;\ + last=first + ((nmemb>limit ? limit : nmemb)-1)*sz;\ while (last!=base) { \ if (compare(first,last)>0) first=last; \ last-=sz; } \ @@ -281,11 +346,14 @@ typedef struct { char * first; char * last; } stack_entry; static char * pivot_big(char *first, char *mid, char *last, size_t size, int compare(const void *, const void *)) { - size_t d=(((last-first)/size)>>3)*size; + int d=(((last-first)/size)>>3)*size; +#ifdef DEBUG_QSORT +fprintf(stderr, "pivot_big: first=%p last=%p size=%lu n=%lu\n", first, (unsigned long)last, size, (unsigned long)((last-first+1)/size)); +#endif char *m1,*m2,*m3; { char *a=first, *b=first+d, *c=first+2*d; #ifdef DEBUG_QSORT -fprintf(stderr,"< %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); +fprintf(stderr,"< %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c); #endif m1 = compare(a,b)<0 ? (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) @@ -293,7 +361,7 @@ fprintf(stderr,"< %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); } { char *a=mid-d, *b=mid, *c=mid+d; #ifdef DEBUG_QSORT -fprintf(stderr,". %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); +fprintf(stderr,". %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c); #endif m2 = compare(a,b)<0 ? (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) @@ -301,14 +369,14 @@ fprintf(stderr,". %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); } { char *a=last-2*d, *b=last-d, *c=last; #ifdef DEBUG_QSORT -fprintf(stderr,"> %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); +fprintf(stderr,"> %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c); #endif m3 = compare(a,b)<0 ? (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); } #ifdef DEBUG_QSORT -fprintf(stderr,"-> %d %d %d\n",*(int*)m1,*(int*)m2,*(int*)m3); +fprintf(stderr,"-> %d %d %d @ %p %p %p\n",*(int*)m1,*(int*)m2,*(int*)m3, m1,m2,m3); #endif return compare(m1,m2)<0 ? (compare(m2,m3)<0 ? m2 : (compare(m1,m3)<0 ? m3 : m1)) @@ -329,7 +397,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size, first=(char*)base; last=first+(nmemb-1)*size; - if ((size_t)(last-first)>trunc) { + if (last-first>=trunc) { char *ffirst=first, *llast=last; while (1) { /* Select pivot */ @@ -343,7 +411,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size, Recurse(trunc) } } - PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size); + PreInsertion(SWAP_nonaligned,TRUNC_nonaligned-1,size); Insertion(SWAP_nonaligned); free(pivot); } @@ -360,7 +428,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size, first=(char*)base; last=first+(nmemb-1)*size; - if ((size_t)(last-first)>trunc) { + if (last-first>=trunc) { char *ffirst=first,*llast=last; while (1) { /* Select pivot */ @@ -374,7 +442,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size, Recurse(trunc) } } - PreInsertion(SWAP_aligned,TRUNC_aligned,size); + PreInsertion(SWAP_aligned,TRUNC_aligned-1,size); Insertion(SWAP_aligned); free(pivot); } @@ -390,7 +458,7 @@ static void qsort_words(void *base, size_t nmemb, first=(char*)base; last=first+(nmemb-1)*WORD_BYTES; - if (last-first>TRUNC_words) { + if (last-first>=TRUNC_words) { char *ffirst=first, *llast=last; while (1) { #ifdef DEBUG_QSORT @@ -402,17 +470,20 @@ fprintf(stderr,"Doing %d:%d: ", { char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES)); Pivot(SWAP_words,WORD_BYTES); *(int*)pivot=*(int*)mid; - } #ifdef DEBUG_QSORT -fprintf(stderr,"pivot=%d\n",*(int*)pivot); +fprintf(stderr,"pivot = %p = #%lu = %d\n", mid, (unsigned long)(((int*)mid)-((int*)base)), *(int*)mid); #endif + } /* Partition. */ Partition(SWAP_words,WORD_BYTES); +#ifdef DEBUG_QSORT +fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)/4lu, (last-(char*)base)/4lu); +#endif /* Prepare to recurse/iterate. */ Recurse(TRUNC_words) } } - PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES); + PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES)-1,WORD_BYTES); /* Now do insertion sort. */ last=((char*)base)+nmemb*WORD_BYTES; for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) { @@ -428,11 +499,11 @@ fprintf(stderr,"pivot=%d\n",*(int*)pivot); /* ---------------------------------------------------------------------- */ -void qsort(void *base, size_t nmemb, size_t size, +extern void qsortG(void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *)) { if (nmemb<=1) return; - if (((uintptr_t)base|size)&(WORD_BYTES-1)) + if (((int)base|size)&(WORD_BYTES-1)) qsort_nonaligned(base,nmemb,size,compare); else if (size!=WORD_BYTES) qsort_aligned(base,nmemb,size,compare); @@ -440,4 +511,7 @@ void qsort(void *base, size_t nmemb, size_t size, qsort_words(base,nmemb,compare); } -#endif /* !HAVE_QSORT */ +#endif /* ifndef HAVE_QSORT */ + +/* vi: set ts=4 sw=4 expandtab: */ + From 1e775278e3b0f493bd47a4d9ebd1b1ca2947553b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 11 Mar 2016 08:30:18 -0800 Subject: [PATCH 02/32] Quick fix for qsort off-by-one error. --HG-- branch : SDL-1.2 --- src/stdlib/SDL_qsort.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 05736f1dce..9bb60ef050 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -411,7 +411,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size, Recurse(trunc) } } - PreInsertion(SWAP_nonaligned,TRUNC_nonaligned-1,size); + PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size); Insertion(SWAP_nonaligned); free(pivot); } @@ -442,7 +442,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size, Recurse(trunc) } } - PreInsertion(SWAP_aligned,TRUNC_aligned-1,size); + PreInsertion(SWAP_aligned,TRUNC_aligned,size); Insertion(SWAP_aligned); free(pivot); } @@ -483,7 +483,7 @@ fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base) Recurse(TRUNC_words) } } - PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES)-1,WORD_BYTES); + PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES); /* Now do insertion sort. */ last=((char*)base)+nmemb*WORD_BYTES; for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) { From eab8ce167fdd658df3779964b88571521a789d99 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 30 Mar 2016 11:23:28 -0400 Subject: [PATCH 03/32] SDL_qsort in SDL 1.2 needs to use the system includes. --HG-- branch : SDL-1.2 --- src/stdlib/SDL_qsort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 9bb60ef050..1e63de657c 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -129,12 +129,12 @@ benefit! * comments. No code changes. */ -/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */ -#if 0 #include #include #include +/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */ +#if 0 #define DEBUG_QSORT static char _ID[]=""; From 8afc9a5faee9927b5e6d8fb2585ca6365330d861 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 30 Mar 2016 13:30:19 -0400 Subject: [PATCH 04/32] gcc-fat.sh: SDL 1.2 won't build with the Mac OS X 10.11 SDK with < 10.7 compat. Several deprecated APIs it uses are flat-out removed from the SDK now. We already had preprocessor checks around them, so gcc-fat.sh just needs its minimum OS compatibility bumped up to 10.7. Leaving the deprecated code in place, however, in case someone wants to target an ancient OS X by compiling with an older SDK. --HG-- branch : SDL-1.2 --- build-scripts/g++-fat.sh | 12 ++++++------ build-scripts/gcc-fat.sh | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build-scripts/g++-fat.sh b/build-scripts/g++-fat.sh index 6e4f53e7ca..fe2be803bb 100755 --- a/build-scripts/g++-fat.sh +++ b/build-scripts/g++-fat.sh @@ -6,17 +6,17 @@ DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer" -# Intel 32-bit compiler flags (10.6 runtime compatibility) -GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.5 \ +# Intel 32-bit compiler flags (10.7 runtime compatibility) +GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.7 \ -I/usr/local/include" -GCC_LINK_X86="-mmacosx-version-min=10.5" +GCC_LINK_X86="-mmacosx-version-min=10.7" -# Intel 64-bit compiler flags (10.6 runtime compatibility) -GCC_COMPILE_X64="g++ -arch x86_64 -mmacosx-version-min=10.6 \ +# Intel 64-bit compiler flags (10.7 runtime compatibility) +GCC_COMPILE_X64="g++ -arch x86_64 -mmacosx-version-min=10.7 \ -I/usr/local/include" -GCC_LINK_X64="-mmacosx-version-min=10.6" +GCC_LINK_X64="-mmacosx-version-min=10.7" # Output both PowerPC and Intel object files args="$*" diff --git a/build-scripts/gcc-fat.sh b/build-scripts/gcc-fat.sh index edabb0d87b..e87a2bc044 100755 --- a/build-scripts/gcc-fat.sh +++ b/build-scripts/gcc-fat.sh @@ -6,18 +6,18 @@ DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer" -# Intel 32-bit compiler flags (10.5 runtime compatibility) -GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.5 \ +# Intel 32-bit compiler flags (10.7 runtime compatibility) +GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.7 \ -I/usr/local/include" -GCC_LINK_X86="-mmacosx-version-min=10.5" +GCC_LINK_X86="-mmacosx-version-min=10.7" -# Intel 64-bit compiler flags (10.6 runtime compatibility) -GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \ --DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \ +# Intel 64-bit compiler flags (10.7 runtime compatibility) +GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.7 \ +-DMAC_OS_X_VERSION_MIN_REQUIRED=1070 \ -I/usr/local/include" -GCC_LINK_X64="-mmacosx-version-min=10.6" +GCC_LINK_X64="-mmacosx-version-min=10.7" # Output both PowerPC and Intel object files args="$*" From 6a38357a502235d48f3fd57892c66a085a04dbb2 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 30 Mar 2016 13:30:59 -0400 Subject: [PATCH 05/32] 1.2 stdlib: include SDL_config.h so we can see if HAVE_QSORT is actually set. --HG-- branch : SDL-1.2 --- src/stdlib/SDL_qsort.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 1e63de657c..44958c7b02 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -19,6 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include "SDL_config.h" + #ifndef HAVE_QSORT #ifdef assert From ec05d22b4907b65474c8577a2bb32105ffcaf9f9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 23 May 2016 15:27:30 -0300 Subject: [PATCH 06/32] SDL 1.2 Windows: Fix other window positions/sizes when exiting fullscreen (bug #3315, thanks Simon Hug!) --HG-- branch : SDL-1.2 --- src/video/windib/SDL_dibvideo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/windib/SDL_dibvideo.c b/src/video/windib/SDL_dibvideo.c index 6187bfcf7e..e096a55b08 100644 --- a/src/video/windib/SDL_dibvideo.c +++ b/src/video/windib/SDL_dibvideo.c @@ -807,7 +807,7 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, } else { #ifndef NO_CHANGEDISPLAYSETTINGS if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { - ChangeDisplaySettings(NULL, 0); + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); } #endif if ( flags & SDL_NOFRAME ) { @@ -1186,7 +1186,7 @@ void DIB_VideoQuit(_THIS) } #ifndef NO_CHANGEDISPLAYSETTINGS if ( this->screen->flags & SDL_FULLSCREEN ) { - ChangeDisplaySettings(NULL, 0); + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); ShowWindow(SDL_Window, SW_HIDE); } #endif From d3486b67ceb367685f290bfcb5f6a1fe4af386fb Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 7 Sep 2016 18:14:26 -0400 Subject: [PATCH 07/32] 1.2 mac: Apparently the magic -psn command line appears in post-10.9 macOSes. So don't bother checking the version. Fixes apps failing to chdir to the app bundle's parent directory, as is expected. --HG-- branch : SDL-1.2 --- src/main/macosx/SDLMain.m | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/macosx/SDLMain.m b/src/main/macosx/SDLMain.m index d43b708ab2..07d392eef5 100644 --- a/src/main/macosx/SDLMain.m +++ b/src/main/macosx/SDLMain.m @@ -358,25 +358,16 @@ static int IsRootCwd() return (cwd && (strcmp(cwd, "/") == 0)); } -static int IsTenPointNineOrLater() -{ - /* Gestalt() is deprecated in 10.8, but I don't care. Stop using SDL 1.2. */ - SInt32 major, minor; - Gestalt(gestaltSystemVersionMajor, &major); - Gestalt(gestaltSystemVersionMinor, &minor); - return ( ((major << 16) | minor) >= ((10 << 16) | 9) ); -} - static int IsFinderLaunch(const int argc, char **argv) { - const int bIsNewerOS = IsTenPointNineOrLater(); - /* -psn_XXX is passed if we are launched from Finder in 10.8 and earlier */ - if ( (!bIsNewerOS) && (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { return 1; - } else if ((bIsNewerOS) && (argc == 1) && IsRootCwd()) { + } else if ((argc == 1) && IsRootCwd()) { /* we might still be launched from the Finder; on 10.9+, you might not - get the -psn command line anymore. Check version, if there's no - command line, and if our current working directory is "/". */ + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ return 1; } return 0; /* not a Finder launch. */ From c82a26edef54c95c880f57e44483b2f873583edf Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 12 Oct 2016 16:27:37 +0200 Subject: [PATCH 08/32] PSP2: add psp2 (ps vita) support --- Makefile.psp2 | 46 ++++ Makefile.psp2-test | 40 ++++ include/SDL_config.h | 47 +++++ include/SDL_config.h.default | 2 + include/SDL_config_psp2.h | 140 +++++++++++++ include/SDL_stdinc.h | 2 + src/audio/SDL_audio.c | 3 + src/audio/SDL_sysaudio.h | 3 + src/audio/psp2/SDL_psp2audio.c | 207 ++++++++++++++++++ src/audio/psp2/SDL_psp2audio.h | 46 ++++ src/joystick/psp2/SDL_sysjoystick.c | 192 +++++++++++++++++ src/thread/SDL_thread_c.h | 2 + src/thread/psp2/SDL_syscond.c | 219 +++++++++++++++++++ src/thread/psp2/SDL_sysmutex.c | 133 ++++++++++++ src/thread/psp2/SDL_sysmutex_c.h | 23 ++ src/thread/psp2/SDL_syssem.c | 172 +++++++++++++++ src/thread/psp2/SDL_systhread.c | 87 ++++++++ src/thread/psp2/SDL_systhread_c.h | 26 +++ src/timer/psp2/SDL_systimer.c | 112 ++++++++++ src/video/SDL_sysvideo.h | 3 + src/video/SDL_video.c | 3 + src/video/psp2/SDL_psp2events.c | 45 ++++ src/video/psp2/SDL_psp2events_c.h | 33 +++ src/video/psp2/SDL_psp2mouse.c | 33 +++ src/video/psp2/SDL_psp2mouse_c.h | 26 +++ src/video/psp2/SDL_psp2video.c | 315 ++++++++++++++++++++++++++++ src/video/psp2/SDL_psp2video.h | 41 ++++ 27 files changed, 2001 insertions(+) create mode 100644 Makefile.psp2 create mode 100644 Makefile.psp2-test create mode 100644 include/SDL_config.h create mode 100644 include/SDL_config_psp2.h create mode 100644 src/audio/psp2/SDL_psp2audio.c create mode 100644 src/audio/psp2/SDL_psp2audio.h create mode 100644 src/joystick/psp2/SDL_sysjoystick.c create mode 100644 src/thread/psp2/SDL_syscond.c create mode 100644 src/thread/psp2/SDL_sysmutex.c create mode 100644 src/thread/psp2/SDL_sysmutex_c.h create mode 100644 src/thread/psp2/SDL_syssem.c create mode 100644 src/thread/psp2/SDL_systhread.c create mode 100644 src/thread/psp2/SDL_systhread_c.h create mode 100644 src/timer/psp2/SDL_systimer.c create mode 100644 src/video/psp2/SDL_psp2events.c create mode 100644 src/video/psp2/SDL_psp2events_c.h create mode 100644 src/video/psp2/SDL_psp2mouse.c create mode 100644 src/video/psp2/SDL_psp2mouse_c.h create mode 100644 src/video/psp2/SDL_psp2video.c create mode 100644 src/video/psp2/SDL_psp2video.h diff --git a/Makefile.psp2 b/Makefile.psp2 new file mode 100644 index 0000000000..2321eec1fe --- /dev/null +++ b/Makefile.psp2 @@ -0,0 +1,46 @@ +# Makefile to build the SDL library + +INCLUDE = -I./include +CFLAGS = -Wl,-q -g -O3 -D__PSP2__ $(INCLUDE) + +CC = arm-vita-eabi-gcc +AR = arm-vita-eabi-ar +RANLIB = arm-vita-eabi-ranlib + +CONFIG_H = include/SDL_config.h +TARGET = libSDL.a +SOURCES = \ + src/*.c \ + src/audio/*.c \ + src/cdrom/*.c \ + src/cpuinfo/*.c \ + src/events/*.c \ + src/file/*.c \ + src/joystick/*.c \ + src/stdlib/*.c \ + src/thread/*.c \ + src/timer/*.c \ + src/video/*.c \ + src/audio/psp2/*.c \ + src/video/psp2/*.c \ + src/joystick/psp2/*.c \ + src/cdrom/dummy/*.c \ + src/thread/psp2/*.c \ + src/timer/psp2/*.c \ + src/loadso/dummy/*.c \ + +OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g') + +all: $(TARGET) + make -f Makefile.psp2-test clean + make -f Makefile.psp2-test + +$(TARGET): $(CONFIG_H) $(OBJECTS) + $(AR) crv $@ $^ + $(RANLIB) $@ + +$(CONFIG_H): + cp $(CONFIG_H).default $(CONFIG_H) + +clean: + rm -f $(TARGET) $(OBJECTS) diff --git a/Makefile.psp2-test b/Makefile.psp2-test new file mode 100644 index 0000000000..42f7287677 --- /dev/null +++ b/Makefile.psp2-test @@ -0,0 +1,40 @@ +TITLE_ID = VSDL00009 +TARGET = vitasdl +OBJS = test/testsprite.o + +LIBS = ./libSDL.a -lpsp2shell -lvita2d -lSceDisplay_stub -lSceGxm_stub \ + -lSceSysmodule_stub -lSceCtrl_stub -lScePgf_stub -lSceNetCtl_stub \ + -lSceNet_stub -lScePower_stub -lSceKernel_stub -lSceCommonDialog_stub \ + -lSceAudio_stub -lSceAppMgr_stub -lpng -ljpeg -lz -lm -lc + +PREFIX = arm-vita-eabi +CC = $(PREFIX)-gcc +CFLAGS = -Wl,-q -Wall -O3 -D__PSP2__ -Iinclude -I$(VITASDK)/arm-vita-eabi/include +ASFLAGS = $(CFLAGS) + +all: $(TARGET).vpk + +%.vpk: eboot.bin + vita-mksfoex -s TITLE_ID=$(TITLE_ID) "$(TARGET)" param.sfo + vita-pack-vpk -s param.sfo -b eboot.bin $@ + +eboot.bin: $(TARGET).velf + vita-make-fself $< $@ + +%.velf: %.elf + vita-elf-create $< $@ + +$(TARGET).elf: $(OBJS) + $(CC) $(CFLAGS) $^ $(LIBS) -o $@ + +clean: + @rm -rf $(TARGET).vpk $(TARGET).velf $(TARGET).elf $(OBJS) \ + eboot.bin param.sfo + +vpksend: $(TARGET).vpk + curl -T $(TARGET).vpk ftp://$(PSVITAIP):1337/ux0:/ + @echo "Sent." + +send: eboot.bin + curl -T eboot.bin ftp://$(PSVITAIP):1337/ux0:/app/$(TITLE_ID)/ + @echo "Sent." diff --git a/include/SDL_config.h b/include/SDL_config.h new file mode 100644 index 0000000000..5207ae016e --- /dev/null +++ b/include/SDL_config.h @@ -0,0 +1,47 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_h +#define _SDL_config_h + +#include "SDL_platform.h" + +/* Add any platform that doesn't build using the configure system */ +#if defined(__DREAMCAST__) +#include "SDL_config_dreamcast.h" +#elif defined(__MACOS__) +#include "SDL_config_macos.h" +#elif defined(__MACOSX__) +#include "SDL_config_macosx.h" +#elif defined(__SYMBIAN32__) +#include "SDL_config_symbian.h" /* must be before win32! */ +#elif defined(__WIN32__) +#include "SDL_config_win32.h" +#elif defined(__OS2__) +#include "SDL_config_os2.h" +#elif defined(__PSP2__) +#include "SDL_config_psp2.h" +#else +#include "SDL_config_minimal.h" +#endif /* platform config */ + +#endif /* _SDL_config_h */ diff --git a/include/SDL_config.h.default b/include/SDL_config.h.default index 09ba38a711..5207ae016e 100644 --- a/include/SDL_config.h.default +++ b/include/SDL_config.h.default @@ -38,6 +38,8 @@ #include "SDL_config_win32.h" #elif defined(__OS2__) #include "SDL_config_os2.h" +#elif defined(__PSP2__) +#include "SDL_config_psp2.h" #else #include "SDL_config_minimal.h" #endif /* platform config */ diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h new file mode 100644 index 0000000000..5370cecc91 --- /dev/null +++ b/include/SDL_config_psp2.h @@ -0,0 +1,140 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_minimal_h +#define _SDL_config_minimal_h + +#include "SDL_platform.h" + +/* This is the minimal configuration that can be used to build SDL */ + +#include +#include +#include + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef unsigned int size_t; + +#define HAVE_GCC_ATOMICS 1 + +#define HAVE_ALLOCA_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_SETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_SETENV 1 +#define HAVE_UNSETENV 1 +#define HAVE_QSORT 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_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +#define HAVE_STRDUP 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#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 +#define HAVE_STRCASECMP 1 +#define HAVE_STRNCASECMP 1 +#define HAVE_VSSCANF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_M_PI 1 +#define HAVE_ATAN 1 +#define HAVE_ATAN2 1 +#define HAVE_ACOS 1 +#define HAVE_ASIN 1 +#define HAVE_CEIL 1 +#define HAVE_COPYSIGN 1 +#define HAVE_COS 1 +#define HAVE_COSF 1 +#define HAVE_FABS 1 +#define HAVE_FLOOR 1 +#define HAVE_LOG 1 +#define HAVE_POW 1 +#define HAVE_SCALBN 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_SETJMP 1 +#define HAVE_NANOSLEEP 1 +/* #define HAVE_SYSCONF 1 */ +/* #define HAVE_SIGACTION 1 */ + +/* VITA isn't that sophisticated */ +#define LACKS_SYS_MMAN_H 1 + +/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */ +#define SDL_CDROM_DISABLED 1 + +/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */ +#define SDL_LOADSO_DISABLED 1 + +/* Enable the stub joystick driver (src/joystick/psp2/\*.c) */ +#define SDL_JOYSTICK_PSP2 1 + +/* Enable the psp2 audio driver (src/audio/psp2/\*.c) */ +#define SDL_AUDIO_DRIVER_PSP2 1 + +/* Enable the stub thread support (src/thread/psp2/\*.c) */ +#define SDL_THREAD_PSP2 1 + +/* Enable the psp2 timer support (src/timer/psp2/\*.c) */ +#define SDL_TIMER_PSP2 1 + +/* Enable the psp2 video driver (src/video/psp2/\*.c) */ +#define SDL_VIDEO_DRIVER_PSP2 1 + +#endif /* _SDL_config_psp2_h */ diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 35a4fdde59..a25fdf935a 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -148,8 +148,10 @@ typedef enum { } SDL_DUMMY_ENUM; #ifndef __NDS__ +#ifndef __PSP2__ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); #endif +#endif /*@}*/ #include "begin_code.h" diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 9babb91741..b506de2135 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -115,6 +115,9 @@ static AudioBootStrap *bootstrap[] = { #endif #if SDL_AUDIO_DRIVER_EPOCAUDIO &EPOCAudio_bootstrap, +#endif +#if SDL_AUDIO_DRIVER_PSP2 + &PSP2AUD_bootstrap, #endif NULL }; diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index fa29a2bbdb..b6b0c97c5f 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -182,6 +182,9 @@ extern AudioBootStrap DART_bootstrap; #if SDL_AUDIO_DRIVER_EPOCAUDIO extern AudioBootStrap EPOCAudio_bootstrap; #endif +#if SDL_AUDIO_DRIVER_PSP2 +extern AudioBootStrap PSP2AUD_bootstrap; +#endif /* This is the current audio device */ extern SDL_AudioDevice *current_audio; diff --git a/src/audio/psp2/SDL_psp2audio.c b/src/audio/psp2/SDL_psp2audio.c new file mode 100644 index 0000000000..97de091953 --- /dev/null +++ b/src/audio/psp2/SDL_psp2audio.c @@ -0,0 +1,207 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org + + This file written by Ryan C. Gordon (icculus@icculus.org) +*/ +#include "SDL_config.h" + +/* Output audio to nowhere... */ + +#include "SDL_rwops.h" +#include "SDL_timer.h" +#include "SDL_audio.h" +#include "../SDL_audiomem.h" +#include "../SDL_audio_c.h" +#include "../SDL_audiodev_c.h" + +#include "SDL_psp2audio.h" + +#include +#include + +/* The tag name used by DUMMY audio */ +#define PSP2AUD_DRIVER_NAME "psp2" + +#define SDL_AUDIO_MASK_BITSIZE (0xFF) +#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE) + +#define SCE_AUDIO_SAMPLE_ALIGN(s) (((s) + 63) & ~63) +#define SCE_AUDIO_MAX_VOLUME 0x8000 + +/* Audio driver functions */ +static int PSP2AUD_OpenAudio(_THIS, SDL_AudioSpec *spec); +static void PSP2AUD_WaitAudio(_THIS); +static void PSP2AUD_PlayAudio(_THIS); +static Uint8 *PSP2AUD_GetAudioBuf(_THIS); +static void PSP2AUD_CloseAudio(_THIS); + +/* Audio driver bootstrap functions */ +static int PSP2AUD_Available(void) +{ + return(1); +} + +static void PSP2AUD_ThreadInit(_THIS) +{ + /* Increase the priority of this audio thread by 1 to put it + ahead of other SDL threads. */ + SceUID thid; + SceKernelThreadInfo info; + thid = sceKernelGetThreadId(); + info.size = sizeof(SceKernelThreadInfo); + if (sceKernelGetThreadInfo(thid, &info) == 0) { + sceKernelChangeThreadPriority(thid, info.currentPriority - 1); + } +} + +static void PSP2AUD_DeleteDevice(SDL_AudioDevice *device) +{ + SDL_free(device->hidden); + SDL_free(device); +} + +static SDL_AudioDevice *PSP2AUD_CreateDevice(int devindex) +{ + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); + if ( this ) { + SDL_memset(this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc((sizeof *this->hidden)); + } + if ( (this == NULL) || (this->hidden == NULL) ) { + SDL_OutOfMemory(); + if ( this ) { + SDL_free(this); + } + return(0); + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = PSP2AUD_OpenAudio; + this->WaitAudio = PSP2AUD_WaitAudio; + this->PlayAudio = PSP2AUD_PlayAudio; + this->GetAudioBuf = PSP2AUD_GetAudioBuf; + this->CloseAudio = PSP2AUD_CloseAudio; + this->ThreadInit = PSP2AUD_ThreadInit; + + this->free = PSP2AUD_DeleteDevice; + + return this; +} + +AudioBootStrap PSP2AUD_bootstrap = { + PSP2AUD_DRIVER_NAME, "SDL psp2 audio driver", + PSP2AUD_Available, PSP2AUD_CreateDevice +}; + +/* This function waits until it is possible to write a full sound buffer */ +static void PSP2AUD_WaitAudio(_THIS) +{ +} + +static void PSP2AUD_PlayAudio(_THIS) +{ + Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer]; + + int vols[2] = {SCE_AUDIO_MAX_VOLUME, SCE_AUDIO_MAX_VOLUME}; + sceAudioOutSetVolume(this->hidden->channel, SCE_AUDIO_VOLUME_FLAG_L_CH|SCE_AUDIO_VOLUME_FLAG_R_CH, vols); + sceAudioOutOutput(this->hidden->channel, mixbuf); + + this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; +} + +static Uint8 *PSP2AUD_GetAudioBuf(_THIS) +{ + return this->hidden->mixbufs[this->hidden->next_buffer]; +} + +static void PSP2AUD_CloseAudio(_THIS) +{ + if (this->hidden->channel >= 0) { + sceAudioOutReleasePort(this->hidden->channel); + this->hidden->channel = -1; + } + + if (this->hidden->rawbuf != NULL) { + free(this->hidden->rawbuf); + this->hidden->rawbuf = NULL; + } +} + +static int PSP2AUD_OpenAudio(_THIS, SDL_AudioSpec *spec) +{ + int format, mixlen, i; + + /* The sample count must be a multiple of 64. */ + this->spec.samples = SCE_AUDIO_SAMPLE_ALIGN(this->spec.samples); + this->spec.freq = 48000; + + /* Update the fragment size as size in bytes. */ + /* SDL_CalculateAudioSpec(this->spec); MOD */ + switch (this->spec.format) { + case AUDIO_U8: + this->spec.silence = 0x80; + break; + default: + this->spec.silence = 0x00; + break; + } + this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8; + this->spec.size *= this->spec.channels; + this->spec.size *= this->spec.samples; + + /* Allocate the mixing buffer. Its size and starting address must + be a multiple of 64 bytes. Our sample count is already a multiple of + 64, so spec->size should be a multiple of 64 as well. */ + mixlen = this->spec.size * NUM_BUFFERS; + this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen); + if (this->hidden->rawbuf == NULL) { + SDL_SetError("Couldn't allocate mixing buffer"); + return -1; + } + + /* Setup the hardware channel. */ + if (this->spec.channels == 1) { + format = SCE_AUDIO_OUT_MODE_MONO; + } else { + format = SCE_AUDIO_OUT_MODE_STEREO; + } + this->hidden->channel = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, this->spec.samples, this->spec.freq, format); + if (this->hidden->channel < 0) { + free(this->hidden->rawbuf); + this->hidden->rawbuf = NULL; + SDL_SetError("Couldn't reserve hardware channel"); + return -1; + } + + memset(this->hidden->rawbuf, 0, mixlen); + for (i = 0; i < NUM_BUFFERS; i++) { + this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size]; + } + + this->hidden->next_buffer = 0; + return 0; +} + diff --git a/src/audio/psp2/SDL_psp2audio.h b/src/audio/psp2/SDL_psp2audio.h new file mode 100644 index 0000000000..e147c59e62 --- /dev/null +++ b/src/audio/psp2/SDL_psp2audio.h @@ -0,0 +1,46 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_psp2audio_h +#define _SDL_psp2audio_h + +#include "../SDL_sysaudio.h" + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_AudioDevice *this + +#define NUM_BUFFERS 2 + +struct SDL_PrivateAudioData { + /* The file descriptor for the audio device */ + /* The hardware output channel. */ + int channel; + /* The raw allocated mixing buffer. */ + Uint8 *rawbuf; + /* Individual mixing buffers. */ + Uint8 *mixbufs[NUM_BUFFERS]; + /* Index of the next available mixing buffer. */ + int next_buffer; +}; + +#endif /* _SDL_psp2audio_h */ diff --git a/src/joystick/psp2/SDL_sysjoystick.c b/src/joystick/psp2/SDL_sysjoystick.c new file mode 100644 index 0000000000..88d9711e46 --- /dev/null +++ b/src/joystick/psp2/SDL_sysjoystick.c @@ -0,0 +1,192 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if SDL_JOYSTICK_PSP2 + +/* This is the system specific header for the SDL joystick API */ + +#include "SDL_joystick.h" +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" + +#include +#include +#include + +/* Current pad state */ +static SceCtrlData pad = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; +static const unsigned int button_map[] = { + SCE_CTRL_TRIANGLE, SCE_CTRL_CIRCLE, SCE_CTRL_CROSS, SCE_CTRL_SQUARE, + SCE_CTRL_LTRIGGER, SCE_CTRL_RTRIGGER, + SCE_CTRL_DOWN, SCE_CTRL_LEFT, SCE_CTRL_UP, SCE_CTRL_RIGHT, + SCE_CTRL_SELECT, SCE_CTRL_START}; +static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */ + +typedef struct +{ + int x; + int y; +} point; + +/* 4 points define the bezier-curve. */ +static point a = { 0, 0 }; +static point b = { 50, 0 }; +static point c = { 78, 32767 }; +static point d = { 128, 32767 }; + +/* simple linear interpolation between two points */ +static inline void lerp (point *dest, point *a, point *b, float t) +{ + dest->x = a->x + (b->x - a->x)*t; + dest->y = a->y + (b->y - a->y)*t; +} + +/* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */ +static int calc_bezier_y(float t) +{ + point ab, bc, cd, abbc, bccd, dest; + lerp (&ab, &a, &b, t); /* point between a and b */ + lerp (&bc, &b, &c, t); /* point between b and c */ + lerp (&cd, &c, &d, t); /* point between c and d */ + lerp (&abbc, &ab, &bc, t); /* point between ab and bc */ + lerp (&bccd, &bc, &cd, t); /* point between bc and cd */ + lerp (&dest, &abbc, &bccd, t); /* point on the bezier-curve */ + return dest.y; +} + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int SDL_SYS_JoystickInit(void) +{ + int i; + + /* Setup input */ + sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); + + /* Create an accurate map from analog inputs (0 to 255) + to SDL joystick positions (-32768 to 32767) */ + for (i = 0; i < 128; i++) + { + float t = (float)i/127.0f; + analog_map[i+128] = calc_bezier_y(t); + analog_map[127-i] = -1 * analog_map[i+128]; + } + + return 1; +} + +/* Function to get the device-dependent name of a joystick */ +const char *SDL_SYS_JoystickName(int index) +{ + if (index == 0) + return "psp2 controller"; + + SDL_SetError("No joystick available with that index"); + return(NULL); +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +{ + joystick->nbuttons = sizeof(button_map)/sizeof(*button_map); + joystick->naxes = 4; + joystick->nhats = 0; + + return 0; +} + +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +{ + int i; + unsigned int buttons; + unsigned int changed; + unsigned char lx, ly, rx, ry; + static unsigned int old_buttons = 0; + static unsigned char old_lx = 0, old_ly = 0; + static unsigned char old_rx = 0, old_ry = 0; + + sceCtrlPeekBufferPositive(0, &pad, 1); + + buttons = pad.buttons; + lx = pad.lx; + ly = pad.ly; + rx = pad.rx; + ry = pad.ry; + + /* Axes */ + if(old_lx != lx) { + SDL_PrivateJoystickAxis(joystick, 0, analog_map[lx]); + old_lx = lx; + } + if(old_ly != ly) { + SDL_PrivateJoystickAxis(joystick, 1, analog_map[ly]); + old_ly = ly; + } + if(old_rx != rx) { + SDL_PrivateJoystickAxis(joystick, 2, analog_map[rx]); + old_rx = rx; + } + if(old_ry != ry) { + SDL_PrivateJoystickAxis(joystick, 3, analog_map[ry]); + old_ry = ry; + } + + /* Buttons */ + changed = old_buttons ^ buttons; + old_buttons = buttons; + if(changed) { + for(i=0; ilock = SDL_CreateMutex(); + cond->wait_sem = SDL_CreateSemaphore(0); + cond->wait_done = SDL_CreateSemaphore(0); + cond->waiting = cond->signals = 0; + if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) { + SDL_DestroyCond(cond); + cond = NULL; + } + } else { + SDL_OutOfMemory(); + } + return(cond); +} + +/* Destroy a condition variable */ +void SDL_DestroyCond(SDL_cond *cond) +{ + if ( cond ) { + if ( cond->wait_sem ) { + SDL_DestroySemaphore(cond->wait_sem); + } + if ( cond->wait_done ) { + SDL_DestroySemaphore(cond->wait_done); + } + if ( cond->lock ) { + SDL_DestroyMutex(cond->lock); + } + SDL_free(cond); + } +} + +/* Restart one of the threads that are waiting on the condition variable */ +int SDL_CondSignal(SDL_cond *cond) +{ + if ( ! cond ) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex(cond->lock); + if ( cond->waiting > cond->signals ) { + ++cond->signals; + SDL_SemPost(cond->wait_sem); + SDL_UnlockMutex(cond->lock); + SDL_SemWait(cond->wait_done); + } else { + SDL_UnlockMutex(cond->lock); + } + + return 0; +} + +/* Restart all threads that are waiting on the condition variable */ +int SDL_CondBroadcast(SDL_cond *cond) +{ + if ( ! cond ) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex(cond->lock); + if ( cond->waiting > cond->signals ) { + int i, num_waiting; + + num_waiting = (cond->waiting - cond->signals); + cond->signals = cond->waiting; + for ( i=0; iwait_sem); + } + /* Now all released threads are blocked here, waiting for us. + Collect them all (and win fabulous prizes!) :-) + */ + SDL_UnlockMutex(cond->lock); + for ( i=0; iwait_done); + } + } else { + SDL_UnlockMutex(cond->lock); + } + + return 0; +} + +/* Wait on the condition variable for at most 'ms' milliseconds. + The mutex must be locked before entering this function! + The mutex is unlocked during the wait, and locked again after the wait. + +Typical use: + +Thread A: + SDL_LockMutex(lock); + while ( ! condition ) { + SDL_CondWait(cond); + } + SDL_UnlockMutex(lock); + +Thread B: + SDL_LockMutex(lock); + ... + condition = true; + ... + SDL_UnlockMutex(lock); + */ +int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +{ + int retval; + + if ( ! cond ) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* Obtain the protection mutex, and increment the number of waiters. + This allows the signal mechanism to only perform a signal if there + are waiting threads. + */ + SDL_LockMutex(cond->lock); + ++cond->waiting; + SDL_UnlockMutex(cond->lock); + + /* Unlock the mutex, as is required by condition variable semantics */ + SDL_UnlockMutex(mutex); + + /* Wait for a signal */ + if ( ms == SDL_MUTEX_MAXWAIT ) { + retval = SDL_SemWait(cond->wait_sem); + } else { + retval = SDL_SemWaitTimeout(cond->wait_sem, ms); + } + + /* Let the signaler know we have completed the wait, otherwise + the signaler can race ahead and get the condition semaphore + if we are stopped between the mutex unlock and semaphore wait, + giving a deadlock. See the following URL for details: + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html + */ + SDL_LockMutex(cond->lock); + if ( cond->signals > 0 ) { + /* If we timed out, we need to eat a condition signal */ + if ( retval > 0 ) { + SDL_SemWait(cond->wait_sem); + } + /* We always notify the signal thread that we are done */ + SDL_SemPost(cond->wait_done); + + /* Signal handshake complete */ + --cond->signals; + } + --cond->waiting; + SDL_UnlockMutex(cond->lock); + + /* Lock the mutex, as is required by condition variable semantics */ + SDL_LockMutex(mutex); + + return retval; +} + +/* Wait on the condition variable forever */ +int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +{ + return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); +} + +#endif // SDL_THREAD_PSP2 diff --git a/src/thread/psp2/SDL_sysmutex.c b/src/thread/psp2/SDL_sysmutex.c new file mode 100644 index 0000000000..741737cf11 --- /dev/null +++ b/src/thread/psp2/SDL_sysmutex.c @@ -0,0 +1,133 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if SDL_THREAD_PSP2 + +/* An implementation of mutexes using semaphores */ + +#include "SDL_thread.h" +#include "SDL_systhread_c.h" + + +struct SDL_mutex { + int recursive; + Uint32 owner; + SDL_sem *sem; +}; + +/* Create a mutex */ +SDL_mutex *SDL_CreateMutex(void) +{ + SDL_mutex *mutex; + + /* Allocate mutex memory */ + mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); + if ( mutex ) { + /* Create the mutex semaphore, with initial value 1 */ + mutex->sem = SDL_CreateSemaphore(1); + mutex->recursive = 0; + mutex->owner = 0; + if ( ! mutex->sem ) { + SDL_free(mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory(); + } + return mutex; +} + +/* Free the mutex */ +void SDL_DestroyMutex(SDL_mutex *mutex) +{ + if ( mutex ) { + if ( mutex->sem ) { + SDL_DestroySemaphore(mutex->sem); + } + SDL_free(mutex); + } +} + +/* Lock the semaphore */ +int SDL_mutexP(SDL_mutex *mutex) +{ +#if SDL_THREADS_DISABLED + return 0; +#else + Uint32 this_thread; + + if ( mutex == NULL ) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID(); + if ( mutex->owner == this_thread ) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + SDL_SemWait(mutex->sem); + mutex->owner = this_thread; + mutex->recursive = 0; + } + + return 0; +#endif /* SDL_THREADS_DISABLED */ +} + +/* Unlock the mutex */ +int SDL_mutexV(SDL_mutex *mutex) +{ +#if SDL_THREADS_DISABLED + return 0; +#else + if ( mutex == NULL ) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + /* If we don't own the mutex, we can't unlock it */ + if ( SDL_ThreadID() != mutex->owner ) { + SDL_SetError("mutex not owned by this thread"); + return -1; + } + + if ( mutex->recursive ) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + SDL_SemPost(mutex->sem); + } + return 0; +#endif /* SDL_THREADS_DISABLED */ +} + +#endif // SDL_THREAD_PSP2 diff --git a/src/thread/psp2/SDL_sysmutex_c.h b/src/thread/psp2/SDL_sysmutex_c.h new file mode 100644 index 0000000000..1120b2d80d --- /dev/null +++ b/src/thread/psp2/SDL_sysmutex_c.h @@ -0,0 +1,23 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + diff --git a/src/thread/psp2/SDL_syssem.c b/src/thread/psp2/SDL_syssem.c new file mode 100644 index 0000000000..e7eda52a90 --- /dev/null +++ b/src/thread/psp2/SDL_syssem.c @@ -0,0 +1,172 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if SDL_THREAD_PSP2 + +/* An implementation of semaphores using mutexes and condition variables */ + +#include "SDL_timer.h" +#include "SDL_thread.h" +#include "SDL_systhread_c.h" + +#include +#include +#include + +struct SDL_semaphore +{ + SceUID semid; +}; + +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +{ + SDL_sem *sem; + + sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); + if ( ! sem ) + { + SDL_OutOfMemory(); + return NULL; + } + + sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, 0); + if (sem->semid < 0) + { + SDL_SetError("Couldn't create semaphore"); + free(sem); + sem = NULL; + } + + return sem; +} + +/* WARNING: + You cannot call this function when another thread is using the semaphore. +*/ +void SDL_DestroySemaphore(SDL_sem *sem) +{ + if (sem != NULL) + { + if (sem->semid > 0) + { + sceKernelDeleteSema(sem->semid); + sem->semid = 0; + } + free(sem); + } +} + +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +{ + Uint32 *pTimeout; + unsigned int res; + + if (sem == NULL) + { + SDL_SetError("Passed a NULL sem"); + return 0; + } + + if (timeout == 0) + { + res = sceKernelPollSema(sem->semid, 1); + if (res < 0) + { + return SDL_MUTEX_TIMEDOUT; + } + return 0; + } + + if (timeout == SDL_MUTEX_MAXWAIT) + { + pTimeout = NULL; + } + else + { + timeout *= 1000; /* Convert to microseconds. */ + pTimeout = &timeout; + } + + res = sceKernelWaitSema(sem->semid, 1, pTimeout); + switch (res) + { + case SCE_KERNEL_OK: + return 0; + case SCE_KERNEL_ERROR_WAIT_TIMEOUT: + return SDL_MUTEX_TIMEDOUT; + default: + SDL_SetError("WaitForSingleObject() failed"); + return -1; + } +} + +int SDL_SemTryWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, 0); +} + +int SDL_SemWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); +} + +Uint32 SDL_SemValue(SDL_sem *sem) +{ + SceKernelSemaInfo info; + info.size = sizeof(info); + + if (sem == NULL) + { + SDL_SetError("Passed a NULL sem"); + return 0; + } + + if (sceKernelGetSemaInfo(sem->semid, &info) >= 0) + { + return info.currentCount; + } + + return 0; +} + +int SDL_SemPost(SDL_sem *sem) +{ + int res; + + if (sem == NULL) + { + SDL_SetError("Passed a NULL sem"); + return -1; + } + + res = sceKernelSignalSema(sem->semid, 1); + if (res < 0) + { + SDL_SetError("sceKernelSignalSema() failed"); + return -1; + } + + return 0; +} + +#endif // SDL_THREAD_PSP2 diff --git a/src/thread/psp2/SDL_systhread.c b/src/thread/psp2/SDL_systhread.c new file mode 100644 index 0000000000..0ad1822504 --- /dev/null +++ b/src/thread/psp2/SDL_systhread.c @@ -0,0 +1,87 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Thread management routines for SDL */ + +#if SDL_THREAD_PSP2 + +#include "SDL_thread.h" +#include "../SDL_thread_c.h" +#include "../SDL_systhread.h" + +#include +#include + +static int ThreadEntry(SceSize args, void *argp) +{ + SDL_RunThread(*(void **) argp); + return 0; +} + +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +{ + SceKernelThreadInfo info; + int priority = 32; + + /* Set priority of new thread to the same as the current thread */ + info.size = sizeof(SceKernelThreadInfo); + if (sceKernelGetThreadInfo(sceKernelGetThreadId(), &info) == 0) + { + priority = info.currentPriority; + } + + thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry, + priority, 0x10000, 0, 0, NULL); + + if (thread->handle < 0) + { + SDL_SetError("sceKernelCreateThread() failed"); + return -1; + } + + sceKernelStartThread(thread->handle, 4, &args); + return 0; +} + +void SDL_SYS_SetupThread(void) +{ + return; +} + +Uint32 SDL_ThreadID(void) +{ + return (Uint32) sceKernelGetThreadId(); +} + +void SDL_SYS_WaitThread(SDL_Thread *thread) +{ + sceKernelWaitThreadEnd(thread->handle, NULL, NULL); + sceKernelDeleteThread(thread->handle); +} + +void SDL_SYS_KillThread(SDL_Thread *thread) +{ + sceKernelDeleteThread(thread->handle); +} + +#endif // SDL_THREAD_PSP2 diff --git a/src/thread/psp2/SDL_systhread_c.h b/src/thread/psp2/SDL_systhread_c.h new file mode 100644 index 0000000000..a9fe662e64 --- /dev/null +++ b/src/thread/psp2/SDL_systhread_c.h @@ -0,0 +1,26 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include + +typedef SceUID SYS_ThreadHandle; diff --git a/src/timer/psp2/SDL_systimer.c b/src/timer/psp2/SDL_systimer.c new file mode 100644 index 0000000000..a61f5aa02b --- /dev/null +++ b/src/timer/psp2/SDL_systimer.c @@ -0,0 +1,112 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if defined(SDL_TIMER_PSP2) + +#include "SDL_timer.h" +#include "../SDL_timer_c.h" +#include + +static uint64_t start; +static SDL_bool ticks_started = SDL_FALSE; + +void SDL_StartTicks(void) +{ + if (ticks_started) + { + return; + } + ticks_started = SDL_TRUE; + start = sceKernelGetProcessTimeWide(); +} + +Uint32 SDL_GetTicks (void) +{ + if (!ticks_started) { + SDL_StartTicks(); + } + + uint64_t now; + Uint32 ticks; + + now = sceKernelGetProcessTimeWide(); + ticks = (now - start)/1000; + return (ticks); +} + +void SDL_Delay (Uint32 ms) +{ + const Uint32 max_delay = 0xffffffffUL / 1000; + if(ms > max_delay) + ms = max_delay; + sceKernelDelayThreadCB(ms * 1000); +} + +#include "SDL_thread.h" + +/* Data to handle a single periodic alarm */ +static int timer_alive = 0; +static SDL_Thread *timer = NULL; + +static int RunTimer(void *unused) +{ + while ( timer_alive ) { + if ( SDL_timer_running ) { + SDL_ThreadedTimerCheck(); + } + SDL_Delay(1); + } + return(0); +} + +/* This is only called if the event thread is not running */ +int SDL_SYS_TimerInit(void) +{ + timer_alive = 1; + timer = SDL_CreateThread(RunTimer, NULL); + if ( timer == NULL ) + return(-1); + return(SDL_SetTimerThreaded(1)); +} + +void SDL_SYS_TimerQuit(void) +{ + timer_alive = 0; + if ( timer ) { + SDL_WaitThread(timer, NULL); + timer = NULL; + } +} + +int SDL_SYS_StartTimer(void) +{ + SDL_SetError("Internal logic error: threaded timer in use"); + return(-1); +} + +void SDL_SYS_StopTimer(void) +{ + return; +} + +#endif /* SDL_TIMER_PSP2 */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 436450e330..bf7a565b09 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -350,6 +350,9 @@ extern VideoBootStrap PS2GS_bootstrap; #if SDL_VIDEO_DRIVER_PS3 extern VideoBootStrap PS3_bootstrap; #endif +#if SDL_VIDEO_DRIVER_PSP2 +extern VideoBootStrap PSP2_bootstrap; +#endif #if SDL_VIDEO_DRIVER_GGI extern VideoBootStrap GGI_bootstrap; #endif diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 46285c990e..d3e4af922c 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -126,6 +126,9 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_CACA &CACA_bootstrap, #endif +#if SDL_VIDEO_DRIVER_PSP2 + &PSP2_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif diff --git a/src/video/psp2/SDL_psp2events.c b/src/video/psp2/SDL_psp2events.c new file mode 100644 index 0000000000..3cf15330a4 --- /dev/null +++ b/src/video/psp2/SDL_psp2events.c @@ -0,0 +1,45 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Being a null driver, there's no event stream. We just define stubs for + most of the API. */ + +#include "SDL.h" +#include "../../events/SDL_sysevents.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_psp2video.h" +#include "SDL_psp2events_c.h" + +void PSP2_PumpEvents(_THIS) +{ + /* do nothing. */ +} + +void PSP2_InitOSKeymap(_THIS) +{ + /* do nothing. */ +} + +/* end of SDL_psp2events.c ... */ + diff --git a/src/video/psp2/SDL_psp2events_c.h b/src/video/psp2/SDL_psp2events_c.h new file mode 100644 index 0000000000..eff717c6d1 --- /dev/null +++ b/src/video/psp2/SDL_psp2events_c.h @@ -0,0 +1,33 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_psp2video.h" + +/* Variables and functions exported by SDL_sysevents.c to other parts + of the native video subsystem (SDL_sysvideo.c) +*/ +extern void PSP2_InitOSKeymap(_THIS); +extern void PSP2_PumpEvents(_THIS); + +/* end of SDL_psp2events_c.h ... */ + diff --git a/src/video/psp2/SDL_psp2mouse.c b/src/video/psp2/SDL_psp2mouse.c new file mode 100644 index 0000000000..0cfec50cfe --- /dev/null +++ b/src/video/psp2/SDL_psp2mouse.c @@ -0,0 +1,33 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_mouse.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_psp2mouse_c.h" + + +/* The implementation dependent data for the window manager cursor */ +struct WMcursor { + int unused; +}; diff --git a/src/video/psp2/SDL_psp2mouse_c.h b/src/video/psp2/SDL_psp2mouse_c.h new file mode 100644 index 0000000000..061acb8ccb --- /dev/null +++ b/src/video/psp2/SDL_psp2mouse_c.h @@ -0,0 +1,26 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_psp2video.h" + +/* Functions to be exported */ diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c new file mode 100644 index 0000000000..943fc45aca --- /dev/null +++ b/src/video/psp2/SDL_psp2video.c @@ -0,0 +1,315 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* PSP2 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_psp2video.h" +#include "SDL_psp2events_c.h" +#include "SDL_psp2mouse_c.h" + +#define PSP2VID_DRIVER_NAME "psp2" + +#define SCREEN_W 960 +#define SCREEN_H 544 + +typedef struct private_hwdata { + vita2d_texture *texture; +} private_hwdata; + +/* Initialization/Query functions */ +static int PSP2_VideoInit(_THIS, SDL_PixelFormat *vformat); +static SDL_Rect **PSP2_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); +static SDL_Surface *PSP2_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); +static int PSP2_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); +static void PSP2_VideoQuit(_THIS); + +/* Hardware surface functions */ +static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface); +static int PSP2_AllocHWSurface(_THIS, SDL_Surface *surface); +static int PSP2_LockHWSurface(_THIS, SDL_Surface *surface); +static void PSP2_UnlockHWSurface(_THIS, SDL_Surface *surface); +static void PSP2_FreeHWSurface(_THIS, SDL_Surface *surface); + +/* etc. */ +static void PSP2_UpdateRects(_THIS, int numrects, SDL_Rect *rects); + +/* PSP2 driver bootstrap functions */ +static int PSP2_Available(void) +{ + return 1; +} + +static void PSP2_DeleteDevice(SDL_VideoDevice *device) +{ + SDL_free(device->hidden); + SDL_free(device); +} + +static SDL_VideoDevice *PSP2_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); + if ( device ) { + SDL_memset(device, 0, (sizeof *device)); + device->hidden = (struct SDL_PrivateVideoData *) + SDL_malloc((sizeof *device->hidden)); + } + if ( (device == NULL) || (device->hidden == NULL) ) { + SDL_OutOfMemory(); + if ( device ) { + SDL_free(device); + } + return(0); + } + SDL_memset(device->hidden, 0, (sizeof *device->hidden)); + + /* Set the function pointers */ + device->VideoInit = PSP2_VideoInit; + device->ListModes = PSP2_ListModes; + device->SetVideoMode = PSP2_SetVideoMode; + device->CreateYUVOverlay = NULL; + device->SetColors = PSP2_SetColors; + device->UpdateRects = PSP2_UpdateRects; + device->VideoQuit = PSP2_VideoQuit; + device->AllocHWSurface = PSP2_AllocHWSurface; + device->CheckHWBlit = NULL; + device->FillHWRect = NULL; + device->SetHWColorKey = NULL; + device->SetHWAlpha = NULL; + device->LockHWSurface = PSP2_LockHWSurface; + device->UnlockHWSurface = PSP2_UnlockHWSurface; + device->FlipHWSurface = PSP2_FlipHWSurface; + device->FreeHWSurface = PSP2_FreeHWSurface; + device->SetCaption = NULL; + device->SetIcon = NULL; + device->IconifyWindow = NULL; + device->GrabInput = NULL; + device->GetWMInfo = NULL; + device->InitOSKeymap = PSP2_InitOSKeymap; + device->PumpEvents = PSP2_PumpEvents; + + device->free = PSP2_DeleteDevice; + + return device; +} + +int PSP2_VideoInit(_THIS, SDL_PixelFormat *vformat) +{ + vita2d_init(); + vita2d_set_vblank_wait(1); + + vformat->BitsPerPixel = 16; + vformat->BytesPerPixel = 2; + vformat->Rmask = 0xF800; + vformat->Gmask = 0x07E0; + vformat->Bmask = 0x001F; + vformat->Amask = 0x0000; + + return(0); +} + +SDL_Surface *PSP2_SetVideoMode(_THIS, SDL_Surface *current, + int width, int height, int bpp, Uint32 flags) +{ + // support only 16/24 bits for now + switch(bpp) + { + case 16: + break; + + case 24: + if (!SDL_ReallocFormat(current, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000)) + { + SDL_SetError("Couldn't allocate new pixel format for requested mode"); + return(NULL); + } + break; + + /* // TODO: crash + case 32: + if (!SDL_ReallocFormat(current, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000)) + { + SDL_SetError("Couldn't allocate new pixel format for requested mode"); + return(NULL); + } + break; + */ + + default: + if (!SDL_ReallocFormat(current, 16, 0xF800, 0x07E0, 0x001F, 0x0000)) + { + SDL_SetError("Couldn't allocate new pixel format for requested mode"); + return(NULL); + } + break; + } + + current->flags = flags | SDL_FULLSCREEN | SDL_DOUBLEBUF; + current->w = width; + current->h = height; + if(current->hwdata == NULL) + { + PSP2_AllocHWSurface(this, current); + } + + return(current); +} + +SDL_Rect **PSP2_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) +{ + static SDL_Rect PSP2_Rects[] = { + {0, 0, 960, 544}, + }; + static SDL_Rect *PSP2_modes[] = { + &PSP2_Rects[0], + NULL + }; + SDL_Rect **modes = PSP2_modes; + + // support only 16/24 bits for now + switch(format->BitsPerPixel) + { + case 16: + case 24: + //case 32: // TODO + return modes; + + default: + return (SDL_Rect **) -1; + } +} + +static int PSP2_AllocHWSurface(_THIS, SDL_Surface *surface) +{ + surface->hwdata = (private_hwdata*) SDL_malloc (sizeof (private_hwdata)); + if (surface->hwdata == NULL) + { + SDL_OutOfMemory(); + return -1; + } + SDL_memset (surface->hwdata, 0, sizeof(private_hwdata)); + + switch(surface->format->BitsPerPixel) + { + case 16: + surface->hwdata->texture = + vita2d_create_empty_texture_format(surface->w, surface->h, SCE_GXM_TEXTURE_FORMAT_R5G6B5); + break; + + case 24: + surface->hwdata->texture = + vita2d_create_empty_texture_format(surface->w, surface->h, SCE_GXM_TEXTURE_FORMAT_U8U8U8_RGB); + break; + + /* // TODO: crash + case 32: + surface->hwdata->texture = + vita2d_create_empty_texture_format(surface->w, surface->h, SCE_GXM_COLOR_FORMAT_A8B8G8R8); + break; + */ + + default: + SDL_SetError("unsupported BitsPerPixel: %i\n", surface->format->BitsPerPixel); + return -1; + } + + surface->pixels = vita2d_texture_get_datap(surface->hwdata->texture); + surface->pitch = vita2d_texture_get_stride(surface->hwdata->texture); + surface->flags |= SDL_HWSURFACE; + + return(0); +} + +static void PSP2_FreeHWSurface(_THIS, SDL_Surface *surface) +{ + vita2d_wait_rendering_done(); + vita2d_free_texture(surface->hwdata->texture); + SDL_free(surface->hwdata); + surface->pixels = NULL; +} + +static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) +{ + vita2d_start_drawing(); + vita2d_draw_texture(surface->hwdata->texture, 0, 0); + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_swap_buffers(); +} + +static int PSP2_LockHWSurface(_THIS, SDL_Surface *surface) +{ + return(0); +} + +static void PSP2_UnlockHWSurface(_THIS, SDL_Surface *surface) +{ + return; +} + +static void PSP2_UpdateRects(_THIS, int numrects, SDL_Rect *rects) +{ + +} + +int PSP2_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +{ + return(1); +} + +void PSP2_VideoQuit(_THIS) +{ + if (this->screen->hwdata != NULL && this->screen->pixels != NULL) + { + PSP2_FreeHWSurface(this, this->screen); + } + vita2d_fini(); +} + +VideoBootStrap PSP2_bootstrap = { + PSP2VID_DRIVER_NAME, "SDL psp2 video driver", + PSP2_Available, PSP2_CreateDevice +}; + + diff --git a/src/video/psp2/SDL_psp2video.h b/src/video/psp2/SDL_psp2video.h new file mode 100644 index 0000000000..d2f16f9fbb --- /dev/null +++ b/src/video/psp2/SDL_psp2video.h @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_psp2video_h +#define _SDL_psp2video_h + +#include "../SDL_sysvideo.h" + +#include + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_VideoDevice *this + + +/* Private display data */ + +struct SDL_PrivateVideoData { + vita2d_texture *texture; +}; + +#endif /* _SDL_psp2video_h */ From 33d5e7fa9a024c4271581c8ab2c8b84ef2fdd91c Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 12 Oct 2016 16:34:30 +0200 Subject: [PATCH 09/32] PSP2: clean tests --- Makefile.psp2 | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.psp2 b/Makefile.psp2 index 2321eec1fe..3f0280aa1c 100644 --- a/Makefile.psp2 +++ b/Makefile.psp2 @@ -44,3 +44,4 @@ $(CONFIG_H): clean: rm -f $(TARGET) $(OBJECTS) + make -f Makefile.psp2-test clean From 189d9352c00e3bb3e765d033bd4e0a76124f9dce Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Fri, 14 Oct 2016 17:18:18 +0200 Subject: [PATCH 10/32] PSP2: add custom hw scaling function --- Makefile.psp2 | 6 ++++++ include/SDL_config_psp2.h | 12 ++++++++++++ src/video/psp2/SDL_psp2video.c | 27 ++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Makefile.psp2 b/Makefile.psp2 index 3f0280aa1c..c6c70cb5a5 100644 --- a/Makefile.psp2 +++ b/Makefile.psp2 @@ -45,3 +45,9 @@ $(CONFIG_H): clean: rm -f $(TARGET) $(OBJECTS) make -f Makefile.psp2-test clean + +install: $(TARGET) + @cp $(TARGET) $(VITASDK)/arm-vita-eabi/lib + @mkdir -p "$(VITASDK)/arm-vita-eabi/include/SDL" + @cp include/*.h "$(VITASDK)/arm-vita-eabi/include/SDL" + @echo "Installed!" diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index 5370cecc91..f6a86cbe88 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -31,6 +31,18 @@ #include #include +#define __PSP2__ 1 + +#ifdef __cplusplus +extern "C" { +#endif +sdffdf +// custom ps vita hardware scaling +void SDL_SetVideoModeVita(int x, int y, float w, float h); +#ifdef __cplusplus +} +#endif + typedef signed char int8_t; typedef unsigned char uint8_t; typedef signed short int16_t; diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 943fc45aca..6d1e837f00 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -53,6 +53,7 @@ typedef struct private_hwdata { vita2d_texture *texture; + SDL_Rect dst; } private_hwdata; /* Initialization/Query functions */ @@ -230,6 +231,12 @@ static int PSP2_AllocHWSurface(_THIS, SDL_Surface *surface) } SDL_memset (surface->hwdata, 0, sizeof(private_hwdata)); + // set initial texture destination + surface->hwdata->dst.x = 0; + surface->hwdata->dst.y = 0; + surface->hwdata->dst.w = surface->w; + surface->hwdata->dst.h = surface->h; + switch(surface->format->BitsPerPixel) { case 16: @@ -272,12 +279,30 @@ static void PSP2_FreeHWSurface(_THIS, SDL_Surface *surface) static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) { vita2d_start_drawing(); - vita2d_draw_texture(surface->hwdata->texture, 0, 0); + + vita2d_draw_texture_scale( + surface->hwdata->texture, + surface->hwdata->dst.x, surface->hwdata->dst.y, + surface->hwdata->dst.w/surface->w, surface->hwdata->dst.h/surface->h); + vita2d_end_drawing(); vita2d_wait_rendering_done(); vita2d_swap_buffers(); } +// custom psp2 function for centering/scaling main screen surface (texture) +void SDL_SetVideoModeVita(int x, int y, float w, float h) +{ + SDL_Surface *surface = SDL_GetVideoSurface(); + if(surface != NULL && surface->hwdata != NULL) + { + surface->hwdata->dst.x = x; + surface->hwdata->dst.y = y; + surface->hwdata->dst.w = w; + surface->hwdata->dst.h = h; + } +} + static int PSP2_LockHWSurface(_THIS, SDL_Surface *surface) { return(0); From 9fdfb07a2332e5c8e9d66f07998b7dadff19e0b5 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Fri, 14 Oct 2016 17:43:12 +0200 Subject: [PATCH 11/32] PSP2: oups! --- include/SDL_config_psp2.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index f6a86cbe88..71b9d2e136 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -36,7 +36,6 @@ #ifdef __cplusplus extern "C" { #endif -sdffdf // custom ps vita hardware scaling void SDL_SetVideoModeVita(int x, int y, float w, float h); #ifdef __cplusplus From 648036f19749a596075a97d4c4bbca70d2dd3a2c Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Sun, 16 Oct 2016 21:02:31 +0200 Subject: [PATCH 12/32] PSP2: fix SDL_VideoQuit PSP2: change SDL_SetVideoModeVita to SDL_SetVideoModeScaling --- include/SDL_config_psp2.h | 2 +- src/video/psp2/SDL_psp2video.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index 71b9d2e136..a5afbff202 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -37,7 +37,7 @@ extern "C" { #endif // custom ps vita hardware scaling -void SDL_SetVideoModeVita(int x, int y, float w, float h); +void SDL_SetVideoModeScaling(int x, int y, float w, float h); #ifdef __cplusplus } #endif diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 6d1e837f00..a292651c69 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -270,10 +270,14 @@ static int PSP2_AllocHWSurface(_THIS, SDL_Surface *surface) static void PSP2_FreeHWSurface(_THIS, SDL_Surface *surface) { - vita2d_wait_rendering_done(); - vita2d_free_texture(surface->hwdata->texture); - SDL_free(surface->hwdata); - surface->pixels = NULL; + if (surface->hwdata != NULL) + { + vita2d_wait_rendering_done(); + vita2d_free_texture(surface->hwdata->texture); + SDL_free(surface->hwdata); + surface->hwdata = NULL; + surface->pixels = NULL; + } } static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) @@ -291,10 +295,10 @@ static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) } // custom psp2 function for centering/scaling main screen surface (texture) -void SDL_SetVideoModeVita(int x, int y, float w, float h) +void SDL_SetVideoModeScaling(int x, int y, float w, float h) { SDL_Surface *surface = SDL_GetVideoSurface(); - if(surface != NULL && surface->hwdata != NULL) + if (surface != NULL && surface->hwdata != NULL) { surface->hwdata->dst.x = x; surface->hwdata->dst.y = y; @@ -325,7 +329,7 @@ int PSP2_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) void PSP2_VideoQuit(_THIS) { - if (this->screen->hwdata != NULL && this->screen->pixels != NULL) + if (this->screen->hwdata != NULL) { PSP2_FreeHWSurface(this, this->screen); } @@ -337,4 +341,3 @@ VideoBootStrap PSP2_bootstrap = { PSP2_Available, PSP2_CreateDevice }; - From e93e0d47c8470613cf35795635ee968a14d439aa Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Sun, 16 Oct 2016 22:47:11 +0200 Subject: [PATCH 13/32] PSP2: fix SDL_SetVideoModeScaling --- src/video/psp2/SDL_psp2video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index a292651c69..04dfd4531f 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -287,7 +287,8 @@ static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) vita2d_draw_texture_scale( surface->hwdata->texture, surface->hwdata->dst.x, surface->hwdata->dst.y, - surface->hwdata->dst.w/surface->w, surface->hwdata->dst.h/surface->h); + (float)surface->hwdata->dst.w/(float)surface->w, + (float)surface->hwdata->dst.h/(float)surface->h); vita2d_end_drawing(); vita2d_wait_rendering_done(); From cefbd25713b2805aa64edf01d6079b6cae541adc Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 19 Oct 2016 15:11:37 +0200 Subject: [PATCH 14/32] PSP2: support for multiple audio freqs --- src/audio/psp2/SDL_psp2audio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/audio/psp2/SDL_psp2audio.c b/src/audio/psp2/SDL_psp2audio.c index 97de091953..a94811cc08 100644 --- a/src/audio/psp2/SDL_psp2audio.c +++ b/src/audio/psp2/SDL_psp2audio.c @@ -152,11 +152,11 @@ static void PSP2AUD_CloseAudio(_THIS) static int PSP2AUD_OpenAudio(_THIS, SDL_AudioSpec *spec) { - int format, mixlen, i; + int format, mixlen, i, port = SCE_AUDIO_OUT_PORT_TYPE_MAIN; /* The sample count must be a multiple of 64. */ this->spec.samples = SCE_AUDIO_SAMPLE_ALIGN(this->spec.samples); - this->spec.freq = 48000; + this->spec.freq = spec->freq; /* Update the fragment size as size in bytes. */ /* SDL_CalculateAudioSpec(this->spec); MOD */ @@ -188,7 +188,12 @@ static int PSP2AUD_OpenAudio(_THIS, SDL_AudioSpec *spec) } else { format = SCE_AUDIO_OUT_MODE_STEREO; } - this->hidden->channel = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, this->spec.samples, this->spec.freq, format); + + if(this->spec.freq < 48000) { + port = SCE_AUDIO_OUT_PORT_TYPE_BGM; + } + + this->hidden->channel = sceAudioOutOpenPort(port, this->spec.samples, this->spec.freq, format); if (this->hidden->channel < 0) { free(this->hidden->rawbuf); this->hidden->rawbuf = NULL; From 96ccfd409e3edd9cd99dd33658329ff15a835d7c Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 14 Nov 2016 15:00:17 +0100 Subject: [PATCH 15/32] PSP2: add custom vsync function --- include/SDL_config_psp2.h | 1 + src/video/psp2/SDL_psp2video.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index a5afbff202..163d8f881b 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -38,6 +38,7 @@ extern "C" { #endif // custom ps vita hardware scaling void SDL_SetVideoModeScaling(int x, int y, float w, float h); +void SDL_SetVideoModeSync(int enable_vsync); #ifdef __cplusplus } #endif diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 04dfd4531f..3652b80abf 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -56,6 +56,8 @@ typedef struct private_hwdata { SDL_Rect dst; } private_hwdata; +static int vsync = 1; + /* Initialization/Query functions */ static int PSP2_VideoInit(_THIS, SDL_PixelFormat *vformat); static SDL_Rect **PSP2_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); @@ -138,7 +140,7 @@ static SDL_VideoDevice *PSP2_CreateDevice(int devindex) int PSP2_VideoInit(_THIS, SDL_PixelFormat *vformat) { vita2d_init(); - vita2d_set_vblank_wait(1); + vita2d_set_vblank_wait(vsync); vformat->BitsPerPixel = 16; vformat->BytesPerPixel = 2; @@ -291,7 +293,10 @@ static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) (float)surface->hwdata->dst.h/(float)surface->h); vita2d_end_drawing(); - vita2d_wait_rendering_done(); + if(vsync == 1) + { + vita2d_wait_rendering_done(); + } vita2d_swap_buffers(); } @@ -308,6 +313,13 @@ void SDL_SetVideoModeScaling(int x, int y, float w, float h) } } +// custom psp2 function for vsync +void SDL_SetVideoModeSync(int enable_vsync) +{ + vsync = enable_vsync; + vita2d_set_vblank_wait(vsync); +} + static int PSP2_LockHWSurface(_THIS, SDL_Surface *surface) { return(0); From 1ad9e590f0a0ffd20a12f631c2e1f1b566139c19 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 16 Nov 2016 10:01:05 +0100 Subject: [PATCH 16/32] PSP2: fix for latest vitasdk --- Makefile.psp2-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.psp2-test b/Makefile.psp2-test index 42f7287677..e9e7c3cf30 100644 --- a/Makefile.psp2-test +++ b/Makefile.psp2-test @@ -4,7 +4,7 @@ OBJS = test/testsprite.o LIBS = ./libSDL.a -lpsp2shell -lvita2d -lSceDisplay_stub -lSceGxm_stub \ -lSceSysmodule_stub -lSceCtrl_stub -lScePgf_stub -lSceNetCtl_stub \ - -lSceNet_stub -lScePower_stub -lSceKernel_stub -lSceCommonDialog_stub \ + -lSceNet_stub -lScePower_stub -lSceCommonDialog_stub \ -lSceAudio_stub -lSceAppMgr_stub -lpng -ljpeg -lz -lm -lc PREFIX = arm-vita-eabi From 9a39d238322e9a7034bf0962cc658057f4592fdb Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Mon, 19 Dec 2016 16:42:24 -0600 Subject: [PATCH 17/32] added Bilinear scaling function for Vita that works well with the sharp-bilinear shader from the shader collection --- include/SDL_config_psp2.h | 1 + src/video/psp2/SDL_psp2video.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index 163d8f881b..846fbdaf76 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -38,6 +38,7 @@ extern "C" { #endif // custom ps vita hardware scaling void SDL_SetVideoModeScaling(int x, int y, float w, float h); +void SDL_SetVideoModeScalingBilinear(int x, int y, float w, float h); void SDL_SetVideoModeSync(int enable_vsync); #ifdef __cplusplus } diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 3652b80abf..834fafbaa3 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -300,10 +300,30 @@ static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) vita2d_swap_buffers(); } +// custom psp2 function for centering/scaling main screen surface (texture) +void SDL_SetVideoModeScalingBilinear(int x, int y, float w, float h) +{ + SDL_Surface *surface = SDL_GetVideoSurface(); + + //reduce pixelation + vita2d_texture_set_filters(surface->hwdata->texture, + SCE_GXM_TEXTURE_FILTER_POINT, + SCE_GXM_TEXTURE_FILTER_LINEAR); + + if (surface != NULL && surface->hwdata != NULL) + { + surface->hwdata->dst.x = x; + surface->hwdata->dst.y = y; + surface->hwdata->dst.w = w; + surface->hwdata->dst.h = h; + } +} + // custom psp2 function for centering/scaling main screen surface (texture) void SDL_SetVideoModeScaling(int x, int y, float w, float h) { SDL_Surface *surface = SDL_GetVideoSurface(); + if (surface != NULL && surface->hwdata != NULL) { surface->hwdata->dst.x = x; From 06e4d1d7b1dd58d30116ec9badc4382481d592a1 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Wed, 21 Dec 2016 01:12:44 -0600 Subject: [PATCH 18/32] psp2: introduced vita specific SDL_SetVideoModeBilinear(int enable_bilinear) function to enable (1) and also disable (0) bilinear texture scaling --- include/SDL_config_psp2.h | 2 +- src/video/psp2/SDL_psp2video.c | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index 846fbdaf76..f9f23c52f6 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -38,7 +38,7 @@ extern "C" { #endif // custom ps vita hardware scaling void SDL_SetVideoModeScaling(int x, int y, float w, float h); -void SDL_SetVideoModeScalingBilinear(int x, int y, float w, float h); +void SDL_SetVideoModeBilinear(int enable_bilinear); void SDL_SetVideoModeSync(int enable_vsync); #ifdef __cplusplus } diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 834fafbaa3..11818569fc 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -301,15 +301,10 @@ static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) } // custom psp2 function for centering/scaling main screen surface (texture) -void SDL_SetVideoModeScalingBilinear(int x, int y, float w, float h) +void SDL_SetVideoModeScaling(int x, int y, float w, float h) { SDL_Surface *surface = SDL_GetVideoSurface(); - //reduce pixelation - vita2d_texture_set_filters(surface->hwdata->texture, - SCE_GXM_TEXTURE_FILTER_POINT, - SCE_GXM_TEXTURE_FILTER_LINEAR); - if (surface != NULL && surface->hwdata != NULL) { surface->hwdata->dst.x = x; @@ -319,19 +314,28 @@ void SDL_SetVideoModeScalingBilinear(int x, int y, float w, float h) } } -// custom psp2 function for centering/scaling main screen surface (texture) -void SDL_SetVideoModeScaling(int x, int y, float w, float h) +// custom psp2 function for setting the texture filter to nearest or bilinear +void SDL_SetVideoModeBilinear(int enable_bilinear) { SDL_Surface *surface = SDL_GetVideoSurface(); - - if (surface != NULL && surface->hwdata != NULL) + + if (enable_bilinear) { - surface->hwdata->dst.x = x; - surface->hwdata->dst.y = y; - surface->hwdata->dst.w = w; - surface->hwdata->dst.h = h; + //reduce pixelation by setting bilinear filtering + //for magnification + //(first one is minimization filter, + //second one is magnification filter) + vita2d_texture_set_filters(surface->hwdata->texture, + SCE_GXM_TEXTURE_FILTER_POINT, + SCE_GXM_TEXTURE_FILTER_LINEAR); } -} + else + { + vita2d_texture_set_filters(surface->hwdata->texture, + SCE_GXM_TEXTURE_FILTER_POINT, + SCE_GXM_TEXTURE_FILTER_POINT); + } +} // custom psp2 function for vsync void SDL_SetVideoModeSync(int enable_vsync) From 7e8181f4e65cdc5cca60dd6e086c180dd7ff43e2 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Sun, 8 Jan 2017 19:51:52 -0600 Subject: [PATCH 19/32] Vita: - Vita TV second controller support --- src/joystick/psp2/SDL_sysjoystick.c | 70 ++++++++++++++++++----------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/src/joystick/psp2/SDL_sysjoystick.c b/src/joystick/psp2/SDL_sysjoystick.c index 88d9711e46..c1cb064e9e 100644 --- a/src/joystick/psp2/SDL_sysjoystick.c +++ b/src/joystick/psp2/SDL_sysjoystick.c @@ -34,7 +34,8 @@ #include /* Current pad state */ -static SceCtrlData pad = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; +static SceCtrlData pad0 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; +static SceCtrlData pad1 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; static const unsigned int button_map[] = { SCE_CTRL_TRIANGLE, SCE_CTRL_CIRCLE, SCE_CTRL_CROSS, SCE_CTRL_SQUARE, SCE_CTRL_LTRIGGER, SCE_CTRL_RTRIGGER, @@ -82,10 +83,9 @@ static int calc_bezier_y(float t) int SDL_SYS_JoystickInit(void) { int i; - /* Setup input */ sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); - + /* Create an accurate map from analog inputs (0 to 255) to SDL joystick positions (-32768 to 32767) */ for (i = 0; i < 128; i++) @@ -95,7 +95,9 @@ int SDL_SYS_JoystickInit(void) analog_map[127-i] = -1 * analog_map[i+128]; } - return 1; + SDL_numjoysticks = 2; //include possibility of paired DS controller + + return 2; } /* Function to get the device-dependent name of a joystick */ @@ -104,6 +106,9 @@ const char *SDL_SYS_JoystickName(int index) if (index == 0) return "psp2 controller"; + if (index == 1) + return "second paired psp2 controller"; + SDL_SetError("No joystick available with that index"); return(NULL); } @@ -133,39 +138,54 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) unsigned int buttons; unsigned int changed; unsigned char lx, ly, rx, ry; - static unsigned int old_buttons = 0; - static unsigned char old_lx = 0, old_ly = 0; - static unsigned char old_rx = 0, old_ry = 0; - - sceCtrlPeekBufferPositive(0, &pad, 1); - - buttons = pad.buttons; - lx = pad.lx; - ly = pad.ly; - rx = pad.rx; - ry = pad.ry; + static unsigned int old_buttons[] = { 0, 0 }; + static unsigned char old_lx[] = { 0, 0 }; + static unsigned char old_ly[] = { 0, 0 }; + static unsigned char old_rx[] = { 0, 0 }; + static unsigned char old_ry[] = { 0, 0 }; + SceCtrlData *pad = NULL; + + int index = joystick->index; + + if (index == 0) + pad = &pad0; + else if (index == 1) + pad = &pad1; + else + return; + + if (index == 0) + sceCtrlPeekBufferPositive(0, pad, 1); // Physical Vita controller or first paired Dualshock on Vita TV + else if (index == 1) + sceCtrlPeekBufferPositive(2, pad, 1); // Second paired Dualshock on Vita TV + + buttons = pad->buttons; + lx = pad->lx; + ly = pad->ly; + rx = pad->rx; + ry = pad->ry; /* Axes */ - if(old_lx != lx) { + if(old_lx[index] != lx) { SDL_PrivateJoystickAxis(joystick, 0, analog_map[lx]); - old_lx = lx; + old_lx[index] = lx; } - if(old_ly != ly) { + if(old_ly[index] != ly) { SDL_PrivateJoystickAxis(joystick, 1, analog_map[ly]); - old_ly = ly; + old_ly[index] = ly; } - if(old_rx != rx) { + if(old_rx[index] != rx) { SDL_PrivateJoystickAxis(joystick, 2, analog_map[rx]); - old_rx = rx; + old_rx[index] = rx; } - if(old_ry != ry) { + if(old_ry[index] != ry) { SDL_PrivateJoystickAxis(joystick, 3, analog_map[ry]); - old_ry = ry; + old_ry[index] = ry; } /* Buttons */ - changed = old_buttons ^ buttons; - old_buttons = buttons; + changed = old_buttons[index] ^ buttons; + old_buttons[index] = buttons; if(changed) { for(i=0; i Date: Wed, 11 Jan 2017 04:43:28 -0600 Subject: [PATCH 20/32] Vita SDL12: - Full support for extra Vita TV controllers --- src/joystick/psp2/SDL_sysjoystick.c | 61 +++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/joystick/psp2/SDL_sysjoystick.c b/src/joystick/psp2/SDL_sysjoystick.c index c1cb064e9e..5bb7de5430 100644 --- a/src/joystick/psp2/SDL_sysjoystick.c +++ b/src/joystick/psp2/SDL_sysjoystick.c @@ -36,6 +36,9 @@ /* Current pad state */ static SceCtrlData pad0 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; static SceCtrlData pad1 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; +static SceCtrlData pad2 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; +static SceCtrlData pad3 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 }; +static int port_map[4]= { 0, 2, 3, 4 }; //index: SDL joy number, entry: Vita port number static const unsigned int button_map[] = { SCE_CTRL_TRIANGLE, SCE_CTRL_CIRCLE, SCE_CTRL_CROSS, SCE_CTRL_SQUARE, SCE_CTRL_LTRIGGER, SCE_CTRL_RTRIGGER, @@ -82,8 +85,9 @@ static int calc_bezier_y(float t) */ int SDL_SYS_JoystickInit(void) { - int i; - /* Setup input */ + int i; + + /* Setup input */ sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); /* Create an accurate map from analog inputs (0 to 255) @@ -94,10 +98,28 @@ int SDL_SYS_JoystickInit(void) analog_map[i+128] = calc_bezier_y(t); analog_map[127-i] = -1 * analog_map[i+128]; } - - SDL_numjoysticks = 2; //include possibility of paired DS controller - - return 2; + + SceCtrlPortInfo myPortInfo; + + // Assume we have at least one controller, even when nothing is paired + // This way the user can jump in, pair a controller + // and control things immediately even if it is paired + // after the app has already started. + + SDL_numjoysticks = 1; + + //How many additional paired controllers are there? + sceCtrlGetControllerPortInfo(&myPortInfo); + //On Vita TV, port 0 and 1 are the same controller + //and that is the first one, so start at port 2 + for (i=2; i<=4; i++) + { + if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED) + { + SDL_numjoysticks++; + } + } + return SDL_numjoysticks; } /* Function to get the device-dependent name of a joystick */ @@ -107,8 +129,14 @@ const char *SDL_SYS_JoystickName(int index) return "psp2 controller"; if (index == 1) - return "second paired psp2 controller"; + return "psp2 controller"; + + if (index == 2) + return "psp2 controller"; + if (index == 3) + return "psp2 controller"; + SDL_SetError("No joystick available with that index"); return(NULL); } @@ -138,11 +166,11 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) unsigned int buttons; unsigned int changed; unsigned char lx, ly, rx, ry; - static unsigned int old_buttons[] = { 0, 0 }; - static unsigned char old_lx[] = { 0, 0 }; - static unsigned char old_ly[] = { 0, 0 }; - static unsigned char old_rx[] = { 0, 0 }; - static unsigned char old_ry[] = { 0, 0 }; + static unsigned int old_buttons[] = { 0, 0, 0, 0 }; + static unsigned char old_lx[] = { 0, 0, 0, 0 }; + static unsigned char old_ly[] = { 0, 0, 0, 0 }; + static unsigned char old_rx[] = { 0, 0, 0, 0 }; + static unsigned char old_ry[] = { 0, 0, 0, 0 }; SceCtrlData *pad = NULL; int index = joystick->index; @@ -151,13 +179,14 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) pad = &pad0; else if (index == 1) pad = &pad1; + else if (index == 2) + pad = &pad2; + else if (index == 3) + pad = &pad3; else return; - if (index == 0) - sceCtrlPeekBufferPositive(0, pad, 1); // Physical Vita controller or first paired Dualshock on Vita TV - else if (index == 1) - sceCtrlPeekBufferPositive(2, pad, 1); // Second paired Dualshock on Vita TV + sceCtrlPeekBufferPositive(port_map[index], pad, 1); buttons = pad->buttons; lx = pad->lx; From 03481fd2382e11bd0397e23196b8c9cb1460f64d Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Tue, 5 Dec 2017 19:58:06 -0600 Subject: [PATCH 21/32] change from __PSP2__ to __vita__ define, rename Makefile.psp2 --- Makefile.psp2 => Makefile.vita | 8 ++++---- Makefile.psp2-test => Makefile.vita-test | 2 +- include/SDL_config.h | 2 +- include/SDL_config.h.default | 2 +- include/SDL_config_psp2.h | 2 +- include/SDL_stdinc.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename Makefile.psp2 => Makefile.vita (87%) rename Makefile.psp2-test => Makefile.vita-test (92%) diff --git a/Makefile.psp2 b/Makefile.vita similarity index 87% rename from Makefile.psp2 rename to Makefile.vita index c6c70cb5a5..c49eb37b15 100644 --- a/Makefile.psp2 +++ b/Makefile.vita @@ -1,7 +1,7 @@ # Makefile to build the SDL library INCLUDE = -I./include -CFLAGS = -Wl,-q -g -O3 -D__PSP2__ $(INCLUDE) +CFLAGS = -Wl,-q -g -O3 $(INCLUDE) CC = arm-vita-eabi-gcc AR = arm-vita-eabi-ar @@ -32,8 +32,8 @@ SOURCES = \ OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g') all: $(TARGET) - make -f Makefile.psp2-test clean - make -f Makefile.psp2-test + make -f Makefile.vita-test clean + make -f Makefile.vita-test $(TARGET): $(CONFIG_H) $(OBJECTS) $(AR) crv $@ $^ @@ -44,7 +44,7 @@ $(CONFIG_H): clean: rm -f $(TARGET) $(OBJECTS) - make -f Makefile.psp2-test clean + make -f Makefile.vita-test clean install: $(TARGET) @cp $(TARGET) $(VITASDK)/arm-vita-eabi/lib diff --git a/Makefile.psp2-test b/Makefile.vita-test similarity index 92% rename from Makefile.psp2-test rename to Makefile.vita-test index e9e7c3cf30..77f83b2f1f 100644 --- a/Makefile.psp2-test +++ b/Makefile.vita-test @@ -9,7 +9,7 @@ LIBS = ./libSDL.a -lpsp2shell -lvita2d -lSceDisplay_stub -lSceGxm_stub \ PREFIX = arm-vita-eabi CC = $(PREFIX)-gcc -CFLAGS = -Wl,-q -Wall -O3 -D__PSP2__ -Iinclude -I$(VITASDK)/arm-vita-eabi/include +CFLAGS = -Wl,-q -Wall -O3 -Iinclude -I$(VITASDK)/arm-vita-eabi/include ASFLAGS = $(CFLAGS) all: $(TARGET).vpk diff --git a/include/SDL_config.h b/include/SDL_config.h index 5207ae016e..42119deab0 100644 --- a/include/SDL_config.h +++ b/include/SDL_config.h @@ -38,7 +38,7 @@ #include "SDL_config_win32.h" #elif defined(__OS2__) #include "SDL_config_os2.h" -#elif defined(__PSP2__) +#elif defined(__vita__) #include "SDL_config_psp2.h" #else #include "SDL_config_minimal.h" diff --git a/include/SDL_config.h.default b/include/SDL_config.h.default index 5207ae016e..42119deab0 100644 --- a/include/SDL_config.h.default +++ b/include/SDL_config.h.default @@ -38,7 +38,7 @@ #include "SDL_config_win32.h" #elif defined(__OS2__) #include "SDL_config_os2.h" -#elif defined(__PSP2__) +#elif defined(__vita__) #include "SDL_config_psp2.h" #else #include "SDL_config_minimal.h" diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index f9f23c52f6..a545aa55b3 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -31,7 +31,7 @@ #include #include -#define __PSP2__ 1 +#define __vita__ 1 #ifdef __cplusplus extern "C" { diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index a25fdf935a..abe3aa90c0 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -148,7 +148,7 @@ typedef enum { } SDL_DUMMY_ENUM; #ifndef __NDS__ -#ifndef __PSP2__ +#ifndef __vita__ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); #endif #endif From da0aa870f5239fd30feacdfcbfa824918da9d3d8 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Tue, 5 Dec 2017 20:57:46 -0600 Subject: [PATCH 22/32] disable tests in Makefile.vita --- Makefile.vita | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.vita b/Makefile.vita index c49eb37b15..98d04653cb 100644 --- a/Makefile.vita +++ b/Makefile.vita @@ -31,9 +31,9 @@ SOURCES = \ OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g') -all: $(TARGET) - make -f Makefile.vita-test clean - make -f Makefile.vita-test +#all: $(TARGET) +# make -f Makefile.vita-test clean +# make -f Makefile.vita-test $(TARGET): $(CONFIG_H) $(OBJECTS) $(AR) crv $@ $^ @@ -44,7 +44,7 @@ $(CONFIG_H): clean: rm -f $(TARGET) $(OBJECTS) - make -f Makefile.vita-test clean +# make -f Makefile.vita-test clean install: $(TARGET) @cp $(TARGET) $(VITASDK)/arm-vita-eabi/lib From dffdec76d8b3ea53d249e33cdfe6f4cd1b6ccc56 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Wed, 20 Dec 2017 11:54:30 -0600 Subject: [PATCH 23/32] VITA: use linear joystick response, fix joystick name --- src/joystick/psp2/SDL_sysjoystick.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/joystick/psp2/SDL_sysjoystick.c b/src/joystick/psp2/SDL_sysjoystick.c index 5bb7de5430..f0de36246e 100644 --- a/src/joystick/psp2/SDL_sysjoystick.c +++ b/src/joystick/psp2/SDL_sysjoystick.c @@ -53,9 +53,10 @@ typedef struct } point; /* 4 points define the bezier-curve. */ +/* The Vita has a good amount of analog travel, so use a linear curve */ static point a = { 0, 0 }; -static point b = { 50, 0 }; -static point c = { 78, 32767 }; +static point b = { 0, 0 }; +static point c = { 128, 32767 }; static point d = { 128, 32767 }; /* simple linear interpolation between two points */ @@ -126,16 +127,16 @@ int SDL_SYS_JoystickInit(void) const char *SDL_SYS_JoystickName(int index) { if (index == 0) - return "psp2 controller"; + return "PSVita Controller"; if (index == 1) - return "psp2 controller"; + return "PSVita Controller"; if (index == 2) - return "psp2 controller"; + return "PSVita Controller"; if (index == 3) - return "psp2 controller"; + return "PSVIta Controller"; SDL_SetError("No joystick available with that index"); return(NULL); From 889767ab2d1b49f6bc0ca0577f0078cc705054b2 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Sat, 23 Dec 2017 11:16:25 -0600 Subject: [PATCH 24/32] Vita: Add BT keyboard and mouse support --- src/video/psp2/SDL_psp2events.c | 5 +- src/video/psp2/SDL_psp2keyboard.c | 257 ++++++++++++++++++++++++++++ src/video/psp2/SDL_psp2keyboard_c.h | 32 ++++ src/video/psp2/SDL_psp2mouse.c | 58 ++++++- src/video/psp2/SDL_psp2mouse_c.h | 7 + src/video/psp2/SDL_psp2video.c | 4 + 6 files changed, 358 insertions(+), 5 deletions(-) create mode 100644 src/video/psp2/SDL_psp2keyboard.c create mode 100644 src/video/psp2/SDL_psp2keyboard_c.h diff --git a/src/video/psp2/SDL_psp2events.c b/src/video/psp2/SDL_psp2events.c index 3cf15330a4..dd5dbafbc1 100644 --- a/src/video/psp2/SDL_psp2events.c +++ b/src/video/psp2/SDL_psp2events.c @@ -30,10 +30,13 @@ #include "SDL_psp2video.h" #include "SDL_psp2events_c.h" +#include "SDL_psp2keyboard_c.h" +#include "SDL_psp2mouse_c.h" void PSP2_PumpEvents(_THIS) { - /* do nothing. */ + PSP2_PollKeyboard(); + PSP2_PollMouse(); } void PSP2_InitOSKeymap(_THIS) diff --git a/src/video/psp2/SDL_psp2keyboard.c b/src/video/psp2/SDL_psp2keyboard.c new file mode 100644 index 0000000000..1a86e20999 --- /dev/null +++ b/src/video/psp2/SDL_psp2keyboard.c @@ -0,0 +1,257 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include +#include +#include + +#include "SDL_keyboard.h" +#include "../../events/SDL_events_c.h" +#include "../../events/SDL_sysevents.h" + +#include "SDL_psp2video.h" +#include "SDL_psp2keyboard_c.h" + +SceHidKeyboardReport k_reports[SCE_HID_MAX_REPORT]; +int keyboard_hid_handle = 0; +Uint8 prev_keys[6] = {0}; +Uint8 prev_modifiers = 0; +Uint8 locks = 0; + +const int numkeys = 0xE8; +const int keymap[0xE8] = { + 255, 255, 255, 255, SDLK_a, SDLK_b, SDLK_c, SDLK_d, + SDLK_e, SDLK_f, SDLK_g, SDLK_h, SDLK_i, SDLK_j, SDLK_k, SDLK_l, + SDLK_m, SDLK_n, SDLK_o, SDLK_p, SDLK_q, SDLK_r, SDLK_s, SDLK_t, + SDLK_u, SDLK_v, SDLK_w, SDLK_x, SDLK_y, SDLK_z, SDLK_1, SDLK_2, + SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, + SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, SDLK_MINUS, SDLK_EQUALS, SDLK_LEFTBRACKET, + SDLK_RIGHTBRACKET, SDLK_BACKSLASH, 255, SDLK_SEMICOLON, SDLK_BACKQUOTE, SDLK_QUOTE, SDLK_COMMA, SDLK_PERIOD, + SDLK_SLASH, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, + SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, SDLK_PRINT, SDLK_SCROLLOCK, + SDLK_BREAK, SDLK_INSERT, SDLK_HOME, SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, + SDLK_LEFT, SDLK_DOWN, SDLK_UP, SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, SDLK_KP_PLUS, + SDLK_KP_ENTER, SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6, SDLK_KP7, + SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + SDLK_LCTRL, SDLK_LSHIFT, SDLK_LALT, SDLK_LSUPER, SDLK_RCTRL, SDLK_RSHIFT, SDLK_RALT, SDLK_RSUPER +}; + +const int SCANCODE_NUMLOCKCLEAR = 0x53; +const int SCANCODE_CAPSLOCK = 0x39; +const int SCANCODE_SCROLLLOCK = 0x47; +const int SCANCODE_LCTRL = 0xE0; +const int SCANCODE_LSHIFT = 0xE1; +const int SCANCODE_LALT = 0xE2; +const int SCANCODE_LGUI = 0xE3; +const int SCANCODE_RCTRL = 0xE4; +const int SCANCODE_RSHIFT = 0xE5; +const int SCANCODE_RALT = 0xE6; +const int SCANCODE_RGUI = 0xE7; + +SDL_keysym *PSP2_TranslateKey(int scancode, SDL_keysym *keysym, SDL_bool pressed) +{ + int asciicode = 0; + + int translated_keysym = SDLK_UNKNOWN; + + if (scancode < numkeys) + if (keymap[scancode] != 255) + translated_keysym = keymap[scancode]; + + /* Set the keysym information */ + keysym->scancode = scancode; + keysym->mod = KMOD_NONE; + keysym->sym = translated_keysym; + keysym->unicode = 0; + + /* + if (keysym->sym == SDLK_UNKNOWN) { + keysym->sym = asciicode = keytab_normal[scancode]; + } + + if (SDL_TranslateUNICODE && pressed) { + keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; + } + */ + return(keysym); +} + +void +PSP2_InitKeyboard(void) +{ + sceHidKeyboardEnumerate(&keyboard_hid_handle, 1); +} + +void +PSP2_PollKeyboard(void) +{ + SDL_keysym keysym; + if (keyboard_hid_handle > 0) + { + int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport**)&k_reports, SCE_HID_MAX_REPORT); + + if (numReports < 0) { + keyboard_hid_handle = 0; + } + else if (numReports) { + + if (k_reports[numReports-1].modifiers[1] & 0x1) { + if (!(locks & 0x1)) { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_NUMLOCKCLEAR, &keysym, 1)); + locks |= 0x1; + } + } + else { + if (locks & 0x1) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_NUMLOCKCLEAR, &keysym, 0)); + locks &= ~0x1; + } + } + + if (k_reports[numReports-1].modifiers[1] & 0x2) { + if (!(locks & 0x2)) { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_CAPSLOCK, &keysym, 1)); + locks |= 0x2; + } + } + else { + if (locks & 0x2) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_CAPSLOCK, &keysym, 0)); + locks &= 0x2; + } + } + + if (k_reports[numReports-1].modifiers[1] & 0x4) { + if (!(locks & 0x4)) { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_SCROLLLOCK, &keysym, 1)); + locks |= 0x4; + } + } + else { + if (locks & 0x4) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_SCROLLLOCK, &keysym, 0)); + locks &= ~0x4; + } + } + + Uint8 changed_modifiers = k_reports[numReports-1].modifiers[0] ^ prev_modifiers; + + if (changed_modifiers & 0x01) { + if (prev_modifiers & 0x01) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_LCTRL, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_LCTRL, &keysym, 1)); + } + } + if (changed_modifiers & 0x02) { + if (prev_modifiers & 0x02) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_LSHIFT, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_LSHIFT, &keysym, 1)); + } + } + if (changed_modifiers & 0x04) { + if (prev_modifiers & 0x04) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_LALT, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_LALT, &keysym, 1)); + } + } + if (changed_modifiers & 0x08) { + if (prev_modifiers & 0x08) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_LGUI, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_LGUI, &keysym, 1)); + } + } + if (changed_modifiers & 0x10) { + if (prev_modifiers & 0x10) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_RCTRL, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_RCTRL, &keysym, 1)); + } + } + if (changed_modifiers & 0x20) { + if (prev_modifiers & 0x20) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_RSHIFT, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_RSHIFT, &keysym, 1)); + } + } + if (changed_modifiers & 0x40) { + if (prev_modifiers & 0x40) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_RALT, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_RALT, &keysym, 1)); + } + } + if (changed_modifiers & 0x80) { + if (prev_modifiers & 0x80) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_RGUI, &keysym, 0)); + } + else { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_RGUI, &keysym, 1)); + } + } + + prev_modifiers = k_reports[numReports-1].modifiers[0]; + + for (int i = 0; i < 6; i++) { + + int keyCode = k_reports[numReports-1].keycodes[i]; + + if (keyCode != prev_keys[i]) { + + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(keyCode, &keysym, 0)); + + if (keyCode) { + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(keyCode, &keysym, 1)); + } + prev_keys[i] = keyCode; + } + } + } + } +} diff --git a/src/video/psp2/SDL_psp2keyboard_c.h b/src/video/psp2/SDL_psp2keyboard_c.h new file mode 100644 index 0000000000..6bcae7d072 --- /dev/null +++ b/src/video/psp2/SDL_psp2keyboard_c.h @@ -0,0 +1,32 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_PSP2KEYBOARD_H_ +#define _SDL_PSP2KEYBOARD_H_ + +/* Functions to be exported */ +extern void PSP2_InitKeyboard(); +extern void PSP2_PollKeyboard(); +extern SDL_keysym *PSP2_TranslateKey(int scancode, SDL_keysym *keysym, SDL_bool pressed); + +#endif /* _SDL_PSP2KEYBOARD_H_ */ diff --git a/src/video/psp2/SDL_psp2mouse.c b/src/video/psp2/SDL_psp2mouse.c index 0cfec50cfe..ba49785cf4 100644 --- a/src/video/psp2/SDL_psp2mouse.c +++ b/src/video/psp2/SDL_psp2mouse.c @@ -21,13 +21,63 @@ */ #include "SDL_config.h" +#include +#include +#include + #include "SDL_mouse.h" #include "../../events/SDL_events_c.h" +#include "../../events/SDL_sysevents.h" +#include "SDL_psp2video.h" #include "SDL_psp2mouse_c.h" +SceHidMouseReport m_reports[SCE_HID_MAX_REPORT]; +int mouse_hid_handle = 0; +Uint8 prev_buttons = 0; + +void +PSP2_InitMouse(void) +{ + sceHidMouseEnumerate(&mouse_hid_handle, 1); +} + +void +PSP2_PollMouse(void) +{ + if (mouse_hid_handle > 0) + { + int ret = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport**)&m_reports, 1); + if (ret > 0) + { + Uint8 changed_buttons = m_reports[0].buttons ^ prev_buttons; + + if (changed_buttons & 0x1) { + if (prev_buttons & 0x1) + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); + else + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); + } + if (changed_buttons & 0x2) { + if (prev_buttons & 0x2) + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); + else + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); + } + if (changed_buttons & 0x4) { + if (prev_buttons & 0x4) + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); + else + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); + } + + prev_buttons = m_reports[0].buttons; + + if (m_reports[0].rel_x || m_reports[0].rel_y) + { + SDL_PrivateMouseMotion(0, 1, m_reports[0].rel_x, m_reports[0].rel_y); + } + } + } +} -/* The implementation dependent data for the window manager cursor */ -struct WMcursor { - int unused; -}; diff --git a/src/video/psp2/SDL_psp2mouse_c.h b/src/video/psp2/SDL_psp2mouse_c.h index 061acb8ccb..1932335309 100644 --- a/src/video/psp2/SDL_psp2mouse_c.h +++ b/src/video/psp2/SDL_psp2mouse_c.h @@ -21,6 +21,13 @@ */ #include "SDL_config.h" +#ifndef _SDL_PSP2MOUSE_H_ +#define _SDL_PSP2MOUSE_H_ + #include "SDL_psp2video.h" /* Functions to be exported */ +extern void PSP2_InitMouse(); +extern void PSP2_PollMouse(); + +#endif /* _SDL_PSP2MOUSE_H_ */ \ No newline at end of file diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 11818569fc..062f037d09 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -45,6 +45,7 @@ #include "SDL_psp2video.h" #include "SDL_psp2events_c.h" #include "SDL_psp2mouse_c.h" +#include "SDL_psp2keyboard_c.h" #define PSP2VID_DRIVER_NAME "psp2" @@ -149,6 +150,9 @@ int PSP2_VideoInit(_THIS, SDL_PixelFormat *vformat) vformat->Bmask = 0x001F; vformat->Amask = 0x0000; + PSP2_InitKeyboard(); + PSP2_InitMouse(); + return(0); } From 39d568701093279eda6c1a1d884f036aa7253a87 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Sat, 23 Dec 2017 19:55:19 -0600 Subject: [PATCH 25/32] VITA: fix repeated BT keyboard events --- src/video/psp2/SDL_psp2keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/psp2/SDL_psp2keyboard.c b/src/video/psp2/SDL_psp2keyboard.c index 1a86e20999..b581b0e02e 100644 --- a/src/video/psp2/SDL_psp2keyboard.c +++ b/src/video/psp2/SDL_psp2keyboard.c @@ -244,7 +244,7 @@ PSP2_PollKeyboard(void) if (keyCode != prev_keys[i]) { - SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(keyCode, &keysym, 0)); + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(prev_keys[i], &keysym, 0)); if (keyCode) { SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(keyCode, &keysym, 1)); From c40c62b8cfba8f29294ec191788e662feac36755 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Sat, 23 Dec 2017 21:06:22 -0600 Subject: [PATCH 26/32] VITA: Fix Caps Lock and Num Lock BT keys --- src/video/psp2/SDL_psp2keyboard.c | 52 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/video/psp2/SDL_psp2keyboard.c b/src/video/psp2/SDL_psp2keyboard.c index b581b0e02e..6993927417 100644 --- a/src/video/psp2/SDL_psp2keyboard.c +++ b/src/video/psp2/SDL_psp2keyboard.c @@ -40,35 +40,35 @@ Uint8 locks = 0; const int numkeys = 0xE8; const int keymap[0xE8] = { - 255, 255, 255, 255, SDLK_a, SDLK_b, SDLK_c, SDLK_d, + 0, 0, 0, 0, SDLK_a, SDLK_b, SDLK_c, SDLK_d, SDLK_e, SDLK_f, SDLK_g, SDLK_h, SDLK_i, SDLK_j, SDLK_k, SDLK_l, SDLK_m, SDLK_n, SDLK_o, SDLK_p, SDLK_q, SDLK_r, SDLK_s, SDLK_t, SDLK_u, SDLK_v, SDLK_w, SDLK_x, SDLK_y, SDLK_z, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, SDLK_MINUS, SDLK_EQUALS, SDLK_LEFTBRACKET, - SDLK_RIGHTBRACKET, SDLK_BACKSLASH, 255, SDLK_SEMICOLON, SDLK_BACKQUOTE, SDLK_QUOTE, SDLK_COMMA, SDLK_PERIOD, + SDLK_RIGHTBRACKET, SDLK_BACKSLASH, SDLK_HASH, SDLK_SEMICOLON, SDLK_BACKQUOTE, SDLK_QUOTE, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, SDLK_PRINT, SDLK_SCROLLOCK, SDLK_BREAK, SDLK_INSERT, SDLK_HOME, SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, SDLK_LEFT, SDLK_DOWN, SDLK_UP, SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, SDLK_KP_PLUS, SDLK_KP_ENTER, SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6, SDLK_KP7, - SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - SDLK_LCTRL, SDLK_LSHIFT, SDLK_LALT, SDLK_LSUPER, SDLK_RCTRL, SDLK_RSHIFT, SDLK_RALT, SDLK_RSUPER + SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, SDLK_KP_EQUALS, SDLK_F13, SDLK_F14, SDLK_F15, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + SDLK_LCTRL, SDLK_LSHIFT, SDLK_LALT, SDLK_LMETA, SDLK_RCTRL, SDLK_RSHIFT, SDLK_RALT, SDLK_RMETA }; const int SCANCODE_NUMLOCKCLEAR = 0x53; @@ -123,6 +123,8 @@ PSP2_PollKeyboard(void) SDL_keysym keysym; if (keyboard_hid_handle > 0) { + // Capslock and Numlock keys only change state on SDL_PRESSED + int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport**)&k_reports, SCE_HID_MAX_REPORT); if (numReports < 0) { @@ -138,7 +140,7 @@ PSP2_PollKeyboard(void) } else { if (locks & 0x1) { - SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_NUMLOCKCLEAR, &keysym, 0)); + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_NUMLOCKCLEAR, &keysym, 0)); locks &= ~0x1; } } @@ -151,8 +153,8 @@ PSP2_PollKeyboard(void) } else { if (locks & 0x2) { - SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(SCANCODE_CAPSLOCK, &keysym, 0)); - locks &= 0x2; + SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_CAPSLOCK, &keysym, 0)); + locks &= ~0x2; } } @@ -243,9 +245,9 @@ PSP2_PollKeyboard(void) int keyCode = k_reports[numReports-1].keycodes[i]; if (keyCode != prev_keys[i]) { - - SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(prev_keys[i], &keysym, 0)); - + if (prev_keys[i]) { + SDL_PrivateKeyboard(SDL_RELEASED, PSP2_TranslateKey(prev_keys[i], &keysym, 0)); + } if (keyCode) { SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(keyCode, &keysym, 1)); } From e7fd897f99246fa2c4f48a382d4a300cadf588d7 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Wed, 10 Jan 2018 18:44:14 -0600 Subject: [PATCH 27/32] VITA: BT keyboard code cleanup --- src/video/psp2/SDL_psp2keyboard.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/video/psp2/SDL_psp2keyboard.c b/src/video/psp2/SDL_psp2keyboard.c index 6993927417..326fcd5b55 100644 --- a/src/video/psp2/SDL_psp2keyboard.c +++ b/src/video/psp2/SDL_psp2keyboard.c @@ -38,7 +38,7 @@ Uint8 prev_keys[6] = {0}; Uint8 prev_modifiers = 0; Uint8 locks = 0; -const int numkeys = 0xE8; +const Uint8 numkeys = 0xE8; const int keymap[0xE8] = { 0, 0, 0, 0, SDLK_a, SDLK_b, SDLK_c, SDLK_d, SDLK_e, SDLK_f, SDLK_g, SDLK_h, SDLK_i, SDLK_j, SDLK_k, SDLK_l, @@ -90,8 +90,7 @@ SDL_keysym *PSP2_TranslateKey(int scancode, SDL_keysym *keysym, SDL_bool pressed int translated_keysym = SDLK_UNKNOWN; if (scancode < numkeys) - if (keymap[scancode] != 255) - translated_keysym = keymap[scancode]; + translated_keysym = keymap[scancode]; /* Set the keysym information */ keysym->scancode = scancode; From 744dd94113379b0b6cb04c0f1416c3d72076813e Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Wed, 17 Jan 2018 16:45:32 -0600 Subject: [PATCH 28/32] VITA: Use the full range of analog stick motion --- src/joystick/psp2/SDL_sysjoystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/psp2/SDL_sysjoystick.c b/src/joystick/psp2/SDL_sysjoystick.c index f0de36246e..9d05f0cfc6 100644 --- a/src/joystick/psp2/SDL_sysjoystick.c +++ b/src/joystick/psp2/SDL_sysjoystick.c @@ -89,7 +89,7 @@ int SDL_SYS_JoystickInit(void) int i; /* Setup input */ - sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); + sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE); /* Create an accurate map from analog inputs (0 to 255) to SDL joystick positions (-32768 to 32767) */ From fd2e756b1af7264f4690a2d9a6dabaa6247794cb Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Wed, 21 Mar 2018 14:28:27 -0500 Subject: [PATCH 29/32] VITA: Support unicode keyboard events --- src/video/psp2/SDL_psp2keyboard.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/video/psp2/SDL_psp2keyboard.c b/src/video/psp2/SDL_psp2keyboard.c index 326fcd5b55..f18a2817b0 100644 --- a/src/video/psp2/SDL_psp2keyboard.c +++ b/src/video/psp2/SDL_psp2keyboard.c @@ -98,15 +98,10 @@ SDL_keysym *PSP2_TranslateKey(int scancode, SDL_keysym *keysym, SDL_bool pressed keysym->sym = translated_keysym; keysym->unicode = 0; - /* - if (keysym->sym == SDLK_UNKNOWN) { - keysym->sym = asciicode = keytab_normal[scancode]; + if (SDL_TranslateUNICODE && pressed && translated_keysym <= 127) { + keysym->unicode = translated_keysym; } - if (SDL_TranslateUNICODE && pressed) { - keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; - } - */ return(keysym); } From 8824a25157285602241c04f8c404369256560a64 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Tue, 3 Apr 2018 23:53:01 -0500 Subject: [PATCH 30/32] VITA: remove bluetooth keyboard and mouse lag --- src/video/psp2/SDL_psp2keyboard.c | 12 +++---- src/video/psp2/SDL_psp2mouse.c | 55 ++++++++++++++++--------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/video/psp2/SDL_psp2keyboard.c b/src/video/psp2/SDL_psp2keyboard.c index f18a2817b0..b1decabf5f 100644 --- a/src/video/psp2/SDL_psp2keyboard.c +++ b/src/video/psp2/SDL_psp2keyboard.c @@ -126,7 +126,7 @@ PSP2_PollKeyboard(void) } else if (numReports) { - if (k_reports[numReports-1].modifiers[1] & 0x1) { + if (k_reports[numReports - 1].modifiers[1] & 0x1) { if (!(locks & 0x1)) { SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_NUMLOCKCLEAR, &keysym, 1)); locks |= 0x1; @@ -139,7 +139,7 @@ PSP2_PollKeyboard(void) } } - if (k_reports[numReports-1].modifiers[1] & 0x2) { + if (k_reports[numReports - 1].modifiers[1] & 0x2) { if (!(locks & 0x2)) { SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_CAPSLOCK, &keysym, 1)); locks |= 0x2; @@ -152,7 +152,7 @@ PSP2_PollKeyboard(void) } } - if (k_reports[numReports-1].modifiers[1] & 0x4) { + if (k_reports[numReports - 1].modifiers[1] & 0x4) { if (!(locks & 0x4)) { SDL_PrivateKeyboard(SDL_PRESSED, PSP2_TranslateKey(SCANCODE_SCROLLLOCK, &keysym, 1)); locks |= 0x4; @@ -165,7 +165,7 @@ PSP2_PollKeyboard(void) } } - Uint8 changed_modifiers = k_reports[numReports-1].modifiers[0] ^ prev_modifiers; + Uint8 changed_modifiers = k_reports[numReports - 1].modifiers[0] ^ prev_modifiers; if (changed_modifiers & 0x01) { if (prev_modifiers & 0x01) { @@ -232,11 +232,11 @@ PSP2_PollKeyboard(void) } } - prev_modifiers = k_reports[numReports-1].modifiers[0]; + prev_modifiers = k_reports[numReports - 1].modifiers[0]; for (int i = 0; i < 6; i++) { - int keyCode = k_reports[numReports-1].keycodes[i]; + int keyCode = k_reports[numReports - 1].keycodes[i]; if (keyCode != prev_keys[i]) { if (prev_keys[i]) { diff --git a/src/video/psp2/SDL_psp2mouse.c b/src/video/psp2/SDL_psp2mouse.c index ba49785cf4..4ce668d6b1 100644 --- a/src/video/psp2/SDL_psp2mouse.c +++ b/src/video/psp2/SDL_psp2mouse.c @@ -47,35 +47,38 @@ PSP2_PollMouse(void) { if (mouse_hid_handle > 0) { - int ret = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport**)&m_reports, 1); - if (ret > 0) + int numReports = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport**)&m_reports, SCE_HID_MAX_REPORT); + if (numReports > 0) { - Uint8 changed_buttons = m_reports[0].buttons ^ prev_buttons; - - if (changed_buttons & 0x1) { - if (prev_buttons & 0x1) - SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); - else - SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); - } - if (changed_buttons & 0x2) { - if (prev_buttons & 0x2) - SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); - else - SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); - } - if (changed_buttons & 0x4) { - if (prev_buttons & 0x4) - SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); - else - SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); - } + for (int i = 0; i <= numReports - 1; i++) + { + Uint8 changed_buttons = m_reports[i].buttons ^ prev_buttons; + + if (changed_buttons & 0x1) { + if (prev_buttons & 0x1) + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); + else + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); + } + if (changed_buttons & 0x2) { + if (prev_buttons & 0x2) + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); + else + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); + } + if (changed_buttons & 0x4) { + if (prev_buttons & 0x4) + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); + else + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); + } - prev_buttons = m_reports[0].buttons; + prev_buttons = m_reports[i].buttons; - if (m_reports[0].rel_x || m_reports[0].rel_y) - { - SDL_PrivateMouseMotion(0, 1, m_reports[0].rel_x, m_reports[0].rel_y); + if (m_reports[i].rel_x || m_reports[i].rel_y) + { + SDL_PrivateMouseMotion(0, 1, m_reports[i].rel_x, m_reports[i].rel_y); + } } } } From 94b2699caab34f6a1f32e0e95d00261cf6dab286 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Thu, 17 May 2018 18:24:07 -0500 Subject: [PATCH 31/32] VITA: Fix SDL_SetVideoModeScaling and SDL_SetVideoModeBilinear functions --- src/video/psp2/SDL_psp2video.c | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/video/psp2/SDL_psp2video.c b/src/video/psp2/SDL_psp2video.c index 062f037d09..f3253c868c 100644 --- a/src/video/psp2/SDL_psp2video.c +++ b/src/video/psp2/SDL_psp2video.c @@ -307,7 +307,7 @@ static int PSP2_FlipHWSurface(_THIS, SDL_Surface *surface) // custom psp2 function for centering/scaling main screen surface (texture) void SDL_SetVideoModeScaling(int x, int y, float w, float h) { - SDL_Surface *surface = SDL_GetVideoSurface(); + SDL_Surface *surface = SDL_VideoSurface; if (surface != NULL && surface->hwdata != NULL) { @@ -321,23 +321,26 @@ void SDL_SetVideoModeScaling(int x, int y, float w, float h) // custom psp2 function for setting the texture filter to nearest or bilinear void SDL_SetVideoModeBilinear(int enable_bilinear) { - SDL_Surface *surface = SDL_GetVideoSurface(); + SDL_Surface *surface = SDL_VideoSurface; - if (enable_bilinear) - { - //reduce pixelation by setting bilinear filtering - //for magnification - //(first one is minimization filter, - //second one is magnification filter) - vita2d_texture_set_filters(surface->hwdata->texture, - SCE_GXM_TEXTURE_FILTER_POINT, - SCE_GXM_TEXTURE_FILTER_LINEAR); - } - else + if (surface != NULL && surface->hwdata != NULL) { - vita2d_texture_set_filters(surface->hwdata->texture, - SCE_GXM_TEXTURE_FILTER_POINT, - SCE_GXM_TEXTURE_FILTER_POINT); + if (enable_bilinear) + { + //reduce pixelation by setting bilinear filtering + //for magnification + //(first one is minimization filter, + //second one is magnification filter) + vita2d_texture_set_filters(surface->hwdata->texture, + SCE_GXM_TEXTURE_FILTER_POINT, + SCE_GXM_TEXTURE_FILTER_LINEAR); + } + else + { + vita2d_texture_set_filters(surface->hwdata->texture, + SCE_GXM_TEXTURE_FILTER_POINT, + SCE_GXM_TEXTURE_FILTER_POINT); + } } } From b85a62b904eb785b667132603e6af9d426977c46 Mon Sep 17 00:00:00 2001 From: Sunguk Lee Date: Sun, 20 Jan 2019 11:59:58 +0900 Subject: [PATCH 32/32] VITA: Enable 64bit support (#5) --- include/SDL_config_psp2.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/SDL_config_psp2.h b/include/SDL_config_psp2.h index a545aa55b3..80248d84f0 100644 --- a/include/SDL_config_psp2.h +++ b/include/SDL_config_psp2.h @@ -50,6 +50,8 @@ typedef signed short int16_t; typedef unsigned short uint16_t; typedef unsigned int size_t; +#define SDL_HAS_64BIT_TYPE 1 + #define HAVE_GCC_ATOMICS 1 #define HAVE_ALLOCA_H 1