yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_map.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_OVERWORLD_MAP_H
2#define YAZE_APP_ZELDA3_OVERWORLD_MAP_H
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7#include <vector>
8
9#include "absl/status/status.h"
12#include "core/rom_settings.h"
13#include "rom/rom.h"
14#include "zelda3/game_data.h"
16
17namespace yaze {
18namespace zelda3 {
19
20static constexpr int kTileOffsets[] = {0, 8, 4096, 4104};
21
22// 2 bytes for each overworld area (0x140)
23constexpr int OverworldCustomAreaSpecificBGPalette = 0x140000;
24
25// 1 byte, not 0 if enabled
26constexpr int OverworldCustomAreaSpecificBGEnabled = 0x140140;
27
28// Additional v3 constants
30 0x140340; // 2 bytes for each overworld area (0x140)
32 0x140144; // 1 byte, not 0 if enabled
34 0x1402A0; // 1 byte for each overworld area (0xA0)
36 0x140143; // 1 byte, not 0 if enabled
38 0x140480; // 8 bytes for each overworld area (0x500)
40 0x140148; // 1 byte, not 0 if enabled
42 0x140200; // 1 byte for each overworld area (0xA0)
44 0x140142; // 1 byte, not 0 if enabled
45
46// Vanilla overlay constants
47constexpr int kOverlayPointers =
48 0x77664; // 2 bytes for each overworld area (0x100)
49constexpr int kOverlayPointersBank = 0x0E; // Bank for overlay pointers
50constexpr int kOverlayData1 = 0x77676; // Check for custom overlay code
51constexpr int kOverlayData2 = 0x77677; // Custom overlay data pointer
52constexpr int kOverlayCodeStart = 0x77657; // Start of overlay code
53
54// 1 byte for each overworld area (0xA0)
55constexpr int OverworldCustomMainPaletteArray = 0x140160;
56// 1 byte, not 0 if enabled
57constexpr int OverworldCustomMainPaletteEnabled = 0x140141;
58
59// v3 expanded constants
60constexpr int kOverworldMessagesExpanded = 0x1417F8;
61constexpr int kOverworldMapParentIdExpanded = 0x140998;
68
74
80
86
92
98
104
110
116
117constexpr int kOverworldSpecialSpriteGFXGroup = 0x016811;
118constexpr int kOverworldSpecialGFXGroup = 0x016821;
119constexpr int kOverworldSpecialPALGroup = 0x016831;
120constexpr int kOverworldSpecialSpritePalette = 0x016841;
121constexpr int kOverworldPalettesScreenToSetNew = 0x4C635;
124
125constexpr int transition_target_northExpanded = 0x1411B8;
126constexpr int transition_target_westExpanded = 0x1412F8;
127
128constexpr int kDarkWorldMapIdStart = 0x40;
129constexpr int kSpecialWorldMapIdStart = 0x80;
130
134using OverworldBlockset = std::vector<std::vector<uint16_t>>;
135
144
149 public:
150 OverworldMap() = default;
151 OverworldMap(int index, Rom* rom, GameData* game_data = nullptr);
152
153 void SetGameData(GameData* game_data) { game_data_ = game_data; }
154
155 absl::Status BuildMap(int count, int game_state, int world,
156 std::vector<gfx::Tile16>& tiles16,
157 OverworldBlockset& world_blockset);
158
163 absl::Status BuildMapWithCache(int count, int game_state, int world,
164 std::vector<gfx::Tile16>& tiles16,
165 OverworldBlockset& world_blockset,
166 const std::vector<uint8_t>* cached_tileset);
167
168 void LoadAreaGraphics();
169 absl::Status LoadPalette();
170 absl::Status LoadOverlay();
171 absl::Status LoadVanillaOverlayData();
172 absl::Status BuildTileset();
173 absl::Status BuildTiles16Gfx(std::vector<gfx::Tile16>& tiles16, int count);
174 absl::Status BuildBitmap(OverworldBlockset& world_blockset);
175
180 void UseCachedTileset(const std::vector<uint8_t>& cached_gfx) {
181 current_gfx_ = cached_gfx;
182 }
183
184 void DrawAnimatedTiles();
185
186 const std::vector<uint8_t>& current_tile16_blockset() const {
187 return current_blockset_;
188 }
189 const std::vector<uint8_t>& current_graphics() const { return current_gfx_; }
191 const std::vector<uint8_t>& bitmap_data() const { return bitmap_data_; }
192 auto is_large_map() const { return large_map_; }
193 auto is_initialized() const { return initialized_; }
194 auto is_built() const { return built_; }
195 auto parent() const { return parent_; }
196 auto mutable_mosaic() { return &mosaic_; }
198
199 void SetNotBuilt() { built_ = false; }
200
201 auto area_graphics() const { return area_graphics_; }
202 auto area_palette() const { return area_palette_; }
203 auto sprite_graphics(int i) const { return sprite_graphics_[i]; }
204 auto sprite_palette(int i) const { return sprite_palette_[i]; }
205 auto message_id() const { return message_id_; }
206 auto area_music(int i) const { return area_music_[i]; }
207 auto static_graphics(int i) const { return static_graphics_[i]; }
208 auto large_index() const { return large_index_; }
209 auto area_size() const { return area_size_; }
210 auto main_gfx_id() const { return main_gfx_id_; }
211
212 auto main_palette() const { return main_palette_; }
213 void set_main_palette(uint8_t palette) { main_palette_ = palette; }
214
216 void set_area_specific_bg_color(uint16_t color) {
218 }
219
220 auto subscreen_overlay() const { return subscreen_overlay_; }
221 void set_subscreen_overlay(uint16_t overlay) { subscreen_overlay_ = overlay; }
222
223 auto animated_gfx() const { return animated_gfx_; }
224 void set_animated_gfx(uint8_t gfx) { animated_gfx_ = gfx; }
225
226 auto game_state() const { return game_state_; }
227 void set_game_state(int state) { game_state_ = state; }
228
229 auto custom_tileset(int index) const { return custom_gfx_ids_[index]; }
230
231 // Overlay accessors (interactive overlays)
232 auto overlay_id() const { return overlay_id_; }
233 auto has_overlay() const { return has_overlay_; }
234 const auto& overlay_data() const { return overlay_data_; }
235
236 // Mosaic expanded accessors
237 const std::array<bool, 4>& mosaic_expanded() const {
238 return mosaic_expanded_;
239 }
240 void set_mosaic_expanded(int index, bool value) {
241 mosaic_expanded_[index] = value;
242 }
243 void set_custom_tileset(int index, uint8_t value) {
244 custom_gfx_ids_[index] = value;
245 }
246
250 auto mutable_sprite_graphics(int i) { return &sprite_graphics_[i]; }
251 auto mutable_sprite_palette(int i) { return &sprite_palette_[i]; }
252 auto mutable_message_id() { return &message_id_; }
256 auto mutable_area_music(int i) { return &area_music_[i]; }
257 auto mutable_static_graphics(int i) { return &static_graphics_[i]; }
258
259 auto set_area_graphics(uint8_t value) { area_graphics_ = value; }
260 auto set_area_palette(uint8_t value) { area_palette_ = value; }
261 auto set_sprite_graphics(int i, uint8_t value) {
262 sprite_graphics_[i] = value;
263 }
264 auto set_sprite_palette(int i, uint8_t value) { sprite_palette_[i] = value; }
265 auto set_message_id(uint16_t value) { message_id_ = value; }
266
267 uint8_t* mutable_custom_tileset(int index) { return &custom_gfx_ids_[index]; }
268
269 void SetAsLargeMap(int parent_index, int quadrant) {
270 parent_ = parent_index;
271 large_index_ = quadrant;
272 large_map_ = true;
274 }
275
276 void SetAsSmallMap(int index = -1) {
277 if (index != -1)
278 parent_ = index;
279 else
280 parent_ = index_;
281 large_index_ = 0;
282 large_map_ = false;
284 }
285
287 area_size_ = size;
289 }
290
291 void SetParent(int parent_index) { parent_ = parent_index; }
292
300 void Destroy() {
301 // Free memory-heavy data
302 current_blockset_.clear();
303 current_gfx_.clear();
304 bitmap_data_.clear();
305 map_tiles_.light_world.clear();
306 map_tiles_.dark_world.clear();
308
309 // Reset build state (allows rebuild)
310 built_ = false;
311 initialized_ = false;
312
313 // Reset runtime state (will be recomputed on rebuild)
314 world_ = 0;
315 game_state_ = 0;
316 main_gfx_id_ = 0;
317
318 // NOTE: Do NOT reset these identity fields - they are needed for rebuild:
319 // - index_: Map's position in overworld array (used for ROM lookups)
320 // - parent_: Map's parent relationship (for large maps)
321 // - rom_: ROM pointer (needed for data access)
322 // - large_map_, large_index_, area_size_: Map structure info
323 // - message_id_, area_graphics_, area_palette_, etc: Loaded from ROM on rebuild
324 }
325
326 private:
327 void LoadAreaInfo();
329 void SetupCustomTileset(uint8_t asm_version);
330
331 void LoadMainBlocksetId();
333 void LoadMainBlocksets();
336 uint8_t ComputeWorldBasedMainPalette() const;
337
338 void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size,
339 const uint8_t* all_gfx);
340 absl::StatusOr<gfx::SnesPalette> GetPalette(const gfx::PaletteGroup& group,
341 int index, int previous_index,
342 int limit);
343
344 // Helper to get version constants from game_data or default to US
346 return kVersionConstantsMap.at(game_data_ ? game_data_->version
347 : zelda3_version::US);
348 }
349
352
353 bool built_ = false;
354 bool large_map_ = false;
355 bool initialized_ = false;
356 bool mosaic_ = false;
357
358 int index_ = 0; // Map index
359 int parent_ = 0; // Parent map index
360 int large_index_ = 0; // Quadrant ID [0-3]
361 int world_ = 0; // World ID [0-2]
362 int game_state_ = 0; // Game state [0-2]
363 int main_gfx_id_ = 0; // Main Gfx ID
365
366 uint16_t message_id_ = 0;
367 uint8_t area_graphics_ = 0;
368 uint8_t area_palette_ = 0;
369 uint8_t main_palette_ = 0; // Custom Overworld Main Palette ID
370 uint8_t animated_gfx_ = 0; // Custom Overworld Animated ID
371 uint16_t subscreen_overlay_ = 0; // Custom Overworld Subscreen Overlay ID
373 0; // Custom Overworld Area-Specific Background Color
374
375 std::array<uint8_t, 8> custom_gfx_ids_;
376 std::array<uint8_t, 3> sprite_graphics_;
377 std::array<uint8_t, 3> sprite_palette_;
378 std::array<uint8_t, 4> area_music_;
379 std::array<uint8_t, 16> static_graphics_;
380
381 std::array<bool, 4> mosaic_expanded_;
382
383 // Overlay support (interactive overlays that reveal holes/change elements)
384 uint16_t overlay_id_ = 0;
385 bool has_overlay_ = false;
386 std::vector<uint8_t> overlay_data_;
387
388 std::vector<uint8_t> current_blockset_;
389 std::vector<uint8_t> current_gfx_;
390 std::vector<uint8_t> bitmap_data_;
391
394};
395
396} // namespace zelda3
397} // namespace yaze
398
399#endif
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
static RomSettings & Get()
uint32_t GetAddressOr(const std::string &key, uint32_t default_value) const
Shared graphical context across editors.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Represents a single Overworld map screen.
auto set_area_palette(uint8_t value)
void SetAsLargeMap(int parent_index, int quadrant)
void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size, const uint8_t *all_gfx)
const gfx::SnesPalette & current_palette() const
zelda3_version_pointers version_constants() const
void set_main_palette(uint8_t palette)
std::vector< uint8_t > current_gfx_
std::vector< uint8_t > current_blockset_
std::array< bool, 4 > mosaic_expanded_
absl::Status LoadVanillaOverlayData()
std::vector< uint8_t > bitmap_data_
void Destroy()
Free memory-heavy data while preserving map identity.
const std::array< bool, 4 > & mosaic_expanded() const
void SetAsSmallMap(int index=-1)
auto set_message_id(uint16_t value)
void SetGameData(GameData *game_data)
auto set_sprite_palette(int i, uint8_t value)
void set_custom_tileset(int index, uint8_t value)
absl::Status BuildMapWithCache(int count, int game_state, int world, std::vector< gfx::Tile16 > &tiles16, OverworldBlockset &world_blockset, const std::vector< uint8_t > *cached_tileset)
Build map with optional cached tileset for performance.
void set_area_specific_bg_color(uint16_t color)
const auto & overlay_data() const
const std::vector< uint8_t > & current_graphics() const
void SetupCustomTileset(uint8_t asm_version)
auto sprite_graphics(int i) const
absl::StatusOr< gfx::SnesPalette > GetPalette(const gfx::PaletteGroup &group, int index, int previous_index, int limit)
absl::Status BuildTiles16Gfx(std::vector< gfx::Tile16 > &tiles16, int count)
OverworldMapTiles map_tiles_
absl::Status BuildMap(int count, int game_state, int world, std::vector< gfx::Tile16 > &tiles16, OverworldBlockset &world_blockset)
std::array< uint8_t, 3 > sprite_graphics_
void SetParent(int parent_index)
auto static_graphics(int i) const
void SetAreaSize(AreaSizeEnum size)
auto custom_tileset(int index) const
auto area_music(int i) const
uint8_t ComputeWorldBasedMainPalette() const
absl::Status BuildBitmap(OverworldBlockset &world_blockset)
std::array< uint8_t, 3 > sprite_palette_
const std::vector< uint8_t > & current_tile16_blockset() const
std::array< uint8_t, 4 > area_music_
std::array< uint8_t, 16 > static_graphics_
std::array< uint8_t, 8 > custom_gfx_ids_
void set_animated_gfx(uint8_t gfx)
auto set_area_graphics(uint8_t value)
void set_game_state(int state)
const std::vector< uint8_t > & bitmap_data() const
void set_subscreen_overlay(uint16_t overlay)
std::vector< uint8_t > overlay_data_
void UseCachedTileset(const std::vector< uint8_t > &cached_gfx)
Use a pre-computed tileset from cache instead of rebuilding.
auto area_specific_bg_color() const
auto sprite_palette(int i) const
gfx::SnesPalette current_palette_
void set_mosaic_expanded(int index, bool value)
uint8_t * mutable_custom_tileset(int index)
auto set_sprite_graphics(int i, uint8_t value)
constexpr char kOverworldTransitionPosYExpanded[]
constexpr char kOverworldScreenChange4Expanded[]
constexpr char kOverworldMapParentExpanded[]
constexpr char kOverworldScreenChange1Expanded[]
constexpr char kOverworldMessagesExpanded[]
constexpr char kOverworldScreenChange2Expanded[]
constexpr char kOverworldScreenChange3Expanded[]
constexpr char kOverworldTransitionPosXExpanded[]
int GetOverworldMapParentIdExpanded()
constexpr int OverworldCustomTileGFXGroupEnabled
constexpr int OverworldCustomAreaSpecificBGEnabled
int GetOverworldScreenChange3Expanded()
int GetOverworldScreenChange4Expanded()
constexpr int kOverworldScreenTileMapChangeByScreen2Expanded
constexpr int kOverlayData1
constexpr int kSpecialWorldMapIdStart
constexpr int OverworldCustomMosaicArray
constexpr int kOverworldTransitionPositionXExpanded
constexpr int OverworldCustomAnimatedGFXEnabled
constexpr int OverworldCustomMainPaletteEnabled
constexpr int OverworldCustomMainPaletteArray
constexpr int kOverworldTransitionPositionYExpanded
constexpr int kOverworldSpecialSpritePaletteExpandedTemp
constexpr int kOverworldMapParentIdExpanded
constexpr int kOverworldSpecialSpriteGfxGroupExpandedTemp
std::vector< std::vector< uint16_t > > OverworldBlockset
Represents tile32 data for the overworld.
AreaSizeEnum
Area size enumeration for v3+ ROMs.
constexpr int kOverlayPointersBank
constexpr int transition_target_westExpanded
int GetOverworldScreenChange1Expanded()
constexpr int kOverworldSpecialPALGroup
struct yaze::zelda3::OverworldMapTiles OverworldMapTiles
Overworld map tile32 data.
int GetOverworldTransitionPositionXExpanded()
constexpr int kOverworldPalettesScreenToSetNew
constexpr int kOverworldMessagesExpanded
constexpr int kOverworldScreenTileMapChangeByScreen3Expanded
constexpr int kOverlayData2
constexpr int transition_target_northExpanded
constexpr int kOverworldSpecialSpritePalette
constexpr int OverworldCustomAnimatedGFXArray
constexpr int kDarkWorldMapIdStart
constexpr int OverworldCustomMosaicEnabled
constexpr int kOverworldScreenTileMapChangeByScreen4Expanded
constexpr int kOverworldSpecialSpriteGFXGroup
constexpr int kOverworldScreenTileMapChangeByScreen1Expanded
constexpr int OverworldCustomTileGFXGroupArray
constexpr int OverworldCustomSubscreenOverlayEnabled
constexpr int OverworldCustomAreaSpecificBGPalette
int GetOverworldMessagesExpanded()
constexpr int kOverlayPointers
int GetOverworldScreenChange2Expanded()
constexpr int kOverlayCodeStart
int GetOverworldTransitionPositionYExpanded()
constexpr int kOverworldSpecialGFXGroup
constexpr int OverworldCustomSubscreenOverlayArray
Represents a group of palettes.
zelda3_version version
Definition game_data.h:79
Overworld map tile32 data.
ROM data pointers for different game versions.
Definition zelda.h:71