home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / batdoor.zip / GETKEY_R.ZIP / GETKEY_R.ASM next >
Assembly Source File  |  1986-11-16  |  4KB  |  91 lines

  1. ;
  2. ; GETKEY_R: A remote "get ASCII value of key pressed" for .BAT DOORS users.
  3. ;
  4. ; Courtesy of: The BBS of Excellence (312)398-2872
  5. ;
  6. ; To make this program work under COM2: change the constant(s) as
  7. ; indicated.
  8. ;
  9. cseg    segment  byte public 'CODE'
  10.         assume   cs:cseg,ds:cseg,es:cseg
  11.         org      100h
  12. GETKEY_R proc     near
  13.         jmp      ReadByteWait  ; Skip over constant
  14. ;
  15. LineReg  dw      3FDh       ; for COM1: 2FDh = COM2:
  16. DataReg  dw      3F8h       ; for COM1: 2F8h = COM2:
  17. ;
  18. ReadByteWait:
  19.            Mov     DX,LineReg      ; Get the Line Register address xFDh
  20.            In      AL,DX           ; Get the Line status
  21.            And     AL,01h          ; Isolate data ready bit
  22.            Cmp     AL,01h          ; Is there data ready
  23.            Jz      Get_Remote_Byte ; Yes...clear buffer and exit
  24.            Mov     AH,1            ; Set up status command
  25.            Int     16h             ; Has a local key been pressed ?
  26.            Jz      ReadByteWait    ; No...keep on waiting
  27.            Xor     AH,AH           ; Set up read command
  28.            Int     16h             ; clear the buffer
  29.            Jmp     Validate        ; Validate the entry
  30. Get_Remote_Byte:
  31.            Mov     DX,DataReg      ; Point to the data register
  32.            In      AL,DX           ; Get the data byte
  33. ;
  34. ; Make sure that the key pressed was 1-9 or A-Z (upper case
  35. ; translation is automatic).
  36. ;
  37. Validate:
  38.            Cmp     AL,'1'          ; Is it less than 1?
  39.            Jb      BadEntry        ; Yes...ignore it
  40.            Cmp     AL,':'          ; Is it numeric ?
  41.            Jb      Compare         ; Yes..check for command line compare
  42.            Cmp     AL,'A'          ; Is it alpha ?
  43.            Jb      BadEntry        ; No...ignore it
  44.            Cmp     AL,'['          ; Upper case ?
  45.            Jb      Compare         ; Yes..Check for command line compare
  46.            Sub     AL,32           ; Convert to upper case
  47.            Cmp     AL,'A'          ; Is it Alpha ?
  48.            Jb      BadEntry        ; Yes...Exit
  49.            Cmp     AL,'['          ; Is it Alpha
  50.            Jb      Compare         ; Yes...Check for command line compare
  51. BadEntry:
  52.            Mov     DX,DataReg      ; Point to output port
  53.            Mov     AL,7            ; Get the "bell"
  54.            Out     DX,AL           ; Output the character
  55.            Mov     DL,7            ; Get the "bell"
  56.            Mov     AH,2            ; Setup to output locally
  57.            Int     21h             ; Do it....
  58.            Jmp     ReadByteWait    ; Get a goob byte
  59. Compare:
  60.            Mov     SI,80h          ; point to the command buffer
  61.            Xor     CX,CX           ; Init the loop counter
  62.            Xor     DX,DX           ; Init the work register
  63.            Mov     CL,[SI]         ; Get the input length
  64.            Or      CL,CL           ; Was there no input ?
  65.            JZ      ExitProgram     ; True...then exit
  66. CompareLoop:
  67.            Inc     SI              ; Point past the length
  68.            Mov     DL,[SI]         ; Get the character
  69.            Cmp     DL,' '          ; Is it a blank ?
  70.            Jz      Continue        ; Yes..keep on scanning
  71.            Cmp     DL,'a'          ; Is it lower case ?
  72.            Jb      DoTheCheck      ; No...continue normally
  73.            Sub     DL,32           ; Yes..make it upper
  74. DoTheCheck:
  75.            Mov     DH,1            ; Set up non-blank indicator
  76.            Cmp     AL,DL           ; Is there a match ?
  77.            Jz      ExitProgram     ; Yes..exit program
  78. Continue:
  79.            Loop    CompareLoop     ; Keep on compareing
  80.            Or      DH,DH           ; Was it all blanks ?
  81.            Jz      ExitProgram     ; Yes...the same as no command line
  82.            Jmp     BadEntry        ; No match..ignore entry
  83. ExitProgram:
  84.            Mov     AH,4Ch          ; Prepare for errorlevel
  85.            Int     21h             ; Exit with the ASCII code
  86. GETKEY_R   Endp
  87. CSEG       Ends
  88.            End     GETKEY_R
  89.  
  90.  
  91.