programmers resources
  http://www.intel-assembler.it/  (c)2017 intel-assembler.it   info@intel-assembler.it
 
Search :  
Lingua Italiana    English Language   
Index
 
just an empty assembly space
just an arrow Intel Platform
just an arrow Article & Guides
just an arrow Download Software


23/01/2009 Featured Article: How to remove Buzus Virus (permalink)




:::3097544:::
Bottone Scambio Directory Pubblicitaonline.it
Home Page | Articles & Guides | Download | Intel Platform | Contacts

Google
 


Bookmark and Share
Download 
Tell a friend



Keyboard Management Library

An x86 source code for keyboard handling

(by sean werkema)

A BIOS-like level handling for the keyboard. This x86 library offers a set of functions to handle the keyboard including extended codes. It must be assembled using Eric Isaacson's A86 assembler (not with TASM or MASM).
This article is online from 2538 days and has been seen 3976 times





_KEYBOARD SEGMENT PARA PUBLIC 'CODE'

;------------------------------------------------------------------------------
; KEYBD.86
; BIOS keyboard access subroutines
; Copyright (C) 1994 by Sean Werkema
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; C Language Interface
;------------------------------------------------------------------------------

KEYSCAN:       DW      0
KEYASCII:      DW      0

; int GetCursorStart (void)
;      Returns value corresponding to top of cursor, usually 0-7.

        PUBLIC  _GetCursorStart

_GetCursorStart:
PUSH BP
MOV AH,03
XOR BH,BH
        INT     10h
MOV AL,CH
XOR AH,AH
        POP     BP
RETF

; int GetCursorEnd (void)
;      Returns value corresponding to bottom of cursor, usually 0-7.

        PUBLIC  _GetCursorEnd

_GetCursorEnd:
PUSH BP
MOV AH,03
XOR BH,BH
        INT     10h
MOV AL,CL
XOR AH,AH
        POP     BP
RETF

; void SetCursorSize (int top, int bottom)
;      Adjusts cursor size to top and bottom values (usually from 0-7).

        PUBLIC  _SetCursorSize

_SetCursorSize:
PUSH BP
MOV BP,SP
MOV CL,[BP+8]
MOV CH,[BP+6]
MOV AH,01
INT 10h
        POP     BP
RETF

; int GetCursorX (int page)
;      Returns horizontal position of cursor, ranging from 1 to <scrn width&
gt;.
;      If page is -1, the currently displayed page will be used.

        PUBLIC  _GetCursorX

_GetCursorX:
PUSH BP
MOV BP,SP
MOV BH,[BP+6]
CMP BH,-1
JNE >L1
MOV AH,0F
INT 10h
L1: MOV AH,03
INT 10h
MOV AL,DL
XOR AH,AH
INC AX
        POP     BP
RETF

; int GetCursorY (int page)
;      Returns vertical position of cursor, ranging from 1 to <scrn height&g
t;.
;      If page is -1, the currently displayed page will be used.

        PUBLIC  _GetCursorY

_GetCursorY:
PUSH BP
MOV BP,SP
MOV BH,[BP+6]
CMP BH,-1
JNE >L1
MOV AH,0F
INT 10h
L1: MOV AH,03
INT 10h
MOV AL,DH
XOR AH,AH
INC AX
        POP     BP
RETF

; void SetCursorPos (int page, int X, int Y)
;      Moves cursor to specified coordinates, with the origin at 1.
;      If page is -1, the currently displayed page will be used.

        PUBLIC  _SetCursorPos

_SetCursorPos:
PUSH BP
MOV BP,SP
        MOV     BH,[BP+10]
        CMP     BH,-1
JNE >L1
MOV AH,0F
INT 10h
L1: MOV DL,[BP+6]
MOV DH,[BP+8]
DEC DL
DEC DH
        MOV     AH,02
INT 10h
POP BP
RETF

; int ReadKeyASCII (void)
;      Waits for a key to be pressed, then returns the ASCII value of that
;      key.  KeyASCII and KeyScan are set to the key's ASCII value & scan code.

        PUBLIC  _ReadKeyASCII

_ReadKeyASCII:
PUSH BP
PUSH DS
        XOR     AH,AH
INT 16h
MOV BX,SEG _TEXT
MOV DS,BX
MOV [KEYASCII],AL
MOV [KEYSCAN],AH
        XOR     AH,AH
POP DS
        POP     BP
RETF

; int ReadKeyScan (void)
;      Waits for a key to be pressed, then returns the scan code of that
;      key.  KeyASCII and KeyScan are set to the key's ASCII value & scan code.

        PUBLIC  _ReadKeyScan

_ReadKeyScan:
PUSH BP
PUSH DS
        XOR     AH,AH
INT 16h
MOV BX,SEG _TEXT
MOV DS,BX
MOV [KEYASCII],AL
MOV [KEYSCAN],AH
        MOV     AL,AH
XOR AH,AH
POP DS
        POP     BP
RETF

; int KeyStatus (void)
;      Returns 1 if a keypress is waiting, and 0 if no keypress is waiting.  If
;      1, KeyASCII and KeyScan are set to the key's ASCII value & scan code.

        PUBLIC  _KeyStatus

_KeyStatus:
PUSH BP
PUSH DS
MOV BX,SEG _TEXT
MOV DS,BX
        MOV     AH,01
INT 16h
        JZ      >L1
MOV BL,1
DB 03D ;Trick to "skip" next instruction, which becomes
L1: XOR BL,BL ;  a CMP AX,value
XOR BH,BH
MOV [KEYASCII],AL
MOV [KEYSCAN],AH
MOV AX,BX
        POP     DS
        POP     BP
RETF

; int KeyFlags (void)
;      Returns keyboard flags: L Shf, R Shf, Ctrl, Alt, Caps, Num, Scrl, Ins.

        PUBLIC  _KeyFlags

_KeyFlags:
PUSH BP
MOV AH,02
INT 16h
XOR AH,AH
POP BP
RETF

; int EReadKeyASCII (void)
;      Waits for a key to be pressed, then returns the ASCII value of that
;      key.  KeyASCII and KeyScan are set to the key's ASCII value & scan code.
;      Same as ReadKeyASCII, except can detect extended keys.

        PUBLIC  _EReadKeyASCII

_EReadKeyASCII:
PUSH BP
PUSH DS
MOV AH,010
INT 16h
MOV BX,SEG _TEXT
MOV DS,BX
MOV [KEYASCII],AL
MOV [KEYSCAN],AH
        XOR     AH,AH
POP DS
        POP     BP
RETF

; int EReadKeyScan (void)
;      Waits for a key to be pressed, then returns the scan code of that
;      key.  KeyASCII and KeyScan are set to the key's ASCII value & scan code.
;      Same as ReadKeyScan, except can detect extended keys.

        PUBLIC  _EReadKeyScan

_EReadKeyScan:
PUSH BP
PUSH DS
MOV AH,010
INT 16h
MOV BX,SEG _TEXT
MOV DS,BX
MOV [KEYASCII],AL
MOV [KEYSCAN],AH
MOV AL,AH
XOR AH,AH
        POP     DS
        POP     BP
RETF

; int EKeyStatus (void)
;      Returns 1 if a keypress is waiting, and 0 if no keypress is waiting.  If
;      1, KeyASCII and KeyScan are set to the key's ASCII value & scan code.
;      Same as KeyStatus, except can detect extended keys.

        PUBLIC  _EKeyStatus

_EKeyStatus:
PUSH BP
PUSH DS
MOV BX,SEG _TEXT
MOV DS,BX
MOV AH,011
INT 16h
        JZ      >L1
MOV BL,1
DB 03D
L1: XOR BL,BL
XOR BH,BH
MOV [KEYASCII],AL
MOV [KEYSCAN],AH
MOV AX,BX
        POP     DS
        POP     BP
RETF

; int EKeyFlags (void)
;      Returns keyboard flags: L Shf, R Shf, L Ctrl, R Ctrl, L Alt, R Alt,
;      Caps, Num, Scrl, Ins, SysReq.
;      Same as KeyFlags, except can detect extended keys.

        PUBLIC  _EKeyFlags

_EKeyFlags:
PUSH BP
MOV AH,012
INT 16h
POP BP
RETF

; int IsEKeybd (void)
;      Returns 0 if not an Extended Keyboard, 1 if is an Extended Keyboard.

        PUBLIC  _IsEKeybd

_IsEKeybd:
PUSH BP
        MOV     AH,05
MOV CX,0FFFF
INT 16h
MOV CX,16
L1: MOV AH,010
PUSH CX
        INT     16h
POP CX
        CMP     AX,0FFFF
JE >L2
LOOP L1
XOR AL,AL
DB 03D
L2: MOV AL,1
XOR AH,AH
        POP     BP
RETF

PUBLIC _KeyASCII

_KeyASCII:
PUSH DS
MOV AX,SEG _TEXT
MOV DS,AX
MOV AX,[KEYASCII]
        POP     DS
RETF

PUBLIC _KeyScan

_KeyScan:
PUSH DS
MOV AX,SEG _TEXT
MOV DS,AX
MOV AX,[KEYSCAN]
        POP     DS
RETF




Top
Download 
Tell a friend
Bookmark and Share



Similar Articles

Assembler Keyboard Handler INT9 IRQ1
An assembly source code for keyboard handling
(by hamell@cs.pdx.edu)

Capture CTRL+ALT+DEL in assembly
Source code for capturing keys under windows
(by Daniel J. Reynolds)

Programming the Keyboard
A short guide on keyboard handling in asm
(by Mark Feldman)

 Tags: keyboard


webmaster jes
writers rguru, tech-g, aiguru, drAx

site optimized for IE/Firefox/Chrome with 1024x768 resolution

Valid HTML 4.01 Transitional


ALL TRADEMARKS ® ARE PROPERTY OF LEGITTIMATE OWNERS.
© ALL RIGHTS RESERVED.

hosting&web - www.accademia3.it

grossocactus
find rguru on
http://www.twitter.com/sicurezza3/
... send an email ...
Your name

Destination email

Message

captcha! Code