summaryrefslogtreecommitdiff
path: root/ppu.c
diff options
context:
space:
mode:
Diffstat (limited to 'ppu.c')
-rw-r--r--ppu.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/ppu.c b/ppu.c
index 3096573..8280265 100644
--- a/ppu.c
+++ b/ppu.c
@@ -19,14 +19,12 @@ static uint8_t __attribute__((aligned(64))) ppu_bitreverse_lut[256] = {
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
};
-
static void ppu_reset(struct nes_state *state) {
struct ppu_state *restrict ppu = &state->ppu;
memset(ppu, 0, sizeof(struct ppu_state));
}
-
-// __attribute__((hot))
+__attribute__((hot))
static inline 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;
@@ -59,7 +57,7 @@ static inline void ppu_evaluate_sprites(struct nes_state *state) {
ppu->sprite_count = n;
}
-// __attribute__((hot))
+__attribute__((hot))
static inline void ppu_fetch_sprite_patterns(struct nes_state *state) {
struct ppu_state *restrict ppu = &state->ppu;
uint32_t addr;
@@ -105,7 +103,7 @@ static inline void ppu_fetch_sprite_patterns(struct nes_state *state) {
}
}
-__attribute__((hot))
+__attribute__((hot, flatten))
static inline void ppu_render_pixel(struct nes_state *state) {
struct ppu_state *restrict ppu = &state->ppu;
@@ -182,7 +180,7 @@ static inline void ppu_tick(struct nes_state *state) {
for(uint32_t ppu_loops = 0; ppu_loops < 3; ++ppu_loops) {
- if(LIKELY(rendering)) {
+ if(rendering) {
switch(scanline) {
case 0 ... 239: {
switch(dot) {
@@ -358,12 +356,12 @@ static inline 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;
@@ -394,7 +392,7 @@ static inline void ppu_tick(struct nes_state *state) {
}
}
- if(UNLIKELY(scanline == 241) && dot == 1) {
+ if(scanline == 241 && dot == 1) {
// static int32_t tas_frame = 0;
// state->input[0] = tas_input[tas_frame++];
@@ -402,7 +400,7 @@ static inline void ppu_tick(struct nes_state *state) {
state->cpu.nmi_pending = (ppu->reg_ctrl & 0x80); // NOTE(peter): Set NMI if enabled.
}
- if(UNLIKELY(scanline == 261) && dot == 1) {
+ if(scanline == 261 && dot == 1) {
ppu->reg_status &= ~0x80;
ppu->reg_status &= ~0x40;
}
@@ -412,7 +410,7 @@ static inline void ppu_tick(struct nes_state *state) {
dot = 0;
scanline++;
- if(UNLIKELY(scanline == 261 && !ppu->even_frame && (ppu->reg_mask & 0x18))) {
+ if(scanline == 261 && !ppu->even_frame && (ppu->reg_mask & 0x18)) {
dot = 1;
}
@@ -426,6 +424,9 @@ 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);
+
+ if(state->mapper_function.tick) {
+ state->mapper_function.tick(state);
+ }
}
}