comparison src/video/windx5/SDL_dx5video.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
470 DDSURFACEDESC desc; 470 DDSURFACEDESC desc;
471 LPDIRECTDRAWSURFACE DDrawSurf; 471 LPDIRECTDRAWSURFACE DDrawSurf;
472 LPDIRECTDRAWSURFACE3 DDrawSurf3; 472 LPDIRECTDRAWSURFACE3 DDrawSurf3;
473 473
474 /* Try to create a DirectDrawSurface3 object */ 474 /* Try to create a DirectDrawSurface3 object */
475 memset(&desc, 0, sizeof(desc)); 475 SDL_memset(&desc, 0, sizeof(desc));
476 desc.dwSize = sizeof(desc); 476 desc.dwSize = sizeof(desc);
477 desc.dwFlags = DDSD_CAPS; 477 desc.dwFlags = DDSD_CAPS;
478 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY; 478 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
479 if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc, 479 if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
480 &DDrawSurf, NULL)) ) { 480 &DDrawSurf, NULL)) ) {
544 IDirectDraw2_Release(ddraw2); 544 IDirectDraw2_Release(ddraw2);
545 } 545 }
546 DX5_Unload(); 546 DX5_Unload();
547 if ( this ) { 547 if ( this ) {
548 if ( this->hidden ) { 548 if ( this->hidden ) {
549 free(this->hidden); 549 SDL_free(this->hidden);
550 } 550 }
551 if ( this->gl_data ) { 551 if ( this->gl_data ) {
552 free(this->gl_data); 552 SDL_free(this->gl_data);
553 } 553 }
554 free(this); 554 SDL_free(this);
555 } 555 }
556 } 556 }
557 557
558 static SDL_VideoDevice *DX5_CreateDevice(int devindex) 558 static SDL_VideoDevice *DX5_CreateDevice(int devindex)
559 { 559 {
563 if ( DX5_Load() < 0 ) { 563 if ( DX5_Load() < 0 ) {
564 return(NULL); 564 return(NULL);
565 } 565 }
566 566
567 /* Initialize all variables that we clean on shutdown */ 567 /* Initialize all variables that we clean on shutdown */
568 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); 568 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
569 if ( device ) { 569 if ( device ) {
570 memset(device, 0, (sizeof *device)); 570 SDL_memset(device, 0, (sizeof *device));
571 device->hidden = (struct SDL_PrivateVideoData *) 571 device->hidden = (struct SDL_PrivateVideoData *)
572 malloc((sizeof *device->hidden)); 572 SDL_malloc((sizeof *device->hidden));
573 device->gl_data = (struct SDL_PrivateGLData *) 573 device->gl_data = (struct SDL_PrivateGLData *)
574 malloc((sizeof *device->gl_data)); 574 SDL_malloc((sizeof *device->gl_data));
575 } 575 }
576 if ( (device == NULL) || (device->hidden == NULL) || 576 if ( (device == NULL) || (device->hidden == NULL) ||
577 (device->gl_data == NULL) ) { 577 (device->gl_data == NULL) ) {
578 SDL_OutOfMemory(); 578 SDL_OutOfMemory();
579 DX5_DeleteDevice(device); 579 DX5_DeleteDevice(device);
580 return(NULL); 580 return(NULL);
581 } 581 }
582 memset(device->hidden, 0, (sizeof *device->hidden)); 582 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
583 memset(device->gl_data, 0, (sizeof *device->gl_data)); 583 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
584 584
585 /* Set the function pointers */ 585 /* Set the function pointers */
586 device->VideoInit = DX5_VideoInit; 586 device->VideoInit = DX5_VideoInit;
587 device->ListModes = DX5_ListModes; 587 device->ListModes = DX5_ListModes;
588 device->SetVideoMode = DX5_SetVideoMode; 588 device->SetVideoMode = DX5_SetVideoMode;
676 #endif 676 #endif
677 } 677 }
678 break; 678 break;
679 } 679 }
680 ++SDL_nummodes[bpp]; 680 ++SDL_nummodes[bpp];
681 enumrect = (struct DX5EnumRect*)malloc(sizeof(struct DX5EnumRect)); 681 enumrect = (struct DX5EnumRect*)SDL_malloc(sizeof(struct DX5EnumRect));
682 if ( !enumrect ) { 682 if ( !enumrect ) {
683 SDL_OutOfMemory(); 683 SDL_OutOfMemory();
684 return(DDENUMRET_CANCEL); 684 return(DDENUMRET_CANCEL);
685 } 685 }
686 enumrect->refreshRate = refreshRate; 686 enumrect->refreshRate = refreshRate;
807 break; 807 break;
808 case E_NOINTERFACE: 808 case E_NOINTERFACE:
809 error = "Interface not present"; 809 error = "Interface not present";
810 break; 810 break;
811 default: 811 default:
812 snprintf(errbuf, SDL_arraysize(errbuf), 812 SDL_snprintf(errbuf, SDL_arraysize(errbuf),
813 "%s: Unknown DirectDraw error: 0x%x", 813 "%s: Unknown DirectDraw error: 0x%x",
814 function, code); 814 function, code);
815 break; 815 break;
816 } 816 }
817 if ( ! errbuf[0] ) { 817 if ( ! errbuf[0] ) {
818 snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); 818 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
819 } 819 }
820 SDL_SetError("%s", errbuf); 820 SDL_SetError("%s", errbuf);
821 return; 821 return;
822 } 822 }
823 823
835 DDCAPS_DX5 DDCaps; 835 DDCAPS_DX5 DDCaps;
836 #endif 836 #endif
837 HRESULT result; 837 HRESULT result;
838 838
839 /* Fill in our hardware acceleration capabilities */ 839 /* Fill in our hardware acceleration capabilities */
840 memset(&DDCaps, 0, sizeof(DDCaps)); 840 SDL_memset(&DDCaps, 0, sizeof(DDCaps));
841 DDCaps.dwSize = sizeof(DDCaps); 841 DDCaps.dwSize = sizeof(DDCaps);
842 result = IDirectDraw2_GetCaps(ddraw2, (DDCAPS *)&DDCaps, NULL); 842 result = IDirectDraw2_GetCaps(ddraw2, (DDCAPS *)&DDCaps, NULL);
843 if ( result != DD_OK ) { 843 if ( result != DD_OK ) {
844 SetDDerror("DirectDraw2::GetCaps", result); 844 SetDDerror("DirectDraw2::GetCaps", result);
845 return(-1); 845 return(-1);
944 return(-1); 944 return(-1);
945 } 945 }
946 for ( i=0; i<NUM_MODELISTS; ++i ) { 946 for ( i=0; i<NUM_MODELISTS; ++i ) {
947 struct DX5EnumRect *rect; 947 struct DX5EnumRect *rect;
948 SDL_modelist[i] = (SDL_Rect **) 948 SDL_modelist[i] = (SDL_Rect **)
949 malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *)); 949 SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
950 if ( SDL_modelist[i] == NULL ) { 950 if ( SDL_modelist[i] == NULL ) {
951 SDL_OutOfMemory(); 951 SDL_OutOfMemory();
952 return(-1); 952 return(-1);
953 } 953 }
954 for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next ) { 954 for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next ) {
1101 */ 1101 */
1102 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1102 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1103 DEVMODE settings; 1103 DEVMODE settings;
1104 BOOL changed; 1104 BOOL changed;
1105 1105
1106 memset(&settings, 0, sizeof(DEVMODE)); 1106 SDL_memset(&settings, 0, sizeof(DEVMODE));
1107 settings.dmSize = sizeof(DEVMODE); 1107 settings.dmSize = sizeof(DEVMODE);
1108 settings.dmBitsPerPel = video->format->BitsPerPixel; 1108 settings.dmBitsPerPel = video->format->BitsPerPixel;
1109 settings.dmPelsWidth = width; 1109 settings.dmPelsWidth = width;
1110 settings.dmPelsHeight = height; 1110 settings.dmPelsHeight = height;
1111 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; 1111 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
1161 UINT swp_flags; 1161 UINT swp_flags;
1162 const char *window = NULL; 1162 const char *window = NULL;
1163 const char *center = NULL; 1163 const char *center = NULL;
1164 1164
1165 if ( !SDL_windowX && !SDL_windowY ) { 1165 if ( !SDL_windowX && !SDL_windowY ) {
1166 window = getenv("SDL_VIDEO_WINDOW_POS"); 1166 window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
1167 center = getenv("SDL_VIDEO_CENTERED"); 1167 center = SDL_getenv("SDL_VIDEO_CENTERED");
1168 if ( window ) { 1168 if ( window ) {
1169 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { 1169 if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {
1170 SDL_windowX = x; 1170 SDL_windowX = x;
1171 SDL_windowY = y; 1171 SDL_windowY = y;
1172 } 1172 }
1173 if ( strcmp(window, "center") == 0 ) { 1173 if ( SDL_strcmp(window, "center") == 0 ) {
1174 center = window; 1174 center = window;
1175 } 1175 }
1176 } 1176 }
1177 } 1177 }
1178 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); 1178 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
1304 DX5_DInputReset(this, 0); 1304 DX5_DInputReset(this, 0);
1305 } 1305 }
1306 DX5_UpdateVideoInfo(this); 1306 DX5_UpdateVideoInfo(this);
1307 1307
1308 /* Create a primary DirectDraw surface */ 1308 /* Create a primary DirectDraw surface */
1309 memset(&ddsd, 0, sizeof(ddsd)); 1309 SDL_memset(&ddsd, 0, sizeof(ddsd));
1310 ddsd.dwSize = sizeof(ddsd); 1310 ddsd.dwSize = sizeof(ddsd);
1311 ddsd.dwFlags = DDSD_CAPS; 1311 ddsd.dwFlags = DDSD_CAPS;
1312 ddsd.ddsCaps.dwCaps = (DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY); 1312 ddsd.ddsCaps.dwCaps = (DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY);
1313 if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) { 1313 if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
1314 /* There's no windowed double-buffering */ 1314 /* There's no windowed double-buffering */
1338 return(NULL); 1338 return(NULL);
1339 } 1339 }
1340 IDirectDrawSurface_Release(dd_surface1); 1340 IDirectDrawSurface_Release(dd_surface1);
1341 1341
1342 /* Get the format of the primary DirectDraw surface */ 1342 /* Get the format of the primary DirectDraw surface */
1343 memset(&ddsd, 0, sizeof(ddsd)); 1343 SDL_memset(&ddsd, 0, sizeof(ddsd));
1344 ddsd.dwSize = sizeof(ddsd); 1344 ddsd.dwSize = sizeof(ddsd);
1345 ddsd.dwFlags = DDSD_PIXELFORMAT|DDSD_CAPS; 1345 ddsd.dwFlags = DDSD_PIXELFORMAT|DDSD_CAPS;
1346 result = IDirectDrawSurface3_GetSurfaceDesc(SDL_primary, &ddsd); 1346 result = IDirectDrawSurface3_GetSurfaceDesc(SDL_primary, &ddsd);
1347 if ( result != DD_OK ) { 1347 if ( result != DD_OK ) {
1348 SetDDerror("DirectDrawSurface::GetSurfaceDesc", result); 1348 SetDDerror("DirectDrawSurface::GetSurfaceDesc", result);
1463 /* Necessary if we're going from fullscreen to window */ 1463 /* Necessary if we're going from fullscreen to window */
1464 if ( video->pixels == NULL ) { 1464 if ( video->pixels == NULL ) {
1465 video->pitch = (width*video->format->BytesPerPixel); 1465 video->pitch = (width*video->format->BytesPerPixel);
1466 /* Pitch needs to be QWORD (8-byte) aligned */ 1466 /* Pitch needs to be QWORD (8-byte) aligned */
1467 video->pitch = (video->pitch + 7) & ~7; 1467 video->pitch = (video->pitch + 7) & ~7;
1468 video->pixels = (void *)malloc(video->h*video->pitch); 1468 video->pixels = (void *)SDL_malloc(video->h*video->pitch);
1469 if ( video->pixels == NULL ) { 1469 if ( video->pixels == NULL ) {
1470 if ( video != current ) { 1470 if ( video != current ) {
1471 SDL_FreeSurface(video); 1471 SDL_FreeSurface(video);
1472 } 1472 }
1473 SDL_OutOfMemory(); 1473 SDL_OutOfMemory();
1491 video->flags |= SDL_NOFRAME; 1491 video->flags |= SDL_NOFRAME;
1492 } 1492 }
1493 } else { 1493 } else {
1494 /* Necessary if we're going from window to fullscreen */ 1494 /* Necessary if we're going from window to fullscreen */
1495 if ( video->pixels != NULL ) { 1495 if ( video->pixels != NULL ) {
1496 free(video->pixels); 1496 SDL_free(video->pixels);
1497 video->pixels = NULL; 1497 video->pixels = NULL;
1498 } 1498 }
1499 dd_surface3 = SDL_primary; 1499 dd_surface3 = SDL_primary;
1500 video->flags |= SDL_HWSURFACE; 1500 video->flags |= SDL_HWSURFACE;
1501 } 1501 }
1564 UINT swp_flags; 1564 UINT swp_flags;
1565 const char *window = NULL; 1565 const char *window = NULL;
1566 const char *center = NULL; 1566 const char *center = NULL;
1567 1567
1568 if ( !SDL_windowX && !SDL_windowY ) { 1568 if ( !SDL_windowX && !SDL_windowY ) {
1569 window = getenv("SDL_VIDEO_WINDOW_POS"); 1569 window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
1570 center = getenv("SDL_VIDEO_CENTERED"); 1570 center = SDL_getenv("SDL_VIDEO_CENTERED");
1571 if ( window ) { 1571 if ( window ) {
1572 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { 1572 if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {
1573 SDL_windowX = x; 1573 SDL_windowX = x;
1574 SDL_windowY = y; 1574 SDL_windowY = y;
1575 } 1575 }
1576 if ( strcmp(window, "center") == 0 ) { 1576 if ( SDL_strcmp(window, "center") == 0 ) {
1577 center = window; 1577 center = window;
1578 } 1578 }
1579 } 1579 }
1580 } 1580 }
1581 swp_flags = SWP_NOCOPYBITS; 1581 swp_flags = SWP_NOCOPYBITS;
1627 /* Clear the hardware flag, in case we fail */ 1627 /* Clear the hardware flag, in case we fail */
1628 surface->flags &= ~flag; 1628 surface->flags &= ~flag;
1629 1629
1630 /* Allocate the hardware acceleration data */ 1630 /* Allocate the hardware acceleration data */
1631 surface->hwdata = (struct private_hwdata *) 1631 surface->hwdata = (struct private_hwdata *)
1632 malloc(sizeof(*surface->hwdata)); 1632 SDL_malloc(sizeof(*surface->hwdata));
1633 if ( surface->hwdata == NULL ) { 1633 if ( surface->hwdata == NULL ) {
1634 SDL_OutOfMemory(); 1634 SDL_OutOfMemory();
1635 return(-1); 1635 return(-1);
1636 } 1636 }
1637 dd_surface3 = NULL; 1637 dd_surface3 = NULL;
1638 1638
1639 /* Set up the surface description */ 1639 /* Set up the surface description */
1640 memset(&ddsd, 0, sizeof(ddsd)); 1640 SDL_memset(&ddsd, 0, sizeof(ddsd));
1641 ddsd.dwSize = sizeof(ddsd); 1641 ddsd.dwSize = sizeof(ddsd);
1642 ddsd.dwFlags = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS| 1642 ddsd.dwFlags = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|
1643 DDSD_PITCH|DDSD_PIXELFORMAT); 1643 DDSD_PITCH|DDSD_PIXELFORMAT);
1644 ddsd.dwWidth = surface->w; 1644 ddsd.dwWidth = surface->w;
1645 ddsd.dwHeight= surface->h; 1645 ddsd.dwHeight= surface->h;
1718 } 1718 }
1719 1719
1720 } 1720 }
1721 1721
1722 /* Make sure the surface format was set properly */ 1722 /* Make sure the surface format was set properly */
1723 memset(&ddsd, 0, sizeof(ddsd)); 1723 SDL_memset(&ddsd, 0, sizeof(ddsd));
1724 ddsd.dwSize = sizeof(ddsd); 1724 ddsd.dwSize = sizeof(ddsd);
1725 result = IDirectDrawSurface3_Lock(dd_surface3, NULL, 1725 result = IDirectDrawSurface3_Lock(dd_surface3, NULL,
1726 &ddsd, (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL); 1726 &ddsd, (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
1727 if ( result != DD_OK ) { 1727 if ( result != DD_OK ) {
1728 SetDDerror("DirectDrawSurface3::Lock", result); 1728 SetDDerror("DirectDrawSurface3::Lock", result);
1802 */ 1802 */
1803 error_end: 1803 error_end:
1804 if ( (dd_surface3 != NULL) && (dd_surface3 != requested) ) { 1804 if ( (dd_surface3 != NULL) && (dd_surface3 != requested) ) {
1805 IDirectDrawSurface_Release(dd_surface3); 1805 IDirectDrawSurface_Release(dd_surface3);
1806 } 1806 }
1807 free(surface->hwdata); 1807 SDL_free(surface->hwdata);
1808 surface->hwdata = NULL; 1808 surface->hwdata = NULL;
1809 return(-1); 1809 return(-1);
1810 } 1810 }
1811 1811
1812 static int DX5_AllocHWSurface(_THIS, SDL_Surface *surface) 1812 static int DX5_AllocHWSurface(_THIS, SDL_Surface *surface)
1823 void PrintSurface(char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags) 1823 void PrintSurface(char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags)
1824 { 1824 {
1825 DDSURFACEDESC ddsd; 1825 DDSURFACEDESC ddsd;
1826 1826
1827 /* Lock and load! */ 1827 /* Lock and load! */
1828 memset(&ddsd, 0, sizeof(ddsd)); 1828 SDL_memset(&ddsd, 0, sizeof(ddsd));
1829 ddsd.dwSize = sizeof(ddsd); 1829 ddsd.dwSize = sizeof(ddsd);
1830 if ( IDirectDrawSurface3_Lock(surface, NULL, &ddsd, 1830 if ( IDirectDrawSurface3_Lock(surface, NULL, &ddsd,
1831 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL) != DD_OK ) { 1831 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL) != DD_OK ) {
1832 return; 1832 return;
1833 } 1833 }
2011 LPDIRECTDRAWSURFACE3 dd_surface; 2011 LPDIRECTDRAWSURFACE3 dd_surface;
2012 DDSURFACEDESC ddsd; 2012 DDSURFACEDESC ddsd;
2013 2013
2014 /* Lock and load! */ 2014 /* Lock and load! */
2015 dd_surface = surface->hwdata->dd_writebuf; 2015 dd_surface = surface->hwdata->dd_writebuf;
2016 memset(&ddsd, 0, sizeof(ddsd)); 2016 SDL_memset(&ddsd, 0, sizeof(ddsd));
2017 ddsd.dwSize = sizeof(ddsd); 2017 ddsd.dwSize = sizeof(ddsd);
2018 result = IDirectDrawSurface3_Lock(dd_surface, NULL, &ddsd, 2018 result = IDirectDrawSurface3_Lock(dd_surface, NULL, &ddsd,
2019 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL); 2019 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
2020 if ( result == DDERR_SURFACELOST ) { 2020 if ( result == DDERR_SURFACELOST ) {
2021 result = IDirectDrawSurface3_Restore( 2021 result = IDirectDrawSurface3_Restore(
2079 { 2079 {
2080 if ( surface->hwdata ) { 2080 if ( surface->hwdata ) {
2081 if ( surface->hwdata->dd_surface != SDL_primary ) { 2081 if ( surface->hwdata->dd_surface != SDL_primary ) {
2082 IDirectDrawSurface3_Release(surface->hwdata->dd_surface); 2082 IDirectDrawSurface3_Release(surface->hwdata->dd_surface);
2083 } 2083 }
2084 free(surface->hwdata); 2084 SDL_free(surface->hwdata);
2085 surface->hwdata = NULL; 2085 surface->hwdata = NULL;
2086 } 2086 }
2087 } 2087 }
2088 2088
2089 void DX5_WindowUpdate(_THIS, int numrects, SDL_Rect *rects) 2089 void DX5_WindowUpdate(_THIS, int numrects, SDL_Rect *rects)
2175 if ( pool == NULL ) { 2175 if ( pool == NULL ) {
2176 /* No worries, just return */; 2176 /* No worries, just return */;
2177 return; 2177 return;
2178 } 2178 }
2179 seen = pool; 2179 seen = pool;
2180 memset(seen, 0, ncolors*sizeof(int)); 2180 SDL_memset(seen, 0, ncolors*sizeof(int));
2181 order = pool+ncolors; 2181 order = pool+ncolors;
2182 2182
2183 /* Start with the brightest color */ 2183 /* Start with the brightest color */
2184 max = 0; 2184 max = 0;
2185 for ( i=0; i<ncolors; ++i ) { 2185 for ( i=0; i<ncolors; ++i ) {
2285 SetDDerror("DirectDrawSurface3::QueryInterface(GAMMA)", result); 2285 SetDDerror("DirectDrawSurface3::QueryInterface(GAMMA)", result);
2286 return(-1); 2286 return(-1);
2287 } 2287 }
2288 2288
2289 /* Set up the gamma ramp */ 2289 /* Set up the gamma ramp */
2290 memcpy(gamma_ramp.red, &ramp[0*256], 256*sizeof(*ramp)); 2290 SDL_memcpy(gamma_ramp.red, &ramp[0*256], 256*sizeof(*ramp));
2291 memcpy(gamma_ramp.green, &ramp[1*256], 256*sizeof(*ramp)); 2291 SDL_memcpy(gamma_ramp.green, &ramp[1*256], 256*sizeof(*ramp));
2292 memcpy(gamma_ramp.blue, &ramp[2*256], 256*sizeof(*ramp)); 2292 SDL_memcpy(gamma_ramp.blue, &ramp[2*256], 256*sizeof(*ramp));
2293 result = IDirectDrawGammaControl_SetGammaRamp(gamma, 0, &gamma_ramp); 2293 result = IDirectDrawGammaControl_SetGammaRamp(gamma, 0, &gamma_ramp);
2294 if ( result != DD_OK ) { 2294 if ( result != DD_OK ) {
2295 SetDDerror("DirectDrawGammaControl::SetGammaRamp()", result); 2295 SetDDerror("DirectDrawGammaControl::SetGammaRamp()", result);
2296 } 2296 }
2297 2297
2333 } 2333 }
2334 2334
2335 /* Set up the gamma ramp */ 2335 /* Set up the gamma ramp */
2336 result = IDirectDrawGammaControl_GetGammaRamp(gamma, 0, &gamma_ramp); 2336 result = IDirectDrawGammaControl_GetGammaRamp(gamma, 0, &gamma_ramp);
2337 if ( result == DD_OK ) { 2337 if ( result == DD_OK ) {
2338 memcpy(&ramp[0*256], gamma_ramp.red, 256*sizeof(*ramp)); 2338 SDL_memcpy(&ramp[0*256], gamma_ramp.red, 256*sizeof(*ramp));
2339 memcpy(&ramp[1*256], gamma_ramp.green, 256*sizeof(*ramp)); 2339 SDL_memcpy(&ramp[1*256], gamma_ramp.green, 256*sizeof(*ramp));
2340 memcpy(&ramp[2*256], gamma_ramp.blue, 256*sizeof(*ramp)); 2340 SDL_memcpy(&ramp[2*256], gamma_ramp.blue, 256*sizeof(*ramp));
2341 } else { 2341 } else {
2342 SetDDerror("DirectDrawGammaControl::GetGammaRamp()", result); 2342 SetDDerror("DirectDrawGammaControl::GetGammaRamp()", result);
2343 } 2343 }
2344 2344
2345 /* Release the interface and return */ 2345 /* Release the interface and return */
2389 2389
2390 /* Free video mode lists */ 2390 /* Free video mode lists */
2391 for ( i=0; i<NUM_MODELISTS; ++i ) { 2391 for ( i=0; i<NUM_MODELISTS; ++i ) {
2392 if ( SDL_modelist[i] != NULL ) { 2392 if ( SDL_modelist[i] != NULL ) {
2393 for ( j=0; SDL_modelist[i][j]; ++j ) 2393 for ( j=0; SDL_modelist[i][j]; ++j )
2394 free(SDL_modelist[i][j]); 2394 SDL_free(SDL_modelist[i][j]);
2395 free(SDL_modelist[i]); 2395 SDL_free(SDL_modelist[i]);
2396 SDL_modelist[i] = NULL; 2396 SDL_modelist[i] = NULL;
2397 } 2397 }
2398 } 2398 }
2399 2399
2400 /* Free the window */ 2400 /* Free the window */
2464 hdc = GetDC(window); 2464 hdc = GetDC(window);
2465 GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries); 2465 GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries);
2466 ReleaseDC(window, hdc); 2466 ReleaseDC(window, hdc);
2467 if ( ! colorchange_expected ) { 2467 if ( ! colorchange_expected ) {
2468 saved = SDL_stack_alloc(SDL_Color, palette->ncolors); 2468 saved = SDL_stack_alloc(SDL_Color, palette->ncolors);
2469 memcpy(saved, palette->colors, 2469 SDL_memcpy(saved, palette->colors,
2470 palette->ncolors*sizeof(SDL_Color)); 2470 palette->ncolors*sizeof(SDL_Color));
2471 } 2471 }
2472 for ( i=0; i<palette->ncolors; ++i ) { 2472 for ( i=0; i<palette->ncolors; ++i ) {
2473 palette->colors[i].r = entries[i].peRed; 2473 palette->colors[i].r = entries[i].peRed;
2474 palette->colors[i].g = entries[i].peGreen; 2474 palette->colors[i].g = entries[i].peGreen;
2476 } 2476 }
2477 SDL_stack_free(entries); 2477 SDL_stack_free(entries);
2478 if ( ! colorchange_expected ) { 2478 if ( ! colorchange_expected ) {
2479 Uint8 mapping[256]; 2479 Uint8 mapping[256];
2480 2480
2481 memset(mapping, 0, sizeof(mapping)); 2481 SDL_memset(mapping, 0, sizeof(mapping));
2482 for ( i=0; i<palette->ncolors; ++i ) { 2482 for ( i=0; i<palette->ncolors; ++i ) {
2483 mapping[i] = SDL_FindColor(palette, 2483 mapping[i] = SDL_FindColor(palette,
2484 saved[i].r, saved[i].g, saved[i].b); 2484 saved[i].r, saved[i].g, saved[i].b);
2485 } 2485 }
2486 DX5_Recolor8Bit(this, SDL_VideoSurface, mapping); 2486 DX5_Recolor8Bit(this, SDL_VideoSurface, mapping);