home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0417.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-31  |  2.4 KB  |  77 lines

  1. ;***********************************************************
  2. ; Inkey.ASM - A FAR PROC for use in TP4 unit to return
  3. ;             the character and scancode of a pressed key.
  4. ;
  5. ; function InKey(var ScanCode : Byte) : Char;
  6. ;
  7. ; This function use BIOS keyboard function 0h to return the
  8. ; information about the key pressed.  You can compare this
  9. ; to the Turbo CRT's ReadKey, except Inkey always returns
  10. ; the charcaters Ascii value and the scancode.
  11. ;
  12. ; Instead of doing:
  13. ;
  14. ;  Ch := ReadKey;
  15. ;  if Ch = #0 then
  16. ;    ScanCode := Byte(ReadKey);
  17. ;
  18. ; you would:
  19. ;
  20. ;  Ch := Inkey(ScanCode);
  21. ;
  22. ; For keys where the Ascii code is irrelevant (or
  23. ; non-existent) the #0 is returned (just like
  24. ; with ReadKey).  Note that the VAR parameter points to
  25. ; a byte, and the function returns a Char.  Turbo Pascal
  26. ; 4 completely ignores the value in the unused byte of
  27. ; a word.  That's why we need not zero out AH on exit.
  28. ; Also note we take care only to move a byte into
  29. ; ScanCode, since a Pascal type declared as a BYTE is
  30. ; exactly that!
  31. ;
  32. ; NOTE: To save stack usage and speed this function, nothing
  33. ; is pushed on the stack.  The stack frame is set up with
  34. ; BX, a register we may freely use within a TP4 unit.
  35. ; Since there is only one parameter and it is accessed
  36. ; just once we use a SS: segment override with the
  37. ; ScanCode parameter based on our BX stack frame.
  38. ; This saves us the trouble of saving and restoring BP
  39. ; (or anything for that matter).
  40. ;
  41. ; by Richard S. Sadowsky
  42. ;
  43. ;***********************************************************
  44.  
  45. CODE      SEGMENT BYTE PUBLIC
  46.           ASSUME CS:CODE
  47.  
  48.           PUBLIC InKey
  49.  
  50. ; function Inkey(var Scancode : Byte) : Char;
  51.  
  52. ; note the SS: segment override in the following EQU and
  53. ; the use of BX as a stack frame.
  54.  
  55. ScanCode         EQU DWORD PTR SS:[BX+04h]
  56.  
  57.  
  58. InKey            PROC FAR
  59.  
  60.        MOV       BX,SP           ; Set up BX based stack frame
  61.        XOR       AX,AX           ; zero out AX
  62.        INT       16h             ; BIOS Keyboard service 0
  63.        LES       DI,ScanCode     ; ES:[DI] points to var ScanCode
  64.        MOV       ES:[DI],AH      ; copy in scancode returned by BIOS
  65.  
  66. ;  NOTE: AL already contains the Character that was
  67. ;  returned by the BIOS keyboard function, so
  68. ;  we just leave it there (Turbo expects the Char
  69. ;  function result in it).
  70.  
  71.        RET       04h             ; remove parameter and return
  72. InKey            ENDP
  73.  
  74. CODE   ENDS
  75.  
  76.        END
  77.