home *** CD-ROM | disk | FTP | other *** search
- ;***********************************************************
- ; Inkey.ASM - A FAR PROC for use in TP4 unit to return
- ; the character and scancode of a pressed key.
- ;
- ; function InKey(var ScanCode : Byte) : Char;
- ;
- ; This function use BIOS keyboard function 0h to return the
- ; information about the key pressed. You can compare this
- ; to the Turbo CRT's ReadKey, except Inkey always returns
- ; the charcaters Ascii value and the scancode.
- ;
- ; Instead of doing:
- ;
- ; Ch := ReadKey;
- ; if Ch = #0 then
- ; ScanCode := Byte(ReadKey);
- ;
- ; you would:
- ;
- ; Ch := Inkey(ScanCode);
- ;
- ; For keys where the Ascii code is irrelevant (or
- ; non-existent) the #0 is returned (just like
- ; with ReadKey). Note that the VAR parameter points to
- ; a byte, and the function returns a Char. Turbo Pascal
- ; 4 completely ignores the value in the unused byte of
- ; a word. That's why we need not zero out AH on exit.
- ; Also note we take care only to move a byte into
- ; ScanCode, since a Pascal type declared as a BYTE is
- ; exactly that!
- ;
- ; NOTE: To save stack usage and speed this function, nothing
- ; is pushed on the stack. The stack frame is set up with
- ; BX, a register we may freely use within a TP4 unit.
- ; Since there is only one parameter and it is accessed
- ; just once we use a SS: segment override with the
- ; ScanCode parameter based on our BX stack frame.
- ; This saves us the trouble of saving and restoring BP
- ; (or anything for that matter).
- ;
- ; by Richard S. Sadowsky
- ;
- ;***********************************************************
-
- CODE SEGMENT BYTE PUBLIC
- ASSUME CS:CODE
-
- PUBLIC InKey
-
- ; function Inkey(var Scancode : Byte) : Char;
-
- ; note the SS: segment override in the following EQU and
- ; the use of BX as a stack frame.
-
- ScanCode EQU DWORD PTR SS:[BX+04h]
-
-
- InKey PROC FAR
-
- MOV BX,SP ; Set up BX based stack frame
- XOR AX,AX ; zero out AX
- INT 16h ; BIOS Keyboard service 0
- LES DI,ScanCode ; ES:[DI] points to var ScanCode
- MOV ES:[DI],AH ; copy in scancode returned by BIOS
-
- ; NOTE: AL already contains the Character that was
- ; returned by the BIOS keyboard function, so
- ; we just leave it there (Turbo expects the Char
- ; function result in it).
-
- RET 04h ; remove parameter and return
- InKey ENDP
-
- CODE ENDS
-
- END