Forum Archive

Go Back   3D Realms Forums > General Topics > Programming Forum
Blogs FAQ Members List Social Groups Calendar Mark Forums Read

Notices

 
 
Thread Tools
Old 06-13-2008, 01:02 AM   #1
Superczar

Superczar's Avatar
Question DJGPP vs. Turbo C
Allright here's a little stumper, I'm going through some tutorials on VGA and the tuts provide both code for compiling under DJGPP and Turbo C. I'm using DJGPP for the time being and I know it does things a little differently. Anyways, the source for one little example program seems to cause a page fault error when runing the program compiled under DJGPP in DOSBox, and this section of code (more specifically the atoi function) is the culprit:



Code:
/* get command-line options */
  if (argc>0) num_objects=atoi(argv[1]);
  if (num_objects<=0) num_objects=8;
Running the program under DOSBox, I only get the error if I don't run the program and put in a number for the argument. Basically it allows you to run the program with an argument (for the # of balls you want to have on the screen), but it seems like it can't handle it when you don't provide one. This is not the case when compiled under Turbo C, as it does what it's supposed to do and that is display 8 balls on the screen if I don't provide an argument...

Another problem with DJGPP-compiled code so far is it's inability to run in a DOS shell under XP. Again not a problem with Turbo C compiled code... But I guess this seems to be a NT/2k/XP-based error that does not support DJGPP's use of near pointers?
__________________
'F*** Fresch!!!'.
Last edited by Superczar; 06-13-2008 at 01:05 AM.
Superczar is offline  
Old 06-13-2008, 01:18 AM   #2
Qbix
DOSBox Advisor

Qbix's Avatar
Re: DJGPP vs. Turbo C
have you tried running it with 8 as parameter ?

and very importantly to which number is num_objects set before those 2 calls ?
Qbix is offline  
Old 06-13-2008, 01:37 AM   #3
Superczar

Superczar's Avatar
Re: DJGPP vs. Turbo C
Num_objects gets initialized to 0 to start with, and yeah if I edit that chunk out and just set num_objects to 8 it runs fine.
__________________
'F*** Fresch!!!'.
Superczar is offline  
Old 06-13-2008, 01:48 AM   #4
Qbix
DOSBox Advisor

Qbix's Avatar
Re: DJGPP vs. Turbo C
the code has to be:
Code:
if(argc>1) num_objects=atoi(argv[1])
Last edited by Qbix; 06-13-2008 at 01:58 AM. Reason: added _objects
Qbix is offline  
Old 06-13-2008, 04:09 AM   #5
Crosma

Crosma's Avatar
Exclamation Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Superczar View Post
Another problem with DJGPP-compiled code so far is it's inability to run in a DOS shell under XP. Again not a problem with Turbo C compiled code...
Turbo C compiles 16-bit real-mode programs and DJGPP compiles 32-bit protected mode programs, so they are very different beasts.

As Qbix said, you've got a memory protection error there. Basically, Turbo C programs have no memory protection, so they can access any non-initialised data they please. Whereas DJGPP programs will crash dead.

I've never had any problems running DJGPP compiled code in Windows NT/XP.
__________________
(define love (lambda () (map conquer all)))
Crosma is offline  
Old 06-13-2008, 04:01 PM   #6
Superczar

Superczar's Avatar
Thumbs up Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Qbix View Post
the code has to be:
Code:
if(argc>1) num_objects=atoi(argv[1])
Yeah that's it, I figured out that, even with no arguments, argc is still equal to 1 (saw the value by printing it to screen before it failed) and yet argv[1] still = 0 though, but thanks Qbix!

Yeah it makes no damn sense why it phails when checking if argc>0 and not checking argc>1, both ways there is still a 0 in argv[1]??? [EDIT AGAIN] Ah n/m I can see why it bombs, there is still no string in argv[1] to convert, unless argc is 2 or greater...

Wonder why it doesn't happen with the same code compiled under Turbo C though?
__________________
'F*** Fresch!!!'.
Last edited by Superczar; 06-13-2008 at 05:47 PM.
Superczar is offline  
Old 06-13-2008, 05:23 PM   #7
Shadow Master

Shadow Master's Avatar
Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Superczar View Post
Another problem with DJGPP-compiled code so far is it's inability to run in a DOS shell under XP. Again not a problem with Turbo C compiled code... But I guess this seems to be a NT/2k/XP-based error that does not support DJGPP's use of near pointers?
I have tried many DJGPP programs (they are 32-bit protected mode programs while Turbo C programs aren't) and they don't crash at all...

Protected mode as provided by DJGPP (using CWSDPMI), simply put, means that a badly written program will be stopped ("crashed") before it screws up the run-time state of your computer, while otherwise (non-protected mode programs) can do anything with it by writing to locations out of their allocated segment. That's also why WinNT/2K/XP/2K3/Vista and Linux are more stable than Win9x.
__________________
You're master of no shadows! -- Steve
Duke Nukem Forever!

[My website | Public Commander Keen Forum | The Commander Keen Wiki]
Last edited by Shadow Master; 06-13-2008 at 05:28 PM. Reason: Made a difference of "protected mode" in this context against the lower-level meaning for system programming...
Shadow Master is offline  
Old 06-14-2008, 02:04 AM   #8
Qbix
DOSBox Advisor

Qbix's Avatar
Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Superczar View Post

Wonder why it doesn't happen with the same code compiled under Turbo C though?
protected mode vs real mode.

in real mode you can access "any" memory even if there is nothing there or if it isn't yours. (there is no protection)

in protected mode you can get an exception when you read memory that isn't yours.
(so if a pointer (as that is argv[1]) points to memory that isn't yours the processor will generate an exception. The os in turn either fires up a debugger or kills your program.)
So the code works by turbo C by accident.
Qbix is offline  
Old 06-15-2008, 03:30 PM   #9
Superczar

Superczar's Avatar
Re: DJGPP vs. Turbo C
Thanks guys, I'll have to keep that in mind when using DJGPP, I think I'm just going to stay with it for compiling. It's nice though to finally find something that shows off how to do gfx instead of the boring old "make an array!" garbage programs that are in my books... not even my C/C++ Programmer's Bible has any info on it...
__________________
'F*** Fresch!!!'.
Superczar is offline  
Old 06-15-2008, 04:12 PM   #10
Qbix
DOSBox Advisor

Qbix's Avatar
Re: DJGPP vs. Turbo C
use a library like SDL or allegro.
Those have easy to use gfx functions.

if you want to use dos graphics you can use allegro I think, although a VGA tutorial exists as well (brackeen has one)
Qbix is offline  
Old 06-15-2008, 04:28 PM   #11
Superczar

Superczar's Avatar
Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Qbix View Post
use a library like SDL or allegro.
Those have easy to use gfx functions.

if you want to use dos graphics you can use allegro I think, although a VGA tutorial exists as well (brackeen has one)
The Brackeen tutorial is one of the ones I am using. And yeah I was planning on doing it in straight up Mode 0x13.
__________________
'F*** Fresch!!!'.
Superczar is offline  
Old 06-15-2008, 06:57 PM   #12
Shadow Master

Shadow Master's Avatar
Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Superczar View Post
Thanks guys, I'll have to keep that in mind when using DJGPP, I think I'm just going to stay with it for compiling. It's nice though to finally find something that shows off how to do gfx instead of the boring old "make an array!" garbage programs that are in my books... not even my C/C++ Programmer's Bible has any info on it...
There are many detailed SDL and Allegro tutorials available in their respective websites, so what's the matter with finding them?
__________________
You're master of no shadows! -- Steve
Duke Nukem Forever!

[My website | Public Commander Keen Forum | The Commander Keen Wiki]
Shadow Master is offline  
Old 06-15-2008, 07:25 PM   #13
Superczar

Superczar's Avatar
Re: DJGPP vs. Turbo C
Well, the Brackeen tutorial is basically what I wanted to get into, something fairly simple and straightforward. The simple game idea I had actually was something secondary to what I mainly wanted to do, and that was be able to display image files (more of a work-related thing). I'll check out Allegro and that as well at some point...
__________________
'F*** Fresch!!!'.
Superczar is offline  
Old 06-15-2008, 08:15 PM   #14
Wooloomooloo

Wooloomooloo's Avatar
Thumbs up Re: DJGPP vs. Turbo C
Brackeen's VGA programming tutorials are very nice. A few years ago I used them to make a VGA version of a Minesweeper game I wrote for a college assignment.
__________________
"I'm an engineer, not a normal person." -Dilbert
Wooloomooloo is offline  
Old 06-15-2008, 08:51 PM   #15
Superczar

Superczar's Avatar
Re: DJGPP vs. Turbo C
Quote:
Originally Posted by Wooloomooloo View Post
Brackeen's VGA programming tutorials are very nice. A few years ago I used them to make a VGA version of a Minesweeper game I wrote for a college assignment.
I wish they would be a little more explanatory in his source code though, he kind of just glances over some of it...
__________________
'F*** Fresch!!!'.
Superczar is offline  
 

Bookmarks

Thread Tools

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


All times are GMT -6. The time now is 05:18 AM.

Page generated in 0.15481496 seconds (100.00% PHP - 0% MySQL) with 16 queries

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.

Website is 1987-2014 Apogee Software, Ltd.
Ideas and messages posted here become property of Apogee Software Ltd.