aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2006-03-09 18:42:05 +0000
committerTorbjörn Andersson2006-03-09 18:42:05 +0000
commita5e0c392ba3cef688b0525dbdd233c95e1657674 (patch)
tree0eab42d9b13f3315282c8e6cd3887c43b97c76b9
parentc571026a20b70b09d706dbefda22ce575c74c7e8 (diff)
downloadscummvm-rg350-a5e0c392ba3cef688b0525dbdd233c95e1657674.tar.gz
scummvm-rg350-a5e0c392ba3cef688b0525dbdd233c95e1657674.tar.bz2
scummvm-rg350-a5e0c392ba3cef688b0525dbdd233c95e1657674.zip
As LordHoto pointed out to me, updateCallback41() was slightly different after
all: it adjusts the frequency even when state.unk16 is zero. Fixed that, and added some comments to hopefully explain the differences between the cleaned up code and the original disassembly. svn-id: r21184
-rw-r--r--engines/kyra/sound_adlib.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/engines/kyra/sound_adlib.cpp b/engines/kyra/sound_adlib.cpp
index fbf1ad5588..d10a5abfeb 100644
--- a/engines/kyra/sound_adlib.cpp
+++ b/engines/kyra/sound_adlib.cpp
@@ -156,7 +156,7 @@ private:
uint16 getRandomNr();
void update1(uint8 unk1, OutputState &state);
- void updateAndOutput1(uint8 unk1, OutputState &state);
+ void updateAndOutput1(uint8 rawNote, OutputState &state, bool flag = false);
void updateAndOutput2(uint8 unk1, uint8 *dataptr, OutputState &state);
void updateAndOutput3(OutputState &state);
@@ -717,7 +717,7 @@ void AdlibDriver::update1(uint8 unk1, OutputState &state) {
state.unk5 = unk1;
}
-void AdlibDriver::updateAndOutput1(uint8 rawNote, OutputState &state) {
+void AdlibDriver::updateAndOutput1(uint8 rawNote, OutputState &state, bool flag) {
debugC(9, kDebugLevelSound, "updateAndOutput1(%d, %d)", rawNote, &state - _outputTables);
state.rawNote = rawNote;
@@ -736,12 +736,25 @@ void AdlibDriver::updateAndOutput1(uint8 rawNote, OutputState &state) {
octave--;
}
+ // The calculation of frequency looks quite different from the original
+ // disassembly at a first glance, but when you consider that the
+ // largest possible value would be 0x0246 + 0xFF + 0x47 (and that's if
+ // baseFreq turns out to be unsigned after all), freq is still a 10-bit
+ // value, just as it should be to fit in the Ax and Bx registers.
+ //
+ // If it were larger than that, it could have overflowed into the
+ // octave bits, and that could possibly have been used in some sound.
+ // But as it is now, I can't see any way it would happen.
+
uint16 freq = _unkTable[note] + state.baseFreq;
- if (state.unk16) {
+ // When called from callback 41, the behaviour is slightly different:
+ // We adjust the frequency, even when state.unk16 is 0.
+
+ if (state.unk16 || flag) {
const uint8 *table;
- if (state.unk16 > 0) {
+ if (state.unk16 >= 0) {
table = _unkTables[(state.rawNote & 0x0F) + 2];
freq += table[state.unk16];
} else {
@@ -1279,7 +1292,7 @@ int AdlibDriver::updateCallback40(uint8 *&dataptr, OutputState &state, uint8 val
int AdlibDriver::updateCallback41(uint8 *&dataptr, OutputState &state, uint8 value) {
state.unk16 = value;
- updateAndOutput1(state.rawNote, state);
+ updateAndOutput1(state.rawNote, state, true);
return 0;
}