aboutsummaryrefslogtreecommitdiff
path: root/engines/made/scriptfuncs.cpp
diff options
context:
space:
mode:
authorAlejandro Marzini2010-07-30 05:28:09 +0000
committerAlejandro Marzini2010-07-30 05:28:09 +0000
commitfb4086cadb8ce3e473dae40558d713e7a31b3858 (patch)
tree95c19d544da914c43a43f0538a1977f43e17cb39 /engines/made/scriptfuncs.cpp
parent7b070bbef8275ff25dfc2cbc3106acfdc8de74a5 (diff)
parenta17e3c444917ca90dfd537c2102a6150e7ffe977 (diff)
downloadscummvm-rg350-fb4086cadb8ce3e473dae40558d713e7a31b3858.tar.gz
scummvm-rg350-fb4086cadb8ce3e473dae40558d713e7a31b3858.tar.bz2
scummvm-rg350-fb4086cadb8ce3e473dae40558d713e7a31b3858.zip
Merged from trunk, from Rev 50841 to HEAD
svn-id: r51495
Diffstat (limited to 'engines/made/scriptfuncs.cpp')
-rw-r--r--engines/made/scriptfuncs.cpp83
1 files changed, 71 insertions, 12 deletions
diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp
index b1a8b0ff84..2f069e882e 100644
--- a/engines/made/scriptfuncs.cpp
+++ b/engines/made/scriptfuncs.cpp
@@ -27,6 +27,7 @@
#include "common/util.h"
#include "common/events.h"
#include "graphics/cursorman.h"
+#include "sound/softsynth/pcspk.h"
#include "made/made.h"
#include "made/resource.h"
@@ -40,6 +41,22 @@
namespace Made {
+ScriptFunctions::ScriptFunctions(MadeEngine *vm) : _vm(vm), _soundStarted(false) {
+ // Initialize the two tone generators
+ _pcSpeaker1 = new Audio::PCSpeaker();
+ _pcSpeaker2 = new Audio::PCSpeaker();
+ _vm->_system->getMixer()->playStream(Audio::Mixer::kMusicSoundType, &_pcSpeakerHandle1, _pcSpeaker1);
+ _vm->_system->getMixer()->playStream(Audio::Mixer::kMusicSoundType, &_pcSpeakerHandle2, _pcSpeaker2);
+}
+
+ScriptFunctions::~ScriptFunctions() {
+ for (uint i = 0; i < _externalFuncs.size(); ++i)
+ delete _externalFuncs[i];
+
+ _vm->_system->getMixer()->stopHandle(_pcSpeakerHandle1);
+ _vm->_system->getMixer()->stopHandle(_pcSpeakerHandle2);
+}
+
typedef Common::Functor2Mem<int16, int16*, int16, ScriptFunctions> ExternalScriptFunc;
#define External(x) \
_externalFuncs.push_back(new ExternalScriptFunc(this, &ScriptFunctions::x)); \
@@ -307,36 +324,78 @@ int16 ScriptFunctions::sfFlashScreen(int16 argc, int16 *argv) {
}
int16 ScriptFunctions::sfPlayNote(int16 argc, int16 *argv) {
- // TODO: Used in Manhole:NE, Manhole EGA
- // This is used when using the piano in the desk screen inside the ship.
+ // This is used when using the piano in the desk screen inside the ship
+ // in The Manhole (EGA/NE).
+
// It takes 2 parameters:
- // The first parameter is the key pressed
+ // The first parameter is the note number of the key pressed + 1
// The second parameter is some sort of modifier (volume, perhaps?),
- // depending on which of the 3 keys on the right has been pressed (12 - 14)
- warning("Unimplemented opcode: sfPlayNote");
+ // depending on which of the 3 keys on the right has been pressed.
+ // This value seems to be [12, 14] in NE and [1, 3] in EGA.
+
+ // Note frequencies based on http://www.phy.mtu.edu/~suits/notefreqs.html
+ static const int freqTable[] = {
+ 16, 17, 18, 19, 21, 22, 23, 24, 26, 28, 29,
+ 30, 32, 35, 37, 39, 41, 44, 46, 49, 52, 55,
+ 58, 62, 65, 69, 73, 77, 82, 87, 93, 98, 104,
+ 110, 117, 123, 131, 139, 147, 156, 165, 175, 195,
+ 196, 208, 220, 233, 247, 262, 277, 294, 311, 330,
+ 349, 370, 392, 415, 440, 466, 494, 523, 554, 587,
+ 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047,
+ 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760,
+ 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960,
+ 3136, 3322, 3529, 3729, 3951, 4186, 4435, 4697, 4978
+ };
+
+ debug(4, "sfPlayNote: Note = %d, Volume(?) = %d", argv[0] - 1, argv[1]);
+
+ _pcSpeaker1->play(Audio::PCSpeaker::kWaveFormSine, freqTable[argv[0] - 1], -1);
+
+ // TODO: Figure out what to do with the second parameter
+ //_pcSpeaker1->setVolume(argv[1]);
+
return 0;
}
int16 ScriptFunctions::sfStopNote(int16 argc, int16 *argv) {
- // TODO: Used in Manhole:NE, Manhole EGA
// Used in the same place as sfPlayNote, with the same parameters
- warning("Unimplemented opcode: sfStopNote");
+ // We just stop the wave generator here
+ _pcSpeaker1->stop();
return 0;
}
int16 ScriptFunctions::sfPlayTele(int16 argc, int16 *argv) {
- // TODO: Used in Manhole:NE, Manhole EGA
// This is used when pressing the phone keys while using the phone in
- // the desk screen inside the ship.
+ // the desk screen inside the ship in The Manhole (EGA/NE).
// It takes 1 parameter, the key pressed (0-9, 10 for asterisk, 11 for hash)
- warning("Unimplemented opcode: sfPlayTele");
+
+ // A telephone keypad uses a two tones for each key.
+ // See http://en.wikipedia.org/wiki/Telephone_keypad for more info
+
+ static const int freqTable1[] = {
+ 1336, 1209, 1336, 1477,
+ 1209, 1336, 1477, 1209,
+ 1336, 1477, 1209, 1477
+ };
+
+ static const int freqTable2[] = {
+ 941, 697, 697, 697,
+ 770, 770, 770, 852,
+ 852, 852, 941, 941
+ };
+
+ debug(4, "sfPlayTele: Button = %d", argv[0]);
+
+ _pcSpeaker1->play(Audio::PCSpeaker::kWaveFormSine, freqTable1[argv[0]], -1);
+ _pcSpeaker2->play(Audio::PCSpeaker::kWaveFormSine, freqTable2[argv[0]], -1);
return 0;
}
int16 ScriptFunctions::sfStopTele(int16 argc, int16 *argv) {
- // TODO: Used in Manhole:NE, Manhole EGA
// Used in the same place as sfPlayTele, with the same parameters
- warning("Unimplemented opcode: sfStopTele");
+ // We just stop both wave generators here
+ _pcSpeaker1->stop();
+ _pcSpeaker2->stop();
return 0;
}