summaryrefslogtreecommitdiff
path: root/ppu.c
diff options
context:
space:
mode:
Diffstat (limited to 'ppu.c')
-rw-r--r--ppu.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/ppu.c b/ppu.c
index 1cb29b8..3096573 100644
--- a/ppu.c
+++ b/ppu.c
@@ -89,11 +89,11 @@ static inline void ppu_fetch_sprite_patterns(struct nes_state *state) {
addr = bank + tile * 16 + row;
if(attr & 0x40) {
- lsb = ppu_bitreverse_lut[state->mapper.chr_read(state, addr)];
- msb = ppu_bitreverse_lut[state->mapper.chr_read(state, addr + 8)];
+ lsb = ppu_bitreverse_lut[state->mapper_function.chr_read(state, addr)];
+ msb = ppu_bitreverse_lut[state->mapper_function.chr_read(state, addr + 8)];
} else {
- lsb = state->mapper.chr_read(state, addr);
- msb = state->mapper.chr_read(state, addr + 8);
+ lsb = state->mapper_function.chr_read(state, addr);
+ msb = state->mapper_function.chr_read(state, addr + 8);
}
ppu->sprite_shift_lo[i] = lsb;
@@ -232,12 +232,12 @@ static inline void ppu_tick(struct nes_state *state) {
switch(dot % 8) {
case 1: {
uint32_t nt_addr = 0x2000 | (ppu->vram_addr & 0x0fff);
- ppu->bg_next_tile_id = state->mapper.ciram_read(state, nt_addr);
+ ppu->bg_next_tile_id = state->mapper_function.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 attr = state->mapper_function.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;
@@ -247,7 +247,7 @@ static inline void ppu_tick(struct nes_state *state) {
uint32_t tile = ppu->bg_next_tile_id;
uint32_t fine_y = (ppu->vram_addr >> 12) & 7;
uint32_t addr_lsb = (base + tile * 16 + fine_y) & 0x1fff;
- ppu->bg_next_tile_lsb = state->mapper.chr_read(state, addr_lsb);
+ ppu->bg_next_tile_lsb = state->mapper_function.chr_read(state, addr_lsb);
} break;
case 7: {
@@ -255,7 +255,7 @@ static inline void ppu_tick(struct nes_state *state) {
uint32_t tile = ppu->bg_next_tile_id;
uint32_t fine_y = (ppu->vram_addr >> 12) & 7;
uint32_t addr_msb = (base + tile * 16 + fine_y + 8) & 0x1fff;
- ppu->bg_next_tile_msb = state->mapper.chr_read(state, addr_msb);
+ ppu->bg_next_tile_msb = state->mapper_function.chr_read(state, addr_msb);
} break;
case 0: {
@@ -331,12 +331,12 @@ static inline void ppu_tick(struct nes_state *state) {
switch(dot % 8) {
case 1: {
uint32_t nt_addr = 0x2000 | (ppu->vram_addr & 0x0fff);
- ppu->bg_next_tile_id = state->mapper.ciram_read(state, nt_addr);
+ ppu->bg_next_tile_id = state->mapper_function.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 attr = state->mapper_function.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;
@@ -346,7 +346,7 @@ static inline void ppu_tick(struct nes_state *state) {
uint32_t tile = ppu->bg_next_tile_id;
uint32_t fine_y = (ppu->vram_addr >> 12) & 7;
uint32_t addr_lsb = (base + tile * 16 + fine_y) & 0x1fff;
- ppu->bg_next_tile_lsb = state->mapper.chr_read(state, addr_lsb);
+ ppu->bg_next_tile_lsb = state->mapper_function.chr_read(state, addr_lsb);
} break;
case 7: {
@@ -354,7 +354,7 @@ static inline void ppu_tick(struct nes_state *state) {
uint32_t tile = ppu->bg_next_tile_id;
uint32_t fine_y = (ppu->vram_addr >> 12) & 7;
uint32_t addr_msb = (base + tile * 16 + fine_y + 8) & 0x1fff;
- ppu->bg_next_tile_msb = state->mapper.chr_read(state, addr_msb);
+ ppu->bg_next_tile_msb = state->mapper_function.chr_read(state, addr_msb);
} break;
case 0: {
@@ -399,9 +399,7 @@ static inline void ppu_tick(struct nes_state *state) {
// state->input[0] = tas_input[tas_frame++];
ppu->reg_status |= 0x80;
- if(ppu->reg_ctrl & 0x80) {
- state->cpu.nmi_pending = 1;
- }
+ state->cpu.nmi_pending = (ppu->reg_ctrl & 0x80); // NOTE(peter): Set NMI if enabled.
}
if(UNLIKELY(scanline == 261) && dot == 1) {
@@ -428,5 +426,6 @@ static inline void ppu_tick(struct nes_state *state) {
ppu->dot = dot;
ppu->scanline = scanline;
+ if(UNLIKELY(state->mapper_function.tick)) state->mapper_function.tick(state);
}
}