2005-04-13 18:27:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2005-2006 The ScummVM project
|
2005-04-13 18:27:29 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-13 18:27:29 +00:00
|
|
|
*
|
2006-02-11 10:11:37 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-04-13 18:27:29 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-03-29 15:59:37 +00:00
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/endian.h"
|
|
|
|
|
2005-04-13 18:27:29 +00:00
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/cdrom.h"
|
|
|
|
#include "gob/dataio.h"
|
|
|
|
#include "gob/game.h"
|
|
|
|
#include "gob/global.h"
|
|
|
|
#include "gob/util.h"
|
|
|
|
#include "sound/audiocd.h"
|
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
CDROM::CDROM(GobEngine *vm) : _vm(vm) {
|
|
|
|
_cdPlaying = false;
|
|
|
|
_LICbuffer = 0;
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
_curTrack[i] = 0;
|
|
|
|
_numTracks = 0;
|
|
|
|
_trackStop = 0;
|
|
|
|
_startTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDROM::readLIC(const char *fname) {
|
2005-04-13 18:27:29 +00:00
|
|
|
char tmp[80];
|
|
|
|
int handle;
|
|
|
|
uint16 version, startChunk, pos;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
freeLICbuffer();
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
*_curTrack = 0;
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
strcpy(tmp, fname);
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
handle = _vm->_dataio->openData(tmp);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
if (handle == -1)
|
|
|
|
return;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->closeData(handle);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->getUnpackedData(tmp);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
handle = _vm->_dataio->openData(tmp);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->readData(handle, (char *)&version, 2);
|
2005-04-13 18:27:29 +00:00
|
|
|
version = READ_LE_UINT16(&version);
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->readData(handle, (char *)&startChunk, 2);
|
2005-04-13 18:27:29 +00:00
|
|
|
startChunk = READ_LE_UINT16(&startChunk);
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->readData(handle, (char *)&_numTracks, 2);
|
|
|
|
_numTracks = READ_LE_UINT16(&_numTracks);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
if (version != 3) {
|
|
|
|
error("Wrong file %s (%d)", fname, version);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->seekData(handle, 50, SEEK_SET);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < startChunk; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->readData(handle, (char *)&pos, 2);
|
2005-04-13 18:27:29 +00:00
|
|
|
pos = READ_LE_UINT16(&pos);
|
|
|
|
|
|
|
|
if (!pos)
|
|
|
|
break;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->seekData(handle, pos, SEEK_CUR);
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-29 02:27:10 +00:00
|
|
|
_LICbuffer = new byte[_numTracks * 22];
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->readData(handle, (char *)_LICbuffer, _numTracks * 22);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->closeData(handle);
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::freeLICbuffer(void) {
|
2006-01-29 02:27:10 +00:00
|
|
|
delete[] _LICbuffer;
|
2006-01-03 23:14:39 +00:00
|
|
|
_LICbuffer = 0;
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::playBgMusic() {
|
2005-04-13 18:27:29 +00:00
|
|
|
static const char *tracks[][2] = {
|
|
|
|
{"avt00.tot", "mine"},
|
|
|
|
{"avt001.tot", "nuit"},
|
|
|
|
{"avt002.tot", "campagne"},
|
|
|
|
{"avt003.tot", "extsor1"},
|
|
|
|
{"avt004.tot", "interieure"},
|
|
|
|
{"avt005.tot", "zombie"},
|
|
|
|
{"avt006.tot", "zombie"},
|
|
|
|
{"avt007.tot", "campagne"},
|
|
|
|
{"avt008.tot", "campagne"},
|
|
|
|
{"avt009.tot", "extsor1"},
|
|
|
|
{"avt010.tot", "extsor1"},
|
|
|
|
{"avt011.tot", "interieure"},
|
|
|
|
{"avt012.tot", "zombie"},
|
|
|
|
{"avt014.tot", "nuit"},
|
|
|
|
{"avt015.tot", "interieure"},
|
|
|
|
{"avt016.tot", "statue"},
|
|
|
|
{"avt017.tot", "zombie"},
|
|
|
|
{"avt018.tot", "statue"},
|
|
|
|
{"avt019.tot", "mine"},
|
|
|
|
{"avt020.tot", "statue"},
|
|
|
|
{"avt021.tot", "mine"},
|
|
|
|
{"avt022.tot", "zombie"}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < ARRAYSIZE(tracks); i++)
|
2006-01-07 22:28:54 +00:00
|
|
|
if (!scumm_stricmp(_vm->_game->_curTotFile, tracks[i][0])) {
|
2006-01-03 23:14:39 +00:00
|
|
|
startTrack(tracks[i][1]);
|
2005-04-13 18:27:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::playMultMusic() {
|
2005-04-13 18:27:29 +00:00
|
|
|
static const char *tracks[][6] = {
|
|
|
|
{"avt005.tot", "fra1", "all1", "ang1", "esp1", "ita1"},
|
|
|
|
{"avt006.tot", "fra2", "all2", "ang2", "esp2", "ita2"},
|
|
|
|
{"avt012.tot", "fra3", "all3", "ang3", "esp3", "ita3"},
|
|
|
|
{"avt016.tot", "fra4", "all4", "ang4", "esp4", "ita4"},
|
|
|
|
{"avt019.tot", "fra5", "all5", "ang5", "esp5", "ita5"},
|
|
|
|
{"avt022.tot", "fra6", "all6", "ang6", "esp6", "ita6"}
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-13 18:27:29 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(tracks); i++)
|
2006-01-07 22:28:54 +00:00
|
|
|
if (!scumm_stricmp(_vm->_game->_curTotFile, tracks[i][0])) {
|
2006-01-04 01:48:15 +00:00
|
|
|
startTrack(tracks[i][_vm->_global->_language + 1]);
|
2005-04-13 18:27:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::startTrack(const char *trackname) {
|
2005-04-13 18:27:29 +00:00
|
|
|
byte *curPtr, *matchPtr;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (!_LICbuffer)
|
2005-04-13 18:27:29 +00:00
|
|
|
return;
|
|
|
|
|
2007-01-25 14:18:12 +00:00
|
|
|
debugC(1, kDebugMusic, "CDROM::startTrack(%s)", trackname);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
matchPtr = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
curPtr = _LICbuffer;
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
for (int i = 0; i < _numTracks; i++) {
|
2005-04-13 18:27:29 +00:00
|
|
|
if (!scumm_stricmp((char *)curPtr, trackname)) {
|
|
|
|
matchPtr = curPtr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curPtr += 22;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!matchPtr) {
|
2007-01-26 19:00:41 +00:00
|
|
|
warning("Track %s not found", trackname);
|
2005-04-13 18:27:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
strcpy(_curTrack, trackname);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
stopPlaying();
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
while (getTrackPos() != -1);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
uint32 start, end;
|
|
|
|
|
|
|
|
start = READ_LE_UINT32(matchPtr + 12);
|
|
|
|
end = READ_LE_UINT32(matchPtr + 16);
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
play(start, end);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_startTime = _vm->_util->getTimeKey();
|
|
|
|
_trackStop = _startTime + (end - start + 1 + 150) * 40 / 3;
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::play(uint32 from, uint32 to) {
|
2005-04-13 18:27:29 +00:00
|
|
|
// play from sector [from] to sector [to]
|
|
|
|
//
|
|
|
|
// format is HSG:
|
|
|
|
// HSG encodes frame information into a double word:
|
|
|
|
// minute multiplied by 4500, plus second multiplied by 75,
|
|
|
|
// plus frame, minus 150
|
2007-01-25 14:18:12 +00:00
|
|
|
debugC(1, kDebugMusic, "CDROM::play(%d, %d)", from, to);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-12-20 15:50:13 +00:00
|
|
|
AudioCD.play(1, 1, from, to - from + 1);
|
|
|
|
_cdPlaying = true;
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
int32 CDROM::getTrackPos(void) {
|
|
|
|
uint32 curPos = _vm->_util->getTimeKey() - _startTime;
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-12-20 15:50:13 +00:00
|
|
|
if (_cdPlaying && (_vm->_util->getTimeKey() < _trackStop))
|
2005-04-13 18:27:29 +00:00
|
|
|
return curPos * 3 / 40;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-11-27 14:19:30 +00:00
|
|
|
const char *CDROM::getCurTrack(void) {
|
|
|
|
return _curTrack;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::stopPlaying(void) {
|
|
|
|
stop();
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
while (getTrackPos() != -1);
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::stop(void) {
|
2007-01-25 14:18:12 +00:00
|
|
|
debugC(1, kDebugMusic, "CDROM::stop()");
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
AudioCD.stop();
|
2006-12-20 15:50:13 +00:00
|
|
|
_cdPlaying = false;
|
2005-04-13 18:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void CDROM::testCD(int trySubst, const char *label) {
|
2005-04-13 18:27:29 +00:00
|
|
|
if (!trySubst) {
|
|
|
|
error("CDROM track substitution is not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_LICbuffer = 0;
|
|
|
|
_cdPlaying = false;
|
2005-04-13 18:27:29 +00:00
|
|
|
|
|
|
|
// Original checked CD label here
|
|
|
|
// but will skip it as it will require OSystem extensions of direct
|
|
|
|
// CD secor reading
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Gob
|