home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / STDERRF.ZIP / GETVLDC.ASM < prev    next >
Assembly Source File  |  1995-05-29  |  4KB  |  155 lines

  1.     page 60,132
  2.     title    GetValidChoice - Get Validated User Choice
  3.     name    GetValidChoice
  4.     
  5. comment ÷
  6.     GetValidChoice                        V1.00
  7. ----------------------------------------------------------------------------
  8. NAME
  9.     GetValidChoice                Get Validated User Choice
  10.  
  11. SYNOPSIS
  12.     mov    ax, Choices        ; AH = ret w/ carry flag set
  13.                     ; AL = ret w/ carry flag clear
  14.     call    GetValidChoice
  15.  
  16. DESCRIPTION
  17.     This procedure is called after a message is displayed to which the
  18.     user has two choices with which to respond.  These valid choices
  19.     must be passed to the procedure in lower case in the AX register.
  20.  
  21.     This procedure waits for the user response.  If the user enters
  22.     the choice in the AH register, this procedure returns with the
  23.     Carry Flag set.     If the user enters the choice in the AL register,
  24.     this procedure returns with the Carry Flag clear.  If the user
  25.     enters an invalid character, this procedure builds a message in
  26.     the form "? (x/y): " where x and y are the AH and AL register
  27.     choices respectively.    This procedure waits for another response.
  28.  
  29.     The user may respond in either case.
  30.  
  31. PROGRAMMING NOTES
  32.  
  33.     Written to be assembled in any memory model with small as the
  34.     default.
  35.  
  36.     Procedures called:
  37.         None
  38.     DOS Interrupts
  39.         Int 21h 40h - Write to file or device
  40.         Int 21h 0ch - Clear input buffer and wait
  41.         Int 21h 01h - Read Keyboard with Echo
  42.  
  43. CAUTIONS
  44.     If selections are combined into a
  45.         mov    ax, Choices
  46.     say for "(y/n)" the values in the initializer must be reverse to
  47.         mov    ax, "ny"
  48. RETURNS
  49.     Carry Flag is set if AH choice is entered by user.
  50.     Carry Flag is clear if AL choice is entered by user.
  51.  
  52. MEMORY REQUIREMENTS
  53.     Model:     Tiny/Small/Compact    Medium/Large/Huge
  54.     Stack:      6 bytes         8 bytes
  55.     Data:      9 bytes         9 bytes
  56.     Code:     55 bytes        55 bytes
  57.  
  58.     All data is kept in DGROUP.
  59.  
  60. AUTHOR
  61.     Raymond Moon - 5 Mar 95
  62.     Copyright (c) 1995, MoonWare
  63.     ALL RIGHTS RESERVED
  64.  
  65. HISTORY
  66.     Version    - Date        - Remarks
  67.     1.00    -  5 Mar 95    - Original
  68.     
  69.     ÷ End of Comment
  70.  
  71. ;----------------------------
  72. ;    Make the small memory model the default.
  73.  
  74. ifndef    memmod
  75. memmod    equ    <small>
  76. endif
  77.  
  78.     include procesor.inc
  79.  
  80. %    .MODEL    memmod,FORTRAN
  81.     assume    es:DGROUP
  82.  
  83. ;-----------------------------
  84. ;    Include files
  85.  
  86.     include stderrf.inc
  87.  
  88. ;----------------------------
  89. ;    Required Stuctures
  90.  
  91. QUERY_S struc
  92. qsOpen    db    "? ("
  93. qsFirst db    ?
  94. qsSep    db    '/'
  95. qsSec    db    ?
  96. qsClose db    "): "
  97. QUERY_S ends
  98.  
  99. ;=========================================================================
  100. ;    DATA
  101. ;=========================================================================
  102.     .DATA
  103.  
  104. QUERY    QUERY_S <>
  105.  
  106. ;=========================================================================
  107. ;    CODE segment
  108. ;=========================================================================
  109.  
  110.     .CODE
  111.  
  112. GetValidChoice    proc
  113. local    Choices:word            ; Automatic storage for Choices
  114.  
  115. ;----------------------------
  116. ;    Save Choices for use later
  117.  
  118.     mov    Choices, ax
  119.  
  120. ;----------------------------
  121. ;    Build Query
  122.  
  123.     mov    QUERY.qsFirst, al    ; Save CF clear choice
  124.     mov    QUERY.qsSec, ah     ; Save CF set choice
  125.  
  126. ;----------------------------
  127. ;    Get the user response
  128.  
  129. GR1:    mov    ax, 0c01h        ; Clear buffer and wait for response
  130.                     ;   with echo
  131.     int    21h            ; Call DOS
  132.  
  133. ;-----------------------------
  134. ;    Process the response
  135.  
  136.     mov    bx, Choices        ; BX = Choices
  137.     or    al, 20h            ; convert to lower case
  138.     cmp    al, bl            ; Is it CF clear choice?
  139.     je    GR2            ; Yes, go to clc code
  140.     cmp    al, bh            ; Is it CF set choice?
  141.     jne    GR4            ; No, invalid response
  142.     stc                ; Yes, set Carry Flay
  143.     jmp    GR3            ; Go to return
  144. GR2:    clc                ; Clear Carry Flag
  145. GR3:    ret                ; Return
  146.  
  147. ;----------------------------
  148. ;    Display query and start again
  149.  
  150. GR4:    @WRITE    QUERY, STDERR
  151.     jmp    GR1
  152.  
  153. GetValidChoice    endp
  154.     end
  155.