Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/TexLoad16b.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 load16bRGBA(uint8_t *src, uint8_t *dst, int wid_64, int height, int line, int ext)40{41uint32_t *v6;42uint32_t *v7;43int v8;44int v9;45uint32_t v10;46uint32_t v11;47uint32_t *v12;48uint32_t *v13;49int v14;50uint32_t v15;51uint32_t v16;52int v17;53int v18;5455v6 = (uint32_t *)src;56v7 = (uint32_t *)dst;57v8 = height;58do59{60v17 = v8;61v9 = wid_64;62do63{64v10 = bswap32(*v6);65v11 = bswap32(v6[1]);66ALOWORD(v10) = __ROR__((uint16_t)v10, 1);67ALOWORD(v11) = __ROR__((uint16_t)v11, 1);68v10 = __ROR__(v10, 16);69v11 = __ROR__(v11, 16);70ALOWORD(v10) = __ROR__((uint16_t)v10, 1);71ALOWORD(v11) = __ROR__((uint16_t)v11, 1);72*v7 = v10;73v7[1] = v11;74v6 += 2;75v7 += 2;76--v9;77}78while ( v9 );79if ( v17 == 1 )80break;81v18 = v17 - 1;82v12 = (uint32_t *)&src[(line + (uintptr_t)v6 - (uintptr_t)src) & 0xFFF];83v13 = (uint32_t *)((char *)v7 + ext);84v14 = wid_64;85do86{87v15 = bswap32(v12[1]);88v16 = bswap32(*v12);89ALOWORD(v15) = __ROR__((uint16_t)v15, 1);90ALOWORD(v16) = __ROR__((uint16_t)v16, 1);91v15 = __ROR__(v15, 16);92v16 = __ROR__(v16, 16);93ALOWORD(v15) = __ROR__((uint16_t)v15, 1);94ALOWORD(v16) = __ROR__((uint16_t)v16, 1);95*v13 = v15;96v13[1] = v16;97v12 += 2;98v13 += 2;99--v14;100}101while ( v14 );102v6 = (uint32_t *)&src[(line + (uintptr_t)v12 - (uintptr_t)src) & 0xFFF];103v7 = (uint32_t *)((char *)v13 + ext);104v8 = v18 - 1;105}106while ( v18 != 1 );107}108109static inline void load16bIA(uint8_t *src, uint8_t *dst, int wid_64, int height, int line, int ext)110{111uint32_t *v6;112uint32_t *v7;113int v8;114int v9;115uint32_t v10;116uint32_t *v11;117uint32_t *v12;118int v13;119uint32_t v14;120int v15;121int v16;122123v6 = (uint32_t *)src;124v7 = (uint32_t *)dst;125v8 = height;126do127{128v15 = v8;129v9 = wid_64;130do131{132v10 = v6[1];133*v7 = *v6;134v7[1] = v10;135v6 += 2;136v7 += 2;137--v9;138}139while ( v9 );140if ( v15 == 1 )141break;142v16 = v15 - 1;143v11 = (uint32_t *)((char *)v6 + line);144v12 = (uint32_t *)((char *)v7 + ext);145v13 = wid_64;146do147{148v14 = *v11;149*v12 = v11[1];150v12[1] = v14;151v11 += 2;152v12 += 2;153--v13;154}155while ( v13 );156v6 = (uint32_t *)((char *)v11 + line);157v7 = (uint32_t *)((char *)v12 + ext);158v8 = v16 - 1;159}160while ( v16 != 1 );161}162163164//****************************************************************165// Size: 2, Format: 0166//167168wxUint32 Load16bRGBA (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int line, int real_width, int tile)169{170if (wid_64 < 1) wid_64 = 1;171if (height < 1) height = 1;172int ext = (real_width - (wid_64 << 2)) << 1;173174load16bRGBA((uint8_t *)src, (uint8_t *)dst, wid_64, height, line, ext);175176return (1 << 16) | GR_TEXFMT_ARGB_1555;177}178179//****************************************************************180// Size: 2, Format: 3181//182// ** by Gugaman/Dave2001 **183184wxUint32 Load16bIA (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int line, int real_width, int tile)185{186if (wid_64 < 1) wid_64 = 1;187if (height < 1) height = 1;188int ext = (real_width - (wid_64 << 2)) << 1;189190load16bIA((uint8_t *)src, (uint8_t *)dst, wid_64, height, line, ext);191192return (1 << 16) | GR_TEXFMT_ALPHA_INTENSITY_88;193}194195//****************************************************************196// Size: 2, Format: 1197//198199wxUint16 yuv_to_rgb565(wxUint8 y, wxUint8 u, wxUint8 v)200{201//*202float r = y + (1.370705f * (v-128));203float g = y - (0.698001f * (v-128)) - (0.337633f * (u-128));204float b = y + (1.732446f * (u-128));205r *= 0.125f;206g *= 0.25f;207b *= 0.125f;208//clipping the result209if (r > 31) r = 31;210if (g > 63) g = 63;211if (b > 31) b = 31;212if (r < 0) r = 0;213if (g < 0) g = 0;214if (b < 0) b = 0;215wxUint16 c = (wxUint16)(((wxUint16)(r) << 11) |216((wxUint16)(g) << 5) |217(wxUint16)(b) );218return c;219//*/220/*221const wxUint32 c = y - 16;222const wxUint32 d = u - 128;223const wxUint32 e = v - 128;224225wxUint32 r = (298 * c + 409 * e + 128) & 0xf800;226wxUint32 g = ((298 * c - 100 * d - 208 * e + 128) >> 5) & 0x7e0;227wxUint32 b = ((298 * c + 516 * d + 128) >> 11) & 0x1f;228229WORD texel = (WORD)(r | g | b);230231return texel;232*/233}234235//****************************************************************236// Size: 2, Format: 1237//238239wxUint32 Load16bYUV (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int line, int real_width, int tile)240{241wxUint32 * mb = (wxUint32*)(gfx.RDRAM+rdp.addr[rdp.tiles[tile].t_mem]); //pointer to the macro block242wxUint16 * tex = (wxUint16*)dst;243wxUint16 i;244for (i = 0; i < 128; i++)245{246wxUint32 t = mb[i]; //each wxUint32 contains 2 pixels247wxUint8 y1 = (wxUint8)t&0xFF;248wxUint8 v = (wxUint8)(t>>8)&0xFF;249wxUint8 y0 = (wxUint8)(t>>16)&0xFF;250wxUint8 u = (wxUint8)(t>>24)&0xFF;251wxUint16 c = yuv_to_rgb565(y0, u, v);252*(tex++) = c;253c = yuv_to_rgb565(y1, u, v);254*(tex++) = c;255}256return (1 << 16) | GR_TEXFMT_RGB_565;257}258259260