Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 20th, 2006, 11:12 AM   #1
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4 Klarre is on a distinguished road
[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
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Aug 20th, 2006, 11:17 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 20th, 2006, 11:27 AM   #3
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4 Klarre is on a distinguished road
I am using Windows XP on a Pentium4 processor. I guess I have to ask the OS for the keyboard events instead then...
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Aug 20th, 2006, 11:38 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Have a look here. If you have further questions, I have some code that gets into this crap to a fair degree.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 20th, 2006, 2:01 PM   #5
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4 Klarre is on a distinguished road
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
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Aug 20th, 2006, 2:39 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 20th, 2006, 2:55 PM   #7
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4 Klarre is on a distinguished road
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
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Aug 20th, 2006, 4:19 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[x86, MASM] Design thoughts Klarre Assembly 0 Apr 2nd, 2006 1:42 PM
[x86 inline]Register needs to be prepared? Klarre C++ 6 Nov 15th, 2005 10:51 AM
how to interrupt an internet stream? bobthe C++ 2 Mar 23rd, 2005 3:39 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:46 AM.

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