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 |
gbeauche |
1.9 |
// Prototypes |
34 |
gbeauche |
1.8 |
extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); |
35 |
|
|
extern bool Screen_blitter_init(VisualFormat const & visual_format, bool native_byte_order, int mac_depth); |
36 |
|
|
extern uint32 ExpandMap[256]; |
37 |
|
|
|
38 |
gbeauche |
1.9 |
// Glue for SheepShaver and BasiliskII |
39 |
|
|
#ifdef SHEEPSHAVER |
40 |
|
|
enum { |
41 |
|
|
VIDEO_DEPTH_1BIT = APPLE_1_BIT, |
42 |
|
|
VIDEO_DEPTH_2BIT = APPLE_2_BIT, |
43 |
|
|
VIDEO_DEPTH_4BIT = APPLE_4_BIT, |
44 |
|
|
VIDEO_DEPTH_8BIT = APPLE_8_BIT, |
45 |
|
|
VIDEO_DEPTH_16BIT = APPLE_16_BIT, |
46 |
|
|
VIDEO_DEPTH_32BIT = APPLE_32_BIT |
47 |
|
|
}; |
48 |
|
|
#define VIDEO_MODE VideoInfo |
49 |
|
|
#define VIDEO_MODE_INIT VideoInfo const & mode = VModes[cur_mode] |
50 |
gbeauche |
1.10 |
#define VIDEO_MODE_INIT_MONITOR VIDEO_MODE_INIT |
51 |
gbeauche |
1.9 |
#define VIDEO_MODE_ROW_BYTES mode.viRowBytes |
52 |
|
|
#define VIDEO_MODE_X mode.viXsize |
53 |
|
|
#define VIDEO_MODE_Y mode.viYsize |
54 |
|
|
#define VIDEO_MODE_RESOLUTION mode.viAppleID |
55 |
|
|
#define VIDEO_MODE_DEPTH mode.viAppleMode |
56 |
|
|
#else |
57 |
|
|
enum { |
58 |
|
|
VIDEO_DEPTH_1BIT = VDEPTH_1BIT, |
59 |
|
|
VIDEO_DEPTH_2BIT = VDEPTH_2BIT, |
60 |
|
|
VIDEO_DEPTH_4BIT = VDEPTH_4BIT, |
61 |
|
|
VIDEO_DEPTH_8BIT = VDEPTH_8BIT, |
62 |
|
|
VIDEO_DEPTH_16BIT = VDEPTH_16BIT, |
63 |
|
|
VIDEO_DEPTH_32BIT = VDEPTH_32BIT |
64 |
|
|
}; |
65 |
|
|
#define VIDEO_MODE video_mode |
66 |
|
|
#define VIDEO_MODE_INIT video_mode const & mode = drv->mode |
67 |
gbeauche |
1.10 |
#define VIDEO_MODE_INIT_MONITOR video_mode const & mode = monitor.get_current_mode() |
68 |
gbeauche |
1.9 |
#define VIDEO_MODE_ROW_BYTES mode.bytes_per_row |
69 |
|
|
#define VIDEO_MODE_X mode.x |
70 |
|
|
#define VIDEO_MODE_Y mode.y |
71 |
|
|
#define VIDEO_MODE_RESOLUTION mode.resolution_id |
72 |
|
|
#define VIDEO_MODE_DEPTH (int)mode.depth |
73 |
|
|
#endif |
74 |
|
|
|
75 |
gbeauche |
1.8 |
#endif /* VIDEO_BLIT_H */ |
76 |
|
|
|
77 |
|
|
#else |
78 |
|
|
|
79 |
gbeauche |
1.4 |
#ifndef FB_DEPTH |
80 |
|
|
# error "Undefined screen depth" |
81 |
|
|
#endif |
82 |
|
|
|
83 |
|
|
#if !defined(FB_BLIT_1) && (FB_DEPTH <= 16) |
84 |
gbeauche |
1.1 |
# error "Undefined 16-bit word blit function" |
85 |
|
|
#endif |
86 |
|
|
|
87 |
gbeauche |
1.4 |
#if !defined(FB_BLIT_2) |
88 |
gbeauche |
1.1 |
# error "Undefined 32-bit word blit function" |
89 |
|
|
#endif |
90 |
|
|
|
91 |
gbeauche |
1.5 |
#if !defined(FB_BLIT_4) |
92 |
|
|
# error "Undefined 64-bit word blit function" |
93 |
|
|
#endif |
94 |
|
|
|
95 |
gbeauche |
1.1 |
static void FB_FUNC_NAME(uint8 * dest, const uint8 * source, uint32 length) |
96 |
|
|
{ |
97 |
gbeauche |
1.5 |
#define DEREF_WORD_PTR(ptr, ofs) (((uint16 *)(ptr))[(ofs)]) |
98 |
gbeauche |
1.4 |
#define DEREF_LONG_PTR(ptr, ofs) (((uint32 *)(ptr))[(ofs)]) |
99 |
gbeauche |
1.5 |
#define DEREF_QUAD_PTR(ptr, ofs) (((uint64 *)(ptr))[(ofs)]) |
100 |
gbeauche |
1.3 |
|
101 |
gbeauche |
1.4 |
#ifndef UNALIGNED_PROFITABLE |
102 |
gbeauche |
1.1 |
#if FB_DEPTH <= 8 |
103 |
|
|
// Align source and dest to 16-bit word boundaries |
104 |
gbeauche |
1.4 |
if (((unsigned long) source) & 1) { |
105 |
|
|
*dest++ = *source++; |
106 |
gbeauche |
1.1 |
length -= 1; |
107 |
|
|
} |
108 |
|
|
#endif |
109 |
|
|
|
110 |
|
|
#if FB_DEPTH <= 16 |
111 |
|
|
// Align source and dest to 32-bit word boundaries |
112 |
|
|
if (((unsigned long) source) & 2) { |
113 |
gbeauche |
1.4 |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
114 |
|
|
dest += 2; source += 2; |
115 |
gbeauche |
1.1 |
length -= 2; |
116 |
|
|
} |
117 |
|
|
#endif |
118 |
gbeauche |
1.4 |
#endif |
119 |
gbeauche |
1.1 |
|
120 |
gbeauche |
1.5 |
// Blit 8-byte words |
121 |
|
|
if (length >= 8) { |
122 |
|
|
const int remainder = (length / 8) % 8; |
123 |
|
|
source += remainder * 8; |
124 |
|
|
dest += remainder * 8; |
125 |
gbeauche |
1.1 |
|
126 |
gbeauche |
1.5 |
int n = ((length / 8) + 7) / 8; |
127 |
gbeauche |
1.1 |
switch (remainder) { |
128 |
|
|
case 0: do { |
129 |
gbeauche |
1.5 |
dest += 64; source += 64; |
130 |
|
|
FB_BLIT_4(DEREF_QUAD_PTR(dest, -8), DEREF_QUAD_PTR(source, -8)); |
131 |
|
|
case 7: FB_BLIT_4(DEREF_QUAD_PTR(dest, -7), DEREF_QUAD_PTR(source, -7)); |
132 |
|
|
case 6: FB_BLIT_4(DEREF_QUAD_PTR(dest, -6), DEREF_QUAD_PTR(source, -6)); |
133 |
|
|
case 5: FB_BLIT_4(DEREF_QUAD_PTR(dest, -5), DEREF_QUAD_PTR(source, -5)); |
134 |
|
|
case 4: FB_BLIT_4(DEREF_QUAD_PTR(dest, -4), DEREF_QUAD_PTR(source, -4)); |
135 |
|
|
case 3: FB_BLIT_4(DEREF_QUAD_PTR(dest, -3), DEREF_QUAD_PTR(source, -3)); |
136 |
|
|
case 2: FB_BLIT_4(DEREF_QUAD_PTR(dest, -2), DEREF_QUAD_PTR(source, -2)); |
137 |
|
|
case 1: FB_BLIT_4(DEREF_QUAD_PTR(dest, -1), DEREF_QUAD_PTR(source, -1)); |
138 |
gbeauche |
1.1 |
} while (--n > 0); |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
142 |
gbeauche |
1.5 |
// There could be one long left to blit |
143 |
|
|
if (length & 4) { |
144 |
|
|
FB_BLIT_2(DEREF_LONG_PTR(dest, 0), DEREF_LONG_PTR(source, 0)); |
145 |
|
|
#if FB_DEPTH <= 16 |
146 |
|
|
dest += 4; |
147 |
|
|
source += 4; |
148 |
|
|
#endif |
149 |
|
|
} |
150 |
|
|
|
151 |
gbeauche |
1.1 |
#if FB_DEPTH <= 16 |
152 |
gbeauche |
1.4 |
// There could be one word left to blit |
153 |
gbeauche |
1.1 |
if (length & 2) { |
154 |
gbeauche |
1.4 |
FB_BLIT_1(DEREF_WORD_PTR(dest, 0), DEREF_WORD_PTR(source, 0)); |
155 |
gbeauche |
1.3 |
#if FB_DEPTH <= 8 |
156 |
gbeauche |
1.4 |
dest += 2; |
157 |
|
|
source += 2; |
158 |
gbeauche |
1.3 |
#endif |
159 |
gbeauche |
1.2 |
} |
160 |
|
|
#endif |
161 |
|
|
|
162 |
|
|
#if FB_DEPTH <= 8 |
163 |
gbeauche |
1.4 |
// There could be one byte left to blit |
164 |
gbeauche |
1.3 |
if (length & 1) |
165 |
gbeauche |
1.4 |
*dest = *source; |
166 |
gbeauche |
1.1 |
#endif |
167 |
gbeauche |
1.4 |
|
168 |
|
|
#undef DEREF_LONG_PTR |
169 |
|
|
#undef DEREF_WORD_PTR |
170 |
gbeauche |
1.1 |
} |
171 |
|
|
|
172 |
|
|
#undef FB_FUNC_NAME |
173 |
|
|
|
174 |
|
|
#ifdef FB_BLIT_1 |
175 |
|
|
#undef FB_BLIT_1 |
176 |
|
|
#endif |
177 |
|
|
|
178 |
|
|
#ifdef FB_BLIT_2 |
179 |
|
|
#undef FB_BLIT_2 |
180 |
gbeauche |
1.5 |
#endif |
181 |
|
|
|
182 |
|
|
#ifdef FB_BLIT_4 |
183 |
|
|
#undef FB_BLIT_4 |
184 |
gbeauche |
1.1 |
#endif |
185 |
|
|
|
186 |
|
|
#ifdef FB_DEPTH |
187 |
|
|
#undef FB_DEPTH |
188 |
|
|
#endif |
189 |
gbeauche |
1.8 |
|
190 |
|
|
#endif /* DEFINE_VIDEO_BLITTERS */ |