Refactor overworld constants to improve naming consistency and readability
This commit is contained in:
@@ -47,11 +47,9 @@ void Overworld::FetchLargeMaps() {
|
||||
overworld_maps_[138].SetAsLargeMap(129, 3);
|
||||
overworld_maps_[136].SetAsSmallMap();
|
||||
|
||||
std::vector<bool> map_checked;
|
||||
map_checked.reserve(0x40);
|
||||
for (int i = 0; i < 64; i++) {
|
||||
map_checked[i] = false;
|
||||
}
|
||||
std::array<bool, 0x40> map_checked;
|
||||
std::fill(map_checked.begin(), map_checked.end(), false);
|
||||
|
||||
int xx = 0;
|
||||
int yy = 0;
|
||||
while (true) {
|
||||
@@ -109,7 +107,7 @@ absl::Status Overworld::AssembleMap32Tiles() {
|
||||
rom_.version_constants().kMap32TileTR,
|
||||
rom_.version_constants().kMap32TileBL,
|
||||
rom_.version_constants().kMap32TileBR};
|
||||
if (rom()->data()[0x01772E] != 0x04) {
|
||||
if (rom()->data()[kMap32ExpandedFlagPos] != 0x04) {
|
||||
map32address[0] = rom_.version_constants().kMap32TileTL;
|
||||
map32address[1] = kMap32TileTRExpanded;
|
||||
map32address[2] = kMap32TileBLExpanded;
|
||||
@@ -119,7 +117,7 @@ absl::Status Overworld::AssembleMap32Tiles() {
|
||||
}
|
||||
|
||||
// Loop through each 32x32 pixel tile in the rom
|
||||
for (int i = 0; i < kMap32TilesLength; i += 6) {
|
||||
for (int i = 0; i < num_tile32; i += 6) {
|
||||
// Loop through each quadrant of the 32x32 pixel tile.
|
||||
for (int k = 0; k < 4; k++) {
|
||||
// Generate the 16-bit tile for the current quadrant of the current
|
||||
@@ -157,7 +155,7 @@ absl::Status Overworld::AssembleMap32Tiles() {
|
||||
void Overworld::AssembleMap16Tiles() {
|
||||
int tpos = kMap16Tiles;
|
||||
int num_tile16 = kNumTile16Individual;
|
||||
if (rom()->data()[0x02FD28] != 0x0F) {
|
||||
if (rom()->data()[kMap16ExpandedFlagPos] != 0x0F) {
|
||||
tpos = kMap16TilesExpanded;
|
||||
num_tile16 = NumberOfMap16Ex;
|
||||
expanded_tile16_ = true;
|
||||
@@ -221,7 +219,7 @@ absl::Status Overworld::DecompressAllMapTiles() {
|
||||
int sx = 0;
|
||||
int sy = 0;
|
||||
int c = 0;
|
||||
for (int i = 0; i < 160; i++) {
|
||||
for (int i = 0; i < kNumOverworldMaps; i++) {
|
||||
auto p1 = get_ow_map_gfx_ptr(
|
||||
i, rom()->version_constants().kCompressedAllMap32PointersHigh);
|
||||
auto p2 = get_ow_map_gfx_ptr(
|
||||
@@ -287,10 +285,7 @@ absl::Status Overworld::LoadOverworldMaps() {
|
||||
|
||||
// Wait for all tasks to complete and check their results
|
||||
for (auto &future : futures) {
|
||||
absl::Status status = future.get();
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
RETURN_IF_ERROR(future.get());
|
||||
}
|
||||
return absl::OkStatus();
|
||||
}
|
||||
@@ -303,14 +298,14 @@ void Overworld::LoadTileTypes() {
|
||||
}
|
||||
|
||||
void Overworld::LoadEntrances() {
|
||||
int ow_entrance_map_ptr = OWEntranceMap;
|
||||
int ow_entrance_pos_ptr = OWEntrancePos;
|
||||
int ow_entrance_id_ptr = OWEntranceEntranceId;
|
||||
int ow_entrance_map_ptr = kOverworldEntranceMap;
|
||||
int ow_entrance_pos_ptr = kOverworldEntrancePos;
|
||||
int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
|
||||
int num_entrances = 129;
|
||||
if (rom()->data()[0x0DB895] != 0xB8) {
|
||||
ow_entrance_map_ptr = 0x0DB55F;
|
||||
ow_entrance_pos_ptr = 0x0DB35F;
|
||||
ow_entrance_id_ptr = 0x0DB75F;
|
||||
if (rom()->data()[kOverworldEntranceExpandedFlagPos] != 0xB8) {
|
||||
ow_entrance_map_ptr = kOverworldEntranceMapExpanded;
|
||||
ow_entrance_pos_ptr = kOverworldEntrancePosExpanded;
|
||||
ow_entrance_id_ptr = kOverworldEntranceEntranceIdExpanded;
|
||||
expanded_entrances_ = true;
|
||||
}
|
||||
|
||||
@@ -332,11 +327,11 @@ void Overworld::LoadEntrances() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 0x13; i++) {
|
||||
auto map_id = (short)((rom_[OWHoleArea + (i * 2) + 1] << 8) +
|
||||
(rom_[OWHoleArea + (i * 2)]));
|
||||
auto map_pos = (short)((rom_[OWHolePos + (i * 2) + 1] << 8) +
|
||||
(rom_[OWHolePos + (i * 2)]));
|
||||
uint8_t entrance_id = (rom_[OWHoleEntrance + i]);
|
||||
auto map_id = (short)((rom_[kOverworldHoleArea + (i * 2) + 1] << 8) +
|
||||
(rom_[kOverworldHoleArea + (i * 2)]));
|
||||
auto map_pos = (short)((rom_[kOverworldHolePos + (i * 2) + 1] << 8) +
|
||||
(rom_[kOverworldHolePos + (i * 2)]));
|
||||
uint8_t entrance_id = (rom_[kOverworldHoleEntrance + i]);
|
||||
int p = (map_pos + 0x400) >> 1;
|
||||
int x = (p % 64);
|
||||
int y = (p >> 6);
|
||||
@@ -459,9 +454,9 @@ absl::Status Overworld::LoadSprites() {
|
||||
all_sprites_.emplace_back();
|
||||
}
|
||||
|
||||
RETURN_IF_ERROR(LoadSpritesFromMap(overworldSpritesBegining, 64, 0));
|
||||
RETURN_IF_ERROR(LoadSpritesFromMap(overworldSpritesZelda, 144, 1));
|
||||
RETURN_IF_ERROR(LoadSpritesFromMap(overworldSpritesAgahnim, 144, 2));
|
||||
RETURN_IF_ERROR(LoadSpritesFromMap(kOverworldSpritesBeginning, 64, 0));
|
||||
RETURN_IF_ERROR(LoadSpritesFromMap(kOverworldSpritesZelda, 144, 1));
|
||||
RETURN_IF_ERROR(LoadSpritesFromMap(kOverworldSpritesAgahnim, 144, 2));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
@@ -527,8 +522,8 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
std::fill(map_pointers2_id.begin(), map_pointers2_id.end(), -1);
|
||||
|
||||
// Compress and save each map
|
||||
int pos = 0x058000;
|
||||
for (int i = 0; i < 160; i++) {
|
||||
int pos = kOverworldCompressedMapPos;
|
||||
for (int i = 0; i < kNumOverworldMaps; i++) {
|
||||
std::vector<uint8_t> single_map_1(512);
|
||||
std::vector<uint8_t> single_map_2(512);
|
||||
|
||||
@@ -573,11 +568,11 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
if ((pos + size_a) >= 0x6411F && (pos + size_a) <= 0x70000) {
|
||||
core::logf("Pos set to overflow region for map %s at %s",
|
||||
std::to_string(i), core::HexLong(pos));
|
||||
pos = OverworldMapDataOverflow; // 0x0F8780;
|
||||
pos = kOverworldMapDataOverflow; // 0x0F8780;
|
||||
}
|
||||
|
||||
auto compareArray = [](const std::vector<uint8_t> &array1,
|
||||
const std::vector<uint8_t> &array2) -> bool {
|
||||
auto compare_array = [](const std::vector<uint8_t> &array1,
|
||||
const std::vector<uint8_t> &array2) -> bool {
|
||||
if (array1.size() != array2.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -592,12 +587,12 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
};
|
||||
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (compareArray(a, map_data_p1[j])) {
|
||||
if (compare_array(a, map_data_p1[j])) {
|
||||
// Reuse pointer id j for P1 (a)
|
||||
map_pointers1_id[i] = j;
|
||||
}
|
||||
|
||||
if (compareArray(b, map_data_p2[j])) {
|
||||
if (compare_array(b, map_data_p2[j])) {
|
||||
map_pointers2_id[i] = j;
|
||||
// Reuse pointer id j for P2 (b)
|
||||
}
|
||||
@@ -632,7 +627,7 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
if ((pos + b.size()) >= 0x6411F && (pos + b.size()) <= 0x70000) {
|
||||
core::logf("Pos set to overflow region for map %s at %s",
|
||||
core::HexByte(i), core::HexLong(pos));
|
||||
pos = OverworldMapDataOverflow;
|
||||
pos = kOverworldMapDataOverflow;
|
||||
}
|
||||
|
||||
if (map_pointers2_id[i] == -1) {
|
||||
@@ -659,7 +654,7 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
}
|
||||
|
||||
// Check if too many maps data
|
||||
if (pos > 0x137FFF) {
|
||||
if (pos > kOverworldCompressedOverflowPos) {
|
||||
core::logf("Too many maps data %s", core::HexLong(pos));
|
||||
return absl::AbortedError("Too many maps data " + std::to_string(pos));
|
||||
}
|
||||
@@ -682,7 +677,7 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
|
||||
// Always write the map parent since it should not matter
|
||||
RETURN_IF_ERROR(
|
||||
rom()->Write(overworldMapParentId + i, overworld_maps_[i].parent()))
|
||||
rom()->Write(kOverworldMapParentId + i, overworld_maps_[i].parent()))
|
||||
|
||||
if (std::find(checked_map.begin(), checked_map.end(), i) !=
|
||||
checked_map.end()) {
|
||||
@@ -695,93 +690,99 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
const uint8_t large_map_offsets[] = {0, 1, 8, 9};
|
||||
for (const auto &offset : large_map_offsets) {
|
||||
// Check 1
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldMapSize + i + offset, 0x20));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapSize + i + offset, 0x20));
|
||||
// Check 2
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(overworldMapSizeHighByte + i + offset, 0x03));
|
||||
rom()->WriteByte(kOverworldMapSizeHighByte + i + offset, 0x03));
|
||||
// Check 3
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(overworldScreenSize + i + offset, 0x00));
|
||||
rom()->WriteByte(kOverworldScreenSize + i + offset, 0x00));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(overworldScreenSize + i + offset + 64, 0x00));
|
||||
rom()->WriteByte(kOverworldScreenSize + i + offset + 64, 0x00));
|
||||
// Check 4
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(OverworldScreenSizeForLoading + i + offset, 0x04));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(
|
||||
OverworldScreenSizeForLoading + i + offset + 64, 0x04));
|
||||
kOverworldScreenSizeForLoading + i + offset, 0x04));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(
|
||||
OverworldScreenSizeForLoading + i + offset + 128, 0x04));
|
||||
kOverworldScreenSizeForLoading + i + offset + 64, 0x04));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(
|
||||
kOverworldScreenSizeForLoading + i + offset + 128, 0x04));
|
||||
}
|
||||
|
||||
// Check 5 and 6
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_north + (i * 2),
|
||||
rom()->WriteShort(kTransitionTargetNorth + (i * 2),
|
||||
(uint16_t)((parent_y_pos * 0x200) - 0xE0)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_west + (i * 2),
|
||||
rom()->WriteShort(kTransitionTargetWest + (i * 2),
|
||||
(uint16_t)((parent_x_pos * 0x200) - 0x100)));
|
||||
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_north + (i * 2) + 2,
|
||||
rom()->WriteShort(kTransitionTargetNorth + (i * 2) + 2,
|
||||
(uint16_t)((parent_y_pos * 0x200) - 0xE0)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_west + (i * 2) + 2,
|
||||
rom()->WriteShort(kTransitionTargetWest + (i * 2) + 2,
|
||||
(uint16_t)((parent_x_pos * 0x200) - 0x100)));
|
||||
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_north + (i * 2) + 16,
|
||||
rom()->WriteShort(kTransitionTargetNorth + (i * 2) + 16,
|
||||
(uint16_t)((parent_y_pos * 0x200) - 0xE0)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_west + (i * 2) + 16,
|
||||
rom()->WriteShort(kTransitionTargetWest + (i * 2) + 16,
|
||||
(uint16_t)((parent_x_pos * 0x200) - 0x100)));
|
||||
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_north + (i * 2) + 18,
|
||||
rom()->WriteShort(kTransitionTargetNorth + (i * 2) + 18,
|
||||
(uint16_t)((parent_y_pos * 0x200) - 0xE0)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(transition_target_west + (i * 2) + 18,
|
||||
rom()->WriteShort(kTransitionTargetWest + (i * 2) + 18,
|
||||
(uint16_t)((parent_x_pos * 0x200) - 0x100)));
|
||||
|
||||
// Check 7 and 8
|
||||
RETURN_IF_ERROR(rom()->WriteShort(overworldTransitionPositionX + (i * 2),
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionX + (i * 2),
|
||||
(parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(overworldTransitionPositionY + (i * 2),
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionY + (i * 2),
|
||||
(parent_y_pos * 0x200)));
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
overworldTransitionPositionX + (i * 2) + 02, (parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
overworldTransitionPositionY + (i * 2) + 02, (parent_y_pos * 0x200)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(kOverworldTransitionPositionX + (i * 2) + 02,
|
||||
(parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(kOverworldTransitionPositionY + (i * 2) + 02,
|
||||
(parent_y_pos * 0x200)));
|
||||
|
||||
// problematic
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
overworldTransitionPositionX + (i * 2) + 16, (parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
overworldTransitionPositionY + (i * 2) + 16, (parent_y_pos * 0x200)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(kOverworldTransitionPositionX + (i * 2) + 16,
|
||||
(parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(kOverworldTransitionPositionY + (i * 2) + 16,
|
||||
(parent_y_pos * 0x200)));
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
overworldTransitionPositionX + (i * 2) + 18, (parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
overworldTransitionPositionY + (i * 2) + 18, (parent_y_pos * 0x200)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(kOverworldTransitionPositionX + (i * 2) + 18,
|
||||
(parent_x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(kOverworldTransitionPositionY + (i * 2) + 18,
|
||||
(parent_y_pos * 0x200)));
|
||||
|
||||
// Check 9
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 00, 0x0060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 00, 0x0060));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 02, 0x0060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 02, 0x0060));
|
||||
|
||||
// If parentX == 0 then lower submaps == 0x0060 too
|
||||
if (parent_x_pos == 0) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 16, 0x0060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 16, 0x0060));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 18, 0x0060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 18, 0x0060));
|
||||
} else {
|
||||
// Otherwise lower submaps == 0x1060
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 16, 0x1060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 16, 0x1060));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 18, 0x1060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 18, 0x1060));
|
||||
|
||||
// If the area to the left is a large map, we don't need to add an
|
||||
// offset to it. otherwise leave it the same. Just to make sure where
|
||||
@@ -792,7 +793,7 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
// If the area to the left is the bottom right of a large area.
|
||||
if (overworld_maps_[i - 1].large_index() == 1) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2) + 16,
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2) + 16,
|
||||
0x0060));
|
||||
}
|
||||
}
|
||||
@@ -801,14 +802,14 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
|
||||
// Always 0x0080
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2) + 00, 0x0080));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 00, 0x0080));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2) + 2, 0x0080));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 2, 0x0080));
|
||||
// Lower always 0x1080
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2) + 16, 0x1080));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 16, 0x1080));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2) + 18, 0x1080));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 18, 0x1080));
|
||||
|
||||
// If the area to the right is a large map, we don't need to add an offset
|
||||
// to it. otherwise leave it the same. Just to make sure where don't try
|
||||
@@ -819,21 +820,21 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
// If the area to the right is the top left of a large area.
|
||||
if (overworld_maps_[i + 2].large_index() == 0) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2) + 18, 0x0080));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2) + 18, 0x0080));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Always 0x1800
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2), 0x1800));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2), 0x1800));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2) + 16, 0x1800));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 16, 0x1800));
|
||||
// Right side is always 0x1840
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2) + 2, 0x1840));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 2, 0x1840));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2) + 18, 0x1840));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 18, 0x1840));
|
||||
|
||||
// If the area above is a large map, we don't need to add an offset to it.
|
||||
// otherwise leave it the same.
|
||||
@@ -844,21 +845,21 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
// If the area just above us is the bottom left of a large area.
|
||||
if (overworld_maps_[i - 8].large_index() == 2) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2) + 02, 0x1800));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2) + 02, 0x1800));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Always 0x2000
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2) + 00, 0x2000));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 00, 0x2000));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2) + 16, 0x2000));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 16, 0x2000));
|
||||
// Right side always 0x2040
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2) + 2, 0x2040));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 2, 0x2040));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2) + 18, 0x2040));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 18, 0x2040));
|
||||
|
||||
// If the area below is a large map, we don't need to add an offset to it.
|
||||
// otherwise leave it the same.
|
||||
@@ -869,7 +870,7 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
// If the area just below us is the top left of a large area.
|
||||
if (overworld_maps_[i + 16].large_index() == 0) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2) + 18, 0x2000));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2) + 18, 0x2000));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -880,21 +881,21 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
checked_map.emplace_back((i + 9));
|
||||
|
||||
} else {
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldMapSize + i, 0x00));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldMapSizeHighByte + i, 0x01));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapSize + i, 0x00));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapSizeHighByte + i, 0x01));
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldScreenSize + i, 0x01));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldScreenSize + i + 64, 0x01));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldScreenSize + i, 0x01));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldScreenSize + i + 64, 0x01));
|
||||
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(OverworldScreenSizeForLoading + i, 0x02));
|
||||
rom()->WriteByte(kOverworldScreenSizeForLoading + i, 0x02));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(OverworldScreenSizeForLoading + i + 64, 0x02));
|
||||
rom()->WriteByte(kOverworldScreenSizeForLoading + i + 64, 0x02));
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(OverworldScreenSizeForLoading + i + 128, 0x02));
|
||||
rom()->WriteByte(kOverworldScreenSizeForLoading + i + 128, 0x02));
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2), 0x0060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2), 0x0060));
|
||||
|
||||
// If the area to the left is a large map, we don't need to add an offset
|
||||
// to it. otherwise leave it the same.
|
||||
@@ -903,25 +904,25 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
if (overworld_maps_[i - 1].is_large_map()) {
|
||||
if (overworld_maps_[i - 1].large_index() == 3) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen1 + (i * 2), 0xF060));
|
||||
kOverworldScreenTileMapChangeByScreen1 + (i * 2), 0xF060));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2), 0x0040));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2), 0x0040));
|
||||
|
||||
if (i + 1 < 64 && parent_x_pos != 7) {
|
||||
if (overworld_maps_[i + 1].is_large_map()) {
|
||||
if (overworld_maps_[i + 1].large_index() == 2) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen2 + (i * 2), 0xF040));
|
||||
kOverworldScreenTileMapChangeByScreen2 + (i * 2), 0xF040));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2), 0x1800));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2), 0x1800));
|
||||
|
||||
// If the area above is a large map, we don't need to add an offset to it.
|
||||
// otherwise leave it the same.
|
||||
@@ -932,13 +933,13 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
// If we are under the bottom right of the large area.
|
||||
if (overworld_maps_[i - 8].large_index() == 3) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen3 + (i * 2), 0x17C0));
|
||||
kOverworldScreenTileMapChangeByScreen3 + (i * 2), 0x17C0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2), 0x1000));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2), 0x1000));
|
||||
|
||||
// If the area below is a large map, we don't need to add an offset to it.
|
||||
// otherwise leave it the same.
|
||||
@@ -949,19 +950,19 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
// If we are on top of the top right of the large area.
|
||||
if (overworld_maps_[i + 8].large_index() == 1) {
|
||||
RETURN_IF_ERROR(rom()->WriteShort(
|
||||
OverworldScreenTileMapChangeByScreen4 + (i * 2), 0x0FC0));
|
||||
kOverworldScreenTileMapChangeByScreen4 + (i * 2), 0x0FC0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(transition_target_north + (i * 2),
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kTransitionTargetNorth + (i * 2),
|
||||
(uint16_t)((y_pos * 0x200) - 0xE0)));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(transition_target_west + (i * 2),
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kTransitionTargetWest + (i * 2),
|
||||
(uint16_t)((x_pos * 0x200) - 0x100)));
|
||||
|
||||
RETURN_IF_ERROR(rom()->WriteShort(overworldTransitionPositionX + (i * 2),
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionX + (i * 2),
|
||||
(x_pos * 0x200)));
|
||||
RETURN_IF_ERROR(rom()->WriteShort(overworldTransitionPositionY + (i * 2),
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kOverworldTransitionPositionY + (i * 2),
|
||||
(y_pos * 0x200)));
|
||||
|
||||
checked_map.emplace_back(i);
|
||||
@@ -1371,21 +1372,21 @@ absl::Status Overworld::SaveMap16Tiles() {
|
||||
absl::Status Overworld::SaveEntrances() {
|
||||
core::logf("Saving Entrances");
|
||||
for (int i = 0; i < 129; i++) {
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(OWEntranceMap + (i * 2), all_entrances_[i].map_id_))
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(OWEntrancePos + (i * 2), all_entrances_[i].map_pos_))
|
||||
RETURN_IF_ERROR(rom()->WriteByte(OWEntranceEntranceId + i,
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kOverworldEntranceMap + (i * 2),
|
||||
all_entrances_[i].map_id_))
|
||||
RETURN_IF_ERROR(rom()->WriteShort(kOverworldEntrancePos + (i * 2),
|
||||
all_entrances_[i].map_pos_))
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldEntranceEntranceId + i,
|
||||
all_entrances_[i].entrance_id_))
|
||||
}
|
||||
|
||||
for (int i = 0; i < 0x13; i++) {
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(OWHoleArea + (i * 2), all_holes_[i].map_id_))
|
||||
rom()->WriteShort(kOverworldHoleArea + (i * 2), all_holes_[i].map_id_))
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteShort(OWHolePos + (i * 2), all_holes_[i].map_pos_))
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteByte(OWHoleEntrance + i, all_holes_[i].entrance_id_))
|
||||
rom()->WriteShort(kOverworldHolePos + (i * 2), all_holes_[i].map_pos_))
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldHoleEntrance + i,
|
||||
all_holes_[i].entrance_id_))
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
@@ -1426,7 +1427,7 @@ absl::Status Overworld::SaveExits() {
|
||||
|
||||
namespace {
|
||||
|
||||
bool compareItemsArrays(std::vector<OverworldItem> item_array1,
|
||||
bool CompareItemsArrays(std::vector<OverworldItem> item_array1,
|
||||
std::vector<OverworldItem> item_array2) {
|
||||
if (item_array1.size() != item_array2.size()) {
|
||||
return false;
|
||||
@@ -1471,12 +1472,10 @@ absl::Status Overworld::SaveItems() {
|
||||
}
|
||||
}
|
||||
|
||||
int data_pos = overworldItemsPointers + 0x100;
|
||||
|
||||
int data_pos = kOverworldItemsPointers + 0x100;
|
||||
int item_pointers[128];
|
||||
int item_pointers_reuse[128];
|
||||
int empty_pointer = 0;
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
item_pointers_reuse[i] = -1;
|
||||
for (int ci = 0; ci < i; ci++) {
|
||||
@@ -1486,7 +1485,7 @@ absl::Status Overworld::SaveItems() {
|
||||
}
|
||||
|
||||
// Copy into separator vectors from i to ci, then ci to end
|
||||
if (compareItemsArrays(
|
||||
if (CompareItemsArrays(
|
||||
std::vector<OverworldItem>(room_items[i].begin(),
|
||||
room_items[i].end()),
|
||||
std::vector<OverworldItem>(room_items[ci].begin(),
|
||||
@@ -1522,10 +1521,10 @@ absl::Status Overworld::SaveItems() {
|
||||
|
||||
int snesaddr = core::PcToSnes(item_pointers[i]);
|
||||
RETURN_IF_ERROR(
|
||||
rom()->WriteWord(overworldItemsPointers + (i * 2), snesaddr));
|
||||
rom()->WriteWord(kOverworldItemsPointers + (i * 2), snesaddr));
|
||||
}
|
||||
|
||||
if (data_pos > overworldItemsEndData) {
|
||||
if (data_pos > kOverworldItemsEndData) {
|
||||
return absl::AbortedError("Too many items");
|
||||
}
|
||||
|
||||
@@ -1543,11 +1542,11 @@ absl::Status Overworld::SaveMapProperties() {
|
||||
overworld_maps_[i].area_graphics()));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapPaletteIds + i,
|
||||
overworld_maps_[i].area_palette()));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldSpriteset + i,
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + i,
|
||||
overworld_maps_[i].sprite_graphics(0)));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldSpriteset + 64 + i,
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + 64 + i,
|
||||
overworld_maps_[i].sprite_graphics(1)));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldSpriteset + 128 + i,
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + 128 + i,
|
||||
overworld_maps_[i].sprite_graphics(2)));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpritePaletteIds + i,
|
||||
overworld_maps_[i].sprite_palette(0)));
|
||||
@@ -1560,11 +1559,11 @@ absl::Status Overworld::SaveMapProperties() {
|
||||
for (int i = 64; i < 128; i++) {
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kAreaGfxIdPtr + i,
|
||||
overworld_maps_[i].area_graphics()));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldSpriteset + i,
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + i,
|
||||
overworld_maps_[i].sprite_graphics(0)));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldSpriteset + 64 + i,
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + 64 + i,
|
||||
overworld_maps_[i].sprite_graphics(1)));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(overworldSpriteset + 128 + i,
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldSpriteset + 128 + i,
|
||||
overworld_maps_[i].sprite_graphics(2)));
|
||||
RETURN_IF_ERROR(rom()->WriteByte(kOverworldMapPaletteIds + i,
|
||||
overworld_maps_[i].area_palette()));
|
||||
|
||||
@@ -19,44 +19,42 @@
|
||||
namespace yaze {
|
||||
namespace zelda3 {
|
||||
|
||||
constexpr int GravesYTilePos = 0x49968; // short (0x0F entries)
|
||||
constexpr int GravesXTilePos = 0x49986; // short (0x0F entries)
|
||||
constexpr int GravesTilemapPos = 0x499A4; // short (0x0F entries)
|
||||
constexpr int GravesGFX = 0x499C2; // short (0x0F entries)
|
||||
|
||||
constexpr int GravesXPos = 0x4994A; // short (0x0F entries)
|
||||
constexpr int GravesYLine = 0x4993A; // short (0x08 entries)
|
||||
constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries
|
||||
|
||||
constexpr int GravesYTilePos = 0x49968; // short (0x0F entries)
|
||||
constexpr int GravesXTilePos = 0x49986; // short (0x0F entries)
|
||||
constexpr int GravesTilemapPos = 0x499A4; // short (0x0F entries)
|
||||
constexpr int GravesGFX = 0x499C2; // short (0x0F entries)
|
||||
constexpr int GravesXPos = 0x4994A; // short (0x0F entries)
|
||||
constexpr int GravesYLine = 0x4993A; // short (0x08 entries)
|
||||
constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries
|
||||
constexpr int GraveLinkSpecialHole = 0x46DD9; // short
|
||||
constexpr int GraveLinkSpecialStairs = 0x46DE0; // short
|
||||
|
||||
constexpr int kOverworldMapPaletteIds = 0x7D1C;
|
||||
constexpr int kOverworldSpritePaletteIds = 0x7B41;
|
||||
constexpr int overworldMapPaletteGroup = 0x75504;
|
||||
constexpr int overworldSpritePaletteGroup = 0x75580;
|
||||
constexpr int overworldSpriteset = 0x7A41;
|
||||
constexpr int overworldSpecialGFXGroup = 0x16821;
|
||||
constexpr int overworldSpecialPALGroup = 0x16831;
|
||||
constexpr int overworldSpritesBegining = 0x4C881;
|
||||
constexpr int overworldSpritesAgahnim = 0x4CA21;
|
||||
constexpr int overworldSpritesZelda = 0x4C901;
|
||||
constexpr int kOverworldSpritePaletteGroup = 0x75580;
|
||||
constexpr int kOverworldSpriteset = 0x7A41;
|
||||
constexpr int kOverworldSpecialGfxGroup = 0x16821;
|
||||
constexpr int kOverworldSpecialPalGroup = 0x16831;
|
||||
constexpr int kOverworldSpritesBeginning = 0x4C881;
|
||||
constexpr int kOverworldSpritesAgahnim = 0x4CA21;
|
||||
constexpr int kOverworldSpritesZelda = 0x4C901;
|
||||
|
||||
constexpr int kAreaGfxIdPtr = 0x7C9C;
|
||||
constexpr int kOverworldMessageIds = 0x3F51D;
|
||||
|
||||
constexpr int overworldMusicBegining = 0x14303;
|
||||
constexpr int overworldMusicZelda = 0x14303 + 0x40;
|
||||
constexpr int overworldMusicMasterSword = 0x14303 + 0x80;
|
||||
constexpr int overworldMusicAgahim = 0x14303 + 0xC0;
|
||||
constexpr int overworldMusicDW = 0x14403;
|
||||
constexpr int overworldEntranceAllowedTilesLeft = 0xDB8C1;
|
||||
constexpr int overworldEntranceAllowedTilesRight = 0xDB917;
|
||||
constexpr int kOverworldMusicBeginning = 0x14303;
|
||||
constexpr int kOverworldMusicZelda = 0x14303 + 0x40;
|
||||
constexpr int kOverworldMusicMasterSword = 0x14303 + 0x80;
|
||||
constexpr int kOverworldMusicAgahnim = 0x14303 + 0xC0;
|
||||
constexpr int kOverworldMusicDarkWorld = 0x14403;
|
||||
constexpr int kOverworldEntranceAllowedTilesLeft = 0xDB8C1;
|
||||
constexpr int kOverworldEntranceAllowedTilesRight = 0xDB917;
|
||||
|
||||
// 0x00 = small maps, 0x20 = large maps
|
||||
constexpr int overworldMapSize = 0x12844;
|
||||
constexpr int kOverworldMapSize = 0x12844;
|
||||
|
||||
// 0x01 = small maps, 0x03 = large maps
|
||||
constexpr int overworldMapSizeHighByte = 0x12884;
|
||||
constexpr int kOverworldMapSizeHighByte = 0x12884;
|
||||
|
||||
// relative to the WORLD + 0x200 per map
|
||||
// large map that are not == parent id = same position as their parent!
|
||||
@@ -64,22 +62,21 @@ constexpr int overworldMapSizeHighByte = 0x12884;
|
||||
// 0000, 0200, 0400, 0600, 0800, 0A00, 0C00, 0E00
|
||||
// all Large map would be :
|
||||
// 0000, 0000, 0400, 0400, 0800, 0800, 0C00, 0C00
|
||||
constexpr int overworldMapParentId = 0x125EC;
|
||||
constexpr int overworldTransitionPositionY = 0x128C4;
|
||||
constexpr int overworldTransitionPositionX = 0x12944;
|
||||
constexpr int overworldScreenSize = 0x1788D;
|
||||
constexpr int OverworldScreenSizeForLoading = 0x4C635;
|
||||
constexpr int kOverworldMapParentId = 0x125EC;
|
||||
constexpr int kOverworldTransitionPositionY = 0x128C4;
|
||||
constexpr int kOverworldTransitionPositionX = 0x12944;
|
||||
constexpr int kOverworldScreenSize = 0x1788D;
|
||||
constexpr int kOverworldScreenSizeForLoading = 0x4C635;
|
||||
|
||||
// constexpr int OverworldScreenTileMapChangeByScreen = 0x12634;
|
||||
constexpr int OverworldScreenTileMapChangeByScreen1 = 0x12634;
|
||||
constexpr int OverworldScreenTileMapChangeByScreen2 = 0x126B4;
|
||||
constexpr int OverworldScreenTileMapChangeByScreen3 = 0x12734;
|
||||
constexpr int OverworldScreenTileMapChangeByScreen4 = 0x127B4;
|
||||
constexpr int kOverworldScreenTileMapChangeByScreen1 = 0x12634;
|
||||
constexpr int kOverworldScreenTileMapChangeByScreen2 = 0x126B4;
|
||||
constexpr int kOverworldScreenTileMapChangeByScreen3 = 0x12734;
|
||||
constexpr int kOverworldScreenTileMapChangeByScreen4 = 0x127B4;
|
||||
|
||||
constexpr int OverworldMapDataOverflow = 0x130000;
|
||||
constexpr int kOverworldMapDataOverflow = 0x130000;
|
||||
|
||||
constexpr int transition_target_north = 0x13EE2;
|
||||
constexpr int transition_target_west = 0x13F62;
|
||||
constexpr int kTransitionTargetNorth = 0x13EE2;
|
||||
constexpr int kTransitionTargetWest = 0x13F62;
|
||||
constexpr int overworldCustomMosaicASM = 0x1301D0;
|
||||
constexpr int overworldCustomMosaicArray = 0x1301F0;
|
||||
|
||||
@@ -89,6 +86,12 @@ constexpr int kMap32TileTRExpanded = 0x020000;
|
||||
constexpr int kMap32TileBLExpanded = 0x1F0000;
|
||||
constexpr int kMap32TileBRExpanded = 0x1F8000;
|
||||
constexpr int kMap32TileCountExpanded = 0x0067E0;
|
||||
constexpr int kMap32ExpandedFlagPos = 0x01772E; // 0x04
|
||||
constexpr int kMap16ExpandedFlagPos = 0x02FD28; // 0x0F
|
||||
constexpr int kOverworldEntranceExpandedFlagPos = 0x0DB895; // 0xB8
|
||||
|
||||
constexpr int kOverworldCompressedMapPos = 0x058000;
|
||||
constexpr int kOverworldCompressedOverflowPos = 0x137FFF;
|
||||
|
||||
constexpr int kMap16Tiles = 0x78000;
|
||||
constexpr int kNumOverworldMaps = 160;
|
||||
|
||||
Reference in New Issue
Block a user