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 / ZSUS / ZSUS001.LBR / LPUT18.LBR / UNDATE.ZZ0 / UNDATE.Z80
Text File  |  1988-03-16  |  3KB  |  154 lines

  1. ;Converted to Zilog mnemonics and put in a few JRs
  2. ;March 16, 1988 by Bruce Morgen for LPUT15
  3.  
  4. ;UNDATE.ASM v 1.00         10/26/83
  5. ; S. Kluger  El Paso RCPM
  6. ;
  7. ; This routine will take a standard ASCII date string
  8. ; and change it into Digital Research date format.
  9. ;
  10. ; Input: none
  11. ;     (The program expects the external variable @dcfld
  12. ;    to be a pointer to a properly set up date string.
  13. ;    The string must conform to MM/DD/YY format.)
  14. ; Output: HL holds the number of days since 1-1-78
  15. ;    The carry flag indicates a possible date format error.
  16. ;
  17.     EXTRN @DCFLD
  18.     PUBLIC @UDCVT
  19. ;
  20. @UDCVT:    LD    HL,@DCFLD+7    ; Point to units year
  21.     LD    A,(HL)        ; Get it
  22.     CALL    CKNUM        ; If not numeric...
  23.     RET    C        ; ...then error
  24.     LD    B,A        ; Save for now
  25.     DEC    HL        ; Point to tens year
  26.     LD    A,(HL)        ; Get it
  27.     CALL    CKNUM        ; Check numeric
  28.     RET    C        ; Abort if error
  29.     LD    C,A        ; Tens into c
  30.     INC    C        ; Plus one for our loop
  31.     LD    D,10
  32.     XOR    A
  33. MCY:    DEC    C
  34.     JR    Z,MCYD        ; Zero = done
  35.     ADD    A,D
  36.     JR    MCY
  37. ;
  38. MCYD:    ADD    A,B        ; Add units
  39.     LD    B,78        ; Set up years counter
  40.     CP    B
  41.     RET    C        ; Error if year < 78
  42.     LD    C,A        ; Year into c
  43.     AND    0FCH        ; Is current leap?
  44.     CP    C
  45.     LD    A,28        ; Expect not
  46.     JR    NZ,NOCL
  47.     INC    A
  48. NOCL:    LD    (FEB),A
  49.     LD    HL,0        ; Set day counter
  50. YLP:    LD    A,C        ; Get year
  51.     CP    B        ; Is it 78 now?
  52.     JR    Z,YDONE        ; Yes, exit this routine
  53.     LD    DE,365        ; Set days for 1 year
  54.     DEC    C        ; Decrement year
  55.     DEC    A        ; Both times
  56.     AND    0FCH        ; Check leap year
  57.     CP    C        ; If not leap year...
  58.     JR    NZ,NOLP        ; ...then leap
  59.     INC    DE        ; Else make 366 days
  60. NOLP:    ADD    HL,DE        ; Sum up days
  61.     JR    YLP
  62. ;
  63. ; years done, process months
  64. ;
  65. YDONE:    LD    (DAYS),HL    ; Save day count for now
  66.     LD    HL,@DCFLD+1    ; Point to units month
  67.     LD    A,(HL)        ; Get them
  68.     CALL    CKNUM        ; Check numeric
  69.     RET    C        ; Ret if error
  70.     LD    B,A        ; Save units
  71.     DEC    HL        ; Point to units
  72.     LD    A,(HL)        ; Get 'em
  73.     CALL    CKNUM        ; Check
  74.     RET    C        ; Ret if error
  75.     CP    2        ; If > 1
  76.     CCF
  77.     RET    C        ; Then error
  78.     OR    A        ; If not zero...
  79.     LD    A,10        ; ...then it's gotta be 10
  80.     JR    NZ,ADU
  81.     XOR    A
  82. ADU:    ADD    A,B        ; Easier than years!
  83.     LD    BC,MONTH    ; Point to months
  84.     LD    H,0
  85.     LD    L,A
  86.     ADD    HL,BC        ; Make months pointer
  87.     LD    B,H
  88.     LD    C,L
  89.     DEC    BC
  90.     LD    HL,(DAYS)
  91.     LD    D,0        ; Prepare for add
  92. MLP:    DEC    A        ; Decrement year
  93.     DEC    BC
  94.     JR    Z,MDONE        ; Go to next routine
  95.     PUSH    AF
  96.     LD    A,(BC)        ; Get days
  97.     LD    E,A
  98.     ADD    HL,DE        ; Add to total
  99.     POP    AF
  100.     JR    MLP
  101. ;
  102. ; months done, now process the days
  103. ;
  104. MDONE:    LD    (DAYS),HL    ; Save days for now
  105.     LD    HL,@DCFLD+4    ; Point to days units
  106.     LD    A,(HL)        ; Get them
  107.     CALL    CKNUM        ; If not numeric
  108.     RET    C        ; Then return
  109.     LD    B,A        ; Save units
  110.     DEC    HL        ; Point to tens
  111.     LD    A,(HL)
  112.     CALL    CKNUM
  113.     RET    C
  114.     CP    4        ; If over 30
  115.     CCF
  116.     RET    C        ; Then error
  117.     LD    C,A        ; Save count
  118.     INC    C        ; 0=1, 1=2, etc
  119.     XOR    A
  120.     LD    D,10        ; Ready for "multiply"
  121. MC:    DEC    C        ; Dec counter
  122.     JR    Z,MULOK        ; Finished multiplying
  123.     ADD    A,D
  124.     JR    MC
  125. ;
  126. MULOK:    ADD    A,B        ; Now make binary days
  127.     LD    E,A
  128.     LD    D,0
  129.     LD    HL,(DAYS)
  130.     ADD    HL,DE
  131.     OR    A        ; Reset carry
  132.     RET
  133. ;
  134. ; check numeric digit, convert to binary if ok
  135. ;
  136. CKNUM:    CP    '0'
  137.     RET    C
  138.     CP    '9'+1
  139.     CCF
  140.     RET    C
  141.     AND    0FH
  142.     RET
  143. ;
  144. MONTH:    DB    31        ; Jan
  145. FEB:    DB    28,31,30,31,30    ; Feb-Jun
  146.     DB    31,31,30,31,30    ; Jul-Nov
  147.  
  148. ; Data
  149.  
  150.     DSEG
  151. DAYS:    DS    2
  152.  
  153.     END
  154.