yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::Rom Class Reference

The Rom class is used to load, save, and modify Rom data. More...

#include <rom.h>

Inheritance diagram for yaze::Rom:
Collaboration diagram for yaze::Rom:

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::Tile16ReadTile16 (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)
 
ResourceLabelManagerresource_label ()
 
zelda3_version_pointers version_constants () const
 

Public Attributes

std::array< std::array< uint8_t, 8 >, kNumMainBlocksetsmain_blockset_ids
 
std::array< std::array< uint8_t, 4 >, kNumRoomBlocksetsroom_blockset_ids
 
std::array< std::array< uint8_t, 4 >, kNumSpritesetsspriteset_ids
 
std::array< std::array< uint8_t, 4 >, kNumPalettesetspaletteset_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
 

Detailed Description

The Rom class is used to load, save, and modify Rom data.

Definition at line 59 of file rom.h.

Member Function Documentation

◆ LoadFromFile()

absl::Status yaze::Rom::LoadFromFile ( const std::string & filename,
bool z3_load = true )

Load Rom data from a file.

Parameters
filenameThe name of the file to load.
z3_loadWhether 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().

Here is the call graph for this function:

◆ LoadFromData()

◆ SaveToFile()

absl::Status yaze::Rom::SaveToFile ( bool backup,
bool save_new = false,
std::string filename = "" )

Saves the Rom data to a file.

Parameters
backupIf true, creates a backup file with timestamp in its name
filenameThe name of the file to save the Rom data to
Returns
absl::Status Returns an OK status if the save was successful, otherwise returns an error status

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().

Here is the call graph for this function:

◆ SavePalette()

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.

Parameters
indexThe index of the palette to save.
group_nameThe name of the group containing the palette.
paletteThe 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().

◆ SaveAllPalettes()

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().

◆ Expand()

void yaze::Rom::Expand ( int size)
inline

Definition at line 102 of file rom.h.

References rom_data_, size(), and size_.

Here is the call graph for this function:

◆ Close()

void yaze::Rom::Close ( )
inline

Definition at line 107 of file rom.h.

References is_loaded_, rom_data_, and size_.

◆ ReadByte()

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().

◆ ReadWord()

absl::StatusOr< uint16_t > yaze::Rom::ReadWord ( int offset)

◆ ReadLong()

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().

◆ ReadByteVector()

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().

◆ ReadTile16()

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().

Here is the call graph for this function:

◆ WriteTile16()

absl::Status yaze::Rom::WriteTile16 ( int tile16_id,
const gfx::Tile16 & tile )

◆ WriteByte()

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().

Here is the call graph for this function:

◆ WriteWord()

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_.

Here is the call graph for this function:

◆ WriteShort()

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().

Here is the call graph for this function:

◆ WriteLong()

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_.

Here is the call graph for this function:

◆ WriteVector()

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().

Here is the call graph for this function:

◆ WriteColor()

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().

Here is the call graph for this function:

◆ WriteTransaction()

template<typename... Args>
absl::Status yaze::Rom::WriteTransaction ( Args... args)
inline

Definition at line 129 of file rom.h.

References WriteHelper().

Referenced by yaze::test::TEST_F(), and yaze::test::TEST_F().

Here is the call graph for this function:

◆ ReadTransaction()

template<typename T, typename... Args>
absl::Status yaze::Rom::ReadTransaction ( T & var,
int address,
Args &&... args )
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().

Here is the call graph for this function:

◆ operator[]()

uint8_t & yaze::Rom::operator[] ( unsigned long i)
inline

Definition at line 148 of file rom.h.

References rom_data_, and size_.

◆ is_loaded()

bool yaze::Rom::is_loaded ( ) const
inline

Definition at line 153 of file rom.h.

References filename_, and is_loaded_.

Referenced by main().

◆ title()

auto yaze::Rom::title ( ) const
inline

Definition at line 161 of file rom.h.

References title_.

◆ size()

◆ data()

◆ mutable_data()

◆ begin()

auto yaze::Rom::begin ( )
inline

◆ end()

auto yaze::Rom::end ( )
inline

Definition at line 166 of file rom.h.

References rom_data_.

◆ vector()

auto yaze::Rom::vector ( ) const
inline

Definition at line 168 of file rom.h.

References rom_data_.

Referenced by yaze::test::anonymous_namespace{compression_test.cc}::ExpectCompressOk(), and main().

◆ version()

auto yaze::Rom::version ( ) const
inline

Definition at line 169 of file rom.h.

References version_.

◆ filename()

auto yaze::Rom::filename ( ) const
inline

Definition at line 170 of file rom.h.

References filename_.

Referenced by LoadFromFile(), SaveToFile(), and yaze::editor::MemoryEditorWithDiffChecker::Update().

◆ set_filename()

auto yaze::Rom::set_filename ( std::string name)
inline

Definition at line 171 of file rom.h.

References filename_.

◆ graphics_buffer()

std::vector< uint8_t > yaze::Rom::graphics_buffer ( ) const
inline

Definition at line 173 of file rom.h.

References graphics_buffer_.

◆ mutable_graphics_buffer()

auto yaze::Rom::mutable_graphics_buffer ( )
inline

Definition at line 174 of file rom.h.

References graphics_buffer_.

Referenced by yaze::LoadAllGraphicsData().

◆ palette_group()

auto yaze::Rom::palette_group ( ) const
inline

◆ mutable_palette_group()

auto yaze::Rom::mutable_palette_group ( )
inline

Definition at line 176 of file rom.h.

References palette_groups_.

◆ dungeon_palette()

auto yaze::Rom::dungeon_palette ( int i)
inline

Definition at line 177 of file rom.h.

References palette_groups_.

◆ mutable_dungeon_palette()

auto yaze::Rom::mutable_dungeon_palette ( int i)
inline

Definition at line 178 of file rom.h.

References palette_groups_.

Referenced by yaze::zelda3::LoadDungeonMapGfxFromBinary().

◆ resource_label()

ResourceLabelManager * yaze::Rom::resource_label ( )
inline

Definition at line 182 of file rom.h.

References resource_label_manager_.

◆ version_constants()

zelda3_version_pointers yaze::Rom::version_constants ( ) const
inline

◆ WriteHelper()

virtual absl::Status yaze::Rom::WriteHelper ( const WriteAction & action)
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().

Here is the call graph for this function:

◆ ReadHelper()

template<typename T>
absl::Status yaze::Rom::ReadHelper ( T & var,
int address )
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().

Here is the call graph for this function:

◆ LoadZelda3()

absl::Status yaze::Rom::LoadZelda3 ( )
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().

Here is the call graph for this function:

◆ LoadGfxGroups()

◆ SaveGroupsToRom()

Member Data Documentation

◆ main_blockset_ids

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().

◆ room_blockset_ids

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().

◆ spriteset_ids

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().

◆ paletteset_ids

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().

◆ is_loaded_

bool yaze::Rom::is_loaded_ = false
private

Definition at line 241 of file rom.h.

Referenced by Close(), is_loaded(), LoadFromData(), and LoadFromFile().

◆ size_

unsigned long yaze::Rom::size_ = 0
private

Definition at line 244 of file rom.h.

Referenced by Close(), Expand(), LoadFromData(), LoadFromFile(), LoadZelda3(), operator[](), and size().

◆ title_

std::string yaze::Rom::title_ = "ROM not loaded"
private

Definition at line 247 of file rom.h.

Referenced by LoadZelda3(), and title().

◆ filename_

std::string yaze::Rom::filename_ = ""
private

Definition at line 250 of file rom.h.

Referenced by filename(), is_loaded(), LoadFromFile(), SaveToFile(), and set_filename().

◆ rom_data_

◆ graphics_buffer_

std::vector<uint8_t> yaze::Rom::graphics_buffer_
private

Definition at line 256 of file rom.h.

Referenced by graphics_buffer(), and mutable_graphics_buffer().

◆ resource_label_manager_

ResourceLabelManager yaze::Rom::resource_label_manager_
private

Definition at line 259 of file rom.h.

Referenced by LoadFromFile(), and resource_label().

◆ palette_groups_

◆ version_

zelda3_version yaze::Rom::version_ = zelda3_version::US
private

Definition at line 265 of file rom.h.

Referenced by LoadZelda3(), version(), and version_constants().


The documentation for this class was generated from the following files: