Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from Device I/O Port in ASM??? 1

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
0
0
US
I am sure this is a simple question...
BUT, it is one that I don't know...

I want to use ASM to read the Keyboard device scan codes...

In Qbasic, if anyone is familiar with it, you use INP(96)

this will return several different things...

when you press a key, it returns the scancode for that key...
when you release a key it returns the scancode + 128
-except-
if the key released was the last key pressed, it returns 170

What is the command you can use in ASM? and where is the returned byte assigned... (AX?)

Thnx N Advnc

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Hi CubeE.

The best way (or rather the easiest) is to use an interrupt for retrieving keyscan codes. Int 16 is used for keyboard input...
AH = 00h
Return: AH = BIOS scan code
AL = ASCII character

This interrupt will accept a keypress from the keyboard. For example,
Code:
keyloop:
  mov ah,00h
  int 16h
  cmp al,'A'
  jne keyloop
(Loops until capital 'A' is pressed).
You could use this interrupt in conjunction with subfunction 01 (ah=01h) if you did not want to wait for key press.

There are other ways like direct port I/O, but I would try using these interrupt before using the ports.
Happy programming...
Adonai :)
 
will that read the key relese...???

the whole point of this is for multikey input...

Mostly for gaming...

Say you press "A"
Then you Press "B"
Then you Press "C"

The program Needs to know...
when you Release "B"
when you Release "A"
when you Release "C"

Because there are things that need to happen While The Key Is Pressed... and when there are no keys pressed...

the command I am looking for uses 96 aka 60h
mov AX, 60h
??? AX

This is why I need to use the ports...
Standard input just won't work in this case.

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
OK CubeE, port I/O will be needed.

You could replace the key I/O interrupt with your own version using int 21h (with ax=2509h), or you could use CLI to disable interrupts for the key I/O code, then STI to restore them after. The following code shows some key I/O using ports (this was for a replacement int09 replacement).
Code:
  in al,60h
  mov keyscan,al
  in al,61h  ; port B
  or al,80h  ; enable keyboard access
  out 61h,al ; send confirm bit
  and al,7Fh ; clear confirm bit
  jmp $+2    ; small delay
; NB: 'keyscan' is a DB defined in the data area.
If you want anymore help just post a note and I will show you the code for making this work.

Adonai :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top