Wiimote and nJoy > Gamepad changes
1. Added LiveUpdates, while the configuration window is open nJoy and Wiimote will check for connected/disconnected pads 2. Removed the 'Nintendo RVL-CNT-01' device from the device list, and other SDL devices with no axes/buttons 3. Added SDL (from the current SVN) to get debugging information for SDL.dll 4. Added 'Upright Wiimote' option to emulated Wiimote options git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4534 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
b858befba2
commit
71506bc0f7
|
@ -1,151 +1,165 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL.h
|
||||
*
|
||||
* Main include header for the SDL library
|
||||
*/
|
||||
/**
|
||||
* \mainpage Simple DirectMedia Layer (SDL)
|
||||
|
||||
http://www.libsdl.org/
|
||||
|
||||
* \section intro_sec Introduction
|
||||
|
||||
This is the Simple DirectMedia Layer, a general API that provides low
|
||||
level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
|
||||
and 2D framebuffer across multiple platforms.
|
||||
|
||||
The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
|
||||
Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
|
||||
The code contains support for Dreamcast, Atari, AIX, OSF/Tru64,
|
||||
RISC OS, SymbianOS, and OS/2, but these are not officially supported.
|
||||
|
||||
SDL is written in C, but works with C++ natively, and has bindings to
|
||||
several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
|
||||
Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
|
||||
Pike, Pliant, Python, Ruby, and Smalltalk.
|
||||
|
||||
This library is distributed under GNU LGPL version 2, which can be
|
||||
found in the file "COPYING". This license allows you to use SDL
|
||||
freely in commercial programs as long as you link with the dynamic
|
||||
library.
|
||||
|
||||
The best way to learn how to use SDL is to check out the header files in
|
||||
the "include" subdirectory and the programs in the "test" subdirectory.
|
||||
The header files and test programs are well commented and always up to date.
|
||||
More documentation is available in HTML format in "docs/index.html", and
|
||||
a documentation wiki is available online at:
|
||||
http://www.libsdl.org/cgi/docwiki.cgi
|
||||
|
||||
The test programs in the "test" subdirectory are in the public domain.
|
||||
|
||||
Frequently asked questions are answered online:
|
||||
http://www.libsdl.org/faq.php
|
||||
|
||||
If you need help with the library, or just want to discuss SDL related
|
||||
issues, you can join the developers mailing list:
|
||||
http://www.libsdl.org/mailing-list.php
|
||||
|
||||
Enjoy!
|
||||
Sam Lantinga (slouken@libsdl.org)
|
||||
*/
|
||||
|
||||
#ifndef _SDL_H
|
||||
#define _SDL_H
|
||||
|
||||
#include "SDL_main.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_cdrom.h"
|
||||
#include "SDL_cpuinfo.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_rwops.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_version.h"
|
||||
#include "SDL_compat.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* As of version 0.5, SDL is loaded dynamically into the application */
|
||||
|
||||
/* These are the flags which may be passed to SDL_Init() -- you should
|
||||
specify the subsystems which you will be using in your application.
|
||||
*/
|
||||
#define SDL_INIT_TIMER 0x00000001
|
||||
#define SDL_INIT_AUDIO 0x00000010
|
||||
#define SDL_INIT_VIDEO 0x00000020
|
||||
#define SDL_INIT_CDROM 0x00000100
|
||||
#define SDL_INIT_JOYSTICK 0x00000200
|
||||
#define SDL_INIT_HAPTIC 0x00001000
|
||||
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
|
||||
#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */
|
||||
#define SDL_INIT_EVERYTHING 0x0000FFFF
|
||||
|
||||
/* This function loads the SDL dynamically linked library and initializes
|
||||
* the subsystems specified by 'flags' (and those satisfying dependencies)
|
||||
* Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
|
||||
* signal handlers for some commonly ignored fatal signals (like SIGSEGV)
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
|
||||
|
||||
/* This function initializes specific SDL subsystems */
|
||||
extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
|
||||
|
||||
/* This function cleans up specific SDL subsystems */
|
||||
extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
|
||||
|
||||
/* This function returns mask of the specified subsystems which have
|
||||
been initialized.
|
||||
If 'flags' is 0, it returns a mask of all initialized subsystems.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
|
||||
|
||||
/* This function cleans up all initialized subsystems and unloads the
|
||||
* dynamically linked library. You should call it upon all exit conditions.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_Quit(void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL.h
|
||||
*
|
||||
* Main include header for the SDL library
|
||||
*/
|
||||
|
||||
/**
|
||||
* \mainpage Simple DirectMedia Layer (SDL)
|
||||
*
|
||||
* http://www.libsdl.org/
|
||||
*
|
||||
* \section intro_sec Introduction
|
||||
*
|
||||
* This is the Simple DirectMedia Layer, a general API that provides low
|
||||
* level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
|
||||
* and 2D framebuffer across multiple platforms.
|
||||
*
|
||||
* The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
|
||||
* Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
|
||||
* The code contains support for AIX, OSF/Tru64, RISC OS, and SymbianOS,
|
||||
* but these are not officially supported.
|
||||
*
|
||||
* SDL is written in C, but works with C++ natively, and has bindings to
|
||||
* several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
|
||||
* Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
|
||||
* Pike, Pliant, Python, Ruby, and Smalltalk.
|
||||
*
|
||||
* This library is distributed under GNU LGPL version 2, which can be
|
||||
* found in the file "COPYING". This license allows you to use SDL
|
||||
* freely in commercial programs as long as you link with the dynamic
|
||||
* library.
|
||||
*
|
||||
* The best way to learn how to use SDL is to check out the header files in
|
||||
* the "include" subdirectory and the programs in the "test" subdirectory.
|
||||
* The header files and test programs are well commented and always up to date.
|
||||
* More documentation is available in HTML format in "docs/index.html", and
|
||||
* a documentation wiki is available online at:
|
||||
* http://www.libsdl.org/cgi/docwiki.cgi
|
||||
*
|
||||
* The test programs in the "test" subdirectory are in the public domain.
|
||||
*
|
||||
* Frequently asked questions are answered online:
|
||||
* http://www.libsdl.org/faq.php
|
||||
*
|
||||
* If you need help with the library, or just want to discuss SDL related
|
||||
* issues, you can join the developers mailing list:
|
||||
* http://www.libsdl.org/mailing-list.php
|
||||
*
|
||||
* Enjoy!
|
||||
* Sam Lantinga (slouken@libsdl.org)
|
||||
*/
|
||||
|
||||
#ifndef _SDL_H
|
||||
#define _SDL_H
|
||||
|
||||
#include "SDL_main.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_atomic.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_cpuinfo.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_power.h"
|
||||
#include "SDL_rwops.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_version.h"
|
||||
#include "SDL_compat.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* As of version 0.5, SDL is loaded dynamically into the application */
|
||||
|
||||
/**
|
||||
* \name SDL_INIT_*
|
||||
*
|
||||
* These are the flags which may be passed to SDL_Init(). You should
|
||||
* specify the subsystems which you will be using in your application.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_INIT_TIMER 0x00000001
|
||||
#define SDL_INIT_AUDIO 0x00000010
|
||||
#define SDL_INIT_VIDEO 0x00000020
|
||||
#define SDL_INIT_JOYSTICK 0x00000200
|
||||
#define SDL_INIT_HAPTIC 0x00001000
|
||||
#define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */
|
||||
#define SDL_INIT_EVENTTHREAD 0x01000000 /**< Not supported on all OS's */
|
||||
#define SDL_INIT_EVERYTHING 0x0000FFFF
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* This function loads the SDL dynamically linked library and initializes
|
||||
* the subsystems specified by \c flags (and those satisfying dependencies).
|
||||
* Unless the ::SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
|
||||
* signal handlers for some commonly ignored fatal signals (like SIGSEGV).
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
|
||||
|
||||
/**
|
||||
* This function initializes specific SDL subsystems
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
|
||||
|
||||
/**
|
||||
* This function cleans up specific SDL subsystems
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
|
||||
|
||||
/**
|
||||
* This function returns mask of the specified subsystems which have
|
||||
* been initialized.
|
||||
*
|
||||
* If \c flags is 0, it returns a mask of all initialized subsystems.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
|
||||
|
||||
/**
|
||||
* This function cleans up all initialized subsystems and unloads the
|
||||
* dynamically linked library. You should call it upon all exit conditions.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_Quit(void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,423 +1,505 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_audio.h
|
||||
*
|
||||
* Access to the raw audio mixing buffer for the SDL library
|
||||
*/
|
||||
|
||||
#ifndef _SDL_audio_h
|
||||
#define _SDL_audio_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_rwops.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
typedef Uint16 SDL_AudioFormat;
|
||||
|
||||
/* The calculated values in this structure are calculated by SDL_OpenAudio() */
|
||||
typedef struct SDL_AudioSpec
|
||||
{
|
||||
int freq; /* DSP frequency -- samples per second */
|
||||
SDL_AudioFormat format; /* Audio data format */
|
||||
Uint8 channels; /* Number of channels: 1 mono, 2 stereo */
|
||||
Uint8 silence; /* Audio buffer silence value (calculated) */
|
||||
Uint16 samples; /* Audio buffer size in samples (power of 2) */
|
||||
Uint16 padding; /* Necessary for some compile environments */
|
||||
Uint32 size; /* Audio buffer size in bytes (calculated) */
|
||||
/* This function is called when the audio device needs more data.
|
||||
'stream' is a pointer to the audio data buffer
|
||||
'len' is the length of that buffer in bytes.
|
||||
Once the callback returns, the buffer will no longer be valid.
|
||||
Stereo samples are stored in a LRLRLR ordering.
|
||||
*/
|
||||
void (SDLCALL * callback) (void *userdata, Uint8 * stream, int len);
|
||||
void *userdata;
|
||||
} SDL_AudioSpec;
|
||||
|
||||
|
||||
/*
|
||||
These are what the 16 bits in SDL_AudioFormat currently mean...
|
||||
(Unspecified bits are always zero.)
|
||||
|
||||
++-----------------------sample is signed if set
|
||||
||
|
||||
|| ++-----------sample is bigendian if set
|
||||
|| ||
|
||||
|| || ++---sample is float if set
|
||||
|| || ||
|
||||
|| || || +---sample bit size---+
|
||||
|| || || | |
|
||||
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
|
||||
|
||||
There are macros in SDL 1.3 and later to query these bits.
|
||||
*/
|
||||
|
||||
#define SDL_AUDIO_MASK_BITSIZE (0xFF)
|
||||
#define SDL_AUDIO_MASK_DATATYPE (1<<8)
|
||||
#define SDL_AUDIO_MASK_ENDIAN (1<<12)
|
||||
#define SDL_AUDIO_MASK_SIGNED (1<<15)
|
||||
#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
|
||||
#define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
|
||||
#define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
|
||||
#define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
|
||||
#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
|
||||
#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
|
||||
#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
|
||||
|
||||
/* Audio format flags (defaults to LSB byte order) */
|
||||
#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */
|
||||
#define AUDIO_S8 0x8008 /* Signed 8-bit samples */
|
||||
#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */
|
||||
#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */
|
||||
#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */
|
||||
#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */
|
||||
#define AUDIO_U16 AUDIO_U16LSB
|
||||
#define AUDIO_S16 AUDIO_S16LSB
|
||||
|
||||
/* int32 support new to SDL 1.3 */
|
||||
#define AUDIO_S32LSB 0x8020 /* 32-bit integer samples */
|
||||
#define AUDIO_S32MSB 0x9020 /* As above, but big-endian byte order */
|
||||
#define AUDIO_S32 AUDIO_S32LSB
|
||||
|
||||
/* float32 support new to SDL 1.3 */
|
||||
#define AUDIO_F32LSB 0x8120 /* 32-bit floating point samples */
|
||||
#define AUDIO_F32MSB 0x9120 /* As above, but big-endian byte order */
|
||||
#define AUDIO_F32 AUDIO_F32LSB
|
||||
|
||||
/* Native audio byte ordering */
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
#define AUDIO_U16SYS AUDIO_U16LSB
|
||||
#define AUDIO_S16SYS AUDIO_S16LSB
|
||||
#define AUDIO_S32SYS AUDIO_S32LSB
|
||||
#define AUDIO_F32SYS AUDIO_F32LSB
|
||||
#else
|
||||
#define AUDIO_U16SYS AUDIO_U16MSB
|
||||
#define AUDIO_S16SYS AUDIO_S16MSB
|
||||
#define AUDIO_S32SYS AUDIO_S32MSB
|
||||
#define AUDIO_F32SYS AUDIO_F32MSB
|
||||
#endif
|
||||
|
||||
/* Which audio format changes are allowed when opening a device */
|
||||
#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
|
||||
#define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
|
||||
#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
|
||||
#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
|
||||
|
||||
/* A structure to hold a set of audio conversion filters and buffers */
|
||||
struct SDL_AudioCVT;
|
||||
typedef void (SDLCALL * SDL_AudioFilter) (struct SDL_AudioCVT * cvt,
|
||||
SDL_AudioFormat format);
|
||||
|
||||
typedef struct SDL_AudioCVT
|
||||
{
|
||||
int needed; /* Set to 1 if conversion possible */
|
||||
SDL_AudioFormat src_format; /* Source audio format */
|
||||
SDL_AudioFormat dst_format; /* Target audio format */
|
||||
double rate_incr; /* Rate conversion increment */
|
||||
Uint8 *buf; /* Buffer to hold entire audio data */
|
||||
int len; /* Length of original audio buffer */
|
||||
int len_cvt; /* Length of converted audio buffer */
|
||||
int len_mult; /* buffer must be len*len_mult big */
|
||||
double len_ratio; /* Given len, final size is len*len_ratio */
|
||||
SDL_AudioFilter filters[10]; /* Filter list */
|
||||
int filter_index; /* Current audio conversion function */
|
||||
} SDL_AudioCVT;
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* These functions return the list of built in audio drivers, in the
|
||||
* order that they are normally initialized by default.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
|
||||
|
||||
/* These functions are used internally, and should not be used unless you
|
||||
* have a specific need to specify the audio driver you want to use.
|
||||
* You should normally use SDL_Init() or SDL_InitSubSystem().
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
|
||||
extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
|
||||
|
||||
/* This function returns the name of the current audio driver, or NULL
|
||||
* if no driver has been initialized.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
|
||||
|
||||
/*
|
||||
* This function opens the audio device with the desired parameters, and
|
||||
* returns 0 if successful, placing the actual hardware parameters in the
|
||||
* structure pointed to by 'obtained'. If 'obtained' is NULL, the audio
|
||||
* data passed to the callback function will be guaranteed to be in the
|
||||
* requested format, and will be automatically converted to the hardware
|
||||
* audio format if necessary. This function returns -1 if it failed
|
||||
* to open the audio device, or couldn't set up the audio thread.
|
||||
*
|
||||
* When filling in the desired audio spec structure,
|
||||
* 'desired->freq' should be the desired audio frequency in samples-per-second.
|
||||
* 'desired->format' should be the desired audio format.
|
||||
* 'desired->samples' is the desired size of the audio buffer, in samples.
|
||||
* This number should be a power of two, and may be adjusted by the audio
|
||||
* driver to a value more suitable for the hardware. Good values seem to
|
||||
* range between 512 and 8096 inclusive, depending on the application and
|
||||
* CPU speed. Smaller values yield faster response time, but can lead
|
||||
* to underflow if the application is doing heavy processing and cannot
|
||||
* fill the audio buffer in time. A stereo sample consists of both right
|
||||
* and left channels in LR ordering.
|
||||
* Note that the number of samples is directly related to time by the
|
||||
* following formula: ms = (samples*1000)/freq
|
||||
* 'desired->size' is the size in bytes of the audio buffer, and is
|
||||
* calculated by SDL_OpenAudio().
|
||||
* 'desired->silence' is the value used to set the buffer to silence,
|
||||
* and is calculated by SDL_OpenAudio().
|
||||
* 'desired->callback' should be set to a function that will be called
|
||||
* when the audio device is ready for more data. It is passed a pointer
|
||||
* to the audio buffer, and the length in bytes of the audio buffer.
|
||||
* This function usually runs in a separate thread, and so you should
|
||||
* protect data structures that it accesses by calling SDL_LockAudio()
|
||||
* and SDL_UnlockAudio() in your code.
|
||||
* 'desired->userdata' is passed as the first parameter to your callback
|
||||
* function.
|
||||
*
|
||||
* The audio device starts out playing silence when it's opened, and should
|
||||
* be enabled for playing by calling SDL_PauseAudio(0) when you are ready
|
||||
* for your audio callback function to be called. Since the audio driver
|
||||
* may modify the requested size of the audio buffer, you should allocate
|
||||
* any local mixing buffers after you open the audio device.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired,
|
||||
SDL_AudioSpec * obtained);
|
||||
|
||||
/*
|
||||
* SDL Audio Device IDs.
|
||||
* A successful call to SDL_OpenAudio() is always device id 1, and legacy
|
||||
* SDL audio APIs assume you want this device ID. SDL_OpenAudioDevice() calls
|
||||
* always returns devices >= 2 on success. The legacy calls are good both
|
||||
* for backwards compatibility and when you don't care about multiple,
|
||||
* specific, or capture devices.
|
||||
*/
|
||||
typedef Uint32 SDL_AudioDeviceID;
|
||||
|
||||
/*
|
||||
* Get the number of available devices exposed by the current driver.
|
||||
* Only valid after a successfully initializing the audio subsystem.
|
||||
* Returns -1 if an explicit list of devices can't be determined; this is
|
||||
* not an error. For example, if SDL is set up to talk to a remote audio
|
||||
* server, it can't list every one available on the Internet, but it will
|
||||
* still allow a specific host to be specified to SDL_OpenAudioDevice().
|
||||
* In many common cases, when this function returns a value <= 0, it can still
|
||||
* successfully open the default device (NULL for first argument of
|
||||
* SDL_OpenAudioDevice()).
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
|
||||
|
||||
/*
|
||||
* Get the human-readable name of a specific audio device.
|
||||
* Must be a value between 0 and (number of audio devices-1).
|
||||
* Only valid after a successfully initializing the audio subsystem.
|
||||
* The values returned by this function reflect the latest call to
|
||||
* SDL_GetNumAudioDevices(); recall that function to redetect available
|
||||
* hardware.
|
||||
*
|
||||
* The string returned by this function is UTF-8 encoded, read-only, and
|
||||
* managed internally. You are not to free it. If you need to keep the
|
||||
* string for any length of time, you should make your own copy of it, as it
|
||||
* will be invalid next time any of several other SDL functions is called.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
|
||||
int iscapture);
|
||||
|
||||
|
||||
/*
|
||||
* Open a specific audio device. Passing in a device name of NULL requests
|
||||
* the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
|
||||
* The device name is a UTF-8 string reported by SDL_GetAudioDevice(), but
|
||||
* some drivers allow arbitrary and driver-specific strings, such as a
|
||||
* hostname/IP address for a remote audio server, or a filename in the
|
||||
* diskaudio driver.
|
||||
* Returns 0 on error, a valid device ID that is >= 2 on success.
|
||||
* SDL_OpenAudio(), unlike this function, always acts on device ID 1.
|
||||
*/
|
||||
extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(const char
|
||||
*device,
|
||||
int iscapture,
|
||||
const
|
||||
SDL_AudioSpec *
|
||||
desired,
|
||||
SDL_AudioSpec *
|
||||
obtained,
|
||||
int
|
||||
allowed_changes);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Get the current audio state:
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SDL_AUDIO_STOPPED = 0,
|
||||
SDL_AUDIO_PLAYING,
|
||||
SDL_AUDIO_PAUSED
|
||||
} SDL_audiostatus;
|
||||
extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void);
|
||||
|
||||
extern DECLSPEC SDL_audiostatus SDLCALL
|
||||
SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
|
||||
|
||||
/*
|
||||
* This function pauses and unpauses the audio callback processing.
|
||||
* It should be called with a parameter of 0 after opening the audio
|
||||
* device to start playing sound. This is so you can safely initialize
|
||||
* data for your callback function after opening the audio device.
|
||||
* Silence will be written to the audio device during the pause.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
|
||||
extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
|
||||
int pause_on);
|
||||
|
||||
/*
|
||||
* This function loads a WAVE from the data source, automatically freeing
|
||||
* that source if 'freesrc' is non-zero. For example, to load a WAVE file,
|
||||
* you could do:
|
||||
* SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
|
||||
*
|
||||
* If this function succeeds, it returns the given SDL_AudioSpec,
|
||||
* filled with the audio data format of the wave data, and sets
|
||||
* 'audio_buf' to a malloc()'d buffer containing the audio data,
|
||||
* and sets 'audio_len' to the length of that audio buffer, in bytes.
|
||||
* You need to free the audio buffer with SDL_FreeWAV() when you are
|
||||
* done with it.
|
||||
*
|
||||
* This function returns NULL and sets the SDL error message if the
|
||||
* wave file cannot be opened, uses an unknown data format, or is
|
||||
* corrupt. Currently raw and MS-ADPCM WAVE files are supported.
|
||||
*/
|
||||
extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
|
||||
int freesrc,
|
||||
SDL_AudioSpec * spec,
|
||||
Uint8 ** audio_buf,
|
||||
Uint32 * audio_len);
|
||||
|
||||
/* Compatibility convenience function -- loads a WAV from a file */
|
||||
#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
|
||||
SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
|
||||
|
||||
/*
|
||||
* This function frees data previously allocated with SDL_LoadWAV_RW()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 * audio_buf);
|
||||
|
||||
/*
|
||||
* This function takes a source format and rate and a destination format
|
||||
* and rate, and initializes the 'cvt' structure with information needed
|
||||
* by SDL_ConvertAudio() to convert a buffer of audio data from one format
|
||||
* to the other.
|
||||
* Returns -1 if the format conversion is not supported, 0 if there's
|
||||
* no conversion needed, or 1 if the audio filter is set up.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
|
||||
SDL_AudioFormat src_format,
|
||||
Uint8 src_channels,
|
||||
int src_rate,
|
||||
SDL_AudioFormat dst_format,
|
||||
Uint8 dst_channels,
|
||||
int dst_rate);
|
||||
|
||||
/* Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(),
|
||||
* created an audio buffer cvt->buf, and filled it with cvt->len bytes of
|
||||
* audio data in the source format, this function will convert it in-place
|
||||
* to the desired format.
|
||||
* The data conversion may expand the size of the audio data, so the buffer
|
||||
* cvt->buf should be allocated after the cvt structure is initialized by
|
||||
* SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT * cvt);
|
||||
|
||||
/*
|
||||
* This takes two audio buffers of the playing audio format and mixes
|
||||
* them, performing addition, volume adjustment, and overflow clipping.
|
||||
* The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME
|
||||
* for full audio volume. Note this does not change hardware volume.
|
||||
* This is provided for convenience -- you can mix your own audio data.
|
||||
*/
|
||||
#define SDL_MIX_MAXVOLUME 128
|
||||
extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
|
||||
Uint32 len, int volume);
|
||||
|
||||
/*
|
||||
* This works like SDL_MixAudio, but you specify the audio format instead of
|
||||
* using the format of audio device 1. Thus it can be used when no audio
|
||||
* device is open at all.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
|
||||
const Uint8 * src,
|
||||
SDL_AudioFormat format,
|
||||
Uint32 len, int volume);
|
||||
|
||||
/*
|
||||
* The lock manipulated by these functions protects the callback function.
|
||||
* During a LockAudio/UnlockAudio pair, you can be guaranteed that the
|
||||
* callback function is not running. Do not call these from the callback
|
||||
* function or you will cause deadlock.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_LockAudio(void);
|
||||
extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
|
||||
extern DECLSPEC void SDLCALL SDL_UnlockAudio(void);
|
||||
extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
|
||||
|
||||
/*
|
||||
* This function shuts down audio processing and closes the audio device.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_CloseAudio(void);
|
||||
extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
|
||||
|
||||
/*
|
||||
* Returns 1 if audio device is still functioning, zero if not, -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AudioDeviceConnected(SDL_AudioDeviceID dev);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_audio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_audio.h
|
||||
*
|
||||
* Access to the raw audio mixing buffer for the SDL library.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_audio_h
|
||||
#define _SDL_audio_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_rwops.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Audio format flags.
|
||||
*
|
||||
* These are what the 16 bits in SDL_AudioFormat currently mean...
|
||||
* (Unspecified bits are always zero).
|
||||
*
|
||||
* \verbatim
|
||||
++-----------------------sample is signed if set
|
||||
||
|
||||
|| ++-----------sample is bigendian if set
|
||||
|| ||
|
||||
|| || ++---sample is float if set
|
||||
|| || ||
|
||||
|| || || +---sample bit size---+
|
||||
|| || || | |
|
||||
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
|
||||
\endverbatim
|
||||
*
|
||||
* There are macros in SDL 1.3 and later to query these bits.
|
||||
*/
|
||||
typedef Uint16 SDL_AudioFormat;
|
||||
|
||||
/**
|
||||
* \name Audio flags
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
#define SDL_AUDIO_MASK_BITSIZE (0xFF)
|
||||
#define SDL_AUDIO_MASK_DATATYPE (1<<8)
|
||||
#define SDL_AUDIO_MASK_ENDIAN (1<<12)
|
||||
#define SDL_AUDIO_MASK_SIGNED (1<<15)
|
||||
#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
|
||||
#define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
|
||||
#define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
|
||||
#define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
|
||||
#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
|
||||
#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
|
||||
#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
|
||||
|
||||
/**
|
||||
* \name Audio format flags
|
||||
*
|
||||
* Defaults to LSB byte order.
|
||||
*/
|
||||
/*@{*/
|
||||
#define AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
|
||||
#define AUDIO_S8 0x8008 /**< Signed 8-bit samples */
|
||||
#define AUDIO_U16LSB 0x0010 /**< Unsigned 16-bit samples */
|
||||
#define AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
|
||||
#define AUDIO_U16MSB 0x1010 /**< As above, but big-endian byte order */
|
||||
#define AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
|
||||
#define AUDIO_U16 AUDIO_U16LSB
|
||||
#define AUDIO_S16 AUDIO_S16LSB
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* \name int32 support
|
||||
*
|
||||
* New to SDL 1.3.
|
||||
*/
|
||||
/*@{*/
|
||||
#define AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
|
||||
#define AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
|
||||
#define AUDIO_S32 AUDIO_S32LSB
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* \name float32 support
|
||||
*
|
||||
* New to SDL 1.3.
|
||||
*/
|
||||
/*@{*/
|
||||
#define AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
|
||||
#define AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
|
||||
#define AUDIO_F32 AUDIO_F32LSB
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* \name Native audio byte ordering
|
||||
*/
|
||||
/*@{*/
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
#define AUDIO_U16SYS AUDIO_U16LSB
|
||||
#define AUDIO_S16SYS AUDIO_S16LSB
|
||||
#define AUDIO_S32SYS AUDIO_S32LSB
|
||||
#define AUDIO_F32SYS AUDIO_F32LSB
|
||||
#else
|
||||
#define AUDIO_U16SYS AUDIO_U16MSB
|
||||
#define AUDIO_S16SYS AUDIO_S16MSB
|
||||
#define AUDIO_S32SYS AUDIO_S32MSB
|
||||
#define AUDIO_F32SYS AUDIO_F32MSB
|
||||
#endif
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* \name Allow change flags
|
||||
*
|
||||
* Which audio format changes are allowed when opening a device.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
|
||||
#define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
|
||||
#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
|
||||
#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
|
||||
/*@}*/
|
||||
|
||||
/*@}*//*Audio flags*/
|
||||
|
||||
/**
|
||||
* The calculated values in this structure are calculated by SDL_OpenAudio().
|
||||
*/
|
||||
typedef struct SDL_AudioSpec
|
||||
{
|
||||
int freq; /**< DSP frequency -- samples per second */
|
||||
SDL_AudioFormat format; /**< Audio data format */
|
||||
Uint8 channels; /**< Number of channels: 1 mono, 2 stereo */
|
||||
Uint8 silence; /**< Audio buffer silence value (calculated) */
|
||||
Uint16 samples; /**< Audio buffer size in samples (power of 2) */
|
||||
Uint16 padding; /**< Necessary for some compile environments */
|
||||
Uint32 size; /**< Audio buffer size in bytes (calculated) */
|
||||
/**
|
||||
* This function is called when the audio device needs more data.
|
||||
*
|
||||
* \param stream A pointer to the audio data buffer.
|
||||
* \param len The length of that buffer in bytes.
|
||||
*
|
||||
* Once the callback returns, the buffer will no longer be valid.
|
||||
* Stereo samples are stored in a LRLRLR ordering.
|
||||
*/
|
||||
void (SDLCALL * callback) (void *userdata, Uint8 * stream, int len);
|
||||
void *userdata;
|
||||
} SDL_AudioSpec;
|
||||
|
||||
|
||||
struct SDL_AudioCVT;
|
||||
typedef void (SDLCALL * SDL_AudioFilter) (struct SDL_AudioCVT * cvt,
|
||||
SDL_AudioFormat format);
|
||||
|
||||
/**
|
||||
* A structure to hold a set of audio conversion filters and buffers.
|
||||
*/
|
||||
typedef struct SDL_AudioCVT
|
||||
{
|
||||
int needed; /**< Set to 1 if conversion possible */
|
||||
SDL_AudioFormat src_format; /**< Source audio format */
|
||||
SDL_AudioFormat dst_format; /**< Target audio format */
|
||||
double rate_incr; /**< Rate conversion increment */
|
||||
Uint8 *buf; /**< Buffer to hold entire audio data */
|
||||
int len; /**< Length of original audio buffer */
|
||||
int len_cvt; /**< Length of converted audio buffer */
|
||||
int len_mult; /**< buffer must be len*len_mult big */
|
||||
double len_ratio; /**< Given len, final size is len*len_ratio */
|
||||
SDL_AudioFilter filters[10]; /**< Filter list */
|
||||
int filter_index; /**< Current audio conversion function */
|
||||
} SDL_AudioCVT;
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
* \name Driver discovery functions
|
||||
*
|
||||
* These functions return the list of built in audio drivers, in the
|
||||
* order that they are normally initialized by default.
|
||||
*/
|
||||
/*@{*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* \name Initialization and cleanup
|
||||
*
|
||||
* \internal These functions are used internally, and should not be used unless
|
||||
* you have a specific need to specify the audio driver you want to
|
||||
* use. You should normally use SDL_Init() or SDL_InitSubSystem().
|
||||
*/
|
||||
/*@{*/
|
||||
extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
|
||||
extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* This function returns the name of the current audio driver, or NULL
|
||||
* if no driver has been initialized.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
|
||||
|
||||
/**
|
||||
* This function opens the audio device with the desired parameters, and
|
||||
* returns 0 if successful, placing the actual hardware parameters in the
|
||||
* structure pointed to by \c obtained. If \c obtained is NULL, the audio
|
||||
* data passed to the callback function will be guaranteed to be in the
|
||||
* requested format, and will be automatically converted to the hardware
|
||||
* audio format if necessary. This function returns -1 if it failed
|
||||
* to open the audio device, or couldn't set up the audio thread.
|
||||
*
|
||||
* When filling in the desired audio spec structure,
|
||||
* - \c desired->freq should be the desired audio frequency in samples-per-
|
||||
* second.
|
||||
* - \c desired->format should be the desired audio format.
|
||||
* - \c desired->samples is the desired size of the audio buffer, in
|
||||
* samples. This number should be a power of two, and may be adjusted by
|
||||
* the audio driver to a value more suitable for the hardware. Good values
|
||||
* seem to range between 512 and 8096 inclusive, depending on the
|
||||
* application and CPU speed. Smaller values yield faster response time,
|
||||
* but can lead to underflow if the application is doing heavy processing
|
||||
* and cannot fill the audio buffer in time. A stereo sample consists of
|
||||
* both right and left channels in LR ordering.
|
||||
* Note that the number of samples is directly related to time by the
|
||||
* following formula: \code ms = (samples*1000)/freq \endcode
|
||||
* - \c desired->size is the size in bytes of the audio buffer, and is
|
||||
* calculated by SDL_OpenAudio().
|
||||
* - \c desired->silence is the value used to set the buffer to silence,
|
||||
* and is calculated by SDL_OpenAudio().
|
||||
* - \c desired->callback should be set to a function that will be called
|
||||
* when the audio device is ready for more data. It is passed a pointer
|
||||
* to the audio buffer, and the length in bytes of the audio buffer.
|
||||
* This function usually runs in a separate thread, and so you should
|
||||
* protect data structures that it accesses by calling SDL_LockAudio()
|
||||
* and SDL_UnlockAudio() in your code.
|
||||
* - \c desired->userdata is passed as the first parameter to your callback
|
||||
* function.
|
||||
*
|
||||
* The audio device starts out playing silence when it's opened, and should
|
||||
* be enabled for playing by calling \c SDL_PauseAudio(0) when you are ready
|
||||
* for your audio callback function to be called. Since the audio driver
|
||||
* may modify the requested size of the audio buffer, you should allocate
|
||||
* any local mixing buffers after you open the audio device.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired,
|
||||
SDL_AudioSpec * obtained);
|
||||
|
||||
/**
|
||||
* SDL Audio Device IDs.
|
||||
*
|
||||
* A successful call to SDL_OpenAudio() is always device id 1, and legacy
|
||||
* SDL audio APIs assume you want this device ID. SDL_OpenAudioDevice() calls
|
||||
* always returns devices >= 2 on success. The legacy calls are good both
|
||||
* for backwards compatibility and when you don't care about multiple,
|
||||
* specific, or capture devices.
|
||||
*/
|
||||
typedef Uint32 SDL_AudioDeviceID;
|
||||
|
||||
/**
|
||||
* Get the number of available devices exposed by the current driver.
|
||||
* Only valid after a successfully initializing the audio subsystem.
|
||||
* Returns -1 if an explicit list of devices can't be determined; this is
|
||||
* not an error. For example, if SDL is set up to talk to a remote audio
|
||||
* server, it can't list every one available on the Internet, but it will
|
||||
* still allow a specific host to be specified to SDL_OpenAudioDevice().
|
||||
*
|
||||
* In many common cases, when this function returns a value <= 0, it can still
|
||||
* successfully open the default device (NULL for first argument of
|
||||
* SDL_OpenAudioDevice()).
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
|
||||
|
||||
/**
|
||||
* Get the human-readable name of a specific audio device.
|
||||
* Must be a value between 0 and (number of audio devices-1).
|
||||
* Only valid after a successfully initializing the audio subsystem.
|
||||
* The values returned by this function reflect the latest call to
|
||||
* SDL_GetNumAudioDevices(); recall that function to redetect available
|
||||
* hardware.
|
||||
*
|
||||
* The string returned by this function is UTF-8 encoded, read-only, and
|
||||
* managed internally. You are not to free it. If you need to keep the
|
||||
* string for any length of time, you should make your own copy of it, as it
|
||||
* will be invalid next time any of several other SDL functions is called.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
|
||||
int iscapture);
|
||||
|
||||
|
||||
/**
|
||||
* Open a specific audio device. Passing in a device name of NULL requests
|
||||
* the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
|
||||
*
|
||||
* The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but
|
||||
* some drivers allow arbitrary and driver-specific strings, such as a
|
||||
* hostname/IP address for a remote audio server, or a filename in the
|
||||
* diskaudio driver.
|
||||
*
|
||||
* \return 0 on error, a valid device ID that is >= 2 on success.
|
||||
*
|
||||
* SDL_OpenAudio(), unlike this function, always acts on device ID 1.
|
||||
*/
|
||||
extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(const char
|
||||
*device,
|
||||
int iscapture,
|
||||
const
|
||||
SDL_AudioSpec *
|
||||
desired,
|
||||
SDL_AudioSpec *
|
||||
obtained,
|
||||
int
|
||||
allowed_changes);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \name Audio state
|
||||
*
|
||||
* Get the current audio state.
|
||||
*/
|
||||
/*@{*/
|
||||
typedef enum
|
||||
{
|
||||
SDL_AUDIO_STOPPED = 0,
|
||||
SDL_AUDIO_PLAYING,
|
||||
SDL_AUDIO_PAUSED
|
||||
} SDL_audiostatus;
|
||||
extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void);
|
||||
|
||||
extern DECLSPEC SDL_audiostatus SDLCALL
|
||||
SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
|
||||
/*@}*//*Audio State*/
|
||||
|
||||
/**
|
||||
* \name Pause audio functions
|
||||
*
|
||||
* These functions pause and unpause the audio callback processing.
|
||||
* They should be called with a parameter of 0 after opening the audio
|
||||
* device to start playing sound. This is so you can safely initialize
|
||||
* data for your callback function after opening the audio device.
|
||||
* Silence will be written to the audio device during the pause.
|
||||
*/
|
||||
/*@{*/
|
||||
extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
|
||||
extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
|
||||
int pause_on);
|
||||
/*@}*//*Pause audio functions*/
|
||||
|
||||
/**
|
||||
* This function loads a WAVE from the data source, automatically freeing
|
||||
* that source if \c freesrc is non-zero. For example, to load a WAVE file,
|
||||
* you could do:
|
||||
* \code
|
||||
* SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
|
||||
* \endcode
|
||||
*
|
||||
* If this function succeeds, it returns the given SDL_AudioSpec,
|
||||
* filled with the audio data format of the wave data, and sets
|
||||
* \c *audio_buf to a malloc()'d buffer containing the audio data,
|
||||
* and sets \c *audio_len to the length of that audio buffer, in bytes.
|
||||
* You need to free the audio buffer with SDL_FreeWAV() when you are
|
||||
* done with it.
|
||||
*
|
||||
* This function returns NULL and sets the SDL error message if the
|
||||
* wave file cannot be opened, uses an unknown data format, or is
|
||||
* corrupt. Currently raw and MS-ADPCM WAVE files are supported.
|
||||
*/
|
||||
extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
|
||||
int freesrc,
|
||||
SDL_AudioSpec * spec,
|
||||
Uint8 ** audio_buf,
|
||||
Uint32 * audio_len);
|
||||
|
||||
/**
|
||||
* Loads a WAV from a file.
|
||||
* Compatibility convenience function.
|
||||
*/
|
||||
#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
|
||||
SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
|
||||
|
||||
/**
|
||||
* This function frees data previously allocated with SDL_LoadWAV_RW()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 * audio_buf);
|
||||
|
||||
/**
|
||||
* This function takes a source format and rate and a destination format
|
||||
* and rate, and initializes the \c cvt structure with information needed
|
||||
* by SDL_ConvertAudio() to convert a buffer of audio data from one format
|
||||
* to the other.
|
||||
*
|
||||
* \return -1 if the format conversion is not supported, 0 if there's
|
||||
* no conversion needed, or 1 if the audio filter is set up.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
|
||||
SDL_AudioFormat src_format,
|
||||
Uint8 src_channels,
|
||||
int src_rate,
|
||||
SDL_AudioFormat dst_format,
|
||||
Uint8 dst_channels,
|
||||
int dst_rate);
|
||||
|
||||
/**
|
||||
* Once you have initialized the \c cvt structure using SDL_BuildAudioCVT(),
|
||||
* created an audio buffer \c cvt->buf, and filled it with \c cvt->len bytes of
|
||||
* audio data in the source format, this function will convert it in-place
|
||||
* to the desired format.
|
||||
*
|
||||
* The data conversion may expand the size of the audio data, so the buffer
|
||||
* \c cvt->buf should be allocated after the \c cvt structure is initialized by
|
||||
* SDL_BuildAudioCVT(), and should be \c cvt->len*cvt->len_mult bytes long.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT * cvt);
|
||||
|
||||
#define SDL_MIX_MAXVOLUME 128
|
||||
/**
|
||||
* This takes two audio buffers of the playing audio format and mixes
|
||||
* them, performing addition, volume adjustment, and overflow clipping.
|
||||
* The volume ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME
|
||||
* for full audio volume. Note this does not change hardware volume.
|
||||
* This is provided for convenience -- you can mix your own audio data.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
|
||||
Uint32 len, int volume);
|
||||
|
||||
/**
|
||||
* This works like SDL_MixAudio(), but you specify the audio format instead of
|
||||
* using the format of audio device 1. Thus it can be used when no audio
|
||||
* device is open at all.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
|
||||
const Uint8 * src,
|
||||
SDL_AudioFormat format,
|
||||
Uint32 len, int volume);
|
||||
|
||||
/**
|
||||
* \name Audio lock functions
|
||||
*
|
||||
* The lock manipulated by these functions protects the callback function.
|
||||
* During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that
|
||||
* the callback function is not running. Do not call these from the callback
|
||||
* function or you will cause deadlock.
|
||||
*/
|
||||
/*@{*/
|
||||
extern DECLSPEC void SDLCALL SDL_LockAudio(void);
|
||||
extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
|
||||
extern DECLSPEC void SDLCALL SDL_UnlockAudio(void);
|
||||
extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
|
||||
/*@}*//*Audio lock functions*/
|
||||
|
||||
/**
|
||||
* This function shuts down audio processing and closes the audio device.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_CloseAudio(void);
|
||||
extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
|
||||
|
||||
/**
|
||||
* \return 1 if audio device is still functioning, zero if not, -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AudioDeviceConnected(SDL_AudioDeviceID dev);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_audio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -20,7 +20,30 @@
|
|||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/* This file contains functions for backwards compatibility with SDL 1.2 */
|
||||
/**
|
||||
* \defgroup Compatibility SDL 1.2 Compatibility API
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* \file SDL_compat.h
|
||||
*
|
||||
* This file contains functions for backwards compatibility with SDL 1.2.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def SDL_NO_COMPAT
|
||||
*
|
||||
* #define SDL_NO_COMPAT to prevent SDL_compat.h from being included.
|
||||
* SDL_NO_COMPAT is intended to make it easier to covert SDL 1.2 code to
|
||||
* SDL 1.3/2.0.
|
||||
*/
|
||||
|
||||
/*@}*/
|
||||
|
||||
#ifdef SDL_NO_COMPAT
|
||||
#define _SDL_compat_h
|
||||
#endif
|
||||
|
||||
#ifndef _SDL_compat_h
|
||||
#define _SDL_compat_h
|
||||
|
@ -36,7 +59,16 @@ extern "C" {
|
|||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
#define SDL_SWSURFACE 0x00000000 /* Not used */
|
||||
/**
|
||||
* \addtogroup Compatibility
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* \name Surface flags
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_SWSURFACE 0x00000000 /**< \note Not used */
|
||||
#define SDL_SRCALPHA 0x00010000
|
||||
#define SDL_SRCCOLORKEY 0x00020000
|
||||
#define SDL_ANYFORMAT 0x00100000
|
||||
|
@ -46,10 +78,11 @@ extern "C" {
|
|||
#define SDL_RESIZABLE 0x01000000
|
||||
#define SDL_NOFRAME 0x02000000
|
||||
#define SDL_OPENGL 0x04000000
|
||||
#define SDL_HWSURFACE 0x08000001 /* Not used */
|
||||
#define SDL_ASYNCBLIT 0x08000000 /* Not used */
|
||||
#define SDL_RLEACCELOK 0x08000000 /* Not used */
|
||||
#define SDL_HWACCEL 0x08000000 /* Not used */
|
||||
#define SDL_HWSURFACE 0x08000001 /**< \note Not used */
|
||||
#define SDL_ASYNCBLIT 0x08000000 /**< \note Not used */
|
||||
#define SDL_RLEACCELOK 0x08000000 /**< \note Not used */
|
||||
#define SDL_HWACCEL 0x08000000 /**< \note Not used */
|
||||
/*@}*//*Surface flags*/
|
||||
|
||||
#define SDL_APPMOUSEFOCUS 0x01
|
||||
#define SDL_APPINPUTFOCUS 0x02
|
||||
|
@ -93,35 +126,51 @@ typedef struct SDL_VideoInfo
|
|||
int current_h;
|
||||
} SDL_VideoInfo;
|
||||
|
||||
/* The most common video overlay formats.
|
||||
For an explanation of these pixel formats, see:
|
||||
http://www.webartz.com/fourcc/indexyuv.htm
|
||||
|
||||
For information on the relationship between color spaces, see:
|
||||
http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
|
||||
/**
|
||||
* \name Overlay formats
|
||||
*
|
||||
* The most common video overlay formats.
|
||||
*
|
||||
* For an explanation of these pixel formats, see:
|
||||
* http://www.webartz.com/fourcc/indexyuv.htm
|
||||
*
|
||||
* For information on the relationship between color spaces, see:
|
||||
* http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
|
||||
*/
|
||||
#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */
|
||||
#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */
|
||||
#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
|
||||
#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
|
||||
#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
|
||||
/*@{*/
|
||||
#define SDL_YV12_OVERLAY 0x32315659 /**< Planar mode: Y + V + U (3 planes) */
|
||||
#define SDL_IYUV_OVERLAY 0x56555949 /**< Planar mode: Y + U + V (3 planes) */
|
||||
#define SDL_YUY2_OVERLAY 0x32595559 /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
|
||||
#define SDL_UYVY_OVERLAY 0x59565955 /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
|
||||
#define SDL_YVYU_OVERLAY 0x55595659 /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
|
||||
/*@}*//*Overlay formats*/
|
||||
|
||||
/* The YUV hardware video overlay */
|
||||
/**
|
||||
* The YUV hardware video overlay.
|
||||
*/
|
||||
typedef struct SDL_Overlay
|
||||
{
|
||||
Uint32 format; /* Read-only */
|
||||
int w, h; /* Read-only */
|
||||
int planes; /* Read-only */
|
||||
Uint16 *pitches; /* Read-only */
|
||||
Uint8 **pixels; /* Read-write */
|
||||
Uint32 format; /**< Read-only */
|
||||
int w, h; /**< Read-only */
|
||||
int planes; /**< Read-only */
|
||||
Uint16 *pitches; /**< Read-only */
|
||||
Uint8 **pixels; /**< Read-write */
|
||||
|
||||
/* Hardware-specific surface info */
|
||||
/**
|
||||
* \name Hardware-specific surface info
|
||||
*/
|
||||
/*@{*/
|
||||
struct private_yuvhwfuncs *hwfuncs;
|
||||
struct private_yuvhwdata *hwdata;
|
||||
/*@}*//*Hardware-specific surface info*/
|
||||
|
||||
/* Special flags */
|
||||
Uint32 hw_overlay:1; /* Flag: This overlay hardware accelerated? */
|
||||
/**
|
||||
* \name Special flags
|
||||
*/
|
||||
/*@{*/
|
||||
Uint32 hw_overlay:1; /**< Flag: This overlay hardware accelerated? */
|
||||
Uint32 UnusedBits:31;
|
||||
/*@}*//*Special flags*/
|
||||
} SDL_Overlay;
|
||||
|
||||
typedef enum
|
||||
|
@ -133,9 +182,17 @@ typedef enum
|
|||
|
||||
struct SDL_SysWMinfo;
|
||||
|
||||
/* Obsolete or renamed key codes */
|
||||
/**
|
||||
* \name Obsolete or renamed key codes
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/* These key constants were renamed for clarity or consistency. */
|
||||
/**
|
||||
* \name Renamed keys
|
||||
*
|
||||
* These key constants were renamed for clarity or consistency.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDLK_0 '0'
|
||||
#define SDLK_1 '1'
|
||||
#define SDLK_2 '2'
|
||||
|
@ -204,19 +261,35 @@ struct SDL_SysWMinfo;
|
|||
#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR
|
||||
#define SDLK_SCROLLOCK SDLK_SCROLLLOCK
|
||||
#define SDLK_PRINT SDLK_PRINTSCREEN
|
||||
/*@}*//*Renamed keys*/
|
||||
|
||||
/* The META modifier is equivalent to the GUI modifier from the USB standard */
|
||||
/**
|
||||
* \name META modifier
|
||||
*
|
||||
* The META modifier is equivalent to the GUI modifier from the USB standard.
|
||||
*/
|
||||
/*@{*/
|
||||
#define KMOD_LMETA KMOD_LGUI
|
||||
#define KMOD_RMETA KMOD_RGUI
|
||||
#define KMOD_META KMOD_GUI
|
||||
/*@}*//*META modifier*/
|
||||
|
||||
/* These keys don't appear in the USB specification (or at least not under those names). I'm unsure if the following assignments make sense or if these codes should be defined as actual additional SDLK_ constants. */
|
||||
/**
|
||||
* \name Not in USB
|
||||
*
|
||||
* These keys don't appear in the USB specification (or at least not under
|
||||
* those names). I'm unsure if the following assignments make sense or if these
|
||||
* codes should be defined as actual additional SDLK_ constants.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDLK_LSUPER SDLK_LMETA
|
||||
#define SDLK_RSUPER SDLK_RMETA
|
||||
#define SDLK_COMPOSE SDLK_APPLICATION
|
||||
#define SDLK_BREAK SDLK_STOP
|
||||
#define SDLK_EURO SDLK_2
|
||||
/*@}*//*Not in USB*/
|
||||
|
||||
/*@}*//*Obsolete or renamed key codes*/
|
||||
|
||||
#define SDL_SetModuleHandle(x)
|
||||
#define SDL_AllocSurface SDL_CreateRGBSurface
|
||||
|
@ -277,6 +350,8 @@ extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
|
|||
extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
|
||||
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
|
||||
|
||||
/*@}*//*Compatibility*/
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
|
|
|
@ -1,45 +1,197 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_h
|
||||
#define _SDL_config_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* Add any platform that doesn't build using the configure system */
|
||||
#if defined(__NINTENDODS__)
|
||||
#include "SDL_config_nintendods.h"
|
||||
#elif defined(__DREAMCAST__)
|
||||
#include "SDL_config_dreamcast.h"
|
||||
#elif defined(__IPHONEOS__)
|
||||
#include "SDL_config_iphoneos.h"
|
||||
#elif defined(__MACOSX__)
|
||||
#include "SDL_config_macosx.h"
|
||||
#elif defined(__WIN32__)
|
||||
#include "SDL_config_win32.h"
|
||||
#elif defined(__OS2__)
|
||||
#include "SDL_config_os2.h"
|
||||
#else
|
||||
#include "SDL_config_minimal.h"
|
||||
#endif /* platform config */
|
||||
|
||||
#endif /* _SDL_config_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_win32_h
|
||||
#define _SDL_config_win32_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
|
||||
#if defined(__GNUC__) || defined(__DMC__)
|
||||
#define HAVE_STDINT_H 1
|
||||
#elif defined(_MSC_VER)
|
||||
typedef signed __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#ifndef _UINTPTR_T_DEFINED
|
||||
#ifdef _WIN64
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif
|
||||
#define _UINTPTR_T_DEFINED
|
||||
#endif
|
||||
/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
|
||||
#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
|
||||
#define DWORD_PTR DWORD
|
||||
#endif
|
||||
#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
|
||||
#define LONG_PTR LONG
|
||||
#endif
|
||||
#else /* !__GNUC__ && !_MSC_VER */
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#ifndef _SIZE_T_DEFINED_
|
||||
#define _SIZE_T_DEFINED_
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif /* __GNUC__ || _MSC_VER */
|
||||
#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
|
||||
|
||||
#ifdef _WIN64
|
||||
# define SIZEOF_VOIDP 8
|
||||
#else
|
||||
# define SIZEOF_VOIDP 4
|
||||
#endif
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
/* Enabled for SDL 1.2 (binary compatibility) */
|
||||
//#define HAVE_LIBC 1
|
||||
#ifdef HAVE_LIBC
|
||||
/* Useful headers */
|
||||
#define HAVE_STDIO_H 1
|
||||
#define STDC_HEADERS 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_CTYPE_H 1
|
||||
#define HAVE_MATH_H 1
|
||||
#ifndef _WIN32_WCE
|
||||
#define HAVE_SIGNAL_H 1
|
||||
#endif
|
||||
|
||||
/* C library functions */
|
||||
#define HAVE_MALLOC 1
|
||||
#define HAVE_CALLOC 1
|
||||
#define HAVE_REALLOC 1
|
||||
#define HAVE_FREE 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_QSORT 1
|
||||
#define HAVE_ABS 1
|
||||
#define HAVE_MEMSET 1
|
||||
#define HAVE_MEMCPY 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_MEMCMP 1
|
||||
#define HAVE_STRLEN 1
|
||||
#define HAVE__STRREV 1
|
||||
#define HAVE__STRUPR 1
|
||||
#define HAVE__STRLWR 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_ITOA 1
|
||||
#define HAVE__LTOA 1
|
||||
#define HAVE__ULTOA 1
|
||||
#define HAVE_STRTOL 1
|
||||
#define HAVE_STRTOUL 1
|
||||
#define HAVE_STRTOLL 1
|
||||
#define HAVE_STRTOD 1
|
||||
#define HAVE_ATOI 1
|
||||
#define HAVE_ATOF 1
|
||||
#define HAVE_STRCMP 1
|
||||
#define HAVE_STRNCMP 1
|
||||
#define HAVE__STRICMP 1
|
||||
#define HAVE__STRNICMP 1
|
||||
#define HAVE_SSCANF 1
|
||||
#define HAVE_M_PI 1
|
||||
#define HAVE_CEIL 1
|
||||
#define HAVE_COPYSIGN 1
|
||||
#define HAVE_COS 1
|
||||
#define HAVE_COSF 1
|
||||
#define HAVE_FABS 1
|
||||
#define HAVE_FLOOR 1
|
||||
#define HAVE_LOG 1
|
||||
#define HAVE_POW 1
|
||||
#define HAVE_SCALBN 1
|
||||
#define HAVE_SIN 1
|
||||
#define HAVE_SINF 1
|
||||
#define HAVE_SQRT 1
|
||||
#else
|
||||
#define HAVE_STDARG_H 1
|
||||
#define HAVE_STDDEF_H 1
|
||||
#endif
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#ifndef _WIN32_WCE
|
||||
#define SDL_AUDIO_DRIVER_DSOUND 1
|
||||
#endif
|
||||
#define SDL_AUDIO_DRIVER_WINWAVEOUT 1
|
||||
#define SDL_AUDIO_DRIVER_DISK 1
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable various input drivers */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_JOYSTICK_DISABLED 1
|
||||
#define SDL_HAPTIC_DUMMY 1
|
||||
#else
|
||||
#define SDL_JOYSTICK_DINPUT 1
|
||||
#define SDL_HAPTIC_DINPUT 1
|
||||
#endif
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#define SDL_LOADSO_WIN32 1
|
||||
|
||||
/* Enable various threading systems */
|
||||
#define SDL_THREAD_WIN32 1
|
||||
|
||||
/* Enable various timer systems */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_TIMER_WINCE 1
|
||||
#else
|
||||
#define SDL_TIMER_WIN32 1
|
||||
#endif
|
||||
|
||||
/* Enable various video drivers */
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
#define SDL_VIDEO_DRIVER_WIN32 1
|
||||
|
||||
#define SDL_VIDEO_RENDER_D3D 1
|
||||
#define SDL_VIDEO_RENDER_GDI 1
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#ifndef _WIN32_WCE
|
||||
#define SDL_VIDEO_OPENGL 1
|
||||
#define SDL_VIDEO_OPENGL_WGL 1
|
||||
#define SDL_VIDEO_RENDER_OGL 1
|
||||
#endif
|
||||
|
||||
/* Enable system power support */
|
||||
#define SDL_POWER_WINDOWS 1
|
||||
|
||||
/* Enable assembly routines (Win64 doesn't have inline asm) */
|
||||
#ifndef _WIN64
|
||||
#define SDL_ASSEMBLY_ROUTINES 1
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_config_win32_h */
|
||||
|
|
|
@ -1,45 +1,47 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_h
|
||||
#define _SDL_config_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* Add any platform that doesn't build using the configure system */
|
||||
#if defined(__NINTENDODS__)
|
||||
#include "SDL_config_nintendods.h"
|
||||
#elif defined(__DREAMCAST__)
|
||||
#include "SDL_config_dreamcast.h"
|
||||
#elif defined(__IPHONEOS__)
|
||||
#include "SDL_config_iphoneos.h"
|
||||
#elif defined(__MACOSX__)
|
||||
#include "SDL_config_macosx.h"
|
||||
#elif defined(__WIN32__)
|
||||
#include "SDL_config_win32.h"
|
||||
#elif defined(__OS2__)
|
||||
#include "SDL_config_os2.h"
|
||||
#else
|
||||
#include "SDL_config_minimal.h"
|
||||
#endif /* platform config */
|
||||
|
||||
#endif /* _SDL_config_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_h
|
||||
#define _SDL_config_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/**
|
||||
* \file SDL_config.h.default
|
||||
*
|
||||
* SDL_config.h for any platform that doesn't build using the configure system.
|
||||
*/
|
||||
|
||||
/* Add any platform that doesn't build using the configure system. */
|
||||
#if defined(__NINTENDODS__)
|
||||
#include "SDL_config_nintendods.h"
|
||||
#elif defined(__IPHONEOS__)
|
||||
#include "SDL_config_iphoneos.h"
|
||||
#elif defined(__MACOSX__)
|
||||
#include "SDL_config_macosx.h"
|
||||
#elif defined(__WIN32__)
|
||||
#include "SDL_config_win32.h"
|
||||
#else
|
||||
#include "SDL_config_minimal.h"
|
||||
#endif /* platform config */
|
||||
|
||||
#endif /* _SDL_config_h */
|
||||
|
|
|
@ -1,327 +1,308 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_h
|
||||
#define _SDL_config_h
|
||||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
/* General platform specific identifiers */
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* Make sure that this isn't included by Visual C++ */
|
||||
#ifdef _MSC_VER
|
||||
#error You should copy include/SDL_config.h.default to include/SDL_config.h
|
||||
#endif
|
||||
|
||||
/* C language features */
|
||||
#undef const
|
||||
#undef inline
|
||||
#undef volatile
|
||||
|
||||
/* C datatypes */
|
||||
#undef size_t
|
||||
#undef int8_t
|
||||
#undef uint8_t
|
||||
#undef int16_t
|
||||
#undef uint16_t
|
||||
#undef int32_t
|
||||
#undef uint32_t
|
||||
#undef int64_t
|
||||
#undef uint64_t
|
||||
#undef uintptr_t
|
||||
#undef SDL_HAS_64BIT_TYPE
|
||||
|
||||
/* Endianness */
|
||||
#undef SDL_BYTEORDER
|
||||
|
||||
/* Comment this if you want to build without any C library requirements */
|
||||
#undef HAVE_LIBC
|
||||
#if HAVE_LIBC
|
||||
|
||||
/* Useful headers */
|
||||
#undef HAVE_ALLOCA_H
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
#undef HAVE_STDIO_H
|
||||
#undef STDC_HEADERS
|
||||
#undef HAVE_STDLIB_H
|
||||
#undef HAVE_STDARG_H
|
||||
#undef HAVE_MALLOC_H
|
||||
#undef HAVE_MEMORY_H
|
||||
#undef HAVE_STRING_H
|
||||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_INTTYPES_H
|
||||
#undef HAVE_STDINT_H
|
||||
#undef HAVE_CTYPE_H
|
||||
#undef HAVE_MATH_H
|
||||
#undef HAVE_ICONV_H
|
||||
#undef HAVE_SIGNAL_H
|
||||
#undef HAVE_ALTIVEC_H
|
||||
|
||||
/* C library functions */
|
||||
#undef HAVE_MALLOC
|
||||
#undef HAVE_CALLOC
|
||||
#undef HAVE_REALLOC
|
||||
#undef HAVE_FREE
|
||||
#undef HAVE_ALLOCA
|
||||
#ifndef _WIN32 /* Don't use C runtime versions of these on Windows */
|
||||
#undef HAVE_GETENV
|
||||
#undef HAVE_PUTENV
|
||||
#undef HAVE_UNSETENV
|
||||
#endif
|
||||
#undef HAVE_QSORT
|
||||
#undef HAVE_ABS
|
||||
#undef HAVE_BCOPY
|
||||
#undef HAVE_MEMSET
|
||||
#undef HAVE_MEMCPY
|
||||
#undef HAVE_MEMMOVE
|
||||
#undef HAVE_MEMCMP
|
||||
#undef HAVE_STRLEN
|
||||
#undef HAVE_STRLCPY
|
||||
#undef HAVE_STRLCAT
|
||||
#undef HAVE_STRDUP
|
||||
#undef HAVE__STRREV
|
||||
#undef HAVE__STRUPR
|
||||
#undef HAVE__STRLWR
|
||||
#undef HAVE_INDEX
|
||||
#undef HAVE_RINDEX
|
||||
#undef HAVE_STRCHR
|
||||
#undef HAVE_STRRCHR
|
||||
#undef HAVE_STRSTR
|
||||
#undef HAVE_ITOA
|
||||
#undef HAVE__LTOA
|
||||
#undef HAVE__UITOA
|
||||
#undef HAVE__ULTOA
|
||||
#undef HAVE_STRTOL
|
||||
#undef HAVE_STRTOUL
|
||||
#undef HAVE__I64TOA
|
||||
#undef HAVE__UI64TOA
|
||||
#undef HAVE_STRTOLL
|
||||
#undef HAVE_STRTOULL
|
||||
#undef HAVE_STRTOD
|
||||
#undef HAVE_ATOI
|
||||
#undef HAVE_ATOF
|
||||
#undef HAVE_STRCMP
|
||||
#undef HAVE_STRNCMP
|
||||
#undef HAVE__STRICMP
|
||||
#undef HAVE_STRCASECMP
|
||||
#undef HAVE__STRNICMP
|
||||
#undef HAVE_STRNCASECMP
|
||||
#undef HAVE_SSCANF
|
||||
#undef HAVE_SNPRINTF
|
||||
#undef HAVE_VSNPRINTF
|
||||
#undef HAVE_M_PI
|
||||
#undef HAVE_CEIL
|
||||
#undef HAVE_COPYSIGN
|
||||
#undef HAVE_COS
|
||||
#undef HAVE_COSF
|
||||
#undef HAVE_FABS
|
||||
#undef HAVE_FLOOR
|
||||
#undef HAVE_LOG
|
||||
#undef HAVE_POW
|
||||
#undef HAVE_SCALBN
|
||||
#undef HAVE_SIN
|
||||
#undef HAVE_SINF
|
||||
#undef HAVE_SQRT
|
||||
#undef HAVE_SIGACTION
|
||||
#undef HAVE_SETJMP
|
||||
#undef HAVE_NANOSLEEP
|
||||
#undef HAVE_CLOCK_GETTIME
|
||||
#undef HAVE_DLVSYM
|
||||
#undef HAVE_GETPAGESIZE
|
||||
|
||||
#else
|
||||
/* We may need some replacement for stdarg.h here */
|
||||
#include <stdarg.h>
|
||||
#endif /* HAVE_LIBC */
|
||||
|
||||
/* Allow disabling of core subsystems */
|
||||
#undef SDL_AUDIO_DISABLED
|
||||
#undef SDL_CDROM_DISABLED
|
||||
#undef SDL_CPUINFO_DISABLED
|
||||
#undef SDL_EVENTS_DISABLED
|
||||
#undef SDL_FILE_DISABLED
|
||||
#undef SDL_JOYSTICK_DISABLED
|
||||
#undef SDL_HAPTIC_DISABLED
|
||||
#undef SDL_LOADSO_DISABLED
|
||||
#undef SDL_THREADS_DISABLED
|
||||
#undef SDL_TIMERS_DISABLED
|
||||
#undef SDL_VIDEO_DISABLED
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#undef SDL_AUDIO_DRIVER_ALSA
|
||||
#undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_ARTS
|
||||
#undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_PULSEAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_BEOSAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_BSD
|
||||
#undef SDL_AUDIO_DRIVER_COREAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_DART
|
||||
#undef SDL_AUDIO_DRIVER_DC
|
||||
#undef SDL_AUDIO_DRIVER_DISK
|
||||
#undef SDL_AUDIO_DRIVER_DUMMY
|
||||
#undef SDL_AUDIO_DRIVER_DMEDIA
|
||||
#undef SDL_AUDIO_DRIVER_DSOUND
|
||||
#undef SDL_AUDIO_DRIVER_ESD
|
||||
#undef SDL_AUDIO_DRIVER_ESD_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_MINT
|
||||
#undef SDL_AUDIO_DRIVER_MMEAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_NAS
|
||||
#undef SDL_AUDIO_DRIVER_NAS_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_NDS
|
||||
#undef SDL_AUDIO_DRIVER_OSS
|
||||
#undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
|
||||
#undef SDL_AUDIO_DRIVER_PAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_QNXNTO
|
||||
#undef SDL_AUDIO_DRIVER_SNDMGR
|
||||
#undef SDL_AUDIO_DRIVER_SUNAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_WINWAVEOUT
|
||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND
|
||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
||||
|
||||
/* Enable various cdrom drivers */
|
||||
#undef SDL_CDROM_AIX
|
||||
#undef SDL_CDROM_BEOS
|
||||
#undef SDL_CDROM_BSDI
|
||||
#undef SDL_CDROM_DC
|
||||
#undef SDL_CDROM_DUMMY
|
||||
#undef SDL_CDROM_FREEBSD
|
||||
#undef SDL_CDROM_LINUX
|
||||
#undef SDL_CDROM_MACOSX
|
||||
#undef SDL_CDROM_MINT
|
||||
#undef SDL_CDROM_OPENBSD
|
||||
#undef SDL_CDROM_OS2
|
||||
#undef SDL_CDROM_OSF
|
||||
#undef SDL_CDROM_QNX
|
||||
#undef SDL_CDROM_WIN32
|
||||
|
||||
/* Enable various input drivers */
|
||||
#undef SDL_INPUT_LINUXEV
|
||||
#undef SDL_INPUT_TSLIB
|
||||
#undef SDL_JOYSTICK_BEOS
|
||||
#undef SDL_JOYSTICK_DC
|
||||
#undef SDL_JOYSTICK_DINPUT
|
||||
#undef SDL_JOYSTICK_DUMMY
|
||||
#undef SDL_JOYSTICK_IOKIT
|
||||
#undef SDL_JOYSTICK_LINUX
|
||||
#undef SDL_JOYSTICK_MINT
|
||||
#undef SDL_JOYSTICK_NDS
|
||||
#undef SDL_JOYSTICK_OS2
|
||||
#undef SDL_JOYSTICK_RISCOS
|
||||
#undef SDL_JOYSTICK_WINMM
|
||||
#undef SDL_JOYSTICK_USBHID
|
||||
#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
|
||||
#undef SDL_HAPTIC_DUMMY
|
||||
#undef SDL_HAPTIC_LINUX
|
||||
#undef SDL_HAPTIC_IOKIT
|
||||
#undef SDL_HAPTIC_DINPUT
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#undef SDL_LOADSO_BEOS
|
||||
#undef SDL_LOADSO_DLCOMPAT
|
||||
#undef SDL_LOADSO_DLOPEN
|
||||
#undef SDL_LOADSO_DUMMY
|
||||
#undef SDL_LOADSO_LDG
|
||||
#undef SDL_LOADSO_OS2
|
||||
#undef SDL_LOADSO_WIN32
|
||||
|
||||
/* Enable various threading systems */
|
||||
#undef SDL_THREAD_BEOS
|
||||
#undef SDL_THREAD_DC
|
||||
#undef SDL_THREAD_NDS
|
||||
#undef SDL_THREAD_OS2
|
||||
#undef SDL_THREAD_PTH
|
||||
#undef SDL_THREAD_PTHREAD
|
||||
#undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX
|
||||
#undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
|
||||
#undef SDL_THREAD_SPROC
|
||||
#undef SDL_THREAD_WIN32
|
||||
|
||||
/* Enable various timer systems */
|
||||
#undef SDL_TIMER_BEOS
|
||||
#undef SDL_TIMER_DC
|
||||
#undef SDL_TIMER_DUMMY
|
||||
#undef SDL_TIMER_MINT
|
||||
#undef SDL_TIMER_NDS
|
||||
#undef SDL_TIMER_OS2
|
||||
#undef SDL_TIMER_RISCOS
|
||||
#undef SDL_TIMER_UNIX
|
||||
#undef SDL_TIMER_WIN32
|
||||
#undef SDL_TIMER_WINCE
|
||||
|
||||
/* Enable various video drivers */
|
||||
#undef SDL_VIDEO_DRIVER_BWINDOW
|
||||
#undef SDL_VIDEO_DRIVER_COCOA
|
||||
#undef SDL_VIDEO_DRIVER_DC
|
||||
#undef SDL_VIDEO_DRIVER_DIRECTFB
|
||||
#undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
|
||||
#undef SDL_VIDEO_DRIVER_DUMMY
|
||||
#undef SDL_VIDEO_DRIVER_FBCON
|
||||
#undef SDL_VIDEO_DRIVER_GAPI
|
||||
#undef SDL_VIDEO_DRIVER_GEM
|
||||
#undef SDL_VIDEO_DRIVER_IPOD
|
||||
#undef SDL_VIDEO_DRIVER_NANOX
|
||||
#undef SDL_VIDEO_DRIVER_NDS
|
||||
#undef SDL_VIDEO_DRIVER_OS2FS
|
||||
#undef SDL_VIDEO_DRIVER_PHOTON
|
||||
#undef SDL_VIDEO_DRIVER_PS2GS
|
||||
#undef SDL_VIDEO_DRIVER_RISCOS
|
||||
#undef SDL_VIDEO_DRIVER_SVGALIB
|
||||
#undef SDL_VIDEO_DRIVER_VGL
|
||||
#undef SDL_VIDEO_DRIVER_WIN32
|
||||
#undef SDL_VIDEO_DRIVER_WSCONS
|
||||
#undef SDL_VIDEO_DRIVER_X11
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
|
||||
#undef SDL_VIDEO_DRIVER_X11_VIDMODE
|
||||
#undef SDL_VIDEO_DRIVER_X11_XINERAMA
|
||||
#undef SDL_VIDEO_DRIVER_X11_XRANDR
|
||||
#undef SDL_VIDEO_DRIVER_X11_XINPUT
|
||||
#undef SDL_VIDEO_DRIVER_X11_SCRNSAVER
|
||||
#undef SDL_VIDEO_DRIVER_X11_XV
|
||||
#undef SDL_VIDEO_DRIVER_XBIOS
|
||||
|
||||
#undef SDL_VIDEO_RENDER_D3D
|
||||
#undef SDL_VIDEO_RENDER_GDI
|
||||
#undef SDL_VIDEO_RENDER_OGL
|
||||
#undef SDL_VIDEO_RENDER_X11
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#undef SDL_VIDEO_OPENGL
|
||||
#undef SDL_VIDEO_OPENGL_BGL
|
||||
#undef SDL_VIDEO_OPENGL_CGL
|
||||
#undef SDL_VIDEO_OPENGL_GLX
|
||||
#undef SDL_VIDEO_OPENGL_WGL
|
||||
#undef SDL_VIDEO_OPENGL_OSMESA
|
||||
#undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
|
||||
|
||||
/* Enable assembly routines */
|
||||
#undef SDL_ASSEMBLY_ROUTINES
|
||||
#undef SDL_ALTIVEC_BLITTERS
|
||||
|
||||
#endif /* _SDL_config_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_h
|
||||
#define _SDL_config_h
|
||||
|
||||
/**
|
||||
* \file SDL_config.h.in
|
||||
*
|
||||
* This is a set of defines to configure the SDL features
|
||||
*/
|
||||
|
||||
/* General platform specific identifiers */
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* Make sure that this isn't included by Visual C++ */
|
||||
#ifdef _MSC_VER
|
||||
#error You should copy include/SDL_config.h.default to include/SDL_config.h
|
||||
#endif
|
||||
|
||||
/* C language features */
|
||||
#undef const
|
||||
#undef inline
|
||||
#undef volatile
|
||||
|
||||
/* C datatypes */
|
||||
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
|
||||
#undef size_t
|
||||
#undef int8_t
|
||||
#undef uint8_t
|
||||
#undef int16_t
|
||||
#undef uint16_t
|
||||
#undef int32_t
|
||||
#undef uint32_t
|
||||
#undef int64_t
|
||||
#undef uint64_t
|
||||
#undef uintptr_t
|
||||
#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
|
||||
|
||||
#undef SIZEOF_VOIDP
|
||||
#undef SDL_HAS_64BIT_TYPE
|
||||
|
||||
/* Comment this if you want to build without any C library requirements */
|
||||
#undef HAVE_LIBC
|
||||
#if HAVE_LIBC
|
||||
|
||||
/* Useful headers */
|
||||
#undef HAVE_ALLOCA_H
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
#undef HAVE_STDIO_H
|
||||
#undef STDC_HEADERS
|
||||
#undef HAVE_STDLIB_H
|
||||
#undef HAVE_STDARG_H
|
||||
#undef HAVE_MALLOC_H
|
||||
#undef HAVE_MEMORY_H
|
||||
#undef HAVE_STRING_H
|
||||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_INTTYPES_H
|
||||
#undef HAVE_STDINT_H
|
||||
#undef HAVE_CTYPE_H
|
||||
#undef HAVE_MATH_H
|
||||
#undef HAVE_ICONV_H
|
||||
#undef HAVE_SIGNAL_H
|
||||
#undef HAVE_ALTIVEC_H
|
||||
|
||||
/* C library functions */
|
||||
#undef HAVE_MALLOC
|
||||
#undef HAVE_CALLOC
|
||||
#undef HAVE_REALLOC
|
||||
#undef HAVE_FREE
|
||||
#undef HAVE_ALLOCA
|
||||
#ifndef _WIN32 /* Don't use C runtime versions of these on Windows */
|
||||
#undef HAVE_GETENV
|
||||
#undef HAVE_PUTENV
|
||||
#undef HAVE_UNSETENV
|
||||
#endif
|
||||
#undef HAVE_QSORT
|
||||
#undef HAVE_ABS
|
||||
#undef HAVE_BCOPY
|
||||
#undef HAVE_MEMSET
|
||||
#undef HAVE_MEMCPY
|
||||
#undef HAVE_MEMMOVE
|
||||
#undef HAVE_MEMCMP
|
||||
#undef HAVE_STRLEN
|
||||
#undef HAVE_STRLCPY
|
||||
#undef HAVE_STRLCAT
|
||||
#undef HAVE_STRDUP
|
||||
#undef HAVE__STRREV
|
||||
#undef HAVE__STRUPR
|
||||
#undef HAVE__STRLWR
|
||||
#undef HAVE_INDEX
|
||||
#undef HAVE_RINDEX
|
||||
#undef HAVE_STRCHR
|
||||
#undef HAVE_STRRCHR
|
||||
#undef HAVE_STRSTR
|
||||
#undef HAVE_ITOA
|
||||
#undef HAVE__LTOA
|
||||
#undef HAVE__UITOA
|
||||
#undef HAVE__ULTOA
|
||||
#undef HAVE_STRTOL
|
||||
#undef HAVE_STRTOUL
|
||||
#undef HAVE__I64TOA
|
||||
#undef HAVE__UI64TOA
|
||||
#undef HAVE_STRTOLL
|
||||
#undef HAVE_STRTOULL
|
||||
#undef HAVE_STRTOD
|
||||
#undef HAVE_ATOI
|
||||
#undef HAVE_ATOF
|
||||
#undef HAVE_STRCMP
|
||||
#undef HAVE_STRNCMP
|
||||
#undef HAVE__STRICMP
|
||||
#undef HAVE_STRCASECMP
|
||||
#undef HAVE__STRNICMP
|
||||
#undef HAVE_STRNCASECMP
|
||||
#undef HAVE_SSCANF
|
||||
#undef HAVE_SNPRINTF
|
||||
#undef HAVE_VSNPRINTF
|
||||
#undef HAVE_M_PI
|
||||
#undef HAVE_CEIL
|
||||
#undef HAVE_COPYSIGN
|
||||
#undef HAVE_COS
|
||||
#undef HAVE_COSF
|
||||
#undef HAVE_FABS
|
||||
#undef HAVE_FLOOR
|
||||
#undef HAVE_LOG
|
||||
#undef HAVE_POW
|
||||
#undef HAVE_SCALBN
|
||||
#undef HAVE_SIN
|
||||
#undef HAVE_SINF
|
||||
#undef HAVE_SQRT
|
||||
#undef HAVE_SIGACTION
|
||||
#undef HAVE_SETJMP
|
||||
#undef HAVE_NANOSLEEP
|
||||
#undef HAVE_CLOCK_GETTIME
|
||||
#undef HAVE_GETPAGESIZE
|
||||
#undef HAVE_MPROTECT
|
||||
|
||||
#else
|
||||
/* We may need some replacement for stdarg.h here */
|
||||
#include <stdarg.h>
|
||||
#endif /* HAVE_LIBC */
|
||||
|
||||
/* Allow disabling of core subsystems */
|
||||
#undef SDL_AUDIO_DISABLED
|
||||
#undef SDL_CPUINFO_DISABLED
|
||||
#undef SDL_EVENTS_DISABLED
|
||||
#undef SDL_FILE_DISABLED
|
||||
#undef SDL_JOYSTICK_DISABLED
|
||||
#undef SDL_HAPTIC_DISABLED
|
||||
#undef SDL_LOADSO_DISABLED
|
||||
#undef SDL_THREADS_DISABLED
|
||||
#undef SDL_TIMERS_DISABLED
|
||||
#undef SDL_VIDEO_DISABLED
|
||||
#undef SDL_POWER_DISABLED
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#undef SDL_AUDIO_DRIVER_ALSA
|
||||
#undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_ARTS
|
||||
#undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_PULSEAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_BEOSAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_BSD
|
||||
#undef SDL_AUDIO_DRIVER_COREAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_DISK
|
||||
#undef SDL_AUDIO_DRIVER_DUMMY
|
||||
#undef SDL_AUDIO_DRIVER_DMEDIA
|
||||
#undef SDL_AUDIO_DRIVER_DSOUND
|
||||
#undef SDL_AUDIO_DRIVER_ESD
|
||||
#undef SDL_AUDIO_DRIVER_ESD_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_MMEAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_NAS
|
||||
#undef SDL_AUDIO_DRIVER_NAS_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_NDS
|
||||
#undef SDL_AUDIO_DRIVER_OSS
|
||||
#undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
|
||||
#undef SDL_AUDIO_DRIVER_PAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_QSA
|
||||
#undef SDL_AUDIO_DRIVER_SUNAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_WINWAVEOUT
|
||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND
|
||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
||||
|
||||
/* Enable various input drivers */
|
||||
#undef SDL_INPUT_LINUXEV
|
||||
#undef SDL_INPUT_TSLIB
|
||||
#undef SDL_JOYSTICK_BEOS
|
||||
#undef SDL_JOYSTICK_DINPUT
|
||||
#undef SDL_JOYSTICK_DUMMY
|
||||
#undef SDL_JOYSTICK_IOKIT
|
||||
#undef SDL_JOYSTICK_LINUX
|
||||
#undef SDL_JOYSTICK_NDS
|
||||
#undef SDL_JOYSTICK_RISCOS
|
||||
#undef SDL_JOYSTICK_WINMM
|
||||
#undef SDL_JOYSTICK_USBHID
|
||||
#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
|
||||
#undef SDL_HAPTIC_DUMMY
|
||||
#undef SDL_HAPTIC_LINUX
|
||||
#undef SDL_HAPTIC_IOKIT
|
||||
#undef SDL_HAPTIC_DINPUT
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#undef SDL_LOADSO_BEOS
|
||||
#undef SDL_LOADSO_DLCOMPAT
|
||||
#undef SDL_LOADSO_DLOPEN
|
||||
#undef SDL_LOADSO_DUMMY
|
||||
#undef SDL_LOADSO_LDG
|
||||
#undef SDL_LOADSO_WIN32
|
||||
|
||||
/* Enable various threading systems */
|
||||
#undef SDL_THREAD_BEOS
|
||||
#undef SDL_THREAD_NDS
|
||||
#undef SDL_THREAD_PTH
|
||||
#undef SDL_THREAD_PTHREAD
|
||||
#undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX
|
||||
#undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
|
||||
#undef SDL_THREAD_SPROC
|
||||
#undef SDL_THREAD_WIN32
|
||||
|
||||
/* Enable various timer systems */
|
||||
#undef SDL_TIMER_BEOS
|
||||
#undef SDL_TIMER_DUMMY
|
||||
#undef SDL_TIMER_NDS
|
||||
#undef SDL_TIMER_RISCOS
|
||||
#undef SDL_TIMER_UNIX
|
||||
#undef SDL_TIMER_WIN32
|
||||
#undef SDL_TIMER_WINCE
|
||||
|
||||
/* Enable various video drivers */
|
||||
#undef SDL_VIDEO_DRIVER_BWINDOW
|
||||
#undef SDL_VIDEO_DRIVER_COCOA
|
||||
#undef SDL_VIDEO_DRIVER_DIRECTFB
|
||||
#undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
|
||||
#undef SDL_VIDEO_DRIVER_DUMMY
|
||||
#undef SDL_VIDEO_DRIVER_FBCON
|
||||
#undef SDL_VIDEO_DRIVER_NDS
|
||||
#undef SDL_VIDEO_DRIVER_PHOTON
|
||||
#undef SDL_VIDEO_DRIVER_QNXGF
|
||||
#undef SDL_VIDEO_DRIVER_PS2GS
|
||||
#undef SDL_VIDEO_DRIVER_PS3
|
||||
#undef SDL_VIDEO_DRIVER_RISCOS
|
||||
#undef SDL_VIDEO_DRIVER_SVGALIB
|
||||
#undef SDL_VIDEO_DRIVER_WIN32
|
||||
#undef SDL_VIDEO_DRIVER_X11
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
|
||||
#undef SDL_VIDEO_DRIVER_X11_VIDMODE
|
||||
#undef SDL_VIDEO_DRIVER_X11_XINERAMA
|
||||
#undef SDL_VIDEO_DRIVER_X11_XRANDR
|
||||
#undef SDL_VIDEO_DRIVER_X11_XINPUT
|
||||
#undef SDL_VIDEO_DRIVER_X11_SCRNSAVER
|
||||
#undef SDL_VIDEO_DRIVER_X11_XV
|
||||
|
||||
#undef SDL_VIDEO_RENDER_D3D
|
||||
#undef SDL_VIDEO_RENDER_GDI
|
||||
#undef SDL_VIDEO_RENDER_OGL
|
||||
#undef SDL_VIDEO_RENDER_OGL_ES
|
||||
#undef SDL_VIDEO_RENDER_X11
|
||||
#undef SDL_VIDEO_RENDER_GAPI
|
||||
#undef SDL_VIDEO_RENDER_DDRAW
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#undef SDL_VIDEO_OPENGL
|
||||
#undef SDL_VIDEO_OPENGL_ES
|
||||
#undef SDL_VIDEO_OPENGL_BGL
|
||||
#undef SDL_VIDEO_OPENGL_CGL
|
||||
#undef SDL_VIDEO_OPENGL_GLX
|
||||
#undef SDL_VIDEO_OPENGL_WGL
|
||||
#undef SDL_VIDEO_OPENGL_OSMESA
|
||||
#undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
|
||||
|
||||
/* Enable system power support */
|
||||
#undef SDL_POWER_LINUX
|
||||
#undef SDL_POWER_WINDOWS
|
||||
#undef SDL_POWER_MACOSX
|
||||
#undef SDL_POWER_BEOS
|
||||
#undef SDL_POWER_NINTENDODS
|
||||
#undef SDL_POWER_HARDWIRED
|
||||
|
||||
/* Enable assembly routines */
|
||||
#undef SDL_ASSEMBLY_ROUTINES
|
||||
#undef SDL_ALTIVEC_BLITTERS
|
||||
|
||||
#endif /* _SDL_config_h */
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
|
@ -32,6 +33,14 @@ typedef unsigned short uint16_t;
|
|||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long uintptr_t;
|
||||
#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define SIZEOF_VOIDP 8
|
||||
#else
|
||||
#define SIZEOF_VOIDP 4
|
||||
#endif
|
||||
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
#define HAVE_ALLOCA_H 1
|
||||
|
@ -82,6 +91,18 @@ typedef unsigned long uintptr_t;
|
|||
#define HAVE_SSCANF 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#define HAVE_CEIL 1
|
||||
#define HAVE_COPYSIGN 1
|
||||
#define HAVE_COS 1
|
||||
#define HAVE_COSF 1
|
||||
#define HAVE_FABS 1
|
||||
#define HAVE_FLOOR 1
|
||||
#define HAVE_LOG 1
|
||||
#define HAVE_POW 1
|
||||
#define HAVE_SCALBN 1
|
||||
#define HAVE_SIN 1
|
||||
#define HAVE_SINF 1
|
||||
#define HAVE_SQRT 1
|
||||
#define HAVE_SIGACTION 1
|
||||
#define HAVE_SETJMP 1
|
||||
#define HAVE_NANOSLEEP 1
|
||||
|
@ -91,9 +112,6 @@ typedef unsigned long uintptr_t;
|
|||
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
|
||||
#define SDL_CDROM_DISABLED 1
|
||||
|
||||
/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
|
||||
#define SDL_HAPTIC_DISABLED 1
|
||||
|
||||
|
@ -119,6 +137,9 @@ typedef unsigned long uintptr_t;
|
|||
#define SDL_VIDEO_OPENGL_ES 1
|
||||
#define SDL_VIDEO_RENDER_OGL_ES 1
|
||||
|
||||
/* Enable system power support */
|
||||
#define SDL_POWER_MACOSX 1
|
||||
|
||||
/* enable iPhone keyboard support */
|
||||
#define SDL_IPHONE_KEYBOARD 1
|
||||
|
||||
|
|
|
@ -1,134 +1,162 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_macosx_h
|
||||
#define _SDL_config_macosx_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
|
||||
#include <AvailabilityMacros.h>
|
||||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
/* Useful headers */
|
||||
/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
|
||||
#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
|
||||
#define HAVE_ALLOCA_H 1
|
||||
#endif
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_STDIO_H 1
|
||||
#define STDC_HEADERS 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_CTYPE_H 1
|
||||
#define HAVE_MATH_H 1
|
||||
#define HAVE_SIGNAL_H 1
|
||||
|
||||
/* C library functions */
|
||||
#define HAVE_MALLOC 1
|
||||
#define HAVE_CALLOC 1
|
||||
#define HAVE_REALLOC 1
|
||||
#define HAVE_FREE 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_GETENV 1
|
||||
#define HAVE_PUTENV 1
|
||||
#define HAVE_UNSETENV 1
|
||||
#define HAVE_QSORT 1
|
||||
#define HAVE_ABS 1
|
||||
#define HAVE_BCOPY 1
|
||||
#define HAVE_MEMSET 1
|
||||
#define HAVE_MEMCPY 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_MEMCMP 1
|
||||
#define HAVE_STRLEN 1
|
||||
#define HAVE_STRLCPY 1
|
||||
#define HAVE_STRLCAT 1
|
||||
#define HAVE_STRDUP 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_STRTOL 1
|
||||
#define HAVE_STRTOUL 1
|
||||
#define HAVE_STRTOLL 1
|
||||
#define HAVE_STRTOULL 1
|
||||
#define HAVE_STRTOD 1
|
||||
#define HAVE_ATOI 1
|
||||
#define HAVE_ATOF 1
|
||||
#define HAVE_STRCMP 1
|
||||
#define HAVE_STRNCMP 1
|
||||
#define HAVE_STRCASECMP 1
|
||||
#define HAVE_STRNCASECMP 1
|
||||
#define HAVE_SSCANF 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#define HAVE_SIGACTION 1
|
||||
#define HAVE_SETJMP 1
|
||||
#define HAVE_NANOSLEEP 1
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#define SDL_AUDIO_DRIVER_COREAUDIO 1
|
||||
#define SDL_AUDIO_DRIVER_SNDMGR 1
|
||||
#define SDL_AUDIO_DRIVER_DISK 1
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable various cdrom drivers */
|
||||
#define SDL_CDROM_MACOSX 1
|
||||
|
||||
/* Enable various input drivers */
|
||||
#define SDL_JOYSTICK_IOKIT 1
|
||||
#define SDL_HAPTIC_IOKIT 1
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#ifdef __ppc__
|
||||
/* For Mac OS X 10.2 compatibility */
|
||||
#define SDL_LOADSO_DLCOMPAT 1
|
||||
#else
|
||||
#define SDL_LOADSO_DLOPEN 1
|
||||
#endif
|
||||
|
||||
/* Enable various threading systems */
|
||||
#define SDL_THREAD_PTHREAD 1
|
||||
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
|
||||
|
||||
/* Enable various timer systems */
|
||||
#define SDL_TIMER_UNIX 1
|
||||
|
||||
/* Enable various video drivers */
|
||||
#define SDL_VIDEO_DRIVER_COCOA 1
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#define SDL_VIDEO_OPENGL 1
|
||||
#define SDL_VIDEO_OPENGL_CGL 1
|
||||
#define SDL_VIDEO_RENDER_OGL 1
|
||||
|
||||
/* Enable assembly routines */
|
||||
#define SDL_ASSEMBLY_ROUTINES 1
|
||||
#ifdef __ppc__
|
||||
#define SDL_ALTIVEC_BLITTERS 1
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_config_macosx_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_macosx_h
|
||||
#define _SDL_config_macosx_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
|
||||
#include <AvailabilityMacros.h>
|
||||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define SIZEOF_VOIDP 8
|
||||
#else
|
||||
#define SIZEOF_VOIDP 4
|
||||
#endif
|
||||
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
/* Useful headers */
|
||||
/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
|
||||
#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
|
||||
#define HAVE_ALLOCA_H 1
|
||||
#endif
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_STDIO_H 1
|
||||
#define STDC_HEADERS 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_CTYPE_H 1
|
||||
#define HAVE_MATH_H 1
|
||||
#define HAVE_SIGNAL_H 1
|
||||
|
||||
/* C library functions */
|
||||
#define HAVE_MALLOC 1
|
||||
#define HAVE_CALLOC 1
|
||||
#define HAVE_REALLOC 1
|
||||
#define HAVE_FREE 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_GETENV 1
|
||||
#define HAVE_PUTENV 1
|
||||
#define HAVE_UNSETENV 1
|
||||
#define HAVE_QSORT 1
|
||||
#define HAVE_ABS 1
|
||||
#define HAVE_BCOPY 1
|
||||
#define HAVE_MEMSET 1
|
||||
#define HAVE_MEMCPY 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_MEMCMP 1
|
||||
#define HAVE_STRLEN 1
|
||||
#define HAVE_STRLCPY 1
|
||||
#define HAVE_STRLCAT 1
|
||||
#define HAVE_STRDUP 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_STRTOL 1
|
||||
#define HAVE_STRTOUL 1
|
||||
#define HAVE_STRTOLL 1
|
||||
#define HAVE_STRTOULL 1
|
||||
#define HAVE_STRTOD 1
|
||||
#define HAVE_ATOI 1
|
||||
#define HAVE_ATOF 1
|
||||
#define HAVE_STRCMP 1
|
||||
#define HAVE_STRNCMP 1
|
||||
#define HAVE_STRCASECMP 1
|
||||
#define HAVE_STRNCASECMP 1
|
||||
#define HAVE_SSCANF 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#define HAVE_CEIL 1
|
||||
#define HAVE_COPYSIGN 1
|
||||
#define HAVE_COS 1
|
||||
#define HAVE_COSF 1
|
||||
#define HAVE_FABS 1
|
||||
#define HAVE_FLOOR 1
|
||||
#define HAVE_LOG 1
|
||||
#define HAVE_POW 1
|
||||
#define HAVE_SCALBN 1
|
||||
#define HAVE_SIN 1
|
||||
#define HAVE_SINF 1
|
||||
#define HAVE_SQRT 1
|
||||
#define HAVE_SIGACTION 1
|
||||
#define HAVE_SETJMP 1
|
||||
#define HAVE_NANOSLEEP 1
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#define SDL_AUDIO_DRIVER_COREAUDIO 1
|
||||
#define SDL_AUDIO_DRIVER_DISK 1
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable various input drivers */
|
||||
#define SDL_JOYSTICK_IOKIT 1
|
||||
#define SDL_HAPTIC_IOKIT 1
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#define SDL_LOADSO_DLOPEN 1
|
||||
|
||||
/* Enable various threading systems */
|
||||
#define SDL_THREAD_PTHREAD 1
|
||||
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
|
||||
|
||||
/* Enable various timer systems */
|
||||
#define SDL_TIMER_UNIX 1
|
||||
|
||||
/* Enable various video drivers */
|
||||
#define SDL_VIDEO_DRIVER_COCOA 1
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
#define SDL_VIDEO_DRIVER_X11 1
|
||||
#define SDL_VIDEO_DRIVER_X11_DYNAMIC "/usr/X11R6/lib/libX11.6.dylib"
|
||||
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/usr/X11R6/lib/libXext.6.dylib"
|
||||
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
|
||||
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER "/usr/X11R6/lib/libXrender.1.dylib"
|
||||
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT "/usr/X11R6/lib/libXi.6.dylib"
|
||||
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.6.dylib"
|
||||
#define SDL_VIDEO_DRIVER_X11_VIDMODE 1
|
||||
#define SDL_VIDEO_DRIVER_X11_XINERAMA 1
|
||||
#define SDL_VIDEO_DRIVER_X11_XRANDR 1
|
||||
#define SDL_VIDEO_DRIVER_X11_XINPUT 1
|
||||
#define SDL_VIDEO_DRIVER_X11_SCRNSAVER 1
|
||||
#define SDL_VIDEO_DRIVER_X11_XV 1
|
||||
|
||||
#define SDL_VIDEO_RENDER_OGL 1
|
||||
#define SDL_VIDEO_RENDER_X11 1
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#define SDL_VIDEO_OPENGL 1
|
||||
#define SDL_VIDEO_OPENGL_CGL 1
|
||||
#define SDL_VIDEO_OPENGL_GLX 1
|
||||
|
||||
/* Enable system power support */
|
||||
#define SDL_POWER_MACOSX 1
|
||||
|
||||
/* Enable assembly routines */
|
||||
#define SDL_ASSEMBLY_ROUTINES 1
|
||||
#ifdef __ppc__
|
||||
#define SDL_ALTIVEC_BLITTERS 1
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_config_macosx_h */
|
||||
|
|
|
@ -1,65 +1,68 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_minimal_h
|
||||
#define _SDL_config_minimal_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* This is the minimal configuration that can be used to build SDL */
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned int size_t;
|
||||
typedef unsigned long uintptr_t;
|
||||
|
||||
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
|
||||
#define SDL_CDROM_DISABLED 1
|
||||
|
||||
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
|
||||
#define SDL_JOYSTICK_DISABLED 1
|
||||
|
||||
/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
|
||||
#define SDL_HAPTIC_DISABLED 1
|
||||
|
||||
/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
|
||||
#define SDL_LOADSO_DISABLED 1
|
||||
|
||||
/* Enable the stub thread support (src/thread/generic/\*.c) */
|
||||
#define SDL_THREADS_DISABLED 1
|
||||
|
||||
/* Enable the stub timer support (src/timer/dummy/\*.c) */
|
||||
#define SDL_TIMERS_DISABLED 1
|
||||
|
||||
/* Enable the dummy video driver (src/video/dummy/\*.c) */
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
|
||||
#endif /* _SDL_config_minimal_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_minimal_h
|
||||
#define _SDL_config_minimal_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/**
|
||||
* \file SDL_config_minimal.h
|
||||
*
|
||||
* This is the minimal configuration that can be used to build SDL.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned int size_t;
|
||||
typedef unsigned long uintptr_t;
|
||||
#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
|
||||
|
||||
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
|
||||
#define SDL_JOYSTICK_DISABLED 1
|
||||
|
||||
/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
|
||||
#define SDL_HAPTIC_DISABLED 1
|
||||
|
||||
/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
|
||||
#define SDL_LOADSO_DISABLED 1
|
||||
|
||||
/* Enable the stub thread support (src/thread/generic/\*.c) */
|
||||
#define SDL_THREADS_DISABLED 1
|
||||
|
||||
/* Enable the stub timer support (src/timer/dummy/\*.c) */
|
||||
#define SDL_TIMERS_DISABLED 1
|
||||
|
||||
/* Enable the dummy video driver (src/video/dummy/\*.c) */
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
|
||||
#endif /* _SDL_config_minimal_h */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
|
@ -43,7 +44,7 @@ typedef unsigned long uintptr_t;
|
|||
#else
|
||||
typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
|
||||
#endif
|
||||
|
||||
#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
|
||||
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
|
@ -95,9 +96,6 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
|
|||
#define SDL_AUDIO_DRIVER_NDS 1
|
||||
/*#define SDL_AUDIO_DRIVER_DUMMY 1 TODO: uncomment this later*/
|
||||
|
||||
/* DS doesn't have optical media */
|
||||
#define SDL_CDROM_DISABLED 1
|
||||
|
||||
/* Enable various input drivers */
|
||||
#define SDL_JOYSTICK_NDS 1
|
||||
/*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/
|
||||
|
@ -116,4 +114,7 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
|
|||
#define SDL_VIDEO_DRIVER_NDS 1
|
||||
/*#define SDL_VIDEO_DRIVER_DUMMY 1 TODO: uncomment this later*/
|
||||
|
||||
/* Enable system power support */
|
||||
#define SDL_POWER_NINTENDODS 1
|
||||
|
||||
#endif /* _SDL_config_nintendods_h */
|
||||
|
|
|
@ -1,193 +1,197 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_win32_h
|
||||
#define _SDL_config_win32_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
#if defined(__GNUC__) || defined(__DMC__)
|
||||
#define HAVE_STDINT_H 1
|
||||
#elif defined(_MSC_VER)
|
||||
typedef signed __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#ifndef _UINTPTR_T_DEFINED
|
||||
#ifdef _WIN64
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif
|
||||
#define _UINTPTR_T_DEFINED
|
||||
#endif
|
||||
/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
|
||||
#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
|
||||
#define DWORD_PTR DWORD
|
||||
#endif
|
||||
#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
|
||||
#define LONG_PTR LONG
|
||||
#endif
|
||||
#else /* !__GNUC__ && !_MSC_VER */
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#ifndef _SIZE_T_DEFINED_
|
||||
#define _SIZE_T_DEFINED_
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif /* __GNUC__ || _MSC_VER */
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
/* Enabled for SDL 1.2 (binary compatibility) */
|
||||
//#define HAVE_LIBC 1
|
||||
#ifdef HAVE_LIBC
|
||||
/* Useful headers */
|
||||
#define HAVE_STDIO_H 1
|
||||
#define STDC_HEADERS 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_CTYPE_H 1
|
||||
#define HAVE_MATH_H 1
|
||||
#ifndef _WIN32_WCE
|
||||
#define HAVE_SIGNAL_H 1
|
||||
#endif
|
||||
|
||||
/* C library functions */
|
||||
#define HAVE_MALLOC 1
|
||||
#define HAVE_CALLOC 1
|
||||
#define HAVE_REALLOC 1
|
||||
#define HAVE_FREE 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_QSORT 1
|
||||
#define HAVE_ABS 1
|
||||
#define HAVE_MEMSET 1
|
||||
#define HAVE_MEMCPY 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_MEMCMP 1
|
||||
#define HAVE_STRLEN 1
|
||||
#define HAVE__STRREV 1
|
||||
#define HAVE__STRUPR 1
|
||||
#define HAVE__STRLWR 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_ITOA 1
|
||||
#define HAVE__LTOA 1
|
||||
#define HAVE__ULTOA 1
|
||||
#define HAVE_STRTOL 1
|
||||
#define HAVE_STRTOUL 1
|
||||
#define HAVE_STRTOLL 1
|
||||
#define HAVE_STRTOD 1
|
||||
#define HAVE_ATOI 1
|
||||
#define HAVE_ATOF 1
|
||||
#define HAVE_STRCMP 1
|
||||
#define HAVE_STRNCMP 1
|
||||
#define HAVE__STRICMP 1
|
||||
#define HAVE__STRNICMP 1
|
||||
#define HAVE_SSCANF 1
|
||||
#define HAVE_M_PI 1
|
||||
#define HAVE_CEIL 1
|
||||
#define HAVE_COPYSIGN 1
|
||||
#define HAVE_COS 1
|
||||
#define HAVE_COSF 1
|
||||
#define HAVE_FABS 1
|
||||
#define HAVE_FLOOR 1
|
||||
#define HAVE_LOG 1
|
||||
#define HAVE_POW 1
|
||||
#define HAVE_SCALBN 1
|
||||
#define HAVE_SIN 1
|
||||
#define HAVE_SINF 1
|
||||
#define HAVE_SQRT 1
|
||||
#else
|
||||
#define HAVE_STDARG_H 1
|
||||
#define HAVE_STDDEF_H 1
|
||||
#endif
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#ifndef _WIN32_WCE
|
||||
#define SDL_AUDIO_DRIVER_DSOUND 1
|
||||
#endif
|
||||
#define SDL_AUDIO_DRIVER_WINWAVEOUT 1
|
||||
#define SDL_AUDIO_DRIVER_DISK 1
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable various cdrom drivers */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_CDROM_DISABLED 1
|
||||
#else
|
||||
#define SDL_CDROM_WIN32 1
|
||||
#endif
|
||||
|
||||
/* Enable various input drivers */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_JOYSTICK_DISABLED 1
|
||||
#define SDL_HAPTIC_DUMMY 1
|
||||
#else
|
||||
#define SDL_JOYSTICK_DINPUT 1
|
||||
#define SDL_HAPTIC_DINPUT 1
|
||||
#endif
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#define SDL_LOADSO_WIN32 1
|
||||
|
||||
/* Enable various threading systems */
|
||||
#define SDL_THREAD_WIN32 1
|
||||
|
||||
/* Enable various timer systems */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_TIMER_WINCE 1
|
||||
#else
|
||||
#define SDL_TIMER_WIN32 1
|
||||
#endif
|
||||
|
||||
/* Enable various video drivers */
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
#define SDL_VIDEO_DRIVER_WIN32 1
|
||||
|
||||
#define SDL_VIDEO_RENDER_D3D 1
|
||||
#define SDL_VIDEO_RENDER_GDI 1
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#ifndef _WIN32_WCE
|
||||
#define SDL_VIDEO_OPENGL 1
|
||||
#define SDL_VIDEO_OPENGL_WGL 1
|
||||
#define SDL_VIDEO_RENDER_OGL 1
|
||||
#endif
|
||||
|
||||
/* Enable assembly routines (Win64 doesn't have inline asm) */
|
||||
#ifndef _WIN64
|
||||
#define SDL_ASSEMBLY_ROUTINES 1
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_config_win32_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_config_win32_h
|
||||
#define _SDL_config_win32_h
|
||||
|
||||
#include "SDL_platform.h"
|
||||
|
||||
/* This is a set of defines to configure the SDL features */
|
||||
|
||||
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
|
||||
#if defined(__GNUC__) || defined(__DMC__)
|
||||
#define HAVE_STDINT_H 1
|
||||
#elif defined(_MSC_VER)
|
||||
typedef signed __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#ifndef _UINTPTR_T_DEFINED
|
||||
#ifdef _WIN64
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif
|
||||
#define _UINTPTR_T_DEFINED
|
||||
#endif
|
||||
/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
|
||||
#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
|
||||
#define DWORD_PTR DWORD
|
||||
#endif
|
||||
#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
|
||||
#define LONG_PTR LONG
|
||||
#endif
|
||||
#else /* !__GNUC__ && !_MSC_VER */
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#ifndef _SIZE_T_DEFINED_
|
||||
#define _SIZE_T_DEFINED_
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif /* __GNUC__ || _MSC_VER */
|
||||
#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
|
||||
|
||||
#ifdef _WIN64
|
||||
# define SIZEOF_VOIDP 8
|
||||
#else
|
||||
# define SIZEOF_VOIDP 4
|
||||
#endif
|
||||
#define SDL_HAS_64BIT_TYPE 1
|
||||
|
||||
/* Enabled for SDL 1.2 (binary compatibility) */
|
||||
//#define HAVE_LIBC 1
|
||||
#ifdef HAVE_LIBC
|
||||
/* Useful headers */
|
||||
#define HAVE_STDIO_H 1
|
||||
#define STDC_HEADERS 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_CTYPE_H 1
|
||||
#define HAVE_MATH_H 1
|
||||
#ifndef _WIN32_WCE
|
||||
#define HAVE_SIGNAL_H 1
|
||||
#endif
|
||||
|
||||
/* C library functions */
|
||||
#define HAVE_MALLOC 1
|
||||
#define HAVE_CALLOC 1
|
||||
#define HAVE_REALLOC 1
|
||||
#define HAVE_FREE 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_QSORT 1
|
||||
#define HAVE_ABS 1
|
||||
#define HAVE_MEMSET 1
|
||||
#define HAVE_MEMCPY 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_MEMCMP 1
|
||||
#define HAVE_STRLEN 1
|
||||
#define HAVE__STRREV 1
|
||||
#define HAVE__STRUPR 1
|
||||
#define HAVE__STRLWR 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_ITOA 1
|
||||
#define HAVE__LTOA 1
|
||||
#define HAVE__ULTOA 1
|
||||
#define HAVE_STRTOL 1
|
||||
#define HAVE_STRTOUL 1
|
||||
#define HAVE_STRTOLL 1
|
||||
#define HAVE_STRTOD 1
|
||||
#define HAVE_ATOI 1
|
||||
#define HAVE_ATOF 1
|
||||
#define HAVE_STRCMP 1
|
||||
#define HAVE_STRNCMP 1
|
||||
#define HAVE__STRICMP 1
|
||||
#define HAVE__STRNICMP 1
|
||||
#define HAVE_SSCANF 1
|
||||
#define HAVE_M_PI 1
|
||||
#define HAVE_CEIL 1
|
||||
#define HAVE_COPYSIGN 1
|
||||
#define HAVE_COS 1
|
||||
#define HAVE_COSF 1
|
||||
#define HAVE_FABS 1
|
||||
#define HAVE_FLOOR 1
|
||||
#define HAVE_LOG 1
|
||||
#define HAVE_POW 1
|
||||
#define HAVE_SCALBN 1
|
||||
#define HAVE_SIN 1
|
||||
#define HAVE_SINF 1
|
||||
#define HAVE_SQRT 1
|
||||
#else
|
||||
#define HAVE_STDARG_H 1
|
||||
#define HAVE_STDDEF_H 1
|
||||
#endif
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#ifndef _WIN32_WCE
|
||||
#define SDL_AUDIO_DRIVER_DSOUND 1
|
||||
#endif
|
||||
#define SDL_AUDIO_DRIVER_WINWAVEOUT 1
|
||||
#define SDL_AUDIO_DRIVER_DISK 1
|
||||
#define SDL_AUDIO_DRIVER_DUMMY 1
|
||||
|
||||
/* Enable various input drivers */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_JOYSTICK_DISABLED 1
|
||||
#define SDL_HAPTIC_DUMMY 1
|
||||
#else
|
||||
#define SDL_JOYSTICK_DINPUT 1
|
||||
#define SDL_HAPTIC_DINPUT 1
|
||||
#endif
|
||||
|
||||
/* Enable various shared object loading systems */
|
||||
#define SDL_LOADSO_WIN32 1
|
||||
|
||||
/* Enable various threading systems */
|
||||
#define SDL_THREAD_WIN32 1
|
||||
|
||||
/* Enable various timer systems */
|
||||
#ifdef _WIN32_WCE
|
||||
#define SDL_TIMER_WINCE 1
|
||||
#else
|
||||
#define SDL_TIMER_WIN32 1
|
||||
#endif
|
||||
|
||||
/* Enable various video drivers */
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
#define SDL_VIDEO_DRIVER_WIN32 1
|
||||
|
||||
#define SDL_VIDEO_RENDER_D3D 1
|
||||
#define SDL_VIDEO_RENDER_GDI 1
|
||||
|
||||
/* Enable OpenGL support */
|
||||
#ifndef _WIN32_WCE
|
||||
#define SDL_VIDEO_OPENGL 1
|
||||
#define SDL_VIDEO_OPENGL_WGL 1
|
||||
#define SDL_VIDEO_RENDER_OGL 1
|
||||
#endif
|
||||
|
||||
/* Enable system power support */
|
||||
#define SDL_POWER_WINDOWS 1
|
||||
|
||||
/* Enable assembly routines (Win64 doesn't have inline asm) */
|
||||
#ifndef _WIN64
|
||||
#define SDL_ASSEMBLY_ROUTINES 1
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_config_win32_h */
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
|
|
@ -1,84 +1,92 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_cpuinfo.h
|
||||
*
|
||||
* CPU feature detection for SDL
|
||||
*/
|
||||
|
||||
#ifndef _SDL_cpuinfo_h
|
||||
#define _SDL_cpuinfo_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* This function returns true if the CPU has the RDTSC instruction
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
|
||||
|
||||
/* This function returns true if the CPU has MMX features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
|
||||
|
||||
/* This function returns true if the CPU has MMX Ext. features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMXExt(void);
|
||||
|
||||
/* This function returns true if the CPU has 3DNow features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
|
||||
|
||||
/* This function returns true if the CPU has 3DNow! Ext. features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNowExt(void);
|
||||
|
||||
/* This function returns true if the CPU has SSE features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
|
||||
|
||||
/* This function returns true if the CPU has SSE2 features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
|
||||
|
||||
/* This function returns true if the CPU has AltiVec features
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_cpuinfo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_cpuinfo.h
|
||||
*
|
||||
* CPU feature detection for SDL.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_cpuinfo_h
|
||||
#define _SDL_cpuinfo_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has the RDTSC instruction.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has MMX features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has MMX Ext.\ features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMXExt(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has 3DNow!\ features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has 3DNow!\ Ext.\ features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNowExt(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has SSE features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has SSE2 features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has AltiVec features.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_cpuinfo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,240 +1,253 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_endian.h
|
||||
*
|
||||
* Functions for reading and writing endian-specific values
|
||||
*/
|
||||
|
||||
#ifndef _SDL_endian_h
|
||||
#define _SDL_endian_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
/* The two types of endianness */
|
||||
#define SDL_LIL_ENDIAN 1234
|
||||
#define SDL_BIG_ENDIAN 4321
|
||||
|
||||
#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
|
||||
#if defined(__hppa__) || \
|
||||
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
|
||||
(defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
|
||||
defined(__sparc__)
|
||||
#define SDL_BYTEORDER SDL_BIG_ENDIAN
|
||||
#else
|
||||
#define SDL_BYTEORDER SDL_LIL_ENDIAN
|
||||
#endif
|
||||
#endif /* !SDL_BYTEORDER */
|
||||
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Use inline functions for compilers that support them, and static
|
||||
functions for those that do not. Because these functions become
|
||||
static for compilers that do not support inline functions, this
|
||||
header should only be included in files that actually use them.
|
||||
*/
|
||||
#if defined(__GNUC__) && defined(__i386__) && \
|
||||
!(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
Uint16 result;
|
||||
|
||||
__asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
|
||||
return result;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
__asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
return ((x << 8) | (x >> 8));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__)
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
__asm__("bswap %0": "=r"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
__asm__("bswapl %0": "=r"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
Uint32 result;
|
||||
|
||||
__asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
|
||||
__asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
|
||||
__asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
|
||||
return result;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) |
|
||||
(x >> 24));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
#if defined(__GNUC__) && defined(__i386__)
|
||||
static __inline__ Uint64
|
||||
SDL_Swap64(Uint64 x)
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Uint32 a, b;
|
||||
} s;
|
||||
Uint64 u;
|
||||
} v;
|
||||
v.u = x;
|
||||
__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
|
||||
"1"(v.s.
|
||||
b));
|
||||
return v.u;
|
||||
}
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
static __inline__ Uint64
|
||||
SDL_Swap64(Uint64 x)
|
||||
{
|
||||
__asm__("bswapq %0": "=r"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
static __inline__ Uint64
|
||||
SDL_Swap64(Uint64 x)
|
||||
{
|
||||
Uint32 hi, lo;
|
||||
|
||||
/* Separate into high and low 32-bit values and swap them */
|
||||
lo = (Uint32) (x & 0xFFFFFFFF);
|
||||
x >>= 32;
|
||||
hi = (Uint32) (x & 0xFFFFFFFF);
|
||||
x = SDL_Swap32(lo);
|
||||
x <<= 32;
|
||||
x |= SDL_Swap32(hi);
|
||||
return (x);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
/* This is mainly to keep compilers from complaining in SDL code.
|
||||
If there is no real 64-bit datatype, then compilers will complain about
|
||||
the fake 64-bit datatype that SDL provides when it compiles user code.
|
||||
*/
|
||||
#define SDL_Swap64(X) (X)
|
||||
#endif /* SDL_HAS_64BIT_TYPE */
|
||||
|
||||
|
||||
static __inline__ float
|
||||
SDL_SwapFloat(float x)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
Uint32 ui32;
|
||||
} swapper;
|
||||
swapper.f = x;
|
||||
swapper.ui32 = SDL_Swap32(swapper.ui32);
|
||||
return swapper.f;
|
||||
}
|
||||
|
||||
|
||||
/* Byteswap item from the specified endianness to the native endianness */
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
#define SDL_SwapLE16(X) (X)
|
||||
#define SDL_SwapLE32(X) (X)
|
||||
#define SDL_SwapLE64(X) (X)
|
||||
#define SDL_SwapFloatLE(X) (X)
|
||||
#define SDL_SwapBE16(X) SDL_Swap16(X)
|
||||
#define SDL_SwapBE32(X) SDL_Swap32(X)
|
||||
#define SDL_SwapBE64(X) SDL_Swap64(X)
|
||||
#define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
|
||||
#else
|
||||
#define SDL_SwapLE16(X) SDL_Swap16(X)
|
||||
#define SDL_SwapLE32(X) SDL_Swap32(X)
|
||||
#define SDL_SwapLE64(X) SDL_Swap64(X)
|
||||
#define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
|
||||
#define SDL_SwapBE16(X) (X)
|
||||
#define SDL_SwapBE32(X) (X)
|
||||
#define SDL_SwapBE64(X) (X)
|
||||
#define SDL_SwapFloatBE(X) (X)
|
||||
#endif
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_endian_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_endian.h
|
||||
*
|
||||
* Functions for reading and writing endian-specific values
|
||||
*/
|
||||
|
||||
#ifndef _SDL_endian_h
|
||||
#define _SDL_endian_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
/**
|
||||
* \name The two types of endianness
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_LIL_ENDIAN 1234
|
||||
#define SDL_BIG_ENDIAN 4321
|
||||
/*@}*/
|
||||
|
||||
#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
|
||||
#if defined(__hppa__) || \
|
||||
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
|
||||
(defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
|
||||
defined(__sparc__)
|
||||
#define SDL_BYTEORDER SDL_BIG_ENDIAN
|
||||
#else
|
||||
#define SDL_BYTEORDER SDL_LIL_ENDIAN
|
||||
#endif
|
||||
#endif /* !SDL_BYTEORDER */
|
||||
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \file SDL_endian.h
|
||||
*
|
||||
* Uses inline functions for compilers that support them, and static
|
||||
* functions for those that do not. Because these functions become
|
||||
* static for compilers that do not support inline functions, this
|
||||
* header should only be included in files that actually use them.
|
||||
*/
|
||||
#if defined(__GNUC__) && defined(__i386__) && \
|
||||
!(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
Uint16 result;
|
||||
|
||||
__asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
|
||||
return result;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
__asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
static __inline__ Uint16
|
||||
SDL_Swap16(Uint16 x)
|
||||
{
|
||||
return ((x << 8) | (x >> 8));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__)
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
__asm__("bswap %0": "=r"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
__asm__("bswapl %0": "=r"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
Uint32 result;
|
||||
|
||||
__asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
|
||||
__asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
|
||||
__asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
|
||||
return result;
|
||||
}
|
||||
#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
static __inline__ Uint32
|
||||
SDL_Swap32(Uint32 x)
|
||||
{
|
||||
return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) |
|
||||
(x >> 24));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
#if defined(__GNUC__) && defined(__i386__)
|
||||
static __inline__ Uint64
|
||||
SDL_Swap64(Uint64 x)
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Uint32 a, b;
|
||||
} s;
|
||||
Uint64 u;
|
||||
} v;
|
||||
v.u = x;
|
||||
__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
|
||||
"1"(v.s.
|
||||
b));
|
||||
return v.u;
|
||||
}
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
static __inline__ Uint64
|
||||
SDL_Swap64(Uint64 x)
|
||||
{
|
||||
__asm__("bswapq %0": "=r"(x):"0"(x));
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
static __inline__ Uint64
|
||||
SDL_Swap64(Uint64 x)
|
||||
{
|
||||
Uint32 hi, lo;
|
||||
|
||||
/* Separate into high and low 32-bit values and swap them */
|
||||
lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
|
||||
x >>= 32;
|
||||
hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
|
||||
x = SDL_Swap32(lo);
|
||||
x <<= 32;
|
||||
x |= SDL_Swap32(hi);
|
||||
return (x);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
/**
|
||||
* This is mainly to keep compilers from complaining in SDL code.
|
||||
* If there is no real 64-bit datatype, then compilers will complain about
|
||||
* the fake 64-bit datatype that SDL provides when it compiles user code.
|
||||
*/
|
||||
#define SDL_Swap64(X) (X)
|
||||
#endif /* SDL_HAS_64BIT_TYPE */
|
||||
|
||||
|
||||
static __inline__ float
|
||||
SDL_SwapFloat(float x)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
Uint32 ui32;
|
||||
} swapper;
|
||||
swapper.f = x;
|
||||
swapper.ui32 = SDL_Swap32(swapper.ui32);
|
||||
return swapper.f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \name Swap to native
|
||||
* Byteswap item from the specified endianness to the native endianness.
|
||||
*/
|
||||
/*@{*/
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
#define SDL_SwapLE16(X) (X)
|
||||
#define SDL_SwapLE32(X) (X)
|
||||
#define SDL_SwapLE64(X) (X)
|
||||
#define SDL_SwapFloatLE(X) (X)
|
||||
#define SDL_SwapBE16(X) SDL_Swap16(X)
|
||||
#define SDL_SwapBE32(X) SDL_Swap32(X)
|
||||
#define SDL_SwapBE64(X) SDL_Swap64(X)
|
||||
#define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
|
||||
#else
|
||||
#define SDL_SwapLE16(X) SDL_Swap16(X)
|
||||
#define SDL_SwapLE32(X) SDL_Swap32(X)
|
||||
#define SDL_SwapLE64(X) SDL_Swap64(X)
|
||||
#define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
|
||||
#define SDL_SwapBE16(X) (X)
|
||||
#define SDL_SwapBE32(X) (X)
|
||||
#define SDL_SwapBE64(X) (X)
|
||||
#define SDL_SwapFloatBE(X) (X)
|
||||
#endif
|
||||
/*@}*//*Swap to native*/
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_endian_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,71 +1,78 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_error.h
|
||||
* Simple error message routines for SDL
|
||||
*/
|
||||
|
||||
#ifndef _SDL_error_h
|
||||
#define _SDL_error_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Public functions */
|
||||
extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...);
|
||||
extern DECLSPEC char *SDLCALL SDL_GetError(void);
|
||||
extern DECLSPEC void SDLCALL SDL_ClearError(void);
|
||||
|
||||
/* Private error message function - used internally */
|
||||
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
|
||||
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
|
||||
typedef enum
|
||||
{
|
||||
SDL_ENOMEM,
|
||||
SDL_EFREAD,
|
||||
SDL_EFWRITE,
|
||||
SDL_EFSEEK,
|
||||
SDL_UNSUPPORTED,
|
||||
SDL_LASTERROR
|
||||
} SDL_errorcode;
|
||||
extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_error_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_error.h
|
||||
*
|
||||
* Simple error message routines for SDL.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_error_h
|
||||
#define _SDL_error_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Public functions */
|
||||
extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...);
|
||||
extern DECLSPEC char *SDLCALL SDL_GetError(void);
|
||||
extern DECLSPEC void SDLCALL SDL_ClearError(void);
|
||||
|
||||
/**
|
||||
* \name Internal error functions
|
||||
*
|
||||
* \internal
|
||||
* Private error message function - used internally.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
|
||||
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
|
||||
typedef enum
|
||||
{
|
||||
SDL_ENOMEM,
|
||||
SDL_EFREAD,
|
||||
SDL_EFWRITE,
|
||||
SDL_EFSEEK,
|
||||
SDL_UNSUPPORTED,
|
||||
SDL_LASTERROR
|
||||
} SDL_errorcode;
|
||||
extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
|
||||
/*@}*//*Internal error functions*/
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_error_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,181 +1,209 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_joystick.h
|
||||
*
|
||||
* Include file for SDL joystick event handling
|
||||
*/
|
||||
|
||||
#ifndef _SDL_joystick_h
|
||||
#define _SDL_joystick_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* In order to use these functions, SDL_Init() must have been called
|
||||
with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
|
||||
for joysticks, and load appropriate drivers.
|
||||
*/
|
||||
|
||||
/* The joystick structure used to identify an SDL joystick */
|
||||
struct _SDL_Joystick;
|
||||
typedef struct _SDL_Joystick SDL_Joystick;
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
/*
|
||||
* Count the number of joysticks attached to the system
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
|
||||
|
||||
/*
|
||||
* Get the implementation dependent name of a joystick.
|
||||
* This can be called before any joysticks are opened.
|
||||
* If no name can be found, this function returns NULL.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
|
||||
|
||||
/*
|
||||
* Open a joystick for use - the index passed as an argument refers to
|
||||
* the N'th joystick on the system. This index is the value which will
|
||||
* identify this joystick in future joystick events.
|
||||
*
|
||||
* This function returns a joystick identifier, or NULL if an error occurred.
|
||||
*/
|
||||
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
|
||||
|
||||
/*
|
||||
* Returns 1 if the joystick has been opened, or 0 if it has not.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
|
||||
|
||||
/*
|
||||
* Get the device index of an opened joystick.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
|
||||
|
||||
/*
|
||||
* Get the number of general axis controls on a joystick
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
|
||||
|
||||
/*
|
||||
* Get the number of trackballs on a joystick
|
||||
* Joystick trackballs have only relative motion events associated
|
||||
* with them and their state cannot be polled.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
|
||||
|
||||
/*
|
||||
* Get the number of POV hats on a joystick
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
|
||||
|
||||
/*
|
||||
* Get the number of buttons on a joystick
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
|
||||
|
||||
/*
|
||||
* Update the current state of the open joysticks.
|
||||
* This is called automatically by the event loop if any joystick
|
||||
* events are enabled.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
|
||||
|
||||
/*
|
||||
* Enable/disable joystick event polling.
|
||||
* If joystick events are disabled, you must call SDL_JoystickUpdate()
|
||||
* yourself and check the state of the joystick when you want joystick
|
||||
* information.
|
||||
* The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
|
||||
|
||||
/*
|
||||
* Get the current state of an axis control on a joystick
|
||||
* The state is a value ranging from -32768 to 32767.
|
||||
* The axis indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
|
||||
int axis);
|
||||
|
||||
/*
|
||||
* Get the current state of a POV hat on a joystick
|
||||
* The return value is one of the following positions:
|
||||
*/
|
||||
#define SDL_HAT_CENTERED 0x00
|
||||
#define SDL_HAT_UP 0x01
|
||||
#define SDL_HAT_RIGHT 0x02
|
||||
#define SDL_HAT_DOWN 0x04
|
||||
#define SDL_HAT_LEFT 0x08
|
||||
#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
|
||||
#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
|
||||
#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
|
||||
#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
|
||||
/*
|
||||
* The hat indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
|
||||
int hat);
|
||||
|
||||
/*
|
||||
* Get the ball axis change since the last poll
|
||||
* This returns 0, or -1 if you passed it invalid parameters.
|
||||
* The ball indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
|
||||
int ball, int *dx, int *dy);
|
||||
|
||||
/*
|
||||
* Get the current state of a button on a joystick
|
||||
* The button indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
|
||||
int button);
|
||||
|
||||
/*
|
||||
* Close a joystick previously opened with SDL_JoystickOpen()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_joystick_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_joystick.h
|
||||
*
|
||||
* Include file for SDL joystick event handling
|
||||
*/
|
||||
|
||||
#ifndef _SDL_joystick_h
|
||||
#define _SDL_joystick_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \file SDL_joystick.h
|
||||
*
|
||||
* In order to use these functions, SDL_Init() must have been called
|
||||
* with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
|
||||
* for joysticks, and load appropriate drivers.
|
||||
*/
|
||||
|
||||
/* The joystick structure used to identify an SDL joystick */
|
||||
struct _SDL_Joystick;
|
||||
typedef struct _SDL_Joystick SDL_Joystick;
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
/**
|
||||
* Count the number of joysticks attached to the system
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
|
||||
|
||||
/**
|
||||
* Get the implementation dependent name of a joystick.
|
||||
* This can be called before any joysticks are opened.
|
||||
* If no name can be found, this function returns NULL.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
|
||||
|
||||
/**
|
||||
* Open a joystick for use.
|
||||
* The index passed as an argument refers tothe N'th joystick on the system.
|
||||
* This index is the value which will identify this joystick in future joystick
|
||||
* events.
|
||||
*
|
||||
* \return A joystick identifier, or NULL if an error occurred.
|
||||
*/
|
||||
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
|
||||
|
||||
/**
|
||||
* Returns 1 if the joystick has been opened, or 0 if it has not.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
|
||||
|
||||
/**
|
||||
* Get the device index of an opened joystick.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
|
||||
|
||||
/**
|
||||
* Get the number of general axis controls on a joystick.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
|
||||
|
||||
/**
|
||||
* Get the number of trackballs on a joystick.
|
||||
*
|
||||
* Joystick trackballs have only relative motion events associated
|
||||
* with them and their state cannot be polled.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
|
||||
|
||||
/**
|
||||
* Get the number of POV hats on a joystick.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
|
||||
|
||||
/**
|
||||
* Get the number of buttons on a joystick.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
|
||||
|
||||
/**
|
||||
* Update the current state of the open joysticks.
|
||||
*
|
||||
* This is called automatically by the event loop if any joystick
|
||||
* events are enabled.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
|
||||
|
||||
/**
|
||||
* Enable/disable joystick event polling.
|
||||
*
|
||||
* If joystick events are disabled, you must call SDL_JoystickUpdate()
|
||||
* yourself and check the state of the joystick when you want joystick
|
||||
* information.
|
||||
*
|
||||
* The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
|
||||
|
||||
/**
|
||||
* Get the current state of an axis control on a joystick.
|
||||
*
|
||||
* The state is a value ranging from -32768 to 32767.
|
||||
*
|
||||
* The axis indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
|
||||
int axis);
|
||||
|
||||
/**
|
||||
* \name Hat positions
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_HAT_CENTERED 0x00
|
||||
#define SDL_HAT_UP 0x01
|
||||
#define SDL_HAT_RIGHT 0x02
|
||||
#define SDL_HAT_DOWN 0x04
|
||||
#define SDL_HAT_LEFT 0x08
|
||||
#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
|
||||
#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
|
||||
#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
|
||||
#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Get the current state of a POV hat on a joystick.
|
||||
*
|
||||
* The hat indices start at index 0.
|
||||
*
|
||||
* \return The return value is one of the following positions:
|
||||
* - ::SDL_HAT_CENTERED
|
||||
* - ::SDL_HAT_UP
|
||||
* - ::SDL_HAT_RIGHT
|
||||
* - ::SDL_HAT_DOWN
|
||||
* - ::SDL_HAT_LEFT
|
||||
* - ::SDL_HAT_RIGHTUP
|
||||
* - ::SDL_HAT_RIGHTDOWN
|
||||
* - ::SDL_HAT_LEFTUP
|
||||
* - ::SDL_HAT_LEFTDOWN
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
|
||||
int hat);
|
||||
|
||||
/**
|
||||
* Get the ball axis change since the last poll.
|
||||
*
|
||||
* \return 0, or -1 if you passed it invalid parameters.
|
||||
*
|
||||
* The ball indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
|
||||
int ball, int *dx, int *dy);
|
||||
|
||||
/**
|
||||
* Get the current state of a button on a joystick.
|
||||
*
|
||||
* The button indices start at index 0.
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
|
||||
int button);
|
||||
|
||||
/**
|
||||
* Close a joystick previously opened with SDL_JoystickOpen().
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_joystick_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,168 +1,182 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_keyboard.h
|
||||
*
|
||||
* Include file for SDL keyboard event handling
|
||||
*/
|
||||
|
||||
#ifndef _SDL_keyboard_h
|
||||
#define _SDL_keyboard_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_keysym.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \struct SDL_keysym
|
||||
*
|
||||
* \brief The SDL keysym structure, used in key events.
|
||||
*/
|
||||
typedef struct SDL_keysym
|
||||
{
|
||||
SDL_scancode scancode; /**< SDL physical key code - see ::SDL_scancode for details */
|
||||
SDLKey sym; /**< SDL virtual key code - see ::SDLKey for details */
|
||||
Uint16 mod; /**< current key modifiers */
|
||||
Uint32 unicode; /**< OBSOLETE, use SDL_TextInputEvent instead */
|
||||
} SDL_keysym;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetNumKeyboards(void)
|
||||
*
|
||||
* \brief Get the number of keyboard input devices available.
|
||||
*
|
||||
* \sa SDL_SelectKeyboard()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumKeyboards(void);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SelectKeyboard(int index)
|
||||
*
|
||||
* \brief Set the index of the currently selected keyboard.
|
||||
*
|
||||
* \return The index of the previously selected keyboard.
|
||||
*
|
||||
* \note You can query the currently selected keyboard by passing an index of -1.
|
||||
*
|
||||
* \sa SDL_GetNumKeyboards()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
|
||||
|
||||
/**
|
||||
* \fn Uint8 *SDL_GetKeyboardState(int *numkeys)
|
||||
*
|
||||
* \brief Get a snapshot of the current state of the selected keyboard.
|
||||
*
|
||||
* \param numkeys if non-NULL, receives the length of the returned array.
|
||||
*
|
||||
* \return An array of key states. Indexes into this array are obtained by using ::SDL_scancode values.
|
||||
*
|
||||
* Example:
|
||||
* Uint8 *state = SDL_GetKeyboardState(NULL);
|
||||
* if ( state[SDL_SCANCODE_RETURN)] ) ... <RETURN> is pressed.
|
||||
*/
|
||||
extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
|
||||
|
||||
/**
|
||||
* \fn SDLMod SDL_GetModState(void)
|
||||
*
|
||||
* \brief Get the current key modifier state for the selected keyboard.
|
||||
*/
|
||||
extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
|
||||
|
||||
/**
|
||||
* \fn void SDL_SetModState(SDLMod modstate)
|
||||
*
|
||||
* \brief Set the current key modifier state for the selected keyboard.
|
||||
*
|
||||
* \note This does not change the keyboard state, only the key modifier flags.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
|
||||
|
||||
/**
|
||||
* \fn SDLKey SDL_GetKeyFromScancode(SDL_scancode scancode)
|
||||
*
|
||||
* \brief Get the key code corresponding to the given scancode according to the current keyboard layout.
|
||||
*
|
||||
* See ::SDLKey for details.
|
||||
*
|
||||
* \sa SDL_GetKeyName()
|
||||
*/
|
||||
extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_scancode scancode);
|
||||
|
||||
/**
|
||||
* \fn SDL_scancode SDL_GetScancodeFromKey(SDLKey key)
|
||||
*
|
||||
* \brief Get the scancode corresponding to the given key code according to the current keyboard layout.
|
||||
*
|
||||
* See ::SDL_scancode for details.
|
||||
*
|
||||
* \sa SDL_GetScancodeName()
|
||||
*/
|
||||
extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key);
|
||||
|
||||
/**
|
||||
* \fn const char *SDL_GetScancodeName(SDL_scancode scancode)
|
||||
*
|
||||
* \brief Get a human-readable name for a scancode.
|
||||
*
|
||||
* \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. If the scancode doesn't have a name, this function returns "".
|
||||
*
|
||||
* \sa SDL_scancode
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode
|
||||
scancode);
|
||||
|
||||
/**
|
||||
* \fn const char *SDL_GetKeyName(SDLKey key)
|
||||
*
|
||||
* \brief Get a human-readable name for a key.
|
||||
*
|
||||
* \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. If the key doesn't have a name, this function returns "".
|
||||
*
|
||||
* \sa SDLKey
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_keyboard_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_keyboard.h
|
||||
*
|
||||
* Include file for SDL keyboard event handling
|
||||
*/
|
||||
|
||||
#ifndef _SDL_keyboard_h
|
||||
#define _SDL_keyboard_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_keysym.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief The SDL keysym structure, used in key events.
|
||||
*/
|
||||
typedef struct SDL_keysym
|
||||
{
|
||||
SDL_scancode scancode; /**< SDL physical key code - see ::SDL_scancode for details */
|
||||
SDLKey sym; /**< SDL virtual key code - see ::SDLKey for details */
|
||||
Uint16 mod; /**< current key modifiers */
|
||||
Uint32 unicode; /**< \deprecated use SDL_TextInputEvent instead */
|
||||
} SDL_keysym;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
* \brief Get the number of keyboard input devices available.
|
||||
*
|
||||
* \sa SDL_SelectKeyboard()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumKeyboards(void);
|
||||
|
||||
/**
|
||||
* \brief Set the index of the currently selected keyboard.
|
||||
*
|
||||
* \return The index of the previously selected keyboard.
|
||||
*
|
||||
* \note You can query the currently selected keyboard by passing an index of -1.
|
||||
*
|
||||
* \sa SDL_GetNumKeyboards()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
|
||||
|
||||
/**
|
||||
* \brief Get a snapshot of the current state of the selected keyboard.
|
||||
*
|
||||
* \param numkeys if non-NULL, receives the length of the returned array.
|
||||
*
|
||||
* \return An array of key states. Indexes into this array are obtained by using ::SDL_scancode values.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* Uint8 *state = SDL_GetKeyboardState(NULL);
|
||||
* if ( state[SDL_SCANCODE_RETURN] ) {
|
||||
* printf("<RETURN> is pressed.\n");
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
|
||||
|
||||
/**
|
||||
* \brief Get the current key modifier state for the selected keyboard.
|
||||
*/
|
||||
extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
|
||||
|
||||
/**
|
||||
* \brief Set the current key modifier state for the selected keyboard.
|
||||
*
|
||||
* \note This does not change the keyboard state, only the key modifier flags.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
|
||||
|
||||
/**
|
||||
* \brief Get the key code corresponding to the given scancode according to the
|
||||
* current keyboard layout.
|
||||
*
|
||||
* See ::SDLKey for details.
|
||||
*
|
||||
* \sa SDL_GetKeyName()
|
||||
*/
|
||||
extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_scancode scancode);
|
||||
|
||||
/**
|
||||
* \brief Get the scancode corresponding to the given key code according to the
|
||||
* current keyboard layout.
|
||||
*
|
||||
* See ::SDL_scancode for details.
|
||||
*
|
||||
* \sa SDL_GetScancodeName()
|
||||
*/
|
||||
extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key);
|
||||
|
||||
/**
|
||||
* \brief Get a human-readable name for a scancode.
|
||||
*
|
||||
* \return A pointer to a UTF-8 string that stays valid at least until the next
|
||||
* call to this function. If you need it around any longer, you must
|
||||
* copy it. If the scancode doesn't have a name, this function returns
|
||||
* an empty string ("").
|
||||
*
|
||||
* \sa SDL_scancode
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode
|
||||
scancode);
|
||||
|
||||
/**
|
||||
* \brief Get a human-readable name for a key.
|
||||
*
|
||||
* \return A pointer to a UTF-8 string that stays valid at least until the next
|
||||
* call to this function. If you need it around any longer, you must
|
||||
* copy it. If the key doesn't have a name, this function returns an
|
||||
* empty string ("").
|
||||
*
|
||||
* \sa SDLKey
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
|
||||
|
||||
/**
|
||||
* \brief Start accepting Unicode text input events.
|
||||
*
|
||||
* \sa SDL_StopTextInput()
|
||||
* \sa SDL_SetTextInputRect()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
|
||||
|
||||
/**
|
||||
* \brief Stop receiving any text input events.
|
||||
*
|
||||
* \sa SDL_StartTextInput()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
|
||||
|
||||
/**
|
||||
* \brief Set the rectangle used to type Unicode text inputs.
|
||||
*
|
||||
* \sa SDL_StartTextInput()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_keyboard_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,277 +1,275 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_keysym.h
|
||||
*/
|
||||
|
||||
#ifndef _SDL_keysym_h
|
||||
#define _SDL_keysym_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_scancode.h"
|
||||
|
||||
/**
|
||||
* \typedef SDLKey
|
||||
*
|
||||
* \brief The SDL virtual key representation.
|
||||
*
|
||||
* Values of this type are used to represent keyboard keys using the current
|
||||
* layout of the keyboard. These values include Unicode values representing
|
||||
* the unmodified character that would be generated by pressing the key, or
|
||||
* an SDLK_* constant for those keys that do not generate characters.
|
||||
*/
|
||||
typedef Sint32 SDLKey;
|
||||
|
||||
#define SDLK_SCANCODE_MASK (1<<30)
|
||||
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
|
||||
|
||||
enum
|
||||
{
|
||||
SDLK_UNKNOWN = 0,
|
||||
|
||||
SDLK_RETURN = '\r',
|
||||
SDLK_ESCAPE = '\033',
|
||||
SDLK_BACKSPACE = '\b',
|
||||
SDLK_TAB = '\t',
|
||||
SDLK_SPACE = ' ',
|
||||
|
||||
SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
|
||||
|
||||
SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1),
|
||||
SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2),
|
||||
SDLK_F3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3),
|
||||
SDLK_F4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4),
|
||||
SDLK_F5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5),
|
||||
SDLK_F6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6),
|
||||
SDLK_F7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7),
|
||||
SDLK_F8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8),
|
||||
SDLK_F9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9),
|
||||
SDLK_F10 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10),
|
||||
SDLK_F11 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11),
|
||||
SDLK_F12 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12),
|
||||
|
||||
SDLK_PRINTSCREEN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN),
|
||||
SDLK_SCROLLLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK),
|
||||
SDLK_PAUSE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE),
|
||||
SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
|
||||
SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
|
||||
SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
|
||||
SDLK_DELETE = '\177',
|
||||
SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
|
||||
SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
|
||||
SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
|
||||
SDLK_LEFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT),
|
||||
SDLK_DOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN),
|
||||
SDLK_UP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP),
|
||||
|
||||
SDLK_NUMLOCKCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR),
|
||||
SDLK_KP_DIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE),
|
||||
SDLK_KP_MULTIPLY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY),
|
||||
SDLK_KP_MINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS),
|
||||
SDLK_KP_PLUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS),
|
||||
SDLK_KP_ENTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER),
|
||||
SDLK_KP_1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1),
|
||||
SDLK_KP_2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2),
|
||||
SDLK_KP_3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3),
|
||||
SDLK_KP_4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4),
|
||||
SDLK_KP_5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5),
|
||||
SDLK_KP_6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6),
|
||||
SDLK_KP_7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7),
|
||||
SDLK_KP_8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8),
|
||||
SDLK_KP_9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9),
|
||||
SDLK_KP_0 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0),
|
||||
SDLK_KP_PERIOD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD),
|
||||
|
||||
SDLK_APPLICATION = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION),
|
||||
SDLK_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER),
|
||||
SDLK_KP_EQUALS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS),
|
||||
SDLK_F13 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13),
|
||||
SDLK_F14 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14),
|
||||
SDLK_F15 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15),
|
||||
SDLK_F16 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16),
|
||||
SDLK_F17 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17),
|
||||
SDLK_F18 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18),
|
||||
SDLK_F19 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19),
|
||||
SDLK_F20 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20),
|
||||
SDLK_F21 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21),
|
||||
SDLK_F22 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22),
|
||||
SDLK_F23 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23),
|
||||
SDLK_F24 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24),
|
||||
SDLK_EXECUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE),
|
||||
SDLK_HELP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP),
|
||||
SDLK_MENU = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU),
|
||||
SDLK_SELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT),
|
||||
SDLK_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP),
|
||||
SDLK_AGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN),
|
||||
SDLK_UNDO = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO),
|
||||
SDLK_CUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT),
|
||||
SDLK_COPY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY),
|
||||
SDLK_PASTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE),
|
||||
SDLK_FIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND),
|
||||
SDLK_MUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE),
|
||||
SDLK_VOLUMEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP),
|
||||
SDLK_VOLUMEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN),
|
||||
SDLK_KP_COMMA = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA),
|
||||
SDLK_KP_EQUALSAS400 =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400),
|
||||
|
||||
SDLK_ALTERASE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE),
|
||||
SDLK_SYSREQ = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ),
|
||||
SDLK_CANCEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL),
|
||||
SDLK_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR),
|
||||
SDLK_PRIOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR),
|
||||
SDLK_RETURN2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2),
|
||||
SDLK_SEPARATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR),
|
||||
SDLK_OUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT),
|
||||
SDLK_OPER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER),
|
||||
SDLK_CLEARAGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN),
|
||||
SDLK_CRSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL),
|
||||
SDLK_EXSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL),
|
||||
|
||||
SDLK_KP_00 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00),
|
||||
SDLK_KP_000 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000),
|
||||
SDLK_THOUSANDSSEPARATOR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR),
|
||||
SDLK_DECIMALSEPARATOR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR),
|
||||
SDLK_CURRENCYUNIT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT),
|
||||
SDLK_CURRENCYSUBUNIT =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT),
|
||||
SDLK_KP_LEFTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN),
|
||||
SDLK_KP_RIGHTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN),
|
||||
SDLK_KP_LEFTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE),
|
||||
SDLK_KP_RIGHTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE),
|
||||
SDLK_KP_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB),
|
||||
SDLK_KP_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE),
|
||||
SDLK_KP_A = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A),
|
||||
SDLK_KP_B = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B),
|
||||
SDLK_KP_C = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C),
|
||||
SDLK_KP_D = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D),
|
||||
SDLK_KP_E = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E),
|
||||
SDLK_KP_F = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F),
|
||||
SDLK_KP_XOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR),
|
||||
SDLK_KP_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER),
|
||||
SDLK_KP_PERCENT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT),
|
||||
SDLK_KP_LESS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS),
|
||||
SDLK_KP_GREATER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER),
|
||||
SDLK_KP_AMPERSAND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND),
|
||||
SDLK_KP_DBLAMPERSAND =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND),
|
||||
SDLK_KP_VERTICALBAR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR),
|
||||
SDLK_KP_DBLVERTICALBAR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR),
|
||||
SDLK_KP_COLON = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON),
|
||||
SDLK_KP_HASH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH),
|
||||
SDLK_KP_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE),
|
||||
SDLK_KP_AT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT),
|
||||
SDLK_KP_EXCLAM = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM),
|
||||
SDLK_KP_MEMSTORE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE),
|
||||
SDLK_KP_MEMRECALL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL),
|
||||
SDLK_KP_MEMCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR),
|
||||
SDLK_KP_MEMADD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD),
|
||||
SDLK_KP_MEMSUBTRACT =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT),
|
||||
SDLK_KP_MEMMULTIPLY =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY),
|
||||
SDLK_KP_MEMDIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE),
|
||||
SDLK_KP_PLUSMINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS),
|
||||
SDLK_KP_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR),
|
||||
SDLK_KP_CLEARENTRY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY),
|
||||
SDLK_KP_BINARY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY),
|
||||
SDLK_KP_OCTAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL),
|
||||
SDLK_KP_DECIMAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL),
|
||||
SDLK_KP_HEXADECIMAL =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL),
|
||||
|
||||
SDLK_LCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL),
|
||||
SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),
|
||||
SDLK_LALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT),
|
||||
SDLK_LGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI),
|
||||
SDLK_RCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL),
|
||||
SDLK_RSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT),
|
||||
SDLK_RALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT),
|
||||
SDLK_RGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI),
|
||||
|
||||
SDLK_MODE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE),
|
||||
|
||||
SDLK_AUDIONEXT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIONEXT),
|
||||
SDLK_AUDIOPREV = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPREV),
|
||||
SDLK_AUDIOSTOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOSTOP),
|
||||
SDLK_AUDIOPLAY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPLAY),
|
||||
SDLK_AUDIOMUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOMUTE),
|
||||
SDLK_MEDIASELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIASELECT),
|
||||
SDLK_WWW = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WWW),
|
||||
SDLK_MAIL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MAIL),
|
||||
SDLK_CALCULATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALCULATOR),
|
||||
SDLK_COMPUTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COMPUTER),
|
||||
SDLK_AC_SEARCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH),
|
||||
SDLK_AC_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME),
|
||||
SDLK_AC_BACK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK),
|
||||
SDLK_AC_FORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD),
|
||||
SDLK_AC_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP),
|
||||
SDLK_AC_REFRESH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH),
|
||||
SDLK_AC_BOOKMARKS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS),
|
||||
|
||||
SDLK_BRIGHTNESSDOWN =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSDOWN),
|
||||
SDLK_BRIGHTNESSUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSUP),
|
||||
SDLK_DISPLAYSWITCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DISPLAYSWITCH),
|
||||
SDLK_KBDILLUMTOGGLE =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMTOGGLE),
|
||||
SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
|
||||
SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
|
||||
SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
|
||||
SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP)
|
||||
};
|
||||
|
||||
/**
|
||||
* \enum SDLMod
|
||||
*
|
||||
* \brief Enumeration of valid key mods (possibly OR'd together)
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KMOD_NONE = 0x0000,
|
||||
KMOD_LSHIFT = 0x0001,
|
||||
KMOD_RSHIFT = 0x0002,
|
||||
KMOD_LCTRL = 0x0040,
|
||||
KMOD_RCTRL = 0x0080,
|
||||
KMOD_LALT = 0x0100,
|
||||
KMOD_RALT = 0x0200,
|
||||
KMOD_LGUI = 0x0400,
|
||||
KMOD_RGUI = 0x0800,
|
||||
KMOD_NUM = 0x1000,
|
||||
KMOD_CAPS = 0x2000,
|
||||
KMOD_MODE = 0x4000,
|
||||
KMOD_RESERVED = 0x8000
|
||||
} SDLMod;
|
||||
|
||||
#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL)
|
||||
#define KMOD_SHIFT (KMOD_LSHIFT|KMOD_RSHIFT)
|
||||
#define KMOD_ALT (KMOD_LALT|KMOD_RALT)
|
||||
#define KMOD_GUI (KMOD_LGUI|KMOD_RGUI)
|
||||
|
||||
#endif /* _SDL_keysym_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_keysym.h
|
||||
*
|
||||
* Defines constants which identify keyboard keys and modifiers.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_keysym_h
|
||||
#define _SDL_keysym_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_scancode.h"
|
||||
|
||||
/**
|
||||
* \brief The SDL virtual key representation.
|
||||
*
|
||||
* Values of this type are used to represent keyboard keys using the current
|
||||
* layout of the keyboard. These values include Unicode values representing
|
||||
* the unmodified character that would be generated by pressing the key, or
|
||||
* an SDLK_* constant for those keys that do not generate characters.
|
||||
*/
|
||||
typedef Sint32 SDLKey;
|
||||
|
||||
#define SDLK_SCANCODE_MASK (1<<30)
|
||||
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
|
||||
|
||||
enum
|
||||
{
|
||||
SDLK_UNKNOWN = 0,
|
||||
|
||||
SDLK_RETURN = '\r',
|
||||
SDLK_ESCAPE = '\033',
|
||||
SDLK_BACKSPACE = '\b',
|
||||
SDLK_TAB = '\t',
|
||||
SDLK_SPACE = ' ',
|
||||
|
||||
SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
|
||||
|
||||
SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1),
|
||||
SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2),
|
||||
SDLK_F3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3),
|
||||
SDLK_F4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4),
|
||||
SDLK_F5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5),
|
||||
SDLK_F6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6),
|
||||
SDLK_F7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7),
|
||||
SDLK_F8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8),
|
||||
SDLK_F9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9),
|
||||
SDLK_F10 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10),
|
||||
SDLK_F11 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11),
|
||||
SDLK_F12 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12),
|
||||
|
||||
SDLK_PRINTSCREEN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN),
|
||||
SDLK_SCROLLLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK),
|
||||
SDLK_PAUSE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE),
|
||||
SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
|
||||
SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
|
||||
SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
|
||||
SDLK_DELETE = '\177',
|
||||
SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
|
||||
SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
|
||||
SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
|
||||
SDLK_LEFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT),
|
||||
SDLK_DOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN),
|
||||
SDLK_UP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP),
|
||||
|
||||
SDLK_NUMLOCKCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR),
|
||||
SDLK_KP_DIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE),
|
||||
SDLK_KP_MULTIPLY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY),
|
||||
SDLK_KP_MINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS),
|
||||
SDLK_KP_PLUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS),
|
||||
SDLK_KP_ENTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER),
|
||||
SDLK_KP_1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1),
|
||||
SDLK_KP_2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2),
|
||||
SDLK_KP_3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3),
|
||||
SDLK_KP_4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4),
|
||||
SDLK_KP_5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5),
|
||||
SDLK_KP_6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6),
|
||||
SDLK_KP_7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7),
|
||||
SDLK_KP_8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8),
|
||||
SDLK_KP_9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9),
|
||||
SDLK_KP_0 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0),
|
||||
SDLK_KP_PERIOD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD),
|
||||
|
||||
SDLK_APPLICATION = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION),
|
||||
SDLK_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER),
|
||||
SDLK_KP_EQUALS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS),
|
||||
SDLK_F13 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13),
|
||||
SDLK_F14 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14),
|
||||
SDLK_F15 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15),
|
||||
SDLK_F16 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16),
|
||||
SDLK_F17 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17),
|
||||
SDLK_F18 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18),
|
||||
SDLK_F19 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19),
|
||||
SDLK_F20 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20),
|
||||
SDLK_F21 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21),
|
||||
SDLK_F22 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22),
|
||||
SDLK_F23 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23),
|
||||
SDLK_F24 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24),
|
||||
SDLK_EXECUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE),
|
||||
SDLK_HELP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP),
|
||||
SDLK_MENU = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU),
|
||||
SDLK_SELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT),
|
||||
SDLK_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP),
|
||||
SDLK_AGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN),
|
||||
SDLK_UNDO = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO),
|
||||
SDLK_CUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT),
|
||||
SDLK_COPY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY),
|
||||
SDLK_PASTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE),
|
||||
SDLK_FIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND),
|
||||
SDLK_MUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE),
|
||||
SDLK_VOLUMEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP),
|
||||
SDLK_VOLUMEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN),
|
||||
SDLK_KP_COMMA = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA),
|
||||
SDLK_KP_EQUALSAS400 =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400),
|
||||
|
||||
SDLK_ALTERASE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE),
|
||||
SDLK_SYSREQ = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ),
|
||||
SDLK_CANCEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL),
|
||||
SDLK_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR),
|
||||
SDLK_PRIOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR),
|
||||
SDLK_RETURN2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2),
|
||||
SDLK_SEPARATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR),
|
||||
SDLK_OUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT),
|
||||
SDLK_OPER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER),
|
||||
SDLK_CLEARAGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN),
|
||||
SDLK_CRSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL),
|
||||
SDLK_EXSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL),
|
||||
|
||||
SDLK_KP_00 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00),
|
||||
SDLK_KP_000 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000),
|
||||
SDLK_THOUSANDSSEPARATOR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR),
|
||||
SDLK_DECIMALSEPARATOR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR),
|
||||
SDLK_CURRENCYUNIT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT),
|
||||
SDLK_CURRENCYSUBUNIT =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT),
|
||||
SDLK_KP_LEFTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN),
|
||||
SDLK_KP_RIGHTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN),
|
||||
SDLK_KP_LEFTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE),
|
||||
SDLK_KP_RIGHTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE),
|
||||
SDLK_KP_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB),
|
||||
SDLK_KP_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE),
|
||||
SDLK_KP_A = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A),
|
||||
SDLK_KP_B = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B),
|
||||
SDLK_KP_C = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C),
|
||||
SDLK_KP_D = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D),
|
||||
SDLK_KP_E = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E),
|
||||
SDLK_KP_F = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F),
|
||||
SDLK_KP_XOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR),
|
||||
SDLK_KP_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER),
|
||||
SDLK_KP_PERCENT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT),
|
||||
SDLK_KP_LESS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS),
|
||||
SDLK_KP_GREATER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER),
|
||||
SDLK_KP_AMPERSAND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND),
|
||||
SDLK_KP_DBLAMPERSAND =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND),
|
||||
SDLK_KP_VERTICALBAR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR),
|
||||
SDLK_KP_DBLVERTICALBAR =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR),
|
||||
SDLK_KP_COLON = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON),
|
||||
SDLK_KP_HASH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH),
|
||||
SDLK_KP_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE),
|
||||
SDLK_KP_AT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT),
|
||||
SDLK_KP_EXCLAM = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM),
|
||||
SDLK_KP_MEMSTORE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE),
|
||||
SDLK_KP_MEMRECALL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL),
|
||||
SDLK_KP_MEMCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR),
|
||||
SDLK_KP_MEMADD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD),
|
||||
SDLK_KP_MEMSUBTRACT =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT),
|
||||
SDLK_KP_MEMMULTIPLY =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY),
|
||||
SDLK_KP_MEMDIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE),
|
||||
SDLK_KP_PLUSMINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS),
|
||||
SDLK_KP_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR),
|
||||
SDLK_KP_CLEARENTRY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY),
|
||||
SDLK_KP_BINARY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY),
|
||||
SDLK_KP_OCTAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL),
|
||||
SDLK_KP_DECIMAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL),
|
||||
SDLK_KP_HEXADECIMAL =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL),
|
||||
|
||||
SDLK_LCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL),
|
||||
SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),
|
||||
SDLK_LALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT),
|
||||
SDLK_LGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI),
|
||||
SDLK_RCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL),
|
||||
SDLK_RSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT),
|
||||
SDLK_RALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT),
|
||||
SDLK_RGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI),
|
||||
|
||||
SDLK_MODE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE),
|
||||
|
||||
SDLK_AUDIONEXT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIONEXT),
|
||||
SDLK_AUDIOPREV = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPREV),
|
||||
SDLK_AUDIOSTOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOSTOP),
|
||||
SDLK_AUDIOPLAY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPLAY),
|
||||
SDLK_AUDIOMUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOMUTE),
|
||||
SDLK_MEDIASELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIASELECT),
|
||||
SDLK_WWW = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WWW),
|
||||
SDLK_MAIL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MAIL),
|
||||
SDLK_CALCULATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALCULATOR),
|
||||
SDLK_COMPUTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COMPUTER),
|
||||
SDLK_AC_SEARCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH),
|
||||
SDLK_AC_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME),
|
||||
SDLK_AC_BACK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK),
|
||||
SDLK_AC_FORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD),
|
||||
SDLK_AC_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP),
|
||||
SDLK_AC_REFRESH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH),
|
||||
SDLK_AC_BOOKMARKS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS),
|
||||
|
||||
SDLK_BRIGHTNESSDOWN =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSDOWN),
|
||||
SDLK_BRIGHTNESSUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSUP),
|
||||
SDLK_DISPLAYSWITCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DISPLAYSWITCH),
|
||||
SDLK_KBDILLUMTOGGLE =
|
||||
SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMTOGGLE),
|
||||
SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
|
||||
SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
|
||||
SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
|
||||
SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP)
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Enumeration of valid key mods (possibly OR'd together).
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KMOD_NONE = 0x0000,
|
||||
KMOD_LSHIFT = 0x0001,
|
||||
KMOD_RSHIFT = 0x0002,
|
||||
KMOD_LCTRL = 0x0040,
|
||||
KMOD_RCTRL = 0x0080,
|
||||
KMOD_LALT = 0x0100,
|
||||
KMOD_RALT = 0x0200,
|
||||
KMOD_LGUI = 0x0400,
|
||||
KMOD_RGUI = 0x0800,
|
||||
KMOD_NUM = 0x1000,
|
||||
KMOD_CAPS = 0x2000,
|
||||
KMOD_MODE = 0x4000,
|
||||
KMOD_RESERVED = 0x8000
|
||||
} SDLMod;
|
||||
|
||||
#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL)
|
||||
#define KMOD_SHIFT (KMOD_LSHIFT|KMOD_RSHIFT)
|
||||
#define KMOD_ALT (KMOD_LALT|KMOD_RALT)
|
||||
#define KMOD_GUI (KMOD_LGUI|KMOD_RGUI)
|
||||
|
||||
#endif /* _SDL_keysym_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,82 +1,86 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_loadso.h
|
||||
*
|
||||
* System dependent library loading routines
|
||||
*
|
||||
* Some things to keep in mind:
|
||||
* - These functions only work on C function names. Other languages may
|
||||
* have name mangling and intrinsic language support that varies from
|
||||
* compiler to compiler.
|
||||
* - Make sure you declare your function pointers with the same calling
|
||||
* convention as the actual library function. Your code will crash
|
||||
* mysteriously if you do not do this.
|
||||
* - Avoid namespace collisions. If you load a symbol from the library,
|
||||
* it is not defined whether or not it goes into the global symbol
|
||||
* namespace for the application. If it does and it conflicts with
|
||||
* symbols in your code or other shared libraries, you will not get
|
||||
* the results you expect. :)
|
||||
*/
|
||||
|
||||
#ifndef _SDL_loadso_h
|
||||
#define _SDL_loadso_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* This function dynamically loads a shared object and returns a pointer
|
||||
* to the object handle (or NULL if there was an error).
|
||||
* The 'sofile' parameter is a system dependent name of the object file.
|
||||
*/
|
||||
extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
|
||||
|
||||
/* Given an object handle, this function looks up the address of the
|
||||
* named function in the shared object and returns it. This address
|
||||
* is no longer valid after calling SDL_UnloadObject().
|
||||
*/
|
||||
extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
|
||||
const char *name);
|
||||
|
||||
/* Unload a shared object from memory */
|
||||
extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_loadso_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_loadso.h
|
||||
*
|
||||
* System dependent library loading routines
|
||||
*
|
||||
* Some things to keep in mind:
|
||||
* \li These functions only work on C function names. Other languages may
|
||||
* have name mangling and intrinsic language support that varies from
|
||||
* compiler to compiler.
|
||||
* \li Make sure you declare your function pointers with the same calling
|
||||
* convention as the actual library function. Your code will crash
|
||||
* mysteriously if you do not do this.
|
||||
* \li Avoid namespace collisions. If you load a symbol from the library,
|
||||
* it is not defined whether or not it goes into the global symbol
|
||||
* namespace for the application. If it does and it conflicts with
|
||||
* symbols in your code or other shared libraries, you will not get
|
||||
* the results you expect. :)
|
||||
*/
|
||||
|
||||
#ifndef _SDL_loadso_h
|
||||
#define _SDL_loadso_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function dynamically loads a shared object and returns a pointer
|
||||
* to the object handle (or NULL if there was an error).
|
||||
* The 'sofile' parameter is a system dependent name of the object file.
|
||||
*/
|
||||
extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
|
||||
|
||||
/**
|
||||
* Given an object handle, this function looks up the address of the
|
||||
* named function in the shared object and returns it. This address
|
||||
* is no longer valid after calling SDL_UnloadObject().
|
||||
*/
|
||||
extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Unload a shared object from memory.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_loadso_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,82 +1,96 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_main_h
|
||||
#define _SDL_main_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
/* Redefine main() on some platforms so that it is called by SDL */
|
||||
|
||||
#if defined(__WIN32__) || \
|
||||
(defined(__MWERKS__) && !defined(__BEOS__)) || \
|
||||
defined(__SYMBIAN32__) || defined(__IPHONEOS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define C_LINKAGE "C"
|
||||
#else
|
||||
#define C_LINKAGE
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* The application's main() function must be called with C linkage,
|
||||
and should be declared like this:
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
}
|
||||
*/
|
||||
#define main SDL_main
|
||||
|
||||
/* The prototype for the application's main() function */
|
||||
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
|
||||
|
||||
|
||||
/* From the SDL library code -- needed for registering the app on Win32 */
|
||||
#ifdef __WIN32__
|
||||
|
||||
#include "begin_code.h"
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* This can be called to set the application class at startup */
|
||||
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
|
||||
void *hInst);
|
||||
extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
#endif
|
||||
|
||||
#endif /* Need to redefine main()? */
|
||||
|
||||
#endif /* _SDL_main_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_main_h
|
||||
#define _SDL_main_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
/**
|
||||
* \file SDL_main.h
|
||||
*
|
||||
* Redefine main() on some platforms so that it is called by SDL.
|
||||
*/
|
||||
|
||||
#if defined(__WIN32__) || \
|
||||
(defined(__MWERKS__) && !defined(__BEOS__)) || \
|
||||
defined(__SYMBIAN32__) || defined(__IPHONEOS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define C_LINKAGE "C"
|
||||
#else
|
||||
#define C_LINKAGE
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* \file SDL_main.h
|
||||
*
|
||||
* The application's main() function must be called with C linkage,
|
||||
* and should be declared like this:
|
||||
* \code
|
||||
* #ifdef __cplusplus
|
||||
* extern "C"
|
||||
* #endif
|
||||
* int main(int argc, char *argv[])
|
||||
* {
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
#define main SDL_main
|
||||
|
||||
/**
|
||||
* The prototype for the application's main() function
|
||||
*/
|
||||
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
|
||||
|
||||
|
||||
/* From the SDL library code -- needed for registering the app on Win32 */
|
||||
#ifdef __WIN32__
|
||||
|
||||
#include "begin_code.h"
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This can be called to set the application class at startup
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
|
||||
void *hInst);
|
||||
extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
#endif
|
||||
|
||||
#endif /* Need to redefine main()? */
|
||||
|
||||
#endif /* _SDL_main_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,274 +1,252 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_mouse.h
|
||||
*
|
||||
* Include file for SDL mouse event handling
|
||||
*/
|
||||
|
||||
#ifndef _SDL_mouse_h
|
||||
#define _SDL_mouse_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_video.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetNumMice(void)
|
||||
*
|
||||
* \brief Get the number of mouse input devices available.
|
||||
*
|
||||
* \sa SDL_SelectMouse()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
|
||||
|
||||
/**
|
||||
* \fn char* SDL_GetMouseName(int index)
|
||||
*
|
||||
* \brief Gets the name of a mouse with the given index.
|
||||
*
|
||||
* \param index is the index of the mouse, which name is to be returned.
|
||||
*
|
||||
* \return the name of the mouse with the specified index
|
||||
*/
|
||||
extern DECLSPEC char *SDLCALL SDL_GetMouseName(int index);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SelectMouse(int index)
|
||||
*
|
||||
* \brief Set the index of the currently selected mouse.
|
||||
*
|
||||
* \return The index of the previously selected mouse.
|
||||
*
|
||||
* \note You can query the currently selected mouse by passing an index of -1.
|
||||
*
|
||||
* \sa SDL_GetNumMice()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
|
||||
|
||||
/**
|
||||
* \fn SDL_WindowID SDL_GetMouseFocusWindow(int index)
|
||||
*
|
||||
* \brief Get the window which currently has focus for the currently selected mouse.
|
||||
*/
|
||||
extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(int index);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetRelativeMouseMode(int index, SDL_bool enabled)
|
||||
*
|
||||
* \brief Set relative mouse mode for the currently selected mouse.
|
||||
*
|
||||
* \param enabled Whether or not to enable relative mode
|
||||
*
|
||||
* \return 0 on success, or -1 if relative mode is not supported.
|
||||
*
|
||||
* While the mouse is in relative mode, the cursor is hidden, and the
|
||||
* driver will try to report continuous motion in the current window.
|
||||
* Only relative motion events will be delivered, the mouse position
|
||||
* will not change.
|
||||
*
|
||||
* \note This function will flush any pending mouse motion.
|
||||
*
|
||||
* \sa SDL_GetRelativeMouseMode()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(int index,
|
||||
SDL_bool enabled);
|
||||
|
||||
/**
|
||||
* \fn SDL_bool SDL_GetRelativeMouseMode(int index)
|
||||
*
|
||||
* \brief Query whether relative mouse mode is enabled for the currently selected mouse.
|
||||
*
|
||||
* \sa SDL_SetRelativeMouseMode()
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(int index);
|
||||
|
||||
/**
|
||||
* \fn Uint8 SDL_GetMouseState(int index, int *x, int *y)
|
||||
*
|
||||
* \brief Retrieve the current state of the currently selected mouse.
|
||||
*
|
||||
* The current button state is returned as a button bitmask, which can
|
||||
* be tested using the SDL_BUTTON(X) macros, and x and y are set to the
|
||||
* mouse cursor position relative to the focus window for the currently
|
||||
* selected mouse. You can pass NULL for either x or y.
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int index, int *x, int *y);
|
||||
|
||||
/**
|
||||
* \fn Uint8 SDL_GetRelativeMouseState(int index, int *x, int *y)
|
||||
*
|
||||
* \brief Retrieve the state of the currently selected mouse.
|
||||
*
|
||||
* The current button state is returned as a button bitmask, which can
|
||||
* be tested using the SDL_BUTTON(X) macros, and x and y are set to the
|
||||
* mouse deltas since the last call to SDL_GetRelativeMouseState().
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int index, int *x,
|
||||
int *y);
|
||||
|
||||
/**
|
||||
* \fn void SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
|
||||
*
|
||||
* \brief Moves the currently selected mouse to the given position within the window.
|
||||
*
|
||||
* \param windowID The window to move the mouse into, or 0 for the current mouse focus
|
||||
* \param x The x coordinate within the window
|
||||
* \param y The y coordinate within the window
|
||||
*
|
||||
* \note This function generates a mouse motion event
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_WindowID windowID,
|
||||
int x, int y);
|
||||
|
||||
/**
|
||||
* \fn SDL_Cursor *SDL_CreateCursor (const Uint8 * data, const Uint8 * mask, int w, int h, int hot_x, int hot_y)
|
||||
*
|
||||
* \brief Create a cursor for the currently selected mouse, using the
|
||||
* specified bitmap data and mask (in MSB format).
|
||||
*
|
||||
* The cursor width must be a multiple of 8 bits.
|
||||
*
|
||||
* The cursor is created in black and white according to the following:
|
||||
* data mask resulting pixel on screen
|
||||
* 0 1 White
|
||||
* 1 1 Black
|
||||
* 0 0 Transparent
|
||||
* 1 0 Inverted color if possible, black if not.
|
||||
*
|
||||
* \sa SDL_FreeCursor()
|
||||
*/
|
||||
extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
|
||||
const Uint8 * mask,
|
||||
int w, int h, int hot_x,
|
||||
int hot_y);
|
||||
|
||||
/**
|
||||
* \fn void SDL_SetCursor(SDL_Cursor * cursor)
|
||||
*
|
||||
* \brief Set the active cursor for the currently selected mouse.
|
||||
*
|
||||
* \note The cursor must have been created for the selected mouse.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
|
||||
|
||||
/**
|
||||
* \fn SDL_Cursor *SDL_GetCursor(void)
|
||||
*
|
||||
* \brief Return the active cursor for the currently selected mouse.
|
||||
*/
|
||||
extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
|
||||
|
||||
/**
|
||||
* \fn void SDL_FreeCursor(SDL_Cursor * cursor)
|
||||
*
|
||||
* \brief Frees a cursor created with SDL_CreateCursor().
|
||||
*
|
||||
* \sa SDL_CreateCursor()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
|
||||
|
||||
/**
|
||||
* \fn int SDL_ShowCursor(int toggle)
|
||||
*
|
||||
* \brief Toggle whether or not the cursor is shown for the currently selected mouse.
|
||||
*
|
||||
* \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current state.
|
||||
*
|
||||
* \return 1 if the cursor is shown, or 0 if the cursor is hidden.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
|
||||
|
||||
/* Used as a mask when testing buttons in buttonstate
|
||||
Button 1: Left mouse button
|
||||
Button 2: Middle mouse button
|
||||
Button 3: Right mouse button
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetCursorsNumber(int index)
|
||||
*
|
||||
* \brief Gets the number of cursors a pointing device supports.
|
||||
* Useful for tablet users. Useful only under Windows.
|
||||
*
|
||||
* \param index is the index of the pointing device, which number of cursors we
|
||||
* want to receive.
|
||||
*
|
||||
* \return the number of cursors supported by the pointing device. On Windows
|
||||
* if a device is a tablet it returns a number >=1. Normal mice always return 1.
|
||||
* On Linux every device reports one cursor.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetCursorsNumber(int index);
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetCurrentCursor(int index)
|
||||
*
|
||||
* \brief Returns the index of the current cursor used by a specific pointing
|
||||
* device. Useful only under Windows.
|
||||
*
|
||||
* \param index is the index of the pointing device, which cursor index we want
|
||||
* to receive.
|
||||
*
|
||||
* \return the index of the cursor currently used by a specific pointing device.
|
||||
* Always 0 under Linux. On Windows if the device isn't a tablet it returns 0.
|
||||
* If the device is the tablet it returns the cursor index.
|
||||
* 0 - stylus, 1 - eraser, 2 - cursor.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetCurrentCursor(int index);
|
||||
|
||||
#define SDL_BUTTON(X) (1 << ((X)-1))
|
||||
#define SDL_BUTTON_LEFT 1
|
||||
#define SDL_BUTTON_MIDDLE 2
|
||||
#define SDL_BUTTON_RIGHT 3
|
||||
#define SDL_BUTTON_X1 4
|
||||
#define SDL_BUTTON_X2 5
|
||||
#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
|
||||
#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
|
||||
#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
|
||||
#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
|
||||
#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_mouse_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_mouse.h
|
||||
*
|
||||
* Include file for SDL mouse event handling.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_mouse_h
|
||||
#define _SDL_mouse_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_video.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
* \brief Get the number of mouse input devices available.
|
||||
*
|
||||
* \sa SDL_SelectMouse()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
|
||||
|
||||
/**
|
||||
* \brief Gets the name of a mouse with the given index.
|
||||
*
|
||||
* \param index is the index of the mouse, which name is to be returned.
|
||||
*
|
||||
* \return the name of the mouse with the specified index
|
||||
*/
|
||||
extern DECLSPEC char *SDLCALL SDL_GetMouseName(int index);
|
||||
|
||||
/**
|
||||
* \brief Set the index of the currently selected mouse.
|
||||
*
|
||||
* \return The index of the previously selected mouse.
|
||||
*
|
||||
* \note You can query the currently selected mouse by passing an index of -1.
|
||||
*
|
||||
* \sa SDL_GetNumMice()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
|
||||
|
||||
/**
|
||||
* \brief Get the window which currently has focus for the specified mouse.
|
||||
*/
|
||||
extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(int index);
|
||||
|
||||
/**
|
||||
* \brief Set relative mouse mode for the specified mouse.
|
||||
*
|
||||
* \param enabled Whether or not to enable relative mode
|
||||
*
|
||||
* \return 0 on success, or -1 if relative mode is not supported.
|
||||
*
|
||||
* While the mouse is in relative mode, the cursor is hidden, and the
|
||||
* driver will try to report continuous motion in the current window.
|
||||
* Only relative motion events will be delivered, the mouse position
|
||||
* will not change.
|
||||
*
|
||||
* \note This function will flush any pending mouse motion.
|
||||
*
|
||||
* \sa SDL_GetRelativeMouseMode()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(int index,
|
||||
SDL_bool enabled);
|
||||
|
||||
/**
|
||||
* \brief Query whether relative mouse mode is enabled for the specified mouse.
|
||||
*
|
||||
* \sa SDL_SetRelativeMouseMode()
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(int index);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the current state of the specified mouse.
|
||||
*
|
||||
* The current button state is returned as a button bitmask, which can
|
||||
* be tested using the SDL_BUTTON(X) macros, and x and y are set to the
|
||||
* mouse cursor position relative to the focus window for the currently
|
||||
* selected mouse. You can pass NULL for either x or y.
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int index, int *x, int *y);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the state of the specified mouse.
|
||||
*
|
||||
* The current button state is returned as a button bitmask, which can
|
||||
* be tested using the SDL_BUTTON(X) macros, and x and y are set to the
|
||||
* mouse deltas since the last call to SDL_GetRelativeMouseState().
|
||||
*/
|
||||
extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int index, int *x,
|
||||
int *y);
|
||||
|
||||
/**
|
||||
* \brief Moves the currently selected mouse to the given position within the window.
|
||||
*
|
||||
* \param windowID The window to move the mouse into, or 0 for the current mouse focus
|
||||
* \param x The x coordinate within the window
|
||||
* \param y The y coordinate within the window
|
||||
*
|
||||
* \note This function generates a mouse motion event
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_WindowID windowID,
|
||||
int x, int y);
|
||||
|
||||
/**
|
||||
* \brief Create a cursor for the currently selected mouse, using the
|
||||
* specified bitmap data and mask (in MSB format).
|
||||
*
|
||||
* The cursor width must be a multiple of 8 bits.
|
||||
*
|
||||
* The cursor is created in black and white according to the following:
|
||||
* <table>
|
||||
* <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
|
||||
* <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
|
||||
* <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
|
||||
* <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
|
||||
* <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
|
||||
if not. </td></tr>
|
||||
* </table>
|
||||
*
|
||||
* \sa SDL_FreeCursor()
|
||||
*/
|
||||
extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
|
||||
const Uint8 * mask,
|
||||
int w, int h, int hot_x,
|
||||
int hot_y);
|
||||
|
||||
/**
|
||||
* \brief Set the active cursor for the currently selected mouse.
|
||||
*
|
||||
* \note The cursor must have been created for the selected mouse.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
|
||||
|
||||
/**
|
||||
* \brief Return the active cursor for the currently selected mouse.
|
||||
*/
|
||||
extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
|
||||
|
||||
/**
|
||||
* \brief Frees a cursor created with SDL_CreateCursor().
|
||||
*
|
||||
* \sa SDL_CreateCursor()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
|
||||
|
||||
/**
|
||||
* \brief Toggle whether or not the cursor is shown for the currently selected
|
||||
* mouse.
|
||||
*
|
||||
* \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
|
||||
* state.
|
||||
*
|
||||
* \return 1 if the cursor is shown, or 0 if the cursor is hidden.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
|
||||
|
||||
/**
|
||||
* \brief Gets the number of cursors a pointing device supports.
|
||||
*
|
||||
* Useful for tablet users. Useful only under Windows.
|
||||
*
|
||||
* \param index is the index of the pointing device, which number of cursors we
|
||||
* want to receive.
|
||||
*
|
||||
* \return the number of cursors supported by the pointing device. On Windows
|
||||
* if a device is a tablet it returns a number >=1. Normal mice always
|
||||
* return 1.
|
||||
*
|
||||
* On Linux every device reports one cursor.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetCursorsNumber(int index);
|
||||
|
||||
/**
|
||||
* \brief Returns the index of the current cursor used by a specific pointing
|
||||
* device.
|
||||
*
|
||||
* Useful only under Windows.
|
||||
*
|
||||
* \param index is the index of the pointing device, which cursor index we want
|
||||
* to receive.
|
||||
*
|
||||
* \return the index of the cursor currently used by a specific pointing
|
||||
* device. Always 0 under Linux. On Windows if the device isn't a
|
||||
* tablet it returns 0. If the device is the tablet it returns the
|
||||
* cursor index. 0 - stylus, 1 - eraser, 2 - cursor.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetCurrentCursor(int index);
|
||||
|
||||
/**
|
||||
* Used as a mask when testing buttons in buttonstate.
|
||||
* - Button 1: Left mouse button
|
||||
* - Button 2: Middle mouse button
|
||||
* - Button 3: Right mouse button
|
||||
*/
|
||||
#define SDL_BUTTON(X) (1 << ((X)-1))
|
||||
#define SDL_BUTTON_LEFT 1
|
||||
#define SDL_BUTTON_MIDDLE 2
|
||||
#define SDL_BUTTON_RIGHT 3
|
||||
#define SDL_BUTTON_X1 4
|
||||
#define SDL_BUTTON_X2 5
|
||||
#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
|
||||
#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
|
||||
#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
|
||||
#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
|
||||
#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_mouse_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,170 +1,223 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_mutex_h
|
||||
#define _SDL_mutex_h
|
||||
|
||||
/**
|
||||
* \file SDL_mutex.h
|
||||
*
|
||||
* Functions to provide thread synchronization primitives
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Synchronization functions which can time out return this value
|
||||
if they time out.
|
||||
*/
|
||||
#define SDL_MUTEX_TIMEDOUT 1
|
||||
|
||||
/* This is the timeout value which corresponds to never time out */
|
||||
#define SDL_MUTEX_MAXWAIT (~(Uint32)0)
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* Mutex functions */
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* The SDL mutex structure, defined in SDL_mutex.c */
|
||||
struct SDL_mutex;
|
||||
typedef struct SDL_mutex SDL_mutex;
|
||||
|
||||
/* Create a mutex, initialized unlocked */
|
||||
extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
|
||||
|
||||
/* Lock the mutex (Returns 0, or -1 on error) */
|
||||
#define SDL_LockMutex(m) SDL_mutexP(m)
|
||||
extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex);
|
||||
|
||||
/* Unlock the mutex (Returns 0, or -1 on error)
|
||||
It is an error to unlock a mutex that has not been locked by
|
||||
the current thread, and doing so results in undefined behavior.
|
||||
*/
|
||||
#define SDL_UnlockMutex(m) SDL_mutexV(m)
|
||||
extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex);
|
||||
|
||||
/* Destroy a mutex */
|
||||
extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex * mutex);
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* Semaphore functions */
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* The SDL semaphore structure, defined in SDL_sem.c */
|
||||
struct SDL_semaphore;
|
||||
typedef struct SDL_semaphore SDL_sem;
|
||||
|
||||
/* Create a semaphore, initialized with value, returns NULL on failure. */
|
||||
extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
|
||||
|
||||
/* Destroy a semaphore */
|
||||
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
|
||||
|
||||
/* This function suspends the calling thread until the semaphore pointed
|
||||
* to by sem has a positive count. It then atomically decreases the semaphore
|
||||
* count.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
|
||||
|
||||
/* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds,
|
||||
SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
|
||||
|
||||
/* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
|
||||
the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
|
||||
the allotted time, and -1 on error.
|
||||
On some platforms this function is implemented by looping with a delay
|
||||
of 1 ms, and so should be avoided if possible.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
|
||||
|
||||
/* Atomically increases the semaphore's count (not blocking), returns 0,
|
||||
or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* Condition variable functions */
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* The SDL condition variable structure, defined in SDL_cond.c */
|
||||
struct SDL_cond;
|
||||
typedef struct SDL_cond SDL_cond;
|
||||
|
||||
/* Create a condition variable */
|
||||
extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
|
||||
|
||||
/* Destroy a condition variable */
|
||||
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable,
|
||||
returns 0 or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable,
|
||||
returns 0 or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
|
||||
|
||||
/* Wait on the condition variable, unlocking the provided mutex.
|
||||
The mutex must be locked before entering this function!
|
||||
The mutex is re-locked once the condition variable is signaled.
|
||||
Returns 0 when it is signaled, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mut);
|
||||
|
||||
/* Waits for at most 'ms' milliseconds, and returns 0 if the condition
|
||||
variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
|
||||
signaled in the allotted time, and -1 on error.
|
||||
On some platforms this function is implemented by looping with a delay
|
||||
of 1 ms, and so should be avoided if possible.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
|
||||
SDL_mutex * mutex, Uint32 ms);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_mutex_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_mutex_h
|
||||
#define _SDL_mutex_h
|
||||
|
||||
/**
|
||||
* \file SDL_mutex.h
|
||||
*
|
||||
* Functions to provide thread synchronization primitives.
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Synchronization functions which can time out return this value
|
||||
* if they time out.
|
||||
*/
|
||||
#define SDL_MUTEX_TIMEDOUT 1
|
||||
|
||||
/**
|
||||
* This is the timeout value which corresponds to never time out.
|
||||
*/
|
||||
#define SDL_MUTEX_MAXWAIT (~(Uint32)0)
|
||||
|
||||
|
||||
/**
|
||||
* \name Mutex functions
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/* The SDL mutex structure, defined in SDL_mutex.c */
|
||||
struct SDL_mutex;
|
||||
typedef struct SDL_mutex SDL_mutex;
|
||||
|
||||
/**
|
||||
* Create a mutex, initialized unlocked.
|
||||
*/
|
||||
extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
|
||||
|
||||
/**
|
||||
* Lock the mutex.
|
||||
*
|
||||
* \return 0, or -1 on error.
|
||||
*/
|
||||
#define SDL_LockMutex(m) SDL_mutexP(m)
|
||||
extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex);
|
||||
|
||||
/**
|
||||
* Unlock the mutex.
|
||||
*
|
||||
* \return 0, or -1 on error.
|
||||
*
|
||||
* \warning It is an error to unlock a mutex that has not been locked by
|
||||
* the current thread, and doing so results in undefined behavior.
|
||||
*/
|
||||
#define SDL_UnlockMutex(m) SDL_mutexV(m)
|
||||
extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex);
|
||||
|
||||
/**
|
||||
* Destroy a mutex.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex * mutex);
|
||||
|
||||
/*@}*//*Mutex functions*/
|
||||
|
||||
|
||||
/**
|
||||
* \name Semaphore functions
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/* The SDL semaphore structure, defined in SDL_sem.c */
|
||||
struct SDL_semaphore;
|
||||
typedef struct SDL_semaphore SDL_sem;
|
||||
|
||||
/**
|
||||
* Create a semaphore, initialized with value, returns NULL on failure.
|
||||
*/
|
||||
extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
|
||||
|
||||
/**
|
||||
* Destroy a semaphore.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
|
||||
|
||||
/**
|
||||
* This function suspends the calling thread until the semaphore pointed
|
||||
* to by \c sem has a positive count. It then atomically decreases the
|
||||
* semaphore count.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
|
||||
|
||||
/**
|
||||
* Non-blocking variant of SDL_SemWait().
|
||||
*
|
||||
* \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait would
|
||||
* block, and -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
|
||||
|
||||
/**
|
||||
* Variant of SDL_SemWait() with a timeout in milliseconds.
|
||||
*
|
||||
* \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not
|
||||
* succeed in the allotted time, and -1 on error.
|
||||
*
|
||||
* \warning On some platforms this function is implemented by looping with a
|
||||
* delay of 1 ms, and so should be avoided if possible.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
|
||||
|
||||
/**
|
||||
* Atomically increases the semaphore's count (not blocking).
|
||||
*
|
||||
* \return 0, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
|
||||
|
||||
/**
|
||||
* Returns the current count of the semaphore.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
|
||||
|
||||
/*@}*//*Semaphore functions*/
|
||||
|
||||
|
||||
/**
|
||||
* \name Condition variable functions
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/* The SDL condition variable structure, defined in SDL_cond.c */
|
||||
struct SDL_cond;
|
||||
typedef struct SDL_cond SDL_cond;
|
||||
|
||||
/**
|
||||
* Create a condition variable.
|
||||
*/
|
||||
extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
|
||||
|
||||
/**
|
||||
* Destroy a condition variable.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
|
||||
|
||||
/**
|
||||
* Restart one of the threads that are waiting on the condition variable.
|
||||
*
|
||||
* \return 0 or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
|
||||
|
||||
/**
|
||||
* Restart all threads that are waiting on the condition variable.
|
||||
* \return 0 or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
|
||||
|
||||
/**
|
||||
* Wait on the condition variable, unlocking the provided mutex.
|
||||
*
|
||||
* \warning The mutex must be locked before entering this function!
|
||||
*
|
||||
* The mutex is re-locked once the condition variable is signaled.
|
||||
*
|
||||
* \return 0 when it is signaled, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mut);
|
||||
|
||||
/**
|
||||
* Waits for at most \c ms milliseconds, and returns 0 if the condition
|
||||
* variable is signaled, ::SDL_MUTEX_TIMEDOUT if the condition is not
|
||||
* signaled in the allotted time, and -1 on error.
|
||||
*
|
||||
* \warning On some platforms this function is implemented by looping with a
|
||||
* delay of 1 ms, and so should be avoided if possible.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
|
||||
SDL_mutex * mutex, Uint32 ms);
|
||||
|
||||
/*@}*//*Condition variable functions*/
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_mutex_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
#ifndef _SDLname_h_
|
||||
#define _SDLname_h_
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define NeedFunctionPrototypes 1
|
||||
#endif
|
||||
|
||||
#define SDL_NAME(X) SDL_##X
|
||||
|
||||
#endif /* _SDLname_h_ */
|
||||
|
||||
#ifndef _SDLname_h_
|
||||
#define _SDLname_h_
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define NeedFunctionPrototypes 1
|
||||
#endif
|
||||
|
||||
#define SDL_NAME(X) SDL_##X
|
||||
|
||||
#endif /* _SDLname_h_ */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,10 +20,13 @@
|
|||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/*
|
||||
This is a simple file to encapsulate the OpenGL ES API headers.
|
||||
Headers copied from The Kronos Group website.
|
||||
http://www.khronos.org/opengles/
|
||||
/**
|
||||
* \file SDL_opengles.h
|
||||
*
|
||||
* This is a simple file to encapsulate the OpenGL ES API headers.
|
||||
*
|
||||
* Headers copied from The Kronos Group website.
|
||||
* http://www.khronos.org/opengles/
|
||||
*/
|
||||
|
||||
#ifndef __gles_h_
|
||||
|
@ -48,6 +51,9 @@ extern "C"
|
|||
#define GL_APIENTRY
|
||||
#endif
|
||||
|
||||
#ifndef GL_API
|
||||
#define GL_API
|
||||
#endif /* GL_API */
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
|
@ -341,6 +347,14 @@ extern "C"
|
|||
#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
|
||||
#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
|
||||
|
||||
/* OpenGL ES 1.0 defines, they gone in 1.1 and 2.0 */
|
||||
#ifndef GL_MAX_ELEMENTS_VERTICES
|
||||
#define GL_MAX_ELEMENTS_VERTICES 0x80E8
|
||||
#endif /* GL_MAX_ELEMENTS_VERTICES */
|
||||
#ifndef GL_MAX_ELEMENTS_INDICES
|
||||
#define GL_MAX_ELEMENTS_INDICES 0x80E9
|
||||
#endif /* GL_MAX_ELEMENTS_INDICES */
|
||||
|
||||
/* GetTextureParameter */
|
||||
/* GL_TEXTURE_MAG_FILTER */
|
||||
/* GL_TEXTURE_MIN_FILTER */
|
||||
|
@ -655,6 +669,29 @@ extern "C"
|
|||
#define GL_COORD_REPLACE_OES 0x8862
|
||||
#endif
|
||||
|
||||
/* GL_OES_draw_texture */
|
||||
#ifndef GL_OES_draw_texture
|
||||
#define GL_TEXTURE_CROP_RECT_OES 0x8B9D
|
||||
#endif /* GL_OES_draw_texture */
|
||||
|
||||
/* GL_OES_vertex_buffer_object */
|
||||
#ifndef GL_OES_vertex_buffer_object
|
||||
#define GL_ARRAY_BUFFER_OES 0x8892
|
||||
#define GL_ELEMENT_ARRAY_BUFFER_OES 0x8893
|
||||
#define GL_ARRAY_BUFFER_BINDING_OES 0x8894
|
||||
#define GL_ELEMENT_ARRAY_BUFFER_BINDING_OES 0x8895
|
||||
#define GL_VERTEX_ARRAY_BUFFER_BINDING_OES 0x8896
|
||||
#define GL_NORMAL_ARRAY_BUFFER_BINDING_OES 0x8897
|
||||
#define GL_COLOR_ARRAY_BUFFER_BINDING_OES 0x8898
|
||||
#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_OES 0x889A
|
||||
#define GL_STATIC_DRAW_OES 0x88E4
|
||||
#define GL_DYNAMIC_DRAW_OES 0x88E8
|
||||
#define GL_WRITE_ONLY_OES 0x88B9
|
||||
#define GL_BUFFER_SIZE_OES 0x8764
|
||||
#define GL_BUFFER_USAGE_OES 0x8765
|
||||
#define GL_BUFFER_ACCESS_OES 0x88BB
|
||||
#endif /* GL_OES_vertex_buffer_object */
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
/* Available only in Common profile */
|
||||
|
@ -936,11 +973,65 @@ extern "C"
|
|||
const GLvoid * pointer);
|
||||
#endif
|
||||
|
||||
/* GL_OES_query_matrix */
|
||||
#ifndef GL_OES_query_matrix
|
||||
#define GL_OES_query_matrix 1
|
||||
GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16],
|
||||
GLint exponent[16]);
|
||||
#endif /* GL_OES_query_matrix */
|
||||
|
||||
/* GL_OES_point_sprite */
|
||||
#ifndef GL_OES_point_sprite
|
||||
#define GL_OES_point_sprite 1
|
||||
#endif
|
||||
|
||||
/* GL_OES_draw_texture */
|
||||
#ifndef GL_OES_draw_texture
|
||||
#define GL_OES_draw_texture 1
|
||||
GL_API void GL_APIENTRY glDrawTexsOES(GLshort x, GLshort y, GLshort z,
|
||||
GLshort width, GLshort height);
|
||||
GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z,
|
||||
GLint width, GLint height);
|
||||
GL_API void GL_APIENTRY glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z,
|
||||
GLfixed width, GLfixed height);
|
||||
GL_API void GL_APIENTRY glDrawTexsvOES(const GLshort * coords);
|
||||
GL_API void GL_APIENTRY glDrawTexivOES(const GLint * coords);
|
||||
GL_API void GL_APIENTRY glDrawTexxvOES(const GLfixed * coords);
|
||||
GL_API void GL_APIENTRY glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z,
|
||||
GLfloat width, GLfloat height);
|
||||
GL_API void GL_APIENTRY glDrawTexfvOES(const GLfloat * coords);
|
||||
#endif /* GL_OES_draw_texture */
|
||||
|
||||
/* GL_OES_single_precision */
|
||||
#ifndef GL_OES_single_precision
|
||||
#define GL_OES_single_precision 1
|
||||
GL_API void GL_APIENTRY glDepthRangefOES(GLclampf zNear, GLclampf zFar);
|
||||
GL_API void GL_APIENTRY glFrustumfOES(GLfloat left, GLfloat right,
|
||||
GLfloat bottom, GLfloat top,
|
||||
GLfloat zNear, GLfloat zFar);
|
||||
GL_API void GL_APIENTRY glOrthofOES(GLfloat left, GLfloat right,
|
||||
GLfloat bottom, GLfloat top,
|
||||
GLfloat zNear, GLfloat zFar);
|
||||
GL_API void GL_APIENTRY glClipPlanefOES(GLenum plane,
|
||||
const GLfloat * equation);
|
||||
GL_API void GL_APIENTRY glGetClipPlanefOES(GLenum pname, GLfloat eqn[4]);
|
||||
GL_API void GL_APIENTRY glClearDepthfOES(GLclampf depth);
|
||||
#endif /* GL_OES_single_precision */
|
||||
|
||||
/* GL_OES_vertex_buffer_object */
|
||||
#ifndef GL_OES_vertex_buffer_object
|
||||
#define GL_OES_vertex_buffer_object 1
|
||||
GL_API void APIENTRY glBindBufferOES(GLenum, GLuint);
|
||||
GL_API void APIENTRY glDeleteBuffersOES(GLsizei, const GLuint *);
|
||||
GL_API void APIENTRY glGenBuffersOES(GLsizei, GLuint *);
|
||||
GL_API GLboolean APIENTRY glIsBufferOES(GLuint);
|
||||
GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *,
|
||||
GLenum);
|
||||
GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr,
|
||||
const GLvoid *);
|
||||
GL_API void APIENTRY glGetBufferParameterivOES(GLenum, GLenum, GLint *);
|
||||
#endif /* GL_OES_vertex_buffer_object */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_pixels.h
|
||||
*
|
||||
* Header for the enumerated pixel format definitions
|
||||
* \file SDL_pixels.h
|
||||
*
|
||||
* Header for the enumerated pixel format definitions.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_pixels_h
|
||||
|
@ -37,12 +37,19 @@ extern "C" {
|
|||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Transparency definitions: These define alpha as the opacity of a surface */
|
||||
/**
|
||||
* \name Transparency definitions
|
||||
*
|
||||
* These define alpha as the opacity of a surface.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_ALPHA_OPAQUE 255
|
||||
#define SDL_ALPHA_TRANSPARENT 0
|
||||
/*@}*/
|
||||
|
||||
/** Pixel type. */
|
||||
enum
|
||||
{ /* Pixel type */
|
||||
{
|
||||
SDL_PIXELTYPE_UNKNOWN,
|
||||
SDL_PIXELTYPE_INDEX1,
|
||||
SDL_PIXELTYPE_INDEX4,
|
||||
|
@ -57,14 +64,17 @@ enum
|
|||
SDL_PIXELTYPE_ARRAYF32
|
||||
};
|
||||
|
||||
/** Bitmap pixel order, high bit -> low bit. */
|
||||
enum
|
||||
{ /* bitmap pixel order, high bit -> low bit */
|
||||
{
|
||||
SDL_BITMAPORDER_NONE,
|
||||
SDL_BITMAPORDER_4321,
|
||||
SDL_BITMAPORDER_1234
|
||||
};
|
||||
|
||||
/** Packed component order, high bit -> low bit. */
|
||||
enum
|
||||
{ /* packed component order, high bit -> low bit */
|
||||
{
|
||||
SDL_PACKEDORDER_NONE,
|
||||
SDL_PACKEDORDER_XRGB,
|
||||
SDL_PACKEDORDER_RGBX,
|
||||
|
@ -75,8 +85,10 @@ enum
|
|||
SDL_PACKEDORDER_ABGR,
|
||||
SDL_PACKEDORDER_BGRA
|
||||
};
|
||||
|
||||
/** Array component order, low byte -> high byte. */
|
||||
enum
|
||||
{ /* array component order, low byte -> high byte */
|
||||
{
|
||||
SDL_ARRAYORDER_NONE,
|
||||
SDL_ARRAYORDER_RGB,
|
||||
SDL_ARRAYORDER_RGBA,
|
||||
|
@ -86,8 +98,9 @@ enum
|
|||
SDL_ARRAYORDER_ABGR
|
||||
};
|
||||
|
||||
/** Packed component layout. */
|
||||
enum
|
||||
{ /* Packed component layout */
|
||||
{
|
||||
SDL_PACKEDLAYOUT_NONE,
|
||||
SDL_PACKEDLAYOUT_332,
|
||||
SDL_PACKEDLAYOUT_4444,
|
||||
|
@ -117,6 +130,12 @@ enum
|
|||
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
|
||||
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8))
|
||||
|
||||
#define SDL_ISPIXELFORMAT_ALPHA(format) \
|
||||
((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
|
||||
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
|
||||
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
|
||||
(SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))
|
||||
|
||||
#define SDL_ISPIXELFORMAT_FOURCC(format) \
|
||||
((format) && !((format) & 0x80000000))
|
||||
|
||||
|
@ -131,10 +150,10 @@ enum
|
|||
1, 0),
|
||||
SDL_PIXELFORMAT_INDEX4LSB =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
|
||||
2, 0),
|
||||
4, 0),
|
||||
SDL_PIXELFORMAT_INDEX4MSB =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
|
||||
2, 0),
|
||||
4, 0),
|
||||
SDL_PIXELFORMAT_INDEX8 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
|
||||
SDL_PIXELFORMAT_RGB332 =
|
||||
|
@ -152,6 +171,9 @@ enum
|
|||
SDL_PIXELFORMAT_ARGB4444 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
|
||||
SDL_PACKEDLAYOUT_4444, 16, 2),
|
||||
SDL_PIXELFORMAT_ABGR4444 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
|
||||
SDL_PACKEDLAYOUT_4444, 16, 2),
|
||||
SDL_PIXELFORMAT_ARGB1555 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
|
||||
SDL_PACKEDLAYOUT_1555, 16, 2),
|
||||
|
@ -161,6 +183,9 @@ enum
|
|||
SDL_PIXELFORMAT_RGB565 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
|
||||
SDL_PACKEDLAYOUT_565, 16, 2),
|
||||
SDL_PIXELFORMAT_BGR565 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
|
||||
SDL_PACKEDLAYOUT_565, 16, 2),
|
||||
SDL_PIXELFORMAT_RGB24 =
|
||||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
|
||||
24, 3),
|
||||
|
@ -189,15 +214,15 @@ enum
|
|||
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
|
||||
SDL_PACKEDLAYOUT_2101010, 32, 4),
|
||||
|
||||
SDL_PIXELFORMAT_YV12 = /* Planar mode: Y + V + U (3 planes) */
|
||||
SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
|
||||
SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
|
||||
SDL_PIXELFORMAT_IYUV = /* Planar mode: Y + U + V (3 planes) */
|
||||
SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
|
||||
SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
|
||||
SDL_PIXELFORMAT_YUY2 = /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
|
||||
SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
|
||||
SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
|
||||
SDL_PIXELFORMAT_UYVY = /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
|
||||
SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
|
||||
SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
|
||||
SDL_PIXELFORMAT_YVYU = /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
|
||||
SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
|
||||
SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U')
|
||||
};
|
||||
|
||||
|
@ -229,7 +254,9 @@ struct SDL_Palette
|
|||
SDL_PaletteWatch *watch;
|
||||
};
|
||||
|
||||
/* Everything in the pixel format structure is read-only */
|
||||
/**
|
||||
* \note Everything in the pixel format structure is read-only.
|
||||
*/
|
||||
typedef struct SDL_PixelFormat
|
||||
{
|
||||
SDL_Palette *palette;
|
||||
|
@ -250,13 +277,11 @@ typedef struct SDL_PixelFormat
|
|||
} SDL_PixelFormat;
|
||||
|
||||
/**
|
||||
* \fn SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
|
||||
*
|
||||
* \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
|
||||
*
|
||||
* \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
|
||||
*
|
||||
* \sa SDL_MasksToPixelFormatEnum()
|
||||
* \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
|
||||
*
|
||||
* \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
|
||||
*
|
||||
* \sa SDL_MasksToPixelFormatEnum()
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
|
||||
int *bpp,
|
||||
|
@ -266,13 +291,12 @@ extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
|
|||
Uint32 * Amask);
|
||||
|
||||
/**
|
||||
* \fn Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
|
||||
*
|
||||
* \brief Convert a bpp and RGBA masks to an enumerated pixel format.
|
||||
*
|
||||
* \return The pixel format, or SDL_PixelFormat_Unknown if the conversion wasn't possible.
|
||||
*
|
||||
* \sa SDL_PixelFormatEnumToMasks()
|
||||
* \brief Convert a bpp and RGBA masks to an enumerated pixel format.
|
||||
*
|
||||
* \return The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion
|
||||
* wasn't possible.
|
||||
*
|
||||
* \sa SDL_PixelFormatEnumToMasks()
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
|
||||
Uint32 Rmask,
|
||||
|
@ -281,107 +305,87 @@ extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
|
|||
Uint32 Amask);
|
||||
|
||||
/**
|
||||
* \fn SDL_Palette *SDL_AllocPalette(int ncolors)
|
||||
*
|
||||
* \brief Create a palette structure with the specified number of color entries.
|
||||
*
|
||||
* \return A new palette, or NULL if there wasn't enough memory
|
||||
*
|
||||
* \note The palette entries are initialized to white.
|
||||
*
|
||||
* \sa SDL_FreePalette()
|
||||
* \brief Create a palette structure with the specified number of color
|
||||
* entries.
|
||||
*
|
||||
* \return A new palette, or NULL if there wasn't enough memory.
|
||||
*
|
||||
* \note The palette entries are initialized to white.
|
||||
*
|
||||
* \sa SDL_FreePalette()
|
||||
*/
|
||||
extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
|
||||
|
||||
/**
|
||||
* \fn int SDL_AddPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
|
||||
*
|
||||
* \brief Add a callback function which is called when the palette changes.
|
||||
*
|
||||
* \sa SDL_DelPaletteWatch()
|
||||
* \brief Add a callback function which is called when the palette changes.
|
||||
*
|
||||
* \sa SDL_DelPaletteWatch()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
|
||||
SDL_PaletteChangedFunc
|
||||
callback, void *userdata);
|
||||
|
||||
/**
|
||||
* \fn void SDL_DelPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
|
||||
*
|
||||
* \brief Remove a callback function previously added with SDL_AddPaletteWatch()
|
||||
*
|
||||
* \sa SDL_AddPaletteWatch()
|
||||
* \brief Remove a callback function previously added with
|
||||
* SDL_AddPaletteWatch().
|
||||
*
|
||||
* \sa SDL_AddPaletteWatch()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette,
|
||||
SDL_PaletteChangedFunc
|
||||
callback, void *userdata);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Colors *colors, int firstcolor, int numcolors)
|
||||
*
|
||||
* \brief Set a range of colors in a palette.
|
||||
*
|
||||
* \param palette The palette to modify
|
||||
* \param colors An array of colors to copy into the palette
|
||||
* \param firstcolor The index of the first palette entry to modify
|
||||
* \param ncolors The number of entries to modify
|
||||
*
|
||||
* \return 0 on success, or -1 if not all of the colors could be set
|
||||
* \brief Set a range of colors in a palette.
|
||||
*
|
||||
* \param palette The palette to modify.
|
||||
* \param colors An array of colors to copy into the palette.
|
||||
* \param firstcolor The index of the first palette entry to modify.
|
||||
* \param ncolors The number of entries to modify.
|
||||
*
|
||||
* \return 0 on success, or -1 if not all of the colors could be set.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
|
||||
const SDL_Color * colors,
|
||||
int firstcolor, int ncolors);
|
||||
|
||||
/**
|
||||
* \fn void SDL_FreePalette(SDL_Palette *palette)
|
||||
*
|
||||
* \brief Free a palette created with SDL_AllocPalette()
|
||||
*
|
||||
* \sa SDL_AllocPalette()
|
||||
* \brief Free a palette created with SDL_AllocPalette().
|
||||
*
|
||||
* \sa SDL_AllocPalette()
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
|
||||
|
||||
/**
|
||||
* \fn Uint32 SDL_MapRGB(const SDL_PixelFormat *format,
|
||||
* Uint8 r, Uint8 g, Uint8 b)
|
||||
*
|
||||
* \brief Maps an RGB triple to an opaque pixel value for a given pixel format
|
||||
*
|
||||
* \sa SDL_MapRGBA
|
||||
* \brief Maps an RGB triple to an opaque pixel value for a given pixel format.
|
||||
*
|
||||
* \sa SDL_MapRGBA
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
|
||||
Uint8 r, Uint8 g, Uint8 b);
|
||||
|
||||
/**
|
||||
* \fn Uint32 SDL_MapRGBA(const SDL_PixelFormat *fmt,
|
||||
* Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
*
|
||||
* \brief Maps an RGBA quadruple to a pixel value for a given pixel format
|
||||
*
|
||||
* \sa SDL_MapRGB
|
||||
* \brief Maps an RGBA quadruple to a pixel value for a given pixel format.
|
||||
*
|
||||
* \sa SDL_MapRGB
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
|
||||
Uint8 r, Uint8 g, Uint8 b,
|
||||
Uint8 a);
|
||||
|
||||
/**
|
||||
* \fn void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format,
|
||||
* Uint8 * r, Uint8 * g, Uint8 * b)
|
||||
*
|
||||
* \brief Maps a pixel value into the RGB components for a given pixel format
|
||||
*
|
||||
* \sa SDL_GetRGBA
|
||||
* \brief Maps a pixel value into the RGB components for a given pixel format.
|
||||
*
|
||||
* \sa SDL_GetRGBA
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
|
||||
const SDL_PixelFormat * format,
|
||||
Uint8 * r, Uint8 * g, Uint8 * b);
|
||||
|
||||
/**
|
||||
* \fn void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
|
||||
* Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
|
||||
*
|
||||
* \brief Maps a pixel value into the RGBA components for a given pixel format
|
||||
*
|
||||
* \sa SDL_GetRGB
|
||||
* \brief Maps a pixel value into the RGBA components for a given pixel format.
|
||||
*
|
||||
* \sa SDL_GetRGB
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
|
||||
const SDL_PixelFormat * format,
|
||||
|
|
|
@ -1,122 +1,154 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/* Try to get a standard set of platform defines */
|
||||
|
||||
#ifndef _SDL_platform_h
|
||||
#define _SDL_platform_h
|
||||
|
||||
#if defined(_AIX)
|
||||
#undef __AIX__
|
||||
#define __AIX__ 1
|
||||
#endif
|
||||
#if defined(__BEOS__)
|
||||
#undef __BEOS__
|
||||
#define __BEOS__ 1
|
||||
#endif
|
||||
#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
|
||||
#undef __BSDI__
|
||||
#define __BSDI__ 1
|
||||
#endif
|
||||
#if defined(_arch_dreamcast)
|
||||
#undef __DREAMCAST__
|
||||
#define __DREAMCAST__ 1
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
#undef __FREEBSD__
|
||||
#define __FREEBSD__ 1
|
||||
#endif
|
||||
#if defined(hpux) || defined(__hpux) || defined(__hpux__)
|
||||
#undef __HPUX__
|
||||
#define __HPUX__ 1
|
||||
#endif
|
||||
#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
|
||||
#undef __IRIX__
|
||||
#define __IRIX__ 1
|
||||
#endif
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__)
|
||||
#undef __LINUX__
|
||||
#define __LINUX__ 1
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/* lets us know what version of Mac OS X we're compiling on */
|
||||
#include "AvailabilityMacros.h"
|
||||
#ifdef MAC_OS_X_VERSION_10_3
|
||||
#include "TargetConditionals.h" /* this header is in 10.3 or later */
|
||||
#if TARGET_OS_IPHONE
|
||||
/* if compiling for iPhone */
|
||||
#undef __IPHONEOS__
|
||||
#define __IPHONEOS__ 1
|
||||
#undef __MACOSX__
|
||||
#else
|
||||
/* if not compiling for iPhone */
|
||||
#undef __MACOSX__
|
||||
#define __MACOSX__ 1
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
#else
|
||||
/* if earlier verion of Mac OS X than version 10.3 */
|
||||
#undef __MACOSX__
|
||||
#define __MACOSX__ 1
|
||||
#endif
|
||||
|
||||
#endif /* defined(__APPLE__) */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#undef __NETBSD__
|
||||
#define __NETBSD__ 1
|
||||
#endif
|
||||
#if defined(__OpenBSD__)
|
||||
#undef __OPENBSD__
|
||||
#define __OPENBSD__ 1
|
||||
#endif
|
||||
#if defined(__OS2__)
|
||||
#undef __OS2__
|
||||
#define __OS2__ 1
|
||||
#endif
|
||||
#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
|
||||
#undef __OSF__
|
||||
#define __OSF__ 1
|
||||
#endif
|
||||
#if defined(__QNXNTO__)
|
||||
#undef __QNXNTO__
|
||||
#define __QNXNTO__ 1
|
||||
#endif
|
||||
#if defined(riscos) || defined(__riscos) || defined(__riscos__)
|
||||
#undef __RISCOS__
|
||||
#define __RISCOS__ 1
|
||||
#endif
|
||||
#if defined(__SVR4)
|
||||
#undef __SOLARIS__
|
||||
#define __SOLARIS__ 1
|
||||
#endif
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
#undef __WIN32__
|
||||
#define __WIN32__ 1
|
||||
#endif
|
||||
|
||||
#if defined(__NDS__)
|
||||
#undef __NINTENDODS__
|
||||
#define __NINTENDODS__ 1
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_platform_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_platform.h
|
||||
*
|
||||
* Try to get a standard set of platform defines.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_platform_h
|
||||
#define _SDL_platform_h
|
||||
|
||||
#if defined(_AIX)
|
||||
#undef __AIX__
|
||||
#define __AIX__ 1
|
||||
#endif
|
||||
#if defined(__BEOS__)
|
||||
#undef __BEOS__
|
||||
#define __BEOS__ 1
|
||||
#endif
|
||||
#if defined(__HAIKU__)
|
||||
#undef __HAIKU__
|
||||
#define __HAIKU__ 1
|
||||
#endif
|
||||
#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
|
||||
#undef __BSDI__
|
||||
#define __BSDI__ 1
|
||||
#endif
|
||||
#if defined(_arch_dreamcast)
|
||||
#undef __DREAMCAST__
|
||||
#define __DREAMCAST__ 1
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
#undef __FREEBSD__
|
||||
#define __FREEBSD__ 1
|
||||
#endif
|
||||
#if defined(hpux) || defined(__hpux) || defined(__hpux__)
|
||||
#undef __HPUX__
|
||||
#define __HPUX__ 1
|
||||
#endif
|
||||
#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
|
||||
#undef __IRIX__
|
||||
#define __IRIX__ 1
|
||||
#endif
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__)
|
||||
#undef __LINUX__
|
||||
#define __LINUX__ 1
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/* lets us know what version of Mac OS X we're compiling on */
|
||||
#include "AvailabilityMacros.h"
|
||||
#ifdef MAC_OS_X_VERSION_10_3
|
||||
#include "TargetConditionals.h" /* this header is in 10.3 or later */
|
||||
#if TARGET_OS_IPHONE
|
||||
/* if compiling for iPhone */
|
||||
#undef __IPHONEOS__
|
||||
#define __IPHONEOS__ 1
|
||||
#undef __MACOSX__
|
||||
#else
|
||||
/* if not compiling for iPhone */
|
||||
#undef __MACOSX__
|
||||
#define __MACOSX__ 1
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
#else
|
||||
/* if earlier verion of Mac OS X than version 10.3 */
|
||||
#undef __MACOSX__
|
||||
#define __MACOSX__ 1
|
||||
#endif
|
||||
|
||||
#endif /* defined(__APPLE__) */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#undef __NETBSD__
|
||||
#define __NETBSD__ 1
|
||||
#endif
|
||||
#if defined(__OpenBSD__)
|
||||
#undef __OPENBSD__
|
||||
#define __OPENBSD__ 1
|
||||
#endif
|
||||
#if defined(__OS2__)
|
||||
#undef __OS2__
|
||||
#define __OS2__ 1
|
||||
#endif
|
||||
#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
|
||||
#undef __OSF__
|
||||
#define __OSF__ 1
|
||||
#endif
|
||||
#if defined(__QNXNTO__)
|
||||
#undef __QNXNTO__
|
||||
#define __QNXNTO__ 1
|
||||
#endif
|
||||
#if defined(riscos) || defined(__riscos) || defined(__riscos__)
|
||||
#undef __RISCOS__
|
||||
#define __RISCOS__ 1
|
||||
#endif
|
||||
#if defined(__SVR4)
|
||||
#undef __SOLARIS__
|
||||
#define __SOLARIS__ 1
|
||||
#endif
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
#undef __WIN32__
|
||||
#define __WIN32__ 1
|
||||
#endif
|
||||
|
||||
#if defined(__NDS__)
|
||||
#undef __NINTENDODS__
|
||||
#define __NINTENDODS__ 1
|
||||
#endif
|
||||
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Gets the name of the platform.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_platform_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,54 +1,59 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_quit.h
|
||||
*
|
||||
* Include file for SDL quit event handling
|
||||
*/
|
||||
|
||||
#ifndef _SDL_quit_h
|
||||
#define _SDL_quit_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
/*
|
||||
An SDL_QUITEVENT is generated when the user tries to close the application
|
||||
window. If it is ignored or filtered out, the window will remain open.
|
||||
If it is not ignored or filtered, it is queued normally and the window
|
||||
is allowed to close. When the window is closed, screen updates will
|
||||
complete, but have no effect.
|
||||
|
||||
SDL_Init() installs signal handlers for SIGINT (keyboard interrupt)
|
||||
and SIGTERM (system termination request), if handlers do not already
|
||||
exist, that generate SDL_QUITEVENT events as well. There is no way
|
||||
to determine the cause of an SDL_QUITEVENT, but setting a signal
|
||||
handler in your application will override the default generation of
|
||||
quit events for that signal.
|
||||
*/
|
||||
|
||||
/* There are no functions directly affecting the quit event */
|
||||
#define SDL_QuitRequested() \
|
||||
(SDL_PumpEvents(), SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUITMASK))
|
||||
|
||||
#endif /* _SDL_quit_h */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_quit.h
|
||||
*
|
||||
* Include file for SDL quit event handling.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_quit_h
|
||||
#define _SDL_quit_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
/**
|
||||
* \file SDL_quit.h
|
||||
*
|
||||
* An ::SDL_QUIT event is generated when the user tries to close the application
|
||||
* window. If it is ignored or filtered out, the window will remain open.
|
||||
* If it is not ignored or filtered, it is queued normally and the window
|
||||
* is allowed to close. When the window is closed, screen updates will
|
||||
* complete, but have no effect.
|
||||
*
|
||||
* SDL_Init() installs signal handlers for SIGINT (keyboard interrupt)
|
||||
* and SIGTERM (system termination request), if handlers do not already
|
||||
* exist, that generate ::SDL_QUIT events as well. There is no way
|
||||
* to determine the cause of an ::SDL_QUIT event, but setting a signal
|
||||
* handler in your application will override the default generation of
|
||||
* quit events for that signal.
|
||||
*
|
||||
* \sa SDL_Quit()
|
||||
*/
|
||||
|
||||
/* There are no functions directly affecting the quit event */
|
||||
|
||||
#define SDL_QuitRequested() \
|
||||
(SDL_PumpEvents(), SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUITMASK))
|
||||
|
||||
#endif /* _SDL_quit_h */
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_rect.h
|
||||
*
|
||||
* Header file for SDL_rect definition and management functions
|
||||
* \file SDL_rect.h
|
||||
*
|
||||
* Header file for SDL_rect definition and management functions.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_rect_h
|
||||
|
@ -43,15 +43,13 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/**
|
||||
* \struct SDL_Rect
|
||||
*
|
||||
* \brief A rectangle, with the origin at the upper left.
|
||||
*
|
||||
* \sa SDL_RectEmpty
|
||||
* \sa SDL_RectEquals
|
||||
* \sa SDL_HasIntersection
|
||||
* \sa SDL_IntersectRect
|
||||
* \sa SDL_UnionRect
|
||||
* \brief A rectangle, with the origin at the upper left.
|
||||
*
|
||||
* \sa SDL_RectEmpty
|
||||
* \sa SDL_RectEquals
|
||||
* \sa SDL_HasIntersection
|
||||
* \sa SDL_IntersectRect
|
||||
* \sa SDL_UnionRect
|
||||
*/
|
||||
typedef struct SDL_Rect
|
||||
{
|
||||
|
@ -60,56 +58,44 @@ typedef struct SDL_Rect
|
|||
} SDL_Rect;
|
||||
|
||||
/**
|
||||
* \def SDL_RectEmpty()
|
||||
*
|
||||
* \brief Returns true if the rectangle has no area.
|
||||
* \brief Returns true if the rectangle has no area.
|
||||
*/
|
||||
#define SDL_RectEmpty(X) (((X)->w <= 0) || ((X)->h <= 0))
|
||||
|
||||
/**
|
||||
* \def SDL_RectEquals()
|
||||
*
|
||||
* \brief Returns true if the two rectangles are equal.
|
||||
* \brief Returns true if the two rectangles are equal.
|
||||
*/
|
||||
#define SDL_RectEquals(A, B) (((A)->x == (B)->x) && ((A)->y == (B)->y) && \
|
||||
((A)->w == (B)->w) && ((A)->h == (B)->h))
|
||||
|
||||
/**
|
||||
* \fn SDL_bool SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B);
|
||||
*
|
||||
* \brief Determine whether two rectangles intersect.
|
||||
*
|
||||
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
* \brief Determine whether two rectangles intersect.
|
||||
*
|
||||
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
|
||||
const SDL_Rect * B);
|
||||
|
||||
/**
|
||||
* \fn SDL_bool SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
|
||||
*
|
||||
* \brief Calculate the intersection of two rectangles.
|
||||
*
|
||||
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
* \brief Calculate the intersection of two rectangles.
|
||||
*
|
||||
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
|
||||
const SDL_Rect * B,
|
||||
SDL_Rect * result);
|
||||
|
||||
/**
|
||||
* \fn void SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
|
||||
*
|
||||
* \brief Calculate the union of two rectangles
|
||||
* \brief Calculate the union of two rectangles.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
|
||||
const SDL_Rect * B,
|
||||
SDL_Rect * result);
|
||||
|
||||
/**
|
||||
* \fn SDL_bool SDL_IntersectRectAndLine(const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2)
|
||||
*
|
||||
* \brief Calculate the intersection of a rectangle and line segment.
|
||||
*
|
||||
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
* \brief Calculate the intersection of a rectangle and line segment.
|
||||
*
|
||||
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
|
||||
rect, int *X1,
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define SDL_REVISION 4404
|
||||
#define SDL_REVISION 0
|
||||
|
|
|
@ -1,168 +1,203 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_rwops.h
|
||||
*
|
||||
* This file provides a general interface for SDL to read and write
|
||||
* data sources. It can easily be extended to files, memory, etc.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_rwops_h
|
||||
#define _SDL_rwops_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* This is the read/write operation structure -- very basic */
|
||||
|
||||
typedef struct SDL_RWops
|
||||
{
|
||||
/* Seek to 'offset' relative to whence, one of stdio's whence values:
|
||||
RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
|
||||
Returns the final offset in the data source.
|
||||
*/
|
||||
long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
|
||||
int whence);
|
||||
|
||||
/* Read up to 'num' objects each of size 'objsize' from the data
|
||||
source to the area pointed at by 'ptr'.
|
||||
Returns the number of objects read, or 0 at error or end of file.
|
||||
*/
|
||||
size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
|
||||
size_t size, size_t maxnum);
|
||||
|
||||
/* Write exactly 'num' objects each of size 'objsize' from the area
|
||||
pointed at by 'ptr' to data source.
|
||||
Returns the number of objects written, or 0 at error or end of file.
|
||||
*/
|
||||
size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
|
||||
size_t size, size_t num);
|
||||
|
||||
/* Close and free an allocated SDL_RWops structure.
|
||||
Returns 0 if successful or -1 on write error when flushing data.
|
||||
*/
|
||||
int (SDLCALL * close) (struct SDL_RWops * context);
|
||||
|
||||
Uint32 type;
|
||||
union
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
struct
|
||||
{
|
||||
SDL_bool append;
|
||||
void *h;
|
||||
struct
|
||||
{
|
||||
void *data;
|
||||
int size;
|
||||
int left;
|
||||
} buffer;
|
||||
} win32io;
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
struct
|
||||
{
|
||||
SDL_bool autoclose;
|
||||
FILE *fp;
|
||||
} stdio;
|
||||
#endif
|
||||
struct
|
||||
{
|
||||
Uint8 *base;
|
||||
Uint8 *here;
|
||||
Uint8 *stop;
|
||||
} mem;
|
||||
struct
|
||||
{
|
||||
void *data1;
|
||||
} unknown;
|
||||
} hidden;
|
||||
|
||||
} SDL_RWops;
|
||||
|
||||
|
||||
/* Functions to create SDL_RWops structures from various data sources */
|
||||
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
|
||||
const char *mode);
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
|
||||
SDL_bool autoclose);
|
||||
#endif
|
||||
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
|
||||
int size);
|
||||
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
|
||||
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
|
||||
|
||||
#define RW_SEEK_SET 0 /* Seek from the beginning of data */
|
||||
#define RW_SEEK_CUR 1 /* Seek relative to current read point */
|
||||
#define RW_SEEK_END 2 /* Seek relative to the end of data */
|
||||
|
||||
/* Macros to easily read and write from an SDL_RWops structure */
|
||||
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
|
||||
#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
|
||||
#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
|
||||
#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
|
||||
#define SDL_RWclose(ctx) (ctx)->close(ctx)
|
||||
|
||||
|
||||
/* Read an item of the specified endianness and return in native format */
|
||||
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
|
||||
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
|
||||
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
|
||||
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
|
||||
|
||||
/* Write an item of native format to the specified endianness */
|
||||
extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
|
||||
extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
|
||||
extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
|
||||
extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
|
||||
extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
|
||||
extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_rwops_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_rwops.h
|
||||
*
|
||||
* This file provides a general interface for SDL to read and write
|
||||
* data sources. It can easily be extended to files, memory, etc.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_rwops_h
|
||||
#define _SDL_rwops_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is the read/write operation structure -- very basic.
|
||||
*/
|
||||
typedef struct SDL_RWops
|
||||
{
|
||||
/**
|
||||
* Seek to \c offset relative to \c whence, one of stdio's whence values:
|
||||
* RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
|
||||
*
|
||||
* \return the final offset in the data source.
|
||||
*/
|
||||
long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
|
||||
int whence);
|
||||
|
||||
/**
|
||||
* Read up to \c num objects each of size \c objsize from the data
|
||||
* source to the area pointed at by \c ptr.
|
||||
*
|
||||
* \return the number of objects read, or 0 at error or end of file.
|
||||
*/
|
||||
size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
|
||||
size_t size, size_t maxnum);
|
||||
|
||||
/**
|
||||
* Write exactly \c num objects each of size \c objsize from the area
|
||||
* pointed at by \c ptr to data source.
|
||||
*
|
||||
* \return the number of objects written, or 0 at error or end of file.
|
||||
*/
|
||||
size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
|
||||
size_t size, size_t num);
|
||||
|
||||
/**
|
||||
* Close and free an allocated SDL_RWops structure.
|
||||
*
|
||||
* \return 0 if successful or -1 on write error when flushing data.
|
||||
*/
|
||||
int (SDLCALL * close) (struct SDL_RWops * context);
|
||||
|
||||
Uint32 type;
|
||||
union
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
struct
|
||||
{
|
||||
SDL_bool append;
|
||||
void *h;
|
||||
struct
|
||||
{
|
||||
void *data;
|
||||
size_t size;
|
||||
size_t left;
|
||||
} buffer;
|
||||
} win32io;
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
struct
|
||||
{
|
||||
SDL_bool autoclose;
|
||||
FILE *fp;
|
||||
} stdio;
|
||||
#endif
|
||||
struct
|
||||
{
|
||||
Uint8 *base;
|
||||
Uint8 *here;
|
||||
Uint8 *stop;
|
||||
} mem;
|
||||
struct
|
||||
{
|
||||
void *data1;
|
||||
} unknown;
|
||||
} hidden;
|
||||
|
||||
} SDL_RWops;
|
||||
|
||||
|
||||
/**
|
||||
* \name RWFrom functions
|
||||
*
|
||||
* Functions to create SDL_RWops structures from various data sources.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
|
||||
const char *mode);
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
|
||||
SDL_bool autoclose);
|
||||
#endif
|
||||
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
|
||||
int size);
|
||||
|
||||
/*@}*//*RWFrom functions*/
|
||||
|
||||
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
|
||||
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
|
||||
|
||||
#define RW_SEEK_SET 0 /**< Seek from the beginning of data */
|
||||
#define RW_SEEK_CUR 1 /**< Seek relative to current read point */
|
||||
#define RW_SEEK_END 2 /**< Seek relative to the end of data */
|
||||
|
||||
/**
|
||||
* \name Read/write macros
|
||||
*
|
||||
* Macros to easily read and write from an SDL_RWops structure.
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
|
||||
#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
|
||||
#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
|
||||
#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
|
||||
#define SDL_RWclose(ctx) (ctx)->close(ctx)
|
||||
/*@}*//*Read/write macros*/
|
||||
|
||||
|
||||
/**
|
||||
* \name Read endian functions
|
||||
*
|
||||
* Read an item of the specified endianness and return in native format.
|
||||
*/
|
||||
/*@{*/
|
||||
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
|
||||
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
|
||||
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
|
||||
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
|
||||
/*@}*//*Read endian functions*/
|
||||
|
||||
/**
|
||||
* \name Write endian functions
|
||||
*
|
||||
* Write an item of native format to the specified endianness.
|
||||
*/
|
||||
/*@{*/
|
||||
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
|
||||
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
|
||||
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
|
||||
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
|
||||
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
|
||||
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
|
||||
/*@}*//*Write endian functions*/
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_rwops_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_scancode.h
|
||||
* \file SDL_scancode.h
|
||||
*
|
||||
* Defines keyboard scancodes.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_scancode_h
|
||||
|
@ -30,22 +32,25 @@
|
|||
#include "SDL_stdinc.h"
|
||||
|
||||
/**
|
||||
* \enum SDL_scancode
|
||||
*
|
||||
* \brief The SDL keyboard scancode representation.
|
||||
*
|
||||
* Values of this type are used to represent keyboard keys, among other places
|
||||
* in the \link SDL_keysym::scancode key.keysym.scancode \endlink field of the
|
||||
* SDL_Event structure.
|
||||
*
|
||||
* The values in this enumeration are based on the USB usage page standard:
|
||||
* http://www.usb.org/developers/devclass_docs/Hut1_12.pdf
|
||||
* \brief The SDL keyboard scancode representation.
|
||||
*
|
||||
* Values of this type are used to represent keyboard keys, among other places
|
||||
* in the \link SDL_keysym::scancode key.keysym.scancode \endlink field of the
|
||||
* SDL_Event structure.
|
||||
*
|
||||
* The values in this enumeration are based on the USB usage page standard:
|
||||
* http://www.usb.org/developers/devclass_docs/Hut1_12.pdf
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SDL_SCANCODE_UNKNOWN = 0,
|
||||
|
||||
/* These values are from usage page 0x07 (USB keyboard page) */
|
||||
/**
|
||||
* \name Usage page 0x07
|
||||
*
|
||||
* These values are from usage page 0x07 (USB keyboard page).
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
SDL_SCANCODE_A = 4,
|
||||
SDL_SCANCODE_B = 5,
|
||||
|
@ -95,11 +100,51 @@ typedef enum
|
|||
SDL_SCANCODE_EQUALS = 46,
|
||||
SDL_SCANCODE_LEFTBRACKET = 47,
|
||||
SDL_SCANCODE_RIGHTBRACKET = 48,
|
||||
SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return key on ISO keyboards and at the right end of the QWERTY row on ANSI keyboards. Produces REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US layout, REVERSE SOLIDUS and VERTICAL LINE in a UK Mac layout, NUMBER SIGN and TILDE in a UK Windows layout, DOLLAR SIGN and POUND SIGN in a Swiss German layout, NUMBER SIGN and APOSTROPHE in a German layout, GRAVE ACCENT and POUND SIGN in a French Mac layout, and ASTERISK and MICRO SIGN in a French Windows layout. */
|
||||
SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code instead of 49 for the same key, but all OSes I've seen treat the two codes identically. So, as an implementor, unless your keyboard generates both of those codes and your OS treats them differently, you should generate SDL_SCANCODE_BACKSLASH instead of this code. As a user, you should not rely on this code because SDL will never generate it with most (all?) keyboards. */
|
||||
SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return
|
||||
* key on ISO keyboards and at the right end
|
||||
* of the QWERTY row on ANSI keyboards.
|
||||
* Produces REVERSE SOLIDUS (backslash) and
|
||||
* VERTICAL LINE in a US layout, REVERSE
|
||||
* SOLIDUS and VERTICAL LINE in a UK Mac
|
||||
* layout, NUMBER SIGN and TILDE in a UK
|
||||
* Windows layout, DOLLAR SIGN and POUND SIGN
|
||||
* in a Swiss German layout, NUMBER SIGN and
|
||||
* APOSTROPHE in a German layout, GRAVE
|
||||
* ACCENT and POUND SIGN in a French Mac
|
||||
* layout, and ASTERISK and MICRO SIGN in a
|
||||
* French Windows layout.
|
||||
*/
|
||||
SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
|
||||
* instead of 49 for the same key, but all
|
||||
* OSes I've seen treat the two codes
|
||||
* identically. So, as an implementor, unless
|
||||
* your keyboard generates both of those
|
||||
* codes and your OS treats them differently,
|
||||
* you should generate SDL_SCANCODE_BACKSLASH
|
||||
* instead of this code. As a user, you
|
||||
* should not rely on this code because SDL
|
||||
* will never generate it with most (all?)
|
||||
* keyboards.
|
||||
*/
|
||||
SDL_SCANCODE_SEMICOLON = 51,
|
||||
SDL_SCANCODE_APOSTROPHE = 52,
|
||||
SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI and ISO keyboards). Produces GRAVE ACCENT and TILDE in a US Windows layout and in US and UK Mac layouts on ANSI keyboards, GRAVE ACCENT and NOT SIGN in a UK Windows layout, SECTION SIGN and PLUS-MINUS SIGN in US and UK Mac layouts on ISO keyboards, SECTION SIGN and DEGREE SIGN in a Swiss German layout (Mac: only on ISO keyboards), CIRCUMFLEX ACCENT and DEGREE SIGN in a German layout (Mac: only on ISO keyboards), SUPERSCRIPT TWO and TILDE in a French Windows layout, COMMERCIAL AT and NUMBER SIGN in a French Mac layout on ISO keyboards, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French Mac layout on ANSI keyboards. */
|
||||
SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI
|
||||
* and ISO keyboards). Produces GRAVE ACCENT and
|
||||
* TILDE in a US Windows layout and in US and UK
|
||||
* Mac layouts on ANSI keyboards, GRAVE ACCENT
|
||||
* and NOT SIGN in a UK Windows layout, SECTION
|
||||
* SIGN and PLUS-MINUS SIGN in US and UK Mac
|
||||
* layouts on ISO keyboards, SECTION SIGN and
|
||||
* DEGREE SIGN in a Swiss German layout (Mac:
|
||||
* only on ISO keyboards), CIRCUMFLEX ACCENT and
|
||||
* DEGREE SIGN in a German layout (Mac: only on
|
||||
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
|
||||
* French Windows layout, COMMERCIAL AT and
|
||||
* NUMBER SIGN in a French Mac layout on ISO
|
||||
* keyboards, and LESS-THAN SIGN and GREATER-THAN
|
||||
* SIGN in a Swiss German, German, or French Mac
|
||||
* layout on ANSI keyboards.
|
||||
*/
|
||||
SDL_SCANCODE_COMMA = 54,
|
||||
SDL_SCANCODE_PERIOD = 55,
|
||||
SDL_SCANCODE_SLASH = 56,
|
||||
|
@ -122,7 +167,8 @@ typedef enum
|
|||
SDL_SCANCODE_PRINTSCREEN = 70,
|
||||
SDL_SCANCODE_SCROLLLOCK = 71,
|
||||
SDL_SCANCODE_PAUSE = 72,
|
||||
SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but does send code 73, not 117) */
|
||||
SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
|
||||
does send code 73, not 117) */
|
||||
SDL_SCANCODE_HOME = 74,
|
||||
SDL_SCANCODE_PAGEUP = 75,
|
||||
SDL_SCANCODE_DELETE = 76,
|
||||
|
@ -133,7 +179,8 @@ typedef enum
|
|||
SDL_SCANCODE_DOWN = 81,
|
||||
SDL_SCANCODE_UP = 82,
|
||||
|
||||
SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards */
|
||||
SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
|
||||
*/
|
||||
SDL_SCANCODE_KP_DIVIDE = 84,
|
||||
SDL_SCANCODE_KP_MULTIPLY = 85,
|
||||
SDL_SCANCODE_KP_MINUS = 86,
|
||||
|
@ -151,9 +198,20 @@ typedef enum
|
|||
SDL_SCANCODE_KP_0 = 98,
|
||||
SDL_SCANCODE_KP_PERIOD = 99,
|
||||
|
||||
SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO keyboards have over ANSI ones, located between left shift and Y. Produces GRAVE ACCENT and TILDE in a US or UK Mac layout, REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US or UK Windows layout, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French layout. */
|
||||
SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
|
||||
* keyboards have over ANSI ones,
|
||||
* located between left shift and Y.
|
||||
* Produces GRAVE ACCENT and TILDE in a
|
||||
* US or UK Mac layout, REVERSE SOLIDUS
|
||||
* (backslash) and VERTICAL LINE in a
|
||||
* US or UK Windows layout, and
|
||||
* LESS-THAN SIGN and GREATER-THAN SIGN
|
||||
* in a Swiss German, German, or French
|
||||
* layout. */
|
||||
SDL_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
|
||||
SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key. */
|
||||
SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag,
|
||||
* not a physical key - but some Mac keyboards
|
||||
* do have a power key. */
|
||||
SDL_SCANCODE_KP_EQUALS = 103,
|
||||
SDL_SCANCODE_F13 = 104,
|
||||
SDL_SCANCODE_F14 = 105,
|
||||
|
@ -172,7 +230,7 @@ typedef enum
|
|||
SDL_SCANCODE_MENU = 118,
|
||||
SDL_SCANCODE_SELECT = 119,
|
||||
SDL_SCANCODE_STOP = 120,
|
||||
SDL_SCANCODE_AGAIN = 121, /*!< redo */
|
||||
SDL_SCANCODE_AGAIN = 121, /**< redo */
|
||||
SDL_SCANCODE_UNDO = 122,
|
||||
SDL_SCANCODE_CUT = 123,
|
||||
SDL_SCANCODE_COPY = 124,
|
||||
|
@ -188,7 +246,8 @@ typedef enum
|
|||
SDL_SCANCODE_KP_COMMA = 133,
|
||||
SDL_SCANCODE_KP_EQUALSAS400 = 134,
|
||||
|
||||
SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see footnotes in USB doc */
|
||||
SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
|
||||
footnotes in USB doc */
|
||||
SDL_SCANCODE_INTERNATIONAL2 = 136,
|
||||
SDL_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
|
||||
SDL_SCANCODE_INTERNATIONAL4 = 138,
|
||||
|
@ -276,9 +335,19 @@ typedef enum
|
|||
SDL_SCANCODE_RALT = 230, /**< alt gr, option */
|
||||
SDL_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
|
||||
|
||||
SDL_SCANCODE_MODE = 257, /* I'm not sure if this is really not covered by any of the above, but since there's a special KMOD_MODE for it I'm adding it here */
|
||||
SDL_SCANCODE_MODE = 257, /**< I'm not sure if this is really not covered
|
||||
* by any of the above, but since there's a
|
||||
* special KMOD_MODE for it I'm adding it here
|
||||
*/
|
||||
|
||||
/*@}*//*Usage page 0x07*/
|
||||
|
||||
/* These values are mapped from usage page 0x0C (USB consumer page) */
|
||||
/**
|
||||
* \name Usage page 0x0C
|
||||
*
|
||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
SDL_SCANCODE_AUDIONEXT = 258,
|
||||
SDL_SCANCODE_AUDIOPREV = 259,
|
||||
|
@ -297,21 +366,32 @@ typedef enum
|
|||
SDL_SCANCODE_AC_STOP = 272,
|
||||
SDL_SCANCODE_AC_REFRESH = 273,
|
||||
SDL_SCANCODE_AC_BOOKMARKS = 274,
|
||||
|
||||
/*@}*//*Usage page 0x0C*/
|
||||
|
||||
/* These are values that Christian Walther added (for mac keyboard?) */
|
||||
/**
|
||||
* \name Walther keys
|
||||
*
|
||||
* These are values that Christian Walther added (for mac keyboard?).
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
SDL_SCANCODE_BRIGHTNESSDOWN = 275,
|
||||
SDL_SCANCODE_BRIGHTNESSUP = 276,
|
||||
SDL_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display switch, video mode switch */
|
||||
SDL_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display
|
||||
switch, video mode switch */
|
||||
SDL_SCANCODE_KBDILLUMTOGGLE = 278,
|
||||
SDL_SCANCODE_KBDILLUMDOWN = 279,
|
||||
SDL_SCANCODE_KBDILLUMUP = 280,
|
||||
SDL_SCANCODE_EJECT = 281,
|
||||
SDL_SCANCODE_SLEEP = 282,
|
||||
|
||||
/*@}*//*Walther keys*/
|
||||
|
||||
/* Add any other keys here */
|
||||
/* Add any other keys here. */
|
||||
|
||||
SDL_NUM_SCANCODES = 512 /**< (not a key, just marks the number of scancodes for array bounds) */
|
||||
SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
|
||||
for array bounds */
|
||||
} SDL_scancode;
|
||||
|
||||
#endif /* _SDL_scancode_h */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,9 +21,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_surface.h
|
||||
*
|
||||
* Header file for SDL_surface definition and management functions
|
||||
* \file SDL_surface.h
|
||||
*
|
||||
* Header file for ::SDL_surface definition and management functions.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_surface_h
|
||||
|
@ -42,20 +42,28 @@ extern "C" {
|
|||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* These are the currently supported flags for the SDL_surface */
|
||||
/* Used internally (read-only) */
|
||||
#define SDL_PREALLOC 0x00000001 /* Surface uses preallocated memory */
|
||||
#define SDL_RLEACCEL 0x00000002 /* Surface is RLE encoded */
|
||||
/**
|
||||
* \name Surface flags
|
||||
*
|
||||
* These are the currently supported flags for the ::SDL_surface.
|
||||
*
|
||||
* \internal
|
||||
* Used internally (read-only).
|
||||
*/
|
||||
/*@{*/
|
||||
#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
|
||||
#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
|
||||
/*@}*//*Surface flags*/
|
||||
|
||||
/* Evaluates to true if the surface needs to be locked before access */
|
||||
/**
|
||||
* Evaluates to true if the surface needs to be locked before access.
|
||||
*/
|
||||
#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
|
||||
|
||||
/**
|
||||
* \struct SDL_Surface
|
||||
* \brief A collection of pixels used in software blitting.
|
||||
*
|
||||
* \brief A collection of pixels used in software blitting
|
||||
*
|
||||
* \note This structure should be treated as read-only, except for 'pixels',
|
||||
* \note This structure should be treated as read-only, except for \c pixels,
|
||||
* which, if not NULL, contains the raw pixel data for the surface.
|
||||
*/
|
||||
typedef struct SDL_Surface
|
||||
|
@ -66,42 +74,42 @@ typedef struct SDL_Surface
|
|||
int pitch; /**< Read-only */
|
||||
void *pixels; /**< Read-write */
|
||||
|
||||
/* Application data associated with the surfade */
|
||||
/** Application data associated with the surfade */
|
||||
void *userdata; /**< Read-write */
|
||||
|
||||
/* information needed for surfaces requiring locks */
|
||||
/** information needed for surfaces requiring locks */
|
||||
int locked; /**< Read-only */
|
||||
void *lock_data; /**< Read-only */
|
||||
|
||||
/* clipping information */
|
||||
/** clipping information */
|
||||
SDL_Rect clip_rect; /**< Read-only */
|
||||
|
||||
/* info for fast blit mapping to other surfaces */
|
||||
/** info for fast blit mapping to other surfaces */
|
||||
struct SDL_BlitMap *map; /**< Private */
|
||||
|
||||
/* format version, bumped at every change to invalidate blit maps */
|
||||
/** format version, bumped at every change to invalidate blit maps */
|
||||
unsigned int format_version; /**< Private */
|
||||
|
||||
/* Reference count -- used when freeing surface */
|
||||
/** Reference count -- used when freeing surface */
|
||||
int refcount; /**< Read-mostly */
|
||||
} SDL_Surface;
|
||||
|
||||
/**
|
||||
* \typedef SDL_blit
|
||||
*
|
||||
* \brief The type of function used for surface blitting functions
|
||||
* \brief The type of function used for surface blitting functions.
|
||||
*/
|
||||
typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
|
||||
struct SDL_Surface * dst, SDL_Rect * dstrect);
|
||||
|
||||
/*
|
||||
* Allocate and free an RGB surface (must be called after SDL_SetVideoMode)
|
||||
* If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
|
||||
* If the depth is greater than 8 bits, the pixel format is set using the
|
||||
* flags '[RGB]mask'.
|
||||
* If the function runs out of memory, it will return NULL.
|
||||
*
|
||||
* The 'flags' are obsolete and should be set to 0.
|
||||
/**
|
||||
* Allocate and free an RGB surface (must be called after SDL_SetVideoMode).
|
||||
*
|
||||
* If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
|
||||
* If the depth is greater than 8 bits, the pixel format is set using the
|
||||
* flags '[RGB]mask'.
|
||||
*
|
||||
* If the function runs out of memory, it will return NULL.
|
||||
*
|
||||
* \param flags The \c flags are obsolete and should be set to 0.
|
||||
*/
|
||||
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
|
||||
(Uint32 flags, int width, int height, int depth,
|
||||
|
@ -118,402 +126,437 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
|
|||
extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
|
||||
*
|
||||
* \brief Set the palette used by a surface.
|
||||
*
|
||||
* \return 0, or -1 if the surface format doesn't use a palette.
|
||||
*
|
||||
* \note A single palette can be shared with many surfaces.
|
||||
* \brief Set the palette used by a surface.
|
||||
*
|
||||
* \return 0, or -1 if the surface format doesn't use a palette.
|
||||
*
|
||||
* \note A single palette can be shared with many surfaces.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
|
||||
SDL_Palette * palette);
|
||||
|
||||
/*
|
||||
* SDL_LockSurface() sets up a surface for directly accessing the pixels.
|
||||
* Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write
|
||||
* to and read from 'surface->pixels', using the pixel format stored in
|
||||
* 'surface->format'. Once you are done accessing the surface, you should
|
||||
* use SDL_UnlockSurface() to release it.
|
||||
*
|
||||
* Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
|
||||
* to 0, then you can read and write to the surface at any time, and the
|
||||
* pixel format of the surface will not change.
|
||||
*
|
||||
* No operating system or library calls should be made between lock/unlock
|
||||
* pairs, as critical system locks may be held during this time.
|
||||
*
|
||||
* SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
|
||||
/**
|
||||
* \brief Sets up a surface for directly accessing the pixels.
|
||||
*
|
||||
* Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
|
||||
* to and read from \c surface->pixels, using the pixel format stored in
|
||||
* \c surface->format. Once you are done accessing the surface, you should
|
||||
* use SDL_UnlockSurface() to release it.
|
||||
*
|
||||
* Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
|
||||
* to 0, then you can read and write to the surface at any time, and the
|
||||
* pixel format of the surface will not change.
|
||||
*
|
||||
* No operating system or library calls should be made between lock/unlock
|
||||
* pairs, as critical system locks may be held during this time.
|
||||
*
|
||||
* SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
|
||||
*
|
||||
* \sa SDL_UnlockSurface()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
|
||||
/** \sa SDL_LockSurface() */
|
||||
extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
|
||||
|
||||
/*
|
||||
* Load a surface from a seekable SDL data source (memory or file.)
|
||||
* If 'freesrc' is non-zero, the source will be closed after being read.
|
||||
* Returns the new surface, or NULL if there was an error.
|
||||
* The new surface should be freed with SDL_FreeSurface().
|
||||
/**
|
||||
* Load a surface from a seekable SDL data source (memory or file).
|
||||
*
|
||||
* If \c freesrc is non-zero, the source will be closed after being read.
|
||||
*
|
||||
* The new surface should be freed with SDL_FreeSurface().
|
||||
*
|
||||
* \return the new surface, or NULL if there was an error.
|
||||
*/
|
||||
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
|
||||
int freesrc);
|
||||
|
||||
/* Convenience macro -- load a surface from a file */
|
||||
/**
|
||||
* Load a surface from a file.
|
||||
*
|
||||
* Convenience macro.
|
||||
*/
|
||||
#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
|
||||
|
||||
/*
|
||||
* Save a surface to a seekable SDL data source (memory or file.)
|
||||
* If 'freedst' is non-zero, the source will be closed after being written.
|
||||
* Returns 0 if successful or -1 if there was an error.
|
||||
/**
|
||||
* Save a surface to a seekable SDL data source (memory or file).
|
||||
*
|
||||
* If \c freedst is non-zero, the source will be closed after being written.
|
||||
*
|
||||
* \return 0 if successful or -1 if there was an error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
|
||||
(SDL_Surface * surface, SDL_RWops * dst, int freedst);
|
||||
|
||||
/* Convenience macro -- save a surface to a file */
|
||||
/**
|
||||
* Save a surface to a file.
|
||||
*
|
||||
* Convenience macro.
|
||||
*/
|
||||
#define SDL_SaveBMP(surface, file) \
|
||||
SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
|
||||
|
||||
/*
|
||||
* \fn int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
|
||||
*
|
||||
* \brief Sets the RLE acceleration hint for a surface.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \note If RLE is enabled, colorkey and alpha blending blits are much faster,
|
||||
* but the surface must be locked before directly accessing the pixels.
|
||||
/**
|
||||
* \brief Sets the RLE acceleration hint for a surface.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \note If RLE is enabled, colorkey and alpha blending blits are much faster,
|
||||
* but the surface must be locked before directly accessing the pixels.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
|
||||
int flag);
|
||||
|
||||
/*
|
||||
* \fn int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
|
||||
*
|
||||
* \brief Sets the color key (transparent pixel) in a blittable surface.
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param flag Non-zero to enable colorkey and 0 to disable colorkey
|
||||
* \param key The transparent pixel in the native surface format
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
/**
|
||||
* \brief Sets the color key (transparent pixel) in a blittable surface.
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param flag Non-zero to enable colorkey and 0 to disable colorkey
|
||||
* \param key The transparent pixel in the native surface format
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
|
||||
Uint32 flag, Uint32 key);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
|
||||
*
|
||||
* \brief Set an additional color value used in blit operations
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param r The red source color value multiplied into blit operations
|
||||
* \param g The green source color value multiplied into blit operations
|
||||
* \param b The blue source color value multiplied into blit operations
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \sa SDL_GetSurfaceColorMod()
|
||||
* \brief Sets the color key (transparent pixel) in a blittable surface.
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param key A pointer filled in with the transparent pixel in the native
|
||||
* surface format
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid or colorkey is not
|
||||
* enabled.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
|
||||
Uint32 * key);
|
||||
|
||||
/**
|
||||
* \brief Set an additional color value used in blit operations.
|
||||
*
|
||||
* \param surface The surface to update.
|
||||
* \param r The red source color value multiplied into blit operations.
|
||||
* \param g The green source color value multiplied into blit operations.
|
||||
* \param b The blue source color value multiplied into blit operations.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid.
|
||||
*
|
||||
* \sa SDL_GetSurfaceColorMod()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
|
||||
Uint8 r, Uint8 g, Uint8 b);
|
||||
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
|
||||
*
|
||||
* \brief Get the additional color value used in blit operations
|
||||
*
|
||||
* \param surface The surface to query
|
||||
* \param r A pointer filled in with the source red color value
|
||||
* \param g A pointer filled in with the source green color value
|
||||
* \param b A pointer filled in with the source blue color value
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \sa SDL_SetSurfaceColorMod()
|
||||
* \brief Get the additional color value used in blit operations.
|
||||
*
|
||||
* \param surface The surface to query.
|
||||
* \param r A pointer filled in with the source red color value.
|
||||
* \param g A pointer filled in with the source green color value.
|
||||
* \param b A pointer filled in with the source blue color value.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid.
|
||||
*
|
||||
* \sa SDL_SetSurfaceColorMod()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
|
||||
Uint8 * r, Uint8 * g,
|
||||
Uint8 * b);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
|
||||
*
|
||||
* \brief Set an additional alpha value used in blit operations
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param alpha The source alpha value multiplied into blit operations.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \sa SDL_GetSurfaceAlphaMod()
|
||||
* \brief Set an additional alpha value used in blit operations.
|
||||
*
|
||||
* \param surface The surface to update.
|
||||
* \param alpha The source alpha value multiplied into blit operations.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid.
|
||||
*
|
||||
* \sa SDL_GetSurfaceAlphaMod()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
|
||||
Uint8 alpha);
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
|
||||
*
|
||||
* \brief Get the additional alpha value used in blit operations
|
||||
*
|
||||
* \param surface The surface to query
|
||||
* \param alpha A pointer filled in with the source alpha value
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \sa SDL_SetSurfaceAlphaMod()
|
||||
* \brief Get the additional alpha value used in blit operations.
|
||||
*
|
||||
* \param surface The surface to query.
|
||||
* \param alpha A pointer filled in with the source alpha value.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid.
|
||||
*
|
||||
* \sa SDL_SetSurfaceAlphaMod()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
|
||||
Uint8 * alpha);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode)
|
||||
*
|
||||
* \brief Set the blend mode used for blit operations
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param blendMode SDL_TextureBlendMode to use for blit blending
|
||||
*
|
||||
* \return 0 on success, or -1 if the parameters are not valid
|
||||
*
|
||||
* \sa SDL_GetSurfaceBlendMode()
|
||||
* \brief Set the blend mode used for blit operations.
|
||||
*
|
||||
* \param surface The surface to update.
|
||||
* \param blendMode ::SDL_BlendMode to use for blit blending.
|
||||
*
|
||||
* \return 0 on success, or -1 if the parameters are not valid.
|
||||
*
|
||||
* \sa SDL_GetSurfaceBlendMode()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
|
||||
int blendMode);
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode)
|
||||
*
|
||||
* \brief Get the blend mode used for blit operations
|
||||
*
|
||||
* \param surface The surface to query
|
||||
* \param blendMode A pointer filled in with the current blend mode
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \sa SDL_SetSurfaceBlendMode()
|
||||
* \brief Get the blend mode used for blit operations.
|
||||
*
|
||||
* \param surface The surface to query.
|
||||
* \param blendMode A pointer filled in with the current blend mode.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid.
|
||||
*
|
||||
* \sa SDL_SetSurfaceBlendMode()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
|
||||
int *blendMode);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode)
|
||||
*
|
||||
* \brief Set the scale mode used for blit operations
|
||||
*
|
||||
* \param surface The surface to update
|
||||
* \param scaleMode SDL_TextureScaleMode to use for blit scaling
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid or the scale mode is not supported
|
||||
*
|
||||
* \note If the scale mode is not supported, the closest supported mode is chosen. Currently only SDL_TEXTURESCALEMODE_FAST is supported on surfaces.
|
||||
*
|
||||
* \sa SDL_GetSurfaceScaleMode()
|
||||
* \brief Set the scale mode used for blit operations.
|
||||
*
|
||||
* \param surface The surface to update.
|
||||
* \param scaleMode ::SDL_TextureScaleMode to use for blit scaling.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid or the scale mode is
|
||||
* not supported.
|
||||
*
|
||||
* \note If the scale mode is not supported, the closest supported mode is
|
||||
* chosen. Currently only ::SDL_TEXTURESCALEMODE_FAST is supported on
|
||||
* surfaces.
|
||||
*
|
||||
* \sa SDL_GetSurfaceScaleMode()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface * surface,
|
||||
int scaleMode);
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode)
|
||||
*
|
||||
* \brief Get the scale mode used for blit operations
|
||||
*
|
||||
* \param surface The surface to query
|
||||
* \param scaleMode A pointer filled in with the current scale mode
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid
|
||||
*
|
||||
* \sa SDL_SetSurfaceScaleMode()
|
||||
* \brief Get the scale mode used for blit operations.
|
||||
*
|
||||
* \param surface The surface to query.
|
||||
* \param scaleMode A pointer filled in with the current scale mode.
|
||||
*
|
||||
* \return 0 on success, or -1 if the surface is not valid.
|
||||
*
|
||||
* \sa SDL_SetSurfaceScaleMode()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface * surface,
|
||||
int *scaleMode);
|
||||
|
||||
/*
|
||||
* Sets the clipping rectangle for the destination surface in a blit.
|
||||
*
|
||||
* If the clip rectangle is NULL, clipping will be disabled.
|
||||
* If the clip rectangle doesn't intersect the surface, the function will
|
||||
* return SDL_FALSE and blits will be completely clipped. Otherwise the
|
||||
* function returns SDL_TRUE and blits to the surface will be clipped to
|
||||
* the intersection of the surface area and the clipping rectangle.
|
||||
*
|
||||
* Note that blits are automatically clipped to the edges of the source
|
||||
* and destination surfaces.
|
||||
/**
|
||||
* Sets the clipping rectangle for the destination surface in a blit.
|
||||
*
|
||||
* If the clip rectangle is NULL, clipping will be disabled.
|
||||
*
|
||||
* If the clip rectangle doesn't intersect the surface, the function will
|
||||
* return SDL_FALSE and blits will be completely clipped. Otherwise the
|
||||
* function returns SDL_TRUE and blits to the surface will be clipped to
|
||||
* the intersection of the surface area and the clipping rectangle.
|
||||
*
|
||||
* Note that blits are automatically clipped to the edges of the source
|
||||
* and destination surfaces.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
|
||||
const SDL_Rect * rect);
|
||||
|
||||
/*
|
||||
* Gets the clipping rectangle for the destination surface in a blit.
|
||||
* 'rect' must be a pointer to a valid rectangle which will be filled
|
||||
* with the correct values.
|
||||
/**
|
||||
* Gets the clipping rectangle for the destination surface in a blit.
|
||||
*
|
||||
* \c rect must be a pointer to a valid rectangle which will be filled
|
||||
* with the correct values.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
|
||||
SDL_Rect * rect);
|
||||
|
||||
/*
|
||||
* Creates a new surface of the specified format, and then copies and maps
|
||||
* the given surface to it so the blit of the converted surface will be as
|
||||
* fast as possible. If this function fails, it returns NULL.
|
||||
*
|
||||
* The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those
|
||||
* semantics. You can also pass SDL_RLEACCEL in the flags parameter and
|
||||
* SDL will try to RLE accelerate colorkey and alpha blits in the resulting
|
||||
* surface.
|
||||
*
|
||||
* This function is used internally by SDL_DisplayFormat().
|
||||
/**
|
||||
* Creates a new surface of the specified format, and then copies and maps
|
||||
* the given surface to it so the blit of the converted surface will be as
|
||||
* fast as possible. If this function fails, it returns NULL.
|
||||
*
|
||||
* The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
|
||||
* semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and
|
||||
* SDL will try to RLE accelerate colorkey and alpha blits in the resulting
|
||||
* surface.
|
||||
*
|
||||
* This function is used internally by SDL_DisplayFormat().
|
||||
*/
|
||||
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
|
||||
(SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
|
||||
|
||||
/*
|
||||
* This function draws a point with 'color'
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
/**
|
||||
* Draws a point with \c color.
|
||||
*
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
*
|
||||
* \return 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_DrawPoint
|
||||
(SDL_Surface * dst, int x, int y, Uint32 color);
|
||||
|
||||
/*
|
||||
* This function blends a point with an RGBA value
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
/**
|
||||
* Blends a point with an RGBA value.
|
||||
*
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
*
|
||||
* \return 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_BlendPoint
|
||||
(SDL_Surface * dst, int x, int y, int blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
/*
|
||||
* This function draws a line with 'color'
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
/**
|
||||
* Draws a line with \c color.
|
||||
*
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
*
|
||||
* \return 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_DrawLine
|
||||
(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
|
||||
|
||||
/*
|
||||
* This function blends an RGBA value along a line
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
/**
|
||||
* Blends an RGBA value along a line.
|
||||
*
|
||||
* \return 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_BlendLine
|
||||
(SDL_Surface * dst, int x1, int y1, int x2, int y2, int blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
/*
|
||||
* This function performs a fast fill of the given rectangle with 'color'
|
||||
* The given rectangle is clipped to the destination surface clip area
|
||||
* and the final fill rectangle is saved in the passed in pointer.
|
||||
* If 'dstrect' is NULL, the whole surface will be filled with 'color'
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
/**
|
||||
* Performs a fast fill of the given rectangle with \c color.
|
||||
*
|
||||
* The given rectangle is clipped to the destination surface clip area
|
||||
* and the final fill rectangle is saved in the passed in pointer.
|
||||
*
|
||||
* If \c dstrect is NULL, the whole surface will be filled with \c color.
|
||||
*
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
*
|
||||
* \return 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_FillRect
|
||||
(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color);
|
||||
|
||||
/*
|
||||
* This function blends an RGBA value into the given rectangle.
|
||||
* The given rectangle is clipped to the destination surface clip area
|
||||
* and the final fill rectangle is saved in the passed in pointer.
|
||||
* If 'dstrect' is NULL, the whole surface will be filled with 'color'
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
/**
|
||||
* Blends an RGBA value into the given rectangle.
|
||||
*
|
||||
* The given rectangle is clipped to the destination surface clip area
|
||||
* and the final fill rectangle is saved in the passed in pointer.
|
||||
*
|
||||
* If \c dstrect is NULL, the whole surface will be filled with \c color.
|
||||
*
|
||||
* \return This function returns 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_BlendRect
|
||||
(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a);
|
||||
|
||||
/*
|
||||
* This performs a fast blit from the source surface to the destination
|
||||
* surface. It assumes that the source and destination rectangles are
|
||||
* the same size. If either 'srcrect' or 'dstrect' are NULL, the entire
|
||||
* surface (src or dst) is copied. The final blit rectangles are saved
|
||||
* in 'srcrect' and 'dstrect' after all clipping is performed.
|
||||
* If the blit is successful, it returns 0, otherwise it returns -1.
|
||||
/**
|
||||
* Performs a fast blit from the source surface to the destination surface.
|
||||
*
|
||||
* This assumes that the source and destination rectangles are
|
||||
* the same size. If either \c srcrect or \c dstrect are NULL, the entire
|
||||
* surface (\c src or \c dst) is copied. The final blit rectangles are saved
|
||||
* in \c srcrect and \c dstrect after all clipping is performed.
|
||||
*
|
||||
* \return If the blit is successful, it returns 0, otherwise it returns -1.
|
||||
*
|
||||
* The blit function should not be called on a locked surface.
|
||||
* The blit function should not be called on a locked surface.
|
||||
*
|
||||
* The blit semantics for surfaces with and without alpha and colorkey
|
||||
* are defined as follows:
|
||||
*
|
||||
* RGBA->RGB:
|
||||
* SDL_SRCALPHA set:
|
||||
* alpha-blend (using alpha-channel).
|
||||
* SDL_SRCCOLORKEY ignored.
|
||||
* SDL_SRCALPHA not set:
|
||||
* copy RGB.
|
||||
* if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
* RGB values of the source colour key, ignoring alpha in the
|
||||
* comparison.
|
||||
*
|
||||
* RGB->RGBA:
|
||||
* SDL_SRCALPHA set:
|
||||
* alpha-blend (using the source per-surface alpha value);
|
||||
* set destination alpha to opaque.
|
||||
* SDL_SRCALPHA not set:
|
||||
* copy RGB, set destination alpha to source per-surface alpha value.
|
||||
* both:
|
||||
* if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
* source colour key.
|
||||
*
|
||||
* RGBA->RGBA:
|
||||
* SDL_SRCALPHA set:
|
||||
* alpha-blend (using the source alpha channel) the RGB values;
|
||||
* leave destination alpha untouched. [Note: is this correct?]
|
||||
* SDL_SRCCOLORKEY ignored.
|
||||
* SDL_SRCALPHA not set:
|
||||
* copy all of RGBA to the destination.
|
||||
* if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
* RGB values of the source colour key, ignoring alpha in the
|
||||
* comparison.
|
||||
*
|
||||
* RGB->RGB:
|
||||
* SDL_SRCALPHA set:
|
||||
* alpha-blend (using the source per-surface alpha value).
|
||||
* SDL_SRCALPHA not set:
|
||||
* copy RGB.
|
||||
* both:
|
||||
* if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
* source colour key.
|
||||
*
|
||||
* If either of the surfaces were in video memory, and the blit returns -2,
|
||||
* the video memory was lost, so it should be reloaded with artwork and
|
||||
* re-blitted:
|
||||
while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
|
||||
while ( SDL_LockSurface(image) < 0 )
|
||||
Sleep(10);
|
||||
-- Write image pixels to image->pixels --
|
||||
SDL_UnlockSurface(image);
|
||||
}
|
||||
* This happens under DirectX 5.0 when the system switches away from your
|
||||
* fullscreen application. The lock will also fail until you have access
|
||||
* to the video memory again.
|
||||
* The blit semantics for surfaces with and without alpha and colorkey
|
||||
* are defined as follows:
|
||||
* \verbatim
|
||||
RGBA->RGB:
|
||||
SDL_SRCALPHA set:
|
||||
alpha-blend (using alpha-channel).
|
||||
SDL_SRCCOLORKEY ignored.
|
||||
SDL_SRCALPHA not set:
|
||||
copy RGB.
|
||||
if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
RGB values of the source colour key, ignoring alpha in the
|
||||
comparison.
|
||||
|
||||
RGB->RGBA:
|
||||
SDL_SRCALPHA set:
|
||||
alpha-blend (using the source per-surface alpha value);
|
||||
set destination alpha to opaque.
|
||||
SDL_SRCALPHA not set:
|
||||
copy RGB, set destination alpha to source per-surface alpha value.
|
||||
both:
|
||||
if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
source colour key.
|
||||
|
||||
RGBA->RGBA:
|
||||
SDL_SRCALPHA set:
|
||||
alpha-blend (using the source alpha channel) the RGB values;
|
||||
leave destination alpha untouched. [Note: is this correct?]
|
||||
SDL_SRCCOLORKEY ignored.
|
||||
SDL_SRCALPHA not set:
|
||||
copy all of RGBA to the destination.
|
||||
if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
RGB values of the source colour key, ignoring alpha in the
|
||||
comparison.
|
||||
|
||||
RGB->RGB:
|
||||
SDL_SRCALPHA set:
|
||||
alpha-blend (using the source per-surface alpha value).
|
||||
SDL_SRCALPHA not set:
|
||||
copy RGB.
|
||||
both:
|
||||
if SDL_SRCCOLORKEY set, only copy the pixels matching the
|
||||
source colour key.
|
||||
\endverbatim
|
||||
*
|
||||
* If either of the surfaces were in video memory, and the blit returns -2,
|
||||
* the video memory was lost, so it should be reloaded with artwork and
|
||||
* re-blitted:
|
||||
* @code
|
||||
* while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
|
||||
* while ( SDL_LockSurface(image) < 0 )
|
||||
* Sleep(10);
|
||||
* -- Write image pixels to image->pixels --
|
||||
* SDL_UnlockSurface(image);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* This happens under DirectX 5.0 when the system switches away from your
|
||||
* fullscreen application. The lock will also fail until you have access
|
||||
* to the video memory again.
|
||||
*
|
||||
* You should call SDL_BlitSurface() unless you know exactly how SDL
|
||||
* blitting works internally and how to use the other blit functions.
|
||||
*/
|
||||
/* You should call SDL_BlitSurface() unless you know exactly how SDL
|
||||
blitting works internally and how to use the other blit functions.
|
||||
*/
|
||||
#define SDL_BlitSurface SDL_UpperBlit
|
||||
|
||||
/* This is the public blit function, SDL_BlitSurface(), and it performs
|
||||
rectangle validation and clipping before passing it to SDL_LowerBlit()
|
||||
*/
|
||||
/**
|
||||
* This is the public blit function, SDL_BlitSurface(), and it performs
|
||||
* rectangle validation and clipping before passing it to SDL_LowerBlit()
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_UpperBlit
|
||||
(SDL_Surface * src, SDL_Rect * srcrect,
|
||||
SDL_Surface * dst, SDL_Rect * dstrect);
|
||||
/* This is a semi-private blit function and it performs low-level surface
|
||||
blitting only.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a semi-private blit function and it performs low-level surface
|
||||
* blitting only.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_LowerBlit
|
||||
(SDL_Surface * src, SDL_Rect * srcrect,
|
||||
SDL_Surface * dst, SDL_Rect * dstrect);
|
||||
|
||||
/**
|
||||
* \fn int SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, const SDL_Rect * dstrect)
|
||||
*
|
||||
* \brief Perform a fast, low quality, stretch blit between two surfaces of the same pixel format.
|
||||
*
|
||||
* \note This function uses a static buffer, and is not thread-safe.
|
||||
* \brief Perform a fast, low quality, stretch blit between two surfaces of the
|
||||
* same pixel format.
|
||||
*
|
||||
* \note This function uses a static buffer, and is not thread-safe.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
|
||||
const SDL_Rect * srcrect,
|
||||
|
|
|
@ -1,244 +1,262 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_syswm.h
|
||||
*
|
||||
* Include file for SDL custom system window manager hooks
|
||||
*/
|
||||
|
||||
#ifndef _SDL_syswm_h
|
||||
#define _SDL_syswm_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_version.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Your application has access to a special type of event 'SDL_SYSWMEVENT',
|
||||
which contains window-manager specific information and arrives whenever
|
||||
an unhandled window event occurs. This event is ignored by default, but
|
||||
you can enable it with SDL_EventState()
|
||||
*/
|
||||
#ifdef SDL_PROTOTYPES_ONLY
|
||||
struct SDL_SysWMinfo;
|
||||
#else
|
||||
|
||||
/* This is the structure for custom window manager events */
|
||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
/* conflicts with Quickdraw.h */
|
||||
#define Cursor X11Cursor
|
||||
#endif
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
/* matches the re-define above */
|
||||
#undef Cursor
|
||||
#endif
|
||||
|
||||
/* These are the various supported subsystems under UNIX */
|
||||
typedef enum
|
||||
{
|
||||
SDL_SYSWM_X11
|
||||
} SDL_SYSWM_TYPE;
|
||||
|
||||
/* The UNIX custom event structure */
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
SDL_SYSWM_TYPE subsystem;
|
||||
union
|
||||
{
|
||||
XEvent xevent;
|
||||
} event;
|
||||
};
|
||||
|
||||
/* The UNIX custom window manager information structure.
|
||||
When this structure is returned, it holds information about which
|
||||
low level system it is using, and will be one of SDL_SYSWM_TYPE.
|
||||
*/
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
SDL_SYSWM_TYPE subsystem;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Display *display; /* The X11 display */
|
||||
Window window; /* The X11 display window */
|
||||
/* These locking functions should be called around
|
||||
any X11 functions using the display variable.
|
||||
They lock the event thread, so should not be
|
||||
called around event functions or from event filters.
|
||||
*/
|
||||
void (*lock_func) (void);
|
||||
void (*unlock_func) (void);
|
||||
|
||||
/* Introduced in SDL 1.0.2 */
|
||||
Window fswindow; /* The X11 fullscreen window */
|
||||
Window wmwindow; /* The X11 managed input window */
|
||||
} x11;
|
||||
} info;
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_NANOX)
|
||||
#include <microwin/nano-X.h>
|
||||
|
||||
/* The generic custom event structure */
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
/* The windows custom window manager information structure */
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
GR_WINDOW_ID window; /* The display window */
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
/* The windows custom event structure */
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
HWND hwnd; /* The window for the message */
|
||||
UINT msg; /* The type of message */
|
||||
WPARAM wParam; /* WORD message parameter */
|
||||
LPARAM lParam; /* LONG message parameter */
|
||||
};
|
||||
|
||||
/* The windows custom window manager information structure */
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
HWND window; /* The Win32 display window */
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_RISCOS)
|
||||
|
||||
/* RISC OS custom event structure */
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int eventCode; /* The window for the message */
|
||||
int pollBlock[64];
|
||||
};
|
||||
|
||||
/* The RISC OS custom window manager information structure */
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
int wimpVersion; /* Wimp version running under */
|
||||
int taskHandle; /* The RISC OS task handle */
|
||||
int window; /* The RISC OS display window */
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_PHOTON)
|
||||
#include <sys/neutrino.h>
|
||||
#include <Ph.h>
|
||||
|
||||
/* The QNX custom event structure */
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
/* The QNX custom window manager information structure */
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/* The generic custom event structure */
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
/* The generic custom window manager information structure */
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
#endif /* video driver type */
|
||||
|
||||
#endif /* SDL_PROTOTYPES_ONLY */
|
||||
|
||||
typedef struct SDL_SysWMinfo SDL_SysWMinfo;
|
||||
|
||||
/* Function prototypes */
|
||||
/**
|
||||
* \fn SDL_bool SDL_GetWindowWMInfo (SDL_WindowID windowID, SDL_SysWMinfo * info)
|
||||
*
|
||||
* \brief This function allows access to driver-dependent window information.
|
||||
*
|
||||
* \param windowID The window about which information is being requested
|
||||
* \param info This structure must be initialized with the SDL version, and is then filled in with information about the given window.
|
||||
*
|
||||
* \return SDL_TRUE if the function is implemented and the version member of the 'info' struct is valid, SDL_FALSE otherwise.
|
||||
*
|
||||
* You typically use this function like this:
|
||||
* \code
|
||||
* SDL_SysWMInfo info;
|
||||
* SDL_VERSION(&info.version);
|
||||
* if ( SDL_GetWindowWMInfo(&info) ) { ... }
|
||||
* \endcode
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_WindowID windowID,
|
||||
SDL_SysWMinfo * info);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_syswm_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_syswm.h
|
||||
*
|
||||
* Include file for SDL custom system window manager hooks.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_syswm_h
|
||||
#define _SDL_syswm_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_version.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \file SDL_syswm.h
|
||||
*
|
||||
* Your application has access to a special type of event ::SDL_SYSWMEVENT,
|
||||
* which contains window-manager specific information and arrives whenever
|
||||
* an unhandled window event occurs. This event is ignored by default, but
|
||||
* you can enable it with SDL_EventState().
|
||||
*/
|
||||
#ifdef SDL_PROTOTYPES_ONLY
|
||||
struct SDL_SysWMinfo;
|
||||
#else
|
||||
|
||||
/* This is the structure for custom window manager events */
|
||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
/* conflicts with Quickdraw.h */
|
||||
#define Cursor X11Cursor
|
||||
#endif
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
/* matches the re-define above */
|
||||
#undef Cursor
|
||||
#endif
|
||||
|
||||
/**
|
||||
* These are the various supported subsystems under UNIX.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SDL_SYSWM_X11
|
||||
} SDL_SYSWM_TYPE;
|
||||
|
||||
/**
|
||||
* The UNIX custom event structure.
|
||||
*/
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
SDL_SYSWM_TYPE subsystem;
|
||||
union
|
||||
{
|
||||
XEvent xevent;
|
||||
} event;
|
||||
};
|
||||
|
||||
/**
|
||||
* The UNIX custom window manager information structure.
|
||||
*
|
||||
* When this structure is returned, it holds information about which
|
||||
* low level system it is using, and will be one of SDL_SYSWM_TYPE.
|
||||
*/
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
SDL_SYSWM_TYPE subsystem;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Display *display; /**< The X11 display */
|
||||
Window window; /**< The X11 display window */
|
||||
/**
|
||||
* These locking functions should be called around
|
||||
* any X11 functions using the display variable.
|
||||
* They lock the event thread, so should not be
|
||||
* called around event functions or from event filters.
|
||||
*/
|
||||
/*@{*/
|
||||
void (*lock_func) (void);
|
||||
void (*unlock_func) (void);
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Introduced in SDL 1.0.2.
|
||||
*/
|
||||
/*@{*/
|
||||
Window fswindow; /**< The X11 fullscreen window */
|
||||
Window wmwindow; /**< The X11 managed input window */
|
||||
/*@}*/
|
||||
} x11;
|
||||
} info;
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
/**
|
||||
* The windows custom event structure.
|
||||
*/
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
HWND hwnd; /**< The window for the message */
|
||||
UINT msg; /**< The type of message */
|
||||
WPARAM wParam; /**< WORD message parameter */
|
||||
LPARAM lParam; /**< LONG message parameter */
|
||||
};
|
||||
|
||||
/**
|
||||
* The windows custom window manager information structure.
|
||||
*/
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
HWND window; /**< The Win32 display window */
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_RISCOS)
|
||||
|
||||
/**
|
||||
* RISC OS custom event structure.
|
||||
*/
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int eventCode; /**< The window for the message */
|
||||
int pollBlock[64];
|
||||
};
|
||||
|
||||
/**
|
||||
* The RISC OS custom window manager information structure.
|
||||
*/
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
int wimpVersion; /**< Wimp version running under */
|
||||
int taskHandle; /**< The RISC OS task handle */
|
||||
int window; /**< The RISC OS display window */
|
||||
};
|
||||
|
||||
#elif defined(SDL_VIDEO_DRIVER_PHOTON) || defined(SDL_VIDEO_DRIVER_QNXGF)
|
||||
#include <sys/neutrino.h>
|
||||
#if defined(SDL_VIDEO_OPENGL_ES)
|
||||
#include <gf/gf.h>
|
||||
#endif /* SDL_VIDEO_OPENGL_ES */
|
||||
#include <Ph.h>
|
||||
|
||||
/**
|
||||
* The QNX custom event structure.
|
||||
*/
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
/**
|
||||
* The QNX Photon custom window manager information structure.
|
||||
*/
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* The generic custom event structure.
|
||||
*/
|
||||
struct SDL_SysWMmsg
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
/**
|
||||
* The generic custom window manager information structure.
|
||||
*/
|
||||
struct SDL_SysWMinfo
|
||||
{
|
||||
SDL_version version;
|
||||
int data;
|
||||
};
|
||||
|
||||
#endif /* video driver type */
|
||||
|
||||
#endif /* SDL_PROTOTYPES_ONLY */
|
||||
|
||||
typedef struct SDL_SysWMinfo SDL_SysWMinfo;
|
||||
|
||||
/* Function prototypes */
|
||||
/**
|
||||
* \brief This function allows access to driver-dependent window information.
|
||||
*
|
||||
* \param windowID The window about which information is being requested
|
||||
* \param info This structure must be initialized with the SDL version, and is
|
||||
* then filled in with information about the given window.
|
||||
*
|
||||
* \return SDL_TRUE if the function is implemented and the version member of
|
||||
* the \c info struct is valid, SDL_FALSE otherwise.
|
||||
*
|
||||
* You typically use this function like this:
|
||||
* \code
|
||||
* SDL_SysWMInfo info;
|
||||
* SDL_VERSION(&info.version);
|
||||
* if ( SDL_GetWindowWMInfo(&info) ) { ... }
|
||||
* \endcode
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_WindowID windowID,
|
||||
SDL_SysWMinfo * info);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_syswm_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,144 +1,170 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_thread_h
|
||||
#define _SDL_thread_h
|
||||
|
||||
/**
|
||||
* \file SDL_thread.h
|
||||
*
|
||||
* Header for the SDL thread management routines
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
/* Thread synchronization primitives */
|
||||
#include "SDL_mutex.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* The SDL thread structure, defined in SDL_thread.c */
|
||||
struct SDL_Thread;
|
||||
typedef struct SDL_Thread SDL_Thread;
|
||||
|
||||
/* Create a thread */
|
||||
#if (defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)
|
||||
/*
|
||||
We compile SDL into a DLL on OS/2. This means, that it's the DLL which
|
||||
creates a new thread for the calling process with the SDL_CreateThread()
|
||||
API. There is a problem with this, that only the RTL of the SDL.DLL will
|
||||
be initialized for those threads, and not the RTL of the calling application!
|
||||
To solve this, we make a little hack here.
|
||||
We'll always use the caller's _beginthread() and _endthread() APIs to
|
||||
start a new thread. This way, if it's the SDL.DLL which uses this API,
|
||||
then the RTL of SDL.DLL will be used to create the new thread, and if it's
|
||||
the application, then the RTL of the application will be used.
|
||||
So, in short:
|
||||
Always use the _beginthread() and _endthread() of the calling runtime library!
|
||||
*/
|
||||
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
#ifndef _WIN32_WCE
|
||||
#include <process.h> /* This has _beginthread() and _endthread() defined! */
|
||||
#endif
|
||||
|
||||
#ifdef __OS2__
|
||||
typedef int (*pfnSDL_CurrentBeginThread) (void (*func) (void *), void *,
|
||||
unsigned, void *arg);
|
||||
typedef void (*pfnSDL_CurrentEndThread) (void);
|
||||
#elif __GNUC__
|
||||
typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned
|
||||
(__stdcall *
|
||||
func) (void *),
|
||||
void *arg,
|
||||
unsigned,
|
||||
unsigned
|
||||
*threadID);
|
||||
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
||||
#else
|
||||
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned (__stdcall *
|
||||
func) (void
|
||||
*),
|
||||
void *arg, unsigned,
|
||||
unsigned *threadID);
|
||||
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
||||
#endif
|
||||
|
||||
extern DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * f) (void *), void *data,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread);
|
||||
|
||||
#ifdef __OS2__
|
||||
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
|
||||
#elif defined(_WIN32_WCE)
|
||||
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
|
||||
#else
|
||||
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
|
||||
#endif
|
||||
#else
|
||||
extern DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *), void *data);
|
||||
#endif
|
||||
|
||||
/* Get the 32-bit thread identifier for the current thread */
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
|
||||
|
||||
/* Get the 32-bit thread identifier for the specified thread,
|
||||
equivalent to SDL_ThreadID() if the specified thread is NULL.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread * thread);
|
||||
|
||||
/* Wait for a thread to finish.
|
||||
The return code for the thread function is placed in the area
|
||||
pointed to by 'status', if 'status' is not NULL.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
|
||||
|
||||
/* This function is here for binary compatibility with legacy apps, but
|
||||
in SDL 1.3 and later, it's a no-op. You cannot forcibly kill a thread
|
||||
in a safe manner on many platforms. You should instead find a way to
|
||||
alert your thread that it is time to terminate, and then have it gracefully
|
||||
exit on its own. Do not ever call this function!
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread * thread);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_thread_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_thread_h
|
||||
#define _SDL_thread_h
|
||||
|
||||
/**
|
||||
* \file SDL_thread.h
|
||||
*
|
||||
* Header for the SDL thread management routines.
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
/* Thread synchronization primitives */
|
||||
#include "SDL_mutex.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* The SDL thread structure, defined in SDL_thread.c */
|
||||
struct SDL_Thread;
|
||||
typedef struct SDL_Thread SDL_Thread;
|
||||
|
||||
#if defined(__WIN32__) && !defined(HAVE_LIBC)
|
||||
/**
|
||||
* \file SDL_thread.h
|
||||
*
|
||||
* We compile SDL into a DLL. This means, that it's the DLL which
|
||||
* creates a new thread for the calling process with the SDL_CreateThread()
|
||||
* API. There is a problem with this, that only the RTL of the SDL.DLL will
|
||||
* be initialized for those threads, and not the RTL of the calling
|
||||
* application!
|
||||
*
|
||||
* To solve this, we make a little hack here.
|
||||
*
|
||||
* We'll always use the caller's _beginthread() and _endthread() APIs to
|
||||
* start a new thread. This way, if it's the SDL.DLL which uses this API,
|
||||
* then the RTL of SDL.DLL will be used to create the new thread, and if it's
|
||||
* the application, then the RTL of the application will be used.
|
||||
*
|
||||
* So, in short:
|
||||
* Always use the _beginthread() and _endthread() of the calling runtime
|
||||
* library!
|
||||
*/
|
||||
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
#ifndef _WIN32_WCE
|
||||
#include <process.h> /* This has _beginthread() and _endthread() defined! */
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned
|
||||
(__stdcall *
|
||||
func) (void *),
|
||||
void *arg,
|
||||
unsigned,
|
||||
unsigned
|
||||
*threadID);
|
||||
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
||||
#else
|
||||
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned (__stdcall *
|
||||
func) (void
|
||||
*),
|
||||
void *arg, unsigned,
|
||||
unsigned *threadID);
|
||||
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Create a thread.
|
||||
*/
|
||||
extern DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * f) (void *), void *data,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread);
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
|
||||
/**
|
||||
* Create a thread.
|
||||
*/
|
||||
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* Create a thread.
|
||||
*/
|
||||
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
|
||||
|
||||
#endif
|
||||
#else
|
||||
|
||||
/**
|
||||
* Create a thread.
|
||||
*/
|
||||
extern DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *), void *data);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Get the 32-bit thread identifier for the current thread.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
|
||||
|
||||
/**
|
||||
* Get the 32-bit thread identifier for the specified thread.
|
||||
*
|
||||
* Equivalent to SDL_ThreadID() if the specified thread is NULL.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread * thread);
|
||||
|
||||
/**
|
||||
* Wait for a thread to finish.
|
||||
*
|
||||
* The return code for the thread function is placed in the area
|
||||
* pointed to by \c status, if \c status is not NULL.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
|
||||
|
||||
/**
|
||||
* \deprecated This function is here for binary compatibility with legacy apps,
|
||||
* but in SDL 1.3 and later, it's a no-op.
|
||||
*
|
||||
* You cannot forcibly kill a thread in a safe manner on many platforms. You
|
||||
* should instead find a way to alert your thread that it is time to terminate,
|
||||
* and then have it gracefully exit on its own. Do not ever call this function!
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread * thread);
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_thread_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,128 +1,153 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_timer_h
|
||||
#define _SDL_timer_h
|
||||
|
||||
/**
|
||||
* \file SDL_timer.h
|
||||
*
|
||||
* Header for the SDL time management routines
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* This is the OS scheduler timeslice, in milliseconds */
|
||||
#define SDL_TIMESLICE 10
|
||||
|
||||
/* This is the maximum resolution of the SDL timer on all platforms */
|
||||
#define TIMER_RESOLUTION 10 /* Experimentally determined */
|
||||
|
||||
/* Get the number of milliseconds since the SDL library initialization.
|
||||
* Note that this value wraps if the program runs for more than ~49 days.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
|
||||
|
||||
/* Wait a specified number of milliseconds before returning */
|
||||
extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
|
||||
|
||||
/* Function prototype for the timer callback function */
|
||||
typedef Uint32(SDLCALL * SDL_TimerCallback) (Uint32 interval);
|
||||
|
||||
/* Set a callback to run after the specified number of milliseconds has
|
||||
* elapsed. The callback function is passed the current timer interval
|
||||
* and returns the next timer interval. If the returned value is the
|
||||
* same as the one passed in, the periodic alarm continues, otherwise a
|
||||
* new alarm is scheduled. If the callback returns 0, the periodic alarm
|
||||
* is cancelled.
|
||||
*
|
||||
* To cancel a currently running timer, call SDL_SetTimer(0, NULL);
|
||||
*
|
||||
* The timer callback function may run in a different thread than your
|
||||
* main code, and so shouldn't call any functions from within itself.
|
||||
*
|
||||
* The maximum resolution of this timer is 10 ms, which means that if
|
||||
* you request a 16 ms timer, your callback will run approximately 20 ms
|
||||
* later on an unloaded system. If you wanted to set a flag signaling
|
||||
* a frame update at 30 frames per second (every 33 ms), you might set a
|
||||
* timer for 30 ms:
|
||||
* SDL_SetTimer((33/10)*10, flag_update);
|
||||
*
|
||||
* If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init().
|
||||
*
|
||||
* Under UNIX, you should not use raise or use SIGALRM and this function
|
||||
* in the same program, as it is implemented using setitimer(). You also
|
||||
* should not use this function in multi-threaded applications as signals
|
||||
* to multi-threaded apps have undefined behavior in some implementations.
|
||||
*
|
||||
* This function returns 0 if successful, or -1 if there was an error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval,
|
||||
SDL_TimerCallback callback);
|
||||
|
||||
/* New timer API, supports multiple timers
|
||||
* Written by Stephane Peter <megastep@lokigames.com>
|
||||
*/
|
||||
|
||||
/* Function prototype for the new timer callback function.
|
||||
* The callback function is passed the current timer interval and returns
|
||||
* the next timer interval. If the returned value is the same as the one
|
||||
* passed in, the periodic alarm continues, otherwise a new alarm is
|
||||
* scheduled. If the callback returns 0, the periodic alarm is cancelled.
|
||||
*/
|
||||
typedef Uint32(SDLCALL * SDL_NewTimerCallback) (Uint32 interval, void *param);
|
||||
|
||||
/* Definition of the timer ID type */
|
||||
typedef struct _SDL_TimerID *SDL_TimerID;
|
||||
|
||||
/* Add a new timer to the pool of timers already running.
|
||||
Returns a timer ID, or NULL when an error occurs.
|
||||
*/
|
||||
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
|
||||
SDL_NewTimerCallback
|
||||
callback, void *param);
|
||||
|
||||
/* Remove one of the multiple timers knowing its ID.
|
||||
* Returns a boolean value indicating success.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_timer_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
#ifndef _SDL_timer_h
|
||||
#define _SDL_timer_h
|
||||
|
||||
/**
|
||||
* \file SDL_timer.h
|
||||
*
|
||||
* Header for the SDL time management routines.
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is the OS scheduler timeslice, in milliseconds.
|
||||
*/
|
||||
#define SDL_TIMESLICE 10
|
||||
|
||||
/**
|
||||
* This is the maximum resolution of the SDL timer on all platforms.
|
||||
*/
|
||||
#define TIMER_RESOLUTION 10 /**< Experimentally determined */
|
||||
|
||||
/**
|
||||
* Get the number of milliseconds since the SDL library initialization.
|
||||
*
|
||||
* Note that this value wraps if the program runs for more than ~49 days.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
|
||||
|
||||
/**
|
||||
* Wait a specified number of milliseconds before returning.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
|
||||
|
||||
/**
|
||||
* Function prototype for the timer callback function.
|
||||
*/
|
||||
typedef Uint32(SDLCALL * SDL_TimerCallback) (Uint32 interval);
|
||||
|
||||
/**
|
||||
* Set a callback to run after the specified number of milliseconds has
|
||||
* elapsed. The callback function is passed the current timer interval
|
||||
* and returns the next timer interval. If the returned value is the
|
||||
* same as the one passed in, the periodic alarm continues, otherwise a
|
||||
* new alarm is scheduled. If the callback returns 0, the periodic alarm
|
||||
* is cancelled.
|
||||
*
|
||||
* To cancel a currently running timer, call
|
||||
* \code SDL_SetTimer(0, NULL); \endcode
|
||||
*
|
||||
* The timer callback function may run in a different thread than your
|
||||
* main code, and so shouldn't call any functions from within itself.
|
||||
*
|
||||
* The maximum resolution of this timer is 10 ms, which means that if
|
||||
* you request a 16 ms timer, your callback will run approximately 20 ms
|
||||
* later on an unloaded system. If you wanted to set a flag signaling
|
||||
* a frame update at 30 frames per second (every 33 ms), you might set a
|
||||
* timer for 30 ms:
|
||||
* \code
|
||||
* SDL_SetTimer((33/10)*10, flag_update);
|
||||
* \endcode
|
||||
*
|
||||
* If you use this function, you need to pass ::SDL_INIT_TIMER to SDL_Init().
|
||||
*
|
||||
* Under UNIX, you should not use raise or use SIGALRM and this function
|
||||
* in the same program, as it is implemented using setitimer(). You also
|
||||
* should not use this function in multi-threaded applications as signals
|
||||
* to multi-threaded apps have undefined behavior in some implementations.
|
||||
*
|
||||
* \return 0 if successful, or -1 if there was an error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval,
|
||||
SDL_TimerCallback callback);
|
||||
|
||||
/**
|
||||
* \name Peter timers
|
||||
* New timer API, supports multiple timers
|
||||
* Written by Stephane Peter <megastep@lokigames.com>
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* Function prototype for the new timer callback function.
|
||||
*
|
||||
* The callback function is passed the current timer interval and returns
|
||||
* the next timer interval. If the returned value is the same as the one
|
||||
* passed in, the periodic alarm continues, otherwise a new alarm is
|
||||
* scheduled. If the callback returns 0, the periodic alarm is cancelled.
|
||||
*/
|
||||
typedef Uint32(SDLCALL * SDL_NewTimerCallback) (Uint32 interval, void *param);
|
||||
|
||||
/**
|
||||
* Definition of the timer ID type.
|
||||
*/
|
||||
typedef struct _SDL_TimerID *SDL_TimerID;
|
||||
|
||||
/**
|
||||
* Add a new timer to the pool of timers already running.
|
||||
* \return A timer ID, or NULL when an error occurs.
|
||||
*/
|
||||
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
|
||||
SDL_NewTimerCallback
|
||||
callback, void *param);
|
||||
|
||||
/**
|
||||
* Remove one of the multiple timers knowing its ID.
|
||||
* \return A boolean value indicating success or failure.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t);
|
||||
|
||||
/*@}*//*Peter timers*/
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_timer_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/* DEPRECATED */
|
||||
#include "SDL_stdinc.h"
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_types.h
|
||||
*
|
||||
* \deprecated
|
||||
*/
|
||||
|
||||
/* DEPRECATED */
|
||||
#include "SDL_stdinc.h"
|
||||
|
|
|
@ -1,151 +1,155 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_version.h
|
||||
*
|
||||
* This header defines the current SDL version
|
||||
*/
|
||||
|
||||
#ifndef _SDL_version_h
|
||||
#define _SDL_version_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_revision.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \struct SDL_version
|
||||
* \brief Information the version of SDL in use.
|
||||
*
|
||||
* Represents the library's version as three levels: major revision
|
||||
* (increments with massive changes, additions, and enhancements),
|
||||
* minor revision (increments with backwards-compatible changes to the
|
||||
* major revision), and patchlevel (increments with fixes to the minor
|
||||
* revision).
|
||||
*
|
||||
* \sa SDL_VERSION
|
||||
* \sa SDL_GetVersion
|
||||
*/
|
||||
typedef struct SDL_version
|
||||
{
|
||||
Uint8 major; /**< major version */
|
||||
Uint8 minor; /**< minor version */
|
||||
Uint8 patch; /**< update version */
|
||||
} SDL_version;
|
||||
|
||||
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
|
||||
*/
|
||||
#define SDL_MAJOR_VERSION 1
|
||||
#define SDL_MINOR_VERSION 3
|
||||
#define SDL_PATCHLEVEL 0
|
||||
|
||||
/**
|
||||
* \def SDL_VERSION(x)
|
||||
* \brief Macro to determine SDL version program was compiled against.
|
||||
*
|
||||
* This macro fills in a SDL_version structure with the version of the
|
||||
* library you compiled against. This is determined by what header the
|
||||
* compiler uses. Note that if you dynamically linked the library, you might
|
||||
* have a slightly newer or older version at runtime. That version can be
|
||||
* determined with SDL_GetVersion(), which, unlike SDL_VERSION,
|
||||
* is not a macro.
|
||||
*
|
||||
* \param x A pointer to a SDL_version struct to initialize.
|
||||
*
|
||||
* \sa SDL_version
|
||||
* \sa SDL_GetVersion
|
||||
*/
|
||||
#define SDL_VERSION(x) \
|
||||
{ \
|
||||
(x)->major = SDL_MAJOR_VERSION; \
|
||||
(x)->minor = SDL_MINOR_VERSION; \
|
||||
(x)->patch = SDL_PATCHLEVEL; \
|
||||
}
|
||||
|
||||
/* This macro turns the version numbers into a numeric value:
|
||||
(1,2,3) -> (1203)
|
||||
This assumes that there will never be more than 100 patchlevels
|
||||
*/
|
||||
#define SDL_VERSIONNUM(X, Y, Z) \
|
||||
((X)*1000 + (Y)*100 + (Z))
|
||||
|
||||
/* This is the version number macro for the current SDL version */
|
||||
#define SDL_COMPILEDVERSION \
|
||||
SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
|
||||
|
||||
/* This macro will evaluate to true if compiled with SDL at least X.Y.Z */
|
||||
#define SDL_VERSION_ATLEAST(X, Y, Z) \
|
||||
(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
|
||||
|
||||
/**
|
||||
* \fn void SDL_GetVersion(SDL_version *ver)
|
||||
* \brief Get the version of SDL that is linked against your program.
|
||||
*
|
||||
* If you are using a shared library (DLL) version of SDL, then it is
|
||||
* possible that it will be different than the version you compiled against.
|
||||
*
|
||||
* This is a real function; the macro SDL_VERSION tells you what version
|
||||
* of SDL you compiled against:
|
||||
*
|
||||
* \code
|
||||
* SDL_version compiled;
|
||||
* SDL_version linked;
|
||||
*
|
||||
* SDL_VERSION(&compiled);
|
||||
* SDL_GetVersion(&linked);
|
||||
* printf("We compiled against SDL version %d.%d.%d ...\n",
|
||||
* compiled.major, compiled.minor, compiled.patch);
|
||||
* printf("But we linked against SDL version %d.%d.%d.\n",
|
||||
* linked.major, linked.minor, linked.patch);
|
||||
* \endcode
|
||||
*
|
||||
* This function may be called safely at any time, even before SDL_Init().
|
||||
*
|
||||
* \sa SDL_VERSION
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
|
||||
|
||||
/**
|
||||
* \fn int SDL_GetRevision(void)
|
||||
* \brief Get the code revision of SDL that is linked against your program.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetRevision(void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_version_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_version.h
|
||||
*
|
||||
* This header defines the current SDL version.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_version_h
|
||||
#define _SDL_version_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_revision.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Information the version of SDL in use.
|
||||
*
|
||||
* Represents the library's version as three levels: major revision
|
||||
* (increments with massive changes, additions, and enhancements),
|
||||
* minor revision (increments with backwards-compatible changes to the
|
||||
* major revision), and patchlevel (increments with fixes to the minor
|
||||
* revision).
|
||||
*
|
||||
* \sa SDL_VERSION
|
||||
* \sa SDL_GetVersion
|
||||
*/
|
||||
typedef struct SDL_version
|
||||
{
|
||||
Uint8 major; /**< major version */
|
||||
Uint8 minor; /**< minor version */
|
||||
Uint8 patch; /**< update version */
|
||||
} SDL_version;
|
||||
|
||||
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
|
||||
*/
|
||||
#define SDL_MAJOR_VERSION 1
|
||||
#define SDL_MINOR_VERSION 3
|
||||
#define SDL_PATCHLEVEL 0
|
||||
|
||||
/**
|
||||
* \brief Macro to determine SDL version program was compiled against.
|
||||
*
|
||||
* This macro fills in a SDL_version structure with the version of the
|
||||
* library you compiled against. This is determined by what header the
|
||||
* compiler uses. Note that if you dynamically linked the library, you might
|
||||
* have a slightly newer or older version at runtime. That version can be
|
||||
* determined with SDL_GetVersion(), which, unlike SDL_VERSION(),
|
||||
* is not a macro.
|
||||
*
|
||||
* \param x A pointer to a SDL_version struct to initialize.
|
||||
*
|
||||
* \sa SDL_version
|
||||
* \sa SDL_GetVersion
|
||||
*/
|
||||
#define SDL_VERSION(x) \
|
||||
{ \
|
||||
(x)->major = SDL_MAJOR_VERSION; \
|
||||
(x)->minor = SDL_MINOR_VERSION; \
|
||||
(x)->patch = SDL_PATCHLEVEL; \
|
||||
}
|
||||
|
||||
/**
|
||||
* This macro turns the version numbers into a numeric value:
|
||||
* \verbatim
|
||||
(1,2,3) -> (1203)
|
||||
\endverbatim
|
||||
*
|
||||
* This assumes that there will never be more than 100 patchlevels.
|
||||
*/
|
||||
#define SDL_VERSIONNUM(X, Y, Z) \
|
||||
((X)*1000 + (Y)*100 + (Z))
|
||||
|
||||
/**
|
||||
* This is the version number macro for the current SDL version.
|
||||
*/
|
||||
#define SDL_COMPILEDVERSION \
|
||||
SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
|
||||
|
||||
/**
|
||||
* This macro will evaluate to true if compiled with SDL at least X.Y.Z.
|
||||
*/
|
||||
#define SDL_VERSION_ATLEAST(X, Y, Z) \
|
||||
(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
|
||||
|
||||
/**
|
||||
* \brief Get the version of SDL that is linked against your program.
|
||||
*
|
||||
* If you are using a shared library (DLL) version of SDL, then it is
|
||||
* possible that it will be different than the version you compiled against.
|
||||
*
|
||||
* This is a real function; the macro SDL_VERSION() tells you what version
|
||||
* of SDL you compiled against:
|
||||
*
|
||||
* \code
|
||||
* SDL_version compiled;
|
||||
* SDL_version linked;
|
||||
*
|
||||
* SDL_VERSION(&compiled);
|
||||
* SDL_GetVersion(&linked);
|
||||
* printf("We compiled against SDL version %d.%d.%d ...\n",
|
||||
* compiled.major, compiled.minor, compiled.patch);
|
||||
* printf("But we linked against SDL version %d.%d.%d.\n",
|
||||
* linked.major, linked.minor, linked.patch);
|
||||
* \endcode
|
||||
*
|
||||
* This function may be called safely at any time, even before SDL_Init().
|
||||
*
|
||||
* \sa SDL_VERSION
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
|
||||
|
||||
/**
|
||||
* \brief Get the code revision of SDL that is linked against your program.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetRevision(void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_version_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,149 +1,136 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/* This file sets things up for C dynamic library function definitions,
|
||||
static inlined functions, and structures aligned at 4-byte alignment.
|
||||
If you don't like ugly C preprocessor code, don't look at this file. :)
|
||||
*/
|
||||
|
||||
/* This shouldn't be nested -- included it around code only. */
|
||||
#ifdef _begin_code_h
|
||||
#error Nested inclusion of begin_code.h
|
||||
#endif
|
||||
#define _begin_code_h
|
||||
|
||||
/* Some compilers use a special export keyword */
|
||||
#ifndef DECLSPEC
|
||||
# if defined(__BEOS__)
|
||||
# if defined(__GNUC__)
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# else
|
||||
# define DECLSPEC __declspec(export)
|
||||
# endif
|
||||
# elif defined(__WIN32__)
|
||||
# ifdef __BORLANDC__
|
||||
# ifdef BUILD_SDL
|
||||
# define DECLSPEC
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# endif
|
||||
# elif defined(__OS2__)
|
||||
# ifdef __WATCOMC__
|
||||
# ifdef BUILD_SDL
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# else
|
||||
# define DECLSPEC
|
||||
# endif
|
||||
# else
|
||||
# define DECLSPEC
|
||||
# endif
|
||||
# else
|
||||
# if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define DECLSPEC __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define DECLSPEC
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* By default SDL uses the C calling convention */
|
||||
#ifndef SDLCALL
|
||||
#if defined(__WIN32__) && !defined(__GNUC__)
|
||||
#define SDLCALL __cdecl
|
||||
#else
|
||||
#ifdef __OS2__
|
||||
/* But on OS/2, we use the _System calling convention */
|
||||
/* to be compatible with every compiler */
|
||||
#define SDLCALL _System
|
||||
#else
|
||||
#define SDLCALL
|
||||
#endif
|
||||
#endif
|
||||
#endif /* SDLCALL */
|
||||
|
||||
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
|
||||
#ifdef __SYMBIAN32__
|
||||
#undef DECLSPEC
|
||||
#define DECLSPEC
|
||||
#endif /* __SYMBIAN32__ */
|
||||
|
||||
/* Force structure packing at 4 byte alignment.
|
||||
This is necessary if the header is included in code which has structure
|
||||
packing set to an alternate value, say for loading structures from disk.
|
||||
The packing is reset to the previous value in close_code.h
|
||||
*/
|
||||
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4103)
|
||||
#endif
|
||||
#ifdef __BORLANDC__
|
||||
#pragma nopackwarning
|
||||
#endif
|
||||
#pragma pack(push,4)
|
||||
#endif /* Compiler needs structure packing set */
|
||||
|
||||
/* Set up compiler-specific options for inlining functions */
|
||||
#ifndef SDL_INLINE_OKAY
|
||||
#ifdef __GNUC__
|
||||
#define SDL_INLINE_OKAY
|
||||
#else
|
||||
/* Add any special compiler-specific cases here */
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__) || \
|
||||
defined(__DMC__) || defined(__SC__) || \
|
||||
defined(__WATCOMC__) || defined(__LCC__) || \
|
||||
defined(__DECC)
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#define SDL_INLINE_OKAY
|
||||
#else
|
||||
#if !defined(__MRC__) && !defined(_SGI_SOURCE)
|
||||
#ifndef __inline__
|
||||
#define __inline__ inline
|
||||
#endif
|
||||
#define SDL_INLINE_OKAY
|
||||
#endif /* Not a funky compiler */
|
||||
#endif /* Visual C++ */
|
||||
#endif /* GNU C */
|
||||
#endif /* SDL_INLINE_OKAY */
|
||||
|
||||
/* If inlining isn't supported, remove "__inline__", turning static
|
||||
inlined functions into static functions (resulting in code bloat
|
||||
in all files which include the offending header files)
|
||||
*/
|
||||
#ifndef SDL_INLINE_OKAY
|
||||
#define __inline__
|
||||
#endif
|
||||
|
||||
/* Apparently this is needed by several Windows compilers */
|
||||
#if !defined(__MACH__)
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
#endif /* NULL */
|
||||
#endif /* ! Mac OS X - breaks precompiled headers */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file begin_code.h
|
||||
*
|
||||
* This file sets things up for C dynamic library function definitions,
|
||||
* static inlined functions, and structures aligned at 4-byte alignment.
|
||||
* If you don't like ugly C preprocessor code, don't look at this file. :)
|
||||
*/
|
||||
|
||||
/* This shouldn't be nested -- included it around code only. */
|
||||
#ifdef _begin_code_h
|
||||
#error Nested inclusion of begin_code.h
|
||||
#endif
|
||||
#define _begin_code_h
|
||||
|
||||
/* Some compilers use a special export keyword */
|
||||
#ifndef DECLSPEC
|
||||
# if defined(__BEOS__) || defined(__HAIKU__)
|
||||
# if defined(__GNUC__)
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# else
|
||||
# define DECLSPEC __declspec(export)
|
||||
# endif
|
||||
# elif defined(__WIN32__)
|
||||
# ifdef __BORLANDC__
|
||||
# ifdef BUILD_SDL
|
||||
# define DECLSPEC
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# endif
|
||||
# else
|
||||
# if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define DECLSPEC __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define DECLSPEC
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* By default SDL uses the C calling convention */
|
||||
#ifndef SDLCALL
|
||||
#if defined(__WIN32__) && !defined(__GNUC__)
|
||||
#define SDLCALL __cdecl
|
||||
#else
|
||||
#define SDLCALL
|
||||
#endif
|
||||
#endif /* SDLCALL */
|
||||
|
||||
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
|
||||
#ifdef __SYMBIAN32__
|
||||
#undef DECLSPEC
|
||||
#define DECLSPEC
|
||||
#endif /* __SYMBIAN32__ */
|
||||
|
||||
/* Force structure packing at 4 byte alignment.
|
||||
This is necessary if the header is included in code which has structure
|
||||
packing set to an alternate value, say for loading structures from disk.
|
||||
The packing is reset to the previous value in close_code.h
|
||||
*/
|
||||
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4103)
|
||||
#endif
|
||||
#ifdef __BORLANDC__
|
||||
#pragma nopackwarning
|
||||
#endif
|
||||
#pragma pack(push,4)
|
||||
#endif /* Compiler needs structure packing set */
|
||||
|
||||
/* Set up compiler-specific options for inlining functions */
|
||||
#ifndef SDL_INLINE_OKAY
|
||||
#ifdef __GNUC__
|
||||
#define SDL_INLINE_OKAY
|
||||
#else
|
||||
/* Add any special compiler-specific cases here */
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__) || \
|
||||
defined(__DMC__) || defined(__SC__) || \
|
||||
defined(__WATCOMC__) || defined(__LCC__) || \
|
||||
defined(__DECC)
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#define SDL_INLINE_OKAY
|
||||
#else
|
||||
#if !defined(__MRC__) && !defined(_SGI_SOURCE)
|
||||
#ifndef __inline__
|
||||
#define __inline__ inline
|
||||
#endif
|
||||
#define SDL_INLINE_OKAY
|
||||
#endif /* Not a funky compiler */
|
||||
#endif /* Visual C++ */
|
||||
#endif /* GNU C */
|
||||
#endif /* SDL_INLINE_OKAY */
|
||||
|
||||
/* If inlining isn't supported, remove "__inline__", turning static
|
||||
inlined functions into static functions (resulting in code bloat
|
||||
in all files which include the offending header files)
|
||||
*/
|
||||
#ifndef SDL_INLINE_OKAY
|
||||
#define __inline__
|
||||
#endif
|
||||
|
||||
/* Apparently this is needed by several Windows compilers */
|
||||
#if !defined(__MACH__)
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
#endif /* NULL */
|
||||
#endif /* ! Mac OS X - breaks precompiled headers */
|
||||
|
|
|
@ -1,35 +1,38 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/* This file reverses the effects of begin_code.h and should be included
|
||||
after you finish any function and structure declarations in your headers
|
||||
*/
|
||||
|
||||
#undef _begin_code_h
|
||||
|
||||
/* Reset structure packing at previous byte alignment */
|
||||
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__) || defined(__BORLANDC__)
|
||||
#ifdef __BORLANDC__
|
||||
#pragma nopackwarning
|
||||
#endif
|
||||
#pragma pack(pop)
|
||||
#endif /* Compiler needs structure packing set */
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file close_code.h
|
||||
*
|
||||
* This file reverses the effects of begin_code.h and should be included
|
||||
* after you finish any function and structure declarations in your headers
|
||||
*/
|
||||
|
||||
#undef _begin_code_h
|
||||
|
||||
/* Reset structure packing at previous byte alignment */
|
||||
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__) || defined(__BORLANDC__)
|
||||
#ifdef __BORLANDC__
|
||||
#pragma nopackwarning
|
||||
#endif
|
||||
#pragma pack(pop)
|
||||
#endif /* Compiler needs structure packing set */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,360 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Initialization code for SDL */
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_fatal.h"
|
||||
#if !SDL_VIDEO_DISABLED
|
||||
#include "video/SDL_leaks.h"
|
||||
#endif
|
||||
|
||||
#if SDL_THREAD_PTH
|
||||
#include <pth.h>
|
||||
#endif
|
||||
|
||||
/* Initialization/Cleanup routines */
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
extern int SDL_JoystickInit(void);
|
||||
extern void SDL_JoystickQuit(void);
|
||||
#endif
|
||||
#if !SDL_HAPTIC_DISABLED
|
||||
extern int SDL_HapticInit(void);
|
||||
extern int SDL_HapticQuit(void);
|
||||
#endif
|
||||
#if !SDL_TIMERS_DISABLED
|
||||
extern void SDL_StartTicks(void);
|
||||
extern int SDL_TimerInit(void);
|
||||
extern void SDL_TimerQuit(void);
|
||||
#endif
|
||||
#if defined(__WIN32__)
|
||||
extern int SDL_HelperWindowCreate(void);
|
||||
extern int SDL_HelperWindowDestroy(void);
|
||||
#endif
|
||||
|
||||
/* The initialized subsystems */
|
||||
static Uint32 SDL_initialized = 0;
|
||||
static Uint32 ticks_started = 0;
|
||||
|
||||
#ifdef CHECK_LEAKS
|
||||
int surfaces_allocated = 0;
|
||||
#endif
|
||||
|
||||
int
|
||||
SDL_InitSubSystem(Uint32 flags)
|
||||
{
|
||||
#if !SDL_VIDEO_DISABLED
|
||||
/* Initialize the video/event subsystem */
|
||||
if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
|
||||
if (SDL_VideoInit(NULL, (flags & SDL_INIT_EVENTTHREAD)) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
SDL_initialized |= SDL_INIT_VIDEO;
|
||||
}
|
||||
#else
|
||||
if (flags & SDL_INIT_VIDEO) {
|
||||
SDL_SetError("SDL not built with video support");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !SDL_AUDIO_DISABLED
|
||||
/* Initialize the audio subsystem */
|
||||
if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) {
|
||||
if (SDL_AudioInit(NULL) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
SDL_initialized |= SDL_INIT_AUDIO;
|
||||
}
|
||||
#else
|
||||
if (flags & SDL_INIT_AUDIO) {
|
||||
SDL_SetError("SDL not built with audio support");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !SDL_TIMERS_DISABLED
|
||||
/* Initialize the timer subsystem */
|
||||
if (!ticks_started) {
|
||||
SDL_StartTicks();
|
||||
ticks_started = 1;
|
||||
}
|
||||
if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) {
|
||||
if (SDL_TimerInit() < 0) {
|
||||
return (-1);
|
||||
}
|
||||
SDL_initialized |= SDL_INIT_TIMER;
|
||||
}
|
||||
#else
|
||||
if (flags & SDL_INIT_TIMER) {
|
||||
SDL_SetError("SDL not built with timer support");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
/* Initialize the joystick subsystem */
|
||||
if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
|
||||
if (SDL_JoystickInit() < 0) {
|
||||
return (-1);
|
||||
}
|
||||
SDL_initialized |= SDL_INIT_JOYSTICK;
|
||||
}
|
||||
#else
|
||||
if (flags & SDL_INIT_JOYSTICK) {
|
||||
SDL_SetError("SDL not built with joystick support");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !SDL_HAPTIC_DISABLED
|
||||
/* Initialize the haptic subsystem */
|
||||
if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
|
||||
if (SDL_HapticInit() < 0) {
|
||||
return (-1);
|
||||
}
|
||||
SDL_initialized |= SDL_INIT_HAPTIC;
|
||||
}
|
||||
#else
|
||||
if (flags & SDL_INIT_HAPTIC) {
|
||||
SDL_SetError("SDL not built with haptic (force feedback) support");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_Init(Uint32 flags)
|
||||
{
|
||||
#if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
|
||||
if (!pth_init()) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clear the error message */
|
||||
SDL_ClearError();
|
||||
|
||||
#if defined(__WIN32__)
|
||||
if (SDL_HelperWindowCreate() < 0) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize the desired subsystems */
|
||||
if (SDL_InitSubSystem(flags) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Everything is initialized */
|
||||
if (!(flags & SDL_INIT_NOPARACHUTE)) {
|
||||
SDL_InstallParachute();
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_QuitSubSystem(Uint32 flags)
|
||||
{
|
||||
/* Shut down requested initialized subsystems */
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
|
||||
SDL_JoystickQuit();
|
||||
SDL_initialized &= ~SDL_INIT_JOYSTICK;
|
||||
}
|
||||
#endif
|
||||
#if !SDL_HAPTIC_DISABLED
|
||||
if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
|
||||
SDL_HapticQuit();
|
||||
SDL_initialized &= ~SDL_INIT_HAPTIC;
|
||||
}
|
||||
#endif
|
||||
#if !SDL_TIMERS_DISABLED
|
||||
if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
|
||||
SDL_TimerQuit();
|
||||
SDL_initialized &= ~SDL_INIT_TIMER;
|
||||
}
|
||||
#endif
|
||||
#if !SDL_AUDIO_DISABLED
|
||||
if ((flags & SDL_initialized & SDL_INIT_AUDIO)) {
|
||||
SDL_AudioQuit();
|
||||
SDL_initialized &= ~SDL_INIT_AUDIO;
|
||||
}
|
||||
#endif
|
||||
#if !SDL_VIDEO_DISABLED
|
||||
if ((flags & SDL_initialized & SDL_INIT_VIDEO)) {
|
||||
SDL_VideoQuit();
|
||||
SDL_initialized &= ~SDL_INIT_VIDEO;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_WasInit(Uint32 flags)
|
||||
{
|
||||
if (!flags) {
|
||||
flags = SDL_INIT_EVERYTHING;
|
||||
}
|
||||
return (SDL_initialized & flags);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Quit(void)
|
||||
{
|
||||
/* Quit all subsystems */
|
||||
#ifdef DEBUG_BUILD
|
||||
printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
#if defined(__WIN32__)
|
||||
SDL_HelperWindowDestroy();
|
||||
#endif
|
||||
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
|
||||
|
||||
#ifdef CHECK_LEAKS
|
||||
#ifdef DEBUG_BUILD
|
||||
printf("[SDL_Quit] : CHECK_LEAKS\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
/* Print the number of surfaces not freed */
|
||||
if (surfaces_allocated != 0) {
|
||||
fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n",
|
||||
surfaces_allocated);
|
||||
}
|
||||
#endif
|
||||
#ifdef DEBUG_BUILD
|
||||
printf("[SDL_Quit] : SDL_UninstallParachute()\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
/* Uninstall any parachute signal handlers */
|
||||
SDL_UninstallParachute();
|
||||
|
||||
#if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
|
||||
pth_kill();
|
||||
#endif
|
||||
#ifdef DEBUG_BUILD
|
||||
printf("[SDL_Quit] : Returning!\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* Get the library version number */
|
||||
void
|
||||
SDL_GetVersion(SDL_version * ver)
|
||||
{
|
||||
SDL_VERSION(ver);
|
||||
}
|
||||
|
||||
/* Get the library source revision */
|
||||
int
|
||||
SDL_GetRevision(void)
|
||||
{
|
||||
return SDL_REVISION;
|
||||
}
|
||||
|
||||
/* Get the name of the platform */
|
||||
const char *
|
||||
SDL_GetPlatform()
|
||||
{
|
||||
#if __AIX__
|
||||
return "AIX";
|
||||
#elif __HAIKU__
|
||||
/* Haiku must appear here before BeOS, since it also defines __BEOS__ */
|
||||
return "Haiku";
|
||||
#elif __BEOS__
|
||||
return "BeOS";
|
||||
#elif __BSDI__
|
||||
return "BSDI";
|
||||
#elif __DREAMCAST__
|
||||
return "Dreamcast";
|
||||
#elif __FREEBSD__
|
||||
return "FreeBSD";
|
||||
#elif __HPUX__
|
||||
return "HP-UX";
|
||||
#elif __IRIX__
|
||||
return "Irix";
|
||||
#elif __LINUX__
|
||||
return "Linux";
|
||||
#elif __MINT__
|
||||
return "Atari MiNT";
|
||||
#elif __MACOS__
|
||||
return "MacOS Classic";
|
||||
#elif __MACOSX__
|
||||
return "Mac OS X";
|
||||
#elif __NETBSD__
|
||||
return "NetBSD";
|
||||
#elif __OPENBSD__
|
||||
return "OpenBSD";
|
||||
#elif __OS2__
|
||||
return "OS/2";
|
||||
#elif __OSF__
|
||||
return "OSF/1";
|
||||
#elif __QNXNTO__
|
||||
return "QNX Neutrino";
|
||||
#elif __RISCOS__
|
||||
return "RISC OS";
|
||||
#elif __SOLARIS__
|
||||
return "Solaris";
|
||||
#elif __WIN32__
|
||||
#ifdef _WIN32_WCE
|
||||
return "Windows CE";
|
||||
#else
|
||||
return "Windows";
|
||||
#endif
|
||||
#elif __IPHONEOS__
|
||||
return "iPhone OS";
|
||||
#else
|
||||
return "Unknown (see SDL_platform.h)";
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__WIN32__)
|
||||
|
||||
#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
|
||||
/* Need to include DllMain() on Watcom C for some reason.. */
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
BOOL APIENTRY
|
||||
_DllMainCRTStartup(HANDLE hModule,
|
||||
DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* building DLL with Watcom C */
|
||||
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,259 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Simple error handling in SDL */
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_error_c.h"
|
||||
|
||||
/* Routine to get the thread-specific error variable */
|
||||
#if SDL_THREADS_DISABLED
|
||||
/* !!! FIXME: what does this comment mean? Victim of Search and Replace? */
|
||||
/* The SDL_arraysize(The ),default (non-thread-safe) global error variable */
|
||||
static SDL_error SDL_global_error;
|
||||
#define SDL_GetErrBuf() (&SDL_global_error)
|
||||
#else
|
||||
extern SDL_error *SDL_GetErrBuf(void);
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
|
||||
#define SDL_ERRBUFIZE 1024
|
||||
|
||||
/* Private functions */
|
||||
|
||||
static const char *
|
||||
SDL_LookupString(const char *key)
|
||||
{
|
||||
/* FIXME: Add code to lookup key in language string hash-table */
|
||||
return key;
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
|
||||
void
|
||||
SDL_SetError(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
SDL_error *error;
|
||||
|
||||
/* Copy in the key, mark error as valid */
|
||||
error = SDL_GetErrBuf();
|
||||
error->error = 1;
|
||||
SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
|
||||
|
||||
va_start(ap, fmt);
|
||||
error->argc = 0;
|
||||
while (*fmt) {
|
||||
if (*fmt++ == '%') {
|
||||
while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
|
||||
++fmt;
|
||||
}
|
||||
switch (*fmt++) {
|
||||
case 0: /* Malformed format string.. */
|
||||
--fmt;
|
||||
break;
|
||||
case 'c':
|
||||
case 'i':
|
||||
case 'd':
|
||||
case 'u':
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'X':
|
||||
error->args[error->argc++].value_i = va_arg(ap, int);
|
||||
break;
|
||||
case 'f':
|
||||
error->args[error->argc++].value_f = va_arg(ap, double);
|
||||
break;
|
||||
case 'p':
|
||||
error->args[error->argc++].value_ptr = va_arg(ap, void *);
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
int i = error->argc;
|
||||
const char *str = va_arg(ap, const char *);
|
||||
if (str == NULL)
|
||||
str = "(null)";
|
||||
SDL_strlcpy((char *) error->args[i].buf, str,
|
||||
ERR_MAX_STRLEN);
|
||||
error->argc++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (error->argc >= ERR_MAX_ARGS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
/* If we are in debug mode, print out an error message */
|
||||
#ifdef DEBUG_ERROR
|
||||
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This function has a bit more overhead than most error functions
|
||||
so that it supports internationalization and thread-safe errors.
|
||||
*/
|
||||
char *
|
||||
SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
|
||||
{
|
||||
SDL_error *error;
|
||||
|
||||
/* Clear the error string */
|
||||
*errstr = '\0';
|
||||
--maxlen;
|
||||
|
||||
/* Get the thread-safe error, and print it out */
|
||||
error = SDL_GetErrBuf();
|
||||
if (error->error) {
|
||||
const char *fmt;
|
||||
char *msg = errstr;
|
||||
int len;
|
||||
int argi;
|
||||
|
||||
fmt = SDL_LookupString(error->key);
|
||||
argi = 0;
|
||||
while (*fmt && (maxlen > 0)) {
|
||||
if (*fmt == '%') {
|
||||
char tmp[32], *spot = tmp;
|
||||
*spot++ = *fmt++;
|
||||
while ((*fmt == '.' || (*fmt >= '0' && *fmt <= '9'))
|
||||
&& spot < (tmp + SDL_arraysize(tmp) - 2)) {
|
||||
*spot++ = *fmt++;
|
||||
}
|
||||
*spot++ = *fmt++;
|
||||
*spot++ = '\0';
|
||||
switch (spot[-2]) {
|
||||
case '%':
|
||||
*msg++ = '%';
|
||||
maxlen -= 1;
|
||||
break;
|
||||
case 'c':
|
||||
case 'i':
|
||||
case 'd':
|
||||
case 'u':
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'X':
|
||||
len =
|
||||
SDL_snprintf(msg, maxlen, tmp,
|
||||
error->args[argi++].value_i);
|
||||
msg += len;
|
||||
maxlen -= len;
|
||||
break;
|
||||
case 'f':
|
||||
len =
|
||||
SDL_snprintf(msg, maxlen, tmp,
|
||||
error->args[argi++].value_f);
|
||||
msg += len;
|
||||
maxlen -= len;
|
||||
break;
|
||||
case 'p':
|
||||
len =
|
||||
SDL_snprintf(msg, maxlen, tmp,
|
||||
error->args[argi++].value_ptr);
|
||||
msg += len;
|
||||
maxlen -= len;
|
||||
break;
|
||||
case 's':
|
||||
len =
|
||||
SDL_snprintf(msg, maxlen, tmp,
|
||||
SDL_LookupString(error->args[argi++].
|
||||
buf));
|
||||
msg += len;
|
||||
maxlen -= len;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*msg++ = *fmt++;
|
||||
maxlen -= 1;
|
||||
}
|
||||
}
|
||||
*msg = 0; /* NULL terminate the string */
|
||||
}
|
||||
return (errstr);
|
||||
}
|
||||
|
||||
/* Available for backwards compatibility */
|
||||
char *
|
||||
SDL_GetError(void)
|
||||
{
|
||||
static char errmsg[SDL_ERRBUFIZE];
|
||||
|
||||
return ((char *) SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_ClearError(void)
|
||||
{
|
||||
SDL_error *error;
|
||||
|
||||
error = SDL_GetErrBuf();
|
||||
error->error = 0;
|
||||
}
|
||||
|
||||
/* Very common errors go here */
|
||||
void
|
||||
SDL_Error(SDL_errorcode code)
|
||||
{
|
||||
switch (code) {
|
||||
case SDL_ENOMEM:
|
||||
SDL_SetError("Out of memory");
|
||||
break;
|
||||
case SDL_EFREAD:
|
||||
SDL_SetError("Error reading from datastream");
|
||||
break;
|
||||
case SDL_EFWRITE:
|
||||
SDL_SetError("Error writing to datastream");
|
||||
break;
|
||||
case SDL_EFSEEK:
|
||||
SDL_SetError("Error seeking in datastream");
|
||||
break;
|
||||
case SDL_UNSUPPORTED:
|
||||
SDL_SetError("That operation is not supported");
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown SDL error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_ERROR
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[BUFSIZ + 1];
|
||||
|
||||
SDL_SetError("Hi there!");
|
||||
printf("Error 1: %s\n", SDL_GetError());
|
||||
SDL_ClearError();
|
||||
SDL_memset(buffer, '1', BUFSIZ);
|
||||
buffer[BUFSIZ] = 0;
|
||||
SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
|
||||
printf("Error 2: %s\n", SDL_GetError());
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* This file defines a structure that carries language-independent
|
||||
error messages
|
||||
*/
|
||||
|
||||
#ifndef _SDL_error_c_h
|
||||
#define _SDL_error_c_h
|
||||
|
||||
#define ERR_MAX_STRLEN 128
|
||||
#define ERR_MAX_ARGS 5
|
||||
|
||||
typedef struct SDL_error
|
||||
{
|
||||
/* This is a numeric value corresponding to the current error */
|
||||
int error;
|
||||
|
||||
/* This is a key used to index into a language hashtable containing
|
||||
internationalized versions of the SDL error messages. If the key
|
||||
is not in the hashtable, or no hashtable is available, the key is
|
||||
used directly as an error message format string.
|
||||
*/
|
||||
char key[ERR_MAX_STRLEN];
|
||||
|
||||
/* These are the arguments for the error functions */
|
||||
int argc;
|
||||
union
|
||||
{
|
||||
void *value_ptr;
|
||||
#if 0 /* What is a character anyway? (UNICODE issues) */
|
||||
unsigned char value_c;
|
||||
#endif
|
||||
int value_i;
|
||||
double value_f;
|
||||
char buf[ERR_MAX_STRLEN];
|
||||
} args[ERR_MAX_ARGS];
|
||||
} SDL_error;
|
||||
|
||||
#endif /* _SDL_error_c_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* General fatal signal handling code for SDL */
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_fatal.h"
|
||||
|
||||
/* This installs some signal handlers for the more common fatal signals,
|
||||
so that if the programmer is lazy, the app doesn't die so horribly if
|
||||
the program crashes.
|
||||
*/
|
||||
|
||||
static void
|
||||
SDL_Parachute(int sig)
|
||||
{
|
||||
signal(sig, SIG_DFL);
|
||||
SDL_Quit();
|
||||
raise(sig);
|
||||
}
|
||||
|
||||
static const int SDL_fatal_signals[] = {
|
||||
SIGSEGV,
|
||||
#ifdef SIGBUS
|
||||
SIGBUS,
|
||||
#endif
|
||||
#ifdef SIGFPE
|
||||
SIGFPE,
|
||||
#endif
|
||||
#ifdef SIGQUIT
|
||||
SIGQUIT,
|
||||
#endif
|
||||
0
|
||||
};
|
||||
|
||||
void
|
||||
SDL_InstallParachute(void)
|
||||
{
|
||||
/* Set a handler for any fatal signal not already handled */
|
||||
int i;
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
|
||||
for (i = 0; SDL_fatal_signals[i]; ++i) {
|
||||
sigaction(SDL_fatal_signals[i], NULL, &action);
|
||||
if (action.sa_handler == SIG_DFL) {
|
||||
action.sa_handler = SDL_Parachute;
|
||||
sigaction(SDL_fatal_signals[i], &action, NULL);
|
||||
}
|
||||
}
|
||||
#ifdef SIGALRM
|
||||
/* Set SIGALRM to be ignored -- necessary on Solaris */
|
||||
sigaction(SIGALRM, NULL, &action);
|
||||
if (action.sa_handler == SIG_DFL) {
|
||||
action.sa_handler = SIG_IGN;
|
||||
sigaction(SIGALRM, &action, NULL);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
void (*ohandler) (int);
|
||||
|
||||
for (i = 0; SDL_fatal_signals[i]; ++i) {
|
||||
ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
|
||||
if (ohandler != SIG_DFL) {
|
||||
signal(SDL_fatal_signals[i], ohandler);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_SIGACTION */
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UninstallParachute(void)
|
||||
{
|
||||
/* Remove a handler for any fatal signal handled */
|
||||
int i;
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
|
||||
for (i = 0; SDL_fatal_signals[i]; ++i) {
|
||||
sigaction(SDL_fatal_signals[i], NULL, &action);
|
||||
if (action.sa_handler == SDL_Parachute) {
|
||||
action.sa_handler = SIG_DFL;
|
||||
sigaction(SDL_fatal_signals[i], &action, NULL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void (*ohandler) (int);
|
||||
|
||||
for (i = 0; SDL_fatal_signals[i]; ++i) {
|
||||
ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
|
||||
if (ohandler != SDL_Parachute) {
|
||||
signal(SDL_fatal_signals[i], ohandler);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_SIGACTION */
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* No signals on this platform, nothing to do.. */
|
||||
|
||||
void
|
||||
SDL_InstallParachute(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UninstallParachute(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* General fatal signal handling code for SDL */
|
||||
|
||||
extern void SDL_InstallParachute(void);
|
||||
extern void SDL_UninstallParachute(void);
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,469 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
Contributed by Bob Pendleton, bob@pendleton.com
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_atomic.h"
|
||||
|
||||
#include "SDL_error.h"
|
||||
|
||||
/*
|
||||
This file provides 32, and 64 bit atomic operations. If the
|
||||
operations are provided by the native hardware and operating system
|
||||
they are used. If they are not then the operations are emulated
|
||||
using the SDL spin lock operations. If spin lock can not be
|
||||
implemented then these functions must fail.
|
||||
*/
|
||||
|
||||
/*
|
||||
DUMMY VERSION.
|
||||
|
||||
This version of the code assumes there is no support for atomic
|
||||
operations. Therefore, every function sets the SDL error
|
||||
message. Oddly enough, if you only have one thread then this
|
||||
version actuallys works.
|
||||
*/
|
||||
|
||||
/*
|
||||
Native spinlock routines. Because this is the dummy implementation
|
||||
these will always call SDL_SetError() and do nothing.
|
||||
*/
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
SDL_SetError("SDL_atomic.c: is not implemented on this platform");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
SDL_SetError("SDL_atomic.c: is not implemented on this platform");
|
||||
}
|
||||
|
||||
/*
|
||||
Note that platform specific versions can be built from this version
|
||||
by changing the #undefs to #defines and adding platform specific
|
||||
code.
|
||||
*/
|
||||
|
||||
#undef nativeTestThenSet32
|
||||
#undef nativeClear32
|
||||
#undef nativeFetchThenIncrement32
|
||||
#undef nativeFetchThenDecrement32
|
||||
#undef nativeFetchThenAdd32
|
||||
#undef nativeFetchThenSubtract32
|
||||
#undef nativeIncrementThenFetch32
|
||||
#undef nativeDecrementThenFetch32
|
||||
#undef nativeAddThenFetch32
|
||||
#undef nativeSubtractThenFetch32
|
||||
|
||||
#undef nativeTestThenSet64
|
||||
#undef nativeClear64
|
||||
#undef nativeFetchThenIncrement64
|
||||
#undef nativeFetchThenDecrement64
|
||||
#undef nativeFetchThenAdd64
|
||||
#undef nativeFetchThenSubtract64
|
||||
#undef nativeIncrementThenFetch64
|
||||
#undef nativeDecrementThenFetch64
|
||||
#undef nativeAddThenFetch64
|
||||
#undef nativeSubtractThenFetch64
|
||||
|
||||
/*
|
||||
If any of the operations are not provided then we must emulate some
|
||||
of them. That means we need a nice implementation of spin locks
|
||||
that avoids the "one big lock" problem. We use a vector of spin
|
||||
locks and pick which one to use based on the address of the operand
|
||||
of the function.
|
||||
|
||||
To generate the index of the lock we first shift by 3 bits to get
|
||||
rid on the zero bits that result from 32 and 64 bit allignment of
|
||||
data. We then mask off all but 5 bits and use those 5 bits as an
|
||||
index into the table.
|
||||
|
||||
Picking the lock this way insures that accesses to the same data at
|
||||
the same time will go to the same lock. OTOH, accesses to different
|
||||
data have only a 1/32 chance of hitting the same lock. That should
|
||||
pretty much eliminate the chances of several atomic operations on
|
||||
different data from waiting on the same "big lock". If it isn't
|
||||
then the table of locks can be expanded to a new size so long as
|
||||
the new size is a power of two.
|
||||
*/
|
||||
|
||||
static SDL_SpinLock locks[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static __inline__ void
|
||||
privateWaitLock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicLock(&locks[index]);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
privateUnlock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicUnlock(&locks[index]);
|
||||
}
|
||||
|
||||
/* 32 bit atomic operations */
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet32
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeClear32
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 64 bit atomic operations */
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet64
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeClear64
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,510 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
Contributed by Bob Pendleton, bob@pendleton.com
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_atomic.h"
|
||||
|
||||
#include "SDL_error.h"
|
||||
|
||||
/*
|
||||
This file provides 32, and 64 bit atomic operations. If the
|
||||
operations are provided by the native hardware and operating system
|
||||
they are used. If they are not then the operations are emulated
|
||||
using the SDL spin lock operations. If spin lock can not be
|
||||
implemented then these functions must fail.
|
||||
*/
|
||||
|
||||
/*
|
||||
LINUX/GCC VERSION.
|
||||
|
||||
This version of the code assumes support of the atomic builtins as
|
||||
documented at gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html This
|
||||
code should work on any modern x86 or other processor supported by
|
||||
GCC.
|
||||
|
||||
Some processors will only support some of these operations so
|
||||
#ifdefs will have to be added as incompatibilities are discovered
|
||||
*/
|
||||
|
||||
/*
|
||||
Native spinlock routines.
|
||||
*/
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
while (0 != __sync_lock_test_and_set(lock, 1))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
__sync_lock_test_and_set(lock, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
Note that platform specific versions can be built from this version
|
||||
by changing the #undefs to #defines and adding platform specific
|
||||
code.
|
||||
*/
|
||||
|
||||
#define nativeTestThenSet32
|
||||
#define nativeClear32
|
||||
#define nativeFetchThenIncrement32
|
||||
#define nativeFetchThenDecrement32
|
||||
#define nativeFetchThenAdd32
|
||||
#define nativeFetchThenSubtract32
|
||||
#define nativeIncrementThenFetch32
|
||||
#define nativeDecrementThenFetch32
|
||||
#define nativeAddThenFetch32
|
||||
#define nativeSubtractThenFetch32
|
||||
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
|
||||
#define nativeTestThenSet64
|
||||
#define nativeClear64
|
||||
#define nativeFetchThenIncrement64
|
||||
#define nativeFetchThenDecrement64
|
||||
#define nativeFetchThenAdd64
|
||||
#define nativeFetchThenSubtract64
|
||||
#define nativeIncrementThenFetch64
|
||||
#define nativeDecrementThenFetch64
|
||||
#define nativeAddThenFetch64
|
||||
#define nativeSubtractThenFetch64
|
||||
#else
|
||||
#undef nativeTestThenSet64
|
||||
#undef nativeClear64
|
||||
#undef nativeFetchThenIncrement64
|
||||
#undef nativeFetchThenDecrement64
|
||||
#undef nativeFetchThenAdd64
|
||||
#undef nativeFetchThenSubtract64
|
||||
#undef nativeIncrementThenFetch64
|
||||
#undef nativeDecrementThenFetch64
|
||||
#undef nativeAddThenFetch64
|
||||
#undef nativeSubtractThenFetch64
|
||||
#endif /* __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 */
|
||||
#endif /* SDL_HAS_64BIT_TYPE */
|
||||
|
||||
/*
|
||||
If any of the operations are not provided then we must emulate some
|
||||
of them. That means we need a nice implementation of spin locks
|
||||
that avoids the "one big lock" problem. We use a vector of spin
|
||||
locks and pick which one to use based on the address of the operand
|
||||
of the function.
|
||||
|
||||
To generate the index of the lock we first shift by 3 bits to get
|
||||
rid on the zero bits that result from 32 and 64 bit allignment of
|
||||
data. We then mask off all but 5 bits and use those 5 bits as an
|
||||
index into the table.
|
||||
|
||||
Picking the lock this way insures that accesses to the same data at
|
||||
the same time will go to the same lock. OTOH, accesses to different
|
||||
data have only a 1/32 chance of hitting the same lock. That should
|
||||
pretty much eliminate the chances of several atomic operations on
|
||||
different data from waiting on the same "big lock". If it isn't
|
||||
then the table of locks can be expanded to a new size so long as
|
||||
the new size is a power of two.
|
||||
*/
|
||||
|
||||
static SDL_SpinLock locks[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static __inline__ void
|
||||
privateWaitLock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicLock(&locks[index]);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
privateUnlock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicUnlock(&locks[index]);
|
||||
}
|
||||
|
||||
/* 32 bit atomic operations */
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet32
|
||||
return 0 == __sync_lock_test_and_set(ptr, 1);
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeClear32
|
||||
__sync_lock_test_and_set(ptr, 0);
|
||||
return;
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement32
|
||||
return __sync_fetch_and_add(ptr, 1);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement32
|
||||
return __sync_fetch_and_sub(ptr, 1);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd32
|
||||
return __sync_fetch_and_add(ptr, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract32
|
||||
return __sync_fetch_and_sub(ptr, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch32
|
||||
return __sync_add_and_fetch(ptr, 1);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch32
|
||||
return __sync_sub_and_fetch(ptr, 1);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch32
|
||||
return __sync_add_and_fetch(ptr, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch32
|
||||
return __sync_sub_and_fetch(ptr, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 64 bit atomic operations */
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet64
|
||||
return 0 == __sync_lock_test_and_set(ptr, 1);
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeClear64
|
||||
__sync_lock_test_and_set(ptr, 0);
|
||||
return;
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement64
|
||||
return __sync_fetch_and_add(ptr, 1);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement64
|
||||
return __sync_fetch_and_sub(ptr, 1);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd64
|
||||
return __sync_fetch_and_add(ptr, value);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract64
|
||||
return __sync_fetch_and_sub(ptr, value);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch64
|
||||
return __sync_add_and_fetch(ptr, 1);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch64
|
||||
return __sync_sub_and_fetch(ptr, 1);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch64
|
||||
return __sync_add_and_fetch(ptr, value);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch64
|
||||
return __sync_sub_and_fetch(ptr, value);
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* SDL_HAS_64BIT_TYPE */
|
|
@ -0,0 +1,469 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
Contributed by Bob Pendleton, bob@pendleton.com
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_atomic.h"
|
||||
|
||||
#include "SDL_error.h"
|
||||
|
||||
/*
|
||||
This file provides 32, and 64 bit atomic operations. If the
|
||||
operations are provided by the native hardware and operating system
|
||||
they are used. If they are not then the operations are emulated
|
||||
using the SDL spin lock operations. If spin lock can not be
|
||||
implemented then these functions must fail.
|
||||
*/
|
||||
|
||||
/*
|
||||
DUMMY VERSION.
|
||||
|
||||
This version of the code assumes there is no support for atomic
|
||||
operations. Therefore, every function sets the SDL error
|
||||
message. Oddly enough, if you only have one thread then this
|
||||
version actuallys works.
|
||||
*/
|
||||
|
||||
/*
|
||||
Native spinlock routines. Because this is the dummy implementation
|
||||
these will always call SDL_SetError() and do nothing.
|
||||
*/
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
SDL_SetError("SDL_atomic.c: is not implemented on this platform");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
SDL_SetError("SDL_atomic.c: is not implemented on this platform");
|
||||
}
|
||||
|
||||
/*
|
||||
Note that platform specific versions can be built from this version
|
||||
by changing the #undefs to #defines and adding platform specific
|
||||
code.
|
||||
*/
|
||||
|
||||
#undef nativeTestThenSet32
|
||||
#undef nativeClear32
|
||||
#undef nativeFetchThenIncrement32
|
||||
#undef nativeFetchThenDecrement32
|
||||
#undef nativeFetchThenAdd32
|
||||
#undef nativeFetchThenSubtract32
|
||||
#undef nativeIncrementThenFetch32
|
||||
#undef nativeDecrementThenFetch32
|
||||
#undef nativeAddThenFetch32
|
||||
#undef nativeSubtractThenFetch32
|
||||
|
||||
#undef nativeTestThenSet64
|
||||
#undef nativeClear64
|
||||
#undef nativeFetchThenIncrement64
|
||||
#undef nativeFetchThenDecrement64
|
||||
#undef nativeFetchThenAdd64
|
||||
#undef nativeFetchThenSubtract64
|
||||
#undef nativeIncrementThenFetch64
|
||||
#undef nativeDecrementThenFetch64
|
||||
#undef nativeAddThenFetch64
|
||||
#undef nativeSubtractThenFetch64
|
||||
|
||||
/*
|
||||
If any of the operations are not provided then we must emulate some
|
||||
of them. That means we need a nice implementation of spin locks
|
||||
that avoids the "one big lock" problem. We use a vector of spin
|
||||
locks and pick which one to use based on the address of the operand
|
||||
of the function.
|
||||
|
||||
To generate the index of the lock we first shift by 3 bits to get
|
||||
rid on the zero bits that result from 32 and 64 bit allignment of
|
||||
data. We then mask off all but 5 bits and use those 5 bits as an
|
||||
index into the table.
|
||||
|
||||
Picking the lock this way insures that accesses to the same data at
|
||||
the same time will go to the same lock. OTOH, accesses to different
|
||||
data have only a 1/32 chance of hitting the same lock. That should
|
||||
pretty much eliminate the chances of several atomic operations on
|
||||
different data from waiting on the same "big lock". If it isn't
|
||||
then the table of locks can be expanded to a new size so long as
|
||||
the new size is a power of two.
|
||||
*/
|
||||
|
||||
static SDL_SpinLock locks[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static __inline__ void
|
||||
privateWaitLock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicLock(&locks[index]);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
privateUnlock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicUnlock(&locks[index]);
|
||||
}
|
||||
|
||||
/* 32 bit atomic operations */
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet32
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeClear32
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch32
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 64 bit atomic operations */
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet64
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeClear64
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,505 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
QNX native atomic operations
|
||||
Copyright (C) 2009 Mike Gorchak
|
||||
(mike@malva.ua, lestat@i.com.ua)
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_atomic.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include <atomic.h>
|
||||
|
||||
/* SMP Exchange for PPC platform */
|
||||
#ifdef __PPC__
|
||||
#include <ppc/smpxchg.h>
|
||||
#endif /* __PPC__ */
|
||||
|
||||
/* SMP Exchange for ARM platform */
|
||||
#ifdef __ARM__
|
||||
#include <arm/smpxchg.h>
|
||||
#endif /* __ARM__ */
|
||||
|
||||
/* SMP Exchange for MIPS platform */
|
||||
#if defined (__MIPSEB__) || defined(__MIPSEL__)
|
||||
#include <mips/smpxchg.h>
|
||||
#endif /* __MIPSEB__ || __MIPSEL__ */
|
||||
|
||||
/* SMP Exchange for SH platform */
|
||||
#ifdef __SH__
|
||||
#include <sh/smpxchg.h>
|
||||
#endif /* __SH__ */
|
||||
|
||||
/* SMP Exchange for x86 platform */
|
||||
#ifdef __X86__
|
||||
#include <x86/smpxchg.h>
|
||||
#endif /* __X86__ */
|
||||
|
||||
/*
|
||||
This file provides 32, and 64 bit atomic operations. If the
|
||||
operations are provided by the native hardware and operating system
|
||||
they are used. If they are not then the operations are emulated
|
||||
using the SDL spin lock operations. If spin lock can not be
|
||||
implemented then these functions must fail.
|
||||
*/
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
unsigned volatile* l = (unsigned volatile*)lock;
|
||||
Uint32 oldval = 0;
|
||||
Uint32 newval = 1;
|
||||
|
||||
oldval = _smp_xchg(l, newval);
|
||||
while(1 == oldval)
|
||||
{
|
||||
oldval = _smp_xchg(l, newval);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
unsigned volatile* l = (unsigned volatile*)lock;
|
||||
Uint32 newval = 0;
|
||||
|
||||
_smp_xchg(l, newval);
|
||||
}
|
||||
|
||||
/*
|
||||
QNX 6.4.1 supports only 32 bit atomic access
|
||||
*/
|
||||
|
||||
#undef nativeTestThenSet32
|
||||
#define nativeClear32
|
||||
#define nativeFetchThenIncrement32
|
||||
#define nativeFetchThenDecrement32
|
||||
#define nativeFetchThenAdd32
|
||||
#define nativeFetchThenSubtract32
|
||||
#define nativeIncrementThenFetch32
|
||||
#define nativeDecrementThenFetch32
|
||||
#define nativeAddThenFetch32
|
||||
#define nativeSubtractThenFetch32
|
||||
|
||||
#undef nativeTestThenSet64
|
||||
#undef nativeClear64
|
||||
#undef nativeFetchThenIncrement64
|
||||
#undef nativeFetchThenDecrement64
|
||||
#undef nativeFetchThenAdd64
|
||||
#undef nativeFetchThenSubtract64
|
||||
#undef nativeIncrementThenFetch64
|
||||
#undef nativeDecrementThenFetch64
|
||||
#undef nativeAddThenFetch64
|
||||
#undef nativeSubtractThenFetch64
|
||||
|
||||
/*
|
||||
If any of the operations are not provided then we must emulate some
|
||||
of them. That means we need a nice implementation of spin locks
|
||||
that avoids the "one big lock" problem. We use a vector of spin
|
||||
locks and pick which one to use based on the address of the operand
|
||||
of the function.
|
||||
|
||||
To generate the index of the lock we first shift by 3 bits to get
|
||||
rid on the zero bits that result from 32 and 64 bit allignment of
|
||||
data. We then mask off all but 5 bits and use those 5 bits as an
|
||||
index into the table.
|
||||
|
||||
Picking the lock this way insures that accesses to the same data at
|
||||
the same time will go to the same lock. OTOH, accesses to different
|
||||
data have only a 1/32 chance of hitting the same lock. That should
|
||||
pretty much eliminate the chances of several atomic operations on
|
||||
different data from waiting on the same "big lock". If it isn't
|
||||
then the table of locks can be expanded to a new size so long as
|
||||
the new size is a power of two.
|
||||
*/
|
||||
|
||||
static SDL_SpinLock locks[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static __inline__ void
|
||||
privateWaitLock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif /* SIZEOF_VOIDP */
|
||||
|
||||
SDL_AtomicLock(&locks[index]);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
privateUnlock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif /* SIZEOF_VOIDP */
|
||||
|
||||
SDL_AtomicUnlock(&locks[index]);
|
||||
}
|
||||
|
||||
/* 32 bit atomic operations */
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet32
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif /* nativeTestThenSet32 */
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeClear32
|
||||
atomic_clr(ptr, 0xFFFFFFFF);
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif /* nativeClear32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement32
|
||||
return atomic_add_value(ptr, 0x00000001);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenIncrement32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement32
|
||||
return atomic_sub_value(ptr, 0x00000001);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenDecrement32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd32
|
||||
return atomic_add_value(ptr, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenAdd32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract32
|
||||
return atomic_sub_value(ptr, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenSubtract32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch32
|
||||
atomic_add(ptr, 0x00000001);
|
||||
return atomic_add_value(ptr, 0x00000000);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeIncrementThenFetch32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch32
|
||||
atomic_sub(ptr, 0x00000001);
|
||||
return atomic_sub_value(ptr, 0x00000000);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeDecrementThenFetch32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch32
|
||||
atomic_add(ptr, value);
|
||||
return atomic_add_value(ptr, 0x00000000);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeAddThenFetch32 */
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch32
|
||||
atomic_sub(ptr, value);
|
||||
return atomic_sub_value(ptr, 0x00000000);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeSubtractThenFetch32 */
|
||||
}
|
||||
|
||||
/* 64 bit atomic operations */
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet64
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif /* nativeTestThenSet64 */
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeClear64
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif /* nativeClear64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenIncrement64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenDecrement64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenAdd64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeFetchThenSubtract64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeIncrementThenFetch64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeDecrementThenFetch64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeAddThenFetch64 */
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif /* nativeSubtractThenFetch64 */
|
||||
}
|
||||
|
||||
#endif /* SDL_HAS_64BIT_TYPE */
|
|
@ -0,0 +1,510 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
Contributed by Bob Pendleton, bob@pendleton.com
|
||||
*/
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_atomic.h"
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "Windows.h"
|
||||
|
||||
/*
|
||||
This file provides 32, and 64 bit atomic operations. If the
|
||||
operations are provided by the native hardware and operating system
|
||||
they are used. If they are not then the operations are emulated
|
||||
using the SDL spin lock operations. If spin lock can not be
|
||||
implemented then these functions must fail.
|
||||
*/
|
||||
|
||||
/*
|
||||
WIN32 VERSION.
|
||||
|
||||
This makes use of native Windows atomic operations.
|
||||
*/
|
||||
|
||||
/*
|
||||
Native spinlock routines. Because this is the dummy implementation
|
||||
these will always call SDL_SetError() and do nothing.
|
||||
*/
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
long volatile * l = (long volatile *)lock;
|
||||
Uint32 old = 0;
|
||||
Uint32 new = 1;
|
||||
|
||||
old = InterlockedExchange(l, new);
|
||||
while(1 == old)
|
||||
{
|
||||
old = InterlockedExchange(l, new);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
long volatile * l = (long volatile *)lock;
|
||||
Uint32 new = 0;
|
||||
|
||||
InterlockedExchange(l, new);
|
||||
}
|
||||
|
||||
/*
|
||||
Note that platform specific versions can be built from this version
|
||||
by changing the #undefs to #defines and adding platform specific
|
||||
code.
|
||||
*/
|
||||
|
||||
#define nativeTestThenSet32
|
||||
#define nativeClear32
|
||||
#define nativeFetchThenIncrement32
|
||||
#define nativeFetchThenDecrement32
|
||||
#define nativeFetchThenAdd32
|
||||
#define nativeFetchThenSubtract32
|
||||
#define nativeIncrementThenFetch32
|
||||
#define nativeDecrementThenFetch32
|
||||
#define nativeAddThenFetch32
|
||||
#define nativeSubtractThenFetch32
|
||||
|
||||
#undef nativeTestThenSet64
|
||||
#undef nativeClear64
|
||||
#undef nativeFetchThenIncrement64
|
||||
#undef nativeFetchThenDecrement64
|
||||
#undef nativeFetchThenAdd64
|
||||
#undef nativeFetchThenSubtract64
|
||||
#undef nativeIncrementThenFetch64
|
||||
#undef nativeDecrementThenFetch64
|
||||
#undef nativeAddThenFetch64
|
||||
#undef nativeSubtractThenFetch64
|
||||
|
||||
/*
|
||||
If any of the operations are not provided then we must emulate some
|
||||
of them. That means we need a nice implementation of spin locks
|
||||
that avoids the "one big lock" problem. We use a vector of spin
|
||||
locks and pick which one to use based on the address of the operand
|
||||
of the function.
|
||||
|
||||
To generate the index of the lock we first shift by 3 bits to get
|
||||
rid on the zero bits that result from 32 and 64 bit allignment of
|
||||
data. We then mask off all but 5 bits and use those 5 bits as an
|
||||
index into the table.
|
||||
|
||||
Picking the lock this way insures that accesses to the same data at
|
||||
the same time will go to the same lock. OTOH, accesses to different
|
||||
data have only a 1/32 chance of hitting the same lock. That should
|
||||
pretty much eliminate the chances of several atomic operations on
|
||||
different data from waiting on the same "big lock". If it isn't
|
||||
then the table of locks can be expanded to a new size so long as
|
||||
the new size is a power of two.
|
||||
*/
|
||||
|
||||
static SDL_SpinLock locks[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static __inline__ void
|
||||
privateWaitLock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicLock(&locks[index]);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
privateUnlock(volatile void *ptr)
|
||||
{
|
||||
#if SIZEOF_VOIDP == 4
|
||||
Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
|
||||
#endif
|
||||
|
||||
SDL_AtomicUnlock(&locks[index]);
|
||||
}
|
||||
|
||||
/* 32 bit atomic operations */
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
Uint32 new = 1;
|
||||
|
||||
return 0 == InterlockedExchange(p, new);
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeClear32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
Uint32 new = 0;
|
||||
|
||||
InterlockedExchange(p, new);
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
|
||||
return InterlockedExchangeAdd(p, 1);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
|
||||
return InterlockedExchangeAdd(p, -1);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
|
||||
return InterlockedExchangeAdd(p, value);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
|
||||
return InterlockedExchangeAdd(p, (0 - value));
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch32
|
||||
long volatile * p = (LONG volatile *)ptr;
|
||||
|
||||
return InterlockedIncrement(p);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch32
|
||||
long volatile * p = (LONG volatile *)ptr;
|
||||
|
||||
return InterlockedDecrement(p);
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
|
||||
return InterlockedExchangeAdd(p, value) + value;
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch32
|
||||
long volatile * p = (long volatile *)ptr;
|
||||
|
||||
return InterlockedExchangeAdd(p, (0 - value)) - value;
|
||||
#else
|
||||
Uint32 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 64 bit atomic operations */
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeTestThenSet64
|
||||
#else
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
result = (*ptr == 0);
|
||||
if (result)
|
||||
{
|
||||
*ptr = 1;
|
||||
}
|
||||
privateUnlock(ptr);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicClear64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeClear64
|
||||
#else
|
||||
privateWaitLock(ptr);
|
||||
*ptr = 0;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenIncrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeFetchThenDecrement64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr) -= 1;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenAdd64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)+= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeFetchThenSubtract64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
tmp = *ptr;
|
||||
(*ptr)-= value;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeIncrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
|
||||
{
|
||||
#ifdef nativeDecrementThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= 1;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeAddThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)+= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
|
||||
{
|
||||
#ifdef nativeSubtractThenFetch64
|
||||
#else
|
||||
Uint64 tmp = 0;
|
||||
|
||||
privateWaitLock(ptr);
|
||||
(*ptr)-= value;
|
||||
tmp = *ptr;
|
||||
privateUnlock(ptr);
|
||||
|
||||
return tmp;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Functions and variables exported from SDL_audio.c for SDL_sysaudio.c */
|
||||
|
||||
/* Functions to get a list of "close" audio formats */
|
||||
extern SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format);
|
||||
extern SDL_AudioFormat SDL_NextAudioFormat(void);
|
||||
|
||||
/* Function to calculate the size and silence for a SDL_AudioSpec */
|
||||
extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
|
||||
|
||||
/* The actual mixing thread function */
|
||||
extern int SDLCALL SDL_RunAudio(void *audiop);
|
||||
|
||||
/* this is used internally to access some autogenerated code. */
|
||||
typedef struct
|
||||
{
|
||||
SDL_AudioFormat src_fmt;
|
||||
SDL_AudioFormat dst_fmt;
|
||||
SDL_AudioFilter filter;
|
||||
} SDL_AudioTypeFilters;
|
||||
extern const SDL_AudioTypeFilters sdl_audio_type_filters[];
|
||||
|
||||
/* this is used internally to access some autogenerated code. */
|
||||
typedef struct
|
||||
{
|
||||
SDL_AudioFormat fmt;
|
||||
int channels;
|
||||
int upsample;
|
||||
int multiple;
|
||||
SDL_AudioFilter filter;
|
||||
} SDL_AudioRateFilters;
|
||||
extern const SDL_AudioRateFilters sdl_audio_rate_filters[];
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Get the name of the audio device we use for output */
|
||||
|
||||
#if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_audiodev_c.h"
|
||||
|
||||
#ifndef _PATH_DEV_DSP
|
||||
#if defined(__NETBSD__) || defined(__OPENBSD__)
|
||||
#define _PATH_DEV_DSP "/dev/audio"
|
||||
#else
|
||||
#define _PATH_DEV_DSP "/dev/dsp"
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _PATH_DEV_DSP24
|
||||
#define _PATH_DEV_DSP24 "/dev/sound/dsp"
|
||||
#endif
|
||||
#ifndef _PATH_DEV_AUDIO
|
||||
#define _PATH_DEV_AUDIO "/dev/audio"
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
test_device(const char *fname, int flags, int (*test) (int fd),
|
||||
char ***devices, int *devCount)
|
||||
{
|
||||
struct stat sb;
|
||||
if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
|
||||
int audio_fd = open(fname, flags, 0);
|
||||
if ((audio_fd >= 0) && (test(audio_fd))) {
|
||||
void *p =
|
||||
SDL_realloc(*devices, ((*devCount) + 1) * sizeof(char *));
|
||||
if (p != NULL) {
|
||||
size_t len = strlen(fname) + 1;
|
||||
char *str = (char *) SDL_malloc(len);
|
||||
*devices = (char **) p;
|
||||
if (str != NULL) {
|
||||
SDL_strlcpy(str, fname, len);
|
||||
(*devices)[(*devCount)++] = str;
|
||||
}
|
||||
}
|
||||
close(audio_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_FreeUnixAudioDevices(char ***devices, int *devCount)
|
||||
{
|
||||
int i = *devCount;
|
||||
if ((i > 0) && (*devices != NULL)) {
|
||||
while (i--) {
|
||||
SDL_free((*devices)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (*devices != NULL) {
|
||||
SDL_free(*devices);
|
||||
}
|
||||
|
||||
*devices = NULL;
|
||||
*devCount = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_stub(int fd)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EnumUnixAudioDevices(int flags, int classic, int (*test) (int fd),
|
||||
char ***devices, int *devCount)
|
||||
{
|
||||
const char *audiodev;
|
||||
char audiopath[1024];
|
||||
|
||||
if (test == NULL)
|
||||
test = test_stub;
|
||||
|
||||
/* Figure out what our audio device is */
|
||||
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
|
||||
((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
|
||||
if (classic) {
|
||||
audiodev = _PATH_DEV_AUDIO;
|
||||
} else {
|
||||
struct stat sb;
|
||||
|
||||
/* Added support for /dev/sound/\* in Linux 2.4 */
|
||||
if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode))
|
||||
&& ((stat(_PATH_DEV_DSP24, &sb) == 0)
|
||||
&& S_ISCHR(sb.st_mode))) {
|
||||
audiodev = _PATH_DEV_DSP24;
|
||||
} else {
|
||||
audiodev = _PATH_DEV_DSP;
|
||||
}
|
||||
}
|
||||
}
|
||||
test_device(audiodev, flags, test, devices, devCount);
|
||||
|
||||
if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
|
||||
int instance = 0;
|
||||
while (instance++ <= 64) {
|
||||
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
|
||||
"%s%d", audiodev, instance);
|
||||
test_device(audiopath, flags, test, devices, devCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Audio driver selection */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
void SDL_EnumUnixAudioDevices(int flags, int classic, int (*test) (int fd),
|
||||
char ***devs, int *count);
|
||||
void SDL_FreeUnixAudioDevices(char ***devices, int *devCount);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#define SDL_AllocAudioMem SDL_malloc
|
||||
#define SDL_FreeAudioMem SDL_free
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,361 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* This provides the default mixing callback for the SDL audio routines */
|
||||
|
||||
#include "SDL_cpuinfo.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_sysaudio.h"
|
||||
#include "SDL_mixer_MMX.h"
|
||||
#include "SDL_mixer_MMX_VC.h"
|
||||
#include "SDL_mixer_m68k.h"
|
||||
|
||||
/* This table is used to add two sound values together and pin
|
||||
* the value to avoid overflow. (used with permission from ARDI)
|
||||
* Changed to use 0xFE instead of 0xFF for better sound quality.
|
||||
*/
|
||||
static const Uint8 mix8[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
|
||||
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
|
||||
0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
|
||||
0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
|
||||
0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
|
||||
0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
|
||||
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B,
|
||||
0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
|
||||
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
|
||||
0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C,
|
||||
0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92,
|
||||
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D,
|
||||
0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
|
||||
0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3,
|
||||
0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
|
||||
0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9,
|
||||
0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4,
|
||||
0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA,
|
||||
0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5,
|
||||
0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE
|
||||
};
|
||||
|
||||
/* The volume ranges from 0 - 128 */
|
||||
#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME)
|
||||
#define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128)
|
||||
|
||||
|
||||
void
|
||||
SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
||||
Uint32 len, int volume)
|
||||
{
|
||||
if (volume == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
|
||||
case AUDIO_U8:
|
||||
{
|
||||
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
SDL_MixAudio_m68k_U8((char *) dst, (char *) src,
|
||||
(unsigned long) len, (long) volume,
|
||||
(char *) mix8);
|
||||
#else
|
||||
Uint8 src_sample;
|
||||
|
||||
while (len--) {
|
||||
src_sample = *src;
|
||||
ADJUST_VOLUME_U8(src_sample, volume);
|
||||
*dst = mix8[*dst + src_sample];
|
||||
++dst;
|
||||
++src;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_S8:
|
||||
{
|
||||
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_MixAudio_MMX_S8((char *) dst, (char *) src,
|
||||
(unsigned int) len, (int) volume);
|
||||
} else
|
||||
#elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_MixAudio_MMX_S8_VC((char *) dst, (char *) src,
|
||||
(unsigned int) len, (int) volume);
|
||||
} else
|
||||
#endif
|
||||
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
SDL_MixAudio_m68k_S8((char *) dst, (char *) src,
|
||||
(unsigned long) len, (long) volume);
|
||||
#else
|
||||
{
|
||||
Sint8 *dst8, *src8;
|
||||
Sint8 src_sample;
|
||||
int dst_sample;
|
||||
const int max_audioval = ((1 << (8 - 1)) - 1);
|
||||
const int min_audioval = -(1 << (8 - 1));
|
||||
|
||||
src8 = (Sint8 *) src;
|
||||
dst8 = (Sint8 *) dst;
|
||||
while (len--) {
|
||||
src_sample = *src8;
|
||||
ADJUST_VOLUME(src_sample, volume);
|
||||
dst_sample = *dst8 + src_sample;
|
||||
if (dst_sample > max_audioval) {
|
||||
*dst8 = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
*dst8 = min_audioval;
|
||||
} else {
|
||||
*dst8 = dst_sample;
|
||||
}
|
||||
++dst8;
|
||||
++src8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_S16LSB:
|
||||
{
|
||||
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_MixAudio_MMX_S16((char *) dst, (char *) src,
|
||||
(unsigned int) len, (int) volume);
|
||||
} else
|
||||
#elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_MixAudio_MMX_S16_VC((char *) dst, (char *) src,
|
||||
(unsigned int) len, (int) volume);
|
||||
} else
|
||||
#endif
|
||||
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
SDL_MixAudio_m68k_S16LSB((short *) dst, (short *) src,
|
||||
(unsigned long) len, (long) volume);
|
||||
#else
|
||||
{
|
||||
Sint16 src1, src2;
|
||||
int dst_sample;
|
||||
const int max_audioval = ((1 << (16 - 1)) - 1);
|
||||
const int min_audioval = -(1 << (16 - 1));
|
||||
|
||||
len /= 2;
|
||||
while (len--) {
|
||||
src1 = ((src[1]) << 8 | src[0]);
|
||||
ADJUST_VOLUME(src1, volume);
|
||||
src2 = ((dst[1]) << 8 | dst[0]);
|
||||
src += 2;
|
||||
dst_sample = src1 + src2;
|
||||
if (dst_sample > max_audioval) {
|
||||
dst_sample = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
dst_sample = min_audioval;
|
||||
}
|
||||
dst[0] = dst_sample & 0xFF;
|
||||
dst_sample >>= 8;
|
||||
dst[1] = dst_sample & 0xFF;
|
||||
dst += 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_S16MSB:
|
||||
{
|
||||
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
SDL_MixAudio_m68k_S16MSB((short *) dst, (short *) src,
|
||||
(unsigned long) len, (long) volume);
|
||||
#else
|
||||
Sint16 src1, src2;
|
||||
int dst_sample;
|
||||
const int max_audioval = ((1 << (16 - 1)) - 1);
|
||||
const int min_audioval = -(1 << (16 - 1));
|
||||
|
||||
len /= 2;
|
||||
while (len--) {
|
||||
src1 = ((src[0]) << 8 | src[1]);
|
||||
ADJUST_VOLUME(src1, volume);
|
||||
src2 = ((dst[0]) << 8 | dst[1]);
|
||||
src += 2;
|
||||
dst_sample = src1 + src2;
|
||||
if (dst_sample > max_audioval) {
|
||||
dst_sample = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
dst_sample = min_audioval;
|
||||
}
|
||||
dst[1] = dst_sample & 0xFF;
|
||||
dst_sample >>= 8;
|
||||
dst[0] = dst_sample & 0xFF;
|
||||
dst += 2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_S32LSB:
|
||||
{
|
||||
const Uint32 *src32 = (Uint32 *) src;
|
||||
Uint32 *dst32 = (Uint32 *) dst;
|
||||
Sint64 src1, src2;
|
||||
Sint64 dst_sample;
|
||||
const Sint64 max_audioval = ((((Sint64) 1) << (32 - 1)) - 1);
|
||||
const Sint64 min_audioval = -(((Sint64) 1) << (32 - 1));
|
||||
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
src1 = (Sint64) ((Sint32) SDL_SwapLE32(*src32));
|
||||
src32++;
|
||||
ADJUST_VOLUME(src1, volume);
|
||||
src2 = (Sint64) ((Sint32) SDL_SwapLE32(*dst32));
|
||||
dst_sample = src1 + src2;
|
||||
if (dst_sample > max_audioval) {
|
||||
dst_sample = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
dst_sample = min_audioval;
|
||||
}
|
||||
*(dst32++) = SDL_SwapLE32((Uint32) ((Sint32) dst_sample));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_S32MSB:
|
||||
{
|
||||
const Uint32 *src32 = (Uint32 *) src;
|
||||
Uint32 *dst32 = (Uint32 *) dst;
|
||||
Sint64 src1, src2;
|
||||
Sint64 dst_sample;
|
||||
const Sint64 max_audioval = ((((Sint64) 1) << (32 - 1)) - 1);
|
||||
const Sint64 min_audioval = -(((Sint64) 1) << (32 - 1));
|
||||
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
src1 = (Sint64) ((Sint32) SDL_SwapBE32(*src32));
|
||||
src32++;
|
||||
ADJUST_VOLUME(src1, volume);
|
||||
src2 = (Sint64) ((Sint32) SDL_SwapBE32(*dst32));
|
||||
dst_sample = src1 + src2;
|
||||
if (dst_sample > max_audioval) {
|
||||
dst_sample = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
dst_sample = min_audioval;
|
||||
}
|
||||
*(dst32++) = SDL_SwapBE32((Uint32) ((Sint32) dst_sample));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_F32LSB:
|
||||
{
|
||||
const float fmaxvolume = 1.0f / ((float) SDL_MIX_MAXVOLUME);
|
||||
const float fvolume = (float) volume;
|
||||
const float *src32 = (float *) src;
|
||||
float *dst32 = (float *) dst;
|
||||
float src1, src2;
|
||||
double dst_sample;
|
||||
/* !!! FIXME: are these right? */
|
||||
const double max_audioval = 3.402823466e+38F;
|
||||
const double min_audioval = -3.402823466e+38F;
|
||||
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
src1 = ((SDL_SwapFloatLE(*src32) * fvolume) * fmaxvolume);
|
||||
src2 = SDL_SwapFloatLE(*dst32);
|
||||
src32++;
|
||||
|
||||
dst_sample = ((double) src1) + ((double) src2);
|
||||
if (dst_sample > max_audioval) {
|
||||
dst_sample = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
dst_sample = min_audioval;
|
||||
}
|
||||
*(dst32++) = SDL_SwapFloatLE((float) dst_sample);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_F32MSB:
|
||||
{
|
||||
const float fmaxvolume = 1.0f / ((float) SDL_MIX_MAXVOLUME);
|
||||
const float fvolume = (float) volume;
|
||||
const float *src32 = (float *) src;
|
||||
float *dst32 = (float *) dst;
|
||||
float src1, src2;
|
||||
double dst_sample;
|
||||
/* !!! FIXME: are these right? */
|
||||
const double max_audioval = 3.402823466e+38F;
|
||||
const double min_audioval = -3.402823466e+38F;
|
||||
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
src1 = ((SDL_SwapFloatBE(*src32) * fvolume) * fmaxvolume);
|
||||
src2 = SDL_SwapFloatBE(*dst32);
|
||||
src32++;
|
||||
|
||||
dst_sample = ((double) src1) + ((double) src2);
|
||||
if (dst_sample > max_audioval) {
|
||||
dst_sample = max_audioval;
|
||||
} else if (dst_sample < min_audioval) {
|
||||
dst_sample = min_audioval;
|
||||
}
|
||||
*(dst32++) = SDL_SwapFloatBE((float) dst_sample);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* If this happens... FIXME! */
|
||||
SDL_SetError("SDL_MixAudio(): unknown audio format");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/*
|
||||
MMX assembler version of SDL_MixAudio for signed little endian 16 bit samples and signed 8 bit samples
|
||||
Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
|
||||
This code is licensed under the LGPL (see COPYING for details)
|
||||
|
||||
Assumes buffer size in bytes is a multiple of 16
|
||||
Assumes SDL_MIX_MAXVOLUME = 128
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************
|
||||
* Mixing for 16 bit signed buffers
|
||||
***********************************************/
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
void
|
||||
SDL_MixAudio_MMX_S16(char *dst, char *src, unsigned int size, int volume)
|
||||
{
|
||||
__asm__ __volatile__(" movl %3,%%eax\n" /* eax = volume */
|
||||
" movl %2,%%edx\n" /* edx = size */
|
||||
" shrl $4,%%edx\n" /* process 16 bytes per iteration = 8 samples */
|
||||
" jz .endS16\n" " pxor %%mm0,%%mm0\n" " movd %%eax,%%mm0\n" " movq %%mm0,%%mm1\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" /* mm0 = vol|vol|vol|vol */
|
||||
".align 8\n" " .mixloopS16:\n" " movq (%1),%%mm1\n" /* mm1 = a|b|c|d */
|
||||
" movq %%mm1,%%mm2\n" /* mm2 = a|b|c|d */
|
||||
" movq 8(%1),%%mm4\n" /* mm4 = e|f|g|h */
|
||||
/* pré charger le buffer dst dans mm7 */
|
||||
" movq (%0),%%mm7\n" /* mm7 = dst[0] */
|
||||
/* multiplier par le volume */
|
||||
" pmullw %%mm0,%%mm1\n" /* mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
|
||||
" pmulhw %%mm0,%%mm2\n" /* mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) */
|
||||
" movq %%mm4,%%mm5\n" /* mm5 = e|f|g|h */
|
||||
" pmullw %%mm0,%%mm4\n" /* mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
|
||||
" pmulhw %%mm0,%%mm5\n" /* mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) */
|
||||
" movq %%mm1,%%mm3\n" /* mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
|
||||
" punpckhwd %%mm2,%%mm1\n" /* mm1 = a*v|b*v */
|
||||
" movq %%mm4,%%mm6\n" /* mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
|
||||
" punpcklwd %%mm2,%%mm3\n" /* mm3 = c*v|d*v */
|
||||
" punpckhwd %%mm5,%%mm4\n" /* mm4 = e*f|f*v */
|
||||
" punpcklwd %%mm5,%%mm6\n" /* mm6 = g*v|h*v */
|
||||
/* pré charger le buffer dst dans mm5 */
|
||||
" movq 8(%0),%%mm5\n" /* mm5 = dst[1] */
|
||||
/* diviser par 128 */
|
||||
" psrad $7,%%mm1\n" /* mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME */
|
||||
" add $16,%1\n" " psrad $7,%%mm3\n" /* mm3 = c*v/128|d*v/128 */
|
||||
" psrad $7,%%mm4\n" /* mm4 = e*v/128|f*v/128 */
|
||||
/* mm1 = le sample avec le volume modifié */
|
||||
" packssdw %%mm1,%%mm3\n" /* mm3 = s(a*v|b*v|c*v|d*v) */
|
||||
" psrad $7,%%mm6\n" /* mm6= g*v/128|h*v/128 */
|
||||
" paddsw %%mm7,%%mm3\n" /* mm3 = adjust_volume(src)+dst */
|
||||
/* mm4 = le sample avec le volume modifié */
|
||||
" packssdw %%mm4,%%mm6\n" /* mm6 = s(e*v|f*v|g*v|h*v) */
|
||||
" movq %%mm3,(%0)\n" " paddsw %%mm5,%%mm6\n" /* mm6 = adjust_volume(src)+dst */
|
||||
" movq %%mm6,8(%0)\n"
|
||||
" add $16,%0\n"
|
||||
" dec %%edx\n"
|
||||
" jnz .mixloopS16\n"
|
||||
" emms\n"
|
||||
".endS16:\n"::"r"(dst), "r"(src),
|
||||
"m"(size), "m"(volume):"eax", "edx", "memory");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*////////////////////////////////////////////// */
|
||||
/* Mixing for 8 bit signed buffers */
|
||||
/*////////////////////////////////////////////// */
|
||||
|
||||
void
|
||||
SDL_MixAudio_MMX_S8(char *dst, char *src, unsigned int size, int volume)
|
||||
{
|
||||
__asm__ __volatile__(" movl %3,%%eax\n" /* eax = volume */
|
||||
" movd %%eax,%%mm0\n" " movq %%mm0,%%mm1\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " movl %2,%%edx\n" /* edx = size */
|
||||
" shr $3,%%edx\n" /* process 8 bytes per iteration = 8 samples */
|
||||
" cmp $0,%%edx\n" " je .endS8\n" ".align 8\n" " .mixloopS8:\n" " pxor %%mm2,%%mm2\n" /* mm2 = 0 */
|
||||
" movq (%1),%%mm1\n" /* mm1 = a|b|c|d|e|f|g|h */
|
||||
" movq %%mm1,%%mm3\n" /* mm3 = a|b|c|d|e|f|g|h */
|
||||
/* on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 */
|
||||
" pcmpgtb %%mm1,%%mm2\n" /* mm2 = 11111111|00000000|00000000.... */
|
||||
" punpckhbw %%mm2,%%mm1\n" /* mm1 = 0|a|0|b|0|c|0|d */
|
||||
" punpcklbw %%mm2,%%mm3\n" /* mm3 = 0|e|0|f|0|g|0|h */
|
||||
" movq (%0),%%mm2\n" /* mm2 = destination */
|
||||
" pmullw %%mm0,%%mm1\n" /* mm1 = v*a|v*b|v*c|v*d */
|
||||
" add $8,%1\n" " pmullw %%mm0,%%mm3\n" /* mm3 = v*e|v*f|v*g|v*h */
|
||||
" psraw $7,%%mm1\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128 */
|
||||
" psraw $7,%%mm3\n" /* mm3 = v*e/128|v*f/128|v*g/128|v*h/128 */
|
||||
" packsswb %%mm1,%%mm3\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 */
|
||||
" paddsb %%mm2,%%mm3\n" /* add to destination buffer */
|
||||
" movq %%mm3,(%0)\n" /* store back to ram */
|
||||
" add $8,%0\n"
|
||||
" dec %%edx\n"
|
||||
" jnz .mixloopS8\n"
|
||||
".endS8:\n"
|
||||
" emms\n"::"r"(dst), "r"(src), "m"(size),
|
||||
"m"(volume):"eax", "edx", "memory");
|
||||
}
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
headers for MMX assembler version of SDL_MixAudio
|
||||
Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
|
||||
This code is licensed under the LGPL (see COPYING for details)
|
||||
|
||||
Assumes buffer size in bytes is a multiple of 16
|
||||
Assumes SDL_MIX_MAXVOLUME = 128
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
void SDL_MixAudio_MMX_S16(char *, char *, unsigned int, int);
|
||||
void SDL_MixAudio_MMX_S8(char *, char *, unsigned int, int);
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include "SDL_mixer_MMX_VC.h"
|
||||
|
||||
#if ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
// MMX assembler version of SDL_MixAudio for signed little endian 16 bit samples and signed 8 bit samples
|
||||
// Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
|
||||
// Converted to Intel ASM notation by Cth
|
||||
// This code is licensed under the LGPL (see COPYING for details)
|
||||
//
|
||||
// Assumes buffer size in bytes is a multiple of 16
|
||||
// Assumes SDL_MIX_MAXVOLUME = 128
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Mixing for 16 bit signed buffers
|
||||
////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
SDL_MixAudio_MMX_S16_VC(char *dst, char *src, unsigned int nSize, int volume)
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm
|
||||
{
|
||||
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
|
||||
mov edi, dst // edi = dst
|
||||
mov esi, src // esi = src
|
||||
mov eax, volume // eax = volume
|
||||
mov ebx, nSize // ebx = size
|
||||
shr ebx, 4 // process 16 bytes per iteration = 8 samples
|
||||
jz endS16
|
||||
|
||||
pxor mm0, mm0
|
||||
movd mm0, eax //%%eax,%%mm0
|
||||
movq mm1, mm0 //%%mm0,%%mm1
|
||||
psllq mm0, 16 //$16,%%mm0
|
||||
por mm0, mm1 //%%mm1,%%mm0
|
||||
psllq mm0, 16 //$16,%%mm0
|
||||
por mm0, mm1 //%%mm1,%%mm0
|
||||
psllq mm0, 16 //$16,%%mm0
|
||||
por mm0, mm1 //%%mm1,%%mm0 // mm0 = vol|vol|vol|vol
|
||||
|
||||
#ifndef __WATCOMC__
|
||||
align 16
|
||||
#endif
|
||||
mixloopS16:
|
||||
movq mm1, [esi] //(%%esi),%%mm1\n" // mm1 = a|b|c|d
|
||||
movq mm2, mm1 //%%mm1,%%mm2\n" // mm2 = a|b|c|d
|
||||
movq mm4, [esi + 8] //8(%%esi),%%mm4\n" // mm4 = e|f|g|h
|
||||
// pre charger le buffer dst dans mm7
|
||||
movq mm7, [edi] //(%%edi),%%mm7\n" // mm7 = dst[0]"
|
||||
// multiplier par le volume
|
||||
pmullw mm1, mm0 //%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
|
||||
pmulhw mm2, mm0 //%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
|
||||
movq mm5, mm4 //%%mm4,%%mm5\n" // mm5 = e|f|g|h
|
||||
pmullw mm4, mm0 //%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
|
||||
pmulhw mm5, mm0 //%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
|
||||
movq mm3, mm1 //%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
|
||||
punpckhwd mm1, mm2 //%%mm2,%%mm1\n" // mm1 = a*v|b*v
|
||||
movq mm6, mm4 //%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
|
||||
punpcklwd mm3, mm2 //%%mm2,%%mm3\n" // mm3 = c*v|d*v
|
||||
punpckhwd mm4, mm5 //%%mm5,%%mm4\n" // mm4 = e*f|f*v
|
||||
punpcklwd mm6, mm5 //%%mm5,%%mm6\n" // mm6 = g*v|h*v
|
||||
// pre charger le buffer dst dans mm5
|
||||
movq mm5, [edi + 8] //8(%%edi),%%mm5\n" // mm5 = dst[1]
|
||||
// diviser par 128
|
||||
psrad mm1, 7 //$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
|
||||
add esi, 16 //$16,%%esi\n"
|
||||
psrad mm3, 7 //$7,%%mm3\n" // mm3 = c*v/128|d*v/128
|
||||
psrad mm4, 7 //$7,%%mm4\n" // mm4 = e*v/128|f*v/128
|
||||
// mm1 = le sample avec le volume modifie
|
||||
packssdw mm3, mm1 //%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
|
||||
psrad mm6, 7 //$7,%%mm6\n" // mm6= g*v/128|h*v/128
|
||||
paddsw mm3, mm7 //%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
|
||||
// mm4 = le sample avec le volume modifie
|
||||
packssdw mm6, mm4 //%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
|
||||
movq [edi], mm3 //%%mm3,(%%edi)\n"
|
||||
paddsw mm6, mm5 //%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
|
||||
movq [edi + 8], mm6 //%%mm6,8(%%edi)\n"
|
||||
add edi, 16 //$16,%%edi\n"
|
||||
dec ebx //%%ebx\n"
|
||||
jnz mixloopS16
|
||||
|
||||
endS16:
|
||||
emms
|
||||
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Mixing for 8 bit signed buffers
|
||||
////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
SDL_MixAudio_MMX_S8_VC(char *dst, char *src, unsigned int nSize, int volume)
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
_asm
|
||||
{
|
||||
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
|
||||
mov edi, dst //movl %0,%%edi // edi = dst
|
||||
mov esi, src //%1,%%esi // esi = src
|
||||
mov eax, volume //%3,%%eax // eax = volume
|
||||
|
||||
movd mm0, eax //%%eax,%%mm0
|
||||
movq mm1, mm0 //%%mm0,%%mm1
|
||||
psllq mm0, 16 //$16,%%mm0
|
||||
por mm0, mm1 //%%mm1,%%mm0
|
||||
psllq mm0, 16 //$16,%%mm0
|
||||
por mm0, mm1 //%%mm1,%%mm0
|
||||
psllq mm0, 16 //$16,%%mm0
|
||||
por mm0, mm1 //%%mm1,%%mm0
|
||||
|
||||
mov ebx, nSize //%2,%%ebx // ebx = size
|
||||
shr ebx, 3 //$3,%%ebx // process 8 bytes per iteration = 8 samples
|
||||
cmp ebx, 0 //$0,%%ebx
|
||||
je endS8
|
||||
|
||||
#ifndef __WATCOMC__
|
||||
align 16
|
||||
#endif
|
||||
mixloopS8:
|
||||
pxor mm2, mm2 //%%mm2,%%mm2 // mm2 = 0
|
||||
movq mm1, [esi] //(%%esi),%%mm1 // mm1 = a|b|c|d|e|f|g|h
|
||||
movq mm3, mm1 //%%mm1,%%mm3 // mm3 = a|b|c|d|e|f|g|h
|
||||
// on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
|
||||
pcmpgtb mm2, mm1 //%%mm1,%%mm2 // mm2 = 11111111|00000000|00000000....
|
||||
punpckhbw mm1, mm2 //%%mm2,%%mm1 // mm1 = 0|a|0|b|0|c|0|d
|
||||
punpcklbw mm3, mm2 //%%mm2,%%mm3 // mm3 = 0|e|0|f|0|g|0|h
|
||||
movq mm2, [edi] //(%%edi),%%mm2 // mm2 = destination
|
||||
pmullw mm1, mm0 //%%mm0,%%mm1 // mm1 = v*a|v*b|v*c|v*d
|
||||
add esi, 8 //$8,%%esi
|
||||
pmullw mm3, mm0 //%%mm0,%%mm3 // mm3 = v*e|v*f|v*g|v*h
|
||||
psraw mm1, 7 //$7,%%mm1 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128
|
||||
psraw mm3, 7 //$7,%%mm3 // mm3 = v*e/128|v*f/128|v*g/128|v*h/128
|
||||
packsswb mm3, mm1 //%%mm1,%%mm3 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128
|
||||
paddsb mm3, mm2 //%%mm2,%%mm3 // add to destination buffer
|
||||
movq [edi], mm3 //%%mm3,(%%edi) // store back to ram
|
||||
add edi, 8 //$8,%%edi
|
||||
dec ebx //%%ebx
|
||||
jnz mixloopS8
|
||||
|
||||
endS8:
|
||||
emms
|
||||
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
#endif /* SDL_ASSEMBLY_ROUTINES */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
|
||||
#if ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
|
||||
/* headers for MMX assembler version of SDL_MixAudio
|
||||
Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
|
||||
Converted to Intel ASM notation by Cth
|
||||
This code is licensed under the LGPL (see COPYING for details)
|
||||
|
||||
Assumes buffer size in bytes is a multiple of 16
|
||||
Assumes SDL_MIX_MAXVOLUME = 128
|
||||
*/
|
||||
void SDL_MixAudio_MMX_S16_VC(char *, char *, unsigned int, int);
|
||||
void SDL_MixAudio_MMX_S8_VC(char *, char *, unsigned int, int);
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/*
|
||||
m68k assembly mix routines
|
||||
|
||||
Patrice Mandin
|
||||
*/
|
||||
|
||||
#if defined(__M68000__) && defined(__GNUC__)
|
||||
void
|
||||
SDL_MixAudio_m68k_U8(char *dst, char *src, long len, long volume, char *mix8)
|
||||
{
|
||||
__asm__ __volatile__("tstl %2\n" " beqs stoploop_u8\n" "mixloop_u8:\n"
|
||||
/* Mix a sample */
|
||||
" moveq #0,%%d0\n" " moveq #0,%%d1\n" " moveb %1@+,%%d0\n" /* d0 = *src++ */
|
||||
" sub #128,%%d0\n" /* d0 -= 128 */
|
||||
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
|
||||
" moveb %0@,%%d1\n" /* d1 = *dst */
|
||||
" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
|
||||
" add #128,%%d0\n" /* d0 += 128 */
|
||||
" add %%d1,%%d0\n"
|
||||
" moveb %4@(%%d0:w),%0@+\n"
|
||||
/* Loop till done */
|
||||
" subql #1,%2\n" " bhis mixloop_u8\n" "stoploop_u8:\n": /* no return value */
|
||||
: /* input */
|
||||
"a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8): /* clobbered registers */
|
||||
"d0", "d1", "cc", "memory");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_MixAudio_m68k_S8(char *dst, char *src, long len, long volume)
|
||||
{
|
||||
__asm__ __volatile__("tstl %2\n"
|
||||
" beqs stoploop_s8\n"
|
||||
" moveq #-128,%%d2\n"
|
||||
" moveq #127,%%d3\n" "mixloop_s8:\n"
|
||||
/* Mix a sample */
|
||||
" moveq #0,%%d0\n" " moveq #0,%%d1\n" " moveb %1@+,%%d0\n" /* d0 = *src++ */
|
||||
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
|
||||
" moveb %0@,%%d1\n" /* d1 = *dst */
|
||||
" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
|
||||
" add %%d1,%%d0\n"
|
||||
" cmp %%d2,%%d0\n"
|
||||
" bges lower_limit_s8\n"
|
||||
" move %%d2,%%d0\n"
|
||||
"lower_limit_s8:\n"
|
||||
" cmp %%d3,%%d0\n"
|
||||
" bles upper_limit_s8\n"
|
||||
" move %%d3,%%d0\n"
|
||||
"upper_limit_s8:\n" " moveb %%d0,%0@+\n"
|
||||
/* Loop till done */
|
||||
" subql #1,%2\n" " bhis mixloop_s8\n" "stoploop_s8:\n": /* no return value */
|
||||
: /* input */
|
||||
"a"(dst), "a"(src), "d"(len), "d"(volume): /* clobbered registers */
|
||||
"d0", "d1", "d2", "d3", "cc", "memory");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_MixAudio_m68k_S16MSB(short *dst, short *src, long len, long volume)
|
||||
{
|
||||
__asm__ __volatile__("tstl %2\n"
|
||||
" beqs stoploop_s16msb\n"
|
||||
" movel #-32768,%%d2\n"
|
||||
" movel #32767,%%d3\n"
|
||||
" lsrl #1,%2\n" "mixloop_s16msb:\n"
|
||||
/* Mix a sample */
|
||||
" move %1@+,%%d0\n" /* d0 = *src++ */
|
||||
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
|
||||
" move %0@,%%d1\n" /* d1 = *dst */
|
||||
" extl %%d1\n" /* extend d1 to 32 bits */
|
||||
" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
|
||||
" addl %%d1,%%d0\n"
|
||||
" cmpl %%d2,%%d0\n"
|
||||
" bges lower_limit_s16msb\n"
|
||||
" move %%d2,%%d0\n"
|
||||
"lower_limit_s16msb:\n"
|
||||
" cmpl %%d3,%%d0\n"
|
||||
" bles upper_limit_s16msb\n"
|
||||
" move %%d3,%%d0\n"
|
||||
"upper_limit_s16msb:\n" " move %%d0,%0@+\n"
|
||||
/* Loop till done */
|
||||
" subql #1,%2\n" " bhis mixloop_s16msb\n" "stoploop_s16msb:\n": /* no return value */
|
||||
: /* input */
|
||||
"a"(dst), "a"(src), "d"(len), "d"(volume): /* clobbered registers */
|
||||
"d0", "d1", "d2", "d3", "cc", "memory");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_MixAudio_m68k_S16LSB(short *dst, short *src, long len, long volume)
|
||||
{
|
||||
__asm__ __volatile__("tstl %2\n"
|
||||
" beqs stoploop_s16lsb\n"
|
||||
" movel #-32768,%%d2\n"
|
||||
" movel #32767,%%d3\n"
|
||||
" lsrl #1,%2\n" "mixloop_s16lsb:\n"
|
||||
/* Mix a sample */
|
||||
" move %1@+,%%d0\n" /* d0 = *src++ */
|
||||
" rorw #8,%%d0\n" " muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
|
||||
" move %0@,%%d1\n" /* d1 = *dst */
|
||||
" rorw #8,%%d1\n" " extl %%d1\n" /* extend d1 to 32 bits */
|
||||
" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
|
||||
" addl %%d1,%%d0\n"
|
||||
" cmpl %%d2,%%d0\n"
|
||||
" bges lower_limit_s16lsb\n"
|
||||
" move %%d2,%%d0\n"
|
||||
"lower_limit_s16lsb:\n"
|
||||
" cmpl %%d3,%%d0\n"
|
||||
" bles upper_limit_s16lsb\n"
|
||||
" move %%d3,%%d0\n"
|
||||
"upper_limit_s16lsb:\n"
|
||||
" rorw #8,%%d0\n" " move %%d0,%0@+\n"
|
||||
/* Loop till done */
|
||||
" subql #1,%2\n" " bhis mixloop_s16lsb\n" "stoploop_s16lsb:\n": /* no return value */
|
||||
: /* input */
|
||||
"a"(dst), "a"(src), "d"(len), "d"(volume): /* clobbered registers */
|
||||
"d0", "d1", "d2", "d3", "cc", "memory");
|
||||
}
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/*
|
||||
m68k assembly mix routines
|
||||
|
||||
Patrice Mandin
|
||||
*/
|
||||
|
||||
#if defined(__M68000__) && defined(__GNUC__)
|
||||
void SDL_MixAudio_m68k_U8(char *dst, char *src, long len, long volume,
|
||||
char *mix8);
|
||||
void SDL_MixAudio_m68k_S8(char *dst, char *src, long len, long volume);
|
||||
|
||||
void SDL_MixAudio_m68k_S16MSB(short *dst, short *src, long len, long volume);
|
||||
void SDL_MixAudio_m68k_S16LSB(short *dst, short *src, long len, long volume);
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is SDL_free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_sysaudio_h
|
||||
#define _SDL_sysaudio_h
|
||||
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* The SDL audio driver */
|
||||
typedef struct SDL_AudioDevice SDL_AudioDevice;
|
||||
#define _THIS SDL_AudioDevice *_this
|
||||
|
||||
typedef struct SDL_AudioDriverImpl
|
||||
{
|
||||
int (*DetectDevices) (int iscapture);
|
||||
const char *(*GetDeviceName) (int index, int iscapture);
|
||||
int (*OpenDevice) (_THIS, const char *devname, int iscapture);
|
||||
void (*ThreadInit) (_THIS); /* Called by audio thread at start */
|
||||
void (*WaitDevice) (_THIS);
|
||||
void (*PlayDevice) (_THIS);
|
||||
Uint8 *(*GetDeviceBuf) (_THIS);
|
||||
void (*WaitDone) (_THIS);
|
||||
void (*CloseDevice) (_THIS);
|
||||
void (*LockDevice) (_THIS);
|
||||
void (*UnlockDevice) (_THIS);
|
||||
void (*Deinitialize) (void);
|
||||
|
||||
/* Some flags to push duplicate code into the core and reduce #ifdefs. */
|
||||
int ProvidesOwnCallbackThread:1;
|
||||
int SkipMixerLock:1;
|
||||
int HasCaptureSupport:1;
|
||||
int OnlyHasDefaultOutputDevice:1;
|
||||
int OnlyHasDefaultInputDevice:1;
|
||||
} SDL_AudioDriverImpl;
|
||||
|
||||
|
||||
typedef struct SDL_AudioDriver
|
||||
{
|
||||
/* * * */
|
||||
/* The name of this audio driver */
|
||||
const char *name;
|
||||
|
||||
/* * * */
|
||||
/* The description of this audio driver */
|
||||
const char *desc;
|
||||
|
||||
SDL_AudioDriverImpl impl;
|
||||
} SDL_AudioDriver;
|
||||
|
||||
|
||||
/* Streamer */
|
||||
typedef struct
|
||||
{
|
||||
Uint8 *buffer;
|
||||
int max_len; /* the maximum length in bytes */
|
||||
int read_pos, write_pos; /* the position of the write and read heads in bytes */
|
||||
} SDL_AudioStreamer;
|
||||
|
||||
|
||||
/* Define the SDL audio driver structure */
|
||||
struct SDL_AudioDevice
|
||||
{
|
||||
/* * * */
|
||||
/* Data common to all devices */
|
||||
|
||||
/* The current audio specification (shared with audio thread) */
|
||||
SDL_AudioSpec spec;
|
||||
|
||||
/* An audio conversion block for audio format emulation */
|
||||
SDL_AudioCVT convert;
|
||||
|
||||
/* The streamer, if sample rate conversion necessitates it */
|
||||
int use_streamer;
|
||||
SDL_AudioStreamer streamer;
|
||||
|
||||
/* Current state flags */
|
||||
int iscapture;
|
||||
int enabled;
|
||||
int paused;
|
||||
int opened;
|
||||
|
||||
/* Fake audio buffer for when the audio hardware is busy */
|
||||
Uint8 *fake_stream;
|
||||
|
||||
/* A semaphore for locking the mixing buffers */
|
||||
SDL_mutex *mixer_lock;
|
||||
|
||||
/* A thread to feed the audio device */
|
||||
SDL_Thread *thread;
|
||||
Uint32 threadid;
|
||||
|
||||
/* * * */
|
||||
/* Data private to this driver */
|
||||
struct SDL_PrivateAudioData *hidden;
|
||||
};
|
||||
#undef _THIS
|
||||
|
||||
typedef struct AudioBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
int (*init) (SDL_AudioDriverImpl * impl);
|
||||
int demand_only:1; /* 1==request explicitly, or it won't be available. */
|
||||
} AudioBootStrap;
|
||||
|
||||
#endif /* _SDL_sysaudio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,633 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Microsoft WAVE file loading routines */
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_wave.h"
|
||||
|
||||
|
||||
static int ReadChunk(SDL_RWops * src, Chunk * chunk);
|
||||
|
||||
struct MS_ADPCM_decodestate
|
||||
{
|
||||
Uint8 hPredictor;
|
||||
Uint16 iDelta;
|
||||
Sint16 iSamp1;
|
||||
Sint16 iSamp2;
|
||||
};
|
||||
static struct MS_ADPCM_decoder
|
||||
{
|
||||
WaveFMT wavefmt;
|
||||
Uint16 wSamplesPerBlock;
|
||||
Uint16 wNumCoef;
|
||||
Sint16 aCoeff[7][2];
|
||||
/* * * */
|
||||
struct MS_ADPCM_decodestate state[2];
|
||||
} MS_ADPCM_state;
|
||||
|
||||
static int
|
||||
InitMS_ADPCM(WaveFMT * format)
|
||||
{
|
||||
Uint8 *rogue_feel;
|
||||
Uint16 extra_info;
|
||||
int i;
|
||||
|
||||
/* Set the rogue pointer to the MS_ADPCM specific data */
|
||||
MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
|
||||
MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
|
||||
MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
|
||||
MS_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate);
|
||||
MS_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign);
|
||||
MS_ADPCM_state.wavefmt.bitspersample =
|
||||
SDL_SwapLE16(format->bitspersample);
|
||||
rogue_feel = (Uint8 *) format + sizeof(*format);
|
||||
if (sizeof(*format) == 16) {
|
||||
extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
rogue_feel += sizeof(Uint16);
|
||||
}
|
||||
MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
rogue_feel += sizeof(Uint16);
|
||||
MS_ADPCM_state.wNumCoef = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
rogue_feel += sizeof(Uint16);
|
||||
if (MS_ADPCM_state.wNumCoef != 7) {
|
||||
SDL_SetError("Unknown set of MS_ADPCM coefficients");
|
||||
return (-1);
|
||||
}
|
||||
for (i = 0; i < MS_ADPCM_state.wNumCoef; ++i) {
|
||||
MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
rogue_feel += sizeof(Uint16);
|
||||
MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
rogue_feel += sizeof(Uint16);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static Sint32
|
||||
MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state,
|
||||
Uint8 nybble, Sint16 * coeff)
|
||||
{
|
||||
const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
|
||||
const Sint32 min_audioval = -(1 << (16 - 1));
|
||||
const Sint32 adaptive[] = {
|
||||
230, 230, 230, 230, 307, 409, 512, 614,
|
||||
768, 614, 512, 409, 307, 230, 230, 230
|
||||
};
|
||||
Sint32 new_sample, delta;
|
||||
|
||||
new_sample = ((state->iSamp1 * coeff[0]) +
|
||||
(state->iSamp2 * coeff[1])) / 256;
|
||||
if (nybble & 0x08) {
|
||||
new_sample += state->iDelta * (nybble - 0x10);
|
||||
} else {
|
||||
new_sample += state->iDelta * nybble;
|
||||
}
|
||||
if (new_sample < min_audioval) {
|
||||
new_sample = min_audioval;
|
||||
} else if (new_sample > max_audioval) {
|
||||
new_sample = max_audioval;
|
||||
}
|
||||
delta = ((Sint32) state->iDelta * adaptive[nybble]) / 256;
|
||||
if (delta < 16) {
|
||||
delta = 16;
|
||||
}
|
||||
state->iDelta = (Uint16) delta;
|
||||
state->iSamp2 = state->iSamp1;
|
||||
state->iSamp1 = (Sint16) new_sample;
|
||||
return (new_sample);
|
||||
}
|
||||
|
||||
static int
|
||||
MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
|
||||
{
|
||||
struct MS_ADPCM_decodestate *state[2];
|
||||
Uint8 *freeable, *encoded, *decoded;
|
||||
Sint32 encoded_len, samplesleft;
|
||||
Sint8 nybble, stereo;
|
||||
Sint16 *coeff[2];
|
||||
Sint32 new_sample;
|
||||
|
||||
/* Allocate the proper sized output buffer */
|
||||
encoded_len = *audio_len;
|
||||
encoded = *audio_buf;
|
||||
freeable = *audio_buf;
|
||||
*audio_len = (encoded_len / MS_ADPCM_state.wavefmt.blockalign) *
|
||||
MS_ADPCM_state.wSamplesPerBlock *
|
||||
MS_ADPCM_state.wavefmt.channels * sizeof(Sint16);
|
||||
*audio_buf = (Uint8 *) SDL_malloc(*audio_len);
|
||||
if (*audio_buf == NULL) {
|
||||
SDL_Error(SDL_ENOMEM);
|
||||
return (-1);
|
||||
}
|
||||
decoded = *audio_buf;
|
||||
|
||||
/* Get ready... Go! */
|
||||
stereo = (MS_ADPCM_state.wavefmt.channels == 2);
|
||||
state[0] = &MS_ADPCM_state.state[0];
|
||||
state[1] = &MS_ADPCM_state.state[stereo];
|
||||
while (encoded_len >= MS_ADPCM_state.wavefmt.blockalign) {
|
||||
/* Grab the initial information for this block */
|
||||
state[0]->hPredictor = *encoded++;
|
||||
if (stereo) {
|
||||
state[1]->hPredictor = *encoded++;
|
||||
}
|
||||
state[0]->iDelta = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += sizeof(Sint16);
|
||||
if (stereo) {
|
||||
state[1]->iDelta = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += sizeof(Sint16);
|
||||
}
|
||||
state[0]->iSamp1 = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += sizeof(Sint16);
|
||||
if (stereo) {
|
||||
state[1]->iSamp1 = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += sizeof(Sint16);
|
||||
}
|
||||
state[0]->iSamp2 = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += sizeof(Sint16);
|
||||
if (stereo) {
|
||||
state[1]->iSamp2 = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += sizeof(Sint16);
|
||||
}
|
||||
coeff[0] = MS_ADPCM_state.aCoeff[state[0]->hPredictor];
|
||||
coeff[1] = MS_ADPCM_state.aCoeff[state[1]->hPredictor];
|
||||
|
||||
/* Store the two initial samples we start with */
|
||||
decoded[0] = state[0]->iSamp2 & 0xFF;
|
||||
decoded[1] = state[0]->iSamp2 >> 8;
|
||||
decoded += 2;
|
||||
if (stereo) {
|
||||
decoded[0] = state[1]->iSamp2 & 0xFF;
|
||||
decoded[1] = state[1]->iSamp2 >> 8;
|
||||
decoded += 2;
|
||||
}
|
||||
decoded[0] = state[0]->iSamp1 & 0xFF;
|
||||
decoded[1] = state[0]->iSamp1 >> 8;
|
||||
decoded += 2;
|
||||
if (stereo) {
|
||||
decoded[0] = state[1]->iSamp1 & 0xFF;
|
||||
decoded[1] = state[1]->iSamp1 >> 8;
|
||||
decoded += 2;
|
||||
}
|
||||
|
||||
/* Decode and store the other samples in this block */
|
||||
samplesleft = (MS_ADPCM_state.wSamplesPerBlock - 2) *
|
||||
MS_ADPCM_state.wavefmt.channels;
|
||||
while (samplesleft > 0) {
|
||||
nybble = (*encoded) >> 4;
|
||||
new_sample = MS_ADPCM_nibble(state[0], nybble, coeff[0]);
|
||||
decoded[0] = new_sample & 0xFF;
|
||||
new_sample >>= 8;
|
||||
decoded[1] = new_sample & 0xFF;
|
||||
decoded += 2;
|
||||
|
||||
nybble = (*encoded) & 0x0F;
|
||||
new_sample = MS_ADPCM_nibble(state[1], nybble, coeff[1]);
|
||||
decoded[0] = new_sample & 0xFF;
|
||||
new_sample >>= 8;
|
||||
decoded[1] = new_sample & 0xFF;
|
||||
decoded += 2;
|
||||
|
||||
++encoded;
|
||||
samplesleft -= 2;
|
||||
}
|
||||
encoded_len -= MS_ADPCM_state.wavefmt.blockalign;
|
||||
}
|
||||
SDL_free(freeable);
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct IMA_ADPCM_decodestate
|
||||
{
|
||||
Sint32 sample;
|
||||
Sint8 index;
|
||||
};
|
||||
static struct IMA_ADPCM_decoder
|
||||
{
|
||||
WaveFMT wavefmt;
|
||||
Uint16 wSamplesPerBlock;
|
||||
/* * * */
|
||||
struct IMA_ADPCM_decodestate state[2];
|
||||
} IMA_ADPCM_state;
|
||||
|
||||
static int
|
||||
InitIMA_ADPCM(WaveFMT * format)
|
||||
{
|
||||
Uint8 *rogue_feel;
|
||||
Uint16 extra_info;
|
||||
|
||||
/* Set the rogue pointer to the IMA_ADPCM specific data */
|
||||
IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
|
||||
IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
|
||||
IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
|
||||
IMA_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate);
|
||||
IMA_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign);
|
||||
IMA_ADPCM_state.wavefmt.bitspersample =
|
||||
SDL_SwapLE16(format->bitspersample);
|
||||
rogue_feel = (Uint8 *) format + sizeof(*format);
|
||||
if (sizeof(*format) == 16) {
|
||||
extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
rogue_feel += sizeof(Uint16);
|
||||
}
|
||||
IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static Sint32
|
||||
IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state, Uint8 nybble)
|
||||
{
|
||||
const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
|
||||
const Sint32 min_audioval = -(1 << (16 - 1));
|
||||
const int index_table[16] = {
|
||||
-1, -1, -1, -1,
|
||||
2, 4, 6, 8,
|
||||
-1, -1, -1, -1,
|
||||
2, 4, 6, 8
|
||||
};
|
||||
const Sint32 step_table[89] = {
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
|
||||
34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130,
|
||||
143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408,
|
||||
449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
|
||||
1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327,
|
||||
3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630,
|
||||
9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350,
|
||||
22385, 24623, 27086, 29794, 32767
|
||||
};
|
||||
Sint32 delta, step;
|
||||
|
||||
/* Compute difference and new sample value */
|
||||
step = step_table[state->index];
|
||||
delta = step >> 3;
|
||||
if (nybble & 0x04)
|
||||
delta += step;
|
||||
if (nybble & 0x02)
|
||||
delta += (step >> 1);
|
||||
if (nybble & 0x01)
|
||||
delta += (step >> 2);
|
||||
if (nybble & 0x08)
|
||||
delta = -delta;
|
||||
state->sample += delta;
|
||||
|
||||
/* Update index value */
|
||||
state->index += index_table[nybble];
|
||||
if (state->index > 88) {
|
||||
state->index = 88;
|
||||
} else if (state->index < 0) {
|
||||
state->index = 0;
|
||||
}
|
||||
|
||||
/* Clamp output sample */
|
||||
if (state->sample > max_audioval) {
|
||||
state->sample = max_audioval;
|
||||
} else if (state->sample < min_audioval) {
|
||||
state->sample = min_audioval;
|
||||
}
|
||||
return (state->sample);
|
||||
}
|
||||
|
||||
/* Fill the decode buffer with a channel block of data (8 samples) */
|
||||
static void
|
||||
Fill_IMA_ADPCM_block(Uint8 * decoded, Uint8 * encoded,
|
||||
int channel, int numchannels,
|
||||
struct IMA_ADPCM_decodestate *state)
|
||||
{
|
||||
int i;
|
||||
Sint8 nybble;
|
||||
Sint32 new_sample;
|
||||
|
||||
decoded += (channel * 2);
|
||||
for (i = 0; i < 4; ++i) {
|
||||
nybble = (*encoded) & 0x0F;
|
||||
new_sample = IMA_ADPCM_nibble(state, nybble);
|
||||
decoded[0] = new_sample & 0xFF;
|
||||
new_sample >>= 8;
|
||||
decoded[1] = new_sample & 0xFF;
|
||||
decoded += 2 * numchannels;
|
||||
|
||||
nybble = (*encoded) >> 4;
|
||||
new_sample = IMA_ADPCM_nibble(state, nybble);
|
||||
decoded[0] = new_sample & 0xFF;
|
||||
new_sample >>= 8;
|
||||
decoded[1] = new_sample & 0xFF;
|
||||
decoded += 2 * numchannels;
|
||||
|
||||
++encoded;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
|
||||
{
|
||||
struct IMA_ADPCM_decodestate *state;
|
||||
Uint8 *freeable, *encoded, *decoded;
|
||||
Sint32 encoded_len, samplesleft;
|
||||
unsigned int c, channels;
|
||||
|
||||
/* Check to make sure we have enough variables in the state array */
|
||||
channels = IMA_ADPCM_state.wavefmt.channels;
|
||||
if (channels > SDL_arraysize(IMA_ADPCM_state.state)) {
|
||||
SDL_SetError("IMA ADPCM decoder can only handle %d channels",
|
||||
SDL_arraysize(IMA_ADPCM_state.state));
|
||||
return (-1);
|
||||
}
|
||||
state = IMA_ADPCM_state.state;
|
||||
|
||||
/* Allocate the proper sized output buffer */
|
||||
encoded_len = *audio_len;
|
||||
encoded = *audio_buf;
|
||||
freeable = *audio_buf;
|
||||
*audio_len = (encoded_len / IMA_ADPCM_state.wavefmt.blockalign) *
|
||||
IMA_ADPCM_state.wSamplesPerBlock *
|
||||
IMA_ADPCM_state.wavefmt.channels * sizeof(Sint16);
|
||||
*audio_buf = (Uint8 *) SDL_malloc(*audio_len);
|
||||
if (*audio_buf == NULL) {
|
||||
SDL_Error(SDL_ENOMEM);
|
||||
return (-1);
|
||||
}
|
||||
decoded = *audio_buf;
|
||||
|
||||
/* Get ready... Go! */
|
||||
while (encoded_len >= IMA_ADPCM_state.wavefmt.blockalign) {
|
||||
/* Grab the initial information for this block */
|
||||
for (c = 0; c < channels; ++c) {
|
||||
/* Fill the state information for this block */
|
||||
state[c].sample = ((encoded[1] << 8) | encoded[0]);
|
||||
encoded += 2;
|
||||
if (state[c].sample & 0x8000) {
|
||||
state[c].sample -= 0x10000;
|
||||
}
|
||||
state[c].index = *encoded++;
|
||||
/* Reserved byte in buffer header, should be 0 */
|
||||
if (*encoded++ != 0) {
|
||||
/* Uh oh, corrupt data? Buggy code? */ ;
|
||||
}
|
||||
|
||||
/* Store the initial sample we start with */
|
||||
decoded[0] = (Uint8) (state[c].sample & 0xFF);
|
||||
decoded[1] = (Uint8) (state[c].sample >> 8);
|
||||
decoded += 2;
|
||||
}
|
||||
|
||||
/* Decode and store the other samples in this block */
|
||||
samplesleft = (IMA_ADPCM_state.wSamplesPerBlock - 1) * channels;
|
||||
while (samplesleft > 0) {
|
||||
for (c = 0; c < channels; ++c) {
|
||||
Fill_IMA_ADPCM_block(decoded, encoded,
|
||||
c, channels, &state[c]);
|
||||
encoded += 4;
|
||||
samplesleft -= 8;
|
||||
}
|
||||
decoded += (channels * 8 * 2);
|
||||
}
|
||||
encoded_len -= IMA_ADPCM_state.wavefmt.blockalign;
|
||||
}
|
||||
SDL_free(freeable);
|
||||
return (0);
|
||||
}
|
||||
|
||||
SDL_AudioSpec *
|
||||
SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
|
||||
SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)
|
||||
{
|
||||
int was_error;
|
||||
Chunk chunk;
|
||||
int lenread;
|
||||
int IEEE_float_encoded, MS_ADPCM_encoded, IMA_ADPCM_encoded;
|
||||
int samplesize;
|
||||
|
||||
/* WAV magic header */
|
||||
Uint32 RIFFchunk;
|
||||
Uint32 wavelen = 0;
|
||||
Uint32 WAVEmagic;
|
||||
Uint32 headerDiff = 0;
|
||||
|
||||
/* FMT chunk */
|
||||
WaveFMT *format = NULL;
|
||||
|
||||
/* Make sure we are passed a valid data source */
|
||||
was_error = 0;
|
||||
if (src == NULL) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Check the magic header */
|
||||
RIFFchunk = SDL_ReadLE32(src);
|
||||
wavelen = SDL_ReadLE32(src);
|
||||
if (wavelen == WAVE) { /* The RIFFchunk has already been read */
|
||||
WAVEmagic = wavelen;
|
||||
wavelen = RIFFchunk;
|
||||
RIFFchunk = RIFF;
|
||||
} else {
|
||||
WAVEmagic = SDL_ReadLE32(src);
|
||||
}
|
||||
if ((RIFFchunk != RIFF) || (WAVEmagic != WAVE)) {
|
||||
SDL_SetError("Unrecognized file type (not WAVE)");
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
headerDiff += sizeof(Uint32); /* for WAVE */
|
||||
|
||||
/* Read the audio data format chunk */
|
||||
chunk.data = NULL;
|
||||
do {
|
||||
if (chunk.data != NULL) {
|
||||
SDL_free(chunk.data);
|
||||
}
|
||||
lenread = ReadChunk(src, &chunk);
|
||||
if (lenread < 0) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
/* 2 Uint32's for chunk header+len, plus the lenread */
|
||||
headerDiff += lenread + 2 * sizeof(Uint32);
|
||||
} while ((chunk.magic == FACT) || (chunk.magic == LIST));
|
||||
|
||||
/* Decode the audio data format */
|
||||
format = (WaveFMT *) chunk.data;
|
||||
if (chunk.magic != FMT) {
|
||||
SDL_SetError("Complex WAVE files not supported");
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
IEEE_float_encoded = MS_ADPCM_encoded = IMA_ADPCM_encoded = 0;
|
||||
switch (SDL_SwapLE16(format->encoding)) {
|
||||
case PCM_CODE:
|
||||
/* We can understand this */
|
||||
break;
|
||||
case IEEE_FLOAT_CODE:
|
||||
IEEE_float_encoded = 1;
|
||||
/* We can understand this */
|
||||
break;
|
||||
case MS_ADPCM_CODE:
|
||||
/* Try to understand this */
|
||||
if (InitMS_ADPCM(format) < 0) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
MS_ADPCM_encoded = 1;
|
||||
break;
|
||||
case IMA_ADPCM_CODE:
|
||||
/* Try to understand this */
|
||||
if (InitIMA_ADPCM(format) < 0) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
IMA_ADPCM_encoded = 1;
|
||||
break;
|
||||
case MP3_CODE:
|
||||
SDL_SetError("MPEG Layer 3 data not supported",
|
||||
SDL_SwapLE16(format->encoding));
|
||||
was_error = 1;
|
||||
goto done;
|
||||
default:
|
||||
SDL_SetError("Unknown WAVE data format: 0x%.4x",
|
||||
SDL_SwapLE16(format->encoding));
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
SDL_memset(spec, 0, (sizeof *spec));
|
||||
spec->freq = SDL_SwapLE32(format->frequency);
|
||||
|
||||
if (IEEE_float_encoded) {
|
||||
if ((SDL_SwapLE16(format->bitspersample)) != 32) {
|
||||
was_error = 1;
|
||||
} else {
|
||||
spec->format = AUDIO_F32;
|
||||
}
|
||||
} else {
|
||||
switch (SDL_SwapLE16(format->bitspersample)) {
|
||||
case 4:
|
||||
if (MS_ADPCM_encoded || IMA_ADPCM_encoded) {
|
||||
spec->format = AUDIO_S16;
|
||||
} else {
|
||||
was_error = 1;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
spec->format = AUDIO_U8;
|
||||
break;
|
||||
case 16:
|
||||
spec->format = AUDIO_S16;
|
||||
break;
|
||||
case 32:
|
||||
spec->format = AUDIO_S32;
|
||||
break;
|
||||
default:
|
||||
was_error = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (was_error) {
|
||||
SDL_SetError("Unknown %d-bit PCM data format",
|
||||
SDL_SwapLE16(format->bitspersample));
|
||||
goto done;
|
||||
}
|
||||
spec->channels = (Uint8) SDL_SwapLE16(format->channels);
|
||||
spec->samples = 4096; /* Good default buffer size */
|
||||
|
||||
/* Read the audio data chunk */
|
||||
*audio_buf = NULL;
|
||||
do {
|
||||
if (*audio_buf != NULL) {
|
||||
SDL_free(*audio_buf);
|
||||
}
|
||||
lenread = ReadChunk(src, &chunk);
|
||||
if (lenread < 0) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
*audio_len = lenread;
|
||||
*audio_buf = chunk.data;
|
||||
if (chunk.magic != DATA)
|
||||
headerDiff += lenread + 2 * sizeof(Uint32);
|
||||
} while (chunk.magic != DATA);
|
||||
headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */
|
||||
|
||||
if (MS_ADPCM_encoded) {
|
||||
if (MS_ADPCM_decode(audio_buf, audio_len) < 0) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (IMA_ADPCM_encoded) {
|
||||
if (IMA_ADPCM_decode(audio_buf, audio_len) < 0) {
|
||||
was_error = 1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't return a buffer that isn't a multiple of samplesize */
|
||||
samplesize = ((SDL_AUDIO_BITSIZE(spec->format)) / 8) * spec->channels;
|
||||
*audio_len &= ~(samplesize - 1);
|
||||
|
||||
done:
|
||||
if (format != NULL) {
|
||||
SDL_free(format);
|
||||
}
|
||||
if (src) {
|
||||
if (freesrc) {
|
||||
SDL_RWclose(src);
|
||||
} else {
|
||||
/* seek to the end of the file (given by the RIFF chunk) */
|
||||
SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
|
||||
}
|
||||
}
|
||||
if (was_error) {
|
||||
spec = NULL;
|
||||
}
|
||||
return (spec);
|
||||
}
|
||||
|
||||
/* Since the WAV memory is allocated in the shared library, it must also
|
||||
be freed here. (Necessary under Win32, VC++)
|
||||
*/
|
||||
void
|
||||
SDL_FreeWAV(Uint8 * audio_buf)
|
||||
{
|
||||
if (audio_buf != NULL) {
|
||||
SDL_free(audio_buf);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ReadChunk(SDL_RWops * src, Chunk * chunk)
|
||||
{
|
||||
chunk->magic = SDL_ReadLE32(src);
|
||||
chunk->length = SDL_ReadLE32(src);
|
||||
chunk->data = (Uint8 *) SDL_malloc(chunk->length);
|
||||
if (chunk->data == NULL) {
|
||||
SDL_Error(SDL_ENOMEM);
|
||||
return (-1);
|
||||
}
|
||||
if (SDL_RWread(src, chunk->data, chunk->length, 1) != 1) {
|
||||
SDL_Error(SDL_EFREAD);
|
||||
SDL_free(chunk->data);
|
||||
return (-1);
|
||||
}
|
||||
return (chunk->length);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is SDL_free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* WAVE files are little-endian */
|
||||
|
||||
/*******************************************/
|
||||
/* Define values for Microsoft WAVE format */
|
||||
/*******************************************/
|
||||
#define RIFF 0x46464952 /* "RIFF" */
|
||||
#define WAVE 0x45564157 /* "WAVE" */
|
||||
#define FACT 0x74636166 /* "fact" */
|
||||
#define LIST 0x5453494c /* "LIST" */
|
||||
#define FMT 0x20746D66 /* "fmt " */
|
||||
#define DATA 0x61746164 /* "data" */
|
||||
#define PCM_CODE 0x0001
|
||||
#define MS_ADPCM_CODE 0x0002
|
||||
#define IEEE_FLOAT_CODE 0x0003
|
||||
#define IMA_ADPCM_CODE 0x0011
|
||||
#define MP3_CODE 0x0055
|
||||
#define WAVE_MONO 1
|
||||
#define WAVE_STEREO 2
|
||||
|
||||
/* Normally, these three chunks come consecutively in a WAVE file */
|
||||
typedef struct WaveFMT
|
||||
{
|
||||
/* Not saved in the chunk we read:
|
||||
Uint32 FMTchunk;
|
||||
Uint32 fmtlen;
|
||||
*/
|
||||
Uint16 encoding;
|
||||
Uint16 channels; /* 1 = mono, 2 = stereo */
|
||||
Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */
|
||||
Uint32 byterate; /* Average bytes per second */
|
||||
Uint16 blockalign; /* Bytes per sample block */
|
||||
Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */
|
||||
} WaveFMT;
|
||||
|
||||
/* The general chunk found in the WAVE file */
|
||||
typedef struct Chunk
|
||||
{
|
||||
Uint32 magic;
|
||||
Uint32 length;
|
||||
Uint8 *data;
|
||||
} Chunk;
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,621 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to a raw mixing buffer */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h> /* For kill() */
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_alsa_audio.h"
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
|
||||
#include "SDL_loadso.h"
|
||||
#endif
|
||||
|
||||
/* The tag name used by ALSA audio */
|
||||
#define DRIVER_NAME "alsa"
|
||||
|
||||
/* The default ALSA audio driver */
|
||||
#define DEFAULT_DEVICE "default"
|
||||
|
||||
static int (*ALSA_snd_pcm_open)
|
||||
(snd_pcm_t **, const char *, snd_pcm_stream_t, int);
|
||||
static int (*ALSA_snd_pcm_close) (snd_pcm_t * pcm);
|
||||
static snd_pcm_sframes_t(*ALSA_snd_pcm_writei)
|
||||
(snd_pcm_t *, const void *, snd_pcm_uframes_t);
|
||||
static int (*ALSA_snd_pcm_resume) (snd_pcm_t *);
|
||||
static int (*ALSA_snd_pcm_prepare) (snd_pcm_t *);
|
||||
static int (*ALSA_snd_pcm_drain) (snd_pcm_t *);
|
||||
static const char *(*ALSA_snd_strerror) (int);
|
||||
static size_t(*ALSA_snd_pcm_hw_params_sizeof) (void);
|
||||
static size_t(*ALSA_snd_pcm_sw_params_sizeof) (void);
|
||||
static int (*ALSA_snd_pcm_hw_params_any) (snd_pcm_t *, snd_pcm_hw_params_t *);
|
||||
static int (*ALSA_snd_pcm_hw_params_set_access)
|
||||
(snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_t);
|
||||
static int (*ALSA_snd_pcm_hw_params_set_format)
|
||||
(snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
|
||||
static int (*ALSA_snd_pcm_hw_params_set_channels)
|
||||
(snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
|
||||
static int (*ALSA_snd_pcm_hw_params_set_rate_near)
|
||||
(snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
|
||||
static int (*ALSA_snd_pcm_hw_params_set_period_size_near)
|
||||
(snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
|
||||
static int (*ALSA_snd_pcm_hw_params_get_channels)
|
||||
(const snd_pcm_hw_params_t *, unsigned int *);
|
||||
static snd_pcm_sframes_t(*ALSA_snd_pcm_hw_params_get_period_size)
|
||||
(const snd_pcm_hw_params_t *);
|
||||
static int (*ALSA_snd_pcm_hw_params_set_periods_near)
|
||||
(snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
|
||||
static int (*ALSA_snd_pcm_hw_params_get_periods) (snd_pcm_hw_params_t *);
|
||||
static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *);
|
||||
static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *,
|
||||
snd_pcm_sw_params_t *);
|
||||
static int (*ALSA_snd_pcm_sw_params_set_start_threshold)
|
||||
(snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
|
||||
static int (*ALSA_snd_pcm_sw_params_set_avail_min)
|
||||
(snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
|
||||
static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *);
|
||||
static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int);
|
||||
#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
|
||||
#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
|
||||
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
|
||||
|
||||
static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
|
||||
static void *alsa_handle = NULL;
|
||||
|
||||
static int
|
||||
load_alsa_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(alsa_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
/* Don't call SDL_SetError(): SDL_LoadFunction already did. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cast funcs to char* first, to please GCC's strict aliasing rules. */
|
||||
#define SDL_ALSA_SYM(x) \
|
||||
if (!load_alsa_sym(#x, (void **) (char *) &ALSA_##x)) return -1
|
||||
#else
|
||||
#define SDL_ALSA_SYM(x) ALSA_##x = x
|
||||
#endif
|
||||
|
||||
static int
|
||||
load_alsa_syms(void)
|
||||
{
|
||||
SDL_ALSA_SYM(snd_pcm_open);
|
||||
SDL_ALSA_SYM(snd_pcm_close);
|
||||
SDL_ALSA_SYM(snd_pcm_writei);
|
||||
SDL_ALSA_SYM(snd_pcm_resume);
|
||||
SDL_ALSA_SYM(snd_pcm_prepare);
|
||||
SDL_ALSA_SYM(snd_pcm_drain);
|
||||
SDL_ALSA_SYM(snd_strerror);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_sizeof);
|
||||
SDL_ALSA_SYM(snd_pcm_sw_params_sizeof);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_any);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_set_access);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_set_format);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_set_channels);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_get_channels);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_set_rate_near);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_set_period_size_near);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_get_period_size);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_set_periods_near);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params_get_periods);
|
||||
SDL_ALSA_SYM(snd_pcm_hw_params);
|
||||
SDL_ALSA_SYM(snd_pcm_sw_params_current);
|
||||
SDL_ALSA_SYM(snd_pcm_sw_params_set_start_threshold);
|
||||
SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min);
|
||||
SDL_ALSA_SYM(snd_pcm_sw_params);
|
||||
SDL_ALSA_SYM(snd_pcm_nonblock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef SDL_ALSA_SYM
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
|
||||
|
||||
static void
|
||||
UnloadALSALibrary(void)
|
||||
{
|
||||
if (alsa_handle != NULL) {
|
||||
SDL_UnloadObject(alsa_handle);
|
||||
alsa_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
LoadALSALibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (alsa_handle == NULL) {
|
||||
alsa_handle = SDL_LoadObject(alsa_library);
|
||||
if (alsa_handle == NULL) {
|
||||
retval = -1;
|
||||
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
|
||||
} else {
|
||||
retval = load_alsa_syms();
|
||||
if (retval < 0) {
|
||||
UnloadALSALibrary();
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void
|
||||
UnloadALSALibrary(void)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
LoadALSALibrary(void)
|
||||
{
|
||||
load_alsa_syms();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_AUDIO_DRIVER_ALSA_DYNAMIC */
|
||||
|
||||
static const char *
|
||||
get_audio_device(int channels)
|
||||
{
|
||||
const char *device;
|
||||
|
||||
device = SDL_getenv("AUDIODEV"); /* Is there a standard variable name? */
|
||||
if (device == NULL) {
|
||||
if (channels == 6)
|
||||
device = "surround51";
|
||||
else if (channels == 4)
|
||||
device = "surround40";
|
||||
else
|
||||
device = DEFAULT_DEVICE;
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
ALSA_WaitDevice(_THIS)
|
||||
{
|
||||
/* Check to see if the thread-parent process is still alive */
|
||||
{
|
||||
static int cnt = 0;
|
||||
/* Note that this only works with thread implementations
|
||||
that use a different process id for each thread.
|
||||
*/
|
||||
/* Check every 10 loops */
|
||||
if (this->hidden->parent && (((++cnt) % 10) == 0)) {
|
||||
if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* !!! FIXME: is there a channel swizzler in alsalib instead? */
|
||||
/*
|
||||
* http://bugzilla.libsdl.org/show_bug.cgi?id=110
|
||||
* "For Linux ALSA, this is FL-FR-RL-RR-C-LFE
|
||||
* and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR"
|
||||
*/
|
||||
#define SWIZ6(T) \
|
||||
T *ptr = (T *) this->hidden->mixbuf; \
|
||||
const Uint32 count = (this->spec.samples / 6); \
|
||||
Uint32 i; \
|
||||
for (i = 0; i < count; i++, ptr += 6) { \
|
||||
T tmp; \
|
||||
tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
|
||||
tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
swizzle_alsa_channels_6_64bit(_THIS)
|
||||
{
|
||||
SWIZ6(Uint64);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
swizzle_alsa_channels_6_32bit(_THIS)
|
||||
{
|
||||
SWIZ6(Uint32);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
swizzle_alsa_channels_6_16bit(_THIS)
|
||||
{
|
||||
SWIZ6(Uint16);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
swizzle_alsa_channels_6_8bit(_THIS)
|
||||
{
|
||||
SWIZ6(Uint8);
|
||||
}
|
||||
|
||||
#undef SWIZ6
|
||||
|
||||
|
||||
/*
|
||||
* Called right before feeding this->hidden->mixbuf to the hardware. Swizzle
|
||||
* channels from Windows/Mac order to the format alsalib will want.
|
||||
*/
|
||||
static __inline__ void
|
||||
swizzle_alsa_channels(_THIS)
|
||||
{
|
||||
if (this->spec.channels == 6) {
|
||||
const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */
|
||||
if (fmtsize == 16)
|
||||
swizzle_alsa_channels_6_16bit(this);
|
||||
else if (fmtsize == 8)
|
||||
swizzle_alsa_channels_6_8bit(this);
|
||||
else if (fmtsize == 32)
|
||||
swizzle_alsa_channels_6_32bit(this);
|
||||
else if (fmtsize == 64)
|
||||
swizzle_alsa_channels_6_64bit(this);
|
||||
}
|
||||
|
||||
/* !!! FIXME: update this for 7.1 if needed, later. */
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ALSA_PlayDevice(_THIS)
|
||||
{
|
||||
int status;
|
||||
int sample_len;
|
||||
signed short *sample_buf;
|
||||
|
||||
swizzle_alsa_channels(this);
|
||||
|
||||
sample_len = this->spec.samples;
|
||||
sample_buf = (signed short *) this->hidden->mixbuf;
|
||||
|
||||
while (sample_len > 0) {
|
||||
status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
|
||||
sample_buf, sample_len);
|
||||
|
||||
if (status < 0) {
|
||||
if (status == -EAGAIN) {
|
||||
SDL_Delay(1);
|
||||
continue;
|
||||
}
|
||||
if (status == -ESTRPIPE) {
|
||||
do {
|
||||
SDL_Delay(1);
|
||||
status = ALSA_snd_pcm_resume(this->hidden->pcm_handle);
|
||||
} while (status == -EAGAIN);
|
||||
}
|
||||
if (status < 0) {
|
||||
status = ALSA_snd_pcm_prepare(this->hidden->pcm_handle);
|
||||
}
|
||||
if (status < 0) {
|
||||
/* Hmm, not much we can do - abort */
|
||||
this->enabled = 0;
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
sample_buf += status * this->spec.channels;
|
||||
sample_len -= status;
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
ALSA_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
ALSA_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->pcm_handle) {
|
||||
ALSA_snd_pcm_drain(this->hidden->pcm_handle);
|
||||
ALSA_snd_pcm_close(this->hidden->pcm_handle);
|
||||
this->hidden->pcm_handle = NULL;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
int status = 0;
|
||||
snd_pcm_t *pcm_handle = NULL;
|
||||
snd_pcm_hw_params_t *hwparams = NULL;
|
||||
snd_pcm_sw_params_t *swparams = NULL;
|
||||
snd_pcm_format_t format = 0;
|
||||
snd_pcm_uframes_t frames = 0;
|
||||
SDL_AudioFormat test_format = 0;
|
||||
unsigned int rate = 0;
|
||||
unsigned int periods = 0;
|
||||
unsigned int channels = 0;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Open the audio device */
|
||||
/* Name of device should depend on # channels in spec */
|
||||
status = ALSA_snd_pcm_open(&pcm_handle,
|
||||
get_audio_device(this->spec.channels),
|
||||
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
|
||||
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't open audio device: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->hidden->pcm_handle = pcm_handle;
|
||||
|
||||
/* Figure out what the hardware is capable of */
|
||||
snd_pcm_hw_params_alloca(&hwparams);
|
||||
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't get hardware config: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SDL only uses interleaved sample output */
|
||||
status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't set interleaved access: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
status = -1;
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
test_format && (status < 0);) {
|
||||
status = 0; /* if we can't support a format, it'll become -1. */
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
format = SND_PCM_FORMAT_U8;
|
||||
break;
|
||||
case AUDIO_S8:
|
||||
format = SND_PCM_FORMAT_S8;
|
||||
break;
|
||||
case AUDIO_S16LSB:
|
||||
format = SND_PCM_FORMAT_S16_LE;
|
||||
break;
|
||||
case AUDIO_S16MSB:
|
||||
format = SND_PCM_FORMAT_S16_BE;
|
||||
break;
|
||||
case AUDIO_U16LSB:
|
||||
format = SND_PCM_FORMAT_U16_LE;
|
||||
break;
|
||||
case AUDIO_U16MSB:
|
||||
format = SND_PCM_FORMAT_U16_BE;
|
||||
break;
|
||||
case AUDIO_S32LSB:
|
||||
format = SND_PCM_FORMAT_S32_LE;
|
||||
break;
|
||||
case AUDIO_S32MSB:
|
||||
format = SND_PCM_FORMAT_S32_BE;
|
||||
break;
|
||||
case AUDIO_F32LSB:
|
||||
format = SND_PCM_FORMAT_FLOAT_LE;
|
||||
break;
|
||||
case AUDIO_F32MSB:
|
||||
format = SND_PCM_FORMAT_FLOAT_BE;
|
||||
break;
|
||||
default:
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
if (status >= 0) {
|
||||
status = ALSA_snd_pcm_hw_params_set_format(pcm_handle,
|
||||
hwparams, format);
|
||||
}
|
||||
if (status < 0) {
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
}
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't find any hardware audio formats");
|
||||
return 0;
|
||||
}
|
||||
this->spec.format = test_format;
|
||||
|
||||
/* Set the number of channels */
|
||||
status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
|
||||
this->spec.channels);
|
||||
channels = this->spec.channels;
|
||||
if (status < 0) {
|
||||
status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't set audio channels");
|
||||
return 0;
|
||||
}
|
||||
this->spec.channels = channels;
|
||||
}
|
||||
|
||||
/* Set the audio rate */
|
||||
rate = this->spec.freq;
|
||||
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
|
||||
&rate, NULL);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't set audio frequency: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
this->spec.freq = rate;
|
||||
|
||||
/* Set the buffer size, in samples */
|
||||
frames = this->spec.samples;
|
||||
status = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
|
||||
&frames, NULL);
|
||||
if ( status < 0 ) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't set audio frequency: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return(-1);
|
||||
}
|
||||
this->spec.samples = frames;
|
||||
|
||||
periods = 2;
|
||||
ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams,
|
||||
&periods, NULL);
|
||||
|
||||
/* "set" the hardware with the desired parameters */
|
||||
status = ALSA_snd_pcm_hw_params(pcm_handle, hwparams);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't set hardware audio parameters: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
#if AUDIO_DEBUG
|
||||
{
|
||||
snd_pcm_sframes_t bufsize;
|
||||
int fragments;
|
||||
bufsize = ALSA_snd_pcm_hw_params_get_period_size(hwparams);
|
||||
fragments = ALSA_snd_pcm_hw_params_get_periods(hwparams);
|
||||
fprintf(stderr, "ALSA: bufsize = %ld, fragments = %d\n", bufsize,
|
||||
fragments);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set the software parameters */
|
||||
snd_pcm_sw_params_alloca(&swparams);
|
||||
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't get software config: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
status =
|
||||
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 0);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("ALSA: Couldn't set start threshold: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
status =
|
||||
ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, frames);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't set avail min: %s", ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
|
||||
if (status < 0) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't set software audio parameters: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
ALSA_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
/* Get the parent process id (we're the parent of the audio thread) */
|
||||
this->hidden->parent = getpid();
|
||||
|
||||
/* Switch to blocking mode for playback */
|
||||
ALSA_snd_pcm_nonblock(pcm_handle, 0);
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
ALSA_Deinitialize(void)
|
||||
{
|
||||
UnloadALSALibrary();
|
||||
}
|
||||
|
||||
static int
|
||||
ALSA_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
if (LoadALSALibrary() < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = ALSA_OpenDevice;
|
||||
impl->WaitDevice = ALSA_WaitDevice;
|
||||
impl->GetDeviceBuf = ALSA_GetDeviceBuf;
|
||||
impl->PlayDevice = ALSA_PlayDevice;
|
||||
impl->CloseDevice = ALSA_CloseDevice;
|
||||
impl->Deinitialize = ALSA_Deinitialize;
|
||||
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */
|
||||
|
||||
return 1; /* !!! FIXME: return 2 once device enum is implemented. */
|
||||
}
|
||||
|
||||
|
||||
AudioBootStrap ALSA_bootstrap = {
|
||||
DRIVER_NAME, "ALSA 0.9 PCM audio", ALSA_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _ALSA_PCM_audio_h
|
||||
#define _ALSA_PCM_audio_h
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The audio device handle */
|
||||
snd_pcm_t *pcm_handle;
|
||||
|
||||
/* The parent process id, to detect when application quits */
|
||||
pid_t parent;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *mixbuf;
|
||||
int mixlen;
|
||||
};
|
||||
|
||||
#endif /* _ALSA_PCM_audio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,379 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to a raw mixing buffer */
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_artsaudio.h"
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
|
||||
#include "SDL_name.h"
|
||||
#include "SDL_loadso.h"
|
||||
#else
|
||||
#define SDL_NAME(X) X
|
||||
#endif
|
||||
|
||||
/* The tag name used by artsc audio */
|
||||
#define ARTS_DRIVER_NAME "arts"
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
|
||||
|
||||
static const char *arts_library = SDL_AUDIO_DRIVER_ARTS_DYNAMIC;
|
||||
static void *arts_handle = NULL;
|
||||
|
||||
/* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */
|
||||
static int (*SDL_NAME(arts_init)) (void);
|
||||
static void (*SDL_NAME(arts_free)) (void);
|
||||
static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
|
||||
int channels,
|
||||
const char *name);
|
||||
static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
|
||||
arts_parameter_t param, int value);
|
||||
static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
|
||||
arts_parameter_t param);
|
||||
static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
|
||||
int count);
|
||||
static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
|
||||
static int (*SDL_NAME(arts_suspended)) (void);
|
||||
static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
|
||||
|
||||
#define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
void **func;
|
||||
} arts_functions[] = {
|
||||
/* *INDENT-OFF* */
|
||||
SDL_ARTS_SYM(arts_init),
|
||||
SDL_ARTS_SYM(arts_free),
|
||||
SDL_ARTS_SYM(arts_play_stream),
|
||||
SDL_ARTS_SYM(arts_stream_set),
|
||||
SDL_ARTS_SYM(arts_stream_get),
|
||||
SDL_ARTS_SYM(arts_write),
|
||||
SDL_ARTS_SYM(arts_close_stream),
|
||||
SDL_ARTS_SYM(arts_suspended),
|
||||
SDL_ARTS_SYM(arts_error_text),
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
#undef SDL_ARTS_SYM
|
||||
|
||||
static void
|
||||
UnloadARTSLibrary()
|
||||
{
|
||||
if (arts_handle != NULL) {
|
||||
SDL_UnloadObject(arts_handle);
|
||||
arts_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
LoadARTSLibrary(void)
|
||||
{
|
||||
int i, retval = -1;
|
||||
|
||||
if (arts_handle == NULL) {
|
||||
arts_handle = SDL_LoadObject(arts_library);
|
||||
if (arts_handle != NULL) {
|
||||
retval = 0;
|
||||
for (i = 0; i < SDL_arraysize(arts_functions); ++i) {
|
||||
*arts_functions[i].func =
|
||||
SDL_LoadFunction(arts_handle, arts_functions[i].name);
|
||||
if (!*arts_functions[i].func) {
|
||||
retval = -1;
|
||||
UnloadARTSLibrary();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void
|
||||
UnloadARTSLibrary()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
LoadARTSLibrary(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
ARTS_WaitDevice(_THIS)
|
||||
{
|
||||
Sint32 ticks;
|
||||
|
||||
/* Check to see if the thread-parent process is still alive */
|
||||
{
|
||||
static int cnt = 0;
|
||||
/* Note that this only works with thread implementations
|
||||
that use a different process id for each thread.
|
||||
*/
|
||||
/* Check every 10 loops */
|
||||
if (this->hidden->parent && (((++cnt) % 10) == 0)) {
|
||||
if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Use timer for general audio synchronization */
|
||||
ticks =
|
||||
((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
|
||||
if (ticks > 0) {
|
||||
SDL_Delay(ticks);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ARTS_PlayDevice(_THIS)
|
||||
{
|
||||
/* Write the audio data */
|
||||
int written = SDL_NAME(arts_write) (this->hidden->stream,
|
||||
this->hidden->mixbuf,
|
||||
this->hidden->mixlen);
|
||||
|
||||
/* If timer synchronization is enabled, set the next write frame */
|
||||
if (this->hidden->frame_ticks) {
|
||||
this->hidden->next_frame += this->hidden->frame_ticks;
|
||||
}
|
||||
|
||||
/* If we couldn't write, assume fatal error for now */
|
||||
if (written < 0) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
ARTS_WaitDone(_THIS)
|
||||
{
|
||||
/* !!! FIXME: camp here until buffer drains... SDL_Delay(???); */
|
||||
}
|
||||
|
||||
|
||||
static Uint8 *
|
||||
ARTS_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ARTS_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->stream) {
|
||||
SDL_NAME(arts_close_stream) (this->hidden->stream);
|
||||
this->hidden->stream = 0;
|
||||
}
|
||||
SDL_NAME(arts_free) ();
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
int rc = 0;
|
||||
int bits = 0, frag_spec = 0;
|
||||
SDL_AudioFormat test_format = 0, format = 0;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
!format && test_format;) {
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
|
||||
#endif
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
bits = 8;
|
||||
format = 1;
|
||||
break;
|
||||
case AUDIO_S16LSB:
|
||||
bits = 16;
|
||||
format = 1;
|
||||
break;
|
||||
default:
|
||||
format = 0;
|
||||
break;
|
||||
}
|
||||
if (!format) {
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
}
|
||||
if (format == 0) {
|
||||
ARTS_CloseDevice(this);
|
||||
SDL_SetError("Couldn't find any hardware audio formats");
|
||||
return 0;
|
||||
}
|
||||
this->spec.format = test_format;
|
||||
|
||||
if ((rc = SDL_NAME(arts_init) ()) != 0) {
|
||||
ARTS_CloseDevice(this);
|
||||
SDL_SetError("Unable to initialize ARTS: %s",
|
||||
SDL_NAME(arts_error_text) (rc));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!SDL_NAME(arts_suspended) ()) {
|
||||
ARTS_CloseDevice(this);
|
||||
SDL_SetError("ARTS can not open audio device");
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
|
||||
bits,
|
||||
this->spec.channels,
|
||||
"SDL");
|
||||
|
||||
/* Play nothing so we have at least one write (server bug workaround). */
|
||||
SDL_NAME(arts_write) (this->hidden->stream, "", 0);
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Determine the power of two of the fragment size */
|
||||
for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
|
||||
if ((0x01 << frag_spec) != this->spec.size) {
|
||||
ARTS_CloseDevice(this);
|
||||
SDL_SetError("Fragment size must be a power of two");
|
||||
return 0;
|
||||
}
|
||||
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
||||
|
||||
#ifdef ARTS_P_PACKET_SETTINGS
|
||||
SDL_NAME(arts_stream_set) (this->hidden->stream,
|
||||
ARTS_P_PACKET_SETTINGS, frag_spec);
|
||||
#else
|
||||
SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_SIZE,
|
||||
frag_spec & 0xffff);
|
||||
SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_COUNT,
|
||||
frag_spec >> 16);
|
||||
#endif
|
||||
this->spec.size = SDL_NAME(arts_stream_get) (this->hidden->stream,
|
||||
ARTS_P_PACKET_SIZE);
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
ARTS_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
/* Get the parent process id (we're the parent of the audio thread) */
|
||||
this->hidden->parent = getpid();
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ARTS_Deinitialize(void)
|
||||
{
|
||||
UnloadARTSLibrary();
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ARTS_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
if (LoadARTSLibrary() < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
if (SDL_NAME(arts_init) () != 0) {
|
||||
UnloadARTSLibrary();
|
||||
SDL_SetError("ARTS: arts_init failed (no audio server?)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Play a stream so aRts doesn't crash */
|
||||
if (SDL_NAME(arts_suspended) ()) {
|
||||
arts_stream_t stream;
|
||||
stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
|
||||
SDL_NAME(arts_write) (stream, "", 0);
|
||||
SDL_NAME(arts_close_stream) (stream);
|
||||
}
|
||||
|
||||
SDL_NAME(arts_free) ();
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = ARTS_OpenDevice;
|
||||
impl->PlayDevice = ARTS_PlayDevice;
|
||||
impl->WaitDevice = ARTS_WaitDevice;
|
||||
impl->GetDeviceBuf = ARTS_GetDeviceBuf;
|
||||
impl->CloseDevice = ARTS_CloseDevice;
|
||||
impl->WaitDone = ARTS_WaitDone;
|
||||
impl->Deinitialize = ARTS_Deinitialize;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
AudioBootStrap ARTS_bootstrap = {
|
||||
ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", ARTS_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_artscaudio_h
|
||||
#define _SDL_artscaudio_h
|
||||
|
||||
#include <artsc.h>
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The stream descriptor for the audio device */
|
||||
arts_stream_t stream;
|
||||
|
||||
/* The parent process id, to detect when application quits */
|
||||
pid_t parent;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *mixbuf;
|
||||
int mixlen;
|
||||
|
||||
/* Support for audio timing using a timer, in addition to select() */
|
||||
float frame_ticks;
|
||||
float next_frame;
|
||||
};
|
||||
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
|
||||
|
||||
#endif /* _SDL_artscaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to the audio stream on BeOS */
|
||||
|
||||
#include <SoundPlayer.h>
|
||||
|
||||
#include "../../main/beos/SDL_BeApp.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_sysaudio.h"
|
||||
#include "../../thread/beos/SDL_systhread_c.h"
|
||||
#include "SDL_beaudio.h"
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* !!! FIXME: have the callback call the higher level to avoid code dupe. */
|
||||
/* The BeOS callback for handling the audio buffer */
|
||||
static void
|
||||
FillSound(void *device, void *stream, size_t len,
|
||||
const media_raw_audio_format & format)
|
||||
{
|
||||
SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
|
||||
|
||||
/* Silence the buffer, since it's ours */
|
||||
SDL_memset(stream, audio->spec.silence, len);
|
||||
|
||||
/* Only do soemthing if audio is enabled */
|
||||
if (!audio->enabled)
|
||||
return;
|
||||
|
||||
if (!audio->paused) {
|
||||
if (audio->convert.needed) {
|
||||
SDL_mutexP(audio->mixer_lock);
|
||||
(*audio->spec.callback) (audio->spec.userdata,
|
||||
(Uint8 *) audio->convert.buf,
|
||||
audio->convert.len);
|
||||
SDL_mutexV(audio->mixer_lock);
|
||||
SDL_ConvertAudio(&audio->convert);
|
||||
SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
|
||||
} else {
|
||||
SDL_mutexP(audio->mixer_lock);
|
||||
(*audio->spec.callback) (audio->spec.userdata,
|
||||
(Uint8 *) stream, len);
|
||||
SDL_mutexV(audio->mixer_lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
BEOSAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (_this->hidden != NULL) {
|
||||
if (_this->hidden->audio_obj) {
|
||||
_this->hidden->audio_obj->Stop();
|
||||
delete _this->hidden->audio_obj;
|
||||
_this->hidden->audio_obj = NULL;
|
||||
}
|
||||
|
||||
delete _this->hidden;
|
||||
_this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
int valid_datatype = 0;
|
||||
media_raw_audio_format format;
|
||||
SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
_this->hidden = new SDL_PrivateAudioData;
|
||||
if (_this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
|
||||
|
||||
/* Parse the audio format and fill the Be raw audio format */
|
||||
SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
|
||||
format.byte_order = B_MEDIA_LITTLE_ENDIAN;
|
||||
format.frame_rate = (float) _this->spec.freq;
|
||||
format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */
|
||||
while ((!valid_datatype) && (test_format)) {
|
||||
valid_datatype = 1;
|
||||
_this->spec.format = test_format;
|
||||
switch (test_format) {
|
||||
case AUDIO_S8:
|
||||
format.format = media_raw_audio_format::B_AUDIO_CHAR;
|
||||
break;
|
||||
|
||||
case AUDIO_U8:
|
||||
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
|
||||
break;
|
||||
|
||||
case AUDIO_S16LSB:
|
||||
format.format = media_raw_audio_format::B_AUDIO_SHORT;
|
||||
break;
|
||||
|
||||
case AUDIO_S16MSB:
|
||||
format.format = media_raw_audio_format::B_AUDIO_SHORT;
|
||||
format.byte_order = B_MEDIA_BIG_ENDIAN;
|
||||
break;
|
||||
|
||||
case AUDIO_S32LSB:
|
||||
format.format = media_raw_audio_format::B_AUDIO_INT;
|
||||
break;
|
||||
|
||||
case AUDIO_S32MSB:
|
||||
format.format = media_raw_audio_format::B_AUDIO_INT;
|
||||
format.byte_order = B_MEDIA_BIG_ENDIAN;
|
||||
break;
|
||||
|
||||
case AUDIO_F32LSB:
|
||||
format.format = media_raw_audio_format::B_AUDIO_FLOAT;
|
||||
break;
|
||||
|
||||
case AUDIO_F32MSB:
|
||||
format.format = media_raw_audio_format::B_AUDIO_FLOAT;
|
||||
format.byte_order = B_MEDIA_BIG_ENDIAN;
|
||||
break;
|
||||
|
||||
default:
|
||||
valid_datatype = 0;
|
||||
test_format = SDL_NextAudioFormat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
format.buffer_size = _this->spec.samples;
|
||||
|
||||
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
||||
BEOSAUDIO_CloseDevice(_this);
|
||||
SDL_SetError("Unsupported audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&_this->spec);
|
||||
|
||||
/* Subscribe to the audio stream (creates a new thread) */
|
||||
sigset_t omask;
|
||||
SDL_MaskSignals(&omask);
|
||||
_this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
|
||||
FillSound, NULL, _this);
|
||||
SDL_UnmaskSignals(&omask);
|
||||
|
||||
if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
|
||||
_this->hidden->audio_obj->SetHasData(true);
|
||||
} else {
|
||||
BEOSAUDIO_CloseDevice(_this);
|
||||
SDL_SetError("Unable to start Be audio");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We're running! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
BEOSAUDIO_Deinitialize(void)
|
||||
{
|
||||
SDL_QuitBeApp();
|
||||
}
|
||||
|
||||
static int
|
||||
BEOSAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Initialize the Be Application, if it's not already started */
|
||||
if (SDL_InitBeApp() < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = BEOSAUDIO_OpenDevice;
|
||||
impl->CloseDevice = BEOSAUDIO_CloseDevice;
|
||||
impl->Deinitialize = BEOSAUDIO_Deinitialize;
|
||||
impl->ProvidesOwnCallbackThread = 1;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern AudioBootStrap BEOSAUDIO_bootstrap;
|
||||
}
|
||||
AudioBootStrap BEOSAUDIO_bootstrap = {
|
||||
"baudio", "BeOS BSoundPlayer", BEOSAUDIO_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_beaudio_h
|
||||
#define _SDL_beaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *_this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
BSoundPlayer *audio_obj;
|
||||
};
|
||||
|
||||
#endif /* _SDL_beaudio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,455 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/*
|
||||
* Driver for native OpenBSD/NetBSD audio(4).
|
||||
* vedge@vedge.com.ar.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/audioio.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_audiodev_c.h"
|
||||
#include "SDL_bsdaudio.h"
|
||||
|
||||
/* The tag name used by NetBSD/OpenBSD audio */
|
||||
#ifdef __NetBSD__
|
||||
#define BSD_AUDIO_DRIVER_NAME "netbsd"
|
||||
#define BSD_AUDIO_DRIVER_DESC "Native NetBSD audio"
|
||||
#else
|
||||
#define BSD_AUDIO_DRIVER_NAME "openbsd"
|
||||
#define BSD_AUDIO_DRIVER_DESC "Native OpenBSD audio"
|
||||
#endif
|
||||
|
||||
/* Open the audio device for playback, and don't block if busy */
|
||||
/* #define USE_BLOCKING_WRITES */
|
||||
|
||||
/* Use timer for synchronization */
|
||||
/* #define USE_TIMER_SYNC */
|
||||
|
||||
/* #define DEBUG_AUDIO */
|
||||
/* #define DEBUG_AUDIO_STREAM */
|
||||
|
||||
#ifdef USE_BLOCKING_WRITES
|
||||
#define OPEN_FLAGS_OUTPUT O_WRONLY
|
||||
#define OPEN_FLAGS_INPUT O_RDONLY
|
||||
#else
|
||||
#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
|
||||
#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
|
||||
#endif
|
||||
|
||||
/* !!! FIXME: so much cut and paste with dsp/dma drivers... */
|
||||
static char **outputDevices = NULL;
|
||||
static int outputDeviceCount = 0;
|
||||
static char **inputDevices = NULL;
|
||||
static int inputDeviceCount = 0;
|
||||
|
||||
static inline void
|
||||
free_device_list(char ***devs, int *count)
|
||||
{
|
||||
SDL_FreeUnixAudioDevices(devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_list(int iscapture, char ***devs, int *count)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
free_device_list(devs, count);
|
||||
SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_lists(void)
|
||||
{
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
free_device_lists(void)
|
||||
{
|
||||
free_device_list(&outputDevices, &outputDeviceCount);
|
||||
free_device_list(&inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
BSDAUDIO_Deinitialize(void)
|
||||
{
|
||||
free_device_lists();
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
BSDAUDIO_DetectDevices(int iscapture)
|
||||
{
|
||||
if (iscapture) {
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
return inputDeviceCount;
|
||||
} else {
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
return outputDeviceCount;
|
||||
}
|
||||
|
||||
return 0; /* shouldn't ever hit this. */
|
||||
}
|
||||
|
||||
static const char *
|
||||
BSDAUDIO_GetDeviceName(int index, int iscapture)
|
||||
{
|
||||
if ((iscapture) && (index < inputDeviceCount)) {
|
||||
return inputDevices[index];
|
||||
} else if ((!iscapture) && (index < outputDeviceCount)) {
|
||||
return outputDevices[index];
|
||||
}
|
||||
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
BSDAUDIO_Status(_THIS)
|
||||
{
|
||||
#ifdef DEBUG_AUDIO
|
||||
/* *INDENT-OFF* */
|
||||
audio_info_t info;
|
||||
|
||||
if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
|
||||
fprintf(stderr, "AUDIO_GETINFO failed.\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "\n"
|
||||
"[play/record info]\n"
|
||||
"buffer size : %d bytes\n"
|
||||
"sample rate : %i Hz\n"
|
||||
"channels : %i\n"
|
||||
"precision : %i-bit\n"
|
||||
"encoding : 0x%x\n"
|
||||
"seek : %i\n"
|
||||
"sample count : %i\n"
|
||||
"EOF count : %i\n"
|
||||
"paused : %s\n"
|
||||
"error occured : %s\n"
|
||||
"waiting : %s\n"
|
||||
"active : %s\n"
|
||||
"",
|
||||
info.play.buffer_size,
|
||||
info.play.sample_rate,
|
||||
info.play.channels,
|
||||
info.play.precision,
|
||||
info.play.encoding,
|
||||
info.play.seek,
|
||||
info.play.samples,
|
||||
info.play.eof,
|
||||
info.play.pause ? "yes" : "no",
|
||||
info.play.error ? "yes" : "no",
|
||||
info.play.waiting ? "yes" : "no",
|
||||
info.play.active ? "yes" : "no");
|
||||
|
||||
fprintf(stderr, "\n"
|
||||
"[audio info]\n"
|
||||
"monitor_gain : %i\n"
|
||||
"hw block size : %d bytes\n"
|
||||
"hi watermark : %i\n"
|
||||
"lo watermark : %i\n"
|
||||
"audio mode : %s\n"
|
||||
"",
|
||||
info.monitor_gain,
|
||||
info.blocksize,
|
||||
info.hiwat, info.lowat,
|
||||
(info.mode == AUMODE_PLAY) ? "PLAY"
|
||||
: (info.mode = AUMODE_RECORD) ? "RECORD"
|
||||
: (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
|
||||
/* *INDENT-ON* */
|
||||
#endif /* DEBUG_AUDIO */
|
||||
}
|
||||
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
BSDAUDIO_WaitDevice(_THIS)
|
||||
{
|
||||
#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
|
||||
/* See if we need to use timed audio synchronization */
|
||||
if (this->hidden->frame_ticks) {
|
||||
/* Use timer for general audio synchronization */
|
||||
Sint32 ticks;
|
||||
|
||||
ticks =
|
||||
((Sint32) (this->hidden->next_frame - SDL_GetTicks())) -
|
||||
FUDGE_TICKS;
|
||||
if (ticks > 0) {
|
||||
SDL_Delay(ticks);
|
||||
}
|
||||
} else {
|
||||
/* Use select() for audio synchronization */
|
||||
fd_set fdset;
|
||||
struct timeval timeout;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(this->hidden->audio_fd, &fdset);
|
||||
timeout.tv_sec = 10;
|
||||
timeout.tv_usec = 0;
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Waiting for audio to get ready\n");
|
||||
#endif
|
||||
if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
|
||||
<= 0) {
|
||||
const char *message =
|
||||
"Audio timeout - buggy audio driver? (disabled)";
|
||||
/* In general we should never print to the screen,
|
||||
but in this case we have no other way of letting
|
||||
the user know what happened.
|
||||
*/
|
||||
fprintf(stderr, "SDL: %s\n", message);
|
||||
this->enabled = 0;
|
||||
/* Don't try to close - may hang */
|
||||
this->hidden->audio_fd = -1;
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Done disabling audio\n");
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Ready!\n");
|
||||
#endif
|
||||
}
|
||||
#endif /* !USE_BLOCKING_WRITES */
|
||||
}
|
||||
|
||||
static void
|
||||
BSDAUDIO_PlayDevice(_THIS)
|
||||
{
|
||||
int written, p = 0;
|
||||
|
||||
/* Write the audio data, checking for EAGAIN on broken audio drivers */
|
||||
do {
|
||||
written = write(this->hidden->audio_fd,
|
||||
&this->hidden->mixbuf[p], this->hidden->mixlen - p);
|
||||
|
||||
if (written > 0)
|
||||
p += written;
|
||||
if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
|
||||
/* Non recoverable error has occurred. It should be reported!!! */
|
||||
perror("audio");
|
||||
break;
|
||||
}
|
||||
|
||||
if (p < written
|
||||
|| ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
|
||||
SDL_Delay(1); /* Let a little CPU time go by */
|
||||
}
|
||||
} while (p < written);
|
||||
|
||||
/* If timer synchronization is enabled, set the next write frame */
|
||||
if (this->hidden->frame_ticks) {
|
||||
this->hidden->next_frame += this->hidden->frame_ticks;
|
||||
}
|
||||
|
||||
/* If we couldn't write, assume fatal error for now */
|
||||
if (written < 0) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
||||
#endif
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
BSDAUDIO_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
BSDAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->audio_fd >= 0) {
|
||||
close(this->hidden->audio_fd);
|
||||
this->hidden->audio_fd = -1;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
SDL_AudioFormat format = 0;
|
||||
audio_info_t info;
|
||||
|
||||
/* We don't care what the devname is...we'll try to open anything. */
|
||||
/* ...but default to first name in the list... */
|
||||
if (devname == NULL) {
|
||||
if (((iscapture) && (inputDeviceCount == 0)) ||
|
||||
((!iscapture) && (outputDeviceCount == 0))) {
|
||||
SDL_SetError("No such audio device");
|
||||
return 0;
|
||||
}
|
||||
devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
|
||||
}
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Open the audio device */
|
||||
this->hidden->audio_fd = open(devname, flags, 0);
|
||||
if (this->hidden->audio_fd < 0) {
|
||||
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
AUDIO_INITINFO(&info);
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Set to play mode */
|
||||
info.mode = AUMODE_PLAY;
|
||||
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
|
||||
BSDAUDIO_CloseDevice(this);
|
||||
SDL_SetError("Couldn't put device into play mode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
AUDIO_INITINFO(&info);
|
||||
for (format = SDL_FirstAudioFormat(this->spec.format);
|
||||
format; format = SDL_NextAudioFormat()) {
|
||||
switch (format) {
|
||||
case AUDIO_U8:
|
||||
info.play.encoding = AUDIO_ENCODING_ULINEAR;
|
||||
info.play.precision = 8;
|
||||
break;
|
||||
case AUDIO_S8:
|
||||
info.play.encoding = AUDIO_ENCODING_SLINEAR;
|
||||
info.play.precision = 8;
|
||||
break;
|
||||
case AUDIO_S16LSB:
|
||||
info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
|
||||
info.play.precision = 16;
|
||||
break;
|
||||
case AUDIO_S16MSB:
|
||||
info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
|
||||
info.play.precision = 16;
|
||||
break;
|
||||
case AUDIO_U16LSB:
|
||||
info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
|
||||
info.play.precision = 16;
|
||||
break;
|
||||
case AUDIO_U16MSB:
|
||||
info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
|
||||
info.play.precision = 16;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!format) {
|
||||
BSDAUDIO_CloseDevice(this);
|
||||
SDL_SetError("No supported encoding for 0x%x", this->spec.format);
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->spec.format = format;
|
||||
|
||||
AUDIO_INITINFO(&info);
|
||||
info.play.channels = this->spec.channels;
|
||||
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
|
||||
this->spec.channels = 1;
|
||||
}
|
||||
AUDIO_INITINFO(&info);
|
||||
info.play.sample_rate = this->spec.freq;
|
||||
info.blocksize = this->spec.size;
|
||||
info.hiwat = 5;
|
||||
info.lowat = 3;
|
||||
(void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
|
||||
(void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
|
||||
this->spec.freq = info.play.sample_rate;
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
BSDAUDIO_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
BSDAUDIO_Status(this);
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->DetectDevices = BSDAUDIO_DetectDevices;
|
||||
impl->GetDeviceName = BSDAUDIO_GetDeviceName;
|
||||
impl->OpenDevice = BSDAUDIO_OpenDevice;
|
||||
impl->PlayDevice = BSDAUDIO_PlayDevice;
|
||||
impl->WaitDevice = BSDAUDIO_WaitDevice;
|
||||
impl->GetDeviceBuf = BSDAUDIO_GetDeviceBuf;
|
||||
impl->CloseDevice = BSDAUDIO_CloseDevice;
|
||||
impl->Deinitialize = BSDAUDIO_Deinitialize;
|
||||
|
||||
build_device_lists();
|
||||
return (outputDeviceCount > 0) ? 2 : 1;
|
||||
}
|
||||
|
||||
|
||||
AudioBootStrap BSD_AUDIO_bootstrap = {
|
||||
BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC, BSDAUDIO_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_bsdaudio_h
|
||||
#define _SDL_bsdaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The file descriptor for the audio device */
|
||||
int audio_fd;
|
||||
|
||||
/* The parent process id, to detect when application quits */
|
||||
pid_t parent;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *mixbuf;
|
||||
int mixlen;
|
||||
|
||||
/* Support for audio timing using a timer, in addition to select() */
|
||||
float frame_ticks;
|
||||
float next_frame;
|
||||
};
|
||||
|
||||
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
|
||||
|
||||
#endif /* _SDL_bsdaudio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
This file written by Ryan C. Gordon (icculus@icculus.org)
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Output raw audio data to a file. */
|
||||
|
||||
#if HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_rwops.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_diskaudio.h"
|
||||
|
||||
/* The tag name used by DISK audio */
|
||||
#define DISKAUD_DRIVER_NAME "disk"
|
||||
|
||||
/* environment variables and defaults. */
|
||||
#define DISKENVR_OUTFILE "SDL_DISKAUDIOFILE"
|
||||
#define DISKDEFAULT_OUTFILE "sdlaudio.raw"
|
||||
#define DISKENVR_WRITEDELAY "SDL_DISKAUDIODELAY"
|
||||
#define DISKDEFAULT_WRITEDELAY 150
|
||||
|
||||
static const char *
|
||||
DISKAUD_GetOutputFilename(const char *devname)
|
||||
{
|
||||
if (devname == NULL) {
|
||||
devname = SDL_getenv(DISKENVR_OUTFILE);
|
||||
if (devname == NULL) {
|
||||
devname = DISKDEFAULT_OUTFILE;
|
||||
}
|
||||
}
|
||||
return devname;
|
||||
}
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
DISKAUD_WaitDevice(_THIS)
|
||||
{
|
||||
SDL_Delay(this->hidden->write_delay);
|
||||
}
|
||||
|
||||
static void
|
||||
DISKAUD_PlayDevice(_THIS)
|
||||
{
|
||||
size_t written;
|
||||
|
||||
/* Write the audio data */
|
||||
written = SDL_RWwrite(this->hidden->output,
|
||||
this->hidden->mixbuf, 1, this->hidden->mixlen);
|
||||
|
||||
/* If we couldn't write, assume fatal error for now */
|
||||
if (written != this->hidden->mixlen) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
||||
#endif
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
DISKAUD_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
DISKAUD_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->output != NULL) {
|
||||
SDL_RWclose(this->hidden->output);
|
||||
this->hidden->output = NULL;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
const char *envr = SDL_getenv(DISKENVR_WRITEDELAY);
|
||||
const char *fname = DISKAUD_GetOutputFilename(devname);
|
||||
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc(sizeof(*this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, sizeof(*this->hidden));
|
||||
|
||||
/* Open the audio device */
|
||||
this->hidden->output = SDL_RWFromFile(fname, "wb");
|
||||
if (this->hidden->output == NULL) {
|
||||
DISKAUD_CloseDevice(this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
DISKAUD_CloseDevice(this);
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->write_delay =
|
||||
(envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
|
||||
|
||||
#if HAVE_STDIO_H
|
||||
fprintf(stderr,
|
||||
"WARNING: You are using the SDL disk writer audio driver!\n"
|
||||
" Writing to file [%s].\n", fname);
|
||||
#endif
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
DISKAUD_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = DISKAUD_OpenDevice;
|
||||
impl->WaitDevice = DISKAUD_WaitDevice;
|
||||
impl->PlayDevice = DISKAUD_PlayDevice;
|
||||
impl->GetDeviceBuf = DISKAUD_GetDeviceBuf;
|
||||
impl->CloseDevice = DISKAUD_CloseDevice;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
AudioBootStrap DISKAUD_bootstrap = {
|
||||
DISKAUD_DRIVER_NAME, "direct-to-disk audio", DISKAUD_Init, 1
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_diskaudio_h
|
||||
#define _SDL_diskaudio_h
|
||||
|
||||
#include "SDL_rwops.h"
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The file descriptor for the audio device */
|
||||
SDL_RWops *output;
|
||||
Uint8 *mixbuf;
|
||||
Uint32 mixlen;
|
||||
Uint32 write_delay;
|
||||
};
|
||||
|
||||
#endif /* _SDL_diskaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,534 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* !!! FIXME: merge this driver with "dsp". */
|
||||
|
||||
/* Allow access to a raw mixing buffer */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h> /* For strerror() */
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
|
||||
/* This is installed on some systems */
|
||||
#include <soundcard.h>
|
||||
#else
|
||||
/* This is recommended by OSS */
|
||||
#include <sys/soundcard.h>
|
||||
#endif
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ((Uint8 *)-1)
|
||||
#endif
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_audiodev_c.h"
|
||||
#include "SDL_dmaaudio.h"
|
||||
|
||||
/* The tag name used by DMA audio */
|
||||
#define DMA_DRIVER_NAME "dma"
|
||||
|
||||
/* Open the audio device for playback, and don't block if busy */
|
||||
#define OPEN_FLAGS_INPUT (O_RDWR|O_NONBLOCK)
|
||||
#define OPEN_FLAGS_OUTPUT (O_RDWR|O_NONBLOCK)
|
||||
|
||||
static char **outputDevices = NULL;
|
||||
static int outputDeviceCount = 0;
|
||||
static char **inputDevices = NULL;
|
||||
static int inputDeviceCount = 0;
|
||||
|
||||
static int
|
||||
test_for_mmap(int fd)
|
||||
{
|
||||
int caps = 0;
|
||||
struct audio_buf_info info;
|
||||
if ((ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) &&
|
||||
(caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
|
||||
(ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0)) {
|
||||
size_t len = info.fragstotal * info.fragsize;
|
||||
Uint8 *buf = (Uint8 *) mmap(NULL, len, PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (buf != MAP_FAILED) {
|
||||
munmap(buf, len);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
free_device_list(char ***devs, int *count)
|
||||
{
|
||||
SDL_FreeUnixAudioDevices(devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_list(int iscapture, char ***devs, int *count)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
free_device_list(devs, count);
|
||||
SDL_EnumUnixAudioDevices(flags, 0, test_for_mmap, devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_lists(void)
|
||||
{
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
free_device_lists(void)
|
||||
{
|
||||
free_device_list(&outputDevices, &outputDeviceCount);
|
||||
free_device_list(&inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DMA_Deinitialize(void)
|
||||
{
|
||||
free_device_lists();
|
||||
}
|
||||
|
||||
static int
|
||||
DMA_DetectDevices(int iscapture)
|
||||
{
|
||||
if (iscapture) {
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
return inputDeviceCount;
|
||||
} else {
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
return outputDeviceCount;
|
||||
}
|
||||
|
||||
return 0; /* shouldn't ever hit this. */
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
DMA_GetDeviceName(int index, int iscapture)
|
||||
{
|
||||
if ((iscapture) && (index < inputDeviceCount)) {
|
||||
return inputDevices[index];
|
||||
} else if ((!iscapture) && (index < outputDeviceCount)) {
|
||||
return outputDevices[index];
|
||||
}
|
||||
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
DMA_ReopenAudio(_THIS, const char *audiodev, int format, int stereo)
|
||||
{
|
||||
int frag_spec;
|
||||
int value;
|
||||
|
||||
/* Close and then reopen the audio device */
|
||||
close(audio_fd);
|
||||
audio_fd = open(audiodev, O_RDWR, 0);
|
||||
if (audio_fd < 0) {
|
||||
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Determine the power of two of the fragment size */
|
||||
for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
|
||||
if ((0x01 << frag_spec) != this->spec.size) {
|
||||
SDL_SetError("Fragment size must be a power of two");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set the audio buffering parameters */
|
||||
if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
|
||||
SDL_SetError("Couldn't set audio fragment spec");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set the audio format */
|
||||
value = format;
|
||||
if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
|
||||
SDL_SetError("Couldn't set audio format");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set mono or stereo audio */
|
||||
value = (this->spec.channels > 1);
|
||||
if ((ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) ||
|
||||
(value != stereo)) {
|
||||
SDL_SetError("Couldn't set audio channels");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set the DSP frequency */
|
||||
value = this->spec.freq;
|
||||
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
|
||||
SDL_SetError("Couldn't set audio frequency");
|
||||
return (-1);
|
||||
}
|
||||
this->spec.freq = value;
|
||||
|
||||
/* We successfully re-opened the audio */
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DMA_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (dma_buf != NULL) {
|
||||
munmap(dma_buf, dma_len);
|
||||
dma_buf = NULL;
|
||||
}
|
||||
if (audio_fd >= 0) {
|
||||
close(audio_fd);
|
||||
audio_fd = -1;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
DMA_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
int format;
|
||||
int stereo;
|
||||
int value;
|
||||
SDL_AudioFormat test_format;
|
||||
struct audio_buf_info info;
|
||||
|
||||
/* We don't care what the devname is...we'll try to open anything. */
|
||||
/* ...but default to first name in the list... */
|
||||
if (devname == NULL) {
|
||||
if (((iscapture) && (inputDeviceCount == 0)) ||
|
||||
((!iscapture) && (outputDeviceCount == 0))) {
|
||||
SDL_SetError("No such audio device");
|
||||
return 0;
|
||||
}
|
||||
devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
|
||||
}
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Open the audio device */
|
||||
audio_fd = open(devname, flags, 0);
|
||||
if (audio_fd < 0) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
dma_buf = NULL;
|
||||
ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
|
||||
|
||||
/* Get a list of supported hardware formats */
|
||||
if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't get audio format list");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
format = 0;
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
!format && test_format;) {
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
|
||||
#endif
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
if (value & AFMT_U8) {
|
||||
format = AFMT_U8;
|
||||
}
|
||||
break;
|
||||
case AUDIO_S8:
|
||||
if (value & AFMT_S8) {
|
||||
format = AFMT_S8;
|
||||
}
|
||||
break;
|
||||
case AUDIO_S16LSB:
|
||||
if (value & AFMT_S16_LE) {
|
||||
format = AFMT_S16_LE;
|
||||
}
|
||||
break;
|
||||
case AUDIO_S16MSB:
|
||||
if (value & AFMT_S16_BE) {
|
||||
format = AFMT_S16_BE;
|
||||
}
|
||||
break;
|
||||
case AUDIO_U16LSB:
|
||||
if (value & AFMT_U16_LE) {
|
||||
format = AFMT_U16_LE;
|
||||
}
|
||||
break;
|
||||
case AUDIO_U16MSB:
|
||||
if (value & AFMT_U16_BE) {
|
||||
format = AFMT_U16_BE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
format = 0;
|
||||
break;
|
||||
}
|
||||
if (!format) {
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
}
|
||||
if (format == 0) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't find any hardware audio formats");
|
||||
return 0;
|
||||
}
|
||||
this->spec.format = test_format;
|
||||
|
||||
/* Set the audio format */
|
||||
value = format;
|
||||
if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't set audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set mono or stereo audio (currently only two channels supported) */
|
||||
stereo = (this->spec.channels > 1);
|
||||
ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo);
|
||||
if (stereo) {
|
||||
this->spec.channels = 2;
|
||||
} else {
|
||||
this->spec.channels = 1;
|
||||
}
|
||||
|
||||
/* Because some drivers don't allow setting the buffer size
|
||||
after setting the format, we must re-open the audio device
|
||||
once we know what format and channels are supported
|
||||
*/
|
||||
if (DMA_ReopenAudio(this, devname, format, stereo) < 0) {
|
||||
DMA_CloseDevice(this);
|
||||
/* Error is set by DMA_ReopenAudio() */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Memory map the audio buffer */
|
||||
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't get OSPACE parameters");
|
||||
return 0;
|
||||
}
|
||||
this->spec.size = info.fragsize;
|
||||
this->spec.samples = this->spec.size / ((this->spec.format & 0xFF) / 8);
|
||||
this->spec.samples /= this->spec.channels;
|
||||
num_buffers = info.fragstotal;
|
||||
dma_len = num_buffers * this->spec.size;
|
||||
dma_buf = (Uint8 *) mmap(NULL, dma_len, PROT_WRITE, MAP_SHARED,
|
||||
audio_fd, 0);
|
||||
if (dma_buf == MAP_FAILED) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("DMA memory map failed");
|
||||
dma_buf = NULL;
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(dma_buf, this->spec.silence, dma_len);
|
||||
|
||||
/* Check to see if we need to use select() workaround */
|
||||
{
|
||||
char *workaround;
|
||||
workaround = SDL_getenv("SDL_DSP_NOSELECT");
|
||||
if (workaround) {
|
||||
frame_ticks =
|
||||
(float) (this->spec.samples * 1000) / this->spec.freq;
|
||||
next_frame = SDL_GetTicks() + frame_ticks;
|
||||
}
|
||||
}
|
||||
|
||||
/* Trigger audio playback */
|
||||
value = 0;
|
||||
ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value);
|
||||
value = PCM_ENABLE_OUTPUT;
|
||||
if (ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0) {
|
||||
DMA_CloseDevice(this);
|
||||
SDL_SetError("Couldn't trigger audio output");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get the parent process id (we're the parent of the audio thread) */
|
||||
parent = getpid();
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
DMA_WaitDevice(_THIS)
|
||||
{
|
||||
fd_set fdset;
|
||||
|
||||
/* Check to see if the thread-parent process is still alive */
|
||||
{
|
||||
static int cnt = 0;
|
||||
/* Note that this only works with thread implementations
|
||||
that use a different process id for each thread.
|
||||
*/
|
||||
if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
|
||||
if (kill(parent, 0) < 0 && errno == ESRCH) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* See if we need to use timed audio synchronization */
|
||||
if (frame_ticks) {
|
||||
/* Use timer for general audio synchronization */
|
||||
Sint32 ticks;
|
||||
|
||||
ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
|
||||
if (ticks > 0) {
|
||||
SDL_Delay(ticks);
|
||||
}
|
||||
} else {
|
||||
/* Use select() for audio synchronization */
|
||||
struct timeval timeout;
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(audio_fd, &fdset);
|
||||
timeout.tv_sec = 10;
|
||||
timeout.tv_usec = 0;
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Waiting for audio to get ready\n");
|
||||
#endif
|
||||
if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
|
||||
const char *message =
|
||||
#ifdef AUDIO_OSPACE_HACK
|
||||
"Audio timeout - buggy audio driver? (trying ospace)";
|
||||
#else
|
||||
"Audio timeout - buggy audio driver? (disabled)";
|
||||
#endif
|
||||
/* In general we should never print to the screen,
|
||||
but in this case we have no other way of letting
|
||||
the user know what happened.
|
||||
*/
|
||||
fprintf(stderr, "SDL: %s\n", message);
|
||||
#ifdef AUDIO_OSPACE_HACK
|
||||
/* We may be able to use GET_OSPACE trick */
|
||||
frame_ticks = (float) (this->spec.samples * 1000) /
|
||||
this->spec.freq;
|
||||
next_frame = SDL_GetTicks() + frame_ticks;
|
||||
#else
|
||||
this->enabled = 0;
|
||||
/* Don't try to close - may hang */
|
||||
audio_fd = -1;
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Done disabling audio\n");
|
||||
#endif
|
||||
#endif /* AUDIO_OSPACE_HACK */
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Ready!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
DMA_PlayDevice(_THIS)
|
||||
{
|
||||
/* If timer synchronization is enabled, set the next write frame */
|
||||
if (frame_ticks) {
|
||||
next_frame += frame_ticks;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
DMA_GetDeviceBuf(_THIS)
|
||||
{
|
||||
count_info info;
|
||||
int playing;
|
||||
int filling;
|
||||
|
||||
/* Get number of blocks, looping if we're not using select() */
|
||||
do {
|
||||
if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
|
||||
/* Uh oh... */
|
||||
this->enabled = 0;
|
||||
return (NULL);
|
||||
}
|
||||
} while (frame_ticks && (info.blocks < 1));
|
||||
#ifdef DEBUG_AUDIO
|
||||
if (info.blocks > 1) {
|
||||
printf("Warning: audio underflow (%d frags)\n", info.blocks - 1);
|
||||
}
|
||||
#endif
|
||||
playing = info.ptr / this->spec.size;
|
||||
filling = (playing + 1) % num_buffers;
|
||||
return (dma_buf + (filling * this->spec.size));
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
DMA_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->DetectDevices = DMA_DetectDevices;
|
||||
impl->GetDeviceName = DMA_GetDeviceName;
|
||||
impl->OpenDevice = DMA_OpenDevice;
|
||||
impl->WaitDevice = DMA_WaitDevice;
|
||||
impl->PlayDevice = DMA_PlayDevice;
|
||||
impl->GetDeviceBuf = DMA_GetDeviceBuf;
|
||||
impl->CloseDevice = DMA_CloseDevice;
|
||||
impl->Deinitialize = DMA_Deinitialize;
|
||||
|
||||
build_device_lists();
|
||||
return (outputDeviceCount > 0) ? 2 : 1;
|
||||
}
|
||||
|
||||
AudioBootStrap DMA_bootstrap = {
|
||||
DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio", DMA_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_dmaaudio_h
|
||||
#define _SDL_dmaaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The file descriptor for the audio device */
|
||||
int audio_fd;
|
||||
|
||||
/* The parent process id, to detect when application quits */
|
||||
pid_t parent;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *dma_buf;
|
||||
int dma_len;
|
||||
int num_buffers;
|
||||
|
||||
/* Support for audio timing using a timer, in addition to select() */
|
||||
float frame_ticks;
|
||||
float next_frame;
|
||||
};
|
||||
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
|
||||
|
||||
/* Old variable names */
|
||||
/* !!! FIXME: remove these. */
|
||||
#define audio_fd (this->hidden->audio_fd)
|
||||
#define parent (this->hidden->parent)
|
||||
#define dma_buf (this->hidden->dma_buf)
|
||||
#define dma_len (this->hidden->dma_len)
|
||||
#define num_buffers (this->hidden->num_buffers)
|
||||
#define frame_ticks (this->hidden->frame_ticks)
|
||||
#define next_frame (this->hidden->next_frame)
|
||||
|
||||
#endif /* _SDL_dmaaudio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */
|
||||
/* patch for IRIX 5 by Georg Schwarz 18/07/2004 */
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_irixaudio.h"
|
||||
|
||||
|
||||
#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */
|
||||
#define OLD_IRIX_AUDIO
|
||||
#define alClosePort(x) ALcloseport(x)
|
||||
#define alFreeConfig(x) ALfreeconfig(x)
|
||||
#define alGetFillable(x) ALgetfillable(x)
|
||||
#define alNewConfig() ALnewconfig()
|
||||
#define alOpenPort(x,y,z) ALopenport(x,y,z)
|
||||
#define alSetChannels(x,y) ALsetchannels(x,y)
|
||||
#define alSetQueueSize(x,y) ALsetqueuesize(x,y)
|
||||
#define alSetSampFmt(x,y) ALsetsampfmt(x,y)
|
||||
#define alSetWidth(x,y) ALsetwidth(x,y)
|
||||
#endif
|
||||
|
||||
void static
|
||||
IRIXAUDIO_WaitDevice(_THIS)
|
||||
{
|
||||
Sint32 timeleft;
|
||||
|
||||
timeleft = this->spec.samples - alGetFillable(this->hidden->audio_port);
|
||||
if (timeleft > 0) {
|
||||
timeleft /= (this->spec.freq / 1000);
|
||||
SDL_Delay((Uint32) timeleft);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
IRIXAUDIO_PlayDevice(_THIS)
|
||||
{
|
||||
/* Write the audio data out */
|
||||
ALport port = this->hidden->audio_port;
|
||||
Uint8 *mixbuf = this->hidden->mixbuf;
|
||||
if (alWriteFrames(port, mixbuf, this->spec.samples) < 0) {
|
||||
/* Assume fatal error, for now */
|
||||
this->enabled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
IRIXAUDIO_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
IRIXAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->audio_port != NULL) {
|
||||
alClosePort(this->hidden->audio_port);
|
||||
this->hidden->audio_port = NULL;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
IRIXAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
long width = 0;
|
||||
long fmt = 0;
|
||||
int valid = 0;
|
||||
|
||||
/* !!! FIXME: Handle multiple devices and capture? */
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
#ifdef OLD_IRIX_AUDIO
|
||||
{
|
||||
long audio_param[2];
|
||||
audio_param[0] = AL_OUTPUT_RATE;
|
||||
audio_param[1] = this->spec.freq;
|
||||
valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
|
||||
}
|
||||
#else
|
||||
{
|
||||
ALpv audio_param;
|
||||
audio_param.param = AL_RATE;
|
||||
audio_param.value.i = this->spec.freq;
|
||||
valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
while ((!valid) && (test_format)) {
|
||||
valid = 1;
|
||||
this->spec.format = test_format;
|
||||
|
||||
switch (test_format) {
|
||||
case AUDIO_S8:
|
||||
width = AL_SAMPLE_8;
|
||||
fmt = AL_SAMPFMT_TWOSCOMP;
|
||||
break;
|
||||
|
||||
case AUDIO_S16SYS:
|
||||
width = AL_SAMPLE_16;
|
||||
fmt = AL_SAMPFMT_TWOSCOMP;
|
||||
break;
|
||||
|
||||
case AUDIO_F32SYS:
|
||||
width = 0; /* not used here... */
|
||||
fmt = AL_SAMPFMT_FLOAT;
|
||||
break;
|
||||
|
||||
/* Docs say there is int24, but not int32.... */
|
||||
|
||||
default:
|
||||
valid = 0;
|
||||
test_format = SDL_NextAudioFormat();
|
||||
break;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
ALconfig audio_config = alNewConfig();
|
||||
valid = 0;
|
||||
if (audio_config) {
|
||||
if (alSetChannels(audio_config, this->spec.channels) < 0) {
|
||||
if (this->spec.channels > 2) { /* can't handle > stereo? */
|
||||
this->spec.channels = 2; /* try again below. */
|
||||
}
|
||||
}
|
||||
|
||||
if ((alSetSampFmt(audio_config, fmt) >= 0) &&
|
||||
((!width) || (alSetWidth(audio_config, width) >= 0)) &&
|
||||
(alSetQueueSize(audio_config, this->spec.samples * 2) >=
|
||||
0)
|
||||
&& (alSetChannels(audio_config, this->spec.channels) >=
|
||||
0)) {
|
||||
|
||||
this->hidden->audio_port = alOpenPort("SDL audio", "w",
|
||||
audio_config);
|
||||
if (this->hidden->audio_port == NULL) {
|
||||
/* docs say AL_BAD_CHANNELS happens here, too. */
|
||||
int err = oserror();
|
||||
if (err == AL_BAD_CHANNELS) {
|
||||
this->spec.channels = 2;
|
||||
alSetChannels(audio_config, this->spec.channels);
|
||||
this->hidden->audio_port =
|
||||
alOpenPort("SDL audio", "w", audio_config);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->hidden->audio_port != NULL) {
|
||||
valid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
alFreeConfig(audio_config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
IRIXAUDIO_CloseDevice(this);
|
||||
SDL_SetError("Unsupported audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Update the fragment size as size in bytes */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
IRIXAUDIO_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
IRIXAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = DSP_OpenDevice;
|
||||
impl->PlayDevice = DSP_PlayDevice;
|
||||
impl->WaitDevice = DSP_WaitDevice;
|
||||
impl->GetDeviceBuf = DSP_GetDeviceBuf;
|
||||
impl->CloseDevice = DSP_CloseDevice;
|
||||
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: not true, I think. */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
AudioBootStrap IRIXAUDIO_bootstrap = {
|
||||
"AL", "IRIX DMedia audio", IRIXAUDIO_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_irixaudio_h
|
||||
#define _SDL_irixaudio_h
|
||||
|
||||
#include <dmedia/audio.h>
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
ALport audio_port; /* The handle for the audio device */
|
||||
Uint8 *mixbuf; /* The app mixing buffer */
|
||||
};
|
||||
|
||||
#endif /* _SDL_irixaudio_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,392 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
Modified in Oct 2004 by Hannu Savolainen
|
||||
hannu@opensound.com
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to a raw mixing buffer */
|
||||
|
||||
#include <stdio.h> /* For perror() */
|
||||
#include <string.h> /* For strerror() */
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
|
||||
/* This is installed on some systems */
|
||||
#include <soundcard.h>
|
||||
#else
|
||||
/* This is recommended by OSS */
|
||||
#include <sys/soundcard.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_audiodev_c.h"
|
||||
#include "SDL_dspaudio.h"
|
||||
|
||||
/* The tag name used by DSP audio */
|
||||
#define DSP_DRIVER_NAME "dsp"
|
||||
|
||||
/* Open the audio device for playback, and don't block if busy */
|
||||
#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
|
||||
#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
|
||||
|
||||
static char **outputDevices = NULL;
|
||||
static int outputDeviceCount = 0;
|
||||
static char **inputDevices = NULL;
|
||||
static int inputDeviceCount = 0;
|
||||
|
||||
static inline void
|
||||
free_device_list(char ***devs, int *count)
|
||||
{
|
||||
SDL_FreeUnixAudioDevices(devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_list(int iscapture, char ***devs, int *count)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
free_device_list(devs, count);
|
||||
SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_lists(void)
|
||||
{
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
free_device_lists(void)
|
||||
{
|
||||
free_device_list(&outputDevices, &outputDeviceCount);
|
||||
free_device_list(&inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DSP_Deinitialize(void)
|
||||
{
|
||||
free_device_lists();
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
DSP_DetectDevices(int iscapture)
|
||||
{
|
||||
if (iscapture) {
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
return inputDeviceCount;
|
||||
} else {
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
return outputDeviceCount;
|
||||
}
|
||||
|
||||
return 0; /* shouldn't ever hit this. */
|
||||
}
|
||||
|
||||
static const char *
|
||||
DSP_GetDeviceName(int index, int iscapture)
|
||||
{
|
||||
if ((iscapture) && (index < inputDeviceCount)) {
|
||||
return inputDevices[index];
|
||||
} else if ((!iscapture) && (index < outputDeviceCount)) {
|
||||
return outputDevices[index];
|
||||
}
|
||||
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DSP_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->audio_fd >= 0) {
|
||||
close(this->hidden->audio_fd);
|
||||
this->hidden->audio_fd = -1;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
DSP_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
int format;
|
||||
int value;
|
||||
int frag_spec;
|
||||
SDL_AudioFormat test_format;
|
||||
|
||||
/* We don't care what the devname is...we'll try to open anything. */
|
||||
/* ...but default to first name in the list... */
|
||||
if (devname == NULL) {
|
||||
if (((iscapture) && (inputDeviceCount == 0)) ||
|
||||
((!iscapture) && (outputDeviceCount == 0))) {
|
||||
SDL_SetError("No such audio device");
|
||||
return 0;
|
||||
}
|
||||
devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
|
||||
}
|
||||
|
||||
/* Make sure fragment size stays a power of 2, or OSS fails. */
|
||||
/* I don't know which of these are actually legal values, though... */
|
||||
if (this->spec.channels > 8)
|
||||
this->spec.channels = 8;
|
||||
else if (this->spec.channels > 4)
|
||||
this->spec.channels = 4;
|
||||
else if (this->spec.channels > 2)
|
||||
this->spec.channels = 2;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Open the audio device */
|
||||
this->hidden->audio_fd = open(devname, flags, 0);
|
||||
if (this->hidden->audio_fd < 0) {
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
this->hidden->mixbuf = NULL;
|
||||
|
||||
/* Make the file descriptor use blocking writes with fcntl() */
|
||||
{
|
||||
long ctlflags;
|
||||
ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
|
||||
ctlflags &= ~O_NONBLOCK;
|
||||
if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Couldn't set audio blocking mode");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a list of supported hardware formats */
|
||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
|
||||
perror("SNDCTL_DSP_GETFMTS");
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Couldn't get audio format list");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
format = 0;
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
!format && test_format;) {
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
|
||||
#endif
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
if (value & AFMT_U8) {
|
||||
format = AFMT_U8;
|
||||
}
|
||||
break;
|
||||
case AUDIO_S16LSB:
|
||||
if (value & AFMT_S16_LE) {
|
||||
format = AFMT_S16_LE;
|
||||
}
|
||||
break;
|
||||
case AUDIO_S16MSB:
|
||||
if (value & AFMT_S16_BE) {
|
||||
format = AFMT_S16_BE;
|
||||
}
|
||||
break;
|
||||
#if 0
|
||||
/*
|
||||
* These formats are not used by any real life systems so they are not
|
||||
* needed here.
|
||||
*/
|
||||
case AUDIO_S8:
|
||||
if (value & AFMT_S8) {
|
||||
format = AFMT_S8;
|
||||
}
|
||||
break;
|
||||
case AUDIO_U16LSB:
|
||||
if (value & AFMT_U16_LE) {
|
||||
format = AFMT_U16_LE;
|
||||
}
|
||||
break;
|
||||
case AUDIO_U16MSB:
|
||||
if (value & AFMT_U16_BE) {
|
||||
format = AFMT_U16_BE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
format = 0;
|
||||
break;
|
||||
}
|
||||
if (!format) {
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
}
|
||||
if (format == 0) {
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Couldn't find any hardware audio formats");
|
||||
return 0;
|
||||
}
|
||||
this->spec.format = test_format;
|
||||
|
||||
/* Set the audio format */
|
||||
value = format;
|
||||
if ((ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
|
||||
(value != format)) {
|
||||
perror("SNDCTL_DSP_SETFMT");
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Couldn't set audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the number of channels of output */
|
||||
value = this->spec.channels;
|
||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
|
||||
perror("SNDCTL_DSP_CHANNELS");
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Cannot set the number of channels");
|
||||
return 0;
|
||||
}
|
||||
this->spec.channels = value;
|
||||
|
||||
/* Set the DSP frequency */
|
||||
value = this->spec.freq;
|
||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
|
||||
perror("SNDCTL_DSP_SPEED");
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Couldn't set audio frequency");
|
||||
return 0;
|
||||
}
|
||||
this->spec.freq = value;
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Determine the power of two of the fragment size */
|
||||
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
|
||||
if ((0x01U << frag_spec) != this->spec.size) {
|
||||
DSP_CloseDevice(this);
|
||||
SDL_SetError("Fragment size must be a power of two");
|
||||
return 0;
|
||||
}
|
||||
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
||||
|
||||
/* Set the audio buffering parameters */
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Requesting %d fragments of size %d\n",
|
||||
(frag_spec >> 16), 1 << (frag_spec & 0xFFFF));
|
||||
#endif
|
||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
|
||||
perror("SNDCTL_DSP_SETFRAGMENT");
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
{
|
||||
audio_buf_info info;
|
||||
ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETOSPACE, &info);
|
||||
fprintf(stderr, "fragments = %d\n", info.fragments);
|
||||
fprintf(stderr, "fragstotal = %d\n", info.fragstotal);
|
||||
fprintf(stderr, "fragsize = %d\n", info.fragsize);
|
||||
fprintf(stderr, "bytes = %d\n", info.bytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
DSP_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DSP_PlayDevice(_THIS)
|
||||
{
|
||||
const Uint8 *mixbuf = this->hidden->mixbuf;
|
||||
const int mixlen = this->hidden->mixlen;
|
||||
if (write(this->hidden->audio_fd, mixbuf, mixlen) == -1) {
|
||||
perror("Audio write");
|
||||
this->enabled = 0;
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen);
|
||||
#endif
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
DSP_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static int
|
||||
DSP_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->DetectDevices = DSP_DetectDevices;
|
||||
impl->GetDeviceName = DSP_GetDeviceName;
|
||||
impl->OpenDevice = DSP_OpenDevice;
|
||||
impl->PlayDevice = DSP_PlayDevice;
|
||||
impl->GetDeviceBuf = DSP_GetDeviceBuf;
|
||||
impl->CloseDevice = DSP_CloseDevice;
|
||||
impl->Deinitialize = DSP_Deinitialize;
|
||||
|
||||
build_device_lists();
|
||||
return (outputDeviceCount > 0) ? 2 : 1;
|
||||
}
|
||||
|
||||
|
||||
AudioBootStrap DSP_bootstrap = {
|
||||
DSP_DRIVER_NAME, "OSS /dev/dsp standard audio", DSP_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_dspaudio_h
|
||||
#define _SDL_dspaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The file descriptor for the audio device */
|
||||
int audio_fd;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *mixbuf;
|
||||
int mixlen;
|
||||
};
|
||||
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
|
||||
|
||||
#endif /* _SDL_dspaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
|
||||
This file written by Ryan C. Gordon (icculus@icculus.org)
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Output audio to nowhere... */
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_dummyaudio.h"
|
||||
|
||||
static int
|
||||
DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
return 1; /* always succeeds. */
|
||||
}
|
||||
|
||||
static int
|
||||
DUMMYAUD_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = DUMMYAUD_OpenDevice;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
AudioBootStrap DUMMYAUD_bootstrap = {
|
||||
"dummy", "SDL dummy audio driver", DUMMYAUD_Init, 1
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_dummyaudio_h
|
||||
#define _SDL_dummyaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The file descriptor for the audio device */
|
||||
Uint8 *mixbuf;
|
||||
Uint32 mixlen;
|
||||
Uint32 write_delay;
|
||||
Uint32 initial_calls;
|
||||
};
|
||||
|
||||
#endif /* _SDL_dummyaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,354 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to an ESD network stream mixing buffer */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <esd.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_esdaudio.h"
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
|
||||
#include "SDL_name.h"
|
||||
#include "SDL_loadso.h"
|
||||
#else
|
||||
#define SDL_NAME(X) X
|
||||
#endif
|
||||
|
||||
/* The tag name used by ESD audio */
|
||||
#define ESD_DRIVER_NAME "esd"
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
|
||||
|
||||
static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC;
|
||||
static void *esd_handle = NULL;
|
||||
|
||||
static int (*SDL_NAME(esd_open_sound)) (const char *host);
|
||||
static int (*SDL_NAME(esd_close)) (int esd);
|
||||
static int (*SDL_NAME(esd_play_stream)) (esd_format_t format, int rate,
|
||||
const char *host, const char *name);
|
||||
|
||||
#define SDL_ESD_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
void **func;
|
||||
} const esd_functions[] = {
|
||||
SDL_ESD_SYM(esd_open_sound),
|
||||
SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),
|
||||
};
|
||||
|
||||
#undef SDL_ESD_SYM
|
||||
|
||||
static void
|
||||
UnloadESDLibrary()
|
||||
{
|
||||
if (esd_handle != NULL) {
|
||||
SDL_UnloadObject(esd_handle);
|
||||
esd_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
LoadESDLibrary(void)
|
||||
{
|
||||
int i, retval = -1;
|
||||
|
||||
if (esd_handle == NULL) {
|
||||
esd_handle = SDL_LoadObject(esd_library);
|
||||
if (esd_handle) {
|
||||
retval = 0;
|
||||
for (i = 0; i < SDL_arraysize(esd_functions); ++i) {
|
||||
*esd_functions[i].func =
|
||||
SDL_LoadFunction(esd_handle, esd_functions[i].name);
|
||||
if (!*esd_functions[i].func) {
|
||||
retval = -1;
|
||||
UnloadESDLibrary();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void
|
||||
UnloadESDLibrary()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
LoadESDLibrary(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_AUDIO_DRIVER_ESD_DYNAMIC */
|
||||
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
ESD_WaitDevice(_THIS)
|
||||
{
|
||||
Sint32 ticks;
|
||||
|
||||
/* Check to see if the thread-parent process is still alive */
|
||||
{
|
||||
static int cnt = 0;
|
||||
/* Note that this only works with thread implementations
|
||||
that use a different process id for each thread.
|
||||
*/
|
||||
/* Check every 10 loops */
|
||||
if (this->hidden->parent && (((++cnt) % 10) == 0)) {
|
||||
if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Use timer for general audio synchronization */
|
||||
ticks =
|
||||
((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
|
||||
if (ticks > 0) {
|
||||
SDL_Delay(ticks);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ESD_PlayDevice(_THIS)
|
||||
{
|
||||
int written = 0;
|
||||
|
||||
/* Write the audio data, checking for EAGAIN on broken audio drivers */
|
||||
do {
|
||||
written = write(this->hidden->audio_fd,
|
||||
this->hidden->mixbuf, this->hidden->mixlen);
|
||||
if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
|
||||
SDL_Delay(1); /* Let a little CPU time go by */
|
||||
}
|
||||
} while ((written < 0) &&
|
||||
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
|
||||
|
||||
/* Set the next write frame */
|
||||
this->hidden->next_frame += this->hidden->frame_ticks;
|
||||
|
||||
/* If we couldn't write, assume fatal error for now */
|
||||
if (written < 0) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
ESD_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
ESD_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->audio_fd >= 0) {
|
||||
SDL_NAME(esd_close) (this->hidden->audio_fd);
|
||||
this->hidden->audio_fd = -1;
|
||||
}
|
||||
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try to get the name of the program */
|
||||
static char *
|
||||
get_progname(void)
|
||||
{
|
||||
char *progname = NULL;
|
||||
#ifdef __LINUX__
|
||||
FILE *fp;
|
||||
static char temp[BUFSIZ];
|
||||
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
|
||||
fp = fopen(temp, "r");
|
||||
if (fp != NULL) {
|
||||
if (fgets(temp, sizeof(temp) - 1, fp)) {
|
||||
progname = SDL_strrchr(temp, '/');
|
||||
if (progname == NULL) {
|
||||
progname = temp;
|
||||
} else {
|
||||
progname = progname + 1;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
#endif
|
||||
return (progname);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ESD_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
esd_format_t format = (ESD_STREAM | ESD_PLAY);
|
||||
SDL_AudioFormat test_format = 0;
|
||||
int found = 0;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
this->hidden->audio_fd = -1;
|
||||
|
||||
/* Convert audio spec to the ESD audio format */
|
||||
/* Try for a closest match on audio format */
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
!found && test_format; test_format = SDL_NextAudioFormat()) {
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
|
||||
#endif
|
||||
found = 1;
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
format |= ESD_BITS8;
|
||||
break;
|
||||
case AUDIO_S16SYS:
|
||||
format |= ESD_BITS16;
|
||||
break;
|
||||
default:
|
||||
found = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
ESD_CloseDevice(this);
|
||||
SDL_SetError("Couldn't find any hardware audio formats");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this->spec.channels == 1) {
|
||||
format |= ESD_MONO;
|
||||
} else {
|
||||
format |= ESD_STEREO;
|
||||
}
|
||||
#if 0
|
||||
this->spec.samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */
|
||||
#endif
|
||||
|
||||
/* Open a connection to the ESD audio server */
|
||||
this->hidden->audio_fd =
|
||||
SDL_NAME(esd_play_stream) (format, this->spec.freq, NULL,
|
||||
get_progname());
|
||||
|
||||
if (this->hidden->audio_fd < 0) {
|
||||
ESD_CloseDevice(this);
|
||||
SDL_SetError("Couldn't open ESD connection");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
this->hidden->frame_ticks =
|
||||
(float) (this->spec.samples * 1000) / this->spec.freq;
|
||||
this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
ESD_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
/* Get the parent process id (we're the parent of the audio thread) */
|
||||
this->hidden->parent = getpid();
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
ESD_Deinitialize(void)
|
||||
{
|
||||
UnloadESDLibrary();
|
||||
}
|
||||
|
||||
static int
|
||||
ESD_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
if (LoadESDLibrary() < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
int connection = 0;
|
||||
|
||||
/* Don't start ESD if it's not running */
|
||||
if (SDL_getenv("ESD_NO_SPAWN") == NULL) {
|
||||
SDL_putenv("ESD_NO_SPAWN=1");
|
||||
}
|
||||
|
||||
connection = SDL_NAME(esd_open_sound) (NULL);
|
||||
if (connection < 0) {
|
||||
UnloadESDLibrary();
|
||||
SDL_SetError("ESD: esd_open_sound failed (no audio server?)");
|
||||
return 0;
|
||||
}
|
||||
SDL_NAME(esd_close) (connection);
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = ESD_OpenDevice;
|
||||
impl->PlayDevice = ESD_PlayDevice;
|
||||
impl->WaitDevice = ESD_WaitDevice;
|
||||
impl->GetDeviceBuf = ESD_GetDeviceBuf;
|
||||
impl->CloseDevice = ESD_CloseDevice;
|
||||
impl->Deinitialize = ESD_Deinitialize;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
return 2; /* return 2 (definitely have a "device"). */
|
||||
}
|
||||
|
||||
|
||||
AudioBootStrap ESD_bootstrap = {
|
||||
ESD_DRIVER_NAME, "Enlightened Sound Daemon", ESD_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_esdaudio_h
|
||||
#define _SDL_esdaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* The file descriptor for the audio device */
|
||||
int audio_fd;
|
||||
|
||||
/* The parent process id, to detect when application quits */
|
||||
pid_t parent;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *mixbuf;
|
||||
int mixlen;
|
||||
|
||||
/* Support for audio timing using a timer */
|
||||
float frame_ticks;
|
||||
float next_frame;
|
||||
};
|
||||
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
|
||||
|
||||
#endif /* _SDL_esdaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,351 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Allow access to a raw mixing buffer */
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audiomem.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_fsaudio.h"
|
||||
|
||||
#include <fusionsound/fusionsound_version.h>
|
||||
|
||||
//#define SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "libfusionsound.so"
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
||||
#include "SDL_name.h"
|
||||
#include "SDL_loadso.h"
|
||||
#else
|
||||
#define SDL_NAME(X) X
|
||||
#endif
|
||||
|
||||
#if (FUSIONSOUND_MAJOR_VERSION == 1) && (FUSIONSOUND_MINOR_VERSION < 1)
|
||||
typedef DFBResult DirectResult;
|
||||
#endif
|
||||
|
||||
/* The tag name used by fusionsoundc audio */
|
||||
#define SDL_FS_DRIVER_NAME "fusionsound"
|
||||
/* Buffers to use - more than 2 gives a lot of latency */
|
||||
#define FUSION_BUFFERS (2)
|
||||
|
||||
#ifdef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
||||
|
||||
static const char *fs_library = SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC;
|
||||
static void *fs_handle = NULL;
|
||||
|
||||
static DirectResult (*SDL_NAME(FusionSoundInit)) (int *argc, char *(*argv[]));
|
||||
static DirectResult (*SDL_NAME(FusionSoundCreate)) (IFusionSound **
|
||||
ret_interface);
|
||||
|
||||
#define SDL_FS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
void **func;
|
||||
} fs_functions[] = {
|
||||
/* *INDENT-OFF* */
|
||||
SDL_FS_SYM(FusionSoundInit),
|
||||
SDL_FS_SYM(FusionSoundCreate),
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
#undef SDL_FS_SYM
|
||||
|
||||
static void
|
||||
UnloadFusionSoundLibrary()
|
||||
{
|
||||
if (fs_handle != NULL) {
|
||||
SDL_UnloadObject(fs_handle);
|
||||
fs_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
LoadFusionSoundLibrary(void)
|
||||
{
|
||||
int i, retval = -1;
|
||||
|
||||
if (fs_handle == NULL) {
|
||||
fs_handle = SDL_LoadObject(fs_library);
|
||||
if (fs_handle != NULL) {
|
||||
retval = 0;
|
||||
for (i = 0; i < SDL_arraysize(fs_functions); ++i) {
|
||||
*fs_functions[i].func =
|
||||
SDL_LoadFunction(fs_handle, fs_functions[i].name);
|
||||
if (!*fs_functions[i].func) {
|
||||
retval = -1;
|
||||
UnloadFusionSoundLibrary();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void
|
||||
UnloadFusionSoundLibrary()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
LoadFusionSoundLibrary(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */
|
||||
|
||||
/* This function waits until it is possible to write a full sound buffer */
|
||||
static void
|
||||
SDL_FS_WaitDevice(_THIS)
|
||||
{
|
||||
this->hidden->stream->Wait(this->hidden->stream,
|
||||
this->hidden->mixsamples);
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_FS_PlayDevice(_THIS)
|
||||
{
|
||||
DirectResult ret;
|
||||
|
||||
ret = this->hidden->stream->Write(this->hidden->stream,
|
||||
this->hidden->mixbuf,
|
||||
this->hidden->mixsamples);
|
||||
/* If we couldn't write, assume fatal error for now */
|
||||
if (ret) {
|
||||
this->enabled = 0;
|
||||
}
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_FS_WaitDone(_THIS)
|
||||
{
|
||||
this->hidden->stream->Wait(this->hidden->stream,
|
||||
this->hidden->mixsamples * FUSION_BUFFERS);
|
||||
}
|
||||
|
||||
|
||||
static Uint8 *
|
||||
SDL_FS_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
SDL_FS_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
if (this->hidden->stream) {
|
||||
this->hidden->stream->Release(this->hidden->stream);
|
||||
this->hidden->stream = NULL;
|
||||
}
|
||||
if (this->hidden->fs) {
|
||||
this->hidden->fs->Release(this->hidden->fs);
|
||||
this->hidden->fs = NULL;
|
||||
}
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
int bytes;
|
||||
SDL_AudioFormat test_format = 0, format = 0;
|
||||
FSSampleFormat fs_format;
|
||||
FSStreamDescription desc;
|
||||
DirectResult ret;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
!format && test_format;) {
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
|
||||
#endif
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
fs_format = FSSF_U8;
|
||||
bytes = 1;
|
||||
format = 1;
|
||||
break;
|
||||
case AUDIO_S16SYS:
|
||||
fs_format = FSSF_S16;
|
||||
bytes = 2;
|
||||
format = 1;
|
||||
break;
|
||||
case AUDIO_S32SYS:
|
||||
fs_format = FSSF_S32;
|
||||
bytes = 4;
|
||||
format = 1;
|
||||
break;
|
||||
case AUDIO_F32SYS:
|
||||
fs_format = FSSF_FLOAT;
|
||||
bytes = 4;
|
||||
format = 1;
|
||||
break;
|
||||
default:
|
||||
format = 0;
|
||||
break;
|
||||
}
|
||||
if (!format) {
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
}
|
||||
|
||||
if (format == 0) {
|
||||
SDL_FS_CloseDevice(this);
|
||||
SDL_SetError("Couldn't find any hardware audio formats");
|
||||
return 0;
|
||||
}
|
||||
this->spec.format = test_format;
|
||||
|
||||
/* Retrieve the main sound interface. */
|
||||
ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs);
|
||||
if (ret) {
|
||||
SDL_FS_CloseDevice(this);
|
||||
SDL_SetError("Unable to initialize FusionSound: %d", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->hidden->mixsamples = this->spec.size / bytes / this->spec.channels;
|
||||
|
||||
/* Fill stream description. */
|
||||
desc.flags = FSSDF_SAMPLERATE | FSSDF_BUFFERSIZE |
|
||||
FSSDF_CHANNELS | FSSDF_SAMPLEFORMAT | FSSDF_PREBUFFER;
|
||||
desc.samplerate = this->spec.freq;
|
||||
desc.buffersize = this->spec.size * FUSION_BUFFERS;
|
||||
desc.channels = this->spec.channels;
|
||||
desc.prebuffer = 10;
|
||||
desc.sampleformat = fs_format;
|
||||
|
||||
ret =
|
||||
this->hidden->fs->CreateStream(this->hidden->fs, &desc,
|
||||
&this->hidden->stream);
|
||||
if (ret) {
|
||||
SDL_FS_CloseDevice(this);
|
||||
SDL_SetError("Unable to create FusionSoundStream: %d", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* See what we got */
|
||||
desc.flags = FSSDF_SAMPLERATE | FSSDF_BUFFERSIZE |
|
||||
FSSDF_CHANNELS | FSSDF_SAMPLEFORMAT;
|
||||
ret = this->hidden->stream->GetDescription(this->hidden->stream, &desc);
|
||||
|
||||
this->spec.freq = desc.samplerate;
|
||||
this->spec.size =
|
||||
desc.buffersize / FUSION_BUFFERS * bytes * desc.channels;
|
||||
this->spec.channels = desc.channels;
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
if (this->hidden->mixbuf == NULL) {
|
||||
SDL_FS_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||
|
||||
/* We're ready to rock and roll. :-) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
SDL_FS_Deinitialize(void)
|
||||
{
|
||||
UnloadFusionSoundLibrary();
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
SDL_FS_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
if (LoadFusionSoundLibrary() < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
DirectResult ret;
|
||||
|
||||
ret = SDL_NAME(FusionSoundInit) (NULL, NULL);
|
||||
if (ret) {
|
||||
UnloadFusionSoundLibrary();
|
||||
SDL_SetError
|
||||
("FusionSound: SDL_FS_init failed (FusionSoundInit: %d)",
|
||||
ret);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = SDL_FS_OpenDevice;
|
||||
impl->PlayDevice = SDL_FS_PlayDevice;
|
||||
impl->WaitDevice = SDL_FS_WaitDevice;
|
||||
impl->GetDeviceBuf = SDL_FS_GetDeviceBuf;
|
||||
impl->CloseDevice = SDL_FS_CloseDevice;
|
||||
impl->WaitDone = SDL_FS_WaitDone;
|
||||
impl->Deinitialize = SDL_FS_Deinitialize;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
AudioBootStrap FUSIONSOUND_bootstrap = {
|
||||
SDL_FS_DRIVER_NAME, "FusionSound", SDL_FS_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_fsaudio_h
|
||||
#define _SDL_fsaudio_h
|
||||
|
||||
#include <fusionsound/fusionsound.h>
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
/* Interface */
|
||||
IFusionSound *fs;
|
||||
|
||||
/* The stream interface for the audio device */
|
||||
IFusionSoundStream *stream;
|
||||
|
||||
/* Raw mixing buffer */
|
||||
Uint8 *mixbuf;
|
||||
int mixlen;
|
||||
int mixsamples;
|
||||
|
||||
};
|
||||
|
||||
#endif /* _SDL_fsaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,340 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include <AudioUnit/AudioUnit.h>
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_sysaudio.h"
|
||||
#include "SDL_coreaudio_iphone.h"
|
||||
|
||||
#define DEBUG_COREAUDIO 0
|
||||
|
||||
static void
|
||||
COREAUDIO_Deinitialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* The CoreAudio callback */
|
||||
static OSStatus
|
||||
outputCallback(void *inRefCon,
|
||||
AudioUnitRenderActionFlags * ioActionFlags,
|
||||
const AudioTimeStamp * inTimeStamp,
|
||||
UInt32 inBusNumber, UInt32 inNumberFrames,
|
||||
AudioBufferList * ioDataList)
|
||||
{
|
||||
SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
|
||||
AudioBuffer *ioData = &ioDataList->mBuffers[0];
|
||||
UInt32 remaining, len;
|
||||
void *ptr;
|
||||
|
||||
/* Is there ever more than one buffer, and what do you do with it? */
|
||||
if (ioDataList->mNumberBuffers != 1) {
|
||||
return noErr;
|
||||
}
|
||||
|
||||
/* Only do anything if audio is enabled and not paused */
|
||||
if (!this->enabled || this->paused) {
|
||||
SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* No SDL conversion should be needed here, ever, since we accept
|
||||
any input format in OpenAudio, and leave the conversion to CoreAudio.
|
||||
*/
|
||||
/*
|
||||
assert(!this->convert.needed);
|
||||
assert(this->spec.channels == ioData->mNumberChannels);
|
||||
*/
|
||||
|
||||
remaining = ioData->mDataByteSize;
|
||||
ptr = ioData->mData;
|
||||
while (remaining > 0) {
|
||||
if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
|
||||
/* Generate the data */
|
||||
SDL_memset(this->hidden->buffer, this->spec.silence,
|
||||
this->hidden->bufferSize);
|
||||
SDL_mutexP(this->mixer_lock);
|
||||
(*this->spec.callback) (this->spec.userdata, this->hidden->buffer,
|
||||
this->hidden->bufferSize);
|
||||
SDL_mutexV(this->mixer_lock);
|
||||
this->hidden->bufferOffset = 0;
|
||||
}
|
||||
|
||||
len = this->hidden->bufferSize - this->hidden->bufferOffset;
|
||||
if (len > remaining)
|
||||
len = remaining;
|
||||
SDL_memcpy(ptr,
|
||||
(char *) this->hidden->buffer + this->hidden->bufferOffset,
|
||||
len);
|
||||
ptr = (char *) ptr + len;
|
||||
remaining -= len;
|
||||
this->hidden->bufferOffset += len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static OSStatus
|
||||
inputCallback(void *inRefCon,
|
||||
AudioUnitRenderActionFlags * ioActionFlags,
|
||||
const AudioTimeStamp * inTimeStamp,
|
||||
UInt32 inBusNumber, UInt32 inNumberFrames,
|
||||
AudioBufferList * ioData)
|
||||
{
|
||||
//err = AudioUnitRender(afr->fAudioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, afr->fAudioBuffer);
|
||||
// !!! FIXME: write me!
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
COREAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->audioUnitOpened) {
|
||||
OSStatus result = noErr;
|
||||
AURenderCallbackStruct callback;
|
||||
const AudioUnitElement output_bus = 0;
|
||||
const AudioUnitElement input_bus = 1;
|
||||
const int iscapture = this->iscapture;
|
||||
const AudioUnitElement bus =
|
||||
((iscapture) ? input_bus : output_bus);
|
||||
const AudioUnitScope scope =
|
||||
((iscapture) ? kAudioUnitScope_Output :
|
||||
kAudioUnitScope_Input);
|
||||
|
||||
/* stop processing the audio unit */
|
||||
result = AudioOutputUnitStop(this->hidden->audioUnit);
|
||||
|
||||
/* Remove the input callback */
|
||||
SDL_memset(&callback, '\0', sizeof(AURenderCallbackStruct));
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
scope, bus, &callback,
|
||||
sizeof(callback));
|
||||
|
||||
//CloseComponent(this->hidden->audioUnit);
|
||||
this->hidden->audioUnitOpened = 0;
|
||||
}
|
||||
SDL_free(this->hidden->buffer);
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define CHECK_RESULT(msg) \
|
||||
if (result != noErr) { \
|
||||
COREAUDIO_CloseDevice(this); \
|
||||
SDL_SetError("CoreAudio error (%s): %d", msg, result); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
static int
|
||||
prepare_audiounit(_THIS, const char *devname, int iscapture,
|
||||
const AudioStreamBasicDescription * strdesc)
|
||||
{
|
||||
OSStatus result = noErr;
|
||||
AURenderCallbackStruct callback;
|
||||
AudioComponentDescription desc;
|
||||
AudioComponent comp = NULL;
|
||||
|
||||
UInt32 enableIO = 0;
|
||||
const AudioUnitElement output_bus = 0;
|
||||
const AudioUnitElement input_bus = 1;
|
||||
const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus);
|
||||
const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output :
|
||||
kAudioUnitScope_Input);
|
||||
|
||||
SDL_memset(&desc, '\0', sizeof(AudioComponentDescription));
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_RemoteIO;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
|
||||
comp = AudioComponentFindNext(NULL, &desc);
|
||||
if (comp == NULL) {
|
||||
SDL_SetError("Couldn't find requested CoreAudio component");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Open & initialize the audio unit */
|
||||
/*
|
||||
AudioComponentInstanceNew only available on iPhone OS 2.0 and Mac OS X 10.6
|
||||
We can't use OpenAComponent on iPhone because it is not present
|
||||
*/
|
||||
result = AudioComponentInstanceNew(comp, &this->hidden->audioUnit);
|
||||
CHECK_RESULT("AudioComponentInstanceNew");
|
||||
|
||||
this->hidden->audioUnitOpened = 1;
|
||||
|
||||
// !!! FIXME: this is wrong?
|
||||
enableIO = ((iscapture) ? 1 : 0);
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Input, input_bus,
|
||||
&enableIO, sizeof(enableIO));
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO input)");
|
||||
|
||||
// !!! FIXME: this is wrong?
|
||||
enableIO = ((iscapture) ? 0 : 1);
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Output, output_bus,
|
||||
&enableIO, sizeof(enableIO));
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO output)");
|
||||
|
||||
/*result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioOutputUnitProperty_CurrentDevice,
|
||||
kAudioUnitScope_Global, 0,
|
||||
&this->hidden->deviceID,
|
||||
sizeof(AudioDeviceID));
|
||||
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)"); */
|
||||
|
||||
/* Set the data format of the audio unit. */
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
scope, bus, strdesc, sizeof(*strdesc));
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)");
|
||||
|
||||
/* Set the audio callback */
|
||||
SDL_memset(&callback, '\0', sizeof(AURenderCallbackStruct));
|
||||
callback.inputProc = ((iscapture) ? inputCallback : outputCallback);
|
||||
callback.inputProcRefCon = this;
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
scope, bus, &callback, sizeof(callback));
|
||||
CHECK_RESULT
|
||||
("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)");
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Allocate a sample buffer */
|
||||
this->hidden->bufferOffset = this->hidden->bufferSize = this->spec.size;
|
||||
this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
|
||||
|
||||
result = AudioUnitInitialize(this->hidden->audioUnit);
|
||||
CHECK_RESULT("AudioUnitInitialize");
|
||||
|
||||
/* Finally, start processing of the audio unit */
|
||||
result = AudioOutputUnitStart(this->hidden->audioUnit);
|
||||
CHECK_RESULT("AudioOutputUnitStart");
|
||||
/* We're running! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
AudioStreamBasicDescription strdesc;
|
||||
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
int valid_datatype = 0;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return (0);
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Setup a AudioStreamBasicDescription with the requested format */
|
||||
SDL_memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription));
|
||||
strdesc.mFormatID = kAudioFormatLinearPCM;
|
||||
strdesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
|
||||
strdesc.mChannelsPerFrame = this->spec.channels;
|
||||
strdesc.mSampleRate = this->spec.freq;
|
||||
strdesc.mFramesPerPacket = 1;
|
||||
|
||||
while ((!valid_datatype) && (test_format)) {
|
||||
this->spec.format = test_format;
|
||||
/* Just a list of valid SDL formats, so people don't pass junk here. */
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
case AUDIO_S8:
|
||||
case AUDIO_U16LSB:
|
||||
case AUDIO_S16LSB:
|
||||
case AUDIO_U16MSB:
|
||||
case AUDIO_S16MSB:
|
||||
case AUDIO_S32LSB:
|
||||
case AUDIO_S32MSB:
|
||||
case AUDIO_F32LSB:
|
||||
case AUDIO_F32MSB:
|
||||
valid_datatype = 1;
|
||||
strdesc.mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
|
||||
if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
|
||||
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
|
||||
|
||||
if (SDL_AUDIO_ISFLOAT(this->spec.format))
|
||||
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
|
||||
else if (SDL_AUDIO_ISSIGNED(this->spec.format))
|
||||
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
||||
COREAUDIO_CloseDevice(this);
|
||||
SDL_SetError("Unsupported audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
strdesc.mBytesPerFrame =
|
||||
strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
|
||||
strdesc.mBytesPerPacket =
|
||||
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
|
||||
|
||||
if (!prepare_audiounit(this, devname, iscapture, &strdesc)) {
|
||||
COREAUDIO_CloseDevice(this);
|
||||
return 0; /* prepare_audiounit() will call SDL_SetError()... */
|
||||
}
|
||||
|
||||
return 1; /* good to go. */
|
||||
}
|
||||
|
||||
static int
|
||||
COREAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = COREAUDIO_OpenDevice;
|
||||
impl->CloseDevice = COREAUDIO_CloseDevice;
|
||||
impl->Deinitialize = COREAUDIO_Deinitialize;
|
||||
impl->ProvidesOwnCallbackThread = 1;
|
||||
|
||||
/* added for iPhone */
|
||||
impl->OnlyHasDefaultInputDevice = 1;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
impl->HasCaptureSupport = 0; /* still needs to be written */
|
||||
|
||||
return 2; /* defitely have an audio device. */
|
||||
}
|
||||
|
||||
AudioBootStrap COREAUDIOIPHONE_bootstrap = {
|
||||
"coreaudio-iphoneos", "SDL CoreAudio (iPhone OS) audio driver",
|
||||
COREAUDIO_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_coreaudio_h
|
||||
#define _SDL_coreaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
AudioUnit audioUnit;
|
||||
int audioUnitOpened;
|
||||
void *buffer;
|
||||
UInt32 bufferOffset;
|
||||
UInt32 bufferSize;
|
||||
// AudioDeviceID deviceID;
|
||||
};
|
||||
|
||||
#endif /* _SDL_coreaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,600 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include <CoreAudio/CoreAudio.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <AudioUnit/AudioUnit.h>
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED == 1050
|
||||
#include <AudioUnit/AUNTComponent.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_sysaudio.h"
|
||||
#include "SDL_coreaudio.h"
|
||||
|
||||
#define DEBUG_COREAUDIO 0
|
||||
|
||||
typedef struct COREAUDIO_DeviceList
|
||||
{
|
||||
AudioDeviceID id;
|
||||
const char *name;
|
||||
} COREAUDIO_DeviceList;
|
||||
|
||||
static COREAUDIO_DeviceList *inputDevices = NULL;
|
||||
static int inputDeviceCount = 0;
|
||||
static COREAUDIO_DeviceList *outputDevices = NULL;
|
||||
static int outputDeviceCount = 0;
|
||||
|
||||
static void
|
||||
free_device_list(COREAUDIO_DeviceList ** devices, int *devCount)
|
||||
{
|
||||
if (*devices) {
|
||||
int i = *devCount;
|
||||
while (i--)
|
||||
SDL_free((void *) (*devices)[i].name);
|
||||
SDL_free(*devices);
|
||||
*devices = NULL;
|
||||
}
|
||||
*devCount = 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
build_device_list(int iscapture, COREAUDIO_DeviceList ** devices,
|
||||
int *devCount)
|
||||
{
|
||||
Boolean outWritable = 0;
|
||||
OSStatus result = noErr;
|
||||
UInt32 size = 0;
|
||||
AudioDeviceID *devs = NULL;
|
||||
UInt32 i = 0;
|
||||
UInt32 max = 0;
|
||||
|
||||
free_device_list(devices, devCount);
|
||||
|
||||
result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
|
||||
&size, &outWritable);
|
||||
|
||||
if (result != kAudioHardwareNoError)
|
||||
return;
|
||||
|
||||
devs = (AudioDeviceID *) alloca(size);
|
||||
if (devs == NULL)
|
||||
return;
|
||||
|
||||
max = size / sizeof(AudioDeviceID);
|
||||
*devices = (COREAUDIO_DeviceList *) SDL_malloc(max * sizeof(**devices));
|
||||
if (*devices == NULL)
|
||||
return;
|
||||
|
||||
result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
|
||||
&size, devs);
|
||||
if (result != kAudioHardwareNoError)
|
||||
return;
|
||||
|
||||
for (i = 0; i < max; i++) {
|
||||
CFStringRef cfstr = NULL;
|
||||
char *ptr = NULL;
|
||||
AudioDeviceID dev = devs[i];
|
||||
AudioBufferList *buflist = NULL;
|
||||
int usable = 0;
|
||||
CFIndex len = 0;
|
||||
|
||||
result = AudioDeviceGetPropertyInfo(dev, 0, iscapture,
|
||||
kAudioDevicePropertyStreamConfiguration,
|
||||
&size, &outWritable);
|
||||
if (result != noErr)
|
||||
continue;
|
||||
|
||||
buflist = (AudioBufferList *) SDL_malloc(size);
|
||||
if (buflist == NULL)
|
||||
continue;
|
||||
|
||||
result = AudioDeviceGetProperty(dev, 0, iscapture,
|
||||
kAudioDevicePropertyStreamConfiguration,
|
||||
&size, buflist);
|
||||
|
||||
if (result == noErr) {
|
||||
UInt32 j;
|
||||
for (j = 0; j < buflist->mNumberBuffers; j++) {
|
||||
if (buflist->mBuffers[j].mNumberChannels > 0) {
|
||||
usable = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_free(buflist);
|
||||
|
||||
if (!usable)
|
||||
continue;
|
||||
|
||||
size = sizeof(CFStringRef);
|
||||
result = AudioDeviceGetProperty(dev, 0, iscapture,
|
||||
kAudioDevicePropertyDeviceNameCFString,
|
||||
&size, &cfstr);
|
||||
|
||||
if (result != kAudioHardwareNoError)
|
||||
continue;
|
||||
|
||||
len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
|
||||
kCFStringEncodingUTF8);
|
||||
|
||||
ptr = (char *) SDL_malloc(len + 1);
|
||||
usable = ((ptr != NULL) &&
|
||||
(CFStringGetCString
|
||||
(cfstr, ptr, len + 1, kCFStringEncodingUTF8)));
|
||||
|
||||
CFRelease(cfstr);
|
||||
|
||||
if (usable) {
|
||||
len = strlen(ptr);
|
||||
/* Some devices have whitespace at the end...trim it. */
|
||||
while ((len > 0) && (ptr[len - 1] == ' ')) {
|
||||
len--;
|
||||
}
|
||||
usable = (len > 0);
|
||||
}
|
||||
|
||||
if (!usable) {
|
||||
SDL_free(ptr);
|
||||
} else {
|
||||
ptr[len] = '\0';
|
||||
|
||||
#if DEBUG_COREAUDIO
|
||||
printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n",
|
||||
((iscapture) ? "capture" : "output"),
|
||||
(int) *devCount, ptr, (int) dev);
|
||||
#endif
|
||||
|
||||
(*devices)[*devCount].id = dev;
|
||||
(*devices)[*devCount].name = ptr;
|
||||
(*devCount)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_lists(void)
|
||||
{
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
free_device_lists(void)
|
||||
{
|
||||
free_device_list(&outputDevices, &outputDeviceCount);
|
||||
free_device_list(&inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
find_device_id(const char *devname, int iscapture, AudioDeviceID * id)
|
||||
{
|
||||
int i = ((iscapture) ? inputDeviceCount : outputDeviceCount);
|
||||
COREAUDIO_DeviceList *devs = ((iscapture) ? inputDevices : outputDevices);
|
||||
while (i--) {
|
||||
if (SDL_strcmp(devname, devs->name) == 0) {
|
||||
*id = devs->id;
|
||||
return 1;
|
||||
}
|
||||
devs++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
COREAUDIO_DetectDevices(int iscapture)
|
||||
{
|
||||
if (iscapture) {
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
return inputDeviceCount;
|
||||
} else {
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
return outputDeviceCount;
|
||||
}
|
||||
|
||||
return 0; /* shouldn't ever hit this. */
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
COREAUDIO_GetDeviceName(int index, int iscapture)
|
||||
{
|
||||
if ((iscapture) && (index < inputDeviceCount)) {
|
||||
return inputDevices[index].name;
|
||||
} else if ((!iscapture) && (index < outputDeviceCount)) {
|
||||
return outputDevices[index].name;
|
||||
}
|
||||
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
COREAUDIO_Deinitialize(void)
|
||||
{
|
||||
free_device_lists();
|
||||
}
|
||||
|
||||
|
||||
/* The CoreAudio callback */
|
||||
static OSStatus
|
||||
outputCallback(void *inRefCon,
|
||||
AudioUnitRenderActionFlags * ioActionFlags,
|
||||
const AudioTimeStamp * inTimeStamp,
|
||||
UInt32 inBusNumber, UInt32 inNumberFrames,
|
||||
AudioBufferList * ioDataList)
|
||||
{
|
||||
SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
|
||||
AudioBuffer *ioData = &ioDataList->mBuffers[0];
|
||||
UInt32 remaining, len;
|
||||
void *ptr;
|
||||
|
||||
/* Is there ever more than one buffer, and what do you do with it? */
|
||||
if (ioDataList->mNumberBuffers != 1) {
|
||||
return noErr;
|
||||
}
|
||||
|
||||
/* Only do anything if audio is enabled and not paused */
|
||||
if (!this->enabled || this->paused) {
|
||||
SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* No SDL conversion should be needed here, ever, since we accept
|
||||
any input format in OpenAudio, and leave the conversion to CoreAudio.
|
||||
*/
|
||||
/*
|
||||
assert(!this->convert.needed);
|
||||
assert(this->spec.channels == ioData->mNumberChannels);
|
||||
*/
|
||||
|
||||
remaining = ioData->mDataByteSize;
|
||||
ptr = ioData->mData;
|
||||
while (remaining > 0) {
|
||||
if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
|
||||
/* Generate the data */
|
||||
SDL_memset(this->hidden->buffer, this->spec.silence,
|
||||
this->hidden->bufferSize);
|
||||
SDL_mutexP(this->mixer_lock);
|
||||
(*this->spec.callback) (this->spec.userdata, this->hidden->buffer,
|
||||
this->hidden->bufferSize);
|
||||
SDL_mutexV(this->mixer_lock);
|
||||
this->hidden->bufferOffset = 0;
|
||||
}
|
||||
|
||||
len = this->hidden->bufferSize - this->hidden->bufferOffset;
|
||||
if (len > remaining)
|
||||
len = remaining;
|
||||
SDL_memcpy(ptr,
|
||||
(char *) this->hidden->buffer + this->hidden->bufferOffset,
|
||||
len);
|
||||
ptr = (char *) ptr + len;
|
||||
remaining -= len;
|
||||
this->hidden->bufferOffset += len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static OSStatus
|
||||
inputCallback(void *inRefCon,
|
||||
AudioUnitRenderActionFlags * ioActionFlags,
|
||||
const AudioTimeStamp * inTimeStamp,
|
||||
UInt32 inBusNumber, UInt32 inNumberFrames,
|
||||
AudioBufferList * ioData)
|
||||
{
|
||||
//err = AudioUnitRender(afr->fAudioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, afr->fAudioBuffer);
|
||||
// !!! FIXME: write me!
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
COREAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->audioUnitOpened) {
|
||||
OSStatus result = noErr;
|
||||
AURenderCallbackStruct callback;
|
||||
const AudioUnitElement output_bus = 0;
|
||||
const AudioUnitElement input_bus = 1;
|
||||
const int iscapture = this->iscapture;
|
||||
const AudioUnitElement bus =
|
||||
((iscapture) ? input_bus : output_bus);
|
||||
const AudioUnitScope scope =
|
||||
((iscapture) ? kAudioUnitScope_Output :
|
||||
kAudioUnitScope_Input);
|
||||
|
||||
/* stop processing the audio unit */
|
||||
result = AudioOutputUnitStop(this->hidden->audioUnit);
|
||||
|
||||
/* Remove the input callback */
|
||||
SDL_memset(&callback, '\0', sizeof(AURenderCallbackStruct));
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
scope, bus, &callback,
|
||||
sizeof(callback));
|
||||
|
||||
CloseComponent(this->hidden->audioUnit);
|
||||
this->hidden->audioUnitOpened = 0;
|
||||
}
|
||||
SDL_free(this->hidden->buffer);
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define CHECK_RESULT(msg) \
|
||||
if (result != noErr) { \
|
||||
COREAUDIO_CloseDevice(this); \
|
||||
SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
static int
|
||||
find_device_by_name(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
AudioDeviceID devid = 0;
|
||||
OSStatus result = noErr;
|
||||
UInt32 size = 0;
|
||||
UInt32 alive = 0;
|
||||
pid_t pid = 0;
|
||||
|
||||
if (devname == NULL) {
|
||||
size = sizeof(AudioDeviceID);
|
||||
const AudioHardwarePropertyID propid =
|
||||
((iscapture) ? kAudioHardwarePropertyDefaultInputDevice :
|
||||
kAudioHardwarePropertyDefaultOutputDevice);
|
||||
|
||||
result = AudioHardwareGetProperty(propid, &size, &devid);
|
||||
CHECK_RESULT("AudioHardwareGetProperty (default device)");
|
||||
} else {
|
||||
if (!find_device_id(devname, iscapture, &devid)) {
|
||||
SDL_SetError("CoreAudio: No such audio device.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size = sizeof(alive);
|
||||
result = AudioDeviceGetProperty(devid, 0, iscapture,
|
||||
kAudioDevicePropertyDeviceIsAlive,
|
||||
&size, &alive);
|
||||
CHECK_RESULT
|
||||
("AudioDeviceGetProperty (kAudioDevicePropertyDeviceIsAlive)");
|
||||
|
||||
if (!alive) {
|
||||
SDL_SetError("CoreAudio: requested device exists, but isn't alive.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = sizeof(pid);
|
||||
result = AudioDeviceGetProperty(devid, 0, iscapture,
|
||||
kAudioDevicePropertyHogMode, &size, &pid);
|
||||
|
||||
/* some devices don't support this property, so errors are fine here. */
|
||||
if ((result == noErr) && (pid != -1)) {
|
||||
SDL_SetError("CoreAudio: requested device is being hogged.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->hidden->deviceID = devid;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
prepare_audiounit(_THIS, const char *devname, int iscapture,
|
||||
const AudioStreamBasicDescription * strdesc)
|
||||
{
|
||||
OSStatus result = noErr;
|
||||
AURenderCallbackStruct callback;
|
||||
ComponentDescription desc;
|
||||
Component comp = NULL;
|
||||
UInt32 enableIO = 0;
|
||||
const AudioUnitElement output_bus = 0;
|
||||
const AudioUnitElement input_bus = 1;
|
||||
const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus);
|
||||
const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output :
|
||||
kAudioUnitScope_Input);
|
||||
|
||||
if (!find_device_by_name(this, devname, iscapture)) {
|
||||
SDL_SetError("Couldn't find requested CoreAudio device");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_memset(&desc, '\0', sizeof(ComponentDescription));
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_HALOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
|
||||
comp = FindNextComponent(NULL, &desc);
|
||||
if (comp == NULL) {
|
||||
SDL_SetError("Couldn't find requested CoreAudio component");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Open & initialize the audio unit */
|
||||
result = OpenAComponent(comp, &this->hidden->audioUnit);
|
||||
CHECK_RESULT("OpenAComponent");
|
||||
|
||||
this->hidden->audioUnitOpened = 1;
|
||||
|
||||
// !!! FIXME: this is wrong?
|
||||
enableIO = ((iscapture) ? 1 : 0);
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Input, input_bus,
|
||||
&enableIO, sizeof(enableIO));
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO input)");
|
||||
|
||||
// !!! FIXME: this is wrong?
|
||||
enableIO = ((iscapture) ? 0 : 1);
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Output, output_bus,
|
||||
&enableIO, sizeof(enableIO));
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_EnableIO output)");
|
||||
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioOutputUnitProperty_CurrentDevice,
|
||||
kAudioUnitScope_Global, 0,
|
||||
&this->hidden->deviceID,
|
||||
sizeof(AudioDeviceID));
|
||||
CHECK_RESULT
|
||||
("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)");
|
||||
|
||||
/* Set the data format of the audio unit. */
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
scope, bus, strdesc, sizeof(*strdesc));
|
||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)");
|
||||
|
||||
/* Set the audio callback */
|
||||
SDL_memset(&callback, '\0', sizeof(AURenderCallbackStruct));
|
||||
callback.inputProc = ((iscapture) ? inputCallback : outputCallback);
|
||||
callback.inputProcRefCon = this;
|
||||
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
scope, bus, &callback, sizeof(callback));
|
||||
CHECK_RESULT
|
||||
("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)");
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Allocate a sample buffer */
|
||||
this->hidden->bufferOffset = this->hidden->bufferSize = this->spec.size;
|
||||
this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
|
||||
|
||||
result = AudioUnitInitialize(this->hidden->audioUnit);
|
||||
CHECK_RESULT("AudioUnitInitialize");
|
||||
|
||||
/* Finally, start processing of the audio unit */
|
||||
result = AudioOutputUnitStart(this->hidden->audioUnit);
|
||||
CHECK_RESULT("AudioOutputUnitStart");
|
||||
|
||||
/* We're running! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
AudioStreamBasicDescription strdesc;
|
||||
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
int valid_datatype = 0;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return (0);
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Setup a AudioStreamBasicDescription with the requested format */
|
||||
SDL_memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription));
|
||||
strdesc.mFormatID = kAudioFormatLinearPCM;
|
||||
strdesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
|
||||
strdesc.mChannelsPerFrame = this->spec.channels;
|
||||
strdesc.mSampleRate = this->spec.freq;
|
||||
strdesc.mFramesPerPacket = 1;
|
||||
|
||||
while ((!valid_datatype) && (test_format)) {
|
||||
this->spec.format = test_format;
|
||||
/* Just a list of valid SDL formats, so people don't pass junk here. */
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
case AUDIO_S8:
|
||||
case AUDIO_U16LSB:
|
||||
case AUDIO_S16LSB:
|
||||
case AUDIO_U16MSB:
|
||||
case AUDIO_S16MSB:
|
||||
case AUDIO_S32LSB:
|
||||
case AUDIO_S32MSB:
|
||||
case AUDIO_F32LSB:
|
||||
case AUDIO_F32MSB:
|
||||
valid_datatype = 1;
|
||||
strdesc.mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
|
||||
if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
|
||||
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
|
||||
|
||||
if (SDL_AUDIO_ISFLOAT(this->spec.format))
|
||||
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
|
||||
else if (SDL_AUDIO_ISSIGNED(this->spec.format))
|
||||
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
||||
COREAUDIO_CloseDevice(this);
|
||||
SDL_SetError("Unsupported audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
strdesc.mBytesPerFrame =
|
||||
strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
|
||||
strdesc.mBytesPerPacket =
|
||||
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
|
||||
|
||||
if (!prepare_audiounit(this, devname, iscapture, &strdesc)) {
|
||||
COREAUDIO_CloseDevice(this);
|
||||
return 0; /* prepare_audiounit() will call SDL_SetError()... */
|
||||
}
|
||||
|
||||
return 1; /* good to go. */
|
||||
}
|
||||
|
||||
static int
|
||||
COREAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->DetectDevices = COREAUDIO_DetectDevices;
|
||||
impl->GetDeviceName = COREAUDIO_GetDeviceName;
|
||||
impl->OpenDevice = COREAUDIO_OpenDevice;
|
||||
impl->CloseDevice = COREAUDIO_CloseDevice;
|
||||
impl->Deinitialize = COREAUDIO_Deinitialize;
|
||||
impl->ProvidesOwnCallbackThread = 1;
|
||||
|
||||
build_device_lists(); /* do an initial check for devices... */
|
||||
|
||||
return (outputDeviceCount > 0) ? 2 : 1;
|
||||
}
|
||||
|
||||
AudioBootStrap COREAUDIO_bootstrap = {
|
||||
"coreaudio", "Mac OS X CoreAudio", COREAUDIO_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_coreaudio_h
|
||||
#define _SDL_coreaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
AudioUnit audioUnit;
|
||||
int audioUnitOpened;
|
||||
void *buffer;
|
||||
UInt32 bufferOffset;
|
||||
UInt32 bufferSize;
|
||||
AudioDeviceID deviceID;
|
||||
};
|
||||
|
||||
#endif /* _SDL_coreaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,260 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Tru64 UNIX MME support */
|
||||
#include <mme_api.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_mmeaudio.h"
|
||||
|
||||
static BOOL inUse[NUM_BUFFERS];
|
||||
|
||||
static void
|
||||
SetMMerror(char *function, MMRESULT code)
|
||||
{
|
||||
int len;
|
||||
char errbuf[MAXERRORLENGTH];
|
||||
|
||||
SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
|
||||
len = SDL_strlen(errbuf);
|
||||
waveOutGetErrorText(code, errbuf + len, MAXERRORLENGTH - len);
|
||||
SDL_SetError("%s", errbuf);
|
||||
}
|
||||
|
||||
static void CALLBACK
|
||||
MME_Callback(HWAVEOUT hwo,
|
||||
UINT uMsg, DWORD dwInstance, LPARAM dwParam1, LPARAM dwParam2)
|
||||
{
|
||||
WAVEHDR *wp = (WAVEHDR *) dwParam1;
|
||||
|
||||
if (uMsg == WOM_DONE)
|
||||
inUse[wp->dwUser] = FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
MME_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
int valid_format = 0;
|
||||
MMRESULT result;
|
||||
Uint8 *mixbuf = NULL;
|
||||
int i;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* Set basic WAVE format parameters */
|
||||
this->hidden->shm = mmeAllocMem(sizeof(*this->hidden->shm));
|
||||
if (this->hidden->shm == NULL) {
|
||||
MME_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_memset(this->hidden->shm, '\0', sizeof(*this->hidden->shm));
|
||||
this->hidden->shm->sound = 0;
|
||||
this->hidden->shm->wFmt.wf.wFormatTag = WAVE_FORMAT_PCM;
|
||||
|
||||
/* Determine the audio parameters from the AudioSpec */
|
||||
/* Try for a closest match on audio format */
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
!valid_format && test_format;) {
|
||||
valid_format = 1;
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
case AUDIO_S16:
|
||||
case AUDIO_S32:
|
||||
break;
|
||||
default:
|
||||
valid_format = 0;
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid_format) {
|
||||
MME_CloseDevice(this);
|
||||
SDL_SetError("Unsupported audio format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->spec.format = test_format;
|
||||
this->hidden->shm->wFmt.wBitsPerSample = SDL_AUDIO_BITSIZE(test_format);
|
||||
|
||||
/* !!! FIXME: Can this handle more than stereo? */
|
||||
this->hidden->shm->wFmt.wf.nChannels = this->spec.channels;
|
||||
this->hidden->shm->wFmt.wf.nSamplesPerSec = this->spec.freq;
|
||||
this->hidden->shm->wFmt.wf.nBlockAlign =
|
||||
this->hidden->shm->wFmt.wf.nChannels *
|
||||
this->hidden->shm->wFmt.wBitsPerSample / 8;
|
||||
this->hidden->shm->wFmt.wf.nAvgBytesPerSec =
|
||||
this->hidden->shm->wFmt.wf.nSamplesPerSec *
|
||||
this->hidden->shm->wFmt.wf.nBlockAlign;
|
||||
|
||||
/* Check the buffer size -- minimum of 1/4 second (word aligned) */
|
||||
if (this->spec.samples < (this->spec.freq / 4))
|
||||
this->spec.samples = ((this->spec.freq / 4) + 3) & ~3;
|
||||
|
||||
/* Update the fragment size as size in bytes */
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* Open the audio device */
|
||||
result = waveOutOpen(&(this->hidden->shm->sound),
|
||||
WAVE_MAPPER,
|
||||
&(this->hidden->shm->wFmt.wf),
|
||||
MME_Callback,
|
||||
NULL, (CALLBACK_FUNCTION | WAVE_OPEN_SHAREABLE));
|
||||
if (result != MMSYSERR_NOERROR) {
|
||||
MME_CloseDevice(this);
|
||||
SetMMerror("waveOutOpen()", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create the sound buffers */
|
||||
mixbuf = (Uint8 *) mmeAllocBuffer(NUM_BUFFERS * (this->spec.size));
|
||||
if (mixbuf == NULL) {
|
||||
MME_CloseDevice(this);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
this->hidden->mixbuf = mixbuf;
|
||||
|
||||
for (i = 0; i < NUM_BUFFERS; i++) {
|
||||
this->hidden->shm->wHdr[i].lpData = &mixbuf[i * (this->spec.size)];
|
||||
this->hidden->shm->wHdr[i].dwBufferLength = this->spec.size;
|
||||
this->hidden->shm->wHdr[i].dwFlags = 0;
|
||||
this->hidden->shm->wHdr[i].dwUser = i;
|
||||
this->hidden->shm->wHdr[i].dwLoops = 0; /* loop control counter */
|
||||
this->hidden->shm->wHdr[i].lpNext = NULL; /* reserved for driver */
|
||||
this->hidden->shm->wHdr[i].reserved = 0;
|
||||
inUse[i] = FALSE;
|
||||
}
|
||||
this->hidden->next_buffer = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
MME_WaitDevice(_THIS)
|
||||
{
|
||||
while (inUse[this->hidden->next_buffer]) {
|
||||
mmeWaitForCallbacks();
|
||||
mmeProcessCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8 *
|
||||
MME_GetDeviceBuf(_THIS)
|
||||
{
|
||||
void *retval = this->hidden->shm->wHdr[this->hidden->next_buffer].lpData;
|
||||
inUse[this->hidden->next_buffer] = TRUE;
|
||||
return (Uint8 *) retval;
|
||||
}
|
||||
|
||||
static void
|
||||
MME_PlayDevice(_THIS)
|
||||
{
|
||||
/* Queue it up */
|
||||
waveOutWrite(this->hidden->shm->sound,
|
||||
&(this->hidden->shm->wHdr[this->hidden->next_buffer]),
|
||||
sizeof(WAVEHDR));
|
||||
this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
|
||||
}
|
||||
|
||||
static void
|
||||
MME_WaitDone(_THIS)
|
||||
{
|
||||
MMRESULT result;
|
||||
int i;
|
||||
|
||||
if (this->hidden->shm->sound) {
|
||||
for (i = 0; i < NUM_BUFFERS; i++)
|
||||
while (inUse[i]) {
|
||||
mmeWaitForCallbacks();
|
||||
mmeProcessCallbacks();
|
||||
}
|
||||
result = waveOutReset(this->hidden->shm->sound);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
SetMMerror("waveOutReset()", result);
|
||||
mmeProcessCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
MME_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
MMRESULT result;
|
||||
|
||||
if (this->hidden->mixbuf) {
|
||||
result = mmeFreeBuffer(this->hidden->mixbuf);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
SetMMerror("mmeFreeBuffer", result);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
|
||||
if (this->hidden->shm) {
|
||||
if (this->hidden->shm->sound) {
|
||||
result = waveOutClose(this->hidden->shm->sound);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
SetMMerror("waveOutClose()", result);
|
||||
mmeProcessCallbacks();
|
||||
}
|
||||
result = mmeFreeMem(this->hidden->shm);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
SetMMerror("mmeFreeMem()", result);
|
||||
this->hidden->shm = NULL;
|
||||
}
|
||||
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
MME_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = MME_OpenDevice;
|
||||
impl->WaitDevice = MME_WaitDevice;
|
||||
impl->WaitDone = MME_WaitDone;
|
||||
impl->PlayDevice = MME_PlayDevice;
|
||||
impl->GetDeviceBuf = MME_GetDeviceBuf;
|
||||
impl->CloseDevice = MME_CloseDevice;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* !!! FIXME: Windows "windib" driver is called waveout, too */
|
||||
AudioBootStrap MMEAUDIO_bootstrap = {
|
||||
"waveout", "Tru64 MME WaveOut", MME_Init, 0
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue