src/SDL12_compat.c
changeset 34 946cbc18ba19
parent 33 4e9cde983cdc
child 35 365748d8ff6c
equal deleted inserted replaced
33:4e9cde983cdc 34:946cbc18ba19
    62     SDL20_SYM(rc,fn,params,args,ret)
    62     SDL20_SYM(rc,fn,params,args,ret)
    63 #include "SDL20_syms.h"
    63 #include "SDL20_syms.h"
    64 #undef SDL20_SYM_PASSTHROUGH
    64 #undef SDL20_SYM_PASSTHROUGH
    65 #undef SDL20_SYM
    65 #undef SDL20_SYM
    66 
    66 
    67 typedef void (*SDL20_SetError_t)(const char *fmt, ...);
    67 typedef int (*SDL20_SetError_t)(const char *fmt, ...);
    68 static SDL20_SetError_t SDL20_SetError = NULL;
    68 static SDL20_SetError_t SDL20_SetError = NULL;
    69 
    69 
    70 /* these are macros in the SDL headers, so make our own. */
    70 /* Things that _should_ be binary compatible pass right through... */
    71 #define SDL20_OutOfMemory()	SDL20_Error(SDL_ENOMEM)
    71 #define SDL20_SYM(rc,fn,params,args,ret)
    72 #define SDL20_Unsupported()	SDL20_Error(SDL_UNSUPPORTED)
    72 #define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) \
    73 #define SDL20_InvalidParamError(param)	SDL20_SetError("Parameter '%s' is invalid", (param))
    73     rc SDL_##fn params { ret SDL20_##fn args; }
    74 
    74 #include "SDL20_syms.h"
       
    75 #undef SDL20_SYM_PASSTHROUGH
       
    76 #undef SDL20_SYM
       
    77 
       
    78 
       
    79 /* these are macros (etc) in the SDL headers, so make our own. */
       
    80 #define SDL20_OutOfMemory() SDL20_Error(SDL_ENOMEM)
       
    81 #define SDL20_Unsupported() SDL20_Error(SDL_UNSUPPORTED)
       
    82 #define SDL20_InvalidParamError(param) SDL20_SetError("Parameter '%s' is invalid", (param))
       
    83 #define SDL20_zero(x) SDL20_memset(&(x), 0, sizeof((x)))
       
    84 #define SDL20_zerop(x) SDL20_memset((x), 0, sizeof(*(x)))
       
    85 #define SDL_ReportAssertion SDL20_ReportAssertion
       
    86 
       
    87 #define SDL12_DEFAULT_REPEAT_DELAY 500
       
    88 #define SDL12_DEFAULT_REPEAT_INTERVAL 30
    75 
    89 
    76 #define SDL12_INIT_TIMER       0x00000001
    90 #define SDL12_INIT_TIMER       0x00000001
    77 #define SDL12_INIT_AUDIO       0x00000010
    91 #define SDL12_INIT_AUDIO       0x00000010
    78 #define SDL12_INIT_VIDEO       0x00000020
    92 #define SDL12_INIT_VIDEO       0x00000020
    79 #define SDL12_INIT_CDROM       0x00000100
    93 #define SDL12_INIT_CDROM       0x00000100
   116     int w;
   130     int w;
   117     int h;
   131     int h;
   118     Uint16 pitch;
   132     Uint16 pitch;
   119     void *pixels;
   133     void *pixels;
   120     int offset;
   134     int offset;
   121     SDL_Surface *hwdata; /* the real SDL 1.2 has an opaque pointer to a platform-specific thing here. */
   135     SDL_Surface *surface20; /* the real SDL 1.2 has an opaque pointer to a platform-specific thing here named "hwdata". */
   122     SDL_Rect clip_rect;
   136     SDL_Rect clip_rect;
   123     Uint32 unused1;
   137     Uint32 unused1;
   124     Uint32 locked;
   138     Uint32 locked;
   125     void *blitmap;
   139     void *blitmap;
   126     unsigned int format_version;
   140     unsigned int format_version;
   428 
   442 
   429 static void
   443 static void
   430 UnloadSDL20(void)
   444 UnloadSDL20(void)
   431 {
   445 {
   432     #define SDL20_SYM(rc,fn,params,args,ret) SDL20_##fn = NULL;
   446     #define SDL20_SYM(rc,fn,params,args,ret) SDL20_##fn = NULL;
   433     #define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) SDL20_##fn = NULL;
   447     #define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) SDL20_SYM(rc,fn,params,args,ret)
   434     #include "SDL20_syms.h"
   448     #include "SDL20_syms.h"
   435     #undef SDL20_SYM_PASSTHROUGH
   449     #undef SDL20_SYM_PASSTHROUGH
   436     #undef SDL20_SYM
   450     #undef SDL20_SYM
   437     SDL20_SetError = NULL;
   451     SDL20_SetError = NULL;
   438     CloseSDL20Library();
   452     CloseSDL20Library();
   465     const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
   479     const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
   466     if ( !variable ) {
   480     if ( !variable ) {
   467         variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
   481         variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
   468     }
   482     }
   469     if ( variable ) {
   483     if ( variable ) {
   470         return SDL_atoi(variable);
   484         return SDL20_atoi(variable);
   471     } else {
   485     } else {
   472         return 0;
   486         return 0;
   473     }
   487     }
   474 }
   488 }
   475 
   489 
   572     if (sdl12flags & SDL12_INIT_VIDEO) {
   586     if (sdl12flags & SDL12_INIT_VIDEO) {
   573         EventFilter12 = NULL;
   587         EventFilter12 = NULL;
   574         EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
   588         EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
   575         CurrentCursor = NULL;
   589         CurrentCursor = NULL;
   576         SDL20_FreeFormat(VideoInfo.vfmt);
   590         SDL20_FreeFormat(VideoInfo.vfmt);
   577         SDL_zero(VideoInfo);
   591         SDL20_zero(VideoInfo);
   578     }
   592     }
   579 
   593 
   580     // !!! FIXME: do something about SDL12_INIT_EVENTTHREAD
   594     // !!! FIXME: do something about SDL12_INIT_EVENTTHREAD
   581     SDL20_QuitSubSystem(sdl20flags);
   595     SDL20_QuitSubSystem(sdl20flags);
   582 
   596 
   589     // !!! FIXME: reset a bunch of other global variables too.
   603     // !!! FIXME: reset a bunch of other global variables too.
   590     EventFilter12 = NULL;
   604     EventFilter12 = NULL;
   591     EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
   605     EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
   592     CurrentCursor = NULL;
   606     CurrentCursor = NULL;
   593     SDL20_FreeFormat(VideoInfo.vfmt);
   607     SDL20_FreeFormat(VideoInfo.vfmt);
   594     SDL_zero(VideoInfo);
   608     SDL20_zero(VideoInfo);
   595     CDRomInit = 0;
   609     CDRomInit = 0;
   596     SDL20_Quit();
   610     SDL20_Quit();
   597     UnloadSDL20();
   611     UnloadSDL20();
   598 }
   612 }
   599 
   613 
   600 void
   614 void
   601 SDL_SetError(const char *fmt, ...)
   615 SDL_SetError(const char *fmt, ...)
   602 {
   616 {
       
   617     char ch;
   603     char *str = NULL;
   618     char *str = NULL;
       
   619     size_t len = 0;
   604     va_list ap;
   620     va_list ap;
   605     va_start(ap, fmt);
   621     va_start(ap, fmt);
   606     vasprintf(&str, fmt, ap);
   622     len = SDL20_vsnprintf(&ch, 1, fmt, ap);
   607     va_end(ap);
   623     va_end(ap);
       
   624 
       
   625     str = (char *) SDL20_malloc(len + 1);
   608     if (!str)
   626     if (!str)
   609         SDL20_OutOfMemory();
   627         SDL20_OutOfMemory();
   610     else
   628     else
   611     {
   629     {
       
   630         va_start(ap, fmt);
       
   631         SDL20_vsnprintf(str, len + 1, fmt, ap);
       
   632         va_end(ap);
   612         SDL20_SetError("%s", str);
   633         SDL20_SetError("%s", str);
   613         free(str);
   634         SDL20_free(str);
   614     }
   635     }
   615 }
   636 }
   616 
   637 
   617 const char *
   638 const char *
   618 SDL_GetError(void)
   639 SDL_GetError(void)
   792     SDL12_Event event12;
   813     SDL12_Event event12;
   793     int x, y;
   814     int x, y;
   794 
   815 
   795     SDL_assert(data == NULL);  /* currently unused. */
   816     SDL_assert(data == NULL);  /* currently unused. */
   796 
   817 
   797     SDL_zero(event12);
   818     SDL20_zero(event12);
   798 
   819 
   799     switch (event20->type)
   820     switch (event20->type)
   800     {
   821     {
   801         case SDL_QUIT:
   822         case SDL_QUIT:
   802             event12.type = SDL12_QUIT;
   823             event12.type = SDL12_QUIT;
   989 {
  1010 {
   990     return EventFilter12;
  1011     return EventFilter12;
   991 }
  1012 }
   992 
  1013 
   993 
  1014 
   994 SDL12_Surface *
  1015 static SDL12_Surface *
   995 Surface20to12(SDL_Surface *surface20)
  1016 Surface20to12(SDL_Surface *surface20)
   996 {
  1017 {
   997     SDL12_Surface *surface12 = NULL;
  1018     SDL12_Surface *surface12 = NULL;
   998     SDL12_Palette *palette12 = NULL;
  1019     SDL12_Palette *palette12 = NULL;
   999     SDL12_PixelFormat *format12 = NULL;
  1020     SDL12_PixelFormat *format12 = NULL;
  1012 
  1033 
  1013     format12 = (SDL12_PixelFormat *) SDL20_malloc(sizeof (SDL12_PixelFormat));
  1034     format12 = (SDL12_PixelFormat *) SDL20_malloc(sizeof (SDL12_PixelFormat));
  1014     if (!format12)
  1035     if (!format12)
  1015         goto failed;
  1036         goto failed;
  1016 
  1037 
  1017     SDL_zerop(palette12);
  1038     SDL20_zerop(palette12);
  1018     palette12->ncolors = surface20->format->palette->ncolors;
  1039     palette12->ncolors = surface20->format->palette->ncolors;
  1019     palette12->colors = surface20->format->palette->colors;
  1040     palette12->colors = surface20->format->palette->colors;
  1020 
  1041 
  1021     SDL_zerop(format12);
  1042     SDL20_zerop(format12);
  1022     format12->palette = palette12;
  1043     format12->palette = palette12;
  1023     format12->BitsPerPixel = surface20->format->BitsPerPixel;
  1044     format12->BitsPerPixel = surface20->format->BitsPerPixel;
  1024     format12->BytesPerPixel = surface20->format->BytesPerPixel;
  1045     format12->BytesPerPixel = surface20->format->BytesPerPixel;
  1025     format12->Rloss = surface20->format->Rloss;
  1046     format12->Rloss = surface20->format->Rloss;
  1026     format12->Gloss = surface20->format->Gloss;
  1047     format12->Gloss = surface20->format->Gloss;
  1035     format12->Bmask = surface20->format->Bmask;
  1056     format12->Bmask = surface20->format->Bmask;
  1036     format12->Amask = surface20->format->Amask;
  1057     format12->Amask = surface20->format->Amask;
  1037     /* !!! FIXME: format12->colorkey; */
  1058     /* !!! FIXME: format12->colorkey; */
  1038     /* !!! FIXME: format12->alpha; */
  1059     /* !!! FIXME: format12->alpha; */
  1039 
  1060 
  1040     SDL_zerop(surface12);
  1061     SDL20_zerop(surface12);
  1041     flags = surface20->flags;
  1062     flags = surface20->flags;
  1042     #define MAPSURFACEFLAGS(fl) { if (surface20->flags & SDL_##fl) { surface12->flags |= SDL12_##fl; flags &= ~SDL_##fl; } }
  1063     #define MAPSURFACEFLAGS(fl) { if (surface20->flags & SDL_##fl) { surface12->flags |= SDL12_##fl; flags &= ~SDL_##fl; } }
  1043     MAPSURFACEFLAGS(PREALLOC);
  1064     MAPSURFACEFLAGS(PREALLOC);
  1044     MAPSURFACEFLAGS(RLEACCEL);
  1065     MAPSURFACEFLAGS(RLEACCEL);
  1045     MAPSURFACEFLAGS(DONTFREE);
  1066     /*MAPSURFACEFLAGS(DONTFREE);*/
  1046     #undef MAPSURFACEFLAGS
  1067     #undef MAPSURFACEFLAGS
  1047     SDL_assert(flags == 0);  /* non-zero if there's a flag we didn't map. */
  1068     SDL_assert(flags == 0);  /* non-zero if there's a flag we didn't map. */
  1048 
  1069 
  1049     surface12->format = format12;
  1070     surface12->format = format12;
  1050     surface12->w = surface20->w;
  1071     surface12->w = surface20->w;
  1051     surface12->h = surface20->h;
  1072     surface12->h = surface20->h;
  1052     surface12->pitch = (Uint16) surface20->pitch;  /* !!! FIXME: make sure this fits in a Uint16 */
  1073     surface12->pitch = (Uint16) surface20->pitch;  /* !!! FIXME: make sure this fits in a Uint16 */
  1053     surface12->pixels = surface20->pixels;
  1074     surface12->pixels = surface20->pixels;
  1054     surface12->offset = 0;
  1075     surface12->offset = 0;
  1055     surface12->hwdata = surface20;
  1076     surface12->surface20 = surface20;
  1056     SDL20_memcpy(&surface12->clip_rect, &surface20->clip_rect, sizeof (SDL_Rect));
  1077     SDL20_memcpy(&surface12->clip_rect, &surface20->clip_rect, sizeof (SDL_Rect));
  1057     surface12->refcount = surface20->refcount;
  1078     surface12->refcount = surface20->refcount;
  1058 
  1079 
  1059     return surface12;
  1080     return surface12;
  1060 
  1081 
  1094 }
  1115 }
  1095 
  1116 
  1096 void SDL_FreeSurface(SDL12_Surface *surface12)
  1117 void SDL_FreeSurface(SDL12_Surface *surface12)
  1097 {
  1118 {
  1098     if (surface12) {
  1119     if (surface12) {
  1099         SDL20_FreeSurface(surface12->hwdata);
  1120         SDL20_FreeSurface(surface12->surface20);
  1100         if (surface12->format) {
  1121         if (surface12->format) {
  1101             SDL20_free(surface12->format->palette);
  1122             SDL20_free(surface12->format->palette);
  1102             SDL20_free(surface12->format);
  1123             SDL20_free(surface12->format);
  1103         }
  1124         }
  1104         SDL20_free(surface12);
  1125         SDL20_free(surface12);
  1116 SDL_SetClipRect(SDL12_Surface *surface12, const SDL_Rect *rect)
  1137 SDL_SetClipRect(SDL12_Surface *surface12, const SDL_Rect *rect)
  1117 {
  1138 {
  1118     SDL_bool retval = SDL_FALSE;
  1139     SDL_bool retval = SDL_FALSE;
  1119     if (surface12)
  1140     if (surface12)
  1120     {
  1141     {
  1121         retval = SDL20_SetClipRect(surface12->hwdata, rect);
  1142         retval = SDL20_SetClipRect(surface12->surface20, rect);
  1122         SDL20_GetClipRect(surface12->hwdata, &surface12->clip_rect);
  1143         SDL20_GetClipRect(surface12->surface20, &surface12->clip_rect);
  1123     }
  1144     }
  1124     return retval;
  1145     return retval;
  1125 }
  1146 }
  1126 
  1147 
  1127 int
  1148 int
  1128 SDL_FillRect(SDL12_Surface *dst, SDL_Rect *dstrect, Uint32 color)
  1149 SDL_FillRect(SDL12_Surface *dst, SDL_Rect *dstrect, Uint32 color)
  1129 {
  1150 {
  1130     const SDL_Rect orig_dstrect = *dstrect;
  1151     const SDL_Rect orig_dstrect = *dstrect;
  1131     const int retval = SDL20_FillRect(dst->hwdata, &orig_dstrect, color);
  1152     const int retval = SDL20_FillRect(dst->surface20, &orig_dstrect, color);
  1132     if (retval != -1)
  1153     if (retval != -1)
  1133     {
  1154     {
  1134         if (dstrect)  /* 1.2 stores the clip intersection in dstrect */
  1155         if (dstrect)  /* 1.2 stores the clip intersection in dstrect */
  1135             SDL20_IntersectRect(&orig_dstrect, &dst->clip_rect, dstrect);
  1156             SDL20_IntersectRect(&orig_dstrect, &dst->clip_rect, dstrect);
  1136     }
  1157     }
  1143 {
  1164 {
  1144     palette20->ncolors = format12->palette->ncolors;
  1165     palette20->ncolors = format12->palette->ncolors;
  1145     palette20->colors = format12->palette->colors;
  1166     palette20->colors = format12->palette->colors;
  1146     palette20->version = 1;
  1167     palette20->version = 1;
  1147     palette20->refcount = 1;
  1168     palette20->refcount = 1;
  1148     format20->format = SDL_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);
  1169     format20->format = SDL20_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);
  1149     format20->palette = palette20;
  1170     format20->palette = palette20;
  1150     format20->BitsPerPixel = format12->BitsPerPixel;
  1171     format20->BitsPerPixel = format12->BitsPerPixel;
  1151     format20->BytesPerPixel = format12->BytesPerPixel;
  1172     format20->BytesPerPixel = format12->BytesPerPixel;
  1152     format20->Rmask = format12->Rmask;
  1173     format20->Rmask = format12->Rmask;
  1153     format20->Gmask = format12->Gmask;
  1174     format20->Gmask = format12->Gmask;
  1247         }
  1268         }
  1248     }
  1269     }
  1249     return actual_bpp;
  1270     return actual_bpp;
  1250 }
  1271 }
  1251 
  1272 
       
  1273 #if SANITY_CHECK_THIS_CODE
  1252 SDL_Rect **
  1274 SDL_Rect **
  1253 SDL_ListModes(const SDL12_PixelFormat *format, Uint32 flags)
  1275 SDL_ListModes(const SDL12_PixelFormat *format, Uint32 flags)
  1254 {
  1276 {
  1255     int i, nmodes;
  1277     int i, nmodes;
  1256     SDL_Rect **modes;
  1278     SDL_Rect **modes;
  1311     if (modes) {
  1333     if (modes) {
  1312         modes[nmodes] = NULL;
  1334         modes[nmodes] = NULL;
  1313     }
  1335     }
  1314     return modes;
  1336     return modes;
  1315 }
  1337 }
       
  1338 #endif
  1316 
  1339 
  1317 void
  1340 void
  1318 SDL_FreeCursor(SDL12_Cursor *cursor12)
  1341 SDL_FreeCursor(SDL12_Cursor *cursor12)
  1319 {
  1342 {
  1320     if (cursor12)
  1343     if (cursor12)
  1336 
  1359 
  1337     retval = (SDL12_Cursor *) SDL20_malloc(sizeof (SDL12_Cursor));
  1360     retval = (SDL12_Cursor *) SDL20_malloc(sizeof (SDL12_Cursor));
  1338     if (!retval)
  1361     if (!retval)
  1339         goto outofmem;
  1362         goto outofmem;
  1340 
  1363 
  1341     SDL_zerop(retval);
  1364     SDL20_zerop(retval);
  1342 
  1365 
  1343     retval->data = (Uint8 *) SDL20_malloc(datasize);
  1366     retval->data = (Uint8 *) SDL20_malloc(datasize);
  1344     if (!retval->data)
  1367     if (!retval->data)
  1345         goto outofmem;
  1368         goto outofmem;
  1346 
  1369 
  1403         *x = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
  1426         *x = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
  1404         *y = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
  1427         *y = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
  1405     }
  1428     }
  1406 }
  1429 }
  1407 
  1430 
       
  1431 #if SANITY_CHECK_THIS_CODE
  1408 static void
  1432 static void
  1409 ClearVideoSurface()
  1433 ClearVideoSurface()
  1410 {
  1434 {
  1411     if (ShadowSurface) {
  1435     if (ShadowSurface) {
  1412         SDL20_FillRect(ShadowSurface, NULL,
  1436         SDL20_FillRect(ShadowSurface, NULL,
  1413             SDL20_MapRGB(ShadowSurface->format, 0, 0, 0));
  1437             SDL20_MapRGB(ShadowSurface->format, 0, 0, 0));
  1414     }
  1438     }
  1415     SDL20_FillRect(WindowSurface, NULL, 0);
  1439     SDL20_FillRect(WindowSurface, NULL, 0);
  1416     SDL20_UpdateWindowSurface(VideoWindow20);
  1440     SDL20_UpdateWindowSurface(VideoWindow20);
  1417 }
  1441 }
       
  1442 #endif
  1418 
  1443 
  1419 static void
  1444 static void
  1420 SetupScreenSaver(int flags12)
  1445 SetupScreenSaver(int flags12)
  1421 {
  1446 {
  1422     const char *env;
  1447     const char *env;
  1423     SDL_bool allow_screensaver;
  1448     SDL_bool allow_screensaver;
  1424 
  1449 
  1425     /* Allow environment override of screensaver disable */
  1450     /* Allow environment override of screensaver disable */
  1426     env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
  1451     env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
  1427     if (env) {
  1452     if (env) {
  1428         allow_screensaver = SDL_atoi(env) ? SDL_TRUE : SDL_FALSE;
  1453         allow_screensaver = SDL20_atoi(env) ? SDL_TRUE : SDL_FALSE;
  1429     } else if (flags12 & SDL12_FULLSCREEN) {
  1454     } else if (flags12 & SDL12_FULLSCREEN) {
  1430         allow_screensaver = SDL_FALSE;
  1455         allow_screensaver = SDL_FALSE;
  1431     } else {
  1456     } else {
  1432         allow_screensaver = SDL_TRUE;
  1457         allow_screensaver = SDL_TRUE;
  1433     }
  1458     }
  1436     } else {
  1461     } else {
  1437         SDL20_DisableScreenSaver();
  1462         SDL20_DisableScreenSaver();
  1438     }
  1463     }
  1439 }
  1464 }
  1440 
  1465 
       
  1466 #if SANITY_CHECK_THIS_CODE
  1441 static int
  1467 static int
  1442 ResizeVideoMode(int width, int height, int bpp, Uint32 flags12)
  1468 ResizeVideoMode(int width, int height, int bpp, Uint32 flags12)
  1443 {
  1469 {
  1444     int w, h;
  1470     int w, h;
  1445 
  1471 
  1585     }
  1611     }
  1586     SDL20_SetWindowIcon(VideoWindow20, VideoIcon);
  1612     SDL20_SetWindowIcon(VideoWindow20, VideoIcon);
  1587 
  1613 
  1588     SetupScreenSaver(flags12);
  1614     SetupScreenSaver(flags12);
  1589 
  1615 
  1590     window_flags20 = SDL_GetWindowFlags(VideoWindow20);
  1616     window_flags20 = SDL20_GetWindowFlags(VideoWindow20);
  1591     surface_flags12 = 0;
  1617     surface_flags12 = 0;
  1592     if (window_flags20 & SDL_WINDOW_FULLSCREEN) {
  1618     if (window_flags20 & SDL_WINDOW_FULLSCREEN) {
  1593         surface_flags12 |= SDL_FULLSCREEN;
  1619         surface_flags12 |= SDL_FULLSCREEN;
  1594     }
  1620     }
  1595     if ((window_flags & SDL_WINDOW_OPENGL) && (flags12 & SDL_OPENGL)) {
  1621     if ((window_flags & SDL_WINDOW_OPENGL) && (flags12 & SDL_OPENGL)) {
  1734     Uint32 rmask = 0x00ff0000;
  1760     Uint32 rmask = 0x00ff0000;
  1735     Uint32 gmask = 0x0000ff00;
  1761     Uint32 gmask = 0x0000ff00;
  1736     Uint32 bmask = 0x000000ff;
  1762     Uint32 bmask = 0x000000ff;
  1737 
  1763 
  1738     if (!PublicSurface) {
  1764     if (!PublicSurface) {
  1739         SDL_SetError("No video mode has been set");
  1765         SDL20_SetError("No video mode has been set");
  1740         return NULL;
  1766         return NULL;
  1741     }
  1767     }
  1742     vf = PublicSurface->format;
  1768     vf = PublicSurface->format;
  1743 
  1769 
  1744     switch (vf->BytesPerPixel) {
  1770     switch (vf->BytesPerPixel) {
  1814         } else {
  1840         } else {
  1815             SDL_UpdateWindowSurfaceRects(VideoWindow20, rects, numrects);
  1841             SDL_UpdateWindowSurfaceRects(VideoWindow20, rects, numrects);
  1816         }
  1842         }
  1817     }
  1843     }
  1818 }
  1844 }
       
  1845 #endif
  1819 
  1846 
  1820 void
  1847 void
  1821 SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
  1848 SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
  1822 {
  1849 {
  1823     if (screen) {
  1850     if (screen) {
  1824         SDL_Rect rect;
  1851         SDL_Rect rect;
  1825 
       
  1826         /* Fill the rectangle */
       
  1827         rect.x = (int) x;
  1852         rect.x = (int) x;
  1828         rect.y = (int) y;
  1853         rect.y = (int) y;
  1829         rect.w = (int) (w ? w : screen->w);
  1854         rect.w = (int) (w ? w : screen->w);
  1830         rect.h = (int) (h ? h : screen->h);
  1855         rect.h = (int) (h ? h : screen->h);
  1831         SDL_UpdateRects(screen, 1, &rect);
  1856         SDL_UpdateRects(screen, 1, &rect);
  1848     if (WindowIconTitle) {
  1873     if (WindowIconTitle) {
  1849         SDL20_free(WindowIconTitle);
  1874         SDL20_free(WindowIconTitle);
  1850     }
  1875     }
  1851     WindowTitle = title ? SDL_strdup(title) : NULL;
  1876     WindowTitle = title ? SDL_strdup(title) : NULL;
  1852     WindowIconTitle = icon ? SDL_strdup(icon) : NULL;
  1877     WindowIconTitle = icon ? SDL_strdup(icon) : NULL;
  1853     SDL_SetWindowTitle(VideoWindow20, WindowTitle);
  1878     SDL20_SetWindowTitle(VideoWindow20, WindowTitle);
  1854 }
  1879 }
  1855 
  1880 
  1856 void
  1881 void
  1857 SDL_WM_GetCaption(const char **title, const char **icon)
  1882 SDL_WM_GetCaption(const char **title, const char **icon)
  1858 {
  1883 {
  1862     if (icon) {
  1887     if (icon) {
  1863         *icon = WindowIconTitle;
  1888         *icon = WindowIconTitle;
  1864     }
  1889     }
  1865 }
  1890 }
  1866 
  1891 
       
  1892 #if SANITY_CHECK_THIS_CODE
  1867 void
  1893 void
  1868 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
  1894 SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
  1869 {
  1895 {
  1870     // !!! FIXME: free previous icon?
  1896     // !!! FIXME: free previous icon?
  1871     VideoIcon = icon;
  1897     VideoIcon = icon;
  1872     ++VideoIcon->refcount;
  1898     ++VideoIcon->refcount;
  1873 }
  1899 }
       
  1900 #endif
  1874 
  1901 
  1875 int
  1902 int
  1876 SDL_WM_IconifyWindow(void)
  1903 SDL_WM_IconifyWindow(void)
  1877 {
  1904 {
  1878     SDL_MinimizeWindow(VideoWindow20);
  1905     SDL20_MinimizeWindow(VideoWindow20);
  1879     return 0;
  1906     return 0;
  1880 }
  1907 }
  1881 
  1908 
       
  1909 #if SANITY_CHECK_THIS_CODE
  1882 int
  1910 int
  1883 SDL_WM_ToggleFullScreen(SDL_Surface * surface)
  1911 SDL_WM_ToggleFullScreen(SDL_Surface *surface)
  1884 {
  1912 {
  1885     int length;
  1913     int length;
  1886     void *pixels;
  1914     void *pixels;
  1887     Uint8 *src, *dst;
  1915     Uint8 *src, *dst;
  1888     int row;
  1916     int row;
  1889     int window_w;
  1917     int window_w;
  1890     int window_h;
  1918     int window_h;
  1891 
  1919 
  1892     if (!PublicSurface) {
  1920     if (!PublicSurface) {
  1893         SDL_SetError("SDL_SetVideoMode() hasn't been called");
  1921         SDL20_SetError("SDL_SetVideoMode() hasn't been called");
  1894         return 0;
  1922         return 0;
  1895     }
  1923     }
  1896 
  1924 
  1897     /* Copy the old bits out */
  1925     /* Copy the old bits out */
  1898     length = PublicSurface->w * PublicSurface->format->BytesPerPixel;
  1926     length = PublicSurface->w * PublicSurface->format->BytesPerPixel;
  1906             dst += length;
  1934             dst += length;
  1907         }
  1935         }
  1908     }
  1936     }
  1909 
  1937 
  1910     /* Do the physical mode switch */
  1938     /* Do the physical mode switch */
  1911     if (SDL_GetWindowFlags(VideoWindow20) & SDL_WINDOW_FULLSCREEN) {
  1939     if (SDL20_GetWindowFlags(VideoWindow20) & SDL_WINDOW_FULLSCREEN) {
  1912         if (SDL_SetWindowFullscreen(VideoWindow20, 0) < 0) {
  1940         if (SDL20_SetWindowFullscreen(VideoWindow20, 0) < 0) {
  1913             return 0;
  1941             return 0;
  1914         }
  1942         }
  1915         PublicSurface->flags &= ~SDL_FULLSCREEN;
  1943         PublicSurface->flags &= ~SDL_FULLSCREEN;
  1916     } else {
  1944     } else {
  1917         if (SDL_SetWindowFullscreen(VideoWindow20, 1) < 0) {
  1945         if (SDL20_SetWindowFullscreen(VideoWindow20, 1) < 0) {
  1918             return 0;
  1946             return 0;
  1919         }
  1947         }
  1920         PublicSurface->flags |= SDL_FULLSCREEN;
  1948         PublicSurface->flags |= SDL_FULLSCREEN;
  1921     }
  1949     }
  1922 
  1950 
  1923     /* Recreate the screen surface */
  1951     /* Recreate the screen surface */
  1924     WindowSurface = SDL_GetWindowSurface(VideoWindow20);
  1952     WindowSurface = SDL20_GetWindowSurface(VideoWindow20);
  1925     if (!WindowSurface) {
  1953     if (!WindowSurface) {
  1926         /* We're totally hosed... */
  1954         /* We're totally hosed... */
  1927         return 0;
  1955         return 0;
  1928     }
  1956     }
  1929 
  1957 
  1996     }
  2024     }
  1997 
  2025 
  1998     /* We're done! */
  2026     /* We're done! */
  1999     return 1;
  2027     return 1;
  2000 }
  2028 }
       
  2029 #endif
  2001 
  2030 
  2002 typedef enum
  2031 typedef enum
  2003 {
  2032 {
  2004     SDL12_GRAB_QUERY = -1,
  2033     SDL12_GRAB_QUERY = -1,
  2005     SDL12_GRAB_OFF = 0,
  2034     SDL12_GRAB_OFF = 0,
  2008 
  2037 
  2009 SDL12_GrabMode
  2038 SDL12_GrabMode
  2010 SDL_WM_GrabInput(SDL12_GrabMode mode)
  2039 SDL_WM_GrabInput(SDL12_GrabMode mode)
  2011 {
  2040 {
  2012     if (mode != SDL12_GRAB_QUERY) {
  2041     if (mode != SDL12_GRAB_QUERY) {
  2013         SDL_SetWindowGrab(VideoWindow20, (mode == SDL_GRAB_ON));
  2042         SDL20_SetWindowGrab(VideoWindow20, (mode == SDL12_GRAB_ON));
  2014     }
  2043     }
  2015     return SDL_GetWindowGrab(VideoWindow20) ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
  2044     return SDL20_GetWindowGrab(VideoWindow20) ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
  2016 }
  2045 }
  2017 
  2046 
  2018 Uint8
  2047 Uint8
  2019 SDL_GetMouseState(int *x, int *y)
  2048 SDL_GetMouseState(int *x, int *y)
  2020 {
  2049 {
  2031 }
  2060 }
  2032 
  2061 
  2033 void
  2062 void
  2034 SDL_WarpMouse(Uint16 x, Uint16 y)
  2063 SDL_WarpMouse(Uint16 x, Uint16 y)
  2035 {
  2064 {
  2036     SDL_WarpMouseInWindow(VideoWindow20, x, y);
  2065     SDL20_WarpMouseInWindow(VideoWindow20, x, y);
  2037 }
  2066 }
  2038 
  2067 
  2039 Uint8
  2068 Uint8
  2040 SDL_GetAppState(void)
  2069 SDL_GetAppState(void)
  2041 {
  2070 {
  2042     Uint8 state = 0;
  2071     Uint8 state12 = 0;
  2043     Uint32 flags = 0;
  2072     Uint32 flags20 = 0;
  2044 
  2073 
  2045     flags = SDL_GetWindowFlags(VideoWindow20);
  2074     flags20 = SDL20_GetWindowFlags(VideoWindow20);
  2046     if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
  2075     if ((flags20 & SDL_WINDOW_SHOWN) && !(flags20 & SDL_WINDOW_MINIMIZED)) {
  2047         state |= SDL_APPACTIVE;
  2076         state12 |= SDL12_APPACTIVE;
  2048     }
  2077     }
  2049     if (flags & SDL_WINDOW_INPUT_FOCUS) {
  2078     if (flags20 & SDL_WINDOW_INPUT_FOCUS) {
  2050         state |= SDL_APPINPUTFOCUS;
  2079         state12 |= SDL12_APPINPUTFOCUS;
  2051     }
  2080     }
  2052     if (flags & SDL_WINDOW_MOUSE_FOCUS) {
  2081     if (flags20 & SDL_WINDOW_MOUSE_FOCUS) {
  2053         state |= SDL_APPMOUSEFOCUS;
  2082         state12 |= SDL12_APPMOUSEFOCUS;
  2054     }
  2083     }
  2055     return state;
  2084     return state12;
  2056 }
  2085 }
  2057 
  2086 
  2058 const SDL_version *
  2087 #if SANITY_CHECK_THIS_CODE
  2059 SDL_Linked_Version(void)
       
  2060 {
       
  2061     static SDL_version version;
       
  2062     SDL_VERSION(&version);
       
  2063     return &version;
       
  2064 }
       
  2065 
       
  2066 int
  2088 int
  2067 SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
  2089 SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
  2068                int firstcolor, int ncolors)
  2090                int firstcolor, int ncolors)
  2069 {
  2091 {
  2070     return SDL_SetColors(surface, colors, firstcolor, ncolors);
  2092     return SDL_SetColors(surface, colors, firstcolor, ncolors);
  2579     SDL_Overlay *overlay;
  2601     SDL_Overlay *overlay;
  2580     Uint32 texture_format;
  2602     Uint32 texture_format;
  2581     SDL_SW_YUVTexture *texture;
  2603     SDL_SW_YUVTexture *texture;
  2582 
  2604 
  2583     if ((display->flags & SDL_OPENGL) == SDL_OPENGL) {
  2605     if ((display->flags & SDL_OPENGL) == SDL_OPENGL) {
  2584         SDL_SetError("YUV overlays are not supported in OpenGL mode");
  2606         SDL20_SetError("YUV overlays are not supported in OpenGL mode");
  2585         return NULL;
  2607         return NULL;
  2586     }
  2608     }
  2587 
  2609 
  2588     if (display != PublicSurface) {
  2610     if (display != PublicSurface) {
  2589         SDL_SetError("YUV display is only supported on the screen surface");
  2611         SDL20_SetError("YUV display is only supported on the screen surface");
  2590         return NULL;
  2612         return NULL;
  2591     }
  2613     }
  2592 
  2614 
  2593     switch (format) {
  2615     switch (format) {
  2594     case SDL_YV12_OVERLAY:
  2616     case SDL_YV12_OVERLAY:
  2605         break;
  2627         break;
  2606     case SDL_YVYU_OVERLAY:
  2628     case SDL_YVYU_OVERLAY:
  2607         texture_format = SDL_PIXELFORMAT_YVYU;
  2629         texture_format = SDL_PIXELFORMAT_YVYU;
  2608         break;
  2630         break;
  2609     default:
  2631     default:
  2610         SDL_SetError("Unknown YUV format");
  2632         SDL20_SetError("Unknown YUV format");
  2611         return NULL;
  2633         return NULL;
  2612     }
  2634     }
  2613 
  2635 
  2614     overlay = (SDL_Overlay *) SDL20_malloc(sizeof(*overlay));
  2636     overlay = (SDL_Overlay *) SDL20_malloc(sizeof(*overlay));
  2615     if (!overlay) {
  2637     if (!overlay) {
  2616         SDL20_OutOfMemory();
  2638         SDL20_OutOfMemory();
  2617         return NULL;
  2639         return NULL;
  2618     }
  2640     }
  2619     SDL_zerop(overlay);
  2641     SDL20_zerop(overlay);
  2620 
  2642 
  2621     overlay->hwdata =
  2643     overlay->hwdata =
  2622         (struct private_yuvhwdata *) SDL20_malloc(sizeof(*overlay->hwdata));
  2644         (struct private_yuvhwdata *) SDL20_malloc(sizeof(*overlay->hwdata));
  2623     if (!overlay->hwdata) {
  2645     if (!overlay->hwdata) {
  2624         SDL20_free(overlay);
  2646         SDL20_free(overlay);
  2656     SDL_Rect rect;
  2678     SDL_Rect rect;
  2657     void *pixels;
  2679     void *pixels;
  2658     int pitch;
  2680     int pitch;
  2659 
  2681 
  2660     if (!overlay) {
  2682     if (!overlay) {
  2661         SDL_SetError("Passed a NULL overlay");
  2683         return SDL20_SetError("Passed a NULL overlay");
  2662         return -1;
       
  2663     }
  2684     }
  2664 
  2685 
  2665     rect.x = 0;
  2686     rect.x = 0;
  2666     rect.y = 0;
  2687     rect.y = 0;
  2667     rect.w = overlay->w;
  2688     rect.w = overlay->w;
  2708     SDL_Rect src_rect;
  2729     SDL_Rect src_rect;
  2709     SDL_Rect dst_rect;
  2730     SDL_Rect dst_rect;
  2710     void *pixels;
  2731     void *pixels;
  2711 
  2732 
  2712     if (!overlay || !dstrect) {
  2733     if (!overlay || !dstrect) {
  2713         SDL_SetError("Passed a NULL overlay or dstrect");
  2734         return SDL20_SetError("Passed a NULL overlay or dstrect");
  2714         return -1;
       
  2715     }
  2735     }
  2716 
  2736 
  2717     display = overlay->hwdata->display;
  2737     display = overlay->hwdata->display;
  2718     if (display != VideoSurface) {
  2738     if (display != VideoSurface) {
  2719         overlay->hwdata->display = display = VideoSurface;
  2739         overlay->hwdata->display = display = VideoSurface;
  2760         }
  2780         }
  2761         SDL20_free(overlay->hwdata);
  2781         SDL20_free(overlay->hwdata);
  2762     }
  2782     }
  2763     SDL20_free(overlay);
  2783     SDL20_free(overlay);
  2764 }
  2784 }
       
  2785 #endif
  2765 
  2786 
  2766 int
  2787 int
  2767 SDL_GL_SetAttribute(SDL12_GLattr attr, int value)
  2788 SDL_GL_SetAttribute(SDL12_GLattr attr, int value)
  2768 {
  2789 {
  2769     if (attr >= SDL12_GL_MAX_ATTRIBUTE)
  2790     if (attr >= SDL12_GL_MAX_ATTRIBUTE)
  2770     {
  2791         return SDL20_SetError("Unknown GL attribute");
  2771         SDL_SetError("Unknown GL attribute");
       
  2772         return -1;
       
  2773     }
       
  2774 
  2792 
  2775     /* swap control was moved out of this API, everything else lines up. */
  2793     /* swap control was moved out of this API, everything else lines up. */
  2776     if (attr == SDL12_GL_SWAP_CONTROL)
  2794     if (attr == SDL12_GL_SWAP_CONTROL)
  2777     {
  2795     {
  2778         SwapInterval = value;
  2796         SwapInterval = value;
  2784 
  2802 
  2785 int
  2803 int
  2786 SDL_GL_GetAttribute(SDL12_GLattr attr, int* value)
  2804 SDL_GL_GetAttribute(SDL12_GLattr attr, int* value)
  2787 {
  2805 {
  2788     if (attr >= SDL12_GL_MAX_ATTRIBUTE)
  2806     if (attr >= SDL12_GL_MAX_ATTRIBUTE)
  2789     {
  2807         return SDL20_SetError("Unknown GL attribute");
  2790         SDL_SetError("Unknown GL attribute");
       
  2791         return -1;
       
  2792     }
       
  2793 
  2808 
  2794     /* swap control was moved out of this API, everything else lines up. */
  2809     /* swap control was moved out of this API, everything else lines up. */
  2795     if (attr == SDL12_GL_SWAP_CONTROL)
  2810     if (attr == SDL12_GL_SWAP_CONTROL)
  2796     {
  2811     {
  2797         *value = SDL20_GL_GetSwapInterval();
  2812         *value = SDL20_GL_GetSwapInterval();
  2803 
  2818 
  2804 
  2819 
  2805 void
  2820 void
  2806 SDL_GL_SwapBuffers(void)
  2821 SDL_GL_SwapBuffers(void)
  2807 {
  2822 {
  2808     SDL_GL_SwapWindow(VideoWindow20);
  2823     if (VideoWindow20)
       
  2824         SDL20_GL_SwapWindow(VideoWindow20);
  2809 }
  2825 }
  2810 
  2826 
  2811 int
  2827 int
  2812 SDL_SetGamma(float red, float green, float blue)
  2828 SDL_SetGamma(float red, float green, float blue)
  2813 {
  2829 {
  2814     Uint16 red_ramp[256];
  2830     Uint16 red_ramp[256];
  2815     Uint16 green_ramp[256];
  2831     Uint16 green_ramp[256];
  2816     Uint16 blue_ramp[256];
  2832     Uint16 blue_ramp[256];
  2817 
  2833 
  2818     SDL_CalculateGammaRamp(red, red_ramp);
  2834     SDL20_CalculateGammaRamp(red, red_ramp);
  2819     if (green == red) {
  2835     if (green == red) {
  2820         SDL_memcpy(green_ramp, red_ramp, sizeof(red_ramp));
  2836         SDL20_memcpy(green_ramp, red_ramp, sizeof(red_ramp));
  2821     } else {
  2837     } else {
  2822         SDL_CalculateGammaRamp(green, green_ramp);
  2838         SDL20_CalculateGammaRamp(green, green_ramp);
  2823     }
  2839     }
  2824     if (blue == red) {
  2840     if (blue == red) {
  2825         SDL_memcpy(blue_ramp, red_ramp, sizeof(red_ramp));
  2841         SDL20_memcpy(blue_ramp, red_ramp, sizeof(red_ramp));
       
  2842     } else if (blue == green) {
       
  2843         SDL20_memcpy(blue_ramp, green_ramp, sizeof(green_ramp));
  2826     } else {
  2844     } else {
  2827         SDL_CalculateGammaRamp(blue, blue_ramp);
  2845         SDL20_CalculateGammaRamp(blue, blue_ramp);
  2828     }
  2846     }
  2829     return SDL_SetWindowGammaRamp(VideoWindow20, red_ramp, green_ramp, blue_ramp);
  2847     return SDL20_SetWindowGammaRamp(VideoWindow20, red_ramp, green_ramp, blue_ramp);
  2830 }
  2848 }
  2831 
  2849 
  2832 int
  2850 int
  2833 SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue)
  2851 SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue)
  2834 {
  2852 {
  2835     return SDL_SetWindowGammaRamp(VideoWindow20, red, green, blue);
  2853     return SDL20_SetWindowGammaRamp(VideoWindow20, red, green, blue);
  2836 }
  2854 }
  2837 
  2855 
  2838 int
  2856 int
  2839 SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue)
  2857 SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue)
  2840 {
  2858 {
  2841     return SDL_GetWindowGammaRamp(VideoWindow20, red, green, blue);
  2859     return SDL20_GetWindowGammaRamp(VideoWindow20, red, green, blue);
  2842 }
  2860 }
  2843 
  2861 
  2844 int
  2862 int
  2845 SDL_EnableKeyRepeat(int delay, int interval)
  2863 SDL_EnableKeyRepeat(int delay, int interval)
  2846 {
  2864 {
  2849 
  2867 
  2850 void
  2868 void
  2851 SDL_GetKeyRepeat(int *delay, int *interval)
  2869 SDL_GetKeyRepeat(int *delay, int *interval)
  2852 {
  2870 {
  2853     if (delay) {
  2871     if (delay) {
  2854         *delay = SDL_DEFAULT_REPEAT_DELAY;
  2872         *delay = SDL12_DEFAULT_REPEAT_DELAY;
  2855     }
  2873     }
  2856     if (interval) {
  2874     if (interval) {
  2857         *interval = SDL_DEFAULT_REPEAT_INTERVAL;
  2875         *interval = SDL12_DEFAULT_REPEAT_INTERVAL;
  2858     }
  2876     }
  2859 }
  2877 }
  2860 
  2878 
  2861 
  2879 #if SANITY_CHECK_THIS_CODE
  2862 
       
  2863 
       
  2864 int
  2880 int
  2865 SDL_EnableUNICODE(int enable)
  2881 SDL_EnableUNICODE(int enable)
  2866 {
  2882 {
  2867     int previous = EnabledUnicode;
  2883     int previous = EnabledUnicode;
  2868 
  2884 
  2869     switch (enable) {
  2885     switch (enable) {
  2870     case 1:
  2886     case 1:
  2871         EnabledUnicode = 1;
  2887         EnabledUnicode = 1;
  2872         SDL_StartTextInput();
  2888         SDL20_StartTextInput();
  2873         break;
  2889         break;
  2874     case 0:
  2890     case 0:
  2875         EnabledUnicode = 0;
  2891         EnabledUnicode = 0;
  2876         SDL_StopTextInput();
  2892         SDL20_StopTextInput();
  2877         break;
  2893         break;
  2878     }
  2894     }
  2879     return previous;
  2895     return previous;
  2880 }
  2896 }
       
  2897 #endif
  2881 
  2898 
  2882 static Uint32
  2899 static Uint32
  2883 SDL_SetTimerCallback(Uint32 interval, void* param)
  2900 SetTimerOld_Callback(Uint32 interval, void* param)
  2884 {
  2901 {
  2885     return ((SDL12_TimerCallback)param)(interval);
  2902     return ((SDL12_TimerCallback)param)(interval);
  2886 }
  2903 }
  2887 
  2904 
  2888 int
  2905 int
  2894         SDL20_RemoveTimer(compat_timer);
  2911         SDL20_RemoveTimer(compat_timer);
  2895         compat_timer = 0;
  2912         compat_timer = 0;
  2896     }
  2913     }
  2897 
  2914 
  2898     if (interval && callback) {
  2915     if (interval && callback) {
  2899         compat_timer = SDL20_AddTimer(interval, SDL_SetTimerCallback, callback);
  2916         compat_timer = SDL20_AddTimer(interval, SetTimerOld_Callback, callback);
  2900         if (!compat_timer) {
  2917         if (!compat_timer) {
  2901             return -1;
  2918             return -1;
  2902         }
  2919         }
  2903     }
  2920     }
  2904     return 0;
  2921     return 0;
  2906 
  2923 
  2907 int
  2924 int
  2908 SDL_putenv(const char *_var)
  2925 SDL_putenv(const char *_var)
  2909 {
  2926 {
  2910     char *ptr = NULL;
  2927     char *ptr = NULL;
  2911     char *var = SDL_strdup(_var);
  2928     char *var = SDL20_strdup(_var);
  2912     if (var == NULL) {
  2929     if (var == NULL) {
  2913         return -1;  /* we don't set errno. */
  2930         return -1;  /* we don't set errno. */
  2914     }
  2931     }
  2915 
  2932 
  2916     ptr = SDL_strchr(var, '=');
  2933     ptr = SDL20_strchr(var, '=');
  2917     if (ptr == NULL) {
  2934     if (ptr == NULL) {
  2918         SDL20_free(var);
  2935         SDL20_free(var);
  2919         return -1;
  2936         return -1;
  2920     }
  2937     }
  2921 
  2938 
  2922     *ptr = '\0';  /* split the string into name and value. */
  2939     *ptr = '\0';  /* split the string into name and value. */
  2923     SDL_setenv(var, ptr + 1, 1);
  2940     SDL20_setenv(var, ptr + 1, 1);
  2924     SDL20_free(var);
  2941     SDL20_free(var);
  2925     return 0;
  2942     return 0;
  2926 }
  2943 }
  2927 
  2944 
  2928 
  2945 
  2930 /* CD-ROM support is gone from SDL 2.0, so just have stubs that fail. */
  2947 /* CD-ROM support is gone from SDL 2.0, so just have stubs that fail. */
  2931 
  2948 
  2932 typedef void *SDL12_CD;  /* close enough.  :) */
  2949 typedef void *SDL12_CD;  /* close enough.  :) */
  2933 typedef int SDL12_CDstatus;  /* close enough.  :) */
  2950 typedef int SDL12_CDstatus;  /* close enough.  :) */
  2934 
  2951 
  2935 static int
       
  2936 CDUnsupported(void)
       
  2937 {
       
  2938     SDL_SetError("CD interface is unsupported");
       
  2939     return -1;
       
  2940 }
       
  2941 
       
  2942 int
  2952 int
  2943 SDL_CDNumDrives(void)
  2953 SDL_CDNumDrives(void)
  2944 {
  2954 {
  2945     return 0;  /* !!! FIXME: should return -1 without SDL_INIT_CDROM */
  2955     return 0;  /* !!! FIXME: should return -1 without SDL_INIT_CDROM */
  2946 }
  2956 }
  2947 
  2957 
  2948 const char *SDL_CDName(int drive) { CDUnsupported(); return NULL; }
  2958 const char *SDL_CDName(int drive) { SDL20_Unsupported(); return NULL; }
  2949 SDL12_CD * SDL_CDOpen(int drive) { CDUnsupported(); return NULL; }
  2959 SDL12_CD * SDL_CDOpen(int drive) { SDL20_Unsupported(); return NULL; }
  2950 SDL12_CDstatus SDL_CDStatus(SDL12_CD *cdrom) { return CDUnsupported(); }
  2960 SDL12_CDstatus SDL_CDStatus(SDL12_CD *cdrom) { return SDL20_Unsupported(); }
  2951 int SDL_CDPlayTracks(SDL12_CD *cdrom, int start_track, int start_frame, int ntracks, int nframes) { return CDUnsupported(); }
  2961 int SDL_CDPlayTracks(SDL12_CD *cdrom, int start_track, int start_frame, int ntracks, int nframes) { return SDL20_Unsupported(); }
  2952 int SDL_CDPlay(SDL12_CD *cdrom, int start, int length) { return CDUnsupported(); }
  2962 int SDL_CDPlay(SDL12_CD *cdrom, int start, int length) { return SDL20_Unsupported(); }
  2953 int SDL_CDPause(SDL12_CD *cdrom) { return CDUnsupported(); }
  2963 int SDL_CDPause(SDL12_CD *cdrom) { return SDL20_Unsupported(); }
  2954 int SDL_CDResume(SDL12_CD *cdrom) { return CDUnsupported(); }
  2964 int SDL_CDResume(SDL12_CD *cdrom) { return SDL20_Unsupported(); }
  2955 int SDL_CDStop(SDL12_CD *cdrom) { return CDUnsupported(); }
  2965 int SDL_CDStop(SDL12_CD *cdrom) { return SDL20_Unsupported(); }
  2956 int SDL_CDEject(SDL12_CD *cdrom) { return CDUnsupported(); }
  2966 int SDL_CDEject(SDL12_CD *cdrom) { return SDL20_Unsupported(); }
  2957 void SDL_CDClose(SDL12_CD *cdrom) {}
  2967 void SDL_CDClose(SDL12_CD *cdrom) {}
  2958 
  2968 
  2959 
  2969 
  2960 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
  2970 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
  2961 SDL_Thread *
  2971 SDL_Thread *
  3060 
  3070 
  3061     rwops12 = SDL_AllocRW();
  3071     rwops12 = SDL_AllocRW();
  3062     if (!rwops12)
  3072     if (!rwops12)
  3063         return NULL;
  3073         return NULL;
  3064 
  3074 
  3065     SDL_zerop(rwops12);
  3075     SDL20_zerop(rwops12);
  3066     rwops12->type = rwops20->type;
  3076     rwops12->type = rwops20->type;
  3067     rwops12->rwops20 = rwops20;
  3077     rwops12->rwops20 = rwops20;
  3068     rwops12->seek = RWops20to12_seek;
  3078     rwops12->seek = RWops20to12_seek;
  3069     rwops12->read = RWops20to12_read;
  3079     rwops12->read = RWops20to12_read;
  3070     rwops12->write = RWops20to12_write;
  3080     rwops12->write = RWops20to12_write;
  3122 BYTESWAP_AND_WRITE(BE,32)
  3132 BYTESWAP_AND_WRITE(BE,32)
  3123 BYTESWAP_AND_WRITE(LE,64)
  3133 BYTESWAP_AND_WRITE(LE,64)
  3124 BYTESWAP_AND_WRITE(BE,64)
  3134 BYTESWAP_AND_WRITE(BE,64)
  3125 #undef BYTESWAP_AND_WRITE
  3135 #undef BYTESWAP_AND_WRITE
  3126 
  3136 
  3127 /* Things that _should_ be binary compatible pass right through... */
       
  3128 #define SDL20_SYM(rc,fn,params,args,ret)
       
  3129 #define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) \
       
  3130     rc SDL_##fn params { ret SDL20_##fn args; }
       
  3131 #include "SDL20_syms.h"
       
  3132 #undef SDL20_SYM_PASSTHROUGH
       
  3133 #undef SDL20_SYM
       
  3134 
       
  3135 
  3137 
  3136 static Sint64 SDLCALL
  3138 static Sint64 SDLCALL
  3137 RWops12to20_size(struct SDL_RWops *rwops20)
  3139 RWops12to20_size(struct SDL_RWops *rwops20)
  3138 {
  3140 {
  3139     SDL12_RWops *rwops12 = (SDL12_RWops *) rwops20->hidden.unknown.data1;
  3141     SDL12_RWops *rwops12 = (SDL12_RWops *) rwops20->hidden.unknown.data1;
  3204 
  3206 
  3205     rwops20 = SDL20_AllocRW();
  3207     rwops20 = SDL20_AllocRW();
  3206     if (!rwops20)
  3208     if (!rwops20)
  3207         return NULL;
  3209         return NULL;
  3208 
  3210 
  3209     SDL_zerop(rwops20);
  3211     SDL20_zerop(rwops20);
  3210     rwops20->type = rwops12->type;
  3212     rwops20->type = rwops12->type;
  3211     rwops20->hidden.unknown.data1 = rwops12;
  3213     rwops20->hidden.unknown.data1 = rwops12;
  3212     rwops20->hidden.unknown.data2 = -1;  /* cached size of stream */
  3214     rwops20->hidden.unknown.data2 = -1;  /* cached size of stream */
  3213     rwops20->size = RWops12to20_size;
  3215     rwops20->size = RWops12to20_size;
  3214     rwops20->seek = RWops12to20_seek;
  3216     rwops20->seek = RWops12to20_seek;
  3220 
  3222 
  3221 SDL12_Surface *
  3223 SDL12_Surface *
  3222 SDL_LoadBMP_RW(SDL12_RWops *rwops12, int freerwops12)
  3224 SDL_LoadBMP_RW(SDL12_RWops *rwops12, int freerwops12)
  3223 {
  3225 {
  3224     SDL_RWops *rwops20 = RWops12to20(rwops12);
  3226     SDL_RWops *rwops20 = RWops12to20(rwops12);
  3225     SDL_Surface *retval = SDL20_LoadBMP_RW(rwops20, freerwops12);
  3227     SDL_Surface *surface20 = SDL20_LoadBMP_RW(rwops20, freerwops12);
       
  3228     SDL12_Surface *surface12 = Surface20to12(surface20);
  3226     if (!freerwops12)  /* free our wrapper if SDL2 didn't close it. */
  3229     if (!freerwops12)  /* free our wrapper if SDL2 didn't close it. */
  3227         SDL20_FreeRW(rwops20);
  3230         SDL20_FreeRW(rwops20);
  3228     // !!! FIXME: wrap surface.
  3231     if ((!surface12) && (surface20))
  3229     return retval;
  3232         SDL20_FreeSurface(surface20);
       
  3233     return surface12;
  3230 }
  3234 }
  3231 
  3235 
  3232 int
  3236 int
  3233 SDL_SaveBMP_RW(SDL12_Surface *surface, SDL12_RWops *rwops12, int freerwops12)
  3237 SDL_SaveBMP_RW(SDL12_Surface *surface12, SDL12_RWops *rwops12, int freerwops12)
  3234 {
  3238 {
  3235     // !!! FIXME: wrap surface.
  3239     // !!! FIXME: wrap surface.
  3236     SDL_RWops *rwops20 = RWops12to20(rwops12);
  3240     SDL_RWops *rwops20 = RWops12to20(rwops12);
  3237     const int retval = SDL20_SaveBMP_RW(surface, rwops20, freerwops12);
  3241     const int retval = SDL20_SaveBMP_RW(surface12->surface20, rwops20, freerwops12);
  3238     if (!freerwops12)  /* free our wrapper if SDL2 didn't close it. */
  3242     if (!freerwops12)  /* free our wrapper if SDL2 didn't close it. */
  3239         SDL20_FreeRW(rwops20);
  3243         SDL20_FreeRW(rwops20);
  3240     return retval;
  3244     return retval;
  3241 }
  3245 }
  3242 
  3246