summaryrefslogtreecommitdiff
path: root/mknes.h
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-05 08:58:12 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-05 08:58:12 +0200
commitf1bd6a7d2f4ffe3e5263e0254bcf7522ab381264 (patch)
treee75bde292329f337d619f9a997aab9b17c37e38b /mknes.h
parent8c82be43720d9e221a9e2541c9ff6151015838bb (diff)
transform to switch case for ppu_tick()
Diffstat (limited to 'mknes.h')
-rw-r--r--mknes.h75
1 files changed, 34 insertions, 41 deletions
diff --git a/mknes.h b/mknes.h
index ed22652..b8bf87f 100644
--- a/mknes.h
+++ b/mknes.h
@@ -21,19 +21,33 @@
#define MIRROR_FOURSCREEN 2
struct ppu_state {
- uint8_t pixels[256 * 240];
-
- uint8_t oam[256];
+ 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;
+ uint8_t bg_next_tile_id;
+ uint8_t bg_next_tile_attrib;
+ uint8_t bg_next_tile_lsb;
+ uint8_t bg_next_tile_msb;
uint8_t oam_addr;
uint8_t oam_data;
+
+ uint8_t pixels[256 * 240] __attribute__((aligned(64)));
+ 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;
- uint8_t reg_scroll[2];
- uint8_t reg_addr[2];
- uint8_t reg_latch;
uint32_t vram_addr;
uint32_t temp_addr;
@@ -44,33 +58,11 @@ struct ppu_state {
uint8_t open_bus;
- uint8_t palette[0x20];
-
- uint32_t scanline;
- uint32_t dot;
- uint8_t even_frame;
uint8_t frame_ready;
- uint8_t sprite_indexes[8];
uint8_t sprite_zero_hit_possible;
uint8_t sprite_count;
- 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];
-
- uint32_t bg_shift_pattern_low;
- uint32_t bg_shift_pattern_high;
- uint32_t bg_shift_attrib_low;
- uint32_t bg_shift_attrib_high;
-
- uint8_t bg_next_tile_id;
- uint8_t bg_next_tile_attrib;
- uint8_t bg_next_tile_lsb;
- uint8_t bg_next_tile_msb;
-};
-
+} __attribute__((packed, aligned(64)));
struct cpu_state {
uint32_t pc; // Program Counter
@@ -81,38 +73,39 @@ struct cpu_state {
uint8_t p; // Processor Status Flags (this can be expanded with separate flags if needed)
uint8_t n; // Negative Flag
uint8_t v; // Overflow Flag
- // uint8_t b; // Break Flag (Set by BRK instruction)
+ // uint8_t b; // Break Flag (Set by BRK instruction) -- does not exist outside the stack
uint8_t d; // Decimal Flag
uint8_t i; // Interrupt Disable Flag
uint8_t z; // Zero Flag
uint8_t c; // Carry Flag
// --
uint8_t die; // KIL instruction found!
-};
+} __attribute__((packed, aligned(64)));
struct ines_state {
uint32_t mapper;
+ uint32_t submapper;
uint8_t mirroring; // 0 = H, 1 = V, 2 = 4-screen
uint32_t prg_size;
uint32_t chr_size;
};
struct nes_state {
+ size_t cycles;
struct ines_state ines;
struct cpu_state cpu;
- struct ppu_state ppu;
- struct mapper mapper;
- union mapper_data map;
- size_t cycles;
uint8_t irq_pending;
uint8_t nmi_pending;
- uint8_t ram[0x800];
- uint8_t sram[0x2000];
- uint8_t ciram[0x1000]; // NOTE(peter): Originally 0x800 bytes, but extended as it should work for up to fourway, this is optimization, reality is 2kb, but there is no side-effects, so this is fine!
- uint8_t prg_rom[4 * 1024 * 1024];
- uint8_t chr_rom[4 * 1024 * 1024];
-};
+ struct ppu_state ppu;
+ struct mapper_entry mapper;
+ union mapper_data map;
+ uint8_t ram[0x800] __attribute__((aligned(64)));
+ uint8_t sram[0x2000] __attribute__((aligned(64)));
+ uint8_t ciram[0x1000] __attribute__((aligned(64))); // NOTE(peter): Originally 0x800 bytes, but extended as it should work for up to fourway, this is optimization, reality is 2kb, but there is no side-effects, so this is fine!
+ uint8_t prg_rom[4 * 1024 * 1024] __attribute__((aligned(64)));
+ uint8_t chr_rom[4 * 1024 * 1024] __attribute__((aligned(64)));
+} __attribute__((aligned(64)));
__attribute__((aligned(4096))) static uint32_t nes_palette[64] = {