test/testplatform.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1621 f12379c41042
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

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