Add support for JP rom and headered ROMs
This commit is contained in:
@@ -21,16 +21,14 @@ namespace zelda3 {
|
||||
|
||||
namespace {
|
||||
|
||||
uint GetOwMapGfxHighPtr(const uchar *rom, int index) {
|
||||
int map_high_ptr = core::compressedAllMap32PointersHigh;
|
||||
uint GetOwMapGfxHighPtr(const uchar *rom, int index, uint32_t map_high_ptr) {
|
||||
int p1 = (rom[map_high_ptr + 2 + (3 * index)] << 16) +
|
||||
(rom[map_high_ptr + 1 + (3 * index)] << 8) +
|
||||
(rom[map_high_ptr + (3 * index)]);
|
||||
return core::SnesToPc(p1);
|
||||
}
|
||||
|
||||
uint GetOwMapGfxLowPtr(const uchar *rom, int index) {
|
||||
int map_low_ptr = core::compressedAllMap32PointersLow;
|
||||
uint GetOwMapGfxLowPtr(const uchar *rom, int index, uint32_t map_low_ptr) {
|
||||
int p2 = (rom[map_low_ptr + 2 + (3 * index)] << 16) +
|
||||
(rom[map_low_ptr + 1 + (3 * index)] << 8) +
|
||||
(rom[map_low_ptr + (3 * index)]);
|
||||
@@ -321,13 +319,13 @@ void Overworld::SaveMap32Tiles() {
|
||||
}
|
||||
};
|
||||
|
||||
write_tiles(core::map32TilesTL,
|
||||
write_tiles(rom_.GetVersionConstants().kMap32TileTL,
|
||||
[&](int i) { return tiles32_unique_[i].tile0_; });
|
||||
write_tiles(core::map32TilesTR,
|
||||
write_tiles(rom_.GetVersionConstants().kMap32TileTR,
|
||||
[&](int i) { return tiles32_unique_[i].tile1_; });
|
||||
write_tiles(core::map32TilesBL,
|
||||
write_tiles(rom_.GetVersionConstants().kMap32TileBL,
|
||||
[&](int i) { return tiles32_unique_[i].tile2_; });
|
||||
write_tiles(core::map32TilesBR,
|
||||
write_tiles(rom_.GetVersionConstants().kMap32TileBR,
|
||||
[&](int i) { return tiles32_unique_[i].tile3_; });
|
||||
|
||||
if (unique_size > max_tiles) {
|
||||
@@ -338,6 +336,11 @@ void Overworld::SaveMap32Tiles() {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ushort Overworld::GenerateTile32(int i, int k, int dimension) {
|
||||
const uint32_t map32address[4] = {rom_.GetVersionConstants().kMap32TileTL,
|
||||
rom_.GetVersionConstants().kMap32TileTR,
|
||||
rom_.GetVersionConstants().kMap32TileBL,
|
||||
rom_.GetVersionConstants().kMap32TileBR};
|
||||
|
||||
return (ushort)(rom_[map32address[dimension] + k + (i)] +
|
||||
(((rom_[map32address[dimension] + (i) + (k <= 1 ? 4 : 5)] >>
|
||||
(k % 2 == 0 ? 4 : 0)) &
|
||||
@@ -428,8 +431,12 @@ absl::Status Overworld::DecompressAllMapTiles() {
|
||||
int sy = 0;
|
||||
int c = 0;
|
||||
for (int i = 0; i < 160; i++) {
|
||||
auto p1 = GetOwMapGfxHighPtr(rom_.data(), i);
|
||||
auto p2 = GetOwMapGfxLowPtr(rom_.data(), i);
|
||||
auto p1 = GetOwMapGfxHighPtr(
|
||||
rom_.data(), i,
|
||||
rom_.GetVersionConstants().compressedAllMap32PointersHigh);
|
||||
auto p2 = GetOwMapGfxLowPtr(
|
||||
rom_.data(), i,
|
||||
rom_.GetVersionConstants().compressedAllMap32PointersLow);
|
||||
int ttpos = 0;
|
||||
|
||||
if (p1 >= highest) {
|
||||
@@ -627,6 +634,51 @@ void Overworld::LoadSpritesFromMap(int spriteStart, int spriteCount,
|
||||
}
|
||||
}
|
||||
|
||||
absl::Status Overworld::LoadPrototype(ROM &rom, std::vector<uint8_t> &tilemap,
|
||||
std::vector<uint8_t> tile32) {
|
||||
rom_ = rom;
|
||||
|
||||
AssembleMap32Tiles();
|
||||
AssembleMap16Tiles();
|
||||
RETURN_IF_ERROR(DecompressAllMapTiles())
|
||||
|
||||
for (int map_index = 0; map_index < core::kNumOverworldMaps; ++map_index)
|
||||
overworld_maps_.emplace_back(map_index, rom_, tiles16);
|
||||
|
||||
FetchLargeMaps();
|
||||
LoadEntrances();
|
||||
|
||||
auto size = tiles16.size();
|
||||
std::vector<std::future<absl::Status>> futures;
|
||||
for (int i = 0; i < core::kNumOverworldMaps; ++i) {
|
||||
futures.push_back(std::async(std::launch::async, [this, i, size]() {
|
||||
if (i < 64) {
|
||||
return overworld_maps_[i].BuildMap(size, game_state_, 0, map_parent_,
|
||||
map_tiles_.light_world);
|
||||
} else if (i < 0x80 && i >= 0x40) {
|
||||
return overworld_maps_[i].BuildMap(size, game_state_, 1, map_parent_,
|
||||
map_tiles_.dark_world);
|
||||
} else {
|
||||
return overworld_maps_[i].BuildMap(size, game_state_, 2, map_parent_,
|
||||
map_tiles_.special_world);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Wait for all tasks to complete and check their results
|
||||
for (auto &future : futures) {
|
||||
absl::Status status = future.get();
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
// LoadSprites();
|
||||
|
||||
is_loaded_ = true;
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace zelda3
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
@@ -94,9 +94,10 @@ class Overworld {
|
||||
auto isLoaded() const { return is_loaded_; }
|
||||
void SetCurrentMap(int i) { current_map_ = i; }
|
||||
|
||||
absl::Status LoadPrototype(ROM &rom_, std::vector<uint8_t> &tilemap,
|
||||
std::vector<uint8_t> tile32);
|
||||
|
||||
private:
|
||||
const int map32address[4] = {core::map32TilesTL, core::map32TilesTR,
|
||||
core::map32TilesBL, core::map32TilesBR};
|
||||
enum Dimension {
|
||||
map32TilesTL = 0,
|
||||
map32TilesTR = 1,
|
||||
|
||||
@@ -285,22 +285,24 @@ void OverworldMap::LoadSpritesBlocksets() {
|
||||
static_graphics_[11] = static_graphics_base + 0x07;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
static_graphics_[12 + i] = (rom_[core::kSpriteBlocksetPointer +
|
||||
(sprite_graphics_[game_state_] * 4) + i] +
|
||||
static_graphics_base);
|
||||
static_graphics_[12 + i] =
|
||||
(rom_[rom_.GetVersionConstants().kSpriteBlocksetPointer +
|
||||
(sprite_graphics_[game_state_] * 4) + i] +
|
||||
static_graphics_base);
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::LoadMainBlocksets() {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
static_graphics_[i] =
|
||||
rom_[core::overworldgfxGroups2 + (world_index_ * 8) + i];
|
||||
static_graphics_[i] = rom_[rom_.GetVersionConstants().kOverworldGfxGroups2 +
|
||||
(world_index_ * 8) + i];
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::LoadAreaGraphicsBlocksets() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
uchar value = rom_[core::overworldgfxGroups + (area_graphics_ * 4) + i];
|
||||
uchar value = rom_[rom_.GetVersionConstants().kOverworldGfxGroups1 +
|
||||
(area_graphics_ * 4) + i];
|
||||
if (value != 0) {
|
||||
static_graphics_[3 + i] = value;
|
||||
}
|
||||
@@ -328,7 +330,8 @@ void OverworldMap::LoadAreaGraphics() {
|
||||
gfx::SNESPalette OverworldMap::GetPalette(const std::string& group, int index,
|
||||
int previousIndex, int limit) {
|
||||
if (index == 255) {
|
||||
index = rom_[core::overworldMapPaletteGroup + (previousIndex * 4)];
|
||||
index = rom_[rom_.GetVersionConstants().overworldMapPaletteGroup +
|
||||
(previousIndex * 4)];
|
||||
}
|
||||
if (index != 255) {
|
||||
if (index >= limit) {
|
||||
@@ -349,9 +352,12 @@ void OverworldMap::LoadPalette() {
|
||||
area_palette_ = std::min(area_palette_, 0xA3);
|
||||
|
||||
uchar pal0 = 0;
|
||||
uchar pal1 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4)];
|
||||
uchar pal2 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4) + 1];
|
||||
uchar pal3 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4) + 2];
|
||||
uchar pal1 = rom_[rom_.GetVersionConstants().overworldMapPaletteGroup +
|
||||
(area_palette_ * 4)];
|
||||
uchar pal2 = rom_[rom_.GetVersionConstants().overworldMapPaletteGroup +
|
||||
(area_palette_ * 4) + 1];
|
||||
uchar pal3 = rom_[rom_.GetVersionConstants().overworldMapPaletteGroup +
|
||||
(area_palette_ * 4) + 2];
|
||||
uchar pal4 = rom_[core::overworldSpritePaletteGroup +
|
||||
(sprite_palette_[game_state_] * 2)];
|
||||
uchar pal5 = rom_[core::overworldSpritePaletteGroup +
|
||||
@@ -364,7 +370,8 @@ void OverworldMap::LoadPalette() {
|
||||
|
||||
// Additional handling of `pal3` and `parent_`
|
||||
if (pal3 == 255) {
|
||||
pal3 = rom_[core::overworldMapPaletteGroup + (previousPalId * 4) + 2];
|
||||
pal3 = rom_[rom_.GetVersionConstants().overworldMapPaletteGroup +
|
||||
(previousPalId * 4) + 2];
|
||||
}
|
||||
if (parent_ < 0x40) {
|
||||
pal0 = parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07 ? 2 : 0;
|
||||
|
||||
Reference in New Issue
Block a user