[Scummvm-cvs-logs] SF.net SVN: scummvm: [21199] scummvm/trunk/engines/kyra/sound_adlib.cpp
eriktorbjorn at users.sourceforge.net
eriktorbjorn at users.sourceforge.net
Fri Mar 10 01:25:10 CET 2006
Revision: 21199
Author: eriktorbjorn
Date: 2006-03-10 01:24:50 -0800 (Fri, 10 Mar 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=21199&view=rev
Log Message:
-----------
The calculateLowByte1() and 2() functions are used for calculating the "total
level", which I believe is the individual channel volume. (The functions also
return the "scaling level" bits, but they are preserved, not calculated.) I
have renamed these functions calculateOpLevel1() and 2().
The unk25 and unk26 variables have been renamed opLevel1 and opLevel2. These
are called oplvl_1 and oplvl_2 in our MidiDriver_ADLIB class.
The unk26, unk27 and unk28 variables are potentially added to both operator
levels, and have been renamed opExtraLevel1, opExtralevel2 and opExtraLevel3.
The updateCallback25() function has been remamed update_setExtraLevel1().
The updateCallback33() function has been renamed update_setExtraLevel2().
The updateCallback32() function has been renamed update_setExtraLevel3().
Note that these callbacks aren't quite as similar as their names would seem to
indicate: They differ in whether or not the volume is updated and/or how the
parameters are passed.
Modified Paths:
--------------
scummvm/trunk/engines/kyra/sound_adlib.cpp
Modified: scummvm/trunk/engines/kyra/sound_adlib.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound_adlib.cpp 2006-03-10 08:55:19 UTC (rev 21198)
+++ scummvm/trunk/engines/kyra/sound_adlib.cpp 2006-03-10 09:24:50 UTC (rev 21199)
@@ -93,7 +93,7 @@
int snd_clearFlag(va_list &list);
struct OutputState {
- uint8 unk27;
+ uint8 opExtraLevel2;
uint8 *dataptr;
uint8 unk5;
uint8 repeatCounter;
@@ -113,7 +113,7 @@
uint8 unk32;
uint8 unk41;
uint8 unk38;
- uint8 unk26;
+ uint8 opExtraLevel1;
uint8 unk7;
uint8 baseFreq;
int8 unk1;
@@ -124,9 +124,9 @@
Callback callback1;
Callback callback2;
uint8 unk12;
- uint8 unk24;
- uint8 unk25;
- uint8 unk28;
+ uint8 opLevel1;
+ uint8 opLevel2;
+ uint8 opExtraLevel3;
uint8 twoChan;
uint8 unk39;
uint8 unk40;
@@ -162,8 +162,8 @@
void adjustVolume(OutputState &state);
- uint8 calculateLowByte1(OutputState &state);
- uint8 calculateLowByte2(OutputState &state);
+ uint8 calculateOpLevel1(OutputState &state);
+ uint8 calculateOpLevel2(OutputState &state);
uint16 checkValue(int16 val) {
if (val < 0)
@@ -208,15 +208,15 @@
int updateCallback22(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback23(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback24(uint8 *&dataptr, OutputState &state, uint8 value);
- int updateCallback25(uint8 *&dataptr, OutputState &state, uint8 value);
+ int update_setExtraLevel1(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback26(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback27(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback28(uint8 *&dataptr, OutputState &state, uint8 value);
int update_setTempo(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback30(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback31(uint8 *&dataptr, OutputState &state, uint8 value);
- int updateCallback32(uint8 *&dataptr, OutputState &state, uint8 value);
- int updateCallback33(uint8 *&dataptr, OutputState &state, uint8 value);
+ int update_setExtraLevel3(uint8 *&dataptr, OutputState &state, uint8 value);
+ int update_setExtraLevel2(uint8 *&dataptr, OutputState &state, uint8 value);
int updateCallback34(uint8 *&dataptr, OutputState &state, uint8 value);
int update_setAMDepth(uint8 *&dataptr, OutputState &state, uint8 value);
int update_setVibratoDepth(uint8 *&dataptr, OutputState &state, uint8 value);
@@ -799,12 +799,12 @@
writeOPL(0xE0 + regOffset, *dataptr++);
writeOPL(0xE3 + regOffset, *dataptr++);
- state.unk24 = *dataptr++;
- state.unk25 = *dataptr++;
+ state.opLevel1 = *dataptr++;
+ state.opLevel2 = *dataptr++;
// Level Key Scaling / Total Level
- writeOPL(0x40 + regOffset, calculateLowByte1(state));
- writeOPL(0x43 + regOffset, calculateLowByte2(state));
+ writeOPL(0x40 + regOffset, calculateOpLevel1(state));
+ writeOPL(0x43 + regOffset, calculateOpLevel2(state));
// Attack Rate / Decay Rate
writeOPL(0x60 + regOffset, *dataptr++);
@@ -831,16 +831,11 @@
void AdlibDriver::adjustVolume(OutputState &state) {
debugC(9, kDebugLevelSound, "adjustVolume(%d)", &state - _outputTables);
- uint8 lowByte = calculateLowByte2(state);
-
// Level Key Scaling / Total Level
- writeOPL(0x43 + _outputTable[_curTable], lowByte);
- if (state.twoChan) {
- lowByte = calculateLowByte1(state);
- // Level Key Scaling / Total Level
- writeOPL(0x40 + _outputTable[_curTable], lowByte);
- }
+ writeOPL(0x43 + _outputTable[_curTable], calculateOpLevel2(state));
+ if (state.twoChan)
+ writeOPL(0x40 + _outputTable[_curTable], calculateOpLevel1(state));
}
void AdlibDriver::stateCallback1_1(OutputState &state) {
@@ -924,34 +919,44 @@
}
}
-uint8 AdlibDriver::calculateLowByte1(OutputState &state) {
- int8 value = state.unk24 & 0x3F;
+uint8 AdlibDriver::calculateOpLevel1(OutputState &state) {
+ int8 value = state.opLevel1 & 0x3F;
+
if (state.twoChan) {
- value += state.unk26;
- value += state.unk27;
- value += state.unk28;
+ value += state.opExtraLevel1;
+ value += state.opExtraLevel2;
+ value += state.opExtraLevel3;
}
+ // Don't allow the total level to overflow into the scaling level bits.
+
if (value > 0x3F) {
value = 0x3F;
} else if (value < 0)
value = 0;
- return value | (state.unk24 & 0xC0);
+ // Preserve the scaling level bits from opLevel1
+
+ return value | (state.opLevel1 & 0xC0);
}
-uint8 AdlibDriver::calculateLowByte2(OutputState &state) {
- int8 value = state.unk25 & 0x3F;
- value += state.unk26;
- value += state.unk27;
- value += state.unk28;
+uint8 AdlibDriver::calculateOpLevel2(OutputState &state) {
+ int8 value = state.opLevel2 & 0x3F;
+ value += state.opExtraLevel1;
+ value += state.opExtraLevel2;
+ value += state.opExtraLevel3;
+
+ // Don't allow the total level to overflow into the scaling level bits.
+
if (value > 0x3F) {
value = 0x3F;
} else if (value < 0)
value = 0;
- return value | (state.unk25 & 0xC0);
+ // Preserve the scaling level bits from opLevel2
+
+ return value | (state.opLevel2 & 0xC0);
}
// parser opcodes
@@ -1152,8 +1157,8 @@
return 2;
}
-int AdlibDriver::updateCallback25(uint8 *&dataptr, OutputState &state, uint8 value) {
- state.unk26 = value;
+int AdlibDriver::update_setExtraLevel1(uint8 *&dataptr, OutputState &state, uint8 value) {
+ state.opExtraLevel1 = value;
adjustVolume(state);
return 0;
}
@@ -1190,17 +1195,18 @@
return 0;
}
-int AdlibDriver::updateCallback32(uint8 *&dataptr, OutputState &state, uint8 value) {
- state.unk28 = value;
+int AdlibDriver::update_setExtraLevel3(uint8 *&dataptr, OutputState &state, uint8 value) {
+ state.opExtraLevel3 = value;
return 0;
+
}
-int AdlibDriver::updateCallback33(uint8 *&dataptr, OutputState &state, uint8 value) {
+int AdlibDriver::update_setExtraLevel2(uint8 *&dataptr, OutputState &state, uint8 value) {
int tableBackup = _curTable;
_curTable = value;
OutputState &state2 = _outputTables[value];
- state2.unk27 = *dataptr++;
+ state2.opExtraLevel2 = *dataptr++;
adjustVolume(state2);
_curTable = tableBackup;
@@ -1212,7 +1218,7 @@
_curTable = value;
OutputState &state2 = _outputTables[value];
- state2.unk27 += *dataptr++;
+ state2.opExtraLevel2 += *dataptr++;
adjustVolume(state2);
_curTable = tableBackup;
@@ -1242,7 +1248,7 @@
}
int AdlibDriver::updateCallback37(uint8 *&dataptr, OutputState &state, uint8 value) {
- state.unk26 += value;
+ state.opExtraLevel1 += value;
adjustVolume(state);
return 0;
}
@@ -1254,7 +1260,7 @@
OutputState &state2 = _outputTables[value];
state2.unk5 = state2.unk2 = 0;
state2.dataptr = 0;
- state2.unk27 = 0;
+ state2.opExtraLevel2 = 0;
if (value != 9) {
uint8 outValue = _outputTable[value];
@@ -1698,7 +1704,7 @@
// 28
COMMAND(updateCallback23),
COMMAND(updateCallback24),
- COMMAND(updateCallback25),
+ COMMAND(update_setExtraLevel1),
COMMAND(updateCallback9),
// 32
@@ -1717,10 +1723,10 @@
COMMAND(updateCallback9),
COMMAND(updateCallback31),
COMMAND(updateCallback9),
- COMMAND(updateCallback32),
+ COMMAND(update_setExtraLevel3),
// 44
- COMMAND(updateCallback33),
+ COMMAND(update_setExtraLevel2),
COMMAND(updateCallback34),
COMMAND(update_setAMDepth),
COMMAND(update_setVibratoDepth),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list