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

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

#include <rom.h>

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

Classes

struct  WriteAction
 

Public Member Functions

absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics ()
 Loads 2bpp graphics from Rom data.
 
absl::Status LoadLinkGraphics ()
 Loads the players 4bpp graphics sheet from Rom data.
 
absl::Status LoadAllGraphicsData (bool defer_render=false)
 This function iterates over all graphics sheets in the Rom and loads them into memory. Depending on the sheet's index, it may be uncompressed or compressed using the LC-LZ2 algorithm. The uncompressed sheets are 3 bits per pixel (BPP), while the compressed sheets are 4 BPP. The loaded graphics data is converted to 8 BPP and stored in a bitmap.
 
absl::Status LoadFromFile (const std::string &filename, bool z3_load=true)
 
absl::Status LoadFromPointer (uchar *data, size_t length, bool z3_load=true)
 
absl::Status LoadFromBytes (const std::vector< uint8_t > &data)
 
absl::Status SaveToFile (bool backup, bool save_new=false, std::string filename="")
 Saves the Rom data to a file.
 
absl::Status SaveAllGraphicsData ()
 
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)
 Expand the Rom data to a specified size.
 
absl::Status Close ()
 Close the Rom file.
 
absl::Status ReadWritePreconditions ()
 Precondition check for reading and writing to the Rom.
 
absl::StatusOr< uint8_t > ReadByte (int offset)
 
absl::StatusOr< uint16_t > ReadWord (int offset)
 
uint16_t toint16 (int offset)
 
absl::StatusOr< uint32_t > ReadLong (int offset)
 
absl::StatusOr< std::vector< uint8_t > > ReadByteVector (uint32_t offset, uint32_t length)
 
absl::StatusOr< gfx::Tile16ReadTile16 (uint32_t tile16_id)
 
absl::Status WriteTile16 (int tile16_id, const gfx::Tile16 &tile)
 
absl::Status Write (int addr, int value)
 
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
 
std::vector< uint8_t > graphics_buffer () const
 
auto title () const
 
auto size () const
 
auto begin ()
 
auto end ()
 
auto data ()
 
auto vector () const
 
auto version () const
 
auto filename () const
 
auto set_filename (std::string name)
 
auto link_graphics ()
 
auto mutable_link_graphics ()
 
auto gfx_sheets ()
 
auto mutable_gfx_sheets ()
 
auto palette_group ()
 
auto mutable_palette_group ()
 
auto dungeon_palette (int i)
 
auto mutable_dungeon_palette (int i)
 
ResourceLabelManagerresource_label ()
 
VersionConstants version_constants () const
 
- Public Member Functions inherited from yaze::app::core::ExperimentFlags
 ExperimentFlags ()=default
 
virtual ~ExperimentFlags ()=default
 
auto flags () const
 
Flagsmutable_flags ()
 
std::string Serialize () 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_
 
std::array< gfx::Bitmap, kNumGfxSheetsgraphics_sheets_
 
std::array< gfx::Bitmap, kNumLinkSheetslink_graphics_
 
ResourceLabelManager resource_label_manager_
 
gfx::PaletteGroupMap palette_groups_
 
Z3_Version version_ = Z3_Version::US
 

Detailed Description

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

Definition at line 136 of file rom.h.

Member Function Documentation

◆ Load2BppGraphics()

absl::StatusOr< std::vector< uint8_t > > yaze::app::Rom::Load2BppGraphics ( )

Loads 2bpp graphics from Rom data.

This function loads 2bpp graphics from Rom data by iterating over a list of sheet IDs, decompressing the sheet data, converting it to 8bpp format, and appending the converted sheet data to a byte vector.

Definition at line 39 of file rom.cc.

References ASSIGN_OR_RETURN, data(), yaze::app::gfx::lc_lz2::DecompressV2(), yaze::app::gfx::SnesTo8bppSheet(), and version_constants().

Here is the call graph for this function:

◆ LoadLinkGraphics()

◆ LoadAllGraphicsData()

absl::Status yaze::app::Rom::LoadAllGraphicsData ( bool defer_render = false)

This function iterates over all graphics sheets in the Rom and loads them into memory. Depending on the sheet's index, it may be uncompressed or compressed using the LC-LZ2 algorithm. The uncompressed sheets are 3 bits per pixel (BPP), while the compressed sheets are 4 BPP. The loaded graphics data is converted to 8 BPP and stored in a bitmap.

The graphics sheets are divided into the following ranges:

Range Compression Type Decompressed Size Number of Chars
0-112 Compressed 3bpp BGR 0x600 chars Decompressed each
113-114 Compressed 2bpp 0x800 chars Decompressed each
115-126 Uncompressed 3bpp sprites 0x600 chars Each
127-217 Compressed 3bpp sprites 0x600 chars Decompressed each
218-222 Compressed 2bpp 0x800 chars Decompressed each

Definition at line 77 of file rom.cc.

References ASSIGN_OR_RETURN, data(), yaze::app::gfx::lc_lz2::DecompressV2(), yaze::app::gfx::PaletteGroupMap::dungeon_main, yaze::app::core::Renderer::GetInstance(), yaze::app::gfx::PaletteGroupMap::global_sprites, graphics_buffer_, graphics_sheets_, yaze::app::kNumGfxSheets, yaze::app::gfx::kTilesheetDepth, yaze::app::gfx::kTilesheetHeight, yaze::app::gfx::kTilesheetWidth, palette_groups_, RETURN_IF_ERROR, rom_data_, yaze::app::gfx::SnesTo8bppSheet(), yaze::app::Uncompressed3BPPSize, and version_constants().

Referenced by yaze::app::editor::Tile16Editor::UpdateTransferTileCanvas().

Here is the call graph for this function:

◆ LoadFromFile()

◆ LoadFromPointer()

absl::Status yaze::app::Rom::LoadFromPointer ( uchar * data,
size_t length,
bool z3_load = true )

◆ LoadFromBytes()

◆ SaveToFile()

absl::Status yaze::app::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 277 of file rom.cc.

References filename(), filename_, yaze::app::core::ExperimentFlags::flags(), RETURN_IF_ERROR, rom_data_, SaveAllGraphicsData(), SaveAllPalettes(), and SaveGroupsToRom().

Referenced by yaze::cli::Backup::handle(), and yaze::cli::Tile16Transfer::handle().

Here is the call graph for this function:

◆ SaveAllGraphicsData()

absl::Status yaze::app::Rom::SaveAllGraphicsData ( )

Definition at line 136 of file rom.cc.

References ASSIGN_OR_RETURN, yaze::app::gfx::lc_lz2::CompressV2(), yaze::app::gfx::ConvertBpp(), data(), graphics_sheets_, yaze::app::kNumGfxSheets, rom_data_, and version_constants().

Referenced by SaveToFile().

Here is the call graph for this function:

◆ SavePalette()

absl::Status yaze::app::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 372 of file rom.cc.

References yaze::app::gfx::GetPaletteAddress(), yaze::app::gfx::SnesColor::is_modified(), RETURN_IF_ERROR, yaze::app::gfx::SnesColor::set_modified(), yaze::app::gfx::SnesPalette::size(), and WriteColor().

Here is the call graph for this function:

◆ SaveAllPalettes()

absl::Status yaze::app::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 386 of file rom.cc.

References yaze::app::gfx::PaletteGroupMap::for_each(), palette_groups_, and RETURN_IF_ERROR.

Referenced by SaveToFile().

Here is the call graph for this function:

◆ Expand()

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

Expand the Rom data to a specified size.

Definition at line 219 of file rom.h.

References rom_data_, size(), and size_.

Referenced by yaze::cli::Expand::handle().

Here is the call graph for this function:

◆ Close()

absl::Status yaze::app::Rom::Close ( )
inline

Close the Rom file.

Definition at line 227 of file rom.h.

References is_loaded_, rom_data_, and size_.

◆ ReadWritePreconditions()

absl::Status yaze::app::Rom::ReadWritePreconditions ( )
inline

Precondition check for reading and writing to the Rom.

Definition at line 237 of file rom.h.

References is_loaded_, rom_data_, and size_.

Referenced by ReadByte(), ReadByteVector(), ReadLong(), ReadWord(), WriteByte(), WriteLong(), WriteShort(), and WriteWord().

◆ ReadByte()

absl::StatusOr< uint8_t > yaze::app::Rom::ReadByte ( int offset)
inline

Definition at line 249 of file rom.h.

References ReadWritePreconditions(), RETURN_IF_ERROR, and rom_data_.

Referenced by yaze::app::zelda3::overworld::Overworld::GetTile16ForTile32(), yaze::cli::ReadFromRom::handle(), and ReadHelper().

Here is the call graph for this function:

◆ ReadWord()

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

◆ toint16()

uint16_t yaze::app::Rom::toint16 ( int offset)
inline

Definition at line 266 of file rom.h.

References rom_data_.

Referenced by yaze::app::zelda3::overworld::OverworldMap::LoadAreaInfo().

◆ ReadLong()

absl::StatusOr< uint32_t > yaze::app::Rom::ReadLong ( int offset)
inline

Definition at line 270 of file rom.h.

References ReadWritePreconditions(), RETURN_IF_ERROR, and rom_data_.

Here is the call graph for this function:

◆ ReadByteVector()

absl::StatusOr< std::vector< uint8_t > > yaze::app::Rom::ReadByteVector ( uint32_t offset,
uint32_t length )
inline

Definition at line 280 of file rom.h.

References ReadWritePreconditions(), RETURN_IF_ERROR, and rom_data_.

Referenced by yaze::cli::ReadFromRom::handle(), LoadLinkGraphics(), and ReadHelper().

Here is the call graph for this function:

◆ ReadTile16()

absl::StatusOr< gfx::Tile16 > yaze::app::Rom::ReadTile16 ( uint32_t tile16_id)
inline

Definition at line 293 of file rom.h.

References ASSIGN_OR_RETURN, yaze::app::kTile16Ptr, ReadWord(), yaze::app::gfx::Tile16::tile0_, and yaze::app::gfx::WordToTileInfo().

Referenced by yaze::cli::Tile16Transfer::handle().

Here is the call graph for this function:

◆ WriteTile16()

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

◆ Write()

absl::Status yaze::app::Rom::Write ( int addr,
int value )
inline

Definition at line 325 of file rom.h.

References rom_data_.

Referenced by yaze::app::zelda3::dungeon::RoomEntrance::Save(), and WriteHelper().

◆ WriteByte()

absl::Status yaze::app::Rom::WriteByte ( int addr,
uint8_t value )
inline

Definition at line 335 of file rom.h.

References data(), yaze::app::core::Logger::log(), ReadWritePreconditions(), RETURN_IF_ERROR, rom_data_, and yaze::app::core::UppercaseHexByte().

Here is the call graph for this function:

◆ WriteWord()

absl::Status yaze::app::Rom::WriteWord ( int addr,
uint16_t value )
inline

Definition at line 349 of file rom.h.

References yaze::app::core::Logger::log(), ReadWritePreconditions(), RETURN_IF_ERROR, rom_data_, and yaze::app::core::UppercaseHexWord().

Here is the call graph for this function:

◆ WriteShort()

absl::Status yaze::app::Rom::WriteShort ( int addr,
uint16_t value )
inline

◆ WriteLong()

absl::Status yaze::app::Rom::WriteLong ( uint32_t addr,
uint32_t value )
inline

Definition at line 377 of file rom.h.

References yaze::app::core::Logger::log(), ReadWritePreconditions(), RETURN_IF_ERROR, rom_data_, and yaze::app::core::UppercaseHexLong().

Here is the call graph for this function:

◆ WriteVector()

absl::Status yaze::app::Rom::WriteVector ( int addr,
std::vector< uint8_t > data )
inline

Definition at line 392 of file rom.h.

References data(), yaze::app::core::Logger::log(), rom_data_, and yaze::app::core::UppercaseHexByte().

Referenced by WriteHelper().

Here is the call graph for this function:

◆ WriteColor()

absl::Status yaze::app::Rom::WriteColor ( uint32_t address,
const gfx::SnesColor & color )
inline

Definition at line 407 of file rom.h.

References yaze::app::core::Logger::log(), yaze::app::gfx::SnesColor::snes(), yaze::app::core::UppercaseHexWord(), and WriteShort().

Referenced by SavePalette(), and WriteHelper().

Here is the call graph for this function:

◆ WriteTransaction()

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

Definition at line 418 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::app::Rom::ReadTransaction ( T & var,
int address,
Args &&... args )
inline

Definition at line 426 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::app::Rom::operator[] ( unsigned long i)
inline

Definition at line 439 of file rom.h.

References rom_data_, and size_.

◆ is_loaded()

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

Definition at line 448 of file rom.h.

References filename_, and is_loaded_.

Referenced by yaze::app::editor::GraphicsEditor::DrawClipboardImport(), and main().

◆ graphics_buffer()

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

Definition at line 457 of file rom.h.

References graphics_buffer_.

Referenced by yaze::app::zelda3::overworld::OverworldMap::BuildTileset().

◆ title()

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

Definition at line 459 of file rom.h.

References title_.

Referenced by yaze::cli::Open::handle().

◆ size()

◆ begin()

auto yaze::app::Rom::begin ( )
inline

◆ end()

auto yaze::app::Rom::end ( )
inline

Definition at line 462 of file rom.h.

References rom_data_.

◆ data()

◆ vector()

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

◆ version()

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

Definition at line 465 of file rom.h.

References version_.

◆ filename()

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

Definition at line 466 of file rom.h.

References filename_.

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

◆ set_filename()

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

Definition at line 467 of file rom.h.

References filename_.

◆ link_graphics()

auto yaze::app::Rom::link_graphics ( )
inline

Definition at line 469 of file rom.h.

References link_graphics_.

◆ mutable_link_graphics()

auto yaze::app::Rom::mutable_link_graphics ( )
inline

Definition at line 470 of file rom.h.

References link_graphics_.

◆ gfx_sheets()

auto yaze::app::Rom::gfx_sheets ( )
inline

Definition at line 471 of file rom.h.

References graphics_sheets_.

◆ mutable_gfx_sheets()

auto yaze::app::Rom::mutable_gfx_sheets ( )
inline

Definition at line 472 of file rom.h.

References graphics_sheets_.

◆ palette_group()

◆ mutable_palette_group()

auto yaze::app::Rom::mutable_palette_group ( )
inline

Definition at line 475 of file rom.h.

References palette_groups_.

◆ dungeon_palette()

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

Definition at line 476 of file rom.h.

References yaze::app::gfx::PaletteGroupMap::dungeon_main, and palette_groups_.

◆ mutable_dungeon_palette()

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

Definition at line 477 of file rom.h.

References yaze::app::gfx::PaletteGroupMap::dungeon_main, yaze::app::gfx::PaletteGroup::mutable_palette(), and palette_groups_.

Here is the call graph for this function:

◆ resource_label()

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

Definition at line 481 of file rom.h.

References resource_label_manager_.

◆ version_constants()

◆ WriteHelper()

virtual absl::Status yaze::app::Rom::WriteHelper ( const WriteAction & action)
inlineprivatevirtual

Definition at line 499 of file rom.h.

References yaze::app::Rom::WriteAction::address, yaze::app::Rom::WriteAction::value, Write(), WriteColor(), WriteShort(), and WriteVector().

Referenced by WriteTransaction().

Here is the call graph for this function:

◆ ReadHelper()

template<typename T >
absl::Status yaze::app::Rom::ReadHelper ( T & var,
int address )
inlineprivate

Definition at line 521 of file rom.h.

References ASSIGN_OR_RETURN, ReadByte(), ReadByteVector(), and ReadWord().

Referenced by ReadTransaction().

Here is the call graph for this function:

◆ LoadZelda3()

absl::Status yaze::app::Rom::LoadZelda3 ( )
private

Definition at line 231 of file rom.cc.

References yaze::app::JP, yaze::app::gfx::LoadAllPalettes(), LoadGfxGroups(), palette_groups_, RETURN_IF_ERROR, rom_data_, size_, title_, yaze::app::US, and version_.

Referenced by LoadFromFile(), and LoadFromPointer().

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::app::Rom::main_blockset_ids

Definition at line 486 of file rom.h.

◆ room_blockset_ids

std::array<std::array<uint8_t, 4>, kNumRoomBlocksets> yaze::app::Rom::room_blockset_ids

Definition at line 487 of file rom.h.

◆ spriteset_ids

std::array<std::array<uint8_t, 4>, kNumSpritesets> yaze::app::Rom::spriteset_ids

Definition at line 488 of file rom.h.

◆ paletteset_ids

std::array<std::array<uint8_t, 4>, kNumPalettesets> yaze::app::Rom::paletteset_ids

Definition at line 489 of file rom.h.

◆ is_loaded_

bool yaze::app::Rom::is_loaded_ = false
private

◆ size_

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

◆ title_

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

Definition at line 546 of file rom.h.

Referenced by LoadZelda3(), and title().

◆ filename_

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

Definition at line 549 of file rom.h.

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

◆ rom_data_

◆ graphics_buffer_

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

Definition at line 555 of file rom.h.

Referenced by graphics_buffer(), and LoadAllGraphicsData().

◆ graphics_sheets_

std::array<gfx::Bitmap, kNumGfxSheets> yaze::app::Rom::graphics_sheets_
private

Definition at line 558 of file rom.h.

Referenced by gfx_sheets(), LoadAllGraphicsData(), mutable_gfx_sheets(), and SaveAllGraphicsData().

◆ link_graphics_

std::array<gfx::Bitmap, kNumLinkSheets> yaze::app::Rom::link_graphics_
private

Definition at line 561 of file rom.h.

Referenced by link_graphics(), LoadLinkGraphics(), and mutable_link_graphics().

◆ resource_label_manager_

ResourceLabelManager yaze::app::Rom::resource_label_manager_
private

Definition at line 564 of file rom.h.

Referenced by LoadFromFile(), and resource_label().

◆ palette_groups_

◆ version_

Z3_Version yaze::app::Rom::version_ = Z3_Version::US
private

Definition at line 570 of file rom.h.

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


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