Re: INT 16h Equivalent Calls in Windows?
- From: Frank Kotler <spamtrap@xxxxxxxxxx>
- Date: Tue, 22 Jan 2008 14:28:32 GMT
bwaichu@xxxxxxxxx wrote:
I'm trying to work through some exercises in an old assembler book I
have by Kip Irvine, and I'm trying to figure out the keyboard
interrupts. Unfortunately, these do not appear to work under windows.
What are my options for low level calls in windows to do the keyboard
exercises without calling C functions? Is there an alternative
interrupt I can call?
There *are* interrupts involved with Windows, but for practical purposes, "we" can't use 'em, and wouldn't want to if we could (highly version-specific, I understand).
I'm not familiar enough with Mr. Irvine's books to know which interrupts you're looking at. There's bios int 16h... and then there's the hardware interrupt generated when the user presses a key (or releases it), and the interrupt handler that processes it into something a program can use - typically int 9. In dos, we can replace the "int 9 handler" with our own, if we wish. In Windows (Linux/BSD), the hardware interrupt is still generated, and still needs to be handled, but the handler probably isn't on "int 9", and is 32-bit code. We don't have direct access to it (for practical purposes). We may be able to achieve the same effect with a "low level" API, however.
What are you trying to do?
One issue I've encountered is "press any key to continue". If you do this with ReadFile from STDIN with a count of 1, you have to change the prompt to "press any key, as long as it's 'Enter'..." :) We might like to "get just one key", and compare it to 'y', 'n', or whatever.
One way to do this is with GetConsoleMode/SetConsoleMode. I don't know if this is the "right" way to do it... this is "cargo cult programming" - I copied it from something Herbert showed us...
;-------------------------
getc:
push edx
push eax ; this is our "buffer"
xor eax, eax
add eax, [read_handle]
jnz .gothandle
push byte STDIN
call [GetStdHandle]
mov [read_handle], eax
push dword mode
push eax
call [GetConsoleMode]
and byte [mode], 11111001b
push dword [mode]
push dword [read_handle]
call [SetConsoleMode]
..gothandle:
mov eax, esp
push byte 0
push num_chars
push byte 1
push eax
push dword [read_handle]
call [ReadFile]
or eax, eax
jnz .goodread
mov esi, badreadmsg
call putz
push eax
call [ExitProcess]
..goodread:
pop eax ; get "buffer" into al
pop edx
ret
;---------------------------
A little research at MS ought to give you some idea what that bit patter means, and what your options are. There are a number of "Console"-related APIs that may give you the keyboard control you can get with interrupts in dos.
When you get into a "real Windows program" - a GUI in which you "own" one or more Windows - your program has a different layout. Essentially, we sit waiting for the phone to ring. Windows sends us a "message" about any keyboard/mouse event that "belongs" to us. In this case, I think you can examine the message structure to see just what key was pressed - dunno how things like "up arrow" are presented... If you want to "stuff" the keyboard buffer, you may need SendMessage(???)...
So while you won't be using interrupts, there "should" be a way to "do the same thing" in Windows.
Best,
Frank
.
- Follow-Ups:
- Re: INT 16h Equivalent Calls in Windows?
- From: dave
- Re: INT 16h Equivalent Calls in Windows?
- References:
- INT 16h Equivalent Calls in Windows?
- From: bwaichu@xxxxxxxxx
- INT 16h Equivalent Calls in Windows?
- Prev by Date: Re: INT 16h Equivalent Calls in Windows?
- Next by Date: Re: INT 16h Equivalent Calls in Windows?
- Previous by thread: Re: INT 16h Equivalent Calls in Windows?
- Next by thread: Re: INT 16h Equivalent Calls in Windows?
- Index(es):
Relevant Pages
|