Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   [x86, MASM]Keyboard interrupt (http://www.programmingforums.org/showthread.php?t=11126)

Klarre Aug 20th, 2006 11:12 AM

[x86, MASM]Keyboard interrupt
 
I am trying to create a function that returns keypresses. The problem is that my C++ application that invokes the function crashes on the interrupt instruction. What might be wrong with the code? Have I forgot something? Or is there some sort of conflict with the OS?
:

.586
.model flat, C

.code

getKey proc
        mov ah, 0
        int 16h
        ret

getKey endp

end


Thanks for your help!

/Klarre

DaWei Aug 20th, 2006 11:17 AM

Presuming that you are dealing with a modern OS, rather than one which allows you unrestricted access to the machine, you are going to get slapped down when you try to do certain "raw" things. If you could get your hands on, say, a 286-12, running MSDOS or C/PM or something, you would probably be fine. Lacking that, you are going to have to explore other alternatives. It's pretty obvious, from your code, that you are on an Intel (or compatible) machine. That isn't quite enough information.

Klarre Aug 20th, 2006 11:27 AM

I am using Windows XP on a Pentium4 processor. I guess I have to ask the OS for the keyboard events instead then...

DaWei Aug 20th, 2006 11:38 AM

Have a look here. If you have further questions, I have some code that gets into this crap to a fair degree.

Klarre Aug 20th, 2006 2:01 PM

Quote:

Originally Posted by DaWei
Have a look here. If you have further questions, I have some code that gets into this crap to a fair degree.

Thanks!

I have another question about how the OS prevents me from doing this low-level operations. I tried to read at a specific memory location (0x417, which I have read is in the BIOS data area), to get the status of the keyboard. But executing this piece of code crashes the application. Is this because Windows XP has locked this memory area? Or is it some other reason? I have tried other memory locations without any problems. Can it be like this, that I am only allowed to fetch data from memory locations I have allocated by myself, and unallocated memory?
:

int* key = (int*)0x417;
std::cout << *key << std::endl;

/Klarre

DaWei Aug 20th, 2006 2:39 PM

The OS protects certain areas of memory. If you were allowed entry to them you could easily destroy the system. We used to do this all the time (destroy things, I mean), but we were the only users, and thus the only one punished. It's actually worse than just protecting. Memory is mapped. The physical address is not the address you see in (for example) your debugger. When the next process switches in, it might see the exact same address, but it wouldn't be the same memory. The uP has differing levels of protection. You have to get low to do anything you like. Again, the uP merely makes those capabilities available. The OS (of whatever flavor) uses them to whatever extent the OS designer saw fit to use. Including not at all.

Klarre Aug 20th, 2006 2:55 PM

Seems to me like I have to get down the basement, remove the dust from my old 486 and grab a version of PC-DOS, if I wish to have some fun! ;)

Thanks for your time!

/Klarre

DaWei Aug 20th, 2006 4:19 PM

That might work. The aforementioned 286-12 would definitely set you free. You might also wish to look into getting a SBC of some kind and get into the whole shooting match from scratch.


All times are GMT -5. The time now is 3:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC