diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-04-08 02:26:58 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-04-08 02:26:58 +0200 |
| commit | 205dc47111125aa2f7458be948cd9cd434d0344c (patch) | |
| tree | dc9c44d9bc431449b478a5a5bc72a6a4d7c36c37 | |
| parent | d45fbf8d2e1adcb35043dfc9e06eae3ccfdf596e (diff) | |
Back at 2618fps
| -rw-r--r-- | mknes.h | 45 | ||||
| -rw-r--r-- | ppu.c | 12 |
2 files changed, 30 insertions, 27 deletions
@@ -21,12 +21,16 @@ #define MIRROR_FOURSCREEN 2 struct ppu_state { + uint16_t bg_shift_pattern_low; + uint16_t bg_shift_pattern_high; + uint16_t bg_shift_attrib_low; + uint16_t bg_shift_attrib_high; + uint32_t scanline; uint32_t dot; - uint32_t bg_shift_pattern_low; - uint32_t bg_shift_pattern_high; - uint32_t bg_shift_attrib_low; - uint32_t bg_shift_attrib_high; + uint32_t vram_addr; + uint32_t temp_addr; + uint32_t fine_x; uint8_t bg_next_tile_id; uint8_t bg_next_tile_attrib; uint8_t bg_next_tile_lsb; @@ -35,26 +39,13 @@ struct ppu_state { uint8_t oam_data; uint8_t even_frame; - uint8_t oam[256]; - uint8_t secondary_oam[32]; - uint8_t palette[0x20]; - uint8_t sprite_indexes[8]; - uint32_t sprite_patterns[8]; - uint8_t sprite_positions[8]; - uint8_t sprite_priorities[8]; - uint8_t sprite_shift_lo[8]; - uint8_t sprite_shift_hi[8]; - uint8_t reg_ctrl; uint8_t reg_mask; uint8_t reg_status; - uint32_t vram_addr; - uint32_t temp_addr; - uint32_t fine_x; + uint8_t write_latch; uint8_t vram_read_buffer; - uint8_t write_latch; uint8_t open_bus; @@ -62,7 +53,17 @@ struct ppu_state { uint8_t sprite_zero_hit_possible; uint8_t sprite_count; -} __attribute__((aligned(64))); + + uint8_t sprite_indexes[8]; + uint8_t sprite_positions[8]; + uint8_t sprite_priorities[8]; + uint8_t sprite_shift_lo[8]; + uint8_t sprite_shift_hi[8]; + uint8_t palette[32]; + uint8_t secondary_oam[32]; + uint8_t oam[256]; + +} __attribute__((packed, aligned(64))); struct cpu_state { uint32_t pc; // Program Counter @@ -80,7 +81,7 @@ struct cpu_state { uint8_t c; // Carry Flag // -- uint8_t die; // KIL instruction found! -} __attribute__((aligned(64))); +};// __attribute__((aligned(64))); struct ines_state { @@ -93,18 +94,18 @@ struct ines_state { struct nes_state { size_t cycles; - struct ines_state ines; struct cpu_state cpu; uint8_t irq_pending; uint8_t nmi_pending; uint8_t input[2]; // Controller 1 & 2 uint8_t input_latch[2]; // Latched inputs after strobe - uint8_t input_strobe; // Control bit (0 or 1) uint8_t input_bit[2]; // Current bit position being shifted out + uint8_t input_strobe; // Control bit (0 or 1) struct ppu_state ppu; struct mapper_entry mapper; union mapper_data map; + struct ines_state ines; uint8_t *pixels; uint8_t *ram; @@ -11,14 +11,14 @@ static uint8_t __attribute__((aligned(64))) ppu_bitreverse_lut[256] = { #undef R6 static void ppu_reset(struct nes_state *state) { - struct ppu_state *ppu = &state->ppu; + struct ppu_state *restrict ppu = &state->ppu; memset(ppu, 0, sizeof(struct ppu_state)); } __attribute__((always_inline, hot)) static inline void ppu_evaluate_sprites(struct nes_state *state) { - struct ppu_state *ppu = &state->ppu; + struct ppu_state *restrict ppu = &state->ppu; uint8_t sprite_height = (ppu->reg_ctrl & 0x20) ? 16 : 8; uint8_t n = 0; @@ -52,7 +52,7 @@ static inline void ppu_evaluate_sprites(struct nes_state *state) { __attribute__((always_inline, hot)) static inline void ppu_fetch_sprite_patterns(struct nes_state *state) { - struct ppu_state *ppu = &state->ppu; + struct ppu_state *restrict ppu = &state->ppu; uint32_t addr; uint32_t bank; @@ -87,6 +87,7 @@ static inline void ppu_fetch_sprite_patterns(struct nes_state *state) { ppu->sprite_shift_lo[i] = lsb; ppu->sprite_shift_hi[i] = msb; + ppu->sprite_positions[i] = x; ppu->sprite_priorities[i] = attr & 0x20; s += 4; @@ -95,7 +96,7 @@ static inline void ppu_fetch_sprite_patterns(struct nes_state *state) { __attribute__((always_inline, hot)) static inline void ppu_render_pixel(struct nes_state *state) { - struct ppu_state *ppu = &state->ppu; + struct ppu_state *restrict ppu = &state->ppu; uint32_t x = ppu->dot - 1; uint32_t y = ppu->scanline; @@ -160,7 +161,8 @@ static inline void ppu_render_pixel(struct nes_state *state) { __attribute__((hot, flatten)) static void ppu_tick(struct nes_state *state) { - struct ppu_state *ppu = &state->ppu; + struct ppu_state *restrict ppu = &state->ppu; + uint32_t dot = ppu->dot; uint32_t scanline = ppu->scanline; |
