From 29acd2d238dfd6fc2837a5c7c5da4116c331ae29 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 8 Aug 2010 22:46:13 +0000 Subject: [PATCH] would you believe there are still bugs in our @#&*@#ing matrix stack? fixes a bug that causes overwrite of matrix stack when offset==31; and apply fixed point logic for texCoordinateTransform==3 --- desmume/src/gfx3d.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index de591b6fa..ddc8df959 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -619,18 +619,17 @@ static void SetVertex() if (texCoordinateTransform == 3) { - //UNTESTED since fixed point conversion, and almost certainly wrong. - last_s =((coord[0]*mtxCurrent[3][0] + - coord[1]*mtxCurrent[3][4] + - coord[2]*mtxCurrent[3][8]) + _s * 16.0f) / 16.0f; - last_t =((coord[0]*mtxCurrent[3][1] + - coord[1]*mtxCurrent[3][5] + - coord[2]*mtxCurrent[3][9]) + _t * 16.0f) / 16.0f; - last_s /= 4096.0f; - last_t /= 4096.0f; + //Tested by: Eledees The Adventures of Kai and Zero (E) [title screen and frontend menus] + last_s = (s32)(((s64)s16coord[0] * mtxCurrent[3][0] + + (s64)s16coord[1] * mtxCurrent[3][4] + + (s64)s16coord[2] * mtxCurrent[3][8] + + (((s64)(_s))<<24))>>24); + last_t = (s32)(((s64)s16coord[0] * mtxCurrent[3][1] + + (s64)s16coord[1] * mtxCurrent[3][5] + + (s64)s16coord[2] * mtxCurrent[3][9] + + (((s64)(_t))<<24))>>24); } - //refuse to do anything if we have too many verts or polys polygonListCompleted = 0; if(vertlist->count >= VERTLIST_SIZE) @@ -889,7 +888,7 @@ static void gfx3d_glStoreMatrix(u32 v) if(mymode==0 || mymode==3) v = 0; - if (v > 31) return; + if (v >= 31) return; MatrixStackLoadMatrix (&mtxStack[mymode], v, mtxCurrent[mymode]); @@ -909,7 +908,7 @@ static void gfx3d_glRestoreMatrix(u32 v) if(mymode==0 || mymode==3) v = 0; - if (v > 31) return; + if (v >= 31) return; MatrixCopy (mtxCurrent[mymode], MatrixStackGetPos(&mtxStack[mymode], v));