summaryrefslogtreecommitdiff
path: root/ppu.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-07 19:47:27 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-07 19:47:27 +0200
commitd45fbf8d2e1adcb35043dfc9e06eae3ccfdf596e (patch)
treec450bc97b2b0e767150e07db745328944dcd1041 /ppu.c
parent5409798e800b6deb5d5874401a2925d1e18d8bd3 (diff)
cleanup and optimization tests, unfortunately nothing great.
Diffstat (limited to 'ppu.c')
-rw-r--r--ppu.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ppu.c b/ppu.c
index 2015b1d..cc223b7 100644
--- a/ppu.c
+++ b/ppu.c
@@ -219,12 +219,14 @@ static void ppu_tick(struct nes_state *state) {
uint32_t nt_addr = 0x2000 | (ppu->vram_addr & 0x0fff);
ppu->bg_next_tile_id = state->mapper.ciram_read(state, nt_addr);
} break;
+
case 3: {
uint32_t attr_addr = 0x23c0 | (ppu->vram_addr & 0x0c00) | ((ppu->vram_addr >> 4) & 0x38) | ((ppu->vram_addr >> 2) & 0x07);
uint8_t attr = state->mapper.ciram_read(state, attr_addr & 0x0fff);
uint8_t shift = ((ppu->vram_addr >> 4) & 4) | (ppu->vram_addr & 2);
ppu->bg_next_tile_attrib = (attr >> shift) & 3;
} break;
+
case 5: {
uint32_t base = (ppu->reg_ctrl & 0x10) ? 0x1000 : 0x0000;
uint32_t tile = ppu->bg_next_tile_id;
@@ -232,6 +234,7 @@ static void ppu_tick(struct nes_state *state) {
uint32_t addr_lsb = (base + tile * 16 + fine_y) & 0x1fff;
ppu->bg_next_tile_lsb = state->mapper.chr_read(state, addr_lsb);
} break;
+
case 7: {
uint32_t base = (ppu->reg_ctrl & 0x10) ? 0x1000 : 0x0000;
uint32_t tile = ppu->bg_next_tile_id;
@@ -239,6 +242,7 @@ static void ppu_tick(struct nes_state *state) {
uint32_t addr_msb = (base + tile * 16 + fine_y + 8) & 0x1fff;
ppu->bg_next_tile_msb = state->mapper.chr_read(state, addr_msb);
} break;
+
case 0: {
ppu->bg_shift_pattern_low = (ppu->bg_shift_pattern_low & 0xff00) | ppu->bg_next_tile_lsb;
ppu->bg_shift_pattern_high = (ppu->bg_shift_pattern_high & 0xff00) | ppu->bg_next_tile_msb;
@@ -339,12 +343,12 @@ static void ppu_tick(struct nes_state *state) {
} break;
case 0: {
- ppu->bg_shift_pattern_low = (ppu->bg_shift_pattern_low & 0xff00) | ppu->bg_next_tile_lsb;
- ppu->bg_shift_pattern_high = (ppu->bg_shift_pattern_high & 0xff00) | ppu->bg_next_tile_msb;
+ ppu->bg_shift_pattern_low = (ppu->bg_shift_pattern_low & 0xff00) | ppu->bg_next_tile_lsb;
+ ppu->bg_shift_pattern_high = (ppu->bg_shift_pattern_high & 0xff00) | ppu->bg_next_tile_msb;
uint8_t a = ppu->bg_next_tile_attrib;
- ppu->bg_shift_attrib_low = (ppu->bg_shift_attrib_low & 0xff00) | ((a & 1) ? 0xff : 0x00);
- ppu->bg_shift_attrib_high = (ppu->bg_shift_attrib_high & 0xff00) | ((a & 2) ? 0xff : 0x00);
+ ppu->bg_shift_attrib_low = (ppu->bg_shift_attrib_low & 0xff00) | ((a & 1) ? 0xff : 0x00);
+ ppu->bg_shift_attrib_high = (ppu->bg_shift_attrib_high & 0xff00) | ((a & 2) ? 0xff : 0x00);
if((ppu->vram_addr & 0x001f) == 31) {
ppu->vram_addr &= ~0x001f;