101 lines
2.3 KiB
C
101 lines
2.3 KiB
C
//
|
|
// Created by william on 12/30/23.
|
|
//
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include "types.h"
|
|
|
|
#ifndef NESEMULATOR_PPU_H
|
|
#define NESEMULATOR_PPU_H
|
|
|
|
#define PPU_REGISTER_SIZE 0x8
|
|
#define PPU_VRAM_SIZE 0x4000
|
|
#define PPU_OAM_SIZE 0xff
|
|
|
|
#define PPU_REGISTER_CTRL 0x00
|
|
#define PPU_REGISTER_MASK 0x01
|
|
#define PPU_REGISTER_STATUS 0x02
|
|
#define PPU_REGISTER_OAM_ADDR 0x03
|
|
#define PPU_REGISTER_OAM_DATA 0x04
|
|
#define PPU_REGISTER_SCROLL 0x05
|
|
#define PPU_REGISTER_ADDR 0x06
|
|
#define PPU_REGISTER_DATA 0x07
|
|
|
|
#define PPU_CTRL_BASE_NAMETABLE_ADDR 0x3
|
|
#define PPU_CTRL_VRAM_ADDR_INCREMENT 0x4
|
|
#define PPU_CTRL_SP_PATTERN_TABLE_ADDR 0x8
|
|
#define PPU_CTRL_BG_PATTERN_TABLE_ADDR 0x10
|
|
#define PPU_CTRL_SP_SIZE 0x20
|
|
#define PPU_CTRL_MODE_SELECT 0x40
|
|
#define PPU_CTRL_GEN_VBLANK_NMI 0x80
|
|
|
|
#define PPU_MASK_GREYSCALE 0x1
|
|
#define PPU_MASK_SHOW_BG_LEFT 0x2
|
|
#define PPU_MASK_SHOW_SP_LEFT 0x4
|
|
#define PPU_MASK_SHOW_BG 0x8
|
|
#define PPU_MASK_SHOW_SP 0x10
|
|
#define PPU_MASK_EMP_RED 0x20
|
|
#define PPU_MASK_EMP_GREEN 0x40
|
|
#define PPU_MASK_EMP_BLUE 0x80
|
|
|
|
#define PPU_STATUS_OPEN_BUS 0x1f
|
|
#define PPU_STATUS_SP_OVERFLOW 0x20
|
|
#define PPU_STATUS_SP_0_HIT 0x40
|
|
#define PPU_STATUS_VBLANK 0x80
|
|
|
|
#define PPU_MASK_NONE 0xff
|
|
|
|
typedef struct ppu {
|
|
byte *registers;
|
|
byte *oam_dma_register;
|
|
byte vram[PPU_VRAM_SIZE];
|
|
byte oam[PPU_OAM_SIZE];
|
|
bool odd_frame;
|
|
address v;
|
|
address t;
|
|
byte x;
|
|
bool w;
|
|
|
|
void (*trigger_nmi)();
|
|
} PPU;
|
|
|
|
PPU *ppu_get_state();
|
|
|
|
/**
|
|
* Initializes the PPU, according to the power up state.
|
|
* https://www.nesdev.org/wiki/PPU_power_up_state
|
|
*
|
|
* @param ppu
|
|
*/
|
|
void ppu_init(byte *registers_ram, byte *oam_dma_register);
|
|
|
|
/**
|
|
* Cycles the PPU.
|
|
*
|
|
* @param ppu
|
|
* @param ram
|
|
*/
|
|
void ppu_cycle();
|
|
|
|
/**
|
|
* Read a flag from the PPU registers.
|
|
*
|
|
* @param reg The register index
|
|
* @param mask The flag mask
|
|
*/
|
|
bool ppu_read_flag(size_t reg, byte mask);
|
|
|
|
/**
|
|
* Read a value from the PPU registers. Does not apply any offset to the value, a mask of 0x20 will either result in 0x20 (true) or 0x0 (false).
|
|
* Read a value from the PPU registers. Does not apply any offset to the value, a mask of 0x20 will either result in 0x20 (true) or 0x0 (false).
|
|
*
|
|
* @param reg The register index
|
|
* @param mask The value mask
|
|
*/
|
|
void ppu_read_register(byte reg);
|
|
|
|
void ppu_write_register(byte reg);
|
|
|
|
#endif //NESEMULATOR_PPU_H
|