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 / TURBODSG / TIMEDIF.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  4KB  |  192 lines

  1. ;TIMEDIF.ASM v1.10
  2. ;12/28/83
  3. ;By S. Kluger
  4. ;
  5. ; the fact that a major bug has not been discovered yet by
  6. ; anyone proves the popularity of the program...
  7. ;
  8. ; This is a module for use with RMAC and can be adapted to
  9. ; M80 with minimum effort.
  10. ;
  11. ; Purpose:
  12. ; Evaluate two ASCII character strings in HH:MM:SS format and
  13. ; return their difference.
  14. ;
  15. ; Entry point:    TIMDIF
  16. ; Externals:    STTIME
  17. ;        ENTIME
  18. ;        ELAPTM
  19. ;
  20. ; Input parameters:
  21. ; STTIME holds a time string of HH:MM:SS format. STTIME must point
  22. ; to the tens hours digit. The time string must be in 24 hour format.
  23. ; The time stored there should be the beginning time of an event.
  24. ;
  25. ; ENTIME holds a string with the same format. The time stored there
  26. ; should be the end of an event.
  27. ;
  28. ; On return, ELAPTM will be filled with the elapsed time in
  29. ; hours and minutes and the accumulator will be cleared with the
  30. ; ZERO flag SET. If either entry parameter contained an illegal
  31. ; quantity, the CARRY flag will be SET and ELAPTM will be undefined.
  32. ; NOTE: TIMDIF will not place delimiters into ELAPTM!
  33. ;
  34. ; Only the first 8 characters of the strings are processed and checked
  35. ; for proper range. Be sure to zero the seconds field if not needed!
  36. ;
  37. ; NOTE:
  38. ; If ENTIME is smaller than STTIME, then 24 hours are added to ENTIME.
  39. ;
  40. ; This routine is intended for application where the event time will
  41. ; never be greater than 23:59:59 (RCPM and BBS use mainly).
  42. ;
  43.     PUBLIC    TIMDIF        ;entry point
  44.     EXTRN    STTIME        ;start time field
  45.     EXTRN    ENTIME        ;end time field
  46.     EXTRN    ELAPTM        ;elapsed time field
  47. ;
  48.     cseg
  49. ;
  50. ; Entry point. All registers meet their doom...
  51. ;
  52. timdif:    lxi    h,sttime    ;point to start time
  53.     call    chform        ;check proper format
  54.     rc            ;return if error
  55.     lxi    h,entime    ;point to end time
  56.     call    chform        ;check that too
  57.     rc
  58. ;
  59. ; The stage is set - let's get down to business...
  60. ;
  61.     lxi    h,sttime+6    ;point to seconds start
  62.     call    getbin        ;get binary
  63.     mov    d,a        ;save it
  64.     lxi    h,entime+6    ;seconds end
  65.     call    getbin        ;get binary
  66.     mvi    e,0        ;reset our private borrow flag
  67.     sub    d        ;subtract
  68.     jnc    skbs        ;skip if no borrow
  69.     dcr    e        ;set our borrow flag
  70.     adi    60        ;make mod 60
  71. skbs:    lxi    h,elaptm+7    ;store as result
  72.     call    stora
  73. ;
  74. ; Do the same stuff for minutes
  75. ;
  76.     lxi    h,sttime+3    ;minutes start
  77.     call    getbin        ;get binary
  78.     mov    d,a        ;save binary
  79.     lxi    h,entime+3    ;minutes end
  80.     call    getbin        ;get binary
  81.     inr    e        ;if not borrow...
  82.     jnz    skbm1        ;then skip...
  83.     inr    d        ;...else add borrowed value
  84. skbm1:    mvi    e,0        ;make sure borrow flag reset
  85.     sub    d        ;subtract
  86.     jnc    skbm2        ;skip if no borrow
  87.     dcr    e        ;set borrow
  88.     adi    60        ;make mod 60
  89. skbm2:    lxi    h,elaptm+4    ;store elapsed minutes
  90.     call    stora
  91. ;
  92. ; Finally, here go the hours.
  93. ;
  94.     lxi    h,sttime    ;hours start
  95.     call    getbin        ;get 'em
  96.     mov    d,a        ;save start hours
  97.     lxi    h,entime    ;hours end
  98.     call    getbin        ;get binary
  99.     inr    e        ;if not borrow...
  100.     jnz    skbh1        ;...then skip...
  101.     inr    d        ;...else add borrowed hour
  102. skbh1:    sub    d        ;subtract
  103.     jnc    skbh2        ;jump if no borrow
  104.     adi    24        ;else add 24 hours
  105. skbh2:    lxi    h,elaptm+1    ;save as hours
  106.     call    stora
  107.     xra    a        ;make sure error is reset
  108.     ret            ;end of execution, back to caller.
  109. ;
  110. ; Get the ASCII value at HL as a binary into A
  111. ;
  112. getbin:    mov    a,m        ;get tens
  113.     ani    0fh        ;strip ASCII offset
  114.     mov    b,a        ;save tens
  115.     xra    a        ;set accumulator
  116.     mvi    c,10        ;set up cheap multiplier
  117. mul:    add    c
  118.     dcr    b
  119.     jnz    mul
  120.     mov    b,a        ;save tens
  121.     inx    h        ;point to units
  122.     mov    a,m        ;get units
  123.     ani    0fh        ;same treatment
  124.     add    b        ;add the tens
  125.     ret
  126. ;
  127. ; Check format of HH:MM:SS string. Checks all digits for presence
  128. ; and validity.
  129. ;
  130. chform:    mov    a,m        ;get 10s H
  131.     cpi    '0'
  132.     rc
  133.     cpi    '3'
  134.     cmc
  135.     rc
  136.     inx    h
  137.     mov    a,m        ;get 1s H
  138.     call    ck10        ;check decimal
  139.     rc
  140.     inx    h        ;get colon
  141.     mov    a,m
  142.     cpi    ':'
  143.     stc
  144.     rnz
  145.     inx    h        ;point to 10s M
  146.     mov    a,m
  147.     call    ck6        ;check hex
  148.     rc
  149.     inx    h
  150.     mov    a,m        ;1s M
  151.     call    ck10
  152.     rc
  153.     inx    h
  154.     mov    a,m        ;get delimiter
  155.     cpi    ':'
  156.     stc
  157.     rnz
  158.     inx    h
  159.     mov    a,m        ;get 10s S
  160.     call    ck6
  161.     rc
  162.     inx    h
  163.     mov    a,m
  164. ck10:    cpi    '0'
  165.     rc
  166.     cpi    '9'+1
  167.     cmc
  168.     ret
  169. ;
  170. ck6:    cpi    '0'
  171.     rc
  172.     cpi    '7'
  173.     cmc
  174.     ret
  175. ;
  176. ; Store accumulator as ASCII digits at HL and HL+1
  177. ;
  178. stora:    mvi    b,-1
  179. tlp:    inr    b
  180.     sui    10        ;subtract 10
  181.     jnc    tlp        ;until borrow
  182.     adi    10        ;make mod 10
  183.     ori    '0'        ;make ASCII
  184.     mov    m,a
  185.     dcx    h
  186.     mvi    a,'0'
  187.     add    b
  188.     mov    m,a
  189.     ret
  190. ;
  191.     end
  192.