test/testplatform.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Sep 2009 09:21:00 +0000
changeset 3292 245a7d79577c
parent 2765 f55c87ae336b
child 3312 c91cb3f0204e
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/
     1 
     2 #include <stdio.h>
     3 
     4 #include "SDL.h"
     5 #include "SDL_endian.h"
     6 #include "SDL_cpuinfo.h"
     7 
     8 /*
     9  * Watcom C flags these as Warning 201: "Unreachable code" if you just
    10  *  compare them directly, so we push it through a function to keep the
    11  *  compiler quiet.  --ryan.
    12  */
    13 static int
    14 badsize(size_t sizeoftype, size_t hardcodetype)
    15 {
    16     return sizeoftype != hardcodetype;
    17 }
    18 
    19 int
    20 TestTypes(SDL_bool verbose)
    21 {
    22     int error = 0;
    23 
    24     if (badsize(sizeof(Uint8), 1)) {
    25         if (verbose)
    26             printf("sizeof(Uint8) != 1, instead = %ul\n", sizeof(Uint8));
    27         ++error;
    28     }
    29     if (badsize(sizeof(Uint16), 2)) {
    30         if (verbose)
    31             printf("sizeof(Uint16) != 2, instead = %ul\n", sizeof(Uint16));
    32         ++error;
    33     }
    34     if (badsize(sizeof(Uint32), 4)) {
    35         if (verbose)
    36             printf("sizeof(Uint32) != 4, instead = %ul\n", sizeof(Uint32));
    37         ++error;
    38     }
    39 #ifdef SDL_HAS_64BIT_TYPE
    40     if (badsize(sizeof(Uint64), 8)) {
    41         if (verbose)
    42             printf("sizeof(Uint64) != 8, instead = %ul\n", sizeof(Uint64));
    43         ++error;
    44     }
    45 #else
    46     if (verbose) {
    47         printf("WARNING: No 64-bit datatype on this platform\n");
    48     }
    49 #endif
    50     if (verbose && !error)
    51         printf("All data types are the expected size.\n");
    52 
    53     return (error ? 1 : 0);
    54 }
    55 
    56 int
    57 TestEndian(SDL_bool verbose)
    58 {
    59     int error = 0;
    60     Uint16 value = 0x1234;
    61     int real_byteorder;
    62     Uint16 value16 = 0xCDAB;
    63     Uint16 swapped16 = 0xABCD;
    64     Uint32 value32 = 0xEFBEADDE;
    65     Uint32 swapped32 = 0xDEADBEEF;
    66 #ifdef SDL_HAS_64BIT_TYPE
    67     Uint64 value64, swapped64;
    68     value64 = 0xEFBEADDE;
    69     value64 <<= 32;
    70     value64 |= 0xCDAB3412;
    71     swapped64 = 0x1234ABCD;
    72     swapped64 <<= 32;
    73     swapped64 |= 0xDEADBEEF;
    74 #endif
    75 
    76     if (verbose) {
    77         printf("Detected a %s endian machine.\n",
    78                (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
    79     }
    80     if ((*((char *) &value) >> 4) == 0x1) {
    81         real_byteorder = SDL_BIG_ENDIAN;
    82     } else {
    83         real_byteorder = SDL_LIL_ENDIAN;
    84     }
    85     if (real_byteorder != SDL_BYTEORDER) {
    86         if (verbose) {
    87             printf("Actually a %s endian machine!\n",
    88                    (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
    89         }
    90         ++error;
    91     }
    92     if (verbose) {
    93         printf("Value 16 = 0x%X, swapped = 0x%X\n", value16,
    94                SDL_Swap16(value16));
    95     }
    96     if (SDL_Swap16(value16) != swapped16) {
    97         if (verbose) {
    98             printf("16 bit value swapped incorrectly!\n");
    99         }
   100         ++error;
   101     }
   102     if (verbose) {
   103         printf("Value 32 = 0x%X, swapped = 0x%X\n", value32,
   104                SDL_Swap32(value32));
   105     }
   106     if (SDL_Swap32(value32) != swapped32) {
   107         if (verbose) {
   108             printf("32 bit value swapped incorrectly!\n");
   109         }
   110         ++error;
   111     }
   112 #ifdef SDL_HAS_64BIT_TYPE
   113     if (verbose) {
   114 #ifdef _MSC_VER
   115         printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
   116                SDL_Swap64(value64));
   117 #else
   118         printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64,
   119                SDL_Swap64(value64));
   120 #endif
   121     }
   122     if (SDL_Swap64(value64) != swapped64) {
   123         if (verbose) {
   124             printf("64 bit value swapped incorrectly!\n");
   125         }
   126         ++error;
   127     }
   128 #endif
   129     return (error ? 1 : 0);
   130 }
   131 
   132 
   133 int
   134 TestCPUInfo(SDL_bool verbose)
   135 {
   136     if (verbose) {
   137         printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
   138         printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
   139         printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected");
   140         printf("3DNow %s\n", SDL_Has3DNow()? "detected" : "not detected");
   141         printf("3DNow Ext %s\n",
   142                SDL_Has3DNowExt()? "detected" : "not detected");
   143         printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
   144         printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
   145         printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
   146     }
   147     return (0);
   148 }
   149 
   150 int
   151 main(int argc, char *argv[])
   152 {
   153     SDL_bool verbose = SDL_TRUE;
   154     int status = 0;
   155 
   156     if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
   157         verbose = SDL_FALSE;
   158     }
   159     if (verbose) {
   160         printf("This system is running %s\n",
   161 #if __AIX__
   162                "AIX"
   163 #elif __HAIKU__
   164 /* Haiku must appear here before BeOS, since it also defines __BEOS__ */
   165                "Haiku"
   166 #elif __BEOS__
   167                "BeOS"
   168 #elif __BSDI__
   169                "BSDI"
   170 #elif __DREAMCAST__
   171                "Dreamcast"
   172 #elif __FREEBSD__
   173                "FreeBSD"
   174 #elif __HPUX__
   175                "HP-UX"
   176 #elif __IRIX__
   177                "Irix"
   178 #elif __LINUX__
   179                "Linux"
   180 #elif __MINT__
   181                "Atari MiNT"
   182 #elif __MACOS__
   183                "MacOS Classic"
   184 #elif __MACOSX__
   185                "Mac OS X"
   186 #elif __NETBSD__
   187                "NetBSD"
   188 #elif __OPENBSD__
   189                "OpenBSD"
   190 #elif __OS2__
   191                "OS/2"
   192 #elif __OSF__
   193                "OSF/1"
   194 #elif __QNXNTO__
   195                "QNX Neutrino"
   196 #elif __RISCOS__
   197                "RISC OS"
   198 #elif __SOLARIS__
   199                "Solaris"
   200 #elif __WIN32__
   201 #ifdef _WIN32_WCE
   202                "Windows CE"
   203 #else
   204                "Windows"
   205 #endif
   206 #elif __IPHONEOS__
   207                "iPhone OS"
   208 #else
   209                "an unknown operating system! (see SDL_platform.h)"
   210 #endif
   211             );
   212     }
   213 
   214     status += TestTypes(verbose);
   215     status += TestEndian(verbose);
   216     status += TestCPUInfo(verbose);
   217     return status;
   218 }