PDA

View Full Version : Tutorial #2: Compiling your first SDL game



MetaFox
April 5th, 2005, 23:25
EDIT (4/6/05): Upgraded tutorial to use KOS 1.3.x instead of 1.2.0. Uploaded a new makefile to coincide with these changes.

EDIT (4/5/05): Mental2k suggested adding comments as to what's being done in the steps. This is a good idea, so I'm updating the tutorial series with comments. Comments will be shown in red.

These tutorials should help you get started with Dreamcast development, even if you haven't coded before in your life. I'm trying to make these as newbie friendly as possible, so if you have any trouble with these, post here and let me know, so I can update them as appropriate. Here's part 2, compiling an SDL game:

1) Run a command prompt (cmd.exe, command.com depending on your version of Windows)

2) Type cd\cygwin

3) Type cygwin.bat

4) Once inside cygwin,
a) Type cd /usr/local/dc/kos1.3/kos The KOS directory
b) Type source environ.sh This loads the dcdevelopment environment variables.

5) Find a simple SDL port (for our usage right now - it should be pure SDL with no other libraries - no SDL_mixer, etc.).
a) For our purposes, grab http://www.consolevision.com/members/metafox/dreamcast/pong.zip (from gameprog.it)
b) extract it's contents to c:\cygwin\usr\local\dc\kos1.3\kos

6) now:
a) download http://www.consolevision.com/members/metafox/dreamcast/makefile.zip
b) Extract to c:\cygwin\usr\local\dc\kos1.3\kos\pong (overwrite the previous makefile) This is a makefile template. It's easy to update it for your own purposes for other ports.

7) edit makefile to change all instances of .o extensions to match every .c in the directory:
- so if you have main.c control.c game.c menu.c
- you'd have main.o control.o game.o menu.o in your makefile (don't change the .c files themselves, the .o files are just for the object files in the makefile) The .o extension stands for object files. The compiler processes the C code and outputs an object file with an .o extension

8) look for the main function - could be main() or main(argc, argv) - or something else in the parenthesis.
a)After the main function, there should be a bracket {
b)After the bracket, add fs_chdir("/cd"); This sets up the main directory as /cd/ rather than / so that the Dreamcast will recognize it.

9) Open up all the files and look for SDL_SetVideoMode
a) make sure the width is either 640 or 320 and the height is 480 or 240, and that SDL_FULLSCREEN is initialized.
- ex: SDL_SetVideoMode(640, 480, 8, SDL_FULLSCREEN) This sets up the screen size to a Dreamcast compatible screen size. 320x240 and 640x480 are the only ones that should be used on SDL for KOS. KOS supports more resolutions, but SDL KOS only supports 3 of those - the 800x600 resolution that SDL KOS supports is only available on VGA monitor setups.

10) Now, in cygwin:
a) type cd /usr/local/dc/kos1.3/kos/pong
b) type make This command processes your makefile, and sets the compiler in motion to process the c files to object files, then finally to link the object files together into a Dreamcast-compatible elf file.

Congratulations! You should now have an elf file which is now a workable SDL port. :)

You can do this for just about every SDL game that you find. Some are more difficult, but most just require these steps. This doesn't have controller support, or any other Dreamcast specific stuff. We'll look at some of that in tutorial #3.

GPF
April 5th, 2005, 23:55
easier step 9 add fs_chdir("/cd"); to the beginning of main()

so everything automatically starts from the root of the cd, instead of trying to track down everything things thats trying to load.

Troy

MetaFox
April 6th, 2005, 00:04
Cool - it's good to have someone more skilled than I adding to this. :)

Plus you've given me some knowledge that I hadn't previously known, which will cut work down considerably. ;)

Cyruz
April 7th, 2005, 00:23
I think the pong download is corrupt...

MetaFox
April 7th, 2005, 01:31
Yeah, Xylene pointed that out to me earlier.

It should work fine now.

ron
April 7th, 2005, 02:02
>Great tutorial. Thank You

Cyruz
April 7th, 2005, 06:07
everything works until get to make...then it says this;

bash: make: command not found

Did I do something wrong? :S

Kamjin
April 7th, 2005, 08:40
Re-run the Cygwin setup, and when you get to the select packages menu click the "view" button until the "Not Installed" option appears then go down the list and find make, and select it for download. then continue.

btcloud
April 18th, 2005, 02:01
I am such a n00b. I can get to the step where we compile the .elf file, but when I enter make, it does it stuff, then spits out some errors ("pong.c:208:warning enumeration value sdlk_fx no handled in switch", for example) with the final statement "Make: *** [pong.elf] Error:1".

Any ideas?

fackue
April 20th, 2005, 09:06
I followed everything, but I think I'm screwing up the part where you initalize the video mode.

I only found SDL_SetVideoMode in init.c, so that isn't the problem. I get an error when I compile. I may of did this part wrong.


SDL_SetVideoMode(640, 480, 8, SDL_FULLSCREEN)
// setto la modalita' video da utilizzare
if ((scr = SDL_SetVideoMode(SCR_W, SCR_H, BPP, flags)) == NULL)
{
fprintf(stderr, "\n%s\n", SDL_GetError());
return -1;
}

Did I do that right? :?

EDIT: I didn't close and save my makefile, so that could of been the problem. I saved it, and I get, "'pause' redeclared as a different type of symbol". Any ideas?

Hawq
April 29th, 2005, 17:30
Well I give up on the pong, too many errors & stuff, should all this setup work for mame as well?

MetaFox
April 29th, 2005, 19:57
Well I give up on the pong, too many errors & stuff, should all this setup work for mame as well?I have to fix this tutorial. It uses a newer version of the pong source than the one I originally wrote it for, and is no longer an easy change.

But yeah, this setup will work for MAME...

As a matter of fact, I'll write a mini tutorial for MAME later tonight.

Hawq
April 29th, 2005, 20:56
I may give it up, tried to do some mame stuff earlier no joy assorted tons of errors, couldnt see a file that was right there where it was lookin etc.. still might be usefull info for someone else

bigral
May 5th, 2005, 14:09
I have built pong.elf using KOS from this archive - kos1.3svn165.rar; there was an problem hovewer with libfreetype. How to check it now then? I've got no coders cable. And also after I issue command: sh-elf-objcopy -O binary -v pong.elf pong.bin it reports:

copy from pong.elf(elf32-shl) to pong.bin(binary)
sh-elf-objcopy: pong.bin: File truncated

:(