aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/cdrom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/gob/cdrom.cpp')
-rw-r--r--engines/gob/cdrom.cpp75
1 files changed, 48 insertions, 27 deletions
diff --git a/engines/gob/cdrom.cpp b/engines/gob/cdrom.cpp
index 2ee8595ad3..1c26199bc1 100644
--- a/engines/gob/cdrom.cpp
+++ b/engines/gob/cdrom.cpp
@@ -151,40 +151,27 @@ void CDROM::playMultMusic() {
}
}
-void CDROM::startTrack(const char *trackname) {
- byte *curPtr, *matchPtr;
-
+void CDROM::startTrack(const char *trackName) {
if (!_LICbuffer)
return;
- debugC(1, kDebugMusic, "CDROM::startTrack(%s)", trackname);
-
- matchPtr = 0;
- curPtr = _LICbuffer;
-
- for (int i = 0; i < _numTracks; i++) {
- if (!scumm_stricmp((char *)curPtr, trackname)) {
- matchPtr = curPtr;
- break;
- }
- curPtr += 22;
- }
+ debugC(1, kDebugMusic, "CDROM::startTrack(%s)", trackName);
+ byte *matchPtr = getTrackBuffer(trackName);
if (!matchPtr) {
- warning("Track \"%s\" not found", trackname);
+ warning("Track \"%s\" not found", trackName);
return;
}
- strncpy0(_curTrack, trackname, 15);
+ strncpy0(_curTrack, trackName, 15);
stopPlaying();
+ _curTrackBuffer = matchPtr;
- while (getTrackPos() != -1);
-
- uint32 start, end;
+ while (getTrackPos() >= 0);
- start = READ_LE_UINT32(matchPtr + 12);
- end = READ_LE_UINT32(matchPtr + 16);
+ uint32 start = READ_LE_UINT32(matchPtr + 12);
+ uint32 end = READ_LE_UINT32(matchPtr + 16);
play(start, end);
@@ -205,12 +192,27 @@ void CDROM::play(uint32 from, uint32 to) {
_cdPlaying = true;
}
-int32 CDROM::getTrackPos() {
- uint32 curPos = _vm->_util->getTimeKey() - _startTime;
+int32 CDROM::getTrackPos(const char *keyTrack) {
+ byte *keyBuffer = getTrackBuffer(keyTrack);
+ uint32 curPos = (_vm->_util->getTimeKey() - _startTime) * 3 / 40;
+
+ if (_cdPlaying && (_vm->_util->getTimeKey() < _trackStop)) {
+ if (keyBuffer && _curTrackBuffer && (keyBuffer != _curTrackBuffer)) {
+ uint32 kStart = READ_LE_UINT32(keyBuffer + 12);
+ uint32 kEnd = READ_LE_UINT32(keyBuffer + 16);
+ uint32 cStart = READ_LE_UINT32(_curTrackBuffer + 12);
+ uint32 cEnd = READ_LE_UINT32(_curTrackBuffer + 16);
+
+ if ((kStart >= cStart) && (kEnd <= cEnd)) {
+ if ((kStart - cStart) > curPos)
+ return -2;
+ if ((kEnd - cStart) < curPos)
+ return -1;
+ }
+ }
- if (_cdPlaying && (_vm->_util->getTimeKey() < _trackStop))
- return curPos * 3 / 40;
- else
+ return curPos;
+ } else
return -1;
}
@@ -227,6 +229,7 @@ void CDROM::stopPlaying() {
void CDROM::stop() {
debugC(1, kDebugMusic, "CDROM::stop()");
+ _curTrackBuffer = 0;
AudioCD.stop();
_cdPlaying = false;
}
@@ -245,4 +248,22 @@ void CDROM::testCD(int trySubst, const char *label) {
// CD secor reading
}
+byte *CDROM::getTrackBuffer(const char *trackName) {
+ if (!_LICbuffer || !trackName)
+ return 0;
+
+ byte *matchPtr = 0;
+ byte *curPtr = _LICbuffer;
+
+ for (int i = 0; i < _numTracks; i++) {
+ if (!scumm_stricmp((char *) curPtr, trackName)) {
+ matchPtr = curPtr;
+ break;
+ }
+ curPtr += 22;
+ }
+
+ return matchPtr;
+}
+
} // End of namespace Gob