commit 2c8a7ed05a4dd082a0ad180f44cfc62d669855c2
parent 5848fbe50b9bbed18d2b70301c32826da286128a
Author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
Date: Sat, 25 Dec 2021 18:56:36 +0100
ppu_blit: tiny bit faster by doing less memory reads in the inner loop
Diffstat:
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/devices/ppu.c b/src/devices/ppu.c
@@ -103,13 +103,11 @@ ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
void
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];
- Uint16 v, h;
- for(v = 0; v < 8; ++v)
- for(h = 0; h < 8; ++h) {
- Uint8 ch = (sprite[v + 0] >> (7 - h)) & 0x1;
- if(twobpp)
- ch |= ((sprite[v + 8] >> (7 - h)) & 0x1) << 1;
+ int v, h, opaque = blending[4][color];
+ for(v = 0; v < 8; ++v) {
+ int c = sprite[v] | (twobpp ? sprite[v + 8] : 0) << 8;
+ for(h = 7; h >= 0; --h, c >>= 1) {
+ Uint8 ch = (c & 1) | ((c >> 7) & 2);
if(opaque || ch)
ppu_write(p,
layer,
@@ -117,6 +115,7 @@ ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, U
y + (flipy ? 7 - v : v),
blending[ch][color]);
}
+ }
}
void