From 1210a9008eab4ef117c13c3c487a75107905c624 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 26 Aug 2008 02:35:58 +0000 Subject: [PATCH] more bugfixes and a very useful workaround for windows OGLRender.c --- desmume/src/NDSSystem.c | 36 +- desmume/src/windows/OGLRender.c | 939 +++++++++++++++----------------- 2 files changed, 462 insertions(+), 513 deletions(-) diff --git a/desmume/src/NDSSystem.c b/desmume/src/NDSSystem.c index c617ec29c..db905f9b1 100644 --- a/desmume/src/NDSSystem.c +++ b/desmume/src/NDSSystem.c @@ -181,7 +181,6 @@ void NDS_DeInit(void) { SPU_DeInit(); Screen_DeInit(); MMU_DeInit(); - NDS_3D_Close(); } BOOL NDS_SetROM(u8 * rom, u32 mask) @@ -534,7 +533,6 @@ void NDS_Reset( void) GPU_Reset(MainScreen.gpu, 0); GPU_Reset(SubScreen.gpu, 1); - NDS_3D_Reset(); SPU_Reset(); execute = oldexecute; @@ -588,6 +586,40 @@ typedef struct } bmpfileheader_struct; #endif +int NDS_WriteBMP_32bppBuffer(int width, int height, const void* buf, const char *filename) +{ + bmpfileheader_struct fileheader; + bmpimgheader_struct imageheader; + FILE *file; + int i,j,k; + u16 * bmp = (u16 *)GPU_screen; + + memset(&fileheader, 0, sizeof(fileheader)); + fileheader.size = sizeof(fileheader); + fileheader.id = 'B' | ('M' << 8); + fileheader.imgoffset = sizeof(fileheader)+sizeof(imageheader); + + memset(&imageheader, 0, sizeof(imageheader)); + imageheader.size = sizeof(imageheader); + imageheader.width = width; + imageheader.height = height; + imageheader.planes = 1; + imageheader.bpp = 32; + imageheader.cmptype = 0; // None + imageheader.imgsize = imageheader.width * imageheader.height * 4; + + if ((file = fopen(filename,"wb")) == NULL) + return 0; + + fwrite(&fileheader, 1, sizeof(fileheader), file); + fwrite(&imageheader, 1, sizeof(imageheader), file); + + fwrite(buf,1,imageheader.imgsize,file); + fclose(file); + + return 1; +} + int NDS_WriteBMP(const char *filename) { bmpfileheader_struct fileheader; diff --git a/desmume/src/windows/OGLRender.c b/desmume/src/windows/OGLRender.c index 0e3cc69be..91ac5bb1a 100644 --- a/desmume/src/windows/OGLRender.c +++ b/desmume/src/windows/OGLRender.c @@ -29,7 +29,7 @@ #include #include #else - #define __forceinline + #define __forceinline #include #include #endif @@ -90,7 +90,10 @@ static unsigned int depthFuncMode=0; static unsigned int lightMask=0; static unsigned int envMode=0; static unsigned int cullingMask=0; -static unsigned char texMAP[1024*2048*4]; +static unsigned int oglTextureID=0; +static unsigned char texMAP[1024*2048*4], texMAP2[2048*2048*4]; +static float invTexWidth = 1.f; +static float invTexHeight = 1.f; static float fogColor[4] = {0.f}; static float fogOffset = 0.f; static float alphaTestRef = 0.01f; @@ -102,46 +105,21 @@ static unsigned long clInd2 = 0; static int alphaDepthWrite = 0; static int colorRGB[4] = { 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; static int texCoordinateTransform = 0; -static int _t=0, _s=0; +static int t=0, s=0; static char beginCalled = 0; static unsigned int vtxFormat; -static unsigned int old_vtxFormat; static unsigned int textureFormat=0, texturePalette=0; +static unsigned int lastTextureFormat=0, lastTexturePalette=0; +static unsigned int textureMode=0; +static u32 sizeX = 1; +static u32 sizeY = 1; +static u8 currentIDtexture=0; static int diffuse[4] = {0}, ambient[4] = {0}, specular[4] = {0}, emission[4] = {0}; -//================================================= Textures -#define MAX_TEXTURE 500 -typedef struct -{ - GLenum id; - unsigned int frm; - unsigned int mode; - unsigned int numcolors; - unsigned int pal; - unsigned int sizeX; - unsigned int sizeY; - int coord; - unsigned int texenv; - float invSizeX; - float invSizeY; - unsigned char texture[128*1024]; // 128Kb texture slot - -} TextureCache; - -TextureCache texcache[MAX_TEXTURE+1]; -u32 texcache_count; - -u32 texcache_start; -u32 texcache_stop; -//u32 texcache_last; - -GLenum oglTempTextureID[MAX_TEXTURE]; -//================================================= - typedef struct { unsigned int color; // Color in hardware format @@ -214,6 +192,9 @@ char NDS_glInit(void) else printlog("OpenGL mode: uknown\n"); #endif + + currentIDtexture=0; + glClearColor (0.f, 0.f, 0.f, 1.f); glColor3f (1.f, 1.f, 1.f); @@ -224,9 +205,10 @@ char NDS_glInit(void) glAlphaFunc (GL_GREATER, 0.1f); glEnable (GL_ALPHA_TEST); - glGenTextures (MAX_TEXTURE, &oglTempTextureID[0]); + glGenTextures (1, (GLuint*)&oglTextureID); glViewport(0, 0, 256, 192); + if (glGetError() != GL_NO_ERROR) return 0; @@ -269,23 +251,7 @@ char NDS_glInit(void) return 1; } -__forceinline void NDS_3D_Reset() -{ - int i; - - memset(&texcache,0,sizeof(texcache)); - texcache_count=0; - for (i = 0; i < MAX_TEXTURE; i++) - texcache[i].id=oglTempTextureID[i]; - texcache_start=0; - texcache_stop=MAX_TEXTURE<<1; -} - -__forceinline void NDS_3D_Close() -{ -} - -__forceinline void SetMaterialAlpha (int alphaValue) +void SetMaterialAlpha (int alphaValue) { diffuse[3] = alphaValue; ambient[3] = alphaValue; @@ -299,18 +265,18 @@ __forceinline void SetMaterialAlpha (int alphaValue) glMaterialiv (GL_FRONT_AND_BACK, GL_EMISSION, emission); } -__forceinline void NDS_glViewPort(unsigned long v) +void NDS_glViewPort(unsigned long v) { if(beginCalled) glEnd(); - glViewport( (v&0xFF), ((v>>8)&0xFF), ((v>>16)&0xFF), ((v>>24)&0xFF)); + glViewport( (v&0xFF), ((v>>8)&0xFF), ((v>>16)&0xFF)+1, (v>>24)+1); if(beginCalled) glBegin(vtxFormat); } -__forceinline void NDS_glClearColor(unsigned long v) +void NDS_glClearColor(unsigned long v) { if(beginCalled) glEnd(); @@ -324,7 +290,7 @@ __forceinline void NDS_glClearColor(unsigned long v) glBegin(vtxFormat); } -__forceinline void NDS_glFogColor(unsigned long v) +void NDS_glFogColor(unsigned long v) { fogColor[0] = ((float)((v )&0x1F))/31.0f; fogColor[1] = ((float)((v>> 5)&0x1F))/31.0f; @@ -332,12 +298,12 @@ __forceinline void NDS_glFogColor(unsigned long v) fogColor[3] = ((float)((v>>16)&0x1F))/31.0f; } -__forceinline void NDS_glFogOffset (unsigned long v) +void NDS_glFogOffset (unsigned long v) { fogOffset = (float)(v&0xffff); } -__forceinline void NDS_glClDepth() +void NDS_glClDepth() { if(beginCalled) glEnd(); @@ -348,7 +314,7 @@ __forceinline void NDS_glClDepth() glBegin(vtxFormat); } -__forceinline void NDS_glClearDepth(unsigned long v) +void NDS_glClearDepth(unsigned long v) { u32 depth24b; @@ -356,15 +322,16 @@ __forceinline void NDS_glClearDepth(unsigned long v) glEnd(); v &= 0x7FFFF; - // Thanks for NHerve - depth24b = (v*0x200)+((v+1)/0x8000)*0x01FF; - glClearDepth(depth24b / ((float)(1<<24))); + depth24b = (v*0x200)+((v+1)/0x8000); + + // Using 23 instead of 24 fixes SM 64 DS + glClearDepth(depth24b / ((float)(1<<23))); if(beginCalled) glBegin(vtxFormat); } -__forceinline void NDS_glMatrixMode(unsigned long v) +void NDS_glMatrixMode(unsigned long v) { if (beginCalled) { @@ -379,7 +346,7 @@ __forceinline void NDS_glMatrixMode(unsigned long v) } } -__forceinline void SetMatrix (void) +void SetMatrix (void) { if (mode < 2) { @@ -401,7 +368,7 @@ __forceinline void SetMatrix (void) } } -__forceinline void NDS_glLoadIdentity (void) +void NDS_glLoadIdentity (void) { MatrixIdentity (mtxCurrent[mode]); @@ -409,7 +376,7 @@ __forceinline void NDS_glLoadIdentity (void) MatrixIdentity (mtxCurrent[1]); } -__forceinline void NDS_glLoadMatrix4x4(signed long v) +void NDS_glLoadMatrix4x4(signed long v) { mtxCurrent[mode][ML4x4ind] = fix2float(v); @@ -422,7 +389,7 @@ __forceinline void NDS_glLoadMatrix4x4(signed long v) ML4x4ind = 0; } -__forceinline void NDS_glLoadMatrix4x3(signed long v) +void NDS_glLoadMatrix4x3(signed long v) { mtxCurrent[mode][(ML4x3_l<<2)+ML4x3_c] = fix2float(v); @@ -438,7 +405,7 @@ __forceinline void NDS_glLoadMatrix4x3(signed long v) MatrixCopy (mtxCurrent[1], mtxCurrent[2]); } -__forceinline void NDS_glStoreMatrix(unsigned long v) +void NDS_glStoreMatrix(unsigned long v) { //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode short mymode = (mode==1?2:mode); @@ -452,7 +419,7 @@ __forceinline void NDS_glStoreMatrix(unsigned long v) MatrixStackLoadMatrix (&mtxStack[1], v&31, mtxCurrent[1]); } -__forceinline void NDS_glRestoreMatrix(unsigned long v) +void NDS_glRestoreMatrix(unsigned long v) { //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode short mymode = (mode==1?2:mode); @@ -466,9 +433,9 @@ __forceinline void NDS_glRestoreMatrix(unsigned long v) MatrixCopy (mtxCurrent[1], MatrixStackGetPos(&mtxStack[1], v&31)); } -__forceinline void NDS_glPushMatrix (void) +void NDS_glPushMatrix (void) { - //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode + //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode short mymode = (mode==1?2:mode); MatrixStackPushMatrix (&mtxStack[mymode], mtxCurrent[mymode]); @@ -476,7 +443,7 @@ __forceinline void NDS_glPushMatrix (void) MatrixStackPushMatrix (&mtxStack[1], mtxCurrent[1]); } -__forceinline void NDS_glPopMatrix(signed long i) +void NDS_glPopMatrix(signed long i) { //this command always works on both pos and vector when either pos or pos-vector are the current mtx mode short mymode = (mode==1?2:mode); @@ -487,7 +454,7 @@ __forceinline void NDS_glPopMatrix(signed long i) MatrixCopy (mtxCurrent[1], MatrixStackPopMatrix (&mtxStack[1], i)); } -__forceinline void NDS_glTranslate(signed long v) +void NDS_glTranslate(signed long v) { trans[transind] = fix2float(v); @@ -504,7 +471,7 @@ __forceinline void NDS_glTranslate(signed long v) MatrixTranslate (mtxCurrent[1], trans); } -__forceinline void NDS_glScale(signed long v) +void NDS_glScale(signed long v) { short mymode = (mode==2?1:mode); @@ -526,7 +493,7 @@ __forceinline void NDS_glScale(signed long v) // MatrixScale (mtxCurrent[1], scale); } -__forceinline void NDS_glMultMatrix3x3(signed long v) +void NDS_glMultMatrix3x3(signed long v) { mtxTemporal[(MM3x3_l<<2)+MM3x3_c] = fix2float(v); @@ -546,7 +513,7 @@ __forceinline void NDS_glMultMatrix3x3(signed long v) MatrixIdentity (mtxTemporal); } -__forceinline void NDS_glMultMatrix4x3(signed long v) +void NDS_glMultMatrix4x3(signed long v) { mtxTemporal[(MM4x3_l<<2)+MM4x3_c] = fix2float(v); @@ -565,7 +532,7 @@ __forceinline void NDS_glMultMatrix4x3(signed long v) MatrixIdentity (mtxTemporal); } -__forceinline void NDS_glMultMatrix4x4(signed long v) +void NDS_glMultMatrix4x4(signed long v) { mtxTemporal[MM4x4ind] = fix2float(v); @@ -581,394 +548,340 @@ __forceinline void NDS_glMultMatrix4x4(signed long v) MatrixIdentity (mtxTemporal); } +//zero 8/25/08 - i dont like this +//#define CHECKSLOT txt_slot_current_size--;\ +// if (txt_slot_current_size<=0)\ +// {\ +// txt_slot_current++;\ +// *adr=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current];\ +// adr-=txt_slot_size;\ +// txt_slot_size=txt_slot_current_size=0x020000;\ +// } + #define CHECKSLOT txt_slot_current_size--;\ if (txt_slot_current_size<=0)\ {\ txt_slot_current++;\ - adr=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current];\ - adr-=txt_slot_size;\ + *adr=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current];\ txt_slot_size=txt_slot_current_size=0x020000;\ } + //#define CHECKSLOT ; #define RGB16TO32(col,alpha) (((alpha)<<24) | ((((col) & 0x7C00)>>7)<<16) | ((((col) & 0x3E0)>>2)<<8) | (((col) & 0x1F)<<3)) -__forceinline void* memcpy_fast(void* dest, const void* src, size_t count) +__forceinline void SetupTexture (unsigned int format, unsigned int palette) { - size_t blockCnt = count / 64; - size_t remainder = count % 64; - - __asm - { - mov esi, [src] - mov edi, [dest] - mov ecx, [blockCnt] - - test ecx, ecx - jz copy_remainder - - copyloop: - //prefetchnta [esi] - mov eax, [esi] - - movq mm0, qword ptr [esi] - movq mm1, qword ptr [esi+8] - movq mm2, qword ptr [esi+16] - movq mm3, qword ptr [esi+24] - movq mm4, qword ptr [esi+32] - movq mm5, qword ptr [esi+40] - movq mm6, qword ptr [esi+48] - movq mm7, qword ptr [esi+56] - movntq qword ptr [edi], mm0 - movntq qword ptr [edi+8], mm1 - movntq qword ptr [edi+16], mm2 - movntq qword ptr [edi+24], mm3 - movntq qword ptr [edi+32], mm4 - movntq qword ptr [edi+40], mm5 - movntq qword ptr [edi+48], mm6 - movntq qword ptr [edi+56], mm7 - - add edi, 64 - add esi, 64 - dec ecx - jnz copyloop - - sfence - emms - - copy_remainder: - - mov ecx, remainder - rep movsb - } - - return dest; -} -//================================================================================ -__forceinline void setTexture(unsigned int format, unsigned int texpal) -{ - int palSize[7]={32,4,16,256,0,8,32768}; - int i=0; - unsigned int x=0, y=0; - unsigned int palZeroTransparent; - unsigned short *pal = NULL; - unsigned char *dst = texMAP; - unsigned int sizeX=(8 << ((format>>20)&0x07)); - unsigned int sizeY=(8 << ((format>>23)&0x07)); unsigned int imageSize = sizeX*sizeY; - - u64 txt_slot_current_size; - u64 txt_slot_size; - u64 txt_slot_current; - unsigned char * adr; - - if (format==0) - { - texcache_count=-1; - return; - } - if ((format>>26)&0x07==0) - { - texcache_count=-1; - return; - } - - txt_slot_current=(format>>14)&0x03; - adr=(unsigned char *)(ARM9Mem.textureSlotAddr[txt_slot_current]+((format&0x3FFF)<<3)); + unsigned int paletteSize = 0; + unsigned int palZeroTransparent = (1-((format>>29)&1))*255; // shash: CONVERT THIS TO A TABLE :) + unsigned int x=0, y=0; + unsigned char * dst = texMAP; + u64 txt_slot_current_size=0x020000-((format & 0x3FFF)<<3); + u64 txt_slot_size=128*1024; //zero 8/25/08 - this was total garbage before I got here. this is at least reasonable.. + u64 txt_slot_current=(format>>14)&3; + unsigned char * adr = (unsigned char *)(ARM9Mem.textureSlotAddr[txt_slot_current]+((format&0x3FFF)<<3)); + //printlog("Format: %04X\n",(format >> 14 & 3)); + //printlog("Texture %08X: width=%d, height=%d\n", format, sizeX, sizeY); - i=texcache_start; - while (TRUE) + //printlog("Texture slot: %02X\n",(format >> 14 & 3)); + //printlog("Texture slot offset: %02X\n",(format&0x3FFF)<<3); + + textureMode = (unsigned short)((format>>26)&0x7); + + switch(textureMode) { - if (texcache_stop==i) break; - if (texcache[i].frm==0) break; - if ((texcache[i].frm==format)&&(texcache[i].pal==texpal)) + case 1: //a3i5 { - if (!memcmp(adr,texcache[i].texture,imageSize)) - { - texcache_count=i; - glBindTexture(GL_TEXTURE_2D,texcache[i].id); - return; - } + paletteSize = 256; + pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + break; } - i++; - if (i>MAX_TEXTURE) + case 2: //i2 { - texcache_stop=texcache_start; - texcache[texcache_stop].frm=0; - texcache_start++; - if (texcache_start>MAX_TEXTURE) - { - texcache_start=0; - texcache_stop=MAX_TEXTURE<<1; - } - i=0; + paletteSize = 4; + pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<3)); + imageSize >>= 2; + break; + } + case 3: //i4 + { + paletteSize = 16; + pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + imageSize >>= 1; + break; + } + case 4: //i8 + { + paletteSize = 256; + pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + break; + } + case 5: //4x4 + { + paletteSize = 0; + pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + break; + } + case 6: //a5i3 + { + paletteSize = 256; + pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + break; + } + case 7: //16bpp + { + paletteSize = 0; + break; } } - - glBindTexture(GL_TEXTURE_2D, texcache[i].id); - texcache[i].mode=(format>>26)&0x07; - texcache[i].pal=texpal; - texcache[i].sizeX=sizeX; - texcache[i].sizeY=sizeY; - texcache[i].coord=(format>>30); - texcache[i].invSizeX=1.0f/((float)sizeX*(1<<4)); - texcache[i].invSizeY=1.0f/((float)sizeY*(1<<4)); - texcache[i].texenv=envMode; - //memcpy(texcache[i].texture,adr,imageSize); //======================= copy - memcpy_fast(texcache[i].texture,adr,imageSize); //======================= copy - texcache[i].numcolors=palSize[texcache[i].mode]; - - texcache[i].frm=format; - - //printlog("Texture %03i - format=%08X; pal=%04X (mode %X, width %04i, height %04i)\n",i, texcache[i].frm, texcache[i].pal, texcache[i].mode, sizeX, sizeY); - //============================================================================ Texture render - palZeroTransparent = (1-((format>>29)&1))*255; // shash: CONVERT THIS TO A TABLE :) - txt_slot_size=(txt_slot_current_size=0x020000-((format & 0x3FFF)<<3)); - - switch (texcache[i].mode) + //printlog("Texture mode %02i: x=%04d, colors=%04X, index=%04d\n",mode,x,pal[adr[x]],adr[x]); + switch(textureMode) + { + case 1: { - case 1: + for(x = 0; x < imageSize; x++, dst += 4) { - pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); - for(x = 0; x < imageSize; x++, dst += 4) - { - unsigned short c = pal[adr[x]&31], alpha = (adr[x]>>5); - dst[0] = (unsigned char)((c & 0x1F)<<3); - dst[1] = (unsigned char)((c & 0x3E0)>>2); - dst[2] = (unsigned char)((c & 0x7C00)>>7); - dst[3] = ((alpha<<2)+(alpha>>1))<<3; - CHECKSLOT; - } - break; + unsigned short c = pal[adr[x]&31], alpha = (adr[x]>>5); + dst[0] = (unsigned char)((c & 0x1F)<<3); + dst[1] = (unsigned char)((c & 0x3E0)>>2); + dst[2] = (unsigned char)((c & 0x7C00)>>7); + dst[3] = ((alpha<<2)+(alpha>>1))<<3; + CHECKSLOT; } - case 2: + break; + } + case 2: + { + for(x = 0; x < imageSize; ++x) { - pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<3)); - for(x = 0; x < imageSize>>2; ++x) - { - unsigned short c = pal[(adr[x])&0x3]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = ((adr[x]&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; - dst += 4; + unsigned short c = pal[(adr[x])&0x3]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = ((adr[x]&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; + dst += 4; - c = pal[((adr[x])>>2)&0x3]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = (((adr[x]>>2)&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; - dst += 4; + c = pal[((adr[x])>>2)&0x3]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = (((adr[x]>>2)&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; + dst += 4; - c = pal[((adr[x])>>4)&0x3]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = (((adr[x]>>4)&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; - dst += 4; + c = pal[((adr[x])>>4)&0x3]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = (((adr[x]>>4)&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; + dst += 4; - c = pal[(adr[x])>>6]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = (((adr[x]>>6)&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; - dst += 4; - CHECKSLOT; - } - break; + c = pal[(adr[x])>>6]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = (((adr[x]>>6)&3) == 0) ? palZeroTransparent : 255;//(c>>15)*255; + dst += 4; + CHECKSLOT; } - case 3: - { - pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); - for(x = 0; x < (imageSize>>1); x++) - { - unsigned short c = pal[adr[x]&0xF]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = (((adr[x])&0xF) == 0) ? palZeroTransparent : 255;//(c>>15)*255; - dst += 4; - - c = pal[((adr[x])>>4)]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = (((adr[x]>>4)&0xF) == 0) ? palZeroTransparent : 255;//(c>>15)*255; - dst += 4; - CHECKSLOT; - } - break; - } - case 4: - { - pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); - for(x = 0; x < imageSize; ++x) - { - unsigned short c = pal[adr[x]]; - dst[0] = (unsigned char)((c & 0x1F)<<3); - dst[1] = (unsigned char)((c & 0x3E0)>>2); - dst[2] = (unsigned char)((c & 0x7C00)>>7); - dst[3] = (adr[x] == 0) ? palZeroTransparent : 255; - dst += 4; - CHECKSLOT; - } - } - break; - case 5: + break; + } + + case 3: + { + for(x = 0; x < imageSize; x++) { - unsigned short * pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); - unsigned short * slot1; - unsigned int * map = (unsigned int *)adr; - unsigned d = 0; - unsigned int * dst = (unsigned int *)texMAP; - if ( (texcache[i].frm & 0xc000) == 0x8000) - // texel are in slot 2 - slot1=(const unsigned short*)&ARM9Mem.textureSlotAddr[1][((texcache[i].frm&0x3FFF)<<2)+0x010000]; - else - slot1=(const unsigned short*)&ARM9Mem.textureSlotAddr[1][(texcache[i].frm&0x3FFF)<<2]; + unsigned short c = pal[adr[x]&0xF]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = (((adr[x])&0xF) == 0) ? palZeroTransparent : 255;//(c>>15)*255; + dst += 4; - for (y = 0; y < (texcache[i].sizeY>>2); y ++) - { - u32 tmpPos[4]={(y<<2)*texcache[i].sizeX,((y<<2)+1)*texcache[i].sizeX, - ((y<<2)+2)*texcache[i].sizeX,((y<<2)+3)*texcache[i].sizeX}; - for (x = 0; x < (texcache[i].sizeX>>2); x ++, d++) + c = pal[((adr[x])>>4)]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = (((adr[x]>>4)&0xF) == 0) ? palZeroTransparent : 255;//(c>>15)*255; + dst += 4; + CHECKSLOT; + } + break; + } + + case 4: + { + //printlog("texture mode 4"); + for(x = 0; x < imageSize; ++x) + { + unsigned short c = pal[adr[x]]; + dst[0] = (unsigned char)((c & 0x1F)<<3); + dst[1] = (unsigned char)((c & 0x3E0)>>2); + dst[2] = (unsigned char)((c & 0x7C00)>>7); + dst[3] = (adr[x] == 0) ? palZeroTransparent : 255; + dst += 4; + CHECKSLOT; + } + break; + } + + case 5: + { + unsigned short * pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + unsigned short * slot1; + unsigned int * map = (unsigned int *)adr; + unsigned i = 0; + unsigned int * dst = (unsigned int *)texMAP; + if ( (format & 0xc000) == 0x8000) + // texel are in slot 2 + slot1=(const unsigned short*)&ARM9Mem.textureSlotAddr[1][((format&0x3FFF)<<2)+0x010000]; + else + slot1=(const unsigned short*)&ARM9Mem.textureSlotAddr[1][(format&0x3FFF)<<2]; + + for (y = 0; y < (sizeY>>2); y ++) + { + u32 tmpPos[4]={(y<<2)*sizeX,((y<<2)+1)*sizeX,((y<<2)+2)*sizeX,((y<<2)+3)*sizeX}; + for (x = 0; x < (sizeX>>2); x ++, i++) + { + u32 currBlock = map[i], sy; + u16 pal1 = slot1[i]; + u16 pal1offset = (pal1 & 0x3FFF)<<1; + u8 mode = pal1>>14; + u32 tmp_col[4]; + + tmp_col[0]=RGB16TO32(pal[pal1offset],255); + tmp_col[1]=RGB16TO32(pal[pal1offset+1],255); + + switch (mode) + { + case 0: + tmp_col[2]=RGB16TO32(pal[pal1offset+2],255); + tmp_col[3]=RGB16TO32(0x7FFF,0); + break; + case 1: + tmp_col[2]=(((tmp_col[0]&0xFF)+(tmp_col[1]&0xff))>>1)| + (((tmp_col[0]&(0xFF<<8))+(tmp_col[1]&(0xFF<<8)))>>1)| + (((tmp_col[0]&(0xFF<<16))+(tmp_col[1]&(0xFF<<16)))>>1)| + (0xff<<24); + tmp_col[3]=RGB16TO32(0x7FFF,0); + break; + case 2: + tmp_col[2]=RGB16TO32(pal[pal1offset+2],255); + tmp_col[3]=RGB16TO32(pal[pal1offset+3],255); + break; + case 3: { - u32 currBlock = map[d], sy; - u16 pal1 = slot1[d]; - u16 pal1offset = (pal1 & 0x3FFF)<<1; - u8 mode = pal1>>14; - u32 tmp_col[4]; + u32 red1, red2; + u32 green1, green2; + u32 blue1, blue2; + u16 tmp1, tmp2; - tmp_col[0]=RGB16TO32(pal[pal1offset],255); - tmp_col[1]=RGB16TO32(pal[pal1offset+1],255); + red1=tmp_col[0]&0xff; + green1=(tmp_col[0]>>8)&0xff; + blue1=(tmp_col[0]>>16)&0xff; + red2=tmp_col[1]&0xff; + green2=(tmp_col[1]>>8)&0xff; + blue2=(tmp_col[1]>>16)&0xff; - switch (mode) + tmp1=((red1*5+red2*3)>>6)| + (((green1*5+green2*3)>>6)<<5)| + (((blue1*5+blue2*3)>>6)<<10); + tmp2=((red2*5+red1*3)>>6)| + (((green2*5+green1*3)>>6)<<5)| + (((blue2*5+blue1*3)>>6)<<10); + + tmp_col[2]=RGB16TO32(tmp1,255); + tmp_col[3]=RGB16TO32(tmp2,255); + break; + } + } + for (sy = 0; sy < 4; sy++) { - case 0: - tmp_col[2]=RGB16TO32(pal[pal1offset+2],255); - tmp_col[3]=RGB16TO32(0x7FFF,0); - break; - case 1: - tmp_col[2]=(((tmp_col[0]&0xFF)+(tmp_col[1]&0xff))>>1)| - (((tmp_col[0]&(0xFF<<8))+(tmp_col[1]&(0xFF<<8)))>>1)| - (((tmp_col[0]&(0xFF<<16))+(tmp_col[1]&(0xFF<<16)))>>1)| - (0xff<<24); - tmp_col[3]=RGB16TO32(0x7FFF,0); - break; - case 2: - tmp_col[2]=RGB16TO32(pal[pal1offset+2],255); - tmp_col[3]=RGB16TO32(pal[pal1offset+3],255); - break; - case 3: + // Texture offset + u32 currentPos = (x<<2) + tmpPos[sy]; + u8 currRow = (u8)((currBlock>>(sy<<3))&0xFF); + + dst[currentPos] = tmp_col[currRow&3]; + dst[currentPos+1] = tmp_col[(currRow>>2)&3]; + dst[currentPos+2] = tmp_col[(currRow>>4)&3]; + dst[currentPos+3] = tmp_col[(currRow>>6)&3]; + //===================================== + txt_slot_current_size-=4;; + if (txt_slot_current_size<=0) { - u32 red1, red2; - u32 green1, green2; - u32 blue1, blue2; - u16 tmp1, tmp2; - - red1=tmp_col[0]&0xff; - green1=(tmp_col[0]>>8)&0xff; - blue1=(tmp_col[0]>>16)&0xff; - red2=tmp_col[1]&0xff; - green2=(tmp_col[1]>>8)&0xff; - blue2=(tmp_col[1]>>16)&0xff; - - tmp1=((red1*5+red2*3)>>6)| - (((green1*5+green2*3)>>6)<<5)| - (((blue1*5+blue2*3)>>6)<<10); - tmp2=((red2*5+red1*3)>>6)| - (((green2*5+green1*3)>>6)<<5)| - (((blue2*5+blue1*3)>>6)<<10); - - tmp_col[2]=RGB16TO32(tmp1,255); - tmp_col[3]=RGB16TO32(tmp2,255); - break; - } - } - for (sy = 0; sy < 4; sy++) - { - // Texture offset - u32 currentPos = (x<<2) + tmpPos[sy]; - u8 currRow = (u8)((currBlock>>(sy<<3))&0xFF); - - dst[currentPos] = tmp_col[currRow&3]; - dst[currentPos+1] = tmp_col[(currRow>>2)&3]; - dst[currentPos+2] = tmp_col[(currRow>>4)&3]; - dst[currentPos+3] = tmp_col[(currRow>>6)&3]; - - txt_slot_current_size-=4;; - if (txt_slot_current_size<=0) - { - txt_slot_current++; - *map=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current]; - map-=txt_slot_size>>2; - txt_slot_size=txt_slot_current_size=0x020000; - } + txt_slot_current++; + *map=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current]; + //map-=txt_slot_size>>2; //zero 8/25/08 - I dont understand this. it broke my game. + txt_slot_size=txt_slot_current_size=0x020000; } } } + } - break; - } - case 6: + //zero debug - dump tex4x4 to verify contents + /* { + int NDS_WriteBMP_32bppBuffer(int width, int height, const void* buf, const char *filename); + static int ctr = 0; + char fname[100]; + FILE* outf; + sprintf(fname,"c:\\dump\\%d.bmp", ctr); + ctr++; + NDS_WriteBMP_32bppBuffer(sizeX,sizeY,texMAP,fname); + }*/ + + break; + } + case 6: //a5i3 + { + unsigned int * dst = (unsigned int *)texMAP; + for(x = 0; x < imageSize; x++) { - pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); - for(x = 0; x < imageSize; x++) - { - unsigned short c = pal[adr[x]&0x07]; - dst[0] = (unsigned char)((c & 0x1F)<<3); - dst[1] = (unsigned char)((c & 0x3E0)>>2); - dst[2] = (unsigned char)((c & 0x7C00)>>7); - dst[3] = (adr[x]&0xF8); - dst += 4; - CHECKSLOT; - } - break; + unsigned short c = pal[adr[x]&0x07]; + /* *dst = A8R8G8B8TOARGB32(128,((c & 0x1F)<<3),((c & 0x3E0)>>2),((c & 0x7C00)>>7)); + dst++;*/ + /**dst = A8R8G8B8TOARGB32(128,255,128,128); + dst++; + */ + dst[0] = (unsigned char)((c & 0x1F)<<3); + dst[1] = (unsigned char)((c & 0x3E0)>>2); + dst[2] = (unsigned char)((c & 0x7C00)>>7); + dst[3] = (adr[x]&0xF8); + dst += 4; + CHECKSLOT; } - case 7: + break; + } + case 7: + { + unsigned short * map = ((unsigned short *)adr); + for(x = 0; x < imageSize; ++x) { - unsigned short * map = ((unsigned short *)adr); - pal = (unsigned short *)(ARM9Mem.texPalSlot[0] + (texturePalette<<4)); + unsigned short c = map[x]; + dst[0] = ((c & 0x1F)<<3); + dst[1] = ((c & 0x3E0)>>2); + dst[2] = ((c & 0x7C00)>>7); + dst[3] = (c>>15)*255; - for(x = 0; x < imageSize; ++x) + dst += 4; + txt_slot_current_size-=2;; + if (txt_slot_current_size<=0) { - unsigned short c = map[x]; - dst[0] = ((c & 0x1F)<<3); - dst[1] = ((c & 0x3E0)>>2); - dst[2] = ((c & 0x7C00)>>7); - dst[3] = (c>>15)*255; - - dst += 4; - txt_slot_current_size-=2;; - if (txt_slot_current_size<=0) - { - txt_slot_current++; - *map=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current]; - map-=txt_slot_size>>1; - txt_slot_size=txt_slot_current_size=0x020000; - } + txt_slot_current++; + *map=(unsigned char *)ARM9Mem.textureSlotAddr[txt_slot_current]; + map-=txt_slot_size>>1; + txt_slot_size=txt_slot_current_size=0x020000; } - break; } + break; + } } - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, - texcache[i].sizeX, texcache[i].sizeY, 0, - GL_RGBA, GL_UNSIGNED_BYTE, texMAP); - //============================================================================================ - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texEnv[texcache[i].texenv]); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (BIT16(texcache[i].frm) ? (BIT18(texcache[i].frm)?GL_MIRRORED_REPEAT:GL_REPEAT) : GL_CLAMP)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (BIT17(texcache[i].frm) ? (BIT18(texcache[i].frm)?GL_MIRRORED_REPEAT:GL_REPEAT) : GL_CLAMP)); - texcache_count=i; } -__forceinline void NDS_glBegin(unsigned long v) +void NDS_glBegin(unsigned long v) { - u32 tmp=0; + int enableDepthWrite = 1; if (beginCalled) { @@ -979,10 +892,10 @@ __forceinline void NDS_glBegin(unsigned long v) if (lightMask) { glEnable (GL_LIGHTING); - (lightMask&0x01)?glEnable (GL_LIGHT0):glDisable(GL_LIGHT0); - (lightMask&0x02)?glEnable (GL_LIGHT1):glDisable(GL_LIGHT1); - (lightMask&0x04)?glEnable (GL_LIGHT2):glDisable(GL_LIGHT2); - (lightMask&0x08)?glEnable (GL_LIGHT3):glDisable(GL_LIGHT3); + (lightMask&1)?glEnable (GL_LIGHT0):glDisable(GL_LIGHT0); + (lightMask&2)?glEnable (GL_LIGHT1):glDisable(GL_LIGHT1); + (lightMask&4)?glEnable (GL_LIGHT2):glDisable(GL_LIGHT2); + (lightMask&8)?glEnable (GL_LIGHT3):glDisable(GL_LIGHT3); } else glDisable (GL_LIGHTING); @@ -1013,6 +926,10 @@ __forceinline void NDS_glBegin(unsigned long v) colorRGB[3] = colorAlpha; glColor4iv ((GLint*)colorRGB); } + + //non-31 alpha polys are translucent + if(colorAlpha != 0x7C000000) + enableDepthWrite = alphaDepthWrite; } else { @@ -1021,29 +938,62 @@ __forceinline void NDS_glBegin(unsigned long v) } // texture environment - setTexture(textureFormat, texturePalette); - //================= - if (texcache_count!=-1) + //printlog("textureFormat=%i\n",((textureFormat>>26)&0x07)); + if (((textureFormat>>26)&0x07)!=0) { - texCoordinateTransform = texcache[texcache_count].coord; + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, envMode); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, oglTextureID); + + if (textureFormat != lastTextureFormat || texturePalette != lastTexturePalette) + { + sizeX = (1<<(((textureFormat>>20)&0x7)+3)); + sizeY = (1<<(((textureFormat>>23)&0x7)+3)); + SetupTexture (textureFormat, texturePalette); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, texMAP); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + // S Coordinate options + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (BIT16(textureFormat) ? (BIT18(textureFormat)?GL_MIRRORED_REPEAT:GL_REPEAT) : GL_CLAMP)); + // T Coordinate options + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (BIT17(textureFormat) ? (BIT18(textureFormat)?GL_MIRRORED_REPEAT:GL_REPEAT) : GL_CLAMP)); + lastTextureFormat = textureFormat; + lastTexturePalette = texturePalette; + + texCoordinateTransform = (textureFormat>>30); + invTexWidth = 1.0f/((float)sizeX*(1<<4)); + invTexHeight = 1.0f/((float)sizeY*(1<<4)); + } glMatrixMode (GL_TEXTURE); glLoadIdentity (); - glScaled (texcache[texcache_count].invSizeX, texcache[texcache_count].invSizeY, 1.0f); + glScaled (invTexWidth, invTexHeight, 1.0f); } - glMatrixMode(GL_PROJECTION); + //a5i3 or a3i5 textures are translucent + alphaDepthWrite = 0; //zero - as a hack, we are never going to write depth buffer for alpha values + //this is the best we can do right now until we can sort and display translucent polys last like we're supposed to + //(here is a sample case which illustrates the problem) + //1. draw something opaque in the distance + //2. draw something translucent in the foreground + //3. draw something opaque in the middle ground + if(textureMode ==1 || textureMode == 6) + enableDepthWrite = alphaDepthWrite; + + glDepthMask(enableDepthWrite?GL_TRUE:GL_FALSE); + + glMatrixMode (GL_PROJECTION); glLoadMatrixf(mtxCurrent[0]); - glMatrixMode(GL_MODELVIEW); + + glMatrixMode (GL_MODELVIEW); glLoadIdentity(); - beginCalled = 1; - vtxFormat = polyType[v&0x03]; + vtxFormat = polyType[v&3]; glBegin(vtxFormat); } -__forceinline void NDS_glEnd (void) +void NDS_glEnd (void) { if (beginCalled) { @@ -1052,7 +1002,7 @@ __forceinline void NDS_glEnd (void) } } -__forceinline void NDS_glColor3b(unsigned long v) +void NDS_glColor3b(unsigned long v) { colorRGB[0] = (v&0x1F) << 26; colorRGB[1] = ((v>>5)&0x1F) << 26; @@ -1060,7 +1010,7 @@ __forceinline void NDS_glColor3b(unsigned long v) glColor4iv ((GLint*)colorRGB); } -static __forceinline void SetVertex() +static __inline void SetVertex() { __declspec(align(16)) float coordTransformed[3] = { coord[0], coord[1], coord[2] }; @@ -1068,23 +1018,25 @@ static __forceinline void SetVertex() { float s2 =((coord[0]*mtxCurrent[3][0] + coord[1]*mtxCurrent[3][4] + - coord[2]*mtxCurrent[3][8]) + _s); + coord[2]*mtxCurrent[3][8]) + s); float t2 =((coord[0]*mtxCurrent[3][1] + coord[1]*mtxCurrent[3][5] + - coord[2]*mtxCurrent[3][9]) + _t); + coord[2]*mtxCurrent[3][9]) + t); glTexCoord2f (s2, t2); - //return; } MatrixMultVec4x4 (mtxCurrent[1], coordTransformed); glVertex3fv (coordTransformed); + + //zero - helpful in making sure vertex colors or lighting arent broken + //glColor3ub(rand()&255,rand()&255,rand()&255); numVertex++; } -__forceinline void NDS_glVertex16b(unsigned int v) +void NDS_glVertex16b(unsigned int v) { if(coordind==0) { @@ -1101,7 +1053,7 @@ __forceinline void NDS_glVertex16b(unsigned int v) SetVertex (); } -__forceinline void NDS_glVertex10b(unsigned long v) +void NDS_glVertex10b(unsigned long v) { coord[0] = float10Table[v&1023]; coord[1] = float10Table[(v>>10)&1023]; @@ -1110,7 +1062,7 @@ __forceinline void NDS_glVertex10b(unsigned long v) SetVertex (); } -__forceinline void NDS_glVertex3_cord(unsigned int one, unsigned int two, unsigned int v) +void NDS_glVertex3_cord(unsigned int one, unsigned int two, unsigned int v) { coord[one] = float16table[v&0xffff]; coord[two] = float16table[v>>16]; @@ -1118,7 +1070,7 @@ __forceinline void NDS_glVertex3_cord(unsigned int one, unsigned int two, unsign SetVertex (); } -__forceinline void NDS_glVertex_rel(unsigned long v) +void NDS_glVertex_rel(unsigned long v) { coord[0] += float10RelTable[v&1023]; coord[1] += float10RelTable[(v>>10)&1023]; @@ -1128,25 +1080,25 @@ __forceinline void NDS_glVertex_rel(unsigned long v) } // Ignored for now -__forceinline void NDS_glSwapScreen(unsigned int screen) +void NDS_glSwapScreen(unsigned int screen) { } // THIS IS A HACK :D -__forceinline int NDS_glGetNumPolys (void) +int NDS_glGetNumPolys (void) { return numVertex/3; } -__forceinline int NDS_glGetNumVertex (void) +int NDS_glGetNumVertex (void) { return numVertex; } -__forceinline void NDS_glGetLine (int line, unsigned short * dst) +void NDS_glGetLine (int line, unsigned short * dst) { - int i, t; + int i; u8 *screen3D = (u8 *)&GPU_screen3D [(192-(line%192))*768]; float *screen3Ddepth = &GPU_screen3Ddepth [(192-(line%192))*256]; u32 r,g,b; @@ -1165,7 +1117,7 @@ __forceinline void NDS_glGetLine (int line, unsigned short * dst) } } -__forceinline void NDS_glFlush(unsigned long v) +void NDS_glFlush(unsigned long v) { if (beginCalled) { @@ -1190,15 +1142,13 @@ __forceinline void NDS_glFlush(unsigned long v) glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } -__forceinline void NDS_glPolygonAttrib (unsigned long val) +void NDS_glPolygonAttrib (unsigned long val) { - // Light enable/disable lightMask = (val&0xF); // texture environment - //envMode = texEnv[(val&0x30)>>4]; - envMode = (val&0x30)>>4; + envMode = texEnv[(val&0x30)>>4]; // overwrite depth on alpha pass alphaDepthWrite = BIT11(val); @@ -1211,7 +1161,6 @@ __forceinline void NDS_glPolygonAttrib (unsigned long val) // Alpha value, actually not well handled, 0 should be wireframe colorAlpha = ((val>>16)&0x1F)<<26; - //printlog("PolygonID=%i;\n",val>>24); } /* @@ -1223,7 +1172,7 @@ __forceinline void NDS_glPolygonAttrib (unsigned long val) 21-25 Ambient Reflection Green 26-30 Ambient Reflection Blue */ -__forceinline void NDS_glMaterial0 (unsigned long val) +void NDS_glMaterial0 (unsigned long val) { diffuse[0] = ((val&0x1F) << 26) | 0x03FFFFFF; diffuse[1] = (((val>>5)&0x1F) << 26) | 0x03FFFFFF; @@ -1256,7 +1205,7 @@ __forceinline void NDS_glMaterial0 (unsigned long val) } } -__forceinline void NDS_glMaterial1 (unsigned long val) +void NDS_glMaterial1 (unsigned long val) { specular[0] = ((val&0x1F) << 26) | 0x03FFFFFF; specular[1] = (((val>>5)&0x1F) << 26) | 0x03FFFFFF; @@ -1282,41 +1231,42 @@ __forceinline void NDS_glMaterial1 (unsigned long val) } } -__forceinline void NDS_glShininess (unsigned long val) +void NDS_glShininess (unsigned long val) { - //printlog("Shininess=%i\n",val); } -__forceinline void NDS_glTexImage(unsigned long val) +void NDS_glTexImage(unsigned long val) { textureFormat = val; } -__forceinline void NDS_glTexPalette(unsigned long val) +void NDS_glTexPalette(unsigned long val) { texturePalette = val; } -__forceinline void NDS_glTexCoord(unsigned long val) +void NDS_glTexCoord(unsigned long val) { - _t = (s16)(val>>16); - _s = (s16)(val&0xFFFF); + t = (s16)(val>>16); + s = (s16)(val&0xFFFF); if (texCoordinateTransform == 1) { float s2, t2; - s2 =_s*mtxCurrent[3][0] + _t*mtxCurrent[3][4] + + s2 =s*mtxCurrent[3][0] + t*mtxCurrent[3][4] + 0.0625f*mtxCurrent[3][8] + 0.0625f*mtxCurrent[3][12]; - t2 =_s*mtxCurrent[3][1] + _t*mtxCurrent[3][5] + + t2 =s*mtxCurrent[3][1] + t* mtxCurrent[3][5] + 0.0625f*mtxCurrent[3][9] + 0.0625f*mtxCurrent[3][13]; glTexCoord2f (s2, t2); - return; } - glTexCoord2f (_s, _t); + else + { + glTexCoord2f (s, t); + } } -__forceinline signed long NDS_glGetClipMatrix (unsigned int index) +signed long NDS_glGetClipMatrix (unsigned int index) { float val = MatrixGetMultipliedIndex (index, mtxCurrent[0], mtxCurrent[1]); @@ -1325,7 +1275,7 @@ __forceinline signed long NDS_glGetClipMatrix (unsigned int index) return (signed long)val; } -__forceinline signed long NDS_glGetDirectionalMatrix (unsigned int index) +signed long NDS_glGetDirectionalMatrix (unsigned int index) { index += (index/3); @@ -1340,7 +1290,7 @@ __forceinline signed long NDS_glGetDirectionalMatrix (unsigned int index) 30-31 Light Number (0..3) */ -__forceinline void NDS_glLightDirection (unsigned long v) +void NDS_glLightDirection (unsigned long v) { int index = v>>30; float direction[4]; @@ -1366,7 +1316,7 @@ __forceinline void NDS_glLightDirection (unsigned long v) g_lightInfo[index].direction = v; } -__forceinline void NDS_glLightColor (unsigned long v) +void NDS_glLightColor (unsigned long v) { int lightColor[4] = { ((v) &0x1F)<<26, ((v>> 5)&0x1F)<<26, @@ -1388,12 +1338,12 @@ __forceinline void NDS_glLightColor (unsigned long v) g_lightInfo[index].color = v; } -__forceinline void NDS_glAlphaFunc(unsigned long v) +void NDS_glAlphaFunc(unsigned long v) { alphaTestRef = (v&31)/31.f; } -__forceinline void NDS_glControl(unsigned long v) +void NDS_glControl(unsigned long v) { if(beginCalled) glEnd(); @@ -1428,14 +1378,14 @@ __forceinline void NDS_glControl(unsigned long v) if (v&(1<<14)) { - printlog("Enabled BITMAP background mode\n"); + LOG ("Enabled BITMAP background mode"); } if(beginCalled) glBegin(vtxFormat); } -__forceinline void NDS_glNormal(unsigned long v) +void NDS_glNormal(unsigned long v) { __declspec(align(16)) float normal[3] = { normalTable[v&1023], @@ -1445,9 +1395,9 @@ __forceinline void NDS_glNormal(unsigned long v) if (texCoordinateTransform == 2) { float s2 =( (normal[0] *mtxCurrent[3][0] + normal[1] *mtxCurrent[3][4] + - normal[2] *mtxCurrent[3][8]) + _s); + normal[2] *mtxCurrent[3][8]) + s); float t2 =( (normal[0] *mtxCurrent[3][1] + normal[1] *mtxCurrent[3][5] + - normal[2] *mtxCurrent[3][9]) + _t); + normal[2] *mtxCurrent[3][9]) + t); glTexCoord2f (s2, t2); } @@ -1457,32 +1407,7 @@ __forceinline void NDS_glNormal(unsigned long v) glNormal3fv(normal); } -__forceinline void NDS_glBoxTest(unsigned long v) -{ -} - -__forceinline void NDS_glPosTest(unsigned long v) -{ -} - -__forceinline void NDS_glVecTest(unsigned long v) -{ - //printlog("NDS_glVecTest\n"); -} - -__forceinline long NDS_glGetPosRes(unsigned int index) -{ - //printlog("NDS_glGetPosRes\n"); - return 0; -} - -__forceinline long NDS_glGetVecRes(unsigned int index) -{ - //printlog("NDS_glGetVecRes\n"); - return 0; -} - -__forceinline void NDS_glCallList(unsigned long v) +void NDS_glCallList(unsigned long v) { //static unsigned long oldval = 0, shit = 0; @@ -1493,6 +1418,7 @@ __forceinline void NDS_glCallList(unsigned long v) return; } + for (;;) { switch ((clCmd&0xFF)) @@ -1505,6 +1431,7 @@ __forceinline void NDS_glCallList(unsigned long v) clCmd >>= 8; continue; } + break; } @@ -1847,7 +1774,6 @@ __forceinline void NDS_glCallList(unsigned long v) case 0x40 : { - //old_vtxFormat=((unsigned long *)ARM9Mem.ARM9_REG)[0x500>>2]; ((unsigned long *)ARM9Mem.ARM9_REG)[0x500>>2] = v; NDS_glBegin(v); --clInd; @@ -1888,7 +1814,7 @@ __forceinline void NDS_glCallList(unsigned long v) */ default: { - LOG ("Unknown 3D command %02X\n", clCmd&0xFF); + LOG ("Unknown 3D command %02X", clCmd&0xFF); --clInd; clCmd>>=8; break; @@ -1906,7 +1832,7 @@ __forceinline void NDS_glCallList(unsigned long v) } } -__forceinline void NDS_glGetMatrix(unsigned int mode, unsigned int index, float* dest) +void NDS_glGetMatrix(unsigned int mode, unsigned int index, float* dest) { //int n; @@ -1919,20 +1845,17 @@ __forceinline void NDS_glGetMatrix(unsigned int mode, unsigned int index, float* MatrixCopy(dest, MatrixStackGetPos(&mtxStack[mode], index)); } -__forceinline void NDS_glGetLightDirection(unsigned int index, unsigned int* dest) +void NDS_glGetLightDirection(unsigned int index, unsigned int* dest) { *dest = g_lightInfo[index].direction; } -__forceinline void NDS_glGetLightColor(unsigned int index, unsigned int* dest) +void NDS_glGetLightColor(unsigned int index, unsigned int* dest) { *dest = g_lightInfo[index].color; } GPU3DInterface gpu3Dgl = { NDS_glInit, - NDS_3D_Reset, - NDS_3D_Close, - NDS_glViewPort, NDS_glClearColor, NDS_glFogColor, @@ -1982,12 +1905,6 @@ GPU3DInterface gpu3Dgl = { NDS_glInit, NDS_glGetMatrix, NDS_glGetLightDirection, - NDS_glGetLightColor, - - NDS_glBoxTest, - NDS_glPosTest, - NDS_glVecTest, - NDS_glGetPosRes, - NDS_glGetVecRes + NDS_glGetLightColor };