yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sprite_sheet_slots.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <map>
5
7
8namespace yaze::zelda3 {
9
10std::array<uint8_t, 8> SpriteSheetSlots(
11 const std::array<uint8_t, 4>& spriteset_values, bool underworld) {
12 constexpr uint8_t kBase = 0x73;
13 return {kBase,
14 static_cast<uint8_t>(kBase + (underworld ? 10 : 1)),
15 static_cast<uint8_t>(kBase + 6),
16 static_cast<uint8_t>(kBase + 7),
17 static_cast<uint8_t>(kBase + spriteset_values[0]),
18 static_cast<uint8_t>(kBase + spriteset_values[1]),
19 static_cast<uint8_t>(kBase + spriteset_values[2]),
20 static_cast<uint8_t>(kBase + spriteset_values[3])};
21}
22
23std::vector<SpriteTileIssue> CheckSpriteTiles(
24 const Rom& rom, const std::vector<int>& tiles,
25 const std::array<uint8_t, 8>& slots,
26 const std::set<uint16_t>& reserved_sheets) {
27 constexpr size_t kTileBytes = 24; // one 3bpp 8x8 tile
28 std::map<uint16_t, std::vector<uint8_t>> sheet_data;
29 std::vector<SpriteTileIssue> issues;
30 for (int tile : tiles) {
31 SpriteTileIssue issue;
32 issue.tile = tile;
33 issue.slot = SpriteSlotForTile(tile);
34 issue.sheet = slots[issue.slot];
35 if (reserved_sheets.count(issue.sheet) != 0) {
37 issues.push_back(issue);
38 continue;
39 }
40 auto cached = sheet_data.find(issue.sheet);
41 if (cached == sheet_data.end()) {
42 auto data = issue.sheet < kGfxSheetCount
43 ? ReadGfxSheetData(rom, issue.sheet)
44 : absl::StatusOr<std::vector<uint8_t>>(
45 absl::OutOfRangeError("sheet past the tables"));
46 cached = sheet_data
47 .emplace(issue.sheet, data.ok() ? std::move(*data)
48 : std::vector<uint8_t>())
49 .first;
50 }
51 const auto& data = cached->second;
52 const size_t begin = static_cast<size_t>(tile % 0x40) * kTileBytes;
53 if (data.size() < begin + kTileBytes) {
55 issues.push_back(issue);
56 continue;
57 }
58 if (std::all_of(data.begin() + begin, data.begin() + begin + kTileBytes,
59 [](uint8_t b) { return b == 0; })) {
61 issues.push_back(issue);
62 }
63 }
64 return issues;
65}
66
67} // namespace yaze::zelda3
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:49
Locates graphics sheets in the ROM and writes edited sheets back.
Zelda 3 specific classes and functions.
absl::StatusOr< std::vector< uint8_t > > ReadGfxSheetData(const Rom &rom, uint16_t sheet_id, const GfxSheetPointerTables &tables)
Returns the sheet's decoded bytes (SNES planar data).
constexpr size_t kGfxSheetCount
constexpr int SpriteSlotForTile(int tile)
Slot (0-7) holding 8x8 OAM tile tile (name-table bit included).
std::array< uint8_t, 8 > SpriteSheetSlots(const std::array< uint8_t, 4 > &spriteset_values, bool underworld)
The eight sheets for a spriteset's four values.
std::vector< SpriteTileIssue > CheckSpriteTiles(const Rom &rom, const std::vector< int > &tiles, const std::array< uint8_t, 8 > &slots, const std::set< uint16_t > &reserved_sheets)
Which graphics sheets back sprite OAM tiles 0x000-0x1FF.