yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::zelda3::music::SpcParser Class Reference

Parser for N-SPC music data from ROM. More...

#include <spc_parser.h>

Classes

struct  ParseContext
 Context for parsing operations. More...
 

Static Public Member Functions

static absl::StatusOr< MusicSongParseSong (Rom &rom, uint16_t address, uint8_t bank)
 Parse a complete song from ROM.
 
static absl::StatusOr< std::vector< uint16_t > > ReadSongPointerTable (Rom &rom, uint16_t table_address, uint8_t bank, int max_entries=40)
 Read the song pointer table for a given SPC bank.
 
static absl::StatusOr< MusicTrackParseTrack (Rom &rom, uint16_t address, uint8_t bank, int max_ticks=50000)
 Parse a single track from ROM.
 
static uint32_t SpcAddressToRomOffset (Rom &rom, uint16_t spc_address, uint8_t bank)
 Convert an SPC address to a ROM offset.
 
static const uint8_t * GetSpcData (Rom &rom, uint16_t spc_address, uint8_t bank, int *out_length=nullptr)
 Get a pointer to ROM data at an SPC address.
 
static int GetCommandParamCount (uint8_t opcode)
 Get the parameter count for an N-SPC command.
 
static bool IsNotePitch (uint8_t byte)
 Check if a byte is a note pitch.
 
static bool IsDuration (uint8_t byte)
 Check if a byte is a duration value (< 128).
 
static bool IsCommand (uint8_t byte)
 Check if a byte is a command opcode.
 

Static Private Member Functions

static absl::StatusOr< MusicTrackParseTrackInternal (ParseContext &ctx, uint16_t address, int max_ticks)
 
static absl::StatusOr< int > ParseSubroutine (ParseContext &ctx, uint16_t address, int repeat_count, int remaining_ticks)
 

Detailed Description

Parser for N-SPC music data from ROM.

This class provides a clean interface for parsing the game's music format, which consists of:

  • Song tables with pointers to segment data
  • Segments with 8 track pointers
  • Tracks with note/command sequences

The implementation is a modernized version of Hyrule Magic's tracker logic.

Definition at line 43 of file spc_parser.h.

Member Function Documentation

◆ ParseSong()

absl::StatusOr< MusicSong > yaze::zelda3::music::SpcParser::ParseSong ( Rom & rom,
uint16_t address,
uint8_t bank )
static

Parse a complete song from ROM.

Parameters
romThe ROM to parse from.
addressThe song table address (SPC address space).
bankThe sound bank (0-3).
Returns
The parsed song, or error status.

Definition at line 16 of file spc_parser.cc.

References yaze::zelda3::music::MusicSong::bank, GetSpcData(), yaze::Rom::is_loaded(), yaze::zelda3::music::MusicSong::loop_point, ParseTrack(), yaze::zelda3::music::MusicSegment::rom_address, yaze::zelda3::music::MusicSong::rom_address, yaze::zelda3::music::MusicSong::segments, and yaze::zelda3::music::MusicSegment::tracks.

Referenced by yaze::zelda3::music::MusicBank::LoadExpandedSongTable(), and yaze::zelda3::music::MusicBank::LoadSongTable().

Here is the call graph for this function:

◆ ReadSongPointerTable()

absl::StatusOr< std::vector< uint16_t > > yaze::zelda3::music::SpcParser::ReadSongPointerTable ( Rom & rom,
uint16_t table_address,
uint8_t bank,
int max_entries = 40 )
static

Read the song pointer table for a given SPC bank.

Parameters
romThe ROM to read from.
table_addressAddress of the pointer table (typically $D000).
bankThe SPC bank identifier.
max_entriesMaximum number of entries to read (default 40).
Returns
Vector of song pointer addresses (including null entries).

Definition at line 106 of file spc_parser.cc.

References GetSpcData(), and yaze::Rom::is_loaded().

Referenced by yaze::zelda3::music::MusicBank::LoadExpandedSongTable(), and yaze::zelda3::music::MusicBank::LoadSongTable().

Here is the call graph for this function:

◆ ParseTrack()

absl::StatusOr< MusicTrack > yaze::zelda3::music::SpcParser::ParseTrack ( Rom & rom,
uint16_t address,
uint8_t bank,
int max_ticks = 50000 )
static

Parse a single track from ROM.

Parameters
romThe ROM to parse from.
addressThe track start address (SPC address space).
bankThe sound bank (0-3).
max_ticksMaximum ticks to parse (prevents infinite loops).
Returns
The parsed track, or error status.

Definition at line 144 of file spc_parser.cc.

References yaze::zelda3::music::SpcParser::ParseContext::bank_offset, yaze::zelda3::music::SpcParser::ParseContext::current_bank, yaze::zelda3::music::SpcParser::ParseContext::current_depth, yaze::zelda3::music::kSoundBankOffsets, yaze::zelda3::music::SpcParser::ParseContext::max_parse_depth, ParseTrackInternal(), and yaze::zelda3::music::SpcParser::ParseContext::rom.

Referenced by ParseSong().

Here is the call graph for this function:

◆ SpcAddressToRomOffset()

uint32_t yaze::zelda3::music::SpcParser::SpcAddressToRomOffset ( Rom & rom,
uint16_t spc_address,
uint8_t bank )
static

Convert an SPC address to a ROM offset.

Parameters
romThe ROM (for reading bank pointers).
spc_addressThe address in SPC RAM space.
bankThe sound bank.
Returns
The ROM file offset, or 0 if not found.

Definition at line 310 of file spc_parser.cc.

References yaze::Rom::data(), yaze::Rom::size(), and SpcAddressToRomOffset().

Referenced by GetSpcData(), yaze::zelda3::music::MusicBank::LoadInstruments(), yaze::zelda3::music::MusicBank::LoadSamples(), and SpcAddressToRomOffset().

Here is the call graph for this function:

◆ GetSpcData()

const uint8_t * yaze::zelda3::music::SpcParser::GetSpcData ( Rom & rom,
uint16_t spc_address,
uint8_t bank,
int * out_length = nullptr )
static

Get a pointer to ROM data at an SPC address.

Parameters
romThe ROM.
spc_addressThe address in SPC RAM space.
bankThe sound bank.
out_lengthReceives the length of the data block.
Returns
Pointer to ROM data, or nullptr if not found.

Definition at line 396 of file spc_parser.cc.

References yaze::Rom::data(), yaze::Rom::size(), and SpcAddressToRomOffset().

Referenced by yaze::zelda3::music::MusicBank::LoadSamples(), ParseSong(), ParseTrackInternal(), and ReadSongPointerTable().

Here is the call graph for this function:

◆ GetCommandParamCount()

static int yaze::zelda3::music::SpcParser::GetCommandParamCount ( uint8_t opcode)
inlinestatic

Get the parameter count for an N-SPC command.

Parameters
opcodeThe command opcode (0xE0-0xFF).
Returns
Number of parameter bytes, or 0 for notes.

Definition at line 130 of file spc_parser.h.

References yaze::zelda3::music::kCommandParamCount.

Referenced by ParseTrackInternal().

◆ IsNotePitch()

static bool yaze::zelda3::music::SpcParser::IsNotePitch ( uint8_t byte)
inlinestatic

Check if a byte is a note pitch.

Definition at line 138 of file spc_parser.h.

References yaze::zelda3::music::kNoteMinPitch, and yaze::zelda3::music::kNoteRest.

Referenced by ParseTrackInternal().

◆ IsDuration()

static bool yaze::zelda3::music::SpcParser::IsDuration ( uint8_t byte)
inlinestatic

Check if a byte is a duration value (< 128).

Definition at line 145 of file spc_parser.h.

Referenced by ParseTrackInternal().

◆ IsCommand()

static bool yaze::zelda3::music::SpcParser::IsCommand ( uint8_t byte)
inlinestatic

Check if a byte is a command opcode.

Definition at line 152 of file spc_parser.h.

Referenced by ParseTrackInternal().

◆ ParseTrackInternal()

◆ ParseSubroutine()

absl::StatusOr< int > yaze::zelda3::music::SpcParser::ParseSubroutine ( ParseContext & ctx,
uint16_t address,
int repeat_count,
int remaining_ticks )
staticprivate

Definition at line 293 of file spc_parser.cc.

References ParseTrackInternal().

Referenced by ParseTrackInternal().

Here is the call graph for this function:

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