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
This commit is contained in:
Torbjörn Andersson 2006-03-09 18:42:05 +00:00
parent c571026a20
commit a5e0c392ba

View File

@ -156,7 +156,7 @@ private:
uint16 getRandomNr(); uint16 getRandomNr();
void update1(uint8 unk1, OutputState &state); 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 updateAndOutput2(uint8 unk1, uint8 *dataptr, OutputState &state);
void updateAndOutput3(OutputState &state); void updateAndOutput3(OutputState &state);
@ -717,7 +717,7 @@ void AdlibDriver::update1(uint8 unk1, OutputState &state) {
state.unk5 = unk1; 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); debugC(9, kDebugLevelSound, "updateAndOutput1(%d, %d)", rawNote, &state - _outputTables);
state.rawNote = rawNote; state.rawNote = rawNote;
@ -736,12 +736,25 @@ void AdlibDriver::updateAndOutput1(uint8 rawNote, OutputState &state) {
octave--; 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; 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; const uint8 *table;
if (state.unk16 > 0) { if (state.unk16 >= 0) {
table = _unkTables[(state.rawNote & 0x0F) + 2]; table = _unkTables[(state.rawNote & 0x0F) + 2];
freq += table[state.unk16]; freq += table[state.unk16];
} else { } else {
@ -1279,7 +1292,7 @@ int AdlibDriver::updateCallback40(uint8 *&dataptr, OutputState &state, uint8 val
int AdlibDriver::updateCallback41(uint8 *&dataptr, OutputState &state, uint8 value) { int AdlibDriver::updateCallback41(uint8 *&dataptr, OutputState &state, uint8 value) {
state.unk16 = value; state.unk16 = value;
updateAndOutput1(state.rawNote, state); updateAndOutput1(state.rawNote, state, true);
return 0; return 0;
} }