diff options
Diffstat (limited to 'engines/groovie')
-rw-r--r-- | engines/groovie/music.cpp | 38 | ||||
-rw-r--r-- | engines/groovie/music.h | 2 | ||||
-rw-r--r-- | engines/groovie/script.cpp | 11 | ||||
-rw-r--r-- | engines/groovie/script.h | 2 |
4 files changed, 45 insertions, 8 deletions
diff --git a/engines/groovie/music.cpp b/engines/groovie/music.cpp index 2c900f73fb..f8a8a4716c 100644 --- a/engines/groovie/music.cpp +++ b/engines/groovie/music.cpp @@ -26,11 +26,13 @@ #include "groovie/music.h" #include "groovie/resource.h" +#include "sound/audiocd.h" + namespace Groovie { MusicPlayer::MusicPlayer(GroovieEngine *vm) : _vm(vm), _midiParser(NULL), _data(NULL), _driver(NULL), - _backgroundFileRef(0), _gameVolume(100) { + _backgroundFileRef(0), _gameVolume(100), _prevCDtrack(0) { // Create the parser _midiParser = MidiParser::createParser_XMIDI(); @@ -79,6 +81,40 @@ void MusicPlayer::setBackgroundSong(uint16 fileref) { _backgroundFileRef = fileref; } +void MusicPlayer::playCD(uint8 track) { + int startms = 0; + + // Stop the MIDI playback + unload(); + + debugC(1, kGroovieDebugMIDI | kGroovieDebugAll, "Groovie::Music: Playing CD track %d", track); + + if (track == 3) { + // This is the credits song, start at 23:20 + startms = 1400000; + // TODO: If we want to play it directly from the CD, we should decrement + // the song number (it's track 2 on the 2nd CD) + } else if ((track == 98) && (_prevCDtrack == 3)) { + // Track 98 is used as a hack to stop the credits song + AudioCD.stop(); + return; + } + + // Save the playing track in order to be able to stop the credits song + _prevCDtrack = track; + + // Wait until the CD stops playing the current song + AudioCD.updateCD(); + while (AudioCD.isPlaying()) { + // Wait a bit and try again + _vm->_system->delayMillis(100); + AudioCD.updateCD(); + } + + // Play the track starting at the requested offset (1000ms = 75 frames) + AudioCD.play(track - 1, 1, startms * 75 / 1000, 0); +} + void MusicPlayer::setUserVolume(uint16 volume) { Common::StackLock lock(_mutex); diff --git a/engines/groovie/music.h b/engines/groovie/music.h index bfafd30aad..91e42c05e9 100644 --- a/engines/groovie/music.h +++ b/engines/groovie/music.h @@ -40,6 +40,7 @@ public: ~MusicPlayer(); void playSong(uint16 fileref); void setBackgroundSong(uint16 fileref); + void playCD(uint8 track); // Volume void setUserVolume(uint16 volume); @@ -80,6 +81,7 @@ private: MidiDriver *_driver; uint16 _backgroundFileRef; + uint8 _prevCDtrack; static void onTimer(void *data); diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp index c1cdd1e7d4..bdae0c1337 100644 --- a/engines/groovie/script.cpp +++ b/engines/groovie/script.cpp @@ -33,7 +33,6 @@ #include "common/endian.h" #include "common/events.h" #include "common/savefile.h" -#include "sound/audiocd.h" #define NUM_OPCODES 90 @@ -1424,16 +1423,16 @@ void Script::o_getcd() { setVariable(0x106, cd); } -void Script::o_opcode4D() { - // TODO: play alternative vie logo, then playcd +void Script::o_playcd() { uint8 val = readScript8bits(); - debugScript(1, true, "PLAYCD? %d", val); + debugScript(1, true, "PLAYCD %d", val); if (val == 2) { - AudioCD.play(1, 1, 0, 0); + // TODO: Play the alternative logo } + _vm->_musicPlayer->playCD(val); } void Script::o_hotspot_outrect() { @@ -1549,7 +1548,7 @@ Script::OpcodeFunc Script::_opcodes[NUM_OPCODES] = { &Script::o_nop16, &Script::o_nop8, &Script::o_getcd, // 0x4C - &Script::o_opcode4D, + &Script::o_playcd, &Script::o_nop16, &Script::o_nop16, &Script::o_nop16, // 0x50 diff --git a/engines/groovie/script.h b/engines/groovie/script.h index b39553b0a6..682638afec 100644 --- a/engines/groovie/script.h +++ b/engines/groovie/script.h @@ -199,7 +199,7 @@ private: void o_sethotspotright(); void o_sethotspotleft(); void o_getcd(); - void o_opcode4D(); + void o_playcd(); void o_hotspot_outrect(); void o_stub56(); void o_stub59(); |