yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
asm_exporter.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_MUSIC_ASM_EXPORTER_H
2#define YAZE_ZELDA3_MUSIC_ASM_EXPORTER_H
3
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
11
12namespace yaze {
13namespace zelda3 {
14namespace music {
15
20 uint16_t base_aram_address = 0xD800; // Default !ARAMAddr
21 bool use_instrument_macros = true; // %Strings() vs %SetInstrument($09)
22 bool detect_subroutines = true; // Extract repeated patterns
23 int min_pattern_length = 8; // Min bytes for subroutine extraction
24 int min_pattern_repeats = 2; // Min occurrences for extraction
25 bool include_comments = true; // Generate documentation comments
26 std::string label_prefix = "MySong"; // Label naming prefix
27};
28
42 public:
43 AsmExporter() = default;
44 ~AsmExporter() = default;
45
52 absl::StatusOr<std::string> ExportSong(const MusicSong& song,
53 const AsmExportOptions& options);
54
62 absl::Status ExportToFile(const MusicSong& song, const std::string& path,
63 const AsmExportOptions& options);
64
65 private:
66 // Generate song header (label, !ARAMAddr, pointers)
67 std::string GenerateHeader(const MusicSong& song,
68 const AsmExportOptions& options);
69
70 // Generate channel pointer table
71 std::string GenerateChannelPointers(const MusicSong& song,
72 const AsmExportOptions& options);
73
74 // Generate channel data
75 std::string GenerateChannelData(const MusicTrack& track, int channel_index,
76 const AsmExportOptions& options);
77
78 // Convert a single event to ASM
79 std::string ConvertEventToAsm(const TrackEvent& event,
80 const AsmExportOptions& options,
81 uint8_t& current_duration);
82
83 // Convert note to ASM format
84 std::string ConvertNoteToAsm(const Note& note,
85 const AsmExportOptions& options,
86 uint8_t& current_duration);
87
88 // Convert command to ASM macro
89 std::string ConvertCommandToAsm(const MusicCommand& cmd,
90 const AsmExportOptions& options);
91
92 // Duration value to constant name
93 static const char* GetDurationConstant(uint8_t duration);
94
95 // Note pitch to name (C4, G4s, etc.)
96 static std::string GetNoteName(uint8_t pitch);
97
98 // Instrument ID to macro name
99 static const char* GetInstrumentMacro(uint8_t instrument_id);
100
101 // Command opcode to macro name and format
102 static const char* GetCommandMacro(uint8_t opcode);
103 static int GetCommandParamCount(uint8_t opcode);
104};
105
106// =============================================================================
107// Duration Constants (from music_macros.asm)
108// =============================================================================
109
110// Maps duration byte values to constant names
112 uint8_t value;
113 const char* name;
114};
115
117 {0x48, "!4th"}, // Quarter note (72 ticks)
118 {0x6C, "!4thD"}, // Dotted quarter (108 ticks)
119 {0x30, "!4thT"}, // Quarter triplet (48 ticks)
120 {0x24, "!8th"}, // Eighth note (36 ticks)
121 {0x36, "!8thD"}, // Dotted eighth (54 ticks)
122 {0x18, "!8thT"}, // Eighth triplet (24 ticks)
123 {0x12, "!16th"}, // Sixteenth (18 ticks)
124 {0x1B, "!16thD"}, // Dotted sixteenth (27 ticks)
125 {0x09, "!32nd"}, // Thirty-second (9 ticks)
126};
127
128// =============================================================================
129// Instrument Macros (from music_macros.asm)
130// =============================================================================
131
133 uint8_t id;
134 const char* macro;
135};
136
138 {0x02, "%Tympani()"}, {0x04, "%Sawtooth()"}, {0x05, "%Sine()"},
139 {0x09, "%Strings()"}, {0x0B, "%Trombone()"}, {0x0C, "%Cymbal()"},
140 {0x0D, "%Ocarina()"}, {0x0F, "%Harp()"}, {0x10, "%Splash()"},
141 {0x11, "%Trumpet()"}, {0x12, "%Horn()"}, {0x13, "%Snare()"},
142 {0x15, "%Choir()"}, {0x16, "%Flute()"}, {0x18, "%Piano()"},
143};
144
145} // namespace music
146} // namespace zelda3
147} // namespace yaze
148
149#endif // YAZE_ZELDA3_MUSIC_ASM_EXPORTER_H
Exports MusicSong to Oracle of Secrets music_macros.asm format.
std::string ConvertCommandToAsm(const MusicCommand &cmd, const AsmExportOptions &options)
static int GetCommandParamCount(uint8_t opcode)
std::string GenerateChannelData(const MusicTrack &track, int channel_index, const AsmExportOptions &options)
static const char * GetDurationConstant(uint8_t duration)
static const char * GetInstrumentMacro(uint8_t instrument_id)
static std::string GetNoteName(uint8_t pitch)
absl::Status ExportToFile(const MusicSong &song, const std::string &path, const AsmExportOptions &options)
Export a song to a file.
std::string GenerateChannelPointers(const MusicSong &song, const AsmExportOptions &options)
static const char * GetCommandMacro(uint8_t opcode)
absl::StatusOr< std::string > ExportSong(const MusicSong &song, const AsmExportOptions &options)
Export a song to ASM string.
std::string ConvertNoteToAsm(const Note &note, const AsmExportOptions &options, uint8_t &current_duration)
std::string GenerateHeader(const MusicSong &song, const AsmExportOptions &options)
std::string ConvertEventToAsm(const TrackEvent &event, const AsmExportOptions &options, uint8_t &current_duration)
constexpr DurationConstant kDurationConstants[]
constexpr InstrumentMacro kInstrumentMacros[]
Options for ASM export in music_macros.asm format.
Represents an N-SPC command (opcodes 0xE0-0xFF).
Definition song_data.h:222
A complete song composed of segments.
Definition song_data.h:334
One of 8 channels in a music segment.
Definition song_data.h:291
Represents a single musical note.
Definition song_data.h:192
A single event in a music track (note, command, or control).
Definition song_data.h:247