BUG: DOSGetCurDate Incorrect in DISKMENU PWB Extension

Last reviewed: July 17, 1997
Article ID: Q100743
2.00 2.01.49 MS-DOS kbtool kbcode kbbuglist

The information in this article applies to:

  • Microsoft Programmer's WorkBench for MS-DOS, versions 2.0 and 2.01.49

SYMPTOMS

An attempt to use the DOSGetCurDate function in the DISKMENU.C sample Programmer's WorkBench (PWB) extension provided with Microsoft C/C++ version 7.0 fails to return the date correctly.

CAUSE

The DOSGetCurDate function is designed to return the date in a packed MS- DOS format. This format is used by Interrupt 21h Function 57h that the DOSSetFileTime function calls. Therefore, the format of the unsigned integer result value should be as follows:

    bits 00h-04h   = day   (1-31)
    bits 05h-08h   = month (1-12)
    bits 09h-0Fh   = year  (relative to 1980)

However, because the extension code shifts the DH register left by five bits the most significant bit of the month number is lost and only the first seven months are represented.

RESOLUTION

Replace the DOSGetCurDate function in the DISKMENU extension with the following code:

   //  DOSGetCurDate - Get current DOS date
   //
   //  Returns the current DOS date in packed format
   //
   unsigned __pascal DOSGetCurDate(void)
   {
      unsigned rv;
      _asm
      {
         mov ah, 2ah         // Get the date
         int 21h
         sub cx, 1980        // CX contains the year. Make relative
                             // to 1980 for DOSSetFileTime function
      #ifdef _M_I8086
         shl cx, 1           // shift to add month from DH
         shl cx, 1
         shl cx, 1
         shl cx, 1
      #else
         shl cx, 4
      #endif
         or  cl, dh           // insert month from DH
      #ifdef _M_I8086
         shl cx, 1            // shift to add day
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
      #else
         shl cx, 5
      #endif
         or  cl, dl           // insert day from DL
         mov rv, cx
      }
      return rv;
   }

MORE INFORMATION

The incorrect code is as follows:

Sample code

   unsigned __pascal DOSGetCurDate( void )
   {
      unsigned rv;
      _asm
      {
         mov ah, 2ah
         int 21h
         sub cx, 1980
      #ifdef _M_I8086
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
         shl cx, 1
      #else
         shl cx, 9
      #endif
         or  cl, dl
      #ifdef _M_I8086
         shl dh, 1
         shl dh, 1
         shl dh, 1
         shl dh, 1
         shl dh, 1
      #else
         shl dh, 5
      #endif
         or  cl, dh
         mov rv, cx
      }
      return rv;
   }


Additional reference words: 2.00 2.01.49 buglist2.00 buglist2.01.49
KBCategory: kbtool kbcode kbbuglist
KBSubcategory: PwbIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.