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 //****************************************************************
41 // 8-bit Horizontal Mirror
43 static inline void mirror8bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count)
56 if ( width & (v10 + width) )
57 *v8++ = *(&tex[mask] - (mask & v10));
59 *v8++ = tex[mask & v10];
62 while ( v10 != count );
70 static inline void wrap8bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count)
76 v7 = (uint32_t *)start;
83 *v7 = *(uint32_t *)&tex[4 * (mask & v9)];
87 while ( v9 != count );
88 v7 = (uint32_t *)((char *)v7 + line);
95 static inline void clamp8bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count)
123 void Mirror8bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)
125 if (mask == 0) return;
127 wxUint32 mask_width = (1 << mask);
128 wxUint32 mask_mask = (mask_width-1);
129 if (mask_width >= max_width) return;
130 int count = max_width - mask_width;
131 if (count <= 0) return;
132 int line_full = real_width;
133 int line = line_full - (count);
134 if (line < 0) return;
135 unsigned char * start = tex + (mask_width);
136 mirror8bS (tex, start, mask_width, height, mask_mask, line, line_full, count);
139 //****************************************************************
140 // 8-bit Horizontal Wrap (like mirror) ** UNTESTED **
143 void Wrap8bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)
145 if (mask == 0) return;
147 wxUint32 mask_width = (1 << mask);
148 wxUint32 mask_mask = (mask_width-1) >> 2;
149 if (mask_width >= max_width) return;
150 int count = (max_width - mask_width) >> 2;
151 if (count <= 0) return;
152 int line_full = real_width;
153 int line = line_full - (count << 2);
154 if (line < 0) return;
155 unsigned char * start = tex + (mask_width);
156 wrap8bS (tex, start, height, mask_mask, line, line_full, count);
159 //****************************************************************
160 // 8-bit Horizontal Clamp
163 void Clamp8bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height)
165 if (real_width <= width) return;
167 unsigned char * dest = tex + (width);
168 unsigned char * constant = dest-1;
169 int count = clamp_to - width;
171 int line_full = real_width;
173 clamp8bS (dest, constant, real_height, line, line_full, count);
176 //****************************************************************
177 // 8-bit Vertical Mirror
179 void Mirror8bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)
181 if (mask == 0) return;
183 wxUint32 mask_height = (1 << mask);
184 wxUint32 mask_mask = mask_height-1;
185 if (max_height <= mask_height) return;
186 int line_full = real_width;
188 unsigned char * dst = tex + mask_height * line_full;
190 for (wxUint32 y=mask_height; y<max_height; y++)
195 memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full);
200 memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);
207 //****************************************************************
208 // 8-bit Vertical Wrap
210 void Wrap8bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)
212 if (mask == 0) return;
214 wxUint32 mask_height = (1 << mask);
215 wxUint32 mask_mask = mask_height-1;
216 if (max_height <= mask_height) return;
217 int line_full = real_width;
219 unsigned char * dst = tex + mask_height * line_full;
221 for (wxUint32 y=mask_height; y<max_height; y++)
224 memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);
230 //****************************************************************
231 // 8-bit Vertical Clamp
233 void Clamp8bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to)
235 int line_full = real_width;
236 unsigned char * dst = tex + height * line_full;
237 unsigned char * const_line = dst - line_full;
239 for (wxUint32 y=height; y<clamp_to; y++)
241 memcpy ((void*)dst, (void*)const_line, line_full);