diff options
author | Jamieson Christian | 2003-05-21 04:36:09 +0000 |
---|---|---|
committer | Jamieson Christian | 2003-05-21 04:36:09 +0000 |
commit | 9c4a1cf65738863a7f52d7741ccc250bf7975ee8 (patch) | |
tree | 187c12a4fc5d0586a9d9ab9647795ff1b942f148 /simon | |
parent | ec46d2f8538aa58eb646f5a543de11072493d3ac (diff) | |
download | scummvm-rg350-9c4a1cf65738863a7f52d7741ccc250bf7975ee8.tar.gz scummvm-rg350-9c4a1cf65738863a7f52d7741ccc250bf7975ee8.tar.bz2 scummvm-rg350-9c4a1cf65738863a7f52d7741ccc250bf7975ee8.zip |
More Simon music fixes
svn-id: r7761
Diffstat (limited to 'simon')
-rw-r--r-- | simon/items.cpp | 18 | ||||
-rw-r--r-- | simon/midi.cpp | 49 | ||||
-rw-r--r-- | simon/midi.h | 8 | ||||
-rw-r--r-- | simon/vga.cpp | 67 |
4 files changed, 107 insertions, 35 deletions
diff --git a/simon/items.cpp b/simon/items.cpp index 5cda599892..df3d49ac3a 100644 --- a/simon/items.cpp +++ b/simon/items.cpp @@ -1444,10 +1444,12 @@ void SimonState::o_unk_127() { // effectively preloaded so there's no latency when // starting playback). if (_game & GF_SIMON2) { - int play = getVarOrByte(); + int loop = getVarOrByte(); if (_debugMode) - debug (0, "o_unk_127 (%d, %d, %d);", music, track, play); + debug (0, "o_unk_127 (%d, %d, %d): Load/play music resource", music, track, loop); + + midi.setLoop (loop != 0); if (_last_music_played != music) { playMusic (music); @@ -1460,19 +1462,11 @@ void SimonState::o_unk_127() { return; _vc72_var1 = track; + _vc70_var1 = -1; _vc70_var2 = -1; + _vc72_var2 = -1; _vc72_var3 = -1; midi_play (track); - - // FIXME: This doesn't seem to actually be a pause - // indicator. If it's interpreted as such, it spoils - // the music when Simon is exiting Calypso's shop - // during the opening cutscene. Let's see if it - // ever goes to anything besides 0 or 1. -// if (play == 0) -// midi.pause (true); - if (play != 0 && play != 1) - warning ("o_unk_127: play mode %d encountered!", play); } else { if (music != _last_music_played) { _last_music_played = music; diff --git a/simon/midi.cpp b/simon/midi.cpp index 3b86103274..a89638dcc4 100644 --- a/simon/midi.cpp +++ b/simon/midi.cpp @@ -37,10 +37,14 @@ MidiPlayer::MidiPlayer (OSystem *system) { _parser = 0; _data = 0; - memset(_volumeTable, 0, sizeof(_volumeTable)); + memset(_volumeTable, 127, sizeof(_volumeTable)); _masterVolume = 255; _paused = false; _currentTrack = 255; + _loopTrack = 0; + + _queuedTrack = 255; + _loopQueuedTrack = 0; _num_songs = 0; memset(_songs, 0, sizeof(_songs)); @@ -99,7 +103,26 @@ void MidiPlayer::metaEvent (byte type, byte *data, uint16 length) { if (type != 0x2F) return; - _parser->jumpToTick (0); + if (_loopTrack) { + _parser->jumpToTick (0); + } else if (_queuedTrack != 255) { + _currentTrack = 255; + byte destination = _queuedTrack; + _queuedTrack = 255; + _loopTrack = _loopQueuedTrack; + _loopQueuedTrack = false; + + // Remember, we're still inside the locked mutex. + // Have to unlock it before calling jump() + // (which locks it itself), and then relock it + // upon returning. + debug (0, " Switching to queued track"); + _system->unlock_mutex (_mutex); + jump (destination, 0); + _system->lock_mutex (_mutex); + } else { + stop(); + } } void MidiPlayer::onTimer (void *data) { @@ -149,9 +172,8 @@ void MidiPlayer::jump (uint16 track, uint16 tick) { } void MidiPlayer::stop() { + pause (true); _system->lock_mutex (_mutex); - if (_parser) - _parser->unloadMusic(); _currentTrack = 255; _system->unlock_mutex (_mutex); } @@ -195,6 +217,25 @@ void MidiPlayer::set_driver(MidiDriver *md) { _driver = md; } +void MidiPlayer::setLoop (bool loop) { + _system->lock_mutex (_mutex); + _loopTrack = loop; + _system->unlock_mutex (_mutex); +} + +void MidiPlayer::queueTrack (byte track, bool loop) { + _system->lock_mutex (_mutex); + if (_currentTrack == 255) { + _system->unlock_mutex (_mutex); + setLoop (loop); + jump (track, 0); + } else { + _queuedTrack = track; + _loopQueuedTrack = loop; + _system->unlock_mutex (_mutex); + } +} + void MidiPlayer::clearConstructs() { if (_num_songs > 0) { byte i; diff --git a/simon/midi.h b/simon/midi.h index 2fc899dd56..2471250924 100644 --- a/simon/midi.h +++ b/simon/midi.h @@ -40,6 +40,9 @@ protected: byte _masterVolume; // 0-255 bool _paused; byte _currentTrack; + bool _loopTrack; + byte _queuedTrack; + bool _loopQueuedTrack; byte _num_songs; byte *_songs[16]; @@ -57,6 +60,11 @@ public: void playSMF (File *in, int song); void playMultipleSMF (File *in); void playXMIDI (File *in); + + void setLoop (bool loop); + void queueTrack (byte track, bool loop); + bool isPlaying (bool check_queued = false) { return (_currentTrack != 255 && (_queuedTrack != 255 || !check_queued)); } + void jump (uint16 track, uint16 tick); void stop(); void pause (bool b); diff --git a/simon/vga.cpp b/simon/vga.cpp index 8b1b40f326..56a1f8823a 100644 --- a/simon/vga.cpp +++ b/simon/vga.cpp @@ -1805,13 +1805,13 @@ void SimonState::vc_68_skip_if_le() { void SimonState::vc_69() { // Simon2 int16 track = vc_read_next_word(); - int16 paused = vc_read_next_word(); + int16 loop = vc_read_next_word(); if (_debugMode) - warning("vc_69(%d,%d): music stuff", track, paused); + debug (0, "vc_69(%d,%d): Play track", track, loop); // Jamieson630: - // This is a "play or queue track". The original + // This is a "play track". The original // design stored the track to play if one was // already in progress, so that the next time a // "fill MIDI stream" event occured, the MIDI @@ -1826,48 +1826,70 @@ void SimonState::vc_69() { // as a means of stopping what music is currently // playing. if (_vc72_var1 != track) { + midi.setLoop (loop != 0); midi_play (track); - if (paused) - midi.pause (true); _vc72_var1 = track; - _vc72_var2 = -1; // (a & 0xFF) << 8 | (a >> 8); + _vc72_var2 = -1; _vc72_var3 = -1; + _vc70_var1 = -1; + _vc70_var2 = loop; } /* // ORIGINAL TRANSLATION FROM DISASSEMBLY if (_vc72_var1 == 999 || _vc72_var1 == -1) { - _vc70_var2 = paused; + _vc70_var2 = loop; midi_play (track); _vc72_var1 = track; } else if (_vc72_var1 != track) { _vc72_var3 = track; - _vc72_var2 = paused; // (a & 0xFF) << 8 | (a >> 8); + _vc72_var2 = loop; // (a & 0xFF) << 8 | (a >> 8); } */ } void SimonState::vc_70() { // Simon2 - uint16 a = vc_read_next_word(); - uint16 b = vc_read_next_word(); + uint16 track = vc_read_next_word(); + uint16 loop = vc_read_next_word(); + + // Jamieson630: + // This sets the "on end of track" action. + // It specifies whether to loop the current + // track and, if not, whether to switch to + // a different track upon completion. + _vc70_var1 = track; + _vc70_var2 = loop; - _vc70_var1 = a; - _vc70_var2 = b; + midi.setLoop (loop != 0); + if (_vc70_var1 != -1 && _vc70_var1 != 999) + midi.queueTrack ((byte) track, 0); if (_debugMode) - warning("vc_70(%d,%d): music stuff?", a, b); + debug (0, "vc_70 (%d,%d): Set end of track conditions", track, loop); } void SimonState::vc_71() { // Simon2 + // Jamieson630: + // This command skips the next instruction + // unless (1) there is a track playing, AND + // (2) there is a track queued to play after it. + if (_debugMode) + debug (0, "vc_71(): Is music playing? %s", midi.isPlaying(true) ? "YES" : "NO"); + + if (!midi.isPlaying (true)) + vc_skip_next_instruction(); +/* + // ORIGINAL TRANSLATION FROM DISASSEMBLY if (_vc72_var3 == -1 && _vc70_var1 == -1) vc_skip_next_instruction(); +*/ } void SimonState::vc_72() { // Simon2 // Jamieson630: - // This is a "queue or stop track". The original + // This is a "play or stop track". The original // design stored the track to play if one was // already in progress, so that the next time a // "fill MIDI stream" event occured, the MIDI @@ -1876,26 +1898,33 @@ void SimonState::vc_72() { // allows for an immediate response here, but // we'll simulate the variable changes so other // scripts don't get thrown off. + // NOTE: This opcode looks very similar in function // to vc_72(), except that this opcode may allow // for specifying a track of 999 or -1 in order to // stop the music. We'll code it that way for now. + + // NOTE: It's possible that when "stopping" a track, + // we're supposed to just go on to the next queued + // track, if any. Must find out if there is ANY + // case where this is used to stop a track in the + // first place. + int16 track = vc_read_next_word(); - int16 paused = !vc_read_next_word(); + int16 loop = vc_read_next_word(); if (_debugMode) - warning ("vc_72 (%d, %d): music stuff?", track, paused); + debug (0, "vc_72 (%d, %d): Play or stop track", track, loop); if (track != _vc72_var1) { if (track == -1 || track == 999) { midi.stop(); _vc72_var1 = -1; } else { + midi.setLoop (loop != 0); midi_play (track); - if (paused) - midi.pause (true); _vc72_var1 = track; - _vc72_var2 = paused; + _vc70_var2 = loop; } _vc72_var3 = -1; } |