Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/MiClWr16b.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//****************************************************************3839static inline void mirror16bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count)40{41uint16_t *v8;42int v9;43int v10;4445v8 = (uint16_t *)start;46v9 = height;47do48{49v10 = 0;50do51{52if ( width & (v10 + width) )53{54*v8 = *(uint16_t *)(&tex[mask] - (mask & 2 * v10));55++v8;56}57else58{59*v8 = *(uint16_t *)&tex[mask & 2 * v10];60++v8;61}62++v10;63}64while ( v10 != count );65v8 = (uint16_t *)((char *)v8 + line);66tex += full;67--v9;68}69while ( v9 );70}7172static inline void wrap16bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count)73{74uint32_t *v7;75int v8;76int v9;7778v7 = (uint32_t *)start;79v8 = height;80do81{82v9 = 0;83do84{85*v7 = *(uint32_t *)&tex[4 * (mask & v9)];86++v7;87++v9;88}89while ( v9 != count );90v7 = (uint32_t *)((char *)v7 + line);91tex += full;92--v8;93}94while ( v8 );95}9697static inline void clamp16bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count)98{99uint16_t *v6;100uint16_t *v7;101int v8;102uint16_t v9;103int v10;104105v6 = (uint16_t *)constant;106v7 = (uint16_t *)tex;107v8 = height;108do109{110v9 = *v6;111v10 = count;112do113{114*v7 = v9;115++v7;116--v10;117}118while ( v10 );119v6 = (uint16_t *)((char *)v6 + full);120v7 = (uint16_t *)((char *)v7 + line);121--v8;122}123while ( v8 );124}125126//****************************************************************127// 16-bit Horizontal Mirror128#include <stdint.h>129#include <string.h>130typedef uint32_t wxUint32;131132void Mirror16bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)133{134if (mask == 0) return;135136wxUint32 mask_width = (1 << mask);137wxUint32 mask_mask = (mask_width-1) << 1;138if (mask_width >= max_width) return;139int count = max_width - mask_width;140if (count <= 0) return;141int line_full = real_width << 1;142int line = line_full - (count << 1);143if (line < 0) return;144unsigned char *start = tex + (mask_width << 1);145mirror16bS (tex, start, mask_width, height, mask_mask, line, line_full, count);146}147148//****************************************************************149// 16-bit Horizontal Wrap (like mirror)150151void Wrap16bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)152{153if (mask == 0) return;154155wxUint32 mask_width = (1 << mask);156wxUint32 mask_mask = (mask_width-1) >> 1;157if (mask_width >= max_width) return;158int count = (max_width - mask_width) >> 1;159if (count <= 0) return;160int line_full = real_width << 1;161int line = line_full - (count << 2);162if (line < 0) return;163unsigned char * start = tex + (mask_width << 1);164wrap16bS (tex, start, height, mask_mask, line, line_full, count);165}166167//****************************************************************168// 16-bit Horizontal Clamp169170void Clamp16bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height)171{172if (real_width <= width) return;173174unsigned char * dest = tex + (width << 1);175unsigned char * constant = dest-2;176int count = clamp_to - width;177178int line_full = real_width << 1;179int line = width << 1;180181clamp16bS (dest, constant, real_height, line, line_full, count);182}183184//****************************************************************185// 16-bit Vertical Mirror186187void Mirror16bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)188{189if (mask == 0) return;190191wxUint32 mask_height = (1 << mask);192wxUint32 mask_mask = mask_height-1;193if (max_height <= mask_height) return;194int line_full = real_width << 1;195196unsigned char * dst = tex + mask_height * line_full;197198for (wxUint32 y=mask_height; y<max_height; y++)199{200if (y & mask_height)201{202// mirrored203memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full);204}205else206{207// not mirrored208memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);209}210211dst += line_full;212}213}214215//****************************************************************216// 16-bit Vertical Wrap217218void Wrap16bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)219{220if (mask == 0) return;221222wxUint32 mask_height = (1 << mask);223wxUint32 mask_mask = mask_height-1;224if (max_height <= mask_height) return;225int line_full = real_width << 1;226227unsigned char * dst = tex + mask_height * line_full;228229for (wxUint32 y=mask_height; y<max_height; y++)230{231// not mirrored232memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);233234dst += line_full;235}236}237238//****************************************************************239// 16-bit Vertical Clamp240241void Clamp16bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to)242{243int line_full = real_width << 1;244unsigned char * dst = tex + height * line_full;245unsigned char * const_line = dst - line_full;246247for (wxUint32 y=height; y<clamp_to; y++)248{249memcpy ((void*)dst, (void*)const_line, line_full);250dst += line_full;251}252}253254255