Mercurial > sdl-ios-xcode
comparison src/video/xbios/SDL_xbios.c @ 2072:4b3f98a9a2c1
xbios: preliminary video mode init
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Mon, 13 Nov 2006 19:59:28 +0000 |
parents | adf732f1f016 |
children | 790726541708 |
comparison
equal
deleted
inserted
replaced
2071:579abbb51f80 | 2072:4b3f98a9a2c1 |
---|---|
44 #include "../ataricommon/SDL_ataric2p_s.h" | 44 #include "../ataricommon/SDL_ataric2p_s.h" |
45 #include "../ataricommon/SDL_atarievents_c.h" | 45 #include "../ataricommon/SDL_atarievents_c.h" |
46 #include "../ataricommon/SDL_atarimxalloc_c.h" | 46 #include "../ataricommon/SDL_atarimxalloc_c.h" |
47 #include "../ataricommon/SDL_atarigl_c.h" | 47 #include "../ataricommon/SDL_atarigl_c.h" |
48 #include "SDL_xbios.h" | 48 #include "SDL_xbios.h" |
49 #include "SDL_xbios_blowup.h" | 49 #include "SDL_xbiosmodes.h" |
50 #include "SDL_xbios_centscreen.h" | |
51 #include "SDL_xbios_sb3.h" | |
52 | 50 |
53 /* Debug print info */ | 51 /* Debug print info */ |
54 #if 0 | 52 #if 0 |
55 #define DEBUG_PRINT(what) \ | 53 #define DEBUG_PRINT(what) \ |
56 { \ | 54 { \ |
63 #endif | 61 #endif |
64 | 62 |
65 /* Initialization/Query functions */ | 63 /* Initialization/Query functions */ |
66 static int XBIOS_VideoInit(_THIS); | 64 static int XBIOS_VideoInit(_THIS); |
67 static void XBIOS_VideoQuit(_THIS); | 65 static void XBIOS_VideoQuit(_THIS); |
68 | |
69 #if 0 | |
70 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat * format, | |
71 Uint32 flags); | |
72 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface * current, | |
73 int width, int height, int bpp, | |
74 Uint32 flags); | |
75 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, | |
76 SDL_Color * colors); | |
77 | |
78 /* Hardware surface functions */ | |
79 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface * surface); | |
80 static int XBIOS_LockHWSurface(_THIS, SDL_Surface * surface); | |
81 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface * surface); | |
82 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface * surface); | |
83 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface * surface); | |
84 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect * rects); | |
85 | |
86 #if SDL_VIDEO_OPENGL | |
87 /* OpenGL functions */ | |
88 static void XBIOS_GL_SwapBuffers(_THIS); | |
89 #endif | |
90 | |
91 /* To setup palette */ | |
92 | |
93 static unsigned short TT_palette[256]; | |
94 static unsigned long F30_palette[256]; | |
95 #endif | |
96 | 66 |
97 /* Xbios driver bootstrap functions */ | 67 /* Xbios driver bootstrap functions */ |
98 | 68 |
99 static int | 69 static int |
100 XBIOS_Available(void) | 70 XBIOS_Available(void) |
124 return 0; | 94 return 0; |
125 break; | 95 break; |
126 case VDO_F30: | 96 case VDO_F30: |
127 if (VgetMonitor() == MONITOR_MONO) | 97 if (VgetMonitor() == MONITOR_MONO) |
128 return 0; | 98 return 0; |
129 if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) { | 99 /*if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) { |
130 if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *) cookie_scpn)) { | 100 if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *) cookie_scpn)) { |
131 return 0; | 101 return 0; |
132 } | 102 } |
133 } | 103 }*/ |
134 break; | 104 break; |
135 default: | 105 default: |
136 return 0; | 106 return 0; |
137 } | 107 } |
138 | 108 |
169 /* Video functions */ | 139 /* Video functions */ |
170 device->VideoInit = XBIOS_VideoInit; | 140 device->VideoInit = XBIOS_VideoInit; |
171 device->VideoQuit = XBIOS_VideoQuit; | 141 device->VideoQuit = XBIOS_VideoQuit; |
172 | 142 |
173 /* Modes */ | 143 /* Modes */ |
174 device->GetDisplayModes = NULL /*XBIOS_GetDisplayModes */ ; | 144 device->GetDisplayModes = SDL_XBIOS_GetDisplayModes; |
175 device->SetDisplayMode = NULL /*XBIOS_SetDisplayMode */ ; | 145 device->SetDisplayMode = SDL_XBIOS_SetDisplayMode; |
176 | 146 |
177 /* Events */ | 147 /* Events */ |
178 device->PumpEvents = SDL_Atari_PumpEvents; | 148 device->PumpEvents = SDL_Atari_PumpEvents; |
179 | 149 |
180 #if SDL_VIDEO_OPENGL | 150 #if SDL_VIDEO_OPENGL |
197 VideoBootStrap XBIOS_bootstrap = { | 167 VideoBootStrap XBIOS_bootstrap = { |
198 "xbios", "Atari Xbios driver", | 168 "xbios", "Atari Xbios driver", |
199 XBIOS_Available, XBIOS_CreateDevice | 169 XBIOS_Available, XBIOS_CreateDevice |
200 }; | 170 }; |
201 | 171 |
202 #if 0 | |
203 void | |
204 SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height, | |
205 Uint16 depth, SDL_bool flags) | |
206 { | |
207 int i, curpos; | |
208 xbiosmode_t *current_mode; | |
209 | |
210 /* Check if mode already exists */ | |
211 if (XBIOS_modelist) { | |
212 current_mode = XBIOS_modelist; | |
213 for (i = 0; i < XBIOS_nummodes; i++, current_mode++) { | |
214 if (current_mode->width != width) | |
215 continue; | |
216 if (current_mode->height != height) | |
217 continue; | |
218 if (current_mode->depth != depth) | |
219 continue; | |
220 return; | |
221 } | |
222 } | |
223 | |
224 ++XBIOS_nummodes; | |
225 XBIOS_modelist = | |
226 (xbiosmode_t *) SDL_realloc(XBIOS_modelist, | |
227 XBIOS_nummodes * sizeof(xbiosmode_t)); | |
228 | |
229 /* Keep the list sorted: bpp, width, height */ | |
230 curpos = 0; | |
231 | |
232 for (i = 0; i < XBIOS_nummodes - 1; i++) { | |
233 if (XBIOS_modelist[i].depth <= depth) { | |
234 if (XBIOS_modelist[i].width < width) { | |
235 break; | |
236 } else if (XBIOS_modelist[i].width == width) { | |
237 if (XBIOS_modelist[i].height <= height) { | |
238 break; | |
239 } | |
240 } | |
241 } | |
242 curpos++; | |
243 } | |
244 | |
245 /* Push remaining modes further */ | |
246 for (i = XBIOS_nummodes - 1; i > curpos; i--) { | |
247 SDL_memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i - 1], | |
248 sizeof(xbiosmode_t)); | |
249 } | |
250 | |
251 XBIOS_modelist[curpos].number = modecode; | |
252 XBIOS_modelist[curpos].width = width; | |
253 XBIOS_modelist[curpos].height = height; | |
254 XBIOS_modelist[curpos].depth = depth; | |
255 XBIOS_modelist[curpos].doubleline = flags; | |
256 } | |
257 #endif | |
258 | |
259 static int | 172 static int |
260 XBIOS_VideoInit(_THIS) | 173 XBIOS_VideoInit(_THIS) |
261 { | 174 { |
262 XBIOS_InitModes(_this); | 175 /* Save screensaver settings */ |
263 | 176 |
264 #if 0 | 177 /* Init video mode list */ |
265 int i, j8, j16; | 178 SDL_XBIOS_InitModes(_this); |
266 xbiosmode_t *current_mode; | |
267 unsigned long cookie_blow, cookie_scpn, cookie_cnts; | |
268 | |
269 /* Initialize all variables that we clean on shutdown */ | |
270 memset(SDL_modelist, 0, sizeof(SDL_modelist)); | |
271 | |
272 /* Cookie _VDO present ? if not, assume ST machine */ | |
273 if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) { | |
274 XBIOS_cvdo = VDO_ST << 16; | |
275 } | |
276 | |
277 /* Allocate memory for old palette */ | |
278 XBIOS_oldpalette = (void *) SDL_malloc(256 * sizeof(long)); | |
279 if (!XBIOS_oldpalette) { | |
280 SDL_SetError("Unable to allocate memory for old palette\n"); | |
281 return (-1); | |
282 } | |
283 | |
284 /* Initialize video mode list */ | |
285 /* and save current screen status (palette, screen address, video mode) */ | |
286 XBIOS_nummodes = 0; | |
287 XBIOS_modelist = NULL; | |
288 XBIOS_centscreen = SDL_FALSE; | |
289 | |
290 switch (XBIOS_cvdo >> 16) { | |
291 case VDO_ST: | |
292 case VDO_STE: | |
293 { | |
294 short *oldpalette; | |
295 | |
296 SDL_XBIOS_AddMode(this, ST_LOW >> 8, 320, 200, 4, SDL_FALSE); | |
297 | |
298 XBIOS_oldvbase = Physbase(); | |
299 XBIOS_oldvmode = Getrez(); | |
300 switch (XBIOS_oldvmode << 8) { | |
301 case ST_LOW: | |
302 XBIOS_oldnumcol = 16; | |
303 break; | |
304 case ST_MED: | |
305 XBIOS_oldnumcol = 4; | |
306 break; | |
307 case ST_HIGH: | |
308 XBIOS_oldnumcol = 2; | |
309 break; | |
310 default: | |
311 XBIOS_oldnumcol = 0; | |
312 break; | |
313 } | |
314 | |
315 oldpalette = (short *) XBIOS_oldpalette; | |
316 for (i = 0; i < XBIOS_oldnumcol; i++) { | |
317 *oldpalette++ = Setcolor(i, -1); | |
318 } | |
319 | |
320 vformat->BitsPerPixel = 8; | |
321 } | |
322 break; | |
323 case VDO_TT: | |
324 | |
325 SDL_XBIOS_AddMode(this, TT_LOW, 320, 480, 8, SDL_FALSE); | |
326 /* Software double-lined mode */ | |
327 SDL_XBIOS_AddMode(this, TT_LOW, 320, 240, 8, SDL_TRUE); | |
328 | |
329 XBIOS_oldvbase = Logbase(); | |
330 XBIOS_oldvmode = EgetShift(); | |
331 | |
332 switch (XBIOS_oldvmode & ES_MODE) { | |
333 case TT_LOW: | |
334 XBIOS_oldnumcol = 256; | |
335 break; | |
336 case ST_LOW: | |
337 case TT_MED: | |
338 XBIOS_oldnumcol = 16; | |
339 break; | |
340 case ST_MED: | |
341 XBIOS_oldnumcol = 4; | |
342 break; | |
343 case ST_HIGH: | |
344 case TT_HIGH: | |
345 XBIOS_oldnumcol = 2; | |
346 break; | |
347 default: | |
348 XBIOS_oldnumcol = 0; | |
349 break; | |
350 } | |
351 if (XBIOS_oldnumcol) { | |
352 EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
353 } | |
354 | |
355 vformat->BitsPerPixel = 8; | |
356 break; | |
357 case VDO_F30: | |
358 switch (VgetMonitor()) { | |
359 case MONITOR_MONO: | |
360 /* Not usable */ | |
361 break; | |
362 case MONITOR_RGB: | |
363 case MONITOR_TV: | |
364 SDL_XBIOS_AddMode(this, BPS16 | COL80 | OVERSCAN | VERTFLAG, | |
365 768, 480, 16, SDL_FALSE); | |
366 SDL_XBIOS_AddMode(this, BPS16 | COL80 | OVERSCAN, 768, 240, | |
367 16, SDL_FALSE); | |
368 SDL_XBIOS_AddMode(this, BPS16 | COL80 | VERTFLAG, 640, 400, | |
369 16, SDL_FALSE); | |
370 SDL_XBIOS_AddMode(this, BPS16 | COL80, 640, 200, 16, SDL_FALSE); | |
371 SDL_XBIOS_AddMode(this, BPS16 | OVERSCAN | VERTFLAG, 384, | |
372 480, 16, SDL_FALSE); | |
373 SDL_XBIOS_AddMode(this, BPS16 | OVERSCAN, 384, 240, 16, | |
374 SDL_FALSE); | |
375 SDL_XBIOS_AddMode(this, BPS16 | VERTFLAG, 320, 400, 16, | |
376 SDL_FALSE); | |
377 SDL_XBIOS_AddMode(this, BPS16, 320, 200, 16, SDL_FALSE); | |
378 SDL_XBIOS_AddMode(this, BPS8 | COL80 | OVERSCAN | VERTFLAG, | |
379 768, 480, 8, SDL_FALSE); | |
380 SDL_XBIOS_AddMode(this, BPS8 | COL80 | OVERSCAN, 768, 240, 8, | |
381 SDL_FALSE); | |
382 SDL_XBIOS_AddMode(this, BPS8 | COL80 | VERTFLAG, 640, 400, 8, | |
383 SDL_FALSE); | |
384 SDL_XBIOS_AddMode(this, BPS8 | COL80, 640, 200, 8, SDL_FALSE); | |
385 SDL_XBIOS_AddMode(this, BPS8 | OVERSCAN | VERTFLAG, 384, 480, | |
386 8, SDL_FALSE); | |
387 SDL_XBIOS_AddMode(this, BPS8 | OVERSCAN, 384, 240, 8, SDL_FALSE); | |
388 SDL_XBIOS_AddMode(this, BPS8 | VERTFLAG, 320, 400, 8, SDL_FALSE); | |
389 SDL_XBIOS_AddMode(this, BPS8, 320, 200, 8, SDL_FALSE); | |
390 break; | |
391 case MONITOR_VGA: | |
392 SDL_XBIOS_AddMode(this, BPS16, 320, 480, 16, SDL_FALSE); | |
393 SDL_XBIOS_AddMode(this, BPS16 | VERTFLAG, 320, 240, 16, | |
394 SDL_FALSE); | |
395 SDL_XBIOS_AddMode(this, BPS8 | COL80, 640, 480, 8, SDL_FALSE); | |
396 SDL_XBIOS_AddMode(this, BPS8 | COL80 | VERTFLAG, 640, 240, 8, | |
397 SDL_FALSE); | |
398 SDL_XBIOS_AddMode(this, BPS8, 320, 480, 8, SDL_FALSE); | |
399 SDL_XBIOS_AddMode(this, BPS8 | VERTFLAG, 320, 240, 8, SDL_FALSE); | |
400 break; | |
401 } | |
402 XBIOS_oldvbase = Logbase(); | |
403 XBIOS_oldvmode = VsetMode(-1); | |
404 | |
405 XBIOS_oldnumcol = 1 << (1 << (XBIOS_oldvmode & NUMCOLS)); | |
406 if (XBIOS_oldnumcol > 256) { | |
407 XBIOS_oldnumcol = 0; | |
408 } | |
409 if (XBIOS_oldnumcol) { | |
410 VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
411 } | |
412 | |
413 vformat->BitsPerPixel = 16; | |
414 | |
415 /* Keep vga/rvb, and pal/ntsc bits */ | |
416 current_mode = XBIOS_modelist; | |
417 for (i = 0; i < XBIOS_nummodes; i++) { | |
418 Uint16 newvmode; | |
419 | |
420 newvmode = current_mode->number; | |
421 newvmode &= ~(VGA | PAL); | |
422 newvmode |= XBIOS_oldvmode & (VGA | PAL); | |
423 current_mode->number = newvmode; | |
424 | |
425 current_mode++; | |
426 } | |
427 | |
428 /* Initialize BlowUp/SB3/Centscreen stuff if present */ | |
429 if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) { | |
430 SDL_XBIOS_BlowupInit(this, (blow_cookie_t *) cookie_blow); | |
431 } else if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) { | |
432 SDL_XBIOS_SB3Init(this, (scpn_cookie_t *) cookie_scpn); | |
433 } else if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) { | |
434 XBIOS_oldvmode = SDL_XBIOS_CentscreenInit(this); | |
435 XBIOS_centscreen = SDL_TRUE; | |
436 } | |
437 | |
438 break; | |
439 } | |
440 | |
441 /* Determine the current screen size */ | |
442 if (XBIOS_nummodes > 0) { | |
443 /* FIXME: parse video mode list to search for current mode */ | |
444 this->info.current_w = XBIOS_modelist[0].width; | |
445 this->info.current_h = XBIOS_modelist[0].height; | |
446 } | |
447 | |
448 current_mode = XBIOS_modelist; | |
449 j8 = j16 = 0; | |
450 for (i = 0; i < XBIOS_nummodes; i++, current_mode++) { | |
451 switch (current_mode->depth) { | |
452 case 4: | |
453 case 8: | |
454 SDL_modelist[0][j8] = SDL_malloc(sizeof(SDL_Rect)); | |
455 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0; | |
456 SDL_modelist[0][j8]->w = current_mode->width; | |
457 SDL_modelist[0][j8]->h = current_mode->height; | |
458 XBIOS_videomodes[0][j8] = current_mode; | |
459 j8++; | |
460 break; | |
461 case 16: | |
462 SDL_modelist[1][j16] = SDL_malloc(sizeof(SDL_Rect)); | |
463 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0; | |
464 SDL_modelist[1][j16]->w = current_mode->width; | |
465 SDL_modelist[1][j16]->h = current_mode->height; | |
466 XBIOS_videomodes[1][j16] = current_mode; | |
467 j16++; | |
468 break; | |
469 } | |
470 } | |
471 SDL_modelist[0][j8] = NULL; | |
472 SDL_modelist[1][j16] = NULL; | |
473 | |
474 XBIOS_screens[0] = NULL; | |
475 XBIOS_screens[1] = NULL; | |
476 XBIOS_shadowscreen = NULL; | |
477 | |
478 /* Update hardware info */ | |
479 this->info.hw_available = 1; | |
480 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM); | |
481 | |
482 /* Init chunky to planar routine */ | |
483 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; | |
484 | |
485 #if SDL_VIDEO_OPENGL | |
486 SDL_AtariGL_InitPointers(this); | |
487 #endif | |
488 | |
489 #endif | |
490 | 179 |
491 return (0); | 180 return (0); |
492 } | 181 } |
493 | 182 |
494 static void | 183 static void |
495 XBIOS_VideoQuit(_THIS) | 184 XBIOS_VideoQuit(_THIS) |
496 { | 185 { |
497 /* int i, j;*/ | |
498 | |
499 XBIOS_QuitModes(_this); | |
500 Atari_ShutdownEvents(); | 186 Atari_ShutdownEvents(); |
501 | 187 |
502 #if 0 | 188 /* Restore screensaver settings */ |
503 /* Restore video mode and palette */ | |
504 #ifndef DEBUG_VIDEO_XBIOS | |
505 switch (XBIOS_cvdo >> 16) { | |
506 case VDO_ST: | |
507 case VDO_STE: | |
508 Setscreen(-1, XBIOS_oldvbase, XBIOS_oldvmode); | |
509 if (XBIOS_oldnumcol) { | |
510 Setpalette(XBIOS_oldpalette); | |
511 } | |
512 break; | |
513 case VDO_TT: | |
514 Setscreen(-1, XBIOS_oldvbase, -1); | |
515 EsetShift(XBIOS_oldvmode); | |
516 if (XBIOS_oldnumcol) { | |
517 EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
518 } | |
519 break; | |
520 case VDO_F30: | |
521 Setscreen(-1, XBIOS_oldvbase, -1); | |
522 if (XBIOS_centscreen) { | |
523 SDL_XBIOS_CentscreenRestore(this, XBIOS_oldvmode); | |
524 } else { | |
525 VsetMode(XBIOS_oldvmode); | |
526 } | |
527 if (XBIOS_oldnumcol) { | |
528 VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
529 } | |
530 break; | |
531 } | |
532 Vsync(); | |
533 #endif | |
534 | 189 |
535 | 190 SDL_XBIOS_QuitModes(_this); |
536 #if SDL_VIDEO_OPENGL | |
537 if (gl_active) { | |
538 SDL_AtariGL_Quit(this, SDL_TRUE); | |
539 } | |
540 #endif | |
541 | |
542 if (XBIOS_oldpalette) { | |
543 SDL_free(XBIOS_oldpalette); | |
544 XBIOS_oldpalette = NULL; | |
545 } | |
546 XBIOS_FreeBuffers(this); | |
547 | |
548 /* Free mode list */ | |
549 for (j = 0; j < NUM_MODELISTS; j++) { | |
550 for (i = 0; i < SDL_NUMMODES; i++) { | |
551 if (SDL_modelist[j][i] != NULL) { | |
552 SDL_free(SDL_modelist[j][i]); | |
553 SDL_modelist[j][i] = NULL; | |
554 } | |
555 } | |
556 } | |
557 | |
558 if (XBIOS_modelist) { | |
559 SDL_free(XBIOS_modelist); | |
560 XBIOS_nummodes = 0; | |
561 XBIOS_modelist = NULL; | |
562 } | |
563 | |
564 this->screen->pixels = NULL; | |
565 #endif | |
566 } | 191 } |
567 | |
568 #if 0 | |
569 static SDL_Rect ** | |
570 XBIOS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) | |
571 { | |
572 /* 8 bits -> list 0 */ | |
573 /* 16 bits -> list 1 */ | |
574 if ((format->BitsPerPixel != 8) && (format->BitsPerPixel != 16)) { | |
575 return NULL; | |
576 } | |
577 | |
578 return (SDL_modelist[(format->BitsPerPixel) >> 4]); | |
579 } | |
580 | |
581 static void | |
582 XBIOS_FreeBuffers(_THIS) | |
583 { | |
584 int i; | |
585 | |
586 for (i = 0; i < 2; i++) { | |
587 if (XBIOS_screensmem[i] != NULL) { | |
588 Mfree(XBIOS_screensmem[i]); | |
589 XBIOS_screensmem[i] = NULL; | |
590 } | |
591 } | |
592 | |
593 if (XBIOS_shadowscreen != NULL) { | |
594 Mfree(XBIOS_shadowscreen); | |
595 XBIOS_shadowscreen = NULL; | |
596 } | |
597 } | |
598 | |
599 static SDL_Surface * | |
600 XBIOS_SetVideoMode(_THIS, SDL_Surface * current, | |
601 int width, int height, int bpp, Uint32 flags) | |
602 { | |
603 int mode, new_depth; | |
604 int i; | |
605 xbiosmode_t *new_video_mode; | |
606 Uint32 new_screen_size; | |
607 Uint32 modeflags; | |
608 | |
609 /* Free current buffers */ | |
610 XBIOS_FreeBuffers(this); | |
611 | |
612 /* Limit bpp */ | |
613 if (bpp > 16) { | |
614 bpp = 16; | |
615 } | |
616 bpp >>= 4; | |
617 | |
618 /* Search if the mode exists (width, height, bpp) */ | |
619 for (mode = 0; SDL_modelist[bpp][mode]; ++mode) { | |
620 if ((SDL_modelist[bpp][mode]->w == width) && | |
621 (SDL_modelist[bpp][mode]->h == height)) { | |
622 | |
623 break; | |
624 } | |
625 } | |
626 if (SDL_modelist[bpp][mode] == NULL) { | |
627 SDL_SetError("Couldn't find requested mode in list"); | |
628 return (NULL); | |
629 } | |
630 | |
631 modeflags = SDL_FULLSCREEN | SDL_PREALLOC; | |
632 | |
633 /* Allocate needed buffers: simple/double buffer and shadow surface */ | |
634 new_video_mode = XBIOS_videomodes[bpp][mode]; | |
635 new_depth = new_video_mode->depth; | |
636 if (new_depth == 4) { | |
637 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4; | |
638 new_depth = 8; | |
639 modeflags |= SDL_SWSURFACE | SDL_HWPALETTE; | |
640 } else if (new_depth == 8) { | |
641 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; | |
642 modeflags |= SDL_SWSURFACE | SDL_HWPALETTE; | |
643 } else { | |
644 modeflags |= SDL_HWSURFACE; | |
645 } | |
646 | |
647 new_screen_size = width * height * ((new_depth) >> 3); | |
648 new_screen_size += 256; /* To align on a 256 byte adress */ | |
649 | |
650 if (new_depth == 8) { | |
651 XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM); | |
652 | |
653 if (XBIOS_shadowscreen == NULL) { | |
654 SDL_SetError("Can not allocate %d KB for shadow buffer", | |
655 new_screen_size >> 10); | |
656 return (NULL); | |
657 } | |
658 SDL_memset(XBIOS_shadowscreen, 0, new_screen_size); | |
659 } | |
660 | |
661 /* Output buffer needs to be twice in size for the software double-line mode */ | |
662 XBIOS_doubleline = SDL_FALSE; | |
663 if (new_video_mode->doubleline) { | |
664 new_screen_size <<= 1; | |
665 XBIOS_doubleline = SDL_TRUE; | |
666 } | |
667 | |
668 XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM); | |
669 | |
670 if (XBIOS_screensmem[0] == NULL) { | |
671 XBIOS_FreeBuffers(this); | |
672 SDL_SetError("Can not allocate %d KB for frame buffer", | |
673 new_screen_size >> 10); | |
674 return (NULL); | |
675 } | |
676 SDL_memset(XBIOS_screensmem[0], 0, new_screen_size); | |
677 | |
678 XBIOS_screens[0] = | |
679 (void *) (((long) XBIOS_screensmem[0] + 256) & 0xFFFFFF00UL); | |
680 | |
681 #if SDL_VIDEO_OPENGL | |
682 if (flags & SDL_INTERNALOPENGL) { | |
683 if (this->gl_config.double_buffer) { | |
684 flags |= SDL_DOUBLEBUF; | |
685 } | |
686 } | |
687 #endif | |
688 | |
689 /* Double buffer ? */ | |
690 if (flags & SDL_DOUBLEBUF) { | |
691 XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM); | |
692 | |
693 if (XBIOS_screensmem[1] == NULL) { | |
694 XBIOS_FreeBuffers(this); | |
695 SDL_SetError("Can not allocate %d KB for double buffer", | |
696 new_screen_size >> 10); | |
697 return (NULL); | |
698 } | |
699 SDL_memset(XBIOS_screensmem[1], 0, new_screen_size); | |
700 | |
701 XBIOS_screens[1] = | |
702 (void *) (((long) XBIOS_screensmem[1] + 256) & 0xFFFFFF00UL); | |
703 modeflags |= SDL_DOUBLEBUF; | |
704 } | |
705 | |
706 /* Allocate the new pixel format for the screen */ | |
707 if (!SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0)) { | |
708 XBIOS_FreeBuffers(this); | |
709 SDL_SetError("Couldn't allocate new pixel format for requested mode"); | |
710 return (NULL); | |
711 } | |
712 | |
713 current->w = XBIOS_width = width; | |
714 current->h = XBIOS_height = height; | |
715 current->pitch = (width * new_depth) >> 3; | |
716 | |
717 /* this is for C2P conversion */ | |
718 XBIOS_pitch = (new_video_mode->width * new_video_mode->depth) >> 3; | |
719 | |
720 if (new_depth == 8) | |
721 current->pixels = XBIOS_shadowscreen; | |
722 else | |
723 current->pixels = XBIOS_screens[0]; | |
724 | |
725 XBIOS_fbnum = 0; | |
726 | |
727 #if SDL_VIDEO_OPENGL | |
728 if (flags & SDL_INTERNALOPENGL) { | |
729 if (!SDL_AtariGL_Init(this, current)) { | |
730 XBIOS_FreeBuffers(this); | |
731 SDL_SetError("Can not create OpenGL context"); | |
732 return NULL; | |
733 } | |
734 | |
735 modeflags |= SDL_INTERNALOPENGL; | |
736 } | |
737 #endif | |
738 | |
739 current->flags = modeflags; | |
740 | |
741 /* Now set the video mode */ | |
742 #ifndef DEBUG_VIDEO_XBIOS | |
743 Setscreen(-1, XBIOS_screens[0], -1); | |
744 #endif | |
745 | |
746 switch (XBIOS_cvdo >> 16) { | |
747 case VDO_ST: | |
748 #ifndef DEBUG_VIDEO_XBIOS | |
749 Setscreen(-1, -1, new_video_mode->number); | |
750 #endif | |
751 /* Reset palette */ | |
752 for (i = 0; i < 16; i++) { | |
753 TT_palette[i] = | |
754 ((i >> 1) << 8) | (((i * 8) / 17) << 4) | (i >> 1); | |
755 } | |
756 #ifndef DEBUG_VIDEO_XBIOS | |
757 Setpalette(TT_palette); | |
758 #endif | |
759 break; | |
760 case VDO_STE: | |
761 #ifndef DEBUG_VIDEO_XBIOS | |
762 Setscreen(-1, -1, new_video_mode->number); | |
763 #endif | |
764 /* Reset palette */ | |
765 for (i = 0; i < 16; i++) { | |
766 int c; | |
767 | |
768 c = ((i & 1) << 3) | ((i >> 1) & 7); | |
769 TT_palette[i] = (c << 8) | (c << 4) | c; | |
770 } | |
771 #ifndef DEBUG_VIDEO_XBIOS | |
772 Setpalette(TT_palette); | |
773 #endif | |
774 break; | |
775 case VDO_TT: | |
776 #ifndef DEBUG_VIDEO_XBIOS | |
777 EsetShift(new_video_mode->number); | |
778 #endif | |
779 break; | |
780 case VDO_F30: | |
781 #ifndef DEBUG_VIDEO_XBIOS | |
782 if (XBIOS_centscreen) { | |
783 SDL_XBIOS_CentscreenSetmode(this, width, height, new_depth); | |
784 } else { | |
785 VsetMode(new_video_mode->number); | |
786 } | |
787 #endif | |
788 /* Set hardware palette to black in True Colour */ | |
789 if (new_depth == 16) { | |
790 SDL_memset(F30_palette, 0, sizeof(F30_palette)); | |
791 VsetRGB(0, 256, F30_palette); | |
792 } | |
793 break; | |
794 } | |
795 | |
796 Vsync(); | |
797 | |
798 this->UpdateRects = XBIOS_UpdateRects; | |
799 | |
800 return (current); | |
801 } | |
802 | |
803 /* We don't actually allow hardware surfaces other than the main one */ | |
804 static int | |
805 XBIOS_AllocHWSurface(_THIS, SDL_Surface * surface) | |
806 { | |
807 return (-1); | |
808 } | |
809 | |
810 static void | |
811 XBIOS_FreeHWSurface(_THIS, SDL_Surface * surface) | |
812 { | |
813 return; | |
814 } | |
815 | |
816 static int | |
817 XBIOS_LockHWSurface(_THIS, SDL_Surface * surface) | |
818 { | |
819 return (0); | |
820 } | |
821 | |
822 static void | |
823 XBIOS_UnlockHWSurface(_THIS, SDL_Surface * surface) | |
824 { | |
825 return; | |
826 } | |
827 | |
828 static void | |
829 XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect * rects) | |
830 { | |
831 SDL_Surface *surface; | |
832 | |
833 surface = this->screen; | |
834 | |
835 if ((surface->format->BitsPerPixel) == 8) { | |
836 int i; | |
837 | |
838 for (i = 0; i < numrects; i++) { | |
839 void *source, *destination; | |
840 int x1, x2; | |
841 | |
842 x1 = rects[i].x & ~15; | |
843 x2 = rects[i].x + rects[i].w; | |
844 if (x2 & 15) { | |
845 x2 = (x2 | 15) + 1; | |
846 } | |
847 | |
848 source = surface->pixels; | |
849 source += surface->pitch * rects[i].y; | |
850 source += x1; | |
851 | |
852 destination = XBIOS_screens[XBIOS_fbnum]; | |
853 destination += XBIOS_pitch * rects[i].y; | |
854 destination += x1; | |
855 | |
856 /* Convert chunky to planar screen */ | |
857 SDL_Atari_C2pConvert(source, | |
858 destination, | |
859 x2 - x1, | |
860 rects[i].h, | |
861 XBIOS_doubleline, | |
862 surface->pitch, XBIOS_pitch); | |
863 } | |
864 } | |
865 #ifndef DEBUG_VIDEO_XBIOS | |
866 Setscreen(-1, XBIOS_screens[XBIOS_fbnum], -1); | |
867 #endif | |
868 Vsync(); | |
869 | |
870 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { | |
871 XBIOS_fbnum ^= 1; | |
872 if ((surface->format->BitsPerPixel) > 8) { | |
873 surface->pixels = XBIOS_screens[XBIOS_fbnum]; | |
874 } | |
875 } | |
876 } | |
877 | |
878 static int | |
879 XBIOS_FlipHWSurface(_THIS, SDL_Surface * surface) | |
880 { | |
881 if ((surface->format->BitsPerPixel) == 8) { | |
882 void *destscr; | |
883 int destx; | |
884 | |
885 /* Center on destination screen */ | |
886 destscr = XBIOS_screens[XBIOS_fbnum]; | |
887 destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1); | |
888 destx = (XBIOS_width - surface->w) >> 1; | |
889 destx &= ~15; | |
890 destscr += destx; | |
891 | |
892 /* Convert chunky to planar screen */ | |
893 SDL_Atari_C2pConvert(surface->pixels, | |
894 destscr, | |
895 surface->w, | |
896 surface->h, | |
897 XBIOS_doubleline, surface->pitch, XBIOS_pitch); | |
898 } | |
899 #ifndef DEBUG_VIDEO_XBIOS | |
900 Setscreen(-1, XBIOS_screens[XBIOS_fbnum], -1); | |
901 #endif | |
902 Vsync(); | |
903 | |
904 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { | |
905 XBIOS_fbnum ^= 1; | |
906 if ((surface->format->BitsPerPixel) > 8) { | |
907 surface->pixels = XBIOS_screens[XBIOS_fbnum]; | |
908 } | |
909 } | |
910 | |
911 return (0); | |
912 } | |
913 | |
914 static int | |
915 XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) | |
916 { | |
917 int i; | |
918 int r, v, b; | |
919 | |
920 switch (XBIOS_cvdo >> 16) { | |
921 case VDO_ST: | |
922 case VDO_STE: | |
923 for (i = 0; i < ncolors; i++) { | |
924 r = colors[i].r; | |
925 v = colors[i].g; | |
926 b = colors[i].b; | |
927 | |
928 TT_palette[firstcolor + i] = | |
929 ((r * 30) + (v * 59) + (b * 11)) / 100; | |
930 } | |
931 SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */ | |
932 break; | |
933 case VDO_TT: | |
934 for (i = 0; i < ncolors; i++) { | |
935 r = colors[i].r; | |
936 v = colors[i].g; | |
937 b = colors[i].b; | |
938 | |
939 TT_palette[i] = ((r >> 4) << 8) | ((v >> 4) << 4) | (b >> 4); | |
940 } | |
941 #ifndef DEBUG_VIDEO_XBIOS | |
942 EsetPalette(firstcolor, ncolors, TT_palette); | |
943 #endif | |
944 break; | |
945 case VDO_F30: | |
946 for (i = 0; i < ncolors; i++) { | |
947 r = colors[i].r; | |
948 v = colors[i].g; | |
949 b = colors[i].b; | |
950 | |
951 F30_palette[i] = (r << 16) | (v << 8) | b; | |
952 } | |
953 #ifndef DEBUG_VIDEO_XBIOS | |
954 VsetRGB(firstcolor, ncolors, F30_palette); | |
955 #endif | |
956 break; | |
957 } | |
958 | |
959 return (1); | |
960 } | |
961 #endif | |
962 | |
963 /* Note: If we are terminated, this could be called in the middle of | |
964 another SDL video routine -- notably UpdateRects. | |
965 */ | |
966 | |
967 #if 0 | |
968 #if SDL_VIDEO_OPENGL | |
969 | |
970 static void | |
971 XBIOS_GL_SwapBuffers(_THIS) | |
972 { | |
973 SDL_AtariGL_SwapBuffers(this); | |
974 XBIOS_FlipHWSurface(this, this->screen); | |
975 SDL_AtariGL_MakeCurrent(this); | |
976 } | |
977 | |
978 #endif | |
979 #endif | |
980 /* vi: set ts=4 sw=4 expandtab: */ |