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 / JSAGE / ZSUS / PROGPACK / ZSLIB21.LBR / BCD2JUL.ZZ0 / BCD2JUL.Z80
Text File  |  1990-02-01  |  2KB  |  107 lines

  1. ; routine:  bcd2jul and bin2jul
  2.  
  3. ; author:  Bridger Mitchell & Howard Goldstein
  4.  
  5. ; date:  4/16/1988
  6.  
  7. ;    BCD to Julian date routine.
  8.  
  9. ; >>    hl-> DateStamper bcd yr/mo/da string
  10. ; <<    hl = Julian date (78/01/01 == 1)
  11. ;     (if yr<78 this routine wraps to next century.  routine covers
  12. ;    1978/01/01-2077/12/31)
  13. ;
  14.     ENTRY    BCD2JUL
  15. ;
  16.     EXTRN    JBCD2BN,DPERMO
  17. ;
  18.     CSEG
  19.  
  20. BCD2JUL:
  21.     push    af
  22.     push    bc
  23.     push    hl
  24.     ld    b,3        ;convert bcd yr/mo/da to bin
  25. BINLP:    ld    a,(hl)        ;at hl...
  26.     call    JBCD2BN
  27.     ld    (hl),a
  28.     inc    hl
  29.     djnz    BINLP
  30.     pop    hl
  31.     pop    bc
  32.     pop    af
  33.  
  34. ; fall thru...
  35. ;
  36. ;
  37. ;    Binary to Julian Date routine.
  38. ;
  39. ; >>    hl -> yr,mo,da in bin
  40. ; <<     hl = Julian date
  41. ;
  42.     ENTRY    BIN2JUL
  43. ;
  44. BIN2JUL:
  45.     push    af
  46.     push    bc
  47.     push    de
  48.     ld    a,(hl)        ;a = yr
  49.     inc    hl
  50.     ld    c,(hl)        ;c = mo
  51.     inc    hl
  52.     push    hl        ;save ptr to day
  53.     push    af        ;save year
  54. ;
  55. ; set hl= initial julian value of 77/12/31
  56. ;
  57.     ld    hl,0
  58.     sub    78
  59.     jr    z,B2JUL3
  60.     jr    nc,B2JUL0
  61.     add    a,100        ;<78, assume next century
  62. B2JUL0:    ld    b,a        ;b = # yrs > 78
  63.     ld    a,1        ;init modulo 4 counter
  64.     ld    de,365        ;days/yr
  65. B2JUL1:    add    hl,de        ;calc julian val. of  (yr/01/01 - 1)
  66.     inc    a
  67.     and    3        ;every 4 yrs,
  68.     jr    nz,B2JUL2
  69.     inc    hl        ;..add 1 for leap year
  70. B2JUL2:    djnz    B2JUL1
  71. ;
  72. ;     hl now = # days in years before current year
  73. ;
  74. B2JUL3:    pop    af
  75.     and    3        ;if current yr == leap year
  76.     jr    nz,B2JUL5
  77.     ld    a,c
  78.     cp    3        ;..and mo >= march
  79.     jr    c,B2JUL5
  80.     inc    hl        ;..add the extra day (Feb 29)
  81. ;
  82. B2JUL5:    ld    b,c        ; b = month = # months +1 to sum
  83.     ld    de,DPERMO    ;point at table
  84.     jr    B2JUL7
  85. ;
  86. B2JUL6:    call    ADDHL        ;add # days in this month
  87.     inc    de        ;bump tbl ptr
  88. B2JUL7:    djnz    B2JUL6
  89. ;
  90.     pop    de        ;ptr to day
  91.     call    ADDHL
  92.     pop    de
  93.     pop    bc
  94.     pop    af
  95.     ret
  96.  
  97. ADDHL:    ld    a,(de)        ;add day of current month
  98. ;
  99. ADDA2HL:add    l
  100.     ld    l,a
  101.     ret    nc
  102.     inc    h
  103.     ret
  104.  
  105.  
  106.     end
  107.