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 //****************************************************************
41 //****************************************************************
44 // Load 32bit RGBA texture
45 // Based on sources of angrylion's software plugin.
47 wxUint32 Load32bRGBA (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int line, int real_width, int tile)
49 if (height < 1) height = 1;
50 const wxUint16 *tmem16 = (wxUint16*)rdp.tmem;
51 const wxUint32 tbase = (src - (wxUIntPtr)rdp.tmem) >> 1;
52 const wxUint32 width = max(1, wid_64 << 1);
53 const int ext = real_width - width;
54 line = width + (line>>2);
56 wxUint32 * tex = (wxUint32*)dst;
58 for (t = 0; t < (wxUint32)height; t++)
60 wxUint32 tline = tbase + line * t;
61 wxUint32 xorval = (t & 1) ? 3 : 1;
62 for (s = 0; s < width; s++)
64 wxUint32 taddr = ((tline + s) ^ xorval) & 0x3ff;
66 ba = tmem16[taddr|0x400];
67 c = ((ba&0xFF)<<24) | (rg << 8) | (ba>>8);
72 int id = tile - rdp.cur_tile;
73 wxUint32 mod = (id == 0) ? cmb.mod_0 : cmb.mod_1;
74 if (mod || !voodoo.sup_32bit_tex)
76 //convert to ARGB_4444
77 const wxUint32 tex_size = real_width * height;
78 tex = (wxUint32 *)dst;
79 wxUint16 *tex16 = (wxUint16*)dst;
81 for (wxUint32 i = 0; i < tex_size; i++) {
87 tex16[i] = (a <<12) | (r << 8) | (g << 4) | b;
89 return (1 << 16) | GR_TEXFMT_ARGB_4444;
91 return (2 << 16) | GR_TEXFMT_ARGB_8888;
94 //****************************************************************
95 // LoadTile for 32bit RGBA texture
96 // Based on sources of angrylion's software plugin.
98 void LoadTile32b (wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 width, wxUint32 height)
100 const wxUint32 line = rdp.tiles[tile].line << 2;
101 const wxUint32 tbase = rdp.tiles[tile].t_mem << 2;
102 const wxUint32 addr = rdp.timg.addr >> 2;
103 const wxUint32* src = (const wxUint32*)gfx.RDRAM;
104 wxUint16 *tmem16 = (wxUint16*)rdp.tmem;
105 wxUint32 c, ptr, tline, s, xorval;
107 for (wxUint32 j = 0; j < height; j++)
109 tline = tbase + line * j;
110 s = ((j + ul_t) * rdp.timg.width) + ul_s;
111 xorval = (j & 1) ? 3 : 1;
112 for (wxUint32 i = 0; i < width; i++)
114 c = src[addr + s + i];
115 ptr = ((tline + i) ^ xorval) & 0x3ff;
116 tmem16[ptr] = c >> 16;
117 tmem16[ptr|0x400] = c & 0xffff;
122 //****************************************************************
123 // LoadBlock for 32bit RGBA texture
124 // Based on sources of angrylion's software plugin.
126 void LoadBlock32b(wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 lr_s, wxUint32 dxt)
128 const wxUint32 * src = (const wxUint32*)gfx.RDRAM;
129 const wxUint32 tb = rdp.tiles[tile].t_mem << 2;
130 const wxUint32 tiwindwords = rdp.timg.width;
131 const wxUint32 slindwords = ul_s;
132 const wxUint32 line = rdp.tiles[tile].line << 2;
134 wxUint16 *tmem16 = (wxUint16*)rdp.tmem;
135 wxUint32 addr = rdp.timg.addr >> 2;
136 wxUint32 width = (lr_s - ul_s + 1) << 2;
138 width = (width & (~7)) + 8;
147 addr += (ul_t * tiwindwords) + slindwords;
149 for (wxUint32 i = 0; i < width; i += 2)
152 t = ((j >> 11) & 1) ? 3 : 1;
155 ptr = ((tb + i) ^ t) & 0x3ff;
157 tmem16[ptr] = c >> 16;
158 tmem16[ptr|0x400] = c & 0xffff;
159 ptr = ((tb+ i + 1) ^ t) & 0x3ff;
160 c = src[addr + i + 1];
161 tmem16[ptr] = c >> 16;
162 tmem16[ptr|0x400] = c & 0xffff;
168 addr += (ul_t * tiwindwords) + slindwords;
170 for (wxUint32 i = 0; i < width; i ++)
172 ptr = ((tb + i) ^ 1) & 0x3ff;
174 tmem16[ptr] = c >> 16;
175 tmem16[ptr|0x400] = c & 0xffff;