Skip to content

Tutorial

Emil Mair edited this page Mar 24, 2023 · 7 revisions

It follows our recommendation on how to develop games for MES.

Setting up a Simulation

Because uploading your game to a real console while debugging is really time consuming, we created a MES simulator called Virtual-MES. V-MES compiles your games source code with its own drivers, allowing MES games to run on PC (this is what makes it a simulator, not an emulator). You can set it up using the instructions over at its repository, but we recommend using our template repository. It incorporates simulation and uploading to real hardware and reduces the complexity of your workflow significantly. In this Tutorial, we will be using the template, so follow the instructions found in that repository. If you want to include MES/V-MES into your own build system, you're probably skilled enough to follow this tutorial anyway.

Creating a "Hello, World!" program

In terms of "Time to hello world", MES ranks quite high, considering it needs to render the characters and not simply send them through a data stream. This is what a "Hello World" program for MES looks like:

#include <gpu.h>

uint8_t start(void) {
    char* helloworld = "Hello, World!";
    gpu_blank(FRONT_BUFFER, 0);
    gpu_print_text(FRONT_BUFFER, 1, 1, 1, 0, helloworld);
    return EXIT_FREEZEFRAME
}

Since we will be drawing something on the screen, first include the GPU header. The main function, the one that will be executed when the user opens your game, is called start and has uint8_t as its return type. For a list of all return codes, see the documentation.

Inside the function we first declare our hello world string as a char*. The following two functions are provided by the GPU header and will clear the screen (with the color black, which is 0 in the standard palette), then render our text onto it at the location (1, 1), with foreground color 1 (white) and background color 0. All of this is applied to the FRONT_BUFFER, which is the buffer the user sees on screen.

Finally, by returning the freeze frame exit code, we leave our program but keep the last frame on screen.

Understanding graphics specifications

Understanding graphics specifications

MES image buffers are formatted in a very specific way to enable fast rendering on the GPU, who otherwise couldn't keep up with the demanding 60 FPS VGA standard. Not only to they have a bit depth of 3 (which means 8 simultaneous colors on screen), but are also grouped in 3-byte-chunks and scrambled among one another inside those chunks. This means the size of an image buffer is always divisible by three.

Especially of you're new to game development on MES, we recommend using additional headers like mesgraphics.h, which abstract the complex graphics specification to a higher level and provide functions for manipulating images easier. Take a look at the GPU Header documentation to learn about the exact specifications.

Because a depth of three bits drastically limits your inner artist, you can change the palette from the default one (black, white, red, green, blue, yellow, magenta, cyan), to any 9-bit color you want.

To keep it simple, lets limit ourselves to black and cyan. Since they have the indices 0 and 1 on the default palette, we can fill any graphics buffers with a those colors by filling them with ones or zeroes respectively.

This is what a 10x10 cyan rectangle at (50, 50) on a black screen looks like:

#include <gpu.h>

uint8_t start(void) {
    uint8_t* square = malloc(39);
    memset(square, 0xFF, 39);
    gpu_blank(FRONT_BUFFER, 0);
    gpu_send_buf(FRONT_BUFFER, 10, 10, 50, 50, square);
    return EXIT_FREEZEFRAME;
}

The buffer is 39 bytes big because 100 pixels at 3 bits per pixel make 300 bits, which would be 37,5 bytes, rounded up to the next multiple of three.

Timing the game loop

Reading controller input

Partitioning SD cards

Uploading to real hardware

Clone this wiki locally