diff --git a/src/f6502.c b/src/f6502.c index fd27754..aecc487 100644 --- a/src/f6502.c +++ b/src/f6502.c @@ -222,12 +222,7 @@ static inline int f6502_write(nes_Memory* mem, // Copy to render reference addr &= 0x1FU; uint8_t* pal = mem->ppu.palette; - if (0 == (addr & 0x3)) { - // TODO: Just initialize this - pal[0] = pal[4] = pal[8] = pal[12] = - pal[16] = pal[20] = pal[24] = - pal[28] = 0xFFU; - } else { + if (0 != (addr & 0x3)) { pal[addr] = val & 0x3FU; } diff --git a/src/memory.h b/src/memory.h index 6a1a1f9..b23bb9e 100644 --- a/src/memory.h +++ b/src/memory.h @@ -42,11 +42,5 @@ static inline uint8_t* prg_rom_page(nes_Memory* mem, int page) { return &mem->rom[page * NES_PRG_ROM_PAGE_SIZE]; } -static inline uint8_t* prg_rom_last_page(nes_Memory* mem, int page) { - // TODO: Where's 0x2000U from? - return &mem->rom[ (mem->n_rom_banks * NES_PRG_ROM_PAGE_SIZE) - - ((page + 1) * 0x2000U)]; -} - #endif // NESE_MEMORY_H_ diff --git a/src/nes.c b/src/nes.c index 72bee51..2053452 100644 --- a/src/nes.c +++ b/src/nes.c @@ -9,7 +9,7 @@ void nes_init(nes* sys) { f6502_init(&sys->core); - // TODO: Init PPU + nes_ppu_init(&sys->ppu, &sys->core.memory.ppu); // TODO: Init APU } @@ -107,6 +107,7 @@ static int nes_hsync(nes* sys, void* plat) { } #define mapper_hsync_dot (300U) +#define render_dot (256U) int nes_loop(nes* sys, void* plat) { int status = 0; diff --git a/src/nes.h b/src/nes.h index 4891640..17bd9c2 100644 --- a/src/nes.h +++ b/src/nes.h @@ -11,7 +11,6 @@ typedef struct { const ines_Header* cart_header; f6502_Core core; nes_PPU ppu; - // TODO: PPU // TODO: APU } nes; diff --git a/src/ppu.c b/src/ppu.c index d14f1e3..bf5addb 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -6,6 +6,14 @@ #include "log.h" +void nes_ppu_init(nes_PPU* ppu, nes_PPU_Memory* mem) { + uint8_t* pal = mem->palette; + pal[0] = pal[4] = pal[8] = pal[12] = + pal[16] = pal[20] = pal[24] = + pal[28] = 0xFFU; +} + + static const uint8_t mirror_schemes[][4] = { [nes_Mirror_Horizontal] = {0, 0, 1, 1}, [nes_Mirror_Vertical] = {0, 1, 0, 1}, diff --git a/src/ppu.h b/src/ppu.h index 25192bf..60f3325 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -136,6 +136,8 @@ typedef struct { uint8_t screen_data[nes_ppu_render_w * nes_ppu_render_h]; } nes_PPU; +void nes_ppu_init(nes_PPU*, nes_PPU_Memory*); + void nes_ppu_find_hit_line(nes_PPU*, nes_PPU_Memory*); void nes_ppu_render_line(nes_PPU*, nes_PPU_Memory*);