19 |
|
*/ |
20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
+ |
#include "video.h" |
23 |
|
|
24 |
|
#include <stdio.h> |
25 |
|
#include <stdlib.h> |
35 |
|
}; |
36 |
|
static VisualFormat visualFormat; |
37 |
|
|
38 |
+ |
// This holds the pixels values of the palette colors for 8->16/32-bit expansion |
39 |
+ |
uint32 ExpandMap[256]; |
40 |
+ |
|
41 |
|
/* -------------------------------------------------------------------------- */ |
42 |
|
/* --- Raw Copy / No conversion required --- */ |
43 |
|
/* -------------------------------------------------------------------------- */ |
262 |
|
#include "video_blit.h" |
263 |
|
|
264 |
|
/* -------------------------------------------------------------------------- */ |
265 |
+ |
/* --- 2/4-bit indexed to 8-bit mode conversion --- */ |
266 |
+ |
/* -------------------------------------------------------------------------- */ |
267 |
+ |
|
268 |
+ |
static void Blit_Expand_2_To_8(uint8 * dest, const uint8 * p, uint32 length) |
269 |
+ |
{ |
270 |
+ |
uint8 *q = (uint8 *)dest; |
271 |
+ |
for (uint32 i=0; i<length; i++) { |
272 |
+ |
uint8 c = *p++; |
273 |
+ |
*q++ = c >> 6; |
274 |
+ |
*q++ = (c >> 4) & 3; |
275 |
+ |
*q++ = (c >> 2) & 3; |
276 |
+ |
*q++ = c & 3; |
277 |
+ |
} |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
static void Blit_Expand_4_To_8(uint8 * dest, const uint8 * p, uint32 length) |
281 |
+ |
{ |
282 |
+ |
uint8 *q = (uint8 *)dest; |
283 |
+ |
for (uint32 i=0; i<length; i++) { |
284 |
+ |
uint8 c = *p++; |
285 |
+ |
*q++ = c >> 4; |
286 |
+ |
*q++ = c & 0x0f; |
287 |
+ |
} |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
/* -------------------------------------------------------------------------- */ |
291 |
+ |
/* --- 2/4/8-bit indexed to 16-bit mode color expansion --- */ |
292 |
+ |
/* -------------------------------------------------------------------------- */ |
293 |
+ |
|
294 |
+ |
static void Blit_Expand_2_To_16(uint8 * dest, const uint8 * p, uint32 length) |
295 |
+ |
{ |
296 |
+ |
uint16 *q = (uint16 *)dest; |
297 |
+ |
for (uint32 i=0; i<length; i++) { |
298 |
+ |
uint8 c = *p++; |
299 |
+ |
*q++ = ExpandMap[c >> 6]; |
300 |
+ |
*q++ = ExpandMap[c >> 4]; |
301 |
+ |
*q++ = ExpandMap[c >> 2]; |
302 |
+ |
*q++ = ExpandMap[c]; |
303 |
+ |
} |
304 |
+ |
} |
305 |
+ |
|
306 |
+ |
static void Blit_Expand_4_To_16(uint8 * dest, const uint8 * p, uint32 length) |
307 |
+ |
{ |
308 |
+ |
uint16 *q = (uint16 *)dest; |
309 |
+ |
for (uint32 i=0; i<length; i++) { |
310 |
+ |
uint8 c = *p++; |
311 |
+ |
*q++ = ExpandMap[c >> 4]; |
312 |
+ |
*q++ = ExpandMap[c]; |
313 |
+ |
} |
314 |
+ |
} |
315 |
+ |
|
316 |
+ |
static void Blit_Expand_8_To_16(uint8 * dest, const uint8 * p, uint32 length) |
317 |
+ |
{ |
318 |
+ |
uint16 *q = (uint16 *)dest; |
319 |
+ |
for (uint32 i=0; i<length; i++) |
320 |
+ |
*q++ = ExpandMap[*p++]; |
321 |
+ |
} |
322 |
+ |
|
323 |
+ |
/* -------------------------------------------------------------------------- */ |
324 |
+ |
/* --- 2/4/8-bit indexed to 32-bit mode color expansion --- */ |
325 |
+ |
/* -------------------------------------------------------------------------- */ |
326 |
+ |
|
327 |
+ |
static void Blit_Expand_2_To_32(uint8 * dest, const uint8 * p, uint32 length) |
328 |
+ |
{ |
329 |
+ |
uint32 *q = (uint32 *)dest; |
330 |
+ |
for (uint32 i=0; i<length; i++) { |
331 |
+ |
uint8 c = *p++; |
332 |
+ |
*q++ = ExpandMap[c >> 6]; |
333 |
+ |
*q++ = ExpandMap[c >> 4]; |
334 |
+ |
*q++ = ExpandMap[c >> 2]; |
335 |
+ |
*q++ = ExpandMap[c]; |
336 |
+ |
} |
337 |
+ |
} |
338 |
+ |
|
339 |
+ |
static void Blit_Expand_4_To_32(uint8 * dest, const uint8 * p, uint32 length) |
340 |
+ |
{ |
341 |
+ |
uint32 *q = (uint32 *)dest; |
342 |
+ |
for (uint32 i=0; i<length; i++) { |
343 |
+ |
uint8 c = *p++; |
344 |
+ |
*q++ = ExpandMap[c >> 4]; |
345 |
+ |
*q++ = ExpandMap[c]; |
346 |
+ |
} |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
static void Blit_Expand_8_To_32(uint8 * dest, const uint8 * p, uint32 length) |
350 |
+ |
{ |
351 |
+ |
uint32 *q = (uint32 *)dest; |
352 |
+ |
for (uint32 i=0; i<length; i++) |
353 |
+ |
*q++ = ExpandMap[*p++]; |
354 |
+ |
} |
355 |
+ |
|
356 |
+ |
/* -------------------------------------------------------------------------- */ |
357 |
|
/* --- Blitters to the host frame buffer, or XImage buffer --- */ |
358 |
|
/* -------------------------------------------------------------------------- */ |
359 |
|
|
400 |
|
// Initialize the framebuffer update function |
401 |
|
// Returns FALSE, if the function was to be reduced to a simple memcpy() |
402 |
|
// --> In that case, VOSF is not necessary |
403 |
< |
bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order) |
403 |
> |
bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth) |
404 |
|
{ |
405 |
< |
visualFormat.depth = visual_info->depth; |
406 |
< |
visualFormat.Rmask = visual_info->red_mask; |
407 |
< |
visualFormat.Gmask = visual_info->green_mask; |
408 |
< |
visualFormat.Bmask = visual_info->blue_mask; |
405 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
406 |
> |
if (mac_depth == VDEPTH_1BIT) { |
407 |
> |
|
408 |
> |
// 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines |
409 |
> |
Screen_blit = Blit_Copy_Raw; |
410 |
> |
|
411 |
> |
} else { |
412 |
> |
|
413 |
> |
visualFormat.depth = visual_info->depth; |
414 |
> |
visualFormat.Rmask = visual_info->red_mask; |
415 |
> |
visualFormat.Gmask = visual_info->green_mask; |
416 |
> |
visualFormat.Bmask = visual_info->blue_mask; |
417 |
> |
|
418 |
> |
// Compute RGB shift values |
419 |
> |
visualFormat.Rshift = 0; |
420 |
> |
for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1) |
421 |
> |
++visualFormat.Rshift; |
422 |
> |
visualFormat.Gshift = 0; |
423 |
> |
for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1) |
424 |
> |
++visualFormat.Gshift; |
425 |
> |
visualFormat.Bshift = 0; |
426 |
> |
for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1) |
427 |
> |
++visualFormat.Bshift; |
428 |
> |
|
429 |
> |
bool blitter_found = false; |
430 |
|
|
431 |
< |
// Compute RGB shift values |
432 |
< |
visualFormat.Rshift = 0; |
433 |
< |
for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1) |
434 |
< |
++visualFormat.Rshift; |
435 |
< |
visualFormat.Gshift = 0; |
436 |
< |
for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1) |
437 |
< |
++visualFormat.Gshift; |
438 |
< |
visualFormat.Bshift = 0; |
439 |
< |
for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1) |
440 |
< |
++visualFormat.Bshift; |
431 |
> |
// 2/4/8-bit mode on 8/16/32-bit screen? |
432 |
> |
if (visualFormat.depth == 8) { |
433 |
> |
if (mac_depth == VDEPTH_2BIT) { |
434 |
> |
Screen_blit = Blit_Expand_2_To_8; |
435 |
> |
blitter_found = true; |
436 |
> |
} else if (mac_depth == VDEPTH_4BIT) { |
437 |
> |
Screen_blit = Blit_Expand_4_To_8; |
438 |
> |
blitter_found = true; |
439 |
> |
} |
440 |
> |
} else if (visualFormat.depth == 15 || visualFormat.depth == 16) { |
441 |
> |
if (mac_depth == VDEPTH_2BIT) { |
442 |
> |
Screen_blit = Blit_Expand_2_To_16; |
443 |
> |
blitter_found = true; |
444 |
> |
} else if (mac_depth == VDEPTH_4BIT) { |
445 |
> |
Screen_blit = Blit_Expand_4_To_16; |
446 |
> |
blitter_found = true; |
447 |
> |
} else if (mac_depth == VDEPTH_8BIT) { |
448 |
> |
Screen_blit = Blit_Expand_8_To_16; |
449 |
> |
blitter_found = true; |
450 |
> |
} |
451 |
> |
} else if (visualFormat.depth == 24 || visualFormat.depth == 32) { |
452 |
> |
if (mac_depth == VDEPTH_2BIT) { |
453 |
> |
Screen_blit = Blit_Expand_2_To_32; |
454 |
> |
blitter_found = true; |
455 |
> |
} else if (mac_depth == VDEPTH_4BIT) { |
456 |
> |
Screen_blit = Blit_Expand_4_To_32; |
457 |
> |
blitter_found = true; |
458 |
> |
} else if (mac_depth == VDEPTH_8BIT) { |
459 |
> |
Screen_blit = Blit_Expand_8_To_32; |
460 |
> |
blitter_found = true; |
461 |
> |
} |
462 |
> |
} |
463 |
|
|
464 |
< |
// Search for an adequate blit function |
465 |
< |
bool blitter_found = false; |
466 |
< |
const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]); |
467 |
< |
for (int i = 0; !blitter_found && (i < blitters_count); i++) { |
468 |
< |
if ( (visualFormat.depth == Screen_blitters[i].depth) |
469 |
< |
&& (visualFormat.Rmask == Screen_blitters[i].Rmask) |
470 |
< |
&& (visualFormat.Gmask == Screen_blitters[i].Gmask) |
471 |
< |
&& (visualFormat.Bmask == Screen_blitters[i].Bmask) |
472 |
< |
) |
473 |
< |
{ |
474 |
< |
blitter_found = true; |
475 |
< |
Screen_blit = native_byte_order |
476 |
< |
? Screen_blitters[i].handler_nbo |
477 |
< |
: Screen_blitters[i].handler_obo |
478 |
< |
; |
464 |
> |
// Search for an adequate blit function |
465 |
> |
const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]); |
466 |
> |
for (int i = 0; !blitter_found && (i < blitters_count); i++) { |
467 |
> |
if ( (visualFormat.depth == Screen_blitters[i].depth) |
468 |
> |
&& (visualFormat.Rmask == Screen_blitters[i].Rmask) |
469 |
> |
&& (visualFormat.Gmask == Screen_blitters[i].Gmask) |
470 |
> |
&& (visualFormat.Bmask == Screen_blitters[i].Bmask) |
471 |
> |
) |
472 |
> |
{ |
473 |
> |
blitter_found = true; |
474 |
> |
Screen_blit = native_byte_order |
475 |
> |
? Screen_blitters[i].handler_nbo |
476 |
> |
: Screen_blitters[i].handler_obo |
477 |
> |
; |
478 |
> |
} |
479 |
|
} |
341 |
– |
} |
480 |
|
|
481 |
< |
// No appropriate blitter found, dump RGB mask values and abort() |
482 |
< |
if (!blitter_found) { |
483 |
< |
fprintf(stderr, "### No appropriate blitter found\n"); |
484 |
< |
fprintf(stderr, "\tR/G/B mask values : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n", |
485 |
< |
visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth); |
486 |
< |
fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n", |
487 |
< |
visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift); |
488 |
< |
abort(); |
481 |
> |
// No appropriate blitter found, dump RGB mask values and abort() |
482 |
> |
if (!blitter_found) { |
483 |
> |
fprintf(stderr, "### No appropriate blitter found\n"); |
484 |
> |
fprintf(stderr, "\tR/G/B mask values : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n", |
485 |
> |
visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth); |
486 |
> |
fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n", |
487 |
> |
visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift); |
488 |
> |
abort(); |
489 |
> |
} |
490 |
|
} |
491 |
+ |
#else |
492 |
+ |
// The UAE memory handlers will blit correctly |
493 |
+ |
// --> no need for specialised blitters here |
494 |
+ |
Screen_blit = Blit_Copy_Raw; |
495 |
+ |
#endif |
496 |
|
|
497 |
|
// If the blitter simply reduces to a copy, we don't need VOSF in DGA mode |
498 |
|
// --> In that case, we return FALSE |