1 |
|
/* |
2 |
|
* video_blit.cpp - Video/graphics emulation, blitters |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2005 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
|
#include "video.h" |
23 |
+ |
#include "video_blit.h" |
24 |
|
|
25 |
|
#include <stdio.h> |
26 |
|
#include <stdlib.h> |
26 |
– |
#include <X11/Xlib.h> |
27 |
– |
#include <X11/Xutil.h> |
27 |
|
|
29 |
– |
#ifdef ENABLE_VOSF |
28 |
|
// Format of the target visual |
31 |
– |
struct VisualFormat { |
32 |
– |
int depth; // Screen depth |
33 |
– |
uint32 Rmask, Gmask, Bmask; // RGB mask values |
34 |
– |
uint32 Rshift, Gshift, Bshift; // RGB shift values |
35 |
– |
}; |
29 |
|
static VisualFormat visualFormat; |
30 |
|
|
31 |
|
// This holds the pixels values of the palette colors for 8->16/32-bit expansion |
32 |
|
uint32 ExpandMap[256]; |
33 |
|
|
34 |
+ |
// Mark video_blit.h for specialization |
35 |
+ |
#define DEFINE_VIDEO_BLITTERS 1 |
36 |
+ |
|
37 |
|
/* -------------------------------------------------------------------------- */ |
38 |
|
/* --- Raw Copy / No conversion required --- */ |
39 |
|
/* -------------------------------------------------------------------------- */ |
302 |
|
#include "video_blit.h" |
303 |
|
|
304 |
|
/* -------------------------------------------------------------------------- */ |
305 |
< |
/* --- 2/4-bit indexed to 8-bit mode conversion --- */ |
305 |
> |
/* --- 1/2/4-bit indexed to 8-bit mode conversion --- */ |
306 |
|
/* -------------------------------------------------------------------------- */ |
307 |
|
|
308 |
+ |
static void Blit_Expand_1_To_8(uint8 * dest, const uint8 * p, uint32 length) |
309 |
+ |
{ |
310 |
+ |
uint8 *q = (uint8 *)dest; |
311 |
+ |
for (uint32 i=0; i<length; i++) { |
312 |
+ |
uint8 c = *p++; |
313 |
+ |
*q++ = c >> 7; |
314 |
+ |
*q++ = (c >> 6) & 1; |
315 |
+ |
*q++ = (c >> 5) & 1; |
316 |
+ |
*q++ = (c >> 4) & 1; |
317 |
+ |
*q++ = (c >> 3) & 1; |
318 |
+ |
*q++ = (c >> 2) & 1; |
319 |
+ |
*q++ = (c >> 1) & 1; |
320 |
+ |
*q++ = c & 1; |
321 |
+ |
} |
322 |
+ |
} |
323 |
+ |
|
324 |
|
static void Blit_Expand_2_To_8(uint8 * dest, const uint8 * p, uint32 length) |
325 |
|
{ |
326 |
|
uint8 *q = (uint8 *)dest; |
344 |
|
} |
345 |
|
|
346 |
|
/* -------------------------------------------------------------------------- */ |
347 |
< |
/* --- 2/4/8-bit indexed to 16-bit mode color expansion --- */ |
347 |
> |
/* --- 1/2/4/8-bit indexed to 16-bit mode color expansion --- */ |
348 |
|
/* -------------------------------------------------------------------------- */ |
349 |
|
|
350 |
+ |
static void Blit_Expand_1_To_16(uint8 * dest, const uint8 * p, uint32 length) |
351 |
+ |
{ |
352 |
+ |
uint16 *q = (uint16 *)dest; |
353 |
+ |
for (uint32 i=0; i<length; i++) { |
354 |
+ |
uint8 c = *p++; |
355 |
+ |
*q++ = -(c >> 7); |
356 |
+ |
*q++ = -((c >> 6) & 1); |
357 |
+ |
*q++ = -((c >> 5) & 1); |
358 |
+ |
*q++ = -((c >> 4) & 1); |
359 |
+ |
*q++ = -((c >> 3) & 1); |
360 |
+ |
*q++ = -((c >> 2) & 1); |
361 |
+ |
*q++ = -((c >> 1) & 1); |
362 |
+ |
*q++ = -(c & 1); |
363 |
+ |
} |
364 |
+ |
} |
365 |
+ |
|
366 |
|
static void Blit_Expand_2_To_16(uint8 * dest, const uint8 * p, uint32 length) |
367 |
|
{ |
368 |
|
uint16 *q = (uint16 *)dest; |
393 |
|
} |
394 |
|
|
395 |
|
/* -------------------------------------------------------------------------- */ |
396 |
< |
/* --- 2/4/8-bit indexed to 32-bit mode color expansion --- */ |
396 |
> |
/* --- 1/2/4/8-bit indexed to 32-bit mode color expansion --- */ |
397 |
|
/* -------------------------------------------------------------------------- */ |
398 |
|
|
399 |
+ |
static void Blit_Expand_1_To_32(uint8 * dest, const uint8 * p, uint32 length) |
400 |
+ |
{ |
401 |
+ |
uint32 *q = (uint32 *)dest; |
402 |
+ |
for (uint32 i=0; i<length; i++) { |
403 |
+ |
uint8 c = *p++; |
404 |
+ |
*q++ = -(c >> 7); |
405 |
+ |
*q++ = -((c >> 6) & 1); |
406 |
+ |
*q++ = -((c >> 5) & 1); |
407 |
+ |
*q++ = -((c >> 4) & 1); |
408 |
+ |
*q++ = -((c >> 3) & 1); |
409 |
+ |
*q++ = -((c >> 2) & 1); |
410 |
+ |
*q++ = -((c >> 1) & 1); |
411 |
+ |
*q++ = -(c & 1); |
412 |
+ |
} |
413 |
+ |
} |
414 |
+ |
|
415 |
|
static void Blit_Expand_2_To_32(uint8 * dest, const uint8 * p, uint32 length) |
416 |
|
{ |
417 |
|
uint32 *q = (uint32 *)dest; |
467 |
|
{ 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO) |
468 |
|
{ 15, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw , Blit_RGB555_OBO }, // OK (OBO) |
469 |
|
{ 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO , Blit_BGR555_OBO }, // NT |
470 |
+ |
{ 16, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw , Blit_RGB555_OBO }, // OK (OBO) |
471 |
|
{ 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (OBO) |
472 |
|
{ 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK (OBO) |
473 |
|
{ 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT |
478 |
|
{ 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO) |
479 |
|
{ 15, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO , Blit_Copy_Raw }, // OK (NBO) |
480 |
|
{ 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO , Blit_BGR555_OBO }, // NT |
481 |
+ |
{ 16, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO , Blit_Copy_Raw }, // OK (NBO) |
482 |
|
{ 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (NBO) |
483 |
|
{ 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO) |
484 |
|
{ 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT |
490 |
|
// Initialize the framebuffer update function |
491 |
|
// Returns FALSE, if the function was to be reduced to a simple memcpy() |
492 |
|
// --> In that case, VOSF is not necessary |
493 |
< |
bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth) |
493 |
> |
bool Screen_blitter_init(VisualFormat const & visual_format, bool native_byte_order, int mac_depth) |
494 |
|
{ |
495 |
+ |
#if USE_SDL_VIDEO |
496 |
+ |
const bool use_sdl_video = true; |
497 |
+ |
#else |
498 |
+ |
const bool use_sdl_video = false; |
499 |
+ |
#endif |
500 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
501 |
< |
if (mac_depth == VDEPTH_1BIT) { |
501 |
> |
if (mac_depth == 1 && !use_sdl_video && !visual_format.fullscreen) { |
502 |
|
|
503 |
< |
// 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines |
503 |
> |
// Windowed 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines |
504 |
|
Screen_blit = Blit_Copy_Raw; |
505 |
|
|
506 |
|
} else { |
507 |
|
|
457 |
– |
visualFormat.depth = visual_info->depth; |
458 |
– |
visualFormat.Rmask = visual_info->red_mask; |
459 |
– |
visualFormat.Gmask = visual_info->green_mask; |
460 |
– |
visualFormat.Bmask = visual_info->blue_mask; |
461 |
– |
|
508 |
|
// Compute RGB shift values |
509 |
+ |
visualFormat = visual_format; |
510 |
|
visualFormat.Rshift = 0; |
511 |
|
for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1) |
512 |
|
++visualFormat.Rshift; |
517 |
|
for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1) |
518 |
|
++visualFormat.Bshift; |
519 |
|
|
520 |
< |
bool blitter_found = false; |
521 |
< |
|
522 |
< |
// 2/4/8-bit mode on 8/16/32-bit screen? |
523 |
< |
if (visualFormat.depth == 8) { |
524 |
< |
if (mac_depth == VDEPTH_2BIT) { |
525 |
< |
Screen_blit = Blit_Expand_2_To_8; |
526 |
< |
blitter_found = true; |
527 |
< |
} else if (mac_depth == VDEPTH_4BIT) { |
481 |
< |
Screen_blit = Blit_Expand_4_To_8; |
482 |
< |
blitter_found = true; |
520 |
> |
// 1/2/4/8-bit mode on 8/16/32-bit screen? |
521 |
> |
Screen_blit = NULL; |
522 |
> |
switch (visualFormat.depth) { |
523 |
> |
case 8: |
524 |
> |
switch (mac_depth) { |
525 |
> |
case 1: Screen_blit = Blit_Expand_1_To_8; break; |
526 |
> |
case 2: Screen_blit = Blit_Expand_2_To_8; break; |
527 |
> |
case 4: Screen_blit = Blit_Expand_4_To_8; break; |
528 |
|
} |
529 |
< |
} else if (visualFormat.depth == 15 || visualFormat.depth == 16) { |
530 |
< |
if (mac_depth == VDEPTH_2BIT) { |
531 |
< |
Screen_blit = Blit_Expand_2_To_16; |
532 |
< |
blitter_found = true; |
533 |
< |
} else if (mac_depth == VDEPTH_4BIT) { |
534 |
< |
Screen_blit = Blit_Expand_4_To_16; |
535 |
< |
blitter_found = true; |
536 |
< |
} else if (mac_depth == VDEPTH_8BIT) { |
492 |
< |
Screen_blit = Blit_Expand_8_To_16; |
493 |
< |
blitter_found = true; |
529 |
> |
break; |
530 |
> |
case 15: |
531 |
> |
case 16: |
532 |
> |
switch (mac_depth) { |
533 |
> |
case 1: Screen_blit = Blit_Expand_1_To_16; break; |
534 |
> |
case 2: Screen_blit = Blit_Expand_2_To_16; break; |
535 |
> |
case 4: Screen_blit = Blit_Expand_4_To_16; break; |
536 |
> |
case 8: Screen_blit = Blit_Expand_8_To_16; break; |
537 |
|
} |
538 |
< |
} else if (visualFormat.depth == 24 || visualFormat.depth == 32) { |
539 |
< |
if (mac_depth == VDEPTH_2BIT) { |
540 |
< |
Screen_blit = Blit_Expand_2_To_32; |
541 |
< |
blitter_found = true; |
542 |
< |
} else if (mac_depth == VDEPTH_4BIT) { |
543 |
< |
Screen_blit = Blit_Expand_4_To_32; |
544 |
< |
blitter_found = true; |
545 |
< |
} else if (mac_depth == VDEPTH_8BIT) { |
503 |
< |
Screen_blit = Blit_Expand_8_To_32; |
504 |
< |
blitter_found = true; |
538 |
> |
break; |
539 |
> |
case 24: |
540 |
> |
case 32: |
541 |
> |
switch (mac_depth) { |
542 |
> |
case 1: Screen_blit = Blit_Expand_1_To_32; break; |
543 |
> |
case 2: Screen_blit = Blit_Expand_2_To_32; break; |
544 |
> |
case 4: Screen_blit = Blit_Expand_4_To_32; break; |
545 |
> |
case 8: Screen_blit = Blit_Expand_8_To_32; break; |
546 |
|
} |
547 |
+ |
break; |
548 |
|
} |
549 |
+ |
bool blitter_found = (Screen_blit != NULL); |
550 |
|
|
551 |
|
// Search for an adequate blit function |
552 |
|
const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]); |
585 |
|
// --> In that case, we return FALSE |
586 |
|
return (Screen_blit != Blit_Copy_Raw); |
587 |
|
} |
545 |
– |
#endif /* ENABLE_VOSF */ |