Main.cpp

From dreamcast.wiki
Jump to navigation Jump to search

A main source file is the starting point for any Dreamcast program. The first run function will be int main(int argc, char **argv), and thus the file it resides in is considered the main source file. It is typical to name this file something like main.cpp, or perhaps game.cpp, or the name of your program with .cpp attached. For the purpose of this tutorial, we will refer to it as Main.cpp.

Create a new text file called Main.cpp, and open it to begin editing.

Headers

Let’s start by adding some header files to the top of our main.cpp:

#include <arch/gdb.h>           /* gdb debugger */
#include <kos.h>                /* KalistiOS Dreamcast SDK */
#include <png/png.h>            /* Library to load png files */
#include <stdio.h>              /* Standard Input-Output */
#include <stdint.h>             /* Standard Integer types (uint_t, etc) */

The top are KOS files. KOS it the dreamcast system SDK we use to talk to the console. We’re including the main KOS calls, along with some files needed for GDB debugging. I’m also including the png library, as we’ll be using pngs as textures in our program. Stdio.h and stdint.h are standard libraries related to input/output, and integer types specifically. The latter defines standard types like uint32_t and uint8_t. These types are important as they let us explicitly define our variables by size.

int main(int argc, char** argv)

Our program begins execution here:

int main(int argc, char **argv) {
#ifdef GAME_DEBUG
    gdb_init();
#endif
    /* init kos  */
    pvr_init_defaults();
	/* Main loop */
    while(1)
    {
		printf(“running!\n”);
    }
    return 0;
}

the function gdb_init() is included in #ifdef tags for GAME_DEBUG. This function will only be called if a GAME_DEBUG flag is set from our compiler. When this is called, we will see our program pause in the console output and declare that it’s waiting for a GDB debugger. When this happens, we can remote connect to our gdb port, and our dreamcast will begin interfacing and debugging with our computer.

After that, we call and initialize PVR, then move into our main loop. Right now, our main loop never ends, and just prints that it’s running. You can test this program out, but it’s not worth running at the moment. For now, we have our basic shell of a program, along with our makefile.