'===========================================================================
' Subject: Long Integer Retrieval             Date: 06-16-02 (  :  )       
'  Author: Don Schullian, Jr.                 Code: PBCC                   
'  Origin: d83@DASoftVSS.com                Packet: PBCC.ABC
'===========================================================================
#IF 0
    ----------------------------                       PowerBASIC/cc v2+
 ---|          DASoft          |------------------------------------------
    ----------------------------         Code           DATE: 2002-04-16
    | FILE NAME   fExitKey.bas |          by
    ----------------------------  Don Schullian, Jr.

              This code is released into the Public Domain
       ----------------------------------------------------------
        No guarantee as to the viability, accuracy, or safety of
         use of this code is implied, warranted, or guaranteed
       ----------------------------------------------------------
                         Use at your own risk!
       ----------------------------------------------------------
                  CONTACT AUTHOR AT d83@DASoftVSS.com
 -------------------------------------------------------------------------
 This function is to be used with the return values from fGetKey. The test
 code, included, assumes that you have fGetKey.bas in the same directory.

 Its purpose is to quickly scan a string looking for an included LONG
 INTEGER value.

#ENDIF

FUNCTION fExitKey ALIAS "fExitKey" ( BYVAL ExitKeys AS STRING, _
                                     BYVAL KeyPress AS LONG    ) EXPORT AS LONG

  #REGISTER NONE

  DIM Tlen AS LOCAL LONG

  Tlen = LEN(ExitKeys)

                ! push  edi                     ; save this for later
                ! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ! mov   ecx, Tlen               ; set length of string to be searched
                ! shr   ecx, 2                  ; divide length by 4
                ! jecxz fExetDONE               ; oops! nothing to search for
                ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ! mov   edi, ExitKeys           ; set string address
                ! mov   eax, KeyPress           ; set INTEGER being searched for
                ! repne scasd                   ; find 4byte string in Exet$
                ! jne   fExetDONE               ; if no match found then EXIT FUNCTION
                ! mov   FUNCTION, -1            ; RETURN TRUE
  fExetDONE:    ' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ! pop   edi                     ;

END FUNCTION


#INCLUDE "fGetKey.bas"

FUNCTION PBmain ()

  DIM ExitKeys AS LOCAL STRING
  DIM K        AS LOCAL LONG

  PRINT "Press different keys to see the return values."
  PRINT "Press <ESC> or <F-10> to end program.

  ExitKeys = $ESC_key & $F10_key
  DO
    K = fGetKey
    PRINT "&h" & HEX$(K,6)
  LOOP UNTIL fExitKey(ExitKeys,K)

END FUNCTION
