aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sfx/old
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/sfx/old')
-rw-r--r--engines/sci/sfx/old/Makefile24
-rw-r--r--engines/sci/sfx/old/README6
-rw-r--r--engines/sci/sfx/old/ROADMAP72
-rw-r--r--engines/sci/sfx/old/main.c49
-rw-r--r--engines/sci/sfx/old/midi.c30
-rw-r--r--engines/sci/sfx/old/midi.h30
-rw-r--r--engines/sci/sfx/old/midi_mt32.c341
-rw-r--r--engines/sci/sfx/old/midi_mt32.h29
-rw-r--r--engines/sci/sfx/old/midiout.c63
-rw-r--r--engines/sci/sfx/old/midiout.h29
-rw-r--r--engines/sci/sfx/old/midiout_alsaraw.c51
-rw-r--r--engines/sci/sfx/old/midiout_alsaraw.h28
-rw-r--r--engines/sci/sfx/old/midiout_unixraw.c52
-rw-r--r--engines/sci/sfx/old/midiout_unixraw.h28
14 files changed, 832 insertions, 0 deletions
diff --git a/engines/sci/sfx/old/Makefile b/engines/sci/sfx/old/Makefile
new file mode 100644
index 0000000000..f7235d945b
--- /dev/null
+++ b/engines/sci/sfx/old/Makefile
@@ -0,0 +1,24 @@
+CC = gcc
+CFLAGS = -O2 -Wall
+LIBS = -L/usr/lib -lasound
+objects = main.o midi_mt32.o midiout.o midiout_unixraw.o midiout_alsaraw.o
+
+sciplaymidi: $(objects)
+ $(CC) $(LIBS) -o sciplaymidi $(objects)
+
+main.o: main.c
+ $(CC) $(CFLAGS) -c main.c
+midi_mt32.o: midi_mt32.c midi_mt32.h midiout.h
+ $(CC) $(CFLAGS) -c midi_mt32.c
+midiout.o: midiout.c midiout.h midiout_unixraw.h midiout_alsaraw.h
+ $(CC) $(CFLAGS) -c midiout.c
+midiout_unixraw.o: midiout_unixraw.c midiout_unixraw.h
+ $(CC) $(CFLAGS) -c midiout_unixraw.c
+midiout_alsaraw.o: midiout_alsaraw.c midiout_alsaraw.h
+ $(CC) $(CFLAGS) -c midiout_alsaraw.c
+
+.PHONY: clean distclean
+clean:
+ rm -f sciplaymidi $(objects)
+distclean:
+ rm -f sciplaymidi $(objects) *~
diff --git a/engines/sci/sfx/old/README b/engines/sci/sfx/old/README
new file mode 100644
index 0000000000..c652175761
--- /dev/null
+++ b/engines/sci/sfx/old/README
@@ -0,0 +1,6 @@
+type 'make' and './sciplaymidi' to program your MT-32 with the file
+'patch.001' in the current directory
+
+Only tested with Linux and ALSA...
+
+Rickard Lind <rpl@dd.chalmers.se>
diff --git a/engines/sci/sfx/old/ROADMAP b/engines/sci/sfx/old/ROADMAP
new file mode 100644
index 0000000000..9a6ec1b4da
--- /dev/null
+++ b/engines/sci/sfx/old/ROADMAP
@@ -0,0 +1,72 @@
+The way I would have made things if I had the time to do it
+Rickard Lind <rpl@dd.chalmers.se>, 2000-12-30
+-------------------------------------------------------------------------------
+
+Step 1:
+
+D rename "src/sound/midi.c" in freesci to "oldmidi.c" and still use it
+D move my "midi*" and "midiout*" to "src/sound"
+D change all "glib.h" to the real thing
+
+Step 2:
+
+D implement all note-playing, volume changing, reverb etc in "midi_mt32.*"
+ use disassembled sierra SCI1.1 driver as the main source of inspiration
+D change "soundserver_null.c" to use the new device driver for MT-32
+* use "~/.freesci/config" to set ALSA/OSS and other options
+
+Step 3:
+
+* Implement a GM translation driver "midi_gm.*" using a parsed textfile
+ for instrument mapping
+* Improve instrument mappings using new features such as keyshift,
+ volume adjust and velocity remap
+
+Step 4:
+
+* Reimplement a SCI0 soundserver using the new sound sub sytem
+* PCM support (samples) with ALSA and possibly DirectX
+* MPU-401 UART midiout driver for DOS/Windows
+
+Step 5:
+
+* SCI01, SCI1, SCI32 soundserver
+* Adlib support "midi_opl2.*", "oplout_alsaraw.*", "oplout_pcmemu.*"
+* PCM support Sound Blaster DOS
+
+Step 6:
+
+* Make it possible to play samples and use opl2 emulation (found in MAME
+ I think) at the same time through the same sound device
+
+Step 7:
+
+* All those other little nifty things...
+
+-------------------------------------------------------------------------------
+
+My idea concerning naming of the files:
+
+src/sound/midi.* wrapper for MIDI device drivers
+src/sound/midiout.* wrapper for different methods to output
+ MIDI data
+src/sound/pcm.* wrapper for PCM device drivers
+src/sound/pcmout.* wrapper for different methods to output
+ PCM data
+src/sound/midi_mt32.* Roland MT-32 device driver
+src/sound/midi_opl2.* Adlib/OPL2 device driver
+src/sound/midiout_alsaraw.* rawmidi output using alsalib
+src/sound/midiout_unixraw.* rawmidi output using unix filesystem
+src/sound/oplout_alsaraw.* opl output using alsa
+
+-------------------------------------------------------------------------------
+
+Use Linux and ALSA 0.5.x (or later) and Roland MT-32 while developing.
+Don't implement supremely stupid abstract frameworks without consulting
+experienced people on the mailinglist first. There are infinite ways to
+implement the sound subsystem the VERY VERY WRONG way. Don't make
+everything too much of a hack either.
+
+Use the files is in "lists/" when doing text output for debugging purposes.
+
+Good luck!
diff --git a/engines/sci/sfx/old/main.c b/engines/sci/sfx/old/main.c
new file mode 100644
index 0000000000..73daebd1bb
--- /dev/null
+++ b/engines/sci/sfx/old/main.c
@@ -0,0 +1,49 @@
+/***************************************************************************
+ main.c Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "midi_mt32.h"
+
+int main()
+{
+ int fd;
+ unsigned char *patch;
+ unsigned int length;
+
+ patch = (unsigned char *)sci_malloc(65536);
+
+ fd = open("patch.001", O_RDONLY);
+ length = read(fd, patch, 65536);
+ close(fd);
+
+ if (patch[0] == 0x89 && patch[1] == 0x00)
+ midi_mt32_open(patch + 2, length - 2);
+ else
+ midi_mt32_open(patch, length);
+
+ midi_mt32_close();
+
+ free(patch);
+ return 0;
+}
diff --git a/engines/sci/sfx/old/midi.c b/engines/sci/sfx/old/midi.c
new file mode 100644
index 0000000000..1be951befb
--- /dev/null
+++ b/engines/sci/sfx/old/midi.c
@@ -0,0 +1,30 @@
+/***************************************************************************
+ midi.c Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#ifndef _MIDI_MT32_H_
+#define _MIDI_MT32_H_
+
+int midi_mt32_open(guint8 *data_ptr, unsigned int data_length);
+int midi_mt32_close();
+
+int midi_mt32_noteoff(guint8 channel, guint8 note);
+int midi_mt32_noteon(guint8 channel, guint8 note, guint8 velocity);
+
+#endif /* _MIDI_MT32_H_ */
diff --git a/engines/sci/sfx/old/midi.h b/engines/sci/sfx/old/midi.h
new file mode 100644
index 0000000000..9a816781d3
--- /dev/null
+++ b/engines/sci/sfx/old/midi.h
@@ -0,0 +1,30 @@
+/***************************************************************************
+ midi.h Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#ifndef _MIDI_H_
+#define _MIDI_H_
+
+int midi_open(guint8 *data_ptr, unsigned int data_length);
+int midi_close();
+
+int midi_noteoff(guint8 channel, guint8 note);
+int midi_noteon(guint8 channel, guint8 note, guint8 velocity);
+
+#endif /* _MIDI_H_ */
diff --git a/engines/sci/sfx/old/midi_mt32.c b/engines/sci/sfx/old/midi_mt32.c
new file mode 100644
index 0000000000..be5550bd93
--- /dev/null
+++ b/engines/sci/sfx/old/midi_mt32.c
@@ -0,0 +1,341 @@
+/***************************************************************************
+ midi_mt32.c Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#include "glib.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "midi_mt32.h"
+#include "midiout.h"
+
+#define RHYTHM_CHANNEL 9
+
+int midi_mt32_poke(guint32 address, guint8 *data, unsigned int n);
+int midi_mt32_poke_gather(guint32 address, guint8 *data1, unsigned int count1,
+ guint8 *data2, unsigned int count2);
+int midi_mt32_write_block(guint8 *data, unsigned int count);
+int midi_mt32_patch001_type(guint8 *data, unsigned int length);
+int midi_mt32_patch001_type0_length(guint8 *data, unsigned int length);
+int midi_mt32_patch001_type1_length(guint8 *data, unsigned int length);
+int midi_mt32_sysex_delay();
+
+static guint8 *data;
+static unsigned int length;
+static int type;
+static guint8 sysex_buffer[266] = {0xF0, 0x41, 0x10, 0x16, 0x12};
+
+static gint8 patch_map[128] = {
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
+ 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
+ 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
+ 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
+ 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
+ 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127};
+static gint8 keyshift[128] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+static gint8 volume_adjust[128] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+static guint8 velocity_map_index[128] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+static guint8 velocity_map[4][128] = {
+ {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
+ 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
+ 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
+ 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
+ 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
+ 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127},
+ {0,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,
+ 39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,
+ 47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,
+ 55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
+ 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
+ 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
+ 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127},
+ {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
+ 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
+ 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,66,67,67,68,68,69,69,70,70,71,71,72,72,
+ 73,73,74,74,75,75,76,76,77,77,78,78,79,79,80,80,
+ 81,81,82,82,83,83,84,84,85,85,86,86,87,87,88,88,
+ 89,89,90,90,91,91,92,92,93,93,94,94,95,95,96,96},
+ {0,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,
+ 39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,
+ 47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,
+ 55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,
+ 64,65,66,66,67,67,68,68,69,69,70,70,71,71,72,72,
+ 73,73,74,74,75,75,76,76,77,77,78,78,79,79,80,80,
+ 81,81,82,82,83,83,84,84,85,85,86,86,87,87,88,88,
+ 89,89,90,90,91,91,92,92,93,93,94,94,95,95,96,96}};
+static gint8 rhythmkey_map[128] = {
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,35,36,37,38,39,40,41,42,43,44,45,46,47,
+ 48,49,50,51,-1,-1,54,-1,56,-1,-1,-1,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,-1,75,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
+/* static struct {
+ gint8 sci_patch;
+ gint8 sci_volume;
+ gint8 sci_pitchwheel;
+ gint8 patch;
+ gint8 keyshift;
+ gint8 volume_adjust;
+ guint8 velocity_map_index;
+ guint8
+} channel[16]; */
+static guint8 master_volume;
+
+int midi_mt32_open(guint8 *data_ptr, unsigned int data_length)
+{
+ guint8 unknown_sysex[6] = {0x16, 0x16, 0x16, 0x16, 0x16, 0x16};
+ guint8 i, memtimbres;
+ unsigned int block2, block3;
+
+ if (midiout_open() < 0)
+ return -1;
+
+ data = data_ptr;
+ length = data_length;
+
+ type = midi_mt32_patch001_type(data, length);
+ printf("MT-32: Programming Roland MT-32 with patch.001 (v%i)\n", type);
+
+ if (type == 0) {
+ /* Display MT-32 initialization message */
+ printf("MT-32: Displaying Text: \"%.20s\"\n", data + 20);
+ midi_mt32_poke(0x200000, data + 20, 20);
+ midi_mt32_sysex_delay();
+
+ /* Write Patches (48 or 96) */
+ memtimbres = data[491];
+ block2 = (memtimbres * 246) + 492;
+ printf("MT-32: Writing Patches #01 - #32\n");
+ midi_mt32_poke(0x050000, data + 107, 256);
+ midi_mt32_sysex_delay();
+ if ((length > block2) &&
+ data[block2] == 0xAB &&
+ data[block2 + 1] == 0xCD) {
+ printf("MT-32: Writing Patches #33 - #64\n");
+ midi_mt32_poke_gather(0x050200, data + 363, 128, data + block2 + 2, 128);
+ midi_mt32_sysex_delay();
+ printf("MT-32: Writing Patches #65 - #96\n");
+ midi_mt32_poke(0x050400, data + block2 + 130, 256);
+ midi_mt32_sysex_delay();
+ block3 = block2 + 386;
+ } else {
+ printf("MT-32: Writing Patches #33 - #48\n");
+ midi_mt32_poke(0x050200, data + 363, 128);
+ midi_mt32_sysex_delay();
+ block3 = block2;
+ }
+ /* Write Memory Timbres */
+ for (i = 0; i < memtimbres; i++) {
+ printf("MT-32: Writing Memory Timbre #%02d: \"%.10s\"\n",
+ i + 1, data + 492 + i * 246);
+ midi_mt32_poke(0x080000 + (i << 9), data + 492 + i * 246, 246);
+ midi_mt32_sysex_delay();
+ }
+ /* Write Rhythm key map and Partial Reserve */
+ if ((length > block3) &&
+ data[block3] == 0xDC &&
+ data[block3 + 1] == 0xBA) {
+ printf("MT-32: Writing Rhythm key map\n");
+ midi_mt32_poke(0x030110, data + block3 + 2, 256);
+ midi_mt32_sysex_delay();
+ printf("MT-32: Writing Partial Reserve\n");
+ midi_mt32_poke(0x100004, data + block3 + 258, 9);
+ midi_mt32_sysex_delay();
+ }
+ /* Display MT-32 initialization done message */
+ printf("MT-32: Displaying Text: \"%.20s\"\n", data);
+ midi_mt32_poke(0x200000, data, 20);
+ midi_mt32_sysex_delay();
+ /* Write undocumented MT-32(?) SysEx */
+ printf("MT-32: Writing {F0 41 10 16 12 52 00 0A 16 16 16 16 16 16 20 F7}\n");
+ midi_mt32_poke(0x52000A, unknown_sysex, 6);
+ midi_mt32_sysex_delay();
+ return 0;
+ } else if (type == 1) {
+ midi_mt32_write_block(data + 1155, (data[1154] << 8) + data[1153]);
+ memcpy(patch_map, data, 128);
+ memcpy(keyshift, data + 128, 128);
+ memcpy(volume_adjust, data + 256, 128);
+ memcpy(velocity_map_index, data + 513, 128);
+ for (i = 0; i < 4; i++)
+ memcpy(velocity_map[i], data + 641 + i * 128, 128);
+ memcpy(rhythmkey_map, data + 384, 128);
+ return 0;
+ }
+ return -1;
+}
+
+int midi_mt32_close()
+{
+if (type == 0) {
+ printf("MT-32: Displaying Text: \"%.20s\"\n", data + 40);
+ midi_mt32_poke(0x200000, data + 40, 20);
+ midi_mt32_sysex_delay();
+}
+return midiout_close();
+}
+
+int midi_mt32_noteoff(guint8 channel, guint8 note)
+{
+ return 0;
+}
+
+int midi_mt32_noteon(guint8 channel, guint8 note, guint8 velocity)
+{
+/* guint8 buffer[3] = {0x90};
+ if (channel == RHYTHM_CHANNEL)
+ if (rhythmkey_map[note] == -1)
+ return 0;
+ else {
+ buffer[0] |= channel
+ buffer[1] = rhythmkey_map[note];
+ buffer[2] = velo
+ midi_write_event(buffer, 3);
+ }; */
+ return 0;
+}
+
+int midi_mt32_poke(guint32 address, guint8 *data, unsigned int count)
+{
+ guint8 checksum = 0;
+ unsigned int i;
+
+ if (count > 256) return -1;
+
+ checksum -= (sysex_buffer[5] = (char)((address >> 16) & 0x7F));
+ checksum -= (sysex_buffer[6] = (char)((address >> 8) & 0x7F));
+ checksum -= (sysex_buffer[7] = (char)(address & 0x7F));
+
+ for (i = 0; i < count; i++)
+ checksum -= (sysex_buffer[i + 8] = data[i]);
+
+ sysex_buffer[count + 8] = checksum & 0x7F;
+ sysex_buffer[count + 9] = 0xF7;
+
+ return midiout_write_block(sysex_buffer, count + 10);
+}
+
+int midi_mt32_poke_gather(guint32 address, guint8 *data1, unsigned int count1,
+ guint8 *data2, unsigned int count2)
+{
+ guint8 checksum = 0;
+ unsigned int i;
+
+ if ((count1 + count2) > 256) return -1;
+
+ checksum -= (sysex_buffer[5] = (char)((address >> 16) & 0x7F));
+ checksum -= (sysex_buffer[6] = (char)((address >> 8) & 0x7F));
+ checksum -= (sysex_buffer[7] = (char)(address & 0x7F));
+
+ for (i = 0; i < count1; i++)
+ checksum -= (sysex_buffer[i + 8] = data1[i]);
+ for (i = 0; i < count2; i++)
+ checksum -= (sysex_buffer[i + 8 + count1] = data2[i]);
+
+ sysex_buffer[count1 + count2 + 8] = checksum & 0x7F;
+ sysex_buffer[count1 + count2 + 9] = 0xF7;
+
+ return midiout_write_block(sysex_buffer, count1 + count2 + 10);
+}
+
+int midi_mt32_write_block(guint8 *data, unsigned int count)
+{
+ unsigned int block_start = 0;
+ unsigned int i = 0;
+
+ while (i < count) {
+ if ((data[i] == 0xF0) && (i != block_start)) {
+ midiout_write_block(data + block_start, i - block_start);
+ block_start = i;
+ }
+ if (data[i] == 0xF7) {
+ midiout_write_block(data + block_start, i - block_start + 1);
+ midi_mt32_sysex_delay();
+ block_start = i + 1;
+ }
+ i++;
+ }
+ if (count >= block_start)
+ midiout_write_block(data + block_start, count - block_start);
+ return 0;
+}
+
+int midi_mt32_patch001_type(guint8 *data, unsigned int length)
+{
+ /* length test */
+ if (length < 1155)
+ return 0;
+ if (length > 16889)
+ return 1;
+ if (midi_mt32_patch001_type0_length(data, length) &&
+ !midi_mt32_patch001_type1_length(data, length))
+ return 0;
+ if (midi_mt32_patch001_type1_length(data, length) &&
+ !midi_mt32_patch001_type0_length(data, length))
+ return 1;
+ return -1;
+}
+
+int midi_mt32_patch001_type0_length(guint8 *data, unsigned int length)
+{
+ unsigned int pos = 492 + 246 * data[491];
+
+ if ((length >= (pos + 386)) && (data[pos] == 0xAB) && (data[pos + 1] == 0xCD))
+ pos += 386;
+ if ((length >= (pos + 267)) && (data[pos] == 0xDC) && (data[pos + 1] == 0xBA))
+ pos += 267;
+ if (pos == length)
+ return 1;
+ return 0;
+}
+
+int midi_mt32_patch001_type1_length(guint8 *data, unsigned int length)
+{
+ if ((length >= 1155) && (((data[1154] << 8) + data[1153] + 1155) == length))
+ return 1;
+ return 0;
+}
+
+int midi_mt32_sysex_delay()
+{
+ usleep(320 * 63); /* One MIDI byte is 320us, 320us * 63 > 20ms */
+ return 0;
+}
diff --git a/engines/sci/sfx/old/midi_mt32.h b/engines/sci/sfx/old/midi_mt32.h
new file mode 100644
index 0000000000..0e14efd41d
--- /dev/null
+++ b/engines/sci/sfx/old/midi_mt32.h
@@ -0,0 +1,29 @@
+/***************************************************************************
+ midi_mt32.h Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#ifndef _MIDI_MT32_H_
+#define _MIDI_MT32_H_
+
+#include "glib.h"
+
+int midi_mt32_open(guint8 *data_ptr, unsigned int data_length);
+int midi_mt32_close();
+
+#endif /* _MIDI_MT32_H_ */
diff --git a/engines/sci/sfx/old/midiout.c b/engines/sci/sfx/old/midiout.c
new file mode 100644
index 0000000000..262836baba
--- /dev/null
+++ b/engines/sci/sfx/old/midiout.c
@@ -0,0 +1,63 @@
+/***************************************************************************
+ midiout.c Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#include "glib.h"
+#include "midiout.h"
+#include "midiout_alsaraw.h"
+#include "midiout_unixraw.h"
+
+static int (*midiout_ptr_close)();
+static int (*midiout_ptr_write)(guint8 *, unsigned int);
+
+static unsigned char running_status = 0;
+
+int midiout_open()
+{
+ midiout_ptr_close = midiout_alsaraw_close;
+ midiout_ptr_write = midiout_alsaraw_write;
+ return midiout_alsaraw_open(0, 0);
+
+ /*
+ midiout_ptr_close = midiout_unixraw_close;
+ midiout_ptr_write = midiout_unixraw_write;
+ return midiout_unixraw_open("/dev/midi00");
+ */
+}
+
+int midiout_close()
+{
+ return midiout_ptr_close();
+}
+
+int midiout_write_event(guint8 *buffer, unsigned int count)
+{
+ if (buffer[0] == running_status)
+ return midiout_ptr_write(buffer + 1, count - 1);
+ else {
+ running_status = buffer[0];
+ return midiout_ptr_write(buffer, count);
+ }
+}
+
+int midiout_write_block(guint8 *buffer, unsigned int count)
+{
+ running_status = 0;
+ return midiout_ptr_write(buffer, count);
+}
diff --git a/engines/sci/sfx/old/midiout.h b/engines/sci/sfx/old/midiout.h
new file mode 100644
index 0000000000..e0ce3915ae
--- /dev/null
+++ b/engines/sci/sfx/old/midiout.h
@@ -0,0 +1,29 @@
+/***************************************************************************
+ midiout.h Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#ifndef _MIDIOUT_H_
+#define _MIDIOUT_H_
+
+int midiout_open();
+int midiout_close();
+int midiout_write_event(guint8 *buffer, unsigned int count);
+int midiout_write_block(guint8 *buffer, unsigned int count);
+
+#endif /* _MIDIOUT_H_ */
diff --git a/engines/sci/sfx/old/midiout_alsaraw.c b/engines/sci/sfx/old/midiout_alsaraw.c
new file mode 100644
index 0000000000..e95aa28425
--- /dev/null
+++ b/engines/sci/sfx/old/midiout_alsaraw.c
@@ -0,0 +1,51 @@
+/***************************************************************************
+ midiout_alsaraw.c Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#include "glib.h"
+#include <stdio.h>
+#include <sys/asoundlib.h>
+#include "midiout_alsaraw.h"
+
+static snd_rawmidi_t *handle;
+
+int midiout_alsaraw_open(int card, int device)
+{
+ int err;
+
+ if ((err = snd_rawmidi_open(&handle, card, device, SND_RAWMIDI_OPEN_OUTPUT)) < 0) {
+ fprintf(stderr, "Open failed (%i): /dev/snd/midiC%iD%i\n", err, card, device);
+ return -1;
+ }
+ return 0;
+}
+
+int midiout_alsaraw_close()
+{
+ if (snd_rawmidi_close(handle) < 0)
+ return -1;
+ return 0;
+}
+
+int midiout_alsaraw_write(guint8 *buffer, unsigned int count)
+{
+ if (snd_rawmidi_write(handle, buffer, count) != count)
+ return -1;
+ return 0;
+}
diff --git a/engines/sci/sfx/old/midiout_alsaraw.h b/engines/sci/sfx/old/midiout_alsaraw.h
new file mode 100644
index 0000000000..cbf9da44c1
--- /dev/null
+++ b/engines/sci/sfx/old/midiout_alsaraw.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+ midiout_alsaraw.h Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#ifndef _MIDIOUT_ALSARAW_H_
+#define _MIDIOUT_ALSARAW_H_
+
+int midiout_alsaraw_open(int card, int device);
+int midiout_alsaraw_close();
+int midiout_alsaraw_write(guint8 *buffer, unsigned int count);
+
+#endif /* _MIDIOUT_ALSARAW_H_ */
diff --git a/engines/sci/sfx/old/midiout_unixraw.c b/engines/sci/sfx/old/midiout_unixraw.c
new file mode 100644
index 0000000000..a0dc85955f
--- /dev/null
+++ b/engines/sci/sfx/old/midiout_unixraw.c
@@ -0,0 +1,52 @@
+/***************************************************************************
+ midiout_unixraw.c Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#include "glib.h"
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "midiout_unixraw.h"
+
+static int fd;
+
+int midiout_unixraw_open(char *devicename)
+{
+ if (!IS_VALID_FD(fd = open(devicename, O_WRONLY|O_SYNC))) {
+ fprintf(stderr, "Open failed (%i): %s\n", fd, devicename);
+ return -1;
+ }
+ return 0;
+}
+
+int midiout_unixraw_close()
+{
+ if (close(fd) < 0)
+ return -1;
+ return 0;
+}
+
+int midiout_unixraw_write(guint8 *buffer, unsigned int count)
+{
+ if (write(fd, buffer, count) != count)
+ return -1;
+ return 0;
+}
diff --git a/engines/sci/sfx/old/midiout_unixraw.h b/engines/sci/sfx/old/midiout_unixraw.h
new file mode 100644
index 0000000000..c5980696e9
--- /dev/null
+++ b/engines/sci/sfx/old/midiout_unixraw.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+ midiout_unixraw.h Copyright (C) 2000 Rickard Lind
+
+
+ This program may be modified and copied freely according to the terms of
+ the GNU general public license (GPL), as long as the above copyright
+ notice and the licensing information contained herein are preserved.
+
+ Please refer to www.gnu.org for licensing details.
+
+ This work is provided AS IS, without warranty of any kind, expressed or
+ implied, including but not limited to the warranties of merchantibility,
+ noninfringement, and fitness for a specific purpose. The author will not
+ be held liable for any damage caused by this work or derivatives of it.
+
+ By using this source code, you agree to the licensing terms as stated
+ above.
+
+***************************************************************************/
+
+#ifndef _MIDIOUT_UNIXRAW_H_
+#define _MIDIOUT_UNIXRAW_H_
+
+int midiout_unixraw_open(char *devicename);
+int midiout_unixraw_close();
+int midiout_unixraw_write(guint8 *buffer, unsigned int count);
+
+#endif /* _MIDIOUT_UNIXRAW_H_ */