Dynamically create list of video modes, easier to add new ones
authorPatrice Mandin <patmandin@gmail.com>
Mon, 07 Mar 2005 10:00:58 +0000
changeset 10420e7218843cfb
parent 1041 af92ee34b3e2
child 1043 21d1d05aad39
Dynamically create list of video modes, easier to add new ones
README.MiNT
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios.h
src/video/xbios/SDL_xbios_blowup.c
src/video/xbios/SDL_xbios_sb3.c
     1.1 --- a/README.MiNT	Wed Mar 02 17:17:26 2005 +0000
     1.2 +++ b/README.MiNT	Mon Mar 07 10:00:58 2005 +0000
     1.3 @@ -156,6 +156,7 @@
     1.4  		320x480x8 and 320x240x8 (software double-lined mode).
     1.5  	Falcon:
     1.6  		All modes supported by the current monitor (RVB or VGA).
     1.7 +		BlowUp extended modes, ScreenBlaster 3 current mode.
     1.8  	Clones and any machine with monochrome monitor:
     1.9  		Not supported.
    1.10  
     2.1 --- a/src/video/xbios/SDL_xbios.c	Wed Mar 02 17:17:26 2005 +0000
     2.2 +++ b/src/video/xbios/SDL_xbios.c	Mon Mar 07 10:00:58 2005 +0000
     2.3 @@ -60,7 +60,17 @@
     2.4  
     2.5  #define XBIOS_VID_DRIVER_NAME "xbios"
     2.6  
     2.7 +/* Debug print info */
     2.8 +#if 1
     2.9 +#define DEBUG_PRINT(what) \
    2.10 +	{ \
    2.11 +		printf what; \
    2.12 +	}
    2.13  /*#define DEBUG_VIDEO_XBIOS 1*/
    2.14 +#else
    2.15 +#define DEBUG_PRINT(what)
    2.16 +#undef DEBUG_VIDEO_XBIOS
    2.17 +#endif
    2.18  
    2.19  /* Initialization/Query functions */
    2.20  static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
    2.21 @@ -82,55 +92,6 @@
    2.22  static void XBIOS_GL_SwapBuffers(_THIS);
    2.23  #endif
    2.24  
    2.25 -/* List of video modes */
    2.26 -
    2.27 -/* ST modes */
    2.28 -static int xbiosnummodes_st=1;
    2.29 -static xbiosmode_t xbiosmodelist_st[]={
    2.30 -	{ST_LOW>>8,320,200,4,SDL_FALSE}
    2.31 -};
    2.32 -
    2.33 -/* TT modes */
    2.34 -static int xbiosnummodes_tt=2;
    2.35 -static xbiosmode_t xbiosmodelist_tt[]={
    2.36 -	{TT_LOW,320,480,8,SDL_FALSE},
    2.37 -	{TT_LOW,320,240,8,SDL_TRUE}	/* Software double-lined mode */
    2.38 -};
    2.39 -
    2.40 -/* Falcon RVB modes */
    2.41 -static int xbiosnummodes_f30rvb=16;
    2.42 -static xbiosmode_t xbiosmodelist_f30rvb[]={
    2.43 -	{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE},
    2.44 -	{BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
    2.45 -	{BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
    2.46 -	{BPS16|COL80,640,200,16,SDL_FALSE},
    2.47 -	{BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
    2.48 -	{BPS16|OVERSCAN,384,240,16,SDL_FALSE},
    2.49 -	{BPS16|VERTFLAG,320,400,16,SDL_FALSE},
    2.50 -	{BPS16,320,200,16,SDL_FALSE},
    2.51 -
    2.52 -	{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE},
    2.53 -	{BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
    2.54 -	{BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
    2.55 -	{BPS8|COL80,640,200,8,SDL_FALSE},
    2.56 -	{BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
    2.57 -	{BPS8|OVERSCAN,384,240,8,SDL_FALSE},
    2.58 -	{BPS8|VERTFLAG,320,400,8,SDL_FALSE},
    2.59 -	{BPS8,320,200,8,SDL_FALSE}
    2.60 -};
    2.61 -
    2.62 -/* Falcon VGA modes */
    2.63 -static int xbiosnummodes_f30vga=6;
    2.64 -static xbiosmode_t xbiosmodelist_f30vga[]={
    2.65 -	{BPS16,320,480,16,SDL_FALSE},
    2.66 -	{BPS16|VERTFLAG,320,240,16,SDL_FALSE},
    2.67 -
    2.68 -	{BPS8|COL80,640,480,8,SDL_FALSE},	
    2.69 -	{BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
    2.70 -	{BPS8,320,480,8,SDL_FALSE},
    2.71 -	{BPS8|VERTFLAG,320,240,8,SDL_FALSE}
    2.72 -};
    2.73 -
    2.74  /* To setup palette */
    2.75  
    2.76  static unsigned short	TT_palette[256];
    2.77 @@ -245,6 +206,57 @@
    2.78  	XBIOS_Available, XBIOS_CreateDevice
    2.79  };
    2.80  
    2.81 +void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height,
    2.82 +	Uint16 depth, SDL_bool flags)
    2.83 +{
    2.84 +	int i, curpos;
    2.85 +	xbiosmode_t *current_mode;
    2.86 +
    2.87 +	/* Check if mode already exists */
    2.88 +	if (XBIOS_modelist) {
    2.89 +		current_mode = XBIOS_modelist;
    2.90 +		for (i=0;i<XBIOS_nummodes; i++, current_mode++) {
    2.91 +			if (current_mode->width != width)
    2.92 +				continue;
    2.93 +			if (current_mode->height != height)
    2.94 +				continue;
    2.95 +			if (current_mode->depth != depth)
    2.96 +				continue;
    2.97 +			return;
    2.98 +		}
    2.99 +	}
   2.100 +
   2.101 +	++XBIOS_nummodes;
   2.102 +	XBIOS_modelist = (xbiosmode_t *) realloc(XBIOS_modelist, XBIOS_nummodes * sizeof(xbiosmode_t));
   2.103 +
   2.104 +	/* Keep the list sorted: bpp, width, height */
   2.105 +	curpos=0;
   2.106 +
   2.107 +	for(i=0; i<XBIOS_nummodes-1; i++) {
   2.108 +		if (XBIOS_modelist[i].depth <= depth) {
   2.109 +			if (XBIOS_modelist[i].width < width) {
   2.110 +				break;
   2.111 +			} else if (XBIOS_modelist[i].width == width) {
   2.112 +				if (XBIOS_modelist[i].height <= height) {
   2.113 +					break;
   2.114 +				}
   2.115 +			}
   2.116 +		}
   2.117 +		curpos++;
   2.118 +	}
   2.119 +
   2.120 +	/* Push remaining modes further */
   2.121 +	for(i=XBIOS_nummodes-1; i>curpos; i--) {
   2.122 +		memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i-1], sizeof(xbiosmode_t));
   2.123 +	}
   2.124 +
   2.125 +	XBIOS_modelist[curpos].number = modecode;
   2.126 +	XBIOS_modelist[curpos].width = width;
   2.127 +	XBIOS_modelist[curpos].height = height;
   2.128 +	XBIOS_modelist[curpos].depth = depth;
   2.129 +	XBIOS_modelist[curpos].doubleline = flags;
   2.130 +}
   2.131 +
   2.132  static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
   2.133  {
   2.134  	int i,j8,j16;
   2.135 @@ -268,6 +280,8 @@
   2.136  
   2.137  	/* Initialize video mode list */
   2.138  	/* and save current screen status (palette, screen address, video mode) */
   2.139 +	XBIOS_nummodes = 0;
   2.140 +	XBIOS_modelist = NULL;
   2.141  
   2.142  	switch (XBIOS_cvdo >>16) {
   2.143  		case VDO_ST:
   2.144 @@ -275,8 +289,7 @@
   2.145  			{
   2.146  				short *oldpalette;
   2.147  
   2.148 -				XBIOS_nummodes=xbiosnummodes_st;
   2.149 -				XBIOS_modelist=xbiosmodelist_st;
   2.150 +				SDL_XBIOS_AddMode(this, ST_LOW>>8,320,200,4,SDL_FALSE);
   2.151  			
   2.152  				XBIOS_oldvbase=Physbase();
   2.153  				XBIOS_oldvmode=Getrez();
   2.154 @@ -304,8 +317,10 @@
   2.155  			}
   2.156  			break;
   2.157  		case VDO_TT:
   2.158 -			XBIOS_nummodes=xbiosnummodes_tt;
   2.159 -			XBIOS_modelist=xbiosmodelist_tt;
   2.160 +
   2.161 +			SDL_XBIOS_AddMode(this, TT_LOW,320,480,8,SDL_FALSE);
   2.162 +			/* Software double-lined mode */
   2.163 +			SDL_XBIOS_AddMode(this, TT_LOW,320,240,8,SDL_TRUE);
   2.164  
   2.165  			XBIOS_oldvbase=Logbase();
   2.166  			XBIOS_oldvmode=EgetShift();
   2.167 @@ -343,12 +358,30 @@
   2.168  					break;
   2.169  				case MONITOR_RGB:
   2.170  				case MONITOR_TV:
   2.171 -					XBIOS_nummodes = xbiosnummodes_f30rvb;
   2.172 -					XBIOS_modelist = xbiosmodelist_f30rvb;
   2.173 +					SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE);
   2.174 +					SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE);
   2.175 +					SDL_XBIOS_AddMode(this, BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE);
   2.176 +					SDL_XBIOS_AddMode(this, BPS16|COL80,640,200,16,SDL_FALSE);
   2.177 +					SDL_XBIOS_AddMode(this, BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE);
   2.178 +					SDL_XBIOS_AddMode(this, BPS16|OVERSCAN,384,240,16,SDL_FALSE);
   2.179 +					SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,400,16,SDL_FALSE);
   2.180 +					SDL_XBIOS_AddMode(this, BPS16,320,200,16,SDL_FALSE);
   2.181 +					SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE);
   2.182 +					SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE);
   2.183 +					SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE);
   2.184 +					SDL_XBIOS_AddMode(this, BPS8|COL80,640,200,8,SDL_FALSE);
   2.185 +					SDL_XBIOS_AddMode(this, BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE);
   2.186 +					SDL_XBIOS_AddMode(this, BPS8|OVERSCAN,384,240,8,SDL_FALSE);
   2.187 +					SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,400,8,SDL_FALSE);
   2.188 +					SDL_XBIOS_AddMode(this, BPS8,320,200,8,SDL_FALSE);
   2.189  					break;
   2.190  				case MONITOR_VGA:
   2.191 -					XBIOS_nummodes = xbiosnummodes_f30vga;
   2.192 -					XBIOS_modelist = xbiosmodelist_f30vga;
   2.193 +					SDL_XBIOS_AddMode(this, BPS16,320,480,16,SDL_FALSE);
   2.194 +					SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,240,16,SDL_FALSE);
   2.195 +					SDL_XBIOS_AddMode(this, BPS8|COL80,640,480,8,SDL_FALSE);
   2.196 +					SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE);
   2.197 +					SDL_XBIOS_AddMode(this, BPS8,320,480,8,SDL_FALSE);
   2.198 +					SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,240,8,SDL_FALSE);
   2.199  					break;
   2.200  			}
   2.201  			XBIOS_oldvbase=Logbase();
   2.202 @@ -386,10 +419,10 @@
   2.203  
   2.204  			break;
   2.205  	}
   2.206 -	
   2.207 +
   2.208  	current_mode = XBIOS_modelist;
   2.209  	j8 = j16 = 0;
   2.210 -	for (i=0;i<XBIOS_nummodes;i++) {
   2.211 +	for (i=0; i<XBIOS_nummodes; i++, current_mode++) {
   2.212  		switch (current_mode->depth) {
   2.213  			case 4:
   2.214  			case 8:
   2.215 @@ -398,7 +431,6 @@
   2.216  				SDL_modelist[0][j8]->w = current_mode->width;
   2.217  				SDL_modelist[0][j8]->h = current_mode->height;
   2.218  				XBIOS_videomodes[0][j8]=current_mode;
   2.219 -				current_mode++;
   2.220  				j8++;
   2.221  				break;
   2.222  			case 16:
   2.223 @@ -407,7 +439,6 @@
   2.224  				SDL_modelist[1][j16]->w = current_mode->width;
   2.225  				SDL_modelist[1][j16]->h = current_mode->height;
   2.226  				XBIOS_videomodes[1][j16]=current_mode;
   2.227 -				current_mode++;
   2.228  				j16++;
   2.229  				break;
   2.230  		}		
   2.231 @@ -891,6 +922,12 @@
   2.232  		}
   2.233  	}
   2.234  
   2.235 +	if (XBIOS_modelist) {
   2.236 +		free(XBIOS_modelist);
   2.237 +		XBIOS_nummodes=0;
   2.238 +		XBIOS_modelist=NULL;
   2.239 +	}
   2.240 +
   2.241  	this->screen->pixels = NULL;	
   2.242  }
   2.243  
     3.1 --- a/src/video/xbios/SDL_xbios.h	Wed Mar 02 17:17:26 2005 +0000
     3.2 +++ b/src/video/xbios/SDL_xbios.h	Mon Mar 07 10:00:58 2005 +0000
     3.3 @@ -124,4 +124,9 @@
     3.4  #define XBIOS_width			(this->hidden->width)
     3.5  #define XBIOS_height		(this->hidden->height)
     3.6  
     3.7 +/*--- Functions prototypes ---*/
     3.8 +
     3.9 +void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height,
    3.10 +	Uint16 depth, SDL_bool flags);
    3.11 +
    3.12  #endif /* _SDL_xbios_h */
     4.1 --- a/src/video/xbios/SDL_xbios_blowup.c	Wed Mar 02 17:17:26 2005 +0000
     4.2 +++ b/src/video/xbios/SDL_xbios_blowup.c	Mon Mar 07 10:00:58 2005 +0000
     4.3 @@ -26,68 +26,44 @@
     4.4  	Patrice Mandin
     4.5  */
     4.6  
     4.7 +#include <mint/falcon.h>
     4.8 +
     4.9  #include "SDL_xbios.h"
    4.10  #include "SDL_xbios_blowup.h"
    4.11  
    4.12  void SDL_XBIOS_BlowupInit(_THIS, blow_cookie_t *cookie_blow)
    4.13  {
    4.14 -	int i, num_mode, bank, keep_old;
    4.15 -	xbiosmode_t *current_mode;
    4.16 +	int i, num_mode, bank;
    4.17  	blow_mode_t *blow_mode;
    4.18  
    4.19 -	current_mode = XBIOS_modelist;
    4.20 +	/* Add bit 15 for old modes */
    4.21  	for (i=0;i<XBIOS_nummodes;i++) {
    4.22 -		keep_old=1;	/* use default mode */
    4.23 -		blow_mode = NULL;
    4.24 -		switch (current_mode->depth) {
    4.25 -			case 1:
    4.26 -				num_mode=0;
    4.27 -				break;
    4.28 -			case 2:
    4.29 -				num_mode=1;
    4.30 -				break;
    4.31 -			case 4:
    4.32 -				num_mode=2;
    4.33 -				break;
    4.34 -			case 8:
    4.35 -				num_mode=3;
    4.36 -				break;
    4.37 -			case 16:
    4.38 -				num_mode=4;
    4.39 -				break;
    4.40 -			default:
    4.41 -				num_mode=-1;
    4.42 -				break;
    4.43 -		}
    4.44 +		XBIOS_modelist[i].number |= 1<<15;
    4.45 +	}
    4.46  
    4.47 -		/* Check which bank of modes to use */
    4.48 -		if (num_mode>=0) {
    4.49 -			bank = cookie_blow->num_mode[num_mode];
    4.50 -			blow_mode = &(cookie_blow->blowup_modes[num_mode+(bank*5)]);
    4.51 -	
    4.52 -			/* Check extended mode enabled */
    4.53 -			if (blow_mode->enabled == 0) {
    4.54 -				/* Check monitor needed for this mode */
    4.55 -				if ((blow_mode->monitor == cookie_blow->montype)
    4.56 -					|| ((blow_mode->monitor == MONITOR_TV)
    4.57 -						&& (cookie_blow->montype == MONITOR_RGB))
    4.58 -					|| ((blow_mode->monitor == MONITOR_RGB)
    4.59 -						&& (cookie_blow->montype == MONITOR_TV)))
    4.60 -				{
    4.61 -					keep_old = 0; /* we can use this extended mode */
    4.62 -				}
    4.63 +	/* Add Blowup modes for 8 and 16 bpp */
    4.64 +	for (num_mode=3; num_mode<5; num_mode++) {
    4.65 +		bank = cookie_blow->num_mode[num_mode];
    4.66 +		blow_mode = &(cookie_blow->blowup_modes[num_mode+(bank*5)]);
    4.67 +
    4.68 +		/* Check extended mode enabled */
    4.69 +		if (blow_mode->enabled == 0) {
    4.70 +			/* Check monitor needed for this mode */
    4.71 +			if ((blow_mode->monitor == cookie_blow->montype)
    4.72 +				|| ((blow_mode->monitor == MONITOR_TV)
    4.73 +					&& (cookie_blow->montype == MONITOR_RGB))
    4.74 +				|| ((blow_mode->monitor == MONITOR_RGB)
    4.75 +					&& (cookie_blow->montype == MONITOR_TV)))
    4.76 +			{
    4.77 +				/* we can use this extended mode */
    4.78 +				SDL_XBIOS_AddMode(this,
    4.79 +					num_mode == 3 ? BPS8 : BPS16,
    4.80 +					blow_mode->width + 1,
    4.81 +					blow_mode->height + 1,
    4.82 +					num_mode == 3 ? 8 : 16,
    4.83 +					SDL_FALSE
    4.84 +				);
    4.85  			}
    4.86  		}
    4.87 -
    4.88 -		if (keep_old) {
    4.89 -			/* disable blowup for this mode */
    4.90 -			current_mode->number |= (1<<15);	
    4.91 -		} else {
    4.92 -			/* Update mode size */
    4.93 -			current_mode->width = blow_mode->width +1;
    4.94 -			current_mode->height = blow_mode->height +1;
    4.95 -		}
    4.96 -
    4.97 -		current_mode++;
    4.98  	}
    4.99  }
     5.1 --- a/src/video/xbios/SDL_xbios_sb3.c	Wed Mar 02 17:17:26 2005 +0000
     5.2 +++ b/src/video/xbios/SDL_xbios_sb3.c	Mon Mar 07 10:00:58 2005 +0000
     5.3 @@ -67,14 +67,19 @@
     5.4  	scpn_screeninfo_t *scrinfo;
     5.5  
     5.6  	/* SB3 prevent changing video modes, we can only use current one */
     5.7 -
     5.8 -	XBIOS_nummodes = 1;
     5.9 -	current_mode = XBIOS_modelist;	
    5.10 -	current_mode->number = -1;
    5.11 +	if (XBIOS_modelist) {
    5.12 +		free(XBIOS_modelist);
    5.13 +		XBIOS_nummodes = 0;
    5.14 +		XBIOS_modelist = NULL;
    5.15 +	}
    5.16  
    5.17  	scrinfo = cookie_scpn->screen_info;
    5.18 -	current_mode->width = scrinfo->virtual_width;
    5.19 -	current_mode->height = scrinfo->virtual_height;
    5.20 -	current_mode->depth = 1<<(SDL_XBIOS_scpn_planes_device[scrinfo->device]);
    5.21  	scrinfo->h_pos = scrinfo->v_pos = 0;
    5.22 +
    5.23 +	SDL_XBIOS_AddMode(this,
    5.24 +		-1,
    5.25 +		scrinfo->virtual_width, scrinfo->virtual_height,
    5.26 +		1<<(SDL_XBIOS_scpn_planes_device[scrinfo->device]),
    5.27 +		SDL_FALSE
    5.28 +	);
    5.29  }