atari:xbios: Move all Milan specific stuff to specific backend file. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Wed, 30 Jul 2014 11:36:59 +0200
branchSDL-1.2
changeset 9026 5b91761249f9
parent 9024 372ca9a5be7c
child 9027 3165f185d1ea
atari:xbios: Move all Milan specific stuff to specific backend file.
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios.h
src/video/xbios/SDL_xbios_milan.c
src/video/xbios/SDL_xbios_milan.h
--- a/src/video/xbios/SDL_xbios.c	Tue Jul 29 17:02:37 2014 +0200
+++ b/src/video/xbios/SDL_xbios.c	Wed Jul 30 11:36:59 2014 +0200
@@ -90,11 +90,6 @@
 static void XBIOS_GL_SwapBuffers(_THIS);
 #endif
 
-/* To setup palette */
-
-static unsigned short	TT_palette[256];
-static unsigned long	F30_palette[256];
-
 /* Default list of video modes */
 
 static const xbiosmode_t stmodes[1]={
@@ -202,6 +197,7 @@
 static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
 {
 	SDL_VideoDevice *device;
+	long cookie_cvdo;
 
 	/* Initialize all variables that we clean on shutdown */
 	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
@@ -250,6 +246,17 @@
 
 	device->free = XBIOS_DeleteDevice;
 
+	/* Setup device specific functions, default to ST for everything */
+	if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) {
+		cookie_cvdo = VDO_ST << 16;
+	}
+
+	switch (cookie_cvdo>>16) {
+		case VDO_MILAN:
+			SDL_XBIOS_VideoInit_Milan(device);
+			break;
+	}
+
 	return device;
 }
 
@@ -489,32 +496,8 @@
 			}
 			break;
 		case VDO_MILAN:
-			{
-				SCREENINFO si;
-
-				/* Read infos about current mode */ 
-				VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);
-
-				si.size = sizeof(SCREENINFO);
-				si.devID = XBIOS_oldvmode;
-				si.scrFlags = 0;
-				VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);
-
-				this->info.current_w = si.scrWidth;
-				this->info.current_h = si.scrHeight;
-
-				XBIOS_oldnumcol = 0;
-				if (si.scrFlags & SCRINFO_OK) {
-					if (si.scrPlanes <= 8) {
-						XBIOS_oldnumcol = 1<<si.scrPlanes;
-					}
-				}
-				if (XBIOS_oldnumcol) {
-					VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
-				}
-
-				SDL_XBIOS_ListMilanModes(this, 0);
-			}
+			(*XBIOS_saveMode)(this, vformat);
+			(*XBIOS_listModes)(this, 0);
 			break;
 	}
 
@@ -592,7 +575,7 @@
 			}
 			break;
 		case VDO_MILAN:
-			SDL_XBIOS_ListMilanModes(this, 1);
+			(*XBIOS_listModes)(this, 1);
 			break;
 	}
 
@@ -629,13 +612,11 @@
 {
 	int i;
 
-	for (i=0;i<2;i++) {
-		if (XBIOS_screensmem[i]!=NULL) {
-			if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-				if (i==1) {
-					VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
-				}
-			} else {
+	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;
@@ -723,25 +704,24 @@
 	}
 
 	/* Allocate buffers */
-	for (i=0; i<num_buffers; i++) {
-		if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-			if (i==0) {
-				XBIOS_screensmem[i] = XBIOS_oldvbase;
-			} else {
-				VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
-			}
-		} else {
-			XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
-		}
-
-		if (XBIOS_screensmem[i]==NULL) {
+	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
+		if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
 			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);
+	} else {
+		for (i=0; i<num_buffers; i++) {
+			XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
 
-		XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
+			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);
+		}
 	}
 
 	/* Allocate the new pixel format for the screen */
@@ -782,9 +762,7 @@
 
 #ifndef DEBUG_VIDEO_XBIOS
 	/* Now set the video mode */
-	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);
-	} else {
+	if ((XBIOS_cvdo>>16) != VDO_MILAN) {
 		Setscreen(-1,XBIOS_screens[0],-1);
 	}
 
@@ -828,13 +806,7 @@
 			}
 			break;
 		case VDO_MILAN:
-			VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);
-
-			/* Set hardware palette to black in True Colour */
-			if (new_depth > 8) {
-				SDL_memset(F30_palette, 0, sizeof(F30_palette));
-				VsetRGB(0,256,F30_palette);
-			}
+			(*XBIOS_setMode)(this, new_video_mode);
 			break;
 	}
 
@@ -910,7 +882,7 @@
 
 #ifndef DEBUG_VIDEO_XBIOS
 	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
+		(*XBIOS_swapVbuffers)(this);
 	} else {
 		Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
 	}
@@ -954,7 +926,7 @@
 
 #ifndef DEBUG_VIDEO_XBIOS
 	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
-		VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
+		(*XBIOS_swapVbuffers)(this);
 	} else {
 		Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
 	}
@@ -1003,7 +975,6 @@
 			EsetPalette(firstcolor,ncolors,TT_palette);
 			break;
 		case VDO_F30:
-		case VDO_MILAN:
 			for(i = 0; i < ncolors; i++)
 			{
 				r = colors[i].r;	
@@ -1058,11 +1029,7 @@
 			}
 			break;
 		case VDO_MILAN:
-			VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
-			VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
-			if (XBIOS_oldnumcol) {
-				VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
-			}
+			(*XBIOS_restoreMode)(this);
 			break;
 	}
 	Vsync();
--- a/src/video/xbios/SDL_xbios.h	Tue Jul 29 17:02:37 2014 +0200
+++ b/src/video/xbios/SDL_xbios.h	Wed Jul 30 11:36:59 2014 +0200
@@ -64,6 +64,19 @@
 	int SDL_nummodes[NUM_MODELISTS];
 	SDL_Rect **SDL_modelist[NUM_MODELISTS];
 	xbiosmode_t **SDL_xbiosmode[NUM_MODELISTS];
+
+	union {
+		Uint16 pal16[16];
+		Uint32 pal32[256];
+	} palette;
+
+	void (*listModes)(_THIS, int actually_add);	/* List video modes */
+	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 */
+	void (*swapVbuffers)(_THIS);	/* Swap video buffers */
+	int (*allocVbuffers)(_THIS, int num_buffers, int bufsize);	/* Allocate video buffers */
+	void (*freeVbuffers)(_THIS);	/* Free video buffers */
 };
 
 /* _VDO cookie values */
@@ -104,8 +117,22 @@
 #define XBIOS_centscreen	(this->hidden->centscreen)
 #define XBIOS_current		(this->hidden->current)
 
+#define TT_palette		(this->hidden->palette.pal16)
+#define F30_palette		(this->hidden->palette.pal32)
+
+#define XBIOS_listModes		(this->hidden->listModes)
+#define XBIOS_saveMode		(this->hidden->saveMode)
+#define XBIOS_setMode		(this->hidden->setMode)
+#define XBIOS_restoreMode	(this->hidden->restoreMode)
+#define XBIOS_swapVbuffers	(this->hidden->swapVbuffers)
+#define XBIOS_allocVbuffers	(this->hidden->allocVbuffers)
+#define XBIOS_freeVbuffers	(this->hidden->freeVbuffers)
+
 /*--- Functions prototypes ---*/
 
 void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo);
 
+/* SDL_xbios_milan.c */
+void SDL_XBIOS_VideoInit_Milan(_THIS);
+
 #endif /* _SDL_xbios_h */
--- a/src/video/xbios/SDL_xbios_milan.c	Tue Jul 29 17:02:37 2014 +0200
+++ b/src/video/xbios/SDL_xbios_milan.c	Wed Jul 30 11:36:59 2014 +0200
@@ -60,6 +60,28 @@
 
 /*--- Functions ---*/
 
+static void listModes(_THIS, int actually_add);
+static void saveMode(_THIS, SDL_PixelFormat *vformat);
+static void setMode(_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_Milan(_THIS)
+{
+	XBIOS_listModes = listModes;
+	XBIOS_saveMode = saveMode;
+	XBIOS_setMode = setMode;
+	XBIOS_restoreMode = restoreMode;
+	XBIOS_swapVbuffers = swapVbuffers;
+	XBIOS_allocVbuffers = allocVbuffers;
+	XBIOS_freeVbuffers = freeVbuffers;
+
+	this->SetColors = setColors;
+}
+
 static unsigned long /*cdecl*/ enumfunc(SCREENINFO *inf, unsigned long flag)
 {
 	xbiosmode_t modeinfo;
@@ -75,7 +97,7 @@
 	return ENUMMODE_CONT; 
 } 
 
-void SDL_XBIOS_ListMilanModes(_THIS, int actually_add)
+static void listModes(_THIS, int actually_add)
 {
 	int i;
 
@@ -104,3 +126,112 @@
 	enum_actually_add = actually_add;
 	VsetScreen(-1, &enumfunc, MI_MAGIC, CMD_ENUMMODES);
 }
+
+static void saveMode(_THIS, SDL_PixelFormat *vformat)
+{
+	SCREENINFO si;
+
+	/* Read infos about current mode */ 
+	VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);
+
+	si.size = sizeof(SCREENINFO);
+	si.devID = XBIOS_oldvmode;
+	si.scrFlags = 0;
+	VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);
+
+	this->info.current_w = si.scrWidth;
+	this->info.current_h = si.scrHeight;
+
+	XBIOS_oldnumcol = 0;
+	if (si.scrFlags & SCRINFO_OK) {
+		if (si.scrPlanes <= 8) {
+			XBIOS_oldnumcol = 1<<si.scrPlanes;
+		}
+	}
+	if (XBIOS_oldnumcol) {
+		VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
+	}
+}
+
+static void setMode(_THIS, xbiosmode_t *new_video_mode)
+{
+	VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);
+
+	VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);
+
+	/* Set hardware palette to black in True Colour */
+	if (new_video_mode->depth > 8) {
+		SDL_memset(F30_palette, 0, sizeof(F30_palette));
+		VsetRGB(0,256,F30_palette);
+	}
+}
+
+static void restoreMode(_THIS)
+{
+	VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
+	VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
+	if (XBIOS_oldnumcol) {
+		VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
+	}
+}
+
+static void swapVbuffers(_THIS)
+{
+	VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
+}
+
+static int allocVbuffers(_THIS, int num_buffers, int bufsize)
+{
+	int i;
+
+	for (i=0; i<num_buffers; i++) {
+		if (i==0) {
+			/* Buffer 0 is current screen */
+			XBIOS_screensmem[i] = XBIOS_oldvbase;
+		} else {
+			VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
+		}
+
+		if (!XBIOS_screensmem[i]) {
+			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]=XBIOS_screensmem[i];
+	}
+
+	return (1);
+}
+
+static void freeVbuffers(_THIS)
+{
+	int i;
+
+	for (i=0;i<2;i++) {
+		if (XBIOS_screensmem[i]) {
+			if (i==1) {
+				VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
+			} else {
+				/* Do not touch buffer 0 */
+			}
+			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;
+
+		F30_palette[i]=(r<<16)|(g<<8)|b;
+	}
+	VsetRGB(firstcolor,ncolors,F30_palette);
+
+	return (1);
+}
--- a/src/video/xbios/SDL_xbios_milan.h	Tue Jul 29 17:02:37 2014 +0200
+++ b/src/video/xbios/SDL_xbios_milan.h	Wed Jul 30 11:36:59 2014 +0200
@@ -209,8 +209,4 @@
 	long blk_pattern;	/* pattern (-1: solid line)     */
 } SCRLINEMEMBLK;
 
-/*--- Functions prototypes ---*/
-
-void SDL_XBIOS_ListMilanModes(_THIS, int actually_add);
-
 #endif /* _SDL_xbios_milan_h */