ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.h
Revision: 1.9
Committed: 2004-06-24T15:19:56Z (20 years, 5 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.8: +36 -0 lines
Log Message:
Move VideoMode wrappers to video_blit.h.

File Contents

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