summaryrefslogtreecommitdiff
path: root/opl/opl.c
diff options
context:
space:
mode:
authorSimon Howard2009-08-28 18:04:04 +0000
committerSimon Howard2009-08-28 18:04:04 +0000
commite33a4961331301b1e3a5c65d148050fa33c4c594 (patch)
treebf28e4e1af04818592e64af72320438b69245ed1 /opl/opl.c
parent480a31094b7621dd7d65ec05a6e36964dca99b66 (diff)
downloadchocolate-doom-e33a4961331301b1e3a5c65d148050fa33c4c594.tar.gz
chocolate-doom-e33a4961331301b1e3a5c65d148050fa33c4c594.tar.bz2
chocolate-doom-e33a4961331301b1e3a5c65d148050fa33c4c594.zip
Working SDL OPL driver.
Subversion-branch: /branches/opl-branch Subversion-revision: 1632
Diffstat (limited to 'opl/opl.c')
-rw-r--r--opl/opl.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/opl/opl.c b/opl/opl.c
index 5fddf205..e53b5d6e 100644
--- a/opl/opl.c
+++ b/opl/opl.c
@@ -28,6 +28,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include "SDL.h"
+
#include "opl.h"
#include "opl_internal.h"
@@ -36,12 +38,14 @@
#ifdef HAVE_IOPERM
extern opl_driver_t opl_linux_driver;
#endif
+extern opl_driver_t opl_sdl_driver;
static opl_driver_t *drivers[] =
{
#ifdef HAVE_IOPERM
&opl_linux_driver,
#endif
+ &opl_sdl_driver,
NULL
};
@@ -129,3 +133,57 @@ void OPL_Unlock(void)
}
}
+typedef struct
+{
+ int finished;
+
+ SDL_mutex *mutex;
+ SDL_cond *cond;
+} delay_data_t;
+
+static void DelayCallback(void *_delay_data)
+{
+ delay_data_t *delay_data = _delay_data;
+
+ SDL_LockMutex(delay_data->mutex);
+ delay_data->finished = 1;
+ SDL_UnlockMutex(delay_data->mutex);
+
+ SDL_CondSignal(delay_data->cond);
+}
+
+void OPL_Delay(unsigned int ms)
+{
+ delay_data_t delay_data;
+
+ if (driver == NULL)
+ {
+ return;
+ }
+
+ // Create a callback that will signal this thread after the
+ // specified time.
+
+ delay_data.finished = 0;
+ delay_data.mutex = SDL_CreateMutex();
+ delay_data.cond = SDL_CreateCond();
+
+ OPL_SetCallback(ms, DelayCallback, &delay_data);
+
+ // Wait until the callback is invoked.
+
+ SDL_LockMutex(delay_data.mutex);
+
+ while (!delay_data.finished)
+ {
+ SDL_CondWait(delay_data.cond, delay_data.mutex);
+ }
+
+ SDL_UnlockMutex(delay_data.mutex);
+
+ // Clean up.
+
+ SDL_DestroyMutex(delay_data.mutex);
+ SDL_DestroyCond(delay_data.cond);
+}
+