Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new OPL proxy with dynamic address #119

Merged
merged 11 commits into from
Dec 31, 2018
Merged
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,14 @@ set(CHIPS_SOURCES
"src/opl/chips/dosbox/dbopl.cpp"
"src/opl/chips/nuked_opl3_v174.cpp"
"src/opl/chips/nuked/nukedopl3_174.c")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND CHIPS_SOURCES "src/opl/chips/win9x_opl_proxy.cpp")
endif()
add_library(Chips STATIC ${CHIPS_SOURCES})
target_include_directories(Chips PUBLIC "src")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_compile_definitions(Chips PUBLIC "-DENABLE_WIN9X_OPL_PROXY")
endif()

set(MEASURER_SOURCES
"src/opl/measurer.cpp")
Expand All @@ -118,6 +124,7 @@ set(SOURCES
"src/formats_sup.cpp"
"src/importer.cpp"
"src/latency.cpp"
"src/hardware.cpp"
"src/ins_names.cpp"
"src/main.cpp"
"src/opl/generator.cpp"
Expand Down
4 changes: 3 additions & 1 deletion FMBankEdit.pro
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ rtmidi {
DEFINES += ENABLE_MIDI
include("src/midi/midi_rtmidi.pri")
}
win32: lessThan(QT_MAJOR_VERSION, 5):{
win32 {
include("src/opl/chips/win9x_opl_proxy.pri")
DEFINES += ENABLE_WIN9X_OPL_PROXY
}
Expand Down Expand Up @@ -122,6 +122,7 @@ SOURCES += \
src/formats_sup.cpp \
src/importer.cpp \
src/latency.cpp \
src/hardware.cpp \
src/ins_names.cpp \
src/main.cpp \
src/opl/generator.cpp \
Expand Down Expand Up @@ -162,6 +163,7 @@ HEADERS += \
src/formats_sup.h \
src/importer.h \
src/latency.h \
src/hardware.h \
src/ins_names.h \
src/main.h \
src/opl/generator.h \
Expand Down
4 changes: 3 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ IF NOT -%1-==-win9x- (
SET DEST_ARCHIVE=opl3-bank-editor-dev-win32.zip
SET DEPLOY_FILES=.\bin-release\*
IF -%1-==-win9x- (
SET DEPLOY_FILES=%DEPLOY_FILES% .\opl_proxy\liboplproxy.dll
SET DEPLOY_FILES=%DEPLOY_FILES% .\opl_proxy\win9x\liboplproxy.dll
SET DEST_ARCHIVE=opl3-bank-editor-dev-win9x.zip
) ELSE (
SET DEPLOY_FILES=%DEPLOY_FILES% .\opl_proxy\modern\liboplproxy.dll .\opl_proxy\modern\inpout32.dll
)
SET DEPLOY_FILES=%DEPLOY_FILES% Bank_Examples
SET DEPLOY_FILES=%DEPLOY_FILES% .\formats_info.htm .\license.txt .\changelog.txt
Expand Down
File renamed without changes.
110 changes: 110 additions & 0 deletions opl_proxy/modern/InpOut32Helper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* inpout32.dll helper functions
* 2013 James Alan Nguyen
* http://www.codingchords.com
*
* Do whatever you want with it. Made this while trying to port the OPL passthrough
* routines on VGMPlay, since PortTalk does not work under 64-bit Windows.
*/

#include "InpOut32Helper.h"

typedef void (__stdcall *lpOut32)(short, short);
typedef short (__stdcall *lpInp32)(short);
typedef BOOL (__stdcall *lpIsInpOutDriverOpen)(void);
typedef BOOL (__stdcall *lpIsXP64Bit)(void);

static lpOut32 gfpOut32 = 0;
static lpInp32 gfpInp32 = 0;
static lpIsInpOutDriverOpen gfpIsInpOutDriverOpen = 0;
static lpIsXP64Bit gfpIsXP64Bit = 0;

static HINSTANCE hInpOutDll ;
#ifdef _DEBUG
static FILE *hwlog;
#endif

/*
* Returns true if inpout32 failed to open (necessary for applications checking for non-zero failures)
*/
BOOL OpenInpOut32(void)
{
#if defined(_X86_)
hInpOutDll = LoadLibraryW ( L"InpOut32.DLL" ) ; //The 32bit DLL. If we are building x64 C++
//applicaiton then use InpOutx64.dll
#elif defined(_AMD64_)
hInpOutDll = LoadLibraryW ( L"InpOutX64.DLL" ) ;
#endif
if ( hInpOutDll != NULL )
{
gfpOut32 = (lpOut32)GetProcAddress(hInpOutDll, "Out32");
gfpInp32 = (lpInp32)GetProcAddress(hInpOutDll, "Inp32");
gfpIsInpOutDriverOpen = (lpIsInpOutDriverOpen)GetProcAddress(hInpOutDll, "IsInpOutDriverOpen");
gfpIsXP64Bit = (lpIsXP64Bit)GetProcAddress(hInpOutDll, "IsXP64Bit");

if (gfpIsInpOutDriverOpen())
#ifdef _DEBUG
hwlog = fopen("C:\\OPLSynth\\hwlog.log", "a");
fprintf(hwlog, "Opened driver\n");
#endif
return FALSE;
}

#if defined(_X86_)
MessageBoxW(NULL, L"Cannot load inpout32.dll for hardware OPL playback.", L"OPL3_HW", MB_OK | MB_ICONEXCLAMATION);
#elif defined(_AMD64_)
MessageBoxW(NULL, L"Cannot load inpoutx64.dll for hardware OPL playback.", L"OPL3_HW", MB_OK | MB_ICONEXCLAMATION);
#endif
return TRUE;
}

void CloseInpOut32(void)
{
#ifdef _DEBUG
fprintf(hwlog, "Closed driver\n");
fclose(hwlog);
#endif
FreeLibrary(hInpOutDll);
gfpOut32 = NULL;
gfpInp32 = NULL;
gfpIsInpOutDriverOpen = NULL;
gfpIsXP64Bit = NULL;
}

void outportb(unsigned short PortAddress, unsigned short Data)
{
if (gfpOut32 == NULL)
{
#ifdef _DEBUG
#if defined(_X86_)
MessageBoxW(NULL, L"Cannot write to register; inpout32.dll not loaded.", L"DEBUG", MB_OK | MB_ICONERROR);
#elif defined(_AMD64_)
MessageBoxW(NULL, L"Cannot write to register; inpoutx64.dll not loaded.", L"DEBUG", MB_OK | MB_ICONERROR);
#endif
#endif
return;
}
gfpOut32(PortAddress, Data);
#ifdef _DEBUG
fprintf(hwlog, "Write: %x, %x\n", PortAddress, Data);
#endif
}

unsigned char inportb(unsigned short PortAddress)
{
if (gfpInp32 == NULL)
{
#ifdef _DEBUG
#if defined(_X86_)
MessageBoxW(NULL, L"Cannot read register; inpout32.dll not loaded.", L"DEBUG", MB_OK | MB_ICONERROR);
#elif defined(_AMD64_)
MessageBoxW(NULL, L"Cannot read register; inpoutx64.dll not loaded.", L"DEBUG", MB_OK | MB_ICONERROR);
#endif
#endif
return ~0;
}
#ifdef _DEBUG
fprintf(hwlog, "Read: %x\n", PortAddress);
#endif
return (char)gfpInp32(PortAddress);
}
13 changes: 13 additions & 0 deletions opl_proxy/modern/InpOut32Helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#ifndef INPOUT32_HELPER_H
#define INPOUT32_HELPER_H

#include <stdio.h>
#include <windows.h>

BOOL OpenInpOut32(void);
void CloseInpOut32(void);
void outportb(unsigned short PortAddress, unsigned short Data);
unsigned char inportb(unsigned short PortAddress);

#endif /*INPOUT32_HELPER_H*/
File renamed without changes.
Binary file added opl_proxy/modern/inpout32.dll
Binary file not shown.
Binary file added opl_proxy/modern/liboplproxy.dll
Binary file not shown.
File renamed without changes.
28 changes: 28 additions & 0 deletions opl_proxy/modern/liboplproxy_exports.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
There is an export table in .edata at 0x6fdc6000

The Export Tables (interpreted .edata section contents)

Export Flags 0
Time/Date stamp 5c1afcbf
Major/Minor 0/0
Name 00006050 oplproxy.dll
Ordinal Base 1
Number in:
Export Address Table 00000004
[Name Pointer/Ordinal] Table 00000004
Table Addresses
Export Address Table 00006028
Name Pointer Table 00006038
Ordinal Table 00006048

Export Address Table -- Ordinal Base 1
[ 0] +base[ 1] 15b0 Export RVA
[ 1] +base[ 2] 15e8 Export RVA
[ 2] +base[ 3] 15be Export RVA
[ 3] +base[ 4] 15da Export RVA

[Ordinal/Name Pointer] Table
[ 0] chipInit@0
[ 1] chipPoke@8
[ 2] chipSetPort@4
[ 3] chipUnInit@0
50 changes: 50 additions & 0 deletions opl_proxy/modern/oplproxy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* OPL3 chip interface proxy for OPL Bank Editor by Wohlstand,
* a part of free tool for music bank editing
*
* Copyright (c) 2016-2018 Vitaly Novichkov <[email protected]>
*
* 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 3 of the License, or
* 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, see <http://www.gnu.org/licenses/>.
*/

/*
Can be built by mingw-w64
*/

#include "InpOut32Helper.h"

#define DLLExport __declspec(dllexport)
#define STDCall __stdcall
typedef unsigned short uint16_t;

static uint16_t OPLBase = 0x388;

DLLExport void STDCall chipInit(void)
{ OpenInpOut32(); }

DLLExport void STDCall chipSetPort(uint16_t port)
{ OPLBase = port; }

DLLExport void STDCall chipUnInit(void)
{ CloseInpOut32(); }

DLLExport void STDCall chipPoke(uint16_t index, uint16_t value)
{
uint16_t c, o = (index >> 8), port = (OPLBase + o * 2);
outportb(port, index);
for(c = 0; c < 6; ++c) inportb(port);
outportb(port + 1, value);
for(c = 0; c < 35; ++c) inportb(port);
}

File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions opl_proxy/win9x/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.lib
!liboplproxy.dll
*.map
*.lk1
*.mk1
*.sym
*.mk
*.obj
6 changes: 6 additions & 0 deletions opl_proxy/win9x/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OPL Proxy - a small backend tool created for OPL Bank Editor by Wohlstand
to provide ability to test instruments on real OPL3 chip by running under Windows 98.

On Windows NT family operating system this trick will not work.

Build this tool by OpenWatcom
File renamed without changes.
Loading