home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / bye3 / b3c-leg2.ins < prev    next >
Text File  |  1994-07-13  |  4KB  |  147 lines

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