From 890c4c5f41e74938640f4bc8ddb843ac3ca9928d Mon Sep 17 00:00:00 2001 From: athrxx Date: Sat, 26 Jan 2019 22:55:25 +0100 Subject: KYRA: (EOB1/Amiga) - fix start up First efforts to get this running. The intro is shown with severe palette glitches. The Main Menu does not show, thanks to the lack of font drawing. - implement endian aware stream wrapper for amiga files - implement sound file handling - implement some Amiga palette handling - etc --- engines/kyra/sound/drivers/audiomaster2.cpp | 2 +- engines/kyra/sound/sound.h | 6 +- engines/kyra/sound/sound_amiga_eob.cpp | 266 +++++++++------------------- engines/kyra/sound/sound_intern.h | 19 +- engines/kyra/sound/sound_towns_darkmoon.cpp | 26 ++- 5 files changed, 120 insertions(+), 199 deletions(-) (limited to 'engines/kyra/sound') diff --git a/engines/kyra/sound/drivers/audiomaster2.cpp b/engines/kyra/sound/drivers/audiomaster2.cpp index 404bb8468d..3ade175931 100644 --- a/engines/kyra/sound/drivers/audiomaster2.cpp +++ b/engines/kyra/sound/drivers/audiomaster2.cpp @@ -830,7 +830,7 @@ void AudioMaster2ResourceManager::loadResourceFile(Common::SeekableReadStream *d AudioMaster2IFFLoader loader(data, this); Common::Functor1Mem cb(&loader, &AudioMaster2IFFLoader::loadChunk); loader.parse(cb); - } while (data->pos() < data->size()); + } while (data->pos() + 8 < data->size()); } void AudioMaster2ResourceManager::initResource(SoundResource *resource) { diff --git a/engines/kyra/sound/sound.h b/engines/kyra/sound/sound.h index ab0e6a16d1..abeb6050bc 100644 --- a/engines/kyra/sound/sound.h +++ b/engines/kyra/sound/sound.h @@ -67,15 +67,17 @@ struct SoundResourceInfo_TownsPC98V2 { }; struct SoundResourceInfo_TownsEoB { - SoundResourceInfo_TownsEoB(const uint8 *pcmdata, uint dataSize, int pcmvolume) : pcmData(pcmdata), pcmDataSize(dataSize), pcmVolume(pcmvolume) {} + SoundResourceInfo_TownsEoB(const char *const *filelist, uint numfiles, const uint8 *pcmdata, uint pcmdataSize, int pcmvolume) : fileList(filelist), numFiles(numfiles), pcmData(pcmdata), pcmDataSize(pcmdataSize), pcmVolume(pcmvolume) {} const uint8 *pcmData; uint pcmDataSize; int pcmVolume; + const char *const *fileList; + uint numFiles; }; struct SoundResourceInfo_AmigaEoB { - SoundResourceInfo_AmigaEoB(const char *const *files, int numFiles, const char *const *sounds, int numSounds) : fileList(files), fileListSize(numFiles), soundList(sounds), soundListSize(numSounds) {} + SoundResourceInfo_AmigaEoB(const char *const *files, int numFiles, const char *const *soundmap, int numSounds) : fileList(files), fileListSize(numFiles), soundList(soundmap), soundListSize(numSounds) {} const char *const *fileList; uint fileListSize; const char *const *soundList; diff --git a/engines/kyra/sound/sound_amiga_eob.cpp b/engines/kyra/sound/sound_amiga_eob.cpp index 781ec46f4d..de8bf220a1 100644 --- a/engines/kyra/sound/sound_amiga_eob.cpp +++ b/engines/kyra/sound/sound_amiga_eob.cpp @@ -24,13 +24,14 @@ #include "kyra/resource/resource.h" #include "kyra/sound/drivers/audiomaster2.h" +#include "common/config-manager.h" #include "common/memstream.h" namespace Kyra { -SoundAmiga_EoB::SoundAmiga_EoB(KyraEngine_v1 *vm, Audio::Mixer *mixer) : Sound(vm, mixer), _vm(vm), _driver(0), _currentResourceSet(0), _ready(false) { +SoundAmiga_EoB::SoundAmiga_EoB(KyraEngine_v1 *vm, Audio::Mixer *mixer) : Sound(vm, mixer), + _vm(vm), _driver(0), _currentResourceSet(-1), _currentFile(-1), _levelSoundList1(0), _levelSoundList2(0), _ready(false) { _fileBuffer = new uint8[64000]; - _version2 = _vm->game() == GI_EOB2; memset(_resInfo, 0, sizeof(_resInfo)); } @@ -50,6 +51,10 @@ bool SoundAmiga_EoB::init() { if (!_driver->init()) return false; + int temp = 0; + _levelSoundList1 = _vm->staticres()->loadStrings(kEoB1BaseLevelSounds1, temp); + _levelSoundList2 = _vm->staticres()->loadStrings(kEoB1BaseLevelSounds2, temp); + _ready = true; return true; } @@ -60,6 +65,9 @@ void SoundAmiga_EoB::initAudioResourceInfo(int set, void *info) { } void SoundAmiga_EoB::selectAudioResourceSet(int set) { + if (set == _currentResourceSet || !_ready) + return; + _driver->flushAllResources(); if (!_resInfo[set]) return; @@ -70,50 +78,22 @@ void SoundAmiga_EoB::selectAudioResourceSet(int set) { _currentResourceSet = set; } -bool SoundAmiga_EoB::hasSoundFile(uint file) const { - return false; -} - void SoundAmiga_EoB::loadSoundFile(uint file) { - /* - _sound->loadSoundFile("INTRO1.CPS"); - _sound->loadSoundFile("INTRO2.CPS"); - _sound->loadSoundFile("INTRO4.CPS"); - _sound->loadSoundFile("INTRO5.CPS"); - _sound->loadSoundFile("NEWINTRO1.CPS"); - _sound->loadSoundFile("CHARGEN1.CPS"); - - _sound->loadSoundFile("SFX1.CPS"); - _sound->loadSoundFile("SFX2.CPS"); - _sound->loadSoundFile("SFX3.CPS"); - _sound->loadSoundFile("SFX4.CPS"); - - _sound->loadSoundFile("HUM1.CPS"); - - _sound->loadSoundFile("SPIDERMOV1.CPS"); - _sound->loadSoundFile("MOVE1.CPS"); - _sound->loadSoundFile("MOVE21.CPS"); - _sound->loadSoundFile("MOVE31.CPS"); - _sound->loadSoundFile("BEASTATK1.CPS"); - _sound->loadSoundFile("BLADE1.CPS"); - _sound->loadSoundFile("MANTISMOV1.CPS"); - _sound->loadSoundFile("FLAYERATK1.CPS"); - _sound->loadSoundFile("LEECHMOV1.CPS"); - _sound->loadSoundFile("SLOSHSUCK1.CPS"); - _sound->loadSoundFile("SCREAM1.CPS"); - _sound->loadSoundFile("RUSTATK1.CPS"); - _sound->loadSoundFile("HOUNDATK1.CPS"); - _sound->loadSoundFile("KUOTOAMOV1.CPS"); - - _sound->loadSoundFile("FINALE2.CPS"); - _sound->loadSoundFile("FINALE1.CPS"); - _sound->loadSoundFile("FINALE.CPS"); - - for (int i = 1; i < 12; ++i) { - char n[13]; - sprintf(n, "LEVELSAM%d.CPS", i); - _sound->loadSoundFile(n); - }*/ + if (_vm->gameFlags().platform != Common::kPlatformAmiga || _currentResourceSet != kMusicIngame || !_ready) + return; + + unloadLevelSounds(); + + for (int i = 0; i < 2; ++i) { + if (_levelSoundList1[file * 2 + i][0]) + loadSoundFile(Common::String::format("%s.CPS", _levelSoundList1[file * 2 + i])); + if (_levelSoundList2[file * 2 + i][0]) + loadSoundFile(Common::String::format("%s.CPS", _levelSoundList2[file * 2 + i])); + } + + loadSoundFile(Common::String::format("LEVELSAM%d.CPS", file)); + + _currentFile = file; } void SoundAmiga_EoB::loadSoundFile(Common::String file) { @@ -155,157 +135,77 @@ void SoundAmiga_EoB::loadSoundFile(Common::String file) { } void SoundAmiga_EoB::playTrack(uint8 track) { - _driver->startSound("newintro1.smus"); - //_driver->startSound("hum1.sam"); - //_driver->startSound("hum"); - //_driver->startSound("playswing"); - //_driver->startSound("door"); - //_driver->startSound("death"); - //_driver->startSound("teleport"); - //_driver->startSound("scream"); - //_driver->startSound("magica"); - //_driver->startSound("magicb"); - - //_driver->startSound("chargen1.smus"); - //_driver->startSound("finale.smus"); + Common::String newSound; + if (_vm->game() == GI_EOB1) { + if (_currentResourceSet == kMusicIntro) { + if (track == 1) + newSound = "newintro1.smus"; + else if (track == 20) + newSound = "chargen1.smus"; + } + } else if (_vm->game() == GI_EOB2) { + + } + + if (!newSound.empty() && _ready) { + _driver->startSound(newSound); + _lastSound = newSound; + } } void SoundAmiga_EoB::haltTrack() { - + if (!_lastSound.empty()) + _driver->stopSound(_lastSound); } void SoundAmiga_EoB::playSoundEffect(uint8 track, uint8 volume) { + if (_currentResourceSet == -1 || !_ready) + return; + if (!_resInfo[_currentResourceSet]->soundList || track >= 120 || !_sfxEnabled) return; - _driver->startSound(_resInfo[_currentResourceSet]->soundList[track]); - - static const char *const kEoB1SoundsAmiga[120] = { - 0, - "button", - "L1M1A", - "door", - "door", - "slam", - "button", - "button", - "transmute", - "eat", - "magica", - "throw", - "plate", - "passage", - "unlock", - "teleport", - "undead", - "pit", - "itemland", - 0, - 0, - "playhit", - "death", - "text", - "electric", - "dart", - "dart", - "unlock", - "bonus", - "bump", - 0, - "electric", - "playswing", - "hum", - "panel", - "explode", - "L10M2M", - "L10M2A", - "L4M1M", - "beastatk", - "L9M2M", - "L8M1A", - "L8M1M", - "L7M1A", - "L7M1M", - "L5M1A", - "L5M1M", - "flindatk", - "L3M2M", - "L4M1A", - "L8M2M", - "houndatk", - "scream", - "L6M1M", - "L3M1A", - "L3M1M", - "sloshsuck", - "L1M2M", - "flayeratk", - 0, - "rustatk", - "L9M1M", - "L10M1A", - "L10M1M", - "blade", - "L7M2M", - "blade", - "L2M2M", - "L12M2A", - "L12M2M", - 0, - "L11M1M", - "L11M1A", - "L2M1A", - "L2M1M", - "L1M1M", - "button", - 0, - "drop", - "text", - "magicb", - "lock", - 0, - 0, - 0, - "Missile", - 0, - "burnhands", - "electric", - "fireball", - 0, - "magica", - "magica", - "magica", - "magicb", - "magicb", - "acid", - "magicb", - "fireball", - "acid", - "magica", - "magicb", - "magicb", - "undead", - "magica", - "magica", - "magica", - "magicb", - "cause", - "magicb", - "magicb", - "magica", - "magicb", - "magica", - "magica", - "magica", - "magica", - "cause", - 0, - "door" - }; + Common::String newSound = _resInfo[_currentResourceSet]->soundList[track]; + + if (!newSound.empty()) { + _driver->startSound(newSound); + _lastSound = newSound; + } } void SoundAmiga_EoB::beginFadeOut() { + haltTrack(); +} +void SoundAmiga_EoB::updateVolumeSettings() { + if (!_driver || !_ready) + return; + + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + + _driver->setMusicVolume((mute ? 0 : ConfMan.getInt("music_volume"))); + _driver->setSoundEffectVolume((mute ? 0 : ConfMan.getInt("sfx_volume"))); +} + +void SoundAmiga_EoB::unloadLevelSounds() { + if (_currentFile != -1) { + _driver->flushResource(Common::String::format("L%dM1A1", _currentFile)); + _driver->flushResource(Common::String::format("L%dM2A1", _currentFile)); + + for (int i = 1; i < 5; ++i) { + _driver->flushResource(Common::String::format("L%dM1M%d", _currentFile, i)); + _driver->flushResource(Common::String::format("L%dM2M%d", _currentFile, i)); + } + + for (int i = 0; i < 2; ++i) { + if (_levelSoundList1[_currentFile * 2 + i][0]) + _driver->flushResource(_levelSoundList1[_currentFile * 2 + i]); + if (_levelSoundList2[_currentFile * 2 + i][0]) + _driver->flushResource(_levelSoundList2[_currentFile * 2 + i]); + } + } } } // End of namespace Kyra diff --git a/engines/kyra/sound/sound_intern.h b/engines/kyra/sound/sound_intern.h index fccdc03eaf..b6e28dad17 100644 --- a/engines/kyra/sound/sound_intern.h +++ b/engines/kyra/sound/sound_intern.h @@ -363,7 +363,7 @@ public: virtual void initAudioResourceInfo(int set, void *info); virtual void selectAudioResourceSet(int set); virtual bool hasSoundFile(uint file) const; - virtual void loadSoundFile(uint file) {} + virtual void loadSoundFile(uint file); virtual void loadSoundFile(Common::String name); virtual void playTrack(uint8 track); @@ -388,6 +388,9 @@ private: int16 para2; } _soundTable[120]; + const char *const *_fileList; + uint _fileListLen; + uint8 _lastSfxChan; uint8 _lastEnvChan; uint8 *_pcmData; @@ -397,7 +400,7 @@ private: int _timer; int _timerSwitch; - SoundResourceInfo_TownsEoB *_pcmResource[3]; + SoundResourceInfo_TownsEoB *_resource[3]; TownsAudioInterface *_intf; }; @@ -413,23 +416,31 @@ public: bool init(); void initAudioResourceInfo(int set, void *info); void selectAudioResourceSet(int set); - bool hasSoundFile(uint file) const; + bool hasSoundFile(uint file) const { return false; } void loadSoundFile(uint file); void loadSoundFile(Common::String file); void playTrack(uint8 track); void haltTrack(); void playSoundEffect(uint8 track, uint8 volume = 0xFF); void beginFadeOut(); + void updateVolumeSettings(); private: + void unloadLevelSounds(); + uint8 *_fileBuffer; KyraEngine_v1 *_vm; AudioMaster2 *_driver; SoundResourceInfo_AmigaEoB *_resInfo[3]; + Common::String _lastSound; + int _currentResourceSet; + int _currentFile; + + const char *const *_levelSoundList1; + const char *const *_levelSoundList2; - bool _version2; bool _ready; }; diff --git a/engines/kyra/sound/sound_towns_darkmoon.cpp b/engines/kyra/sound/sound_towns_darkmoon.cpp index 25fd4142b9..747e1bd3f4 100644 --- a/engines/kyra/sound/sound_towns_darkmoon.cpp +++ b/engines/kyra/sound/sound_towns_darkmoon.cpp @@ -39,7 +39,7 @@ SoundTowns_Darkmoon::SoundTowns_Darkmoon(KyraEngine_v1 *vm, Audio::Mixer *mixer) _pcmVol = 0; _timer = 0; _timerSwitch = 0; - memset(_pcmResource, 0, sizeof(_pcmResource)); + memset(_resource, 0, sizeof(_resource)); } SoundTowns_Darkmoon::~SoundTowns_Darkmoon() { @@ -85,31 +85,39 @@ void SoundTowns_Darkmoon::timerCallback(int timerId) { } void SoundTowns_Darkmoon::initAudioResourceInfo(int set, void *info) { - delete _pcmResource[set]; - _pcmResource[set] = info ? new SoundResourceInfo_TownsEoB(*(SoundResourceInfo_TownsEoB*)info) : 0; + delete _resource[set]; + _resource[set] = info ? new SoundResourceInfo_TownsEoB(*(SoundResourceInfo_TownsEoB*)info) : 0; } void SoundTowns_Darkmoon::selectAudioResourceSet(int set) { delete[] _pcmData; - if (!_pcmResource[set] || !_pcmResource[kMusicIngame]) + if (!_resource[set] || !_resource[kMusicIngame]) return; - - _pcmDataSize = _pcmResource[kMusicIngame]->pcmDataSize; + + _fileList = _resource[set]->fileList; + _fileListLen = _resource[set]->numFiles; + + _pcmDataSize = _resource[kMusicIngame]->pcmDataSize; _pcmData = new uint8[_pcmDataSize]; - _pcmVol = _pcmResource[set]->pcmVolume; - memcpy(_pcmData, _pcmResource[kMusicIngame]->pcmData, _pcmDataSize); + _pcmVol = _resource[set]->pcmVolume; + memcpy(_pcmData, _resource[kMusicIngame]->pcmData, _pcmDataSize); if (set == kMusicIngame) return; - memcpy(_pcmData, _pcmResource[set]->pcmData, _pcmResource[set]->pcmDataSize); + memcpy(_pcmData, _resource[set]->pcmData, _resource[set]->pcmDataSize); } bool SoundTowns_Darkmoon::hasSoundFile(uint file) const { return true; } +void SoundTowns_Darkmoon::loadSoundFile(uint file) { + if (file < _fileListLen) + loadSoundFile(_fileList[file]); +} + void SoundTowns_Darkmoon::loadSoundFile(Common::String name) { Common::SeekableReadStream *s = _vm->resource()->createReadStream(Common::String::format("%s.SDT", name.c_str())); if (!s) -- cgit v1.2.3