Home‎ > ‎Tutorials‎ > ‎SGDK‎ > ‎

Tutorial 2 : Create a New Project

When I followed other tutorials to create a new SGDK project using Code::Blocks I always encountered errors. This is why I've decided to produce my own working tutorial - tested on Windows 7 and Windows 8.1.

Purpose

The purpose of this tutorial is to provide instructions on how to create a new SGDK project using Code::Blocks. This tutorial was written using SGDK 1.01 and Code::Blocks 13.12.

Create Empty Project

Start by creating a new empty project.
  • Open Code::Blocks
  • Go to File -> New -> Project
  • Select "Empty Project"
  • Click "Go"

If this is your first time using Code::Blocks you'll probably want to put a checkmark in "Skip this page next time" on the first empty project prompt.
  • Enter a Project Title and a directory in which to create your project
    • Note that Code::Blocks will create a directory with the Project Title in the directory you selected
  • The "Project filename" and "Resulting filename" textboxes are filled automatically by Code::Blocks
  • Click "Next" when done

Setup Release Configuration

  • Select "SGDK" from the "Compiler" dropdown list
  • Uncheck "Create Debug Configuration" since SGDK has no debugger
  • Change the "Release Configuration" name to "default"
  • Change both release output dirs to "out\" as shown below
  • When done, click "Finish"

Configure Your Project

We need to make a few minor adjustments to the project before it will happily compile with SGDK.

Project Target Options

  • In the project navigator, right-click on your newly created project and select "Properties"
  • Enter the path to SGDK's makefile (in my case, C:\Dev\SGDK\makefile.gen) in the "Makefile" textbox
  • Place a checkmark in "This is a custom Makefile"
Although not required, I like to change the "Execution directory" to a relative path, this lets you develop with team members who might not have their project stored in the same exact directory as you (though they would still need to store SGDK in the same directory).
  • To do this, click on the browse icon next to the "Execution directory" text box
  • Browse to this project's directory
  • When prompted, answer Yes to "Keep this path as relative"
  • Click "OK" to close this window

Project Build Options

  • Right-click on your project in the project explorer again, and again select "Properties"
  • Click on "Project's Build Options" on the bottom right
  • Select the "Default" configuration
  • Select the "Make commands" tab
    • if you're wondering why we closed and re-opened the project properties, not doing so would've left the make commands greyed-out
  • Enter the following:
    • Build project/target: $make -f $makefile
    • Compile single file: $make -f $makefile $file
    • Clean project/target: $make -f $makefile clean
    • Ask if rebuild is needed: $make -q -f $makefile clean


If you're wondering what the bloody hell all these make commands are, these are simply a generic version of the command line we used to compile in Tutorial 1.

        %GDK_WIN%\bin\make -f %GDK_WIN%\makefile.gen

Compare the above to the Code::Blocks make command for Build project/target

        $make -f $makefile

Both of these commands are in effect the same and have 3 components: the make command, the file argument, and the makefile path.

And that's it for configuration, we are now ready to start adding files to our project.

Create the Project

Create Directory Structure

SGDK expects files to be in a certain directory structure within your project. The root of your project should contain at least one folder:
  • \src
In effect, SGDK project should obey the following directory structure rules:
  • source files : in root directory or "\src"
  • include files: in root directory or "\inc"
  • resource files: in root directory or "\res"
It would be bad practise to store everything in the root directory.

Add Source Files

Navigate to your project's directory in Windows Explorer and create the \src directory. Inside the \src directory, create a new text file and rename it to "main.c". Now return to Code::Blocks.
  • Right-click on your project in the project explorer and select "Properties"
  • Click on "Add Files..."
  • Browse to your project's directory and select "main.c" which we just created
    • At this point, you could obviously add an existing file
  • Expand the project tree in the project explorer until you reach "main.c"
  • Double-click on "main.c" to open the empty source file
  • Code away!

Test Build Parameters

I've placed the generic Hello World example above, you can quickly type it up (or copy it from below) to test your build parameters. If successful, you see the last few lines of the build log (bottom of screen) with something similar to:
  • C:/Dev/SGDK/bin/objcopy -O binary out/rom.out out/rom.bin
  • C:/Dev/SGDK/bin/sizebnd out/rom.bin -sizealign 131072
  • Process terminated with status 0 (0 minute(s), 7 second(s))
  • 0 error(s), 0 warning(s) (0 minute(s), 7 second(s))
Which indicates to you that a "rom.bin" was generated in the \out directory of your project directory. You can open this file in your favourite emulator to see the fruits of your labour.

Genesis "Hello World!"

#include <genesis.h>

int main()
{
        VDP_drawText("Hello World!", 10, 13);
        return (0);
}