home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / bye5 / b5-clock.lbr / B5C-LEG2.IQS / B5C-LEG2.INS
Encoding:
Text File  |  1986-03-08  |  4.3 KB  |  158 lines

  1. ;**********************************************************************
  2. ;
  3. ; B5C-LEG2.INS        Wayne Masters
  4. ;  07/15/85        Potpourri, 408-378-7474
  5. ;
  6. ;            For BYE500 and up
  7. ;
  8. ;    TIME routine for BYE5 running on Kaypro 2 with a Legacy RTC.
  9. ;    (adapted from MBC-LGC2.ASM by Sanders, Levitt, Jones)
  10. ;
  11. ;    This insert is designed to work on a Kaypro running BYE5
  12. ;    and equipped with a Legacy Computer Systems RTC.
  13. ;    NOTE:  This is an insert...not an overlay.
  14. ;
  15. ;    (Use the DATE program to initialize the clock outside of BYE.)
  16. ;
  17. ;    Just set the equate below for K2 or K10 to select proper
  18. ;    Data and Command ports for your particular board.
  19. ;
  20. ;    When called this routine will check the RTCBUF. If a '99H'
  21. ;    is in the first byte, the clock is initialized. Next the
  22. ;    seconds are checked, and if changed since last update of
  23. ;    RTC buffer, the clock is stopped, data copied to RTCBUF, the
  24. ;    BCD Hours and minutes converted to binary for CCHOUR/CCMIN
  25. ;    and the clock is restarted. (If no change in seconds, the
  26. ;    routine returns immediately.)
  27. ;
  28. ;**********************************************************************
  29. ;
  30. ; Set TIMEON EQU YES in the BYE5 equates and replace the TIME: routine in
  31. ; BYE5 with this file.
  32. ;
  33. ; select only one of the following
  34. ;
  35. K2    EQU    NO        ; Yes, using Kaypro II board
  36. K10    EQU    YES        ; Yes, using Kaypro 10 board
  37. ;
  38. TIME:
  39.     LDA    RTCBUF        ; Get first BCD byte
  40.     CPI    099H        ; 99 ?
  41.     CZ    CLKINIT        ; If so, init clock...
  42.     MVI    C,0        ; Check low seconds
  43.     CALL    CLKREAD        ; To see if change...
  44.     LXI    H,RTCBUF+2    ; Compared to old secs
  45.     XRA    M        ; Value stored in
  46.     ANI    0FH        ; RTC buffer (low nibble)
  47.     JZ    CLKEXIT        ; If no change, skip update
  48.     MVI    C,5        ; Start with hi hours
  49.     LXI    H,RTCBUF    ; And copy to RTCBUF
  50.     CALL    GETCLK        ; (get time)
  51.     MVI    C,12        ; Start with hi year
  52.     LXI    H,RTCBUF+4    ; And copy to RTCBUF
  53.     CALL    GETCLK        ; (and date)
  54.     LDA    RTCBUF        ; Get hours
  55.     ANI    03FH        ; Mask out PM/24 hour bits
  56.     STA    RTCBUF
  57.     LDA    RTCBUF+6    ; Get day
  58.     ANI    03FH        ; Mask out leap year bit
  59.     STA    RTCBUF+6
  60. ;
  61. CLKEXIT:
  62.     LDA    RTCBUF        ; Pick up HH
  63.     CALL    BCDBIN        ; And convert it to binary
  64.     STA    CCHOUR        ; Save as current hour
  65.     LDA    RTCBUF+1    ; Pick up MM
  66.     CALL    BCDBIN        ; And convert it to binary
  67.     STA    CCMIN        ; Save as current minute
  68.     RET            ; And return (for now..)
  69. ;
  70. GETCLK:
  71.     MVI    B,3        ; Repeat 3 times for 3 BCD bytes
  72. CLKLP:
  73.     CALL    CLKREAD        ; Get data at address C
  74.     RLC ! RLC ! RLC    ! RLC    ; Move to high nibble for BCD
  75.     MOV    M,A        ; Save at location temporarily
  76.     DCR    C        ; Decrement clock addr
  77.     CALL    CLKREAD        ; Get data at next address
  78.     ORA    M        ; OR with previously saved data
  79.     MOV    M,A        ; And save it
  80.     DCR    C        ; Decrement clock addr
  81.     INX    H        ; Increment to next BCD byte
  82.     DCR    B        ; Decrement BCD counter
  83.     JNZ    CLKLP        ; If 3rd BCD byte, done..
  84.     RET            ; Return
  85. ;
  86. ; PIO STUFF
  87. ;
  88.      IF    K2        ; Kaypro II board
  89. DATA    EQU    0AH        ; Port B data
  90. CMD    EQU    0BH        ; Port B cmd
  91.      ENDIF            ; K2
  92. ;
  93.      IF    K10        ; Kaypro 10 board
  94. DATA    EQU    79H        ; Port B data
  95. CMD    EQU    7BH        ; Port B cmd
  96.      ENDIF            ; K10
  97. ;
  98. MODE0    EQU    0FH        ; Output mode
  99. MODE3    EQU    0CFH        ; Bit control mode
  100. ;
  101. ; mask values for clock chip
  102. ;
  103. LATCH    EQU    80H        ; Set address latch (active high)
  104. RD    EQU    20H        ; Read (active high)
  105. HOLD    EQU    10H        ; Time hold (active high)
  106. ;
  107. CLKINIT:
  108.     MVI    A,MODE0        ; Output mode
  109.     OUT    CMD        ; Command port
  110.     MVI    A,3        ; Disable interrupts
  111.     OUT    CMD
  112.     MVI    A,MODE3        ; Set bit control mode
  113.     OUT    CMD
  114.     MVI    A,0FH        ; Set D3-D0 inputs mask
  115.     OUT    CMD
  116.     RET
  117. ;
  118. ; read data into A from address in C
  119. ;
  120. CLKREAD:
  121.     PUSH    B
  122.     MVI    A,MODE3        ; Set bit control mode
  123.     OUT    CMD
  124.     MVI    A,00H        ; Set all outputs mask
  125.     OUT    CMD
  126.     MVI    A,LATCH+HOLD
  127.     ORA    C        ; Set latch, hold, & address
  128.     OUT    DATA
  129.     MVI    A,HOLD
  130.     ORA    C        ; Reset latch
  131.     OUT    DATA
  132.     MVI    B,20        ; Wait 150 uS
  133. CLKR1:    XCHG ! XCHG
  134.     DCR    B
  135.     JNZ    CLKR1
  136.     MVI    A,MODE3        ; Set bit control mode
  137.     OUT    CMD
  138.     MVI    A,0FH        ; Set D3-D0 inputs mask
  139.     OUT    CMD
  140.     MVI    A,RD+HOLD    ; Set read & hold
  141.     OUT    DATA
  142.     XCHG ! XCHG        ; Wait 6 uS
  143.     IN    DATA        ; Input data
  144.     ANI    0FH        ; Just in case
  145.     MOV    C,A        ; Save in C
  146.     XRA    A
  147.     OUT    DATA        ; Write 0 to command register
  148.     MOV    A,C        ; Get saved data
  149.     POP    B        ; Restore BC
  150.     RET
  151. ;
  152. ;
  153. ;**********************************************************************
  154. ;
  155. ; This is the end of the TIME insert for BYE5xx.ASM
  156. ;
  157. ;**********************************************************************
  158.