atari:xbios: Let SDL handles centering on screen. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Fri, 22 Aug 2014 12:40:49 +0200
branchSDL-1.2
changeset 91098b2109994b82
parent 9062 74356aed1fa2
child 9110 d0300b8ab099
atari:xbios: Let SDL handles centering on screen.
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios.h
src/video/xbios/SDL_xbios_ctpci.c
src/video/xbios/SDL_xbios_f30.c
     1.1 --- a/src/video/xbios/SDL_xbios.c	Wed Aug 13 20:06:53 2014 +0200
     1.2 +++ b/src/video/xbios/SDL_xbios.c	Fri Aug 22 12:40:49 2014 +0200
     1.3 @@ -528,6 +528,8 @@
     1.4  #endif
     1.5  
     1.6  	this->UpdateRects = XBIOS_updRects;
     1.7 +	XBIOS_recoffset = 2;
     1.8 +
     1.9  	return (current);
    1.10  }
    1.11  
    1.12 @@ -552,6 +554,21 @@
    1.13  	return;
    1.14  }
    1.15  
    1.16 +static void recalc_offset(_THIS)
    1.17 +{
    1.18 +	int offset_x;
    1.19 +
    1.20 +	offset_x = (XBIOS_current->width - this->screen->w)>>1;
    1.21 +	offset_x &= ~15;
    1.22 +
    1.23 +	this->offset_x = offset_x;
    1.24 +
    1.25 +	this->screen->offset = this->offset_y*this->screen->pitch +
    1.26 +				this->offset_x*this->screen->format->BytesPerPixel;
    1.27 +
    1.28 +	--XBIOS_recoffset;
    1.29 +}
    1.30 +
    1.31  static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
    1.32  {
    1.33  	SDL_Surface *surface;
    1.34 @@ -562,8 +579,12 @@
    1.35  		int i;
    1.36  		int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
    1.37  
    1.38 +		if (XBIOS_recoffset>0) {
    1.39 +			recalc_offset(this);
    1.40 +		}
    1.41 +
    1.42  		for (i=0;i<numrects;i++) {
    1.43 -			void *source,*destination;
    1.44 +			Uint8 *source,*destination;
    1.45  			int x1,x2;
    1.46  
    1.47  			x1 = rects[i].x & ~15;
    1.48 @@ -576,7 +597,7 @@
    1.49  			source += surface->pitch * rects[i].y;
    1.50  			source += x1;
    1.51  
    1.52 -			destination = XBIOS_screens[XBIOS_fbnum];
    1.53 +			destination = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    1.54  			destination += XBIOS_pitch * rects[i].y;
    1.55  			destination += x1;
    1.56  
    1.57 @@ -602,7 +623,7 @@
    1.58  	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    1.59  		XBIOS_fbnum ^= 1;
    1.60  		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
    1.61 -			surface->pixels=XBIOS_screens[XBIOS_fbnum];
    1.62 +			surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    1.63  		}
    1.64  	}
    1.65  }
    1.66 @@ -610,21 +631,16 @@
    1.67  static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
    1.68  {
    1.69  	if (XBIOS_current->flags & XBIOSMODE_C2P) {
    1.70 -		void *destscr;
    1.71 -		int destx;
    1.72  		int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
    1.73  			
    1.74 -		/* Center on destination screen */
    1.75 -		destscr = XBIOS_screens[XBIOS_fbnum];
    1.76 -		destscr += XBIOS_pitch * ((XBIOS_current->height - surface->h) >> 1);
    1.77 -		destx = (XBIOS_current->width - surface->w) >> 1;
    1.78 -		destx &= ~15;
    1.79 -		destscr += destx;
    1.80 +		if (XBIOS_recoffset>0) {
    1.81 +			recalc_offset(this);
    1.82 +		}
    1.83  
    1.84  		/* Convert chunky to planar screen */
    1.85  		SDL_Atari_C2pConvert(
    1.86  			surface->pixels,
    1.87 -			destscr,
    1.88 +			((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset,
    1.89  			surface->w,
    1.90  			surface->h,
    1.91  			doubleline,
    1.92 @@ -642,7 +658,7 @@
    1.93  	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    1.94  		XBIOS_fbnum ^= 1;
    1.95  		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
    1.96 -			surface->pixels=XBIOS_screens[XBIOS_fbnum];
    1.97 +			surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    1.98  		}
    1.99  	}
   1.100  
     2.1 --- a/src/video/xbios/SDL_xbios.h	Wed Aug 13 20:06:53 2014 +0200
     2.2 +++ b/src/video/xbios/SDL_xbios.h	Fri Aug 22 12:40:49 2014 +0200
     2.3 @@ -56,6 +56,7 @@
     2.4  	void *shadowscreen;		/* Shadow screen for c2p conversion */
     2.5  	int frame_number;		/* Number of frame for double buffer */
     2.6  	int pitch;				/* Destination line width for C2P */
     2.7 +	int recalc_offset;		/* Recalculate SDL_Surface offset for C2P */
     2.8  
     2.9  	xbiosmode_t *current;	/* Current set mode */
    2.10  	int SDL_nummodes[NUM_MODELISTS];
    2.11 @@ -113,6 +114,7 @@
    2.12  #define XBIOS_fbnum			(this->hidden->frame_number)
    2.13  #define XBIOS_pitch			(this->hidden->pitch)
    2.14  #define XBIOS_current		(this->hidden->current)
    2.15 +#define XBIOS_recoffset		(this->hidden->recalc_offset)
    2.16  
    2.17  #define TT_palette		(this->hidden->palette.pal16)
    2.18  #define F30_palette		(this->hidden->palette.pal32)
     3.1 --- a/src/video/xbios/SDL_xbios_ctpci.c	Wed Aug 13 20:06:53 2014 +0200
     3.2 +++ b/src/video/xbios/SDL_xbios_ctpci.c	Fri Aug 22 12:40:49 2014 +0200
     3.3 @@ -74,7 +74,6 @@
     3.4  static void setMode(_THIS, xbiosmode_t *new_video_mode);
     3.5  static void restoreMode(_THIS);
     3.6  static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp);
     3.7 -static void swapVbuffers(_THIS);
     3.8  static int allocVbuffers(_THIS, int num_buffers, int bufsize);
     3.9  static void freeVbuffers(_THIS);
    3.10  static void updateRects(_THIS, int numrects, SDL_Rect *rects);
    3.11 @@ -87,7 +86,6 @@
    3.12  	XBIOS_setMode = setMode;
    3.13  	XBIOS_restoreMode = restoreMode;
    3.14  	XBIOS_getLineWidth = getLineWidth;
    3.15 -	XBIOS_swapVbuffers = swapVbuffers;
    3.16  	XBIOS_allocVbuffers = allocVbuffers;
    3.17  	XBIOS_freeVbuffers = freeVbuffers;
    3.18  
    3.19 @@ -209,11 +207,6 @@
    3.20  	return (retvalue);
    3.21  }
    3.22  
    3.23 -static void swapVbuffers(_THIS)
    3.24 -{
    3.25 -	VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], VN_MAGIC, CMD_SETADR);
    3.26 -}
    3.27 -
    3.28  static int allocVbuffers(_THIS, int num_buffers, int bufsize)
    3.29  {
    3.30  	int i;
    3.31 @@ -275,15 +268,9 @@
    3.32  {
    3.33  	SDL_Surface *surface;
    3.34  	int i;
    3.35 -	/*unsigned long offset,size;*/
    3.36  	  
    3.37  	surface = this->screen;
    3.38  
    3.39 -	/* Center on destination screen */
    3.40 -	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
    3.41 -	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
    3.42 -	destscr =  (void *)((unsigned long)destscr+offset);*/
    3.43 -
    3.44  	for (i=0;i<numrects;i++) {
    3.45  		Uint8 *blockSrcStart, *blockDstStart;
    3.46  		int y;
    3.47 @@ -292,7 +279,7 @@
    3.48  		blockSrcStart += surface->pitch*rects[i].y;
    3.49  		blockSrcStart += surface->format->BytesPerPixel*rects[i].x;
    3.50  
    3.51 -		blockDstStart = (Uint8 *) XBIOS_screens[XBIOS_fbnum];
    3.52 +		blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    3.53  		blockDstStart += XBIOS_pitch*rects[i].y;
    3.54  		blockDstStart += surface->format->BytesPerPixel*rects[i].x;
    3.55  
    3.56 @@ -309,29 +296,29 @@
    3.57  
    3.58  	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    3.59  		XBIOS_fbnum ^= 1;
    3.60 -		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
    3.61 -			surface->pixels=XBIOS_screens[XBIOS_fbnum];
    3.62 -		}
    3.63  	}
    3.64  }
    3.65  
    3.66  static int flipHWSurface(_THIS, SDL_Surface *surface)
    3.67  {
    3.68 -	/* Center on destination screen */
    3.69 -	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
    3.70 -	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
    3.71 -	destscr = (void *)((unsigned long)destscr+offset);*/
    3.72 +	int i;
    3.73 +	Uint8 *src, *dst;
    3.74  
    3.75 -	SDL_memcpy(XBIOS_screens[XBIOS_fbnum], surface->pixels, surface->h * surface->pitch);
    3.76 -	  
    3.77 +	src = surface->pixels;
    3.78 +	dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    3.79 +
    3.80 +	for (i=0; i<surface->h; i++) {
    3.81 +		SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
    3.82 +		src += surface->pitch;
    3.83 +		dst += XBIOS_pitch;
    3.84 +		
    3.85 +	}
    3.86 +
    3.87  	VsetScreen(-1L, -1L, VN_MAGIC, CMD_FLIPPAGE);
    3.88  	Vsync();
    3.89 -  
    3.90 +
    3.91  	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    3.92  		XBIOS_fbnum ^= 1;
    3.93 -		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
    3.94 -			surface->pixels=XBIOS_screens[XBIOS_fbnum];
    3.95 -		}
    3.96  	}
    3.97  
    3.98  	return(0);
     4.1 --- a/src/video/xbios/SDL_xbios_f30.c	Wed Aug 13 20:06:53 2014 +0200
     4.2 +++ b/src/video/xbios/SDL_xbios_f30.c	Fri Aug 22 12:40:49 2014 +0200
     4.3 @@ -268,15 +268,9 @@
     4.4  {
     4.5  	SDL_Surface *surface;
     4.6  	int i;
     4.7 -	/*unsigned long offset,size;*/
     4.8  	  
     4.9  	surface = this->screen;
    4.10  
    4.11 -	/* Center on destination screen */
    4.12 -	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
    4.13 -	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
    4.14 -	destscr =  (void *)((unsigned long)destscr+offset);*/
    4.15 -
    4.16  	for (i=0;i<numrects;i++) {
    4.17  		Uint8 *blockSrcStart, *blockDstStart;
    4.18  		int y;
    4.19 @@ -285,7 +279,7 @@
    4.20  		blockSrcStart += surface->pitch*rects[i].y;
    4.21  		blockSrcStart += surface->format->BytesPerPixel*rects[i].x;
    4.22  
    4.23 -		blockDstStart = (Uint8 *) XBIOS_screens[XBIOS_fbnum];
    4.24 +		blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    4.25  		blockDstStart += XBIOS_pitch*rects[i].y;
    4.26  		blockDstStart += surface->format->BytesPerPixel*rects[i].x;
    4.27  
    4.28 @@ -302,29 +296,29 @@
    4.29  
    4.30  	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    4.31  		XBIOS_fbnum ^= 1;
    4.32 -		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
    4.33 -			surface->pixels=XBIOS_screens[XBIOS_fbnum];
    4.34 -		}
    4.35  	}
    4.36  }
    4.37  
    4.38  static int flipHWSurface_SV(_THIS, SDL_Surface *surface)
    4.39  {
    4.40 -	/* Center on destination screen */
    4.41 -	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
    4.42 -	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
    4.43 -	destscr = (void *)((unsigned long)destscr+offset);*/
    4.44 +	int i;
    4.45 +	Uint8 *src, *dst;
    4.46  
    4.47 -	SDL_memcpy(XBIOS_screens[XBIOS_fbnum], surface->pixels, surface->h * surface->pitch);
    4.48 -	  
    4.49 +	src = surface->pixels;
    4.50 +	dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
    4.51 +
    4.52 +	for (i=0; i<surface->h; i++) {
    4.53 +		SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
    4.54 +		src += surface->pitch;
    4.55 +		dst += XBIOS_pitch;
    4.56 +		
    4.57 +	}
    4.58 +
    4.59  	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
    4.60  	Vsync();
    4.61    
    4.62  	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    4.63  		XBIOS_fbnum ^= 1;
    4.64 -		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
    4.65 -			surface->pixels=XBIOS_screens[XBIOS_fbnum];
    4.66 -		}
    4.67  	}
    4.68  
    4.69  	return(0);