Path: blob/master/libmupen64plus/mupen64plus-video-glide64/src/TexLoad16b.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* License 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//****************************************************************3637//****************************************************************38// Size: 2, Format: 03940DWORD Load16bRGBA (unsigned char * dst, unsigned char * src, int wid_64, int height, int line, int real_width, int tile)41{42if (wid_64 < 1) wid_64 = 1;43if (height < 1) height = 1;44int ext = (real_width - (wid_64 << 2)) << 1;45#if !defined(__GNUC__) && !defined(NO_ASM)46__asm {47mov esi,dword ptr [src]48mov edi,dword ptr [dst]4950mov ecx,dword ptr [height]51y_loop:52push ecx5354mov ecx,dword ptr [wid_64]55x_loop:56mov eax,dword ptr [esi] // read both pixels57add esi,458bswap eax59mov edx,eax6061ror ax,162ror eax,1663ror ax,16465mov dword ptr [edi],eax66add edi,46768// * copy69mov eax,dword ptr [esi] // read both pixels70add esi,471bswap eax72mov edx,eax7374ror ax,175ror eax,1676ror ax,17778mov dword ptr [edi],eax79add edi,480// *8182dec ecx83jnz x_loop8485pop ecx86dec ecx87jz end_y_loop88push ecx8990add esi,dword ptr [line]91add edi,dword ptr [ext]9293mov ecx,dword ptr [wid_64]94x_loop_2:95mov eax,dword ptr [esi+4] // read both pixels96bswap eax97mov edx,eax9899ror ax,1100ror eax,16101ror ax,1102103mov dword ptr [edi],eax104add edi,4105106// * copy107mov eax,dword ptr [esi] // read both pixels108add esi,8109bswap eax110mov edx,eax111112ror ax,1113ror eax,16114ror ax,1115116mov dword ptr [edi],eax117add edi,4118// *119120dec ecx121jnz x_loop_2122123add esi,dword ptr [line]124add edi,dword ptr [ext]125126pop ecx127dec ecx128jnz y_loop129130end_y_loop:131}132#elif !defined(NO_ASM)133//printf("Load16bRGBA\n");134long lTemp, lHeight = (long) height;135asm volatile (136"y_loop7: \n"137"mov %[c], %[temp] \n"138139"mov %[wid_64], %%ecx \n"140"x_loop7: \n"141"mov (%[src]), %%eax \n" // read both pixels142"add $4, %[src] \n"143"bswap %%eax \n"144"mov %%eax, %%edx \n"145146"ror $1, %%ax \n"147"ror $16, %%eax \n"148"ror $1, %%ax \n"149150"mov %%eax, (%[dst]) \n"151"add $4, %[dst] \n"152153// * copy154"mov (%[src]), %%eax \n" // read both pixels155"add $4, %[src] \n"156"bswap %%eax \n"157"mov %%eax, %%edx \n"158159"ror $1, %%ax \n"160"ror $16, %%eax \n"161"ror $1, %%ax \n"162163"mov %%eax, (%[dst]) \n"164"add $4, %[dst] \n"165// *166167"dec %%ecx \n"168"jnz x_loop7 \n"169170"mov %[temp], %[c] \n"171"dec %%ecx \n"172"jz end_y_loop7 \n"173"mov %[c], %[temp] \n"174175"add %[line], %[src] \n"176"add %[ext], %[dst] \n"177178"mov %[wid_64], %%ecx \n"179"x_loop_27: \n"180"mov 4(%[src]), %%eax \n" // read both pixels181"bswap %%eax \n"182"mov %%eax, %%edx \n"183184"ror $1, %%ax \n"185"ror $16, %%eax \n"186"ror $1, %%ax \n"187188"mov %%eax, (%[dst]) \n"189"add $4, %[dst] \n"190191// * copy192"mov (%[src]), %%eax \n" // read both pixels193"add $8, %[src] \n"194"bswap %%eax \n"195"mov %%eax, %%edx \n"196197"ror $1, %%ax \n"198"ror $16, %%eax \n"199"ror $1, %%ax \n"200201"mov %%eax, (%[dst]) \n"202"add $4, %[dst] \n"203// *204205"dec %%ecx \n"206"jnz x_loop_27 \n"207208"add %[line], %[src] \n"209"add %[ext], %[dst] \n"210211"mov %[temp], %[c] \n"212"dec %%ecx \n"213"jnz y_loop7 \n"214215"end_y_loop7: \n"216: [temp]"=m"(lTemp), [src]"+S"(src), [dst]"+D"(dst), [c]"+c"(lHeight)217: [wid_64] "g" (wid_64), [line] "g" ((uintptr_t)line), [ext] "g" ((uintptr_t)ext)218: "memory", "cc", "eax", "edx"219);220#endif221return (1 << 16) | GR_TEXFMT_ARGB_1555;222}223224//****************************************************************225// Size: 2, Format: 3226//227// ** by Gugaman/Dave2001 **228229DWORD Load16bIA (unsigned char * dst, unsigned char * src, int wid_64, int height, int line, int real_width, int tile)230{231if (wid_64 < 1) wid_64 = 1;232if (height < 1) height = 1;233int ext = (real_width - (wid_64 << 2)) << 1;234#if !defined(__GNUC__) && !defined(NO_ASM)235__asm {236mov esi,dword ptr [src]237mov edi,dword ptr [dst]238239mov ecx,dword ptr [height]240y_loop:241push ecx242243mov ecx,dword ptr [wid_64]244x_loop:245mov eax,dword ptr [esi] // read both pixels246add esi,4247mov dword ptr [edi],eax248add edi,4249250// * copy251mov eax,dword ptr [esi] // read both pixels252add esi,4253mov dword ptr [edi],eax254add edi,4255// *256257dec ecx258jnz x_loop259260pop ecx261dec ecx262jz end_y_loop263push ecx264265add esi,dword ptr [line]266add edi,dword ptr [ext]267268mov ecx,dword ptr [wid_64]269x_loop_2:270mov eax,dword ptr [esi+4] // read both pixels271mov dword ptr [edi],eax272add edi,4273274// * copy275mov eax,dword ptr [esi] // read both pixels276add esi,8277mov dword ptr [edi],eax278add edi,4279// *280281dec ecx282jnz x_loop_2283284add esi,dword ptr [line]285add edi,dword ptr [ext]286287pop ecx288dec ecx289jnz y_loop290291end_y_loop:292}293#elif !defined(NO_ASM)294//printf("Load16bIA\n");295long lTemp, lHeight = (long) height;296asm volatile (297"y_loop8: \n"298"mov %[c], %[temp] \n"299300"mov %[wid_64], %%ecx \n"301"x_loop8: \n"302"mov (%[src]), %%eax \n" // read both pixels303"add $4, %[src] \n"304"mov %%eax, (%[dst]) \n"305"add $4, %[dst] \n"306307// * copy308"mov (%[src]), %%eax \n" // read both pixels309"add $4, %[src] \n"310"mov %%eax, (%[dst]) \n"311"add $4, %[dst] \n"312// *313314"dec %%ecx \n"315"jnz x_loop8 \n"316317"mov %[temp], %[c] \n"318"dec %%ecx \n"319"jz end_y_loop8 \n"320"mov %[c], %[temp] \n"321322"add %[line], %[src] \n"323"add %[ext], %[dst] \n"324325"mov %[wid_64], %%ecx \n"326"x_loop_28: \n"327"mov 4(%[src]), %%eax \n" // read both pixels328"mov %%eax, (%[dst]) \n"329"add $4, %[dst] \n"330331// * copy332"mov (%[src]), %%eax \n" // read both pixels333"add $8, %[src] \n"334"mov %%eax, (%[dst]) \n"335"add $4, %[dst] \n"336// *337338"dec %%ecx \n"339"jnz x_loop_28 \n"340341"add %[line], %[src] \n"342"add %[ext], %[dst] \n"343344"mov %[temp], %[c] \n"345"dec %%ecx \n"346"jnz y_loop8 \n"347348"end_y_loop8: \n"349: [temp]"=m"(lTemp), [src]"+S"(src), [dst]"+D"(dst), [c]"+c"(lHeight)350: [wid_64] "g" (wid_64), [line] "g" ((uintptr_t)line), [ext] "g" ((uintptr_t)ext)351: "memory", "cc", "eax"352);353#endif354return (1 << 16) | GR_TEXFMT_ALPHA_INTENSITY_88;355}356357358359