int21 / buffered input fix, some migration stuff

Jukka Heinonen jhei at iki.fi
Tue Jan 28 15:26:12 CST 2003


This patch fixes Dungeon Master startup menu.
Buffered input function was rather buggy. Now
it works better but unfortunately the function
it is quite poorly documented in all sources known 
to me.




Changelog:
  Fix buffered input function. Add support
  for UMB subfunctions to memory allocation strategy
  function. Move flock to winedos.




Index: dlls/winedos/int21.c
===================================================================
RCS file: /home/wine/wine/dlls/winedos/int21.c,v
retrieving revision 1.22
diff -u -r1.22 int21.c
--- dlls/winedos/int21.c	28 Jan 2003 00:18:58 -0000	1.22
+++ dlls/winedos/int21.c	28 Jan 2003 21:16:13 -0000
@@ -283,6 +283,80 @@
 
 
 /***********************************************************************
+ *           INT21_BufferedInput
+ *
+ * Handler for function 0x0a.
+ *
+ * Reads a string of characters from standard input until
+ * enter key is pressed.
+ */
+static void INT21_BufferedInput( CONTEXT86 *context )
+{
+    BYTE *ptr = CTX_SEG_OFF_TO_LIN(context,
+                                   context->SegDs,
+                                   context->Edx);
+    BYTE capacity = ptr[0]; /* includes CR */
+    BYTE length = 0;        /* excludes CR */
+
+    TRACE( "BUFFERED INPUT (size=%d)\n", capacity );
+
+    /*
+     * Return immediately if capacity is zero.
+     *
+     * FIXME: What to return to application?
+     */
+    if (capacity == 0)
+        return;
+
+    /*
+     * FIXME: Some documents state that
+     *        ptr[1] holds number of chars from last input which 
+     *        may be recalled on entry, other documents do not mention
+     *        this at all.
+     */
+    if (ptr[1])
+        TRACE( "Handle old chars in buffer!\n" );
+
+    while(TRUE)
+    {
+        BYTE ascii;
+        BYTE scan;
+
+        DOSVM_Int16ReadChar( &ascii, &scan, FALSE );
+
+        if (ascii == '\r' || ascii == '\n')
+        {
+            /*
+             * FIXME: What should be echoed here?
+             */
+            DOSVM_PutChar( '\r' );
+            DOSVM_PutChar( '\n' );
+            ptr[1] = length;
+            ptr[2 + length] = '\r';
+            return;
+        }
+
+        /*
+         * FIXME: This function is supposed to support
+         *        DOS editing keys...
+         */
+
+        /*
+         * If the buffer becomes filled to within one byte of
+         * capacity, DOS rejects all further characters up to,
+         * but not including, the terminating carriage return.
+         */
+        if (ascii != 0 && length < capacity-1)
+        {
+            DOSVM_PutChar( ascii );
+            ptr[2 + length] = ascii;
+            length++;
+        }
+    }
+}
+
+
+/***********************************************************************
  *           INT21_ExtendedCountryInformation
  *
  * Handler for function 0x65.
@@ -792,7 +866,7 @@
         break;
 
     case 0x0a: /* BUFFERED INPUT */
-        INT_Int21Handler( context );
+        INT21_BufferedInput( context );
         break;
 
     case 0x0b: /* GET STDIN STATUS */
@@ -1222,22 +1296,30 @@
         break;
 
     case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
-	TRACE( "GET OR SET MEMORY ALLOCATION STRATEGY, subfunction %d\n", 
-               AL_reg(context) );
         switch (AL_reg(context))
         {
-        case 0x00: /* GET ALLOCATION STRATEGY */
-            SET_AX( context, 1 ); /* low memory best fit */
+        case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
+            TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
+            SET_AX( context, 0 ); /* low memory first fit */
             break;
 
         case 0x01: /* SET ALLOCATION STRATEGY */
-            TRACE( "Set allocation strategy to %d - ignored\n",
+            TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
                    BL_reg(context) );
             break;
 
+        case 0x02: /* GET UMB LINK STATE */
+            TRACE( "GET UMB LINK STATE\n" );
+            SET_AL( context, 0 ); /* UMBs not part of DOS memory chain */
+            break;
+
+        case 0x03: /* SET UMB LINK STATE */
+            TRACE( "SET UMB LINK STATE to %d - ignored\n",
+                   BX_reg(context) );
+            break;
+
         default:
             INT_BARF( context, 0x21 );
-            break;
         }
         break;
 
@@ -1247,8 +1329,35 @@
 
     case 0x5a: /* CREATE TEMPORARY FILE */
     case 0x5b: /* CREATE NEW FILE */ 
-    case 0x5c: /* "FLOCK" - RECORD LOCKING */
         INT_Int21Handler( context );
+        break;
+
+    case 0x5c: /* "FLOCK" - RECORD LOCKING */
+        {
+            DWORD  offset = MAKELONG(DX_reg(context), CX_reg(context));
+            DWORD  length = MAKELONG(DI_reg(context), SI_reg(context));
+            HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
+
+            switch (AL_reg(context))
+            {
+            case 0x00: /* LOCK */
+                TRACE( "lock handle %d offset %ld length %ld\n",
+                       BX_reg(context), offset, length );
+                if (!LockFile( handle, offset, 0, length, 0 ))
+                    bSetDOSExtendedError = TRUE;
+                break;
+
+            case 0x01: /* UNLOCK */
+                TRACE( "unlock handle %d offset %ld length %ld\n",
+                       BX_reg(context), offset, length );
+                if (!UnlockFile( handle, offset, 0, length, 0 ))
+                    bSetDOSExtendedError = TRUE;
+                break;
+
+            default:
+                INT_BARF( context, 0x21 );
+            }
+        }
         break;
 
     case 0x5d: /* NETWORK 5D */




Index: msdos/int21.c
===================================================================
RCS file: /home/wine/wine/msdos/int21.c,v
retrieving revision 1.85
diff -u -r1.85 int21.c
--- msdos/int21.c	28 Jan 2003 00:18:57 -0000	1.85
+++ msdos/int21.c	28 Jan 2003 21:16:19 -0000
@@ -876,43 +876,6 @@
 }
 
 
-static void fLock( CONTEXT86 * context )
-{
-
-    switch ( AX_reg(context) & 0xff )
-    {
-        case 0x00: /* LOCK */
-	  TRACE("lock handle %d offset %ld length %ld\n",
-		BX_reg(context),
-		MAKELONG(DX_reg(context),CX_reg(context)),
-		MAKELONG(DI_reg(context),SI_reg(context))) ;
-          if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context)),
-                        MAKELONG(DX_reg(context),CX_reg(context)), 0,
-                        MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
-	    SET_AX( context, GetLastError() );
-	    SET_CFLAG(context);
-	  }
-          break;
-
-	case 0x01: /* UNLOCK */
-	  TRACE("unlock handle %d offset %ld length %ld\n",
-		BX_reg(context),
-		MAKELONG(DX_reg(context),CX_reg(context)),
-		MAKELONG(DI_reg(context),SI_reg(context))) ;
-          if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context)),
-                          MAKELONG(DX_reg(context),CX_reg(context)), 0,
-                          MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
-	    SET_AX( context, GetLastError() );
-	    SET_CFLAG(context);
-	  }
-	  return;
-	default:
-	  SET_AX( context, 0x0001 );
-	  SET_CFLAG(context);
-	  return;
-     }
-}
-
 static BOOL
 INT21_networkfunc (CONTEXT86 *context)
 {
@@ -978,26 +941,6 @@
             _hwrite16( 1, data, (int)p - (int)data);
             SET_AL( context, '$' ); /* yes, '$' (0x24) gets returned in AL */
         }
-        break;
-
-    case 0x0a: /* BUFFERED INPUT */
-      {
-	char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
-						   context->Edx ));
-	int res;
-
-	TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
-	if (buffer[1])
-	  TRACE("Handle old chars in buffer!\n");
-	res=_lread16( 0, buffer+2,buffer[0]);
-	buffer[1]=res;
-	if(buffer[res+1] == '\n')
-	  buffer[res+1] = '\r';
-	break;
-      }
-
-    case 0x5c: /* "FLOCK" - RECORD LOCKING */
-        fLock(context);
         break;
 
     case 0x0e: /* SELECT DEFAULT DRIVE */




-- 
Jukka Heinonen <http://www.iki.fi/jhei/>



More information about the wine-patches mailing list