yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld.cc
Go to the documentation of this file.
1#include "overworld.h"
2
3#include <algorithm>
4#include <future>
5#include <unordered_map>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "app/core/features.h"
10#include "app/gfx/compression.h"
11#include "app/gfx/snes_tile.h"
12#include "app/rom.h"
13#include "util/hex.h"
14#include "util/log.h"
15#include "util/macro.h"
16
17namespace yaze {
18namespace zelda3 {
19
20absl::Status Overworld::Load(Rom &rom) {
21 if (rom.size() == 0) {
22 return absl::InvalidArgumentError("ROM file not loaded");
23 }
24 rom_ = rom;
25
29
30 for (int map_index = 0; map_index < kNumOverworldMaps; ++map_index)
31 overworld_maps_.emplace_back(map_index, rom_);
32
40
41 is_loaded_ = true;
42 return absl::OkStatus();
43}
44
46 for (int i = 128; i < 145; i++) {
47 overworld_maps_[i].SetAsSmallMap(0);
48 }
49
50 overworld_maps_[129].SetAsLargeMap(129, 0);
51 overworld_maps_[130].SetAsLargeMap(129, 1);
52 overworld_maps_[137].SetAsLargeMap(129, 2);
53 overworld_maps_[138].SetAsLargeMap(129, 3);
54 overworld_maps_[136].SetAsSmallMap();
55
56 std::array<bool, kNumMapsPerWorld> map_checked;
57 std::fill(map_checked.begin(), map_checked.end(), false);
58
59 int xx = 0;
60 int yy = 0;
61 while (true) {
62 if (int i = xx + (yy * 8); map_checked[i] == false) {
63 if (overworld_maps_[i].is_large_map()) {
64 map_checked[i] = true;
65 overworld_maps_[i].SetAsLargeMap(i, 0);
66 overworld_maps_[i + 64].SetAsLargeMap(i + 64, 0);
67
68 map_checked[i + 1] = true;
69 overworld_maps_[i + 1].SetAsLargeMap(i, 1);
70 overworld_maps_[i + 65].SetAsLargeMap(i + 64, 1);
71
72 map_checked[i + 8] = true;
73 overworld_maps_[i + 8].SetAsLargeMap(i, 2);
74 overworld_maps_[i + 72].SetAsLargeMap(i + 64, 2);
75
76 map_checked[i + 9] = true;
77 overworld_maps_[i + 9].SetAsLargeMap(i, 3);
78 overworld_maps_[i + 73].SetAsLargeMap(i + 64, 3);
79 xx++;
80 } else {
81 overworld_maps_[i].SetAsSmallMap();
82 overworld_maps_[i + 64].SetAsSmallMap();
83 map_checked[i] = true;
84 }
85 }
86
87 xx++;
88 if (xx >= 8) {
89 xx = 0;
90 yy += 1;
91 if (yy >= 8) {
92 break;
93 }
94 }
95 }
96}
97
98absl::StatusOr<uint16_t> Overworld::GetTile16ForTile32(
99 int index, int quadrant, int dimension, const uint32_t *map32address) {
100 ASSIGN_OR_RETURN(auto arg1,
101 rom_.ReadByte(map32address[dimension] + quadrant + (index)));
102 ASSIGN_OR_RETURN(auto arg2, rom_.ReadWord(map32address[dimension] + (index) +
103 (quadrant <= 1 ? 4 : 5)));
104 return (uint16_t)(arg1 +
105 (((arg2 >> (quadrant % 2 == 0 ? 4 : 0)) & 0x0F) * 256));
106}
107
109 constexpr int kMap32TilesLength = 0x33F0;
110 int num_tile32 = kMap32TilesLength;
111 uint32_t map32address[4] = {rom_.version_constants().kMap32TileTL,
112 rom_.version_constants().kMap32TileTR,
113 rom_.version_constants().kMap32TileBL,
114 rom_.version_constants().kMap32TileBR};
115 if (rom()->data()[kMap32ExpandedFlagPos] != 0x04 &&
116 core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
117 map32address[0] = rom_.version_constants().kMap32TileTL;
118 map32address[1] = kMap32TileTRExpanded;
119 map32address[2] = kMap32TileBLExpanded;
120 map32address[3] = kMap32TileBRExpanded;
121 num_tile32 = kMap32TileCountExpanded;
122 expanded_tile32_ = true;
123 }
124
125 // Loop through each 32x32 pixel tile in the rom
126 for (int i = 0; i < num_tile32; i += 6) {
127 // Loop through each quadrant of the 32x32 pixel tile.
128 for (int k = 0; k < 4; k++) {
129 // Generate the 16-bit tile for the current quadrant of the current
130 // 32x32 pixel tile.
132 uint16_t tl,
133 GetTile16ForTile32(i, k, (int)Dimension::map32TilesTL, map32address));
135 uint16_t tr,
136 GetTile16ForTile32(i, k, (int)Dimension::map32TilesTR, map32address));
138 uint16_t bl,
139 GetTile16ForTile32(i, k, (int)Dimension::map32TilesBL, map32address));
141 uint16_t br,
142 GetTile16ForTile32(i, k, (int)Dimension::map32TilesBR, map32address));
143
144 // Add the generated 16-bit tiles to the tiles32 vector.
145 tiles32_unique_.emplace_back(gfx::Tile32(tl, tr, bl, br));
146 }
147 }
148
149 map_tiles_.light_world.resize(0x200);
150 map_tiles_.dark_world.resize(0x200);
151 map_tiles_.special_world.resize(0x200);
152 for (int i = 0; i < 0x200; i++) {
153 map_tiles_.light_world[i].resize(0x200);
154 map_tiles_.dark_world[i].resize(0x200);
155 map_tiles_.special_world[i].resize(0x200);
156 }
157
158 return absl::OkStatus();
159}
160
162 int tpos = kMap16Tiles;
163 int num_tile16 = kNumTile16Individual;
164 if (rom()->data()[kMap16ExpandedFlagPos] != 0x0F &&
165 core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
166 tpos = kMap16TilesExpanded;
167 num_tile16 = NumberOfMap16Ex;
168 expanded_tile16_ = true;
169 }
170
171 for (int i = 0; i < num_tile16; i += 1) {
172 ASSIGN_OR_RETURN(auto t0_data, rom()->ReadWord(tpos));
173 gfx::TileInfo t0 = gfx::GetTilesInfo(t0_data);
174 tpos += 2;
175 ASSIGN_OR_RETURN(auto t1_data, rom()->ReadWord(tpos));
176 gfx::TileInfo t1 = gfx::GetTilesInfo(t1_data);
177 tpos += 2;
178 ASSIGN_OR_RETURN(auto t2_data, rom()->ReadWord(tpos));
179 gfx::TileInfo t2 = gfx::GetTilesInfo(t2_data);
180 tpos += 2;
181 ASSIGN_OR_RETURN(auto t3_data, rom()->ReadWord(tpos));
182 gfx::TileInfo t3 = gfx::GetTilesInfo(t3_data);
183 tpos += 2;
184 tiles16_.emplace_back(t0, t1, t2, t3);
185 }
186 return absl::OkStatus();
187}
188
189void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
190 OverworldBlockset &world) {
191 int position_x1 = (x * 2) + (sx * 32);
192 int position_y1 = (y * 2) + (sy * 32);
193 int position_x2 = (x * 2) + 1 + (sx * 32);
194 int position_y2 = (y * 2) + 1 + (sy * 32);
195 world[position_x1][position_y1] = tiles32_unique_[tpos].tile0_;
196 world[position_x2][position_y1] = tiles32_unique_[tpos].tile1_;
197 world[position_x1][position_y2] = tiles32_unique_[tpos].tile2_;
198 world[position_x2][position_y2] = tiles32_unique_[tpos].tile3_;
199}
200
201void Overworld::OrganizeMapTiles(std::vector<uint8_t> &bytes,
202 std::vector<uint8_t> &bytes2, int i, int sx,
203 int sy, int &ttpos) {
204 for (int y = 0; y < 16; y++) {
205 for (int x = 0; x < 16; x++) {
206 auto tidD = (uint16_t)((bytes2[ttpos] << 8) + bytes[ttpos]);
207 if (int tpos = tidD; tpos < tiles32_unique_.size()) {
208 if (i < kDarkWorldMapIdStart) {
209 AssignWorldTiles(x, y, sx, sy, tpos, map_tiles_.light_world);
210 } else if (i < kSpecialWorldMapIdStart && i >= kDarkWorldMapIdStart) {
211 AssignWorldTiles(x, y, sx, sy, tpos, map_tiles_.dark_world);
212 } else {
213 AssignWorldTiles(x, y, sx, sy, tpos, map_tiles_.special_world);
214 }
215 }
216 ttpos += 1;
217 }
218 }
219}
220
222 const auto get_ow_map_gfx_ptr = [this](int index, uint32_t map_ptr) {
223 int p = (rom()->data()[map_ptr + 2 + (3 * index)] << 16) +
224 (rom()->data()[map_ptr + 1 + (3 * index)] << 8) +
225 (rom()->data()[map_ptr + (3 * index)]);
226 return SnesToPc(p);
227 };
228
229 constexpr uint32_t kBaseLowest = 0x0FFFFF;
230 constexpr uint32_t kBaseHighest = 0x0F8000;
231
232 uint32_t lowest = kBaseLowest;
233 uint32_t highest = kBaseHighest;
234 int sx = 0;
235 int sy = 0;
236 int c = 0;
237 for (int i = 0; i < kNumOverworldMaps; i++) {
238 auto p1 = get_ow_map_gfx_ptr(
239 i, rom()->version_constants().kCompressedAllMap32PointersHigh);
240 auto p2 = get_ow_map_gfx_ptr(
241 i, rom()->version_constants().kCompressedAllMap32PointersLow);
242
243 int ttpos = 0;
244
245 if (p1 >= highest) highest = p1;
246 if (p2 >= highest) highest = p2;
247
248 if (p1 <= lowest && p1 > kBaseHighest) lowest = p1;
249 if (p2 <= lowest && p2 > kBaseHighest) lowest = p2;
250
251 int size1, size2;
252 auto bytes = gfx::HyruleMagicDecompress(rom()->data() + p2, &size1, 1);
253 auto bytes2 = gfx::HyruleMagicDecompress(rom()->data() + p1, &size2, 1);
254 OrganizeMapTiles(bytes, bytes2, i, sx, sy, ttpos);
255
256 sx++;
257 if (sx >= 8) {
258 sy++;
259 sx = 0;
260 }
261
262 c++;
263 if (c >= 64) {
264 sx = 0;
265 sy = 0;
266 c = 0;
267 }
268 }
269}
270
272 auto size = tiles16_.size();
273 std::vector<std::future<absl::Status>> futures;
274 for (int i = 0; i < kNumOverworldMaps; ++i) {
275 int world_type = 0;
277 world_type = 1;
278 } else if (i >= kSpecialWorldMapIdStart) {
279 world_type = 2;
280 }
281 auto task_function = [this, i, size, world_type]() {
282 return overworld_maps_[i].BuildMap(size, game_state_, world_type,
283 tiles16_, GetMapTiles(world_type));
284 };
285 futures.emplace_back(std::async(std::launch::async, task_function));
286 }
287
288 // Wait for all tasks to complete and check their results
289 for (auto &future : futures) {
290 future.wait();
291 RETURN_IF_ERROR(future.get());
292 }
293 return absl::OkStatus();
294}
295
297 for (int i = 0; i < kNumTileTypes; ++i) {
299 rom()->data()[rom()->version_constants().kOverworldTilesType + i];
300 }
301}
302
304 int ow_entrance_map_ptr = kOverworldEntranceMap;
305 int ow_entrance_pos_ptr = kOverworldEntrancePos;
306 int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
307 int num_entrances = 129;
308 if (rom()->data()[kOverworldEntranceExpandedFlagPos] != 0xB8 &&
309 core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
310 ow_entrance_map_ptr = kOverworldEntranceMapExpanded;
311 ow_entrance_pos_ptr = kOverworldEntrancePosExpanded;
312 ow_entrance_id_ptr = kOverworldEntranceEntranceIdExpanded;
313 expanded_entrances_ = true;
314 }
315
316 for (int i = 0; i < num_entrances; i++) {
317 ASSIGN_OR_RETURN(auto map_id,
318 rom()->ReadWord(ow_entrance_map_ptr + (i * 2)));
319 ASSIGN_OR_RETURN(auto map_pos,
320 rom()->ReadWord(ow_entrance_pos_ptr + (i * 2)));
321 ASSIGN_OR_RETURN(auto entrance_id, rom()->ReadByte(ow_entrance_id_ptr + i));
322 int p = map_pos >> 1;
323 int x = (p % 64);
324 int y = (p >> 6);
325 bool deleted = false;
326 if (map_pos == 0xFFFF) {
327 deleted = true;
328 }
329 all_entrances_.emplace_back(
330 (x * 16) + (((map_id % 64) - (((map_id % 64) / 8) * 8)) * 512),
331 (y * 16) + (((map_id % 64) / 8) * 512), entrance_id, map_id, map_pos,
332 deleted);
333 }
334
335 return absl::OkStatus();
336}
337
338absl::Status Overworld::LoadHoles() {
339 constexpr int kNumHoles = 0x13;
340 for (int i = 0; i < kNumHoles; i++) {
341 ASSIGN_OR_RETURN(auto map_id,
342 rom()->ReadWord(kOverworldHoleArea + (i * 2)));
343 ASSIGN_OR_RETURN(auto map_pos,
344 rom()->ReadWord(kOverworldHolePos + (i * 2)));
345 ASSIGN_OR_RETURN(auto entrance_id,
346 rom()->ReadByte(kOverworldHoleEntrance + i));
347 int p = (map_pos + 0x400) >> 1;
348 int x = (p % 64);
349 int y = (p >> 6);
350 all_holes_.emplace_back(
351 (x * 16) + (((map_id % 64) - (((map_id % 64) / 8) * 8)) * 512),
352 (y * 16) + (((map_id % 64) / 8) * 512), entrance_id, map_id,
353 (uint16_t)(map_pos + 0x400), true);
354 }
355 return absl::OkStatus();
356}
357
358absl::Status Overworld::LoadExits() {
359 const int NumberOfOverworldExits = 0x4F;
360 std::vector<OverworldExit> exits;
361 for (int i = 0; i < NumberOfOverworldExits; i++) {
362 auto rom_data = rom()->data();
363
364 uint16_t exit_room_id;
365 uint16_t exit_map_id;
366 uint16_t exit_vram;
367 uint16_t exit_y_scroll;
368 uint16_t exit_x_scroll;
369 uint16_t exit_y_player;
370 uint16_t exit_x_player;
371 uint16_t exit_y_camera;
372 uint16_t exit_x_camera;
373 uint16_t exit_scroll_mod_y;
374 uint16_t exit_scroll_mod_x;
375 uint16_t exit_door_type_1;
376 uint16_t exit_door_type_2;
377 RETURN_IF_ERROR(rom()->ReadTransaction(
378 exit_room_id, (OWExitRoomId + (i * 2)), exit_map_id, OWExitMapId + i,
379 exit_vram, OWExitVram + (i * 2), exit_y_scroll, OWExitYScroll + (i * 2),
380 exit_x_scroll, OWExitXScroll + (i * 2), exit_y_player,
381 OWExitYPlayer + (i * 2), exit_x_player, OWExitXPlayer + (i * 2),
382 exit_y_camera, OWExitYCamera + (i * 2), exit_x_camera,
383 OWExitXCamera + (i * 2), exit_scroll_mod_y, OWExitUnk1 + i,
384 exit_scroll_mod_x, OWExitUnk2 + i, exit_door_type_1,
385 OWExitDoorType1 + (i * 2), exit_door_type_2,
386 OWExitDoorType2 + (i * 2)));
387
388 uint16_t py = (uint16_t)((rom_data[OWExitYPlayer + (i * 2) + 1] << 8) +
389 rom_data[OWExitYPlayer + (i * 2)]);
390 uint16_t px = (uint16_t)((rom_data[OWExitXPlayer + (i * 2) + 1] << 8) +
391 rom_data[OWExitXPlayer + (i * 2)]);
392
393 util::logf(
394 "Exit: %d RoomID: %d MapID: %d VRAM: %d YScroll: %d XScroll: "
395 "%d YPlayer: %d XPlayer: %d YCamera: %d XCamera: %d "
396 "ScrollModY: %d ScrollModX: %d DoorType1: %d DoorType2: %d",
397 i, exit_room_id, exit_map_id, exit_vram, exit_y_scroll, exit_x_scroll,
398 py, px, exit_y_camera, exit_x_camera, exit_scroll_mod_y,
399 exit_scroll_mod_x, exit_door_type_1, exit_door_type_2);
400
401 exits.emplace_back(exit_room_id, exit_map_id, exit_vram, exit_y_scroll,
402 exit_x_scroll, py, px, exit_y_camera, exit_x_camera,
403 exit_scroll_mod_y, exit_scroll_mod_x, exit_door_type_1,
404 exit_door_type_2, (px & py) == 0xFFFF);
405 }
407 return absl::OkStatus();
408}
409
410absl::Status Overworld::LoadItems() {
411 ASSIGN_OR_RETURN(uint32_t pointer,
413 uint32_t pointer_pc = SnesToPc(pointer); // 1BC2F9 -> 0DC2F9
414 for (int i = 0; i < 128; i++) {
415 ASSIGN_OR_RETURN(uint16_t word_address,
416 rom()->ReadWord(pointer_pc + i * 2));
417 uint32_t addr = (pointer & 0xFF0000) | word_address; // 1B F9 3C
418 addr = SnesToPc(addr);
419
420 if (overworld_maps_[i].is_large_map()) {
421 if (overworld_maps_[i].parent() != (uint8_t)i) {
422 continue;
423 }
424 }
425
426 while (true) {
427 ASSIGN_OR_RETURN(uint8_t b1, rom()->ReadByte(addr));
428 ASSIGN_OR_RETURN(uint8_t b2, rom()->ReadByte(addr + 1));
429 ASSIGN_OR_RETURN(uint8_t b3, rom()->ReadByte(addr + 2));
430
431 if (b1 == 0xFF && b2 == 0xFF) {
432 break;
433 }
434
435 int p = (((b2 & 0x1F) << 8) + b1) >> 1;
436
437 int x = p % 64;
438 int y = p >> 6;
439
440 int fakeID = i;
441 if (fakeID >= 64) {
442 fakeID -= 64;
443 }
444
445 int sy = fakeID / 8;
446 int sx = fakeID - (sy * 8);
447
448 all_items_.emplace_back(b3, (uint16_t)i, (x * 16) + (sx * 512),
449 (y * 16) + (sy * 512), false);
450 auto size = all_items_.size();
451
452 all_items_[size - 1].game_x_ = (uint8_t)x;
453 all_items_[size - 1].game_y_ = (uint8_t)y;
454 addr += 3;
455 }
456 }
457 return absl::OkStatus();
458}
459
461 std::vector<std::future<absl::Status>> futures;
462 futures.emplace_back(std::async(std::launch::async, [this]() {
464 }));
465 futures.emplace_back(std::async(std::launch::async, [this]() {
467 }));
468 futures.emplace_back(std::async(std::launch::async, [this]() {
470 }));
471
472 for (auto &future : futures) {
473 future.wait();
474 RETURN_IF_ERROR(future.get());
475 }
476 return absl::OkStatus();
477}
478
479absl::Status Overworld::LoadSpritesFromMap(int sprites_per_gamestate_ptr,
480 int num_maps_per_gamestate,
481 int game_state) {
482 for (int i = 0; i < num_maps_per_gamestate; i++) {
483 if (map_parent_[i] != i) continue;
484
485 int current_spr_ptr = sprites_per_gamestate_ptr + (i * 2);
486 ASSIGN_OR_RETURN(auto word_addr, rom()->ReadWord(current_spr_ptr));
487 int sprite_address = SnesToPc((0x09 << 0x10) | word_addr);
488 while (true) {
489 ASSIGN_OR_RETURN(uint8_t b1, rom()->ReadByte(sprite_address));
490 ASSIGN_OR_RETURN(uint8_t b2, rom()->ReadByte(sprite_address + 1));
491 ASSIGN_OR_RETURN(uint8_t b3, rom()->ReadByte(sprite_address + 2));
492 if (b1 == 0xFF) break;
493
494 int editor_map_index = i;
495 if (game_state != 0) {
496 if (editor_map_index >= 128)
497 editor_map_index -= 128;
498 else if (editor_map_index >= 64)
499 editor_map_index -= 64;
500 }
501 int mapY = (editor_map_index / 8);
502 int mapX = (editor_map_index % 8);
503
504 int realX = ((b2 & 0x3F) * 16) + mapX * 512;
505 int realY = ((b1 & 0x3F) * 16) + mapY * 512;
506 all_sprites_[game_state].emplace_back(
507 *overworld_maps_[i].mutable_current_graphics(), (uint8_t)i, b3,
508 (uint8_t)(b2 & 0x3F), (uint8_t)(b1 & 0x3F), realX, realY);
509 all_sprites_[game_state][i].Draw();
510
511 sprite_address += 3;
512 }
513 }
514
515 return absl::OkStatus();
516}
517
529
531 util::logf("Saving Overworld Maps");
532
533 // Initialize map pointers
534 std::fill(map_pointers1_id.begin(), map_pointers1_id.end(), -1);
535 std::fill(map_pointers2_id.begin(), map_pointers2_id.end(), -1);
536
537 // Compress and save each map
539 for (int i = 0; i < kNumOverworldMaps; i++) {
540 std::vector<uint8_t> single_map_1(512);
541 std::vector<uint8_t> single_map_2(512);
542
543 // Copy tiles32 data to single_map_1 and single_map_2
544 int npos = 0;
545 for (int y = 0; y < 16; y++) {
546 for (int x = 0; x < 16; x++) {
547 auto packed = tiles32_list_[npos + (i * 256)];
548 single_map_1[npos] = packed & 0xFF; // Lower 8 bits
549 single_map_2[npos] = (packed >> 8) & 0xFF; // Next 8 bits
550 npos++;
551 }
552 }
553
554 int size_a, size_b;
555 // Compress single_map_1 and single_map_2
556 auto a = gfx::HyruleMagicCompress(single_map_1.data(), 256, &size_a, 1);
557 auto b = gfx::HyruleMagicCompress(single_map_2.data(), 256, &size_b, 1);
558 if (a.empty() || b.empty()) {
559 return absl::AbortedError("Error compressing map gfx.");
560 }
561
562 // Save compressed data and pointers
563 map_data_p1[i] = std::vector<uint8_t>(size_a);
564 map_data_p2[i] = std::vector<uint8_t>(size_b);
565
566 if ((pos + size_a) >= 0x5FE70 && (pos + size_a) <= 0x60000) {
567 pos = 0x60000;
568 }
569
570 if ((pos + size_a) >= 0x6411F && (pos + size_a) <= 0x70000) {
571 util::logf("Pos set to overflow region for map %s at %s",
572 std::to_string(i), util::HexLong(pos));
573 pos = kOverworldMapDataOverflow; // 0x0F8780;
574 }
575
576 const auto compare_array = [](const std::vector<uint8_t> &array1,
577 const std::vector<uint8_t> &array2) -> bool {
578 if (array1.size() != array2.size()) {
579 return false;
580 }
581
582 for (size_t i = 0; i < array1.size(); i++) {
583 if (array1[i] != array2[i]) {
584 return false;
585 }
586 }
587
588 return true;
589 };
590
591 for (int j = 0; j < i; j++) {
592 if (compare_array(a, map_data_p1[j])) {
593 // Reuse pointer id j for P1 (a)
594 map_pointers1_id[i] = j;
595 }
596
597 if (compare_array(b, map_data_p2[j])) {
598 map_pointers2_id[i] = j;
599 // Reuse pointer id j for P2 (b)
600 }
601 }
602
603 if (map_pointers1_id[i] == -1) {
604 // Save compressed data and pointer for map1
605 std::copy(a.begin(), a.end(), map_data_p1[i].begin());
606 int snes_pos = PcToSnes(pos);
607 map_pointers1[i] = snes_pos;
608 util::logf("Saving map pointers1 and compressed data for map %s at %s",
609 util::HexByte(i), util::HexLong(snes_pos));
610 RETURN_IF_ERROR(rom()->WriteLong(
611 rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
612 snes_pos));
613 RETURN_IF_ERROR(rom()->WriteVector(pos, a));
614 pos += size_a;
615 } else {
616 // Save pointer for map1
617 int snes_pos = map_pointers1[map_pointers1_id[i]];
618 util::logf("Saving map pointers1 for map %s at %s", util::HexByte(i),
619 util::HexLong(snes_pos));
620 RETURN_IF_ERROR(rom()->WriteLong(
621 rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
622 snes_pos));
623 }
624
625 if ((pos + b.size()) >= 0x5FE70 && (pos + b.size()) <= 0x60000) {
626 pos = 0x60000;
627 }
628
629 if ((pos + b.size()) >= 0x6411F && (pos + b.size()) <= 0x70000) {
630 util::logf("Pos set to overflow region for map %s at %s",
633 }
634
635 if (map_pointers2_id[i] == -1) {
636 // Save compressed data and pointer for map2
637 std::copy(b.begin(), b.end(), map_data_p2[i].begin());
638 int snes_pos = PcToSnes(pos);
639 map_pointers2[i] = snes_pos;
640 util::logf("Saving map pointers2 and compressed data for map %s at %s",
641 util::HexByte(i), util::HexLong(snes_pos));
642 RETURN_IF_ERROR(rom()->WriteLong(
643 rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
644 snes_pos));
645 RETURN_IF_ERROR(rom()->WriteVector(pos, b));
646 pos += size_b;
647 } else {
648 // Save pointer for map2
649 int snes_pos = map_pointers2[map_pointers2_id[i]];
650 util::logf("Saving map pointers2 for map %s at %s", util::HexByte(i),
651 util::HexLong(snes_pos));
652 RETURN_IF_ERROR(rom()->WriteLong(
653 rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
654 snes_pos));
655 }
656 }
657
658 // Check if too many maps data
660 util::logf("Too many maps data %s", util::HexLong(pos));
661 return absl::AbortedError("Too many maps data " + std::to_string(pos));
662 }
663
665 return absl::OkStatus();
666}
667
669 util::logf("Saving Large Maps");
670 std::vector<uint8_t> checked_map;
671
672 for (int i = 0; i < kNumMapsPerWorld; ++i) {
673 int y_pos = i / 8;
674 int x_pos = i % 8;
675 int parent_y_pos = overworld_maps_[i].parent() / 8;
676 int parent_x_pos = overworld_maps_[i].parent() % 8;
677
678 // Always write the map parent since it should not matter
680 overworld_maps_[i].parent()))
681
682 if (std::find(checked_map.begin(), checked_map.end(), i) !=
683 checked_map.end()) {
684 continue;
685 }
686
687 // If it's large then save parent pos *
688 // 0x200 otherwise pos * 0x200
689 if (overworld_maps_[i].is_large_map()) {
690 const uint8_t large_map_offsets[] = {0, 1, 8, 9};
691 for (const auto &offset : large_map_offsets) {
692 // Check 1
693 RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapSize + i + offset, 0x20));
694 // Check 2
696 rom()->WriteByte(kOverworldMapSizeHighByte + i + offset, 0x03));
697 // Check 3
699 rom()->WriteByte(kOverworldScreenSize + i + offset, 0x00));
701 rom()->WriteByte(kOverworldScreenSize + i + offset + 64, 0x00));
702 // Check 4
703 RETURN_IF_ERROR(rom()->WriteByte(
704 kOverworldScreenSizeForLoading + i + offset, 0x04));
705 RETURN_IF_ERROR(rom()->WriteByte(
707 0x04));
710 0x04));
711 }
712
713 // Check 5 and 6
715 rom()->WriteShort(kTransitionTargetNorth + (i * 2),
716 (uint16_t)((parent_y_pos * 0x200) - 0xE0)));
718 rom()->WriteShort(kTransitionTargetWest + (i * 2),
719 (uint16_t)((parent_x_pos * 0x200) - 0x100)));
720
722 rom()->WriteShort(kTransitionTargetNorth + (i * 2) + 2,
723 (uint16_t)((parent_y_pos * 0x200) - 0xE0)));
725 rom()->WriteShort(kTransitionTargetWest + (i * 2) + 2,
726 (uint16_t)((parent_x_pos * 0x200) - 0x100)));
727
729 rom()->WriteShort(kTransitionTargetNorth + (i * 2) + 16,
730 (uint16_t)((parent_y_pos * 0x200) - 0xE0)));
732 rom()->WriteShort(kTransitionTargetWest + (i * 2) + 16,
733 (uint16_t)((parent_x_pos * 0x200) - 0x100)));
734
736 rom()->WriteShort(kTransitionTargetNorth + (i * 2) + 18,
737 (uint16_t)((parent_y_pos * 0x200) - 0xE0)));
739 rom()->WriteShort(kTransitionTargetWest + (i * 2) + 18,
740 (uint16_t)((parent_x_pos * 0x200) - 0x100)));
741
742 // Check 7 and 8
743 RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionX + (i * 2),
744 (parent_x_pos * 0x200)));
745 RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionY + (i * 2),
746 (parent_y_pos * 0x200)));
747
749 rom()->WriteShort(kOverworldTransitionPositionX + (i * 2) + 02,
750 (parent_x_pos * 0x200)));
752 rom()->WriteShort(kOverworldTransitionPositionY + (i * 2) + 02,
753 (parent_y_pos * 0x200)));
754
755 // problematic
757 rom()->WriteShort(kOverworldTransitionPositionX + (i * 2) + 16,
758 (parent_x_pos * 0x200)));
760 rom()->WriteShort(kOverworldTransitionPositionY + (i * 2) + 16,
761 (parent_y_pos * 0x200)));
762
764 rom()->WriteShort(kOverworldTransitionPositionX + (i * 2) + 18,
765 (parent_x_pos * 0x200)));
767 rom()->WriteShort(kOverworldTransitionPositionY + (i * 2) + 18,
768 (parent_y_pos * 0x200)));
769
770 // Check 9
771 RETURN_IF_ERROR(rom()->WriteShort(
772 kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 00, 0x0060));
773 RETURN_IF_ERROR(rom()->WriteShort(
774 kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 02, 0x0060));
775
776 // If parentX == 0 then lower submaps == 0x0060 too
777 if (parent_x_pos == 0) {
778 RETURN_IF_ERROR(rom()->WriteShort(
779 kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 16, 0x0060));
780 RETURN_IF_ERROR(rom()->WriteShort(
781 kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 18, 0x0060));
782 } else {
783 // Otherwise lower submaps == 0x1060
784 RETURN_IF_ERROR(rom()->WriteShort(
785 kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 16, 0x1060));
786 RETURN_IF_ERROR(rom()->WriteShort(
787 kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 18, 0x1060));
788
789 // If the area to the left is a large map, we don't need to add an
790 // offset to it. otherwise leave it the same. Just to make sure where
791 // don't try to read outside of the array.
792 if ((i - 1) >= 0) {
793 // If the area to the left is a large area.
794 if (overworld_maps_[i - 1].is_large_map()) {
795 // If the area to the left is the bottom right of a large area.
796 if (overworld_maps_[i - 1].large_index() == 1) {
797 RETURN_IF_ERROR(rom()->WriteShort(
799 0x0060));
800 }
801 }
802 }
803 }
804
805 // Always 0x0080
806 RETURN_IF_ERROR(rom()->WriteShort(
807 kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 00, 0x0080));
808 RETURN_IF_ERROR(rom()->WriteShort(
809 kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 2, 0x0080));
810 // Lower always 0x1080
811 RETURN_IF_ERROR(rom()->WriteShort(
812 kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 16, 0x1080));
813 RETURN_IF_ERROR(rom()->WriteShort(
814 kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 18, 0x1080));
815
816 // If the area to the right is a large map, we don't need to add an offset
817 // to it. otherwise leave it the same. Just to make sure where don't try
818 // to read outside of the array.
819 if ((i + 2) < 64) {
820 // If the area to the right is a large area.
821 if (overworld_maps_[i + 2].is_large_map()) {
822 // If the area to the right is the top left of a large area.
823 if (overworld_maps_[i + 2].large_index() == 0) {
824 RETURN_IF_ERROR(rom()->WriteShort(
825 kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 18, 0x0080));
826 }
827 }
828 }
829
830 // Always 0x1800
831 RETURN_IF_ERROR(rom()->WriteShort(
832 kOverworldScreenTileMapChangeByScreen3 + (i * 2), 0x1800));
833 RETURN_IF_ERROR(rom()->WriteShort(
834 kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 16, 0x1800));
835 // Right side is always 0x1840
836 RETURN_IF_ERROR(rom()->WriteShort(
837 kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 2, 0x1840));
838 RETURN_IF_ERROR(rom()->WriteShort(
839 kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 18, 0x1840));
840
841 // If the area above is a large map, we don't need to add an offset to it.
842 // otherwise leave it the same.
843 // Just to make sure where don't try to read outside of the array.
844 if (i - 8 >= 0) {
845 // If the area just above us is a large area.
846 if (overworld_maps_[i - 8].is_large_map()) {
847 // If the area just above us is the bottom left of a large area.
848 if (overworld_maps_[i - 8].large_index() == 2) {
849 RETURN_IF_ERROR(rom()->WriteShort(
850 kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 02, 0x1800));
851 }
852 }
853 }
854
855 // Always 0x2000
856 RETURN_IF_ERROR(rom()->WriteShort(
857 kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 00, 0x2000));
858 RETURN_IF_ERROR(rom()->WriteShort(
859 kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 16, 0x2000));
860 // Right side always 0x2040
861 RETURN_IF_ERROR(rom()->WriteShort(
862 kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 2, 0x2040));
863 RETURN_IF_ERROR(rom()->WriteShort(
864 kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 18, 0x2040));
865
866 // If the area below is a large map, we don't need to add an offset to it.
867 // otherwise leave it the same.
868 // Just to make sure where don't try to read outside of the array.
869 if (i + 16 < 64) {
870 // If the area just below us is a large area.
871 if (overworld_maps_[i + 16].is_large_map()) {
872 // If the area just below us is the top left of a large area.
873 if (overworld_maps_[i + 16].large_index() == 0) {
874 RETURN_IF_ERROR(rom()->WriteShort(
875 kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 18, 0x2000));
876 }
877 }
878 }
879
880 checked_map.emplace_back(i);
881 checked_map.emplace_back((i + 1));
882 checked_map.emplace_back((i + 8));
883 checked_map.emplace_back((i + 9));
884
885 } else {
886 RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapSize + i, 0x00));
887 RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapSizeHighByte + i, 0x01));
888
889 RETURN_IF_ERROR(rom()->WriteByte(kOverworldScreenSize + i, 0x01));
890 RETURN_IF_ERROR(rom()->WriteByte(kOverworldScreenSize + i + 64, 0x01));
891
893 rom()->WriteByte(kOverworldScreenSizeForLoading + i, 0x02));
894 RETURN_IF_ERROR(rom()->WriteByte(
896 RETURN_IF_ERROR(rom()->WriteByte(
898
899 RETURN_IF_ERROR(rom()->WriteShort(
900 kOverworldScreenTileMapChangeByScreen1 + (i * 2), 0x0060));
901
902 // If the area to the left is a large map, we don't need to add an offset
903 // to it. otherwise leave it the same.
904 // Just to make sure where don't try to read outside of the array.
905 if (i - 1 >= 0 && parent_x_pos != 0) {
906 if (overworld_maps_[i - 1].is_large_map()) {
907 if (overworld_maps_[i - 1].large_index() == 3) {
908 RETURN_IF_ERROR(rom()->WriteShort(
909 kOverworldScreenTileMapChangeByScreen1 + (i * 2), 0xF060));
910 }
911 }
912 }
913
914 RETURN_IF_ERROR(rom()->WriteShort(
915 kOverworldScreenTileMapChangeByScreen2 + (i * 2), 0x0040));
916
917 if (i + 1 < 64 && parent_x_pos != 7) {
918 if (overworld_maps_[i + 1].is_large_map()) {
919 if (overworld_maps_[i + 1].large_index() == 2) {
920 RETURN_IF_ERROR(rom()->WriteShort(
921 kOverworldScreenTileMapChangeByScreen2 + (i * 2), 0xF040));
922 }
923 }
924 }
925
926 RETURN_IF_ERROR(rom()->WriteShort(
927 kOverworldScreenTileMapChangeByScreen3 + (i * 2), 0x1800));
928
929 // If the area above is a large map, we don't need to add an offset to it.
930 // otherwise leave it the same.
931 // Just to make sure where don't try to read outside of the array.
932 if (i - 8 >= 0) {
933 // If the area just above us is a large area.
934 if (overworld_maps_[i - 8].is_large_map()) {
935 // If we are under the bottom right of the large area.
936 if (overworld_maps_[i - 8].large_index() == 3) {
937 RETURN_IF_ERROR(rom()->WriteShort(
938 kOverworldScreenTileMapChangeByScreen3 + (i * 2), 0x17C0));
939 }
940 }
941 }
942
943 RETURN_IF_ERROR(rom()->WriteShort(
944 kOverworldScreenTileMapChangeByScreen4 + (i * 2), 0x1000));
945
946 // If the area below is a large map, we don't need to add an offset to it.
947 // otherwise leave it the same.
948 // Just to make sure where don't try to read outside of the array.
949 if (i + 8 < 64) {
950 // If the area just below us is a large area.
951 if (overworld_maps_[i + 8].is_large_map()) {
952 // If we are on top of the top right of the large area.
953 if (overworld_maps_[i + 8].large_index() == 1) {
954 RETURN_IF_ERROR(rom()->WriteShort(
955 kOverworldScreenTileMapChangeByScreen4 + (i * 2), 0x0FC0));
956 }
957 }
958 }
959
960 RETURN_IF_ERROR(rom()->WriteShort(kTransitionTargetNorth + (i * 2),
961 (uint16_t)((y_pos * 0x200) - 0xE0)));
962 RETURN_IF_ERROR(rom()->WriteShort(kTransitionTargetWest + (i * 2),
963 (uint16_t)((x_pos * 0x200) - 0x100)));
964
965 RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionX + (i * 2),
966 (x_pos * 0x200)));
967 RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionY + (i * 2),
968 (y_pos * 0x200)));
969
970 checked_map.emplace_back(i);
971 }
972 }
973
974 constexpr int OverworldScreenTileMapChangeMask = 0x1262C;
975
977 rom()->WriteShort(OverworldScreenTileMapChangeMask + 0, 0x1F80));
979 rom()->WriteShort(OverworldScreenTileMapChangeMask + 2, 0x1F80));
981 rom()->WriteShort(OverworldScreenTileMapChangeMask + 4, 0x007F));
983 rom()->WriteShort(OverworldScreenTileMapChangeMask + 6, 0x007F));
984
985 return absl::OkStatus();
986}
987
988namespace {
989std::vector<uint64_t> GetAllTile16(OverworldMapTiles &map_tiles_) {
990 std::vector<uint64_t> all_tile_16; // Ensure it's 64 bits
991
992 int sx = 0;
993 int sy = 0;
994 int c = 0;
995 OverworldBlockset tiles_used;
996 for (int i = 0; i < kNumOverworldMaps; i++) {
997 if (i < kDarkWorldMapIdStart) {
998 tiles_used = map_tiles_.light_world;
999 } else if (i < kSpecialWorldMapIdStart && i >= kDarkWorldMapIdStart) {
1000 tiles_used = map_tiles_.dark_world;
1001 } else {
1002 tiles_used = map_tiles_.special_world;
1003 }
1004
1005 for (int y = 0; y < 32; y += 2) {
1006 for (int x = 0; x < 32; x += 2) {
1007 gfx::Tile32 current_tile(
1008 tiles_used[x + (sx * 32)][y + (sy * 32)],
1009 tiles_used[x + 1 + (sx * 32)][y + (sy * 32)],
1010 tiles_used[x + (sx * 32)][y + 1 + (sy * 32)],
1011 tiles_used[x + 1 + (sx * 32)][y + 1 + (sy * 32)]);
1012
1013 all_tile_16.emplace_back(current_tile.GetPackedValue());
1014 }
1015 }
1016
1017 sx++;
1018 if (sx >= 8) {
1019 sy++;
1020 sx = 0;
1021 }
1022
1023 c++;
1024 if (c >= 64) {
1025 sx = 0;
1026 sy = 0;
1027 c = 0;
1028 }
1029 }
1030
1031 return all_tile_16;
1032}
1033} // namespace
1034
1036 tiles32_unique_.clear();
1037 tiles32_list_.clear();
1038
1039 // Get all tiles16 and packs them into tiles32
1040 std::vector<uint64_t> all_tile_16 = GetAllTile16(map_tiles_);
1041
1042 // Convert to set then back to vector
1043 std::set<uint64_t> unique_tiles_set(all_tile_16.begin(), all_tile_16.end());
1044
1045 std::vector<uint64_t> unique_tiles(all_tile_16);
1046 unique_tiles.assign(unique_tiles_set.begin(), unique_tiles_set.end());
1047
1048 // Create the indexed tiles list
1049 std::unordered_map<uint64_t, uint16_t> all_tiles_indexed;
1050 for (size_t tile32_id = 0; tile32_id < unique_tiles.size(); tile32_id++) {
1051 all_tiles_indexed.insert(
1052 {unique_tiles[tile32_id], static_cast<uint16_t>(tile32_id)});
1053 }
1054
1055 // Add all tiles32 from all maps.
1056 // Convert all tiles32 non-unique IDs into unique array of IDs.
1057 for (int j = 0; j < NumberOfMap32; j++) {
1058 tiles32_list_.emplace_back(all_tiles_indexed[all_tile_16[j]]);
1059 }
1060
1061 // Create the unique tiles list
1062 for (size_t i = 0; i < unique_tiles.size(); ++i) {
1063 tiles32_unique_.emplace_back(gfx::Tile32(unique_tiles[i]));
1064 }
1065
1066 while (tiles32_unique_.size() % 4 != 0) {
1067 gfx::Tile32 padding_tile(0, 0, 0, 0);
1068 tiles32_unique_.emplace_back(padding_tile.GetPackedValue());
1069 }
1070
1071 if (tiles32_unique_.size() > LimitOfMap32) {
1072 return absl::InternalError(absl::StrFormat(
1073 "Number of unique Tiles32: %d Out of: %d\nUnique Tile32 count exceed "
1074 "the limit\nThe ROM Has not been saved\nYou can fill maps with grass "
1075 "tiles to free some space\nOr use the option Clear DW Tiles in the "
1076 "Overworld Menu",
1077 unique_tiles.size(), LimitOfMap32));
1078 }
1079
1080 if (core::FeatureFlags::get().kLogToConsole) {
1081 std::cout << "Number of unique Tiles32: " << tiles32_unique_.size()
1082 << " Saved:" << tiles32_unique_.size()
1083 << " Out of: " << LimitOfMap32 << std::endl;
1084 }
1085
1086 int v = tiles32_unique_.size();
1087 for (int i = v; i < LimitOfMap32; i++) {
1088 gfx::Tile32 padding_tile(420, 420, 420, 420);
1089 tiles32_unique_.emplace_back(padding_tile.GetPackedValue());
1090 }
1091
1092 return absl::OkStatus();
1093}
1094
1096 int bottomLeft = kMap32TileBLExpanded;
1097 int bottomRight = kMap32TileBRExpanded;
1098 int topRight = kMap32TileTRExpanded;
1099 int limit = 0x8A80;
1100
1101 // Updates the pointers too for the tile32
1102 // Top Right
1103 RETURN_IF_ERROR(rom()->WriteLong(0x0176EC, PcToSnes(kMap32TileTRExpanded)));
1105 rom()->WriteLong(0x0176F3, PcToSnes(kMap32TileTRExpanded + 1)));
1107 rom()->WriteLong(0x0176FA, PcToSnes(kMap32TileTRExpanded + 2)));
1109 rom()->WriteLong(0x017701, PcToSnes(kMap32TileTRExpanded + 3)));
1111 rom()->WriteLong(0x017708, PcToSnes(kMap32TileTRExpanded + 4)));
1113 rom()->WriteLong(0x01771A, PcToSnes(kMap32TileTRExpanded + 5)));
1114
1115 // BottomLeft
1116 RETURN_IF_ERROR(rom()->WriteLong(0x01772C, PcToSnes(kMap32TileBLExpanded)));
1118 rom()->WriteLong(0x017733, PcToSnes(kMap32TileBLExpanded + 1)));
1120 rom()->WriteLong(0x01773A, PcToSnes(kMap32TileBLExpanded + 2)));
1122 rom()->WriteLong(0x017741, PcToSnes(kMap32TileBLExpanded + 3)));
1124 rom()->WriteLong(0x017748, PcToSnes(kMap32TileBLExpanded + 4)));
1126 rom()->WriteLong(0x01775A, PcToSnes(kMap32TileBLExpanded + 5)));
1127
1128 // BottomRight
1129 RETURN_IF_ERROR(rom()->WriteLong(0x01776C, PcToSnes(kMap32TileBRExpanded)));
1131 rom()->WriteLong(0x017773, PcToSnes(kMap32TileBRExpanded + 1)));
1133 rom()->WriteLong(0x01777A, PcToSnes(kMap32TileBRExpanded + 2)));
1135 rom()->WriteLong(0x017781, PcToSnes(kMap32TileBRExpanded + 3)));
1137 rom()->WriteLong(0x017788, PcToSnes(kMap32TileBRExpanded + 4)));
1139 rom()->WriteLong(0x01779A, PcToSnes(kMap32TileBRExpanded + 5)));
1140 return absl::OkStatus();
1141}
1142
1144 util::logf("Saving Map32 Tiles");
1145 constexpr int kMaxUniqueTiles = 0x4540;
1146 constexpr int kTilesPer32x32Tile = 6;
1147
1148 int unique_tile_index = 0;
1149 int num_unique_tiles = tiles32_unique_.size();
1150
1151 for (int i = 0; i < num_unique_tiles; i += kTilesPer32x32Tile) {
1152 if (unique_tile_index >= kMaxUniqueTiles) {
1153 return absl::AbortedError("Too many unique tile32 definitions.");
1154 }
1155
1156 // Top Left.
1157 auto top_left = rom()->version_constants().kMap32TileTL;
1158
1159 RETURN_IF_ERROR(rom()->WriteByte(
1160 top_left + i,
1161 (uint8_t)(tiles32_unique_[unique_tile_index].tile0_ & 0xFF)));
1162 RETURN_IF_ERROR(rom()->WriteByte(
1163 top_left + (i + 1),
1164 (uint8_t)(tiles32_unique_[unique_tile_index + 1].tile0_ & 0xFF)));
1165 RETURN_IF_ERROR(rom()->WriteByte(
1166 top_left + (i + 2),
1167 (uint8_t)(tiles32_unique_[unique_tile_index + 2].tile0_ & 0xFF)));
1168 RETURN_IF_ERROR(rom()->WriteByte(
1169 top_left + (i + 3),
1170 (uint8_t)(tiles32_unique_[unique_tile_index + 3].tile0_ & 0xFF)));
1171
1172 RETURN_IF_ERROR(rom()->WriteByte(
1173 top_left + (i + 4),
1174 (uint8_t)(((tiles32_unique_[unique_tile_index].tile0_ >> 4) & 0xF0) +
1175 ((tiles32_unique_[unique_tile_index + 1].tile0_ >> 8) &
1176 0x0F))));
1177 RETURN_IF_ERROR(rom()->WriteByte(
1178 top_left + (i + 5),
1179 (uint8_t)(((tiles32_unique_[unique_tile_index + 2].tile0_ >> 4) &
1180 0xF0) +
1181 ((tiles32_unique_[unique_tile_index + 3].tile0_ >> 8) &
1182 0x0F))));
1183
1184 // Top Right.
1185 auto top_right = rom()->version_constants().kMap32TileTR;
1186 RETURN_IF_ERROR(rom()->WriteByte(
1187 top_right + i,
1188 (uint8_t)(tiles32_unique_[unique_tile_index].tile1_ & 0xFF)));
1189 RETURN_IF_ERROR(rom()->WriteByte(
1190 top_right + (i + 1),
1191 (uint8_t)(tiles32_unique_[unique_tile_index + 1].tile1_ & 0xFF)));
1192 RETURN_IF_ERROR(rom()->WriteByte(
1193 top_right + (i + 2),
1194 (uint8_t)(tiles32_unique_[unique_tile_index + 2].tile1_ & 0xFF)));
1195 RETURN_IF_ERROR(rom()->WriteByte(
1196 top_right + (i + 3),
1197 (uint8_t)(tiles32_unique_[unique_tile_index + 3].tile1_ & 0xFF)));
1198
1199 RETURN_IF_ERROR(rom()->WriteByte(
1200 top_right + (i + 4),
1201 (uint8_t)(((tiles32_unique_[unique_tile_index].tile1_ >> 4) & 0xF0) |
1202 ((tiles32_unique_[unique_tile_index + 1].tile1_ >> 8) &
1203 0x0F))));
1204 RETURN_IF_ERROR(rom()->WriteByte(
1205 top_right + (i + 5),
1206 (uint8_t)(((tiles32_unique_[unique_tile_index + 2].tile1_ >> 4) &
1207 0xF0) |
1208 ((tiles32_unique_[unique_tile_index + 3].tile1_ >> 8) &
1209 0x0F))));
1210
1211 // Bottom Left.
1212 const auto map32TilesBL = rom()->version_constants().kMap32TileBL;
1213 RETURN_IF_ERROR(rom()->WriteByte(
1214 map32TilesBL + i,
1215 (uint8_t)(tiles32_unique_[unique_tile_index].tile2_ & 0xFF)));
1216 RETURN_IF_ERROR(rom()->WriteByte(
1217 map32TilesBL + (i + 1),
1218 (uint8_t)(tiles32_unique_[unique_tile_index + 1].tile2_ & 0xFF)));
1219 RETURN_IF_ERROR(rom()->WriteByte(
1220 map32TilesBL + (i + 2),
1221 (uint8_t)(tiles32_unique_[unique_tile_index + 2].tile2_ & 0xFF)));
1222 RETURN_IF_ERROR(rom()->WriteByte(
1223 map32TilesBL + (i + 3),
1224 (uint8_t)(tiles32_unique_[unique_tile_index + 3].tile2_ & 0xFF)));
1225
1226 RETURN_IF_ERROR(rom()->WriteByte(
1227 map32TilesBL + (i + 4),
1228 (uint8_t)(((tiles32_unique_[unique_tile_index].tile2_ >> 4) & 0xF0) |
1229 ((tiles32_unique_[unique_tile_index + 1].tile2_ >> 8) &
1230 0x0F))));
1231 RETURN_IF_ERROR(rom()->WriteByte(
1232 map32TilesBL + (i + 5),
1233 (uint8_t)(((tiles32_unique_[unique_tile_index + 2].tile2_ >> 4) &
1234 0xF0) |
1235 ((tiles32_unique_[unique_tile_index + 3].tile2_ >> 8) &
1236 0x0F))));
1237
1238 // Bottom Right.
1239 const auto map32TilesBR = rom()->version_constants().kMap32TileBR;
1240 RETURN_IF_ERROR(rom()->WriteByte(
1241 map32TilesBR + i,
1242 (uint8_t)(tiles32_unique_[unique_tile_index].tile3_ & 0xFF)));
1243 RETURN_IF_ERROR(rom()->WriteByte(
1244 map32TilesBR + (i + 1),
1245 (uint8_t)(tiles32_unique_[unique_tile_index + 1].tile3_ & 0xFF)));
1246 RETURN_IF_ERROR(rom()->WriteByte(
1247 map32TilesBR + (i + 2),
1248 (uint8_t)(tiles32_unique_[unique_tile_index + 2].tile3_ & 0xFF)));
1249 RETURN_IF_ERROR(rom()->WriteByte(
1250 map32TilesBR + (i + 3),
1251 (uint8_t)(tiles32_unique_[unique_tile_index + 3].tile3_ & 0xFF)));
1252
1253 RETURN_IF_ERROR(rom()->WriteByte(
1254 map32TilesBR + (i + 4),
1255 (uint8_t)(((tiles32_unique_[unique_tile_index].tile3_ >> 4) & 0xF0) |
1256 ((tiles32_unique_[unique_tile_index + 1].tile3_ >> 8) &
1257 0x0F))));
1258 RETURN_IF_ERROR(rom()->WriteByte(
1259 map32TilesBR + (i + 5),
1260 (uint8_t)(((tiles32_unique_[unique_tile_index + 2].tile3_ >> 4) &
1261 0xF0) |
1262 ((tiles32_unique_[unique_tile_index + 3].tile3_ >> 8) &
1263 0x0F))));
1264
1265 unique_tile_index += 4;
1266 num_unique_tiles += 2;
1267 }
1268
1269 return absl::OkStatus();
1270}
1271
1274 rom()->WriteLong(SnesToPc(0x008865), PcToSnes(kMap16TilesExpanded)));
1276 rom()->WriteLong(SnesToPc(0x0EDE4F), PcToSnes(kMap16TilesExpanded)));
1278 rom()->WriteLong(SnesToPc(0x0EDEE9), PcToSnes(kMap16TilesExpanded)));
1279
1281 rom()->WriteLong(SnesToPc(0x1BBC2D), PcToSnes(kMap16TilesExpanded + 2)));
1283 rom()->WriteLong(SnesToPc(0x1BBC4C), PcToSnes(kMap16TilesExpanded)));
1285 rom()->WriteLong(SnesToPc(0x1BBCC2), PcToSnes(kMap16TilesExpanded + 4)));
1287 rom()->WriteLong(SnesToPc(0x1BBCCB), PcToSnes(kMap16TilesExpanded + 6)));
1288
1290 rom()->WriteLong(SnesToPc(0x1BBEF6), PcToSnes(kMap16TilesExpanded)));
1292 rom()->WriteLong(SnesToPc(0x1BBF23), PcToSnes(kMap16TilesExpanded)));
1294 rom()->WriteLong(SnesToPc(0x1BC041), PcToSnes(kMap16TilesExpanded)));
1296 rom()->WriteLong(SnesToPc(0x1BC9B3), PcToSnes(kMap16TilesExpanded)));
1297
1299 rom()->WriteLong(SnesToPc(0x1BC9BA), PcToSnes(kMap16TilesExpanded + 2)));
1301 rom()->WriteLong(SnesToPc(0x1BC9C1), PcToSnes(kMap16TilesExpanded + 4)));
1303 rom()->WriteLong(SnesToPc(0x1BC9C8), PcToSnes(kMap16TilesExpanded + 6)));
1304
1306 rom()->WriteLong(SnesToPc(0x1BCA40), PcToSnes(kMap16TilesExpanded)));
1308 rom()->WriteLong(SnesToPc(0x1BCA47), PcToSnes(kMap16TilesExpanded + 2)));
1310 rom()->WriteLong(SnesToPc(0x1BCA4E), PcToSnes(kMap16TilesExpanded + 4)));
1312 rom()->WriteLong(SnesToPc(0x1BCA55), PcToSnes(kMap16TilesExpanded + 6)));
1313
1315 rom()->WriteLong(SnesToPc(0x02F457), PcToSnes(kMap16TilesExpanded)));
1317 rom()->WriteLong(SnesToPc(0x02F45E), PcToSnes(kMap16TilesExpanded + 2)));
1319 rom()->WriteLong(SnesToPc(0x02F467), PcToSnes(kMap16TilesExpanded + 4)));
1321 rom()->WriteLong(SnesToPc(0x02F46E), PcToSnes(kMap16TilesExpanded + 6)));
1323 rom()->WriteLong(SnesToPc(0x02F51F), PcToSnes(kMap16TilesExpanded)));
1325 rom()->WriteLong(SnesToPc(0x02F526), PcToSnes(kMap16TilesExpanded + 4)));
1327 rom()->WriteLong(SnesToPc(0x02F52F), PcToSnes(kMap16TilesExpanded + 2)));
1329 rom()->WriteLong(SnesToPc(0x02F536), PcToSnes(kMap16TilesExpanded + 6)));
1330
1332 rom()->WriteShort(SnesToPc(0x02FE1C), PcToSnes(kMap16TilesExpanded)));
1334 rom()->WriteShort(SnesToPc(0x02FE23), PcToSnes(kMap16TilesExpanded + 4)));
1336 rom()->WriteShort(SnesToPc(0x02FE2C), PcToSnes(kMap16TilesExpanded + 2)));
1338 rom()->WriteShort(SnesToPc(0x02FE33), PcToSnes(kMap16TilesExpanded + 6)));
1339
1340 RETURN_IF_ERROR(rom()->WriteByte(
1341 SnesToPc(0x02FD28),
1342 static_cast<uint8_t>(PcToSnes(kMap16TilesExpanded) >> 16)));
1343 RETURN_IF_ERROR(rom()->WriteByte(
1344 SnesToPc(0x02FD39),
1345 static_cast<uint8_t>(PcToSnes(kMap16TilesExpanded) >> 16)));
1346
1347 return absl::OkStatus();
1348}
1349
1351 util::logf("Saving Map16 Tiles");
1352 int tpos = kMap16Tiles;
1353 // 3760
1354 for (int i = 0; i < NumberOfMap16; i += 1) {
1356 rom()->WriteShort(tpos, TileInfoToShort(tiles16_[i].tile0_)))
1357 tpos += 2;
1359 rom()->WriteShort(tpos, TileInfoToShort(tiles16_[i].tile1_)))
1360 tpos += 2;
1362 rom()->WriteShort(tpos, TileInfoToShort(tiles16_[i].tile2_)))
1363 tpos += 2;
1365 rom()->WriteShort(tpos, TileInfoToShort(tiles16_[i].tile3_)))
1366 tpos += 2;
1367 }
1368 return absl::OkStatus();
1369}
1370
1372 util::logf("Saving Entrances");
1373 int ow_entrance_map_ptr = kOverworldEntranceMap;
1374 int ow_entrance_pos_ptr = kOverworldEntrancePos;
1375 int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
1376 int num_entrances = kNumOverworldEntrances;
1377 if (expanded_entrances_) {
1378 ow_entrance_map_ptr = kOverworldEntranceMapExpanded;
1379 ow_entrance_pos_ptr = kOverworldEntrancePosExpanded;
1380 ow_entrance_id_ptr = kOverworldEntranceEntranceIdExpanded;
1381 expanded_entrances_ = true;
1382 }
1383
1384 for (int i = 0; i < kNumOverworldEntrances; i++) {
1385 RETURN_IF_ERROR(rom()->WriteShort(kOverworldEntranceMap + (i * 2),
1386 all_entrances_[i].map_id_))
1387 RETURN_IF_ERROR(rom()->WriteShort(kOverworldEntrancePos + (i * 2),
1388 all_entrances_[i].map_pos_))
1390 all_entrances_[i].entrance_id_))
1391 }
1392
1393 for (int i = 0; i < kNumOverworldHoles; i++) {
1395 rom()->WriteShort(kOverworldHoleArea + (i * 2), all_holes_[i].map_id_))
1397 rom()->WriteShort(kOverworldHolePos + (i * 2), all_holes_[i].map_pos_))
1399 all_holes_[i].entrance_id_))
1400 }
1401
1402 return absl::OkStatus();
1403}
1404
1405absl::Status Overworld::SaveExits() {
1406 util::logf("Saving Exits");
1407 for (int i = 0; i < kNumOverworldExits; i++) {
1409 rom()->WriteShort(OWExitRoomId + (i * 2), all_exits_[i].room_id_));
1410 RETURN_IF_ERROR(rom()->WriteByte(OWExitMapId + i, all_exits_[i].map_id_));
1412 rom()->WriteShort(OWExitVram + (i * 2), all_exits_[i].map_pos_));
1414 rom()->WriteShort(OWExitYScroll + (i * 2), all_exits_[i].y_scroll_));
1416 rom()->WriteShort(OWExitXScroll + (i * 2), all_exits_[i].x_scroll_));
1418 rom()->WriteByte(OWExitYPlayer + (i * 2), all_exits_[i].y_player_));
1420 rom()->WriteByte(OWExitXPlayer + (i * 2), all_exits_[i].x_player_));
1422 rom()->WriteByte(OWExitYCamera + (i * 2), all_exits_[i].y_camera_));
1424 rom()->WriteByte(OWExitXCamera + (i * 2), all_exits_[i].x_camera_));
1426 rom()->WriteByte(OWExitUnk1 + i, all_exits_[i].scroll_mod_y_));
1428 rom()->WriteByte(OWExitUnk2 + i, all_exits_[i].scroll_mod_x_));
1429 RETURN_IF_ERROR(rom()->WriteShort(OWExitDoorType1 + (i * 2),
1430 all_exits_[i].door_type_1_));
1431 RETURN_IF_ERROR(rom()->WriteShort(OWExitDoorType2 + (i * 2),
1432 all_exits_[i].door_type_2_));
1433 }
1434
1435 return absl::OkStatus();
1436}
1437
1438namespace {
1439bool CompareItemsArrays(std::vector<OverworldItem> item_array1,
1440 std::vector<OverworldItem> item_array2) {
1441 if (item_array1.size() != item_array2.size()) {
1442 return false;
1443 }
1444
1445 bool match;
1446 for (size_t i = 0; i < item_array1.size(); i++) {
1447 match = false;
1448 for (size_t j = 0; j < item_array2.size(); j++) {
1449 // Check all sprite in 2nd array if one match
1450 if (item_array1[i].x_ == item_array2[j].x_ &&
1451 item_array1[i].y_ == item_array2[j].y_ &&
1452 item_array1[i].id_ == item_array2[j].id_) {
1453 match = true;
1454 break;
1455 }
1456 }
1457
1458 if (!match) {
1459 return false;
1460 }
1461 }
1462
1463 return true;
1464}
1465} // namespace
1466
1467absl::Status Overworld::SaveItems() {
1468 std::vector<std::vector<OverworldItem>> room_items(
1470
1471 for (int i = 0; i < kNumOverworldMapItemPointers; i++) {
1472 room_items[i] = std::vector<OverworldItem>();
1473 for (const OverworldItem &item : all_items_) {
1474 if (item.room_map_id_ == i) {
1475 room_items[i].emplace_back(item);
1476 if (item.id_ == 0x86) {
1477 RETURN_IF_ERROR(rom()->WriteWord(
1478 0x16DC5 + (i * 2), (item.game_x_ + (item.game_y_ * 64)) * 2));
1479 }
1480 }
1481 }
1482 }
1483
1484 int data_pos = kOverworldItemsPointers + 0x100;
1485 int item_pointers[kNumOverworldMapItemPointers];
1486 int item_pointers_reuse[kNumOverworldMapItemPointers];
1487 int empty_pointer = 0;
1488 for (int i = 0; i < kNumOverworldMapItemPointers; i++) {
1489 item_pointers_reuse[i] = -1;
1490 for (int ci = 0; ci < i; ci++) {
1491 if (room_items[i].empty()) {
1492 item_pointers_reuse[i] = -2;
1493 break;
1494 }
1495
1496 // Copy into separator vectors from i to ci, then ci to end
1497 if (CompareItemsArrays(
1498 std::vector<OverworldItem>(room_items[i].begin(),
1499 room_items[i].end()),
1500 std::vector<OverworldItem>(room_items[ci].begin(),
1501 room_items[ci].end()))) {
1502 item_pointers_reuse[i] = ci;
1503 break;
1504 }
1505 }
1506 }
1507
1508 for (int i = 0; i < kNumOverworldMapItemPointers; i++) {
1509 if (item_pointers_reuse[i] == -1) {
1510 item_pointers[i] = data_pos;
1511 for (const OverworldItem &item : room_items[i]) {
1512 short map_pos =
1513 static_cast<short>(((item.game_y_ << 6) + item.game_x_) << 1);
1514
1515 uint32_t data = static_cast<uint8_t>(map_pos & 0xFF) |
1516 static_cast<uint8_t>(map_pos >> 8) |
1517 static_cast<uint8_t>(item.id_);
1518 RETURN_IF_ERROR(rom()->WriteLong(data_pos, data));
1519 data_pos += 3;
1520 }
1521
1522 empty_pointer = data_pos;
1523 RETURN_IF_ERROR(rom()->WriteWord(data_pos, 0xFFFF));
1524 data_pos += 2;
1525 } else if (item_pointers_reuse[i] == -2) {
1526 item_pointers[i] = empty_pointer;
1527 } else {
1528 item_pointers[i] = item_pointers[item_pointers_reuse[i]];
1529 }
1530
1531 int snesaddr = PcToSnes(item_pointers[i]);
1533 rom()->WriteWord(kOverworldItemsPointers + (i * 2), snesaddr));
1534 }
1535
1536 if (data_pos > kOverworldItemsEndData) {
1537 return absl::AbortedError("Too many items");
1538 }
1539
1540 util::logf("End of Items : %d", data_pos);
1541
1542 return absl::OkStatus();
1543}
1544
1546 util::logf("Saving Map Properties");
1547 for (int i = 0; i < kDarkWorldMapIdStart; i++) {
1548 RETURN_IF_ERROR(rom()->WriteByte(kAreaGfxIdPtr + i,
1549 overworld_maps_[i].area_graphics()));
1551 overworld_maps_[i].area_palette()));
1552 RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + i,
1553 overworld_maps_[i].sprite_graphics(0)));
1555 rom()->WriteByte(kOverworldSpriteset + kDarkWorldMapIdStart + i,
1556 overworld_maps_[i].sprite_graphics(1)));
1559 overworld_maps_[i].sprite_graphics(2)));
1561 overworld_maps_[i].sprite_palette(0)));
1564 overworld_maps_[i].sprite_palette(1)));
1565 RETURN_IF_ERROR(rom()->WriteByte(
1567 overworld_maps_[i].sprite_palette(2)));
1568 }
1569
1570 for (int i = kDarkWorldMapIdStart; i < kSpecialWorldMapIdStart; i++) {
1571 RETURN_IF_ERROR(rom()->WriteByte(kAreaGfxIdPtr + i,
1572 overworld_maps_[i].area_graphics()));
1573 RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + i,
1574 overworld_maps_[i].sprite_graphics(0)));
1576 rom()->WriteByte(kOverworldSpriteset + kDarkWorldMapIdStart + i,
1577 overworld_maps_[i].sprite_graphics(1)));
1580 overworld_maps_[i].sprite_graphics(2)));
1582 overworld_maps_[i].area_palette()));
1585 overworld_maps_[i].sprite_palette(0)));
1586 RETURN_IF_ERROR(rom()->WriteByte(
1588 overworld_maps_[i].sprite_palette(1)));
1589 RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpritePaletteIds + 192 + i,
1590 overworld_maps_[i].sprite_palette(2)));
1591 }
1592
1593 return absl::OkStatus();
1594}
1595
1596} // namespace zelda3
1597} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:59
auto rom()
Definition rom.h:382
static Flags & get()
Definition features.h:69
Tile composition of four 16x16 tiles.
Definition snes_tile.h:80
uint64_t GetPackedValue() const
Definition snes_tile.h:110
SNES 16-bit tile metadata container.
Definition snes_tile.h:49
absl::Status SaveMap32Expanded()
absl::Status LoadExits()
Definition overworld.cc:358
std::vector< uint16_t > tiles32_list_
Definition overworld.h:260
absl::Status Load(Rom &rom)
Definition overworld.cc:20
std::vector< OverworldItem > all_items_
Definition overworld.h:254
void OrganizeMapTiles(std::vector< uint8_t > &bytes, std::vector< uint8_t > &bytes2, int i, int sx, int sy, int &ttpos)
Definition overworld.cc:201
std::array< int, kNumOverworldMaps > map_pointers1
Definition overworld.h:270
std::vector< gfx::Tile32 > tiles32_unique_
Definition overworld.h:258
absl::Status SaveMapProperties()
absl::Status SaveMap32Tiles()
std::vector< OverworldEntrance > all_entrances_
Definition overworld.h:251
OverworldMapTiles map_tiles_
Definition overworld.h:248
absl::Status SaveMap16Tiles()
absl::Status SaveLargeMaps()
Definition overworld.cc:668
std::array< uint8_t, kNumOverworldMaps > map_parent_
Definition overworld.h:263
void AssignWorldTiles(int x, int y, int sx, int sy, int tpos, OverworldBlockset &world)
Definition overworld.cc:189
std::array< uint8_t, kNumTileTypes > all_tiles_types_
Definition overworld.h:264
absl::Status CreateTile32Tilemap()
std::array< int, kNumOverworldMaps > map_pointers1_id
Definition overworld.h:268
absl::Status Save(Rom &rom)
Definition overworld.cc:518
absl::Status LoadItems()
Definition overworld.cc:410
absl::Status SaveEntrances()
absl::Status SaveExits()
absl::Status LoadSprites()
Definition overworld.cc:460
absl::Status LoadHoles()
Definition overworld.cc:338
std::vector< OverworldMap > overworld_maps_
Definition overworld.h:250
absl::Status SaveItems()
absl::Status LoadEntrances()
Definition overworld.cc:303
absl::Status SaveOverworldMaps()
Definition overworld.cc:530
std::array< std::vector< Sprite >, 3 > all_sprites_
Definition overworld.h:265
std::array< int, kNumOverworldMaps > map_pointers2_id
Definition overworld.h:269
absl::Status LoadOverworldMaps()
Definition overworld.cc:271
std::vector< gfx::Tile16 > tiles16_
Definition overworld.h:256
absl::Status AssembleMap16Tiles()
Definition overworld.cc:161
absl::Status LoadSpritesFromMap(int sprite_start, int sprite_count, int sprite_index)
Definition overworld.cc:479
std::array< std::vector< uint8_t >, kNumOverworldMaps > map_data_p1
Definition overworld.h:266
absl::Status SaveMap16Expanded()
std::vector< OverworldExit > all_exits_
Definition overworld.h:253
std::array< int, kNumOverworldMaps > map_pointers2
Definition overworld.h:271
absl::StatusOr< uint16_t > GetTile16ForTile32(int index, int quadrant, int dimension, const uint32_t *map32address)
Definition overworld.cc:98
std::array< std::vector< uint8_t >, kNumOverworldMaps > map_data_p2
Definition overworld.h:267
absl::Status AssembleMap32Tiles()
Definition overworld.cc:108
OverworldBlockset & GetMapTiles(int world_type)
Definition overworld.h:167
std::vector< OverworldEntrance > all_holes_
Definition overworld.h:252
#define RETURN_IF_ERROR(expression)
Definition macro.h:51
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:59
std::vector< uint8_t > HyruleMagicDecompress(uint8_t const *src, int *const size, int const p_big_endian)
TileInfo GetTilesInfo(uint16_t tile)
Definition snes_tile.cc:364
std::vector< uint8_t > HyruleMagicCompress(uint8_t const *const src, int const oldsize, int *const size, int const flag)
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:33
std::string HexLong(uint32_t dword, HexStringParams params)
Definition hex.cc:59
bool CompareItemsArrays(std::vector< OverworldItem > item_array1, std::vector< OverworldItem > item_array2)
std::vector< uint64_t > GetAllTile16(OverworldMapTiles &map_tiles_)
Definition overworld.cc:989
Zelda 3 specific classes and functions.
constexpr int OWExitYScroll
constexpr int kAreaGfxIdPtr
Definition overworld.h:40
constexpr int kOverworldHoleArea
constexpr int kOverworldTransitionPositionY
Definition overworld.h:64
constexpr int kOverworldEntrancePos
constexpr int kOverworldHoleEntrance
constexpr int kNumMapsPerWorld
Definition overworld.h:104
constexpr int kOverworldSpriteset
Definition overworld.h:33
constexpr int kMap16ExpandedFlagPos
Definition overworld.h:88
constexpr int LimitOfMap32
Definition overworld.h:101
constexpr int NumberOfMap16Ex
Definition overworld.h:100
constexpr int kOverworldScreenTileMapChangeByScreen1
Definition overworld.h:69
constexpr int kOverworldMapDataOverflow
Definition overworld.h:74
constexpr int kOverworldMapSizeHighByte
Definition overworld.h:55
constexpr int kOverworldEntranceEntranceIdExpanded
constexpr int kNumTileTypes
Definition overworld.h:94
constexpr int NumberOfMap32
Definition overworld.h:103
constexpr int kNumOverworldMapItemPointers
constexpr int kOverworldScreenSize
Definition overworld.h:66
constexpr int kOverworldScreenTileMapChangeByScreen4
Definition overworld.h:72
constexpr int kNumTile16Individual
Definition overworld.h:97
constexpr int kNumOverworldHoles
constexpr int kSpecialWorldMapIdStart
constexpr int OWExitDoorType2
constexpr int kOverworldEntranceEntranceId
constexpr int kOverworldItemsAddress
constexpr int kMap16Tiles
Definition overworld.h:95
constexpr int kOverworldHolePos
constexpr int kNumOverworldMaps
Definition overworld.h:96
constexpr int kOverworldEntranceMap
constexpr int kOverworldItemsEndData
constexpr int OWExitYCamera
std::vector< std::vector< uint16_t > > OverworldBlockset
Represents tile32 data for the overworld.
constexpr int kMap32TileBLExpanded
Definition overworld.h:84
constexpr int kOverworldTransitionPositionX
Definition overworld.h:65
constexpr int OWExitXScroll
constexpr int OWExitRoomId
constexpr int OWExitXCamera
constexpr int OWExitUnk1
constexpr int OWExitYPlayer
constexpr int kOverworldScreenSizeForLoading
Definition overworld.h:67
constexpr int kOverworldSpritePaletteIds
Definition overworld.h:31
constexpr int kMap32TileBRExpanded
Definition overworld.h:85
constexpr int kMap32TileCountExpanded
Definition overworld.h:86
constexpr int OWExitMapId
constexpr int OWExitUnk2
constexpr int kTransitionTargetWest
Definition overworld.h:77
constexpr int kOverworldSpritesZelda
Definition overworld.h:38
constexpr int kOverworldMapParentId
Definition overworld.h:63
constexpr int kMap32ExpandedFlagPos
Definition overworld.h:87
constexpr int kOverworldEntrancePosExpanded
constexpr int OWExitDoorType1
constexpr int kOverworldItemsPointers
constexpr int kNumOverworldExits
constexpr int NumberOfMap16
Definition overworld.h:99
constexpr int kOverworldMapSize
Definition overworld.h:52
constexpr int kOverworldScreenTileMapChangeByScreen2
Definition overworld.h:70
constexpr int kOverworldEntranceMapExpanded
constexpr int kDarkWorldMapIdStart
constexpr int kOverworldCompressedMapPos
Definition overworld.h:91
constexpr int kOverworldSpritesBeginning
Definition overworld.h:36
constexpr int kOverworldScreenTileMapChangeByScreen3
Definition overworld.h:71
constexpr int kMap16TilesExpanded
Definition overworld.h:82
constexpr int kOverworldEntranceExpandedFlagPos
Definition overworld.h:89
constexpr int kNumOverworldEntrances
constexpr int kOverworldSpritesAgahnim
Definition overworld.h:37
constexpr int kTransitionTargetNorth
Definition overworld.h:76
constexpr int kOverworldCompressedOverflowPos
Definition overworld.h:92
constexpr int kMap32TileTRExpanded
Definition overworld.h:83
constexpr int OWExitXPlayer
constexpr int OWExitVram
constexpr int kOverworldMapPaletteIds
Definition overworld.h:30
Main namespace for the application.
Definition controller.cc:18
uint32_t PcToSnes(uint32_t addr)
Definition rom.h:335
uint32_t SnesToPc(uint32_t addr) noexcept
Definition rom.h:327
Overworld map tile32 data.