aboutsummaryrefslogtreecommitdiff
path: root/engines/agos/midiparser_s1d.cpp
diff options
context:
space:
mode:
authorMartin Kiewitz2015-06-21 11:19:28 +0200
committerMartin Kiewitz2015-06-21 11:19:28 +0200
commit155d5541834d220a7b7fe8b73dcf12c65dff6cc3 (patch)
tree30cda17bebc84a11d92dd08221432862a6baa311 /engines/agos/midiparser_s1d.cpp
parent5f77bcc74c1aac5179c78c53c69e73b0fdf37858 (diff)
downloadscummvm-rg350-155d5541834d220a7b7fe8b73dcf12c65dff6cc3.tar.gz
scummvm-rg350-155d5541834d220a7b7fe8b73dcf12c65dff6cc3.tar.bz2
scummvm-rg350-155d5541834d220a7b7fe8b73dcf12c65dff6cc3.zip
AGOS: MidiParser_S1D: do proper skipping of SysEx
figured out the code that the original interpreters used to skip over the header-SysEx
Diffstat (limited to 'engines/agos/midiparser_s1d.cpp')
-rw-r--r--engines/agos/midiparser_s1d.cpp41
1 files changed, 30 insertions, 11 deletions
diff --git a/engines/agos/midiparser_s1d.cpp b/engines/agos/midiparser_s1d.cpp
index f07ef5be41..7b9a058efc 100644
--- a/engines/agos/midiparser_s1d.cpp
+++ b/engines/agos/midiparser_s1d.cpp
@@ -179,22 +179,41 @@ void MidiParser_S1D::parseNextEvent(EventInfo &info) {
bool MidiParser_S1D::loadMusic(byte *data, uint32 size) {
unloadMusic();
+ if (!size)
+ return false;
+
// The original actually just ignores the first two bytes.
byte *pos = data;
if (*pos == 0xFC) {
// SysEx found right at the start
- // this seems to happen since Elvira 2, we currently ignore it
- // the original Accolade code does see 0xFC as end of track, which means there must have been a change
- if ((pos[1] == 0x29) && (pos[2] == 0x07) && (pos[3] == 0x01)) {
- // Security check
- // Last byte is either 0x00 or 0x01. Maybe some looping indicator?
- pos += 5; // Waxworks / Simon 1 demo
+ // this seems to happen since Elvira 2, we ignore it
+ // 3rd byte after the SysEx seems to be saved into a global
+
+ // We expect at least 4 bytes in total
+ if (size < 4)
+ return false;
+
+ byte skipOffset = pos[2]; // get second byte after the SysEx
+ // pos[1] seems to have been ignored
+ // pos[3] is saved into a global inside the original interpreters
+
+ // Waxworks + Simon 1 demo typical header is:
+ // 0xFC 0x29 0x07 0x01 [0x00/0x01]
+ // Elvira 2 typical header is:
+ // 0xFC 0x04 0x06 0x06
+
+ if (skipOffset >= 6) {
+ // should be at least 6, so that we skip over the 2 size bytes and the
+ // smallest SysEx possible
+ skipOffset -= 2; // 2 size bytes were already read by previous code outside of this method
+
+ if (size <= skipOffset) // Skip to the end of file? -> something is not correct
+ return false;
+
+ // Do skip over the bytes
+ pos += skipOffset;
} else {
- if ((pos[1] == 0x04) && (pos[2] == 0x06) && (pos[3] == 06)) {
- pos += 4; // Elvira 2
- } else {
- warning("0xFC startup without proper signature");
- }
+ warning("MidiParser_S1D: unexpected skip offset in music file");
}
}