home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BYE5 / B5C-SB.INS < prev    next >
Text File  |  2000-06-30  |  5KB  |  141 lines

  1. ; B5C-SB.INS - Clock routine for SB-180
  2. ;
  3. ; Uses the the wallclock data area of the BIOS to return the current
  4. ; time to BYE5. The first time check after midnight will automatically
  5. ; update the BYE5 date area, but since the SB-180 does not store the
  6. ; current date, this area must first be intitialized to the correct date
  7. ; by some other means.
  8. ;
  9. ; (Dec 16 1986)    Initial release for BYE510 and above. Note that
  10. ;        this insert uses the Z80 "LDIR" instruction to
  11. ;        minimize the time that interrupts are disabled.
  12. ;        Since all SB-180s use the HD64180 CPU chip, this
  13. ;        should be no problem.
  14. ;                        -- Stuart Rose
  15. ;
  16. ;----------------------------------------------------------------
  17. ;
  18. ; This clock insert uses BCDBIN and BINBCD subroutines.  It requires that
  19. ; configuration tags BCD2BIN and BIN2BCD as well as CLOCK be set to YES.
  20. ;
  21. ;    Note: This is an insert -- not an overlay
  22. ;
  23.      IF    CLOCK OR RSPEED
  24.  
  25. WBOOT    equ    0000H        ; address of warm boot vector
  26. CENTURY    equ    19H        ; current century (19xx) in BCD
  27. TIMOFF    equ    33        ; offset to time routine in BIOS jump table
  28.  
  29. TIME:    call    getclk        ; get the time from the system clock
  30.  
  31.     lda    TMPBUF+2    ; get hours (binary)
  32.     sta    CCHOUR        ; save as current hour
  33.     call    BINBCD        ; convert to BCD
  34.     sta    RTCBUF        ; and store BCD hours in RTCBUF
  35.     lda    TMPBUF+1    ; get minutes (binary)
  36.     sta    CCMIN        ; save as current minute
  37.     call    BINBCD        ; convert to BCD
  38.     STA    RTCBUF+1    ; and store tore BCD minutes in RTCBUF
  39.     lda    TMPBUF        ; Get seconds (binary)
  40.     call    BINBCD        ; convert to BCD
  41.     STA    RTCBUF+2    ; and store BCD seconds in RTCBUF
  42.  
  43.     lda    OLDHRS        ; get old system hours
  44.     mov    B,A        ; save it
  45.     lda    TMPBUF + 2    ; get new system hours
  46.     sta    OLDHRS        ; store it
  47.     sub    B        ; day rollover?
  48.     rnc            ; nope
  49.  
  50.     mvi    A,CENTURY    ; yep, get current century
  51.     sta    RTCBUF+3    ; and store in RTC buffer
  52.  
  53.     lda    RTCBUF+6    ; get the day of the month (BCD)
  54.     adi    1        ; bump up ...
  55.     daa            ; adjust to BCD ...
  56.     sta    RTCBUF+6    ; store the new day ...
  57.     mov    B,A        ; and save
  58.     lxi    H,monmap    ; point to the month map
  59.     lda    RTCBUF+5    ; get the month of the year (BCD)
  60.     call    BCDBIN        ; convert to binary
  61.     dcr    A        ; remove offset (for base zero)
  62.     call    chkly        ; check for leap year
  63.     adc    A        ; multiply by 2 (with carry for ly)
  64.     mvi    D,0        ; and create an offset
  65.     mov    E,A        ;
  66.     dad    D        ; add offset
  67.     mov    A,M        ; get number of days this month
  68.     sub    B        ; rollover?
  69.     rnc            ; nope
  70.     mvi    A,01H        ; yep reset the day of the month
  71.     sta    RTCBUF+6    ;
  72.  
  73.     lda    RTCBUF+5    ; get the month of the year (BCD)
  74.     adi    1        ; bump up ...
  75.     daa            ; adjust to BCD ..
  76.     sta    RTCBUF+5    ; store the new month ...
  77.     cpi    12+1        ; rollover?
  78.     rc            ; nope
  79.     mvi    A,01H        ; yep reset the month of the year
  80.     sta    RTCBUF+5    ;
  81.  
  82.     lda    RTCBUF+4    ; get the year (BCD)
  83.     adi    1        ; bump up ...
  84.     daa            ; adjust to BCD ...
  85.     sta    RTCBUF+4    ; and store the new year
  86.  
  87.     ret            ; done
  88. ;
  89. ; This routine checks for leap years. If the current year is a leap
  90. ; year, then this routine returns with the CARRY set.
  91. ;
  92. chkly:    lda    RTCBUF+4    ; get the year (BCD)
  93.     call    BCDBIN        ; convert to binary
  94.     mov    B,A        ; save it
  95.     ani    0FCH        ; year = year mod 4
  96.     cmp    B        ; same as original?
  97.     cmc            ; set CARRY if so
  98.     ret
  99. ;
  100. ; This routine will read from the SB-180 wallclock data area
  101. ;
  102. getclk:    call    biosclk        ; point to BIOS RTC data area
  103.     lxi    D,TMPBUF    ; point to temporary buffer
  104.     lxi    B,3        ; moving 3 bytes
  105.     di            ; disable interrupts
  106.     db    0EDH,0B0H    ; Z80 LDIR instruction
  107.     ei            ; enable interrupts
  108.     ret            ; done
  109. ;
  110. ; This routine will call the BIOS time routine and return with the
  111. ; the <HL> register pair pointing to the BIOS RTC data area
  112. ;
  113. biosclk:lxi    H,WBOOT+1    ; point to warmboot vector
  114.     lxi    D,TIMOFF    ; get offset to BIOS time routine
  115.     dad    D        ; add offset
  116.     pchl            ; and jump to it
  117. ;
  118. ; This is a month map for the number of day in each month of the
  119. ; year. The first value is for a standard year, the second for a
  120. ; leap year. Note all values are in BCD.
  121. ;
  122. monmap:    db    31H,31H        ; January   std,lpyr
  123.     db    28H,29H        ; February  std,lpyr
  124.     db    31H,31H        ; March     std,lpyr
  125.     db    30H,30H        ; April     std,lpyr
  126.     db    31H,31H        ; May       std,lpyr
  127.     db    30H,30H        ; June      std,lpyr
  128.     db    31H,31H        ; July      std,lpyr
  129.     db    31H,31H        ; August    std,lpyr
  130.     db    30H,30H        ; September std,lpyr
  131.     db    31H,31H        ; October   std,lpyr
  132.     db    30H,30H        ; November  std,lpyr
  133.     db    31H,31H        ; December  std,lpyr
  134.  
  135. OLDHRS:    db    0        ; remember hours from last call
  136. TMPBUF:    db    0        ; temporary storage for the seconds
  137.     db    0        ; temporary storage for the minutes
  138.     db    0        ; temporary storage for the hours
  139.  
  140.      ENDIF            ; CLOCK OR RSPEED
  141.