nesemu/include/ppu.h

101 lines
2.3 KiB
C
Raw Normal View History

2024-01-06 14:27:09 -05:00
//
// 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 {
2024-05-06 20:23:44 -04:00
byte *registers;
byte *oam_dma_register;
2024-01-06 14:27:09 -05:00
byte vram[PPU_VRAM_SIZE];
byte oam[PPU_OAM_SIZE];
bool odd_frame;
address v;
address t;
byte x;
bool w;
2024-05-06 20:23:44 -04:00
void (*trigger_nmi)();
2024-01-06 14:27:09 -05:00
} PPU;
2024-05-06 20:23:44 -04:00
PPU *ppu_get_state();
2024-01-06 14:27:09 -05:00
/**
* Initializes the PPU, according to the power up state.
* https://www.nesdev.org/wiki/PPU_power_up_state
*
* @param ppu
*/
2024-05-06 20:23:44 -04:00
void ppu_init(byte *registers_ram, byte *oam_dma_register);
2024-01-06 14:27:09 -05:00
/**
* Cycles the PPU.
*
* @param ppu
* @param ram
*/
2024-05-06 20:23:44 -04:00
void ppu_cycle();
2024-01-06 14:27:09 -05:00
/**
* Read a flag from the PPU registers.
*
* @param reg The register index
* @param mask The flag mask
*/
2024-05-06 20:23:44 -04:00
bool ppu_read_flag(size_t reg, byte mask);
2024-01-06 14:27:09 -05:00
/**
* 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
*/
2024-05-06 20:23:44 -04:00
void ppu_read_register(byte reg);
2024-01-06 14:27:09 -05:00
2024-05-06 20:23:44 -04:00
void ppu_write_register(byte reg);
2024-01-06 14:27:09 -05:00
#endif //NESEMULATOR_PPU_H