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"
16
17namespace yaze {
18namespace zelda3 {
19
20// ============================================================================
21// Graphics Constants
22// ============================================================================
23
24// Sheet counts
25constexpr uint32_t kNumGfxSheets = 223;
26constexpr uint32_t kNumLinkSheets = 14;
27
28// Blockset/Group counts
29constexpr uint32_t kNumMainBlocksets = 37;
30constexpr uint32_t kNumRoomBlocksets = 82;
31constexpr uint32_t kNumSpritesets = 144;
32constexpr uint32_t kNumPalettesets = 72;
33
34// ROM pointer locations
35constexpr uint32_t kEntranceGfxGroup = 0x5D97;
36// Note: kGfxGroupsPointer defined in zelda3/dungeon/dungeon_rom_addresses.h
37constexpr uint32_t kMaxGraphics = 0x0C3FFF;
38
39// Dungeon palette lookup tables
40// Room headers store a "palette set ID" (0-71), NOT a direct palette index!
41// Two-level lookup: paletteset_ids[room.palette][0] gives a byte offset into
42// kDungeonPalettePointerTable. The word there, divided by 180, is the palette.
43constexpr uint32_t kPalettesetIdsAddress = 0x75460;
44constexpr uint32_t kDungeonPalettePointerTable = 0xDEC4B;
45
46// Link graphics location ($10:8000)
47constexpr uint32_t kLinkGfxOffset = 0x80000;
48constexpr uint16_t kLinkGfxLength = 0x800;
49
50// Font graphics location
51constexpr uint32_t kFontSpriteLocation = 0x70000;
52
53// Sheet sizes
54constexpr uint32_t kUncompressedSheetSize = 0x0800; // 2048 bytes
55
56// Tile16 pointer location
57constexpr uint32_t kTile16Ptr = 0x78000;
58
59// Version constants map
60static const std::map<zelda3_version, zelda3_version_pointers>
61 kVersionConstantsMap = {
62 {zelda3_version::US, zelda3_us_pointers},
63 {zelda3_version::JP, zelda3_jp_pointers},
64 {zelda3_version::SD, {}},
65 {zelda3_version::RANDO, {}},
66};
67
68struct GameData {
69 // Constructors
70 GameData() = default;
71 explicit GameData(Rom* rom) : rom_(rom) {}
72
73 // ROM reference (non-owning)
74 Rom* rom() const { return rom_; }
75 void set_rom(Rom* rom) { rom_ = rom; }
76
77 // Version info
78 zelda3_version version = zelda3_version::US;
79 std::string title;
80
81 // Graphics Resources
82 std::vector<uint8_t> graphics_buffer; // Legacy contiguous buffer
83 std::array<std::vector<uint8_t>, kNumGfxSheets> raw_gfx_sheets; // 8BPP indexed
84 std::array<gfx::Bitmap, kNumGfxSheets> gfx_bitmaps; // Renderable bitmaps
85 std::array<gfx::Bitmap, kNumLinkSheets> link_graphics;
87
88 // Game Data Structures
90
91 std::array<std::array<uint8_t, 8>, kNumMainBlocksets> main_blockset_ids;
92 std::array<std::array<uint8_t, 4>, kNumRoomBlocksets> room_blockset_ids;
93 std::array<std::array<uint8_t, 4>, kNumSpritesets> spriteset_ids;
94
95 // Palette set lookup table (72 entries × 4 bytes each)
96 // Entry format: [bg_palette_offset, aux1, aux2, aux3]
97 // NOTE: paletteset_ids[n][0] is a BYTE OFFSET into kDungeonPalettePointerTable,
98 // NOT a direct palette index! See room.cc for correct lookup algorithm.
99 std::array<std::array<uint8_t, 4>, kNumPalettesets> paletteset_ids;
100
101 // Diagnostics
103
104 void Clear() {
105 graphics_buffer.clear();
106 for (auto& sheet : raw_gfx_sheets) sheet.clear();
107 // gfx_bitmaps don't need explicit clearing if reloaded
109 }
110
111 private:
112 Rom* rom_ = nullptr;
113};
114
116 bool load_graphics = true;
117 bool load_palettes = true;
118 bool load_gfx_groups = true;
119 bool expand_rom = true;
120 bool populate_metadata = true;
121};
122
129absl::Status LoadGameData(Rom& rom, GameData& data, const LoadOptions& options = {});
130
136absl::Status SaveGameData(Rom& rom, GameData& data);
137
138// Individual loaders (internal use or fine-grained control)
139absl::Status LoadMetadata(const Rom& rom, GameData& data);
140absl::Status LoadPalettes(const Rom& rom, GameData& data);
141absl::Status LoadGfxGroups(Rom& rom, GameData& data);
142absl::Status LoadGraphics(Rom& rom, GameData& data);
143absl::Status SaveGfxGroups(Rom& rom, const GameData& data);
144
150absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
151 const Rom& rom);
152
158absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom& rom);
159
165absl::StatusOr<gfx::Bitmap> LoadFontGraphics(const Rom& rom);
166
173absl::Status SaveAllGraphicsData(
174 Rom& rom, const std::array<gfx::Bitmap, kNumGfxSheets>& sheets);
175
186uint32_t GetGraphicsAddress(const uint8_t* data, uint8_t addr, uint32_t ptr1,
187 uint32_t ptr2, uint32_t ptr3, size_t rom_size);
188
189} // namespace zelda3
190} // namespace yaze
191
192#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:24
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
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:211
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2BPP graphics sheets from ROM.
Definition game_data.cc:456
constexpr uint32_t kPalettesetIdsAddress
Definition game_data.h:43
constexpr uint16_t kLinkGfxLength
Definition game_data.h:48
constexpr uint32_t kFontSpriteLocation
Definition game_data.h:51
absl::StatusOr< std::array< gfx::Bitmap, kNumLinkSheets > > LoadLinkGraphics(const Rom &rom)
Loads Link's graphics sheets from ROM.
Definition game_data.cc:432
absl::StatusOr< gfx::Bitmap > LoadFontGraphics(const Rom &rom)
Loads font graphics from ROM.
Definition game_data.cc:493
constexpr uint32_t kNumRoomBlocksets
Definition game_data.h:30
constexpr uint32_t kUncompressedSheetSize
Definition game_data.h:54
absl::Status LoadGameData(Rom &rom, GameData &data, const LoadOptions &options)
Loads all Zelda3-specific game data from a generic ROM.
Definition game_data.cc:80
absl::Status LoadMetadata(const Rom &rom, GameData &data)
Definition game_data.cc:136
constexpr uint32_t kMaxGraphics
Definition game_data.h:37
constexpr uint32_t kTile16Ptr
Definition game_data.h:57
constexpr uint32_t kNumPalettesets
Definition game_data.h:32
absl::Status SaveAllGraphicsData(Rom &rom, const std::array< gfx::Bitmap, kNumGfxSheets > &sheets)
Saves all graphics sheets back to ROM.
Definition game_data.cc:516
constexpr uint32_t kLinkGfxOffset
Definition game_data.h:47
constexpr uint32_t kNumMainBlocksets
Definition game_data.h:29
constexpr uint32_t kNumGfxSheets
Definition game_data.h:25
constexpr uint32_t kEntranceGfxGroup
Definition game_data.h:35
constexpr uint32_t kNumSpritesets
Definition game_data.h:31
constexpr uint32_t kNumLinkSheets
Definition game_data.h:26
absl::Status LoadPalettes(const Rom &rom, GameData &data)
Definition game_data.cc:159
absl::Status SaveGameData(Rom &rom, GameData &data)
Saves modified game data back to the ROM.
Definition game_data.cc:108
absl::Status LoadGraphics(Rom &rom, GameData &data)
Definition game_data.cc:285
constexpr uint32_t kDungeonPalettePointerTable
Definition game_data.h:44
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:69
absl::Status LoadGfxGroups(Rom &rom, GameData &data)
Definition game_data.cc:165
Represents a mapping of palette groups.
std::array< std::array< uint8_t, 4 >, kNumSpritesets > spriteset_ids
Definition game_data.h:93
void set_rom(Rom *rom)
Definition game_data.h:75
std::array< std::array< uint8_t, 4 >, kNumRoomBlocksets > room_blockset_ids
Definition game_data.h:92
std::array< std::array< uint8_t, 4 >, kNumPalettesets > paletteset_ids
Definition game_data.h:99
gfx::Bitmap font_graphics
Definition game_data.h:86
gfx::PaletteGroupMap palette_groups
Definition game_data.h:89
GraphicsLoadDiagnostics diagnostics
Definition game_data.h:102
zelda3_version version
Definition game_data.h:78
std::array< gfx::Bitmap, kNumGfxSheets > gfx_bitmaps
Definition game_data.h:84
std::array< gfx::Bitmap, kNumLinkSheets > link_graphics
Definition game_data.h:85
Rom * rom() const
Definition game_data.h:74
std::array< std::array< uint8_t, 8 >, kNumMainBlocksets > main_blockset_ids
Definition game_data.h:91
std::array< std::vector< uint8_t >, kNumGfxSheets > raw_gfx_sheets
Definition game_data.h:83
std::vector< uint8_t > graphics_buffer
Definition game_data.h:82
The Legend of Zelda: A Link to the Past - Data Structures and Constants.