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
187 auto current_graphics() const { return current_gfx_; }
188 auto current_palette() const { return current_palette_; }
189 auto bitmap_data() const { return bitmap_data_; }
190 auto is_large_map() const { return large_map_; }
191 auto is_initialized() const { return initialized_; }
192 auto is_built() const { return built_; }
193 auto parent() const { return parent_; }
194 auto mutable_mosaic() { return &mosaic_; }
196
197 void SetNotBuilt() { built_ = false; }
198
199 auto area_graphics() const { return area_graphics_; }
200 auto area_palette() const { return area_palette_; }
201 auto sprite_graphics(int i) const { return sprite_graphics_[i]; }
202 auto sprite_palette(int i) const { return sprite_palette_[i]; }
203 auto message_id() const { return message_id_; }
204 auto area_music(int i) const { return area_music_[i]; }
205 auto static_graphics(int i) const { return static_graphics_[i]; }
206 auto large_index() const { return large_index_; }
207 auto area_size() const { return area_size_; }
208 auto main_gfx_id() const { return main_gfx_id_; }
209
210 auto main_palette() const { return main_palette_; }
211 void set_main_palette(uint8_t palette) { main_palette_ = palette; }
212
214 void set_area_specific_bg_color(uint16_t color) {
216 }
217
218 auto subscreen_overlay() const { return subscreen_overlay_; }
219 void set_subscreen_overlay(uint16_t overlay) { subscreen_overlay_ = overlay; }
220
221 auto animated_gfx() const { return animated_gfx_; }
222 void set_animated_gfx(uint8_t gfx) { animated_gfx_ = gfx; }
223
224 auto game_state() const { return game_state_; }
225 void set_game_state(int state) { game_state_ = state; }
226
227 auto custom_tileset(int index) const { return custom_gfx_ids_[index]; }
228
229 // Overlay accessors (interactive overlays)
230 auto overlay_id() const { return overlay_id_; }
231 auto has_overlay() const { return has_overlay_; }
232 const auto& overlay_data() const { return overlay_data_; }
233
234 // Mosaic expanded accessors
235 const std::array<bool, 4>& mosaic_expanded() const {
236 return mosaic_expanded_;
237 }
238 void set_mosaic_expanded(int index, bool value) {
239 mosaic_expanded_[index] = value;
240 }
241 void set_custom_tileset(int index, uint8_t value) {
242 custom_gfx_ids_[index] = value;
243 }
244
248 auto mutable_sprite_graphics(int i) { return &sprite_graphics_[i]; }
249 auto mutable_sprite_palette(int i) { return &sprite_palette_[i]; }
250 auto mutable_message_id() { return &message_id_; }
254 auto mutable_area_music(int i) { return &area_music_[i]; }
255 auto mutable_static_graphics(int i) { return &static_graphics_[i]; }
256
257 auto set_area_graphics(uint8_t value) { area_graphics_ = value; }
258 auto set_area_palette(uint8_t value) { area_palette_ = value; }
259 auto set_sprite_graphics(int i, uint8_t value) {
260 sprite_graphics_[i] = value;
261 }
262 auto set_sprite_palette(int i, uint8_t value) { sprite_palette_[i] = value; }
263 auto set_message_id(uint16_t value) { message_id_ = value; }
264
265 uint8_t* mutable_custom_tileset(int index) { return &custom_gfx_ids_[index]; }
266
267 void SetAsLargeMap(int parent_index, int quadrant) {
268 parent_ = parent_index;
269 large_index_ = quadrant;
270 large_map_ = true;
272 }
273
274 void SetAsSmallMap(int index = -1) {
275 if (index != -1)
276 parent_ = index;
277 else
278 parent_ = index_;
279 large_index_ = 0;
280 large_map_ = false;
282 }
283
285 area_size_ = size;
287 }
288
289 void SetParent(int parent_index) { parent_ = parent_index; }
290
298 void Destroy() {
299 // Free memory-heavy data
300 current_blockset_.clear();
301 current_gfx_.clear();
302 bitmap_data_.clear();
303 map_tiles_.light_world.clear();
304 map_tiles_.dark_world.clear();
306
307 // Reset build state (allows rebuild)
308 built_ = false;
309 initialized_ = false;
310
311 // Reset runtime state (will be recomputed on rebuild)
312 world_ = 0;
313 game_state_ = 0;
314 main_gfx_id_ = 0;
315
316 // NOTE: Do NOT reset these identity fields - they are needed for rebuild:
317 // - index_: Map's position in overworld array (used for ROM lookups)
318 // - parent_: Map's parent relationship (for large maps)
319 // - rom_: ROM pointer (needed for data access)
320 // - large_map_, large_index_, area_size_: Map structure info
321 // - message_id_, area_graphics_, area_palette_, etc: Loaded from ROM on rebuild
322 }
323
324 private:
325 void LoadAreaInfo();
327 void SetupCustomTileset(uint8_t asm_version);
328
329 void LoadMainBlocksetId();
331 void LoadMainBlocksets();
334 uint8_t ComputeWorldBasedMainPalette() const;
335
336 void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size,
337 const uint8_t* all_gfx);
338 absl::StatusOr<gfx::SnesPalette> GetPalette(const gfx::PaletteGroup& group,
339 int index, int previous_index,
340 int limit);
341
342 // Helper to get version constants from game_data or default to US
344 return kVersionConstantsMap.at(game_data_ ? game_data_->version : zelda3_version::US);
345 }
346
349
350 bool built_ = false;
351 bool large_map_ = false;
352 bool initialized_ = false;
353 bool mosaic_ = false;
354
355 int index_ = 0; // Map index
356 int parent_ = 0; // Parent map index
357 int large_index_ = 0; // Quadrant ID [0-3]
358 int world_ = 0; // World ID [0-2]
359 int game_state_ = 0; // Game state [0-2]
360 int main_gfx_id_ = 0; // Main Gfx ID
362
363 uint16_t message_id_ = 0;
364 uint8_t area_graphics_ = 0;
365 uint8_t area_palette_ = 0;
366 uint8_t main_palette_ = 0; // Custom Overworld Main Palette ID
367 uint8_t animated_gfx_ = 0; // Custom Overworld Animated ID
368 uint16_t subscreen_overlay_ = 0; // Custom Overworld Subscreen Overlay ID
370 0; // Custom Overworld Area-Specific Background Color
371
372 std::array<uint8_t, 8> custom_gfx_ids_;
373 std::array<uint8_t, 3> sprite_graphics_;
374 std::array<uint8_t, 3> sprite_palette_;
375 std::array<uint8_t, 4> area_music_;
376 std::array<uint8_t, 16> static_graphics_;
377
378 std::array<bool, 4> mosaic_expanded_;
379
380 // Overlay support (interactive overlays that reveal holes/change elements)
381 uint16_t overlay_id_ = 0;
382 bool has_overlay_ = false;
383 std::vector<uint8_t> overlay_data_;
384
385 std::vector<uint8_t> current_blockset_;
386 std::vector<uint8_t> current_gfx_;
387 std::vector<uint8_t> bitmap_data_;
388
391};
392
393} // namespace zelda3
394} // namespace yaze
395
396#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)
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
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 current_tile16_blockset() const
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_
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)
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:78
Overworld map tile32 data.
ROM data pointers for different game versions.
Definition zelda.h:71