From 16dd75b1e4e2b9547ac082efb47e83e7da319ab4 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 30 Mar 2012 04:11:00 +0000 Subject: [PATCH] fix regression from r4111 in store/restore matrix operations regarding stack size and overflow. also fix regression from other time in the handling of push/pop commands regarding stack size and overflow (fixes sims games and spiderman games). also a bunch of unrelated license cleanup i foolishly mixed in here --- desmume/src/Disassembler.cpp | 29 +++++++++++++---------------- desmume/src/MMU.cpp | 2 +- desmume/src/MMU.h | 2 +- desmume/src/NDSSystem.cpp | 2 +- desmume/src/arm_instructions.cpp | 15 ++++++--------- desmume/src/armcpu.cpp | 7 ++++--- desmume/src/armcpu.h | 2 +- desmume/src/bios.cpp | 7 ++++--- desmume/src/cp15.cpp | 2 +- desmume/src/gfx3d.cpp | 32 +++++++++++++++++++++----------- desmume/src/matrix.cpp | 25 +++++-------------------- desmume/src/matrix.h | 1 - desmume/src/saves.cpp | 2 +- desmume/src/utils/emufat.cpp | 2 +- desmume/src/utils/emufat.h | 2 +- 15 files changed, 61 insertions(+), 71 deletions(-) diff --git a/desmume/src/Disassembler.cpp b/desmume/src/Disassembler.cpp index eea1842ba..49f18c460 100644 --- a/desmume/src/Disassembler.cpp +++ b/desmume/src/Disassembler.cpp @@ -1,22 +1,19 @@ -/* Copyright (C) 2006 yopyop - yopyop156@ifrance.com - yopyop156.ifrance.com +/* + Copyright (C) 2006 yopyop + Copyright (C) 2006-2012 DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ #include diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 20fb4cf99..db3a131fb 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2006 yopyop Copyright (C) 2007 shash - Copyright (C) 2007-2011 DeSmuME team + Copyright (C) 2007-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 8589e4916..4fc2750ea 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -1,7 +1,7 @@ /* Copyright (C) 2006 yopyop Copyright (C) 2007 shash - Copyright (C) 2007-2011 DeSmuME team + Copyright (C) 2007-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index cfe85f7b7..28e27252e 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2006 yopyop - Copyright (C) 2008-2011 DeSmuME team + Copyright (C) 2008-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/desmume/src/arm_instructions.cpp b/desmume/src/arm_instructions.cpp index 73f5646f4..4abb60989 100644 --- a/desmume/src/arm_instructions.cpp +++ b/desmume/src/arm_instructions.cpp @@ -1,23 +1,20 @@ -/* +/* Copyright (C) 2006 yopyop Copyright (C) 2006-2007 shash - Copyright (C) 2008-2011 DeSmuME team + Copyright (C) 2008-2012 DeSmuME team - This file is part of DeSmuME - - DeSmuME is free software; you can redistribute it and/or modify + This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. - DeSmuME is distributed in the hope that it will be useful, + This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + along with the this software. If not, see . */ // ARM core TODO: diff --git a/desmume/src/armcpu.cpp b/desmume/src/armcpu.cpp index 402535dcd..764a43a13 100644 --- a/desmume/src/armcpu.cpp +++ b/desmume/src/armcpu.cpp @@ -1,9 +1,10 @@ -/* Copyright (C) 2006 yopyop - Copyright (C) 2009-2010 DeSmuME team +/* + Copyright (C) 2006 yopyop + Copyright (C) 2009-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This file is distributed in the hope that it will be useful, diff --git a/desmume/src/armcpu.h b/desmume/src/armcpu.h index b62e97070..142b3f4cb 100644 --- a/desmume/src/armcpu.h +++ b/desmume/src/armcpu.h @@ -3,7 +3,7 @@ This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This file is distributed in the hope that it will be useful, diff --git a/desmume/src/bios.cpp b/desmume/src/bios.cpp index ae761f996..e2fd09e06 100644 --- a/desmume/src/bios.cpp +++ b/desmume/src/bios.cpp @@ -1,9 +1,10 @@ -/* Copyright (C) 2006 yopyop - Copyright (C) 2008-2011 DeSmuME team +/* + Copyright (C) 2006 yopyop + Copyright (C) 2008-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This file is distributed in the hope that it will be useful, diff --git a/desmume/src/cp15.cpp b/desmume/src/cp15.cpp index 263cd8b5c..120bab413 100644 --- a/desmume/src/cp15.cpp +++ b/desmume/src/cp15.cpp @@ -3,7 +3,7 @@ This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This file is distributed in the hope that it will be useful, diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 94a129a47..b8c9b6c42 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2006 yopyop - Copyright (C) 2008-2011 DeSmuME team + Copyright (C) 2008-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -863,9 +863,13 @@ static void gfx3d_glPopMatrix(s32 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); - //6 bits, sign extended - //this was necessary to fix sims apartment pets //i = (i<<26)>>26; + //previously, we sign extended here. that isnt really necessary since the stacks are apparently modularly addressed. so i am somewhat doubtful that this is a real concept. + //example: + //suppose we had a -30 that would be %100010. + //which is the same as adding 34. if our stack was at 17 then one way is 17-30(+32)=19 and the other way is 17+34(-32)=19 + + //please note that our ability to skip treating this as signed is dependent on the modular addressing later. if that ever changes, we need to change this back. MatrixStackPopMatrix(mtxCurrent[mymode], &mtxStack[mymode], i); @@ -886,8 +890,13 @@ static void gfx3d_glStoreMatrix(u32 v) v = 0; v &= 31; - //this behaviour is unverified. gbatek suggests that it may be meaningful somehow. - if(v==31) return; + + //according to gbatek, 31 works but sets the stack overflow flag + //spider-man 2 tests this on the spiderman model (and elsewhere) + //i am somewhat skeptical of this, but we'll leave it this way for now. + //a test shouldnt be too hard + if(v==31) + MMU_new.gxstat.se = 1; MatrixStackLoadMatrix (&mtxStack[mymode], v, mtxCurrent[mymode]); @@ -909,12 +918,13 @@ static void gfx3d_glRestoreMatrix(u32 v) v &= 31; - //this seems to do something irrational if v==31, as far as we know. - //lets arbitrarily choose to use entry - - if(v==31) { - v = 0; - printf("gfx3d_glRestoreMatrix is using -1. why would anyone do this? please report!\n"); - } + //according to gbatek, 31 works but sets the stack overflow flag + //spider-man 2 tests this on the spiderman model (and elsewhere) + //i am somewhat skeptical of this, but we'll leave it this way for now. + //a test shouldnt be too hard + if(v==31) + MMU_new.gxstat.se = 1; + MatrixCopy (mtxCurrent[mymode], MatrixStackGetPos(&mtxStack[mymode], v)); diff --git a/desmume/src/matrix.cpp b/desmume/src/matrix.cpp index ee06ed2ad..8a05950a1 100644 --- a/desmume/src/matrix.cpp +++ b/desmume/src/matrix.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2006-2007 shash - Copyright (C) 2007-2011 DeSmuME team + Copyright (C) 2007-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -149,19 +149,6 @@ void MatrixInit (float *matrix) matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; } -void MatrixTranspose(s32 *matrix) -{ - float temp; -#define swap(A,B) temp = matrix[A];matrix[A] = matrix[B]; matrix[B] = temp; - swap(1,4); - swap(2,8); - swap(3,0xC); - swap(6,9); - swap(7,0xD); - swap(0xB,0xE); -#undef swap -} - void MatrixIdentity (s32 *matrix) { matrix[1] = matrix[2] = matrix[3] = matrix[4] = 0; @@ -258,12 +245,10 @@ static void MatrixStackSetStackPosition (MatrixStack *stack, int pos) if((stack->position < 0) || (stack->position > stack->size)) MMU_new.gxstat.se = 1; - //this behaviour is unverified, but its more logical than the old code which would wrap around and turn negative - //it may still be right to wrap around, but we have no proof right now one way or another - if(stack->position < 0) - stack->position = 0; - if(stack->position > stack->size) - stack->position = stack->size; + //once upon a time, we tried clamping to the size. + //this utterly broke sims 2 apartment pets. + //changing to wrap around made it work perfectly + stack->position = ((u32)stack->position) & stack->size; } void MatrixStackPushMatrix (MatrixStack *stack, const s32 *ptr) diff --git a/desmume/src/matrix.h b/desmume/src/matrix.h index 2806b1800..783335b0e 100644 --- a/desmume/src/matrix.h +++ b/desmume/src/matrix.h @@ -56,7 +56,6 @@ void MatrixCopy (s32 * matrixDST, const s32 * matrixSRC); int MatrixCompare (const s32 * matrixDST, const float * matrixSRC); void MatrixIdentity (s32 *matrix); -void MatrixTranspose (s32 *matrix); void MatrixStackInit (MatrixStack *stack); void MatrixStackSetMaxSize (MatrixStack *stack, int size); void MatrixStackPushMatrix (MatrixStack *stack, const s32 *ptr); diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 82ae775c2..54adede4b 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -2,7 +2,7 @@ Copyright (C) 2006 Normmatt Copyright (C) 2006 Theo Berkau Copyright (C) 2007 Pascal Giard - Copyright (C) 2008-2011 DeSmuME team + Copyright (C) 2008-2012 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/desmume/src/utils/emufat.cpp b/desmume/src/utils/emufat.cpp index bcacc348c..32185a5e8 100644 --- a/desmume/src/utils/emufat.cpp +++ b/desmume/src/utils/emufat.cpp @@ -2,7 +2,7 @@ This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This file is distributed in the hope that it will be useful, diff --git a/desmume/src/utils/emufat.h b/desmume/src/utils/emufat.h index c41172047..a7b422943 100644 --- a/desmume/src/utils/emufat.h +++ b/desmume/src/utils/emufat.h @@ -2,7 +2,7 @@ This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This file is distributed in the hope that it will be useful,