From e08b851c79ae9a7fc0a2066e49110dc7fb426bce Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Mon, 28 Apr 2025 22:19:43 +0200 Subject: reverted rewrite of ppu, optimized what functions should be forced inline, gained ~2.5% performance --- ppu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'ppu.c') diff --git a/ppu.c b/ppu.c index cd549d1..48ccbfc 100644 --- a/ppu.c +++ b/ppu.c @@ -26,8 +26,8 @@ static void ppu_reset(struct nes_state *state) { } -__attribute__((always_inline, hot)) -static inline void ppu_evaluate_sprites(struct nes_state *state) { +__attribute__((hot)) +static void ppu_evaluate_sprites(struct nes_state *state) { struct ppu_state *restrict ppu = &state->ppu; uint8_t sprite_height = (ppu->reg_ctrl & 0x20) ? 16 : 8; uint8_t n = 0; @@ -59,8 +59,8 @@ static inline void ppu_evaluate_sprites(struct nes_state *state) { ppu->sprite_count = n; } -__attribute__((always_inline, hot)) -static inline void ppu_fetch_sprite_patterns(struct nes_state *state) { +__attribute__((hot)) +static void ppu_fetch_sprite_patterns(struct nes_state *state) { struct ppu_state *restrict ppu = &state->ppu; uint32_t addr; uint32_t bank; @@ -126,8 +126,8 @@ static inline void ppu_render_pixel(struct nes_state *state) { uint8_t left_bg = ppu->reg_mask & 0x02; uint8_t left_sp = ppu->reg_mask & 0x04; - uint8_t bg_mask = (show_bg && (left_bg || x >= 8)) ? 0xff : 0x00; - uint8_t sp_mask = (show_sprites && (left_sp || x >= 8)) ? 0xff : 0x00; + uint8_t bg_mask = (show_bg && (left_bg || x & ~7)) ? 0xff : 0x00; + uint8_t sp_mask = (show_sprites && (left_sp || x & ~7)) ? 0xff : 0x00; // Background uint8_t p0 = !!(ppu->bg_shift_pattern_low & bit); @@ -149,8 +149,8 @@ static inline void ppu_render_pixel(struct nes_state *state) { if(!sp_pixel) continue; sp_palette = ppu->secondary_oam[i * 4 + 2] & 3; - sp_prio = ppu->sprite_priorities[i]; - sp_zero = (ppu->sprite_indexes[i] == 0); + sp_prio = ppu->sprite_priorities[i]; + sp_zero = (ppu->sprite_indexes[i] == 0); break; } @@ -167,8 +167,6 @@ static inline void ppu_render_pixel(struct nes_state *state) { case 3: { ppu->reg_status |= (sp_zero && x < 255) ? 0x40 : 0; // NOTE(peter): Sprite zero hit! palette_index = (sp_prio) ? bg_index : 0x10 | sp_index; -// printf("sprite zero hit: scanline: %3.3d dot: %3.3d\n", ppu->scanline, ppu->dot); - } break; } @@ -397,8 +395,8 @@ static void ppu_tick(struct nes_state *state) { } if(UNLIKELY(scanline == 241) && dot == 1) { - static int32_t tas_frame = 0; - state->input[0] = tas_input[tas_frame++]; + // static int32_t tas_frame = 0; + // state->input[0] = tas_input[tas_frame++]; ppu->reg_status |= 0x80; if(ppu->reg_ctrl & 0x80) { -- cgit v1.2.3