| 1 | struct Background { |
| 2 | struct ID { enum { BG1, BG2, BG3, BG4 }; }; |
| 3 | unsigned id; |
| 4 | |
| 5 | struct Mode { enum { BPP2, BPP4, BPP8, Mode7, Inactive }; }; |
| 6 | struct ScreenSize { enum { Size32x32, Size32x64, Size64x32, Size64x64 }; }; |
| 7 | struct TileSize { enum { Size8x8, Size16x16 }; }; |
| 8 | struct Screen { enum { Main, Sub }; }; |
| 9 | |
| 10 | struct Regs { |
| 11 | uint16 tiledata_addr; |
| 12 | uint16 screen_addr; |
| 13 | uint2 screen_size; |
| 14 | uint4 mosaic; |
| 15 | bool tile_size; |
| 16 | |
| 17 | unsigned mode; |
| 18 | unsigned priority0; |
| 19 | unsigned priority1; |
| 20 | |
| 21 | bool main_enable; |
| 22 | bool sub_enable; |
| 23 | |
| 24 | uint16 hoffset; |
| 25 | uint16 voffset; |
| 26 | } regs; |
| 27 | |
| 28 | struct Cache { |
| 29 | uint16 hoffset; |
| 30 | uint16 voffset; |
| 31 | } cache; |
| 32 | |
| 33 | unsigned voffset() const; |
| 34 | unsigned hoffset() const; |
| 35 | |
| 36 | struct Output { |
| 37 | struct Pixel { |
| 38 | unsigned priority; //0 = none (transparent) |
| 39 | uint8 palette; |
| 40 | uint16 tile; |
| 41 | } main, sub; |
| 42 | } output; |
| 43 | |
| 44 | struct Mosaic : Output::Pixel { |
| 45 | unsigned vcounter; |
| 46 | unsigned voffset; |
| 47 | unsigned hcounter; |
| 48 | unsigned hoffset; |
| 49 | } mosaic; |
| 50 | |
| 51 | struct { |
| 52 | signed x; |
| 53 | signed y; |
| 54 | |
| 55 | unsigned tile_counter; |
| 56 | unsigned tile; |
| 57 | unsigned priority; |
| 58 | unsigned palette_number; |
| 59 | unsigned palette_index; |
| 60 | uint8 data[8]; |
| 61 | }; |
| 62 | |
| 63 | inline void frame(); |
| 64 | inline void scanline(); |
| 65 | inline void begin(); |
| 66 | inline void run(bool screen); |
| 67 | inline void reset(); |
| 68 | |
| 69 | inline void get_tile(); |
| 70 | inline unsigned get_tile_color(); |
| 71 | inline unsigned get_tile(unsigned x, unsigned y); |
| 72 | inline signed clip(signed n); |
| 73 | inline void begin_mode7(); |
| 74 | inline void run_mode7(); |
| 75 | |
| 76 | inline void serialize(serializer&); |
| 77 | inline Background(PPU& self, unsigned id); |
| 78 | |
| 79 | PPU& self; |
| 80 | friend class PPU; |
| 81 | }; |