[Scummvm-cvs-logs] SF.net SVN: scummvm: [21102] scummvm/trunk/engines/kyra/sound_adlib.cpp

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sun Mar 5 16:57:29 CET 2006


Revision: 21102
Author:   eriktorbjorn
Date:     2006-03-05 12:09:02 -0800 (Sun, 05 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm?rev=21102&view=rev

Log Message:
-----------
The updateUnk6Value() appears to be some sort of random number generator, so I
have renamed it getRandomNr(). The _unk6 variable has been renamed _rnd. (Our
MidiDriver_ADLIB class also has its own random number generator, so it's not
such a far-fetched guess as it may seem.)

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-05 19:48:22 UTC (rev 21101)
+++ scummvm/trunk/engines/kyra/sound_adlib.cpp	2006-03-05 20:09:02 UTC (rev 21102)
@@ -248,7 +248,7 @@
 	uint8 _unk5;
 	int _soundsPlaying;
 
-	uint16 _unk6;
+	uint16 _rnd;
 	uint8 _continueFlag;
 
 	uint8 _unkValue1;
@@ -320,7 +320,7 @@
 	_unkOutputByte2 = _unkOutputByte1 = 0;
 
 	_lastProcessed = _flagTrigger = _curTable = _unk4 = 0;
-	_unk6 = 0x1234;
+	_rnd = 0x1234;
 	_continueFlag = 0;
 
 	_unkTableByte1 = 0;
@@ -611,7 +611,7 @@
 
 void AdlibDriver::resetAdlibState() {
 	debugC(9, kDebugLevelSound, "resetAdlibState()");
-	_unk6 = 0x1234;
+	_rnd = 0x1234;
 
 	// Authorize the control of the waveforms
 	writeOPL(0x01, 0x20);
@@ -692,19 +692,23 @@
 	writeOPL(0xB0 + num, 0x20);
 }
 
-uint16 AdlibDriver::updateUnk6Value() {
-	_unk6 += 0x9248;
-	uint16 lowBits = _unk6 & 7;
-	_unk6 >>= 3;
-	_unk6 |= lowBits << 13;
-	return _unk6;
+// I believe this is a random number generator. It actually does seem to
+// generate an even distribution of almost all numbers from 0 through 65535,
+// though in my tests some numbers were never generated.
+
+uint16 AdlibDriver::getRandomNr() {
+	_rnd += 0x9248;
+	uint16 lowBits = _rnd & 7;
+	_rnd >>= 3;
+	_rnd |= (lowBits << 13);
+	return _rnd;
 }
 
 void AdlibDriver::update1(uint8 unk1, OutputState &state) {
 	debugC(9, kDebugLevelSound, "update1(%d, %d)", unk1, &state - _outputTables);
 	_continueFlag = unk1;
 	if (state.unk11) {
-		state.unk5 = unk1 + (updateUnk6Value() & state.unk11 & 0xFF);
+		state.unk5 = unk1 + (getRandomNr() & state.unk11 & 0xFF);
 		return;
 	}
 	uint8 value = unk1;
@@ -1259,7 +1263,7 @@
 int AdlibDriver::updateCallback39(uint8 *&dataptr, OutputState &state, uint8 value) {
 	uint16 unk = *dataptr++;
 	unk |= value << 8;
-	unk &= updateUnk6Value();
+	unk &= getRandomNr();
 
 	uint16 unk2 = ((state.unkOutputValue1 & 0x1F) << 8) | state.unk17;
 	unk2 += unk;







More information about the Scummvm-git-logs mailing list