The Rom class is used to load, save, and modify Rom data. More...
#include <rom.h>
Classes | |
struct | SaveSettings |
struct | WriteAction |
Public Member Functions | |
absl::Status | LoadFromFile (const std::string &filename, bool z3_load=true) |
absl::Status | LoadFromData (const std::vector< uint8_t > &data, bool z3_load=true) |
absl::Status | LoadZelda3 () |
absl::Status | LoadGfxGroups () |
absl::Status | SaveGfxGroups () |
absl::Status | SaveToFile (const SaveSettings &settings) |
absl::Status | SavePalette (int index, const std::string &group_name, gfx::SnesPalette &palette) |
absl::Status | SaveAllPalettes () |
void | Expand (int size) |
void | Close () |
absl::StatusOr< uint8_t > | ReadByte (int offset) |
absl::StatusOr< uint16_t > | ReadWord (int offset) |
absl::StatusOr< uint32_t > | ReadLong (int offset) |
absl::StatusOr< std::vector< uint8_t > > | ReadByteVector (uint32_t offset, uint32_t length) const |
absl::StatusOr< gfx::Tile16 > | ReadTile16 (uint32_t tile16_id) |
absl::Status | WriteTile16 (int tile16_id, const gfx::Tile16 &tile) |
absl::Status | WriteByte (int addr, uint8_t value) |
absl::Status | WriteWord (int addr, uint16_t value) |
absl::Status | WriteShort (int addr, uint16_t value) |
absl::Status | WriteLong (uint32_t addr, uint32_t value) |
absl::Status | WriteVector (int addr, std::vector< uint8_t > data) |
absl::Status | WriteColor (uint32_t address, const gfx::SnesColor &color) |
template<typename... Args> | |
absl::Status | WriteTransaction (Args... args) |
template<typename T, typename... Args> | |
absl::Status | ReadTransaction (T &var, int address, Args &&... args) |
virtual absl::Status | WriteHelper (const WriteAction &action) |
template<typename T> | |
absl::Status | ReadHelper (T &var, int address) |
uint8_t & | operator[] (unsigned long i) |
bool | is_loaded () const |
auto | title () const |
auto | size () const |
auto | data () const |
auto | mutable_data () |
auto | begin () |
auto | end () |
auto | vector () const |
auto | filename () const |
auto | set_filename (std::string_view name) |
auto | short_name () const |
auto | graphics_buffer () const |
auto | mutable_graphics_buffer () |
auto | palette_group () const |
auto | mutable_palette_group () |
auto | dungeon_palette (int i) |
auto | mutable_dungeon_palette (int i) |
ResourceLabelManager * | resource_label () |
zelda3_version_pointers | version_constants () const |
Public Attributes | |
std::array< std::array< uint8_t, 8 >, kNumMainBlocksets > | main_blockset_ids |
std::array< std::array< uint8_t, 4 >, kNumRoomBlocksets > | room_blockset_ids |
std::array< std::array< uint8_t, 4 >, kNumSpritesets > | spriteset_ids |
std::array< std::array< uint8_t, 4 >, kNumPalettesets > | paletteset_ids |
Private Attributes | |
unsigned long | size_ = 0 |
std::string | title_ = "ROM not loaded" |
std::string | filename_ = "" |
std::string | short_name_ = "" |
std::vector< uint8_t > | rom_data_ |
std::vector< uint8_t > | graphics_buffer_ |
ResourceLabelManager | resource_label_manager_ |
gfx::PaletteGroupMap | palette_groups_ |
zelda3_version | version_ = zelda3_version::US |
absl::Status yaze::Rom::LoadFromFile | ( | const std::string & | filename, |
bool | z3_load = true ) |
Definition at line 231 of file rom.cc.
References filename(), filename_, LoadZelda3(), resource_label_manager_, RETURN_IF_ERROR, rom_data_, short_name_, and size_.
Referenced by yaze::editor::MessageEditor::DrawExpandedMessageSettings(), main(), yaze::cli::Tile16Transfer::Run(), yaze::editor::MemoryEditorWithDiffChecker::Update(), and yaze_load_rom().
absl::Status yaze::Rom::LoadFromData | ( | const std::vector< uint8_t > & | data, |
bool | z3_load = true ) |
Definition at line 271 of file rom.cc.
References data(), LoadZelda3(), RETURN_IF_ERROR, rom_data_, and size_.
Referenced by yaze::test::anonymous_namespace{compression_test.cc}::ExpectCompressOk(), yaze::test::anonymous_namespace{compression_test.cc}::ExpectDecompressBytesOk(), yaze::test::anonymous_namespace{compression_test.cc}::ExpectDecompressOk(), yaze::test::TEST_F(), yaze::test::TEST_F(), yaze::test::TEST_F(), yaze::test::TEST_F(), yaze::gfx::lc_lz2::ValidateCompressionResult(), and yaze::gfx::lc_lz2::ValidateCompressionResultV3().
absl::Status yaze::Rom::LoadZelda3 | ( | ) |
Definition at line 284 of file rom.cc.
References JP, yaze::gfx::LoadAllPalettes(), LoadGfxGroups(), palette_groups_, RETURN_IF_ERROR, rom_data_, size_, title_, US, and version_.
Referenced by LoadFromData(), and LoadFromFile().
absl::Status yaze::Rom::LoadGfxGroups | ( | ) |
Definition at line 320 of file rom.cc.
References ASSIGN_OR_RETURN, zelda3_version_pointers::kDungeonPalettesGroups, yaze::kEntranceGfxGroup, yaze::kGfxGroupsPointer, yaze::kNumMainBlocksets, yaze::kNumPalettesets, yaze::kNumRoomBlocksets, yaze::kNumSpritesets, zelda3_version_pointers::kSpriteBlocksetPointer, main_blockset_ids, paletteset_ids, ReadWord(), rom_data_, room_blockset_ids, yaze::SnesToPc(), spriteset_ids, and version_constants().
Referenced by LoadZelda3().
absl::Status yaze::Rom::SaveGfxGroups | ( | ) |
Definition at line 353 of file rom.cc.
References ASSIGN_OR_RETURN, zelda3_version_pointers::kDungeonPalettesGroups, yaze::kEntranceGfxGroup, yaze::kGfxGroupsPointer, yaze::kNumMainBlocksets, yaze::kNumPalettesets, yaze::kNumRoomBlocksets, yaze::kNumSpritesets, zelda3_version_pointers::kSpriteBlocksetPointer, main_blockset_ids, paletteset_ids, ReadWord(), rom_data_, room_blockset_ids, yaze::SnesToPc(), spriteset_ids, and version_constants().
Referenced by SaveToFile().
absl::Status yaze::Rom::SaveToFile | ( | const SaveSettings & | settings | ) |
Definition at line 386 of file rom.cc.
References yaze::Rom::SaveSettings::backup, filename(), yaze::Rom::SaveSettings::filename, filename_, yaze::core::FeatureFlags::get(), RETURN_IF_ERROR, rom_data_, yaze::Rom::SaveSettings::save_new, SaveAllPalettes(), SaveGfxGroups(), and yaze::Rom::SaveSettings::z3_save.
Referenced by yaze::cli::Tile16Transfer::Run(), and yaze_save_rom().
absl::Status yaze::Rom::SavePalette | ( | int | index, |
const std::string & | group_name, | ||
gfx::SnesPalette & | palette ) |
Definition at line 488 of file rom.cc.
References yaze::gfx::GetPaletteAddress(), yaze::gfx::SnesColor::is_modified(), RETURN_IF_ERROR, yaze::gfx::SnesColor::set_modified(), yaze::gfx::SnesPalette::size(), and WriteColor().
absl::Status yaze::Rom::SaveAllPalettes | ( | ) |
Definition at line 502 of file rom.cc.
References palette_groups_, and RETURN_IF_ERROR.
Referenced by SaveToFile().
|
inline |
|
inline |
Definition at line 84 of file rom.h.
References palette_groups_, rom_data_, and size_.
absl::StatusOr< uint8_t > yaze::Rom::ReadByte | ( | int | offset | ) |
Definition at line 515 of file rom.cc.
References ReadByte(), and rom_data_.
Referenced by yaze::zelda3::LoadDungeonMaps(), yaze::test::MockRom::MOCK_METHOD(), ReadByte(), and ReadHelper().
absl::StatusOr< uint16_t > yaze::Rom::ReadWord | ( | int | offset | ) |
Definition at line 522 of file rom.cc.
References ReadWord(), and rom_data_.
Referenced by yaze::editor::DungeonEditor::Load(), yaze::zelda3::LoadDungeonMaps(), yaze::zelda3::LoadDungeonMapTile16(), yaze::zelda3::LoadEntranceTileTypes(), LoadGfxGroups(), yaze::test::MockRom::MOCK_METHOD(), ReadHelper(), ReadTile16(), ReadWord(), and SaveGfxGroups().
absl::StatusOr< uint32_t > yaze::Rom::ReadLong | ( | int | offset | ) |
Definition at line 530 of file rom.cc.
References ReadLong(), and rom_data_.
Referenced by yaze::test::MockRom::MOCK_METHOD(), and ReadLong().
absl::StatusOr< std::vector< uint8_t > > yaze::Rom::ReadByteVector | ( | uint32_t | offset, |
uint32_t | length ) const |
Definition at line 539 of file rom.cc.
References ReadByteVector(), and rom_data_.
Referenced by yaze::LoadLinkGraphics(), ReadByteVector(), and ReadHelper().
absl::StatusOr< gfx::Tile16 > yaze::Rom::ReadTile16 | ( | uint32_t | tile16_id | ) |
Definition at line 551 of file rom.cc.
References ASSIGN_OR_RETURN, yaze::kTile16Ptr, ReadTile16(), ReadWord(), and yaze::gfx::WordToTileInfo().
Referenced by ReadTile16(), and yaze::cli::Tile16Transfer::Run().
absl::Status yaze::Rom::WriteTile16 | ( | int | tile16_id, |
const gfx::Tile16 & | tile ) |
Definition at line 569 of file rom.cc.
References yaze::kTile16Ptr, RETURN_IF_ERROR, yaze::gfx::Tile16::tile0_, yaze::gfx::Tile16::tile1_, yaze::gfx::Tile16::tile2_, yaze::gfx::Tile16::tile3_, yaze::gfx::TileInfoToWord(), WriteShort(), and WriteTile16().
Referenced by yaze::cli::Tile16Transfer::Run(), and WriteTile16().
absl::Status yaze::Rom::WriteByte | ( | int | addr, |
uint8_t | value ) |
Definition at line 582 of file rom.cc.
References data(), yaze::util::HexByte(), rom_data_, and WriteByte().
Referenced by yaze::zelda3::RoomEntrance::Save(), yaze::zelda3::SaveDungeonMaps(), WriteByte(), and WriteHelper().
absl::Status yaze::Rom::WriteWord | ( | int | addr, |
uint16_t | value ) |
Definition at line 593 of file rom.cc.
References data(), yaze::util::HexWord(), rom_data_, and WriteWord().
Referenced by yaze::zelda3::SaveDungeonMapTile16(), and WriteWord().
absl::Status yaze::Rom::WriteShort | ( | int | addr, |
uint16_t | value ) |
Definition at line 605 of file rom.cc.
References data(), yaze::util::HexWord(), rom_data_, and WriteShort().
Referenced by yaze::zelda3::RoomEntrance::Save(), WriteColor(), WriteHelper(), WriteShort(), and WriteTile16().
absl::Status yaze::Rom::WriteLong | ( | uint32_t | addr, |
uint32_t | value ) |
Definition at line 617 of file rom.cc.
References data(), yaze::util::HexLong(), rom_data_, and WriteLong().
Referenced by WriteLong().
absl::Status yaze::Rom::WriteVector | ( | int | addr, |
std::vector< uint8_t > | data ) |
Definition at line 630 of file rom.cc.
References data(), yaze::util::HexByte(), rom_data_, and WriteVector().
Referenced by WriteHelper(), and WriteVector().
absl::Status yaze::Rom::WriteColor | ( | uint32_t | address, |
const gfx::SnesColor & | color ) |
Definition at line 643 of file rom.cc.
References data(), yaze::util::HexWord(), yaze::gfx::SnesColor::snes(), WriteColor(), and WriteShort().
Referenced by SavePalette(), WriteColor(), and WriteHelper().
|
inline |
Definition at line 106 of file rom.h.
References WriteHelper().
Referenced by yaze::test::TEST_F(), and yaze::test::TEST_F().
|
inline |
Definition at line 114 of file rom.h.
References ReadHelper(), and ReadTransaction().
Referenced by ReadTransaction(), yaze::test::TEST_F(), and yaze::test::TEST_F().
|
inlinevirtual |
Definition at line 133 of file rom.h.
References yaze::Rom::WriteAction::address, yaze::Rom::WriteAction::value, WriteByte(), WriteColor(), WriteShort(), and WriteVector().
Referenced by yaze::test::MockRom::MOCK_METHOD(), and WriteTransaction().
|
inline |
Definition at line 155 of file rom.h.
References ASSIGN_OR_RETURN, ReadByte(), ReadByteVector(), and ReadWord().
Referenced by yaze::test::MockRom::MOCK_METHOD2(), yaze::test::MockRom::MOCK_METHOD2(), yaze::test::MockRom::MOCK_METHOD2(), and ReadTransaction().
|
inline |
|
inline |
|
inline |
Definition at line 176 of file rom.h.
References size_.
Referenced by Expand(), yaze::editor::MemoryEditorWithDiffChecker::Update(), yaze::gfx::lc_lz2::ValidateCompressionResult(), yaze::gfx::lc_lz2::ValidateCompressionResultV3(), and yaze_load_rom().
|
inline |
Definition at line 177 of file rom.h.
References rom_data_.
Referenced by yaze::editor::BuildDictionaryEntries(), yaze::zelda3::CalculateRoomSize(), yaze::test::anonymous_namespace{compression_test.cc}::ExpectDecompressBytesOk(), yaze::test::anonymous_namespace{compression_test.cc}::ExpectDecompressOk(), yaze::editor::MessageEditor::Initialize(), yaze::Load2BppGraphics(), yaze::LoadAllGraphicsData(), yaze::zelda3::LoadDungeonMaps(), yaze::zelda3::LoadDungeonMapTile16(), yaze::LoadFontGraphics(), LoadFromData(), yaze::zelda3::LoadRoomFromRom(), yaze::zelda3::RoomEntrance::RoomEntrance(), yaze::SaveAllGraphicsData(), yaze::zelda3::SaveDungeonMapTile16(), yaze::gfx::lc_lz2::ValidateCompressionResult(), yaze::gfx::lc_lz2::ValidateCompressionResultV3(), WriteByte(), WriteColor(), WriteLong(), WriteShort(), WriteVector(), WriteWord(), and yaze_load_rom().
|
inline |
Definition at line 178 of file rom.h.
References rom_data_.
Referenced by yaze::editor::MessageEditor::DrawExpandedMessageSettings(), yaze::zelda3::music::Tracker::GetSpcAddr(), yaze::zelda3::music::Tracker::LoadSongs(), yaze::zelda3::music::Tracker::SaveSongs(), and yaze::zelda3::music::Tracker::WriteSpcData().
|
inline |
Definition at line 179 of file rom.h.
References rom_data_.
Referenced by yaze::SaveAllGraphicsData(), yaze::gfx::lc_lz2::ValidateCompressionResult(), and yaze::gfx::lc_lz2::ValidateCompressionResultV3().
|
inline |
Definition at line 181 of file rom.h.
References rom_data_.
Referenced by yaze::test::anonymous_namespace{compression_test.cc}::ExpectCompressOk(), main(), and yaze::editor::MessageEditor::Save().
|
inline |
Definition at line 182 of file rom.h.
References filename_.
Referenced by LoadFromFile(), SaveToFile(), and yaze::editor::MemoryEditorWithDiffChecker::Update().
|
inline |
|
inline |
Definition at line 184 of file rom.h.
References short_name_.
|
inline |
Definition at line 185 of file rom.h.
References graphics_buffer_.
|
inline |
Definition at line 186 of file rom.h.
References graphics_buffer_.
Referenced by yaze::LoadAllGraphicsData().
|
inline |
Definition at line 187 of file rom.h.
References palette_groups_.
Referenced by yaze::editor::GraphicsEditor::DecompressImportData(), yaze::editor::GraphicsEditor::DecompressSuperDonkey(), yaze::editor::MessageEditor::Initialize(), yaze::editor::DungeonEditor::Load(), yaze::LoadAllGraphicsData(), yaze::LoadLinkGraphics(), yaze::editor::DungeonEditor::RefreshGraphics(), yaze::zelda3::palette_internal::SetColorsPalette(), yaze::editor::DungeonEditor::UpdateDungeonRoomView(), yaze::editor::GraphicsEditor::UpdatePaletteColumn(), and yaze_get_color_from_paletteset().
|
inline |
Definition at line 188 of file rom.h.
References palette_groups_.
Referenced by yaze::editor::PaletteEditor::DrawPaletteGroup().
|
inline |
Definition at line 189 of file rom.h.
References palette_groups_.
|
inline |
Definition at line 190 of file rom.h.
References palette_groups_.
Referenced by yaze::zelda3::LoadDungeonMapGfxFromBinary(), and yaze::zelda3::LoadDungeonMapTile16().
|
inline |
Definition at line 194 of file rom.h.
References resource_label_manager_.
Referenced by yaze::editor::ScreenEditor::DrawDungeonMapsEditor(), yaze::editor::DungeonEditor::DrawEntranceSelector(), yaze::editor::PaletteEditor::DrawPaletteGroup(), yaze::editor::DungeonEditor::DrawRoomSelector(), yaze::editor::SpriteEditor::DrawSpritesList(), and yaze::editor::PaletteEditor::Load().
|
inline |
Definition at line 195 of file rom.h.
References version_.
Referenced by yaze::Load2BppGraphics(), yaze::LoadAllGraphicsData(), LoadGfxGroups(), yaze::SaveAllGraphicsData(), and SaveGfxGroups().
std::array<std::array<uint8_t, 8>, kNumMainBlocksets> yaze::Rom::main_blockset_ids |
Definition at line 199 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGfxGroups().
std::array<std::array<uint8_t, 4>, kNumRoomBlocksets> yaze::Rom::room_blockset_ids |
Definition at line 200 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGfxGroups().
std::array<std::array<uint8_t, 4>, kNumSpritesets> yaze::Rom::spriteset_ids |
Definition at line 201 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGfxGroups().
std::array<std::array<uint8_t, 4>, kNumPalettesets> yaze::Rom::paletteset_ids |
Definition at line 202 of file rom.h.
Referenced by yaze::editor::DungeonEditor::Load(), LoadGfxGroups(), and SaveGfxGroups().
|
private |
Definition at line 206 of file rom.h.
Referenced by Close(), Expand(), LoadFromData(), LoadFromFile(), LoadZelda3(), operator[](), and size().
|
private |
Definition at line 209 of file rom.h.
Referenced by LoadZelda3(), and title().
|
private |
Definition at line 212 of file rom.h.
Referenced by filename(), LoadFromFile(), SaveToFile(), and set_filename().
|
private |
Definition at line 215 of file rom.h.
Referenced by LoadFromFile(), and short_name().
|
private |
Definition at line 218 of file rom.h.
Referenced by begin(), Close(), data(), end(), Expand(), is_loaded(), LoadFromData(), LoadFromFile(), LoadGfxGroups(), LoadZelda3(), mutable_data(), operator[](), ReadByte(), ReadByteVector(), ReadLong(), ReadWord(), SaveGfxGroups(), SaveToFile(), vector(), WriteByte(), WriteLong(), WriteShort(), WriteVector(), and WriteWord().
|
private |
Definition at line 221 of file rom.h.
Referenced by graphics_buffer(), and mutable_graphics_buffer().
|
private |
Definition at line 224 of file rom.h.
Referenced by LoadFromFile(), and resource_label().
|
private |
Definition at line 227 of file rom.h.
Referenced by Close(), dungeon_palette(), LoadZelda3(), mutable_dungeon_palette(), mutable_palette_group(), palette_group(), and SaveAllPalettes().
|
private |
Definition at line 230 of file rom.h.
Referenced by LoadZelda3(), and version_constants().