comparison 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
comparison
equal deleted inserted replaced
1041:af92ee34b3e2 1042:0e7218843cfb
58 #include "SDL_xbios_blowup.h" 58 #include "SDL_xbios_blowup.h"
59 #include "SDL_xbios_sb3.h" 59 #include "SDL_xbios_sb3.h"
60 60
61 #define XBIOS_VID_DRIVER_NAME "xbios" 61 #define XBIOS_VID_DRIVER_NAME "xbios"
62 62
63 /* Debug print info */
64 #if 1
65 #define DEBUG_PRINT(what) \
66 { \
67 printf what; \
68 }
63 /*#define DEBUG_VIDEO_XBIOS 1*/ 69 /*#define DEBUG_VIDEO_XBIOS 1*/
70 #else
71 #define DEBUG_PRINT(what)
72 #undef DEBUG_VIDEO_XBIOS
73 #endif
64 74
65 /* Initialization/Query functions */ 75 /* Initialization/Query functions */
66 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat); 76 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
67 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 77 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
68 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 78 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
79 89
80 #ifdef HAVE_OPENGL 90 #ifdef HAVE_OPENGL
81 /* OpenGL functions */ 91 /* OpenGL functions */
82 static void XBIOS_GL_SwapBuffers(_THIS); 92 static void XBIOS_GL_SwapBuffers(_THIS);
83 #endif 93 #endif
84
85 /* List of video modes */
86
87 /* ST modes */
88 static int xbiosnummodes_st=1;
89 static xbiosmode_t xbiosmodelist_st[]={
90 {ST_LOW>>8,320,200,4,SDL_FALSE}
91 };
92
93 /* TT modes */
94 static int xbiosnummodes_tt=2;
95 static xbiosmode_t xbiosmodelist_tt[]={
96 {TT_LOW,320,480,8,SDL_FALSE},
97 {TT_LOW,320,240,8,SDL_TRUE} /* Software double-lined mode */
98 };
99
100 /* Falcon RVB modes */
101 static int xbiosnummodes_f30rvb=16;
102 static xbiosmode_t xbiosmodelist_f30rvb[]={
103 {BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE},
104 {BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
105 {BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
106 {BPS16|COL80,640,200,16,SDL_FALSE},
107 {BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
108 {BPS16|OVERSCAN,384,240,16,SDL_FALSE},
109 {BPS16|VERTFLAG,320,400,16,SDL_FALSE},
110 {BPS16,320,200,16,SDL_FALSE},
111
112 {BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE},
113 {BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
114 {BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
115 {BPS8|COL80,640,200,8,SDL_FALSE},
116 {BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
117 {BPS8|OVERSCAN,384,240,8,SDL_FALSE},
118 {BPS8|VERTFLAG,320,400,8,SDL_FALSE},
119 {BPS8,320,200,8,SDL_FALSE}
120 };
121
122 /* Falcon VGA modes */
123 static int xbiosnummodes_f30vga=6;
124 static xbiosmode_t xbiosmodelist_f30vga[]={
125 {BPS16,320,480,16,SDL_FALSE},
126 {BPS16|VERTFLAG,320,240,16,SDL_FALSE},
127
128 {BPS8|COL80,640,480,8,SDL_FALSE},
129 {BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
130 {BPS8,320,480,8,SDL_FALSE},
131 {BPS8|VERTFLAG,320,240,8,SDL_FALSE}
132 };
133 94
134 /* To setup palette */ 95 /* To setup palette */
135 96
136 static unsigned short TT_palette[256]; 97 static unsigned short TT_palette[256];
137 static unsigned long F30_palette[256]; 98 static unsigned long F30_palette[256];
243 VideoBootStrap XBIOS_bootstrap = { 204 VideoBootStrap XBIOS_bootstrap = {
244 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver", 205 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
245 XBIOS_Available, XBIOS_CreateDevice 206 XBIOS_Available, XBIOS_CreateDevice
246 }; 207 };
247 208
209 void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height,
210 Uint16 depth, SDL_bool flags)
211 {
212 int i, curpos;
213 xbiosmode_t *current_mode;
214
215 /* Check if mode already exists */
216 if (XBIOS_modelist) {
217 current_mode = XBIOS_modelist;
218 for (i=0;i<XBIOS_nummodes; i++, current_mode++) {
219 if (current_mode->width != width)
220 continue;
221 if (current_mode->height != height)
222 continue;
223 if (current_mode->depth != depth)
224 continue;
225 return;
226 }
227 }
228
229 ++XBIOS_nummodes;
230 XBIOS_modelist = (xbiosmode_t *) realloc(XBIOS_modelist, XBIOS_nummodes * sizeof(xbiosmode_t));
231
232 /* Keep the list sorted: bpp, width, height */
233 curpos=0;
234
235 for(i=0; i<XBIOS_nummodes-1; i++) {
236 if (XBIOS_modelist[i].depth <= depth) {
237 if (XBIOS_modelist[i].width < width) {
238 break;
239 } else if (XBIOS_modelist[i].width == width) {
240 if (XBIOS_modelist[i].height <= height) {
241 break;
242 }
243 }
244 }
245 curpos++;
246 }
247
248 /* Push remaining modes further */
249 for(i=XBIOS_nummodes-1; i>curpos; i--) {
250 memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i-1], sizeof(xbiosmode_t));
251 }
252
253 XBIOS_modelist[curpos].number = modecode;
254 XBIOS_modelist[curpos].width = width;
255 XBIOS_modelist[curpos].height = height;
256 XBIOS_modelist[curpos].depth = depth;
257 XBIOS_modelist[curpos].doubleline = flags;
258 }
259
248 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat) 260 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
249 { 261 {
250 int i,j8,j16; 262 int i,j8,j16;
251 xbiosmode_t *current_mode; 263 xbiosmode_t *current_mode;
252 unsigned long cookie_blow, cookie_scpn; 264 unsigned long cookie_blow, cookie_scpn;
266 return(-1); 278 return(-1);
267 } 279 }
268 280
269 /* Initialize video mode list */ 281 /* Initialize video mode list */
270 /* and save current screen status (palette, screen address, video mode) */ 282 /* and save current screen status (palette, screen address, video mode) */
283 XBIOS_nummodes = 0;
284 XBIOS_modelist = NULL;
271 285
272 switch (XBIOS_cvdo >>16) { 286 switch (XBIOS_cvdo >>16) {
273 case VDO_ST: 287 case VDO_ST:
274 case VDO_STE: 288 case VDO_STE:
275 { 289 {
276 short *oldpalette; 290 short *oldpalette;
277 291
278 XBIOS_nummodes=xbiosnummodes_st; 292 SDL_XBIOS_AddMode(this, ST_LOW>>8,320,200,4,SDL_FALSE);
279 XBIOS_modelist=xbiosmodelist_st;
280 293
281 XBIOS_oldvbase=Physbase(); 294 XBIOS_oldvbase=Physbase();
282 XBIOS_oldvmode=Getrez(); 295 XBIOS_oldvmode=Getrez();
283 switch(XBIOS_oldvmode << 8) { 296 switch(XBIOS_oldvmode << 8) {
284 case ST_LOW: 297 case ST_LOW:
302 315
303 vformat->BitsPerPixel = 8; 316 vformat->BitsPerPixel = 8;
304 } 317 }
305 break; 318 break;
306 case VDO_TT: 319 case VDO_TT:
307 XBIOS_nummodes=xbiosnummodes_tt; 320
308 XBIOS_modelist=xbiosmodelist_tt; 321 SDL_XBIOS_AddMode(this, TT_LOW,320,480,8,SDL_FALSE);
322 /* Software double-lined mode */
323 SDL_XBIOS_AddMode(this, TT_LOW,320,240,8,SDL_TRUE);
309 324
310 XBIOS_oldvbase=Logbase(); 325 XBIOS_oldvbase=Logbase();
311 XBIOS_oldvmode=EgetShift(); 326 XBIOS_oldvmode=EgetShift();
312 327
313 switch(XBIOS_oldvmode & ES_MODE) { 328 switch(XBIOS_oldvmode & ES_MODE) {
341 case MONITOR_MONO: 356 case MONITOR_MONO:
342 /* Not usable */ 357 /* Not usable */
343 break; 358 break;
344 case MONITOR_RGB: 359 case MONITOR_RGB:
345 case MONITOR_TV: 360 case MONITOR_TV:
346 XBIOS_nummodes = xbiosnummodes_f30rvb; 361 SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE);
347 XBIOS_modelist = xbiosmodelist_f30rvb; 362 SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE);
363 SDL_XBIOS_AddMode(this, BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE);
364 SDL_XBIOS_AddMode(this, BPS16|COL80,640,200,16,SDL_FALSE);
365 SDL_XBIOS_AddMode(this, BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE);
366 SDL_XBIOS_AddMode(this, BPS16|OVERSCAN,384,240,16,SDL_FALSE);
367 SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,400,16,SDL_FALSE);
368 SDL_XBIOS_AddMode(this, BPS16,320,200,16,SDL_FALSE);
369 SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE);
370 SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE);
371 SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE);
372 SDL_XBIOS_AddMode(this, BPS8|COL80,640,200,8,SDL_FALSE);
373 SDL_XBIOS_AddMode(this, BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE);
374 SDL_XBIOS_AddMode(this, BPS8|OVERSCAN,384,240,8,SDL_FALSE);
375 SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,400,8,SDL_FALSE);
376 SDL_XBIOS_AddMode(this, BPS8,320,200,8,SDL_FALSE);
348 break; 377 break;
349 case MONITOR_VGA: 378 case MONITOR_VGA:
350 XBIOS_nummodes = xbiosnummodes_f30vga; 379 SDL_XBIOS_AddMode(this, BPS16,320,480,16,SDL_FALSE);
351 XBIOS_modelist = xbiosmodelist_f30vga; 380 SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,240,16,SDL_FALSE);
381 SDL_XBIOS_AddMode(this, BPS8|COL80,640,480,8,SDL_FALSE);
382 SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE);
383 SDL_XBIOS_AddMode(this, BPS8,320,480,8,SDL_FALSE);
384 SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,240,8,SDL_FALSE);
352 break; 385 break;
353 } 386 }
354 XBIOS_oldvbase=Logbase(); 387 XBIOS_oldvbase=Logbase();
355 XBIOS_oldvmode=Vsetmode(-1); 388 XBIOS_oldvmode=Vsetmode(-1);
356 389
384 SDL_XBIOS_SB3Init(this, (scpn_cookie_t *)cookie_scpn); 417 SDL_XBIOS_SB3Init(this, (scpn_cookie_t *)cookie_scpn);
385 } 418 }
386 419
387 break; 420 break;
388 } 421 }
389 422
390 current_mode = XBIOS_modelist; 423 current_mode = XBIOS_modelist;
391 j8 = j16 = 0; 424 j8 = j16 = 0;
392 for (i=0;i<XBIOS_nummodes;i++) { 425 for (i=0; i<XBIOS_nummodes; i++, current_mode++) {
393 switch (current_mode->depth) { 426 switch (current_mode->depth) {
394 case 4: 427 case 4:
395 case 8: 428 case 8:
396 SDL_modelist[0][j8] = malloc(sizeof(SDL_Rect)); 429 SDL_modelist[0][j8] = malloc(sizeof(SDL_Rect));
397 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0; 430 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0;
398 SDL_modelist[0][j8]->w = current_mode->width; 431 SDL_modelist[0][j8]->w = current_mode->width;
399 SDL_modelist[0][j8]->h = current_mode->height; 432 SDL_modelist[0][j8]->h = current_mode->height;
400 XBIOS_videomodes[0][j8]=current_mode; 433 XBIOS_videomodes[0][j8]=current_mode;
401 current_mode++;
402 j8++; 434 j8++;
403 break; 435 break;
404 case 16: 436 case 16:
405 SDL_modelist[1][j16] = malloc(sizeof(SDL_Rect)); 437 SDL_modelist[1][j16] = malloc(sizeof(SDL_Rect));
406 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0; 438 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0;
407 SDL_modelist[1][j16]->w = current_mode->width; 439 SDL_modelist[1][j16]->w = current_mode->width;
408 SDL_modelist[1][j16]->h = current_mode->height; 440 SDL_modelist[1][j16]->h = current_mode->height;
409 XBIOS_videomodes[1][j16]=current_mode; 441 XBIOS_videomodes[1][j16]=current_mode;
410 current_mode++;
411 j16++; 442 j16++;
412 break; 443 break;
413 } 444 }
414 } 445 }
415 SDL_modelist[0][j8] = NULL; 446 SDL_modelist[0][j8] = NULL;
889 SDL_modelist[j][i]=NULL; 920 SDL_modelist[j][i]=NULL;
890 } 921 }
891 } 922 }
892 } 923 }
893 924
925 if (XBIOS_modelist) {
926 free(XBIOS_modelist);
927 XBIOS_nummodes=0;
928 XBIOS_modelist=NULL;
929 }
930
894 this->screen->pixels = NULL; 931 this->screen->pixels = NULL;
895 } 932 }
896 933
897 #ifdef HAVE_OPENGL 934 #ifdef HAVE_OPENGL
898 935