Path: blob/master/libmupen64plus/mupen64plus-video-glide64/src/TexConv.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2008 Günther <[email protected]>4*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 Public16* Licence along with this program; if not, write to the Free17* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,18* Boston, MA 02110-1301, USA19*/2021//****************************************************************22//23// Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)24// Project started on December 29th, 200125//26// To modify Glide64:27// * 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.28// * 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.29//30// Official Glide64 development channel: #Glide64 on EFnet31//32// Original author: Dave2001 ([email protected])33// Other authors: Gonetz, Gugaman34//35//****************************************************************3637void TexConv_ARGB1555_ARGB4444 (unsigned char * _src, unsigned char * _dst, int width, int height)38{39int _size = (width * height) << 1;40#if !defined(__GNUC__) && !defined(NO_ASM)41__asm {42mov esi,dword ptr [_src]43mov edi,dword ptr [_dst]44mov ecx,dword ptr [_size]4546tc1_loop:47mov eax,dword ptr [esi]48add esi,44950// arrr rrgg gggb bbbb51// aaaa rrrr gggg bbbb52mov edx,eax53and eax,0x8000800054mov ebx,eax // ebx = 0xa00000000000000055shr eax,156or ebx,eax // ebx = 0xaa0000000000000057shr eax,158or ebx,eax // ebx = 0xaaa000000000000059shr eax,160or ebx,eax // ebx = 0xaaaa0000000000006162mov eax,edx63and eax,0x78007800 // eax = 0x0rrrr0000000000064shr eax,3 // eax = 0x0000rrrr0000000065or ebx,eax // ebx = 0xaaaarrrr000000006667mov eax,edx68and eax,0x03c003c0 // eax = 0x000000gggg00000069shr eax,2 // eax = 0x00000000gggg000070or ebx,eax // ebx = 0xaaaarrrrgggg00007172and edx,0x001e001e // edx = 0x00000000000bbbb073shr edx,1 // edx = 0x000000000000bbbb74or ebx,edx // ebx = 0xaaaarrrrggggbbbb7576mov dword ptr [edi],ebx77add edi,47879dec ecx80jnz tc1_loop81}82#elif !defined(NO_ASM)83//printf("TexConv_ARGB1555_ARGB4444\n");84asm volatile (85//"tc1_loop2: \n"86"0: \n"87"mov (%[_src]), %%eax \n"88"add $4, %[_src] \n"8990// arrr rrgg gggb bbbb91// aaaa rrrr gggg bbbb92"mov %%eax, %%edx \n"93"and $0x80008000, %%eax \n"94"mov %%eax, %%ecx \n" // ecx = 0xa00000000000000095"shr $1, %%eax \n"96"or %%eax, %%ecx \n" // ecx = 0xaa0000000000000097"shr $1, %%eax \n"98"or %%eax, %%ecx \n" // ecx = 0xaaa000000000000099"shr $1, %%eax \n"100"or %%eax, %%ecx \n" // ecx = 0xaaaa000000000000101102"mov %%edx, %%eax \n"103"and $0x78007800, %%eax \n" // eax = 0x0rrrr00000000000104"shr $3, %%eax \n" // eax = 0x0000rrrr00000000105"or %%eax, %%ecx \n" // ecx = 0xaaaarrrr00000000106107"mov %%edx, %%eax \n"108"and $0x03c003c0, %%eax \n" // eax = 0x000000gggg000000109"shr $2, %%eax \n" // eax = 0x00000000gggg0000110"or %%eax, %%ecx \n" // ecx = 0xaaaarrrrgggg0000111112"and $0x001e001e, %%edx \n" // edx = 0x00000000000bbbb0113"shr $1, %%edx \n" // edx = 0x000000000000bbbb114"or %%edx, %%ecx \n" // ecx = 0xaaaarrrrggggbbbb115116"mov %%ecx, (%[_dst]) \n"117"add $4, %[_dst] \n"118119"decl %[_size] \n"120"jnz 0b \n"121: [_src]"+S"(_src), [_dst]"+D"(_dst), [_size]"+g"(_size)122:123: "memory", "cc", "eax", "edx", "ecx"124);125#endif126}127128void TexConv_AI88_ARGB4444 (unsigned char * _src, unsigned char * _dst, int width, int height)129{130int _size = (width * height) << 1;131#if !defined(__GNUC__) && !defined(NO_ASM)132__asm {133mov esi,dword ptr [_src]134mov edi,dword ptr [_dst]135mov ecx,dword ptr [_size]136137tc1_loop:138mov eax,dword ptr [esi]139add esi,4140141// aaaa aaaa iiii iiii142// aaaa rrrr gggg bbbb143mov edx,eax144and eax,0xF000F000 // eax = 0xaaaa000000000000145mov ebx,eax // ebx = 0xaaaa000000000000146147and edx,0x00F000F0 // edx = 0x00000000iiii0000148shl edx,4 // edx = 0x0000iiii00000000149or ebx,edx // ebx = 0xaaaaiiii00000000150shr edx,4 // edx = 0x00000000iiii0000151or ebx,edx // ebx = 0xaaaaiiiiiiii0000152shr edx,4 // edx = 0x000000000000iiii153or ebx,edx // ebx = 0xaaaaiiiiiiiiiiii154155mov dword ptr [edi],ebx156add edi,4157158dec ecx159jnz tc1_loop160}161#elif !defined(NO_ASM)162//printf("TexConv_AI88_ARGB4444\n");163asm volatile (164//"tc1_loop3: \n"165"0: \n"166"mov (%[_src]), %%eax \n"167"add $4, %[_src] \n"168169// aaaa aaaa iiii iiii170// aaaa rrrr gggg bbbb171"mov %%eax, %%edx \n"172"and $0xF000F000, %%eax \n" // eax = 0xaaaa000000000000173"mov %%eax, %%ecx \n" // ecx = 0xaaaa000000000000174175"and $0x00F000F0, %%edx \n" // edx = 0x00000000iiii0000176"shl $4, %%edx \n" // edx = 0x0000iiii00000000177"or %%edx, %%ecx \n" // ecx = 0xaaaaiiii00000000178"shr $4, %%edx \n" // edx = 0x00000000iiii0000179"or %%edx, %%ecx \n" // ecx = 0xaaaaiiiiiiii0000180"shr $4, %%edx \n" // edx = 0x000000000000iiii181"or %%edx, %%ecx \n" // ecx = 0xaaaaiiiiiiiiiiii182183"mov %%ecx, (%[_dst]) \n"184"add $4, %[_dst] \n"185186"decl %[_size] \n"187"jnz 0b \n"188: [_src]"+S"(_src), [_dst]"+D"(_dst), [_size]"+g"(_size)189:190: "memory", "cc", "eax", "edx", "ecx"191);192#endif193}194195void TexConv_AI44_ARGB4444 (unsigned char * _src, unsigned char * _dst, int width, int height)196{197int _size = width * height;198#if !defined(__GNUC__) && !defined(NO_ASM)199__asm {200mov esi,dword ptr [_src]201mov edi,dword ptr [_dst]202mov ecx,dword ptr [_size]203204tc1_loop:205mov eax,dword ptr [esi]206add esi,4207208// aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0209// aaaa1 rrrr1 gggg1 bbbb1 aaaa0 rrrr0 gggg0 bbbb0210// aaaa3 rrrr3 gggg3 bbbb3 aaaa2 rrrr2 gggg2 bbbb2211mov edx,eax // eax = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0212shl eax,16 // eax = aaaa1 iiii1 aaaa0 iiii0 0000 0000 0000 0000213and eax,0xFF000000 // eax = aaaa1 iiii1 0000 0000 0000 0000 0000 0000214mov ebx,eax // ebx = aaaa1 iiii1 0000 0000 0000 0000 0000 0000215and eax,0x0F000000 // eax = 0000 iiii1 0000 0000 0000 0000 0000 0000216shr eax,4 // eax = 0000 0000 iiii1 0000 0000 0000 0000 0000217or ebx,eax // ebx = aaaa1 iiii1 iiii1 0000 0000 0000 0000 0000218shr eax,4 // eax = 0000 0000 0000 iiii1 0000 0000 0000 0000219or ebx,eax // ebx = aaaa1 iiii1 iiii1 iiii1 0000 0000 0000 0000220221mov eax,edx // eax = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0222shl eax,8 // eax = aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0 0000 0000223and eax,0x0000FF00 // eax = 0000 0000 0000 0000 aaaa0 iiii0 0000 0000224or ebx,eax // ebx = aaaa1 iiii1 iiii1 iiii1 aaaa0 iiii0 0000 0000225and eax,0x00000F00 // eax = 0000 0000 0000 0000 0000 iiii0 0000 0000226shr eax,4 // eax = 0000 0000 0000 0000 0000 0000 iiii0 0000227or ebx,eax // ebx = aaaa1 iiii1 iiii1 iiii1 aaaa0 iiii0 iiii0 0000228shr eax,4 // eax = 0000 0000 0000 0000 0000 0000 0000 iiii0229or ebx,eax // ebx = aaaa1 iiii1 iiii1 iiii1 aaaa0 iiii0 iiii0 iiii0230231mov dword ptr [edi],ebx232add edi,4233234mov eax,edx // eax = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0235and eax,0xFF000000 // eax = aaaa3 iiii3 0000 0000 0000 0000 0000 0000236mov ebx,eax // ebx = aaaa3 iiii3 0000 0000 0000 0000 0000 0000237and eax,0x0F000000 // eax = 0000 iiii3 0000 0000 0000 0000 0000 0000238shr eax,4 // eax = 0000 0000 iiii3 0000 0000 0000 0000 0000239or ebx,eax // ebx = aaaa3 iiii3 iiii3 0000 0000 0000 0000 0000240shr eax,4 // eax = 0000 0000 0000 iiii3 0000 0000 0000 0000241or ebx,eax // ebx = aaaa3 iiii3 iiii3 iiii3 0000 0000 0000 0000242243// edx = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0244shr edx,8 // edx = 0000 0000 aaaa3 aaaa3 aaaa2 iiii2 aaaa1 iiii1245and edx,0x0000FF00 // edx = 0000 0000 0000 0000 aaaa2 iiii2 0000 0000246or ebx,edx // ebx = aaaa3 iiii3 iiii3 iiii3 aaaa2 iiii2 0000 0000247and edx,0x00000F00 // edx = 0000 0000 0000 0000 0000 iiii2 0000 0000248shr edx,4 // edx = 0000 0000 0000 0000 0000 0000 iiii2 0000249or ebx,edx // ebx = aaaa3 iiii3 iiii3 iiii3 aaaa2 iiii2 iiii2 0000250shr edx,4 // edx = 0000 0000 0000 0000 0000 0000 0000 iiii2251or ebx,edx // ebx = aaaa3 iiii3 iiii3 iiii3 aaaa2 iiii2 iiii2 iiii2252253mov dword ptr [edi],ebx254add edi,4255256dec ecx257jnz tc1_loop258}259#elif !defined(NO_ASM)260//printf("TexConv_AI44_ARGB4444\n");261asm volatile (262//"tc1_loop4: \n"263"0: \n"264"mov (%[_src]), %%eax \n"265"add $4, %[_src] \n"266267// aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0268// aaaa1 rrrr1 gggg1 bbbb1 aaaa0 rrrr0 gggg0 bbbb0269// aaaa3 rrrr3 gggg3 bbbb3 aaaa2 rrrr2 gggg2 bbbb2270"mov %%eax, %%edx \n" // eax = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0271"shl $16, %%eax \n" // eax = aaaa1 iiii1 aaaa0 iiii0 0000 0000 0000 0000272"and $0xFF000000, %%eax \n" // eax = aaaa1 iiii1 0000 0000 0000 0000 0000 0000273"mov %%eax, %%ecx \n" // ecx = aaaa1 iiii1 0000 0000 0000 0000 0000 0000274"and $0x0F000000, %%eax \n" // eax = 0000 iiii1 0000 0000 0000 0000 0000 0000275"shr $4, %%eax \n" // eax = 0000 0000 iiii1 0000 0000 0000 0000 0000276"or %%eax, %%ecx \n" // ecx = aaaa1 iiii1 iiii1 0000 0000 0000 0000 0000277"shr $4, %%eax \n" // eax = 0000 0000 0000 iiii1 0000 0000 0000 0000278"or %%eax, %%ecx \n" // ecx = aaaa1 iiii1 iiii1 iiii1 0000 0000 0000 0000279280"mov %%edx, %%eax \n" // eax = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0281"shl $8, %%eax \n" // eax = aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0 0000 0000282"and $0x0000FF00, %%eax \n" // eax = 0000 0000 0000 0000 aaaa0 iiii0 0000 0000283"or %%eax, %%ecx \n" // ecx = aaaa1 iiii1 iiii1 iiii1 aaaa0 iiii0 0000 0000284"and $0x00000F00, %%eax \n" // eax = 0000 0000 0000 0000 0000 iiii0 0000 0000285"shr $4, %%eax \n" // eax = 0000 0000 0000 0000 0000 0000 iiii0 0000286"or %%eax, %%ecx \n" // ecx = aaaa1 iiii1 iiii1 iiii1 aaaa0 iiii0 iiii0 0000287"shr $4, %%eax \n" // eax = 0000 0000 0000 0000 0000 0000 0000 iiii0288"or %%eax, %%ecx \n" // ecx = aaaa1 iiii1 iiii1 iiii1 aaaa0 iiii0 iiii0 iiii0289290"mov %%ecx, (%[_dst]) \n"291"add $4, %[_dst] \n"292293"mov %%edx, %%eax \n" // eax = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0294"and $0xFF000000, %%eax \n" // eax = aaaa3 iiii3 0000 0000 0000 0000 0000 0000295"mov %%eax, %%ecx \n" // ecx = aaaa3 iiii3 0000 0000 0000 0000 0000 0000296"and $0x0F000000, %%eax \n" // eax = 0000 iiii3 0000 0000 0000 0000 0000 0000297"shr $4, %%eax \n" // eax = 0000 0000 iiii3 0000 0000 0000 0000 0000298"or %%eax, %%ecx \n" // ecx = aaaa3 iiii3 iiii3 0000 0000 0000 0000 0000299"shr $4, %%eax \n" // eax = 0000 0000 0000 iiii3 0000 0000 0000 0000300"or %%eax, %%ecx \n" // ecx = aaaa3 iiii3 iiii3 iiii3 0000 0000 0000 0000301302// edx = aaaa3 iiii3 aaaa2 iiii2 aaaa1 iiii1 aaaa0 iiii0303"shr $8, %%edx \n" // edx = 0000 0000 aaaa3 aaaa3 aaaa2 iiii2 aaaa1 iiii1304"and $0x0000FF00, %%edx \n" // edx = 0000 0000 0000 0000 aaaa2 iiii2 0000 0000305"or %%edx, %%ecx \n" // ecx = aaaa3 iiii3 iiii3 iiii3 aaaa2 iiii2 0000 0000306"and $0x00000F00, %%edx \n" // edx = 0000 0000 0000 0000 0000 iiii2 0000 0000307"shr $4, %%edx \n" // edx = 0000 0000 0000 0000 0000 0000 iiii2 0000308"or %%edx, %%ecx \n" // ecx = aaaa3 iiii3 iiii3 iiii3 aaaa2 iiii2 iiii2 0000309"shr $4, %%edx \n" // edx = 0000 0000 0000 0000 0000 0000 0000 iiii2310"or %%edx, %%ecx \n" // ecx = aaaa3 iiii3 iiii3 iiii3 aaaa2 iiii2 iiii2 iiii2311312"mov %%ecx, (%[_dst]) \n"313"add $4, %[_dst] \n"314315"decl %[_size] \n"316"jnz 0b \n"317: [_src]"+S"(_src), [_dst]"+D"(_dst), [_size]"+g"(_size)318:319: "memory", "cc", "eax", "edx", "ecx"320);321#endif322}323324void TexConv_A8_ARGB4444 (unsigned char * _src, unsigned char * _dst, int width, int height)325{326int _size = (width * height) << 1;327#if !defined(__GNUC__) && !defined(NO_ASM)328__asm {329mov esi,dword ptr [_src]330mov edi,dword ptr [_dst]331mov ecx,dword ptr [_size]332333tc1_loop:334mov eax,dword ptr [esi]335add esi,4336337// aaaa3 aaaa3 aaaa2 aaaa2 aaaa1 aaaa1 aaaa0 aaaa0338// aaaa1 rrrr1 gggg1 bbbb1 aaaa0 rrrr0 gggg0 bbbb0339// aaaa3 rrrr3 gggg3 bbbb3 aaaa2 rrrr2 gggg2 bbbb2340mov edx,eax341and eax,0x0000F000 // eax = 00 00 00 00 a1 00 00 00342shl eax,16 // eax = a1 00 00 00 00 00 00 00343mov ebx,eax // ebx = a1 00 00 00 00 00 00 00344shr eax,4345or ebx,eax // ebx = a1 a1 00 00 00 00 00 00346shr eax,4347or ebx,eax // ebx = a1 a1 a1 00 00 00 00 00348shr eax,4349or ebx,eax // ebx = a1 a1 a1 a1 00 00 00 00350351mov eax,edx352and eax,0x000000F0 // eax = 00 00 00 00 00 00 a0 00353shl eax,8 // eax = 00 00 00 00 a0 00 00 00354or ebx,eax355shr eax,4356or ebx,eax357shr eax,4358or ebx,eax359shr eax,4360or ebx,eax // ebx = a1 a1 a1 a1 a0 a0 a0 a0361362mov dword ptr [edi],ebx363add edi,4364365mov eax,edx // eax = a3 a3 a2 a2 a1 a1 a0 a0366and eax,0xF0000000 // eax = a3 00 00 00 00 00 00 00367mov ebx,eax // ebx = a3 00 00 00 00 00 00 00368shr eax,4369or ebx,eax // ebx = a3 a3 00 00 00 00 00 00370shr eax,4371or ebx,eax // ebx = a3 a3 a3 00 00 00 00 00372shr eax,4373or ebx,eax // ebx = a3 a3 a3 a3 00 00 00 00374375and edx,0x00F00000 // eax = 00 00 a2 00 00 00 00 00376shr edx,8 // eax = 00 00 00 00 a2 00 00 00377or ebx,edx378shr edx,4379or ebx,edx380shr edx,4381or ebx,edx382shr edx,4383or ebx,edx // ebx = a3 a3 a3 a3 a2 a2 a2 a2384385mov dword ptr [edi],ebx386add edi,4387388dec ecx389jnz tc1_loop390}391#elif !defined(NO_ASM)392//printf("TexConv_A8_ARGB4444\n");393asm volatile (394//"tc1_loop: \n"395"0: \n"396"mov (%[src]), %%eax \n"397"add $4, %[src] \n"398399// aaaa3 aaaa3 aaaa2 aaaa2 aaaa1 aaaa1 aaaa0 aaaa0400// aaaa1 rrrr1 gggg1 bbbb1 aaaa0 rrrr0 gggg0 bbbb0401// aaaa3 rrrr3 gggg3 bbbb3 aaaa2 rrrr2 gggg2 bbbb2402"mov %%eax, %%edx \n"403"and $0x0000F000, %%eax \n" // eax = 00 00 00 00 a1 00 00 00404"shl $16, %%eax \n" // eax = a1 00 00 00 00 00 00 00405"mov %%eax, %%ecx \n" // ecx = a1 00 00 00 00 00 00 00406"shr $4, %%eax \n"407"or %%eax, %%ecx \n" // ecx = a1 a1 00 00 00 00 00 00408"shr $4, %%eax \n"409"or %%eax, %%ecx \n" // ecx = a1 a1 a1 00 00 00 00 00410"shr $4, %%eax \n"411"or %%eax, %%ecx \n" // ecx = a1 a1 a1 a1 00 00 00 00412413"mov %%edx, %%eax \n"414"and $0x000000F0, %%eax \n" // eax = 00 00 00 00 00 00 a0 00415"shl $8, %%eax \n" // eax = 00 00 00 00 a0 00 00 00416"or %%eax, %%ecx \n"417"shr $4, %%eax \n"418"or %%eax, %%ecx \n"419"shr $4, %%eax \n"420"or %%eax, %%ecx \n"421"shr $4, %%eax \n"422"or %%eax, %%ecx \n" // ecx = a1 a1 a1 a1 a0 a0 a0 a0423424"mov %%ecx, (%[_dst]) \n"425"add $4, %[_dst] \n"426427"mov %%edx, %%eax \n" // eax = a3 a3 a2 a2 a1 a1 a0 a0428"and $0xF0000000, %%eax \n" // eax = a3 00 00 00 00 00 00 00429"mov %%eax, %%ecx \n" // ecx = a3 00 00 00 00 00 00 00430"shr $4, %%eax \n"431"or %%eax, %%ecx \n" // ecx = a3 a3 00 00 00 00 00 00432"shr $4, %%eax \n"433"or %%eax, %%ecx \n" // ecx = a3 a3 a3 00 00 00 00 00434"shr $4, %%eax \n"435"or %%eax, %%ecx \n" // ecx = a3 a3 a3 a3 00 00 00 00436437"and $0x00F00000, %%edx \n" // eax = 00 00 a2 00 00 00 00 00438"shr $8, %%edx \n" // eax = 00 00 00 00 a2 00 00 00439"or %%edx, %%ecx \n"440"shr $4, %%edx \n"441"or %%edx, %%ecx \n"442"shr $4, %%edx \n"443"or %%edx, %%ecx \n"444"shr $4, %%edx \n"445"or %%edx, %%ecx \n" // ecx = a3 a3 a3 a3 a2 a2 a2 a2446447"mov %%ecx, (%[_dst]) \n"448"add $4, %[_dst] \n"449450"decl %[_size] \n"451"jnz 0b \n"452: [src]"+S"(_src), [_dst]"+D"(_dst), [_size]"+g"(_size)453:454: "memory", "cc", "eax", "ecx", "edx"455);456#endif457}458459460461