Re: INT 16h Equivalent Calls in Windows?



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

.



Relevant Pages

  • Re: Linux, X, ld, gcc, linking, shared libraries and stuff
    ... > If someone would like to create a simple windows program which creates a ... mov D$WindowClass@hInstance, eax ... push &IDC_ARROW ...
    (alt.lang.asm)
  • Re: File I/O using NASM in 32-bit mode
    ... My Windows drive just died, ... extern CreateFile ... push 80000000h; READ_ONLY ... test eax, eax ...
    (alt.lang.asm)
  • Re: A (mild-mannered) defense of RosAsm
    ... are a lot of characters that *don't* want to be altered. ... clueless in Windows, and not really too interested in learning it. ... Linux, I think the arrow keys return "ESC" ... push a single byte onto the stack - no such instruction! ...
    (alt.lang.asm)
  • Re: Yay!
    ... I'd like to switch because the security ops group has started using SMS to push updates to Windows machines and I've been forced to reboot in the middle of the day, and while updates are being pushed my computer is useless. ... They even push MS Office and other garbage patches during the day and every update causes Windows to want to reboot. ...
    (rec.pets.cats.anecdotes)
  • Re: bits 32 oddities in NASM
    ... extender or switch to pm yourself - and *then* dos interrupts won't work... ... stupid people who try to write DOS in Windows. ... without resorting to the C library or the evil Win32 API. ...
    (alt.lang.asm)