Browse Source

PPU init and cleanup

v2
Nathaniel Walizer 9 months ago
parent
commit
99009eb11e
6 changed files with 13 additions and 14 deletions
  1. +1
    -6
      src/f6502.c
  2. +0
    -6
      src/memory.h
  3. +2
    -1
      src/nes.c
  4. +0
    -1
      src/nes.h
  5. +8
    -0
      src/ppu.c
  6. +2
    -0
      src/ppu.h

+ 1
- 6
src/f6502.c View File

@@ -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;
}



+ 0
- 6
src/memory.h View File

@@ -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_

+ 2
- 1
src/nes.c View File

@@ -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;


+ 0
- 1
src/nes.h View File

@@ -11,7 +11,6 @@ typedef struct {
const ines_Header* cart_header;
f6502_Core core;
nes_PPU ppu;
// TODO: PPU
// TODO: APU
} nes;



+ 8
- 0
src/ppu.c View File

@@ -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},


+ 2
- 0
src/ppu.h View File

@@ -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*);


Loading…
Cancel
Save