comparison src/video/os2fslib/SDL_os2fslib.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 173c063d4f55
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
1167 { 1167 {
1168 if (cursor) 1168 if (cursor)
1169 { 1169 {
1170 GpiDeleteBitmap(cursor->hbm); 1170 GpiDeleteBitmap(cursor->hbm);
1171 WinDestroyPointer(cursor->hptr); 1171 WinDestroyPointer(cursor->hptr);
1172 free(cursor->pchData); 1172 SDL_free(cursor->pchData);
1173 free(cursor); 1173 SDL_free(cursor);
1174 } 1174 }
1175 } 1175 }
1176 1176
1177 /* Local functions to convert the SDL cursor mask into OS/2 format */ 1177 /* Local functions to convert the SDL cursor mask into OS/2 format */
1178 static void memnot(Uint8 *dst, Uint8 *src, int len) 1178 static void memnot(Uint8 *dst, Uint8 *src, int len)
1206 1206
1207 // Check for max size! 1207 // Check for max size!
1208 if ((w>maxx) || (h>maxy)) 1208 if ((w>maxx) || (h>maxy))
1209 return (WMcursor *) NULL; 1209 return (WMcursor *) NULL;
1210 1210
1211 pResult = (WMcursor *) malloc(sizeof(WMcursor)); 1211 pResult = (WMcursor *) SDL_malloc(sizeof(WMcursor));
1212 if (!pResult) return (WMcursor *) NULL; 1212 if (!pResult) return (WMcursor *) NULL;
1213 1213
1214 pchTemp = (char *) malloc((maxx + 7)/8 * maxy*2); 1214 pchTemp = (char *) SDL_malloc((maxx + 7)/8 * maxy*2);
1215 if (!pchTemp) 1215 if (!pchTemp)
1216 { 1216 {
1217 free(pResult); 1217 SDL_free(pResult);
1218 return (WMcursor *) NULL; 1218 return (WMcursor *) NULL;
1219 } 1219 }
1220 1220
1221 memset(pchTemp, 0, (maxx + 7)/8 * maxy*2); 1221 SDL_memset(pchTemp, 0, (maxx + 7)/8 * maxy*2);
1222 1222
1223 hps = WinGetPS(_this->hidden->hwndClient); 1223 hps = WinGetPS(_this->hidden->hwndClient);
1224 1224
1225 bmi.cbFix = sizeof(BITMAPINFOHEADER); 1225 bmi.cbFix = sizeof(BITMAPINFOHEADER);
1226 bmi.cx = maxx; 1226 bmi.cx = maxx;
1232 bmi.argbColor[0].bRed = 0x00; 1232 bmi.argbColor[0].bRed = 0x00;
1233 bmi.argbColor[1].bBlue = 0x00; 1233 bmi.argbColor[1].bBlue = 0x00;
1234 bmi.argbColor[1].bGreen = 0x00; 1234 bmi.argbColor[1].bGreen = 0x00;
1235 bmi.argbColor[1].bRed = 0xff; 1235 bmi.argbColor[1].bRed = 0xff;
1236 1236
1237 memset(&bmih, 0, sizeof(BITMAPINFOHEADER)); 1237 SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
1238 bmih.cbFix = sizeof(BITMAPINFOHEADER); 1238 bmih.cbFix = sizeof(BITMAPINFOHEADER);
1239 bmih.cx = maxx; 1239 bmih.cx = maxx;
1240 bmih.cy = 2*maxy; 1240 bmih.cy = 2*maxy;
1241 bmih.cPlanes = 1; 1241 bmih.cPlanes = 1;
1242 bmih.cBitCount = 1; 1242 bmih.cBitCount = 1;
1252 xptr += run; 1252 xptr += run;
1253 data += run; 1253 data += run;
1254 memnot(aptr, mask, run); 1254 memnot(aptr, mask, run);
1255 mask += run; 1255 mask += run;
1256 aptr += run; 1256 aptr += run;
1257 memset(xptr, 0, pad); 1257 SDL_memset(xptr, 0, pad);
1258 xptr += pad; 1258 xptr += pad;
1259 memset(aptr, ~0, pad); 1259 SDL_memset(aptr, ~0, pad);
1260 aptr += pad; 1260 aptr += pad;
1261 } 1261 }
1262 pad += run; 1262 pad += run;
1263 for (i=h ; i<maxy; i++ ) 1263 for (i=h ; i<maxy; i++ )
1264 { 1264 {
1265 xptr = pchTemp + (maxx+7)/8 * (maxy-1-i); 1265 xptr = pchTemp + (maxx+7)/8 * (maxy-1-i);
1266 aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i); 1266 aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i);
1267 1267
1268 memset(xptr, 0, (maxx+7)/8); 1268 SDL_memset(xptr, 0, (maxx+7)/8);
1269 xptr += (maxx+7)/8; 1269 xptr += (maxx+7)/8;
1270 memset(aptr, ~0, (maxx+7)/8); 1270 SDL_memset(aptr, ~0, (maxx+7)/8);
1271 aptr += (maxx+7)/8; 1271 aptr += (maxx+7)/8;
1272 } 1272 }
1273 1273
1274 hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT, (PBYTE) pchTemp, (PBITMAPINFO2)&bmi); 1274 hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT, (PBYTE) pchTemp, (PBITMAPINFO2)&bmi);
1275 hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE, hot_x, maxy - hot_y - 1); 1275 hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE, hot_x, maxy - hot_y - 1);
1505 1505
1506 // Check for max size! 1506 // Check for max size!
1507 if ((w>maxx) || (h>maxy)) 1507 if ((w>maxx) || (h>maxy))
1508 return; 1508 return;
1509 1509
1510 pchTemp = (char *) malloc(w * h*2 * 4); 1510 pchTemp = (char *) SDL_malloc(w * h*2 * 4);
1511 if (!pchTemp) 1511 if (!pchTemp)
1512 return; 1512 return;
1513 1513
1514 memset(pchTemp, 0, w * h*2 * 4); 1514 SDL_memset(pchTemp, 0, w * h*2 * 4);
1515 1515
1516 // Convert surface to RGB, if it's not RGB yet! 1516 // Convert surface to RGB, if it's not RGB yet!
1517 icon_rgb = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h, 1517 icon_rgb = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
1518 32, 0, 0, 0, 0); 1518 32, 0, 0, 0, 0);
1519 if ( icon_rgb == NULL ) 1519 if ( icon_rgb == NULL )
1520 { 1520 {
1521 free(pchTemp); 1521 SDL_free(pchTemp);
1522 return; 1522 return;
1523 } 1523 }
1524 bounds.x = 0; 1524 bounds.x = 0;
1525 bounds.y = 0; 1525 bounds.y = 0;
1526 bounds.w = icon->w; 1526 bounds.w = icon->w;
1527 bounds.h = icon->h; 1527 bounds.h = icon->h;
1528 if ( SDL_LowerBlit(icon, &bounds, icon_rgb, &bounds) < 0 ) 1528 if ( SDL_LowerBlit(icon, &bounds, icon_rgb, &bounds) < 0 )
1529 { 1529 {
1530 SDL_FreeSurface(icon_rgb); 1530 SDL_FreeSurface(icon_rgb);
1531 free(pchTemp); 1531 SDL_free(pchTemp);
1532 return; 1532 return;
1533 } 1533 }
1534 1534
1535 /* Copy pixels upside-down from RGB surface into BMP, masked with the icon mask */ 1535 /* Copy pixels upside-down from RGB surface into BMP, masked with the icon mask */
1536 1536
1594 bmi.cx = w; 1594 bmi.cx = w;
1595 bmi.cy = 2*h; 1595 bmi.cy = 2*h;
1596 bmi.cPlanes = 1; 1596 bmi.cPlanes = 1;
1597 bmi.cBitCount = 32; 1597 bmi.cBitCount = 32;
1598 1598
1599 memset(&bmih, 0, sizeof(BITMAPINFOHEADER)); 1599 SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
1600 bmih.cbFix = sizeof(BITMAPINFOHEADER); 1600 bmih.cbFix = sizeof(BITMAPINFOHEADER);
1601 bmih.cx = w; 1601 bmih.cx = w;
1602 bmih.cy = 2*h; 1602 bmih.cy = 2*h;
1603 bmih.cPlanes = 1; 1603 bmih.cPlanes = 1;
1604 bmih.cBitCount = 32; 1604 bmih.cBitCount = 32;
1607 hptrIcon = WinCreatePointer(HWND_DESKTOP, hbm, FALSE, 0, 0); 1607 hptrIcon = WinCreatePointer(HWND_DESKTOP, hbm, FALSE, 0, 0);
1608 1608
1609 WinReleasePS(hps); 1609 WinReleasePS(hps);
1610 1610
1611 // Free pixel array 1611 // Free pixel array
1612 free(pchTemp); 1612 SDL_free(pchTemp);
1613 1613
1614 // Change icon in frame window 1614 // Change icon in frame window
1615 WinSendMsg(hwndFrame, 1615 WinSendMsg(hwndFrame,
1616 WM_SETICON, 1616 WM_SETICON,
1617 (MPARAM) hptrIcon, 1617 (MPARAM) hptrIcon,
2114 2114
2115 // Free result of an old ListModes() call, because there is 2115 // Free result of an old ListModes() call, because there is
2116 // no FreeListModes() call in SDL! 2116 // no FreeListModes() call in SDL!
2117 if (_this->hidden->pListModesResult) 2117 if (_this->hidden->pListModesResult)
2118 { 2118 {
2119 free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL; 2119 SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL;
2120 } 2120 }
2121 2121
2122 // Free list of available fullscreen modes 2122 // Free list of available fullscreen modes
2123 if (_this->hidden->pAvailableFSLibVideoModes) 2123 if (_this->hidden->pAvailableFSLibVideoModes)
2124 { 2124 {
2252 printf("[os2fslib_SetVideoMode] : Found mode!\n"); fflush(stdout); 2252 printf("[os2fslib_SetVideoMode] : Found mode!\n"); fflush(stdout);
2253 #endif 2253 #endif
2254 2254
2255 // We'll possibly adjust the structure, so copy out the values 2255 // We'll possibly adjust the structure, so copy out the values
2256 // into TempModeInfo! 2256 // into TempModeInfo!
2257 memcpy(&TempModeInfo, pModeInfoFound, sizeof(TempModeInfo)); 2257 SDL_memcpy(&TempModeInfo, pModeInfoFound, sizeof(TempModeInfo));
2258 pModeInfoFound = &TempModeInfo; 2258 pModeInfoFound = &TempModeInfo;
2259 2259
2260 if (flags & SDL_RESIZABLE) 2260 if (flags & SDL_RESIZABLE)
2261 { 2261 {
2262 #ifdef DEBUG_BUILD 2262 #ifdef DEBUG_BUILD
2333 // It might be that the software surface pitch is not the same as 2333 // It might be that the software surface pitch is not the same as
2334 // the pitch we have, so adjust that! 2334 // the pitch we have, so adjust that!
2335 pModeInfoFound->uiScanLineSize = pResult->pitch; 2335 pModeInfoFound->uiScanLineSize = pResult->pitch;
2336 2336
2337 // Store new source buffer parameters! 2337 // Store new source buffer parameters!
2338 memcpy(&(_this->hidden->SrcBufferDesc), pModeInfoFound, sizeof(*pModeInfoFound)); 2338 SDL_memcpy(&(_this->hidden->SrcBufferDesc), pModeInfoFound, sizeof(*pModeInfoFound));
2339 _this->hidden->pchSrcBuffer = pResult->pixels; 2339 _this->hidden->pchSrcBuffer = pResult->pixels;
2340 2340
2341 #ifdef DEBUG_BUILD 2341 #ifdef DEBUG_BUILD
2342 printf("[os2fslib_SetVideoMode] : Telling FSLib the stuffs\n"); fflush(stdout); 2342 printf("[os2fslib_SetVideoMode] : Telling FSLib the stuffs\n"); fflush(stdout);
2343 #endif 2343 #endif
2444 printf("[os2fslib_ListModes] : ListModes of %d Bpp\n", format->BitsPerPixel); 2444 printf("[os2fslib_ListModes] : ListModes of %d Bpp\n", format->BitsPerPixel);
2445 #endif 2445 #endif
2446 // Destroy result of previous call, if there is any 2446 // Destroy result of previous call, if there is any
2447 if (_this->hidden->pListModesResult) 2447 if (_this->hidden->pListModesResult)
2448 { 2448 {
2449 free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL; 2449 SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL;
2450 } 2450 }
2451 2451
2452 // For resizable and windowed mode we support every resolution! 2452 // For resizable and windowed mode we support every resolution!
2453 if ((flags & SDL_RESIZABLE) && ((flags & SDL_FULLSCREEN) == 0)) 2453 if ((flags & SDL_RESIZABLE) && ((flags & SDL_FULLSCREEN) == 0))
2454 return (SDL_Rect **)-1; 2454 return (SDL_Rect **)-1;
2467 pFSMode = _this->hidden->pAvailableFSLibVideoModes; 2467 pFSMode = _this->hidden->pAvailableFSLibVideoModes;
2468 while (pFSMode) 2468 while (pFSMode)
2469 { 2469 {
2470 if (pFSMode->uiBPP == format->BitsPerPixel) 2470 if (pFSMode->uiBPP == format->BitsPerPixel)
2471 { 2471 {
2472 SDL_Rect *pRect = (SDL_Rect *) malloc(sizeof(SDL_Rect)); 2472 SDL_Rect *pRect = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
2473 if (pRect) 2473 if (pRect)
2474 { 2474 {
2475 // Fill description 2475 // Fill description
2476 pRect->x = 0; 2476 pRect->x = 0;
2477 pRect->y = 0; 2477 pRect->y = 0;
2487 #ifdef DEBUG_BUILD 2487 #ifdef DEBUG_BUILD
2488 // printf("!!! Inserting to beginning\n"); 2488 // printf("!!! Inserting to beginning\n");
2489 #endif 2489 #endif
2490 2490
2491 // We're the first one to be inserted! 2491 // We're the first one to be inserted!
2492 _this->hidden->pListModesResult = (SDL_Rect**) malloc(2*sizeof(SDL_Rect*)); 2492 _this->hidden->pListModesResult = (SDL_Rect**) SDL_malloc(2*sizeof(SDL_Rect*));
2493 if (_this->hidden->pListModesResult) 2493 if (_this->hidden->pListModesResult)
2494 { 2494 {
2495 _this->hidden->pListModesResult[0] = pRect; 2495 _this->hidden->pListModesResult[0] = pRect;
2496 _this->hidden->pListModesResult[1] = NULL; 2496 _this->hidden->pListModesResult[1] = NULL;
2497 } else 2497 } else
2498 { 2498 {
2499 free(pRect); 2499 SDL_free(pRect);
2500 } 2500 }
2501 } else 2501 } else
2502 { 2502 {
2503 // We're not the first ones, so find the place where we 2503 // We're not the first ones, so find the place where we
2504 // have to insert ourselves 2504 // have to insert ourselves
2526 2526
2527 #ifdef DEBUG_BUILD 2527 #ifdef DEBUG_BUILD
2528 // printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace); 2528 // printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace);
2529 #endif 2529 #endif
2530 2530
2531 pNewList = (SDL_Rect**) realloc(_this->hidden->pListModesResult, (iNumOfSlots+1)*sizeof(SDL_Rect*)); 2531 pNewList = (SDL_Rect**) SDL_realloc(_this->hidden->pListModesResult, (iNumOfSlots+1)*sizeof(SDL_Rect*));
2532 if (pNewList) 2532 if (pNewList)
2533 { 2533 {
2534 for (i=iNumOfSlots;i>iPlace;i--) 2534 for (i=iNumOfSlots;i>iPlace;i--)
2535 pNewList[i] = pNewList[i-1]; 2535 pNewList[i] = pNewList[i-1];
2536 pNewList[iPlace] = pRect; 2536 pNewList[iPlace] = pRect;
2537 _this->hidden->pListModesResult = pNewList; 2537 _this->hidden->pListModesResult = pNewList;
2538 } else 2538 } else
2539 { 2539 {
2540 free(pRect); 2540 SDL_free(pRect);
2541 } 2541 }
2542 } 2542 }
2543 } 2543 }
2544 } 2544 }
2545 pFSMode = pFSMode->pNext; 2545 pFSMode = pFSMode->pNext;
2609 2609
2610 // Now create our window with a default size 2610 // Now create our window with a default size
2611 2611
2612 // For this, we select the first available fullscreen mode as 2612 // For this, we select the first available fullscreen mode as
2613 // current window size! 2613 // current window size!
2614 memcpy(&(_this->hidden->SrcBufferDesc), _this->hidden->pAvailableFSLibVideoModes, sizeof(_this->hidden->SrcBufferDesc)); 2614 SDL_memcpy(&(_this->hidden->SrcBufferDesc), _this->hidden->pAvailableFSLibVideoModes, sizeof(_this->hidden->SrcBufferDesc));
2615 // Allocate new video buffer! 2615 // Allocate new video buffer!
2616 _this->hidden->pchSrcBuffer = (char *) malloc(_this->hidden->pAvailableFSLibVideoModes->uiScanLineSize * _this->hidden->pAvailableFSLibVideoModes->uiYResolution); 2616 _this->hidden->pchSrcBuffer = (char *) SDL_malloc(_this->hidden->pAvailableFSLibVideoModes->uiScanLineSize * _this->hidden->pAvailableFSLibVideoModes->uiYResolution);
2617 if (!_this->hidden->pchSrcBuffer) 2617 if (!_this->hidden->pchSrcBuffer)
2618 { 2618 {
2619 #ifdef DEBUG_BUILD 2619 #ifdef DEBUG_BUILD
2620 printf("[os2fslib_VideoInit] : Yikes, not enough memory for new video buffer!\n"); fflush(stdout); 2620 printf("[os2fslib_VideoInit] : Yikes, not enough memory for new video buffer!\n"); fflush(stdout);
2621 #endif 2621 #endif
2664 printf("[os2fslib_DeleteDevice]\n"); fflush(stdout); 2664 printf("[os2fslib_DeleteDevice]\n"); fflush(stdout);
2665 #endif 2665 #endif
2666 // Free used memory 2666 // Free used memory
2667 FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes); 2667 FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes);
2668 if (_this->hidden->pListModesResult) 2668 if (_this->hidden->pListModesResult)
2669 free(_this->hidden->pListModesResult); 2669 SDL_free(_this->hidden->pListModesResult);
2670 if (_this->hidden->pchSrcBuffer) 2670 if (_this->hidden->pchSrcBuffer)
2671 free(_this->hidden->pchSrcBuffer); 2671 SDL_free(_this->hidden->pchSrcBuffer);
2672 DosCloseMutexSem(_this->hidden->hmtxUseSrcBuffer); 2672 DosCloseMutexSem(_this->hidden->hmtxUseSrcBuffer);
2673 free(_this->hidden); 2673 SDL_free(_this->hidden);
2674 free(_this); 2674 SDL_free(_this);
2675 FSLib_Uninitialize(); 2675 FSLib_Uninitialize();
2676 } 2676 }
2677 2677
2678 static int os2fslib_Available(void) 2678 static int os2fslib_Available(void)
2679 { 2679 {
2701 #ifdef DEBUG_BUILD 2701 #ifdef DEBUG_BUILD
2702 printf("[os2fslib_CreateDevice] : Enter\n"); fflush(stdout); 2702 printf("[os2fslib_CreateDevice] : Enter\n"); fflush(stdout);
2703 #endif 2703 #endif
2704 2704
2705 /* Initialize all variables that we clean on shutdown */ 2705 /* Initialize all variables that we clean on shutdown */
2706 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); 2706 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
2707 if ( device ) 2707 if ( device )
2708 { 2708 {
2709 memset(device, 0, (sizeof *device)); 2709 SDL_memset(device, 0, (sizeof *device));
2710 // Also allocate memory for private data 2710 // Also allocate memory for private data
2711 device->hidden = (struct SDL_PrivateVideoData *) malloc((sizeof(struct SDL_PrivateVideoData))); 2711 device->hidden = (struct SDL_PrivateVideoData *) SDL_malloc((sizeof(struct SDL_PrivateVideoData)));
2712 } 2712 }
2713 if ( (device == NULL) || (device->hidden == NULL) ) 2713 if ( (device == NULL) || (device->hidden == NULL) )
2714 { 2714 {
2715 SDL_OutOfMemory(); 2715 SDL_OutOfMemory();
2716 if ( device ) 2716 if ( device )
2717 free(device); 2717 SDL_free(device);
2718 return NULL; 2718 return NULL;
2719 } 2719 }
2720 memset(device->hidden, 0, (sizeof *device->hidden)); 2720 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
2721 2721
2722 /* Set the function pointers */ 2722 /* Set the function pointers */
2723 #ifdef DEBUG_BUILD 2723 #ifdef DEBUG_BUILD
2724 printf("[os2fslib_CreateDevice] : VideoInit is %p\n", os2fslib_VideoInit); fflush(stdout); 2724 printf("[os2fslib_CreateDevice] : VideoInit is %p\n", os2fslib_VideoInit); fflush(stdout);
2725 #endif 2725 #endif
2768 // Could not initialize FSLib! 2768 // Could not initialize FSLib!
2769 #ifdef DEBUG_BUILD 2769 #ifdef DEBUG_BUILD
2770 printf("[os2fslib_CreateDevice] : Could not initialize FSLib!\n"); 2770 printf("[os2fslib_CreateDevice] : Could not initialize FSLib!\n");
2771 #endif 2771 #endif
2772 SDL_SetError("Could not initialize FSLib!"); 2772 SDL_SetError("Could not initialize FSLib!");
2773 free(device->hidden); 2773 SDL_free(device->hidden);
2774 free(device); 2774 SDL_free(device);
2775 return NULL; 2775 return NULL;
2776 } 2776 }
2777 device->hidden->pAvailableFSLibVideoModes = 2777 device->hidden->pAvailableFSLibVideoModes =
2778 FSLib_GetVideoModeList(); 2778 FSLib_GetVideoModeList();
2779 2779