yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
snes_tile.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_SNES_TILE_H
2#define YAZE_APP_GFX_SNES_TILE_H
3
4#include <cstdint>
5#include <cstring>
6#include <vector>
7
9
10namespace yaze {
11namespace app {
12namespace gfx {
13
14constexpr int kTilesheetWidth = 128;
15constexpr int kTilesheetHeight = 32;
16constexpr int kTilesheetDepth = 8;
17
18constexpr uint8_t kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
19 0x08, 0x04, 0x02, 0x01};
20
21std::vector<uint8_t> SnesTo8bppSheet(const std::vector<uint8_t>& sheet,
22 int bpp);
23std::vector<uint8_t> Bpp8SnesToIndexed(std::vector<uint8_t> data,
24 uint64_t bpp = 0);
25
26struct tile8 {
27 uint32_t id;
28 char data[64];
29 uint32_t palette_id;
30};
31using tile8 = struct tile8;
32
33tile8 UnpackBppTile(const std::vector<uint8_t>& data, const uint32_t offset,
34 const uint32_t bpp);
35
36std::vector<uint8_t> PackBppTile(const tile8& tile, const uint32_t bpp);
37
38std::vector<uint8_t> ConvertBpp(const std::vector<uint8_t>& tiles,
39 uint32_t from_bpp, uint32_t to_bpp);
40
41std::vector<uint8_t> Convert3bppTo4bpp(const std::vector<uint8_t>& tiles);
42std::vector<uint8_t> Convert4bppTo3bpp(const std::vector<uint8_t>& tiles);
43
52class TileInfo {
53 public:
54 uint16_t id_;
55 uint8_t palette_;
56 bool over_;
59 TileInfo() = default;
60 TileInfo(uint16_t id, uint8_t palette, bool v, bool h, bool o)
61 : id_(id),
62 over_(o),
65 palette_(palette) {}
66
67 bool operator==(const TileInfo& other) const {
68 return id_ == other.id_ && over_ == other.over_ &&
71 palette_ == other.palette_;
72 }
73};
74
75uint16_t TileInfoToWord(TileInfo tile_info);
76TileInfo WordToTileInfo(uint16_t word);
77uint16_t TileInfoToShort(TileInfo tile_info);
78
79TileInfo GetTilesInfo(uint16_t tile);
80
84class Tile32 {
85 public:
86 uint16_t tile0_;
87 uint16_t tile1_;
88 uint16_t tile2_;
89 uint16_t tile3_;
90
91 // Default constructor
92 Tile32() : tile0_(0), tile1_(0), tile2_(0), tile3_(0) {}
93
94 // Parameterized constructor
95 Tile32(uint16_t t0, uint16_t t1, uint16_t t2, uint16_t t3)
96 : tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {}
97
98 // Copy constructor
99 Tile32(const Tile32& other)
100 : tile0_(other.tile0_),
101 tile1_(other.tile1_),
102 tile2_(other.tile2_),
103 tile3_(other.tile3_) {}
104
105 // Constructor from packed value
106 Tile32(uint64_t packedVal) {
107 tile0_ = (uint16_t)packedVal;
108 tile1_ = (uint16_t)(packedVal >> 16);
109 tile2_ = (uint16_t)(packedVal >> 32);
110 tile3_ = (uint16_t)(packedVal >> 48);
111 }
112
113 // Get packed uint64_t representation
114 uint64_t GetPackedValue() const {
115 return static_cast<uint64_t>(tile3_) << 48 |
116 (static_cast<uint64_t>(tile2_) << 32) |
117 (static_cast<uint64_t>(tile1_) << 16) | tile0_;
118 }
119
120 // Equality operator
121 bool operator==(const Tile32& other) const {
122 return tile0_ == other.tile0_ && tile1_ == other.tile1_ &&
123 tile2_ == other.tile2_ && tile3_ == other.tile3_;
124 }
125
126 // Inequality operator
127 bool operator!=(const Tile32& other) const { return !(*this == other); }
128};
129
133class Tile16 {
134 public:
139 std::vector<TileInfo> tiles_info;
140
141 Tile16() = default;
143 : tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {
144 tiles_info.push_back(tile0_);
145 tiles_info.push_back(tile1_);
146 tiles_info.push_back(tile2_);
147 tiles_info.push_back(tile3_);
148 }
149
150 bool operator==(const Tile16& other) const {
151 return tile0_ == other.tile0_ && tile1_ == other.tile1_ &&
152 tile2_ == other.tile2_ && tile3_ == other.tile3_;
153 }
154
155 bool operator!=(const Tile16& other) const { return !(*this == other); }
156};
157
161class OamTile {
162 public:
163 int x_;
164 int y_;
165 int mx_;
166 int my_;
167 int pal_;
168 uint16_t tile_;
169 OamTile() = default;
170 OamTile(int x, int y, uint16_t tile, int pal, bool upper = false, int mx = 0,
171 int my = 0)
172 : x_(x), y_(y), mx_(mx), my_(my), pal_(pal) {
173 if (upper) {
174 tile_ = (uint16_t)(tile + 512);
175 } else {
176 tile_ = (uint16_t)(tile + 256 + 512);
177 }
178 }
179};
180
181} // namespace gfx
182} // namespace app
183} // namespace yaze
184
185#endif // YAZE_APP_GFX_SNES_TILE_H
Object Attribute Memory tile abstraction container.
Definition snes_tile.h:161
OamTile(int x, int y, uint16_t tile, int pal, bool upper=false, int mx=0, int my=0)
Definition snes_tile.h:170
Tile composition of four 8x8 tiles.
Definition snes_tile.h:133
std::vector< TileInfo > tiles_info
Definition snes_tile.h:139
bool operator==(const Tile16 &other) const
Definition snes_tile.h:150
bool operator!=(const Tile16 &other) const
Definition snes_tile.h:155
Tile16(TileInfo t0, TileInfo t1, TileInfo t2, TileInfo t3)
Definition snes_tile.h:142
Tile composition of four 16x16 tiles.
Definition snes_tile.h:84
Tile32(const Tile32 &other)
Definition snes_tile.h:99
bool operator!=(const Tile32 &other) const
Definition snes_tile.h:127
Tile32(uint16_t t0, uint16_t t1, uint16_t t2, uint16_t t3)
Definition snes_tile.h:95
uint64_t GetPackedValue() const
Definition snes_tile.h:114
bool operator==(const Tile32 &other) const
Definition snes_tile.h:121
Tile32(uint64_t packedVal)
Definition snes_tile.h:106
SNES 16-bit tile metadata container.
Definition snes_tile.h:52
TileInfo(uint16_t id, uint8_t palette, bool v, bool h, bool o)
Definition snes_tile.h:60
bool operator==(const TileInfo &other) const
Definition snes_tile.h:67
std::vector< uint8_t > Convert4bppTo3bpp(const std::vector< uint8_t > &tiles)
Definition snes_tile.cc:148
TileInfo WordToTileInfo(uint16_t word)
Definition snes_tile.cc:324
constexpr int kTilesheetDepth
Definition snes_tile.h:16
std::vector< uint8_t > PackBppTile(const tile8 &tile, const uint32_t bpp)
Definition snes_tile.cc:83
std::vector< uint8_t > Bpp8SnesToIndexed(std::vector< uint8_t > data, uint64_t bpp)
Definition snes_tile.cc:205
constexpr int kTilesheetWidth
Definition snes_tile.h:14
std::vector< uint8_t > SnesTo8bppSheet(const std::vector< uint8_t > &sheet, int bpp)
Definition snes_tile.cc:152
uint16_t TileInfoToShort(TileInfo tile_info)
Definition snes_tile.cc:339
tile8 UnpackBppTile(const std::vector< uint8_t > &data, const uint32_t offset, const uint32_t bpp)
Definition snes_tile.cc:26
constexpr uint8_t kGraphicsBitmap[8]
Definition snes_tile.h:18
std::vector< uint8_t > ConvertBpp(const std::vector< uint8_t > &tiles, uint32_t from_bpp, uint32_t to_bpp)
Definition snes_tile.cc:130
std::vector< uint8_t > Convert3bppTo4bpp(const std::vector< uint8_t > &tiles)
Definition snes_tile.cc:144
constexpr int kTilesheetHeight
Definition snes_tile.h:15
uint16_t TileInfoToWord(TileInfo tile_info)
Definition snes_tile.cc:307
TileInfo GetTilesInfo(uint16_t tile)
Definition snes_tile.cc:370
Definition common.cc:21