diff src/video/xbios/SDL_xbios.c @ 1042:0e7218843cfb

Dynamically create list of video modes, easier to add new ones
author Patrice Mandin <patmandin@gmail.com>
date Mon, 07 Mar 2005 10:00:58 +0000
parents c6ed27c7d47d
children 21d1d05aad39
line wrap: on
line diff
--- a/src/video/xbios/SDL_xbios.c	Wed Mar 02 17:17:26 2005 +0000
+++ b/src/video/xbios/SDL_xbios.c	Mon Mar 07 10:00:58 2005 +0000
@@ -60,7 +60,17 @@
 
 #define XBIOS_VID_DRIVER_NAME "xbios"
 
+/* Debug print info */
+#if 1
+#define DEBUG_PRINT(what) \
+	{ \
+		printf what; \
+	}
 /*#define DEBUG_VIDEO_XBIOS 1*/
+#else
+#define DEBUG_PRINT(what)
+#undef DEBUG_VIDEO_XBIOS
+#endif
 
 /* Initialization/Query functions */
 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
@@ -82,55 +92,6 @@
 static void XBIOS_GL_SwapBuffers(_THIS);
 #endif
 
-/* List of video modes */
-
-/* ST modes */
-static int xbiosnummodes_st=1;
-static xbiosmode_t xbiosmodelist_st[]={
-	{ST_LOW>>8,320,200,4,SDL_FALSE}
-};
-
-/* TT modes */
-static int xbiosnummodes_tt=2;
-static xbiosmode_t xbiosmodelist_tt[]={
-	{TT_LOW,320,480,8,SDL_FALSE},
-	{TT_LOW,320,240,8,SDL_TRUE}	/* Software double-lined mode */
-};
-
-/* Falcon RVB modes */
-static int xbiosnummodes_f30rvb=16;
-static xbiosmode_t xbiosmodelist_f30rvb[]={
-	{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE},
-	{BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
-	{BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
-	{BPS16|COL80,640,200,16,SDL_FALSE},
-	{BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
-	{BPS16|OVERSCAN,384,240,16,SDL_FALSE},
-	{BPS16|VERTFLAG,320,400,16,SDL_FALSE},
-	{BPS16,320,200,16,SDL_FALSE},
-
-	{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE},
-	{BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
-	{BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
-	{BPS8|COL80,640,200,8,SDL_FALSE},
-	{BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
-	{BPS8|OVERSCAN,384,240,8,SDL_FALSE},
-	{BPS8|VERTFLAG,320,400,8,SDL_FALSE},
-	{BPS8,320,200,8,SDL_FALSE}
-};
-
-/* Falcon VGA modes */
-static int xbiosnummodes_f30vga=6;
-static xbiosmode_t xbiosmodelist_f30vga[]={
-	{BPS16,320,480,16,SDL_FALSE},
-	{BPS16|VERTFLAG,320,240,16,SDL_FALSE},
-
-	{BPS8|COL80,640,480,8,SDL_FALSE},	
-	{BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
-	{BPS8,320,480,8,SDL_FALSE},
-	{BPS8|VERTFLAG,320,240,8,SDL_FALSE}
-};
-
 /* To setup palette */
 
 static unsigned short	TT_palette[256];
@@ -245,6 +206,57 @@
 	XBIOS_Available, XBIOS_CreateDevice
 };
 
+void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height,
+	Uint16 depth, SDL_bool flags)
+{
+	int i, curpos;
+	xbiosmode_t *current_mode;
+
+	/* Check if mode already exists */
+	if (XBIOS_modelist) {
+		current_mode = XBIOS_modelist;
+		for (i=0;i<XBIOS_nummodes; i++, current_mode++) {
+			if (current_mode->width != width)
+				continue;
+			if (current_mode->height != height)
+				continue;
+			if (current_mode->depth != depth)
+				continue;
+			return;
+		}
+	}
+
+	++XBIOS_nummodes;
+	XBIOS_modelist = (xbiosmode_t *) realloc(XBIOS_modelist, XBIOS_nummodes * sizeof(xbiosmode_t));
+
+	/* Keep the list sorted: bpp, width, height */
+	curpos=0;
+
+	for(i=0; i<XBIOS_nummodes-1; i++) {
+		if (XBIOS_modelist[i].depth <= depth) {
+			if (XBIOS_modelist[i].width < width) {
+				break;
+			} else if (XBIOS_modelist[i].width == width) {
+				if (XBIOS_modelist[i].height <= height) {
+					break;
+				}
+			}
+		}
+		curpos++;
+	}
+
+	/* Push remaining modes further */
+	for(i=XBIOS_nummodes-1; i>curpos; i--) {
+		memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i-1], sizeof(xbiosmode_t));
+	}
+
+	XBIOS_modelist[curpos].number = modecode;
+	XBIOS_modelist[curpos].width = width;
+	XBIOS_modelist[curpos].height = height;
+	XBIOS_modelist[curpos].depth = depth;
+	XBIOS_modelist[curpos].doubleline = flags;
+}
+
 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
 {
 	int i,j8,j16;
@@ -268,6 +280,8 @@
 
 	/* Initialize video mode list */
 	/* and save current screen status (palette, screen address, video mode) */
+	XBIOS_nummodes = 0;
+	XBIOS_modelist = NULL;
 
 	switch (XBIOS_cvdo >>16) {
 		case VDO_ST:
@@ -275,8 +289,7 @@
 			{
 				short *oldpalette;
 
-				XBIOS_nummodes=xbiosnummodes_st;
-				XBIOS_modelist=xbiosmodelist_st;
+				SDL_XBIOS_AddMode(this, ST_LOW>>8,320,200,4,SDL_FALSE);
 			
 				XBIOS_oldvbase=Physbase();
 				XBIOS_oldvmode=Getrez();
@@ -304,8 +317,10 @@
 			}
 			break;
 		case VDO_TT:
-			XBIOS_nummodes=xbiosnummodes_tt;
-			XBIOS_modelist=xbiosmodelist_tt;
+
+			SDL_XBIOS_AddMode(this, TT_LOW,320,480,8,SDL_FALSE);
+			/* Software double-lined mode */
+			SDL_XBIOS_AddMode(this, TT_LOW,320,240,8,SDL_TRUE);
 
 			XBIOS_oldvbase=Logbase();
 			XBIOS_oldvmode=EgetShift();
@@ -343,12 +358,30 @@
 					break;
 				case MONITOR_RGB:
 				case MONITOR_TV:
-					XBIOS_nummodes = xbiosnummodes_f30rvb;
-					XBIOS_modelist = xbiosmodelist_f30rvb;
+					SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|COL80,640,200,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|OVERSCAN,384,240,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,400,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16,320,200,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|COL80,640,200,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|OVERSCAN,384,240,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,400,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8,320,200,8,SDL_FALSE);
 					break;
 				case MONITOR_VGA:
-					XBIOS_nummodes = xbiosnummodes_f30vga;
-					XBIOS_modelist = xbiosmodelist_f30vga;
+					SDL_XBIOS_AddMode(this, BPS16,320,480,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,240,16,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|COL80,640,480,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8,320,480,8,SDL_FALSE);
+					SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,240,8,SDL_FALSE);
 					break;
 			}
 			XBIOS_oldvbase=Logbase();
@@ -386,10 +419,10 @@
 
 			break;
 	}
-	
+
 	current_mode = XBIOS_modelist;
 	j8 = j16 = 0;
-	for (i=0;i<XBIOS_nummodes;i++) {
+	for (i=0; i<XBIOS_nummodes; i++, current_mode++) {
 		switch (current_mode->depth) {
 			case 4:
 			case 8:
@@ -398,7 +431,6 @@
 				SDL_modelist[0][j8]->w = current_mode->width;
 				SDL_modelist[0][j8]->h = current_mode->height;
 				XBIOS_videomodes[0][j8]=current_mode;
-				current_mode++;
 				j8++;
 				break;
 			case 16:
@@ -407,7 +439,6 @@
 				SDL_modelist[1][j16]->w = current_mode->width;
 				SDL_modelist[1][j16]->h = current_mode->height;
 				XBIOS_videomodes[1][j16]=current_mode;
-				current_mode++;
 				j16++;
 				break;
 		}		
@@ -891,6 +922,12 @@
 		}
 	}
 
+	if (XBIOS_modelist) {
+		free(XBIOS_modelist);
+		XBIOS_nummodes=0;
+		XBIOS_modelist=NULL;
+	}
+
 	this->screen->pixels = NULL;	
 }