2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
4 * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
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
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.
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
21 //****************************************************************
23 // Glide64 - Glide Plugin for Nintendo 64 emulators
24 // Project started on December 29th, 2001
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
32 //****************************************************************
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.
38 //****************************************************************
40 // Created by Gonetz, 2007
42 //****************************************************************
44 static inline void mirror32bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count)
50 v8 = (uint32_t *)start;
57 if ( width & (v10 + width) )
59 *v8 = *(uint32_t *)(&tex[mask] - (mask & 4 * v10));
64 *v8 = *(uint32_t *)&tex[mask & 4 * v10];
69 while ( v10 != count );
70 v8 = (uint32_t *)((char *)v8 + line);
77 static inline void wrap32bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count)
83 v7 = (uint32_t *)start;
90 *v7 = *(uint32_t *)&tex[4 * (mask & v9)];
94 while ( v9 != count );
95 v7 = (uint32_t *)((char *)v7 + line);
102 static inline void clamp32bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count)
110 v6 = (uint32_t *)constant;
111 v7 = (uint32_t *)tex;
124 v6 = (uint32_t *)((char *)v6 + full);
125 v7 = (uint32_t *)((char *)v7 + line);
131 //****************************************************************
132 // 32-bit Horizontal Mirror
134 void Mirror32bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)
136 if (mask == 0) return;
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);
150 //****************************************************************
151 // 32-bit Horizontal Wrap
153 void Wrap32bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)
155 if (mask == 0) return;
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);
169 //****************************************************************
170 // 32-bit Horizontal Clamp
172 void Clamp32bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height)
174 if (real_width <= width) return;
176 unsigned char *dest = tex + (width << 2);
177 unsigned char *constant = dest-4;
179 int count = clamp_to - width;
181 int line_full = real_width << 2;
182 int line = width << 2;
183 clamp32bS (dest, constant, real_height, line, line_full, count);
186 //****************************************************************
187 // 32-bit Vertical Mirror
189 void Mirror32bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)
191 if (mask == 0) return;
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;
198 unsigned char *dst = tex + mask_height * line_full;
200 for (wxUint32 y=mask_height; y<max_height; y++)
205 memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full);
210 memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);
217 //****************************************************************
218 // 32-bit Vertical Wrap
220 void Wrap32bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)
222 if (mask == 0) return;
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;
229 unsigned char *dst = tex + mask_height * line_full;
231 for (wxUint32 y=mask_height; y<max_height; y++)
234 memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * (line_full>>2)), (line_full>>2));
240 //****************************************************************
241 // 32-bit Vertical Clamp
243 void Clamp32bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to)
245 int line_full = real_width << 2;
246 unsigned char *dst = tex + height * line_full;
247 unsigned char *const_line = dst - line_full;
249 for (wxUint32 y=height; y<clamp_to; y++)
251 memcpy ((void*)dst, (void*)const_line, line_full);