home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc / task.lzh / TASK.ASM next >
Assembly Source File  |  1985-12-06  |  11KB  |  306 lines

  1.          page    60,132
  2.          title   TASK - Timed ASK for batch files
  3.          subttl  (C) Copyright 1985 by System Enhancement Associates
  4.          page
  5. ;
  6. ;        This program allows the use of yes-or-no questions in batch
  7. ;        files, while placing a time limit on how long the user has before
  8. ;        an answer must be given.  Here's an example of how to use it:
  9. ;
  10. ;                task Are you there?
  11. ;
  12. ;        TASK will print the question "Are you there? " and wait up to
  13. ;        twenty seconds for an answer.  You can change the time limit
  14. ;        by preceeding the question with the number of seconds you wish
  15. ;        to allow.  Here's how to ask a question with a ten second limit:
  16. ;
  17. ;                task 10 Shall we begin?
  18. ;
  19. ;        TASK exits with an error level of zero if a "yes" is given,
  20. ;        or one if a "no" is given, or two if no answer is given.
  21. ;        Escape and Enter count as "no answer". Ctrl Break counts as "no".
  22. ;
  23. ;        Most people want to assume a default of either "yes" or "no" when
  24. ;        the time limit expires.  This can be easily done in the batch
  25. ;        file.  Here's a way to make "no" the default:
  26. ;
  27. ;                task Are you sure you want to do this?
  28. ;                if errorlevel 1 goto dothing
  29. ;
  30. ;        Since "if errorlevel 1" really means "if the error level is 1 or
  31. ;        higher", then the timeout error level of 2 will also work.  Here
  32. ;        is a way to make "yes" the default:
  33. ;
  34. ;                task Last chance! Are you sure?
  35. ;                if not errorlevel 2 if errorlevel 1 goto dothing
  36. ;
  37. ;        The DOS manual never really says that you can combine IF
  38. ;        statements like that, but we've tried it and it works.
  39. ;
  40. ;        You can also leave off the question and use TASK for a timed
  41. ;        delay.  Here's how to get a thirty second delay:
  42. ;
  43. ;                task 30
  44. ;
  45. ;        The delay can be cut short by any of Y, N, Escape, Enter, or
  46. ;        Ctrl Break.
  47. ;
  48.          page
  49.  
  50. code     segment
  51.          assume ds:code, ss:code, cs:code, es:code
  52.  
  53.          org     100h
  54. task     proc    near                ;simpler for COM file interface
  55.          jmp     start               ;skip over our data
  56.  
  57. banner   db      'TASK; Version '
  58. TED_VERSION DB '1.32, created on '
  59. TED_DATE DB '12/06/85 at '
  60. TED_TIME DB '11:00:00',13,10
  61.          db      '(C) COPYRIGHT 1985 by System Enhancement Associates;'
  62.          db      ' ALL RIGHTS RESERVED',13,10,10
  63.          db      'Timed ASK for batch files.'
  64.          db      '  Error level 0=Yes, 1=No, 2=No answer',13,10,10
  65.          db      'Usage: task [<n>] [<q>]',13,10
  66.          db      'Where:   <n> = Time limit in seconds (default 20)',13,10
  67.          db      '         <q> = Question to ask',13,10,'$'
  68.  
  69. yorn     db      '(Y or N) $'
  70. saidno   db      'No',13,10,'$'
  71. saidyes  db      'Yes',13,10,'$'
  72. unsaid   db      ' (no answer given)',13,10,'$'
  73.  
  74. tgtday   db      0                   ;target time of day
  75. tgthr    db      0
  76. tgtmin   db      0
  77. tgtsec   db      0
  78. tgthun   db      0
  79.  
  80. outyorn  db      0                   ;true when "Y or N" message displayed
  81. outsec   db      0                   ;output timer
  82. abstim   dw      ?                   ;target time in seconds
  83.  
  84. timcon   proc    near                ;convert time to number of seconds
  85.          mov     dl,dh               ;save seconds
  86.          xor     dh,dh
  87.          push    dx
  88.          mov     dl,cl               ;save minutes
  89.          push    dx
  90.  
  91.          xor     ah,ah               ;convert hours to minutes
  92.          mov     al,ch
  93.          mov     dx,60
  94.          mul     dx
  95.          pop     dx                  ;add minutes
  96.          add     ax,dx
  97.  
  98.          mov     dx,60               ;convert minutes to seconds
  99.          mul     dx
  100.          pop     dx                  ;add seconds
  101.          add     ax,dx
  102.  
  103.          ret                         ;return seconds in ax
  104. timcon   endp
  105.  
  106. count    proc    near                ;show a countdown
  107.          cmp     dh,outsec           ;see if time for a tick
  108.          jz      countx              ;not yet
  109.          mov     byte ptr outsec,dh
  110.  
  111.          call    timcon              ;calculate seconds left
  112.          mov     dx,word ptr abstim
  113.          sub     dx,ax
  114.  
  115.          cmp     dx,9                ;small enough to show?
  116.          jg      countx              ;not yet
  117.          cmp     dx,0                ;too small to show?
  118.          jle     countx              ;yep
  119.  
  120.          mov     ah,2                ;display character
  121.          add     dx,'0'              ;seconds left
  122.          int     21h
  123.          mov     dx,8                ;backspace
  124.          int     21h
  125.  
  126. countx:  ret
  127. count    endp
  128.  
  129. noargs:  mov     dx,offset banner    ;point to no args message
  130.          mov     ah,9                ;print string
  131.          int     21h
  132.          ret                         ;exit
  133.  
  134. start:   mov     ax,2523h            ;take over breaks
  135.          mov     dx,offset broken    ;equivalent to a no
  136.          int     21h
  137.  
  138.          mov     ah,2ch              ;get time of day
  139.          int     21h
  140.          mov     byte ptr tgtday,al  ;store it
  141.          mov     byte ptr tgthr,ch
  142.          mov     byte ptr tgtmin,cl
  143.          mov     byte ptr tgtsec,dh
  144.          mov     byte ptr tgthun,dl
  145.  
  146.          xor     ch,ch               ;zero out ch
  147.          mov     cl,ds:80h           ;get length of unformatted arguments
  148.          cmp     cx,1
  149.          jle     noargs              ;no args given!
  150.  
  151.          mov     di,81h              ;point at unformatted args
  152.          cld
  153.          mov     al,' '
  154.          repz    scasb               ;scan to a non-space
  155.          dec     di                  ;back up to start of delay
  156.          inc     cx
  157.          xor     ax,ax               ;clear out accumulator
  158. digloop: xor     bx,bx               ;clear out scratch
  159.          jcxz    digend              ;if more args
  160.          mov     bl,[di]             ;get a digit?
  161.          cmp     bl,'0'
  162.          jl      digend
  163.          cmp     bl,'9'
  164.          jg      digend
  165.          sub     bl,'0'              ;convert to true value
  166.          mov     dx,10               ;set multiplier
  167.          mul     dx                  ;decimal shift
  168.          add     ax,bx               ;add in new digit
  169.          dec     cx                  ;one less digit
  170.          inc     di                  ;point to next digit
  171.          jmp     digloop             ;go for next digit
  172.  
  173. digend:  push    ax                  ;save the delay time
  174.          mov     al,' '
  175.          repz    scasb               ;scan to a non-space
  176.          mov     bx,cx
  177.          mov     byte ptr [di+bx],'$';terminate the question
  178.          dec     di                  ;back up to start of question
  179.  
  180.          pop     ax                  ;get back delay time
  181.          cmp     ax,0                ;did we get a delay?
  182.          jnz     gotdel              ;yes
  183.          mov     ax,20               ;no - use default
  184.  
  185. gotdel:  add     al,byte ptr tgtsec  ;get target time
  186.          xor     bx,bx
  187.          mov     bl,byte ptr tgtmin
  188.          xor     cx,cx
  189.          mov     cl,byte ptr tgthr
  190.          xor     dx,dx
  191.          mov     dl,byte ptr tgtday
  192.  
  193. secloop: cmp     ax,60               ;seconds modulo 60
  194.          jl      minloop
  195.          sub     ax,60
  196.          inc     bx
  197.          jmp     secloop
  198.  
  199. minloop: cmp     bx,60               ;minutes modulo 60
  200.          jl      hrloop
  201.          sub     bx,60
  202.          inc     cx
  203.          jmp     minloop
  204.  
  205. hrloop:  cmp     cx,24               ;hours modulo 24
  206.          jl      dayloop
  207.          sub     cx,24
  208.          inc     dx
  209.          jmp     hrloop
  210.  
  211. dayloop: cmp     dx,7                ;days modulo 7
  212.          jl      tgtfixed
  213.          sub     dx,7
  214.          jmp     dayloop
  215.  
  216. tgtfixed:mov     byte ptr tgtsec,al  ;store fixed target time
  217.          mov     byte ptr tgtmin,bl
  218.          mov     byte ptr tgthr,cl
  219.          mov     byte ptr tgtday,dl
  220.  
  221.          mov     ch,cl               ;set up for time conversion
  222.          mov     cl,bl
  223.          mov     dh,al               ;set up for time conversion
  224.          call    timcon              ;calculate partial answer for timer
  225.          mov     word ptr abstim,ax
  226.  
  227.          mov     dx,di               ;point to question
  228.          mov     ah,9                ;print string
  229.          int     21h
  230.          mov     ah,2                ;display character
  231.          mov     dl,' '
  232.          int     21h
  233.  
  234. loop:    mov     ah,0bh              ;check input status
  235.          int     21h
  236.          cmp     al,0
  237.          jz      nogot               ;nothing typed yet
  238.  
  239.          mov     ah,8                ;input char with no echo
  240.          int     21h
  241.          cmp     al,13
  242.          jz      timeup              ;he refused comment
  243.          cmp     al,27
  244.          jz      timeup              ;he escaped the question
  245.          and     al,5fh              ;mask to uppercase
  246.          cmp     al,'Y'
  247.          jz      gotyes              ;he said yes
  248.          cmp     al,'N'
  249.          jz      gotno               ;he said no
  250.  
  251.          mov     dl,7                ;unknown input
  252.          mov     ah,2                ;beep at him
  253.          int     21h
  254.  
  255.          cmp     outyorn,0           ;have we said this yet?
  256.          jnz     nogot               ;yes - don't repeat
  257.          mov     ah,9                ;print string
  258.          mov     dx,offset yorn
  259.          int     21h
  260.          mov     outyorn,1
  261.  
  262. nogot:   mov     ah,2ch              ;get time
  263.          int     21h
  264.          cmp     al,byte ptr tgtday  ;check time
  265.          jg      timeup
  266.          jl      showout
  267.          cmp     ch,byte ptr tgthr
  268.          jg      timeup
  269.          jl      showout
  270.          cmp     cl,byte ptr tgtmin
  271.          jg      timeup
  272.          jl      showout
  273.          cmp     dh,byte ptr tgtsec
  274.          jg      timeup
  275.          jl      showout
  276.          cmp     dl,byte ptr tgthun
  277.          jg      timeup
  278.  
  279. showout: call    count               ;show a countdown timer
  280.          jmp     short loop
  281.  
  282. gotno:   mov     dx,offset saidno    ;point to echo
  283.          mov     ah,9                ;print string
  284.          int     21h
  285. broken:  mov     ah,4ch              ;exit with error level
  286.          mov     al,1
  287.          int     21h
  288.  
  289. gotyes:  mov     dx,offset saidyes   ;point to echo
  290.          mov     ah,9                ;print string
  291.          int     21h
  292.          mov     ah,4ch              ;exit with error level
  293.          mov     al,0
  294.          int     21h
  295.  
  296. timeup:  mov     dx,offset unsaid    ;point to echo
  297.          mov     ah,9                ;print string
  298.          int     21h
  299.          mov     ah,4ch              ;exit with error level
  300.          mov     al,2
  301.          int     21h
  302.  
  303. task     endp
  304. code     ends
  305.          end     task
  306.