Ticket #8542: simon-adlib.diff

File simon-adlib.diff, 4.9 KB (added by eriktorbjorn, 18 years ago)

Patch against current SVN (2006-06-06)

  • engines/simon/simon.cpp

     
    450450                if (_native_mt32) {
    451451                        driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    452452                }
     453                if (midiDriver == MD_ADLIB) {
     454                        midi.property(PROP_ADLIB, 1);
     455                }
    453456        }
    454457
    455458        midi.mapMT32toGM (getGameType() == GType_SIMON1 && !_native_mt32);
  • engines/simon/midi.h

     
    3434
    3535namespace Simon {
    3636
     37enum {
     38        PROP_ADLIB
     39};
     40
    3741struct MusicInfo {
    3842        MidiParser *parser;
    3943        byte *data;
     
    5963        MidiDriver *_driver;
    6064        bool _map_mt32_to_gm;
    6165        bool _passThrough;
     66        bool _adlib;
    6267
    6368        MusicInfo _music;
    6469        MusicInfo _sfx;
     
    7479        byte _queuedTrack;
    7580        bool _loopQueuedTrack;
    7681
     82        byte *_adlibPatches;
     83
    7784protected:
    7885        static void onTimer(void *data);
    7986        void clearConstructs();
    8087        void clearConstructs(MusicInfo &info);
    8188        void resetVolumeTable();
     89        void loadAdlibPatches();
     90        void unloadAdlibPatches();
    8291
    8392public:
    8493        bool _enable_sfx;
     
    110119        int open();
    111120        void close();
    112121        void send(uint32 b);
     122        uint32 property(int prop, uint32 param);
    113123
    114124        void metaEvent(byte type, byte *data, uint16 length);
    115125        void setPassThrough(bool b)             { _passThrough = b; }
  • engines/simon/midi.cpp

     
    4646        _map_mt32_to_gm = false;
    4747        _passThrough = false;
    4848
     49        _adlib = false;
     50        _adlibPatches = NULL;
     51
    4952        _enable_sfx = true;
    5053        _current = 0;
    5154
     
    8487                _driver->close();
    8588        _driver = NULL;
    8689        clearConstructs();
     90        unloadAdlibPatches();
    8791//      _system->unlockMutex(_mutex);
    8892}
    8993
     
    103107                _current->volume[channel] = volume;
    104108                volume = volume * _masterVolume / 255;
    105109                b = (b & 0xFF00FFFF) | (volume << 16);
    106         } else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) {
    107                 b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8);
     110        } else if ((b & 0xF0) == 0xC0) {
     111                if (_map_mt32_to_gm && (!_adlib || !_adlibPatches)) {
     112                        b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8);
     113                }
    108114        } else if ((b & 0xFFF0) == 0x007BB0) {
    109115                // Only respond to an All Notes Off if this channel
    110116                // has already been allocated.
     
    129135        if (_current->channel[channel]) {
    130136                if (channel == 9)
    131137                        _current->channel[9]->volume(_current->volume[9] * _masterVolume / 255);
    132                 _current->channel[channel]->send(b);
     138                if ((b & 0xF0) == 0xC0 && _adlib && _adlibPatches) {
     139                        // NOTE: In the percussion channel, this function is a
     140                        //       no-op. Any percussion instruments you hear may
     141                        //       be the stock ones from adlib.cpp.
     142                        _driver->sysEx_customInstrument(_current->channel[channel]->getNumber(), 'ADL ', _adlibPatches + 30 * ((b >> 8) & 0xFF));
     143                } else {
     144                        _current->channel[channel]->send(b);
     145                }
    133146                if ((b & 0xFFF0) == 0x79B0) {
    134147                        // We have received a "Reset All Controllers" message
    135148                        // and passed it on to the MIDI driver. This may or may
     
    142155        }
    143156}
    144157
     158uint32 MidiPlayer::property(int prop, uint32 param) {
     159        if (prop == PROP_ADLIB) {
     160                uint32 ret = _adlib ? 1 : 0;
     161                _adlib = (param != 0);
     162                if (_adlib)
     163                        loadAdlibPatches();
     164                else
     165                        unloadAdlibPatches();
     166                return ret;
     167        }
     168        return MidiDriver::property(prop, param);
     169}
     170
    145171void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
    146172        // Only thing we care about is End of Track.
    147173        if (!_current || type != 0x2F) {
     
    352378        }
    353379}
    354380
     381void MidiPlayer::loadAdlibPatches() {
     382        if (!_adlib)
     383                return;
     384
     385        Common::File ibk;
     386
     387        if (!ibk.open("mt_fm.ibk"))
     388                return;
     389
     390        if (ibk.readUint32BE() == 0x49424b1a) {
     391                _adlibPatches = new byte[128 * 30];
     392                byte *ptr = _adlibPatches;
     393
     394                memset(_adlibPatches, 0, 128 * 30);
     395
     396                for (int i = 0; i < 128; i++) {
     397                        byte instr[16];
     398
     399                        ibk.read(instr, 16);
     400
     401                        ptr[0] = instr[0];   // Modulator Sound Characteristics
     402                        ptr[1] = instr[2];   // Modulator Scaling/Output Level
     403                        ptr[2] = ~instr[4];  // Modulator Attack/Decay
     404                        ptr[3] = ~instr[6];  // Modulator Sustain/Release
     405                        ptr[4] = instr[8];   // Modulator Wave Select
     406                        ptr[5] = instr[1];   // Carrier Sound Characteristics
     407                        ptr[6] = instr[3];   // Carrier Scaling/Output Level
     408                        ptr[7] = ~instr[5];  // Carrier Attack/Delay
     409                        ptr[8] = ~instr[7];  // Carrier Sustain/Release
     410                        ptr[9] = instr[9];   // Carrier Wave Select
     411                        ptr[10] = instr[10]; // Feedback/Connection
     412
     413                        // The remaining six bytes are reserved for future use
     414
     415                        ptr += 30;
     416                }
     417        }
     418}
     419
     420void MidiPlayer::unloadAdlibPatches() {
     421        delete[] _adlibPatches;
     422        _adlibPatches = NULL;
     423}
     424
    355425static int simon1_gmf_size[] = {
    356426        8900, 12166, 2848, 3442, 4034, 4508, 7064, 9730, 6014, 4742, 3138,
    357427        6570, 5384, 8909, 6457, 16321, 2742, 8968, 4804, 8442, 7717,