diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cge2/detection.cpp | 13 | ||||
-rw-r--r-- | engines/cge2/spare.cpp | 3 | ||||
-rw-r--r-- | engines/kyra/sound_adlib.cpp | 327 | ||||
-rw-r--r-- | engines/mads/nebular/dialogs_nebular.cpp | 12 | ||||
-rw-r--r-- | engines/mads/nebular/menu_nebular.cpp | 183 | ||||
-rw-r--r-- | engines/mads/nebular/menu_nebular.h | 17 | ||||
-rw-r--r-- | engines/mads/nebular/nebular_scenes.cpp | 2 | ||||
-rw-r--r-- | engines/mads/nebular/sound_nebular.cpp | 307 | ||||
-rw-r--r-- | engines/mads/nebular/sound_nebular.h | 59 | ||||
-rw-r--r-- | engines/mads/scene.cpp | 1 | ||||
-rw-r--r-- | engines/mads/sound.cpp | 3 | ||||
-rw-r--r-- | engines/savestate.h | 2 | ||||
-rw-r--r-- | engines/sci/sound/drivers/midi.cpp | 2 | ||||
-rw-r--r-- | engines/scumm/dialogs.cpp | 4 | ||||
-rw-r--r-- | engines/scumm/script.cpp | 12 | ||||
-rw-r--r-- | engines/scumm/scumm.cpp | 3 | ||||
-rw-r--r-- | engines/scumm/scumm.h | 3 | ||||
-rw-r--r-- | engines/scumm/vars.cpp | 1 | ||||
-rw-r--r-- | engines/sword1/animation.cpp | 2 | ||||
-rw-r--r-- | engines/sword2/animation.cpp | 2 | ||||
-rw-r--r-- | engines/tsage/sound.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/gfx/base_renderer.h | 1 | ||||
-rw-r--r-- | engines/wintermute/utils/utils.cpp | 5 |
23 files changed, 791 insertions, 175 deletions
diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 2b16f8c3b7..7821752f52 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -49,6 +49,17 @@ static const ADGameDescription gameDescriptions[] = { }, Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, + + { + "sfinx", "Freeware v1.0", + { + {"vol.cat", 0, "794a390177c644790df91dc363d808b3", 129024}, + {"vol.dat", 0, "a4c8cff2c432df4b7d4968fea3511001", 34180085}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + }, + AD_TABLE_END_MARKER }; @@ -120,7 +131,7 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, continue; desc.gameid = "sfinx"; - desc.extra = "Translation Alpha v0.1"; + desc.extra = "Translation Alpha v0.2"; desc.language = Common::EN_ANY; desc.platform = Common::kPlatformDOS; desc.flags = ADGF_NO_FLAGS; diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 53f99e4e67..76bdbfa7ef 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -30,8 +30,8 @@ namespace CGE2 { void Spare::sync(Common::Serializer &s) { + int size = 0; if (s.isSaving()) { - int size = 0; for (uint i = 0; i < _container.size(); i++) if (_container[i]->_ref >= 141) size++; @@ -42,7 +42,6 @@ void Spare::sync(Common::Serializer &s) { _container[i]->sync(s); } } else { - int size; s.syncAsSint16LE(size); for (int i = 0; i < size; i++) { diff --git a/engines/kyra/sound_adlib.cpp b/engines/kyra/sound_adlib.cpp index f950f9d5aa..89ee41e859 100644 --- a/engines/kyra/sound_adlib.cpp +++ b/engines/kyra/sound_adlib.cpp @@ -61,7 +61,7 @@ public: ~AdLibDriver(); void initDriver(); - void setSoundData(uint8 *data); + void setSoundData(uint8 *data, uint32 size); void queueTrack(int track, int volume); bool isChannelPlaying(int channel) const; void stopAllChannels(); @@ -130,13 +130,13 @@ private: struct Channel { bool lock; // New to ScummVM uint8 opExtraLevel2; - uint8 *dataptr; + const uint8 *dataptr; uint8 duration; uint8 repeatCounter; int8 baseOctave; uint8 priority; uint8 dataptrStackPos; - uint8 *dataptrStack[4]; + const uint8 *dataptrStack[4]; int8 baseNote; uint8 unk29; uint8 unk31; @@ -194,7 +194,7 @@ private: void setupDuration(uint8 duration, Channel &channel); void setupNote(uint8 rawNote, Channel &channel, bool flag = false); - void setupInstrument(uint8 regOffset, uint8 *dataptr, Channel &channel); + void setupInstrument(uint8 regOffset, const uint8 *dataptr, Channel &channel); void noteOn(Channel &channel); void adjustVolume(Channel &channel); @@ -216,14 +216,24 @@ private: // * One for instruments, starting at offset 500. uint8 *getProgram(int progId) { - uint16 offset = READ_LE_UINT16(_soundData + 2 * progId); - //TODO: Check in LoL CD AdLib driver - if (offset == 0xFFFF) - return 0; - return _soundData + READ_LE_UINT16(_soundData + 2 * progId); + const uint16 offset = READ_LE_UINT16(_soundData + 2 * progId); + + // In case an invalid offset is specified we return nullptr to + // indicate an error. 0xFFFF seems to indicate "this is not a valid + // program/instrument". However, 0 is also invalid because it points + // inside the offset table itself. We also ignore any offsets outside + // of the actual data size. + // The original does not contain any safety checks and will simply + // read outside of the valid sound data in case an invalid offset is + // encountered. + if (offset == 0 || offset >= _soundDataSize) { + return nullptr; + } else { + return _soundData + offset; + } } - uint8 *getInstrument(int instrumentId) { + const uint8 *getInstrument(int instrumentId) { return getProgram(_numPrograms + instrumentId); } @@ -231,7 +241,7 @@ private: void executePrograms(); struct ParserOpcode { - typedef int (AdLibDriver::*POpcode)(uint8 *&dataptr, Channel &channel, uint8 value); + typedef int (AdLibDriver::*POpcode)(const uint8 *&dataptr, Channel &channel, uint8 value); POpcode function; const char *name; }; @@ -240,61 +250,61 @@ private: const ParserOpcode *_parserOpcodeTable; int _parserOpcodeTableSize; - int update_setRepeat(uint8 *&dataptr, Channel &channel, uint8 value); - int update_checkRepeat(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupProgram(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value); - int update_jump(uint8 *&dataptr, Channel &channel, uint8 value); - int update_jumpToSubroutine(uint8 *&dataptr, Channel &channel, uint8 value); - int update_returnFromSubroutine(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setBaseOctave(uint8 *&dataptr, Channel &channel, uint8 value); - int update_stopChannel(uint8 *&dataptr, Channel &channel, uint8 value); - int update_playRest(uint8 *&dataptr, Channel &channel, uint8 value); - int update_writeAdLib(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupNoteAndDuration(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setBaseNote(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); - int update_stopOtherChannel(uint8 *&dataptr, Channel &channel, uint8 value); - int update_waitForEndOfProgram(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupInstrument(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupPrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); - int update_removePrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setBaseFreq(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupPrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setPriority(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback23(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback24(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupDuration(uint8 *&dataptr, Channel &channel, uint8 value); - int update_playNote(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setFractionalNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setTempo(uint8 *&dataptr, Channel &channel, uint8 value); - int update_removeSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setExtraLevel3(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value); - int update_changeExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setAMDepth(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setVibratoDepth(uint8 *&dataptr, Channel &channel, uint8 value); - int update_changeExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback38(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback39(uint8 *&dataptr, Channel &channel, uint8 value); - int update_removePrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value); - int update_pitchBend(uint8 *&dataptr, Channel &channel, uint8 value); - int update_resetToGlobalTempo(uint8 *&dataptr, Channel &channel, uint8 value); - int update_nop(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setDurationRandomness(uint8 *&dataptr, Channel &channel, uint8 value); - int update_changeChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback46(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setupRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value); - int update_playRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value); - int update_removeRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback51(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback52(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback53(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setSoundTrigger(uint8 *&dataptr, Channel &channel, uint8 value); - int update_setTempoReset(uint8 *&dataptr, Channel &channel, uint8 value); - int updateCallback56(uint8 *&dataptr, Channel &channel, uint8 value); + int update_setRepeat(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_checkRepeat(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupProgram(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setNoteSpacing(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_jump(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_jumpToSubroutine(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_returnFromSubroutine(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setBaseOctave(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_stopChannel(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_playRest(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_writeAdLib(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupNoteAndDuration(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setBaseNote(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupSecondaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_stopOtherChannel(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_waitForEndOfProgram(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupInstrument(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupPrimaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_removePrimaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setBaseFreq(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupPrimaryEffect2(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setPriority(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback23(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback24(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setExtraLevel1(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupDuration(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_playNote(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setFractionalNoteSpacing(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setTempo(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_removeSecondaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setChannelTempo(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setExtraLevel3(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setExtraLevel2(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_changeExtraLevel2(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setAMDepth(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setVibratoDepth(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_changeExtraLevel1(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback38(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback39(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_removePrimaryEffect2(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_pitchBend(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_resetToGlobalTempo(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_nop(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setDurationRandomness(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_changeChannelTempo(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback46(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setupRhythmSection(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_playRhythmSection(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_removeRhythmSection(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback51(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback52(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback53(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setSoundTrigger(const uint8 *&dataptr, Channel &channel, uint8 value); + int update_setTempoReset(const uint8 *&dataptr, Channel &channel, uint8 value); + int updateCallback56(const uint8 *&dataptr, Channel &channel, uint8 value); private: // These variables have not yet been named, but some of them are partly // known nevertheless: @@ -358,6 +368,7 @@ private: FM_OPL *_adlib; uint8 *_soundData; + uint32 _soundDataSize; struct QueueEntry { QueueEntry() : data(0), id(0), volume(0) {} @@ -421,6 +432,7 @@ AdLibDriver::AdLibDriver(Audio::Mixer *mixer, int version) { memset(_channels, 0, sizeof(_channels)); _soundData = 0; + _soundDataSize = 0; _vibratoAndAMDepthBits = _curRegOffset = 0; @@ -522,7 +534,7 @@ void AdLibDriver::initDriver() { resetAdLibState(); } -void AdLibDriver::setSoundData(uint8 *data) { +void AdLibDriver::setSoundData(uint8 *data, uint32 size) { Common::StackLock lock(_mutex); // Drop all tracks that are still queued. These would point to the old @@ -536,6 +548,7 @@ void AdLibDriver::setSoundData(uint8 *data) { } _soundData = data; + _soundDataSize = size; } void AdLibDriver::queueTrack(int track, int volume) { @@ -791,7 +804,7 @@ void AdLibDriver::executePrograms() { // This fixes a subtle music bug where the // wrong music would play when getting the // quill in Kyra 1. - uint8 *dataptr = channel.dataptr; + const uint8 *dataptr = channel.dataptr; while (dataptr) { uint8 opcode = *dataptr++; uint8 param = *dataptr++; @@ -1030,7 +1043,7 @@ void AdLibDriver::setupNote(uint8 rawNote, Channel &channel, bool flag) { writeOPL(0xB0 + _curChannel, channel.regBx); } -void AdLibDriver::setupInstrument(uint8 regOffset, uint8 *dataptr, Channel &channel) { +void AdLibDriver::setupInstrument(uint8 regOffset, const uint8 *dataptr, Channel &channel) { debugC(9, kDebugLevelSound, "setupInstrument(%d, %p, %lu)", regOffset, (const void *)dataptr, (long)(&channel - _channels)); if (_curChannel >= 9) @@ -1340,12 +1353,12 @@ uint8 AdLibDriver::calculateOpLevel2(Channel &channel) { // parser opcodes -int AdLibDriver::update_setRepeat(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setRepeat(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.repeatCounter = value; return 0; } -int AdLibDriver::update_checkRepeat(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_checkRepeat(const uint8 *&dataptr, Channel &channel, uint8 value) { ++dataptr; if (--channel.repeatCounter) { int16 add = READ_LE_UINT16(dataptr - 2); @@ -1354,14 +1367,23 @@ int AdLibDriver::update_checkRepeat(uint8 *&dataptr, Channel &channel, uint8 val return 0; } -int AdLibDriver::update_setupProgram(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupProgram(const uint8 *&dataptr, Channel &channel, uint8 value) { if (value == 0xFF) return 0; - uint8 *ptr = getProgram(value); - //TODO: Check in LoL CD AdLib driver - if (!ptr) + const uint8 *ptr = getProgram(value); + + // In case we encounter an invalid program we simply ignore it and do + // nothing instead. The original did not care about invalid programs and + // simply tried to play them anyway... But to avoid crashes due we ingore + // them. + // This, for example, happens in the Lands of Lore intro when Scotia gets + // the ring in the intro. + if (!ptr) { + debugC(3, kDebugLevelSound, "AdLibDriver::update_setupProgram: Invalid program %d specified", value); return 0; + } + uint8 chan = *ptr++; uint8 priority = *ptr++; @@ -1390,12 +1412,12 @@ int AdLibDriver::update_setupProgram(uint8 *&dataptr, Channel &channel, uint8 va return 0; } -int AdLibDriver::update_setNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setNoteSpacing(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.spacing1 = value; return 0; } -int AdLibDriver::update_jump(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_jump(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; int16 add = READ_LE_UINT16(dataptr); dataptr += 2; if (_version == 1) @@ -1407,7 +1429,7 @@ int AdLibDriver::update_jump(uint8 *&dataptr, Channel &channel, uint8 value) { return 0; } -int AdLibDriver::update_jumpToSubroutine(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_jumpToSubroutine(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; int16 add = READ_LE_UINT16(dataptr); dataptr += 2; channel.dataptrStack[channel.dataptrStackPos++] = dataptr; @@ -1418,17 +1440,17 @@ int AdLibDriver::update_jumpToSubroutine(uint8 *&dataptr, Channel &channel, uint return 0; } -int AdLibDriver::update_returnFromSubroutine(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_returnFromSubroutine(const uint8 *&dataptr, Channel &channel, uint8 value) { dataptr = channel.dataptrStack[--channel.dataptrStackPos]; return 0; } -int AdLibDriver::update_setBaseOctave(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setBaseOctave(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.baseOctave = value; return 0; } -int AdLibDriver::update_stopChannel(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_stopChannel(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.priority = 0; if (_curChannel != 9) noteOff(channel); @@ -1436,30 +1458,30 @@ int AdLibDriver::update_stopChannel(uint8 *&dataptr, Channel &channel, uint8 val return 2; } -int AdLibDriver::update_playRest(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_playRest(const uint8 *&dataptr, Channel &channel, uint8 value) { setupDuration(value, channel); noteOff(channel); return (value != 0); } -int AdLibDriver::update_writeAdLib(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_writeAdLib(const uint8 *&dataptr, Channel &channel, uint8 value) { writeOPL(value, *dataptr++); return 0; } -int AdLibDriver::update_setupNoteAndDuration(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupNoteAndDuration(const uint8 *&dataptr, Channel &channel, uint8 value) { setupNote(value, channel); value = *dataptr++; setupDuration(value, channel); return (value != 0); } -int AdLibDriver::update_setBaseNote(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setBaseNote(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.baseNote = value; return 0; } -int AdLibDriver::update_setupSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupSecondaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.unk18 = value; channel.unk19 = value; channel.unk20 = channel.unk21 = *dataptr++; @@ -1483,7 +1505,7 @@ int AdLibDriver::update_setupSecondaryEffect1(uint8 *&dataptr, Channel &channel, return 0; } -int AdLibDriver::update_stopOtherChannel(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_stopOtherChannel(const uint8 *&dataptr, Channel &channel, uint8 value) { Channel &channel2 = _channels[value]; channel2.duration = 0; channel2.priority = 0; @@ -1491,8 +1513,16 @@ int AdLibDriver::update_stopOtherChannel(uint8 *&dataptr, Channel &channel, uint return 0; } -int AdLibDriver::update_waitForEndOfProgram(uint8 *&dataptr, Channel &channel, uint8 value) { - uint8 *ptr = getProgram(value); +int AdLibDriver::update_waitForEndOfProgram(const uint8 *&dataptr, Channel &channel, uint8 value) { + const uint8 *ptr = getProgram(value); + + // Safety check in case an invalid program is specified. This would make + // getProgram return a nullptr and thus cause invalid memory reads. + if (!ptr) { + debugC(3, kDebugLevelSound, "AdLibDriver::update_waitForEndOfProgram: Invalid program %d specified", value); + return 0; + } + uint8 chan = *ptr; if (!_channels[chan].dataptr) @@ -1502,12 +1532,25 @@ int AdLibDriver::update_waitForEndOfProgram(uint8 *&dataptr, Channel &channel, u return 2; } -int AdLibDriver::update_setupInstrument(uint8 *&dataptr, Channel &channel, uint8 value) { - setupInstrument(_curRegOffset, getInstrument(value), channel); +int AdLibDriver::update_setupInstrument(const uint8 *&dataptr, Channel &channel, uint8 value) { + const uint8 *instrument = getInstrument(value); + + // We add a safety check to avoid setting up invalid instruments. This is + // not done in the original. However, to avoid crashes due to invalid + // memory reads we simply ignore the request. + // This happens, for example, in Hand of Fate when using the swampsnake + // potion on Zanthia to scare off the rat in the cave in the first chapter + // of the game. + if (!instrument) { + debugC(3, kDebugLevelSound, "AdLibDriver::update_setupInstrument: Invalid instrument %d specified", value); + return 0; + } + + setupInstrument(_curRegOffset, instrument, channel); return 0; } -int AdLibDriver::update_setupPrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupPrimaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.unk29 = value; channel.unk30 = READ_BE_UINT16(dataptr); dataptr += 2; @@ -1516,19 +1559,19 @@ int AdLibDriver::update_setupPrimaryEffect1(uint8 *&dataptr, Channel &channel, u return 0; } -int AdLibDriver::update_removePrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_removePrimaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; channel.primaryEffect = 0; channel.unk30 = 0; return 0; } -int AdLibDriver::update_setBaseFreq(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setBaseFreq(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.baseFreq = value; return 0; } -int AdLibDriver::update_setupPrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupPrimaryEffect2(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.unk32 = value; channel.unk33 = *dataptr++; uint8 temp = *dataptr++; @@ -1539,12 +1582,12 @@ int AdLibDriver::update_setupPrimaryEffect2(uint8 *&dataptr, Channel &channel, u return 0; } -int AdLibDriver::update_setPriority(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setPriority(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.priority = value; return 0; } -int AdLibDriver::updateCallback23(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback23(const uint8 *&dataptr, Channel &channel, uint8 value) { value >>= 1; _unkValue1 = _unkValue2 = value; _callbackTimer = 0xFF; @@ -1552,7 +1595,7 @@ int AdLibDriver::updateCallback23(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::updateCallback24(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback24(const uint8 *&dataptr, Channel &channel, uint8 value) { if (_unkValue5) { if (_unkValue4 & value) { _unkValue5 = 0; @@ -1568,50 +1611,50 @@ int AdLibDriver::updateCallback24(uint8 *&dataptr, Channel &channel, uint8 value return 2; } -int AdLibDriver::update_setExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setExtraLevel1(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.opExtraLevel1 = value; adjustVolume(channel); return 0; } -int AdLibDriver::update_setupDuration(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupDuration(const uint8 *&dataptr, Channel &channel, uint8 value) { setupDuration(value, channel); return (value != 0); } -int AdLibDriver::update_playNote(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_playNote(const uint8 *&dataptr, Channel &channel, uint8 value) { setupDuration(value, channel); noteOn(channel); return (value != 0); } -int AdLibDriver::update_setFractionalNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setFractionalNoteSpacing(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.fractionalSpacing = value & 7; return 0; } -int AdLibDriver::update_setTempo(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setTempo(const uint8 *&dataptr, Channel &channel, uint8 value) { _tempo = value; return 0; } -int AdLibDriver::update_removeSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_removeSecondaryEffect1(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; channel.secondaryEffect = 0; return 0; } -int AdLibDriver::update_setChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setChannelTempo(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.tempo = value; return 0; } -int AdLibDriver::update_setExtraLevel3(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setExtraLevel3(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.opExtraLevel3 = value; return 0; } -int AdLibDriver::update_setExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setExtraLevel2(const uint8 *&dataptr, Channel &channel, uint8 value) { int channelBackUp = _curChannel; _curChannel = value; @@ -1623,7 +1666,7 @@ int AdLibDriver::update_setExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 return 0; } -int AdLibDriver::update_changeExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_changeExtraLevel2(const uint8 *&dataptr, Channel &channel, uint8 value) { int channelBackUp = _curChannel; _curChannel = value; @@ -1638,7 +1681,7 @@ int AdLibDriver::update_changeExtraLevel2(uint8 *&dataptr, Channel &channel, uin // Apart from initializing to zero, these two functions are the only ones that // modify _vibratoAndAMDepthBits. -int AdLibDriver::update_setAMDepth(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setAMDepth(const uint8 *&dataptr, Channel &channel, uint8 value) { if (value & 1) _vibratoAndAMDepthBits |= 0x80; else @@ -1648,7 +1691,7 @@ int AdLibDriver::update_setAMDepth(uint8 *&dataptr, Channel &channel, uint8 valu return 0; } -int AdLibDriver::update_setVibratoDepth(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setVibratoDepth(const uint8 *&dataptr, Channel &channel, uint8 value) { if (value & 1) _vibratoAndAMDepthBits |= 0x40; else @@ -1658,13 +1701,13 @@ int AdLibDriver::update_setVibratoDepth(uint8 *&dataptr, Channel &channel, uint8 return 0; } -int AdLibDriver::update_changeExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_changeExtraLevel1(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.opExtraLevel1 += value; adjustVolume(channel); return 0; } -int AdLibDriver::updateCallback38(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback38(const uint8 *&dataptr, Channel &channel, uint8 value) { int channelBackUp = _curChannel; _curChannel = value; @@ -1693,7 +1736,7 @@ int AdLibDriver::updateCallback38(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::updateCallback39(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback39(const uint8 *&dataptr, Channel &channel, uint8 value) { if (_curChannel >= 9) return 0; @@ -1714,35 +1757,35 @@ int AdLibDriver::updateCallback39(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::update_removePrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_removePrimaryEffect2(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; channel.primaryEffect = 0; return 0; } -int AdLibDriver::update_pitchBend(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_pitchBend(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.pitchBend = value; setupNote(channel.rawNote, channel, true); return 0; } -int AdLibDriver::update_resetToGlobalTempo(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_resetToGlobalTempo(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; channel.tempo = _tempo; return 0; } -int AdLibDriver::update_nop(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_nop(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; return 0; } -int AdLibDriver::update_setDurationRandomness(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setDurationRandomness(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.durationRandomness = value; return 0; } -int AdLibDriver::update_changeChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_changeChannelTempo(const uint8 *&dataptr, Channel &channel, uint8 value) { int tempo = channel.tempo + (int8)value; if (tempo <= 0) @@ -1754,7 +1797,7 @@ int AdLibDriver::update_changeChannelTempo(uint8 *&dataptr, Channel &channel, ui return 0; } -int AdLibDriver::updateCallback46(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback46(const uint8 *&dataptr, Channel &channel, uint8 value) { uint8 entry = *dataptr++; _tablePtr1 = _unkTable2[entry++]; _tablePtr2 = _unkTable2[entry]; @@ -1765,27 +1808,43 @@ int AdLibDriver::updateCallback46(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::update_setupRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setupRhythmSection(const uint8 *&dataptr, Channel &channel, uint8 value) { int channelBackUp = _curChannel; int regOffsetBackUp = _curRegOffset; _curChannel = 6; _curRegOffset = _regOffset[6]; - setupInstrument(_curRegOffset, getInstrument(value), channel); + const uint8 *instrument; + instrument = getInstrument(value); + if (instrument) { + setupInstrument(_curRegOffset, instrument, channel); + } else { + debugC(3, kDebugLevelSound, "AdLibDriver::update_setupRhythmSection: Invalid instrument %d for channel 6 specified", value); + } _unkValue6 = channel.opLevel2; _curChannel = 7; _curRegOffset = _regOffset[7]; - setupInstrument(_curRegOffset, getInstrument(*dataptr++), channel); + instrument = getInstrument(*dataptr++); + if (instrument) { + setupInstrument(_curRegOffset, instrument, channel); + } else { + debugC(3, kDebugLevelSound, "AdLibDriver::update_setupRhythmSection: Invalid instrument %d for channel 7 specified", value); + } _unkValue7 = channel.opLevel1; _unkValue8 = channel.opLevel2; _curChannel = 8; _curRegOffset = _regOffset[8]; - setupInstrument(_curRegOffset, getInstrument(*dataptr++), channel); + instrument = getInstrument(*dataptr++); + if (instrument) { + setupInstrument(_curRegOffset, instrument, channel); + } else { + debugC(3, kDebugLevelSound, "AdLibDriver::update_setupRhythmSection: Invalid instrument %d for channel 8 specified", value); + } _unkValue9 = channel.opLevel1; _unkValue10 = channel.opLevel2; @@ -1810,7 +1869,7 @@ int AdLibDriver::update_setupRhythmSection(uint8 *&dataptr, Channel &channel, ui return 0; } -int AdLibDriver::update_playRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_playRhythmSection(const uint8 *&dataptr, Channel &channel, uint8 value) { // Any instrument that we want to play, and which was already playing, // is temporarily keyed off. Instruments that were off already, or // which we don't want to play, retain their old on/off status. This is @@ -1830,7 +1889,7 @@ int AdLibDriver::update_playRhythmSection(uint8 *&dataptr, Channel &channel, uin return 0; } -int AdLibDriver::update_removeRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_removeRhythmSection(const uint8 *&dataptr, Channel &channel, uint8 value) { --dataptr; _rhythmSectionBits = 0; @@ -1841,7 +1900,7 @@ int AdLibDriver::update_removeRhythmSection(uint8 *&dataptr, Channel &channel, u return 0; } -int AdLibDriver::updateCallback51(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback51(const uint8 *&dataptr, Channel &channel, uint8 value) { uint8 value2 = *dataptr++; if (value & 1) { @@ -1882,7 +1941,7 @@ int AdLibDriver::updateCallback51(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::updateCallback52(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback52(const uint8 *&dataptr, Channel &channel, uint8 value) { uint8 value2 = *dataptr++; if (value & 1) { @@ -1923,7 +1982,7 @@ int AdLibDriver::updateCallback52(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::updateCallback53(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback53(const uint8 *&dataptr, Channel &channel, uint8 value) { uint8 value2 = *dataptr++; if (value & 1) { @@ -1964,17 +2023,17 @@ int AdLibDriver::updateCallback53(uint8 *&dataptr, Channel &channel, uint8 value return 0; } -int AdLibDriver::update_setSoundTrigger(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setSoundTrigger(const uint8 *&dataptr, Channel &channel, uint8 value) { _soundTrigger = value; return 0; } -int AdLibDriver::update_setTempoReset(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::update_setTempoReset(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.tempoReset = value; return 0; } -int AdLibDriver::updateCallback56(uint8 *&dataptr, Channel &channel, uint8 value) { +int AdLibDriver::updateCallback56(const uint8 *&dataptr, Channel &channel, uint8 value) { channel.unk39 = value; channel.unk40 = *dataptr++; return 0; @@ -2487,13 +2546,13 @@ void SoundAdLibPC::internalLoadFile(Common::String file) { _soundDataPtr = new uint8[soundDataSize]; assert(_soundDataPtr); - memcpy(_soundDataPtr, p, soundDataSize*sizeof(uint8)); + memcpy(_soundDataPtr, p, soundDataSize); delete[] fileData; fileData = p = 0; fileSize = 0; - _driver->setSoundData(_soundDataPtr); + _driver->setSoundData(_soundDataPtr, soundDataSize); _soundFileLoaded = file; } diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp index f3eddc3fbb..5b0fb7b538 100644 --- a/engines/mads/nebular/dialogs_nebular.cpp +++ b/engines/mads/nebular/dialogs_nebular.cpp @@ -313,6 +313,18 @@ void DialogsNebular::showDialog() { delete dlg; break; } + case DIALOG_TEXTVIEW: { + TextView *dlg = new TextView(_vm); + dlg->show(); + delete dlg; + break; + } + case DIALOG_ANIMVIEW: { + AnimationView *dlg = new AnimationView(_vm); + dlg->show(); + delete dlg; + break; + } default: break; } diff --git a/engines/mads/nebular/menu_nebular.cpp b/engines/mads/nebular/menu_nebular.cpp index 98eb669616..aa14353092 100644 --- a/engines/mads/nebular/menu_nebular.cpp +++ b/engines/mads/nebular/menu_nebular.cpp @@ -24,6 +24,7 @@ #include "mads/game.h" #include "mads/mads.h" #include "mads/resources.h" +#include "mads/scene.h" #include "mads/screen.h" #include "mads/nebular/menu_nebular.h" @@ -34,6 +35,7 @@ namespace Nebular { #define NEBULAR_MENUSCREEN 990 #define MADS_MENU_Y ((MADS_SCREEN_HEIGHT - MADS_SCENE_HEIGHT) / 2) #define MADS_MENU_ANIM_DELAY 70 +#define DIALOG_TOP 22 MenuView::MenuView(MADSEngine *vm) : FullScreenDialog(vm) { _breakFlag = false; @@ -44,6 +46,9 @@ MenuView::MenuView(MADSEngine *vm) : FullScreenDialog(vm) { void MenuView::show() { Scene &scene = _vm->_game->_scene; EventsManager &events = *_vm->_events; + _vm->_screenFade = SCREEN_FADE_FAST; + + scene._spriteSlots.reset(true); display(); events.setEventTarget(this); @@ -51,9 +56,7 @@ void MenuView::show() { while (!_breakFlag && !_vm->shouldQuit()) { if (_redrawFlag) { - scene.drawElements(_vm->_game->_fx, _vm->_game->_fx); - - _vm->_screen.copyRectToScreen(Common::Rect(0, 0, 320, 200)); + handleFrame(); _redrawFlag = false; } @@ -65,6 +68,11 @@ void MenuView::show() { events.setEventTarget(nullptr); } +void MenuView::handleFrame() { + _vm->_game->_scene.drawElements(_vm->_game->_fx, _vm->_game->_fx); + _vm->_screen.copyRectToScreen(Common::Rect(0, 0, 320, 200)); +} + void MenuView::display() { _vm->_palette->resetGamePalette(4, 8); @@ -375,6 +383,8 @@ void AdvertView::show() { sceneInfo->load(screenId, 0, Common::String(), 0, _vm->_game->_scene._depthSurface, _vm->_screen); _vm->_screen.copyRectToScreen(_vm->_screen.getBounds()); + _vm->_palette->setFullPalette(_vm->_palette->_mainPalette); + delete sceneInfo; EventsManager &events = *_vm->_events; @@ -426,6 +436,9 @@ TextView::TextView(MADSEngine *vm) : MenuView(vm), _scrollTimeout = 0; _panCountdown = 0; _translationX = 0; + + _vm->_palette->resetGamePalette(4, 8); + load(); } TextView::~TextView() { @@ -433,7 +446,10 @@ TextView::~TextView() { } void TextView::load() { - if (!_script.open(_resourceName)) + Common::String scriptName(_resourceName); + scriptName += ".txr"; + + if (!_script.open(scriptName)) error("Could not open resource %s", _resourceName); processLines(); @@ -444,7 +460,11 @@ void TextView::processLines() { error("Attempted to read past end of response file"); while (!_script.eos()) { + // Read in the next line _script.readLine(_currentLine, 79); + char *p = _currentLine + strlen(_currentLine) - 1; + if (*p == '\n') + *p = '\0'; // Commented out line, so go loop for another if (_currentLine[0] == '#') @@ -499,21 +519,6 @@ void TextView::processCommand() { } else if (!strncmp(commandStr, "GO", 2)) { _animating = true; - // Grab what the final palete will be - byte destPalette[PALETTE_SIZE]; - _vm->_palette->grabPalette(destPalette, 0, 256); - - // Copy the loaded background, if any, to the view surface - //int yp = 22; - //scene._backgroundSurface.copyTo(this, 0, 22); - - // Handle fade-in - //byte srcPalette[768]; - //Common::fill(&srcPalette[0], &srcPalette[PALETTE_SIZE], 0); - //_vm->_palette->fadeIn(srcPalette, destPalette, 0, PALETTE_COUNT, 0, 0, - // TV_FADE_DELAY_MILLI, TV_NUM_FADE_STEPS); - _vm->_game->_fx = kTransitionFadeIn; - } else if (!strncmp(commandStr, "PAN", 3)) { // Set panning values paramP = commandStr + 3; @@ -528,10 +533,12 @@ void TextView::processCommand() { } else if (!strncmp(commandStr, "DRIVER", 6)) { // Set the driver to use - paramP = commandStr + 6; - int driverNum = getParameter(¶mP); - _vm->_sound->init(driverNum); + paramP = commandStr + 7; + if (!strncmp(paramP, "#SOUND.00", 9)) { + int driverNum = paramP[9] - '0'; + _vm->_sound->init(driverNum); + } } else if (!strncmp(commandStr, "SOUND", 5)) { // Set sound number paramP = commandStr + 5; @@ -628,6 +635,138 @@ void TextView::processText() { _vm->_font->writeString(&_textSurface, _currentLine, Common::Point(xStart, yp)); } +void TextView::display() { + _vm->_screen.empty(); + _vm->_screen.hLine(0, 20, MADS_SCREEN_WIDTH, 2); + _vm->_screen.hLine(0, 179, MADS_SCREEN_WIDTH, 2); + + _vm->_palette->setEntry(10, 0, 63, 0); + _vm->_palette->setEntry(11, 0, 45, 0); + _vm->_palette->setEntry(12, 63, 63, 0); + _vm->_palette->setEntry(13, 45, 45, 0); + _vm->_palette->setEntry(14, 63, 63, 63); + _vm->_palette->setEntry(15, 45, 45, 45); + + // Copy the loaded background, if any, to the view surface + _vm->_game->_scene._backgroundSurface.copyTo(&_vm->_screen, DIALOG_TOP); + _vm->_screen.copyRectToScreen(Common::Rect(0, DIALOG_TOP, + MADS_SCREEN_WIDTH, DIALOG_TOP + MADS_SCENE_HEIGHT)); +} + +void TextView::handleFrame() { + // Stop inherited behaviour +} + +void TextView::doFrame() { + Scene &scene = _vm->_game->_scene; + if (!_animating) + return; + + // Only update state if wait period has expired + uint32 currTime = g_system->getMillis(); + + // If a screen transition is in progress and it's time for another column, handle it + if (_spareScreen) { + byte *srcP = _spareScreen->getBasePtr(_translationX, 0); + byte *destP = scene._backgroundSurface.getBasePtr(_translationX, 0); + + for (int y = 0; y < MADS_SCENE_HEIGHT; ++y, srcP += _spareScreen->w, + destP += MADS_SCREEN_WIDTH) { + *destP = *srcP; + } + + if (++_translationX >= MADS_SCREEN_WIDTH) { + // Surface transition is complete + /* + delete _spareScreen; + _spareScreen = nullptr; + +// _vm->_palette->deleteRange(_bgCurrent); + delete _bgCurrent; + _bgCurrent = _bgSpare; + _bgSpare = nullptr; + */ + } + } + + // Make sure it's time for an update + if (currTime < _scrollTimeout) + return; + _scrollTimeout = g_system->getMillis() + TEXT_ANIMATION_DELAY; + + // If any panning values are set, pan the background surface + if ((_pan.x != 0) || (_pan.y != 0)) { + if (_panCountdown > 0) { + --_panCountdown; + return; + } + + // Handle horizontal panning + if (_pan.x != 0) { + byte *lineTemp = new byte[_pan.x]; + for (int y = 0; y < MADS_SCENE_HEIGHT; ++y) { + byte *pixelsP = (byte *)scene._backgroundSurface.getBasePtr(0, y); + + // Copy the first X pixels into temp buffer, move the rest of the line + // to the start of the line, and then move temp buffer pixels to end of line + Common::copy(pixelsP, pixelsP + _pan.x, lineTemp); + Common::copy(pixelsP + _pan.x, pixelsP + MADS_SCREEN_WIDTH, pixelsP); + Common::copy(lineTemp, lineTemp + _pan.x, pixelsP + MADS_SCREEN_WIDTH - _pan.x); + } + + delete[] lineTemp; + } + + // Handle vertical panning + if (_pan.y != 0) { + // Store the bottom Y lines into a temp buffer, move the rest of the lines down, + // and then copy the stored lines back to the top of the screen + byte *linesTemp = new byte[_pan.y * MADS_SCREEN_WIDTH]; + byte *pixelsP = (byte *)scene._backgroundSurface.getBasePtr(0, MADS_SCENE_HEIGHT - _pan.y); + Common::copy(pixelsP, pixelsP + MADS_SCREEN_WIDTH * _pan.y, linesTemp); + + for (int y = MADS_SCENE_HEIGHT - 1; y >= _pan.y; --y) { + byte *destP = (byte *)scene._backgroundSurface.getBasePtr(0, y); + byte *srcP = (byte *)scene._backgroundSurface.getBasePtr(0, y - _pan.y); + Common::copy(srcP, srcP + MADS_SCREEN_WIDTH, destP); + } + + Common::copy(linesTemp, linesTemp + _pan.y * MADS_SCREEN_WIDTH, + (byte *)scene._backgroundSurface.getPixels()); + delete[] linesTemp; + } + } + + // Scroll the text surface up by one row + byte *pixelsP = (byte *)_textSurface.getPixels(); + Common::copy(pixelsP + _textSurface.w, pixelsP + _textSurface.w * _textSurface.h, pixelsP); + pixelsP = _textSurface.getBasePtr(0, _textSurface.h - 1); + Common::fill(pixelsP, pixelsP + _textSurface.w, 0); + + if (_scrollCount > 0) { + // Handling final scrolling of text off of screen + if (--_scrollCount == 0) { + scriptDone(); + return; + } + } else { + // Handling a text row + if (++_lineY == (_vm->_font->getHeight() + TEXTVIEW_LINE_SPACING)) + processLines(); + } + + // Refresh the view + scene._backgroundSurface.copyTo(&_vm->_screen, Common::Point(0, DIALOG_TOP)); + _textSurface.copyTo(&_vm->_screen, Common::Rect(0, 0, _textSurface.w, MADS_SCENE_HEIGHT), + Common::Point(0, DIALOG_TOP), 0); + _vm->_screen.copyRectToScreen(Common::Rect(0, DIALOG_TOP, + MADS_SCREEN_WIDTH, DIALOG_TOP + MADS_SCENE_HEIGHT)); +} + +void TextView::scriptDone() { + _breakFlag = true; +} + /*------------------------------------------------------------------------*/ char AnimationView::_resourceName[100]; diff --git a/engines/mads/nebular/menu_nebular.h b/engines/mads/nebular/menu_nebular.h index 6e877a8a24..dfb26eb16e 100644 --- a/engines/mads/nebular/menu_nebular.h +++ b/engines/mads/nebular/menu_nebular.h @@ -43,6 +43,8 @@ protected: virtual void doFrame() = 0; + virtual void handleFrame(); + virtual void display(); public: MenuView(MADSEngine *vm); @@ -188,6 +190,17 @@ private: * Get a parameter from line */ int getParameter(const char **paramP); + + /** + * Called when the script is finished + */ + void scriptDone(); +protected: + virtual void display(); + + virtual void handleFrame(); + + virtual void doFrame(); public: /** * Queue the given text resource for display @@ -219,9 +232,9 @@ private: void processCommand(); void scriptDone(); - - void doFrame(); protected: + virtual void doFrame(); + virtual bool onEvent(Common::Event &event); public: /** diff --git a/engines/mads/nebular/nebular_scenes.cpp b/engines/mads/nebular/nebular_scenes.cpp index c71512ed4c..b5e2491624 100644 --- a/engines/mads/nebular/nebular_scenes.cpp +++ b/engines/mads/nebular/nebular_scenes.cpp @@ -331,7 +331,7 @@ void SceneInfoNebular::loadCodes(MSurface &depthSurface, Common::SeekableReadStr byte runValue = stream->readByte(); // Write out the run length - Common::fill(destP, destP + runLength, runValue); + Common::fill(destP, MIN(endP, destP + runLength), runValue); destP += runLength; // Get the next run length diff --git a/engines/mads/nebular/sound_nebular.cpp b/engines/mads/nebular/sound_nebular.cpp index fc2755db2f..4c6070b528 100644 --- a/engines/mads/nebular/sound_nebular.cpp +++ b/engines/mads/nebular/sound_nebular.cpp @@ -3114,6 +3114,313 @@ int ASound8::command37() { return 0; } +/*-----------------------------------------------------------------------*/ + +const ASound9::CommandPtr ASound9::_commandList[52] = { + &ASound9::command0, &ASound9::command1, &ASound9::command2, &ASound9::command3, + &ASound9::command4, &ASound9::command5, &ASound9::command6, &ASound9::command7, + &ASound9::command8, &ASound9::command9, &ASound9::command10, &ASound9::command11, + &ASound9::command12, &ASound9::command13, &ASound9::command14, &ASound9::command15, + &ASound9::command16, &ASound9::command17, &ASound9::command18, &ASound9::command19, + &ASound9::command20, &ASound9::command21, &ASound9::command22, &ASound9::command23, + &ASound9::command24, &ASound9::command25, &ASound9::command26, &ASound9::command27, + &ASound9::command28, &ASound9::command29, &ASound9::command30, &ASound9::command31, + &ASound9::command32, &ASound9::command33, &ASound9::command34, &ASound9::command35, + &ASound9::command36, &ASound9::command37, &ASound9::command38, &ASound9::command39, + &ASound9::command40, &ASound9::command41, &ASound9::command42, &ASound9::command43, + &ASound9::command44_46, &ASound9::command45, &ASound9::command44_46, &ASound9::command47, + &ASound9::command48, &ASound9::command49, &ASound9::command50, &ASound9::command51 +}; + +ASound9::ASound9(Audio::Mixer *mixer) : ASound(mixer, "asound.009", 0x16F0) { + _v1 = _v2 = 0; + _soundPtr = nullptr; + + // Load sound samples + _soundFile.seek(_dataOffset + 0x50); + for (int i = 0; i < 94; ++i) + _samples.push_back(AdlibSample(_soundFile)); +} + +int ASound9::command(int commandId, int param) { + if (commandId > 60) + return 0; + + _commandParam = param; + _frameCounter = 0; + return (this->*_commandList[commandId])(); +} + +int ASound9::command9() { + _v1 = 1848; + _v2 = 84; + _channels[0].load(loadData(0xAA4, 470)); + _channels[1].load(loadData(0xE4C, 450)); + _channels[2].load(loadData(0x1466, 702)); + _channels[3].load(loadData(0x137E, 232)); + _channels[4].load(loadData(0x1014, 65)); + _channels[5].load(loadData(0x11C4, 44)); + _channels[6].load(loadData(0XC7A, 466)); + return 0; +} + +int ASound9::command10() { + _channels[0].load(loadData(0x1724, 24)); + _channels[1].load(loadData(0x173C, 24)); + _channels[2].load(loadData(0x1754, 20)); + _channels[3].load(loadData(0x1768, 20)); + _channels[4].load(loadData(0x177C, 20)); + _channels[5].load(loadData(0x1790, 20)); + return 0; +} + +int ASound9::command11() { + playSound(0x8232, 168); + playSound(0x82DA, 170); + return 0; +} + +int ASound9::command12() { + playSound(0x80DA, 12); + playSound(0x80E6, 12); + return 0; +} + +int ASound9::command13() { + playSound(0x80F2, 38); + playSound(0x8118, 42); + return 0; +} + +int ASound9::command14() { + playSound(0x81F6, 22); + return 0; +} + +int ASound9::command15() { + playSound(0x818A, 32); + playSound(0x81AA, 32); + return 0; +} + +int ASound9::command16() { + playSound(0x8022, 36); + playSound(0x8046, 42); + return 0; +} + +int ASound9::command17() { + command29(); + playSound(0x858C, 11); + return 0; +} + +int ASound9::command18() { + playSound(0x80C2, 24); + return 0; +} + +int ASound9::command19() { + playSound(0x80A0, 34); + return 0; +} + +int ASound9::command20() { + int v = (getRandomNumber() & 0x10) | 0x4D; + byte *pData = loadData(0x8142, 8); + pData[4] = v & 0x7F; + playSoundData(pData); + return 0; +} + +int ASound9::command21() { + playSound(0x815A, 16); + return 0; +} + +int ASound9::command22() { + playSound(0x816A, 16); + return 0; +} + +int ASound9::command23() { + playSound(0x814A, 16); + return 0; +} + +int ASound9::command24() { + playSound(0x7FE2, 34); + return 0; +} + +int ASound9::command25() { + playSound(0x8004, 30); + return 0; +} + +int ASound9::command26() { + _channels[6].load(loadData(0x8384, 156)); + _channels[7].load(loadData(0x8420, 160)); + return 0; +} + +int ASound9::command27() { + playSound(0x84C0, 140); + return 0; +} + +int ASound9::command28() { + playSound(0x81CA, 10); + return 0; +} + +int ASound9::command29() { + playSound(0x81D4, 10); + return 0; +} + +int ASound9::command30() { + playSound(0x817A, 16); + return 0; +} + +int ASound9::command31() { + playSound(0x820C, 14); + playSound(0x821A, 24); + return 0; +} + +int ASound9::command32() { + playSound(0x8070, 8); + return 0; +} + +int ASound9::command33() { + playSound(0x8078, 16); + playSound(0x8088, 16); + return 0; +} + +int ASound9::command34() { + // Skipped stuff in original + _channels[0].load(loadData(0x17A4, 24)); + _channels[1].load(loadData(0x1CDE, 62)); + _channels[2].load(loadData(0x2672, 980)); + _channels[3].load(loadData(0x3336, 1000)); + _channels[4].load(loadData(0x469E, 176)); + _channels[5].load(loadData(0x57F2, 138)); + + return 0; +} + +int ASound9::command35() { + playSound(0x854C, 64); + return 0; +} + +int ASound9::command36() { + playSound(0x81DE, 10); + playSound(0x81E8, 14); + return 0; +} + +int ASound9::command37() { + byte *pData = loadData(0x8098, 8); + int v = getRandomNumber(); + if ((v &= 0x40) != 0) + v |= 8; + else + v += 0x4A; + + pData[6] = v; + playSoundData(pData); + return 0; +} + +int ASound9::command38() { + playSound(0x100E, 6); + return 0; +} + +int ASound9::command39() { + _soundPtr = loadData(0x1055, 128); + return 0; +} + +int ASound9::command40() { + _soundPtr = loadData(0x118C, 50); + return 0; +} + +int ASound9::command41() { + _soundPtr = loadData(0x11BE, 6); + return 0; +} + +int ASound9::command42() { + _soundPtr = loadData(0x11F0, 50); + return 0; +} + +int ASound9::command43() { + _v1 = _v2 = 80; + _channels[0].load(loadData(0x626A, 90)); + _channels[1].load(loadData(0x67F2, 92)); + _channels[2].load(loadData(0x6CFE, 232)); + _channels[3].load(loadData(0x7146, 236)); + + return 0; +} + +int ASound9::command44_46() { + _soundPtr = loadData(0x10D5, 38); + return 0; +} + +int ASound9::command45() { + _soundPtr = loadData(0x10FB, 38); + return 0; +} + +int ASound9::command47() { + _soundPtr = loadData(0x1121, 107); + return 0; +} + +int ASound9::command48() { + playSound(0x7FD0, 8); + playSound(0x7FD8, 10); + return 0; +} + +int ASound9::command49() { + _channels[0].load(loadData(0x7AD6, 92)); + _channels[1].load(loadData(0x7B32, 90)); + _channels[2].load(loadData(0x7B8C, 738)); + _channels[3].load(loadData(0x7E6E, 28)); + _channels[4].load(loadData(0x7E8A, 30)); + _channels[5].load(loadData(0x7EA8, 30)); + _channels[6].load(loadData(0x7EC6, 195)); + return 0; +} + +int ASound9::command50() { + _soundPtr = loadData(0x1222, 348); + return 0; +} + +int ASound9::command51() { + // Skipped stuff in original + _channels[0].load(loadData(0x17BC, 1282)); + _channels[1].load(loadData(0x1CFC, 2422)); + _channels[2].load(loadData(0x2A46, 2288)); + _channels[3].load(loadData(0x371E, 3964)); + _channels[4].load(loadData(0x474E, 1863)); + _channels[5].load(loadData(0x587C, 2538)); + return 0; +} + + } // End of namespace Nebular } // End of namespace MADS diff --git a/engines/mads/nebular/sound_nebular.h b/engines/mads/nebular/sound_nebular.h index c485bd7955..744467b45e 100644 --- a/engines/mads/nebular/sound_nebular.h +++ b/engines/mads/nebular/sound_nebular.h @@ -713,6 +713,65 @@ public: virtual int command(int commandId, int param); }; +class ASound9 : public ASound { +private: + int _v1, _v2; + byte *_soundPtr; + + typedef int (ASound9::*CommandPtr)(); + static const CommandPtr _commandList[52]; + + int command9(); + int command10(); + int command11(); + int command12(); + int command13(); + int command14(); + int command15(); + int command16(); + int command17(); + int command18(); + int command19(); + int command20(); + int command21(); + int command22(); + int command23(); + int command24(); + int command25(); + int command26(); + int command27(); + int command28(); + int command29(); + int command30(); + int command31(); + int command32(); + int command33(); + int command34(); + int command35(); + int command36(); + int command37(); + int command38(); + int command39(); + int command40(); + int command41(); + int command42(); + int command43(); + int command44_46(); + int command45(); + int command47(); + int command48(); + int command49(); + int command50(); + int command51(); + int command57(); + int command59(); + int command60(); +public: + ASound9(Audio::Mixer *mixer); + + virtual int command(int commandId, int param); +}; + } // End of namespace Nebular } // End of namespace MADS diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 1f95749fd8..cb68d38eec 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -82,6 +82,7 @@ Scene::Scene(MADSEngine *vm) Scene::~Scene() { delete _sceneLogic; delete _sceneInfo; + delete _animationData; } void Scene::clearVocab() { diff --git a/engines/mads/sound.cpp b/engines/mads/sound.cpp index bd99aed2f4..35d948e0b0 100644 --- a/engines/mads/sound.cpp +++ b/engines/mads/sound.cpp @@ -73,7 +73,8 @@ void SoundManager::init(int sectionNumber) { _driver = new Nebular::ASound8(_mixer); break; case 9: - error("Sound driver 9 not implemented"); + _driver = new Nebular::ASound9(_mixer); + break; default: _driver = nullptr; break; diff --git a/engines/savestate.h b/engines/savestate.h index 970e01485d..54eff0f8cb 100644 --- a/engines/savestate.h +++ b/engines/savestate.h @@ -140,7 +140,7 @@ public: * Sets the time the game was played before the save state was created. * * @param hours How many hours the user played the game so far. - * @param min How many minutes the user played the game so far. + * @param minutes How many minutes the user played the game so far. */ void setPlayTime(int hours, int minutes); diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp index 8f535aeddc..80a72b9a6f 100644 --- a/engines/sci/sound/drivers/midi.cpp +++ b/engines/sci/sound/drivers/midi.cpp @@ -956,7 +956,7 @@ int MidiPlayer_Midi::open(ResourceManager *resMan) { if (getSciVersion() >= SCI_VERSION_1_EGA_ONLY) warning("The automatic mapping for General MIDI hasn't been worked on for " "SCI1 games. Music might sound wrong or broken. Please choose another " - "music driver for this game (e.g. Adlib or MT-32) if you are " + "music driver for this game (e.g. AdLib or MT-32) if you are " "experiencing issues with music"); // Modify velocity map to make low velocity notes a little louder diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp index 8321daa583..52120949cc 100644 --- a/engines/scumm/dialogs.cpp +++ b/engines/scumm/dialogs.cpp @@ -428,7 +428,9 @@ const Common::String InfoDialog::queryResString(int stringno) { if (stringno == 0) return String(); - if (_vm->_game.version == 8) + if (_vm->_game.heversion >= 80) + return _(string_map_table_v6[stringno - 1].string); + else if (_vm->_game.version == 8) result = (const byte *)string_map_table_v8[stringno - 1].string; else if (_vm->_game.version == 7) result = _vm->getStringAddressVar(string_map_table_v7[stringno - 1].num); diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp index 2c672ccc89..2fe5333bfc 100644 --- a/engines/scumm/script.cpp +++ b/engines/scumm/script.cpp @@ -972,6 +972,18 @@ void ScummEngine::runEntryScript() { runScript(VAR(VAR_ENTRY_SCRIPT2), 0, 0, 0); } +void ScummEngine::runQuitScript() { + if (VAR_QUIT_SCRIPT != 0xFF && VAR(VAR_QUIT_SCRIPT)) { + int args[NUM_SCRIPT_LOCAL]; + + memset(args, 0, sizeof(args)); + args[0] = 2; + args[1] = 1003; + + runScript(VAR(VAR_QUIT_SCRIPT), 0, 0, args); + } +} + void ScummEngine::killScriptsAndResources() { ScriptSlot *ss; int i; diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index 73776bad5a..475b146a7b 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -467,6 +467,8 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr) VAR_NUM_SCRIPT_CYCLES = 0xFF; VAR_SCRIPT_CYCLE = 0xFF; + VAR_QUIT_SCRIPT = 0xFF; + VAR_NUM_GLOBAL_OBJS = 0xFF; // Use g_scumm from error() ONLY @@ -2073,6 +2075,7 @@ Common::Error ScummEngine::go() { if (shouldQuit()) { // TODO: Maybe perform an autosave on exit? + runQuitScript(); } } diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h index 36d05077c6..af118a89a1 100644 --- a/engines/scumm/scumm.h +++ b/engines/scumm/scumm.h @@ -671,6 +671,7 @@ protected: virtual void checkAndRunSentenceScript(); void runExitScript(); void runEntryScript(); + void runQuitScript(); void runAllScripts(); void freezeScripts(int scr); void unfreezeScripts(); @@ -1361,6 +1362,8 @@ public: byte VAR_SCRIPT_CYCLE; // Used in runScript()/runObjectScript() byte VAR_NUM_SCRIPT_CYCLES; // Used in runAllScripts() + + byte VAR_QUIT_SCRIPT; // Used in confirmExitDialog() // Exists both in V7 and in V72HE: byte VAR_NUM_GLOBAL_OBJS; diff --git a/engines/scumm/vars.cpp b/engines/scumm/vars.cpp index 79d7ed03da..a903ac5804 100644 --- a/engines/scumm/vars.cpp +++ b/engines/scumm/vars.cpp @@ -320,6 +320,7 @@ void ScummEngine_v90he::setupScummVars() { ScummEngine_v80he::setupScummVars(); VAR_TIMER = 97; + VAR_QUIT_SCRIPT = 102; VAR_SCRIPT_CYCLE = 103; VAR_NUM_SCRIPT_CYCLES = 104; diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index b42b833304..ac358e774b 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -542,7 +542,7 @@ MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, ResMan * Video::VideoDecoder *dxaDecoder = new Video::DXADecoder(); return new MoviePlayer(vm, textMan, resMan, system, dxaDecoder, kVideoDecoderDXA); #else - GUI::MessageDialog dialog(_("DXA cutscenes found but ScummVM has been built without zlib support"), _("OK")); + GUI::MessageDialog dialog(_("DXA cutscenes found but ScummVM has been built without zlib"), _("OK")); dialog.runModal(); return 0; #endif diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp index 92fa9d0e44..e93f27f76c 100644 --- a/engines/sword2/animation.cpp +++ b/engines/sword2/animation.cpp @@ -442,7 +442,7 @@ MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, OSystem *system Video::DXADecoder *dxaDecoder = new Video::DXADecoder(); return new MoviePlayer(vm, system, dxaDecoder, kVideoDecoderDXA); #else - GUI::MessageDialog dialog(_("DXA cutscenes found but ScummVM has been built without zlib support"), _("OK")); + GUI::MessageDialog dialog(_("DXA cutscenes found but ScummVM has been built without zlib"), _("OK")); dialog.runModal(); return NULL; #endif diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp index fee1bd752b..b95b614f09 100644 --- a/engines/tsage/sound.cpp +++ b/engines/tsage/sound.cpp @@ -164,7 +164,7 @@ Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool detectFlag) { sd._status = detectFlag ? SNDSTATUS_DETECTED : SNDSTATUS_SKIPPED; sd._field2 = 0; sd._field6 = 15000; - sd._shortDescription = "Adlib or SoundBlaster"; + sd._shortDescription = "AdLib or SoundBlaster"; sd._longDescription = "3812fm"; _availableDrivers.push_back(sd); diff --git a/engines/wintermute/base/gfx/base_renderer.h b/engines/wintermute/base/gfx/base_renderer.h index 42ff2cb9e1..6b1a4f97f4 100644 --- a/engines/wintermute/base/gfx/base_renderer.h +++ b/engines/wintermute/base/gfx/base_renderer.h @@ -72,7 +72,6 @@ public: * Fade the screen to black * * @param alpha amount to fade by (alpha value of black) - * @return */ virtual void fade(uint16 alpha) = 0; /** diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index d592019418..dc6476d4ea 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -32,11 +32,6 @@ namespace Wintermute { -////////////////////////////////////////////////////////////////////// -static inline unsigned Sqr(int x) { - return (x * x); -} - ////////////////////////////////////////////////////////////////////////////////// // Swap - swaps two integers ////////////////////////////////////////////////////////////////////////////////// |