test/testplatform.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Sep 2009 09:18:42 +0000
branchSDL-1.2
changeset 4215 d83830711a5b
parent 4164 7a4c511c980a
child 5637 d39fe8e7d26a
permissions -rw-r--r--
Fixed bug #615

Scott McCreary 2008-08-21 10:48:14 PDT

This patch adds support for Haiku.
http://ports.haiku-files.org/browser/haikuports/trunk/media-libs/libsdl/SDL-1.2.13-haiku.diff
Haiku is an open-source recreation of BeOS. It has better POSIX compliance
than beOS did, and other improved features, which in some cases causes us to
have to "undo" previous BeOS workarounds.
Here's our port log entry for it, showing the steps to force the changes into
configure and Makefile:
http://ports.haiku-files.org/wiki/media-libs/libsdl/1.2.13/1
Note that this was only tried on 1.2.13 stable so far.
Haiku is using a newer config.guess / config.sub that doesn't yet seem to be in
the released libtool, so we are having to copy it in for now.
http://haiku-files.org/files/optional-packages/
slouken@1421
     1
slouken@1421
     2
#include <stdio.h>
slouken@1421
     3
slouken@1421
     4
#include "SDL.h"
slouken@1421
     5
#include "SDL_endian.h"
slouken@1421
     6
#include "SDL_cpuinfo.h"
slouken@1421
     7
slouken@1421
     8
/*
slouken@1421
     9
 * Watcom C flags these as Warning 201: "Unreachable code" if you just
slouken@1421
    10
 *  compare them directly, so we push it through a function to keep the
slouken@1421
    11
 *  compiler quiet.  --ryan.
slouken@1421
    12
 */
slouken@1421
    13
static int badsize(size_t sizeoftype, size_t hardcodetype)
slouken@1421
    14
{
slouken@1421
    15
    return sizeoftype != hardcodetype;
slouken@1421
    16
}
slouken@1421
    17
slouken@1421
    18
int TestTypes(SDL_bool verbose)
slouken@1421
    19
{
slouken@1421
    20
	int error = 0;
slouken@1421
    21
slouken@1421
    22
	if ( badsize(sizeof(Uint8), 1) ) {
slouken@1421
    23
		if ( verbose )
slouken@1615
    24
			printf("sizeof(Uint8) != 1, instead = %ul\n",
slouken@1421
    25
								sizeof(Uint8));
slouken@1421
    26
		++error;
slouken@1421
    27
	}
slouken@1421
    28
	if ( badsize(sizeof(Uint16), 2) ) {
slouken@1421
    29
		if ( verbose )
slouken@1615
    30
			printf("sizeof(Uint16) != 2, instead = %ul\n",
slouken@1421
    31
								sizeof(Uint16));
slouken@1421
    32
		++error;
slouken@1421
    33
	}
slouken@1421
    34
	if ( badsize(sizeof(Uint32), 4) ) {
slouken@1421
    35
		if ( verbose )
slouken@1615
    36
			printf("sizeof(Uint32) != 4, instead = %ul\n",
slouken@1421
    37
								sizeof(Uint32));
slouken@1421
    38
		++error;
slouken@1421
    39
	}
slouken@1421
    40
#ifdef SDL_HAS_64BIT_TYPE
slouken@1421
    41
	if ( badsize(sizeof(Uint64), 8) ) {
slouken@1421
    42
		if ( verbose )
slouken@1615
    43
			printf("sizeof(Uint64) != 8, instead = %ul\n",
slouken@1421
    44
								sizeof(Uint64));
slouken@1421
    45
		++error;
slouken@1421
    46
	}
slouken@1421
    47
#else
slouken@1421
    48
	if ( verbose ) {
slouken@1421
    49
		printf("WARNING: No 64-bit datatype on this platform\n");
slouken@1421
    50
	}
slouken@1421
    51
#endif
slouken@1421
    52
	if ( verbose && !error )
slouken@1421
    53
		printf("All data types are the expected size.\n");
slouken@1421
    54
slouken@1421
    55
	return( error ? 1 : 0 );
slouken@1421
    56
}
slouken@1421
    57
slouken@1421
    58
int TestEndian(SDL_bool verbose)
slouken@1421
    59
{
slouken@1421
    60
	int error = 0;
slouken@1421
    61
	Uint16 value = 0x1234;
slouken@1421
    62
	int real_byteorder;
slouken@1421
    63
	Uint16 value16 = 0xCDAB;
slouken@1421
    64
	Uint16 swapped16 = 0xABCD;
slouken@1421
    65
	Uint32 value32 = 0xEFBEADDE;
slouken@1421
    66
	Uint32 swapped32 = 0xDEADBEEF;
slouken@1421
    67
#ifdef SDL_HAS_64BIT_TYPE
slouken@1421
    68
	Uint64 value64, swapped64;
slouken@1421
    69
	value64 = 0xEFBEADDE;
slouken@1421
    70
	value64 <<= 32;
slouken@1421
    71
	value64 |= 0xCDAB3412;
slouken@1421
    72
	swapped64 = 0x1234ABCD;
slouken@1421
    73
	swapped64 <<= 32;
slouken@1421
    74
	swapped64 |= 0xDEADBEEF;
slouken@1421
    75
#endif
slouken@1421
    76
slouken@1421
    77
	if ( verbose ) {
slouken@1421
    78
		printf("Detected a %s endian machine.\n",
slouken@1421
    79
			(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1421
    80
	}
slouken@1424
    81
	if ( (*((char *)&value) >> 4) == 0x1 ) {
slouken@1421
    82
		real_byteorder = SDL_BIG_ENDIAN;
slouken@1421
    83
	} else {
slouken@1421
    84
		real_byteorder = SDL_LIL_ENDIAN;
slouken@1421
    85
	}
slouken@1421
    86
	if ( real_byteorder != SDL_BYTEORDER ) {
slouken@1421
    87
		if ( verbose ) {
slouken@1421
    88
			printf("Actually a %s endian machine!\n",
slouken@1421
    89
				(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1421
    90
		}
slouken@1421
    91
		++error;
slouken@1421
    92
	}
slouken@1421
    93
	if ( verbose ) {
slouken@1421
    94
		printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
slouken@1421
    95
	}
slouken@1421
    96
	if ( SDL_Swap16(value16) != swapped16 ) {
slouken@1421
    97
		if ( verbose ) {
slouken@1421
    98
			printf("16 bit value swapped incorrectly!\n");
slouken@1421
    99
		}
slouken@1421
   100
		++error;
slouken@1421
   101
	}
slouken@1421
   102
	if ( verbose ) {
slouken@1421
   103
		printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
slouken@1421
   104
	}
slouken@1421
   105
	if ( SDL_Swap32(value32) != swapped32 ) {
slouken@1421
   106
		if ( verbose ) {
slouken@1421
   107
			printf("32 bit value swapped incorrectly!\n");
slouken@1421
   108
		}
slouken@1421
   109
		++error;
slouken@1421
   110
	}
slouken@1421
   111
#ifdef SDL_HAS_64BIT_TYPE
slouken@1421
   112
	if ( verbose ) {
slouken@1615
   113
#ifdef _MSC_VER
slouken@1615
   114
		printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, SDL_Swap64(value64));
slouken@1615
   115
#else
slouken@1421
   116
		printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64));
slouken@1615
   117
#endif
slouken@1421
   118
	}
slouken@1421
   119
	if ( SDL_Swap64(value64) != swapped64 ) {
slouken@1421
   120
		if ( verbose ) {
slouken@1421
   121
			printf("64 bit value swapped incorrectly!\n");
slouken@1421
   122
		}
slouken@1421
   123
		++error;
slouken@1421
   124
	}
slouken@1421
   125
#endif
slouken@1421
   126
	return( error ? 1 : 0 );
slouken@1421
   127
}
slouken@1421
   128
slouken@1421
   129
slouken@1421
   130
int TestCPUInfo(SDL_bool verbose)
slouken@1421
   131
{
slouken@1421
   132
	if ( verbose ) {
slouken@1421
   133
		printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
slouken@1421
   134
		printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
slouken@1421
   135
		printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
slouken@1421
   136
		printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
slouken@1421
   137
		printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
slouken@1421
   138
		printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
slouken@1421
   139
		printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
slouken@1421
   140
		printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
slouken@1421
   141
	}
slouken@1421
   142
	return(0);
slouken@1421
   143
}
slouken@1421
   144
slouken@1421
   145
int main(int argc, char *argv[])
slouken@1421
   146
{
slouken@1421
   147
	SDL_bool verbose = SDL_TRUE;
slouken@1421
   148
	int status = 0;
slouken@1421
   149
slouken@1421
   150
	if ( argv[1] && (SDL_strcmp(argv[1], "-q") == 0) ) {
slouken@1421
   151
		verbose = SDL_FALSE;
slouken@1421
   152
	}
slouken@1421
   153
	if ( verbose ) {
slouken@1421
   154
		printf("This system is running %s\n",
slouken@1421
   155
#if __AIX__
slouken@1421
   156
			"AIX"
slouken@4215
   157
#elif __HAIKU__
slouken@4215
   158
/* Haiku must appear here before BeOS, since it also defines __BEOS__ */
slouken@4215
   159
			"Haiku"
slouken@1421
   160
#elif __BEOS__
slouken@1421
   161
			"BeOS"
slouken@1421
   162
#elif __BSDI__
slouken@1421
   163
			"BSDI"
slouken@1421
   164
#elif __DREAMCAST__
slouken@1421
   165
			"Dreamcast"
slouken@1421
   166
#elif __FREEBSD__
slouken@1421
   167
			"FreeBSD"
slouken@1421
   168
#elif __HPUX__
slouken@1421
   169
			"HP-UX"
slouken@1421
   170
#elif __IRIX__
slouken@1421
   171
			"Irix"
slouken@1421
   172
#elif __LINUX__
slouken@1421
   173
			"Linux"
slouken@1421
   174
#elif __MINT__
slouken@1421
   175
			"Atari MiNT"
slouken@1421
   176
#elif __MACOS__
slouken@1421
   177
			"MacOS Classic"
slouken@1421
   178
#elif __MACOSX__
slouken@1621
   179
			"Mac OS X"
slouken@1421
   180
#elif __NETBSD__
slouken@1421
   181
			"NetBSD"
slouken@1421
   182
#elif __OPENBSD__
slouken@1421
   183
			"OpenBSD"
slouken@1421
   184
#elif __OS2__
slouken@1421
   185
			"OS/2"
slouken@1421
   186
#elif __OSF__
slouken@1421
   187
			"OSF/1"
slouken@1421
   188
#elif __QNXNTO__
slouken@1421
   189
			"QNX Neutrino"
slouken@1421
   190
#elif __RISCOS__
slouken@1421
   191
			"RISC OS"
slouken@1421
   192
#elif __SOLARIS__
slouken@1421
   193
			"Solaris"
slouken@1421
   194
#elif __WIN32__
slouken@1421
   195
#ifdef _WIN32_WCE
slouken@1421
   196
			"Windows CE"
slouken@1421
   197
#else
slouken@1421
   198
			"Windows"
slouken@1421
   199
#endif
slouken@1421
   200
#else
slouken@1421
   201
			"an unknown operating system! (see SDL_platform.h)"
slouken@1421
   202
#endif
slouken@1421
   203
		);
slouken@1421
   204
	}
slouken@1421
   205
slouken@1421
   206
	status += TestTypes(verbose);
slouken@1421
   207
	status += TestEndian(verbose);
slouken@1421
   208
	status += TestCPUInfo(verbose);
slouken@1421
   209
	return status;
slouken@1421
   210
}