[Wine-patches] [eterhack 12/12] kernel32: Use parport.sys functions if it is loaded.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Чт Май 21 17:53:48 MSD 2009


---
 dlls/kernel32/instr.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/instr.c b/dlls/kernel32/instr.c
index 9014ecf..a035884 100644
--- a/dlls/kernel32/instr.c
+++ b/dlls/kernel32/instr.c
@@ -46,6 +46,19 @@ WINE_DECLARE_DEBUG_CHANNEL(io);
 #define ADD_LOWORD(dw,val)  ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
 #define ISV86(context)      ((context)->EFlags & 0x00020000)
 
+static CRITICAL_SECTION pp_section;
+static CRITICAL_SECTION_DEBUG critsect_debug =
+{
+    0, 0, &pp_section,
+    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
+      0, 0, { (DWORD_PTR)(__FILE__ ": pp_section") }
+};
+static CRITICAL_SECTION pp_section = { &critsect_debug, -1, 0, 0, 0, 0 };
+
+static int parport_flag;
+static UCHAR (CDECL *pp_read)( UCHAR* );
+static void (CDECL *pp_write)( UCHAR*, UCHAR );
+
 static inline void add_stack( CONTEXT86 *context, int offset )
 {
     if (ISV86(context) || !IS_SELECTOR_32BIT(context->SegSs))
@@ -364,6 +377,27 @@ static BOOL INSTR_EmulateLDS( CONTEXT86 *context, BYTE *instr, int long_op,
     return TRUE;
 }
 
+/* set pointers to parport.sys functions if it is loaded */
+static void init_parport(void)
+{
+    static const WCHAR parportW[] = {'p','a','r','p','o','r','t','.','s','y','s',0};
+
+    static HMODULE parport;
+
+    RtlEnterCriticalSection( &pp_section );
+    if (!parport_flag)
+    {
+        parport = GetModuleHandleW( parportW );
+        if (parport)
+        {
+            pp_read = (void *)GetProcAddress( parport, "__wine_read_parport" );
+            pp_write = (void *)GetProcAddress( parport, "__wine_write_parport" );
+        }
+        parport_flag = 1;
+    }
+    RtlLeaveCriticalSection( &pp_section );
+}
+
 /***********************************************************************
  *           INSTR_inport
  *
@@ -374,7 +408,9 @@ static DWORD INSTR_inport( WORD port, int size, CONTEXT86 *context )
     DWORD res = ~0U;
 
     if (!winedos.inport) load_winedos();
-    if (winedos.inport) res = winedos.inport( port, size );
+    if (!parport_flag) init_parport();
+    if (pp_read && size == 1) res = pp_read( (UCHAR *)(int)port );
+    else if (winedos.inport) res = winedos.inport( port, size );
 
     if (TRACE_ON(io))
     {
@@ -406,7 +442,9 @@ static DWORD INSTR_inport( WORD port, int size, CONTEXT86 *context )
 static void INSTR_outport( WORD port, int size, DWORD val, CONTEXT86 *context )
 {
     if (!winedos.outport) load_winedos();
-    if (winedos.outport) winedos.outport( port, size, val );
+    if (!parport_flag) init_parport();
+    if (pp_write && size == 1) pp_write( (UCHAR *)(int)port, val );
+    else if (winedos.outport) winedos.outport( port, size, val );
 
     if (TRACE_ON(io))
     {
-- 
1.6.2.5



Подробная информация о списке рассылки Wine-patches