From 506fb710434c0c5afd8ea9597ccd8dd88fae3dc1 Mon Sep 17 00:00:00 2001
From: Andreas Mohr <mohr@elektron.ikp.physik.tu-darmstadt.de>
Date: Thu, 13 May 1999 18:44:14 +0000
Subject: [PATCH] Implemented InsertInASPIChain and fixed minor things.

---
 dlls/winaspi/winaspi16.c | 67 ++++++++++++++++++++++++++++++----------
 if1632/winaspi.spec      |  2 +-
 include/aspi.h           |  4 +--
 3 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/dlls/winaspi/winaspi16.c b/dlls/winaspi/winaspi16.c
index 0c670eb67df..45c9bcf2323 100644
--- a/dlls/winaspi/winaspi16.c
+++ b/dlls/winaspi/winaspi16.c
@@ -27,6 +27,10 @@ DEFAULT_DEBUG_CHANNEL(aspi)
  */
 
 #ifdef linux
+
+static FARPROC16 ASPIChainFunc = NULL;
+static WORD HA_Count = 1; /* host adapter count; FIXME: detect it */
+
 static int
 ASPI_OpenDevice16(SRB_ExecSCSICmd16 *prb)
 {
@@ -383,13 +387,10 @@ WORD WINAPI GetASPISupportInfo16()
 {
 #ifdef linux
     TRACE(aspi, "GETASPISupportInfo16\n");
-    /* high byte SS_COMP - low byte number of host adapters.
-     * FIXME!!! The number of host adapters is incorrect.
-     * I'm not sure how to determine this under linux etc.
-     */
-    return ((SS_COMP << 8) | 1);
+    /* high byte SS_COMP - low byte number of host adapters */
+    return ((SS_COMP << 8) | HA_Count);
 #else
-    return ((SS_COMP << 8) | 0);
+    return ((SS_NO_ASPI << 8) | 0);
 #endif
 }
 
@@ -407,6 +408,16 @@ DWORD ASPI_SendASPICommand(DWORD ptrSRB, UINT16 mode)
 	break;
       case ASPI_WIN16:
 	lpSRB = PTR_SEG_TO_LIN(ptrSRB);
+	if (ASPIChainFunc)
+	{
+	    /* This is not the post proc, it's the chain proc this time */
+	    DWORD ret = Callbacks->CallASPIPostProc(ASPIChainFunc, ptrSRB);
+	    if (ret)
+	    {
+		lpSRB->inquiry.SRB_Status = SS_INVALID_SRB;
+		return ret;
+	    }
+	}
 	break;
   }
 
@@ -417,7 +428,7 @@ DWORD ASPI_SendASPICommand(DWORD ptrSRB, UINT16 mode)
 	TRACE(aspi, "Extended request detected (Adaptec's ASPIxDOS).\nWe don't support it at the moment.\n");
     }
     lpSRB->inquiry.SRB_ExtBufferSize = 0x2000; /* bogus value */
-    lpSRB->inquiry.HA_Count = 1;               /* not always */
+    lpSRB->inquiry.HA_Count = HA_Count;
     lpSRB->inquiry.HA_SCSI_ID = 7;             /* not always ID 7 */
     strcat(lpSRB->inquiry.HA_ManagerId, "Wine ASPI16"); /* max 15 chars */
     strcat(lpSRB->inquiry.HA_Identifier, "Wine host"); /* FIXME: return host
@@ -436,12 +447,10 @@ adapter name */
     FIXME(aspi, "Not implemented SC_RESET_DEV\n");
     break;
   default:
-    WARN(aspi, "Unknown command %d\n", lpSRB->common.SRB_Cmd);
+    FIXME(aspi, "Unknown command %d\n", lpSRB->common.SRB_Cmd);
   }
-  return SS_INVALID_SRB;
-#else
-  return SS_INVALID_SRB;
 #endif
+  return SS_INVALID_SRB;
 }
 
 
@@ -458,6 +467,34 @@ WORD WINAPI SendASPICommand16(SEGPTR segptr_srb)
 }
 
 
+/***********************************************************************
+ *             InsertInASPIChain16   (WINASPI.3)
+ */
+WORD WINAPI InsertInASPIChain16(BOOL16 remove, FARPROC16 pASPIChainFunc)
+{
+#ifdef linux
+    if (remove == TRUE) /* Remove */
+    {
+	if (ASPIChainFunc == pASPIChainFunc)
+	{
+	    ASPIChainFunc = NULL;
+	    return SS_COMP;
+	}
+    }
+    else
+    if (remove == FALSE) /* Insert */
+    {
+	if (ASPIChainFunc == NULL)
+	{
+	    ASPIChainFunc = pASPIChainFunc;
+	    return SS_COMP;
+	}
+    }
+#endif
+    return SS_ERR;
+}
+
+
 /***********************************************************************
  *             GetASPIDLLVersion16   (WINASPI.4)
  */
@@ -465,9 +502,9 @@ WORD WINAPI SendASPICommand16(SEGPTR segptr_srb)
 DWORD WINAPI GetASPIDLLVersion16()
 {
 #ifdef linux
-	return (DWORD)2;
+	return 2;
 #else
-	return (DWORD)0;
+	return 0;
 #endif
 }
 
@@ -498,8 +535,6 @@ void ASPI_DOS_HandleInt(CONTEXT *context)
 	    AX_reg(context) = CX_reg(context);
 	}
 	else
-	SET_CFLAG(context);
-#else
-       SET_CFLAG(context);
 #endif
+	SET_CFLAG(context);
 }
diff --git a/if1632/winaspi.spec b/if1632/winaspi.spec
index 01af0f8702e..a7cbf91410d 100644
--- a/if1632/winaspi.spec
+++ b/if1632/winaspi.spec
@@ -3,6 +3,6 @@ type	win16
 
 1	pascal16 GetASPISupportInfo() GetASPISupportInfo16
 2	pascal16 SendASPICommand(segptr) SendASPICommand16
-3       stub INSERTINASPICHAIN
+3   pascal16 InsertInASPIChain(word segptr) InsertInASPIChain16
 4	pascal GETASPIDLLVERSION() GetASPIDLLVersion16
 5	stub ___EXPORTEDSTUB
diff --git a/include/aspi.h b/include/aspi.h
index f899e46f4a7..2700a2aa676 100644
--- a/include/aspi.h
+++ b/include/aspi.h
@@ -9,12 +9,12 @@
 #define SS_COMP         0x01
 #define SS_ABORTED      0x02
 #define SS_ERR          0x04
+#define SS_INVALID_HA   0x81
+#define SS_INVALID_SRB  0xe0
 #define SS_OLD_MANAGE   0xe1
 #define SS_ILLEGAL_MODE 0xe2
 #define SS_NO_ASPI      0xe3
 #define SS_FAILED_INIT  0xe4
-#define SS_INVALID_HA   0x81
-#define SS_INVALID_SRB  0xe0
 #define SS_ASPI_IS_BUSY 0xe5
 #define SS_BUFFER_TO_BIG        0xe6
 
-- 
GitLab