home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / bye5 / b5-clock.lbr / B5C-MORE.IQS / B5C-MORE.INS
Encoding:
Text File  |  1986-03-09  |  7.8 KB  |  249 lines

  1. ;
  2. ; B5C-MORE.INS        Wayne Masters
  3. ; 02/09/86        Potpourri, 408-378-7474
  4. ;
  5. ; BYE5 insert for MORE-CLOCK running on CP/M-2 or CP/M-3 systems
  6. ;
  7. ; To install this insert you must set the following equates in BYE5:
  8. ;    CLOCK    EQU    YES
  9. ;    TIMEON    EQU    YES
  10. ;    BCDBIN    EQU    YES
  11. ;    BINBCD    EQU    NO
  12. ;
  13. ; You must set the PIAPORT equate below to match your system
  14. ;
  15. ; You should use your clock initialization utility to set the date/time
  16. ; prior to executing BYE.  Make sure you initialize the clock as a 24
  17. ; hour clock if you want it to work correctly with BYE5.
  18. ;
  19. ; Locate the area near the beginning of BYE5 +++ Install your clock insert+++
  20. ; and remove the existing code inside the equates.  Replace it with this
  21. ; insert.
  22. ;
  23. ;************************************************************************
  24. ;*        MM58321 port library & 8255 PIA ports            *
  25. ;*                  for                    *
  26. ;*          MORE-CLOCK  ver 2.1     with version 2 PC board        *
  27. ;************************************************************************
  28. ;
  29. ; Port addresses and register assignments in the clock system.
  30. ;       clock chip used : MM58321 OKI
  31. ;       PIA chip used   : D8255AC-5 NEC
  32. ;
  33. ; This is the port addresses and equates for the MORE-CLOCK using version 2
  34. ; PC board ( with wire jumper to select the page lines ).
  35. ; The primary difference in the software are the 4 control lines -
  36. ;  stop, read, write, and address write. If the page number is changed,
  37. ;  the only thing that will have to be altered in the software is the
  38. ;  PIAPORT equate, which can have values of 00h, 10h, 20h, and 30h.
  39. ;
  40. ;
  41. CENTURY    EQU    19H        ; Change this in year 2000 to 20
  42. PIAPORT    EQU    00H        ; Hardware port for the PIA
  43.                 ; ( jumpered on pc board )
  44. CDAPORT    EQU    PIAPORT+2    ; Location of clock data port ( in PIA )
  45. CTLPORT    EQU    PIAPORT+3    ; Location of PIA control port
  46.  
  47.                 ; PIA configuration words:
  48. WMODE    EQU    10000000B    ; PC 0-3 being outputs ( clock writes )
  49. RMODE    EQU    10000001B    ; PC 0-3 being inputs ( clock reads )
  50.                 ; ( PC 4-7 are always outputs )
  51. ;
  52.                 ; PC 4-7 are the control bits for the clock
  53. CSBIT    EQU    10000000B    ; Clock chip stop bit
  54. CABIT    EQU    01000000B    ; Clock chip register address bit
  55. CRBIT    EQU    00100000B    ; Clock chip read bit
  56. CWBIT    EQU    00010000B    ; Clock chip write bit
  57. ;
  58. ;----------------------------------
  59. ;  CLOCK CHIP DATA REGISTERS
  60. ;----------------------------------
  61. ;
  62. USEC    EQU    00H        ; Units of seconds
  63. TSEC    EQU    01H        ; Tens of seconds
  64. ;
  65. UMIN    EQU    02H        ; Units of minutes
  66. TMIN    EQU    03H        ; Tens of minutes
  67. ;
  68. UHOU    EQU    04H        ; Units of hours
  69. THOU    EQU    05H        ; Tens of hours
  70. MO12    EQU    00000000B    ; 12 hour mode ( D3 clear )
  71. MO24    EQU    00001000B    ; 24 hour mode ( D3 set )
  72. AMTM    EQU    00000000B    ; AM time ( D2 clear )
  73. PMTM    EQU    00000100B    ; PM time ( D2 set )
  74. ;
  75. DOWK    EQU    06H        ; Day of the week
  76. UDAY    EQU    07H        ; Units of days
  77. TDAY    EQU    08H        ; Tens of days
  78. LPYR    EQU    00000000B    ; D2 and D3 select the leap year operation
  79. ;
  80. UMON    EQU    09H        ; Units of months
  81. TMON    EQU    0AH        ; Tens of months
  82. ;
  83. UYEA    EQU    0BH        ; Units of years
  84. TYEA    EQU    0CH        ; Tens of years
  85. ;
  86. ; Machine code interface to get the time and date information from the
  87. ;  MORE-CLOCK and store it for BYE5.
  88. ;
  89. TIME:    DI            ; Disable the interrupts while we do this
  90.     MVI    A,CENTURY
  91.     STA    RTCBUF+3    ; Store century
  92.     MVI    H,TMON        ; Load the tens month register number
  93.     CALL    CLKRD        ; Get the clock data
  94.     STA    BCDMSB        ; Save MSB
  95.     MVI    H,UMON        ; Load the units month register number
  96.     CALL    CLKRD        ; Get the clock data
  97.     STA    BCDLSB        ; Save LSB
  98.     CALL    PACKBCD        ; Make it packed bcd
  99.     STA    RTCBUF+5    ; Store month
  100. ;
  101.     MVI    H,TDAY        ; Load in the tens day register number
  102.     CALL    CLKRD        ; Get the clock data
  103.     STA    BCDMSB
  104.     MVI    H,UDAY        ; Load in the units day register number
  105.     CALL    CLKRD        ; Get the clock data
  106.     STA    BCDLSB
  107.     CALL    PACKBCD
  108.     STA    RTCBUF+6    ; Store day
  109. ;
  110.     MVI    H,TYEA        ; Load in the tens year number
  111.     CALL    CLKRD        ; Get the clock data
  112.     STA    BCDMSB
  113.     MVI    H,UYEA        ; Load in the units of years number
  114.     CALL    CLKRD        ; Get the clock data
  115.     STA    BCDLSB
  116.     CALL    PACKBCD
  117.     STA    RTCBUF+4    ; Store year
  118. ;
  119.     MVI    H,THOU        ; Load in the tens hour
  120.     CALL    CLKRD        ; Get the clock data
  121.     ANI    00000011B    ; Strip off the 24 mode and AM PM bits
  122.     STA    BCDMSB
  123.     MVI    H,UHOU        ; Load in the units of hours reg. number
  124.     CALL    CLKRD        ; Get the clock data
  125.     STA    BCDLSB
  126.     CALL    PACKBCD
  127.     STA    RTCBUF        ; Store hour
  128.     CALL    BCDBIN
  129.     STA    CCHOUR        ; For BYE
  130. ;
  131.     MVI    H,TMIN        ; Load in the tens of minutes reg.
  132.     CALL    CLKRD        ; Get the clock data
  133.     STA    BCDMSB
  134.     MVI    H,UMIN        ; Load in the units of minutes
  135.     CALL    CLKRD        ; Get the clock data
  136.     STA    BCDLSB
  137.     CALL    PACKBCD
  138.     STA    RTCBUF+1    ; Store minutes
  139.     CALL    BCDBIN        ; Convert to binary
  140.     STA    CCMIN        ; For BYE
  141. ;
  142.     MVI    H,TSEC        ; Load in the tens of seconds reg.
  143.     CALL    CLKRD        ; Get the clock data
  144.     STA    BCDMSB
  145.     MVI    H,USEC        ; Load in the units of seconds number
  146.     CALL    CLKRD        ; Get the clock data
  147.     STA    BCDLSB
  148.     CALL    PACKBCD
  149.     STA    RTCBUF+2    ; Store seconds
  150. ;
  151.     EI            ; Enable the interrupts again
  152.     RET
  153. ;
  154. ;*********************************************************************
  155. ;
  156. ; Modified to automatically handle the 24 hour mode flag in the tens
  157. ;   of hours register.
  158. ;
  159. ;    CLKRD - reads a referenced clock register
  160. ;
  161. ; Entrance parameters :
  162. ;    register address in H, data will be returned in A
  163. ;
  164. ;----------------------------------------------------------------------
  165. ;
  166. ; The trick to getting to the clock chip is the D8255 PIA which will be
  167. ; necessary to program for a read and a write operation. The PIA was
  168. ; used for two reasons, the speed of most clock chips are not sufficient
  169. ; for use directly attached to a computer's buss and the polarity of the
  170. ; control lines were wrong. The C port of the PIA is attached to the
  171. ; clock chip, 4 lines as the data buss and 4 lines as control. The PIA's
  172. ; C port can be configured as two 4 bit ports which is the situation
  173. ; here. Only the two modes are used to 'talk' to the clock, RMODE and
  174. ; WMODE.
  175. ;
  176. ;
  177. ; The port numbers that must be passed are:
  178. ;        0    units of seconds
  179. ;        1    tens of seconds
  180. ;        2    units of minutes
  181. ;        3    tens of minutes
  182. ;        4    units of hours
  183. ;        5    tens of hours
  184. ;        6    day of week
  185. ;        7    units of days
  186. ;        8    tens of days
  187. ;        9    units of months
  188. ;        10    tens of months
  189. ;        11    units of years
  190. ;        12    tens of years
  191. ;
  192. ; Special bits used :
  193. ;        5    tens of hours    D3 used to indicate 24 hour mode
  194. ;                    D2 indicates PM if 12 hour mode
  195. ;        8    tens of days    D3 & D2 used to indicate leap year
  196. ;
  197. ;--------------------------------------------------------------------
  198. ;
  199. CLKRD:                ; Read a clock register
  200.     MVI    A,WMODE        ; Control word for PIA write
  201.     OUT    CTLPORT        ; Set the control lines to the clock
  202. ;
  203.     MVI    A,CABIT        ; Get the clock register address bit
  204.     ORA    H        ; Add in the register address
  205.     ORI    CSBIT        ; Stop line of the clock must be high
  206.     OUT    CDAPORT        ; Output the data
  207. ;
  208.     MVI    A,RMODE        ; PIA control word for chip read
  209.     OUT    CTLPORT        ; Output the data
  210. ;
  211.     MVI    A,CRBIT        ; Set the read bit
  212.     ORI    CSBIT        ; Set the stop bit
  213.     OUT    CDAPORT        ; Init. the clock chip for a read
  214.     NOP            ; Delay for the clock chip to stabilize
  215.     NOP
  216.     NOP
  217.     NOP
  218.     NOP
  219.     IN    CDAPORT        ; The clock data will now be on the low nib
  220.     MOV    B,A        ; Temp. store data
  221.     XRA    A        ; Reset all of the control lines to
  222.     OUT    CDAPORT        ; The clock chip
  223.     MVI    A,THOU        ; Get the real tens register address
  224.     CMP    H        ; See if this is it
  225.     MOV    A,B        ; Get the data back
  226.     JNZ    CX1        ; If not tens reg. then jump around
  227.     ANI    00000011B    ; Make sure only the low two bits are sent
  228. CX1:    ANI    0FH        ; Mask of the high nibble
  229.     RET
  230. ;
  231. ;----------------------------------------------------------------------------
  232. ;
  233. ; BCDMSB= Most significent byte, BCDLSB= Least signficent byte
  234. ;
  235. PACKBCD:LDA    BCDLSB
  236.     ANI    0FH
  237.     MOV    B,A        ; Save lsb in B
  238.     LDA    BCDMSB
  239.     ANI    0FH
  240.     RLC!RLC!RLC!RLC        ; Shift it to high nibble
  241.     ORA    B        ; Combine with lsb
  242.     RET
  243. ;
  244. BCDMSB:    DB    0
  245. BCDLSB:    DB    0
  246. ;
  247. ;  That's the end of B5C-MORE.INS
  248. ;
  249.