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

  1. ;
  2. ; B3C-DD.INS - Clock routine for the Digital Dynamics card 08/22/85
  3. ;                        -- by pst
  4. ;    This insert should read the clock from a Digital Dynamics
  5. ;    SpeedPro5 clock card.  The SpeedPro5 uses a 5832 chip.
  6. ;
  7. ;    This clock routine needs:
  8. ;        BCD2BIN    - no
  9. ;        BIN2BCD - no
  10. ;
  11. ;    This routine NEEDS a Z80 processor to function properly.
  12. ;    It will NOT work with an 8080 or 8085.
  13. ;
  14. ;----------------------------------------------------------------
  15. ;
  16. ;    Note- This is an insert--not an overlay
  17. ;
  18.      IF    RTC
  19. DDBASE    EQU    156        ; Base port of PIO
  20. ADATA    EQU    DDBASE        ; Data port A
  21. ACTRL    EQU    DDBASE+1    ; Control port A
  22. BDATA    EQU    DDBASE+2    ; Data port B
  23. BCTRL    EQU    DDBASE+3    ; Control port B
  24. ;
  25. NCS    EQU    00000001B    ; Not chip select
  26. CLKRD    EQU    00000010B    ; Clock read
  27. CLKWR    EQU    00000100B    ; Clock write
  28. ADWWR    EQU    00001000B    ; Address write
  29. CLKHD    EQU    00010000B    ; Clock hold
  30. ;
  31. TIME:    LXI    B,ACTRL        ; Output mode - port A (reg B=0, C=port)
  32.     CALL    SETMODE
  33. ;
  34.     LXI    B,BCTRL        ; Output mode - port B (reg B=0, C=port)
  35.     CALL    SETMODE
  36. ;
  37.     XRA    A
  38.     OUT    ADATA        ; Zero address/data lines
  39.     MVI    A,NCS+CLKHD
  40.     OUT    BDATA        ; Deselect chip
  41. ;
  42.     LXI    H,RTCBUF    ; Point to RTC buffer
  43.     MVI    D,5        ; Set counter for hour tens
  44.     CALL    RDIGIT        ; Get hour tens
  45.     CALL    SHFT4        ; Save in buffer
  46.     CALL    MULT10        ; Multiply by 10
  47.     STA    CCHOUR        ; Save temporarily
  48.     CALL    RDIGIT        ; Get hour units in A reg
  49.     CALL    ADDLOW        ; Set BCD digit
  50.     MOV    B,A
  51.     LDA    CCHOUR
  52.     ADD    B        ; Add ones digit from B
  53.     STA    CCHOUR        ; Store for later use
  54. ;
  55. ;    Minutes
  56. ;
  57.     CALL    RDIGIT        ; Get minute tens in A reg
  58.     CALL    SHFT4        ; Save in buffer
  59.     CALL    MULT10        ; Multiply by 10
  60.     STA    CCMIN        ; Save in CCMIN
  61.     CALL    RDIGIT        ; Get minute units in A reg
  62.     CALL    ADDLOW        ; Set BCD digit
  63.     MOV    B,A
  64.     LDA    CCMIN
  65.     ADD    B        ; Add in minutes ones from B
  66.     STA    CCMIN        ; Store for later use
  67. ;
  68. ;    Seconds
  69. ;
  70.     CALL    RDIGIT        ; Second tens
  71.     CALL    SHFT4
  72.     CALL    RDIGIT        ; Second units
  73.     CALL    ADDLOW
  74. ;
  75. ;    Year
  76. ;
  77.     INX    H        ; Skip over "19"
  78.     MVI    D,12        ; Start with years tens
  79.     CALL    RDIGIT
  80.     CALL    SHFT4
  81.     CALL    RDIGIT        ; Years units
  82.     CALL    ADDLOW
  83. ;
  84.     CALL    RDIGIT        ; Month tens
  85.     CALL    SHFT4
  86.     CALL    RDIGIT        ; Month units
  87.     CALL    ADDLOW
  88. ;
  89.     CALL    RDIGIT        ; Day tens
  90.     CALL    SHFT4
  91.     CALL    RDIGIT        ; Day units
  92.     CALL    ADDLOW
  93. ;
  94.     MVI    A,0        ; Turn off hold
  95.     OUT    BDATA
  96.     MVI    A,NCS        ; Deselect chip
  97.     OUT    BDATA
  98.     RET
  99. ;
  100. ;    Read a digit
  101. ;        Command in D
  102. ;        Digit returned in A
  103. ;        D is decremented
  104. ;        Hold bit is set
  105. ;        Destroys: 'BCE'
  106. ;
  107. RDIGIT:    LXI    B,ACTRL        ; Output mode - port A (b=0, c=port)
  108.     CALL    SETMODE
  109. ;
  110.     MOV    A,D        ; Get command byte
  111.     OUT    ADATA        ; Set address on lines
  112.     MVI    A,CLKHD+ADWWR    ; Hold & Write
  113.     OUT    BDATA
  114.     MVI    A,CLKHD        ; Hold
  115.     OUT    BDATA
  116. ;
  117.     LXI    B,0FF00H+ACTRL    ; Input mode - port A (b=255, c=port)
  118.     CALL    SETMODE
  119. ;
  120.     MVI    A,CLKHD+CLKRD    ; Hold & Read
  121.     OUT    BDATA
  122. ;
  123.     MOV    A,D        ; Check for hour tens digit
  124.     DCR    D
  125.     CPI    5        ; Was it hour tens digit?
  126. ;
  127.     IN    ADATA        ; Read the digit
  128.     PUSH    PSW
  129.     MVI    A,CLKHD        ; Set hold mode
  130.     OUT    BDATA
  131.     POP    PSW
  132.     RNZ            ; No, return
  133.     ANI    3        ; Yes, so kill 24 hour bit
  134.     RET
  135. ;
  136. ;    Set for input or output mode of port A
  137. ;    Entry: mode in B -- 255=output, 0=input
  138. ;           port to send to in C
  139. ;
  140. SETMODE:MVI    A,207        ; Mode 3, bit I/O
  141.     DB    0EDh,079h    ; Z80 instruction = OUT (C),A
  142.     DB    0EDh,041h    ; Z80 instruction = OUT (C),B
  143.     MVI    A,7        ; Interrupt control
  144.     DB    0EDh,079h    ; Z80 instruction = OUT (C),A
  145.     MVI    A,3
  146.     DB    0EDh,079h    ; Z80 instruction = OUT (C),A
  147.     RET
  148. ;
  149. ;    Multiply register A by 10
  150. ;    Destroys 'E'
  151. ;
  152. MULT10:    ADD    A        ; 2x
  153.     MOV    E,A
  154.     ADD    A        ; 4x
  155.     ADD    A        ; 8x
  156.     ADD    D        ; 10x
  157.     RET
  158. ;
  159. ;    Shift A to high nibble
  160. ;        Stores shifted value in 'M'
  161. ;        Destroys 'E'
  162. ;        A is left unchanged
  163. ;
  164. SHFT4:    MOV    E,A
  165.     ANI    15        ; Only handle lower 4 bits
  166.     RLC            ; Shift A over 4 bits
  167.     RLC
  168.     RLC
  169.     RLC            
  170.     MOV    M,A        ; Save it while we're at it
  171.     MOV    A,E
  172.     RET
  173. ;
  174. ;    Add in low BCD nibble
  175. ;        Gets high nibble from M
  176. ;        Stores new BCD byte in M
  177. ;        Increments HL
  178. ;        Destroyes 'E'
  179. ;
  180. ADDLOW:    MOV    E,A
  181.     ANI    15        ; Deal with low nibble only
  182.     ORA    M        ; Add in high nibble from tens digit
  183.     MOV    M,A        ; Save new BCD byte in buffer
  184.     INX    H        ; Move on to next location
  185.     MOV    A,E
  186.     RET
  187.      ENDIF            ; RTC
  188.