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 |
21 |
> |
#ifndef FB_DEPTH |
22 |
> |
# error "Undefined screen depth" |
23 |
> |
#endif |
24 |
> |
|
25 |
> |
#if !defined(FB_BLIT_1) && (FB_DEPTH <= 16) |
26 |
|
# error "Undefined 16-bit word blit function" |
27 |
|
#endif |
28 |
|
|
29 |
< |
#ifndef FB_BLIT_2 |
29 |
> |
#if !defined(FB_BLIT_2) |
30 |
|
# error "Undefined 32-bit word blit function" |
31 |
|
#endif |
32 |
|
|
33 |
< |
#ifndef FB_DEPTH |
34 |
< |
# error "Undefined screen depth" |
33 |
> |
#if !defined(FB_BLIT_4) |
34 |
> |
# error "Undefined 64-bit word blit function" |
35 |
|
#endif |
36 |
|
|
37 |
|
static void FB_FUNC_NAME(uint8 * dest, const uint8 * source, uint32 length) |
38 |
|
{ |
39 |
< |
union { |
40 |
< |
uint8 * bp; |
41 |
< |
uint16 * wp; |
38 |
< |
uint32 * lp; |
39 |
< |
} s, d; |
40 |
< |
|
41 |
< |
s.bp = (uint8 *)source; |
42 |
< |
d.bp = dest; |
39 |
> |
#define DEREF_WORD_PTR(ptr, ofs) (((uint16 *)(ptr))[(ofs)]) |
40 |
> |
#define DEREF_LONG_PTR(ptr, ofs) (((uint32 *)(ptr))[(ofs)]) |
41 |
> |
#define DEREF_QUAD_PTR(ptr, ofs) (((uint64 *)(ptr))[(ofs)]) |
42 |
|
|
43 |
+ |
#ifndef UNALIGNED_PROFITABLE |
44 |
|
#if FB_DEPTH <= 8 |
45 |
|
// Align source and dest to 16-bit word boundaries |
46 |
< |
if (FB_DEPTH <= 8 && ((unsigned long) source) & 1) { |
47 |
< |
*d.bp++ = *s.bp++; |
46 |
> |
if (((unsigned long) source) & 1) { |
47 |
> |
*dest++ = *source++; |
48 |
|
length -= 1; |
49 |
|
} |
50 |
|
#endif |
51 |
|
|
52 |
– |
#if FB_DEPTH <= 8 |
53 |
– |
if (length >= 2) { |
54 |
– |
#endif |
55 |
– |
|
52 |
|
#if FB_DEPTH <= 16 |
53 |
|
// Align source and dest to 32-bit word boundaries |
54 |
|
if (((unsigned long) source) & 2) { |
55 |
< |
const uint16 val = *s.wp++; |
56 |
< |
FB_BLIT_1(*d.wp++, val); |
55 |
> |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
56 |
> |
dest += 2; source += 2; |
57 |
|
length -= 2; |
58 |
|
} |
59 |
|
#endif |
60 |
+ |
#endif |
61 |
|
|
62 |
< |
// Blit 4-byte words |
63 |
< |
if (length >= 4) { |
64 |
< |
const int remainder = (length / 4) % 8; |
65 |
< |
s.lp += remainder; |
66 |
< |
d.lp += remainder; |
62 |
> |
// Blit 8-byte words |
63 |
> |
if (length >= 8) { |
64 |
> |
const int remainder = (length / 8) % 8; |
65 |
> |
source += remainder * 8; |
66 |
> |
dest += remainder * 8; |
67 |
|
|
68 |
< |
int n = ((length / 4) + 7) / 8; |
68 |
> |
int n = ((length / 8) + 7) / 8; |
69 |
|
switch (remainder) { |
70 |
|
case 0: do { |
71 |
< |
s.lp += 8; d.lp += 8; |
72 |
< |
FB_BLIT_2(d.lp[-8], s.lp[-8]); |
73 |
< |
case 7: FB_BLIT_2(d.lp[-7], s.lp[-7]); |
74 |
< |
case 6: FB_BLIT_2(d.lp[-6], s.lp[-6]); |
75 |
< |
case 5: FB_BLIT_2(d.lp[-5], s.lp[-5]); |
76 |
< |
case 4: FB_BLIT_2(d.lp[-4], s.lp[-4]); |
77 |
< |
case 3: FB_BLIT_2(d.lp[-3], s.lp[-3]); |
78 |
< |
case 2: FB_BLIT_2(d.lp[-2], s.lp[-2]); |
79 |
< |
case 1: FB_BLIT_2(d.lp[-1], s.lp[-1]); |
71 |
> |
dest += 64; source += 64; |
72 |
> |
FB_BLIT_4(DEREF_QUAD_PTR(dest, -8), DEREF_QUAD_PTR(source, -8)); |
73 |
> |
case 7: FB_BLIT_4(DEREF_QUAD_PTR(dest, -7), DEREF_QUAD_PTR(source, -7)); |
74 |
> |
case 6: FB_BLIT_4(DEREF_QUAD_PTR(dest, -6), DEREF_QUAD_PTR(source, -6)); |
75 |
> |
case 5: FB_BLIT_4(DEREF_QUAD_PTR(dest, -5), DEREF_QUAD_PTR(source, -5)); |
76 |
> |
case 4: FB_BLIT_4(DEREF_QUAD_PTR(dest, -4), DEREF_QUAD_PTR(source, -4)); |
77 |
> |
case 3: FB_BLIT_4(DEREF_QUAD_PTR(dest, -3), DEREF_QUAD_PTR(source, -3)); |
78 |
> |
case 2: FB_BLIT_4(DEREF_QUAD_PTR(dest, -2), DEREF_QUAD_PTR(source, -2)); |
79 |
> |
case 1: FB_BLIT_4(DEREF_QUAD_PTR(dest, -1), DEREF_QUAD_PTR(source, -1)); |
80 |
|
} while (--n > 0); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
+ |
// There could be one long left to blit |
85 |
+ |
if (length & 4) { |
86 |
+ |
FB_BLIT_2(DEREF_LONG_PTR(dest, 0), DEREF_LONG_PTR(source, 0)); |
87 |
+ |
#if FB_DEPTH <= 16 |
88 |
+ |
dest += 4; |
89 |
+ |
source += 4; |
90 |
+ |
#endif |
91 |
+ |
} |
92 |
+ |
|
93 |
|
#if FB_DEPTH <= 16 |
94 |
< |
// There might remain at least one word to blit |
94 |
> |
// There could be one word left to blit |
95 |
|
if (length & 2) { |
96 |
< |
FB_BLIT_1(*d.wp, *s.wp); |
96 |
> |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
97 |
|
#if FB_DEPTH <= 8 |
98 |
< |
d.wp++; |
99 |
< |
s.wp++; |
98 |
> |
dest += 2; |
99 |
> |
source += 2; |
100 |
|
#endif |
101 |
|
} |
102 |
|
#endif |
103 |
|
|
104 |
|
#if FB_DEPTH <= 8 |
105 |
< |
} |
100 |
< |
|
101 |
< |
// There might remain one byte to blit |
105 |
> |
// There could be one byte left to blit |
106 |
|
if (length & 1) |
107 |
< |
*d.bp = *s.bp; |
107 |
> |
*dest = *source; |
108 |
|
#endif |
109 |
+ |
|
110 |
+ |
#undef DEREF_LONG_PTR |
111 |
+ |
#undef DEREF_WORD_PTR |
112 |
|
} |
113 |
|
|
114 |
|
#undef FB_FUNC_NAME |
121 |
|
#undef FB_BLIT_2 |
122 |
|
#endif |
123 |
|
|
124 |
+ |
#ifdef FB_BLIT_4 |
125 |
+ |
#undef FB_BLIT_4 |
126 |
+ |
#endif |
127 |
+ |
|
128 |
|
#ifdef FB_DEPTH |
129 |
|
#undef FB_DEPTH |
130 |
|
#endif |