--- hatari/src/falcon/hostscreen.c 2019/04/01 07:13:46 1.1 +++ hatari/src/falcon/hostscreen.c 2019/04/01 07:15:34 1.1.1.3 @@ -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_rcsid[] = "Hatari $Id: hostscreen.c,v 1.1.1.3 2019/04/01 07:15:34 root Exp $"; #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 @@ -50,13 +52,13 @@ static SDL_Surface *surf; 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,8 +69,8 @@ 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) { @@ -93,6 +95,10 @@ 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". @@ -120,10 +126,15 @@ void HostScreen_toggleFullScreen(void) /* refresh the screen */ 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 +157,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,8 +211,10 @@ 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; + nScreenZoomX = 1; nScreenZoomY = 1; if (ConfigureParams.Screen.bZoomLowRes) @@ -219,27 +232,36 @@ void HostScreen_setWindowSize( uint32 wi 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,7 +288,7 @@ 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; @@ -276,7 +298,7 @@ static void HostScreen_update5( int32 x, 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 ); } @@ -287,84 +309,34 @@ void HostScreen_update0() } -uint32 HostScreen_getBitsPerPixel(void) +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() { return surf->format->BytesPerPixel; } -uint32 HostScreen_getPitch() { +Uint32 HostScreen_getPitch() { return surf->pitch; } -uint32 HostScreen_getWidth() { +Uint32 HostScreen_getWidth() { return hs_width; } -uint32 HostScreen_getHeight() { +Uint32 HostScreen_getHeight() { return hs_height; } -uint8 *HostScreen_getVideoramAddress() { +Uint8 *HostScreen_getVideoramAddress() { 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,15 +345,15 @@ 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 ); } @@ -401,7 +373,8 @@ void HostScreen_unlock(void) { } #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"); @@ -414,6 +387,7 @@ BOOL HostScreen_renderBegin(void) { void HostScreen_renderEnd() { if (SDL_MUSTLOCK(surf)) SDL_UnlockSurface(surf); + Statusbar_Update(surf); } @@ -422,9 +396,9 @@ void HostScreen_renderEnd() { * 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] ) +void HostScreen_bitplaneToChunky(Uint16 *atariBitplaneData, Uint16 bpp, Uint8 colorValues[16] ) { - uint32 a, b, c, d, x; + 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. @@ -436,18 +410,18 @@ void HostScreen_bitplaneToChunky( uint16 * this code, though, so it would be nice to do something about it. */ if (bpp >= 4) { - d = *(uint32 *)&atariBitplaneData[0]; - c = *(uint32 *)&atariBitplaneData[2]; + d = *(Uint32 *)&atariBitplaneData[0]; + c = *(Uint32 *)&atariBitplaneData[2]; if (bpp == 4) { a = b = 0; } else { - b = *(uint32 *)&atariBitplaneData[4]; - a = *(uint32 *)&atariBitplaneData[6]; + b = *(Uint32 *)&atariBitplaneData[4]; + a = *(Uint32 *)&atariBitplaneData[6]; } } else { a = b = c = 0; if (bpp == 2) { - d = *(uint32 *)&atariBitplaneData[0]; + d = *(Uint32 *)&atariBitplaneData[0]; } else { #if SDL_BYTEORDER == SDL_BIG_ENDIAN d = atariBitplaneData[0]<<16;