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 / BEEHIVE / OS / BZ8DCLK.Z80 < prev    next >
Text File  |  2000-06-30  |  3KB  |  119 lines

  1.  
  2. ;+----------------------------------------------------------------------+
  3. ;| BZ8DCLK    Read time and date from real-time-clock, convert to    |
  4. ;|        Z80dos format and exit with HL pointing to buffer.    |
  5. ;|                                    |
  6. ;|        For MicroBee's with Z80DOS and BIOS V9 or PJB's BIOS.    |
  7. ;|                                    |
  8. ;|        BZ8DCLK.Z80 adapted from Peter De Lacey's BIOSCLK.Z80.    |
  9. ;|        BIOSCLK.Z80 adapted from Ron Murray's BEECLK.Z80.    |
  10. ;|        BEECLK.Z80 adapted from S. Kluger's UNDATE.ASM.        |
  11. ;|                                    |
  12. ;|        BZ8DCLK.Z80 written by Phil Summers c/o Z-node 62 Perth |
  13. ;+----------------------------------------------------------------------+
  14.  
  15. bz8dclk    push    de        ; save all        1
  16.     push    bc        ; registers        1
  17.     push    af        ; used            1
  18.  
  19.     ld    hl,tb        ;            3
  20.     push    hl        ; read time        1
  21.     ld    e,0        ; and date from        2
  22.     ld    b,7        ; RTC using        2
  23.     ld    a,26        ; extended        2
  24.     rst    28h        ; BIOS call        1
  25.     pop    hl        ;            1
  26.  
  27.     ld    b,3        ;            2
  28. lp    ld    a,(hl)        ;            1
  29.  
  30.     ld    e,a        ;            1
  31.     and    0FH        ;            2
  32.     ld    d,a        ;            1
  33.     ld    a,e        ; convert BCD        1
  34.     and    0F0H        ; year, month        2
  35.     rrca            ; and date in        1
  36.     ld    e,a        ; A to binary        1
  37.     rrca            ;            1
  38.     rrca            ;            1
  39.     add    a,e        ;            1
  40.     add    a,d        ;            1
  41.  
  42.     ld    (hl),a        ; save binary        1
  43.     inc    hl        ; value and point    1
  44.     djnz    lp        ; to next        2
  45.  
  46.     ld    l,a        ; count days in HL    1
  47.     ld    h,b        ; start with the date    1    b=0
  48.  
  49.     ld    de,365        ; days in a year, start    3
  50.     ld    bc,78+(3*256)    ; year, leap year mask    3
  51.  
  52. ay    ld    a,(year)    ; exit if the year    3
  53.     cp    c        ; counter has reached    1
  54.     jr    z,fin        ; the current year    2
  55.  
  56.     inc    c        ; add 365 days        1
  57.     add    hl,de        ; for each year        1
  58.  
  59.     ld    a,c        ; also, if        1
  60.     and    b        ; the year is        1
  61.     jr    nz,ay        ; a leap year        2
  62.     inc    hl        ; then add an        1
  63.     jr    ay        ; extra day        2
  64.  
  65. fin    and    b        ; if this year is    1
  66.     ld    a,(month)    ; a leap year but    3
  67.     jr    nz,nly        ; if the month isn't    2
  68.     cp    b        ; past February        1    b=3
  69.     jr    nc,nly        ; then subtract the    2
  70.     dec    hl        ; incorrect leap year    1
  71.  
  72. nly    push    hl        ; save days so far    1
  73.  
  74.     ld    e,a        ; calculate the        1
  75.     dec    d        ; address of the    1    d=0
  76.     ld    hl,dt-1        ; number of days    3
  77.     add    hl,de        ; so far this        1
  78.     ld    c,(hl)        ; year and get        1
  79.     ld    b,d        ; it in BC        1
  80.  
  81.     add    a,246        ; adjust fo Oct.,    2
  82.     rl    b        ; Nov. and Dec.        2
  83.  
  84.     pop    hl        ; add year-days        1
  85.     add    hl,bc        ; to month-days        1
  86.     ld    (nd),hl        ; and save in buffer    3
  87.  
  88.     pop    af        ; restore all        1
  89.     pop    bc        ; registers        1
  90.     pop    de        ; used            1
  91.  
  92.     ld    hl,nd        ; exit with HL        3
  93.     ret            ; pointing to buffer    1
  94.  
  95. dt    db    0        ; 1st Jan - 1st Jan    1
  96.     db    31        ; 1st Jan - 1st Feb    1
  97.     db    59        ; 1st Jan - 1st Mar    1
  98.     db    90        ; 1st Jan - 1st Apr    1
  99.     db    120        ; 1st Jan - 1st May    1
  100.     db    151        ; 1st Jan - 1st Jun    1
  101.     db    181        ; 1st Jan - 1st Jul    1
  102.     db    212        ; 1st Jan - 1st Aug    1
  103.     db    243        ; 1st Jan - 1st Sep    1
  104.     db    273-256        ; 1st Jan - 1st Oct    1
  105.     db    304-256        ; 1st Jan - 1st Nov    1
  106.     db    334-256        ; 1st Jan - 1st Dec    1
  107.  
  108. tb    equ    $
  109.  
  110. year    ds    1        ; year            1
  111. month    ds    1        ; month            1
  112. nd    ds    1        ; date            1
  113.     ds    1        ; day            1
  114.     ds    1        ; hours            1
  115.     ds    1        ; minutes        1
  116.     ds    1        ; seconds        1
  117.  
  118.     end
  119.