atari:xbios: Add function to get line width. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Sun, 03 Aug 2014 20:05:42 +0200
branchSDL-1.2
changeset 9043 1a6ca0c7977e
parent 9042 89d54976ff74
child 9058 dc32c43c2c92
atari:xbios: Add function to get line width.
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
src/video/xbios/SDL_xbios_milan.c
src/video/xbios/SDL_xbios_st.c
--- a/src/video/xbios/SDL_xbios.c	Sat Aug 02 11:16:16 2014 +0200
+++ b/src/video/xbios/SDL_xbios.c	Sun Aug 03 20:05:42 2014 +0200
@@ -409,6 +409,7 @@
 	xbiosmode_t *new_video_mode;
 	Uint32 new_screen_size;
 	Uint32 modeflags;
+	Uint32 lineWidth;
 
 	/* Free current buffers */
 	XBIOS_FreeBuffers(this);
@@ -442,7 +443,9 @@
 		modeflags |= SDL_HWSURFACE;
 	}
 
-	new_screen_size = width * height * ((new_depth)>>3);
+	lineWidth = (*XBIOS_getLineWidth)(this, new_video_mode, width, new_depth);
+
+	new_screen_size = lineWidth * height;
 	new_screen_size += 256; /* To align on a 256 byte adress */	
 
 	if (new_video_mode->flags & XBIOSMODE_C2P) {
@@ -491,10 +494,10 @@
 	XBIOS_current = new_video_mode;
 	current->w = width;
 	current->h = height;
-	current->pitch = (width * new_depth)>>3;
+	current->pitch = lineWidth;
 
 	/* this is for C2P conversion */
-	XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
+	XBIOS_pitch = (*XBIOS_getLineWidth)(this, new_video_mode, new_video_mode->width, new_video_mode->depth);
 
 	if (XBIOS_shadowscreen)
 		current->pixels = XBIOS_shadowscreen;
--- a/src/video/xbios/SDL_xbios.h	Sat Aug 02 11:16:16 2014 +0200
+++ b/src/video/xbios/SDL_xbios.h	Sun Aug 03 20:05:42 2014 +0200
@@ -71,6 +71,7 @@
 	void (*saveMode)(_THIS, SDL_PixelFormat *vformat);	/* Save mode,palette,vbase change format if needed */
 	void (*setMode)(_THIS, xbiosmode_t *new_video_mode);	/* Set mode */
 	void (*restoreMode)(_THIS);	/* Restore system mode */
+	int (*getLineWidth)(_THIS, xbiosmode_t *new_video_mode, int width, int bpp);	/* Return video mode pitch */
 	void (*swapVbuffers)(_THIS);	/* Swap video buffers */
 	int (*allocVbuffers)(_THIS, int num_buffers, int bufsize);	/* Allocate video buffers */
 	void (*freeVbuffers)(_THIS);	/* Free video buffers */
@@ -120,6 +121,7 @@
 #define XBIOS_saveMode		(this->hidden->saveMode)
 #define XBIOS_setMode		(this->hidden->setMode)
 #define XBIOS_restoreMode	(this->hidden->restoreMode)
+#define XBIOS_getLineWidth	(this->hidden->getLineWidth)
 #define XBIOS_swapVbuffers	(this->hidden->swapVbuffers)
 #define XBIOS_allocVbuffers	(this->hidden->allocVbuffers)
 #define XBIOS_freeVbuffers	(this->hidden->freeVbuffers)
--- a/src/video/xbios/SDL_xbios_ctpci.c	Sat Aug 02 11:16:16 2014 +0200
+++ b/src/video/xbios/SDL_xbios_ctpci.c	Sun Aug 03 20:05:42 2014 +0200
@@ -73,6 +73,7 @@
 static void saveMode(_THIS, SDL_PixelFormat *vformat);
 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);
@@ -85,6 +86,7 @@
 	XBIOS_saveMode = saveMode;
 	XBIOS_setMode = setMode;
 	XBIOS_restoreMode = restoreMode;
+	XBIOS_getLineWidth = getLineWidth;
 	XBIOS_swapVbuffers = swapVbuffers;
 	XBIOS_allocVbuffers = allocVbuffers;
 	XBIOS_freeVbuffers = freeVbuffers;
@@ -170,8 +172,6 @@
 
 static void setMode(_THIS, xbiosmode_t *new_video_mode)
 {
-	SCREENINFO si;
-
 	VsetScreen(-1, XBIOS_screens[0], VN_MAGIC, CMD_SETADR);
 
 	VsetScreen(-1, new_video_mode->number, VN_MAGIC, CMD_SETMODE);
@@ -181,15 +181,6 @@
 		SDL_memset(F30_palette, 0, sizeof(F30_palette));
 		VsetRGB(0,256,F30_palette);
 	}
-
-	/* Set pitch of new mode */
-	si.size = sizeof(SCREENINFO);
-	si.devID = new_video_mode->number;
-	si.scrFlags = 0;
-	VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
-	if (si.scrFlags & SCRINFO_OK) {
-		XBIOS_pitch = si.lineWrap;
-	}
 }
 
 static void restoreMode(_THIS)
@@ -201,6 +192,23 @@
 	}
 }
 
+static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
+{
+	SCREENINFO si;
+	int retvalue = width * (((bpp==15) ? 16 : bpp)>>3);
+
+	/* Set pitch of new mode */
+	si.size = sizeof(SCREENINFO);
+	si.devID = new_video_mode->number;
+	si.scrFlags = 0;
+	VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
+	if (si.scrFlags & SCRINFO_OK) {
+		retvalue = si.lineWrap;
+	}
+
+	return (retvalue);
+}
+
 static void swapVbuffers(_THIS)
 {
 	VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], VN_MAGIC, CMD_SETADR);
--- a/src/video/xbios/SDL_xbios_f30.c	Sat Aug 02 11:16:16 2014 +0200
+++ b/src/video/xbios/SDL_xbios_f30.c	Sun Aug 03 20:05:42 2014 +0200
@@ -180,7 +180,7 @@
 {
 	Setscreen(-1,XBIOS_screens[0],-1);
 
-	VsetMode(new_video_mode->number);
+	(void) VsetMode(new_video_mode->number);
 
 	/* Set hardware palette to black in True Colour */
 	if (new_video_mode->depth > 8) {
@@ -193,7 +193,7 @@
 {
 	Setscreen(-1,XBIOS_oldvbase,-1);
 
-	VsetMode(XBIOS_oldvmode);
+	(void) VsetMode(XBIOS_oldvmode);
 
 	if (XBIOS_oldnumcol) {
 		VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
--- a/src/video/xbios/SDL_xbios_milan.c	Sat Aug 02 11:16:16 2014 +0200
+++ b/src/video/xbios/SDL_xbios_milan.c	Sun Aug 03 20:05:42 2014 +0200
@@ -64,6 +64,7 @@
 static void saveMode(_THIS, SDL_PixelFormat *vformat);
 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);
@@ -75,6 +76,7 @@
 	XBIOS_saveMode = saveMode;
 	XBIOS_setMode = setMode;
 	XBIOS_restoreMode = restoreMode;
+	XBIOS_getLineWidth = getLineWidth;
 	XBIOS_swapVbuffers = swapVbuffers;
 	XBIOS_allocVbuffers = allocVbuffers;
 	XBIOS_freeVbuffers = freeVbuffers;
@@ -180,6 +182,23 @@
 	VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
 }
 
+static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
+{
+	SCREENINFO si;
+	int retvalue = width * (((bpp==15) ? 16 : bpp)>>3);
+
+	/* Set pitch of new mode */
+	si.size = sizeof(SCREENINFO);
+	si.devID = new_video_mode->number;
+	si.scrFlags = 0;
+	VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
+	if (si.scrFlags & SCRINFO_OK) {
+		retvalue = si.lineWrap;
+	}
+
+	return (retvalue);
+}
+
 static int allocVbuffers(_THIS, int num_buffers, int bufsize)
 {
 	int i;
--- a/src/video/xbios/SDL_xbios_st.c	Sat Aug 02 11:16:16 2014 +0200
+++ b/src/video/xbios/SDL_xbios_st.c	Sun Aug 03 20:05:42 2014 +0200
@@ -45,6 +45,7 @@
 static void setMode_ST(_THIS, xbiosmode_t *new_video_mode);
 static void setMode_STE(_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);
@@ -56,6 +57,7 @@
 	XBIOS_saveMode = saveMode;
 	XBIOS_setMode = setMode_ST;
 	XBIOS_restoreMode = restoreMode;
+	XBIOS_getLineWidth = getLineWidth;
 	XBIOS_swapVbuffers = swapVbuffers;
 	XBIOS_allocVbuffers = allocVbuffers;
 	XBIOS_freeVbuffers = freeVbuffers;
@@ -140,6 +142,11 @@
 	}
 }
 
+static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
+{
+	return (width * (((bpp==15) ? 16 : bpp)>>3));
+}
+
 static void swapVbuffers(_THIS)
 {
 	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);