Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/MiClWr32b.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators23// Project started on December 29th, 200124//25// Authors:26// Dave2001, original author, founded the project in 2001, left it in 200227// Gugaman, joined the project in 2002, left it in 200228// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 200229// Hiroshi 'KoolSmoky' Morii, joined the project in 200730//31//****************************************************************32//33// To modify Glide64:34// * 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.35// * 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.36//37//****************************************************************38//39// Created by Gonetz, 200740//41//****************************************************************4243static inline void mirror32bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count)44{45uint32_t *v8;46int v9;47int v10;4849v8 = (uint32_t *)start;50v9 = height;51do52{53v10 = 0;54do55{56if ( width & (v10 + width) )57{58*v8 = *(uint32_t *)(&tex[mask] - (mask & 4 * v10));59++v8;60}61else62{63*v8 = *(uint32_t *)&tex[mask & 4 * v10];64++v8;65}66++v10;67}68while ( v10 != count );69v8 = (uint32_t *)((char *)v8 + line);70tex += full;71--v9;72}73while ( v9 );74}7576static inline void wrap32bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count)77{78uint32_t *v7;79int v8;80int v9;8182v7 = (uint32_t *)start;83v8 = height;84do85{86v9 = 0;87do88{89*v7 = *(uint32_t *)&tex[4 * (mask & v9)];90++v7;91++v9;92}93while ( v9 != count );94v7 = (uint32_t *)((char *)v7 + line);95tex += full;96--v8;97}98while ( v8 );99}100101static inline void clamp32bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count)102{103uint32_t *v6;104uint32_t *v7;105int v8;106uint32_t v9;107int v10;108109v6 = (uint32_t *)constant;110v7 = (uint32_t *)tex;111v8 = height;112do113{114v9 = *v6;115v10 = count;116do117{118*v7 = v9;119++v7;120--v10;121}122while ( v10 );123v6 = (uint32_t *)((char *)v6 + full);124v7 = (uint32_t *)((char *)v7 + line);125--v8;126}127while ( v8 );128}129130//****************************************************************131// 32-bit Horizontal Mirror132133void Mirror32bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)134{135if (mask == 0) return;136137wxUint32 mask_width = (1 << mask);138wxUint32 mask_mask = (mask_width-1) << 2;139if (mask_width >= max_width) return;140int count = max_width - mask_width;141if (count <= 0) return;142int line_full = real_width << 2;143int line = line_full - (count << 2);144if (line < 0) return;145unsigned char * start = tex + (mask_width << 2);146mirror32bS (tex, start, mask_width, height, mask_mask, line, line_full, count);147}148149//****************************************************************150// 32-bit Horizontal Wrap151152void Wrap32bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)153{154if (mask == 0) return;155156wxUint32 mask_width = (1 << mask);157wxUint32 mask_mask = (mask_width-1);158if (mask_width >= max_width) return;159int count = (max_width - mask_width);160if (count <= 0) return;161int line_full = real_width << 2;162int line = line_full - (count << 2);163if (line < 0) return;164unsigned char * start = tex + (mask_width << 2);165wrap32bS (tex, start, height, mask_mask, line, line_full, count);166}167168//****************************************************************169// 32-bit Horizontal Clamp170171void Clamp32bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height)172{173if (real_width <= width) return;174175unsigned char *dest = tex + (width << 2);176unsigned char *constant = dest-4;177178int count = clamp_to - width;179180int line_full = real_width << 2;181int line = width << 2;182clamp32bS (dest, constant, real_height, line, line_full, count);183}184185//****************************************************************186// 32-bit Vertical Mirror187188void Mirror32bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)189{190if (mask == 0) return;191192wxUint32 mask_height = (1 << mask);193wxUint32 mask_mask = mask_height-1;194if (max_height <= mask_height) return;195int line_full = real_width << 2;196197unsigned char *dst = tex + mask_height * line_full;198199for (wxUint32 y=mask_height; y<max_height; y++)200{201if (y & mask_height)202{203// mirrored204memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full);205}206else207{208// not mirrored209memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);210}211212dst += line_full;213}214}215216//****************************************************************217// 32-bit Vertical Wrap218219void Wrap32bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)220{221if (mask == 0) return;222223wxUint32 mask_height = (1 << mask);224wxUint32 mask_mask = mask_height-1;225if (max_height <= mask_height) return;226int line_full = real_width << 2;227228unsigned char *dst = tex + mask_height * line_full;229230for (wxUint32 y=mask_height; y<max_height; y++)231{232// not mirrored233memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * (line_full>>2)), (line_full>>2));234235dst += line_full;236}237}238239//****************************************************************240// 32-bit Vertical Clamp241242void Clamp32bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to)243{244int line_full = real_width << 2;245unsigned char *dst = tex + height * line_full;246unsigned char *const_line = dst - line_full;247248for (wxUint32 y=height; y<clamp_to; y++)249{250memcpy ((void*)dst, (void*)const_line, line_full);251dst += line_full;252}253}254255256