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 / Z8D24SUP.ARC / DATEHL.Z8° < prev    next >
Text File  |  1991-02-10  |  3KB  |  154 lines

  1. ; Module Name:    DATEHL
  2. ; Author:    Carson Wilson
  3. ; Version:    1.0
  4. ; Date:     25 Sept 87
  5.  
  6.     Public    DateHL
  7.  
  8. ;
  9. ; DATEHL converts the value in HL to BCD year, month, day
  10. ;     for use with Z80DOS time stamps.
  11. ;
  12. ; Inputs:    HL contains hex days since December 31, 1977
  13. ;
  14. ; Outputs:    H contains BCD 20th century year
  15. ;        L contains BCD month
  16. ;        A contains BCD day
  17. ;
  18. ;        Zero flag set (Z) and A=0 if invalid date (zero) detected,
  19. ;        Zero flag reset (NZ) and A=0ffh otherwise.
  20.  
  21. ; Adapted from B5C-CPM3.INS
  22.  
  23. DateHL:
  24.     ld    a,h
  25.     or    l        ; Test blank date (zero)
  26.     ret    z        ; Return Z and A=0 if so
  27.  
  28.     ld    (days),hl    ; Save initial value
  29.     ld    b,78        ; Set years counter
  30. loop:
  31.     call    ckleap
  32.     ld    de,-365        ; Set up for subtract
  33.     jp    nz,nolpy    ; Skip if no leap year
  34.     dec    de        ; Set for leap year
  35. nolpy:
  36.     add    hl,de        ; Subtract
  37.     jp    nc,ydone    ; Continue if years done
  38.     ld    a,h
  39.     or    l
  40.     jp    z,ydone
  41.     ld    (days),hl    ; Else save days count
  42.     inc    b        ; Increment years count
  43.     jp    loop        ; And do again
  44. ;
  45. ; The years are now finished, the years count is in 'B' (HL is invalid)
  46. ;
  47. ydone:
  48.     ld    a,b
  49.     call    binbcd
  50.     ld    (year),a    ; save BCD year
  51. ;
  52.     call    ckleap        ; Check if leap year
  53.     ld    a,-28
  54.     jp    nz,febno    ; February not 29 days
  55.     ld    a,-29        ; Leap year
  56. febno:
  57.     ld    (feb),a        ; Set february
  58.     ld    hl,(days)    ; Get days count
  59.     ld    de,mtable    ; Point to months table
  60.     ld    b,0ffh        ; Set up 'B' for subtract
  61.     ld    a,0        ; Set a for # of months
  62. mloop:
  63.     push    af
  64.     ld    a,(de)        ; Get month
  65.     ld    c,a        ; Put in 'C' for subtract
  66.     pop    af
  67.     ld    (days),hl    ; save days count
  68.     add    hl,bc        ; Subtract
  69.     inc    de        ; Increment months counter
  70.     inc    a
  71.     jp    c,mloop        ; Loop for next month
  72. ;
  73. ; The months are finished, days count is on stack.  First, calculate
  74. ; month.
  75. ;
  76. mdone:
  77.     ld    b,a        ; Save months
  78.     ld    hl,(days)
  79.     ld    a,h
  80.     or    l
  81.     jp    nz,nzd
  82.     dec    de
  83.     dec    de
  84.     ld    a,(de)
  85.     cpl
  86.     inc    a
  87.     ld    l,a
  88.     dec    b
  89. nzd:
  90.     ld    a,l        ; Retrieve binary day of month
  91.     call    binbcd        ; Convert to BCD
  92.     push    af        ; Save day in A
  93. ;
  94.     ld    a,b        ; Retrieve the binary month
  95.     call    binbcd        ; Convert binary month to BCD
  96.     ld    l,a        ; Return month in L
  97. ;
  98.     ld    a,(year)
  99.     ld    h,a        ; Return year in H
  100. ;
  101.     or    0ffh        ; Return no error
  102.     pop    af        ; Restore day
  103.     ret
  104.  
  105. ;
  106. ; Support Routines:
  107. ;
  108.  
  109. ;
  110. ; Check for leap years.
  111. ;
  112. ckleap:    ld    a,b
  113.     and    0fch
  114.     cp    b
  115.     ret
  116. ;
  117. ; Convert A to BCD & store back in A
  118. ;
  119. BinBCD:
  120.     or    a
  121.     ret    z
  122.     push    bc
  123.     ld    b,a
  124.     xor    a
  125. BinBCD1:
  126.     add    a,1
  127.     daa
  128.     djnz    BinBCD1
  129.     pop    bc
  130.     ret
  131. ;
  132. ; Buffers:
  133. ;
  134.  
  135. ;
  136. ; Months table
  137. ;
  138. mtable:
  139.     db    -31        ;January
  140. feb:
  141.     db    -28        ;February
  142.     db    -31,-30,-31,-30    ;Mar-Jun
  143.     db    -31,-31,-30    ;Jul-Sep
  144.     db    -31,-30,-31    ;Oct-Dec
  145. days:
  146.     ds    2        ; temporary buffers
  147. year:
  148.     ds    1
  149.  
  150.     end
  151.  
  152. ; END DATEHD.Z80
  153.  
  154.