Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-glide64/src/TexLoad32b.h
2 views
1
/*
2
* Glide64 - Glide video plugin for Nintendo 64 emulators.
3
* Copyright (c) 2002 Dave2001
4
* Copyright (c) 2008 Günther <[email protected]>
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
17
* License along with this program; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA
20
*/
21
22
//****************************************************************
23
//
24
// Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)
25
// Project started on December 29th, 2001
26
//
27
// To modify Glide64:
28
// * 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.
29
// * 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.
30
//
31
// Official Glide64 development channel: #Glide64 on EFnet
32
//
33
// Original author: Dave2001 ([email protected])
34
// Other authors: Gonetz, Gugaman
35
//
36
//****************************************************************
37
38
//****************************************************************
39
// Size: 2, Format: 0
40
41
DWORD Load32bRGBA (unsigned char * dst, unsigned char * src, int wid_64, int height, int line, int real_width, int tile)
42
{
43
if (wid_64 < 1) wid_64 = 1;
44
if (height < 1) height = 1;
45
int ext = (real_width - (wid_64 << 1)) << 1;
46
47
wid_64 >>= 1; // re-shift it, load twice as many quadwords
48
#if !defined(__GNUC__) && !defined(NO_ASM)
49
__asm {
50
mov esi,dword ptr [src]
51
mov edi,dword ptr [dst]
52
53
mov ecx,dword ptr [height]
54
y_loop:
55
push ecx
56
57
mov ecx,dword ptr [wid_64]
58
x_loop:
59
mov eax,dword ptr [esi] // read first pixel
60
add esi,4
61
bswap eax
62
mov edx,eax
63
64
xor ebx,ebx
65
shl eax,8 // 0x000000F0 -> 0x0000F000 (a)
66
and eax,0x0000F000
67
or ebx,eax
68
shr edx,12 // 0x0000F000 -> 0x0000000F (b)
69
mov eax,edx
70
and eax,0x0000000F
71
or ebx,eax
72
shr edx,4 // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
73
mov eax,edx
74
and eax,0x000000F0
75
or ebx,eax
76
shr edx,4 // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
77
and edx,0x00000F00
78
or ebx,edx
79
80
mov eax,dword ptr [esi] // read second pixel
81
add esi,4
82
bswap eax
83
mov edx,eax
84
85
shl eax,24 // 0x000000F0 -> 0xF0000000 (a)
86
and eax,0xF0000000
87
or ebx,eax
88
// 0x00F00000 -> 0x00F00000 (g)
89
mov eax,edx
90
and eax,0x00F00000
91
or ebx,eax
92
rol edx,4 // 0x0000F000 (did not shift) -> 0x000F0000 (b)
93
mov eax,edx
94
and eax,0x000F0000
95
or ebx,eax
96
shl edx,24 // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
97
and edx,0x0F000000
98
or ebx,edx
99
100
mov dword ptr [edi],ebx
101
add edi,4
102
103
// * copy
104
mov eax,dword ptr [esi] // read first pixel
105
add esi,4
106
bswap eax
107
mov edx,eax
108
109
xor ebx,ebx
110
shl eax,8 // 0x000000F0 -> 0x0000F000 (a)
111
and eax,0x0000F000
112
or ebx,eax
113
shr edx,12 // 0x0000F000 -> 0x0000000F (b)
114
mov eax,edx
115
and eax,0x0000000F
116
or ebx,eax
117
shr edx,4 // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
118
mov eax,edx
119
and eax,0x000000F0
120
or ebx,eax
121
shr edx,4 // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
122
and edx,0x00000F00
123
or ebx,edx
124
125
mov eax,dword ptr [esi] // read second pixel
126
add esi,4
127
bswap eax
128
mov edx,eax
129
130
shl eax,24 // 0x000000F0 -> 0xF0000000 (a)
131
and eax,0xF0000000
132
or ebx,eax
133
// 0x00F00000 -> 0x00F00000 (g)
134
mov eax,edx
135
and eax,0x00F00000
136
or ebx,eax
137
rol edx,4 // 0x0000F000 (did not shift) -> 0x000F0000 (b)
138
mov eax,edx
139
and eax,0x000F0000
140
or ebx,eax
141
shl edx,24 // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
142
and edx,0x0F000000
143
or ebx,edx
144
145
mov dword ptr [edi],ebx
146
add edi,4
147
// *
148
149
dec ecx
150
jnz x_loop
151
152
pop ecx
153
dec ecx
154
jz end_y_loop
155
push ecx
156
157
add esi,dword ptr [line]
158
add edi,dword ptr [ext]
159
160
mov ecx,dword ptr [wid_64]
161
x_loop_2:
162
mov eax,dword ptr [esi+8] // read first pixel
163
bswap eax
164
mov edx,eax
165
166
xor ebx,ebx
167
shl eax,8 // 0x000000F0 -> 0x0000F000 (a)
168
and eax,0x0000F000
169
or ebx,eax
170
shr edx,12 // 0x0000F000 -> 0x0000000F (b)
171
mov eax,edx
172
and eax,0x0000000F
173
or ebx,eax
174
shr edx,4 // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
175
mov eax,edx
176
and eax,0x000000F0
177
or ebx,eax
178
shr edx,4 // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
179
and edx,0x00000F00
180
or ebx,edx
181
182
mov eax,dword ptr [esi+12] // read second pixel
183
bswap eax
184
mov edx,eax
185
186
shl eax,24 // 0x000000F0 -> 0xF0000000 (a)
187
and eax,0xF0000000
188
or ebx,eax
189
// 0x00F00000 -> 0x00F00000 (g)
190
mov eax,edx
191
and eax,0x00F00000
192
or ebx,eax
193
rol edx,4 // 0x0000F000 (did not shift) -> 0x000F0000 (b)
194
mov eax,edx
195
and eax,0x000F0000
196
or ebx,eax
197
shl edx,24 // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
198
and edx,0x0F000000
199
or ebx,edx
200
201
mov dword ptr [edi],ebx
202
add edi,4
203
204
// * copy
205
mov eax,dword ptr [esi+0] // read first pixel
206
bswap eax
207
mov edx,eax
208
209
xor ebx,ebx
210
shl eax,8 // 0x000000F0 -> 0x0000F000 (a)
211
and eax,0x0000F000
212
or ebx,eax
213
shr edx,12 // 0x0000F000 -> 0x0000000F (b)
214
mov eax,edx
215
and eax,0x0000000F
216
or ebx,eax
217
shr edx,4 // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
218
mov eax,edx
219
and eax,0x000000F0
220
or ebx,eax
221
shr edx,4 // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
222
and edx,0x00000F00
223
or ebx,edx
224
225
mov eax,dword ptr [esi+4] // read second pixel
226
add esi,16
227
bswap eax
228
mov edx,eax
229
230
shl eax,24 // 0x000000F0 -> 0xF0000000 (a)
231
and eax,0xF0000000
232
or ebx,eax
233
// 0x00F00000 -> 0x00F00000 (g)
234
mov eax,edx
235
and eax,0x00F00000
236
or ebx,eax
237
rol edx,4 // 0x0000F000 (did not shift) -> 0x000F0000 (b)
238
mov eax,edx
239
and eax,0x000F0000
240
or ebx,eax
241
shl edx,24 // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
242
and edx,0x0F000000
243
or ebx,edx
244
245
mov dword ptr [edi],ebx
246
add edi,4
247
// *
248
249
dec ecx
250
jnz x_loop_2
251
252
add esi,dword ptr [line]
253
add edi,dword ptr [ext]
254
255
pop ecx
256
dec ecx
257
jnz y_loop
258
259
end_y_loop:
260
}
261
#elif !defined(NO_ASM)
262
//printf("Load32bRGBA\n");
263
int lTemp, lHeight = (int) height;
264
asm volatile (
265
"y_loop9: \n"
266
267
"mov %[wid_64], %%eax \n"
268
"mov %%eax, %[temp] \n"
269
"x_loop9: \n"
270
"mov (%[src]), %%eax \n" // read first pixel
271
"add $4, %[src] \n"
272
"bswap %%eax \n"
273
"mov %%eax, %%edx \n"
274
275
"xor %%ecx, %%ecx \n"
276
"shl $8, %%eax \n" // 0x000000F0 -> 0x0000F000 (a)
277
"and $0x0000F000, %%eax \n"
278
"or %%eax, %%ecx \n"
279
"shr $12, %%edx \n" // 0x0000F000 -> 0x0000000F (b)
280
"mov %%edx, %%eax \n"
281
"and $0x0000000F, %%eax \n"
282
"or %%eax, %%ecx \n"
283
"shr $4, %%edx \n" // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
284
"mov %%edx, %%eax \n"
285
"and $0x000000F0, %%eax \n"
286
"or %%eax, %%ecx \n"
287
"shr $4, %%edx \n" // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
288
"and $0x00000F00, %%edx \n"
289
"or %%edx, %%ecx \n"
290
291
"mov (%[src]), %%eax \n" // read second pixel
292
"add $4, %[src] \n"
293
"bswap %%eax \n"
294
"mov %%eax, %%edx \n"
295
296
"shl $24, %%eax \n" // 0x000000F0 -> 0xF0000000 (a)
297
"and $0xF0000000, %%eax \n"
298
"or %%eax, %%ecx \n" // 0x00F00000 -> 0x00F00000 (g)
299
"mov %%edx, %%eax \n"
300
"and $0x00F00000, %%eax \n"
301
"or %%eax, %%ecx \n"
302
"rol $4, %%edx \n" // 0x0000F000 (did not shift) -> 0x000F0000 (b)
303
"mov %%edx, %%eax \n"
304
"and $0x000F0000, %%eax \n"
305
"or %%eax, %%ecx \n"
306
"shl $24, %%edx \n" // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
307
"and $0x0F000000, %%edx \n"
308
"or %%edx, %%ecx \n"
309
310
"mov %%ecx, (%[dst]) \n"
311
"add $4, %[dst] \n"
312
313
// * copy
314
"mov (%[src]), %%eax \n" // read first pixel
315
"add $4, %[src] \n"
316
"bswap %%eax \n"
317
"mov %%eax, %%edx \n"
318
319
"xor %%ecx, %%ecx \n"
320
"shl $8, %%eax \n" // 0x000000F0 -> 0x0000F000 (a)
321
"and $0x0000F000, %%eax \n"
322
"or %%eax, %%ecx \n"
323
"shr $12, %%edx \n" // 0x0000F000 -> 0x0000000F (b)
324
"mov %%edx, %%eax \n"
325
"and $0x0000000F, %%eax \n"
326
"or %%eax, %%ecx \n"
327
"shr $4, %%edx \n" // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
328
"mov %%edx, %%eax \n"
329
"and $0x000000F0, %%eax \n"
330
"or %%eax, %%ecx \n"
331
"shr $4, %%edx \n" // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
332
"and $0x00000F00, %%edx \n"
333
"or %%edx, %%ecx \n"
334
335
"mov (%[src]), %%eax \n" // read second pixel
336
"add $4, %[src] \n"
337
"bswap %%eax \n"
338
"mov %%eax, %%edx \n"
339
340
"shl $24, %%eax \n" // 0x000000F0 -> 0xF0000000 (a)
341
"and $0xF0000000, %%eax \n"
342
"or %%eax, %%ecx \n" // 0x00F00000 -> 0x00F00000 (g)
343
"mov %%edx, %%eax \n"
344
"and $0x00F00000, %%eax \n"
345
"or %%eax, %%ecx \n"
346
"rol $4, %%edx \n" // 0x0000F000 (did not shift) -> 0x000F0000 (b)
347
"mov %%edx, %%eax \n"
348
"and $0x000F0000, %%eax \n"
349
"or %%eax, %%ecx \n"
350
"shl $24, %%edx \n" // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
351
"and $0x0F000000, %%edx \n"
352
"or %%edx, %%ecx \n"
353
354
"mov %%ecx, (%[dst]) \n"
355
"add $4, %[dst] \n"
356
// *
357
358
"decl %[temp] \n"
359
"jnz x_loop9 \n"
360
361
"decl %[height] \n"
362
"jz end_y_loop9 \n"
363
364
"add %[line], %[src] \n"
365
"add %[ext], %[dst] \n"
366
367
"mov %[wid_64], %%eax \n"
368
"mov %%eax, %[temp] \n"
369
"x_loop_29: \n"
370
"mov 8(%[src]), %%eax \n" // read first pixel
371
"bswap %%eax \n"
372
"mov %%eax, %%edx \n"
373
374
"xor %%ecx, %%ecx \n"
375
"shl $8, %%eax \n" // 0x000000F0 -> 0x0000F000 (a)
376
"and $0x0000F000, %%eax \n"
377
"or %%eax, %%ecx \n"
378
"shr $12, %%edx \n" // 0x0000F000 -> 0x0000000F (b)
379
"mov %%edx, %%eax \n"
380
"and $0x0000000F, %%eax \n"
381
"or %%eax, %%ecx \n"
382
"shr $4, %%edx \n" // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
383
"mov %%edx, %%eax \n"
384
"and $0x000000F0, %%eax \n"
385
"or %%eax, %%ecx \n"
386
"shr $4, %%edx \n" // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
387
"and $0x00000F00, %%edx \n"
388
"or %%edx, %%ecx \n"
389
390
"mov 12(%[src]), %%eax \n" // read second pixel
391
"bswap %%eax \n"
392
"mov %%eax, %%edx \n"
393
394
"shl $24, %%eax \n" // 0x000000F0 -> 0xF0000000 (a)
395
"and $0xF0000000, %%eax \n"
396
"or %%eax, %%ecx \n" // 0x00F00000 -> 0x00F00000 (g)
397
"mov %%edx, %%eax \n"
398
"and $0x00F00000, %%eax \n"
399
"or %%eax, %%ecx \n"
400
"rol $4, %%edx \n" // 0x0000F000 (did not shift) -> 0x000F0000 (b)
401
"mov %%edx, %%eax \n"
402
"and $0x000F0000, %%eax \n"
403
"or %%eax, %%ecx \n"
404
"shl $24, %%edx \n" // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
405
"and $0x0F000000, %%edx \n"
406
"or %%edx, %%ecx \n"
407
408
"mov %%ecx, (%[dst]) \n"
409
"add $4, %[dst] \n"
410
411
// * copy
412
"mov (%[src]), %%eax \n" // read first pixel
413
"bswap %%eax \n"
414
"mov %%eax, %%edx \n"
415
416
"xor %%ecx, %%ecx \n"
417
"shl $8, %%eax \n" // 0x000000F0 -> 0x0000F000 (a)
418
"and $0x0000F000, %%eax \n"
419
"or %%eax, %%ecx \n"
420
"shr $12, %%edx \n" // 0x0000F000 -> 0x0000000F (b)
421
"mov %%edx, %%eax \n"
422
"and $0x0000000F, %%eax \n"
423
"or %%eax, %%ecx \n"
424
"shr $4, %%edx \n" // 0x00F00000 went to 0x00000F00 -> 0x000000F0 (g)
425
"mov %%edx, %%eax \n"
426
"and $0x000000F0, %%eax \n"
427
"or %%eax, %%ecx \n"
428
"shr $4, %%edx \n" // 0xF0000000 went to 0x000F0000 went to 0x0000F000 -> 0x00000F00 (r)
429
"and $0x00000F00, %%edx \n"
430
"or %%edx, %%ecx \n"
431
432
"mov 4(%[src]), %%eax \n" // read second pixel
433
"add $16, %[src] \n"
434
"bswap %%eax \n"
435
"mov %%eax, %%edx \n"
436
437
"shl $24, %%eax \n" // 0x000000F0 -> 0xF0000000 (a)
438
"and $0xF0000000, %%eax \n"
439
"or %%eax, %%ecx \n" // 0x00F00000 -> 0x00F00000 (g)
440
"mov %%edx, %%eax \n"
441
"and $0x00F00000, %%eax \n"
442
"or %%eax, %%ecx \n"
443
"rol $4, %%edx \n" // 0x0000F000 (did not shift) -> 0x000F0000 (b)
444
"mov %%edx, %%eax \n"
445
"and $0x000F0000, %%eax \n"
446
"or %%eax, %%ecx \n"
447
"shl $24, %%edx \n" // 0xF0000000 went to 0x0000000F -> 0x0F000000 (r)
448
"and $0x0F000000, %%edx \n"
449
"or %%edx, %%ecx \n"
450
451
"mov %%ecx, (%[dst]) \n"
452
"add $4, %[dst] \n"
453
// *
454
455
"decl %[temp] \n"
456
"jnz x_loop_29 \n"
457
458
"add %[line], %[src] \n"
459
"add %[ext], %[dst] \n"
460
461
"decl %[height] \n"
462
"jnz y_loop9 \n"
463
464
"end_y_loop9: \n"
465
: [temp]"=m"(lTemp), [src]"+S"(src), [dst]"+D"(dst), [height]"+g"(lHeight)
466
: [wid_64] "g" (wid_64), [line] "g" ((uintptr_t)line), [ext] "g" ((uintptr_t)ext)
467
: "memory", "cc", "ecx", "eax", "edx"
468
);
469
#endif
470
return (1 << 16) | GR_TEXFMT_ARGB_4444;
471
}
472
473
474