summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in4
-rw-r--r--opl/Makefile.am1
-rw-r--r--opl/opl.c6
-rw-r--r--opl/opl_obsd.c105
4 files changed, 116 insertions, 0 deletions
diff --git a/configure.in b/configure.in
index 6f450d85..17ec9dc4 100644
--- a/configure.in
+++ b/configure.in
@@ -71,6 +71,10 @@ AC_SDL_MAIN_WORKAROUND([
AC_CHECK_HEADERS([linux/kd.h dev/isa/spkrio.h dev/speaker/speaker.h])
AC_CHECK_FUNCS(mmap sched_setaffinity)
+
+ # OpenBSD I/O i386 library for I/O port access.
+
+ AC_CHECK_LIB(i386, i386_iopl)
])
AC_CHECK_TOOL(WINDRES, windres, )
diff --git a/opl/Makefile.am b/opl/Makefile.am
index d48b491b..9a757fdb 100644
--- a/opl/Makefile.am
+++ b/opl/Makefile.am
@@ -8,6 +8,7 @@ noinst_LIBRARIES=libopl.a
libopl_a_SOURCES = \
opl_internal.h \
opl.c opl.h \
+ opl_obsd.c opl_obsd.h \
opl_linux.c \
opl_sdl.c \
opl_queue.c opl_queue.h \
diff --git a/opl/opl.c b/opl/opl.c
index 9ec19fd4..f28cd63f 100644
--- a/opl/opl.c
+++ b/opl/opl.c
@@ -38,6 +38,9 @@
#ifdef HAVE_IOPERM
extern opl_driver_t opl_linux_driver;
#endif
+#ifdef HAVE_LIBI386
+extern opl_driver_t opl_openbsd_driver;
+#endif
extern opl_driver_t opl_sdl_driver;
static opl_driver_t *drivers[] =
@@ -45,6 +48,9 @@ static opl_driver_t *drivers[] =
#ifdef HAVE_IOPERM
&opl_linux_driver,
#endif
+#ifdef HAVE_LIBI386
+ &opl_openbsd_driver,
+#endif
&opl_sdl_driver,
NULL
};
diff --git a/opl/opl_obsd.c b/opl/opl_obsd.c
new file mode 100644
index 00000000..a3a22ab8
--- /dev/null
+++ b/opl/opl_obsd.c
@@ -0,0 +1,105 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 2009 Simon Howard
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// DESCRIPTION:
+// OPL OpenBSD interface (also NetBSD)
+//
+//-----------------------------------------------------------------------------
+
+#include "config.h"
+
+#ifdef HAVE_LIBI386
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <machine/sysarch.h>
+#include <i386/pio.h>
+
+#include "opl.h"
+#include "opl_internal.h"
+#include "opl_timer.h"
+
+static unsigned int opl_port_base;
+
+static int OPL_OpenBSD_Init(unsigned int port_base)
+{
+ // Try to get permissions:
+
+ if (i386_iopl(1) < 0)
+ {
+ fprintf(stderr, "Failed to get raise I/O privilege level: "
+ "check that you are running as root.\n");
+ return 0;
+ }
+
+ opl_port_base = port_base;
+
+ // Start callback thread
+
+ if (!OPL_Timer_StartThread())
+ {
+ i386_iopl(0);
+ return 0;
+ }
+
+ return 1;
+}
+
+static void OPL_OpenBSD_Shutdown(void)
+{
+ // Stop callback thread
+
+ OPL_Timer_StopThread();
+
+ // Release I/O port permissions:
+
+ i386_iopl(0);
+}
+
+static unsigned int OPL_OpenBSD_PortRead(opl_port_t port)
+{
+ return inb(opl_port_base + port);
+}
+
+static void OPL_OpenBSD_PortWrite(opl_port_t port, unsigned int value)
+{
+ outb(opl_port_base + port, value);
+}
+
+opl_driver_t opl_openbsd_driver =
+{
+ "OpenBSD",
+ OPL_OpenBSD_Init,
+ OPL_OpenBSD_Shutdown,
+ OPL_OpenBSD_PortRead,
+ OPL_OpenBSD_PortWrite,
+ OPL_Timer_SetCallback,
+ OPL_Timer_ClearCallbacks,
+ OPL_Timer_Lock,
+ OPL_Timer_Unlock,
+ OPL_Timer_SetPaused
+};
+
+#endif /* #ifdef HAVE_IOPERM */
+