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< MusicSong > | ParseSong (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< MusicTrack > | ParseTrack (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< MusicTrack > | ParseTrackInternal (ParseContext &ctx, uint16_t address, int max_ticks) |
| static absl::StatusOr< int > | ParseSubroutine (ParseContext &ctx, uint16_t address, int repeat_count, int remaining_ticks) |
Parser for N-SPC music data from ROM.
This class provides a clean interface for parsing the game's music format, which consists of:
The implementation is a modernized version of Hyrule Magic's tracker logic.
Definition at line 43 of file spc_parser.h.
|
static |
Parse a complete song from ROM.
| rom | The ROM to parse from. |
| address | The song table address (SPC address space). |
| bank | The sound bank (0-3). |
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().

|
static |
Read the song pointer table for a given SPC bank.
| rom | The ROM to read from. |
| table_address | Address of the pointer table (typically $D000). |
| bank | The SPC bank identifier. |
| max_entries | Maximum number of entries to read (default 40). |
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().

|
static |
Parse a single track from ROM.
| rom | The ROM to parse from. |
| address | The track start address (SPC address space). |
| bank | The sound bank (0-3). |
| max_ticks | Maximum ticks to parse (prevents infinite loops). |
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().

|
static |
Convert an SPC address to a ROM offset.
| rom | The ROM (for reading bank pointers). |
| spc_address | The address in SPC RAM space. |
| bank | The sound bank. |
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().

|
static |
Get a pointer to ROM data at an SPC address.
| rom | The ROM. |
| spc_address | The address in SPC RAM space. |
| bank | The sound bank. |
| out_length | Receives the length of the data block. |
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().

|
inlinestatic |
Get the parameter count for an N-SPC command.
| opcode | The command opcode (0xE0-0xFF). |
Definition at line 130 of file spc_parser.h.
References yaze::zelda3::music::kCommandParamCount.
Referenced by ParseTrackInternal().
|
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().
|
inlinestatic |
Check if a byte is a duration value (< 128).
Definition at line 145 of file spc_parser.h.
Referenced by ParseTrackInternal().
|
inlinestatic |
Check if a byte is a command opcode.
Definition at line 152 of file spc_parser.h.
Referenced by ParseTrackInternal().
|
staticprivate |
Definition at line 156 of file spc_parser.cc.
References yaze::zelda3::music::MusicTrack::CalculateDuration(), yaze::zelda3::music::TrackEvent::Command, yaze::zelda3::music::SpcParser::ParseContext::current_bank, yaze::zelda3::music::SpcParser::ParseContext::current_depth, yaze::zelda3::music::MusicTrack::events, GetCommandParamCount(), GetSpcData(), yaze::zelda3::music::MusicTrack::is_empty, yaze::Rom::is_loaded(), IsCommand(), IsDuration(), IsNotePitch(), yaze::zelda3::music::kNoteTie, yaze::zelda3::music::kTrackEnd, yaze::zelda3::music::TrackEvent::MakeEnd(), yaze::zelda3::music::SpcParser::ParseContext::max_parse_depth, yaze::zelda3::music::TrackEvent::Note, ParseSubroutine(), yaze::zelda3::music::SpcParser::ParseContext::rom, yaze::zelda3::music::MusicTrack::rom_address, yaze::zelda3::music::TrackEvent::type, and yaze::zelda3::music::SpcParser::ParseContext::visited_addresses.
Referenced by ParseSubroutine(), and ParseTrack().
|
staticprivate |
Definition at line 293 of file spc_parser.cc.
References ParseTrackInternal().
Referenced by ParseTrackInternal().
