diff options
author | Simon Howard | 2009-09-30 00:11:44 +0000 |
---|---|---|
committer | Simon Howard | 2009-09-30 00:11:44 +0000 |
commit | d484bfaf001faeb48fee28d046149108ab52a394 (patch) | |
tree | 69c16f2c37c8714689ba25953681c486f596c99f | |
parent | 614351cebaaf2b1a372c78639d2ede7d1d7091fc (diff) | |
download | chocolate-doom-d484bfaf001faeb48fee28d046149108ab52a394.tar.gz chocolate-doom-d484bfaf001faeb48fee28d046149108ab52a394.tar.bz2 chocolate-doom-d484bfaf001faeb48fee28d046149108ab52a394.zip |
Add Win9x native OPL driver (untested).
Subversion-branch: /branches/opl-branch
Subversion-revision: 1696
-rw-r--r-- | opl/Makefile.am | 5 | ||||
-rw-r--r-- | opl/opl.c | 6 | ||||
-rw-r--r-- | opl/opl_win9x.c | 137 |
3 files changed, 146 insertions, 2 deletions
diff --git a/opl/Makefile.am b/opl/Makefile.am index 9a757fdb..8bbed9f0 100644 --- a/opl/Makefile.am +++ b/opl/Makefile.am @@ -8,10 +8,11 @@ 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_obsd.c \ opl_queue.c opl_queue.h \ + opl_sdl.c \ opl_timer.c opl_timer.h \ + opl_win9x.c \ fmopl.c fmopl.h @@ -45,6 +45,9 @@ extern opl_driver_t opl_linux_driver; #ifdef HAVE_LIBI386 extern opl_driver_t opl_openbsd_driver; #endif +#ifdef _WIN32 +extern opl_driver_t opl_win9x_driver; +#endif extern opl_driver_t opl_sdl_driver; static opl_driver_t *drivers[] = @@ -55,6 +58,9 @@ static opl_driver_t *drivers[] = #ifdef HAVE_LIBI386 &opl_openbsd_driver, #endif +#ifdef _WIN32 + &opl_win9x_driver, +#endif &opl_sdl_driver, NULL }; diff --git a/opl/opl_win9x.c b/opl/opl_win9x.c new file mode 100644 index 00000000..04555760 --- /dev/null +++ b/opl/opl_win9x.c @@ -0,0 +1,137 @@ +// 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 Win9x native interface. +// +//----------------------------------------------------------------------------- + +#include "config.h" + +#ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include "opl.h" +#include "opl_internal.h" +#include "opl_timer.h" + +static unsigned int opl_port_base; + +// MingW? + +#if defined(__GNUC__) && defined(__i386__) + +static unsigned int OPL_Win9x_PortRead(opl_port_t port) +{ + unsigned char result; + + __asm__ volatile ( + "movl %1, %%edx\n" + "inb %%dx, %%al\n" + "movb %%al, %0" + : "=m" (result) + : "r" (opl_port_base + port) + : "edx", "al", "memory" + ); + + return result; +} + +static void OPL_Win9x_PortWrite(opl_port_t port, unsigned int value) +{ + __asm__ volatile ( + "movl %0, %%edx\n" + "movb %1, %%al\n" + "outb %%al, %%dx" + : + : "r" (opl_port_base + port), "r" ((unsigned char) value) + : "edx", "al" + ); +} + +// TODO: MSVC version +// #elif defined(_MSC_VER) && defined(_M_IX6) ... + +#else + +// Not x86, or don't know how to do port R/W on this compiler. + +#define NO_PORT_RW + +static unsigned int OPL_Win9x_PortRead(opl_port_t port) +{ + return 0; +} + +static void OPL_Win9x_PortWrite(opl_port_t port, unsigned int value) +{ +} + +#endif + +static int OPL_Win9x_Init(unsigned int port_base) +{ +#ifndef NO_PORT_RW + + OSVERSIONINFO version_info; + + // Check that this is a Windows 9x series OS: + + GetVersionEx(&version_info); + + if (version_info.dwPlatformId == 1) + { + opl_port_base = port_base; + + // Start callback thread + + return OPL_Timer_StartThread(); + } + +#endif + + return 0; +} + +static void OPL_Win9x_Shutdown(void) +{ + // Stop callback thread + + OPL_Timer_StopThread(); +} + +opl_driver_t opl_win9x_driver = +{ + "Win9x", + OPL_Win9x_Init, + OPL_Win9x_Shutdown, + OPL_Win9x_PortRead, + OPL_Win9x_PortWrite, + OPL_Timer_SetCallback, + OPL_Timer_ClearCallbacks, + OPL_Timer_Lock, + OPL_Timer_Unlock, + OPL_Timer_SetPaused +}; + +#endif /* #ifdef _WIN32 */ + |