ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.h
Revision: 1.15
Committed: 2008-01-01T09:40:33Z (16 years, 10 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +1 -1 lines
Log Message:
Happy New Year!

File Contents

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