home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / USCX / DOSUT-17.ZIP / QUERY.ASM < prev    next >
Assembly Source File  |  1984-02-22  |  7KB  |  146 lines

  1. ;
  2. ; QUERY - BATch file 'Y/N' prompt routine.
  3. ; Written byKevin Cogan.
  4. ; Copyright October, 1983
  5. ;
  6. COMMENT &       This program, which can be called from a BATch file,
  7.                 prompts the user for yes or no (Y OR N) response
  8.                 and then returns an ERRORLEVEL of 1 to the BATch file
  9.                 for a reply of 'y' or 'Y' and a 0 for a reply of 'n'
  10.                 or 'N'. The only acceptable responses to the prompt
  11.                 are 'y', 'Y', 'n', or 'N'. an 80 column display is
  12.                 assumed.
  13.                     The 'question' displayed from the BATch file
  14.                 can be via a REM statement or an ECHO statement, but
  15.                 the 'question' should end with a '?'. the '(Y or N)'
  16.                 prompt will then start 2 spaces beyond the '?'. if
  17.                 a '?' is not used, then the '(Y or N)' prompt will
  18.                 be placed on the next line following the 'question',
  19.                 in the third column. A typical application of this
  20.                 program is as follows: ZAP.BAT
  21.                        
  22.               ECH OFF
  23.               DIR %1
  24.               ECHO The above file(s) have been targeted for
  25.               ECHO destruction. Is this acceptable?
  26.               QUERY
  27.               IF ERRORLEVEL 1 DEL %1
  28.               IF NOT ERRORLEVEL 1 ECHO * Destruction aborted * &
  29. ;
  30. ; Set up stack segment.
  31. ;
  32.        SSEG     SEGMENT STACK
  33.                 DB      16 DUP ('STACK   ')
  34.        SSEG     ENDS
  35. ;
  36. ; Set up data segment which contains prompt.
  37. ;
  38.        DSEG     SEGMENT 'DATA'
  39.        PRMPT    DB      ' (Y or N)'     ; Prompt message
  40.                 
  41.                 DB      '$'             ; String terminator
  42.        DSEG     ENDS
  43. ;
  44. ; Start of the routine.
  45. ;
  46.        CSEG     SEGMENT 'CODE'
  47.        START    PROC    FAR
  48.                 ASSUME CS:CSEG;DS:DSEG;SS:SSEG;ES:NOTHING
  49. ;
  50.                 MOV     AX,DSEG         ; Get location of data segment
  51.                 MOV     DS,AX           ;Load data segment into DS
  52. ;
  53. ; The first task is to find where the cursor is, since the 'question'
  54. ; requiring the prompt will be on the line above the current cursor
  55. ; location.
  56.                 MOV     BH,0            ; Set page number to 0
  57.                 MOV     AH,3            ; AH=3: Request cursor position
  58.                 INT     10H             ; Call BIOS for cursor position
  59. ;
  60. ; The cursor position is in DX (DH=row, DL=column). We now can
  61. ; begin searching the previous line, which contains the question,
  62. ; for a '?' which is the question terminator.
  63. ;
  64.                 SUB     DH,1            ; Decrement row index by 1
  65.                 MOV     CX,80           ; Load counter for '?' search
  66.                 MOV     DL,CL           ; Load column index
  67. ;
  68. ; Beginning of the '?' search loop. Search will begin in the last
  69. ; column of the display (79), and continue towards column 0 until
  70. ; search is successful. If no '?' is found, the prompt message
  71. ; will be placed on the line following the 'question'.
  72. ;
  73.        LOOK     LABEL   NEAR
  74.                 SUB     DL,1            ; Decrement the column index
  75.                 MOV     AH,2            ; AH=2: Move cursor to (DH,DL)
  76.                 INT     10H             ; BIOS request to locate cursor
  77.                 MOV     AH,8            ; AH=8: Get value of character
  78.                 INT     10H             ; BIOS request for character
  79.                 CMP     AL,63           ; Is character a '?'
  80.                 JZ      FIND            ; Goto FIND when '?' is found
  81.                 LOOP    LOOK            ; Else continue looking
  82. ;
  83. ; If '?' search is unsuccessful, then the row index is incremented
  84. ; by 1 so that the prompt will appear on the next line.
  85. ;
  86.                 ADD     DH,1            ; Increment row index by 1
  87.        FIND     LABEL   NEAR
  88.                 ADD     DL,1            ; Increment column index by 1
  89. ;
  90. ; If '?' search is unsuccessful, then the row index is incremented
  91. ; by 1 so that the prompt will appear on the next line.
  92. ;
  93. ; Prompt message is displayed and reply is read from the keyboard.
  94. ;
  95.        PLACE    LABEL   NEAR
  96.                 MOV     AH,2            ; AH=2: Move cursor to (DH,DL)
  97.                 INT     10H             ; BIOS request to locate cursor
  98.                 PUSH    DX              ; Save cursor location
  99.                 MOV     DX,OFFSET PRMPT ; Load data location into DX
  100.                 MOV     AH,9            ; AH-9: Output data
  101.                 INT     21H             ;DOS service request
  102.                 POP     DX              ; Retrieve cursor location
  103.                 MOV     AH,1            ; AH-1: Wait for keyboard input
  104.                 INT     21H             ; DOS service request
  105. ;
  106. ; Check input for affirmative, negative, or illegeal value.
  107. ;
  108.               
  109.                 CMP     AL,89           ; Is input 'Y'?
  110.                 JZ      YES             ; Then goto YES routine.
  111.                 CMP     AL,121          ; Is input 'y'?
  112.                 JZ      YES             ; Then goto YES routine.
  113.                 CMP     AL,78           ; Is input 'N'?
  114.                 JZ      NO              ; Then goto NO routine.
  115.                 CMP     AL,110          ; Is input 'n'?
  116.                 JZ      NO              ; Then goto NO routine.
  117.                 JMP     PLACE           ; Bad input: Reissue prompt
  118. ;
  119. ; Affirmative response routine. ERRORLEVEL flag is set to 1 via AL.
  120. ;
  121.        YES      LABEL   NEAR
  122.                 MOV     AL,1            ; Set ERRORLEVEL to value of 1
  123.                 JMP     DONE            ; Goto wrap-up routine
  124. ;
  125. ; Negative response routine.  ERRORLEVEL flag is set to 0 via AL.
  126. ;
  127.        NO       LABEL   NEAR
  128.                 MOV     AL,0            ; Set ERRORLEVEL value
  129. ;
  130. ; Wrap-up routine
  131. ;
  132.        DONE     LABEL   NEAR
  133.                 PUSH    AX              ; Save ERRORLEVEL value
  134.                 MOV     DL,10           ; Set DL value for LINEFEED
  135.                 MOV     AH,2            ; AH=2: Output character in DL
  136.                 INT     21H             ; DOS service request
  137.                 MOV     DL,13           ; Set DL value for CR
  138.                 MOV     AH,2            ; AH=2: Output character in DL
  139.                 INT     21H             ; DOS service request
  140.                 POP     AX              ; Retrieve ERRORLEVEL value
  141.                 MOV     AH,4CH          ; AH=4CH: Terminate code
  142.                 INT     21H             ; DOS service request
  143.        START    ENDP
  144.        CSEG     ENDS
  145.                 END
  146.