Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/TexLoad32b.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#include "Gfx_1.3.h"3940//****************************************************************41// Size: 2, Format: 042//43// Load 32bit RGBA texture44// Based on sources of angrylion's software plugin.45//46wxUint32 Load32bRGBA (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int line, int real_width, int tile)47{48if (height < 1) height = 1;49const wxUint16 *tmem16 = (wxUint16*)rdp.tmem;50const wxUint32 tbase = (src - (wxUIntPtr)rdp.tmem) >> 1;51const wxUint32 width = max(1, wid_64 << 1);52const int ext = real_width - width;53line = width + (line>>2);54wxUint32 s, t, c;55wxUint32 * tex = (wxUint32*)dst;56wxUint16 rg, ba;57for (t = 0; t < (wxUint32)height; t++)58{59wxUint32 tline = tbase + line * t;60wxUint32 xorval = (t & 1) ? 3 : 1;61for (s = 0; s < width; s++)62{63wxUint32 taddr = ((tline + s) ^ xorval) & 0x3ff;64rg = tmem16[taddr];65ba = tmem16[taddr|0x400];66c = ((ba&0xFF)<<24) | (rg << 8) | (ba>>8);67*tex++ = c;68}69tex += ext;70}71int id = tile - rdp.cur_tile;72wxUint32 mod = (id == 0) ? cmb.mod_0 : cmb.mod_1;73if (mod || !voodoo.sup_32bit_tex)74{75//convert to ARGB_444476const wxUint32 tex_size = real_width * height;77tex = (wxUint32 *)dst;78wxUint16 *tex16 = (wxUint16*)dst;79wxUint16 a, r, g, b;80for (wxUint32 i = 0; i < tex_size; i++) {81c = tex[i];82a = (c >> 28) & 0xF;83r = (c >> 20) & 0xF;84g = (c >> 12) & 0xF;85b = (c >> 4) & 0xF;86tex16[i] = (a <<12) | (r << 8) | (g << 4) | b;87}88return (1 << 16) | GR_TEXFMT_ARGB_4444;89}90return (2 << 16) | GR_TEXFMT_ARGB_8888;91}9293//****************************************************************94// LoadTile for 32bit RGBA texture95// Based on sources of angrylion's software plugin.96//97void LoadTile32b (wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 width, wxUint32 height)98{99const wxUint32 line = rdp.tiles[tile].line << 2;100const wxUint32 tbase = rdp.tiles[tile].t_mem << 2;101const wxUint32 addr = rdp.timg.addr >> 2;102const wxUint32* src = (const wxUint32*)gfx.RDRAM;103wxUint16 *tmem16 = (wxUint16*)rdp.tmem;104wxUint32 c, ptr, tline, s, xorval;105106for (wxUint32 j = 0; j < height; j++)107{108tline = tbase + line * j;109s = ((j + ul_t) * rdp.timg.width) + ul_s;110xorval = (j & 1) ? 3 : 1;111for (wxUint32 i = 0; i < width; i++)112{113c = src[addr + s + i];114ptr = ((tline + i) ^ xorval) & 0x3ff;115tmem16[ptr] = c >> 16;116tmem16[ptr|0x400] = c & 0xffff;117}118}119}120121//****************************************************************122// LoadBlock for 32bit RGBA texture123// Based on sources of angrylion's software plugin.124//125void LoadBlock32b(wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 lr_s, wxUint32 dxt)126{127const wxUint32 * src = (const wxUint32*)gfx.RDRAM;128const wxUint32 tb = rdp.tiles[tile].t_mem << 2;129const wxUint32 tiwindwords = rdp.timg.width;130const wxUint32 slindwords = ul_s;131const wxUint32 line = rdp.tiles[tile].line << 2;132133wxUint16 *tmem16 = (wxUint16*)rdp.tmem;134wxUint32 addr = rdp.timg.addr >> 2;135wxUint32 width = (lr_s - ul_s + 1) << 2;136if (width & 7)137width = (width & (~7)) + 8;138139if (dxt != 0)140{141wxUint32 j= 0;142wxUint32 t = 0;143wxUint32 oldt = 0;144wxUint32 ptr;145146addr += (ul_t * tiwindwords) + slindwords;147wxUint32 c = 0;148for (wxUint32 i = 0; i < width; i += 2)149{150oldt = t;151t = ((j >> 11) & 1) ? 3 : 1;152if (t != oldt)153i += line;154ptr = ((tb + i) ^ t) & 0x3ff;155c = src[addr + i];156tmem16[ptr] = c >> 16;157tmem16[ptr|0x400] = c & 0xffff;158ptr = ((tb+ i + 1) ^ t) & 0x3ff;159c = src[addr + i + 1];160tmem16[ptr] = c >> 16;161tmem16[ptr|0x400] = c & 0xffff;162j += dxt;163}164}165else166{167addr += (ul_t * tiwindwords) + slindwords;168wxUint32 c, ptr;169for (wxUint32 i = 0; i < width; i ++)170{171ptr = ((tb + i) ^ 1) & 0x3ff;172c = src[addr + i];173tmem16[ptr] = c >> 16;174tmem16[ptr|0x400] = c & 0xffff;175}176}177}178179180