yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::ZsprLoader Class Reference

Loader for ZSPR (ALttP Randomizer) sprite files. More...

#include <zspr_loader.h>

Static Public Member Functions

static absl::StatusOr< ZsprDataLoadFromFile (const std::string &path)
 Load ZSPR data from a file path.
 
static absl::StatusOr< ZsprDataLoadFromData (const std::vector< uint8_t > &data)
 Load ZSPR data from a byte buffer.
 
static absl::Status ApplyToRom (Rom &rom, const ZsprData &zspr)
 Apply loaded ZSPR sprite data to ROM's Link graphics.
 
static absl::Status ApplyPaletteToRom (Rom &rom, const ZsprData &zspr)
 Apply ZSPR palette data to ROM.
 

Static Public Attributes

static constexpr uint32_t kZsprMagic = 0x5250535A
 
static constexpr size_t kExpectedSpriteDataSize = 28672
 
static constexpr size_t kExpectedPaletteDataSize = 120
 
static constexpr size_t kTilesPerSheet = 64
 
static constexpr size_t kBytesPerTile = 32
 
static constexpr size_t kLinkSheetCount = 14
 

Static Private Member Functions

static bool ValidateChecksum (const std::vector< uint8_t > &data, uint32_t expected_checksum)
 Validate ZSPR checksum (Adler-32)
 
static uint32_t CalculateAdler32 (const uint8_t *data, size_t length)
 Calculate Adler-32 checksum.
 
static std::string ReadNullTerminatedString (const uint8_t *data, size_t max_length, size_t &bytes_read)
 Read null-terminated string from buffer.
 
static uint16_t ReadU16LE (const uint8_t *data)
 Read 16-bit little-endian value.
 
static uint32_t ReadU32LE (const uint8_t *data)
 Read 32-bit little-endian value.
 

Detailed Description

Loader for ZSPR (ALttP Randomizer) sprite files.

ZSPR Format (v1):

Offset Size Description
------ ---- -----------
0x00 4 Magic: "ZSPR"
0x04 1 Version (currently 1)
0x05 4 Checksum (Adler-32)
0x09 2 Sprite data offset (little-endian)
0x0B 2 Sprite data size (little-endian)
0x0D 2 Palette data offset (little-endian)
0x0F 2 Palette data size (little-endian)
0x11 2 Sprite type (0 = Link, 1 = Other)
0x13 var Display name (null-terminated UTF-8)
... var Author name (null-terminated UTF-8)
... var Author ROM name (null-terminated)
... 28672 Sprite data (896 tiles × 32 bytes/tile, 4BPP)
... 120 Palette data (15 colors × 4 palettes × 2 bytes)
... 4 Glove colors (2 colors × 2 bytes)

Definition at line 72 of file zspr_loader.h.

Member Function Documentation

◆ LoadFromFile()

absl::StatusOr< ZsprData > yaze::gfx::ZsprLoader::LoadFromFile ( const std::string & path)
static

Load ZSPR data from a file path.

Parameters
pathPath to the .zspr file
Returns
ZsprData on success, or error status

Definition at line 14 of file zspr_loader.cc.

References LoadFromData().

Referenced by yaze::editor::LinkSpritePanel::ImportZspr().

Here is the call graph for this function:

◆ LoadFromData()

◆ ApplyToRom()

absl::Status yaze::gfx::ZsprLoader::ApplyToRom ( Rom & rom,
const ZsprData & zspr )
static

Apply loaded ZSPR sprite data to ROM's Link graphics.

Writes the sprite data to the ROM at Link's graphics sheet locations. The ZSPR 4BPP data is converted to the ROM's expected format.

Parameters
romROM to modify
zsprZSPR data to apply
Returns
Status indicating success or failure

Definition at line 147 of file zspr_loader.cc.

References yaze::gfx::ZsprMetadata::display_name, yaze::gfx::ZsprData::is_link_sprite(), yaze::Rom::is_loaded(), kExpectedSpriteDataSize, kLinkSheetCount, LOG_INFO, LOG_WARN, yaze::gfx::ZsprData::metadata, yaze::gfx::ZsprData::sprite_data, and yaze::Rom::WriteByte().

Referenced by yaze::editor::LinkSpritePanel::ImportZspr().

Here is the call graph for this function:

◆ ApplyPaletteToRom()

absl::Status yaze::gfx::ZsprLoader::ApplyPaletteToRom ( Rom & rom,
const ZsprData & zspr )
static

Apply ZSPR palette data to ROM.

Writes the sprite palette data to the appropriate ROM locations.

Parameters
romROM to modify
zsprZSPR data containing palette
Returns
Status indicating success or failure
Todo
Find exact glove color offsets for US ROM

Definition at line 206 of file zspr_loader.cc.

References yaze::Rom::is_loaded(), kExpectedPaletteDataSize, yaze::gfx::kNumPalettes, LOG_INFO, yaze::gfx::ZsprData::palette_data, and yaze::Rom::WriteByte().

Referenced by yaze::editor::LinkSpritePanel::ImportZspr().

Here is the call graph for this function:

◆ ValidateChecksum()

bool yaze::gfx::ZsprLoader::ValidateChecksum ( const std::vector< uint8_t > & data,
uint32_t expected_checksum )
staticprivate

Validate ZSPR checksum (Adler-32)

Definition at line 257 of file zspr_loader.cc.

References CalculateAdler32().

Referenced by LoadFromData().

Here is the call graph for this function:

◆ CalculateAdler32()

uint32_t yaze::gfx::ZsprLoader::CalculateAdler32 ( const uint8_t * data,
size_t length )
staticprivate

Calculate Adler-32 checksum.

Definition at line 263 of file zspr_loader.cc.

Referenced by ValidateChecksum().

◆ ReadNullTerminatedString()

std::string yaze::gfx::ZsprLoader::ReadNullTerminatedString ( const uint8_t * data,
size_t max_length,
size_t & bytes_read )
staticprivate

Read null-terminated string from buffer.

Definition at line 275 of file zspr_loader.cc.

Referenced by LoadFromData().

◆ ReadU16LE()

uint16_t yaze::gfx::ZsprLoader::ReadU16LE ( const uint8_t * data)
staticprivate

Read 16-bit little-endian value.

Definition at line 292 of file zspr_loader.cc.

Referenced by LoadFromData().

◆ ReadU32LE()

uint32_t yaze::gfx::ZsprLoader::ReadU32LE ( const uint8_t * data)
staticprivate

Read 32-bit little-endian value.

Definition at line 297 of file zspr_loader.cc.

Referenced by LoadFromData().

Member Data Documentation

◆ kZsprMagic

constexpr uint32_t yaze::gfx::ZsprLoader::kZsprMagic = 0x5250535A
staticconstexpr

Definition at line 74 of file zspr_loader.h.

◆ kExpectedSpriteDataSize

constexpr size_t yaze::gfx::ZsprLoader::kExpectedSpriteDataSize = 28672
staticconstexpr

Definition at line 75 of file zspr_loader.h.

Referenced by ApplyToRom(), and LoadFromData().

◆ kExpectedPaletteDataSize

constexpr size_t yaze::gfx::ZsprLoader::kExpectedPaletteDataSize = 120
staticconstexpr

Definition at line 76 of file zspr_loader.h.

Referenced by ApplyPaletteToRom().

◆ kTilesPerSheet

constexpr size_t yaze::gfx::ZsprLoader::kTilesPerSheet = 64
staticconstexpr

Definition at line 77 of file zspr_loader.h.

◆ kBytesPerTile

constexpr size_t yaze::gfx::ZsprLoader::kBytesPerTile = 32
staticconstexpr

Definition at line 78 of file zspr_loader.h.

◆ kLinkSheetCount

constexpr size_t yaze::gfx::ZsprLoader::kLinkSheetCount = 14
staticconstexpr

Definition at line 79 of file zspr_loader.h.

Referenced by ApplyToRom().


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