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

  1.  
  2. ; B5C-CPM3.INS - Clock routine for CP/M Plus
  3. ;
  4. ; (8/28/85)    Added option to use standard BDOS calls for non-interrupt
  5. ;        driven CP/M Plus systems.  Unless the BIOS uses an
  6. ;        interrupt driven clock, the SCB doesn't get updated.
  7. ;        Also removed surrounding IF CLOCK OR RSPEED.
  8. ;                        -- Paul Bartholomew
  9. ;
  10. ; (8/17/85)    Initial release for BYE501 and above.  This INSert uses
  11. ;        time/date routines originally written by Sigi Kluger.
  12. ;                        -- George Peace
  13. ;----------------------------------------------------------------
  14. ;
  15. ; This clock insert uses BCDBIN and BINBCD subroutines.  It requires that
  16. ; configuration tags BCD2BIN and BIN2BCD as well as CLOCK be set to YES.
  17. ;
  18. ;    Note- This is an insert--not an overlay
  19. ;
  20. CLKINT    EQU    YES        ; YES if SCB time is updated by interrupts
  21.                 ;     as on Osborne Executive (OX)
  22.                 ; NO  if BDOS access required to update SCB
  23.                 ;     as on Morrow hard disk (MH) series
  24. ;
  25. CENTURY    EQU    19H        ; Current century (19xx) in BCD
  26. ;
  27. TIME:     IF    CLKINT
  28.     DI            ; Disable interrupts while checking time (SCB)
  29.     LHLD    SCBBASE        ; Get SCB base address
  30.     MVI    L,SCBTIM    ; Build SCB time field address
  31.     MOV    A,M        ; Get hours (BCD)
  32.      ENDIF            ; CLKINT
  33.  
  34.      IF    NOT CLKINT
  35.     MVI    C,105        ; CP/M Plus Get date/time call
  36.     LXI    D,DTDAT        ; Address of DAT buffer
  37.     DI            ; Disable interrupts while checking time
  38.     CALL    BDOS        ; Get info through BDOS
  39.     EI            ; Re-enable interrupts
  40.     STA    RTCBUF+2    ; Seconds returned in A (BCD)
  41.     LDA    DTHR        ; Get Hour
  42.      ENDIF            ; NOT CLKINT
  43.  
  44.     STA    RTCBUF        ; Store BCD hours in RTCBUF
  45.     CALL    BCDBIN        ; Convert to binary
  46.     STA    CCHOUR        ; And save as current hour
  47.  
  48.      IF    CLKINT
  49.     INX    H        ; Point to minute byte
  50.     MOV    A,M        ; Get minutes (BCD)
  51.      ENDIF            ; CLKINT
  52.  
  53.      IF    NOT CLKINT
  54.     LDA    DTMN        ; Get minutes
  55.      ENDIF            ; NOT CLKINT
  56.  
  57.     STA    RTCBUF+1    ; Store BCD minutes in RTCBUF
  58.     CALL    BCDBIN        ; Convert to binary
  59.     STA    CCMIN        ; And save as current minute
  60.  
  61.      IF    CLKINT
  62.     INX    H        ; Point to seconds byte
  63.     MOV    A,M        ; Get seconds (BCD)
  64.     STA    RTCBUF+2    ; Store BCD seconds in RTCBUF
  65.      ENDIF            ; CLKINT
  66. ;
  67.     MVI    A,CENTURY    ; Get current century
  68.     STA    RTCBUF+3    ; And store in RTC buffer
  69. ;
  70. ; Get the date
  71. ;
  72.      IF    CLKINT
  73.     LHLD    SCBBASE        ; Get SCB base address
  74.     MVI    L,SCBDAT    ; Build SCB date field address
  75.     MOV    E,M
  76.     INX    H
  77.     MOV    D,M
  78.     EI            ; Enable interrupts after SCB access is done
  79.     XCHG            ; Transfer date to HL
  80.      ENDIF            ; CLKINT
  81.  
  82.      IF    NOT CLKINT
  83.     LHLD    DTDAT        ; Date in HL
  84.      ENDIF            ; NOT CLKINT
  85. ;
  86.     MVI    B,78        ; Set years counter
  87. ;
  88. LOOP:    CALL    CKLEAP
  89.     LXI    D,-365        ; Set up for subtract
  90.     JNZ    NOLPY        ; Skip if no leap year
  91.     DCX    D        ; Set for leap year
  92. ;
  93. NOLPY:    DAD    D        ; Subtract
  94.     JNC    YDONE        ; Continue if years done
  95.     MOV    A,H
  96.     ORA    L
  97.     JZ    YDONE
  98.     SHLD    DTDAT        ; Else save days count
  99.     INR    B        ; Increment years count
  100.     JMP    LOOP        ; And do again
  101. ;
  102. ;
  103. ; The years are now finished, the years count is in 'B' and DTDAT holds
  104. ; the days (HL is invalid)
  105. ;
  106. YDONE:    MOV    A,B
  107.     CALL    BINBCD
  108.     STA    RTCBUF+4
  109.     CALL    CKLEAP        ; Check if leap year
  110.     MVI    A,-28
  111.     JNZ    FEBNO        ; February not 29 days
  112.     MVI    A,-29        ; Leap year
  113. ;
  114. FEBNO:    STA    FEB        ; Set february
  115.     LHLD    DTDAT        ; Get days count
  116.     LXI    D,MTABLE    ; Point to months table
  117.     MVI    B,0FFH        ; Set up 'B' for subtract
  118.     MVI    A,0        ; Set a for # of months
  119. ;
  120. MLOOP:    PUSH    PSW
  121.     LDAX    D        ; Get month
  122.     MOV    C,A        ; Put in 'C' for subtract
  123.     POP    PSW
  124.     SHLD    DTDAT        ; Save days count
  125.     DAD    B        ; Subtract
  126.     INX    D        ; Increment months counter
  127.     INR    A
  128.     JC    MLOOP        ; Loop for next month
  129. ;
  130. ;
  131. ; The months are finished, days count is on stack.  First, calculate
  132. ; month.
  133. ;
  134. MDONE:    MOV    B,A        ; Save months
  135.     LHLD    DTDAT
  136.     MOV    A,H
  137.     ORA    L
  138.     JNZ    NZD
  139.     DCX    D
  140.     DCX    D
  141.     LDAX    D
  142.     CMA
  143.     INR    A
  144.     MOV    L,A
  145.     DCR    B
  146. ;
  147. NZD:    MOV    A,B        ; Retrieve the binary month
  148.     CALL    BINBCD        ; Convert binary month to BCD
  149.     STA    RTCBUF+5    ; Store BCD month in RTCBUF
  150.     MOV    A,L        ; Retrieve binary day of month
  151.     CALL    BINBCD        ; Convert to BCD
  152.     STA    RTCBUF+6    ; Store BCD day of month in RTCBUF
  153. ;
  154.     RET
  155. ;.....
  156. ;
  157. ;
  158. ; This routine checks for leap years.
  159. ;
  160. CKLEAP:    MOV    A,B
  161.     ANI    0FCH
  162.     CMP    B
  163.     RET
  164. ;.....
  165. ;
  166. ;
  167. ; This is the month's table
  168. ;
  169. MTABLE:    DB    -31        ;January
  170. FEB:    DB    -28        ;February
  171.     DB    -31,-30,-31,-30    ;Mar-Jun
  172.     DB    -31,-31,-30    ;Jul-Sep
  173.     DB    -31,-30,-31    ;Oct-Dec
  174. ;
  175. DTDAT:    DW    0        ; Storage for DATE
  176.  
  177.      IF    NOT CLKINT
  178. DTHR:    DB    0        ; Hour in BCD
  179. DTMN:    DB    0        ; Minute in BCD
  180.      ENDIF            ; NOT CLKINT
  181.