Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Help with this little program.

5 views
Skip to first unread message

Rod Pemberton

unread,
Nov 25, 2009, 10:24:08 PM11/25/09
to
"carlos" <cmon...@gmail.com> wrote in message
news:77a6ea74-9e1e-4144...@m3g2000yqf.googlegroups.com...
> Hello, I'm trying to make a little program that do the following:
>
> Check if a key was pressed. If so, return the ascii value of the key.
> Otherwise, returns 0.
>
> I made this code, but I'm can't capturing the ascii value of the
> arrows.
>
> org 100h
>
> mov ah, 11h
> int 16h
> je pre_quit
>

Those lines seems to have no effect on my machine. So, I commented them
out:

; mov ah, 11h
; int 16h
; je pre_quit

> mov ah,8h

After trying to figure out why your code didn't work for a while, I realized
that you probably confused ah=8h with ah=6h. It seems that ah=8h doesn't
check for extended keys. I think what you want is:

kbwait:
mov ah,6h
mov dl,0ffh ; needed to select input

> int 21h

It seems you are missing a wait loop. The function returns ZF set for no
key available. It sets AL=0, if not an extended key. But, you must wait
until a key is available (ZF clear) to check for AL=0... So:

int21h
jz kbwait ; wait for key

> cmp al,0 ; if not extended key
> jnz quit
> int 21h
> jmp quit
>
> pre_quit:
> mov al,0
> quit:
> mov ah,4ch
> int 21h
>

In total, I get this:

org 100h

; mov ah, 11h
; int 16h
; je pre_quit

kbdwait:
; mov ah,8h
mov ah,6h ; read w/extended
mov dl,0ffh ; input
int 21h
jz kbdwait ; wait for key
cmp al,0 ; if not extended key
jnz quit
int 21h
jmp quit

pre_quit:
mov al,0
quit:
mov ah,4ch
int 21h

HTH,


Rod Pemberton
PS. Threw on comp.os.msdos.programmer in case someone there knows how to do
it with ah=8h, or has a better method.


Alex Russell

unread,
Nov 26, 2009, 11:35:05 AM11/26/09
to

According to my docs the jz kbdwait should not be required as int 21
func 08h is supposed to wait for the next key press or return the last
key pressed. My dos machine is lent out so I can't test.

The cmp al, 0 is required to check for extended keys.

int 16h, func 00h also waits.
This func returns scan codes in ah and ascii in al. al will be zero if a
non-ascii key was pressed. This func doesn't require a second call to
get the extended keys


int21 and int16 both have funcs to check for a key being ready to
prevent waits.


Alex

0 new messages