Refactor overworld map handling to improve custom ASM logic
- Simplified the logic for determining custom overworld behavior based on ASM version, enhancing clarity and maintainability. - Updated comments for better understanding of expanded tile and entrance data checks in the Overworld class. - Ensured that expanded data checks are more straightforward, improving the overall flow of the overworld map assembly process.
This commit is contained in:
@@ -124,12 +124,11 @@ absl::Status Overworld::AssembleMap32Tiles() {
|
|||||||
rom()->version_constants().kMap32TileBL,
|
rom()->version_constants().kMap32TileBL,
|
||||||
rom()->version_constants().kMap32TileBR};
|
rom()->version_constants().kMap32TileBR};
|
||||||
|
|
||||||
// Use ASM version to determine expanded tile32 support, with flag as override
|
// Check if expanded tile32 data is actually present in ROM
|
||||||
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
// The flag position should contain 0x04 for vanilla, something else for expanded
|
||||||
bool use_custom_overworld =
|
uint8_t asm_version = (*rom_)[OverworldCustomASMHasBeenApplied];
|
||||||
(asm_version != 0xFF) ||
|
if (rom()->data()[kMap32ExpandedFlagPos] != 0x04 || asm_version >= 3) {
|
||||||
core::FeatureFlags::get().overworld.kLoadCustomOverworld;
|
// ROM has expanded tile32 data - use expanded addresses
|
||||||
if (rom()->data()[kMap32ExpandedFlagPos] != 0x04 && use_custom_overworld) {
|
|
||||||
map32address[0] = rom()->version_constants().kMap32TileTL;
|
map32address[0] = rom()->version_constants().kMap32TileTL;
|
||||||
map32address[1] = kMap32TileTRExpanded;
|
map32address[1] = kMap32TileTRExpanded;
|
||||||
map32address[2] = kMap32TileBLExpanded;
|
map32address[2] = kMap32TileBLExpanded;
|
||||||
@@ -137,6 +136,7 @@ absl::Status Overworld::AssembleMap32Tiles() {
|
|||||||
num_tile32 = kMap32TileCountExpanded;
|
num_tile32 = kMap32TileCountExpanded;
|
||||||
expanded_tile32_ = true;
|
expanded_tile32_ = true;
|
||||||
}
|
}
|
||||||
|
// Otherwise use vanilla addresses (already set above)
|
||||||
|
|
||||||
// Loop through each 32x32 pixel tile in the rom
|
// Loop through each 32x32 pixel tile in the rom
|
||||||
for (int i = 0; i < num_tile32; i += 6) {
|
for (int i = 0; i < num_tile32; i += 6) {
|
||||||
@@ -178,16 +178,16 @@ absl::Status Overworld::AssembleMap16Tiles() {
|
|||||||
int tpos = kMap16Tiles;
|
int tpos = kMap16Tiles;
|
||||||
int num_tile16 = kNumTile16Individual;
|
int num_tile16 = kNumTile16Individual;
|
||||||
|
|
||||||
// Use ASM version to determine expanded tile16 support, with flag as override
|
// Check if expanded tile16 data is actually present in ROM
|
||||||
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
// The flag position should contain 0x0F for vanilla, something else for expanded
|
||||||
bool use_custom_overworld =
|
uint8_t asm_version = (*rom_)[OverworldCustomASMHasBeenApplied];
|
||||||
(asm_version != 0xFF) ||
|
if (rom()->data()[kMap16ExpandedFlagPos] == 0x0F || asm_version >= 3) {
|
||||||
core::FeatureFlags::get().overworld.kLoadCustomOverworld;
|
// ROM has expanded tile16 data - use expanded addresses
|
||||||
if (rom()->data()[kMap16ExpandedFlagPos] != 0x0F && use_custom_overworld) {
|
|
||||||
tpos = kMap16TilesExpanded;
|
tpos = kMap16TilesExpanded;
|
||||||
num_tile16 = NumberOfMap16Ex;
|
num_tile16 = NumberOfMap16Ex;
|
||||||
expanded_tile16_ = true;
|
expanded_tile16_ = true;
|
||||||
}
|
}
|
||||||
|
// Otherwise use vanilla addresses (already set above)
|
||||||
|
|
||||||
for (int i = 0; i < num_tile16; i += 1) {
|
for (int i = 0; i < num_tile16; i += 1) {
|
||||||
ASSIGN_OR_RETURN(auto t0_data, rom()->ReadWord(tpos));
|
ASSIGN_OR_RETURN(auto t0_data, rom()->ReadWord(tpos));
|
||||||
@@ -331,19 +331,17 @@ absl::Status Overworld::LoadEntrances() {
|
|||||||
int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
|
int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
|
||||||
int num_entrances = 129;
|
int num_entrances = 129;
|
||||||
|
|
||||||
// Use ASM version to determine expanded entrance support, with flag as override
|
// Check if expanded entrance data is actually present in ROM
|
||||||
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
// The flag position should contain 0xB8 for vanilla, something else for expanded
|
||||||
bool use_custom_overworld =
|
if (rom()->data()[kOverworldEntranceExpandedFlagPos] != 0xB8) {
|
||||||
(asm_version != 0xFF) ||
|
// ROM has expanded entrance data - use expanded addresses
|
||||||
core::FeatureFlags::get().overworld.kLoadCustomOverworld;
|
|
||||||
if (rom()->data()[kOverworldEntranceExpandedFlagPos] != 0xB8 &&
|
|
||||||
use_custom_overworld) {
|
|
||||||
ow_entrance_map_ptr = kOverworldEntranceMapExpanded;
|
ow_entrance_map_ptr = kOverworldEntranceMapExpanded;
|
||||||
ow_entrance_pos_ptr = kOverworldEntrancePosExpanded;
|
ow_entrance_pos_ptr = kOverworldEntrancePosExpanded;
|
||||||
ow_entrance_id_ptr = kOverworldEntranceEntranceIdExpanded;
|
ow_entrance_id_ptr = kOverworldEntranceEntranceIdExpanded;
|
||||||
expanded_entrances_ = true;
|
expanded_entrances_ = true;
|
||||||
num_entrances = 256; // Expanded entrance count
|
num_entrances = 256; // Expanded entrance count
|
||||||
}
|
}
|
||||||
|
// Otherwise use vanilla addresses (already set above)
|
||||||
|
|
||||||
for (int i = 0; i < num_entrances; i++) {
|
for (int i = 0; i < num_entrances; i++) {
|
||||||
ASSIGN_OR_RETURN(auto map_id,
|
ASSIGN_OR_RETURN(auto map_id,
|
||||||
@@ -443,9 +441,9 @@ absl::Status Overworld::LoadItems() {
|
|||||||
// Version 0x03 of the OW ASM added item support for the SW.
|
// Version 0x03 of the OW ASM added item support for the SW.
|
||||||
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
// Determine max number of overworld maps based on ASM version
|
// Determine max number of overworld maps based on actual ASM version
|
||||||
int max_ow =
|
// Only use expanded maps (0xA0) if v3+ ASM is actually applied
|
||||||
(asm_version >= 0x03 && asm_version != 0xFF) ? kNumOverworldMaps : 0x80;
|
int max_ow = (asm_version >= 0x03 && asm_version != 0xFF) ? kNumOverworldMaps : 0x80;
|
||||||
|
|
||||||
ASSIGN_OR_RETURN(uint32_t pointer_snes,
|
ASSIGN_OR_RETURN(uint32_t pointer_snes,
|
||||||
rom()->ReadLong(zelda3::overworldItemsAddress));
|
rom()->ReadLong(zelda3::overworldItemsAddress));
|
||||||
@@ -508,13 +506,10 @@ absl::Status Overworld::LoadItems() {
|
|||||||
absl::Status Overworld::LoadSprites() {
|
absl::Status Overworld::LoadSprites() {
|
||||||
std::vector<std::future<absl::Status>> futures;
|
std::vector<std::future<absl::Status>> futures;
|
||||||
|
|
||||||
// Use ASM version to determine sprite table locations, with flag as override
|
// Determine sprite table locations based on actual ASM version in ROM
|
||||||
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
bool use_custom_overworld =
|
|
||||||
(asm_version != 0xFF) ||
|
|
||||||
core::FeatureFlags::get().overworld.kLoadCustomOverworld;
|
|
||||||
|
|
||||||
if (use_custom_overworld && asm_version >= 3 && asm_version != 0xFF) {
|
if (asm_version >= 3 && asm_version != 0xFF) {
|
||||||
// v3: Use expanded sprite tables
|
// v3: Use expanded sprite tables
|
||||||
futures.emplace_back(std::async(std::launch::async, [this]() {
|
futures.emplace_back(std::async(std::launch::async, [this]() {
|
||||||
return LoadSpritesFromMap(overworldSpritesBeginingExpanded, 64, 0);
|
return LoadSpritesFromMap(overworldSpritesBeginingExpanded, 64, 0);
|
||||||
|
|||||||
@@ -18,21 +18,23 @@ OverworldMap::OverworldMap(int index, Rom *rom)
|
|||||||
: index_(index), parent_(index), rom_(rom) {
|
: index_(index), parent_(index), rom_(rom) {
|
||||||
LoadAreaInfo();
|
LoadAreaInfo();
|
||||||
|
|
||||||
// Use ASM version byte as source of truth, with flag as override
|
// Use ASM version byte as source of truth
|
||||||
uint8_t asm_version = (*rom_)[OverworldCustomASMHasBeenApplied];
|
uint8_t asm_version = (*rom_)[OverworldCustomASMHasBeenApplied];
|
||||||
bool use_custom_overworld = (asm_version != 0xFF) ||
|
|
||||||
core::FeatureFlags::get().overworld.kLoadCustomOverworld;
|
|
||||||
|
|
||||||
if (use_custom_overworld) {
|
if (asm_version != 0xFF) {
|
||||||
if (asm_version == 0x00 || asm_version == 0xFF) {
|
// Custom overworld ASM is applied - use custom logic
|
||||||
// No custom ASM applied but flag enabled - set up vanilla values manually
|
if (asm_version == 0x00) {
|
||||||
|
// Special case: version 0 means flag-enabled vanilla mode
|
||||||
LoadCustomOverworldData();
|
LoadCustomOverworldData();
|
||||||
} else {
|
} else {
|
||||||
// Custom overworld ASM applied - set up custom tileset
|
// Custom overworld ASM applied - set up custom tileset
|
||||||
SetupCustomTileset(asm_version);
|
SetupCustomTileset(asm_version);
|
||||||
}
|
}
|
||||||
|
} else if (core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
|
||||||
|
// Pure vanilla ROM but flag enabled - set up custom data manually
|
||||||
|
LoadCustomOverworldData();
|
||||||
}
|
}
|
||||||
// For vanilla ROMs without flag, LoadAreaInfo already handles everything
|
// For pure vanilla ROMs, LoadAreaInfo already handles everything
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
||||||
|
|||||||
Reference in New Issue
Block a user