The Rom class is used to load, save, and modify Rom data. More...
#include <rom.h>
Classes | |
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 | SaveToFile (bool backup, bool save_new=false, std::string filename="") |
Saves the Rom data to a file. | |
absl::Status | SavePalette (int index, const std::string &group_name, gfx::SnesPalette &palette) |
absl::Status | SaveAllPalettes () |
Saves all palettes in the Rom. | |
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) |
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 | version () const |
auto | filename () const |
auto | set_filename (std::string name) |
std::vector< uint8_t > | 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 Member Functions | |
virtual absl::Status | WriteHelper (const WriteAction &action) |
template<typename T> | |
absl::Status | ReadHelper (T &var, int address) |
absl::Status | LoadZelda3 () |
absl::Status | LoadGfxGroups () |
absl::Status | SaveGroupsToRom () |
Private Attributes | |
bool | is_loaded_ = false |
unsigned long | size_ = 0 |
std::string | title_ = "ROM not loaded" |
std::string | filename_ = "" |
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 ) |
Load Rom data from a file.
filename | The name of the file to load. |
z3_load | Whether to load data specific to Zelda 3. |
Definition at line 172 of file rom.cc.
References filename(), filename_, is_loaded_, LoadZelda3(), resource_label_manager_, RETURN_IF_ERROR, rom_data_, and size_.
Referenced by yaze::cli::Tile16Transfer::handle(), main(), 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 217 of file rom.cc.
References data(), is_loaded_, LoadZelda3(), palette_groups_, 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::SaveToFile | ( | bool | backup, |
bool | save_new = false, | ||
std::string | filename = "" ) |
Saves the Rom data to a file.
backup | If true, creates a backup file with timestamp in its name |
filename | The name of the file to save the Rom data to |
Definition at line 407 of file rom.cc.
References filename(), filename_, yaze::core::FeatureFlags::get(), RETURN_IF_ERROR, rom_data_, SaveAllPalettes(), and SaveGroupsToRom().
Referenced by yaze::cli::Tile16Transfer::handle(), and yaze_save_rom().
absl::Status yaze::Rom::SavePalette | ( | int | index, |
const std::string & | group_name, | ||
gfx::SnesPalette & | palette ) |
Saves the given palette to the Rom if any of its colors have been modified.
index | The index of the palette to save. |
group_name | The name of the group containing the palette. |
palette | The palette to save. |
Definition at line 503 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 | ( | ) |
Saves all palettes in the Rom.
This function iterates through all palette groups and all palettes in each group, and saves each palette using the SavePalette() function.
Definition at line 517 of file rom.cc.
References palette_groups_, and RETURN_IF_ERROR.
Referenced by SaveToFile().
|
inline |
|
inline |
Definition at line 107 of file rom.h.
References is_loaded_, rom_data_, and size_.
absl::StatusOr< uint8_t > yaze::Rom::ReadByte | ( | int | offset | ) |
Definition at line 234 of file rom.cc.
References rom_data_.
Referenced by yaze::test::MockRom::MOCK_METHOD(), and ReadHelper().
absl::StatusOr< uint16_t > yaze::Rom::ReadWord | ( | int | offset | ) |
Definition at line 241 of file rom.cc.
References rom_data_.
Referenced by yaze::zelda3::LoadEntranceTileTypes(), LoadGfxGroups(), yaze::test::MockRom::MOCK_METHOD(), ReadHelper(), ReadTile16(), and SaveGroupsToRom().
absl::StatusOr< uint32_t > yaze::Rom::ReadLong | ( | int | offset | ) |
Definition at line 249 of file rom.cc.
References rom_data_.
Referenced by yaze::test::MockRom::MOCK_METHOD().
absl::StatusOr< std::vector< uint8_t > > yaze::Rom::ReadByteVector | ( | uint32_t | offset, |
uint32_t | length ) const |
Definition at line 258 of file rom.cc.
References rom_data_.
Referenced by yaze::LoadLinkGraphics(), and ReadHelper().
absl::StatusOr< gfx::Tile16 > yaze::Rom::ReadTile16 | ( | uint32_t | tile16_id | ) |
Definition at line 270 of file rom.cc.
References ASSIGN_OR_RETURN, yaze::kTile16Ptr, ReadWord(), yaze::gfx::Tile16::tile0_, and yaze::gfx::WordToTileInfo().
Referenced by yaze::cli::Tile16Transfer::handle().
absl::Status yaze::Rom::WriteTile16 | ( | int | tile16_id, |
const gfx::Tile16 & | tile ) |
Definition at line 288 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(), and WriteShort().
Referenced by yaze::cli::Tile16Transfer::handle().
absl::Status yaze::Rom::WriteByte | ( | int | addr, |
uint8_t | value ) |
Definition at line 301 of file rom.cc.
References data(), yaze::util::HexByte(), and rom_data_.
Referenced by yaze::zelda3::RoomEntrance::Save(), and WriteHelper().
absl::Status yaze::Rom::WriteWord | ( | int | addr, |
uint16_t | value ) |
Definition at line 312 of file rom.cc.
References data(), yaze::util::HexWord(), and rom_data_.
absl::Status yaze::Rom::WriteShort | ( | int | addr, |
uint16_t | value ) |
Definition at line 324 of file rom.cc.
References data(), yaze::util::HexWord(), and rom_data_.
Referenced by yaze::zelda3::RoomEntrance::Save(), WriteColor(), WriteHelper(), and WriteTile16().
absl::Status yaze::Rom::WriteLong | ( | uint32_t | addr, |
uint32_t | value ) |
Definition at line 336 of file rom.cc.
References data(), yaze::util::HexLong(), and rom_data_.
absl::Status yaze::Rom::WriteVector | ( | int | addr, |
std::vector< uint8_t > | data ) |
Definition at line 349 of file rom.cc.
References data(), yaze::util::HexByte(), and rom_data_.
Referenced by WriteHelper().
absl::Status yaze::Rom::WriteColor | ( | uint32_t | address, |
const gfx::SnesColor & | color ) |
Definition at line 362 of file rom.cc.
References data(), yaze::util::HexWord(), yaze::gfx::SnesColor::snes(), and WriteShort().
Referenced by SavePalette(), and WriteHelper().
|
inline |
Definition at line 129 of file rom.h.
References WriteHelper().
Referenced by yaze::test::TEST_F(), and yaze::test::TEST_F().
|
inline |
Definition at line 137 of file rom.h.
References ReadHelper(), and ReadTransaction().
Referenced by ReadTransaction(), yaze::test::TEST_F(), and yaze::test::TEST_F().
|
inline |
|
inline |
|
inline |
Definition at line 162 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 163 of file rom.h.
References rom_data_.
Referenced by yaze::editor::BuildDictionaryEntries(), yaze::test::anonymous_namespace{compression_test.cc}::ExpectDecompressBytesOk(), yaze::test::anonymous_namespace{compression_test.cc}::ExpectDecompressOk(), yaze::Load2BppGraphics(), yaze::LoadAllGraphicsData(), LoadFromData(), yaze::SaveAllGraphicsData(), yaze::gfx::lc_lz2::ValidateCompressionResult(), yaze::gfx::lc_lz2::ValidateCompressionResultV3(), WriteByte(), WriteColor(), WriteLong(), WriteShort(), WriteVector(), WriteWord(), and yaze_load_rom().
|
inline |
Definition at line 164 of file rom.h.
References rom_data_.
Referenced by 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 165 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 168 of file rom.h.
References rom_data_.
Referenced by yaze::test::anonymous_namespace{compression_test.cc}::ExpectCompressOk(), and main().
|
inline |
Definition at line 170 of file rom.h.
References filename_.
Referenced by LoadFromFile(), SaveToFile(), and yaze::editor::MemoryEditorWithDiffChecker::Update().
|
inline |
|
inline |
Definition at line 173 of file rom.h.
References graphics_buffer_.
|
inline |
Definition at line 174 of file rom.h.
References graphics_buffer_.
Referenced by yaze::LoadAllGraphicsData().
|
inline |
Definition at line 175 of file rom.h.
References palette_groups_.
Referenced by yaze::LoadAllGraphicsData(), yaze::LoadLinkGraphics(), yaze::zelda3::palette_internal::SetColorsPalette(), and yaze_get_color_from_paletteset().
|
inline |
Definition at line 176 of file rom.h.
References palette_groups_.
|
inline |
Definition at line 177 of file rom.h.
References palette_groups_.
|
inline |
Definition at line 178 of file rom.h.
References palette_groups_.
Referenced by yaze::zelda3::LoadDungeonMapGfxFromBinary().
|
inline |
Definition at line 182 of file rom.h.
References resource_label_manager_.
|
inline |
Definition at line 183 of file rom.h.
References version_.
Referenced by yaze::Load2BppGraphics(), yaze::LoadAllGraphicsData(), LoadGfxGroups(), yaze::SaveAllGraphicsData(), and SaveGroupsToRom().
|
inlineprivatevirtual |
Definition at line 200 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().
|
inlineprivate |
Definition at line 222 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().
|
private |
Definition at line 371 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().
|
private |
Definition at line 530 of file rom.cc.
References ASSIGN_OR_RETURN, yaze::kEntranceGfxGroup, yaze::kGfxGroupsPointer, yaze::kNumMainBlocksets, yaze::kNumPalettesets, yaze::kNumRoomBlocksets, yaze::kNumSpritesets, LoadGfxGroups(), main_blockset_ids, paletteset_ids, ReadWord(), rom_data_, room_blockset_ids, yaze::SnesToPc(), spriteset_ids, and version_constants().
Referenced by LoadGfxGroups(), and LoadZelda3().
|
private |
Definition at line 563 of file rom.cc.
References ASSIGN_OR_RETURN, yaze::kEntranceGfxGroup, yaze::kGfxGroupsPointer, yaze::kNumMainBlocksets, yaze::kNumPalettesets, yaze::kNumRoomBlocksets, yaze::kNumSpritesets, main_blockset_ids, paletteset_ids, ReadWord(), rom_data_, room_blockset_ids, SaveGroupsToRom(), yaze::SnesToPc(), spriteset_ids, and version_constants().
Referenced by SaveGroupsToRom(), and SaveToFile().
std::array<std::array<uint8_t, 8>, kNumMainBlocksets> yaze::Rom::main_blockset_ids |
Definition at line 187 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGroupsToRom().
std::array<std::array<uint8_t, 4>, kNumRoomBlocksets> yaze::Rom::room_blockset_ids |
Definition at line 188 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGroupsToRom().
std::array<std::array<uint8_t, 4>, kNumSpritesets> yaze::Rom::spriteset_ids |
Definition at line 189 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGroupsToRom().
std::array<std::array<uint8_t, 4>, kNumPalettesets> yaze::Rom::paletteset_ids |
Definition at line 190 of file rom.h.
Referenced by LoadGfxGroups(), and SaveGroupsToRom().
|
private |
Definition at line 241 of file rom.h.
Referenced by Close(), is_loaded(), LoadFromData(), and LoadFromFile().
|
private |
Definition at line 244 of file rom.h.
Referenced by Close(), Expand(), LoadFromData(), LoadFromFile(), LoadZelda3(), operator[](), and size().
|
private |
Definition at line 247 of file rom.h.
Referenced by LoadZelda3(), and title().
|
private |
Definition at line 250 of file rom.h.
Referenced by filename(), is_loaded(), LoadFromFile(), SaveToFile(), and set_filename().
|
private |
Definition at line 253 of file rom.h.
Referenced by begin(), Close(), data(), end(), Expand(), LoadFromData(), LoadFromFile(), LoadGfxGroups(), LoadZelda3(), mutable_data(), operator[](), ReadByte(), ReadByteVector(), ReadLong(), ReadWord(), SaveGroupsToRom(), SaveToFile(), vector(), WriteByte(), WriteLong(), WriteShort(), WriteVector(), and WriteWord().
|
private |
Definition at line 256 of file rom.h.
Referenced by graphics_buffer(), and mutable_graphics_buffer().
|
private |
Definition at line 259 of file rom.h.
Referenced by LoadFromFile(), and resource_label().
|
private |
Definition at line 262 of file rom.h.
Referenced by dungeon_palette(), LoadFromData(), LoadZelda3(), mutable_dungeon_palette(), mutable_palette_group(), palette_group(), and SaveAllPalettes().
|
private |
Definition at line 265 of file rom.h.
Referenced by LoadZelda3(), version(), and version_constants().