From 5808f00555c48e1cc1cc110af6a5cd73ddf13010 Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Fri, 2 May 2025 23:15:47 +0200 Subject: cleanup and rewrite of ppu_registers.c --- mknes.h | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'mknes.h') diff --git a/mknes.h b/mknes.h index fb1228b..e1dc8f2 100644 --- a/mknes.h +++ b/mknes.h @@ -64,6 +64,10 @@ struct ppu_state { uint8_t secondary_oam[32]; uint8_t oam[256]; + uint8_t input[2]; // Controller 1 & 2 + uint8_t input_latch[2]; // Latched inputs after strobe + uint8_t input_bit[2]; // Current bit position being shifted out + uint8_t input_strobe; // Control bit (0 or 1) uint8_t frame_ready; } __attribute__((packed, aligned(64))); @@ -74,9 +78,10 @@ struct apu_state { uint8_t irq_pending; uint8_t dmc_dma_enabled; uint32_t dmc_sample_timer; -}; +} __attribute__((packed, aligned(64))); struct cpu_state { + size_t cycles; uint32_t pc; // Program Counter uint8_t sp; // Stack Pointer uint8_t a; // Accumulator @@ -91,42 +96,35 @@ struct cpu_state { uint8_t z; // Zero Flag uint8_t c; // Carry Flag // -- - uint8_t die; // KIL instruction found! -};// __attribute__((aligned(64))); + uint8_t irq_pending; + uint8_t nmi_pending; +} __attribute__((packed, aligned(64))); struct ines_state { - uint32_t mapper; - uint32_t submapper; + uint8_t mapper; + uint8_t submapper; uint8_t mirroring; // 0 = H, 1 = V, 2 = 4-screen uint32_t prg_size; uint32_t chr_size; -}; +} __attribute__((packed, aligned(64))); struct nes_state { - size_t cycles; - 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_bit[2]; // Current bit position being shifted out - uint8_t input_strobe; // Control bit (0 or 1) - // struct apu_state apu; struct ppu_state ppu; - - struct mapper_entry mapper; + struct mapper_functions mapper; union mapper_data map; struct ines_state ines; + struct cpu_state cpu; + // struct apu_state apu; - uint8_t *pixels; uint8_t *ram; uint8_t *ciram; - uint8_t *chr_ram; uint8_t *prg_rom; uint8_t *chr_rom; + uint8_t *chr_ram; + uint8_t *pixels; uint8_t *sram; -}; +} __attribute__((packed, aligned(64))); __attribute__((aligned(4096))) static uint32_t nes_palette[65] = { -- cgit v1.2.3