Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sound/MPlayDef.s
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@
.equ TUNE, 0xc8 @ micro tuning (c_v+??)

.equ XCMD, 0xcd @ extend command ***lib
.equ xWAVE, 0x01
.equ xTYPE, 0x02
.equ xATTA, 0x04
.equ xDECA, 0x05
.equ xSUST, 0x06
.equ xRELE, 0x07
.equ xIECV, 0x08 @ imi.echo vol ***lib
.equ xIECL, 0x09 @ imi.echo len ***lib
.equ xLENG, 0x0A
.equ xSWEE, 0x0B

.equ EOT, 0xce @ End of Tie
.equ TIE, 0xcf @
Expand Down
52 changes: 48 additions & 4 deletions tools/mid2agb/agb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,38 @@ void PrintMemAcc(const Event& event)

void PrintExtendedOp(const Event& event)
{
// TODO: support for other extended commands

switch (s_extendedCommand)
{
case 0x01:
PrintOp(event.time, "XCMD ", "xWAVE , %u", event.param2);
break;
case 0x02:
PrintOp(event.time, "XCMD ", "xTYPE , %u", event.param2);
break;
case 0x04:
PrintOp(event.time, "XCMD ", "xATTA , %u", event.param2);
break;
case 0x05:
PrintOp(event.time, "XCMD ", "xDECA , %u", event.param2);
break;
case 0x06:
PrintOp(event.time, "XCMD ", "xSUST , %u", event.param2);
break;
case 0x07:
PrintOp(event.time, "XCMD ", "xRELE , %u", event.param2);
break;
case 0x08:
PrintOp(event.time, "XCMD ", "xIECV , %u", event.param2);
break;
case 0x09:
PrintOp(event.time, "XCMD ", "xIECL , %u", event.param2);
break;
case 0x0A:
PrintOp(event.time, "XCMD ", "xLENG , %u", event.param2);
break;
case 0x0B:
PrintOp(event.time, "XCMD ", "xSWEE , %u", event.param2);
break;
default:
PrintWait(event.time);
break;
Expand All @@ -348,7 +370,14 @@ void PrintExtendedOp(const Event& event)

void PrintControllerOp(const Event& event)
{
switch (event.param1)
int param1 = event.param1;

// Map alternate controller ranges (42-63) down by 30
// e.g. CC 63 -> 33 (PRIO)
if (param1 >= 42 && param1 < 64)
param1 -= 30;

switch (param1)
{
case 0x01:
PrintOp(event.time, "MOD ", "%u", event.param2);
Expand Down Expand Up @@ -401,7 +430,22 @@ void PrintControllerOp(const Event& event)
break;
case 0x1E:
s_extendedCommand = event.param2;
// TODO: loop op
if (event.param2 == 100)
{
std::fprintf(g_outputFile, "%s_%u_LOOP:\n", g_asmLabel.c_str(), g_agbTrack);
PrintWait(event.time);
ResetTrackVars();
}
else if (event.param2 == 101)
{
PrintByte("GOTO");
PrintWord("%s_%u_LOOP", g_asmLabel.c_str(), g_agbTrack);
PrintWait(event.time);
}
else
{
PrintWait(event.time);
}
break;
case 0x21:
case 0x27:
Expand Down
6 changes: 3 additions & 3 deletions tools/mid2agb/midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void ReadMidiFileHeader()
g_midiTrackCount = ReadInt16();
g_midiTimeDiv = ReadInt16();

if (g_midiTimeDiv < 0)
if (g_midiTimeDiv <= 0)
RaiseError("unsupported MIDI time division (%d)", g_midiTimeDiv);
}

Expand Down Expand Up @@ -238,7 +238,7 @@ std::string ReadEventText()

if (length <= 2)
{
if (fread(buffer, length, 1, g_inputFile) != 1)
if (length > 0 && fread(buffer, length, 1, g_inputFile) != 1)
RaiseError("failed to read event text");
}
else
Expand Down Expand Up @@ -636,7 +636,7 @@ void ConvertTimes(std::vector<Event>& events)

if (event.type == EventType::Note)
{
event.param1 = g_noteVelocityLUT[event.param1];
event.param1 = g_noteVelocityLUT[event.param1 & 0x7F];

std::uint32_t duration = (24 * g_clocksPerBeat * event.param2) / g_midiTimeDiv;

Expand Down