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

  1. ; B5C-CW.INS - Clock routine for the CompuTime/QT clock card.  07/03/85
  2. ;                        -- by pst
  3. ;
  4. ;  This routine needs:        BCD2BIN = no
  5. ;                BIN2BCD = no
  6. ;
  7. ;----------------------------------------------------------------
  8. ;
  9. ;    Note- This is an insert--not an overlay
  10. ;
  11. CWBASE    EQU    241        ; Base port for board
  12. CLKCMD    EQU    CWBASE        ; Clock command port
  13. CLKDATA    EQU    CWBASE+1    ; Clock data port (same as command)
  14. CLKREAD    EQU    32        ; Read command bit
  15. CLKHOLD    EQU    64        ; Hold command bit
  16. ;
  17. TIME:    LXI    H,RTCBUF    ; Point to RTC buffer
  18.     MVI    C,5        ; Set counter for hour tens
  19.     CALL    RDIGIT        ; Get hour tens
  20.     CALL    SHFT4        ; Save in buffer
  21.     CALL    MULT10        ; Multiply by 10
  22.     MOV    B,A        ; Save in B reg
  23.     CALL    RDIGIT        ; Get hour units in A reg
  24.     CALL    ADDLOW        ; Set BCD digit
  25.     ADD    B        ; Add tens digit from B
  26.     STA    CCHOUR        ; Store for later use
  27. ;
  28. ;    Minutes
  29. ;
  30.     CALL    RDIGIT        ; Get minute tens in A reg
  31.     CALL    SHFT4        ; Save in buffer
  32.     CALL    MULT10        ; Multiply by 10
  33.     MOV    B,A        ; Save in B reg
  34.     CALL    RDIGIT        ; Get minute units in A reg
  35.     CALL    ADDLOW        ; Set BCD digit
  36.     ADD    B        ; Add in minutes tens from B
  37.     STA    CCMIN        ; Store for later use
  38. ;
  39. ;    Seconds
  40. ;
  41.     CALL    RDIGIT        ; Second tens
  42.     CALL    SHFT4
  43.     CALL    RDIGIT        ; Second units
  44.     CALL    ADDLOW
  45. ;
  46. ;    Year
  47. ;
  48.     INX    H        ; Skip over "19"
  49.     MVI    C,12        ; Start with years tens
  50.     CALL    RDIGIT
  51.     CALL    SHFT4
  52.     CALL    RDIGIT        ; Years units
  53.     CALL    ADDLOW
  54. ;
  55.     CALL    RDIGIT        ; Month tens
  56.     CALL    SHFT4
  57.     CALL    RDIGIT        ; Month units
  58.     CALL    ADDLOW
  59. ;
  60.     CALL    RDIGIT        ; Day tens
  61.     CALL    SHFT4
  62.     CALL    RDIGIT        ; Day units
  63.     CALL    ADDLOW
  64. ;
  65.     XRA    A
  66.     OUT    CLKCMD        ; Turn off hold bit
  67.     RET
  68. ;
  69. ;    Read a digit
  70. ;        Command in C
  71. ;        Digit returned in A
  72. ;        C is decremented
  73. ;        Hold bit is set
  74. ;
  75. RDIGIT:    MVI    A,CLKHOLD    ; Set clock hold command
  76.     OUT    CLKCMD
  77.     XRA    A
  78. RDLP1:    XTHL
  79.     XTHL
  80.     DCR    A
  81.     JNZ    RDLP1
  82. ;
  83.     MOV    A,C
  84.     DCR    C
  85.     ORI    CLKREAD
  86.     OUT    CLKDATA        ; Select digit
  87.     MVI    A,20
  88. RDLP2:    XTHL
  89.     XTLH
  90.     DCR    A
  91.     JNZ    RDLP2
  92. ;
  93.     IN    CLKDATA        ; read a digit
  94.     ANI    15        ; Strip off any commands
  95.     PUSH    B
  96.     MOV    B,A        ; Save in B
  97.     MOV    A,C
  98.     CPI    5        ; Was it hour tens digit?
  99.     MOV    A,B        ; Get digit back
  100.     JNZ    NOTENS
  101.     ANI    3        ; Hour tens gets striped more
  102. NOTENS:    POP    B
  103.     RET
  104. ;
  105. ;    Multiply register A by 10
  106. ;    Destroys 'D'
  107. ;
  108. MULT10:    ADD    A        ; 2x
  109.     MOV    D,A
  110.     ADD    A        ; 4x
  111.     ADD    A        ; 8x
  112.     ADD    D        ; 10x
  113.     RET
  114. ;
  115. ;    Shift A to high nibble
  116. ;        Stores shifted value in 'M'
  117. ;        Destroys 'E'
  118. ;        A is left unchanged
  119. ;
  120. SHFT4:    MOV    E,A
  121.     ANI    15        ; Only handle lower 4 bits
  122.     RLC            ; Shift A over 4 bits
  123.     RLC
  124.     RLC
  125.     RLC            
  126.     MOV    M,A        ; Save it while we're at it
  127.     MOV    A,E
  128.     RET
  129. ;
  130. ;    Add in low BCD nibble
  131. ;        Gets high nibble from M
  132. ;        Stores new BCD byte in M
  133. ;        Increments HL
  134. ;        Destroyes 'E'
  135. ;
  136. ADDLOW:    MOV    E,A
  137.     ANI    15        ; Deal with low nibble only
  138.     ORA    M        ; Add in high nibble from tens digit
  139.     MOV    M,A        ; Save new BCD byte in buffer
  140.     INX    H        ; Move on to next location
  141.     MOV    A,E
  142.     RET
  143. ;
  144. ;  Insert this routine in BYE5 between the IF CLOCK OR RSPEED and ENDIF
  145. ;  statements in the area marked +++ Install your clock +++.