atari:xbios: Move all ST specific stuff to specific backend file. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Wed, 30 Jul 2014 12:39:05 +0200
branchSDL-1.2
changeset 9027 3165f185d1ea
parent 9026 5b91761249f9
child 9028 50e0a2f1333d
atari:xbios: Move all ST specific stuff to specific backend file.
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios.h
src/video/xbios/SDL_xbios_st.c
--- a/src/video/xbios/SDL_xbios.c	Wed Jul 30 11:36:59 2014 +0200
+++ b/src/video/xbios/SDL_xbios.c	Wed Jul 30 12:39:05 2014 +0200
@@ -92,10 +92,6 @@
 
 /* Default list of video modes */
 
-static const xbiosmode_t stmodes[1]={
-	{ST_LOW>>8,320,200,4, XBIOSMODE_C2P}
-};
-
 static const xbiosmode_t ttmodes[2]={
 	{TT_LOW,320,480,8, XBIOSMODE_C2P},
 	{TT_LOW,320,240,8, XBIOSMODE_C2P|XBIOSMODE_DOUBLELINE}
@@ -250,8 +246,13 @@
 	if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) {
 		cookie_cvdo = VDO_ST << 16;
 	}
+	SDL_XBIOS_VideoInit_ST(device, cookie_cvdo);
 
 	switch (cookie_cvdo>>16) {
+		case VDO_ST:
+		case VDO_STE:
+			/* Already done as default */
+			break;
 		case VDO_MILAN:
 			SDL_XBIOS_VideoInit_Milan(device);
 			break;
@@ -322,11 +323,6 @@
 	}
 }
 
-static void XBIOS_ListSTModes(_THIS, int actually_add)
-{
-	SDL_XBIOS_AddMode(this, actually_add, &stmodes[0]);
-}
-
 static void XBIOS_ListTTModes(_THIS, int actually_add)
 {
 	int i;
@@ -406,29 +402,8 @@
 	switch (XBIOS_cvdo >>16) {
 		case VDO_ST:
 		case VDO_STE:
-			{
-				short *oldpalette;
-			
-				XBIOS_oldvmode=Getrez();
-				switch(XBIOS_oldvmode << 8) {
-					case ST_LOW:
-						XBIOS_oldnumcol=16;
-						break;
-					case ST_MED:
-						XBIOS_oldnumcol=4;
-						break;
-					case ST_HIGH:
-						XBIOS_oldnumcol=2;
-						break;
-				}
-
-				oldpalette= (short *) XBIOS_oldpalette;
-				for (i=0;i<XBIOS_oldnumcol;i++) {
-					*oldpalette++=Setcolor(i,-1);
-				}
-
-				XBIOS_ListSTModes(this, 0);
-			}
+			(*XBIOS_saveMode)(this, vformat);
+			(*XBIOS_listModes)(this, 0);
 			break;
 		case VDO_TT:
 			XBIOS_oldvmode=EgetShift();
@@ -541,7 +516,7 @@
 	switch (XBIOS_cvdo >>16) {
 		case VDO_ST:
 		case VDO_STE:
-			XBIOS_ListSTModes(this, 1);
+			(*XBIOS_listModes)(this, 1);
 			break;
 		case VDO_TT:
 			XBIOS_ListTTModes(this, 1);
@@ -610,18 +585,7 @@
 
 static void XBIOS_FreeBuffers(_THIS)
 {
-	int i;
-
-	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		(*XBIOS_freeVbuffers)(this);
-	} else {
-		for (i=0;i<2;i++) {
-			if (XBIOS_screensmem[i]!=NULL) {
-				Mfree(XBIOS_screensmem[i]);
-			}
-			XBIOS_screensmem[i]=NULL;
-		}
-	}
+	(*XBIOS_freeVbuffers)(this);
 
 	if (XBIOS_shadowscreen!=NULL) {
 		Mfree(XBIOS_shadowscreen);
@@ -633,7 +597,7 @@
 				int width, int height, int bpp, Uint32 flags)
 {
 	int mode, new_depth;
-	int i, num_buffers;
+	int num_buffers;
 	xbiosmode_t *new_video_mode;
 	Uint32 new_screen_size;
 	Uint32 modeflags;
@@ -704,24 +668,9 @@
 	}
 
 	/* Allocate buffers */
-	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
-			XBIOS_FreeBuffers(this);
-			return (NULL);
-		}
-	} else {
-		for (i=0; i<num_buffers; i++) {
-			XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
-
-			if (XBIOS_screensmem[i]==NULL) {
-				XBIOS_FreeBuffers(this);
-				SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
-				return (NULL);
-			}
-			SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);
-
-			XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
-		}
+	if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
+		XBIOS_FreeBuffers(this);
+		return (NULL);
 	}
 
 	/* Allocate the new pixel format for the screen */
@@ -768,26 +717,8 @@
 
 	switch(XBIOS_cvdo >> 16) {
 		case VDO_ST:
-			Setscreen(-1,-1,new_video_mode->number);
-
-			/* Reset palette */
-			for (i=0;i<16;i++) {
-				TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1);
-			}
-			Setpalette(TT_palette);
-			break;
 		case VDO_STE:
-			Setscreen(-1,-1,new_video_mode->number);
-
-			/* Reset palette */
-			for (i=0;i<16;i++)
-			{
-				int c;
-
-				c=((i&1)<<3)|((i>>1)&7);
-				TT_palette[i]=(c<<8)|(c<<4)|c;
-			}
-			Setpalette(TT_palette);
+			(*XBIOS_setMode)(this, new_video_mode);
 			break;
 		case VDO_TT:
 			EsetShift(new_video_mode->number);
@@ -881,11 +812,7 @@
 	}
 
 #ifndef DEBUG_VIDEO_XBIOS
-	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		(*XBIOS_swapVbuffers)(this);
-	} else {
-		Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
-	}
+	(*XBIOS_swapVbuffers)(this);
 
 	Vsync();
 #endif
@@ -925,11 +852,7 @@
 	}
 
 #ifndef DEBUG_VIDEO_XBIOS
-	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		(*XBIOS_swapVbuffers)(this);
-	} else {
-		Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
-	}
+	(*XBIOS_swapVbuffers)(this);
 
 	Vsync();
 #endif
@@ -951,18 +874,6 @@
 	int		r,v,b;
 
 	switch( XBIOS_cvdo >> 16) {
-		case VDO_ST:
-		case VDO_STE:
-		 	for (i=0;i<ncolors;i++)
-			{
-				r = colors[i].r;	
-				v = colors[i].g;
-				b = colors[i].b;
-
-				TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100;
-			}
-			SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */
-			break;
 		case VDO_TT:
 			for(i = 0; i < ncolors; i++)
 			{
@@ -1005,10 +916,7 @@
 	switch(XBIOS_cvdo >> 16) {
 		case VDO_ST:
 		case VDO_STE:
-			Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode);
-			if (XBIOS_oldnumcol) {
-				Setpalette(XBIOS_oldpalette);
-			}
+			(*XBIOS_restoreMode)(this);
 			break;
 		case VDO_TT:
 			Setscreen(-1,XBIOS_oldvbase,-1);
--- a/src/video/xbios/SDL_xbios.h	Wed Jul 30 11:36:59 2014 +0200
+++ b/src/video/xbios/SDL_xbios.h	Wed Jul 30 12:39:05 2014 +0200
@@ -132,6 +132,9 @@
 
 void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo);
 
+/* SDL_xbios_st.c */
+void SDL_XBIOS_VideoInit_ST(_THIS, unsigned long cookie_cvdo);
+
 /* SDL_xbios_milan.c */
 void SDL_XBIOS_VideoInit_Milan(_THIS);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/xbios/SDL_xbios_st.c	Wed Jul 30 12:39:05 2014 +0200
@@ -0,0 +1,194 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2012 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+/*
+	ST/STE Xbios video functions
+
+	Patrice Mandin
+*/
+
+#include <mint/cookie.h>
+#include <mint/osbind.h>
+
+#include "../SDL_sysvideo.h"
+
+#include "../ataricommon/SDL_atarimxalloc_c.h"
+#include "../ataricommon/SDL_ataric2p_s.h"
+#include "SDL_xbios.h"
+
+static const xbiosmode_t stmodes[]={
+	{ST_LOW>>8,320,200,4, XBIOSMODE_C2P}
+};
+
+static void listModes(_THIS, int actually_add);
+static void saveMode(_THIS, SDL_PixelFormat *vformat);
+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 void swapVbuffers(_THIS);
+static int allocVbuffers(_THIS, int num_buffers, int bufsize);
+static void freeVbuffers(_THIS);
+static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
+
+void SDL_XBIOS_VideoInit_ST(_THIS, unsigned long cookie_cvdo)
+{
+	XBIOS_listModes = listModes;
+	XBIOS_saveMode = saveMode;
+	XBIOS_setMode = setMode_ST;
+	XBIOS_restoreMode = restoreMode;
+	XBIOS_swapVbuffers = swapVbuffers;
+	XBIOS_allocVbuffers = allocVbuffers;
+	XBIOS_freeVbuffers = freeVbuffers;
+
+	this->SetColors = setColors;
+
+	if ((cookie_cvdo>>16) == VDO_STE) {
+		XBIOS_setMode = setMode_STE;
+	}
+}
+
+static void listModes(_THIS, int actually_add)
+{
+	SDL_XBIOS_AddMode(this, actually_add, &stmodes[0]);
+}
+
+static void saveMode(_THIS, SDL_PixelFormat *vformat)
+{
+	short *oldpalette;
+	int i;
+		
+	XBIOS_oldvbase=Physbase();
+	XBIOS_oldvmode=Getrez();
+
+	switch(XBIOS_oldvmode << 8) {
+		case ST_LOW:
+			XBIOS_oldnumcol=16;
+			break;
+		case ST_MED:
+			XBIOS_oldnumcol=4;
+			break;
+		case ST_HIGH:
+			XBIOS_oldnumcol=2;
+		break;
+	}
+
+	oldpalette= (short *) XBIOS_oldpalette;
+	for (i=0;i<XBIOS_oldnumcol;i++) {
+		*oldpalette++=Setcolor(i,-1);
+	}
+}
+
+static void setMode_ST(_THIS, xbiosmode_t *new_video_mode)
+{
+	int i;
+
+	Setscreen(-1,XBIOS_screens[0],-1);
+
+	Setscreen(-1,-1,new_video_mode->number);
+
+	/* Reset palette, 8 shades of gray with a bit of green interleaved */
+	for (i=0;i<16;i++) {
+		TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1);
+	}
+	Setpalette(TT_palette);
+}
+
+static void setMode_STE(_THIS, xbiosmode_t *new_video_mode)
+{
+	int i;
+
+	Setscreen(-1,XBIOS_screens[0],-1);
+
+	Setscreen(-1,-1,new_video_mode->number);
+
+	/* Reset palette, 16 shades of gray */
+	for (i=0;i<16;i++) {
+		int c;
+
+		c=((i&1)<<3)|((i>>1)&7);
+		TT_palette[i]=(c<<8)|(c<<4)|c;
+	}
+	Setpalette(TT_palette);
+}
+
+static void restoreMode(_THIS)
+{
+	Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode);
+
+	if (XBIOS_oldnumcol) {
+		Setpalette(XBIOS_oldpalette);
+	}
+}
+
+static void swapVbuffers(_THIS)
+{
+	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
+}
+
+static int allocVbuffers(_THIS, int num_buffers, int bufsize)
+{
+	int i;
+
+	for (i=0; i<num_buffers; i++) {
+		XBIOS_screensmem[i] = Atari_SysMalloc(bufsize, MX_STRAM);
+
+		if (XBIOS_screensmem[i]==NULL) {
+			SDL_SetError("Can not allocate %d KB for buffer %d", bufsize>>10, i);
+			return (0);
+		}
+		SDL_memset(XBIOS_screensmem[i], 0, bufsize);
+
+		XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
+	}
+
+	return (1);
+}
+
+static void freeVbuffers(_THIS)
+{
+	int i;
+
+	for (i=0;i<2;i++) {
+		if (XBIOS_screensmem[i]) {
+			Mfree(XBIOS_screensmem[i]);
+		}
+		XBIOS_screensmem[i]=NULL;
+	}
+}
+
+static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
+{
+	int	i, r,g,b;
+
+ 	for (i=0;i<ncolors;i++) {
+		r = colors[i].r;	
+		g = colors[i].g;
+		b = colors[i].b;
+
+		TT_palette[firstcolor+i]=((r*30)+(g*59)+(b*11))/100;
+	}
+
+	SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */
+
+	return(1);
+}