yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
game_data.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_GAME_DATA_H
2#define YAZE_ZELDA3_GAME_DATA_H
3
4#include <array>
5#include <cstdint>
6#include <map>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "app/gfx/core/bitmap.h"
13#include "rom/rom.h"
14#include "rom/rom_diagnostics.h"
15#include "zelda.h"
19
20namespace yaze {
21namespace zelda3 {
22
23// ============================================================================
24// Graphics Constants
25// ============================================================================
26
27// Sheet counts
28constexpr uint32_t kNumGfxSheets = 223;
29constexpr uint32_t kNumLinkSheets = 14;
30
31// Blockset/Group counts
32constexpr uint32_t kNumMainBlocksets = 37;
33constexpr uint32_t kNumRoomBlocksets = 82;
34constexpr uint32_t kNumSpritesets = 144;
35constexpr uint32_t kNumPalettesets = 72;
36
37// ROM pointer locations
38constexpr uint32_t kEntranceGfxGroup = 0x5D97;
39// Note: kGfxGroupsPointer defined in zelda3/dungeon/dungeon_rom_addresses.h
40constexpr uint32_t kMaxGraphics = 0x0C3FFF;
41
42// Dungeon palette lookup tables
43// Room headers store a "palette set ID" (0-71), NOT a direct palette index!
44// Two-level lookup: paletteset_ids[room.palette][0] gives a byte offset into
45// kDungeonPalettePointerTable. The word there, divided by 180, is the palette.
46constexpr uint32_t kPalettesetIdsAddress = 0x75460;
47constexpr uint32_t kDungeonPalettePointerTable = 0xDEC4B;
48constexpr int kDungeonPaletteBytes = 180;
49
50// Link graphics location ($10:8000)
51constexpr uint32_t kLinkGfxOffset = 0x80000;
52constexpr uint16_t kLinkGfxLength = 0x800;
53
54// Font graphics location
55constexpr uint32_t kFontSpriteLocation = 0x70000;
56
57// Sheet sizes
58constexpr uint32_t kUncompressedSheetSize = 0x0800; // 2048 bytes
59
60// Tile16 pointer location
61constexpr uint32_t kTile16Ptr = 0x78000;
62
63// Version constants map
64static const std::map<zelda3_version, zelda3_version_pointers>
65 kVersionConstantsMap = {
66 {zelda3_version::US, zelda3_us_pointers},
67 {zelda3_version::JP, zelda3_jp_pointers},
68 {zelda3_version::SD, {}},
69 {zelda3_version::RANDO, {}},
70};
71
72// Sheet pixels live in `sheet_store` (inherited, with the legacy
73// `graphics_buffer` alias); see graphics_sheet_store.h.
75 // Constructors
76 GameData() = default;
77 explicit GameData(Rom* rom) : rom_(rom) {}
78
79 // ROM reference (non-owning)
80 Rom* rom() const { return rom_; }
81 void set_rom(Rom* rom) { rom_ = rom; }
82
83 // Version info
84 zelda3_version version = zelda3_version::US;
85 std::string title;
86
87 // Graphics Resources (`graphics_buffer` and `sheet_store` are inherited)
88 std::array<std::vector<uint8_t>, kNumGfxSheets>
89 raw_gfx_sheets; // 8BPP indexed
90 std::array<gfx::Bitmap, kNumGfxSheets> gfx_bitmaps; // Renderable bitmaps
91 std::array<gfx::Bitmap, kNumLinkSheets> link_graphics;
93
94 // Game Data Structures
96
97 std::array<std::array<uint8_t, 8>, kNumMainBlocksets> main_blockset_ids{};
98 std::array<std::array<uint8_t, 4>, kNumRoomBlocksets> room_blockset_ids{};
99 std::array<std::array<uint8_t, 4>, kNumSpritesets> spriteset_ids{};
100 // Zero is a valid assignment. Do not infer readiness from table contents.
101 bool gfx_groups_loaded = false;
103
104 // Palette set lookup table (72 entries × 4 bytes each)
105 // Entry format: [bg_palette_offset, aux1, aux2, aux3]
106 // NOTE: paletteset_ids[n][0] is a BYTE OFFSET into kDungeonPalettePointerTable,
107 // NOT a direct palette index! See room.cc for correct lookup algorithm.
108 std::array<std::array<uint8_t, 4>, kNumPalettesets> paletteset_ids{};
109
110 // Diagnostics
112
113 // Global RoomsWithPitDamage membership table (bank $07).
115
116 // Per-room default entrance and the main graphics set it selects; see
117 // room_default_entrance.h. Empty until LoadGameData runs.
118 std::vector<RoomDefaultEntrance> room_default_entrances;
119
120 void Clear() {
121 gfx_groups_loaded = false;
125 for (auto& sheet : raw_gfx_sheets)
126 sheet.clear();
127 // gfx_bitmaps don't need explicit clearing if reloaded
130 }
131
132 private:
133 Rom* rom_ = nullptr;
134};
135
137 bool load_graphics = true;
138 bool load_palettes = true;
139 bool load_gfx_groups = true;
140 bool expand_rom = true;
141 bool populate_metadata = true;
142};
143
150absl::Status LoadGameData(Rom& rom, GameData& data,
151 const LoadOptions& options = {});
152
158absl::Status SaveGameData(Rom& rom, GameData& data);
159
160// Individual loaders (internal use or fine-grained control)
161absl::Status LoadMetadata(const Rom& rom, GameData& data);
162absl::Status LoadPalettes(const Rom& rom, GameData& data);
163absl::Status LoadGfxGroups(Rom& rom, GameData& data);
164absl::Status LoadGraphics(Rom& rom, GameData& data);
167 bool main_blocksets = false;
168 bool room_blocksets = false;
169 bool spritesets = false;
170 bool palettesets = false;
172
173 bool any() const { return changed_bytes > 0; }
174};
175
179absl::StatusOr<GfxGroupDiff> DiffGfxGroups(const Rom& rom,
180 const GameData& data);
181
184absl::Status SaveGfxGroups(Rom& rom, const GameData& data);
185
191absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
192 const Rom& rom);
193
199absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom& rom);
200
206absl::StatusOr<gfx::Bitmap> LoadFontGraphics(const Rom& rom);
207
213absl::Status SaveAllGraphicsData(
214 Rom& rom, const std::array<gfx::Bitmap, kNumGfxSheets>& sheets);
215
226uint32_t GetGraphicsAddress(const uint8_t* data, uint8_t addr, uint32_t ptr1,
227 uint32_t ptr2, uint32_t ptr3, size_t rom_size);
228
229} // namespace zelda3
230} // namespace yaze
231
232#endif // YAZE_ZELDA3_GAME_DATA_H
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
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
void Clear()
Empties the buffer and bumps every revision.
One ROM session's graphics sheet pixels, with a revision per sheet.
zelda3_version
Different versions of the game supported by YAZE.
Definition zelda.h:33
absl::Status SaveGfxGroups(Rom &rom, const GameData &data)
Definition game_data.cc:362
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2BPP graphics sheets from ROM.
Definition game_data.cc:638
constexpr uint32_t kPalettesetIdsAddress
Definition game_data.h:46
constexpr uint16_t kLinkGfxLength
Definition game_data.h:52
constexpr uint32_t kFontSpriteLocation
Definition game_data.h:55
absl::StatusOr< std::array< gfx::Bitmap, kNumLinkSheets > > LoadLinkGraphics(const Rom &rom)
Loads Link's graphics sheets from ROM.
Definition game_data.cc:612
absl::StatusOr< gfx::Bitmap > LoadFontGraphics(const Rom &rom)
Loads font graphics from ROM.
Definition game_data.cc:682
constexpr uint32_t kNumRoomBlocksets
Definition game_data.h:33
constexpr uint32_t kUncompressedSheetSize
Definition game_data.h:58
absl::StatusOr< GfxGroupDiff > DiffGfxGroups(const Rom &rom, const GameData &data)
Definition game_data.cc:334
absl::Status LoadGameData(Rom &rom, GameData &data, const LoadOptions &options)
Loads all Zelda3-specific game data from a generic ROM.
Definition game_data.cc:123
absl::Status LoadMetadata(const Rom &rom, GameData &data)
Definition game_data.cc:186
constexpr uint32_t kMaxGraphics
Definition game_data.h:40
constexpr uint32_t kTile16Ptr
Definition game_data.h:61
constexpr uint32_t kNumPalettesets
Definition game_data.h:35
absl::Status SaveAllGraphicsData(Rom &rom, const std::array< gfx::Bitmap, kNumGfxSheets > &sheets)
Not implemented; always returns UnimplementedError.
Definition game_data.cc:706
constexpr uint32_t kLinkGfxOffset
Definition game_data.h:51
constexpr int kDungeonPaletteBytes
Definition game_data.h:48
constexpr uint32_t kNumMainBlocksets
Definition game_data.h:32
constexpr uint32_t kNumGfxSheets
Definition game_data.h:28
constexpr uint32_t kEntranceGfxGroup
Definition game_data.h:38
constexpr uint32_t kNumSpritesets
Definition game_data.h:34
constexpr uint32_t kNumLinkSheets
Definition game_data.h:29
absl::Status LoadPalettes(const Rom &rom, GameData &data)
Definition game_data.cc:210
absl::Status SaveGameData(Rom &rom, GameData &data)
Saves modified game data back to the ROM.
Definition game_data.cc:157
absl::Status LoadGraphics(Rom &rom, GameData &data)
Definition game_data.cc:530
constexpr uint32_t kDungeonPalettePointerTable
Definition game_data.h:47
uint32_t GetGraphicsAddress(const uint8_t *data, uint8_t addr, uint32_t ptr1, uint32_t ptr2, uint32_t ptr3, size_t rom_size)
Gets the graphics address for a sheet index.
Definition game_data.cc:112
absl::Status LoadGfxGroups(Rom &rom, GameData &data)
Definition game_data.cc:216
Represents a mapping of palette groups.
std::vector< RoomDefaultEntrance > room_default_entrances
Definition game_data.h:118
std::array< std::array< uint8_t, 4 >, kNumSpritesets > spriteset_ids
Definition game_data.h:99
void set_rom(Rom *rom)
Definition game_data.h:81
std::array< std::array< uint8_t, 4 >, kNumRoomBlocksets > room_blockset_ids
Definition game_data.h:98
std::array< std::array< uint8_t, 4 >, kNumPalettesets > paletteset_ids
Definition game_data.h:108
gfx::Bitmap font_graphics
Definition game_data.h:92
gfx::PaletteGroupMap palette_groups
Definition game_data.h:95
GraphicsLoadDiagnostics diagnostics
Definition game_data.h:111
zelda3_version version
Definition game_data.h:84
PitDamageTable pit_damage_table
Definition game_data.h:114
std::array< gfx::Bitmap, kNumGfxSheets > gfx_bitmaps
Definition game_data.h:90
std::array< gfx::Bitmap, kNumLinkSheets > link_graphics
Definition game_data.h:91
Rom * rom() const
Definition game_data.h:80
std::array< std::array< uint8_t, 8 >, kNumMainBlocksets > main_blockset_ids
Definition game_data.h:97
uint32_t gfx_main_group_address
Definition game_data.h:102
std::array< std::vector< uint8_t >, kNumGfxSheets > raw_gfx_sheets
Definition game_data.h:89
Which gfx group tables in data differ from the bytes in rom.
Definition game_data.h:166
The Legend of Zelda: A Link to the Past - Data Structures and Constants.