summaryrefslogtreecommitdiff
path: root/opl
diff options
context:
space:
mode:
authorSimon Howard2009-03-10 21:55:55 +0000
committerSimon Howard2009-03-10 21:55:55 +0000
commit84a05be9dbc9d1b181670f8fd7e036bbe691d856 (patch)
tree1705a506cfc5f66637b11921715bbc88b750f0bf /opl
parentca7f823d48bb78eda9048750909cdb315836125c (diff)
downloadchocolate-doom-84a05be9dbc9d1b181670f8fd7e036bbe691d856.tar.gz
chocolate-doom-84a05be9dbc9d1b181670f8fd7e036bbe691d856.tar.bz2
chocolate-doom-84a05be9dbc9d1b181670f8fd7e036bbe691d856.zip
Add OPL lib plumbing and Linux native driver.
Subversion-branch: /branches/opl-branch Subversion-revision: 1458
Diffstat (limited to 'opl')
-rw-r--r--opl/Makefile.am4
-rw-r--r--opl/opl.c56
-rw-r--r--opl/opl_internal.h96
-rw-r--r--opl/opl_linux.c79
4 files changed, 228 insertions, 7 deletions
diff --git a/opl/Makefile.am b/opl/Makefile.am
index 65f8b2de..e1dbe42c 100644
--- a/opl/Makefile.am
+++ b/opl/Makefile.am
@@ -4,6 +4,8 @@ AM_CFLAGS=@SDLMIXER_CFLAGS@
noinst_LIBRARIES=libopl.a
libopl_a_SOURCES = \
+ opl_internal.h \
opl.c opl.h \
- fmopl.c
+ opl_linux.c \
+ fmopl.c fmopl.h
diff --git a/opl/opl.c b/opl/opl.c
index d3dfc23b..28609223 100644
--- a/opl/opl.c
+++ b/opl/opl.c
@@ -23,27 +23,71 @@
//
//-----------------------------------------------------------------------------
+#include "config.h"
+
+#include <stdlib.h>
+
#include "opl.h"
+#include "opl_internal.h"
+
+#ifdef HAVE_IOPERM
+extern opl_driver_t opl_linux_driver;
+#endif
+
+static opl_driver_t *drivers[] =
+{
+#ifdef HAVE_IOPERM
+ &opl_linux_driver,
+#endif
+ NULL
+};
+
+static opl_driver_t *driver = NULL;
int OPL_Init(unsigned int port_base)
{
- // TODO
- return 1;
+ int i;
+
+ // Try drivers until we find a working one:
+
+ for (i=0; drivers[i] != NULL; ++i)
+ {
+ if (drivers[i]->init_func(port_base))
+ {
+ driver = drivers[i];
+ return 1;
+ }
+ }
+
+ return 0;
}
void OPL_Shutdown(void)
{
- // TODO
+ if (driver != NULL)
+ {
+ driver->shutdown_func();
+ driver = NULL;
+ }
}
void OPL_WritePort(opl_port_t port, unsigned int value)
{
- // TODO
+ if (driver != NULL)
+ {
+ driver->write_port_func(port, value);
+ }
}
unsigned int OPL_ReadPort(opl_port_t port)
{
- // TODO
- return 0;
+ if (driver != NULL)
+ {
+ return driver->read_port_func(port);
+ }
+ else
+ {
+ return 0;
+ }
}
diff --git a/opl/opl_internal.h b/opl/opl_internal.h
new file mode 100644
index 00000000..964f55cc
--- /dev/null
+++ b/opl/opl_internal.h
@@ -0,0 +1,96 @@
+// 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 internal interface.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef OPL_INTERNAL_H
+#define OPL_INTERNAL_H
+
+#include "opl.h"
+
+typedef int (*opl_init_func)(unsigned int port_base);
+typedef void (*opl_shutdown_func)(void);
+typedef unsigned int (*opl_read_port_func)(opl_port_t port);
+typedef void (*opl_write_port_func)(opl_port_t port, unsigned int value);
+
+typedef struct
+{
+ char *name;
+
+ opl_init_func init_func;
+ opl_shutdown_func shutdown_func;
+ opl_read_port_func read_port_func;
+ opl_write_port_func write_port_func;
+} opl_driver_t;
+
+#endif /* #ifndef OPL_INTERNAL_H */
+
+// 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 internal interface.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef OPL_INTERNAL_H
+#define OPL_INTERNAL_H
+
+#include "opl.h"
+
+typedef int (*opl_init_func)(unsigned int port_base);
+typedef void (*opl_shutdown_func)(void);
+typedef unsigned int (*opl_read_port_func)(opl_port_t port);
+typedef void (*opl_write_port_func)(opl_port_t port, unsigned int value);
+
+typedef struct
+{
+ char *name;
+
+ opl_init_func init_func;
+ opl_shutdown_func shutdown_func;
+ opl_read_port_func read_port_func;
+ opl_write_port_func write_port_func;
+} opl_driver_t;
+
+#endif /* #ifndef OPL_INTERNAL_H */
+
diff --git a/opl/opl_linux.c b/opl/opl_linux.c
new file mode 100644
index 00000000..438b091a
--- /dev/null
+++ b/opl/opl_linux.c
@@ -0,0 +1,79 @@
+// 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 Linux interface.
+//
+//-----------------------------------------------------------------------------
+
+#include "config.h"
+
+#ifdef HAVE_IOPERM
+
+#include <unistd.h>
+#include <sys/io.h>
+
+#include "opl.h"
+#include "opl_internal.h"
+
+static unsigned int opl_port_base;
+
+static void OPL_Linux_Init(unsigned int port_base)
+{
+ // Try to get permissions:
+
+ if (ioperm(port_base, 2, 1) < 0)
+ {
+ return 0;
+ }
+
+ opl_port_base = port_base;
+
+ return 1;
+}
+
+static void OPL_Linux_Shutdown(void)
+{
+ // Release permissions
+
+ ioperm(opl_port_base, 2, 0);
+}
+
+static unsigned int OPL_Linux_PortRead(opl_port_t port)
+{
+ return inb(opl_port_base + port);
+}
+
+static void OPL_Linux_PortWrite(opl_port_t port, unsigned int value)
+{
+ outb(opl_port_base + port, value);
+}
+
+opl_driver_t opl_linux_driver =
+{
+ "Linux",
+ OPL_Linux_Init,
+ OPL_Linux_Shutdown,
+ OPL_Linux_PortRead,
+ OPL_Linux_PortWrite
+};
+
+#endif /* #ifdef HAVE_IOPERM */
+