Microsoft KB Archive/100743

From BetaArchive Wiki

BUG: DOSGetCurDate Incorrect in DISKMENU PWB Extension

Q100743



The information in this article applies to:


  • Microsoft Programmer's Workbench for MS-DOS, versions 2.0, 2.1.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 query words: 2.00 2.01.49 buglist2.00 buglist2.01.49

Keywords : kb16bitonly
Issue type :
Technology : kbAudDeveloper kbPWBSearch kbZNotKeyword3 kbPWB200DOS kbPWB2149DOS


Last Reviewed: June 12, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.