2008-12-01 20:35:36 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* CD/drive handling functions
|
|
|
|
*/
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2008-12-01 20:35:36 +00:00
|
|
|
#include "tinsel/drives.h"
|
|
|
|
#include "tinsel/scene.h"
|
|
|
|
#include "tinsel/tinsel.h"
|
|
|
|
#include "tinsel/sched.h"
|
|
|
|
#include "tinsel/strres.h"
|
|
|
|
|
|
|
|
namespace Tinsel {
|
|
|
|
|
2010-11-16 09:53:55 +00:00
|
|
|
// FIXME: Avoid non-const global vars
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
char g_currentCD = '1';
|
2008-12-01 20:35:36 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static bool g_bChangingCD = false;
|
|
|
|
static char g_nextCD = '\0';
|
2008-12-01 20:35:36 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static uint32 g_lastTime = 0;
|
|
|
|
extern LANGUAGE g_sampleLanguage;
|
2010-11-16 09:53:55 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
void CdCD(CORO_PARAM) {
|
|
|
|
CORO_BEGIN_CONTEXT;
|
|
|
|
CORO_END_CONTEXT(_ctx);
|
|
|
|
|
|
|
|
CORO_BEGIN_CODE(_ctx);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
while (g_bChangingCD) {
|
2012-05-11 13:10:12 +00:00
|
|
|
if (CoroScheduler.getCurrentProcess()) {
|
|
|
|
// FIXME: CdCD gets passed a Common::nullContext in RegisterGlobals() and
|
2008-12-01 20:35:36 +00:00
|
|
|
// PrimeSceneHopper(), because I didn't know how to get a proper
|
|
|
|
// context without converting the whole calling stack to CORO'd
|
|
|
|
// functions. If these functions really get called while a CD
|
|
|
|
// change is requested, this needs to be resolved.
|
2012-05-11 13:10:12 +00:00
|
|
|
if (coroParam == Common::nullContext)
|
2009-05-31 10:02:16 +00:00
|
|
|
error("CdCD needs context");
|
2008-12-01 20:35:36 +00:00
|
|
|
CORO_SLEEP(1);
|
|
|
|
} else
|
2009-05-31 10:02:16 +00:00
|
|
|
error("No current process in CdCD()");
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CORO_END_CODE;
|
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
int GetCurrentCD() {
|
2008-12-01 20:35:36 +00:00
|
|
|
// count from 1
|
2012-02-22 22:14:29 +00:00
|
|
|
return (g_currentCD - '1' + 1);
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2011-04-10 17:22:06 +00:00
|
|
|
static const uint32 cdFlags[] = { fCd1, fCd2, fCd3, fCd4, fCd5, fCd6, fCd7, fCd8 };
|
2011-04-10 02:53:42 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
void SetCD(int flags) {
|
2012-02-22 22:14:29 +00:00
|
|
|
if (flags & cdFlags[g_currentCD - '1'])
|
2008-12-01 20:35:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error("SetCD() problem");
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetCD(int flags) {
|
|
|
|
int i;
|
|
|
|
char cd = '\0';
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (flags & cdFlags[g_currentCD - '1'])
|
2008-12-01 20:35:36 +00:00
|
|
|
return GetCurrentCD();
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (flags & cdFlags[i]) {
|
|
|
|
cd = (char)(i + '1');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(i != 8);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_nextCD = cd;
|
2008-12-01 20:35:36 +00:00
|
|
|
return cd;
|
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void DoCdChange() {
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_bChangingCD && (g_system->getMillis() > (g_lastTime + 1000))) {
|
|
|
|
g_lastTime = g_system->getMillis();
|
2008-12-01 20:35:36 +00:00
|
|
|
_vm->_sound->closeSampleStream();
|
2009-04-25 06:42:01 +00:00
|
|
|
|
|
|
|
// Use the filesize of the sample file to determine, for Discworld 2, which CD it is
|
|
|
|
if (TinselV2) {
|
|
|
|
TinselFile f;
|
2012-02-22 22:14:29 +00:00
|
|
|
if (!f.open(_vm->getSampleFile(g_sampleLanguage)))
|
2009-04-25 06:42:01 +00:00
|
|
|
// No CD present
|
|
|
|
return;
|
|
|
|
|
|
|
|
char sampleCdNumber = (f.size() >= (200 * 1024 * 1024)) ? '1' : '2';
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_currentCD != sampleCdNumber)
|
2009-04-25 06:42:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
_vm->_sound->openSampleFiles();
|
|
|
|
ChangeLanguage(TextLanguage());
|
2012-02-22 22:14:29 +00:00
|
|
|
g_bChangingCD = false;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNextCD(int cdNumber) {
|
|
|
|
assert(cdNumber == 1 || cdNumber == 2);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_nextCD = (char)(cdNumber + '1' - 1);
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
bool GotoCD() {
|
2008-12-01 20:35:36 +00:00
|
|
|
// WORKAROUND: Somehow, CdDoChange() is called twice... Hopefully, this guard helps
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_currentCD == g_nextCD)
|
2008-12-01 20:35:36 +00:00
|
|
|
return false;
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_currentCD = g_nextCD;
|
2008-12-01 20:35:36 +00:00
|
|
|
|
2009-03-07 19:24:31 +00:00
|
|
|
/* if (bNoCD) {
|
2008-12-01 20:35:36 +00:00
|
|
|
strcpy(cdDirectory, hdDirectory);
|
|
|
|
cdLastBit[3] = currentCD;
|
|
|
|
strcat(cdDirectory, cdLastBit);
|
|
|
|
}
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
g_bChangingCD = true;
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-25 06:42:01 +00:00
|
|
|
bool TinselFile::_warningShown = false;
|
|
|
|
|
2012-07-15 12:00:00 +00:00
|
|
|
TinselFile::TinselFile() : ReadStreamEndian(TinselV1Mac) {
|
2010-11-20 03:14:03 +00:00
|
|
|
_stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TinselFile::~TinselFile() {
|
|
|
|
delete _stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TinselFile::openInternal(const Common::String &filename) {
|
2010-11-23 22:33:26 +00:00
|
|
|
_stream = SearchMan.createReadStreamForMember(filename);
|
|
|
|
if (!_stream)
|
|
|
|
_stream = SearchMan.createReadStreamForMember(filename + ".");
|
|
|
|
return _stream != 0;
|
2010-11-20 03:14:03 +00:00
|
|
|
}
|
2009-04-25 06:42:01 +00:00
|
|
|
|
2010-11-20 03:14:03 +00:00
|
|
|
bool TinselFile::open(const Common::String &filename) {
|
|
|
|
if (openInternal(filename))
|
2009-04-25 06:42:01 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!TinselV2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if the file being requested is the *1.* or *2.* files
|
|
|
|
const char *fname = filename.c_str();
|
|
|
|
const char *p = strchr(fname, '1');
|
|
|
|
if (!p)
|
|
|
|
p = strchr(fname, '2');
|
|
|
|
if (!p || (*(p + 1) != '.'))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Form a filename without the CD number character
|
|
|
|
char newFilename[50];
|
|
|
|
strncpy(newFilename, fname, p - fname);
|
|
|
|
strcpy(newFilename + (p - fname), p + 1);
|
|
|
|
|
2010-11-20 03:14:03 +00:00
|
|
|
return openInternal(newFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TinselFile::close() {
|
|
|
|
delete _stream;
|
|
|
|
_stream = NULL;
|
2009-04-25 06:42:01 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 22:26:09 +00:00
|
|
|
int32 TinselFile::pos() const {
|
|
|
|
assert(_stream);
|
|
|
|
return _stream->pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 TinselFile::size() const {
|
|
|
|
assert(_stream);
|
|
|
|
return _stream->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TinselFile::seek(int32 offset, int whence) {
|
|
|
|
assert(_stream);
|
|
|
|
return _stream->seek(offset, whence);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TinselFile::eos() const {
|
|
|
|
assert(_stream);
|
|
|
|
return _stream->eos();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TinselFile::err() const {
|
|
|
|
assert(_stream);
|
|
|
|
return _stream->err();
|
|
|
|
}
|
|
|
|
|
2010-11-23 22:26:43 +00:00
|
|
|
void TinselFile::clearErr() {
|
2010-11-23 22:26:09 +00:00
|
|
|
assert(_stream);
|
2010-11-23 22:26:43 +00:00
|
|
|
_stream->clearErr();
|
2010-11-23 22:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 TinselFile::read(void *dataPtr, uint32 dataSize) {
|
|
|
|
assert(_stream);
|
|
|
|
return _stream->read(dataPtr, dataSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Tinsel
|