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

  1. ;
  2. ;**********************************************************************
  3. ;
  4. ; B5C-KPRO.INS    A TIME insert for BYE500 and up
  5. ;  07/15/85    Note:  This is an insert--not an overlay
  6. ;            Wayne Masters
  7. ;            Potpourri, 408-378-7474
  8. ;
  9. ; Adapted from:
  10. ; MBC-KPRO.ASM -- Version 1.0 -- 03/01/84 -- by Kim Levitt
  11. ;
  12. ;    TIME routine for BYE5 running on Kaypro 2 with Pro-Clock
  13. ;    (adapted from Kaypro Pro-Clock driver written by Greg Haerr)
  14. ;
  15. ;    This overlay is designed to work on a Kaypro II running BYE5
  16. ;    and equipped with a Business Computer Systems Pro-Clock RTC.
  17. ;    (Use the DATE program to initialize the clock outside of BYE.)
  18. ;    (BCS address: 5350 South 3600 West; Salt Lake City, UT 84118)
  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 and
  24. ;    the clock is restarted. (If no change in seconds, the
  25. ;    routine returns immediately.)
  26. ;
  27. ;**********************************************************************
  28. ;
  29. TIME:
  30.     LDA    RTCBUF        ; Get first BCD byte
  31.     CPI    099H        ; 99 ?
  32.     CZ    CLKINIT        ; If so, init clock...
  33.     CALL    HOLDON        ; Put clock on hold
  34.     MVI    C,0        ; Check low seconds
  35.     CALL    RDPIO        ; To see if change...
  36.     LXI    H,RTCBUF+2    ; Compared to old secs
  37.     XRA    M        ; Value stored in
  38.     ANI    0FH        ; RTC buffer (low nibble)
  39.     JZ    CLKEXIT        ; If no change, skip update
  40.     MVI    C,5        ; Start with hi hours
  41.     LXI    H,RTCBUF    ; And copy to RTCBUF
  42.     CALL    GETCLK        ; (get time)
  43.     MVI    C,12        ; Start with hi year
  44.     LXI    H,RTCBUF+4    ; And copy to RTCBUF
  45.     CALL    GETCLK        ; (and date)
  46.     LDA    RTCBUF        ; Get hours
  47.     ANI    03FH        ; Mask out PM/24 hour bits
  48.     STA    RTCBUF
  49.     LDA    RTCBUF+6    ; Get day
  50.     ANI    03FH        ; Mask out leap year bit
  51.     STA    RTCBUF+6
  52. CLKEXIT:
  53.     MVI    C,13        ; Set clock addr. to
  54.     CALL    WRADDR        ; Junk location so no data cleared
  55.     CALL    HOLDOFF        ; When we take clock off hold..
  56.     LDA    RTCBUF        ; Get BCD HH
  57.     CALL    BCDBIN        ; Convert to binary
  58.     STA    CCHOUR        ; For BYE5
  59.     LDA    RTCBUF+1    ; Get BCD MM
  60.     CALL    BCDBIN        ; Convert to binary
  61.     STA    CCMIN        ; For BYE5
  62.     RET            ; And return (for now..)
  63. ;
  64. GETCLK:
  65.     MVI    B,3        ; Repeat 3 times for 3 BCD bytes
  66. CLKLP:
  67.     CALL    RDPIO        ; Get data at address C
  68.     RLC ! RLC ! RLC    ! RLC    ; Move to high nibble for BCD
  69.     MOV    M,A        ; Save at location temporarily
  70.     DCR    C        ; Decrement clock addr
  71.     CALL    RDPIO        ; Get data at next address
  72.     ORA    M        ; OR with previously saved data
  73.     MOV    M,A        ; And save it
  74.     DCR    C        ; Decrement clock addr
  75.     INX    H        ; Increment to next BCD byte
  76.     DCR    B        ; Decrement BCD counter
  77.     JNZ    CLKLP        ; If 3rd BCD byte, done..
  78.     RET            ; Return
  79. ;
  80. ; PIO STUFF
  81. ;
  82. MODE3    EQU    0CFH        ; Bit control mode
  83. ;
  84. DATA    EQU    0AH        ; Port B data
  85. CMD    EQU    0BH        ; Port B cmd
  86. ;
  87. ; mask values for clock chip
  88. ;
  89. LATCH    EQU    80H        ; Set address latch (active high)
  90. WR    EQU    40H        ; Write (active high)
  91. RD    EQU    20H        ; Read (active high)
  92. HOLD    EQU    10H        ; Time hold (active high)
  93. ;
  94. CLKINIT:
  95.     MVI    A,7        ; Disable interrupts
  96.     OUT    CMD
  97. ;
  98. ; fall into set output
  99. ;
  100. ; set output mode
  101. ;
  102. SETOUT:
  103.     LDA    FLAG        ; Get current state
  104.     OUT    DATA        ; Preset data register
  105.     MVI    A,MODE3        ; Set bit control mode
  106.     OUT    CMD
  107.     XRA    A        ; Set all outputs mask
  108.     OUT    CMD
  109.     LDA    FLAG
  110.     OUT    DATA
  111.     RET
  112. ;
  113. ; set input mode
  114. ;
  115. SETIN:
  116.     LDA    FLAG        ; Get current state
  117.     ORI    RD        ; Set read line
  118.     OUT    DATA
  119.     MVI    A,MODE3
  120.     OUT    CMD
  121.     MVI    A,0FH        ; D7-d4 are still output, mask em'
  122.     OUT    CMD
  123.     LDA    FLAG
  124.     ORI    RD
  125.     OUT    DATA
  126.     XCHG ! XCHG        ; Delay for 6 uS min.
  127.     RET
  128. ;
  129. ; send data in A to address in C
  130. ;
  131. WRPIO:
  132.     MOV    B,A        ; Save data in B
  133.     CALL    WRADDR        ; Set address
  134.     MOV    A,B        ; Fall into write data
  135. ;
  136. ; write data in A
  137. ;
  138. WRDATA:
  139.     MOV    C,A        ; Save in C
  140.     LDA    FLAG        ; Get current flag
  141.     ORA    C        ; Or in data
  142.     OUT    DATA
  143.     ORI    WR        ; And write it
  144.     OUT    DATA
  145.     NOP            ; Delay for 1 uS min
  146.     NOP
  147.     ANI    (NOT WR) AND 0FFH ; Reset write
  148.     OUT    DATA
  149.     RET
  150. ;
  151. ; read data into A from address in C
  152. ;
  153. RDPIO:
  154.     PUSH    B
  155.     CALL    WRADDR        ; Set address
  156. ;
  157. ; fall into read data
  158. ;
  159. ; read data into A
  160. ;
  161. RDDATA:
  162.     CALL    SETIN        ; Set input mode
  163.     IN    DATA        ; Input data
  164.     ANI    0FH        ; Just in case
  165.     MOV    C,A        ; Save in C
  166.     CALL    SETOUT        ; Set to output mode
  167.     MOV    A,C        ; Get saved data
  168.     POP    B        ; Restore BC
  169.     RET
  170. ;
  171. ; latch address in C
  172. ;
  173. WRADDR:
  174.     LDA    FLAG        ; Get current flag
  175.     ORA    C        ; Or in address
  176.     OUT    DATA        ; Send address
  177.     ORI    LATCH        ; Set latch
  178.     OUT    DATA        ; And latch it
  179.     ANI    (NOT LATCH) AND    0FFH
  180.     OUT    DATA
  181.     RET
  182. ;
  183. HOLDON:
  184.     MVI    A,HOLD        ; Set hold flag
  185.     STA    FLAG
  186.     CALL    WRDATA
  187. HOLD0:
  188.     MVI    B,20        ; Wait 150 uS
  189. HOLD1:
  190.     XCHG ! XCHG
  191.     DCR    B
  192.     JNZ    HOLD1
  193.     RET
  194. ;
  195. HOLDOFF:
  196.     XRA    A        ; Reset hold flag
  197.     STA    FLAG
  198.     JMP    WRDATA
  199. ;
  200. FLAG:    DB    0        ; Current hold/nohold status flag
  201. ;
  202. ;**********************************************************************
  203. ;
  204. ; This is the end of the TIME insert for BYE500 and up. If you
  205. ; replace the existing TIME insert with this, and have a Kaypro 2 equipped
  206. ; with a Pro-Clock, it SHOULD work fine...
  207. ;
  208. ;**********************************************************************
  209. ;
  210.