diff options
author | Torbjörn Andersson | 2004-03-19 07:36:20 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-03-19 07:36:20 +0000 |
commit | 578b87b856121a3718abbc4d5b2026762afa2ade (patch) | |
tree | c120648d8d0a4d2c8b1f096a4ad023b6fee1fb56 | |
parent | da0c6e41d3212e0e24c170c59711826167e9bed9 (diff) | |
download | scummvm-rg350-578b87b856121a3718abbc4d5b2026762afa2ade.tar.gz scummvm-rg350-578b87b856121a3718abbc4d5b2026762afa2ade.tar.bz2 scummvm-rg350-578b87b856121a3718abbc4d5b2026762afa2ade.zip |
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.
svn-id: r13341
-rw-r--r-- | backends/midi/adlib.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/backends/midi/adlib.cpp b/backends/midi/adlib.cpp index 6b6ebb3528..662c7d450b 100644 --- a/backends/midi/adlib.cpp +++ b/backends/midi/adlib.cpp @@ -573,8 +573,6 @@ private: bool _isOpen; bool _game_SmallHeader; - static Common::RandomSource _rnd; - FM_OPL *_opl; byte *_adlib_reg_cache; SoundMixer *_mixer; @@ -626,6 +624,7 @@ private: 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 @@ void MidiDriver_ADLIB::struct10_setup(Struct10 *s10) { 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 @@ void MidiDriver_ADLIB::struct10_setup(Struct10 *s10) { 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 @@ void MidiDriver_ADLIB::adlib_playnote(int channel, int note) { 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 @@ void MidiDriver_ADLIB::adlib_note_on(int chan, byte note, int mod) { curnote_table[chan] = code; adlib_playnote(chan, (int16) channel_table_2[chan] + code); } - -Common::RandomSource MidiDriver_ADLIB::_rnd; |