ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.h
Revision: 1.2
Committed: 2000-09-23T06:51:46Z (24 years, 2 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.1: +8 -0 lines
Log Message:
- added a condition if (depth <= 8) before copying more than two bytes

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * video_blit.h - Video/graphics emulation, blitters
3     *
4     * Basilisk II (C) 1997-2000 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 FB_BLIT_1
22     # error "Undefined 16-bit word blit function"
23     #endif
24    
25     #ifndef FB_BLIT_2
26     # error "Undefined 32-bit word blit function"
27     #endif
28    
29     #ifndef FB_DEPTH
30     # error "Undefined screen depth"
31     #endif
32    
33     static void FB_FUNC_NAME(uint8 * dest, const uint8 * source, uint32 length)
34     {
35     #if FB_DEPTH <= 8
36     // Align source and dest to 16-bit word boundaries
37     if (FB_DEPTH <= 8 && ((unsigned long) source) & 1) {
38     *dest++ = *source++;
39     length -= 1;
40     }
41     #endif
42    
43     // source and dest are mutually aligned
44     uint16 * swp = ((uint16 *)source);
45     uint16 * dwp = ((uint16 *) dest );
46 gbeauche 1.2
47     #if FB_DEPTH <= 8
48     if (length >= 2) {
49     #endif
50 gbeauche 1.1
51     #if FB_DEPTH <= 16
52     // Align source and dest to 32-bit word boundaries
53     if (((unsigned long) source) & 2) {
54     const uint16 val = *swp++;
55     FB_BLIT_1(*dwp++, val);
56     length -= 2;
57     }
58     #endif
59    
60     // Blit 4-byte words
61     if (length >= 4) {
62     const int remainder = (length / 4) % 8;
63     uint32 * slp = (uint32 *)swp + remainder;
64     uint32 * dlp = (uint32 *)dwp + remainder;
65    
66     int n = ((length / 4) + 7) / 8;
67     switch (remainder) {
68     case 0: do {
69     slp += 8; dlp += 8;
70     FB_BLIT_2(dlp[-8], slp[-8]);
71     case 7: FB_BLIT_2(dlp[-7], slp[-7]);
72     case 6: FB_BLIT_2(dlp[-6], slp[-6]);
73     case 5: FB_BLIT_2(dlp[-5], slp[-5]);
74     case 4: FB_BLIT_2(dlp[-4], slp[-4]);
75     case 3: FB_BLIT_2(dlp[-3], slp[-3]);
76     case 2: FB_BLIT_2(dlp[-2], slp[-2]);
77     case 1: FB_BLIT_2(dlp[-1], slp[-1]);
78     } while (--n > 0);
79     }
80     }
81    
82     #if FB_DEPTH <= 16
83     // There might remain one word to blit
84     if (length & 2) {
85     uint16 * const s = (uint16 *)(((uint8 *)swp) + length - 2);
86     uint16 * const d = (uint16 *)(((uint8 *)dwp) + length - 2);
87     FB_BLIT_1(*d, *s);
88 gbeauche 1.2 }
89     #endif
90    
91     #if FB_DEPTH <= 8
92 gbeauche 1.1 }
93     #endif
94     }
95    
96     #undef FB_FUNC_NAME
97    
98     #ifdef FB_BLIT_1
99     #undef FB_BLIT_1
100     #endif
101    
102     #ifdef FB_BLIT_2
103     #undef FB_BLIT_2
104     #endif
105    
106     #ifdef FB_DEPTH
107     #undef FB_DEPTH
108     #endif