It's now possible to build SDL without any C runtime at all on Windows,

using Visual C++ 2005

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401334
This commit is contained in:
Sam Lantinga 2006-02-06 08:28:51 +00:00
parent 5372bfd326
commit 6c3f928cd8
101 changed files with 8882 additions and 601 deletions

Binary file not shown.

View File

@ -3008,6 +3008,7 @@ src/main/Makefile
src/main/macos/Makefile
src/main/macosx/Makefile
src/main/macosx/Info.plist
src/stdlib/Makefile
src/audio/Makefile
src/audio/alsa/Makefile
src/audio/arts/Makefile

View File

@ -10,8 +10,10 @@ libSDLinclude_HEADERS = \
SDL_audio.h \
SDL_byteorder.h \
SDL_cdrom.h \
SDL_config.h \
SDL_copying.h \
SDL_cpuinfo.h \
SDL_ctype.h \
SDL_endian.h \
SDL_error.h \
SDL_events.h \
@ -27,11 +29,15 @@ libSDLinclude_HEADERS = \
SDL_opengl.h \
SDL_quit.h \
SDL_rwops.h \
SDL_stdarg.h \
SDL_stdlib.h \
SDL_string.h \
SDL_syswm.h \
SDL_thread.h \
SDL_timer.h \
SDL_types.h \
SDL_version.h \
SDL_video.h \
SDL_windows.h \
begin_code.h \
close_code.h

View File

@ -25,8 +25,6 @@
#ifndef _SDL_audio_h
#define _SDL_audio_h
#include <stdio.h>
#include "SDL_main.h"
#include "SDL_types.h"
#include "SDL_error.h"

87
include/SDL_config.h Normal file
View File

@ -0,0 +1,87 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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 */
#define HAVE_STDARG_H
/* Comment this if you want to build without any libc requirements */
#define HAVE_LIBC
#ifdef HAVE_LIBC
/* Various C library headers */
#define HAVE_CTYPE_H
#define HAVE_STDIO_H
#define HAVE_STDLIB_H
#define HAVE_MALLOC_H
#define HAVE_STRING_H
#if !defined(_WIN32_WCE)
#define HAVE_SIGNAL_H
#endif
/* Features provided by SDL_stdlib.h */
#if !defined(_WIN32) /* Don't use C runtime versions of these on Windows */
#define HAVE_GETENV
#define HAVE_PUTENV
#endif
#define HAVE_MALLOC
#define HAVE_REALLOC
#define HAVE_FREE
#define HAVE_ALLOCA
/*#define HAVE_QSORT*/
/* Features provided by SDL_string.h */
#define HAVE_MEMSET
#define HAVE_MEMCPY
#define HAVE_MEMMOVE
#define HAVE_MEMCMP
#define HAVE_STRLEN
#define HAVE_STRCPY
#define HAVE_STRNCPY
/*#define HAVE__STRREV*/
/*#define HAVE__STRUPR*/
/*#define HAVE__STRLWR*/
#define HAVE_STRCHR
#define HAVE_STRRCHR
#define HAVE_STRSTR
/*#define HAVE_ITOA*/
/*#define HAVE__LTOA*/
/*#define HAVE__UITOA*/
/*#define HAVE__ULTOA*/
/*#define HAVE_STRTOL*/
/*#define HAVE__I64TOA*/
/*#define HAVE__UI64TOA*/
/*#define HAVE_STRTOLL*/
#define HAVE_STRCMP
#define HAVE_STRNCMP
/*#define HAVE_STRICMP*/
/*#define HAVE_STRCASECMP*/
#define HAVE_SSCANF
/*#define HAVE_SNPRINTF*/
#define HAVE_VSNPRINTF
#endif /* HAVE_LIBC */
#endif /* _SDL_config_h */

39
include/SDL_ctype.h Normal file
View File

@ -0,0 +1,39 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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 contains portable character manipulation functions for SDL */
#ifndef _SDL_CTYPE_H_
#define _SDL_CTYPE_H_
#include "SDL_config.h"
#ifdef HAVE_CTYPE_H
#include <ctype.h>
#else
#define isdigit(X) (((X) >= '0') && ((X) <= '9'))
#define isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
#define toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
#define tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
#endif
#endif /* _SDL_CTYPE_H_ */

View File

@ -37,8 +37,6 @@
and other data sources.
*/
#include <stdio.h>
#include "SDL_types.h"
#include "SDL_rwops.h"
#include "SDL_byteorder.h"

View File

@ -38,6 +38,10 @@
extern "C" {
#endif
/* General keyboard/mouse state definitions */
#define SDL_RELEASED 0
#define SDL_PRESSED 1
/* Event enumerations */
typedef enum {
SDL_NOEVENT = 0, /* Unused (do not remove) */

View File

@ -23,29 +23,31 @@
#ifndef _SDL_getenv_h
#define _SDL_getenv_h
#include "SDL_config.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* Not all environments have a working getenv()/putenv() */
#if defined(macintosh) || defined(WIN32) || defined(_WIN32_WCE)
#define NEED_SDL_GETENV
#ifdef HAVE_GETENV
#define SDL_getenv getenv
#else
#define getenv SDL_getenv
extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
#endif
#ifdef NEED_SDL_GETENV
/* Put a variable of the form "name=value" into the environment */
#ifdef HAVE_PUTENV
#define SDL_putenv putenv
#else
#define putenv SDL_putenv
extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
#define putenv(X) SDL_putenv(X)
/* Retrieve a variable named "name" from the environment */
extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
#define getenv(X) SDL_getenv(X)
#endif /* NEED_GETENV */
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -115,7 +115,7 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
Button 4: Mouse wheel up (may also be a real button)
Button 5: Mouse wheel down (may also be a real button)
*/
#define SDL_BUTTON(X) (SDL_PRESSED << ((X)-1))
#define SDL_BUTTON(X) (1 << ((X)-1))
#define SDL_BUTTON_LEFT 1
#define SDL_BUTTON_MIDDLE 2
#define SDL_BUTTON_RIGHT 3

View File

@ -27,7 +27,11 @@
#ifndef _SDL_RWops_h
#define _SDL_RWops_h
#include "SDL_config.h"
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#include "SDL_types.h"
@ -63,10 +67,12 @@ typedef struct SDL_RWops {
Uint32 type;
union {
#ifdef HAVE_STDIO_H
struct {
int autoclose;
FILE *fp;
} stdio;
#endif
struct {
Uint8 *base;
Uint8 *here;
@ -84,7 +90,9 @@ typedef struct SDL_RWops {
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, int 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);
@ -92,9 +100,13 @@ 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, SEEK_CUR)
#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)

34
include/SDL_stdarg.h Normal file
View File

@ -0,0 +1,34 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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_stdarg_h
#define _SDL_stdarg_h
#include "SDL_config.h"
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#else
#error Need stdarg.h equivalent for this platform
#endif
#endif /* _SDL_stdarg_h */

105
include/SDL_stdlib.h Normal file
View File

@ -0,0 +1,105 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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_stdlib_h
#define _SDL_stdlib_h
#include "SDL_config.h"
/* AIX requires this to be the first thing in the file. */
#ifndef __GNUC__
# if HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca ();
# endif
# endif
# endif
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include "SDL_types.h"
#include "SDL_stdarg.h"
#include "SDL_getenv.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_MALLOC
#define SDL_malloc malloc
#else
#define malloc SDL_malloc
extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
#endif
#ifdef HAVE_REALLOC
#define SDL_realloc realloc
#else
#define realloc SDL_realloc
extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
#endif
#ifdef HAVE_FREE
#define SDL_free free
#else
#define free SDL_free
extern DECLSPEC void SDLCALL SDL_free(void *mem);
#endif
#ifdef HAVE_ALLOCA
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count)
#define SDL_stack_free(data)
#else
#define SDL_stack_alloc(type, count) SDL_malloc(sizeof(type)*count)
#define SDL_stack_free(data) SDL_free(data)
#endif
#ifdef HAVE_QSORT
#define SDL_qsort qsort
#else
#define qsort SDL_qsort
extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *));
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_stdlib_h */

359
include/SDL_string.h Normal file
View File

@ -0,0 +1,359 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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 contains portable string manipulation functions for SDL */
#ifndef _SDL_string_h
#define _SDL_string_h
#include "SDL_config.h"
#ifdef HAVE_STDIO_H
#include <stdio.h> /* For snprintf() and friends */
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "SDL_types.h"
#include "SDL_stdarg.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef HAVE_MEMSET
#define memset SDL_memset
#endif
#ifndef SDL_memset
extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
#endif
#if defined(__GNUC__) && defined(i386)
#define SDL_memset4(dst, val, len) \
do { \
int u0, u1, u2; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; stosl\n\t" \
: "=&D" (u0), "=&a" (u1), "=&c" (u2) \
: "0" (dst), "1" (val), "2" ((Uint32)(len)) \
: "memory" ); \
} while(0)
#endif
#ifndef SDL_memset4
#define SDL_memset4(dst, val, len) \
do { \
unsigned _count = (len); \
unsigned _n = (_count + 3) / 4; \
Uint32 *_p = (Uint32 *)(dst); \
Uint32 _val = (val); \
switch (_count % 4) { \
case 0: do { *_p++ = _val; \
case 3: *_p++ = _val; \
case 2: *_p++ = _val; \
case 1: *_p++ = _val; \
} while ( --_n ); \
} \
} while(0)
#endif
#if defined(__GNUC__) && defined(i386)
#define SDL_memcpy(dst, src, len) \
do { \
int u0, u1, u2; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl\n\t" \
"testb $2,%b4\n\t" \
"je 1f\n\t" \
"movsw\n" \
"1:\ttestb $1,%b4\n\t" \
"je 2f\n\t" \
"movsb\n" \
"2:" \
: "=&c" (u0), "=&D" (u1), "=&S" (u2) \
: "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
: "memory" ); \
} while(0)
#define SDL_memcpy4(dst, src, len) \
do { \
int ecx, edi, esi; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl" \
: "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
: "0" ((unsigned)(len)), "1" (dst), "2" (src) \
: "memory" ); \
} while(0)
#endif
#ifndef HAVE_MEMCPY
#define memcpy SDL_memcpy
#endif
#ifndef SDL_memcpy
extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
#endif
#if defined(__GNUC__) && defined(i386)
#define SDL_memcpy4(dst, src, len) \
do { \
int ecx, edi, esi; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl" \
: "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
: "0" ((unsigned)(len)), "1" (dst), "2" (src) \
: "memory" ); \
} while(0)
#endif
#ifndef SDL_memcpy4
#define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2)
#endif
#if defined(__GNUC__) && defined(i386)
#define SDL_revcpy(dst, src, len) \
do { \
int u0, u1, u2; \
char *dstp = (char *)(dst); \
char *srcp = (char *)(src); \
int n = (len); \
if ( n >= 4 ) { \
__asm__ __volatile__ ( \
"std\n\t" \
"rep ; movsl\n\t" \
: "=&c" (u0), "=&D" (u1), "=&S" (u2) \
: "0" (n >> 2), \
"1" (dstp+(n-4)), "2" (srcp+(n-4)) \
: "memory" ); \
} \
switch (n & 3) { \
case 3: dstp[2] = srcp[2]; \
case 2: dstp[1] = srcp[1]; \
case 1: dstp[0] = srcp[0]; \
break; \
default: \
break; \
} \
} while(0)
#endif
#ifndef SDL_revcpy
extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
#endif
#ifndef HAVE_MEMMOVE
#define memmove SDL_memmove
#endif
#define SDL_memmove(dst, src, len) \
do { \
if ( dst < src ) { \
SDL_memcpy(dst, src, len); \
} else { \
SDL_revcpy(dst, src, len); \
} \
} while(0)
#ifndef HAVE_MEMCMP
#define memcmp SDL_memcmp
#endif
#ifndef SDL_memcmp
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
#endif
#ifdef HAVE_STRLEN
#define SDL_strlen strlen
#else
#define strlen SDL_strlen
extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
#endif
#ifdef HAVE_STRCPY
#define SDL_strcpy strcpy
#else
#define strcpy SDL_strcpy
extern DECLSPEC char * SDLCALL SDL_strcpy(char *dst, const char *src);
#endif
#ifdef HAVE_STRNCPY
#define SDL_strncpy strncpy
#else
#define strncpy SDL_strncpy
extern DECLSPEC char * SDLCALL SDL_strncpy(char *dst, const char *src, size_t maxlen);
#endif
#ifdef HAVE__STRREV
#define SDL_strrev _strrev
#else
#define _strrev SDL_strrev
extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
#endif
#ifdef HAVE__STRUPR
#define SDL_strupr _strupr
#else
#define _strupr SDL_strupr
extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
#endif
#ifdef HAVE__STRLWR
#define SDL_strlwr _strlwr
#else
#define _strlwr SDL_strlwr
extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
#endif
#ifdef HAVE_STRCHR
#define SDL_strchr strchr
#else
#define strchr SDL_strchr
extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
#endif
#ifdef HAVE_STRRCHR
#define SDL_strrchr strrchr
#else
#define strrchr SDL_strrchr
extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
#endif
#ifdef HAVE_STRSTR
#define SDL_strstr strstr
#else
#define strstr SDL_strstr
extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
#endif
#ifdef HAVE_ITOA
#define SDL_itoa itoa
#else
#define itoa SDL_itoa
#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix)
#endif
#ifdef HAVE__LTOA
#define SDL_ltoa _ltoa
#else
#define _ltoa SDL_ltoa
extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
#endif
#ifdef HAVE__UITOA
#define SDL_uitoa _uitoa
#else
#define _uitoa SDL_uitoa
#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
#endif
#ifdef HAVE__ULTOA
#define SDL_ultoa _ultoa
#else
#define _ultoa SDL_ultoa
extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
#endif
#ifdef HAVE_STRTOL
#define SDL_strtol strtol
#else
#define strtol SDL_strtol
extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
#endif
#ifdef SDL_HAS_64BIT_TYPE
#ifdef HAVE__I64TOA
#define SDL_lltoa _i64toa
#else
#define _i64toa SDL_lltoa
extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
#endif
#ifdef HAVE__UI64TOA
#define SDL_ulltoa _ui64toa
#else
#define _ui64toa SDL_ulltoa
extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
#endif
#ifdef HAVE_STRTOLL
#define SDL_strtoll strtoll
#else
#define strtoll SDL_strtoll
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
#endif
#endif /* SDL_HAS_64BIT_TYPE */
#ifdef HAVE_STRCMP
#define SDL_strcmp strcmp
#else
#define strcmp SDL_strcmp
extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
#endif
#ifdef HAVE_STRNCMP
#define SDL_strncmp strncmp
#else
#define strncmp SDL_strncmp
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
#endif
#if defined(HAVE_STRICMP) && !defined(HAVE_STRCASECMP)
#define strcasecmp stricmp
#define HAVE_STRCASECMP
#endif
#ifdef HAVE_STRCASECMP
#define SDL_strcasecmp strcasecmp
#else
#define strcasecmp SDL_strcasecmp
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
#endif
#ifdef HAVE_SSCANF
#define SDL_sscanf sscanf
#else
#define sscanf SDL_sscanf
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
#endif
#ifdef HAVE_SNPRINTF
#define SDL_snprintf snprintf
#else
#define snprintf SDL_snprintf
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
#endif
#ifdef HAVE_VSNPRINTF
#define SDL_vsnprintf vsnprintf
#else
#define vsnprintf SDL_vsnprintf
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_string_h */

View File

@ -119,8 +119,7 @@ typedef struct SDL_SysWMinfo {
} SDL_SysWMinfo;
#elif defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "SDL_windows.h"
/* The windows custom event structure */
struct SDL_SysWMmsg {

View File

@ -45,7 +45,7 @@ struct SDL_Thread;
typedef struct SDL_Thread SDL_Thread;
/* Create a thread */
#ifdef __OS2__
#if defined(_WIN32) || 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()
@ -53,39 +53,39 @@ typedef struct SDL_Thread SDL_Thread;
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, it it's the SDL.DLL which uses this API,
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!
*/
#ifdef __WATCOMC__
#include <process.h> // This has _beginthread() and _endthread() defined!
#endif
#ifdef __EMX__
#include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used!
#endif
typedef Uint32 SDLCALL (*pfnSDL_CurrentBeginThread)(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam);
typedef void SDLCALL (*pfnSDL_CurrentEndThread)(void);
#ifdef __OS2__
typedef int (__cdecl *pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg);
typedef void (__cdecl *pfnSDL_CurrentEndThread)(void);
#else
#ifdef __GNUC__
#include <stdint.h>
#endif
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_Core(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
// Disable warnings about unreferenced symbol!
#pragma disable_message (202)
static Uint32 SDLCALL SDL_CurrentBeginThread(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam)
{
return _beginthread(pfnThreadFn, NULL, uiStackSize, pParam);
}
static void SDLCALL SDL_CurrentEndThread(void)
{
_endthread();
}
#define SDL_CreateThread(fn, data) SDL_CreateThread_Core(fn, data, SDL_CurrentBeginThread, SDL_CurrentEndThread)
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(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

View File

@ -25,11 +25,17 @@
#ifndef _SDL_types_h
#define _SDL_types_h
/* The number of elements in a table */
#define SDL_TABLESIZE(table) (sizeof(table)/sizeof(table[0]))
#include <sys/types.h>
#ifdef _MSC_VER
#include <crtdefs.h> /* For size_t */
#endif
/* The number of elements in an array */
#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
#define SDL_TABLESIZE(table) SDL_arraysize(table)
/* Basic data types */
typedef enum {
typedef enum SDL_bool {
SDL_FALSE = 0,
SDL_TRUE = 1
} SDL_bool;
@ -107,9 +113,4 @@ typedef enum {
SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#undef SDL_COMPILE_TIME_ASSERT
/* General keyboard/mouse state definitions */
enum { SDL_PRESSED = 0x01, SDL_RELEASED = 0x00 };
#endif

View File

@ -25,8 +25,6 @@
#ifndef _SDL_video_h
#define _SDL_video_h
#include <stdio.h>
#include "SDL_types.h"
#include "SDL_mutex.h"
#include "SDL_rwops.h"

46
include/SDL_windows.h Normal file
View File

@ -0,0 +1,46 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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_windows_h
#define _SDL_windows_h
#include "SDL_config.h"
/* This includes only the windows headers needed by SDL, with no C runtime */
#define WIN32_LEAN_AND_MEAN
#ifndef HAVE_LIBC
#ifdef _MSC_VER
#ifndef __FLTUSED__
#define __FLTUSED__
#ifdef __cplusplus
extern "C"
#endif
__declspec(selectany) int _fltused=1;
#endif
#endif /* _MSC_VER */
#define _INC_STDLIB
#define _INC_STRING
#define __STRALIGN_H_
#endif/* !HAVE_LIBC */
#include <windows.h>
#endif /* _SDL_windows_h */

View File

@ -3,7 +3,7 @@
# These are the subdirectories that are always built
CORE_SUBDIRS = \
main
main stdlib
# These are the subdirectories which may be built
EXTRA_SUBDIRS = \
@ -25,10 +25,12 @@ libSDL_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
libSDL_la_LIBADD = \
main/libarch.la \
stdlib/libstdlib.la \
@SDL_EXTRALIBS@ \
@SYSTEM_LIBS@
libSDL_la_DEPENDENCIES = \
main/libarch.la \
stdlib/libstdlib.la \
@SDL_EXTRALIBS@
# The SDL library sources
@ -38,6 +40,5 @@ GENERAL_SRCS = \
SDL_error_c.h \
SDL_fatal.c \
SDL_fatal.h \
SDL_getenv.c \
SDL_loadso.c

View File

@ -22,7 +22,6 @@
/* Initialization code for SDL */
#include <stdlib.h> /* For getenv() */
#ifdef ENABLE_PTH
#include <pth.h>
#endif
@ -30,6 +29,7 @@
#include "SDL.h"
#include "SDL_endian.h"
#include "SDL_fatal.h"
#include "SDL_stdlib.h"
#ifndef DISABLE_VIDEO
#include "SDL_leaks.h"
#endif
@ -253,26 +253,7 @@ const SDL_version * SDL_Linked_Version(void)
return(&version);
}
#ifndef __OS2__
#if defined(_WIN32_WCE) || (defined(__WATCOMC__) && defined(BUILD_DLL))
/* Need to include DllMain() on Windows CE and Watcom C for some reason.. */
#include <windows.h>
BOOL APIENTRY DllMain( 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 /* _WIN32_WCE and building DLL with Watcom C */
#else
#if defined(__OS2__)
// Building for OS/2
#ifdef __WATCOMC__
@ -341,6 +322,27 @@ unsigned _System LibMain(unsigned hmod, unsigned termination)
return 1;
}
}
#endif /* __WATCOMC__ */
#endif
#endif
#elif defined(_WIN32)
#if !defined(HAVE_LIBC) || defined(_WIN32_WCE) || (defined(__WATCOMC__) && defined(BUILD_DLL))
/* Need to include DllMain() on Windows CE and Watcom C for some reason.. */
#include "SDL_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 /* _WIN32_WCE and building DLL with Watcom C */
#endif /* OS/2 elif _WIN32 */

View File

@ -22,13 +22,9 @@
/* Simple error handling in SDL */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "SDL_types.h"
#include "SDL_getenv.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_error.h"
#include "SDL_error_c.h"
#ifndef DISABLE_THREADS
@ -42,10 +38,6 @@ static SDL_error SDL_global_error;
#define SDL_GetErrBuf() (&SDL_global_error)
#endif /* DISABLE_THREADS */
#ifdef __CYGWIN__
#define DISABLE_STDIO
#endif
#define SDL_ERRBUFIZE 1024
/* Private functions */
@ -121,16 +113,10 @@ void SDL_SetError (const char *fmt, ...)
}
va_end(ap);
#ifndef DISABLE_STDIO
/* If we are in debug mode, print out an error message */
#ifdef DEBUG_ERROR
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
#else
if ( getenv("SDL_DEBUG") ) {
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
}
#endif
#endif /* !DISABLE_STDIO */
}
/* Print out an integer value to a UNICODE buffer */
@ -139,7 +125,7 @@ static int PrintInt(Uint16 *str, unsigned int maxlen, int value)
char tmp[128];
int len, i;
sprintf(tmp, "%d", value);
snprintf(tmp, SDL_arraysize(tmp), "%d", value);
len = 0;
if ( strlen(tmp) < maxlen ) {
for ( i=0; tmp[i]; ++i ) {
@ -155,7 +141,7 @@ static int PrintDouble(Uint16 *str, unsigned int maxlen, double value)
char tmp[128];
int len, i;
sprintf(tmp, "%f", value);
snprintf(tmp, SDL_arraysize(tmp), "%f", value);
len = 0;
if ( strlen(tmp) < maxlen ) {
for ( i=0; tmp[i]; ++i ) {
@ -171,7 +157,7 @@ static int PrintPointer(Uint16 *str, unsigned int maxlen, void *value)
char tmp[128];
int len, i;
sprintf(tmp, "%p", value);
snprintf(tmp, SDL_arraysize(tmp), "%p", value);
len = 0;
if ( strlen(tmp) < maxlen ) {
for ( i=0; tmp[i]; ++i ) {

View File

@ -20,91 +20,27 @@
slouken@libsdl.org
*/
#ifdef _WIN32_WCE
#define NO_SIGNAL_H
#endif
/* General fatal signal handling code for SDL */
#ifdef NO_SIGNAL_H
#include "SDL_config.h"
/* No signals on this platform, nothing to do.. */
#ifdef HAVE_SIGNAL_H
void SDL_InstallParachute(void)
{
return;
}
void SDL_UninstallParachute(void)
{
return;
}
#else
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include "SDL.h"
#include "SDL_fatal.h"
#ifdef __CYGWIN__
#define DISABLE_STDIO
#endif
/* 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 print_msg(const char *text)
{
#ifndef DISABLE_STDIO
fprintf(stderr, "%s", text);
#endif
}
static void SDL_Parachute(int sig)
{
signal(sig, SIG_DFL);
print_msg("Fatal signal: ");
switch (sig) {
case SIGSEGV:
print_msg("Segmentation Fault");
break;
#ifdef SIGBUS
#if SIGBUS != SIGSEGV
case SIGBUS:
print_msg("Bus Error");
break;
#endif
#endif /* SIGBUS */
#ifdef SIGFPE
case SIGFPE:
print_msg("Floating Point Exception");
break;
#endif /* SIGFPE */
#ifdef SIGQUIT
case SIGQUIT:
print_msg("Keyboard Quit");
break;
#endif /* SIGQUIT */
#ifdef SIGPIPE
case SIGPIPE:
print_msg("Broken Pipe");
break;
#endif /* SIGPIPE */
default:
#ifndef DISABLE_STDIO
fprintf(stderr, "# %d", sig);
#endif
break;
}
print_msg(" (SDL Parachute Deployed)\n");
SDL_Quit();
exit(-sig);
raise(sig);
}
static int SDL_fatal_signals[] = {
@ -182,4 +118,18 @@ void SDL_UninstallParachute(void)
#endif /* HAVE_SIGACTION */
}
#endif /* NO_SIGNAL_H */
#else
/* No signals on this platform, nothing to do.. */
void SDL_InstallParachute(void)
{
return;
}
void SDL_UninstallParachute(void)
{
return;
}
#endif /* HAVE_SIGNAL_H */

View File

@ -21,14 +21,12 @@
*/
/* Allow access to a raw mixing buffer */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_audio.h"
#include "SDL_timer.h"
#include "SDL_error.h"
#include "SDL_string.h"
#include "SDL_audio_c.h"
#include "SDL_audiomem.h"
#include "SDL_sysaudio.h"
@ -456,7 +454,12 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
D(bug("Locking semaphore..."));
SDL_mutexP(audio->mixer_lock);
#if (defined(_WIN32) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL);
#else
audio->thread = SDL_CreateThread(SDL_RunAudio, audio);
#endif
D(bug("Created thread...\n"));
if ( audio->thread == NULL ) {
@ -516,7 +519,12 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
switch (audio->opened) {
case 1:
/* Start the audio thread */
#if (defined(_WIN32) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL);
#else
audio->thread = SDL_CreateThread(SDL_RunAudio, audio);
#endif
if ( audio->thread == NULL ) {
SDL_CloseAudio();
SDL_SetError("Couldn't create audio thread");

View File

@ -22,8 +22,6 @@
/* Functions for audio drivers to perform runtime conversion of audio format */
#include <stdio.h>
#include "SDL_error.h"
#include "SDL_audio.h"

View File

@ -24,7 +24,6 @@
(necessary because SDL audio emulates threads with fork()
*/
#include <stdlib.h>
#ifdef FORK_HACK
#include <sys/types.h>
#include <sys/ipc.h>
@ -33,6 +32,7 @@
#endif
#include "SDL_audiomem.h"
#include "SDL_stdlib.h"
/* Allocate memory that will be shared between threads (freed on exit) */
void *SDL_AllocAudioMem(int size)

View File

@ -22,10 +22,6 @@
/* This provides the default mixing callback for the SDL audio routines */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_audio.h"
#include "SDL_mutex.h"
#include "SDL_timer.h"

View File

@ -1,3 +1,6 @@
#include "SDL_mixer_MMX_VC.h"
#if defined(USE_ASM_MIXER_VC)
// 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)
@ -12,11 +15,6 @@
// Mixing for 16 bit signed buffers
////////////////////////////////////////////////
#ifndef __WATCOMC__
#include <windows.h>
#include <stdio.h>
#endif
void SDL_MixAudio_MMX_S16_VC(char* dst,char* src,unsigned int nSize,int volume)
{
__asm

View File

@ -1,3 +1,6 @@
#ifdef _MSC_VER
#define USE_ASM_MIXER_VC
#endif
#if defined(USE_ASM_MIXER_VC)
// headers for MMX assembler version of SDL_MixAudio
// Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)

View File

@ -24,17 +24,13 @@
/* Microsoft WAVE file loading routines */
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_audio.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_wave.h"
#include "SDL_endian.h"
#ifndef NELEMS
#define NELEMS(array) ((sizeof array)/(sizeof array[0]))
#endif
static int ReadChunk(SDL_RWops *src, Chunk *chunk);
@ -342,9 +338,9 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
/* Check to make sure we have enough variables in the state array */
channels = IMA_ADPCM_state.wavefmt.channels;
if ( channels > NELEMS(IMA_ADPCM_state.state) ) {
if ( channels > SDL_arraysize(IMA_ADPCM_state.state) ) {
SDL_SetError("IMA ADPCM decoder can only handle %d channels",
NELEMS(IMA_ADPCM_state.state));
SDL_arraysize(IMA_ADPCM_state.state));
return(-1);
}
state = IMA_ADPCM_state.state;
@ -564,7 +560,7 @@ done:
}
else {
// seek to the end of the file (given by the RIFF chunk)
SDL_RWseek(src, wavelen - chunk.length - headerDiff, SEEK_CUR);
SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
}
if ( was_error ) {
spec = NULL;

View File

@ -22,14 +22,14 @@
/* Allow access to a raw mixing buffer */
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "SDL_windows.h"
#include <mmsystem.h>
#include "SDL_audio.h"
#include "SDL_mutex.h"
#include "SDL_timer.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_audio_c.h"
#include "SDL_dibaudio.h"
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
@ -125,7 +125,7 @@ static void SetMMerror(char *function, MMRESULT code)
wchar_t werrbuf[MAXERRORLENGTH];
#endif
sprintf(errbuf, "%s: ", function);
snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
len = strlen(errbuf);
#ifdef _WIN32_WCE

View File

@ -22,12 +22,12 @@
/* Allow access to a raw mixing buffer */
#include <stdio.h>
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_audio.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_audio_c.h"
#include "SDL_dx5audio.h"
@ -223,12 +223,13 @@ static void SetDSerror(const char *function, int code)
error = "Function not supported";
break;
default:
sprintf(errbuf, "%s: Unknown DirectSound error: 0x%x",
snprintf(errbuf, SDL_arraysize(errbuf),
"%s: Unknown DirectSound error: 0x%x",
function, code);
break;
}
if ( ! errbuf[0] ) {
sprintf(errbuf, "%s: %s", function, error);
snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
}
SDL_SetError("%s", errbuf);
return;

View File

@ -4,7 +4,7 @@
/* Include all of the DirectX 5.0 headers and adds any necessary tweaks */
#include <windows.h>
#include "SDL_windows.h"
#include <mmsystem.h>
#ifndef WIN32
#define WIN32

View File

@ -22,12 +22,10 @@
/* This is the CD-audio control API for Simple DirectMedia Layer */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_cdrom.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_syscdrom.h"
#if !defined(macintosh)

View File

@ -22,13 +22,13 @@
/* Functions for system-level CD-ROM audio control */
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "SDL_windows.h"
#include <mmsystem.h>
#include "SDL_error.h"
#include "SDL_cdrom.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_syscdrom.h"
/* This really broken?? */
@ -99,7 +99,7 @@ int SDL_SYS_CDInit(void)
/* Scan the system for CD-ROM drives */
for ( i='A'; i<='Z'; ++i ) {
sprintf(drive, "%c:\\", i);
snprintf(drive, SDL_arraysize(drive), "%c:\\", i);
if ( GetDriveType(drive) == DRIVE_CDROM ) {
AddDrive(drive);
}

View File

@ -22,10 +22,8 @@
/* Application focus/iconification handling code for SDL */
#include <stdio.h>
#include <string.h>
#include "SDL_events.h"
#include "SDL_string.h"
#include "SDL_events_c.h"

View File

@ -22,13 +22,11 @@
/* General event handling code for SDL */
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_thread.h"
#include "SDL_mutex.h"
#include "SDL_events.h"
#include "SDL_string.h"
#include "SDL_events_c.h"
#include "SDL_timer_c.h"
#ifndef DISABLE_JOYSTICK
@ -177,7 +175,12 @@ static int SDL_StartEventThread(Uint32 flags)
/* The event thread will handle timers too */
SDL_SetTimerThreaded(2);
#if (defined(_WIN32) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
#else
SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
#endif
if ( SDL_EventThread == NULL ) {
return(-1);
}

View File

@ -22,14 +22,10 @@
/* General keyboard handling code for SDL */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_timer.h"
#include "SDL_string.h"
#include "SDL_events_c.h"
#include "SDL_sysevents.h"
@ -58,17 +54,14 @@ int SDL_KeyboardInit(void)
{
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
Uint16 i;
/* Set default mode of UNICODE translation */
SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
/* Initialize the tables */
SDL_ModState = KMOD_NONE;
for ( i=0; i<SDL_TABLESIZE(keynames); ++i )
keynames[i] = NULL;
for ( i=0; i<SDL_TABLESIZE(SDL_KeyState); ++i )
SDL_KeyState[i] = SDL_RELEASED;
memset(keynames, 0, sizeof(keynames));
memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
video->InitOSKeymap(this);
SDL_EnableKeyRepeat(0, 0);

View File

@ -22,11 +22,8 @@
/* General mouse handling code for SDL */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_events.h"
#include "SDL_string.h"
#include "SDL_events_c.h"
#include "SDL_cursor_c.h"
#include "SDL_sysvideo.h"

View File

@ -22,12 +22,9 @@
/* General quit handling code for SDL */
#if defined (_WIN32_WCE)
#define NO_SIGNAL_H
#endif
#include "SDL_config.h"
#include <stdio.h>
#ifndef NO_SIGNAL_H
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
@ -35,7 +32,7 @@
#include "SDL_events_c.h"
#ifndef NO_SIGNAL_H
#ifdef HAVE_SIGNAL_H
static void SDL_HandleSIG(int sig)
{
/* Reset the signal handler */
@ -44,12 +41,12 @@ static void SDL_HandleSIG(int sig)
/* Signal a quit interrupt */
SDL_PrivateQuit();
}
#endif /* NO_SIGNAL_H */
#endif /* HAVE_SIGNAL_H */
/* Public functions */
int SDL_QuitInit(void)
{
#ifndef NO_SIGNAL_H
#ifdef HAVE_SIGNAL_H
void (*ohandler)(int);
/* Both SIGINT and SIGTERM are translated into quit interrupts */
@ -59,14 +56,14 @@ int SDL_QuitInit(void)
ohandler = signal(SIGTERM, SDL_HandleSIG);
if ( ohandler != SIG_DFL )
signal(SIGTERM, ohandler);
#endif /* NO_SIGNAL_H */
#endif /* HAVE_SIGNAL_H */
/* That's it! */
return(0);
}
void SDL_QuitQuit(void)
{
#ifndef NO_SIGNAL_H
#ifdef HAVE_SIGNAL_H
void (*ohandler)(int);
ohandler = signal(SIGINT, SIG_DFL);
@ -75,7 +72,7 @@ void SDL_QuitQuit(void)
ohandler = signal(SIGTERM, SIG_DFL);
if ( ohandler != SDL_HandleSIG )
signal(SIGTERM, ohandler);
#endif /* NO_SIGNAL_H */
#endif /* HAVE_SIGNAL_H */
}
/* This function returns 1 if it's okay to close the application window */

View File

@ -24,12 +24,12 @@
data sources. It can easily be extended to files, memory, etc.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_rwops.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#ifdef HAVE_STDIO_H
/* Functions to read/write stdio file pointers */
@ -74,6 +74,8 @@ static int stdio_close(SDL_RWops *context)
return(0);
}
#endif /* HAVE_STDIO_H */
/* Functions to read/write memory pointers */
static int mem_seek(SDL_RWops *context, int offset, int whence)
@ -81,13 +83,13 @@ static int mem_seek(SDL_RWops *context, int offset, int whence)
Uint8 *newpos;
switch (whence) {
case SEEK_SET:
case RW_SEEK_SET:
newpos = context->hidden.mem.base+offset;
break;
case SEEK_CUR:
case RW_SEEK_CUR:
newpos = context->hidden.mem.here+offset;
break;
case SEEK_END:
case RW_SEEK_END:
newpos = context->hidden.mem.stop+offset;
break;
default:
@ -199,10 +201,9 @@ static char *unix_to_mac(const char *file)
SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
{
SDL_RWops *rwops = NULL;
#ifdef HAVE_STDIO_H
FILE *fp;
SDL_RWops *rwops;
rwops = NULL;
#ifdef macintosh
{
@ -224,12 +225,14 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
rwops = SDL_RWFromFP(fp, 1);
#endif
}
#endif /* HAVE_STDIO_H */
return(rwops);
}
#ifdef HAVE_STDIO_H
SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
{
SDL_RWops *rwops;
SDL_RWops *rwops = NULL;
#ifdef WIN32
if ( ! in_sdl ) {
@ -249,6 +252,7 @@ SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
}
return(rwops);
}
#endif /* HAVE_STDIO_H */
SDL_RWops *SDL_RWFromMem(void *mem, int size)
{

View File

@ -22,12 +22,10 @@
/* This is the joystick API for Simple DirectMedia Layer */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#ifndef DISABLE_EVENTS
#include "SDL_events_c.h"
#endif

View File

@ -22,15 +22,15 @@
/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
#include <stdlib.h>
#include <stdio.h> /* For the definition of NULL */
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_joystick.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysjoystick.h"
#include "SDL_joystick_c.h"
#include <windows.h>
#include "SDL_windows.h"
#include <mmsystem.h>
#include <regstr.h>
@ -82,7 +82,7 @@ static char *GetJoystickName(int index, const char *szRegKey)
unsigned char regvalue[256];
unsigned char regname[256];
sprintf((char *) regkey, "%s\\%s\\%s",
snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s",
REGSTR_PATH_JOYCONFIG,
szRegKey,
REGSTR_KEY_JOYCURR);
@ -95,7 +95,7 @@ static char *GetJoystickName(int index, const char *szRegKey)
joystick's properties
*/
regsize = sizeof(regname);
sprintf((char *) regvalue,
snprintf((char *) regvalue, SDL_arraysize(regvalue),
"Joystick%d%s", index+1,
REGSTR_VAL_JOYOEMNAME);
regresult = RegQueryValueExA(hKey,
@ -105,7 +105,7 @@ static char *GetJoystickName(int index, const char *szRegKey)
if (regresult == ERROR_SUCCESS)
{
/* open that registry key */
sprintf((char *) regkey, "%s\\%s",
snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s",
REGSTR_PATH_JOYOEM, regname);
regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
(char *) regkey, 0, KEY_READ, &hKey);
@ -379,7 +379,7 @@ void SDL_SYS_JoystickQuit(void)
void SetMMerror(char *function, int code)
{
static char *error;
static char errbuf[BUFSIZ];
static char errbuf[1024];
errbuf[0] = 0;
switch (code)
@ -406,13 +406,14 @@ void SetMMerror(char *function, int code)
break;
default:
sprintf(errbuf, "%s: Unknown Multimedia system error: 0x%x",
snprintf(errbuf, SDL_arraysize(errbuf),
"%s: Unknown Multimedia system error: 0x%x",
function, code);
break;
}
if ( ! errbuf[0] ) {
sprintf(errbuf, "%s: %s", function, error);
snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
}
SDL_SetError("%s", errbuf);
}

View File

@ -31,8 +31,7 @@
#error Compiling for the wrong platform?
#endif
#include <stdio.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_types.h"
#include "SDL_error.h"

6
src/stdlib/.cvsignore Normal file
View File

@ -0,0 +1,6 @@
Makefile.in
Makefile
.libs
*.o
*.lo
*.la

15
src/stdlib/Makefile.am Normal file
View File

@ -0,0 +1,15 @@
## Makefile.am for the SDL file library
noinst_LTLIBRARIES = libstdlib.la
# Include the architecture-independent sources
COMMON_SRCS = \
SDL_getenv.c \
SDL_malloc.c \
SDL_qsort.c \
SDL_stdlib.c \
SDL_string.c
libstdlib_la_SOURCES = $(COMMON_SRCS)

View File

@ -20,22 +20,14 @@
slouken@libsdl.org
*/
/* Not all environments have a working getenv()/putenv() */
#include "SDL_stdlib.h"
#include "SDL_string.h"
#ifdef TEST_MAIN
#define NEED_SDL_GETENV
#endif
#include "SDL_getenv.h"
#ifdef NEED_SDL_GETENV
#if defined(WIN32) && !defined(_WIN32_WCE)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <malloc.h>
#include <string.h>
#include "SDL_windows.h"
#include "SDL_string.h"
/* Note this isn't thread-safe! */
@ -94,9 +86,6 @@ char *SDL_getenv(const char *name)
#else /* roll our own */
#include <stdlib.h>
#include <string.h>
static char **SDL_env = (char **)0;
/* Put a variable of the form "name=value" into the environment */
@ -184,8 +173,6 @@ char *SDL_getenv(const char *name)
#endif /* WIN32 */
#endif /* NEED_GETENV */
#ifdef TEST_MAIN
#include <stdio.h>

5108
src/stdlib/SDL_malloc.c Normal file

File diff suppressed because it is too large Load Diff

418
src/stdlib/SDL_qsort.c Normal file
View File

@ -0,0 +1,418 @@
/* qsort.c
* (c) 1998 Gareth McCaughan
*
* This is a drop-in replacement for the C library's |qsort()| routine.
*
* Features:
* - Median-of-three pivoting (and more)
* - Truncation and final polishing by a single insertion sort
* - Early truncation when no swaps needed in pivoting step
* - Explicit recursion, guaranteed not to overflow
* - A few little wrinkles stolen from the GNU |qsort()|.
* - separate code for non-aligned / aligned / word-size objects
*
* This code may be reproduced freely provided
* - this file is retained unaltered apart from minor
* changes for portability and efficiency
* - no changes are made to this comment
* - any changes that *are* made are clearly flagged
* - the _ID string below is altered by inserting, after
* the date, the string " altered" followed at your option
* by other material. (Exceptions: you may change the name
* of the exported routine without changing the ID string.
* You may change the values of the macros TRUNC_* and
* PIVOT_THRESHOLD without changing the ID string, provided
* they remain constants with TRUNC_nonaligned, TRUNC_aligned
* and TRUNC_words/WORD_BYTES between 8 and 24, and
* PIVOT_THRESHOLD between 32 and 200.)
*
* You may use it in anything you like; you may make money
* out of it; you may distribute it in object form or as
* part of an executable without including source code;
* you don't have to credit me. (But it would be nice if
* you did.)
*
* If you find problems with this code, or find ways of
* making it significantly faster, please let me know!
* My e-mail address, valid as of early 1998 and certainly
* OK for at least the next 18 months, is
* gjm11@dpmms.cam.ac.uk
* Thanks!
*
* Gareth McCaughan Peterhouse Cambridge 1998
*/
/*
#include <assert.h>
#include <stdlib.h>
#include <string.h>
*/
#define assert(X)
#include "SDL_stdlib.h"
#include "SDL_string.h"
#ifndef HAVE_QSORT
static char _ID[]="<qsort.c gjm 1.12 1998-03-19>";
/* How many bytes are there per word? (Must be a power of 2,
* and must in fact equal sizeof(int).)
*/
#define WORD_BYTES sizeof(int)
/* How big does our stack need to be? Answer: one entry per
* bit in a |size_t|.
*/
#define STACK_SIZE (8*sizeof(size_t))
/* Different situations have slightly different requirements,
* and we make life epsilon easier by using different truncation
* points for the three different cases.
* So far, I have tuned TRUNC_words and guessed that the same
* value might work well for the other two cases. Of course
* what works well on my machine might work badly on yours.
*/
#define TRUNC_nonaligned 12
#define TRUNC_aligned 12
#define TRUNC_words 12*WORD_BYTES /* nb different meaning */
/* We use a simple pivoting algorithm for shortish sub-arrays
* and a more complicated one for larger ones. The threshold
* is PIVOT_THRESHOLD.
*/
#define PIVOT_THRESHOLD 40
typedef struct { char * first; char * last; } stack_entry;
#define pushLeft {stack[stacktop].first=ffirst;stack[stacktop++].last=last;}
#define pushRight {stack[stacktop].first=first;stack[stacktop++].last=llast;}
#define doLeft {first=ffirst;llast=last;continue;}
#define doRight {ffirst=first;last=llast;continue;}
#define pop {if (--stacktop<0) break;\
first=ffirst=stack[stacktop].first;\
last=llast=stack[stacktop].last;\
continue;}
/* Some comments on the implementation.
* 1. When we finish partitioning the array into "low"
* and "high", we forget entirely about short subarrays,
* because they'll be done later by insertion sort.
* Doing lots of little insertion sorts might be a win
* on large datasets for locality-of-reference reasons,
* but it makes the code much nastier and increases
* bookkeeping overhead.
* 2. We always save the shorter and get to work on the
* longer. This guarantees that every time we push
* an item onto the stack its size is <= 1/2 of that
* of its parent; so the stack can't need more than
* log_2(max-array-size) entries.
* 3. We choose a pivot by looking at the first, last
* and middle elements. We arrange them into order
* because it's easy to do that in conjunction with
* choosing the pivot, and it makes things a little
* easier in the partitioning step. Anyway, the pivot
* is the middle of these three. It's still possible
* to construct datasets where the algorithm takes
* time of order n^2, but it simply never happens in
* practice.
* 3' Newsflash: On further investigation I find that
* it's easy to construct datasets where median-of-3
* simply isn't good enough. So on large-ish subarrays
* we do a more sophisticated pivoting: we take three
* sets of 3 elements, find their medians, and then
* take the median of those.
* 4. We copy the pivot element to a separate place
* because that way we can always do our comparisons
* directly against a pointer to that separate place,
* and don't have to wonder "did we move the pivot
* element?". This makes the inner loop better.
* 5. It's possible to make the pivoting even more
* reliable by looking at more candidates when n
* is larger. (Taking this to its logical conclusion
* results in a variant of quicksort that doesn't
* have that n^2 worst case.) However, the overhead
* from the extra bookkeeping means that it's just
* not worth while.
* 6. This is pretty clean and portable code. Here are
* all the potential portability pitfalls and problems
* I know of:
* - In one place (the insertion sort) I construct
* a pointer that points just past the end of the
* supplied array, and assume that (a) it won't
* compare equal to any pointer within the array,
* and (b) it will compare equal to a pointer
* obtained by stepping off the end of the array.
* These might fail on some segmented architectures.
* - I assume that there are 8 bits in a |char| when
* computing the size of stack needed. This would
* fail on machines with 9-bit or 16-bit bytes.
* - I assume that if |((int)base&(sizeof(int)-1))==0|
* and |(size&(sizeof(int)-1))==0| then it's safe to
* get at array elements via |int*|s, and that if
* actually |size==sizeof(int)| as well then it's
* safe to treat the elements as |int|s. This might
* fail on systems that convert pointers to integers
* in non-standard ways.
* - I assume that |8*sizeof(size_t)<=INT_MAX|. This
* would be false on a machine with 8-bit |char|s,
* 16-bit |int|s and 4096-bit |size_t|s. :-)
*/
/* The recursion logic is the same in each case: */
#define Recurse(Trunc) \
{ size_t l=last-ffirst,r=llast-first; \
if (l<Trunc) { \
if (r>=Trunc) doRight \
else pop \
} \
else if (l<=r) { pushLeft; doRight } \
else if (r>=Trunc) { pushRight; doLeft }\
else doLeft \
}
/* and so is the pivoting logic: */
#define Pivot(swapper,sz) \
if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
else { \
if (compare(first,mid)<0) { \
if (compare(mid,last)>0) { \
swapper(mid,last); \
if (compare(first,mid)>0) swapper(first,mid);\
} \
} \
else { \
if (compare(mid,last)>0) swapper(first,last)\
else { \
swapper(first,mid); \
if (compare(mid,last)>0) swapper(mid,last);\
} \
} \
first+=sz; last-=sz; \
}
#ifdef DEBUG_QSORT
#include <stdio.h>
#endif
/* and so is the partitioning logic: */
#define Partition(swapper,sz) { \
int swapped=0; \
do { \
while (compare(first,pivot)<0) first+=sz; \
while (compare(pivot,last)<0) last-=sz; \
if (first<last) { \
swapper(first,last); swapped=1; \
first+=sz; last-=sz; } \
else if (first==last) { first+=sz; last-=sz; break; }\
} while (first<=last); \
if (!swapped) pop \
}
/* and so is the pre-insertion-sort operation of putting
* the smallest element into place as a sentinel.
* Doing this makes the inner loop nicer. I got this
* idea from the GNU implementation of qsort().
*/
#define PreInsertion(swapper,limit,sz) \
first=base; \
last=first + (nmemb>limit ? limit : nmemb-1)*sz;\
while (last!=base) { \
if (compare(first,last)>0) first=last; \
last-=sz; } \
if (first!=base) swapper(first,(char*)base);
/* and so is the insertion sort, in the first two cases: */
#define Insertion(swapper) \
last=((char*)base)+nmemb*size; \
for (first=((char*)base)+size;first!=last;first+=size) { \
char *test; \
/* Find the right place for |first|. \
* My apologies for var reuse. */ \
for (test=first-size;compare(test,first)>0;test-=size) ; \
test+=size; \
if (test!=first) { \
/* Shift everything in [test,first) \
* up by one, and place |first| \
* where |test| is. */ \
memcpy(pivot,first,size); \
memmove(test+size,test,first-test); \
memcpy(test,pivot,size); \
} \
}
#define SWAP_nonaligned(a,b) { \
register char *aa=(a),*bb=(b); \
register size_t sz=size; \
do { register char t=*aa; *aa++=*bb; *bb++=t; } while (--sz); }
#define SWAP_aligned(a,b) { \
register int *aa=(int*)(a),*bb=(int*)(b); \
register size_t sz=size; \
do { register int t=*aa;*aa++=*bb; *bb++=t; } while (sz-=WORD_BYTES); }
#define SWAP_words(a,b) { \
register int t=*((int*)a); *((int*)a)=*((int*)b); *((int*)b)=t; }
/* ---------------------------------------------------------------------- */
static char * pivot_big(char *first, char *mid, char *last, size_t size,
int compare(const void *, const void *)) {
int d=(((last-first)/size)>>3)*size;
char *m1,*m2,*m3;
{ char *a=first, *b=first+d, *c=first+2*d;
#ifdef DEBUG_QSORT
fprintf(stderr,"< %d %d %d\n",*(int*)a,*(int*)b,*(int*)c);
#endif
m1 = compare(a,b)<0 ?
(compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
: (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
}
{ char *a=mid-d, *b=mid, *c=mid+d;
#ifdef DEBUG_QSORT
fprintf(stderr,". %d %d %d\n",*(int*)a,*(int*)b,*(int*)c);
#endif
m2 = compare(a,b)<0 ?
(compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
: (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
}
{ char *a=last-2*d, *b=last-d, *c=last;
#ifdef DEBUG_QSORT
fprintf(stderr,"> %d %d %d\n",*(int*)a,*(int*)b,*(int*)c);
#endif
m3 = compare(a,b)<0 ?
(compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
: (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
}
#ifdef DEBUG_QSORT
fprintf(stderr,"-> %d %d %d\n",*(int*)m1,*(int*)m2,*(int*)m3);
#endif
return compare(m1,m2)<0 ?
(compare(m2,m3)<0 ? m2 : (compare(m1,m3)<0 ? m3 : m1))
: (compare(m1,m3)<0 ? m1 : (compare(m2,m3)<0 ? m3 : m2));
}
/* ---------------------------------------------------------------------- */
static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *)) {
stack_entry stack[STACK_SIZE];
int stacktop=0;
char *first,*last;
char *pivot=malloc(size);
size_t trunc=TRUNC_nonaligned*size;
assert(pivot!=0);
first=(char*)base; last=first+(nmemb-1)*size;
if ((size_t)(last-first)>trunc) {
char *ffirst=first, *llast=last;
while (1) {
/* Select pivot */
{ char * mid=first+size*((last-first)/size >> 1);
Pivot(SWAP_nonaligned,size);
memcpy(pivot,mid,size);
}
/* Partition. */
Partition(SWAP_nonaligned,size);
/* Prepare to recurse/iterate. */
Recurse(trunc)
}
}
PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size);
Insertion(SWAP_nonaligned);
free(pivot);
}
static void qsort_aligned(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *)) {
stack_entry stack[STACK_SIZE];
int stacktop=0;
char *first,*last;
char *pivot=malloc(size);
size_t trunc=TRUNC_aligned*size;
assert(pivot!=0);
first=(char*)base; last=first+(nmemb-1)*size;
if ((size_t)(last-first)>trunc) {
char *ffirst=first,*llast=last;
while (1) {
/* Select pivot */
{ char * mid=first+size*((last-first)/size >> 1);
Pivot(SWAP_aligned,size);
memcpy(pivot,mid,size);
}
/* Partition. */
Partition(SWAP_aligned,size);
/* Prepare to recurse/iterate. */
Recurse(trunc)
}
}
PreInsertion(SWAP_aligned,TRUNC_aligned,size);
Insertion(SWAP_aligned);
free(pivot);
}
static void qsort_words(void *base, size_t nmemb,
int (*compare)(const void *, const void *)) {
stack_entry stack[STACK_SIZE];
int stacktop=0;
char *first,*last;
char *pivot=malloc(WORD_BYTES);
assert(pivot!=0);
first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
if (last-first>TRUNC_words) {
char *ffirst=first, *llast=last;
while (1) {
#ifdef DEBUG_QSORT
fprintf(stderr,"Doing %d:%d: ",
(first-(char*)base)/WORD_BYTES,
(last-(char*)base)/WORD_BYTES);
#endif
/* Select pivot */
{ char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES));
Pivot(SWAP_words,WORD_BYTES);
*(int*)pivot=*(int*)mid;
}
#ifdef DEBUG_QSORT
fprintf(stderr,"pivot=%d\n",*(int*)pivot);
#endif
/* Partition. */
Partition(SWAP_words,WORD_BYTES);
/* Prepare to recurse/iterate. */
Recurse(TRUNC_words)
}
}
PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES);
/* Now do insertion sort. */
last=((char*)base)+nmemb*WORD_BYTES;
for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) {
/* Find the right place for |first|. My apologies for var reuse */
int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first;
*(int*)pivot=*(int*)first;
for (;compare(pl,pivot)>0;pr=pl,--pl) {
*pr=*pl; }
if (pr!=(int*)first) *pr=*(int*)pivot;
}
free(pivot);
}
/* ---------------------------------------------------------------------- */
void SDL_qsort(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *)) {
if (nmemb<=1) return;
if (((int)base|size)&(WORD_BYTES-1))
qsort_nonaligned(base,nmemb,size,compare);
else if (size!=WORD_BYTES)
qsort_aligned(base,nmemb,size,compare);
else
qsort_words(base,nmemb,compare);
}
#endif /* !HAVE_QSORT */

70
src/stdlib/SDL_stdlib.c Normal file
View File

@ -0,0 +1,70 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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 contains portable stdlib functions for SDL */
#include "SDL_stdlib.h"
#ifndef HAVE_LIBC
/* These are some C runtime intrinsics that need to be defined */
#if defined(_MSC_VER)
/* Float to long (FIXME!) */
long _ftol2_sse()
{
return 0;
}
/* 64-bit math operators (FIXME!) */
void _allmul()
{
}
void _alldiv()
{
}
void _aulldiv()
{
}
void _allrem()
{
}
void _aullrem()
{
}
void _alldvrm()
{
}
void _aulldvrm()
{
}
void _allshl()
{
}
void _aullshr()
{
}
#endif /* MSC_VER */
#endif /* !HAVE_LIBC */

1108
src/stdlib/SDL_string.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,7 @@
saves a system-dependent thread id in thread->id, and returns 0
on success.
*/
#ifdef __OS2__
#if defined(_WIN32) || defined(__OS2__)
extern int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
#else
extern int SDL_SYS_CreateThread(SDL_Thread *thread, void *args);

View File

@ -22,13 +22,11 @@
/* System independent thread management routines for SDL */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_thread_c.h"
#include "SDL_systhread.h"
@ -213,8 +211,9 @@ void SDL_RunThread(void *data)
*statusloc = userfunc(userdata);
}
#ifdef __OS2__
DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread_Core(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
#if defined(_WIN32) || defined(__OS2__)
#undef SDL_CreateThread
DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
#else
DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data)
#endif
@ -253,8 +252,8 @@ DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data)
SDL_AddThread(thread);
/* Create the thread and go! */
#ifdef __OS2__
ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
#if defined(_WIN32) || defined(__OS2__)
ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
#else
ret = SDL_SYS_CreateThread(thread, args);
#endif

View File

@ -26,11 +26,9 @@
implementation, written by Christopher Tate and Owen Smith. Thanks!
*/
#include <stdio.h>
#include <stdlib.h>
#include "SDL_error.h"
#include "SDL_thread.h"
#include "SDL_stdlib.h"
struct SDL_cond
{

View File

@ -22,11 +22,9 @@
/* An implementation of mutexes using semaphores */
#include <stdio.h>
#include <stdlib.h>
#include "SDL_error.h"
#include "SDL_thread.h"
#include "SDL_stdlib.h"
#include "SDL_systhread_c.h"

View File

@ -22,11 +22,10 @@
/* An implementation of semaphores using mutexes and condition variables */
#include <stdlib.h>
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_thread.h"
#include "SDL_stdlib.h"
#include "SDL_systhread_c.h"

View File

@ -72,7 +72,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThre
// Also save the real parameters we have to pass to thread function
pThreadParms->args = args;
// Start the thread using the runtime library of calling app!
thread->threadid = thread->handle = (*pfnBeginThread)(threadfunc, 512*1024, pThreadParms);
thread->threadid = thread->handle = (*pfnBeginThread)(threadfunc, NULL, 512*1024, pThreadParms);
if (thread->threadid<=0)
{
SDL_SetError("Not enough resources to create thread");

View File

@ -22,12 +22,11 @@
/* Mutex functions using the Win32 API */
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_error.h"
#include "SDL_mutex.h"
#include "SDL_stdlib.h"
struct SDL_mutex {

View File

@ -22,12 +22,11 @@
/* Semaphore functions using the Win32 API */
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_error.h"
#include "SDL_thread.h"
#include "SDL_stdlib.h"
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
#include "win_ce_semaphore.h"
#endif

View File

@ -22,43 +22,59 @@
/* Win32 thread management routines for SDL */
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#ifndef _WIN32_WCE
#include <process.h>
#endif
#include "SDL_windows.h"
#include "SDL_error.h"
#include "SDL_thread.h"
#include "SDL_stdlib.h"
#include "SDL_systhread.h"
typedef struct ThreadStartParms
{
void *args;
pfnSDL_CurrentEndThread pfnCurrentEndThread;
} tThreadStartParms, *pThreadStartParms;
static unsigned __stdcall RunThread(void *data)
{
SDL_RunThread(data);
return(0);
pThreadStartParms pThreadParms = (pThreadStartParms)data;
pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL;
// Call the thread function!
SDL_RunThread(pThreadParms->args);
// Get the current endthread we have to use!
if (pThreadParms)
{
pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread;
free(pThreadParms);
}
// Call endthread!
if (pfnCurrentEndThread)
(*pfnCurrentEndThread)(0);
return(0);
}
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
{
unsigned threadid;
pThreadStartParms pThreadParms = (pThreadStartParms)malloc(sizeof(tThreadStartParms));
if (!pThreadParms) {
SDL_OutOfMemory();
return(-1);
}
/*
* Avoid CreateThread: https://bugzilla.libsdl.org/show_bug.cgi?id=22
*
* have to use _beginthreadex if we want the returned handle
* to be accessible after the thread exits
* threads created with _beginthread auto-close the handle
* Windows CE still use CreateThread.
*/
#ifdef _WIN32_WCE
thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadid);
#else
thread->handle = (SYS_ThreadHandle) _beginthreadex(NULL, 0, RunThread,
args, 0, &threadid);
#endif
// Save the function which we will have to call to clear the RTL of calling app!
pThreadParms->pfnCurrentEndThread = pfnEndThread;
// Also save the real parameters we have to pass to thread function
pThreadParms->args = args;
if (pfnBeginThread) {
thread->handle = (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread,
pThreadParms, 0, &threadid);
} else {
thread->handle = CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid);
}
if (thread->handle == NULL) {
SDL_SetError("Not enough resources to create thread");
return(-1);

View File

@ -20,7 +20,7 @@
slouken@libsdl.org
*/
#include <windows.h>
#include "SDL_windows.h"
typedef HANDLE SYS_ThreadHandle;

View File

@ -28,7 +28,7 @@
and it is not clear how to handle a mixture of WCE semaphores and normal
events and mutexes. */
#include <windows.h>
#include "SDL_windows.h"
#include "win_ce_semaphore.h"
static SYNCHHANDLE CleanUp (SYNCHHANDLE hSynch, DWORD Flags);

View File

@ -20,11 +20,9 @@
slouken@libsdl.org
*/
#include <stdlib.h>
#include <stdio.h> /* For the definition of NULL */
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_stdlib.h"
#include "SDL_timer_c.h"
#include "SDL_mutex.h"
#include "SDL_systimer.h"

View File

@ -20,7 +20,7 @@
slouken@libsdl.org
*/
#include <windows.h>
#include "SDL_windows.h"
#include <mmsystem.h>
#include "SDL_timer.h"

View File

@ -20,7 +20,7 @@
slouken@libsdl.org
*/
#include <windows.h>
#include "SDL_windows.h"
#include <mmsystem.h>
#include "SDL_timer.h"

View File

@ -30,7 +30,6 @@ COMMON_SRCS = \
SDL_gamma.c \
SDL_glfuncs.h \
SDL_leaks.h \
SDL_memops.h \
SDL_pixels.c \
SDL_pixels_c.h \
SDL_surface.c \
@ -44,6 +43,10 @@ COMMON_SRCS = \
SDL_yuv_sw_c.h \
SDL_yuv_mmx.c \
mmx.h \
math_private.h \
e_log.h \
e_pow.h \
e_sqrt.h \
blank_cursor.h \
default_cursor.h

View File

@ -85,16 +85,13 @@
* beginning of an opaque line.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_types.h"
#include "SDL_video.h"
#include "SDL_error.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_memops.h"
#include "SDL_RLEaccel_c.h"
#if (defined(i386) || defined(__x86_64__)) && defined(__GNUC__) && defined(USE_ASMBLIT)

View File

@ -20,17 +20,13 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_RLEaccel_c.h"
#include "SDL_pixels_c.h"
#include "SDL_memops.h"
#if (defined(i386) || defined(__x86_64__)) && defined(__GNUC__) && defined(USE_ASMBLIT)
#define MMX_ASMBLIT

View File

@ -20,11 +20,9 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include <string.h>
#include "SDL_types.h"
#include "SDL_video.h"
#include "SDL_string.h"
#include "SDL_blit.h"
/* Functions to blit from bitmaps to other surfaces */

View File

@ -20,8 +20,6 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include "SDL_types.h"
#include "SDL_video.h"
#include "SDL_blit.h"

View File

@ -20,8 +20,6 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include "SDL_types.h"
#include "SDL_video.h"
#include "SDL_blit.h"

View File

@ -20,8 +20,6 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include "SDL_types.h"
#include "SDL_video.h"
#include "SDL_blit.h"

View File

@ -34,11 +34,10 @@
This code currently supports Win32 DIBs in uncompressed 8 and 24 bpp.
*/
#include <string.h>
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_endian.h"
#include "SDL_string.h"
/* Compression encodings for BMP files */
#ifndef BI_RGB
@ -238,7 +237,7 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
}
/* Read the surface pixels. Note that the bmp image is upside down */
if ( SDL_RWseek(src, fp_offset+bfOffBits, SEEK_SET) < 0 ) {
if ( SDL_RWseek(src, fp_offset+bfOffBits, RW_SEEK_SET) < 0 ) {
SDL_Error(SDL_EFSEEK);
was_error = 1;
goto done;
@ -319,7 +318,7 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
done:
if ( was_error ) {
if ( src ) {
SDL_RWseek(src, fp_offset, SEEK_SET);
SDL_RWseek(src, fp_offset, RW_SEEK_SET);
}
if ( surface ) {
SDL_FreeSurface(surface);
@ -475,11 +474,11 @@ int SDL_SaveBMP_RW (SDL_Surface *saveme, SDL_RWops *dst, int freedst)
/* Write the bitmap offset */
bfOffBits = SDL_RWtell(dst)-fp_offset;
if ( SDL_RWseek(dst, fp_offset+10, SEEK_SET) < 0 ) {
if ( SDL_RWseek(dst, fp_offset+10, RW_SEEK_SET) < 0 ) {
SDL_Error(SDL_EFSEEK);
}
SDL_WriteLE32(dst, bfOffBits);
if ( SDL_RWseek(dst, fp_offset+bfOffBits, SEEK_SET) < 0 ) {
if ( SDL_RWseek(dst, fp_offset+bfOffBits, RW_SEEK_SET) < 0 ) {
SDL_Error(SDL_EFSEEK);
}
@ -502,11 +501,11 @@ int SDL_SaveBMP_RW (SDL_Surface *saveme, SDL_RWops *dst, int freedst)
/* Write the BMP file size */
bfSize = SDL_RWtell(dst)-fp_offset;
if ( SDL_RWseek(dst, fp_offset+2, SEEK_SET) < 0 ) {
if ( SDL_RWseek(dst, fp_offset+2, RW_SEEK_SET) < 0 ) {
SDL_Error(SDL_EFSEEK);
}
SDL_WriteLE32(dst, bfSize);
if ( SDL_RWseek(dst, fp_offset+bfSize, SEEK_SET) < 0 ) {
if ( SDL_RWseek(dst, fp_offset+bfSize, RW_SEEK_SET) < 0 ) {
SDL_Error(SDL_EFSEEK);
}

View File

@ -22,14 +22,12 @@
/* General cursor handling code for SDL */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_mutex.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_blit.h"
#include "SDL_events_c.h"
#include "SDL_sysvideo.h"

View File

@ -22,18 +22,26 @@
/* Gamma correction support */
#define USE_MATH_H /* Used for calculating gamma ramps */
#include "SDL_config.h"
#ifdef USE_MATH_H
#include <math.h>
#ifdef HAVE_MATH_H
#include <math.h> /* Used for calculating gamma ramps */
#endif
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#ifdef USE_MATH_H
#ifndef HAVE_MATH_H
#include "math_private.h"
#include "e_sqrt.h"
#include "e_pow.h"
#include "e_log.h"
#define pow(x, y) __ieee754_pow(x, y)
#define log(x) __ieee754_log(x)
#endif
static void CalculateGammaRamp(float gamma, Uint16 *ramp)
{
int i;
@ -85,7 +93,6 @@ static void CalculateGammaFromRamp(float *gamma, Uint16 *ramp)
*gamma = 1.0f / (sum / count);
}
}
#endif /* USE_MATH_H */
int SDL_SetGamma(float red, float green, float blue)
{
@ -94,7 +101,6 @@ int SDL_SetGamma(float red, float green, float blue)
SDL_VideoDevice *this = current_video;
succeeded = -1;
#ifdef USE_MATH_H
/* Prefer using SetGammaRamp(), as it's more flexible */
{
Uint16 ramp[3][256];
@ -104,9 +110,6 @@ int SDL_SetGamma(float red, float green, float blue)
CalculateGammaRamp(blue, ramp[2]);
succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
}
#else
SDL_SetError("Gamma correction not supported");
#endif
if ( (succeeded < 0) && video->SetGamma ) {
SDL_ClearError();
succeeded = video->SetGamma(this, red, green, blue);
@ -124,7 +127,6 @@ int SDL_GetGamma(float *red, float *green, float *blue)
SDL_VideoDevice *this = current_video;
succeeded = -1;
#ifdef USE_MATH_H
/* Prefer using GetGammaRamp(), as it's more flexible */
{
Uint16 ramp[3][256];
@ -136,9 +138,6 @@ int SDL_GetGamma(float *red, float *green, float *blue)
CalculateGammaFromRamp(blue, ramp[2]);
}
}
#else
SDL_SetError("Gamma correction not supported");
#endif
if ( (succeeded < 0) && video->GetGamma ) {
SDL_ClearError();
succeeded = video->GetGamma(this, red, green, blue);

View File

@ -1,139 +0,0 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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_memops_h
#define _SDL_memops_h
/* System dependent optimized memory manipulation routines:
*/
#include <string.h>
#if defined(__GNUC__) && defined(i386)
/* Thanks to Brennan "Bas" Underwood, for the inspiration. :)
*/
#define SDL_memcpy(dst, src, len) \
do { \
int u0, u1, u2; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl\n\t" \
"testb $2,%b4\n\t" \
"je 1f\n\t" \
"movsw\n" \
"1:\ttestb $1,%b4\n\t" \
"je 2f\n\t" \
"movsb\n" \
"2:" \
: "=&c" (u0), "=&D" (u1), "=&S" (u2) \
: "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
: "memory" ); \
} while(0)
#define SDL_memcpy4(dst, src, len) \
do { \
int ecx, edi, esi; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl" \
: "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
: "0" ((unsigned)(len)), "1" (dst), "2" (src) \
: "memory" ); \
} while(0)
#define SDL_revcpy(dst, src, len) \
do { \
int u0, u1, u2; \
char *dstp = (char *)(dst); \
char *srcp = (char *)(src); \
int n = (len); \
if ( n >= 4 ) { \
__asm__ __volatile__ ( \
"std\n\t" \
"rep ; movsl\n\t" \
: "=&c" (u0), "=&D" (u1), "=&S" (u2) \
: "0" (n >> 2), \
"1" (dstp+(n-4)), "2" (srcp+(n-4)) \
: "memory" ); \
} \
switch (n & 3) { \
case 3: dstp[2] = srcp[2]; \
case 2: dstp[1] = srcp[1]; \
case 1: dstp[0] = srcp[0]; \
break; \
default: \
break; \
} \
} while(0)
#define SDL_memmove(dst, src, len) \
do { \
if ( (dst) < (src) ) { \
SDL_memcpy((dst), (src), (len)); \
} else { \
SDL_revcpy((dst), (src), (len)); \
} \
} while(0)
#define SDL_memset4(dst, val, len) \
do { \
int u0, u1, u2; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; stosl\n\t" \
: "=&D" (u0), "=&a" (u1), "=&c" (u2) \
: "0" (dst), "1" (val), "2" ((Uint32)(len)) \
: "memory" ); \
} while(0)
#endif /* GNU C and x86 */
/* If there are no optimized versions, define the normal versions */
#ifndef SDL_memcpy
#define SDL_memcpy(dst, src, len) memcpy(dst, src, len)
#endif
#ifndef SDL_memcpy4
#define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len) << 2)
#endif
#ifndef SDL_revcpy
#define SDL_revcpy(dst, src, len) memmove(dst, src, len)
#endif
#ifndef SDL_memset4
#define SDL_memset4(dst, val, len) \
do { \
unsigned _count = (len); \
unsigned _n = (_count + 3) / 4; \
Uint32 *_p = (Uint32 *)(dst); \
Uint32 _val = (val); \
switch (_count % 4) { \
case 0: do { *_p++ = _val; \
case 3: *_p++ = _val; \
case 2: *_p++ = _val; \
case 1: *_p++ = _val; \
} while ( --_n ); \
} \
} while(0)
#endif
#endif /* _SDL_memops_h */

View File

@ -22,13 +22,11 @@
/* General (mostly internal) pixel/color manipulation routines for SDL */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_endian.h"
#include "SDL_video.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_pixels_c.h"

View File

@ -20,18 +20,15 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_cursor_c.h"
#include "SDL_blit.h"
#include "SDL_RLEaccel_c.h"
#include "SDL_pixels_c.h"
#include "SDL_memops.h"
#include "SDL_leaks.h"

View File

@ -37,8 +37,7 @@
#ifndef _WIN32_WCE
#define HAVE_OPENGL
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "SDL_windows.h"
#endif
#ifdef HAVE_OPENGL

View File

@ -22,15 +22,13 @@
/* The high-level video driver subsystem */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_events.h"
#include "SDL_mutex.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_sysevents.h"
#include "SDL_blit.h"

View File

@ -22,12 +22,9 @@
/* This is the implementation of the YUV video surface support */
#include <stdlib.h>
#include <string.h>
#include "SDL_getenv.h"
#include "SDL_video.h"
#include "SDL_error.h"
#include "SDL_stdlib.h"
#include "SDL_sysvideo.h"
#include "SDL_yuvfuncs.h"
#include "SDL_yuv_sw_c.h"
@ -57,7 +54,7 @@ SDL_Overlay *SDL_CreateYUVOverlay(int w, int h, Uint32 format,
overlay = NULL;
yuv_hwaccel = getenv("SDL_VIDEO_YUV_HWACCEL");
if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) &&
(!yuv_hwaccel || (atoi(yuv_hwaccel) > 0)) ) {
(!yuv_hwaccel || (*yuv_hwaccel != '0')) ) {
overlay = video->CreateYUVOverlay(this, w, h, format, display);
}
/* If hardware YUV overlay failed ... */

View File

@ -82,12 +82,11 @@
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_cpuinfo.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_stretch_c.h"
#include "SDL_yuvfuncs.h"
#include "SDL_yuv_sw_c.h"

140
src/video/e_log.h Normal file
View File

@ -0,0 +1,140 @@
/* @(#)e_log.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_log.c,v 1.8 1995/05/10 20:45:49 jtc Exp $";
#endif
/* __ieee754_log(x)
* Return the logrithm of x
*
* Method :
* 1. Argument Reduction: find k and f such that
* x = 2^k * (1+f),
* where sqrt(2)/2 < 1+f < sqrt(2) .
*
* 2. Approximation of log(1+f).
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
* = 2s + s*R
* We use a special Reme algorithm on [0,0.1716] to generate
* a polynomial of degree 14 to approximate R The maximum error
* of this polynomial approximation is bounded by 2**-58.45. In
* other words,
* 2 4 6 8 10 12 14
* R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
* (the values of Lg1 to Lg7 are listed in the program)
* and
* | 2 14 | -58.45
* | Lg1*s +...+Lg7*s - R(z) | <= 2
* | |
* Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
* In order to guarantee error in log below 1ulp, we compute log
* by
* log(1+f) = f - s*(f - R) (if f is not too large)
* log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
*
* 3. Finally, log(x) = k*ln2 + log(1+f).
* = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
* Here ln2 is split into two floating point number:
* ln2_hi + ln2_lo,
* where n*ln2_hi is always exact for |n| < 2000.
*
* Special cases:
* log(x) is NaN with signal if x < 0 (including -INF) ;
* log(+INF) is +INF; log(0) is -INF with signal;
* log(NaN) is that NaN with no signal.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
/*#include "math.h"*/
#include "math_private.h"
#ifdef __STDC__
static const double
#else
static double
#endif
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
#ifdef __STDC__
double __ieee754_log(double x)
#else
double __ieee754_log(x)
double x;
#endif
{
double hfsq,f,s,z,R,w,t1,t2,dk;
int32_t k,hx,i,j;
u_int32_t lx;
EXTRACT_WORDS(hx,lx,x);
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
GET_HIGH_WORD(hx,x);
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
hx &= 0x000fffff;
i = (hx+0x95f64)&0x100000;
SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
k += (i>>20);
f = x-1.0;
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
if(f==zero) {if(k==0) return zero; else {dk=(double)k;
return dk*ln2_hi+dk*ln2_lo;}
}
R = f*f*(0.5-0.33333333333333333*f);
if(k==0) return f-R; else {dk=(double)k;
return dk*ln2_hi-((R-dk*ln2_lo)-f);}
}
s = f/(2.0+f);
dk = (double)k;
z = s*s;
i = hx-0x6147a;
w = z*z;
j = 0x6b851-hx;
t1= w*(Lg2+w*(Lg4+w*Lg6));
t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
i |= j;
R = t2+t1;
if(i>0) {
hfsq=0.5*f*f;
if(k==0) return f-(hfsq-s*(hfsq+R)); else
return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
} else {
if(k==0) return f-s*(f-R); else
return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
}
}

302
src/video/e_pow.h Normal file
View File

@ -0,0 +1,302 @@
/* @(#)e_pow.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_pow.c,v 1.9 1995/05/12 04:57:32 jtc Exp $";
#endif
/* __ieee754_pow(x,y) return x**y
*
* n
* Method: Let x = 2 * (1+f)
* 1. Compute and return log2(x) in two pieces:
* log2(x) = w1 + w2,
* where w1 has 53-24 = 29 bit trailing zeros.
* 2. Perform y*log2(x) = n+y' by simulating muti-precision
* arithmetic, where |y'|<=0.5.
* 3. Return x**y = 2**n*exp(y'*log2)
*
* Special cases:
* 1. (anything) ** 0 is 1
* 2. (anything) ** 1 is itself
* 3. (anything) ** NAN is NAN
* 4. NAN ** (anything except 0) is NAN
* 5. +-(|x| > 1) ** +INF is +INF
* 6. +-(|x| > 1) ** -INF is +0
* 7. +-(|x| < 1) ** +INF is +0
* 8. +-(|x| < 1) ** -INF is +INF
* 9. +-1 ** +-INF is NAN
* 10. +0 ** (+anything except 0, NAN) is +0
* 11. -0 ** (+anything except 0, NAN, odd integer) is +0
* 12. +0 ** (-anything except 0, NAN) is +INF
* 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
* 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
* 15. +INF ** (+anything except 0,NAN) is +INF
* 16. +INF ** (-anything except 0,NAN) is +0
* 17. -INF ** (anything) = -0 ** (-anything)
* 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
* 19. (-anything except 0 and inf) ** (non-integer) is NAN
*
* Accuracy:
* pow(x,y) returns x**y nearly rounded. In particular
* pow(integer,integer)
* always returns the correct integer provided it is
* representable.
*
* Constants :
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
/*#include "math.h"*/
#include "math_private.h"
#ifdef __STDC__
static const double
#else
static double
#endif
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
#ifdef __STDC__
double __ieee754_pow(double x, double y)
#else
double __ieee754_pow(x,y)
double x, y;
#endif
{
double z,ax,z_h,z_l,p_h,p_l;
double y1,t1,t2,r,s,t,u,v,w;
int32_t i,j,k,yisint,n;
int32_t hx,hy,ix,iy;
u_int32_t lx,ly;
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
/* y==zero: x**0 = 1 */
if((iy|ly)==0) return one;
/* +-NaN return x+y */
if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
return x+y;
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if(hx<0) {
if(iy>=0x43400000) yisint = 2; /* even integer y */
else if(iy>=0x3ff00000) {
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
if((j<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
}
}
}
/* special value of y */
if(ly==0) {
if (iy==0x7ff00000) { /* y is +-inf */
if(((ix-0x3ff00000)|lx)==0)
return y - y; /* inf**+-1 is NaN */
else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zero;
}
if(iy==0x3ff00000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3fe00000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return __ieee754_sqrt(x);
}
}
ax = x < 0 ? -x : x; /*fabs(x);*/
/* special value of x */
if(lx==0) {
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3ff00000)|yisint)==0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
} else if(yisint==1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
}
/* (x<0)**(non-int) is NaN */
if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
/* |y| is huge */
if(iy>0x41e00000) { /* if |y| > 2**31 */
if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
}
/* over/underflow if x is not close to one */
if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = x-1; /* t has 20 trailing zeros */
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
SET_LOW_WORD(t1,0);
t2 = v-(t1-u);
} else {
double s2,s_h,s_l,t_h,t_l;
n = 0;
/* take care subnormal number */
if(ix<0x00100000)
{ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
n += ((ix)>>20)-0x3ff;
j = ix&0x000fffff;
/* determine interval */
ix = j|0x3ff00000; /* normalize ix */
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00100000;}
SET_HIGH_WORD(ax,ix);
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
s = u*v;
s_h = s;
SET_LOW_WORD(s_h,0);
/* t_h=ax+bp[k] High */
t_h = zero;
SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
/* compute log(ax) */
s2 = s*s;
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
r += s_l*(s_h+s);
s2 = s_h*s_h;
t_h = 3.0+s2+r;
SET_LOW_WORD(t_h,0);
t_l = r-((t_h-3.0)-s2);
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h+t_l*s;
/* 2/(3log2)*(s+...) */
p_h = u+v;
SET_LOW_WORD(p_h,0);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = (double)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
SET_LOW_WORD(t1,0);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0)
s = -one;/* (-ve)**(odd int) */
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
y1 = y;
SET_LOW_WORD(y1,0);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
EXTRACT_WORDS(j,i,z);
if (j>=0x40900000) { /* z >= 1024 */
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
return s*huge*huge; /* overflow */
else {
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
}
} else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
return s*tiny*tiny; /* underflow */
else {
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
}
/*
* compute 2**(p_h+p_l)
*/
i = j&0x7fffffff;
k = (i>>20)-0x3ff;
n = 0;
if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00100000>>(k+1));
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
t = zero;
SET_HIGH_WORD(t,n&~(0x000fffff>>k));
n = ((n&0x000fffff)|0x00100000)>>(20-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
SET_LOW_WORD(t,0);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
GET_HIGH_WORD(j,z);
j += (n<<20);
if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
else SET_HIGH_WORD(z,j);
return s*z;
}

493
src/video/e_sqrt.h Normal file
View File

@ -0,0 +1,493 @@
/* @(#)e_sqrt.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_sqrt.c,v 1.8 1995/05/10 20:46:17 jtc Exp $";
#endif
/* __ieee754_sqrt(x)
* Return correctly rounded sqrt.
* ------------------------------------------
* | Use the hardware sqrt if you have one |
* ------------------------------------------
* Method:
* Bit by bit method using integer arithmetic. (Slow, but portable)
* 1. Normalization
* Scale x to y in [1,4) with even powers of 2:
* find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
* sqrt(x) = 2^k * sqrt(y)
* 2. Bit by bit computation
* Let q = sqrt(y) truncated to i bit after binary point (q = 1),
* i 0
* i+1 2
* s = 2*q , and y = 2 * ( y - q ). (1)
* i i i i
*
* To compute q from q , one checks whether
* i+1 i
*
* -(i+1) 2
* (q + 2 ) <= y. (2)
* i
* -(i+1)
* If (2) is false, then q = q ; otherwise q = q + 2 .
* i+1 i i+1 i
*
* With some algebric manipulation, it is not difficult to see
* that (2) is equivalent to
* -(i+1)
* s + 2 <= y (3)
* i i
*
* The advantage of (3) is that s and y can be computed by
* i i
* the following recurrence formula:
* if (3) is false
*
* s = s , y = y ; (4)
* i+1 i i+1 i
*
* otherwise,
* -i -(i+1)
* s = s + 2 , y = y - s - 2 (5)
* i+1 i i+1 i i
*
* One may easily use induction to prove (4) and (5).
* Note. Since the left hand side of (3) contain only i+2 bits,
* it does not necessary to do a full (53-bit) comparison
* in (3).
* 3. Final rounding
* After generating the 53 bits result, we compute one more bit.
* Together with the remainder, we can decide whether the
* result is exact, bigger than 1/2ulp, or less than 1/2ulp
* (it will never equal to 1/2ulp).
* The rounding mode can be detected by checking whether
* huge + tiny is equal to huge, and whether huge - tiny is
* equal to huge for some floating point number "huge" and "tiny".
*
* Special cases:
* sqrt(+-0) = +-0 ... exact
* sqrt(inf) = inf
* sqrt(-ve) = NaN ... with invalid signal
* sqrt(NaN) = NaN ... with invalid signal for signaling NaN
*
* Other methods : see the appended file at the end of the program below.
*---------------
*/
/*#include "math.h"*/
#include "math_private.h"
#ifdef __STDC__
double copysign(double x, double y)
#else
double copysign(x,y)
double x,y;
#endif
{
u_int32_t hx,hy;
GET_HIGH_WORD(hx,x);
GET_HIGH_WORD(hy,y);
SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
return x;
}
#ifdef __STDC__
double scalbn (double x, int n)
#else
double scalbn (x,n)
double x; int n;
#endif
{
int32_t k,hx,lx;
EXTRACT_WORDS(hx,lx,x);
k = (hx&0x7ff00000)>>20; /* extract exponent */
if (k==0) { /* 0 or subnormal x */
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
x *= two54;
GET_HIGH_WORD(hx,x);
k = ((hx&0x7ff00000)>>20) - 54;
if (n< -50000) return tiny*x; /*underflow*/
}
if (k==0x7ff) return x+x; /* NaN or Inf */
k = k+n;
if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */
if (k > 0) /* normal result */
{SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
if (k <= -54) {
if (n > 50000) /* in case integer overflow in n+k */
return huge*copysign(huge,x); /*overflow*/
else return tiny*copysign(tiny,x); /*underflow*/
}
k += 54; /* subnormal result */
SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
return x*twom54;
}
#ifdef __STDC__
double __ieee754_sqrt(double x)
#else
double __ieee754_sqrt(x)
double x;
#endif
{
double z;
int32_t sign = (int)0x80000000;
int32_t ix0,s0,q,m,t,i;
u_int32_t r,t1,s1,ix1,q1;
EXTRACT_WORDS(ix0,ix1,x);
/* take care of Inf and NaN */
if((ix0&0x7ff00000)==0x7ff00000) {
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
sqrt(-inf)=sNaN */
}
/* take care of zero */
if(ix0<=0) {
if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
else if(ix0<0)
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
}
/* normalize x */
m = (ix0>>20);
if(m==0) { /* subnormal x */
while(ix0==0) {
m -= 21;
ix0 |= (ix1>>11); ix1 <<= 21;
}
for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
m -= i-1;
ix0 |= (ix1>>(32-i));
ix1 <<= i;
}
m -= 1023; /* unbias exponent */
ix0 = (ix0&0x000fffff)|0x00100000;
if(m&1){ /* odd m, double x to make it even */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
}
m >>= 1; /* m = [m/2] */
/* generate sqrt(x) bit by bit */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
r = 0x00200000; /* r = moving bit from right to left */
while(r!=0) {
t = s0+r;
if(t<=ix0) {
s0 = t+r;
ix0 -= t;
q += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
r = sign;
while(r!=0) {
t1 = s1+r;
t = s0;
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
s1 = t1+r;
if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
ix0 -= t;
if (ix1 < t1) ix0 -= 1;
ix1 -= t1;
q1 += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
/* use floating add to find out rounding direction */
if((ix0|ix1)!=0) {
z = one-tiny; /* trigger inexact flag */
if (z>=one) {
z = one+tiny;
if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
else if (z>one) {
if (q1==(u_int32_t)0xfffffffe) q+=1;
q1+=2;
} else
q1 += (q1&1);
}
}
ix0 = (q>>1)+0x3fe00000;
ix1 = q1>>1;
if ((q&1)==1) ix1 |= sign;
ix0 += (m <<20);
INSERT_WORDS(z,ix0,ix1);
return z;
}
/*
Other methods (use floating-point arithmetic)
-------------
(This is a copy of a drafted paper by Prof W. Kahan
and K.C. Ng, written in May, 1986)
Two algorithms are given here to implement sqrt(x)
(IEEE double precision arithmetic) in software.
Both supply sqrt(x) correctly rounded. The first algorithm (in
Section A) uses newton iterations and involves four divisions.
The second one uses reciproot iterations to avoid division, but
requires more multiplications. Both algorithms need the ability
to chop results of arithmetic operations instead of round them,
and the INEXACT flag to indicate when an arithmetic operation
is executed exactly with no roundoff error, all part of the
standard (IEEE 754-1985). The ability to perform shift, add,
subtract and logical AND operations upon 32-bit words is needed
too, though not part of the standard.
A. sqrt(x) by Newton Iteration
(1) Initial approximation
Let x0 and x1 be the leading and the trailing 32-bit words of
a floating point number x (in IEEE double format) respectively
1 11 52 ...widths
------------------------------------------------------
x: |s| e | f |
------------------------------------------------------
msb lsb msb lsb ...order
------------------------ ------------------------
x0: |s| e | f1 | x1: | f2 |
------------------------ ------------------------
By performing shifts and subtracts on x0 and x1 (both regarded
as integers), we obtain an 8-bit approximation of sqrt(x) as
follows.
k := (x0>>1) + 0x1ff80000;
y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits
Here k is a 32-bit integer and T1[] is an integer array containing
correction terms. Now magically the floating value of y (y's
leading 32-bit word is y0, the value of its trailing word is 0)
approximates sqrt(x) to almost 8-bit.
Value of T1:
static int T1[32]= {
0, 1024, 3062, 5746, 9193, 13348, 18162, 23592,
29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215,
83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581,
16499, 12183, 8588, 5674, 3403, 1742, 661, 130,};
(2) Iterative refinement
Apply Heron's rule three times to y, we have y approximates
sqrt(x) to within 1 ulp (Unit in the Last Place):
y := (y+x/y)/2 ... almost 17 sig. bits
y := (y+x/y)/2 ... almost 35 sig. bits
y := y-(y-x/y)/2 ... within 1 ulp
Remark 1.
Another way to improve y to within 1 ulp is:
y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x)
y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)
2
(x-y )*y
y := y + 2* ---------- ...within 1 ulp
2
3y + x
This formula has one division fewer than the one above; however,
it requires more multiplications and additions. Also x must be
scaled in advance to avoid spurious overflow in evaluating the
expression 3y*y+x. Hence it is not recommended uless division
is slow. If division is very slow, then one should use the
reciproot algorithm given in section B.
(3) Final adjustment
By twiddling y's last bit it is possible to force y to be
correctly rounded according to the prevailing rounding mode
as follows. Let r and i be copies of the rounding mode and
inexact flag before entering the square root program. Also we
use the expression y+-ulp for the next representable floating
numbers (up and down) of y. Note that y+-ulp = either fixed
point y+-1, or multiply y by nextafter(1,+-inf) in chopped
mode.
I := FALSE; ... reset INEXACT flag I
R := RZ; ... set rounding mode to round-toward-zero
z := x/y; ... chopped quotient, possibly inexact
If(not I) then { ... if the quotient is exact
if(z=y) {
I := i; ... restore inexact flag
R := r; ... restore rounded mode
return sqrt(x):=y.
} else {
z := z - ulp; ... special rounding
}
}
i := TRUE; ... sqrt(x) is inexact
If (r=RN) then z=z+ulp ... rounded-to-nearest
If (r=RP) then { ... round-toward-+inf
y = y+ulp; z=z+ulp;
}
y := y+z; ... chopped sum
y0:=y0-0x00100000; ... y := y/2 is correctly rounded.
I := i; ... restore inexact flag
R := r; ... restore rounded mode
return sqrt(x):=y.
(4) Special cases
Square root of +inf, +-0, or NaN is itself;
Square root of a negative number is NaN with invalid signal.
B. sqrt(x) by Reciproot Iteration
(1) Initial approximation
Let x0 and x1 be the leading and the trailing 32-bit words of
a floating point number x (in IEEE double format) respectively
(see section A). By performing shifs and subtracts on x0 and y0,
we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
k := 0x5fe80000 - (x0>>1);
y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits
Here k is a 32-bit integer and T2[] is an integer array
containing correction terms. Now magically the floating
value of y (y's leading 32-bit word is y0, the value of
its trailing word y1 is set to zero) approximates 1/sqrt(x)
to almost 7.8-bit.
Value of T2:
static int T2[64]= {
0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,
0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,
0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,
0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,
0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,
0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,
0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,
0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};
(2) Iterative refinement
Apply Reciproot iteration three times to y and multiply the
result by x to get an approximation z that matches sqrt(x)
to about 1 ulp. To be exact, we will have
-1ulp < sqrt(x)-z<1.0625ulp.
... set rounding mode to Round-to-nearest
y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)
y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)
... special arrangement for better accuracy
z := x*y ... 29 bits to sqrt(x), with z*y<1
z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)
Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that
(a) the term z*y in the final iteration is always less than 1;
(b) the error in the final result is biased upward so that
-1 ulp < sqrt(x) - z < 1.0625 ulp
instead of |sqrt(x)-z|<1.03125ulp.
(3) Final adjustment
By twiddling y's last bit it is possible to force y to be
correctly rounded according to the prevailing rounding mode
as follows. Let r and i be copies of the rounding mode and
inexact flag before entering the square root program. Also we
use the expression y+-ulp for the next representable floating
numbers (up and down) of y. Note that y+-ulp = either fixed
point y+-1, or multiply y by nextafter(1,+-inf) in chopped
mode.
R := RZ; ... set rounding mode to round-toward-zero
switch(r) {
case RN: ... round-to-nearest
if(x<= z*(z-ulp)...chopped) z = z - ulp; else
if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;
break;
case RZ:case RM: ... round-to-zero or round-to--inf
R:=RP; ... reset rounding mod to round-to-+inf
if(x<z*z ... rounded up) z = z - ulp; else
if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;
break;
case RP: ... round-to-+inf
if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else
if(x>z*z ...chopped) z = z+ulp;
break;
}
Remark 3. The above comparisons can be done in fixed point. For
example, to compare x and w=z*z chopped, it suffices to compare
x1 and w1 (the trailing parts of x and w), regarding them as
two's complement integers.
...Is z an exact square root?
To determine whether z is an exact square root of x, let z1 be the
trailing part of z, and also let x0 and x1 be the leading and
trailing parts of x.
If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0
I := 1; ... Raise Inexact flag: z is not exact
else {
j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2
k := z1 >> 26; ... get z's 25-th and 26-th
fraction bits
I := i or (k&j) or ((k&(j+j+1))!=(x1&3));
}
R:= r ... restore rounded mode
return sqrt(x):=z.
If multiplication is cheaper then the foregoing red tape, the
Inexact flag can be evaluated by
I := i;
I := (z*z!=x) or I.
Note that z*z can overwrite I; this value must be sensed if it is
True.
Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be
zero.
--------------------
z1: | f2 |
--------------------
bit 31 bit 0
Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd
or even of logb(x) have the following relations:
-------------------------------------------------
bit 27,26 of z1 bit 1,0 of x1 logb(x)
-------------------------------------------------
00 00 odd and even
01 01 even
10 10 odd
10 00 even
11 01 even
-------------------------------------------------
(4) Special cases (see (4) of Section A).
*/

View File

@ -23,8 +23,6 @@
#ifndef SDL_fbelo_h
#define SDL_fbelo_h
#include <stdlib.h>
#include "SDL_fbvideo.h"
/* ELO */

172
src/video/math_private.h Normal file
View File

@ -0,0 +1,172 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* from: @(#)fdlibm.h 5.1 93/09/24
* $Id$
*/
#ifndef _MATH_PRIVATE_H_
#define _MATH_PRIVATE_H_
#include "SDL_endian.h"
typedef Sint32 int32_t;
typedef Uint32 u_int32_t;
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *
ix0 = *(n0+(int*)&x); * high word of x *
ix1 = *((1-n0)+(int*)&x); * low word of x *
to dig two 32 bit words out of the 64 bit IEEE floating point
value. That is non-ANSI, and, moreover, the gcc instruction
scheduler gets it wrong. We instead use the following macros.
Unlike the original code, we determine the endianness at compile
time, not at run time; I don't see much benefit to selecting
endianness at run time. */
/* A union which permits us to convert between a double and two 32 bit
ints. */
/*
* Math on arm is special:
* For FPA, float words are always big-endian.
* For VFP, floats words follow the memory system mode.
*/
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) || \
(!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
} ieee_double_shape_type;
#else
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
} ieee_double_shape_type;
#endif
/* Get two 32 bit ints from a double. */
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
/* Get the more significant 32 bit int from a double. */
#define GET_HIGH_WORD(i,d) \
do { \
ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
/* Get the less significant 32 bit int from a double. */
#define GET_LOW_WORD(i,d) \
do { \
ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)
/* Set a double from two 32 bit ints. */
#define INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
/* Set the more significant 32 bits of a double from an int. */
#define SET_HIGH_WORD(d,v) \
do { \
ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
/* Set the less significant 32 bits of a double from an int. */
#define SET_LOW_WORD(d,v) \
do { \
ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)
/* A union which permits us to convert between a float and a 32 bit
int. */
typedef union
{
float value;
u_int32_t word;
} ieee_float_shape_type;
/* Get a 32 bit int from a float. */
#define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
/* Set a float from a 32 bit int. */
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
#ifdef __STDC__
static const double
#else
static double
#endif
zero = 0.0,
one = 1.0,
two = 2.0,
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
huge = 1.0e+300,
tiny = 1.0e-300;
#endif /* _MATH_PRIVATE_H_ */

View File

@ -237,8 +237,6 @@ mmx_ok(void)
/* Include the stuff for printing a trace to stderr...
*/
#include <stdio.h>
#define mmx_i2r(op, imm, reg) \
{ \
mmx_t mmx_trace; \

View File

@ -22,6 +22,7 @@
#ifndef _SDL_QWin_h
#define _SDL_QWin_h
#include <stdio.h>
#include <qimage.h>

View File

@ -23,7 +23,7 @@
#ifndef _SDL_lowvideo_h
#define _SDL_lowvideo_h
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_sysvideo.h"

View File

@ -20,15 +20,15 @@
slouken@libsdl.org
*/
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_getenv.h"
#include "SDL_events.h"
#include "SDL_video.h"
#include "SDL_error.h"
#include "SDL_syswm.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_getenv.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h"
#include "SDL_sysvideo.h"
@ -798,7 +798,7 @@ static int GetCodePage()
int cp = GetACP();
if (GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof(buff))) {
cp = atoi(buff);
cp = strtol(buff, NULL, 0);
}
return cp;
}

View File

@ -20,11 +20,12 @@
slouken@libsdl.org
*/
#include <stdlib.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_error.h"
#include "SDL_mouse.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysmouse_c.h"
#include "SDL_events_c.h"
#include "SDL_cursor_c.h"

View File

@ -20,14 +20,14 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include <malloc.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_version.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_syswm.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_syswm_c.h"
#include "SDL_wingl_c.h"
#include "SDL_pixels_c.h"
@ -119,7 +119,7 @@ void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
icon_plen = icon->h*icon_pitch;
icon_mlen = icon->h*mask_pitch;
icon_len = sizeof(*icon_win32)+icon_plen+icon_mlen;
icon_win32 = (struct Win32Icon *)alloca(icon_len);
icon_win32 = (struct Win32Icon *)SDL_stack_alloc(Uint8, icon_len);
if ( icon_win32 == NULL ) {
return;
}
@ -137,6 +137,7 @@ void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
icon_256 = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
icon_win32->biBitCount, 0, 0, 0, 0);
if ( icon_256 == NULL ) {
SDL_stack_free(icon_win32);
return;
}
pal_256 = icon_256->format->palette;
@ -167,17 +168,19 @@ void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
be necessary, as Windows supports a variety of BMP formats, but
it greatly simplifies our code.
*/
bounds.x = 0;
bounds.y = 0;
bounds.w = icon->w;
bounds.h = icon->h;
if ( SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0 ) {
bounds.x = 0;
bounds.y = 0;
bounds.w = icon->w;
bounds.h = icon->h;
if ( SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0 ) {
SDL_stack_free(icon_win32);
SDL_FreeSurface(icon_256);
return;
return;
}
/* Copy pixels upside-down to icon BMP, masked with the icon mask */
if ( SDL_MUSTLOCK(icon_256) || (icon_256->pitch != icon_pitch) ) {
SDL_stack_free(icon_win32);
SDL_FreeSurface(icon_256);
SDL_SetError("Warning: Unexpected icon_256 characteristics");
return;
@ -223,6 +226,7 @@ void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
} else {
SetClassLong(SDL_Window, GCL_HICON, (LONG)screen_icn);
}
SDL_stack_free(icon_win32);
#endif /* DISABLE_ICON_SUPPORT */
}

View File

@ -20,15 +20,14 @@
slouken@libsdl.org
*/
#include <stdlib.h>
#include <string.h>
/* WGL implementation of SDL OpenGL support */
#ifdef HAVE_OPENGL
#include "SDL_opengl.h"
#endif
#include "SDL_error.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_lowvideo.h"
#include "SDL_wingl_c.h"

View File

@ -20,13 +20,13 @@
slouken@libsdl.org
*/
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "SDL_windows.h"
#include "SDL_events.h"
#include "SDL_error.h"
#include "SDL_syswm.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h"
#include "SDL_lowvideo.h"

View File

@ -20,11 +20,7 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <windows.h>
#include "SDL_windows.h"
#if defined(_WIN32_WCE)
@ -41,6 +37,8 @@ extern HINSTANCE aygshell;
#include "SDL.h"
#include "SDL_mutex.h"
#include "SDL_syswm.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h"
@ -539,7 +537,8 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current,
settings.dmPelsWidth = width;
settings.dmPelsHeight = height;
settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
if ( width <= SDL_desktop_mode.dmPelsWidth && height <= SDL_desktop_mode.dmPelsHeight ) {
if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&
height <= (int)SDL_desktop_mode.dmPelsHeight ) {
settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
settings.dmFields |= DM_DISPLAYFREQUENCY;
}
@ -794,7 +793,7 @@ int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
if ( screen_pal ) {
PALETTEENTRY *entries;
entries = (PALETTEENTRY *)alloca(ncolors*sizeof(PALETTEENTRY));
entries = SDL_stack_alloc(PALETTEENTRY, ncolors);
for ( i=0; i<ncolors; ++i ) {
entries[i].peRed = colors[i].r;
entries[i].peGreen = colors[i].g;
@ -804,11 +803,12 @@ int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
SetPaletteEntries(screen_pal, firstcolor, ncolors, entries);
SelectPalette(hdc, screen_pal, FALSE);
RealizePalette(hdc);
SDL_stack_free(entries);
}
#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
/* Copy palette colors into DIB palette */
pal = (RGBQUAD *)alloca(ncolors*sizeof(RGBQUAD));
pal = SDL_stack_alloc(RGBQUAD, ncolors);
for ( i=0; i<ncolors; ++i ) {
pal[i].rgbRed = colors[i].r;
pal[i].rgbGreen = colors[i].g;
@ -823,6 +823,7 @@ int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
BitBlt(hdc, 0, 0, this->screen->w, this->screen->h,
mdc, 0, 0, SRCCOPY);
DeleteDC(mdc);
SDL_stack_free(pal);
#endif
ReleaseDC(SDL_Window, hdc);
return(1);

View File

@ -23,7 +23,7 @@
#ifndef _SDL_dibvideo_h
#define _SDL_dibvideo_h
#include <windows.h>
#include "SDL_windows.h"
/* for PDA */
typedef enum

View File

@ -24,11 +24,12 @@
#include "directx.h"
#include <stdio.h>
#include "SDL_events.h"
#include "SDL_video.h"
#include "SDL_error.h"
#include "SDL_syswm.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h"
#include "SDL_lowvideo.h"
@ -111,12 +112,13 @@ static void SetDIerror(char *function, int code)
error = "Device not initialized";
break;
default:
sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x",
snprintf(errbuf, SDL_arraysize(errbuf),
"%s: Unknown DirectInput error: 0x%x",
function, code);
break;
}
if ( ! errbuf[0] ) {
sprintf(errbuf, "%s: %s", function, error);
snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
}
SDL_SetError("%s", errbuf);
return;
@ -610,7 +612,7 @@ static int DX5_CheckInput(_THIS, int timeout, BOOL processInput)
timeout, QS_ALLEVENTS);
if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) {
DWORD numevents;
DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
static DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
event -= WAIT_OBJECT_0;
numevents = INPUT_QSIZE;

View File

@ -20,10 +20,7 @@
slouken@libsdl.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <windows.h>
#include "SDL_windows.h"
#include "directx.h"
/* Not yet in the mingw32 cross-compile headers */
@ -35,6 +32,8 @@
#include "SDL_timer.h"
#include "SDL_events.h"
#include "SDL_syswm.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_pixels_c.h"
@ -810,12 +809,13 @@ void SetDDerror(const char *function, int code)
error = "Interface not present";
break;
default:
sprintf(errbuf, "%s: Unknown DirectDraw error: 0x%x",
snprintf(errbuf, SDL_arraysize(errbuf),
"%s: Unknown DirectDraw error: 0x%x",
function, code);
break;
}
if ( ! errbuf[0] ) {
sprintf(errbuf, "%s: %s", function, error);
snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
}
SDL_SetError("%s", errbuf);
return;
@ -1109,7 +1109,8 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current,
settings.dmPelsWidth = width;
settings.dmPelsHeight = height;
settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
if ( width <= SDL_desktop_mode.dmPelsWidth && height <= SDL_desktop_mode.dmPelsHeight ) {
if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&
height <= (int)SDL_desktop_mode.dmPelsHeight ) {
settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
settings.dmFields |= DM_DISPLAYFREQUENCY;
}
@ -2170,7 +2171,7 @@ static void DX5_CompressPalette(_THIS, SDL_Color *colors, int ncolors, int maxco
}
#else
/* Allocate memory for the arrays we use */
pool = (int *)alloca(2*ncolors*sizeof(int));
pool = SDL_stack_alloc(int, 2*ncolors);
if ( pool == NULL ) {
/* No worries, just return */;
return;
@ -2217,6 +2218,7 @@ static void DX5_CompressPalette(_THIS, SDL_Color *colors, int ncolors, int maxco
SDL_colors[j].peGreen = colors[order[i]].g;
SDL_colors[j].peBlue = colors[order[i]].b;
}
SDL_stack_free(pool);
#endif /* SIMPLE_COMPRESSION */
}
@ -2458,12 +2460,12 @@ void DX5_PaletteChanged(_THIS, HWND window)
if ( palette == NULL ) { /* Sometimes we don't have a palette */
return;
}
entries = (PALETTEENTRY *)alloca(palette->ncolors*sizeof(*entries));
entries = SDL_stack_alloc(PALETTEENTRY, palette->ncolors);
hdc = GetDC(window);
GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries);
ReleaseDC(window, hdc);
if ( ! colorchange_expected ) {
saved = (SDL_Color *)alloca(palette->ncolors*sizeof(SDL_Color));
saved = SDL_stack_alloc(SDL_Color, palette->ncolors);
memcpy(saved, palette->colors,
palette->ncolors*sizeof(SDL_Color));
}
@ -2472,6 +2474,7 @@ void DX5_PaletteChanged(_THIS, HWND window)
palette->colors[i].g = entries[i].peGreen;
palette->colors[i].b = entries[i].peBlue;
}
SDL_stack_free(entries);
if ( ! colorchange_expected ) {
Uint8 mapping[256];
@ -2481,6 +2484,7 @@ void DX5_PaletteChanged(_THIS, HWND window)
saved[i].r, saved[i].g, saved[i].b);
}
DX5_Recolor8Bit(this, SDL_VideoSurface, mapping);
SDL_stack_free(saved);
}
colorchange_expected = 0;

View File

@ -22,11 +22,10 @@
/* This is the DirectDraw implementation of YUV video overlays */
#include <stdlib.h>
#include <string.h>
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_stdlib.h"
#include "SDL_string.h"
#include "SDL_dx5yuv_c.h"
#include "SDL_yuvfuncs.h"

Some files were not shown because too many files have changed in this diff Show More