misc optimizations

This commit is contained in:
StapleButter 2017-04-25 01:14:26 +02:00
parent 61798ac880
commit 9eb68c2ede
4 changed files with 33 additions and 22 deletions

View File

@ -153,7 +153,8 @@ FIFO<CmdFIFOEntry>* CmdPIPE;
u32 NumCommands, CurCommand, ParamCount, TotalParams; u32 NumCommands, CurCommand, ParamCount, TotalParams;
u32 DispCnt; u32 DispCnt;
u32 AlphaRef; u8 AlphaRefVal;
u8 AlphaRef;
u16 ToonTable[32]; u16 ToonTable[32];
u16 EdgeTable[8]; u16 EdgeTable[8];
@ -1932,7 +1933,8 @@ void Write8(u32 addr, u8 val)
switch (addr) switch (addr)
{ {
case 0x04000340: case 0x04000340:
AlphaRef = val & 0x1F; AlphaRefVal = val & 0x1F;
AlphaRef = (DispCnt & (1<<2)) ? AlphaRefVal : 0;
return; return;
} }
@ -1953,10 +1955,12 @@ void Write16(u32 addr, u16 val)
DispCnt = (val & 0x4FFF) | (DispCnt & 0x3000); DispCnt = (val & 0x4FFF) | (DispCnt & 0x3000);
if (val & (1<<12)) DispCnt &= ~(1<<12); if (val & (1<<12)) DispCnt &= ~(1<<12);
if (val & (1<<13)) DispCnt &= ~(1<<13); if (val & (1<<13)) DispCnt &= ~(1<<13);
AlphaRef = (DispCnt & (1<<2)) ? AlphaRefVal : 0;
return; return;
case 0x04000340: case 0x04000340:
AlphaRef = val & 0x1F; AlphaRefVal = val & 0x1F;
AlphaRef = (DispCnt & (1<<2)) ? AlphaRefVal : 0;
return; return;
case 0x04000350: case 0x04000350:
@ -2014,10 +2018,12 @@ void Write32(u32 addr, u32 val)
DispCnt = (val & 0x4FFF) | (DispCnt & 0x3000); DispCnt = (val & 0x4FFF) | (DispCnt & 0x3000);
if (val & (1<<12)) DispCnt &= ~(1<<12); if (val & (1<<12)) DispCnt &= ~(1<<12);
if (val & (1<<13)) DispCnt &= ~(1<<13); if (val & (1<<13)) DispCnt &= ~(1<<13);
AlphaRef = (DispCnt & (1<<2)) ? AlphaRefVal : 0;
return; return;
case 0x04000340: case 0x04000340:
AlphaRef = val & 0x1F; AlphaRefVal = val & 0x1F;
AlphaRef = (DispCnt & (1<<2)) ? AlphaRefVal : 0;
return; return;
case 0x04000350: case 0x04000350:

View File

@ -65,7 +65,7 @@ typedef struct
} Polygon; } Polygon;
extern u32 DispCnt; extern u32 DispCnt;
extern u32 AlphaRef; extern u8 AlphaRef;
extern s32 Viewport[4]; extern s32 Viewport[4];
extern u32 RenderClearAttr1, RenderClearAttr2; extern u32 RenderClearAttr1, RenderClearAttr2;

View File

@ -894,6 +894,10 @@ void RenderPolygon(Polygon* polygon)
r_filledge = slope_end->Increment==0; r_filledge = slope_end->Increment==0;
} }
int yedge = 0;
if (y == ytop) yedge = 0x4;
else if (y == ybot-1) yedge = 0x8;
Interpolator interpX(xstart, xend+1, wl, wr, 8); Interpolator interpX(xstart, xend+1, wl, wr, 8);
for (s32 x = xstart; x <= xend; x++) for (s32 x = xstart; x <= xend; x++)
@ -901,9 +905,7 @@ void RenderPolygon(Polygon* polygon)
if (x < 0) continue; if (x < 0) continue;
if (x > 255) break; if (x > 255) break;
int edge = 0; int edge = yedge;
if (y == ytop) edge |= 0x4;
else if (y == ybot-1) edge |= 0x8;
if (x < l_edgeend) edge |= 0x1; if (x < l_edgeend) edge |= 0x1;
else if (x > r_edgestart) edge |= 0x2; else if (x > r_edgestart) edge |= 0x2;
@ -966,14 +968,7 @@ void RenderPolygon(Polygon* polygon)
// alpha test // alpha test
// TODO: check alpha test when blending is disabled // TODO: check alpha test when blending is disabled
if (DispCnt & (1<<2))
{
if (alpha <= AlphaRef) continue; if (alpha <= AlphaRef) continue;
}
else
{
if (alpha == 0) continue;
}
if (alpha == 31) if (alpha == 31)
{ {

View File

@ -83,6 +83,7 @@ u16 PowerControl7;
u16 ARM7BIOSProt; u16 ARM7BIOSProt;
Timer Timers[8]; Timer Timers[8];
u8 TimerCheckMask[2];
DMA* DMAs[8]; DMA* DMAs[8];
u32 DMA9Fill[4]; u32 DMA9Fill[4];
@ -294,6 +295,8 @@ void Reset()
CPUStop = 0; CPUStop = 0;
memset(Timers, 0, 8*sizeof(Timer)); memset(Timers, 0, 8*sizeof(Timer));
TimerCheckMask[0] = 0;
TimerCheckMask[1] = 0;
for (i = 0; i < 8; i++) DMAs[i]->Reset(); for (i = 0; i < 8; i++) DMAs[i]->Reset();
memset(DMA9Fill, 0, 4*4); memset(DMA9Fill, 0, 4*4);
@ -614,8 +617,8 @@ void HandleTimerOverflow(u32 tid)
void RunTimer(u32 tid, s32 cycles) void RunTimer(u32 tid, s32 cycles)
{ {
Timer* timer = &Timers[tid]; Timer* timer = &Timers[tid];
if ((timer->Cnt & 0x84) != 0x80) //if ((timer->Cnt & 0x84) != 0x80)
return; // return;
u32 oldcount = timer->Counter; u32 oldcount = timer->Counter;
timer->Counter += (cycles << timer->CycleShift); timer->Counter += (cycles << timer->CycleShift);
@ -625,10 +628,12 @@ void RunTimer(u32 tid, s32 cycles)
void RunTimingCriticalDevices(u32 cpu, s32 cycles) void RunTimingCriticalDevices(u32 cpu, s32 cycles)
{ {
RunTimer((cpu<<2)+0, cycles); register u32 timermask = TimerCheckMask[cpu];
RunTimer((cpu<<2)+1, cycles);
RunTimer((cpu<<2)+2, cycles); if (timermask & 0x1) RunTimer((cpu<<2)+0, cycles);
RunTimer((cpu<<2)+3, cycles); if (timermask & 0x2) RunTimer((cpu<<2)+1, cycles);
if (timermask & 0x4) RunTimer((cpu<<2)+2, cycles);
if (timermask & 0x8) RunTimer((cpu<<2)+3, cycles);
if (cpu == 0) if (cpu == 0)
{ {
@ -681,6 +686,11 @@ void TimerStart(u32 id, u16 cnt)
{ {
timer->Counter = timer->Reload << 16; timer->Counter = timer->Reload << 16;
} }
if ((cnt & 0x84) == 0x80)
TimerCheckMask[id>>2] |= (1<<(id&0x3));
else
TimerCheckMask[id>>2] &= ~(1<<(id&0x3));
} }