fix #97 - increasing matrix stack cursor size to 6bits caused garbage to get masked into GXSTAT since there had been no &31 to select only the needed 5 bits

This commit is contained in:
zeromus 2017-09-29 14:47:09 -05:00
parent d37ef1ff95
commit 2c1360dec5
3 changed files with 23 additions and 13 deletions

View File

@ -1942,13 +1942,11 @@ u32 TGXSTAT::read32()
ret |= tb|(tr<<1);
int _hack_getMatrixStackLevel(int which);
// stack position always equal zero. possible timings is wrong
// using in "The Wild West"
int proj_level = _hack_getMatrixStackLevel(0);
int mv_level = _hack_getMatrixStackLevel(1);
ret |= ((proj_level << 13) | (mv_level << 8)); //matrix stack levels //no proof that these are needed yet
int proj_level = mtxStack[MATRIXMODE_PROJECTION].position & 1;
int mv_level = mtxStack[MATRIXMODE_POSITION].position & 31;
ret |= ((proj_level << 13) | (mv_level << 8));
ret |= sb<<14; //stack busy
ret |= se<<15;
@ -1981,6 +1979,7 @@ void TGXSTAT::write32(const u32 val)
{
// Writing "1" to Bit15 does reset the Error Flag (Bit15),
// and additionally resets the Projection Stack Pointer (Bit13)
// (and probably (?) also the Texture Stack Pointer)??
mtxStack[0].position = 0;
se = 0; //clear stack error flag
}

View File

@ -295,8 +295,6 @@ CACHE_ALIGN MatrixStack mtxStack[4] = {
MatrixStack(1, 3), // Texture stack
};
int _hack_getMatrixStackLevel(int which) { return mtxStack[which].position; }
static CACHE_ALIGN s32 mtxCurrent[4][16];
static CACHE_ALIGN s32 mtxTemporal[16];
static MatrixMode mode = MATRIXMODE_PROJECTION;
@ -967,6 +965,9 @@ static void gfx3d_glPushMatrix()
//2. mask that bit off to actually index the matrix for reading
//3. SE is set depending on resulting internal counter
//printf("%d %d %d %d -> ",mtxStack[0].position,mtxStack[1].position,mtxStack[2].position,mtxStack[3].position);
//printf("PUSH mode: %d -> ",mode,mtxStack[mode].position);
if(mode == MATRIXMODE_PROJECTION || mode == MATRIXMODE_TEXTURE)
{
MatrixCopy(MatrixStackGetPos(&mtxStack[mode], 0), mtxCurrent[mode]);
@ -985,9 +986,11 @@ static void gfx3d_glPushMatrix()
index += 1;
index &= 63;
if(index >= 32) MMU_new.gxstat.se = 1;
if(index >= 32) MMU_new.gxstat.se = 1; //(not sure, this might be off by 1)
}
//printf("%d %d %d %d\n",mtxStack[0].position,mtxStack[1].position,mtxStack[2].position,mtxStack[3].position);
GFX_DELAY(17);
}
@ -997,6 +1000,9 @@ static void gfx3d_glPopMatrix(u32 v)
//2. SE is set depending on resulting internal counter
//3. mask that bit off to actually index the matrix for reading
//printf("%d %d %d %d -> ",mtxStack[0].position,mtxStack[1].position,mtxStack[2].position,mtxStack[3].position);
//printf("POP (%d): mode: %d -> ",v,mode,mtxStack[mode].position);
if(mode == MATRIXMODE_PROJECTION || mode == MATRIXMODE_TEXTURE)
{
//parameter is ignored and treated as sensible (always 1)
@ -1012,17 +1018,22 @@ static void gfx3d_glPopMatrix(u32 v)
index -= v & 63;
index &= 63;
if(index >= 32) MMU_new.gxstat.se = 1;
if(index >= 32) MMU_new.gxstat.se = 1; //(not sure, this might be off by 1)
MatrixCopy(mtxCurrent[MATRIXMODE_POSITION], MatrixStackGetPos(&mtxStack[MATRIXMODE_POSITION], index&31));
MatrixCopy(mtxCurrent[MATRIXMODE_POSITION_VECTOR], MatrixStackGetPos(&mtxStack[MATRIXMODE_POSITION_VECTOR], index&31));
}
//printf("%d %d %d %d\n",mtxStack[0].position,mtxStack[1].position,mtxStack[2].position,mtxStack[3].position);
GFX_DELAY(36);
}
static void gfx3d_glStoreMatrix(u32 v)
{
//printf("%d %d %d %d -> ",mtxStack[0].position,mtxStack[1].position,mtxStack[2].position,mtxStack[3].position);
//printf("STORE (%d): mode: %d -> ",v,mode,mtxStack[mode].position);
if(mode == MATRIXMODE_PROJECTION || mode == MATRIXMODE_TEXTURE)
{
//parameter ignored and treated as sensible
@ -1034,13 +1045,15 @@ static void gfx3d_glStoreMatrix(u32 v)
{
v &= 31;
//out of bounds function fully properly, but set errors
//out of bounds function fully properly, but set errors (not sure, this might be off by 1)
if(v >= 31) MMU_new.gxstat.se = 1;
MatrixStackLoadMatrix(&mtxStack[MATRIXMODE_POSITION], v, mtxCurrent[MATRIXMODE_POSITION]);
MatrixStackLoadMatrix(&mtxStack[MATRIXMODE_POSITION_VECTOR], v, mtxCurrent[MATRIXMODE_POSITION_VECTOR]);
}
//printf("%d %d %d %d\n",mtxStack[0].position,mtxStack[1].position,mtxStack[2].position,mtxStack[3].position);
GFX_DELAY(17);
}
@ -1055,7 +1068,7 @@ static void gfx3d_glRestoreMatrix(u32 v)
else
{
//out of bounds errors function fully properly, but set errors
MMU_new.gxstat.se = v>=31;
MMU_new.gxstat.se = v>=31; //(not sure, this might be off by 1)
MatrixCopy(mtxCurrent[MATRIXMODE_POSITION], MatrixStackGetPos(&mtxStack[MATRIXMODE_POSITION], v));
MatrixCopy(mtxCurrent[MATRIXMODE_POSITION_VECTOR], MatrixStackGetPos(&mtxStack[MATRIXMODE_POSITION_VECTOR], v));

View File

@ -696,8 +696,6 @@ extern CACHE_ALIGN u8 mixTable555[32][32][32];
extern BOOL isSwapBuffers;
int _hack_getMatrixStackLevel(int);
void gfx3d_glFlush(u32 v);
// end GE commands