aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth/fmtowns_pc98
diff options
context:
space:
mode:
authorathrxx2011-04-29 22:16:02 +0200
committerWillem Jan Palenstijn2011-05-17 20:24:24 +0200
commit5c34e33c2c27b2b5083199b40306370d732f4e53 (patch)
treedaa2f5103ef488ee02edc655e956cce46c30b52d /audio/softsynth/fmtowns_pc98
parent52d81727a3c4ee5a5737b10366951021066eda13 (diff)
downloadscummvm-rg350-5c34e33c2c27b2b5083199b40306370d732f4e53.tar.gz
scummvm-rg350-5c34e33c2c27b2b5083199b40306370d732f4e53.tar.bz2
scummvm-rg350-5c34e33c2c27b2b5083199b40306370d732f4e53.zip
FM-TOWNS AUDIO: Some more midi driver code for FM-TOWNS monkey2 and indy4
Diffstat (limited to 'audio/softsynth/fmtowns_pc98')
-rw-r--r--audio/softsynth/fmtowns_pc98/towns_midi.cpp239
-rw-r--r--audio/softsynth/fmtowns_pc98/towns_midi.h70
-rw-r--r--audio/softsynth/fmtowns_pc98/towns_pc98_plugins.cpp87
3 files changed, 396 insertions, 0 deletions
diff --git a/audio/softsynth/fmtowns_pc98/towns_midi.cpp b/audio/softsynth/fmtowns_pc98/towns_midi.cpp
new file mode 100644
index 0000000000..c223d44c11
--- /dev/null
+++ b/audio/softsynth/fmtowns_pc98/towns_midi.cpp
@@ -0,0 +1,239 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: $
+ * $Id: $
+ */
+
+#include "audio/softsynth/fmtowns_pc98/towns_midi.h"
+#include "common/textconsole.h"
+
+class MidiChannel_TOWNS : public MidiChannel {
+public:
+ MidiChannel_TOWNS(MidiDriver_TOWNS *driver);
+ ~MidiChannel_TOWNS();
+
+ MidiDriver *device() { return _driver; }
+ byte getNumber() { return 0; }
+ void release();
+
+ void send(uint32 b);
+
+ void noteOff(byte note);
+ void noteOn(byte note, byte velocity);
+ void programChange(byte program);
+ void pitchBend(int16 bend);
+ void controlChange(byte control, byte value);
+ void pitchBendFactor(byte value);
+ void priority(byte value);
+
+ void sysEx_customInstrument(uint32 type, const byte *instr);
+
+private:
+ MidiDriver_TOWNS *_driver;
+};
+
+MidiChannel_TOWNS::MidiChannel_TOWNS(MidiDriver_TOWNS *driver) : MidiChannel(), _driver(driver) {
+
+}
+
+MidiChannel_TOWNS::~MidiChannel_TOWNS() {
+
+}
+
+void MidiChannel_TOWNS::release() {
+
+}
+
+void MidiChannel_TOWNS::send(uint32 b) {
+
+}
+
+void MidiChannel_TOWNS::noteOff(byte note) {
+
+}
+
+void MidiChannel_TOWNS::noteOn(byte note, byte velocity) {
+
+}
+
+void MidiChannel_TOWNS::programChange(byte program) {
+
+}
+
+void MidiChannel_TOWNS::pitchBend(int16 bend) {
+
+}
+
+void MidiChannel_TOWNS::controlChange(byte control, byte value) {
+
+}
+
+void MidiChannel_TOWNS::pitchBendFactor(byte value) {
+
+}
+
+void MidiChannel_TOWNS::priority(byte value) {
+
+}
+
+void MidiChannel_TOWNS::sysEx_customInstrument(uint32 type, const byte *instr) {
+
+}
+
+MidiDriver_TOWNS::MidiDriver_TOWNS(Audio::Mixer *mixer) : _timerBproc(0), _timerBpara(0), _open(false) {
+ _intf = new TownsAudioInterface(mixer, this);
+ _channels = new MidiChannel_TOWNS*[16];
+ for (int i = 0; i < 16; i++)
+ _channels[i] = new MidiChannel_TOWNS(this);
+
+ _tickCounter = 0;
+ _curChan = 0;
+ //unbuffered write: _intf->callback(17, part, reg, val);
+ //buffered write: _intf->callback(19, part, reg, val);
+}
+
+MidiDriver_TOWNS::~MidiDriver_TOWNS() {
+ close();
+ delete _intf;
+ setTimerCallback(0, 0);
+
+ for (int i = 0; i < 16; i++)
+ delete _channels[i];
+ delete[] _channels;
+}
+
+int MidiDriver_TOWNS::open() {
+ if (_open)
+ return MERR_ALREADY_OPEN;
+
+ if (!_intf->init())
+ return MERR_CANNOT_CONNECT;
+
+ _intf->callback(0);
+
+ _intf->callback(21, 255, 1);
+ _intf->callback(21, 0, 1);
+ _intf->callback(22, 255, 221);
+
+ _intf->callback(33, 8);
+ _intf->setSoundEffectChanMask(~0x3f);
+
+ _open = true;
+
+ return 0;
+}
+
+void MidiDriver_TOWNS::close() {
+ _open = false;
+}
+
+void MidiDriver_TOWNS::send(uint32 b) {
+ byte param2 = (b >> 16) & 0xFF;
+ byte param1 = (b >> 8) & 0xFF;
+ byte cmd = b & 0xF0;
+
+ /*AdLibPart *part;
+ if (chan == 9)
+ part = &_percussion;
+ else**/
+ MidiChannel_TOWNS *c = _channels[b & 0x0F];
+
+ switch (cmd) {
+ case 0x80:
+ //part->noteOff(param1);
+ break;
+ case 0x90:
+ //part->noteOn(param1, param2);
+ if (param2)
+ c->noteOn(param1, param2);
+ else
+ c->noteOff(param1);
+ break;
+ case 0xB0:
+ // supported: 1, 7, 0x40
+ c->controlChange(param1, param2);
+ break;
+ case 0xC0:
+ c->programChange(param1);
+ break;
+ case 0xE0:
+ //part->pitchBend((param1 | (param2 << 7)) - 0x2000);
+ c->pitchBend((param1 | (param2 << 7)) - 0x2000);
+ break;
+ case 0xF0:
+ warning("MidiDriver_ADLIB: Receiving SysEx command on a send() call");
+ break;
+
+ default:
+ break;
+ }
+}
+
+void MidiDriver_TOWNS::setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) {
+ _timerBproc = timer_proc;
+ _timerBpara = timer_param;
+}
+
+uint32 MidiDriver_TOWNS::getBaseTempo() {
+ return 0;
+}
+
+MidiChannel *MidiDriver_TOWNS::allocateChannel() {
+ MidiChannel *res = 0;
+
+ for (int i = 0; i < 6; i++) {
+ if (++_curChan == 6)
+ _curChan = 0;
+
+ //if (_channels[i]-> //// )
+ // return _channels[i];
+
+ }
+
+ //if (res)
+ // res->noteOff();
+
+ return res;
+}
+
+MidiChannel *MidiDriver_TOWNS::getPercussionChannel() {
+ return 0;
+}
+
+void MidiDriver_TOWNS::timerCallback(int timerId) {
+ if (!_open)
+ return;
+
+ switch (timerId) {
+ case 1:
+ if (_timerBproc) {
+ _timerBproc(_timerBpara);
+ _tickCounter += 10000;
+ while (_tickCounter >= 4167) {
+ _tickCounter -= 4167;
+ //_timerBproc(_timerBpara);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
diff --git a/audio/softsynth/fmtowns_pc98/towns_midi.h b/audio/softsynth/fmtowns_pc98/towns_midi.h
new file mode 100644
index 0000000000..658c5a456b
--- /dev/null
+++ b/audio/softsynth/fmtowns_pc98/towns_midi.h
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: $
+ * $Id: $
+ */
+
+#ifndef TOWNS_MIDI_H
+#define TOWNS_MIDI_H
+
+#include "audio/mididrv.h"
+#include "audio/softsynth/fmtowns_pc98/towns_audio.h"
+
+class MidiChannel_TOWNS;
+class MidiDriver_TOWNS : public MidiDriver, public TownsAudioInterfacePluginDriver {
+friend class MidiChannel_TOWNS;
+public:
+ MidiDriver_TOWNS(Audio::Mixer *mixer);
+ ~MidiDriver_TOWNS();
+
+ int open();
+ bool isOpen() const { return _open; }
+ void close();
+ void send(uint32 b);
+ //virtual uint32 property(int prop, uint32 param) { return 0; }
+ //virtual void sysEx(const byte *msg, uint16 length) { }
+ //virtual void sysEx_customInstrument(byte channel, uint32 type, const byte *instr) { }
+ //virtual void metaEvent(byte type, byte *data, uint16 length) { }
+ void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc);
+ uint32 getBaseTempo();
+ MidiChannel *allocateChannel();
+ MidiChannel *getPercussionChannel();
+
+ void timerCallback(int timerId);
+
+ TownsAudioInterface *intf() { return _intf; }
+
+private:
+ MidiChannel_TOWNS **_channels;
+
+ Common::TimerManager::TimerProc _timerBproc;
+ void *_timerBpara;
+
+ TownsAudioInterface *_intf;
+
+ uint32 _tickCounter;
+ uint8 _curChan;
+
+ bool _open;
+};
+
+#endif
+
diff --git a/audio/softsynth/fmtowns_pc98/towns_pc98_plugins.cpp b/audio/softsynth/fmtowns_pc98/towns_pc98_plugins.cpp
new file mode 100644
index 0000000000..bbde75eb66
--- /dev/null
+++ b/audio/softsynth/fmtowns_pc98/towns_pc98_plugins.cpp
@@ -0,0 +1,87 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: $
+ * $Id: $
+ */
+
+#include "audio/softsynth/fmtowns_pc98/towns_midi.h"
+#include "audio/musicplugin.h"
+#include "common/translation.h"
+#include "common/error.h"
+
+
+class TownsEmuMusicPlugin : public MusicPluginObject {
+public:
+ const char *getName() const {
+ return _s("FM-Towns Audio");
+ }
+
+ const char *getId() const {
+ return "towns";
+ }
+
+ MusicDevices getDevices() const;
+ Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
+};
+
+MusicDevices TownsEmuMusicPlugin::getDevices() const {
+ MusicDevices devices;
+ devices.push_back(MusicDevice(this, "", MT_TOWNS));
+ return devices;
+}
+
+Common::Error TownsEmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
+ *mididriver = new MidiDriver_TOWNS(g_system->getMixer());
+ return Common::kNoError;
+}
+
+class PC98EmuMusicPlugin : public MusicPluginObject {
+public:
+ const char *getName() const {
+ return _s("PC-98 Audio");
+ }
+
+ const char *getId() const {
+ return "pc98";
+ }
+
+ MusicDevices getDevices() const;
+ Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
+};
+
+MusicDevices PC98EmuMusicPlugin::getDevices() const {
+ MusicDevices devices;
+ devices.push_back(MusicDevice(this, "", MT_PC98));
+ return devices;
+}
+
+Common::Error PC98EmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
+ //*mididriver = /**/
+ return Common::kNoError;
+}
+
+//#if PLUGIN_ENABLED_DYNAMIC(TOWNS)
+ //REGISTER_PLUGIN_DYNAMIC(TOWNS, PLUGIN_TYPE_MUSIC, TownsEmuMusicPlugin);
+ //REGISTER_PLUGIN_DYNAMIC(TOWNS, PLUGIN_TYPE_MUSIC, TownsEmuMusicPlugin);
+//#else
+ REGISTER_PLUGIN_STATIC(TOWNS, PLUGIN_TYPE_MUSIC, TownsEmuMusicPlugin);
+ REGISTER_PLUGIN_STATIC(PC98, PLUGIN_TYPE_MUSIC, PC98EmuMusicPlugin);
+//#endif