summaryrefslogtreecommitdiff
path: root/ppu.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-09 13:02:18 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-09 13:02:18 +0200
commit6d7f00f7a662845905c3d8cc99351c328d02e802 (patch)
treebcdbce8cf685b6d0afa66d365af38c78e50df543 /ppu.c
parentc9bd7fecdb5d6c8954cf31efef910ed734386c70 (diff)
Last few optimizations to ppu_render_pixel, down to 1.59ns per pixel
Diffstat (limited to 'ppu.c')
-rw-r--r--ppu.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/ppu.c b/ppu.c
index bab97d5..be22921 100644
--- a/ppu.c
+++ b/ppu.c
@@ -35,7 +35,6 @@ static inline void ppu_evaluate_sprites(struct nes_state *state) {
dst[2] = src[2];
dst[3] = src[3];
ppu->sprite_indexes[n] = i;
- ppu->sprite_zero_hit_possible |= (i == 0);
dst += 4;
n++;
@@ -115,6 +114,11 @@ static inline void ppu_render_pixel(struct nes_state *state) {
uint8_t bg_mask = (ppu->reg_mask & 0x08) ? 0xff : 0x00;
uint8_t sp_mask = (ppu->reg_mask & 0x10) ? 0xff : 0x00;
+ // uint8_t left_mask = (x >= 8) ? 0xff : 0x00;
+ // bg_mask &= ((ppu->reg_mask & 0x02) ? 0xff : 0x00) | left_mask;
+ // sp_mask &= ((ppu->reg_mask & 0x04) ? 0xff : 0x00) | left_mask;
+
+
// Background
uint8_t p0 = !!(ppu->bg_shift_pattern_low & bit);
uint8_t p1 = !!(ppu->bg_shift_pattern_high & bit);
@@ -151,9 +155,7 @@ static inline void ppu_render_pixel(struct nes_state *state) {
case 1: { palette_index = 0x10 | sp_index; } break;
case 2: { palette_index = bg_index; } break;
case 3: {
- if(sp_zero && ppu->sprite_zero_hit_possible && x < 255) {
- ppu->reg_status |= 0x40;
- }
+ ppu->reg_status |= (sp_zero && x < 255) ? 0x40 : 0; // NOTE(peter): Sprite zero hit!
palette_index = (sp_prio) ? bg_index : 0x10 | sp_index;
} break;
}
@@ -395,7 +397,6 @@ static void ppu_tick(struct nes_state *state) {
if(UNLIKELY(scanline == 261) && dot == 1) {
ppu->reg_status &= ~0x80;
ppu->reg_status &= ~0x40;
- ppu->sprite_zero_hit_possible = 0;
}
dot++;