Creating Hello World - U-K-L/Schoolbell-Sega-Saturn GitHub Wiki

These series of tutorials will go over some basic key points of creating games on sega saturn. There are some important notes about the format of these guides.

  • "If you see something in bold quotations, this is a hint it may exists in some manual."
#include "sgl.h"

This include give us access to the entire SGL library sega has created.

We need to tell the saturn where to start our program. By default C programs start with the main function.

#include "sgl.h"
int main(void)
{
    return 0;
}

This will return 0 which indicates success to the Saturn. Which will immediately end our program and stall at the bios screen.

SegaScreen

#include "sgl.h"
int main(void)
{
    return 0;
}

We need to instruct the Saturn to somehow clear the screen.

We can find a command name slInitSystem. slInitSystem initializes the SGL system, SGL is the graphics library, which in simple terms means slInitSystem clears the screen and starts the rendering process.

slInitSystem takes in three arguments, one is the tv_mode. tv_mode is "TV screen mode" a 16 bit value (from 0-65,535). However, these values neatly align in an enum found.

enum tvsz {
	TV_320x224 , TV_320x240 , TV_320x256 , TV_dummy1 ,
	TV_352x224 , TV_352x240 , TV_352x256 , TV_dummy2 ,
	TV_640x224 , TV_640x240 , TV_640x256 , TV_dummy3 ,
	TV_704x224 , TV_704x240 , TV_704x256 , TV_dummy4 ,

	TV_320x448 , TV_320x480 , TV_320x512 , TV_dummy5 ,
	TV_352x448 , TV_352x480 , TV_352x512 , TV_dummy6 ,
	TV_640x448 , TV_640x480 , TV_640x512 , TV_dummy7 ,
	TV_704x448 , TV_704x480 , TV_704x512 , TV_dummy8
    } ;

The Saturn has a number of processors, each with its own tasks. The VDP2 is responsible for handling TV Screen Modes. This enum takes that value and instructs the VDP2 on what screen mode to render at.

See: TV Screen Mode in VDP2 Users Manual for more info.

slInitSystem takes in three arguments, the next of which is the texture address. The texture address is the relative address of VDP1 memory, another processor within the saturn. In order to use this we can do the following:

#include "sgl.h"
exterm Texture tex_sample[];

This tex_sample can be used to initialize the graphics with a texture. For our use case, we will ensure this is NULL, as we won't be using any texture.

The final argument is the Graphics processing unit specification. This essentially instructs how often the GPU updates. At a value of 1, it will update 60 times per second, 2 will be two drawing processes which is 30 times a second, and so on.

Okay now, let's wrap that up and start coding again!

#include "sgl.h"

int main(void)
{
    slInitSystem(TV_320x224, NULL, 1); // Initialize the system, set the video mode to 320x224, 60 FPS.
    return 0;
}

BlackScreen (2)

We now have a black screen! Congratulations! Now let's try to print something to the screen.

We can use another function called "slPrint" this function takes in two arguments, the first being the string to print, the second being the location to print it at. The location can be done with the following command: SlLocate(x,y).

Let's also add a game loop as well:

#include "sgl.h"
int main(void)
{
    slInitSystem(TV_320x224, NULL, 1); // Initialize the system, set the video mode to 320x224, 60 FPS.

    //Game loop.
    while(TRUE)
    {
        slPrint("Hello World!", slLocate(0,0));
    }
    return 0;
}

HelloWorldSegaSaturn