1 |
|
/* |
2 |
|
* video_blit.h - Video/graphics emulation, blitters |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 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 |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
*/ |
20 |
|
|
21 |
< |
#ifndef FB_BLIT_1 |
22 |
< |
# error "Undefined 16-bit word blit function" |
21 |
> |
#ifndef FB_DEPTH |
22 |
> |
# error "Undefined screen depth" |
23 |
|
#endif |
24 |
|
|
25 |
< |
#ifndef FB_BLIT_2 |
26 |
< |
# error "Undefined 32-bit word blit function" |
25 |
> |
#if !defined(FB_BLIT_1) && (FB_DEPTH <= 16) |
26 |
> |
# error "Undefined 16-bit word blit function" |
27 |
|
#endif |
28 |
|
|
29 |
< |
#ifndef FB_DEPTH |
30 |
< |
# error "Undefined screen depth" |
29 |
> |
#if !defined(FB_BLIT_2) |
30 |
> |
# error "Undefined 32-bit word blit function" |
31 |
|
#endif |
32 |
|
|
33 |
|
static void FB_FUNC_NAME(uint8 * dest, const uint8 * source, uint32 length) |
34 |
|
{ |
35 |
+ |
#define DEREF_LONG_PTR(ptr, ofs) (((uint32 *)(ptr))[(ofs)]) |
36 |
+ |
#define DEREF_WORD_PTR(ptr, ofs) (((uint16 *)(ptr))[(ofs)]) |
37 |
+ |
|
38 |
+ |
#ifndef UNALIGNED_PROFITABLE |
39 |
|
#if FB_DEPTH <= 8 |
40 |
|
// Align source and dest to 16-bit word boundaries |
41 |
< |
if (FB_DEPTH <= 8 && ((unsigned long) source) & 1) { |
41 |
> |
if (((unsigned long) source) & 1) { |
42 |
|
*dest++ = *source++; |
43 |
|
length -= 1; |
44 |
|
} |
45 |
|
#endif |
46 |
|
|
43 |
– |
// source and dest are mutually aligned |
44 |
– |
uint16 * swp = ((uint16 *)source); |
45 |
– |
uint16 * dwp = ((uint16 *) dest ); |
46 |
– |
|
47 |
|
#if FB_DEPTH <= 16 |
48 |
|
// Align source and dest to 32-bit word boundaries |
49 |
|
if (((unsigned long) source) & 2) { |
50 |
< |
const uint16 val = *swp++; |
51 |
< |
FB_BLIT_1(*dwp++, val); |
50 |
> |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
51 |
> |
dest += 2; source += 2; |
52 |
|
length -= 2; |
53 |
|
} |
54 |
|
#endif |
55 |
+ |
#endif |
56 |
|
|
57 |
|
// Blit 4-byte words |
58 |
|
if (length >= 4) { |
59 |
|
const int remainder = (length / 4) % 8; |
60 |
< |
uint32 * slp = (uint32 *)swp + remainder; |
61 |
< |
uint32 * dlp = (uint32 *)dwp + remainder; |
60 |
> |
source += remainder * 4; |
61 |
> |
dest += remainder * 4; |
62 |
|
|
63 |
|
int n = ((length / 4) + 7) / 8; |
64 |
|
switch (remainder) { |
65 |
|
case 0: do { |
66 |
< |
slp += 8; dlp += 8; |
67 |
< |
FB_BLIT_2(dlp[-8], slp[-8]); |
68 |
< |
case 7: FB_BLIT_2(dlp[-7], slp[-7]); |
69 |
< |
case 6: FB_BLIT_2(dlp[-6], slp[-6]); |
70 |
< |
case 5: FB_BLIT_2(dlp[-5], slp[-5]); |
71 |
< |
case 4: FB_BLIT_2(dlp[-4], slp[-4]); |
72 |
< |
case 3: FB_BLIT_2(dlp[-3], slp[-3]); |
73 |
< |
case 2: FB_BLIT_2(dlp[-2], slp[-2]); |
74 |
< |
case 1: FB_BLIT_2(dlp[-1], slp[-1]); |
66 |
> |
dest += 32; source += 32; |
67 |
> |
FB_BLIT_2(DEREF_LONG_PTR(dest, -8), DEREF_LONG_PTR(source, -8)); |
68 |
> |
case 7: FB_BLIT_2(DEREF_LONG_PTR(dest, -7), DEREF_LONG_PTR(source, -7)); |
69 |
> |
case 6: FB_BLIT_2(DEREF_LONG_PTR(dest, -6), DEREF_LONG_PTR(source, -6)); |
70 |
> |
case 5: FB_BLIT_2(DEREF_LONG_PTR(dest, -5), DEREF_LONG_PTR(source, -5)); |
71 |
> |
case 4: FB_BLIT_2(DEREF_LONG_PTR(dest, -4), DEREF_LONG_PTR(source, -4)); |
72 |
> |
case 3: FB_BLIT_2(DEREF_LONG_PTR(dest, -3), DEREF_LONG_PTR(source, -3)); |
73 |
> |
case 2: FB_BLIT_2(DEREF_LONG_PTR(dest, -2), DEREF_LONG_PTR(source, -2)); |
74 |
> |
case 1: FB_BLIT_2(DEREF_LONG_PTR(dest, -1), DEREF_LONG_PTR(source, -1)); |
75 |
|
} while (--n > 0); |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
|
#if FB_DEPTH <= 16 |
80 |
< |
// There might remain one word to blit |
80 |
> |
// There could be one word left to blit |
81 |
|
if (length & 2) { |
82 |
< |
uint16 * const s = (uint16 *)(((uint8 *)swp) + length - 2); |
83 |
< |
uint16 * const d = (uint16 *)(((uint8 *)dwp) + length - 2); |
84 |
< |
FB_BLIT_1(*d, *s); |
82 |
> |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
83 |
> |
#if FB_DEPTH <= 8 |
84 |
> |
dest += 2; |
85 |
> |
source += 2; |
86 |
> |
#endif |
87 |
|
} |
88 |
|
#endif |
89 |
+ |
|
90 |
+ |
#if FB_DEPTH <= 8 |
91 |
+ |
// There could be one byte left to blit |
92 |
+ |
if (length & 1) |
93 |
+ |
*dest = *source; |
94 |
+ |
#endif |
95 |
+ |
|
96 |
+ |
#undef DEREF_LONG_PTR |
97 |
+ |
#undef DEREF_WORD_PTR |
98 |
|
} |
99 |
|
|
100 |
|
#undef FB_FUNC_NAME |