Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/TexLoad32b.h
2 views
1
/*
2
* Glide64 - Glide video plugin for Nintendo 64 emulators.
3
* Copyright (c) 2002 Dave2001
4
* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
5
*
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
9
* any later version.
10
*
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.
15
*
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
19
*/
20
21
//****************************************************************
22
//
23
// Glide64 - Glide Plugin for Nintendo 64 emulators
24
// Project started on December 29th, 2001
25
//
26
// Authors:
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
31
//
32
//****************************************************************
33
//
34
// To modify Glide64:
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.
37
//
38
//****************************************************************
39
#include "Gfx_1.3.h"
40
41
//****************************************************************
42
// Size: 2, Format: 0
43
//
44
// Load 32bit RGBA texture
45
// Based on sources of angrylion's software plugin.
46
//
47
wxUint32 Load32bRGBA (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int line, int real_width, int tile)
48
{
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);
55
wxUint32 s, t, c;
56
wxUint32 * tex = (wxUint32*)dst;
57
wxUint16 rg, ba;
58
for (t = 0; t < (wxUint32)height; t++)
59
{
60
wxUint32 tline = tbase + line * t;
61
wxUint32 xorval = (t & 1) ? 3 : 1;
62
for (s = 0; s < width; s++)
63
{
64
wxUint32 taddr = ((tline + s) ^ xorval) & 0x3ff;
65
rg = tmem16[taddr];
66
ba = tmem16[taddr|0x400];
67
c = ((ba&0xFF)<<24) | (rg << 8) | (ba>>8);
68
*tex++ = c;
69
}
70
tex += ext;
71
}
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)
75
{
76
//convert to ARGB_4444
77
const wxUint32 tex_size = real_width * height;
78
tex = (wxUint32 *)dst;
79
wxUint16 *tex16 = (wxUint16*)dst;
80
wxUint16 a, r, g, b;
81
for (wxUint32 i = 0; i < tex_size; i++) {
82
c = tex[i];
83
a = (c >> 28) & 0xF;
84
r = (c >> 20) & 0xF;
85
g = (c >> 12) & 0xF;
86
b = (c >> 4) & 0xF;
87
tex16[i] = (a <<12) | (r << 8) | (g << 4) | b;
88
}
89
return (1 << 16) | GR_TEXFMT_ARGB_4444;
90
}
91
return (2 << 16) | GR_TEXFMT_ARGB_8888;
92
}
93
94
//****************************************************************
95
// LoadTile for 32bit RGBA texture
96
// Based on sources of angrylion's software plugin.
97
//
98
void LoadTile32b (wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 width, wxUint32 height)
99
{
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;
106
107
for (wxUint32 j = 0; j < height; j++)
108
{
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++)
113
{
114
c = src[addr + s + i];
115
ptr = ((tline + i) ^ xorval) & 0x3ff;
116
tmem16[ptr] = c >> 16;
117
tmem16[ptr|0x400] = c & 0xffff;
118
}
119
}
120
}
121
122
//****************************************************************
123
// LoadBlock for 32bit RGBA texture
124
// Based on sources of angrylion's software plugin.
125
//
126
void LoadBlock32b(wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 lr_s, wxUint32 dxt)
127
{
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;
133
134
wxUint16 *tmem16 = (wxUint16*)rdp.tmem;
135
wxUint32 addr = rdp.timg.addr >> 2;
136
wxUint32 width = (lr_s - ul_s + 1) << 2;
137
if (width & 7)
138
width = (width & (~7)) + 8;
139
140
if (dxt != 0)
141
{
142
wxUint32 j= 0;
143
wxUint32 t = 0;
144
wxUint32 oldt = 0;
145
wxUint32 ptr;
146
147
addr += (ul_t * tiwindwords) + slindwords;
148
wxUint32 c = 0;
149
for (wxUint32 i = 0; i < width; i += 2)
150
{
151
oldt = t;
152
t = ((j >> 11) & 1) ? 3 : 1;
153
if (t != oldt)
154
i += line;
155
ptr = ((tb + i) ^ t) & 0x3ff;
156
c = src[addr + i];
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;
163
j += dxt;
164
}
165
}
166
else
167
{
168
addr += (ul_t * tiwindwords) + slindwords;
169
wxUint32 c, ptr;
170
for (wxUint32 i = 0; i < width; i ++)
171
{
172
ptr = ((tb + i) ^ 1) & 0x3ff;
173
c = src[addr + i];
174
tmem16[ptr] = c >> 16;
175
tmem16[ptr|0x400] = c & 0xffff;
176
}
177
}
178
}
179
180