home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / MMCLK12.ZIP / MMCLOCK.DOC < prev    next >
Encoding:
Text File  |  1990-08-01  |  9.8 KB  |  233 lines

  1.                  MMCLOCK.SYS
  2.  
  3.              An installable driver for the
  4.             National Semiconductor MM58167A
  5.              real-time clock/calendar chip
  6.  
  7.                  Version 1.2
  8.                   June 1990
  9.  
  10.              Richard B. Wales
  11.              UCLA Computer Science Dept.
  12.              3531 Boelter Hall
  13.              Los Angeles, CA 90024-1596
  14.              (213) 825-5683
  15.              Internet:  wales@CS.UCLA.EDU
  16.  
  17.  
  18. WHAT IS MMCLOCK.SYS?
  19.  
  20. MMCLOCK.SYS is an installable device driver for a real-time clock/calendar
  21. (PC or XT) based on the National Semiconductor MM58167A chip.  This chip is
  22. used in various multifunction cards and clone motherboards.
  23.  
  24. Add-on clock cards usually come with some software for manipulating the date
  25. and time on the card.  Many of these programs are inconvenient to use and/or
  26. are of inferior quality.  The great majority of them do not understand about
  27. leap year (which could give you minor headaches in 1992).  MMCLOCK.SYS per-
  28. mits the clock card to be treated "transparently"; the system date/time is
  29. automatically set on each reboot, and any changes to the date/time (e.g., via
  30. the DOS commands DATE and TIME) automatically update the clock card without
  31. the need to run any additional program.
  32.  
  33. MMCLOCK.SYS was written in assembly language and assembled using the Borland
  34. Turbo Assembler (version 2.0).  The code has also been successfully assem-
  35. bled using the Microsoft Macro Assembler (version 5.1).
  36.  
  37. INSTALLING THE DRIVER
  38.  
  39. In most cases, all that need be done is to put MMCLOCK.SYS on a disk drive
  40. (generally C:) and add a DRIVER= line to the CONFIG.SYS file.  MMCLOCK.SYS
  41. will automatically locate the clock/calendar (if present).
  42.  
  43. If MMCLOCK.SYS cannot find the clock/calendar, it may be that the hardware is
  44. set up to use an unusual I/O port address.  In this case, you need to deter-
  45. mine the port address used (possibly by disassembling the driver software
  46. that came with the machine or card), and then include this address as an argu-
  47. ment on the DRIVER= line.  For example:
  48.  
  49.             DRIVER=C:\BIN\MMCLOCK.SYS 280
  50.  
  51. Note that not all add-on clock/calendar cards use the MM58167A chip.  If your
  52. clock card does not use this chip, MMCLOCK.SYS will not work for you.
  53.  
  54. If you use MMCLOCK.SYS, you should NOT use ANY other clock driver or other
  55. software that may have been supplied with your clock card.  This is impor-
  56. tant, because MMCLOCK.SYS reads and writes the date on the clock card in a
  57. highly nonstandard manner that is completely incompatible with other drivers.
  58.  
  59. COMPATIBILITY CONSIDERATIONS
  60.  
  61. MMCLOCK.SYS works with the same kind of clock/calendar hardware as does the
  62. Strickland clock driver (CLKDRV.SYS).  Any software which claims compatibil-
  63. ity with CLKDRV.SYS should work equally well with MMCLOCK.SYS.
  64.  
  65. MMCLOCK.SYS IMPLEMENTATION DETAILS
  66.  
  67. The following information is not essential for the user of MMCLOCK.SYS, but
  68. may be interesting to some users.
  69.  
  70. The MM58167A chip contains a 14-decimal-digit counter, plus 14 hexadecimal
  71. digits (56 bits) of RAM.
  72.  
  73. The counter holds the month, day of the month, day of the week, and time of
  74. day (hours, minutes, seconds, and milliseconds).
  75.  
  76. The RAM is officially designed to hold the same kind of information as the
  77. counter -- in conjunction with an alarm-clock interrupt feature.  However,
  78. most clock cards which use the MM58167A do not even try to use the alarm-
  79. clock facility, so the RAM can in practice hold arbitrary data.
  80.  
  81. The counter data is accessed via eight consecutive I/O ports, thus:
  82.  
  83.      Port        High-order        Low-order
  84.         number          nybble         nybble
  85.     =================================================
  86.      x+0        1/1000 sec          ZERO
  87.      x+1         1/10 sec        1/100 sec
  88.      x+2            seconds (2 digits)
  89.      x+3            minutes (2 digits)
  90.      x+4             hours (2 digits)
  91.      x+5           ZERO            day of wk.
  92.      x+6             day of month (2 digits)
  93.      x+7             month (2 digits)
  94.  
  95. Wherever "2 digits" are indicated, the value is stored as binary coded deci-
  96. mal (BCD) -- not as straight binary.
  97.  
  98. The "day of the week" portion of the counter cycles through the values 1
  99.  through 7 inclusive.
  100.  
  101. The RAM is laid out in the same manner as the counter, and is accessed via
  102. eight consecutive I/O ports (x+8 through x+15).  The two nybbles shown as
  103. "ZERO" in the counter diagram above do not have RAM associated with them; any-
  104. thing written to these two nybbles will be discarded, and the value read for
  105. these nybbles will always be zero.
  106.  
  107. Except for the two "ZERO" nybbles, the RAM is not restricted to BCD values;
  108. rather, any nybble may hold any 4-bit binary value.
  109.  
  110. The MM58167A also has several status and control registers.  In particular,
  111. one status register indicates whether the clock has ticked during a "read" or
  112. "write" operation.  Since some hardware implementations may not provide
  113. access to the status and control registers, MMCLOCK.SYS does not use them.
  114. Instead, after the counter information has been read/written, MMCLOCK.SYS
  115. reads back the low-order position of the counter and compares it with the
  116. value originally read/written.  If the re-read value does not match the orig-
  117. inal value, the read/write is repeated.
  118.  
  119. The MM58167A chip has two major flaws which complicate efforts to use it as a
  120. perpetual clock/calendar.  The first problem is that it has no provisions for
  121. keeping track of the year.  The second problem (a logical consequence of the
  122. first) is that it has no concept of a leap year.  Many drivers or other soft-
  123. ware for the MM58167A simply store the year somewhere in the RAM; this tech-
  124. nique doesn't work very well for leap year, however.  Since the RAM may be
  125. used in just about any desired fashion at all, though, it is possible to get
  126. around these problems through clever, unorthodox use of the RAM.
  127.  
  128. MMCLOCK.SYS handles the date in a manner that completely bypasses the issue
  129. of leap years.  The fourth and fifth byte of the clock chip's RAM are used to
  130. store a 16-bit integer representing the number of days since January 1, 1980.
  131. Each time the date is set in this manner, the "month" and "day" portions of
  132. the clock counter are set to January 1, no matter what the real date might be.
  133.  
  134. When MMCLOCK.SYS reads the date from the clock, it examines both the count of
  135. days in the RAM and the date information in the counter.  The month and day
  136. from the counter are not used "as is", but are instead translated into an
  137. integer number of days elapsed since January 1.  This number is added to the
  138. RAM's day count to give the current date.
  139.  
  140. The "day count" technique turns out to be especially convenient, as this is
  141. precisely the format in which DOS expects a clock driver to handle the date
  142. anyway.  MMCLOCK.SYS doesn't need to convert between the day count and a con-
  143. ventional month/day/year format (DOS already does that).  Further, there is
  144. no need to be concerned about leap years.
  145.  
  146. Whenever the date has advanced since the last time it was set (i.e., whenever
  147. the "month" and "day" information in the counter says something other than
  148. January 1), MMCLOCK.SYS rewrites the date in the RAM and the counter.  This
  149. prevents the month/day information in the counter from getting too high, and
  150. simplifies the task of translating month and day into a number of days.  The
  151. resetting of the date is skipped, however, if the time on the clock is 23:59;
  152. this averts the possibility that the time might roll over to midnight (and a
  153. new day) while the date is being rewritten.
  154.  
  155. Whenever the time of day is reset, MMCLOCK.SYS also updates the BIOS time-of-
  156. day count (via INT 1AH, function 1).  As a result, any programs which depend
  157. on the BIOS time-of-day count at 0040:006CH will work OK.
  158.  
  159.  
  160. REQUIREMENTS FOR A DOS CLOCK DRIVER
  161.  
  162. The following information may be useful for the programmer who wishes to
  163. write a DOS driver for a different clock/calendar card.  It is assumed that
  164. the reader already understands the basics for writing an installable device
  165. driver under DOS.
  166.  
  167. The "attribute word" for a clock driver should be 8008H.
  168.  
  169. The driver needs to handle the various possible I/O requests as follows:
  170.  
  171.      0 (initialize)
  172.         Initialize the driver.
  173.  
  174.      4 (read)
  175.         Read the date/time.
  176.  
  177.      8 (write)
  178.      9 (write and verify)
  179.         Write the date/time.
  180.  
  181.      1 (media check)
  182.      2 (build parameter block)
  183.      6 (current input status)
  184.      7 (flush input buffers)
  185.     10 (current output status)
  186.     11 (flush output buffers)
  187.     13 (open)
  188.     14 (close)
  189.         Set DONE status bit, but do nothing else.
  190.  
  191.      5 (non-destructive read)
  192.         Set BUSY, ERROR, and DONE status bits, but do nothing else.
  193.  
  194.      3 (I/O control read)
  195.     12 (I/O control write)
  196.     15 (removable media check)
  197.     16 (output until busy)
  198.         Set UNKNOWN, ERROR, and DONE status bits, but do nothing
  199.         else.
  200.  
  201. For "read" and "write" operations, DOS communicates with the clock driver
  202. via a six-byte buffer with the following format (all fields are in straight
  203. binary, not BCD):
  204.  
  205.     Byte    Meaning
  206.  
  207.     0-1    Date (16-bit count of days elapsed since 1 January 1980;
  208.         low-order byte comes first).
  209.  
  210.      2    Minutes (0-59).
  211.  
  212.      3    Hours (0-23).
  213.  
  214.      4    Hundredths of a second (0-99).
  215.  
  216.      5    Seconds (0-59).
  217.  
  218. CONDITIONS FOR USING MMCLOCK.SYS
  219.  
  220. MMCLOCK.SYS is Copyright 1990 by Richard B. Wales.  It may be freely used by
  221. anyone without charge.  You may distribute it to anyone, but you may not
  222. charge anything (beyond a nominal copying or communications charge).  You may
  223. not distribute the MMCLOCK.SYS file alone, but you must distribute the source
  224. code and this documentation along with it.  You may not distribute a modified
  225. version of MMCLOCK.SYS, its source, or this documentation unless you clearly
  226. indicate what you have modified.
  227.  
  228. The author (Richard B. Wales) believes that MMCLOCK.SYS is bug-free.  How-
  229. ever, he is not responsible for any damages which you may incur as a result
  230. of using MMCLOCK.SYS -- including incidental or consequential damages -- even
  231. if he has been informed in advance of the possibility of such damages.  Use
  232. of MMCLOCK.SYS is completely at your own risk, and you accept full responsi-
  233. bility for its use.