--- hatari/src/falcon/hostscreen.c 2019/04/01 07:13:46 1.1 +++ hatari/src/falcon/hostscreen.c 2019/04/09 08:47:21 1.1.1.4 @@ -8,15 +8,17 @@ has been thoroughly reworked for Hatari. However, integration with the rest of the Hatari source code is still bad and needs a lot of improvement... */ -const char HostScreen_rcsid[] = "Hatari $Id: hostscreen.c,v 1.1 2019/04/01 07:13:46 root Exp $"; +const char HostScreen_fileid[] = "Hatari hostscreen.c : " __DATE__ " " __TIME__; #include "main.h" #include "configuration.h" +#include "control.h" #include "sysdeps.h" #include "stMemory.h" #include "ioMem.h" #include "hostscreen.h" #include "screen.h" +#include "statusbar.h" #define VIDEL_DEBUG 0 @@ -49,14 +51,13 @@ static SDL_Surface *mainSurface; static SDL_Surface *surf; // pointer to actual surface -static SDL_mutex *screenLock; -static uint32 sdl_videoparams; -static uint32 hs_width, hs_height, hs_bpp; -static BOOL doUpdate; // the HW surface is available -> the SDL need not to update the surface after ->pixel access +static Uint32 sdl_videoparams; +static Uint32 hs_width, hs_height, hs_bpp; +static bool doUpdate; // the HW surface is available -> the SDL need not to update the surface after ->pixel access static struct { // TOS palette (bpp < 16) to SDL color mapping SDL_Color standard[256]; - uint32 native[256]; + Uint32 native[256]; } palette; @@ -67,11 +68,12 @@ static const unsigned long default_palet RGB_LTBLUE, RGB_LTMAGENTA, RGB_LTCYAN, RGB_BLACK }; -static int HostScreen_selectVideoMode(SDL_Rect **modes, uint32 *width, uint32 *height); -static void HostScreen_searchVideoMode( uint32 *width, uint32 *height, uint32 *bpp ); +static int HostScreen_selectVideoMode(SDL_Rect **modes, Uint32 *width, Uint32 *height); +static void HostScreen_searchVideoMode( Uint32 *width, Uint32 *height, Uint32 *bpp ); -void HostScreen_Init(void) { +void HostScreen_Init(void) +{ int i; for(i=0; i<256; i++) { unsigned long color = default_palette[i%16]; @@ -80,19 +82,21 @@ void HostScreen_Init(void) { palette.standard[i].b = color & 0xff; } - screenLock = SDL_CreateMutex(); - mainSurface=NULL; } -void HostScreen_UnInit(void) { - SDL_DestroyMutex(screenLock); +void HostScreen_UnInit(void) +{ } void HostScreen_toggleFullScreen(void) { sdl_videoparams ^= SDL_FULLSCREEN; + if (sdl_videoparams & SDL_FULLSCREEN) { + /* un-embed the Hatari WM window for fullscreen */ + Control_ReparentWindow(hs_width, hs_height, true); + } if(SDL_WM_ToggleFullScreen(mainSurface) == 0) { // SDL_WM_ToggleFullScreen() did not work. // We have to change video mode "by hand". @@ -101,29 +105,34 @@ void HostScreen_toggleFullScreen(void) Dprintf(("toggleFullScreen: SDL_WM_ToggleFullScreen() not supported" " -> using SDL_SetVideoMode()")); if (temp == NULL) - bug("toggleFullScreen: Unable to save screen content."); + Dprintf(("toggleFullScreen: Unable to save screen content.")); #if 1 HostScreen_setWindowSize(hs_width, hs_height, hs_bpp); #else mainSurface = SDL_SetVideoMode(width, height, bpp, sdl_videoparams); if (mainSurface == NULL) - bug("toggleFullScreen: Unable to set new video mode."); + Dprintf(("toggleFullScreen: Unable to set new video mode.")); if (mainSurface->format->BitsPerPixel <= 8) SDL_SetColors(mainSurface, temp->format->palette->colors, 0, temp->format->palette->ncolors); #endif if (SDL_BlitSurface(temp, NULL, mainSurface, NULL) != 0) - bug("toggleFullScreen: Unable to restore screen content."); + Dprintf(("toggleFullScreen: Unable to restore screen content.")); SDL_FreeSurface(temp); /* refresh the screen */ - HostScreen_update1(TRUE); + HostScreen_update1(true); + } else { + if (!(sdl_videoparams & SDL_FULLSCREEN)) { + /* re-embed the new Hatari SDL window */ + Control_ReparentWindow(hs_width, hs_height, false); + } } } -static int HostScreen_selectVideoMode(SDL_Rect **modes, uint32 *width, uint32 *height) +static int HostScreen_selectVideoMode(SDL_Rect **modes, Uint32 *width, Uint32 *height) { int i, bestw, besth; @@ -146,7 +155,7 @@ static int HostScreen_selectVideoMode(SD return 1; } -static void HostScreen_searchVideoMode( uint32 *width, uint32 *height, uint32 *bpp ) +static void HostScreen_searchVideoMode( Uint32 *width, Uint32 *height, Uint32 *bpp ) { SDL_Rect **modes; SDL_PixelFormat pixelformat; @@ -200,46 +209,60 @@ static void HostScreen_searchVideoMode( Dprintf(("hostscreen: video mode selected: %dx%dx%d\n",*width,*height,*bpp)); } -void HostScreen_setWindowSize( uint32 width, uint32 height, uint32 bpp ) +void HostScreen_setWindowSize( Uint32 width, Uint32 height, Uint32 bpp ) { + Uint32 screenheight; + + if (bpp == 24) + bpp = 32; + nScreenZoomX = 1; nScreenZoomY = 1; if (ConfigureParams.Screen.bZoomLowRes) { /* Ugly: 400x300 threshold is currently hard-coded. */ /* Should rather be selectable by the user! */ - if (width <= 400) + if (width && width <= 400) { nScreenZoomX = (800/width); width *= nScreenZoomX; } - if (height <= 300) + if (height && height <= 300) { nScreenZoomY = (550/height); height *= nScreenZoomY; } } + screenheight = height + Statusbar_SetHeight(width, height); // Select a correct video mode - HostScreen_searchVideoMode(&width, &height, &bpp); + HostScreen_searchVideoMode(&width, &screenheight, &bpp); - hs_width = width; + hs_width = width; hs_height = height; hs_bpp = bpp; // SelectVideoMode(); - if (bInFullScreen) + if (bInFullScreen) { + /* un-embed the Hatari WM window for fullscreen */ + Control_ReparentWindow(width, screenheight, bInFullScreen); + sdl_videoparams = SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN; - else + } else { sdl_videoparams = SDL_SWSURFACE|SDL_HWPALETTE; - - mainSurface = SDL_SetVideoMode(width, height, bpp, sdl_videoparams); - + } + mainSurface = SDL_SetVideoMode(width, screenheight, bpp, sdl_videoparams); + if (!bInFullScreen) { + /* re-embed the new Hatari SDL window */ + Control_ReparentWindow(width, screenheight, bInFullScreen); + } sdlscrn = surf = mainSurface; // update the surface's palette HostScreen_updatePalette( 256 ); + Statusbar_Init(mainSurface); + Dprintf(("Surface Pitch = %d, width = %d, height = %d\n", surf->pitch, surf->w, surf->h)); Dprintf(("Must Lock? %s\n", SDL_MUSTLOCK(surf) ? "YES" : "NO")); @@ -266,105 +289,47 @@ void HostScreen_setWindowSize( uint32 wi } -static void HostScreen_update5( int32 x, int32 y, int32 w, int32 h, BOOL forced ) +static void HostScreen_update5(Sint32 x, Sint32 y, Sint32 w, Sint32 h, bool forced) { if ( !forced && !doUpdate ) // the HW surface is available return; - // SDL_UpdateRect(SDL_GetVideoSurface(), 0, 0, width, height); - // SDL_UpdateRect(surf, x, y, w, h); SDL_UpdateRect(mainSurface, x, y, w, h); } -void HostScreen_update1( BOOL forced ) +void HostScreen_update1(bool forced) { HostScreen_update5( 0, 0, hs_width, hs_height, forced ); } -void HostScreen_update0() -{ - HostScreen_update5( 0, 0, hs_width, hs_height, FALSE ); -} - - -uint32 HostScreen_getBitsPerPixel(void) -{ - return surf->format->BitsPerPixel; -} - - -#if 0 -void HostScreen_gfxFastPixelColorNolock(int16 x, int16 y, uint32 color) -{ - int bpp; - uint8 *p; - - /* Get destination format */ - bpp = surf->format->BytesPerPixel; - p = (uint8 *)surf->pixels + y * surf->pitch + x * bpp; - switch(bpp) { - case 1: - *p = color; - break; - case 2: - *(uint16 *)p = color; - break; - case 3: - putBpp24Pixel( p, color ); - break; - case 4: - *(uint32 *)p = color; - break; - } /* switch */ -} -#endif - -#if 0 -uint32 HostScreen_gfxGetPixel( int16 x, int16 y ) -{ - int bpp; - uint8 *p; - - /* Get destination format */ - bpp = surf->format->BytesPerPixel; - p = (uint8 *)surf->pixels + y * surf->pitch + x * bpp; - switch(bpp) { - case 1: - return (uint32)(*(uint8 *)p); - case 2: - return (uint32)(*(uint16 *)p); - case 3: - // FIXME maybe some & problems? and endian - return getBpp24Pixel( p ); - case 4: - return *(uint32 *)p; - } /* switch */ - return 0; // should never happen -} -#endif -uint32 HostScreen_getBpp() +Uint32 HostScreen_getBpp(void) { return surf->format->BytesPerPixel; } -uint32 HostScreen_getPitch() { +Uint32 HostScreen_getPitch(void) +{ return surf->pitch; } -uint32 HostScreen_getWidth() { +Uint32 HostScreen_getWidth(void) +{ return hs_width; } -uint32 HostScreen_getHeight() { +Uint32 HostScreen_getHeight(void) +{ return hs_height; } -uint8 *HostScreen_getVideoramAddress() { +Uint8 *HostScreen_getVideoramAddress(void) +{ return surf->pixels; /* FIXME maybe this should be mainSurface? */ } -void HostScreen_setPaletteColor( uint8 idx, uint32 red, uint32 green, uint32 blue ) { +void HostScreen_setPaletteColor(Uint8 idx, Uint32 red, Uint32 green, Uint32 blue) +{ // set the SDL standard RGB palette settings palette.standard[idx].r = red; palette.standard[idx].g = green; @@ -373,177 +338,36 @@ void HostScreen_setPaletteColor( uint8 i palette.native[idx] = SDL_MapRGB( surf->format, red, green, blue ); } -uint32 HostScreen_getPaletteColor( uint8 idx ) { +Uint32 HostScreen_getPaletteColor(Uint8 idx) +{ return palette.native[idx]; } -void HostScreen_updatePalette( uint16 colorCount ) { +void HostScreen_updatePalette(Uint16 colorCount) +{ SDL_SetColors( surf, palette.standard, 0, colorCount ); } -uint32 HostScreen_getColor( uint32 red, uint32 green, uint32 blue ) { +Uint32 HostScreen_getColor(Uint32 red, Uint32 green, Uint32 blue) +{ return SDL_MapRGB( surf->format, red, green, blue ); } -#if 0 -void HostScreen_lock(void) { - while (SDL_mutexP(screenLock)==-1) { - SDL_Delay(20); - fprintf(stderr, "Couldn't lock mutex\n"); - } -} - -void HostScreen_unlock(void) { - while (SDL_mutexV(screenLock)==-1) { - SDL_Delay(20); - fprintf(stderr, "Couldn't unlock mutex\n"); - } -} -#endif -BOOL HostScreen_renderBegin(void) { +bool HostScreen_renderBegin(void) +{ if (SDL_MUSTLOCK(surf)) if (SDL_LockSurface(surf) < 0) { printf("Couldn't lock surface to refresh!\n"); - return FALSE; + return false; } - return TRUE; + return true; } -void HostScreen_renderEnd() { +void HostScreen_renderEnd(void) +{ if (SDL_MUSTLOCK(surf)) SDL_UnlockSurface(surf); -} - - - -/** - * Performs conversion from the TOS's bitplane word order (big endian) data - * into the native chunky color index. - */ -void HostScreen_bitplaneToChunky( uint16 *atariBitplaneData, uint16 bpp, uint8 colorValues[16] ) -{ - uint32 a, b, c, d, x; - - /* Obviously the different cases can be broken out in various - * ways to lessen the amount of work needed for <8 bit modes. - * It's doubtful if the usage of those modes warrants it, though. - * The branches below should be ~100% correctly predicted and - * thus be more or less for free. - * Getting the palette values inline does not seem to help - * enough to worry about. The palette lookup is much slower than - * this code, though, so it would be nice to do something about it. - */ - if (bpp >= 4) { - d = *(uint32 *)&atariBitplaneData[0]; - c = *(uint32 *)&atariBitplaneData[2]; - if (bpp == 4) { - a = b = 0; - } else { - b = *(uint32 *)&atariBitplaneData[4]; - a = *(uint32 *)&atariBitplaneData[6]; - } - } else { - a = b = c = 0; - if (bpp == 2) { - d = *(uint32 *)&atariBitplaneData[0]; - } else { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - d = atariBitplaneData[0]<<16; -#else - d = atariBitplaneData[0]; -#endif - } - } - - x = a; - a = (a & 0xf0f0f0f0) | ((c & 0xf0f0f0f0) >> 4); - c = ((x & 0x0f0f0f0f) << 4) | (c & 0x0f0f0f0f); - x = b; - b = (b & 0xf0f0f0f0) | ((d & 0xf0f0f0f0) >> 4); - d = ((x & 0x0f0f0f0f) << 4) | (d & 0x0f0f0f0f); - - x = a; - a = (a & 0xcccccccc) | ((b & 0xcccccccc) >> 2); - b = ((x & 0x33333333) << 2) | (b & 0x33333333); - x = c; - c = (c & 0xcccccccc) | ((d & 0xcccccccc) >> 2); - d = ((x & 0x33333333) << 2) | (d & 0x33333333); - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - a = (a & 0x5555aaaa) | ((a & 0x00005555) << 17) | ((a & 0xaaaa0000) >> 17); - b = (b & 0x5555aaaa) | ((b & 0x00005555) << 17) | ((b & 0xaaaa0000) >> 17); - c = (c & 0x5555aaaa) | ((c & 0x00005555) << 17) | ((c & 0xaaaa0000) >> 17); - d = (d & 0x5555aaaa) | ((d & 0x00005555) << 17) | ((d & 0xaaaa0000) >> 17); - - colorValues[ 8] = a; - a >>= 8; - colorValues[ 0] = a; - a >>= 8; - colorValues[ 9] = a; - a >>= 8; - colorValues[ 1] = a; - - colorValues[10] = b; - b >>= 8; - colorValues[ 2] = b; - b >>= 8; - colorValues[11] = b; - b >>= 8; - colorValues[ 3] = b; - - colorValues[12] = c; - c >>= 8; - colorValues[ 4] = c; - c >>= 8; - colorValues[13] = c; - c >>= 8; - colorValues[ 5] = c; - - colorValues[14] = d; - d >>= 8; - colorValues[ 6] = d; - d >>= 8; - colorValues[15] = d; - d >>= 8; - colorValues[ 7] = d; -#else - a = (a & 0xaaaa5555) | ((a & 0x0000aaaa) << 15) | ((a & 0x55550000) >> 15); - b = (b & 0xaaaa5555) | ((b & 0x0000aaaa) << 15) | ((b & 0x55550000) >> 15); - c = (c & 0xaaaa5555) | ((c & 0x0000aaaa) << 15) | ((c & 0x55550000) >> 15); - d = (d & 0xaaaa5555) | ((d & 0x0000aaaa) << 15) | ((d & 0x55550000) >> 15); - - colorValues[ 1] = a; - a >>= 8; - colorValues[ 9] = a; - a >>= 8; - colorValues[ 0] = a; - a >>= 8; - colorValues[ 8] = a; - - colorValues[ 3] = b; - b >>= 8; - colorValues[11] = b; - b >>= 8; - colorValues[ 2] = b; - b >>= 8; - colorValues[10] = b; - - colorValues[ 5] = c; - c >>= 8; - colorValues[13] = c; - c >>= 8; - colorValues[ 4] = c; - c >>= 8; - colorValues[12] = c; - - colorValues[ 7] = d; - d >>= 8; - colorValues[15] = d; - d >>= 8; - colorValues[ 6] = d; - d >>= 8; - colorValues[14] = d; -#endif + Statusbar_Update(surf); }