diff options
author | Matthew Hoops | 2011-02-20 02:12:35 -0500 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-09 08:37:30 +0200 |
commit | e07fe3f1a438b245b0a4dbf4506fe4c9d03d9258 (patch) | |
tree | a9af5caafecc7ed0ee78975a1c563a071a1e3676 /engines | |
parent | b47cae789b5ccfbf3999c870d372081ad9c50629 (diff) | |
download | scummvm-rg350-e07fe3f1a438b245b0a4dbf4506fe4c9d03d9258.tar.gz scummvm-rg350-e07fe3f1a438b245b0a4dbf4506fe4c9d03d9258.tar.bz2 scummvm-rg350-e07fe3f1a438b245b0a4dbf4506fe4c9d03d9258.zip |
STARTREK: Import my startrek engine
Now updated even
Diffstat (limited to 'engines')
-rw-r--r-- | engines/startrek/configure.engine | 3 | ||||
-rwxr-xr-x | engines/startrek/detection.cpp | 217 | ||||
-rwxr-xr-x | engines/startrek/font.cpp | 69 | ||||
-rwxr-xr-x | engines/startrek/font.h | 51 | ||||
-rwxr-xr-x | engines/startrek/graphics.cpp | 133 | ||||
-rwxr-xr-x | engines/startrek/graphics.h | 58 | ||||
-rwxr-xr-x | engines/startrek/lzss.cpp | 79 | ||||
-rwxr-xr-x | engines/startrek/lzss.h | 57 | ||||
-rwxr-xr-x | engines/startrek/module.mk | 19 | ||||
-rwxr-xr-x | engines/startrek/sound.cpp | 192 | ||||
-rwxr-xr-x | engines/startrek/sound.h | 76 | ||||
-rwxr-xr-x | engines/startrek/startrek.cpp | 318 | ||||
-rwxr-xr-x | engines/startrek/startrek.h | 93 |
13 files changed, 1365 insertions, 0 deletions
diff --git a/engines/startrek/configure.engine b/engines/startrek/configure.engine new file mode 100644 index 0000000000..bdcd68ef5d --- /dev/null +++ b/engines/startrek/configure.engine @@ -0,0 +1,3 @@ +# This file is included from the main "configure" script +# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] +add_engine startrek "Star Trek 25th Anniversary/Judgment Rites" no diff --git a/engines/startrek/detection.cpp b/engines/startrek/detection.cpp new file mode 100755 index 0000000000..f0f2a353a6 --- /dev/null +++ b/engines/startrek/detection.cpp @@ -0,0 +1,217 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/detection.cpp $ + * $Id: detection.cpp 15 2010-06-27 06:13:42Z clone2727 $ + * + */ + +#include "base/plugins.h" + +#include "engines/advancedDetector.h" +#include "common/config-manager.h" +#include "common/file.h" + +#include "startrek/startrek.h" + +namespace StarTrek { + +struct StarTrekGameDescription { + ADGameDescription desc; + + uint8 gameType; + uint32 features; + uint16 version; +}; + +uint32 StarTrekEngine::getFeatures() const { + return _gameDescription->features; +} + +Common::Platform StarTrekEngine::getPlatform() const { + return _gameDescription->desc.platform; +} + +uint16 StarTrekEngine::getVersion() const { + return _gameDescription->version; +} + +uint8 StarTrekEngine::getGameType() { + return _gameDescription->gameType; +} + +Common::Language StarTrekEngine::getLanguage() { + return _gameDescription->desc.language; +} + +} // End of Namespace StarTrek + +static const PlainGameDescriptor starTrekGames[] = { + {"startrek", "Star Trek game"}, + {"st25", "Star Trek: 25th Anniversary"}, + {"stjr", "Star Trek: Judgment Rites"}, + {0, 0} +}; + + +namespace StarTrek { + +static const StarTrekGameDescription gameDescriptions[] = { + { + { + "st25", + "", + AD_ENTRY1("data.001", "57040928a0f374281aa86ba4e7db8444"), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_NO_FLAGS, + GUIO0() + }, + GType_ST25, + 0, + 0, + }, + + { + { + "st25", + "", + AD_ENTRY1("data.000", "f0918b6d096455ce2ae6dd5ef973292e"), + Common::EN_ANY, + Common::kPlatformAmiga, + ADGF_NO_FLAGS, + GUIO0() + }, + GType_ST25, + 0, + 0, + }, + + { + { + "st25", + "", + AD_ENTRY1("data.000", "70d0e374d5fa973e536dba0f42310672"), + Common::DE_DEU, + Common::kPlatformAmiga, + ADGF_NO_FLAGS, + GUIO0() + }, + GType_ST25, + 0, + 0, + }, + + { + { + "st25", + "", + AD_ENTRY1("data.000", "d0299af1385edd7c7612ed453e417dd8"), + Common::FR_FRA, + Common::kPlatformAmiga, + ADGF_NO_FLAGS, + GUIO0() + }, + GType_ST25, + 0, + 0, + }, + + { + { + "st25", + "", + AD_ENTRY1("Star Trek Data", "871fa51c7680c0a43df9622128f1569f"), + Common::EN_ANY, + Common::kPlatformMacintosh, + ADGF_MACRESFORK, + GUIO0() + }, + GType_ST25, + 0, + 0, + }, + + { + { + "st25", + "Demo", + AD_ENTRY1("data.001", "f68126e7e36ce6286c4c8575f8b594f5"), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_DEMO, + GUIO0() + }, + GType_ST25, + GF_DEMO, + 0, + }, + + { + { + "stjr", + "", + AD_ENTRY1("data.001", "1c8de3c02f69c07c582d59d3c29e4dd9"), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_NO_FLAGS, + GUIO0() + }, + GType_STJR, + 0, + 0, + }, + + { AD_TABLE_END_MARKER, 0, 0, 0 } +}; + +} // End of namespace StarTrek + +class StarTrekMetaEngine : public AdvancedMetaEngine { +public: + StarTrekMetaEngine() : AdvancedMetaEngine(StarTrek::gameDescriptions, sizeof(StarTrek::StarTrekGameDescription), starTrekGames) { + _singleId = "startrek"; + } + + virtual const char *getName() const { + return "Star Trek Engine"; + } + + virtual const char *getOriginalCopyright() const { + return "Star Trek: 25th Anniversary, Star Trek: Judgment Rites (C) Interplay"; + } + + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; +}; + +bool StarTrekMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + const StarTrek::StarTrekGameDescription *gd = (const StarTrek::StarTrekGameDescription *)desc; + + *engine = new StarTrek::StarTrekEngine(syst, gd); + + return (gd != 0); +} + +#if PLUGIN_ENABLED_DYNAMIC(STARTREK) + REGISTER_PLUGIN_DYNAMIC(STARTREK, PLUGIN_TYPE_ENGINE, StarTrekMetaEngine); +#else + REGISTER_PLUGIN_STATIC(STARTREK, PLUGIN_TYPE_ENGINE, StarTrekMetaEngine); +#endif + diff --git a/engines/startrek/font.cpp b/engines/startrek/font.cpp new file mode 100755 index 0000000000..157c9848f2 --- /dev/null +++ b/engines/startrek/font.cpp @@ -0,0 +1,69 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/font.cpp $ + * $Id: font.cpp 2 2009-09-12 20:13:40Z clone2727 $ + * + */ + +#include "startrek/font.h" + +namespace StarTrek { + +static const byte CHARACTER_COUNT = 0x80; +static const byte CHARACTER_SIZE = 0x40; + +Font::Font(StarTrekEngine *vm) : _vm(vm) { + Common::SeekableReadStream *fontStream = _vm->openFile("FONT.FNT"); + + _characters = new Character[CHARACTER_COUNT]; + + for (byte i = 0; i < CHARACTER_COUNT; i++) + fontStream->read(_characters[i].data, CHARACTER_SIZE); + + delete fontStream; + +#if 0 + // Code to dump the font + printf ("DUMPING FONT"); + for (byte i = 0; i < CHARACTER_COUNT; i++) { + printf ("\n\nCHARACTER %02x (%d):\n", i, i); + for (byte j = 0; j < CHARACTER_SIZE; j++) { + if (!(j % 8)) + printf ("\n"); + if (_characters[i].data[j] == 0x7d) + printf ("1 "); + else if (_characters[i].data[j] == 0x78) + printf ("0 "); + else if (_characters[i].data[j] == 0) + printf (" "); + else + printf ("? "); + } + } + printf("\n\n"); +#endif +} + +Font::~Font() { + delete[] _characters; +} + +} diff --git a/engines/startrek/font.h b/engines/startrek/font.h new file mode 100755 index 0000000000..857c98e8e6 --- /dev/null +++ b/engines/startrek/font.h @@ -0,0 +1,51 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/font.h $ + * $Id: font.h 2 2009-09-12 20:13:40Z clone2727 $ + * + */ + +#ifndef STARTREK_FONT_H +#define STARTREK_FONT_H + +#include "startrek/startrek.h" + +namespace StarTrek { + +class StarTrekEngine; + +class Font { +public: + Font(StarTrekEngine *vm); + ~Font(); + +private: + StarTrekEngine *_vm; + + struct Character { + byte data[0x40]; + } *_characters; +}; + + +} + +#endif diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp new file mode 100755 index 0000000000..e2ba26670c --- /dev/null +++ b/engines/startrek/graphics.cpp @@ -0,0 +1,133 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/graphics.cpp $ + * $Id: graphics.cpp 14 2010-05-26 15:44:12Z clone2727 $ + * + */ + +#include "startrek/graphics.h" + +#include "common/config-manager.h" +#include "common/rendermode.h" +#include "graphics/palette.h" + +namespace StarTrek { + +Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) { + _font = 0; + _egaData = 0; + + if (ConfMan.hasKey("render_mode")) + _egaMode = (Common::parseRenderMode(ConfMan.get("render_mode").c_str()) == Common::kRenderEGA) && (_vm->getGameType() != GType_STJR) && !(_vm->getFeatures() & GF_DEMO); + + if (_vm->getGameType() == GType_ST25 && _vm->getPlatform() == Common::kPlatformDOS) + _font = new Font(_vm); +} + +Graphics::~Graphics() { + if (_egaData) + free(_egaData); + + delete _font; +} + +void Graphics::setPalette(const char *paletteFile) { + // Set the palette from a PAL file + + Common::SeekableReadStream *palStream = _vm->openFile(paletteFile); + byte *palette = new byte[256 * 3]; + palStream->read(palette, 256 * 3); + + // Expand color components + if (_vm->getPlatform() == Common::kPlatformDOS || _vm->getPlatform() == Common::kPlatformMacintosh) + for (uint16 i = 0; i < 256 * 3; i++) + palette[i] <<= 2; + + _vm->_system->getPaletteManager()->setPalette(palette, 0, 256); + + delete[] palette; + delete palStream; +} + +void Graphics::loadEGAData(const char *filename) { + // Load EGA palette data + if (!_egaMode) + return; + + if (!_egaData) + _egaData = (byte *)malloc(256); + + Common::SeekableReadStream *egaStream = _vm->openFile(filename); + egaStream->read(_egaData, 256); + delete egaStream; +} + +void Graphics::drawImage(const char *filename) { + // Draw a regular bitmap + + Common::SeekableReadStream *imageStream = _vm->openFile(filename); + uint16 xoffset = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); + uint16 yoffset = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); + uint16 width = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); + uint16 height = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); + + byte *pixels = (byte *)malloc(width * height); + + if (_egaMode && _egaData) { + // FIXME: This doesn't work right + for (uint32 i = 0; i < (uint32)(width * height); i++) + pixels[i] = _egaData[imageStream->readByte()]; + } else { + imageStream->read(pixels, width * height); + } + + _vm->_system->copyRectToScreen(pixels, width, xoffset, yoffset, width, height); + _vm->_system->updateScreen(); +} + +void Graphics::drawBackgroundImage(const char *filename) { + // Draw an stjr BGD image (palette built-in) + + Common::SeekableReadStream *imageStream = _vm->openFile(filename); + byte *palette = new byte[256 * 3]; + imageStream->read(palette, 256 * 3); + + // Expand color components + for (uint16 i = 0; i < 256 * 3; i++) + palette[i] <<= 2; + + uint16 xoffset = imageStream->readUint16LE(); + uint16 yoffset = imageStream->readUint16LE(); + uint16 width = imageStream->readUint16LE(); + uint16 height = imageStream->readUint16LE(); + + byte *pixels = (byte *)malloc(width * height); + imageStream->read(pixels, width * height); + + _vm->_system->getPaletteManager()->setPalette(palette, 0, 256); + _vm->_system->copyRectToScreen(pixels, width, xoffset, yoffset, width, height); + _vm->_system->updateScreen(); + + delete[] palette; + delete imageStream; +} + +} diff --git a/engines/startrek/graphics.h b/engines/startrek/graphics.h new file mode 100755 index 0000000000..b796e83491 --- /dev/null +++ b/engines/startrek/graphics.h @@ -0,0 +1,58 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/graphics.h $ + * $Id: graphics.h 2 2009-09-12 20:13:40Z clone2727 $ + * + */ + +#ifndef STARTREK_GRAPHICS_H +#define STARTREK_GRAPHICS_H + +#include "startrek/startrek.h" +#include "startrek/font.h" + +namespace StarTrek { + +class Font; +class StarTrekEngine; + +class Graphics { +public: + Graphics(StarTrekEngine *vm); + ~Graphics(); + + void setPalette(const char *paletteFile); + void loadEGAData(const char *egaFile); + void drawImage(const char *filename); + void drawBackgroundImage(const char *filename); + + +private: + StarTrekEngine *_vm; + Font *_font; + + bool _egaMode; + byte *_egaData; +}; + +} + +#endif diff --git a/engines/startrek/lzss.cpp b/engines/startrek/lzss.cpp new file mode 100755 index 0000000000..03aa6de8cd --- /dev/null +++ b/engines/startrek/lzss.cpp @@ -0,0 +1,79 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/lzss.cpp $ + * $Id: lzss.cpp 18 2010-12-17 01:22:54Z clone2727 $ + * + */ + +#include "startrek/lzss.h" +#include "common/util.h" +#include "common/memstream.h" + +namespace StarTrek { + +Common::SeekableReadStream *decodeLZSS(Common::SeekableReadStream *indata, uint32 uncompressedSize) { + uint32 N = 0x1000; /* History buffer size */ + byte *histbuff = new byte[N]; /* History buffer */ + memset(histbuff, 0, N); + uint32 outstreampos = 0; + uint32 bufpos = 0; + byte *outLzssBufData = (byte *)malloc(uncompressedSize); + + for (;;) { + byte flagbyte = indata->readByte(); + + if (indata->eos()) + break; + + for (byte i = 0; i < 8; i++) { + if ((flagbyte & (1 << i)) == 0) { + uint32 offsetlen = indata->readUint16LE(); + + if (indata->eos()) + break; + + uint32 length = (offsetlen & 0xF) + 3; + uint32 offset = (bufpos - (offsetlen >> 4)) & (N - 1); + for (uint32 j = 0; j < length; j++) { + byte tempa = histbuff[(offset + j) & (N - 1)]; + outLzssBufData[outstreampos++] = tempa; + histbuff[bufpos] = tempa; + bufpos = (bufpos + 1) & (N - 1); + } + } else { + byte tempa = indata->readByte(); + + if (indata->eos()) + break; + + outLzssBufData[outstreampos++] = tempa; + histbuff[bufpos] = tempa; + bufpos = (bufpos + 1) & (N - 1); + } + } + } + + delete[] histbuff; + return new Common::MemoryReadStream(outLzssBufData, uncompressedSize, DisposeAfterUse::YES); +} + +} + diff --git a/engines/startrek/lzss.h b/engines/startrek/lzss.h new file mode 100755 index 0000000000..293a6894db --- /dev/null +++ b/engines/startrek/lzss.h @@ -0,0 +1,57 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/lzss.h $ + * $Id: lzss.h 2 2009-09-12 20:13:40Z clone2727 $ + * + */ + +#include "common/stream.h" + +namespace StarTrek { + +Common::SeekableReadStream *decodeLZSS(Common::SeekableReadStream *indata, uint32 uncompressedSize); + +/* +class LzssReadStream : public Common::SeekableReadStream { +private: + uint8 *_outLzssBufData; + uint32 _size; + uint32 _pos; + + uint32 decodeLZSS(Common::ReadStream *in, uint8 lengthmask, uint8 lengthbits); + +public: + LzssReadStream(Common::ReadStream *indata, uint8 lengthmask, uint8 lengthbits); + ~LzssReadStream(); + + bool eos() const; + uint32 read(void *buf, uint32 length); + int32 pos() const { return _pos; } + int32 size() const { return _size; } + bool seek(int32 offset, int whence) { + // TODO + return false; + } + +}; +*/ + +} diff --git a/engines/startrek/module.mk b/engines/startrek/module.mk new file mode 100755 index 0000000000..75878e03f0 --- /dev/null +++ b/engines/startrek/module.mk @@ -0,0 +1,19 @@ +MODULE := engines/startrek + +MODULE_OBJS = \ + detection.o \ + font.o \ + lzss.o \ + graphics.o \ + sound.o \ + startrek.o + + + +# This module can be built as a plugin +ifeq ($(ENABLE_STARTREK), DYNAMIC_PLUGIN) +PLUGIN := 1 +endif + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engines/startrek/sound.cpp b/engines/startrek/sound.cpp new file mode 100755 index 0000000000..114ec8acec --- /dev/null +++ b/engines/startrek/sound.cpp @@ -0,0 +1,192 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/sound.cpp $ + * $Id: sound.cpp 15 2010-06-27 06:13:42Z clone2727 $ + * + */ + +#include "startrek/sound.h" + +#include "common/file.h" +#include "common/macresman.h" + +#include "audio/mods/protracker.h" +#include "audio/decoders/raw.h" + +namespace StarTrek { + +// Main Sound Functions + +Sound::Sound(StarTrekEngine *vm) : _vm(vm) { + if (_vm->getPlatform() == Common::kPlatformDOS || _vm->getPlatform() == Common::kPlatformMacintosh) { + // The main PC versions use XMIDI. ST25 Demo and Macintosh versions use SMF. + if ((_vm->getGameType() == GType_ST25 && _vm->getFeatures() & GF_DEMO) || _vm->getPlatform() == Common::kPlatformMacintosh) + _midiParser = MidiParser::createParser_SMF(); + else + _midiParser = MidiParser::createParser_XMIDI(); + + _midiDevice = MidiDriver::detectDevice(MDT_PCSPK|MDT_ADLIB|MDT_MIDI); + _midiDriver = MidiDriver::createMidi(_midiDevice); + _midiDriver->open(); + _midiParser->setMidiDriver(_midiDriver); + _midiParser->setTimerRate(_midiDriver->getBaseTempo()); + } + + if (_vm->getPlatform() == Common::kPlatformMacintosh) { + _macAudioResFork = new Common::MacResManager(); + if (!_macAudioResFork->open("Star Trek Audio")) + error("Could not open 'Star Trek Audio'"); + assert(_macAudioResFork->hasResFork()); + } else + _macAudioResFork = 0; + + _soundHandle = new Audio::SoundHandle(); +} + +Sound::~Sound() { + delete _midiParser; + delete _midiDriver; + delete _soundHandle; + delete _macAudioResFork; +} + +void Sound::playSound(const char *baseSoundName) { + if (_vm->getPlatform() == Common::kPlatformAmiga) + playAmigaSound(baseSoundName); + else if (_vm->getPlatform() == Common::kPlatformMacintosh) + playMacSMFSound(baseSoundName); + else if (_vm->getFeatures() & GF_DEMO) + playSMFSound(baseSoundName); + else + playXMIDISound(baseSoundName); +} + +void Sound::playSoundEffect(const char *baseSoundName) { + if (_vm->getPlatform() == Common::kPlatformAmiga) + playAmigaSoundEffect(baseSoundName); + else if (_vm->getPlatform() == Common::kPlatformMacintosh) + playMacSoundEffect(baseSoundName); + else + error("PC Sound Effects Not Supported"); +} + +// PC Functions + +void Sound::playSMFSound(const char *baseSoundName) { + Common::String soundName = baseSoundName; + + soundName += '.'; + + switch (MidiDriver::getMusicType(_midiDevice)) { + case MT_MT32: + soundName += "ROL"; + break; + case MT_PCSPK: + return; // Not supported... + default: + soundName += "ADL"; + break; + } + + debug(0, "Playing sound \'%s\'\n", soundName.c_str()); + Common::SeekableReadStream *soundStream = _vm->openFile(soundName.c_str()); + + byte *soundData = (byte *)malloc(soundStream->size()); + soundStream->read(soundData, soundStream->size()); + _midiParser->loadMusic(soundData, soundStream->size()); + delete soundStream; + + _midiDriver->setTimerCallback(_midiParser, MidiParser::timerCallback); +} + +void Sound::playXMIDISound(const char *baseSoundName) { + Common::String soundName = baseSoundName; + + soundName += '.'; + + switch (MidiDriver::getMusicType(_midiDevice)) { + case MT_MT32: + soundName += "MT"; + break; + case MT_PCSPK: + soundName += "PC"; + break; + default: + soundName += "AD"; + break; + } + + debug(0, "Playing sound \'%s\'\n", soundName.c_str()); + Common::SeekableReadStream *soundStream = _vm->openFile(soundName.c_str()); + + byte *soundData = (byte *)malloc(soundStream->size()); + soundStream->read(soundData, soundStream->size()); + _midiParser->loadMusic(soundData, soundStream->size()); + delete soundStream; + + _midiDriver->setTimerCallback(_midiParser, MidiParser::timerCallback); +} + +// Amiga Functions + +void Sound::playAmigaSound(const char *baseSoundName) { + // Nope, this is wrong... see http://protracker.de/files/amiga/formats/theplayer_41_format.txt +#if 0 + Common::String soundName = baseSoundName; + soundName += ".SNG"; + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->stopHandle(*_soundHandle); + _vm->_mixer->playInputStream(Audio::Mixer::kMusicSoundType, _soundHandle, Audio::makeProtrackerStream(_vm->openFile(soundName.c_str()))); +#endif +} + +void Sound::playAmigaSoundEffect(const char *baseSoundName) { + Common::String soundName = baseSoundName; + soundName += ".SFX"; + + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->stopHandle(*_soundHandle); + + Audio::AudioStream *audStream = (Audio::AudioStream *)Audio::makeRawStream(_vm->openFile(soundName.c_str()), 11025, 0); + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _soundHandle, audStream); +} + +// Macintosh Functions + +void Sound::playMacSMFSound(const char *baseSoundName) { + Common::SeekableReadStream *soundStream = _macAudioResFork->getResource(baseSoundName); + byte *soundData = (byte *)malloc(soundStream->size()); + soundStream->read(soundData, soundStream->size()); + _midiParser->loadMusic(soundData, soundStream->size()); + delete soundStream; + + _midiDriver->setTimerCallback(_midiParser, MidiParser::timerCallback); +} + +void Sound::playMacSoundEffect(const char *baseSoundName) { + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->stopHandle(*_soundHandle); + + Audio::AudioStream *audStream = (Audio::AudioStream *)Audio::makeRawStream(_macAudioResFork->getResource(baseSoundName), 11025, 0); + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _soundHandle, audStream); +} + +} // End of namespace StarTrek diff --git a/engines/startrek/sound.h b/engines/startrek/sound.h new file mode 100755 index 0000000000..f8f9b88696 --- /dev/null +++ b/engines/startrek/sound.h @@ -0,0 +1,76 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/sound.h $ + * $Id: sound.h 15 2010-06-27 06:13:42Z clone2727 $ + * + */ + +#ifndef STARTREK_SOUND_H +#define STARTREK_SOUND_H + +#include "startrek/startrek.h" + +#include "audio/midiparser.h" +#include "audio/mididrv.h" +#include "audio/mixer.h" + +namespace Common { + class MacResManager; +} + +namespace StarTrek { + +class StarTrekEngine; + +class Sound { +public: + Sound(StarTrekEngine *vm); + ~Sound(); + + void playSound(const char *baseSoundName); + void playSoundEffect(const char *baseSoundName); + +private: + StarTrekEngine *_vm; + Audio::SoundHandle *_soundHandle; + + // PC Sound Functions + void playXMIDISound(const char *baseSoundName); + void playSMFSound(const char *baseSoundName); + + // Macintosh Sound Functions + void playMacSMFSound(const char *baseSoundName); + void playMacSoundEffect(const char *baseSoundName); + Common::MacResManager *_macAudioResFork; + + // Amiga Sound Functions + void playAmigaSound(const char *baseSoundName); + void playAmigaSoundEffect(const char *baseSoundName); + + // MIDI-Related Variables + MidiParser *_midiParser; + MidiDriver *_midiDriver; + uint32 _midiDevice; +}; + +} + +#endif diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp new file mode 100755 index 0000000000..78b78aacac --- /dev/null +++ b/engines/startrek/startrek.cpp @@ -0,0 +1,318 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/startrek.cpp $ + * $Id: startrek.cpp 17 2010-12-16 02:29:35Z clone2727 $ + * + */ + +#include "base/plugins.h" +#include "base/version.h" +#include "common/archive.h" +#include "common/config-manager.h" +#include "common/error.h" +#include "common/events.h" +#include "common/file.h" +#include "common/macresman.h" +#include "graphics/surface.h" +#include "engines/util.h" +#include "video/qt_decoder.h" + +#include "startrek/lzss.h" +#include "startrek/startrek.h" + +namespace StarTrek { + +StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gamedesc) : Engine(syst), _gameDescription(gamedesc) { + _macResFork = 0; +} + +StarTrekEngine::~StarTrekEngine() { + delete _gfx; + delete _sound; + delete _macResFork; +} + +Common::Error StarTrekEngine::run() { + _gfx = new Graphics(this); + _sound = new Sound(this); + + if (getPlatform() == Common::kPlatformMacintosh) { + _macResFork = new Common::MacResManager(); + if (!_macResFork->open("Star Trek Data")) + error("Could not load Star Trek Data"); + assert(_macResFork->hasDataFork() && _macResFork->hasResFork()); + } + + initGraphics(320, 200); + +// Hexdump data +#if 0 + Common::SeekableReadStream *stream = openFile("BRIDGE.PAL"); + byte *data = (byte *)malloc(stream->size()); + stream->read(data, stream->size()); + Common::hexdump(data, stream->size()); + free(data); + delete stream; +#endif + +// Test graphics/music: + +// Music Status: +// DOS Full: Adlib and MT-32 Sounds supported +// DOS Demo: Adlib and MT-32 Sounds supported +// Amiga: Sound effects supported +// Macintosh: MIDI and sound effects playable, format not handled. + +// Graphics Status: +// DOS/Amiga/Macintosh/Demo Graphics: 100% +// Judgment Rites Backgrounds supported too +// EGA not supported +#if 1 + if (getGameType() == GType_ST25) { + if (getPlatform() == Common::kPlatformMacintosh) { + playMovie("Voice Data/Additional Audio/Intro Movie"); + _gfx->setPalette("BRIDGES.PAL"); + _gfx->drawImage("BRIDGE0.BMP"); + } else { + _gfx->setPalette("BRIDGE.PAL"); + //_gfx->loadEGAData("BRIDGE.EGA"); + _gfx->drawImage("BRIDGE.BMP"); + } + + if (getPlatform() == Common::kPlatformAmiga) + _sound->playSoundEffect("TREK2"); + else if (getPlatform() == Common::kPlatformMacintosh) + _sound->playSound("title 2"); + else if (getFeatures() & GF_DEMO) + _sound->playSound("STTITLE"); + else + _sound->playSound("TITLE"); + } else { + _gfx->drawBackgroundImage("BRIDGE.BGD"); + } + + Common::Event event; + + while (!shouldQuit()) { + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_QUIT: + _system->quit(); + break; + default: + break; + } + } + } +#endif + + return Common::kNoError; +} + +Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename) { + // The Judgment Rites demo has its files not in the standard archive + if (getGameType() == GType_STJR && (getFeatures() & GF_DEMO)) { + Common::File *file = new Common::File(); + if (!file->open(filename.c_str())) + error ("Could not find file \'%s\'", filename.c_str()); + return file; + } + + Common::SeekableReadStream *indexFile = 0; + + if (getPlatform() == Common::kPlatformAmiga) { + indexFile = SearchMan.createReadStreamForMember("data000.dir"); + if (!indexFile) + error ("Could not open data000.dir"); + } else if (getPlatform() == Common::kPlatformMacintosh) { + indexFile = _macResFork->getResource("Directory"); + if (!indexFile) + error("Could not find 'Directory' resource in 'Star Trek Data'"); + } else { + indexFile = SearchMan.createReadStreamForMember("data.dir"); + if (!indexFile) + error ("Could not open data.dir"); + } + + uint32 indexOffset = 0; + bool foundData = false; + uint16 fileCount = 1; + uint16 uncompressedSize = 0; + + while (!indexFile->eos() && !indexFile->err()) { + Common::String testfile; + for (byte i = 0; i < 8; i++) { + char c = indexFile->readByte(); + if (c) + testfile += c; + } + testfile += '.'; + + for (byte i = 0; i < 3; i++) + testfile += indexFile->readByte(); + + if (getFeatures() & GF_DEMO) { + indexFile->readByte(); // Always 0? + fileCount = indexFile->readUint16LE(); // Always 1 + indexOffset = indexFile->readUint32LE(); + uncompressedSize = indexFile->readUint16LE(); + } else { + if (getPlatform() == Common::kPlatformAmiga) + indexOffset = (indexFile->readByte() << 16) + (indexFile->readByte() << 8) + indexFile->readByte(); + else + indexOffset = indexFile->readByte() + (indexFile->readByte() << 8) + (indexFile->readByte() << 16); + + if (indexOffset & (1 << 23)) { + fileCount = (indexOffset >> 16) & 0x7F; + indexOffset = indexOffset & 0xFFFF; + + // TODO: Replace necessary number with ? + } else { + fileCount = 1; + } + } + + if (filename.matchString(testfile)) { + foundData = true; + break; + } + } + + delete indexFile; + + if (!foundData) + error ("Could not find file \'%s\'", filename.c_str()); + + Common::SeekableReadStream *dataFile = 0; + + if (getPlatform() == Common::kPlatformAmiga) { + dataFile = SearchMan.createReadStreamForMember("data.000"); + if (!dataFile) + error("Could not open data.000"); + } else if (getPlatform() == Common::kPlatformMacintosh) { + dataFile = _macResFork->getDataFork(); + if (!dataFile) + error("Could not get 'Star Trek Data' data fork"); + } else { + dataFile = SearchMan.createReadStreamForMember("data.001"); + if (!dataFile) + error("Could not open data.001"); + } + + dataFile->seek(indexOffset); + + if (getFeatures() & GF_DEMO) { + assert(fileCount == 1); // Sanity check... + Common::SeekableReadStream *stream = dataFile->readStream(uncompressedSize); + delete dataFile; + return stream; + } else { + uint16 fileIndex = 0; + + // TODO! + //if (fileCount > 1) + // fileIndex = filename.lastChar() - '0'; + if (fileCount != 1) + error ("Multi-part files not yet handled"); + + for (uint16 i = 0; i < fileCount; i++) { + uncompressedSize = (getPlatform() == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE(); + uint16 compressedSize = (getPlatform() == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE(); + if (i == fileIndex) { + debug(0, "Opening file \'%s\'\n", filename.c_str()); + Common::SeekableReadStream *stream = decodeLZSS(dataFile->readStream(compressedSize), uncompressedSize); + delete dataFile; + return stream; + } else { + dataFile->skip(compressedSize); + } + } + } + + // We should not get to this point... + error("Could not find data for \'%s\'", filename.c_str()); + + return NULL; +} + +byte StarTrekEngine::getStartingIndex(Common::String filename) { + // Find last number + int32 lastNumIndex = -1; + for (uint32 i = 0; i < filename.size(); i++) { + if (filename[i] >= '0' && filename[i] <= '9') + lastNumIndex = i; + else if (filename[i] == '.') + break; + } + + if (lastNumIndex == -1) + return 0; + return (filename[lastNumIndex] - '0'); +} + +void StarTrekEngine::playMovie(Common::String filename) { + if (getPlatform() == Common::kPlatformMacintosh) + playMovieMac(filename); + else + error("Interplay MVE not yet supported"); +} + +void StarTrekEngine::playMovieMac(Common::String filename) { + // Swap to 16bpp mode + initGraphics(512, 384, NULL); + + Video::QuickTimeDecoder *qtDecoder = new Video::QuickTimeDecoder(); + + if (!qtDecoder->loadFile(filename)) + error("Could not open '%s'", filename.c_str()); + + bool continuePlaying = true; + + qtDecoder->start(); + + while (!qtDecoder->endOfVideo() && !shouldQuit() && continuePlaying) { + if (qtDecoder->needsUpdate()) { + const ::Graphics::Surface *frame = qtDecoder->decodeNextFrame(); + + if (frame) { + ::Graphics::Surface *convertedFrame = frame->convertTo(_system->getScreenFormat()); + _system->copyRectToScreen(convertedFrame->getPixels(), convertedFrame->pitch, 0, 0, convertedFrame->w, convertedFrame->h); + _system->updateScreen(); + convertedFrame->free(); + delete convertedFrame; + } + } + + Common::Event event; + while (g_system->getEventManager()->pollEvent(event)) + if (event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) + continuePlaying = false; + + g_system->delayMillis(10); + } + + delete qtDecoder; + + // Swap back to 8bpp mode + initGraphics(320, 200); +} + +} // End of namespace StarTrek diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h new file mode 100755 index 0000000000..f181160b30 --- /dev/null +++ b/engines/startrek/startrek.h @@ -0,0 +1,93 @@ +/* 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. + * + * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/startrek.h $ + * $Id: startrek.h 14 2010-05-26 15:44:12Z clone2727 $ + * + */ + +#ifndef STARTREK_H +#define STARTREK_H + +#include "common/scummsys.h" +#include "common/util.h" +#include "common/system.h" +#include "common/rect.h" +#include "common/str.h" +#include "common/stream.h" + +#include "engines/engine.h" + +#include "startrek/graphics.h" +#include "startrek/sound.h" + +namespace Common { + class MacResManager; +} + +namespace StarTrek { + +enum StarTrekGameType { + GType_ST25 = 1, + GType_STJR = 2 +}; + +enum StarTrekGameFeatures { + GF_DEMO = (1 << 0) +}; + +struct StarTrekGameDescription; +class Graphics; +class Sound; + +class StarTrekEngine : public ::Engine { +protected: + Common::Error run(); + +public: + StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gamedesc); + virtual ~StarTrekEngine(); + + // Detection related functions + const StarTrekGameDescription *_gameDescription; + uint32 getFeatures() const; + uint16 getVersion() const; + Common::Platform getPlatform() const; + uint8 getGameType(); + Common::Language getLanguage(); + + // Resource related functions + Common::SeekableReadStream *openFile(Common::String filename); + + // Movie related functions + void playMovie(Common::String filename); + void playMovieMac(Common::String filename); + +private: + Graphics *_gfx; + Sound *_sound; + Common::MacResManager *_macResFork; + + byte getStartingIndex(Common::String filename); +}; + +} // End of namespace StarTrek + +#endif |