ref: 6f3d0abb12bcc05336e780414fe84a8f9f25ec26
parent: 07f50245788a5a5b259864c1631d4e97eaec92fb
author: Simon Howard <fraggle@gmail.com>
date: Sat Sep 26 15:56:24 EDT 2009
Add OpenBSD/NetBSD native OPL backend. Subversion-branch: /branches/opl-branch Subversion-revision: 1690
--- a/configure.in
+++ b/configure.in
@@ -71,6 +71,10 @@
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, )
--- a/opl/Makefile.am
+++ b/opl/Makefile.am
@@ -8,6 +8,7 @@
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 \
--- 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[] =
@@ -44,6 +47,9 @@
{
#ifdef HAVE_IOPERM
&opl_linux_driver,
+#endif
+#ifdef HAVE_LIBI386
+ &opl_openbsd_driver,
#endif
&opl_sdl_driver,
NULL
--- /dev/null
+++ b/opl/opl_obsd.c
@@ -1,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 */
+