Skip to content

Commit

Permalink
DM: Add sound loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendegúz Nagy committed Aug 26, 2016
1 parent e29d843 commit 22d6973
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 3 deletions.
7 changes: 5 additions & 2 deletions engines/dm/dm.cpp
Expand Up @@ -202,6 +202,9 @@ DMEngine::~DMEngine() {
delete _projexpl;
delete _dialog;

for (uint16 i = 0; i < k34_D13_soundCount; ++i)
delete[] _gK24_soundData[i]._firstSample;

// clear debug channels
DebugMan.clearAllDebugChannels();
}
Expand All @@ -227,7 +230,8 @@ void DMEngine::f463_initializeGame() {
_displayMan->loadPalette(g21_PalDungeonView[0]);
_displayMan->f94_loadFloorSet(k0_FloorSetStone);
_displayMan->f95_loadWallSet(k0_WallSetStone);

f503_loadSounds();
warning(false, "MISSING CODE: F0437_STARTEND_DrawTitle");
_textMan->f54_textInitialize();
_objectMan->loadObjectNames();
_eventMan->initMouse();
Expand Down Expand Up @@ -697,5 +701,4 @@ void DMEngine::f439_drawEntrance() {
_displayMan->f21_blitToScreen(_g562_entranceDoorAnimSteps[4], &G0011_s_Graphic562_Box_Entrance_ClosedDoorRight, k64_byteWidth, kM1_ColorNoTransparency, 161);
warning(false, "MISSING CODE: F0436_STARTEND_FadeToPalette(g20_PalEntrance);");
}

} // End of namespace DM
12 changes: 12 additions & 0 deletions engines/dm/dm.h
Expand Up @@ -195,6 +195,16 @@ struct SaveGameHeader {
};


#define k34_D13_soundCount 34 // @ D13_SOUND_COUNT

class SoundData {
public:
uint32 _byteCount;
byte* _firstSample;
uint32 _sampleCount;
SoundData(): _byteCount(0), _firstSample(nullptr), _sampleCount(0) {}
}; // @ SOUND_DATA

class DMEngine : public Engine {
void f462_startGame(); // @ F0462_START_StartGame_CPSF
void f3_processNewPartyMap(uint16 mapIndex); // @ F0003_MAIN_ProcessNewPartyMap_CPSE
Expand All @@ -206,6 +216,7 @@ class DMEngine : public Engine {
void writeSaveGameHeader(Common::OutSaveFile *out, const Common::String &saveName);
bool readSaveGameHeader(Common::InSaveFile *file, SaveGameHeader *header);
void f439_drawEntrance(); // @ F0439_STARTEND_DrawEntrance
void f503_loadSounds(); // @ F0503_SOUND_LoadAll
public:
explicit DMEngine(OSystem *syst);
~DMEngine();
Expand Down Expand Up @@ -233,6 +244,7 @@ class DMEngine : public Engine {
byte *_g562_entranceDoorAnimSteps[10]; // @ G0562_apuc_Bitmap_EntranceDoorAnimationSteps
byte *_g564_interfaceCredits; // @ G0564_puc_Graphic5_InterfaceCredits
Common::RandomSource *_rnd;
SoundData _gK24_soundData[k34_D13_soundCount]; // @ K0024_as_SoundData
public:
DisplayMan *_displayMan;
DungeonMan *_dungeonMan;
Expand Down
2 changes: 2 additions & 0 deletions engines/dm/gfx.cpp
Expand Up @@ -2642,10 +2642,12 @@ Common::MemoryReadStream DisplayMan::getCompressedData(uint16 index) {
return Common::MemoryReadStream(_packedBitmaps + _packedItemPos[index], getCompressedDataSize(index), DisposeAfterUse::NO);
}


uint32 DisplayMan::getCompressedDataSize(uint16 index) {
return _packedItemPos[index + 1] - _packedItemPos[index];
}


/* Field Aspect Mask */
#define kMaskFieldAspectFlipMask 0x0080 // @ MASK0x0080_FLIP_MASK
#define kMaskFieldAspectIndex 0x007F // @ MASK0x007F_MASK_INDEX
Expand Down
1 change: 0 additions & 1 deletion engines/dm/group.h
Expand Up @@ -149,7 +149,6 @@ class Group {
#define k255_immobile 255 // @ C255_IMMOBILE
#define kM1_wholeCreatureGroup -1 // @ CM1_WHOLE_CREATURE_GROUP

#define k34_D13_soundCount 34 // @ D13_SOUND_COUNT

int32 M32_setTime(int32 &map_time, int32 time); // @ M32_SET_TIME

Expand Down
1 change: 1 addition & 0 deletions engines/dm/module.mk
Expand Up @@ -44,6 +44,7 @@ MODULE_OBJS := \
movesens.o \
objectman.o \
projexpl.o \
sounds.o \
text.o \
timeline.o

Expand Down
99 changes: 99 additions & 0 deletions engines/dm/sounds.cpp
@@ -0,0 +1,99 @@
/* 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.
*
*/

/*
* Based on the Reverse Engineering work of Christophe Fontanel,
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
*/

#include "audio/audiostream.h"
#include "audio/decoders/raw.h"

#include "dm.h"
#include "gfx.h"


namespace DM {

class Sound {
public:
int16 _graphicIndex;
byte _period;
byte _priority;
byte _loudDistance;
byte _softDistance;
Sound(int16 index, byte period, byte priority, byte loudDist, byte softDist) :
_graphicIndex(index), _period(period), _priority(priority), _loudDistance(loudDist), _softDistance(softDist) {}
}; // @ Sound


Sound G0060_as_Graphic562_Sounds[k34_D13_soundCount] = {
Sound(533, 112, 11, 3, 6), /* k00_soundMETALLIC_THUD 0 */
Sound(534, 112, 15, 0, 3), /* k01_soundSWITCH 1 */
Sound(535, 112, 72, 3, 6), /* k02_soundDOOR_RATTLE 2 */
Sound(550, 112, 60, 3, 5), /* k03_soundATTACK_PAIN_RAT_HELLHOUND_RED_DRAGON 3 */
Sound(536, 112, 10, 3, 6), /* k04_soundWOODEN_THUD_ATTACK_TROLIN_ANTMAN_STONE_GOLEM 4 */
Sound(537, 112, 99, 3, 7), /* k05_soundSTRONG_EXPLOSION 5 */
Sound(539, 112, 110, 3, 6), /* k06_soundSCREAM 6 */
Sound(551, 112, 55, 3, 5), /* k07_soundATTACK_MUMMY_GHOST_RIVE 7 */
Sound(540, 112, 2, 3, 6), /* k08_soundSWALLOW 8 */
Sound(541, 112, 80, 3, 6), /* k09_soundCHAMPION_0_DAMAGED 9 */
Sound(542, 112, 82, 3, 6), /* k10_soundCHAMPION_1_DAMAGED 10 */
Sound(543, 112, 84, 3, 6), /* k11_soundCHAMPION_2_DAMAGED 11 */
Sound(544, 112, 86, 3, 6), /* k12_soundCHAMPION_3_DAMAGED 12 */
Sound(545, 112, 95, 3, 6), /* k13_soundSPELL 13 */
Sound(552, 112, 57, 3, 5), /* k14_soundATTACK_SCREAMER_OITU 14 */
Sound(553, 112, 52, 3, 5), /* k15_soundATTACK_GIANT_SCORPION_SCORPION 15 */
Sound(546, 112, 40, 2, 4), /* k16_soundCOMBAT_ATTACK_SKELETON_ANIMATED_ARMOUR_DETH_KNIGHT 16 */
Sound(547, 112, 70, 1, 4), /* k17_soundBUZZ 17 */
Sound(549, 138, 75, 3, 6), /* k18_soundPARTY_DAMAGED 18 */
Sound(554, 112, 50, 3, 5), /* k19_soundATTACK_MAGENTA_WORM_WORM 19 */
Sound(537, 112, 98, 0, 4), /* k20_soundWEAK_EXPLOSION 20 */
Sound(555, 112, 96, 2, 4), /* k21_soundATTACK_GIGGLER 21 */
Sound(563, 138, 24, 0, 4), /* k22_soundMOVE_ANIMATED_ARMOUR_DETH_KNIGHT 22 Atari ST: not present */
Sound(564, 138, 21, 0, 4), /* k23_soundMOVE_COUATL_GIANT_WASP_MUNCHER 23 Atari ST: not present */
Sound(565, 138, 23, 0, 4), /* k24_soundMOVE_MUMMY_TROLIN_ANTMAN_STONE_GOLEM_GIGGLER_VEXIRK_DEMON 24 Atari ST: not present */
Sound(566, 138, 105, 0, 4), /* k25_soundBLOW_HORN 25 Atari ST: not present */
Sound(567, 138, 27, 0, 4), /* k26_soundMOVE_SCREAMER_ROCK_ROCKPILE_MAGENTA_WORM_WORM_PAIN_RAT_HELLHOUND_RUSTER_GIANT_SCORPION_SCORPION_OITU 26 Atari ST: not present */
Sound(568, 138, 28, 0, 4), /* k27_soundMOVE_SWAMP_SLIME_SLIME_DEVIL_WATER_ELEMENTAL 27 Atari ST: not present */
Sound(569, 138, 106, 0, 4), /* k28_soundWAR_CRY 28 Atari ST: not present */
Sound(570, 138, 56, 0, 4), /* k29_soundATTACK_ROCK_ROCKPILE 29 Atari ST: not present */
Sound(571, 138, 58, 0, 4), /* k30_soundATTACK_WATER_ELEMENTAL 30 Atari ST: not present */
Sound(572, 112, 53, 0, 4), /* k31_soundATTACK_COUATL 31 Atari ST: not present */
Sound(573, 138, 29, 0, 4), /* k32_soundMOVE_RED_DRAGON 32 Atari ST: not present */
Sound(574, 150, 22, 0, 4)}; /* k33_soundMOVE_SKELETON 33 Atari ST: not present */

void DMEngine::f503_loadSounds() {
for (uint16 soundIndex = 0; soundIndex < k34_D13_soundCount; ++soundIndex) {
SoundData *soundData = _gK24_soundData + soundIndex;

uint16 graphicIndex = G0060_as_Graphic562_Sounds[soundIndex]._graphicIndex;
soundData->_byteCount = _displayMan->getCompressedDataSize(graphicIndex) - 2; // the header is 2 bytes long
soundData->_firstSample = new byte[soundData->_byteCount];

Common::MemoryReadStream stream = _displayMan->getCompressedData(graphicIndex);
soundData->_sampleCount = stream.readUint16BE();
stream.read(soundData->_firstSample, soundData->_byteCount);
}
}

}

0 comments on commit 22d6973

Please sign in to comment.