ppu_blit: tiny bit faster by doing less memory reads in the inner loop

This commit is contained in:
Sigrid Solveig Haflínudóttir 2021-12-25 18:56:36 +01:00
parent 5848fbe50b
commit 2c8a7ed05a
1 changed files with 6 additions and 7 deletions

View File

@ -103,13 +103,11 @@ ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
void void
ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp)
{ {
Uint8 opaque = blending[4][color]; int v, h, opaque = blending[4][color];
Uint16 v, h; for(v = 0; v < 8; ++v) {
for(v = 0; v < 8; ++v) int c = sprite[v] | (twobpp ? sprite[v + 8] : 0) << 8;
for(h = 0; h < 8; ++h) { for(h = 7; h >= 0; --h, c >>= 1) {
Uint8 ch = (sprite[v + 0] >> (7 - h)) & 0x1; Uint8 ch = (c & 1) | ((c >> 7) & 2);
if(twobpp)
ch |= ((sprite[v + 8] >> (7 - h)) & 0x1) << 1;
if(opaque || ch) if(opaque || ch)
ppu_write(p, ppu_write(p,
layer, layer,
@ -118,6 +116,7 @@ ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, U
blending[ch][color]); blending[ch][color]);
} }
} }
}
void void
ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)