home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / CLOCK.AZM / CLOCK.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  5.1 KB  |  195 lines

  1. ;----------------------------------------------------------------
  2. ;        This is a module in the ASMLIB library            *
  3. ;                                *
  4. ; This module is used to read and write to the sbc-800  clock.  *
  5. ;                                *
  6. ; The two entry points of this module are called indetically    *
  7. ; by passing a pointer to the required data areas to be read    *
  8. ; into or written to the clock from.                 *
  9. ;                                *
  10. ; The read function reads the time into m-->DE while the write  *
  11. ; function wrtites m-->DE into the clock chip.            *
  12. ;                                *
  13. ;        Written        R.C.H.    14/8/82            *
  14. ;        Last Update    R.C.H.    19/9/83            *
  15. ;
  16. ; Added new clock read software for holding for 150us.    R.C.H.  21/9/83
  17. ;****************************************************************
  18. ;
  19.     name    'clock'
  20. ;
  21.     public    clkrd,clkwr
  22.     maclib    z80
  23. ;
  24. ; The following equates specify the port addresses of the real time clock
  25. ; chip and interface. The clock chip is an OKI 5832 and the interface 
  26. ; is an intel 8255.
  27. ;
  28. ;    Clock and centronics ports on the sbc-800
  29. ;
  30. pp0a    equ    84h            ; Port a 0
  31. pp0b    equ    pp0a+1            ; Port b 0
  32. pp0c    equ    pp0a+2            ; Port c 0
  33. pp0d    equ    pp0a+3            ; Control port 0
  34. ;
  35. ;    I/O lines and part of clock strobe
  36. ;
  37. pp1a    equ    80h            ; Port a 1
  38. pp1b    equ    pp1a+1            ; Port b 1
  39. pp1c    equ    pp1a+2            ; Port c 1
  40. pp1d    equ    pp1a+3            ; Control port 1
  41. ;
  42. ;****************************************************************
  43. ;*        Read Real Time Clock to memory            *
  44. ;*        pointed by DE, and stored as follows        *
  45. ;*                                *
  46. ;*    hl+0 =>    years    1 byte 2 digit bcd            *
  47. ;*      +1 => months  1 byte 2 digit bcd            *
  48. ;*      +2 => days    1 byte 2 digit bcd            *
  49. ;*      +3 => dweek    1 byte 1 digit bcd ** low nibble only ***
  50. ;*      +4 => hours   1 byte 2 digit bcd            *
  51. ;*      +5 => minutes 1 byte 2 digit bcd            *
  52. ;*      +6 => seconds 1 byte 2 digit bcd            *
  53. ;*                                *
  54. ;****************************************************************
  55. ;
  56. clkrd:    ; Read clock into memory at DE or to screen
  57.     push    psw
  58.     push    h            ; Save users register
  59.     push    b
  60.     xchg                ; Load address into HL
  61. ;
  62. ; Here try to hold the clock chip for 150 us. 
  63.     mvi    a,00001101b        ; Hld bit
  64.     out    pp0d            ; Set bit
  65. ; Now load a counter for a 150 us delay.
  66.     mvi    b,120            ; 7 T
  67. ;
  68. hld$wait:
  69.     djnz    hld$wait        ; 8/10 T
  70. ;
  71.     out    pp1d            ; this is the read bit load
  72. ; Loop to read all registers in one go
  73.     mvi    b,12            ; register count
  74. rclk1:
  75.     call    get$reg
  76.     mov    a,b
  77.     cpi    6            ; Was it day of week
  78.     jrz    rclk2            ; Skip second register if so
  79.     dcr    b            ; Next register
  80.     call    get$reg            ; read the register
  81. rclk2:    ; Jump here after reading day of week
  82.     inx    h            ; next byte in ram to rotate into
  83.     dcr    b            ; register number
  84.     xra    a
  85.     ora    b            ; set the minus flag
  86.     jp    rclk1
  87. ; restore the port bits
  88.            mvi    a,00001100b        ; Reset bit 6
  89.     out    pp0d
  90.     out    pp1d               ; Clear hold+read
  91.     pop    b
  92.           pop    h            ; Restore last location
  93.     pop    psw
  94.     ret
  95. ;
  96. get$reg:    ; Read register in B into memory with an RLD
  97.     mov    a,b
  98.     out    pp0b
  99.     mvi    a,8
  100. rdreg1:    ; This loop is needed for a 6 us delay for reading the register
  101.     dcr    a
  102.     jrnz    rdreg1            ; another wait of 15 us or better
  103.     in    pp0a
  104.     ani    15            ; Get data
  105.     rld                ; Saved in memory
  106.     ret
  107. ;
  108. ;****************************************************************
  109. ;*        Write to Clock, takes a bcd string        *
  110. ;*    pointed to by the DE registers, and updates the clock    *
  111. ;*                                *
  112. ;*    Format of string is :=                    *
  113. ;*                                *
  114. ;*    hl+0    =>    1 byte 2 bcd digits year        *
  115. ;*      +1    =>    1 byte 2 bcd digits month        *
  116. ;*      +2    => *    1 byte 2 bcd digits date        *
  117. ;*      +3    =>    1 byte 1 bcd digit weekday (low nibble) *
  118. ;*      +4    => **   1 byte 2 bcd digits hours        *
  119. ;*      +5    =>    1 byte 2 bcd digits minutes        *
  120. ;*      +6    =>    1 byte 2 bcd digits seconds        *
  121. ;*                                *
  122. ;*    * note1 = bit 6 = 1 for 29 days in month 2        *
  123. ;*              0 for 28 days in month 2        *
  124. ;*                                *
  125. ;*     ** note2 = bit 7 = 1 for 24 hour format            *
  126. ;*              0 for 12 hour format            *
  127. ;*                                *
  128. ;*          bit 6 = 1 for pm                *
  129. ;*              0 for am                *
  130. ;*                                *
  131. ;****************************************************************
  132. ;
  133. clkwr:
  134.     push    psw
  135.     push    h
  136.     push    b
  137. ;
  138.     xchg                ; DE --> time string
  139. ;
  140.     mvi    b,12            ; Register count
  141.     mvi    a,80h            ; Set port 0 for write
  142.     out    pp0d
  143. wrclk0:
  144.     rld                ; Get upper bcd digit by rotation
  145.     ani    15            ; Mask off upper
  146.     out    pp0a              ; Send data
  147.     mov    a,b
  148.     out    pp0b              ; Send address
  149.     mvi    a,00001101b        ; Hold bit
  150.     out    pp0d
  151.     mvi    a,15
  152. wrclk1:
  153.     dcr    a
  154.     jrnz    wrclk1            ; Hold setup time
  155.     call    wrstrb            ; Strobe write line
  156.     mov    a,b
  157.     cpi    6
  158.     jrz    wrclk2
  159.     dcr    b
  160.     rld                ; Lower digit
  161.     out    pp0a              ; Send data
  162.     mov    a,b
  163.     out    pp0b              ; Send reg address
  164.     call    wrstrb            ; Strobe write pulse
  165. wrclk2:
  166.     inx    h
  167.     mov    a,b
  168.     ora    a            ; Test for zero already
  169.     jrnz    wrclk3            ; Skip if not endstrobes
  170. ; Re-initialize the clock ports then.
  171.     push    psw
  172.     mvi    a,10110100b        ; Centronics port init
  173.     out    pp0d            ; Set up command
  174.     mvi    a,5
  175.     out    pp0d            ; Set pc2 for strobe acknowledge
  176.     pop    psw
  177. ;
  178. wrclk3:
  179.     dcr    b
  180.     jr    wrclk0            ; B=count-1, loop till zero
  181. ;
  182. wrstrb:
  183.     mvi    a,00001111b        ; Send write pulse now
  184.     out    pp1d              ; Send write
  185.     dcr    a
  186.     out    pp1d              ; Clear write strobe
  187.     pop    b
  188.     pop    h
  189.     pop    psw
  190.     ret
  191. ;
  192.     end
  193.  
  194.  
  195.