diff options
author | Jamieson Christian | 2003-09-26 14:05:33 +0000 |
---|---|---|
committer | Jamieson Christian | 2003-09-26 14:05:33 +0000 |
commit | 7f707acfb6bbcb138dbcb04eddc05d91821477a1 (patch) | |
tree | fb0a0b967077ab27c1ba4c9be8e67c74e1b0fc9f | |
parent | b21208e6a92b4e8082d04994b0c99709e2712472 (diff) | |
download | scummvm-rg350-7f707acfb6bbcb138dbcb04eddc05d91821477a1.tar.gz scummvm-rg350-7f707acfb6bbcb138dbcb04eddc05d91821477a1.tar.bz2 scummvm-rg350-7f707acfb6bbcb138dbcb04eddc05d91821477a1.zip |
Converted the MPU-401 timer to use the Timer class.
Since this was the only place where we were using
create_thread, that method should be removable now.
I also removed the midi_driver_thread overrides
for the MorphOS and YPA1 (Palm) backends. These need
to be tested by their respective porters.
svn-id: r10414
-rw-r--r-- | backends/midi/morphos.cpp | 44 | ||||
-rw-r--r-- | backends/midi/ypa1.cpp | 31 | ||||
-rw-r--r-- | sound/mpu401.cpp | 65 | ||||
-rw-r--r-- | sound/mpu401.h | 11 |
4 files changed, 16 insertions, 135 deletions
diff --git a/backends/midi/morphos.cpp b/backends/midi/morphos.cpp index f75839cdd2..ab941ca6bf 100644 --- a/backends/midi/morphos.cpp +++ b/backends/midi/morphos.cpp @@ -94,49 +94,5 @@ MidiDriver *MidiDriver_ETUDE_create() return EtudeMidiDriver; } -int MidiDriver_MPU401::midi_driver_thread(void *param) -{ - MidiDriver_MPU401 *mid = (MidiDriver_MPU401 *)param; - int old_time, cur_time; - MsgPort *music_timer_port = NULL; - timerequest *music_timer_request = NULL; - - // Grab the MidiDriver's mutex. When the MidiDriver - // shuts down, it will wait on that mutex until we've - // detected the shutdown and quit looping. - g_system->lock_mutex(mid->_mutex); - - if (!OSystem_MorphOS::OpenATimer(&music_timer_port, (IORequest **) &music_timer_request, UNIT_MICROHZ, false)) { - warning("Could not open a timer - music will not play"); - Wait(SIGBREAKF_CTRL_C); - } - else { - old_time = g_system->get_msecs(); - - while (mid->_started_thread) { - music_timer_request->tr_node.io_Command = TR_ADDREQUEST; - music_timer_request->tr_time.tv_secs = 0; - music_timer_request->tr_time.tv_micro = 10000; - DoIO((struct IORequest *)music_timer_request); - - if (!mid->_started_thread || CheckSignal(SIGBREAKF_CTRL_C)) - break; - - cur_time = g_system->get_msecs(); - while (old_time < cur_time) { - old_time += 10; - if (mid->_timer_proc) - (*(mid->_timer_proc))(mid->_timer_param); - } - } - CloseDevice((IORequest *) music_timer_request); - DeleteIORequest((IORequest *) music_timer_request); - DeleteMsgPort(music_timer_port); - } - - g_system->unlock_mutex(mid->_mutex); - return 0; -} - #endif diff --git a/backends/midi/ypa1.cpp b/backends/midi/ypa1.cpp index e2c12de70b..3bcb06eb3a 100644 --- a/backends/midi/ypa1.cpp +++ b/backends/midi/ypa1.cpp @@ -103,34 +103,3 @@ void MidiDriver_YamahaPa1::send(uint32 b) { MidiDriver *MidiDriver_YamahaPa1_create() { return new MidiDriver_YamahaPa1(); } - -////////////////////////////////////////// -// thread emu -#include "palm.h" - -int MidiDriver_MPU401::midi_driver_thread(void *param) { - MidiDriver_MPU401 *mid = (MidiDriver_MPU401 *)param; - int cur_time; - - if (mid->_started_thread) { - UInt8 id = ((OSystem_PALMOS *)g_system)->_threadID; - ThreadEmuPtr thread = &(((OSystem_PALMOS *)g_system)->_thread[id]); - - // wait 10 msecs - cur_time = g_system->get_msecs(); - if (cur_time - thread->old_time >= 10) - thread->sleep = false; - - // if 10 msecs - if (!thread->sleep) { - thread->sleep = true; - while (thread->old_time < cur_time) { - thread->old_time += 10; - if (mid->_timer_proc) - (*(mid->_timer_proc)) (mid->_timer_param); - } - } - } - - return 0; -}
\ No newline at end of file diff --git a/sound/mpu401.cpp b/sound/mpu401.cpp index 78845f99a8..0b34ed0f7c 100644 --- a/sound/mpu401.cpp +++ b/sound/mpu401.cpp @@ -20,7 +20,8 @@ #include "stdafx.h" #include "mpu401.h" -#include "base/engine.h" // for g_system +#include "base/engine.h" // for g_engine +#include "common/timer.h" #include "common/util.h" // for ARRAYSIZE @@ -82,10 +83,7 @@ const char *MidiDriver::getErrorName(int error_code) { MidiDriver_MPU401::MidiDriver_MPU401() : MidiDriver(), - _started_thread (false), - _mutex (0), _timer_proc (0), - _timer_param (0), _channel_mask (0xFFFF) // Permit all 16 channels by default { @@ -96,14 +94,11 @@ MidiDriver_MPU401::MidiDriver_MPU401() : } void MidiDriver_MPU401::close() { - if (_mutex) { - _started_thread = false; - g_system->lock_mutex (_mutex); // Wait for the timer thread to shutdown. - g_system->unlock_mutex (_mutex); - g_system->delete_mutex (_mutex); - } - int i; - for (i = 0; i < 16; ++i) + // FIXME: I'd really prefer a g_timer instead of going through g_engine + if (_timer_proc) + g_engine->_timer->releaseProcedure (_timer_proc); + _timer_proc = 0; + for (int i = 0; i < 16; ++i) send (0x7B << 8 | 0xB0 | i); } @@ -133,47 +128,13 @@ MidiChannel *MidiDriver_MPU401::allocateChannel() { return NULL; } -void MidiDriver_MPU401::setTimerCallback (void *timer_param, TimerCallback timer_proc) { +void MidiDriver_MPU401::setTimerCallback (void *timer_param, TimerProc timer_proc) { + // FIXME: I'd really prefer a g_timer instead of going through g_engine if (!_timer_proc || !timer_proc) { + if (_timer_proc) + g_engine->_timer->releaseProcedure (_timer_proc); _timer_proc = timer_proc; - _timer_param = timer_param; - if (!_started_thread && timer_proc) { - // TODO: This is the only place in ScummVM where create_thread is - // being used. And it's used for a timer like thread. So if we - // could convert it to use the timer API instead, we could get - // rid of create_thread completely. - _mutex = g_system->create_mutex(); - _started_thread = true; - g_system->create_thread(midi_driver_thread, this); - } + if (timer_proc) + g_engine->_timer->installProcedure (timer_proc, 10000, timer_param); } } - -#if !defined(__MORPHOS__) && !defined(__PALM_OS__) - -int MidiDriver_MPU401::midi_driver_thread(void *param) { - MidiDriver_MPU401 *mid = (MidiDriver_MPU401 *)param; - int old_time, cur_time; - - // Grab the MidiDriver's mutex. When the MidiDriver - // shuts down, it will wait on that mutex until we've - // detected the shutdown and quit looping. - g_system->lock_mutex (mid->_mutex); - - old_time = g_system->get_msecs(); - while (mid->_started_thread) { - g_system->delay_msecs(10); - - cur_time = g_system->get_msecs(); - while (old_time < cur_time) { - old_time += 10; - if (mid->_timer_proc) - (*(mid->_timer_proc)) (mid->_timer_param); - } - } - - g_system->unlock_mutex (mid->_mutex); - return 0; -} -#endif - diff --git a/sound/mpu401.h b/sound/mpu401.h index 5551fdf48c..aef0ea9abb 100644 --- a/sound/mpu401.h +++ b/sound/mpu401.h @@ -78,22 +78,17 @@ public: class MidiDriver_MPU401 : public MidiDriver { private: - typedef void (*TimerCallback) (void*); + typedef void (*TimerProc)(void *refCon); // Copied from class Timer MidiChannel_MPU401 _midi_channels [16]; - volatile bool _started_thread; - OSystem::MutexRef _mutex; // Concurrent shutdown barrier - volatile TimerCallback _timer_proc; - void *_timer_param; + TimerProc _timer_proc; uint16 _channel_mask; - static int midi_driver_thread (void *param); - public: MidiDriver_MPU401(); virtual void close(); - void setTimerCallback(void *timer_param, TimerCallback timer_proc); + void setTimerCallback(void *timer_param, TimerProc timer_proc); uint32 getBaseTempo(void) { return 10000; } uint32 property(int prop, uint32 param); |