1 |
gbeauche |
1.1 |
/* |
2 |
|
|
* video_blit.h - Video/graphics emulation, blitters |
3 |
|
|
* |
4 |
cebix |
1.7 |
* Basilisk II (C) 1997-2004 Christian Bauer |
5 |
gbeauche |
1.1 |
* |
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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
gbeauche |
1.8 |
#ifndef DEFINE_VIDEO_BLITTERS |
22 |
|
|
|
23 |
|
|
#ifndef VIDEO_BLIT_H |
24 |
|
|
#define VIDEO_BLIT_H |
25 |
|
|
|
26 |
|
|
// Format of the target visual |
27 |
|
|
struct VisualFormat { |
28 |
|
|
int depth; // Screen depth |
29 |
|
|
uint32 Rmask, Gmask, Bmask; // RGB mask values |
30 |
|
|
uint32 Rshift, Gshift, Bshift; // RGB shift values |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
|
extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); |
34 |
|
|
extern bool Screen_blitter_init(VisualFormat const & visual_format, bool native_byte_order, int mac_depth); |
35 |
|
|
extern uint32 ExpandMap[256]; |
36 |
|
|
|
37 |
|
|
#endif /* VIDEO_BLIT_H */ |
38 |
|
|
|
39 |
|
|
#else |
40 |
|
|
|
41 |
gbeauche |
1.4 |
#ifndef FB_DEPTH |
42 |
|
|
# error "Undefined screen depth" |
43 |
|
|
#endif |
44 |
|
|
|
45 |
|
|
#if !defined(FB_BLIT_1) && (FB_DEPTH <= 16) |
46 |
gbeauche |
1.1 |
# error "Undefined 16-bit word blit function" |
47 |
|
|
#endif |
48 |
|
|
|
49 |
gbeauche |
1.4 |
#if !defined(FB_BLIT_2) |
50 |
gbeauche |
1.1 |
# error "Undefined 32-bit word blit function" |
51 |
|
|
#endif |
52 |
|
|
|
53 |
gbeauche |
1.5 |
#if !defined(FB_BLIT_4) |
54 |
|
|
# error "Undefined 64-bit word blit function" |
55 |
|
|
#endif |
56 |
|
|
|
57 |
gbeauche |
1.1 |
static void FB_FUNC_NAME(uint8 * dest, const uint8 * source, uint32 length) |
58 |
|
|
{ |
59 |
gbeauche |
1.5 |
#define DEREF_WORD_PTR(ptr, ofs) (((uint16 *)(ptr))[(ofs)]) |
60 |
gbeauche |
1.4 |
#define DEREF_LONG_PTR(ptr, ofs) (((uint32 *)(ptr))[(ofs)]) |
61 |
gbeauche |
1.5 |
#define DEREF_QUAD_PTR(ptr, ofs) (((uint64 *)(ptr))[(ofs)]) |
62 |
gbeauche |
1.3 |
|
63 |
gbeauche |
1.4 |
#ifndef UNALIGNED_PROFITABLE |
64 |
gbeauche |
1.1 |
#if FB_DEPTH <= 8 |
65 |
|
|
// Align source and dest to 16-bit word boundaries |
66 |
gbeauche |
1.4 |
if (((unsigned long) source) & 1) { |
67 |
|
|
*dest++ = *source++; |
68 |
gbeauche |
1.1 |
length -= 1; |
69 |
|
|
} |
70 |
|
|
#endif |
71 |
|
|
|
72 |
|
|
#if FB_DEPTH <= 16 |
73 |
|
|
// Align source and dest to 32-bit word boundaries |
74 |
|
|
if (((unsigned long) source) & 2) { |
75 |
gbeauche |
1.4 |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
76 |
|
|
dest += 2; source += 2; |
77 |
gbeauche |
1.1 |
length -= 2; |
78 |
|
|
} |
79 |
|
|
#endif |
80 |
gbeauche |
1.4 |
#endif |
81 |
gbeauche |
1.1 |
|
82 |
gbeauche |
1.5 |
// Blit 8-byte words |
83 |
|
|
if (length >= 8) { |
84 |
|
|
const int remainder = (length / 8) % 8; |
85 |
|
|
source += remainder * 8; |
86 |
|
|
dest += remainder * 8; |
87 |
gbeauche |
1.1 |
|
88 |
gbeauche |
1.5 |
int n = ((length / 8) + 7) / 8; |
89 |
gbeauche |
1.1 |
switch (remainder) { |
90 |
|
|
case 0: do { |
91 |
gbeauche |
1.5 |
dest += 64; source += 64; |
92 |
|
|
FB_BLIT_4(DEREF_QUAD_PTR(dest, -8), DEREF_QUAD_PTR(source, -8)); |
93 |
|
|
case 7: FB_BLIT_4(DEREF_QUAD_PTR(dest, -7), DEREF_QUAD_PTR(source, -7)); |
94 |
|
|
case 6: FB_BLIT_4(DEREF_QUAD_PTR(dest, -6), DEREF_QUAD_PTR(source, -6)); |
95 |
|
|
case 5: FB_BLIT_4(DEREF_QUAD_PTR(dest, -5), DEREF_QUAD_PTR(source, -5)); |
96 |
|
|
case 4: FB_BLIT_4(DEREF_QUAD_PTR(dest, -4), DEREF_QUAD_PTR(source, -4)); |
97 |
|
|
case 3: FB_BLIT_4(DEREF_QUAD_PTR(dest, -3), DEREF_QUAD_PTR(source, -3)); |
98 |
|
|
case 2: FB_BLIT_4(DEREF_QUAD_PTR(dest, -2), DEREF_QUAD_PTR(source, -2)); |
99 |
|
|
case 1: FB_BLIT_4(DEREF_QUAD_PTR(dest, -1), DEREF_QUAD_PTR(source, -1)); |
100 |
gbeauche |
1.1 |
} while (--n > 0); |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
|
104 |
gbeauche |
1.5 |
// There could be one long left to blit |
105 |
|
|
if (length & 4) { |
106 |
|
|
FB_BLIT_2(DEREF_LONG_PTR(dest, 0), DEREF_LONG_PTR(source, 0)); |
107 |
|
|
#if FB_DEPTH <= 16 |
108 |
|
|
dest += 4; |
109 |
|
|
source += 4; |
110 |
|
|
#endif |
111 |
|
|
} |
112 |
|
|
|
113 |
gbeauche |
1.1 |
#if FB_DEPTH <= 16 |
114 |
gbeauche |
1.4 |
// There could be one word left to blit |
115 |
gbeauche |
1.1 |
if (length & 2) { |
116 |
gbeauche |
1.4 |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
117 |
gbeauche |
1.3 |
#if FB_DEPTH <= 8 |
118 |
gbeauche |
1.4 |
dest += 2; |
119 |
|
|
source += 2; |
120 |
gbeauche |
1.3 |
#endif |
121 |
gbeauche |
1.2 |
} |
122 |
|
|
#endif |
123 |
|
|
|
124 |
|
|
#if FB_DEPTH <= 8 |
125 |
gbeauche |
1.4 |
// There could be one byte left to blit |
126 |
gbeauche |
1.3 |
if (length & 1) |
127 |
gbeauche |
1.4 |
*dest = *source; |
128 |
gbeauche |
1.1 |
#endif |
129 |
gbeauche |
1.4 |
|
130 |
|
|
#undef DEREF_LONG_PTR |
131 |
|
|
#undef DEREF_WORD_PTR |
132 |
gbeauche |
1.1 |
} |
133 |
|
|
|
134 |
|
|
#undef FB_FUNC_NAME |
135 |
|
|
|
136 |
|
|
#ifdef FB_BLIT_1 |
137 |
|
|
#undef FB_BLIT_1 |
138 |
|
|
#endif |
139 |
|
|
|
140 |
|
|
#ifdef FB_BLIT_2 |
141 |
|
|
#undef FB_BLIT_2 |
142 |
gbeauche |
1.5 |
#endif |
143 |
|
|
|
144 |
|
|
#ifdef FB_BLIT_4 |
145 |
|
|
#undef FB_BLIT_4 |
146 |
gbeauche |
1.1 |
#endif |
147 |
|
|
|
148 |
|
|
#ifdef FB_DEPTH |
149 |
|
|
#undef FB_DEPTH |
150 |
|
|
#endif |
151 |
gbeauche |
1.8 |
|
152 |
|
|
#endif /* DEFINE_VIDEO_BLITTERS */ |