summaryrefslogtreecommitdiff
path: root/ppu.h
blob: d7cd93c865c8c05370b0fbc3e75aa3b3a314dfa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef PPU_H
#define PPU_H

#include <stdio.h>
#include <stdint.h>

#include "rom.h"

struct ppu {
	uint8_t vram[2048];
	uint8_t oam[64*4];
	uint8_t oam_addr;	/* $2003 */
	uint8_t palette[16*2];
	uint16_t cycles, scanlines;
	struct rom *rom;

	uint8_t last_read;

	struct ppu_regs {
		uint16_t v : 15;          /* current vram address */
		uint16_t t : 15;          /* temporary vram address */
		uint16_t scroll_x : 9;    /* x scroll position */
		uint16_t scroll_y : 9;    /* y scroll position */
		uint8_t write_toggle : 1; /* first/second write toggle */
	} regs;

	struct ppu_ctrl {	/* $2000 */
		uint8_t nmi_enable : 1;
		uint8_t master_slave : 1;
		uint8_t sprite_height : 1;
		uint8_t bg_tile_sel : 1;
		uint8_t sprite_tile_sel : 1;
		uint8_t inc_mode : 1;
		uint8_t nametable_base : 2;
	} ctrl;
	struct ppu_mask {	/* $2001 */
		uint8_t colour_emphasis : 3;
		uint8_t sprite_enable : 1;
		uint8_t bg_enable : 1;
		uint8_t sprite_left_enable : 1;
		uint8_t bg_left_enable : 1;
		uint8_t grayscale : 1;
	} mask;
	struct ppu_status {	/* $2002 */
		uint8_t vblank : 1;
		uint8_t sprite0_hit : 1;
		uint8_t sprite_overflow : 1;
		uint8_t pad : 5;
	} status;
};
extern struct ppu ppu;

void ppu_tick(void);

#endif /* PPU_H */