flat assembler
Message board for the users of flat assembler.

Index > Main > check for a keystroke, not WAIT for a keystroke

Author
Thread Post new topic Reply to topic
Diguidi



Joined: 11 Sep 2009
Posts: 9
Location: France
Diguidi 26 Sep 2009, 15:06
hi everybody ! i've a problem with a little program :

debut:
xor ah,ah
int 0x16

mov dl,al
mov ah,0x2
int 0x21

jmp debut

this program waits for a keystroke and then, displays it to the standard output.

what i want to do now, is to check for a keystroke but not wait for.

i've tried this :

debut:
mov ah,0x1
int 0x16

mov dl,al
mov ah,0x2
int 0x21

jmp debut

the problem is that, instead of show me just one character a time, i have : (if the keystroke is 'a' for example) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
it doesn't stop and i don't know what's going on

if anybody knows something interesting on this, i wait his answer eagerly Smile

Regards,
Post 26 Sep 2009, 15:06
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 26 Sep 2009, 15:12
Diguidi, the problem is that Int16/AH=01 does not remove the keystroke from the buffer. The code you need is something like this:

Code:
get_keystroke:
  mov ah, 1
  int $16
  jz do_something_while_there_is_no_keystroke
; We already have our keystroke but we are going to call Int16/AH=0 to remove it (and get it again)
  xor ah, ah
  int $16
    
Post 26 Sep 2009, 15:12
View user's profile Send private message Reply with quote
Diguidi



Joined: 11 Sep 2009
Posts: 9
Location: France
Diguidi 26 Sep 2009, 15:22
ok we call another function which removes the keystroke from the buffer.

there is no function which clears the buffer only ?

thanks LocoDelAssembly
Post 26 Sep 2009, 15:22
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 26 Sep 2009, 15:42
Not sure but I wouldn't advice it as you may miss some keystrokes that way. If you need a clear procedure then you could use this:
Code:
clear_keystroke_buffer.remove:
  mov ah, 0
  int $16

clear_keystroke_buffer: ; Call here
  mov ah, 1
  int $16
  jnz .remove

  ret    
Post 26 Sep 2009, 15:42
View user's profile Send private message Reply with quote
Diguidi



Joined: 11 Sep 2009
Posts: 9
Location: France
Diguidi 26 Sep 2009, 16:15
ok thanks a lot !
Post 26 Sep 2009, 16:15
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.