home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / MMCLK12.ZIP / DATE.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-03-27  |  3.7 KB  |  139 lines

  1.     include    mmclock.mac
  2.     title    MM58167A date routines -- Copyright 1990 Wales
  3.  
  4. ; ======================================================================
  5. ;
  6. ; Date routines for the MM58167A clock/calendar.
  7. ; (C) Copyright 1990 Richard B. Wales.  All Rights Reserved.
  8. ;
  9. ; Global variables:
  10. ;
  11. ;    None.
  12. ;
  13. ; Global routines:
  14. ;
  15. ;    GetDate
  16. ;        Reads the date from the real-time clock.
  17. ;
  18. ;    SetDate
  19. ;        Sets the date in the real-time clock.
  20.  
  21. ; ======================================================================
  22. ;
  23. ; Global symbols.
  24.  
  25.     public    GetDate, SetDate
  26.  
  27. ; ======================================================================
  28. ;
  29. ; XLAT table for converting BCD to binary (in TIME.ASM).
  30.  
  31.     extrn    bcd2bin:byte
  32.  
  33. ; ======================================================================
  34. ;
  35. ; XLAT table for converting a month into a number of days.
  36. ; Since we need the total number of days since the date was last reset
  37. ; to be no more than 255, this table goes only up to August.
  38.  
  39. mon2day    db    -1, 30, 58, 89, 119, 150, 180, 211
  40.  
  41. ; ======================================================================
  42. ;
  43. ; GetDate
  44. ;
  45. ;    Read the date info from the clock.
  46. ;
  47. ;    Arguments:
  48. ;
  49. ;        DX    Should be set to the initial I/O port address
  50. ;            for the clock.
  51. ;
  52. ;    Returned values:
  53. ;
  54. ;        CX    Date, represented as a 16-bit unsigned integer giving
  55. ;            the number of days since 1 January 1980.
  56. ;        DX    Number of days since the date was last set.
  57. ;
  58. ;    Note:
  59. ;        No effort is made to detect clock rollover while reading
  60. ;        the date.  This task is performed by "ClkToBuf".
  61.  
  62. GetDate    proc    near
  63.  
  64.     ; Set up DS now, so that it will be ready for XLAT'ing later.
  65.     ; Since INIT_DS uses AX, we could not keep the pseudo-date in
  66.     ; AX if we deferred INIT_DS to just before DS was needed.
  67.     INIT_DS
  68.  
  69.     ; Read the pseudo-date (month/day from clock) and the long-count
  70.     ; date (4th and 5th bytes of clock RAM).  We get the pseudo-date
  71.     ; last because we need to play with it using several XLAT's.
  72.     add    dx, 11            ; skip to 4th/5th bytes of RAM
  73.     INWR    cx            ; long-count date (save in CX)
  74.     sub    dx, 5            ; skip to 7th/8th bytes of counter
  75.     INWR    ax            ; day and month (save in AX)
  76.  
  77.     ; Convert everything from BCD to straight binary.
  78.     ; Note that we are accepting months only through August, in order
  79.     ; to ensure that the extra day count will be less than 256.
  80.     mov    bx, offset bcd2bin
  81.     XLATCKZ    ax, ax, 8, 31, bad_read
  82.  
  83.     ; Translate the month into a number of days, add in the extra days,
  84.     ; and add the total to the long-count date.  This gives us the current
  85.     ; date (taking into account the time that has elapsed since the date
  86.     ; was last set).
  87.     mov    bx, offset mon2day - 1
  88.     xlat                ; month -> # of days
  89.     add    al, ah            ; add in extra days
  90.     xor    ah, ah
  91.     add     cx, ax            ; add month/day to long count
  92.     mov    dx, ax            ; return # days since date set too
  93.     ret
  94.  
  95. bad_read:
  96.     ; If the date info is bogus, return 1 January 1980 (0 days).
  97.     xor    cx, cx
  98.     xor    dx, dx
  99.     ret
  100.  
  101. GetDate    endp
  102.  
  103. ; ======================================================================
  104. ;
  105. ; SetDate
  106. ;
  107. ;    Write the time-of-day info to the clock.
  108. ;
  109. ;    Arguments:
  110. ;
  111. ;        CX    Long-count date (number of days since 1/1/80).
  112. ;        DX    Should be set to the initial I/O port address
  113. ;            for the clock.
  114. ;
  115. ;    Returned values:
  116. ;
  117. ;        None.
  118. ;
  119. ;    Note:
  120. ;
  121. ;        No effort is made to detect clock rollover while setting
  122. ;        the date, since care is taken to call this routine only
  123. ;        in situations where midnight cannot occur during its
  124. ;        execution.
  125.  
  126. SetDate    proc    near
  127.  
  128.     add    dx, 6            ; start with pseudo-date
  129.     mov    ax, 0101h        ; set pseudo-date
  130.     OUTWR    ax            ; pseudo-date (January 1)
  131.     add    dx, 5            ; date in 4th/5th bytes of RAM
  132.     OUTWR    cx            ; long-count date
  133.     ret
  134.  
  135. SetDate    endp
  136.  
  137. code    ends
  138.  
  139.     end