1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "audio/fmopl.h"
24 #include "audio/mididrv.h"
25 
26 namespace Queen {
27 
28 class AdLibMidiDriver : public MidiDriver {
29 public:
30 
AdLibMidiDriver()31 	AdLibMidiDriver() {
32 		_adlibWaveformSelect = 0;
33 		_isOpen = false;
34 	}
35 
~AdLibMidiDriver()36 	~AdLibMidiDriver() {}
37 
38 	// MidiDriver
39 	int open();
40 	void close();
41 	void send(uint32 b);
42 	void metaEvent(byte type, byte *data, uint16 length);
allocateChannel()43 	MidiChannel *allocateChannel() { return 0; }
getPercussionChannel()44 	MidiChannel *getPercussionChannel() { return 0; }
45 	void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc);
isOpen()46 	bool isOpen() const { return _isOpen; }
getBaseTempo()47 	uint32 getBaseTempo() { return 1000000 / OPL::OPL::kDefaultCallbackFrequency; }
48 
49 	void setVolume(uint32 volume);
50 
51 private:
52 
53 	void handleMidiEvent0x90_NoteOn(int channel, int param1, int param2);
54 	void handleSequencerSpecificMetaEvent1(int channel, const uint8 *data);
55 	void handleSequencerSpecificMetaEvent2(uint8 value);
56 	void handleSequencerSpecificMetaEvent3(uint8 value);
57 
58 	void adlibWrite(uint8 port, uint8 value);
59 	void adlibSetupCard();
60 	void adlibSetupChannels(int fl);
61 	void adlibResetAmpVibratoRhythm(int am, int vib, int kso);
62 	void adlibResetChannels();
63 	void adlibSetAmpVibratoRhythm();
64 	void adlibSetCSMKeyboardSplit();
65 	void adlibSetNoteMul(int mul);
66 	void adlibSetWaveformSelect(int fl);
67 	void adlibSetPitchBend(int channel, int range);
68 	void adlibPlayNote(int channel);
69 	uint8 adlibPlayNoteHelper(int channel, int note1, int note2, int oct);
70 	void adlibTurnNoteOff(int channel);
71 	void adlibTurnNoteOn(int channel, int note);
72 	void adlibSetupChannelFromSequence(int channel, const uint8 *src, int fl);
73 	void adlibSetupChannel(int channel, const uint16 *src, int fl);
74 	void adlibSetNoteVolume(int channel, int volume);
75 	void adlibSetChannelVolume(int channel, uint8 volume);
76 	void adlibSetupChannelHelper(int channel);
77 	void adlibSetChannel0x40(int channel);
78 	void adlibSetChannel0xC0(int channel);
79 	void adlibSetChannel0x60(int channel);
80 	void adlibSetChannel0x80(int channel);
81 	void adlibSetChannel0x20(int channel);
82 	void adlibSetChannel0xE0(int channel);
83 
84 	void onTimer();
85 
86 	OPL::OPL *_opl;
87 	int _midiNumberOfChannels;
88 	int _adlibNoteMul;
89 	int _adlibWaveformSelect;
90 	int _adlibAMDepthEq48;
91 	int _adlibVibratoDepthEq14;
92 	int _adlibRhythmEnabled;
93 	int _adlibKeyboardSplitOn;
94 	int _adlibVibratoRhythm;
95 	uint8 _midiChannelsFreqTable[9];
96 	uint8 _adlibChannelsLevelKeyScalingTable[11];
97 	uint8 _adlibSetupChannelSequence1[14 * 18];
98 	uint16 _adlibSetupChannelSequence2[14];
99 	int16 _midiChannelsNote2Table[9];
100 	uint8 _midiChannelsNote1Table[9];
101 	uint8 _midiChannelsOctTable[9];
102 	uint16 _adlibChannelsVolume[11];
103 	uint16 _adlibMetaSequenceData[28];
104 	uint8 _adlibChannelsVolumeTable[11];
105 
106 	bool _isOpen;
107 	Common::TimerManager::TimerProc _adlibTimerProc;
108 	void *_adlibTimerParam;
109 
110 	static const uint8 _adlibChannelsMappingTable1[];
111 	static const uint8 _adlibChannelsNoFeedback[];
112 	static const uint8 _adlibChannelsMappingTable2[];
113 	static const uint8 _adlibChannelsMappingTable3[];
114 	static const uint8 _adlibChannelsKeyScalingTable1[];
115 	static const uint8 _adlibChannelsKeyScalingTable2[];
116 	static const uint8 _adlibInitSequenceData1[];
117 	static const uint8 _adlibInitSequenceData2[];
118 	static const uint8 _adlibInitSequenceData3[];
119 	static const uint8 _adlibInitSequenceData4[];
120 	static const uint8 _adlibInitSequenceData5[];
121 	static const uint8 _adlibInitSequenceData6[];
122 	static const uint8 _adlibInitSequenceData7[];
123 	static const uint8 _adlibInitSequenceData8[];
124 	static const int16 _midiChannelsNoteTable[];
125 	static const int16 _midiNoteFreqTable[];
126 };
127 
128 } // End of namespace Queen
129