98e75f2d |
1 | /* |
2 | * Glide64 - Glide video plugin for Nintendo 64 emulators. |
3 | * Copyright (c) 2002 Dave2001 |
4 | * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski |
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 | * 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 | //**************************************************************** |
22 | // |
23 | // Glide64 - Glide Plugin for Nintendo 64 emulators |
24 | // Project started on December 29th, 2001 |
25 | // |
26 | // Authors: |
27 | // Dave2001, original author, founded the project in 2001, left it in 2002 |
28 | // Gugaman, joined the project in 2002, left it in 2002 |
29 | // Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002 |
30 | // Hiroshi 'KoolSmoky' Morii, joined the project in 2007 |
31 | // |
32 | //**************************************************************** |
33 | // |
34 | // To modify Glide64: |
35 | // * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me. |
36 | // * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all. |
37 | // |
38 | //**************************************************************** |
39 | // |
40 | // Created by Gonetz, 2007 |
41 | // |
42 | //**************************************************************** |
43 | |
44 | static inline void mirror32bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count) |
45 | { |
46 | uint32_t *v8; |
47 | int v9; |
48 | int v10; |
49 | |
50 | v8 = (uint32_t *)start; |
51 | v9 = height; |
52 | do |
53 | { |
54 | v10 = 0; |
55 | do |
56 | { |
57 | if ( width & (v10 + width) ) |
58 | { |
59 | *v8 = *(uint32_t *)(&tex[mask] - (mask & 4 * v10)); |
60 | ++v8; |
61 | } |
62 | else |
63 | { |
64 | *v8 = *(uint32_t *)&tex[mask & 4 * v10]; |
65 | ++v8; |
66 | } |
67 | ++v10; |
68 | } |
69 | while ( v10 != count ); |
70 | v8 = (uint32_t *)((char *)v8 + line); |
71 | tex += full; |
72 | --v9; |
73 | } |
74 | while ( v9 ); |
75 | } |
76 | |
77 | static inline void wrap32bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count) |
78 | { |
79 | uint32_t *v7; |
80 | int v8; |
81 | int v9; |
82 | |
83 | v7 = (uint32_t *)start; |
84 | v8 = height; |
85 | do |
86 | { |
87 | v9 = 0; |
88 | do |
89 | { |
90 | *v7 = *(uint32_t *)&tex[4 * (mask & v9)]; |
91 | ++v7; |
92 | ++v9; |
93 | } |
94 | while ( v9 != count ); |
95 | v7 = (uint32_t *)((char *)v7 + line); |
96 | tex += full; |
97 | --v8; |
98 | } |
99 | while ( v8 ); |
100 | } |
101 | |
102 | static inline void clamp32bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count) |
103 | { |
104 | uint32_t *v6; |
105 | uint32_t *v7; |
106 | int v8; |
107 | uint32_t v9; |
108 | int v10; |
109 | |
110 | v6 = (uint32_t *)constant; |
111 | v7 = (uint32_t *)tex; |
112 | v8 = height; |
113 | do |
114 | { |
115 | v9 = *v6; |
116 | v10 = count; |
117 | do |
118 | { |
119 | *v7 = v9; |
120 | ++v7; |
121 | --v10; |
122 | } |
123 | while ( v10 ); |
124 | v6 = (uint32_t *)((char *)v6 + full); |
125 | v7 = (uint32_t *)((char *)v7 + line); |
126 | --v8; |
127 | } |
128 | while ( v8 ); |
129 | } |
130 | |
131 | //**************************************************************** |
132 | // 32-bit Horizontal Mirror |
133 | |
134 | void Mirror32bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height) |
135 | { |
136 | if (mask == 0) return; |
137 | |
138 | wxUint32 mask_width = (1 << mask); |
139 | wxUint32 mask_mask = (mask_width-1) << 2; |
140 | if (mask_width >= max_width) return; |
141 | int count = max_width - mask_width; |
142 | if (count <= 0) return; |
143 | int line_full = real_width << 2; |
144 | int line = line_full - (count << 2); |
145 | if (line < 0) return; |
146 | unsigned char * start = tex + (mask_width << 2); |
147 | mirror32bS (tex, start, mask_width, height, mask_mask, line, line_full, count); |
148 | } |
149 | |
150 | //**************************************************************** |
151 | // 32-bit Horizontal Wrap |
152 | |
153 | void Wrap32bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height) |
154 | { |
155 | if (mask == 0) return; |
156 | |
157 | wxUint32 mask_width = (1 << mask); |
158 | wxUint32 mask_mask = (mask_width-1); |
159 | if (mask_width >= max_width) return; |
160 | int count = (max_width - mask_width); |
161 | if (count <= 0) return; |
162 | int line_full = real_width << 2; |
163 | int line = line_full - (count << 2); |
164 | if (line < 0) return; |
165 | unsigned char * start = tex + (mask_width << 2); |
166 | wrap32bS (tex, start, height, mask_mask, line, line_full, count); |
167 | } |
168 | |
169 | //**************************************************************** |
170 | // 32-bit Horizontal Clamp |
171 | |
172 | void Clamp32bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height) |
173 | { |
174 | if (real_width <= width) return; |
175 | |
176 | unsigned char *dest = tex + (width << 2); |
177 | unsigned char *constant = dest-4; |
178 | |
179 | int count = clamp_to - width; |
180 | |
181 | int line_full = real_width << 2; |
182 | int line = width << 2; |
183 | clamp32bS (dest, constant, real_height, line, line_full, count); |
184 | } |
185 | |
186 | //**************************************************************** |
187 | // 32-bit Vertical Mirror |
188 | |
189 | void Mirror32bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width) |
190 | { |
191 | if (mask == 0) return; |
192 | |
193 | wxUint32 mask_height = (1 << mask); |
194 | wxUint32 mask_mask = mask_height-1; |
195 | if (max_height <= mask_height) return; |
196 | int line_full = real_width << 2; |
197 | |
198 | unsigned char *dst = tex + mask_height * line_full; |
199 | |
200 | for (wxUint32 y=mask_height; y<max_height; y++) |
201 | { |
202 | if (y & mask_height) |
203 | { |
204 | // mirrored |
205 | memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full); |
206 | } |
207 | else |
208 | { |
209 | // not mirrored |
210 | memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full); |
211 | } |
212 | |
213 | dst += line_full; |
214 | } |
215 | } |
216 | |
217 | //**************************************************************** |
218 | // 32-bit Vertical Wrap |
219 | |
220 | void Wrap32bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width) |
221 | { |
222 | if (mask == 0) return; |
223 | |
224 | wxUint32 mask_height = (1 << mask); |
225 | wxUint32 mask_mask = mask_height-1; |
226 | if (max_height <= mask_height) return; |
227 | int line_full = real_width << 2; |
228 | |
229 | unsigned char *dst = tex + mask_height * line_full; |
230 | |
231 | for (wxUint32 y=mask_height; y<max_height; y++) |
232 | { |
233 | // not mirrored |
234 | memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * (line_full>>2)), (line_full>>2)); |
235 | |
236 | dst += line_full; |
237 | } |
238 | } |
239 | |
240 | //**************************************************************** |
241 | // 32-bit Vertical Clamp |
242 | |
243 | void Clamp32bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to) |
244 | { |
245 | int line_full = real_width << 2; |
246 | unsigned char *dst = tex + height * line_full; |
247 | unsigned char *const_line = dst - line_full; |
248 | |
249 | for (wxUint32 y=height; y<clamp_to; y++) |
250 | { |
251 | memcpy ((void*)dst, (void*)const_line, line_full); |
252 | dst += line_full; |
253 | } |
254 | } |