[Scummvm-cvs-logs] CVS: scummvm/backends/midi adlib.cpp,1.56,1.57
Torbj?rn Andersson
eriktorbjorn at users.sourceforge.net
Fri Mar 19 00:15:29 CET 2004
Update of /cvsroot/scummvm/scummvm/backends/midi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20124
Modified Files:
adlib.cpp
Log Message:
Reverted to the old random_nr() function. This appears to have been the
cause of bug #916886: Calling getRandomNumber(-1) causes ScummVM to crash,
while calling random_nr(-1) doesn't. We may still want to replace it with
getRandomNumber() later, of course.
Index: adlib.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/adlib.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- adlib.cpp 13 Mar 2004 18:44:09 -0000 1.56
+++ adlib.cpp 19 Mar 2004 07:36:20 -0000 1.57
@@ -573,8 +573,6 @@
bool _isOpen;
bool _game_SmallHeader;
- static Common::RandomSource _rnd;
-
FM_OPL *_opl;
byte *_adlib_reg_cache;
SoundMixer *_mixer;
@@ -626,6 +624,7 @@
void struct10_init(Struct10 * s10, InstrumentExtra * ie);
static byte struct10_ontimer(Struct10 * s10, Struct11 * s11);
static void struct10_setup(Struct10 * s10);
+ static int random_nr(int a);
void mc_key_on(AdlibVoice *voice, AdlibInstrument *instr, byte note, byte velocity);
static void premix_proc(void *param, int16 *buf, uint len);
@@ -1231,7 +1230,7 @@
t = s10->table_a[f];
e = num_steps_table[lookup_table[t & 0x7F][b]];
if (t & 0x80) {
- e = _rnd.getRandomNumber(e);
+ e = random_nr(e);
}
if (e == 0)
e++;
@@ -1244,7 +1243,7 @@
t = s10->table_b[f];
d = lookup_volume(c, (t & 0x7F) - 31);
if (t & 0x80) {
- d = _rnd.getRandomNumber(d);
+ d = random_nr(d);
}
if (d + g > c) {
h = c - g;
@@ -1306,6 +1305,21 @@
adlib_write(channel + 0xB0, oct | 0x20);
}
+// TODO: Replace this with RandomSource? But if so, please note that this
+// function will be called with negative parameters - getRandomNumber(-1) will
+// crash ScummVM, random_nr(-1) won't.
+
+int MidiDriver_ADLIB::random_nr(int a) {
+ static byte _rand_seed = 1;
+ if (_rand_seed & 1) {
+ _rand_seed >>= 1;
+ _rand_seed ^= 0xB8;
+ } else {
+ _rand_seed >>= 1;
+ }
+ return _rand_seed * a >> 8;
+}
+
void MidiDriver_ADLIB::part_key_off(AdlibPart *part, byte note) {
AdlibVoice *voice;
@@ -1554,5 +1568,3 @@
curnote_table[chan] = code;
adlib_playnote(chan, (int16) channel_table_2[chan] + code);
}
-
-Common::RandomSource MidiDriver_ADLIB::_rnd;
More information about the Scummvm-git-logs
mailing list