home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bm_rm.zip / GETKEYN.ASM < prev    next >
Assembly Source File  |  1989-08-16  |  2KB  |  62 lines

  1. ;getkeyn() - Get the next keystroke, echo it, and print a newline.
  2. ;
  3. ;Syntax: int getkeyn (void);
  4. ;
  5. ;We return the high byte as 0 for normal characters, 0xFF for special chars.
  6. ;The character itself is returned in the low byte.
  7. ;
  8. ;Copyright (C) 1989 Brian B. McGuinness
  9. ;                   15 Kevin Road
  10. ;                   Scotch Plains, NJ 07076
  11. ;
  12. ;This function is free software; you can redistribute it and/or modify it under 
  13. ;the terms of the GNU General Public License as published by the Free Software 
  14. ;Foundation; either version 1, or (at your option) any later version.
  15. ;
  16. ;This function is distributed in the hope that it will be useful, but WITHOUT 
  17. ;ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  18. ;FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  19. ;details.
  20. ;
  21. ;You should have received a copy of the GNU General Public License along with 
  22. ;this function; if not, write to the Free Software Foundation, Inc., 675 Mass 
  23. ;Ave, Cambridge, MA 02139, USA.
  24. ;
  25. ;Version 1.01          August, 1989          MASM 5.1
  26.  
  27.         DOSSEG
  28.         .MODEL small,C 
  29.         .CODE
  30.  
  31. getkeyn proc uses dx
  32.         mov ah,8        ;Get keystroke in AL.
  33.         int 21H
  34.         xor ah,ah
  35.         mov dl,al
  36.  
  37.         or al,al        ;Is it an extended keycode?
  38.         jnz @F
  39.  
  40.         mov ah,8        ;Yes, so get second half.
  41.         int 21H
  42.         mov ah,0FFH     ;Flag it as a special character.
  43.  
  44. @@:     push ax         ;If nonprinting char, don't print it.
  45.         cmp ax,32
  46.         jb crlf
  47.         cmp ax,127
  48.         jae crlf
  49.  
  50. @@:     mov ah,2        ;Print character (or blank for a special char).
  51.         int 21H
  52.  
  53. crlf:   mov ah,2        ;Print CR, LF.
  54.         mov dl,13
  55.         int 21H
  56.         mov dl,10
  57.         int 21H
  58.         pop ax
  59.         ret
  60. getkeyn endp
  61.         end
  62.