home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / batutil / batques.asm < prev    next >
Assembly Source File  |  1994-03-04  |  3KB  |  96 lines

  1.     page 64,132
  2.     title bat-ques -- Batch file Question Asker, sets errorlevel
  3. .RADIX 10
  4. ;
  5. ;
  6. ;
  7. ;*****************************************************************
  8. ; INFO-IBMPC libarary contribution by H. Fischer - HFischer@eclb 12/83
  9. ; If you like it, do not send me $10 (but I will accept amounts
  10. ; with many more zeros if your generosity is excessive).
  11. ; Questions/problems to HFischer@eclb (213/902-5139).
  12. ;
  13. ; This program allows a batch file to ask the user a question
  14. ; and return a one-character response which is testable
  15. ; by the IF subcommand of bat files, via the errorlevel.
  16. ;
  17. ; You use the question asker per following example:
  18. ;
  19. ;   .
  20. ;   .  (your batch file to ask if guy wants to edit with
  21. ;   .       mince/emacs or ibm's editor)
  22. ;   .
  23. ;   echo off
  24. ;   bat-ques WHICH EDITOR, m OR e FOR MINCE (EMACS), i FOR IBM's? $
  25. ;   if errorlevel 110 goto badresp
  26. ;   if errorlevel 109 goto minceed
  27. ;   if errorlevel 106 goto badresp
  28. ;   if errorlevel 105 goto ibmed
  29. ;   if errorlevel 102 goto badresp
  30. ;   if errorlevel 101 goto minceed
  31. ;   :badresp
  32. ;   echo Your response was invalid. Sorry
  33. ;   goto endit
  34. ;   :minceed
  35. ;   if not exist mincomm.sum copy \bin\mince.swp mince.swp
  36. ;   mince %1
  37. ;   if not exist mincomm.sum del mince.swp
  38. ;   goto endit
  39. ;   :ibmed
  40. ;   profed %1
  41. ;   :endit
  42. ;   echo on
  43. ;
  44. ; Note that the question prompt follows the bat-ques command and
  45. ; must end with a dollar sign.  The ascii value of the response is
  46. ; returned as the error level.  Since error level tests are always
  47. ; greater than or equal tests, you must check for highest value first
  48. ; and lowest value last.  Example above shows what you doto check for
  49. ; missing values.  Note example assumes lower case answer only for
  50. ; simplicity sake.
  51. ;
  52. ; Ascii values (e.g., A is 65, B is 66, a is 97) are found in back
  53. ; of your BASIC manual.  Only one character responses are accepted,
  54. ; and they are not followed by a carriage return.
  55. ;
  56. ; Extended ascii codes (function and alt keys) should work as per
  57. ; page G-6 of your BASIC manual;  the first call to bat-ques will
  58. ; return a zero and the next call (presumably "bat-ques $" without
  59. ; another prompt) will return the number shown on page G-7.
  60. ;
  61. ; To build this program:
  62. ;    1) asm bat-ques
  63. ;    2) link bat-ques
  64. ;    3) exe2bin bat-ques.exe \bin\bat-ques.com (name your path dir!)
  65. ;    4) del bat-ques.exe
  66. ;
  67. ; have fun
  68. ;********************************************************************
  69. code    segment    para
  70.     assume    cs:code
  71.     org     82h
  72. PROMPT    label    byte        ; here DOS places the prompt string
  73.     org     100h
  74. KEY    proc    far
  75. START:
  76.     mov    ax,cs        ; make this mess addressable via ds
  77.     mov    ds,ax
  78.     assume    ds:code
  79.     mov    dx,offset PROMPT
  80.     mov    ah,9
  81.     int    21h        ; display the prompt
  82.     mov    ah,1
  83.     int    21h             ; get the input into AL
  84.     mov    saveit,al
  85.     mov    dx,offset newlin  ; move display to new line
  86.     mov    ah,9
  87.     int    21h
  88.     mov    al,saveit
  89.     mov    ah,4ch        ; return the errorlevel already in AL
  90.     int    21h
  91. newlin: db    10,13,'$'    ; give user a new line before quitting
  92. saveit    db    0
  93. KEY endp
  94. code ends
  95. end start
  96.