[CRT] Massively improve performance of rand_s
[reactos.git] / ntoskrnl / inbv / inbvport.c
index 5f58cff..269c8f9 100644 (file)
@@ -23,22 +23,41 @@ CPPORT Port[4] =
 
 /* FUNCTIONS *****************************************************************/
 
-VOID
+BOOLEAN
 NTAPI
-InbvPortEnableFifo(IN ULONG   PortId,
-                   IN BOOLEAN Enable)
+InbvPortPollOnly(IN ULONG PortId)
 {
-    /* Set FIFO as requested */
-    CpEnableFifo(Port[PortId].Address, Enable);
+    UCHAR Dummy;
+
+    /* Poll a byte from the port */
+    return CpGetByte(&Port[PortId], &Dummy, FALSE, TRUE) == CP_GET_SUCCESS;
+}
+
+BOOLEAN
+NTAPI
+InbvPortGetByte(IN  ULONG  PortId,
+                OUT PUCHAR Byte)
+{
+    /* Read a byte from the port */
+    return CpGetByte(&Port[PortId], Byte, TRUE, FALSE) == CP_GET_SUCCESS;
 }
 
 VOID
 NTAPI
-InbvPortPutByte(IN ULONG   PortId,
-                IN BOOLEAN Output)
+InbvPortPutByte(IN ULONG PortId,
+                IN UCHAR Byte)
 {
     /* Send the byte */
-    CpPutByte(&Port[PortId], Output);
+    CpPutByte(&Port[PortId], Byte);
+}
+
+VOID
+NTAPI
+InbvPortEnableFifo(IN ULONG   PortId,
+                   IN BOOLEAN Enable)
+{
+    /* Set FIFO as requested */
+    CpEnableFifo(Port[PortId].Address, Enable);
 }
 
 VOID
@@ -60,6 +79,45 @@ InbvPortInitialize(IN  ULONG   BaudRate,
     /* Not yet supported */
     ASSERT(IsMMIODevice == FALSE);
 
+#if defined(SARCH_PC98)
+    /* Set default baud rate */
+    if (BaudRate == 0) BaudRate = 9600;
+
+    /* Check if port or address given */
+    if (PortNumber)
+    {
+        /* Pick correct address for port */
+        if (!PortAddress)
+        {
+            if (PortNumber == 1)
+            {
+                PortAddress = (PUCHAR)0x30;
+            }
+            else
+            {
+                PortAddress = (PUCHAR)0x238;
+                PortNumber = 2;
+            }
+        }
+    }
+    else
+    {
+        /* Pick correct port for address */
+        PortAddress = (PUCHAR)0x30;
+        if (CpDoesPortExist(PortAddress))
+        {
+            PortNumber = 1;
+        }
+        else
+        {
+            PortAddress = (PUCHAR)0x238;
+            if (!CpDoesPortExist(PortAddress))
+                return FALSE;
+
+            PortNumber = 2;
+        }
+    }
+#else
     /* Set default baud rate */
     if (BaudRate == 0) BaudRate = 19200;
 
@@ -104,6 +162,7 @@ InbvPortInitialize(IN  ULONG   BaudRate,
             PortNumber = 1;
         }
     }
+#endif
 
     /* Initialize the port unless it's already up, and then return it */
     if (Port[PortNumber - 1].Address) return FALSE;