Category Archives: libyaul

Getting started on SEGA saturn development – Part 2

After the Hello World

After writing a simple hello world, 2 things are needed before proceeding :

  • Get the execution time, (and in turn, frame times) in order to properly write time based animations
  • How to get simple primitives drawn on the screen

Getting execution time

libyaul supplies following function

static uint16_t cpu_frt_count_get(void);

However the return type is a problem : it quickly overflows.
After some digging on discord, as well as examples provided with libyaul:

#include <yaul.h>

#include <stdio.h>
#include <stdlib.h>

uint32_t elapsed_time = 0;
static void _frt_ovi_handler(void);
static uint16_t _frt_overflow_count = 0;

void main(void)
{
    //initialize dbgio
    dbgio_dev_default_init(DBGIO_DEV_VDP2_SIMPLE);
    dbgio_dev_font_load();
    dbgio_dev_font_load_wait();
    vdp2_tvmd_display_set();

    cpu_frt_init(CPU_FRT_CLOCK_DIV_32);

    uint32_t frame_time = 0 ;
    uint32_t frame_start = 0 ;
    uint32_t frame_end = 0 ;

    //init

    cpu_frt_ovi_set(_frt_ovi_handler);
    cpu_frt_count_set(0);

    /* Reset overflow counter after setting the FRT count to zero in case
     * there's an FRT overflow interrupt */
    
    _frt_overflow_count = 0;

    while(1)
    {
        elapsed_time += frame_time;
        frame_start = ((65536 * _frt_overflow_count) + (uint32_t) cpu_frt_count_get()) / CPU_FRT_PAL_320_32_COUNT_1MS;
        
        dbgio_printf("\x1b[H\x1b[2J");
        dbgio_printf("Elapsed time :\t %u
        \nFrame_time :\t %u
        \nFrame Start :\t %u
        \nFrame End :\t %u
        \noverflow cnt :\t %u\n", 
        (unsigned int) elapsed_time,
        (unsigned int) frame_time, 
        (unsigned int) frame_start,
        (unsigned int) frame_end,
        (unsigned int) _frt_overflow_count);
        dbgio_flush();
        vdp_sync();

        frame_end = ((65536 * _frt_overflow_count) + (uint32_t) cpu_frt_count_get()) / CPU_FRT_PAL_320_32_COUNT_1MS;
        frame_time = (frame_end - frame_start) ; // get tick count at start 
    }
}

static void _frt_ovi_handler(void)
{
        _frt_overflow_count++;
}


Now I’m able to measure the render time and also have the elapsed time.

Getting started on SEGA Saturn development – Part 1

A hello world on libyaul.

Nothing better than a simple hello world to get the feet wet on a new hardware.

My goal, as of April 2021, is to get a simple demo (as in demoscene demo) done by October, for Inercia Demoparty , for the sega saturn.

I’ve already had a USB dev cart for the sega saturn that I’ve brought from cafe-alpha, but had been gathering dust for several years.

Toolchains

As toolchains for the sega saturn I’ve found :

  • Libyaul : available for windows and linux. Tools such as emulators to test the code are already included.
  • Saturn SDK : SDK, libs and documentation.
  • Jo Engine : an open source 2d and 3d engine.

The list is not complete.
I´ve decided to stick to libyaul. On windows it was simple to setup, examples could be easy compiled out of the box, and it has a helpful and active community on discord , where the author of libyaul is also part of.

Hello World

Makefile

The make file was just a modified makefile already available from the exemples provided with libyaul.

Code

#include <yaul.h>

#include <stdio.h>
#include <stdlib.h>

void main(void)
{
    //init the subsystem to print debug text to the screen
    dbgio_dev_default_init(DBGIO_DEV_VDP2_SIMPLE);
    dbgio_dev_font_load();
    dbgio_dev_font_load_wait();

    //enable vdp2
    vdp2_tvmd_display_set();
  
    while(1)
    {
        dbgio_printf("\x1b[H\x1b[2J");  // clears the screen
        dbgio_printf("Hello World\n");  // actual text
        dbgio_flush();                  // flush 
        vdp_sync();                     // required at the end of each frame
    }
}