1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Makefile.psp Sun Mar 17 20:07:02 2013 +0800
1.3 @@ -0,0 +1,92 @@
1.4 +TARGET_LIB = libSDL2.a
1.5 +OBJS= src/SDL.o \
1.6 + src/SDL_assert.o \
1.7 + src/SDL_error.o \
1.8 + src/SDL_fatal.o \
1.9 + src/SDL_hints.o \
1.10 + src/SDL_log.o \
1.11 + src/atomic/SDL_atomic.o \
1.12 + src/atomic/SDL_spinlock.o \
1.13 + src/audio/SDL_audio.o \
1.14 + src/audio/SDL_audiocvt.o \
1.15 + src/audio/SDL_audiodev.o \
1.16 + src/audio/SDL_audiotypecvt.o \
1.17 + src/audio/SDL_mixer.o \
1.18 + src/audio/SDL_wave.o \
1.19 + src/audio/psp/SDL_pspaudio.o \
1.20 + src/cpuinfo/SDL_cpuinfo.o \
1.21 + src/events/SDL_clipboardevents.o \
1.22 + src/events/SDL_dropevents.o \
1.23 + src/events/SDL_events.o \
1.24 + src/events/SDL_gesture.o \
1.25 + src/events/SDL_keyboard.o \
1.26 + src/events/SDL_mouse.o \
1.27 + src/events/SDL_quit.o \
1.28 + src/events/SDL_touch.o \
1.29 + src/events/SDL_windowevents.o \
1.30 + src/file/SDL_rwops.o \
1.31 + src/haptic/SDL_haptic.o \
1.32 + src/haptic/dummy/SDL_syshaptic.o \
1.33 + src/joystick/SDL_joystick.o \
1.34 + src/joystick/SDL_gamecontroller.o \
1.35 + src/joystick/psp/SDL_sysjoystick.o \
1.36 + src/power/SDL_power.o \
1.37 + src/power/psp/SDL_syspower.o \
1.38 + src/render/SDL_render.o \
1.39 + src/render/SDL_yuv_sw.o \
1.40 + src/render/psp/SDL_render_psp.o \
1.41 + src/render/software/SDL_blendfillrect.o \
1.42 + src/render/software/SDL_blendline.o \
1.43 + src/render/software/SDL_blendpoint.o \
1.44 + src/render/software/SDL_drawline.o \
1.45 + src/render/software/SDL_drawpoint.o \
1.46 + src/render/software/SDL_render_sw.o \
1.47 + src/render/software/SDL_rotate.o \
1.48 + src/stdlib/SDL_getenv.o \
1.49 + src/stdlib/SDL_iconv.o \
1.50 + src/stdlib/SDL_malloc.o \
1.51 + src/stdlib/SDL_qsort.o \
1.52 + src/stdlib/SDL_stdlib.o \
1.53 + src/stdlib/SDL_string.o \
1.54 + src/thread/SDL_thread.o \
1.55 + src/thread/psp/SDL_syssem.o \
1.56 + src/thread/psp/SDL_systhread.o \
1.57 + src/thread/psp/SDL_sysmutex.o \
1.58 + src/thread/psp/SDL_syscond.o \
1.59 + src/timer/SDL_timer.o \
1.60 + src/timer/psp/SDL_systimer.o \
1.61 + src/video/SDL_RLEaccel.o \
1.62 + src/video/SDL_blit.o \
1.63 + src/video/SDL_blit_0.o \
1.64 + src/video/SDL_blit_1.o \
1.65 + src/video/SDL_blit_A.o \
1.66 + src/video/SDL_blit_N.o \
1.67 + src/video/SDL_blit_auto.o \
1.68 + src/video/SDL_blit_copy.o \
1.69 + src/video/SDL_blit_slow.o \
1.70 + src/video/SDL_bmp.o \
1.71 + src/video/SDL_clipboard.o \
1.72 + src/video/SDL_fillrect.o \
1.73 + src/video/SDL_pixels.o \
1.74 + src/video/SDL_rect.o \
1.75 + src/video/SDL_stretch.o \
1.76 + src/video/SDL_surface.o \
1.77 + src/video/SDL_video.o \
1.78 + src/video/psp/SDL_pspevents.o \
1.79 + src/video/psp/SDL_pspvideo.o \
1.80 + src/video/psp/SDL_pspgl.o \
1.81 + src/video/psp/SDL_pspmouse.o \
1.82 +
1.83 +INCDIR = ./include
1.84 +CFLAGS = -g -O2 -G0 -Wall -D__PSP__ -DHAVE_OPENGL
1.85 +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
1.86 +ASFLAGS = $(CFLAGS)
1.87 +
1.88 +LIBDIR =
1.89 +LIBS = -lGL -lGLU -lglut -lz \
1.90 + -lpspvfpu -lpsphprm -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgum -lpspgu -lpspaudiolib -lpspaudio -lpsphttp -lpspssl -lpspwlan \
1.91 + -lpspnet_adhocmatching -lpspnet_adhoc -lpspnet_adhocctl -lm -lpspvram
1.92 +
1.93 +PSPSDK=$(shell psp-config --pspsdk-path)
1.94 +include $(PSPSDK)/lib/build.mak
1.95 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/README.psp Sun Mar 17 20:07:02 2013 +0800
2.3 @@ -0,0 +1,17 @@
2.4 +SDL port for the Sony PSP contributed by
2.5 + Captian Lex
2.6 +
2.7 +Credit to
2.8 + Marcus R.Brown,Jim Paris,Matthew H for the original SDL 1.2 for PSP
2.9 + Geecko for his PSP GU lib "Glib2d"
2.10 +
2.11 +Building
2.12 +--------
2.13 +To build for the PSP, make sure psp-config is in the path and run:
2.14 + make -f Makefile.psp
2.15 +
2.16 +
2.17 +
2.18 +To Do
2.19 +------
2.20 +PSP Screen Keyboard
2.21 \ No newline at end of file
3.1 --- a/include/SDL_config.h Sat Mar 16 11:00:04 2013 -0700
3.2 +++ b/include/SDL_config.h Sun Mar 17 20:07:02 2013 +0800
3.3 @@ -39,6 +39,8 @@
3.4 #include "SDL_config_android.h"
3.5 #elif defined(__NINTENDODS__)
3.6 #include "SDL_config_nintendods.h"
3.7 +#elif defined(__PSP__)
3.8 +#include "SDL_config_psp.h"
3.9 #else
3.10 /* This is a minimal configuration just to get SDL running on new platforms */
3.11 #include "SDL_config_minimal.h"
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/include/SDL_config_psp.h Sun Mar 17 20:07:02 2013 +0800
4.3 @@ -0,0 +1,136 @@
4.4 +/*
4.5 + Simple DirectMedia Layer
4.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4.7 +
4.8 + This software is provided 'as-is', without any express or implied
4.9 + warranty. In no event will the authors be held liable for any damages
4.10 + arising from the use of this software.
4.11 +
4.12 + Permission is granted to anyone to use this software for any purpose,
4.13 + including commercial applications, and to alter it and redistribute it
4.14 + freely, subject to the following restrictions:
4.15 +
4.16 + 1. The origin of this software must not be misrepresented; you must not
4.17 + claim that you wrote the original software. If you use this software
4.18 + in a product, an acknowledgment in the product documentation would be
4.19 + appreciated but is not required.
4.20 + 2. Altered source versions must be plainly marked as such, and must not be
4.21 + misrepresented as being the original software.
4.22 + 3. This notice may not be removed or altered from any source distribution.
4.23 +*/
4.24 +
4.25 +#ifndef _SDL_config_psp_h
4.26 +#define _SDL_config_psp_h
4.27 +
4.28 +#include "SDL_platform.h"
4.29 +
4.30 +
4.31 +
4.32 +#ifdef __GNUC__
4.33 +#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1
4.34 +#endif
4.35 +
4.36 +#define HAVE_GCC_ATOMICS 1
4.37 +
4.38 +#define HAVE_ALLOCA_H 1
4.39 +#define HAVE_SYS_TYPES_H 1
4.40 +#define HAVE_STDIO_H 1
4.41 +#define STDC_HEADERS 1
4.42 +#define HAVE_STRING_H 1
4.43 +#define HAVE_INTTYPES_H 1
4.44 +#define HAVE_STDINT_H 1
4.45 +#define HAVE_CTYPE_H 1
4.46 +#define HAVE_MATH_H 1
4.47 +#define HAVE_SIGNAL_H 1
4.48 +
4.49 +/* C library functions */
4.50 +#define HAVE_MALLOC 1
4.51 +#define HAVE_CALLOC 1
4.52 +#define HAVE_REALLOC 1
4.53 +#define HAVE_FREE 1
4.54 +#define HAVE_ALLOCA 1
4.55 +#define HAVE_GETENV 1
4.56 +#define HAVE_SETENV 1
4.57 +#define HAVE_PUTENV 1
4.58 +#define HAVE_SETENV 1
4.59 +#define HAVE_UNSETENV 1
4.60 +#define HAVE_QSORT 1
4.61 +#define HAVE_ABS 1
4.62 +#define HAVE_BCOPY 1
4.63 +#define HAVE_MEMSET 1
4.64 +#define HAVE_MEMCPY 1
4.65 +#define HAVE_MEMMOVE 1
4.66 +#define HAVE_MEMCMP 1
4.67 +#define HAVE_STRLEN 1
4.68 +#define HAVE_STRLCPY 1
4.69 +#define HAVE_STRLCAT 1
4.70 +#define HAVE_STRDUP 1
4.71 +#define HAVE_STRCHR 1
4.72 +#define HAVE_STRRCHR 1
4.73 +#define HAVE_STRSTR 1
4.74 +#define HAVE_STRTOL 1
4.75 +#define HAVE_STRTOUL 1
4.76 +#define HAVE_STRTOLL 1
4.77 +#define HAVE_STRTOULL 1
4.78 +#define HAVE_STRTOD 1
4.79 +#define HAVE_ATOI 1
4.80 +#define HAVE_ATOF 1
4.81 +#define HAVE_STRCMP 1
4.82 +#define HAVE_STRNCMP 1
4.83 +#define HAVE_STRCASECMP 1
4.84 +#define HAVE_STRNCASECMP 1
4.85 +#define HAVE_SSCANF 1
4.86 +#define HAVE_SNPRINTF 1
4.87 +#define HAVE_VSNPRINTF 1
4.88 +#define HAVE_M_PI 1
4.89 +#define HAVE_ATAN 1
4.90 +#define HAVE_ATAN2 1
4.91 +#define HAVE_CEIL 1
4.92 +#define HAVE_COPYSIGN 1
4.93 +#define HAVE_COS 1
4.94 +#define HAVE_COSF 1
4.95 +#define HAVE_FABS 1
4.96 +#define HAVE_FLOOR 1
4.97 +#define HAVE_LOG 1
4.98 +#define HAVE_POW 1
4.99 +#define HAVE_SCALBN 1
4.100 +#define HAVE_SIN 1
4.101 +#define HAVE_SINF 1
4.102 +#define HAVE_SQRT 1
4.103 +#define HAVE_SETJMP 1
4.104 +#define HAVE_NANOSLEEP 1
4.105 +//#define HAVE_SYSCONF 1
4.106 +//#define HAVE_SIGACTION 1
4.107 +
4.108 +
4.109 +/* PSP isn't that sophisticated */
4.110 +#define LACKS_SYS_MMAN_H 1
4.111 +
4.112 +/* Enable the stub thread support (src/thread/psp/\*.c) */
4.113 +#define SDL_THREAD_PSP 1
4.114 +
4.115 +/* Enable the stub timer support (src/timer/psp/\*.c) */
4.116 +#define SDL_TIMERS_PSP 1
4.117 +
4.118 +/* Enable the stub joystick driver (src/joystick/psp/\*.c) */
4.119 +#define SDL_JOYSTICK_PSP 1
4.120 +
4.121 +/* Enable the stub audio driver (src/audio/psp/\*.c) */
4.122 +#define SDL_AUDIO_DRIVER_PSP 1
4.123 +
4.124 +/* PSP video dirver */
4.125 +#define SDL_VIDEO_DRIVER_PSP 1
4.126 +
4.127 +/* PSP render dirver */
4.128 +#define SDL_VIDEO_RENDER_PSP 1
4.129 +
4.130 +#define SDL_POWER_PSP 1
4.131 +
4.132 +/* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */
4.133 +#define SDL_HAPTIC_DISABLED 1
4.134 +
4.135 +/* PSP can't load shared object (src/loadso/dummy/\*.c) */
4.136 +#define SDL_LOADSO_DISABLED 1
4.137 +
4.138 +
4.139 +#endif /* _SDL_config_minimal_h */
5.1 --- a/include/SDL_platform.h Sat Mar 16 11:00:04 2013 -0700
5.2 +++ b/include/SDL_platform.h Sun Mar 17 20:07:02 2013 +0800
5.3 @@ -124,6 +124,10 @@
5.4 #define __NINTENDODS__ 1
5.5 #endif
5.6
5.7 +#if defined(__PSP__)
5.8 +#undef __PLAYSTATIONPORTABLE__
5.9 +#define __PLAYSTATIONPORTABLE__ 1
5.10 +#endif
5.11
5.12 #include "begin_code.h"
5.13 /* Set up for C function definitions, even when using C++ */
6.1 --- a/include/SDL_test_common.h Sat Mar 16 11:00:04 2013 -0700
6.2 +++ b/include/SDL_test_common.h Sun Mar 17 20:07:02 2013 +0800
6.3 @@ -37,6 +37,9 @@
6.4 #ifdef __NDS__
6.5 #define DEFAULT_WINDOW_WIDTH 256
6.6 #define DEFAULT_WINDOW_HEIGHT (2*192)
6.7 +#elif defined(__PSP__)
6.8 +#define DEFAULT_WINDOW_WIDTH 480
6.9 +#define DEFAULT_WINDOW_HEIGHT 272
6.10 #else
6.11 #define DEFAULT_WINDOW_WIDTH 640
6.12 #define DEFAULT_WINDOW_HEIGHT 480
7.1 --- a/src/SDL.c Sat Mar 16 11:00:04 2013 -0700
7.2 +++ b/src/SDL.c Sun Mar 17 20:07:02 2013 +0800
7.3 @@ -408,6 +408,8 @@
7.4 return "Windows";
7.5 #elif __IPHONEOS__
7.6 return "iPhone OS";
7.7 +#elif __PSP__
7.8 + return "PlayStation Portable";
7.9 #else
7.10 return "Unknown (see SDL_platform.h)";
7.11 #endif
8.1 --- a/src/SDL_log.c Sat Mar 16 11:00:04 2013 -0700
8.2 +++ b/src/SDL_log.c Sun Mar 17 20:07:02 2013 +0800
8.3 @@ -327,6 +327,20 @@
8.4 return;
8.5 }
8.6 }
8.7 +#elif defined(__PSP__)
8.8 +//Simple Log System for PSP
8.9 + {
8.10 + unsigned int length;
8.11 + char* output;
8.12 + FILE* pFile;
8.13 + length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1;
8.14 + output = SDL_stack_alloc(char, length);
8.15 + SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message);
8.16 + pFile = fopen ("SDL_Log.txt", "a");
8.17 + fwrite (output, strlen (output), 1, pFile);
8.18 + SDL_stack_free(output);
8.19 + fclose (pFile);
8.20 + }
8.21 #endif
8.22 #if HAVE_STDIO_H
8.23 fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
9.1 --- a/src/audio/SDL_audio.c Sat Mar 16 11:00:04 2013 -0700
9.2 +++ b/src/audio/SDL_audio.c Sun Mar 17 20:07:02 2013 +0800
9.3 @@ -66,7 +66,7 @@
9.4 extern AudioBootStrap NDSAUD_bootstrap;
9.5 extern AudioBootStrap FUSIONSOUND_bootstrap;
9.6 extern AudioBootStrap ANDROIDAUD_bootstrap;
9.7 -
9.8 +extern AudioBootStrap PSPAUD_bootstrap;
9.9
9.10 /* Available audio drivers */
9.11 static const AudioBootStrap *const bootstrap[] = {
9.12 @@ -130,6 +130,9 @@
9.13 #if SDL_AUDIO_DRIVER_ANDROID
9.14 &ANDROIDAUD_bootstrap,
9.15 #endif
9.16 +#if SDL_AUDIO_DRIVER_PSP
9.17 + &PSPAUD_bootstrap,
9.18 +#endif
9.19 NULL
9.20 };
9.21
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/src/audio/psp/SDL_pspaudio.c Sun Mar 17 20:07:02 2013 +0800
10.3 @@ -0,0 +1,199 @@
10.4 +/*
10.5 + Simple DirectMedia Layer
10.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
10.7 +
10.8 + This software is provided 'as-is', without any express or implied
10.9 + warranty. In no event will the authors be held liable for any damages
10.10 + arising from the use of this software.
10.11 +
10.12 + Permission is granted to anyone to use this software for any purpose,
10.13 + including commercial applications, and to alter it and redistribute it
10.14 + freely, subject to the following restrictions:
10.15 +
10.16 + 1. The origin of this software must not be misrepresented; you must not
10.17 + claim that you wrote the original software. If you use this software
10.18 + in a product, an acknowledgment in the product documentation would be
10.19 + appreciated but is not required.
10.20 + 2. Altered source versions must be plainly marked as such, and must not be
10.21 + misrepresented as being the original software.
10.22 + 3. This notice may not be removed or altered from any source distribution.
10.23 +*/
10.24 +
10.25 +#include <stdio.h>
10.26 +#include <string.h>
10.27 +#include <stdlib.h>
10.28 +#include <malloc.h>
10.29 +
10.30 +#include "SDL_audio.h"
10.31 +#include "SDL_error.h"
10.32 +#include "SDL_timer.h"
10.33 +#include "../SDL_audiomem.h"
10.34 +#include "../SDL_audio_c.h"
10.35 +#include "../SDL_audiodev_c.h"
10.36 +#include "../SDL_sysaudio.h"
10.37 +#include "SDL_pspaudio.h"
10.38 +
10.39 +#include <pspaudio.h>
10.40 +#include <pspthreadman.h>
10.41 +
10.42 +/* The tag name used by PSP audio */
10.43 +#define PSPAUD_DRIVER_NAME "psp"
10.44 +
10.45 +static int
10.46 +PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
10.47 +{
10.48 + int format, mixlen, i;
10.49 + this->hidden = (struct SDL_PrivateAudioData *)
10.50 + SDL_malloc(sizeof(*this->hidden));
10.51 + if (this->hidden == NULL) {
10.52 + SDL_OutOfMemory();
10.53 + return 0;
10.54 + }
10.55 + SDL_memset(this->hidden, 0, sizeof(*this->hidden));
10.56 + switch (this->spec.format & 0xff) {
10.57 + case 8:
10.58 + case 16:
10.59 + this->spec.format = AUDIO_S16LSB;
10.60 + break;
10.61 + default:
10.62 + SDL_SetError("Unsupported audio format");
10.63 + return 0;
10.64 + }
10.65 +
10.66 + /* The sample count must be a multiple of 64. */
10.67 + this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
10.68 + this->spec.freq = 44100;
10.69 +
10.70 + /* Update the fragment size as size in bytes. */
10.71 +// SDL_CalculateAudioSpec(this->spec); MOD
10.72 + switch (this->spec.format) {
10.73 + case AUDIO_U8:
10.74 + this->spec.silence = 0x80;
10.75 + break;
10.76 + default:
10.77 + this->spec.silence = 0x00;
10.78 + break;
10.79 + }
10.80 + this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8;
10.81 + this->spec.size *= this->spec.channels;
10.82 + this->spec.size *= this->spec.samples;
10.83 +
10.84 +//==========================================
10.85 +
10.86 + /* Allocate the mixing buffer. Its size and starting address must
10.87 + be a multiple of 64 bytes. Our sample count is already a multiple of
10.88 + 64, so spec->size should be a multiple of 64 as well. */
10.89 + mixlen = this->spec.size * NUM_BUFFERS;
10.90 + this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
10.91 + if (this->hidden->rawbuf == NULL) {
10.92 + SDL_SetError("Couldn't allocate mixing buffer");
10.93 + return 0;
10.94 + }
10.95 +
10.96 + /* Setup the hardware channel. */
10.97 + if (this->spec.channels == 1) {
10.98 + format = PSP_AUDIO_FORMAT_MONO;
10.99 + } else {
10.100 + format = PSP_AUDIO_FORMAT_STEREO;
10.101 + }
10.102 + this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
10.103 + if (this->hidden->channel < 0) {
10.104 + SDL_SetError("Couldn't reserve hardware channel");
10.105 + free(this->hidden->rawbuf);
10.106 + this->hidden->rawbuf = NULL;
10.107 + return 0;
10.108 + }
10.109 +
10.110 + memset(this->hidden->rawbuf, 0, mixlen);
10.111 + for (i = 0; i < NUM_BUFFERS; i++) {
10.112 + this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
10.113 + }
10.114 +
10.115 + this->hidden->next_buffer = 0;
10.116 + return 1;
10.117 +}
10.118 +
10.119 +static void PSPAUD_PlayDevice(_THIS)
10.120 +{
10.121 + Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
10.122 +
10.123 + if (this->spec.channels == 1) {
10.124 + sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
10.125 + } else {
10.126 + sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
10.127 + }
10.128 +
10.129 + this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
10.130 +}
10.131 +
10.132 +/* This function waits until it is possible to write a full sound buffer */
10.133 +static void PSPAUD_WaitDevice(_THIS)
10.134 +{
10.135 + /* Because we block when sending audio, there's no need for this function to do anything. */
10.136 +}
10.137 +static Uint8 *PSPAUD_GetDeviceBuf(_THIS)
10.138 +{
10.139 + return this->hidden->mixbufs[this->hidden->next_buffer];
10.140 +}
10.141 +
10.142 +static void PSPAUD_CloseDevice(_THIS)
10.143 +{
10.144 + if (this->hidden->channel >= 0) {
10.145 + sceAudioChRelease(this->hidden->channel);
10.146 + this->hidden->channel = -1;
10.147 + }
10.148 +
10.149 + if (this->hidden->rawbuf != NULL) {
10.150 + free(this->hidden->rawbuf);
10.151 + this->hidden->rawbuf = NULL;
10.152 + }
10.153 +}
10.154 +static void PSPAUD_ThreadInit(_THIS)
10.155 +{
10.156 + /* Increase the priority of this audio thread by 1 to put it
10.157 + ahead of other SDL threads. */
10.158 + SceUID thid;
10.159 + SceKernelThreadInfo status;
10.160 + thid = sceKernelGetThreadId();
10.161 + status.size = sizeof(SceKernelThreadInfo);
10.162 + if (sceKernelReferThreadStatus(thid, &status) == 0) {
10.163 + sceKernelChangeThreadPriority(thid, status.currentPriority - 1);
10.164 + }
10.165 +}
10.166 +
10.167 +
10.168 +static int
10.169 +PSPAUD_Init(SDL_AudioDriverImpl * impl)
10.170 +{
10.171 +
10.172 + // Set the function pointers
10.173 + impl->OpenDevice = PSPAUD_OpenDevice;
10.174 + impl->PlayDevice = PSPAUD_PlayDevice;
10.175 + impl->WaitDevice = PSPAUD_WaitDevice;
10.176 + impl->GetDeviceBuf = PSPAUD_GetDeviceBuf;
10.177 + impl->WaitDone = PSPAUD_WaitDevice;
10.178 + impl->CloseDevice = PSPAUD_CloseDevice;
10.179 + impl->ThreadInit = PSPAUD_ThreadInit;
10.180 +
10.181 + //PSP audio device
10.182 + impl->OnlyHasDefaultOutputDevice = 1;
10.183 +/*
10.184 + impl->HasCaptureSupport = 1;
10.185 +
10.186 + impl->OnlyHasDefaultInputDevice = 1;
10.187 +*/
10.188 + /*
10.189 + impl->DetectDevices = DSOUND_DetectDevices;
10.190 + impl->Deinitialize = DSOUND_Deinitialize;
10.191 + */
10.192 + return 1; /* this audio target is available. */
10.193 +}
10.194 +
10.195 +AudioBootStrap PSPAUD_bootstrap = {
10.196 + "psp", "PSP audio driver", PSPAUD_Init, 0
10.197 +};
10.198 +
10.199 + /* SDL_AUDI*/
10.200 +
10.201 +
10.202 +
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/src/audio/psp/SDL_pspaudio.h Sun Mar 17 20:07:02 2013 +0800
11.3 @@ -0,0 +1,45 @@
11.4 +/*
11.5 + Simple DirectMedia Layer
11.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
11.7 +
11.8 + This software is provided 'as-is', without any express or implied
11.9 + warranty. In no event will the authors be held liable for any damages
11.10 + arising from the use of this software.
11.11 +
11.12 + Permission is granted to anyone to use this software for any purpose,
11.13 + including commercial applications, and to alter it and redistribute it
11.14 + freely, subject to the following restrictions:
11.15 +
11.16 + 1. The origin of this software must not be misrepresented; you must not
11.17 + claim that you wrote the original software. If you use this software
11.18 + in a product, an acknowledgment in the product documentation would be
11.19 + appreciated but is not required.
11.20 + 2. Altered source versions must be plainly marked as such, and must not be
11.21 + misrepresented as being the original software.
11.22 + 3. This notice may not be removed or altered from any source distribution.
11.23 +*/
11.24 +
11.25 +#ifndef _SDL_pspaudio_h
11.26 +#define _SDL_pspaudio_h
11.27 +
11.28 +#include "../SDL_sysaudio.h"
11.29 +
11.30 +/* Hidden "this" pointer for the video functions */
11.31 +#define _THIS SDL_AudioDevice *this
11.32 +
11.33 +#define NUM_BUFFERS 2
11.34 +
11.35 +struct SDL_PrivateAudioData {
11.36 + /* The hardware output channel. */
11.37 + int channel;
11.38 + /* The raw allocated mixing buffer. */
11.39 + Uint8 *rawbuf;
11.40 + /* Individual mixing buffers. */
11.41 + Uint8 *mixbufs[NUM_BUFFERS];
11.42 + /* Index of the next available mixing buffer. */
11.43 + int next_buffer;
11.44 +};
11.45 +
11.46 +#endif /* _SDL_pspaudio_h */
11.47 +/* vim: ts=4 sw=4
11.48 + */
12.1 --- a/src/events/SDL_gesture.c Sat Mar 16 11:00:04 2013 -0700
12.2 +++ b/src/events/SDL_gesture.c Sun Mar 17 20:07:02 2013 +0800
12.3 @@ -27,7 +27,10 @@
12.4 #include "SDL_events_c.h"
12.5 #include "SDL_gesture_c.h"
12.6
12.7 +#if !defined(__PSP__)
12.8 #include <memory.h>
12.9 +#endif
12.10 +
12.11 #include <string.h>
12.12 #include <stdio.h>
12.13 #include <math.h>
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/src/joystick/psp/SDL_sysjoystick.c Sun Mar 17 20:07:02 2013 +0800
13.3 @@ -0,0 +1,276 @@
13.4 +/*
13.5 + Simple DirectMedia Layer
13.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
13.7 +
13.8 + This software is provided 'as-is', without any express or implied
13.9 + warranty. In no event will the authors be held liable for any damages
13.10 + arising from the use of this software.
13.11 +
13.12 + Permission is granted to anyone to use this software for any purpose,
13.13 + including commercial applications, and to alter it and redistribute it
13.14 + freely, subject to the following restrictions:
13.15 +
13.16 + 1. The origin of this software must not be misrepresented; you must not
13.17 + claim that you wrote the original software. If you use this software
13.18 + in a product, an acknowledgment in the product documentation would be
13.19 + appreciated but is not required.
13.20 + 2. Altered source versions must be plainly marked as such, and must not be
13.21 + misrepresented as being the original software.
13.22 + 3. This notice may not be removed or altered from any source distribution.
13.23 +*/
13.24 +
13.25 +/* This is the system specific header for the SDL joystick API */
13.26 +#include <pspctrl.h>
13.27 +#include <pspkernel.h>
13.28 +
13.29 +#include <stdio.h> /* For the definition of NULL */
13.30 +#include <stdlib.h>
13.31 +
13.32 +#include "../SDL_sysjoystick.h"
13.33 +#include "../SDL_joystick_c.h"
13.34 +
13.35 +#include "SDL_events.h"
13.36 +#include "SDL_error.h"
13.37 +#include "SDL_thread.h"
13.38 +#include "SDL_mutex.h"
13.39 +#include "SDL_timer.h"
13.40 +
13.41 +/* Current pad state */
13.42 +static SceCtrlData pad = { .Lx = 0, .Ly = 0, .Buttons = 0 };
13.43 +static SDL_sem *pad_sem = NULL;
13.44 +static SDL_Thread *thread = NULL;
13.45 +static int running = 0;
13.46 +static const enum PspCtrlButtons button_map[] = {
13.47 + PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE,
13.48 + PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER,
13.49 + PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT,
13.50 + PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD };
13.51 +static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
13.52 +
13.53 +typedef struct
13.54 +{
13.55 + int x;
13.56 + int y;
13.57 +} point;
13.58 +
13.59 +// 4 points define the bezier-curve.
13.60 +static point a = { 0, 0 };
13.61 +static point b = { 50, 0 };
13.62 +static point c = { 78, 32767 };
13.63 +static point d = { 128, 32767 };
13.64 +
13.65 +// simple linear interpolation between two points
13.66 +static __inline__ void lerp (point *dest, point *a, point *b, float t)
13.67 +{
13.68 + dest->x = a->x + (b->x - a->x)*t;
13.69 + dest->y = a->y + (b->y - a->y)*t;
13.70 +}
13.71 +
13.72 +// evaluate a point on a bezier-curve. t goes from 0 to 1.0
13.73 +static int calc_bezier_y(float t)
13.74 +{
13.75 + point ab, bc, cd, abbc, bccd, dest;
13.76 + lerp (&ab, &a, &b, t); // point between a and b
13.77 + lerp (&bc, &b, &c, t); // point between b and c
13.78 + lerp (&cd, &c, &d, t); // point between c and d
13.79 + lerp (&abbc, &ab, &bc, t); // point between ab and bc
13.80 + lerp (&bccd, &bc, &cd, t); // point between bc and cd
13.81 + lerp (&dest, &abbc, &bccd, t); // point on the bezier-curve
13.82 + return dest.y;
13.83 +}
13.84 +
13.85 +/*
13.86 + * Collect pad data about once per frame
13.87 + */
13.88 +int JoystickUpdate(void *data)
13.89 +{
13.90 + while (running) {
13.91 + SDL_SemWait(pad_sem);
13.92 + sceCtrlPeekBufferPositive(&pad, 1);
13.93 + SDL_SemPost(pad_sem);
13.94 + /* Delay 1/60th of a second */
13.95 + sceKernelDelayThread(1000000 / 60);
13.96 + }
13.97 + return 0;
13.98 +}
13.99 +
13.100 +
13.101 +
13.102 +/* Function to scan the system for joysticks.
13.103 + * This function should set SDL_numjoysticks to the number of available
13.104 + * joysticks. Joystick 0 should be the system default joystick.
13.105 + * It should return number of joysticks, or -1 on an unrecoverable fatal error.
13.106 + */
13.107 +int SDL_SYS_JoystickInit(void)
13.108 +{
13.109 + int i;
13.110 +
13.111 +// SDL_numjoysticks = 1;
13.112 +
13.113 + /* Setup input */
13.114 + sceCtrlSetSamplingCycle(0);
13.115 + sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
13.116 +
13.117 + /* Start thread to read data */
13.118 + if((pad_sem = SDL_CreateSemaphore(1)) == NULL) {
13.119 + SDL_SetError("Can't create input semaphore\n");
13.120 + return -1;
13.121 + }
13.122 + running = 1;
13.123 + if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) {
13.124 + SDL_SetError("Can't create input thread\n");
13.125 + return -1;
13.126 + }
13.127 +
13.128 + /* Create an accurate map from analog inputs (0 to 255)
13.129 + to SDL joystick positions (-32768 to 32767) */
13.130 + for (i = 0; i < 128; i++)
13.131 + {
13.132 + float t = (float)i/127.0f;
13.133 + analog_map[i+128] = calc_bezier_y(t);
13.134 + analog_map[127-i] = -1 * analog_map[i+128];
13.135 + }
13.136 +
13.137 + return 1;
13.138 +}
13.139 +
13.140 +int SDL_SYS_NumJoysticks()
13.141 +{
13.142 + return 1;
13.143 +}
13.144 +
13.145 +void SDL_SYS_JoystickDetect()
13.146 +{
13.147 +}
13.148 +
13.149 +SDL_bool SDL_SYS_JoystickNeedsPolling()
13.150 +{
13.151 + return SDL_FALSE;
13.152 +}
13.153 +
13.154 +/* Function to get the device-dependent name of a joystick */
13.155 +const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
13.156 +{
13.157 + return "PSP builtin joypad";
13.158 +}
13.159 +
13.160 +/* Function to perform the mapping from device index to the instance id for this index */
13.161 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
13.162 +{
13.163 + return device_index;
13.164 +}
13.165 +
13.166 +/* Function to get the device-dependent name of a joystick */
13.167 +const char *SDL_SYS_JoystickName(int index)
13.168 +{
13.169 + if (index == 0)
13.170 + return "PSP controller";
13.171 +
13.172 + SDL_SetError("No joystick available with that index");
13.173 + return(NULL);
13.174 +}
13.175 +
13.176 +/* Function to open a joystick for use.
13.177 + The joystick to open is specified by the index field of the joystick.
13.178 + This should fill the nbuttons and naxes fields of the joystick structure.
13.179 + It returns 0, or -1 if there is an error.
13.180 + */
13.181 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
13.182 +{
13.183 + joystick->nbuttons = 14;
13.184 + joystick->naxes = 2;
13.185 + joystick->nhats = 0;
13.186 +
13.187 + return 0;
13.188 +}
13.189 +
13.190 +/* Function to determine is this joystick is attached to the system right now */
13.191 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
13.192 +{
13.193 + return SDL_TRUE;
13.194 +}
13.195 +/* Function to update the state of a joystick - called as a device poll.
13.196 + * This function shouldn't update the joystick structure directly,
13.197 + * but instead should call SDL_PrivateJoystick*() to deliver events
13.198 + * and update joystick device state.
13.199 + */
13.200 +
13.201 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
13.202 +{
13.203 + int i;
13.204 + enum PspCtrlButtons buttons;
13.205 + enum PspCtrlButtons changed;
13.206 + unsigned char x, y;
13.207 + static enum PspCtrlButtons old_buttons = 0;
13.208 + static unsigned char old_x = 0, old_y = 0;
13.209 +
13.210 + SDL_SemWait(pad_sem);
13.211 + buttons = pad.Buttons;
13.212 + x = pad.Lx;
13.213 + y = pad.Ly;
13.214 + SDL_SemPost(pad_sem);
13.215 +
13.216 + /* Axes */
13.217 + if(old_x != x) {
13.218 + SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]);
13.219 + old_x = x;
13.220 + }
13.221 + if(old_y != y) {
13.222 + SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]);
13.223 + old_y = y;
13.224 + }
13.225 +
13.226 + /* Buttons */
13.227 + changed = old_buttons ^ buttons;
13.228 + old_buttons = buttons;
13.229 + if(changed) {
13.230 + for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
13.231 + if(changed & button_map[i]) {
13.232 + SDL_PrivateJoystickButton(
13.233 + joystick, i,
13.234 + (buttons & button_map[i]) ?
13.235 + SDL_PRESSED : SDL_RELEASED);
13.236 + }
13.237 + }
13.238 + }
13.239 +
13.240 + sceKernelDelayThread(0);
13.241 +}
13.242 +
13.243 +/* Function to close a joystick after use */
13.244 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
13.245 +{
13.246 + /* Do nothing. */
13.247 +}
13.248 +
13.249 +/* Function to perform any system-specific joystick related cleanup */
13.250 +void SDL_SYS_JoystickQuit(void)
13.251 +{
13.252 + /* Cleanup Threads and Semaphore. */
13.253 + running = 0;
13.254 + SDL_WaitThread(thread, NULL);
13.255 + SDL_DestroySemaphore(pad_sem);
13.256 +}
13.257 +
13.258 +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
13.259 +{
13.260 + SDL_JoystickGUID guid;
13.261 + // the GUID is just the first 16 chars of the name for now
13.262 + const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
13.263 + SDL_zero( guid );
13.264 + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
13.265 + return guid;
13.266 +}
13.267 +
13.268 +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
13.269 +{
13.270 + SDL_JoystickGUID guid;
13.271 + // the GUID is just the first 16 chars of the name for now
13.272 + const char *name = joystick->name;
13.273 + SDL_zero( guid );
13.274 + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
13.275 + return guid;
13.276 +}
13.277 +
13.278 +/* vim: ts=4 sw=4
13.279 + */
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/src/main/psp/SDL_psp_main.c Sun Mar 17 20:07:02 2013 +0800
14.3 @@ -0,0 +1,80 @@
14.4 +/*
14.5 + Simple DirectMedia Layer
14.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
14.7 +
14.8 + This software is provided 'as-is', without any express or implied
14.9 + warranty. In no event will the authors be held liable for any damages
14.10 + arising from the use of this software.
14.11 +
14.12 + Permission is granted to anyone to use this software for any purpose,
14.13 + including commercial applications, and to alter it and redistribute it
14.14 + freely, subject to the following restrictions:
14.15 +
14.16 + 1. The origin of this software must not be misrepresented; you must not
14.17 + claim that you wrote the original software. If you use this software
14.18 + in a product, an acknowledgment in the product documentation would be
14.19 + appreciated but is not required.
14.20 + 2. Altered source versions must be plainly marked as such, and must not be
14.21 + misrepresented as being the original software.
14.22 + 3. This notice may not be removed or altered from any source distribution.
14.23 +*/
14.24 +
14.25 +#include "SDL_main.h"
14.26 +#include <pspkernel.h>
14.27 +#include <pspdebug.h>
14.28 +#include <pspsdk.h>
14.29 +#include <pspthreadman.h>
14.30 +#include <stdlib.h>
14.31 +#include <stdio.h>
14.32 +
14.33 +/* If application's main() is redefined as SDL_main, and libSDLmain is
14.34 + linked, then this file will create the standard exit callback,
14.35 + define the PSP_MODULE_INFO macro, and exit back to the browser when
14.36 + the program is finished.
14.37 +
14.38 + You can still override other parameters in your own code if you
14.39 + desire, such as PSP_HEAP_SIZE_KB, PSP_MAIN_THREAD_ATTR,
14.40 + PSP_MAIN_THREAD_STACK_SIZE, etc.
14.41 +*/
14.42 +
14.43 +extern int SDL_main(int argc, char *argv[]);
14.44 +
14.45 +PSP_MODULE_INFO("SDL App", 0, 1, 1);
14.46 +
14.47 +int sdl_psp_exit_callback(int arg1, int arg2, void *common)
14.48 +{
14.49 + exit(0);
14.50 + return 0;
14.51 +}
14.52 +
14.53 +int sdl_psp_callback_thread(SceSize args, void *argp)
14.54 +{
14.55 + int cbid;
14.56 + cbid = sceKernelCreateCallback("Exit Callback",
14.57 + sdl_psp_exit_callback, NULL);
14.58 + sceKernelRegisterExitCallback(cbid);
14.59 + sceKernelSleepThreadCB();
14.60 + return 0;
14.61 +}
14.62 +
14.63 +int sdl_psp_setup_callbacks(void)
14.64 +{
14.65 + int thid = 0;
14.66 + thid = sceKernelCreateThread("update_thread",
14.67 + sdl_psp_callback_thread, 0x11, 0xFA0, 0, 0);
14.68 + if(thid >= 0)
14.69 + sceKernelStartThread(thid, 0, 0);
14.70 + return thid;
14.71 +}
14.72 +
14.73 +int main(int argc, char *argv[])
14.74 +{
14.75 + pspDebugScreenInit();
14.76 + sdl_psp_setup_callbacks();
14.77 +
14.78 + /* Register sceKernelExitGame() to be called when we exit */
14.79 + atexit(sceKernelExitGame);
14.80 +
14.81 + (void)SDL_main(argc, argv);
14.82 + return 0;
14.83 +}
15.1 --- a/src/power/SDL_power.c Sat Mar 16 11:00:04 2013 -0700
15.2 +++ b/src/power/SDL_power.c Sun Mar 17 20:07:02 2013 +0800
15.3 @@ -37,6 +37,7 @@
15.4 SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *);
15.5 SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
15.6 SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
15.7 +SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
15.8
15.9 #ifndef SDL_POWER_DISABLED
15.10 #ifdef SDL_POWER_HARDWIRED
15.11 @@ -77,6 +78,10 @@
15.12 #ifdef SDL_POWER_ANDROID /* handles Android. */
15.13 SDL_GetPowerInfo_Android,
15.14 #endif
15.15 +#ifdef SDL_POWER_PSP /* handles PSP. */
15.16 + SDL_GetPowerInfo_PSP,
15.17 +#endif
15.18 +
15.19 #ifdef SDL_POWER_HARDWIRED
15.20 SDL_GetPowerInfo_Hardwired,
15.21 #endif
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/src/power/psp/SDL_syspower.c Sun Mar 17 20:07:02 2013 +0800
16.3 @@ -0,0 +1,68 @@
16.4 +/*
16.5 + Simple DirectMedia Layer
16.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
16.7 +
16.8 + This software is provided 'as-is', without any express or implied
16.9 + warranty. In no event will the authors be held liable for any damages
16.10 + arising from the use of this software.
16.11 +
16.12 + Permission is granted to anyone to use this software for any purpose,
16.13 + including commercial applications, and to alter it and redistribute it
16.14 + freely, subject to the following restrictions:
16.15 +
16.16 + 1. The origin of this software must not be misrepresented; you must not
16.17 + claim that you wrote the original software. If you use this software
16.18 + in a product, an acknowledgment in the product documentation would be
16.19 + appreciated but is not required.
16.20 + 2. Altered source versions must be plainly marked as such, and must not be
16.21 + misrepresented as being the original software.
16.22 + 3. This notice may not be removed or altered from any source distribution.
16.23 +*/
16.24 +
16.25 +#include "SDL_config.h"
16.26 +
16.27 +#ifndef SDL_POWER_DISABLED
16.28 +#if SDL_POWER_PSP
16.29 +
16.30 +#include "SDL_power.h"
16.31 +#include <psppower.h>
16.32 +
16.33 +
16.34 +SDL_bool
16.35 +SDL_GetPowerInfo_PSP(SDL_PowerState * state, int *seconds,
16.36 + int *percent)
16.37 +{
16.38 + int battery = scePowerIsBatteryExist();
16.39 + int plugged = scePowerIsPowerOnline();
16.40 + int charging = scePowerIsBatteryCharging();
16.41 +
16.42 + *state = SDL_POWERSTATE_UNKNOWN;
16.43 + *seconds = -1;
16.44 + *percent = -1;
16.45 +
16.46 + if (!battery) {
16.47 + *state = SDL_POWERSTATE_NO_BATTERY;
16.48 + *seconds = -1;
16.49 + *percent = -1;
16.50 + } else if (charging) {
16.51 + *state = SDL_POWERSTATE_CHARGING;
16.52 + *percent = scePowerGetBatteryLifePercent();
16.53 + *seconds = scePowerGetBatteryLifeTime()*60;
16.54 + } else if (plugged) {
16.55 + *state = SDL_POWERSTATE_CHARGED;
16.56 + *percent = scePowerGetBatteryLifePercent();
16.57 + *seconds = scePowerGetBatteryLifeTime()*60;
16.58 + } else {
16.59 + *state = SDL_POWERSTATE_ON_BATTERY;
16.60 + *percent = scePowerGetBatteryLifePercent();
16.61 + *seconds = scePowerGetBatteryLifeTime()*60;
16.62 + }
16.63 +
16.64 +
16.65 + return SDL_TRUE; /* always the definitive answer on PSP. */
16.66 +}
16.67 +
16.68 +#endif /* SDL_POWER_PSP */
16.69 +#endif /* SDL_POWER_DISABLED */
16.70 +
16.71 +/* vi: set ts=4 sw=4 expandtab: */
17.1 --- a/src/render/SDL_render.c Sat Mar 16 11:00:04 2013 -0700
17.2 +++ b/src/render/SDL_render.c Sun Mar 17 20:07:02 2013 +0800
17.3 @@ -64,6 +64,9 @@
17.4 #if SDL_VIDEO_RENDER_NDS
17.5 &NDS_RenderDriver,
17.6 #endif
17.7 +#if SDL_VIDEO_RENDER_PSP
17.8 + &PSP_RenderDriver,
17.9 +#endif
17.10 &SW_RenderDriver
17.11 #endif /* !SDL_RENDER_DISABLED */
17.12 };
18.1 --- a/src/render/SDL_sysrender.h Sat Mar 16 11:00:04 2013 -0700
18.2 +++ b/src/render/SDL_sysrender.h Sun Mar 17 20:07:02 2013 +0800
18.3 @@ -176,6 +176,9 @@
18.4 #if SDL_VIDEO_RENDER_NDS
18.5 extern SDL_RenderDriver NDS_RenderDriver;
18.6 #endif
18.7 +#if SDL_VIDEO_RENDER_PSP
18.8 +extern SDL_RenderDriver PSP_RenderDriver;
18.9 +#endif
18.10 extern SDL_RenderDriver SW_RenderDriver;
18.11
18.12 #endif /* !SDL_RENDER_DISABLED */
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/src/render/psp/SDL_render_psp.c Sun Mar 17 20:07:02 2013 +0800
19.3 @@ -0,0 +1,1024 @@
19.4 +/*
19.5 + Simple DirectMedia Layer
19.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
19.7 +
19.8 + This software is provided 'as-is', without any express or implied
19.9 + warranty. In no event will the authors be held liable for any damages
19.10 + arising from the use of this software.
19.11 +
19.12 + Permission is granted to anyone to use this software for any purpose,
19.13 + including commercial applications, and to alter it and redistribute it
19.14 + freely, subject to the following restrictions:
19.15 +
19.16 + 1. The origin of this software must not be misrepresented; you must not
19.17 + claim that you wrote the original software. If you use this software
19.18 + in a product, an acknowledgment in the product documentation would be
19.19 + appreciated but is not required.
19.20 + 2. Altered source versions must be plainly marked as such, and must not be
19.21 + misrepresented as being the original software.
19.22 + 3. This notice may not be removed or altered from any source distribution.
19.23 +*/
19.24 +#include "SDL_config.h"
19.25 +
19.26 +#if SDL_VIDEO_RENDER_PSP
19.27 +
19.28 +#include "SDL_hints.h"
19.29 +#include "../SDL_sysrender.h"
19.30 +
19.31 +#include <pspkernel.h>
19.32 +#include <pspdisplay.h>
19.33 +#include <pspgu.h>
19.34 +#include <pspgum.h>
19.35 +#include <stdio.h>
19.36 +#include <string.h>
19.37 +#include <math.h>
19.38 +#include <pspge.h>
19.39 +#include <stdarg.h>
19.40 +#include <stdlib.h>
19.41 +#include <vram.h>
19.42 +
19.43 +
19.44 +
19.45 +
19.46 +/* PSP renderer implementation, based on the PGE */
19.47 +
19.48 +
19.49 +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
19.50 +
19.51 +
19.52 +static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags);
19.53 +static void PSP_WindowEvent(SDL_Renderer * renderer,
19.54 + const SDL_WindowEvent *event);
19.55 +static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
19.56 +static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
19.57 + const SDL_Rect * rect, const void *pixels,
19.58 + int pitch);
19.59 +static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
19.60 + const SDL_Rect * rect, void **pixels, int *pitch);
19.61 +static void PSP_UnlockTexture(SDL_Renderer * renderer,
19.62 + SDL_Texture * texture);
19.63 +static int PSP_SetRenderTarget(SDL_Renderer * renderer,
19.64 + SDL_Texture * texture);
19.65 +static int PSP_UpdateViewport(SDL_Renderer * renderer);
19.66 +static int PSP_RenderClear(SDL_Renderer * renderer);
19.67 +static int PSP_RenderDrawPoints(SDL_Renderer * renderer,
19.68 + const SDL_FPoint * points, int count);
19.69 +static int PSP_RenderDrawLines(SDL_Renderer * renderer,
19.70 + const SDL_FPoint * points, int count);
19.71 +static int PSP_RenderFillRects(SDL_Renderer * renderer,
19.72 + const SDL_FRect * rects, int count);
19.73 +static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
19.74 + const SDL_Rect * srcrect,
19.75 + const SDL_FRect * dstrect);
19.76 +static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
19.77 + Uint32 pixel_format, void * pixels, int pitch);
19.78 +static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
19.79 + const SDL_Rect * srcrect, const SDL_FRect * dstrect,
19.80 + const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
19.81 +static void PSP_RenderPresent(SDL_Renderer * renderer);
19.82 +static void PSP_DestroyTexture(SDL_Renderer * renderer,
19.83 + SDL_Texture * texture);
19.84 +static void PSP_DestroyRenderer(SDL_Renderer * renderer);
19.85 +
19.86 +/*
19.87 +SDL_RenderDriver PSP_RenderDriver = {
19.88 + PSP_CreateRenderer,
19.89 + {
19.90 + "PSP",
19.91 + (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
19.92 + 1,
19.93 + {SDL_PIXELFORMAT_ABGR8888},
19.94 + 0,
19.95 + 0}
19.96 +};
19.97 +*/
19.98 +SDL_RenderDriver PSP_RenderDriver = {
19.99 + .CreateRenderer = PSP_CreateRenderer,
19.100 + .info = {
19.101 + .name = "PSP",
19.102 + .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
19.103 + .num_texture_formats = 4,
19.104 + .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565,
19.105 + [1] = SDL_PIXELFORMAT_ABGR1555,
19.106 + [2] = SDL_PIXELFORMAT_ABGR4444,
19.107 + [3] = SDL_PIXELFORMAT_ABGR8888,
19.108 + },
19.109 + .max_texture_width = 512,
19.110 + .max_texture_height = 512,
19.111 + }
19.112 +};
19.113 +
19.114 +#define PSP_SCREEN_WIDTH 480
19.115 +#define PSP_SCREEN_HEIGHT 272
19.116 +
19.117 +#define PSP_FRAME_BUFFER_WIDTH 512
19.118 +#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
19.119 +
19.120 +static unsigned int __attribute__((aligned(16))) DisplayList[262144];
19.121 +
19.122 +
19.123 +#define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
19.124 +#define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
19.125 +#define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
19.126 +#define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
19.127 +
19.128 +
19.129 +typedef struct
19.130 +{
19.131 + void* frontbuffer ;
19.132 + void* backbuffer ;
19.133 + SDL_bool initialized ;
19.134 + SDL_bool displayListAvail ;
19.135 + unsigned int psm ;
19.136 + unsigned int bpp ;
19.137 +
19.138 + SDL_bool vsync;
19.139 + unsigned int currentColor;
19.140 + int currentBlendMode;
19.141 +
19.142 +} PSP_RenderData;
19.143 +
19.144 +
19.145 +typedef struct
19.146 +{
19.147 + void *data; /**< Image data. */
19.148 + unsigned int size; /**< Size of data in bytes. */
19.149 + unsigned int width; /**< Image width. */
19.150 + unsigned int height; /**< Image height. */
19.151 + unsigned int textureWidth; /**< Texture width (power of two). */
19.152 + unsigned int textureHeight; /**< Texture height (power of two). */
19.153 + unsigned int bits; /**< Image bits per pixel. */
19.154 + unsigned int format; /**< Image format - one of ::pgePixelFormat. */
19.155 + unsigned int pitch;
19.156 + SDL_bool swizzled; /**< Is image swizzled. */
19.157 +
19.158 +} PSP_TextureData;
19.159 +
19.160 +typedef struct
19.161 +{
19.162 + float x, y, z;
19.163 +} VertV;
19.164 +
19.165 +
19.166 +typedef struct
19.167 +{
19.168 + float u, v;
19.169 + float x, y, z;
19.170 +
19.171 +} VertTV;
19.172 +
19.173 +
19.174 +// Return next power of 2
19.175 +static int
19.176 +TextureNextPow2(unsigned int w)
19.177 +{
19.178 + if(w == 0)
19.179 + return 0;
19.180 +
19.181 + unsigned int n = 2;
19.182 +
19.183 + while(w > n)
19.184 + n <<= 1;
19.185 +
19.186 + return n;
19.187 +}
19.188 +
19.189 +
19.190 +static int
19.191 +GetScaleQuality(void)
19.192 +{
19.193 + const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
19.194 +
19.195 + if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
19.196 + return GU_NEAREST; // GU_NEAREST good for tile-map
19.197 + } else {
19.198 + return GU_LINEAR; // GU_LINEAR good for scaling
19.199 + }
19.200 +}
19.201 +
19.202 +static int
19.203 +PixelFormatToPSPFMT(Uint32 format)
19.204 +{
19.205 + switch (format) {
19.206 + case SDL_PIXELFORMAT_BGR565:
19.207 + return GU_PSM_5650;
19.208 + case SDL_PIXELFORMAT_ABGR1555:
19.209 + return GU_PSM_5551;
19.210 + case SDL_PIXELFORMAT_ABGR4444:
19.211 + return GU_PSM_4444;
19.212 + case SDL_PIXELFORMAT_ABGR8888:
19.213 + return GU_PSM_8888;
19.214 + default:
19.215 + return GU_PSM_8888;
19.216 + }
19.217 +}
19.218 +
19.219 +void
19.220 +StartDrawing(SDL_Renderer * renderer)
19.221 +{
19.222 + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
19.223 + if(data->displayListAvail)
19.224 + return;
19.225 +
19.226 + sceGuStart(GU_DIRECT, DisplayList);
19.227 + data->displayListAvail = SDL_TRUE;
19.228 +}
19.229 +
19.230 +
19.231 +int
19.232 +TextureSwizzle(PSP_TextureData *psp_texture)
19.233 +{
19.234 + if(psp_texture->swizzled)
19.235 + return 1;
19.236 +
19.237 + int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
19.238 + int height = psp_texture->size / bytewidth;
19.239 +
19.240 + int rowblocks = (bytewidth>>4);
19.241 + int rowblocksadd = (rowblocks-1)<<7;
19.242 + unsigned int blockaddress = 0;
19.243 + unsigned int *src = (unsigned int*) psp_texture->data;
19.244 +
19.245 + unsigned char *data = NULL;
19.246 + data = malloc(psp_texture->size);
19.247 +
19.248 + int j;
19.249 +
19.250 + for(j = 0; j < height; j++, blockaddress += 16)
19.251 + {
19.252 + unsigned int *block;
19.253 +
19.254 + block = (unsigned int*)&data[blockaddress];
19.255 +
19.256 + int i;
19.257 +
19.258 + for(i = 0; i < rowblocks; i++)
19.259 + {
19.260 + *block++ = *src++;
19.261 + *block++ = *src++;
19.262 + *block++ = *src++;
19.263 + *block++ = *src++;
19.264 + block += 28;
19.265 + }
19.266 +
19.267 + if((j & 0x7) == 0x7)
19.268 + blockaddress += rowblocksadd;
19.269 + }
19.270 +
19.271 + free(psp_texture->data);
19.272 + psp_texture->data = data;
19.273 + psp_texture->swizzled = SDL_TRUE;
19.274 +
19.275 + return 1;
19.276 +}
19.277 +int TextureUnswizzle(PSP_TextureData *psp_texture)
19.278 +{
19.279 + if(!psp_texture->swizzled)
19.280 + return 1;
19.281 +
19.282 + int blockx, blocky;
19.283 +
19.284 + int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
19.285 + int height = psp_texture->size / bytewidth;
19.286 +
19.287 + int widthblocks = bytewidth/16;
19.288 + int heightblocks = height/8;
19.289 +
19.290 + int dstpitch = (bytewidth - 16)/4;
19.291 + int dstrow = bytewidth * 8;
19.292 +
19.293 + unsigned int *src = (unsigned int*) psp_texture->data;
19.294 +
19.295 + unsigned char *data = NULL;
19.296 +
19.297 + data = malloc(psp_texture->size);
19.298 +
19.299 + if(!data)
19.300 + return 0;
19.301 +
19.302 + sceKernelDcacheWritebackAll();
19.303 +
19.304 + int j;
19.305 +
19.306 + unsigned char *ydst = (unsigned char *)data;
19.307 +
19.308 + for(blocky = 0; blocky < heightblocks; ++blocky)
19.309 + {
19.310 + unsigned char *xdst = ydst;
19.311 +
19.312 + for(blockx = 0; blockx < widthblocks; ++blockx)
19.313 + {
19.314 + unsigned int *block;
19.315 +
19.316 + block = (unsigned int*)xdst;
19.317 +
19.318 + for(j = 0; j < 8; ++j)
19.319 + {
19.320 + *(block++) = *(src++);
19.321 + *(block++) = *(src++);
19.322 + *(block++) = *(src++);
19.323 + *(block++) = *(src++);
19.324 + block += dstpitch;
19.325 + }
19.326 +
19.327 + xdst += 16;
19.328 + }
19.329 +
19.330 + ydst += dstrow;
19.331 + }
19.332 +
19.333 + free(psp_texture->data);
19.334 +
19.335 + psp_texture->data = data;
19.336 +
19.337 + psp_texture->swizzled = SDL_FALSE;
19.338 +
19.339 + return 1;
19.340 +}
19.341 +
19.342 +SDL_Renderer *
19.343 +PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
19.344 +{
19.345 +
19.346 + SDL_Renderer *renderer;
19.347 + PSP_RenderData *data;
19.348 + int pixelformat;
19.349 + renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
19.350 + if (!renderer) {
19.351 + SDL_OutOfMemory();
19.352 + return NULL;
19.353 + }
19.354 +
19.355 + data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data));
19.356 + if (!data) {
19.357 + PSP_DestroyRenderer(renderer);
19.358 + SDL_OutOfMemory();
19.359 + return NULL;
19.360 + }
19.361 +
19.362 +
19.363 + renderer->WindowEvent = PSP_WindowEvent;
19.364 + renderer->CreateTexture = PSP_CreateTexture;
19.365 + renderer->UpdateTexture = PSP_UpdateTexture;
19.366 + renderer->LockTexture = PSP_LockTexture;
19.367 + renderer->UnlockTexture = PSP_UnlockTexture;
19.368 + renderer->SetRenderTarget = PSP_SetRenderTarget;
19.369 + renderer->UpdateViewport = PSP_UpdateViewport;
19.370 + renderer->RenderClear = PSP_RenderClear;
19.371 + renderer->RenderDrawPoints = PSP_RenderDrawPoints;
19.372 + renderer->RenderDrawLines = PSP_RenderDrawLines;
19.373 + renderer->RenderFillRects = PSP_RenderFillRects;
19.374 + renderer->RenderCopy = PSP_RenderCopy;
19.375 + renderer->RenderReadPixels = PSP_RenderReadPixels;
19.376 + renderer->RenderCopyEx = PSP_RenderCopyEx;
19.377 + renderer->RenderPresent = PSP_RenderPresent;
19.378 + renderer->DestroyTexture = PSP_DestroyTexture;
19.379 + renderer->DestroyRenderer = PSP_DestroyRenderer;
19.380 + renderer->info = PSP_RenderDriver.info;
19.381 + renderer->info.flags = SDL_RENDERER_ACCELERATED;
19.382 + renderer->driverdata = data;
19.383 + renderer->window = window;
19.384 +
19.385 + if (data->initialized != SDL_FALSE)
19.386 + return 0;
19.387 + data->initialized = SDL_TRUE;
19.388 +
19.389 + if (flags & SDL_RENDERER_PRESENTVSYNC) {
19.390 + data->vsync = SDL_TRUE;
19.391 + } else {
19.392 + data->vsync = SDL_FALSE;
19.393 + }
19.394 +
19.395 + pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window));
19.396 + switch(pixelformat)
19.397 + {
19.398 + case GU_PSM_4444:
19.399 + case GU_PSM_5650:
19.400 + case GU_PSM_5551:
19.401 + data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
19.402 + data->backbuffer = (unsigned int *)(0);
19.403 + data->bpp = 2;
19.404 + data->psm = pixelformat;
19.405 + break;
19.406 + default:
19.407 + data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
19.408 + data->backbuffer = (unsigned int *)(0);
19.409 + data->bpp = 4;
19.410 + data->psm = GU_PSM_8888;
19.411 + break;
19.412 + }
19.413 +
19.414 + sceGuInit();
19.415 + // setup GU
19.416 + sceGuStart(GU_DIRECT, DisplayList);
19.417 + sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
19.418 + sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
19.419 +
19.420 +
19.421 + sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
19.422 + sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
19.423 +
19.424 + data->frontbuffer = vabsptr(data->frontbuffer);
19.425 + data->backbuffer = vabsptr(data->backbuffer);
19.426 +
19.427 + // Scissoring
19.428 + sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
19.429 + sceGuEnable(GU_SCISSOR_TEST);
19.430 +
19.431 + // Backface culling
19.432 + sceGuFrontFace(GU_CCW);
19.433 + sceGuEnable(GU_CULL_FACE);
19.434 +
19.435 + // Texturing
19.436 + sceGuEnable(GU_TEXTURE_2D);
19.437 + sceGuShadeModel(GU_SMOOTH);
19.438 + sceGuTexWrap(GU_REPEAT, GU_REPEAT);
19.439 +
19.440 + // Blending
19.441 + sceGuEnable(GU_BLEND);
19.442 + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
19.443 +
19.444 + sceGuTexFilter(GU_LINEAR,GU_LINEAR);
19.445 +
19.446 + sceGuFinish();
19.447 + sceGuSync(0,0);
19.448 + sceDisplayWaitVblankStartCB();
19.449 + sceGuDisplay(GU_TRUE);
19.450 +
19.451 + return renderer;
19.452 +}
19.453 +
19.454 +static void
19.455 +PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
19.456 +{
19.457 +
19.458 +}
19.459 +
19.460 +
19.461 +static int
19.462 +PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
19.463 +{
19.464 +// PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
19.465 + PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));;
19.466 +
19.467 + if(!psp_texture)
19.468 + return -1;
19.469 +
19.470 + psp_texture->swizzled = SDL_FALSE;
19.471 + psp_texture->width = texture->w;
19.472 + psp_texture->height = texture->h;
19.473 + psp_texture->textureHeight = TextureNextPow2(texture->h);
19.474 + psp_texture->textureWidth = TextureNextPow2(texture->w);
19.475 + psp_texture->format = PixelFormatToPSPFMT(texture->format);
19.476 +
19.477 + switch(psp_texture->format)
19.478 + {
19.479 + case GU_PSM_5650:
19.480 + case GU_PSM_5551:
19.481 + case GU_PSM_4444:
19.482 + psp_texture->bits = 16;
19.483 + break;
19.484 +
19.485 + case GU_PSM_8888:
19.486 + psp_texture->bits = 32;
19.487 + break;
19.488 +
19.489 + default:
19.490 + return -1;
19.491 + }
19.492 +
19.493 + psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format);
19.494 + psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
19.495 + psp_texture->data = SDL_calloc(1, psp_texture->size);
19.496 +
19.497 + if(!psp_texture->data)
19.498 + {
19.499 + SDL_OutOfMemory();
19.500 + SDL_free(psp_texture);
19.501 + return -1;
19.502 + }
19.503 + texture->driverdata = psp_texture;
19.504 +
19.505 + return 0;
19.506 +}
19.507 +
19.508 +
19.509 +void
19.510 +TextureActivate(SDL_Texture * texture)
19.511 +{
19.512 + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
19.513 + int scaleMode = GetScaleQuality();
19.514 +
19.515 + // Swizzling is useless with small textures.
19.516 + if (texture->w >= 16 || texture->h >= 16)
19.517 + {
19.518 + TextureSwizzle(psp_texture);
19.519 + }
19.520 +
19.521 + sceGuEnable(GU_TEXTURE_2D);
19.522 + sceGuTexWrap(GU_REPEAT, GU_REPEAT);
19.523 + sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
19.524 + sceGuTexFilter(scaleMode, scaleMode); // GU_NEAREST good for tile-map
19.525 + // GU_LINEAR good for scaling
19.526 + sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
19.527 + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
19.528 +}
19.529 +
19.530 +
19.531 +static int
19.532 +PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
19.533 + const SDL_Rect * rect, const void *pixels, int pitch)
19.534 +{
19.535 +// PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
19.536 + const Uint8 *src;
19.537 + Uint8 *dst;
19.538 + int row, length,dpitch;
19.539 + src = pixels;
19.540 +
19.541 + PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch);
19.542 + length = rect->w * SDL_BYTESPERPIXEL(texture->format);
19.543 + if (length == pitch && length == dpitch) {
19.544 + SDL_memcpy(dst, src, length*rect->h);
19.545 + } else {
19.546 + for (row = 0; row < rect->h; ++row) {
19.547 + SDL_memcpy(dst, src, length);
19.548 + src += pitch;
19.549 + dst += dpitch;
19.550 + }
19.551 + }
19.552 +
19.553 + sceKernelDcacheWritebackAll();
19.554 + return 0;
19.555 +}
19.556 +
19.557 +static int
19.558 +PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
19.559 + const SDL_Rect * rect, void **pixels, int *pitch)
19.560 +{
19.561 + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
19.562 +
19.563 + *pixels =
19.564 + (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch +
19.565 + rect->x * SDL_BYTESPERPIXEL(texture->format));
19.566 + *pitch = psp_texture->pitch;
19.567 + return 0;
19.568 +}
19.569 +
19.570 +static void
19.571 +PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
19.572 +{
19.573 + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
19.574 + SDL_Rect rect;
19.575 +
19.576 + /* We do whole texture updates, at least for now */
19.577 + rect.x = 0;
19.578 + rect.y = 0;
19.579 + rect.w = texture->w;
19.580 + rect.h = texture->h;
19.581 + PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch);
19.582 +}
19.583 +
19.584 +static int
19.585 +PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
19.586 +{
19.587 +
19.588 + return 0;
19.589 +}
19.590 +
19.591 +static int
19.592 +PSP_UpdateViewport(SDL_Renderer * renderer)
19.593 +{
19.594 +
19.595 + return 0;
19.596 +}
19.597 +
19.598 +
19.599 +static void
19.600 +PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
19.601 +{
19.602 + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
19.603 + if (blendMode != data-> currentBlendMode) {
19.604 + switch (blendMode) {
19.605 + case SDL_BLENDMODE_NONE:
19.606 + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
19.607 + sceGuDisable(GU_BLEND);
19.608 + break;
19.609 + case SDL_BLENDMODE_BLEND:
19.610 + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
19.611 + sceGuEnable(GU_BLEND);
19.612 + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
19.613 + break;
19.614 + case SDL_BLENDMODE_ADD:
19.615 + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
19.616 + sceGuEnable(GU_BLEND);
19.617 + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
19.618 + break;
19.619 + case SDL_BLENDMODE_MOD:
19.620 + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
19.621 + sceGuEnable(GU_BLEND);
19.622 + sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
19.623 + break;
19.624 + }
19.625 + data->currentBlendMode = blendMode;
19.626 + }
19.627 +}
19.628 +
19.629 +
19.630 +
19.631 +static int
19.632 +PSP_RenderClear(SDL_Renderer * renderer)
19.633 +{
19.634 + //start list
19.635 + StartDrawing(renderer);
19.636 + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
19.637 + sceGuClearColor(color);
19.638 + sceGuClearDepth(0);
19.639 + sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
19.640 +
19.641 + return 0;
19.642 +}
19.643 +
19.644 +static int
19.645 +PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
19.646 + int count)
19.647 +{
19.648 + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
19.649 + int i;
19.650 + StartDrawing(renderer);
19.651 + VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
19.652 +
19.653 + for (i = 0; i < count; ++i) {
19.654 + vertices[i].x = points[i].x;
19.655 + vertices[i].y = points[i].y;
19.656 + vertices[i].z = 0.0f;
19.657 + }
19.658 + sceGuDisable(GU_TEXTURE_2D);
19.659 + sceGuColor(color);
19.660 + sceGuShadeModel(GU_FLAT);
19.661 + sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
19.662 + sceGuShadeModel(GU_SMOOTH);
19.663 + sceGuEnable(GU_TEXTURE_2D);
19.664 +
19.665 + return 0;
19.666 +}
19.667 +
19.668 +static int
19.669 +PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
19.670 + int count)
19.671 +{
19.672 + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
19.673 + int i;
19.674 + StartDrawing(renderer);
19.675 + VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
19.676 +
19.677 + for (i = 0; i < count; ++i) {
19.678 + vertices[i].x = points[i].x;
19.679 + vertices[i].y = points[i].y;
19.680 + vertices[i].z = 0.0f;
19.681 + }
19.682 +
19.683 + sceGuDisable(GU_TEXTURE_2D);
19.684 + sceGuColor(color);
19.685 + sceGuShadeModel(GU_FLAT);
19.686 + sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
19.687 + sceGuShadeModel(GU_SMOOTH);
19.688 + sceGuEnable(GU_TEXTURE_2D);
19.689 +
19.690 + return 0;
19.691 +}
19.692 +
19.693 +static int
19.694 +PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
19.695 + int count)
19.696 +{
19.697 + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
19.698 + int i;
19.699 + StartDrawing(renderer);
19.700 +
19.701 + for (i = 0; i < count; ++i) {
19.702 + const SDL_FRect *rect = &rects[i];
19.703 + VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1));
19.704 + vertices[0].x = rect->x;
19.705 + vertices[0].y = rect->y;
19.706 + vertices[0].z = 0.0f;
19.707 +
19.708 + vertices[1].x = rect->x + rect->w;
19.709 + vertices[1].y = rect->y + rect->h;
19.710 + vertices[1].z = 0.0f;
19.711 +
19.712 + sceGuDisable(GU_TEXTURE_2D);
19.713 + sceGuColor(color);
19.714 + sceGuShadeModel(GU_FLAT);
19.715 + sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
19.716 + sceGuShadeModel(GU_SMOOTH);
19.717 + sceGuEnable(GU_TEXTURE_2D);
19.718 + }
19.719 +
19.720 + return 0;
19.721 +}
19.722 +
19.723 +
19.724 +#define PI 3.14159265358979f
19.725 +
19.726 +#define radToDeg(x) ((x)*180.f/PI)
19.727 +#define degToRad(x) ((x)*PI/180.f)
19.728 +
19.729 +float MathAbs(float x)
19.730 +{
19.731 + float result;
19.732 +
19.733 + __asm__ volatile (
19.734 + "mtv %1, S000\n"
19.735 + "vabs.s S000, S000\n"
19.736 + "mfv %0, S000\n"
19.737 + : "=r"(result) : "r"(x));
19.738 +
19.739 + return result;
19.740 +}
19.741 +
19.742 +void MathSincos(float r, float *s, float *c)
19.743 +{
19.744 + __asm__ volatile (
19.745 + "mtv %2, S002\n"
19.746 + "vcst.s S003, VFPU_2_PI\n"
19.747 + "vmul.s S002, S002, S003\n"
19.748 + "vrot.p C000, S002, [s, c]\n"
19.749 + "mfv %0, S000\n"
19.750 + "mfv %1, S001\n"
19.751 + : "=r"(*s), "=r"(*c): "r"(r));
19.752 +}
19.753 +
19.754 +void Swap(float *a, float *b)
19.755 +{
19.756 + float n=*a;
19.757 + *a = *b;
19.758 + *b = n;
19.759 +}
19.760 +
19.761 +static int
19.762 +PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
19.763 + const SDL_Rect * srcrect, const SDL_FRect * dstrect)
19.764 +{
19.765 + float x, y, width, height;
19.766 + float u0, v0, u1, v1;
19.767 + unsigned char alpha;
19.768 +
19.769 + x = dstrect->x;
19.770 + y = dstrect->y;
19.771 + width = dstrect->w;
19.772 + height = dstrect->h;
19.773 +
19.774 + u0 = srcrect->x;
19.775 + v0 = srcrect->y;
19.776 + u1 = srcrect->x + srcrect->w;
19.777 + v1 = srcrect->y + srcrect->h;
19.778 +
19.779 + alpha = texture->a;
19.780 +
19.781 + StartDrawing(renderer);
19.782 + TextureActivate(texture);
19.783 + PSP_SetBlendMode(renderer, renderer->blendMode);
19.784 +
19.785 + if(alpha != 255)
19.786 + {
19.787 + sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
19.788 + sceGuColor(GU_RGBA(255, 255, 255, alpha));
19.789 + }else{
19.790 + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
19.791 + sceGuColor(0xFFFFFFFF);
19.792 + }
19.793 +
19.794 + if((MathAbs(u1) - MathAbs(u0)) < 64.0f)
19.795 + {
19.796 + VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
19.797 +
19.798 + vertices[0].u = u0;
19.799 + vertices[0].v = v0;
19.800 + vertices[0].x = x;
19.801 + vertices[0].y = y;
19.802 + vertices[0].z = 0;
19.803 +
19.804 + vertices[1].u = u1;
19.805 + vertices[1].v = v1;
19.806 + vertices[1].x = x + width;
19.807 + vertices[1].y = y + height;
19.808 + vertices[1].z = 0;
19.809 +
19.810 + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
19.811 + }
19.812 + else
19.813 + {
19.814 + float start, end;
19.815 + float curU = u0;
19.816 + float curX = x;
19.817 + float endX = x + width;
19.818 + float slice = 64.0f;
19.819 + float ustep = (u1 - u0)/width * slice;
19.820 +
19.821 + if(ustep < 0.0f)
19.822 + ustep = -ustep;
19.823 +
19.824 + for(start = 0, end = width; start < end; start += slice)
19.825 + {
19.826 + VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
19.827 +
19.828 + float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
19.829 + float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
19.830 +
19.831 + vertices[0].u = curU;
19.832 + vertices[0].v = v0;
19.833 + vertices[0].x = curX;
19.834 + vertices[0].y = y;
19.835 + vertices[0].z = 0;
19.836 +
19.837 + curU += sourceWidth;
19.838 + curX += polyWidth;
19.839 +
19.840 + vertices[1].u = curU;
19.841 + vertices[1].v = v1;
19.842 + vertices[1].x = curX;
19.843 + vertices[1].y = (y + height);
19.844 + vertices[1].z = 0;
19.845 +
19.846 + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
19.847 + }
19.848 + }
19.849 +
19.850 + if(alpha != 255)
19.851 + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
19.852 + return 0;
19.853 +}
19.854 +
19.855 +static int
19.856 +PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
19.857 + Uint32 pixel_format, void * pixels, int pitch)
19.858 +
19.859 +{
19.860 + return 0;
19.861 +}
19.862 +
19.863 +
19.864 +static int
19.865 +PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
19.866 + const SDL_Rect * srcrect, const SDL_FRect * dstrect,
19.867 + const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
19.868 +{
19.869 + float x, y, width, height;
19.870 + float u0, v0, u1, v1;
19.871 + unsigned char alpha;
19.872 + float centerx, centery;
19.873 +
19.874 + x = dstrect->x;
19.875 + y = dstrect->y;
19.876 + width = dstrect->w;
19.877 + height = dstrect->h;
19.878 +
19.879 + u0 = srcrect->x;
19.880 + v0 = srcrect->y;
19.881 + u1 = srcrect->x + srcrect->w;
19.882 + v1 = srcrect->y + srcrect->h;
19.883 +
19.884 + centerx = center->x;
19.885 + centery = center->y;
19.886 +
19.887 + alpha = texture->a;
19.888 +
19.889 + StartDrawing(renderer);
19.890 + TextureActivate(texture);
19.891 + PSP_SetBlendMode(renderer, renderer->blendMode);
19.892 +
19.893 + if(alpha != 255)
19.894 + {
19.895 + sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
19.896 + sceGuColor(GU_RGBA(255, 255, 255, alpha));
19.897 + }else{
19.898 + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
19.899 + sceGuColor(0xFFFFFFFF);
19.900 + }
19.901 +
19.902 +// x += width * 0.5f;
19.903 +// y += height * 0.5f;
19.904 + x += centerx;
19.905 + y += centery;
19.906 +
19.907 + float c, s;
19.908 +
19.909 + MathSincos(degToRad(angle), &s, &c);
19.910 +
19.911 +// width *= 0.5f;
19.912 +// height *= 0.5f;
19.913 + width -= centerx;
19.914 + height -= centery;
19.915 +
19.916 +
19.917 + float cw = c*width;
19.918 + float sw = s*width;
19.919 + float ch = c*height;
19.920 + float sh = s*height;
19.921 +
19.922 + VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
19.923 +
19.924 + vertices[0].u = u0;
19.925 + vertices[0].v = v0;
19.926 + vertices[0].x = x - cw + sh;
19.927 + vertices[0].y = y - sw - ch;
19.928 + vertices[0].z = 0;
19.929 +
19.930 + vertices[1].u = u0;
19.931 + vertices[1].v = v1;
19.932 + vertices[1].x = x - cw - sh;
19.933 + vertices[1].y = y - sw + ch;
19.934 + vertices[1].z = 0;
19.935 +
19.936 + vertices[2].u = u1;
19.937 + vertices[2].v = v1;
19.938 + vertices[2].x = x + cw - sh;
19.939 + vertices[2].y = y + sw + ch;
19.940 + vertices[2].z = 0;
19.941 +
19.942 + vertices[3].u = u1;
19.943 + vertices[3].v = v0;
19.944 + vertices[3].x = x + cw + sh;
19.945 + vertices[3].y = y + sw - ch;
19.946 + vertices[3].z = 0;
19.947 +
19.948 + if (flip & SDL_FLIP_HORIZONTAL) {
19.949 + Swap(&vertices[0].v, &vertices[2].v);
19.950 + Swap(&vertices[1].v, &vertices[3].v);
19.951 + }
19.952 + if (flip & SDL_FLIP_VERTICAL) {
19.953 + Swap(&vertices[0].u, &vertices[2].u);
19.954 + Swap(&vertices[1].u, &vertices[3].u);
19.955 + }
19.956 +
19.957 + sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
19.958 +
19.959 + if(alpha != 255)
19.960 + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
19.961 + return 0;
19.962 +}
19.963 +
19.964 +static void
19.965 +PSP_RenderPresent(SDL_Renderer * renderer)
19.966 +{
19.967 + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
19.968 + if(!data->displayListAvail)
19.969 + return;
19.970 +
19.971 + data->displayListAvail = SDL_FALSE;
19.972 + sceGuFinish();
19.973 + sceGuSync(0,0);
19.974 +
19.975 +// if(data->vsync)
19.976 + sceDisplayWaitVblankStart();
19.977 +
19.978 + data->backbuffer = data->frontbuffer;
19.979 + data->frontbuffer = vabsptr(sceGuSwapBuffers());
19.980 +
19.981 +}
19.982 +
19.983 +static void
19.984 +PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
19.985 +{
19.986 + PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
19.987 + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
19.988 +
19.989 + if (renderdata == 0)
19.990 + return;
19.991 +
19.992 + if(psp_texture == 0)
19.993 + return;
19.994 +
19.995 + if(psp_texture->data != 0)
19.996 + {
19.997 + free(psp_texture->data);
19.998 + }
19.999 + free(texture);
19.1000 + texture->driverdata = NULL;
19.1001 +}
19.1002 +
19.1003 +static void
19.1004 +PSP_DestroyRenderer(SDL_Renderer * renderer)
19.1005 +{
19.1006 + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
19.1007 + if (data) {
19.1008 + if (!data->initialized)
19.1009 + return;
19.1010 +
19.1011 + StartDrawing(renderer);
19.1012 +
19.1013 + sceGuTerm();
19.1014 +// vfree(data->backbuffer);
19.1015 +// vfree(data->frontbuffer);
19.1016 +
19.1017 + data->initialized = SDL_FALSE;
19.1018 + data->displayListAvail = SDL_FALSE;
19.1019 + SDL_free(data);
19.1020 + }
19.1021 + SDL_free(renderer);
19.1022 +}
19.1023 +
19.1024 +#endif /* SDL_VIDEO_RENDER_PSP */
19.1025 +
19.1026 +/* vi: set ts=4 sw=4 expandtab: */
19.1027 +
20.1 --- a/src/thread/SDL_thread_c.h Sat Mar 16 11:00:04 2013 -0700
20.2 +++ b/src/thread/SDL_thread_c.h Sun Mar 17 20:07:02 2013 +0800
20.3 @@ -36,6 +36,8 @@
20.4 #include "windows/SDL_systhread_c.h"
20.5 #elif SDL_THREAD_NDS
20.6 #include "nds/SDL_systhread_c.h"
20.7 +#elif SDL_THREAD_PSP
20.8 +#include "psp/SDL_systhread_c.h"
20.9 #else
20.10 #error Need thread implementation for this platform
20.11 #include "generic/SDL_systhread_c.h"
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/src/thread/psp/SDL_syscond.c Sun Mar 17 20:07:02 2013 +0800
21.3 @@ -0,0 +1,223 @@
21.4 +/*
21.5 + Simple DirectMedia Layer
21.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
21.7 +
21.8 + This software is provided 'as-is', without any express or implied
21.9 + warranty. In no event will the authors be held liable for any damages
21.10 + arising from the use of this software.
21.11 +
21.12 + Permission is granted to anyone to use this software for any purpose,
21.13 + including commercial applications, and to alter it and redistribute it
21.14 + freely, subject to the following restrictions:
21.15 +
21.16 + 1. The origin of this software must not be misrepresented; you must not
21.17 + claim that you wrote the original software. If you use this software
21.18 + in a product, an acknowledgment in the product documentation would be
21.19 + appreciated but is not required.
21.20 + 2. Altered source versions must be plainly marked as such, and must not be
21.21 + misrepresented as being the original software.
21.22 + 3. This notice may not be removed or altered from any source distribution.
21.23 +*/
21.24 +#include "SDL_config.h"
21.25 +
21.26 +/* An implementation of condition variables using semaphores and mutexes */
21.27 +/*
21.28 + This implementation borrows heavily from the BeOS condition variable
21.29 + implementation, written by Christopher Tate and Owen Smith. Thanks!
21.30 + */
21.31 +
21.32 +#include "SDL_thread.h"
21.33 +
21.34 +struct SDL_cond
21.35 +{
21.36 + SDL_mutex *lock;
21.37 + int waiting;
21.38 + int signals;
21.39 + SDL_sem *wait_sem;
21.40 + SDL_sem *wait_done;
21.41 +};
21.42 +
21.43 +/* Create a condition variable */
21.44 +SDL_cond *
21.45 +SDL_CreateCond(void)
21.46 +{
21.47 + SDL_cond *cond;
21.48 +
21.49 + cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
21.50 + if (cond) {
21.51 + cond->lock = SDL_CreateMutex();
21.52 + cond->wait_sem = SDL_CreateSemaphore(0);
21.53 + cond->wait_done = SDL_CreateSemaphore(0);
21.54 + cond->waiting = cond->signals = 0;
21.55 + if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
21.56 + SDL_DestroyCond(cond);
21.57 + cond = NULL;
21.58 + }
21.59 + } else {
21.60 + SDL_OutOfMemory();
21.61 + }
21.62 + return (cond);
21.63 +}
21.64 +
21.65 +/* Destroy a condition variable */
21.66 +void
21.67 +SDL_DestroyCond(SDL_cond * cond)
21.68 +{
21.69 + if (cond) {
21.70 + if (cond->wait_sem) {
21.71 + SDL_DestroySemaphore(cond->wait_sem);
21.72 + }
21.73 + if (cond->wait_done) {
21.74 + SDL_DestroySemaphore(cond->wait_done);
21.75 + }
21.76 + if (cond->lock) {
21.77 + SDL_DestroyMutex(cond->lock);
21.78 + }
21.79 + SDL_free(cond);
21.80 + }
21.81 +}
21.82 +
21.83 +/* Restart one of the threads that are waiting on the condition variable */
21.84 +int
21.85 +SDL_CondSignal(SDL_cond * cond)
21.86 +{
21.87 + if (!cond) {
21.88 + SDL_SetError("Passed a NULL condition variable");
21.89 + return -1;
21.90 + }
21.91 +
21.92 + /* If there are waiting threads not already signalled, then
21.93 + signal the condition and wait for the thread to respond.
21.94 + */
21.95 + SDL_LockMutex(cond->lock);
21.96 + if (cond->waiting > cond->signals) {
21.97 + ++cond->signals;
21.98 + SDL_SemPost(cond->wait_sem);
21.99 + SDL_UnlockMutex(cond->lock);
21.100 + SDL_SemWait(cond->wait_done);
21.101 + } else {
21.102 + SDL_UnlockMutex(cond->lock);
21.103 + }
21.104 +
21.105 + return 0;
21.106 +}
21.107 +
21.108 +/* Restart all threads that are waiting on the condition variable */
21.109 +int
21.110 +SDL_CondBroadcast(SDL_cond * cond)
21.111 +{
21.112 + if (!cond) {
21.113 + SDL_SetError("Passed a NULL condition variable");
21.114 + return -1;
21.115 + }
21.116 +
21.117 + /* If there are waiting threads not already signalled, then
21.118 + signal the condition and wait for the thread to respond.
21.119 + */
21.120 + SDL_LockMutex(cond->lock);
21.121 + if (cond->waiting > cond->signals) {
21.122 + int i, num_waiting;
21.123 +
21.124 + num_waiting = (cond->waiting - cond->signals);
21.125 + cond->signals = cond->waiting;
21.126 + for (i = 0; i < num_waiting; ++i) {
21.127 + SDL_SemPost(cond->wait_sem);
21.128 + }
21.129 + /* Now all released threads are blocked here, waiting for us.
21.130 + Collect them all (and win fabulous prizes!) :-)
21.131 + */
21.132 + SDL_UnlockMutex(cond->lock);
21.133 + for (i = 0; i < num_waiting; ++i) {
21.134 + SDL_SemWait(cond->wait_done);
21.135 + }
21.136 + } else {
21.137 + SDL_UnlockMutex(cond->lock);
21.138 + }
21.139 +
21.140 + return 0;
21.141 +}
21.142 +
21.143 +/* Wait on the condition variable for at most 'ms' milliseconds.
21.144 + The mutex must be locked before entering this function!
21.145 + The mutex is unlocked during the wait, and locked again after the wait.
21.146 +
21.147 +Typical use:
21.148 +
21.149 +Thread A:
21.150 + SDL_LockMutex(lock);
21.151 + while ( ! condition ) {
21.152 + SDL_CondWait(cond, lock);
21.153 + }
21.154 + SDL_UnlockMutex(lock);
21.155 +
21.156 +Thread B:
21.157 + SDL_LockMutex(lock);
21.158 + ...
21.159 + condition = true;
21.160 + ...
21.161 + SDL_CondSignal(cond);
21.162 + SDL_UnlockMutex(lock);
21.163 + */
21.164 +int
21.165 +SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
21.166 +{
21.167 + int retval;
21.168 +
21.169 + if (!cond) {
21.170 + SDL_SetError("Passed a NULL condition variable");
21.171 + return -1;
21.172 + }
21.173 +
21.174 + /* Obtain the protection mutex, and increment the number of waiters.
21.175 + This allows the signal mechanism to only perform a signal if there
21.176 + are waiting threads.
21.177 + */
21.178 + SDL_LockMutex(cond->lock);
21.179 + ++cond->waiting;
21.180 + SDL_UnlockMutex(cond->lock);
21.181 +
21.182 + /* Unlock the mutex, as is required by condition variable semantics */
21.183 + SDL_UnlockMutex(mutex);
21.184 +
21.185 + /* Wait for a signal */
21.186 + if (ms == SDL_MUTEX_MAXWAIT) {
21.187 + retval = SDL_SemWait(cond->wait_sem);
21.188 + } else {
21.189 + retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
21.190 + }
21.191 +
21.192 + /* Let the signaler know we have completed the wait, otherwise
21.193 + the signaler can race ahead and get the condition semaphore
21.194 + if we are stopped between the mutex unlock and semaphore wait,
21.195 + giving a deadlock. See the following URL for details:
21.196 + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
21.197 + */
21.198 + SDL_LockMutex(cond->lock);
21.199 + if (cond->signals > 0) {
21.200 + /* If we timed out, we need to eat a condition signal */
21.201 + if (retval > 0) {
21.202 + SDL_SemWait(cond->wait_sem);
21.203 + }
21.204 + /* We always notify the signal thread that we are done */
21.205 + SDL_SemPost(cond->wait_done);
21.206 +
21.207 + /* Signal handshake complete */
21.208 + --cond->signals;
21.209 + }
21.210 + --cond->waiting;
21.211 + SDL_UnlockMutex(cond->lock);
21.212 +
21.213 + /* Lock the mutex, as is required by condition variable semantics */
21.214 + SDL_LockMutex(mutex);
21.215 +
21.216 + return retval;
21.217 +}
21.218 +
21.219 +/* Wait on the condition variable forever */
21.220 +int
21.221 +SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
21.222 +{
21.223 + return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
21.224 +}
21.225 +
21.226 +/* vi: set ts=4 sw=4 expandtab: */
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/src/thread/psp/SDL_sysmutex.c Sun Mar 17 20:07:02 2013 +0800
22.3 @@ -0,0 +1,135 @@
22.4 +/*
22.5 + Simple DirectMedia Layer
22.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
22.7 +
22.8 + This software is provided 'as-is', without any express or implied
22.9 + warranty. In no event will the authors be held liable for any damages
22.10 + arising from the use of this software.
22.11 +
22.12 + Permission is granted to anyone to use this software for any purpose,
22.13 + including commercial applications, and to alter it and redistribute it
22.14 + freely, subject to the following restrictions:
22.15 +
22.16 + 1. The origin of this software must not be misrepresented; you must not
22.17 + claim that you wrote the original software. If you use this software
22.18 + in a product, an acknowledgment in the product documentation would be
22.19 + appreciated but is not required.
22.20 + 2. Altered source versions must be plainly marked as such, and must not be
22.21 + misrepresented as being the original software.
22.22 + 3. This notice may not be removed or altered from any source distribution.
22.23 +*/
22.24 +#include "SDL_config.h"
22.25 +
22.26 +/* An implementation of mutexes using semaphores */
22.27 +
22.28 +#include "SDL_thread.h"
22.29 +#include "SDL_systhread_c.h"
22.30 +
22.31 +
22.32 +struct SDL_mutex
22.33 +{
22.34 + int recursive;
22.35 + SDL_threadID owner;
22.36 + SDL_sem *sem;
22.37 +};
22.38 +
22.39 +/* Create a mutex */
22.40 +SDL_mutex *
22.41 +SDL_CreateMutex(void)
22.42 +{
22.43 + SDL_mutex *mutex;
22.44 +
22.45 + /* Allocate mutex memory */
22.46 + mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
22.47 + if (mutex) {
22.48 + /* Create the mutex semaphore, with initial value 1 */
22.49 + mutex->sem = SDL_CreateSemaphore(1);
22.50 + mutex->recursive = 0;
22.51 + mutex->owner = 0;
22.52 + if (!mutex->sem) {
22.53 + SDL_free(mutex);
22.54 + mutex = NULL;
22.55 + }
22.56 + } else {
22.57 + SDL_OutOfMemory();
22.58 + }
22.59 + return mutex;
22.60 +}
22.61 +
22.62 +/* Free the mutex */
22.63 +void
22.64 +SDL_DestroyMutex(SDL_mutex * mutex)
22.65 +{
22.66 + if (mutex) {
22.67 + if (mutex->sem) {
22.68 + SDL_DestroySemaphore(mutex->sem);
22.69 + }
22.70 + SDL_free(mutex);
22.71 + }
22.72 +}
22.73 +
22.74 +/* Lock the semaphore */
22.75 +int
22.76 +SDL_mutexP(SDL_mutex * mutex)
22.77 +{
22.78 +#if SDL_THREADS_DISABLED
22.79 + return 0;
22.80 +#else
22.81 + SDL_threadID this_thread;
22.82 +
22.83 + if (mutex == NULL) {
22.84 + SDL_SetError("Passed a NULL mutex");
22.85 + return -1;
22.86 + }
22.87 +
22.88 + this_thread = SDL_ThreadID();
22.89 + if (mutex->owner == this_thread) {
22.90 + ++mutex->recursive;
22.91 + } else {
22.92 + /* The order of operations is important.
22.93 + We set the locking thread id after we obtain the lock
22.94 + so unlocks from other threads will fail.
22.95 + */
22.96 + SDL_SemWait(mutex->sem);
22.97 + mutex->owner = this_thread;
22.98 + mutex->recursive = 0;
22.99 + }
22.100 +
22.101 + return 0;
22.102 +#endif /* SDL_THREADS_DISABLED */
22.103 +}
22.104 +
22.105 +/* Unlock the mutex */
22.106 +int
22.107 +SDL_mutexV(SDL_mutex * mutex)
22.108 +{
22.109 +#if SDL_THREADS_DISABLED
22.110 + return 0;
22.111 +#else
22.112 + if (mutex == NULL) {
22.113 + SDL_SetError("Passed a NULL mutex");
22.114 + return -1;
22.115 + }
22.116 +
22.117 + /* If we don't own the mutex, we can't unlock it */
22.118 + if (SDL_ThreadID() != mutex->owner) {
22.119 + SDL_SetError("mutex not owned by this thread");
22.120 + return -1;
22.121 + }
22.122 +
22.123 + if (mutex->recursive) {
22.124 + --mutex->recursive;
22.125 + } else {
22.126 + /* The order of operations is important.
22.127 + First reset the owner so another thread doesn't lock
22.128 + the mutex and set the ownership before we reset it,
22.129 + then release the lock semaphore.
22.130 + */
22.131 + mutex->owner = 0;
22.132 + SDL_SemPost(mutex->sem);
22.133 + }
22.134 + return 0;
22.135 +#endif /* SDL_THREADS_DISABLED */
22.136 +}
22.137 +
22.138 +/* vi: set ts=4 sw=4 expandtab: */
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/src/thread/psp/SDL_sysmutex_c.h Sun Mar 17 20:07:02 2013 +0800
23.3 @@ -0,0 +1,22 @@
23.4 +/*
23.5 + Simple DirectMedia Layer
23.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
23.7 +
23.8 + This software is provided 'as-is', without any express or implied
23.9 + warranty. In no event will the authors be held liable for any damages
23.10 + arising from the use of this software.
23.11 +
23.12 + Permission is granted to anyone to use this software for any purpose,
23.13 + including commercial applications, and to alter it and redistribute it
23.14 + freely, subject to the following restrictions:
23.15 +
23.16 + 1. The origin of this software must not be misrepresented; you must not
23.17 + claim that you wrote the original software. If you use this software
23.18 + in a product, an acknowledgment in the product documentation would be
23.19 + appreciated but is not required.
23.20 + 2. Altered source versions must be plainly marked as such, and must not be
23.21 + misrepresented as being the original software.
23.22 + 3. This notice may not be removed or altered from any source distribution.
23.23 +*/
23.24 +#include "SDL_config.h"
23.25 +/* vi: set ts=4 sw=4 expandtab: */
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
24.2 +++ b/src/thread/psp/SDL_syssem.c Sun Mar 17 20:07:02 2013 +0800
24.3 @@ -0,0 +1,159 @@
24.4 +/*
24.5 + Simple DirectMedia Layer
24.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
24.7 +
24.8 + This software is provided 'as-is', without any express or implied
24.9 + warranty. In no event will the authors be held liable for any damages
24.10 + arising from the use of this software.
24.11 +
24.12 + Permission is granted to anyone to use this software for any purpose,
24.13 + including commercial applications, and to alter it and redistribute it
24.14 + freely, subject to the following restrictions:
24.15 +
24.16 + 1. The origin of this software must not be misrepresented; you must not
24.17 + claim that you wrote the original software. If you use this software
24.18 + in a product, an acknowledgment in the product documentation would be
24.19 + appreciated but is not required.
24.20 + 2. Altered source versions must be plainly marked as such, and must not be
24.21 + misrepresented as being the original software.
24.22 + 3. This notice may not be removed or altered from any source distribution.
24.23 +*/
24.24 +
24.25 +/* Semaphore functions for the PSP. */
24.26 +
24.27 +#include <stdio.h>
24.28 +#include <stdlib.h>
24.29 +
24.30 +#include "SDL_error.h"
24.31 +#include "SDL_thread.h"
24.32 +
24.33 +#include <pspthreadman.h>
24.34 +#include <pspkerror.h>
24.35 +
24.36 +struct SDL_semaphore {
24.37 + SceUID semid;
24.38 +};
24.39 +
24.40 +
24.41 +/* Create a semaphore */
24.42 +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
24.43 +{
24.44 + SDL_sem *sem;
24.45 +
24.46 + sem = (SDL_sem *) malloc(sizeof(*sem));
24.47 + if (sem != NULL) {
24.48 + /* TODO: Figure out the limit on the maximum value. */
24.49 + sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
24.50 + if (sem->semid < 0) {
24.51 + SDL_SetError("Couldn't create semaphore");
24.52 + free(sem);
24.53 + sem = NULL;
24.54 + }
24.55 + } else {
24.56 + SDL_OutOfMemory();
24.57 + }
24.58 +
24.59 + return sem;
24.60 +}
24.61 +
24.62 +/* Free the semaphore */
24.63 +void SDL_DestroySemaphore(SDL_sem *sem)
24.64 +{
24.65 + if (sem != NULL) {
24.66 + if (sem->semid > 0) {
24.67 + sceKernelDeleteSema(sem->semid);
24.68 + sem->semid = 0;
24.69 + }
24.70 +
24.71 + free(sem);
24.72 + }
24.73 +}
24.74 +
24.75 +/* TODO: This routine is a bit overloaded.
24.76 + * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass
24.77 + * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout
24.78 + * is specified, convert it to microseconds. */
24.79 +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
24.80 +{
24.81 + Uint32 *pTimeout;
24.82 + unsigned int res;
24.83 +
24.84 + if (sem == NULL) {
24.85 + SDL_SetError("Passed a NULL sem");
24.86 + return 0;
24.87 + }
24.88 +
24.89 + if (timeout == 0) {
24.90 + res = sceKernelPollSema(sem->semid, 1);
24.91 + if (res < 0) {
24.92 + return SDL_MUTEX_TIMEDOUT;
24.93 + }
24.94 + return 0;
24.95 + }
24.96 +
24.97 + if (timeout == SDL_MUTEX_MAXWAIT) {
24.98 + pTimeout = NULL;
24.99 + } else {
24.100 + timeout *= 1000; /* Convert to microseconds. */
24.101 + pTimeout = &timeout;
24.102 + }
24.103 +
24.104 + res = sceKernelWaitSema(sem->semid, 1, pTimeout);
24.105 + switch (res) {
24.106 + case SCE_KERNEL_ERROR_OK:
24.107 + return 0;
24.108 + case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
24.109 + return SDL_MUTEX_TIMEDOUT;
24.110 + default:
24.111 + SDL_SetError("WaitForSingleObject() failed");
24.112 + return -1;
24.113 + }
24.114 +}
24.115 +
24.116 +int SDL_SemTryWait(SDL_sem *sem)
24.117 +{
24.118 + return SDL_SemWaitTimeout(sem, 0);
24.119 +}
24.120 +
24.121 +int SDL_SemWait(SDL_sem *sem)
24.122 +{
24.123 + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
24.124 +}
24.125 +
24.126 +/* Returns the current count of the semaphore */
24.127 +Uint32 SDL_SemValue(SDL_sem *sem)
24.128 +{
24.129 + SceKernelSemaInfo info;
24.130 +
24.131 + if (sem == NULL) {
24.132 + SDL_SetError("Passed a NULL sem");
24.133 + return 0;
24.134 + }
24.135 +
24.136 + if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) {
24.137 + return info.currentCount;
24.138 + }
24.139 +
24.140 + return 0;
24.141 +}
24.142 +
24.143 +int SDL_SemPost(SDL_sem *sem)
24.144 +{
24.145 + int res;
24.146 +
24.147 + if (sem == NULL) {
24.148 + SDL_SetError("Passed a NULL sem");
24.149 + return -1;
24.150 + }
24.151 +
24.152 + res = sceKernelSignalSema(sem->semid, 1);
24.153 + if (res < 0) {
24.154 + SDL_SetError("sceKernelSignalSema() failed");
24.155 + return -1;
24.156 + }
24.157 +
24.158 + return 0;
24.159 +}
24.160 +
24.161 +/* vim: ts=4 sw=4
24.162 + */
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/src/thread/psp/SDL_systhread.c Sun Mar 17 20:07:02 2013 +0800
25.3 @@ -0,0 +1,103 @@
25.4 +/*
25.5 + Simple DirectMedia Layer
25.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
25.7 +
25.8 + This software is provided 'as-is', without any express or implied
25.9 + warranty. In no event will the authors be held liable for any damages
25.10 + arising from the use of this software.
25.11 +
25.12 + Permission is granted to anyone to use this software for any purpose,
25.13 + including commercial applications, and to alter it and redistribute it
25.14 + freely, subject to the following restrictions:
25.15 +
25.16 + 1. The origin of this software must not be misrepresented; you must not
25.17 + claim that you wrote the original software. If you use this software
25.18 + in a product, an acknowledgment in the product documentation would be
25.19 + appreciated but is not required.
25.20 + 2. Altered source versions must be plainly marked as such, and must not be
25.21 + misrepresented as being the original software.
25.22 + 3. This notice may not be removed or altered from any source distribution.
25.23 +*/
25.24 +
25.25 +
25.26 +/* PSP thread management routines for SDL */
25.27 +
25.28 +#include <stdio.h>
25.29 +#include <stdlib.h>
25.30 +
25.31 +#include "SDL_error.h"
25.32 +#include "SDL_thread.h"
25.33 +#include "../SDL_systhread.h"
25.34 +#include "../SDL_thread_c.h"
25.35 +#include <pspkerneltypes.h>
25.36 +#include <pspthreadman.h>
25.37 +
25.38 +
25.39 +static int ThreadEntry(SceSize args, void *argp)
25.40 +{
25.41 + SDL_RunThread(*(void **) argp);
25.42 + return 0;
25.43 +}
25.44 +
25.45 +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
25.46 +{
25.47 + SceKernelThreadInfo status;
25.48 + int priority = 32;
25.49 +
25.50 + /* Set priority of new thread to the same as the current thread */
25.51 + status.size = sizeof(SceKernelThreadInfo);
25.52 + if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
25.53 + priority = status.currentPriority;
25.54 + }
25.55 +
25.56 + thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
25.57 + priority, 0x8000,
25.58 + PSP_THREAD_ATTR_VFPU, NULL);
25.59 + if (thread->handle < 0) {
25.60 + SDL_SetError("sceKernelCreateThread() failed");
25.61 + return -1;
25.62 + }
25.63 +
25.64 + sceKernelStartThread(thread->handle, 4, &args);
25.65 + return 0;
25.66 +}
25.67 +
25.68 +void SDL_SYS_SetupThread(const char *name)
25.69 +{
25.70 + /* Do nothing. */
25.71 +}
25.72 +
25.73 +SDL_threadID SDL_ThreadID(void)
25.74 +{
25.75 + return (SDL_threadID) sceKernelGetThreadId();
25.76 +}
25.77 +
25.78 +void SDL_SYS_WaitThread(SDL_Thread *thread)
25.79 +{
25.80 + sceKernelWaitThreadEnd(thread->handle, NULL);
25.81 + sceKernelDeleteThread(thread->handle);
25.82 +}
25.83 +
25.84 +void SDL_SYS_KillThread(SDL_Thread *thread)
25.85 +{
25.86 + sceKernelTerminateDeleteThread(thread->handle);
25.87 +}
25.88 +
25.89 +int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
25.90 +{
25.91 + int value;
25.92 +
25.93 + if (priority == SDL_THREAD_PRIORITY_LOW) {
25.94 + value = 19;
25.95 + } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
25.96 + value = -20;
25.97 + } else {
25.98 + value = 0;
25.99 + }
25.100 +
25.101 + return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
25.102 +
25.103 +}
25.104 +
25.105 +/* vim: ts=4 sw=4
25.106 + */
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/src/thread/psp/SDL_systhread_c.h Sun Mar 17 20:07:02 2013 +0800
26.3 @@ -0,0 +1,24 @@
26.4 +/*
26.5 + Simple DirectMedia Layer
26.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
26.7 +
26.8 + This software is provided 'as-is', without any express or implied
26.9 + warranty. In no event will the authors be held liable for any damages
26.10 + arising from the use of this software.
26.11 +
26.12 + Permission is granted to anyone to use this software for any purpose,
26.13 + including commercial applications, and to alter it and redistribute it
26.14 + freely, subject to the following restrictions:
26.15 +
26.16 + 1. The origin of this software must not be misrepresented; you must not
26.17 + claim that you wrote the original software. If you use this software
26.18 + in a product, an acknowledgment in the product documentation would be
26.19 + appreciated but is not required.
26.20 + 2. Altered source versions must be plainly marked as such, and must not be
26.21 + misrepresented as being the original software.
26.22 + 3. This notice may not be removed or altered from any source distribution.
26.23 +*/
26.24 +
26.25 +#include <pspkerneltypes.h>
26.26 +
26.27 +typedef SceUID SYS_ThreadHandle;
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/src/timer/psp/SDL_systimer.c Sun Mar 17 20:07:02 2013 +0800
27.3 @@ -0,0 +1,69 @@
27.4 +/*
27.5 + Simple DirectMedia Layer
27.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
27.7 +
27.8 + This software is provided 'as-is', without any express or implied
27.9 + warranty. In no event will the authors be held liable for any damages
27.10 + arising from the use of this software.
27.11 +
27.12 + Permission is granted to anyone to use this software for any purpose,
27.13 + including commercial applications, and to alter it and redistribute it
27.14 + freely, subject to the following restrictions:
27.15 +
27.16 + 1. The origin of this software must not be misrepresented; you must not
27.17 + claim that you wrote the original software. If you use this software
27.18 + in a product, an acknowledgment in the product documentation would be
27.19 + appreciated but is not required.
27.20 + 2. Altered source versions must be plainly marked as such, and must not be
27.21 + misrepresented as being the original software.
27.22 + 3. This notice may not be removed or altered from any source distribution.
27.23 +*/
27.24 +
27.25 +#include "SDL_thread.h"
27.26 +#include "SDL_timer.h"
27.27 +#include "SDL_error.h"
27.28 +#include "../SDL_timer_c.h"
27.29 +#include <stdlib.h>
27.30 +#include <time.h>
27.31 +#include <sys/time.h>
27.32 +#include <pspthreadman.h>
27.33 +
27.34 +static struct timeval start;
27.35 +
27.36 +void SDL_StartTicks(void)
27.37 +{
27.38 + gettimeofday(&start, NULL);
27.39 +}
27.40 +
27.41 +Uint32 SDL_GetTicks(void)
27.42 +{
27.43 + struct timeval now;
27.44 + Uint32 ticks;
27.45 +
27.46 + gettimeofday(&now, NULL);
27.47 + ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
27.48 + return(ticks);
27.49 +}
27.50 +
27.51 +Uint64
27.52 +SDL_GetPerformanceCounter(void)
27.53 +{
27.54 + return SDL_GetTicks();
27.55 +}
27.56 +
27.57 +Uint64
27.58 +SDL_GetPerformanceFrequency(void)
27.59 +{
27.60 + return 1000;
27.61 +}
27.62 +
27.63 +void SDL_Delay(Uint32 ms)
27.64 +{
27.65 + const Uint32 max_delay = 0xffffffffUL / 1000;
27.66 + if(ms > max_delay)
27.67 + ms = max_delay;
27.68 + sceKernelDelayThreadCB(ms * 1000);
27.69 +}
27.70 +
27.71 +/* vim: ts=4 sw=4
27.72 + */
28.1 --- a/src/video/SDL_sysvideo.h Sat Mar 16 11:00:04 2013 -0700
28.2 +++ b/src/video/SDL_sysvideo.h Sun Mar 17 20:07:02 2013 +0800
28.3 @@ -350,6 +350,9 @@
28.4 #if SDL_VIDEO_DRIVER_ANDROID
28.5 extern VideoBootStrap Android_bootstrap;
28.6 #endif
28.7 +#if SDL_VIDEO_DRIVER_PSP
28.8 +extern VideoBootStrap PSP_bootstrap;
28.9 +#endif
28.10 #if SDL_VIDEO_DRIVER_DUMMY
28.11 extern VideoBootStrap DUMMY_bootstrap;
28.12 #endif
29.1 --- a/src/video/SDL_video.c Sat Mar 16 11:00:04 2013 -0700
29.2 +++ b/src/video/SDL_video.c Sun Mar 17 20:07:02 2013 +0800
29.3 @@ -78,6 +78,9 @@
29.4 #if SDL_VIDEO_DRIVER_ANDROID
29.5 &Android_bootstrap,
29.6 #endif
29.7 +#if SDL_VIDEO_DRIVER_PSP
29.8 + &PSP_bootstrap,
29.9 +#endif
29.10 #if SDL_VIDEO_DRIVER_DUMMY
29.11 &DUMMY_bootstrap,
29.12 #endif
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/src/video/psp/SDL_pspevents.c Sun Mar 17 20:07:02 2013 +0800
30.3 @@ -0,0 +1,284 @@
30.4 +/*
30.5 + Simple DirectMedia Layer
30.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
30.7 +
30.8 + This software is provided 'as-is', without any express or implied
30.9 + warranty. In no event will the authors be held liable for any damages
30.10 + arising from the use of this software.
30.11 +
30.12 + Permission is granted to anyone to use this software for any purpose,
30.13 + including commercial applications, and to alter it and redistribute it
30.14 + freely, subject to the following restrictions:
30.15 +
30.16 + 1. The origin of this software must not be misrepresented; you must not
30.17 + claim that you wrote the original software. If you use this software
30.18 + in a product, an acknowledgment in the product documentation would be
30.19 + appreciated but is not required.
30.20 + 2. Altered source versions must be plainly marked as such, and must not be
30.21 + misrepresented as being the original software.
30.22 + 3. This notice may not be removed or altered from any source distribution.
30.23 +*/
30.24 +
30.25 +/* Being a null driver, there's no event stream. We just define stubs for
30.26 + most of the API. */
30.27 +
30.28 +#include "SDL.h"
30.29 +#include "../../events/SDL_sysevents.h"
30.30 +#include "../../events/SDL_events_c.h"
30.31 +#include "../../events/SDL_keyboard_c.h"
30.32 +#include "SDL_pspvideo.h"
30.33 +#include "SDL_pspevents_c.h"
30.34 +#include "SDL_thread.h"
30.35 +#include "SDL_keyboard.h"
30.36 +#include <psphprm.h>
30.37 +
30.38 +#ifdef PSPIRKEYB
30.39 +#include <pspirkeyb.h>
30.40 +#include <pspirkeyb_rawkeys.h>
30.41 +
30.42 +#define IRKBD_CONFIG_FILE NULL /* this will take ms0:/seplugins/pspirkeyb.ini */
30.43 +
30.44 +static int irkbd_ready = 0;
30.45 +static SDLKey keymap[256];
30.46 +#endif
30.47 +
30.48 +static enum PspHprmKeys hprm = 0;
30.49 +static SDL_sem *event_sem = NULL;
30.50 +static SDL_Thread *thread = NULL;
30.51 +static int running = 0;
30.52 +static struct {
30.53 + enum PspHprmKeys id;
30.54 + SDL_Keycode sym;
30.55 +} keymap_psp[] = {
30.56 + { PSP_HPRM_PLAYPAUSE, SDLK_F10 },
30.57 + { PSP_HPRM_FORWARD, SDLK_F11 },
30.58 + { PSP_HPRM_BACK, SDLK_F12 },
30.59 + { PSP_HPRM_VOL_UP, SDLK_F13 },
30.60 + { PSP_HPRM_VOL_DOWN, SDLK_F14 },
30.61 + { PSP_HPRM_HOLD, SDLK_F15 }
30.62 +};
30.63 +
30.64 +int EventUpdate(void *data)
30.65 +{
30.66 + while (running) {
30.67 + SDL_SemWait(event_sem);
30.68 + sceHprmPeekCurrentKey(&hprm);
30.69 + SDL_SemPost(event_sem);
30.70 + /* Delay 1/60th of a second */
30.71 + sceKernelDelayThread(1000000 / 60);
30.72 + }
30.73 + return 0;
30.74 +}
30.75 +
30.76 +void PSP_PumpEvents(_THIS)
30.77 +{
30.78 + int i;
30.79 + enum PspHprmKeys keys;
30.80 + enum PspHprmKeys changed;
30.81 + static enum PspHprmKeys old_keys = 0;
30.82 + SDL_Keysym sym;
30.83 +
30.84 + SDL_SemWait(event_sem);
30.85 + keys = hprm;
30.86 + SDL_SemPost(event_sem);
30.87 +
30.88 + /* HPRM Keyboard */
30.89 + changed = old_keys ^ keys;
30.90 + old_keys = keys;
30.91 + if(changed) {
30.92 + for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
30.93 + if(changed & keymap_psp[i].id) {
30.94 + sym.scancode = keymap_psp[i].id;
30.95 + sym.sym = keymap_psp[i].sym;
30.96 +
30.97 + /* out of date
30.98 + SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
30.99 + SDL_PRESSED : SDL_RELEASED,
30.100 + &sym);
30.101 + */
30.102 + SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
30.103 + SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
30.104 + }
30.105 + }
30.106 + }
30.107 +
30.108 +#ifdef PSPIRKEYB
30.109 + if (irkbd_ready) {
30.110 + unsigned char buffer[255];
30.111 + int i, length, count;
30.112 + SIrKeybScanCodeData *scanData;
30.113 +
30.114 + if(pspIrKeybReadinput(buffer, &length) >= 0) {
30.115 + if((length % sizeof(SIrKeybScanCodeData)) == 0){
30.116 + count = length / sizeof(SIrKeybScanCodeData);
30.117 + for( i=0; i < count; i++ ) {
30.118 + unsigned char raw, pressed;
30.119 + scanData=(SIrKeybScanCodeData*) buffer+i;
30.120 + raw = scanData->raw;
30.121 + pressed = scanData->pressed;
30.122 + sym.scancode = raw;
30.123 + sym.sym = keymap[raw];
30.124 + /* not tested*/
30.125 + //SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym);
30.126 + SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
30.127 + SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]);
30.128 +
30.129 + }
30.130 + }
30.131 + }
30.132 + }
30.133 +#endif
30.134 + sceKernelDelayThread(0);
30.135 +
30.136 + return;
30.137 +}
30.138 +
30.139 +void PSP_InitOSKeymap(_THIS)
30.140 +{
30.141 +#ifdef PSPIRKEYB
30.142 + int i;
30.143 + for (i=0; i<SDL_TABLESIZE(keymap); ++i)
30.144 + keymap[i] = SDLK_UNKNOWN;
30.145 +
30.146 + keymap[KEY_ESC] = SDLK_ESCAPE;
30.147 +
30.148 + keymap[KEY_F1] = SDLK_F1;
30.149 + keymap[KEY_F2] = SDLK_F2;
30.150 + keymap[KEY_F3] = SDLK_F3;
30.151 + keymap[KEY_F4] = SDLK_F4;
30.152 + keymap[KEY_F5] = SDLK_F5;
30.153 + keymap[KEY_F6] = SDLK_F6;
30.154 + keymap[KEY_F7] = SDLK_F7;
30.155 + keymap[KEY_F8] = SDLK_F8;
30.156 + keymap[KEY_F9] = SDLK_F9;
30.157 + keymap[KEY_F10] = SDLK_F10;
30.158 + keymap[KEY_F11] = SDLK_F11;
30.159 + keymap[KEY_F12] = SDLK_F12;
30.160 + keymap[KEY_F13] = SDLK_PRINT;
30.161 + keymap[KEY_F14] = SDLK_PAUSE;
30.162 +
30.163 + keymap[KEY_GRAVE] = SDLK_BACKQUOTE;
30.164 + keymap[KEY_1] = SDLK_1;
30.165 + keymap[KEY_2] = SDLK_2;
30.166 + keymap[KEY_3] = SDLK_3;
30.167 + keymap[KEY_4] = SDLK_4;
30.168 + keymap[KEY_5] = SDLK_5;
30.169 + keymap[KEY_6] = SDLK_6;
30.170 + keymap[KEY_7] = SDLK_7;
30.171 + keymap[KEY_8] = SDLK_8;
30.172 + keymap[KEY_9] = SDLK_9;
30.173 + keymap[KEY_0] = SDLK_0;
30.174 + keymap[KEY_MINUS] = SDLK_MINUS;
30.175 + keymap[KEY_EQUAL] = SDLK_EQUALS;
30.176 + keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
30.177 +
30.178 + keymap[KEY_TAB] = SDLK_TAB;
30.179 + keymap[KEY_Q] = SDLK_q;
30.180 + keymap[KEY_W] = SDLK_w;
30.181 + keymap[KEY_E] = SDLK_e;
30.182 + keymap[KEY_R] = SDLK_r;
30.183 + keymap[KEY_T] = SDLK_t;
30.184 + keymap[KEY_Y] = SDLK_y;
30.185 + keymap[KEY_U] = SDLK_u;
30.186 + keymap[KEY_I] = SDLK_i;
30.187 + keymap[KEY_O] = SDLK_o;
30.188 + keymap[KEY_P] = SDLK_p;
30.189 + keymap[KEY_LEFTBRACE] = SDLK_LEFTBRACKET;
30.190 + keymap[KEY_RIGHTBRACE] = SDLK_RIGHTBRACKET;
30.191 + keymap[KEY_ENTER] = SDLK_RETURN;
30.192 +
30.193 + keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
30.194 + keymap[KEY_A] = SDLK_a;
30.195 + keymap[KEY_S] = SDLK_s;
30.196 + keymap[KEY_D] = SDLK_d;
30.197 + keymap[KEY_F] = SDLK_f;
30.198 + keymap[KEY_G] = SDLK_g;
30.199 + keymap[KEY_H] = SDLK_h;
30.200 + keymap[KEY_J] = SDLK_j;
30.201 + keymap[KEY_K] = SDLK_k;
30.202 + keymap[KEY_L] = SDLK_l;
30.203 + keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
30.204 + keymap[KEY_APOSTROPHE] = SDLK_QUOTE;
30.205 + keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
30.206 +
30.207 + keymap[KEY_Z] = SDLK_z;
30.208 + keymap[KEY_X] = SDLK_x;
30.209 + keymap[KEY_C] = SDLK_c;
30.210 + keymap[KEY_V] = SDLK_v;
30.211 + keymap[KEY_B] = SDLK_b;
30.212 + keymap[KEY_N] = SDLK_n;
30.213 + keymap[KEY_M] = SDLK_m;
30.214 + keymap[KEY_COMMA] = SDLK_COMMA;
30.215 + keymap[KEY_DOT] = SDLK_PERIOD;
30.216 + keymap[KEY_SLASH] = SDLK_SLASH;
30.217 +
30.218 + keymap[KEY_SPACE] = SDLK_SPACE;
30.219 +
30.220 + keymap[KEY_UP] = SDLK_UP;
30.221 + keymap[KEY_DOWN] = SDLK_DOWN;
30.222 + keymap[KEY_LEFT] = SDLK_LEFT;
30.223 + keymap[KEY_RIGHT] = SDLK_RIGHT;
30.224 +
30.225 + keymap[KEY_HOME] = SDLK_HOME;
30.226 + keymap[KEY_END] = SDLK_END;
30.227 + keymap[KEY_INSERT] = SDLK_INSERT;
30.228 + keymap[KEY_DELETE] = SDLK_DELETE;
30.229 +
30.230 + keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
30.231 + keymap[KEY_LEFTMETA] = SDLK_LSUPER;
30.232 +
30.233 + keymap[KEY_KPSLASH] = SDLK_KP_DIVIDE;
30.234 + keymap[KEY_KPASTERISK] = SDLK_KP_MULTIPLY;
30.235 + keymap[KEY_KPMINUS] = SDLK_KP_MINUS;
30.236 + keymap[KEY_KPPLUS] = SDLK_KP_PLUS;
30.237 + keymap[KEY_KPDOT] = SDLK_KP_PERIOD;
30.238 + keymap[KEY_KPEQUAL] = SDLK_KP_EQUALS;
30.239 +
30.240 + keymap[KEY_LEFTCTRL] = SDLK_LCTRL;
30.241 + keymap[KEY_RIGHTCTRL] = SDLK_RCTRL;
30.242 + keymap[KEY_LEFTALT] = SDLK_LALT;
30.243 + keymap[KEY_RIGHTALT] = SDLK_RALT;
30.244 + keymap[KEY_LEFTSHIFT] = SDLK_LSHIFT;
30.245 + keymap[KEY_RIGHTSHIFT] = SDLK_RSHIFT;
30.246 +#endif
30.247 +}
30.248 +
30.249 +void PSP_EventInit(_THIS)
30.250 +{
30.251 +#ifdef PSPIRKEYB
30.252 + int outputmode = PSP_IRKBD_OUTPUT_MODE_SCANCODE;
30.253 + int ret = pspIrKeybInit(IRKBD_CONFIG_FILE, 0);
30.254 + if (ret == PSP_IRKBD_RESULT_OK) {
30.255 + pspIrKeybOutputMode(outputmode);
30.256 + irkbd_ready = 1;
30.257 + } else {
30.258 + irkbd_ready = 0;
30.259 + }
30.260 +#endif
30.261 + /* Start thread to read data */
30.262 + if((event_sem = SDL_CreateSemaphore(1)) == NULL) {
30.263 + SDL_SetError("Can't create input semaphore\n");
30.264 + return;
30.265 + }
30.266 + running = 1;
30.267 + if((thread = SDL_CreateThread(EventUpdate, "PSPInputThread",NULL)) == NULL) {
30.268 + SDL_SetError("Can't create input thread\n");
30.269 + return;
30.270 + }
30.271 +}
30.272 +
30.273 +void PSP_EventQuit(_THIS)
30.274 +{
30.275 + running = 0;
30.276 + SDL_WaitThread(thread, NULL);
30.277 + SDL_DestroySemaphore(event_sem);
30.278 +#ifdef PSPIRKEYB
30.279 + if (irkbd_ready) {
30.280 + pspIrKeybFinish();
30.281 + irkbd_ready = 0;
30.282 + }
30.283 +#endif
30.284 +}
30.285 +
30.286 +/* end of SDL_pspevents.c ... */
30.287 +
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/src/video/psp/SDL_pspevents_c.h Sun Mar 17 20:07:02 2013 +0800
31.3 @@ -0,0 +1,31 @@
31.4 +/*
31.5 + Simple DirectMedia Layer
31.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
31.7 +
31.8 + This software is provided 'as-is', without any express or implied
31.9 + warranty. In no event will the authors be held liable for any damages
31.10 + arising from the use of this software.
31.11 +
31.12 + Permission is granted to anyone to use this software for any purpose,
31.13 + including commercial applications, and to alter it and redistribute it
31.14 + freely, subject to the following restrictions:
31.15 +
31.16 + 1. The origin of this software must not be misrepresented; you must not
31.17 + claim that you wrote the original software. If you use this software
31.18 + in a product, an acknowledgment in the product documentation would be
31.19 + appreciated but is not required.
31.20 + 2. Altered source versions must be plainly marked as such, and must not be
31.21 + misrepresented as being the original software.
31.22 + 3. This notice may not be removed or altered from any source distribution.
31.23 +*/
31.24 +
31.25 +#include "SDL_pspvideo.h"
31.26 +
31.27 +/* Variables and functions exported by SDL_sysevents.c to other parts
31.28 + of the native video subsystem (SDL_sysvideo.c)
31.29 +*/
31.30 +extern void PSP_InitOSKeymap(_THIS);
31.31 +extern void PSP_PumpEvents(_THIS);
31.32 +
31.33 +/* end of SDL_pspevents_c.h ... */
31.34 +
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/src/video/psp/SDL_pspgl.c Sun Mar 17 20:07:02 2013 +0800
32.3 @@ -0,0 +1,207 @@
32.4 +/*
32.5 + Simple DirectMedia Layer
32.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
32.7 +
32.8 + This software is provided 'as-is', without any express or implied
32.9 + warranty. In no event will the authors be held liable for any damages
32.10 + arising from the use of this software.
32.11 +
32.12 + Permission is granted to anyone to use this software for any purpose,
32.13 + including commercial applications, and to alter it and redistribute it
32.14 + freely, subject to the following restrictions:
32.15 +
32.16 + 1. The origin of this software must not be misrepresented; you must not
32.17 + claim that you wrote the original software. If you use this software
32.18 + in a product, an acknowledgment in the product documentation would be
32.19 + appreciated but is not required.
32.20 + 2. Altered source versions must be plainly marked as such, and must not be
32.21 + misrepresented as being the original software.
32.22 + 3. This notice may not be removed or altered from any source distribution.
32.23 +*/
32.24 +
32.25 +#include <stdlib.h>
32.26 +#include <string.h>
32.27 +
32.28 +#include "SDL_error.h"
32.29 +#include "SDL_pspvideo.h"
32.30 +#include "SDL_pspgl_c.h"
32.31 +
32.32 +/*****************************************************************************/
32.33 +/* SDL OpenGL/OpenGL ES functions */
32.34 +/*****************************************************************************/
32.35 +#define EGLCHK(stmt) \
32.36 + do { \
32.37 + EGLint err; \
32.38 + \
32.39 + stmt; \
32.40 + err = eglGetError(); \
32.41 + if (err != EGL_SUCCESS) { \
32.42 + SDL_SetError("EGL error %d", err); \
32.43 + return 0; \
32.44 + } \
32.45 + } while (0)
32.46 +
32.47 +int
32.48 +PSP_GL_LoadLibrary(_THIS, const char *path)
32.49 +{
32.50 + if (!_this->gl_config.driver_loaded) {
32.51 + _this->gl_config.driver_loaded = 1;
32.52 + }
32.53 +
32.54 + return 0;
32.55 +}
32.56 +
32.57 +/* pspgl doesn't provide this call, so stub it out since SDL requires it.
32.58 +#define GLSTUB(func,params) void func params {}
32.59 +
32.60 +GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
32.61 + GLdouble zNear, GLdouble zFar))
32.62 +*/
32.63 +void *
32.64 +PSP_GL_GetProcAddress(_THIS, const char *proc)
32.65 +{
32.66 + return eglGetProcAddress(proc);
32.67 +}
32.68 +
32.69 +void
32.70 +PSP_GL_UnloadLibrary(_THIS)
32.71 +{
32.72 + eglTerminate(_this->gl_data->display);
32.73 +}
32.74 +
32.75 +static EGLint width = 480;
32.76 +static EGLint height = 272;
32.77 +
32.78 +SDL_GLContext
32.79 +PSP_GL_CreateContext(_THIS, SDL_Window * window)
32.80 +{
32.81 +
32.82 + SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
32.83 +
32.84 + EGLint attribs[32];
32.85 + EGLDisplay display;
32.86 + EGLContext context;
32.87 + EGLSurface surface;
32.88 + EGLConfig config;
32.89 + EGLint num_configs;
32.90 + int i;
32.91 +
32.92 +
32.93 + /* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */
32.94 + EGLCHK(display = eglGetDisplay(0));
32.95 + EGLCHK(eglInitialize(display, NULL, NULL));
32.96 + wdata->uses_gles = SDL_TRUE;
32.97 + window->flags |= SDL_WINDOW_FULLSCREEN;
32.98 +
32.99 + /* Setup the config based on SDL's current values. */
32.100 + i = 0;
32.101 + attribs[i++] = EGL_RED_SIZE;
32.102 + attribs[i++] = _this->gl_config.red_size;
32.103 + attribs[i++] = EGL_GREEN_SIZE;
32.104 + attribs[i++] = _this->gl_config.green_size;
32.105 + attribs[i++] = EGL_BLUE_SIZE;
32.106 + attribs[i++] = _this->gl_config.blue_size;
32.107 + attribs[i++] = EGL_DEPTH_SIZE;
32.108 + attribs[i++] = _this->gl_config.depth_size;
32.109 +
32.110 + if (_this->gl_config.alpha_size)
32.111 + {
32.112 + attribs[i++] = EGL_ALPHA_SIZE;
32.113 + attribs[i++] = _this->gl_config.alpha_size;
32.114 + }
32.115 + if (_this->gl_config.stencil_size)
32.116 + {
32.117 + attribs[i++] = EGL_STENCIL_SIZE;
32.118 + attribs[i++] = _this->gl_config.stencil_size;
32.119 + }
32.120 +
32.121 + attribs[i++] = EGL_NONE;
32.122 +
32.123 + EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
32.124 +
32.125 + if (num_configs == 0)
32.126 + {
32.127 + SDL_SetError("No valid EGL configs for requested mode");
32.128 + return 0;
32.129 + }
32.130 +
32.131 + EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width));
32.132 + EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height));
32.133 +
32.134 + EGLCHK(context = eglCreateContext(display, config, NULL, NULL));
32.135 + EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL));
32.136 + EGLCHK(eglMakeCurrent(display, surface, surface, context));
32.137 +
32.138 + _this->gl_data->display = display;
32.139 + _this->gl_data->context = context;
32.140 + _this->gl_data->surface = surface;
32.141 +
32.142 +
32.143 + return context;
32.144 +}
32.145 +
32.146 +int
32.147 +PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
32.148 +{
32.149 + if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
32.150 + _this->gl_data->surface, _this->gl_data->context))
32.151 + {
32.152 + SDL_SetError("Unable to make EGL context current");
32.153 + return -1;
32.154 + }
32.155 + return 0;
32.156 +}
32.157 +
32.158 +int
32.159 +PSP_GL_SetSwapInterval(_THIS, int interval)
32.160 +{
32.161 + EGLBoolean status;
32.162 + status = eglSwapInterval(_this->gl_data->display, interval);
32.163 + if (status == EGL_TRUE) {
32.164 + /* Return success to upper level */
32.165 + _this->gl_data->swapinterval = interval;
32.166 + return 0;
32.167 + }
32.168 + /* Failed to set swap interval */
32.169 + SDL_SetError("Unable to set the EGL swap interval");
32.170 + return -1;
32.171 +}
32.172 +
32.173 +int
32.174 +PSP_GL_GetSwapInterval(_THIS)
32.175 +{
32.176 + return _this->gl_data->swapinterval;
32.177 +}
32.178 +
32.179 +void
32.180 +PSP_GL_SwapWindow(_THIS, SDL_Window * window)
32.181 +{
32.182 + eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface);
32.183 +}
32.184 +
32.185 +void
32.186 +PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
32.187 +{
32.188 + SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
32.189 + EGLBoolean status;
32.190 +
32.191 + if (phdata->egl_initialized != SDL_TRUE) {
32.192 + SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support");
32.193 + return;
32.194 + }
32.195 +
32.196 + /* Check if OpenGL ES connection has been initialized */
32.197 + if (_this->gl_data->display != EGL_NO_DISPLAY) {
32.198 + if (context != EGL_NO_CONTEXT) {
32.199 + status = eglDestroyContext(_this->gl_data->display, context);
32.200 + if (status != EGL_TRUE) {
32.201 + /* Error during OpenGL ES context destroying */
32.202 + SDL_SetError("PSP: OpenGL ES context destroy error");
32.203 + return;
32.204 + }
32.205 + }
32.206 + }
32.207 +
32.208 + return;
32.209 +}
32.210 +
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/src/video/psp/SDL_pspgl_c.h Sun Mar 17 20:07:02 2013 +0800
33.3 @@ -0,0 +1,52 @@
33.4 +/*
33.5 + Simple DirectMedia Layer
33.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
33.7 +
33.8 + This software is provided 'as-is', without any express or implied
33.9 + warranty. In no event will the authors be held liable for any damages
33.10 + arising from the use of this software.
33.11 +
33.12 + Permission is granted to anyone to use this software for any purpose,
33.13 + including commercial applications, and to alter it and redistribute it
33.14 + freely, subject to the following restrictions:
33.15 +
33.16 + 1. The origin of this software must not be misrepresented; you must not
33.17 + claim that you wrote the original software. If you use this software
33.18 + in a product, an acknowledgment in the product documentation would be
33.19 + appreciated but is not required.
33.20 + 2. Altered source versions must be plainly marked as such, and must not be
33.21 + misrepresented as being the original software.
33.22 + 3. This notice may not be removed or altered from any source distribution.
33.23 +*/
33.24 +
33.25 +#ifndef _SDL_pspgl_c_h
33.26 +#define _SDL_pspgl_c_h
33.27 +
33.28 +
33.29 +#include <GLES/egl.h>
33.30 +#include <GLES/gl.h>
33.31 +
33.32 +#include "SDL_pspvideo.h"
33.33 +
33.34 +
33.35 +typedef struct SDL_GLDriverData {
33.36 + EGLDisplay display;
33.37 + EGLContext context;
33.38 + EGLSurface surface;
33.39 + uint32_t swapinterval;
33.40 +}SDL_GLDriverData;
33.41 +
33.42 +extern void * PSP_GL_GetProcAddress(_THIS, const char *proc);
33.43 +extern int PSP_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context);
33.44 +extern void PSP_GL_SwapBuffers(_THIS);
33.45 +
33.46 +extern void PSP_GL_SwapWindow(_THIS, SDL_Window * window);
33.47 +extern SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window);
33.48 +
33.49 +extern int PSP_GL_LoadLibrary(_THIS, const char *path);
33.50 +extern void PSP_GL_UnloadLibrary(_THIS);
33.51 +extern int PSP_GL_SetSwapInterval(_THIS, int interval);
33.52 +extern int PSP_GL_GetSwapInterval(_THIS);
33.53 +
33.54 +
33.55 +#endif /* _SDL_pspgl_c_h */
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
34.2 +++ b/src/video/psp/SDL_pspmouse.c Sun Mar 17 20:07:02 2013 +0800
34.3 @@ -0,0 +1,35 @@
34.4 +/*
34.5 + Simple DirectMedia Layer
34.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
34.7 +
34.8 + This software is provided 'as-is', without any express or implied
34.9 + warranty. In no event will the authors be held liable for any damages
34.10 + arising from the use of this software.
34.11 +
34.12 + Permission is granted to anyone to use this software for any purpose,
34.13 + including commercial applications, and to alter it and redistribute it
34.14 + freely, subject to the following restrictions:
34.15 +
34.16 + 1. The origin of this software must not be misrepresented; you must not
34.17 + claim that you wrote the original software. If you use this software
34.18 + in a product, an acknowledgment in the product documentation would be
34.19 + appreciated but is not required.
34.20 + 2. Altered source versions must be plainly marked as such, and must not be
34.21 + misrepresented as being the original software.
34.22 + 3. This notice may not be removed or altered from any source distribution.
34.23 +*/
34.24 +
34.25 +
34.26 +#include <stdio.h>
34.27 +
34.28 +#include "SDL_error.h"
34.29 +#include "SDL_mouse.h"
34.30 +#include "../../events/SDL_events_c.h"
34.31 +
34.32 +#include "SDL_pspmouse_c.h"
34.33 +
34.34 +
34.35 +/* The implementation dependent data for the window manager cursor */
34.36 +struct WMcursor {
34.37 + int unused;
34.38 +};
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
35.2 +++ b/src/video/psp/SDL_pspmouse_c.h Sun Mar 17 20:07:02 2013 +0800
35.3 @@ -0,0 +1,24 @@
35.4 +/*
35.5 + Simple DirectMedia Layer
35.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
35.7 +
35.8 + This software is provided 'as-is', without any express or implied
35.9 + warranty. In no event will the authors be held liable for any damages
35.10 + arising from the use of this software.
35.11 +
35.12 + Permission is granted to anyone to use this software for any purpose,
35.13 + including commercial applications, and to alter it and redistribute it
35.14 + freely, subject to the following restrictions:
35.15 +
35.16 + 1. The origin of this software must not be misrepresented; you must not
35.17 + claim that you wrote the original software. If you use this software
35.18 + in a product, an acknowledgment in the product documentation would be
35.19 + appreciated but is not required.
35.20 + 2. Altered source versions must be plainly marked as such, and must not be
35.21 + misrepresented as being the original software.
35.22 + 3. This notice may not be removed or altered from any source distribution.
35.23 +*/
35.24 +
35.25 +#include "SDL_pspvideo.h"
35.26 +
35.27 +/* Functions to be exported */
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/src/video/psp/SDL_pspvideo.c Sun Mar 17 20:07:02 2013 +0800
36.3 @@ -0,0 +1,334 @@
36.4 +/*
36.5 + Simple DirectMedia Layer
36.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
36.7 +
36.8 + This software is provided 'as-is', without any express or implied
36.9 + warranty. In no event will the authors be held liable for any damages
36.10 + arising from the use of this software.
36.11 +
36.12 + Permission is granted to anyone to use this software for any purpose,
36.13 + including commercial applications, and to alter it and redistribute it
36.14 + freely, subject to the following restrictions:
36.15 +
36.16 + 1. The origin of this software must not be misrepresented; you must not
36.17 + claim that you wrote the original software. If you use this software
36.18 + in a product, an acknowledgment in the product documentation would be
36.19 + appreciated but is not required.
36.20 + 2. Altered source versions must be plainly marked as such, and must not be
36.21 + misrepresented as being the original software.
36.22 + 3. This notice may not be removed or altered from any source distribution.
36.23 +*/
36.24 +
36.25 +#include "SDL_config.h"
36.26 +
36.27 +#if SDL_VIDEO_DRIVER_PSP
36.28 +
36.29 +/* SDL internals */
36.30 +#include "../SDL_sysvideo.h"
36.31 +#include "SDL_version.h"
36.32 +#include "SDL_syswm.h"
36.33 +#include "SDL_loadso.h"
36.34 +#include "SDL_events.h"
36.35 +#include "../../events/SDL_mouse_c.h"
36.36 +#include "../../events/SDL_keyboard_c.h"
36.37 +
36.38 +
36.39 +
36.40 +/* PSP declarations */
36.41 +#include "SDL_pspvideo.h"
36.42 +#include "SDL_pspevents_c.h"
36.43 +#include "SDL_pspgl_c.h"
36.44 +
36.45 +/* unused
36.46 +static SDL_bool PSP_initialized = SDL_FALSE;
36.47 +*/
36.48 +static int
36.49 +PSP_Available(void)
36.50 +{
36.51 + return 1;
36.52 +}
36.53 +
36.54 +static void
36.55 +PSP_Destroy(SDL_VideoDevice * device)
36.56 +{
36.57 +// SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
36.58 +
36.59 + if (device->driverdata != NULL) {
36.60 + device->driverdata = NULL;
36.61 + }
36.62 +}
36.63 +
36.64 +static SDL_VideoDevice *
36.65 +PSP_Create()
36.66 +{
36.67 + SDL_VideoDevice *device;
36.68 + SDL_VideoData *phdata;
36.69 + SDL_GLDriverData *gldata;
36.70 + int status;
36.71 +
36.72 + /* Check if pandora could be initialized */
36.73 + status = PSP_Available();
36.74 + if (status == 0) {
36.75 + /* PSP could not be used */
36.76 + return NULL;
36.77 + }
36.78 +
36.79 + /* Initialize SDL_VideoDevice structure */
36.80 + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
36.81 + if (device == NULL) {
36.82 + SDL_OutOfMemory();
36.83 + return NULL;
36.84 + }
36.85 +
36.86 + /* Initialize internal Pandora specific data */
36.87 + phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
36.88 + if (phdata == NULL) {
36.89 + SDL_OutOfMemory();
36.90 + SDL_free(device);
36.91 + return NULL;
36.92 + }
36.93 +
36.94 + gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData));
36.95 + if (gldata == NULL) {
36.96 + SDL_OutOfMemory();
36.97 + SDL_free(device);
36.98 + return NULL;
36.99 + }
36.100 + device->gl_data = gldata;
36.101 +
36.102 + device->driverdata = phdata;
36.103 +
36.104 + phdata->egl_initialized = SDL_TRUE;
36.105 +
36.106 +
36.107 + /* Setup amount of available displays and current display */
36.108 + device->num_displays = 0;
36.109 +
36.110 + /* Set device free function */
36.111 + device->free = PSP_Destroy;
36.112 +
36.113 + /* Setup all functions which we can handle */
36.114 + device->VideoInit = PSP_VideoInit;
36.115 + device->VideoQuit = PSP_VideoQuit;
36.116 + device->GetDisplayModes = PSP_GetDisplayModes;
36.117 + device->SetDisplayMode = PSP_SetDisplayMode;
36.118 + device->CreateWindow = PSP_CreateWindow;
36.119 + device->CreateWindowFrom = PSP_CreateWindowFrom;
36.120 + device->SetWindowTitle = PSP_SetWindowTitle;
36.121 + device->SetWindowIcon = PSP_SetWindowIcon;
36.122 + device->SetWindowPosition = PSP_SetWindowPosition;
36.123 + device->SetWindowSize = PSP_SetWindowSize;
36.124 + device->ShowWindow = PSP_ShowWindow;
36.125 + device->HideWindow = PSP_HideWindow;
36.126 + device->RaiseWindow = PSP_RaiseWindow;
36.127 + device->MaximizeWindow = PSP_MaximizeWindow;
36.128 + device->MinimizeWindow = PSP_MinimizeWindow;
36.129 + device->RestoreWindow = PSP_RestoreWindow;
36.130 + device->SetWindowGrab = PSP_SetWindowGrab;
36.131 + device->DestroyWindow = PSP_DestroyWindow;
36.132 + device->GetWindowWMInfo = PSP_GetWindowWMInfo;
36.133 + device->GL_LoadLibrary = PSP_GL_LoadLibrary;
36.134 + device->GL_GetProcAddress = PSP_GL_GetProcAddress;
36.135 + device->GL_UnloadLibrary = PSP_GL_UnloadLibrary;
36.136 + device->GL_CreateContext = PSP_GL_CreateContext;
36.137 + device->GL_MakeCurrent = PSP_GL_MakeCurrent;
36.138 + device->GL_SetSwapInterval = PSP_GL_SetSwapInterval;
36.139 + device->GL_GetSwapInterval = PSP_GL_GetSwapInterval;
36.140 + device->GL_SwapWindow = PSP_GL_SwapWindow;
36.141 + device->GL_DeleteContext = PSP_GL_DeleteContext;
36.142 + device->SDL_HasScreenKeyboardSupport = PSP_SDL_HasScreenKeyboardSupport;
36.143 + device->SDL_ShowScreenKeyboard = PSP_SDL_ShowScreenKeyboard;
36.144 + device->SDL_HideScreenKeyboard = PSP_SDL_HideScreenKeyboard;
36.145 + device->SDL_IsScreenKeyboardShown = PSP_SDL_IsScreenKeyboardShown;
36.146 +
36.147 + device->PumpEvents = PSP_PumpEvents;
36.148 +
36.149 + return device;
36.150 +}
36.151 +
36.152 +VideoBootStrap PSP_bootstrap = {
36.153 + "PSP",
36.154 + "PSP Video Driver",
36.155 + PSP_Available,
36.156 + PSP_Create
36.157 +};
36.158 +
36.159 +/*****************************************************************************/
36.160 +/* SDL Video and Display initialization/handling functions */
36.161 +/*****************************************************************************/
36.162 +int
36.163 +PSP_VideoInit(_THIS)
36.164 +{
36.165 + SDL_VideoDisplay display;
36.166 + SDL_DisplayMode current_mode;
36.167 +
36.168 + SDL_zero(current_mode);
36.169 +
36.170 + current_mode.w = 480;
36.171 + current_mode.h = 272;
36.172 +
36.173 + current_mode.refresh_rate = 60;
36.174 + // 32 bpp for default
36.175 + // current_mode.format = SDL_PIXELFORMAT_RGBA8888;
36.176 + current_mode.format = SDL_PIXELFORMAT_ABGR8888;
36.177 +
36.178 + current_mode.driverdata = NULL;
36.179 +
36.180 + SDL_zero(display);
36.181 + display.desktop_mode = current_mode;
36.182 + display.current_mode = current_mode;
36.183 + display.driverdata = NULL;
36.184 +
36.185 + SDL_AddVideoDisplay(&display);
36.186 +
36.187 + return 1;
36.188 +}
36.189 +
36.190 +void
36.191 +PSP_VideoQuit(_THIS)
36.192 +{
36.193 +
36.194 +}
36.195 +
36.196 +void
36.197 +PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
36.198 +{
36.199 +
36.200 +}
36.201 +
36.202 +int
36.203 +PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
36.204 +{
36.205 + return 0;
36.206 +}
36.207 +#define EGLCHK(stmt) \
36.208 + do { \
36.209 + EGLint err; \
36.210 + \
36.211 + stmt; \
36.212 + err = eglGetError(); \
36.213 + if (err != EGL_SUCCESS) { \
36.214 + SDL_SetError("EGL error %d", err); \
36.215 + return 0; \
36.216 + } \
36.217 + } while (0)
36.218 +
36.219 +int
36.220 +PSP_CreateWindow(_THIS, SDL_Window * window)
36.221 +{
36.222 +// SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
36.223 +
36.224 + SDL_WindowData *wdata;
36.225 +
36.226 + /* Allocate window internal data */
36.227 + wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
36.228 + if (wdata == NULL) {
36.229 + SDL_OutOfMemory();
36.230 + return -1;
36.231 + }
36.232 +
36.233 + /* Setup driver data for this window */
36.234 + window->driverdata = wdata;
36.235 +
36.236 +
36.237 + /* Window has been successfully created */
36.238 + return 0;
36.239 +}
36.240 +
36.241 +int
36.242 +PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
36.243 +{
36.244 + return -1;
36.245 +}
36.246 +
36.247 +void
36.248 +PSP_SetWindowTitle(_THIS, SDL_Window * window)
36.249 +{
36.250 +}
36.251 +void
36.252 +PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
36.253 +{
36.254 +}
36.255 +void
36.256 +PSP_SetWindowPosition(_THIS, SDL_Window * window)
36.257 +{
36.258 +}
36.259 +void
36.260 +PSP_SetWindowSize(_THIS, SDL_Window * window)
36.261 +{
36.262 +}
36.263 +void
36.264 +PSP_ShowWindow(_THIS, SDL_Window * window)
36.265 +{
36.266 +}
36.267 +void
36.268 +PSP_HideWindow(_THIS, SDL_Window * window)
36.269 +{
36.270 +}
36.271 +void
36.272 +PSP_RaiseWindow(_THIS, SDL_Window * window)
36.273 +{
36.274 +}
36.275 +void
36.276 +PSP_MaximizeWindow(_THIS, SDL_Window * window)
36.277 +{
36.278 +}
36.279 +void
36.280 +PSP_MinimizeWindow(_THIS, SDL_Window * window)
36.281 +{
36.282 +}
36.283 +void
36.284 +PSP_RestoreWindow(_THIS, SDL_Window * window)
36.285 +{
36.286 +}
36.287 +void
36.288 +PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
36.289 +{
36.290 +
36.291 +}
36.292 +void
36.293 +PSP_DestroyWindow(_THIS, SDL_Window * window)
36.294 +{
36.295 +
36.296 +// eglTerminate(_this->gl_data->display);
36.297 +}
36.298 +
36.299 +/*****************************************************************************/
36.300 +/* SDL Window Manager function */
36.301 +/*****************************************************************************/
36.302 +SDL_bool
36.303 +PSP_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
36.304 +{
36.305 + if (info->version.major <= SDL_MAJOR_VERSION) {
36.306 + return SDL_TRUE;
36.307 + } else {
36.308 + SDL_SetError("application not compiled with SDL %d.%d\n",
36.309 + SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
36.310 + return SDL_FALSE;
36.311 + }
36.312 +
36.313 + /* Failed to get window manager information */
36.314 + return SDL_FALSE;
36.315 +}
36.316 +
36.317 +
36.318 +/* TO Write Me*/
36.319 +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS)
36.320 +{
36.321 + return SDL_TRUE;
36.322 +}
36.323 +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window)
36.324 +{
36.325 +}
36.326 +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window)
36.327 +{
36.328 +}
36.329 +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window)
36.330 +{
36.331 + return SDL_FALSE;
36.332 +}
36.333 +
36.334 +
36.335 +#endif /* SDL_VIDEO_DRIVER_PSP */
36.336 +
36.337 +/* vi: set ts=4 sw=4 expandtab: */
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
37.2 +++ b/src/video/psp/SDL_pspvideo.h Sun Mar 17 20:07:02 2013 +0800
37.3 @@ -0,0 +1,102 @@
37.4 +/*
37.5 + Simple DirectMedia Layer
37.6 + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
37.7 +
37.8 + This software is provided 'as-is', without any express or implied
37.9 + warranty. In no event will the authors be held liable for any damages
37.10 + arising from the use of this software.
37.11 +
37.12 + Permission is granted to anyone to use this software for any purpose,
37.13 + including commercial applications, and to alter it and redistribute it
37.14 + freely, subject to the following restrictions:
37.15 +
37.16 + 1. The origin of this software must not be misrepresented; you must not
37.17 + claim that you wrote the original software. If you use this software
37.18 + in a product, an acknowledgment in the product documentation would be
37.19 + appreciated but is not required.
37.20 + 2. Altered source versions must be plainly marked as such, and must not be
37.21 + misrepresented as being the original software.
37.22 + 3. This notice may not be removed or altered from any source distribution.
37.23 +*/
37.24 +
37.25 +#ifndef __SDL_PANDORA_H__
37.26 +#define __SDL_PANDORA_H__
37.27 +
37.28 +#include <GLES/egl.h>
37.29 +
37.30 +#include "SDL_config.h"
37.31 +#include "../SDL_sysvideo.h"
37.32 +
37.33 +typedef struct SDL_VideoData
37.34 +{
37.35 + SDL_bool egl_initialized; /* OpenGL ES device initialization status */
37.36 + uint32_t egl_refcount; /* OpenGL ES reference count */
37.37 +
37.38 +
37.39 +
37.40 +} SDL_VideoData;
37.41 +
37.42 +
37.43 +typedef struct SDL_DisplayData
37.44 +{
37.45 +
37.46 +} SDL_DisplayData;
37.47 +
37.48 +
37.49 +typedef struct SDL_WindowData
37.50 +{
37.51 + SDL_bool uses_gles; /* if true window must support OpenGL ES */
37.52 +
37.53 +} SDL_WindowData;
37.54 +
37.55 +
37.56 +
37.57 +
37.58 +/****************************************************************************/
37.59 +/* SDL_VideoDevice functions declaration */
37.60 +/****************************************************************************/
37.61 +
37.62 +/* Display and window functions */
37.63 +int PSP_VideoInit(_THIS);
37.64 +void PSP_VideoQuit(_THIS);
37.65 +void PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
37.66 +int PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
37.67 +int PSP_CreateWindow(_THIS, SDL_Window * window);
37.68 +int PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
37.69 +void PSP_SetWindowTitle(_THIS, SDL_Window * window);
37.70 +void PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
37.71 +void PSP_SetWindowPosition(_THIS, SDL_Window * window);
37.72 +void PSP_SetWindowSize(_THIS, SDL_Window * window);
37.73 +void PSP_ShowWindow(_THIS, SDL_Window * window);
37.74 +void PSP_HideWindow(_THIS, SDL_Window * window);
37.75 +void PSP_RaiseWindow(_THIS, SDL_Window * window);
37.76 +void PSP_MaximizeWindow(_THIS, SDL_Window * window);
37.77 +void PSP_MinimizeWindow(_THIS, SDL_Window * window);
37.78 +void PSP_RestoreWindow(_THIS, SDL_Window * window);
37.79 +void PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
37.80 +void PSP_DestroyWindow(_THIS, SDL_Window * window);
37.81 +
37.82 +/* Window manager function */
37.83 +SDL_bool PSP_GetWindowWMInfo(_THIS, SDL_Window * window,
37.84 + struct SDL_SysWMinfo *info);
37.85 +
37.86 +/* OpenGL/OpenGL ES functions */
37.87 +int PSP_GL_LoadLibrary(_THIS, const char *path);
37.88 +void *PSP_GL_GetProcAddress(_THIS, const char *proc);
37.89 +void PSP_GL_UnloadLibrary(_THIS);
37.90 +SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window);
37.91 +int PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
37.92 +int PSP_GL_SetSwapInterval(_THIS, int interval);
37.93 +int PSP_GL_GetSwapInterval(_THIS);
37.94 +void PSP_GL_SwapWindow(_THIS, SDL_Window * window);
37.95 +void PSP_GL_DeleteContext(_THIS, SDL_GLContext context);
37.96 +
37.97 +/*PSP on screen keyboard */
37.98 +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS);
37.99 +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window);
37.100 +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window);
37.101 +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window);
37.102 +
37.103 +#endif /* __SDL_PANDORA_H__ */
37.104 +
37.105 +/* vi: set ts=4 sw=4 expandtab: */