DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/hardopl.cpp
00001 #include "config.h"
00002 //#include "../libs/porttalk/porttalk.h"
00003 #include "inout.h"
00004 #include "logging.h"
00005 #include "pic.h"
00006 #include "hardware.h"
00007 #if defined (WIN32)
00008 #include "windows.h"
00009 #endif
00010 #include <stdio.h>
00011 
00012 #if defined (WIN32) && 0 //|| defined (LINUX)
00013 
00014 /* prototype (function typedef) for DLL function Inp32: */
00015 
00016      typedef short (_stdcall *inpfuncPtr)(short portaddr);
00017      typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
00018 
00019 /* After successful initialization, these 2 variables
00020    will contain function pointers.
00021  */
00022      extern inpfuncPtr inp32fp;
00023      extern oupfuncPtr oup32fp;
00024 
00025 /* Wrapper functions for the function pointers
00026     - call these functions to perform I/O.
00027  */
00028      extern short  Inp32 (short portaddr);
00029 
00030      extern void  Out32 (short portaddr, short datum);
00031 
00032 static Bit16s hardopldiff;
00033 static bool isCMS;
00034 static FILE * logfp = NULL;
00035 
00036 static void write_hwio(Bitu port,Bitu val,Bitu /*iolen*/) {
00037         if(port<0x388) port += hardopldiff;
00038         //LOG_MSG("write port %x",port);
00039         //outportb(port, val);
00040         Out32(port, val);
00041 }
00042 
00043 static Bitu read_hwio(Bitu port,Bitu /*iolen*/) {
00044         if(port<0x388) port += hardopldiff;
00045         //LOG_MSG("read port %x",port);
00046         //Bitu retval = inportb(port);
00047         Bitu retval = Inp32(port);
00048         return retval;
00049 
00050 }
00051 
00052 // handlers for Gameblaster passthrough
00053 
00054 static void write_hwcmsio(Bitu port,Bitu val,Bitu /*iolen*/) {
00055         if(logfp) fprintf(logfp,"%4.3f w % 3x % 2x\r\n",PIC_FullIndex(),port,val);
00056         //outportb(port + hardopldiff, val);
00057         Out32(port + hardopldiff, val);
00058 }
00059 
00060 static Bitu read_hwcmsio(Bitu port,Bitu /*iolen*/) {
00061         //Bitu retval = inportb(port + hardopldiff);
00062         Bitu retval = Inp32(port + hardopldiff);
00063         if(logfp) fprintf(logfp,"%4.3f r\t\t% 3x % 2x\r\n",PIC_FullIndex(),port,retval);
00064         return retval;
00065 }
00066 
00067 bool hwopl_dirty=false;
00068 
00069 static IO_ReadHandleObject* hwOPL_ReadHandler[16] ;
00070 static IO_WriteHandleObject* hwOPL_WriteHandler[16];
00071 
00072 const Bit16u oplports[]={
00073                 0x0,0x1,0x2,0x3,0x8,0x9,
00074                 0x388,0x389,0x38A,0x38B};
00075 
00076 void HARDOPL_Init(Bitu hardwareaddr, Bitu blasteraddr, bool isCMSp) {
00077         isCMS = isCMSp;
00078         int err=0;
00079      HINSTANCE hLib;
00080 
00081      short x;
00082      int i;
00083 
00084 
00085      /* Load the library for win 64 driver */
00086      hLib = LoadLibrary("inpout32.dll");
00087 
00088      if (hLib == NULL) {
00089           LOG_MSG("LoadLibrary Failed.\n");
00090           return ;
00091      }
00092 
00093      /* get the address of the function */
00094 
00095      inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
00096 
00097      if (inp32fp == NULL) {
00098           LOG_MSG("GetProcAddress for Inp32 Failed.\n");
00099           return ;
00100      }
00101 
00102 
00103      oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
00104 
00105      if (oup32fp == NULL) {
00106           LOG_MSG("GetProcAddress for Oup32 Failed.\n");
00107           return ;
00108      }
00109 /*
00110         if(!(hardwareaddr==0x210 || hardwareaddr==0x220 || hardwareaddr==0x230 ||
00111                  hardwareaddr==0x240 || hardwareaddr==0x250 || hardwareaddr==0x260 ||
00112                  hardwareaddr==0x280)) {
00113                         LOG_MSG("OPL passthrough: Invalid hardware base address. Aborting.");
00114                         return;
00115                  }
00116         
00117         if(!initPorttalk()) {
00118 #ifdef WIN32            
00119                 LOG_MSG("OPL passthrough: Porttalk not loaded. Aborting.");
00120 #endif
00121 #ifdef LINUX
00122                 LOG_MSG("OPL passthrough: permission denied. Aborting.");
00123 #endif
00124                 return;
00125         }
00126 */
00127         hardopldiff=hardwareaddr-blasteraddr;
00128         hwopl_dirty=true;
00129 
00130         // map the port
00131         LOG_MSG("Port mappings hardware -> DOSBox:");
00132 
00133         if(isCMS) {
00134                 logfp=OpenCaptureFile("Portlog",".portlog.txt");
00135                 hwOPL_ReadHandler[0]=new IO_ReadHandleObject();
00136                 hwOPL_WriteHandler[0]=new IO_WriteHandleObject();
00137                 hwOPL_ReadHandler[0]->Install(blasteraddr, read_hwcmsio, IO_MB, 16);
00138                 hwOPL_WriteHandler[0]->Install(blasteraddr, write_hwcmsio, IO_MB, 16);
00139                 //for(int i = 0; i < 0x10; i++) {
00140                 //      addIOPermission(hardwareaddr+i);
00141                 //}
00142                 LOG_MSG("%x-%x -> %x-%x",hardwareaddr,hardwareaddr+15,blasteraddr,blasteraddr+15);
00143         } else {
00144                 for(int i = 0; i < 10; i++)     {
00145                         hwOPL_ReadHandler[i]=new IO_ReadHandleObject();
00146                         hwOPL_WriteHandler[i]=new IO_WriteHandleObject();
00147                         Bit16u port=oplports[i];
00148                         if(i<6) port+=blasteraddr; 
00149                         hwOPL_ReadHandler[i]->Install(port,read_hwio,IO_MB);
00150                         hwOPL_WriteHandler[i]->Install(port,write_hwio,IO_MB);
00151 
00152                         if(i<6) port+=hardopldiff;
00153                         LOG_MSG("%x -> %x",port,i<6?port-hardopldiff:port);
00154                         //addIOPermission(port);
00155                 }
00156         }
00157         //setPermissionList();
00158 }
00159 
00160 void HWOPL_Cleanup() {
00161         if(logfp) fclose(logfp);
00162         if(hwopl_dirty) {
00163                 for(int i = 0; i < 10; i++) {
00164                         delete hwOPL_ReadHandler[i];
00165                         delete hwOPL_WriteHandler[i];
00166                 }
00167                 hwopl_dirty=false;
00168         }
00169 }
00170 #else
00171 
00172 void HWOPL_Cleanup() {}
00173 void HARDOPL_Init(Bitu hardwareaddr, Bitu blasteraddr, bool isCMSp) {
00174     (void)hardwareaddr;//UNUSED
00175     (void)blasteraddr;//UNUSED
00176     (void)isCMSp;//UNUSED
00177         LOG_MSG("OPL passthrough is not supported on this operating system.");
00178 }
00179 #endif