aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen
diff options
context:
space:
mode:
authorPaul Gilbert2016-09-16 19:13:01 -0400
committerPaul Gilbert2016-09-16 19:13:01 -0400
commit1879aeae578e75518f0c798a77b2983eb1b29c26 (patch)
tree0c18c56645757f5d85d3e4ed70ba6831afe16ce3 /engines/xeen
parent9691da2b05a2dd701beeefc260c7a2bedda046fd (diff)
downloadscummvm-rg350-1879aeae578e75518f0c798a77b2983eb1b29c26.tar.gz
scummvm-rg350-1879aeae578e75518f0c798a77b2983eb1b29c26.tar.bz2
scummvm-rg350-1879aeae578e75518f0c798a77b2983eb1b29c26.zip
XEEN: Further fixes and cleanup for music player
Diffstat (limited to 'engines/xeen')
-rw-r--r--engines/xeen/music.cpp70
-rw-r--r--engines/xeen/music.h9
-rw-r--r--engines/xeen/worldofxeen/darkside_cutscenes.cpp1
3 files changed, 50 insertions, 30 deletions
diff --git a/engines/xeen/music.cpp b/engines/xeen/music.cpp
index c4e4f7b4c3..2000070c9b 100644
--- a/engines/xeen/music.cpp
+++ b/engines/xeen/music.cpp
@@ -31,7 +31,7 @@ namespace Xeen {
/*------------------------------------------------------------------------*/
-MusicDriver::MusicDriver() : _fieldF(false), _field1E(false), _lowMusicIgnored(false),
+MusicDriver::MusicDriver() : _fieldF(false), _musicPlaying(false), _fxPlaying(false),
_musCountdownTimer(0), _fxCountdownTimer(0), _musDataPtr(nullptr),
_fxDataPtr(nullptr), _fxStartPtr(nullptr), _musStartPtr(nullptr) {
_channels.resize(CHANNEL_COUNT);
@@ -39,27 +39,31 @@ MusicDriver::MusicDriver() : _fieldF(false), _field1E(false), _lowMusicIgnored(f
void MusicDriver::execute() {
bool isFX = false;
- bool flag = !_field1E;
- const byte *srcP = _musDataPtr;
+ const byte *srcP = nullptr;
+
+ // Single iteration loop to avoid use of GOTO
+ do {
+ if (_musicPlaying) {
+ srcP = _musDataPtr;
+ isFX = false;
+ if (_musCountdownTimer == 0 || --_musCountdownTimer == 0)
+ break;
+ }
- if (!flag) {
- if (_musCountdownTimer && --_musCountdownTimer == 0)
- flag = true;
- }
- if (flag && _lowMusicIgnored) {
- srcP = _fxDataPtr;
- isFX = true;
- if (!_fxCountdownTimer || --_fxCountdownTimer == 0)
- flag = false;
- }
+ if (_fxPlaying) {
+ srcP = _fxDataPtr;
+ isFX = true;
+ if (_fxCountdownTimer == 0 || --_fxCountdownTimer == 0)
+ break;
+ }
- if (flag) {
- // Do paused handling and exit immediately
pausePostProcess();
return;
- }
+ } while (0);
// Main loop
+ debugC(kDebugSound, 8, "MusicDriver frame starting");
+
bool breakFlag = false;
while (!breakFlag) {
byte nextByte = *srcP++;
@@ -126,10 +130,12 @@ bool MusicDriver::cmdChangeFrequency(const byte *&srcP, byte param) {
bool MusicDriver::musEndSubroutine(const byte *&srcP, byte param) {
if (param != 15) {
- _field1E = 0;
+ // Music has ended, so flag it stopped
+ _musicPlaying = false;
return true;
}
+ // Returning from subroutine, or looping back to start of music
srcP = _musSubroutines.empty() ? _musStartPtr : _musSubroutines.pop()._returnP;
return false;
}
@@ -159,7 +165,8 @@ bool MusicDriver::fxSetCountdown(const byte *&srcP, byte param) {
bool MusicDriver::fxEndSubroutine(const byte *&srcP, byte param) {
if (param != 15) {
- _lowMusicIgnored = false;
+ // FX has ended, so flag it stopped
+ _fxPlaying = false;
return true;
}
@@ -168,21 +175,24 @@ bool MusicDriver::fxEndSubroutine(const byte *&srcP, byte param) {
}
void MusicDriver::playFX(uint effectId, const byte *data) {
- if (!_lowMusicIgnored || effectId < 7 || effectId >= 11) {
+ if (!_fxPlaying || effectId < 7 || effectId >= 11) {
_musStartPtr = nullptr;
_fxDataPtr = _fxStartPtr = data;
_fxCountdownTimer = 0;
_channels[7]._changeFrequency = _channels[8]._changeFrequency = false;
resetFX();
- _lowMusicIgnored = true;
+ _fxPlaying = true;
}
+
+ debugC(1, kDebugSound, "Starting FX");
}
void MusicDriver::playSong(const byte *data) {
_musDataPtr = _musStartPtr = data;
_musSubroutines.clear();
_musCountdownTimer = 0;
- _field1E = true;
+ _musicPlaying = true;
+ debugC(1, kDebugSound, "Starting song");
}
int MusicDriver::songCommand(uint commandId, byte volume) {
@@ -258,20 +268,21 @@ void AdlibMusicDriver::playSong(const byte *data) {
Common::StackLock slock(_driverMutex);
MusicDriver::playSong(data);
_field180 = 0;
+ resetFrequencies();
}
int AdlibMusicDriver::songCommand(uint commandId, byte volume) {
Common::StackLock slock(_driverMutex);
if (commandId == STOP_MUSIC) {
- _field1E = 0;
+ _musicPlaying = false;
_field180 = 0;
resetFrequencies();
} else if (commandId == RESTART_MUSIC) {
_field180 = 0;
- _field1E = true;
+ _musicPlaying = true;
} else if (commandId < 0x100) {
- if (_field1E) {
+ if (_musicPlaying) {
_field180 = commandId;
_field182 = 63;
}
@@ -286,6 +297,7 @@ int AdlibMusicDriver::songCommand(uint commandId, byte volume) {
void AdlibMusicDriver::write(int reg, int val) {
_queue.push(RegisterValue(reg, val));
+ debugC(9, kDebugSound, "%.2x %2x", reg, val);
}
void AdlibMusicDriver::flush() {
@@ -300,7 +312,7 @@ void AdlibMusicDriver::flush() {
void AdlibMusicDriver::pausePostProcess() {
if (_field180 && ((_field181 += _field180) < 0)) {
if (--_field182 < 0) {
- _field1E = false;
+ _musicPlaying = false;
_field180 = 0;
resetFrequencies();
} else {
@@ -386,7 +398,7 @@ void AdlibMusicDriver::setOutputLevel(byte channelNum, uint level) {
void AdlibMusicDriver::playInstrument(byte channelNum, const byte *data) {
byte op1 = OPERATOR1_INDEXES[channelNum];
byte op2 = OPERATOR2_INDEXES[channelNum];
-
+ debugC(2, kDebugSound, "---START-playInstrument - %d", channelNum);
write(0x20 + op1, *data++);
write(0x40 + op1, *data++);
write(0x60 + op1, *data++);
@@ -408,7 +420,9 @@ void AdlibMusicDriver::playInstrument(byte channelNum, const byte *data) {
write(0x60 + op2, *data++);
write(0x80 + op2, *data++);
write(0xE0 + op2, *data++);
- write(0xC0 + op2, *data++);
+ write(0xC0 + channelNum, *data++);
+
+ debugC(2, kDebugSound, "---END-playInstrument");
}
bool AdlibMusicDriver::musSetInstrument(const byte *&srcP, byte param) {
@@ -454,7 +468,7 @@ bool AdlibMusicDriver::musStartNote(const byte *&srcP, byte param) {
}
bool AdlibMusicDriver::musSetVolume(const byte *&srcP, byte param) {
- if (*srcP++ == 2 && !_field180) {
+ if (*srcP++ == 5 && !_field180) {
_channels[param]._volume = *srcP;
setOutputLevel(param, *srcP);
}
diff --git a/engines/xeen/music.h b/engines/xeen/music.h
index f09f96ff79..5b23cc1965 100644
--- a/engines/xeen/music.h
+++ b/engines/xeen/music.h
@@ -77,7 +77,6 @@ private:
Common::Stack<Subroutine> _musSubroutines, _fxSubroutines;
int _musCountdownTimer;
int _fxCountdownTimer;
- bool _lowMusicIgnored;
const byte *_fxDataPtr, *_musDataPtr;
const byte *_fxStartPtr;
const byte *_musStartPtr;
@@ -91,7 +90,8 @@ private:
protected:
Common::Array<Channel> _channels;
bool _fieldF;
- bool _field1E;
+ bool _musicPlaying;
+ bool _fxPlaying;
protected:
/**
* Executes a series of commands until instructed to stop
@@ -334,6 +334,11 @@ public:
void restartMusic() { songCommand(RESTART_MUSIC); }
/**
+ * Sets the music volume
+ */
+ void setMusicVolume(byte volume) { songCommand(SET_VOLUME, volume); }
+
+ /**
* Plays a song
*/
void playSong(Common::SeekableReadStream &stream);
diff --git a/engines/xeen/worldofxeen/darkside_cutscenes.cpp b/engines/xeen/worldofxeen/darkside_cutscenes.cpp
index 6dd4bd20f6..6a6eec20d3 100644
--- a/engines/xeen/worldofxeen/darkside_cutscenes.cpp
+++ b/engines/xeen/worldofxeen/darkside_cutscenes.cpp
@@ -56,6 +56,7 @@ bool DarkSideCutscenes::showDarkSideTitle() {
screen.fadeIn(4);
// **DEBUG**: Testing music
+ sound.setMusicVolume(0x5f);
File f("bigtheme.m", *_vm->_files->_sideArchives[1]);
byte *data = new byte[f.size()];
f.read(data, f.size());