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 9109 8b2109994b82
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
--- a/src/video/xbios/SDL_xbios.c	Wed Aug 13 20:06:53 2014 +0200
+++ b/src/video/xbios/SDL_xbios.c	Fri Aug 22 12:40:49 2014 +0200
@@ -528,6 +528,8 @@
 #endif
 
 	this->UpdateRects = XBIOS_updRects;
+	XBIOS_recoffset = 2;
+
 	return (current);
 }
 
@@ -552,6 +554,21 @@
 	return;
 }
 
+static void recalc_offset(_THIS)
+{
+	int offset_x;
+
+	offset_x = (XBIOS_current->width - this->screen->w)>>1;
+	offset_x &= ~15;
+
+	this->offset_x = offset_x;
+
+	this->screen->offset = this->offset_y*this->screen->pitch +
+				this->offset_x*this->screen->format->BytesPerPixel;
+
+	--XBIOS_recoffset;
+}
+
 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
 {
 	SDL_Surface *surface;
@@ -562,8 +579,12 @@
 		int i;
 		int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
 
+		if (XBIOS_recoffset>0) {
+			recalc_offset(this);
+		}
+
 		for (i=0;i<numrects;i++) {
-			void *source,*destination;
+			Uint8 *source,*destination;
 			int x1,x2;
 
 			x1 = rects[i].x & ~15;
@@ -576,7 +597,7 @@
 			source += surface->pitch * rects[i].y;
 			source += x1;
 
-			destination = XBIOS_screens[XBIOS_fbnum];
+			destination = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 			destination += XBIOS_pitch * rects[i].y;
 			destination += x1;
 
@@ -602,7 +623,7 @@
 	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 		XBIOS_fbnum ^= 1;
 		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
-			surface->pixels=XBIOS_screens[XBIOS_fbnum];
+			surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 		}
 	}
 }
@@ -610,21 +631,16 @@
 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
 {
 	if (XBIOS_current->flags & XBIOSMODE_C2P) {
-		void *destscr;
-		int destx;
 		int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
 			
-		/* Center on destination screen */
-		destscr = XBIOS_screens[XBIOS_fbnum];
-		destscr += XBIOS_pitch * ((XBIOS_current->height - surface->h) >> 1);
-		destx = (XBIOS_current->width - surface->w) >> 1;
-		destx &= ~15;
-		destscr += destx;
+		if (XBIOS_recoffset>0) {
+			recalc_offset(this);
+		}
 
 		/* Convert chunky to planar screen */
 		SDL_Atari_C2pConvert(
 			surface->pixels,
-			destscr,
+			((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset,
 			surface->w,
 			surface->h,
 			doubleline,
@@ -642,7 +658,7 @@
 	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 		XBIOS_fbnum ^= 1;
 		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
-			surface->pixels=XBIOS_screens[XBIOS_fbnum];
+			surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 		}
 	}
 
--- a/src/video/xbios/SDL_xbios.h	Wed Aug 13 20:06:53 2014 +0200
+++ b/src/video/xbios/SDL_xbios.h	Fri Aug 22 12:40:49 2014 +0200
@@ -56,6 +56,7 @@
 	void *shadowscreen;		/* Shadow screen for c2p conversion */
 	int frame_number;		/* Number of frame for double buffer */
 	int pitch;				/* Destination line width for C2P */
+	int recalc_offset;		/* Recalculate SDL_Surface offset for C2P */
 
 	xbiosmode_t *current;	/* Current set mode */
 	int SDL_nummodes[NUM_MODELISTS];
@@ -113,6 +114,7 @@
 #define XBIOS_fbnum			(this->hidden->frame_number)
 #define XBIOS_pitch			(this->hidden->pitch)
 #define XBIOS_current		(this->hidden->current)
+#define XBIOS_recoffset		(this->hidden->recalc_offset)
 
 #define TT_palette		(this->hidden->palette.pal16)
 #define F30_palette		(this->hidden->palette.pal32)
--- a/src/video/xbios/SDL_xbios_ctpci.c	Wed Aug 13 20:06:53 2014 +0200
+++ b/src/video/xbios/SDL_xbios_ctpci.c	Fri Aug 22 12:40:49 2014 +0200
@@ -74,7 +74,6 @@
 static void setMode(_THIS, xbiosmode_t *new_video_mode);
 static void restoreMode(_THIS);
 static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp);
-static void swapVbuffers(_THIS);
 static int allocVbuffers(_THIS, int num_buffers, int bufsize);
 static void freeVbuffers(_THIS);
 static void updateRects(_THIS, int numrects, SDL_Rect *rects);
@@ -87,7 +86,6 @@
 	XBIOS_setMode = setMode;
 	XBIOS_restoreMode = restoreMode;
 	XBIOS_getLineWidth = getLineWidth;
-	XBIOS_swapVbuffers = swapVbuffers;
 	XBIOS_allocVbuffers = allocVbuffers;
 	XBIOS_freeVbuffers = freeVbuffers;
 
@@ -209,11 +207,6 @@
 	return (retvalue);
 }
 
-static void swapVbuffers(_THIS)
-{
-	VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], VN_MAGIC, CMD_SETADR);
-}
-
 static int allocVbuffers(_THIS, int num_buffers, int bufsize)
 {
 	int i;
@@ -275,15 +268,9 @@
 {
 	SDL_Surface *surface;
 	int i;
-	/*unsigned long offset,size;*/
 	  
 	surface = this->screen;
 
-	/* Center on destination screen */
-	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
-	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
-	destscr =  (void *)((unsigned long)destscr+offset);*/
-
 	for (i=0;i<numrects;i++) {
 		Uint8 *blockSrcStart, *blockDstStart;
 		int y;
@@ -292,7 +279,7 @@
 		blockSrcStart += surface->pitch*rects[i].y;
 		blockSrcStart += surface->format->BytesPerPixel*rects[i].x;
 
-		blockDstStart = (Uint8 *) XBIOS_screens[XBIOS_fbnum];
+		blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 		blockDstStart += XBIOS_pitch*rects[i].y;
 		blockDstStart += surface->format->BytesPerPixel*rects[i].x;
 
@@ -309,29 +296,29 @@
 
 	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 		XBIOS_fbnum ^= 1;
-		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
-			surface->pixels=XBIOS_screens[XBIOS_fbnum];
-		}
 	}
 }
 
 static int flipHWSurface(_THIS, SDL_Surface *surface)
 {
-	/* Center on destination screen */
-	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
-	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
-	destscr = (void *)((unsigned long)destscr+offset);*/
+	int i;
+	Uint8 *src, *dst;
+
+	src = surface->pixels;
+	dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 
-	SDL_memcpy(XBIOS_screens[XBIOS_fbnum], surface->pixels, surface->h * surface->pitch);
-	  
+	for (i=0; i<surface->h; i++) {
+		SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
+		src += surface->pitch;
+		dst += XBIOS_pitch;
+		
+	}
+
 	VsetScreen(-1L, -1L, VN_MAGIC, CMD_FLIPPAGE);
 	Vsync();
-  
+
 	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 		XBIOS_fbnum ^= 1;
-		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
-			surface->pixels=XBIOS_screens[XBIOS_fbnum];
-		}
 	}
 
 	return(0);
--- a/src/video/xbios/SDL_xbios_f30.c	Wed Aug 13 20:06:53 2014 +0200
+++ b/src/video/xbios/SDL_xbios_f30.c	Fri Aug 22 12:40:49 2014 +0200
@@ -268,15 +268,9 @@
 {
 	SDL_Surface *surface;
 	int i;
-	/*unsigned long offset,size;*/
 	  
 	surface = this->screen;
 
-	/* Center on destination screen */
-	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
-	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
-	destscr =  (void *)((unsigned long)destscr+offset);*/
-
 	for (i=0;i<numrects;i++) {
 		Uint8 *blockSrcStart, *blockDstStart;
 		int y;
@@ -285,7 +279,7 @@
 		blockSrcStart += surface->pitch*rects[i].y;
 		blockSrcStart += surface->format->BytesPerPixel*rects[i].x;
 
-		blockDstStart = (Uint8 *) XBIOS_screens[XBIOS_fbnum];
+		blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 		blockDstStart += XBIOS_pitch*rects[i].y;
 		blockDstStart += surface->format->BytesPerPixel*rects[i].x;
 
@@ -302,29 +296,29 @@
 
 	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 		XBIOS_fbnum ^= 1;
-		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
-			surface->pixels=XBIOS_screens[XBIOS_fbnum];
-		}
 	}
 }
 
 static int flipHWSurface_SV(_THIS, SDL_Surface *surface)
 {
-	/* Center on destination screen */
-	/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
-	offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
-	destscr = (void *)((unsigned long)destscr+offset);*/
+	int i;
+	Uint8 *src, *dst;
+
+	src = surface->pixels;
+	dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
 
-	SDL_memcpy(XBIOS_screens[XBIOS_fbnum], surface->pixels, surface->h * surface->pitch);
-	  
+	for (i=0; i<surface->h; i++) {
+		SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
+		src += surface->pitch;
+		dst += XBIOS_pitch;
+		
+	}
+
 	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
 	Vsync();
   
 	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 		XBIOS_fbnum ^= 1;
-		if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
-			surface->pixels=XBIOS_screens[XBIOS_fbnum];
-		}
 	}
 
 	return(0);