├── README.md ├── configure.engine ├── module.mk ├── .gitignore ├── sentences.h ├── console.h ├── sprite.h ├── font.h ├── cryo.h ├── sentences.cpp ├── hsq.h ├── resource.h ├── font.cpp ├── music.h ├── detection.cpp ├── hsq.cpp ├── cryo.cpp ├── resource.cpp ├── sprite.cpp ├── console.cpp ├── music.cpp └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # scummvm-cryo 2 | ScummVM engine for Cryo games 3 | -------------------------------------------------------------------------------- /configure.engine: -------------------------------------------------------------------------------- 1 | # This file is included from the main "configure" script 2 | # add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] 3 | add_engine cryo "Cryo" no 4 | -------------------------------------------------------------------------------- /module.mk: -------------------------------------------------------------------------------- 1 | MODULE := engines/cryo 2 | 3 | MODULE_OBJS := \ 4 | console.o \ 5 | detection.o \ 6 | cryo.o \ 7 | font.o \ 8 | music.o \ 9 | resource.o \ 10 | sentences.o \ 11 | sprite.o \ 12 | hsq.o 13 | 14 | MODULE_DIRS += \ 15 | engines/cryo 16 | 17 | # This module can be built as a plugin 18 | ifeq ($(ENABLE_CRYO), DYNAMIC_PLUGIN) 19 | PLUGIN := 1 20 | endif 21 | 22 | # Include common rules 23 | include $(srcdir)/rules.mk -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.swp 3 | .*.swo 4 | *.o 5 | lib*.a 6 | .deps 7 | 8 | #Ignore XCode user data and build files 9 | xcuserdata 10 | project.xcworkspace 11 | 12 | #ignore thumbnails created by windows 13 | Thumbs.db 14 | #Ignore files build by Visual Studio 15 | *.obj 16 | *.exe 17 | *.pdb 18 | *.user 19 | *.aps 20 | *.pch 21 | *.vspscc 22 | *.ncb 23 | *.suo 24 | *.tlb 25 | *.tlh 26 | *.bak 27 | *.cache 28 | *.ilk 29 | *.log 30 | *.sbr 31 | *.sdf 32 | *.opensdf 33 | *.opendb 34 | obj/ 35 | _ReSharper*/ 36 | ipch/ 37 | [Tt]est[Rr]esult* 38 | *.vcproj 39 | *.sln 40 | *.vsprops 41 | *.props 42 | *.vcxproj* 43 | *.bat 44 | *.tss 45 | 46 | #Ignore default Visual Studio build folders 47 | [Dd]ebug/ 48 | [Rr]elease/ 49 | [Dd]ebug32/ 50 | [Rr]elease32/ 51 | [Dd]ebug64/ 52 | [Rr]elease64/ 53 | LLVM32/ 54 | LLVM64/ 55 | 56 | #Ignore Qt Creator project files 57 | ScummVM.config 58 | ScummVM.creator 59 | ScummVM.files 60 | ScummVM.includes 61 | 62 | #Ignore Komodo IDE/Edit project files 63 | *.komodoproject 64 | 65 | #Ignore Mac DS_Store files 66 | .DS_Store 67 | -------------------------------------------------------------------------------- /sentences.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_SENTENCES_H 24 | #define CRYO_SENTENCES_H 25 | 26 | namespace Cryo { 27 | 28 | class Sentences { 29 | public: 30 | Sentences(Common::String filename, CryoEngine *engine); 31 | ~Sentences(); 32 | 33 | uint16 count() const { return _sentenceCount; } 34 | Common::String getSentence(uint16 index, bool printableOnly = false); 35 | 36 | private: 37 | Common::SeekableReadStream *_stream; 38 | uint16 _sentenceCount; 39 | CryoEngine *_engine; 40 | }; 41 | 42 | } // End of namespace Cryo 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /console.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_CONSOLE_H 24 | #define CRYO_CONSOLE_H 25 | 26 | #include "gui/debugger.h" 27 | 28 | namespace Cryo { 29 | 30 | class CryoEngine; 31 | 32 | class CryoConsole : public GUI::Debugger { 33 | public: 34 | CryoConsole(CryoEngine *vm); 35 | virtual ~CryoConsole(void); 36 | 37 | private: 38 | bool cmdDump(int argc, const char **argv); 39 | bool cmdSentences(int argc, const char **argv); 40 | bool cmdSprite(int argc, const char **argv); 41 | bool cmdSound(int argc, const char **argv); 42 | 43 | CryoEngine *_engine; 44 | }; 45 | 46 | } // End of namespace Cryo 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /sprite.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_SPRITE_H 24 | #define CRYO_SPRITE_H 25 | 26 | #include "cryo/cryo.h" 27 | 28 | namespace Cryo { 29 | 30 | struct FrameInfo { 31 | uint16 offset; 32 | bool isCompressed; 33 | uint16 width; 34 | uint16 height; 35 | int8 palOffset; 36 | }; 37 | 38 | class Sprite { 39 | public: 40 | Sprite(Common::String filename, CryoEngine *engine); 41 | Sprite(Common::SeekableReadStream *stream, CryoEngine *engine); 42 | ~Sprite(); 43 | 44 | void setPalette(); 45 | uint16 getFrameCount(); 46 | FrameInfo getFrameInfo(uint16 frameIndex); 47 | void drawFrame(uint16 frameIndex, uint16 x = 0, uint16 y = 0); 48 | 49 | private: 50 | Common::SeekableReadStream *_stream; 51 | 52 | CryoEngine *_engine; 53 | }; 54 | 55 | } // End of namespace Cryo 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /font.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_FONT_H 24 | #define CRYO_FONT_H 25 | 26 | namespace Cryo { 27 | 28 | class Resource; 29 | class Sprite; 30 | 31 | class FixedFont { 32 | public: 33 | FixedFont(Common::String filename, CryoEngine *engine); 34 | ~FixedFont(); 35 | 36 | void drawText(Common::String text, uint16 x, uint16 y, byte color); 37 | 38 | private: 39 | Common::SeekableReadStream *_stream; 40 | // An array of all the character widths. Each character is 41 | // stored as a bit array, so its width can be 0 - 8 pixels 42 | byte _charWidth[256]; 43 | CryoEngine *_engine; 44 | }; 45 | 46 | class SpriteFont { 47 | public: 48 | SpriteFont(Common::String filename, CryoEngine *engine); 49 | ~SpriteFont(); 50 | 51 | void drawText(Common::String text, uint16 x, uint16 y); 52 | 53 | private: 54 | Sprite *_spr; 55 | }; 56 | 57 | } // End of namespace Cryo 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cryo.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_H 24 | #define CRYO_H 25 | 26 | #include "common/random.h" 27 | 28 | #include "engines/advancedDetector.h" 29 | #include "engines/engine.h" 30 | 31 | #include "gui/debugger.h" 32 | 33 | namespace Cryo { 34 | 35 | class CryoConsole; 36 | class ResourceManager; 37 | 38 | // our engine debug levels 39 | enum { 40 | kQuuxDebugExample = 1 << 0, 41 | kQuuxDebugExample2 = 1 << 1 42 | // next new level must be 1 << 2 (4) 43 | // the current limitation is 32 debug levels (1 << 31 is the last one) 44 | }; 45 | 46 | class CryoEngine : public Engine { 47 | public: 48 | CryoEngine(OSystem *syst, const ADGameDescription *gameDesc); 49 | ~CryoEngine(); 50 | 51 | virtual Common::Error run(); 52 | virtual bool hasFeature(EngineFeature f) const; 53 | 54 | ResourceManager *getResourceManager() const { return _resMan; } 55 | bool isCD(); 56 | 57 | private: 58 | CryoConsole *_console; 59 | ResourceManager *_resMan; 60 | 61 | // We need random numbers 62 | Common::RandomSource* _rnd; 63 | const ADGameDescription *_gameDescription; 64 | }; 65 | 66 | 67 | } // End of namespace Cryo 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /sentences.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/memstream.h" 24 | 25 | #include "cryo/resource.h" 26 | #include "cryo/sentences.h" 27 | 28 | namespace Cryo { 29 | 30 | Sentences::Sentences(Common::String filename, CryoEngine *engine) : _engine(engine) { 31 | ResourceManager *resMan = _engine->getResourceManager(); 32 | _stream = resMan->getResource(filename); 33 | uint16 firstSentence = _stream->readUint16LE(); 34 | _stream->seek(0); 35 | _sentenceCount = firstSentence / 2; 36 | } 37 | 38 | Sentences::~Sentences() { 39 | delete _stream; 40 | } 41 | 42 | Common::String Sentences::getSentence(uint16 index, bool printableOnly) { 43 | assert(index <= _sentenceCount); 44 | 45 | _stream->seek(index * 2); 46 | uint16 start = _stream->readUint16LE(); 47 | _stream->seek(start); 48 | 49 | // Keep reading till we find a 0xFF marker 50 | Common::String sentence; 51 | byte cur = 0; 52 | 53 | while(true) { 54 | cur = _stream->readByte(); 55 | if ((cur == 0x2E || cur == 0x0D) && printableOnly) 56 | continue; 57 | if (cur == 0xFF) 58 | break; 59 | sentence += cur; 60 | } 61 | 62 | return sentence; 63 | } 64 | 65 | } // End of namespace Cryo 66 | -------------------------------------------------------------------------------- /hsq.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_HSQ_STREAM_H 24 | #define CRYO_HSQ_STREAM_H 25 | 26 | #include "common/stream.h" 27 | #include "common/array.h" 28 | 29 | namespace Common { 30 | class SeekableReadStream; 31 | } 32 | 33 | namespace Cryo { 34 | 35 | class HsqReadStream : public Common::ReadStream { 36 | public: 37 | /** 38 | * A class that decompresses HSQ data and implements ReadStream for easy access 39 | * to the decompiled data. 40 | * 41 | * @param source The source data 42 | */ 43 | HsqReadStream(Common::SeekableReadStream *source); 44 | 45 | private: 46 | enum { 47 | BLOCK_SIZE = 0x1000 48 | }; 49 | 50 | private: 51 | Common::SeekableReadStream *_source; 52 | byte _window[BLOCK_SIZE]; 53 | uint _windowCursor; 54 | bool _eosFlag; 55 | 56 | public: 57 | bool eos() const; 58 | uint32 read(void *dataPtr, uint32 dataSize); 59 | 60 | private: 61 | /** 62 | * Decompress the next from the source stream. Or until EOS 63 | * 64 | * @param numberOfBytes How many bytes to decompress. This is a count of source bytes, not destination bytes 65 | */ 66 | uint32 decompressBytes(byte *destination, uint32 numberOfBytes); 67 | }; 68 | 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef CRYO_RESOURCE_H 24 | #define CRYO_RESOURCE_H 25 | 26 | #include "common/memstream.h" 27 | #include "cryo/cryo.h" 28 | 29 | namespace Cryo { 30 | 31 | class Archive; 32 | 33 | class DatArchive : public Common::Archive { 34 | public: 35 | DatArchive(const Common::String &filename); 36 | 37 | virtual bool hasFile(const Common::String &name) const; 38 | virtual int listMembers(Common::ArchiveMemberList &list) const; 39 | virtual const Common::ArchiveMemberPtr getMember(const Common::String &name) const; 40 | virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; 41 | 42 | protected: 43 | Common::SeekableReadStream *_stream; 44 | 45 | struct DatEntry { 46 | uint32 offset; 47 | uint32 size; 48 | char filename[16]; 49 | }; 50 | 51 | typedef Common::HashMap FileMap; 52 | 53 | FileMap _files; 54 | Common::String _datFilename; 55 | }; 56 | 57 | Common::Archive *makeDatArchive(const Common::String &name); 58 | 59 | class ResourceManager { 60 | public: 61 | ResourceManager(bool isCD); 62 | ~ResourceManager(); 63 | 64 | Common::SeekableReadStream *getResource(Common::String fileName); 65 | bool dumpResource(Common::String fileName); 66 | 67 | protected: 68 | void hsqUnpack(Common::SeekableReadStream *inData, byte *outData); 69 | 70 | bool _isCD; 71 | DatArchive *_archive; 72 | }; 73 | 74 | } // End of namespace Cryo 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /font.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/memstream.h" 24 | #include "common/system.h" 25 | 26 | #include "graphics/surface.h" 27 | 28 | #include "cryo/resource.h" 29 | #include "cryo/sprite.h" 30 | #include "cryo/font.h" 31 | 32 | namespace Cryo { 33 | 34 | #define FIXED_FONT_HEIGHT 9 35 | // DOS 437 characters start from ASCII 48 ('0') 36 | // The equivalent ASCII character for '0' in Dune's sprite files is in sprite 15 37 | #define SPRITE_FONT_OFFSET 33 38 | #define SPRITE_FONT_SPACE_WIDTH 16 39 | 40 | #define SCREEN_WIDTH 320 41 | 42 | FixedFont::FixedFont(Common::String filename, CryoEngine *engine) : _engine(engine) { 43 | ResourceManager *resMan = _engine->getResourceManager(); 44 | _stream = resMan->getResource(filename); 45 | _stream->read(_charWidth, 256); 46 | } 47 | 48 | FixedFont::~FixedFont() { 49 | delete _stream; 50 | } 51 | 52 | void FixedFont::drawText(Common::String text, uint16 x, uint16 y, byte color) { 53 | uint16 curX = x; 54 | char curChar; 55 | byte charLine; 56 | byte *dest; 57 | 58 | Graphics::Surface *screen = _engine->_system->lockScreen(); 59 | byte *scr = (byte *)screen->getPixels(); 60 | 61 | for (uint c = 0; c < text.size(); c++) { 62 | dest = scr + y * SCREEN_WIDTH + curX; 63 | curChar = text[c]; 64 | 65 | _stream->seek(256 + curChar * 9); 66 | 67 | for (uint charY = 0; charY < FIXED_FONT_HEIGHT; charY++) { 68 | charLine = _stream->readByte(); 69 | 70 | for (uint charX = 0; charX < _charWidth[(uint8)curChar]; charX++) { 71 | if (charLine & 0x80) 72 | dest[charX] = color; 73 | 74 | charLine <<= 1; 75 | } 76 | 77 | dest += SCREEN_WIDTH; 78 | } 79 | 80 | curX += _charWidth[(uint8)curChar]; 81 | } 82 | 83 | _engine->_system->unlockScreen(); 84 | } 85 | 86 | SpriteFont::SpriteFont(Common::String filename, CryoEngine *engine) { 87 | _spr = new Sprite(filename, engine); 88 | } 89 | 90 | SpriteFont::~SpriteFont() { 91 | delete _spr; 92 | } 93 | 94 | void SpriteFont::drawText(Common::String text, uint16 x, uint16 y) { 95 | uint16 curX = x; 96 | char curChar; 97 | 98 | for (uint i = 0; i < text.size(); i++) { 99 | curChar = text[i]; 100 | 101 | if (curChar == ' ') { 102 | curX += SPRITE_FONT_SPACE_WIDTH; 103 | } else { 104 | _spr->drawFrame(curChar - SPRITE_FONT_OFFSET, curX, y); 105 | curX += _spr->getFrameInfo(curChar - SPRITE_FONT_OFFSET).width; 106 | } 107 | } 108 | } 109 | 110 | } // End of namespace Cryo 111 | -------------------------------------------------------------------------------- /music.h: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | // Music class 24 | 25 | #ifndef CRYO_MUSIC_H 26 | #define CRYO_MUSIC_H 27 | 28 | #include "audio/mididrv.h" 29 | #include "audio/midiparser.h" 30 | #include "audio/mixer.h" 31 | 32 | #include "common/array.h" 33 | #include "common/mutex.h" 34 | 35 | namespace Cryo { 36 | 37 | enum MusicFlags { 38 | MUSIC_NORMAL = 0, 39 | MUSIC_LOOP = 0x0001, 40 | MUSIC_DEFAULT = 0xffff 41 | }; 42 | 43 | class CryoMusicDriver : public MidiDriver { 44 | public: 45 | CryoMusicDriver(); 46 | ~CryoMusicDriver(); 47 | 48 | void setVolume(int volume); 49 | int getVolume() { return _masterVolume; } 50 | 51 | bool isAdlib() { return _driverType == MT_ADLIB; } 52 | bool isMT32() { return _driverType == MT_MT32 || _nativeMT32; } 53 | void setGM(bool isGM) { _isGM = isGM; } 54 | 55 | //MidiDriver interface implementation 56 | int open(); 57 | void close() { _driver->close();} 58 | void send(uint32 b); 59 | bool isOpen(void) const; 60 | 61 | void metaEvent(byte type, byte *data, uint16 length) {} 62 | 63 | void setTimerCallback(void *timerParam, void (*timerProc)(void *)) { _driver->setTimerCallback(timerParam, timerProc); } 64 | uint32 getBaseTempo() { return _driver->getBaseTempo(); } 65 | 66 | //Channel allocation functions 67 | MidiChannel *allocateChannel() { return 0; } 68 | MidiChannel *getPercussionChannel() { return 0; } 69 | 70 | Common::Mutex _mutex; 71 | 72 | protected: 73 | 74 | static void onTimer(void *data); 75 | 76 | MidiChannel *_channel[16]; 77 | MidiDriver *_driver; 78 | MusicType _driverType; 79 | byte _channelVolume[16]; 80 | bool _isGM; 81 | bool _nativeMT32; 82 | 83 | byte _masterVolume; 84 | 85 | byte *_musicData; 86 | uint16 *_buf; 87 | size_t _musicDataSize; 88 | }; 89 | 90 | class CryoMusic { 91 | public: 92 | 93 | CryoMusic(Audio::Mixer *mixer); 94 | ~CryoMusic(); 95 | bool isPlaying(); 96 | 97 | void play(Common::String filename, MusicFlags flags = MUSIC_DEFAULT); 98 | void pause(); 99 | void resume(); 100 | void stop(); 101 | 102 | void setVolume(int volume, int time = 1); 103 | int getVolume() { return _currentVolume; } 104 | 105 | Common::Array _songTable; 106 | 107 | private: 108 | Audio::Mixer *_mixer; 109 | 110 | CryoMusicDriver *_driver; 111 | Audio::SoundHandle _musicHandle; 112 | uint32 _trackNumber; 113 | 114 | int _targetVolume; 115 | int _currentVolume; 116 | int _currentVolumePercent; 117 | 118 | MidiParser *_parser; 119 | byte *_data; 120 | 121 | static void musicVolumeGaugeCallback(void *refCon); 122 | static void onTimer(void *refCon); 123 | void musicVolumeGauge(); 124 | //ByteArray *_currentMusicBuffer; 125 | //ByteArray _musicBuffer[2]; 126 | }; 127 | 128 | } // End of namespace Saga 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /detection.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "engines/advancedDetector.h" 24 | 25 | #include "common/savefile.h" 26 | #include "common/system.h" 27 | #include "common/util.h" 28 | 29 | #include "base/plugins.h" 30 | 31 | #include "cryo/cryo.h" 32 | 33 | static const PlainGameDescriptor cryoGames[] = { 34 | { "dune", "Dune" }, 35 | { 0, 0 } 36 | }; 37 | 38 | 39 | namespace Cryo { 40 | 41 | static const ADGameDescription gameDescriptions[] = { 42 | // English floppy version 43 | { 44 | "dune", 45 | "", 46 | { 47 | {"dunes.hsq", 0, "c290b19cfc87333ed2208fa8ffba655d", 21874}, 48 | {0,0,0,0} 49 | }, 50 | Common::EN_ANY, 51 | Common::kPlatformDOS, 52 | ADGF_NO_FLAGS, 53 | GUIO0() 54 | }, 55 | 56 | // English CD version 57 | { 58 | "dune", 59 | "CD", 60 | { 61 | {"dune.dat", 0, "f096565944ab48cf4cb6cbf389384e6f", 397794384}, 62 | {0,0,0,0} 63 | }, 64 | Common::EN_ANY, 65 | Common::kPlatformDOS, 66 | ADGF_CD, 67 | GUIO0() 68 | }, 69 | 70 | AD_TABLE_END_MARKER 71 | }; 72 | 73 | } // End of namespace Cryo 74 | 75 | /* OLD STYLE 76 | static const ADParams detectionParams = { 77 | // Pointer to ADGameDescription or its superset structure 78 | (const byte *)Cryo::gameDescriptions, 79 | // Size of that superset structure 80 | sizeof(ADGameDescription), 81 | // Number of bytes to compute MD5 sum for 82 | 5000, 83 | // List of all engine targets 84 | cryoGames, 85 | // Structure for autoupgrading obsolete targets 86 | 0, 87 | // Name of single gameid (optional) 88 | "cryo", 89 | // List of files for file-based fallback detection (optional) 90 | 0, 91 | // Flags 92 | 0, 93 | // Additional GUI options (for every game} 94 | GUIO0(), 95 | // Maximum directory depth 96 | 1, 97 | // List of directory globs 98 | 0 99 | }; 100 | */ 101 | 102 | class CryoMetaEngine : public AdvancedMetaEngine { 103 | public: 104 | //OLD STYLE CryoMetaEngine() : AdvancedMetaEngine(detectionParams) {} 105 | //NEW STYLE 106 | CryoMetaEngine() : AdvancedMetaEngine(Cryo::gameDescriptions, sizeof(ADGameDescription), cryoGames) {} 107 | 108 | virtual const char *getName() const { 109 | return "Cryo Engine"; 110 | } 111 | 112 | virtual const char *getOriginalCopyright() const { 113 | return "Cryo Engine (C) Cryo Interactive Entertainment"; 114 | } 115 | 116 | virtual bool hasFeature(MetaEngineFeature f) const; 117 | virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; 118 | }; 119 | 120 | bool CryoMetaEngine::hasFeature(MetaEngineFeature f) const { 121 | return 122 | false; 123 | } 124 | 125 | bool Cryo::CryoEngine::hasFeature(EngineFeature f) const { 126 | return 127 | (f == kSupportsRTL); 128 | } 129 | 130 | bool CryoMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { 131 | if (desc) { 132 | *engine = new Cryo::CryoEngine(syst, desc); 133 | } 134 | return desc != 0; 135 | } 136 | 137 | #if PLUGIN_ENABLED_DYNAMIC(CRYO) 138 | REGISTER_PLUGIN_DYNAMIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine); 139 | #else 140 | REGISTER_PLUGIN_STATIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine); 141 | #endif 142 | -------------------------------------------------------------------------------- /hsq.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/scummsys.h" 24 | 25 | #include "cryo/hsq.h" 26 | 27 | namespace Cryo { 28 | 29 | class BitByteReader { 30 | public: 31 | BitByteReader(Common::SeekableReadStream *data) : _data(data), _curBit(0), _queue(0) { } 32 | 33 | byte getBit() { 34 | if (!_curBit) 35 | refillQueue(); 36 | 37 | byte result = _queue & 0x1; 38 | _queue >>= 1; 39 | _curBit--; 40 | 41 | return result; 42 | } 43 | 44 | byte getByte() { 45 | return _data->readByte(); 46 | } 47 | 48 | private: 49 | void refillQueue() { 50 | _curBit = 16; 51 | _queue = _data->readUint16LE(); 52 | } 53 | 54 | Common::SeekableReadStream *_data; 55 | byte _curBit; 56 | uint16 _queue; 57 | }; 58 | 59 | 60 | HsqReadStream::HsqReadStream(Common::SeekableReadStream *source) 61 | : _source(source), 62 | // It's convention to set the starting cursor position to blockSize - 16 63 | _windowCursor(0x0FEE), 64 | _eosFlag(false) { 65 | // All values up to _windowCursor inits by 0x20 66 | memset(_window, 0x20, _windowCursor); 67 | memset(_window + _windowCursor, 0, BLOCK_SIZE - _windowCursor); 68 | } 69 | 70 | /* The data is organized in a chunks, 18 and more bytes each. 71 | * Every chunk starts with the 2-bytes "header" bitmap, followed 72 | * by 16 or more data bytes. 73 | * The bits in the bitmap specify how to interpret the respective 74 | * data bytes of a chunk. If the subsequent bit in the bitmap is 75 | * set (1), then the corresponding data byte is just copied to an 76 | * output. If the bitmap bit is zero, then the subsequent bitmap 77 | * bits and data bytes are used to locate the sequence in a 78 | * previously extracted data and duplicate it. */ 79 | 80 | uint32 HsqReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) { 81 | uint16 count; 82 | int16 offset; 83 | BitByteReader br(_source); 84 | byte *dst = destination; 85 | 86 | while (true) { 87 | if (br.getBit()) { 88 | /* 1 - just copy one byte */ 89 | *dst++ = br.getByte(); 90 | } else { 91 | if (br.getBit()) { 92 | /* 10 - copy up to 7 bytes of previously extracted 93 | * data, from no more than 8192 bytes behind the 94 | * current extract position. */ 95 | byte low = br.getByte(); 96 | byte high = br.getByte(); 97 | 98 | count = low & 0x7; 99 | offset = ((low >> 3) | (high << 5)) - 8192; 100 | 101 | if (!count) { 102 | /* can copy up to 255 bytes */ 103 | count = br.getByte(); 104 | } 105 | 106 | if (!count) 107 | break; // finish the unpacking 108 | } else { 109 | /* 00 - copy up to 3 bytes from the position not 110 | * further than 256 bytes behind. */ 111 | count = br.getBit() * 2; 112 | count += br.getBit(); 113 | offset = br.getByte() - 256; 114 | } 115 | 116 | count += 2; 117 | 118 | byte *src = dst + offset; 119 | while (count--) 120 | *dst++ = *src++; 121 | } 122 | } 123 | 124 | return dst - destination; 125 | } 126 | 127 | bool HsqReadStream::eos() const { 128 | return _eosFlag; 129 | } 130 | 131 | uint32 HsqReadStream::read(void *dataPtr, uint32 dataSize) { 132 | uint32 bytesRead = decompressBytes(static_cast(dataPtr), dataSize); 133 | if (bytesRead < dataSize) { 134 | // Flag that we're at EOS 135 | _eosFlag = true; 136 | } 137 | 138 | return bytesRead; 139 | } 140 | 141 | } // End of namespace Cryo 142 | -------------------------------------------------------------------------------- /cryo.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/scummsys.h" 24 | 25 | #include "common/config-manager.h" 26 | #include "common/debug.h" 27 | #include "common/debug-channels.h" 28 | #include "gui/EventRecorder.h" 29 | #include "common/file.h" 30 | #include "common/fs.h" 31 | 32 | #include "engines/util.h" 33 | 34 | #include "cryo/console.h" 35 | #include "cryo/cryo.h" 36 | #include "cryo/font.h" 37 | #include "cryo/resource.h" 38 | #include "cryo/sentences.h" 39 | #include "cryo/sprite.h" 40 | 41 | namespace Cryo { 42 | 43 | CryoEngine::CryoEngine(OSystem *syst, const ADGameDescription *gameDesc) 44 | : Engine(syst), _gameDescription(gameDesc) { 45 | // Put your engine in a sane state, but do nothing big yet; 46 | // in particular, do not load data from files; rather, if you 47 | // need to do such things, do them from init(). 48 | 49 | // Do not initialize graphics here 50 | 51 | // However this is the place to specify all default directories 52 | //const Common::FSNode gameDataDir(ConfMan.get("path")); 53 | //SearchMan.addSubDirectoryMatching(gameDataDir, "sound"); 54 | 55 | // Here is the right place to set up the engine specific debug levels 56 | //DebugMan.addDebugChannel(kQuuxDebugExample, "example", "this is just an example for a engine specific debug level"); 57 | //DebugMan.addDebugChannel(kQuuxDebugExample2, "example2", "also an example"); 58 | 59 | // Don't forget to register your random source 60 | //OLDSTYLE 61 | //g_eventRec.registerRandomSource(_rnd, "cryo"); 62 | //NEWSTYLE 63 | _resMan = 0; 64 | _rnd = new Common::RandomSource("cryo_randomseed"); 65 | //debug("CryoEngine::CryoEngine"); 66 | } 67 | 68 | CryoEngine::~CryoEngine() { 69 | // Dispose your resources here 70 | //debug("CryoEngine::~CryoEngine"); 71 | 72 | // Remove all of our debug levels here 73 | delete _resMan; 74 | delete _rnd; 75 | DebugMan.clearAllDebugChannels(); 76 | } 77 | 78 | Common::Error CryoEngine::run() { 79 | // Initialize graphics using following: 80 | initGraphics(320, 200, false); 81 | 82 | // Create debugger console. It requires GFX to be initialized 83 | _console = new CryoConsole(this); 84 | 85 | // Additional setup. 86 | //debug("CryoEngine::init\n"); 87 | 88 | Common::Event event; 89 | Common::EventManager *eventMan = _system->getEventManager(); 90 | 91 | _resMan = new ResourceManager(isCD()); 92 | 93 | // Show something 94 | Sprite *s = new Sprite("intds.hsq", this); 95 | s->setPalette(); 96 | s->drawFrame(0, 0, 92); 97 | delete s; 98 | 99 | SpriteFont *sf = new SpriteFont("generic.hsq", this); 100 | sf->drawText("DUNE TEST", 100, 50); 101 | delete sf; 102 | 103 | Common::String charFile = isCD() ? "dnchar.bin" : "dunechar.hsq"; 104 | FixedFont *f = new FixedFont(charFile, this); 105 | f->drawText("DUNE TEST", 100, 120, 10); 106 | delete f; 107 | 108 | /*Game *g = new Game(_system); 109 | g->loadProtection(); 110 | delete g;*/ 111 | 112 | // Update the screen so that its contents can be shown 113 | _system->updateScreen(); 114 | 115 | // Your main even loop should be (invoked from) here. 116 | //debug("CryoEngine::go: Hello, World!\n"); 117 | while (!shouldQuit()) { 118 | // Open the debugger window, if requested 119 | while (eventMan->pollEvent(event)) { 120 | if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d) { 121 | _console->attach(); 122 | _console->onFrame(); 123 | } 124 | } 125 | 126 | // TODO: Do something... 127 | 128 | _system->delayMillis(10); 129 | } 130 | 131 | // This test will show up if -d1 and --debugflags=example are specified on the commandline 132 | //debugC(1, kQuuxDebugExample, "Example debug call"); 133 | 134 | // This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline 135 | //debugC(3, kQuuxDebugExample | kQuuxDebugExample2, "Example debug call two"); 136 | 137 | return Common::kNoError; 138 | } 139 | 140 | bool CryoEngine::isCD() { 141 | return _gameDescription->flags & ADGF_CD; 142 | } 143 | 144 | } // End of namespace Cryo 145 | -------------------------------------------------------------------------------- /resource.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/file.h" 24 | #include "common/debug.h" 25 | #include "common/substream.h" 26 | #include "common/archive.h" 27 | 28 | #include "cryo/resource.h" 29 | #include "cryo/hsq.h" 30 | 31 | namespace Cryo { 32 | 33 | #define HSQ_PACKED_CHECKSUM 171 34 | 35 | DatArchive::DatArchive(const Common::String &filename) : _datFilename(filename) { 36 | Common::File datFile; 37 | 38 | if (!datFile.open(_datFilename)) { 39 | warning("DatArchive::DatArchive(): Could not find archive file %s", _datFilename.c_str()); 40 | return; 41 | } 42 | 43 | uint16 entries = datFile.readUint16LE(); 44 | 45 | DatEntry entry; 46 | DatEntry *entr; 47 | 48 | for (uint16 i = 0; i < entries; i++) { 49 | datFile.read(&entry.filename, 16); 50 | 51 | entry.size = datFile.readUint32LE(); 52 | entry.offset = datFile.readUint32LE(); 53 | 54 | entr = new DatEntry(entry); 55 | 56 | _files[entry.filename] = entr; 57 | 58 | datFile.readByte(); 59 | //if (_fileTable[i].offset != 0) 60 | // debug("Entry %d: name: %s size: %d offset: %d", i, _fileTable[i].fileName, _fileTable[i].size, _fileTable[i].offset); 61 | } 62 | } 63 | 64 | bool DatArchive::hasFile(const Common::String &name) const { 65 | return _files.contains(name); 66 | } 67 | 68 | int DatArchive::listMembers(Common::ArchiveMemberList &list) const { 69 | int matches = 0; 70 | 71 | FileMap::const_iterator it = _files.begin(); 72 | for ( ; it != _files.end(); ++it) { 73 | list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->filename, this))); 74 | matches++; 75 | } 76 | 77 | return matches; 78 | } 79 | 80 | const Common::ArchiveMemberPtr DatArchive::getMember(const Common::String &name) const { 81 | if (!hasFile(name)) 82 | return Common::ArchiveMemberPtr(); 83 | 84 | return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); 85 | } 86 | 87 | Common::SeekableReadStream *DatArchive::createReadStreamForMember(const Common::String &name) const { 88 | if (!_files.contains(name)) { 89 | return 0; 90 | } 91 | 92 | DatEntry *entry = _files[name]; 93 | 94 | Common::File *archive = new Common::File(); 95 | if (!archive->open(_datFilename)) { 96 | delete archive; 97 | return NULL; 98 | } 99 | 100 | return new Common::SeekableSubReadStream(archive, entry->offset, entry->offset + entry->size, DisposeAfterUse::YES); 101 | } 102 | 103 | Common::Archive *makeDatArchive(const Common::String &name) { 104 | return new DatArchive(name); 105 | } 106 | 107 | 108 | ResourceManager::ResourceManager(bool isCD) : _isCD(isCD) { 109 | if (_isCD) { 110 | _archive = (DatArchive *)makeDatArchive("DUNE.DAT"); 111 | } else { 112 | _archive = 0; 113 | } 114 | } 115 | 116 | ResourceManager::~ResourceManager() { 117 | delete _archive; 118 | } 119 | 120 | Common::SeekableReadStream *ResourceManager::getResource(Common::String fileName) { 121 | Common::SeekableReadStream *rsrc = NULL; 122 | Common::SeekableReadStream *res = NULL; 123 | 124 | if (_isCD) { 125 | rsrc = _archive->createReadStreamForMember(fileName); 126 | } else { 127 | Common::File* file = new Common::File(); 128 | file->open(fileName); 129 | rsrc = file; 130 | } 131 | 132 | if (!rsrc) 133 | error("Could not get file %s", fileName.c_str()); 134 | 135 | byte sum = 0; // sum must be a byte, so that the salt value can overflow it to 0xAB 136 | for (int i = 0; i < 6; i++) 137 | sum += rsrc->readByte(); 138 | 139 | rsrc->seek(0); 140 | 141 | if (sum == HSQ_PACKED_CHECKSUM) { 142 | uint16 unpackedSize = rsrc->readUint16LE(); 143 | assert (rsrc->readByte() == 0); 144 | uint16 packedSize = rsrc->readUint16LE(); 145 | rsrc->readByte(); // Salt byte for checksum 146 | 147 | if (packedSize != rsrc->size()) 148 | error("File %s is corrupt - size is %d, it should be %d", fileName.c_str(), rsrc->size(), packedSize); 149 | 150 | byte *unpackData = new byte[unpackedSize]; 151 | 152 | HsqReadStream hsqStream(rsrc); 153 | uint32 unpacked = hsqStream.read(unpackData, unpackedSize); 154 | res = new Common::MemoryReadStream(unpackData, unpacked, DisposeAfterUse::YES); 155 | } else { 156 | rsrc->seek(0); 157 | res = rsrc; 158 | } 159 | 160 | return res; 161 | } 162 | 163 | bool ResourceManager::dumpResource(Common::String fileName) { 164 | Common::SeekableReadStream *rsrc = getResource(fileName); 165 | uint16 size = rsrc->size(); 166 | 167 | byte *data = new byte[size]; 168 | 169 | rsrc->read(data, size); 170 | 171 | debug("Dumping %s size %d", fileName.c_str(), size); 172 | 173 | Common::DumpFile f; 174 | if (f.open(fileName + ".raw")) { 175 | f.write(data, size); 176 | f.flush(); 177 | f.close(); 178 | } 179 | delete[] data; 180 | 181 | return true; 182 | } 183 | 184 | } // End of namespace Cryo 185 | -------------------------------------------------------------------------------- /sprite.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/memstream.h" 24 | #include "common/system.h" 25 | #include "common/debug.h" 26 | #include "graphics/palette.h" 27 | 28 | #include "cryo/resource.h" 29 | #include "cryo/sprite.h" 30 | 31 | namespace Cryo { 32 | 33 | Sprite::Sprite(Common::String filename, CryoEngine *engine) : _engine(engine) { 34 | ResourceManager *resMan = _engine->getResourceManager(); 35 | _stream = resMan->getResource(filename); 36 | } 37 | 38 | Sprite::Sprite(Common::SeekableReadStream *stream, CryoEngine *engine) : _engine(engine), _stream(stream) { 39 | 40 | } 41 | 42 | Sprite::~Sprite() { 43 | delete _stream; 44 | } 45 | 46 | void Sprite::setPalette() { 47 | // The first chunk is the palette chunk 48 | _stream->seek(0); 49 | uint16 chunkSize = _stream->readUint16LE(); 50 | uint16 curPos = 2; 51 | 52 | if (chunkSize > _stream->size()) 53 | error("Sprite file is corrupted"); 54 | 55 | while (curPos < chunkSize) { 56 | byte palStart = _stream->readByte(); 57 | byte palCount = _stream->readByte(); 58 | 59 | if (palStart == 0xFF && palCount == 0xFF) 60 | break; 61 | 62 | if (palStart == 0 && palCount == 1) { 63 | _stream->seek(3, SEEK_CUR); 64 | continue; 65 | } 66 | 67 | byte *palChunk = new byte[palCount * 3]; // RGB 68 | for (uint i = 0; i < palCount; i++) { 69 | if (i + palStart > 256) 70 | break; 71 | palChunk[i * 3 + 0] = _stream->readByte() << 2; // R 72 | palChunk[i * 3 + 1] = _stream->readByte() << 2; // G 73 | palChunk[i * 3 + 2] = _stream->readByte() << 2; // B 74 | } 75 | _engine->_system->getPaletteManager()->setPalette(palChunk, palStart, palCount); 76 | delete[] palChunk; 77 | } 78 | } 79 | 80 | uint16 Sprite::getFrameCount() { 81 | // The second chunk is the frame chunk, a list of 16-bit offsets 82 | _stream->seek(0); 83 | 84 | uint16 chunkSize = _stream->readUint16LE(); 85 | _stream->seek(chunkSize); 86 | chunkSize = _stream->readUint16LE(); 87 | 88 | return (chunkSize - 2) / 2; 89 | } 90 | 91 | FrameInfo Sprite::getFrameInfo(uint16 frameIndex) { 92 | FrameInfo result; 93 | // First, get the frame count 94 | // This will place the pointer at the start of the frame table 95 | uint16 frameCount = getFrameCount(); 96 | uint16 chunkStart = _stream->pos() - 2; 97 | assert (frameIndex < frameCount); 98 | 99 | // Now, get the offset of the frame 100 | _stream->skip(frameIndex * 2); 101 | result.offset = _stream->readUint16LE(); 102 | _stream->seek(chunkStart + result.offset); 103 | 104 | uint16 infos = _stream->readUint16LE(); 105 | if (infos & 0x4000) 106 | error("Unsupported compression 0x4000 !"); 107 | 108 | if (infos & 0x2000) 109 | error("Unsupported compression 0x2000 !"); 110 | 111 | result.isCompressed = infos & 0x8000; 112 | result.width = infos & 0x01FF; 113 | result.height = _stream->readByte(); 114 | result.palOffset = _stream->readSByte(); 115 | 116 | // width must be divisible by 4 117 | while (result.width % 4 != 0) 118 | result.width++; 119 | 120 | return result; 121 | } 122 | 123 | void Sprite::drawFrame(uint16 frameIndex, uint16 x, uint16 y) { 124 | FrameInfo info = getFrameInfo(frameIndex); 125 | // The pointer is now at the beginning of the frame data 126 | assert (info.width > 0 && info.height > 0); 127 | 128 | uint32 totalSize = info.width * info.height; 129 | 130 | byte *rect = new byte[totalSize]; 131 | memset(rect, 0, totalSize); 132 | byte *dst = rect; 133 | uint32 cur = 0; 134 | byte pixel; 135 | int count; 136 | 137 | if (!info.isCompressed) { 138 | byte *buf = new byte[totalSize / 2]; 139 | _stream->read(buf, totalSize / 2); 140 | while (cur < totalSize) { 141 | pixel = buf[cur / 2]; 142 | // Data is stored in half bytes 143 | *dst++ = (pixel & 0xf) + info.palOffset; 144 | *dst++ = (pixel >> 4) + info.palOffset; 145 | cur += 2; 146 | if (cur >= totalSize) 147 | break; 148 | } 149 | delete[] buf; 150 | } else { 151 | while (cur < totalSize) { 152 | // Data is stored in half bytes, with a simple RLE compression 153 | int8 repetition = _stream->readSByte(); 154 | bool fillSingleValue = (repetition < 0); 155 | count = ((repetition < 0) ? -repetition : repetition) + 1; 156 | pixel = fillSingleValue ? _stream->readByte() : 0; 157 | 158 | for (int i = 0; i < count; i++) { 159 | if (!fillSingleValue) 160 | pixel = _stream->readByte(); 161 | 162 | byte pix1 = pixel & 0xf; 163 | byte pix2 = pixel >> 4; 164 | 165 | if (pix1) { 166 | *dst++ = pix1 + info.palOffset; 167 | } else { 168 | dst++; 169 | } 170 | 171 | if (pix2) { 172 | *dst++ = pix2 + info.palOffset; 173 | } else { 174 | dst++; 175 | } 176 | 177 | cur += 2; 178 | if (cur >= totalSize) 179 | break; 180 | } 181 | } 182 | } 183 | 184 | _engine->_system->copyRectToScreen(rect, info.width, x, y, info.width, info.height); 185 | 186 | delete[] rect; 187 | } 188 | 189 | } // End of namespace Cryo 190 | -------------------------------------------------------------------------------- /console.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #include "common/system.h" 24 | 25 | #include "audio/audiostream.h" 26 | #include "audio/decoders/voc.h" 27 | #include "audio/decoders/raw.h" 28 | #include "audio/mixer.h" 29 | 30 | #include "cryo/console.h" 31 | #include "cryo/cryo.h" 32 | #include "cryo/resource.h" 33 | #include "cryo/sentences.h" 34 | #include "cryo/sprite.h" 35 | 36 | namespace Cryo { 37 | 38 | CryoConsole::CryoConsole(CryoEngine *engine) : GUI::Debugger(), 39 | _engine(engine) { 40 | 41 | registerCmd("dump", WRAP_METHOD(CryoConsole, cmdDump)); 42 | registerCmd("sentences", WRAP_METHOD(CryoConsole, cmdSentences)); 43 | registerCmd("sound", WRAP_METHOD(CryoConsole, cmdSound)); 44 | registerCmd("sprite", WRAP_METHOD(CryoConsole, cmdSprite)); 45 | } 46 | 47 | CryoConsole::~CryoConsole() { 48 | } 49 | 50 | bool CryoConsole::cmdDump(int argc, const char **argv) { 51 | if (argc < 2) { 52 | debugPrintf("Decompresses the given HSQ file into a raw uncompressed file\n"); 53 | debugPrintf(" Usage: %s \n\n", argv[0]); 54 | debugPrintf(" Example: %s phrase11.hsq\n", argv[0]); 55 | debugPrintf(" The above will uncompress phrase11.hsq into phrase11.hsq.raw\n"); 56 | return true; 57 | } 58 | 59 | Common::String fileName(argv[1]); 60 | if (!fileName.contains('.')) 61 | fileName += ".hsq"; 62 | 63 | ResourceManager *resMan = _engine->getResourceManager(); 64 | resMan->dumpResource(fileName); 65 | 66 | debugPrintf("%s has been dumped to %s\n", fileName.c_str(), (fileName + ".raw").c_str()); 67 | return true; 68 | } 69 | 70 | bool CryoConsole::cmdSentences(int argc, const char **argv) { 71 | if (argc < 2) { 72 | debugPrintf("Shows information about a sentence file, or prints a specific sentence from a file\n"); 73 | debugPrintf(" Usage: %s \n\n", argv[0]); 74 | debugPrintf(" Example: \"%s phrase12\" - show information on file phrase12.hsq\n", argv[0]); 75 | debugPrintf(" Example: \"%s phrase12.hsq 0\" - print sentence with index 0 from file phrase12.hsq\n\n", argv[0]); 76 | return true; 77 | } 78 | 79 | Common::String fileName(argv[1]); 80 | if (!fileName.contains('.')) 81 | fileName += ".hsq"; 82 | 83 | Sentences *s = new Sentences(fileName, _engine); 84 | if (argc == 2) { 85 | debugPrintf("File contains %d sentences\n", s->count()); 86 | } else { 87 | if (atoi(argv[2]) >= s->count()) 88 | debugPrintf("Invalid sentence\n"); 89 | else 90 | debugPrintf("%s\n", s->getSentence(atoi(argv[2]), true).c_str()); 91 | } 92 | delete s; 93 | 94 | return true; 95 | } 96 | 97 | bool CryoConsole::cmdSound(int argc, const char **argv) { 98 | if (argc < 2) { 99 | debugPrintf("Plays a sound file (sd*.hsq). Valid sounds are 1-11\n"); 100 | return true; 101 | } 102 | 103 | uint16 soundId = atoi(argv[1]); 104 | if (soundId < 1 || soundId > 11) { 105 | debugPrintf("Invalid sound\n"); 106 | return true; 107 | } 108 | 109 | char filename[10]; 110 | sprintf(filename, "sd%x.hsq", soundId); 111 | 112 | ResourceManager *resMan = _engine->getResourceManager(); 113 | Common::SeekableReadStream& readS = *resMan->getResource(filename); 114 | Audio::SoundHandle handle; 115 | 116 | //NEW STYLE 117 | Audio::RewindableAudioStream *stream = Audio::makeVOCStream(&readS,Audio::FLAG_UNSIGNED); 118 | 119 | 120 | _engine->_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, stream, -1, 255); 121 | 122 | return true; 123 | } 124 | 125 | bool CryoConsole::cmdSprite(int argc, const char **argv) { 126 | if (argc < 2) { 127 | debugPrintf("Shows information about a game sprite (character/background) file\n"); 128 | debugPrintf(" Usage: %s \n\n", argv[0]); 129 | debugPrintf(" Example: \"%s mirror\" - show information on file mirror.hsq\n", argv[0]); 130 | debugPrintf(" Example: \"%s mirror.hsq 0\" - display frame number 0 from mirror.hsq at 0, 0\n", argv[0]); 131 | debugPrintf(" Example: \"%s mirror.hsq 0 100 100\" - display frame number 0 from mirror.hsq at 100, 100\n", argv[0]); 132 | return true; 133 | } 134 | 135 | Common::String fileName(argv[1]); 136 | if (!fileName.contains('.')) 137 | fileName += ".hsq"; 138 | 139 | Sprite *s = new Sprite(fileName, _engine); 140 | bool showConsole = true; 141 | 142 | uint16 frameCount = s->getFrameCount(); 143 | if (argc == 2) { 144 | // Show sprite info 145 | debugPrintf("Frame count: %d\n", frameCount); 146 | for (int i = 0; i < frameCount; i++) { 147 | FrameInfo info = s->getFrameInfo(i); 148 | debugPrintf("%d: offset %d, comp: %d, size: %dx%d, pal offset: %d\n", 149 | i, info.offset, info.isCompressed, info.width, info.height, info.palOffset); 150 | } 151 | } else { 152 | // Draw sprite frame 153 | //TODO: if any part of the sprite is outside of the screen, the game crashes (graphics.cpp assert) 154 | _engine->_system->fillScreen(0); 155 | uint16 frameNumber = atoi(argv[2]); 156 | uint16 x = (argc > 3) ? atoi(argv[3]) : 0; 157 | uint16 y = (argc > 4) ? atoi(argv[4]) : 0; 158 | 159 | if (frameNumber >= frameCount) { 160 | debugPrintf("Invalid frame\n"); 161 | } else { 162 | s->setPalette(); 163 | s->drawFrame(frameNumber, x, y); 164 | showConsole = false; 165 | } 166 | } 167 | 168 | delete s; 169 | 170 | return showConsole; 171 | } 172 | 173 | } // End of namespace Cryo 174 | -------------------------------------------------------------------------------- /music.cpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | // MIDI and digital music class 24 | 25 | #include "cryo/cryo.h" 26 | #include "cryo/resource.h" 27 | #include "cryo/music.h" 28 | 29 | #include "audio/audiostream.h" 30 | #include "audio/mididrv.h" 31 | #include "audio/midiparser.h" 32 | 33 | #include "common/config-manager.h" 34 | #include "common/file.h" 35 | #include "common/substream.h" 36 | 37 | namespace Cryo { 38 | 39 | #define BUFFER_SIZE 4096 40 | #define MUSIC_SUNSPOT 26 41 | 42 | CryoMusicDriver::CryoMusicDriver() : _isGM(false) { 43 | memset(_channel, 0, sizeof(_channel)); 44 | _masterVolume = 0; 45 | _nativeMT32 = ConfMan.getBool("native_mt32"); 46 | 47 | MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); 48 | _driver = MidiDriver::createMidi(dev); 49 | _driverType = MidiDriver::getMusicType(dev); 50 | if (isMT32()) 51 | _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); 52 | 53 | this->open(); 54 | } 55 | 56 | CryoMusicDriver::~CryoMusicDriver() { 57 | this->close(); 58 | delete _driver; 59 | } 60 | 61 | int CryoMusicDriver::open() { 62 | int retValue = _driver->open(); 63 | if (retValue) 64 | return retValue; 65 | 66 | if (_nativeMT32) 67 | _driver->sendMT32Reset(); 68 | else 69 | _driver->sendGMReset(); 70 | 71 | return 0; 72 | } 73 | 74 | bool CryoMusicDriver::isOpen(void) const 75 | { 76 | return (_driver->isOpen()); 77 | } 78 | 79 | 80 | void CryoMusicDriver::setVolume(int volume) { 81 | volume = CLIP(volume, 0, 255); 82 | 83 | if (_masterVolume == volume) 84 | return; 85 | 86 | _masterVolume = volume; 87 | 88 | Common::StackLock lock(_mutex); 89 | 90 | for (int i = 0; i < 16; ++i) { 91 | if (_channel[i]) { 92 | _channel[i]->volume(_channelVolume[i] * _masterVolume / 255); 93 | } 94 | } 95 | } 96 | 97 | void CryoMusicDriver::send(uint32 b) { 98 | byte channel = (byte)(b & 0x0F); 99 | if ((b & 0xFFF0) == 0x07B0) { 100 | // Adjust volume changes by master volume 101 | byte volume = (byte)((b >> 16) & 0x7F); 102 | _channelVolume[channel] = volume; 103 | volume = volume * _masterVolume / 255; 104 | b = (b & 0xFF00FFFF) | (volume << 16); 105 | } else if ((b & 0xF0) == 0xC0 && !_isGM && !isMT32()) { 106 | // Remap MT32 instruments to General Midi 107 | b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; 108 | } else if ((b & 0xFFF0) == 0x007BB0) { 109 | // Only respond to All Notes Off if this channel 110 | // has currently been allocated 111 | if (!_channel[channel]) 112 | return; 113 | } 114 | 115 | if (!_channel[channel]) 116 | _channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); 117 | else 118 | _channel[channel]->send(b); 119 | } 120 | 121 | CryoMusic::CryoMusic(Audio::Mixer *mixer) : _mixer(mixer), _data(0) { 122 | _currentVolume = 0; 123 | //OLD STYLE _driver = new MusicDriver(); 124 | _driver = new CryoMusicDriver(); 125 | 126 | if (!_driver->isAdlib()) { 127 | } 128 | 129 | // TODO: Dune has a custom MIDI format (neither SMF nor XMIDI), 130 | // so a custom parser is needed... thus, die here 131 | error("TODO: Implement parser for the custom MIDI format"); 132 | 133 | _parser = MidiParser::createParser_XMIDI(); 134 | //_parser = MidiParser::createParser_SMF(); 135 | _driver->setGM(false); 136 | 137 | _parser->setMidiDriver(_driver); 138 | _parser->setTimerRate(_driver->getBaseTempo()); 139 | _parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); 140 | } 141 | 142 | CryoMusic::~CryoMusic() { 143 | _mixer->stopHandle(_musicHandle); 144 | _driver->setTimerCallback(NULL, NULL); 145 | delete _driver; 146 | _parser->setMidiDriver(NULL); 147 | delete _parser; 148 | delete _data; 149 | } 150 | 151 | void CryoMusic::musicVolumeGaugeCallback(void *refCon) { 152 | ((CryoMusic *)refCon)->musicVolumeGauge(); 153 | } 154 | 155 | 156 | void CryoMusic::onTimer(void *refCon) { 157 | CryoMusic *music = (CryoMusic *)refCon; 158 | Common::StackLock lock(music->_driver->_mutex); 159 | music->_parser->onTimer(); 160 | } 161 | 162 | void CryoMusic::musicVolumeGauge() { 163 | int volume; 164 | 165 | _currentVolumePercent += 10; 166 | 167 | if (_currentVolume - _targetVolume > 0) { // Volume decrease 168 | volume = _targetVolume + (_currentVolume - _targetVolume) * (100 - _currentVolumePercent) / 100; 169 | } else { 170 | volume = _currentVolume + (_targetVolume - _currentVolume) * _currentVolumePercent / 100; 171 | } 172 | 173 | if (volume < 0) 174 | volume = 1; 175 | 176 | _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume); 177 | _driver->setVolume(volume); 178 | 179 | if (_currentVolumePercent == 100) { 180 | _currentVolume = _targetVolume; 181 | } 182 | } 183 | 184 | void CryoMusic::setVolume(int volume, int time) { 185 | _targetVolume = volume; 186 | _currentVolumePercent = 0; 187 | 188 | if (volume == -1) // Set Full volume 189 | volume = 255; 190 | 191 | if (time == 1) { 192 | _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume); 193 | _driver->setVolume(volume); 194 | _currentVolume = volume; 195 | return; 196 | } 197 | 198 | } 199 | 200 | bool CryoMusic::isPlaying() { 201 | return _mixer->isSoundHandleActive(_musicHandle) || _parser->isPlaying(); 202 | } 203 | 204 | void CryoMusic::play(Common::String filename, MusicFlags flags) { 205 | //TODO: find the new version of function "debug" in the new scummvm 206 | //debug(2, "Music::play %s, %d", filename.c_str(), flags); 207 | 208 | //if (isPlaying() && _trackNumber == resourceId) { 209 | // return; 210 | //} 211 | 212 | //_trackNumber = resourceId; 213 | _mixer->stopHandle(_musicHandle); 214 | _parser->unloadMusic(); 215 | 216 | if (flags == MUSIC_DEFAULT) 217 | flags = MUSIC_NORMAL; 218 | 219 | /*Resource *res = new Resource(filename); 220 | 221 | delete[] _data; 222 | _data = 0; 223 | _data = new byte[res->_stream->size()]; 224 | res->_stream->read(_data, res->_stream->size()); 225 | 226 | if (!_parser->loadMusic(_data, res->_stream->size())) 227 | error("Music::play() wrong music resource"); 228 | 229 | delete res; 230 | 231 | _parser->setTrack(0); 232 | _driver->setTimerCallback(this, &onTimer); 233 | 234 | //setVolume(_vm->_musicVolume); 235 | 236 | // Handle music looping 237 | _parser->property(MidiParser::mpAutoLoop, (flags & MUSIC_LOOP) ? 1 : 0);*/ 238 | } 239 | 240 | void CryoMusic::pause() { 241 | _driver->setTimerCallback(NULL, NULL); 242 | } 243 | 244 | void CryoMusic::resume() { 245 | _driver->setTimerCallback(this, &onTimer); 246 | } 247 | 248 | void CryoMusic::stop() { 249 | _driver->setTimerCallback(NULL, NULL); 250 | _parser->unloadMusic(); 251 | delete[] _data; 252 | _data = 0; 253 | } 254 | 255 | } // End of namespace Cryo 256 | 257 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------