home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / clkmnt11.lbr / CLOCKMNT.Z80 < prev   
Encoding:
Text File  |  1992-01-30  |  2.1 KB  |  64 lines

  1.     TITLE    CLOCKMNT
  2. ;                                 Version 1.1
  3. ;                               by Steve Dresser
  4. ;                                   01/30/92
  5. ;
  6. ;    For use with Kenmore real-time clock and ZS/ZdDOS
  7. ;
  8. ; Gets current date directly from the clock registers.
  9. ; Compares current month to month of the previous run, and
  10. ;    increments the year register if current month is less.
  11. ; Saves month in unused latch (base address of chip + 00FH)
  12. ;    for future reference.
  13. ; Computes day-of-week for current date and
  14. ;    sets the Kenmore's day-of-week register.
  15. ;
  16. ;===============================================================
  17.     EXTRN    WDAY0    ; Convert BCD date to weekday (0-6)
  18.     .REQUEST    ZSLIB,SYSLIB
  19. ;
  20. CLOCK    EQU    0E0H    ; Base address of Kenmore RTC
  21. WEEK    EQU    CLOCK+5        ; Day-of-week stored here
  22. DAY    EQU    CLOCK+6        ; Day-of-month stored here
  23. MONTH    EQU    CLOCK+7        ; Month stored here
  24. YEAR    EQU    CLOCK+9        ; Year stored here
  25. PRVMON    EQU    CLOCK+0FH    ; Month on last clock access
  26.  
  27. CLOCKMNT:
  28.     LD    (STACK),SP    ; Save stack pointer
  29.     LD    SP,STACK    ; SP points to new stack
  30.     IN    A,(PRVMON)    ; Month saved at last run
  31.     LD    B,A        ; Save it in B
  32.     IN    A,(MONTH)    ; <A> = Current Month
  33.     OUT    (PRVMON),A    ; Update previous month latch
  34.     CP    B        ; Is Current < Previous?
  35.     JR    NC,SETWKDAY    ; If not, don't change the year
  36.     IN    A,(YEAR)    ; <A> = Year.
  37.     ADD    A,1        ; Bump it up
  38.     DAA            ; Adjust for packed BCD.
  39.     OUT    (YEAR),A    ; Store Year in chip.
  40. SETWKDAY:
  41.     LD    HL,DATTIM    ; ADDR DATE/TIME STRING
  42.     PUSH    HL        ; Save on stack
  43.     LD    C,YEAR        ; Point to port addr of year
  44.     INI            ; Read port and bump HL
  45.     LD    BC,256*2+MONTH    ; B=2, C to address of month
  46. RDLOOP:
  47.     INI            ; Read data and increment HL
  48.     DEC    BC        ; Decrement C, flags unchanged
  49.     JR    NZ,RDLOOP    ; Do until B = 0
  50.     POP    HL        ; Point to start of DATTIM
  51.     CALL    WDAY0        ; Put number of weekday in A
  52.     OR    A        ; Set Z-flag if 0
  53.     JR    NZ,SET        ; Don't change it if not 0
  54.     ADD    A,7        ; Change Saturday to 7
  55. SET:
  56.     OUT    (WEEK),A    ; Set weekday
  57.     LD    SP,(STACK)    ; Get old stack
  58.     RET
  59.     DSEG
  60. DATTIM:    DS    6        ; Date/time storage
  61.     DS    48        ; Stack area
  62. STACK:    DS    2        ; Value of stack ptr saved here
  63.     END
  64.