flat assembler
Message board for the users of flat assembler.
Index
> DOS > Very very simple keyboard input? |
Author |
|
gunblade 06 Apr 2005, 09:59
Code: mov ah, 8 ;non echoed input int 21h ; al now equals the character pressed use mov ah, 1 if you want the input character to be echoed |
|||
06 Apr 2005, 09:59 |
|
Giedrius 06 Apr 2005, 13:01
Thanks. But I need it to be accessed directly (so the program can continue working if no button was pressed) I don't know if there's a simple way of doing that... And I need it to be as fast as it can be.
_________________ Better to rule in hell, than to be a slave in heaven... |
|||
06 Apr 2005, 13:01 |
|
Matrix 06 Apr 2005, 16:52
Hello
please go here there is no simpler way to read keyboard directly, if you're willing to use interrupts, it will be very slow. speed - method fast - directly via keyboard port slow - via bios keyboard handling interrupt very slow - via dos keyboard handling |
|||
06 Apr 2005, 16:52 |
|
Giedrius 06 Apr 2005, 17:00
That's what I was trying to get to work... It didn't work. Maybe I should try again...
|
|||
06 Apr 2005, 17:00 |
|
Dex4u 09 Apr 2005, 17:00
Why not do this:
Code: xor ax,ax in AL,60h test al,10000000b jnz NoKey; Yes a key has been pressed, do some thing hereNoKey:;Carry on with the loop here, as no key pressed let me know if it for a game. |
|||
09 Apr 2005, 17:00 |
|
Giedrius 10 Apr 2005, 10:29
I don't know if you can call it a game, but it needs to be fast. It has significant speed decrease when using your code... I only need it to exit when a key was pressed. Or there's no faster way than this one?
_________________ Better to rule in hell, than to be a slave in heaven... |
|||
10 Apr 2005, 10:29 |
|
f0dder 10 Apr 2005, 11:35
You could set up an interrupt handler for the keyboard IRQ, and handle keys on interrupt rather than keep polling...
|
|||
10 Apr 2005, 11:35 |
|
Giedrius 10 Apr 2005, 13:57
Maybe you could give me an example, or lead me to some guide? I don't know much about assembly programming yet...
_________________ Better to rule in hell, than to be a slave in heaven... |
|||
10 Apr 2005, 13:57 |
|
Dex4u 10 Apr 2005, 17:22
This will replace Dos keyboard interrupt, for yours (call this bit, at start of program)
Code: MOV AL,09h ; Get INT 09h addressMOV AH,35hINT 21hMOV [oldint9],BX ; Save it for laterMOV [oldint9+2],ESMOV AL,09h ; Set new INT 09hMOV DX,Newint9 ; DS:DX = new interruptMOV AH,25hINT 21h This is you new interrupt so do what needs to be done on key press here; Code: Newint9: pusha ;Do some thing here mov al, 0x20out 0x20, al ; If you do something like, jump exit do it here, after the above code. popaIRET This needs calling at end of program Code: ReStoreInt9:MOV AL,09h ; Restore original INT 09hMOV DX,[oldint9]MOV DS,[oldint9+2] ; Move old INT 09H pointer to DS:DXMOV AH,25hINT 21hRET Note: Most of this code is from a TASM Game, i wrote, so may need converting to FASM. You will need to set up var for saving "old INT 09H " eg: oldint9 dd 0 |
|||
10 Apr 2005, 17:22 |
|
Giedrius 10 Apr 2005, 17:45
Thank you!!
Where is the button code stored in the interrupt? And could you explain me what does mov al, 0x20 out 0x20, al do? _________________ Better to rule in hell, than to be a slave in heaven... |
|||
10 Apr 2005, 17:45 |
|
Dex4u 10 Apr 2005, 18:20
When you press a key a interrupt is generated, which jump from your program to some code to deal with the IRQ, at the end of a IRQ you do the above code, so it now its the end.
As for the button code, i left it out as you said you only need to exit on keypress so soon as a key is press it jump to that code, you could try something like this ? Code: Newint9: call Newint9ajmp exitret Code: Newint9a:pusha ;Do some thing here mov al, 0x20out 0x20, al ; If you do something like, jump exit do it here, after the above code. popaIRET I do not know if it will work as its a long time since using dos. at the exit lable you need to call ReStoreInt9 before exiting. |
|||
10 Apr 2005, 18:20 |
|
Giedrius 10 Apr 2005, 18:34
I've done everything that I wanted. Thanks. I only asked for some explanation about it.
_________________ Better to rule in hell, than to be a slave in heaven... |
|||
10 Apr 2005, 18:34 |
|
bubach 11 Apr 2005, 06:32
Code: mov al, 0x20 out 0x20, al = on my forum, Dex4u wrote: There are two types of interrupts a software and a hardware, when you write a "int 21h" you get a software int and when a key is pressed you get a hardware int. And how to actually get the scancodes? Do like this: Code: xor eax, eax ; clear eax in al, 0x60 ; mov scan-code into al test al, 0x80 ; check if it was a press or a release jnz .key_up ; check diffrent keys here: cmp al, 42 ; this checks for a press on the left shift jnz .check_next ; nope, that wasn't pressed, check next .key_up: |
|||
11 Apr 2005, 06:32 |
|
Dilshod 12 Apr 2005, 09:44
Try this:
Code: mov ah,1 int 16h jz .NoKeyPressed mov ah,0 int 16h ;... ;... KeyCode in AX, AL-ASCII, AH-Scan ;... .NoKeyPressed: |
|||
12 Apr 2005, 09:44 |
|
vid 12 Apr 2005, 11:37
|
|||
12 Apr 2005, 11:37 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.