DPMI and how to make it work

This is a discussion on DPMI and how to make it work within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Resume: I'm trying to understand how to do DPMI programming. My problem is that i can't understand how to switch ...

  1. #1
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101

    DPMI and how to make it work

    Resume:

    I'm trying to understand how to do DPMI programming. My problem is that i can't understand how to switch to DPMI. The readon i am so interested in this is because when i run my programms from within the IDE ( Borland C++ 3.1 ) everything works fine, but when i run the executable from outside the compiler some things don't work ( Like reading from certain files ).
    I also tried to understand how to use Dos4gw but had no success.

    anyone out there with some source code or TSR to help a poor programmer...?

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    you need a memory extender like dos4gw... cwsdpmi is an option. i use djgpp and it uses cwsdpmi to provide flat memory access... it automatically provides the access per compile time so i dont' think doing it manually is the best option. i tried and tried to get it like that before finding djgpp, but it's really just redundant, you've got a lot of interrupts and switching to protected/real mode can be a hassle, learning about transfer buffers and all sorts of error-prone stuff... if you are really curious, then check out www.delorie.com/djgpp for the compiler, it's 32-bit, quite nice... and dos... so...

    and a search on your favorite engine for extended memory access and mode switching'll do you nicely as well... let me know how this goes okay?

    hth...
    hasafraggin shizigishin oppashigger...

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Yes, popping in to protected mode and then back to real-mode is not something you want to get into (unless you know what you are doing), and I don't think it can be done in C/C++. EMS is very easy to use, but it only allows access to 32MB. XMS is much different, and slower, but allows more access. But XMS must be accessed via a function pointer and you must query XMS for the address of it's control handler.

    Also, query EMS/XMS before you try to go using them. EMS will lock your system up if you do not use it correctly (XMS will too)
    Remember to unlock your memory handles and free them as well. If you are in a DOS shell and forget to do this, it is possible that Windows will not restore correctly.

    Their are some websites that have the DPMI and DPMI32 specs. Do a search and you'll find a ton of info.

    Overall, DJGPP is the best way to go. Certain memory accesses can be quite confusing (the docs are confusing and vague - within RHIDE). Your programs may run within RHIDE, but not outside of it - similar to your problem. Just make sure all your pointers are pointing at the right thing and that you do not overrun your array bounds - ever. If you do, future data will be corrupted and correct code will not even function correctly since the memory has been trashed. DJGPP is even pickier about pointers than Borland/Microsoft C++ or at least that seems to be the case.

  4. #4
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101

    Smile

    Thanks a lot for the tip. I downloaded the DjCpp compiler. My personal objective observations are that (1) it doesn't have an IDE and im not used to programming in notepad yet and (2) i couldn't find the Gcc.exe file which is probably the Gcc from Linux ported to Win32 platforms or something like that. But thanks anyways... I still have these bugs with the BC 3.1 compiler. I think it's a memory problem though. Im not very good at memory handling yet. Im just using the BGI driver so far. If any one has a video driver better please tell me about it ---- that would REALLY help a LOT!!!
    Are there any better compilers for DOS than the BC?

    Thanks, a lot guys...
    Last edited by Sunny; 11-29-2001 at 06:06 AM.

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    unfortunately i never got into bgi... rather, i started with 13h [320x200x8bit] modes for graphics... and used pixel pushing... but as soon as i got DJGPP to work out, i looked for access to higher resolution/color VESA modes... i recommend getting DJGPP to work out... i never had the problem of obtaining or using gcc or gpp... if you do, bubba and i can help you set it all up... PM us if you like...

    and, i use the editor i got from BC45... and i don't like text based editors... [RHIDE/EMACS] even though they are specifically designed around DJGPP... perhaps you can use Dev-C++ just for it's editor if you can't find another one...

    perhaps you forgot to check the language[s] to use in the zip picker...
    hasafraggin shizigishin oppashigger...

  6. #6
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101
    Ok. Still looking for the GCC.exe file. I seem to like the DJGpp compiler.. From the examples i've looked at for the source it seems real nice. The host ftp address from where i downloaded it
    was very vague - i mean it didn't have all the files stored in one pachet or zip file. They let me choose which files i need to download. Ill look again and see if i can find it allthough i don't think i noticed it last time... I tried Dev C++ but because i am using Win 95 PE which has a GREAT deal of bugs i can't even launch the software. But ill go for using a simple editor is fine for me. As long as i can compile easily...That is: if i ever succeed to compile...:P

    Later on i will need however some tips on how to handle graphics with this compiler...

    Anyways thank you very much one again
    Yes...YES!!! I did it! Ha ha ha...I'm king of the world...No..No..please-wait-no...!!!!-- This program has performed an illegal operation AND WILL be shut down....Ack-Choking..help...ack..

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    speaking of editors... JFE [Jens' File Editor] is something to look at... i haven't gotten everything i want to work with it just yet... but so far so good... check the general discussions board for links to it...
    hasafraggin shizigishin oppashigger...

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    DJGPP does have an editor. Download RHIDE from www.delorie.com. It has a fairly extensive help file, too. There are some minor bugs that have popped up, but nothing that has threatened my source.

    Borland may have a patch on their website for your compiler, although it has been included as part of their Turbo C++ suite of compilers. Last time I looked, they only had patches for versions 4.52+ and BCB.

    I still don't know why you need the DPMI (Borland C++ 3.1 I believe is a real-mode compiler) to do what you want. File access should not be based on what mode the processor is running in. An open in DJGPP is an open in real mode C. All they are doing is calling DOS int 21h to open the file. The major difference is that the CWSDPMI handles the interrupt, switches to real and back to protected, for DJGPP and DOS directly handles the interrupt call in real mode.

    I'm pretty sure that the RHIDE docs inform you that interrupts in DJGPP might be slower than in a real-mode compiler. File i/o should not be done via interrupts but via the C I/O system. If you are bypassing the I/O system in C, you are defeating yourself.

    I need more info about what you are trying to do and why.

  9. #9
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101
    Ok. Thanks anyways. My current problems are - don't get panicked now... - Im having problems configuring the DjGpp to work- downloading Gcc.exe. The reason i was enquiring about DPMI is because i thought my problem was memory related, and i think i need a memory extender. Somehow i don't think my program uses more than 640k from phisical
    ram, but im not sure about that. It's 'cause when i open a file , read something, then close, i can't repeat the process. It tells me that either the file doesn't exist, or the internal pointer doesn't read the objects properly. I am running in graphics mode through the BGI driver- which i hate now- on a high resolution of 640x480 with a mouse loop that uses double buffering for redrawing. Thanks a lot for the tip on RHIDE. Ill look for it. I hope it's not to big for downloading... :P
    Should i consider enquiring also about WATCOM C++ ? I mean, i heard it's good. What do you guyz think about it?


    Thanks a lot again,
    Sunny
    Last edited by Sunny; 12-05-2001 at 02:59 AM.
    Yes...YES!!! I did it! Ha ha ha...I'm king of the world...No..No..please-wait-no...!!!!-- This program has performed an illegal operation AND WILL be shut down....Ack-Choking..help...ack..

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    That's one compiler I've not looked at too much. Been to the website, but I don't enjoy downloading crippled versions of compilers or demo versions. DJGPP is awesome and the code speed is comparable to many commercial compilers. Rumor has it that MSVC overall has the fastest code and BCB is a bit easier to program GUIs. In the DOS world, DJGPP reigns because it is the only free PM compiler out there.

    Your code should be using memory above 640KB especially if you are in DJGPP. In order to access lower memory you have to do a bunch of pointer stuff and make calls to CWSDPMI so I'm sure that your code is way above 640KB. I've never had a file handle become corrupt on me. Perhaps in your read() function you are passing the pointer incorrectly. Which I/O file functions are you using? read();open();fopen();fread() ? Streams or no streams?

  11. #11
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101
    Ok. I downloaded the gcc.exe binaries. But i have problems compiling programs with it. Do i have to use the gcc? because every time i do, i get fatal: enviornment variable not installed correctly. This gcc is so darn complicated. I just unzipped the files manually to a directory from each zip file, but no one told me about configuring any files to make it run. And i still can't find RHIDE - if you coud..er..give me a more specific URL plz...


    Thanks a lot...




    Sunny

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Here is the page where you can get RHIDE for DJGPP.
    Just check the box next to RHIDE.

    Also if you are using DJGPP, read the huge FAQ. It's bothersome to read on the computer, but it does contain a lot of helpful info - particularly relating to memory access in protected-mode.

    You must have this in your autoexec.bat. DJGPP is the directory you installed it into - cannot be called DEV or it won't work.

    set DJGPP=c:\DJGPP\DJGPP.ENV

    This should stop the environment error.


    Here is the link for RHIDE, Allegro, and other utils for DJGPP.

    http://www.delorie.com/djgpp/zip-picker.html

  13. #13
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101
    Ok... Feeling much better now... Just spent 3 quarters of my day reinstalling Windows, then configuring the modem, then the rest of the day making my sound card to work by tweaking the inf files - almost reediting them .... That was NOT fun...:P

    So much for Plug & Play.....

    Buth ayways... Things are geting better, like i always say...
    So yeah... Thanks a lot for the enviornment setting... I would've never guessed that myself.... Ok. and ill check out RHIDE Too....
    I just installed Dev C++ 4.0 . Looks pretty good. I noticed though that you cannot make standalone DOS Applications, but only Windows Consoler. What do you guys think about Dev so far? Worth any shots?


    The function i was using for reading from the file was 'fopen()', in text mode, and then i tried using

    Byte *buffer; // as in unsigned char *buffer
    scanf( f, "%s", buffer); //<-- has a problem on second
    //reading i think...



    Thanks a lot,
    Sunny

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I just downloaded the Watcom compiler and checking it out. The old DOS4GW used to be the extender for it, but they've changed it to another. Haven't used Dev-c yet.

  15. #15
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101
    Dev C++ Is pretty great, but it's only good for windows programming. It's not bad at all... But you can't even do assembly interrupts with it, because it only compiles to DOS consoles.... I've been tryying to do DOS programming for quite a few years now and i really wonder if anyone actually would still use a dos program nowadays... sad... *sigh*...


    Yes, i've been looking for the WATCOM compiler too for quite a while. How is it? How big is it? And could u pleeezzzeee give me the URL too? I don't have such a fast internet connection though ( 6k/s )....

    Thanks ...


    Sunny

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21