| 1 | #pragma once |
| 2 | #include "common.hpp" |
| 3 | |
| 4 | namespace PPU { |
| 5 | |
| 6 | |
| 7 | enum Scanline { VISIBLE, POST, NMI, PRE }; |
| 8 | enum Mirroring { VERTICAL, HORIZONTAL }; |
| 9 | |
| 10 | /* Sprite buffer */ |
| 11 | struct Sprite |
| 12 | { |
| 13 | u8 id; // Index in OAM. |
| 14 | u8 x; // X position. |
| 15 | u8 y; // Y position. |
| 16 | u8 tile; // Tile index. |
| 17 | u8 attr; // Attributes. |
| 18 | u8 dataL; // Tile data (low). |
| 19 | u8 dataH; // Tile data (high). |
| 20 | }; |
| 21 | |
| 22 | /* PPUCTRL ($2000) register */ |
| 23 | union Ctrl |
| 24 | { |
| 25 | struct |
| 26 | { |
| 27 | unsigned nt : 2; // Nametable ($2000 / $2400 / $2800 / $2C00). |
| 28 | unsigned incr : 1; // Address increment (1 / 32). |
| 29 | unsigned sprTbl : 1; // Sprite pattern table ($0000 / $1000). |
| 30 | unsigned bgTbl : 1; // BG pattern table ($0000 / $1000). |
| 31 | unsigned sprSz : 1; // Sprite size (8x8 / 8x16). |
| 32 | unsigned slave : 1; // PPU master/slave. |
| 33 | unsigned nmi : 1; // Enable NMI. |
| 34 | }; |
| 35 | u8 r; |
| 36 | }; |
| 37 | |
| 38 | /* PPUMASK ($2001) register */ |
| 39 | union Mask |
| 40 | { |
| 41 | struct |
| 42 | { |
| 43 | unsigned gray : 1; // Grayscale. |
| 44 | unsigned bgLeft : 1; // Show background in leftmost 8 pixels. |
| 45 | unsigned sprLeft : 1; // Show sprite in leftmost 8 pixels. |
| 46 | unsigned bg : 1; // Show background. |
| 47 | unsigned spr : 1; // Show sprites. |
| 48 | unsigned red : 1; // Intensify reds. |
| 49 | unsigned green : 1; // Intensify greens. |
| 50 | unsigned blue : 1; // Intensify blues. |
| 51 | }; |
| 52 | u8 r; |
| 53 | }; |
| 54 | |
| 55 | /* PPUSTATUS ($2002) register */ |
| 56 | union Status |
| 57 | { |
| 58 | struct |
| 59 | { |
| 60 | unsigned bus : 5; // Not significant. |
| 61 | unsigned sprOvf : 1; // Sprite overflow. |
| 62 | unsigned sprHit : 1; // Sprite 0 Hit. |
| 63 | unsigned vBlank : 1; // In VBlank? |
| 64 | }; |
| 65 | u8 r; |
| 66 | }; |
| 67 | |
| 68 | /* Loopy's VRAM address */ |
| 69 | union Addr |
| 70 | { |
| 71 | struct |
| 72 | { |
| 73 | unsigned cX : 5; // Coarse X. |
| 74 | unsigned cY : 5; // Coarse Y. |
| 75 | unsigned nt : 2; // Nametable. |
| 76 | unsigned fY : 3; // Fine Y. |
| 77 | }; |
| 78 | struct |
| 79 | { |
| 80 | unsigned l : 8; |
| 81 | unsigned h : 7; |
| 82 | }; |
| 83 | unsigned addr : 14; |
| 84 | unsigned r : 15; |
| 85 | }; |
| 86 | |
| 87 | template <bool write> u8 access(u16 index, u8 v = 0); |
| 88 | void set_mirroring(Mirroring mode); |
| 89 | void step(); |
| 90 | void reset(); |
| 91 | |
| 92 | |
| 93 | } |
| 94 | |