aboutsummaryrefslogtreecommitdiff
path: root/engines/agos
diff options
context:
space:
mode:
authorMartin Kiewitz2015-07-03 00:52:36 +0200
committerMartin Kiewitz2015-07-03 00:52:36 +0200
commitbfa7d895002198a364a599893953f911f2095ce6 (patch)
tree0129ff1a4fe1906bb4e76a1ceed85701d2b6924b /engines/agos
parentb74edc093768b2885dc2a5bd40d748b5baa64605 (diff)
downloadscummvm-rg350-bfa7d895002198a364a599893953f911f2095ce6.tar.gz
scummvm-rg350-bfa7d895002198a364a599893953f911f2095ce6.tar.bz2
scummvm-rg350-bfa7d895002198a364a599893953f911f2095ce6.zip
AGOS: Accolade music: read driver data in factory
moved driver reading code into factory of both Accolade music drivers
Diffstat (limited to 'engines/agos')
-rw-r--r--engines/agos/drivers/accolade/adlib.cpp24
-rw-r--r--engines/agos/drivers/accolade/driverfile.cpp166
-rw-r--r--engines/agos/drivers/accolade/mididriver.h7
-rw-r--r--engines/agos/drivers/accolade/mt32.cpp24
-rw-r--r--engines/agos/midi.cpp177
-rw-r--r--engines/agos/module.mk1
6 files changed, 213 insertions, 186 deletions
diff --git a/engines/agos/drivers/accolade/adlib.cpp b/engines/agos/drivers/accolade/adlib.cpp
index a748ac2323..ed05fe19ac 100644
--- a/engines/agos/drivers/accolade/adlib.cpp
+++ b/engines/agos/drivers/accolade/adlib.cpp
@@ -862,12 +862,24 @@ bool MidiDriver_Accolade_AdLib::setupInstruments(byte *driverData, uint16 driver
return true;
}
-MidiDriver *MidiDriver_Accolade_AdLib_create() {
- return new MidiDriver_Accolade_AdLib(g_system->getMixer());
-}
-
-bool MidiDriver_Accolade_AdLib_setupInstruments(MidiDriver *driver, byte *driverData, uint16 driverDataSize, bool useMusicDrvFile) {
- return static_cast<MidiDriver_Accolade_AdLib *>(driver)->setupInstruments(driverData, driverDataSize, useMusicDrvFile);
+MidiDriver *MidiDriver_Accolade_AdLib_create(Common::String driverFilename) {
+ byte *driverData = NULL;
+ uint16 driverDataSize = 0;
+ bool isMusicDrvFile = false;
+
+ MidiDriver_Accolade_readDriver(driverFilename, MT_ADLIB, driverData, driverDataSize, isMusicDrvFile);
+ if (!driverData)
+ error("ACCOLADE-ADLIB: error during readDriver()");
+
+ MidiDriver_Accolade_AdLib *driver = new MidiDriver_Accolade_AdLib(g_system->getMixer());
+ if (!driver)
+ return nullptr;
+
+ if (!driver->setupInstruments(driverData, driverDataSize, isMusicDrvFile)) {
+ delete driver;
+ return nullptr;
+ }
+ return driver;
}
} // End of namespace AGOS
diff --git a/engines/agos/drivers/accolade/driverfile.cpp b/engines/agos/drivers/accolade/driverfile.cpp
new file mode 100644
index 0000000000..4ff2fd550f
--- /dev/null
+++ b/engines/agos/drivers/accolade/driverfile.cpp
@@ -0,0 +1,166 @@
+/* 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.
+ *
+ */
+
+#include "agos/agos.h"
+#include "audio/mididrv.h"
+#include "common/error.h"
+#include "common/file.h"
+
+namespace AGOS {
+
+// this reads and gets Accolade driver data
+// we need it for channel mapping, instrument mapping and other things
+// this driver data chunk gets passed to the actual music driver (MT32 / AdLib)
+void MidiDriver_Accolade_readDriver(Common::String filename, MusicType requestedDriverType, byte *&driverData, uint16 &driverDataSize, bool &isMusicDrvFile) {
+ Common::File *driverStream = new Common::File();
+
+ isMusicDrvFile = false;
+
+ if (!driverStream->open(filename)) {
+ error("%s: unable to open file", filename.c_str());
+ }
+
+ if (filename == "INSTR.DAT") {
+ // INSTR.DAT: used by Elvira 1
+ uint32 streamSize = driverStream->size();
+ uint32 streamLeft = streamSize;
+ uint16 skipChunks = 0; // 1 for MT32, 0 for AdLib
+ uint16 chunkSize = 0;
+
+ switch (requestedDriverType) {
+ case MT_ADLIB:
+ skipChunks = 0;
+ break;
+ case MT_MT32:
+ skipChunks = 1; // Skip one entry for MT32
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ do {
+ if (streamLeft < 2)
+ error("%s: unexpected EOF", filename.c_str());
+
+ chunkSize = driverStream->readUint16LE();
+ streamLeft -= 2;
+
+ if (streamLeft < chunkSize)
+ error("%s: unexpected EOF", filename.c_str());
+
+ if (skipChunks) {
+ // Skip the chunk
+ driverStream->skip(chunkSize);
+ streamLeft -= chunkSize;
+
+ skipChunks--;
+ }
+ } while (skipChunks);
+
+ // Seek over the ASCII string until there is a NUL terminator
+ byte curByte = 0;
+
+ do {
+ if (chunkSize == 0)
+ error("%s: no actual instrument data found", filename.c_str());
+
+ curByte = driverStream->readByte();
+ chunkSize--;
+ } while (curByte);
+
+ driverDataSize = chunkSize;
+
+ // Read the requested instrument data entry
+ driverData = new byte[driverDataSize];
+ driverStream->read(driverData, driverDataSize);
+
+ } else if (filename == "MUSIC.DRV") {
+ // MUSIC.DRV / used by Elvira 2 / Waxworks / Simon 1 demo
+ uint32 streamSize = driverStream->size();
+ uint32 streamLeft = streamSize;
+ uint16 getChunk = 0; // 4 for MT32, 2 for AdLib
+
+ switch (requestedDriverType) {
+ case MT_ADLIB:
+ getChunk = 2;
+ break;
+ case MT_MT32:
+ getChunk = 4;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ if (streamLeft < 2)
+ error("%s: unexpected EOF", filename.c_str());
+
+ uint16 chunkCount = driverStream->readUint16LE();
+ streamLeft -= 2;
+
+ if (getChunk >= chunkCount)
+ error("%s: required chunk not available", filename.c_str());
+
+ uint16 headerOffset = 2 + (28 * getChunk);
+ streamLeft -= (28 * getChunk);
+
+ if (streamLeft < 28)
+ error("%s: unexpected EOF", filename.c_str());
+
+ // Seek to required chunk
+ driverStream->seek(headerOffset);
+ driverStream->skip(20); // skip over name
+ streamLeft -= 20;
+
+ uint16 musicDrvSignature = driverStream->readUint16LE();
+ uint16 musicDrvType = driverStream->readUint16LE();
+ uint16 chunkOffset = driverStream->readUint16LE();
+ uint16 chunkSize = driverStream->readUint16LE();
+
+ // Security checks
+ if (musicDrvSignature != 0xFEDC)
+ error("%s: chunk signature mismatch", filename.c_str());
+ if (musicDrvType != 1)
+ error("%s: not a music driver", filename.c_str());
+ if (chunkOffset >= streamSize)
+ error("%s: driver chunk points outside of file", filename.c_str());
+
+ streamLeft = streamSize - chunkOffset;
+ if (streamLeft < chunkSize)
+ error("%s: driver chunk is larger than file", filename.c_str());
+
+ driverDataSize = chunkSize;
+
+ // Read the requested instrument data entry
+ driverData = new byte[driverDataSize];
+
+ driverStream->seek(chunkOffset);
+ driverStream->read(driverData, driverDataSize);
+ isMusicDrvFile = true;
+ }
+
+ driverStream->close();
+ delete driverStream;
+}
+
+} // End of namespace AGOS
diff --git a/engines/agos/drivers/accolade/mididriver.h b/engines/agos/drivers/accolade/mididriver.h
index 96637ed1f2..253fb6b736 100644
--- a/engines/agos/drivers/accolade/mididriver.h
+++ b/engines/agos/drivers/accolade/mididriver.h
@@ -34,11 +34,10 @@ namespace AGOS {
#define AGOS_MIDI_KEYNOTE_COUNT 64
-extern MidiDriver *MidiDriver_Accolade_AdLib_create();
-extern bool MidiDriver_Accolade_AdLib_setupInstruments(MidiDriver *driver, byte *instrDATData, uint16 instrDATDataSize, bool useMusicDrvFile);
+extern void MidiDriver_Accolade_readDriver(Common::String filename, MusicType requestedDriverType, byte *&driverData, uint16 &driverDataSize, bool &isMusicDrvFile);
-extern MidiDriver *MidiDriver_Accolade_MT32_create();
-extern bool MidiDriver_Accolade_MT32_setupInstruments(MidiDriver *driver, byte *instrDATData, uint16 instrDATDataSize, bool useMusicDrvFile);
+extern MidiDriver *MidiDriver_Accolade_AdLib_create(Common::String driverFilename);
+extern MidiDriver *MidiDriver_Accolade_MT32_create(Common::String driverFilename);
} // End of namespace AGOS
diff --git a/engines/agos/drivers/accolade/mt32.cpp b/engines/agos/drivers/accolade/mt32.cpp
index f863ffba4c..2a023297ee 100644
--- a/engines/agos/drivers/accolade/mt32.cpp
+++ b/engines/agos/drivers/accolade/mt32.cpp
@@ -254,12 +254,24 @@ bool MidiDriver_Accolade_MT32::setupInstruments(byte *driverData, uint16 driverD
return true;
}
-MidiDriver *MidiDriver_Accolade_MT32_create() {
- return new MidiDriver_Accolade_MT32();
-}
-
-bool MidiDriver_Accolade_MT32_setupInstruments(MidiDriver *driver, byte *instrumentData, uint16 instrumentDataSize, bool useMusicDrvFile) {
- return static_cast<MidiDriver_Accolade_MT32 *>(driver)->setupInstruments(instrumentData, instrumentDataSize, useMusicDrvFile);
+MidiDriver *MidiDriver_Accolade_MT32_create(Common::String driverFilename) {
+ byte *driverData = NULL;
+ uint16 driverDataSize = 0;
+ bool isMusicDrvFile = false;
+
+ MidiDriver_Accolade_readDriver(driverFilename, MT_MT32, driverData, driverDataSize, isMusicDrvFile);
+ if (!driverData)
+ error("ACCOLADE-ADLIB: error during readDriver()");
+
+ MidiDriver_Accolade_MT32 *driver = new MidiDriver_Accolade_MT32();
+ if (!driver)
+ return nullptr;
+
+ if (!driver->setupInstruments(driverData, driverDataSize, isMusicDrvFile)) {
+ delete driver;
+ return nullptr;
+ }
+ return driver;
}
} // End of namespace AGOS
diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp
index fdc2227c6e..c536e85742 100644
--- a/engines/agos/midi.cpp
+++ b/engines/agos/midi.cpp
@@ -85,29 +85,30 @@ int MidiPlayer::open(int gameType, bool isDemo) {
// Don't call open() twice!
assert(!_driver);
- bool accoladeUseMusicDrvFile = false;
+ Common::String accoladeDriverFilename;
MusicType accoladeMusicType = MT_INVALID;
MusicType milesAudioMusicType = MT_INVALID;
switch (gameType) {
case GType_ELVIRA1:
_musicMode = kMusicModeAccolade;
+ accoladeDriverFilename = "INSTR.DAT";
break;
case GType_ELVIRA2:
case GType_WW:
// Attention: Elvira 2 shipped with INSTR.DAT and MUSIC.DRV
// MUSIC.DRV is the correct one. INSTR.DAT seems to be a left-over
_musicMode = kMusicModeAccolade;
- accoladeUseMusicDrvFile = true;
+ accoladeDriverFilename = "MUSIC.DRV";
break;
case GType_SIMON1:
if (isDemo) {
_musicMode = kMusicModeAccolade;
- accoladeUseMusicDrvFile = true;
+ accoladeDriverFilename = "MUSIC.DRV";
}
break;
case GType_SIMON2:
- //_musicMode = kMusicModeMilesAudio;
+ _musicMode = kMusicModeMilesAudio;
// currently disabled, because there are a few issues
// MT32 seems to work fine now, AdLib seems to use bad instruments and is also outputting music on
// the right speaker only. The original driver did initialize the panning to 0 and the Simon2 XMIDI
@@ -184,10 +185,10 @@ int MidiPlayer::open(int gameType, bool isDemo) {
// Setup midi driver
switch (accoladeMusicType) {
case MT_ADLIB:
- _driver = MidiDriver_Accolade_AdLib_create();
+ _driver = MidiDriver_Accolade_AdLib_create(accoladeDriverFilename);
break;
case MT_MT32:
- _driver = MidiDriver_Accolade_MT32_create();
+ _driver = MidiDriver_Accolade_MT32_create(accoladeDriverFilename);
break;
default:
assert(0);
@@ -196,170 +197,6 @@ int MidiPlayer::open(int gameType, bool isDemo) {
if (!_driver)
return 255;
- byte *instrumentData = NULL;
- uint16 instrumentDataSize = 0;
-
- if (!accoladeUseMusicDrvFile) {
- // Elvira 1 / Elvira 2: read INSTR.DAT
- Common::File *instrDatStream = new Common::File();
-
- if (!instrDatStream->open("INSTR.DAT")) {
- error("INSTR.DAT: unable to open file");
- }
-
- uint32 streamSize = instrDatStream->size();
- uint32 streamLeft = streamSize;
- uint16 skipChunks = 0; // 1 for MT32, 0 for AdLib
- uint16 chunkSize = 0;
-
- switch (accoladeMusicType) {
- case MT_ADLIB:
- skipChunks = 0;
- break;
- case MT_MT32:
- skipChunks = 1; // Skip one entry for MT32
- break;
- default:
- assert(0);
- break;
- }
-
- do {
- if (streamLeft < 2)
- error("INSTR.DAT: unexpected EOF");
-
- chunkSize = instrDatStream->readUint16LE();
- streamLeft -= 2;
-
- if (streamLeft < chunkSize)
- error("INSTR.DAT: unexpected EOF");
-
- if (skipChunks) {
- // Skip the chunk
- instrDatStream->skip(chunkSize);
- streamLeft -= chunkSize;
-
- skipChunks--;
- }
- } while (skipChunks);
-
- // Seek over the ASCII string until there is a NUL terminator
- byte curByte = 0;
-
- do {
- if (chunkSize == 0)
- error("INSTR.DAT: no actual instrument data found");
-
- curByte = instrDatStream->readByte();
- chunkSize--;
- } while (curByte);
-
- instrumentDataSize = chunkSize;
-
- // Read the requested instrument data entry
- instrumentData = new byte[instrumentDataSize];
- instrDatStream->read(instrumentData, instrumentDataSize);
-
- instrDatStream->close();
- delete instrDatStream;
-
- } else {
- // Waxworks / Simon 1 demo: Read MUSIC.DRV
- Common::File *musicDrvStream = new Common::File();
-
- if (!musicDrvStream->open("MUSIC.DRV")) {
- error("MUSIC.DRV: unable to open file");
- }
-
- uint32 streamSize = musicDrvStream->size();
- uint32 streamLeft = streamSize;
- uint16 getChunk = 0; // 4 for MT32, 2 for AdLib
-
- switch (accoladeMusicType) {
- case MT_ADLIB:
- getChunk = 2;
- break;
- case MT_MT32:
- getChunk = 4;
- break;
- default:
- assert(0);
- break;
- }
-
- if (streamLeft < 2)
- error("MUSIC.DRV: unexpected EOF");
-
- uint16 chunkCount = musicDrvStream->readUint16LE();
- streamLeft -= 2;
-
- if (getChunk >= chunkCount)
- error("MUSIC.DRV: required chunk not available");
-
- uint16 headerOffset = 2 + (28 * getChunk);
- streamLeft -= (28 * getChunk);
-
- if (streamLeft < 28)
- error("MUSIC.DRV: unexpected EOF");
-
- // Seek to required chunk
- musicDrvStream->seek(headerOffset);
- musicDrvStream->skip(20); // skip over name
- streamLeft -= 20;
-
- uint16 musicDrvSignature = musicDrvStream->readUint16LE();
- uint16 musicDrvType = musicDrvStream->readUint16LE();
- uint16 chunkOffset = musicDrvStream->readUint16LE();
- uint16 chunkSize = musicDrvStream->readUint16LE();
-
- // Security checks
- if (musicDrvSignature != 0xFEDC)
- error("MUSIC.DRV: chunk signature mismatch");
- if (musicDrvType != 1)
- error("MUSIC.DRV: not a music driver");
- if (chunkOffset >= streamSize)
- error("MUSIC.DRV: driver chunk points outside of file");
-
- streamLeft = streamSize - chunkOffset;
- if (streamLeft < chunkSize)
- error("MUSIC.DRV: driver chunk is larger than file");
-
- instrumentDataSize = chunkSize;
-
- // Read the requested instrument data entry
- instrumentData = new byte[instrumentDataSize];
-
- musicDrvStream->seek(chunkOffset);
- musicDrvStream->read(instrumentData, instrumentDataSize);
-
- musicDrvStream->close();
- delete musicDrvStream;
- }
-
- // Pass the instrument data to the driver
- bool instrumentSuccess = false;
-
- switch (accoladeMusicType) {
- case MT_ADLIB:
- instrumentSuccess = MidiDriver_Accolade_AdLib_setupInstruments(_driver, instrumentData, instrumentDataSize, accoladeUseMusicDrvFile);
- break;
- case MT_MT32:
- instrumentSuccess = MidiDriver_Accolade_MT32_setupInstruments(_driver, instrumentData, instrumentDataSize, accoladeUseMusicDrvFile);
- break;
- default:
- assert(0);
- break;
- }
- delete[] instrumentData;
-
- if (!instrumentSuccess) {
- // driver did not like the contents
- if (!accoladeUseMusicDrvFile)
- error("INSTR.DAT: contents not acceptable");
- else
- error("MUSIC.DRV: contents not acceptable");
- }
-
ret = _driver->open();
if (ret == 0) {
// Reset is done inside our MIDI driver
diff --git a/engines/agos/module.mk b/engines/agos/module.mk
index ae9d5cb108..6d4e72e433 100644
--- a/engines/agos/module.mk
+++ b/engines/agos/module.mk
@@ -2,6 +2,7 @@ MODULE := engines/agos
MODULE_OBJS := \
drivers/accolade/adlib.o \
+ drivers/accolade/driverfile.o \
drivers/accolade/mt32.o \
agos.o \
charset.o \