home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BBSING / MBBS / MBC-KPRO.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  5KB  |  204 lines

  1. ;
  2. ;**********************************************************************
  3. ;
  4. ; MBC-KPRO.ASM -- Version 1.0 -- 03/01/84 -- by Kim Levitt
  5. ;
  6. ;    CLOCK routine for MBYE running on Kaypro 2 with Pro-Clock
  7. ;    (adapted from Kaypro Pro-Clock driver written by Greg Haerr)
  8. ;
  9. ;    This overlay is designed to work on a Kaypro II running MBYE
  10. ;    and equipped with a Business Computer Systems Pro-Clock RTC.
  11. ;    (Use the DATE program to initialize the clock outside of BYE.)
  12. ;    (BCS address: 5350 South 3600 West; Salt Lake City, UT 84118)
  13. ;
  14. ;    When called this routine will check the RTCBUF. If a '99H'
  15. ;    is in the first byte, the clock is initialized. Next the
  16. ;    seconds are checked, and if changed since last update of
  17. ;    RTC buffer, the clock is stopped, data copied to RTCBUF and
  18. ;    the clock is restarted. (If no change in seconds, the
  19. ;    routine returns immediately.)
  20. ;
  21. ;**********************************************************************
  22. ;
  23. CLOCK:
  24.     PUSH    PSW        ; save ALL regs that are used
  25.     PUSH    B
  26.     PUSH    H
  27.     LDA    RTCBUF        ; get first BCD byte
  28.     CPI    099H        ; 99 ?
  29.     CZ    CLKINIT        ; if so, init clock...
  30.     CALL    HOLDON        ; put clock on hold
  31.     MVI    C,0        ; check low seconds
  32.     CALL    RDPIO        ; to see if change...
  33.     LXI    H,RTCBUF+2    ; compared to old secs
  34.     XRA    M        ; value stored in
  35.     ANI    0FH        ; RTC buffer (low nibble)
  36.     JZ    CLKEXIT        ; if no change, skip update
  37.     MVI    C,5        ; start with hi hours
  38.     LXI    H,RTCBUF    ; and copy to RTCBUF
  39.     CALL    GETCLK        ; (get time)
  40.     MVI    C,12        ; start with hi year
  41.     LXI    H,RTCBUF+4    ; and copy to RTCBUF
  42.     CALL    GETCLK        ; (and date)
  43.     LDA    RTCBUF        ; get hours
  44.     ANI    03FH        ; mask out PM/24 hour bits
  45.     STA    RTCBUF
  46.     LDA    RTCBUF+6    ; get day
  47.     ANI    03FH        ; mask out leap year bit
  48.      STA    RTCBUF+6
  49. CLKEXIT:
  50.     MVI    C,13        ; set clock addr. to
  51.     CALL    WRADDR        ; junk location so no data cleared
  52.     CALL    HOLDOFF        ; when we take clock off hold..
  53.     POP    H        ; restore ALL regs
  54.     POP    B
  55.     POP    PSW
  56.     RET            ; and return (for now..)
  57. ;
  58. GETCLK:
  59.     MVI    B,3        ; repeat 3 times for 3 BCD bytes
  60. CLKLP:
  61.     CALL    RDPIO        ; get data at address C
  62.     RLC ! RLC ! RLC ! RLC    ; move to high nibble for BCD
  63.     MOV    M,A        ; save at location temporarily
  64.     DCR    C        ; decrement clock addr
  65.     CALL    RDPIO        ; get data at next address
  66.     ORA    M        ; OR with previously saved data
  67.     MOV    M,A        ; and save it
  68.     DCR    C        ; decrement clock addr
  69.     INX    H        ; increment to next BCD byte
  70.     DCR    B        ; decrement BCD counter
  71.     JNZ    CLKLP        ; if 3rd BCD byte, done..
  72.     RET            ; return
  73. ;
  74. ; PIO STUFF
  75. ;
  76. MODE3    EQU    0CFH    ; bit control mode
  77. ;
  78. DATA    EQU    0AH    ; port B data
  79. CMD    EQU    0BH    ; port B cmd
  80. ;
  81. ; mask values for clock chip
  82. ;
  83. LATCH    EQU    80H    ; set address latch (active high)
  84. WR    EQU    40H    ; write (active high)
  85. RD    EQU    20H    ; read (active high)
  86. HOLD    EQU    10H    ; time hold (active high)
  87. ;
  88. CLKINIT:
  89.     MVI    A,7        ; disable interrupts
  90.     OUT    CMD
  91. ;
  92. ; fall into set output 
  93. ;
  94. ; set output mode
  95. ;
  96. SETOUT:
  97.     LDA    FLAG        ; get current state
  98.     OUT    DATA        ; preset data register
  99.     MVI    A,MODE3        ; set bit control mode
  100.     OUT    CMD
  101.     XRA    A        ; set all outputs mask
  102.     OUT    CMD
  103.     LDA    FLAG
  104.     OUT    DATA
  105.     RET
  106. ;
  107. ; set input mode
  108. ;
  109. SETIN:
  110.     LDA    FLAG        ; get current state
  111.     ORI    RD        ; set read line
  112.     OUT    DATA
  113.     MVI    A,MODE3
  114.     OUT    CMD
  115.     MVI    A,0FH        ; d7-d4 are still output, mask em'
  116.     OUT    CMD
  117.     LDA    FLAG
  118.     ORI    RD
  119.     OUT    DATA
  120.     XCHG ! XCHG        ; delay for 6 uS min.
  121.     RET
  122. ;
  123. ; send data in A to address in C
  124. ;
  125. WRPIO:
  126.     MOV    B,A        ; save data in B
  127.     CALL    WRADDR        ; set address
  128.     MOV    A,B        ; fall into write data
  129. ;
  130. ; write data in A
  131. ;
  132. WRDATA:
  133.     MOV    C,A        ; save in C
  134.     LDA    FLAG        ; get current flag
  135.     ORA    C        ; or in data
  136.     OUT    DATA
  137.     ORI    WR        ; and write it
  138.     OUT    DATA
  139.     NOP            ; delay for 1 uS min
  140.     NOP
  141.     ANI    (NOT WR) AND 0FFH    ; reset write
  142.     OUT    DATA
  143.     RET
  144. ;
  145. ; read data into A from address in C
  146. ;
  147. RDPIO:
  148.     PUSH    B
  149.     CALL    WRADDR        ; set address
  150. ;
  151. ; fall into read data
  152. ;
  153. ; read data into A
  154. ;
  155. RDDATA:
  156.     CALL    SETIN        ; set input mode
  157.     IN    DATA        ; input data
  158.     ANI    0FH        ; just in case
  159.     MOV    C,A        ; save in C
  160.     CALL    SETOUT        ; set to output mode
  161.     MOV    A,C        ; get saved data
  162.     POP    B        ; restore BC
  163.     RET
  164. ;
  165. ; latch address in C
  166. ;
  167. WRADDR:
  168.     LDA    FLAG        ; get current flag
  169.     ORA    C        ; or in address
  170.     OUT    DATA        ; send address
  171.     ORI    LATCH        ; set latch
  172.     OUT    DATA        ; and latch it
  173.     ANI    (NOT LATCH) AND 0FFH
  174.     OUT    DATA
  175.     RET
  176. ;
  177. HOLDON:
  178.     MVI    A,HOLD        ; set hold flag
  179.     STA    FLAG
  180.     CALL    WRDATA
  181. HOLD0:
  182.     MVI    B,20        ; wait 150 uS
  183. HOLD1:
  184.     XCHG ! XCHG
  185.     DCR    B
  186.     JNZ    HOLD1
  187.     RET
  188. ;
  189. HOLDOFF:
  190.     XRA    A        ; reset hold flag
  191.     STA    FLAG
  192.     JMP    WRDATA
  193. ;
  194. FLAG:    DB    0        ; current hold/nohold status flag
  195. ;
  196. ;**********************************************************************
  197. ;
  198. ; This is the end of the CLOCK routine overlay for MBYE-31. If you
  199. ; include this after your modem overlay, and have a Kaypro 2 equipped
  200. ; with a Pro-Clock, it SHOULD work fine...
  201. ;
  202. ;**********************************************************************
  203. ;
  204.