Question

I want to direct a shape in assembly language using arrow keys, my code is like this:

call getkey
cmp al, ...
je direct

what should I put after al to diagnose which arrow key does the user push?

Was it helpful?

Solution 2

The keyboard buffer is at segment 0, offset 1054 (41E hex)

http://webcache.googleusercontent.com/search?hl=en-GB&q=cache:HTLtXndIlCQJ:http://support.microsoft.com/kb/60140%2Bdos+keyboard+buffer+location&gbv=2&ct=clnk

downarrow is 0150

uparrow is 0148

left arrow is 014B

right arrow is 014D

OTHER TIPS

This works fine for me in DOS (tested under DOSBox):

[org 0x100]

repeat:
; Get keystroke
mov ah,0
int 0x16
; AH = BIOS scan code
cmp ah,0x48
je up
cmp ah,0x4B
je left
cmp ah,0x4D
je right
cmp ah,0x50
je down
cmp ah,1
jne repeat  ; loop until Esc is pressed

mov ah,0x4c
int 0x21

up:
mov dx,upstring
mov ah,9
int 0x21
jmp repeat

down:
mov dx,downstring
mov ah,9
int 0x21
jmp repeat

left:
mov dx,leftstring
mov ah,9
int 0x21
jmp repeat

right:
mov dx,rightstring
mov ah,9
int 0x21
jmp repeat

upstring db "Up pressed",13,10,'$'
downstring db "Down pressed",13,10,'$'
leftstring db "Left pressed",13,10,'$'
rightstring db "Right pressed",13,10,'$'

If you can't / don't want to use int 0x16 (e.g. because you need the read to be non-blocking) you could try reading from port 0x60 instead.

Considering al contains key value, compare the key value with ascii value of the arrow you want. Try following ascii values 37(left arrow) 38(up arrow) 39(right arrow) 40(down arrow)

I remember in DOS using 16h (or 21h) interrupt provided you 0 the first time and then you would of have to read key once more to get an actual code. The same was with functional keys and things like "insert" or "home". Only keys that could be mapped to ASCII were comming directly in one interrupt call. Maybe this applies here too.

It depends on what you do for key detection in getkey function. Mostly if you do direct hardware access then the keys are returned in scan codes. You should look for scan codes table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top