atari:xbios: Move all Milan specific stuff to specific backend file. SDL-1.2
authorPatrice Mandin
Wed, 30 Jul 2014 11:36:59 +0200
branchSDL-1.2
changeset 90265b91761249f9
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
     1.1 --- a/src/video/xbios/SDL_xbios.c	Tue Jul 29 17:02:37 2014 +0200
     1.2 +++ b/src/video/xbios/SDL_xbios.c	Wed Jul 30 11:36:59 2014 +0200
     1.3 @@ -90,11 +90,6 @@
     1.4  static void XBIOS_GL_SwapBuffers(_THIS);
     1.5  #endif
     1.6  
     1.7 -/* To setup palette */
     1.8 -
     1.9 -static unsigned short	TT_palette[256];
    1.10 -static unsigned long	F30_palette[256];
    1.11 -
    1.12  /* Default list of video modes */
    1.13  
    1.14  static const xbiosmode_t stmodes[1]={
    1.15 @@ -202,6 +197,7 @@
    1.16  static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
    1.17  {
    1.18  	SDL_VideoDevice *device;
    1.19 +	long cookie_cvdo;
    1.20  
    1.21  	/* Initialize all variables that we clean on shutdown */
    1.22  	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
    1.23 @@ -250,6 +246,17 @@
    1.24  
    1.25  	device->free = XBIOS_DeleteDevice;
    1.26  
    1.27 +	/* Setup device specific functions, default to ST for everything */
    1.28 +	if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) {
    1.29 +		cookie_cvdo = VDO_ST << 16;
    1.30 +	}
    1.31 +
    1.32 +	switch (cookie_cvdo>>16) {
    1.33 +		case VDO_MILAN:
    1.34 +			SDL_XBIOS_VideoInit_Milan(device);
    1.35 +			break;
    1.36 +	}
    1.37 +
    1.38  	return device;
    1.39  }
    1.40  
    1.41 @@ -489,32 +496,8 @@
    1.42  			}
    1.43  			break;
    1.44  		case VDO_MILAN:
    1.45 -			{
    1.46 -				SCREENINFO si;
    1.47 -
    1.48 -				/* Read infos about current mode */ 
    1.49 -				VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);
    1.50 -
    1.51 -				si.size = sizeof(SCREENINFO);
    1.52 -				si.devID = XBIOS_oldvmode;
    1.53 -				si.scrFlags = 0;
    1.54 -				VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);
    1.55 -
    1.56 -				this->info.current_w = si.scrWidth;
    1.57 -				this->info.current_h = si.scrHeight;
    1.58 -
    1.59 -				XBIOS_oldnumcol = 0;
    1.60 -				if (si.scrFlags & SCRINFO_OK) {
    1.61 -					if (si.scrPlanes <= 8) {
    1.62 -						XBIOS_oldnumcol = 1<<si.scrPlanes;
    1.63 -					}
    1.64 -				}
    1.65 -				if (XBIOS_oldnumcol) {
    1.66 -					VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
    1.67 -				}
    1.68 -
    1.69 -				SDL_XBIOS_ListMilanModes(this, 0);
    1.70 -			}
    1.71 +			(*XBIOS_saveMode)(this, vformat);
    1.72 +			(*XBIOS_listModes)(this, 0);
    1.73  			break;
    1.74  	}
    1.75  
    1.76 @@ -592,7 +575,7 @@
    1.77  			}
    1.78  			break;
    1.79  		case VDO_MILAN:
    1.80 -			SDL_XBIOS_ListMilanModes(this, 1);
    1.81 +			(*XBIOS_listModes)(this, 1);
    1.82  			break;
    1.83  	}
    1.84  
    1.85 @@ -629,13 +612,11 @@
    1.86  {
    1.87  	int i;
    1.88  
    1.89 -	for (i=0;i<2;i++) {
    1.90 -		if (XBIOS_screensmem[i]!=NULL) {
    1.91 -			if ((XBIOS_cvdo>>16) == VDO_MILAN) {
    1.92 -				if (i==1) {
    1.93 -					VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
    1.94 -				}
    1.95 -			} else {
    1.96 +	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
    1.97 +		(*XBIOS_freeVbuffers)(this);
    1.98 +	} else {
    1.99 +		for (i=0;i<2;i++) {
   1.100 +			if (XBIOS_screensmem[i]!=NULL) {
   1.101  				Mfree(XBIOS_screensmem[i]);
   1.102  			}
   1.103  			XBIOS_screensmem[i]=NULL;
   1.104 @@ -723,25 +704,24 @@
   1.105  	}
   1.106  
   1.107  	/* Allocate buffers */
   1.108 -	for (i=0; i<num_buffers; i++) {
   1.109 -		if ((XBIOS_cvdo>>16) == VDO_MILAN) {
   1.110 -			if (i==0) {
   1.111 -				XBIOS_screensmem[i] = XBIOS_oldvbase;
   1.112 -			} else {
   1.113 -				VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
   1.114 -			}
   1.115 -		} else {
   1.116 -			XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
   1.117 -		}
   1.118 -
   1.119 -		if (XBIOS_screensmem[i]==NULL) {
   1.120 +	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
   1.121 +		if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
   1.122  			XBIOS_FreeBuffers(this);
   1.123 -			SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
   1.124  			return (NULL);
   1.125  		}
   1.126 -		SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);
   1.127 +	} else {
   1.128 +		for (i=0; i<num_buffers; i++) {
   1.129 +			XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
   1.130  
   1.131 -		XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
   1.132 +			if (XBIOS_screensmem[i]==NULL) {
   1.133 +				XBIOS_FreeBuffers(this);
   1.134 +				SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
   1.135 +				return (NULL);
   1.136 +			}
   1.137 +			SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);
   1.138 +
   1.139 +			XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
   1.140 +		}
   1.141  	}
   1.142  
   1.143  	/* Allocate the new pixel format for the screen */
   1.144 @@ -782,9 +762,7 @@
   1.145  
   1.146  #ifndef DEBUG_VIDEO_XBIOS
   1.147  	/* Now set the video mode */
   1.148 -	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
   1.149 -		VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);
   1.150 -	} else {
   1.151 +	if ((XBIOS_cvdo>>16) != VDO_MILAN) {
   1.152  		Setscreen(-1,XBIOS_screens[0],-1);
   1.153  	}
   1.154  
   1.155 @@ -828,13 +806,7 @@
   1.156  			}
   1.157  			break;
   1.158  		case VDO_MILAN:
   1.159 -			VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);
   1.160 -
   1.161 -			/* Set hardware palette to black in True Colour */
   1.162 -			if (new_depth > 8) {
   1.163 -				SDL_memset(F30_palette, 0, sizeof(F30_palette));
   1.164 -				VsetRGB(0,256,F30_palette);
   1.165 -			}
   1.166 +			(*XBIOS_setMode)(this, new_video_mode);
   1.167  			break;
   1.168  	}
   1.169  
   1.170 @@ -910,7 +882,7 @@
   1.171  
   1.172  #ifndef DEBUG_VIDEO_XBIOS
   1.173  	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
   1.174 -		VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
   1.175 +		(*XBIOS_swapVbuffers)(this);
   1.176  	} else {
   1.177  		Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
   1.178  	}
   1.179 @@ -954,7 +926,7 @@
   1.180  
   1.181  #ifndef DEBUG_VIDEO_XBIOS
   1.182  	if ((XBIOS_cvdo>>16) == VDO_MILAN) {
   1.183 -		VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
   1.184 +		(*XBIOS_swapVbuffers)(this);
   1.185  	} else {
   1.186  		Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
   1.187  	}
   1.188 @@ -1003,7 +975,6 @@
   1.189  			EsetPalette(firstcolor,ncolors,TT_palette);
   1.190  			break;
   1.191  		case VDO_F30:
   1.192 -		case VDO_MILAN:
   1.193  			for(i = 0; i < ncolors; i++)
   1.194  			{
   1.195  				r = colors[i].r;	
   1.196 @@ -1058,11 +1029,7 @@
   1.197  			}
   1.198  			break;
   1.199  		case VDO_MILAN:
   1.200 -			VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
   1.201 -			VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
   1.202 -			if (XBIOS_oldnumcol) {
   1.203 -				VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
   1.204 -			}
   1.205 +			(*XBIOS_restoreMode)(this);
   1.206  			break;
   1.207  	}
   1.208  	Vsync();
     2.1 --- a/src/video/xbios/SDL_xbios.h	Tue Jul 29 17:02:37 2014 +0200
     2.2 +++ b/src/video/xbios/SDL_xbios.h	Wed Jul 30 11:36:59 2014 +0200
     2.3 @@ -64,6 +64,19 @@
     2.4  	int SDL_nummodes[NUM_MODELISTS];
     2.5  	SDL_Rect **SDL_modelist[NUM_MODELISTS];
     2.6  	xbiosmode_t **SDL_xbiosmode[NUM_MODELISTS];
     2.7 +
     2.8 +	union {
     2.9 +		Uint16 pal16[16];
    2.10 +		Uint32 pal32[256];
    2.11 +	} palette;
    2.12 +
    2.13 +	void (*listModes)(_THIS, int actually_add);	/* List video modes */
    2.14 +	void (*saveMode)(_THIS, SDL_PixelFormat *vformat);	/* Save mode,palette,vbase change format if needed */
    2.15 +	void (*setMode)(_THIS, xbiosmode_t *new_video_mode);	/* Set mode */
    2.16 +	void (*restoreMode)(_THIS);	/* Restore system mode */
    2.17 +	void (*swapVbuffers)(_THIS);	/* Swap video buffers */
    2.18 +	int (*allocVbuffers)(_THIS, int num_buffers, int bufsize);	/* Allocate video buffers */
    2.19 +	void (*freeVbuffers)(_THIS);	/* Free video buffers */
    2.20  };
    2.21  
    2.22  /* _VDO cookie values */
    2.23 @@ -104,8 +117,22 @@
    2.24  #define XBIOS_centscreen	(this->hidden->centscreen)
    2.25  #define XBIOS_current		(this->hidden->current)
    2.26  
    2.27 +#define TT_palette		(this->hidden->palette.pal16)
    2.28 +#define F30_palette		(this->hidden->palette.pal32)
    2.29 +
    2.30 +#define XBIOS_listModes		(this->hidden->listModes)
    2.31 +#define XBIOS_saveMode		(this->hidden->saveMode)
    2.32 +#define XBIOS_setMode		(this->hidden->setMode)
    2.33 +#define XBIOS_restoreMode	(this->hidden->restoreMode)
    2.34 +#define XBIOS_swapVbuffers	(this->hidden->swapVbuffers)
    2.35 +#define XBIOS_allocVbuffers	(this->hidden->allocVbuffers)
    2.36 +#define XBIOS_freeVbuffers	(this->hidden->freeVbuffers)
    2.37 +
    2.38  /*--- Functions prototypes ---*/
    2.39  
    2.40  void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo);
    2.41  
    2.42 +/* SDL_xbios_milan.c */
    2.43 +void SDL_XBIOS_VideoInit_Milan(_THIS);
    2.44 +
    2.45  #endif /* _SDL_xbios_h */
     3.1 --- a/src/video/xbios/SDL_xbios_milan.c	Tue Jul 29 17:02:37 2014 +0200
     3.2 +++ b/src/video/xbios/SDL_xbios_milan.c	Wed Jul 30 11:36:59 2014 +0200
     3.3 @@ -60,6 +60,28 @@
     3.4  
     3.5  /*--- Functions ---*/
     3.6  
     3.7 +static void listModes(_THIS, int actually_add);
     3.8 +static void saveMode(_THIS, SDL_PixelFormat *vformat);
     3.9 +static void setMode(_THIS, xbiosmode_t *new_video_mode);
    3.10 +static void restoreMode(_THIS);
    3.11 +static void swapVbuffers(_THIS);
    3.12 +static int allocVbuffers(_THIS, int num_buffers, int bufsize);
    3.13 +static void freeVbuffers(_THIS);
    3.14 +static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
    3.15 +
    3.16 +void SDL_XBIOS_VideoInit_Milan(_THIS)
    3.17 +{
    3.18 +	XBIOS_listModes = listModes;
    3.19 +	XBIOS_saveMode = saveMode;
    3.20 +	XBIOS_setMode = setMode;
    3.21 +	XBIOS_restoreMode = restoreMode;
    3.22 +	XBIOS_swapVbuffers = swapVbuffers;
    3.23 +	XBIOS_allocVbuffers = allocVbuffers;
    3.24 +	XBIOS_freeVbuffers = freeVbuffers;
    3.25 +
    3.26 +	this->SetColors = setColors;
    3.27 +}
    3.28 +
    3.29  static unsigned long /*cdecl*/ enumfunc(SCREENINFO *inf, unsigned long flag)
    3.30  {
    3.31  	xbiosmode_t modeinfo;
    3.32 @@ -75,7 +97,7 @@
    3.33  	return ENUMMODE_CONT; 
    3.34  } 
    3.35  
    3.36 -void SDL_XBIOS_ListMilanModes(_THIS, int actually_add)
    3.37 +static void listModes(_THIS, int actually_add)
    3.38  {
    3.39  	int i;
    3.40  
    3.41 @@ -104,3 +126,112 @@
    3.42  	enum_actually_add = actually_add;
    3.43  	VsetScreen(-1, &enumfunc, MI_MAGIC, CMD_ENUMMODES);
    3.44  }
    3.45 +
    3.46 +static void saveMode(_THIS, SDL_PixelFormat *vformat)
    3.47 +{
    3.48 +	SCREENINFO si;
    3.49 +
    3.50 +	/* Read infos about current mode */ 
    3.51 +	VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);
    3.52 +
    3.53 +	si.size = sizeof(SCREENINFO);
    3.54 +	si.devID = XBIOS_oldvmode;
    3.55 +	si.scrFlags = 0;
    3.56 +	VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);
    3.57 +
    3.58 +	this->info.current_w = si.scrWidth;
    3.59 +	this->info.current_h = si.scrHeight;
    3.60 +
    3.61 +	XBIOS_oldnumcol = 0;
    3.62 +	if (si.scrFlags & SCRINFO_OK) {
    3.63 +		if (si.scrPlanes <= 8) {
    3.64 +			XBIOS_oldnumcol = 1<<si.scrPlanes;
    3.65 +		}
    3.66 +	}
    3.67 +	if (XBIOS_oldnumcol) {
    3.68 +		VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
    3.69 +	}
    3.70 +}
    3.71 +
    3.72 +static void setMode(_THIS, xbiosmode_t *new_video_mode)
    3.73 +{
    3.74 +	VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);
    3.75 +
    3.76 +	VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);
    3.77 +
    3.78 +	/* Set hardware palette to black in True Colour */
    3.79 +	if (new_video_mode->depth > 8) {
    3.80 +		SDL_memset(F30_palette, 0, sizeof(F30_palette));
    3.81 +		VsetRGB(0,256,F30_palette);
    3.82 +	}
    3.83 +}
    3.84 +
    3.85 +static void restoreMode(_THIS)
    3.86 +{
    3.87 +	VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
    3.88 +	VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
    3.89 +	if (XBIOS_oldnumcol) {
    3.90 +		VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
    3.91 +	}
    3.92 +}
    3.93 +
    3.94 +static void swapVbuffers(_THIS)
    3.95 +{
    3.96 +	VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
    3.97 +}
    3.98 +
    3.99 +static int allocVbuffers(_THIS, int num_buffers, int bufsize)
   3.100 +{
   3.101 +	int i;
   3.102 +
   3.103 +	for (i=0; i<num_buffers; i++) {
   3.104 +		if (i==0) {
   3.105 +			/* Buffer 0 is current screen */
   3.106 +			XBIOS_screensmem[i] = XBIOS_oldvbase;
   3.107 +		} else {
   3.108 +			VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
   3.109 +		}
   3.110 +
   3.111 +		if (!XBIOS_screensmem[i]) {
   3.112 +			SDL_SetError("Can not allocate %d KB for buffer %d", bufsize>>10, i);
   3.113 +			return (0);
   3.114 +		}
   3.115 +		SDL_memset(XBIOS_screensmem[i], 0, bufsize);
   3.116 +
   3.117 +		XBIOS_screens[i]=XBIOS_screensmem[i];
   3.118 +	}
   3.119 +
   3.120 +	return (1);
   3.121 +}
   3.122 +
   3.123 +static void freeVbuffers(_THIS)
   3.124 +{
   3.125 +	int i;
   3.126 +
   3.127 +	for (i=0;i<2;i++) {
   3.128 +		if (XBIOS_screensmem[i]) {
   3.129 +			if (i==1) {
   3.130 +				VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
   3.131 +			} else {
   3.132 +				/* Do not touch buffer 0 */
   3.133 +			}
   3.134 +			XBIOS_screensmem[i]=NULL;
   3.135 +		}
   3.136 +	}
   3.137 +}
   3.138 +
   3.139 +static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   3.140 +{
   3.141 +	int i, r,g,b;
   3.142 +
   3.143 +	for(i = 0; i < ncolors; i++) {
   3.144 +		r = colors[i].r;	
   3.145 +		g = colors[i].g;
   3.146 +		b = colors[i].b;
   3.147 +
   3.148 +		F30_palette[i]=(r<<16)|(g<<8)|b;
   3.149 +	}
   3.150 +	VsetRGB(firstcolor,ncolors,F30_palette);
   3.151 +
   3.152 +	return (1);
   3.153 +}
     4.1 --- a/src/video/xbios/SDL_xbios_milan.h	Tue Jul 29 17:02:37 2014 +0200
     4.2 +++ b/src/video/xbios/SDL_xbios_milan.h	Wed Jul 30 11:36:59 2014 +0200
     4.3 @@ -209,8 +209,4 @@
     4.4  	long blk_pattern;	/* pattern (-1: solid line)     */
     4.5  } SCRLINEMEMBLK;
     4.6  
     4.7 -/*--- Functions prototypes ---*/
     4.8 -
     4.9 -void SDL_XBIOS_ListMilanModes(_THIS, int actually_add);
    4.10 -
    4.11  #endif /* _SDL_xbios_milan_h */