home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1703.ZIP / TI1703.ASC
Text File  |  1993-10-08  |  6KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1703
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  October 8, 1993                          PAGE  :  1/3
  12.  
  13.     TITLE  :  Possible conflicts with DOS time and date functions
  14.  
  15.  
  16.  
  17.  
  18.   Every IBM compatible PC is capable of keeping track of the
  19.   current date and time.  Your PC can keep the current time
  20.   even when it is turned off, because of a clock that is built
  21.   in to the CMOS.  However, this CMOS clock is only used once,
  22.   when your computer is turned on.  From this point on the
  23.   date/time is maintained by both BIOS and DOS working together.
  24.   Because of some quirks in the way BIOS and DOS work, some
  25.   problems can occur if you are not careful in your program.
  26.  
  27.   To understand these problems and how to avoid them, we first
  28.   need to see how BIOS and DOS stores the time.  The BIOS keeps
  29.   two variables in memory at the following locations:
  30.  
  31.     0x0040:0x006C - # of ticks since midnight (double word)
  32.     0x0040:0x0070 - midnight flag (byte)
  33.  
  34.   These values are updated 18.2 times a second, by the system
  35.   timer.  This timer does nothing but increment the tick count,
  36.   and check to see if midnight has passed.  If midnight passes,
  37.   the tick count is reset to 0, and the midnight flag is set
  38.   to 1.  It is important to note the midnight flag is a Boolean,
  39.   not a count.  That is, it doesn't count the number of times
  40.   midnight has passed, it only indicates that midnight has passed
  41.   "at least once".
  42.  
  43.   It is also important to note that the BIOS doesn't update
  44.   the actual clock time or date.  It only updates the timer tick
  45.   count and midnight flag.  DOS maintains the time and date, but
  46.   only when you ask it to retrieve these values.
  47.  
  48.   There are several ways to find the current date and time.  Listed
  49.   below are BIOS/DOS interrupts, and their corresponding functions
  50.   from the Borland C++ run-time library:
  51.  
  52.    BIOS int 0x1A,0x00 - read system time (biostime)
  53.    BIOS int 0x1A,0x01 - DOS system time  (biostime)
  54.    DOS  int 0x21,0x2A - get DOS date     (getdate, _dos_getdate)
  55.    DOS  int 0x21,0x2B - set DOS date     (setdate, _dos_setdate)
  56.    DOS  int 0x21,0x2C - get DOS time     (gettime, _dos_gettime)
  57.    DOS  int 0x21,0x2D - set DOS time     (settime, _dos_settime)
  58.  
  59.   The DOS functions operate by first calling the BIOS function
  60.   to get the timer tick count and midnight flag, and then
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1703
  75.   VERSION  :  All
  76.        OS  :  DOS
  77.      DATE  :  October 8, 1993                          PAGE  :  2/3
  78.  
  79.     TITLE  :  Possible conflicts with DOS time and date functions
  80.  
  81.  
  82.  
  83.  
  84.   calculating the appropriate values.  The date is only updated
  85.   when you call one of the DOS date functions.
  86.  
  87.   The first problem that can occur is due to the fact that the
  88.   midnight flag is Boolean.  DOS only updates the date when you
  89.   call a DOS date function, and the midnight flag is reset at
  90.   this time.  Consider the following scenario:
  91.  
  92.     actual                                           DOS date
  93.     date/time   | F |  event                      |  after event
  94.     ------------+---+-----------------------------+---------------
  95.     12/01 12:00 |   |  turn on computer           |  12/01
  96.     12/02 00:00 | X |  midnight flag is set       |  12/01
  97.     12/02 15:45 |   |  call DOS getdate function  |  12/02
  98.     12/03 00:01 | X |  midnight flag set          |  12/02
  99.     12/04 00:00 | X |  midnight flag set (again)  |  12/02
  100.     12/04 11:30 |   |  call DOS getdate function  |  12/03
  101.  
  102.   If an entire day passes with no call to a date function, the
  103.   internal DOS date never gets updated, causing a day to be missed.
  104.  
  105.   The second problem comes in because of how BIOS int 0x1A
  106.   operates.  Whenever you call this function to retrieve the
  107.   system time (the current timer tick value) it also returns the
  108.   current midnight flag and RESETS THE FLAG.  But since the BIOS
  109.   function doesn't update the DOS date, the next time you ask for
  110.   the date, it will not be updated correctly.  DOS is aware of
  111.   the behavior, so when you call any DOS function, the midnight
  112.   flag is maintained correctly.  If you call BIOS int 0x1A
  113.   yourself, you MUST check the midnight flag value and turn it
  114.   back on if it was set.
  115.  
  116.   The following function is a safe replacement for the biostime()
  117.   function.  It properly restores the midnight flag, avoiding the
  118.   problem described above:
  119.  
  120.   long safebiostime(int cmd, long newtime) {
  121.     long temptime;
  122.     asm {
  123.       mov     ax,cmd
  124.       mov     dx,word ptr newtime
  125.       mov     cx,word ptr newtime+2
  126.       int     0x1a
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1703
  141.   VERSION  :  All
  142.        OS  :  DOS
  143.      DATE  :  October 8, 1993                          PAGE  :  3/3
  144.  
  145.     TITLE  :  Possible conflicts with DOS time and date functions
  146.  
  147.  
  148.  
  149.  
  150.       mov     word ptr temptime,dx
  151.       mov     word ptr temptime+2,cx
  152.       or      al,al
  153.       jz      not_midnight
  154.       mov     ax,0x40
  155.       mov     es,ax
  156.       mov     bx,0x70
  157.       mov     byte ptr es:[bx],1
  158.     }
  159.   not_midnight:
  160.  
  161.     return temptime;
  162.   }
  163.  
  164.   DISCLAIMER: You have the right to use this technical information
  165.   subject to the terms of the No-Nonsense License Statement that
  166.   you received with the Borland product to which this information
  167.   pertains.
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.